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