Skip to content

Commit

Permalink
Customizing linter and fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-tomas committed Oct 30, 2023
1 parent e718e07 commit ff97d82
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bloss1/src/ecs/systems/ophanim_controller_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace bls
{
const f32 OPHANIM_MAX_HP = 10000;
const f32 OPHANIM_MAX_HP = 1000;

void ophanim_controller_system(ECS &ecs, f32 dt)
{
Expand Down
8 changes: 4 additions & 4 deletions bloss1/src/ecs/systems/physics_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ namespace bls
// Box v. Sphere
if (collider_a->type == Collider::ColliderType::Box && collider_b->type == Collider::ColliderType::Sphere)
{
auto col_a = static_cast<BoxCollider *>(collider_a);
auto col_b = static_cast<SphereCollider *>(collider_b);
const auto *col_a = static_cast<BoxCollider *>(collider_a);
const auto *col_b = static_cast<SphereCollider *>(collider_b);

// Point where the box 'begins'
vec3 min_aabb = trans_a.position - col_a->dimensions;
Expand Down Expand Up @@ -209,8 +209,8 @@ namespace bls
else if (collider_a->type == Collider::ColliderType::Sphere &&
collider_b->type == Collider::ColliderType::Sphere)
{
auto col_a = static_cast<SphereCollider *>(collider_a);
auto col_b = static_cast<SphereCollider *>(collider_b);
const auto *col_a = static_cast<SphereCollider *>(collider_a);
const auto *col_b = static_cast<SphereCollider *>(collider_b);

// Insert tolerance to avoid equal points
const f32 TOL = 0.002;
Expand Down
2 changes: 1 addition & 1 deletion bloss1/src/ecs/systems/player_controller_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ namespace bls
bullet(ecs, transform, object);

// Create and emit particles
auto &player_particle_sys = ecs.particle_systems[0];
const auto &player_particle_sys = ecs.particle_systems[0];
player_particle_sys->emitter->set_center(transform.position);
player_particle_sys->particles_to_be_emitted += 15;
}
Expand Down
2 changes: 1 addition & 1 deletion bloss1/src/ecs/systems/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace bls
shader.set_uniform4("model", model_matrix);

// Render the model
for (auto &mesh : model->model->meshes)
for (const auto &mesh : model->model->meshes)
{
// Bind textures
for (u32 i = 0; i < mesh->textures.size(); i++)
Expand Down
18 changes: 12 additions & 6 deletions bloss1/src/platform/glfw/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ namespace bls
"GLEW");

// Get native_window dimensions
glfwGetWindowSize(native_window, (i32 *)&width, (i32 *)&height);
glfwGetWindowSize(native_window,
const_cast<i32 *>(reinterpret_cast<const i32 *>(&width)),
const_cast<i32 *>(reinterpret_cast<const i32 *>(&height)));

// Set debug callbacks
#if defined(_DEBUG)
Expand Down Expand Up @@ -75,7 +77,8 @@ namespace bls
glfwSetWindowCloseCallback(native_window,
[](GLFWwindow *window)
{
auto &window_data = *(WindowData *)glfwGetWindowUserPointer(window);
auto &window_data =
*reinterpret_cast<WindowData *>(glfwGetWindowUserPointer(window));
WindowCloseEvent event = {};
window_data.event_callback(event);
});
Expand All @@ -84,7 +87,8 @@ namespace bls
glfwSetFramebufferSizeCallback(native_window,
[](GLFWwindow *window, i32 width, i32 height)
{
auto &window_data = *(WindowData *)glfwGetWindowUserPointer(window);
auto &window_data =
*reinterpret_cast<WindowData *>(glfwGetWindowUserPointer(window));
window_data.width = width;
window_data.height = height;

Expand All @@ -99,7 +103,8 @@ namespace bls
// Key press
if (action == GLFW_PRESS || action == GLFW_REPEAT)
{
auto &window_data = *(WindowData *)glfwGetWindowUserPointer(window);
auto &window_data =
*reinterpret_cast<WindowData *>(glfwGetWindowUserPointer(window));
KeyPressEvent event = {(u32)key};
window_data.event_callback(event);
}
Expand All @@ -109,7 +114,8 @@ namespace bls
glfwSetCursorPosCallback(native_window,
[](GLFWwindow *window, f64 x_position, f64 y_position)
{
auto &window_data = *(WindowData *)glfwGetWindowUserPointer(window);
auto &window_data =
*reinterpret_cast<WindowData *>(glfwGetWindowUserPointer(window));
MouseMoveEvent event = {x_position, y_position};
window_data.event_callback(event);
});
Expand All @@ -118,7 +124,7 @@ namespace bls
glfwSetScrollCallback(native_window,
[](GLFWwindow *window, f64 x_offset, f64 y_offset)
{
auto &window_data = *(WindowData *)glfwGetWindowUserPointer(window);
auto &window_data = *reinterpret_cast<WindowData *>(glfwGetWindowUserPointer(window));
MouseScrollEvent event = {x_offset, y_offset};
window_data.event_callback(event);
});
Expand Down
58 changes: 43 additions & 15 deletions bloss1/src/renderer/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace bls
Model::~Model()
{
delete importer;
for (auto &mesh : meshes) delete mesh;
for (const auto &mesh : meshes) delete mesh;
}

void Model::process_node(aiNode *node, const aiScene *scene)
Expand Down Expand Up @@ -166,32 +166,60 @@ namespace bls
auto ebo = IndexBuffer::create(indices, indices.size());

// Position
vao->add_vertex_buffer(
0, 3, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::position));
vao->add_vertex_buffer(0,
3,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::position)));

// Normals
vao->add_vertex_buffer(
1, 3, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::normal));
vao->add_vertex_buffer(1,
3,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::normal)));

// Texture coords
vao->add_vertex_buffer(
2, 2, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::tex_coords));
vao->add_vertex_buffer(2,
2,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::tex_coords)));

// Tangent
vao->add_vertex_buffer(
3, 3, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::tangent));
vao->add_vertex_buffer(3,
3,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::tangent)));

// Bitangent
vao->add_vertex_buffer(
4, 3, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::bitangent));
vao->add_vertex_buffer(4,
3,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::bitangent)));

// Bone ids
vao->add_vertex_buffer(
5, 4, ShaderDataType::Int, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::bone_ids));
vao->add_vertex_buffer(5,
4,
ShaderDataType::Int,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::bone_ids)));

// Weights
vao->add_vertex_buffer(
6, 4, ShaderDataType::Float, false, sizeof(Vertex), (void *)offsetof(Vertex, Vertex::weights));
vao->add_vertex_buffer(6,
4,
ShaderDataType::Float,
false,
sizeof(Vertex),
reinterpret_cast<void *>(offsetof(Vertex, Vertex::weights)));

return new Mesh(vao, vbo, ebo, vertices, indices, textures);
}
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set positional-arguments
@release: (build "release") (run "release")

@lint:
cppcheck --enable=all --std=c++20 bloss1/src/**
cppcheck --enable=warning,performance,portability,unusedFunction,style,information --disable=missingInclude --std=c++20 bloss1/src/**

@format:
find bloss1/src/ -iname *.hpp -o -iname *.cpp | xargs clang-format -i -style=file
Expand Down

0 comments on commit ff97d82

Please sign in to comment.