increased world loading speed and ui scroll

This commit is contained in:
MihailRis 2024-01-19 03:53:30 +03:00
parent ac9d0d7993
commit 1938ccc803
3 changed files with 11 additions and 12 deletions

View File

@ -61,7 +61,7 @@ void Container::act(float delta) {
void Container::scrolled(int value) {
int diff = (actualLength-size().y);
if (diff > 0 && scrollable_) {
scroll += value * 20;
scroll += value * 40;
if (scroll > 0)
scroll = 0;
if (-scroll > diff) {

View File

@ -7,12 +7,11 @@
#include "../voxels/voxel.h"
#include "../voxels/Block.h"
#include "../constants.h"
#include "../typedefs.h"
#include <memory>
#include <iostream>
using std::shared_ptr;
Lighting::Lighting(const Content* content, Chunks* chunks)
: content(content), chunks(chunks) {
auto indices = content->getIndices();
@ -31,7 +30,7 @@ Lighting::~Lighting(){
void Lighting::clear(){
for (unsigned int index = 0; index < chunks->volume; index++){
shared_ptr<Chunk> chunk = chunks->chunks[index];
auto chunk = chunks->chunks[index];
if (chunk == nullptr)
continue;
Lightmap* lightmap = chunk->lightmap;
@ -98,10 +97,10 @@ void Lighting::onChunkLoaded(int cx, int cz){
const Block* const* blockDefs = content->getIndices()->getBlockDefs();
const Chunk* chunk = chunks->getChunk(cx, cz);
for (unsigned int y = 0; y < CHUNK_H; y++){
for (unsigned int z = 0; z < CHUNK_D; z++){
for (unsigned int x = 0; x < CHUNK_W; x++){
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
for (uint y = 0; y < CHUNK_H; y++){
for (uint z = 0; z < CHUNK_D; z++){
for (uint x = 0; x < CHUNK_W; x++){
voxel& vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
const Block* block = blockDefs[vox.id];
int gx = x + cx * CHUNK_W;
int gz = z + cz * CHUNK_D;

View File

@ -40,11 +40,11 @@ void ChunksController::update(int64_t maxDuration) {
timeutil::Timer timer;
if (loadVisible()) {
int64_t mcs = timer.stop();
avgDurationMcs = mcs * 0.2 + avgDurationMcs * 0.8;
if (mcstotal + max(avgDurationMcs, mcs) * 2 < maxDuration * 1000) {
if (mcstotal + mcs * 2 < maxDuration * 1000) {
mcstotal += mcs;
continue;
}
mcstotal += mcs;
}
break;
}
@ -74,8 +74,8 @@ bool ChunksController::loadVisible(){
if (surrounding == MIN_SURROUNDING && !chunk->isLighted()) {
if (!chunk->isLoadedLights()) {
lighting->buildSkyLight(chunk->x, chunk->z);
}
lighting->onChunkLoaded(chunk->x, chunk->z);
lighting->onChunkLoaded(chunk->x, chunk->z);
}
chunk->setLighted(true);
return true;
}