From 47c829f962c3a94b9dff52601a3cd3744ba76d2d Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Tue, 9 Sep 2025 14:02:53 -0500 Subject: [PATCH] first pass on procedural sky --- client/Makefile | 2 +- client/main.cpp | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/client/Makefile b/client/Makefile index 93e34d0..c1eaa88 100644 --- a/client/Makefile +++ b/client/Makefile @@ -3,7 +3,7 @@ CXXFLAGS = -std=c++20 -Wall -Wextra -O2 -I. LDFLAGS = -lraylib -lboost_system -lpthread -lGL -lm -ldl -lrt -lX11 TARGET = game -SOURCES = main.cpp entity/Entity.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp +SOURCES = main.cpp entity/Entity.cpp entity/player/PlayerController.cpp net/NetworkManager.cpp sky/Sky.cpp OBJECTS = $(SOURCES:.cpp=.o) all: $(TARGET) diff --git a/client/main.cpp b/client/main.cpp index 2ae10e6..028c31e 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -12,8 +12,10 @@ #include #include #include +#include #include "entity/player/PlayerController.hpp" #include "net/NetworkManager.hpp" +#include "sky/Sky.hpp" constexpr int WORLD_SIZE = 100; constexpr float WORLD_SCALE = 10.0f; @@ -112,6 +114,7 @@ class Game { Model playerModel; Heightmap heightmap; NetworkManager network; + std::unique_ptr sky; Vector3 playerPos{0, 0, 0}; Texture2D terrainTexture; std::unordered_map playerTextures; @@ -133,6 +136,9 @@ public: InitWindow(1280, 720, "Multiplayer Terrain Game"); SetTargetFPS(60); + // Initialize sky after window is created + sky = std::make_unique(); + // Load heightmap if (!heightmap.load("../assets/heightmap.bin")) { std::cerr << "Failed to load heightmap\n"; @@ -222,6 +228,17 @@ private: return; } + // Update sky + sky->update(GetFrameTime()); + + // Time of day controls (for testing) + if (IsKeyPressed(KEY_T)) { + float currentTime = sky->getTimeOfDay(); + currentTime += 0.1f; + if (currentTime > 1.0f) currentTime -= 1.0f; + sky->setTimeOfDay(currentTime); + } + // Get server position and update player controller playerPos = network.getPosition(); playerController.setPlayerPosition(playerPos); @@ -317,6 +334,8 @@ private: void render() { BeginDrawing(); + + // Clear with a default color first ClearBackground(SKYBLUE); switch (gameState) { @@ -381,6 +400,11 @@ private: void renderGame() { BeginMode3D(playerController.getCamera()); + + // Render skybox first (it will handle its own depth settings) + if (sky) { + sky->renderSkybox(playerController.getCamera()); + } // Draw terrain DrawModel(terrainModel, {0, 0, 0}, 1.0f, WHITE); @@ -404,11 +428,19 @@ private: DrawText(TextFormat("Logged in as: %s", currentUsername.c_str()), 10, 10, 20, WHITE); DrawText("WASD: Move | Q/E: Strafe | Right-Click: Rotate Camera", 10, 35, 20, WHITE); DrawText("Left/Right Arrow: Change Color | Mouse Wheel: Zoom | ESC: Logout", 10, 60, 20, WHITE); + DrawText("T: Change Time of Day", 10, 85, 20, WHITE); if (network.isConnected()) { std::string colorText = "Your color: " + network.getPlayerColor(); - DrawText(colorText.c_str(), 10, 85, 20, WHITE); + DrawText(colorText.c_str(), 10, 110, 20, WHITE); } - DrawFPS(10, 110); + + // Show time of day + float timeHour = sky->getTimeOfDay() * 24.0f; + int hour = (int)timeHour; + int minute = (int)((timeHour - hour) * 60); + DrawText(TextFormat("Time: %02d:%02d", hour, minute), 10, 135, 20, WHITE); + + DrawFPS(10, 160); } };