This commit is contained in:
parent
5b785068c2
commit
fa5105d783
96 changed files with 550 additions and 406 deletions
|
@ -11,6 +11,7 @@
|
|||
|
||||
===========================================================================*/
|
||||
|
||||
//#define USE_FREE_LIST
|
||||
/*----------------------------------------------------------------------
|
||||
Includes
|
||||
-------- */
|
||||
|
@ -31,9 +32,13 @@
|
|||
|
||||
#include "level\level.h"
|
||||
|
||||
#ifndef __HAZARD_HAZARD_H__
|
||||
#include "hazard\hazard.h"
|
||||
#endif
|
||||
// Needed for freelist table :o(
|
||||
#include "pickups\pickup.h"
|
||||
#include "platform\platform.h"
|
||||
#include "projectl\projectl.h"
|
||||
#include "enemy\npc.h"
|
||||
#include "friend\friend.h"
|
||||
#include "fx\fx.h"
|
||||
|
||||
#ifndef __HAZARD_HRWEIGHT_H__
|
||||
#include "hazard\hrweight.h"
|
||||
|
@ -47,7 +52,6 @@
|
|||
#include "hazard\hpswitch.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* Std Lib
|
||||
------- */
|
||||
|
||||
|
@ -82,11 +86,34 @@ static const int s_ThinkBBoxY1=256+128;
|
|||
CThing *CThingManager::s_thingLists[CThing::MAX_TYPE];
|
||||
CThing *CThingManager::s_CollisionLists[CThing::MAX_TYPE];
|
||||
int CThingManager::s_initialised=false;
|
||||
|
||||
sBBox CThingManager::m_RenderBBox;
|
||||
sBBox CThingManager::m_ThinkBBox;
|
||||
|
||||
#ifdef USE_FREE_LIST
|
||||
CThing **CThingManager::s_FreeList[CThing::MAX_TYPE];
|
||||
|
||||
|
||||
struct sFreeListTable
|
||||
{
|
||||
u16 Type;
|
||||
u16 Count;
|
||||
};
|
||||
|
||||
static const sFreeListTable FreeListTable[]=
|
||||
{
|
||||
/* 0*/ {CThing::TYPE_PICKUP ,CBasePickup::MAX_SUBTYPE},
|
||||
/* 1*/ {CThing::TYPE_PLATFORM ,CNpcPlatform::MAX_SUBTYPE},
|
||||
/* 2*/ {CThing::TYPE_PLAYER ,CPlayerThing::MAX_SUBTYPE},
|
||||
/* 3*/ {CThing::TYPE_PLAYERPROJECTILE ,CPlayerProjectile::MAX_SUBTYPE},
|
||||
/* 4*/ {CThing::TYPE_NPC ,CNpcFriend::MAX_SUBTYPE},
|
||||
/* 5*/ {CThing::TYPE_ENEMY ,CNpcEnemy::MAX_SUBTYPE},
|
||||
/* 6*/ {CThing::TYPE_ENEMYPROJECTILE ,CProjectile::MAX_SUBTYPE},
|
||||
/* 7*/ {CThing::TYPE_TRIGGER ,CTriggerThing::MAX_SUBTYPE},
|
||||
/* 8*/ {CThing::TYPE_HAZARD ,CNpcHazard::MAX_SUBTYPE},
|
||||
/* 9*/ {CThing::TYPE_FX ,CFX::MAX_SUBTYPE},
|
||||
};
|
||||
static const int FreeListTableSize=sizeof(FreeListTable)/sizeof(sFreeListTable);
|
||||
#endif
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
|
@ -98,6 +125,7 @@ void CThingManager::init()
|
|||
ASSERT(!s_initialised);
|
||||
initList(s_thingLists);
|
||||
initList(s_CollisionLists);
|
||||
initFreeList();
|
||||
s_initialised=true;
|
||||
}
|
||||
|
||||
|
@ -119,10 +147,11 @@ void CThingManager::shutdown()
|
|||
{
|
||||
thing=s_thingLists[i];
|
||||
thing->shutdown();
|
||||
delete thing;
|
||||
DeleteThing(thing);
|
||||
}
|
||||
}
|
||||
s_initialised=false;
|
||||
shutdownFreeList();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -167,7 +196,7 @@ void CThingManager::killAllThingsForRespawn()
|
|||
else
|
||||
{
|
||||
thing->shutdown();
|
||||
delete thing;
|
||||
DeleteThing(thing);
|
||||
thing=s_thingLists[i];
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +382,7 @@ DVECTOR const &CamPos=CLevel::getCameraPos();
|
|||
if (player && playerThing)
|
||||
{
|
||||
playerThing->setHasPlatformCollided( false );
|
||||
playerThing->setNewCollidedPos( playerThing->getPos() );
|
||||
//!Dave! playerThing->setNewCollidedPos( playerThing->getPos() );
|
||||
|
||||
// Player -> Platform collision
|
||||
thing1=s_CollisionLists[CThing::TYPE_PLATFORM];
|
||||
|
@ -521,7 +550,7 @@ DVECTOR const &CamPos=CLevel::getCameraPos();
|
|||
if ( thing->isSetToShutdown() )
|
||||
{
|
||||
thing->shutdown();
|
||||
delete thing;
|
||||
DeleteThing(thing);
|
||||
}
|
||||
|
||||
thing = nextThing;
|
||||
|
@ -629,6 +658,7 @@ CThing *CThingManager::checkCollisionAreaAgainstThings(CRECT *_area,int _type,i
|
|||
void CThingManager::addToThingList(CThing *_this)
|
||||
{
|
||||
int Type=_this->getThingType();
|
||||
|
||||
_this->m_nextListThing=s_thingLists[Type];
|
||||
s_thingLists[Type]=_this;
|
||||
}
|
||||
|
@ -675,14 +705,130 @@ int Type=thing->getThingType();
|
|||
s_CollisionLists[Type]=thing;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
/*** Free List Stuff ************************************************/
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
void CThingManager::initFreeList()
|
||||
{
|
||||
#ifdef USE_FREE_LIST
|
||||
// Make sure no-one is being naughty
|
||||
ASSERT(FreeListTableSize==CThing::MAX_TYPE)
|
||||
|
||||
for (int i=0; i<FreeListTableSize; i++)
|
||||
{
|
||||
sFreeListTable const &ThisType=FreeListTable[i];
|
||||
int Count=ThisType.Count;
|
||||
CThing **List=(CThing**)MemAlloc(Count*sizeof(CThing**),"ThingCache");
|
||||
for (int t=0; t<Count; t++)
|
||||
{
|
||||
List[t]=0;
|
||||
|
||||
}
|
||||
s_FreeList[ThisType.Type]=List;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void CThingManager::resetFreeList()
|
||||
{
|
||||
#ifdef USE_FREE_LIST
|
||||
for (int i=0; i<FreeListTableSize; i++)
|
||||
{
|
||||
sFreeListTable const &ThisType=FreeListTable[i];
|
||||
int Count=ThisType.Count;
|
||||
|
||||
CThing **List=s_FreeList[i];
|
||||
for (int t=0; t<Count; t++)
|
||||
{
|
||||
CThing *ThisThing=List[t];
|
||||
while (ThisThing)
|
||||
{
|
||||
CThing *Next=ThisThing->NextFreeThing;
|
||||
delete ThisThing;
|
||||
ThisThing=Next;
|
||||
}
|
||||
List[t]=0;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void CThingManager::shutdownFreeList()
|
||||
{
|
||||
#ifdef USE_FREE_LIST
|
||||
resetFreeList();
|
||||
for (int i=0; i<FreeListTableSize; i++)
|
||||
{
|
||||
sFreeListTable const &ThisType=FreeListTable[i];
|
||||
MemFree(s_FreeList[ThisType.Type]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
CThing *CThingManager::GetThing(int Type,int SubType)
|
||||
{
|
||||
#ifdef USE_FREE_LIST
|
||||
CThing **List=s_FreeList[Type];
|
||||
CThing *Thing=List[SubType];
|
||||
|
||||
|
||||
if (Thing)
|
||||
{
|
||||
List[SubType]=Thing->NextFreeThing;
|
||||
Thing->initDef();
|
||||
Thing->NextFreeThing=0;
|
||||
}
|
||||
|
||||
return(Thing);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void CThingManager::DeleteThing(CThing *Thing)
|
||||
{
|
||||
#ifdef USE_FREE_LIST
|
||||
int Type=Thing->getThingType();
|
||||
int SubType=Thing->getThingSubType();
|
||||
CThing **List=s_FreeList[Type];
|
||||
|
||||
// Check its been aquired/set correctly
|
||||
|
||||
ASSERT(SubType!=1234);
|
||||
|
||||
Thing->NextFreeThing=List[SubType];
|
||||
List[SubType]=Thing;
|
||||
|
||||
#else
|
||||
delete Thing;
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
int DaveDbg=1;
|
||||
void CThing::init()
|
||||
{
|
||||
ASSERT(DaveDbg);
|
||||
ParentThing=NULL;
|
||||
NextThing=NULL;
|
||||
m_numChildren = 0;
|
||||
|
@ -691,11 +837,10 @@ void CThing::init()
|
|||
// These need to stay for init
|
||||
setCollisionSize(20,20); // Some temporary defaults.. (pkg)
|
||||
setCollisionCentreOffset(0,0);
|
||||
setCollisionAngle(0);
|
||||
//!Dave! setCollisionAngle(0);
|
||||
|
||||
// Add to thing list
|
||||
CThingManager::addToThingList(this);
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -983,7 +1128,7 @@ CThing *List=NextThing;
|
|||
List->ParentThing=NULL;
|
||||
List->NextThing=NULL;
|
||||
List->shutdown();
|
||||
delete List;
|
||||
CThingManager::DeleteThing(List);
|
||||
List=NextThing;
|
||||
}
|
||||
NextThing=NULL;
|
||||
|
@ -1181,6 +1326,5 @@ void CTriggerThing::setTargetBox(int _x,int _y,int _w,int _h)
|
|||
m_boxY2=_y+_h;
|
||||
}
|
||||
|
||||
/*===========================================================================
|
||||
end */
|
||||
|
||||
|
||||
|
|
|
@ -84,11 +84,19 @@ private:
|
|||
static CThing *s_CollisionLists[];
|
||||
static sBBox m_RenderBBox;
|
||||
static sBBox m_ThinkBBox;
|
||||
public:
|
||||
// FreeList Stuff
|
||||
static void initFreeList();
|
||||
static void resetFreeList();
|
||||
static void shutdownFreeList();
|
||||
static CThing *GetThing(int Type,int SubType);
|
||||
static void DeleteThing(CThing *Thing);
|
||||
|
||||
// static CThing *s_FreeList[];
|
||||
|
||||
private:
|
||||
static CThing **s_FreeList[];
|
||||
};
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
// Base thing class
|
||||
class CThing
|
||||
|
@ -110,16 +118,29 @@ public:
|
|||
MAX_TYPE,
|
||||
};
|
||||
// TYPE;
|
||||
CThing() {m_isShuttingDown=false;}
|
||||
CThing()
|
||||
{
|
||||
initDef();
|
||||
m_SubType=1234;
|
||||
}
|
||||
virtual ~CThing() {;}
|
||||
|
||||
virtual void initDef()
|
||||
{
|
||||
m_isShuttingDown=false;
|
||||
NextFreeThing=0;
|
||||
}
|
||||
|
||||
virtual TYPE getThingType()=0;
|
||||
|
||||
virtual void setThingSubType(int T) {m_SubType=T;}
|
||||
virtual int getThingSubType() {return(m_SubType);}
|
||||
|
||||
virtual void init();
|
||||
virtual void shutdown();
|
||||
virtual void think(int _frames);
|
||||
virtual void render();
|
||||
void setToShutdown() {m_isShuttingDown = true;}
|
||||
void setToShutdown(bool f=true) {m_isShuttingDown = f;}
|
||||
u8 isSetToShutdown() {return( m_isShuttingDown);}
|
||||
virtual int dontKillDuringLevelRespawn() {return false;}
|
||||
|
||||
|
@ -167,8 +188,8 @@ virtual bool alwaysThink() {return(false);}
|
|||
DVECTOR const &getCollisionCentreOffset() {return m_collisionCentreOffset;}
|
||||
int getCollisionRadius() {return m_collisionRadius;}
|
||||
virtual CRECT const &getCollisionArea() {return m_collisionArea;}
|
||||
s16 getCollisionAngle() {return m_collisionAngle;} // pkg - move to CNpcPlatform?
|
||||
DVECTOR const &getNewCollidedPos() {return m_newCollidedPos;} // pkg - to be removed?
|
||||
//!Dave! s16 getCollisionAngle() {return m_collisionAngle;} // pkg - move to CNpcPlatform?
|
||||
//!Dave! DVECTOR const &getNewCollidedPos() {return m_newCollidedPos;} // pkg - to be removed?
|
||||
DVECTOR const &getCollisionSize() {return m_collisionSize;}
|
||||
|
||||
virtual int canCollide() {return true;}
|
||||
|
@ -179,8 +200,7 @@ virtual void collidedWith(CThing *_thisThing) {;}
|
|||
virtual void setHasPlatformCollided( bool newVal ) {;}
|
||||
virtual bool getHasPlatformCollided() {return false;}
|
||||
virtual s32 getNewYPos( CThing *_thisThing );
|
||||
void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;} // pkg - to be removed?
|
||||
|
||||
//!Dave! void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;} // pkg - to be removed?
|
||||
|
||||
public:
|
||||
// Thing states
|
||||
|
@ -193,24 +213,26 @@ protected:
|
|||
bool m_renderFlag,m_thinkFlag;
|
||||
DVECTOR m_RenderPos;
|
||||
bool m_isShuttingDown;
|
||||
int m_SubType;
|
||||
|
||||
protected:
|
||||
virtual void setCollisionSize(int _w,int _h);
|
||||
virtual void setCollisionCentreOffset(int _x,int _y) {m_collisionCentreOffset.vx=_x;m_collisionCentreOffset.vy=_y;}
|
||||
virtual void setCollisionCentreOffset(DVECTOR xy) {m_collisionCentreOffset=xy;}
|
||||
virtual void setCollisionAngle(int newAngle) {m_collisionAngle = newAngle;} // pkg - move to CNpcPlatform?
|
||||
//!Dave!virtual void setCollisionAngle(int newAngle) {m_collisionAngle = newAngle;} // pkg - move to CNpcPlatform?
|
||||
private:
|
||||
DVECTOR m_collisionSize;
|
||||
DVECTOR m_collisionCentreOffset;
|
||||
int m_collisionRadius;
|
||||
CRECT m_collisionArea;
|
||||
DVECTOR m_collisionCentre;
|
||||
s16 m_collisionAngle; // pkg - move to CNpcPlatform?
|
||||
DVECTOR m_newCollidedPos; // pkg - to be removed?
|
||||
//!Dave! s16 m_collisionAngle; // pkg - move to CNpcPlatform?
|
||||
//!Dave! DVECTOR m_newCollidedPos; // pkg - to be removed?
|
||||
|
||||
// Free List Stuff
|
||||
public:
|
||||
//virtual int getMaxType()=0;
|
||||
public:
|
||||
CThing *NextFreeThing;
|
||||
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------- */
|
||||
|
@ -224,6 +246,10 @@ virtual TYPE getThingType() {return TYPE_PICKUP;}
|
|||
class CPlayerThing : public CThing
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{ // For Dynamic ThingCache
|
||||
MAX_SUBTYPE =1,
|
||||
};
|
||||
virtual TYPE getThingType() {return TYPE_PLAYER;}
|
||||
virtual bool alwaysThink() {return(true);}
|
||||
|
||||
|
@ -262,9 +288,15 @@ virtual TYPE getThingType() {return TYPE_PLATFORM;}
|
|||
class CTriggerThing : public CThing
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{ // For Dynamic ThingCache
|
||||
MAX_SUBTYPE =1,
|
||||
};
|
||||
|
||||
virtual TYPE getThingType() {return TYPE_TRIGGER;}
|
||||
virtual void setPositionAndSize(int _x,int _y,int _w,int _h); // Wonder if this might be better in CThing? (pkg)
|
||||
virtual void setTargetBox(int _x,int _y,int _w,int _h); // Wonder if this might be better in CThing? (pkg)
|
||||
|
||||
protected:
|
||||
int m_boxX1,m_boxY1,m_boxX2,m_boxY2;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue