Commit 25e1e19d authored by Johannes Braun's avatar Johannes Braun
Browse files

Node class cleanup and ReSharper refactoring with removal of redundant includes.

parent 62a50c97
......@@ -35,8 +35,8 @@ int main(int argc, char* argv[])
//Attach plane as child in front of the camera.
auto plane = core::Resources::getInstance().getColladaMesh(files::asset("meshes/scenery/TY_Plane.dae"), "Cube_001");
cam_node->attach(plane);
plane->transform()->position = { 0, -2.f, -15 };
plane->transform()->rotate({ glm::radians(-90.f), glm::radians(90.f), 0.f });
plane->transform.position = { 0, -2.f, -15 };
plane->transform.rotate({ glm::radians(-90.f), glm::radians(90.f), 0.f });
// add the terrain
auto terrain_node = std::make_shared<core::GraphNode>("terrain");
......@@ -49,8 +49,8 @@ int main(int argc, char* argv[])
// Sun light source
auto sun_node = std::make_shared<core::GraphNode>("light_sun");
sun_node->transform()->rotate({ glm::radians(80.f), 0, 0 });
auto light_sun = sun_node->makeComponent<core::LightComponent>(color::rgba32f{ 0.4f, 0.4f, 0.4f, 1.f }, core::Attenuation{ 1,0,0 }, core::LightParameters::makeDirectionalLight(0.1f));
sun_node->transform.rotate({ glm::radians(80.f), 0, 0 });
auto light_sun = sun_node->makeComponent<core::LightComponent>(color::rgba32f{ 0.4f, 0.4f, 0.4f, 1.f }, core::LightParameters::makeDirectionalLight(0.1f));
// Make Environment lighting node
auto lighting_node = std::make_shared<core::GraphNode>("environment");
......@@ -62,11 +62,11 @@ int main(int argc, char* argv[])
{
// Rotate the sun on keypress
if (controls::keyState(controls::Key::eF) == controls::ButtonAction::ePress) {
sun_node->transform()->rotate({ glm::radians(80.f)*delta, 0, 0 });
sun_node->transform.rotate({ glm::radians(80.f)*delta, 0, 0 });
}
// Set the light position to the player camera position
lighting_node->transform()->position = core::state::camera->getOwner()->c_transform().position * glm::vec3(1, 0, 1);
lighting_node->transform.position = core::state::camera->owner()->transform.position * glm::vec3(1, 0, 1);
core::state::gbuffer->activate();
glare::core::state::graph_root->draw();
......
......@@ -250,7 +250,7 @@ namespace glare
return m_mesh_renderer;
}
std::shared_ptr<core::Material> Map::makeMaterial()
std::shared_ptr<core::Material> Map::makeMaterial() const
{
std::shared_ptr<core::Material> material = std::make_shared<core::Material>("terrain");
material->base.value = color::preset::white.rgb;
......
......@@ -22,7 +22,7 @@ namespace glare
glm::vec3 getSectorCenter(unsigned x, unsigned z) const;
private:
std::shared_ptr<core::Material> makeMaterial();
std::shared_ptr<core::Material> makeMaterial() const;
std::shared_ptr<core::MeshRenderer> m_mesh_renderer;
std::vector<std::vector<float>> m_heights;
......
#include <iostream>
#include <array>
#include <functional>
......
......@@ -19,7 +19,7 @@ int main(int argc, char* argv[])
core::state::skybox->reset(core::Skybox::collectFilesFrom(files::asset("textures/ryfjallet/")));
// Add a PlayerController to move around
core::state::camera->getOwner()->makeComponent<component::PlayerController>();
core::state::camera->owner()->makeComponent<component::PlayerController>();
// Create a Pathtracer and all needed stuff for it from the graph
const auto pathtracer = std::make_unique<raytrace::Pathtracer>(core::state::graph_root);
......
#include <imgui/imgui_glfw.h>
#include <util/files.h>
#include <util/console.h>
......@@ -28,7 +30,7 @@ const fs::path engine_settings_path = files::asset("/preferences/default.xml");
const fs::path pathtracer_settings_path = files::asset("/preferences/pathtracer_default.xml");
const fs::path skybox_files_path = files::asset("/textures/ryfjallet/");
const fs::path env_audio_path = files::asset("/audio/env.wav");
const fs::path startup_scene_path = files::asset("/meshes/scenery/sphere.dae");
const fs::path startup_scene_path = files::asset("/meshes/scenery/House.dae");
// My little all-enclosing pathtracer pointer
std::unique_ptr<raytrace::Pathtracer> pathtracer = nullptr;
......@@ -132,7 +134,7 @@ void loadScene(const fs::path& path, float scale)
console::prompt("Scene could not be loaded: " + path.string() + ". Press [ENTER] to exit.", 1);
}
std::shared_ptr<core::GraphNode> cam_node = core::state::graph_root->findFirstWithComponent<core::Camera>();
std::shared_ptr<core::GraphNode> cam_node = core::state::graph_root->find<core::Camera>();
if (cam_node)
{
//If there are any cameras in the collada file, take the first one.
......
......@@ -37,11 +37,9 @@ namespace glare
{
case tags::camera:
{
if (getOwner() != core::state::camera->getOwner())
if (owner() != core::state::camera->owner())
{
auto shared = std::static_pointer_cast<PlayerController>(shared_from_this());
getOwner()->removeComponent(shared);
core::state::camera->getOwner()->addComponent(shared);
core::state::camera->owner()->addComponent(detachAs<PlayerController>());
}
} break;
}
......@@ -86,7 +84,7 @@ namespace glare
void PlayerController::update()
{
auto transform = m_owner.lock()->transform();
auto&& transform = owner()->transform;
float forward = static_cast<float>((controls::keyState(controls::Key::eW) == controls::ButtonAction::ePress) -
(controls::keyState(controls::Key::eS) == controls::ButtonAction::ePress));
......@@ -101,18 +99,18 @@ namespace glare
up *= m_boost;
}
transform->position +=
m_owner.lock()->c_worldTransform().forward() * forward * m_speed * core::Time::deltaTime()
+ m_owner.lock()->c_worldTransform().right() * right * m_speed * core::Time::deltaTime()
+ m_owner.lock()->c_worldTransform().up() * up * m_speed * core::Time::deltaTime();
transform.position +=
owner()->worldTransform().forward() * forward * m_speed * core::Time::deltaTime()
+ 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();
if (controls::isCursorGrabbed())
{
transform->rotation = glm::quat(glm::vec3(0.f, glm::radians(delta.x / 10) * m_rotation_speed, 0.f))*m_owner.lock()->c_transform().rotation;
transform->rotation *= glm::quat(glm::vec3(glm::radians(delta.y / 10) * m_rotation_speed, 0.f, 0.f));
transform.rotation = glm::quat(glm::vec3(0.f, glm::radians(delta.x / 10) * m_rotation_speed, 0.f))*owner()->transform.rotation;
transform.rotation *= glm::quat(glm::vec3(glm::radians(delta.y / 10) * m_rotation_speed, 0.f, 0.f));
}
}
}
......
#ifndef __PLAYERCONTROLLER_H
#define __PLAYERCONTROLLER_H
#include <util/messaging.h>
#include <core/graph/component.h>
#include <core/control.h>
......
......@@ -17,7 +17,7 @@ namespace glare
void Rotator::update()
{
getOwner()->transform()->rotate(glm::vec3(0, glm::radians(80.f), 0) * core::Time::deltaTime());
owner()->transform.rotate(glm::vec3(0, glm::radians(80.f), 0) * static_cast<float>(core::Time::deltaTime()));
}
}
}
......@@ -2,7 +2,6 @@
#define __ANIMATIONMANAGER_H
// --------------- STDLIB ---------------
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
......
......@@ -22,7 +22,7 @@ namespace glare
void SoundSource::update()
{
glm::vec3 position = getOwner()->c_worldTransform().position;
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);
......@@ -30,17 +30,17 @@ namespace glare
m_last_position = position;
}
void SoundSource::play()
void SoundSource::play() const
{
al::sourcePlay(m_source);
}
void SoundSource::pause()
void SoundSource::pause() const
{
al::sourcePause(m_source);
}
void SoundSource::stop()
void SoundSource::stop() const
{
al::sourceStop(m_source);
}
......
......@@ -4,8 +4,6 @@
#include <util/openal.h>
#include <core/graph/component.h>
#include "sound_buffer.h"
namespace glare
{
namespace core
......@@ -17,9 +15,9 @@ namespace glare
SoundSource(unsigned buffer);
void update() override;
void play();
void pause();
void stop();
void play() const;
void pause() const;
void stop() const;
void setLooping(bool looping);
......
......@@ -2,14 +2,12 @@
#define INCLUDE_FRAMEBUFFER_H
// --- STDLIB ---------------------------------------------
#include <functional>
#include <map>
#include <memory>
// --- EXTERN ---------------------------------------------
#include <util/log.h>
#include <util/opengl.h>
#include <util/templates.h>
// --- INTERN ---------------------------------------------
......@@ -46,7 +44,7 @@ namespace glare
unsigned attachments() const;
unsigned samples() const;
public:
private:
void putAttachment(gl::Attachment attachment, unsigned texture);
gl::handle::framebuffer m_handle;
......
......@@ -29,12 +29,10 @@ namespace glare
throw std::runtime_error(log);
}
else
{
for (auto && shader : shaders)
gl::detachShader(m_handle, shader->id());
Log_Debug << "Program was linked successfully.";
}
for (auto && shader : shaders)
gl::detachShader(m_handle, shader->id());
Log_Debug << "Program was linked successfully.";
collectUniforms();
collectSubroutines(shaders);
......@@ -65,11 +63,10 @@ namespace glare
if (data.size > 1 && std::string(data.name.data() + data.name.length() - 3) == "[0]")
{
const auto idx = data.name.find_last_of('[', 0);
for (int i = 1; i < data.size; ++i)
for (int j = 1; j < data.size; ++j)
{
std::string last_ending = "[" + std::to_string(i-1) + "]";
std::string ending = "[" + std::to_string(i) + "]";
std::string last_ending = "[" + std::to_string(j-1) + "]";
std::string ending = "[" + std::to_string(j) + "]";
data.name = std::string(data.name.data(), data.name.data() + data.name.length() - last_ending.length()) + ending;
data.index = uniformLocation(data.name);
......@@ -160,7 +157,7 @@ namespace glare
return -1;
}
void Program::setSubroutines(gl::ShaderType stage, std::vector<unsigned> indices) const
void Program::setSubroutines(gl::ShaderType stage, std::vector<unsigned> indices)
{
gl::uniformSubroutinesuiv(stage, indices.size(), indices.data());
}
......
......@@ -7,9 +7,9 @@
#include <glm/ext.hpp>
#include <util/opengl.h>
#include <util/files.h>
#include <util/log.h>
#include <core/base/buffer.h>
#include "shader.h"
namespace glare
......@@ -52,10 +52,6 @@ namespace glare
void use() const;
template<typename T> void uniform(const std::string &name, const T& data) const;
template<> void uniform<bool>(const std::string &name, const bool& data) const;
template<> void uniform<glm::bvec2>(const std::string &name, const glm::bvec2& data) const;
template<> void uniform<glm::bvec3>(const std::string &name, const glm::bvec3& data) const;
template<> void uniform<glm::bvec4>(const std::string &name, const glm::bvec4& data) const;
void bindSubroutine(gl::ShaderType stage, const std::string& uniform, const std::string& subroutine);
......@@ -79,12 +75,12 @@ namespace glare
void collectUniforms();
void collectSubroutines(const std::vector<std::shared_ptr<Shader>> &shaders);
void setSubroutines(gl::ShaderType stage, std::vector<unsigned> indices) const;
static void setSubroutines(gl::ShaderType stage, std::vector<unsigned> indices);
void uniformUpdate(gl::UniformType type, unsigned location, const void* data) const;
unsigned invocations(unsigned global, unsigned local);
static unsigned invocations(unsigned global, unsigned local);
template<typename T>
bool typeValid(gl::UniformType type) const;
static bool typeValid(gl::UniformType type);
gl::handle::shader_program m_handle;
std::map<std::string, UniformInfo> m_uniforms;
......@@ -93,22 +89,22 @@ namespace glare
std::map<gl::ShaderType, std::vector<unsigned>> m_subroutine_bindings;
};
template<> void Program::uniform<bool>(const std::string &name, const bool& data) const
template<> inline void Program::uniform<bool>(const std::string &name, const bool& data) const
{
uniform<int>(name, int(data));
}
template<> void Program::uniform<glm::bvec2>(const std::string &name, const glm::bvec2& data) const
template<> inline void Program::uniform<glm::bvec2>(const std::string &name, const glm::bvec2& data) const
{
uniform<glm::ivec2>(name, data);
}
template<> void Program::uniform<glm::bvec3>(const std::string &name, const glm::bvec3& data) const
template<> inline void Program::uniform<glm::bvec3>(const std::string &name, const glm::bvec3& data) const
{
uniform<glm::ivec3>(name, data);
}
template<> void Program::uniform<glm::bvec4>(const std::string &name, const glm::bvec4& data) const
template<> inline void Program::uniform<glm::bvec4>(const std::string &name, const glm::bvec4& data) const
{
uniform<glm::ivec4>(name, data);
}
......@@ -130,7 +126,7 @@ namespace glare
}
template<typename T>
bool Program::typeValid(gl::UniformType type) const
bool Program::typeValid(gl::UniformType type)
{
switch (type)
{
......
......@@ -5,6 +5,9 @@
#include "shader_system.h"
#include <gl/glew.h>
#include <GLFW/glfw3.h>
namespace glare
{
namespace core
......@@ -77,9 +80,9 @@ namespace glare
return m_identifier;
}
const gl::ShaderType Shader::type() const
gl::ShaderType Shader::type() const
{
return m_type;
}
}
}
\ No newline at end of file
}
......@@ -2,14 +2,9 @@
#define INCLUDE_SHADER_H
#include <filesystem>
#include <memory>
#include <string>
#include <util/opengl.h>
#include "buffer.h"
#include "vertex_array.h"
namespace glare
{
namespace core
......@@ -32,7 +27,7 @@ namespace glare
unsigned id() const;
const std::string& identifierName() const;
const gl::ShaderType type() const;
gl::ShaderType type() const;
private:
std::string m_identifier;
......
......@@ -7,6 +7,9 @@
#include <util/files.h>
#include <util/console.h>
#include <gl/glew.h>
#include "GLFW/glfw3.h"
namespace glare
{
namespace core
......@@ -74,7 +77,6 @@ namespace glare
static std::string str_required = "require";
std::string current_requirement = "";
ExtensionRequirement current_enum_requirement;
for (const auto &character : source)
{
......@@ -136,7 +138,6 @@ namespace glare
requirement_stream << character;
state = ExtensionParseState::eRequirementCheckForm;
current_requirement = character == 'e' ? str_enabled : str_required;
current_enum_requirement = character == 'e' ? ExtensionRequirement::eEnabled : ExtensionRequirement::eRequired;
current_requirement_position = 0;
break;
}
......@@ -166,7 +167,7 @@ namespace glare
state = ExtensionParseState::eNone;
break;
}
else if (requirement_stream.str() == str_required)
if (requirement_stream.str() == str_required)
{
std::string extension_name = input_stream.str();
if (!glfwExtensionSupported(extension_name.c_str()))
......@@ -182,14 +183,11 @@ namespace glare
state = ExtensionParseState::eNone;
break;
}
else
{
//Uhm... not inside the requirement string, nor at the current req. string position, nor equal to any requirement.
//So clearly malformed.
Log_Error << "Extension malformed.";
close_loop = true;
break;
}
//Uhm... not inside the requirement string, nor at the current req. string position, nor equal to any requirement.
//So clearly malformed.
Log_Error << "Extension malformed.";
close_loop = true;
break;
default:
break;
......
#ifndef INCLUDE_SHADER_SYSTEM_H
#define INCLUDE_SHADER_SYSTEM_H
#include <string>
#include <vector>
#include <util/opengl.h>
......
......@@ -12,7 +12,7 @@ namespace glare
gl::bindVertexArray(m_handle);
}
void VertexArray::unbind() const
void VertexArray::unbind()
{
gl::bindVertexArray(0);
}
......@@ -22,7 +22,7 @@ namespace glare
return m_handle;
}
void VertexArray::linkAttribute(unsigned buffer, size_t buffer_offset, unsigned attribute, size_t components, gl::Type type, bool normalized, size_t stride, size_t start_index)
void VertexArray::linkAttribute(unsigned buffer, size_t buffer_offset, unsigned attribute, size_t components, gl::Type type, bool normalized, size_t stride, size_t start_index) const
{
gl::enableVertexArrayAttrib(m_handle, attribute);
gl::vertexArrayVertexBuffer(m_handle, attribute, buffer, buffer_offset, stride);
......@@ -30,12 +30,12 @@ namespace glare
gl::vertexArrayAttribBinding(m_handle, attribute, attribute);
}
void VertexArray::linkAttribute(unsigned buffer, unsigned attribute, size_t components, gl::Type type, bool normalize, size_t stride, size_t first_index)
void VertexArray::linkAttribute(unsigned buffer, unsigned attribute, size_t components, gl::Type type, bool normalize, size_t stride, size_t first_index) const
{
linkAttribute(buffer, 0, attribute, components, type, normalize, stride, first_index);
}
void VertexArray::linkIndices(unsigned buffer)
void VertexArray::linkIndices(unsigned buffer) const
{
gl::vertexArrayElementBuffer(m_handle, buffer);
}
......
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