[Config] No clip mode added. [SettingsMenuState] Small refactoring.

This commit is contained in:
Quentin Bazin 2019-01-19 15:21:49 +01:00
parent b86f8d719a
commit f146e2d5da
9 changed files with 26 additions and 28 deletions

View File

@ -34,6 +34,8 @@ class SettingsMenuState : public gk::ApplicationState {
void addGraphicsButtons();
void addInputButtons();
void addToggleButton(u16 x, u16 y, const std::string &text, bool &configOption, bool worldReloadRequested = false);
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
MenuWidget m_menuWidget{1, 8};

View File

@ -34,8 +34,8 @@ class ClientChunk : public Chunk {
ChunkBuilder m_builder;
std::array<gk::VertexBuffer, ChunkBuilder::layers> m_vbo;
std::array<std::size_t, ChunkBuilder::layers> m_verticesCount;
std::array<gk::VertexBuffer, ChunkBuilder::layers> m_vbo{};
std::array<std::size_t, ChunkBuilder::layers> m_verticesCount{};
};
#endif // CLIENTCHUNK_HPP_

View File

@ -40,7 +40,7 @@ class ClientWorld : public gk::IDrawable {
// FIXME: Duplicated with those in ServerWorld
const s32 m_width = 32;
const s32 m_height = 8;
const s32 m_height = 4;
const s32 m_depth = 32;
std::vector<std::unique_ptr<ClientChunk>> m_chunks;

View File

@ -67,11 +67,8 @@ void SettingsMenuState::addMainButtons() {
}
void SettingsMenuState::addGameplayButtons() {
m_menuWidget.addButton(0, 0, std::string("Fly Mode: ") + (Config::isFlyModeEnabled ? "ON" : "OFF"), [] (TextButton &button) {
Config::isFlyModeEnabled = !Config::isFlyModeEnabled;
button.setText(std::string("Fly Mode: ") + (Config::isFlyModeEnabled ? "ON" : "OFF"));
World::isReloadRequested = true;
});
addToggleButton(0, 0, "Fly Mode", Config::isFlyModeEnabled, false);
addToggleButton(0, 1, "No Clip", Config::isNoClipEnabled, false);
m_menuWidget.addButton(0, 7, "Done", [this] (TextButton &) {
m_menuWidget.reset(1, 8);
@ -86,23 +83,9 @@ void SettingsMenuState::addGraphicsButtons() {
World::isReloadRequested = true;
});
m_menuWidget.addButton(0, 1, std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF"), [] (TextButton &button) {
Config::isSmoothLightingEnabled = !Config::isSmoothLightingEnabled;
button.setText(std::string("Smooth Lighting: ") + (Config::isSmoothLightingEnabled ? "ON" : "OFF"));
World::isReloadRequested = true;
});
m_menuWidget.addButton(0, 2, std::string("Ambient Occlusion: ") + (Config::isAmbientOcclusionEnabled ? "ON" : "OFF"), [] (TextButton &button) {
Config::isAmbientOcclusionEnabled = !Config::isAmbientOcclusionEnabled;
button.setText(std::string("Ambient Occlusion: ") + (Config::isAmbientOcclusionEnabled ? "ON" : "OFF"));
World::isReloadRequested = true;
});
m_menuWidget.addButton(0, 3, std::string("Wireframe Mode: ") + (Config::isWireframeModeEnabled ? "ON" : "OFF"), [] (TextButton &button) {
Config::isWireframeModeEnabled = !Config::isWireframeModeEnabled;
button.setText(std::string("Wireframe Mode: ") + (Config::isWireframeModeEnabled ? "ON" : "OFF"));
World::isReloadRequested = true;
});
addToggleButton(0, 1, "Smooth Lighting", Config::isSmoothLightingEnabled, true);
addToggleButton(0, 2, "Ambient Occlusion", Config::isAmbientOcclusionEnabled, true);
addToggleButton(0, 3, "Wireframe Mode", Config::isWireframeModeEnabled, false);
m_menuWidget.addButton(0, 4, "GUI Scale: " + std::to_string(GUI_SCALE), [] (TextButton &button) {
GUI_SCALE = 1 + (GUI_SCALE + 1) % 3;
@ -127,6 +110,16 @@ void SettingsMenuState::addInputButtons() {
});
}
void SettingsMenuState::addToggleButton(u16 x, u16 y, const std::string &text, bool &configOption, bool worldReloadRequested) {
m_menuWidget.addButton(x, y, text + ": " + (configOption ? "ON" : "OFF"), [=, &configOption] (TextButton &button) {
configOption = !configOption;
button.setText(text + ": " + (configOption ? "ON" : "OFF"));
if (worldReloadRequested)
World::isReloadRequested = true;
});
}
void SettingsMenuState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (m_parent)
target.draw(*m_parent, states);

View File

@ -23,7 +23,7 @@ void ClientChunk::update() {
}
void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u8 layer) const {
if (m_verticesCount.at(layer) == 0) return;
if (m_verticesCount.size() <= layer || m_verticesCount.at(layer) == 0) return;
states.texture = &m_texture;

View File

@ -102,6 +102,7 @@ void Player::updatePosition(const ClientWorld &world) {
m_velocity.y = -m_jumpSpeed;
}
if (!Config::isNoClipEnabled)
checkCollisions(world);
m_x += m_velocity.x;

View File

@ -39,6 +39,7 @@ extern int GUI_SCALE; // FIXME
namespace Config {
// Gameplay
extern bool isFlyModeEnabled;
extern bool isNoClipEnabled;
// Graphics
extern bool isSmoothLightingEnabled;

View File

@ -17,6 +17,7 @@ int GUI_SCALE = 3; // FIXME
// Gameplay
bool Config::isFlyModeEnabled = false;
bool Config::isNoClipEnabled = false;
// Graphics
bool Config::isSmoothLightingEnabled = true;

View File

@ -40,7 +40,7 @@ class ServerWorld {
private:
// FIXME: Duplicated with those in ClientWorld
const s32 m_width = 32;
const s32 m_height = 8;
const s32 m_height = 4;
const s32 m_depth = 32;
std::vector<std::unique_ptr<ServerChunk>> m_chunks;