From 611d12bdd245dd43b7434661d3e24f2b435378cb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Nov 2018 21:21:54 +0800 Subject: =?UTF-8?q?*=E6=9B=B4=E6=96=B0=E6=B8=B2=E6=9F=93=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/3rdparty/buildvm/buildvm.exe | Bin 123392 -> 121856 bytes src/3rdparty/minilua/minilua.exe | Bin 219136 -> 209920 bytes src/jin/main.cpp | 2 +- src/libjin/Graphics/animations/je_animation.h | 7 ++- src/libjin/Graphics/je_bitmap.h | 7 +++ src/libjin/Graphics/je_mesh.h | 2 +- src/libjin/Graphics/je_sprite.cpp | 20 ++++++++- src/libjin/Graphics/je_sprite.h | 13 ++++-- src/libjin/Graphics/je_sprite_batch.cpp | 11 +++++ src/libjin/Graphics/je_sprite_batch.h | 7 ++- src/lua/common/je_lua_shared.hpp | 4 +- src/lua/modules/graphics/je_lua_graphics.cpp | 7 +-- src/lua/modules/graphics/je_lua_page.h | 2 +- src/lua/modules/graphics/je_lua_shader.cpp | 3 -- src/lua/modules/graphics/je_lua_sprite.cpp | 45 ++++++++++++++----- src/lua/modules/graphics/je_lua_sprite.h | 20 +++++++++ src/lua/modules/graphics/je_lua_spritesheet.cpp | 53 +++++++++++++++++++++++ src/lua/modules/graphics/je_lua_spritesheet.h | 2 +- src/lua/modules/graphics/je_lua_texture_font.cpp | 2 +- src/lua/modules/graphics/je_lua_ttf.cpp | 2 +- src/lua/modules/types.h | 1 + 21 files changed, 177 insertions(+), 33 deletions(-) create mode 100644 src/lua/modules/graphics/je_lua_sprite.h create mode 100644 src/lua/modules/graphics/je_lua_spritesheet.cpp (limited to 'src') diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe index f60b37b..6d94ce5 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 1070809..d7f6719 100644 Binary files a/src/3rdparty/minilua/minilua.exe and b/src/3rdparty/minilua/minilua.exe differ diff --git a/src/jin/main.cpp b/src/jin/main.cpp index da5b5e7..8b91cf3 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -104,4 +104,4 @@ int main(int argc, char* args[]) load(cwd.c_str()); return 0; -} \ No newline at end of file +}// todo:吧main.lua的读取提出来 \ No newline at end of file diff --git a/src/libjin/Graphics/animations/je_animation.h b/src/libjin/Graphics/animations/je_animation.h index 05e1d4f..9926cf9 100644 --- a/src/libjin/Graphics/animations/je_animation.h +++ b/src/libjin/Graphics/animations/je_animation.h @@ -30,7 +30,12 @@ namespace JinEngine /// /// Get current frame index. /// - uint getCurrentFrame(); + uint getCurrentFrameIndex(); + + /// + /// + /// + Sprite* getCurrentFrame(); /// /// Set current frame index. diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h index b0b7dad..c3041f8 100644 --- a/src/libjin/Graphics/je_bitmap.h +++ b/src/libjin/Graphics/je_bitmap.h @@ -3,6 +3,8 @@ #include "../core/je_configuration.h" #if defined(jin_graphics) +#include + #include "GLee/GLee.h" #include "../common/je_types.h" @@ -62,6 +64,11 @@ namespace JinEngine /// static Bitmap* createBitmap(int width, int height, Color color = Color::BLACK); + /// + /// Create bitmap and set bitmap pixels with given drawer. + /// + static Bitmap* createBitmap(int width, int height, std::function drawer); + /// /// Create bitmap with another one. /// diff --git a/src/libjin/Graphics/je_mesh.h b/src/libjin/Graphics/je_mesh.h index f5680ee..dbb2881 100644 --- a/src/libjin/Graphics/je_mesh.h +++ b/src/libjin/Graphics/je_mesh.h @@ -7,7 +7,7 @@ namespace JinEngine { /// - /// + /// A 2D mesh. /// class Mesh { diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp index 176447c..810cb0e 100644 --- a/src/libjin/Graphics/je_sprite.cpp +++ b/src/libjin/Graphics/je_sprite.cpp @@ -93,7 +93,7 @@ namespace JinEngine mIsOriginEnum = false; } - void Sprite::setPosition(int x, int y) + void Sprite::setPosition(float x, float y) { mPosition.set(x, y); } @@ -121,6 +121,24 @@ namespace JinEngine setQuad(0, 0, w, h); } + + void Sprite::move(float x, float y) + { + mPosition.x += x; + mPosition.y += y; + } + + void Sprite::rotate(float r) + { + mRotation += r; + } + + void Sprite::scale(float sx, float sy) + { + mScale.x += sx; + mScale.y += sy; + } + void Sprite::render() { Shader* shader = Shader::getCurrentShader(); diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index ad95aa4..d48fbbc 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -38,12 +38,16 @@ namespace JinEngine 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); + void setPosition(float x, float y); + void setScale(float sx, float sy); void setColor(Color color); void setShader(Shaders::Shader* shader); void setGraphic(const Graphic* graphic); + void move(float x, float y); + void rotate(float r); + void scale(float sx, float sy); + float getRotation() { return mRotation; } Math::Vector2 getSize() { return Math::Vector2(mQuad.w, mQuad.h); } const Math::Quad& getQuad() { return mQuad; } @@ -64,13 +68,14 @@ namespace JinEngine Math::Vector2 mPosition; Math::Vector2 mOrigin; Math::Vector2 mScale; + float mRotation; + Color mColor; + Math::Quad mQuad; bool mIsOriginEnum; Origin mOriginEnum; - float mRotation; - Color mColor; Shaders::Shader* mShader; const Graphic* mGraphic; diff --git a/src/libjin/Graphics/je_sprite_batch.cpp b/src/libjin/Graphics/je_sprite_batch.cpp index e69de29..f339715 100644 --- a/src/libjin/Graphics/je_sprite_batch.cpp +++ b/src/libjin/Graphics/je_sprite_batch.cpp @@ -0,0 +1,11 @@ +#include "je_sprite_batch.h" + +namespace JinEngine +{ + namespace Graphics + { + + + + } +} \ No newline at end of file diff --git a/src/libjin/Graphics/je_sprite_batch.h b/src/libjin/Graphics/je_sprite_batch.h index 7c1098b..64f9805 100644 --- a/src/libjin/Graphics/je_sprite_batch.h +++ b/src/libjin/Graphics/je_sprite_batch.h @@ -8,10 +8,13 @@ namespace JinEngine class SpriteBatch { + public: + + private: }; - } -} + } // namespace Graphics +} // namespace JinEngine #endif \ No newline at end of file diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp index 2c3e309..9cd7073 100644 --- a/src/lua/common/je_lua_shared.hpp +++ b/src/lua/common/je_lua_shared.hpp @@ -1,5 +1,5 @@ -#ifndef __JIN_COMMON_SHARED_H -#define __JIN_COMMON_SHARED_H +#ifndef __JIN_COMMON_SHARED_H__ +#define __JIN_COMMON_SHARED_H__ #include #include 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(); - Shared& shrSSheet = pxySSheet->getShared(); + Shared* shrSSheet = new Shared(new SpriteSheet(graphic), JIN_GRAPHICS_SPRITESHEET); Shared& shrGraphic = pxyGraphic->getShared(); - shrSSheet.setDependency(SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic); - pxySSheet->bind(new Shared(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& 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(); sprite->setShader(shader); - sprite.setDependency(SpriteDependency::DEP_SHADER, &proxy->getShared()); + sprite.setDependency((int)SpriteDependency::DEP_SHADER, &proxy->getShared()); return 0; } @@ -114,11 +108,37 @@ namespace JinEngine if (p != nullptr) { sprite->setGraphic(p->getObject()); - sprite.setDependency(SpriteDependency::DEP_GRAPHIC, &p->getShared()); + sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared()); } 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& shrSSheet = pxySSheet->getShared(); + SpriteSheet* sheet = pxySSheet->getObject(); + 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* shrSprite = new Shared(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* shrPage = new Shared(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* refPage = new Shared(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" -- cgit v1.1-26-g67d0