Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit d0fd46b

Browse files
committed
Restructure scene
1 parent 43cfb32 commit d0fd46b

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main() {
1313
auto game = std::make_unique<Game>();
1414
game->addPlugin(DefaultPlugins());
1515
game->addPlugin(plugins::Physics());
16-
game->addPlugin(scenes::NFS());
16+
game->addPlugin(scenes::nfs::NFS());
1717

1818
auto result = game->start();
1919
if (!result.has_value()) {

src/scenes/nfs.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,20 @@ static std::expected<void, std::string> update(/* clang-format off */
9797
auto& velocity = carView.get<components::Velocity>(entity);
9898
auto& angularVelocity = carView.get<components::AngularVelocity>(entity);
9999

100-
const float maxCarSpeed = 15.0f; // Maximum speed in units per second
101-
const float acceleration = 25.0f; // Acceleration rate
102-
const float deceleration = 30.0f; // Deceleration rate when no input
100+
const float maxCarSpeed = 15.0f; // Maximum speed in units per second
101+
const float acceleration = 25.0f; // Acceleration rate
102+
const float deceleration = 30.0f; // Deceleration rate when no input
103103
const float brakeDeceleration = 40.0f; // Deceleration when braking
104-
const float maxTurnSpeed = 2.0f; // Maximum radians per second
105-
const float turnAcceleration = 8.0f; // How fast we accelerate into turns
106-
const float turnDeceleration = 12.0f; // How fast we decelerate out of turns
104+
const float maxTurnSpeed = 2.0f; // Maximum radians per second
105+
const float turnAcceleration = 8.0f; // How fast we accelerate into turns
106+
const float turnDeceleration = 12.0f; // How fast we decelerate out of turns
107107

108108
float targetSpeed = 0.0f;
109109
float movementInput = 0.0f; // Track how much we're moving
110110
float targetAngularVelocity = 0.0f; // Target turning speed
111111

112112
glm::vec3 forward = rotation.value * glm::vec3(0.0f, 1.0f, 0.0f);
113-
113+
114114
// Get current speed in the forward direction
115115
float currentSpeed = glm::dot(velocity.value, -forward);
116116

@@ -120,13 +120,13 @@ static std::expected<void, std::string> update(/* clang-format off */
120120
movementInput = 1.0f; // Moving forward
121121
} else if (input::Keyboard::isBeingHeld(input::Key::S)) {
122122
targetSpeed = -maxCarSpeed * 0.6f; // Reverse is slower
123-
movementInput = 1.0f; // Moving backward
123+
movementInput = 1.0f; // Moving backward
124124
}
125125

126126
// Smooth speed interpolation
127127
float speedDifference = targetSpeed - currentSpeed;
128128
float maxSpeedChange;
129-
129+
130130
if (movementInput > 0.0f) {
131131
// We have input - accelerate towards target
132132
if ((targetSpeed > 0 && currentSpeed < targetSpeed) || (targetSpeed < 0 && currentSpeed > targetSpeed)) {
@@ -139,14 +139,14 @@ static std::expected<void, std::string> update(/* clang-format off */
139139
// No input - natural deceleration
140140
maxSpeedChange = deceleration * time.deltaTime;
141141
}
142-
142+
143143
// Apply speed change with limits
144144
if (std::abs(speedDifference) > maxSpeedChange) {
145145
currentSpeed += (speedDifference > 0) ? maxSpeedChange : -maxSpeedChange;
146146
} else {
147147
currentSpeed = targetSpeed;
148148
}
149-
149+
150150
// Convert speed back to velocity vector
151151
velocity.value = -forward * currentSpeed;
152152

@@ -198,7 +198,10 @@ static std::expected<void, std::string> update(/* clang-format off */
198198
return {};
199199
}
200200

201-
void scenes::NFS::build(Game& game) {
201+
void scenes::nfs::NFS::build(Game& game) {
202+
std::shared_ptr<scenes::nfs::components::CameraState> cameraState;
203+
game.addResource(cameraState);
204+
202205
game.addSystem(Schedule::Startup, startup);
203206
game.addSystem(Schedule::Update, update);
204207
}

src/scenes/nfs.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
class Game;
55

6-
namespace scenes {
6+
namespace scenes::nfs {
7+
namespace components {
8+
struct CameraState {};
9+
};
10+
711
struct NFS {
812
void build(Game& game);
913
};

0 commit comments

Comments
 (0)