I really felt a detailed explanation of my Database methodology was in order. I have used the concept of Primary ID Keys to devise a flexible Resource Management System that may be useful in other projects.
My Resource Management System relies on Array of Types, ID field in the Blitz Custom type, and a dedicated FILO Stack. Each type stores a unique index number in the ID field. A single element array of types stores a reference to the game object matching the id%. A FILO stack is used to track the ids in use. All types can be linked to another by id%. Thus, if you need to know "What invader shot that defender and witch vampire bit some ghostships? And why is everything moving in slow motion? Oops; where did those 10.000 guided missiles come from?" you can store a id reference to it.
My Resource Management System relies on Array of Types, ID field in the Blitz Custom type, and a dedicated FILO Stack. Each type stores a unique index number in the ID field. A single element array of types stores a reference to the game object matching the id%. A FILO stack is used to track the ids in use. All types can be linked to another by id%. Thus, if you need to know "What invader shot that defender and witch vampire bit some ghostships? And why is everything moving in slow motion? Oops; where did those 10.000 guided missiles come from?" you can store a id reference to it.
;Example of missile object Const MISSILE_MAX%=100 ;<-- Predefined maximum number of missiles Global missileIndex.stack=stackIndexCreate(MISSILE_MAX%) ;<-- Dedicated FILO Stack Type missile ;<-- missile Game Object Custom Type Field id%<-- Primary Key Field typeid% <-- Composite Key Field shipid%<-- Foreign Key Field entityid% Field targetid% Field state% Field life% Field damage% End Type Dim missileID.missile(MISSILE_MAX%) ;<-- Array of Types (Reference) Function missileNew.missile() ;<-- initiallizes a new instance of object aka constructor this.missile=New missile this\id%=0 ;<-- Default values (optional) this\typeid%=0 this\shipid%=0 this\entityid%=0 this\targetid%=0 this\state%=0 this\life%=0 this\damage%=0 this\id%=StackPop(missileIndex.stack) ;<-- Pops available ID off FILO Stack missileId(this\id%)=this ;<-- assign Primary Key to object matching array index/object id Return this End Function Function missileDelete(this.missile) missileId(this\id%)=Null StackPush(missileIndex.stack,this\id%) Delete this End Function Function missileCreate.missile(typeid%,shipid%,targetid%,state%,life%,damage%) this.missile=missileNew() this\typeid%=typeid% this\shipid%=shipid% this\entityid%=stackPop(missileEntity.stack[this\typeid]) this\targetid%=targetid% this\state%=state% this\life%=life% this\damage%=damage% End Function Function missileDestroy(this.missile) stackPush(missileEntity.stack[this\typeid],this\entityid%) missileDelete(this) End Function Function missileUpdate() ;<-- update function included in primary game loop For this.missile = Each missile Select this\state% Case 1 ;flight movement and collsion Select this\typeid% ;<-- Case 1 ;guided missileGuide(this) Case 2 ;heatseeker missileHeatSeek(this) Case 3 ;rocket missileMove(this) End Select Case 2 ;impact missileDamage(this) Case 3 ;detonated missileDestroy(this) End Select Next End FunctionI've developed the TypeWriter][ Code Wizard for Project PLASMA FPS 2004 to generate common initialization, deletion, update, open, and save functions from a Custom Type based on my object-based programming methodology. The code produced takes into count the Resource Management System, types within types, and type arrays. Ultimately its all about the design of your game objects.