diff --git a/client/init.lua b/client/init.lua index e62549b..d3df826 100644 --- a/client/init.lua +++ b/client/init.lua @@ -63,13 +63,6 @@ local log = buildat.Logger("__client/init") log:info("init.lua loaded") -local polycode_path = __buildat_get_path("polycode") -CoreServices.getInstance():getConfig():loadConfig("Polycode", polycode_path.."/Assets/UIThemes/dark/theme.xml") -CoreServices.getInstance():getConfig():loadConfig("Polycode", polycode_path.."/Assets/UIThemes/dark/theme.xml") -CoreServices.getInstance():getResourceManager():addArchive(polycode_path.."/Assets"); - -CoreServices.getInstance():getConfig():setNumericValue("Polycode", "uiButtonFontSize", 20) - dofile(__buildat_get_path("share").."/client/test.lua") dofile(__buildat_get_path("share").."/client/packet.lua") dofile(__buildat_get_path("share").."/client/extensions.lua") diff --git a/src/client/app.cpp b/src/client/app.cpp index 7cfb272..58d0383 100644 --- a/src/client/app.cpp +++ b/src/client/app.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #pragma GCC diagnostic pop extern "C" { #include @@ -23,22 +24,31 @@ extern "C" { namespace u3d = Urho3D; extern client::Config g_client_config; +extern bool g_sigint_received; namespace app { struct CApp: public App, public u3d::Application { sp_ m_state; - u3d::LuaScript m_script; + up_ m_script; lua_State *L; int64_t m_last_script_tick_us; CApp(u3d::Context *context): u3d::Application(context), - m_script(context), - L(m_script.GetState()), + m_script(nullptr), + L(nullptr), m_last_script_tick_us(get_timeofday_us()) { + // Instantiate and register the Lua script subsystem so that we can use the LuaScriptInstance component + context_->RegisterSubsystem(new u3d::LuaScript(context_)); + + m_script.reset(new u3d::LuaScript(context_)); + L = m_script->GetState(); + if(L == nullptr) + throw Exception("m_script.GetState() returned null"); + lua_pushlightuserdata(L, (void*)this); lua_setfield(L, LUA_REGISTRYINDEX, "__buildat_app"); @@ -63,7 +73,19 @@ struct CApp: public App, public u3d::Application lua_pop(L, 1); } + engineParameters_["WindowTitle"] = "Buildat Client"; + engineParameters_["LogName"] = "client_Urho3D.log"; + engineParameters_["FullScreen"] = false; + engineParameters_["Headless"] = false; + // TODO + engineParameters_["ResourcePaths"] = + "/home/celeron55/softat/Urho3D/Bin/CoreData"; + engineParameters_["ResourcePackages"] = ""; + engineParameters_["AutoloadPaths"] = "../../../Urho3D/Bin/Data"; + // TODO: Set up update() event + SubscribeToEvent(u3d::E_UPDATE, HANDLER(CApp, on_update)); + // TODO: Set up input events (Call stuff like // call_global_if_exists(L, "__buildat_key_down", 1, 0);) } @@ -84,7 +106,8 @@ struct CApp: public App, public u3d::Application void shutdown() { - // TODO + u3d::Engine *engine = GetSubsystem(); + engine->Exit(); } void run_script(const ss_ &script) @@ -115,8 +138,12 @@ struct CApp: public App, public u3d::Application // Non-public methods - void update() + void on_update(u3d::StringHash eventType, u3d::VariantMap &eventData) { + if(g_sigint_received) + shutdown(); + if(m_state) + m_state->update(); script_tick(); } diff --git a/test/testmodules/minigame/minigame.cpp b/test/testmodules/minigame/minigame.cpp index 43df7cc..826ff92 100644 --- a/test/testmodules/minigame/minigame.cpp +++ b/test/testmodules/minigame/minigame.cpp @@ -82,7 +82,8 @@ struct Module: public interface::Module m_server->sub_event(this, Event::t("network:client_disconnected")); m_server->sub_event(this, Event::t("client_file:files_transmitted")); m_server->sub_event(this, Event::t("network:packet_received/minigame:move")); - m_server->sub_event(this, Event::t("network:packet_received/minigame:clear_field")); + m_server->sub_event(this, + Event::t("network:packet_received/minigame:clear_field")); } void event(const Event::Type &type, const Event::Private *p) @@ -185,9 +186,9 @@ struct Module: public interface::Module log_i(MODULE, "minigame::on_packet_clear_field: name=%zu, size=%zu", cs(packet.name), packet.data.size()); - for(size_t y=0; y