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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.