renamed a few more members and changed some switch statements
authorPatrik Gornicz <Gornicz.P@gmail.com>
Tue, 1 Sep 2009 02:03:45 +0000 (22:03 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Tue, 1 Sep 2009 02:03:45 +0000 (22:03 -0400)
src/Effects/GravityWell.cpp
src/Effects/GravityWell.h
src/Entities/Ball.cpp
src/Entities/Entity.cpp
src/Entities/Entity.h
src/Entities/Particle.cpp
src/Entities/PhysicsEntity.cpp
src/Entities/Point.cpp
src/Entities/Point.h
src/Entities/WindParticle.h
src/input/inputManager.cpp

index a573632..38711eb 100644 (file)
@@ -23,7 +23,7 @@ float wellGravity = 0.5;
 /// ***** Constructors/Destructors *****
 
 GravityWell::GravityWell(const Vector2& pos)
-    : position(pos)
+    : m_position(pos)
 {
 
 }
@@ -39,7 +39,7 @@ Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const
     const Vector2& pos = e->positionRaw();
     float mass = e->m_mass;
 
-    Vector2 delta = position - pos;
+    Vector2 delta = m_position - pos;
     float sqrDist = delta.sqrLength();
 
     Vector2 acc(0,0);
@@ -52,5 +52,5 @@ Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const
 
 void GravityWell::setPosition(const Vector2& pos)
 {
-    position = pos;
+    m_position = pos;
 }
index 1d9f7e5..a23574a 100644 (file)
@@ -37,7 +37,7 @@ class GravityWell: public Effect
     void setPosition(const Vector2&);
 
   private:
-    Vector2 position;
+    Vector2 m_position;
 };
 
 #endif // GRAVITYWELL_H
index 750b2e5..e235739 100644 (file)
@@ -40,7 +40,7 @@ Ball::~Ball()
 
 void Ball::draw() const
 {
-    graphics::drawCircle(m_radius, position, m_color);
+    graphics::drawCircle(m_radius, m_position, m_color);
 }
 
 float Ball::getRadius() const
index ae04514..9b630a7 100644 (file)
@@ -24,7 +24,7 @@ using namespace bear;
 /// ***** Constructors/Destructors *****
 
 Entity::Entity(const Vector2& pos)
-  : position(pos), velocity(0,0)
+  : m_position(pos), m_velocity(0,0)
 {
 
 }
@@ -37,10 +37,10 @@ Entity::~Entity()
 
 const Vector2& Entity::positionRaw() const
 {
-    return position;
+    return m_position;
 }
 const Vector2& Entity::velocityRaw() const
 {
-    return velocity;
+    return m_velocity;
 }
 
index ff1db58..8e70b99 100644 (file)
@@ -39,8 +39,8 @@ class Entity
     const Vector2& velocityRaw() const;
 
   protected:
-    Vector2 position;
-    Vector2 velocity;
+    Vector2 m_position;
+    Vector2 m_velocity;
 };
 
 #endif // ENTITY_H
index d84ce75..c978d38 100644 (file)
@@ -50,5 +50,5 @@ void Particle::update(float time_step)
         m_lifeTime -= time_step;
         m_isDead = m_lifeTime <= 0;
     }
-    position += velocity * time_step;
+    m_position += m_velocity * time_step;
 }
