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_GROUP_01_PROJ\n\n"); |
---|
100 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
101 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
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_01_PROJ)); |
---|
105 | PRINTF(5)("\n-----------------------------------------\nchecking OM_PLAYERS vs OM_PLAYERS_PROJ\n\n"); |
---|
106 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_PLAYERS), |
---|
107 | this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); |
---|
108 | |
---|
109 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
110 | this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
111 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
112 | this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01_PROJ\n\n"); |
---|
117 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
118 | this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); |
---|
119 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_00 vs OM_GROUP_01\n\n"); |
---|
120 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
121 | this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
122 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_00), |
---|
123 | this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); |
---|
124 | |
---|
125 | PRINTF(5)("\n-----------------------------------------\nchecking OM_GROUP_01 vs OM_GROUP_00_PROJ\n\n"); |
---|
126 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
127 | this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); |
---|
128 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
129 | this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
130 | CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), |
---|
131 | this->dataTank->objectManager->getObjectList(OM_PLAYERS_PROJ)); |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | // ground collision detection: BSP Model |
---|
136 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_00)); |
---|
137 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_GROUP_01)); |
---|
138 | CDEngine::getInstance()->checkCollisionGround(this->dataTank->objectManager->getObjectList(OM_PLAYERS)); |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | /** |
---|
143 | * some debug ouptut - shell command |
---|
144 | */ |
---|
145 | void MultiPlayerWorld::debug() |
---|
146 | { |
---|
147 | ((MultiPlayerWorldData*)this->dataTank)->debug(); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * cleanup |
---|
152 | * @return |
---|
153 | */ |
---|
154 | ErrorMessage MultiPlayerWorld::unloadData( ) |
---|
155 | { |
---|
156 | |
---|
157 | GameWorld::unloadData(); |
---|
158 | |
---|
159 | delete NetworkManager::getInstance(); |
---|
160 | delete NetworkGameManager::getInstance(); |
---|
161 | |
---|
162 | State::setOnline( false ); |
---|
163 | |
---|
164 | return ErrorMessage(); |
---|
165 | } |
---|