21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 |
*/ |
*/ |
23 |
|
|
24 |
|
#include <ode/objects.h> |
25 |
|
|
26 |
#include <Foundation/NSArray.h> |
#include <Foundation/NSArray.h> |
27 |
#include <Foundation/NSDictionary.h> |
#include <Foundation/NSDictionary.h> |
28 |
#include <Foundation/NSException.h> |
#include <Foundation/NSException.h> |
29 |
#include <Foundation/NSCoder.h> |
#include <Foundation/NSCoder.h> |
30 |
#include <Foundation/NSValue.h> |
#include <Foundation/NSValue.h> |
31 |
#include <Foundation/NSNotification.h> |
#include <Foundation/NSNotification.h> |
32 |
|
#include <Foundation/NSRunLoop.h> |
33 |
|
|
34 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
35 |
#include "GameEngine/HgPlayer.h" |
#include "GameEngine/HgPlayer.h" |
37 |
#include "GameEngine/HgTeam.h" |
#include "GameEngine/HgTeam.h" |
38 |
#include "Map/MapTerrain.h" |
#include "Map/MapTerrain.h" |
39 |
|
|
40 |
|
@interface HgGame (Private) |
41 |
|
- (void) _mainLoop; |
42 |
|
@end |
43 |
|
|
44 |
/** |
/** |
45 |
* HgGame stores players, teams, and objects wich belongs to the |
* HgGame stores players, teams, and objects wich belongs to the |
59 |
|
|
60 |
|
|
61 |
/** |
/** |
62 |
|
* Initializes the dynamics associated with the game. |
63 |
|
* This methods also register the dynamics update in the currentRunLoop. |
64 |
|
*/ |
65 |
|
- (void) _initDynamics |
66 |
|
{ |
67 |
|
_dWorld = dWorldCreate (); |
68 |
|
dWorldSetGravity (_dWorld, 0.0, -0.5, 0.0); |
69 |
|
[[NSRunLoop currentRunLoop] |
70 |
|
performSelector: @selector(_mainLoop) |
71 |
|
target: self |
72 |
|
argument: nil |
73 |
|
order: 600000 |
74 |
|
modes: [NSArray arrayWithObjects: |
75 |
|
NSDefaultRunLoopMode, nil]]; |
76 |
|
} |
77 |
|
|
78 |
|
/** |
79 |
* Initialize a new game, with a given name. |
* Initialize a new game, with a given name. |
80 |
* Post an notification named "newGame" containing the game. |
* Post an notification named "newGame" containing the game. |
81 |
*/ |
*/ |
92 |
_teams = [[NSMutableDictionary alloc] init]; |
_teams = [[NSMutableDictionary alloc] init]; |
93 |
_map = nil; |
_map = nil; |
94 |
_objects = [[NSMutableDictionary alloc] init]; |
_objects = [[NSMutableDictionary alloc] init]; |
95 |
|
[self _initDynamics]; |
96 |
|
|
97 |
_currentGame = self; |
_currentGame = self; |
98 |
} |
} |
110 |
{ |
{ |
111 |
_currentGame = nil; |
_currentGame = nil; |
112 |
|
|
113 |
|
dWorldDestroy (_dWorld); |
114 |
RELEASE(_name); |
RELEASE(_name); |
115 |
RELEASE(_players); |
RELEASE(_players); |
116 |
RELEASE(_teams); |
RELEASE(_teams); |
294 |
return _objects; |
return _objects; |
295 |
} |
} |
296 |
|
|
297 |
|
|
298 |
|
/** |
299 |
|
* Returns the dynamic world associated with the game. |
300 |
|
*/ |
301 |
|
- (dWorldID) dWorld |
302 |
|
{ |
303 |
|
return _dWorld; |
304 |
|
} |
305 |
|
|
306 |
|
/** |
307 |
|
* Updates the dynamics world associated with the game. |
308 |
|
*/ |
309 |
|
- (void) _mainLoop |
310 |
|
{ |
311 |
|
dWorldStepFast1 (_dWorld, 0.05, 10); |
312 |
|
|
313 |
|
[[NSRunLoop currentRunLoop] |
314 |
|
performSelector: @selector(_mainLoop) |
315 |
|
target: self |
316 |
|
argument: nil |
317 |
|
order: 600000 |
318 |
|
modes: [NSArray arrayWithObjects: |
319 |
|
NSDefaultRunLoopMode, nil]]; |
320 |
|
} |
321 |
|
|
322 |
@end |
@end |
323 |
|
|
324 |
|
|