소스 검색

Some more work on new scripting system

Ivan Safrin 9 년 전
부모
커밋
29346d7e9c

+ 8 - 0
build/osx/PolycodeCore/PolycodeCore.xcodeproj/project.pbxproj

@@ -9,6 +9,8 @@
 /* Begin PBXBuildFile section */
 		6D904FCD1CC2A4DA00D0E80A /* PolyScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D904FCC1CC2A4DA00D0E80A /* PolyScript.cpp */; };
 		6D904FCF1CC2A4E900D0E80A /* PolyScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D904FCE1CC2A4E900D0E80A /* PolyScript.h */; };
+		6D904FD51CC368E200D0E80A /* PolyLuaAPI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D904FD41CC368E200D0E80A /* PolyLuaAPI.cpp */; };
+		6D904FD71CC368F300D0E80A /* PolyLuaAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 6D904FD61CC368F300D0E80A /* PolyLuaAPI.h */; };
 		8A7349081B86A53C00F660C0 /* lodepng.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A7349071B86A53C00F660C0 /* lodepng.h */; };
 		8A73490A1B86A54800F660C0 /* lodepng.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A7349091B86A54800F660C0 /* lodepng.cpp */; };
 		8A825F231B829BA70039E823 /* PolyPAAudioInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A825F221B829BA70039E823 /* PolyPAAudioInterface.h */; };
@@ -173,6 +175,8 @@
 /* Begin PBXFileReference section */
 		6D904FCC1CC2A4DA00D0E80A /* PolyScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PolyScript.cpp; path = ../../../src/core/PolyScript.cpp; sourceTree = "<group>"; };
 		6D904FCE1CC2A4E900D0E80A /* PolyScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyScript.h; path = ../../../include/polycode/core/PolyScript.h; sourceTree = "<group>"; };
+		6D904FD41CC368E200D0E80A /* PolyLuaAPI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PolyLuaAPI.cpp; path = ../../../src/core/PolyLuaAPI.cpp; sourceTree = "<group>"; };
+		6D904FD61CC368F300D0E80A /* PolyLuaAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyLuaAPI.h; path = ../../../include/polycode/core/PolyLuaAPI.h; sourceTree = "<group>"; };
 		8A7349071B86A53C00F660C0 /* lodepng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lodepng.h; path = ../../../include/lodepng.h; sourceTree = "<group>"; };
 		8A7349091B86A54800F660C0 /* lodepng.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lodepng.cpp; path = ../../../src/core/lodepng.cpp; sourceTree = "<group>"; };
 		8A825F221B829BA70039E823 /* PolyPAAudioInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyPAAudioInterface.h; path = ../../../include/polycode/core/PolyPAAudioInterface.h; sourceTree = "<group>"; };
@@ -385,6 +389,7 @@
 				8A8652A01B72867E009F94DD /* PolyInputEvent.cpp */,
 				8A8652A11B72867E009F94DD /* PolyLabel.cpp */,
 				8A8652A21B72867E009F94DD /* PolyLogger.cpp */,
+				6D904FD41CC368E200D0E80A /* PolyLuaAPI.cpp */,
 				8A8652A31B72867E009F94DD /* PolyMaterial.cpp */,
 				8A8652A41B72867E009F94DD /* PolyMaterialManager.cpp */,
 				8A8652A51B72867E009F94DD /* PolyMatrix4.cpp */,
@@ -479,6 +484,7 @@
 				8A8652001B72865C009F94DD /* PolyInputKeys.h */,
 				8A8652011B72865C009F94DD /* PolyLabel.h */,
 				8A8652021B72865C009F94DD /* PolyLogger.h */,
+				6D904FD61CC368F300D0E80A /* PolyLuaAPI.h */,
 				8A8652031B72865C009F94DD /* PolyMaterial.h */,
 				8A8652041B72865C009F94DD /* PolyMaterialManager.h */,
 				8A8652051B72865C009F94DD /* PolyMatrix4.h */,
