summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Editor/GUI/Dock.cpp0
-rw-r--r--Editor/GUI/Dock.h0
-rw-r--r--Editor/GUI/EditorWindows.cpp0
-rw-r--r--Editor/GUI/EditorWindows.h28
-rw-r--r--Editor/GUI/MenuController.cpp0
-rw-r--r--Editor/GUI/MenuController.h11
-rw-r--r--Editor/main.cpp43
-rw-r--r--Editor/wog.c746
-rw-r--r--Editor/wog.h219
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/.suobin30720 -> 0 bytes
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/Browse.VC.dbbin77180928 -> 0 bytes
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/Solution.VC.dbbin2191360 -> 0 bytes
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/19f11c8463ef0178/DEVICE.ipchbin28639232 -> 0 bytes
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/75d245bf98f791a/MAIN.ipchbin13697024 -> 0 bytes
-rw-r--r--Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/7e12c6410b8f7e79/MAINS.ipchbin13697024 -> 0 bytes
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj21
-rw-r--r--Projects/VisualStudio/Editor/Editor.vcxproj.filters33
-rw-r--r--Projects/VisualStudio/GameLab.sln (renamed from Projects/VisualStudio/Jin.sln)13
-rw-r--r--Projects/VisualStudio/ImGUI/ImGUI.vcxproj122
-rw-r--r--Projects/VisualStudio/ImGUI/ImGUI.vcxproj.filters2
-rw-r--r--Projects/VisualStudio/ImGUI/ImGUI.vcxproj.user (renamed from Projects/VisualStudio/Runner/Runner.vcxproj.user)0
-rw-r--r--Projects/VisualStudio/Runtime/Runtime.vcxproj (renamed from Projects/VisualStudio/Runner/Runner.vcxproj)201
-rw-r--r--Projects/VisualStudio/Runtime/Runtime.vcxproj.filters (renamed from Projects/VisualStudio/Runner/Runner.vcxproj.filters)212
-rw-r--r--Projects/VisualStudio/Runtime/Runtime.vcxproj.user4
-rw-r--r--Runtime/FileSystem/FileSystem.cpp9
-rw-r--r--Runtime/FileSystem/FileSystem.h24
-rw-r--r--Runtime/FileSystem/Unzip.cpp0
-rw-r--r--Runtime/FileSystem/Unzip.h0
-rw-r--r--Runtime/Graphics/Color.h22
-rw-r--r--Runtime/Graphics/Device.cpp78
-rw-r--r--Runtime/Graphics/Device.h82
-rw-r--r--Runtime/Graphics/DeviceDefine.h69
-rw-r--r--Runtime/Graphics/FrameBuffer.cpp12
-rw-r--r--Runtime/Graphics/FrameBuffer.h35
-rw-r--r--Runtime/Graphics/GlyphAtlas.cpp0
-rw-r--r--Runtime/Graphics/GlyphAtlas.h6
-rw-r--r--Runtime/Graphics/GpuDataBuffer.cpp206
-rw-r--r--Runtime/Graphics/GpuDataBuffer.h90
-rw-r--r--Runtime/Graphics/ImageData.cpp0
-rw-r--r--Runtime/Graphics/ImageData.h43
-rw-r--r--Runtime/Graphics/OpenGL.cpp0
-rw-r--r--Runtime/Graphics/OpenGL.h6
-rw-r--r--Runtime/Graphics/Point.cpp0
-rw-r--r--Runtime/Graphics/Point.h0
-rw-r--r--Runtime/Graphics/PolyLine.cpp11
-rw-r--r--Runtime/Graphics/PolyLine.h18
-rw-r--r--Runtime/Graphics/Quad.cpp52
-rw-r--r--Runtime/Graphics/Quad.h25
-rw-r--r--Runtime/Graphics/RenderTexture.cpp0
-rw-r--r--Runtime/Graphics/RenderTexture.h16
-rw-r--r--Runtime/Graphics/Scripting/wrap_Device.cpp0
-rw-r--r--Runtime/Graphics/Scripting/wrap_GL.cpp0
-rw-r--r--Runtime/Graphics/Scripting/wrap_RenderTexture.cpp0
-rw-r--r--Runtime/Graphics/Texture.cpp0
-rw-r--r--Runtime/Graphics/Texture.h59
-rw-r--r--Runtime/Graphics/VertexBuffer.cpp322
-rw-r--r--Runtime/Graphics/VertexBuffer.h103
-rw-r--r--Runtime/ImGUI/GUIButton.cpp0
-rw-r--r--Runtime/ImGUI/GUIButton.h6
-rw-r--r--Runtime/ImGUI/GUILabel.cpp0
-rw-r--r--Runtime/ImGUI/GUILabel.h0
-rw-r--r--Runtime/Input/Input.cpp3
-rw-r--r--Runtime/Input/Input.h19
-rw-r--r--Runtime/Math/AABB.h0
-rw-r--r--Runtime/Math/Vector2.cpp0
-rw-r--r--Runtime/Math/Vector2.h17
-rw-r--r--Runtime/Math/Vector3.cpp1
-rw-r--r--Runtime/Math/Vector3.h18
-rw-r--r--Runtime/Mesh/Font.cpp0
-rw-r--r--Runtime/Mesh/Font.h0
-rw-r--r--Runtime/Mesh/FontManager.h0
-rw-r--r--Runtime/Mesh/Glyph.h9
-rw-r--r--Runtime/Mesh/Mesh.cpp4
-rw-r--r--Runtime/Mesh/Mesh.h62
-rw-r--r--Runtime/Mesh/MeshUtil.h6
-rw-r--r--Runtime/Mesh/TextMesh.h11
-rw-r--r--Runtime/Physics/Rigidbody.h6
-rw-r--r--Runtime/Physics/Scripting/wrap_Joint.cpp0
-rw-r--r--Runtime/Profiler/FrameStats.h29
-rw-r--r--Runtime/Profiler/Profiler.h0
-rw-r--r--Runtime/Scripting/luax.h18
-rw-r--r--Runtime/Scripting/luax_cfunctions.cpp19
-rw-r--r--Runtime/Scripting/luax_cfunctions.h25
-rw-r--r--Runtime/Scripting/luax_class.cpp243
-rw-r--r--Runtime/Scripting/luax_class.hpp207
-rw-r--r--Runtime/Scripting/luax_class.inc637
-rw-r--r--Runtime/Scripting/luax_config.h66
-rw-r--r--Runtime/Scripting/luax_enum.cpp67
-rw-r--r--Runtime/Scripting/luax_enum.h39
-rw-r--r--Runtime/Scripting/luax_globalstate.h7
-rw-r--r--Runtime/Scripting/luax_internal.h12
-rw-r--r--Runtime/Scripting/luax_memberref.cpp16
-rw-r--r--Runtime/Scripting/luax_memberref.h27
-rw-r--r--Runtime/Scripting/luax_ref.cpp72
-rw-r--r--Runtime/Scripting/luax_ref.h62
-rw-r--r--Runtime/Scripting/luax_reftable.cpp120
-rw-r--r--Runtime/Scripting/luax_reftable.h67
-rw-r--r--Runtime/Scripting/luax_state.cpp857
-rw-r--r--Runtime/Scripting/luax_state.h298
-rw-r--r--Runtime/Scripting/luax_state.inc180
-rw-r--r--Runtime/Scripting/luax_utility.h66
-rw-r--r--Runtime/Scripting/luax_vm.cpp76
-rw-r--r--Runtime/Scripting/luax_vm.h63
-rw-r--r--Runtime/Scripting/luax_watchdog.cpp0
-rw-r--r--Runtime/Scripting/luax_watchdog.h33
-rw-r--r--Runtime/Shaders/ShaderChannel.h27
-rw-r--r--Runtime/Shaders/ShaderDefine.cpp11
-rw-r--r--Runtime/Shaders/ShaderDefine.h19
-rw-r--r--Runtime/Shaders/ShaderUniform.h4
-rw-r--r--Runtime/Threads/Mutex.cpp0
-rw-r--r--Runtime/Threads/Mutex.h0
-rw-r--r--Runtime/Threads/Semaphore.cpp0
-rw-r--r--Runtime/Threads/Semaphore.h0
-rw-r--r--Runtime/Threads/Thread.h0
-rw-r--r--Runtime/Utilities/Assert.h8
-rw-r--r--Runtime/Utilities/Base64.cpp0
-rw-r--r--Runtime/Utilities/Base64.h0
-rw-r--r--Runtime/Utilities/Exception.h6
-rw-r--r--Runtime/Utilities/NonCopyable.h14
-rw-r--r--Runtime/Utilities/Singleton.h43
-rw-r--r--Runtime/Utilities/Type.h21
-rw-r--r--Runtime/Utilities/UIDGenerator.h20
-rw-r--r--Runtime/Utilities/Utf8.cpp0
-rw-r--r--Runtime/Utilities/Utf8.h0
-rw-r--r--Runtime/Utilities/UtilMacros.h16
-rw-r--r--Runtime/main.cpp6
126 files changed, 6409 insertions, 197 deletions
diff --git a/Editor/GUI/Dock.cpp b/Editor/GUI/Dock.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Editor/GUI/Dock.cpp
diff --git a/Editor/GUI/Dock.h b/Editor/GUI/Dock.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Editor/GUI/Dock.h
diff --git a/Editor/GUI/EditorWindows.cpp b/Editor/GUI/EditorWindows.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Editor/GUI/EditorWindows.cpp
diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h
new file mode 100644
index 0000000..90e71a4
--- /dev/null
+++ b/Editor/GUI/EditorWindows.h
@@ -0,0 +1,28 @@
+#ifndef EDITOR_WINDOW_H
+#define EDITOR_WINDOW_H
+
+#include <windows.h>
+
+// Ò»¸öcontainner windowÖÐÓжà¸öviewport
+class ContainnerWindow
+{
+public:
+
+private:
+ HWND m_Window;
+ POINT m_Size;
+
+};
+
+
+// ´°¿ÚÄڵĵ¥¸öviewport
+class Viewport
+{
+public:
+
+private:
+ HWND m_View;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Editor/GUI/MenuController.cpp b/Editor/GUI/MenuController.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Editor/GUI/MenuController.cpp
diff --git a/Editor/GUI/MenuController.h b/Editor/GUI/MenuController.h
new file mode 100644
index 0000000..9abe9e5
--- /dev/null
+++ b/Editor/GUI/MenuController.h
@@ -0,0 +1,11 @@
+#ifndef MENU_CONTROLLER_H
+#define MENU_CONTROLLER_H
+
+// ¹ÜÀímenu item
+
+class MenuController {
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/Editor/main.cpp b/Editor/main.cpp
new file mode 100644
index 0000000..58e5f04
--- /dev/null
+++ b/Editor/main.cpp
@@ -0,0 +1,43 @@
+extern "C" {
+#include "wog.h"
+}
+
+#include <glad/glad.h>
+#include <windows.h>
+
+wog_Window * wnd ;
+
+void* proc(const char *name) {
+ return wglGetProcAddress(name);
+}
+
+int main(int argc, char* argv[]) {
+ wnd = wog_createWindow("GameLab" , 800, 600, 500, 500, 0);
+ wog_show(wnd);
+
+ wog_GLContext* ctx = wog_createGLContext(wnd);
+ wog_makeCurrent(wnd, ctx);
+
+ //gladLoadGLLoader(proc);
+ int load = gladLoadGL();
+
+// wog_makeCurrent(wnd, ctx);
+
+ while (true) {
+ wog_Event e;
+ while (wog_pollEvent(wnd, &e)) {
+ if (e.type == WOG_ECLOSE)
+ goto quit;
+ }
+ //glViewport(0, 0, 500, 500);
+ glClearColor(0.16, 0.16, 0.16, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glFlush();
+
+ wog_swapBuffers(wnd);
+ }
+
+quit:
+
+ return 0;
+}
diff --git a/Editor/wog.c b/Editor/wog.c
new file mode 100644
index 0000000..6cfbf64
--- /dev/null
+++ b/Editor/wog.c
@@ -0,0 +1,746 @@
+/**
+* Copyright (c) 2015~2017 chai(neonum)
+*
+* This library is free software; you can redistribute it and/or modify it
+* under the terms of the MIT license. See LICENSE for details.
+*/
+
+#include "wog.h"
+#include <windows.h>
+#include <malloc.h>
+#include <stdio.h>
+#include <memory.h>
+#include <assert.h>
+
+#if WOG_API == WOG_GL
+#include <gl/GL.h>
+#include <gl/GLU.h>
+#endif
+
+
+#if WOG_API == WOG_GL
+/**
+* We need opengl32.lib and glu32.lib for using opengl functions on
+* windows platform.
+*/
+#pragma comment( lib, "opengl32.lib" )
+//#pragma comment( lib, "glu32.lib" )
+#endif
+
+#define WINDOW_CLASS "WOG_WND"
+
+#define heap_alloc(T, C) (T*)malloc(sizeof(T)*(C))
+#define stack_alloc(T, C) (T*)alloca(sizeof(T)*(C))
+#define zero_mem(I, L) memset(I, 0, L)
+
+#define max(a, b) (a < b ? b : a)
+#define min(a, b) (a < b ? a : b)
+#define clamp(x, minv, maxv) (max(minv, min(x, maxv)))
+
+static HINSTANCE g_hinstance = NULL;
+
+typedef struct wog_Window
+{
+ HWND hwnd; // Window handler
+ HINSTANCE hInstance;
+ HDC hdc; // Device Context
+ HDC mdc; // Memory Device Contexts
+#if WOG_API == WOG_GDI
+ wog_Surface* surface; // render buffer
+#endif
+ int mouse_capture; // mouse capture count
+}wog_Window;
+
+#if WOG_API == WOG_GL
+typedef struct wog_GLContext
+{
+ HGLRC hrc; // Rendering Context
+}wog_GLContext;
+#endif
+
+// A mouse capture count is used
+void wog_setMouseCapture(wog_Window* wnd)
+{
+ if (wnd->mouse_capture <= 0)
+ {
+ SetCapture(wnd->hwnd);
+ wnd->mouse_capture = 0;
+ }
+ ++wnd->mouse_capture;
+}
+
+void wog_releaseMouseCapture(wog_Window* wnd)
+{
+ --wnd->mouse_capture;
+ if (wnd->mouse_capture <= 0)
+ ReleaseCapture();
+}
+
+void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
+{
+ UINT uMsg;
+ WPARAM wParam;
+ LPARAM lParam;
+ uMsg = msg->message;
+ wParam = msg->wParam;
+ lParam = msg->lParam;
+ HWND hWnd = window->hwnd;
+
+ switch (uMsg)
+ {
+ case WM_SYSCOMMAND:
+ {
+ switch (wParam)
+ {
+ case SC_SCREENSAVE:
+ case SC_MONITORPOWER:
+ return ;
+ }
+ break;
+ }
+ return ;
+
+ case WM_CLOSE:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_ECLOSE;
+ return ;
+ }
+
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ if ((wParam >= 0) && (wParam <= 255))
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EKEYDOWN;
+ e->key = wParam;
+
+ return ;
+ }
+ break;
+
+ case WM_KEYUP:
+ case WM_SYSKEYUP:
+ if ((wParam >= 0) && (wParam <= 255))
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EKEYUP;
+ e->key = wParam;
+
+ return ;
+ }
+ break;
+
+ case WM_MOUSEMOVE:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEMOTION;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ return ;
+ }
+
+ case WM_MOUSEWHEEL: // mousewheel scroll
+ {
+ int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEWHEEL;
+ e->wheel = zDelta > 0 ? 1 : -1;
+ return ;
+ }
+
+ case WM_LBUTTONDOWN:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONDOWN;
+ e->button = WOG_MOUSE_LBUTTON;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_setMouseCapture(window);
+ return ;
+ }
+
+ case WM_RBUTTONDOWN:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONDOWN;
+ e->button = WOG_MOUSE_RBUTTON;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_setMouseCapture(window);
+ return ;
+ }
+
+ case WM_MBUTTONDOWN:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONDOWN;
+ e->button = WOG_MOUSE_MIDDLE;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_setMouseCapture(window);
+ return ;
+ }
+
+ case WM_LBUTTONUP:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONUP;
+ e->button = WOG_MOUSE_LBUTTON;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_releaseMouseCapture(window);
+ return ;
+ }
+
+ case WM_RBUTTONUP:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONUP;
+ e->button = WOG_MOUSE_RBUTTON;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_releaseMouseCapture(window);
+ return ;
+ }
+
+ case WM_MBUTTONUP:
+ {
+ zero_mem(e, sizeof(wog_Event));
+ e->type = WOG_EMOUSEBUTTONUP;
+ e->button = WOG_MOUSE_MIDDLE;
+ wog_getMouse(window, &e->pos.x, &e->pos.y);
+ wog_releaseMouseCapture(window);
+ return ;
+ }
+
+ case WM_PAINT:
+
+ UpdateWindow(window->hwnd);
+
+ return 0;
+
+ break;
+
+ default:
+ e->type = WOG_EUNKNOWN;
+ break;
+ }
+ DefWindowProc(hWnd, uMsg, wParam, lParam);
+ return ;
+}
+
+
+int wog_pollEvent(wog_Window* wnd, wog_Event* e)
+{
+ MSG msg;
+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ if (msg.message == WM_QUIT) return 0;
+ TranslateMessage(&msg);
+ wog_handleEvent(wnd, &msg, e);
+ return 1;
+ }
+ return 0;
+}
+
+
+// on size changed callback;
+static wog_Callback onSizeChanged = 0;
+static wog_Callback onQuit = 0;
+
+
+static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ // Get The Window Context
+ wog_Window* window = (wog_Window*)(GetWindowLong(hWnd, GWL_USERDATA));
+
+ // call callback functions
+#define call(callback)\
+ if (callback) \
+ callback(window)
+
+ switch (uMsg)
+ {
+ case WM_CREATE:
+ {
+ CREATESTRUCT* creation = (CREATESTRUCT*)(lParam); // Store Window Structure Pointer
+ window = (wog_Window*)(creation->lpCreateParams); // Get wog_Window
+ SetWindowLong(hWnd, GWL_USERDATA, (LONG)(window)); // Save it
+ }
+ return 0;
+
+ case WM_CLOSE: // Post WM_CLOSE to message queue.
+ PostMessage(hWnd, WM_CLOSE, wParam, lParam);
+ return 0;
+
+ case WM_SIZE:
+ call(onSizeChanged);
+ return 0;
+
+ case WM_QUIT:
+ call(onQuit);
+ return 0;
+
+ }
+
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+#undef call
+}
+
+
+void wog_registerResizeCallback(wog_Callback cal)
+{
+ onSizeChanged = cal;
+}
+
+
+void wog_registerQuitCallback(wog_Callback cal)
+{
+ onQuit = cal;
+}
+
+#if WOG_API == WOG_GDI
+wog_Surface* wog_getsurface(wog_Window* wnd) {
+ return wnd->surface;
+}
+#endif
+
+static int registerWindowClass()
+{
+ // Register A Window Class
+ WNDCLASSEX windowClass; // Window Class
+ zero_mem(&windowClass, sizeof(WNDCLASSEX)); // Make Sure Memory Is Cleared
+
+ windowClass.cbSize = sizeof(WNDCLASSEX); // Size Of The windowClass Structure
+ windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraws The Window For Any Movement / Resizing
+ windowClass.lpfnWndProc = (WNDPROC)(WindowProc); // WindowProc Handles Messages
+ windowClass.hInstance = g_hinstance; // Set The Instance
+ windowClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE); // Class Background Brush Color
+ windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
+ windowClass.lpszClassName = WINDOW_CLASS; // Sets The Applications Classname
+ //windowClass.hIcon = (HICON)LoadIcon(g_hinstance, "icon.ico");
+
+ if (RegisterClassEx(&windowClass) == 0) // Did Registering The Class Fail?
+ {
+ // NOTE: Failure, Should Never Happen
+ MessageBox(HWND_DESKTOP, "RegisterClassEx Failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
+ return FALSE; // Return False (Failure)
+ }
+ return TRUE;
+}
+
+/*
+ * for memory device context, see
+ * https://docs.microsoft.com/en-us/windows/desktop/gdi/memory-device-contexts
+ * also
+ * SDL_windowsframebuffer.c WIN_CreateWindowFramebuffer
+ */
+static void create_surface(wog_Window* wnd, int width, int height) {
+ BITMAPINFOHEADER bi_header;
+ HDC memory_dc;
+ HBITMAP dib_bitmap;
+ HBITMAP old_bitmap;
+ unsigned char *buffer; // color buffer
+ wog_Surface *surface;
+
+ memory_dc = CreateCompatibleDC(wnd->hdc); /*memory device contexts*/
+
+ memset(&bi_header, 0, sizeof(BITMAPINFOHEADER));
+ bi_header.biSize = sizeof(BITMAPINFOHEADER);
+ bi_header.biWidth = width;
+ bi_header.biHeight = -height; /* top-down */
+ bi_header.biPlanes = 1;
+ bi_header.biBitCount = 32;
+ bi_header.biCompression = BI_RGB;
+ /*create bitmap*/
+ dib_bitmap = CreateDIBSection(memory_dc, (BITMAPINFO*)&bi_header, DIB_RGB_COLORS, (void**)&buffer, NULL, 0);
+ assert(dib_bitmap != NULL);
+ old_bitmap = (HBITMAP)SelectObject(memory_dc, dib_bitmap);
+ DeleteObject(old_bitmap);
+
+ surface = (wog_Surface*)malloc(sizeof(wog_Surface));
+ surface->width = width;
+ surface->height = height;
+ surface->channels = 4;
+ surface->buffer = buffer;
+
+#if WOG_API == WOG_GDI
+ wnd->surface = surface;
+#endif
+ wnd->mdc = memory_dc;
+}
+
+
+wog_Window* wog_createWindow(const char* title, int width, int height, int x, int y, uint32 flags)
+{
+ int client_w = width, client_h = height;
+
+ if (g_hinstance == NULL)
+ {
+ g_hinstance = GetModuleHandle(NULL);
+ }
+
+ if (! registerWindowClass())
+ {
+ printf("Register window class failed.\n");
+ return 0;
+ }
+
+ wog_Window* wnd = heap_alloc(wog_Window, 1);
+ zero_mem(wnd, sizeof(wog_Window));
+
+ DWORD windowStyle = 0; // Define Our Window Style
+ windowStyle |= WS_POPUP;
+ windowStyle |= WS_OVERLAPPED;
+ windowStyle |= WS_CAPTION;
+ windowStyle |= WS_SYSMENU;
+ windowStyle |= WS_MINIMIZEBOX;
+ windowStyle |= WS_MAXIMIZEBOX;
+ //windowStyle |= WS_VISIBLE;
+#define hasbit(fs, f) ((fs & f) == f)
+ /*if (hasbit(flags, WOG_RESIZABLE)) */windowStyle |= WS_SIZEBOX;
+ if (hasbit(flags, WOG_DISABLE)) windowStyle |= WS_DISABLED;
+
+ DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style
+ RECT windowRect = { 0, 0, width, height };
+ AdjustWindowRectEx(&windowRect, windowStyle, 0, windowExtendedStyle);
+ width = windowRect.right - windowRect.left;
+ height = windowRect.bottom - windowRect.top;
+ wnd->hwnd = CreateWindowEx(
+ windowExtendedStyle,
+ WINDOW_CLASS,
+ title,
+ windowStyle,
+ x, y,
+ width, height,
+ HWND_DESKTOP,
+ 0,
+ GetModuleHandle(NULL),
+ wnd
+ );
+
+ wnd->hInstance = g_hinstance;
+
+ if (wnd->hwnd == 0)
+ return 0;
+
+ if (hasbit(flags, WOG_HIDDEN)) wog_hide(wnd);
+
+ // init device context
+ wnd->hdc = GetDC(wnd->hwnd);
+ if (wnd->hdc== 0)
+ {
+ DestroyWindow(wnd->hwnd);
+ wnd->hwnd = 0;
+ return 0;
+ }
+
+ wnd->mouse_capture = 0;
+
+#if WOG_API == WOG_GDI
+ create_surface(wnd, client_w, client_h);
+#endif
+
+#if WOG_API == WOG_GL
+ PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
+ {
+ sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
+ 1, // Version Number
+ PFD_DRAW_TO_WINDOW | // Format Must Support Window
+ PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
+ PFD_DOUBLEBUFFER, // Must Support Double Buffering
+ PFD_TYPE_RGBA, // Request An RGBA Format
+ 32, // Select Our Color Depth
+ 0, 0, 0, 0, 0, 0, // Color Bits Ignored
+ 0, // No Alpha Buffer
+ 0, // Shift Bit Ignored
+ 0, // No Accumulation Buffer
+ 0, 0, 0, 0, // Accumulation Bits Ignored
+ 16, // 16Bit Z-Buffer (Depth Buffer)
+ 0, // No Stencil Buffer
+ 0, // No Auxiliary Buffer
+ PFD_MAIN_PLANE, // Main Drawing Layer
+ 0, // Reserved
+ 0, 0, 0 // Layer Masks Ignored
+ };
+ // set pixel format
+ unsigned int pixelformat;
+ pixelformat = ChoosePixelFormat(wnd->hdc, &pfd);
+ if (pixelformat == 0)
+ {
+ wog_destroyWindow(wnd);
+ return 0;
+ }
+
+ // set pixel format
+ if (SetPixelFormat(wnd->hdc, pixelformat, &pfd) == 0 )
+ {
+ wog_destroyWindow(wnd);
+ return 0;
+ }
+#endif
+
+ return wnd;
+}
+
+#if WOG_API == WOG_GL
+wog_GLContext* wog_createGLContext(wog_Window* wnd)
+{
+ wog_GLContext* cxt = heap_alloc(wog_GLContext, 1);
+ zero_mem(cxt, sizeof(wog_GLContext));
+ cxt->hrc = wglCreateContext(wnd->hdc); // create opengl context base on device context
+ if (cxt->hrc == 0)
+ {
+ free(cxt);
+ return 0;
+ }
+ return cxt;
+}
+#endif
+
+#if WOG_API == WOG_GL
+int wog_makeCurrent(wog_Window* wnd, wog_GLContext* cxt)
+{
+ if (wnd && cxt)
+ {
+ if (wglMakeCurrent(wnd->hdc, cxt->hrc) == 0)
+ {
+ return 0;
+ }
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
+#if WOG_API == WOG_GL
+void wog_destroyGLContext(wog_GLContext* cxt)
+{
+ if (cxt && cxt->hrc)
+ {
+ wglDeleteContext(cxt->hrc);
+ free(cxt);
+ }
+}
+#endif
+
+#if WOG_API == WOG_GDI
+void wog_updateSurface(wog_Window* wnd) {
+ if(wnd->surface == NULL) return ;
+ int width = wnd->surface->width, height = wnd->surface->height;
+ BitBlt(wnd->hdc, 0, 0, wnd->surface, height, wnd->mdc, 0, 0, SRCCOPY);
+}
+#endif
+
+void wog_destroyWindow(wog_Window* wnd)
+{
+ if (wnd)
+ {
+ ReleaseDC(wnd->hwnd, wnd->hdc);
+ DestroyWindow(wnd->hwnd);
+ free(wnd);
+ }
+}
+
+
+static void UnEscapeQuotes(char *arg)
+{
+ char *last = NULL;
+
+ while (*arg) {
+ if (*arg == '"' && *last == '\\') {
+ char *c_curr = arg;
+ char *c_last = last;
+
+ while (*c_curr) {
+ *c_last = *c_curr;
+ c_last = c_curr;
+ c_curr++;
+ }
+ *c_last = '\0';
+ }
+ last = arg;
+ arg++;
+ }
+}
+
+
+/* Parse a command line buffer into arguments */
+static int ParseCommandLine(char *cmdline, char **argv)
+{
+ char *bufp;
+ char *lastp = NULL;
+ int argc, last_argc;
+
+ argc = last_argc = 0;
+ for (bufp = cmdline; *bufp; ) {
+ /* Skip leading whitespace */
+ while (isspace(*bufp)) {
+ ++bufp;
+ }
+ /* Skip over argument */
+ if (*bufp == '"') {
+ ++bufp;
+ if (*bufp) {
+ if (argv) {
+ argv[argc] = bufp;
+ }
+ ++argc;
+ }
+ /* Skip over word */
+ while (*bufp && (*bufp != '"' || (lastp && *lastp == '\\'))) {
+ lastp = bufp;
+ ++bufp;
+ }
+ }
+ else {
+ if (*bufp) {
+ if (argv) {
+ argv[argc] = bufp;
+ }
+ ++argc;
+ }
+ /* Skip over word */
+ while (*bufp && !isspace(*bufp)) {
+ ++bufp;
+ }
+ }
+ if (*bufp) {
+ if (argv) {
+ *bufp = '\0';
+ }
+ ++bufp;
+ }
+
+ /* Strip out \ from \" sequences */
+ if (argv && last_argc != argc) {
+ UnEscapeQuotes(argv[last_argc]);
+ }
+ last_argc = argc;
+ }
+ if (argv) {
+ argv[argc] = NULL;
+ }
+ return(argc);
+}
+
+
+#ifdef main
+#undef main
+#endif
+
+
+#if defined(_MSC_VER) && !defined(_WIN32_WCE)
+/* The VC++ compiler needs main defined */
+#define console_main main
+#endif
+
+extern int wog_main(int argc, char* argv[]);
+
+/**
+* Entry of console application.
+*/
+int console_main(int argc, char* argv[])
+{
+ int status = wog_main(argc, argv);
+ return status;
+}
+
+
+/**
+* Entry of windows application.
+*/
+int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
+{
+ g_hinstance = hInst;
+
+ char* temp = GetCommandLine();
+ int len = strlen(temp) + 1;
+ char* cmd = stack_alloc(char, len);
+ strcpy(cmd, temp);
+ cmd[len - 1] = '\0';
+
+ int argc = 0;
+ char** argv = 0;
+ argc = ParseCommandLine(cmd, 0);
+ ParseCommandLine(cmd, 0);
+ argv = stack_alloc(char*, argc + 1);
+ ParseCommandLine(cmd, argv);
+
+ int status = console_main(argc, argv);
+
+ return status;
+}
+
+
+void wog_swapBuffers(wog_Window* wnd)
+{
+ if (wnd)
+ {
+ SwapBuffers(wnd->hdc);
+ }
+}
+
+
+void wog_getMouse(wog_Window* wnd, int *x, int *y)
+{
+ POINT p;
+ GetCursorPos(&p);
+ ScreenToClient(wnd->hwnd, &p);
+ int w, h;
+ wog_getwindowsize(wnd, &w, &h);
+ //*x = clamp(p.x, 0, w);
+ //*y = clamp(p.y, 0, h);
+ *x = p.x;
+ *y = p.y;
+}
+
+
+void wog_getwindowsize(wog_Window* wnd, int* width, int* height)
+{
+ RECT r;
+ GetClientRect(wnd->hwnd, &r);
+ *width = r.right;
+ *height = r.bottom;
+}
+
+
+void wog_show(wog_Window* wnd)
+{
+ ShowWindow(wnd->hwnd, SW_SHOW);
+}
+
+
+void wog_hide(wog_Window* wnd)
+{
+ ShowWindow(wnd->hwnd, SW_HIDE);
+}
+
+
+void wog_sleep(int ms)
+{
+ Sleep(ms);
+}
+
+int wog_tick()
+{
+ return GetTickCount();
+}
+
+
+void wog_setcursor(wog_Window* wnd, unsigned int cursor)
+{
+ SetCursor(LoadCursor(NULL, cursor));
+}
+
+//void wog_setcursorImage(wog_Window* wnd, const char* path)
+//{
+// SetCursor(LoadImageA(NULL, path, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE));
+// printf("wog_setcursorImage\n");
+//}
+
+void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon)
+{
+ SetCursor(icon);
+}
+
+HINSTANCE wog_get_instance()
+{
+ return g_hinstance;
+}
diff --git a/Editor/wog.h b/Editor/wog.h
new file mode 100644
index 0000000..f5661db
--- /dev/null
+++ b/Editor/wog.h
@@ -0,0 +1,219 @@
+/*
+* Copyright (c) 2015~2020 chai
+*/
+
+#ifndef _WOG_H
+#define _WOG_H
+#include <Windows.h> // for virtual key value
+
+#define WOG_GL 1
+#define WOG_GDI 2
+
+#define WOG_API WOG_GL
+
+typedef unsigned int uint32;
+typedef unsigned short uint16;
+
+enum // event type
+{
+ WOG_EUNKNOWN = 0, // unknown event
+
+ WOG_EKEYDOWN, // key pressed
+ WOG_EKEYUP, // key released
+
+ WOG_EMOUSEMOTION, // mouse motion
+ WOG_EMOUSEWHEEL, // mouse wheel scrolling
+ WOG_EMOUSEBUTTONDOWN, // mosue button down
+ WOG_EMOUSEBUTTONUP, // mosue button down
+
+ WOG_ECLOSE, // close window
+};
+
+enum // mouse button event, e.button value
+{
+ WOG_MOUSE_LBUTTON, // left mouse button
+ WOG_MOUSE_RBUTTON, // right mouse button
+ WOG_MOUSE_MIDDLE, // middle button
+};
+
+typedef struct wog_Event
+{
+ int type;
+ //union // event value
+ //{
+ int key; // for key, simply use windows virtual key value
+ // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
+ struct // for mouse motion
+ {
+ int x, y; // mouse position
+ }pos;
+ int wheel; // 1 indicate scroll up and -1 indicate scrool down
+ int button; // mouse button
+ //};
+}wog_Event;
+
+//* VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
+ //* 0x40 : unassigned
+ //* VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
+
+//¶¨ÒåÊý¾Ý×Ö·û0~9
+#define VK_0 0x30
+#define VK_1 0x31
+#define VK_2 0x32
+#define VK_3 0x33
+#define VK_4 0x34
+#define VK_5 0x35
+#define VK_6 0x36
+#define VK_7 0x37
+#define VK_8 0x38
+#define VK_9 0x39
+
+//¶¨ÒåÊý¾Ý×Ö·ûA~Z
+#define VK_A 0x41
+#define VK_B 0x42
+#define VK_C 0x43
+#define VK_D 0x44
+#define VK_E 0x45
+#define VK_F 0x46
+#define VK_G 0x47
+#define VK_H 0x48
+#define VK_I 0x49
+#define VK_J 0x4A
+#define VK_K 0x4B
+#define VK_L 0x4C
+#define VK_M 0x4D
+#define VK_N 0x4E
+#define VK_O 0x4F
+#define VK_P 0x50
+#define VK_Q 0x51
+#define VK_R 0x52
+#define VK_S 0x53
+#define VK_T 0x54
+#define VK_U 0x55
+#define VK_V 0x56
+#define VK_W 0x57
+#define VK_X 0x58
+#define VK_Y 0x59
+#define VK_Z 0x5A
+
+//¶¨ÒåÊý¾Ý×Ö·ûa~z
+#define VK_a 0x61
+#define VK_b 0x62
+#define VK_c 0x63
+#define VK_d 0x64
+#define VK_e 0x65
+#define VK_f 0x66
+#define VK_g 0x67
+#define VK_h 0x68
+#define VK_i 0x69
+#define VK_j 0x6A
+#define VK_k 0x6B
+#define VK_l 0x6C
+#define VK_m 0x6D
+#define VK_n 0x6E
+#define VK_o 0x6F
+#define VK_p 0x70
+#define VK_q 0x71
+#define VK_r 0x72
+#define VK_s 0x73
+#define VK_t 0x74
+#define VK_u 0x75
+#define VK_v 0x76
+#define VK_w 0x77
+#define VK_x 0x78
+#define VK_y 0x79
+#define VK_z 0x7A
+
+typedef struct {
+ int width, height, channels;
+ unsigned char* buffer;
+} wog_Surface;
+
+/**
+* Entry of user program which defined in user project. You need provide
+* this function's defination.
+*/
+#define main wog_main
+extern int wog_main(int argc, char* argv[]);
+
+typedef struct wog_Window wog_Window;
+
+#if WOG_API == WOG_GL
+/**
+* Struct that hold opengl context generated by wglCreateContext() which
+* defined in opengl32.lib
+*/
+typedef struct wog_GLContext wog_GLContext;
+#endif
+
+enum // window style flag
+{
+ WOG_HIDDEN = 4,
+ WOG_RESIZABLE = 8,
+ WOG_DISABLE = 16,
+};
+
+/**
+* Create window with given configures.
+* flag would be:
+* WOG_HIDDEN
+* WOG_RESIZABLE
+* WOG_DISABLE
+* or just 0;
+*/
+wog_Window* wog_createWindow(const char* title, int width, int height, int x, int y, uint32 flags);
+
+#if WOG_API == WOG_GL
+wog_GLContext* wog_createGLContext(wog_Window* wnd);
+
+int wog_makeCurrent(wog_Window* wnd, wog_GLContext* cxt);
+
+void wog_destroyGLContext(wog_GLContext* cxt);
+#endif
+
+void wog_destroyWindow(wog_Window* wnd);
+
+#if WOG_API == WOG_GL
+void wog_swapBuffers(wog_Window* wnd);
+#endif
+
+#if WOG_API == WOG_GDI
+void wog_updateSurface(wog_Window* wnd);
+#endif
+
+int wog_pollEvent(wog_Window* wnd, wog_Event* e);
+
+void wog_getMouse(wog_Window* wnd, int *x, int *y);
+
+// get current ticks
+int wog_tick();
+
+void wog_sleep(int ms);
+
+void wog_getwindowsize(wog_Window* wnd, int* width, int* height);
+
+void wog_show(wog_Window* wnd);
+
+void wog_hide(wog_Window* wnd);
+
+typedef void(*wog_Callback)(wog_Window* wnd) ;
+
+/**
+* Register callback functions.
+*/
+void wog_registerResizeCallback(wog_Callback cal);
+void wog_registerQuitCallback(wog_Callback cal);
+
+wog_Surface* wog_getsurface(wog_Window* wnd);
+
+void wog_setcursor(wog_Window* wnd, unsigned int cursor);
+//void wog_setcursorImage(wog_Window* wnd, const char* path);
+typedef HANDLE Wog_Cursor;
+void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon);
+
+void wog_setMouseCapture(wog_Window* wnd);
+void wog_releaseMouseCapture(wog_Window* wnd);
+
+HINSTANCE wog_get_instance();
+
+#endif \ No newline at end of file
diff --git a/Projects/VisualStudio/.vs/Jin/v15/.suo b/Projects/VisualStudio/.vs/Jin/v15/.suo
deleted file mode 100644
index 8b4def7..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/.suo
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/.vs/Jin/v15/Browse.VC.db b/Projects/VisualStudio/.vs/Jin/v15/Browse.VC.db
deleted file mode 100644
index 60080a9..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/Browse.VC.db
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/.vs/Jin/v15/Solution.VC.db b/Projects/VisualStudio/.vs/Jin/v15/Solution.VC.db
deleted file mode 100644
index b5f9a99..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/Solution.VC.db
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/19f11c8463ef0178/DEVICE.ipch b/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/19f11c8463ef0178/DEVICE.ipch
deleted file mode 100644
index 66245be..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/19f11c8463ef0178/DEVICE.ipch
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/75d245bf98f791a/MAIN.ipch b/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/75d245bf98f791a/MAIN.ipch
deleted file mode 100644
index 459655c..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/75d245bf98f791a/MAIN.ipch
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/7e12c6410b8f7e79/MAINS.ipch b/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/7e12c6410b8f7e79/MAINS.ipch
deleted file mode 100644
index 93759f3..0000000
--- a/Projects/VisualStudio/.vs/Jin/v15/ipch/AutoPCH/7e12c6410b8f7e79/MAINS.ipch
+++ /dev/null
Binary files differ
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj
index 3f32198..6d95bed 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj
@@ -87,6 +87,8 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>D:\Documents\VisualStudio2017\Projects\GameLab\ThirdParty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -98,9 +100,12 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
+ <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>D:\Documents\VisualStudio2017\Projects\GameLab\ThirdParty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
+ <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -134,6 +139,22 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="..\..\..\Editor\GUI\Dock.cpp" />
+ <ClCompile Include="..\..\..\Editor\GUI\EditorWindows.cpp" />
+ <ClCompile Include="..\..\..\Editor\GUI\MenuController.cpp" />
+ <ClCompile Include="..\..\..\Editor\main.cpp" />
+ <ClCompile Include="..\..\..\Editor\wog.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\Editor\GUI\Dock.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\EditorWindows.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\MenuController.h" />
+ <ClInclude Include="..\..\..\Editor\wog.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\glad\glad.vcxproj">
+ <Project>{385f2d3a-1cef-4aa1-8051-527f6b68dd81}</Project>
+ </ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
index 9cd8510..2614cc9 100644
--- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters
+++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters
@@ -1,2 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="GUI">
+ <UniqueIdentifier>{87a57ef1-78d8-42b8-b179-ce1bbb5c4f8b}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\..\Editor\GUI\MenuController.cpp">
+ <Filter>GUI</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Editor\GUI\Dock.cpp">
+ <Filter>GUI</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Editor\main.cpp" />
+ <ClCompile Include="..\..\..\Editor\wog.c" />
+ <ClCompile Include="..\..\..\Editor\GUI\EditorWindows.cpp">
+ <Filter>GUI</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\..\Editor\GUI\MenuController.h">
+ <Filter>GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Editor\GUI\Dock.h">
+ <Filter>GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Editor\wog.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\EditorWindows.h">
+ <Filter>GUI</Filter>
+ </ClInclude>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Projects/VisualStudio/Jin.sln b/Projects/VisualStudio/GameLab.sln
index 5ebfa47..aac6292 100644
--- a/Projects/VisualStudio/Jin.sln
+++ b/Projects/VisualStudio/GameLab.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1022
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Runner", "Runner\Runner.vcxproj", "{4C26BDCC-CA08-4C43-8EFF-B62A204D5FBD}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Runtime", "Runtime\Runtime.vcxproj", "{4C26BDCC-CA08-4C43-8EFF-B62A204D5FBD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL2", "SDL2\SDL2.vcxproj", "{8658F91C-9AAE-4819-9005-77D09C61D97F}"
EndProject
@@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stb", "stb\stb.vcxproj", "{
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{49F29C84-8A46-4421-9F93-CA96A9292716}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGUI", "ImGUI\ImGUI.vcxproj", "{A93844EE-1BF4-42A9-B58C-27192721A063}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -103,6 +105,14 @@ Global
{49F29C84-8A46-4421-9F93-CA96A9292716}.Release|x64.Build.0 = Release|x64
{49F29C84-8A46-4421-9F93-CA96A9292716}.Release|x86.ActiveCfg = Release|Win32
{49F29C84-8A46-4421-9F93-CA96A9292716}.Release|x86.Build.0 = Release|Win32
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Debug|x64.ActiveCfg = Debug|x64
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Debug|x64.Build.0 = Debug|x64
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Debug|x86.ActiveCfg = Debug|Win32
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Debug|x86.Build.0 = Debug|Win32
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Release|x64.ActiveCfg = Release|x64
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Release|x64.Build.0 = Release|x64
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Release|x86.ActiveCfg = Release|Win32
+ {A93844EE-1BF4-42A9-B58C-27192721A063}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -115,6 +125,7 @@ Global
{AD09415F-4BF9-4FCE-901F-7AB22D429CFC} = {0F6EE105-E1FF-4770-8314-06F9F98FB68F}
{BFAA8A26-DE6F-4B71-8851-3FF3CF0C8B9F} = {0F6EE105-E1FF-4770-8314-06F9F98FB68F}
{49F29C84-8A46-4421-9F93-CA96A9292716} = {0F6EE105-E1FF-4770-8314-06F9F98FB68F}
+ {A93844EE-1BF4-42A9-B58C-27192721A063} = {0F6EE105-E1FF-4770-8314-06F9F98FB68F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C78D376C-9B0B-4EF0-A7D1-0F612F43E793}
diff --git a/Projects/VisualStudio/ImGUI/ImGUI.vcxproj b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj
new file mode 100644
index 0000000..615e945
--- /dev/null
+++ b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>15.0</VCProjectVersion>
+ <ProjectGuid>{A93844EE-1BF4-42A9-B58C-27192721A063}</ProjectGuid>
+ <RootNamespace>ImGUI</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/Projects/VisualStudio/ImGUI/ImGUI.vcxproj.filters b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj.filters
new file mode 100644
index 0000000..9cd8510
--- /dev/null
+++ b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj.filters
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
diff --git a/Projects/VisualStudio/Runner/Runner.vcxproj.user b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj.user
index be25078..be25078 100644
--- a/Projects/VisualStudio/Runner/Runner.vcxproj.user
+++ b/Projects/VisualStudio/ImGUI/ImGUI.vcxproj.user
diff --git a/Projects/VisualStudio/Runner/Runner.vcxproj b/Projects/VisualStudio/Runtime/Runtime.vcxproj
index 91f731c..c0179de 100644
--- a/Projects/VisualStudio/Runner/Runner.vcxproj
+++ b/Projects/VisualStudio/Runtime/Runtime.vcxproj
@@ -19,103 +19,108 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\..\..\Runner\FileSystem\FileSystem.h" />
- <ClInclude Include="..\..\..\Runner\FileSystem\Unzip.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\Color.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\GpuDataBuffer.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\Device.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\DeviceDefine.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\FrameBuffer.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\OpenGL.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\RenderTexture.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\ImageData.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\PolyLine.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\Point.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\Quad.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\GlyphAtlas.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\Texture.h" />
- <ClInclude Include="..\..\..\Runner\Graphics\VertexBuffer.h" />
- <ClInclude Include="..\..\..\Runner\Input\Input.h" />
- <ClInclude Include="..\..\..\Runner\Math\AABB.h" />
- <ClInclude Include="..\..\..\Runner\Math\Vector2.h" />
- <ClInclude Include="..\..\..\Runner\Math\Vector3.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\Font.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\FontManager.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\Glyph.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\Mesh.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\MeshUtil.h" />
- <ClInclude Include="..\..\..\Runner\Mesh\TextMesh.h" />
- <ClInclude Include="..\..\..\Runner\Profiler\FrameStats.h" />
- <ClInclude Include="..\..\..\Runner\Profiler\Profiler.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_cfunctions.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_class.hpp" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_config.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_enum.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_globalstate.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_internal.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_memberref.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_ref.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_reftable.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_state.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_utility.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_vm.h" />
- <ClInclude Include="..\..\..\Runner\Scripting\luax_watchdog.h" />
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderChannel.h" />
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderDefine.h" />
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderUniform.h" />
- <ClInclude Include="..\..\..\Runner\Threads\Mutex.h" />
- <ClInclude Include="..\..\..\Runner\Threads\Semaphore.h" />
- <ClInclude Include="..\..\..\Runner\Threads\Thread.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Assert.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Base64.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Exception.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\NonCopyable.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Singleton.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Type.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\UIDGenerator.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\Utf8.h" />
- <ClInclude Include="..\..\..\Runner\Utilities\UtilMacros.h" />
+ <ClInclude Include="..\..\..\Runtime\FileSystem\FileSystem.h" />
+ <ClInclude Include="..\..\..\Runtime\FileSystem\Unzip.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Color.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Device.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\DeviceDefine.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\FrameBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\OpenGL.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\RenderTexture.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\PolyLine.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Point.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Quad.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\Texture.h" />
+ <ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h" />
+ <ClInclude Include="..\..\..\Runtime\ImGUI\GUIButton.h" />
+ <ClInclude Include="..\..\..\Runtime\ImGUI\GUILabel.h" />
+ <ClInclude Include="..\..\..\Runtime\Input\Input.h" />
+ <ClInclude Include="..\..\..\Runtime\Math\AABB.h" />
+ <ClInclude Include="..\..\..\Runtime\Math\Vector2.h" />
+ <ClInclude Include="..\..\..\Runtime\Math\Vector3.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\Font.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\FontManager.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\Glyph.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\Mesh.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\MeshUtil.h" />
+ <ClInclude Include="..\..\..\Runtime\Mesh\TextMesh.h" />
+ <ClInclude Include="..\..\..\Runtime\Physics\Rigidbody.h" />
+ <ClInclude Include="..\..\..\Runtime\Profiler\FrameStats.h" />
+ <ClInclude Include="..\..\..\Runtime\Profiler\Profiler.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_cfunctions.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_class.hpp" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_config.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_enum.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_globalstate.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_internal.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_memberref.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_ref.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_reftable.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_state.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_utility.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_vm.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_watchdog.h" />
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderChannel.h" />
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderDefine.h" />
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderUniform.h" />
+ <ClInclude Include="..\..\..\Runtime\Threads\Mutex.h" />
+ <ClInclude Include="..\..\..\Runtime\Threads\Semaphore.h" />
+ <ClInclude Include="..\..\..\Runtime\Threads\Thread.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Assert.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Base64.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Exception.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\NonCopyable.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Singleton.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Type.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\UIDGenerator.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\Utf8.h" />
+ <ClInclude Include="..\..\..\Runtime\Utilities\UtilMacros.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\..\..\Runner\FileSystem\FileSystem.cpp" />
- <ClCompile Include="..\..\..\Runner\FileSystem\Unzip.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\GpuDataBuffer.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Device.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\FrameBuffer.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\OpenGL.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\RenderTexture.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\ImageData.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\PolyLine.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Point.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_Device.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_GL.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_RenderTexture.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Quad.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\GlyphAtlas.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\Texture.cpp" />
- <ClCompile Include="..\..\..\Runner\Graphics\VertexBuffer.cpp" />
- <ClCompile Include="..\..\..\Runner\Input\Input.cpp" />
- <ClCompile Include="..\..\..\Runner\Main.cpp" />
- <ClCompile Include="..\..\..\Runner\Math\Vector2.cpp" />
- <ClCompile Include="..\..\..\Runner\Math\Vector3.cpp" />
- <ClCompile Include="..\..\..\Runner\Mesh\Font.cpp" />
- <ClCompile Include="..\..\..\Runner\Mesh\Mesh.cpp" />
- <ClCompile Include="..\..\..\Runner\Physics\Scripting\wrap_Joint.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_cfunctions.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_class.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_enum.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_memberref.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_ref.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_reftable.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_state.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_vm.cpp" />
- <ClCompile Include="..\..\..\Runner\Scripting\luax_watchdog.cpp" />
- <ClCompile Include="..\..\..\Runner\Shaders\ShaderDefine.cpp" />
- <ClCompile Include="..\..\..\Runner\Threads\Mutex.cpp" />
- <ClCompile Include="..\..\..\Runner\Threads\Semaphore.cpp" />
- <ClCompile Include="..\..\..\Runner\Utilities\Base64.cpp" />
- <ClCompile Include="..\..\..\Runner\Utilities\Utf8.cpp" />
+ <ClCompile Include="..\..\..\Runtime\FileSystem\FileSystem.cpp" />
+ <ClCompile Include="..\..\..\Runtime\FileSystem\Unzip.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Device.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\FrameBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\OpenGL.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\RenderTexture.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\PolyLine.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Point.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_Device.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_GL.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_RenderTexture.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Quad.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\Texture.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp" />
+ <ClCompile Include="..\..\..\Runtime\ImGUI\GUIButton.cpp" />
+ <ClCompile Include="..\..\..\Runtime\ImGUI\GUILabel.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Input\Input.cpp" />
+ <ClCompile Include="..\..\..\Runtime\main.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Math\Vector2.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Math\Vector3.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Mesh\Font.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Mesh\Mesh.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Physics\Scripting\wrap_Joint.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_cfunctions.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_class.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_enum.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_memberref.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_ref.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_reftable.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_state.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_vm.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_watchdog.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Shaders\ShaderDefine.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Threads\Mutex.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Threads\Semaphore.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Utilities\Base64.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Utilities\Utf8.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Box2D\Box2D.vcxproj">
@@ -129,13 +134,13 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="..\..\..\Runner\Scripting\luax_class.inc" />
- <None Include="..\..\..\Runner\Scripting\luax_state.inc" />
+ <None Include="..\..\..\Runtime\Scripting\luax_class.inc" />
+ <None Include="..\..\..\Runtime\Scripting\luax_state.inc" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{4C26BDCC-CA08-4C43-8EFF-B62A204D5FBD}</ProjectGuid>
- <RootNamespace>Runner</RootNamespace>
+ <RootNamespace>Runtime</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
diff --git a/Projects/VisualStudio/Runner/Runner.vcxproj.filters b/Projects/VisualStudio/Runtime/Runtime.vcxproj.filters
index 028ee4a..018dac5 100644
--- a/Projects/VisualStudio/Runner/Runner.vcxproj.filters
+++ b/Projects/VisualStudio/Runtime/Runtime.vcxproj.filters
@@ -46,299 +46,317 @@
<Filter Include="Physics\Scripting">
<UniqueIdentifier>{4478c64f-e27a-4be6-a189-8d99e0fc6b15}</UniqueIdentifier>
</Filter>
+ <Filter Include="ImGUI">
+ <UniqueIdentifier>{c865b35b-5537-4757-927d-7476009f4de2}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\..\..\Runner\Utilities\NonCopyable.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\NonCopyable.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Singleton.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Singleton.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\Device.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\Device.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\Mesh.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\Mesh.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\MeshUtil.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\MeshUtil.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Threads\Mutex.h">
+ <ClInclude Include="..\..\..\Runtime\Threads\Mutex.h">
<Filter>Threads</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Threads\Thread.h">
+ <ClInclude Include="..\..\..\Runtime\Threads\Thread.h">
<Filter>Threads</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Threads\Semaphore.h">
+ <ClInclude Include="..\..\..\Runtime\Threads\Semaphore.h">
<Filter>Threads</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\TextMesh.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\TextMesh.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Profiler\Profiler.h">
+ <ClInclude Include="..\..\..\Runtime\Profiler\Profiler.h">
<Filter>Profiler</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\UIDGenerator.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\UIDGenerator.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\Quad.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\Quad.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\Texture.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\Texture.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Math\Vector3.h">
+ <ClInclude Include="..\..\..\Runtime\Math\Vector3.h">
<Filter>Math</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\ImageData.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\ImageData.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\Glyph.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\Glyph.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Math\Vector2.h">
+ <ClInclude Include="..\..\..\Runtime\Math\Vector2.h">
<Filter>Math</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\Point.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\Point.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Input\Input.h">
+ <ClInclude Include="..\..\..\Runtime\Input\Input.h">
<Filter>Input</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\VertexBuffer.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\VertexBuffer.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\RenderTexture.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\RenderTexture.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\FrameBuffer.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\FrameBuffer.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\UtilMacros.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\UtilMacros.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Type.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Type.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\FileSystem\FileSystem.h">
+ <ClInclude Include="..\..\..\Runtime\FileSystem\FileSystem.h">
<Filter>FileSystem</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Utf8.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Utf8.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Base64.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Base64.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\PolyLine.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\PolyLine.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_cfunctions.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_cfunctions.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_class.hpp">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_class.hpp">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_config.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_config.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_enum.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_enum.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_globalstate.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_globalstate.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_internal.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_internal.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_memberref.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_memberref.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_ref.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_ref.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_reftable.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_reftable.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_state.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_state.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_utility.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_utility.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_vm.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_vm.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Scripting\luax_watchdog.h">
+ <ClInclude Include="..\..\..\Runtime\Scripting\luax_watchdog.h">
<Filter>Scripting</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\FileSystem\Unzip.h">
+ <ClInclude Include="..\..\..\Runtime\FileSystem\Unzip.h">
<Filter>FileSystem</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\OpenGL.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\OpenGL.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\Font.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\Font.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\Color.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\Color.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Exception.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Exception.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\DeviceDefine.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\DeviceDefine.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\GpuDataBuffer.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\GpuDataBuffer.h">
<Filter>Graphics</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Math\AABB.h">
+ <ClInclude Include="..\..\..\Runtime\Math\AABB.h">
<Filter>Math</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderChannel.h">
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderChannel.h">
<Filter>Shaders</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderDefine.h">
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderDefine.h">
<Filter>Shaders</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Shaders\ShaderUniform.h">
+ <ClInclude Include="..\..\..\Runtime\Shaders\ShaderUniform.h">
<Filter>Shaders</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Utilities\Assert.h">
+ <ClInclude Include="..\..\..\Runtime\Utilities\Assert.h">
<Filter>Utilities</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Profiler\FrameStats.h">
+ <ClInclude Include="..\..\..\Runtime\Profiler\FrameStats.h">
<Filter>Profiler</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Mesh\FontManager.h">
+ <ClInclude Include="..\..\..\Runtime\Mesh\FontManager.h">
<Filter>Mesh</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Runner\Graphics\GlyphAtlas.h">
+ <ClInclude Include="..\..\..\Runtime\Graphics\GlyphAtlas.h">
<Filter>Graphics</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Physics\Rigidbody.h">
+ <Filter>Physics</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\ImGUI\GUIButton.h">
+ <Filter>ImGUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\ImGUI\GUILabel.h">
+ <Filter>ImGUI</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\..\..\Runner\Mesh\Mesh.cpp">
+ <ClCompile Include="..\..\..\Runtime\Mesh\Mesh.cpp">
<Filter>Mesh</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Threads\Mutex.cpp">
+ <ClCompile Include="..\..\..\Runtime\Threads\Mutex.cpp">
<Filter>Threads</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Threads\Semaphore.cpp">
+ <ClCompile Include="..\..\..\Runtime\Threads\Semaphore.cpp">
<Filter>Threads</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Device.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Device.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Math\Vector3.cpp">
+ <ClCompile Include="..\..\..\Runtime\main.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Math\Vector3.cpp">
<Filter>Math</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_Device.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_Device.cpp">
<Filter>Graphics\Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Quad.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Quad.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Texture.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Texture.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\ImageData.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\ImageData.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Math\Vector2.cpp">
+ <ClCompile Include="..\..\..\Runtime\Math\Vector2.cpp">
<Filter>Math</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Point.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Point.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Physics\Scripting\wrap_Joint.cpp">
+ <ClCompile Include="..\..\..\Runtime\Physics\Scripting\wrap_Joint.cpp">
<Filter>Physics\Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Input\Input.cpp">
+ <ClCompile Include="..\..\..\Runtime\Input\Input.cpp">
<Filter>Input</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\VertexBuffer.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\VertexBuffer.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\RenderTexture.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\RenderTexture.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_RenderTexture.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_RenderTexture.cpp">
<Filter>Graphics\Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\FrameBuffer.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\FrameBuffer.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\FileSystem\FileSystem.cpp">
+ <ClCompile Include="..\..\..\Runtime\FileSystem\FileSystem.cpp">
<Filter>FileSystem</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Utilities\Utf8.cpp">
+ <ClCompile Include="..\..\..\Runtime\Utilities\Utf8.cpp">
<Filter>Utilities</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Utilities\Base64.cpp">
+ <ClCompile Include="..\..\..\Runtime\Utilities\Base64.cpp">
<Filter>Utilities</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\PolyLine.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\PolyLine.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_cfunctions.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_cfunctions.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_class.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_class.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_enum.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_enum.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_memberref.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_memberref.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_ref.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_ref.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_reftable.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_reftable.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_state.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_state.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_vm.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_vm.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Scripting\luax_watchdog.cpp">
+ <ClCompile Include="..\..\..\Runtime\Scripting\luax_watchdog.cpp">
<Filter>Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\FileSystem\Unzip.cpp">
+ <ClCompile Include="..\..\..\Runtime\FileSystem\Unzip.cpp">
<Filter>FileSystem</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\OpenGL.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\OpenGL.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\Scripting\wrap_GL.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\Scripting\wrap_GL.cpp">
<Filter>Graphics\Scripting</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Mesh\Font.cpp">
+ <ClCompile Include="..\..\..\Runtime\Mesh\Font.cpp">
<Filter>Mesh</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\GpuDataBuffer.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\GpuDataBuffer.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Shaders\ShaderDefine.cpp">
+ <ClCompile Include="..\..\..\Runtime\Shaders\ShaderDefine.cpp">
<Filter>Shaders</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Graphics\GlyphAtlas.cpp">
+ <ClCompile Include="..\..\..\Runtime\Graphics\GlyphAtlas.cpp">
<Filter>Graphics</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runner\Main.cpp" />
+ <ClCompile Include="..\..\..\Runtime\ImGUI\GUIButton.cpp">
+ <Filter>ImGUI</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\ImGUI\GUILabel.cpp">
+ <Filter>ImGUI</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
- <None Include="..\..\..\Runner\Scripting\luax_class.inc">
+ <None Include="..\..\..\Runtime\Scripting\luax_class.inc">
<Filter>Scripting</Filter>
</None>
- <None Include="..\..\..\Runner\Scripting\luax_state.inc">
+ <None Include="..\..\..\Runtime\Scripting\luax_state.inc">
<Filter>Scripting</Filter>
</None>
</ItemGroup>
diff --git a/Projects/VisualStudio/Runtime/Runtime.vcxproj.user b/Projects/VisualStudio/Runtime/Runtime.vcxproj.user
new file mode 100644
index 0000000..be25078
--- /dev/null
+++ b/Projects/VisualStudio/Runtime/Runtime.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file
diff --git a/Runtime/FileSystem/FileSystem.cpp b/Runtime/FileSystem/FileSystem.cpp
new file mode 100644
index 0000000..8816f78
--- /dev/null
+++ b/Runtime/FileSystem/FileSystem.cpp
@@ -0,0 +1,9 @@
+#include "FileSystem.h"
+
+FileSystem& GetFileSystem() {
+ if (!FileSystem::m_Instance)
+ {
+ FileSystem::m_Instance = new FileSystem();
+ }
+ return *FileSystem::m_Instance;
+}
diff --git a/Runtime/FileSystem/FileSystem.h b/Runtime/FileSystem/FileSystem.h
new file mode 100644
index 0000000..aae39c1
--- /dev/null
+++ b/Runtime/FileSystem/FileSystem.h
@@ -0,0 +1,24 @@
+#ifndef FILESYSTEM_H
+#define FILESYSTEM_H
+
+#include <string>
+
+class FileSystem
+{
+public:
+ std::string GetDataPath();
+ std::string GetPersistentPath();
+ std::string GetTempPath();
+
+private:
+ FileSystem();
+
+ static FileSystem* m_Instance;
+
+ friend FileSystem& GetFileSystem();
+
+};
+
+FileSystem& GetFileSystem();
+
+#endif \ No newline at end of file
diff --git a/Runtime/FileSystem/Unzip.cpp b/Runtime/FileSystem/Unzip.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/FileSystem/Unzip.cpp
diff --git a/Runtime/FileSystem/Unzip.h b/Runtime/FileSystem/Unzip.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/FileSystem/Unzip.h
diff --git a/Runtime/Graphics/Color.h b/Runtime/Graphics/Color.h
new file mode 100644
index 0000000..461e7af
--- /dev/null
+++ b/Runtime/Graphics/Color.h
@@ -0,0 +1,22 @@
+#ifndef COLOR_H
+#define COLOR_H
+
+#include "../Utilities/Type.h"
+
+class ColorRGBAf
+{
+public:
+ float r, g, b, a;
+
+};
+
+class ColorRGBA32
+{
+public:
+ uint8 r, g, b, a;
+
+};
+
+using Color = ColorRGBAf;
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/Device.cpp b/Runtime/Graphics/Device.cpp
new file mode 100644
index 0000000..d729a37
--- /dev/null
+++ b/Runtime/Graphics/Device.cpp
@@ -0,0 +1,78 @@
+#include "Device.h"
+
+bool deviceInited = false;
+Device g_Device;
+
+Device::Device()
+{
+ Assert(deviceInited);
+ deviceInited = true;
+}
+
+void Device::Initialize(DeviceSetting& setting)
+{
+ GPU::BufferPool::Instance()->Initialize();
+}
+
+void Device::Enable(DeviceEnable enabled)
+{
+
+}
+
+void Device::Disable(DeviceEnable enabled)
+{
+
+}
+
+void Device::IsEnable(uint flag)
+{
+
+}
+
+void Device::SetDepthTest(DepthTest testing)
+{
+
+}
+
+void Device::SetCullFace(CullFace face)
+{
+
+}
+
+void Device::SetStencilMask(byte stencilMask)
+{
+
+}
+
+void Device::SetStencilOp(StencilOp op)
+{
+
+}
+
+void Device::SetAntiAliasing(int level /*= 0*/)
+{
+
+}
+
+void Device::Clear(int clearFlag)
+{
+
+}
+
+void Device::BeginFrame()
+{
+ m_IsInsideFrame = true;
+
+}
+
+void Device::EndFrame()
+{
+ GPU::BufferPool::Instance()->OnEndFrame();
+
+ m_IsInsideFrame = false;
+}
+
+void Device::PresentFrame()
+{
+// swap buffers
+} \ No newline at end of file
diff --git a/Runtime/Graphics/Device.h b/Runtime/Graphics/Device.h
new file mode 100644
index 0000000..4e02b72
--- /dev/null
+++ b/Runtime/Graphics/Device.h
@@ -0,0 +1,82 @@
+#ifndef DEVICE_H
+#define DEVICE_H
+
+#include "../Utilities/NonCopyable.h"
+#include "../Utilities/Type.h"
+#include "../Utilities/Assert.h"
+
+#include "Texture.h"
+#include "Color.h"
+#include "DeviceDefine.h"
+#include "VertexBuffer.h"
+
+struct DeviceSetting
+{
+ TextureFilter texFilter;
+ TextureWrap texWrap;
+};
+
+class Device : public NonCopyable
+{
+public:
+ Device();
+ ~Device();
+
+ void Initialize(DeviceSetting& setting);
+
+ void Enable(DeviceEnable enabled);
+ void Disable(DeviceEnable enabled);
+ void IsEnable(uint flag);
+
+ void SetDepthTest(DepthTest testing);
+ void SetCullFace(CullFace face);
+ void SetStencilMask(byte stencilMask);
+ void SetStencilOp(StencilOp op);
+
+ void SetAntiAliasing(int level = 0);
+
+ void Clear(int clearFlag);
+
+ void BeginFrame();
+ void EndFrame();
+ void PresentFrame();
+
+ GET(SharedVertexBuffer*, SharedVBO, m_SharedVBO);
+
+ GET_SET(Color, ClearColor, m_ClearColor);
+
+ GET_SET(TextureFilter, TextureFilter, m_TexFilter);
+ GET_SET(TextureWrap, TextureWrap, m_TexWrap);
+
+ inline bool IsInsideFrame();
+
+private:
+ uint m_EnableFlag;
+
+ // Global texture setting
+ TextureFilter m_TexFilter;
+ TextureWrap m_TexWrap;
+
+ Color m_ClearColor;
+
+ DepthTest m_DepthTest;
+ StencilTest m_StencilTest;
+ StencilOp m_StencilOp;
+ byte m_StencilMask;
+
+ SharedVertexBuffer m_SharedVBO;
+
+ bool m_IsInsideFrame;
+
+};
+
+extern Device g_Device;
+
+#define g_SharedVBO (*g_Device.GetSharedVBO())
+
+inline bool Device::IsInsideFrame()
+{
+ return m_IsInsideFrame;
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/DeviceDefine.h b/Runtime/Graphics/DeviceDefine.h
new file mode 100644
index 0000000..2f3cb6b
--- /dev/null
+++ b/Runtime/Graphics/DeviceDefine.h
@@ -0,0 +1,69 @@
+#ifndef DEVICE_DEFINE_H
+#define DEVICE_DEFINE_H
+
+enum DeviceEnable
+{
+ DeviceEnable_DepthTest = 1,
+ DeviceEnable_DepthWrite = 1 << 1,
+ DeviceEnable_StencilTest = 1 << 2,
+ DeviceEnable_StencilWrite = 1 << 3,
+ DeviceEnable_Cull = 1 << 4,
+ DeviceEnable_Blend = 1 << 5,
+ DeviceEnable_AntiAliasing = 1 << 6,
+};
+
+enum DepthTest
+{
+ DepthTest_Greater = 1,
+ DepthTest_GreaterEqual,
+ DepthTest_Less,
+ DepthTest_LessEqual,
+ DepthTest_Equal,
+ DepthTest_NotEqual,
+ DepthTest_Always,
+};
+
+enum StencilTest {
+ StencilTest_Always,
+ StencilTest_Never,
+ StencilTest_Less,
+ StencilTest_Equal,
+ StencilTest_NotEqual,
+ StencilTest_LessEqual,
+ StencilTest_Greater,
+ StencilTest_GreaterEqual,
+};
+
+enum StencilOp {
+ StencilOp_Keep,
+ StencilOp_Zero,
+ StencilOp_Replace,
+ StencilOp_Incr,
+ StencilOp_IncrWrap,
+ StencilOp_Decr,
+ StencilOp_DecrWrap,
+ StencilOp_Invert,
+};
+
+enum DeviceClear
+{
+ DeviceClear_Depth = 1,
+ DeviceClear_Stencil = 1 << 1,
+ DeviceClear_Color = 1 << 2,
+};
+
+enum CullFace
+{
+ CullFace_Front = 1,
+ CullFace_Back = 2,
+ CullFace_None = 3,
+ CullFace_All = 4,
+};
+
+enum BlendMode
+{
+ BlendMode_Additive = 1,
+ BlendMode_Substract = 1,
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/FrameBuffer.cpp b/Runtime/Graphics/FrameBuffer.cpp
new file mode 100644
index 0000000..e675aab
--- /dev/null
+++ b/Runtime/Graphics/FrameBuffer.cpp
@@ -0,0 +1,12 @@
+#include "FrameBuffer.h"
+
+// ÓÐЩ°æ±¾µÄOpenGL²»Ö§³Ö°ó¶¨¶à¸öRT
+bool FrameBuffer::BindRenderTexture(RenderTexture* rt, int location /* = 0 */)
+{
+
+}
+
+bool FrameBuffer::Blit(FrameBuffer* target)
+{
+
+}
diff --git a/Runtime/Graphics/FrameBuffer.h b/Runtime/Graphics/FrameBuffer.h
new file mode 100644
index 0000000..4b9104b
--- /dev/null
+++ b/Runtime/Graphics/FrameBuffer.h
@@ -0,0 +1,35 @@
+#ifndef FRAME_BUFFER_H
+#define FRAME_BUFFER_H
+
+#include "OpenGL.h"
+#include "RenderTexture.h"
+
+// Fbo£¬ËùÓа󶨵ÄtextureºÍrenderbufferµÄtarget¶¼ÊǿɶÁдµÄGL_FRAMEBUFFER
+class FrameBuffer
+{
+public:
+ enum FrameBufferUsage
+ {
+ FrameBufferUsage_None = 0,
+ FrameBufferUsage_Depth = 1,
+ FrameBufferUsage_Stencil = 2,
+ FrameBufferUsage_DepthStencil = 3,
+ };
+
+ FrameBuffer(FrameBufferUsage usage, int width, int height);
+ ~FrameBuffer();
+
+ bool Blit(FrameBuffer* target);
+
+ bool BindRenderTexture(RenderTexture* rt, int location = 0);
+
+ GET(int, Width, m_Width);
+ GET(int, Height, m_Height);
+
+private:
+ int m_Width, m_Height;
+ FrameBufferUsage m_Usage;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/GlyphAtlas.cpp b/Runtime/Graphics/GlyphAtlas.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/GlyphAtlas.cpp
diff --git a/Runtime/Graphics/GlyphAtlas.h b/Runtime/Graphics/GlyphAtlas.h
new file mode 100644
index 0000000..b0ab858
--- /dev/null
+++ b/Runtime/Graphics/GlyphAtlas.h
@@ -0,0 +1,6 @@
+#ifndef TEXT_ATLAS_H
+#define TEXT_ATLAS_H
+
+
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/GpuDataBuffer.cpp b/Runtime/Graphics/GpuDataBuffer.cpp
new file mode 100644
index 0000000..0b3e4ee
--- /dev/null
+++ b/Runtime/Graphics/GpuDataBuffer.cpp
@@ -0,0 +1,206 @@
+#include <math.h>
+
+#include "GpuDataBuffer.h"
+
+namespace GPU
+{
+
+ // ÐÞ¸ÄbufferÊý¾ÝÒª°ó¶¨µ½Õâ¸öÄ¿±êÉÏ£¬ÆäËûÇé¿öÏÂÓÃGetHandle()°ó¶¨µ½ÆäËûÄ¿±ê
+ // GL_COPY_READ_BUFFER
+ static const GLenum kBufferTarget = GL_COPY_WRITE_BUFFER;
+
+ DataBuffer::DataBuffer()
+ {
+ glGenBuffers(1, &m_Handle);
+ }
+
+ DataBuffer::~DataBuffer()
+ {
+ glDeleteBuffers(1, &m_Handle);
+ }
+
+ void DataBuffer::Restore(int size, GLenum usage)
+ {
+ RestoreWithData(size, usage, 0);
+ }
+
+ void DataBuffer::RestoreWithData(int size, GLenum usage, const void* data)
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ glBufferData(kBufferTarget, size, data, usage);
+ glBindBuffer(kBufferTarget, 0);
+ m_Size = size;
+ m_Usage = usage;
+ }
+
+ // glBufferSubData
+ // glMapBuffer
+ // glMapBufferRange (best one)
+
+ void DataBuffer::Upload(int offset, int size, const void* data)
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ glBufferSubData(kBufferTarget, offset, size, data);
+ glBindBuffer(kBufferTarget, 0);
+ }
+
+ void* DataBuffer::Map(uint32 access)
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ void* ptr = glMapBuffer(kBufferTarget, access);
+ glBindBuffer(kBufferTarget, 0);
+ return ptr;
+ }
+
+ void* DataBuffer::MapRange(int offset, int size, uint32 access)
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ void* ptr = glMapBufferRange(kBufferTarget, offset, size, access);
+ glBindBuffer(kBufferTarget, 0);
+ return ptr;
+ }
+
+ void DataBuffer::FlushMapedRange(int offset, int size)
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ glFlushMappedBufferRange(kBufferTarget, offset, size);
+ glBindBuffer(kBufferTarget, 0);
+ }
+
+ void DataBuffer::UnMap()
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ glUnmapBuffer(kBufferTarget);
+ glBindBuffer(kBufferTarget, 0);
+ }
+
+ void DataBuffer::Orphan()
+ {
+ glBindBuffer(kBufferTarget, m_Handle);
+ glBufferData(kBufferTarget, 0, 0, GL_STREAM_DRAW);
+ glBindBuffer(kBufferTarget, 0);
+ }
+
+ static bool IsBufferPoolCreated = false;
+
+ BufferPool::BufferPool()
+ :m_LiveBuffers()
+ {
+ Assert(!IsBufferPoolCreated);
+ IsBufferPoolCreated = true;
+ }
+
+ BufferPool::~BufferPool()
+ {
+
+ }
+
+ void BufferPool::Initialize()
+ {
+ for(int i = 0; i < kSizeClassCount; ++i)
+ m_LiveBuffers[i].clear();
+ }
+
+ static const float kBufferAllocateWeight = 10.0f; //! Default weight for buffer allocation from scratch.
+ static const float kBufferSizeWeightFactor = 1.f / 8096.f; //!< Weight factor for size difference.
+ static const float kBufferUsageDiffWeight = 8.f; //!< Weight factor for usage difference.
+
+ static int ComputeBufferWeight(DataBuffer* buffer, int desiredSize, GLenum desiredUsage)
+ {
+ const int bufferSize = buffer->GetSize();
+ const GLenum bufferUsage = buffer->GetUsage();
+
+ if(bufferSize == 0)
+ return kBufferAllocateWeight;
+
+ const int sizeDiff = std::abs(bufferSize - desiredSize);
+
+ return float(sizeDiff)*kBufferSizeWeightFactor + ((bufferUsage != desiredUsage) ? kBufferUsageDiffWeight : 0.f);
+ }
+
+ DataBuffer* BufferPool::ClaimBuffer(int size, GLenum usage)
+ {
+ const float maxWeight = kBufferAllocateWeight;
+ const int maxCandidates = 5; // Number of potential candidates to consider actually.
+
+ const int sizeClass = GetSizeClass(size);
+ int numCandidates = 0; // Number of potential candidates considered
+ int bestBufferNdx = -1;
+ float bestWeight = std::numeric_limits<float>::infinity();
+
+ for (int idx = 0; idx < m_LiveBuffers[sizeClass].size(); ++idx)
+ {
+ DataBuffer* buffer = m_LiveBuffers[sizeClass][idx];
+ const float weight = ComputeBufferWeight(buffer, size, usage);
+
+ if (weight < maxWeight && weight < bestWeight)
+ {
+ bestWeight = weight;
+ bestBufferNdx = idx;
+ ++numCandidates;
+ }
+
+ if(numCandidates >= maxCandidates)
+ break; // Do not try other buffers, sorry.
+ }
+
+ if (bestBufferNdx >= 0)
+ {
+ DataBuffer* selectedBuffer = m_LiveBuffers[sizeClass][bestBufferNdx];
+
+ if (bestBufferNdx + 1 != m_LiveBuffers[sizeClass].size())
+ std::swap(m_LiveBuffers[sizeClass][bestBufferNdx], m_LiveBuffers[sizeClass].back());
+ m_LiveBuffers[sizeClass].pop_back();
+
+ return selectedBuffer;
+ }
+ else
+ return new DataBuffer();
+
+ }
+
+ void BufferPool::ReleaseBuffer(DataBuffer* buffer)
+ {
+ InsertToLive(buffer);
+ }
+
+ void BufferPool::OnEndFrame()
+ {
+ UpdatePendingBuffersArray();
+ }
+
+ void BufferPool::UpdatePendingBuffersArray()
+ {
+
+ }
+
+ void BufferPool::InsertToLive(DataBuffer* buffer)
+ {
+ const int bufferSize = buffer->GetSize();
+ const int sizeClass = GetSizeClass(bufferSize);
+
+ m_LiveBuffers[sizeClass].push_back(buffer);
+ }
+
+ uint BufferPool::GetSizeClass(uint bufferSize)
+ {
+ for (int idx = 0; idx < kSizeClassCount; ++idx)
+ {
+ if(bufferSize < GetSizeClassLimit(idx))
+ return idx;
+ }
+ Assert(false); // never reach here
+ return 0;
+ }
+
+ DataBuffer* ClaimBuffer(int size = 0, GLenum usage = GL_ARRAY_BUFFER)
+ {
+ return BufferPool::Instance()->ClaimBuffer(size, usage);
+ }
+
+ void ReleaseBuffer(DataBuffer* buffer)
+ {
+ BufferPool::Instance()->ReleaseBuffer(buffer);
+ }
+
+}
diff --git a/Runtime/Graphics/GpuDataBuffer.h b/Runtime/Graphics/GpuDataBuffer.h
new file mode 100644
index 0000000..0d65d3d
--- /dev/null
+++ b/Runtime/Graphics/GpuDataBuffer.h
@@ -0,0 +1,90 @@
+#ifndef GPU_DATABUFFER_H
+#define GPU_DATABUFFER_H
+
+#include <vector>
+
+#include "../Utilities/Type.h"
+#include "../Utilities/Singleton.h"
+#include "../Utilities/UtilMacros.h"
+#include "../Utilities/Assert.h"
+#include "OpenGL.h"
+
+namespace GPU
+{
+
+ class DataBuffer
+ {
+ public:
+ void Upload(int offset, int size, const void* data);
+ void* Map(uint32 access);
+ void* MapRange(int offset, int size, uint32 access); // best performance
+ void FlushMapedRange(int offset, int size);
+
+ void UnMap();
+
+ void Orphan();
+
+ // claim storage of size
+ void Restore(int size, GLenum usage);
+ // claim storage of size and fill it
+ void RestoreWithData(int size, GLenum usage, const void* data);
+
+ GET(int, Size, m_Size);
+ GET(GLenum, Usage, m_Usage);
+ GET(GLuint, Handle, m_Handle);
+
+ private:
+ friend class BufferPool;
+
+ DataBuffer();
+ ~DataBuffer();
+
+ GLuint m_Handle;
+ int m_Size;
+ GLenum m_Usage;
+ };
+
+ // recycle data buffer
+ class BufferPool : public Singleton<BufferPool>
+ {
+ public:
+ BufferPool();
+ ~BufferPool();
+
+ void Initialize();
+
+ DataBuffer* ClaimBuffer(int size, GLenum usage);
+ void ReleaseBuffer(DataBuffer* buffer);
+
+ void OnEndFrame();
+
+ private:
+
+ inline int GetSizeClassLimit(int classNdx);
+
+ void UpdatePendingBuffersArray();
+ void InsertToLive(DataBuffer* buffer);
+ uint GetSizeClass(uint bufferSize);
+
+ enum {
+ kSizeClassBaseLog2 = 10,
+ kSizeClassStepLog2 = 1,
+ kSizeClassCount = 7
+ };
+
+ std::vector<DataBuffer*> m_LiveBuffers[kSizeClassCount];
+
+ };
+
+ inline int BufferPool::GetSizeClassLimit(int classNdx)
+ {
+ // (0, 2^10] 2^11 2^12 2^13 2^14 2^15 INT_MAX
+ return classNdx + 1 < kSizeClassCount ? (1 << (classNdx*kSizeClassStepLog2 + kSizeClassBaseLog2)) : INT_MAX;
+ }
+
+ DataBuffer* ClaimBuffer(int size = 0, GLenum usage = GL_ARRAY_BUFFER);
+ void ReleaseBuffer(DataBuffer* buffer);
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/ImageData.cpp b/Runtime/Graphics/ImageData.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/ImageData.cpp
diff --git a/Runtime/Graphics/ImageData.h b/Runtime/Graphics/ImageData.h
new file mode 100644
index 0000000..cd56e83
--- /dev/null
+++ b/Runtime/Graphics/ImageData.h
@@ -0,0 +1,43 @@
+#ifndef IMAGE_DATA_H
+#define IMAGE_DATA_H
+
+#include <vector>
+
+class ImageData
+{
+public:
+ enum ImageFormat
+ {
+ ImageFormat_Rgba_Int,
+ ImageFormat_Rgba_Float,
+ };
+
+private:
+ void* m_Data;
+
+};
+
+enum ImageDataAsyncError
+{
+ ImageDataAsyncError_NoFile = 1,
+ ImageDataAsyncError_ParseFailed = 2,
+ ImageDataAsyncError_InvalidFormat = 3,
+};
+
+struct ImageDataRequest
+{
+ bool isDone, hasError;
+ int error;
+ int progress, all;
+ ImageData* result;
+ std::vector<ImageData*> results;
+};
+
+namespace ImageDataUtil
+{
+ ImageData* Load(const char* path);
+ ImageDataRequest* LoadAsync(const char* path);
+ ImageDataRequest* LoadAsync(std::vector<const char*> paths);
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/OpenGL.cpp b/Runtime/Graphics/OpenGL.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/OpenGL.cpp
diff --git a/Runtime/Graphics/OpenGL.h b/Runtime/Graphics/OpenGL.h
new file mode 100644
index 0000000..413b70b
--- /dev/null
+++ b/Runtime/Graphics/OpenGL.h
@@ -0,0 +1,6 @@
+#ifndef OPENGL_H
+#define OPENGL_H
+
+#include "glad/glad.h"
+
+#endif
diff --git a/Runtime/Graphics/Point.cpp b/Runtime/Graphics/Point.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Point.cpp
diff --git a/Runtime/Graphics/Point.h b/Runtime/Graphics/Point.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Point.h
diff --git a/Runtime/Graphics/PolyLine.cpp b/Runtime/Graphics/PolyLine.cpp
new file mode 100644
index 0000000..794819a
--- /dev/null
+++ b/Runtime/Graphics/PolyLine.cpp
@@ -0,0 +1,11 @@
+#include "PolyLine.h"
+#include "../Math/Vector3.h"
+#include "Color.h"
+
+struct PolyLineVBOLayout
+{
+ Vector3 position;
+ ColorRGBA32 color;
+};
+
+
diff --git a/Runtime/Graphics/PolyLine.h b/Runtime/Graphics/PolyLine.h
new file mode 100644
index 0000000..1850e47
--- /dev/null
+++ b/Runtime/Graphics/PolyLine.h
@@ -0,0 +1,18 @@
+#ifndef POLY_LINE_H
+#define POLY_LINE_H
+
+#include "../Math/Vector3.h"
+
+class PolyLine
+{
+public:
+ PolyLine();
+ ~PolyLine();
+
+ void Draw();
+
+private:
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/Quad.cpp b/Runtime/Graphics/Quad.cpp
new file mode 100644
index 0000000..cbe8b74
--- /dev/null
+++ b/Runtime/Graphics/Quad.cpp
@@ -0,0 +1,52 @@
+#include "../Math/Vector2.h"
+#include "../Math/Vector3.h"
+#include "Quad.h"
+#include "Device.h"
+
+struct QuadVBOLayout
+{
+ Vector3 position;
+ Vector2 uv;
+};
+
+void Quad::Draw()
+{
+ const int nVerts = 4;
+ const int nIndices = 6;
+
+ float pos[] = {
+ m_Left, m_Bottom, 0, // left-bottom
+ m_Right, m_Bottom, 0, // right-bottom
+ m_Right, m_Top, 0, // right-top
+ m_Left, m_Top, 0, // top-left
+ };
+ float uv[] = {
+ 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 1,
+ };
+ int indices[] = {
+ 0, 1, 3, // right-top
+ 1, 2, 3, // left-bottom
+ };
+
+ uint8* vb;
+ uint16* ib;
+
+ uint attrs = Mask(VertexAttr_Position) | Mask(VertexAttr_TexCoord0);
+ g_SharedVBO.GetChunk(attrs, 4, 6, RenderMode_Triangle, (void**)&vb, (void**)&ib);
+
+ QuadVBOLayout* dst = (QuadVBOLayout*)vb;
+ for (int i = 0; i < nVerts; ++i)
+ {
+ dst[i].position.Set(pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]);
+ dst[i].uv.Set(uv[2 * i], uv[2 * i + 1]);
+ }
+
+ for (int i = 0; i < nIndices; ++i)
+ ib[i] = indices[i];
+
+ g_SharedVBO.ReleaseChunk(4, 6);
+ g_SharedVBO.DrawChunk();
+} \ No newline at end of file
diff --git a/Runtime/Graphics/Quad.h b/Runtime/Graphics/Quad.h
new file mode 100644
index 0000000..0e38ec4
--- /dev/null
+++ b/Runtime/Graphics/Quad.h
@@ -0,0 +1,25 @@
+#ifndef QUAD_H
+#define QUAD_H
+
+#include "../Utilities/UtilMacros.h"
+
+class Quad
+{
+public:
+ Quad(float l, float r, float t, float b);
+
+ void Set(float l, float r, float t, float b);
+
+ GET_SET(float, Left, m_Left);
+ GET_SET(float, Right, m_Right);
+ GET_SET(float, Top, m_Top);
+ GET_SET(float, Bottom, m_Bottom);
+
+ void Draw();
+
+private:
+ float m_Left, m_Right, m_Top, m_Bottom;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/RenderTexture.cpp b/Runtime/Graphics/RenderTexture.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/RenderTexture.cpp
diff --git a/Runtime/Graphics/RenderTexture.h b/Runtime/Graphics/RenderTexture.h
new file mode 100644
index 0000000..74c5602
--- /dev/null
+++ b/Runtime/Graphics/RenderTexture.h
@@ -0,0 +1,16 @@
+#ifndef RENDER_TEXTURE_H
+#define RENDER_TEXTURE_H
+
+#include "Texture.h"
+
+// ÀëÆÁäÖȾ
+class RenderTexture : public Texture
+{
+public:
+ RenderTexture(TextureFormat format);
+
+};
+
+RenderTexture* CreateRenderTexture(int width, int height, TextureFormat format);
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/Scripting/wrap_Device.cpp b/Runtime/Graphics/Scripting/wrap_Device.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Scripting/wrap_Device.cpp
diff --git a/Runtime/Graphics/Scripting/wrap_GL.cpp b/Runtime/Graphics/Scripting/wrap_GL.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Scripting/wrap_GL.cpp
diff --git a/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp b/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Scripting/wrap_RenderTexture.cpp
diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Graphics/Texture.cpp
diff --git a/Runtime/Graphics/Texture.h b/Runtime/Graphics/Texture.h
new file mode 100644
index 0000000..ce05ff7
--- /dev/null
+++ b/Runtime/Graphics/Texture.h
@@ -0,0 +1,59 @@
+#ifndef TEXTURE_H
+#define TEXTURE_H
+
+#include "../Utilities/UtilMacros.h"
+#include "OpenGL.h"
+#include "ImageData.h"
+
+enum TextureFormat
+{
+ TextureFormat_DepthComponent,
+ TextureFormat_Red,
+ TextureFormat_Green,
+ TextureFormat_Blue,
+ TextureFormat_Alpha,
+ TextureFormat_Rgb,
+ TextureFormat_Rgba,
+};
+
+enum TextureWrap
+{
+ TextureWrap_Clamp,
+ TextureWrap_Repeat,
+};
+
+enum TextureFilter
+{
+ TextureFilter_Nearest,
+ TextureFilter_Bilinear,
+ TextureFilter_Trilinear,
+};
+
+class Texture
+{
+public:
+ Texture(ImageData* imgData, TextureFormat format);
+ Texture(ImageData* imgData, TextureFormat format, TextureWrap wrap, TextureFilter filter);
+ Texture();
+ ~Texture();
+
+ GET(int, Width, m_Width);
+ GET(int, Height, m_Height);
+
+ GET(TextureFilter, Filter, m_Filter);
+ GET(TextureWrap, Wrap, m_Wrap);
+
+ GET(GLint, Handle, m_Handle);
+
+protected:
+ GLint m_Handle;
+ int m_Width, m_Height;
+ TextureFilter m_Filter;
+ TextureWrap m_Wrap;
+
+};
+
+Texture* CreateTexture(ImageData* imgData, TextureFormat format);
+Texture* CreateTexture(ImageData* imgData, TextureFormat format, TextureWrap wrap, TextureFilter filter);
+
+#endif \ No newline at end of file
diff --git a/Runtime/Graphics/VertexBuffer.cpp b/Runtime/Graphics/VertexBuffer.cpp
new file mode 100644
index 0000000..c9f5164
--- /dev/null
+++ b/Runtime/Graphics/VertexBuffer.cpp
@@ -0,0 +1,322 @@
+#include "VertexBuffer.h"
+#include "../Profiler/FrameStats.h"
+
+void SetupDefaultVertexArray(const VertexArrayInfo& info);
+void InvalidateVertexInputCache();
+
+// LUTs of vertex attributes
+static const int kVertexAttrSize[VertexAttr_Count] = {
+ 3 * sizeof(float), // position
+ 3 * sizeof(float), // normal
+ 4 * sizeof(float), // tangent
+ 1 * sizeof(uint32), // color
+ 2 * sizeof(float), // uv0
+ 2 * sizeof(float), // uv1
+};
+
+static const int kVertexAttrDimension[VertexAttr_Count] = {
+ 3, // position
+ 3, // normal
+ 4, // tangent
+ 1, // color
+ 2, // uv0
+ 2 // uv1
+};
+
+enum VertexAttrFormat
+{
+ VertexAttrFormat_Float = 0, // position \ normal \ tangent \ uv0 \ uv1
+ VertexAttrFormat_Float16 = 1,
+ VertexAttrFormat_Color = 2, // color
+ VertexAttrFormat_Byte = 3,
+
+ VertexAttrFormat_Count = 4
+};
+
+// map VertexAttrFormat to OpenGL type
+static GLenum kGLVertexAttrFormat [VertexAttr_Count] = {
+ GL_FLOAT, // VertexAttrFormat_Float
+ GL_HALF_FLOAT, // VertexAttrFormat_Float16
+ GL_UNSIGNED_BYTE, // VertexAttrFormat_Color
+ GL_BYTE // VertexAttrFormat_Byte
+};
+
+static bool IsGLVertexAttrNeedNormalized(uint attr, uint format)
+{
+ if(attr == VertexAttr_Position)
+ return false;
+ else // color and byte need to be normalized
+ return format != VertexAttrFormat_Float && format != VertexAttrFormat_Float16;
+}
+
+static uint GetDefaultShaderChannelFormat(uint attr)
+{
+// besides color, other attributes are all composite of float values
+ return attr == VertexAttr_Color ? VertexAttrFormat_Color : VertexAttrFormat_Float;
+}
+
+static uint32 GetDefaultVertexAttrSize(/*VertexAttr*/ int attr)
+{
+ return kVertexAttrSize[attr];
+}
+
+static uint GetDefaultVertexAttrDimension(uint attr)
+{
+ return kVertexAttrDimension[attr];
+}
+
+static uint GetDefaultShaderChannelDimension(uint attr)
+{
+ return attr == VertexAttr_Color ? 4 : GetDefaultVertexAttrDimension(attr);
+}
+
+// index is stored in unsgined short (GL_UNSIGNED_SHORT)
+static const int kIndexSize = sizeof(uint16);
+static GLenum kGLIndexFormat = GL_UNSIGNED_SHORT;
+
+// Get size used for vertexAttrMask
+static uint32 GetDynamicChunkStride(uint32 vertexAttrMask)
+{
+ uint32 stride = 0;
+ for (int i = 0; i < vertexAttrMask; ++i)
+ {
+ if (vertexAttrMask & Mask(i))
+ stride += GetDefaultVertexAttrSize(i);
+ }
+ return stride;
+}
+
+VertexBuffer::VertexBuffer(VertexBufferType type)
+{
+}
+
+VertexBuffer::~VertexBuffer()
+{
+}
+
+SharedVertexBuffer::SharedVertexBuffer()
+{
+}
+
+SharedVertexBuffer::~SharedVertexBuffer()
+{
+}
+
+//GetChunk
+//-> ReleaseChunk
+//-> DrawChunk
+
+void SharedVertexBuffer::GetChunk(uint attrsMask, int maxVerts, int maxIndices, RenderMode mode, void **out_vb, void **out_ib)
+{
+ Assert(out_vb && out_ib);
+
+ uint stride = GetDynamicChunkStride(attrsMask); // data size of single vertex
+ GLenum usage = GL_STREAM_DRAW;
+ uint vbufferSize = stride * maxVerts;
+ uint ibufferSize = kIndexSize * maxIndices;
+
+ const bool mapVertexBuffer = vbufferSize >= DataBufferThreshold;
+ const bool mapIndexBuffer = ibufferSize >= DataBufferThreshold;
+
+ GPU::DataBuffer* vertexBuffer = mapVertexBuffer ? GPU::ClaimBuffer(vbufferSize, usage) : 0;
+ GPU::DataBuffer* indexBuffer = mapIndexBuffer ? GPU::ClaimBuffer(ibufferSize, usage) : 0;
+
+ if(vertexBuffer && vertexBuffer->GetSize() < vbufferSize)
+ vertexBuffer->Restore(vbufferSize, usage);
+
+ if(indexBuffer && indexBuffer->GetSize() < ibufferSize)
+ indexBuffer->Restore(ibufferSize, usage);
+
+ if(!mapVertexBuffer && m_CurVBData.size() < vbufferSize)
+ m_CurVBData.resize(vbufferSize);
+
+ if(!mapIndexBuffer && m_CurIBData.size() < ibufferSize)
+ m_CurIBData.resize(ibufferSize);
+
+ const GLenum access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT;
+
+ if (vertexBuffer)
+ *out_vb = vertexBuffer->MapRange(0, vbufferSize, access);
+ else
+ *out_vb = &m_CurVBData[0];
+
+ if(indexBuffer)
+ *out_ib = indexBuffer->MapRange(0, ibufferSize, access);
+ else
+ *out_ib = &m_CurIBData[0];
+
+ m_CurVB = vertexBuffer;
+ m_CurIB = indexBuffer;
+ m_CurRenderMode = mode;
+ m_CurAttrMask = attrsMask;
+ m_CurStride = stride;
+}
+
+void SharedVertexBuffer::ReleaseChunk(int actualVerts, int actualIndices)
+{
+ int actualVBufferSize = m_CurStride * actualVerts;
+ int actualIBufferSize = kIndexSize * actualIndices;
+
+ const GLenum usage = GL_STREAM_DRAW;
+
+ if (m_CurVB)
+ {
+ m_CurVB->FlushMapedRange(0, actualVBufferSize);
+ m_CurVB->UnMap();
+ }
+ else if(actualVBufferSize >= DataBufferThreshold)
+ {
+ m_CurVB = GPU::ClaimBuffer(actualVBufferSize, usage);
+ m_CurVB->RestoreWithData(actualVBufferSize, usage, &m_CurVBData[0]);
+ }
+
+ if (m_CurIB)
+ {
+ m_CurIB->FlushMapedRange(0, actualIBufferSize);
+ m_CurIB->UnMap();
+ }
+ else if (actualIBufferSize >= DataBufferThreshold)
+ {
+ m_CurIB = GPU::ClaimBuffer(0, usage);
+ m_CurIB->RestoreWithData(0, usage, &m_CurIBData[0]);
+ }
+
+ m_CurVertexCount = actualVerts;
+ m_CurIndexCount = actualIndices;
+}
+
+void SharedVertexBuffer::DrawChunk()
+{
+ VertexArrayInfo vertexArray;
+ FillVertexArrayInfo(vertexArray);
+
+ // bind vertex attributes data
+ SetupDefaultVertexArray(vertexArray);
+
+ const void* indexPtr = m_CurIB ? 0 : (m_CurIBData.empty() ? 0 : &m_CurIBData[0]);
+
+ if (m_CurIB)
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CurIB->GetHandle());
+
+ switch (m_CurRenderMode)
+ {
+ case RenderMode_Triangle:
+ glDrawElements(GL_TRIANGLES, m_CurIndexCount, kGLIndexFormat, indexPtr);
+ g_FrameStats.AddDrawCall();
+ g_FrameStats.AddTrianglesCount(m_CurIndexCount / 3);
+ break;
+ case RenderMode_Line:
+ glDrawElements(GL_LINE, m_CurIndexCount, kGLIndexFormat, indexPtr);
+ g_FrameStats.AddDrawCall();
+ break;
+ case RenderMode_Point:
+ glDrawElements(GL_POINT, m_CurIndexCount, kGLIndexFormat, indexPtr);
+ g_FrameStats.AddDrawCall();
+ break;
+ }
+
+ if(m_CurIB)
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ // End draw
+ Clean();
+}
+
+void SharedVertexBuffer::FillVertexArrayInfo(VertexArrayInfo& dst)
+{
+ const byte* basepointer = m_CurVB ? 0 : &m_CurVBData[0];
+ const GLuint buffer = m_CurVB ? m_CurVB->GetHandle() : 0;
+
+ int attrOffsets[VertexAttr_Count] = {0};
+
+ {
+ uint32 curOffset = 0;
+ for (uint idx = 0; idx < VertexAttr_Count; ++idx)
+ {
+ if (m_CurAttrMask & Mask(idx))
+ {
+ attrOffsets[idx] = curOffset;
+ curOffset += GetDefaultVertexAttrSize(idx);
+ }
+ }
+ }
+
+ for (uint32 attrIdx = 0; attrIdx < VertexAttr_Count; ++attrIdx)
+ {
+ if (m_CurAttrMask & Mask(attrIdx))
+ {
+ dst.buffers[attrIdx] = buffer;
+
+ dst.attributes[attrIdx].pointer = basepointer + attrOffsets[attrIdx];
+ dst.attributes[attrIdx].componentType = GetDefaultShaderChannelFormat(attrIdx);
+ dst.attributes[attrIdx].componentNum = GetDefaultShaderChannelDimension(attrIdx);
+ dst.attributes[attrIdx].stride = m_CurStride;
+
+ dst.enableMask |= Mask(attrIdx);
+ }
+ }
+}
+
+void SharedVertexBuffer::Clean()
+{
+ if (m_CurVB)
+ {
+ GPU::ReleaseBuffer(m_CurVB);
+ m_CurVB = 0;
+ }
+
+ if (m_CurIB)
+ {
+ GPU::ReleaseBuffer(m_CurIB);
+ m_CurIB = 0;
+ }
+
+ m_CurRenderMode = (RenderMode)0;
+ m_CurAttrMask = 0;
+ m_CurStride = 0;
+ m_CurVertexCount = 0;
+ m_CurIndexCount = 0;
+
+ m_CurVBData.clear();
+ m_CurIBData.clear();
+}
+
+static uint32 sEnabledArrays = 0;
+
+void SetupDefaultVertexArray(const VertexArrayInfo& info)
+{
+ GLuint curBoundBuffer = 0;
+
+ for (int attrIdx = 0; attrIdx < VertexAttr_Count; ++attrIdx)
+ {
+ if (info.enableMask & Mask(attrIdx))
+ {
+ if (!sEnabledArrays & Mask(attrIdx))
+ glEnableVertexAttribArray(attrIdx);
+ const GLuint buffer = info.buffers[attrIdx];
+ const int numCompo = info.attributes[attrIdx].componentNum;
+ const GLenum compoType = kGLVertexAttrFormat[info.attributes[attrIdx].componentType];
+ const bool normalized = IsGLVertexAttrNeedNormalized(attrIdx, compoType);
+ const uint stride = info.attributes[attrIdx].stride;
+ const void* pointer = info.attributes[attrIdx].pointer;
+
+ if (curBoundBuffer != buffer)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, buffer);
+ curBoundBuffer = buffer;
+ }
+
+ glVertexAttribPointer(attrIdx, numCompo, compoType, normalized ? GL_TRUE : GL_FALSE, stride, pointer);
+ }
+ else if(sEnabledArrays & Mask(attrIdx))
+ glDisableVertexAttribArray(attrIdx);
+ }
+ sEnabledArrays = info.enableMask;
+}
+
+void InvalidateVertexInputCache()
+{
+ sEnabledArrays = 0;
+ for(int attrIdx = 0; attrIdx < VertexAttr_Count; ++attrIdx)
+ glDisableVertexAttribArray(attrIdx);
+} \ No newline at end of file
diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h
new file mode 100644
index 0000000..33c0783
--- /dev/null
+++ b/Runtime/Graphics/VertexBuffer.h
@@ -0,0 +1,103 @@
+#ifndef VBO_H
+#define VBO_H
+
+#include <vector>
+
+#include "../Utilities/UtilMacros.h"
+#include "../Shaders/ShaderChannel.h"
+
+#include "OpenGL.h"
+#include "GpuDataBuffer.h"
+
+enum VertexAttr
+{
+ VertexAttr_Position = 0,
+ VertexAttr_Normal = 1,
+ VertexAttr_Tangent = 2,
+ VertexAttr_Color = 3,
+ VertexAttr_TexCoord0 = 4,
+ VertexAttr_TexCoord1 = 5,
+
+ VertexAttr_Count = 6
+};
+
+enum RenderMode
+{
+ RenderMode_Triangle = 1,
+ RenderMode_Line = 2,
+ RenderMode_Point = 3,
+};
+
+struct VertexInputInfo
+{
+ const void* pointer; // either cpu memory or gpu memory
+ uint componentType; // one of VertexAttrFormat
+ uint componentNum;
+ uint16 stride;
+};
+
+// gpu side vertex attributes array
+struct VertexArrayInfo
+{
+ uint32 enableMask;
+ GLuint buffers[VertexAttr_Count];
+ VertexInputInfo attributes[VertexAttr_Count];
+};
+
+class VertexBuffer
+{
+public:
+ enum VertexBufferType
+ {
+ VertexBufferType_Static, // device
+ VertexBufferType_Stream, // pinned (best performance)
+ VertexBufferType_Dynamic,// device
+ };
+
+ VertexBuffer(VertexBufferType type);
+ ~VertexBuffer();
+
+ void Draw();
+
+private:
+
+ VertexBufferType m_Type;
+ GPU::DataBuffer *m_VB, *m_IB;// vertex buffer and index buffer
+
+};
+
+class SharedVertexBuffer
+{
+public:
+ void GetChunk(uint attrs, int maxVerts, int maxIndices, RenderMode mode, void **out_vb, void **out_ib);
+ void ReleaseChunk(int actualVerts, int actualIndices);
+
+ void DrawChunk();
+
+private:
+
+ void FillVertexArrayInfo(VertexArrayInfo& dst);
+
+ void Clean();
+
+ // if vertex databuffer size beyond this value, use pinned memory mapping, instead of glBufferData.
+ enum { DataBufferThreshold = 1024 };
+
+ // shared vbo and ibo
+ GPU::DataBuffer *m_CurVB, *m_CurIB;
+
+ // restore vbo and ibo data if not using pinned memory mapping
+ std::vector<byte> m_CurVBData;
+ std::vector<uint16> m_CurIBData;
+
+ RenderMode m_CurRenderMode;
+
+ uint m_CurAttrMask;
+ uint m_CurStride;
+
+ uint m_CurVertexCount;
+ uint m_CurIndexCount;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/ImGUI/GUIButton.cpp b/Runtime/ImGUI/GUIButton.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/ImGUI/GUIButton.cpp
diff --git a/Runtime/ImGUI/GUIButton.h b/Runtime/ImGUI/GUIButton.h
new file mode 100644
index 0000000..fbcd0bb
--- /dev/null
+++ b/Runtime/ImGUI/GUIButton.h
@@ -0,0 +1,6 @@
+#ifndef GUI_BUTTON_H
+#define GUI_BUTTON_H
+
+
+
+#endif \ No newline at end of file
diff --git a/Runtime/ImGUI/GUILabel.cpp b/Runtime/ImGUI/GUILabel.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/ImGUI/GUILabel.cpp
diff --git a/Runtime/ImGUI/GUILabel.h b/Runtime/ImGUI/GUILabel.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/ImGUI/GUILabel.h
diff --git a/Runtime/Input/Input.cpp b/Runtime/Input/Input.cpp
new file mode 100644
index 0000000..d82bd64
--- /dev/null
+++ b/Runtime/Input/Input.cpp
@@ -0,0 +1,3 @@
+#include "Input.h"
+
+
diff --git a/Runtime/Input/Input.h b/Runtime/Input/Input.h
new file mode 100644
index 0000000..5612e74
--- /dev/null
+++ b/Runtime/Input/Input.h
@@ -0,0 +1,19 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include "SDL2/SDL.h"
+
+class Input
+{
+public:
+ void PollEvent(SDL_Event& e);
+
+ bool IsKeyDown();
+ bool IsKeyUp();
+ bool IsKeyClick();
+
+};
+
+extern Input g_Input;
+
+#endif \ No newline at end of file
diff --git a/Runtime/Math/AABB.h b/Runtime/Math/AABB.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Math/AABB.h
diff --git a/Runtime/Math/Vector2.cpp b/Runtime/Math/Vector2.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Math/Vector2.cpp
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
new file mode 100644
index 0000000..7bf3987
--- /dev/null
+++ b/Runtime/Math/Vector2.h
@@ -0,0 +1,17 @@
+#ifndef VECTOR2_H
+#define VECTOR2_H
+
+class Vector2
+{
+public:
+ float x, y;
+
+ inline void Set(float x, float y)
+ {
+ this->x = x;
+ this->y = y;
+ }
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Math/Vector3.cpp b/Runtime/Math/Vector3.cpp
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/Runtime/Math/Vector3.cpp
@@ -0,0 +1 @@
+
diff --git a/Runtime/Math/Vector3.h b/Runtime/Math/Vector3.h
new file mode 100644
index 0000000..041ffef
--- /dev/null
+++ b/Runtime/Math/Vector3.h
@@ -0,0 +1,18 @@
+#ifndef VECTOR3_H
+#define VECTOR3_H
+
+class Vector3
+{
+public:
+ float x, y, z;
+
+ inline void Set(float x, float y, float z)
+ {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ }
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Mesh/Font.cpp b/Runtime/Mesh/Font.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Mesh/Font.cpp
diff --git a/Runtime/Mesh/Font.h b/Runtime/Mesh/Font.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Mesh/Font.h
diff --git a/Runtime/Mesh/FontManager.h b/Runtime/Mesh/FontManager.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Mesh/FontManager.h
diff --git a/Runtime/Mesh/Glyph.h b/Runtime/Mesh/Glyph.h
new file mode 100644
index 0000000..6020b45
--- /dev/null
+++ b/Runtime/Mesh/Glyph.h
@@ -0,0 +1,9 @@
+#ifndef GLYPH_H
+#define GLYPH_H
+
+class Glyph
+{
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Mesh/Mesh.cpp b/Runtime/Mesh/Mesh.cpp
new file mode 100644
index 0000000..95bd597
--- /dev/null
+++ b/Runtime/Mesh/Mesh.cpp
@@ -0,0 +1,4 @@
+#include "Mesh.h"
+#include "MeshUtil.h"
+
+
diff --git a/Runtime/Mesh/Mesh.h b/Runtime/Mesh/Mesh.h
new file mode 100644
index 0000000..77c6577
--- /dev/null
+++ b/Runtime/Mesh/Mesh.h
@@ -0,0 +1,62 @@
+#ifndef MESH_H
+#define MESH_H
+
+#include "../Graphics/VertexBuffer.h"
+#include "../Utilities/Type.h"
+
+// Ïà¶ÔVertexBuffer¸ü¼Óuplevel
+class Mesh
+{
+public:
+
+ Mesh(bool readable = false);
+ ~Mesh();
+
+ void IsReadable();
+
+ void SetVertices(float* data);
+ void SetNormals(float* data);
+ void SetTangents(float* data);
+ void SetColors(float* data);
+ void SetTexCoords(int channel, float* data);
+
+ void SetTriangles(int* indices);
+ void SetIndices(int* indices);
+
+ void SetVertices(float* data, int start, int length);
+ void SetNormals(float* data, int start, int length);
+ void SetTangents(float* data, int start, int length);
+ void SetColors(float* data, int start, int length);
+ void SetTexCoords(int channel, float* data, int start, int length);
+
+ void SetVertex(float x, float y, float z, int index);
+ void SetNormal(float x, float y, float z, int index);
+ void SetTangent(float x, float y, float z, int index);
+ void SetColor(float r, float g, float b, float a, int index);
+ void SetTexCoord(float u, float v, int index);
+
+ void GetAABB(float bias = 0.f);
+
+ inline bool HasVertexAttr(VertexAttrMask attr);
+
+ void Draw();
+
+ void CalculateNormal();
+ void CalculateTangent();
+
+private:
+
+ uint m_VertexAttrBits;
+
+ bool m_IsReadable;
+
+ VertexBuffer* m_VBO;
+
+};
+
+inline bool Mesh::HasVertexAttr(VertexAttrMask attr)
+{
+ return m_VertexAttrBits & attr;
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Mesh/MeshUtil.h b/Runtime/Mesh/MeshUtil.h
new file mode 100644
index 0000000..830ac70
--- /dev/null
+++ b/Runtime/Mesh/MeshUtil.h
@@ -0,0 +1,6 @@
+#ifndef MESH_UTIL_H
+#define MESH_UTIL_H
+
+
+
+#endif \ No newline at end of file
diff --git a/Runtime/Mesh/TextMesh.h b/Runtime/Mesh/TextMesh.h
new file mode 100644
index 0000000..1f27bbb
--- /dev/null
+++ b/Runtime/Mesh/TextMesh.h
@@ -0,0 +1,11 @@
+#ifndef TEXT_MESH_H
+#define TEXT_MESH_H
+
+class TextMesh
+{
+public:
+
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Physics/Rigidbody.h b/Runtime/Physics/Rigidbody.h
new file mode 100644
index 0000000..6692567
--- /dev/null
+++ b/Runtime/Physics/Rigidbody.h
@@ -0,0 +1,6 @@
+#ifndef RIGIDBODY_H
+#define RIGIDBODY_H
+
+
+
+#endif \ No newline at end of file
diff --git a/Runtime/Physics/Scripting/wrap_Joint.cpp b/Runtime/Physics/Scripting/wrap_Joint.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Physics/Scripting/wrap_Joint.cpp
diff --git a/Runtime/Profiler/FrameStats.h b/Runtime/Profiler/FrameStats.h
new file mode 100644
index 0000000..b3073d5
--- /dev/null
+++ b/Runtime/Profiler/FrameStats.h
@@ -0,0 +1,29 @@
+#ifndef FRAME_STATS_H
+#define FRAME_STATS_H
+
+#include "../Utilities/Singleton.h"
+#include "../Utilities/UtilMacros.h"
+#include "../Utilities/Type.h"
+
+class FrameStats : public Singleton<FrameStats>
+{
+public:
+ void OnBeginFrame();
+ void OnEndFrame();
+
+ void AddDrawCall(uint n = 1);
+ void AddTrianglesCount(uint n = 1);
+
+ GET(uint, DrawCall, m_DrawCall);
+ GET(uint, TrianglesCount, m_TrianglesCount);
+
+private:
+
+ uint m_DrawCall;
+ uint m_TrianglesCount;
+
+};
+
+#define g_FrameStats (*FrameStats::Instance())
+
+#endif \ No newline at end of file
diff --git a/Runtime/Profiler/Profiler.h b/Runtime/Profiler/Profiler.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Profiler/Profiler.h
diff --git a/Runtime/Scripting/luax.h b/Runtime/Scripting/luax.h
new file mode 100644
index 0000000..1980f41
--- /dev/null
+++ b/Runtime/Scripting/luax.h
@@ -0,0 +1,18 @@
+#ifndef __LUAX_H__
+#define __LUAX_H__
+
+///
+/// Luax(port) library ÓÃÓÚ¸ølua×¢²áÀàºÍº¯Êý
+///
+
+#include "luax_state.h"
+#include "luax_vm.h"
+#include "luax_ref.h"
+#include "luax_reftable.h"
+#include "luax_enum.h"
+#include "luax_class.hpp"
+#include "luax_memberref.h"
+#include "luax_class.inc"
+#include "luax_state.inc"
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_cfunctions.cpp b/Runtime/Scripting/luax_cfunctions.cpp
new file mode 100644
index 0000000..d93a0ee
--- /dev/null
+++ b/Runtime/Scripting/luax_cfunctions.cpp
@@ -0,0 +1,19 @@
+#include "luax_cfunctions.h"
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ int luax_c_getupvalue(lua_State* L)
+ {
+ lua_pushvalue(L, lua_upvalueindex(1));
+ return 1;
+ }
+
+ int luax_c_errfunc(lua_State* L)
+ {
+ cc8* msg = luaL_optstring(L, lua_upvalueindex(1), "");
+ return luaL_error(L, msg);
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_cfunctions.h b/Runtime/Scripting/luax_cfunctions.h
new file mode 100644
index 0000000..2570bb9
--- /dev/null
+++ b/Runtime/Scripting/luax_cfunctions.h
@@ -0,0 +1,25 @@
+#ifndef __LUAX_CFUNCTIONS_H__
+#define __LUAX_CFUNCTIONS_H__
+
+#include "luax_config.h"
+
+/**
+ * luax_cfunctionÀïµÄº¯ÊýÓÃÀ´×¢²á¸ølua£¬Ò»Ð©ÌØÊ⹦ÄܵÄͨÓú¯Êý¡£
+*/
+
+namespace Luax
+{
+
+ ///
+ /// »ñµÃµÚÒ»¸öupvalue
+ ///
+ extern int luax_c_getupvalue(lua_State* L);
+
+ ///
+ /// µ÷Óô˺¯Êýʱ»á±¨´í£¬upvalue(1)ÊÇ´íÎóÐÅÏ¢
+ ///
+ extern int luax_c_errfunc(lua_State* L);
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_class.cpp b/Runtime/Scripting/luax_class.cpp
new file mode 100644
index 0000000..762f0dc
--- /dev/null
+++ b/Runtime/Scripting/luax_class.cpp
@@ -0,0 +1,243 @@
+#include "luax_class.hpp"
+#include "luax_cfunctions.h"
+#include "luax_vm.h"
+
+namespace Luax
+{
+
+#if LUAX_ENABLE_PLAIN_CLASS
+
+ int LuaxPlainClass::registry(lua_State* L)
+ {
+ LUAX_STATE(L);
+
+ // params:
+ // 1: class name
+
+ cc8* type = state.GetValue<cc8*>(1, "");
+
+ lua_newtable(L); // class table
+
+ // GetClassName()
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClassName");
+
+ // GetClass()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClass");
+
+ // TypeOf()
+ lua_pushcfunction(L, _TypeOf);
+ lua_setfield(L, -2, "TypeOf");
+
+ // New()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, _New, 1);
+ lua_setfield(L, -2, "New");
+
+ // Extend()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, _Extend, 1);
+ lua_setfield(L, -2, "Extend");
+
+ lua_pushvalue(L, -1); // class table
+ lua_setfield(L, -2, "__index");
+
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, __tostring, 1);
+ lua_setfield(L, -2, "__tostring");
+
+ return 1;
+ }
+
+ int LuaxPlainClass::__tostring(lua_State* L)
+ {
+ // upvalues:
+ // 1: class name
+
+ // params:
+ // 1: instance
+
+ if (!lua_istable(L, 1))
+ {
+ return luaL_typerror(L, 1, lua_typename(L, LUA_TTABLE));
+ }
+
+ cc8* type = lua_tostring(L, lua_upvalueindex(1));
+
+ lua_pushfstring(L, "%s: %p", type, lua_topointer(L, 1));
+
+ return 1;
+ }
+
+ ///
+ /// Newº¯Êý½ÓÊÜn¸ö²ÎÊý£¬²¢³¢ÊÔ»ñÈ¡__init£¬½«²ÎÊý´«¸ø__init³õʼ»¯ÊµÀý¡£
+ ///
+ int LuaxPlainClass::_New(lua_State* L)
+ {
+ LUAX_STATE(L);
+
+ // upvalues:
+ // 1: class table
+
+ // params:
+ // n: params
+ int n = lua_gettop(L);
+
+ int classTable = lua_upvalueindex(1);
+
+ lua_newtable(L); // instance table
+
+ // instance µÄ metatable ÉèÖÃΪ class
+ lua_pushvalue(L, classTable);
+ lua_setmetatable(L, -2);
+
+ // ÕÒµ½¹¹Ô캯Êý£¬»á´¥·¢metatable.__index,¸ù¾Ý¼Ì³ÐÁ´ÏòÉÏÕÒ¡£
+ lua_getfield(L, classTable, "__init");
+ if (state.IsType(-1, LUA_TFUNCTION))
+ {
+ // stack:
+ // -1: __init()
+ // -2: instance
+ // -3~-n-2: params
+
+ lua_insert(L, -2 - n);
+ // stack:
+ // -1: instance
+ // -2~-n-1: params
+ // -n-2: __init()
+
+ lua_pushvalue(L, -1);
+ // stack:
+ // -1: instance
+ // -2: instance
+ // -3~-n-2: params
+ // -n-3: __init
+
+ lua_insert(L, -3 - n);
+ // stack:
+ // -1: instance
+ // -2~-n-1: params
+ // -n-2: __init()
+ // -n-3: instance
+
+ lua_insert(L, -1 - n);
+ // stack:
+ // -1~-n: params
+ // -n-1: instance
+ // -n-2: __init()
+ // -n-3: instance
+
+ lua_pcall(L, n + 1, 0, 0);
+ }
+ else
+ {
+ state.Pop();
+ }
+
+ return 1;
+ }
+
+ int LuaxPlainClass::_Extend(lua_State* L)
+ {
+ LUAX_STATE(L);
+
+ // upvalues:
+ // 1: base class
+
+ // params:
+ // 1: class name
+
+ cc8* type = state.GetValue<cc8*>(1, "");
+
+ int baseClass = lua_upvalueindex(1);
+
+ lua_newtable(L); // class table
+
+ // GetClassName()
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClassName");
+
+ // GetClass()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClass");
+
+ // New()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, _New, 1);
+ lua_setfield(L, -2, "New");
+
+ // Extend()
+ lua_pushvalue(L, -1); // class table
+ lua_pushcclosure(L, _Extend, 1);
+ lua_setfield(L, -2, "Extend");
+
+ // .__base ÓÃÀ´Ë÷Òýµ½»ùÀà
+ lua_pushvalue(L, baseClass); // base class
+ lua_setfield(L, -2, "__base");
+
+ lua_pushvalue(L, -1); // class table
+ lua_setfield(L, -2, "__index");
+
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, __tostring, 1);
+ lua_setfield(L, -2, "__tostring");
+
+ // classµÄmetatableÉèÖÃΪbaseClass
+ lua_pushvalue(L, baseClass);
+ lua_setmetatable(L, -2);
+
+ return 1;
+ }
+
+ int LuaxPlainClass::_TypeOf(lua_State* L)
+ {
+ // params:
+ // 1: lua instance
+ // 2: type string
+
+ LUAX_STATE(L);
+
+ cc8* type = state.GetValue<cc8*>(2, "");
+
+ if (!lua_istable(L, 1))
+ {
+ return luaL_typerror(L, 1, "Object");
+ }
+
+ lua_pushvalue(L, 1); // lua instance
+
+ while (lua_getmetatable(L, -1))
+ {
+ lua_getfield(L, -1, "GetClassName");
+ if (lua_isfunction(L, -1))
+ {
+ state.Call(0, 1);
+ cc8* name = state.GetValue<cc8*>(-1, "");
+ if (strcmp(name, type) == 0)
+ {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+ else
+ {
+ state.Pop(); // name
+ }
+ }
+ else
+ {
+ state.Pop();
+ }
+ }
+
+ lua_pushboolean(L, false);
+ return 1;
+ }
+
+#endif /*LUAX_ENABLE_PLAIN_CLASS*/
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_class.hpp b/Runtime/Scripting/luax_class.hpp
new file mode 100644
index 0000000..12eb268
--- /dev/null
+++ b/Runtime/Scripting/luax_class.hpp
@@ -0,0 +1,207 @@
+#ifndef __LUAX_CLASS_H__
+#define __LUAX_CLASS_H__
+
+#include "luax_config.h"
+
+#if LUAX_PROFILER
+#include <unordered_set>
+#endif
+
+#include <vector>
+
+#include "luax_ref.h"
+#include "luax_memberref.h"
+#include "luax_cfunctions.h"
+#include "luax_watchdog.h"
+#include "luax_utility.h"
+
+namespace Luax
+{
+
+ class LuaxVM;
+
+ ///
+ /// Ðé»ùÀ࣬ΪÁËʵÏÖ¶à̬¡£ÐèÒª·ÃÎÊÏÂÃæÕâЩ½Ó¿ÚµÄÍⲿ»ùÀàÐèÒªÐé¼Ì³Ð´ËÀ֮࣬ºóÔÙÅÉÉúÁ´Öоͻá
+ /// µ÷ÓöÔӦʵÌåµÄ·½·¨¡£×¢Òâ¼Ì³Ð´ËÀàʱ²»ÄÜʵÏÖÏÂÃæµÄ·½·¨£¬ÊµÏÖÔÚLuaxNativeClassÖУ¬ÊµÏÖ»á
+ /// µ¼Ö¶þÒåÐÔ¡£
+ ///
+ /// ÒÀ¾ÝEffective C++Ìõ¿î40£¬Èç¹ûÔÚ±ØÐëʹÓÃvirtual base»ùÀàÇé¿öÏ£¬Ó¦¸Ã¾¡¿ÉÄܱÜÃâÏòÆäÖзÅ
+ /// ÖÃÊý¾Ý³ÉÔ±£¬¹æ±ÜÊý¾Ý³ÉÔ±³õʼ»¯Ôì³ÉµÄһЩÒþÐÔÎÊÌâ¡£ÒÀ¾ÝÕâÒ»µã£¬vpb»ùÀà¸ü¼Ó½Ó½üC#ºÍJavaÖÐ
+ /// µÄInterface¡£ËùÒÔ£¬ÔÚÕâÀï°ÑÀàÓÃI¿ªÍ·±êʶÕâÊÇÒ»¸ö½Ó¿Ú¡£
+ ///
+ class LuaxObject
+ {
+ public:
+ LuaxObject() {};
+ virtual ~LuaxObject() {};
+
+ ///
+ /// ³ÉÔ±ÒýÓùÜÀí£¬ÔÚʵÀýµÄref tableÀï¡£ÉèÖá¢È¡¡¢Çå³ý¡£
+ ///
+ virtual bool PushLuaxMemberRef(LuaxState& state, int refID) = 0;
+ virtual bool PushLuaxUserdata(LuaxState& state) = 0;
+ virtual bool PushLuaxMemberTable(LuaxState& state) = 0;
+ virtual bool PushLuaxRefTable(LuaxState& state) = 0;
+
+ ///
+ /// ±»LuaxNativeClassʵÏÖ¡£±£³ÖºÍÊÍ·Ånative×ÊÔ´¡£
+ ///
+ virtual void Retain() = 0;
+ virtual void Release() = 0;
+
+ };
+
+ // TODO: ½«¹«¹²²¿·ÖÌáÈ¡³öÀ´£¬²»ÒªÖظ´Éú³É´úÂë
+ //class LuaxNativeClassBase
+ //{
+ //}
+
+ ///
+ /// ÐèÒª±©Â¶¸øluaµÄnative classÐèÒª¼Ì³Ð´ËÀࡣͨ¹ýlua¹ÜÀíµÄʵÀýҪȷ±£ÒýÓüÆÊýµÄÕýÈ·ÐÔ£¬ÔÚ¶à¸öÏß³ÌÖÐÐèҪȷ
+ /// ¶¨²»»áÎóÊÍ·Å¡£
+ ///
+ template<class TYPE, class BASE = LuaxObject>
+ class LuaxNativeClass : public BASE
+ {
+ public:
+
+ ///
+ /// ½«userdata×÷Ϊkey£¬ÔÚref tableÀï¶ÔuserdataÌí¼ÓÒ»¸öÒýÓã¬ÒÔά³ÖuserdataµÄÉúÃüÖÜÆÚ¡£
+ /// Ïà±È½Ïmember ref£¬Õâ¸öÓÃÔÚʵÌå»á±»¶à´Î±»²»Í¬ÆäËûʵÌåÒýÓõÄÇé¿ö£¬²¢Æµ·±Ïú»ÙÕâЩʵÌ壬
+ /// ±ÜÃâluaƵ·±µÄµ÷ÓÃgc¼ì²â¡£
+ ///
+ template<class DATATYPE> void LuaxRetain(LuaxState& state, DATATYPE* userdata);
+
+ ///
+ /// ¶Ôuserdata¼õÉÙÒ»¸öÒýÓÃÔÚref tableÀÒÔ³¢ÊÔ»ØÊÕuserdata¡£
+ ///
+ template<class DATATYPE> void LuaxRelease(LuaxState& state, DATATYPE* userdata);
+
+ ///
+ /// ½«userdata pushµ½Õ»¶¥£¬Èç¹ûûÓгõʼ»¯mUserdata£¬³õʼ»¯ÉèÖúÃÔª±í²¢°Ñ³õʼ»¯ºÃµÄ
+ /// userdataÁôÔÚÕ»¶¥¡£²¢Ìí¼ÓÒ»¸öÒýÓá£ÕâÊÇÒ»¸ö½«native¶ÔÏóËùÓÐÈ¨ÒÆ½»¸ølua¿ØÖƵķ½·¨¡£
+ ///
+ bool PushLuaxMemberRef(LuaxState& state, int refID) override;
+ bool PushLuaxUserdata(LuaxState& state) override;
+ bool PushLuaxMemberTable(LuaxState& state) override;
+ bool PushLuaxRefTable(LuaxState& state) override;
+
+ ///
+ /// Watch dog Ìí¼ÓÒ»¸önativeÒýÓá£luaVMÒýÓò»»áÌṩÍⲿ½Ó¿Ú¡£¼Ì³Ð´ËÀàµÄÅÉÉúÀ಻ÄÜÖ±½ÓʹÓÃ
+ /// delete·½·¨£¬Ó¦¸ÃʹÓÃReleaseÊÍ·Å¡£Ò»°ãÇé¿öÏÂÕâ¸ö²Ù×÷ÓÉÐéÄâ»ú__gc½øÐУ¬µ«ÊÇÔÊÐíÓû§
+ /// ³ÌÐòÔÚnativeÖиô¾øÐéÄâ»úÇé¿öÏÂÊÍ·Å£¬ÕâÖÖÇé¿öÏÂҪʹÓÃRelease¡£
+ ///
+ /// ÕâÁ½¸öº¯ÊýÊÇnative½Ó¿Ú¡£
+ ///
+ void Retain() override final;
+ void Release() override final;
+
+#if LUAX_PROFILER
+ // ¶Ô¶ÑÉÏ´´½¨µÄʵÀý½øÐÐdelete±£ÏÕ¼ì²é
+ static void operator delete(void* pdead, size_t size);
+#endif
+
+ protected:
+
+ LuaxNativeClass();
+ virtual ~LuaxNativeClass();
+
+ ///
+ /// ³ÉÔ±ÒýÓùÜÀí£¬ÔÚʵÀýµÄref tableÀï¡£ÉèÖá¢È¡¡¢Çå³ý
+ ///
+ void SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx);
+ bool PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
+ void ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
+
+ private:
+
+ friend class LuaxState;
+
+ static void RegisterLuaxClassShared(LuaxState& state);
+ static void RegisterLuaxFactoryClass(LuaxState& state);
+ static void RegisterLuaxSingletonClass(LuaxState& state);
+
+ static void SetLuaxClassTableRef(LuaxState& state, int idx);
+ static void PushLuaxClassTable(LuaxState& state);
+
+ ///
+ /// ´´½¨userdata£¬°ó¶¨ÊµÀýµ½state¡£
+ ///
+ void BindToLua(LuaxState& state);
+
+ //------------------------------------------------------------------------------//
+
+ // ¹«¹²ÄÚÈÝ
+ static int __tostring (lua_State*);
+ static int _GetClass (lua_State*);
+ static int _GetClassName (lua_State*);
+
+ // ¹¤³§ÀàÏà¹Ø
+ static int __gc (lua_State*);
+ static int _GetRefTable (lua_State*);
+ static int _New (lua_State*);
+
+#if LUAX_ENABLE_NATIVE_EXTEND
+ static int _ExtendFactory (lua_State*);
+ static int _ExtendSingleton (lua_State*);
+#endif
+
+ //--------------------------------------------------------------------------------//
+
+ ///
+ /// class table£¬¹¤³§ºÍµ¥Àý¶¼ÓС£
+ ///
+ static LuaxStrongRef mClassTable;
+
+ ///
+ /// Èç¹ûÀàÊǵ¥Àý£¬Õâ¸öÓÃÀ´±£´æsingletonµÄÒýÓùØÏµ£¬ÒÔ±£Ö¤²»»á±»»ØÊÕÀàËÆÆÕͨÀàµÄref table¡£
+ /// µ¥ÀýµÄ³ÉÔ±ÊÇÈ«ÉúÃüÖÜÆÚµÄ£¬ËùÒÔÖ±½ÓÔÚ_LUAX_STRONGREF_TABLE¡£µ¥Àý¶Ôuserdata½øÐÐ
+ /// LuaxRetain\LuaxReleaseºÍmember ref²Ù×÷ʱºÍ¹¤³§ÊµÀý²»Í¬£¬ÊÇ´æÔÚÏÂÃæÕâ¸öref tableÀï
+ /// µÄ£¬Õâ¸ötableÔÚ_LUAX_STRONGREF_TABLEÀï¡£
+ ///
+ static LuaxStrongRef mSingletonRefTable;
+
+ ///
+ /// ͨ¹ýuserdata¿ÉÒÔÄõ½:
+ /// 1: ref table
+ /// 2: member table
+ /// 3: class table
+ ///
+ LuaxWeakRef mUserdata;
+
+ /// ͨ¹ýºó²ÅÄÜɾ³ý
+ LuaxWatchDog mWatchDog;
+
+#if LUAX_PROFILER
+ // Íйܴ˶ÔÏóµÄÐéÄâ»ú
+ std::unordered_set<LuaxVM*> mRefVMs;
+ // ±£ÏÕ£¬´ËÀàµÄÅÉÉúÀ಻ÄÜÔÚÍⲿʹÓÃdeleteÖ±½Óɾ³ý£¬¶øÓ¦¸ÃʹÓÃRelease
+ bool mSafer;
+#endif
+
+ };
+
+#if LUAX_ENABLE_PLAIN_CLASS
+ ///
+ /// ´¿luaÀà
+ ///
+ class LuaxPlainClass
+ {
+ public:
+
+ ///
+ /// ÓÃÀ´×¢²áÀàµÄÈë¿Úº¯Êý¡£¿ÉÒÔͨ¹ýregistry(ÀàÃû)×¢²áÀà¡£
+ ///
+ static int registry(lua_State* L);
+
+ LUAX_DECL_METHOD(__tostring);
+ LUAX_DECL_METHOD(_Extend);
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_TypeOf);
+
+ };
+#endif
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_class.inc b/Runtime/Scripting/luax_class.inc
new file mode 100644
index 0000000..1d6a89f
--- /dev/null
+++ b/Runtime/Scripting/luax_class.inc
@@ -0,0 +1,637 @@
+namespace Luax
+{
+
+ //--------------------------------------------------------------------------------//
+
+ ///
+ /// ¶Ô²»Í¬ÀàÐÍ£¬Í¨¹ýµ÷ÓÃGetLuaClassName»ñµÃÀàÐÍÃû£¬Èç¹ûÊÇÅÉÉúÀ࣬GetClassName»á±»¸²¸Ç£¬Ö¸Ïòluax_c_getupvalue¡£
+ ///
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetClassName(lua_State* L)
+ {
+ LUAX_SETUP(L, "*");
+
+ cc8* type = TYPE::GetLuaxClassName();
+ state.Push(type);
+ return 1;
+ }
+
+ //--------------------------------------------------------------------------------//
+
+ ///
+ /// ×¢²á¹¤³§ºÍµ¥Àý¹²ÓеÄÀà³ÉÔ±
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxClassShared(LuaxState& state)
+ {
+ luaL_Reg regTable[] = {
+ { "GetClass", _GetClass },
+ { "GetClassName", _GetClassName },
+ { NULL, NULL }
+ };
+
+ state.RegisterMethods(regTable);
+ }
+
+ ///
+ /// ¹¤³§ÀàµÄ³ÉÔ±£¬×¢²áÔÚclass table
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxFactoryClass(LuaxState& state)
+ {
+ luaL_Reg regTable[] = {
+ { "GetRefTable", _GetRefTable },
+ { NULL, NULL }
+ };
+
+ state.RegisterMethods(regTable);
+ }
+
+ ///
+ /// µ¥ÀýÀàµÄ³ÉÔ±£¬×¢²áÔÚclass table
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxSingletonClass(LuaxState& state)
+ {
+ luaL_Reg regTable[] = {
+ { NULL, NULL }
+ };
+
+ state.RegisterMethods(regTable);
+ }
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::PushLuaxClassTable(LuaxState& state)
+ {
+ assert(mClassTable);
+
+ mClassTable.PushRef(state);
+ }
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::SetLuaxClassTableRef(LuaxState& state, int idx)
+ {
+ mClassTable.SetRef(state, idx);
+ }
+
+ template<class TYPE, class BASE>
+ LuaxNativeClass<TYPE, BASE>::LuaxNativeClass()
+ : mWatchDog()
+#if LUAX_PROFILER
+ , mSafer(false)
+#endif
+ {
+ }
+
+ template<class TYPE, class BASE>
+ LuaxNativeClass<TYPE, BASE>::~LuaxNativeClass()
+ {
+ }
+
+#if LUAX_PROFILER
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::operator delete(void* pdead, size_t size)
+ {
+ if (pdead == nullptr)
+ return;
+ // ¶ÑÉÏ´´½¨µÄʵÀý±ØÐëʹÓÃReleaseÊÍ·Å¡£
+ TYPE* p = static_cast<TYPE*>(pdead);
+ assert(p->mSafer);
+ ::operator delete(pdead, size);
+ }
+#endif
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::Retain()
+ {
+ ++mWatchDog.mNativeRef;
+ }
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::Release()
+ {
+ if (mWatchDog.mNativeRef > 0)
+ --mWatchDog.mNativeRef;
+ if (mWatchDog)
+ {
+#if LUAX_PROFILER
+ mSafer = true;
+#endif
+ delete this;
+ }
+ }
+
+ template<class TYPE, class BASE>
+ template<typename U>
+ void LuaxNativeClass<TYPE, BASE>::LuaxRetain(LuaxState& state, U* userdata)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ if (userdata->PushLuaxUserdata(state))
+ {
+ lua_pushvalue(state, -1); // copy the userdata
+ lua_gettable(state, -3); // get the count (or nil)
+ u32 count = state.GetValue<u32>(-1, 0); // get the count (or 0)
+ lua_pop(state, 1); // pop the old count
+ lua_pushnumber(state, count + 1); // push the new count
+ lua_settable(state, -3); // save it in the table: reftable[userdata] = count
+ }
+ }
+ }
+
+ template<class TYPE, class BASE>
+ template<typename U>
+ void LuaxNativeClass<TYPE, BASE>::LuaxRelease(LuaxState& state, U* userdata)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ if (userdata->PushLuaxUserdata(state))
+ {
+ lua_pushvalue(state, -1); // copy the userdata
+ lua_gettable(state, -3); // get the count (or nil)
+ u32 count = state.GetValue<u32>(-1, 0); // get the count (or 0)
+ lua_pop(state, 1); // pop the old count
+
+ // no such reference
+ if (count == 0)
+ {
+ state.Pop(2); // userdata, reftable
+ return; // nothing to do
+ }
+
+ if (count > 1) {
+ lua_pushnumber(state, count - 1); // push the new count
+ }
+ else {
+ lua_pushnil(state); // maybe cause gc
+ }
+ lua_settable(state, -3); // save it in the table
+
+ state.Pop(1); // reftable
+ return;
+ }
+ state.Pop(2); // nil, reftable
+ return;
+ }
+ }
+
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxUserdata(LuaxState& state)
+ {
+ assert(!TYPE::IsLuaxClassSingleton());
+ if (!mUserdata)
+ {
+ BindToLua(state);
+ return true;
+ }
+ return mUserdata.PushRef(state);
+ }
+
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberTable(LuaxState& state)
+ {
+ int top = state.GetTop();
+ if (this->PushLuaxUserdata(state))
+ {
+ if (lua_getmetatable(state, -1)) // ref table
+ {
+ lua_replace(state, -2);
+ if (lua_getmetatable(state, -1)) // member table
+ {
+ lua_replace(state, -2);
+ return true;
+ }
+ }
+ }
+ lua_settop(state, top);
+ lua_pushnil(state);
+ return false;
+ }
+
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxRefTable(LuaxState& state)
+ {
+ // Singleton
+ if (TYPE::IsLuaxClassSingleton())
+ {
+ if (!this->mSingletonRefTable) {
+ lua_newtable(state);
+ this->mSingletonRefTable.SetRef(state, -1); // strong ref to member table won't be garbage collected
+ }
+ else {
+ this->mSingletonRefTable.PushRef(state);
+ }
+ return true;
+ }
+ // Factory
+ else
+ {
+ if (this->PushLuaxUserdata(state))
+ {
+ if (lua_getmetatable(state, -1))
+ {
+ lua_replace(state, -2);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ ///
+ /// ´´½¨userdata£¬²¢ÒÔ´ËÌí¼Óref table£¬member tableºÍclass table¡£
+ /// ref table ÊÇkvÇ¿ÒýÓÃtable£¬±£´æ¶ÔÆäËûuserdataµÄÒýÓüÆÊý£¨Í¨¹ýuserdata×÷Ϊkey£¬
+ /// ¼ÆÊýΪvalue£©£¬ÒÔ¼°³ÉÔ±ÒýÓÃ
+ /// member table ±£´ælua´´½¨µÄʵÀýµÄ³ÉÔ±
+ /// class table ËùÓб¾ÀàÐ͵ÄʵÀý¹²Óеĺ¯Êý±í
+ ///
+ /// BindToLuaÖ»»áÔÚµÚÒ»´Î×¢²á¸øLuaÐéÄâ»úʱµ÷Óá£
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::BindToLua(LuaxState& state)
+ {
+ // µ¥Àý²»Äܰó¶¨userdata
+ assert(!TYPE::IsLuaxClassSingleton());
+ assert(!mUserdata);
+
+ ///
+ /// ´´½¨userdata²¢ÁôÔÚÕ»¶¥£¬×¢ÒâµØÖ·Òª×ª»»ÎªTYPE*£¬Ö±½ÓÓÃthis¿ÉÄܻᵼÖ¶àÖØ¼Ì³ÐµÄÀàɥʧ¶à̬¡£
+ /// Èç¹ûÖ±½Ó´«this½øÈ¥£¬ÔÚ¶àÖØ¼Ì³ÐÇé¿öÏ£¬ÊÇÄò»µ½ÁíһͷµÄÐ麯Êý±íµÄ¡£ËùÒÔÕâÀïÐèÒª½«this
+ /// ת»»ÎªÕû¸ö¶ÔÏóµÄµÍµØÖ·£¬ÕâÑù¿ÉÒÔÄõ½ÁíÒ»¸ö»ùÀàµÄÐ麯Êý±í£¬Í¨¹ýÁíÒ»¸ö»ùÀàʵÏÖ¶à̬¡£
+ ///
+ TYPE* p = static_cast<TYPE*>(this);
+ state.PushPtrUserdata(p);
+
+ lua_newtable(state); // ref table£¬ÎÞ·¨ÔÚlua´¦·ÃÎÊ£¬ÓÃÀ´¹ÜÀíC¶ÔÏóµÄÉúÃüÖÜÆÚ
+ lua_newtable(state); // member table£¬luaÖд´½¨µÄ¶ÔÏó³ÉÔ±¶¼±£´æÔÚÕâÀï
+ PushLuaxClassTable(state); // class table
+
+ // stack:
+ // -1: class table
+ // -2: member table
+ // -3: ref table
+ // -4: userdata
+
+ int top = state.GetTop();
+ int memberTable = top - 1;
+ int refTable = top - 2;
+
+ // ref table ×¢²á __tostring ºÍ __gc
+ lua_pushcfunction(state, __tostring);
+ lua_setfield(state, refTable, "__tostring");
+
+ lua_pushcfunction(state, __gc);
+ lua_setfield(state, refTable, "__gc");
+
+ // ref table µÄ __index ºÍ __newindex ÉèΪ member table
+ lua_pushvalue(state, memberTable);
+ lua_setfield(state, refTable, "__index");
+
+ lua_pushvalue(state, memberTable);
+ lua_setfield(state, refTable, "__newindex");
+
+ // ÉèÖÃÔª±í
+ lua_setmetatable(state, -2); // class is meta of member
+ lua_setmetatable(state, -2); // member is meta of ref
+ lua_setmetatable(state, -2); // ref is meta of userdata
+
+ // ÉèÖÃÒ»¸öuserdataµÄÈõÒýÓ㬷½±ãͨ¹ýPushLuaUserdata·½·¨·µ»Ølua¶ÔÏó
+ mUserdata.SetRef(state, -1);
+ assert(mUserdata);
+
+ // Ôö¼ÓÒ»¸öÐéÄâ»úÒýÓã¬ÔÚGCʱ-1
+ ++mWatchDog.mVMRef;
+#if LUAX_PROFILER
+ mRefVMs.insert(state.GetVM());
+#endif
+ }
+
+ ///
+ /// ³ÉÔ±ÒýÓùÜÀí
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx)
+ {
+ ClearLuaxMemberRef(state, memRef);
+ if (!lua_isnil(state, idx))
+ {
+ idx = state.AbsIndex(idx);
+ if (PushLuaxRefTable(state))
+ {
+ lua_pushvalue(state, idx);
+ memRef.refID = luaL_ref(state, -2);
+ state.Pop(); // ref table
+ }
+ }
+ }
+
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ {
+ if (memRef)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ lua_rawgeti(state, -1, memRef.refID);
+ lua_replace(state, -2); // ref table
+ if (lua_isnil(state, -1))
+ goto failed;
+ return true;
+ }
+ }
+ lua_pushnil(state);
+ failed:
+ memRef.refID = LUA_NOREF;
+ return false;
+ }
+
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberRef(LuaxState& state, int refID)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ lua_rawgeti(state, -1, refID);
+ lua_replace(state, -2); // ref table
+ if (lua_isnil(state, -1))
+ goto failed;
+ return true;
+ }
+ lua_pushnil(state);
+ failed:
+ return false;
+ }
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ {
+ if (memRef)
+ {
+ if (PushLuaxRefTable(state))
+ {
+ luaL_unref(state, -1, memRef.refID);
+ state.Pop(); // ref table
+ }
+ memRef.refID = LUA_NOREF;
+ }
+ }
+
+ //--------------------------------------------------------------------------------//
+
+ ///
+ /// Êͷʤ³§´´½¨µÄʵÀý
+ ///
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::__gc(lua_State* L)
+ {
+ LUAX_STATE(L);
+
+ TYPE* self = state.GetUserdata<TYPE>(1);
+ assert(self);
+
+#if LUAX_PROFILER
+ std::cout << "Luax: GC<" << TYPE::GetLuaxClassName() << ">\n";
+#endif
+
+ if(self->mWatchDog.mVMRef > 0)
+ --self->mWatchDog.mVMRef;
+
+ self->Release();
+
+ return 0;
+ }
+
+ ///
+ /// Êä³ö¸ñʽÈçÏÂ:
+ /// µØÖ· ÀàÃû
+ ///
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::__tostring(lua_State* L)
+ {
+ // params:
+ // 1: userdata
+
+ LUAX_STATE(L);
+ TYPE* self = state.GetUserdata<TYPE>(1);
+ if (self)
+ {
+ cc8* classname = "";
+ lua_getfield(state, 1, "GetClassName");
+ if (state.IsType(-1, LUA_TFUNCTION))
+ {
+ lua_pushvalue(L, 1); // userdata
+ state.Call(1, 1); // ÅÉÉúÀàµÄGetClassNameº¯Êý
+ classname = state.GetValue<cc8*>(-1, "");
+ }
+ else
+ {
+ classname = TYPE::GetLuaxClassName();
+ }
+ lua_pushfstring(L, "%s: %p", classname, self);
+ return 1;
+ }
+ return 0;
+ }
+
+#if LUAX_ENABLE_NATIVE_EXTEND
+ ///
+ /// ÅÉÉú³ö×ÓÀ࣬ÔÚluaÀï¶ÔÅÉÉúÀàµÄ³ÉÔ±ºÍÐÐΪ½øÐÐÖØÐÂÉè¼Æ£¬µ«ÊDZ£Ö¤ÁËuserdataµÄͳһ¡£Native classµÄÅÉÉúÌṩ__initÖ§³Ö£¬ÔÚ
+ /// nativeʵÌå´´½¨ºó¿ÉÒÔʹÓÃ__init½øÐгõʼ»¯£¬ÅÉÉúÀàÓµÓкͻùÀàÒ»ÑùµÄNew²ÎÊýÁÐ±í£¬ÇÒnative¶ÔÏóÊÇÒ»ÑùµÄÀàÐÍ¡£
+ ///
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_ExtendFactory(lua_State* L)
+ {
+ // upvalues:
+ // 1: base class
+
+ // params:
+ // 1: class name
+
+ int baseClass = lua_upvalueindex(1);
+
+ lua_newtable(L); // class table
+
+ int inheritClass = lua_gettop(L);
+
+ // .GetClassName()
+ cc8* type = lua_tostring(L, 1);
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClassName");
+
+ // .GetClass()
+ lua_pushvalue(L, inheritClass);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClass");
+
+ // .Extend()
+ lua_pushvalue(L, inheritClass);
+ lua_pushcclosure(L, _ExtendFactory, 1);
+ lua_setfield(L, -2, "Extend");
+
+ // .New()
+ lua_pushvalue(L, inheritClass);
+ lua_getfield(L, baseClass, "New");
+ lua_pushcclosure(L, _New, 2);
+ lua_setfield(L, -2, "New");
+
+ // __base = baseClass
+ lua_pushvalue(L, baseClass);
+ lua_setfield(L, -2, "__base");
+
+ // __index = inheritClass
+ lua_pushvalue(L, inheritClass);
+ lua_setfield(L, -2, "__index");
+
+ // metatable is baseClass
+ lua_pushvalue(L, baseClass);
+ lua_setmetatable(L, inheritClass);
+
+ return 1;
+ }
+
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_ExtendSingleton(lua_State* L)
+ {
+ // upvalues:
+ // 1: base class
+
+ // params:
+ // 1: class name
+
+ int baseClass = lua_upvalueindex(1);
+
+ lua_newtable(L); // class name
+
+ int inheritClass = lua_gettop(L);
+
+ // .GetClassName()
+ cc8* type = lua_tostring(L, 1);
+ lua_pushstring(L, type);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClassName");
+
+ // .GetClass()
+ lua_pushvalue(L, inheritClass);
+ lua_pushcclosure(L, luax_c_getupvalue, 1);
+ lua_setfield(L, -2, "GetClass");
+
+ // .Extend()
+ lua_pushvalue(L, inheritClass);
+ lua_pushcclosure(L, _ExtendFactory, 1);
+ lua_setfield(L, -2, "Extend");
+
+ // __base = baseClass
+ lua_pushvalue(L, baseClass);
+ lua_setfield(L, -2, "__base");
+
+ // __index = inheritClass
+ lua_pushvalue(L, inheritClass);
+ lua_setfield(L, -2, "__index");
+
+ // metatable is baseClass
+ lua_pushvalue(L, baseClass);
+ lua_setmetatable(L, inheritClass);
+
+ return 1;
+ }
+#endif /*LUAX_ENABLE_NATIVE_EXTEND*/
+
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetClass(lua_State* L)
+ {
+ LUAX_STATE(L);
+ if (!mClassTable)
+ lua_pushnil(L);
+ else
+ mClassTable.PushRef(state);
+ return 1;
+ }
+
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetRefTable(lua_State* L)
+ {
+ LUAX_STATE(L);
+ TYPE* self = state.GetUserdata<TYPE>(1);
+ bool success = self->PushLuaxRefTable(state);
+ if (!success)
+ lua_pushnil(L);
+ return 1;
+ }
+
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_New(lua_State* L)
+ {
+ LUAX_STATE(L);
+
+ // upvalues:
+ // 1: class table
+ // 2: original New()
+
+ // stack:
+ // -1~-n: args
+
+ int n = lua_gettop(L); // n args
+
+ lua_pushvalue(L, lua_upvalueindex(2));
+ if (state.IsType(-1, LUA_TFUNCTION))
+ {
+ // stack:
+ // -1: New
+ // -2~-1-n: args
+
+ state.PushValues(-1 - n, n);
+
+ // stack:
+ // -1~-n: args
+ // -n-1: New
+ // -n-2~-1-2n: args
+
+ state.Call(n, 1);
+
+ // stack:
+ // -1: userdata
+ // -2~-1-n: args
+
+ // reset member table's metatable to class table
+ if (state.IsType(-1, LUA_TUSERDATA))
+ {
+ if (lua_getmetatable(L, -1)) // ref table
+ {
+ if (lua_getmetatable(L, -1)) // member table
+ {
+ lua_pushvalue(L, lua_upvalueindex(1)); // class table
+ lua_setmetatable(L, -2);
+ state.Pop(); // member table
+ }
+ state.Pop(); // ref table
+ }
+
+ // stack:
+ // -1: userdata
+ // -2~-1-n: args
+
+ int args = state.AbsIndex(-1 - n);
+
+ // ³¢ÊÔµ÷ÓÃ__initº¯Êý
+ lua_getfield(L, lua_upvalueindex(1), "__init");
+
+ if (state.IsType(-1, LUA_TFUNCTION))
+ {
+ lua_pushvalue(L, -2); // userdata
+ state.PushValues(args, n);
+ state.Call(n + 1, 0);
+ }
+ else
+ state.Pop();
+
+ }
+
+ return 1;
+ }
+ return 0;
+ }
+
+ template<class TYPE, class BASE> LuaxStrongRef LuaxNativeClass<TYPE, BASE>::mClassTable; // class table
+ template<class TYPE, class BASE> LuaxStrongRef LuaxNativeClass<TYPE, BASE>::mSingletonRefTable; // µ¥Àý
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_config.h b/Runtime/Scripting/luax_config.h
new file mode 100644
index 0000000..31ea7df
--- /dev/null
+++ b/Runtime/Scripting/luax_config.h
@@ -0,0 +1,66 @@
+#ifndef __LUAX_TYPE_H__
+#define __LUAX_TYPE_H__
+
+#include <iostream>
+
+extern "C" {
+#include "lua51/lua.h"
+#include "lua51/lualib.h"
+#include "lua51/lauxlib.h"
+}
+
+#include <assert.h>
+
+namespace Luax
+{
+
+ typedef unsigned int uint;
+ typedef unsigned long uintptr;
+ typedef long sintptr;
+
+ typedef const char cc8;
+
+ typedef unsigned char u8;
+ typedef unsigned short u16;
+ typedef unsigned int u32;
+ typedef unsigned long long u64;
+
+ typedef signed char s8;
+ typedef signed short s16;
+ typedef signed int s32;
+ typedef signed long long s64;
+
+#ifdef _WIN32
+ #define LUAX_FINAL final
+ #define LUAX_LIBRARY_EXPORT __declspec(dllexport)
+ #define LUAX_LIBRARY_IMPORT __declspec(dllimport)
+ #define LUAX_FORCE_INLINE __forceinline
+ #define LUAX_RESTRICT __restrict
+ #define LUAX_ATTRIBUTE_USED
+ #define LUAX_ABSTRACT
+ #define LUAX_API LUAX_LIBRARY_EXPORT
+#else
+ #define LUAX_FINAL final
+ #define LUAX_LIBRARY_EXPORT __attribute__((visibility("default")))
+ #define LUAX_LIBRARY_IMPORT
+ #define LUAX_FORCE_INLINE __attribute__((always_inline)) inline
+ #define LUAX_RESTRICT __restrict__
+ #define LUAX_ATTRIBUTE_USED __attribute__((used))
+ #define LUAX_ABSTRACT
+ #define LUAX_API LUAX_LIBRARY_EXPORT
+#endif
+
+#define LUAX_ENABLE_NATIVE_EXTEND 0
+
+#define LUAX_ENABLE_PLAIN_CLASS 0
+#define LUAX_ENABLE_PLAIN_ENUM 0
+
+#define LUAX_PROFILER 1
+
+}
+
+#if LUAX_PROFILER
+#include <iostream>
+#endif
+
+#endif // __LUAX_TYPE_H__ \ No newline at end of file
diff --git a/Runtime/Scripting/luax_enum.cpp b/Runtime/Scripting/luax_enum.cpp
new file mode 100644
index 0000000..ec73fce
--- /dev/null
+++ b/Runtime/Scripting/luax_enum.cpp
@@ -0,0 +1,67 @@
+#include "luax_enum.h"
+#include "luax_state.h"
+#include "luax_vm.h"
+
+namespace Luax
+{
+
+ ///
+ /// Ö»¶ÁmetatableµÄ__index
+ ///
+ int _rmt__index(lua_State* L)
+ {
+ // params:
+ // 1: enum table
+ // 2: key
+
+ // upvalues:
+ // 1: metatable
+
+ int mt = lua_upvalueindex(1);
+ lua_pushvalue(L, 2);
+ lua_rawget(L, mt);
+
+ return 1;
+ }
+
+ int _rmt__newindex(lua_State* L)
+ {
+ // upvalue:
+ // 1: enum table name
+
+ cc8* name = lua_tostring(L, lua_upvalueindex(1));
+
+ return luaL_error(L, "Enum called \"%s\" is readonly.", name);
+ }
+
+ //--------------------------------------------------------------------------------//
+#if LUAX_ENABLE_PLAIN_ENUM
+ int LuaxPlainEnum::registry(lua_State* L)
+ {
+ // params:
+ // 1: enum name
+ // 2: metatable
+
+ cc8* name = luaL_checkstring(L, 1);
+
+ if (!lua_istable(L, 2))
+ {
+ return luaL_error(L, "Create plain enum failed. Require table, but get %s", luaL_typename(L, 2));
+ }
+
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "__index");
+
+ lua_pushstring(L, name);
+ lua_pushcclosure(L, _rmt__newindex, 1);
+ lua_setfield(L, -2, "__newindex");
+
+ lua_newtable(L); // enum table
+
+ lua_pushvalue(L, -2); // metatable
+ lua_setmetatable(L, -2);
+
+ return 1;
+ }
+#endif
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_enum.h b/Runtime/Scripting/luax_enum.h
new file mode 100644
index 0000000..9afece2
--- /dev/null
+++ b/Runtime/Scripting/luax_enum.h
@@ -0,0 +1,39 @@
+#ifndef __LUAX_ENUM_H__
+#define __LUAX_ENUM_H__
+
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ ///
+ /// µ¼³öö¾Ù£¬Ã¶¾ÙÊÇÒ»À಻¿ÉÐÞ¸ÄÕûÐͼ¯ºÏ£¬Ã¶¾ÙµÄÖµÔÚ
+ ///
+ struct LuaxEnum
+ {
+ cc8* name;
+ int value;
+ };
+
+ extern int _rmt__index(lua_State* L);
+
+ extern int _rmt__newindex(lua_State* L);
+
+ //--------------------------------------------------------------------------------//
+
+#if LUAX_ENABLE_PLAIN_ENUM
+ ///
+ /// ´¿luaµÄö¾Ù£¬´´½¨²»¿ÉÐ޸ĵÄtable
+ ///
+ class LuaxPlainEnum
+ {
+ public:
+
+ static int registry(lua_State* L);
+
+ };
+#endif
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_globalstate.h b/Runtime/Scripting/luax_globalstate.h
new file mode 100644
index 0000000..91be51f
--- /dev/null
+++ b/Runtime/Scripting/luax_globalstate.h
@@ -0,0 +1,7 @@
+#ifndef __LUAX_GLOBAL_STATE_H__
+#define __LUAX_GLOBAL_STATE_H__
+
+// Ë÷Òýµ½luaÀïµÄglobal_State
+typedef struct global_State global_State;
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_internal.h b/Runtime/Scripting/luax_internal.h
new file mode 100644
index 0000000..5904008
--- /dev/null
+++ b/Runtime/Scripting/luax_internal.h
@@ -0,0 +1,12 @@
+#ifndef __LUAX_INTERNAL_H__
+#define __LUAX_INTERNAL_H__
+
+///
+/// ¶ÔluaÔ´´úÂëµÄÉî¶ÈʹÓÃ
+///
+extern "C"
+{
+#include "lua51/lstate.h"
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_memberref.cpp b/Runtime/Scripting/luax_memberref.cpp
new file mode 100644
index 0000000..a8a09ba
--- /dev/null
+++ b/Runtime/Scripting/luax_memberref.cpp
@@ -0,0 +1,16 @@
+#include "luax_memberref.h"
+
+namespace Luax
+{
+
+ LuaxMemberRef::LuaxMemberRef()
+ : refID(LUA_NOREF)
+ {
+ }
+
+ LuaxMemberRef::~LuaxMemberRef()
+ {
+
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_memberref.h b/Runtime/Scripting/luax_memberref.h
new file mode 100644
index 0000000..cda7946
--- /dev/null
+++ b/Runtime/Scripting/luax_memberref.h
@@ -0,0 +1,27 @@
+#ifndef __LUAX_MEMBER_REF_H__
+#define __LUAX_MEMBER_REF_H__
+
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ ///
+ /// ʵÀýµÄref table±£´æµÄmember ref¡£ÓÉluax class×ö¾ßÌåµÄ¹ÜÀí¡£ÊµÀýµÄref tableÊÇÇ¿ÒýÓã¬ÓÃÀ´¹ÜÀíÀïÃæmemberµÄÉúÃüÖÜÆÚ¡£
+ /// ÓÃÀ´ÔÚluaºÍnativeÖ®¼ä½øÐÐÊý¾Ý¹µÍ¨¡£
+ ///
+ class LuaxMemberRef
+ {
+ public:
+ LuaxMemberRef();
+ ~LuaxMemberRef();
+
+ inline operator bool() { return refID != LUA_NOREF; };
+
+ int refID;
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_ref.cpp b/Runtime/Scripting/luax_ref.cpp
new file mode 100644
index 0000000..d4be775
--- /dev/null
+++ b/Runtime/Scripting/luax_ref.cpp
@@ -0,0 +1,72 @@
+#include "luax_vm.h"
+#include "luax_ref.h"
+
+namespace Luax
+{
+
+ LuaxRef::LuaxRef(int mode)
+ : mRefID(LUA_NOREF)
+ , mMode(mode)
+ {
+ }
+
+ LuaxRef::~LuaxRef()
+ {
+ }
+
+ LuaxRef::operator bool()
+ {
+ return (mRefID != LUA_NOREF);
+ }
+
+ bool LuaxRef::PushRef(LuaxState& state)
+ {
+ assert(mRefID != LUA_NOREF);
+
+ LuaxVM* vm = state.GetVM();
+ if (!vm) return false;
+ if (mMode == STRONG_REF)
+ {
+ LuaxRefTable& table = vm->GetStrongRefTable();
+ table.PushRef(state, mRefID);
+ }
+ else if (mMode == WEAK_REF)
+ {
+ LuaxRefTable& table = vm->GetWeakRefTable();
+ table.PushRef(state, mRefID);
+ }
+ else
+ {
+ state.PushNil();
+ return false;
+ }
+ return true;
+ }
+
+ void LuaxRef::SetRef(LuaxState& state, int idx)
+ {
+ LuaxVM* vm = state.GetVM();
+ if (!vm) return;
+ if (mMode == STRONG_REF)
+ {
+ LuaxRefTable& table = vm->GetStrongRefTable();
+ mRefID = table.Ref(state, idx);
+ }
+ else if (mMode == WEAK_REF)
+ {
+ LuaxRefTable& table = vm->GetWeakRefTable();
+ mRefID = table.Ref(state, idx);
+ }
+ }
+
+ LuaxStrongRef::LuaxStrongRef()
+ : LuaxRef(STRONG_REF)
+ {
+ }
+
+ LuaxWeakRef::LuaxWeakRef()
+ : LuaxRef(WEAK_REF)
+ {
+ }
+
+}
diff --git a/Runtime/Scripting/luax_ref.h b/Runtime/Scripting/luax_ref.h
new file mode 100644
index 0000000..d0001f2
--- /dev/null
+++ b/Runtime/Scripting/luax_ref.h
@@ -0,0 +1,62 @@
+#ifndef __LUAX_REF_H__
+#define __LUAX_REF_H__
+
+#include "luax_config.h"
+#include "luax_state.h"
+
+namespace Luax
+{
+
+ ///
+ /// ÒýÓ㬴æÔÚLUA_REGISTRYINDEXÏÂÃæµÄÁ½¸ö±íÀï
+ ///
+ class LuaxRef
+ {
+ public:
+
+ enum RefMode
+ {
+ STRONG_REF,
+ WEAK_REF
+ };
+
+ LuaxRef(int mode = STRONG_REF);
+ virtual ~LuaxRef();
+
+ operator bool();
+
+ void SetRef(LuaxState& state, int idx);
+ bool PushRef(LuaxState& state);
+
+ int GetRefID();
+
+ private:
+
+ int mRefID; // luaL_ref
+ int mMode; // strong or weak
+
+ };
+
+ ///
+ /// Ç¿ÒýÓã¬ÔÚLUA_REGISTRYINDEX["_LUAX_STRONGREF_TABLE"]À±£Ö¤lua object²»»á±»»ØÊÕ¡£
+ ///
+ class LuaxStrongRef: public LuaxRef
+ {
+ public:
+ LuaxStrongRef();
+
+ };
+
+ ///
+ /// ÈõÒýÓã¬ÔÚLUA_REGISTRYINDEX["_LUAX_WEAKREF_TABLE"]À²»Ó°Ïìlua objectµÄ»ØÊÕ£¬Ö»ÊÇ×÷Ϊһ¸ö·½±ãÈ¡lua objectµÄÓ³Éä¡£
+ ///
+ class LuaxWeakRef : public LuaxRef
+ {
+ public:
+ LuaxWeakRef();
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_reftable.cpp b/Runtime/Scripting/luax_reftable.cpp
new file mode 100644
index 0000000..461e2d9
--- /dev/null
+++ b/Runtime/Scripting/luax_reftable.cpp
@@ -0,0 +1,120 @@
+#include "luax_reftable.h"
+#include "luax_state.h"
+
+namespace Luax
+{
+
+ LuaxRefTable::LuaxRefTable()
+ : mState(nullptr)
+ {
+ }
+
+ LuaxRefTable::~LuaxRefTable()
+ {
+ }
+
+ void LuaxRefTable::Init(LuaxState& state, cc8* name, cc8* mode)
+ {
+ assert(!mState);
+ assert(name);
+
+ mName = name;
+ mMode = 0;
+ for (int i = 0; mode && mode[i]; ++i)
+ {
+ if (mode[i] == 'k') mMode |= WEAK_KEY;
+ else if (mode[i] == 'v') mMode |= WEAK_VALUE;
+ }
+ mState = state.GetHandle();
+
+ state.GetField(LUA_REGISTRYINDEX, name); // register[mName]
+ if (state.IsNil(-1))
+ {
+ state.Pop();
+
+ lua_newtable(state); // ref table
+ int ridx = state.AbsIndex(-1);
+ lua_newtable(state); // metatable of ref table
+ int idx = state.AbsIndex(-1);
+
+ // __mode
+ if (mode)
+ {
+ state.Push(mode);
+ state.SetField(idx, "__mode");
+ }
+
+ state.Settop(idx);
+ lua_setmetatable(state, ridx);
+
+ state.Settop(ridx);
+ state.SetField(LUA_REGISTRYINDEX, name);
+ }
+ else
+ {
+ state.Pop();
+ }
+ }
+
+ bool LuaxRefTable::IsKeyWeak()
+ {
+ assert(mState);
+
+ return mMode & WEAK_KEY;
+ }
+
+ bool LuaxRefTable::IsValueWeak()
+ {
+ assert(mState);
+
+ return mMode & WEAK_VALUE;
+ }
+
+ int LuaxRefTable::Ref(LuaxState& state, int idx)
+ {
+ assert(mState);
+
+ idx = state.AbsIndex(idx);
+ state.GetField(LUA_REGISTRYINDEX, mName); // ref table
+ lua_pushvalue(state, idx); // stuff
+ int refID = luaL_ref(state, -2);
+ assert(refID != LUA_NOREF);
+ state.Pop();
+ return refID;
+ }
+
+ void LuaxRefTable::Unref(LuaxState& state, int refID)
+ {
+ assert(mState);
+
+ state.GetField(LUA_REGISTRYINDEX, mName); // ref table
+ luaL_unref(state, -1, refID);
+ state.Pop();
+ return;
+ }
+
+ void LuaxRefTable::PushRefTable(LuaxState& state)
+ {
+ assert(mState);
+
+ lua_getfield(state, LUA_REGISTRYINDEX, mName);
+ }
+
+ void LuaxRefTable::PushRef(LuaxState& state, int refID)
+ {
+ assert(mState);
+
+ lua_getfield(state, LUA_REGISTRYINDEX, mName);
+ lua_rawgeti(state, -1, refID);
+ lua_replace(state, -2);
+ }
+
+ void LuaxRefTable::Clear(LuaxState& state)
+ {
+ assert(mState);
+
+ lua_newtable(state);
+ state.SetField(LUA_REGISTRYINDEX, mName);
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_reftable.h b/Runtime/Scripting/luax_reftable.h
new file mode 100644
index 0000000..58e4b9c
--- /dev/null
+++ b/Runtime/Scripting/luax_reftable.h
@@ -0,0 +1,67 @@
+#ifndef __LUAX_REFTABLE_H__
+#define __LUAX_REFTABLE_H__
+
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ class LuaxState;
+
+ ///
+ /// ref table ¹ÜÀí£¬¶Ôstrong ref tableºÍweak ref tableÁ½¸ötableµÄ´úÀí¡£
+ ///
+ class LuaxRefTable
+ {
+ public:
+
+ enum
+ {
+ WEAK_KEY = 1,
+ WEAK_VALUE = 1 << 1
+ };
+
+ LuaxRefTable();
+ ~LuaxRefTable();
+
+ inline operator bool() { return mState; };
+
+ void Init(LuaxState& state, cc8* name, cc8* mode = nullptr);
+
+ bool IsKeyWeak();
+ bool IsValueWeak();
+
+ ///
+ /// ¶Ôstack[idx]µÄʵÌåÔÚ´Ëref tableÖÐÔö¼ÓÒ»¸öÒýÓ㬲¢·µ»ØrefID
+ ///
+ int Ref(LuaxState& state, int idx);
+ void Unref(LuaxState& state, int refID);
+
+ ///
+ /// ½«´Ë ref table ·ÅÔÚÕ»¶¥
+ ///
+ void PushRefTable(LuaxState& state);
+
+ ///
+ /// ½« reftable[refID] ·ÅÔÚÕ»¶¥
+ ///
+ void PushRef(LuaxState& state, int refID);
+
+ ///
+ /// Çå¿Õ ref table£¬±í»¹ÁôÔÚLUA_REGISTRYINDEX[mName]
+ ///
+ void Clear(LuaxState& state);
+
+ private:
+
+ friend class LuaxState;
+
+ lua_State* mState; // ÓÃÀ´×öһЩȷÈϹ¤×÷
+ cc8* mName; // ref tableµÄÃû³Æ
+ int mMode; // ref tableµÄÀàÐÍ
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_state.cpp b/Runtime/Scripting/luax_state.cpp
new file mode 100644
index 0000000..a2610b4
--- /dev/null
+++ b/Runtime/Scripting/luax_state.cpp
@@ -0,0 +1,857 @@
+#include "luax_enum.h"
+#include "luax_state.h"
+#include "luax_vm.h"
+#include "luax_class.hpp"
+#include "luax_internal.h"
+
+namespace Luax
+{
+
+ LuaxState::LuaxState(lua_State* state)
+ : mState(state)
+ {
+ assert(state);
+ }
+
+ LuaxState::LuaxState(const LuaxState& state)
+ : mState(state.mState)
+ {
+ assert(state.mState);
+ }
+
+ LuaxState::~LuaxState()
+ {
+ }
+
+ void LuaxState::OpenLibs()
+ {
+ luaL_openlibs(mState);
+ }
+
+ global_State* LuaxState::GetGlobalState()
+ {
+ return G(mState);
+ }
+
+ LuaxVM* LuaxState::GetVM()
+ {
+ return LuaxVM::TryGetVM(G(mState));
+ }
+
+ void LuaxState::PushGlobalNamespace()
+ {
+ int top = GetTop();
+
+ lua_newtable(mState); // pseudo namespace table
+ int pnt = GetTop();
+
+ lua_newtable(mState); // metatable
+ int mt = GetTop();
+
+ // __index = _G
+ // __newindex = _G
+ lua_pushvalue(mState, LUA_GLOBALSINDEX);
+ lua_pushvalue(mState, LUA_GLOBALSINDEX);
+ lua_setfield(mState, mt, "__index");
+ lua_setfield(mState, mt, "__newindex");
+
+ lua_setmetatable(mState, pnt);
+
+ // stack:
+ // -1 pseudo global namespace
+ }
+
+ void LuaxState::PushNamespace(cc8* name)
+ {
+ assert(IsNamespace(-1));
+
+ int top = GetTop();
+
+ lua_getfield(mState, -1, name);
+ if (lua_isnil(mState, -1))
+ {
+ lua_pop(mState, 1);
+
+ lua_newtable(mState);
+ lua_pushvalue(mState, -1);
+ lua_setfield(mState, top, name);
+ }
+
+ // stack:
+ // -1 namespace
+ }
+
+ void LuaxState::PopNamespace()
+ {
+ assert(lua_istable(mState, -1));
+ lua_pop(mState, 1);
+ }
+
+ bool LuaxState::IsNamespace(int idx)
+ {
+ return lua_istable(mState, idx);
+ }
+
+ void LuaxState::DoString(const std::string& code)
+ {
+ luaL_dostring(mState, code.c_str());
+ }
+
+ int LuaxState::AbsIndex(int idx)
+ {
+/*
+#define abs_index(mState, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
+ lua_gettop(mState) + (i) + 1)
+*/
+ if (idx < 0) {
+ //return lua_gettop(mState) + idx + 1;
+ return ((idx) > 0 || (idx) <= LUA_REGISTRYINDEX ? (idx) : \
+ lua_gettop(mState) + (idx)+1);
+ }
+ return idx;
+ }
+
+ void LuaxState::Call(int nArgs, int nResults)
+ {
+ lua_pcall(mState, nArgs, nResults, 0);
+ }
+
+ void LuaxState::PushNil()
+ {
+ lua_pushnil(mState);
+ }
+
+ void LuaxState::Push(bool value)
+ {
+ lua_pushboolean(mState, value ? 1 : 0);
+ }
+
+ void LuaxState::Push(cc8* value)
+ {
+ lua_pushstring(mState, value);
+ }
+
+ void LuaxState::Push(double value)
+ {
+ lua_pushnumber(mState, value);
+ }
+
+ void LuaxState::Push(float value)
+ {
+ lua_pushnumber(mState, value);
+ }
+
+ void LuaxState::Push(int value)
+ {
+ lua_pushnumber(mState, value);
+ }
+
+ void LuaxState::Push(u16 value)
+ {
+ lua_pushnumber(mState, value);
+ }
+
+ void LuaxState::Push(u32 value)
+ {
+ lua_pushnumber(mState, value);
+ }
+
+ void LuaxState::Push(u64 value)
+ {
+ lua_pushnumber(mState, (double)value);
+ }
+
+ void LuaxState::Push(s64 value)
+ {
+ lua_pushinteger(mState, value);
+ }
+
+ void LuaxState::Push(uintptr value)
+ {
+ lua_pushlightuserdata(mState, (void*)value);
+ }
+
+ void LuaxState::Push(lua_CFunction value)
+ {
+ lua_pushcfunction(mState, value);
+ }
+
+ void LuaxState::Push(void* data, size_t size)
+ {
+ lua_pushlstring(mState, (cc8*)data, size);
+ }
+
+ void LuaxState::Push(const void* value)
+ {
+ lua_pushlightuserdata(mState, (void*)value);
+ }
+
+ void LuaxState::Push(std::string value)
+ {
+ Push(value.c_str());
+ }
+
+ void LuaxState::PushValues(int idx, int n)
+ {
+ idx = AbsIndex(idx);
+ for (int i = idx; i < idx + n; ++i)
+ lua_pushvalue(mState, i);
+ }
+
+ void LuaxState::Pop(int n /* = 1 */)
+ {
+ lua_pop(mState, n);
+ }
+
+ bool LuaxState::IsNil(int idx)
+ {
+ return lua_isnil(mState, idx);
+ }
+
+ bool LuaxState::IsNilOrNone(int idx)
+ {
+ int t = lua_type(mState, idx);
+ return ((t == LUA_TNONE) || (t == LUA_TNIL));
+ }
+
+ bool LuaxState::IsTableOrUserdata(int idx)
+ {
+ int check = lua_type(mState, idx);
+ return ((check == LUA_TTABLE) || (check == LUA_TUSERDATA));
+ }
+
+ bool LuaxState::IsTrueOrNotNil(int idx)
+ {
+ if (lua_isboolean(mState, idx)) {
+ return lua_toboolean(mState, idx) ? true : false;
+ }
+ return !lua_isnil(mState, idx);
+ }
+
+ bool LuaxState::IsType(int idx, int type)
+ {
+ return (lua_type(mState, idx) == type);
+ }
+
+ bool LuaxState::IsType(int idx, cc8* name, int type)
+ {
+ return this->HasField(idx, name, type);
+ }
+
+ bool LuaxState::IsValid()
+ {
+ return (mState != 0);
+ }
+
+ void LuaxState::Settop(int idx)
+ {
+ lua_settop(mState, idx);
+ }
+
+ int LuaxState::GetTop()
+ {
+ return lua_gettop(mState);
+ }
+
+ bool LuaxState::HasField(int idx, cc8* name) {
+
+ lua_getfield(mState, idx, name);
+ bool hasField = (lua_isnil(mState, -1) == false);
+ lua_pop(mState, 1);
+
+ return hasField;
+ }
+
+ bool LuaxState::HasField(int idx, int key) {
+
+ this->GetField(idx, key);
+ bool hasField = (lua_isnil(mState, -1) == false);
+ lua_pop(mState, 1);
+
+ return hasField;
+ }
+
+ bool LuaxState::HasField(int idx, cc8* name, int type) {
+
+ lua_getfield(mState, idx, name);
+ bool hasField = (lua_type(mState, -1) == type);
+ lua_pop(mState, 1);
+
+ return hasField;
+ }
+
+ bool LuaxState::HasField(int idx, int key, int type) {
+
+ this->GetField(idx, key);
+ bool hasField = (lua_type(mState, -1) == type);
+ lua_pop(mState, 1);
+
+ return hasField;
+ }
+
+ bool LuaxState::HasKeys(int idx) {
+
+ idx = this->AbsIndex(idx);
+
+ lua_pushnil(mState); /* first key */
+ if (lua_next(mState, idx) != 0) {
+ lua_pop(mState, 2);
+ return true;
+ }
+ return false;
+ }
+
+ void LuaxState::GetField(int idx, cc8* name)
+ {
+ lua_getfield(mState, idx, name);
+ }
+
+ void LuaxState::GetField(int idx, int key)
+ {
+ idx = this->AbsIndex(idx);
+
+ lua_pushinteger(mState, key);
+ lua_gettable(mState, idx);
+ }
+
+ std::string LuaxState::GetField(int idx, cc8* key, cc8* default_value)
+ {
+ std::string str;
+ if (this->GetFieldWithType(idx, key, LUA_TSTRING)) {
+ str = lua_tostring(mState, -1);
+ lua_pop(mState, 1);
+ }
+ else {
+ str = default_value;
+ }
+ return str;
+ }
+
+ std::string LuaxState::GetField(int idx, int key, cc8* default_value)
+ {
+ std::string str;
+ if (this->GetFieldWithType(idx, key, LUA_TSTRING)) {
+ str = lua_tostring(mState, -1);
+ lua_pop(mState, 1);
+ }
+ else {
+ str = default_value;
+ }
+ return str;
+ }
+
+ std::string LuaxState::GetField(int idx, cc8* key, const std::string& value)
+ {
+ std::string str;
+ if (this->GetFieldWithType(idx, key, LUA_TSTRING)) {
+ str = lua_tostring(mState, -1);
+ lua_pop(mState, 1);
+ }
+ else {
+ str = value;
+ }
+ return str;
+ }
+
+ std::string LuaxState::GetField(int idx, int key, const std::string& value)
+ {
+ std::string str;
+ if (this->GetFieldWithType(idx, key, LUA_TSTRING)) {
+ str = lua_tostring(mState, -1);
+ lua_pop(mState, 1);
+ }
+ else {
+ str = value;
+ }
+ return str;
+ }
+
+ bool LuaxState::GetFieldWithType(int idx, cc8* name, int type)
+ {
+ lua_getfield(mState, idx, name);
+ if (lua_type(mState, -1) != type) {
+ lua_pop(mState, 1);
+ return false;
+ }
+ return true;
+ }
+
+ bool LuaxState::GetFieldWithType(int idx, int key, int type)
+ {
+ this->GetField(idx, key);
+ if (lua_type(mState, -1) != type) {
+ lua_pop(mState, 1);
+ return false;
+ }
+ return true;
+ }
+
+ void LuaxState::SetField(int idx, cc8* key)
+ {
+ if (IsTableOrUserdata(idx))
+ {
+ idx = AbsIndex(idx);
+ lua_setfield(mState, idx, key);
+ }
+ }
+
+ cc8* LuaxState::GetLuaTypeName(int type)
+ {
+ switch (type) {
+ case LUA_TNONE: return "none";
+ case LUA_TNIL: return "nil";
+ case LUA_TBOOLEAN: return "boolean";
+ case LUA_TLIGHTUSERDATA: return "lightuserdata";
+ case LUA_TNUMBER: return "number";
+ case LUA_TSTRING: return "string";
+ case LUA_TTABLE: return "table";
+ case LUA_TFUNCTION: return "function";
+ case LUA_TUSERDATA: return "userdata";
+ case LUA_TTHREAD: return "thread";
+ }
+ return "unknown";
+ }
+
+
+ bool LuaxState::GetSubfieldWithType(int idx, cc8* format, int type, ...)
+ {
+ va_list args;
+ va_start(args, type);
+
+ idx = this->AbsIndex(idx);
+ lua_pushvalue(this->mState, idx);
+
+ for (cc8* c = format; *c; ++c) {
+ switch (*c) {
+ // number
+ case 'N':
+ lua_pushnumber(this->mState, va_arg(args, int));
+ lua_gettable(this->mState, -1);
+ break;
+
+ // string
+ case 'S':
+ lua_getfield(this->mState, -1, va_arg(args, char*));
+ break;
+
+ default:
+ lua_pushnil(this->mState);
+ }
+
+ if (lua_isnil(this->mState, -1)) break;
+ lua_replace(this->mState, -2);
+ }
+ va_end(args);
+ if (lua_type(this->mState, -1) != type) {
+ lua_pop(this->mState, 1);
+ return false;
+ }
+ return true;
+ }
+
+ bool LuaxState::CheckParams(int idx, cc8* format)
+ {
+ idx = AbsIndex(idx);
+
+ for (int i = 0; format[i]; ++i) {
+
+ int pos = idx + i;
+ int type = LUA_TNIL;
+ int expected = LUA_TNONE;
+
+ if (pos <= GetTop()) {
+ type = lua_type(mState, pos);
+ }
+
+ switch (format[i]) {
+
+ // boolean
+ case 'B':
+ if (type != LUA_TBOOLEAN) expected = LUA_TBOOLEAN;
+ break;
+
+ // coroutine
+ case 'C':
+ if (type != LUA_TTHREAD) expected = LUA_TTHREAD;
+ break;
+
+ // function
+ case 'F':
+ if (type != LUA_TFUNCTION) expected = LUA_TFUNCTION;
+ break;
+
+ // light userdata
+ case 'L':
+ if (type != LUA_TLIGHTUSERDATA) expected = LUA_TLIGHTUSERDATA;
+ break;
+
+ // number
+ case 'N':
+ if (type != LUA_TNUMBER) expected = LUA_TNUMBER;
+ break;
+
+ // string
+ case 'S':
+ if (type != LUA_TSTRING) expected = LUA_TSTRING;
+ break;
+
+ // table
+ case 'T':
+ if (type != LUA_TTABLE) expected = LUA_TTABLE;
+ break;
+
+ // userdata
+ case 'U':
+ if (type != LUA_TUSERDATA) expected = LUA_TUSERDATA;
+ break;
+
+ // any type
+ case '*':
+ case '.':
+ break;
+ }
+
+ if (expected != LUA_TNONE) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ template <>
+ bool LuaxState::GetValue < bool >(int idx, const bool value) {
+
+ if (this->IsType(idx, LUA_TBOOLEAN)) {
+ return (lua_toboolean(this->mState, idx) != 0);
+ }
+ return value;
+ }
+
+
+ template <>
+ cc8* LuaxState::GetValue < cc8* >(int idx, const cc8* value) {
+
+ if (this->IsType(idx, LUA_TSTRING)) {
+ return lua_tostring(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ std::string LuaxState::GetValue<std::string>(int idx, const std::string value)
+ {
+ std::string str;
+ if (lua_type(this->mState, idx) == LUA_TSTRING) {
+ str = lua_tostring(this->mState, idx);
+ }
+ else {
+ str = value;
+ }
+ return str;
+ }
+
+ template <>
+ double LuaxState::GetValue < double >(int idx, const double value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ float LuaxState::GetValue < float >(int idx, const float value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (float)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ s8 LuaxState::GetValue < s8 >(int idx, const s8 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (s8)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+
+ template <>
+ s16 LuaxState::GetValue < s16 >(int idx, const s16 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (s16)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+
+ template <>
+ s32 LuaxState::GetValue < s32 >(int idx, const s32 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (s32)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ s64 LuaxState::GetValue < s64 >(int idx, const s64 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (s64)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ u8 LuaxState::GetValue < u8 >(int idx, const u8 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (u8)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ u16 LuaxState::GetValue < u16 >(int idx, const u16 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (u16)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ u32 LuaxState::GetValue < u32 >(int idx, const u32 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (u32)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ u64 LuaxState::GetValue < u64 >(int idx, const u64 value)
+ {
+ if (this->IsType(idx, LUA_TNUMBER)) {
+ return (u64)lua_tonumber(this->mState, idx);
+ }
+ return value;
+ }
+
+ template <>
+ const void* LuaxState::GetValue < const void* >(int idx, const void* value)
+ {
+ if (this->IsType(idx, LUA_TLIGHTUSERDATA)) {
+ return (void*)lua_touserdata(this->mState, idx);
+ }
+ return value;
+ }
+
+ void LuaxState::PushPtrUserdata(void* ptr)
+ {
+ void** handle = (void**)lua_newuserdata(this->mState, sizeof(void*));
+ assert(handle);
+ (*handle) = ptr;
+ }
+
+ void LuaxState::RegisterEnum(cc8* name, LuaxEnum* en)
+ {
+ assert(name);
+ assert(en);
+
+ // short name
+ lua_State* L = mState;
+
+ int top = GetTop();
+
+ lua_newtable(L); // enum table
+
+ int et = GetTop();
+
+ lua_newtable(L); // matatable
+
+ // ËùÓÐö¾Ù¶¼´æÔÚmetatableÏ£¬ÐÞ¸Äʱ´¥·¢__newindex±¨´í
+ for (; en->name; ++en)
+ {
+ lua_pushinteger(L, en->value);
+ lua_setfield(L, -2, en->name);
+ }
+
+ // __index
+ //lua_pushvalue(L, -1); // metatable
+ //lua_pushcclosure(L, _rmt__index, 1);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "__index");
+
+ // __newinedx
+ lua_pushstring(L, name); // enum name
+ lua_pushcclosure(L, _rmt__newindex, 1);
+ lua_setfield(L, -2, "__newindex");
+
+ lua_setmetatable(L, et);
+
+ lua_setfield(L, top, name);
+ }
+
+
+ void LuaxState::RegisterMethods(const luaL_Reg *l)
+ {
+ assert(lua_istable(mState, -1));
+ // luaL_registerµÚ¶þ¸ö²ÎÊýΪ¿Õ£¬ÔòÏò-1λÖÃ×¢²áluaL_RegÖÐÕâЩº¯Êý
+ luaL_register(mState, 0, l);
+ }
+
+ void LuaxState::RegisterMethod(cc8* fname, lua_CFunction func)
+ {
+ assert(lua_istable(mState, -1));
+ lua_pushcfunction(mState, func);
+ lua_setfield(mState, -1, fname);
+ }
+
+ void LuaxState::RegisterPreloader(cc8* libname, lua_CFunction preloader)
+ {
+ lua_getglobal(mState, "package");
+ lua_getfield(mState, -1, "preload");
+ lua_pushcfunction(mState, preloader);
+ lua_setfield(mState, -2, libname);
+ lua_pop(mState, 2);
+ }
+
+ void LuaxState::RegisterLib(cc8* libname, const luaL_Reg* l)
+ {
+ luaL_register(mState, libname, l);
+ }
+
+#if LUAX_ENABLE_PLAIN_CLASS
+ void LuaxState::RegisterPlainClassRegistry(cc8* name)
+ {
+ assert(lua_istable(mState, -1));
+ lua_pushcfunction(mState, LuaxPlainClass::registry);
+ lua_setfield(mState, -2, name);
+ }
+#endif
+
+#if LUAX_ENABLE_PLAIN_ENUM
+ void LuaxState::RegisterPlainEnumRegistry(cc8* name)
+ {
+ assert(lua_istable(mState, -1));
+ lua_pushcfunction(mState, LuaxPlainEnum::registry);
+ lua_setfield(mState, -2, name);
+ }
+#endif
+
+ int LuaxState::ErrorType(int idx, cc8* hint)
+ {
+ return luaL_typerror(mState, idx, hint);
+ }
+
+ template <>
+ bool LuaxState::CheckValue < bool >(int idx)
+ {
+ bool b = false;
+ if (lua_type(mState, idx) == LUA_TBOOLEAN)
+ {
+ b = lua_toboolean(mState, idx);
+ }
+ else
+ {
+ luaL_typerror(mState, idx, lua_typename(mState, LUA_TBOOLEAN));
+ }
+ return b;
+ }
+
+ template <>
+ cc8* LuaxState::CheckValue < cc8* >(int idx)
+ {
+ return luaL_checkstring(mState, idx);
+ }
+
+ template <>
+ double LuaxState::CheckValue < double >(int idx)
+ {
+ return luaL_checknumber(mState, idx);
+ }
+
+ template <>
+ float LuaxState::CheckValue < float >(int idx)
+ {
+ return luaL_checknumber(mState, idx);
+ }
+
+ template <>
+ s8 LuaxState::CheckValue < s8 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ s16 LuaxState::CheckValue < s16 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ s32 LuaxState::CheckValue < s32 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ s64 LuaxState::CheckValue < s64 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ u8 LuaxState::CheckValue < u8 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ u16 LuaxState::CheckValue < u16 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ u32 LuaxState::CheckValue < u32 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ u64 LuaxState::CheckValue < u64 >(int idx)
+ {
+ return luaL_checkinteger(mState, idx);
+ }
+
+ template <>
+ std::string LuaxState::CheckValue < std::string >(int idx)
+ {
+ return luaL_checkstring(mState, idx);
+ }
+
+ ///
+ /// check light userdata
+ ///
+ template <>
+ const void* LuaxState::CheckValue < const void* >(int idx)
+ {
+ if (IsType(idx, LUA_TLIGHTUSERDATA))
+ {
+ return GetValue<const void*>(idx, nullptr);
+ }
+ else
+ {
+ luaL_typerror(mState, idx, "light userdata");
+ return nullptr;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_state.h b/Runtime/Scripting/luax_state.h
new file mode 100644
index 0000000..e162965
--- /dev/null
+++ b/Runtime/Scripting/luax_state.h
@@ -0,0 +1,298 @@
+#ifndef __LUAX_STATE_H__
+#define __LUAX_STATE_H__
+
+#include <string>
+
+#include "luax_config.h"
+#include "luax_reftable.h"
+#include "luax_globalstate.h"
+
+namespace Luax
+{
+
+ class LuaxVM;
+ class LuaxEnum;
+ class LuaxStrongRef;
+ class LuaxWeakRef;
+
+ ///
+ /// ¶Ôlua_StateµÄ´úÀí£¬³ýÁ˱£´æÒ»¸ölua_StateµÄÒýÓò»±£´æÆäËûÄÚÈÝ¡£Ò»¸öʵÀýµÄmetatableÈçÏ£º
+ /// class table
+ /// member table
+ /// ref table
+ /// userdata
+ /// ´Óuserdataͨ¹ýgetmetatable»ñÈ¡Éϼ¶metatable¡£³ý´ËÖ®Í⻹ÓÐÒ»¸öclass table×¢²áÔÚ¶ÔÓ¦
+ /// µÄÃû³Æ¿Õ¼äÀï¡£
+ ///
+ LUAX_API class LuaxState
+ {
+ public:
+
+ LuaxState(lua_State* state);
+ LuaxState(const LuaxState& state);
+ virtual ~LuaxState();
+
+ inline lua_State* operator ->() { return mState; };
+ inline lua_State& operator *() { return *mState; };
+ inline operator lua_State*() { return mState; }
+ inline operator bool() { return mState != nullptr; };
+
+ ///
+ /// »ñÈ¡°ó¶¨µÄlua_State
+ ///
+ inline lua_State* GetHandle() { return mState; };
+
+ global_State* GetGlobalState();
+
+ LuaxVM* GetVM();
+
+ //------------------------------------------------------------------------------//
+
+ void OpenLibs();
+
+ //------------------------------------------------------------------------------//
+ // Ãû³Æ¿Õ¼ä¹ÜÀí£¬Ãû³Æ¿Õ¼ä¾ÍÊÇÒ»¸ö±í£¬_GÊÇ×îÉÏÃæµÄ±í
+
+ void PushGlobalNamespace();
+ void PushNamespace(cc8* name);
+ void PopNamespace();
+ bool IsNamespace(int idx);
+
+ //------------------------------------------------------------------------------//
+
+ void SetTop(int top);
+ int GetTop();
+ bool CheckParams(int idx, cc8* format);
+ int AbsIndex(int idx);
+ void Call(int nArgs, int nResults);
+
+ //------------------------------------------------------------------------------//
+
+ void GetField(int idx, cc8* name);
+ void GetField(int idx, int key);
+ std::string GetField(int idx, cc8* key, cc8* value);
+ std::string GetField(int idx, int key, cc8* value);
+ std::string GetField(int idx, cc8* key, const std::string& value);
+ std::string GetField(int idx, int key, const std::string& value);
+ bool GetFieldWithType(int idx, cc8* name, int type);
+ bool GetFieldWithType(int idx, int key, int type);
+ bool GetSubfieldWithType(int idx, cc8* format, int type, ...);
+ static cc8* GetLuaTypeName(int type);
+
+ void SetField(int idx, cc8* key);
+
+ bool IsNil(int idx);
+ bool IsNilOrNone(int idx);
+ bool IsTableOrUserdata(int idx);
+ bool IsTrueOrNotNil(int idx);
+ bool IsType(int idx, int type);
+ bool IsType(int idx, cc8* name, int type);
+ bool IsValid();
+
+ bool HasField(int idx, cc8* name);
+ bool HasField(int idx, int key);
+ bool HasField(int idx, cc8* name, int type);
+ bool HasField(int idx, int name, int type);
+ bool HasKeys(int idx);
+
+ void PushNil();
+ void Push(bool value);
+ void Push(cc8* value);
+ void Push(double value);
+ void Push(float value);
+ void Push(int value);
+ void Push(u16 value);
+ void Push(u32 value);
+ void Push(u64 value);
+ void Push(s64 value);
+ void Push(uintptr value);
+ void Push(lua_CFunction value);
+ void Push(void* data, size_t size);
+ void Push(const void* value);
+ void Push(std::string value);
+
+ ///
+ /// ½«idx¿ªÊ¼µÄn¸öpushµ½Õ»¶¥£¬idx»á±»È¡Õý£¬nÏòÉÏÉú³¤¡£
+ ///
+ void PushValues(int idx, int n);
+
+ ///
+ /// ÒÔvoid** µÄÐÎʽ´´½¨userdata£¬²¢½«ÖµÉèÖÃΪptr
+ ///
+ void PushPtrUserdata(void* ptr);
+
+ void Pop(int n = 1);
+
+ void Settop(int idx);
+
+ template<typename T> T* GetUserdata(int idx = 1);
+
+ //------------------------------------------------------------------------------//
+
+ int ErrorType(int idx, cc8* hint);
+
+ //------------------------------------------------------------------------------//
+
+ template<typename T> T GetValue(int idx, T default_value);
+ template<typename T> T GetField(int idx, int key, T value);
+ template<typename T> T GetField(int idx, cc8* key, T value);
+ template<typename T> void SetField(int idx, cc8* key, T value);
+ template<typename T> void SetFieldByIndex(int idx, int key, T value);
+
+ template<typename T> T* CheckUserdata(int idx);
+ template<typename T> T CheckValue(int idx);
+
+ //------------------------------------------------------------------------------//
+
+ void DoString(const std::string& code);
+ void DoFile(const std::string& file);
+
+ //------------------------------------------------------------------------------//
+ // ×¢²á·½·¨
+
+ ///
+ /// ×¢²á¹¤³§£¬ÊÊÓÃÓÚÆÕͨÀ࣬ÓÐNew·½·¨
+ ///
+ template<class TYPE> void RegisterFactory();
+
+ ///
+ /// ×¢²áµ¥Àý£¬Ã»ÓÐNew·½·¨
+ ///
+ template<class TYPE> void RegisterSingleton();
+
+ ///
+ /// ×¢²áö¾Ù
+ ///
+ void RegisterEnum(cc8* name, LuaxEnum* enums);
+
+ ///
+ /// ×¢²áCº¯Êý£¬×¢ÒâºóÃæ¼ÓÒ»ÐÐ{0£¬ 0}
+ ///
+ void RegisterMethods(const luaL_Reg *l);
+
+ ///
+ /// ×¢²áµ¥¸öCº¯Êý
+ ///
+ void RegisterMethod(cc8* fname, lua_CFunction func);
+
+ ///
+ /// °Ñpreloader¼Óµ½package.preloadÀµ±require"libname"ʱluaµÄloader_preload¸ù¾Ý
+ /// libnameÕÒµ½preloaderÖ±½Ó¼ÓÔØ¡£ÓÃÀ´ÊµÏÖÐèÒªrequireµÄʱºò²Å¼ÓÔØ£¬²¢ÇÒ¼ÓÔØ¹ýÒ»´Îºó
+ /// package.loaded¼Ç¼ÏÂÀ´£¬Ï´β»»áÔÙ¼ÓÔØ¡£Í¨¹ýrequire»áµ÷ÓÃÕâ¸öpreloader¡£
+ ///
+ void RegisterPreloader(cc8* libname, lua_CFunction preloader);
+
+ ///
+ /// ¸ù¾ÝluaL_Reg½¨Á¢lib table£¬²¢ÔÚ_GºÍpackage.loaded½¨Á¢¶ÔlibnameµÄË÷Òý£¬Ö¸Ïòlib table¡£
+ ///
+ void RegisterLib(cc8* libname, const luaL_Reg* l);
+
+#if LUAX_ENABLE_PLAIN_CLASS
+ ///
+ /// ×¢²á´¿luaÀàµÄ×¢²áº¯Êý£¬ÓÃÀ´´´½¨´¿luaÀà¡£
+ ///
+ void RegisterPlainClassRegistry(cc8* name);
+#endif
+
+#if LUAX_ENABLE_PLAIN_ENUM
+ ///
+ /// ×¢²á´¿luaµÄö¾Ù£¬ÒÔ·ÀÖ¹ÐÞ¸Äö¾ÙÖµ¡£
+ ///
+ void RegisterPlainEnumRegistry(cc8* name);
+#endif
+
+ protected:
+
+ friend class LuaxVM;
+
+ ///
+ /// ÆÁ±Î¶ÔLuaxStateµÄµØÖ·Ïà¹Ø²Ù×÷
+ ///
+ void* operator &();
+ void* operator new(size_t size);
+
+ lua_State* const mState;
+ };
+
+ //--------------------------------------------------------------------------------//
+ // GetValue()Ä£°åÌØ»¯
+
+ template <> bool LuaxState::GetValue < bool >(int idx, const bool value);
+ template <> cc8* LuaxState::GetValue < cc8* >(int idx, const cc8* value);
+ template <> double LuaxState::GetValue < double >(int idx, const double value);
+ template <> float LuaxState::GetValue < float >(int idx, const float value);
+ template <> s8 LuaxState::GetValue < s8 >(int idx, const s8 value);
+ template <> s16 LuaxState::GetValue < s16 >(int idx, const s16 value);
+ template <> s32 LuaxState::GetValue < s32 >(int idx, const s32 value);
+ template <> s64 LuaxState::GetValue < s64 >(int idx, const s64 value);
+ template <> u8 LuaxState::GetValue < u8 >(int idx, const u8 value);
+ template <> u16 LuaxState::GetValue < u16 >(int idx, const u16 value);
+ template <> u32 LuaxState::GetValue < u32 >(int idx, const u32 value);
+ template <> u64 LuaxState::GetValue < u64 >(int idx, const u64 value);
+ template <> std::string LuaxState::GetValue < std::string >(int idx, const std::string value);
+ template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value);
+
+ //--------------------------------------------------------------------------------//
+ // CheckValueÄ£°åÌØ»¯
+
+ template <> bool LuaxState::CheckValue < bool >(int idx);
+ template <> cc8* LuaxState::CheckValue < cc8* >(int idx);
+ template <> double LuaxState::CheckValue < double >(int idx);
+ template <> float LuaxState::CheckValue < float >(int idx);
+ template <> s8 LuaxState::CheckValue < s8 >(int idx);
+ template <> s16 LuaxState::CheckValue < s16 >(int idx);
+ template <> s32 LuaxState::CheckValue < s32 >(int idx);
+ template <> s64 LuaxState::CheckValue < s64 >(int idx);
+ template <> u8 LuaxState::CheckValue < u8 >(int idx);
+ template <> u16 LuaxState::CheckValue < u16 >(int idx);
+ template <> u32 LuaxState::CheckValue < u32 >(int idx);
+ template <> u64 LuaxState::CheckValue < u64 >(int idx);
+ template <> std::string LuaxState::CheckValue < std::string >(int idx);
+ template <> const void* LuaxState::CheckValue < const void* >(int idx);
+
+ ///
+ /// ÔÚ³ÉÔ±·½·¨Àï´´½¨LuaxState²¢¶Ô²ÎÊý½øÐмì²é¡£
+ ///
+#define LUAX_SETUP(L, params) \
+ Luax::LuaxState state(L); \
+ if(!state.CheckParams(1, params)) return 0
+
+#define LUAX_STATE(L) \
+ Luax::LuaxState state(L)
+
+ //--------------------------------------------------------------------------------//
+
+ ///
+ /// È·±£²»°²È«µÄluaµ÷ÓÃÄܹ»ÔÚµ÷ÓÃÖ®ºó·µ»Øµ½×î³õstack״̬¡£
+ ///
+ class LuaxScopedState
+ : public LuaxState
+ {
+ public:
+ LuaxScopedState(lua_State* state)
+ : LuaxState(state)
+ {
+ mRestoreTop = lua_gettop(mState);
+ }
+ LuaxScopedState(const LuaxState& state)
+ : LuaxState(state)
+ {
+ mRestoreTop = lua_gettop(mState);
+ }
+ ~LuaxScopedState()
+ {
+ if (mState) {
+ if (lua_gettop(mState) != mRestoreTop) {
+ lua_settop(mState, mRestoreTop);
+ }
+ }
+ }
+ private:
+ void* operator new(size_t);
+ int mRestoreTop;
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_state.inc b/Runtime/Scripting/luax_state.inc
new file mode 100644
index 0000000..6671bb5
--- /dev/null
+++ b/Runtime/Scripting/luax_state.inc
@@ -0,0 +1,180 @@
+namespace Luax
+{
+
+ ///
+ /// ×¢²á¹¤³§£¬×¢²áclass table£¬ÒÔtype nameΪ¼üÉèÖÃÔÚÃû³Æ¿Õ¼äÉÏ¡£ÔÚ×¢²á½×¶Î²»»áÉèÖÃÔª±í£¬µÈµ½New·½·¨µ÷ÓõÄʱºò²Å»á¡£
+ ///
+ template<class TYPE>
+ void LuaxState::RegisterFactory()
+ {
+ cc8* type = TYPE::GetLuaxFactoryName();
+
+ lua_State* L = mState;
+ LuaxState& state = *this;
+
+ int top = lua_gettop(L); // namespace table
+ assert(lua_istable(L, top));
+
+ // class table
+ lua_newtable(L);
+ TYPE::RegisterLuaxClassShared(state);
+ TYPE::RegisterLuaxFactoryClass(state);
+ TYPE::RegisterLuaxClass(state);
+
+ // ¼ì²âTYPEÀïÃæÊÇ·ñûÓÐ×¢²á±ØÐëµÄ·½·¨
+#define _assertmethod(I, NAME) \
+ GetField(I, NAME); \
+ assert(IsType(-1, LUA_TFUNCTION)); \
+ Pop();
+
+ //_assertmethod(-1, "New");
+
+#undef _assertmethod
+
+#if LUAX_ENABLE_NATIVE_EXTEND
+ // .Extend()
+ lua_pushvalue(state, -1); // class table
+ lua_pushcclosure(state, TYPE::_ExtendFactory, 1);
+ lua_setfield(state, -2, "Extend");
+#endif
+
+ // class["__index"] = class
+ lua_pushvalue(state, -1); // class table
+ lua_setfield(state, -2, "__index");
+
+ TYPE::SetLuaxClassTableRef(state, -1);
+
+ SetField(top, type);
+
+ // reset top
+ lua_settop(L, top);
+
+ // ºó´¦Àí
+ TYPE::RegisterLuaxPostprocess(state);
+ }
+
+ ///
+ /// Singleton
+ ///
+ template<typename TYPE>
+ void LuaxState::RegisterSingleton()
+ {
+ lua_State* L = mState;
+ LuaxState& state = *this;
+
+ int top = lua_gettop(L); // namespace table
+ assert(lua_istable(L, top));
+
+ // class table.
+ lua_newtable(L);
+ TYPE::RegisterLuaxClassShared(state);
+ TYPE::RegisterLuaxSingletonClass(state);
+ TYPE::RegisterLuaxClass(state);
+
+ TYPE::SetLuaxClassTableRef(state, -1);
+
+ lua_pushvalue(state, -1);
+ lua_setfield(state, -2, "__index");
+
+#if LUAX_ENABLE_NATIVE_EXTEND
+ // .Extend()
+ lua_pushvalue(state, -1); // class table
+ lua_pushcclosure(state, TYPE::_ExtendSingleton, 1);
+ lua_setfield(state, -2, "Extend");
+#endif
+
+ cc8* type = TYPE::GetLuaxSingletonName();
+ SetField(top, type);
+
+ // reset top
+ lua_settop(L, top);
+
+ // ºó´¦Àí
+ TYPE::RegisterLuaxPostprocess(state);
+ }
+
+ template<typename TYPE>
+ void LuaxState::SetField(int idx, cc8* key, TYPE value)
+ {
+ if (IsTableOrUserdata(idx))
+ {
+ idx = AbsIndex(idx);
+ this->Push(value);
+ lua_setfield(mState, idx, key);
+ }
+ }
+
+ template<typename TYPE>
+ void LuaxState::SetFieldByIndex(int idx, int key, TYPE value)
+ {
+ if (IsTableOrUserdata(idx))
+ {
+ idx = AbsIndex(idx);
+ this->Push(value);
+ lua_rawseti(mState, idx, key);
+ }
+ }
+
+ template<typename TYPE>
+ TYPE LuaxState::GetField(int idx, cc8* key, TYPE value)
+ {
+ GetField(idx, key);
+ TYPE result = GetValue < TYPE >(-1, value);
+ this->Pop();
+
+ return result;
+ }
+
+ template<typename TYPE>
+ TYPE LuaxState::GetField(int idx, int key, TYPE value)
+ {
+ GetField(idx, key);
+ TYPE result = GetValue < TYPE >(-1, value);
+ Pop();
+
+ return result;
+ }
+
+ template<typename TYPE>
+ TYPE* LuaxState::GetUserdata(int idx)
+ {
+ void* p = nullptr;
+
+ if (IsType(idx, LUA_TUSERDATA))
+ {
+ p = *(void**)lua_touserdata(mState, idx);
+ }
+
+ return static_cast<TYPE*>(p);
+ }
+
+ template<typename TYPE>
+ TYPE* LuaxState::CheckUserdata(int idx)
+ {
+ if (IsType(idx, LUA_TUSERDATA))
+ {
+ if (lua_getmetatable(mState, idx)) // ref table
+ {
+ if (lua_getmetatable(mState, -1)) // member table
+ {
+ if (lua_getmetatable(mState, -1)) // class table
+ {
+ TYPE::PushLuaxClassTable(*this); // target class table
+ if (lua_rawequal(mState, -1, -2))
+ {
+ Pop(4); // ref\member\class\target class
+ TYPE* udata = GetUserdata<TYPE>(idx);
+ return udata; // userdata
+ }
+ Pop(2); // target class table\class table
+ }
+ Pop(1); // member table
+ }
+ Pop(1); // ref table
+ }
+ }
+ luaL_typerror(mState, idx, TYPE::GetLuaxClassName());
+ return nullptr;
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_utility.h b/Runtime/Scripting/luax_utility.h
new file mode 100644
index 0000000..79601e0
--- /dev/null
+++ b/Runtime/Scripting/luax_utility.h
@@ -0,0 +1,66 @@
+#ifndef __LUAX_UTILITY_H__
+#define __LUAX_UTILITY_H__
+
+// µ¼³önative½Ó¿Ú
+
+/// RegisterLuaxClass ×¢²áÀàµÄ·½·¨ºÍ³ÉÔ±£¬±ÈÈçö¾Ù¡¢³£Á¿µÈµ½class table LuaxGetFactoryName »ñµÃ¹¤³§µÄÀàÃû£¬
+/// ͬʱÓÃÀ´±ÜÃâ×¢²áʱ´íÎó×¢²áΪÁËsingleton£¬Í¨¹ý±àÒëʱ±¨´í±ÜÃâ
+#define LUAX_DECL_FACTORY(type, ...) \
+ friend class Luax::LuaxState; \
+ friend class Luax::LuaxNativeClass<type,##__VA_ARGS__>; \
+ static void RegisterLuaxClass(Luax::LuaxState&); \
+ static void RegisterLuaxPostprocess(Luax::LuaxState&); \
+ static const char* GetLuaxFactoryName() { return #type; };\
+ static const char* GetLuaxClassName() { return #type; };\
+ static bool IsLuaxClassSingleton() { return false; }
+
+/// ×÷Ϊ»ùÀàµÄ³éÏ󹤳§Àà¿ÉÒÔʹÓô˺꣬ע²áÒ»¸öÈë¿Ú£¬ÔÚÅÉÉúÀàµÄ×¢²áº¯ÊýÖе÷Óã¬×¢²á»ùÀàµÄÕâЩ·½·¨¡£
+#define LUAX_DECL_ABSTRACT_FACTORY() \
+ static void RegisterLuaxClass(Luax::LuaxState&);\
+ static void RegisterLuaxPostprocess(Luax::LuaxState&)
+
+/// RegisterLuaxClass ×¢²áÀàµÄ·½·¨ºÍ³ÉÔ±£¬±ÈÈçö¾Ù¡¢³£Á¿µÈµ½class table LuaxGetSingletonName »ñµÃµ¥ÀýµÄÀàÃû
+#define LUAX_DECL_SINGLETON(type, ...) \
+ friend class Luax::LuaxState; \
+ friend class Luax::LuaxNativeClass<type,##__VA_ARGS__>; \
+ static void RegisterLuaxClass(Luax::LuaxState&); \
+ static void RegisterLuaxPostprocess(Luax::LuaxState&); \
+ static const char* GetLuaxSingletonName() { return #type; }; \
+ static const char* GetLuaxClassName() { return #type; }; \
+ static bool IsLuaxClassSingleton() { return true; }
+
+#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State* L)
+
+#define LUAX_DECL_ENUM(e, under_line_index)
+
+/// ±êÃ÷·½·¨ÊµÏֵĺꡣÉÏÏÂÎÄÀïÓÐÒ»¸öL¡£
+#define LUAX_IMPL_METHOD(type, f) int type::f(lua_State* L)
+
+/// ÓÉÓ¦ÓóÌÐòʵÏÖµÄÁ½¸ö½Ó¿Ú¡£ÉÏÏÂÎÄÀïÓÐÒ»¸östate¡£
+#define LUAX_REGISTRY(type) void type::RegisterLuaxClass(Luax::LuaxState& state)
+#define LUAX_POSTPROCESS(type) void type::RegisterLuaxPostprocess(Luax::LuaxState& state)
+
+/// ÓÃÀ´×¢²áµÄºê¡£Ö®Ç°ÕâÀïÍüÁËÓÿɱäºê£¬µ¼ÖÂûÓÐluaclastable refûÓÐ×¢²á¶Ô¡£
+#define LUAX_REGISTER_FACTORY(state, param) state.RegisterFactory<param>()
+#define LUAX_REGISTER_SINGLETON(state, param) state.RegisterSingleton<param>()
+#define LUAX_REGISTER_ABSTRACT_FACTORY(state, type) type::RegisterLuaxPostprocess(state)
+#define LUAX_REGISTER_METHODS(state, ...) \
+ do{ \
+ luaL_Reg __m[] = {__VA_ARGS__,{0, 0}}; \
+ state.RegisterMethods(__m); \
+ }while(0)
+#define LUAX_REGISTER_ENUM(state, name, ...) \
+ do{ \
+ Luax::LuaxEnum __e[] = {__VA_ARGS__,{0, 0}}; \
+ state.RegisterEnum(name, __e); \
+ }while(0)
+
+#define LUAX_PREPARE(L, T) \
+ LUAX_STATE(L); \
+ T* self = state.GetUserdata<T>(1);
+
+#define LUAX_INHERIT(state, type) type::RegisterLuaxClass(state)
+
+#define luaxport private
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_vm.cpp b/Runtime/Scripting/luax_vm.cpp
new file mode 100644
index 0000000..4dc7e0c
--- /dev/null
+++ b/Runtime/Scripting/luax_vm.cpp
@@ -0,0 +1,76 @@
+#include "luax_internal.h"
+#include "luax_vm.h"
+
+namespace Luax
+{
+
+ LuaxVM::VMap LuaxVM::VMs; // ͨ¹ýÏ̲߳éÕÒÐéÄâ»ú£¬ÎªÁË·½±ã
+
+ LuaxVM* LuaxVM::TryGetVM(global_State* gState)
+ {
+ auto it = VMs.find(gState);
+ if (it != VMs.end())
+ return it->second;
+ else
+ return nullptr;
+ }
+
+ LuaxVM* LuaxVM::TryGetVM(lua_State* state)
+ {
+ return TryGetVM(G(state));
+ }
+
+ LuaxVM::LuaxVM()
+ : mStrongRefTable()
+ , mWeakRefTable()
+ {
+ mMainThread = luaL_newstate();
+ assert(mMainThread);
+ mGlobalState = G(mMainThread);
+
+ VMs.insert(std::pair<global_State*, LuaxVM*>(mGlobalState, this));
+ }
+
+ LuaxVM::~LuaxVM()
+ {
+ VMs.erase(mGlobalState);
+ lua_close(mMainThread);
+ }
+
+ // ³õʼ»¯context
+ void LuaxVM::Setup()
+ {
+ LUAX_STATE(mMainThread);
+
+ mStrongRefTable.Init(state, "_LUAX_STRONGREF_TABLE");
+ mWeakRefTable.Init(state, "_LUAX_WEAKREF_TABLE", "v");
+ }
+
+ lua_State* LuaxVM::CreateThread()
+ {
+ lua_State* thread = lua_newthread(mMainThread);
+ assert(thread);
+ return thread;
+ }
+
+ lua_State* LuaxVM::GetMainThread()
+ {
+ return mMainThread;
+ }
+
+ LuaxState LuaxVM::GetMainState()
+ {
+ return mMainThread;
+ }
+
+ LuaxRefTable& LuaxVM::GetStrongRefTable()
+ {
+ return mStrongRefTable;
+ }
+
+ LuaxRefTable& LuaxVM::GetWeakRefTable()
+ {
+ return mWeakRefTable;
+ }
+
+} \ No newline at end of file
diff --git a/Runtime/Scripting/luax_vm.h b/Runtime/Scripting/luax_vm.h
new file mode 100644
index 0000000..3eda3f8
--- /dev/null
+++ b/Runtime/Scripting/luax_vm.h
@@ -0,0 +1,63 @@
+#ifndef __LUAX_CONTEXT_H__
+#define __LUAX_CONTEXT_H__
+
+#include <map>
+#include <unordered_set>
+
+#include "luax_ref.h"
+#include "luax_config.h"
+#include "luax_state.h"
+#include "luax_globalstate.h"
+
+namespace Luax
+{
+
+ ///
+ /// µ¥¸ölua_stateÏà¹ØµÄcontext¡£ÊÇһϵÁдúÀíµÄ¼¯ºÏ£¬¿½±´Ò²Ã»¹ØÏµ£¬Ö÷ÒªÊÇΪÁ˽ÚÔ¼ÄÚ´æ¡£
+ ///
+ class LuaxVM
+ {
+ public:
+
+ ///
+ /// ¸ù¾Ýglobal_StateÄõ½ÐéÄâ»ú¡£
+ ///
+ static LuaxVM* TryGetVM(global_State* gState);
+ static LuaxVM* TryGetVM(lua_State* state);
+
+ LuaxVM();
+ ~LuaxVM();
+
+ ///
+ /// ´´½¨ÐéÄâ»úºó£¬ÐèÒªÊÖ¶¯µ÷ÓÃSetupº¯Êý£¬³õʼ»¯Ò»Ð©ÐéÄâ»ú״̬¡£
+ ///
+ void Setup();
+
+ lua_State* GetMainThread();
+ lua_State* CreateThread();
+ LuaxState GetMainState();
+
+ LuaxRefTable& GetStrongRefTable();
+ LuaxRefTable& GetWeakRefTable();
+
+ private:
+
+ typedef std::map<global_State*, LuaxVM*> VMap;
+
+ static VMap VMs; // ͨ¹ýglobal_StateË÷ÒýÐéÄâ»ú£¬ÎªÁË·½±ã
+
+ LuaxRefTable mStrongRefTable; // _LUAX_STRONGREF_TABLE
+ LuaxRefTable mWeakRefTable; // _LUAX_WEAKREF_TABLE
+
+ global_State* mGlobalState; // ÐéÄâ»úµÄglobal_State£¬Óɵ±Ç°ÐéÄâ»úµÄËùÓÐÏ̹߳²Ïí
+ lua_State* mMainThread; // Ö÷Ïß³Ì
+
+#if LUAX_PROFILER
+ size_t mObjectCount; // ͳ¼ÆËùÓÐÔÚ´ËÐéÄâ»úÖд´½¨µÄʵÀý
+#endif
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Scripting/luax_watchdog.cpp b/Runtime/Scripting/luax_watchdog.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Scripting/luax_watchdog.cpp
diff --git a/Runtime/Scripting/luax_watchdog.h b/Runtime/Scripting/luax_watchdog.h
new file mode 100644
index 0000000..b07b007
--- /dev/null
+++ b/Runtime/Scripting/luax_watchdog.h
@@ -0,0 +1,33 @@
+#ifndef __LUAX_DOG_H__
+#define __LUAX_DOG_H__
+
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ ///
+ /// LuaxNativeClassʵÀýµÄÒýÓüÆÊý¶îwatch dog£¬Ö»ÓÐÔÚwatch dogͨ¹ýʱ²Å¿ÉÒÔdelete¡£
+ ///
+ class LuaxWatchDog
+ {
+ public:
+ LuaxWatchDog()
+ : mVMRef(0)
+ , mNativeRef(0)
+ {
+ }
+
+ inline operator bool()
+ {
+ return mVMRef == 0 && mNativeRef == 0;
+ }
+
+ uint mVMRef; // ÍйܸøµÄÐéÄâ»úÊý
+ uint mNativeRef; // ±¾µØÒýÓÃÊý
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/Runtime/Shaders/ShaderChannel.h b/Runtime/Shaders/ShaderChannel.h
new file mode 100644
index 0000000..d0d2e0a
--- /dev/null
+++ b/Runtime/Shaders/ShaderChannel.h
@@ -0,0 +1,27 @@
+#ifndef SHADER_CHANNEL_H
+#define SHADER_CHANNEL_H
+
+enum ShaderChannel
+{
+ ShaderChannel_Position = 0,
+ ShaderChannel_Normal = 1,
+ ShaderChannel_Tangent = 2,
+ ShaderChannel_Color = 3,
+ ShaderChannel_TexCoord0 = 4,
+ ShaderChannel_TexCoord1 = 5,
+
+ ShaderChannel_Count = 6,
+};
+
+// Vertex attributes locations
+enum VertexAttrLocs
+{
+ VertexAttrLocs_Position = 0,
+ VertexAttrLocs_Normal = 1,
+ VertexAttrLocs_Tangent = 2,
+ VertexAttrLocs_Color = 3,
+ VertexAttrLocs_TexCoord0 = 4,
+ VertexAttrLocs_TexCoord1 = 5,
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Shaders/ShaderDefine.cpp b/Runtime/Shaders/ShaderDefine.cpp
new file mode 100644
index 0000000..bd6a7dc
--- /dev/null
+++ b/Runtime/Shaders/ShaderDefine.cpp
@@ -0,0 +1,11 @@
+#include "ShaderDefine.h"
+
+BuiltinAttirbutes BuiltinAttributesNames[ShaderChannel_Count] = {
+ {ShaderChannel_Position, "Jin_Position"},
+ {ShaderChannel_Normal, "Jin_Normal"},
+ {ShaderChannel_Tangent, "Jin_Tangent"},
+ {ShaderChannel_Color, "Jin_Color"},
+ {ShaderChannel_TexCoord0, "Jin_TexCoord0"},
+ {ShaderChannel_TexCoord1, "Jin_TexCoord1"}
+};
+
diff --git a/Runtime/Shaders/ShaderDefine.h b/Runtime/Shaders/ShaderDefine.h
new file mode 100644
index 0000000..058bfc4
--- /dev/null
+++ b/Runtime/Shaders/ShaderDefine.h
@@ -0,0 +1,19 @@
+#ifndef SHADER_DEFINE_H
+#define SHADER_DEFINE_H
+
+#include "ShaderChannel.h"
+
+struct BuiltinAttirbutes
+{
+ int channel;
+ const char* name;
+};
+
+extern BuiltinAttirbutes BuiltinAttributesNames[ShaderChannel_Count];
+
+struct BuilinUniforms
+{
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Shaders/ShaderUniform.h b/Runtime/Shaders/ShaderUniform.h
new file mode 100644
index 0000000..d736e40
--- /dev/null
+++ b/Runtime/Shaders/ShaderUniform.h
@@ -0,0 +1,4 @@
+#ifndef SHADER_UNIFORM_H
+#define SHADER_UNIFORM_H
+
+#endif \ No newline at end of file
diff --git a/Runtime/Threads/Mutex.cpp b/Runtime/Threads/Mutex.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Threads/Mutex.cpp
diff --git a/Runtime/Threads/Mutex.h b/Runtime/Threads/Mutex.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Threads/Mutex.h
diff --git a/Runtime/Threads/Semaphore.cpp b/Runtime/Threads/Semaphore.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Threads/Semaphore.cpp
diff --git a/Runtime/Threads/Semaphore.h b/Runtime/Threads/Semaphore.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Threads/Semaphore.h
diff --git a/Runtime/Threads/Thread.h b/Runtime/Threads/Thread.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Threads/Thread.h
diff --git a/Runtime/Utilities/Assert.h b/Runtime/Utilities/Assert.h
new file mode 100644
index 0000000..aab7b73
--- /dev/null
+++ b/Runtime/Utilities/Assert.h
@@ -0,0 +1,8 @@
+#ifndef ASSERT_H
+#define ASSERT_H
+
+#include <assert.h>
+
+#define Assert(c) assert(c)
+
+#endif \ No newline at end of file
diff --git a/Runtime/Utilities/Base64.cpp b/Runtime/Utilities/Base64.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Utilities/Base64.cpp
diff --git a/Runtime/Utilities/Base64.h b/Runtime/Utilities/Base64.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Utilities/Base64.h
diff --git a/Runtime/Utilities/Exception.h b/Runtime/Utilities/Exception.h
new file mode 100644
index 0000000..bd73c6b
--- /dev/null
+++ b/Runtime/Utilities/Exception.h
@@ -0,0 +1,6 @@
+#ifndef EXCEPTION_H
+#define EXCEPTION_H
+
+
+
+#endif \ No newline at end of file
diff --git a/Runtime/Utilities/NonCopyable.h b/Runtime/Utilities/NonCopyable.h
new file mode 100644
index 0000000..7135827
--- /dev/null
+++ b/Runtime/Utilities/NonCopyable.h
@@ -0,0 +1,14 @@
+#ifndef NON_COPYABLE_H
+#define NON_COPYABLE_H
+
+class NonCopyable
+{
+public:
+ NonCopyable() {}
+
+private:
+ NonCopyable(const NonCopyable&);
+ NonCopyable& operator=(const NonCopyable&);
+};
+
+#endif
diff --git a/Runtime/Utilities/Singleton.h b/Runtime/Utilities/Singleton.h
new file mode 100644
index 0000000..f864a42
--- /dev/null
+++ b/Runtime/Utilities/Singleton.h
@@ -0,0 +1,43 @@
+#ifndef SINGLETON_H
+#define SINGLETON_H
+
+template<class T>
+class Singleton
+{
+public:
+
+ static T* Instance()
+ {
+ if (!instance) instance = new T;
+ return instance;
+ }
+
+ static void Destroy()
+ {
+ delete instance;
+ instance = nullptr;
+ }
+
+protected:
+
+ Singleton()
+ {
+ instance = static_cast<T*>(this);
+ };
+
+ virtual ~Singleton() {};
+
+ static T* instance;
+
+private:
+
+ Singleton(const Singleton& singleton);
+
+ Singleton& operator = (const Singleton& singleton);
+
+};
+
+template<class T>
+T* Singleton<T>::instance = nullptr;
+
+#endif \ No newline at end of file
diff --git a/Runtime/Utilities/Type.h b/Runtime/Utilities/Type.h
new file mode 100644
index 0000000..b3d0826
--- /dev/null
+++ b/Runtime/Utilities/Type.h
@@ -0,0 +1,21 @@
+#ifndef TYPE_H
+#define TYPE_H
+
+#include <cstdlib>
+#include <stdint.h>
+
+typedef int8_t int8;
+typedef uint8_t uint8;
+typedef unsigned char byte;
+typedef char sbyte;
+typedef int16_t int16;
+typedef uint16_t uint16;
+typedef int32_t int32;
+typedef uint32_t uint32;
+typedef int64_t int64;
+typedef uint64_t uint64;
+
+typedef uint32_t uint;
+typedef int32_t sint;
+
+#endif \ No newline at end of file
diff --git a/Runtime/Utilities/UIDGenerator.h b/Runtime/Utilities/UIDGenerator.h
new file mode 100644
index 0000000..81918f0
--- /dev/null
+++ b/Runtime/Utilities/UIDGenerator.h
@@ -0,0 +1,20 @@
+#ifndef UID_GENERATOR_H
+#define UID_GENERATOR_H
+
+class UIDGenerator
+{
+public:
+ UIDGenerator(int from = 0)
+ : m_Index(from)
+ {
+ };
+ ~UIDGenerator(){};
+
+ int GenUID(){return m_Index++;};
+
+private:
+ int m_Index;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Utilities/Utf8.cpp b/Runtime/Utilities/Utf8.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Utilities/Utf8.cpp
diff --git a/Runtime/Utilities/Utf8.h b/Runtime/Utilities/Utf8.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Runtime/Utilities/Utf8.h
diff --git a/Runtime/Utilities/UtilMacros.h b/Runtime/Utilities/UtilMacros.h
new file mode 100644
index 0000000..1941d7f
--- /dev/null
+++ b/Runtime/Utilities/UtilMacros.h
@@ -0,0 +1,16 @@
+#ifndef UTIL_MACROS_H
+#define UTIL_MACROS_H
+
+#define GET_SET(TYPE,PROP,VAR) \
+ inline void Set##PROP (TYPE val) { VAR = val; } \
+ inline TYPE Get##PROP () {return VAR; }
+
+#define GET(TYPE, PROP, VAR) \
+ inline TYPE Get##PROP () const {return VAR; }
+
+#define SET(TYPE, PROP, VAR) \
+ inline void Set##PROP (TYPE val) { VAR = val; } \
+
+#define Mask(v) (1 << v)
+
+#endif \ No newline at end of file
diff --git a/Runtime/main.cpp b/Runtime/main.cpp
new file mode 100644
index 0000000..8e8dba0
--- /dev/null
+++ b/Runtime/main.cpp
@@ -0,0 +1,6 @@
+#include "SDL2/SDL.h"
+
+int main(int argn, char* args[])
+{
+ return 0;
+}