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.h" |
---|
19 | #include "multi_player_world_data.h" |
---|
20 | |
---|
21 | #include "util/loading/factory.h" |
---|
22 | #include "util/loading/load_param.h" |
---|
23 | #include "shell_command.h" |
---|
24 | |
---|
25 | #include "cd_engine.h" |
---|
26 | |
---|
27 | #include "network_manager.h" |
---|
28 | #include "network_game_manager.h" |
---|
29 | |
---|
30 | #include "state.h" |
---|
31 | |
---|
32 | |
---|
33 | using namespace std; |
---|
34 | |
---|
35 | |
---|
36 | //! Register a command to print some multiplayer world infos |
---|
37 | SHELL_COMMAND(debug, MultiPlayerWorld, debug); |
---|
38 | |
---|
39 | |
---|
40 | //! This creates a Factory to fabricate a MultiPlayerWorld |
---|
41 | CREATE_FACTORY(MultiPlayerWorld, CL_MULTI_PLAYER_WORLD); |
---|
42 | |
---|
43 | |
---|
44 | MultiPlayerWorld::MultiPlayerWorld(const TiXmlElement* root) |
---|
45 | : GameWorld() |
---|
46 | { |
---|
47 | this->setClassID(CL_MULTI_PLAYER_WORLD, "MultiPlayerWorld"); |
---|
48 | |
---|
49 | this->dataTank = new MultiPlayerWorldData(); |
---|
50 | |
---|
51 | this->loadParams(root); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * remove the MultiPlayerWorld from memory |
---|
57 | * |
---|
58 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
59 | * things contained in the tree are deleted automaticaly |
---|
60 | */ |
---|
61 | MultiPlayerWorld::~MultiPlayerWorld () |
---|
62 | { |
---|
63 | PRINTF(3)("MultiPlayerWorld::~MultiPlayerWorld() - deleting current world\n"); |
---|
64 | if( this->dataTank) |
---|
65 | delete this->dataTank; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * loads the parameters of a MultiPlayerWorld from an XML-element |
---|
71 | * @param root the XML-element to load from |
---|
72 | */ |
---|
73 | void MultiPlayerWorld::loadParams(const TiXmlElement* root) |
---|
74 | { |
---|
75 | GameWorld::loadParams(root); |
---|
76 | |
---|
77 | PRINTF(4)("Creating a MultiPlayerWorld\n"); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /** |
---|
82 | * synchronizes the network since this is a network world |
---|
83 | * |
---|
84 | * this function overrides the synchrinize from the GameWorld |
---|
85 | */ |
---|
86 | void MultiPlayerWorld::synchronize() |
---|
87 | { |
---|
88 | NetworkManager::getInstance()->synchronize(this->dtS); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | /** |
---|
93 | * kicks the CDEngine to detect the collisions between the object groups in the world |
---|
94 | */ |
---|
95 | void MultiPlayerWorld::collisionDetection() |
---|
96 | { |
---|
97 | //CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
98 | |
---|
99 | PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_PLAYERS_PROJ\n\n"); |
---|
100 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ), |
---|
101 | this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
102 | PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_GROUP_01_PROJ\n\n"); |
---|
103 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
104 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
105 | PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_GROUP_01_PROJ\n\n"); |
---|
106 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
107 | this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); |
---|
108 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
109 | this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
110 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
111 | this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01_PROJ\n\n"); |
---|
116 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
117 | this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); |
---|
118 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01\n\n"); |
---|
119 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
120 | this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
121 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
122 | this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); |
---|
123 | |
---|
124 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_01 vs OM_GROUP_00_PROJ\n\n"); |
---|
125 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
126 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
127 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
128 | this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
129 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
130 | this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | // ground collision detection: BSP Model |
---|
135 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
136 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
137 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | /** |
---|
142 | * some debug ouptut - shell command |
---|
143 | */ |
---|
144 | void MultiPlayerWorld::debug() |
---|
145 | { |
---|
146 | ((MultiPlayerWorldData*)this->dataTank)->debug(); |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * cleanup |
---|
151 | * @return |
---|
152 | */ |
---|
153 | ErrorMessage MultiPlayerWorld::unloadData( ) |
---|
154 | { |
---|
155 | |
---|
156 | GameWorld::unloadData(); |
---|
157 | |
---|
158 | delete NetworkManager::getInstance(); |
---|
159 | delete NetworkGameManager::getInstance(); |
---|
160 | |
---|
161 | State::setOnline( false ); |
---|
162 | |
---|
163 | return ErrorMessage(); |
---|
164 | } |
---|