Migrate to latest ReWindow
This commit is contained in:
@@ -26,7 +26,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-21.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-23.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -12,7 +12,7 @@ namespace CaveGame::Client {
|
||||
using CaveGame::Core::Entity;
|
||||
class GameSession : public Scene {
|
||||
public:
|
||||
GameSession();
|
||||
GameSession(bool createNewWorld);
|
||||
|
||||
void Update(float elapsed) override;
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace CaveGame::Client {
|
||||
{ }
|
||||
void PassKeyInput(Key key, bool pressed) override;
|
||||
|
||||
void SaveAndExit();
|
||||
|
||||
std::vector<Entity*> entity_list;
|
||||
LocalWorld* world;
|
||||
JUI::Scene* hud;
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
@@ -13,13 +13,16 @@ namespace CaveGame::Client
|
||||
using Core::ConcurrentQueue;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class WorldAsyncIOThreadManager
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class LocalWorld : public CaveGame::Core::World
|
||||
{
|
||||
public:
|
||||
// TODO: WTF
|
||||
//
|
||||
JGL::Font font;
|
||||
LocalWorld();
|
||||
LocalWorld(const std::string& world_name, int seed, bool overwrite);
|
||||
void PostInit();
|
||||
void Draw();
|
||||
void Update(float elapsed) override;
|
||||
|
@@ -12,7 +12,7 @@ namespace CaveGame::Client
|
||||
{
|
||||
|
||||
struct SingleplayerSessionInfo {
|
||||
|
||||
bool NewWorld;
|
||||
};
|
||||
|
||||
class MainMenu : public Scene {
|
||||
|
@@ -11,27 +11,27 @@ void CaveGame::Client::GameSession::Load() {
|
||||
|
||||
void CaveGame::Client::GameSession::Draw() {
|
||||
world->Draw();
|
||||
for (auto& entity: entity_list)
|
||||
{
|
||||
entity->Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//for (auto& entity: entity_list)
|
||||
//{
|
||||
// entity->Draw();
|
||||
//}
|
||||
}
|
||||
|
||||
void CaveGame::Client::GameSession::SaveAndExit()
|
||||
{
|
||||
world->SaveAndExit();
|
||||
}
|
||||
|
||||
void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
world->Update(elapsed);
|
||||
for (auto& entity: entity_list)
|
||||
{
|
||||
entity->Update(elapsed);
|
||||
}
|
||||
//for (auto& entity: entity_list)
|
||||
//{
|
||||
// entity->Update(elapsed);
|
||||
//}
|
||||
}
|
||||
|
||||
CaveGame::Client::GameSession::GameSession() : Scene() {
|
||||
entity_list = std::vector<Entity*>();
|
||||
world = new LocalWorld();
|
||||
CaveGame::Client::GameSession::GameSession(bool overwite_world) : Scene() {
|
||||
world = new LocalWorld("test_world", 0, overwite_world);
|
||||
}
|
||||
|
||||
void CaveGame::Client::GameSession::PassWindowSize(const Vector2 &size) {
|
||||
|
@@ -8,7 +8,8 @@
|
||||
namespace CaveGame::Client {
|
||||
|
||||
|
||||
LocalWorld::LocalWorld() : World("test_world", 0) {
|
||||
LocalWorld::LocalWorld(const std::string& world_name, int seed, bool overwrite)
|
||||
: World(world_name, seed, overwrite) {
|
||||
chunk_thread = std::thread(&LocalWorld::ChunkServerThread, this);
|
||||
chunk_thread.detach();
|
||||
//hud = nullptr;
|
||||
@@ -179,7 +180,10 @@ namespace CaveGame::Client {
|
||||
const auto coords = it->first;
|
||||
if (!IsChunkCellWithinViewport(coords))
|
||||
{
|
||||
|
||||
// TODO: Move off main thread.
|
||||
SaveChunkToFile(coords, it->second);
|
||||
|
||||
//delete it->second;
|
||||
loaded_chunks.erase(it++);
|
||||
|
||||
@@ -240,7 +244,6 @@ namespace CaveGame::Client {
|
||||
void LocalWorld::Update(float elapsed) {
|
||||
World::Update(elapsed);
|
||||
|
||||
|
||||
camera.Update(elapsed);
|
||||
|
||||
LookForChunksNeedUnloading();
|
||||
|
@@ -92,13 +92,28 @@ void CaveGame::Client::MainMenu::BuildWidgets() {
|
||||
auto *button_list = new JUI::VerticalListLayout(button_group);
|
||||
button_list->PaddingBottom(5_px);
|
||||
|
||||
auto *sp_btn = create_mainmenu_btn("Singleplayer", button_list);
|
||||
auto *new_world_btn = create_mainmenu_btn("New World", button_list);
|
||||
|
||||
sp_btn->OnReleaseEvent += [this](Vector2 pos, MouseButton btn, bool b) {
|
||||
if (b)
|
||||
RequestWorld.Invoke({});
|
||||
new_world_btn->OnReleaseEvent += [this](Vector2 pos, MouseButton btn, bool b)
|
||||
{
|
||||
RequestWorld.Invoke({.NewWorld = true});
|
||||
};
|
||||
|
||||
auto *load_world_btn = create_mainmenu_btn("Load World", button_list);
|
||||
|
||||
load_world_btn->OnReleaseEvent += [this](Vector2 pos, MouseButton btn, bool b)
|
||||
{
|
||||
RequestWorld.Invoke({.NewWorld = false});
|
||||
};
|
||||
|
||||
|
||||
//auto *sp_btn = create_mainmenu_btn("Singleplayer", button_list);
|
||||
|
||||
//sp_btn->OnReleaseEvent += [this](Vector2 pos, MouseButton btn, bool b) {
|
||||
// if (b)
|
||||
// RequestWorld.Invoke({});
|
||||
//};
|
||||
|
||||
auto *mp_btn = create_mainmenu_btn("Multiplayer", button_list);
|
||||
auto *credits_btn = create_mainmenu_btn("Credits", button_list);
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
namespace CaveGame::ClientApp
|
||||
{
|
||||
|
||||
using CaveGame::Client::Scene;
|
||||
using CaveGame::Client::SceneManager;
|
||||
|
||||
@@ -81,11 +82,11 @@ namespace CaveGame::ClientApp
|
||||
|
||||
public:
|
||||
void OnRefresh(float elapsed) override;
|
||||
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent &ev) override;
|
||||
void OnKeyUp(const ReWindow::WindowEvents::KeyUpEvent &ev) override;
|
||||
void OnMouseButtonUp(const ReWindow::WindowEvents::MouseButtonUpEvent &ev) override;
|
||||
void OnMouseMove(const ReWindow::WindowEvents::MouseMoveEvent &ev) override;
|
||||
bool OnResizeRequest(const ReWindow::WindowEvents::WindowResizeRequestEvent &ev) override;
|
||||
void OnMouseButtonDown(const ReWindow::MouseButtonDownEvent &ev) override;
|
||||
void OnKeyUp(const ReWindow::KeyUpEvent &ev) override;
|
||||
void OnMouseButtonUp(const ReWindow::MouseButtonUpEvent &ev) override;
|
||||
void OnMouseMove(const ReWindow::MouseMoveEvent &ev) override;
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &ev) override;
|
||||
protected:
|
||||
/// Draws a sequence of 'debug' information strings to the screen, in a descending list.
|
||||
void draw_debug_info(std::vector<std::string> tokens);
|
||||
|
@@ -13,14 +13,16 @@ namespace CaveGame::ClientApp
|
||||
{
|
||||
splash_ctx = new CaveGame::Client::Splash();
|
||||
menu_ctx = new CaveGame::Client::MainMenu();
|
||||
game_ctx = new CaveGame::Client::GameSession();
|
||||
//game_ctx = new CaveGame::Client::GameSession();
|
||||
|
||||
menu_ctx->RequestWorld += [this](Client::SingleplayerSessionInfo info) {
|
||||
|
||||
game_ctx = new CaveGame::Client::GameSession(info.NewWorld);
|
||||
// TODO: Parse Info to construct gameworld files.
|
||||
ChangeScene(game_ctx);
|
||||
};
|
||||
menu_ctx->RequestQuit += [this]() {
|
||||
Die();
|
||||
Die();
|
||||
};
|
||||
menu_ctx->RequestShowCredits += [this]()
|
||||
{
|
||||
@@ -35,8 +37,8 @@ namespace CaveGame::ClientApp
|
||||
|
||||
void CaveGameWindow::Step()
|
||||
{
|
||||
this->pollEvents();
|
||||
this->refresh();
|
||||
//this->PollEvents();
|
||||
this->ManagedRefresh();
|
||||
}
|
||||
|
||||
void CaveGameWindow::Gameloop()
|
||||
@@ -48,11 +50,11 @@ namespace CaveGame::ClientApp
|
||||
|
||||
void CaveGameWindow::Run()
|
||||
{
|
||||
this->setRenderer(RenderingAPI::OPENGL);
|
||||
this->SetRenderer(RenderingAPI::OPENGL);
|
||||
this->Open();
|
||||
this->Init();
|
||||
this->setResizable(true);
|
||||
this->setVsyncEnabled(false);
|
||||
this->SetResizable(true);
|
||||
this->SetVsyncEnabled(false);
|
||||
|
||||
// TODO: Implement Resource/Asset manager rather than passing asset references around like this.
|
||||
this->splash_ctx->PassFont(Jupiteroid);
|
||||
@@ -92,7 +94,7 @@ namespace CaveGame::ClientApp
|
||||
|
||||
// Init Josh Graphics
|
||||
JGL::InitTextEngine();
|
||||
JGL::Update(getSize());
|
||||
JGL::Update(GetSize());
|
||||
|
||||
// Fetch core assets
|
||||
// TODO: Asset manager? Need to share references and pointers of assets between many files..
|
||||
@@ -137,33 +139,33 @@ namespace CaveGame::ClientApp
|
||||
// so we had to bring this code up here.
|
||||
// @maxi suggests function pointers and closure.
|
||||
|
||||
if (isKeyDown(Keys::LeftArrow))
|
||||
if (IsKeyDown(Keys::LeftArrow))
|
||||
game_ctx->world->camera.MoveLeft();
|
||||
if (isKeyDown(Keys::RightArrow))
|
||||
if (IsKeyDown(Keys::RightArrow))
|
||||
game_ctx->world->camera.MoveRight();
|
||||
if (isKeyDown(Keys::UpArrow))
|
||||
if (IsKeyDown(Keys::UpArrow))
|
||||
game_ctx->world->camera.MoveUp();
|
||||
if (isKeyDown(Keys::DownArrow))
|
||||
if (IsKeyDown(Keys::DownArrow))
|
||||
game_ctx->world->camera.MoveDown();
|
||||
|
||||
if (isKeyDown(Keys::LeftBracket))
|
||||
if (IsKeyDown(Keys::LeftBracket))
|
||||
game_ctx->world->camera.Rotate(-5*elapsed);
|
||||
if (isKeyDown(Keys::RightBracket))
|
||||
if (IsKeyDown(Keys::RightBracket))
|
||||
game_ctx->world->camera.Rotate(5*elapsed);
|
||||
|
||||
if (isKeyDown(Keys::Minus))
|
||||
if (IsKeyDown(Keys::Minus))
|
||||
game_ctx->world->camera.ZoomIn(-elapsed);
|
||||
if (isKeyDown(Keys::Equals))
|
||||
if (IsKeyDown(Keys::Equals))
|
||||
game_ctx->world->camera.ZoomIn(elapsed);
|
||||
|
||||
|
||||
if (isKeyDown(Keys::R))
|
||||
if (IsKeyDown(Keys::R))
|
||||
game_ctx->world->RefreshAll();
|
||||
|
||||
if (mbd)
|
||||
{
|
||||
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(mouse_coords);
|
||||
Vector2 transformed = game_ctx->world->camera.ScreenToWorld(GetMouseCoordinates());
|
||||
game_ctx->world->SetTile(transformed.x, transformed.y, Core::TileID::AIR);
|
||||
game_ctx->world->SetTile(transformed.x+1, transformed.y, Core::TileID::AIR);
|
||||
game_ctx->world->SetTile(transformed.x-1, transformed.y, Core::TileID::AIR);
|
||||
@@ -182,7 +184,7 @@ namespace CaveGame::ClientApp
|
||||
// Update Current Scene
|
||||
if (current_scene != nullptr)
|
||||
{
|
||||
current_scene->PassWindowSize(getSize());
|
||||
current_scene->PassWindowSize(GetSize());
|
||||
current_scene->Update(elapsed);
|
||||
// TODO: current_scene->PassInputState(...); ?
|
||||
}
|
||||
@@ -193,7 +195,7 @@ namespace CaveGame::ClientApp
|
||||
|
||||
if (current_scene == game_ctx)
|
||||
{
|
||||
game_ctx->world->mouse_pos = mouse_coords;
|
||||
game_ctx->world->mouse_pos = GetMouseCoordinates();
|
||||
InGameControls(elapsed);
|
||||
}
|
||||
|
||||
@@ -201,7 +203,7 @@ namespace CaveGame::ClientApp
|
||||
|
||||
void CaveGameWindow::Draw()
|
||||
{
|
||||
JGL::Update(getSize());
|
||||
JGL::Update(GetSize());
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -239,11 +241,11 @@ namespace CaveGame::ClientApp
|
||||
int glError = glGetError();
|
||||
if (glError != GL_NO_ERROR)
|
||||
std::cout << glError << std::endl;
|
||||
glSwapBuffers();
|
||||
GLSwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
void CaveGameWindow::OnKeyUp(const ReWindow::WindowEvents::KeyUpEvent& ev)
|
||||
void CaveGameWindow::OnKeyUp(const ReWindow::KeyUpEvent& ev)
|
||||
{
|
||||
if (current_scene != nullptr)
|
||||
current_scene->PassKeyInput(ev.key, true);
|
||||
@@ -257,7 +259,7 @@ namespace CaveGame::ClientApp
|
||||
//RWindow::OnKeyUp(ev);
|
||||
}
|
||||
|
||||
void CaveGameWindow::OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent& ev)
|
||||
void CaveGameWindow::OnMouseButtonDown(const ReWindow::MouseButtonDownEvent& ev)
|
||||
{
|
||||
|
||||
if (current_scene != nullptr)
|
||||
@@ -278,7 +280,7 @@ namespace CaveGame::ClientApp
|
||||
}
|
||||
|
||||
|
||||
void CaveGameWindow::OnMouseButtonUp(const ReWindow::WindowEvents::MouseButtonUpEvent& ev)
|
||||
void CaveGameWindow::OnMouseButtonUp(const ReWindow::MouseButtonUpEvent& ev)
|
||||
{
|
||||
if (current_scene != nullptr)
|
||||
current_scene->PassMouseInput(ev.Button.ButtonIndex, false);
|
||||
@@ -296,7 +298,7 @@ namespace CaveGame::ClientApp
|
||||
RWindow::OnMouseButtonUp(ev);
|
||||
}
|
||||
|
||||
void CaveGameWindow::OnMouseMove(const ReWindow::WindowEvents::MouseMoveEvent& ev)
|
||||
void CaveGameWindow::OnMouseMove(const ReWindow::MouseMoveEvent& ev)
|
||||
{
|
||||
|
||||
if (current_scene != nullptr)
|
||||
@@ -307,7 +309,7 @@ namespace CaveGame::ClientApp
|
||||
RWindow::OnMouseMove(ev);
|
||||
}
|
||||
|
||||
bool CaveGameWindow::OnResizeRequest(const ReWindow::WindowEvents::WindowResizeRequestEvent& ev)
|
||||
bool CaveGameWindow::OnResizeRequest(const ReWindow::WindowResizeRequestEvent& ev)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ namespace CaveGame::Core
|
||||
World() = default;
|
||||
~World() = default;
|
||||
|
||||
explicit World(const std::string &worldName, int seed = 0);
|
||||
explicit World(const std::string &worldName, int seed = 0, bool overwrite = false);
|
||||
|
||||
|
||||
TileID GetTile(int x, int y) const;
|
||||
@@ -49,6 +49,8 @@ namespace CaveGame::Core
|
||||
|
||||
virtual void RefreshAll();
|
||||
|
||||
virtual void SaveAndExit();
|
||||
|
||||
/// Returns whether or not the world currently has a chunk loaded at the specified chunk coordinates.
|
||||
/// @note Valid Chunk coordinates are integers only.
|
||||
bool HasChunkAtCell(const Vector2 &cell) const;
|
||||
|
@@ -79,7 +79,7 @@ namespace CaveGame::Core
|
||||
return {std::cos(rotation), std::cos(rotation)};
|
||||
}
|
||||
|
||||
World::World(const std::string &worldName, int seed) : world_name(worldName), generator(seed) {
|
||||
World::World(const std::string &worldName, int seed, bool overwrite) : world_name(worldName), generator(seed) {
|
||||
|
||||
/// Create "worlds" directory if not already there.
|
||||
if (!std::filesystem::exists(worlds))
|
||||
@@ -87,6 +87,12 @@ namespace CaveGame::Core
|
||||
|
||||
std::filesystem::path current_world_path = worlds/worldName;
|
||||
|
||||
if (overwrite)
|
||||
{
|
||||
if (std::filesystem::exists(current_world_path))
|
||||
std::filesystem::remove_all(current_world_path);
|
||||
}
|
||||
|
||||
/// Create directory for this world if not already there.
|
||||
if (!std::filesystem::exists(current_world_path))
|
||||
std::filesystem::create_directory(current_world_path);
|
||||
@@ -269,6 +275,14 @@ namespace CaveGame::Core
|
||||
}
|
||||
}
|
||||
|
||||
void World::SaveAndExit() {
|
||||
std::cout << "Saving before closing!!" << std::endl;
|
||||
for (auto&[coords, chunk] : loaded_chunks)
|
||||
{
|
||||
SaveChunkToFile(coords, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
//Chunk* World::GetChunkAtCell(const Vector2 &cell) {
|
||||
// return loaded_chunks.at(cell);
|
||||
//}
|
||||
|
Reference in New Issue
Block a user