1 /** * LiveML - LiveML is screen(graphic) controling library using XML.
4 * Copyright (C) 2010 Nothan
5 * http://github.com/nothan/liveml/
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * private@nothan.xrea.jp
26 * http://tsuioku-denrai.xrea.jp/
29 #ifndef __LIVEMLRUNNER_H__
30 #define __LIVEMLRUNNER_H__
32 #include "livemlparser.h"
34 #include "bool_list.hpp"
36 #define LML_CMDFUNC(name) LML_CMDRTN name(LMLParameter ¶m)
38 typedef int LML_CMDRTN;
41 LML_CMDRTN_NULL = 0x00,
42 LML_CMDRTN_STOP = 0x01,
43 LML_CMDRTN_NEXT = 0x02,
44 LML_CMDRTN_REACTION = 0x04,
49 struct NumericVariable
57 fixed_float* getNumeric(variable_size id)
60 printf("LMLVariable::getNumeric(%d)\n", id);
62 id = VAR_LOCAL_ID(id);
63 NumericVariable *v = numericList.front();
69 numericList.chain_front(v);
72 v = (NumericVariable*)((list_item<NumericVariable>*)v)->next;
78 printf("added variable %d\n", id);
80 v = numericList.push_front();
87 list<NumericVariable> numericList;
91 numericList.clear(true);
94 void setFixedFloat(variable_size id, fixed_float v)
97 printf("LMLVariable::setFixedFloat(%d) = %d\n", id, v);
102 void setString(variable_size id, const char *v)
106 fixed_float getFixedFloat(variable_size id)
109 printf("LMLVariable::getFixedFloat(%d) = %d\n", id, *getNumeric(id));
111 return *getNumeric(id);
114 const char* getString(variable_size id)
123 ActionParser *action;
126 LMLVariable variable;
147 return list.push_back();
165 return current() != NULL;
169 class ActiveActionStack : public ActiveStack<ActiveAction>
172 unsigned int waitCounter;
173 ::list<unsigned int> repeatCounter;
176 class ActiveEventStack : public ActiveActionStack
183 ActiveActionStack activeActionStack;
184 ActiveEventStack activeEventStack;
187 LMLVariable variable;
202 activeActionStack.waitCounter = 0;
203 activeEventStack.waitCounter = 0;
211 void setRepeatAllocator(list_allocator<unsigned int> *alloc)
213 activeActionStack.repeatCounter.allocator(alloc);
214 activeEventStack.repeatCounter.allocator(alloc);
217 void setVariableAllocator(list_allocator<NumericVariable> *alloc)
219 variable.numericList.allocator(alloc);
222 bool setAction(ActionParser *action)
225 printf("LMLObject::setAction(ActionParser*) begin.\n");
227 if (action == NULL) return false;
229 ActiveAction *aa = activeActionStack.add();
231 aa->variable.numericList.allocator(variable.numericList.get_allocator());
232 aa->tag = action->tag;
234 printf("LMLObject::setAction(ActionParser*) end.\n");
238 bool setAction(action_type type)
241 printf("LMLObject::setAction(%d) begin.\n", type);
243 ActionParser *action = parser->actionContainer[type];
244 if (action == NULL) return false;
248 printf("LMLObject::setAction(%d) end.\n", type);
252 bool setActionByName(const char *name)
255 printf("LMLObject::setActionByName(%s)\n", name);
257 return setAction(parser->actionContainer[name]);
260 bool setEvent(EventParser *event)
263 printf("LMLObject::setEvent(EventParser*) begin.\n");
265 if (event == NULL) return false;
267 activeEventStack.clear();
268 ActiveAction *aa = activeEventStack.add();
269 aa->action = (ActionParser*)event;
270 aa->variable.numericList.allocator(variable.numericList.get_allocator());
271 aa->tag = event->tag;
273 printf("LMLObject::setEvent(EventParser*) end.\n");
278 bool setEvent(event_type type)
281 printf("LMLObject::setEvent(%d) begin.\n", type);
283 EventParser *event = parser->eventContainer[type];
284 if (event == NULL) return false;
287 printf("LMLObject::setEvent(%d) end.\n", type);
289 return setEvent(event);
293 struct LMLSceneObject : public LMLObject
297 struct LMLActorObject : public LMLObject
303 friend class LiveMLRunner;
306 LiveMLRunner *runner;
308 ActiveActionStack *actionStack;
310 LMLParameter(Parameter *param, LiveMLRunner *runner, LMLObject *obj, ActiveActionStack *actionStack)
313 this->runner = runner;
315 this->actionStack = actionStack;
318 LMLVariable* getVariable(variable_size);
319 float getFloat(size_t);
320 int getInteger(size_t);
321 int getFixedFloat(size_t);
322 const char* getText(size_t);
325 const void* get(size_t);
327 const char* getString(size_t);
334 LML_CMDRTN (*func)(LMLParameter&);
335 LML_CMDRTN (*closeFunc)(LMLParameter&);
338 LMLSceneObject _scene;
339 list<LMLActorObject> _actorList;
340 LMLActorObject *_currentActor;
341 LMLObject *_currentObject;
342 vector<FuncPtr> _commandFuncs;
344 list_allocator<ActiveAction> _actionAllocator;
345 list_allocator<unsigned int> _repeatAllocator;
346 list_allocator<NumericVariable> _numericVariableAllocator;
349 LiveMLParser *parser;
351 LMLVariable variable;
353 LiveMLRunner(LiveMLParser*);
356 bool registerCommand(
358 LML_CMDRTN (*)(LMLParameter&),
359 LML_CMDRTN (*)(LMLParameter&) = NULL
362 void setMaxActors(size_t);
363 LMLSceneObject* setScene(const char*);
364 LMLActorObject* addActor(const char*);
366 void setCurrentActor(LMLActorObject *obj) { _currentActor = obj; }
367 LMLActorObject* getCurrentActor(void) { return _currentActor; }
369 void setCurrentObject(LMLObject *obj) { _currentObject = obj; }
370 LMLObject* getCurrentObject(void) { return _currentObject; }
372 LML_CMDRTN runCommand(LMLParameter&, Tag*);
373 LML_CMDRTN runAction(LMLParameter&);
374 void callEvent(LMLObject&, event_type);
375 void callEvent(event_type);
376 bool runActiveActions(LMLObject&);
377 bool runObject(LMLObject&);
380 static fixed_float variableNumericDecoder(variable_size, void*);
381 static const char* variableStringDecoder(variable_size, void*);
384 #endif // __LIVEMLRUNNER_H__