OSDN Git Service

changed actionRef to callAction, added callEvent command
authornothan <nothan87@gmail.com>
Thu, 17 Feb 2011 17:57:08 +0000 (02:57 +0900)
committernothan <nothan87@gmail.com>
Thu, 17 Feb 2011 17:57:08 +0000 (02:57 +0900)
src/list.hpp
src/livemlparser.cpp
src/livemlrunner.cpp
src/livemlrunner.h
test/test.xml

index d14fab3..d065e70 100644 (file)
@@ -63,6 +63,11 @@ public:
     resize(0);
   }
 
+  T* operator[](size_t id)
+  {
+    return (T*)(_pool + id);
+  }
+
   void clear(void)
   {
     _free = _pool;
@@ -130,9 +135,9 @@ public:
     _free = li;
   }
 
-  size_t size(void)
+  list_item<T>* pool(void)
   {
-    return _size;
+    return _pool;
   }
 };
 
@@ -166,7 +171,7 @@ public:
     _free_alloc = is_free;
   }
 
-  list_allocator<T>* get_allocator(void)
+  list_allocator<T>* allocator(void)
   {
     return _alloc;
   }
index 3465b85..93c3981 100644 (file)
@@ -263,10 +263,19 @@ PARAM_VAR(registerParameterType(paramVar))
   po = reg->addParameter();
   po->set(0, PARAM_STRING, "name");
 
-  // actionRef
-  reg = addTagType("actionRef");
+  // callAction
+  reg = addTagType("callAction");
   po = reg->addParameter();
   po->set(0, PARAM_TEXT);
+  po = reg->addParameter();
+  po->set(1, PARAM_TEXT, "target");
+
+  // callEvent
+  reg = addTagType("callEvent");
+  po = reg->addParameter();
+  po->set(0, PARAM_TEXT);
+  po = reg->addParameter();
+  po->set(1, PARAM_TEXT, "target");
 
   // include
   reg = addTagType("include");
index 82b7939..6708b1c 100644 (file)
@@ -222,22 +222,53 @@ namespace lmlCommand
     return LML_CMDRTN_NEXT;
   }
 
-  LML_CMDFUNC(actionRef)
+  LML_CMDFUNC(callAction)
   {
 #ifdef DEBUG
-    printf("actionRef: %s\n", param.getText(0));
+    printf("callAction: %s\n", param.getText(0));
 #endif
-    // local
-    if (!param.obj->setActionByName(param.getText(0)))
+    LMLObject *obj;
+    if (param.has(1))
     {
-      // global
+      obj = param.runner->getActorObject(param.getInteger(1));
+    }
+    else
+    {
+      obj = param.obj;
+    }
+
+    if (!obj->setAction(param.getText(0)))
+    {
+      ActionParser *ap = param.runner->parser->actionContainer[param.getText(0)];
+      obj->setAction(ap);
+    }
+
+    return LML_CMDRTN_STOP | LML_CMDRTN_NEXT | LML_CMDRTN_REACTION;
+  }
+
+  LML_CMDFUNC(callEvent)
+  {
 #ifdef DEBUG
-      printf("search in global\n");
+    printf("callEvent: %s\n", param.getText(0));
 #endif
-      ActionParser *ap = param.runner->parser->actionContainer[param.getText(0)];
-      param.obj->setAction(ap);
+    LMLObject *obj;
+    if (param.has(1))
+    {
+      obj = param.runner->getActorObject(param.getInteger(1));
+    }
+    else
+    {
+      obj = param.obj;
+    }
+
+    if (&param.obj->activeActionStack == param.actionStack)
+    {
+      param.runner->callEvent(*obj, param.getText(0));
+      return LML_CMDRTN_NEXT;
     }
 
+    obj->setEvent(param.getText(0));
+
     return LML_CMDRTN_STOP | LML_CMDRTN_NEXT | LML_CMDRTN_REACTION;
   }
 }
@@ -269,7 +300,8 @@ LiveMLRunner::LiveMLRunner(LiveMLParser *p)
 //  registerCommand("if", lmlCommand::rif);
   registerCommand("wait", lmlCommand::wait);
   registerCommand("val", lmlCommand::val);
-  registerCommand("actionRef", lmlCommand::actionRef);
+  registerCommand("callAction", lmlCommand::callAction);
+  registerCommand("callEvent", lmlCommand::callEvent);
 #ifdef DEBUG
   printf("LiveMLRunner::LiveMLRunner() end.\n");
 #endif
@@ -347,8 +379,14 @@ LML_CMDRTN LiveMLRunner::runAction(LMLParameter& param)
   return result;
 }
 
+void LiveMLRunner::callEvent(LMLObject &obj, const char *name)
+{
+  callEvent(obj, (event_type)parser->eventTypeContainer.getId(name));
+}
+
 void LiveMLRunner::callEvent(LMLObject &obj, event_type id)
 {
+  obj.activeEventStack.clear();
   if (!obj.setEvent(id)) return;
 
   do
@@ -456,6 +494,16 @@ bool LiveMLRunner::run(void)
   return running;
 }
 
