Ver Fonte

Added experimental emscripten support, added flags to compile without Lua and/or PhysFS, Labels defaulting to clamped+no mipmaps for strict OpenGL ES2 compatibility

Ivan Safrin há 9 anos atrás
pai
commit
21d0173540
36 ficheiros alterados com 907 adições e 135 exclusões
  1. 10 0
      .gitignore
  2. 0 2
      bindings/javascript/Polycode.js
  3. 4 0
      bindings/javascript/Polycode/RenderThread.js
  4. 1 1
      bindings/javascript/Polycode/Resource.js
  5. BIN
      bindings/javascript/js_Polycode.pak
  6. 0 2
      bindings/lua/Polycode.lua
  7. 4 0
      bindings/lua/Polycode/RenderThread.lua
  8. 1 1
      bindings/lua/Polycode/Resource.lua
  9. BIN
      bindings/lua/lua_Polycode.pak
  10. 6 0
      build/emscripten/Makefile
  11. 17 0
      build/emscripten/TemplateApp/PolycodeTemplate.cpp
  12. 73 0
      build/emscripten/TemplateApp/PolycodeTemplateApp.cpp
  13. 28 0
      build/emscripten/TemplateApp/PolycodeTemplateApp.h
  14. 4 4
      build/osx/PolycodeCore/PolycodeCore.xcodeproj/project.pbxproj
  15. 5 1
      include/Polycode.h
  16. 17 35
      include/polycode/bindings/javascript/PolycodeJSWrappers.h
  17. 7 32
      include/polycode/bindings/lua/PolycodeLuaWrappers.h
  18. 104 0
      include/polycode/core/PolyEmscriptenCore.h
  19. 5 2
      include/polycode/core/PolyOpenGLGraphicsInterface.h
  20. 3 3
      include/polycode/core/PolyRenderer.h
  21. 1 1
      include/polycode/core/PolyResource.h
  22. 6 3
      include/polycode/core/PolyResourceManager.h
  23. 6 3
      include/polycode/core/PolyScript.h
  24. 2 2
      scripts/create_bindings/bindings.conf
  25. 1 4
      src/bindings/javascript/PolycodeJS.cpp
  26. 1 16
      src/bindings/lua/PolycodeLua.cpp
  27. 559 0
      src/core/PolyEmscriptenCore.cpp
  28. 1 0
      src/core/PolyOpenGLGraphicsInterface.cpp
  29. 1 0
      src/core/PolyParticleEmitter.cpp
  30. 18 12
      src/core/PolyRenderer.cpp
  31. 16 9
      src/core/PolyResourceManager.cpp
  32. 2 2
      src/core/PolySceneLabel.cpp
  33. 2 0
      src/core/PolyScript.cpp
  34. 1 0
      src/core/PolyShader.cpp
  35. 1 0
      src/core/PolySound.cpp
  36. 0 0
      src/duktape/duktape.cpp

+ 10 - 0
.gitignore

@@ -14,6 +14,16 @@ build/linux/TemplateApp/default
 build/linux/TemplateApp/default.pak
 build/linux/Studio/*
 
+build/emscripten/default
+build/emscripten/TemplateApp/*.mem
+build/emscripten/TemplateApp/*.js
+build/emscripten/TemplateApp/*.html
+build/emscripten/TemplateApp/*.png
+build/emscripten/TemplateApp/*.bc
+build/emscripten/TemplateApp/*.pak
+build/emscripten/TemplateApp/*.data
+build/emscripten/main_icon.png
+
 *.opendb
 
 docs/cldoc

+ 0 - 2
bindings/javascript/Polycode.js

@@ -91,8 +91,6 @@ require('Polycode/Sprite')
 require('Polycode/SpriteSet')
 require('Polycode/SpriteFrame')
 require('Polycode/SpriteState')
-require('Polycode/JSScriptInstance')
-require('Polycode/LuaScriptInstance')
 require('Polycode/ScriptInstance')
 require('Polycode/ProgramParam')
 require('Polycode/ProgramAttribute')

+ 4 - 0
bindings/javascript/Polycode/RenderThread.js

@@ -15,6 +15,10 @@ RenderThread.prototype.runThread = function() {
 	Polycode.RenderThread_runThread(this.__ptr)
 }
 
+RenderThread.prototype.updateRenderThread = function() {
+	Polycode.RenderThread_updateRenderThread(this.__ptr)
+}
+
 RenderThread.prototype.enqueueFrame = function(frame) {
 	Polycode.RenderThread_enqueueFrame(this.__ptr, frame)
 }

+ 1 - 1
bindings/javascript/Polycode/Resource.js

@@ -13,7 +13,7 @@ Resource.prototype.__set_reloadOnFileModify = function(val) {
 }
 
 Resource.prototype.__get_resourceFileTime = function() {
-	var retVal = new time_t()
+	var retVal = new size_t()
 	retVal.__ptr = 	Polycode.Resource__get_resourceFileTime(this.__ptr)
 	return retVal
 }

BIN
bindings/javascript/js_Polycode.pak


+ 0 - 2
bindings/lua/Polycode.lua

@@ -91,8 +91,6 @@ require "Polycode/Sprite"
 require "Polycode/SpriteSet"
 require "Polycode/SpriteFrame"
 require "Polycode/SpriteState"
-require "Polycode/JSScriptInstance"
-require "Polycode/LuaScriptInstance"
 require "Polycode/ScriptInstance"
 require "Polycode/ProgramParam"
 require "Polycode/ProgramAttribute"

+ 4 - 0
bindings/lua/Polycode/RenderThread.lua

@@ -39,6 +39,10 @@ function RenderThread:runThread()
 	local retVal =  Polycode.RenderThread_runThread(self.__ptr)
 end
 
+function RenderThread:updateRenderThread()
+	local retVal =  Polycode.RenderThread_updateRenderThread(self.__ptr)
+end
+
 function RenderThread:enqueueFrame(frame)
 	local retVal = Polycode.RenderThread_enqueueFrame(self.__ptr, frame.__ptr)
 end

+ 1 - 1
bindings/lua/Polycode/Resource.lua

@@ -19,7 +19,7 @@ function Resource:__getvar(name)
 	elseif name == "resourceFileTime" then
 		local retVal = Polycode.Resource_get_resourceFileTime(self.__ptr)
 		if retVal == nil then return nil end
-		local __c = _G["time_t"]("__skip_ptr__")
+		local __c = _G["size_t"]("__skip_ptr__")
 		__c.__ptr = retVal
 		return __c
 	end

BIN
bindings/lua/lua_Polycode.pak


Diff do ficheiro suprimidas por serem muito extensas
+ 6 - 0
build/emscripten/Makefile


+ 17 - 0
build/emscripten/TemplateApp/PolycodeTemplate.cpp

@@ -0,0 +1,17 @@
+#include "PolycodeTemplateApp.h"
+#include "polycode/view/linux/PolycodeView.h"
+#include <emscripten.h>a
+
+PolycodeTemplateApp *app;
+
+void render()
+{
+	app->Update();
+}
+
+int main(int argc, char **argv) {
+	PolycodeView *view = new PolycodeView("Polycode Template");
+	app = new PolycodeTemplateApp(view);
+	emscripten_set_main_loop(render,60,true);
+	return 0;
+}

+ 73 - 0
build/emscripten/TemplateApp/PolycodeTemplateApp.cpp

@@ -0,0 +1,73 @@
+//
+// Polycode template. Write your code here.
+// 
+
+#include "PolycodeTemplateApp.h"
+
+
+PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
+    core = new POLYCODE_CORE(view, 800,480,false,false, 0,0,60);
+    
+    core->addFileSource("archive", "default.pak");
+    ResourcePool *globalPool = Services()->getResourceManager()->getGlobalPool();
+    globalPool->loadResourcesFromFolder("default", true);
+    
+	// Write your code here!
+    
+    Scene *scene = new Scene(Scene::SCENE_2D);
+    scene->useClearColor = true;
+    
+    test = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.5, 0.5);
+    test->setMaterialByName("Unlit");
+    test->getShaderPass(0).shaderBinding->loadTextureForParam("diffuse", "main_icon.png");
+    scene->addChild(test);
+	test->setPositionY(0.2);
+    
+	SceneLabel *testLabel = new SceneLabel("Hello Polycode!", 32, "sans", Label::ANTIALIAS_FULL, 0.2);
+	testLabel->setPositionY(-0.2);
+	scene->addChild(testLabel);
+    
+/*
+    bgSound = new Sound("bedlayer_main.wav");
+    bgSound->Play();
+//    bgSound->setPitch(10.0);
+    
+    
+    sound1 = new Sound("marimba-lo.wav");
+    
+    sound1->setPitch(2.3);
+    
+    sound2 = new Sound("initial_touch_01.wav");
+    sound3 = new Sound("curve_02_c.wav");
+    
+    //sound2->Play(true);
+  */
+    Services()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
+}
+
+void PolycodeTemplateApp::handleEvent(Event *event) {
+    InputEvent *inputEvent = (InputEvent*) event;
+    
+//     switch(inputEvent->getKey()) {
+//         case KEY_z:
+//             sound1->Play(true);
+//         break;
+//         case KEY_x:
+//             sound2->Play();
+//         break;
+//         case KEY_c:
+//             sound3->Play();
+//         break;
+//             
+//     }
+}
+
+PolycodeTemplateApp::~PolycodeTemplateApp() {
+    
+}
+
+bool PolycodeTemplateApp::Update() {
+    Number elapsed = core->getElapsed();
+    test->Roll(elapsed * 30.0);
+    return core->updateAndRender();
+}

