aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/client/config.lua8
-rw-r--r--bin/client/main.lua43
-rw-r--r--bin/jin.exebin651776 -> 1680384 bytes
-rw-r--r--bin/main.lua40
-rw-r--r--build/vs2015/jin.rcbin3330 -> 3268 bytes
-rw-r--r--build/vs2015/jin.vcxproj3
-rw-r--r--build/vs2015/jin.vcxproj.filters6
-rw-r--r--src/lua/bit/luaopen_bit.cpp2
-rw-r--r--src/lua/embed/boot.lua16
-rw-r--r--src/lua/graphics/Canvas.h1
-rw-r--r--src/lua/graphics/Image.h12
-rw-r--r--src/lua/graphics/JSL.h2
-rw-r--r--src/lua/luaopen_types.h20
-rw-r--r--src/lua/thread/luaopen_Thread.cpp2
-rw-r--r--src/lua/thread/luaopen_thread.cpp2
15 files changed, 75 insertions, 82 deletions
diff --git a/bin/client/config.lua b/bin/client/config.lua
deleted file mode 100644
index 3e696b8..0000000
--- a/bin/client/config.lua
+++ /dev/null
@@ -1,8 +0,0 @@
-return
-{
- width = 512,
- height = 400,
- fullscreen = false,
- resizable = true,
- title = "Jin Modules"
-}
diff --git a/bin/client/main.lua b/bin/client/main.lua
deleted file mode 100644
index 5a036e8..0000000
--- a/bin/client/main.lua
+++ /dev/null
@@ -1,43 +0,0 @@
-io.stdout:setvbuf("no")
-local thread = nil
-local socket = nil
-local asynReceive = [[
-io.stdout:setvbuf("no")
-local thread = jin.thread.getThread()
-local socket = thread:demand(1)
-local buf = nil
-while true do
- buf = socket:receive()
- thread:send(2, buf)
-end
-]]
-jin.core.onLoad = function()
- jin.net.init()
- socket = jin.net.Socket("TCP", "127.0.0.1", 8708)
-
- thread = jin.thread.Thread("asynReceive", asynReceive)
- thread:start()
- thread:send(1, socket)
-end
-
-jin.core.onEvent = function(e)
- if e.type == "quit" then
- jin.core.stop() elseif e.type == "keydown" then
- if e.key == "Escape" then
- jin.core.stop()
- end
- end
-end
-local x = 0
-local y = 0
-jin.core.onUpdate = function(dt)
- if thread:receive(2) then
- local buf = thread:fetch(2)
- x, xl = buf:grabFloat(0)
- y, yl = buf:grabFloat(xl)
- end
-end
-
-jin.core.onDraw = function()
- jin.graphics.circle("fill", x, y, 12)
-end
diff --git a/bin/jin.exe b/bin/jin.exe
index 839622b..43703b7 100644
--- a/bin/jin.exe
+++ b/bin/jin.exe
Binary files differ
diff --git a/bin/main.lua b/bin/main.lua
index b7f7124..bd2c011 100644
--- a/bin/main.lua
+++ b/bin/main.lua
@@ -1,3 +1,41 @@
-require "client.main"
+local loadAssets = [[
+local thread = jin.thread.getThread()
+local path = thread:demand(1)
+local img = jin.graphics.Image(path)
+thread:send(2, img)
+while(true) do
+ if(thread:receive(255)) then
+ break; -- quit thread
+ end
+end
+]]
+local img = nil
+local loader = nil
+jin.core.onLoad = function()
+ loader = jin.thread.Thread("load assets", loadAssets)
+ loader:start()
+ loader:send(1, "./icon.png")
+ --img = jin.graphics.Image("./icon.png")
+end
+
+jin.core.onEvent = function(e)
+ if e.type == "quit" then
+ jin.core.stop()
+ end
+end
+
+jin.core.onUpdate = function(dt)
+ if loader:receive(2) and img == nil then
+ img = loader:fetch(2)
+ loader:send(255, 1)
+ loader:remove(2)
+ end
+end
+
+jin.core.onDraw = function()
+ if img ~= nil then
+ jin.graphics.draw(img, 20, 20)
+ end
+end
diff --git a/build/vs2015/jin.rc b/build/vs2015/jin.rc
index d452afb..6fcc3a7 100644
--- a/build/vs2015/jin.rc
+++ b/build/vs2015/jin.rc
Binary files differ
diff --git a/build/vs2015/jin.vcxproj b/build/vs2015/jin.vcxproj
index b6dd7ab..6a9bff6 100644
--- a/build/vs2015/jin.vcxproj
+++ b/build/vs2015/jin.vcxproj
@@ -85,6 +85,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)..\..\src\;$(SolutionDir)libs\SDL2-2.0.5\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAs>CompileAsCpp</CompileAs>
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
</ClCompile>
<Link>
<AdditionalDependencies>opengl32.lib;glu32.lib;SDL2main.lib;SDL2.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -119,7 +120,7 @@
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opengl32.lib;glu32.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)libs\SDL2-2.0.5\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <SubSystem>Windows</SubSystem>
+ <SubSystem>Console</SubSystem>
<EntryPointSymbol>
</EntryPointSymbol>
</Link>
diff --git a/build/vs2015/jin.vcxproj.filters b/build/vs2015/jin.vcxproj.filters
index 3da7d4b..d1c7370 100644
--- a/build/vs2015/jin.vcxproj.filters
+++ b/build/vs2015/jin.vcxproj.filters
@@ -261,9 +261,6 @@
<ClCompile Include="..\..\src\lua\filesystem\luaopen_filesystem.cpp">
<Filter>src\lua\filesystem</Filter>
</ClCompile>
- <ClCompile Include="..\..\src\lua\graphics\luaopen_Canvas.cpp">
- <Filter>src\lua\graphics</Filter>
- </ClCompile>
<ClCompile Include="..\..\src\lua\graphics\luaopen_Font.cpp">
<Filter>src\lua\graphics</Filter>
</ClCompile>
@@ -420,6 +417,9 @@
<ClCompile Include="..\..\src\lua\thread\Thread.cpp">
<Filter>src\lua\thread</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\lua\graphics\luaopen_Canvas.cpp">
+ <Filter>src\lua\graphics</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\3rdparty\lua51\lapi.h">
diff --git a/src/lua/bit/luaopen_bit.cpp b/src/lua/bit/luaopen_bit.cpp
index 9610a84..9520909 100644
--- a/src/lua/bit/luaopen_bit.cpp
+++ b/src/lua/bit/luaopen_bit.cpp
@@ -71,8 +71,6 @@ namespace lua
{ "bRs", l_rshift },
{ "bInc", l_include },
- // , offset
-
{ 0, 0 }
};
diff --git a/src/lua/embed/boot.lua b/src/lua/embed/boot.lua
index 6869ac8..e649737 100644
--- a/src/lua/embed/boot.lua
+++ b/src/lua/embed/boot.lua
@@ -1,4 +1,3 @@
-
jin._argv[2] = jin._argv[2] or '.'
jin.filesystem.init()
jin.filesystem.mount(jin._argv[2])
@@ -28,13 +27,14 @@ local function safecall(func, ...)
if func then
func(...)
end
-end
+end
function jin.core.run()
- safecall(jin.core.load)
+ safecall(jin.core.onLoad)
local previous = jin.time.second()
local SEC_PER_UPDATE = 1 / conf.fps
local dt = SEC_PER_UPDATE
+ local running = true
while(jin.core.running()) do
for _, e in pairs(jin.event.poll()) do
if e.type == "keydown" then
@@ -43,10 +43,10 @@ function jin.core.run()
jin.keyboard.set(e.key, false)
end
safecall(jin.core.onEvent, e)
+ running = jin.core.running()
+ if not running then break end
end
- if not jin.core.running() then
- break
- end
+ if not running then break end
safecall(jin.core.onUpdate, dt)
@@ -88,7 +88,7 @@ local function onError(msg)
end
end
-local function main()
+local function boot()
if jin.filesystem.exist("main.lua") then
-- require main game script
xpcall(function() require"main" end, onError)
@@ -115,4 +115,4 @@ local function main()
jin.core.quit()
end
-main()
+boot()
diff --git a/src/lua/graphics/Canvas.h b/src/lua/graphics/Canvas.h
index d2c9287..4494db4 100644
--- a/src/lua/graphics/Canvas.h
+++ b/src/lua/graphics/Canvas.h
@@ -44,6 +44,7 @@ namespace graphics
static void unbind();
private:
+ Canvas() {}
~Canvas()
{
delete canvas;
diff --git a/src/lua/graphics/Image.h b/src/lua/graphics/Image.h
index d96f69d..0d1d010 100644
--- a/src/lua/graphics/Image.h
+++ b/src/lua/graphics/Image.h
@@ -20,19 +20,23 @@ namespace graphics
{
return image->getWidth();
}
+
int getHeight()
{
return image->getHeight();
}
- void setAnchor(int x, int y)
+
+ void setAnchor(int x, int y)
{
image->setAnchor(x, y);
}
- jin::graphics::color getPixel(int x, int y)
+
+ jin::graphics::color getPixel(int x, int y)
{
return image->getPixel(x, y);
}
- inline const jin::graphics::Texture* getRawImage() const
+
+ inline const jin::graphics::Texture* getRawImage() const
{
return image;
}
@@ -43,6 +47,8 @@ namespace graphics
}
private:
+ Image() {};
+
~Image()
{
delete image;
diff --git a/src/lua/graphics/JSL.h b/src/lua/graphics/JSL.h
index 62aa638..af6c54d 100644
--- a/src/lua/graphics/JSL.h
+++ b/src/lua/graphics/JSL.h
@@ -74,6 +74,8 @@ namespace graphics
static JSLProgram* currentJSLProgram;
+ JSLProgram() {}
+
~JSLProgram()
{
delete jslprogram;
diff --git a/src/lua/luaopen_types.h b/src/lua/luaopen_types.h
index b32d849..a685407 100644
--- a/src/lua/luaopen_types.h
+++ b/src/lua/luaopen_types.h
@@ -2,20 +2,20 @@
#define __JIN_M_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"
+#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"
+#define JIN_AUDIO_SOURCE "jin.Audio.Source"
// thread module
-#define JIN_THREAD_THREAD "JIN_THREAD_THREAD"
+#define JIN_THREAD_THREAD "jin.thread.Thread"
// network module
-#define JIN_NETWORK_SOCKET "JIN_NETWORK_SOCKET"
-#define JIN_NETWORK_BUFFER "JIN_NETWORK_BUFFER"
+#define JIN_NETWORK_SOCKET "jin.net.Socket"
+#define JIN_NETWORK_BUFFER "jin.net.Buffer"
namespace jin
{
@@ -45,9 +45,7 @@ namespace lua
}
protected:
- virtual ~Object() = 0
- {
- }
+ virtual ~Object() = 0 {}
private:
// reference count
diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp
index b6fb33b..30eb343 100644
--- a/src/lua/thread/luaopen_Thread.cpp
+++ b/src/lua/thread/luaopen_Thread.cpp
@@ -172,7 +172,7 @@ namespace lua
static int l_remove(lua_State* L)
{
Thread* t = checkThread(L);
- int slot = luax_checkinteger(L, 1);
+ int slot = luax_checkinteger(L, 2);
t->remove(slot);
return 0;
}
diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/thread/luaopen_thread.cpp
index b6fb33b..30eb343 100644
--- a/src/lua/thread/luaopen_thread.cpp
+++ b/src/lua/thread/luaopen_thread.cpp
@@ -172,7 +172,7 @@ namespace lua
static int l_remove(lua_State* L)
{
Thread* t = checkThread(L);
- int slot = luax_checkinteger(L, 1);
+ int slot = luax_checkinteger(L, 2);
t->remove(slot);
return 0;
}