- Timestamp:
- Jan 7, 2006, 11:07:22 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 4 deleted
- 35 edited
- 19 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r6222 r6424 48 48 story_entities/story_entity.cc \ 49 49 story_entities/campaign.cc \ 50 story_entities/world.cc \ 51 story_entities/network_world.cc \ 50 story_entities/campaign_data.cc \ 51 story_entities/game_world.cc \ 52 story_entities/game_world_data.cc \ 53 story_entities/single_player_world.cc \ 54 story_entities/single_player_world_data.cc \ 55 story_entities/multi_player_world.cc \ 56 story_entities/multi_player_world_data.cc \ 52 57 world_entities/world_entity.cc \ 53 58 world_entities/camera.cc \ … … 96 101 story_entities/story_def.h \ 97 102 story_entities/campaign.h \ 98 story_entities/world.h \ 99 story_entities/network_world.h \ 103 story_entities/campaign_data.h \ 104 story_entities/game_world.h \ 105 story_entities/game_world_data.h \ 106 story_entities/single_player_world.h \ 107 story_entities/single_player_world_data.h \ 108 story_entities/multi_player_world.h \ 109 story_entities/multi_player_world_data.h \ 100 110 world_entities/world_entity.h \ 101 111 world_entities/camera.h \ -
trunk/src/defs/class_id.h
r6341 r6424 147 147 // StoryEntities (range from 0x00000100 to 0x000001ff) 148 148 CL_CAMPAIGN = 0x00000101, 149 CL_WORLD = 0x00000102, 150 149 CL_CAMPAIGN_DATA = 0x00000102, 150 CL_GAME_WORLD = 0x00000103, 151 CL_GAME_WORLD_DATA = 0x00000104, 152 CL_SINGLE_PLAYER_WORLD = 0x00000105, 153 CL_SINGLE_PLAYER_WORLD_DATA = 0x00000106, 154 CL_MULTI_PLAYER_WORLD = 0x00000107, 155 CL_MULTI_PLAYER_WORLD_DATA = 0x00000108, 151 156 152 157 // WorldEntities (range from 0x00000200 to 0x000004ff) -
trunk/src/lib/Makefile.am
r6074 r6424 36 36 lang/base_object.cc \ 37 37 lang/class_list.cc \ 38 data/data_tank.cc \ 38 39 util/substring.cc \ 39 40 util/color.cc \ … … 47 48 noinst_HEADERS = coord/p_node.h \ 48 49 lang/base_object.h \ 50 data/data_tank.h \ 49 51 graphics/render2D/element_2d.h \ 50 52 graphics/render2D/render_2d.h \ … … 70 72 particles \ 71 73 collision_detection \ 72 network \74 network \ 73 75 parser \ 74 76 shell \ -
trunk/src/lib/coord/p_node.cc
r6341 r6424 29 29 30 30 #include "synchronizeable.h" 31 32 #include "shell_command.h" 33 SHELL_COMMAND(debugNode, PNode, debugNodeSC); 31 34 32 35 using namespace std; … … 152 155 } 153 156 } 157 158 159 /** 160 * init the pnode to a well definied state 161 * 162 * this function actualy only updates the PNode tree 163 */ 164 void PNode::init() 165 { 166 /* just update all aboslute positions via timestep 0.001ms */ 167 this->updateNode(0.001f); 168 this->updateNode(0.001f); 169 } 170 154 171 155 172 /** -
trunk/src/lib/coord/p_node.h
r6341 r6424 78 78 79 79 void loadParams(const TiXmlElement* root); 80 81 void init(); 80 82 81 83 // ACTIVATION // … … 172 174 // DEBUG // 173 175 void countChildNodes(int& nodes) const; 176 void debugNodeSC (unsigned int depth = 1, unsigned int level = 0) { this->debugNode(depth, level); }; 174 177 void debugNode (unsigned int depth = 1, unsigned int level = 0) const; 175 178 void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1, 0, 0), unsigned int level = 0) const; -
trunk/src/lib/network/network_game_manager.cc
r6341 r6424 23 23 #include "network_stream.h" 24 24 #include "converter.h" 25 26 #include "p_node.h" 27 25 28 26 29 /* include your own header */ … … 237 240 * @param classID: The ID of the class of which an entity should be created 238 241 */ 239 BaseObject* NetworkGameManager::createEntity( TiXmlElement* element)242 BaseObject* NetworkGameManager::createEntity(const TiXmlElement* element) 240 243 { 241 244 if ( this->isServer() ) … … 252 255 if ( !b ) 253 256 { 254 PRINTF(1)("Could not fabricate Object with class ID %x\n", element->Value() );257 PRINTF(1)("Could not fabricate Object with className %s\n", element->Value() ); 255 258 return NULL; 256 259 } … … 391 394 //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 ); 392 395 396 int n = 0; 397 393 398 while ( it != e ) 394 399 { … … 403 408 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) ) 404 409 return; 410 411 412 PRINTF(0)("id = %x %s %s\n", (int)((*it)->getLeafClassID()), (*it)->getClassName(), (*it)->getName()); 413 414 415 /*if ( (*it)->isA(CL_WORLD_ENTITY) ) 416 { 417 n = dynamic_cast<WorldEntity*>((*it))->readState( outBuffer[userID].buffer, outBuffer[userID].maxLength-outBuffer[userID].length ); 418 if ( n = 0 ) 419 { 420 PRINTF(2)("n = 0\n"); 421 } 422 outBuffer[userID].length += n; 423 }*/ 405 424 406 425 it++; … … 436 455 * @param owner: owner of this synchronizealbe 437 456 */ 438 voidNetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )457 BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) 439 458 { 440 459 BaseObject * b = Factory::fabricate( classID ); … … 443 462 { 444 463 PRINTF(1)("Could not fabricate Object with classID %x\n", classID); 445 return ;464 return NULL; 446 465 } 447 466 … … 455 474 s->setIsOutOfSync( true ); 456 475 PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID()); 476 return b; 457 477 } 458 478 else … … 461 481 delete b; 462 482 } 483 return NULL; 463 484 } 464 485 … … 695 716 i += Converter::byteArrayToInt( &data[i], &owner ); 696 717 718 PRINTF(0)("before fabricate\n"); 697 719 if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE ) 698 doCreateEntity( (ClassID)classID, uniqueID, owner ); 699 700 } 720 { 721 BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner ); 722 723 /*if ( b != NULL ) 724 { 725 if ( b->isA(CL_WORLD_ENTITY) ) 726 { 727 int n = dynamic_cast<WorldEntity*>(b)->writeState( data, length, sender ); 728 729 i += n; 730 } 731 }*/ 732 } 733 734 } 735 701 736 return true; 702 737 } -
trunk/src/lib/network/network_game_manager.h
r6341 r6424 75 75 76 76 void createEntity( ClassID classID, int owner = 0 ); 77 BaseObject* createEntity( TiXmlElement* element);77 BaseObject* createEntity(const TiXmlElement* element); 78 78 void removeEntity( int uniqueID ); 79 79 void sendYouAre( int uniqueID, int userID ); … … 94 94 void executeRequestSync( int uniqueID, int user ); 95 95 96 voiddoCreateEntity(ClassID classID, int uniqueID, int owner);96 BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner); 97 97 void doRemoveEntity(int uniqueID); 98 98 void doRequestSync(int uniqueID, int userID); -
trunk/src/lib/network/synchronizeable.cc
r6341 r6424 36 36 this->networkStream = NULL; 37 37 this->setRequestedSync( false ); 38 this->setIsOutOfSync( !(this->isServer()) ); 38 39 } 39 40 -
trunk/src/orxonox.cc
r6142 r6424 409 409 else if(!strcmp( "--server", argv[i]) || !strcmp("-s", argv[i])) 410 410 return startNetworkOrxonox(argc, argv); 411 else if(!strcmp( "--license", argv[i]) || !strcmp("- s", argv[i]))411 else if(!strcmp( "--license", argv[i]) || !strcmp("-l", argv[i])) 412 412 return PRINT(0)(ORXONOX_LICENSE_SHORT); 413 413 } -
trunk/src/story_entities/campaign.cc
r6153 r6424 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer:16 15 */ 17 16 … … 20 19 21 20 #include "factory.h" 22 #include "game_loader.h"23 #include "story_entity.h"24 25 #include "world.h"26 #include "camera.h"27 28 21 #include "load_param.h" 29 22 23 #include "campaign_data.h" 30 24 31 25 using namespace std; 32 26 33 27 34 Campaign::Campaign () 35 { 36 this->setClassID(CL_CAMPAIGN, "Campaign");37 this->isInit = false;38 } 39 28 /** 29 * the constructor 30 * @param root the XML root element 31 * 32 * this constructor is always called in a XML context (loading procedure) 33 */ 40 34 Campaign::Campaign ( TiXmlElement* root) 41 35 { … … 43 37 44 38 PRINTF(4)("Loading Campaign...\n"); 45 46 39 assert( root != NULL); 47 40 48 this->isInit = false; 49 41 this->campaignData = new CampaignData(root); 50 42 this->loadParams(root); 51 43 52 53 //if( lastCreated != NULL)54 //lastCreated->setStoryID( WORLD_ID_GAMEEND);55 }56 57 Campaign::~Campaign ()58 {}59 60 61 ErrorMessage Campaign::init()62 {63 this->isInit = true;64 }65 66 /**67 \brief loads the Parameters of a Campaign68 * @param root: The XML-element to load from69 */70 void Campaign::loadParams(const TiXmlElement* root)71 {72 static_cast<BaseObject*>(this)->loadParams(root);73 74 LoadParam(root, "identifier", this, Campaign, setStoryID)75 .describe("A Unique Identifier for this Campaign");76 77 LoadParamXML(root, "WorldList", this, Campaign, loadWorldListParams)78 .describe("A List of Worlds to be loaded in this Campaign");79 }80 81 /**82 \brief loads a WorldList83 * @param root: the XML-element to load from84 */85 void Campaign::loadWorldListParams(const TiXmlElement* root)86 {87 if (root == NULL)88 return;89 90 LOAD_PARAM_START_CYCLE(root, element);91 {92 PRINTF(5)("Campaign: Constructor: adding a world\n");93 StoryEntity* created = (StoryEntity*) Factory::fabricate(element);94 if( created != NULL)95 {96 this->addEntity( created);97 }98 }99 LOAD_PARAM_END_CYCLE(element);100 }101 102 ErrorMessage Campaign::start()103 {104 this->start(0);105 }106 107 //! @todo boky -> fix it108 ErrorMessage Campaign::start(int storyID = 0)109 {110 ErrorMessage errorCode;111 if( !this->isInit) return errorCode;112 if( storyID == WORLD_ID_GAMEEND) return errorCode;113 this->running = true;114 StoryEntity* se = this->getStoryEntity(storyID);115 this->currentEntity = se;116 while( se != NULL && this->running)117 {118 PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID());119 se->preLoad();120 se->load();121 se->postLoad();122 123 se->init();124 se->preStart();125 se->start();126 se->destroy();127 128 int nextWorldID = se->getNextStoryID();129 130 this->entities.remove(se);131 delete se;132 133 //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);134 se = this->getStoryEntity(nextWorldID);135 this->currentEntity = se;136 if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) )137 {138 PRINTF(4)("Quitting campaing story loop\n");139 if(se != NULL)140 delete se;141 return errorCode;142 }143 }144 145 /* clean up all world that have not been loaded and therefore are still in the world list -146 this probably does not belong into the start function. remove this later147 */148 list<StoryEntity*>::iterator it;149 for(it = this->entities.begin(); it != entities.end(); it++)150 {151 delete (*it);152 }153 PRINTF(1)("There is no StoryEnity left to play, quitting\n");154 }155 156 157 ErrorMessage Campaign::pause()158 {159 if(this->currentEntity != NULL)160 this->isPaused = true;161 }162 163 164 ErrorMessage Campaign::resume()165 {166 if(this->currentEntity != NULL)167 this->isPaused = false;168 }169 170 171 ErrorMessage Campaign::stop()172 {173 this->running = false;174 if(this->currentEntity != NULL)175 {176 this->currentEntity->stop();177 }178 }179 180 181 ErrorMessage Campaign::destroy()182 {183 if(this->currentEntity != NULL)184 {185 this->currentEntity->destroy();186 delete this->currentEntity;187 this->currentEntity = NULL;188 }189 44 } 190 45 191 46 192 47 /** 193 * adds an game stroy entity to the campaign 194 195 * @param se: The entity 196 * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign 197 198 An entity can be a world (playable), a cinematic, a shop, sounds, whatever you 199 want to queue up in the campaign. 200 */ 201 void Campaign::addEntity(StoryEntity* se, int storyID) 48 * the campaign destructor 49 */ 50 Campaign::~Campaign () 202 51 { 203 se->setStoryID(storyID); 204 this->addEntity(se); 205 } 206 207 void Campaign::addEntity(StoryEntity* se) 208 { 209 this->entities.push_back(se); 52 if( this->campaignData) 53 delete this->campaignData; 210 54 } 211 55 212 56 213 void Campaign::removeEntity(int storyID) 57 /** 58 * loads the Parameters of a Campaign 59 * @param root: The XML-element to load from 60 */ 61 void Campaign::loadParams(const TiXmlElement* root) 214 62 { 215 this->removeEntity(this->getStoryEntity(storyID));63 static_cast<StoryEntity*>(this)->loadParams(root); 216 64 65 PRINTF(4)("Loaded Campaign specific stuff\n"); 217 66 } 218 67 219 68 220 void Campaign::removeEntity(StoryEntity* se) 69 /** 70 * starts the campaing with a specific ID 71 * @param storyID the id of the StoryEntity 72 */ 73 bool Campaign::start() 221 74 { 222 this->entities.remove(se); 75 PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID()); 76 77 this->isRunning = true; 78 this->run(); 223 79 } 224 80 225 81 226 /* 227 \brief this changes to the next level228 */229 void Campaign::nextLevel()82 /** 83 * pauses the campaign 84 */ 85 bool Campaign::pause() 230 86 { 231 PRINTF(4)("Campaign:nextLevel()\n"); 87 this->isPaused = true; 88 } 89 90 91 /** 92 * resumes the campaign after a pause 93 */ 94 bool Campaign::resume() 95 { 96 PRINTF(4)("Resuming the current Campaign\n"); 97 this->isPaused = false; 98 } 99 100 101 /** 102 * stops the campaign 103 */ 104 bool Campaign::stop() 105 { 106 PRINTF(4)("Stopping the current Campaign\n"); 107 this->isRunning = false; 108 if( this->currentEntity != NULL) 109 { 110 this->currentEntity->stop(); 111 } 112 } 113 114 115 /** 116 * runs the campaign 117 */ 118 void Campaign::run() 119 { 120 ErrorMessage errorCode; 121 int storyID = WORLD_ID_0; 122 123 for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true; 124 this->currentEntity != NULL && this->isRunning; 125 this->currentEntity = this->campaignData->getNextLevel()) 126 { 127 PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID()); 128 129 this->currentEntity->init(); 130 131 this->currentEntity->loadData(); 132 this->currentEntity->start(); 133 this->currentEntity->unloadData(); 134 } 135 PRINTF(2)("There is no StoryEnity left to play, quitting\n"); 136 } 137 138 139 /** 140 * this changes to the next level 141 */ 142 void Campaign::switchToNextLevel() 143 { 144 PRINTF(4)("Switching to the next StoryEntity\n"); 232 145 this->currentEntity->stop(); 233 146 } 234 147 235 /*236 \brief change to the previous level - not implemented237 148 238 this propably useless239 */240 void Campaign::previousLevel()241 {}242 243 244 /*245 \brief lookup a entity with a given id246 * @param story id to be lookuped247 @returns the entity found or NULL if search ended without match248 */249 StoryEntity* Campaign::getStoryEntity(int storyID)250 {251 //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);252 if( storyID == WORLD_ID_GAMEEND)253 return NULL;254 255 /*256 tList<StoryEntity>* l;257 StoryEntity* entity = NULL;258 l = this->entities->getNext();259 while( l != NULL)260 {261 entity = l->getObject();262 l = l->getNext();263 264 int id = entity->getStoryID();265 //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);266 if(id == storyID)267 {268 //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");269 return entity;270 }271 272 }273 */274 275 276 list<StoryEntity*>::iterator it;277 for (it = this->entities.begin(); it != this->entities.end(); it++)278 {279 int id = (*it)->getStoryID();280 //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);281 if(id == storyID)282 {283 //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");284 return (*it);285 }286 }287 288 289 290 return NULL;291 } -
trunk/src/story_entities/campaign.h
r5774 r6424 1 /*! 2 * @file campaign.h 3 * definition of the campaign 4 */ 1 5 2 6 #ifndef _CAMPAIGN_H 3 7 #define _CAMPAIGN_H 4 8 9 5 10 #include "story_entity.h" 6 11 7 #include <list>8 12 9 class World;10 13 class TiXmlElement; 14 class CampaignData; 11 15 12 class Campaign : public StoryEntity {13 16 14 public: 15 Campaign (); 16 Campaign ( TiXmlElement* root); 17 virtual ~Campaign (); 17 //! A class that represents a game Campaign that contains other StoryEntities like GameWorlds, movies, etc. 18 class Campaign : public StoryEntity 19 { 18 20 19 void loadParams(const TiXmlElement* root); 20 void loadWorldListParams(const TiXmlElement* root); 21 public: 22 Campaign( TiXmlElement* root); 23 virtual ~Campaign (); 21 24 22 StoryEntity* currentEntity;25 void loadParams(const TiXmlElement* root); 23 26 24 virtual ErrorMessage init(); 25 virtual ErrorMessage start(); 26 virtual ErrorMessage start(int storyID); 27 virtual ErrorMessage pause(); 28 virtual ErrorMessage resume(); 29 virtual ErrorMessage stop(); 30 virtual ErrorMessage destroy(); 27 virtual bool start(); 28 virtual bool stop(); 29 virtual bool pause(); 30 virtual bool resume(); 31 virtual void run(); 31 32 32 void addEntity(StoryEntity* se, int storyID); 33 void addEntity(StoryEntity* se); 34 void removeEntity(int storyID); 35 void removeEntity(StoryEntity* se); 33 void switchToNextLevel(); 36 34 37 void nextLevel();38 void previousLevel();39 35 40 private: 41 //ListTemplate<StoryEntity>* entities; 42 std::list<StoryEntity*> entities; 43 bool running; 44 45 StoryEntity* getStoryEntity(int storyID); 36 private: 37 StoryEntity* currentEntity; //!< reference to the current StoryEntity 38 CampaignData* campaignData; //!< reference to the CampaignData 46 39 }; 47 40 -
trunk/src/story_entities/debug_world.cc
r6222 r6424 1 /*2 orxonox - the future of 3D-vertical-scrollers3 4 Copyright (C) 2004 orx5 6 This program is free software; you can redistribute it and/or modify7 it under the terms of the GNU General Public License as published by8 the Free Software Foundation; either version 2, or (at your option)9 any later version.10 11 ### File Specific:12 main-programmer: Patrick Boenzli13 co-programmer: Christian Meyer14 co-programmer: Benjamin Grauer15 */16 17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD18 19 #include "world.h"20 21 #include "shell_command.h"22 23 #include "state.h"24 25 #include "p_node.h"26 #include "pilot_node.h"27 #include "world_entity.h"28 #include "player.h"29 #include "camera.h"30 #include "environment.h"31 #include "skysphere.h"32 #include "skybox.h"33 #include "satellite.h"34 #include "test_entity.h"35 #include "terrain.h"36 #include "light.h"37 #include "load_param.h"38 #include "shell.h"39 40 #include "fast_factory.h"41 #include "animation_player.h"42 #include "particle_engine.h"43 #include "graphics_engine.h"44 #include "physics_engine.h"45 #include "fields.h"46 47 #include "md2Model.h"48 49 #include "glmenu_imagescreen.h"50 #include "game_loader.h"51 52 #include "animation3d.h"53 54 #include "substring.h"55 56 #include "factory.h"57 58 #include "weapons/projectile.h"59 #include "event_handler.h"60 #include "sound_engine.h"61 #include "ogg_player.h"62 63 #include "class_list.h"64 65 #include "cd_engine.h"66 #include "npcs/npc_test1.h"67 #include "shader.h"68 69 #include "playable.h"70 #include "network_manager.h"71 #include "playable.h"72 73 74 SHELL_COMMAND(speed, World, setSpeed);75 SHELL_COMMAND(togglePNodeVisibility, World, togglePNodeVisibility);76 SHELL_COMMAND(toggleBVVisibility, World, toggleBVVisibility);77 78 using namespace std;79 80 //! This creates a Factory to fabricate a World81 CREATE_FACTORY(World, CL_WORLD);82 83 World::World(const TiXmlElement* root)84 {85 this->constuctorInit("", -1);86 this->path = NULL;87 88 this->loadParams(root);89 }90 91 /**92 * create a new World93 94 This creates a new empty world!95 */96 World::World (const char* name)97 {98 this->path = NULL;99 this->constuctorInit(name, -1);100 }101 102 /**103 * creates a new World...104 * @param worldID with this ID105 */106 World::World (int worldID)107 {108 this->path = NULL;109 this->constuctorInit(NULL, worldID);110 }111 112 /**113 * remove the World from memory114 115 delete everything explicitly, that isn't contained in the parenting tree!116 things contained in the tree are deleted automaticaly117 */118 World::~World ()119 {120 delete this->shell;121 PRINTF(3)("World::~World() - deleting current world\n");122 123 delete this->localPlayer;124 125 // delete all the initialized Engines.126 FastFactory::flushAll(true);127 delete LightManager::getInstance();128 delete ParticleEngine::getInstance();129 delete AnimationPlayer::getInstance();130 delete PhysicsEngine::getInstance();131 132 // external engines initialized by the orxonox-class get deleted133 SoundEngine::getInstance()->flushAllBuffers();134 SoundEngine::getInstance()->flushAllSources();135 136 if (State::getObjectManager() == &this->objectManager)137 State::setObjectManager(NULL);138 // erease everything that is left.139 delete PNode::getNullParent();140 141 //secondary cleanup of PNodes;142 const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE);143 if (nodeList != NULL)144 while (!nodeList->empty())145 delete nodeList->front();146 147 Shader::suspendShader();148 149 // unload the resources !!150 ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);151 152 delete[] this->path;153 }154 155 /**156 * initializes the world.157 * @param name the name of the world158 * @param worldID the ID of this world159 *160 * set all stuff here that is world generic and does not use to much memory161 * because the real init() function StoryEntity::init() will be called162 * shortly before start of the game.163 * since all worlds are initiated/referenced before they will be started.164 * NO LEVEL LOADING HERE - NEVER!165 */166 void World::constuctorInit(const char* name, int worldID)167 {168 this->setClassID(CL_WORLD, "World");169 170 this->setName(name);171 this->debugWorldNr = worldID;172 this->gameTime = 0.0f;173 this->setSpeed(1.0);174 this->music = NULL;175 this->shell = NULL;176 this->localPlayer = NULL;177 this->localCamera = NULL;178 179 this->showPNodes = false;180 this->showBV = false;181 }182 183 /**184 * loads the parameters of a World from an XML-element185 * @param root the XML-element to load from186 */187 void World::loadParams(const TiXmlElement* root)188 {189 PRINTF(4)("Creating a World\n");190 191 LoadParam(root, "identifier", this, World, setStoryID)192 .describe("Sets the StoryID of this world");193 194 LoadParam(root, "nextid", this, World, setNextStoryID)195 .describe("Sets the ID of the next world");196 197 LoadParam(root, "path", this, World, setPath)198 .describe("The Filename of this World (relative from the data-dir)");199 }200 201 /**202 * this is executed just before load203 *204 * since the load function sometimes needs data, that has been initialized205 * before the load and after the proceeding storyentity has finished206 */207 ErrorMessage World::preLoad()208 {209 State::setObjectManager(&this->objectManager);210 this->cycle = 0;211 212 /* init the world interface */213 this->shell = new Shell();214 215 LightManager::getInstance();216 PNode::getNullParent();217 218 AnimationPlayer::getInstance(); // initializes the animationPlayer219 ParticleEngine::getInstance();220 PhysicsEngine::getInstance();221 222 this->localCamera = new Camera();223 this->localCamera->setName ("World-Camera");224 225 State::setCamera(this->localCamera, this->localCamera->getTarget());226 227 GraphicsEngine::getInstance()->displayFPS(true);228 }229 230 231 /**232 * loads the World by initializing all resources, and set their default values.233 */234 ErrorMessage World::load()235 {236 PRINTF(3)("> Loading world: '%s'\n", getPath());237 TiXmlElement* element;238 GameLoader* loader = GameLoader::getInstance();239 240 if( getPath() == NULL)241 {242 PRINTF(1)("World has no path specified for loading");243 this->loadDebugWorld(this->getStoryID());244 return (ErrorMessage){213,"Path not specified","World::load()"};245 }246 247 TiXmlDocument* XMLDoc = new TiXmlDocument( getPath());248 // load the campaign document249 if( !XMLDoc->LoadFile())250 {251 // report an error252 PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc->ErrorDesc(), this->getPath(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());253 delete XMLDoc;254 return (ErrorMessage){213,"XML File parsing error","World::load()"};255 }256 257 // check basic validity258 TiXmlElement* root = XMLDoc->RootElement();259 assert( root != NULL);260 261 if( root == NULL || root->Value() == NULL || strcmp( root->Value(), "WorldDataFile"))262 {263 // report an error264 PRINTF(1)("Specified XML File is not an orxonox world data file (WorldDataFile element missing)\n");265 delete XMLDoc;266 return (ErrorMessage){213,"Path not a WorldDataFile","World::load()"};267 }268 269 // load the parameters270 // name271 const char* string = grabParameter( root, "name");272 if( string == NULL)273 {274 PRINTF(2)("World is missing a proper 'name'\n");275 this->setName("Unknown");276 }277 else278 {279 this->setName(string);280 }281 282 ////////////////283 // LOADSCREEN //284 ////////////////285 element = root->FirstChildElement("LoadScreen");286 if (element == NULL)287 {288 PRINTF(2)("no LoadScreen specified, loading default\n");289 290 glmis->setBackgroundImage("pictures/load_screen.jpg");291 this->glmis->setMaximum(8);292 this->glmis->draw();293 }294 else295 {296 this->glmis->loadParams(element);297 this->glmis->draw();298 }299 this->glmis->draw();300 301 ////////////////////////302 // find WorldEntities //303 ////////////////////////304 305 element = root->FirstChildElement("WorldEntities");306 307 if( element == NULL)308 {309 PRINTF(1)("World is missing 'WorldEntities'\n");310 }311 else312 {313 element = element->FirstChildElement();314 // load Players/Objects/Whatever315 PRINTF(4)("Loading WorldEntities\n");316 while( element != NULL)317 {318 BaseObject* created = Factory::fabricate(element);319 if( created != NULL )320 {321 if(created->isA(CL_WORLD_ENTITY))322 this->spawn(dynamic_cast<WorldEntity*>(created));323 printf("Created a %s: %s\n", created->getClassName(), created->getName());324 }325 326 // if we load a 'Player' we use it as localPlayer327 328 329 //todo do this more elegant330 if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))331 sky = dynamic_cast<SkyBox*>(created);332 if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))333 {334 terrain = dynamic_cast<Terrain*>(created);335 CDEngine::getInstance()->setTerrain(terrain);336 }337 element = element->NextSiblingElement();338 glmis->step(); //! @todo temporary339 }340 PRINTF(4)("Done loading WorldEntities\n");341 }342 343 //////////////////////////////344 // LOADING ADDITIONAL STUFF //345 //////////////////////////////346 347 LoadParamXML(root, "LightManager", LightManager::getInstance(), LightManager, loadParams);348 349 LoadParamXML(root, "ParticleEngine", ParticleEngine::getInstance(), ParticleEngine, loadParams);350 // LoadParamXML(root, "PhysicsEngine", PhysicsEngine::getInstance(), PhysicsEngine, loadParams);351 352 // free the XML data353 354 delete XMLDoc;355 /* GENERIC LOADING PROCESS FINISHED */356 357 358 // Create a Player359 this->localPlayer = new Player();360 361 Playable* playable;362 const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);363 if (playableList != NULL)364 {365 playable = dynamic_cast<Playable*>(playableList->front());366 this->localPlayer->setControllable(playable);367 }368 369 // bind camera370 playable->addChild (this->localCamera);371 372 // //localCamera->setParent(TrackNode::getInstance());373 // tn->addChild(this->localCamera);374 localCamera->setClipRegion(1, 10000.0);375 localCamera->lookAt(playable);376 // this->localPlayer->setParentMode(PNODE_ALL);377 if (sky != NULL)378 {379 this->sky->setParent(this->localCamera);380 this->sky->setParentMode(PNODE_MOVEMENT);381 }382 383 // initialize debug coord system384 objectList = glGenLists(1);385 glNewList (objectList, GL_COMPILE);386 387 glEndList();388 389 SoundEngine::getInstance()->setListener(this->localCamera);390 391 392 393 ////////////394 // STATIC //395 ////////////396 397 398 // TestEntity* testEntity = new TestEntity();399 // testEntity->setRelCoor(Vector(570, 10, -15));400 // testEntity->setRelDir(Quaternion(M_PI, Vector(0, 1, 0)));401 // this->spawn(testEntity);402 403 for(int i = 0; i < 100; i++)404 {405 WorldEntity* tmp = new NPCTest1();406 char npcChar[10];407 sprintf (npcChar, "NPC_%d", i);408 tmp->setName(npcChar);409 tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);410 this->spawn(tmp);411 }412 413 this->music = NULL;414 //(OggPlayer*)ResourceManager::getInstance()->load("sound/00-luke_grey_-_hypermode.ogg", OGG, RP_LEVEL);415 //music->playback();416 }417 418 419 420 /**421 * creates a debug world: only for experimental stuff422 */423 void World::loadDebugWorld(int worldID)424 {425 /*monitor progress*/426 this->glmis->step();427 // stuff beyond this point remains to be loaded properly428 429 // LIGHT initialisation430 LightManager::getInstance()->setAmbientColor(.1,.1,.1);431 // LightManager::getInstance()->addLight();432 LightManager::getInstance()->debug();433 434 switch(this->debugWorldNr)435 {436 /*437 this loads the hard-coded debug world. this only for simplicity and will be438 removed by a reald world-loader, which interprets a world-file.439 if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and440 make whatever you want...441 */442 case DEBUG_WORLD_0:443 {444 LightManager::getInstance()->getLight()->setAbsCoor(-5.0, 10.0, -40.0);445 /*monitor progress*/446 this->glmis->step();447 448 // bind camera449 this->localCamera = new Camera();450 this->localCamera->setName ("camera");451 /*monitor progress*/452 this->glmis->step();453 454 455 // Create SkySphere456 this->sky = new Skysphere("pictures/sky-replace.jpg");457 this->sky->setName("SkySphere");458 this->spawn(this->sky);459 this->localCamera->addChild(this->sky);460 this->sky->setParentMode(PNODE_MOVEMENT);461 /*monitor progress*/462 this->glmis->step();463 464 465 terrain = new Terrain("worlds/newGround.obj");466 terrain->setRelCoor(Vector(0,-10,0));467 this->spawn(terrain);468 /*monitor progress*/469 this->glmis->step();470 471 this->glmis->step();472 break;473 }474 case DEBUG_WORLD_1:475 {476 477 break;478 }479 case DEBUG_WORLD_2:480 {481 482 break;483 }484 default:485 break;486 }487 }488 489 /**490 * initializes a new World shortly before start491 *492 * this is the function, that will be loaded shortly before the world is493 * started494 */495 ErrorMessage World::init()496 {497 this->bPause = false;498 499 /* update the object position before game start - so there are no wrong coordinates used in the first processing */500 PNode::getNullParent()->updateNode (0.001f);501 PNode::getNullParent()->updateNode (0.001f);502 503 }504 505 506 /**507 * starts the World508 */509 ErrorMessage World::start()510 {511 PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);512 this->bQuitOrxonox = false;513 this->bQuitCurrentGame = false;514 this->mainLoop();515 }516 517 /**518 * stops the world.519 520 This happens, when the player decides to end the Level.521 */522 ErrorMessage World::stop()523 {524 PRINTF(3)("World::stop() - got stop signal\n");525 this->bQuitCurrentGame = true;526 }527 528 /**529 * pauses the Game530 */531 ErrorMessage World::pause()532 {533 this->isPaused = true;534 }535 536 /**537 * ends the pause Phase538 */539 ErrorMessage World::resume()540 {541 this->isPaused = false;542 }543 544 /**545 * destroys the World546 */547 ErrorMessage World::destroy()548 {549 550 }551 552 /**553 * shows the loading screen554 */555 void World::displayLoadScreen ()556 {557 PRINTF(3)("World::displayLoadScreen - start\n");558 559 //GLMenuImageScreen*560 this->glmis = new GLMenuImageScreen();561 this->glmis->setMaximum(8);562 563 PRINTF(3)("World::displayLoadScreen - end\n");564 }565 566 /**567 * removes the loadscreen, and changes over to the game568 569 @todo take out the delay570 */571 void World::releaseLoadScreen ()572 {573 PRINTF(3)("World::releaseLoadScreen - start\n");574 this->glmis->setValue(this->glmis->getMaximum());575 PRINTF(3)("World::releaseLoadScreen - end\n");576 delete this->glmis;577 }578 579 580 /**581 * this returns the current game time582 * @returns elapsed game time583 */584 double World::getGameTime()585 {586 return this->gameTime;587 }588 589 /**590 \brief main loop of the world: executing all world relevant function591 592 in this loop we synchronize (if networked), handle input events, give the heart-beat to593 all other member-entities of the world (tick to player, enemies etc.), checking for594 collisions drawing everything to the screen.595 */596 void World::mainLoop()597 {598 this->lastFrame = SDL_GetTicks ();599 PRINTF(3)("World::mainLoop() - Entering main loop\n");600 601 while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* @todo implement pause */602 {603 ++this->cycle;604 // Network605 this->synchronize ();606 // Process input607 this->handleInput ();608 if( this->bQuitCurrentGame || this->bQuitOrxonox)609 break;610 // Process time611 this->tick ();612 // Process collision613 this->collide ();614 // Update the state615 this->update ();616 // Draw617 this->display ();618 }619 620 PRINTF(3)("World::mainLoop() - Exiting the main loop\n");621 }622 623 624 /**625 * synchronize local data with remote data626 */627 void World::synchronize ()628 {629 // Get remote input630 // Update synchronizables631 /* NetworkManager::getInstance()->synchronize();*/632 }633 634 635 /**636 * run all input processing637 638 the command node is the central input event dispatcher. the node uses the even-queue from639 sdl and has its own event-passing-queue.640 */641 void World::handleInput ()642 {643 EventHandler::getInstance()->process();644 645 // remoteinput646 }647 648 void World::tick(std::list<WorldEntity*> entityList, float dt)649 {650 std::list<WorldEntity*>::iterator entity;651 for (entity = entityList.begin(); entity != entityList.end(); entity++)652 (*entity)->tick(dt);653 654 }655 656 /**657 * advance the timeline658 659 this calculates the time used to process one frame (with all input handling, drawing, etc)660 the time is mesured in ms and passed to all world-entities and other classes that need661 a heart-beat.662 */663 void World::tick ()664 {665 Uint32 currentFrame = SDL_GetTicks();666 if(!this->bPause)667 {668 this->dt = currentFrame - this->lastFrame;669 670 if( this->dt > 10)671 {672 float fps = 1000/dt;673 674 // temporary, only for showing how fast the text-engine is675 char tmpChar[20];676 sprintf(tmpChar, "fps: %4.0f", fps);677 }678 else679 {680 /* the frame-rate is limited to 100 frames per second, all other things are for681 nothing.682 */683 PRINTF(3)("fps = 1000 - frame rate is adjusted\n");684 SDL_Delay(10-dt);685 this->dt = 10;686 }687 688 this->dtS = (float)this->dt / 1000.0 * this->speed;689 this->gameTime += this->dtS;690 691 /* this->tick(this->objectManager.getObjectList(OM_DEAD_TICK), this->dtS);692 this->tick(this->objectManager.getObjectList(OM_COMMON), this->dtS);693 this->tick(this->objectManager.getObjectList(OM_GROUP_00), this->dtS);*/694 this->tick(this->objectManager.getObjectList(OM_GROUP_01), this->dtS);695 this->tick(this->objectManager.getObjectList(OM_GROUP_01_PROJ), this->dtS);696 697 /* update tick the rest */698 this->localCamera->tick(this->dtS);699 // tick the engines700 AnimationPlayer::getInstance()->tick(this->dtS);701 // if (this->cycle > 5)702 PhysicsEngine::getInstance()->tick(this->dtS);703 704 ParticleEngine::getInstance()->tick(this->dtS);705 706 707 /** actualy the Graphics Engine should tick the world not the other way around...708 but since we like the things not too complicated we got it this way around709 until there is need or time to do it the other way around.710 @todo: GraphicsEngine ticks world: separation of processes and data...711 712 bensch: in my opinion the GraphicsEngine could draw the world, but not tick it,713 beceause graphics have nothing(or at least not much) to do with Motion.714 */715 GraphicsEngine::getInstance()->tick(this->dtS);716 }717 this->lastFrame = currentFrame;718 }719 720 721 /**722 * this function gives the world a consistant state723 724 after ticking (updating the world state) this will give a constistant725 state to the whole system.726 */727 void World::update()728 {729 GraphicsEngine::getInstance()->update(this->dtS);730 PNode::getNullParent()->updateNode (this->dtS);731 732 SoundEngine::getInstance()->update();733 //music->update();734 }735 736 737 void World::collide()738 {739 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_00),740 this->objectManager.getObjectList(OM_GROUP_01_PROJ));741 CDEngine::getInstance()->checkCollisions(this->objectManager.getObjectList(OM_GROUP_01),742 this->objectManager.getObjectList(OM_COMMON));743 }744 745 /**746 * render the current frame747 748 clear all buffers and draw the world749 */750 void World::display ()751 {752 // clear buffer753 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);754 // set camera755 this->localCamera->apply ();756 // draw world757 this->draw();758 // draw HUD759 /** @todo draw HUD */760 // flip buffers761 GraphicsEngine::swapBuffers();762 //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();763 //SDL_Flip (screen);764 }765 766 767 /**768 * runs through all entities calling their draw() methods769 */770 void World::draw ()771 {772 GraphicsEngine* engine = GraphicsEngine::getInstance();773 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON_NOTICK));774 engine->draw(State::getObjectManager()->getObjectList(OM_ENVIRON));775 engine->draw(State::getObjectManager()->getObjectList(OM_COMMON));776 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_00));777 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01));778 engine->draw(State::getObjectManager()->getObjectList(OM_GROUP_01_PROJ));779 780 // {781 // if( entity->isVisible() ) entity->draw();782 //FIXME783 // if( unlikely( this->showBV)) entity->drawBVTree(3, 226); // to draw the bounding boxes of the objects at level 2 for debug purp784 // entity = iterator->nextElement();785 // }786 787 glCallList (objectList);788 789 ParticleEngine::getInstance()->draw();790 791 if (unlikely(this->showPNodes))792 PNode::getNullParent()->debugDraw(0);793 794 engine->draw();795 //TextEngine::getInstance()->draw();796 }797 798 /**799 * add and spawn a new entity to this world800 * @param entity to be added801 */802 void World::spawn(WorldEntity* entity)803 {804 // this->entities->add (entity);805 entity->postSpawn ();806 }807 808 809 /**810 * add and spawn a new entity to this world811 * @param entity to be added812 * @param absCoor At what coordinates to add this entity.813 * @param absDir In which direction should it look.814 */815 void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)816 {817 // this->entities->add (entity);818 819 entity->setAbsCoor (*absCoor);820 entity->setAbsDir (*absDir);821 822 entity->postSpawn ();823 }824 825 826 /**827 * add and spawn a new entity to this world828 * @param entity to be added829 * @param entity to be added to (PNode)830 * @param At what relative coordinates to add this entity.831 * @param In which relative direction should it look.832 */833 void World::spawn(WorldEntity* entity, PNode* parentNode,834 Vector* relCoor, Quaternion* relDir)835 {836 if( parentNode != NULL)837 {838 parentNode->addChild (entity);839 840 entity->setRelCoor (*relCoor);841 entity->setRelDir (*relDir);842 843 // this->entities->add (entity);844 845 entity->postSpawn ();846 }847 }848 849 void World::setPath( const char* name)850 {851 if (this->path)852 delete this->path;853 if (ResourceManager::isFile(name))854 {855 this->path = new char[strlen(name)+1];856 strcpy(this->path, name);857 }858 else859 {860 this->path = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(name) +1];861 sprintf(this->path, "%s%s", ResourceManager::getInstance()->getDataDir(), name);862 }863 }864 865 const char* World::getPath( void)866 {867 return path;868 } -
trunk/src/story_entities/debug_world.h
r6150 r6424 1 /*!2 * @file world.h3 * Holds and manages all game data4 */5 6 #ifndef _WORLD_H7 #define _WORLD_H8 9 #include "stdincl.h"10 #include "comincl.h"11 #include "story_entity.h"12 #include "p_node.h"13 #include "object_manager.h"14 15 16 class WorldEntity;17 class Camera;18 class Player;19 class GLMenuImageScreen;20 class Terrain;21 class TiXmlElement;22 23 class Shell;24 class OggPlayer;25 26 //! The game world27 /**28 this class initializes everything that should be displayed inside of the current level.29 it is the main driving factor during gameplay.30 */31 class World : public StoryEntity {32 33 public:34 World (const char* name);35 World (int worldID);36 World (const TiXmlElement* root = NULL);37 virtual ~World ();38 39 void loadParams(const TiXmlElement* root);40 41 double getGameTime();42 43 /* classes from story-entity */44 virtual ErrorMessage preLoad();45 virtual ErrorMessage load ();46 virtual ErrorMessage init ();47 virtual ErrorMessage start ();48 virtual ErrorMessage stop ();49 virtual ErrorMessage pause ();50 virtual ErrorMessage resume ();51 virtual ErrorMessage destroy ();52 53 void loadDebugWorld(int worldID);54 55 virtual void displayLoadScreen();56 virtual void releaseLoadScreen();57 58 /* command node functions */59 bool command (Command* cmd);60 61 /* interface to world */62 void spawn (WorldEntity* entity);63 void spawn (WorldEntity* entity, Vector* absCoor, Quaternion* absDir);64 void spawn(WorldEntity* entity, PNode* parentNode, Vector* relCoor, Quaternion* relDir);65 66 /** @param speed sets the speed of the Game */67 inline void setSpeed(float speed) { this->speed = speed; };68 const char* getPath();69 void setPath( const char* name);70 71 inline Camera* getLocalCamera() { return this->localCamera; };72 73 void togglePNodeVisibility() { this->showPNodes = !this->showPNodes; };74 void toggleBVVisibility() { this->showBV = !this->showBV; };75 76 private:77 void constuctorInit(const char* name, int worldID);78 /* function for main-loop */79 void mainLoop ();80 void synchronize ();81 void handleInput ();82 void tick (std::list<WorldEntity*> worldEntity, float dt);83 void tick ();84 void update ();85 void collide ();86 void draw ();87 void display ();88 void debug ();89 90 private:91 bool showPNodes; //!< if the PNodes should be visible.92 bool showBV; //!< if the Bounding Volumes should be visible.93 Uint32 lastFrame; //!< last time of frame94 Uint32 cycle; //!< The cycle we are in (starts with 0 and rises with every frame)95 Uint32 dt; //!< time needed to calculate this frame (in milliSeconds)96 float dtS; //!< The time needed for caluculations in seconds97 float speed; //!< how fast the game flows98 double gameTime; //!< this is where the game time is saved99 bool bQuitOrxonox; //!< quit this application100 bool bQuitCurrentGame; //!< quit only the current game and return to menu101 bool bPause; //!< pause mode102 103 ObjectManager objectManager; //!< The ObjectManager of this World.104 105 GLMenuImageScreen* glmis; //!< The Level-Loader Display106 107 int debugWorldNr; //!< The Debug Nr. needed, if something goes wrong108 char* path; //!< The file from which this world is loaded109 110 Shell* shell;111 OggPlayer* music;112 113 // IMPORTANT WORLD-ENTITIES114 Camera* localCamera; //!< The current Camera115 WorldEntity* sky; //!< The Environmental Heaven of orxonox @todo insert this to environment insted116 Terrain* terrain; //!< The Terrain of the World.117 118 GLuint objectList; //!< temporary: @todo this will be ereased soon119 120 Player* localPlayer; //!< The Player, you fly through the level.121 };122 123 #endif /* _WORLD_H */ -
trunk/src/story_entities/story_entity.cc
r6153 r6424 17 17 18 18 19 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD 20 21 19 22 #include "story_entity.h" 23 24 #include "load_param.h" 20 25 21 26 … … 23 28 24 29 25 30 /** 31 * default constructor initializes all needed data 32 */ 26 33 StoryEntity::StoryEntity () 27 34 { 28 35 this->setClassID(CL_STORY_ENTITY, "StoryEntity"); 36 29 37 this->isInit = false; 30 this->readyToRun = false;31 38 this->isPaused = false; 32 this->isSuspended = false; 33 } 39 this->isRunning = false; 34 40 35 StoryEntity::~StoryEntity () {} 36 37 38 /** 39 * sets the story ID 40 41 sets the story id of the current entity, this enables it to be identified in a 42 global context. 43 */ 44 void StoryEntity::setStoryID(int storyID) 45 { 46 this->storyID = storyID; 41 this->storyID = -1; 42 this->nextStoryID = WORLD_ID_GAMEEND; 47 43 } 48 44 49 45 50 46 /** 51 * this reads the story id of the current entity 52 * @returns the story entity id 53 */ 54 int StoryEntity::getStoryID() 55 { 56 return this->storyID; 57 } 47 * deconstructor 48 */ 49 StoryEntity::~StoryEntity () 50 {} 58 51 59 52 60 53 /** 61 * sets the id of the next story entity 54 * loads the Parameters of a Campaign 55 * @param root: The XML-element to load from 56 */ 57 void StoryEntity::loadParams(const TiXmlElement* root) 58 { 59 static_cast<BaseObject*>(this)->loadParams(root); 62 60 63 StoryEntities can choose their following entity themselfs. the entity id defined here64 will be startet after this entity ends. this can be convenient if you want to have a65 non linear story with switches. 66 */ 67 void StoryEntity::setNextStoryID(int nextStoryID) 68 { 69 this->nextStoryID = nextStoryID;61 LoadParam(root, "identifier", this, StoryEntity, setStoryID) 62 .describe("A Unique Identifier for this StoryEntity"); 63 64 LoadParam(root, "nextid", this, StoryEntity, setNextStoryID) 65 .describe("Sets the ID of the next StoryEntity"); 66 67 PRINTF(4)("Loaded StoryEntity specific stuff\n"); 70 68 } 71 72 /**73 * gets the story id of the current entity74 * @returns story id75 */76 int StoryEntity::getNextStoryID()77 {78 return this->nextStoryID;79 } -
trunk/src/story_entities/story_entity.h
r6153 r6424 1 1 /*! 2 2 * @file story_entity.h 3 4 */3 * holds the base class of everything that is playable - that is part of the story 4 */ 5 5 6 6 … … 12 12 #include "error.h" 13 13 14 15 typedef enum StoryEntityState 16 { 17 SE_STATE_RUN = 0, 18 SE_STATE_STOP, 19 SE_STATE_PAUSE, 20 21 SE_STATE_NUM 22 }; 23 24 14 25 //! A class that represents something to play in orxonox. it is a container for worlds, movies, mission briefings, etc... 15 26 class StoryEntity : public BaseObject { … … 19 30 virtual ~StoryEntity (); 20 31 21 // INIT AND LOAD // 22 /** @brief initializes a Story Entity to default Values */ 32 void loadParams(const TiXmlElement* root); 33 34 /* initialisation and loading */ 35 /** initializes a Story Entity to the needed values */ 23 36 virtual ErrorMessage init() {}; 24 /** @brief called before loading */ 25 virtual ErrorMessage preLoad() {}; 26 /** @brief called to load. */ 27 virtual ErrorMessage load() {}; 28 /** @brief called right after loading */ 29 virtual ErrorMessage postLoad() {}; 30 /** @brief called after postload to check for integrity. (optional) */ 31 virtual ErrorMessage check() {}; 37 /** called to load the data into the StoryEntity*/ 38 virtual ErrorMessage loadData() {}; 39 /** function that unloads the data from the StoryEntity */ 40 virtual ErrorMessage unloadData() {}; 32 41 33 // RUNNING // 34 /** @brief called shortly before starting the Entity */ 35 virtual ErrorMessage preStart() {}; 36 /** @brief starts the Entity. Starts the main cycle */ 37 virtual ErrorMessage start() = 0; 38 /** @brief pauses the Entity. call to resume required to get it running again */ 39 virtual ErrorMessage pause() = 0; 40 /** @brief resumes the Entity after a stop/pause or suspend. */ 41 virtual ErrorMessage resume() = 0; 42 /** @brief suspends the Entity detaches all mayor functions (optional) */ 43 virtual ErrorMessage suspend() {}; 44 /** @brief rewinds to the beginning/last checkpoint */ 45 virtual ErrorMessage rewind() {}; 46 /** @brief leaves the Entity. Ends it */ 47 virtual ErrorMessage preStop() {}; 48 /** @brief Stops the entity. */ 49 virtual ErrorMessage stop() = 0; 42 /* running, stopping and pausing */ 43 /** starts the Entity. Starts the main cycle */ 44 virtual bool start() = 0; 45 /** Stops the entity. */ 46 virtual bool stop() = 0; 47 /** pauses the Entity, you can resume the game by calling the resume() function */ 48 virtual bool pause() = 0; 49 /** resumes a paused StoryEntity */ 50 virtual bool resume() = 0; 51 /** function that is been called when the StoryEntity is started via start() */ 52 virtual void run() = 0; 50 53 51 / / KILLING52 /** @brief kills the Entity. should also calls prestop stop*/53 virtual ErrorMessage destroy() {};54 /* properties interface */ 55 /** returns the state of this StoryEntity */ 56 StoryEntityState getState(); 54 57 55 void setStoryID(int storyID); 56 int getStoryID(); 58 /** sets the story id of the current entity, this enables it to be identified in a global context. @param storyID the story id */ 59 inline void setStoryID(int storyID) { this->storyID = storyID; } 60 /** sets the story id of the current entity, this enables it to be identified in a global context. @returns the story id */ 61 inline int getStoryID() { return this->storyID; } 62 /** sets the id of the next story entity: StoryEntities can choose their following entity themselfs. 63 * the entity id defined here will be startet after this entity ends. this can be convenient if you 64 * want to have a non linear story with switches. 65 * @param nextStoryID the story id of the next StoryEntity */ 66 inline void setNextStoryID(int nextStoryID) { this->nextStoryID = nextStoryID; } 67 /** gets the story id of the current entity @returns story id */ 68 inline int getNextStoryID() { return this->nextStoryID; } 57 69 58 void setNextStoryID(int nextStoryID); 59 int getNextStoryID(); 70 60 71 61 72 protected: 62 73 bool isInit; //!< if the entity is initialized, this has to be true. 63 bool readyToRun; //!< If the entity is ready to run -> post-check.74 bool isRunning; //!< is true if the entity is running 64 75 bool isPaused; //!< is true if the entity is paused 65 bool isSuspended; //!< if the Entity is suspended. 76 66 77 67 78 private: -
trunk/src/subprojects/network/network_unit_test.cc
r6341 r6424 136 136 137 137 /* create a server stream */ 138 nm->createServer( *serverSync,port);138 nm->createServer(port); 139 139 140 140 /* esatblish a connection */ … … 289 289 printf("%f = ", f); 290 290 printf(s); printf("\n"); 291 291 292 292 byte* res = Converter::floatToByteArray(f); 293 293 printf("Byte Array: "); … … 295 295 printf("%i ", res[i]); 296 296 printf("\n"); 297 297 298 298 float b = Converter::byteArrayToFloat(res); 299 299 printf("ReConvert: %f \n", b); … … 305 305 printf("### %f = ", f); 306 306 printf(s); printf("\n"); 307 307 308 308 byte* res = Converter::_floatToByteArray(f); 309 309 printf("Byte Array: "); … … 311 311 printf("%i ", res[i]); 312 312 printf("\n"); 313 313 314 314 float b = Converter::_byteArrayToFloat(res); 315 315 printf("ReConvert: %f \n", b); … … 324 324 printf("%i ", res[i]); 325 325 printf("\n"); 326 326 327 327 int z = Converter::byteArrayToInt(res); 328 328 329 329 printf("ReConvert: %i\n", z); 330 330 331 331 332 332 //float a = 5.4f; 333 333 //float b = 2.0f; 334 334 //printf("%f mod %f = %f", a, b, a % b); 335 336 printf("\n"); 337 335 336 printf("\n"); 337 338 338 */ 339 339 /* 340 340 float y; 341 341 char* s; 342 342 343 343 y = 12.0f; 344 344 s = Converter::floatToBinString(y); 345 345 printf("%f = ", y); 346 346 printf(s); printf("\n"); 347 347 348 348 y = 24549026.0f; 349 349 s = Converter::floatToBinString(y); 350 350 printf("%f = ", y); 351 351 printf(s); printf("\n"); 352 352 353 353 y = 12.4e20f; 354 354 s = Converter::floatToBinString(y); 355 355 printf("%f = ", y); 356 356 printf(s); printf("\n"); 357 357 358 358 y = 4.7824f; 359 359 s = Converter::floatToBinString(y); 360 360 printf("%f = ", y); 361 361 printf(s); printf("\n"); 362 362 363 363 y = -4.7824f; 364 364 s = Converter::floatToBinString(y); 365 365 printf("%f = ", y); 366 366 printf(s); printf("\n"); 367 367 368 368 y = -14.35e14f; 369 369 s = Converter::floatToBinString(y); … … 371 371 printf(s); printf("\n"); 372 372 */ 373 374 373 374 375 375 /* 376 376 float a = 12.3f; 377 377 378 378 char* s = Converter::floatToBinString(a); 379 379 printf("%f = ", a); 380 380 printf(s); printf("\n"); 381 381 382 382 byte* res = Converter::floatToByteArray(a); 383 383 printf("Byte Array: \n"); … … 385 385 printf("%i ", res[i]); 386 386 printf("\n"); 387 387 388 388 float b = Converter::byteArrayToFloat(res); 389 389 printf("ReConvert: %f \n", b); … … 392 392 // testFloatConverter(134.26455646546548741661675165f); printf("\n"); 393 393 // testFloatConverter(35.67e14f); printf("\n"); 394 394 395 395 testFloatConverter(12.3e-7f); printf("\n"); 396 396 testFloatConverter(134.26455646546548741661675165f); printf("\n"); 397 397 testFloatConverter(35.67e14f); printf("\n"); 398 398 399 399 return 0; 400 400 } -
trunk/src/util/loading/game_loader.cc
r6152 r6424 61 61 } 62 62 63 64 /**65 * this class is a singleton class66 * @returns an instance of itself67 *68 * if you are unsure about singleton classes, check the theory out on the internet :)69 */70 GameLoader* GameLoader::getInstance()71 {72 if(singletonRef == NULL)73 singletonRef = new GameLoader();74 return singletonRef;75 }76 63 77 64 /** … … 124 111 if (campaignName) 125 112 { 126 this->currentCampaign = this->fileTo NetworkCampaign(campaignName);113 this->currentCampaign = this->fileToCampaign(campaignName); 127 114 delete[] campaignName; 128 115 } … … 225 212 226 213 /** 227 * release the mem ATTENTION: not implemented228 */229 ErrorMessage GameLoader::destroy()230 {231 232 }233 234 235 /**236 214 * reads a campaign definition file into a campaign class 237 215 * @param fileName to be loaded … … 285 263 286 264 287 /**288 * reads a campaign definition file into a campaign class289 * @param fileName to be loaded290 * @returns the loaded campaign291 *292 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns293 */294 Campaign* GameLoader::fileToNetworkCampaign(const char* fileName)295 {296 /* do not entirely load the campaign. just the current world297 before start of each world, it has to be initialized so it298 can load everything it needs into memory then.299 */300 301 if( fileName == NULL)302 {303 PRINTF(2)("No filename specified for loading");304 return NULL;305 }306 307 TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);308 // load the campaign document309 if( !XMLDoc->LoadFile())310 {311 // report an error312 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());313 delete XMLDoc;314 return NULL;315 }316 317 // check basic validity318 TiXmlElement* root = XMLDoc->RootElement();319 assert( root != NULL);320 321 if( strcmp( root->Value(), "Campaign"))322 {323 // report an error324 PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");325 delete XMLDoc;326 return NULL;327 }328 329 // construct campaign330 Campaign* c = new Campaign( root);331 332 // free the XML data333 delete XMLDoc;334 335 return c;336 }337 338 265 339 266 /** … … 347 274 if( likely(event.bPressed)) 348 275 { 349 this->nextLevel(); 350 } 351 } 352 else if( event.type == KeyMapper::PEV_PREVIOUS_WORLD) 353 { 354 if( likely(event.bPressed)) 355 { 356 this->previousLevel(); 276 this->switchToNextLevel(); 357 277 } 358 278 } … … 377 297 378 298 /** 379 * \brief this changes to the next level 380 */ 381 void GameLoader::nextLevel() 382 { 383 if(this->currentCampaign != NULL) 384 this->currentCampaign->nextLevel(); 385 } 386 387 388 /** 389 * change to the previous level - not implemented 390 * 391 * this propably useless 392 */ 393 void GameLoader::previousLevel() 394 { 395 if(this->currentCampaign != NULL) 396 this->currentCampaign->previousLevel(); 397 } 299 * this changes to the next level 300 */ 301 void GameLoader::switchToNextLevel() 302 { 303 if(this->currentCampaign != NULL) 304 this->currentCampaign->switchToNextLevel(); 305 } 306 307 -
trunk/src/util/loading/game_loader.h
r6152 r6424 41 41 public: 42 42 ~GameLoader (); 43 /** this class is a singleton class @returns an instance of itself */ 44 static GameLoader* getInstance() { if(singletonRef == NULL) singletonRef = new GameLoader(); return singletonRef; } 43 45 44 static GameLoader* getInstance(); 46 ErrorMessage loadCampaign(const char* name); 47 ErrorMessage loadDebugCampaign(Uint32 campaignID); 48 ErrorMessage loadNetworkCampaign(const char* fileName); 45 49 46 50 ErrorMessage init(); … … 49 53 ErrorMessage pause(); 50 54 ErrorMessage resume(); 51 ErrorMessage destroy();52 55 53 ErrorMessage loadCampaign(const char* name); 54 ErrorMessage loadDebugCampaign(Uint32 campaignID); 55 ErrorMessage loadNetworkCampaign(const char* fileName); 56 57 void nextLevel(); 58 void previousLevel(); 56 void switchToNextLevel(); 59 57 60 58 void process(const Event &event); … … 65 63 66 64 Campaign* fileToCampaign(const char* name); 67 Campaign* fileToNetworkCampaign(const char* fileName);68 65 69 66 -
trunk/src/world_entities/camera.cc
r6222 r6424 11 11 ### File Specific: 12 12 main-programmer: Christian Meyer 13 co-programmer: ...13 co-programmer: Benjamin Grauer 14 14 */ 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY … … 17 17 #include "camera.h" 18 18 19 #include "world.h"20 #include "world_entity.h"21 #include "vector.h"22 #include "event.h"23 19 #include "event_handler.h" 24 20 25 21 using namespace std; 26 22 27 ////////////28 // CAMERA //29 ////////////30 23 31 24 /** … … 58 51 */ 59 52 Camera::~Camera() 60 { 61 } 53 {} 62 54 63 55 /** … … 115 107 currentMode = mode; 116 108 switch (mode) 117 109 { 118 110 default: 119 111 case VIEW_NORMAL: 120 112 this->toFovy = 60.0; 121 /* this->setParentSoft("TrackNode");122 this->target->setParentSoft("TrackNode"); */113 /* this->setParentSoft("TrackNode"); 114 this->target->setParentSoft("TrackNode"); */ 123 115 this->setRelCoorSoft(-10, 5, 0); 124 116 this->target->setRelCoorSoft(0,0,0); 125 117 break; 126 118 case VIEW_BEHIND: 127 // this->toFovy = 120.0;128 // this->setRelCoorSoft(Vector(3.5, 0, 0));129 // this->target->setRelCoorSoft(Vector(10,0,0));130 131 // if (!strcmp(this->target->getParent()->getName(), "Player"))132 // this->target->setParentSoft("TrackNode");133 // else134 // this->target->setParentSoft("Player");135 // this->getParent()->debugNode(0);136 137 // this->setParent("main-Turret");138 // this->setParentMode(PNODE_ALL);139 // this->target->setParentSoft("Player");119 // this->toFovy = 120.0; 120 // this->setRelCoorSoft(Vector(3.5, 0, 0)); 121 // this->target->setRelCoorSoft(Vector(10,0,0)); 122 123 // if (!strcmp(this->target->getParent()->getName(), "Player")) 124 // this->target->setParentSoft("TrackNode"); 125 // else 126 // this->target->setParentSoft("Player"); 127 // this->getParent()->debugNode(0); 128 129 // this->setParent("main-Turret"); 130 // this->setParentMode(PNODE_ALL); 131 // this->target->setParentSoft("Player"); 140 132 141 133 break; 142 134 case VIEW_FRONT: 143 135 this->toFovy = 120.0; 144 /* this->setParentSoft("Player");145 this->target->setParentSoft("Player");*/146 147 148 // this->target->setRelDirSoft(Quaternion(M_PI/4.0, Vector(0,1,0)));136 /* this->setParentSoft("Player"); 137 this->target->setParentSoft("Player");*/ 138 this->setRelCoorSoft(4, 0, 0, 5); 139 this->target->setRelCoorSoft(Vector(10,0,0), 5); 140 // this->target->setRelDirSoft(Quaternion(M_PI/4.0, Vector(0,1,0))); 149 141 break; 150 142 case VIEW_LEFT: 151 143 this->toFovy = 90; 152 /* this->setParentSoft("TrackNode");153 this->target->setParentSoft("TrackNode");*/144 /* this->setParentSoft("TrackNode"); 145 this->target->setParentSoft("TrackNode");*/ 154 146 this->setRelCoorSoft(0, 1, -10, .5); 155 147 this->target->setRelCoorSoft(0,0,0); … … 157 149 case VIEW_RIGHT: 158 150 this->toFovy = 90; 159 /* this->setParentSoft("TrackNode");160 this->target->setParentSoft("TrackNode");*/151 /* this->setParentSoft("TrackNode"); 152 this->target->setParentSoft("TrackNode");*/ 161 153 this->setRelCoorSoft(Vector(0, 1, 10)); 162 154 this->target->setRelCoorSoft(0,0,0); … … 164 156 case VIEW_TOP: 165 157 this->toFovy= 120; 166 /* this->setParentSoft("TrackNode");167 this->target->setParentSoft("TrackNode");*/158 /* this->setParentSoft("TrackNode"); 159 this->target->setParentSoft("TrackNode");*/ 168 160 this->setRelCoorSoft(Vector(30, 50, 0)); 169 161 this->target->setRelCoorSoft(35,0,0); 170 162 } 171 163 } 172 164 … … 216 208 // switching back to Modeling Matrix 217 209 glMatrixMode (GL_MODELVIEW); 218 // this->target->getParent()->getParent()->debugDraw(0, 2, Vector(1,0,0));210 // this->target->getParent()->getParent()->debugDraw(0, 2, Vector(1,0,0)); 219 211 } 220 212 … … 226 218 { 227 219 if( event.type == KeyMapper::PEV_VIEW0) 228 229 230 220 { 221 this->setViewMode(VIEW_NORMAL); 222 } 231 223 else if( event.type == KeyMapper::PEV_VIEW1) 232 233 234 224 { 225 this->setViewMode(VIEW_BEHIND); 226 } 235 227 else if( event.type == KeyMapper::PEV_VIEW2) 236 237 238 228 { 229 this->setViewMode(VIEW_FRONT); 230 } 239 231 else if( event.type == KeyMapper::PEV_VIEW3) 240 241 242 232 { 233 this->setViewMode(VIEW_LEFT); 234 } 243 235 else if( event.type == KeyMapper::PEV_VIEW4) 244 245 246 236 { 237 this->setViewMode(VIEW_RIGHT); 238 } 247 239 else if( event.type == KeyMapper::PEV_VIEW5) 248 249 250 240 { 241 this->setViewMode(VIEW_TOP); 242 } 251 243 } 252 244 … … 260 252 { 261 253 this->setClassID(CL_CAMERA_TARGET, "CameraTarget"); 262 // this->setParentMode(PNODE_MOVEMENT);263 } 264 254 // this->setParentMode(PNODE_MOVEMENT); 255 } 256 -
trunk/src/world_entities/power_ups/laser_power_up.cc
r6222 r6424 19 19 #include "factory.h" 20 20 #include "state.h" 21 #include "network_game_manager.h" 21 22 22 23 #include "primitive_model.h" … … 118 119 } 119 120 121 int LaserPowerUp::writeBytes( const byte * data, int length, int sender ) 122 { 123 setRequestedSync( false ); 124 setIsOutOfSync( false ); 125 126 SYNCHELP_READ_BEGIN(); 127 128 SYNCHELP_READ_FKT( PowerUp::writeState ); 129 130 return SYNCHELP_READ_N; 131 } 132 133 134 135 int LaserPowerUp::readBytes( byte * data, int maxLength, int * reciever ) 136 { 137 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 138 { 139 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 140 setRequestedSync( true ); 141 } 142 143 int rec = this->getRequestSync(); 144 if ( rec > 0 ) 145 { 146 *reciever = rec; 147 148 SYNCHELP_WRITE_BEGIN(); 149 150 SYNCHELP_WRITE_FKT( PowerUp::readState ); 151 152 return SYNCHELP_WRITE_N; 153 } 154 155 *reciever = 0; 156 return 0; 157 } 158 -
trunk/src/world_entities/power_ups/laser_power_up.h
r5511 r6424 23 23 virtual void draw() const; 24 24 25 virtual int writeBytes(const byte* data, int length, int sender); 26 virtual int readBytes(byte* data, int maxLength, int * reciever ); 27 25 28 private: 26 29 void init(); -
trunk/src/world_entities/power_ups/param_power_up.cc
r6243 r6424 25 25 #include "factory.h" 26 26 #include "load_param.h" 27 #include "network_game_manager.h" 27 28 28 29 using namespace std; … … 53 54 void ParamPowerUp::init() 54 55 { 56 this->setClassID(CL_PARAM_POWER_UP, "ParamPowerUp"); 55 57 this->value = 0; 56 58 this->max_value = 0; … … 63 65 static_cast<PowerUp*>(this)->loadParams(root); 64 66 LoadParam(root, "type", this, ParamPowerUp, setType); 65 if(root->FirstChildElement("value") != NULL) { 67 68 if( root != NULL && root->FirstChildElement("value") != NULL) { 69 66 70 LoadParam(root, "value", this, ParamPowerUp, setValue); 67 71 } … … 116 120 } 117 121 122 int ParamPowerUp::writeBytes( const byte * data, int length, int sender ) 123 { 124 setRequestedSync( false ); 125 setIsOutOfSync( false ); 118 126 127 SYNCHELP_READ_BEGIN(); 128 129 SYNCHELP_READ_FKT( PowerUp::writeState ); 130 131 int i; 132 SYNCHELP_READ_INT( i ); 133 this->type = (EnumParamPowerUpType)i; 134 SYNCHELP_READ_INT( this->value ); 135 136 if ( this->value != 0 ) 137 { 138 SYNCHELP_READ_INT( this->min_value ); 139 SYNCHELP_READ_INT( this->max_value ); 140 } 141 142 return SYNCHELP_READ_N; 143 } 144 145 146 147 int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever ) 148 { 149 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 150 { 151 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 152 setRequestedSync( true ); 153 } 154 155 int rec = this->getRequestSync(); 156 if ( rec > 0 ) 157 { 158 *reciever = rec; 159 160 SYNCHELP_WRITE_BEGIN(); 161 162 SYNCHELP_WRITE_FKT( PowerUp::readState ); 163 164 int i = this->type; 165 SYNCHELP_WRITE_INT( i ); 166 SYNCHELP_WRITE_INT( this->value ); 167 168 if ( this->value != 0 ) 169 { 170 SYNCHELP_WRITE_INT( this->min_value ); 171 SYNCHELP_WRITE_INT( this->max_value ); 172 } 173 174 return SYNCHELP_WRITE_N; 175 } 176 177 *reciever = 0; 178 return 0; 179 } 180 -
trunk/src/world_entities/power_ups/param_power_up.h
r6113 r6424 30 30 int getValue(); 31 31 32 virtual int writeBytes(const byte* data, int length, int sender); 33 virtual int readBytes(byte* data, int maxLength, int * reciever ); 34 32 35 protected: 33 36 virtual void respawn(); -
trunk/src/world_entities/power_ups/power_up.cc
r6282 r6424 25 25 PowerUp::PowerUp(float r, float g, float b) 26 26 { 27 this->setClassID(CL_POWER_UP, "PowerUp"); 28 27 29 this->respawnType = RESPAWN_NONE; 28 30 /* if(!PowerUp::sphereModel) {*/ … … 52 54 void PowerUp::collidesWith (WorldEntity* entity, const Vector& location) 53 55 { 54 if(entity->isA(CL_EXTENDABLE))56 if(entity->isA(CL_EXTENDABLE)) 55 57 { 56 58 if(dynamic_cast<Extendable*>(entity)->pickup(this)) … … 94 96 } 95 97 98 /** 99 * data copied in data will bee sent to another host 100 * @param data pointer to data 101 * @param maxLength max length of data 102 * @return the number of bytes writen 103 */ 104 int PowerUp::readState( byte * data, int maxLength ) 105 { 106 SYNCHELP_WRITE_BEGIN(); 107 SYNCHELP_WRITE_FKT( WorldEntity::readState ); 108 return SYNCHELP_WRITE_N; 109 } 110 111 /** 112 * Writes data from network containing information about the state 113 * @param data pointer to data 114 * @param length length of data 115 * @param sender hostID of sender 116 */ 117 int PowerUp::writeState( const byte * data, int length, int sender ) 118 { 119 SYNCHELP_READ_BEGIN(); 120 SYNCHELP_READ_FKT( WorldEntity::writeState ); 121 return SYNCHELP_READ_N; 122 } 123 -
trunk/src/world_entities/power_ups/power_up.h
r6282 r6424 26 26 void setRespawnType(const char* type); 27 27 28 int writeState(const byte* data, int length, int sender); 29 int readState(byte* data, int maxLength ); 30 28 31 protected: 29 32 PowerUp(float r, float g, float b); -
trunk/src/world_entities/power_ups/turret_power_up.cc
r6222 r6424 18 18 #include "turret_power_up.h" 19 19 #include "factory.h" 20 #include "network_game_manager.h" 20 21 #include "state.h" 21 22 … … 118 119 } 119 120 121 int TurretPowerUp::writeBytes( const byte * data, int length, int sender ) 122 { 123 setRequestedSync( false ); 124 setIsOutOfSync( false ); 125 126 SYNCHELP_READ_BEGIN(); 127 128 SYNCHELP_READ_FKT( PowerUp::writeState ); 129 130 return SYNCHELP_READ_N; 131 } 132 133 134 135 int TurretPowerUp::readBytes( byte * data, int maxLength, int * reciever ) 136 { 137 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 138 { 139 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 140 setRequestedSync( true ); 141 } 142 143 int rec = this->getRequestSync(); 144 if ( rec > 0 ) 145 { 146 *reciever = rec; 147 148 SYNCHELP_WRITE_BEGIN(); 149 150 SYNCHELP_WRITE_FKT( PowerUp::readState ); 151 152 return SYNCHELP_WRITE_N; 153 } 154 155 *reciever = 0; 156 return 0; 157 } -
trunk/src/world_entities/power_ups/turret_power_up.h
r5511 r6424 23 23 virtual void draw() const; 24 24 25 virtual int writeBytes(const byte* data, int length, int sender); 26 virtual int readBytes(byte* data, int maxLength, int * reciever ); 27 25 28 private: 26 29 void init(); -
trunk/src/world_entities/power_ups/weapon_power_up.cc
r6243 r6424 20 20 #include "state.h" 21 21 #include "list.h" 22 #include "network_game_manager.h" 22 23 23 24 #include "primitive_model.h" … … 85 86 this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); 86 87 } 88 89 int WeaponPowerUp::writeBytes( const byte * data, int length, int sender ) 90 { 91 setRequestedSync( false ); 92 setIsOutOfSync( false ); 93 94 SYNCHELP_READ_BEGIN(); 95 96 SYNCHELP_READ_FKT( PowerUp::writeState ); 97 98 //TODO: sync weapon class ( see loadParams ) 99 100 return SYNCHELP_READ_N; 101 } 102 103 104 105 int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever ) 106 { 107 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 108 { 109 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 110 setRequestedSync( true ); 111 } 112 113 int rec = this->getRequestSync(); 114 if ( rec > 0 ) 115 { 116 *reciever = rec; 117 118 SYNCHELP_WRITE_BEGIN(); 119 120 SYNCHELP_WRITE_FKT( PowerUp::readState ); 121 122 //TODO: sync weapon class ( see loadParams ) 123 124 return SYNCHELP_WRITE_N; 125 } 126 127 *reciever = 0; 128 return 0; 129 } -
trunk/src/world_entities/power_ups/weapon_power_up.h
r6113 r6424 22 22 void setWeaponClass(const char* name); 23 23 24 virtual int writeBytes(const byte* data, int length, int sender); 25 virtual int readBytes(byte* data, int maxLength, int * reciever ); 26 24 27 protected: 25 28 virtual void respawn(); -
trunk/src/world_entities/space_ships/space_ship.cc
r6341 r6424 31 31 #include "key_mapper.h" 32 32 #include "event_handler.h" 33 34 #include "network_game_manager.h" 33 35 34 36 #include "power_ups/weapon_power_up.h" … … 121 123 PRINTF(4)("SPACESHIP INIT\n"); 122 124 123 //EventHandler::getInstance()->grabEvents(true);125 EventHandler::getInstance()->grabEvents(true); 124 126 125 127 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; … … 516 518 } 517 519 } 520 521 522 int SpaceShip::writeBytes( const byte * data, int length, int sender ) 523 { 524 setRequestedSync( false ); 525 setIsOutOfSync( false ); 526 527 SYNCHELP_READ_BEGIN(); 528 529 SYNCHELP_READ_FKT( WorldEntity::writeState ); 530 531 return SYNCHELP_READ_N; 532 } 533 534 int SpaceShip::readBytes( byte * data, int maxLength, int * reciever ) 535 { 536 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 537 { 538 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 539 setRequestedSync( true ); 540 } 541 542 int rec = this->getRequestSync(); 543 if ( rec > 0 ) 544 { 545 *reciever = rec; 546 547 SYNCHELP_WRITE_BEGIN(); 548 549 SYNCHELP_WRITE_FKT( WorldEntity::readState ); 550 551 return SYNCHELP_WRITE_N; 552 } 553 554 *reciever = 0; 555 return 0; 556 } -
trunk/src/world_entities/space_ships/space_ship.h
r6243 r6424 44 44 bool pickup(PowerUp* powerUp); 45 45 46 virtual int writeBytes(const byte* data, int length, int sender); 47 virtual int readBytes(byte* data, int maxLength, int * reciever); 48 46 49 47 50 private: -
trunk/src/world_entities/spawning_point.cc
r6139 r6424 16 16 17 17 #include "spawning_point.h" 18 18 19 #include "load_param.h" 19 20 #include "factory.h" 21 20 22 #include "compiler.h" 21 #include "world.h" /* only temp. until the object manager is implemented*/ 23 22 24 23 25 /** … … 97 99 this->frequency, this->seed); 98 100 BaseObject* spawningEntity = Factory::fabricate(this->classID); 99 if( likely(this->world != NULL)) 100 this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); 101 102 // if( likely(this->world != NULL)) 103 // this->world->spawn(dynamic_cast<WorldEntity*>(spawningEntity)); 101 104 } 102 105 -
trunk/src/world_entities/weapons/ground_turret.cc
r6341 r6424 119 119 void GroundTurret::draw () const 120 120 { 121 glMatrixMode(GL_MODELVIEW); 122 glPushMatrix(); 123 float matrix[4][4]; 124 125 /* translate */ 126 glTranslatef (this->getAbsCoor ().x, 127 this->getAbsCoor ().y, 128 this->getAbsCoor ().z); 129 /* rotate */ 130 this->getAbsDir().matrix(matrix); 131 glMultMatrixf((float*)matrix); 132 133 if (this->getModel()) 134 this->getModel()->draw(); 135 136 glPopMatrix(); 121 WorldEntity::draw(); 122 137 123 if (this->left != NULL) 138 124 this->left->draw(); -
trunk/src/world_entities/world_entity.cc
r6341 r6424 35 35 ->defaultValues(2, "models/ships/fighter.obj", 1.0); 36 36 37 SHELL_COMMAND(debugEntity, WorldEntity, debugWE); 37 38 38 39 /** … … 48 49 49 50 this->obbTree = NULL; 51 52 this->md2TextureFileName = NULL; 50 53 51 54 if (root != NULL) … … 105 108 void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber) 106 109 { 110 this->scaling = scaling; 107 111 if ( fileName != NULL && strcmp(fileName, "") ) 108 112 { … … 123 127 return; 124 128 } 125 129 if (scaling == 0.0) 130 { 131 scaling = 1.0; 132 PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1\n"); 133 } 126 134 if(strstr(fileName, ".obj")) 127 135 { … … 343 351 } 344 352 353 354 /** 355 * Debug the WorldEntity 356 */ 357 void WorldEntity::debugEntity() const 358 { 359 PRINT(0)("WorldEntity %s::%s (DEBUG)\n", this->getClassName(), this->getName()); 360 this->debugNode(); 361 PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber) , this->models.size()); 362 for (unsigned int i = 0; i < this->models.size(); i++) 363 { 364 if (models[i] != NULL) 365 PRINT(0)(" : %d:%s", i, this->models[i]->getName()); 366 } 367 PRINT(0)("\n"); 368 369 } 370 371 345 372 /** 346 373 * Writes data from network containing information about the state … … 359 386 SYNCHELP_READ_FLOAT( scaling ); 360 387 //check if modelFileName is relative to datadir or absolute 361 if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) ) 362 { 363 loadModel( modelFileName+strlen(ResourceManager::getInstance()->getDataDir()), scaling ); 364 } 365 else 366 { 367 loadModel( modelFileName, scaling ); 388 389 if ( strcmp(modelFileName, "") ) 390 { 391 392 if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) ) 393 { 394 loadModel( modelFileName+strlen(ResourceManager::getInstance()->getDataDir()), scaling ); 395 } 396 else 397 { 398 loadModel( modelFileName, scaling ); 399 } 368 400 } 369 401 delete[] modelFileName; 402 403 SYNCHELP_READ_STRINGM( modelFileName ); 404 if ( strcmp(modelFileName, "") ) 405 this->md2TextureFileName = modelFileName; 370 406 371 407 return SYNCHELP_READ_N; … … 386 422 SYNCHELP_WRITE_STRING( getModel( 0 )->getName() ); 387 423 SYNCHELP_WRITE_FLOAT( scaling ); 424 if ( this->md2TextureFileName!=NULL && strcmp(this->md2TextureFileName, "") ) 425 { 426 SYNCHELP_WRITE_STRING(this->md2TextureFileName); 427 } 428 else 429 { 430 SYNCHELP_WRITE_STRING(""); 431 } 432 388 433 return SYNCHELP_WRITE_N; 389 434 } -
trunk/src/world_entities/world_entity.h
r6341 r6424 60 60 void drawBVTree(unsigned int depth, int drawMode) const; 61 61 62 63 void debugWE() { this->debugEntity(); }; ///FIXME 64 void debugEntity() const; 65 66 62 67 /* @returns the Count of Faces on this WorldEntity */ 63 68 //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
Note: See TracChangeset
for help on using the changeset viewer.