aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/audio/luaopen_Source.cpp1
-rw-r--r--src/lua/modules/audio/luaopen_audio.cpp1
-rw-r--r--src/lua/modules/embed/boot.lua.h32
-rw-r--r--src/lua/modules/graphics/luaopen_Canvas.cpp1
-rw-r--r--src/lua/modules/graphics/luaopen_Font.cpp1
-rw-r--r--src/lua/modules/graphics/luaopen_Image.cpp1
-rw-r--r--src/lua/modules/graphics/luaopen_JSL.cpp1
-rw-r--r--src/lua/modules/graphics/luaopen_graphics.cpp79
-rw-r--r--src/lua/modules/net/luaopen_Buffer.cpp1
-rw-r--r--src/lua/modules/net/luaopen_Socket.cpp1
-rw-r--r--src/lua/modules/net/luaopen_net.cpp3
-rw-r--r--src/lua/modules/thread/luaopen_thread.cpp1
-rw-r--r--src/lua/modules/types.h20
13 files changed, 103 insertions, 40 deletions
diff --git a/src/lua/modules/audio/luaopen_Source.cpp b/src/lua/modules/audio/luaopen_Source.cpp
index 4c98ead..1953121 100644
--- a/src/lua/modules/audio/luaopen_Source.cpp
+++ b/src/lua/modules/audio/luaopen_Source.cpp
@@ -1,6 +1,7 @@
#include "libjin/jin.h"
#include "lua/modules/luax.h"
#include "lua/common/common.h"
+#include "lua/modules/types.h"
namespace jin
{
diff --git a/src/lua/modules/audio/luaopen_audio.cpp b/src/lua/modules/audio/luaopen_audio.cpp
index 1c44374..8e11b88 100644
--- a/src/lua/modules/audio/luaopen_audio.cpp
+++ b/src/lua/modules/audio/luaopen_audio.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
diff --git a/src/lua/modules/embed/boot.lua.h b/src/lua/modules/embed/boot.lua.h
index 32d3e1d..42f38d8 100644
--- a/src/lua/modules/embed/boot.lua.h
+++ b/src/lua/modules/embed/boot.lua.h
@@ -4,6 +4,10 @@ jin._argv[2] = jin._argv[2] or '.'
jin.filesystem.init()
jin.filesystem.mount(jin._argv[2])
+-------------------------------------------------------------------------
+-- Config game
+-------------------------------------------------------------------------
+
local conf = {}
if jin.filesystem.exist("config.lua") then
conf = require "config"
@@ -16,7 +20,10 @@ conf.title = conf.title or ("jin v" .. jin.version())
conf.resizable = conf.resizable or false
conf.fullscreen = conf.fullscreen or false
--- initialize subsystems
+-------------------------------------------------------------------------
+-- Initialize sub systems
+-------------------------------------------------------------------------
+
jin.graphics.init(conf)
jin.audio.init()
@@ -57,10 +64,10 @@ function jin.core.run()
call(jin.core.onUpdate, dt)
- jin.graphics.unbind()
+ jin.graphics.unbindCanvas()
jin.graphics.clear()
- jin.graphics.color()
- jin.graphics.study()
+ jin.graphics.setColor()
+ jin.graphics.setFont()
call(jin.core.onDraw)
jin.graphics.present()
@@ -85,16 +92,16 @@ local function onError(msg)
jin.core.stop()
end
end
- local ww, wh = jin.graphics.size()
+ local ww, wh = jin.graphics.getSize()
function jin.core.onDraw()
jin.graphics.write("Error: ", 10, 10, 30, 3, 30)
jin.graphics.write(msg, 10, 50)
end
end
--------------------------------------------------------------------------------
+-------------------------------------------------------------------------
-- No game handler
--------------------------------------------------------------------------------
+-------------------------------------------------------------------------
jin.nogame = {
cs = 64,
@@ -131,7 +138,12 @@ jin.nogame = {
end
r = math.sin((r/nogame.ww)*math.pi)*nogame.cs/2
local fact = (x + y) / nogame.ch * nogame.cw
- jin.graphics.color(155 + 100 * math.sin(fact), 155 + 100 * math.cos(fact), 155 + 100 * math.sin(fact * fact), 255)
+ jin.graphics.setColor(
+ 155 + 100 * math.sin(fact),
+ 155 + 100 * math.cos(fact),
+ 155 + 100 * math.sin(fact * fact),
+ 255
+ )
jin.graphics.circle("fill", x*nogame.cs + nogame.cs/2, y*nogame.cs + nogame.cs/2, r)
end,
onDraw = function()
@@ -144,9 +156,9 @@ jin.nogame = {
end
}
--------------------------------------------------------------------------------
+-------------------------------------------------------------------------
-- Boot jin
--------------------------------------------------------------------------------
+-------------------------------------------------------------------------
local function boot()
if jin.filesystem.exist("main.lua") then
diff --git a/src/lua/modules/graphics/luaopen_Canvas.cpp b/src/lua/modules/graphics/luaopen_Canvas.cpp
index d94e578..f42dfba 100644
--- a/src/lua/modules/graphics/luaopen_Canvas.cpp
+++ b/src/lua/modules/graphics/luaopen_Canvas.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
diff --git a/src/lua/modules/graphics/luaopen_Font.cpp b/src/lua/modules/graphics/luaopen_Font.cpp
index c5789ad..926f2cc 100644
--- a/src/lua/modules/graphics/luaopen_Font.cpp
+++ b/src/lua/modules/graphics/luaopen_Font.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
diff --git a/src/lua/modules/graphics/luaopen_Image.cpp b/src/lua/modules/graphics/luaopen_Image.cpp
index 0f68873..5824660 100644
--- a/src/lua/modules/graphics/luaopen_Image.cpp
+++ b/src/lua/modules/graphics/luaopen_Image.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
diff --git a/src/lua/modules/graphics/luaopen_JSL.cpp b/src/lua/modules/graphics/luaopen_JSL.cpp
index c7a257a..ccd9ebd 100644
--- a/src/lua/modules/graphics/luaopen_JSL.cpp
+++ b/src/lua/modules/graphics/luaopen_JSL.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
diff --git a/src/lua/modules/graphics/luaopen_graphics.cpp b/src/lua/modules/graphics/luaopen_graphics.cpp
index f0a7f5b..9c1d404 100644
--- a/src/lua/modules/graphics/luaopen_graphics.cpp
+++ b/src/lua/modules/graphics/luaopen_graphics.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "libjin/jin.h"
#include "lua/common/common.h"
#include "lua/modules/embed/graphics.lua.h"
@@ -16,6 +17,7 @@ namespace lua
static struct
{
color curRenderColor;
+ color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
} context;
@@ -123,6 +125,26 @@ namespace lua
return 0;
}
+ static int l_setClearColor(lua_State* L)
+ {
+ if (luax_gettop(L) == 0)
+ {
+ glClearColor(1, 1, 1, 1);
+ return 0;
+ }
+
+ context.curClearColor.rgba.r = luax_checknumber(L, 1);
+ context.curClearColor.rgba.g = luax_checknumber(L, 2);
+ context.curClearColor.rgba.b = luax_checknumber(L, 3);
+ context.curClearColor.rgba.a = luax_checknumber(L, 4);
+
+ glClearColor(context.curClearColor.rgba.r / 255.f,
+ context.curClearColor.rgba.g / 255.f,
+ context.curClearColor.rgba.b / 255.f,
+ context.curClearColor.rgba.a / 255.f);
+ return 0;
+ }
+
static int l_present(lua_State* L)
{
Window::get()->swapBuffers();
@@ -440,34 +462,35 @@ namespace lua
}
static const luaL_Reg f[] = {
- { "init", l_init },
- { "size", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "newImage", l_newImage },
- { "newShader", l_newShader },
- { "newCanvas", l_newCanvas },
- { "newFont", l_newFont },
- { "box", l_box },
- { "write", l_write },
- { "clear", l_clear },
- { "draw", l_draw },
- { "color", l_setColor },
- { "palette", l_getColor },
- { "present", l_present },
- { "study", l_study },
- { "bind", l_bindCanvas },
- { "unbind", l_unbindCanvas },
- { "use", l_useShader },
- { "unuse", l_unuseShader },
- { "point", l_drawpoint },
- { "line", l_drawLine },
- { "rect", l_drawRect },
- { "circle", l_drawCircle },
- { "triangle", l_drawTriangle },
- { "polygon", l_drawPolygon },
- { "destroy", l_destroy },
- { 0, 0 }
+ { "init", l_init },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "newImage", l_newImage },
+ { "newShader", l_newShader },
+ { "newCanvas", l_newCanvas },
+ { "newFont", l_newFont },
+ { "box", l_box },
+ { "write", l_write },
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "setColor", l_setColor },
+ { "palette", l_getColor },
+ { "present", l_present },
+ { "setFont", l_study },
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ { "useShader", l_useShader },
+ { "unuseShader", l_unuseShader },
+ { "point", l_drawpoint },
+ { "line", l_drawLine },
+ { "rect", l_drawRect },
+ { "circle", l_drawCircle },
+ { "triangle", l_drawTriangle },
+ { "polygon", l_drawPolygon },
+ { "destroy", l_destroy },
+ { 0, 0 }
};
extern int luaopen_Image(lua_State* L);
diff --git a/src/lua/modules/net/luaopen_Buffer.cpp b/src/lua/modules/net/luaopen_Buffer.cpp
index cb5b952..3354518 100644
--- a/src/lua/modules/net/luaopen_Buffer.cpp
+++ b/src/lua/modules/net/luaopen_Buffer.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
#include "Buffer.h"
diff --git a/src/lua/modules/net/luaopen_Socket.cpp b/src/lua/modules/net/luaopen_Socket.cpp
index 2e5d9f3..6d3fdfb 100644
--- a/src/lua/modules/net/luaopen_Socket.cpp
+++ b/src/lua/modules/net/luaopen_Socket.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "lua/common/common.h"
#include "libjin/jin.h"
#include "Buffer.h"
diff --git a/src/lua/modules/net/luaopen_net.cpp b/src/lua/modules/net/luaopen_net.cpp
index e7e55c4..a984920 100644
--- a/src/lua/modules/net/luaopen_net.cpp
+++ b/src/lua/modules/net/luaopen_net.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "libjin/jin.h"
#include "lua/common/common.h"
#include "Buffer.h"
@@ -16,7 +17,6 @@ namespace lua
return 1;
}
- // jin.net.Socket()
static int l_Socket(lua_State* L)
{
SocketInformation info = { 0 };
@@ -52,7 +52,6 @@ namespace lua
return 1;
}
- // jin.net.Buffer()
static int l_Buffer(lua_State* L)
{
int size = luax_checkinteger(L, 1);
diff --git a/src/lua/modules/thread/luaopen_thread.cpp b/src/lua/modules/thread/luaopen_thread.cpp
index 65a7c29..d581f54 100644
--- a/src/lua/modules/thread/luaopen_thread.cpp
+++ b/src/lua/modules/thread/luaopen_thread.cpp
@@ -1,4 +1,5 @@
#include "lua/modules/luax.h"
+#include "lua/modules/types.h"
#include "libjin/jin.h"
#include "lua/modules/luaopen_jin.h"
#include "lua/common/common.h"
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
new file mode 100644
index 0000000..318f5fa
--- /dev/null
+++ b/src/lua/modules/types.h
@@ -0,0 +1,20 @@
+#ifndef __JIN_MODULES_TYPES_H
+#define __JIN_MODULES_TYPES_H
+
+// graphics module
+#define JIN_GRAPHICS_IMAGE "jin.graphics.Image"
+#define JIN_GRAPHICS_SHADER "jin.graphics.Shader"
+#define JIN_GRAPHICS_CANVAS "jin.graphics.Canvas"
+#define JIN_GRAPHICS_FONT "jin.graphics.Font"
+
+// audio module
+#define JIN_AUDIO_SOURCE "jin.Audio.Source"
+
+// thread module
+#define JIN_THREAD_THREAD "jin.thread.Thread"
+
+// network module
+#define JIN_NETWORK_SOCKET "jin.net.Socket"
+#define JIN_NETWORK_BUFFER "jin.net.Buffer"
+
+#endif \ No newline at end of file