From ac738ee24b5e55fc66644436d0b63a1d0db1b530 Mon Sep 17 00:00:00 2001 From: Daveo Date: Thu, 10 May 2001 21:09:23 +0000 Subject: [PATCH] --- source/thing/thing.cpp | 100 ++++++++++++++++++++++------------------- source/thing/thing.h | 2 + 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/source/thing/thing.cpp b/source/thing/thing.cpp index bfb344c25..128fff2ee 100644 --- a/source/thing/thing.cpp +++ b/source/thing/thing.cpp @@ -54,6 +54,16 @@ Vars ---- */ +static int s_RenderBBoxX0=0; +static int s_RenderBBoxX1=512; +static int s_RenderBBoxY0=0; +static int s_RenderBBoxY1=256; +static int s_ThinkBBoxX0=0-256; +static int s_ThinkBBoxX1=512+526; +static int s_ThinkBBoxY0=0-128; +static int s_ThinkBBoxY1=256+128; + + CThing *CThingManager::s_thingLists[CThing::MAX_TYPE];//={NULL,NULL}; CThing *CThingManager::s_CollisionLists[CThing::MAX_TYPE]; int CThingManager::s_initialised=false; @@ -61,6 +71,7 @@ int CThingManager::s_initialised=false; sBBox CThingManager::m_RenderBBox; sBBox CThingManager::m_ThinkBBox; + /*---------------------------------------------------------------------- Function: Purpose: @@ -147,8 +158,17 @@ void CThingManager::killAllThingsForRespawn() Params: Returns: ---------------------------------------------------------------------- */ +bool FO=false; void CThingManager::thinkAllThings(int _frames) { +// Setup Screen BBox's +DVECTOR const &CamPos=CLevel::getCameraPos(); + + m_ThinkBBox.XMin=s_ThinkBBoxX0+CamPos.vx; + m_ThinkBBox.XMax=s_ThinkBBoxX1+CamPos.vx; + m_ThinkBBox.YMin=s_ThinkBBoxY0+CamPos.vy; + m_ThinkBBox.YMax=s_ThinkBBoxY1+CamPos.vy; + int i; CThing *thing; CThing *thing1,*thing2; @@ -158,8 +178,20 @@ void CThingManager::thinkAllThings(int _frames) thing=s_thingLists[i]; while(thing) { - thing->think(_frames); - thing->updateCollisionArea(); + // Check If in Thinkable range + CRECT const &ThingRect= thing->getCollisionArea(); + bool Flag=true; + // Will speed this up + + if (ThingRect.x2m_ThinkBBox.XMax) Flag=false; + if (ThingRect.y2m_ThinkBBox.YMax) Flag=false; + thing->setThinkFlag(Flag); + + if (Flag) + { + thing->think(_frames); + thing->updateCollisionArea(); + } thing=thing->m_nextListThing; } } @@ -180,10 +212,8 @@ void CThingManager::thinkAllThings(int _frames) while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { - thing1->collidedWith(thing2); } thing1=thing1->m_nextListThing; @@ -194,8 +224,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -207,8 +236,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -220,8 +248,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -233,8 +260,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -246,8 +272,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -259,8 +284,7 @@ void CThingManager::thinkAllThings(int _frames) thing2=s_thingLists[CThing::TYPE_PLAYER]; while(thing1&&thing2) { - if(thing1->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -274,9 +298,7 @@ void CThingManager::thinkAllThings(int _frames) { while(thing2) { - if(thing1->canCollide()&& - thing2->canCollide()&& - thing1->checkCollisionAgainst(thing2, _frames)) + if(thing1->canCollide()&& thing2->canCollide() && thing1->checkCollisionAgainst(thing2, _frames)) { thing1->collidedWith(thing2); } @@ -295,9 +317,7 @@ void CThingManager::thinkAllThings(int _frames) { if ( thing1 != thing2 ) { - if ( thing1->canCollide() && - thing2->canCollide() && - thing1->checkCollisionAgainst( thing2, _frames ) ) + if ( thing1->canCollide() && thing2->canCollide() && thing1->checkCollisionAgainst( thing2, _frames ) ) { thing1->collidedWith( thing2 ); //thing2->collidedWith( thing1 ); @@ -320,9 +340,7 @@ void CThingManager::thinkAllThings(int _frames) { if ( thing1 != thing2 ) { - if ( thing1->canCollide() && - thing2->canCollide() && - thing1->checkCollisionAgainst( thing2, _frames ) ) + if ( thing1->canCollide() && thing2->canCollide() && thing1->checkCollisionAgainst( thing2, _frames ) ) { thing1->collidedWith( thing2 ); //thing2->collidedWith( thing1 ); @@ -335,6 +353,7 @@ void CThingManager::thinkAllThings(int _frames) thing1 = thing1->m_nextListThing; } +// Shut emm down, sh sh shut em down, we shutem down for(i=0;irender(); @@ -556,6 +559,8 @@ void CThing::think(int _frames) PosDelta.vx=Pos.vx-PosLast.vx; PosDelta.vy=Pos.vy-PosLast.vy; PosLast=Pos; + + } /*---------------------------------------------------------------------- @@ -577,7 +582,7 @@ int showthings=false; void CThing::render() { // Check Is Onscreen -CRECT const &collisionRect = getCollisionArea(); +CRECT const &ThingRect= getCollisionArea(); sBBox &ScrBBox=CThingManager::getRenderBBox(); DVECTOR const &CamPos=CLevel::getCameraPos(); @@ -586,8 +591,8 @@ DVECTOR const &CamPos=CLevel::getCameraPos(); // Will speed this up m_renderFlag=true; - if (collisionRect.x2ScrBBox.XMax) m_renderFlag=false; - if (collisionRect.y2ScrBBox.YMax) m_renderFlag=false; + if (ThingRect.x2ScrBBox.XMax) m_renderFlag=false; + if (ThingRect.y2ScrBBox.YMax) m_renderFlag=false; /***/ #ifdef SHOW_BBOX @@ -1007,3 +1012,4 @@ void CTriggerThing::setTargetBox(int _x,int _y,int _w,int _h) /*=========================================================================== end */ + diff --git a/source/thing/thing.h b/source/thing/thing.h index 50ead1628..febe5bda4 100644 --- a/source/thing/thing.h +++ b/source/thing/thing.h @@ -165,6 +165,8 @@ virtual bool getHasPlatformCollided() {return false;} virtual s32 getNewYPos( CThing *_thisThing ); void setNewCollidedPos(DVECTOR newPos) {m_newCollidedPos = newPos;} // pkg - to be removed? + void setRenderFlag(bool f) {m_renderFlag=f;} + void setThinkFlag(bool f) {m_thinkFlag=f;} bool canRender() {return (m_renderFlag);} DVECTOR &getRenderPos() {return(m_RenderPos);} bool canThink() {return (m_thinkFlag);}