aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-26 18:40:32 +0800
committerchai <chaifix@163.com>2018-10-26 18:40:32 +0800
commitb04c097db4bf8c45342bca403ca2c8a6d5783a84 (patch)
treee9c6a8c67998d359ede587bc2ce0edf257c8ceae /src
parentba97a053286bdb17643448cc5034c71065bc4e86 (diff)
*修复错误界面关闭bug
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/jin/main.cpp28
-rw-r--r--src/libjin/Common/je_object.h2
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.cpp4
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.h4
-rw-r--r--src/libjin/Graphics/je_canvas.cpp2
-rw-r--r--src/libjin/Graphics/je_canvas.h4
-rw-r--r--src/libjin/Graphics/je_graphic.cpp61
-rw-r--r--src/libjin/Graphics/je_graphic.h16
-rw-r--r--src/libjin/Graphics/je_graphic_batch.cpp11
-rw-r--r--src/libjin/Graphics/je_graphic_batch.h31
-rw-r--r--src/libjin/Graphics/je_graphic_manager.cpp (renamed from src/libjin/Graphics/je_graphic_sheet.cpp)0
-rw-r--r--src/libjin/Graphics/je_graphic_manager.h0
-rw-r--r--src/libjin/Graphics/je_graphic_sheet.h22
-rw-r--r--src/libjin/Graphics/je_graphic_single.cpp82
-rw-r--r--src/libjin/Graphics/je_graphic_single.h53
-rw-r--r--src/libjin/Graphics/je_sprite.h4
-rw-r--r--src/libjin/Graphics/je_sprite_batch.cpp0
-rw-r--r--src/libjin/Graphics/je_sprite_batch.h0
-rw-r--r--src/libjin/Graphics/je_sprite_sheet.cpp0
-rw-r--r--src/libjin/Graphics/je_sprite_sheet.h44
-rw-r--r--src/libjin/Graphics/je_texture.cpp2
-rw-r--r--src/libjin/Graphics/je_texture.h4
-rw-r--r--src/libjin/ai/je_state_machine.h221
-rw-r--r--src/libjin/jin.h1
-rw-r--r--src/lua/embed/boot.lua.h136
-rw-r--r--src/lua/libraries/luax/luax.h2
-rw-r--r--src/lua/modules/event/je_lua_event.cpp1
29 files changed, 359 insertions, 376 deletions
diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe
index ad3e5ed..189229d 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 9190d50..e7b40d3 100644
--- a/src/3rdparty/minilua/minilua.exe
+++ b/src/3rdparty/minilua/minilua.exe
Binary files differ
diff --git a/src/jin/main.cpp b/src/jin/main.cpp
index 2d65064..2144fbc 100644
--- a/src/jin/main.cpp
+++ b/src/jin/main.cpp
@@ -11,21 +11,16 @@
using namespace JinEngine::Lua;
using namespace JinEngine::Filesystem;
-int main(int argc, char* argv[])
+static void setParamters(lua_State* L, int argc, char* args[])
{
- lua_State* L = luax_newstate();
-
- // Open lua standard module.
- luax_openlibs(L);
- // Open jin module.
- luaopen_jin(L);
// Add args to field.
luax_newtable(L);
for (int i = 0; i < argc; ++i)
- luax_setrawstring(L, -2, i + 1, argv[i]);
+ luax_setrawstring(L, -2, i + 1, args[i]);
luax_setfield(L, -2, "args");
// Push current working directory.
// Absolute directory.
+ // An 1KB buffer.
Buffer cwd = Buffer(1024);
#ifdef _WIN32
_getcwd((char*)&cwd, cwd.size());
@@ -33,11 +28,26 @@ int main(int argc, char* argv[])
#elif defined __APPLE__
#endif
luax_setfieldstring(L, "cwd", (char*)&cwd);
- luax_clear(L);
+}
+
+int main(int argc, char* args[])
+{
+ // Global lua runtime.
+ lua_State* L = luax_newstate();
+
+ // Open lua standard module.
+ luax_openlibs(L);
+ // Open jin module.
+ luaopen_jin(L);
+ // Set parameters.
+ setParamters(L, argc, args);
+ // Clear lua stack.
+ luax_clearstack(L);
// Boot jin and run it.
boot(L);
+ // Close lua lib.
luax_close(L);
return 0;
diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h
index c256879..0d3e848 100644
--- a/src/libjin/Common/je_object.h
+++ b/src/libjin/Common/je_object.h
@@ -9,6 +9,8 @@ namespace JinEngine
///
class Object
{
+ public:
+
};
} // namespace JinEngine
diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp
index 15d0ace..dcebdb2 100644
--- a/src/libjin/Graphics/Font/je_texture_font.cpp
+++ b/src/libjin/Graphics/Font/je_texture_font.cpp
@@ -246,7 +246,7 @@ namespace JinEngine
}
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
- : GraphicSingle(bitmap)
+ : Graphic(bitmap)
, Font(cellh)
{
TextureGlyph glyph;
@@ -267,7 +267,7 @@ namespace JinEngine
}
TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
- : GraphicSingle(bitmap)
+ : Graphic(bitmap)
, Font(cellh)
{
TextureGlyph glyph;
diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h
index 5b08747..d61991a 100644
--- a/src/libjin/Graphics/Font/je_texture_font.h
+++ b/src/libjin/Graphics/Font/je_texture_font.h
@@ -6,7 +6,7 @@
#include "../../math/je_vector4.hpp"
-#include "../je_graphic_single.h"
+#include "../je_graphic.h"
#include "../je_bitmap.h"
#include "je_page.h"
@@ -21,7 +21,7 @@ namespace JinEngine
///
///
///
- class TextureFont : public Font , public GraphicSingle
+ class TextureFont : public Font , public Graphic
{
public:
diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp
index 417127d..7c8e849 100644
--- a/src/libjin/Graphics/je_canvas.cpp
+++ b/src/libjin/Graphics/je_canvas.cpp
@@ -24,7 +24,7 @@ namespace JinEngine
}
Canvas::Canvas(int w, int h)
- : GraphicSingle(w, h)
+ : Graphic(w, h)
{
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h
index ddfd092..f39b0de 100644
--- a/src/libjin/Graphics/je_canvas.h
+++ b/src/libjin/Graphics/je_canvas.h
@@ -3,7 +3,7 @@
#include "../core/je_configuration.h"
#if defined(jin_graphics)
-#include "je_graphic_single.h"
+#include "je_graphic.h"
namespace JinEngine
{
@@ -14,7 +14,7 @@ namespace JinEngine
///
/// A canvas is a rendering target.
///
- class Canvas: public GraphicSingle
+ class Canvas: public Graphic
{
public:
///
diff --git a/src/libjin/Graphics/je_graphic.cpp b/src/libjin/Graphics/je_graphic.cpp
index 86b6bf4..66fb494 100644
--- a/src/libjin/Graphics/je_graphic.cpp
+++ b/src/libjin/Graphics/je_graphic.cpp
@@ -41,6 +41,67 @@ namespace JinEngine
glDeleteTextures(1, &mTexture);
}
+ void Graphic::render(int x, int y, float sx, float sy, float r, float ox, float oy)
+ {
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy);
+ int w = getWidth(), h = getHeight();
+ static float vertexCoords[8];
+ static float textureCoords[8];
+ // Set vertex coordinates.
+ vertexCoords[0] = 0; vertexCoords[1] = 0;
+ vertexCoords[2] = 0; vertexCoords[3] = h;
+ vertexCoords[4] = w; vertexCoords[5] = h;
+ vertexCoords[6] = w; vertexCoords[7] = 0;
+ // Set texture coordinates.
+ textureCoords[0] = 0; textureCoords[1] = 0;
+ textureCoords[2] = 0; textureCoords[3] = 1;
+ textureCoords[4] = 1; textureCoords[5] = 1;
+ textureCoords[6] = 1; textureCoords[7] = 0;
+ // Set shader.
+ Shader* shader = Shader::getCurrentShader();
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords);
+ shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords);
+
+ gl.bindTexture(getGLTexture());
+ gl.drawArrays(GL_QUADS, 0, 4);
+ gl.bindTexture(0);
+ }
+
+ void Graphic::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
+ {
+ static float vertexCoords[8];
+ static float textureCoords[8];
+
+ // Set vertex coordinates.
+ vertexCoords[0] = 0; vertexCoords[1] = 0;
+ vertexCoords[2] = 0; vertexCoords[3] = slice.h;
+ vertexCoords[4] = slice.w; vertexCoords[5] = slice.h;
+ vertexCoords[6] = slice.w; vertexCoords[7] = 0;
+ // Set texture coordinates.
+ float slx = slice.x / mSize.w;
+ float sly = slice.y / mSize.h;
+ float slw = slice.w / mSize.w;
+ float slh = slice.h / mSize.h;
+ textureCoords[0] = slx; textureCoords[1] = sly;
+ textureCoords[2] = slx; textureCoords[3] = sly + slh;
+ textureCoords[4] = slx + slw; textureCoords[5] = sly + slh;
+ textureCoords[6] = slx + slw; textureCoords[7] = sly;
+
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay);
+
+ Shader* shader = Shader::getCurrentShader();
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords);
+ shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords);
+
+ gl.bindTexture(getGLTexture());
+ gl.drawArrays(GL_QUADS, 0, 4);
+ gl.bindTexture(0);
+ }
+
//void Graphic::setFilter(GLint min, GLint max)
//{
// glTexParameteri(GL_)
diff --git a/src/libjin/Graphics/je_graphic.h b/src/libjin/Graphics/je_graphic.h
index 2ed028d..69fa109 100644
--- a/src/libjin/Graphics/je_graphic.h
+++ b/src/libjin/Graphics/je_graphic.h
@@ -14,12 +14,6 @@ namespace JinEngine
namespace Graphics
{
- //
- // Graphic
- // |- GraphicSingle
- // |- GraphicBatch
- //
-
///
/// Class inherites Graphic doesn't keep any state such as origin, scale and other properties.
///
@@ -63,6 +57,16 @@ namespace JinEngine
///
void setFilter(GLint min, GLint max);
+ ///
+ /// Render graphic single with given coordinates.
+ ///
+ void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
+
+ ///
+ /// Render part of graphic single with given coordinates.
+ ///
+ void render(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
+
protected:
JinEngine::Math::Vector2<uint> mSize;
diff --git a/src/libjin/Graphics/je_graphic_batch.cpp b/src/libjin/Graphics/je_graphic_batch.cpp
deleted file mode 100644
index 1b8601a..0000000
--- a/src/libjin/Graphics/je_graphic_batch.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "je_graphic_batch.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
-
-
- } // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphic_batch.h b/src/libjin/Graphics/je_graphic_batch.h
deleted file mode 100644
index 274ce4d..0000000
--- a/src/libjin/Graphics/je_graphic_batch.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef __JE_GRAPHIC_BATCH_H
-#define __JE_GRAPHIC_BATCH_H
-
-#include "je_graphic_single.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- //
- // GraphicsBatch
- //
-
- ///
- /// For reducing draw call. Draw a bunch of graphic.
- ///
- class GraphicBatch : public GraphicSingle
- {
- public:
- void add(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
-
- private:
-
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphic_sheet.cpp b/src/libjin/Graphics/je_graphic_manager.cpp
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/je_graphic_sheet.cpp
+++ b/src/libjin/Graphics/je_graphic_manager.cpp
diff --git a/src/libjin/Graphics/je_graphic_manager.h b/src/libjin/Graphics/je_graphic_manager.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/je_graphic_manager.h
diff --git a/src/libjin/Graphics/je_graphic_sheet.h b/src/libjin/Graphics/je_graphic_sheet.h
deleted file mode 100644
index 72c038f..0000000
--- a/src/libjin/Graphics/je_graphic_sheet.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef __JE_GRAPHIC_SHEET
-#define __JE_GRAPHIC_SHEET
-
-#include "je_graphic.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// A graphic sheet is a atlas.
- ///
- class GraphicSheet : public Graphic
- {
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphic_single.cpp b/src/libjin/Graphics/je_graphic_single.cpp
deleted file mode 100644
index 96eb1af..0000000
--- a/src/libjin/Graphics/je_graphic_single.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "shader/je_shader.h"
-
-#include "je_graphic_single.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- GraphicSingle::GraphicSingle(int w, int h)
- : Graphic(w, h)
- {
- }
-
- GraphicSingle::GraphicSingle(const Bitmap* bitmap)
- : Graphic(bitmap)
- {
- }
-
- void GraphicSingle::render(int x, int y, float sx, float sy, float r, float ox, float oy)
- {
- gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy);
- int w = getWidth(), h = getHeight();
- static float vertexCoords[8];
- static float textureCoords[8];
- // Set vertex coordinates.
- vertexCoords[0] = 0; vertexCoords[1] = 0;
- vertexCoords[2] = 0; vertexCoords[3] = h;
- vertexCoords[4] = w; vertexCoords[5] = h;
- vertexCoords[6] = w; vertexCoords[7] = 0;
- // Set texture coordinates.
- textureCoords[0] = 0; textureCoords[1] = 0;
- textureCoords[2] = 0; textureCoords[3] = 1;
- textureCoords[4] = 1; textureCoords[5] = 1;
- textureCoords[6] = 1; textureCoords[7] = 0;
- // Set shader.
- Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords);
- shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords);
-
- gl.bindTexture(getGLTexture());
- gl.drawArrays(GL_QUADS, 0, 4);
- gl.bindTexture(0);
- }
-
- void GraphicSingle::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
- {
- static float vertexCoords[8];
- static float textureCoords[8];
-
- // Set vertex coordinates.
- vertexCoords[0] = 0; vertexCoords[1] = 0;
- vertexCoords[2] = 0; vertexCoords[3] = slice.h;
- vertexCoords[4] = slice.w; vertexCoords[5] = slice.h;
- vertexCoords[6] = slice.w; vertexCoords[7] = 0;
- // Set texture coordinates.
- float slx = slice.x / mSize.w;
- float sly = slice.y / mSize.h;
- float slw = slice.w / mSize.w;
- float slh = slice.h / mSize.h;
- textureCoords[0] = slx; textureCoords[1] = sly;
- textureCoords[2] = slx; textureCoords[3] = sly + slh;
- textureCoords[4] = slx + slw; textureCoords[5] = sly + slh;
- textureCoords[6] = slx + slw; textureCoords[7] = sly;
-
- gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay);
-
- Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertexCoords);
- shader->bindUVPointer(2, GL_FLOAT, 0, textureCoords);
-
- gl.bindTexture(getGLTexture());
- gl.drawArrays(GL_QUADS, 0, 4);
- gl.bindTexture(0);
- }
-
- } // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphic_single.h b/src/libjin/Graphics/je_graphic_single.h
deleted file mode 100644
index f61234b..0000000
--- a/src/libjin/Graphics/je_graphic_single.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef __JE_GRAPHIC_SINGLE_H
-#define __JE_GRAPHIC_SINGLE_H
-
-#include "../math/je_quad.h"
-
-#include "je_graphic.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
- //
- // GraphicSingle
- // |- Canvas
- // |- Texture
- // |- TextureFont
- //
-
- ///
- /// Single graphic, comparing to graphics batch, a single graphic need assign it's vertex and screen uv.
- /// For example, a texture and canvas should be a graphic single.
- ///
- class GraphicSingle : public Graphic
- {
- public:
- ///
- ///
- ///
- GraphicSingle(const Bitmap* bitmap);
-
- ///
- ///
- ///
- GraphicSingle(int w = 0, int h = 0);
-
- ///
- /// Render graphic single with given coordinates.
- ///
- void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
-
- ///
- /// Render part of graphic single with given coordinates.
- ///
- void render(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
-
- private:
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h
index df8d6eb..730e11e 100644
--- a/src/libjin/Graphics/je_sprite.h
+++ b/src/libjin/Graphics/je_sprite.h
@@ -28,7 +28,7 @@ namespace JinEngine
///
/// Render callback.
///
- void onRender();
+ virtual void onRender();
private:
///
@@ -39,7 +39,7 @@ namespace JinEngine
Math::Vector2<float> mScale;
Color mColor;
Shader* mShader;
- GraphicSingle* mGraphic;
+ Graphic* mGraphic;
};
diff --git a/src/libjin/Graphics/je_sprite_batch.cpp b/src/libjin/Graphics/je_sprite_batch.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_batch.cpp
diff --git a/src/libjin/Graphics/je_sprite_batch.h b/src/libjin/Graphics/je_sprite_batch.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_batch.h
diff --git a/src/libjin/Graphics/je_sprite_sheet.cpp b/src/libjin/Graphics/je_sprite_sheet.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_sheet.cpp
diff --git a/src/libjin/Graphics/je_sprite_sheet.h b/src/libjin/Graphics/je_sprite_sheet.h
new file mode 100644
index 0000000..29f3a0e
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_sheet.h
@@ -0,0 +1,44 @@
+#ifndef __JE_SPRITE_SHEET_H
+#define __JE_SPRITE_SHEET_H
+
+#include <vector>
+
+#include "../math/je_quad.h"
+
+#include "je_sprite.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ class SpriteSheet
+ {
+ public:
+ ///
+ /// Create a new sprite in sheet.
+ ///
+ Sprite* createSprite(const Math::Quad& quad);
+
+ private:
+ class SpriteInSheet : public Sprite
+ {
+ public:
+
+ private:
+ ///
+ /// Quad in sprite sheet.
+ ///
+ Math::Quad quad;
+
+ };
+
+ std::vector<SpriteInSheet> mSprites;
+ Graphic* mGraphic;
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_texture.cpp b/src/libjin/Graphics/je_texture.cpp
index ff07748..8aa3f9a 100644
--- a/src/libjin/Graphics/je_texture.cpp
+++ b/src/libjin/Graphics/je_texture.cpp
@@ -30,7 +30,7 @@ namespace JinEngine
}
Texture::Texture(const Bitmap* bitmap)
- : GraphicSingle(bitmap)
+ : Graphic(bitmap)
{
}
diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h
index dff3f40..e47ad58 100644
--- a/src/libjin/Graphics/je_texture.h
+++ b/src/libjin/Graphics/je_texture.h
@@ -6,7 +6,7 @@
#include "GLee/GLee.h"
#include "je_color.h"
-#include "je_graphic_single.h"
+#include "je_graphic.h"
#include "je_bitmap.h"
namespace JinEngine
@@ -17,7 +17,7 @@ namespace JinEngine
///
///
///
- class Texture: public GraphicSingle
+ class Texture: public Graphic
{
public:
///
diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h
index 0d19be9..19b884b 100644
--- a/src/libjin/ai/je_state_machine.h
+++ b/src/libjin/ai/je_state_machine.h
@@ -1,5 +1,5 @@
-#ifndef __JE_STATEMACHINE_TREE_H
-#define __JE_STATEMACHINE_TREE_H
+#ifndef __JE_STATE_MACHINE_H
+#define __JE_STATE_MACHINE_H
#include "../core/je_configuration.h"
#if defined(jin_ai)
@@ -7,71 +7,56 @@
#include <map>
#include <vector>
+#include "../common/je_types.h"
#include "../common/je_object.h"
namespace JinEngine
{
namespace AI
{
- // From Unity3D game engine.
-
- class State;
-
- enum ConditionType
- {
-
- };
+ // Grab from Unity engine.
///
- /// Traslation's condition.
+ /// A single layer statemachine.
///
- struct Condition
+ class StateMachine : public Object
{
+ public:
- };
+ union ParameterValue
+ {
+ int _int;
+ float _float;
+ bool _bool;
+ byte _trigger;
+ };
- ///
- /// Translate to another state.
- ///
- struct Transition
- {
- Condition condition; ///< Condition to active transition.
- State* state; ///< State translate to.
- };
+ enum ParameterType
+ {
+ Int, ///< A integer value.
+ FLoat, ///< A float value.
+ Bool, ///< A bool value.
+ Trigger ///< A trigger will be reset to false after activated.
+ };
- ///
- /// Definition of state.
- ///
- struct StateDef
- {
- };
-
- ///
- /// A single state.
- ///
- struct State
- {
- std::string name; ///< Name of state.
- std::vector<Transition> translations; ///< All transitions this state have.
- StateDef definition; ///< Definition of state.
- void* userdata; ///< A state could have a user data.
- };
+ ///
+ /// Traslation's condition.
+ ///
+ struct Condition
+ {
+ std::string parameter;
+ ParameterValue value;
+ };
- ///
- /// A single layer statemachine.
- ///
- class StateMachine : public Object
- {
- public:
///
///
///
- typedef void(*SingleStateCallback)(State* state);
+ typedef void(*SingleStateCallback)(const std::string& stateName);
///
///
///
- typedef void(*DoubleStateCallback)(State* stateFrom, State* stateTo);
+ typedef void(*DoubleStateCallback)(const std::string& stateFrom, const std::string& stateTo);
///
/// State machine constructor.
@@ -88,24 +73,139 @@ namespace JinEngine
///
void onUpdate();
+ ///
+ /// Get current state name.
+ ///
+ const std::string& getCurrentStateName();
+
+ ///
+ ///
+ ///
+ void addParameter(ParameterType type, const std::string& name);
+
///
- /// Add new state.
+ /// Add a state.
///
- void addState(const std::string& name, const State& state);
+ void addState(const std::string& name);
///
- /// Get state reference by given state name.
///
- const State* getState(const std::string& name);
+ ///
+ void addTransition(const std::string& stateFrom, const std::string& stateTo, const std::string& name, const ParameterValue& value);
- void addEnterListener();
- void addExitListener();
- void addTranslateListener();
+ ///
+ ///
+ ///
+ void addTransitioni(const std::string& stateFrom, const std::string& stateTo, const std::string& name, int value);
- const std::string& getCurrentStateName();
- const State* getCurrentState();
+ ///
+ ///
+ ///
+ void addTransitionf(const std::string& stateFrom, const std::string& stateTo, const std::string& name, float value);
+
+ ///
+ ///
+ ///
+ void addTransitionb(const std::string& stateFrom, const std::string& stateTo, const std::string& name, bool value);
+
+ ///
+ ///
+ ///
+ void addTransitiont(const std::string& stateFrom, const std::string& stateTo, const std::string& name);
+
+ ///
+ ///
+ ///
+ void addTransitiont(const std::string& stateFrom, const std::string& stateTo, const std::string& name, const ParameterValue& value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameter(const std::string& name, const ParameterValue& value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameteri(const std::string& name, int value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameterf(const std::string& name, float value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameterb(const std::string& name, bool value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParametert(const std::string& name);
+
+ ///
+ /// Equivalent to setParameter(triggername);
+ ///
+ void trigger(const std::string& name);
+
+ ///
+ /// Force change to state.
+ ///
+ void forceToState(const std::string& name);
+
+ ///
+ /// Reset state machine.
+ ///
+ void resetState();
+
+ ///
+ ///
+ ///
+ void addEnterListener(SingleStateCallback callback);
+
+ ///
+ ///
+ ///
+ void addExitListener(SingleStateCallback callback);
+
+ ///
+ ///
+ ///
+ void addTranslateListener(DoubleStateCallback callback);
private:
+
+ struct Parameter
+ {
+ ParameterType type;
+ ParameterValue value;
+ };
+
+ ///
+ /// Translate to another state.
+ ///
+ struct Transition
+ {
+ Condition condition; ///< Condition to active transition.
+ std::string& state; ///<
+ };
+
+ ///
+ /// A single state.
+ ///
+ struct State
+ {
+ std::string name; ///< Name of state.
+ std::vector<Transition> transitions; ///< All transitions this state have.
+ };
+
+ ///
+ /// Check if condition is full filled.
+ ///
+ /// @param condition Condition to check.
+ ///
+ bool checkCondition(const Condition& condition);
+
///
/// All state this state machine keeps.
///
@@ -129,12 +229,17 @@ namespace JinEngine
///
/// Current state.
///
- State* mCurrentState;
+ const State* mCurrentState;
+
+ ///
+ /// All parameters.
+ ///
+ std::map<std::string, Parameter> mParameters;
};
- }
-}
+ } // namespace Graphics
+} // namespace JinEngine
#endif // jin_ai
diff --git a/src/libjin/jin.h b/src/libjin/jin.h
index 88276ca..a43730d 100644
--- a/src/libjin/jin.h
+++ b/src/libjin/jin.h
@@ -16,5 +16,6 @@
#include "time/je_timer.h"
#include "multithread/je_thread.h"
#include "common/je_common.h"
+#include "ai/je_state_machine.h"
#endif // __JE_H \ No newline at end of file
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
index 99e657b..ca08e87 100644
--- a/src/lua/embed/boot.lua.h
+++ b/src/lua/embed/boot.lua.h
@@ -12,8 +12,8 @@ jin.config = {}
if jin.filesystem.exist("config.lua") then
jin.config = require "config"
end
-jin.config.width = jin.config.width or 576
-jin.config.height = jin.config.height or 448
+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
@@ -26,7 +26,7 @@ jin.config.fps = jin.config.fps or 60
jin.graphics.init(jin.config)
jin.audio.init()
--- TODO: ϵͳģ
+-- TODO: Disable some internal lua modules.
-------------------------------------------------------------------------
-- Default game loop
@@ -66,110 +66,66 @@ function jin.core.run()
end
-------------------------------------------------------------------------
--- No game handler
+-- Boot game
-------------------------------------------------------------------------
-jin.core.setHandler = function(handler)
- if handler == nil then
- return
- end
- jin.core.onLoad = handler.onLoad
- jin.core.onEvent = handler.onEvent
- jin.core.onUpdate = handler.onUpdate
- jin.core.onDraw = handler.onDraw
-end
-
--- TODO: Ĭͼbase64
-jin.nogame = {
- cs = 64,
- sw = jin.graphics.getWidth(),
- sh = jin.graphics.getHeight(),
- cw = 0,
- ch = 0,
- ww = 6,
- ww2 = 6*2,
- speed = 4,
- t = 0,
- onLoad = function()
- local nogame = jin.nogame
- nogame.cw = nogame.sw / nogame.cs
- nogame.ch = nogame.sh / nogame.cs
- nogame.t = nogame.ww - 1
- end,
- onEvent = function(e)
- if e.type == 'Quit' then
- jin.core.stop()
- end
- end,
- onUpdate = function(dt)
- print(dt)
- local nogame = jin.nogame
- nogame.t = nogame.t + dt * nogame.speed
- if nogame.t > nogame.ww2 then
- nogame.t = nogame.t - nogame.ww2
- end
- end,
- circle = function(x, y, r)
- local nogame = jin.nogame
- if r % nogame.ww2 > nogame.ww then
- return
- end
- r = math.sin((r/nogame.ww)*math.pi)*nogame.cs/2
- local fact = (x + y) / nogame.ch * nogame.cw
- 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()
- local nogame = jin.nogame
- for y = 0, nogame.ch - 1 do
- for x = 0, nogame.cw - 1 do
- nogame.circle(x, y, nogame.t+x+y)
- end
+local function plainLoop()
+ 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
-}
-
--------------------------------------------------------------------------
--- Boot jin
--------------------------------------------------------------------------
+end
+-- Display error message.
local function onError(msg)
+ local err = "Error:\n" .. msg .. "\n" .. debug.traceback()
jin.graphics.reset()
jin.graphics.setClearColor(100, 100, 100, 255)
jin.graphics.clear()
- jin.graphics.print("Error:\n" .. msg .. "\n" .. debug.traceback(), 5, 5)
+ jin.graphics.print(err, 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
- jin.core.quit()
+ plainLoop()
+end
+
+-- 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()
+ plainLoop()
end
local function boot()
if jin.filesystem.exist("main.lua") then
- -- Require main game script
- xpcall(function() require"main" end, onError)
- xpcall(function() jin.core.run() end, onError)
+ call(function()
+ require"main"
+ jin.core.run()
+ end)
else
- -- No game
- jin.core.setHandler(jin.nogame)
- jin.core.run()
+ noGame()
end
- jin.graphics.destroy()
- jin.audio.destroy()
- jin.core.quit()
-end
+end
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/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h
index fd10737..be2e227 100644
--- a/src/lua/libraries/luax/luax.h
+++ b/src/lua/libraries/luax/luax.h
@@ -46,7 +46,7 @@ lua_setglobal(L, name);
#define luax_newtable lua_newtable
#define luax_getglobal lua_getglobal
-#define luax_clear(L) lua_settop(L, 0)
+#define luax_clearstack(L) lua_settop(L, 0)
/**
*
*/
diff --git a/src/lua/modules/event/je_lua_event.cpp b/src/lua/modules/event/je_lua_event.cpp
index 2133f3b..d09108a 100644
--- a/src/lua/modules/event/je_lua_event.cpp
+++ b/src/lua/modules/event/je_lua_event.cpp
@@ -101,7 +101,6 @@ namespace JinEngine
case EventType::CONTROLLERAXISMOTION:
-
default:
// Ignore oter events and pop up the event table.
luax_pop(L, 1);