瀏覽代碼

Merge pull request #242 from seanpaultaylor/next

Next
Sean Paul Taylor 13 年之前
父節點
當前提交
9dc6480b55

+ 1 - 1
gameplay-luagen/src/main.cpp

@@ -28,7 +28,7 @@ int main(int argc, char** argv)
     // Ensure the user is calling the program correctly.
     if (argc < 2 || argc > 4)
     {
-        GP_ERROR("Usage: luagen <input-directory> [output-directory] [binding-namespace]");
+        GP_ERROR("Usage: gameplay-luagen <doxygen-xml-input-directory> [output-directory] [binding-namespace]");
     }
 
     // Generate the bindings.

+ 2 - 2
gameplay/src/Joystick.h

@@ -50,7 +50,7 @@ public:
      * Sets the image size of the inner region of the joystick. Does not do anything if there is no
      * inner image region defined.
      * 
-     * @param region The size of the inner region of the joystick. (x, y) == (width, height)
+     * @param size The size of the inner region of the joystick. (x, y) == (width, height)
      */
     inline void setInnerRegionSize(const Vector2& size);
 
@@ -66,7 +66,7 @@ public:
      * Sets the image size of the outer region of the joystick. Does not do anything if there is no
      * outer image region defined.
      * 
-     * @param region The size of the outer region of the joystick. (x, y) == (width, height)
+     * @param size The size of the outer region of the joystick. (x, y) == (width, height)
      */
     inline void setOuterRegionSize(const Vector2& size);
 

+ 9 - 15
gameplay/src/Material.cpp

@@ -77,9 +77,12 @@ Material* Material::create(Properties* materialProperties)
     // Set the current technique to the first found technique.
     if (material->getTechniqueCount() > 0)
     {
-        material->setTechnique((unsigned int)0);
+        Technique* t = material->getTechniqueByIndex(0);
+        if (t)
+        {
+            material->_currentTechnique = t;
+        }
     }
-
     return material;
 }
 
@@ -148,7 +151,7 @@ unsigned int Material::getTechniqueCount() const
     return _techniques.size();
 }
 
-Technique* Material::getTechnique(unsigned int index) const
+Technique* Material::getTechniqueByIndex(unsigned int index) const
 {
     GP_ASSERT(index < _techniques.size());
     return _techniques[index];
@@ -184,15 +187,6 @@ void Material::setTechnique(const char* id)
     }
 }
 