+ 28 - 0
build/emscripten/TemplateApp/PolycodeTemplateApp.h

@@ -0,0 +1,28 @@
+//
+// Polycode template. Write your code here.
+//
+
+#include "Polycode.h"
+
+using namespace Polycode;
+
+class PolycodeTemplateApp : public EventHandler {
+public:
+    PolycodeTemplateApp(PolycodeView *view);
+    ~PolycodeTemplateApp();
+    
+    void handleEvent(Event *event);
+    
+    bool Update();
+    
+private:
+    
+    Sound *bgSound;
+    
+    Sound *sound1;
+    Sound *sound2;
+    Sound *sound3;
+    ScenePrimitive *test;
+    
+    Core *core;
+};

+ 4 - 4
build/osx/PolycodeCore/PolycodeCore.xcodeproj/project.pbxproj

@@ -9,7 +9,7 @@
 /* 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 */; };
-		6D904FD91CC4817C00D0E80A /* duktape.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D904FD81CC4817C00D0E80A /* duktape.c */; };
+		8A40875E1D0087AD009FF944 /* duktape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A40875D1D0087AD009FF944 /* duktape.cpp */; };
 		8A5EF4FC1CD90E4800F8466A /* PolycodeLua.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A5EF4FB1CD90E4800F8466A /* PolycodeLua.cpp */; };
 		8A5EF4FF1CD90F0200F8466A /* PolycodeLua.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A5EF4FD1CD90F0200F8466A /* PolycodeLua.h */; };
 		8A5EF5001CD90F0200F8466A /* PolycodeLuaWrappers.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A5EF4FE1CD90F0200F8466A /* PolycodeLuaWrappers.h */; };
