From f206d19d6b5baa4cb25ba77726f1fd4fcd7492e3 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 1 Aug 2008 19:33:55 -0400 Subject: [PATCH] effectManager created --- src/Entities/PhysicsEntity.cpp | 15 ++++++--------- src/Entities/PhysicsEntity.h | 3 --- src/Makefile | 1 + src/effectManager.cpp | 18 ++++++++++++++++++ src/effectManager.h | 14 ++++++++++++++ 5 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/effectManager.cpp create mode 100644 src/effectManager.h diff --git a/src/Entities/PhysicsEntity.cpp b/src/Entities/PhysicsEntity.cpp index 727b89f..fba6a89 100644 --- a/src/Entities/PhysicsEntity.cpp +++ b/src/Entities/PhysicsEntity.cpp @@ -2,18 +2,15 @@ #include "../debug.h" #include "../Vector2.h" -#include "../Effects/Effect.h" -#include "../Effects/Gravity.h" +#include "../effectManager.h" /// ***** Public Class Methods ***** PhysicsEntity::PhysicsEntity(const Vector2& pos) : Entity(pos), force(0,0), mass(1), CoR(1) { - g = new Gravity(); } PhysicsEntity::~PhysicsEntity() { - delete g; } void PhysicsEntity::update(float time_step) @@ -30,9 +27,9 @@ Vector2 PhysicsEntity::positionAt(float time_step) const Vector2 newVelocity = velocity; Vector2 newForce = force; - newPosition += g->positionDelta(this, time_step); - newVelocity += g->velocityDelta(this, time_step); - newForce += g->forceDelta(this, time_step); + newPosition += effect::positionDelta(this, time_step); + newVelocity += effect::velocityDelta(this, time_step); + newForce += effect::forceDelta(this, time_step); return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition; } @@ -42,8 +39,8 @@ Vector2 PhysicsEntity::velocityAt(float time_step) const Vector2 newForce = force; Vector2 newVelocity = velocity; - newForce += g->forceDelta(this, time_step); - newVelocity += g->velocityDelta(this, time_step); + newForce += effect::forceDelta(this, time_step); + newVelocity += effect::velocityDelta(this, time_step); return newForce/mass / 2 * time_step + newVelocity; } diff --git a/src/Entities/PhysicsEntity.h b/src/Entities/PhysicsEntity.h index 4df29b3..85c0558 100644 --- a/src/Entities/PhysicsEntity.h +++ b/src/Entities/PhysicsEntity.h @@ -2,7 +2,6 @@ #define PHYSICS_H #include "Entity.h" -#include "../Effects/Effect.h" #include "../Vector2.h" /// ***** Header Class ***** @@ -29,8 +28,6 @@ class PhysicsEntity: public Entity // Coefficient of Restitution float CoR; - - Effect* g; }; #endif // PHYSICS_H diff --git a/src/Makefile b/src/Makefile index 6d5b94e..b399061 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,6 +14,7 @@ TARGET := ../run_physics SRCS := # simply to keep every line below the same SRCS += entityManager.cpp +SRCS += effectManager.cpp SRCS += entityCreator.cpp SRCS += game.cpp SRCS += main.cpp diff --git a/src/effectManager.cpp b/src/effectManager.cpp new file mode 100644 index 0000000..ab13b25 --- /dev/null +++ b/src/effectManager.cpp @@ -0,0 +1,18 @@ +#include "effectManager.h" + +#include "Effects/Gravity.h" + +Gravity* g = new Gravity(); + +Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) +{ + return g->positionDelta(e, time_step); +} +Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step) +{ + return g->velocityDelta(e, time_step); +} +Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step) +{ + return g->forceDelta(e, time_step); +} diff --git a/src/effectManager.h b/src/effectManager.h new file mode 100644 index 0000000..e8ba499 --- /dev/null +++ b/src/effectManager.h @@ -0,0 +1,14 @@ +#ifndef EFFECTMANAGER_H +#define EFFECTMANAGER_H + +#include "Vector2.h" +#include "Entities/PhysicsEntity.h" + +/// ***** Header Methods ***** +namespace effect +{ + Vector2 positionDelta(const PhysicsEntity*, float); + Vector2 velocityDelta(const PhysicsEntity*, float); + Vector2 forceDelta(const PhysicsEntity*, float); +} +#endif // EFFECTMANAGER_H -- 2.10.2