Commit 33e3821f authored by Gerhard Stein's avatar Gerhard Stein

more SmartPointers ...

parent 272eee97
......@@ -51,7 +51,8 @@
namespace galaxy
{
CVorticonMapLoaderGalaxy::CVorticonMapLoaderGalaxy(CExeFile &ExeFile, std::vector<CSpriteObject*>& ObjectPtr,
CVorticonMapLoaderGalaxy::CVorticonMapLoaderGalaxy(CExeFile &ExeFile,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtr,
CInventory &Inventory, stCheat &Cheatmode):
m_ExeFile(ExeFile),
m_ObjectPtr(ObjectPtr),
......@@ -288,11 +289,9 @@ void CVorticonMapLoaderGalaxy::spawnFoes(CMap &Map)
word height = Map.m_height;
// If objects are in the buffer clean them up
while(!m_ObjectPtr.empty())
{
delete m_ObjectPtr.back();
m_ObjectPtr.pop_back();
}
if(!m_ObjectPtr.empty())
m_ObjectPtr.clear();
// he we go to the adding objects
data_ptr = start_data;
......
......@@ -14,6 +14,7 @@
#include "common/Cheat.h"
#include "engine/galaxy/CInventory.h"
#include "common/CSpriteObject.h"
#include "SmartPointer.h"
#include <vector>
#include <string>
......@@ -25,7 +26,8 @@ namespace galaxy
class CVorticonMapLoaderGalaxy
{
public:
CVorticonMapLoaderGalaxy(CExeFile &ExeFile, std::vector<CSpriteObject*>& ObjectPtr,
CVorticonMapLoaderGalaxy(CExeFile &ExeFile,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtr,
CInventory &Inventory, stCheat &Cheatmode);
size_t getMapheadOffset();
bool gotoSignature(std::ifstream &MapFile);
......@@ -40,7 +42,7 @@ private:
word magic_word);
CExeFile &m_ExeFile;
std::vector<CSpriteObject*>& m_ObjectPtr;
std::vector< SmartPointer<CSpriteObject> > &m_ObjectPtr;
CInventory &m_Inventory;
stCheat &m_Cheatmode;
};
......
......@@ -68,7 +68,7 @@ void CMapPlayGalaxy::process(const bool msgboxactive)
{
for(size_t i=0 ; i<m_ObjectPtr.size() ; i++)
{
CSpriteObject* p_Object = m_ObjectPtr[i];
CSpriteObject* p_Object = m_ObjectPtr[i].get();
// If the Player is not only dying, but also lost it's existence, meaning he got out of the screen
// how the death-message or go gameover.
......@@ -94,7 +94,7 @@ void CMapPlayGalaxy::process(const bool msgboxactive)
// Check collision between objects
for(size_t j=0 ; j<m_ObjectPtr.size() ; j++)
{
CSpriteObject *theOtherObj = m_ObjectPtr[j];
CSpriteObject *theOtherObj = m_ObjectPtr[j].get();
if( theOtherObj != p_Object )
{
p_Object->isNearby(*theOtherObj);
......@@ -108,7 +108,7 @@ void CMapPlayGalaxy::process(const bool msgboxactive)
g_pVideoDriver->mDrawTasks.add( new BlitScrollSurfaceTask() );
std::vector<CSpriteObject*>::reverse_iterator obj;
std::vector< SmartPointer <CSpriteObject> >::reverse_iterator obj;
// Draw all the sprites without player
// The player sprites are drawn as last
......@@ -117,7 +117,7 @@ void CMapPlayGalaxy::process(const bool msgboxactive)
obj!=m_ObjectPtr.rend() ; obj++ )
{
if( galaxy::CPlayerBase* newplayer = dynamic_cast<galaxy::CPlayerBase*>(*obj) )
if( galaxy::CPlayerBase* newplayer = dynamic_cast<galaxy::CPlayerBase*>(obj->get()) )
{
player = newplayer;
continue;
......@@ -166,14 +166,3 @@ void CMapPlayGalaxy::operator<<(CSaveGameController &savedGame)
{
}
CMapPlayGalaxy::~CMapPlayGalaxy()
{
while(!m_ObjectPtr.empty())
{
delete m_ObjectPtr.back();
m_ObjectPtr.pop_back();
}
}
......@@ -23,13 +23,13 @@
#include "sdl/CVideoDriver.h"
#include "sdl/music/CMusic.h"
#include "StringUtils.h"
#include "SmartPointer.h"
#include <vector>
#include <list>
class CMapPlayGalaxy {
public:
CMapPlayGalaxy(CExeFile &ExeFile, CInventory &Inventory, stCheat &Cheatmode);
~CMapPlayGalaxy();
bool isActive();
void setActive(const bool value);
......@@ -49,7 +49,7 @@ public:
protected:
std::vector<CSpriteObject*> m_ObjectPtr;
std::vector< SmartPointer<CSpriteObject> > m_ObjectPtr;
bool m_active;
CMap m_Map;
......
......@@ -9,6 +9,7 @@
#include "CItemEffect.h"
#include "sdl/input/CInput.h"
#include "sdl/sound/CSound.h"
#include "SmartPointer.h"
namespace galaxy {
......@@ -16,7 +17,7 @@ CPlayerBase::CPlayerBase(
CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> >& ObjectPtrs,
direction_t facedir,
CInventory &l_Inventory,
stCheat &Cheatmode) :
......
......@@ -21,6 +21,7 @@
#include "common/Cheat.h"
#include "engine/CCamera.h"
#include "engine/galaxy/CInventory.h"
#include "SmartPointer.h"
namespace galaxy
{
......@@ -39,7 +40,7 @@ public:
CPlayerBase(CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> >& ObjectPtrs,
direction_t facedir,
CInventory &l_Inventory,
stCheat &Cheatmode);
......@@ -94,7 +95,7 @@ protected:
unsigned short mPlayerNum;
std::vector<CSpriteObject*>& m_ObjectPtrs;
std::vector< SmartPointer<CSpriteObject> >& m_ObjectPtrs;
Sint16 m_playcontrol[PA_MAX_ACTIONS];
int m_timer;
......
......@@ -34,7 +34,7 @@ const int FIRE_RECHARGE_TIME = 5;
CPlayerLevel::CPlayerLevel(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs, direction_t facedir,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs, direction_t facedir,
CInventory &l_Inventory, stCheat &Cheatmode) :
CPlayerBase(pmap, x, y, ObjectPtrs, facedir, l_Inventory, Cheatmode),
m_jumpdownfromobject(false)
......@@ -64,7 +64,7 @@ void CPlayerLevel::processMoveBitDown()
{
if(m_ObjectPtrs[i]->hitdetect(*this))
{
if( CPlatform *platform = dynamic_cast<CPlatform*>(m_ObjectPtrs[i]) )
if( CPlatform *platform = dynamic_cast<CPlatform*>(m_ObjectPtrs[i].get()) )
{
platform->getTouchedBy(*this);
}
......
......@@ -50,7 +50,7 @@ namespace galaxy {
class CPlayerLevel : public CPlayerBase {
public:
CPlayerLevel(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs, direction_t facedir,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs, direction_t facedir,
CInventory &l_Inventory, stCheat &Cheatmode);
......
......@@ -22,7 +22,7 @@ namespace galaxy {
CPlayerWM::CPlayerWM(CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs,
CInventory &l_Inventory,
stCheat &Cheatmode):
CPlayerBase(pmap, x, y,
......
......@@ -17,7 +17,7 @@ public:
CPlayerWM(CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs,
CInventory &l_Inventory,
stCheat &Cheatmode);
......
......@@ -16,7 +16,7 @@ namespace galaxy {
const int MAX_ANIMATION_TIMER = 20;
CSpriteItem::CSpriteItem(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs, Uint32 sprite) :
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs, Uint32 sprite) :
CGalaxySpriteObject(pmap, x, y),
m_ObjectPtrs(ObjectPtrs)
{
......
......@@ -13,6 +13,7 @@
#define CSPRITEITEM_H_
#include "engine/galaxy/CGalaxySpriteObject.h"
#include "SmartPointer.h"
namespace galaxy {
......@@ -21,14 +22,14 @@ class CSpriteItem : public CGalaxySpriteObject
{
public:
CSpriteItem(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs, Uint32 sprite);
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs, Uint32 sprite);
void process();
void getTouchedBy(CSpriteObject &theObject);
private:
int m_timer;
Uint32 m_basesprite;
std::vector<CSpriteObject*>& m_ObjectPtrs;
std::vector< SmartPointer<CSpriteObject> > &m_ObjectPtrs;
};
}
......
......@@ -15,7 +15,7 @@ namespace galaxy {
CPlayerDive::CPlayerDive(CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs,
direction_t facedir,
CInventory &l_Inventory,
stCheat &Cheatmode) :
......
......@@ -20,7 +20,7 @@ public:
CPlayerDive(CMap *pmap,
Uint32 x,
Uint32 y,
std::vector<CSpriteObject*>& ObjectPtrs,
std::vector< SmartPointer<CSpriteObject> > &ObjectPtrs,
direction_t facedir,
CInventory &l_Inventory,
stCheat &Cheatmode);
......
......@@ -18,7 +18,7 @@ const int SLUG_MOVE_SPEED = 1;
const int SLUG_MOVE_TIMER = 10;
CPoisonSlug::CPoisonSlug(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>&ObjectPtrs) :
std::vector< SmartPointer<CSpriteObject> >&ObjectPtrs) :
CGalaxySpriteObject(pmap, x, y),
CStunnable(pmap, x, y),
m_ObjectPtrs(ObjectPtrs),
......
......@@ -20,10 +20,11 @@ namespace galaxy {
#define A_SLUG_STUNNED 3
#define A_SLUG_STUNNED_ALT 4
class CPoisonSlug : public CStunnable {
class CPoisonSlug : public CStunnable
{
public:
CPoisonSlug(CMap *pmap, Uint32 x, Uint32 y,
std::vector<CSpriteObject*>&ObjectPtrs);
std::vector< SmartPointer<CSpriteObject> >&ObjectPtrs);
/**
* When slug is moving normally
......@@ -45,7 +46,7 @@ public:
void getTouchedBy(CSpriteObject &theObject);
private:
std::vector<CSpriteObject*>& m_ObjectPtrs;
std::vector< SmartPointer<CSpriteObject> > &m_ObjectPtrs;
int m_timer;
};
......
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