aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-27 08:31:00 +0800
committerchai <chaifix@163.com>2018-10-27 08:31:00 +0800
commit73c42ddcc4eeb6ac3f0282d2c08ae8e632f3355f (patch)
treeeeddce1725b9d6f81693d2ae99f665226d7a9d24 /src
parente21485a60da2b304a0d529d72e9a47061a3f9502 (diff)
*修改boot.lua
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/buildvm/buildvm.exebin62976 -> 62976 bytes
-rw-r--r--src/3rdparty/minilua/minilua.exebin112640 -> 112640 bytes
-rw-r--r--src/libjin/Audio/SDL/je_sdl_audio.cpp1
-rw-r--r--src/libjin/Core/je_configuration.h2
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.h2
-rw-r--r--src/libjin/Graphics/je_window.cpp2
-rw-r--r--src/libjin/ai/je_state_machine.h81
-rw-r--r--src/lua/embed/boot.lua.h130
-rw-r--r--src/lua/embed/graphics.lua.h13
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp14
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp31
11 files changed, 160 insertions, 116 deletions
diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe
index 189229d..48f869f 100644
--- a/src/3rdparty/buildvm/buildvm.exe
+++ b/src/3rdparty/buildvm/buildvm.exe
Binary files differ
diff --git a/src/3rdparty/minilua/minilua.exe b/src/3rdparty/minilua/minilua.exe
index e7b40d3..c6925a3 100644
--- a/src/3rdparty/minilua/minilua.exe
+++ b/src/3rdparty/minilua/minilua.exe
Binary files differ
diff --git a/src/libjin/Audio/SDL/je_sdl_audio.cpp b/src/libjin/Audio/SDL/je_sdl_audio.cpp
index 96df17f..4ce02f7 100644
--- a/src/libjin/Audio/SDL/je_sdl_audio.cpp
+++ b/src/libjin/Audio/SDL/je_sdl_audio.cpp
@@ -37,6 +37,7 @@ namespace JinEngine
if (SDL_Init(SDL_INIT_AUDIO) < 0)
return false;
+
SDL_AudioSpec spec;
Setting* setting = (Setting*)s;
if (setting == nullptr)
diff --git a/src/libjin/Core/je_configuration.h b/src/libjin/Core/je_configuration.h
index 065fbae..d96d5b9 100644
--- a/src/libjin/Core/je_configuration.h
+++ b/src/libjin/Core/je_configuration.h
@@ -6,7 +6,7 @@
///
/// Debug output
///
-#define jin_debug
+//#define jin_debug
#define jin_os_windows 0x01
#define jin_os_mac 0x02
diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h
index d61991a..fb74eca 100644
--- a/src/libjin/Graphics/Font/je_texture_font.h
+++ b/src/libjin/Graphics/Font/je_texture_font.h
@@ -39,7 +39,7 @@ namespace JinEngine
///
///
static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
-
+
///
///
///
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index f0b789e..b36a2a3 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -76,8 +76,6 @@ namespace JinEngine
gl.enable(GL_BLEND);
gl.enable(GL_TEXTURE_2D);
gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // avoid white screen blink on windows
- swapBuffers();
// bind to default canvas
Canvas::unbind();
Shader::unuse();
diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h
index 71bf7ba..7b199ac 100644
--- a/src/libjin/ai/je_state_machine.h
+++ b/src/libjin/ai/je_state_machine.h
@@ -23,31 +23,6 @@ namespace JinEngine
{
public:
- union ParameterValue
- {
- int _int;
- float _float;
- bool _bool;
- byte _trigger;
- };
-
- enum ParameterType
- {
- Int, ///< A integer value.
- FLoat, ///< A float value.
- Bool, ///< A bool value.
- Trigger ///< A trigger will be reset to false after activated.
- };
-
- ///
- /// Traslation's condition.
- ///
- struct Condition
- {
- std::string parameter;
- ParameterValue value;
- };
-
///
///
///
@@ -81,17 +56,27 @@ namespace JinEngine
///
///
///
- void addParameter(ParameterType type, const std::string& name);
+ void addParameteri(const std::string& name);
- ///
- /// Add a state.
- ///
- void addState(const std::string& name);
+ ///
+ ///
+ ///
+ void addParameterf(const std::string& name);
///
///
///
- void addTransition(const std::string& stateFrom, const std::string& stateTo, const std::string& name, const ParameterValue& value);
+ void addParameterb(const std::string& name);
+
+ ///
+ ///
+ ///
+ void addParametert(const std::string& name);
+
+ ///
+ /// Add a state.
+ ///
+ void addState(const std::string& name);
///
///
@@ -116,11 +101,6 @@ namespace JinEngine
///
/// Set parameter value.
///
- void setParameter(const std::string& name, const ParameterValue& value);
-
- ///
- /// Set parameter value.
- ///
void setParameteri(const std::string& name, int value);
///
@@ -151,7 +131,7 @@ namespace JinEngine
///
/// Reset state machine.
///
- void resetState();
+ void reset();
///
///
@@ -170,19 +150,44 @@ namespace JinEngine
private:
+ enum ParameterType
+ {
+ Int, ///< A integer value.
+ FLoat, ///< A float value.
+ Bool, ///< A bool value.
+ Trigger ///< A trigger will be reset to false after activated.
+ };
+
+ union ParameterValue
+ {
+ int _int;
+ float _float;
+ bool _bool;
+ byte _trigger;
+ };
+
struct Parameter
{
ParameterType type;
ParameterValue value;
};
+ ///
+ /// Traslation's condition.
+ ///
+ struct Condition
+ {
+ std::string parameter;
+ ParameterValue value;
+ };
+
///
/// Translate to another state.
///
struct Transition
{
Condition condition; ///< Condition to active transition.
- std::string& state; ///<
+ std::string state; ///<
};
///
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
index 13368d6..212a1e5 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/boot.lua.h
@@ -1,11 +1,28 @@
/* boot.lua */
static const char* boot_lua = R"(
--- Set game root directory
jin.args[2] = jin.args[2] or '.'
jin.filesystem.init()
jin.filesystem.mount(jin.args[2])
+-------------------------------------------------------------------------
+-- Config game
+-------------------------------------------------------------------------
+
jin.config = {}
+if jin.filesystem.exist("config.lua") then
+ xpcall(function()jin.config = require "config" end, function()end)
+end
+jin.config.width = jin.config.width or 580
+jin.config.height = jin.config.height or 450
+jin.config.vsync = jin.config.vsync or true
+jin.config.title = jin.config.title or ("jin v" .. jin.version)
+jin.config.resizable = jin.config.resizable or false
+jin.config.fullscreen = jin.config.fullscreen or false
+jin.config.fps = jin.config.fps or 60
+
+-------------------------------------------------------------------------
+-- Default game loop
+-------------------------------------------------------------------------
local function call(func, ...)
if func then
@@ -13,20 +30,9 @@ local function call(func, ...)
end
end
-local function open_sub_systems()
- jin.audio.init()
- jin.graphics.init(jin.config)
-end
-
-local function close_sub_systems()
- jin.audio.destroy()
- jin.graphics.destroy()
-end
-
--- Default game loop
function jin.core.run()
- call(jin.core.onLoad)
jin.graphics.reset()
+ call(jin.core.onLoad)
local dt = 0
local previous = jin.time.second()
local current = previous
@@ -50,52 +56,12 @@ function jin.core.run()
end
end
-local function noGame()
- jin.core.onLoad = nil
- jin.core.onEvent = function(e)
- if e.type == "Quit" then
- jin.core.stop()
- end
- end
- jin.core.onUpdate = nil
- jin.core.onDraw = function()
- jin.graphics.print("No game", 5, 5)
- end
-end
-
-local function main()
- -- Load config file
- if jin.filesystem.exist("config.lua") then
- jin.config = require "config"
- end
- jin.config.width = jin.config.width or 580
- jin.config.height = jin.config.height or 450
- jin.config.vsync = jin.config.vsync or true
- jin.config.title = jin.config.title or ("jin v" .. jin.version)
- jin.config.resizable = jin.config.resizable or false
- jin.config.fullscreen = jin.config.fullscreen or false
- jin.config.fps = jin.config.fps or 60
-
- -- Load game source.
- if jin.filesystem.exist("main.lua") then
- call(function() require"main" end)
- else
- call(noGame)
- end
-
- open_sub_systems()
-
- call(jin.core.run)
-
- close_sub_systems()
-
- -- Quit
- jin.core.quit()
-end
+-------------------------------------------------------------------------
+-- Boot game
+-------------------------------------------------------------------------
-- Display error message.
local function onError(msg)
- open_sub_systems()
local err = "Error:\n" .. msg .. "\n" .. debug.traceback()
jin.graphics.reset()
jin.graphics.setClearColor(100, 100, 100, 255)
@@ -110,9 +76,57 @@ local function onError(msg)
end
jin.time.sleep(0.001)
end
- close_sub_systems()
end
-xpcall(main, onError)
+-- No game screen.
+local function noGame()
+ jin.graphics.reset()
+ jin.graphics.reset()
+ jin.graphics.setClearColor(100, 100, 100, 255)
+ jin.graphics.clear()
+ jin.graphics.print("No Game", 5, 5)
+ jin.graphics.present()
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ end
+ jin.time.sleep(0.001)
+ end
+end
+
+local function boot()
+ if jin.filesystem.exist("main.lua") then
+ call(function()
+ require"main"
+ jin.core.run()
+ end)
+ else
+ noGame()
+ end
+end
+
+-------------------------------------------------------------------------
+-- Initialize sub systems
+-------------------------------------------------------------------------
+
+jin.audio.init()
+jin.graphics.init(jin.config)
+
+xpcall(boot, onError)
+
+-------------------------------------------------------------------------
+-- Destroy sub-systems
+-------------------------------------------------------------------------
+
+jin.graphics.destroy()
+jin.audio.destroy()
+
+-------------------------------------------------------------------------
+-- Quit game
+-------------------------------------------------------------------------
+
+jin.core.quit()
)"; \ No newline at end of file
diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/graphics.lua.h
index 5fa5dad..b2a19b5 100644
--- a/src/lua/embed/graphics.lua.h
+++ b/src/lua/embed/graphics.lua.h
@@ -24,11 +24,18 @@ Color frag(Color col, Texture tex, Vertex v)
]]
local _init = jin.graphics.init
+local initialized = false
jin.graphics.init = function(setting)
- _init(setting);
- default_shader = jin.graphics.newShader(default_shader_source)
- jin.graphics.useShader(default_shader)
+ 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)
+ end
+ return initialized
end
jin.graphics.unuseShader = function()
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
index c021ef1..8ffa794 100644
--- a/src/lua/modules/audio/je_lua_audio.cpp
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -14,12 +14,24 @@ namespace JinEngine
typedef SDLAudio Audio;
typedef SDLSource Source;
+ struct
+ {
+ bool initialized = false;
+ } context;
+
LUA_IMPLEMENT int l_init(lua_State* L)
{
+ if (context.initialized)
+ {
+ // Already initialized.
+ luax_pushboolean(L, true);
+ return 1;
+ }
Audio::Setting setting;
setting.samplerate = 44100;
setting.samples = 44100;
- if (!Audio::get()->init(&setting))
+ context.initialized = Audio::get()->init(&setting);
+ if (!context.initialized)
{
luax_error(L, "could not init audio");
luax_pushboolean(L, false);
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 83ef40b..d59a67d 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -24,10 +24,17 @@ namespace JinEngine
Color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
+ bool initialized = false;
} context;
LUA_IMPLEMENT int l_init(lua_State* L)
{
+ if (context.initialized)
+ {
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
Window* wnd = Window::get();
Window::Setting setting;
setting.width = luax_getfieldinteger(L, 1, "width");
@@ -36,21 +43,21 @@ namespace JinEngine
setting.vsync = luax_getfieldbool(L, 1, "vsync");
setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen");
setting.resizable = luax_getfieldbool(L, 1, "resizable");
- if (!wnd->init(&setting))
+ context.initialized = wnd->init(&setting);
+ if (!context.initialized)
{
- luax_pushboolean(L, false);
+ luax_pushboolean(L, context.initialized);
return 1;
}
- {
- /* load default font */
- Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
- TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
- context.defaultFont = tf;
- delete bitmap;
- }
- context.curFont = context.defaultFont;
-
- luax_pushboolean(L, true);
+
+ /* load default font */
+ Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
+ TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
+ delete bitmap;
+ context.defaultFont = tf;
+ context.curFont = tf;
+
+ luax_pushboolean(L, context.initialized);
return 1;
}