diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/buildvm/buildvm.exe | bin | 121856 -> 123392 bytes | |||
-rw-r--r-- | src/3rdparty/minilua/minilua.exe | bin | 209920 -> 219136 bytes | |||
-rw-r--r-- | src/libjin/Graphics/je_gl.cpp | 18 | ||||
-rw-r--r-- | src/libjin/Graphics/je_gl.h | 10 | ||||
-rw-r--r-- | src/libjin/Graphics/je_sprite.cpp | 63 | ||||
-rw-r--r-- | src/libjin/Graphics/je_sprite.h | 34 | ||||
-rw-r--r-- | src/lua/common/je_lua_callback.cpp (renamed from src/lua/common/je_lua_function.cpp) | 16 | ||||
-rw-r--r-- | src/lua/common/je_lua_callback.h (renamed from src/lua/common/je_lua_function.h) | 35 | ||||
-rw-r--r-- | src/lua/common/je_lua_reference.h | 17 | ||||
-rw-r--r-- | src/lua/common/je_lua_shared.hpp | 8 | ||||
-rw-r--r-- | src/lua/jin.cpp | 47 | ||||
-rw-r--r-- | src/lua/luax.h | 4 | ||||
-rw-r--r-- | src/lua/modules/audio/je_lua_audio.cpp | 4 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_graphics.cpp | 36 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_net.cpp | 7 | ||||
-rw-r--r-- | src/lua/modules/time/je_lua_time.cpp | 5 | ||||
-rw-r--r-- | src/lua/modules/time/je_lua_timer.cpp | 57 |
17 files changed, 228 insertions, 133 deletions
diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe Binary files differindex 9cacff6..00cd94d 100644 --- a/src/3rdparty/buildvm/buildvm.exe +++ b/src/3rdparty/buildvm/buildvm.exe diff --git a/src/3rdparty/minilua/minilua.exe b/src/3rdparty/minilua/minilua.exe Binary files differindex 512e93b..003f2a1 100644 --- a/src/3rdparty/minilua/minilua.exe +++ b/src/3rdparty/minilua/minilua.exe diff --git a/src/libjin/Graphics/je_gl.cpp b/src/libjin/Graphics/je_gl.cpp index 9ef1460..f72ce37 100644 --- a/src/libjin/Graphics/je_gl.cpp +++ b/src/libjin/Graphics/je_gl.cpp @@ -1,5 +1,6 @@ #define OGL2D_IMPLEMENT #include "je_gl.h" +#include "je_color.h" namespace JinEngine { @@ -8,5 +9,22 @@ namespace JinEngine OpenGL gl; + void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a) + { + setColor(Color(r, g, b, a)); + } + + void OpenGL::setColor(Color c) + { + mCurrentColor = c; + glColor4f(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f); + } + + Color OpenGL::getColor() + { + return mCurrentColor; + } + + } // namespace Graphics } // namespace JinEngine diff --git a/src/libjin/Graphics/je_gl.h b/src/libjin/Graphics/je_gl.h index 48dccc2..331d899 100644 --- a/src/libjin/Graphics/je_gl.h +++ b/src/libjin/Graphics/je_gl.h @@ -3,6 +3,7 @@ #include "../math/je_matrix.h" +#include "je_color.h" #include "GLee/GLee.h" #include "ogl/OpenGL.h" @@ -31,6 +32,15 @@ namespace JinEngine { } + void setColor(Channel r, Channel g, Channel b, Channel a); + + void setColor(Color c); + + Color getColor(); + + private: + Color mCurrentColor; + }; extern OpenGL gl; diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp index 4d4fa12..4ef32a4 100644 --- a/src/libjin/Graphics/je_sprite.cpp +++ b/src/libjin/Graphics/je_sprite.cpp @@ -1,16 +1,69 @@ +#include "shaders/je_shader.h" + #include "je_sprite.h" +using namespace JinEngine::Graphics::Shaders; + namespace JinEngine { namespace Graphics { - void Sprite::onRender() + Sprite::Sprite() + : mShader(nullptr) + , mGraphic(nullptr) + { + } + + void Sprite::setRotation(float r) + { + mRotation = r; + } + + void Sprite::setOrigin(Origin origin) + { + + } + + void Sprite::setOrigin(int x, int y) + { + + } + + void Sprite::setPosition(int x, int y) + { + + } + + void Sprite::setScale(float x, float y) + { + + } + + void Sprite::setColor(Color color) + { + + } + + void Sprite::setShader(const Shader* shader) + { + + } + + void Sprite::setGraphic(const Graphic* graphic) + { + + } + + void Sprite::render() { - if (mShader != nullptr) - mShader->use(); - - mShader->unuse(); + Shader* shader = Shader::getCurrentShader(); + Color c = gl.getColor(); + gl.setColor(mColor); + mShader->use(); + mGraphic->render(mPosition.x, mPosition.y, mScale.x, mScale.y, mRotation, mOrigin.x, mOrigin.y); + shader->use(); + gl.setColor(c); } } // namespace Graphics diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index 76ef30a..4fb7ebf 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -11,19 +11,6 @@ namespace JinEngine { namespace Graphics { - /** Determines position of the sprite in its bounds. */ - enum SpriteAnchor - { - SA_TopLeft, - SA_TopCenter, - SA_TopRight, - SA_MiddleLeft, - SA_MiddleCenter, - SA_MiddleRight, - SA_BottomLeft, - SA_BottomCenter, - SA_BottomRight - }; /// /// A sprite is unit of rendering. Animation is based on sprite, but not texture or other graphic stuff. @@ -31,6 +18,24 @@ namespace JinEngine class Sprite { public: + Sprite(); + virtual ~Sprite(); + + enum Origin + { + TopLeft, + TopCenter, + TopRight, + MiddleLeft, + MiddleCenter, + MiddleRight, + BottomLeft, + BottomCenter, + BottomRight + }; + + void setRotation(float r); + void setOrigin(Origin origin); void setOrigin(int x, int y); void setPosition(int x, int y); void setScale(float x, float y); @@ -41,7 +46,7 @@ namespace JinEngine /// /// Render callback. /// - virtual void onRender(); + virtual void render(); private: /// @@ -50,6 +55,7 @@ namespace JinEngine Math::Vector2<float> mPosition; Math::Vector2<int> mOrigin; Math::Vector2<float> mScale; + float mRotation; Color mColor; Shaders::Shader* mShader; Graphic* mGraphic; diff --git a/src/lua/common/je_lua_function.cpp b/src/lua/common/je_lua_callback.cpp index e202d99..392f919 100644 --- a/src/lua/common/je_lua_function.cpp +++ b/src/lua/common/je_lua_callback.cpp @@ -1,44 +1,42 @@ -#include "je_lua_function.h" +#include "je_lua_callback.h" namespace JinEngine { namespace Lua { - LuaFunc::LuaFunc(lua_State* L) + LuaCallback::LuaCallback(lua_State* L) : mLuaFunc(nullptr) , mParams(0) , mL(L) { } - LuaFunc::~LuaFunc() + LuaCallback::~LuaCallback() { delete mLuaFunc; for (auto p : mParams) delete p; } - void LuaFunc::setFunc(int i, uint nresults ) + void LuaCallback::setFunc(int i) { if (mLuaFunc != nullptr) delete mLuaFunc; mLuaFunc = new LuaRef(mL, i); - mNResults = nresults; } - void LuaFunc::pushParam(int i) + void LuaCallback::pushParam(int i) { mParams.push_back(new LuaRef(mL, i)); } - uint LuaFunc::call() + void LuaCallback::call() { mLuaFunc->push(); for (auto p : mParams) p->push(); - luax_call(mL, mParams.size(), mNResults); - return mNResults; + luax_call(mL, mParams.size(), 0); } } diff --git a/src/lua/common/je_lua_function.h b/src/lua/common/je_lua_callback.h index a2d5ccc..f3301fc 100644 --- a/src/lua/common/je_lua_function.h +++ b/src/lua/common/je_lua_callback.h @@ -12,16 +12,26 @@ namespace JinEngine namespace Lua { - class LuaFunc + /// + /// + /// + class LuaCallback { public: - LuaFunc(lua_State* L); - ~LuaFunc(); + /// + /// + /// + LuaCallback(lua_State* L); + + /// + /// + /// + ~LuaCallback(); /// /// /// - void setFunc(int i, uint nresults); + void setFunc(int i); /// /// @@ -31,13 +41,24 @@ namespace JinEngine /// /// /// - uint call(); + void call(); private: + /// + /// + /// LuaRef* mLuaFunc; + + /// + /// + /// std::vector<LuaRef*> mParams; - lua_State* mL; - uint mNResults; + + /// + /// + /// + lua_State* const mL; + }; } // namespace Lua diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h index d2d077f..f338762 100644 --- a/src/lua/common/je_lua_reference.h +++ b/src/lua/common/je_lua_reference.h @@ -15,9 +15,19 @@ namespace JinEngine class LuaRef { public: + /// + /// + /// LuaRef(lua_State* L, int i); + + /// + /// + /// ~LuaRef(); + /// + /// + /// void unref(); /// @@ -26,7 +36,14 @@ namespace JinEngine void push(); private: + /// + /// + /// lua_State* const mL; + + /// + /// + /// int mIndex; }; diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp index 7ac8923..876fe28 100644 --- a/src/lua/common/je_lua_shared.hpp +++ b/src/lua/common/je_lua_shared.hpp @@ -6,7 +6,7 @@ namespace JinEngine namespace Lua { - /*abstract*/class SharedBase + class SharedBase { public: void retain() @@ -20,7 +20,7 @@ namespace JinEngine delete this; } - // object type string + // Object type string. const char* const type; void setUserdata(void* data) @@ -63,12 +63,12 @@ namespace JinEngine T* operator->() { - return (T*)object; + return static_cast<T*>(object); } T* getObject() { - return (T*)object; + return static_cast<T*>(object); } private: diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp index 186b9b2..d9f685b 100644 --- a/src/lua/jin.cpp +++ b/src/lua/jin.cpp @@ -64,39 +64,38 @@ namespace JinEngine { 0, 0 } }; - /* sub modules */ - LUA_IMPLEMENT const luax_Reg mods[] = { - { "core", luaopen_core }, - { "event", luaopen_event }, - { "graphics", luaopen_graphics }, - { "time", luaopen_time }, - { "mouse", luaopen_mouse }, - { "keyboard", luaopen_keyboard }, - { "filesystem", luaopen_filesystem }, - { "net", luaopen_net }, - { "audio", luaopen_audio }, - { "joypad", luaopen_joypad }, - { "math", luaopen_math }, - { "thread", luaopen_thread }, - { "bit", luaopen_bit }, - //{"ai", luaopen_ai }, - { 0, 0 } - }; - /* register jin module, keep it on the top of stack */ LUA_EXPORT int luaopen_jin(lua_State* L) { luax_globaltable(L, MODULE_NAME); - /* register values */ + // Register values. luax_setfieldstrings(L, s); luax_setfieldnumbers(L, n); - /* register submodules */ - for (int i = 0; mods[i].name; ++i) + luax_Reg modules[] = { + { "core", luaopen_core }, + { "event", luaopen_event }, + { "graphics", luaopen_graphics }, + { "time", luaopen_time }, + { "mouse", luaopen_mouse }, + { "keyboard", luaopen_keyboard }, + { "filesystem", luaopen_filesystem }, + { "net", luaopen_net }, + { "audio", luaopen_audio }, + { "joypad", luaopen_joypad }, + { "math", luaopen_math }, + { "thread", luaopen_thread }, + { "bit", luaopen_bit }, + //{"ai", luaopen_ai }, + { 0, 0 } + }; + + // Register sub modules. + for (int i = 0; modules[i].name; ++i) { - mods[i].func(L); - luax_setfield(L, -2, mods[i].name); + modules[i].func(L); + luax_setfield(L, -2, modules[i].name); } return 1; diff --git a/src/lua/luax.h b/src/lua/luax.h index 89e456e..1c2081c 100644 --- a/src/lua/luax.h +++ b/src/lua/luax.h @@ -4,4 +4,8 @@ #include "LuaJIT/lua.hpp" #include "lua/libraries/luax/luax.h" +#define luax_newclass(l, f) \ +extern int f(lua_State*);\ +f(l) + #endif
\ No newline at end of file diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp index 92e2e04..29705b2 100644 --- a/src/lua/modules/audio/je_lua_audio.cpp +++ b/src/lua/modules/audio/je_lua_audio.cpp @@ -109,11 +109,9 @@ namespace JinEngine return 0; } - LUA_PORT int luaopen_Source(lua_State* L); - LUA_EXPORT int luaopen_audio(lua_State* L) { - luaopen_Source(L); + luax_newclass(L, luaopen_Source); luaL_Reg f[] = { { "init", l_init }, diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 3155aa0..b1437e2 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -426,7 +426,7 @@ namespace JinEngine { if (luax_gettop(L) == 0) { - glColor4f(1, 1, 1, 1); + gl.setColor(Color(255, 255, 255, 255)); return 0; } @@ -437,10 +437,7 @@ namespace JinEngine context.curRenderColor.a = luax_checknumber(L, 4); else context.curRenderColor.a = 255; - glColor4f(context.curRenderColor.r / 255.f, - context.curRenderColor.g / 255.f, - context.curRenderColor.b / 255.f, - context.curRenderColor.a / 255.f); + gl.setColor(context.curRenderColor); return 0; } @@ -738,28 +735,17 @@ namespace JinEngine return 0; } - LUA_PORT int luaopen_Texture(lua_State* L); - LUA_PORT int luaopen_Text(lua_State* L); - LUA_PORT int luaopen_TTF(lua_State* L); - LUA_PORT int luaopen_TextureFont(lua_State* L); - LUA_PORT int luaopen_TTFData(lua_State* L); - LUA_PORT int luaopen_Page(lua_State* L); - LUA_PORT int luaopen_Canvas(lua_State* L); - LUA_PORT int luaopen_JSL(lua_State* L); - LUA_PORT int luaopen_Bitmap(lua_State* L); - LUA_EXPORT int luaopen_graphics(lua_State* L) { - // register types - luaopen_Bitmap(L); - luaopen_Texture(L); - luaopen_Canvas(L); - luaopen_TTFData(L); - luaopen_TTF(L); - luaopen_Text(L); - luaopen_TextureFont(L); - luaopen_Page(L); - luaopen_JSL(L); + luax_newclass(L, luaopen_Bitmap); + luax_newclass(L, luaopen_Texture); + luax_newclass(L, luaopen_Canvas); + luax_newclass(L, luaopen_TTFData); + luax_newclass(L, luaopen_TTF); + luax_newclass(L, luaopen_Text); + luax_newclass(L, luaopen_TextureFont); + luax_newclass(L, luaopen_Page); + luax_newclass(L, luaopen_JSL); luaL_Reg f[] = { /* window */ diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp index 4240903..1d0204a 100644 --- a/src/lua/modules/net/je_lua_net.cpp +++ b/src/lua/modules/net/je_lua_net.cpp @@ -62,13 +62,10 @@ namespace Lua return 1; } - LUA_PORT int luaopen_Socket(lua_State* L); - LUA_PORT int luaopen_Buffer(lua_State* L); - LUA_EXPORT int luaopen_net(lua_State* L) { - luaopen_Socket(L); - luaopen_Buffer(L); + luax_newclass(L, luaopen_Socket); + luax_newclass(L, luaopen_Buffer); luaL_Reg f[] = { { "init", l_initNetwork }, diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp index c42fc0f..4546337 100644 --- a/src/lua/modules/time/je_lua_time.cpp +++ b/src/lua/modules/time/je_lua_time.cpp @@ -50,12 +50,9 @@ namespace JinEngine return 0; } - LUA_PORT int luaopen_Timer(lua_State* L); - LUA_EXPORT int luaopen_time(lua_State* L) { - luaopen_Timer(L); - + luax_newclass(L, luaopen_Timer); luaL_Reg f[] = { { "second", l_sec }, { "sleep", l_sleep }, diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp index 42d4215..6e5c390 100644 --- a/src/lua/modules/time/je_lua_timer.cpp +++ b/src/lua/modules/time/je_lua_timer.cpp @@ -1,5 +1,5 @@ #include "../types.h" -#include "lua/common/je_lua_function.h" +#include "lua/common/je_lua_callback.h" #include "lua/common/je_lua_common.h" #include "je_lua_timer.h" @@ -12,31 +12,15 @@ namespace JinEngine typedef Shared<Timer>& SharedTimer; - class Callback - { - public: - Callback() - { - } - ~Callback() - { - delete func; - delete param; - } - - LuaRef* func; - LuaRef* param; - }; - - static Timer::TimerCallback Timer_Callback = [](void* data)->void + static Timer::TimerCallback timerCallback = [](void* data)->void { - LuaFunc* func = static_cast<LuaFunc*>(data); + LuaCallback* func = static_cast<LuaCallback*>(data); func->call(); }; - static Timer::FinishCallback Finish_Callback = [](void* data)->void + static Timer::FinishCallback finishCallback = [](void* data)->void { - LuaFunc* func = static_cast<LuaFunc*>(data); + LuaCallback* func = static_cast<LuaCallback*>(data); delete func; }; @@ -49,13 +33,15 @@ namespace JinEngine // timer:every(time, callback, parameter) LUA_IMPLEMENT int l_every(lua_State* L) { + int n = luax_gettop(L); SharedTimer shared = checkTimer(L); Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); - LuaFunc* func = new LuaFunc(L); - func->setFunc(3, 0); - func->pushParam(4); - Timer::Handler* handler = timer->every(s, Timer_Callback, func, Finish_Callback); + LuaCallback* func = new LuaCallback(L); + func->setFunc(3); + for(int i = 4; i <= n; ++i) + func->pushParam(i); + Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; @@ -64,13 +50,15 @@ namespace JinEngine // timer:after(time, callback, parameter) LUA_IMPLEMENT int l_after(lua_State* L) { + int n = luax_gettop(L); SharedTimer shared = checkTimer(L); Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); - LuaFunc* func = new LuaFunc(L); - func->setFunc(3, 0); - func->pushParam(4); - Timer::Handler* handler = timer->after(s, Timer_Callback, func, Finish_Callback); + LuaCallback* func = new LuaCallback(L); + func->setFunc(3); + for (int i = 4; i <= n; ++i) + func->pushParam(i); + Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; @@ -79,14 +67,16 @@ namespace JinEngine // timer:repeat(time, callback, parameter) LUA_IMPLEMENT int l_repeat(lua_State* L) { + int n = luax_gettop(L); SharedTimer shared = checkTimer(L); Timer* timer = shared.getObject(); float s = luax_checknumber(L, 2); int count = luax_checkinteger(L, 3); - LuaFunc* func = new LuaFunc(L); - func->setFunc(4, 0); - func->pushParam(5); - Timer::Handler* handler = timer->repeat(s, count, Timer_Callback, func, Finish_Callback); + LuaCallback* func = new LuaCallback(L); + func->setFunc(4); + for (int i = 5; i <= n; ++i) + func->pushParam(i); + Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback); Proxy* proxy = luax_newinstance(L, JIN_TIME_HANDLER); proxy->bind(new Shared<Timer::Handler>(handler, JIN_TIME_HANDLER)); return 1; @@ -140,6 +130,7 @@ namespace JinEngine }; luax_newtype(L, JIN_TIME_TIMER, f); + return 0; } |