aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libjin/common/je_utf8.cpp42
-rw-r--r--src/libjin/common/je_utf8.h34
-rw-r--r--src/libjin/graphics/particles/je_particle_system.cpp8
-rw-r--r--src/libjin/graphics/particles/je_particle_system.h4
-rw-r--r--src/libjin/utils/je_log.h1
-rw-r--r--src/lua/common/je_lua.cpp5
-rw-r--r--src/lua/common/je_lua.h5
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.cpp1
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.cpp387
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.h21
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp2
-rw-r--r--src/lua/modules/net/je_lua_net.cpp2
12 files changed, 428 insertions, 84 deletions
diff --git a/src/libjin/common/je_utf8.cpp b/src/libjin/common/je_utf8.cpp
deleted file mode 100644
index bd7ce94..0000000
--- a/src/libjin/common/je_utf8.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "../core/je_configuration.h"
-#if jin_os == jin_os_windows
-
-#include "je_utf8.h"
-
-namespace JinEngine
-{
-
- std::string to_utf8(LPCWSTR wstr)
- {
- size_t wide_len = wcslen(wstr) + 1;
-
- // Get size in UTF-8.
- int utf8_size = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, 0, 0, 0, 0);
-
- char * utf8_str = new char[utf8_size];
-
- // Convert to UTF-8.
- int ok = WideCharToMultiByte(CP_UTF8, 0, wstr, wide_len, utf8_str, utf8_size, 0, 0);
-
- if (!ok)
- {
- delete[] utf8_str;
- }
-
- return ok ? std::string(utf8_str) : std::string();
- }
-
- void replace_char(std::string & str, char find, char replace)
- {
- int length = str.length();
-
- for (int i = 0; i<length; i++)
- {
- if (str[i] == find)
- str[i] = replace;
- }
- }
-
-} // namespace JinEngine
-
-#endif // jin_os == jin_os_windows \ No newline at end of file
diff --git a/src/libjin/common/je_utf8.h b/src/libjin/common/je_utf8.h
deleted file mode 100644
index a720640..0000000
--- a/src/libjin/common/je_utf8.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef __JE_COMMON_UTF8_H__
-#define __JE_COMMON_UTF8_H__
-
-#include "../core/je_configuration.h"
-#if jin_os == jin_os_windows
-
-#include <string>
-#include <windows.h>
-
-namespace JinEngine
-{
-
- ///
- /// Convert the wide string to a UTF-8 encoded string.
- ///
- /// @param wstr The wide-char string.
- /// @return A UTF-8 string.
- ///
- std::string to_utf8(LPCWSTR wstr);
-
- ///
- /// Replace all occurences of 'find' with 'replace' in a string.
- ///
- /// @param str The string to modify.
- /// @param find The character to match.
- /// @param replace The character to replace matches.
- ///
- void replace_char(std::string & str, char find, char replace);
-
-} // namespace JinEngine
-
-#endif // jin_os == jin_os_windows
-
-#endif // __JE_COMMON_UTF8_H__ \ No newline at end of file
diff --git a/src/libjin/graphics/particles/je_particle_system.cpp b/src/libjin/graphics/particles/je_particle_system.cpp
index a6e9460..cb2472f 100644
--- a/src/libjin/graphics/particles/je_particle_system.cpp
+++ b/src/libjin/graphics/particles/je_particle_system.cpp
@@ -192,6 +192,14 @@ namespace JinEngine
va_end(args);
}
+ void ParticleSystem::addParticleSprites(const std::vector<const Sprite*>& sprs)
+ {
+ for (const Sprite* spr : sprs)
+ {
+ addParticleSprite(spr);
+ }
+ }
+
void ParticleSystem::removeParticleSprite(uint i)
{
mDef.particleDef.spritesDef.sprites.erase(mDef.particleDef.spritesDef.sprites.begin() + i);
diff --git a/src/libjin/graphics/particles/je_particle_system.h b/src/libjin/graphics/particles/je_particle_system.h
index 56043a5..4734313 100644
--- a/src/libjin/graphics/particles/je_particle_system.h
+++ b/src/libjin/graphics/particles/je_particle_system.h
@@ -131,6 +131,7 @@ namespace JinEngine
void setParticleSpritesMode(SpriteMode mode);
void addParticleSprite(const Sprite* sprite);
void addParticleSprites(uint count, ...);
+ void addParticleSprites(const std::vector<const Sprite*>& sprs);
void removeParticleSprite(uint i);
void enableParticleBlendAdditive(bool enable);
@@ -148,7 +149,6 @@ namespace JinEngine
void removeParticleTransparencyPoint(uint i);
private:
-
friend class ParticleEmitter;
///
@@ -190,6 +190,6 @@ namespace JinEngine
} // namespace Particles
} // namespace Graphics
-} // namespace JinEngine
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/utils/je_log.h b/src/libjin/utils/je_log.h
index f81bbae..3d34943 100644
--- a/src/libjin/utils/je_log.h
+++ b/src/libjin/utils/je_log.h
@@ -45,7 +45,6 @@ private:
static std::ofstream fs; // ļ
};
-
typedef Loghelper::Level Loglevel;
#if defined(jin_debug)
diff --git a/src/lua/common/je_lua.cpp b/src/lua/common/je_lua.cpp
index 0b6c498..73f671c 100644
--- a/src/lua/common/je_lua.cpp
+++ b/src/lua/common/je_lua.cpp
@@ -33,6 +33,11 @@ namespace JinEngine
return obj;
}
+ LuaObject* luax_checkobject(lua_State* L, int idx, const char* type)
+ {
+ return (LuaObject*)luax_checktype(L, idx, type);
+ }
+
LuaObject* luax_copyinstance(lua_State* to, LuaObject* src)
{
if (to == src->state)
diff --git a/src/lua/common/je_lua.h b/src/lua/common/je_lua.h
index 24f89fe..b390e4c 100644
--- a/src/lua/common/je_lua.h
+++ b/src/lua/common/je_lua.h
@@ -28,6 +28,11 @@ namespace JinEngine
LuaObject* luax_copyinstance(lua_State* to, LuaObject* src);
///
+ ///
+ ///
+ LuaObject* luax_checkobject(lua_State* L, int idx, const char* type);
+
+ ///
/// Access lua object by object pointer.
///
int luax_getobject(lua_State* L, SharedBase* shared);
diff --git a/src/lua/modules/filesystem/je_lua_filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp
index 8bc3a69..e73d1ad 100644
--- a/src/lua/modules/filesystem/je_lua_filesystem.cpp
+++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp
@@ -133,7 +133,6 @@ namespace JinEngine
};
luax_newlib(L, methods);
luax_registersearcher(L, loader, 1);
-
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp
index b0cb221..53611a9 100644
--- a/src/lua/modules/graphics/je_lua_particle_system.cpp
+++ b/src/lua/modules/graphics/je_lua_particle_system.cpp
@@ -1,11 +1,396 @@
+#include <vector>
+
+#include "common/je_lua_object.h"
+#include "common/je_lua_common.h"
#include "libjin/jin.h"
+#include "je_lua_sprite.h"
+#include "je_lua_particle_system.h"
+
+using namespace std;
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Particles;
+
namespace JinEngine
{
namespace Lua
{
+ const char* Jin_Lua_ParticleSystem = "ParticleSystem";
+
+ typedef Shared<ParticleSystem>& SharedParticleSystem;
+
+ LUA_IMPLEMENT inline SharedParticleSystem checkPS(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ return luaObj->getShared<ParticleSystem>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ LuaObject* luaObj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ luaObj->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float dt = luax_checknumber(L, 2);
+ ps->update(dt);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ ps->render();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setPosition(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ ps->setPosition(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setScale(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ ps->setScale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ bool b = luax_checkbool(L, 2);
+ ps->pause(b);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_clear(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ ps->clear();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitRate(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitRate(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitRate(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitForce(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitForce(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitForce(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitDirection(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setEmitDirection(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setEmitDirection(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setEmitPosition(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ Vector2<float> floor, ceil;
+ floor.x = luax_rawgetnumber(L, 2, 1);
+ floor.y = luax_rawgetnumber(L, 2, 2);
+ ceil.x = luax_rawgetnumber(L, 3, 1);
+ ceil.y = luax_rawgetnumber(L, 3, 2);
+ ps->setEmitPosition(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ Vector2<float> pos;
+ pos.x = luax_rawgetnumber(L, 2, 1);
+ pos.y = luax_rawgetnumber(L, 2, 2);
+ ps->setEmitPosition(pos);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleLife(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setParticleLife(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setParticleLife(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleLinearAccelaration(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "table");
+ return 1;
+ }
+ Vector2<float> ac;
+ ac.x = luax_rawgetnumber(L, 2, 1);
+ ac.y = luax_rawgetnumber(L, 2, 2);
+ ps->setParticleLinearAccelaration(ac);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleRadialAccelaration(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float ra = luax_checknumber(L, 2);
+ ps->setParticleRadialAccelaration(ra);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleAngularSpeed(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (luax_gettop(L) >= 3)
+ {
+ float floor = luax_checknumber(L, 2);
+ float ceil = luax_checknumber(L, 3);
+ ps->setParticleAngularSpeed(floor, ceil);
+ }
+ else if (luax_gettop(L) >= 2)
+ {
+ float n = luax_checknumber(L, 2);
+ ps->setParticleAngularSpeed(n);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleSpritesMode(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ int n = luax_checkinteger(L, 2);
+ SpriteMode mode = static_cast<SpriteMode>(n);
+ ps->setParticleSpritesMode(mode);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleSprite(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ SharedParticleSystem ps = obj->getShared<ParticleSystem>();
+ LuaObject* objSpr = luax_checkobject(L, 2, Jin_Lua_Sprite);
+ Sprite* spr = objSpr->getObject<Sprite>();
+ ps->addParticleSprite(spr);
+ int depn = (*obj).getDependenciesCount();
+ (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn, objSpr->getSharedBase());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleSprites(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ SharedParticleSystem ps = obj->getShared<ParticleSystem>();
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "sprites table");
+ return 1;
+ }
+ int n = luax_tableidxlen(L, 2);
+ int depn = (*obj).getDependenciesCount();
+ for (int i = 1; i <= n; ++i)
+ {
+ luax_rawgeti(L, 2, i);
+ LuaObject* objSpr = luax_checkobject(L, -1, Jin_Lua_Sprite);
+ luax_pop(L, 1);
+ Sprite* spr = objSpr->getObject<Sprite>();
+ ps->addParticleSprite(spr);
+ (*obj).setDependency((int)ParticleSystemDependency::DEP_SPRITES + depn + i - 1, objSpr->getSharedBase());
+ }
+ return 0;
+ }
+
+ // From 0
+ LUA_IMPLEMENT int l_removeParticleSprite(lua_State* L)
+ {
+ LuaObject* obj = luax_checkobject(L, 1, Jin_Lua_ParticleSystem);
+ SharedParticleSystem ps = obj->getShared<ParticleSystem>();
+ int n = luax_checkinteger(L, 2);
+ ps->removeParticleSprite(n);
+ (*obj).removeDependency((int)ParticleSystemDependency::DEP_SPRITES + n);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_enableParticleBlendAdditive(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ bool enable = luax_checkbool(L, 2);
+ ps->enableParticleBlendAdditive(enable);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleScale(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float scale = luax_checknumber(L, 2);
+ ps->setParticleScale(scale);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleScalePoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float scale = luax_checknumber(L, 2);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleScalePoint(scale, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleScalePoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleScalePoint(i);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleColor(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "color table");
+ return 1;
+ }
+ Color c;
+ c.r = luax_rawgetnumber(L, 2, 1);
+ c.g = luax_rawgetnumber(L, 2, 2);
+ c.b = luax_rawgetnumber(L, 2, 3);
+ c.a = luax_rawgetnumber(L, 2, 4);
+ ps->setParticleColor(c);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleColorPoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ if (!luax_istable(L, 2))
+ {
+ luax_typerror(L, 2, "color table");
+ return 1;
+ }
+ Color c;
+ c.r = luax_rawgetnumber(L, 2, 1);
+ c.g = luax_rawgetnumber(L, 2, 2);
+ c.b = luax_rawgetnumber(L, 2, 3);
+ c.a = luax_rawgetnumber(L, 2, 4);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleColorPoint(c, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleColorPoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleColorPoint(i);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setParticleTransparency(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float transparency = luax_checknumber(L, 2);
+ ps->setParticleTransparency(transparency);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_addParticleTransparencyPoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ float transparency = luax_checknumber(L, 2);
+ float t = luax_checknumber(L, 3);
+ ps->addParticleTransparencyPoint(transparency, t);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_removeParticleTransparencyPoint(lua_State* L)
+ {
+ SharedParticleSystem ps = checkPS(L);
+ int i = luax_checkinteger(L, 2);
+ ps->removeParticleTransparencyPoint(i);
+ return 0;
+ }
+ LUA_EXPORT void luaopen_ParticleSystem(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_ParticleSystem, methods);
+ }
- } // Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.h b/src/lua/modules/graphics/je_lua_particle_system.h
index e69de29..b75b569 100644
--- a/src/lua/modules/graphics/je_lua_particle_system.h
+++ b/src/lua/modules/graphics/je_lua_particle_system.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_PARTICLESYSTEM_H__
+#define __JE_LUA_PARTICLESYSTEM_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class ParticleSystemDependency
+ {
+ DEP_SPRITES = 1,
+ };
+
+ extern const char* Jin_Lua_ParticleSystem;
+
+ void luaopen_ParticleSystem(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index 8bef1bf..f4a4231 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -23,7 +23,7 @@ namespace JinEngine
LuaObject* luaObj = (LuaObject*)luax_checktype(L, 1, Jin_Lua_Shader);
return luaObj->getShared<Shader>();
}
-
+
/**
* jsl:sendNumber("variable", 0.1)
*/
diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp
index e631827..5db4722 100644
--- a/src/lua/modules/net/je_lua_net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -65,7 +65,6 @@ namespace JinEngine
{
luaopen_Socket(L);
luaopen_Buffer(L);
-
luaL_Reg methods[] = {
{ "init", l_initNetwork },
{ "newSocket", l_Socket },
@@ -73,7 +72,6 @@ namespace JinEngine
{ 0, 0 }
};
luax_newlib(L, methods);
-
return 1;
}