OSDN Git Service

first commit
[liveml/LiveML.git] / src / livemlrunner.h
1 /**
2  * LiveML - LiveML is screen(graphic) controling library using XML.
3  *
4  * LGPL License
5  * Copyright (C) 2010 Nothan
6  * http://github.com/nothan/liveml/
7  * All rights reserved.
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Library General Public
11  *  License as published by the Free Software Foundation; either
12  *  version 2 of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Library General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Library General Public
20  *  License along with this library; if not, write to the Free
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  * Nothan
24  * private@nothan.xrea.jp
25  *
26  * Tsuioku Denrai
27  * http://tsuioku-denrai.xrea.jp/
28  */
29
30 #ifndef __LIVEMLRUNNER_H__
31 #define __LIVEMLRUNNER_H__
32
33 #include "livemlparser.h"
34 #include "list.hpp"
35 #include "bool_list.hpp"
36
37 struct LMLObject
38 {
39 public:
40   TagAct *parser;
41   list<ActionParser*> currentActionList;
42   list<Tag*> currentTagList;
43   unsigned int waitCounter;
44   list<unsigned int> repeatCounter;
45
46   void init()
47   {
48     parser = NULL;
49     waitCounter = 0;
50   }
51
52   bool setAction(ActionParser *action)
53   {
54     *currentActionList.push_back() = action;
55     if (action == NULL) return false;
56     *currentTagList.push_back() = action->tag;
57
58     return true;
59   }
60   bool setAction(action_type type)
61   {
62     ActionParser *action = parser->actionContainer.getAction(type);
63     if (action == NULL) return false;
64
65     setAction(action);
66     return true;
67   }
68   bool setActionByName(const char *name)
69   {
70     action_type type = parser->actionContainer.getActionType(name);
71     printf("find %s => %d\n", name, type);
72     return setAction(type);
73   }
74 };
75
76 struct LMLSceneObject : public LMLObject
77 {
78 };
79
80 struct LMLActorObject : public LMLObject
81 {
82 };
83
84 class LiveMLRunner
85 {
86   struct FuncPtr
87   {
88     bool (*func)(Parameter&, LMLObject&, LiveMLRunner&);
89     bool (*closeFunc)(Parameter&, LMLObject&, LiveMLRunner&);
90   };
91
92   LMLSceneObject _scene;
93   list<LMLActorObject> _actorList;
94   LMLActorObject *_currentActor;
95   LMLObject *_focusObject;
96   vector<FuncPtr> _commandFuncs;
97   bool_list _eventFlag;
98   list_allocator<ActionParser*> _actionAllocator;
99   list_allocator<Tag*> _tagAllocator;
100   list_allocator<unsigned int> _repeatAllocator;
101
102 public:
103   LiveMLParser *parser;
104   bool registerCommand(
105     const char*,
106     bool (*)(Parameter&, LMLObject&, LiveMLRunner&),
107     bool (*)(Parameter&, LMLObject&, LiveMLRunner&) = NULL
108   );
109
110   LiveMLRunner(LiveMLParser*);
111
112   void setMaxActors(size_t);
113   LMLSceneObject* setScene(const char*);
114   LMLActorObject* addActor(const char*);
115
116   LMLActorObject* setCurrentActor(LMLActorObject *obj) { _currentActor = obj; }
117   LMLActorObject* getCurrentActor(void) { return _currentActor; }
118
119   void setFocusObject(LMLObject* obj) { _focusObject = obj; }
120   LMLObject* getFocusObject(void) { return  _focusObject; }
121
122   void onEvent(size_t index) { _eventFlag.on(index); }
123   void offEvent(size_t index) { _eventFlag.off(index); }
124   bool stateEvent(size_t index) { return _eventFlag[index]; }
125   bool_list getbool_lists(void) { return _eventFlag; }
126   void setbool_lists(bool_list &f) { _eventFlag = f; }
127
128   bool runCommand(LMLObject&, Tag*);
129   bool runObjectEvent(LMLObject&);
130   bool runObjectAction(LMLObject&);
131   bool runObject(LMLObject&);
132   void run(void);
133 };
134
135 #endif // __LIVEMLRUNNER_H__