+LMLActorObject* LiveMLRunner::getActorObject(size_t id)
+{
+  return (*_actorList.allocator())[id];
+}
+
+size_t LiveMLRunner::getActorObjectId(LMLActorObject &obj)
+{
+  return ((char*)&obj - (char*)_actorList.allocator()->pool()) / sizeof(list_item<LMLActorObject>);
+}
+
 void LiveMLRunner::setMaxActors(size_t size)
 {
   _actorList.resize(size);
index 3c69928..ff64e16 100644 (file)
@@ -228,7 +228,7 @@ public:
 
     ActiveAction *aa = activeActionStack.add();
     aa->action = action;
-    aa->variable.numericList.allocator(variable.numericList.get_allocator());
+    aa->variable.numericList.allocator(variable.numericList.allocator());
     aa->tag = action->tag;
 #ifdef DEBUG
     printf("LMLObject::setAction(ActionParser*) end.\n");
@@ -249,7 +249,7 @@ public:
 #endif
     return true;
   }
-  bool setActionByName(const char *name)
+  bool setAction(const char *name)
   {
 #ifdef DEBUG
     printf("LMLObject::setActionByName(%s)\n", name);
@@ -264,10 +264,9 @@ public:
 #endif
     if (event == NULL) return false;
 
-    activeEventStack.clear();
     ActiveAction *aa = activeEventStack.add();
     aa->action = (ActionParser*)event;
-    aa->variable.numericList.allocator(variable.numericList.get_allocator());
+    aa->variable.numericList.allocator(variable.numericList.allocator());
     aa->tag = event->tag;
 #ifdef DEBUG
     printf("LMLObject::setEvent(EventParser*) end.\n");
@@ -288,6 +287,15 @@ public:
 #endif
     return setEvent(event);
   }
+
+  bool setEvent(const char *name)
+  {
+#ifdef DEBUG
+    printf("LMLObject::setActionByName(%s)\n", name);
+#endif
+    return setEvent(parser->eventContainer[name]);
+  }
+
 };
 
 struct LMLSceneObject : public LMLObject
@@ -361,6 +369,7 @@ public:
 
   void setMaxActors(size_t);
   LMLSceneObject* setScene(const char*);
+  LMLSceneObject* getScene(void) { return &_scene; };
   LMLActorObject* addActor(const char*);
 
   void setCurrentActor(LMLActorObject *obj) { _currentActor = obj; }
@@ -372,10 +381,13 @@ public:
   LML_CMDRTN runCommand(LMLParameter&, Tag*);
   LML_CMDRTN runAction(LMLParameter&);
   void callEvent(LMLObject&, event_type);
+  void callEvent(LMLObject&, const char*);
   void callEvent(event_type);
   bool runActiveActions(LMLObject&);
   bool runObject(LMLObject&);
   bool run(void);
+  LMLActorObject* getActorObject(size_t);
+  size_t getActorObjectId(LMLActorObject&);
 
   static fixed_float variableNumericDecoder(variable_size, void*);
   static const char* variableStringDecoder(variable_size, void*);
index 80ddf98..24d20db 100644 (file)
@@ -8,23 +8,14 @@
     <!-- Local Actions -->
     <action name="1">
       <active>actor</active>
-      <actionRef>g1</actionRef>
+      <callAction>g1</callAction>
     </action>
     <action name="2">
       <print>call[action 2]</print>
-      <actionRef>g2</actionRef>
+      <callAction>g2</callAction>
     </action>
   </scene>
 
-  <!--Global Actions -->
-  <action name="g1">
-    <print>call[global action 1]</print>
-    <actionRef>2</actionRef>
-  </action>
-  <action name="g2">
-    <print>call[global action 2]</print>
-  </action>
-
   <actor name="actor">
     <event type="init">
       <print>call[init]</print>
         <print>roop[actor]</print>
         <wait>1</wait>
       </repeat>
+      <callEvent>release</callEvent>
     </action>
   </actor>
 
-<!--
-  <actor type="spritebox" name="actor1">
-    <event type="init">
-      <image>image1</image>
-      <pos name="x" type="absolute">0</pos>
-      <pos name="y" type="absolute">0</pos>
-      <pos name="z" type="absolute">0</pos>
-      <scale name="x" type="absolute">1</scale>
-      <scale name="y" type="absolute">1</scale>
-      <create type="actor" relation="child" src="render1"></create>
-      <width type="absolute">100</width>
-      <height type="absolute">100</height>
-    </event>
-    <event type="focus-on">
-    </event>
-    <event type="focus-off">
-    </event>
-    <action name="action1">
-      <print>actor1 action1</print>
-    </action>
-    <action name="action2">
-      <repeat count="5">
-        <wait>1</wait>
-      </repeat>
-    </action>
-  </actor>
-
-  <actor type="render" name="render1">
-    <event type="init">
-      <vertex name="x" id="0" type="absolute">0</vertex>
-      <vertex name="y" id="0" type="absolute">0</vertex>
-      <color name="r" type="absolute">255</color>
-      <color name="g" type="absolute">255</color>
-      <color name="b" type="absolute">255</color>
-    </event>
-    <action name="action">
-      <render type="2d" />
-    </action>
-  </actor>
--->
+  <!--Global Actions -->
+  <action name="g1">
+    <print>call[global action 1]</print>
+    <callAction>2</callAction>
+  </action>
+  <action name="g2">
+    <print>call[global action 2]</print>
+  </action>
 </liveml>