]> Dogcows Code - chaz/yoink/blobdiff - src/Animation.cc
sockets documentation and cleanup
[chaz/yoink] / src / Animation.cc
index 2a3d03a5922e62a6ef68e4cf106dd3a0e8c1c99b..bd31f9b5dc26a8248952d8d7b5d5028bc6e45a63 100644 (file)
@@ -12,6 +12,7 @@
 #include <map>
 #include <vector>
 
+#include <Moof/Error.hh>
 #include <Moof/Manager.hh>
 #include <Moof/Log.hh>
 #include <Moof/Script.hh>
@@ -62,17 +63,12 @@ public:
                         * animation file.
                         */
                
-                       Frame(Mf::Script& script, Mf::Script::Slot table) :
+                       Frame(const Mf::Script::Slot& table) :
                                mIndex(0),
                                mDuration(1.0)
                        {
-                               table.pushField("index");
-                               script[-1].get(mIndex);
-                               script.pop();
-
-                               table.pushField("duration");
-                               script[-1].get(mDuration);
-                               script.pop();
+                               table.get(mIndex,    "index");
+                               table.get(mDuration, "duration");
                        }
                };
 
@@ -98,46 +94,36 @@ public:
                         * the frame's constructor which loads each individual frame.
                         */
 
-                       Sequence(Mf::Script& script, Mf::Script::Slot table) :
+                       Sequence(const Mf::Script::Slot& table) :
                                mDelay(0.0),
                                mLoop(true)
                        {
-                               table.pushField("delay");
-                               script[-1].get(mDelay);
-                               script.pop();
-
-                               table.pushField("loop");
-                               script[-1].get(mLoop);
-                               script.pop();
-
-                               table.pushField("next");
-                               script[-1].get(mNext);
-                               script.pop();
+                               table.get(mDelay, "delay");
+                               table.get(mLoop,  "loop");
+                               table.get(mNext,  "next");
 
                                // TODO - sequence class/type not yet implemented
 
-                               table.pushField("frames");
-                               Mf::Script::Slot frameTable = script.getTop();
+                               Mf::Script::Slot frameTable = table.pushField("frames");
                                if (frameTable.isTable())
                                {
-                                       Mf::Script::Slot top = script[-1];
-                                       int index = 1;
-
-                                       for (;;)
+                                       int max = frameTable.length();
+                                       for (int index = 1; index <= max; ++index)
                                        {
-                                               script.push(index);
-                                               frameTable.pushField();
+                                               Mf::Script::Slot top = frameTable.pushField(index);
 
                                                if (top.isTable())
                                                {
-                                                       mFrames.push_back(Frame(script, top));
+                                                       mFrames.push_back(Frame(top));
+                                               }
+                                               else
+                                               {
+                                                       Mf::logWarning << "invalid frame at index "
+                                                                                  << index << std::endl;
                                                }
-                                               else break;
-
-                                               ++index;
                                        }
                                }
-                               script.pop();
+                               frameTable.remove();
                        }
                };
 
@@ -151,13 +137,18 @@ public:
                void init(const std::string& name)
                {
                        Mf::Script script;
-                       std::string filePath = Animation::getPath(name);
+                       std::string path(name);
+                       
+                       if (!Animation::getPath(path))
+                       {
+                               Mf::Error(Mf::Error::RESOURCE_NOT_FOUND).raise();
+                       }
 
                        script.importBaseLibrary();
                        importLogFunctions(script);
                        importAnimationBindings(script);
 
-                       if (script.doFile(filePath) != Mf::Script::SUCCESS)
+                       if (script.doFile(path) != Mf::Script::SUCCESS)
                        {
                                std::string str;
                                script[-1].get(str);
@@ -173,8 +164,7 @@ public:
                        std::string nameStr;
                        name.get(nameStr);
 
-                       mSequences.insert(std::make_pair(nameStr,
-                                                                                        Sequence(script, table)));
+                       mSequences.insert(std::make_pair(nameStr, Sequence(table)));
 
                        return 0;
                }
@@ -186,13 +176,13 @@ public:
                                                                  boost::bind(&Data::defineSequence,
                                                                                          this, _1));
 
-                       script.push(1); script.set("ATTACK");
-                       script.push(2); script.set("CHARGE");
-                       script.push(3); script.set("FLY");
-                       script.push(4); script.set("HIT");
-                       script.push(5); script.set("JUMP");
-                       script.push(6); script.set("RUN");
-                       script.push(7); script.set("STAND");
+                       script.globals().setField("ATTACK",     1);
+                       script.globals().setField("CHARGE",     2);
+                       script.globals().setField("FLY",        3);
+                       script.globals().setField("HIT",        4);
+                       script.globals().setField("JUMP",       5);
+                       script.globals().setField("RUN",        6);
+                       script.globals().setField("STAND",      7);
                }
 
 
@@ -322,8 +312,8 @@ unsigned Animation::getFrame() const
  * the "animations" subdirectory of any of the search directories.
  */
 
-std::string Animation::getPath(const std::string& name)
+bool Animation::getPath(std::string& name)
 {
-       return Mf::Resource::getPath("animations/" + name + ".lua");
+       return Mf::Resource::getPath(name, "animations/", "lua");
 }
 
This page took 0.024292 seconds and 4 git commands to generate.