From 0bfff69053e27fbb6e541a6b8afa6c8e61a62403 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Nov 2018 00:51:15 +0800 Subject: =?UTF-8?q?*shared=20=E5=A2=9E=E5=8A=A0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/Jin.exe | Bin 2206208 -> 2458624 bytes bin/SDL2.dll | Bin 1279488 -> 1279488 bytes bin/game/0.png | Bin 0 -> 563072 bytes bin/game/1.png | Bin 0 -> 73228 bytes bin/game/SDL.jpg | Bin 0 -> 6481 bytes bin/game/config.lua | 5 ++ bin/game/forest.ogg | Bin 0 -> 789109 bytes bin/game/icon.ico | Bin 0 -> 85182 bytes bin/game/main.lua | 93 +++++++++++++++++++++++ bin/game/splash.png | Bin 0 -> 392 bytes build/vc++/jin.vcxproj | 2 +- build/vc++/jin.vcxproj.filters | 2 +- build/vc++/libjin/libjin.vcxproj | 2 - build/vc++/libjin/libjin.vcxproj.filters | 6 -- src/3rdparty/buildvm/buildvm.exe | Bin 123392 -> 123392 bytes src/3rdparty/minilua/minilua.exe | Bin 219136 -> 219136 bytes src/libjin/Graphics/je_graphic_manager.cpp | 0 src/libjin/Graphics/je_graphic_manager.h | 0 src/lua/common/je_lua_proxy.h | 6 -- src/lua/common/je_lua_shared.hpp | 79 +++++++++++++++---- src/lua/modules/graphics/je_lua_canvas.cpp | 2 +- src/lua/modules/graphics/je_lua_graphics.cpp | 4 +- src/lua/modules/graphics/je_lua_page.cpp | 6 -- src/lua/modules/graphics/je_lua_page.h | 18 +++++ src/lua/modules/graphics/je_lua_sprite.cpp | 60 ++++----------- src/lua/modules/graphics/je_lua_sprite.h | 42 ---------- src/lua/modules/graphics/je_lua_texture_font.cpp | 19 ++--- src/lua/modules/graphics/je_lua_ttf.cpp | 50 +++--------- src/lua/modules/graphics/je_lua_ttf.h | 39 ---------- src/lua/modules/graphics/je_lua_ttf_data.cpp | 23 +++--- 30 files changed, 229 insertions(+), 229 deletions(-) create mode 100644 bin/game/0.png create mode 100644 bin/game/1.png create mode 100644 bin/game/SDL.jpg create mode 100644 bin/game/config.lua create mode 100644 bin/game/forest.ogg create mode 100644 bin/game/icon.ico create mode 100644 bin/game/main.lua create mode 100644 bin/game/splash.png delete mode 100644 src/libjin/Graphics/je_graphic_manager.cpp delete mode 100644 src/libjin/Graphics/je_graphic_manager.h create mode 100644 src/lua/modules/graphics/je_lua_page.h delete mode 100644 src/lua/modules/graphics/je_lua_sprite.h delete mode 100644 src/lua/modules/graphics/je_lua_ttf.h diff --git a/bin/Jin.exe b/bin/Jin.exe index e648fd4..6f56539 100644 Binary files a/bin/Jin.exe and b/bin/Jin.exe differ diff --git a/bin/SDL2.dll b/bin/SDL2.dll index 81f8ae4..97527fa 100644 Binary files a/bin/SDL2.dll and b/bin/SDL2.dll differ diff --git a/bin/game/0.png b/bin/game/0.png new file mode 100644 index 0000000..fa62576 Binary files /dev/null and b/bin/game/0.png differ diff --git a/bin/game/1.png b/bin/game/1.png new file mode 100644 index 0000000..7e3fe49 Binary files /dev/null and b/bin/game/1.png differ diff --git a/bin/game/SDL.jpg b/bin/game/SDL.jpg new file mode 100644 index 0000000..dcd530a Binary files /dev/null and b/bin/game/SDL.jpg differ diff --git a/bin/game/config.lua b/bin/game/config.lua new file mode 100644 index 0000000..380dd1b --- /dev/null +++ b/bin/game/config.lua @@ -0,0 +1,5 @@ +return +{ + title = "window form", + icon = "splash.png", +} \ No newline at end of file diff --git a/bin/game/forest.ogg b/bin/game/forest.ogg new file mode 100644 index 0000000..d3059e1 Binary files /dev/null and b/bin/game/forest.ogg differ diff --git a/bin/game/icon.ico b/bin/game/icon.ico new file mode 100644 index 0000000..3043332 Binary files /dev/null and b/bin/game/icon.ico differ diff --git a/bin/game/main.lua b/bin/game/main.lua new file mode 100644 index 0000000..2c9036f --- /dev/null +++ b/bin/game/main.lua @@ -0,0 +1,93 @@ +io.stdout:setvbuf("no") +local shader = [[ +#VERTEX_SHADER +Vertex vert(Vertex v) +{ + return v; +} +#END_VERTEX_SHADER +#FRAGMENT_SHADER +Color frag(Color col, Texture tex, Vertex v) +{ + return col; +} +#END_FRAGMENT_SHADER +]] + +local shader2 = [[ +#VERTEX_SHADER +Vertex vert(Vertex v) +{ + return v; +} +#END_VERTEX_SHADER +#FRAGMENT_SHADER +Color frag(Color col, Texture tex, Vertex v) +{ + Color c = texel(tex, v.uv); + return c; +} +#END_FRAGMENT_SHADER +]] +music = nil +local tex = nil +local shader_program = nil +local shader_program2 = nil +local timer = nil +local tb = {x = 1, y = 2} +local t = 0 +local spr = nil +function jin.core.onLoad() + jin.graphics.setClearColor(100, 100, 100, 255) + shader_program = jin.graphics.newShader(shader) + shader_program2 = jin.graphics.newShader(shader2) + tex = jin.graphics.newTexture("1.png") + spr = jin.graphics.newSprite() + spr:setShader(shader_program2) + spr:setGraphic(tex) + tex = nil + spr:setScale(1, 1) + spr:setOrigin(jin.graphics.SpriteOrigin.MIDDLERIGHT) + music = jin.audio.newSource("forest.ogg") + music:setVolume(0.5) + music:setLoop(true) + music:play() + jin.graphics.clear() + jin.graphics.showWindow() + timer = jin.time.newTimer() + local h = timer:every(0.5, function(sp) + local x, y = spr:getPosition() + spr:setPosition(x + 1, y) + end, spr) + timer:after(3, function(p) + --timer:cancel(h) + end, h) +end +local stop = false + +function jin.core.onEvent(e) + if e.type == "Quit" then + jin.core.stop() + end +end + +function jin.core.onUpdate() + tb.x = t + t = t + jin.time.getDelta() +end + +function jin.core.onDraw() + timer:update(jin.time.getDelta()) + jin.graphics.useShader(shader_program) + jin.graphics.setColor(255, 0, 255, 255) + jin.graphics.rect(jin.graphics.RenderMode.FILL, 30, 50, 100, 200) + jin.graphics.setColor(255, 255, 255, 255) + jin.graphics.unuseShader() + spr:render() + --jin.graphics.useShader(shader_program2) + --jin.graphics.draw(tex, 0, 0,0.2, 0.2) + --jin.graphics.unuseShader() + if stop then + jin.graphics.print("Quit", 100, 300) + end +end \ No newline at end of file diff --git a/bin/game/splash.png b/bin/game/splash.png new file mode 100644 index 0000000..b0c4256 Binary files /dev/null and b/bin/game/splash.png differ diff --git a/build/vc++/jin.vcxproj b/build/vc++/jin.vcxproj index b28f79b..6b9449f 100644 --- a/build/vc++/jin.vcxproj +++ b/build/vc++/jin.vcxproj @@ -198,7 +198,7 @@ - + diff --git a/build/vc++/jin.vcxproj.filters b/build/vc++/jin.vcxproj.filters index 960d7a3..7b8a9a9 100644 --- a/build/vc++/jin.vcxproj.filters +++ b/build/vc++/jin.vcxproj.filters @@ -254,7 +254,7 @@ source\common - + source\modules\graphics diff --git a/build/vc++/libjin/libjin.vcxproj b/build/vc++/libjin/libjin.vcxproj index 552272d..a1bfa66 100644 --- a/build/vc++/libjin/libjin.vcxproj +++ b/build/vc++/libjin/libjin.vcxproj @@ -171,7 +171,6 @@ - @@ -245,7 +244,6 @@ - diff --git a/build/vc++/libjin/libjin.vcxproj.filters b/build/vc++/libjin/libjin.vcxproj.filters index c70aa25..f68943f 100644 --- a/build/vc++/libjin/libjin.vcxproj.filters +++ b/build/vc++/libjin/libjin.vcxproj.filters @@ -246,9 +246,6 @@ source\graphics - - source\graphics - source\graphics\shaders\built-in @@ -436,9 +433,6 @@ source\graphics - - source\graphics - source\graphics\shaders diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe index 00cd94d..f60b37b 100644 Binary files a/src/3rdparty/buildvm/buildvm.exe and b/src/3rdparty/buildvm/buildvm.exe differ diff --git a/src/3rdparty/minilua/minilua.exe b/src/3rdparty/minilua/minilua.exe index 003f2a1..1070809 100644 Binary files a/src/3rdparty/minilua/minilua.exe and b/src/3rdparty/minilua/minilua.exe differ diff --git a/src/libjin/Graphics/je_graphic_manager.cpp b/src/libjin/Graphics/je_graphic_manager.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/libjin/Graphics/je_graphic_manager.h b/src/libjin/Graphics/je_graphic_manager.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h index 96b2093..9f55490 100644 --- a/src/lua/common/je_lua_proxy.h +++ b/src/lua/common/je_lua_proxy.h @@ -35,12 +35,6 @@ namespace JinEngine shared->retain(); } - void setUserdata(void* data) - { - if (shared != nullptr) - shared->setUserdata(data); - } - template Shared& getShared() { diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp index 876fe28..d6ea357 100644 --- a/src/lua/common/je_lua_shared.hpp +++ b/src/lua/common/je_lua_shared.hpp @@ -1,6 +1,9 @@ #ifndef __JIN_COMMON_SHARED_H #define __JIN_COMMON_SHARED_H +#include +#include + namespace JinEngine { namespace Lua @@ -11,32 +14,77 @@ namespace JinEngine public: void retain() { - ++count; + ++mCount; } void release() { - if (--count <= 0) + if (--mCount <= 0) delete this; } - // Object type string. + // Object type. const char* const type; - void setUserdata(void* data) + void setDependency(int key, SharedBase* shared) + { + removeDependency(key); + shared->retain(); + mDependencies.insert(std::pair(key, shared)); + } + + void removeDependency(int key) { - userdata = data; + if (!isDependOn(key)) + return; + DepMap::iterator it = mDependencies.find(key); + it->second->release(); + mDependencies.erase(it); } - void* getUserdata() + void removeDependency(SharedBase* dep) { - return userdata; + for (DepMap::iterator it = mDependencies.begin(); it != mDependencies.end();) + { + if (it->second == dep) + { + it->second->release(); + mDependencies.erase(it); + } + else + ++it; + } + } + + bool isDependOn(int key) + { + return mDependencies.find(key) != mDependencies.end(); + } + + bool isDependOn(SharedBase* shared) + { + for (std::pair dep : mDependencies) + { + if (dep.second == shared) + return true; + } + return false; + } + + void clearDependencies() + { + for (std::pair dep : mDependencies) + dep.second->release(); + mDependencies.clear(); } protected: + + using DepMap = std::map; + SharedBase(void* obj, const char* t) - : count(1) - , object(obj) + : mCount(1) + , mObject(obj) , type(t) { } @@ -45,11 +93,12 @@ namespace JinEngine virtual ~SharedBase() { + clearDependencies(); } - void* object; - int count; - void* userdata; + void* mObject; + int mCount; + DepMap mDependencies; }; template @@ -63,12 +112,12 @@ namespace JinEngine T* operator->() { - return static_cast(object); + return static_cast(mObject); } T* getObject() { - return static_cast(object); + return static_cast(mObject); } private: @@ -78,7 +127,7 @@ namespace JinEngine // Make shared only be able created with new. ~Shared() { - T* obj = static_cast(object); + T* obj = static_cast(mObject); delete obj; } diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp index 8d8630f..70edfd1 100644 --- a/src/lua/modules/graphics/je_lua_canvas.cpp +++ b/src/lua/modules/graphics/je_lua_canvas.cpp @@ -62,4 +62,4 @@ namespace JinEngine } } // namespace Lua -} // namespace JinEngine \ No newline at end of file +} // namespace JinEngine \ No newline at end of file diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 78674dd..5255de7 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -6,8 +6,6 @@ #include "lua/modules/types.h" #include "lua/common/je_lua_common.h" -#include "je_lua_sprite.h" - using namespace std; using namespace JinEngine; using namespace JinEngine::Graphics; @@ -664,7 +662,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newSprite(lua_State* L) { Proxy* p = luax_newinstance(L, JIN_GRAPHICS_SPRITE); - p->bind(new Shared(new Lua::Sprite(), JIN_GRAPHICS_SPRITE)); + p->bind(new Shared(new Sprite(), JIN_GRAPHICS_SPRITE)); return 1; } diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp index 7e9b6d1..3ebd557 100644 --- a/src/lua/modules/graphics/je_lua_page.cpp +++ b/src/lua/modules/graphics/je_lua_page.cpp @@ -25,12 +25,6 @@ namespace JinEngine LUA_IMPLEMENT int l_gc(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE); - { - /* release font */ - Shared* page = &proxy->getShared(); - SharedBase* font = (SharedBase*)page->getUserdata(); - font->release(); - } proxy->release(); return 0; } diff --git a/src/lua/modules/graphics/je_lua_page.h b/src/lua/modules/graphics/je_lua_page.h new file mode 100644 index 0000000..d2d9f22 --- /dev/null +++ b/src/lua/modules/graphics/je_lua_page.h @@ -0,0 +1,18 @@ +#ifndef __JE_LUA_PAGE_H__ +#define __JE_LUA_PAGE_H__ + +namespace JinEngine +{ + namespace Lua + { + + enum PageDependency + { + DEP_TTF = 1, + DEP_TEXTURE_FONT = 2, + }; + + } +} + +#endif \ No newline at end of file diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp index f02d1cc..b81b66b 100644 --- a/src/lua/modules/graphics/je_lua_sprite.cpp +++ b/src/lua/modules/graphics/je_lua_sprite.cpp @@ -2,7 +2,6 @@ #include "lua/modules/types.h" #include "lua/common/je_lua_common.h" #include "libjin/jin.h" -#include "je_lua_sprite.h" using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Shaders; @@ -11,52 +10,20 @@ namespace JinEngine { namespace Lua { - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Sprite class. - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - Lua::Sprite::~Sprite() + // Sprite dependency slots. + enum SpriteDependency { - if (mGraphicShared != nullptr) - { - mGraphicShared->release(); - mGraphicShared = nullptr; - } - if (mShaderShared != nullptr) - { - mShaderShared->release(); - mShaderShared = nullptr; - } - } - - void Lua::Sprite::setShader(Shared* shader) - { - if (mShaderShared != nullptr) - mShaderShared->release(); - mShaderShared = shader; - mShaderShared->retain(); - Parent::setShader(mShaderShared->getObject()); - } - - void Lua::Sprite::setGraphic(Shared* graphic) - { - if (mGraphicShared != nullptr) - mGraphicShared = graphic; - mGraphicShared = graphic; - mGraphicShared->retain(); - Parent::setGraphic(mGraphicShared->getObject()); - } + DEP_GRAPHIC = 1, + DEP_SHADER = 2, + }; - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Register Sprite class. - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - - typedef Shared& SharedSprite; + typedef Shared& SharedSprite; LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SPRITE); - return proxy->getShared(); + return proxy->getShared(); } LUA_IMPLEMENT int l_gc(lua_State* L) @@ -82,7 +49,7 @@ namespace JinEngine case 2: { int origin = luax_checkinteger(L, 2); - sprite->setOrigin(static_cast(origin)); + sprite->setOrigin(static_cast(origin)); } break; case 3: @@ -129,7 +96,9 @@ namespace JinEngine { SharedSprite sprite = checkSprite(L); Proxy* proxy = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_SHADER); - sprite->setShader(&proxy->getShared()); + Shader* shader = proxy->getObject(); + sprite->setShader(shader); + sprite.setDependency(DEP_SHADER, &proxy->getShared()); return 0; } @@ -142,8 +111,11 @@ namespace JinEngine p = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXTURE); else if (luax_istype(L, 2, JIN_GRAPHICS_CANVAS)) p = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_CANVAS); - if(p != nullptr) - sprite->setGraphic(&p->getShared()); + if (p != nullptr) + { + sprite->setGraphic(p->getObject()); + sprite.setDependency(DEP_GRAPHIC, &p->getShared()); + } return 0; } diff --git a/src/lua/modules/graphics/je_lua_sprite.h b/src/lua/modules/graphics/je_lua_sprite.h deleted file mode 100644 index ded237e..0000000 --- a/src/lua/modules/graphics/je_lua_sprite.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __JE_LUA_SPRITE_H__ -#define __JE_LUA_SPRITE_H__ - -#include "../../common/je_lua_shared.hpp" - -#include "libjin/jin.h" - -namespace JinEngine -{ - namespace Lua - { - - class Sprite - : public Graphics::Sprite - { - public: - ~Sprite(); - - void setShader(Shared* shader); - - void setGraphic(Shared* graphic); - - private: - - using Parent = Graphics::Sprite; - - /// - /// - /// - Shared* mGraphicShared; - - /// - /// - /// - Shared* mShaderShared; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp index 1cdbfff..dc48ce4 100644 --- a/src/lua/modules/graphics/je_lua_texture_font.cpp +++ b/src/lua/modules/graphics/je_lua_texture_font.cpp @@ -2,6 +2,7 @@ #include "lua/modules/types.h" #include "lua/common/je_lua_common.h" #include "libjin/jin.h" +#include "je_lua_page.h" using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Fonts; @@ -21,8 +22,9 @@ namespace JinEngine /* typeset(Text | string, lineheight, spacing) */ LUA_IMPLEMENT int l_typeset(lua_State* L) { - Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT); - TextureFont* tf = p->getObject(); + Proxy* pxyTexFont = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT); + Shared& shrTexFont = pxyTexFont->getShared(); + TextureFont* tf = pxyTexFont->getObject(); int lineheight = luax_checkinteger(L, 3); int spacing = luax_optnumber(L, 4, 0); Page* page = nullptr; @@ -39,15 +41,10 @@ namespace JinEngine Text* text = p2->getObject(); page = tf->typeset(*text, lineheight, spacing); } - Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE); - Shared* refPage = new Shared(page, JIN_GRAPHICS_PAGE); - { - /* retain related ttf */ - Shared& refTF = p->getShared(); - refTF.retain(); - refPage->setUserdata(&refTF); - } - proxy->bind(refPage); + Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE); + Shared* shrPage = new Shared(page, JIN_GRAPHICS_PAGE); + shrPage->setDependency(DEP_TEXTURE_FONT, &shrTexFont); + pxyPage->bind(shrPage); return 1; } diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp index 31af310..6cade75 100644 --- a/src/lua/modules/graphics/je_lua_ttf.cpp +++ b/src/lua/modules/graphics/je_lua_ttf.cpp @@ -2,7 +2,7 @@ #include "lua/modules/types.h" #include "lua/common/je_lua_common.h" #include "libjin/jin.h" -#include "je_lua_ttf.h" +#include "je_lua_page.h" using namespace JinEngine::Graphics; using namespace JinEngine::Graphics::Fonts; @@ -12,37 +12,9 @@ namespace JinEngine namespace Lua { - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // TTFData - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - - TTF* TTFData::createTTF(unsigned fontSize) - { - TTF* ttf; - try - { - ttf = new TTF(this, fontSize); - } - catch (...) - { - return nullptr; - } - return ttf; - } - - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - // TTF - ////////////////////////////////////////////////////////////////////////////////////////////////////////// - LUA_IMPLEMENT int l_gc(lua_State* L) { Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); - { - /* release ttf data */ - Shared* ttf = &proxy->getShared(); - SharedBase* data = (SharedBase*)ttf->getUserdata(); - data->release(); - } proxy->release(); return 0; } @@ -50,8 +22,9 @@ namespace JinEngine /* typeset(Text | string, lineheight, spacing) */ LUA_IMPLEMENT int l_typeset(lua_State* L) { - Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); - TTF* ttf = p->getObject(); + Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF); + Shared& shrTTF = pxyTTF->getShared(); + TTF* ttf = pxyTTF->getObject(); int lineheight = luax_optnumber(L, 3, ttf->getFontSize()); int spacing = luax_optnumber(L, 4, 0); Page* page = nullptr; @@ -64,19 +37,14 @@ namespace JinEngine } else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT)) { - Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); - Text* text = p2->getObject(); + Proxy* pxyText = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT); + Text* text = pxyText->getObject(); page = ttf->typeset(*text, lineheight, spacing); } - Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE); + Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE); Shared* refPage = new Shared(page, JIN_GRAPHICS_PAGE); - { - /* retain related ttf */ - Shared& refTTF = p->getShared(); - refTTF.retain(); - refPage->setUserdata(&refTTF); - } - proxy->bind(refPage); + refPage->setDependency(DEP_TTF, &shrTTF); + pxyPage->bind(refPage); return 1; } diff --git a/src/lua/modules/graphics/je_lua_ttf.h b/src/lua/modules/graphics/je_lua_ttf.h deleted file mode 100644 index 7673d67..0000000 --- a/src/lua/modules/graphics/je_lua_ttf.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __JE_LUA_TTF_H__ -#define __JE_LUA_TTF_H__ - -#include "../../common/je_lua_shared.hpp" - -#include "libjin/jin.h" - -namespace JinEngine -{ - namespace Lua - { - - class TTFData - : public Graphics::Fonts::TTFData - { - public: - TTF * createTTF(unsigned fontSize); - - private: - using Parent = Graphics::Fonts::TTFData; - - }; - - class TTF - : public Graphics::Fonts::TTF - { - public: - - private: - using Parent = Graphics::Fonts::TTF; - - Shared* ttfDataShared; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp index cc91d60..4df2f6e 100644 --- a/src/lua/modules/graphics/je_lua_ttf_data.cpp +++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp @@ -11,21 +11,22 @@ namespace JinEngine namespace Lua { + enum TTFDependency + { + DEP_TTFDATA = 1, + }; + LUA_IMPLEMENT int l_newTTF(lua_State* L) { - Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA); + Proxy* pxyTTFData = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA); int fontsize = luax_checkinteger(L, 2); - Shared& refFontData = p->getShared(); - TTFData* fontData = refFontData.getObject(); - Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TTF); + Shared& shrFontData = pxyTTFData->getShared(); + TTFData* fontData = shrFontData.getObject(); + Proxy* pxyTTF = luax_newinstance(L, JIN_GRAPHICS_TTF); TTF* font = fontData->createTTF(fontsize); - Shared* refTTF = new Shared(font, JIN_GRAPHICS_TTF); - { - Shared& refTTFData = p->getShared(); - refTTFData.retain(); - refTTF->setUserdata(&refTTFData); - } - proxy->bind(refTTF); + Shared* shrTTF = new Shared(font, JIN_GRAPHICS_TTF); + shrTTF->setDependency(DEP_TTFDATA, &shrFontData); + pxyTTF->bind(shrTTF); return 1; } -- cgit v1.1-26-g67d0