EngineSettings.chunksLoadSpeed; removed unused assets
This commit is contained in:
parent
7730da0056
commit
e437cc99ce
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB |
@ -1,7 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
out vec4 f_color;
|
|
||||||
|
|
||||||
void main(){
|
|
||||||
f_color = vec4(1.0);
|
|
||||||
}
|
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
BIN
res/img.png
BIN
res/img.png
Binary file not shown.
|
Before Width: | Height: | Size: 793 B |
@ -81,7 +81,6 @@ void AssetsLoader::createDefaults(AssetsLoader& loader) {
|
|||||||
|
|
||||||
void AssetsLoader::addDefaults(AssetsLoader& loader) {
|
void AssetsLoader::addDefaults(AssetsLoader& loader) {
|
||||||
loader.add(ASSET_SHADER, "res/main", "main");
|
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/lines", "lines");
|
||||||
loader.add(ASSET_SHADER, "res/ui", "ui");
|
loader.add(ASSET_SHADER, "res/ui", "ui");
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,14 @@ inline int min(int a, int b) {
|
|||||||
return (a < b) ? a : 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;
|
static unsigned int g_seed;
|
||||||
|
|
||||||
inline void fast_srand(int seed) {
|
inline void fast_srand(int seed) {
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
#include "player_control.h"
|
#include "player_control.h"
|
||||||
|
|
||||||
#include "objects/Player.h"
|
#include "Player.h"
|
||||||
#include "physics/PhysicsSolver.h"
|
#include "../physics/PhysicsSolver.h"
|
||||||
#include "physics/Hitbox.h"
|
#include "../physics/Hitbox.h"
|
||||||
#include "lighting/Lighting.h"
|
#include "../lighting/Lighting.h"
|
||||||
#include "world/Level.h"
|
#include "../world/Level.h"
|
||||||
#include "voxels/Block.h"
|
#include "../voxels/Block.h"
|
||||||
#include "voxels/voxel.h"
|
#include "../voxels/voxel.h"
|
||||||
#include "voxels/Chunks.h"
|
#include "../voxels/Chunks.h"
|
||||||
#include "window/Camera.h"
|
#include "../window/Camera.h"
|
||||||
#include "window/Events.h"
|
#include "../window/Events.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#define CROUCH_SPEED_MUL 0.25f
|
#define CROUCH_SPEED_MUL 0.25f
|
||||||
@ -49,12 +49,15 @@ struct EngineSettings {
|
|||||||
int displayHeight;
|
int displayHeight;
|
||||||
int displaySamples;
|
int displaySamples;
|
||||||
const char* title;
|
const char* title;
|
||||||
|
/* Max milliseconds that engine uses for chunks loading only */
|
||||||
|
uint chunksLoadSpeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
Assets* assets;
|
Assets* assets;
|
||||||
Level* level;
|
Level* level;
|
||||||
|
EngineSettings settings;
|
||||||
|
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
float lastTime = 0.0f;
|
float lastTime = 0.0f;
|
||||||
@ -70,6 +73,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Engine::Engine(const EngineSettings& settings) {
|
Engine::Engine(const EngineSettings& settings) {
|
||||||
|
this->settings = settings;
|
||||||
|
|
||||||
Window::initialize(settings.displayWidth, settings.displayHeight, settings.title, settings.displaySamples);
|
Window::initialize(settings.displayWidth, settings.displayHeight, settings.title, settings.displaySamples);
|
||||||
|
|
||||||
assets = new Assets();
|
assets = new Assets();
|
||||||
@ -117,7 +122,7 @@ void Engine::updateHotkeys() {
|
|||||||
level->player->debug = !level->player->debug;
|
level->player->debug = !level->player->debug;
|
||||||
}
|
}
|
||||||
if (Events::jpressed(GLFW_KEY_F5)) {
|
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];
|
shared_ptr<Chunk> chunk = level->chunks->chunks[i];
|
||||||
if (chunk != nullptr && chunk->isReady()) {
|
if (chunk != nullptr && chunk->isReady()) {
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
@ -140,7 +145,7 @@ void Engine::mainloop() {
|
|||||||
updateHotkeys();
|
updateHotkeys();
|
||||||
|
|
||||||
level->update(delta, Events::_cursor_locked);
|
level->update(delta, Events::_cursor_locked);
|
||||||
level->chunksController->loadVisible(world->wfile);
|
level->chunksController->update(settings.chunksLoadSpeed);
|
||||||
|
|
||||||
worldRenderer.draw(camera, occlusion);
|
worldRenderer.draw(camera, occlusion);
|
||||||
hud.draw(level, assets);
|
hud.draw(level, assets);
|
||||||
@ -172,7 +177,7 @@ Engine::~Engine() {
|
|||||||
int main() {
|
int main() {
|
||||||
setup_definitions();
|
setup_definitions();
|
||||||
try {
|
try {
|
||||||
Engine engine(EngineSettings{ 1280, 720, 1, "VoxelEngine-Cpp v13" });
|
Engine engine(EngineSettings{ 1280, 720, 1, "VoxelEngine-Cpp v13", 10 });
|
||||||
engine.mainloop();
|
engine.mainloop();
|
||||||
}
|
}
|
||||||
catch (const initialize_error& err) {
|
catch (const initialize_error& err) {
|
||||||
|
|||||||
@ -9,9 +9,11 @@
|
|||||||
#include "../files/WorldFiles.h"
|
#include "../files/WorldFiles.h"
|
||||||
#include "../world/Level.h"
|
#include "../world/Level.h"
|
||||||
#include "../world/World.h"
|
#include "../world/World.h"
|
||||||
|
#include "../maths/voxmaths.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(__MINGW32__)
|
#if defined(_WIN32) && defined(__MINGW32__)
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
@ -20,9 +22,13 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_WORK_PER_FRAME 16
|
||||||
#define MIN_SURROUNDING 9
|
#define MIN_SURROUNDING 9
|
||||||
|
|
||||||
using std::shared_ptr;
|
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){
|
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(){
|
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){
|
bool ChunksController::loadVisible(WorldFiles* worldFiles){
|
||||||
const int w = chunks->w;
|
const int w = chunks->w;
|
||||||
const int d = chunks->d;
|
const int d = chunks->d;
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef VOXELS_CHUNKSCONTROLLER_H_
|
#ifndef VOXELS_CHUNKSCONTROLLER_H_
|
||||||
#define VOXELS_CHUNKSCONTROLLER_H_
|
#define VOXELS_CHUNKSCONTROLLER_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
class Chunks;
|
class Chunks;
|
||||||
class Lighting;
|
class Lighting;
|
||||||
@ -13,10 +15,12 @@ private:
|
|||||||
Level* level;
|
Level* level;
|
||||||
Chunks* chunks;
|
Chunks* chunks;
|
||||||
Lighting* lighting;
|
Lighting* lighting;
|
||||||
|
int64_t avgDurationMcs = 1000;
|
||||||
public:
|
public:
|
||||||
ChunksController(Level* level, Chunks* chunks, Lighting* lighting);
|
ChunksController(Level* level, Chunks* chunks, Lighting* lighting);
|
||||||
~ChunksController();
|
~ChunksController();
|
||||||
|
|
||||||
|
void update(int64_t maxDuration);
|
||||||
bool loadVisible(WorldFiles* worldFiles);
|
bool loadVisible(WorldFiles* worldFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,10 +6,10 @@
|
|||||||
#include "../voxels/Chunks.h"
|
#include "../voxels/Chunks.h"
|
||||||
#include "../voxels/ChunksController.h"
|
#include "../voxels/ChunksController.h"
|
||||||
#include "../voxels/ChunksStorage.h"
|
#include "../voxels/ChunksStorage.h"
|
||||||
#include "../player_control.h"
|
|
||||||
#include "../physics/Hitbox.h"
|
#include "../physics/Hitbox.h"
|
||||||
#include "../physics/PhysicsSolver.h"
|
#include "../physics/PhysicsSolver.h"
|
||||||
#include "../objects/Player.h"
|
#include "../objects/Player.h"
|
||||||
|
#include "../objects/player_control.h"
|
||||||
|
|
||||||
Level::Level(World* world, Player* player, Chunks* chunks, ChunksStorage* chunksStorage, PhysicsSolver* physics, LevelEvents* events) :
|
Level::Level(World* world, Player* player, Chunks* chunks, ChunksStorage* chunksStorage, PhysicsSolver* physics, LevelEvents* events) :
|
||||||
world(world),
|
world(world),
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
#include "world/LevelEvents.h"
|
#include "world/LevelEvents.h"
|
||||||
#include "objects/Player.h"
|
#include "objects/Player.h"
|
||||||
#include "assets/Assets.h"
|
#include "assets/Assets.h"
|
||||||
#include "player_control.h"
|
#include "objects/player_control.h"
|
||||||
|
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user