~ubuntu-branches/ubuntu/saucy/enigma/saucy

« back to all changes in this revision

Viewing changes to src/stones/LaserStone.hh

  • Committer: Bazaar Package Importer
  • Author(s): Erich Schubert
  • Date: 2010-05-26 02:27:26 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100526022726-7tnbf65s6btbibu2
Tags: 1.10~~pre-alpha+r2100-1
* New SVN checkout, shortly after upstream "pre-alpha" release
* Target unstable, to get more testing for enigma
* Remove spelling patches included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Ronald Lamprecht
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 */
 
19
#ifndef LASERSTONE_HH
 
20
#define LASERSTONE_HH
 
21
 
 
22
#include "laser.hh"
 
23
#include <list>
 
24
 
 
25
namespace enigma {
 
26
 
 
27
    /** 
 
28
     * 
 
29
     * 
 
30
     * When a laser is switched on or off this may directly cause an action. 
 
31
     * A part of such an action can be another laser switching of the same laser.
 
32
     * To break infinit loops and to avoid laser flickering at a frequency that
 
33
     * the user cannot recognize laser switching is limited. After a switching
 
34
     * a laser stays in a NEW* state where further switch requests are delayed.
 
35
     */
 
36
    class LaserStone : public Stone, public TimeHandler {
 
37
    private:
 
38
        enum iState {
 
39
            OFF, 
 
40
            ON, 
 
41
            NEW_OFF,
 
42
            NEW_ON,
 
43
            NEW_OFF_PENDING_ON,
 
44
            NEW_ON_PENDING_OFF
 
45
        };
 
46
        typedef std::list<LaserStone*> InstanceList;
 
47
        static InstanceList instances;
 
48
 
 
49
    public:
 
50
        static void reemit_all();
 
51
 
 
52
        LaserStone(Direction dir=EAST);
 
53
 
 
54
        // Object interface
 
55
        virtual std::string getClass() const;
 
56
        virtual LaserStone *clone();
 
57
        virtual void dispose();
 
58
        virtual void setAttr(const string& key, const Value &val);
 
59
        virtual Value message(const Message &m);
 
60
        
 
61
        // StateObject interface
 
62
        virtual int externalState() const;
 
63
        virtual void setState(int extState);
 
64
        virtual void toggleState();
 
65
 
 
66
        // GridObject interface
 
67
        virtual void init_model();
 
68
        virtual void on_creation(GridPos p);
 
69
        virtual void on_removal(GridPos p);
 
70
        virtual DirectionBits emissionDirections() const;
 
71
        
 
72
        // TimeHandler interface
 
73
        virtual void alarm();
 
74
 
 
75
        
 
76
    private:
 
77
        // Private methods.
 
78
        void emit_light();
 
79
        Direction getOrientation() const;
 
80
    };
 
81
 
 
82
} // namespace enigma
 
83
 
 
84
#endif