/[hegemonie]/hegemonie/GameEngine/HgGame.m
ViewVC logotype

Diff of /hegemonie/GameEngine/HgGame.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by dam, Sun Sep 7 13:23:36 2003 UTC revision 1.24 by dam, Tue Sep 9 00:46:49 2003 UTC
# Line 23  Line 23 
23    
24  #include <ode/objects.h>  #include <ode/objects.h>
25  #include <ode/space.h>  #include <ode/space.h>
26    #include <ode/geom.h>
27    
28  #include <Foundation/NSArray.h>  #include <Foundation/NSArray.h>
29  #include <Foundation/NSDictionary.h>  #include <Foundation/NSDictionary.h>
# Line 39  Line 40 
40  #include "GameEngine/HgTeam.h"  #include "GameEngine/HgTeam.h"
41  #include "Map/MapTerrain.h"  #include "Map/MapTerrain.h"
42  #include "Common/Coord.h"  #include "Common/Coord.h"
43    #include "Ode.h"
44    
45  @interface HgGame (Private)  @interface HgGame (Private)
46  - (void) _initDynamics;  - (void) _initDynamics;
# Line 75  static HgGame *_currentGame = nil; Line 77  static HgGame *_currentGame = nil;
77    /* FIXME - use QuadTreeSpece */    /* FIXME - use QuadTreeSpece */
78    _dSpace = dHashSpaceCreate (0);    _dSpace = dHashSpaceCreate (0);
79    
80      _dGround = dCreatePlane ([self dSpace], 0, 1, 0, [[self map] seaLevel]);
81    
82      _dContactGroup = dJointGroupCreate (0);
83    
84    [[NSRunLoop currentRunLoop]    [[NSRunLoop currentRunLoop]
85      performSelector: @selector(_mainLoop)      performSelector: @selector(_mainLoop)
86               target: self               target: self
# Line 131  static HgGame *_currentGame = nil; Line 137  static HgGame *_currentGame = nil;
137    RELEASE(_objects);    RELEASE(_objects);
138    RELEASE(_freePosition);    RELEASE(_freePosition);
139    
140      dJointGroupDestroy (_dContactGroup);
141      dGeomDestroy (_dGround);
142    dWorldDestroy (_dWorld);    dWorldDestroy (_dWorld);
143    dSpaceDestroy (_dSpace);    dSpaceDestroy (_dSpace);
144    
# Line 374  static HgGame *_currentGame = nil; Line 382  static HgGame *_currentGame = nil;
382    return _dSpace;    return _dSpace;
383  }  }
384    
385    - (dJointGroupID) dContactGroup
386    {
387      return _dContactGroup;
388    }
389    
390    static void
391    nearCallback (HgGame *game, dGeomID o1, dGeomID o2)
392    {
393      const int N = 10;
394      dContact contact[N];
395    
396      const int n = dCollide (o1, o2, N, &contact[0].geom, sizeof(dContact));
397    
398      int i;
399      for (i=0; i<n; i++)
400        {
401          contact[i].surface.mode = (dContactSlip1 | dContactSlip2
402                                     | dContactSoftERP | dContactSoftCFM
403                                     | dContactApprox1);
404          contact[i].surface.mu = dInfinity;
405          contact[i].surface.slip1 = 0.1;
406          contact[i].surface.slip2 = 0.1;
407          contact[i].surface.soft_erp = 0.5;
408          contact[i].surface.soft_cfm = 0.3;
409          dJointID joint
410            = dJointCreateContact ([game dWorld],
411                                   [game dContactGroup], &contact[i]);
412          dJointAttach (joint,
413                        dGeomGetBody(contact[i].geom.g1),
414                        dGeomGetBody(contact[i].geom.g2));
415        }
416    }
417    
418  /**  /**
419   * Updates the dynamics world associated with the game.   * Updates the dynamics world associated with the game.
420   */   */
421  - (void) _mainLoop  - (void) _mainLoop
422  {  {
423    dWorldStepFast1 (_dWorld, 0.05, 10);    dSpaceCollide ([self dSpace], self, (dNearCallback *)&nearCallback);
424      dWorldStepFast1 ([self dWorld], 0.05, 10);
425      dJointGroupEmpty ([self dContactGroup]);
426    
427    [[NSRunLoop currentRunLoop]    [[NSRunLoop currentRunLoop]
428      performSelector: @selector(_mainLoop)      performSelector: @selector(_mainLoop)

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26