namespace lmlCommand
{
- bool action_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN action(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ {
+ return LML_CMDRTN_NEXT;
+ }
+
+ LML_CMDRTN action_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
#ifdef DEBUG
printf("action closed [%s]\n", param.getTag(0)->param.getString(0));
obj.activeActionStack.close();
}
- return obj.activeActionStack.has();
- }
-
- bool event(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
- {
- return true;
+ return LML_CMDRTN_STOP | LML_CMDRTN_REACTION;
}
- bool event_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN event_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
#ifdef DEBUG
printf("event closed [%s]\n", param.getTag(0)->param.getString(0));
obj.activeEventStack.close();
}
- return obj.activeEventStack.has();
+ return LML_CMDRTN_STOP | LML_CMDRTN_REACTION;
}
- bool print(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN print(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
printf(param.getText(0, runner));
printf("\n");
- return true;
+ return LML_CMDRTN_NEXT;
}
- bool active(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN active(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
#ifdef DEBUG
printf("active [%s]\n", param.getText(0, runner));
#endif
runner.addActor(param.getText(0, runner));
- return true;
+ return LML_CMDRTN_NEXT;
}
- bool repeat(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN repeat(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
*obj.repeatCounter.push_back() = param.has(1) ? param.getInteger(1, runner) : -1;
- return true;
+ return LML_CMDRTN_NEXT;
}
- bool repeat_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN repeat_close(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
unsigned int *counter = obj.repeatCounter.back();
if (*counter > 1)
}
else obj.repeatCounter.remove(counter);
- return true;
+ return LML_CMDRTN_NEXT;
}
- bool rcontinue(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN rcontinue(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
Tag **t = &obj.activeActionStack.current()->tag;
*t = param.getTag(0)->param.getTag(0);
- *t = (Tag*)((list_item<Tag>*)*t)->prev;
- return true;
+ return LML_CMDRTN_NULL;
}
- bool rbreak(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN rbreak(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
- if (obj.repeatCounter.back() == NULL) return false;
+ if (obj.repeatCounter.back() == NULL) return LML_CMDRTN_NEXT;
(*obj.repeatCounter.back()) = 0;
return rcontinue(param, obj, runner);
}
- bool wait(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN wait(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
if (obj.waitCounter) obj.waitCounter--;
else obj.waitCounter = param.getInteger(0, runner);
- return obj.waitCounter == 0;
+ return obj.waitCounter ? LML_CMDRTN_STOP : LML_CMDRTN_NEXT;
}
- bool val(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN val(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
variable_size id = *(variable_size*)param.get(0);
#ifdef DEBUG
#endif
runner.getVariable(id)->setFixedFloat(id, param.getFixedFloat(1, runner));
- return true;
+ return LML_CMDRTN_NEXT;
}
- bool actionRef(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
+ LML_CMDRTN actionRef(LMLParameter ¶m, LMLObject &obj, LiveMLRunner &runner)
{
#ifdef DEBUG
printf("actionRef: %s\n", param.getText(0, runner));
obj.setAction(ap);
}
- return true;
+ return LML_CMDRTN_STOP | LML_CMDRTN_NEXT | LML_CMDRTN_REACTION;
}
}
_scene.activeActionStack.list.allocator(&_actionAllocator);
_scene.activeEventStack.list.allocator(&_actionAllocator);
- registerCommand("action", NULL, lmlCommand::action_close);
registerCommand("print", lmlCommand::print);
registerCommand("active", lmlCommand::active);
- registerCommand("event", lmlCommand::event);
+ registerCommand("action", lmlCommand::action, lmlCommand::action_close);
+ registerCommand("event", NULL, lmlCommand::event_close);
registerCommand("repeat", lmlCommand::repeat, lmlCommand::repeat_close);
registerCommand("continue", lmlCommand::rcontinue);
registerCommand("break", lmlCommand::rbreak);
bool LiveMLRunner::registerCommand(
const char* name,
- bool (*func)(LMLParameter&, LMLObject&, LiveMLRunner&),
- bool (*closeFunc)(LMLParameter&, LMLObject&, LiveMLRunner&)
+ LML_CMDRTN (*func)(LMLParameter&, LMLObject&, LiveMLRunner&),
+ LML_CMDRTN (*closeFunc)(LMLParameter&, LMLObject&, LiveMLRunner&)
)
{
tag_type id = parser->getTagTypeId(name);
return true;
}
-bool LiveMLRunner::runCommand(LMLObject &obj, Tag *tag)
+LML_CMDRTN LiveMLRunner::runCommand(LMLObject &obj, Tag *tag)
{
- Tag **activeTag = &obj.activeActionStack.current()->tag;
- *activeTag = tag;
+ LML_CMDRTN (*func)(LMLParameter&, LMLObject&, LiveMLRunner&) = NULL;
+ TagType *rt = tag->type;
- setCurrentObject(&obj);
-
- while (tag != NULL)
+ // close a tag
+ if (rt == NULL)
{
- bool (*func)(LMLParameter&, LMLObject&, LiveMLRunner&) = NULL;
- TagType *rt = tag->type;
-
- if (rt == NULL)
- {
- if (tag->param.getTag(0)->type != NULL)
- {
- rt = tag->param.getTag(0)->type;
- func = _commandFuncs[rt->id].closeFunc;
- }
- }
- else
- {
- func = _commandFuncs[rt->id].func;
- }
+ rt = tag->param.getTag(0)->type;
+ func = _commandFuncs[rt->id].closeFunc;
+#ifdef DEBUG
+ printf("close tag: %s\n", rt->getName().c_str());
+#endif
+ }
+ else
+ {
+ func = _commandFuncs[rt->id].func;
+ }
- if (func != NULL)
- {
+ LML_CMDRTN result = LML_CMDRTN_NEXT;
+ if (func != NULL)
+ {
#ifdef DEBUG
- printf("execute command: %s\n", rt->getName().c_str());
+ printf("execute command: %s\n", rt->getName().c_str());
#endif
- bool result = (*func)((LMLParameter&)tag->param, obj, *this);
- text_decode_clear();
+ result = (*func)((LMLParameter&)tag->param, obj, *this);
+ text_decode_clear();
#ifdef DEBUG
- printf("finish command: %s\n", rt->getName().c_str());
+ printf("finish command: %s\n", rt->getName().c_str());
#endif
- if (result == false) return false;
- activeTag = &obj.activeActionStack.current()->tag;
- }
+ }
- tag = *activeTag = (Tag*)((list_item<Tag>*)*activeTag)->next;
+ return result;
+}
+
+LML_CMDRTN LiveMLRunner::runAction(LMLObject &obj, ActiveAction &aa)
+{
+ LML_CMDRTN result = LML_CMDRTN_NULL;
+
+ while (aa.tag != NULL)
+ {
+ result = runCommand(obj, aa.tag);
+
+ if (result & LML_CMDRTN_NEXT)
+ {
+ aa.tag = list_next(aa.tag);
+ }
+ if (result & LML_CMDRTN_STOP)
+ {
+ break;
+ }
}
- return true;
+ return result;
}
-bool LiveMLRunner::runObjectEvent(LMLObject &obj)
+bool LiveMLRunner::runActiveEvents(LMLObject &obj)
{
bindGlobalEvent(obj);
while (obj.activeEventStack.has())
{
- runCommand(obj, obj.activeEventStack.current()->tag);
+ ActiveAction *aa = obj.activeEventStack.current();
+ LML_CMDRTN result = runAction(obj, *aa);
+ if (result & LML_CMDRTN_REACTION)
+ {
+ continue;
+ }
}
return obj.activeEventStack.has();
}
-bool LiveMLRunner::runObjectAction(LMLObject &obj)
+bool LiveMLRunner::runActiveActions(LMLObject &obj)
{
- if (!obj.activeActionStack.has()) return false;
+ while (obj.activeActionStack.has())
+ {
+ ActiveAction *aa = obj.activeActionStack.current();
+ LML_CMDRTN result = runAction(obj, *aa);
- runCommand(obj, obj.activeActionStack.current()->tag);
+ if ((result & LML_CMDRTN_STOP) && !(result & LML_CMDRTN_REACTION))
+ {
+ break;
+ }
+ }
- return true;
+ return obj.activeActionStack.has();
}
bool LiveMLRunner::runObject(LMLObject &obj)
{
- return runObjectEvent(obj) | runObjectAction(obj);
+ setCurrentObject(&obj);
+ return runActiveEvents(obj) | runActiveActions(obj);
}
LMLSceneObject* LiveMLRunner::setScene(const char *name)
obj->activeActionStack.list.allocator(&_actionAllocator);
obj->activeEventStack.list.allocator(&_actionAllocator);
obj->repeatCounter.allocator(&_repeatAllocator);
- obj->setAction((size_t)0);
+ obj->setAction((action_type)0);
+ obj->addEvent((event_type)0);
#ifdef DEBUG
printf("add actor: end\n");
#endif
#ifdef DEBUG
printf("execute actor: start\n");
#endif
- LMLActorObject *actorNext = (LMLActorObject*)((list_item<LMLActorObject>*)actor)->next;
+ LMLActorObject *actorNext = list_next(actor);
running |= runObject((LMLObject&)*actor);
actor = actorNext;
#ifdef DEBUG
#include "list.hpp"
#include "bool_list.hpp"
+typedef int LML_CMDRTN;
+enum
+{
+ LML_CMDRTN_NULL = 0x00,
+ LML_CMDRTN_STOP = 0x01,
+ LML_CMDRTN_NEXT = 0x02,
+ LML_CMDRTN_REACTION = 0x04,
+};
+
class LiveMLRunner;
class LMLParameter : public Parameter
public:
list<T> list;
- ActiveAction* current(void)
+ T* current(void)
{
return list.back();
}
- ActiveAction* add(void)
+ T* add(void)
{
return list.push_back();
}
EventParser *event = parser->eventContainer[type];
if (event == NULL) return false;
- addEvent(event);
#ifdef DEBUG
printf("LMLObject::setEvent(%d) end.\n", type);
#endif
- return true;
+ return addEvent(event);
}
};
{
struct FuncPtr
{
- bool (*func)(LMLParameter&, LMLObject&, LiveMLRunner&);
- bool (*closeFunc)(LMLParameter&, LMLObject&, LiveMLRunner&);
+ LML_CMDRTN (*func)(LMLParameter&, LMLObject&, LiveMLRunner&);
+ LML_CMDRTN (*closeFunc)(LMLParameter&, LMLObject&, LiveMLRunner&);
};
struct OnEvent
bool registerCommand(
const char*,
- bool (*)(LMLParameter&, LMLObject&, LiveMLRunner&),
- bool (*)(LMLParameter&, LMLObject&, LiveMLRunner&) = NULL
+ LML_CMDRTN (*)(LMLParameter&, LMLObject&, LiveMLRunner&),
+ LML_CMDRTN (*)(LMLParameter&, LMLObject&, LiveMLRunner&) = NULL
);
void setMaxActors(size_t);
void onEvent(event_type id) { _onEventList.push_back()->id = id; }
void bindGlobalEvent(LMLObject&);
- bool runCommand(LMLObject&, Tag*);
- bool runObjectEvent(LMLObject&);
- bool runObjectAction(LMLObject&);
+ LML_CMDRTN runCommand(LMLObject&, Tag*);
+ LML_CMDRTN runAction(LMLObject&, ActiveAction&);
+ bool runActiveEvents(LMLObject&);
+ bool runActiveActions(LMLObject&);
bool runObject(LMLObject&);
bool run(void);
LMLVariable* getVariable(variable_size);