mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- Titi, fixed the remove object so its done in the Object destructor (using an interface)
This commit is contained in:
parent
02979a7430
commit
2357e2cfd1
@ -90,6 +90,8 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
||||
speed= sNormal;
|
||||
showFullConsole= false;
|
||||
|
||||
Object::setStateCallback(&gui);
|
||||
|
||||
Logger &logger= Logger::getInstance();
|
||||
logger.showProgress();
|
||||
|
||||
@ -99,6 +101,7 @@ Game::Game(Program *program, const GameSettings *gameSettings):
|
||||
Game::~Game() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Object::setStateCallback(NULL);
|
||||
thisGamePtr = NULL;
|
||||
if(originalDisplayMsgCallback != NULL) {
|
||||
NetworkInterface::setDisplayMessageFunction(originalDisplayMsgCallback);
|
||||
|
@ -993,7 +993,7 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::removeObject(Object* o){
|
||||
void Gui::removingObjectEvent(Object* o){
|
||||
if(getSelectedResourceObject()==o){
|
||||
selectedResourceObject=NULL;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
/// In game GUI
|
||||
// =====================================================
|
||||
|
||||
class Gui{
|
||||
class Gui : public ObjectStateInterface {
|
||||
public:
|
||||
static const int maxSelBuff= 128*5;
|
||||
static const int upgradeDisplayIndex= 8;
|
||||
@ -143,6 +143,9 @@ public:
|
||||
void init(Game *game);
|
||||
void end();
|
||||
|
||||
// callback when tileset objects are removed from the world
|
||||
virtual void removingObjectEvent(Object* o) ;
|
||||
|
||||
//get
|
||||
Vec2i getPosObjWorld() const {return posObjWorld;}
|
||||
const UnitType *getBuilding() const;
|
||||
@ -151,7 +154,6 @@ public:
|
||||
const Display *getDisplay() const {return &display;}
|
||||
const Selection *getSelection() const {return &selection;}
|
||||
const Object *getSelectedResourceObject() const {return selectedResourceObject;}
|
||||
void removeObject(Object* o) ;
|
||||
|
||||
const SelectionQuad *getSelectionQuad() const {return &selectionQuad;}
|
||||
CardinalDir getSelectedFacing() const {return selectedBuildingFacing;}
|
||||
|
@ -26,6 +26,7 @@ using namespace Shared::Util;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
ObjectStateInterface *Object::stateCallback=NULL;
|
||||
|
||||
// =====================================================
|
||||
// class Object
|
||||
@ -49,7 +50,10 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) {
|
||||
Object::~Object(){
|
||||
Renderer &renderer= Renderer::getInstance();
|
||||
renderer.removeObjectFromQuadCache(this);
|
||||
//renderer.getGame()->getGui()->removeObject(this);
|
||||
if(stateCallback) {
|
||||
stateCallback->removingObjectEvent(this);
|
||||
//renderer.getGame()->getGui()->removeObject(this);
|
||||
}
|
||||
delete resource;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,13 @@ using Shared::Graphics::Vec3f;
|
||||
/// A map object: tree, stone...
|
||||
// =====================================================
|
||||
|
||||
class Object;
|
||||
|
||||
class ObjectStateInterface {
|
||||
public:
|
||||
virtual void removingObjectEvent(Object *object) = 0;
|
||||
};
|
||||
|
||||
class Object {
|
||||
private:
|
||||
ObjectType *objectType;
|
||||
@ -41,10 +48,14 @@ private:
|
||||
int lastRenderFrame;
|
||||
Vec2i mapPos;
|
||||
|
||||
static ObjectStateInterface *stateCallback;
|
||||
|
||||
public:
|
||||
Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos);
|
||||
~Object();
|
||||
|
||||
static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; }
|
||||
|
||||
void setHeight(float height) {pos.y= height;}
|
||||
|
||||
const ObjectType *getType() const {return objectType;}
|
||||
|
@ -1028,11 +1028,6 @@ void UnitUpdater::updateHarvest(Unit *unit) {
|
||||
//if resource exausted, then delete it and stop
|
||||
if (r->decAmount(1)) {
|
||||
const ResourceType *rt = r->getType();
|
||||
|
||||
//TODO:
|
||||
// the following line should be done in Object::~Object(), but I don't know how (titi)!
|
||||
this->game->getGui()->removeObject(sc->getObject());
|
||||
|
||||
sc->deleteResource();
|
||||
unit->getFaction()->removeResourceTargetFromCache(unitTargetPos);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user