local dirtools = require("tools.vfs.dirtools") dirtools.init("sokol%-luajit") dirtools.add_package_path("editor"..dirtools.sep.."twig") --_G.SOKOL_DLL = "sokol_debug_dll" local sapp = require("sokol_app") sg = require("sokol_gfx") sg = require("sokol_nuklear") local nk = sg local slib = require("sokol_libs") -- Warn - always after gfx!! local hmm = require("hmm") local hutils = require("hmm_utils") local stb = require("stb") local utils = require("utils") local ffi = require("ffi") -- -------------------------------------------------------------------------------------- local engineState = require("engine.state_engine") -- -------------------------------------------------------------------------------------- local shell32 = ffi.load("shell32") ffi.cdef[[ void Sleep(uint32_t ms); void * ShellExecuteA(const void * hwnd, const char * lpOperation, const char * lpFile, const char * lpParameters, char* lpDirectory, int nShowCmd); int ShowWindow(const void * hWnd, int nCmdShow); ]] local SW_MAXIMIZE = 3 -- -------------------------------------------------------------------------------------- local enabled_profile = arg[1] == "-profile" local profile = nil if(enabled_profile) then profile = require("jit.profile") function cb(thread, samples, vmstate) print(profile.dumpstack(thread, "l\n", 1)) end profile.start("fi4", cb) end -- -------------------------------------------------------------------------------------- -- Grab some gui elements for testing local SmainGui = require("editor.states.mainGui") engineState.queue( "mainGui", SmainGui, true ) -- -------------------------------------------------------------------------------------- local width = 1920 local height = 1080 if(arg[1] and arg[2]) then width = tonumber(arg[1]) height = tonumber(arg[2]) end print("Display: "..width .. " x ".. height) -- -------------------------------------------------------------------------------------- local function ErrorCheck(status, err) if(status == false) then print(status) print(err) print(debug.traceback()) os.exit() end end -- -------------------------------------------------------------------------------------- -- The project manager handles configuration of the project data (build, debug etc) -- Project manager defines what worlds, assets and folders are accessible for the project -- Note: the editor should _always_ have an active project. If it doesnt have one, it will -- show a load panel to load one. local projectmgr = require("editor.project-manager") local function init() projectmgr:init() local desc = ffi.new("sg_desc[1]") desc[0].environment = slib.sglue_environment() desc[0].logger.func = slib.slog_func desc[0].disable_validation = false sg.sg_setup( desc ) local snk = ffi.new("snk_desc_t[1]") snk[0].dpi_scale = sapp.sapp_dpi_scale() snk[0].logger.func = slib.slog_func nk.snk_setup(snk) print("Sokol Is Valid: "..tostring(sg.sg_isvalid())) engineState.ready = nil mainState.ctx = nil sapp.sapp_show_mouse(true) sapp.sapp_set_window_title("Thunc Editor v"..PROJECT_VERSION) local hwnd = sapp.sapp_win32_get_hwnd() ffi.C.ShowWindow(hwnd, SW_MAXIMIZE) end -- -------------------------------------------------------------------------------------- local function input(event) -- Only kick things off once the window is ready. if(event.type == sapp.SAPP_EVENTTYPE_RESIZED) then engineState.ready = true end engineState.input(event, {}) end -- -------------------------------------------------------------------------------------- local function frame() -- /* NOTE: the vs_params_t struct has been code-generated by the shader-code-gen */ local w = sapp.sapp_widthf() local h = sapp.sapp_heightf() local t = (sapp.sapp_frame_duration() * 60.0) local dt = sapp.sapp_frame_duration() local ctx = nk.snk_new_frame() if(engineState.ready == true and mainState.ctx == nil) then mainState.ctx = ctx ErrorCheck( pcall( engineState.init, w, h ) ) nk.nk_style_show_cursor(ctx) elseif(mainState.ctx) then mainState.ctx = ctx end ErrorCheck( pcall( engineState.update, dt ) ) -- // the sokol_gfx draw pass local pass = ffi.new("sg_pass[1]") pass[0].action.colors[0].load_action = sg.SG_LOADACTION_CLEAR pass[0].action.colors[0].clear_value = { 0.25, 0.5, 0.7, 1.0 } pass[0].swapchain = slib.sglue_swapchain() sg.sg_begin_pass(pass) nk.snk_render(sapp.sapp_width(), sapp.sapp_height()) sg.sg_end_pass() sg.sg_commit() -- Display frame stats in console. -- hutils.show_stats() end -- -------------------------------------------------------------------------------------- local function cleanup() nk.snk_shutdown() sg.sg_shutdown() end -- -------------------------------------------------------------------------------------- local app_desc = ffi.new("sapp_desc[1]") app_desc[0].init_cb = init app_desc[0].frame_cb = frame app_desc[0].cleanup_cb = cleanup app_desc[0].event_cb = input app_desc[0].width = width app_desc[0].height = height app_desc[0].high_dpi = true app_desc[0].window_title = "editor - sokol" app_desc[0].fullscreen = false -- app_desc[0].icon.sokol_default = true app_desc[0].enable_clipboard = true app_desc[0].ios_keyboard_resizes_canvas = false app_desc[0].logger.func = slib.slog_func sapp.sapp_run( app_desc ) -- -------------------------------------------------------------------------------------- if(profile) then profile.stop() end -- --------------------------------------------------------------------------------------