#include "Game.hpp" #include #include "Time.hpp" #include "Common/Sizes.hpp" #include "Entities/Player.hpp" #include "GFX/Camera.hpp" #include "GFX/Window.hpp" #include "World/Clouds.hpp" #include "World/World.hpp" namespace MC { void Game::run() const { World::World world{}; GFX::Camera camera{}; World::Clouds clouds{}; Entities::Player player{{0, World::Chunk::Height / 2.0, 0}}; Time time; while (!m_window.should_close()) { m_window.poll_events(); #ifdef __APPLE__ // Needs to happen on the main thread fix_macos_render(); #endif time.start_frame(); if (m_window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) { m_window.close(); } player.update(time, m_window, camera, world); clouds.update(time); GFX::Actions actions; for (auto chunk : world.get_visible_chunks(time, camera.position())) { auto position = chunk->chunk.value().position(); actions.add({ .program = GFX::Resources::Program::Terrain, .mesh = &chunk->land_mesh.value(), .transform = Transform(position), }); actions.add({ .program = GFX::Resources::Program::Terrain, .mesh = &chunk->water_mesh.value(), .transform = Transform(position - Vec3{0, 0.2, 0}), .alpha = 0.4, }); } player.render(actions); clouds.render(actions, player.position()); m_render_control->send_render_data({actions, camera}); m_render_control->wait_for_render_finish(); time.end_frame(); } } void Game::fix_macos_render() const { static Bool moved = false; if(!moved) { I32 x, y; glfwGetWindowPos(m_window.get(), &x, &y); glfwSetWindowPos(m_window.get(), ++x, y); moved = true; } } }