@@ -619,6 +625,7 @@
 				8A86525E1B72865C009F94DD /* PolyResourceManager.h in Headers */,
 				8A8652631B72865C009F94DD /* PolySceneLight.h in Headers */,
 				8A8652571B72865C009F94DD /* PolyQuaternion.h in Headers */,
+				6D904FD71CC368F300D0E80A /* PolyLuaAPI.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -774,6 +781,7 @@
 				8A8652FD1B72867F009F94DD /* PolyResource.cpp in Sources */,
 				8A8653111B72867F009F94DD /* PolyString.cpp in Sources */,
 				8A8652D91B72867F009F94DD /* PolyClient.cpp in Sources */,
+				6D904FD51CC368E200D0E80A /* PolyLuaAPI.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 2
build/osx/TemplateApp/TemplateApp/PolycodeTemplateApp.mm

@@ -15,7 +15,7 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
     core->addFileSource("archive", "hdr.pak");
     globalPool->loadResourcesFromFolder("hdr", true);
     
-    Polycode::Script *rotateScript = (Polycode::Script*) globalPool->loadResource("rotate.lua");
+    Polycode:Script *rotateScript = (Script*) globalPool->loadResource("rotate.lua");
     
 	// Write your code here!
     
@@ -23,7 +23,6 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
     scene->useClearColor = true;
     scene->clearColor.setColor(0.2, 0.2, 0.2, 1.0);
     
-    
    // scene->setOverrideMaterial((Material*)globalPool->getResource(Resource::RESOURCE_MATERIAL, "Unlit"));
     
     for(int i=0; i  < 5; i++) {

+ 1 - 2
build/osx/TemplateApp/TemplateApp/rotate.lua

@@ -6,12 +6,11 @@ Rotator.__index = Rotator
 function Rotator.init(entity)
 	local rotator = {}
 	rotator.entity = entity
-	print(entity)
 	return rotator
 end
 
 function Rotator:update(elapsed)
-	print(self.entity)
+	Entity.Roll(self.entity, elapsed * 100.0)
 end
 
 return Rotator

+ 1 - 1
include/polycode/core/PolyEntity.h

@@ -492,7 +492,7 @@ namespace Polycode {
              * Returns the bounding box Y value.
              */
 			Number getHeight() const;
-
+        
             /**
              * Returns the bounding box Z value.
              */

+ 31 - 0
include/polycode/core/PolyLuaAPI.h

@@ -0,0 +1,31 @@
+/*
+ Copyright (C) 2016 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#pragma once
+#include <Polycode.h>
+
+extern "C" {
+    #include "lua.h"
+    #include "lualib.h"
+    #include "lauxlib.h"
+    int luaopen_Polycode(lua_State *L);
+}

+ 47 - 0
src/core/PolyLuaAPI.cpp

@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2016 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#include "polycode/core/PolyLuaAPI.h"
+
+using namespace Polycode;
+
+static int Lua_Entity_Roll(lua_State *L) {
+    Entity *entity = (Entity*) lua_topointer(L, 1);
+    Number amt = lua_tonumber(L, 2);
+    if(!entity) {
+        return 0;
+    }
+    entity->Roll(amt);
+    return 0;
+}
+
+int luaopen_Polycode(lua_State *L) {
+    
+    static const luaL_reg entityFunctions[] =
+    {
+        { "Roll", Lua_Entity_Roll},
+        { NULL, NULL }
+    };
+    
+    luaL_register(L, "Entity", entityFunctions);
+    return 1;
+}

+ 2 - 0
src/core/PolyResourceManager.cpp

@@ -32,6 +32,7 @@
 #include "polycode/core/PolyFont.h"
 #include "polycode/core/PolyMesh.h"
 #include "polycode/core/PolyScript.h"
+#include "polycode/core/PolyLuaApi.h"
 #include "tinyxml.h"
 
 using std::vector;
@@ -372,6 +373,7 @@ ScriptResourceLoader::ScriptResourceLoader() {
     luaState =  lua_open();
     luaL_openlibs(luaState);
     luaopen_debug(luaState);
+    luaopen_Polycode(luaState);
     extensions.push_back("lua");
 }