feat: move players to world instead of main

This commit is contained in:
2026-03-13 16:35:36 +08:00
parent 32d617b440
commit 98967275ff
6 changed files with 40 additions and 18 deletions

View File

@@ -2,7 +2,10 @@
#include <Cubed/gameplay/player.hpp>
Player::Player() {
Player::Player(const World& world, const std::string& name) :
m_world(world),
m_name(name)
{
}
@@ -18,10 +21,6 @@ const MoveState& Player::get_move_state() const {
return m_move_state;
}
void Player::init(bool** block_present) {
m_block_present = block_present;
}
void Player::set_player_pos(const glm::vec3& pos) {
m_player_pos = pos;
}

View File

@@ -1,5 +1,7 @@
#include <Cubed/gameplay/player.hpp>
#include <Cubed/gameplay/world.hpp>
#include <Cubed/tools/cubed_assert.hpp>
#include <Cubed/tools/cubed_hash.hpp>
World::World() {
}
@@ -209,6 +211,16 @@ const BlockRenderData& World::get_block_render_data(int world_x, int world_y ,in
return m_block_render_data;
}
Player& World::get_player(const std::string& name){
auto it = m_players.find(HASH::str(name));
if (it == m_players.end()) {
LOG::error("Can't find player {}", name);
CUBED_ASSERT(0);
}
return it->second;
}
void World::init_world() {
for (int s = 0; s < DISTANCE; s++) {
@@ -235,7 +247,8 @@ void World::init_world() {
chunk.gen_vertex_data();
}
// init players
m_players.emplace(HASH::str("TestPlayer"), Player(*this, "TestPlayer"));
}
void World::render() {
@@ -255,4 +268,10 @@ void World::render() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
//LOG::info("Chunk {} {} render finished", pos.x, pos.z);
}
}
void World::update(float delta_time) {
for (auto& player : m_players) {
player.second.update(delta_time);
}
}