-void Material::setTechnique(unsigned int index)
-{
-    Technique* t = getTechnique(index);
-    if (t)
-    {
-        _currentTechnique = t;
-    }
-}
-
 bool Material::loadTechnique(Material* material, Properties* techniqueProperties)
 {
     GP_ASSERT(material);
@@ -346,7 +340,7 @@ void Material::loadRenderState(RenderState* renderState, Properties* properties)
     properties->rewind();
 
     const char* name;
-    while (name = properties->getNextProperty())
+    while ((name = properties->getNextProperty()))
     {
         if (isMaterialKeyword(name))
             continue; // keyword - skip
@@ -408,7 +402,7 @@ void Material::loadRenderState(RenderState* renderState, Properties* properties)
 
     // Iterate through all child namespaces searching for samplers and render state blocks.
     Properties* ns;
-    while (ns = properties->getNextNamespace())
+    while ((ns = properties->getNextNamespace()))
     {
         if (strcmp(ns->getNamespace(), "sampler") == 0)
         {
@@ -446,7 +440,7 @@ void Material::loadRenderState(RenderState* renderState, Properties* properties)
         }
         else if (strcmp(ns->getNamespace(), "renderState") == 0)
         {
-            while (name = ns->getNextProperty())
+            while ((name = ns->getNextProperty()))
             {
                 GP_ASSERT(renderState->getStateBlock());
                 renderState->getStateBlock()->setState(name, ns->getString());

+ 1 - 8
gameplay/src/Material.h

@@ -100,7 +100,7 @@ public:
      * 
      * @return The specified technique.
      */
-    Technique* getTechnique(unsigned int index) const;
+    Technique* getTechniqueByIndex(unsigned int index) const;
 
     /**
      * Returns the technique with the specified ID in this material.
@@ -118,13 +118,6 @@ public:
      */
     Technique* getTechnique() const;
 
-    /**
-     * Sets the current material technique.
-     *
-     * @param index Index of the technique to set.
-     */
-    void setTechnique(unsigned int index);
-
     /**
      * Sets the current material technique. 
      *

+ 3 - 3
gameplay/src/MeshBatch.cpp

@@ -49,11 +49,11 @@ void MeshBatch::updateVertexAttributeBinding()
     // Update our vertex attribute bindings.
     for (unsigned int i = 0, techniqueCount = _material->getTechniqueCount(); i < techniqueCount; ++i)
     {
-        Technique* t = _material->getTechnique(i);
+        Technique* t = _material->getTechniqueByIndex(i);
         GP_ASSERT(t);
         for (unsigned int j = 0, passCount = t->getPassCount(); j < passCount; ++j)
         {
-            Pass* p = t->getPass(j);
+            Pass* p = t->getPassByIndex(j);
             GP_ASSERT(p);
             VertexAttributeBinding* b = VertexAttributeBinding::create(_vertexFormat, _vertices, p->getEffect());
             p->setVertexAttributeBinding(b);
@@ -187,7 +187,7 @@ void MeshBatch::draw()
     unsigned int passCount = technique->getPassCount();
     for (unsigned int i = 0; i < passCount; ++i)
     {
-        Pass* pass = technique->getPass(i);
+        Pass* pass = technique->getPassByIndex(i);
         GP_ASSERT(pass);
         pass->bind();
 

+ 9 - 9
gameplay/src/Model.cpp

@@ -126,12 +126,12 @@ void Model::setMaterial(Material* material, int partIndex)
     {
         for (unsigned int i = 0, tCount = oldMaterial->getTechniqueCount(); i < tCount; ++i)
         {
-            Technique* t = oldMaterial->getTechnique(i);
+            Technique* t = oldMaterial->getTechniqueByIndex(i);
             GP_ASSERT(t);
             for (unsigned int j = 0, pCount = t->getPassCount(); j < pCount; ++j)
             {
-                GP_ASSERT(t->getPass(j));
-                t->getPass(j)->setVertexAttributeBinding(NULL);
+                GP_ASSERT(t->getPassByIndex(j));
+                t->getPassByIndex(j)->setVertexAttributeBinding(NULL);
             }
         }
         SAFE_RELEASE(oldMaterial);
@@ -142,11 +142,11 @@ void Model::setMaterial(Material* material, int partIndex)
         // Hookup vertex attribute bindings for all passes in the new material.
         for (unsigned int i = 0, tCount = material->getTechniqueCount(); i < tCount; ++i)
         {
-            Technique* t = material->getTechnique(i);
+            Technique* t = material->getTechniqueByIndex(i);
             GP_ASSERT(t);
             for (unsigned int j = 0, pCount = t->getPassCount(); j < pCount; ++j)
             {
-                Pass* p = t->getPass(j);
+                Pass* p = t->getPassByIndex(j);
                 GP_ASSERT(p);
                 VertexAttributeBinding* b = VertexAttributeBinding::create(_mesh, p->getEffect());
                 p->setVertexAttributeBinding(b);
@@ -268,7 +268,7 @@ void Model::draw(bool wireframe)
             unsigned int passCount = technique->getPassCount();
             for (unsigned int i = 0; i < passCount; ++i)
             {
-                Pass* pass = technique->getPass(i);
+                Pass* pass = technique->getPassByIndex(i);
                 GP_ASSERT(pass);
                 pass->bind();
                 GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
@@ -304,7 +304,7 @@ void Model::draw(bool wireframe)
                 unsigned int passCount = technique->getPassCount();
                 for (unsigned int j = 0; j < passCount; ++j)
                 {
-                    Pass* pass = technique->getPass(j);
+                    Pass* pass = technique->getPassByIndex(j);
                     GP_ASSERT(pass);
                     pass->bind();
                     GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, part->_indexBuffer) );
@@ -423,7 +423,7 @@ void Model::setMaterialNodeBinding(Material *material)
         unsigned int techniqueCount = material->getTechniqueCount();
         for (unsigned int i = 0; i < techniqueCount; ++i)
         {
-            Technique* technique = material->getTechnique(i);
+            Technique* technique = material->getTechniqueByIndex(i);
             GP_ASSERT(technique);
             
             technique->setNodeBinding(_node);
@@ -431,7 +431,7 @@ void Model::setMaterialNodeBinding(Material *material)
             unsigned int passCount = technique->getPassCount();
             for (unsigned int j = 0; j < passCount; ++j)
             {
-                Pass* pass = technique->getPass(j);
+                Pass* pass = technique->getPassByIndex(j);
                 GP_ASSERT(pass);
 
                 pass->setNodeBinding(_node);

+ 1 - 2
gameplay/src/Technique.cpp

@@ -31,7 +31,7 @@ unsigned int Technique::getPassCount() const
     return _passes.size();
 }
 
-Pass* Technique::getPass(unsigned int index) const
+Pass* Technique::getPassByIndex(unsigned int index) const
 {
     GP_ASSERT(index < _passes.size());
     return _passes[index];
@@ -50,7 +50,6 @@ Pass* Technique::getPass(const char* id) const
             return pass;
         }
     }
-
     return NULL;
 }
 

+ 5 - 5
gameplay/src/Technique.h

@@ -23,22 +23,22 @@ class Technique : public RenderState
 public:
 
     /**
-     * Returns the Id of this Material technique.
+     * Gets the Id of this Material technique.
      */ 
     const char* getId() const;
 
     /**
-     * Returns the number of passes in this technique.
+     * Gets the number of passes in this technique.
      */
     unsigned int getPassCount() const;
 
     /**
-     * Returns the pass at the specified index.
+     * Gets the pass at the specified index.
      */
-    Pass* getPass(unsigned int index) const;
+    Pass* getPassByIndex(unsigned int index) const;
 
     /**
-     * Returns the pass with the specified ID.
+     * Gets the pass with the specified ID.
      */
     Pass* getPass(const char* id) const;
 

+ 36 - 19
gameplay/src/lua/lua_Material.cpp

@@ -28,6 +28,7 @@ void luaRegister_Material()
         {"getRefCount", lua_Material_getRefCount},
         {"getStateBlock", lua_Material_getStateBlock},
         {"getTechnique", lua_Material_getTechnique},
+        {"getTechniqueByIndex", lua_Material_getTechniqueByIndex},
         {"getTechniqueCount", lua_Material_getTechniqueCount},
         {"release", lua_Material_release},
         {"setParameterAutoBinding", lua_Material_setParameterAutoBinding},
@@ -348,10 +349,10 @@ int lua_Material_getTechnique(lua_State* state)
         case 2:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                lua_type(state, 2) == LUA_TNUMBER)
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+                const char* param1 = ScriptUtil::getString(2, false);
 
                 Material* instance = getInstance(state);
                 void* returnPtr = (void*)instance->getTechnique(param1);
@@ -370,14 +371,41 @@ int lua_Material_getTechnique(lua_State* state)
 
                 return 1;
             }
-            else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            else
+            {
+                lua_pushstring(state, "lua_Material_getTechnique - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Material_getTechniqueByIndex(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = ScriptUtil::getString(2, false);
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Material* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getTechnique(param1);
+                void* returnPtr = (void*)instance->getTechniqueByIndex(param1);
                 if (returnPtr)
                 {
                     ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
@@ -395,14 +423,14 @@ int lua_Material_getTechnique(lua_State* state)
             }
             else
             {
-                lua_pushstring(state, "lua_Material_getTechnique - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_Material_getTechniqueByIndex - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
             }
             break;
         }
         default:
         {
-            lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
             lua_error(state);
             break;
         }
@@ -587,17 +615,6 @@ int lua_Material_setTechnique(lua_State* state)
         case 2:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                lua_type(state, 2) == LUA_TNUMBER)
-            {
-                // Get parameter 1 off the stack.
-                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
-
-                Material* instance = getInstance(state);
-                instance->setTechnique(param1);
-                
-                return 0;
-            }
-            else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
                 (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.

+ 1 - 0
gameplay/src/lua/lua_Material.h

@@ -12,6 +12,7 @@ int lua_Material_getParameter(lua_State* state);
 int lua_Material_getRefCount(lua_State* state);
 int lua_Material_getStateBlock(lua_State* state);
 int lua_Material_getTechnique(lua_State* state);
+int lua_Material_getTechniqueByIndex(lua_State* state);
 int lua_Material_getTechniqueCount(lua_State* state);
 int lua_Material_release(lua_State* state);
 int lua_Material_setParameterAutoBinding(lua_State* state);

+ 47 - 0
gameplay/src/lua/lua_SpriteBatch.cpp

@@ -16,6 +16,7 @@ void luaRegister_SpriteBatch()
         {"finish", lua_SpriteBatch_finish},
         {"getMaterial", lua_SpriteBatch_getMaterial},
         {"getProjectionMatrix", lua_SpriteBatch_getProjectionMatrix},
+        {"getSampler", lua_SpriteBatch_getSampler},
         {"getStateBlock", lua_SpriteBatch_getStateBlock},
         {"setProjectionMatrix", lua_SpriteBatch_setProjectionMatrix},
         {"start", lua_SpriteBatch_start},
@@ -865,6 +866,52 @@ int lua_SpriteBatch_getProjectionMatrix(lua_State* state)
     return 0;
 }
 
+int lua_SpriteBatch_getSampler(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                SpriteBatch* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getSampler();
+                if (returnPtr)
+                {
+                    ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "TextureSampler");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "lua_SpriteBatch_getSampler - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_SpriteBatch_getStateBlock(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 0
gameplay/src/lua/lua_SpriteBatch.h

@@ -10,6 +10,7 @@ int lua_SpriteBatch_draw(lua_State* state);
 int lua_SpriteBatch_finish(lua_State* state);
 int lua_SpriteBatch_getMaterial(lua_State* state);
 int lua_SpriteBatch_getProjectionMatrix(lua_State* state);
+int lua_SpriteBatch_getSampler(lua_State* state);
 int lua_SpriteBatch_getStateBlock(lua_State* state);
 int lua_SpriteBatch_setProjectionMatrix(lua_State* state);
 int lua_SpriteBatch_start(lua_State* state);

+ 35 - 7
gameplay/src/lua/lua_Technique.cpp

@@ -23,6 +23,7 @@ void luaRegister_Technique()
         {"getId", lua_Technique_getId},
         {"getParameter", lua_Technique_getParameter},
         {"getPass", lua_Technique_getPass},
+        {"getPassByIndex", lua_Technique_getPassByIndex},
         {"getPassCount", lua_Technique_getPassCount},
         {"getRefCount", lua_Technique_getRefCount},
         {"getStateBlock", lua_Technique_getStateBlock},
@@ -216,10 +217,10 @@ int lua_Technique_getPass(lua_State* state)
         case 2:
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                lua_type(state, 2) == LUA_TNUMBER)
+                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
             {
                 // Get parameter 1 off the stack.
-                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
+                const char* param1 = ScriptUtil::getString(2, false);
 
                 Technique* instance = getInstance(state);
                 void* returnPtr = (void*)instance->getPass(param1);
@@ -238,14 +239,41 @@ int lua_Technique_getPass(lua_State* state)
 
                 return 1;
             }
-            else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
+            else
+            {
+                lua_pushstring(state, "lua_Technique_getPass - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 2).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
+int lua_Technique_getPassByIndex(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 2:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
+                lua_type(state, 2) == LUA_TNUMBER)
             {
                 // Get parameter 1 off the stack.
-                const char* param1 = ScriptUtil::getString(2, false);
+                unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
 
                 Technique* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getPass(param1);
+                void* returnPtr = (void*)instance->getPassByIndex(param1);
                 if (returnPtr)
                 {
                     ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
@@ -263,7 +291,7 @@ int lua_Technique_getPass(lua_State* state)
             }
             else
             {
-                lua_pushstring(state, "lua_Technique_getPass - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_Technique_getPassByIndex - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
             }
             break;

+ 1 - 0
gameplay/src/lua/lua_Technique.h

@@ -10,6 +10,7 @@ int lua_Technique_addRef(lua_State* state);
 int lua_Technique_getId(lua_State* state);
 int lua_Technique_getParameter(lua_State* state);
 int lua_Technique_getPass(lua_State* state);
+int lua_Technique_getPassByIndex(lua_State* state);
 int lua_Technique_getPassCount(lua_State* state);
 int lua_Technique_getRefCount(lua_State* state);
 int lua_Technique_getStateBlock(lua_State* state);