Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 24, 2008, 2:48:43 AM (16 years ago)
Author:
landauf
Message:

many changes, can't remember everything, but these are the most important:

  • attaching entities to other entities works
  • displaying models, lights and shadows works
  • controlling a spectator works
  • removed an update hack in PositionableEntity because I've found a much better solution

and with "works" I mean: it works on client, server and standalone

Location:
code/branches/objecthierarchy/src/orxonox/objects/infos
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/infos/LevelInfo.cc

    r1968 r2006  
    3131
    3232#include <OgreSceneManager.h>
     33#include <OgreLight.h>
    3334
    3435#include "core/CoreIncludes.h"
    3536#include "core/XMLPort.h"
    3637#include "core/Core.h"
     38#include "core/ConsoleCommand.h"
     39#include "core/Loader.h"
     40#include "core/Template.h"
    3741
    3842#include "GraphicsEngine.h"
     43#include "Settings.h"
     44#include "PlayerInfo.h"
     45
     46#include "util/Math.h"
    3947
    4048namespace orxonox
    4149{
     50    SetConsoleCommand(LevelInfo, listPlayers, true);
     51
    4252    CreateFactory(LevelInfo);
    4353
     
    4656        RegisterObject(LevelInfo);
    4757
    48         this->gametypeInstance_ = 0;
     58        this->rootGametype_ = 0;
    4959        this->registerVariables();
    5060
     61        // test test test
     62        {
     63            Ogre::Light* light;
     64            light = GraphicsEngine::getInstance().getLevelSceneManager()->createLight("Light0");
     65            light->setType(Ogre::Light::LT_DIRECTIONAL);
     66            light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0));
     67            light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0));
     68            light->setDirection(1, -0.2, 0.2);
     69        }
     70        // test test test
     71
    5172        COUT(0) << "created LevelInfo" << std::endl;
    5273    }
    5374
     75    LevelInfo* LevelInfo::getActiveLevelInfo()
     76    {
     77        for (ObjectList<LevelInfo>::iterator it = ObjectList<LevelInfo>::begin(); it != ObjectList<LevelInfo>::end(); ++it)
     78            if (it->isActive())
     79                return (*it);
     80
     81        return 0;
     82    }
     83
     84    PlayerInfo* LevelInfo::getClient(unsigned int clientID)
     85    {
     86        LevelInfo* levelinfo = LevelInfo::getActiveLevelInfo();
     87
     88        if (levelinfo)
     89        {
     90            std::map<unsigned int, PlayerInfo*>::const_iterator it = levelinfo->clients_.find(clientID);
     91            if (it != levelinfo->clients_.end())
     92                return it->second;
     93        }
     94        else
     95        {
     96            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
     97                if (it->getClientID() == clientID)
     98                    return (*it);
     99        }
     100        return 0;
     101    }
     102
     103    void LevelInfo::listPlayers()
     104    {
     105        LevelInfo* levelinfo = LevelInfo::getActiveLevelInfo();
     106
     107        if (levelinfo->getGametype())
     108        {
     109            for (std::set<PlayerInfo*>::const_iterator it = levelinfo->getGametype()->getPlayers().begin(); it != levelinfo->getGametype()->getPlayers().end(); ++it)
     110                COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;
     111        }
     112        else
     113        {
     114            for (ObjectList<PlayerInfo>::iterator it = ObjectList<PlayerInfo>::begin(); it != ObjectList<PlayerInfo>::end(); ++it)
     115                COUT(0) << "ID: " << (*it)->getClientID() << ", Name: " << (*it)->getName() << std::endl;
     116        }
     117    }
     118
     119    void LevelInfo::clientConnected(unsigned int clientID)
     120    {
     121        COUT(0) << "client connected" << std::endl;
     122
     123        // create new PlayerInfo instance
     124        PlayerInfo* player = new PlayerInfo();
     125        player->setGametype(this->getGametype());
     126        player->setClientID(clientID);
     127
     128        // add to clients-map
     129        assert(!this->clients_[clientID]);
     130        this->clients_[clientID] = player;
     131    }
     132
     133    void LevelInfo::clientDisconnected(unsigned int clientID)
     134    {
     135        COUT(0) << "client disconnected" << std::endl;
     136
     137        // remove from clients-map
     138        PlayerInfo* player = this->clients_[clientID];
     139        this->clients_.erase(clientID);
     140
     141        // delete PlayerInfo instance
     142        delete player;
     143    }
     144
    54145    void LevelInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    55146    {
     
    57148
    58149        XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
    59         XMLPortParam(LevelInfo, "gametype", setGametype, getGametype, xmlelement, mode).defaultValues("Gametype");
     150        XMLPortParam(LevelInfo, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
    60151        XMLPortParam(LevelInfo, "skybox", setSkybox, getSkybox, xmlelement, mode);
    61152        XMLPortParam(LevelInfo, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1));
     153
     154        this->levelfile_ = this->getLevelfile();
    62155    }
    63156
    64157    void LevelInfo::registerVariables()
    65158    {
    66         REGISTERSTRING(name_,         network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::changedName));
    67         REGISTERSTRING(description_,  network::direction::toclient);
    68         REGISTERSTRING(skybox_,       network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applySkybox));
    69         REGISTERDATA(ambientLight_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyAmbientLight));
     159        REGISTERSTRING(this->levelfile_,    network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyLevel));
     160        REGISTERSTRING(this->name_,         network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::changedName));
     161        REGISTERSTRING(this->description_,  network::direction::toclient);
     162        REGISTERSTRING(this->skybox_,       network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applySkybox));
     163        REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<LevelInfo>(this, &LevelInfo::applyAmbientLight));
     164    }
     165
     166    void LevelInfo::applyLevel()
     167    {
     168        COUT(0) << "Loading level \"" << this->levelfile_ << "\"..." << std::endl;
     169
     170        ClassTreeMask mask;
     171        mask.exclude(Class(BaseObject));
     172        mask.include(Class(Template));
     173
     174        Level* level = new Level(Settings::getDataPath() + this->levelfile_, mask);
     175
     176        Loader::open(level);
    70177    }
    71178
     
    87194    }
    88195
    89     void LevelInfo::setGametype(const std::string& gametype)
     196    void LevelInfo::setGametypeString(const std::string& gametype)
    90197    {
    91198        Identifier* identifier = ClassByString(gametype);
     
    94201            this->gametype_ = gametype;
    95202            this->gametypeIdentifier_ = identifier;
    96             this->gametypeInstance_ = this->gametypeIdentifier_.fabricate();
     203            this->rootGametype_ = this->gametypeIdentifier_.fabricate();
     204            this->getConnectedClients();
    97205        }
    98206    }
  • code/branches/objecthierarchy/src/orxonox/objects/infos/LevelInfo.h

    r1940 r2006  
    3737
    3838#include "objects/gametypes/Gametype.h"
     39#include "network/ClientConnectionListener.h"
    3940
    4041namespace orxonox
    4142{
    42     class _OrxonoxExport LevelInfo : public Info
     43    class _OrxonoxExport LevelInfo : public Info, public network::ClientConnectionListener
    4344    {
    4445        public:
     
    4849            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4950            void registerVariables();
     51
     52            inline const std::map<unsigned int, PlayerInfo*>& getClients() const
     53                { return this->clients_; }
    5054
    5155            inline void setDescription(const std::string& description)
     
    6266                { return this->ambientLight_; }
    6367
    64             void setGametype(const std::string& gametype);
    65             inline const std::string& getGametype() const
     68            void setGametypeString(const std::string& gametype);
     69            inline const std::string& getGametypeString() const
    6670                { return this->gametype_; }
     71            inline Gametype* getGametype() const
     72                { return this->rootGametype_; }
     73
     74            static LevelInfo* getActiveLevelInfo();
     75            static void listPlayers();
     76            static PlayerInfo* getClient(unsigned int clientID);
    6777
    6878        private:
     79            virtual void clientConnected(unsigned int clientID);
     80            virtual void clientDisconnected(unsigned int clientID);
     81
     82            void applyLevel();
     83
    6984            void applySkybox()
    7085                { this->setSkybox(this->skybox_); }
     
    7287                { this->setAmbientLight(this->ambientLight_); }
    7388
     89            std::map<unsigned int, PlayerInfo*> clients_;
    7490            std::string description_;
    7591            std::string skybox_;
     
    7793            std::string gametype_;
    7894            SubclassIdentifier<Gametype> gametypeIdentifier_;
    79             Gametype* gametypeInstance_;
     95            Gametype* rootGametype_;
     96            std::string levelfile_;
    8097    };
    8198}
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc

    r1993 r2006  
    3838
    3939#include "network/Host.h"
     40#include "network/ClientInformation.h"
    4041
    4142#include "GraphicsEngine.h"
     
    5758        this->bHumanPlayer_ = false;
    5859        this->bFinishedSetup_ = false;
     60        this->gametype_ = 0;
    5961
    6062        this->pawn_ = 0;
     
    7173        if (this->isInitialized())
    7274        {
    73             Gametype* gametype = Gametype::getCurrentGametype();
    74             if (gametype)
    75                 gametype->removePlayer(this);
     75            if (this->gametype_)
     76                this->gametype_->removePlayer(this);
    7677
    7778            if (this->controller_)
     
    101102    void PlayerInfo::changedName()
    102103    {
    103         Gametype* gametype = Gametype::getCurrentGametype();
    104         if (gametype)
    105             gametype->playerChangedName(this);
     104        if (this->gametype_)
     105            this->gametype_->playerChangedName(this);
    106106    }
    107107
     
    147147        else if (this->bFinishedSetup_)
    148148        {
    149             Gametype* gametype = Gametype::getCurrentGametype();
    150             if (gametype)
    151                 gametype->addPlayer(this);
     149            if (this->gametype_)
     150                this->gametype_->addPlayer(this);
    152151        }
    153152    }
     
    165164    void PlayerInfo::stopControl()
    166165    {
    167         this->pawn_->removePlayer();
     166        if (this->pawn_)
     167            this->pawn_->removePlayer();
    168168        this->pawn_ = 0;
    169169        this->pawnID_ = network::OBJECTID_UNKNOWN;
  • code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h

    r1993 r2006  
    7171                { return this->controller_; }
    7272*/
     73            inline void setGametype(Gametype* gametype)
     74                { this->gametype_ = gametype; }
     75            inline Gametype* getGametype() const
     76                { return this->gametype_; }
     77
    7378        protected:
    7479            inline void setDefaultController(Identifier* identifier)
     
    98103            Controller* controller_;
    99104            SubclassIdentifier<Controller> defaultController_;
     105            Gametype* gametype_;
    100106    };
    101107}
Note: See TracChangeset for help on using the changeset viewer.