Commit ae6bdcc7 authored by Gerhard Stein's avatar Gerhard Stein

Spawn Object function should now compile correctly

parent b3895bff
......@@ -28,6 +28,8 @@
#include "engine/CEventContainer.h"
#include "common/options.h"
#include <lib/base/GsEvent.h>
#include "CSingleton.h"
#if defined (SINGLEPLAYER)
......
......@@ -346,7 +346,7 @@ void CPlayer::TogglePogo_and_Switches()
// spawn a "sector effector" to extend/retract the platform
CBridges *platobject = new CBridges(mp_Map, mx<<CSF, my<<CSF,
platx, platy);
g_pBehaviorEngine->EventList().spawnObj(platobject);
spawnObj(platobject);
}
ppogostick = false;
......
......@@ -452,3 +452,9 @@ CSpriteObject::~CSpriteObject()
m_number_of_objects--;
}
void spawnObj(const CSpriteObject *obj)
{
gEventManager.add(new EventSpawnObject( obj ));
}
......@@ -12,7 +12,8 @@
#ifndef __CSPRITEOBJECT_H_
#define __CSPRITEOBJECT_H_
#include "engine/CEventContainer.h"
#include <lib/base/GsEvent.h>
#include "ActionFormat.h"
#include "CVec.h"
#include "direction.h"
......@@ -100,6 +101,9 @@ struct ObjMoveCouples : ObjMove
};
// Small special routine for spawning objects. Might be called by other objects and the level manager
void spawnObj(const CSpriteObject *obj);
class CSpriteObject
{
public:
......
......@@ -10,7 +10,9 @@
#ifndef CEVENTCONTAINER_H_
#define CEVENTCONTAINER_H_
#include "CEvent.h"
#include <lib/base/GsEvent.h>
/*#include "CEvent.h"
#include <deque>
#include <vector>
#include <ctime>
......@@ -27,7 +29,7 @@ public:
size_t size() { return m_EventList.size(); }
bool empty() { return m_EventList.empty(); }
void clear() { m_EventList.clear(); }
void clear() { m_EventList.clear(); }*/
/**
* @brief regSink will register the sink in the Container
......@@ -35,7 +37,7 @@ public:
* Otherwise app might crash.
* @param pSink pointer to the sink to be registered
*/
void regSink(GsEventSink *pSink)
/*void regSink(GsEventSink *pSink)
{
mSinkPtrList.push_back(pSink);
}
......@@ -129,6 +131,5 @@ T* CEventContainer::occurredEvent()
return dynamic_cast<T*> (m_EventList.front().get());
}
*/
#endif /* CEVENTCONTAINER_H_ */
......@@ -339,7 +339,7 @@ void CPlayerBase::processLevelMiscFlagsCheck()
const int lc_y = l_y>>CSF;
mp_Map->setTile( lc_x, lc_y, 0, true, 1 );
CItemEffect *iEffect = new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, dropanimation_sprite, ANIMATE);
g_pBehaviorEngine->m_EventList.spawnObj( iEffect );
spawnObj( iEffect );
m_Item.m_drops++;
if(m_Item.m_drops >= 100)
......@@ -362,7 +362,7 @@ void CPlayerBase::processLevelMiscFlagsCheck()
const int ep = g_pBehaviorEngine->getEpisode();
mp_Map->setTile( lc_x, lc_y, 0, true, 1 );
g_pBehaviorEngine->m_EventList.spawnObj( new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, got_sprite_item_pics[ep-4][4+i-21], FADEOUT) );
spawnObj( new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, got_sprite_item_pics[ep-4][4+i-21], FADEOUT) );
switch(i)
{
case 21: m_Item.m_points += 100; g_pSound->playSound( SOUND_GET_BONUS ); break;
......@@ -487,7 +487,7 @@ void CPlayerBase::respawnImportantItem(const int itemId)
if(itemId == 4)
{
VectorD2<int> where = mp_Map->getSpriteOrigin(105);
g_pBehaviorEngine->m_EventList.spawnObj( new galaxy::CSpriteItem(mp_Map, 0x46, where.x, where.y, 105, 0) );
spawnObj( new galaxy::CSpriteItem(mp_Map, 0x46, where.x, where.y, 105, 0) );
return;
}
}
......@@ -501,7 +501,7 @@ void CPlayerBase::respawnImportantItem(const int itemId)
// Now respawn the item
VectorD2<int> where = mp_Map->getSpriteOrigin(itemId+itemOffset);
g_pBehaviorEngine->m_EventList.spawnObj( new galaxy::CSpriteItem(mp_Map, itemId+itemOffset, where.x, where.y, newsprite, 0) );
spawnObj( new galaxy::CSpriteItem(mp_Map, itemId+itemOffset, where.x, where.y, newsprite, 0) );
}
......
......@@ -641,7 +641,7 @@ void CPlayerLevel::tryToShoot( const VectorD2<int> &pos, const int xDir, const i
{
if(m_Inventory.Item.m_bullets > 0)
{
g_pBehaviorEngine->m_EventList.spawnObj(new CBullet(mp_Map, 0, pos.x, pos.y, xDir, yDir, mSprVar));
spawnObj(new CBullet(mp_Map, 0, pos.x, pos.y, xDir, yDir, mSprVar));
m_Inventory.Item.m_bullets--;
}
else
......@@ -1542,7 +1542,7 @@ void CPlayerLevel::processPressUp() {
//check_ground(new_object, ACTION_SECURITYDOOROPEN);
//o->action = ACTION_KEENENTERDOOR0;
//o->int16 = 0;
g_pBehaviorEngine->EventList().spawnObj( new CSecurityDoor(getMapPtr(), 0, x_left-(1<<CSF), up_y-(3<<CSF) ) );
spawnObj( new CSecurityDoor(getMapPtr(), 0, x_left-(1<<CSF), up_y-(3<<CSF) ) );
mTarget = getPosition();
mTarget.y -= (1<<CSF);
......
......@@ -308,7 +308,7 @@ void CPlayerWM::processMoving()
x = x>>CSF; y = y>>CSF;
x = x<<CSF; y = (y+climbDir)<<CSF;
g_pBehaviorEngine->m_EventList.spawnObj(new CRope(mp_Map, x, y));
spawnObj(new CRope(mp_Map, x, y));
playSound(SOUND_ROPE_THROW);
}
else
......@@ -1016,7 +1016,7 @@ bool CPlayerWM::finishLevel(const int object)
CFlag *pFlag = new CFlag(mp_Map, src, dst, mSprVar, true, true);
g_pBehaviorEngine->m_EventList.spawnObj(pFlag);
spawnObj(pFlag);
// Mark the tileinfo on the map as level finished!! So player cannot just re-enter. Exception is if replayability is on.
......
......@@ -146,7 +146,7 @@ void CSpriteItem::getTouchedBy(CSpriteObject &theObject)
g_pSound->playSound( SOUND_GET_GEM );
}
g_pBehaviorEngine->m_EventList.spawnObj(new CItemEffect(mp_Map, 0, getXPosition(), getYPosition(), newanimsprite, FADEOUT));
spawnObj(new CItemEffect(mp_Map, 0, getXPosition(), getYPosition(), newanimsprite, FADEOUT));
exists = false;
}
......
......@@ -104,7 +104,7 @@ bool CThunderCloud::isNearby(CSpriteObject &theObject)
setAction(A_CLOUD_STRIKING);
playSound(SOUND_THUNDERCLOUD_STRIKE);
mpBolt = new CThunderBolt( mp_Map, getXLeftPos() + (12<<STC), getYDownPos() + (32<<STC), mSprVar );
g_pBehaviorEngine->m_EventList.spawnObj( mpBolt );
spawnObj( mpBolt );
}
}
}
......
......@@ -207,7 +207,7 @@ void CTreasureEater::checkForItem()
const int ep = g_pBehaviorEngine->getEpisode();
mp_Map->setTile( lc_x, lc_y, 0, true, 1 );
g_pBehaviorEngine->m_EventList.spawnObj( new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, got_sprite_item_pics[ep-4][4+i-21], FADEOUT) );
spawnObj( new CItemEffect(mp_Map, 0, lc_x<<CSF, lc_y<<CSF, got_sprite_item_pics[ep-4][4+i-21], FADEOUT) );
mStolen = true;
}
......
......@@ -122,7 +122,7 @@ void CRoboRed::processShoot()
swapYDir = !swapYDir;
int newX = xDirection == RIGHT ? getXRightPos() : getXLeftPos();
int newY = getYPosition() + 0x300;
g_pBehaviorEngine->m_EventList.spawnObj( new CRedShot( getMapPtr(),
spawnObj( new CRedShot( getMapPtr(),
0,
newX, newY,
newXDir, newYDir ) );
......
......@@ -163,13 +163,13 @@ void CShelly::processSmoke()
const int newX = getXMidPos();
const int newY = getYUpPos();
g_pBehaviorEngine->m_EventList.spawnObj( new CShellyFrags( getMapPtr(),
spawnObj( new CShellyFrags( getMapPtr(),
0, newX, newY, -100 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CShellyFrags( getMapPtr(),
spawnObj( new CShellyFrags( getMapPtr(),
0, newX, newY, -50 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CShellyFrags( getMapPtr(),
spawnObj( new CShellyFrags( getMapPtr(),
0, newX, newY, 50 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CShellyFrags( getMapPtr(),
spawnObj( new CShellyFrags( getMapPtr(),
0, newX, newY, 100 ) );
exists = false;
}
......
......@@ -104,7 +104,7 @@ void CShikadi::processWalking()
{
newX = (newX>>CSF)<<CSF;
// Spawn a Enemyshot in form electrostatic charge which goes upwards
g_pBehaviorEngine->m_EventList.spawnObj( new CEnemyShot(mp_Map, 0,
spawnObj( new CEnemyShot(mp_Map, 0,
newX, getYUpPos(),
0x2E5A, 0, UP, 150, mSprVar) );
setAction(A_SHIKADI_POLE_ZAPS);
......
......@@ -81,7 +81,7 @@ void CShikadiMaster::processStanding()
// ... and spawn a shot that might hurt Keen
const int newX = (xDirection == LEFT) ? getXLeftPos()+(4<<STC) : getXRightPos()-(4<<STC);
g_pBehaviorEngine->m_EventList.spawnObj( new CEnemyShot(mp_Map, 0,
spawnObj( new CEnemyShot(mp_Map, 0,
newX, getYUpPos()+(8<<STC),
0x2C3E, xDirection, CENTER, 150, mSprVar) );
......
......@@ -293,13 +293,13 @@ void CShikadiMine::processDetonate()
const int newX = getXMidPos();
const int newY = getYUpPos();
g_pBehaviorEngine->m_EventList.spawnObj( new CMineShards( getMapPtr(),
spawnObj( new CMineShards( getMapPtr(),
0, newX, newY, -100 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CMineShards( getMapPtr(),
spawnObj( new CMineShards( getMapPtr(),
0, newX, newY, -50 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CMineShards( getMapPtr(),
spawnObj( new CMineShards( getMapPtr(),
0, newX, newY, 50 ) );
g_pBehaviorEngine->m_EventList.spawnObj( new CMineShards( getMapPtr(),
spawnObj( new CMineShards( getMapPtr(),
0, newX, newY, 100 ) );
}
......
......@@ -110,7 +110,7 @@ void CShockshound::processBark()
{
// Spawn a Enemyshot in form electrostatic
const int newX = (xDirection == LEFT) ? getXLeftPos()+(4<<STC) : getXRightPos()-(4<<STC);
g_pBehaviorEngine->m_EventList.spawnObj( new CEnemyShot(mp_Map, 0,
spawnObj( new CEnemyShot(mp_Map, 0,
newX, getYUpPos()-(8<<STC),
0x2FC2, xDirection, CENTER, 150, mSprVar) );
......
......@@ -100,7 +100,7 @@ void CBabobba::processSitting()
CCinder *cinder = new CCinder(mp_Map, 0,
getXMidPos(), getYUpPos(), xDirection, mSprVar);
g_pBehaviorEngine->m_EventList.spawnObj( cinder );
spawnObj( cinder );
}
setAction(A_BABOBBA_NAPPING);
......
......@@ -77,7 +77,7 @@ void CBipShip::processMoving()
CEnemyShot *laser = new CEnemyShot(mp_Map, 0, x_coord, getYMidPos()-(8<<STC),
0x2A7A, xDirection, 0, 100, mSprVar);
g_pBehaviorEngine->m_EventList.spawnObj( laser );
spawnObj( laser );
mKeenIsNear = false;
}
}
......@@ -103,7 +103,7 @@ void CBipShip::processHit()
const int newX = getXMidPos();
const int newY = getYUpPos();
auto *bip = new CBip(mp_Map, 0x6C, newX, newY);
g_pBehaviorEngine->m_EventList.spawnObj( bip );
spawnObj( bip );
setAction(A_BIPSHIP_WRECKAGE);
}
}
......
......@@ -64,7 +64,7 @@ void CBlooglet::getTouchedBy(CSpriteObject &theObject)
const Uint32 newSprite = 118+2*( mFoeID-0xB );
auto *gem = new CSpriteItem(mp_Map, mFoeID+0x2E, newX, newY, newSprite, 0,true);
gem->honorPriority = false;
g_pBehaviorEngine->m_EventList.spawnObj( gem );
spawnObj( gem );
playSound(SOUND_JUMPED_GEM);
}
......
......@@ -82,7 +82,7 @@ void CBobba::processSitting()
CEnemyShot *fireball = new CEnemyShot(mp_Map, 0, x_coord, getYUpPos(),
0x2E76, xDirection, 0, 100, mSprVar);
g_pBehaviorEngine->m_EventList.spawnObj( fireball );
spawnObj( fireball );
}
......
......@@ -221,7 +221,7 @@ void COrbatrix::getTouchedBy(CSpriteObject& theObject)
{
stItemGalaxy &Item = player->m_Inventory.Item;
Item.m_gem.red++;
g_pBehaviorEngine->m_EventList.spawnObj(new CItemEffect(mp_Map, 0, getXPosition(), getYPosition(), got_sprite_item_pics[2][2], FADEOUT));
spawnObj(new CItemEffect(mp_Map, 0, getXPosition(), getYPosition(), got_sprite_item_pics[2][2], FADEOUT));
dead = true;
exists = false;
}
......
......@@ -66,7 +66,7 @@ void CAutoRay::process()
NewRay->sprite = ENEMYRAYEP3;
NewRay->m_HorDir = RIGHT;
}
g_pBehaviorEngine->EventList().spawnObj(NewRay);
spawnObj(NewRay);
if(!silent)
{
......
......@@ -65,7 +65,7 @@ void CIceCannon::process()
silent = true;
}
g_pBehaviorEngine->EventList().spawnObj(chunk);
spawnObj(chunk);
mTimer = 0;
}
else
......@@ -192,19 +192,19 @@ void CIceChunk::smash()
// upleft
chunk = new CIceBit(mp_Map, getXPosition(), getYPosition(), -1, -1);
g_pBehaviorEngine->EventList().spawnObj(chunk);
spawnObj(chunk);
// upright
chunk = new CIceBit(mp_Map, getXPosition(), getYPosition(), 1, -1);
g_pBehaviorEngine->EventList().spawnObj(chunk);
spawnObj(chunk);
// downleft
chunk = new CIceBit(mp_Map, getXPosition(), getYPosition(), -1, 1);
g_pBehaviorEngine->EventList().spawnObj(chunk);
spawnObj(chunk);
// downright
chunk = new CIceBit(mp_Map, getXPosition(), getYPosition(), 1, 1);
g_pBehaviorEngine->EventList().spawnObj(chunk);
spawnObj(chunk);
}
exists = false;
}
......
......@@ -358,7 +358,7 @@ void CManglingMachine::se_mortimer_spark()
CRay *newobject = new CRay(mp_Map, ((mx<<4)+4)<<STC, my<<4<<STC, CENTER, DOWN, getSpriteVariantId());
newobject->state = CRay::RAY_STATE_SETZAPZOT;
newobject->inhibitfall = true;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
}
mx = MORTIMER_RIGHT_ARM_X+x;
......@@ -369,7 +369,7 @@ void CManglingMachine::se_mortimer_spark()
CRay *newobject = new CRay(mp_Map, ((mx<<4)+4)<<STC, my<<4<<STC, CENTER, DOWN, getSpriteVariantId());
newobject->state = CRay::RAY_STATE_SETZAPZOT;
newobject->inhibitfall = true;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
}
}
......@@ -418,7 +418,7 @@ void CManglingMachine::se_mortimer_heart(CVorticonSpriteObject *obj)
}
else counter++;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
}
else timer--;
break;
......@@ -433,7 +433,7 @@ void CManglingMachine::se_mortimer_heart(CVorticonSpriteObject *obj)
CRay *newobject = new CRay(mp_Map, ((x<<4)+4)<<STC, my<<4<<STC, CENTER, DOWN, getSpriteVariantId());
newobject->state = CRay::RAY_STATE_SETZAPZOT;
newobject->inhibitfall = true;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
}
timer = MACHINE_DESTROY_RATE;
......@@ -532,7 +532,7 @@ void CManglingMachine::se_mortimer_zapsup()
CRay *newobject = new CRay(mp_Map, ((x<<4)+4)<<STC, (my+1)<<CSF, CENTER, DOWN, getSpriteVariantId());
newobject->state = CRay::RAY_STATE_SETZAPZOT;
newobject->inhibitfall = true;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
if (destroytiles)
{
......@@ -761,7 +761,7 @@ void CManglingMachine::se_mortimer_randomzaps()
CRay *newobject = new CRay(mp_Map,x<<CSF, y<<CSF, RIGHT, CENTER, getSpriteVariantId() );
newobject->state = CRay::RAY_STATE_SETZAPZOT;
newobject->inhibitfall = true;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
timer = TIME_BETWEEN_ZAPS;
if (counter > NUM_RANDOM_ZAPS)
......
......@@ -168,7 +168,7 @@ void CMeep::process()
newobject = new CSoundWave(mp_Map, getXLeftPos(), getYPosition()+(5<<STC), LEFT);
newobject->setOwner(OBJ_MEEP, m_index);
newobject->solid = false;
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
playSound(SOUND_MEEP);
state = MEEP_WALK;
}
......
......@@ -258,7 +258,7 @@ void CVorticonElite::process()
newobject->setOwner( m_type, m_index);
newobject->sprite = ENEMYRAYEP2;
// don't shoot other vorticon elite
g_pBehaviorEngine->EventList().spawnObj(newobject);
spawnObj(newobject);
if (onscreen)
playSound(SOUND_KEEN_FIRE);
......
#ifndef __GSEVENT_H_
#define __GSEVENT_H_
#include <base/Singleton.h>
#include <ctime>
#include <vector>
#include <deque>
#include <list>
#include <memory>
struct CEvent { virtual ~CEvent() {} };
/**
......@@ -12,4 +19,115 @@ public:
virtual void pumpEvent(const CEvent *ev) = 0;
};
class CEventContainer : public GsSingleton<CEventContainer>
{
public:
CEventContainer() :
pausetime(0),
timepoint(0)
{}
size_t size() { return m_EventList.size(); }
bool empty() { return m_EventList.empty(); }
void clear() { m_EventList.clear(); }
/**
* @brief regSink will register the sink in the Container
* when you are destroying the object, you must call unregSink() first!
* Otherwise app might crash.
* @param pSink pointer to the sink to be registered
*/
void regSink(GsEventSink *pSink)
{
mSinkPtrList.push_back(pSink);
}
void unregSink(GsEventSink *pSink)
{
// TODO: Code for unregistering the Sink
}
void processSinks()
{
// First check if there are pendingEvents to be processed
if(m_EventList.empty())
return;
// Make a copy of that list, because the original
// could change, while pumping happens
for(auto &ev : m_EventList)
mPumpEventPtrs.push_back(ev);
// We don't need anything from this list anymore
m_EventList.clear();
for( GsEventSink* sink : mSinkPtrList )
{
for( auto &event : mPumpEventPtrs )
{
sink->pumpEvent( event.get() );
}
}
mPumpEventPtrs.clear();
}
void add(std::shared_ptr<CEvent>& ev)
{
m_EventList.push_back(ev);
}
void add(CEvent *ev)
{
m_EventList.push_back(std::shared_ptr<CEvent>(ev));
}
void wait(const float time)
{
timepoint = clock();
pausetime = static_cast<clock_t>(time*static_cast<float>(CLOCKS_PER_SEC));
}
void update()
{
if(pausetime<=0.0f)
return;
const clock_t newTime = clock();
const clock_t passed = newTime-timepoint;
timepoint = newTime;
pausetime -= passed;
return;
}
std::deque< std::shared_ptr<CEvent> >::iterator erase(std::deque< std::shared_ptr<CEvent> >::iterator &it)
{ return m_EventList.erase(it); }
std::deque< std::shared_ptr<CEvent> >::iterator begin() { return m_EventList.begin(); }
std::deque< std::shared_ptr<CEvent> >::iterator end() { return m_EventList.end(); }
template<typename T> T* occurredEvent();
void pop_Event() { m_EventList.pop_front(); }
private:
std::list< GsEventSink* > mSinkPtrList;
std::deque< std::shared_ptr<CEvent> > m_EventList;
std::vector< std::shared_ptr<CEvent> > mPumpEventPtrs;
clock_t pausetime;
clock_t timepoint;
};
template<typename T>
T* CEventContainer::occurredEvent()
{
if(m_EventList.empty() || pausetime > 0 )
return NULL;
return dynamic_cast<T*> (m_EventList.front().get());
}
#define gEventManager CEventContainer::get()
#endif /* __GSEVENT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment