Skip to content

Refactor lighthouse #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: feature/actors
Choose a base branch
from
Draft

Refactor lighthouse #4

wants to merge 10 commits into from

Conversation

NikolaJelic
Copy link
Collaborator

  • Create Lighthouse class
  • Add texture rendering with placeholder texture

- Create Lighthouse class
- Add texture rendering with placeholder texture
@NikolaJelic NikolaJelic requested a review from karnkaul June 17, 2025 22:38
@NikolaJelic NikolaJelic self-assigned this Jun 17, 2025
m_texture = asset_loader.load_texture("images/lighthouse.png");
m_sprite.texture = &m_texture.value();
}
void Lighthouse::rotate_towards_cursor(glm::vec2 const& cursor_pos) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add empty line between functions

Copy link
Member

@karnkaul karnkaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix incorrect unit vector

- rotate lighthouse image so it better follows the cursor
- adjust whitespace
- fix unit vector typo
@NikolaJelic NikolaJelic requested a review from karnkaul June 18, 2025 20:06
@NikolaJelic NikolaJelic requested a review from karnkaul June 20, 2025 17:27
src/enemy.cpp Outdated
Comment on lines 21 to 22
glm::vec2 direction = glm::normalize(m_target_pos - m_sprite.transform.position);
glm::vec2 movement = direction * m_move_speed * dt.count();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: locals should be const unless being mutated after construction

src/enemy.cpp Outdated
Comment on lines 27 to 28
float radius = std::max(screen_size.x, screen_size.y) / 2.0f;
float angle = util::random_range(0.0f, 2.0f * std::numbers::pi_v<float>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

src/enemy.hpp Outdated

void render(le::Renderer& renderer) const;
void move();
void move(kvf::Seconds dt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the name to tick() , and don't use the identifier move in C++, it might conflict with std::move(), despite being in different namespaces. Also looks weird (use translate() or something instead).

src/enemy.hpp Outdated

private:
glm::vec2 generate_spawn_pos(glm::vec2 screen_size);
static glm::vec2 generate_spawn_pos(glm::vec2 screen_size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a static member function make this a free function in an unnamed namespace in the cpp file

src/enemy.hpp Outdated
Comment on lines 27 to 28
glm::vec2 m_target_pos;
float m_move_speed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uninitialized primitives (use {})

src/game.cpp Outdated
@@ -1,10 +1,11 @@
#include <game.hpp>
#include <glm/gtx/norm.hpp>
#include <le2d/context.hpp>
#include "glm/ext/vector_float2.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

namespace miracle {
class Enemy {
public:
explicit Enemy(gsl::not_null<le::ServiceLocator const*> services, glm::vec2 target_pos, float move_speed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest moving target_pos and move_speed params into a struct and take an instance of that in the constructor. A few benefits:

  • Constructor signature doesn't change even if the struct members evolve over time
  • Much more readable at call site: {.move_speed = 50.0f, .target_pos = {1.0f, 2.0f}} vs (50.0f, {1.0f, 2.0f})
  • Callers can memoize params into their own objects that can be reused

src/enemy.hpp Outdated
Comment on lines 27 to 28
glm::vec2 m_target_pos;
float m_move_speed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uninitialized members (use {})

- move spawn point position generation to the 'util::random' namespace
- add default initialization to primitives
- remove redudant includes
- add 'const' to local variables where appropriate
- rename 'move' function to avoid naming conflicts
@NikolaJelic NikolaJelic marked this pull request as draft June 21, 2025 13:48
@@ -0,0 +1,27 @@
#include <enemy.hpp>
#include <algorithm>
#include "glm/ext/vector_float2.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these random glm headers keep popping up in your PR?

// Returns a random coordinate on the specified radius
[[nodiscard]] inline auto get_random_location_on_radius(float radius) -> glm::vec2 {
float const angle = random_range(0.0f, 2.0f * std::numbers::pi_v<float>);
return {radius * std::cos(angle), radius * std::sin(angle)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::cos requires <cmath>

@@ -0,0 +1,44 @@
#pragma once
#include <glm/ext/vector_float2.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants