enigma-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Enigma-cvs] enigma/src world.cc,1.81,1.82


From: Daniel Heck <address@hidden>
Subject: [Enigma-cvs] enigma/src world.cc,1.81,1.82
Date: Thu, 20 Nov 2003 20:26:28 +0000

Update of /cvsroot/enigma/enigma/src
In directory subversions:/tmp/cvs-serv3956/src

Modified Files:
        world.cc 
Log Message:

- Renamed WorldImpl to World.  
- Moved get_accel() into class World.  
- Added stub for SetConstantForce().  
- Call Actor::on_creation() from AddActor() (this is usually done
  in InitWorld(), but this doesn't work when creating actors during
  the game, like CannonBalls).
- Added world::KillActor()
- Fixed bug in world::Tick() that lead to a core dump when adding
  a new actor during the game


Index: world.cc
===================================================================
RCS file: /cvsroot/enigma/enigma/src/world.cc,v
retrieving revision 1.81
retrieving revision 1.82
diff -C2 -d -r1.81 -r1.82
*** world.cc    16 Nov 2003 19:34:52 -0000      1.81
--- world.cc    20 Nov 2003 20:26:26 -0000      1.82
***************
*** 51,54 ****
--- 51,57 ----
  
  
+ 
+ /* -------------------- Signals -------------------- */
+ 
  Object *SimpleSignal::get_target()
  {
***************
*** 122,125 ****
--- 125,130 ----
  }
  
+ 
+ /* -------------------- RubberBand -------------------- */
  //----------------------------------------
  // Rubber band
