Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/raynder/raynder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class RAYNDERCAST_EXPORT Game {
std::unique_ptr<Map> map_ptr;
std::unique_ptr<Player> player_ptr;

uint64_t last_tick;
uint64_t current_tick;
float delta;
uint64_t last_tick{0};
uint64_t current_tick{0};
float delta{0};

void compute_delta();

Expand Down
14 changes: 7 additions & 7 deletions include/raynder/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace Raynder {
};

struct RAYNDERCAST_EXPORT IdxPair {
uint8_t x;
uint8_t y;
uint8_t x{0};
uint8_t y{0};
};

struct RAYNDERCAST_EXPORT CartesianPair {
Expand All @@ -38,7 +38,7 @@ namespace Raynder {
struct RAYNDERCAST_EXPORT HitData {
CartesianPair coords;
IdxPair hit_idx;
bool vertical;
bool vertical{false};
};

struct RAYNDERCAST_EXPORT Color {
Expand All @@ -51,11 +51,11 @@ namespace Raynder {
};

struct SignedColor {
int16_t r = 0;
int16_t g = 0;
int16_t b = 0;
int16_t r;
int16_t g;
int16_t b;

SignedColor();
SignedColor() : r{0}, g{0}, b{0} {};
SignedColor(const int16_t r, const int16_t g, const int16_t b) : r{r}, g{g}, b{b} {}
SignedColor(const Color color) :
r{(int16_t)color.r},
Expand Down
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Map::Map(
std::regex row_regex(row_regex_str);

std::stringstream ss(string_as_data);
std::string line;
std::string line{""};

uint8_t loc_y = 0;

Expand Down
22 changes: 4 additions & 18 deletions src/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void Player::reset_collision_dir() {
}

enum MovementDirection Player::get_movement_direction(enum Axis axis) const {
enum MovementDirection dir;
enum MovementDirection dir = MovementDirection::UP;
switch (axis) {
case Axis::HORIZONTAL:
if (!global_basis_dy) break;
Expand All @@ -65,6 +65,9 @@ enum MovementDirection Player::get_movement_direction(enum Axis axis) const {
if (!global_basis_dx) break;
dir = (global_basis_dx > 0) ? MovementDirection::RIGHT : MovementDirection::LEFT;
break;
default:
throw std::runtime_error("Unexpected code execution path.");
break;
}
return dir;
}
Expand Down Expand Up @@ -104,23 +107,6 @@ void Player::move_and_slide() {
const float p_vel_x = this->global_basis_dx * this->config.translational_speed;
const float p_vel_y = this->global_basis_dy * this->config.translational_speed;

/*const float relative_angle = this->get_basis_d_relative_rotation();

const float hit_dist_squared = pow(hit_data.coords.x, 2) + pow(hit_data.coords.y, 2);

if (hit_dist_squared <= pow(this->config.collision_radius, 2)) {

if (hit_data.vertical) {
this->vel_y = p_vel_y;
} else {
this->vel_x = p_vel_x;
}
} else {
this->vel_x = p_vel_x;
this->vel_y = p_vel_y;
}*/


if (collision_direction.y_colliding && collision_direction.x_colliding) {

} else if (collision_direction.y_colliding) {
Expand Down
4 changes: 2 additions & 2 deletions src/player/player_collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Raynder {

const float Player::get_basis_d_relative_rotation() const {
float result;
float result = 0.0;
if (basis_dy > 0 && basis_dx == 0) { //forward
result = 0;
result = 0.0;
} else if (basis_dy < 0 && basis_dx == 0) { //backward
result = M_PI;
} else if (basis_dy == 0 && basis_dx > 0) { //left
Expand Down
2 changes: 1 addition & 1 deletion src/raycaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const bool Raycaster::cast_ray_along_axis_in_tile(
};

CartesianPair diff;
bool vertical;
bool vertical{false};

switch (dir) {
case MovementDirection::UP:
Expand Down
34 changes: 19 additions & 15 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Raynder {

void Renderer::set_drawing_color(const uint8_t r, const uint8_t g, const uint8_t b) const {
if (SDL_SetRenderDrawColor(this->context, r, g, b, 255)) {
throw std::runtime_error(SDL_GetError());
throw std::runtime_error(SDL_GetError());
}
}

Expand All @@ -33,11 +33,11 @@ void Renderer::set_drawing_color(const Color color) const {
}

void Renderer::draw_quad(
const float x1, const float y1,
const float x2, const float y2,
const float x3, const float y3,
const float x4, const float y4,
const Color color
const float x1, const float y1,
const float x2, const float y2,
const float x3, const float y3,
const float x4, const float y4,
const Color color
) {
const SDL_Color draw_color{color.r, color.g, color.b, 255};

Expand Down Expand Up @@ -163,9 +163,9 @@ void Renderer::draw_3d_floor(
enum Viewport viewport
) {

float top_y;
float bottom_y;
float max_x;
float top_y{0};
float bottom_y{0};
float max_x{0};
float min_x = this->config.eucliview_offset_x;

switch (viewport) {
Expand All @@ -179,7 +179,10 @@ void Renderer::draw_3d_floor(
top_y = this->eucliview_height/2.0 + this->config.eucliview_offset_y;
bottom_y = this->eucliview_height + this->config.eucliview_offset_y;
max_x = this->eucliview_width + min_x;
break;
break;
default:
throw std::runtime_error("Unexpected code execution path.");
break;
}

const Color col = this->config.floor_color;
Expand All @@ -203,7 +206,7 @@ void Renderer::draw_3d_wall(
) {
this->viewport_indicator = viewport;

float last_theta;
float last_theta{0};
HitData last_hit_data;
bool first_theta_iteration = true;

Expand All @@ -219,11 +222,9 @@ void Renderer::draw_3d_wall(

const bool same_or_adjacent_blocks = Renderer::same_or_adjacent_blocks(last_hit_data.hit_idx, hit_data.hit_idx);

bool convex_outline_from_view;

if (!first_theta_iteration && same_or_adjacent_blocks) {

convex_outline_from_view = !diagonal_blocks(last_hit_data.hit_idx, hit_data.hit_idx);
const bool convex_outline_from_view = !diagonal_blocks(last_hit_data.hit_idx, hit_data.hit_idx);
const bool diagonal = !convex_outline_from_view;

const bool same_orientation = hit_data.vertical == last_hit_data.vertical;
Expand Down Expand Up @@ -255,14 +256,17 @@ const float Renderer::get_renderer_distance(
const float y,
enum Viewport viewport
) const {
float result;
float result = 0.0f;
switch (viewport) {
case Viewport::MAIN:
result = this->distance_func(x, y);
break;
case Viewport::EUCLI:
result = sqrt(pow(x, 2) + pow(y, 2));
break;
default:
throw std::runtime_error("Unexpected code execution path.");
break;
}
return result;
}
Expand Down