@@ -180,7 +180,7 @@
 /* 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>"; };
-		6D904FD81CC4817C00D0E80A /* duktape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = duktape.c; path = ../../../src/duktape/duktape.c; sourceTree = "<group>"; };
+		8A40875D1D0087AD009FF944 /* duktape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = duktape.cpp; path = ../../../src/duktape/duktape.cpp; sourceTree = "<group>"; };
 		8A5EF4FB1CD90E4800F8466A /* PolycodeLua.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PolycodeLua.cpp; path = ../../../src/bindings/lua/PolycodeLua.cpp; sourceTree = "<group>"; };
 		8A5EF4FD1CD90F0200F8466A /* PolycodeLua.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeLua.h; path = ../../../include/polycode/bindings/lua/PolycodeLua.h; sourceTree = "<group>"; };
 		8A5EF4FE1CD90F0200F8466A /* PolycodeLuaWrappers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeLuaWrappers.h; path = ../../../include/polycode/bindings/lua/PolycodeLuaWrappers.h; sourceTree = "<group>"; };
@@ -372,7 +372,7 @@
 		8A8651E61B728638009F94DD /* src */ = {
 			isa = PBXGroup;
 			children = (
-				6D904FD81CC4817C00D0E80A /* duktape.c */,
+				8A40875D1D0087AD009FF944 /* duktape.cpp */,
 				8A9D12311CDD504400ACD484 /* PolycodeJS.cpp */,
 				8A5EF4FB1CD90E4800F8466A /* PolycodeLua.cpp */,
 				8A825F241B829BC20039E823 /* PolyPAAudioInterface.cpp */,
@@ -736,6 +736,7 @@
 				8A8652E21B72867F009F94DD /* PolyEntity.cpp in Sources */,
 				8A8652F21B72867F009F94DD /* PolyObject.cpp in Sources */,
 				8A8653011B72867F009F94DD /* PolySceneImage.cpp in Sources */,
+				8A40875E1D0087AD009FF944 /* duktape.cpp in Sources */,
 				8A8653001B72867F009F94DD /* PolySceneEntityInstance.cpp in Sources */,
 				8A8652DC1B72867F009F94DD /* PolyConfig.cpp in Sources */,
 				8A8652FE1B72867F009F94DD /* PolyResourceManager.cpp in Sources */,
@@ -764,7 +765,6 @@
 				8A825F251B829BC20039E823 /* PolyPAAudioInterface.cpp in Sources */,
 				8A8653041B72867F009F94DD /* PolySceneLine.cpp in Sources */,
 				8A8653191B72867F009F94DD /* PolyVector3.cpp in Sources */,
-				6D904FD91CC4817C00D0E80A /* duktape.c in Sources */,
 				8A8653141B72867F009F94DD /* PolyTimer.cpp in Sources */,
 				8A86530D1B72867F009F94DD /* PolySkeleton.cpp in Sources */,
 				8A86530E1B72867F009F94DD /* PolySocket.cpp in Sources */,

+ 5 - 1
include/Polycode.h

@@ -104,7 +104,11 @@
 			#ifdef RPI_CORE
 				#include "polycode/core/PolyRPICore.h"
 			#else
-				#include "polycode/core/PolySDLCore.h"
+				#ifdef EMSCRIPTEN
+					#include "polycode/core/PolyEmscriptenCore.h"
+				#else
+					#include "polycode/core/PolySDLCore.h"
+				#endif
 			#endif
 		#endif
     #endif

+ 17 - 35
include/polycode/bindings/javascript/PolycodeJSWrappers.h

@@ -813,7 +813,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Camera_setViewport(duk_context *context) {
 		Camera *inst = (Camera*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->setViewport(viewport);
 		return 0;
 	}
@@ -847,7 +847,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Camera_projectRayFrom2DCoordinate(duk_context *context) {
 		Camera *inst = (Camera*)duk_to_pointer(context, 0);
 		Vector2 coordinate = *(Vector2*)duk_to_pointer(context, 1);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 2);
 		Vector3 *retInst = new Vector3();
 		*retInst = inst->projectRayFrom2DCoordinate(coordinate,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -2546,7 +2546,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_CoreServices_Render(duk_context *context) {
 		CoreServices *inst = (CoreServices*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->Render(viewport);
 		return 0;
 	}
@@ -3100,7 +3100,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Entity_transformAndRender(duk_context *context) {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		GPUDrawBuffer* drawBuffer = (GPUDrawBuffer*)duk_to_pointer(context, 1);
-		Rectangle* parentScissorBox = (Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle* parentScissorBox = (Polycode::Rectangle*)duk_to_pointer(context, 2);
 		inst->transformAndRender(drawBuffer,parentScissorBox);
 		return 0;
 	}
@@ -3108,7 +3108,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Entity_renderChildren(duk_context *context) {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		GPUDrawBuffer* buffer = (GPUDrawBuffer*)duk_to_pointer(context, 1);
-		Rectangle* parentScissorBox = (Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle* parentScissorBox = (Polycode::Rectangle*)duk_to_pointer(context, 2);
 		inst->renderChildren(buffer,parentScissorBox);
 		return 0;
 	}
@@ -3846,7 +3846,7 @@ namespace Polycode {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		Matrix4 projectionMatrix = *(Matrix4*)duk_to_pointer(context, 1);
 		Matrix4 cameraMatrix = *(Matrix4*)duk_to_pointer(context, 2);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 3);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 3);
 		Vector2 *retInst = new Vector2();
 		*retInst = inst->getScreenPosition(projectionMatrix,cameraMatrix,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -4845,7 +4845,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Image_getImagePart(duk_context *context) {
 		Image *inst = (Image*)duk_to_pointer(context, 0);
-		Rectangle subRect = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle subRect = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		PolyBase *ptrRetVal = (PolyBase*)inst->getImagePart(subRect);
 		duk_push_pointer(context, (void*)ptrRetVal);
 		return 1;
@@ -7880,7 +7880,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Rectangle_Clipped(duk_context *context) {
 		Rectangle *inst = (Rectangle*)duk_to_pointer(context, 0);
-		Rectangle rect = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle rect = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		Polycode::Rectangle *retInst = new Polycode::Rectangle();
 		*retInst = inst->Clipped(rect);
 		duk_push_pointer(context, (void*)retInst);
@@ -8165,6 +8165,12 @@ namespace Polycode {
 		return 0;
 	}
 
+	duk_ret_t Polycode_RenderThread_updateRenderThread(duk_context *context) {
+		RenderThread *inst = (RenderThread*)duk_to_pointer(context, 0);
+		inst->updateRenderThread();
+		return 0;
+	}
+
 	duk_ret_t Polycode_RenderThread_enqueueFrame(duk_context *context) {
 		RenderThread *inst = (RenderThread*)duk_to_pointer(context, 0);
 		RenderFrame* frame = (RenderFrame*)duk_to_pointer(context, 1);
@@ -8492,7 +8498,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Resource__get_resourceFileTime(duk_context *context) {
 		Resource *inst = (Resource*)duk_to_pointer(context, 0);
-		time_t *retInst = new time_t();
+		size_t *retInst = new size_t();
 		*retInst = inst->resourceFileTime;
 		duk_push_pointer(context, (void*)retInst);
 		return 1;
@@ -8500,7 +8506,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Resource__set_resourceFileTime(duk_context *context) {
 		Resource *inst = (Resource*)duk_to_pointer(context, 0);
-		inst->resourceFileTime = *(time_t*)duk_to_pointer(context, 1);
+		inst->resourceFileTime = *(size_t*)duk_to_pointer(context, 1);
 		return 0;
 	}
 
@@ -9999,7 +10005,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_SceneManager_Render(duk_context *context) {
 		SceneManager *inst = (SceneManager*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->Render(viewport);
 		return 0;
 	}
@@ -11073,30 +11079,6 @@ namespace Polycode {
 		return 0;
 	}
 
-	duk_ret_t Polycode_JSScriptInstance__delete(duk_context *context) {
-		JSScriptInstance *inst = (JSScriptInstance*)duk_to_pointer(context, 0);
-		delete inst;
-		return 0;
-	}
-
-	duk_ret_t Polycode_LuaScriptInstance__get_tableRef(duk_context *context) {
-		LuaScriptInstance *inst = (LuaScriptInstance*)duk_to_pointer(context, 0);
-		duk_push_int(context, inst->tableRef);
-		return 1;
-	}
-
-	duk_ret_t Polycode_LuaScriptInstance__set_tableRef(duk_context *context) {
-		LuaScriptInstance *inst = (LuaScriptInstance*)duk_to_pointer(context, 0);
-		inst->tableRef = duk_to_int(context, 1);
-		return 0;
-	}
-
-	duk_ret_t Polycode_LuaScriptInstance__delete(duk_context *context) {
-		LuaScriptInstance *inst = (LuaScriptInstance*)duk_to_pointer(context, 0);
-		delete inst;
-		return 0;
-	}
-
 	duk_ret_t Polycode_ScriptInstance__get_script(duk_context *context) {
 		ScriptInstance *inst = (ScriptInstance*)duk_to_pointer(context, 0);
 		PolyBase *ptrRetVal = (PolyBase*)inst->script;

+ 7 - 32
include/polycode/bindings/lua/PolycodeLuaWrappers.h

@@ -11264,6 +11264,12 @@ static int Polycode_RendererThreadJob_set_jobType(lua_State *L) {
 		inst->runThread();
 		return 0;
 	}
+	static int Polycode_RenderThread_updateRenderThread(lua_State *L) {
+		luaL_checktype(L, 1, LUA_TUSERDATA);
+		RenderThread *inst = (RenderThread*) *((PolyBase**)lua_touserdata(L, 1));
+		inst->updateRenderThread();
+		return 0;
+	}
 	static int Polycode_RenderThread_enqueueFrame(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		RenderThread *inst = (RenderThread*) *((PolyBase**)lua_touserdata(L, 1));
@@ -11747,7 +11753,7 @@ static int Polycode_Resource_set_resourceFileTime(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TUSERDATA);
 	Resource *inst = (Resource*) *((PolyBase**)lua_touserdata(L, 1));
 	luaL_checktype(L, 2, LUA_TUSERDATA);
-	time_t *argInst = (time_t*) *((PolyBase**)lua_touserdata(L, 2));
+	size_t *argInst = (size_t*) *((PolyBase**)lua_touserdata(L, 2));
 	inst->resourceFileTime = *argInst;
 	return 0;
 }
@@ -15597,37 +15603,6 @@ static int Polycode_SpriteFrame_set_frameID(lua_State *L) {
 		return 0;
 	}
 
-	static int Polycode_delete_JSScriptInstance(lua_State *L) {
-		luaL_checktype(L, 1, LUA_TUSERDATA);
-		PolyBase **inst = (PolyBase**)lua_touserdata(L, 1);
-		delete ((JSScriptInstance*) *inst);
-		*inst = NULL;
-		return 0;
-	}
-
-static int Polycode_LuaScriptInstance_get_tableRef(lua_State *L) {
-	luaL_checktype(L, 1, LUA_TUSERDATA);
-	LuaScriptInstance *inst = (LuaScriptInstance*) *((PolyBase**)lua_touserdata(L, 1));
-	lua_pushinteger(L, inst->tableRef);
-	return 1;
-}
-
-static int Polycode_LuaScriptInstance_set_tableRef(lua_State *L) {
-	luaL_checktype(L, 1, LUA_TUSERDATA);
-	LuaScriptInstance *inst = (LuaScriptInstance*) *((PolyBase**)lua_touserdata(L, 1));
-	int param = lua_tointeger(L, 2);
-	inst->tableRef = param;
-	return 0;
-}
-
-	static int Polycode_delete_LuaScriptInstance(lua_State *L) {
-		luaL_checktype(L, 1, LUA_TUSERDATA);
-		PolyBase **inst = (PolyBase**)lua_touserdata(L, 1);
-		delete ((LuaScriptInstance*) *inst);
-		*inst = NULL;
-		return 0;
-	}
-
 static int Polycode_ScriptInstance_get_script(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TUSERDATA);
 	ScriptInstance *inst = (ScriptInstance*) *((PolyBase**)lua_touserdata(L, 1));

+ 104 - 0
include/polycode/core/PolyEmscriptenCore.h

@@ -0,0 +1,104 @@
+/*
+ Copyright (C) 2011 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 "PolyGlobals.h"
+#include "PolyCore.h"
+#include <vector>
+#include <pthread.h>
+#include <time.h>
+// #include <SDL2/SDL.h>
+
+#ifndef NO_PAUDIO
+	#include "polycode/core/PolyPAAudioInterface.h"
+#endif
+
+#define POLYCODE_CORE EmscriptenCore
+
+struct SDL_mutex;
+
+namespace Polycode {
+
+	class PolycodeView;
+	class RenderThread;
+
+	class _PolyExport EmscriptenCoreMutex : public CoreMutex {
+	public:
+		void lock();
+		void unlock();
+		pthread_mutex_t pMutex;
+	};
+
+	class _PolyExport EmscriptenCore : public Core {
+		
+	public:
+		
+		EmscriptenCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex=-1, bool retinaSupport=false);
+		~EmscriptenCore();
+
+		void enableMouse(bool newval);
+		void captureMouse(bool);
+		unsigned int getTicks();
+		bool systemUpdate();
+		void Render();
+		void flushRenderContext();
+		
+		void handleVideoModeChange(VideoModeChangeInfo *modeInfo);
+		void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport = true);
+		void createThread(Threaded *target);
+		std::vector<Rectangle> getVideoModes();
+		
+		bool systemParseFolder(const String& pathString, bool showHidden, std::vector<OSFileEntry> &targetVector);
+				
+		void setCursor(int cursorType);
+		void warpCursor(int x, int y);
+		//void lockMutex(CoreMutex *mutex);
+		//void unlockMutex(CoreMutex *mutex);
+		CoreMutex *createMutex();
+		void copyStringToClipboard(const String& str);
+		String getClipboardString();
+		void createFolder(const String& folderPath);
+		void copyDiskItem(const String& itemPath, const String& destItemPath);
+		void moveDiskItem(const String& itemPath, const String& destItemPath);
+		void removeDiskItem(const String& itemPath);
+		String openFolderPicker();
+		std::vector<String> openFilePicker(std::vector<CoreFileExtension> extensions, bool allowMultiple);
+                String saveFilePicker(std::vector<CoreFileExtension> extensions);
+		void resizeTo(int xRes, int yRes);
+
+		String executeExternalCommand(String command, String args, String inDirectory="");
+		void openURL(String url);
+
+	private:
+		bool checkSpecialKeyEvents(PolyKEY key);
+		
+		uint32_t flags;
+		bool resizableWindow;
+		
+		String* windowTitle;
+		RenderThread *renderThread;
+
+		int lastMouseX;
+		int lastMouseY;
+	};
+}

+ 5 - 2
include/polycode/core/PolyOpenGLGraphicsInterface.h

@@ -59,8 +59,11 @@ THE SOFTWARE.
 		#include <EGL/eglext.h>
 		#include <GLES2/gl2.h>
 	#else
-		#include <glew/GL/glew.h>
-		
+		#ifdef EMSCRIPTEN
+			#include "SDL/SDL_opengl.h"
+		#else
+			#include <glew/GL/glew.h>
+		#endif
 		/*#include <GL/gl.h>
 		#include <GL/glu.h>
 		#include <GL/glext.h>*/

+ 3 - 3
include/polycode/core/PolyRenderer.h

@@ -130,7 +130,7 @@ namespace Polycode {
             RenderThread();
              void setGraphicsInterface(Core *core, GraphicsInterface *graphicsInterface);
             virtual void runThread();
-        
+	    void updateRenderThread();   
             void enqueueFrame(RenderFrame *frame);
         
             void enqueueJob(int jobType, void *data, void *data2=NULL);
@@ -192,8 +192,8 @@ namespace Polycode {
     class _PolyExport Renderer : public PolyBase {
 	public:
         
-		Renderer();
-		virtual ~Renderer();
+	Renderer(RenderThread *customThread=NULL);
+	virtual ~Renderer();
         void setGraphicsInterface(Core *core, GraphicsInterface *graphicsInterface);
         
         RenderThread *getRenderThread();

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

@@ -66,7 +66,7 @@ namespace Polycode {
         
             static bool defaultReloadOnFileModify;
         
-			time_t resourceFileTime;
+			size_t resourceFileTime;
 						
 			//@}
 			

+ 6 - 3
include/polycode/core/PolyResourceManager.h

@@ -32,10 +32,11 @@ THE SOFTWARE.
 #include FT_LCD_FILTER_H
 
 extern "C" {
+#ifndef NO_LUA
     #include "lua.h"
     #include "lualib.h"
     #include "lauxlib.h"
-    
+#endif   
     #include "duktape.h"
 }
 
@@ -142,11 +143,13 @@ namespace Polycode {
         Resource *loadResource(const String &path, ResourcePool *targetPool);
     private:
         
-        void initLua();
         void initJavascript();
+        duk_context *duktapeContext;
         
+#ifndef NO_LUA
+        void initLua();
         lua_State *luaState;
-        duk_context *duktapeContext;
+#endif
     };
     
     class _PolyExport MeshResourceLoader : public ResourceLoader {

+ 6 - 3
include/polycode/core/PolyScript.h

@@ -26,10 +26,11 @@
 #include "polycode/core/PolyString.h"
 
 extern "C" {
+#ifndef NO_LUA
     #include "lua.h"
     #include "lualib.h"
     #include "lauxlib.h"
-    
+#endif
     #include "duktape.h"
 }
 
@@ -51,6 +52,7 @@ namespace Polycode {
             virtual void callUpdate(ScriptInstance *instance, Entity *entity, Number elapsed) = 0;
     };
     
+#ifndef NO_LUA
     class LuaScriptInstance : public ScriptInstance {
         public:
             int tableRef;
@@ -68,7 +70,8 @@ namespace Polycode {
             int tableRef;
             int errH;
     };
-    
+#endif
+
     class JSScriptInstance : public ScriptInstance {
     public:
         void *objectRef;
@@ -86,4 +89,4 @@ namespace Polycode {
         duk_context *context;
     };
 
-}
+}

+ 2 - 2
scripts/create_bindings/bindings.conf

@@ -7,11 +7,11 @@ TargetDirectory = ../../include/polycode/core
 #include path prefix used when including the header files from generated headers (i.e. bar for #include "bar/Foo.h")
 HeaderIncludeDirectory = polycode/core
 #comma separated list of header files without extensions to ignore (i.e. Foo for Foo.h)
-IgnoreFiles = PolyTween, PolyTweenManager, PolyGLSLProgram, PolyGLSLShader, PolyGLSLShaderModule, PolyWinCore, PolyIOSCore, PolyRPICore, PolyUWPCore, PolyCocoaCore, PolyAGLCore, PolySDLCore, Poly_iPhone, PolyGLES1Renderer, PolyGLRenderer, tinyxml, tinystr, OpenGLCubemap, PolyiPhoneCore, PolyGLES1Texture, PolyGLTexture, PolyGLVertexBuffer, PolyThreaded, PolyGLHeaders, GLee, PolyPeer, PolySocket, PolyClient, PolyServer, PolyServerWorld, OSFILE, OSFileEntry, OSBasics, PolyLogger, PolyFontGlyphSheet, PolyXAudio2AudioInterface
+IgnoreFiles = PolyTween, PolyTweenManager, PolyGLSLProgram, PolyGLSLShader, PolyGLSLShaderModule, PolyWinCore, PolyEmscriptenCore, PolyIOSCore, PolyRPICore, PolyUWPCore, PolyCocoaCore, PolyAGLCore, PolySDLCore, Poly_iPhone, PolyGLES1Renderer, PolyGLRenderer, tinyxml, tinystr, OpenGLCubemap, PolyiPhoneCore, PolyGLES1Texture, PolyGLTexture, PolyGLVertexBuffer, PolyThreaded, PolyGLHeaders, GLee, PolyPeer, PolySocket, PolyClient, PolyServer, PolyServerWorld, OSFILE, OSFileEntry, OSBasics, PolyLogger, PolyFontGlyphSheet, PolyXAudio2AudioInterface
 #comma separated list of non-standard symbols to strip that might affect header parsing (i.e. __declspec(dllexport))
 StripSymbols = _PolyExport
 #comma separated list of classes to ignore when parsing (i.e. CFoo, CBar)
-IgnoreClasses = PAAudioInterface, AudioInterface, ResourceLoader, CoreFile, CoreFileProvider, GraphicsInterface, Script, LuaScript, JSScript, Object, Threaded, OpenGLCubemap, PolyBase, Matrix4::union, BasicFile, BasicFileProvider, Cubemap, OpenGLGraphicsInterface, PhysFSFile, PhysFSFileProvider, TimerManager, VertexDataArray, IndexDataArray, CoreMutex
+IgnoreClasses = PAAudioInterface, AudioInterface, ResourceLoader, CoreFile, CoreFileProvider, GraphicsInterface, Script, LuaScript, JSScript, Object, Threaded, OpenGLCubemap, PolyBase, Matrix4::union, BasicFile, BasicFileProvider, Cubemap, OpenGLGraphicsInterface, PhysFSFile, PhysFSFileProvider, TimerManager, VertexDataArray, IndexDataArray, CoreMutex, LuaScriptInstance, JSScriptInstance
 #comma separated list of class methods to ignore
 IgnoreMethods = readByte32, readByte16, getCustomEntitiesByType, Core, Renderer, Shader, Texture, handleEvent, secondaryHandler, getSTLString, readInt, CoreServices
 #main library name

+ 1 - 4
src/bindings/javascript/PolycodeJS.cpp

@@ -1169,6 +1169,7 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"RenderThread__delete", Polycode_RenderThread__delete, 1},
 			{"RenderThread_setGraphicsInterface", Polycode_RenderThread_setGraphicsInterface, 3},
 			{"RenderThread_runThread", Polycode_RenderThread_runThread, 1},
+			{"RenderThread_updateRenderThread", Polycode_RenderThread_updateRenderThread, 1},
 			{"RenderThread_enqueueFrame", Polycode_RenderThread_enqueueFrame, 2},
 			{"RenderThread_enqueueJob", Polycode_RenderThread_enqueueJob, 4},
 			{"RenderThread_processJob", Polycode_RenderThread_processJob, 2},
@@ -1588,10 +1589,6 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"SpriteState_getBoundingBox", Polycode_SpriteState_getBoundingBox, 1},
 			{"SpriteState_getSpriteOffset", Polycode_SpriteState_getSpriteOffset, 1},
 			{"SpriteState_setSpriteOffset", Polycode_SpriteState_setSpriteOffset, 2},
-			{"JSScriptInstance__delete", Polycode_JSScriptInstance__delete, 1},
-			{"LuaScriptInstance__get_tableRef", Polycode_LuaScriptInstance__get_tableRef, 1},
-			{"LuaScriptInstance__set_tableRef", Polycode_LuaScriptInstance__set_tableRef, 2},
-			{"LuaScriptInstance__delete", Polycode_LuaScriptInstance__delete, 1},
 			{"ScriptInstance__get_script", Polycode_ScriptInstance__get_script, 1},
 			{"ScriptInstance__set_script", Polycode_ScriptInstance__set_script, 2},
 			{"ScriptInstance__delete", Polycode_ScriptInstance__delete, 1},

+ 1 - 16
src/bindings/lua/PolycodeLua.cpp

@@ -1227,6 +1227,7 @@ int luaopen_Polycode(lua_State *L) {
 		{"RenderThread", Polycode_RenderThread},
 		{"RenderThread_setGraphicsInterface", Polycode_RenderThread_setGraphicsInterface},
 		{"RenderThread_runThread", Polycode_RenderThread_runThread},
+		{"RenderThread_updateRenderThread", Polycode_RenderThread_updateRenderThread},
 		{"RenderThread_enqueueFrame", Polycode_RenderThread_enqueueFrame},
 		{"RenderThread_enqueueJob", Polycode_RenderThread_enqueueJob},
 		{"RenderThread_processJob", Polycode_RenderThread_processJob},
@@ -1683,10 +1684,6 @@ int luaopen_Polycode(lua_State *L) {
 		{"SpriteState_getSpriteOffset", Polycode_SpriteState_getSpriteOffset},
 		{"SpriteState_setSpriteOffset", Polycode_SpriteState_setSpriteOffset},
 		{"delete_SpriteState", Polycode_delete_SpriteState},
-		{"delete_JSScriptInstance", Polycode_delete_JSScriptInstance},
-		{"LuaScriptInstance_get_tableRef", Polycode_LuaScriptInstance_get_tableRef},
-		{"LuaScriptInstance_set_tableRef", Polycode_LuaScriptInstance_set_tableRef},
-		{"delete_LuaScriptInstance", Polycode_delete_LuaScriptInstance},
 		{"ScriptInstance_get_script", Polycode_ScriptInstance_get_script},
 		{"ScriptInstance_set_script", Polycode_ScriptInstance_set_script},
 		{"delete_ScriptInstance", Polycode_delete_ScriptInstance},
@@ -2590,18 +2587,6 @@ int luaopen_Polycode(lua_State *L) {
 	lua_settable(L, -3);
 	lua_pop(L, 1);
 
-	luaL_newmetatable(L, "Polycode.JSScriptInstance");
-	lua_pushstring(L, "__gc");
-	lua_pushcfunction(L, Polycode_delete_JSScriptInstance);
-	lua_settable(L, -3);
-	lua_pop(L, 1);
-
-	luaL_newmetatable(L, "Polycode.LuaScriptInstance");
-	lua_pushstring(L, "__gc");
-	lua_pushcfunction(L, Polycode_delete_LuaScriptInstance);
-	lua_settable(L, -3);
-	lua_pop(L, 1);
-
 	luaL_newmetatable(L, "Polycode.ScriptInstance");
 	lua_pushstring(L, "__gc");
 	lua_pushcfunction(L, Polycode_delete_ScriptInstance);

+ 559 - 0
src/core/PolyEmscriptenCore.cpp

@@ -0,0 +1,559 @@
+/*
+ Copyright (C) 2011 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/PolyEmscriptenCore.h"
+#include "polycode/view/linux/PolycodeView.h"
+#include "polycode/core/PolyCoreServices.h"
+#include "polycode/core/PolyCoreInput.h"
+#include "polycode/core/PolyMaterialManager.h"
+#include "polycode/core/PolyThreaded.h"
+#include "polycode/core/PolyLogger.h"
+
+#include "polycode/core/PolyOpenGLGraphicsInterface.h"
+#include "polycode/core/PolyBasicFileProvider.h"
+#ifndef NO_PHYSFS
+	#include "polycode/core/PolyPhysFSFileProvider.h"
+#endif
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_syswm.h>
+#include <stdio.h>
+#include <limits.h>
+#include <dirent.h>
+
+#include <iostream>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <pwd.h>
+
+using namespace Polycode;
+using std::vector;
+
+void EmscriptenCoreMutex::lock()
+{
+	//pthread_mutex_lock(&pMutex);    
+}
+
+void EmscriptenCoreMutex::unlock() {
+//	pthread_mutex_unlock(&pMutex);
+}
+
+
+long getThreadID() {
+	return 0;
+}
+
+void Core::getScreenInfo(int *width, int *height, int *hz) {
+	SDL_Init(SDL_INIT_VIDEO); // Or GetVideoInfo will not work
+	const SDL_VideoInfo *video = SDL_GetVideoInfo();
+	if (width) *width = video->current_w;
+	if (height) *height = video->current_h;
+	if (hz) *hz = 0;
+}
+
+EmscriptenCore::EmscriptenCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex, bool retinaSupport) : Core(_xRes, _yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
+  
+	this->resizableWindow = view->resizable;
+
+	fileProviders.push_back(new BasicFileProvider());
+#ifndef NO_PHYSFS
+	fileProviders.push_back(new PhysFSFileProvider());
+#endif
+	char *buffer = getcwd(NULL, 0);
+	defaultWorkingDirectory = String(buffer);
+	free(buffer);
+
+	struct passwd *pw = getpwuid(getuid());
+	const char *homedir = pw->pw_dir;
+	userHomeDirectory = String(homedir);
+
+	windowTitle = (String*)view->windowData;
+	
+	if(resizableWindow) {
+		unsetenv("SDL_VIDEO_CENTERED");
+	} else {
+		setenv("SDL_VIDEO_CENTERED", "1", 1);
+	}
+	
+	int sdlerror = SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
+	if(sdlerror < 0) {
+	  Logger::log("SDL_Init failed! Code: %d, %s\n", sdlerror, SDL_GetError());
+	}
+	
+	SDL_Surface* icon = SDL_LoadBMP("icon.bmp");
+	if(icon){
+		SDL_WM_SetIcon(icon, NULL);
+	}
+	
+	eventMutex = createMutex();
+	
+	renderThread = new RenderThread();
+	renderer = new Renderer(renderThread);
+
+
+	OpenGLGraphicsInterface *renderInterface = new OpenGLGraphicsInterface();
+	renderInterface->lineSmooth = true;
+	renderer->setGraphicsInterface(this, renderInterface);
+	services->setRenderer(renderer);
+	setVideoMode(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport);
+	
+	SDL_WM_SetCaption(windowTitle->c_str(), windowTitle->c_str());
+	
+	SDL_EnableUNICODE(1);
+	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+	
+	SDL_JoystickEventState(SDL_ENABLE);
+	
+	int numJoysticks = SDL_NumJoysticks();
+	
+	for(int i=0; i < numJoysticks; i++) {
+		SDL_JoystickOpen(i);
+		input->addJoystick(i);
+	}
+
+#ifndef NO_PAUDIO
+	services->getSoundManager()->setAudioInterface(new PAAudioInterface());
+#endif 
+
+	lastMouseX = 0;
+	lastMouseY = 0;
+
+#ifdef USE_X11
+	// Start listening to clipboard events.
+	// (Yes on X11 you need to actively listen to
+	//  clipboard events and respond to them)
+	init_scrap();
+#endif // USE_X11
+}
+
+void EmscriptenCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport) {
+	//renderer->Resize(xRes, yRes);
+	//CoreServices::getInstance()->getMaterialManager()->reloadProgramsAndTextures();
+	//dispatchEvent(new Event(), EVENT_CORE_RESIZE);
+	Core::setVideoMode(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport);
+}
+
+void EmscriptenCore::handleVideoModeChange(VideoModeChangeInfo* modeInfo){
+
+
+	this->xRes = modeInfo->xRes;
+	this->yRes = modeInfo->yRes;
+	this->fullScreen = modeInfo->fullScreen;
+	this->aaLevel = modeInfo->aaLevel;
+	this->anisotropyLevel = modeInfo->anisotropyLevel;
+	this->vSync = modeInfo->vSync;
+	
+	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24);
+	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
+	SDL_GL_SetAttribute( SDL_GL_RED_SIZE,   8);
+	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
+	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE,  8);
+	SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
+	
+	if(aaLevel > 0) {
+		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, aaLevel); //0, 2, 4
+	} else {
+		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
+		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
+	}
+	
+	flags = SDL_OPENGL;
+
+	if(fullScreen) {
+		flags |= SDL_FULLSCREEN;
+	}
+
+	if(resizableWindow) {
+		flags |= SDL_RESIZABLE;
+	}
+	
+// 	if(modeInfo->retinaSupport) {
+// 		flags |= SDL_WINDOW_ALLOW_HIGHDPI;
+// 	}
+/*
+	if(vSync) {
+		flags |= SDL_DOUBLEBUF;
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+	} else {
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
+ -		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0);
+	}
+*/
+
+	SDL_SetVideoMode(xRes, yRes, 0, flags);
+
+	/*
+	int glewcode = glewInit();
+	if (glewcode != GLEW_OK){
+	  Logger::log("glewInit failed! code: %d, %s\n", glewcode, glewGetErrorString(glewcode));
+	}
+	*/
+
+	//setVSync(modeInfo->vSync);
+	renderer->setAnisotropyAmount(modeInfo->anisotropyLevel);
+	renderThread->initGlobals();
+}
+
+vector<Polycode::Rectangle> EmscriptenCore::getVideoModes() {
+	vector<Polycode::Rectangle> retVector;
+	
+	SDL_Rect **modes;
+	modes=SDL_ListModes(NULL, SDL_FULLSCREEN);
+	for(int i=0;modes[i];++i) {
+		Rectangle res;
+		res.w = modes[i]->w;
+		res.h = modes[i]->h;
+		retVector.push_back(res);
+	}	
+	
+	return retVector;
+}
+
+EmscriptenCore::~EmscriptenCore() {
+	SDL_Quit();
+}
+
+void EmscriptenCore::openURL(String url) {
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+	execl("/usr/bin/xdg-open", "/usr/bin/xdg-open", url.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
+    }
+}
+
+String EmscriptenCore::executeExternalCommand(String command, String args, String inDirectory) {
+	String finalCommand = command + " " + args;
+
+	if(inDirectory != "") {
+		finalCommand = "cd " + inDirectory + " && " + finalCommand;
+	}
+
+	FILE *fp = popen(finalCommand.c_str(), "r");
+	if(!fp) {
+		return "Unable to execute command";
+	}	
+
+	int fd = fileno(fp);
+
+	char path[2048];
+	String retString;
+
+	while (fgets(path, sizeof(path), fp) != NULL) {
+		retString = retString + String(path);
+	}
+
+	pclose(fp);
+	return retString;
+}
+
+void *ManagedThreadFunc(void *data) {
+	Threaded *target = (Threaded*)data;
+	target->runThread();
+	target->scheduledForRemoval = true;
+	return NULL;
+}
+
+void EmscriptenCore::createThread(Threaded *target) {
+	Core::createThread(target);
+//	pthread_t thread;
+//	pthread_create( &thread, NULL, ManagedThreadFunc, (void*)target);
+}
+
+unsigned int EmscriptenCore::getTicks() {
+	return SDL_GetTicks();
+}
+
+void EmscriptenCore::enableMouse(bool newval) {
+	if(newval) {
+		SDL_ShowCursor(1);
+		//SDL_WM_GrabInput(SDL_GRAB_OFF);
+	} else {
+		SDL_ShowCursor(0);
+		//SDL_WM_GrabInput(SDL_GRAB_ON);
+	}
+	Core::enableMouse(newval);
+}
+
+void EmscriptenCore::captureMouse(bool newval) {
+	if(newval) {
+		SDL_WM_GrabInput(SDL_GRAB_ON);
+	} else {
+		SDL_WM_GrabInput(SDL_GRAB_OFF);
+	}
+	Core::captureMouse(newval);
+}
+
+bool EmscriptenCore::checkSpecialKeyEvents(PolyKEY key) {
+	
+	if(key == KEY_a && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL))) {
+		dispatchEvent(new Event(), Core::EVENT_SELECT_ALL);
+		return true;
+	}
+	
+	if(key == KEY_c && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL))) {
+		dispatchEvent(new Event(), Core::EVENT_COPY);
+		return true;
+	}
+	
+	if(key == KEY_x && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL))) {
+		dispatchEvent(new Event(), Core::EVENT_CUT);
+		return true;
+	}
+	
+	
+	if(key == KEY_z  && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL)) && (input->getKeyState(KEY_LSHIFT) || input->getKeyState(KEY_RSHIFT))) {
+		dispatchEvent(new Event(), Core::EVENT_REDO);
+		return true;
+	}
+		
+	if(key == KEY_z  && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL))) {
+		dispatchEvent(new Event(), Core::EVENT_UNDO);
+		return true;
+	}
+	
+	if(key == KEY_v && (input->getKeyState(KEY_LCTRL) || input->getKeyState(KEY_RCTRL))) {
+		dispatchEvent(new Event(), Core::EVENT_PASTE);
+		return true;
+	}
+	return false;
+}
+
+void EmscriptenCore::Render() {
+	renderer->beginFrame();
+	services->Render(Polycode::Rectangle(0, 0, getBackingXRes(), getBackingYRes()));
+	renderer->endFrame();
+	renderThread->updateRenderThread();
+}
+
+void EmscriptenCore::flushRenderContext(){
+	SDL_GL_SwapBuffers();
+}
+
+bool EmscriptenCore::systemUpdate() {
+	if(!running)
+		return false;
+	doSleep();	
+	
+	updateCore();
+	
+	SDL_Event event;
+	while ( SDL_PollEvent(&event) ) {
+			switch (event.type) {
+				case SDL_QUIT:
+					running = false;
+				break;
+				case SDL_VIDEORESIZE:
+					if(resizableWindow) {
+						unsetenv("SDL_VIDEO_CENTERED");
+					} else {
+						setenv("SDL_VIDEO_CENTERED", "1", 1);
+					}
+					this->xRes = event.resize.w;
+					this->yRes = event.resize.h;
+					SDL_SetVideoMode(xRes, yRes, 0, flags);
+					dispatchEvent(new Event(), EVENT_CORE_RESIZE);	
+				break;
+				case SDL_ACTIVEEVENT:
+					if(event.active.state == SDL_APPINPUTFOCUS){
+						if(event.active.gain == 1){
+							gainFocus();
+						} else {
+							loseFocus();
+						}
+					}
+				break;
+				case SDL_JOYAXISMOTION:
+					input->joystickAxisMoved(event.jaxis.axis, ((Number)event.jaxis.value)/32767.0, event.jaxis.which);
+				break;
+				case SDL_JOYBUTTONDOWN:
+					input->joystickButtonDown(event.jbutton.button, event.jbutton.which);
+				break;
+				case SDL_JOYBUTTONUP:
+					input->joystickButtonUp(event.jbutton.button, event.jbutton.which);
+				break;
+				case SDL_KEYDOWN:
+					if(!checkSpecialKeyEvents((PolyKEY)(event.key.keysym.sym))) {
+						input->setKeyState((PolyKEY)(event.key.keysym.sym), event.key.keysym.unicode, true, getTicks());
+					}
+				break;
+				case SDL_KEYUP:
+					input->setKeyState((PolyKEY)(event.key.keysym.sym), event.key.keysym.unicode, false, getTicks());
+				break;
+				case SDL_MOUSEBUTTONDOWN:
+					if(event.button.button == SDL_BUTTON_WHEELUP){
+						input->mouseWheelUp(getTicks());
+					} else if (event.button.button == SDL_BUTTON_WHEELDOWN){
+						input->mouseWheelDown(getTicks());
+					} else {
+						switch(event.button.button) {
+							case SDL_BUTTON_LEFT:
+								input->setMouseButtonState(CoreInput::MOUSE_BUTTON1, true, getTicks());
+							break;
+							case SDL_BUTTON_RIGHT:
+								input->setMouseButtonState(CoreInput::MOUSE_BUTTON2, true, getTicks());
+							break;
+							case SDL_BUTTON_MIDDLE:
+								input->setMouseButtonState(CoreInput::MOUSE_BUTTON3, true, getTicks());
+							break;
+						}
+					}
+				break;
+				case SDL_MOUSEBUTTONUP:
+					switch(event.button.button) {
+						case SDL_BUTTON_LEFT:
+							input->setMouseButtonState(CoreInput::MOUSE_BUTTON1, false, getTicks());
+						break;
+						case SDL_BUTTON_RIGHT:
+							input->setMouseButtonState(CoreInput::MOUSE_BUTTON2, false, getTicks());
+						break;
+						case SDL_BUTTON_MIDDLE:
+							input->setMouseButtonState(CoreInput::MOUSE_BUTTON3, false, getTicks());
+						break;
+					}
+				break;
+				case SDL_MOUSEMOTION:
+					input->setDeltaPosition(lastMouseX - event.motion.x, lastMouseY - event.motion.y);					
+					input->setMousePosition(event.motion.x, event.motion.y, getTicks());
+					lastMouseY = event.motion.y;
+					lastMouseX = event.motion.x;
+				break;
+				default:
+					break;
+			}
+		}
+	return running;
+}
+
+void EmscriptenCore::setCursor(int cursorType) {
+}
+
+void EmscriptenCore::warpCursor(int x, int y) {
+	SDL_WarpMouse(x, y);
+	lastMouseX = x;
+	lastMouseY = y;
+}
+
+/*void EmscriptenCore::lockMutex(CoreMutex *mutex) {
+	EmscriptenCoreMutex *smutex = (EmscriptenCoreMutex*)mutex;
+	SDL_mutexP(smutex->pMutex);
+
+}
+
+void EmscriptenCore::unlockMutex(CoreMutex *mutex) {
+	EmscriptenCoreMutex *smutex = (EmscriptenCoreMutex*)mutex;
+	SDL_mutexV(smutex->pMutex);
+}*/
+
+CoreMutex *EmscriptenCore::createMutex() {
+	EmscriptenCoreMutex *mutex = new EmscriptenCoreMutex();
+	//pthread_mutex_init(&mutex->pMutex, NULL);
+	return mutex;	
+}
+
+void EmscriptenCore::copyStringToClipboard(const String& str) {
+// 	SDL_SetClipboardText(str.c_str());
+}
+
+String EmscriptenCore::getClipboardString() {
+}
+
+void EmscriptenCore::createFolder(const String& folderPath) {
+	mkdir(folderPath.c_str(), 0700);
+}
+
+void EmscriptenCore::copyDiskItem(const String& itemPath, const String& destItemPath) {
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/cp", "/bin/cp", "-RT", itemPath.c_str(), destItemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, 0);
+    }
+}
+
+void EmscriptenCore::moveDiskItem(const String& itemPath, const String& destItemPath) {
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/mv", "/bin/mv", itemPath.c_str(), destItemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, 0);
+    }
+}
+
+void EmscriptenCore::removeDiskItem(const String& itemPath) {
+    int childExitStatus;
+    pid_t pid = fork();
+    if (pid == 0) {
+        execl("/bin/rm", "/bin/rm", "-rf", itemPath.c_str(), (char *)0);
+    } else {
+        pid_t ws = waitpid( pid, &childExitStatus, 0);
+    }
+}
+
+String EmscriptenCore::openFolderPicker() {
+	String r = "";
+	return r;
+}
+
+vector<String> EmscriptenCore::openFilePicker(vector<CoreFileExtension> extensions, bool allowMultiple) {
+	vector<String> r;
+	return r;
+}
+
+String EmscriptenCore::saveFilePicker(std::vector<CoreFileExtension> extensions) {
+        String r = "";
+        return r;
+}
+
+void EmscriptenCore::resizeTo(int xRes, int yRes) {
+	this->xRes = xRes;
+	this->yRes = yRes;
+	dispatchEvent(new Event(), EVENT_CORE_RESIZE);
+}
+
+bool EmscriptenCore::systemParseFolder(const String& pathString, bool showHidden, vector< OSFileEntry >& targetVector) {
+    DIR           *d;
+    struct dirent *dir;
+    
+    d = opendir(pathString.c_str());
+    if(d) {
+        while ((dir = readdir(d)) != NULL) {
+            if(dir->d_name[0] != '.' || (dir->d_name[0] == '.'  && showHidden)) {
+                if(dir->d_type == DT_DIR) {
+                    targetVector.push_back(OSFileEntry(pathString, dir->d_name, OSFileEntry::TYPE_FOLDER));
+                } else {
+                    targetVector.push_back(OSFileEntry(pathString, dir->d_name, OSFileEntry::TYPE_FILE));
+                }
+            }
+        }
+        closedir(d);
+    }
+    return true;
+}

+ 1 - 0
src/core/PolyOpenGLGraphicsInterface.cpp

@@ -24,6 +24,7 @@
 #include "polycode/core/PolyOpenGLGraphicsInterface.h"
 #include "polycode/core/PolyLogger.h"
 #include "polycode/core/PolyCoreServices.h"
+#include <stdlib.h>
 
 using namespace Polycode;
 

+ 1 - 0
src/core/PolyParticleEmitter.cpp

@@ -25,6 +25,7 @@
 #include "polycode/core/PolyCore.h"
 #include "polycode/core/PolyMesh.h"
 #include "polycode/core/PolyRenderer.h"
+#include <stdlib.h>
 
 using namespace Polycode;
 

+ 18 - 12
src/core/PolyRenderer.cpp

@@ -67,13 +67,7 @@ void RenderThread::initGlobals() {
     }
 }
 
-
-void RenderThread::runThread() {
-    
-    initGlobals();
-    
-    while(threadRunning) {
-        
+void RenderThread::updateRenderThread() {
         jobQueueMutex->lock();
         
         while(jobQueue.size() > 0) {
@@ -98,6 +92,15 @@ void RenderThread::runThread() {
             }
             delete nextFrame;
         }
+
+}
+
+void RenderThread::runThread() {
+    
+    initGlobals();
+    
+    while(threadRunning) {
+        updateRenderThread();
     }
 }
 
@@ -309,7 +312,6 @@ void RenderThread::clearFrameQueue() {
 }
 
 void RenderThread::processJob(const RendererThreadJob &job) {
-    
     lockRenderMutex();
     switch(job.jobType) {
         case JOB_REQUEST_CONTEXT_CHANGE:
@@ -457,15 +459,19 @@ void RenderThread::setGraphicsInterface(Core *core, GraphicsInterface *graphicsI
     this->core = core;
 }
 
-Renderer::Renderer() :
+Renderer::Renderer(RenderThread *customThread) :
     backingResolutionScaleX(1.0),
     backingResolutionScaleY(1.0),
     cpuBufferIndex(0),
     gpuBufferIndex(1),
     currentFrame(NULL) {
-        
-    renderThread = new RenderThread();
-    Services()->getCore()->createThread(renderThread);
+       
+	if(!customThread) {
+		renderThread = new RenderThread();
+		Services()->getCore()->createThread(renderThread);
+	} else {
+		renderThread = customThread;
+	}
 }
 
 Renderer::~Renderer() {

+ 16 - 9
src/core/PolyResourceManager.cpp

@@ -33,7 +33,9 @@
 #include "polycode/core/PolyMesh.h"
 #include "polycode/core/PolyScript.h"
 #include "polycode/core/PolyCore.h"
-#include "polycode/bindings/lua/PolycodeLua.h"
+#ifndef NO_LUA
+	#include "polycode/bindings/lua/PolycodeLua.h"
+#endif
 #include "polycode/bindings/javascript/PolycodeJS.h"
 #include "tinyxml.h"
 
@@ -371,6 +373,7 @@ Resource *ProgramResourceLoader::loadResource(const String &path, ResourcePool *
     return newProgram;
 }
 
+#ifndef NO_LUA
 static int customError(lua_State *L) {
     std::vector<DebugBackTraceEntry> backTrace;
     lua_Debug entry;
@@ -517,6 +520,7 @@ void ScriptResourceLoader::initLua() {
     lua_pushstring(luaState, "defaults");
     lua_pcall(luaState, 1, 0, errH);
 }
+#endif
 
 void loadJSFile(duk_context *context, String fileName) {
 
@@ -572,15 +576,18 @@ void ScriptResourceLoader::initJavascript() {
 }
 
 ScriptResourceLoader::ScriptResourceLoader() {
+#ifndef NO_LUA
     luaState = NULL;
-    duktapeContext = NULL;
-    
     extensions.push_back("lua");
+#endif
+    duktapeContext = NULL;
     extensions.push_back("js");
 }
 
 ScriptResourceLoader::~ScriptResourceLoader() {
+#ifndef NO_LUA
     lua_close(luaState);
+#endif
     duk_destroy_heap(duktapeContext);
 }
 
@@ -588,10 +595,12 @@ Resource *ScriptResourceLoader::loadResource(const String &path, ResourcePool *t
     OSFileEntry entry(path, OSFileEntry::TYPE_FILE);
     Script *newScript = NULL;
     if(entry.extension == "lua") {
+#ifndef NO_LUA
         if(!luaState) {
             initLua();
         }
         newScript = new LuaScript(luaState, path);
+#endif
     } else if(entry.extension == "js") {
         if(!duktapeContext) {
             initJavascript();
@@ -602,10 +611,8 @@ Resource *ScriptResourceLoader::loadResource(const String &path, ResourcePool *t
 }
 
 FontResourceLoader::FontResourceLoader() {
-    
     FT_Init_FreeType(&FTLibrary);
     FT_Library_SetLcdFilter(FTLibrary, FT_LCD_FILTER_LIGHT);
-    
     extensions.push_back("ttf");
     extensions.push_back("otf");
 }
@@ -625,10 +632,10 @@ Resource *MeshResourceLoader::loadResource(const String &path, ResourcePool *tar
 
 
 Resource *FontResourceLoader::loadResource(const String &path, ResourcePool *targetPool) {
-    OSFileEntry entry = OSFileEntry(path, OSFileEntry::TYPE_FILE);
-    Font *font = new Font(path, FTLibrary);
-    font->setResourceName(entry.nameWithoutExtension);
-    return font;
+	OSFileEntry entry = OSFileEntry(path, OSFileEntry::TYPE_FILE);
+	Font *font = new Font(path, FTLibrary);
+	font->setResourceName(entry.nameWithoutExtension);
+	return font;
 }
 
 void ResourceManager::handleEvent(Event *event) {

+ 2 - 2
src/core/PolySceneLabel.cpp

@@ -116,9 +116,9 @@ void SceneLabel::updateFromLabel() {
 
     Texture *texture;
 	if(SceneLabel::createMipmapsForLabels) {
-		texture = materialManager->createTextureFromImage(label, materialManager->clampDefault, materialManager->mipmapsDefault);
+		texture = materialManager->createTextureFromImage(label, true, false);
 	} else {
-		texture = materialManager->createTextureFromImage(label, materialManager->clampDefault, false);		
+		texture = materialManager->createTextureFromImage(label, true, false);
 	}
 
 	setPrimitiveOptions(type, label->getWidth()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX(),label->getHeight()*labelScale/CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());

+ 2 - 0
src/core/PolyScript.cpp

@@ -107,6 +107,7 @@ void JSScript::callUpdate(ScriptInstance *instance, Entity *entity, Number elaps
 
 }
 
+#ifndef NO_LUA
 LuaScript::LuaScript(lua_State *state, const String &path) : Script(path) {
 
     lua_getglobal(state, "__customError");
@@ -159,3 +160,4 @@ void LuaScript::callUpdate(ScriptInstance *instance, Entity *entity, Number elap
         lua_pcall(state, 2, 0, errH);
     }
 }
+#endif

+ 1 - 0
src/core/PolyShader.cpp

@@ -25,6 +25,7 @@
 #include "polycode/core/PolyCoreServices.h"
 #include "polycode/core/PolyRenderer.h"
 #include "polycode/core/PolyCore.h"
+#include <stdlib.h>
 
 using namespace Polycode;
 

+ 1 - 0
src/core/PolySound.cpp

@@ -33,6 +33,7 @@
 #include "polycode/core/PolySoundManager.h"
 #include "polycode/core/PolyCore.h"
 #include "polycode/core/PolyCoreServices.h"
+#include <stdlib.h>
 #include <string>
 #include <vector>
 #include <stdint.h>

+ 0 - 0
src/duktape/duktape.c → src/duktape/duktape.cpp


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff