Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (16 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/core/BaseObject.cc

    r2171 r2485  
    3636#include "CoreIncludes.h"
    3737#include "EventIncludes.h"
     38#include "Functor.h"
    3839#include "XMLPort.h"
    3940#include "XMLFile.h"
     
    6061        this->oldGametype_ = 0;
    6162
     63        this->functorSetMainState_ = 0;
     64        this->functorGetMainState_ = 0;
     65
    6266        this->setCreator(creator);
    6367        if (this->creator_)
     
    8286    BaseObject::~BaseObject()
    8387    {
    84         for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    85             (*it)->unregisterEventListener(this);
    86 
    87         for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
    88             it->first->removeEvent(this);
     88        if (this->isInitialized())
     89        {
     90            for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
     91                (*it)->unregisterEventListener(this);
     92
     93            for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     94                it->first->removeEvent(this);
     95
     96            if (this->functorSetMainState_)
     97                delete this->functorSetMainState_;
     98            if (this->functorGetMainState_)
     99                delete this->functorGetMainState_;
     100        }
    89101    }
    90102
     
    100112        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
    101113        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
     114        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
    102115
    103116        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     
    109122            std::list<std::string> eventnames;
    110123
    111             if (mode == XMLPort::LoadObject)
     124            if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject)
    112125            {
    113126                for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++)
     
    279292        SetEvent(BaseObject, "visibility", setVisible, event);
    280293    }
     294
     295    void BaseObject::setMainStateName(const std::string& name)
     296    {
     297        if (this->mainStateName_ != name)
     298        {
     299            this->mainStateName_ = name;
     300            if (this->functorSetMainState_)
     301                delete this->functorSetMainState_;
     302            if (this->functorGetMainState_)
     303                delete this->functorGetMainState_;
     304            this->changedMainState();
     305            if (!this->functorSetMainState_)
     306                COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl;
     307        }
     308    }
     309
     310    void BaseObject::setMainState(bool state)
     311    {
     312        if (this->functorSetMainState_)
     313            (*this->functorSetMainState_)(state);
     314        else
     315            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     316    }
     317
     318    bool BaseObject::getMainState() const
     319    {
     320        if (this->functorGetMainState_)
     321        {
     322            (*this->functorGetMainState_)();
     323            return this->functorGetMainState_->getReturnvalue();
     324        }
     325        else
     326        {
     327            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     328            return false;
     329        }
     330    }
     331
     332    void BaseObject::changedMainState()
     333    {
     334        SetMainState(BaseObject, "activity",   setActive,  isActive);
     335        SetMainState(BaseObject, "visibility", setVisible, isVisible);
     336    }
    281337}
Note: See TracChangeset for help on using the changeset viewer.