From 16dcad8d0d2fbd30deac13979062eee67450a8d4 Mon Sep 17 00:00:00 2001 From: nothan Date: Thu, 17 Feb 2011 06:09:39 +0900 Subject: [PATCH] Changing the design of the event --- src/livemlparser.cpp | 4 +++- src/livemlrunner.cpp | 43 +++++++++++++++++++++++-------------------- src/livemlrunner.h | 19 ++++++------------- src/xmlparser.h | 7 ++++++- test/test.xml | 3 +++ 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/livemlparser.cpp b/src/livemlparser.cpp index 41db5fb..3465b85 100644 --- a/src/livemlparser.cpp +++ b/src/livemlparser.cpp @@ -40,6 +40,7 @@ namespace lmlTag { LiveMLParser &p = (LiveMLParser&)parser; SceneParser *scene = p.sceneContainer.add(p.getCurrentTag()); + scene->eventContainer.resize(p.eventTypeContainer.size()); p.setCurrentScene(scene); if (param.has(1)) @@ -56,6 +57,7 @@ namespace lmlTag LiveMLParser &p = (LiveMLParser&)parser; ActorParser *actor = p.actorContainer.add(p.getCurrentTag()); p.setCurrentActor(actor); + actor->eventContainer.resize(p.eventTypeContainer.size()); if (param.has(1)) { @@ -95,7 +97,7 @@ namespace lmlTag #ifdef DEBUG printf("added event[%s]\n", param.getString(0)); #endif - ec->add(p.getCurrentTag()); + ec->get(et)->tag = p.getCurrentTag(); p.variableList[VAR_SCOPE_LOCAL].clear(); return true; diff --git a/src/livemlrunner.cpp b/src/livemlrunner.cpp index 7a2a7bb..82b7939 100644 --- a/src/livemlrunner.cpp +++ b/src/livemlrunner.cpp @@ -253,7 +253,6 @@ LiveMLRunner::LiveMLRunner(LiveMLParser *p) _commandFuncs.resize(parser->countTagType()); _currentActor = NULL; _currentObject = NULL; - _onEventList.resize(parser->eventTypeContainer.size()); _scene.setVariableAllocator(&_numericVariableAllocator); _scene.setRepeatAllocator(&_repeatAllocator); @@ -348,19 +347,34 @@ LML_CMDRTN LiveMLRunner::runAction(LMLParameter& param) return result; } -bool LiveMLRunner::runActiveEvents(LMLObject &obj) +void LiveMLRunner::callEvent(LMLObject &obj, event_type id) { - bindGlobalEvent(obj); + if (!obj.setEvent(id)) return; - while (obj.activeEventStack.has()) + do { LMLParameter param(NULL, this, &obj, &(ActiveActionStack)obj.activeEventStack); LML_CMDRTN result = runAction(param); - if (result & LML_CMDRTN_REACTION) continue; + if ((result & LML_CMDRTN_STOP) && !(result & LML_CMDRTN_REACTION)) break; + } + while (obj.activeEventStack.has()); +} + +void LiveMLRunner::callEvent(event_type id) +{ + if (_scene.parser) + { + callEvent((LMLObject&)_scene, id); } - return obj.activeEventStack.has(); + LMLActorObject *actor = _actorList.front(); + while (actor) + { + LMLActorObject *actorNext = list_next(actor); + callEvent((LMLObject&)*actor, id); + actor = actorNext; + } } bool LiveMLRunner::runActiveActions(LMLObject &obj) @@ -378,7 +392,7 @@ bool LiveMLRunner::runActiveActions(LMLObject &obj) bool LiveMLRunner::runObject(LMLObject &obj) { - return runActiveEvents(obj) | runActiveActions(obj); + return runActiveActions(obj); } LMLSceneObject* LiveMLRunner::setScene(const char *name) @@ -408,7 +422,7 @@ LMLActorObject* LiveMLRunner::addActor(const char *name) obj->activeEventStack.list.allocator(&_actionAllocator); obj->setRepeatAllocator(&_repeatAllocator); obj->setAction((action_type)0); - obj->addEvent((event_type)0); + callEvent(*obj, (event_type)0); #ifdef DEBUG printf("add actor: end\n"); #endif @@ -439,24 +453,13 @@ bool LiveMLRunner::run(void) #endif } - _onEventList.clear(true); - return running; } -void LiveMLRunner::bindGlobalEvent(LMLObject &obj) -{ -/* - while (OnEvent e = _onEventList.front(); ) - { - addEvent(e.id); - } -*/ -} - void LiveMLRunner::setMaxActors(size_t size) { _actorList.resize(size); + size++; _repeatAllocator.resize(size * 5); _actionAllocator.resize(size * 5); _numericVariableAllocator.resize(100 + size * 50); diff --git a/src/livemlrunner.h b/src/livemlrunner.h index 24339b3..3c69928 100644 --- a/src/livemlrunner.h +++ b/src/livemlrunner.h @@ -257,13 +257,14 @@ public: return setAction(parser->actionContainer[name]); } - bool addEvent(EventParser *event) + bool setEvent(EventParser *event) { #ifdef DEBUG printf("LMLObject::setEvent(EventParser*) begin.\n"); #endif if (event == NULL) return false; + activeEventStack.clear(); ActiveAction *aa = activeEventStack.add(); aa->action = (ActionParser*)event; aa->variable.numericList.allocator(variable.numericList.get_allocator()); @@ -274,7 +275,7 @@ public: return true; } - bool addEvent(event_type type) + bool setEvent(event_type type) { #ifdef DEBUG printf("LMLObject::setEvent(%d) begin.\n", type); @@ -285,7 +286,7 @@ public: #ifdef DEBUG printf("LMLObject::setEvent(%d) end.\n", type); #endif - return addEvent(event); + return setEvent(event); } }; @@ -334,17 +335,11 @@ class LiveMLRunner LML_CMDRTN (*closeFunc)(LMLParameter&); }; - struct OnEvent - { - event_type id; - }; - LMLSceneObject _scene; list _actorList; LMLActorObject *_currentActor; LMLObject *_currentObject; vector _commandFuncs; - list _onEventList; list_allocator _actionAllocator; list_allocator _repeatAllocator; @@ -374,12 +369,10 @@ public: void setCurrentObject(LMLObject *obj) { _currentObject = obj; } LMLObject* getCurrentObject(void) { return _currentObject; } - void onEvent(event_type id) { _onEventList.push_back()->id = id; } - void bindGlobalEvent(LMLObject&); - LML_CMDRTN runCommand(LMLParameter&, Tag*); LML_CMDRTN runAction(LMLParameter&); - bool runActiveEvents(LMLObject&); + void callEvent(LMLObject&, event_type); + void callEvent(event_type); bool runActiveActions(LMLObject&); bool runObject(LMLObject&); bool run(void); diff --git a/src/xmlparser.h b/src/xmlparser.h index a0565f0..fefdf12 100644 --- a/src/xmlparser.h +++ b/src/xmlparser.h @@ -184,7 +184,7 @@ public: { } - T* operator[](tag_type id) + T* operator[](size_t id) { return get(id); } @@ -233,6 +233,11 @@ public: { return _list.size(); } + + void resize(size_t size) + { + _list.resize(size); + } }; template diff --git a/test/test.xml b/test/test.xml index 666b0bd..80ddf98 100644 --- a/test/test.xml +++ b/test/test.xml @@ -29,6 +29,9 @@ call[init] + + call[release] + 10 -- 2.11.0