aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-14 00:51:15 +0800
committerchai <chaifix@163.com>2018-11-14 00:51:15 +0800
commit0bfff69053e27fbb6e541a6b8afa6c8e61a62403 (patch)
treed3bd41f8defef8e08f80850d56eaf7a50de3c05a /src/lua/modules/graphics
parentd2058dce75ceb67f27c50e9f27d755a4d30c9003 (diff)
*shared 增加依赖
Diffstat (limited to 'src/lua/modules/graphics')
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp6
-rw-r--r--src/lua/modules/graphics/je_lua_page.h18
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp60
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.h42
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp19
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp50
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.h39
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp23
10 files changed, 65 insertions, 198 deletions
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<Lua::Sprite>(new Lua::Sprite(), JIN_GRAPHICS_SPRITE));
+ p->bind(new Shared<Sprite>(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>* page = &proxy->getShared<Page>();
- 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>* shader)
- {
- if (mShaderShared != nullptr)
- mShaderShared->release();
- mShaderShared = shader;
- mShaderShared->retain();
- Parent::setShader(mShaderShared->getObject());
- }
-
- void Lua::Sprite::setGraphic(Shared<Graphic>* 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<Lua::Sprite>& SharedSprite;
+ typedef Shared<Sprite>& SharedSprite;
LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SPRITE);
- return proxy->getShared<Lua::Sprite>();
+ return proxy->getShared<Sprite>();
}
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<Lua::Sprite::Origin>(origin));
+ sprite->setOrigin(static_cast<Sprite::Origin>(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* shader = proxy->getObject<Shader>();
+ sprite->setShader(shader);
+ sprite.setDependency(DEP_SHADER, &proxy->getShared<Shader>());
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<Graphic>());
+ if (p != nullptr)
+ {
+ sprite->setGraphic(p->getObject<Graphic>());
+ sprite.setDependency(DEP_GRAPHIC, &p->getShared<Graphic>());
+ }
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<Graphics::Shaders::Shader>* shader);
-
- void setGraphic(Shared<Graphics::Graphic>* graphic);
-
- private:
-
- using Parent = Graphics::Sprite;
-
- ///
- ///
- ///
- Shared<Graphics::Graphic>* mGraphicShared;
-
- ///
- ///
- ///
- Shared<Graphics::Shaders::Shader>* 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<TextureFont>();
+ Proxy* pxyTexFont = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
+ Shared<TextureFont>& shrTexFont = pxyTexFont->getShared<TextureFont>();
+ TextureFont* tf = pxyTexFont->getObject<TextureFont>();
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<Text>();
page = tf->typeset(*text, lineheight, spacing);
}
- Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE);
- Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Shared<TextureFont>& refTF = p->getShared<TextureFont>();
- refTF.retain();
- refPage->setUserdata(&refTF);
- }
- proxy->bind(refPage);
+ Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
+ Shared<Page>* shrPage = new Shared<Page>(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>* ttf = &proxy->getShared<TTF>();
- 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<TTF>();
+ Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
+ Shared<TTF>& shrTTF = pxyTTF->getShared<TTF>();
+ TTF* ttf = pxyTTF->getObject<TTF>();
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<Text>();
+ Proxy* pxyText = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
+ Text* text = pxyText->getObject<Text>();
page = ttf->typeset(*text, lineheight, spacing);
}
- Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_PAGE);
+ Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Shared<TTF>& refTTF = p->getShared<TTF>();
- 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<Graphics::Fonts::TTFData>* 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<TTFData>& refFontData = p->getShared<TTFData>();
- TTFData* fontData = refFontData.getObject();
- Proxy* proxy = luax_newinstance(L, JIN_GRAPHICS_TTF);
+ Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>();
+ TTFData* fontData = shrFontData.getObject();
+ Proxy* pxyTTF = luax_newinstance(L, JIN_GRAPHICS_TTF);
TTF* font = fontData->createTTF(fontsize);
- Shared<TTF>* refTTF = new Shared<TTF>(font, JIN_GRAPHICS_TTF);
- {
- Shared<TTFData>& refTTFData = p->getShared<TTFData>();
- refTTFData.retain();
- refTTF->setUserdata(&refTTFData);
- }
- proxy->bind(refTTF);
+ Shared<TTF>* shrTTF = new Shared<TTF>(font, JIN_GRAPHICS_TTF);
+ shrTTF->setDependency(DEP_TTFDATA, &shrFontData);
+ pxyTTF->bind(shrTTF);
return 1;
}