aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-12-07 11:22:59 +0800
committerchai <chaifix@163.com>2018-12-07 11:22:59 +0800
commit150944ee9e41df2ae5ee25c7845c3f5b2bd74af0 (patch)
treeea399aeb2172132855ffa2a8c9533b9870a0e9a9
parentfe16b453e093d721e60be0a12219d40635b96a3a (diff)
*私有化shared object template retain和release
-rw-r--r--bin/game/main.lua28
-rw-r--r--bin/game/particle.pngbin0 -> 1821 bytes
-rw-r--r--bin/jin.exebin540672 -> 554496 bytes
-rw-r--r--examples/particle_system/main.cpp4
-rw-r--r--src/lua/common/je_lua_shared.hpp14
-rw-r--r--src/lua/embed/scripts/boot.lua.h2
-rw-r--r--src/lua/embed/scripts/graphics.lua.h6
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp12
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.cpp6
10 files changed, 55 insertions, 21 deletions
diff --git a/bin/game/main.lua b/bin/game/main.lua
index 8ff5e68..6851c45 100644
--- a/bin/game/main.lua
+++ b/bin/game/main.lua
@@ -53,17 +53,39 @@ local bitmap = nil
local sprs = {}
local animator = nil
local spr = nil
+local particle_sprite = nil
+local ps = nil
local function createAnimation(path, count, r, c, w, h, loop, speed)
local tex = jin.graphics.newTexture(path)
local ssheet = jin.graphics.newSpriteSheet(tex)
local sprs = ssheet:newSprites(count, r, c, w, h, 96, 168)
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")
+ particle_sprite = jin.graphics.newSprite(tex, jin.graphics.SpriteOrigin.MIDDLECENTER)
+ ps = jin.graphics.newParticleSystem()
+
+ ps:setEmitRate(0.02);
+ ps:setEmitForce(80, 120);
+ ps:setEmitPosition({50, 50});
+ ps:setEmitDirection(-Pi / 10 - Pi / 2, Pi / 10 - Pi / 2);
+ ps:setParticleLinearAccelaration({0, 10});
+ ps:setParticleSpritesMode(jin.graphics.SpriteMode.SINGLE);
+ ps:setParticleColor({255, 30, 0, 255});
+ ps:addParticleTransparencyPoint(1, 0);
+ ps:addParticleTransparencyPoint(0, 0.5);
+ ps:enableParticleBlendAdditive(true);
+ ps:setParticleLife(0.5, 2);
+ ps:addParticleScalePoint(3, 0);
+ ps:addParticleScalePoint(0, 1);
+ ps:addParticleSprite(particle_sprite)
+
shader_program = jin.graphics.newShader(shader)
shader_program2 = jin.graphics.newShader(shader2)
local animation = createAnimation("anim2.png", 27, 3, 10, 200, 200, true, 50)
@@ -97,11 +119,12 @@ function jin.core.onEvent(e)
end
end
-function jin.core.onUpdate()
+function jin.core.onUpdate(dt)
tb.x = t
t = t + jin.time.getDelta()
animator:update(jin.time.getDelta())
timer:update(jin.time.getDelta())
+ ps:update(dt)
end
function jin.core.onDraw()
@@ -113,6 +136,7 @@ function jin.core.onDraw()
--jin.graphics.draw(sprs[2], 150, 150, 1, 1, 0)
local x, y = jin.mouse.getPosition()
animator:render(x, y, 1, 1, 0)
+ ps:render()
--jin.graphics.print(#sprs, 10, 10)
jin.graphics.draw(spr, 100, 200, 1, 1, 0)
--jin.graphics.useShader(shader_program2)
diff --git a/bin/game/particle.png b/bin/game/particle.png
new file mode 100644
index 0000000..632fcc1
--- /dev/null
+++ b/bin/game/particle.png
Binary files differ
diff --git a/bin/jin.exe b/bin/jin.exe
index 4e260c9..c74c8b7 100644
--- a/bin/jin.exe
+++ b/bin/jin.exe
Binary files differ
diff --git a/examples/particle_system/main.cpp b/examples/particle_system/main.cpp
index ba2f496..93efc82 100644
--- a/examples/particle_system/main.cpp
+++ b/examples/particle_system/main.cpp
@@ -160,7 +160,7 @@ int main(int argc, char* argv[])
setting.eventHandler = onEvent;
setting.updater = onUpdate;
setting.drawer = onDraw;
- app->init(&setting);
+ app->start(&setting);
AssetDatabase::get()->mount(".");
@@ -174,7 +174,7 @@ int main(int argc, char* argv[])
wndSetting.fullscreen = false;
wndSetting.resizable = false;
wndSetting.icon = ".";
- wnd->init(&wndSetting);
+ wnd->start(&wndSetting);
wnd->show();
app->run();
diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp
index ad65be0..bfe0629 100644
--- a/src/lua/common/je_lua_shared.hpp
+++ b/src/lua/common/je_lua_shared.hpp
@@ -10,25 +10,31 @@ namespace JinEngine
namespace Lua
{
+ class LuaObject;
+
///
/// Thread safe.
///
class SharedBase
{
public:
- void retain();
-
- void release();
-
bool isType(const char* t);
const char* getType();
protected:
+ friend class LuaObject;
+
SharedBase(void* obj, const char* t);
SharedBase(const SharedBase&);
+ // ͬһ̵߳lua_StateУLuaObjectEngineObjectӦһһӦLuaObject(lua runtime)
+ // üͻաEngine-sideüΪά̵ͬ߳lua_StateͬһEngineObject
+ void retain();
+
+ void release();
+
virtual ~SharedBase();
void* mObject;
diff --git a/src/lua/embed/scripts/boot.lua.h b/src/lua/embed/scripts/boot.lua.h
index af81c16..a42f7d4 100644
--- a/src/lua/embed/scripts/boot.lua.h
+++ b/src/lua/embed/scripts/boot.lua.h
@@ -49,7 +49,7 @@ function jin.core.run()
end
step()
dt = jin.time.getDelta()
- call(jin.core.onUpdate)
+ call(jin.core.onUpdate, dt)
jin.graphics.clear()
call(jin.core.onDraw)
jin.graphics.present()
diff --git a/src/lua/embed/scripts/graphics.lua.h b/src/lua/embed/scripts/graphics.lua.h
index e1079b9..1dddbf5 100644
--- a/src/lua/embed/scripts/graphics.lua.h
+++ b/src/lua/embed/scripts/graphics.lua.h
@@ -21,6 +21,12 @@ jg.SpriteOrigin = {
BOTTOMRIGHT = 8
}
+jg.SpriteMode = {
+ SINGLE = 1,
+ RANDOM = 2,
+ ANIMATED = 3
+}
+
local default_shader = nil
local default_shader_source = [[
#VERTEX_SHADER
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
index 1733529..8d8b76e 100644
--- a/src/lua/modules/graphics/je_lua_bitmap.cpp
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -23,8 +23,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_gc(lua_State* L)
{
- SharedBitmap shared = checkBitmap(L);
- shared.release();
+ LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ luaObj->release();
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 981e30f..2fc8ecf 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -19,6 +19,7 @@
#include "je_lua_sprite.h"
#include "je_lua_animation.h"
#include "je_lua_animator.h"
+#include "je_lua_particle_system.h"
using namespace std;
using namespace JinEngine;
@@ -27,6 +28,7 @@ using namespace JinEngine::Graphics;
using namespace JinEngine::Graphics::Fonts;
using namespace JinEngine::Graphics::Shaders;
using namespace JinEngine::Graphics::Animations;
+using namespace JinEngine::Graphics::Particles;
using namespace JinEngine::Filesystem;
namespace JinEngine
@@ -892,13 +894,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_newParticleSystem(lua_State* L)
{
- // Definition table.
- if (!luax_istable(L, 1))
- {
- luax_typerror(L, 1, "particle system definition table");
- return 1;
- }
-
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_ParticleSystem, new Shared<ParticleSystem>(new ParticleSystem(), Jin_Lua_ParticleSystem));
+ return 1;
}
/* setFont(font) */
@@ -981,6 +978,7 @@ namespace JinEngine
luaopen_SpriteSheet(L);
luaopen_Animation(L);
luaopen_Animator(L);
+ luaopen_ParticleSystem(L);
luaL_Reg methods[] = {
/* window */
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp
index a6c4eed..8c2e4c7 100644
--- a/src/lua/modules/graphics/je_lua_particle_system.cpp
+++ b/src/lua/modules/graphics/je_lua_particle_system.cpp
@@ -63,7 +63,7 @@ namespace JinEngine
SharedParticleSystem ps = checkPS(L);
float sx = luax_checknumber(L, 2);
float sy = luax_checknumber(L, 3);
- ps->setScale(sx, sy);
+ //ps->setScale(sx, sy);
return 0;
}
@@ -71,14 +71,14 @@ namespace JinEngine
{
SharedParticleSystem ps = checkPS(L);
bool b = luax_checkbool(L, 2);
- ps->pause(b);
+ //ps->pause(b);
return 0;
}
LUA_IMPLEMENT int l_clear(lua_State* L)
{
SharedParticleSystem ps = checkPS(L);
- ps->clear();
+ //ps->clear();
return 0;
}