Skip to content

Commit

Permalink
Форматирование кода и т.д.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyaalabai committed Jun 24, 2024
1 parent 0253030 commit e4019b3
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 125 deletions.
6 changes: 3 additions & 3 deletions firesteel/includes/firesteel/input/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ class Keyboard {
/// <param name="t_mods">Modifier.</param>
static void key_callback(GLFWwindow* t_window, int t_key, int t_scan_code, int t_action, int t_mods) {
//Check action.
if (t_key == -1) return;
if (t_action != GLFW_RELEASE) {
if (!m_keys[t_key]) m_keys[t_key] = true;
if(t_key == -1) return;
if(t_action != GLFW_RELEASE) {
if(!m_keys[t_key]) m_keys[t_key] = true;
}
else m_keys[t_key] = false;
//Detect if key is pressed continuously.
Expand Down
6 changes: 3 additions & 3 deletions firesteel/includes/firesteel/input/mouse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Mouse {
m_x = t_x;
m_y = t_y;
//Check if first mouse button.
if (m_first_move) {
if(m_first_move) {
m_old_x = t_x;
m_old_y = t_y;
m_first_move = false;
Expand All @@ -36,8 +36,8 @@ class Mouse {
/// <param name="t_mods">Modifiers.</param>
static void button_callback(GLFWwindow* t_window, int t_button, int t_action, int t_mods) {
//Check action.
if (t_action != GLFW_RELEASE) {
if (!m_buttons[t_button]) m_buttons[t_button] = true;
if(t_action != GLFW_RELEASE) {
if(!m_buttons[t_button]) m_buttons[t_button] = true;
}
else m_buttons[t_button] = false;
//Detect if button is pressed continuously.
Expand Down
2 changes: 1 addition & 1 deletion firesteel/includes/firesteel/log.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef LOG_H
#define LOG_H

#include <string>
#include <sstream>
#include <string>

namespace firesteel {

Expand Down
4 changes: 2 additions & 2 deletions firesteel/includes/firesteel/procedural/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace firesteel {
};
//Indicies.
std::vector<unsigned int> indicies(6);
for (unsigned int i = 0; i < 6; i++)
for(unsigned int i = 0; i < 6; i++)
indicies[i] = i;
return firesteel::Mesh(firesteel::Vertex::generate_list(vertices, 6), indicies);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace firesteel {
};
//Indicies.
std::vector<unsigned int> indicies(36);
for (unsigned int i = 0; i < 36; i++)
for(unsigned int i = 0; i < 36; i++)
indicies[i] = i;
return firesteel::Mesh(firesteel::Vertex::generate_list(vertices, 36), indicies);
}
Expand Down
44 changes: 27 additions & 17 deletions firesteel/includes/firesteel/rendering/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MATERIAL_H

#include "../math.hpp"
#include "shader.hpp"
#include "../utils.hpp"
#include <fstream>
#include "../json.hpp"
Expand All @@ -16,6 +17,14 @@ namespace firesteel {
std::string name = "New Material";
bool usable = true;

/// <summary>
/// Destroy shader (cleanup).
/// </summary>
void remove() { shader.remove(); }
/// <summary>
/// Load material properties from file.
/// </summary>
/// <param name="t_mat_file">File path.</param>
void load(const char* t_mat_file) {
if(!std::filesystem::exists(t_mat_file)) { usable = false; return; }
std::ifstream f(t_mat_file);
Expand All @@ -32,25 +41,25 @@ namespace firesteel {
if(data.at("variables").at(i.key()).is_array()) {
if(data.at("variables").at(i.key()).size() == 1)
shader.set_4_floats("material." + i.key(),
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[0]);
jskey(data, i.key(), 0),
jskey(data, i.key(), 0),
jskey(data, i.key(), 0),
jskey(data, i.key(), 0));
else if(data.at("variables").at(i.key()).size() == 2)
shader.set_2_floats("material." + i.key(),
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[1]);
else if(data.at("variables").at(i.key()).size() == 3)
jskey(data, i.key(), 0),
jskey(data, i.key(), 1));
else if (data.at("variables").at(i.key()).size() == 3)
shader.set_3_floats("material." + i.key(),
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[1],
data.at("variables").at(i.key())[2]);
else if(data.at("variables").at(i.key()).size() == 4)
jskey(data, i.key(), 0),
jskey(data, i.key(), 1),
jskey(data, i.key(), 2));
else if (data.at("variables").at(i.key()).size() == 4)
shader.set_4_floats("material." + i.key(),
data.at("variables").at(i.key())[0],
data.at("variables").at(i.key())[1],
data.at("variables").at(i.key())[2],
data.at("variables").at(i.key())[3]);
jskey(data, i.key(), 0),
jskey(data, i.key(), 1),
jskey(data, i.key(), 2),
jskey(data, i.key(), 3));
} else {
if(data.at("variables").at(i.key()).is_number_float())
shader.set_float("material." + i.key(), data.at("variables").value(i.key(), 0.0f));
Expand All @@ -61,8 +70,9 @@ namespace firesteel {
shader.disable();
}
}
void remove() {
shader.remove();
private:
float jskey(json t_data, const std::string t_key, size_t t_id) {
return t_data.at("variables").at(t_key)[t_id];
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion firesteel/includes/firesteel/rendering/mesh.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef OG_MESH_H
#define OG_MESH_H

#include <vector>
#include "firesteel/math.hpp"
#include <vector>

#include "firesteel/rendering/shader.hpp"
#include "firesteel/rendering/texture.hpp"
Expand Down
139 changes: 82 additions & 57 deletions firesteel/includes/firesteel/rendering/transform.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef OG_TRANSFORM_H
#define OG_TRANSFORM_H

#include <bitset>
#include "firesteel/log.hpp"
#include "firesteel/component.hpp"
#include "firesteel/rendering/mesh.hpp"
#include "firesteel/log.hpp"
#include "firesteel/rendering/material.hpp"
#include "firesteel/rendering/mesh.hpp"
#include <bitset>

constexpr auto MAX_INSTANCES = 128;
typedef unsigned long long TransformID;
Expand All @@ -20,18 +20,57 @@ struct aiMaterial;
namespace firesteel {

class Transform {

/* Basic functions */
public:
Transform(glm::vec3 t_pos = glm::vec3(0.f),
glm::vec4 t_rot = glm::vec4(glm::vec3(0.f), 1.f),
glm::vec3 t_size = glm::vec3(1.f), const char* t_name = "New Object",
bool is_instance = false, Transform* source_instance = nullptr);

Transform operator=(Transform t) {
position = t.position;
rotation = t.rotation;
size = t.size;
name = t.name;
m_instances = t.m_instances;
m_components = t.m_components;
m_is_initialized = t.m_is_initialized;
m_is_instance = t.m_is_instance;
m_source_instance = t.m_source_instance;
m_no_textures = t.m_no_textures;
m_material = t.m_material;
m_meshes = t.m_meshes;
m_model_path = t.m_model_path;
m_model_file = t.m_model_file;
m_textures = t.m_textures;
return *this;
}

/* Callback functions (for meshes) */
public:
/// <summary>
/// Initializes transform.
/// </summary>
/// <param name="t_add_to_scene">Add to scene?</param>
void initialize(bool t_add_to_scene = true);
bool is_initialized() const { return m_is_initialized; }
/// <summary>
/// Function, that runs before general render.
/// </summary>
void prerender();
/// <summary>
/// Render transform.
/// </summary>
/// <param name="t_update_components">Update components?</param>
void render(bool t_update_components = true);
/// <summary>
/// Deletes transform (cleanup).
/// </summary>
void remove();

/* Model & Mesh manipulations */
public:
/// <summary>
/// Loads transform.
/// </summary>
Expand All @@ -51,20 +90,27 @@ namespace firesteel {
/// </summary>
/// <returns>Absolute path to model.</returns>
std::string get_model_path() const { return m_model_path + m_model_file; }

/* Material & cubemap manipulations */
public:
/// <summary>
/// Function, that runs before general render.
/// Set material.
/// </summary>
void prerender();
/// <param name="t_mat">New material.</param>
void set_material(Material* t_mat) { m_material = *t_mat; }
/// <summary>
/// Render transform.
/// Set material's cubemap ID.
/// </summary>
/// <param name="t_update_components">Update components?</param>
void render(bool t_update_components = true);
/// <param name="t_id">Cubemap ID (-1 to disable).</param>
void set_cubemap(unsigned int t_id);
/// <summary>
/// Deletes transform (cleanup).
/// Gets material.
/// </summary>
void remove();
/// <returns>Material.</returns>
Material get_material() const { return m_material; }

/* Instancing */
public:
/// <summary>
/// Creates instance of this object.
/// </summary>
Expand All @@ -79,44 +125,11 @@ namespace firesteel {
/// Returns amount of instances.
/// </summary>
/// <returns>Amount of instances.</returns>
int instances_amount();
int instances_amount() { return static_cast<int>(m_instances.size()); }
bool is_instance() const { return m_is_instance; }

Transform operator=(Transform t) {
position = t.position;
rotation = t.rotation;
size = t.size;
name = t.name;
m_instances = t.m_instances;
m_components = t.m_components;
m_is_initialized = t.m_is_initialized;
m_is_instance = t.m_is_instance;
m_source_instance = t.m_source_instance;
m_no_textures = t.m_no_textures;
m_material = t.m_material;
m_meshes = t.m_meshes;
m_model_path = t.m_model_path;
m_model_file = t.m_model_file;
m_textures = t.m_textures;
return *this;
}

/// <summary>
/// Set material.
/// </summary>
/// <param name="t_mat">New material.</param>
void set_material(Material* t_mat);
/// <summary>
/// Set material's cubemap ID.
/// </summary>
/// <param name="t_id">Cubemap ID (-1 to disable).</param>
void set_cubemap(unsigned int t_id);
/// <summary>
/// Gets material.
/// </summary>
/// <returns>Material.</returns>
Material get_material() const;

/* Component functions */
public:
/// <summary>
/// Add new component by class.
/// </summary>
Expand All @@ -127,7 +140,7 @@ namespace firesteel {
template <typename T, typename... Args>
std::shared_ptr<T> add_component(Args&&... args) {
//Check if valid.
if (!std::is_base_of<Component, T>::value) {
if(!std::is_base_of<Component, T>::value) {
LOG_WARN("T must be derived from Component.");
return std::make_shared<T>();
}
Expand All @@ -147,13 +160,18 @@ namespace firesteel {
/// Gets components amount.
/// </summary>
/// <returns>Components amount.</returns>
int components_amount();
int components_amount() { return static_cast<int>(m_components.size()); }
/// <summary>
/// Gets component by local ID (index).
/// </summary>
/// <param name="t_id">Index of component.</param>
/// <returns>Component (if present).</returns>
Component get_component(int t_id);
Component get_component(int t_id) {
//Checks if ID is valid.
if(t_id < static_cast<int>(m_components.size())) return *(m_components[t_id].get());
//If it's not - return empty component.
return Component();
}
/// <summary>
/// Get component by class.
/// </summary>
Expand All @@ -163,13 +181,13 @@ namespace firesteel {
T& get_component() const {
static T default_component;
//Check if valid.
if (!std::is_base_of<Component, T>::value) {
if(!std::is_base_of<Component, T>::value) {
LOG_WARN("T must be derived from Component.");
return default_component;
}
//Search for component.
for (const auto& component : m_components)
if (typeid(*component) == typeid(T))
for(const auto& component : m_components)
if(typeid(*component) == typeid(T))
return dynamic_cast<T&>(*(component.get()));
//If component not found - return empty constructor.
return default_component;
Expand All @@ -180,25 +198,32 @@ namespace firesteel {
/// <returns>List of components.</returns>
std::vector<std::shared_ptr<Component>>* get_component_list() { return &m_components; }

/* Built-in orientation component */
public:
glm::vec3 position;
glm::vec4 rotation;
glm::vec3 size;
std::string name;

/* Instance and component related */
protected:
//Global attributes.
std::vector<Transform> m_instances;
Transform* m_source_instance;
std::vector<std::shared_ptr<Component>> m_components;
//Local attributes.
bool m_is_initialized = false;
bool m_is_instance;
Transform* m_source_instance;
bool m_is_initialized = false;

/* Mesh and texture related */
protected:
bool m_no_textures = false;
Material m_material;
std::vector<Mesh> m_meshes;
std::string m_model_path;
std::string m_model_file;
std::vector<Texture> m_textures;
//Functions.

/* Mesh functions */
protected:
/// <summary>
/// Processes model node.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion firesteel/includes/firesteel/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace firesteel {
std::string output = "";
//Try to read file.
file.open(t_path);
if (file.is_open()) {
if(file.is_open()) {
buffer << file.rdbuf();
output = buffer.str();
}
Expand Down
Loading

0 comments on commit e4019b3

Please sign in to comment.