-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "engine_files.h" | ||
|
||
#include <filesystem> | ||
|
||
namespace filesystem = std::filesystem; | ||
using std::string; | ||
using filesystem::path; | ||
|
||
path enginefs::get_screenshot_file(string ext) { | ||
path folder = SCREENSHOTS_FOLDER; | ||
if (!filesystem::is_directory(folder)) { | ||
filesystem::create_directory(folder); | ||
} | ||
|
||
auto t = std::time(nullptr); | ||
auto tm = *std::localtime(&t); | ||
|
||
const char* format = "%d-%m-%Y_%H-%M-%S"; | ||
|
||
std::stringstream ss; | ||
ss << std::put_time(&tm, format); | ||
string datetimestr = ss.str(); | ||
|
||
path filename = folder/("screenshot-"+datetimestr+"."+ext); | ||
uint index = 0; | ||
while (filesystem::exists(filename)) { | ||
filename = folder/("screenshot-"+datetimestr+"-"+std::to_string(index)+"."+ext); | ||
index++; | ||
} | ||
return filename; | ||
} | ||
|
||
path enginefs::get_worlds_folder() { | ||
return "worlds"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef FILES_ENGINE_FILES_H_ | ||
#define FILES_ENGINE_FILES_H_ | ||
|
||
#include <string> | ||
#include <filesystem> | ||
|
||
#define SCREENSHOTS_FOLDER "screenshots" | ||
|
||
namespace enginefs { | ||
extern std::filesystem::path get_screenshot_file(std::string ext); | ||
extern std::filesystem::path get_worlds_folder(); | ||
} | ||
|
||
#endif // FILES_ENGINE_FILES_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "screens.h" | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "../window/Camera.h" | ||
#include "../window/Events.h" | ||
#include "../window/input.h" | ||
#include "../assets/Assets.h" | ||
#include "../world/Level.h" | ||
#include "../world/World.h" | ||
#include "../objects/Player.h" | ||
#include "../voxels/ChunksController.h" | ||
#include "../voxels/Chunks.h" | ||
#include "../voxels/Chunk.h" | ||
#include "world_render.h" | ||
#include "hud.h" | ||
#include "gui/GUI.h" | ||
#include "../engine.h" | ||
|
||
using std::shared_ptr; | ||
|
||
LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine), level(level) { | ||
worldRenderer = new WorldRenderer(level, engine->getAssets()); | ||
hud = new HudRenderer(engine->getGUI(), level, engine->getAssets()); | ||
} | ||
|
||
LevelScreen::~LevelScreen() { | ||
delete hud; | ||
delete worldRenderer; | ||
|
||
|
||
World* world = level->world; | ||
|
||
std::cout << "-- saving world" << std::endl; | ||
world->write(level, !engine->getSettings().debug.generatorTestMode); | ||
|
||
delete world; | ||
delete level; | ||
|
||
} | ||
|
||
void LevelScreen::updateHotkeys() { | ||
if (Events::jpressed(keycode::O)) { | ||
occlusion = !occlusion; | ||
} | ||
if (Events::jpressed(keycode::F3)) { | ||
level->player->debug = !level->player->debug; | ||
} | ||
if (Events::jpressed(keycode::F5)) { | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void LevelScreen::update(float delta) { | ||
gui::GUI* gui = engine->getGUI(); | ||
EngineSettings& settings = engine->getSettings(); | ||
|
||
bool inputLocked = hud->isPause() || hud->isInventoryOpen() || gui->isFocusCaught(); | ||
if (!inputLocked) { | ||
updateHotkeys(); | ||
} | ||
level->updatePlayer(delta, !inputLocked, hud->isPause(), !inputLocked); | ||
level->update(); | ||
level->chunksController->update(settings.chunks.loadSpeed); | ||
} | ||
|
||
void LevelScreen::draw(float delta) { | ||
EngineSettings& settings = engine->getSettings(); | ||
Camera* camera = level->player->camera; | ||
|
||
float fovFactor = 18.0f / (float)settings.chunks.loadDistance; | ||
worldRenderer->draw(camera, occlusion, fovFactor, settings.graphics.fogCurve); | ||
hud->draw(); | ||
if (level->player->debug) { | ||
hud->drawDebug( 1 / delta, occlusion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef FRONTEND_SCREENS_H_ | ||
#define FRONTEND_SCREENS_H_ | ||
|
||
#include "../settings.h" | ||
|
||
class Assets; | ||
class Level; | ||
class WorldRenderer; | ||
class HudRenderer; | ||
class Engine; | ||
|
||
|
||
/* Screen is a mainloop state */ | ||
class Screen { | ||
protected: | ||
Engine* engine; | ||
public: | ||
Screen(Engine* engine) : engine(engine) {}; | ||
virtual ~Screen() {}; | ||
virtual void update(float delta) = 0; | ||
virtual void draw(float delta) = 0; | ||
}; | ||
|
||
class LevelScreen : public Screen { | ||
Level* level; | ||
WorldRenderer* worldRenderer; | ||
HudRenderer* hud; | ||
bool occlusion; | ||
void updateHotkeys(); | ||
public: | ||
LevelScreen(Engine* engine, Level* level); | ||
~LevelScreen(); | ||
|
||
void update(float delta) override; | ||
void draw(float delta) override; | ||
}; | ||
|
||
#endif // FRONTEND_SCREENS_H_ |