I am not using types at all - only simulating an implimentation of them ... example given is primarily of the CAMERA object but a section of the code for the BASE object is given for clarity (i hope

)
Please note that this is code 'in progress' - i have tried to avoid ad hoc inprovisation where possible because that is just generally bad practice (yes, you will see *one* example of it!) - but the code works - I just need the flexability that this system provides for the type of game i am writing (no, sorry - no hints at this stage cos as far as i am aware no noone has used the idea in its entirity yet)
All objects are created from the BASE object which is comprised of differing subblocks depending on how flags
are set at the time of object creation
The CAMERA object only needs an ID to identify the correct Dark Basic camera but subtype determines the camera's behaviour within the enviroment. Additionally the camera has a Parent-Peer-Child Ptr block to link to other camera's that may or may not be created during run time
************************************************************
BASE OBJECT CODE : baseObj.dba
************************************************************
Rem Project: baseObj
Rem Created: 18/01/2003 00:55:33
Rem ***** Main Source File *****
#include "..\memio\memio.dba"
REMstart
TYPE baseObj
class as BYTE
subType as BYTE
id as WORD
flags as DWORD
ENDTYPE
REMend
REM *** Constants ***
REM BASE Header constants
#constant C_BASE_SIZEOFHEADER 8
#constant C_BASE_CLASSOFFSET 0
#constant C_BASE_SUBTYPEOFFSET 1
#constant C_BASE_IDOFFSET 2
#constant C_BASE_FLAGSOFFSET 4
REM *** BASE Block Flag constants 00000000 0000000 0000000 0000000
#constant C_BASE_2DBLOCKFLAG %00000000000000000000000000000001
#constant C_BASE_PTRBLOCKFLAG %00000000000000000000000000000010
#constant C_BASE_BEHAVIOURBLOCKFLAG %00000000000000000000000000000100
#constant C_BASE_MOUSEBLOCKFLAG %10000000000000000000000000000000
REM *** BASE Block size constants ***
REM To be added to as work progresses
REM *** 2D POS Block ***
REM X,Y Z - Depth 12
REM W,H spare 12
#constant C_BASE_2DBLOCK 24
REM *** PTR Block ***
REM Parent Ptr 4
REM Peer Ptr 4
REM Child Ptr 4
#constant C_BASE_PTRBLOCK 12
REM *** Behaviour state Block
REM State 4
#constant C_BASE_BEHAVIOURBLOCK 4
REM *** Mouse block
REM Mx 4
REM My 4
REM MButton 4
#constant C_BASE_MOUSEBLOCK 12
FUNCTION BASE_createBaseObj(bFlags)
tPtr as DWORD
tSize as integer
tMask as DWORD
REM Init size count and mask
tSize = 0
tMask = 1
for lCount = 0 to 31
if tMask AND bFlags <> 0
tSize = tSize + BASE_getBaseBlockSize(tMask)
endif
tMask = tMask * 2
next lCount
REM Add header block
tSize = tSize + C_BASE_SIZEOFHEADER
tPtr = MEM_getMemblock(tSize)
if tPtr = 0
REM Failed
else
REM Success
endif
ENDFUNCTION tPtr
************************************************************
CAMERA OBJECT CODE : camera.dba
************************************************************
Rem Project: camera
Rem Created: 19/01/2003 07:56:20
Rem ***** Main Source File *****
#include "..\memio\memio.dba"
#include "..\baseObj\baseObj.dba"
#include "..\sysConst\sysConst.dba"
#include "..\sysMsg\sysMsg.dba"
REMstart
TYPE baseObj
class as BYTE
subType as BYTE
id as WORD
flags as DWORD
ENDTYPE
REMend
REMstart
TYPE cam
HEADER BLOCK camheader
- class 01 - see SYSCLASS in sysConst
- subtype 00 - 0 = standard fullscreen camera
- id - is the same id system uses - default camera is 1
- flags - block types and behaviour
BASE PTR BLOCK - as defined in baseObj and set by flags in cam flags item
- Parent Ptr as DWORD
- Peer Ptr as DWORD
- Child Ptr as DWORD
ENDTYPE
REMend
REM Standard subtype for camera - fullscreen
#constant C_CAMERA_STANDARDSUB 0
REM NB NB NB - Bad pracice - should be calculated from BASE flags
REM But this is the same for all cameras and constant can be used
#constant C_CAMERA_PREBLOCKOFFSET 8
REM NB NB NB
REM CAMERA constants
#constant C_CAMERA_ROTATESPEED 3
FUNCTION CAMERA_createCamera(parentPtr,tCamSub)
REM createCamera creates a cam with the specified type
REM and returns - doesnt need to attach it - done by receiving function
REM parentPtr passes the cameraPtr of the calling SYSTEM object
camTop as DWORD
tPtr as DWORD
tFlags as DWORD
tId as integer
camTop = parentPtr
REMstart
if C_SYSTEM_DEBUG = 1
print "CAMERA_createCamera initialized"
sync
endif
REMend
REM Set camera flags
tFlags = 0
select tCamSub
case C_CAMERA_STANDARDSUB
tFlags = tFlags + C_BASE_PTRBLOCKFLAG
endcase
case default
REM Create as standard camera
tFlags = tFlags + C_BASE_PTRBLOCKFLAG
endcase
endselect
tPtr = BASE_createBaseObj(tFlags)
tId = CAMERA_getNextId(camTop)
REM tCamFlag is calculated as defined by the SUBTYPE
REM BASE_setHeader(tPtr, C_SYSCLASS_CAMERA, tCamSub, tId ,tCamFlag)
BASE_setHeader(tPtr, C_SYSCLASS_CAMERA, tCamSub, tId ,tFlag)
REM TEMP setup of camera - to be removed and replaced by sysMsg's from system
MAKE CAMERA tId
POSITION CAMERA tId, 0, 100, 0
ROTATE CAMERA tId, 0, 0, 0
ENDFUNCTION tPtr
FUNCTION CAMERA_getNextId(camTop)
nPtr as DWORD
tPtr as DWORD
tId as integer
nId as integer
quitFlag as integer
tVal as DWORD
tVal = *camTop
quitFlag = 0
tId = 1
while quitFlag = 0
REM DeRef ptr to determine if NULL
if tVal = 0
REM Parent is unlinked to cameras - tId will be its current value
quitFlag = 1
else
REM New camera's linked to END of list - should be in approximate order
REM Get Parent Ptr of object
nId = BASE_getId(camTop)
if nId = tId
tId = tId + 1
endif
nPtr = BASE_getBlockOffset(camTop, C_BASE_PTRBLOCKFLAG)
REM Top of block (ie ParentPtr) is returned - update to Peer Ptr
nPtr = nPtr + C_SIZEOFDWORD
endif
endwhile
ENDFUNCTION tId
FUNCTION CAMERA_receiveMsg(cPtr,mPtr)
camPtr as DWORD
msgPtr as DWORD
tempPtr as DWORD
mId as WORD
cID as WORD
nOffset as DWORD
nCamPtr as DWORD
camPtr = cPtr
msgPtr = mPtr
mId = SYSMSG_getId(msgPtr)
cId = BASE_getId(camPtr)
if cId = mId
REM Msg has reached right object
CAMERA_processMsg(camPtr,msgPtr)
else
REM Either wrong id or subtype
REM Check for PEER
REM Point to camtop + ptrBlockOffset + peerPtrOffset
tempPtr = camPtr + C_CAMERA_PTRBLOCKOFFSET + C_SIZEOFDWORD
nCamPtr = *tempPtr
if nCamPtr = 0
REM Mis-sent MSG
else
REM Send to camera
CAMERA_receiveMsg(nCamPtr,mPtr)
endif
endif
ENDFUNCTION
FUNCTION CAMERA_processMsg(cPtr,mPtr)
camPtr as DWORD
msgPtr as DWORD
cId as BYTE
cmsg as WORD
cdata as integer
camPtr = cPtr
msgPtr = mPtr
REM Get ID of camera
cId = BASE_getId(camPtr)
REM Get System msg and data
cmsg = SYSMSG_getMsg(msgPtr)
cdata = SYSMSG_getMsgData(msgPtr)
select cmsg
case C_SYSMSG_HROTATEMSG
yrotate camera cId, camera angle y(cId) + (cdata/C_CAMERA_ROTATESPEED)
endcase
case C_SYSMSG_VROTATEMSG
endcase
case default
REMstart
print "CAMERA_processMsg: DEFAULT MSG"
MEM_dumpMem(msgPtr,C_SIZEOFMSG)
sync
wait key
REMend
endcase
endselect
ENDFUNCTION