Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
calint committed Jul 8, 2024
1 parent 31bd513 commit 1d9328b
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 67 deletions.
22 changes: 3 additions & 19 deletions src/application/application.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

// make common used namespace available in game code
using namespace glos;
Expand Down Expand Up @@ -111,20 +113,6 @@ static auto application_init() -> void {
// single player mode
ship *p = new (objects.alloc()) ship{};
p->net_state = &net.states[1];

// sphere *s = new (objects.alloc()) sphere{};
// s->scale = {2.0f, 2.0f, 2.0f};
// s->bounding_radius = globs.at(s->glob_ix).bounding_radius * s->scale.x;
// s->net_state = &net.states[1];

// cube *c1 = new (objects.alloc()) cube{};
// c1->scale.z = 5;
// c1->bounding_radius = 20; // bypass bounding radius check
// c1->net_state = &net.states[1];

// cube *c2 = new (objects.alloc()) cube{};
// c2->scale.y = 10;
// c2->bounding_radius = 20; // bypass bounding radius check
}
} else {
switch (performance_test_type) {
Expand Down Expand Up @@ -152,10 +140,6 @@ static auto application_init() -> void {
camera.ortho_max_x = game_area_half_x;
camera.ortho_max_y = game_area_half_z;

// camera.type = camera::type::LOOK_AT;
// camera.position = {0, 30, 30};
// camera.look_at = {0, 0, -0.0001f};

hud.load_font("assets/fonts/digital-7 (mono).ttf", 20);
}

Expand All @@ -174,10 +158,10 @@ static auto application_on_update_done() -> void {
// engine interface
static auto application_on_render_done() -> void {
if (score != score_prv) {
score_prv = score;
std::array<char, 256> buf{};
sprintf(buf.data(), "score: %06u", score);
hud.print(buf.data(), SDL_Color{255, 0, 0, 255}, 60, 10);
score_prv = score;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/application/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// reviewed: 2024-01-04
// reviewed: 2024-01-06
// reviewed: 2024-01-08
// reviewed: 2024-07-08

//
// configuration used by engine
Expand Down Expand Up @@ -124,7 +125,7 @@ static constexpr float game_area_min_z =
static constexpr float game_area_max_z =
game_area_half_z + asteroid_large_scale;

// glob indexes (are set by 'application_init()' when loading)
// glob indexes (are set by 'application_init()' when loading models)
static uint32_t glob_ix_ship = 0;
static uint32_t glob_ix_ship_engine_on = 0;
static uint32_t glob_ix_bullet = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/application/objects/asteroid_large.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

// include order relevant
#include "../configuration.hpp"
Expand All @@ -12,10 +13,9 @@
class asteroid_large final : public object {
public:
inline asteroid_large() {
name = "asteroid_large";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("asteroid_large_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down Expand Up @@ -58,11 +58,11 @@ class asteroid_large final : public object {

for (uint32_t i = 0; i < asteroid_large_split; ++i) {
asteroid_medium *ast = new (objects.alloc()) asteroid_medium{};
float const rd2 = bounding_radius / 2;
vec3 const rp = {rnd1(rd2), 0, rnd1(rd2)};
ast->position = position + rp;
float const br = bounding_radius / 2;
vec3 const rel_pos = {rnd1(br), 0, rnd1(br)};
ast->position = position + rel_pos;
ast->velocity =
velocity + rnd2(asteroid_large_split_speed) * normalize(rp);
velocity + rnd2(asteroid_large_split_speed) * normalize(rel_pos);
ast->angular_velocity = vec3{rnd1(asteroid_large_split_agl_vel_rnd)};
}

Expand Down
12 changes: 6 additions & 6 deletions src/application/objects/asteroid_medium.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

// include order relevant
#include "../configuration.hpp"
Expand All @@ -12,10 +13,9 @@
class asteroid_medium final : public object {
public:
inline asteroid_medium() {
name = "asteroid_medium";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("asteroid_medium_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down Expand Up @@ -57,11 +57,11 @@ class asteroid_medium final : public object {

for (uint32_t i = 0; i < asteroid_medium_split; ++i) {
asteroid_small *ast = new (objects.alloc()) asteroid_small{};
float const rd2 = bounding_radius / 2;
vec3 const rp = {rnd1(rd2), 0, rnd1(rd2)};
ast->position = position + rp;
float const br = bounding_radius / 2;
vec3 const rel_pos = {rnd1(br), 0, rnd1(br)};
ast->position = position + rel_pos;
ast->velocity =
velocity + rnd2(asteroid_medium_split_speed) * normalize(rp);
velocity + rnd2(asteroid_medium_split_speed) * normalize(rel_pos);
ast->angular_velocity = vec3{rnd1(asteroid_medium_split_agl_vel_rnd)};
}

Expand Down
12 changes: 9 additions & 3 deletions src/application/objects/asteroid_small.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

// include order relevant
#include "../configuration.hpp"
//
#include "power_up.hpp"
//
#include "../utils.hpp"

class asteroid_small final : public object {
public:
inline asteroid_small() {
name = "asteroid_small";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("asteroid_small_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down Expand Up @@ -53,7 +55,11 @@ class asteroid_small final : public object {

score += 100;

power_up_by_chance(position);
if (rnd3(power_up_chance_rem)) {
power_up *pu = new (objects.alloc()) power_up{};
pu->position = position;
pu->angular_velocity.y = radians(90.0f);
}

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/application/objects/bullet.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

#include "fragment.hpp"

class bullet final : public object {
public:
inline bullet() {
name = "bullet";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("bullet_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down
10 changes: 5 additions & 5 deletions src/application/objects/cube.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

class cube final : public object {
public:
inline cube() {
name = "cube";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("cube_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down Expand Up @@ -38,12 +38,12 @@ class cube final : public object {
return true;
}

velocity = {0, 0, 0};
angular_velocity = {0, 0, 0};
velocity = {};
angular_velocity = {};

uint64_t const keys = net_state->keys;

// handle ship controls
// handle controls
float const v = 1;
float const a = radians(10.0f);
if (keys & key_w) {
Expand Down
4 changes: 2 additions & 2 deletions src/application/objects/fragment.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

class fragment final : public object {
public:
uint64_t death_time_ms = 0;

inline fragment() {
name = "fragment";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("fragment_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions src/application/objects/power_up.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

class power_up final : public object {
public:
inline power_up() {
name = "power_up";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("power_up_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down
6 changes: 3 additions & 3 deletions src/application/objects/ship.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

#include "bullet.hpp"

class ship final : public object {
public:
inline ship() {
name = "hero";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("hero_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand All @@ -36,7 +36,7 @@ class ship final : public object {

game_area_roll(position);

angular_velocity = {0, 0, 0};
angular_velocity = {};
glob_ix(glob_ix_ship);

if (net_state == nullptr) {
Expand Down
6 changes: 3 additions & 3 deletions src/application/objects/sphere.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

class sphere final : public object {
public:
inline sphere() {
name = "sphere";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("sphere_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
Expand Down Expand Up @@ -39,7 +39,7 @@ class sphere final : public object {
return true;
}

velocity = {0, 0, 0};
velocity = {};

uint64_t const keys = net_state->keys;

Expand Down
5 changes: 2 additions & 3 deletions src/application/objects/tetra.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

class tetra final : public object {
public:
inline tetra() {
name = "tetra";
if (debug_multiplayer) {
++counter;
name.append(1, '_').append(std::to_string(counter));
name.append("tetra_").append(std::to_string(counter));
printf("%lu: %lu: create %s\n", frame_context.frame_num, frame_context.ms,
name.c_str());
}
glob_ix(glob_ix_tetra);
scale = {2.0f, 1.0f, 7.0f};
bounding_radius = globs.at(glob_ix()).bounding_radius * scale.x;
// angular_velocity.z = radians(20.0f);
mass = 10;
collision_bits = cb_power_up;
collision_mask = cb_hero;
Expand Down
13 changes: 1 addition & 12 deletions src/application/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once
// reviewed: 2024-01-04
// reviewed: 2024-01-08
// reviewed: 2024-07-08

// include order matters
#include "configuration.hpp"
//
#include "objects/power_up.hpp"
//

inline static auto rnd1(float const range) -> float {
int const r = rand();
Expand Down Expand Up @@ -62,13 +61,3 @@ inline static auto is_outside_game_area(glm::vec3 const &position) -> bool {
position.y < game_area_min_y || position.y > game_area_max_y ||
position.z < game_area_min_z || position.z > game_area_max_z;
}

inline static auto power_up_by_chance(glm::vec3 const &position) -> void {
if (!rnd3(power_up_chance_rem)) {
return;
}

power_up *pu = new (objects.alloc()) power_up{};
pu->position = position;
pu->angular_velocity.y = radians(90.0f);
}

0 comments on commit 1d9328b

Please sign in to comment.