From ec6920656d8225538baaac677b62aa564fc1055e Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 7 Dec 2018 11:46:49 +0800 Subject: *particle system demo --- bin/SDL2.dll | Bin 1279488 -> 1242112 bytes bin/game/main.lua | 3 +-- bin/jin.exe | Bin 554496 -> 1703424 bytes bin/lua51.dll | Bin 364544 -> 364544 bytes build/vc++/jin/jin.vcxproj | 4 ++-- src/lua/common/je_lua_shared.cpp | 1 + src/lua/common/je_lua_shared.hpp | 8 +++++--- src/lua/modules/graphics/je_lua_graphics.cpp | 4 ++++ 8 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/SDL2.dll b/bin/SDL2.dll index 0b08ce2..47c1b1e 100644 Binary files a/bin/SDL2.dll and b/bin/SDL2.dll differ diff --git a/bin/game/main.lua b/bin/game/main.lua index 6851c45..8de71f1 100644 --- a/bin/game/main.lua +++ b/bin/game/main.lua @@ -62,12 +62,11 @@ local function createAnimation(path, count, r, c, w, h, loop, speed) return jin.graphics.newAnimation(sprs, loop, speed) end local Pi = 3.1415 -local tex = nil function jin.core.onLoad() -- bitmap = jin.graphics.newBitmap(200, 200, function(w, h, x, y) -- return {255*math.sin(x/w),255 - 255,255*math.cos(y/w),255} -- end) - tex = jin.graphics.newTexture("particle.png") + local tex = jin.graphics.newTexture("particle.png") particle_sprite = jin.graphics.newSprite(tex, jin.graphics.SpriteOrigin.MIDDLECENTER) ps = jin.graphics.newParticleSystem() diff --git a/bin/jin.exe b/bin/jin.exe index c74c8b7..fffa828 100644 Binary files a/bin/jin.exe and b/bin/jin.exe differ diff --git a/bin/lua51.dll b/bin/lua51.dll index 88d71ef..4857c1e 100644 Binary files a/bin/lua51.dll and b/bin/lua51.dll differ diff --git a/build/vc++/jin/jin.vcxproj b/build/vc++/jin/jin.vcxproj index 20cad7c..1a0ca08 100644 --- a/build/vc++/jin/jin.vcxproj +++ b/build/vc++/jin/jin.vcxproj @@ -91,7 +91,7 @@ true true - Windows + Console opengl32.lib;%(AdditionalDependencies) @@ -107,7 +107,7 @@ true - Windows + Console opengl32.lib;%(AdditionalDependencies) diff --git a/src/lua/common/je_lua_shared.cpp b/src/lua/common/je_lua_shared.cpp index 91a5105..eecf632 100644 --- a/src/lua/common/je_lua_shared.cpp +++ b/src/lua/common/je_lua_shared.cpp @@ -1,5 +1,6 @@ #include "je_lua.h" #include "je_lua_shared.hpp" +#include "libjin/jin.h" namespace JinEngine { diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp index bfe0629..f89783d 100644 --- a/src/lua/common/je_lua_shared.hpp +++ b/src/lua/common/je_lua_shared.hpp @@ -13,7 +13,7 @@ namespace JinEngine class LuaObject; /// - /// Thread safe. + /// 线程安全的共享模板。 /// class SharedBase { @@ -29,8 +29,10 @@ namespace JinEngine SharedBase(const SharedBase&); - // 在同一个线程的lua_State中,LuaObject和EngineObject应该是一一对应,由LuaObject(lua runtime)管理 - // 引用计数和回收。Engine-side引用计数是为了维护不同线程的lua_State共享同一个EngineObject。 + // 在同一个线程的lua_State中,LuaObject和EngineObject应该是一一对应,由LuaObject(lua runtime)管理引用计数和 + // 回收。Engine-side引用计数是为了维护不同线程的lua_State共享同一个EngineObject。每次由LuaObject绑定一个 + // Shared时就增加一个引用计数,理论上在同一个线程中,一个EngineObject只能由一个LuaObject绑定,发生在new + // instance过程中,那么mCount就表明EngineObject的共享线程数。 void retain(); void release(); diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 2fc8ecf..ea9a265 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -737,6 +737,7 @@ namespace JinEngine int o = luax_checkinteger(L, 3); Origin origin = static_cast(o); LuaObject* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); + p->setDependency((int)SpriteDependency::DEP_GRAPHIC, objGraphic->getSharedBase()); } else if (n == 4) { @@ -748,18 +749,21 @@ namespace JinEngine int ox = luax_checkinteger(L, 3); int oy = luax_checkinteger(L, 4); LuaObject* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite)); + p->setDependency((int)SpriteDependency::DEP_GRAPHIC, objGraphic->getSharedBase()); } else if (n == 2) { int o = luax_checkinteger(L, 2); Origin origin = static_cast(o); LuaObject* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared(new Sprite(graphic, origin), Jin_Lua_Sprite)); + p->setDependency((int)SpriteDependency::DEP_GRAPHIC, objGraphic->getSharedBase()); } else if (n == 3) { int ox = luax_checkinteger(L, 2); int oy = luax_checkinteger(L, 3); LuaObject* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared(new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); + p->setDependency((int)SpriteDependency::DEP_GRAPHIC, objGraphic->getSharedBase()); } else { -- cgit v1.1-26-g67d0