EngineSettings.chunksLoadSpeed; removed unused assets

This commit is contained in:
MihailRis 2023-11-06 00:20:58 +03:00
parent 7730da0056
commit e437cc99ce
14 changed files with 55 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

View File

@ -1,7 +0,0 @@
#version 330 core
out vec4 f_color;
void main(){
f_color = vec4(1.0);
}

View File

@ -1,10 +0,0 @@
#version 330 core
layout (location = 0) in vec2 v_position;
uniform float u_ar;
uniform float u_scale;
void main(){
gl_Position = vec4(v_position.x * u_ar * u_scale, v_position.y * u_scale, 0.0, 1.0);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 793 B

View File

@ -81,7 +81,6 @@ void AssetsLoader::createDefaults(AssetsLoader& loader) {
void AssetsLoader::addDefaults(AssetsLoader& loader) {
loader.add(ASSET_SHADER, "res/main", "main");
loader.add(ASSET_SHADER, "res/crosshair", "crosshair");
loader.add(ASSET_SHADER, "res/lines", "lines");
loader.add(ASSET_SHADER, "res/ui", "ui");

View File

@ -25,6 +25,14 @@ inline int min(int a, int b) {
return (a < b) ? a : b;
}
inline int64_t max(int64_t a, int64_t b) {
return (a > b) ? a : b;
}
inline int64_t min(int64_t a, int64_t b) {
return (a < b) ? a : b;
}
static unsigned int g_seed;
inline void fast_srand(int seed) {

View File

@ -1,15 +1,15 @@
#include "player_control.h"
#include "objects/Player.h"
#include "physics/PhysicsSolver.h"
#include "physics/Hitbox.h"
#include "lighting/Lighting.h"
#include "world/Level.h"
#include "voxels/Block.h"
#include "voxels/voxel.h"
#include "voxels/Chunks.h"
#include "window/Camera.h"
#include "window/Events.h"
#include "Player.h"
#include "../physics/PhysicsSolver.h"
#include "../physics/Hitbox.h"
#include "../lighting/Lighting.h"
#include "../world/Level.h"
#include "../voxels/Block.h"
#include "../voxels/voxel.h"
#include "../voxels/Chunks.h"
#include "../window/Camera.h"
#include "../window/Events.h"
#include <GLFW/glfw3.h>
#define CROUCH_SPEED_MUL 0.25f

View File

@ -49,12 +49,15 @@ struct EngineSettings {
int displayHeight;
int displaySamples;
const char* title;
/* Max milliseconds that engine uses for chunks loading only */
uint chunksLoadSpeed;
};
class Engine {
Assets* assets;
Level* level;
EngineSettings settings;
uint64_t frame = 0;
float lastTime = 0.0f;
@ -70,6 +73,8 @@ public:
};
Engine::Engine(const EngineSettings& settings) {
this->settings = settings;
Window::initialize(settings.displayWidth, settings.displayHeight, settings.title, settings.displaySamples);
assets = new Assets();
@ -117,7 +122,7 @@ void Engine::updateHotkeys() {
level->player->debug = !level->player->debug;
}
if (Events::jpressed(GLFW_KEY_F5)) {
for (unsigned i = 0; i < level->chunks->volume; i++) {
for (uint i = 0; i < level->chunks->volume; i++) {
shared_ptr<Chunk> chunk = level->chunks->chunks[i];
if (chunk != nullptr && chunk->isReady()) {
chunk->setModified(true);
@ -140,7 +145,7 @@ void Engine::mainloop() {
updateHotkeys();
level->update(delta, Events::_cursor_locked);
level->chunksController->loadVisible(world->wfile);
level->chunksController->update(settings.chunksLoadSpeed);
worldRenderer.draw(camera, occlusion);
hud.draw(level, assets);
@ -172,7 +177,7 @@ Engine::~Engine() {
int main() {
setup_definitions();
try {
Engine engine(EngineSettings{ 1280, 720, 1, "VoxelEngine-Cpp v13" });
Engine engine(EngineSettings{ 1280, 720, 1, "VoxelEngine-Cpp v13", 10 });
engine.mainloop();
}
catch (const initialize_error& err) {

View File

@ -9,9 +9,11 @@
#include "../files/WorldFiles.h"
#include "../world/Level.h"
#include "../world/World.h"
#include "../maths/voxmaths.h"
#include <iostream>
#include <limits.h>
#include <memory>
#include <chrono>
#if defined(_WIN32) && defined(__MINGW32__)
#define _WIN32_WINNT 0x0501
@ -20,9 +22,13 @@
#include <thread>
#endif
#define MAX_WORK_PER_FRAME 16
#define MIN_SURROUNDING 9
using std::shared_ptr;
using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::microseconds;
ChunksController::ChunksController(Level* level, Chunks* chunks, Lighting* lighting) : level(level), chunks(chunks), lighting(lighting){
@ -31,6 +37,23 @@ ChunksController::ChunksController(Level* level, Chunks* chunks, Lighting* light
ChunksController::~ChunksController(){
}
void ChunksController::update(int64_t maxDuration) {
int64_t mcstotal = 0;
for (uint i = 0; i < MAX_WORK_PER_FRAME; i++) {
auto start = high_resolution_clock::now();
if (loadVisible(level->world->wfile)) {
auto elapsed = high_resolution_clock::now() - start;
int64_t mcs = duration_cast<microseconds>(elapsed).count();
avgDurationMcs = mcs * 0.2 + avgDurationMcs * 0.8;
if (mcstotal + max(avgDurationMcs, mcs) * 2 < maxDuration * 1000) {
mcstotal += mcs;
continue;
}
}
break;
}
}
bool ChunksController::loadVisible(WorldFiles* worldFiles){
const int w = chunks->w;
const int d = chunks->d;

View File

@ -1,6 +1,8 @@
#ifndef VOXELS_CHUNKSCONTROLLER_H_
#define VOXELS_CHUNKSCONTROLLER_H_
#include "../typedefs.h"
class Level;
class Chunks;
class Lighting;
@ -13,10 +15,12 @@ private:
Level* level;
Chunks* chunks;
Lighting* lighting;
int64_t avgDurationMcs = 1000;
public:
ChunksController(Level* level, Chunks* chunks, Lighting* lighting);
~ChunksController();
void update(int64_t maxDuration);
bool loadVisible(WorldFiles* worldFiles);
};

View File

@ -6,10 +6,10 @@
#include "../voxels/Chunks.h"
#include "../voxels/ChunksController.h"
#include "../voxels/ChunksStorage.h"
#include "../player_control.h"
#include "../physics/Hitbox.h"
#include "../physics/PhysicsSolver.h"
#include "../objects/Player.h"
#include "../objects/player_control.h"
Level::Level(World* world, Player* player, Chunks* chunks, ChunksStorage* chunksStorage, PhysicsSolver* physics, LevelEvents* events) :
world(world),

View File

@ -20,7 +20,7 @@
#include "world/LevelEvents.h"
#include "objects/Player.h"
#include "assets/Assets.h"
#include "player_control.h"
#include "objects/player_control.h"
using std::shared_ptr;