aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp7
-rw-r--r--src/lua/modules/graphics/je_lua_page.h2
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp3
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp45
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.h20
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp53
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.h2
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp2
-rw-r--r--src/lua/modules/types.h1
10 files changed, 116 insertions, 21 deletions
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index d129e6a..6b84651 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -678,10 +678,10 @@ namespace JinEngine
{
Proxy* pxySSheet = luax_newinstance(L, JIN_GRAPHICS_SPRITESHEET);
Graphic* graphic = pxyGraphic->getObject<Graphic>();
- Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), JIN_GRAPHICS_SPRITESHEET);
Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
- shrSSheet.setDependency(SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
- pxySSheet->bind(new Shared<SpriteSheet>(new SpriteSheet(graphic), JIN_GRAPHICS_SPRITESHEET));
+ shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
+ pxySSheet->bind(shrSSheet);
return 1;
}
else
@@ -776,6 +776,7 @@ namespace JinEngine
luax_newclass(L, luaopen_Page);
luax_newclass(L, luaopen_JSL);
luax_newclass(L, luaopen_Sprite);
+ luax_newclass(L, luaopen_SpriteSheet);
luaL_Reg f[] = {
/* window */
diff --git a/src/lua/modules/graphics/je_lua_page.h b/src/lua/modules/graphics/je_lua_page.h
index d2d9f22..c9775e9 100644
--- a/src/lua/modules/graphics/je_lua_page.h
+++ b/src/lua/modules/graphics/je_lua_page.h
@@ -6,7 +6,7 @@ namespace JinEngine
namespace Lua
{
- enum PageDependency
+ enum class PageDependency
{
DEP_TTF = 1,
DEP_TEXTURE_FONT = 2,
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index cab31cf..8c1c2e4 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -111,9 +111,6 @@ namespace JinEngine
return 0;
}
- /**
- * JSL program
- */
LUA_EXPORT int luaopen_JSL(lua_State* L)
{
luaL_Reg f[] = {
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
index af1ac60..511f877 100644
--- a/src/lua/modules/graphics/je_lua_sprite.cpp
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -2,6 +2,7 @@
#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,13 +12,6 @@ namespace JinEngine
namespace Lua
{
- // Sprite dependency slots.
- enum SpriteDependency
- {
- DEP_GRAPHIC = 1,
- DEP_SHADER = 2,
- };
-
typedef Shared<Sprite>& SharedSprite;
LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L)
@@ -66,8 +60,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_setPosition(lua_State* L)
{
SharedSprite sprite = checkSprite(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
sprite->setPosition(x, y);
return 0;
}
@@ -98,7 +92,7 @@ namespace JinEngine
Proxy* proxy = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_SHADER);
Shader* shader = proxy->getObject<Shader>();
sprite->setShader(shader);
- sprite.setDependency(SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
+ sprite.setDependency((int)SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
return 0;
}
@@ -114,11 +108,37 @@ namespace JinEngine
if (p != nullptr)
{
sprite->setGraphic(p->getObject<Graphic>());
- sprite.setDependency(SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
+ sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
}
return 0;
}
+ LUA_IMPLEMENT int l_move(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->move(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->rotate(r);
+ return 0;
+ }
+
LUA_IMPLEMENT int l_getRotation(lua_State* L)
{
SharedSprite sprite = checkSprite(L);
@@ -184,6 +204,9 @@ namespace JinEngine
{ "setColor", l_setColor },
{ "setShader", l_setShader },
{ "setGraphic", l_setGraphic },
+ { "move", l_move },
+ { "scale", l_scale },
+ { "rotate", l_rotate },
{ "getRotation", l_getRotation },
{ "getPosition", l_getPosition },
{ "getOrigin", l_getOrigin },
diff --git a/src/lua/modules/graphics/je_lua_sprite.h b/src/lua/modules/graphics/je_lua_sprite.h
new file mode 100644
index 0000000..cdd3a50
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.h
@@ -0,0 +1,20 @@
+#ifndef __JE_LUA_SPRITE_H__
+#define __JE_LUA_SPRITE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ // Sprite dependency slots.
+ enum class SpriteDependency
+ {
+ DEP_GRAPHIC = 1,
+ DEP_SHADER = 2,
+ DEP_SPRITESHEET = 3
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
new file mode 100644
index 0000000..7994237
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -0,0 +1,53 @@
+#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SPRITESHEET);
+ pxySSheet->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SPRITESHEET);
+ Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ SpriteSheet* sheet = pxySSheet->getObject<SpriteSheet>();
+ Quad quad;
+ quad.x = luax_checkinteger(L, 2);
+ quad.y = luax_checkinteger(L, 3);
+ quad.w = luax_checkinteger(L, 4);
+ quad.h = luax_checkinteger(L, 5);
+ Sprite* spr = sheet->createSprite(quad);
+ Proxy* pxySprite = luax_newinstance(L, JIN_GRAPHICS_SPRITE);
+ Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, JIN_GRAPHICS_SPRITE);
+ shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet);
+ pxySprite->bind(shrSprite);
+ return 1;
+ }
+
+ LUA_EXPORT int luaopen_SpriteSheet(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { 0, 0 }
+ };
+ luax_newtype(L, JIN_GRAPHICS_SPRITESHEET, methods);
+ return 0;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.h b/src/lua/modules/graphics/je_lua_spritesheet.h
index b4e965d..bedf945 100644
--- a/src/lua/modules/graphics/je_lua_spritesheet.h
+++ b/src/lua/modules/graphics/je_lua_spritesheet.h
@@ -6,7 +6,7 @@ namespace JinEngine
namespace Lua
{
- enum SpriteSheetDependency
+ enum class SpriteSheetDependency
{
DEP_GRAPHIC = 1
};
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index 0bd36e6..8be9a9d 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -43,7 +43,7 @@ namespace JinEngine
}
Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* shrPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- shrPage->setDependency(PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
+ shrPage->setDependency((int)PageDependency::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 319fdd6..0216a9a 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -43,7 +43,7 @@ namespace JinEngine
}
Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- refPage->setDependency(PageDependency::DEP_TTF, &shrTTF);
+ refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF);
pxyPage->bind(refPage);
return 1;
}
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
index 4bd0943..7e5c4fd 100644
--- a/src/lua/modules/types.h
+++ b/src/lua/modules/types.h
@@ -13,6 +13,7 @@
#define JIN_GRAPHICS_BITMAP "Bitmap"
#define JIN_GRAPHICS_SPRITE "Sprite"
#define JIN_GRAPHICS_SPRITESHEET "SpriteSheet"
+#define JIN_GRAPHICS_SPRITEBATCH "SpriteBatch"
// audio module
#define JIN_AUDIO_SOURCE "Source"