***************
*** 261,265 ****
  
  
! WorldImpl::WorldImpl(int ww, int hh) : fields(ww,hh)
  {
      w = ww;
--- 266,270 ----
  
  
! World::World(int ww, int hh) : fields(ww,hh)
  {
      w = ww;
***************
*** 269,273 ****
  }
  
! WorldImpl::~WorldImpl()
  {
      fields = FieldArray(0,0);
--- 274,278 ----
  }
  
! World::~World()
  {
      fields = FieldArray(0,0);
***************
*** 276,280 ****
  }
  
! void WorldImpl::remove (ForceField *ff)
  {
      ForceList::iterator i=find (forces.begin(), forces.end(), ff);
--- 281,301 ----
  }
  
! bool World::contains (GridPos p) {
!     return (p.x>=0 && p.y>=0 && p.x<w && p.y<h);
! }
! 
! bool World::is_border (GridPos p) {
!     return(p.x==0 || p.y==0 || p.x==w-1 || p.y==h-1);
! }
! 
! Field *World::get_field (GridPos p) {
!     if (this->contains(p))
!         return &fields(p.x,p.y);
!     else
!         return 0;
! }
! 
! 
! void World::remove (ForceField *ff)
  {
      ForceList::iterator i=find (forces.begin(), forces.end(), ff);
***************
*** 283,287 ****
  }
  
! Object *WorldImpl::get_named (const string &name)
  {
      px::Dict<Object*>::iterator found = m_objnames.find(name);
--- 304,308 ----
  }
  
! Object *World::get_named (const string &name)
  {
      px::Dict<Object*>::iterator found = m_objnames.find(name);
***************
*** 289,293 ****
  }
  
! void WorldImpl::name_object (Object *obj, const std::string &name)
  {
      m_objnames.insert(name, obj); // [name] = obj;
--- 310,314 ----
  }
  
! void World::name_object (Object *obj, const std::string &name)
  {
      m_objnames.insert(name, obj); // [name] = obj;
***************
*** 295,299 ****
  }
  
! void WorldImpl::unname (Object *obj)
  {
      assert(obj);
--- 316,320 ----
  }
  
! void World::unname (Object *obj)
  {
      assert(obj);
***************
*** 305,309 ****
  }
  
! void WorldImpl::tick (double dtime)
  {
      mouseforce.tick (dtime);
--- 326,330 ----
  }
  
! void World::tick (double dtime)
  {
      mouseforce.tick (dtime);
***************
*** 322,331 ****
  //======================================================================
  
! void WorldImpl::add_scramble(GridPos p, Direction dir)
  {
      scrambles.push_back(Scramble(p, dir, scrambleIntensity));
  }
  
! void WorldImpl::scramble_puzzles()
  {
      while (!scrambles.empty()) {
--- 343,352 ----
  //======================================================================
  
! void World::add_scramble(GridPos p, Direction dir)
  {
      scrambles.push_back(Scramble(p, dir, scrambleIntensity));
  }
  
! void World::scramble_puzzles()
  {
      while (!scrambles.empty()) {
***************
*** 351,365 ****
  
  //======================================================================
- // VARIABLES
- //======================================================================
- 
- namespace
- {
-     auto_ptr<WorldImpl> level;
- }
- 
- 
- 
- //======================================================================
  // PHYSICS SIMULATION
  //======================================================================
--- 372,375 ----
***************
*** 370,375 ****
     only after a *successful* time step, so they cannot be used
     here.] */
! static V2
! get_accel (Actor *a, const V2 & x, const V2 & v, double time)
  {
      V2 f;
--- 380,384 ----
     only after a *successful* time step, so they cannot be used
     here.] */
! V2 World::get_accel (Actor *a, const V2 & x, const V2 & v, double time)
  {
      V2 f;
***************
*** 380,384 ****
  
              // Mouse force
!             V2 mousef (floor->process_mouseforce(a, 
level->mouseforce.get_force(a)));
              if (a->is_drunken()) {
                  // rotate mouse force by random angle
--- 389,393 ----
  
              // Mouse force
!             V2 mousef (floor->process_mouseforce(a, mouseforce.get_force(a)));
              if (a->is_drunken()) {
                  // rotate mouse force by random angle
***************
*** 413,418 ****
      // Electrostatic forces between actors.
      if (double q = a->get_charge()) {
!         for (ActorList::iterator i=level->actorlist.begin();
!              i != level->actorlist.end(); ++i)
          {
              Actor *a2 = *i;
--- 422,427 ----
      // Electrostatic forces between actors.
      if (double q = a->get_charge()) {
!         for (ActorList::iterator i=actorlist.begin();
!              i != actorlist.end(); ++i)
          {
              Actor *a2 = *i;
***************
*** 428,433 ****
  
      // All other force fields.
!     for (ForceList::iterator i=level->forces.begin();
!          i != level->forces.end(); ++i)
      {
          f += (*i)->get_force(a, x, v, time);
--- 437,442 ----
  
      // All other force fields.
!     for (ForceList::iterator i=forces.begin();
!          i != forces.end(); ++i)
      {
          f += (*i)->get_force(a, x, v, time);
***************
*** 440,443 ****
--- 449,463 ----
  }
  
+ 
+ //======================================================================
+ // VARIABLES
+ //======================================================================
+ 
+ namespace
+ {
+     auto_ptr<World> level;
+ }
+ 
+ 
  
  /* This function performs one step in the numerical integration of an
***************
*** 450,454 ****
  
      ActorInfo &ai = *a->get_actorinfo();
!     V2 accel = get_accel(a, ai.pos, ai.vel, time);
  
      // If the actor is currently in contact with other objects, remove
--- 470,474 ----
  
      ActorInfo &ai = *a->get_actorinfo();
!     V2 accel = level->get_accel(a, ai.pos, ai.vel, time);
  
      // If the actor is currently in contact with other objects, remove
***************
*** 764,768 ****
  void world::Create (int w, int h)
  {
!     level.reset (new WorldImpl(w,h));
      display::NewWorld(w, h);
  }
--- 784,788 ----
  void world::Create (int w, int h)
  {
!     level.reset (new World(w,h));
      display::NewWorld(w, h);
  }
***************
*** 864,870 ****
  }
  
! //----------------------------------------
! // Force fields
! //----------------------------------------
  
  void world::AddForceField(ForceField *ff)
--- 884,889 ----
  }
  
! 
! /* -------------------- Force fields -------------------- */
  
  void world::AddForceField(ForceField *ff)
***************
*** 877,883 ****
  }
  
! //----------------------------------------
! // Rubber bands
! //----------------------------------------
  
  void world::AddRubberBand (Actor *a, Stone *st, double strength,double length)
--- 896,906 ----
  }
  
! void world::SetConstantForce (V2 force) {
! 
! }
! 
! 
! 
! /* -------------------- Rubber bands -------------------- */
  
  void world::AddRubberBand (Actor *a, Stone *st, double strength,double length)
***************
*** 960,966 ****
  }
  
! //----------------------------------------
! // Signals
! //----------------------------------------
  
  void world::AddSignal (GridLoc srcloc, GridLoc dstloc, const string &msg)
--- 983,988 ----
  }
  
!  
! /* -------------------- Signals -------------------- */
  
  void world::AddSignal (GridLoc srcloc, GridLoc dstloc, const string &msg)
***************
*** 1057,1062 ****
  // "bombstone" : (sent by bombstone)
  
! void
! world::SendExplosionEffect(GridPos center, ExplosionType type) {
      const int AFFECTED_FIELDS       = 8;
      int       xoff[AFFECTED_FIELDS] = { 0, 0, 1,-1, 1,-1, 1,-1 };
--- 1079,1083 ----
  // "bombstone" : (sent by bombstone)
  
! void world::SendExplosionEffect(GridPos center, ExplosionType type) {
      const int AFFECTED_FIELDS       = 8;
      int       xoff[AFFECTED_FIELDS] = { 0, 0, 1,-1, 1,-1, 1,-1 };
***************
*** 1100,1111 ****
  }
  
  namespace
  {
- //----------------------------------------
- // Layer
- //
- // Changes to a layer are cached and only applied at the end of a
- // tick. [### not implemented]
- //----------------------------------------
      template <class T>
      class Layer {
--- 1121,1130 ----
  }
  
+ 
+ 
+ /* -------------------- Layer -------------------- */
+ 
  namespace
  {
      template <class T>
      class Layer {
***************
*** 1387,1405 ****
  //----------------------------------------
  
! void
! world::AddActor(double x, double y, Actor* a)
! {
!     V2 pos(x,y);
      level->actorlist.push_back(a);
!     a->get_actorinfo()->pos = pos;
! 
!     // now done in AddActor(int, Actor*) :
!     //     a->on_creation(pos);
!     //     ReleaseActor(a);
  }
  
! Actor *
! world::YieldActor(Actor *a)
! {
      ActorList::iterator i=find(level->actorlist.begin(), 
level->actorlist.end(), a);
      if (i!=level->actorlist.end()) {
--- 1406,1416 ----
  //----------------------------------------
  
! void world::AddActor(double x, double y, Actor* a) {
      level->actorlist.push_back(a);
!     a->get_actorinfo()->pos = V2(x, y);
!     a->on_creation(a->get_actorinfo()->pos);
  }
  
! Actor * world::YieldActor(Actor *a) {
      ActorList::iterator i=find(level->actorlist.begin(), 
level->actorlist.end(), a);
      if (i!=level->actorlist.end()) {
***************
*** 1411,1414 ****
--- 1422,1429 ----
  }
  
+ void world::KillActor (Actor *a) {
+     delete YieldActor (a);
+ }
+ 
  void world::WarpActor(Actor *a, double newx, double newy, bool keep_velocity)
  {
***************
*** 1537,1543 ****
  //----------------------------------------
  
! void
! world::Tick(double dtime)
! {
      const double timestep = 15.0/1000;
      static double timeaccu = 0.0;
--- 1552,1556 ----
  //----------------------------------------
  
! void world::Tick(double dtime) {
      const double timestep = 15.0/1000;
      static double timeaccu = 0.0;
***************
*** 1548,1560 ****
      {
        // Move actors
!         for (ActorList::iterator i=level->actorlist.begin(); 
i!=level->actorlist.end(); ++i) {
!             ActorInfo *ai = (*i)->get_actorinfo();
!             if (!ai->grabbed && !(*i)->is_dead())
              {
                ai->force= ai->forceacc;
                ai->forceacc = V2();
!                 tick_actor(*i, timestep);
              }
!           (*i)->think(timestep);
          }
  
--- 1561,1574 ----
      {
        // Move actors
!         for (unsigned i=0; i<level->actorlist.size(); ++i) {
!             Actor *a = level->actorlist[i];
!             ActorInfo *ai = a->get_actorinfo();
!             if (!ai->grabbed && !a->is_dead())
              {
                ai->force= ai->forceacc;
                ai->forceacc = V2();
!                 tick_actor(a, timestep);
              }
!           a->think(timestep);
          }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]