[6404] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #include "multi_player_world_data.h" |
---|
| 19 | |
---|
[7193] | 20 | #include "util/loading/resource_manager.h" |
---|
[6404] | 21 | #include "state.h" |
---|
| 22 | #include "class_list.h" |
---|
| 23 | #include "substring.h" |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/game_loader.h" |
---|
[6404] | 26 | #include "cd_engine.h" |
---|
| 27 | |
---|
| 28 | #include "p_node.h" |
---|
| 29 | #include "world_entity.h" |
---|
| 30 | #include "player.h" |
---|
| 31 | #include "camera.h" |
---|
| 32 | #include "environment.h" |
---|
| 33 | #include "terrain.h" |
---|
| 34 | #include "test_entity.h" |
---|
| 35 | #include "terrain.h" |
---|
[8490] | 36 | #include "md2/md2Model.h" |
---|
[6434] | 37 | #include "world_entities/projectiles/projectile.h" |
---|
[6404] | 38 | #include "npcs/npc_test1.h" |
---|
| 39 | #include "playable.h" |
---|
| 40 | |
---|
[7193] | 41 | #include "util/loading/factory.h" |
---|
[6404] | 42 | #include "fast_factory.h" |
---|
[7193] | 43 | #include "util/loading/load_param.h" |
---|
[6404] | 44 | |
---|
| 45 | #include "network_manager.h" |
---|
| 46 | #include "network_game_manager.h" |
---|
[8068] | 47 | #include "player_stats.h" |
---|
[6404] | 48 | |
---|
[9406] | 49 | #include "proxy/network_settings.h" |
---|
[6404] | 50 | |
---|
| 51 | #include "glmenu_imagescreen.h" |
---|
| 52 | |
---|
| 53 | |
---|
[6498] | 54 | |
---|
[6404] | 55 | |
---|
| 56 | |
---|
[9406] | 57 | |
---|
[6404] | 58 | /** |
---|
| 59 | * constructor of the GameWorldDataData |
---|
| 60 | */ |
---|
| 61 | MultiPlayerWorldData::MultiPlayerWorldData() |
---|
| 62 | : GameWorldData() |
---|
[6498] | 63 | { |
---|
| 64 | this->toggle = false; |
---|
| 65 | } |
---|
[6404] | 66 | |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * destructor for the GameWorldDataData |
---|
| 70 | */ |
---|
| 71 | MultiPlayerWorldData::~MultiPlayerWorldData() |
---|
| 72 | {} |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * initialize the GameWorldDataData |
---|
| 77 | */ |
---|
| 78 | ErrorMessage MultiPlayerWorldData::init() |
---|
| 79 | { |
---|
| 80 | /* call underlying function */ |
---|
[8717] | 81 | return GameWorldData::init(); |
---|
[6404] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * loads the GUI data |
---|
| 87 | * @param root reference to the xml root element |
---|
| 88 | */ |
---|
[7370] | 89 | ErrorMessage MultiPlayerWorldData::loadGUI(const TiXmlElement* root) |
---|
[6404] | 90 | { |
---|
| 91 | /* call underlying function */ |
---|
[8717] | 92 | return GameWorldData::loadGUI(root); |
---|
[6404] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * unloads the GUI data |
---|
| 98 | */ |
---|
| 99 | ErrorMessage MultiPlayerWorldData::unloadGUI() |
---|
| 100 | { |
---|
| 101 | /* call underlying function */ |
---|
[8717] | 102 | return GameWorldData::unloadGUI(); |
---|
[6404] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * overloads the GameWorld::loadWorldEntities(...) class since the network WorldEntity loading is different |
---|
| 108 | * @param root reference to the xml root parameter |
---|
| 109 | */ |
---|
[7370] | 110 | ErrorMessage MultiPlayerWorldData::loadWorldEntities(const TiXmlElement* root) |
---|
[6404] | 111 | { |
---|
[9235] | 112 | const TiXmlElement* element = NULL; |
---|
[9406] | 113 | |
---|
[9494] | 114 | if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) |
---|
[6404] | 115 | { |
---|
[9235] | 116 | /* load the spawning points */ |
---|
| 117 | element = root->FirstChildElement("SpawningPoints"); |
---|
| 118 | if( element == NULL) |
---|
[6404] | 119 | { |
---|
[9235] | 120 | PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n"); |
---|
| 121 | } |
---|
| 122 | else |
---|
| 123 | { |
---|
| 124 | element = element->FirstChildElement(); |
---|
| 125 | // load Players/Objects/Whatever |
---|
| 126 | PRINTF(4)("Loading Spawning Points\n"); |
---|
| 127 | while( element != NULL) |
---|
| 128 | { |
---|
| 129 | BaseObject* created = Factory::fabricate(element); |
---|
| 130 | if( created != NULL ) |
---|
[9406] | 131 | printf("Created a Spawning Point %s: %s\n", created->getClassCName(), created->getCName()); |
---|
[6404] | 132 | |
---|
[9235] | 133 | element = element->NextSiblingElement(); |
---|
| 134 | glmis->step(); |
---|
| 135 | } |
---|
| 136 | PRINTF(4)("Done loading Spawning Points\n"); |
---|
[6404] | 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /* load the WorldEntities */ |
---|
| 141 | element = root->FirstChildElement("WorldEntities"); |
---|
| 142 | if( element == NULL) |
---|
[6409] | 143 | { |
---|
[6404] | 144 | PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n"); |
---|
[6409] | 145 | } |
---|
[6404] | 146 | else |
---|
| 147 | { |
---|
| 148 | element = element->FirstChildElement(); |
---|
| 149 | |
---|
[9494] | 150 | if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) |
---|
[6404] | 151 | { |
---|
[7071] | 152 | while( element != NULL) |
---|
[6404] | 153 | { |
---|
| 154 | /* pass the entity to the NetworkGameManager to be created */ |
---|
[8068] | 155 | BaseObject* created = Factory::fabricate(element); |
---|
[6404] | 156 | if( created != NULL ) |
---|
[9406] | 157 | PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), created->getLeafClassID(), element->Value()); |
---|
[6404] | 158 | else |
---|
| 159 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 160 | |
---|
| 161 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) |
---|
| 162 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
| 163 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 164 | { |
---|
| 165 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 166 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 167 | } |
---|
[7071] | 168 | |
---|
| 169 | element = element->NextSiblingElement(); |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | glmis->step(); |
---|
| 173 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
[6404] | 174 | } |
---|
[7071] | 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | while( element != NULL) |
---|
| 179 | { |
---|
| 180 | PRINTF(0)("load: %s\n", element->Value()); |
---|
| 181 | if( !strcmp(element->Value(), "Terrain") || !strcmp(element->Value(), "Building") ) |
---|
| 182 | { |
---|
[6404] | 183 | |
---|
[7071] | 184 | /* pass the entity to the NetworkGameManager to be created */ |
---|
| 185 | BaseObject* created = Factory::fabricate(element); |
---|
[6498] | 186 | |
---|
[7071] | 187 | if( created != NULL ) |
---|
[9406] | 188 | PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassCName(), created->getCName(), created->getLeafClassID(), element->Value()); |
---|
[7071] | 189 | else |
---|
| 190 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 191 | |
---|
| 192 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) |
---|
| 193 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
| 194 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 195 | { |
---|
| 196 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 197 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | glmis->step(); |
---|
| 201 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
| 202 | } |
---|
| 203 | element = element->NextSiblingElement(); |
---|
| 204 | } |
---|
[6404] | 205 | } |
---|
| 206 | |
---|
[7071] | 207 | |
---|
[9494] | 208 | if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) |
---|
[6498] | 209 | { |
---|
| 210 | this->localPlayer = new Player(); |
---|
[6404] | 211 | |
---|
[8068] | 212 | #if 0 |
---|
[6498] | 213 | Playable* playable; |
---|
| 214 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 215 | assert( playableList != NULL); |
---|
| 216 | |
---|
| 217 | if (playableList != NULL) |
---|
| 218 | { |
---|
| 219 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
[6985] | 220 | this->localPlayer->setPlayable(playable); |
---|
[7078] | 221 | playable->toList(OM_GROUP_00); |
---|
[7074] | 222 | playable->setAbsCoor(213.37, 57.71, -47.98); |
---|
[7346] | 223 | playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0))); |
---|
[6498] | 224 | } |
---|
[8068] | 225 | #endif |
---|
[6498] | 226 | } |
---|
| 227 | else |
---|
[6404] | 228 | { |
---|
[6498] | 229 | /* create a Player */ |
---|
| 230 | this->localPlayer = new Player(); |
---|
[9535] | 231 | PRINTF(0)("created the player\n"); |
---|
[6404] | 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /* init the pnode tree */ |
---|
| 236 | PNode::getNullParent()->init(); |
---|
| 237 | } |
---|
[7954] | 238 | // Fill the EntityLists. Tick then Draw: |
---|
| 239 | this->tickLists.push_back(OM_DEAD_TICK); |
---|
| 240 | this->tickLists.push_back(OM_ENVIRON); |
---|
| 241 | this->tickLists.push_back(OM_COMMON); |
---|
[9008] | 242 | this->tickLists.push_back(OM_PLAYERS); |
---|
| 243 | this->tickLists.push_back(OM_PLAYERS_PROJ); |
---|
[7954] | 244 | this->tickLists.push_back(OM_GROUP_00); |
---|
| 245 | this->tickLists.push_back(OM_GROUP_00_PROJ); |
---|
| 246 | this->tickLists.push_back(OM_GROUP_01); |
---|
| 247 | this->tickLists.push_back(OM_GROUP_01_PROJ); |
---|
| 248 | |
---|
| 249 | this->drawLists.push_back(OM_ENVIRON_NOTICK); |
---|
| 250 | this->drawLists.push_back(OM_ENVIRON); |
---|
| 251 | this->drawLists.push_back(OM_COMMON); |
---|
[9008] | 252 | this->drawLists.push_back(OM_PLAYERS); |
---|
| 253 | this->drawLists.push_back(OM_PLAYERS_PROJ); |
---|
[7954] | 254 | this->drawLists.push_back(OM_GROUP_00); |
---|
| 255 | this->drawLists.push_back(OM_GROUP_00_PROJ); |
---|
| 256 | this->drawLists.push_back(OM_GROUP_01); |
---|
| 257 | this->drawLists.push_back(OM_GROUP_01_PROJ); |
---|
[8717] | 258 | |
---|
[7082] | 259 | State::setPlayer(this->localPlayer); |
---|
[8717] | 260 | |
---|
| 261 | return ErrorMessage(); |
---|
[6404] | 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | /** |
---|
| 266 | * unloads the world entities from the xml file |
---|
| 267 | */ |
---|
| 268 | ErrorMessage MultiPlayerWorldData::unloadWorldEntities() |
---|
| 269 | { |
---|
| 270 | /* call underlying function */ |
---|
[8717] | 271 | return GameWorldData::unloadWorldEntities(); |
---|
[6404] | 272 | } |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | /** |
---|
| 276 | * loads the scene data |
---|
| 277 | * @param root reference to the xml root element |
---|
| 278 | */ |
---|
[7370] | 279 | ErrorMessage MultiPlayerWorldData::loadScene(const TiXmlElement* root) |
---|
[6404] | 280 | { |
---|
| 281 | /* call underlying function */ |
---|
| 282 | GameWorldData::loadScene(root); |
---|
[8717] | 283 | |
---|
[9406] | 284 | // LoadParamXML(root, "NetworkSettings", NetworkSettings::getInstance(), NetworkSettings, loadNetworkSettings); |
---|
| 285 | |
---|
[8068] | 286 | // create server playable |
---|
[9494] | 287 | if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) |
---|
[8068] | 288 | { |
---|
| 289 | NetworkGameManager::getInstance()->signalNewPlayer( 0 ); |
---|
| 290 | State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() ); |
---|
| 291 | } |
---|
[8717] | 292 | |
---|
| 293 | return ErrorMessage(); |
---|
[6404] | 294 | } |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | /** |
---|
| 298 | * unloads the scene data |
---|
| 299 | */ |
---|
| 300 | ErrorMessage MultiPlayerWorldData::unloadScene() |
---|
| 301 | { |
---|
[9406] | 302 | // delete the proxy settings |
---|
| 303 | delete NetworkSettings::getInstance(); |
---|
| 304 | |
---|
[6404] | 305 | /* call underlying function */ |
---|
[8717] | 306 | return GameWorldData::unloadScene(); |
---|
[6404] | 307 | } |
---|
| 308 | |
---|
[6498] | 309 | |
---|
| 310 | /** |
---|
| 311 | * some debug output |
---|
| 312 | */ |
---|
| 313 | void MultiPlayerWorldData::debug() |
---|
| 314 | { |
---|
| 315 | PRINT(0)("==================================================\n"); |
---|
| 316 | Playable* playable; |
---|
| 317 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 318 | assert(playableList != NULL); |
---|
| 319 | std::list<BaseObject*>::const_iterator entity; |
---|
| 320 | |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | for (entity = playableList->begin(); entity != playableList->end(); entity++) |
---|
| 324 | { |
---|
| 325 | Playable* p = dynamic_cast<Playable*>(*entity); |
---|
[9406] | 326 | PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassCName(), (*entity)->getCName(), p->getUniqueID()); |
---|
[6498] | 327 | } |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | if( this->toggle) |
---|
| 331 | { |
---|
| 332 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
[6985] | 333 | this->localPlayer->setPlayable(playable); |
---|
[6498] | 334 | this->toggle = !this->toggle; |
---|
| 335 | } |
---|
| 336 | else |
---|
| 337 | { |
---|
| 338 | playable = dynamic_cast<Playable*>(playableList->back()); |
---|
[6985] | 339 | this->localPlayer->setPlayable(playable); |
---|
[6498] | 340 | this->toggle = !this->toggle; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | |
---|
[6985] | 344 | Playable* pl = this->localPlayer->getPlayable(); |
---|
[6634] | 345 | PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID()); |
---|
[6498] | 346 | |
---|
[6634] | 347 | |
---|
[7014] | 348 | PNode* cam = State::getCameraTargetNode(); |
---|
[9406] | 349 | PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassCName(), cam->getCName(), cam->getUniqueID()); |
---|
[6498] | 350 | |
---|
| 351 | PRINT(0)("==================================================\n"); |
---|
| 352 | |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | |
---|
| 363 | |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | |
---|