/[enigma]/enigma/src/laser.cc
ViewVC logotype

Diff of /enigma/src/laser.cc

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

revision 1.12 by sfennig, Sat May 24 20:19:42 2003 UTC revision 1.13 by reallysoft, Mon May 26 09:41:42 2003 UTC
# Line 22  Line 22 
22  #include "actors.hh"  #include "actors.hh"
23  #include <algorithm>  #include <algorithm>
24  #include <cassert>  #include <cassert>
25    #include <map>
26    
27  using namespace world::laser;  using namespace world::laser;
28  using namespace world;  using namespace world;
29    using std::map;
30    
31  //======================================================================  //======================================================================
32  // TYPES  // TYPES
# Line 38  namespace Line 40  namespace
40      public:      public:
41          static void emit_from(GridPos p, Direction d);          static void emit_from(GridPos p, Direction d);
42          static void kill_all();          static void kill_all();
43            static void all_emitted();
44    
45          // LaserEmitter interface          // LaserEmitter interface
46          DirectionBits emission_directions() const { return directions; }          DirectionBits emission_directions() const { return directions; }
# Line 61  namespace Line 64  namespace
64    
65          // Variables          // Variables
66          DirectionBits directions;          DirectionBits directions;
67          static vector<void*> instances;  
68            static vector<LaserBeam*> instances;
69            static map<GridPos, int>  old_laser_positions;
70      };      };
71    
72  //----------------------------------------  //----------------------------------------
# Line 219  void PhotoStone::check_state() Line 224  void PhotoStone::check_state()
224  // stones and mirrors.  // stones and mirrors.
225  //----------------------------------------  //----------------------------------------
226    
227  vector<void*> LaserBeam::instances;  vector<LaserBeam*> LaserBeam::instances;
228    map<GridPos, int>  LaserBeam::old_laser_positions;
229    
230  void LaserBeam::init_model()  void LaserBeam::init_model()
231  {  {
# Line 294  bool LaserBeam::actor_hit(Actor *actor) Line 300  bool LaserBeam::actor_hit(Actor *actor)
300    
301  void LaserBeam::kill_all()  void LaserBeam::kill_all()
302  {  {
303        assert(old_laser_positions.empty());
304    
305      while (!instances.empty())      while (!instances.empty())
306      {      {
307          LaserBeam *lb = (LaserBeam*) instances[0];          LaserBeam *lb  = instances[0];
308          world::KillItem(lb->get_pos());          GridPos    pos = lb->get_pos();
309    
310            old_laser_positions[pos] = static_cast<int>(lb->directions);
311            world::KillItem(pos);
312        }
313    }
314    
315    void LaserBeam::all_emitted()
316    {
317        vector<LaserBeam*>::const_iterator end  = instances.end();
318        map<GridPos, int>::iterator        none = old_laser_positions.end();
319    
320        double x     = 0, y = 0;
321        int    count = 0;
322    
323        for (vector<LaserBeam*>::const_iterator i = instances.begin(); i != end; ++i) {
324            LaserBeam                   *lb    = *i;
325            GridPos                      pos   = lb->get_pos();
326            map<GridPos, int>::iterator  found = old_laser_positions.find(pos);
327    
328            if (found != none) {
329                // a beam was at the current position (during last kill_all())
330                DirectionBits old_dir = static_cast<DirectionBits>(found->second);
331    
332                if ((old_dir&lb->directions) != lb->directions) {
333                    // a beam has been added here
334                    x += pos.x;
335                    y += pos.y;
336                    ++count;
337                }
338            }
339            else {
340                // store newly created LaserBeams
341                x += pos.x;
342                y += pos.y;
343                ++count;
344            }
345        }
346    
347        if (count) {
348            sound::PlaySound("st-laser", px::V2(x/count+.5, y/count+.5));
349      }      }
350    
351        old_laser_positions.clear();
352  }  }
353    
354  void LaserBeam::dispose()  void LaserBeam::dispose()
# Line 338  void LaserStone::reemit_all() Line 388  void LaserStone::reemit_all()
388      }      }
389  }  }
390    
391  void LaserStone::notify_onoff(bool on)  void LaserStone::notify_onoff(bool /*on*/)
392  {  {
393      RecalcLight();      RecalcLight();
     if (on)  
         sound::PlaySound("st-laseron");  
394  }  }
395    
396  void LaserStone::emit_light()  void LaserStone::emit_light()
# Line 708  world::laser::RecalcLightNow() Line 756  world::laser::RecalcLightNow()
756          LaserBeam::kill_all();          LaserBeam::kill_all();
757          LaserStone::reemit_all();          LaserStone::reemit_all();
758          PhotoCell::notify_finish();          PhotoCell::notify_finish();
759            LaserBeam::all_emitted();
760          light_recalc_scheduled = false;          light_recalc_scheduled = false;
761      }      }
762  }  }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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