aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Graphics/particles/je_particle_emitter.cpp4
-rw-r--r--src/libjin/Graphics/particles/je_particle_emitter.h2
-rw-r--r--src/libjin/Math/je_random.cpp2
-rw-r--r--src/libjin/ai/je_state_machine.h13
-rw-r--r--src/lua/common/je_lua_common.h2
-rw-r--r--src/lua/common/je_lua_proxy.h30
-rw-r--r--src/lua/common/je_lua_shared.hpp (renamed from src/lua/common/je_lua_reference.hpp)43
-rw-r--r--src/lua/embed/embed.h8
-rw-r--r--src/lua/embed/scripts/ai.lua.h26
-rw-r--r--src/lua/embed/scripts/boot.lua.h (renamed from src/lua/embed/boot.lua.h)3
-rw-r--r--src/lua/embed/scripts/graphics.lua.h (renamed from src/lua/embed/graphics.lua.h)32
-rw-r--r--src/lua/embed/scripts/keyboard.lua.h (renamed from src/lua/embed/keyboard.lua.h)2
-rw-r--r--src/lua/embed/scripts/mouse.lua.h (renamed from src/lua/embed/mouse.lua.h)2
-rw-r--r--src/lua/embed/scripts/net.lua.h (renamed from src/lua/embed/net.lua.h)3
-rw-r--r--src/lua/embed/scripts/path.lua.h (renamed from src/lua/embed/path.lua.h)2
-rw-r--r--src/lua/jin.cpp2
-rw-r--r--src/lua/libraries/luax/luax.h6
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.cpp23
-rw-r--r--src/lua/modules/ai/je_lua_statemachine.cpp11
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp2
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp6
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp60
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp6
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp8
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp8
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp6
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp4
-rw-r--r--src/lua/modules/net/je_lua_net.cpp4
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp18
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp16
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp30
-rw-r--r--src/lua/modules/time/je_lua_timer.h19
-rw-r--r--src/lua/modules/types.h3
37 files changed, 260 insertions, 162 deletions
diff --git a/src/libjin/Graphics/particles/je_particle_emitter.cpp b/src/libjin/Graphics/particles/je_particle_emitter.cpp
index 63d3393..edc4bee 100644
--- a/src/libjin/Graphics/particles/je_particle_emitter.cpp
+++ b/src/libjin/Graphics/particles/je_particle_emitter.cpp
@@ -31,9 +31,9 @@ namespace JinEngine
mTime -= 1;
}
- void ParticleEmitter::emit(const ParticleEmitterDef& emitterDef, const ParticleDef& def, Particle& particle)
+ void ParticleEmitter::emit()
{
- particle.reset();
+
}
diff --git a/src/libjin/Graphics/particles/je_particle_emitter.h b/src/libjin/Graphics/particles/je_particle_emitter.h
index 34d0ee4..9200532 100644
--- a/src/libjin/Graphics/particles/je_particle_emitter.h
+++ b/src/libjin/Graphics/particles/je_particle_emitter.h
@@ -96,7 +96,7 @@ namespace JinEngine
/// Emit a particle according to emitter definition and particle definition, particle system should
/// assign particle value to the particle in particle pool, but not use this return particle.
///
- void emit(const ParticleEmitterDef& emitterDef, const ParticleDef& def, Particle& particle);
+ void emit();
///
///
diff --git a/src/libjin/Math/je_random.cpp b/src/libjin/Math/je_random.cpp
index a8f3310..983fa36 100644
--- a/src/libjin/Math/je_random.cpp
+++ b/src/libjin/Math/je_random.cpp
@@ -5,8 +5,6 @@ namespace JinEngine
namespace Math
{
-
-
RandomGenerator::RandomGenerator()
{
}
diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h
index d496c61..6cd3f17 100644
--- a/src/libjin/ai/je_state_machine.h
+++ b/src/libjin/ai/je_state_machine.h
@@ -411,15 +411,4 @@ namespace JinEngine
#endif // jin_ai
-#endif
-
-//local sp = jin.graphics.newSprite()
-//local sm = jin.ai.newStateMachine(jin.StateMachineMode.STEPWISE, sp)
-//sm:addState("run")
-//sm:addEnterCallback("run", function(spr)
-// spr:setRun()
-//end)
-//
-//function jin.core.onUpdate(dt)
-// sm:update()
-//end
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_common.h b/src/lua/common/je_lua_common.h
index 1d772a5..82c550a 100644
--- a/src/lua/common/je_lua_common.h
+++ b/src/lua/common/je_lua_common.h
@@ -3,7 +3,7 @@
#include "je_lua_port.h"
#include "je_lua_proxy.h"
-#include "je_lua_reference.hpp"
+#include "je_lua_shared.hpp"
#include "je_lua_error.h"
#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h
index b428dc9..56e5fee 100644
--- a/src/lua/common/je_lua_proxy.h
+++ b/src/lua/common/je_lua_proxy.h
@@ -1,7 +1,7 @@
#ifndef __JIN_COMMON_PROXY_H
#define __JIN_COMMON_PROXY_H
-#include "je_lua_reference.hpp"
+#include "je_lua_shared.hpp"
namespace JinEngine
{
@@ -11,53 +11,53 @@ namespace JinEngine
class Proxy
{
public:
- void bind(RefBase* ref)
+ void bind(SharedBase* ref)
{
if (ref == nullptr)
return;
- reference = ref;
+ shared = ref;
}
void release()
{
- if (reference != nullptr)
+ if (shared != nullptr)
{
- reference->release();
- reference = nullptr;
+ shared->release();
+ shared = nullptr;
}
}
void retain()
{
- if (reference != nullptr)
- reference->retain();
+ if (shared != nullptr)
+ shared->retain();
}
void setUserdata(void* data)
{
- if (reference != nullptr)
- reference->setUserdata(data);
+ if (shared != nullptr)
+ shared->setUserdata(data);
}
template<class T>
- Ref<T>& getRef()
+ Shared<T>& getShared()
{
- return *(Ref<T>*) reference;
+ return *(static_cast<Shared<T>*>(shared));
}
template<class T>
T* getObject()
{
- Ref<T>& ref = getRef<T>();
+ Shared<T>& ref = getShared<T>();
return ref.getObject();
}
const char* getObjectType()
{
- return reference->type;
+ return shared->type;
}
- RefBase* reference;
+ SharedBase* shared;
};
diff --git a/src/lua/common/je_lua_reference.hpp b/src/lua/common/je_lua_shared.hpp
index ba918bb..7ad7c1d 100644
--- a/src/lua/common/je_lua_reference.hpp
+++ b/src/lua/common/je_lua_shared.hpp
@@ -6,17 +6,17 @@ namespace JinEngine
namespace Lua
{
- /*abstract*/class RefBase
+ /*abstract*/class SharedBase
{
public:
void retain()
{
- ++count;
+ ++(*count);
}
void release()
{
- if (--count <= 0)
+ if (--(*count) <= 0)
delete this;
}
@@ -34,34 +34,35 @@ namespace JinEngine
}
protected:
- RefBase(void* obj, const char* t)
- : count(1)
- , object(obj)
+ SharedBase(void* obj, const char* t)
+ : object(obj)
, type(t)
{
+ count = new int(1);
}
- RefBase(const RefBase&);
+ SharedBase(const SharedBase&);
- virtual ~RefBase()
+ virtual ~SharedBase()
{
+
}
void* object;
- int count;
+ int* count;
void* userdata;
};
template<class T>
- class Ref : public RefBase
+ class Shared : public SharedBase
{
public:
- Ref(T* obj, const char* type)
- : RefBase(obj, type)
+ Shared(T* obj, const char* type)
+ : SharedBase(obj, type)
{
}
- ~Ref()
+ ~Shared()
{
T* obj = static_cast<T*>(object);
delete obj;
@@ -69,16 +70,26 @@ namespace JinEngine
T* operator->()
{
- return (T*)object;
+ return static_cast<T*>(object);
}
T* getObject()
{
- return (T*)object;
+ return static_cast<T*>(object);
+ }
+
+ T* operator &()
+ {
+ return static_cast<T*>(object);
+ }
+
+ T& operator *()
+ {
+ return *(static_cast<T*>(object));
}
private:
- Ref(const Ref<T>& ref);
+ Shared(const Shared<T>& ref);
};
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
index 1efbc95..054672c 100644
--- a/src/lua/embed/embed.h
+++ b/src/lua/embed/embed.h
@@ -18,10 +18,10 @@ namespace JinEngine
};
// Embed scripts.
- #include "graphics.lua.h"
- #include "keyboard.lua.h"
- #include "mouse.lua.h"
- #include "boot.lua.h"
+ #include "scripts/graphics.lua.h"
+ #include "scripts/keyboard.lua.h"
+ #include "scripts/mouse.lua.h"
+ #include "scripts/boot.lua.h"
// In order.
const jin_Embed scripts[] = {
diff --git a/src/lua/embed/scripts/ai.lua.h b/src/lua/embed/scripts/ai.lua.h
new file mode 100644
index 0000000..a69da84
--- /dev/null
+++ b/src/lua/embed/scripts/ai.lua.h
@@ -0,0 +1,26 @@
+/* graphics.lua */
+static const char* ai_lua = R"(
+jin.ai = jin.ai or {}
+
+local ja = jin.ai
+
+ja.StateMachineType = {
+ STEPWISE = 1,
+ ITERATIVE = 2,
+}
+
+
+
+)";
+
+
+//local sp = jin.graphics.newSprite()
+//local sm = jin.ai.newStateMachine(jin.StateMachineMode.STEPWISE, sp)
+//sm:addState("run")
+//sm:addEnterCallback("run", function(spr)
+// spr:setRun()
+//end)
+//
+//function jin.core.onUpdate(dt)
+// sm:update()
+//end
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/scripts/boot.lua.h
index 0884188..cffeca6 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/scripts/boot.lua.h
@@ -63,12 +63,13 @@ end
-- Display error message.
local function onError(msg)
+ jin.audio.destroy()
jin.graphics.showWindow()
local err = "Error:\n" .. msg .. "\n" .. debug.traceback()
jin.graphics.reset()
jin.graphics.setClearColor(100, 100, 100, 255)
jin.graphics.clear()
- jin.graphics.print(err, 5, 5)
+ jin.graphics.print(err, 5, 5)
jin.graphics.present()
while jin.core.running() do
for _, e in pairs(jin.event.poll()) do
diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/scripts/graphics.lua.h
index b2a19b5..751d029 100644
--- a/src/lua/embed/graphics.lua.h
+++ b/src/lua/embed/scripts/graphics.lua.h
@@ -2,6 +2,13 @@
static const char* graphics_lua = R"(
jin.graphics = jin.graphics or {}
+local jg = jin.graphics
+
+jg.RenderMode = {
+ FILL = 1,
+ LINE = 2,
+}
+
local default_shader = nil
local default_shader_source = [[
#VERTEX_SHADER
@@ -23,31 +30,32 @@ Color frag(Color col, Texture tex, Vertex v)
#END_FRAGMENT_SHADER
]]
-local _init = jin.graphics.init
+local _init = jg.init
local initialized = false
-jin.graphics.init = function(setting)
+jg.init = function(setting)
if initialized then
return initialized
end
initialized = _init(setting)
if initialized then
- default_shader = jin.graphics.newShader(default_shader_source)
- jin.graphics.useShader(default_shader)
+ default_shader = jg.newShader(default_shader_source)
+ jg.useShader(default_shader)
end
return initialized
end
-jin.graphics.unuseShader = function()
- jin.graphics.useShader(default_shader)
+jg.unuseShader = function()
+ jg.useShader(default_shader)
end
-- Reset all attributes to default value.
-jin.graphics.reset = function()
- jin.graphics.setColor(255, 255, 255, 255)
- jin.graphics.setClearColor(0, 0, 0, 255)
- jin.graphics.clear()
- jin.graphics.unsetFont()
+jg.reset = function()
+ jg.setColor(255, 255, 255, 255)
+ jg.setClearColor(0, 0, 0, 255)
+ jg.clear()
+ jg.unsetFont()
+ jg.unuseShader()
end
-)";
+)"; \ No newline at end of file
diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/embed/scripts/keyboard.lua.h
index ee8428f..e989928 100644
--- a/src/lua/embed/keyboard.lua.h
+++ b/src/lua/embed/scripts/keyboard.lua.h
@@ -2,6 +2,8 @@
static const char* keyboard_lua = R"(
jin.keyboard = jin.keyboard or {}
+local jk = jin.keyboard
+
local keys = {}
function jin.keyboard.isPressed(k)
diff --git a/src/lua/embed/mouse.lua.h b/src/lua/embed/scripts/mouse.lua.h
index 3c222f3..ca070a3 100644
--- a/src/lua/embed/mouse.lua.h
+++ b/src/lua/embed/scripts/mouse.lua.h
@@ -1,6 +1,8 @@
static const char* mouse_lua = R"(
jin.mouse = jin.mouse or {}
+local jm = jin.mouse
+
local button = {}
function jin.mouse.isDown(btn)
diff --git a/src/lua/embed/net.lua.h b/src/lua/embed/scripts/net.lua.h
index 4d89dc7..a986ce6 100644
--- a/src/lua/embed/net.lua.h
+++ b/src/lua/embed/scripts/net.lua.h
@@ -1,4 +1,7 @@
/* net.lua */
static const char* net_lua = R"(
jin.net = jin.net or {}
+
+local jn = jin.net
+
)"; \ No newline at end of file
diff --git a/src/lua/embed/path.lua.h b/src/lua/embed/scripts/path.lua.h
index 648adf8..f7e1ec3 100644
--- a/src/lua/embed/path.lua.h
+++ b/src/lua/embed/scripts/path.lua.h
@@ -2,6 +2,8 @@
static const char* path_lua = R"(
jin.path = jin.path or {}
+local jp = jin.path
+
-- game root directory
jin._root = nil
diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp
index 26b5f04..186b9b2 100644
--- a/src/lua/jin.cpp
+++ b/src/lua/jin.cpp
@@ -65,7 +65,7 @@ namespace JinEngine
};
/* sub modules */
- LUA_IMPLEMENT const luax_Ref mods[] = {
+ LUA_IMPLEMENT const luax_Reg mods[] = {
{ "core", luaopen_core },
{ "event", luaopen_event },
{ "graphics", luaopen_graphics },
diff --git a/src/lua/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h
index be2e227..8a01a05 100644
--- a/src/lua/libraries/luax/luax.h
+++ b/src/lua/libraries/luax/luax.h
@@ -417,7 +417,11 @@ inline void luax_setfieldnumbers(lua_State* L, const luax_Num* strs)
}
}
-typedef luaL_Reg luax_Ref;
+typedef luaL_Reg luax_Reg;
+
+#define luax_ref luaL_ref
+
+#define luax_unref luaL_unref
#endif // #if LUA_VERSION_NUM == 501
diff --git a/src/lua/modules/ai/je_lua_state_machine.cpp b/src/lua/modules/ai/je_lua_state_machine.cpp
new file mode 100644
index 0000000..9b95f43
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.cpp
@@ -0,0 +1,23 @@
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
+ {
+ StateMachine* sm;
+ sm->addEnterListener("", [](void* p) -> void{
+
+
+ });
+
+ return 0;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_statemachine.cpp b/src/lua/modules/ai/je_lua_statemachine.cpp
deleted file mode 100644
index f79d79a..0000000
--- a/src/lua/modules/ai/je_lua_statemachine.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
-
-
- }
-} \ 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 698d88a..88c0561 100644
--- a/src/lua/modules/audio/je_lua_audio.cpp
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -98,7 +98,7 @@ namespace JinEngine
return 1;
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
+ proxy->bind(new Shared<Source>(src, JIN_AUDIO_SOURCE));
return 1;
}
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
index d75d942..04f0528 100644
--- a/src/lua/modules/audio/je_lua_source.cpp
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -10,12 +10,12 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Source>& SourceRef;
+ typedef Shared<Source>& SourceRef;
LUA_IMPLEMENT inline SourceRef checkSource(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- return proxy->getRef<Source>();
+ return proxy->getShared<Source>();
}
LUA_IMPLEMENT int l_play(lua_State* L)
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
index a8d5bc0..8d4897b 100644
--- a/src/lua/modules/graphics/je_lua_bitmap.cpp
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -10,12 +10,12 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Bitmap>& BitmapRef;
+ typedef Shared<Bitmap>& BitmapRef;
LUA_IMPLEMENT inline BitmapRef checkBitmap(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- return proxy->getRef<Bitmap>();
+ return proxy->getShared<Bitmap>();
}
LUA_IMPLEMENT int l_gc(lua_State* L)
@@ -88,7 +88,7 @@ namespace JinEngine
Bitmap* bitmap = ref.getObject();
Bitmap* b = Bitmap::clone(bitmap);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(b, JIN_GRAPHICS_BITMAP));
+ proxy->bind(new Shared<Bitmap>(b, JIN_GRAPHICS_BITMAP));
return 1;
}
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
index f6834b1..87516b3 100644
--- a/src/lua/modules/graphics/je_lua_canvas.cpp
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -10,12 +10,12 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Canvas>& CanvasRef;
+ typedef Shared<Canvas>& CanvasRef;
LUA_IMPLEMENT inline CanvasRef checkCanvas(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- return proxy->getRef<Canvas>();
+ return proxy->getShared<Canvas>();
}
LUA_IMPLEMENT int l_getWidth(lua_State* L)
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 3befdde..639a542 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -165,7 +165,7 @@ namespace JinEngine
}
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
+ proxy->bind(new Shared<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
return 1;
}
@@ -176,7 +176,7 @@ namespace JinEngine
if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP))
{
Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- Ref<Bitmap>& refBitmap = p->getRef<Bitmap>();
+ Shared<Bitmap>& refBitmap = p->getShared<Bitmap>();
Bitmap* bitmap = refBitmap.getObject();
texture = Texture::createTexture(bitmap);
}
@@ -186,7 +186,7 @@ namespace JinEngine
texture = Texture::createTexture(path);
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
- proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE));
+ proxy->bind(new Shared<Texture>(texture, JIN_GRAPHICS_TEXTURE));
return 1;
}
@@ -201,7 +201,7 @@ namespace JinEngine
return 1;
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -225,7 +225,7 @@ namespace JinEngine
return 1;
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ proxy->bind(new Shared<Shader>(jsl, JIN_GRAPHICS_SHADER));
return 1;
}
@@ -235,7 +235,7 @@ namespace JinEngine
int h = luax_checknumber(L, 2);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
Canvas* cvs = Canvas::createCanvas(w, h);
- proxy->bind(new Ref<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
+ proxy->bind(new Shared<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
return 1;
}
@@ -283,7 +283,7 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
+ Shared<Texture>& tex = proxy->getShared<Texture>();
tex->render(x, y, sx, sy, r, ox, oy);
}
@@ -299,7 +299,7 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
p->render(x, y, sx, sy, r, ox, oy);
}
@@ -389,13 +389,13 @@ namespace JinEngine
if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
+ Shared<Texture>& tex = proxy->getShared<Texture>();
tex->render(q, x, y, sx, sy, r, ox, oy);
}
else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
p->render(q, x, y, sx, sy, r, ox, oy);
}
else
@@ -462,7 +462,7 @@ namespace JinEngine
return 0;
}
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& ref = proxy->getRef<Canvas>();
+ Shared<Canvas>& ref = proxy->getShared<Canvas>();
Canvas::bind(ref.getObject());
return 0;
}
@@ -483,7 +483,7 @@ namespace JinEngine
if (luax_istype(L, 1, JIN_GRAPHICS_SHADER))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Shader>& jsl = proxy->getRef<Shader>();
+ Shared<Shader>& jsl = proxy->getShared<Shader>();
jsl->use();
}
else
@@ -496,18 +496,10 @@ namespace JinEngine
LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
- return 0;
+ return 0;
}
- LUA_IMPLEMENT RenderMode strtomode(const char* str)
- {
- std::string s = std::string(str);
- if (s == "fill")
- return RenderMode::FILL;
- else if (s == "line")
- return RenderMode::LINE;
- else return RenderMode::NONE;
- }
+#define IntToRenderMode(I) static_cast<RenderMode>(I)
LUA_IMPLEMENT int l_point(lua_State* L)
{
@@ -531,8 +523,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_rect(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -552,8 +543,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_circle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -572,8 +562,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -598,9 +587,8 @@ namespace JinEngine
LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- int n = luax_checknumber(L, 2);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = IntToRenderMode(luax_checkinteger(L, 1));
+ int n = luax_checknumber(L, 2);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -648,7 +636,7 @@ namespace JinEngine
fs->read(path, b);
fd = TTFData::createTTFData(&b, b.size());
}
- proxy->bind(new Ref<TTFData>(fd, JIN_GRAPHICS_TTFDATA));
+ proxy->bind(new Shared<TTFData>(fd, JIN_GRAPHICS_TTFDATA));
return 1;
}
@@ -672,7 +660,7 @@ namespace JinEngine
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
- proxy->bind(new Ref<Text>(text, JIN_GRAPHICS_TEXT));
+ proxy->bind(new Shared<Text>(text, JIN_GRAPHICS_TEXT));
return 1;
}
@@ -724,7 +712,7 @@ namespace JinEngine
delete text;
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
- proxy->bind(new Ref<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
+ proxy->bind(new Shared<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
return 1;
}
@@ -810,7 +798,7 @@ namespace JinEngine
LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // register types
+ // Register types.
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -821,7 +809,7 @@ namespace JinEngine
luaopen_Page(L);
luaopen_JSL(L);
- // load whole lib
+ // Load whole lib.
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
index 36754a0..f3c2517 100644
--- a/src/lua/modules/graphics/je_lua_page.cpp
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -14,7 +14,7 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Font>& FontRef;
+ typedef Shared<Font>& FontRef;
Page* getPage(lua_State* L)
{
@@ -27,8 +27,8 @@ namespace JinEngine
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
{
/* release font */
- Ref<Page>* page = &proxy->getRef<Page>();
- RefBase* font = (RefBase*)page->getUserdata();
+ Shared<Page>* page = &proxy->getShared<Page>();
+ SharedBase* font = (SharedBase*)page->getUserdata();
font->release();
}
proxy->release();
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
index 9131815..e2e1413 100644
--- a/src/lua/modules/graphics/je_lua_shader.cpp
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -11,12 +11,12 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Shader>& ShaderRef;
+ typedef Shared<Shader>& ShaderRef;
static inline ShaderRef checkShader(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- return proxy->getRef<Shader>();
+ return proxy->getShared<Shader>();
}
/**
@@ -36,7 +36,7 @@ namespace JinEngine
ShaderRef ref = checkShader(L);
const char* variable = luax_checkstring(L, 2);
Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
- Ref<Texture>& tex = proxy->getRef<Texture>();
+ Shared<Texture>& tex = proxy->getShared<Texture>();
ref->sendTexture(variable, tex.getObject());
return 0;
}
@@ -46,7 +46,7 @@ namespace JinEngine
ShaderRef ref = checkShader(L);
const char* variable = luax_checkstring(L, 2);
Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& canvas = proxy->getRef<Canvas>();
+ Shared<Canvas>& canvas = proxy->getShared<Canvas>();
ref->sendCanvas(variable, canvas.getObject());
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
index 0ab79b5..a643dae 100644
--- a/src/lua/modules/graphics/je_lua_texture.cpp
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -10,12 +10,12 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Texture>& TextureRef;
+ typedef Shared<Texture>& TextureRef;
LUA_IMPLEMENT inline TextureRef checkTexture(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- return proxy->getRef<Texture>();
+ return proxy->getShared<Texture>();
}
LUA_IMPLEMENT int l_getWidth(lua_State* L)
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index ba0a504..58011a7 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -40,10 +40,10 @@ namespace JinEngine
page = tf->typeset(*text, lineheight, spacing);
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
+ Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
{
/* retain related ttf */
- Ref<TextureFont>& refTF = p->getRef<TextureFont>();
+ Shared<TextureFont>& refTF = p->getShared<TextureFont>();
refTF.retain();
refPage->setUserdata(&refTF);
}
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index 49f13c0..4c56ae1 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -16,8 +16,8 @@ namespace JinEngine
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
{
/* release ttf data */
- Ref<TTF>* ttf = &proxy->getRef<TTF>();
- RefBase* data = (RefBase*)ttf->getUserdata();
+ Shared<TTF>* ttf = &proxy->getShared<TTF>();
+ SharedBase* data = (SharedBase*)ttf->getUserdata();
data->release();
}
proxy->release();
@@ -46,10 +46,10 @@ namespace JinEngine
page = ttf->typeset(*text, lineheight, spacing);
}
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
+ Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
{
/* retain related ttf */
- Ref<TTF>& refTTF = p->getRef<TTF>();
+ Shared<TTF>& refTTF = p->getShared<TTF>();
refTTF.retain();
refPage->setUserdata(&refTTF);
}
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
index 4212778..d076ab8 100644
--- a/src/lua/modules/graphics/je_lua_ttf_data.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -15,13 +15,13 @@ namespace JinEngine
{
Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
int fontsize = luax_checkinteger(L, 2);
- Ref<TTFData>& refFontData = p->getRef<TTFData>();
+ Shared<TTFData>& refFontData = p->getShared<TTFData>();
TTFData* fontData = refFontData.getObject();
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTF, sizeof(Proxy));
TTF* font = fontData->createTTF(fontsize);
- Ref<TTF>* refTTF = new Ref<TTF>(font, JIN_GRAPHICS_TTF);
+ Shared<TTF>* refTTF = new Shared<TTF>(font, JIN_GRAPHICS_TTF);
{
- Ref<TTFData>& refTTFData = p->getRef<TTFData>();
+ Shared<TTFData>& refTTFData = p->getShared<TTFData>();
refTTFData.retain();
refTTF->setUserdata(&refTTFData);
}
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
index 9e769e8..4c6880a 100644
--- a/src/lua/modules/net/je_lua_buffer.cpp
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -11,12 +11,12 @@ namespace JinEngine
namespace Net
{
- typedef Ref<Buffer>& BufferRef;
+ typedef Shared<Buffer>& BufferRef;
static inline BufferRef checkNetBuffer(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
+ return proxy->getShared<Buffer>();
}
// net.Buffer:append(value) -> value_length
diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp
index de5d506..cd454d5 100644
--- a/src/lua/modules/net/je_lua_net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -49,7 +49,7 @@ namespace Lua
}
Socket* socket = new Socket(info);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(socket, JIN_NETWORK_SOCKET));
+ proxy->bind(new Shared<Socket>(socket, JIN_NETWORK_SOCKET));
return 1;
}
@@ -58,7 +58,7 @@ namespace Lua
int size = luax_checkinteger(L, 1);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
Net::Buffer* buffer = new Net::Buffer(size);
- proxy->bind(new Ref<Buffer>(buffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(buffer, JIN_NETWORK_BUFFER));
return 1;
}
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
index d68cb51..0b59199 100644
--- a/src/lua/modules/net/je_lua_socket.cpp
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -12,20 +12,20 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Socket>& SocketRef;
+ typedef Shared<Socket>& SocketRef;
const int BUFFER_SIZE = 1024;
LUA_IMPLEMENT inline SocketRef checkSocket(lua_State* L, int pos = 1)
{
Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
- return proxy->getRef<Socket>();
+ return proxy->getShared<Socket>();
}
- LUA_IMPLEMENT inline Ref<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
+ LUA_IMPLEMENT inline Shared<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
{
Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
+ return proxy->getShared<Buffer>();
}
// return net.Socket
@@ -34,7 +34,7 @@ namespace JinEngine
SocketRef socket = checkSocket(L);
Socket* client = socket->accept();
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(client, JIN_NETWORK_SOCKET));
+ proxy->bind(new Shared<Socket>(client, JIN_NETWORK_SOCKET));
return 1;
}
@@ -46,7 +46,7 @@ namespace JinEngine
int size = socket->receive(buffer, BUFFER_SIZE);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
return 1;
}
@@ -60,7 +60,7 @@ namespace JinEngine
int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
return 1;
}
@@ -68,7 +68,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_send(lua_State* L)
{
SocketRef socket = checkSocket(L);
- Ref<Buffer>& ref = checkNetBuffer(L, 2);
+ Shared<Buffer>& ref = checkNetBuffer(L, 2);
int len = socket->send(ref->buffer, ref->size);
luax_pushinteger(L, len);
return 1;
@@ -80,7 +80,7 @@ namespace JinEngine
SocketRef socket = checkSocket(L);
int address = luax_checkinteger(L, 2);
int port = luax_checkinteger(L, 3);
- Ref<Buffer>& buffer = checkNetBuffer(L, 4);
+ Shared<Buffer>& buffer = checkNetBuffer(L, 4);
socket->sendTo(buffer->buffer, buffer->size, address, port);
return 0;
}
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
index 5babc13..ab03561 100644
--- a/src/lua/modules/thread/je_lua_thread.cpp
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -10,19 +10,19 @@ namespace JinEngine
namespace Lua
{
- typedef Ref<Thread>& ThreadRef;
+ typedef Shared<Thread>& ThreadRef;
int luaopen_thread(lua_State* L);
static inline ThreadRef checkThread(lua_State* L)
{
Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- return proxy->getRef<Thread>();
+ return proxy->getShared<Thread>();
}
LUA_IMPLEMENT int threadRunner(void* t)
{
- ThreadRef ref = *(Ref<Thread>*)t;
+ ThreadRef ref = *(Shared<Thread>*)t;
lua_State* L = lua_open();
luax_openlibs(L);
luaopen_jin(L);
@@ -126,8 +126,8 @@ namespace JinEngine
case Thread::Variant::POINTER:
Proxy* p = (Proxy*)v.pointer;
Proxy* proxy = (Proxy*)luax_newinstance(L, p->getObjectType(), sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
+ p->shared->retain();
+ proxy->bind(p->shared);
break;
}
@@ -161,8 +161,8 @@ namespace JinEngine
Proxy* p = (Proxy*)v.pointer;
const char* objType = p->getObjectType();
Proxy* proxy = (Proxy*)luax_newinstance(L, objType, sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
+ p->retain();
+ proxy->bind(p->shared);
break;
}
@@ -220,7 +220,7 @@ namespace JinEngine
const char* code = luax_checkstring(L, 2);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy));
Thread* thread = new Thread(name, code, threadRunner);
- proxy->bind(new Ref<Thread>(thread, JIN_THREAD_THREAD));
+ proxy->bind(new Shared<Thread>(thread, JIN_THREAD_THREAD));
return 1;
}
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
new file mode 100644
index 0000000..c28aafe
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -0,0 +1,30 @@
+#include "../types.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_timer.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ typedef Shared<Timer>& TimerRef;
+
+ LUA_IMPLEMENT inline TimerRef checkTimer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_TIME_TIMER);
+ return proxy->getShared<Timer>();
+ }
+
+ LUA_IMPLEMENT int l_every(lua_State* L)
+ {
+ //TimerRef ref = checkTimer(L);
+ //Timer* timer = ref.getObject();
+ //int n = luax_checkinteger(L, 1);
+ //int ref = luax_ref(L, 2);
+ //timer->every(n, [](void* data)->void {
+ //
+ //}, );
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_timer.h b/src/lua/modules/time/je_lua_timer.h
new file mode 100644
index 0000000..9beadf5
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.h
@@ -0,0 +1,19 @@
+#ifndef __JE_LUA_TIMER_H__
+#define __JE_LUA_TIMER_H__
+
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ class Timer : public JinEngine::Time::Timer
+ {
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
index 123604e..c6600dc 100644
--- a/src/lua/modules/types.h
+++ b/src/lua/modules/types.h
@@ -22,4 +22,7 @@
#define JIN_NETWORK_SOCKET "Socket"
#define JIN_NETWORK_BUFFER "Buffer"
+// time module
+#define JIN_TIME_TIMER "Timer"
+
#endif \ No newline at end of file