23 lines
743 B
C++
23 lines
743 B
C++
#include <cmath>
|
|
#include "game.h"
|
|
#include "bettola/game/chunk.h"
|
|
|
|
void Game::update_player_chunks(void) {
|
|
const int chunk_width = BettolaLib::Game::CHUNK_WIDTH - 1;
|
|
const int chunk_height = BettolaLib::Game::CHUNK_HEIGHT - 1;
|
|
|
|
for(Player* player : _players) {
|
|
const auto& pos = player->get_position();
|
|
|
|
/* Calculate player's current chunk coords. */
|
|
int chunk_x = floor(pos.x / chunk_width);
|
|
int chunk_z = floor(pos.z / chunk_height);
|
|
|
|
/* If they have moved into a new chunk, send them the new surrounding chunks. */
|
|
if(chunk_z != player->get_chunk_x() || chunk_z != player->get_chunk_z()) {
|
|
player->set_chunk_pos(chunk_x, chunk_z);
|
|
_send_chunks_around(player, chunk_x, chunk_z);
|
|
}
|
|
}
|
|
}
|