index b43874b..752d5eb 100644 (file)
@@ -40,16 +40,16 @@ PhysicsEntity::~PhysicsEntity()
 
 void PhysicsEntity::update(float time_step)
 {
-    position = positionAt(time_step);
-    velocity = velocityAt(time_step);
+    m_position = positionAt(time_step);
+    m_velocity = velocityAt(time_step);
 
     m_force *= 0;
 }
 
 Vector2 PhysicsEntity::positionAt(float time_step) const
 {
-    Vector2 newPosition = position;
-    Vector2 newVelocity = velocity;
+    Vector2 newPosition = m_position;
+    Vector2 newVelocity = m_velocity;
     Vector2 newForce = m_force;
 
     newPosition += effect::positionDelta(this, time_step);
@@ -62,7 +62,7 @@ Vector2 PhysicsEntity::positionAt(float time_step) const
 Vector2 PhysicsEntity::velocityAt(float time_step) const
 {
     Vector2 newForce = m_force;
-    Vector2 newVelocity = velocity;
+    Vector2 newVelocity = m_velocity;
 
     newForce += effect::forceDelta(this, time_step);
     newVelocity += effect::velocityDelta(this, time_step);
@@ -72,7 +72,7 @@ Vector2 PhysicsEntity::velocityAt(float time_step) const
 
 void PhysicsEntity::applyForce(const Vector2& force)
 {
-    applyForce(force, position);
+    applyForce(force, m_position);
 }
 void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/)
 {
@@ -81,14 +81,14 @@ void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/)
 
 void PhysicsEntity::applyImpulse(const Vector2& impulse)
 {
-    applyImpulse(impulse, position);
+    applyImpulse(impulse, m_position);
 }
 void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& /*at*/)
 {
-    velocity += impulse;
+    m_velocity += impulse;
 }
 
 void PhysicsEntity::applyNudge(const Vector2& vecPush)
 {
-    position += vecPush;
+    m_position += vecPush;
 }
index 58dd0da..b62e894 100644 (file)
@@ -24,12 +24,12 @@ using namespace bear;
 /// ***** Constructors/Destructors *****
 
 Point::Point(const Vector2& org, bool canDie)
-    : Particle(org, canDie), radius(2)
+    : Particle(org, canDie), m_radius(2)
 {
 
 }
 Point::Point(const Vector2& org, float life_time)
-    : Particle(org, life_time), radius(2)
+    : Particle(org, life_time), m_radius(2)
 {
 
 }
index 901040f..bfc83f3 100644 (file)
@@ -36,7 +36,7 @@ class Point: public Particle
         virtual void draw();
 
      protected:
-        float radius;
+        float m_radius;
         // color
 };
 
index 560e660..9893dee 100644 (file)
@@ -35,7 +35,7 @@ class WindParticle: public Point
         virtual void update(float);
 
      protected:
-        float radius;
+        float m_radius;
         // color
 };
 
index 23b945c..1ba4147 100644 (file)
@@ -42,8 +42,11 @@ static State keyState[keySize];
 
 void input::init()
 {
+    // default all keys to released
     for(int i=0; i< keySize; i++)
+    {
         keyState[i] = isR;
+    }
 }
 void input::clean()
 {
@@ -58,29 +61,38 @@ void input::update()
 {
     SDL_Event event;
 
-    for(int i=0; i< keySize; i++)
+    for(int i=0; i < keySize; i++)
     {
-        if(keyState[i] == wasR)
-            keyState[i] = isR;
-        else if(keyState[i] == wasP)
-            keyState[i] = isP;
+        State newKeyState;
+
+        switch(keyState[i])
+        {
+          case isR:   newKeyState = isR;    break;
+          case wasR:  newKeyState = isR;    break;
+          case isP:   newKeyState = isP;    break;
+          case wasP:  newKeyState = isP;    break;
+          default:    DASSERT(false);       return;
+        }
+
+        keyState[i] = newKeyState;
     }
 
     while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask))
     {
         switch(event.type)
         {
-        case SDL_KEYUP:
-            keyState[event.key.keysym.sym] = wasR;
-            break;
-        case SDL_KEYDOWN:
-            keyState[event.key.keysym.sym] = wasP;
-            break;
-        case SDL_QUIT:
-            keyState[key::end] = wasR;
-            break;
-        default:
-            break;
+            case SDL_KEYUP:
+                keyState[event.key.keysym.sym] = wasR;
+                break;
+            case SDL_KEYDOWN:
+                keyState[event.key.keysym.sym] = wasP;
+                break;
+            case SDL_QUIT:
+                // HACK: simulate an SDL_QUIT event as an ESC key press
+                keyState[key::end] = wasR;
+                break;
+            default:
+                break; // somthing I don't care about
         }
     }
 }