Code archives/Miscellaneous/Project PLASMA FPS 2004: Stack.bb
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
General Purpose First In - LastOut (FILO) Integer Stack. Used in all code modules. Can be used manage a pool of entities and much more. Note a majority of the code generated with the TypeWriter Code Wizard:) Summary of functions: stackCreate(size%) Creates a stack object of a specified size. stackIndexCreate(size%) Creates a stack of indexed integers. Primarily used to create a list of object ids. Object IDs are pushed and poped as needed. stackDelete(this.stack) Removes a stack from memory. stackPush(this.stack,value%) Inserts a value on the stack. stackPop(this.stack) Extracts the last value inserted on the stack. Last Update 01/16/04 Check out the Wip Zip for demos and more code! | |||||
;============================ ;STACK (FILO) ;============================ Type stack Field pointer% Field size% Field bank% End Type Function stackStop() For this.stack=Each stack stackDelete(this) Next End Function Function stackNew.stack() this.stack=New stack this\pointer%=0 this\size%=0 this\bank%=0 Return this End Function Function stackDelete(this.stack) FreeBank this\bank% Delete this End Function Function stackManager() For this.stack=Each stack Next End Function Function stackCreate.stack(size%) this.stack=stacknew() this\size%=size% this\bank=CreateBank(4*this\size%) Return this End Function Function stackIndexCreate.stack(size%) this.stack=stackCreate(size%) For loop = size% To 1 Step -1 stackPush(this,loop) Next Return this End Function Function stackPush%(this.stack,value%) PokeInt(this\bank%,this\pointer%,value%) this\pointer%=this\pointer%+4 End Function Function stackPop%(this.stack) this\pointer%=this\pointer%-4 Return PeekInt(this\bank%,this\pointer%) End Function |
Comments
| ||
This is a FIFO stack. |
| ||
Erm... Oops. |
Code Archives Forum