Skip to content

Commit

Permalink
Remove unused component
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjaltesorgenfrei committed Feb 2, 2024
1 parent e01c8c2 commit ca109cd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ entt::entity App::addPlayer(T input) {
auto color = Color::playerColor(playerId);
registry.emplace<Player>(entity, playerId, color);
registry.emplace<Transform>(entity);
registry.emplace<CarStateLastUpdate>(entity);
registry.emplace<CarControl>(entity);
registry.emplace<std::shared_ptr<RenderObject>>(entity, std::make_shared<RenderObject>(meshes["car"], carMaterial));
registry.emplace<SelectedTag>(entity);
Expand Down
7 changes: 0 additions & 7 deletions src/engine/Components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ struct CarControl {
float desiredBrake = 0.0f;
};

// Struct to store speed, direction and position of a car for the last frame.
struct CarStateLastUpdate {
float speed;
glm::vec3 direction;
glm::vec3 position;
};

// TODO: Organize the values better. And add the rest of the values.
// TODO: Add a short description of each value and its unit
struct CarSettings {
Expand Down
18 changes: 3 additions & 15 deletions src/engine/systems/CarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inline glm::quat toGlm(JPH::Quat quat) {
}

void CarSystem::update(entt::registry &registry, float delta, entt::entity ent, CarControl const &carControl,
CarPhysics &car, CarStateLastUpdate &lastState) const {
CarPhysics &car) const {
using namespace JPH;

WheeledVehicleController *controller = static_cast<WheeledVehicleController *>(car.constraint->GetController());
Expand All @@ -32,7 +32,7 @@ void CarSystem::update(entt::registry &registry, float delta, entt::entity ent,
}

void CarKeyboardSystem::update(entt::registry &registry, float delta, entt::entity ent, KeyboardInput const &input,
CarStateLastUpdate const &lastState, CarControl &carControl) const {
CarControl &carControl) const {
carControl.desiredAcceleration = 0.0f;
carControl.desiredBrake = 0.0f;

Expand All @@ -52,19 +52,13 @@ void CarKeyboardSystem::update(entt::registry &registry, float delta, entt::enti
carControl.desiredAcceleration = 0.0f;
}

if (lastState.speed >= 15.0f && input.keys[GLFW_KEY_DOWN]) {
carControl.desiredBrake = 1.0f;
} else if (lastState.speed <= -15.0f && input.keys[GLFW_KEY_UP]) {
carControl.desiredBrake = 1.0f;
}

if (input.keys[GLFW_KEY_SPACE]) {
carControl.desiredBrake = 1.0f;
}
}

void CarJoystickSystem::update(entt::registry &registry, float delta, entt::entity ent, GamepadInput const &input,
CarStateLastUpdate const &lastState, CarControl &carControl) const {
CarControl &carControl) const {
carControl.desiredAcceleration = 0.0f;
carControl.desiredBrake = 0.0f;

Expand All @@ -74,11 +68,5 @@ void CarJoystickSystem::update(entt::registry &registry, float delta, entt::enti
carControl.desiredAcceleration += -input.leftTrigger * 1.0f;
carControl.desiredAcceleration = std::clamp(carControl.desiredAcceleration, -1.0f, 1.0f);

if (lastState.speed >= 15.0f) {
carControl.desiredBrake = input.leftTrigger * 1.0f;
} else if (lastState.speed <= -15.0f) {
carControl.desiredBrake = input.rightTrigger * 1.0f;
}

// TODO: Right now you have to stop completely before you can reverse. fix this
}
16 changes: 7 additions & 9 deletions src/engine/systems/CarSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
#include "../DependentSystem.hpp"
#include "../PhysicsBody.hpp"

struct CarSystem : System<CarSystem, Reads<CarControl>, Writes<CarPhysics>, Others<CarStateLastUpdate>> {
void update(entt::registry &registry, float delta, entt::entity ent, CarControl const &carControl, CarPhysics &car,
CarStateLastUpdate &lastState) const;
struct CarSystem : System<CarSystem, Reads<CarControl>, Writes<CarPhysics>, Others<>> {
void update(entt::registry &registry, float delta, entt::entity ent, CarControl const &carControl,
CarPhysics &car) const;
};

struct CarKeyboardSystem
: System<CarKeyboardSystem, Reads<KeyboardInput, CarStateLastUpdate>, Writes<CarControl>, Others<>> {
struct CarKeyboardSystem : System<CarKeyboardSystem, Reads<KeyboardInput>, Writes<CarControl>, Others<>> {
void update(entt::registry &registry, float delta, entt::entity ent, KeyboardInput const &input,
CarStateLastUpdate const &lastState, CarControl &carControl) const;
CarControl &carControl) const;
};

struct CarJoystickSystem
: System<CarJoystickSystem, Reads<GamepadInput, CarStateLastUpdate>, Writes<CarControl>, Others<>> {
struct CarJoystickSystem : System<CarJoystickSystem, Reads<GamepadInput>, Writes<CarControl>, Others<>> {
void update(entt::registry &registry, float delta, entt::entity ent, GamepadInput const &input,
CarStateLastUpdate const &lastState, CarControl &carControl) const;
CarControl &carControl) const;
};

0 comments on commit ca109cd

Please sign in to comment.