Moved Client Renderer to a seperate std::thread, now runs alongside the server and can shut it down.

This commit is contained in:
Rebekah 2024-02-14 15:54:24 -05:00
parent 937b62a7fd
commit cc71f0613b
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
2 changed files with 72 additions and 58 deletions

View File

@ -150,7 +150,7 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo)
#ifdef NYQUBEL_CLIENT #ifdef NYQUBEL_CLIENT
start_nyqubel_client(); start_nyqubel_client();
return s_NextState == NextState::Restart; //return s_NextState == NextState::Restart;
#endif #endif
LOG("Creating new server instance..."); LOG("Creating new server instance...");

View File

@ -47,6 +47,9 @@
#include "libpdw/gui/ncc/logo.hpp" #include "libpdw/gui/ncc/logo.hpp"
#include "Root.h"
#include "ChatColor.h"
namespace x11 { namespace x11 {
using RawKey = decltype(XK_2); using RawKey = decltype(XK_2);
@ -874,13 +877,16 @@ public:
}; };
ChunkRenderer* render_scene; ChunkRenderer* render_scene;
class SkyRenderer : public CBaseWidget { class SkyRenderer : public CBaseWidget {
static constexpr bool debug_log = false;
public: public:
SkyRenderer(IWidget* parent) SkyRenderer(IWidget* parent)
: CBaseWidget("qubelmesh_test_renderer_skybox", parent) { : CBaseWidget("qubelmesh_test_renderer_skybox", parent) {
this->SetPositionMode(FLOATING); this->SetPositionMode(FLOATING);
this->zindex = -999; this->zindex = -999;
this->UpdateTime(12000); this->UpdateTime(23000);
if (debug_log)
PrintDebug(); PrintDebug();
} }
virtual void Update() override { virtual void Update() override {
@ -888,6 +894,7 @@ public:
const auto psize = this->GetParent()->GetSize(); const auto psize = this->GetParent()->GetSize();
this->SetSize(psize.first, psize.second); this->SetSize(psize.first, psize.second);
this->UpdateTime(this->curtime + 1); this->UpdateTime(this->curtime + 1);
if (debug_log)
PrintDebug(); PrintDebug();
} }
virtual void Draw(ICanvas* the_drawing_machine) override { virtual void Draw(ICanvas* the_drawing_machine) override {
@ -940,6 +947,7 @@ public:
// https://github.com/ddevault/TrueCraft/blob/master/TrueCraft.Client/Modules/SkyModule.cs // https://github.com/ddevault/TrueCraft/blob/master/TrueCraft.Client/Modules/SkyModule.cs
static float CalcCelestialAngle(int time_of_day) { static float CalcCelestialAngle(int time_of_day) {
float x = (time_of_day % 24000) / 24000.0f - 0.25f; float x = (time_of_day % 24000) / 24000.0f - 0.25f;
if (debug_log)
std::cout << "First X: " << x << std::endl; std::cout << "First X: " << x << std::endl;
if (x < 0) if (x < 0)
x = 0; x = 0;
@ -967,6 +975,7 @@ public:
} }
static glez::rgba CalcFogColor(float celestial_angle) { static glez::rgba CalcFogColor(float celestial_angle) {
const float y = cos(celestial_angle * glm::two_pi<float>()) * 2 + 0.5f; const float y = cos(celestial_angle * glm::two_pi<float>()) * 2 + 0.5f;
if (debug_log)
std::cout << "fog color y: " << y << std::endl; std::cout << "fog color y: " << y << std::endl;
glez::rgba fog_color; glez::rgba fog_color;
fog_color.r = 0.7529412f * y * 0.94f + 0.06f; fog_color.r = 0.7529412f * y * 0.94f + 0.06f;
@ -983,9 +992,9 @@ public:
}; };
const auto &fog = this->GetWorldFogColor(), sky = this->GetWorldSkyColor(); const auto &fog = this->GetWorldFogColor(), sky = this->GetWorldSkyColor();
glez::rgba air_color; glez::rgba air_color;
air_color.r = blend(sky.r, fog.r) * 0.5f; air_color.r = blend(sky.r, fog.r);
air_color.g = blend(sky.g, fog.g) * 0.5f; air_color.g = blend(sky.g, fog.g);
air_color.b = blend(sky.b, fog.b) * 0.5f; air_color.b = blend(sky.b, fog.b);
air_color.a = 1.0f; air_color.a = 1.0f;
return air_color; return air_color;
} }
@ -1020,6 +1029,7 @@ public:
}; };
int start_nyqubel_client() { int start_nyqubel_client() {
auto client_rendering_thread = std::thread([&]() {
hydride_init(); hydride_init();
glez::init(hydride_library.width, hydride_library.height); glez::init(hydride_library.width, hydride_library.height);
@ -1066,7 +1076,7 @@ int start_nyqubel_client() {
canvas->Update(); canvas->Update();
using namespace std::chrono_literals; using namespace std::chrono_literals;
std::this_thread::sleep_for(500us); std::this_thread::sleep_for(18ms);
} }
glez::end(); glez::end();
hydride_draw_end(); hydride_draw_end();
@ -1075,5 +1085,9 @@ int start_nyqubel_client() {
break; break;
} }
std::cout << "Client is Exiting!!!" << std::endl; std::cout << "Client is Exiting!!!" << std::endl;
cRoot::Get()->BroadcastChat((AString)cChatColor::Red + "[WARNING] " + cChatColor::White + "Server is terminating!");
cRoot::Get()->QueueExecuteConsoleCommand("stop");
});
client_rendering_thread.detach();
return 0; return 0;
} }