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