indentation fix + minor refactor
This commit is contained in:
+56
-56
@@ -12,79 +12,79 @@
|
|||||||
#include "../data/dynamic.h"
|
#include "../data/dynamic.h"
|
||||||
|
|
||||||
toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
toml::Wrapper* create_wrapper(EngineSettings& settings) {
|
||||||
std::unique_ptr<toml::Wrapper> wrapper (new toml::Wrapper());
|
std::unique_ptr<toml::Wrapper> wrapper (new toml::Wrapper());
|
||||||
toml::Section& display = wrapper->add("display");
|
toml::Section& display = wrapper->add("display");
|
||||||
display.add("fullscreen", &settings.display.fullscreen);
|
display.add("fullscreen", &settings.display.fullscreen);
|
||||||
display.add("width", &settings.display.width);
|
display.add("width", &settings.display.width);
|
||||||
display.add("height", &settings.display.height);
|
display.add("height", &settings.display.height);
|
||||||
display.add("samples", &settings.display.samples);
|
display.add("samples", &settings.display.samples);
|
||||||
display.add("swap-interval", &settings.display.swapInterval);
|
display.add("swap-interval", &settings.display.swapInterval);
|
||||||
|
|
||||||
toml::Section& chunks = wrapper->add("chunks");
|
toml::Section& chunks = wrapper->add("chunks");
|
||||||
chunks.add("load-distance", &settings.chunks.loadDistance);
|
chunks.add("load-distance", &settings.chunks.loadDistance);
|
||||||
chunks.add("load-speed", &settings.chunks.loadSpeed);
|
chunks.add("load-speed", &settings.chunks.loadSpeed);
|
||||||
chunks.add("padding", &settings.chunks.padding);
|
chunks.add("padding", &settings.chunks.padding);
|
||||||
|
|
||||||
toml::Section& camera = wrapper->add("camera");
|
toml::Section& camera = wrapper->add("camera");
|
||||||
camera.add("fov-effects", &settings.camera.fovEvents);
|
camera.add("fov-effects", &settings.camera.fovEvents);
|
||||||
camera.add("fov", &settings.camera.fov);
|
camera.add("fov", &settings.camera.fov);
|
||||||
camera.add("shaking", &settings.camera.shaking);
|
camera.add("shaking", &settings.camera.shaking);
|
||||||
camera.add("sensitivity", &settings.camera.sensitivity);
|
camera.add("sensitivity", &settings.camera.sensitivity);
|
||||||
|
|
||||||
toml::Section& graphics = wrapper->add("graphics");
|
toml::Section& graphics = wrapper->add("graphics");
|
||||||
graphics.add("gamma", &settings.graphics.gamma);
|
graphics.add("gamma", &settings.graphics.gamma);
|
||||||
graphics.add("fog-curve", &settings.graphics.fogCurve);
|
graphics.add("fog-curve", &settings.graphics.fogCurve);
|
||||||
graphics.add("backlight", &settings.graphics.backlight);
|
graphics.add("backlight", &settings.graphics.backlight);
|
||||||
graphics.add("frustum-culling", &settings.graphics.frustumCulling);
|
graphics.add("frustum-culling", &settings.graphics.frustumCulling);
|
||||||
graphics.add("skybox-resolution", &settings.graphics.skyboxResolution);
|
graphics.add("skybox-resolution", &settings.graphics.skyboxResolution);
|
||||||
|
|
||||||
toml::Section& debug = wrapper->add("debug");
|
toml::Section& debug = wrapper->add("debug");
|
||||||
debug.add("generator-test-mode", &settings.debug.generatorTestMode);
|
debug.add("generator-test-mode", &settings.debug.generatorTestMode);
|
||||||
debug.add("show-chunk-borders", &settings.debug.showChunkBorders);
|
debug.add("show-chunk-borders", &settings.debug.showChunkBorders);
|
||||||
debug.add("do-write-lights", &settings.debug.doWriteLights);
|
debug.add("do-write-lights", &settings.debug.doWriteLights);
|
||||||
|
|
||||||
toml::Section& ui = wrapper->add("ui");
|
toml::Section& ui = wrapper->add("ui");
|
||||||
ui.add("language", &settings.ui.language);
|
ui.add("language", &settings.ui.language);
|
||||||
return wrapper.release();
|
return wrapper.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string write_controls() {
|
std::string write_controls() {
|
||||||
dynamic::Map obj;
|
dynamic::Map obj;
|
||||||
for (auto& entry : Events::bindings) {
|
for (auto& entry : Events::bindings) {
|
||||||
const auto& binding = entry.second;
|
const auto& binding = entry.second;
|
||||||
|
|
||||||
auto& jentry = obj.putMap(entry.first);
|
auto& jentry = obj.putMap(entry.first);
|
||||||
switch (binding.type) {
|
switch (binding.type) {
|
||||||
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
||||||
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
||||||
default: throw std::runtime_error("unsupported control type");
|
default: throw std::runtime_error("unsupported control type");
|
||||||
}
|
}
|
||||||
jentry.put("code", binding.code);
|
jentry.put("code", binding.code);
|
||||||
}
|
}
|
||||||
return json::stringify(&obj, true, " ");
|
return json::stringify(&obj, true, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_controls(std::string filename, std::string source) {
|
void load_controls(std::string filename, std::string source) {
|
||||||
auto obj = json::parse(filename, source);
|
auto obj = json::parse(filename, source);
|
||||||
for (auto& entry : Events::bindings) {
|
for (auto& entry : Events::bindings) {
|
||||||
auto& binding = entry.second;
|
auto& binding = entry.second;
|
||||||
|
|
||||||
auto jentry = obj->map(entry.first);
|
auto jentry = obj->map(entry.first);
|
||||||
if (jentry == nullptr)
|
if (jentry == nullptr)
|
||||||
continue;
|
continue;
|
||||||
inputtype type;
|
inputtype type;
|
||||||
std::string typestr;
|
std::string typestr;
|
||||||
jentry->str("type", typestr);
|
jentry->str("type", typestr);
|
||||||
|
|
||||||
if (typestr == "keyboard") {
|
if (typestr == "keyboard") {
|
||||||
type = inputtype::keyboard;
|
type = inputtype::keyboard;
|
||||||
} else if (typestr == "mouse") {
|
} else if (typestr == "mouse") {
|
||||||
type = inputtype::mouse;
|
type = inputtype::mouse;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "unknown input type '" << typestr << "'" << std::endl;
|
std::cerr << "unknown input type '" << typestr << "'" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
binding.type = type;
|
binding.type = type;
|
||||||
jentry->num("code", binding.code);
|
jentry->num("code", binding.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,35 +34,25 @@ SlotLayout::SlotLayout(
|
|||||||
slotcallback updateFunc,
|
slotcallback updateFunc,
|
||||||
slotcallback shareFunc,
|
slotcallback shareFunc,
|
||||||
slotcallback rightClick
|
slotcallback rightClick
|
||||||
)
|
) : index(index),
|
||||||
: index(index),
|
position(position),
|
||||||
position(position),
|
background(background),
|
||||||
background(background),
|
itemSource(itemSource),
|
||||||
itemSource(itemSource),
|
updateFunc(updateFunc),
|
||||||
updateFunc(updateFunc),
|
shareFunc(shareFunc),
|
||||||
shareFunc(shareFunc),
|
rightClick(rightClick) {}
|
||||||
rightClick(rightClick) {}
|
|
||||||
|
|
||||||
InventoryBuilder::InventoryBuilder() {
|
InventoryBuilder::InventoryBuilder() {
|
||||||
view = std::make_shared<InventoryView>();
|
view = std::make_shared<InventoryView>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add slots grid to inventory view
|
|
||||||
* @param cols grid columns
|
|
||||||
* @param count total number of grid slots
|
|
||||||
* @param pos position of the first slot of the grid
|
|
||||||
* @param padding additional space around the grid
|
|
||||||
* @param addpanel automatically create panel behind the grid
|
|
||||||
* with size including padding
|
|
||||||
* @param slotLayout slot settings (index and position are ignored)
|
|
||||||
*/
|
|
||||||
void InventoryBuilder::addGrid(
|
void InventoryBuilder::addGrid(
|
||||||
int cols, int count,
|
int cols, int count,
|
||||||
glm::vec2 pos,
|
glm::vec2 pos,
|
||||||
int padding,
|
int padding,
|
||||||
bool addpanel,
|
bool addpanel,
|
||||||
SlotLayout slotLayout)
|
SlotLayout slotLayout
|
||||||
{
|
) {
|
||||||
const int slotSize = InventoryView::SLOT_SIZE;
|
const int slotSize = InventoryView::SLOT_SIZE;
|
||||||
const int interval = InventoryView::SLOT_INTERVAL;
|
const int interval = InventoryView::SLOT_INTERVAL;
|
||||||
|
|
||||||
@@ -88,8 +78,9 @@ void InventoryBuilder::addGrid(
|
|||||||
|
|
||||||
for (int row = 0; row < rows; row++) {
|
for (int row = 0; row < rows; row++) {
|
||||||
for (int col = 0; col < cols; col++) {
|
for (int col = 0; col < cols; col++) {
|
||||||
if (row * cols + col >= count)
|
if (row * cols + col >= count) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
glm::vec2 position (
|
glm::vec2 position (
|
||||||
col * (slotSize + interval) + padding,
|
col * (slotSize + interval) + padding,
|
||||||
row * (slotSize + interval) + padding
|
row * (slotSize + interval) + padding
|
||||||
@@ -122,14 +113,13 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (bound == nullptr)
|
if (bound == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const int slotSize = InventoryView::SLOT_SIZE;
|
||||||
|
|
||||||
ItemStack& stack = *bound;
|
ItemStack& stack = *bound;
|
||||||
|
|
||||||
glm::vec2 pos = calcPos();
|
|
||||||
|
|
||||||
int slotSize = InventoryView::SLOT_SIZE;
|
|
||||||
|
|
||||||
glm::vec4 tint(1.0f);
|
glm::vec4 tint(1.0f);
|
||||||
|
glm::vec2 pos = calcPos();
|
||||||
glm::vec4 color = getColor();
|
glm::vec4 color = getColor();
|
||||||
|
|
||||||
if (hover || highlighted) {
|
if (hover || highlighted) {
|
||||||
tint *= 1.333f;
|
tint *= 1.333f;
|
||||||
color = glm::vec4(1, 1, 1, 0.2f);
|
color = glm::vec4(1, 1, 1, 0.2f);
|
||||||
|
|||||||
@@ -48,13 +48,15 @@ struct SlotLayout {
|
|||||||
slotcallback rightClick;
|
slotcallback rightClick;
|
||||||
int padding = 0;
|
int padding = 0;
|
||||||
|
|
||||||
SlotLayout(int index,
|
SlotLayout(
|
||||||
glm::vec2 position,
|
int index,
|
||||||
bool background,
|
glm::vec2 position,
|
||||||
bool itemSource,
|
bool background,
|
||||||
slotcallback updateFunc,
|
bool itemSource,
|
||||||
slotcallback shareFunc,
|
slotcallback updateFunc,
|
||||||
slotcallback rightClick);
|
slotcallback shareFunc,
|
||||||
|
slotcallback rightClick
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SlotView : public gui::UINode {
|
class SlotView : public gui::UINode {
|
||||||
@@ -135,6 +137,14 @@ class InventoryBuilder {
|
|||||||
public:
|
public:
|
||||||
InventoryBuilder();
|
InventoryBuilder();
|
||||||
|
|
||||||
|
/// @brief Add slots grid to inventory view
|
||||||
|
/// @param cols grid columns
|
||||||
|
/// @param count total number of grid slots
|
||||||
|
/// @param pos position of the first slot of the grid
|
||||||
|
/// @param padding additional space around the grid
|
||||||
|
/// @param addpanel automatically create panel behind the grid
|
||||||
|
/// with size including padding
|
||||||
|
/// @param slotLayout slot settings (index and position are ignored)
|
||||||
void addGrid(
|
void addGrid(
|
||||||
int cols, int count,
|
int cols, int count,
|
||||||
glm::vec2 pos,
|
glm::vec2 pos,
|
||||||
|
|||||||
+42
-42
@@ -7,59 +7,59 @@
|
|||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
|
|
||||||
struct DisplaySettings {
|
struct DisplaySettings {
|
||||||
/* Is window in full screen mode */
|
/// @brief Is window in full screen mode
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
/* Window width (pixels) */
|
/// @brief Window width (pixels)
|
||||||
int width = 1280;
|
int width = 1280;
|
||||||
/* Window height (pixels) */
|
/// @brief Window height (pixels)
|
||||||
int height = 720;
|
int height = 720;
|
||||||
/* Anti-aliasing samples */
|
/// @brief Anti-aliasing samples
|
||||||
int samples = 0;
|
int samples = 0;
|
||||||
/* GLFW swap interval value, 0 - unlimited fps, 1 - vsync*/
|
/// @brief GLFW swap interval value, 0 - unlimited fps, 1 - vsync
|
||||||
int swapInterval = 1;
|
int swapInterval = 1;
|
||||||
/* Window title */
|
/// @brief Window title */
|
||||||
std::string title = "VoxelEngine-Cpp v" +
|
std::string title = "VoxelEngine-Cpp v" +
|
||||||
std::to_string(ENGINE_VERSION_MAJOR) + "." +
|
std::to_string(ENGINE_VERSION_MAJOR) + "." +
|
||||||
std::to_string(ENGINE_VERSION_MINOR);
|
std::to_string(ENGINE_VERSION_MINOR);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ChunksSettings {
|
struct ChunksSettings {
|
||||||
/* Max milliseconds that engine uses for chunks loading only */
|
/// @brief Max milliseconds that engine uses for chunks loading only
|
||||||
uint loadSpeed = 4;
|
uint loadSpeed = 4;
|
||||||
/* Radius of chunks loading zone (chunk is unit) */
|
/// @brief Radius of chunks loading zone (chunk is unit)
|
||||||
uint loadDistance = 22;
|
uint loadDistance = 22;
|
||||||
/* Buffer zone where chunks are not unloading (chunk is unit)*/
|
/// @brief Buffer zone where chunks are not unloading (chunk is unit)
|
||||||
uint padding = 2;
|
uint padding = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CameraSettings {
|
struct CameraSettings {
|
||||||
/* Camera dynamic field of view effects */
|
/// @brief Camera dynamic field of view effects
|
||||||
bool fovEvents = true;
|
bool fovEvents = true;
|
||||||
/* Camera movement shake */
|
/// @brief Camera movement shake
|
||||||
bool shaking = true;
|
bool shaking = true;
|
||||||
/* Camera field of view */
|
/// @brief Camera field of view
|
||||||
float fov = 90.0f;
|
float fov = 90.0f;
|
||||||
/* Camera sensitivity */
|
/// @brief Camera sensitivity
|
||||||
float sensitivity = 2.0f;
|
float sensitivity = 2.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GraphicsSettings {
|
struct GraphicsSettings {
|
||||||
/* Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance.
|
/// @brief Fog opacity is calculated as `pow(depth*k, fogCurve)` where k depends on chunksLoadDistance.
|
||||||
Use values in range [1.0 - 2.0] where 1.0 is linear, 2.0 is quadratic */
|
/// Use values in range [1.0 - 2.0] where 1.0 is linear, 2.0 is quadratic
|
||||||
float fogCurve = 1.6f;
|
float fogCurve = 1.6f;
|
||||||
float gamma = 1.0f;
|
float gamma = 1.0f;
|
||||||
/* Enable blocks backlight to prevent complete darkness */
|
/// @brief Enable blocks backlight to prevent complete darkness
|
||||||
bool backlight = true;
|
bool backlight = true;
|
||||||
/* Enable chunks frustum culling */
|
/// @brief Enable chunks frustum culling */
|
||||||
bool frustumCulling = true;
|
bool frustumCulling = true;
|
||||||
int skyboxResolution = 64 + 32;
|
int skyboxResolution = 64 + 32;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DebugSettings {
|
struct DebugSettings {
|
||||||
/* Turns off chunks saving/loading */
|
/// @brief Turns off chunks saving/loading
|
||||||
bool generatorTestMode = false;
|
bool generatorTestMode = false;
|
||||||
bool showChunkBorders = false;
|
bool showChunkBorders = false;
|
||||||
bool doWriteLights = true;
|
bool doWriteLights = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UiSettings {
|
struct UiSettings {
|
||||||
@@ -68,10 +68,10 @@ struct UiSettings {
|
|||||||
|
|
||||||
struct EngineSettings {
|
struct EngineSettings {
|
||||||
DisplaySettings display;
|
DisplaySettings display;
|
||||||
ChunksSettings chunks;
|
ChunksSettings chunks;
|
||||||
CameraSettings camera;
|
CameraSettings camera;
|
||||||
GraphicsSettings graphics;
|
GraphicsSettings graphics;
|
||||||
DebugSettings debug;
|
DebugSettings debug;
|
||||||
UiSettings ui;
|
UiSettings ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
// some magic code
|
// reduce nesting on next modification
|
||||||
void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||||
const Content* content = level->content;
|
const Content* content = level->content;
|
||||||
auto indices = content->getIndices();
|
auto indices = content->getIndices();
|
||||||
|
|||||||
Reference in New Issue
Block a user