mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
fix: attempting to build lights in non-local players chunk matrices
This commit is contained in:
parent
0051f06e46
commit
3308a61d56
4 changed files with 23 additions and 9 deletions
|
|
@ -33,7 +33,11 @@ ChunksController::ChunksController(Level& level)
|
|||
ChunksController::~ChunksController() = default;
|
||||
|
||||
void ChunksController::update(
|
||||
int64_t maxDuration, int loadDistance, uint padding, Player& player
|
||||
int64_t maxDuration,
|
||||
int loadDistance,
|
||||
uint padding,
|
||||
Player& player,
|
||||
bool isLocalPlayer
|
||||
) const {
|
||||
const auto& position = player.getPosition();
|
||||
int centerX = floordiv<CHUNK_W>(glm::floor(position.x));
|
||||
|
|
@ -50,7 +54,7 @@ void ChunksController::update(
|
|||
|
||||
for (uint i = 0; i < MAX_WORK_PER_FRAME; i++) {
|
||||
timeutil::Timer timer;
|
||||
if (loadVisible(player, padding)) {
|
||||
if (loadVisible(player, padding, isLocalPlayer)) {
|
||||
int64_t mcs = timer.stop();
|
||||
if (mcstotal + mcs < maxDuration * 1000) {
|
||||
mcstotal += mcs;
|
||||
|
|
@ -77,7 +81,9 @@ bool ChunksController::isInLoadingZone(
|
|||
return distance < minDistance;
|
||||
}
|
||||
|
||||
bool ChunksController::loadVisible(const Player& player, uint padding) const {
|
||||
bool ChunksController::loadVisible(
|
||||
const Player& player, uint padding, bool isLocalPlayer
|
||||
) const {
|
||||
auto& chunks = *player.chunks;
|
||||
int sizeX = chunks.getWidth();
|
||||
int sizeY = chunks.getHeight();
|
||||
|
|
@ -113,7 +119,7 @@ bool ChunksController::loadVisible(const Player& player, uint padding) const {
|
|||
auto& chunk = chunks.getChunks()[index];
|
||||
if (chunk != nullptr) {
|
||||
if (chunk->flags.loaded && !chunk->flags.lighted) {
|
||||
if (buildLights(player, chunk)) {
|
||||
if (isLocalPlayer && buildLights(player, chunk)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ private:
|
|||
std::unique_ptr<WorldGenerator> generator;
|
||||
|
||||
/// @brief Process one chunk: load it or calculate lights for it
|
||||
bool loadVisible(const Player& player, uint padding) const;
|
||||
bool loadVisible(const Player& player, uint padding, bool isLocalPlayer) const;
|
||||
bool buildLights(const Player& player, const std::shared_ptr<Chunk>& chunk) const;
|
||||
void createChunk(const Player& player, int x, int y) const;
|
||||
public:
|
||||
|
|
@ -29,7 +29,11 @@ public:
|
|||
|
||||
/// @param maxDuration milliseconds reserved for chunks loading
|
||||
void update(
|
||||
int64_t maxDuration, int loadDistance, uint padding, Player& player
|
||||
int64_t maxDuration,
|
||||
int loadDistance,
|
||||
uint padding,
|
||||
Player& player,
|
||||
bool isLocalPlayer
|
||||
) const;
|
||||
|
||||
bool isInLoadingZone(const Player& player, uint padding, int x, int z) const;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ LevelController::LevelController(
|
|||
settings(engine.getSettings()),
|
||||
level(std::move(levelPtr)),
|
||||
chunks(std::make_unique<ChunksController>(*level)),
|
||||
playerTickClock(20, 3) {
|
||||
playerTickClock(20, 3),
|
||||
clientPlayer(clientPlayer) {
|
||||
|
||||
level->events->listen(LevelEventType::CHUNK_PRESENT, [](auto, Chunk* chunk) {
|
||||
scripting::on_chunk_present(*chunk, chunk->flags.loaded);
|
||||
|
|
@ -61,7 +62,7 @@ LevelController::LevelController(
|
|||
player->chunks->configure(
|
||||
std::floor(position.x), std::floor(position.z), 1
|
||||
);
|
||||
chunks->update(16, 1, 0, *player);
|
||||
chunks->update(16, 1, 0, *player, player.get() == clientPlayer);
|
||||
if (player->chunks->get(
|
||||
std::floor(position.x), 0, std::floor(position.z)
|
||||
)) {
|
||||
|
|
@ -91,7 +92,8 @@ void LevelController::update(float delta, bool pause) {
|
|||
settings.chunks.loadSpeed.get(),
|
||||
settings.chunks.loadDistance.get(),
|
||||
settings.chunks.padding.get(),
|
||||
*player
|
||||
*player,
|
||||
player.get() == clientPlayer
|
||||
);
|
||||
}
|
||||
if (!pause) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ class LevelController {
|
|||
std::unique_ptr<ChunksController> chunks;
|
||||
|
||||
util::Clock playerTickClock;
|
||||
|
||||
Player* clientPlayer;
|
||||
public:
|
||||
CallbacksSet<> preQuitCallbacks;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue