Commit 3a4dfe22 authored by Johannes Braun's avatar Johannes Braun
Browse files

Eradicated some C++ issues

parent bceb5936
......@@ -111,12 +111,12 @@ namespace glare
// Connection on the upper side
{
float h1 = m_heights[x][y];
float h2 = m_heights[x + 1][y];
float delta = 2 * offset;
const float h1 = m_heights[x][y];
const float h2 = m_heights[x + 1][y];
const float delta = 2 * offset;
float dy = delta;
float dx = h1 - h2;
const float dy = delta;
const float dx = h1 - h2;
vertex.normal = glm::normalize(glm::vec4{ dx, dy, 0, 0 });
//4
......@@ -150,12 +150,12 @@ namespace glare
// Connection on the right side
{
float h1 = m_heights[x][y];
float h2 = m_heights[x][y + 1];
float delta = 2 * offset;
const float h1 = m_heights[x][y];
const float h2 = m_heights[x][y + 1];
const float delta = 2 * offset;
float dy = delta;
float dz = h1 - h2;
const float dy = delta;
const float dz = h1 - h2;
vertex.normal = glm::normalize(glm::vec4{ 0, dy, dz, 0 });
//8
vertex.position = { size * x - (size / 2) + offset, m_heights[x][y], size * y + (size / 2) - offset, 1 };
......@@ -265,8 +265,8 @@ namespace glare
glm::vec3 Map::getSectorCenter(unsigned x, unsigned z) const
{
float cx = x * (m_sector_size + m_sector_border) + m_sector_size / 2;
float cz = z * (m_sector_size + m_sector_border) + m_sector_size / 2;
const float cx = x * (m_sector_size + m_sector_border) + m_sector_size / 2;
const float cz = z * (m_sector_size + m_sector_border) + m_sector_size / 2;
return glm::vec3(cx, m_heights[x][z], cz);
}
}
......
......@@ -62,7 +62,7 @@ void gui(std::vector<std::string> extensions, std::function<void(const fs::path&
for (auto& p : fs::directory_iterator(root)) {
fs::path path = p;
bool extended = std::binary_search(extensions.begin(), extensions.end(), path.extension().string());
const bool extended = std::binary_search(extensions.begin(), extensions.end(), path.extension().string());
// Either draw directory button or...
if (is_directory(path) && ImGui::Button(path.filename().string().c_str(), ImVec2(ImGui::GetContentRegionAvailWidth()/(5-(i%5)), 32)))
root = path;
......
......@@ -8,7 +8,6 @@
#include <core/rendering/batch_render_list.h>
#include <core/objects/camera.h>
#include "util/files.h"
#include <core/time.h>
using namespace glare;
......
......@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
// Make some ambient sound source
al::listenerf(al::ListenerParam::eGain, 0.02f);
auto audio_buffer = core::global_resources::sounds.get(env_audio_path);
const auto audio_buffer = core::global_resources::sounds.get(env_audio_path);
auto environment_source = core::Context::current().graph()->makeComponent<core::SoundSource>(audio_buffer->id());
environment_source->setLooping(true);
environment_source->play();
......@@ -111,12 +111,12 @@ void keyPress(controls::Key key, controls::KeyMods mods)
void loadScene(const fs::path& path, float scale)
{
// Ain't no need for the last scene anymore.
bool had_player_controller = core::Context::current().graph()->find<component::PlayerController>() != nullptr;
const bool had_player_controller = core::Context::current().graph()->find<component::PlayerController>() != nullptr;
core::Context::current().graph()->clearChildren();
//Initialize some scene graph from an obj file
// Don't use resources here, because of duplicating lights.
if (auto scene = core::Collada().load(path, scale))
if (const auto scene = core::Collada().load(path, scale))
{
core::Context::current().graph()->attach(scene);
}
......@@ -461,7 +461,7 @@ void drawSettingsWindow()
ImGui::Spacing();
std::array<std::string, 3> names{ "Scene Settings", "Sampling and Performance" , "Linespace Thresholds" };
const std::array<std::string, 3> names{ "Scene Settings", "Sampling and Performance" , "Linespace Thresholds" };
static int curr = 0;
ImGui::Tabs(names, curr);
......
......@@ -7,14 +7,12 @@
#include <imgui/imgui_glfw.h>
#include <core/message_tags.h>
#include <core/state.h>
namespace glare::component
{
size_t PlayerController::s_current_id = 0;
size_t PlayerController::m_current_id = 0;
PlayerController::PlayerController()
: SceneComponent("Player Controller"), m_id(s_current_id++)
: SceneComponent("Player Controller"), m_id(m_current_id++)
{
core::Context::current().callbacks().addKeyActionCallback("player_controller" + std::to_string(m_id), std::bind(&PlayerController::onKeyAction, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
core::Context::current().callbacks().addMouseButtonCallback("player_controller" + std::to_string(m_id), std::bind(&PlayerController::onMouseButtonAction, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
......@@ -50,10 +48,11 @@ namespace glare::component
core::Context::current().camera()->owner()->addComponent(detachAs<PlayerController>());
}
} break;
default: break;
}
}
void PlayerController::onKeyAction(controls::Key key, controls::ButtonAction action, controls::KeyMods mods)
void PlayerController::onKeyAction(controls::Key key, controls::ButtonAction action, controls::KeyMods mods) const
{
if (isPossessed() && action == controls::ButtonAction::ePress)
{
......@@ -62,11 +61,12 @@ namespace glare::component
case controls::Key::eEscape:
core::Context::current().window().close();
return;
default: break;
}
}
}
void PlayerController::onMouseButtonAction(controls::MouseButton button, controls::ButtonAction action, controls::KeyMods mods)
void PlayerController::onMouseButtonAction(controls::MouseButton button, controls::ButtonAction action, controls::KeyMods mods) const
{
if (isPossessed() && action == controls::ButtonAction::ePress)
{
......@@ -75,6 +75,7 @@ namespace glare::component
case controls::MouseButton::eRight:
controls::setCursorGrabbed(!controls::isCursorGrabbed());
return;
default: break;
}
}
}
......@@ -110,8 +111,8 @@ namespace glare::component
+ owner()->worldTransform().right() * right * m_speed * core::Time::deltaTime()
+ owner()->worldTransform().up() * up * m_speed * core::Time::deltaTime();
const glm::vec2 delta = last_position - controls::getCursorPosition();
last_position = controls::getCursorPosition();
const glm::vec2 delta = m_last_position - controls::getCursorPosition();
m_last_position = controls::getCursorPosition();
if (controls::isCursorGrabbed())
{
......
......@@ -15,8 +15,8 @@ namespace glare::component
void onNotify(msg::id_type id, msg::message_type message) override;
void onKeyAction(controls::Key key, controls::ButtonAction action, controls::KeyMods mods);
void onMouseButtonAction(controls::MouseButton button, controls::ButtonAction action, controls::KeyMods mods);
void onKeyAction(controls::Key key, controls::ButtonAction action, controls::KeyMods mods) const;
void onMouseButtonAction(controls::MouseButton button, controls::ButtonAction action, controls::KeyMods mods) const;
bool isPossessed() const;
......@@ -25,10 +25,10 @@ namespace glare::component
void onDebugGui() override;
private:
static size_t s_current_id;
static size_t m_current_id;
size_t m_id;
glm::vec2 last_position;
glm::vec2 m_last_position;
float m_speed = 10.f;
float m_rotation_speed = 1.f;
float m_boost = 8.f;
......
......@@ -20,7 +20,7 @@ namespace glare::core
void SoundSource::onUpdate()
{
glm::vec3 position = owner()->worldTransform().position;
const glm::vec3 position = owner()->worldTransform().position;
al::source3f(m_source, al::SourceParam::ePosition, position);
al::source3f(m_source, al::SourceParam::eVelocity, position - m_last_position);
......
......@@ -113,7 +113,7 @@ namespace glare::core
// -------------------------------------------------------------------------------------------------------------------------
template<typename T>
Buffer::MappedBuffer<T>::MappedBuffer(Buffer* buffer, gl::BufferMapBit flags, size_t offset)
: m_buffer(buffer), m_data(buffer->map<T>(buffer->size() / sizeof(T), offset, flags))
: m_data(buffer->map<T>(buffer->size() / sizeof(T), offset, flags)), m_buffer(buffer)
{
}
......
......@@ -38,7 +38,7 @@ namespace glare::core
const char *source_chars = precompiled.c_str();
gl::shaderSource(m_handle, 1, &source_chars, nullptr);
static const char* root = "/.";
static auto root = "/.";
if (glfwExtensionSupported("GL_ARB_shading_language_include")) {
gl::compileShaderInclude(m_handle, 1, &root, nullptr);
......
......@@ -5,7 +5,8 @@
#include <util/log.h>
#include <util/files.h>
#include <util/console.h>
#include <util/console.h>
#include <util/opengl.h>
#include "GLFW/glfw3.h"
......
#ifndef INCLUDE_SHADER_SYSTEM_H
#define INCLUDE_SHADER_SYSTEM_H
#include <vector>
#include <util/opengl.h>
#include <vector>
namespace glare::core
{
......
......@@ -314,10 +314,6 @@ namespace glare::core
glGetError();
glGetError();
gl::textureImage(m_handle, t, image.samples(), m_format, { image.width(), image.height(), image.depth() });
auto x = gl::getError();
x = gl::getError();
}
template<typename T> void Texture::set(SubTarget t, const Image<T>& image)
......
......@@ -39,7 +39,7 @@ namespace glare::core
virtual void onTransform() {}
private:
bool m_active;
bool m_active = true;
};
}
......
......@@ -2,7 +2,6 @@
#define INCLUDE_MESH_H
#include <vector>
#include <memory>
#include <core/numeric/geometry.h>
#include <core/base/buffer.h>
......
......@@ -25,8 +25,6 @@ namespace glare::core
m_texture_renderer = TextureRenderer::make(files::shader("screenshader/gbuffer/gbuffer.frag"));
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
m_gbuffer_framebuffer = std::make_shared<Framebuffer>(width, height, samples);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor0);
m_gbuffer_framebuffer->attach(gl::Attachment::eColor1);
......
......@@ -226,7 +226,7 @@ namespace glare::core
int max_width = 0;
line_offsets.push_back(0);
int space = getGlyph(' ').advance.x;
const int space = getGlyph(' ').advance.x;
if (align != Align::eLeft)
{
int current_line = 0;
......
#include "preferences.h"
#include <sstream>
namespace glare::core
{
Preferences::Preferences(fs::path path): m_path(path)
{
m_document.load_file(path.c_str());
}
void Preferences::apply() const
{
m_document.save_file(m_path.c_str());
}
void Preferences::reload()
{
m_document.load_file(m_path.c_str());
}
pugi::xml_attribute Preferences::operator[](const std::string& name) const
{
std::istringstream iss(name);
std::vector<std::string> tokens;
std::string token;
std::string last_token = "";
pugi::xml_node current = m_document.root().first_child();
while (std::getline(iss, token, '/'))
{
if (last_token != "")
{
current = current.find_child_by_attribute("group", "name", last_token.c_str());
}
if (!token.empty())
last_token = token;
}
current = current.find_child_by_attribute("item", "name", last_token.c_str());
return current.attribute("value");
}
pugi::xml_attribute Preferences::operator[](const std::string& name)
{
std::istringstream iss(name);
std::vector<std::string> tokens;
std::string token;
std::string last_token = "";
pugi::xml_node current = m_document.root().first_child();
while (std::getline(iss, token, '/'))
{
if (last_token != "")
{
const auto next = current.find_child_by_attribute("group", "name", last_token.c_str());
if (!next)
{
current = current.append_child("group");
current.append_attribute("name").set_value(last_token.c_str());
}
else
{
current = next;
}
}
if (!token.empty())
last_token = token;
}
const auto next = current.find_child_by_attribute("item", "name", last_token.c_str());
if (!next)
{
current = current.append_child("item");
current.append_attribute("name").set_value(last_token.c_str());
}
else
{
current = next;
}
auto attr = current.attribute("value");
if (!attr)
attr = current.append_attribute("value");
return attr;
}
template <typename T>
void Preferences::set(const std::string& name, T&& value)
{
(*this)[name] = value;
}
}
#ifndef INCLUDE_PREFERENCES_H
#define INCLUDE_PREFERENCES_H
#include <sstream>
#include <pugixml/pugixml.hpp>
#include <util/files.h>
......@@ -9,86 +8,16 @@ namespace glare::core
{
struct Preferences
{
Preferences(fs::path path)
: m_path(path)
{
m_document.load_file(path.c_str());
}
Preferences(fs::path path);
void apply() const
{
m_document.save_file(m_path.c_str());
}
void apply() const;
void reload();
void reload()
{
m_document.load_file(m_path.c_str());
}
const pugi::xml_attribute operator[](const std::string& name) const
{
std::istringstream iss(name);
std::vector<std::string> tokens;
std::string token;
std::string last_token = "";
pugi::xml_node current = m_document.root().first_child();
while (std::getline(iss, token, '/')) {
if (last_token != "") {
current = current.find_child_by_attribute("group", "name", last_token.c_str());
}
if (!token.empty())
last_token = token;
}
current = current.find_child_by_attribute("item", "name", last_token.c_str());
auto attr = current.attribute("value");
return attr;
}
pugi::xml_attribute operator[](const std::string& name)
{
std::istringstream iss(name);
std::vector<std::string> tokens;
std::string token;
std::string last_token = "";
pugi::xml_node current = m_document.root().first_child();
while (std::getline(iss, token, '/')) {
if (last_token != "") {
auto next = current.find_child_by_attribute("group", "name", last_token.c_str());
if (!next) {
current = current.append_child("group");
current.append_attribute("name").set_value(last_token.c_str());
}
else
{
current = next;
}
}
if (!token.empty())
last_token = token;
}
auto next = current.find_child_by_attribute("item", "name", last_token.c_str());
if (!next) {
current = current.append_child("item");
current.append_attribute("name").set_value(last_token.c_str());
}
else
{
current = next;
}
auto attr = current.attribute("value");
if (!attr)
attr = current.append_attribute("value");
return attr;
}
pugi::xml_attribute operator[](const std::string& name) const;
pugi::xml_attribute operator[](const std::string& name);
template<typename T>
void set(const std::string& name, T&& value)
{
(*this)[name] = value;
}
void set(const std::string& name, T&& value);
private:
fs::path m_path;
......
......@@ -58,7 +58,7 @@ namespace glare::core
Context::id_type Context::create()
{
struct unique_context_enable : public Context {};
struct unique_context_enable : Context {};
auto new_context = std::make_unique<unique_context_enable>();
const auto id = new_context->id();
m_contexts.emplace(new_context->id(), std::move(new_context));
......
......@@ -150,7 +150,7 @@ namespace glare::core
template<typename... Args>
Context::id_type Context::create(Args&&... args)
{
struct unique_context_enable : public Context {};
struct unique_context_enable : Context {};
auto new_context = std::make_unique<unique_context_enable>();
m_contexts.emplace(new_context->id(), std::move(new_context));
new_context->initialize(std::forward<Args>(args)...);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment