aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-02 18:44:15 +0800
committerchai <chaifix@163.com>2018-09-02 18:44:15 +0800
commit4f147c08fc5498af393729c5e4a3d91894c97467 (patch)
tree0a00c636b84238d60bd4535dc988591e24d15458 /src
parent6d67345bd5ddea7a4ce37e6bbeda15d341b1ee82 (diff)
*update
Diffstat (limited to 'src')
-rw-r--r--src/libjin/Filesystem/Filesystem.cpp9
-rw-r--r--src/libjin/Filesystem/Filesystem.h2
-rw-r--r--src/libjin/Graphics/Window.cpp5
-rw-r--r--src/libjin/Graphics/Window.h1
-rw-r--r--src/lua/modules/embed/embed.h17
-rw-r--r--src/lua/modules/filesystem/filesystem.cpp60
-rw-r--r--src/lua/modules/graphics/graphics.cpp14
-rw-r--r--src/lua/modules/keyboard/keyboard.cpp1
-rw-r--r--src/lua/modules/mouse/mouse.cpp12
9 files changed, 77 insertions, 44 deletions
diff --git a/src/libjin/Filesystem/Filesystem.cpp b/src/libjin/Filesystem/Filesystem.cpp
index 8089c9d..3f91274 100644
--- a/src/libjin/Filesystem/Filesystem.cpp
+++ b/src/libjin/Filesystem/Filesystem.cpp
@@ -34,8 +34,13 @@ namespace filesystem
{
buffer->data = smtread(S, path, &buffer->size);
if (buffer->data == 0)
- return 0;
- return 1;
+ return 0;
+ return 1;
+ }
+
+ void* Filesystem::read(const char* path, unsigned int* len)
+ {
+ return smtread(S, path, len);
}
const char* Filesystem::getFull(const char* path)
diff --git a/src/libjin/Filesystem/Filesystem.h b/src/libjin/Filesystem/Filesystem.h
index f2e39af..17b3e0b 100644
--- a/src/libjin/Filesystem/Filesystem.h
+++ b/src/libjin/Filesystem/Filesystem.h
@@ -12,11 +12,11 @@ namespace filesystem
static Filesystem* get();
Filesystem();
-
bool isDir(const char* path);
bool isFile(const char* path);
bool exists(const char* path);
int read(const char* path, Buffer* buffer);
+ void* read(const char* path, unsigned int* len);
void mount(const char* root);
const char* getFull(const char* path);
diff --git a/src/libjin/Graphics/Window.cpp b/src/libjin/Graphics/Window.cpp
index 4e168dc..ede202e 100644
--- a/src/libjin/Graphics/Window.cpp
+++ b/src/libjin/Graphics/Window.cpp
@@ -91,6 +91,11 @@ namespace graphics
SDL_GL_SwapWindow(wnd);
}
+ void Window::setTitle(const char* title)
+ {
+ SDL_SetWindowTitle(wnd, title);
+ };
+
} // graphics
} // jin
diff --git a/src/libjin/Graphics/Window.h b/src/libjin/Graphics/Window.h
index 4617ef8..23b932d 100644
--- a/src/libjin/Graphics/Window.h
+++ b/src/libjin/Graphics/Window.h
@@ -27,6 +27,7 @@ namespace graphics
bool resizable; // resize
};
+ void setTitle(const char* title);
inline int getW(){ return size.x; }
inline int getH(){ return size.y; }
inline int getFPS(){ return fps; }
diff --git a/src/lua/modules/embed/embed.h b/src/lua/modules/embed/embed.h
index 6393454..8d0ba85 100644
--- a/src/lua/modules/embed/embed.h
+++ b/src/lua/modules/embed/embed.h
@@ -22,21 +22,20 @@ namespace embed
static void boot(lua_State* L)
{
// embed scripts
- #include "graphics.lua.h" // graphics
- #include "keyboard.lua.h" // keyboard
- #include "mouse.lua.h" // mouse
- #include "boot.lua.h" // boot
+ #include "graphics.lua.h"
+ #include "keyboard.lua.h"
+ #include "mouse.lua.h"
+ #include "boot.lua.h"
- // embed scripts
+ // in order
const jin_Embed scripts[] = {
{ "graphics.lua", graphics_lua },
{ "keyboard.lua", keyboard_lua },
- { "mouse.lua", mouse_lua },
- { "boot.lua", boot_lua },
- { 0, 0 }
+ { "mouse.lua", mouse_lua },
+ { "boot.lua", boot_lua },
+ { 0, 0 }
};
- // load all emebd lua scripts
for (int i = 0; scripts[i].file; ++i)
embed(L, scripts[i].source, scripts[i].file);
}
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp
index 55f4c06..e1d496e 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/filesystem.cpp
@@ -20,10 +20,6 @@ namespace lua
return 0;
}
- /**
- * set current game root, like
- * C:/jin/games/tank/
- */
static int l_mount(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
@@ -31,38 +27,31 @@ namespace lua
return 0;
}
- /**
- *
- */
- static int l_isDir(lua_State *L)
+ static int l_exist(lua_State * L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->isDir(path);
- luax_pushboolean(L, r);
- return 1;
+ int r = context.fs->exists(path);
+ luax_pushboolean(L, r);
+ return 1;
}
- /**
- *
- */
- static int l_exist(lua_State * L)
+ static int l_isDir(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->exists(path);
+ int r = context.fs->isDir(path);
luax_pushboolean(L, r);
return 1;
}
- static int l_isdir(lua_State* L)
+ static int l_isFile(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
- int r = context.fs->isDir(path);
+ int r = context.fs->isFile(path);
luax_pushboolean(L, r);
return 1;
}
- // load but dont run it
- static int loadf(lua_State* L)
+ static int loadbuffer(lua_State* L)
{
const char* filename = lua_tostring(L, -1);
Buffer bf;
@@ -92,7 +81,7 @@ namespace lua
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
- return loadf(L);
+ return loadbuffer(L);
}
tmp = filename;
@@ -110,7 +99,7 @@ namespace lua
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
- return loadf(L);
+ return loadbuffer(L);
}
}
@@ -118,12 +107,25 @@ namespace lua
return 1;
}
+ static int l_read(lua_State* L)
+ {
+ Filesystem* fs = context.fs;
+ const char* file = luax_checkstring(L, 1);
+ unsigned int len;
+ char* data = (char*)fs->read(file, &len);
+ luax_pushstring(L, data);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
static const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isdir", l_isDir },
- { "exist", l_exist },
- { 0, 0 }
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDir", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
};
int luaopen_filesystem(lua_State* L)
@@ -133,5 +135,5 @@ namespace lua
return 0;
}
-}
-} \ No newline at end of file
+} // filesystem
+} // jin \ No newline at end of file
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index cd79211..fadc59d 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -42,6 +42,14 @@ namespace lua
return 1;
}
+ static int l_setTitle(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ const char* title = luax_checkstring(L, 1);
+ wnd->setTitle(title);
+ return 0;
+ }
+
static int l_destroy(lua_State* L)
{
Window* wnd = Window::get();
@@ -189,7 +197,10 @@ namespace lua
context.curRenderColor.rgba.r = luax_checknumber(L, 1);
context.curRenderColor.rgba.g = luax_checknumber(L, 2);
context.curRenderColor.rgba.b = luax_checknumber(L, 3);
- context.curRenderColor.rgba.a = luax_checknumber(L, 4);
+ if (luax_gettop(L) == 4)
+ context.curRenderColor.rgba.a = luax_checknumber(L, 4);
+ else
+ context.curClearColor.rgba.a = 255;
glColor4f(context.curRenderColor.rgba.r / 255.f,
context.curRenderColor.rgba.g / 255.f,
@@ -463,6 +474,7 @@ namespace lua
static const luaL_Reg f[] = {
{ "init", l_init },
+ { "setTitle", l_setTitle },
{ "getSize", l_getSize },
{ "getWidth", l_getWidth },
{ "getHeight", l_getHeight },
diff --git a/src/lua/modules/keyboard/keyboard.cpp b/src/lua/modules/keyboard/keyboard.cpp
index 9d27a4f..0df9562 100644
--- a/src/lua/modules/keyboard/keyboard.cpp
+++ b/src/lua/modules/keyboard/keyboard.cpp
@@ -5,6 +5,7 @@ namespace jin
{
namespace lua
{
+ //https://wiki.libsdl.org/SDL_Keycode
int luaopen_keyboard(lua_State* L)
{
diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/mouse.cpp
index f907abb..b7ce933 100644
--- a/src/lua/modules/mouse/mouse.cpp
+++ b/src/lua/modules/mouse/mouse.cpp
@@ -17,9 +17,17 @@ namespace lua
return 2;
}
+ static int l_setVisible(lua_State* L)
+ {
+ bool visible = luax_checkbool(L, 1);
+ SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
+ return 0;
+ }
+
static const luaL_Reg f[] = {
- { "position", l_pos },
- { 0, 0 }
+ { "position", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
};
int luaopen_mouse(lua_State* L)