Moved Client Renderer to a seperate std::thread, now runs alongside the server and can shut it down.
This commit is contained in:
parent
937b62a7fd
commit
cc71f0613b
@ -150,7 +150,7 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo)
|
||||
#ifdef NYQUBEL_CLIENT
|
||||
start_nyqubel_client();
|
||||
|
||||
return s_NextState == NextState::Restart;
|
||||
//return s_NextState == NextState::Restart;
|
||||
#endif
|
||||
|
||||
LOG("Creating new server instance...");
|
||||
|
@ -47,6 +47,9 @@
|
||||
|
||||
#include "libpdw/gui/ncc/logo.hpp"
|
||||
|
||||
#include "Root.h"
|
||||
#include "ChatColor.h"
|
||||
|
||||
namespace x11 {
|
||||
|
||||
using RawKey = decltype(XK_2);
|
||||
@ -874,21 +877,25 @@ public:
|
||||
};
|
||||
ChunkRenderer* render_scene;
|
||||
class SkyRenderer : public CBaseWidget {
|
||||
static constexpr bool debug_log = false;
|
||||
|
||||
public:
|
||||
SkyRenderer(IWidget* parent)
|
||||
: CBaseWidget("qubelmesh_test_renderer_skybox", parent) {
|
||||
this->SetPositionMode(FLOATING);
|
||||
this->zindex = -999;
|
||||
|
||||
this->UpdateTime(12000);
|
||||
PrintDebug();
|
||||
this->UpdateTime(23000);
|
||||
if (debug_log)
|
||||
PrintDebug();
|
||||
}
|
||||
virtual void Update() override {
|
||||
this->CBaseWidget::Update();
|
||||
const auto psize = this->GetParent()->GetSize();
|
||||
this->SetSize(psize.first, psize.second);
|
||||
this->UpdateTime(this->curtime + 1);
|
||||
PrintDebug();
|
||||
if (debug_log)
|
||||
PrintDebug();
|
||||
}
|
||||
virtual void Draw(ICanvas* the_drawing_machine) override {
|
||||
this->CBaseWidget::Draw(the_drawing_machine);
|
||||
@ -940,7 +947,8 @@ public:
|
||||
// https://github.com/ddevault/TrueCraft/blob/master/TrueCraft.Client/Modules/SkyModule.cs
|
||||
static float CalcCelestialAngle(int time_of_day) {
|
||||
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)
|
||||
x = 0;
|
||||
if (x > 1)
|
||||
@ -967,7 +975,8 @@ public:
|
||||
}
|
||||
static glez::rgba CalcFogColor(float celestial_angle) {
|
||||
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;
|
||||
fog_color.r = 0.7529412f * 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();
|
||||
glez::rgba air_color;
|
||||
air_color.r = blend(sky.r, fog.r) * 0.5f;
|
||||
air_color.g = blend(sky.g, fog.g) * 0.5f;
|
||||
air_color.b = blend(sky.b, fog.b) * 0.5f;
|
||||
air_color.r = blend(sky.r, fog.r);
|
||||
air_color.g = blend(sky.g, fog.g);
|
||||
air_color.b = blend(sky.b, fog.b);
|
||||
air_color.a = 1.0f;
|
||||
return air_color;
|
||||
}
|
||||
@ -1020,60 +1029,65 @@ public:
|
||||
};
|
||||
|
||||
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;
|
||||
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();
|
||||
Canvas* canvas;
|
||||
x11::X11Poller x11_poller(hydride_library.display, hydride_library.window);
|
||||
{
|
||||
x11_poller.UpdateKeys();
|
||||
x11_poller.UpdateMouse();
|
||||
input::RefreshInput();
|
||||
|
||||
canvas->Update();
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(500us);
|
||||
hydride_draw_begin();
|
||||
glez::begin();
|
||||
|
||||
canvas = new Canvas();
|
||||
canvas->Setup();
|
||||
|
||||
glez::end();
|
||||
hydride_draw_end();
|
||||
}
|
||||
glez::end();
|
||||
hydride_draw_end();
|
||||
|
||||
if (client_exiting)
|
||||
break;
|
||||
}
|
||||
std::cout << "Client is Exiting!!!" << std::endl;
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user