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,21 +877,25 @@ 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);
PrintDebug(); if (debug_log)
PrintDebug();
} }
virtual void Update() override { virtual void Update() override {
this->CBaseWidget::Update(); this->CBaseWidget::Update();
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);
PrintDebug(); if (debug_log)
PrintDebug();
} }
virtual void Draw(ICanvas* the_drawing_machine) override { virtual void Draw(ICanvas* the_drawing_machine) override {
this->CBaseWidget::Draw(the_drawing_machine); this->CBaseWidget::Draw(the_drawing_machine);
@ -940,7 +947,8 @@ 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;
std::cout << "First X: " << x << std::endl; if (debug_log)
std::cout << "First X: " << x << std::endl;
if (x < 0) if (x < 0)
x = 0; x = 0;
if (x > 1) if (x > 1)
@ -967,7 +975,8 @@ 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;
std::cout << "fog color y: " << y << std::endl; if (debug_log)
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;
fog_color.g = 0.8470588f * y * 0.94f + 0.06f; fog_color.g = 0.8470588f * 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,60 +1029,65 @@ public:
}; };
int start_nyqubel_client() { int start_nyqubel_client() {
hydride_init(); auto client_rendering_thread = std::thread([&]() {
hydride_init();
glez::init(hydride_library.width, hydride_library.height); glez::init(hydride_library.width, hydride_library.height);
Canvas* canvas; Canvas* canvas;
x11::X11Poller x11_poller(hydride_library.display, hydride_library.window); x11::X11Poller x11_poller(hydride_library.display, hydride_library.window);
{
input::RefreshInput();
hydride_draw_begin();
glez::begin();
canvas = new Canvas();
canvas->Setup();
glez::end();
hydride_draw_end();
}
canvas->Add<ncc::Logo>()->SetOffset(500, 525);
auto mesh_test_settings_window = canvas->Add<QubelMeshingTestWindow>();
auto mesh_test_rendering_window = canvas->Add<QubelMeshingTestRenderingWindow>(mesh_test_settings_window);
mesh_test_settings_window->SetOffset(2000, 400);
mesh_test_rendering_window->SetOffset(3000, 800);
bool client_exiting = false;
mesh_test_settings_window->Add<CBaseButton>("exit_button", "Press to Quit-rite", [&](CBaseButton*) {
client_exiting = true;
std::cout << "User Requested Client quit." << std::endl;
});
// Need a 856/480 size window.
hydride_show();
while (1) {
input::RefreshInput();
// Must be called in that order.
hydride_draw_begin();
glez::begin();
{ {
x11_poller.UpdateKeys(); input::RefreshInput();
x11_poller.UpdateMouse();
canvas->Update(); hydride_draw_begin();
using namespace std::chrono_literals; glez::begin();
std::this_thread::sleep_for(500us);
canvas = new Canvas();
canvas->Setup();
glez::end();
hydride_draw_end();
} }
glez::end();
hydride_draw_end();
if (client_exiting) canvas->Add<ncc::Logo>()->SetOffset(500, 525);
break;
} auto mesh_test_settings_window = canvas->Add<QubelMeshingTestWindow>();
std::cout << "Client is Exiting!!!" << std::endl; auto mesh_test_rendering_window = canvas->Add<QubelMeshingTestRenderingWindow>(mesh_test_settings_window);
mesh_test_settings_window->SetOffset(2000, 400);
mesh_test_rendering_window->SetOffset(3000, 800);
bool client_exiting = false;
mesh_test_settings_window->Add<CBaseButton>("exit_button", "Press to Quit-rite", [&](CBaseButton*) {
client_exiting = true;
std::cout << "User Requested Client quit." << std::endl;
});
// Need a 856/480 size window.
hydride_show();
while (1) {
input::RefreshInput();
// Must be called in that order.
hydride_draw_begin();
glez::begin();
{
x11_poller.UpdateKeys();
x11_poller.UpdateMouse();
canvas->Update();
using namespace std::chrono_literals;
std::this_thread::sleep_for(18ms);
}
glez::end();
hydride_draw_end();
if (client_exiting)
break;
}
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;
} }