added fps noted significant and unexplained speed change
authorunknown <Ivan Lloyd@.(none)>
Sun, 30 Jan 2011 21:55:35 +0000 (15:55 -0600)
committerunknown <Ivan Lloyd@.(none)>
Sun, 30 Jan 2011 21:55:35 +0000 (15:55 -0600)
updated dcumentation

Collision.cpp
Collision.h
Frame.h
Game.cpp
Game.h
Level.cpp
Level.h

index a49d69e..68f9bd8 100644 (file)
@@ -73,7 +73,8 @@ void DrawPixel(SDL_Surface *screen, int x, int y, Uint32 c)
 /**
        This function is tasked with drawing the 8 points on a circle so that only 1/8th need be calculated. 
        \param screen the Screen
-       \param pos This is the position to draw the points (not & because may want to have an added value pushed in)
+       \param wPos This is the world position to draw the points (not & because may want to have an added value pushed in)
+       \param pos This is the relative position to draw the points (not & because may want to have an added value pushed in)
        \param color the color to be drawn
 */
 void DrawCircle(SDL_Surface* screen, const Point2D wPos, const Point2D pos, Uint32 color){
@@ -197,7 +198,7 @@ bool CollisionRectangle::collision(const Collision *c, const Point2D cPos, const
                
        }
        else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
-               ///col->collision(this, cPos, pos); \todo this flips a shit!!!!!!
+               ///col->collision(this, cPos, pos);/// \todo this flips a shit!!!!!!
        }
        
        return false;
index 3cfba1b..c13fdd1 100644 (file)
@@ -99,7 +99,7 @@ public:
                \param pos the current sprite's position.
                \return Returns true if any of the object's collision datas are colliding  .
        */
-       bool collision(const CollisionRectangle*, const Point2D cPos, const Point2D pos);/**< This does collision between Rectangles and Circles */
+       bool collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos);/**< This does collision between Rectangles and Circles */
        virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
 };
 #endif
diff --git a/Frame.h b/Frame.h
index e2628da..5044066 100644 (file)
--- a/Frame.h
+++ b/Frame.h
@@ -12,7 +12,7 @@ struct SpriteFrame{
        int width;/**< Base width of the frame's image. \todo make this and animation's match or at least sync or delete*/
        int height;/**< Base height of the frame's image. \todo make this and animation's match or at least sync or delete*/
        vector<Point2D> hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/
-       Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */
+       Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) */
        vector<Collision*> collisionData;/**< The collision data for this sprite */
 };
 
index 85fedd8..3d38db4 100644 (file)
--- a/Game.cpp
+++ b/Game.cpp
@@ -10,8 +10,8 @@ const Uint32 Game::waitTime = 1000/60; /* ms */
 Game* Game::m_instance = NULL;
 
 /** This function is called to create an instance of the class.
-    Calling the constructor publicly is not allowed.
-       The constructor is private and is only called by this Instance function.
+Calling the constructor publicly is not allowed.
+The constructor is private and is only called by this Instance function.
 */
 Game* Game::game(){
        if(!m_instance)
@@ -19,7 +19,7 @@ Game* Game::game(){
        return m_instance;
 }
 
-Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false)
+Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false), ShowFPS(false), startclock(0), deltaclock(0), currentFPS(0)
 {
        /** Initialize SDL */
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
@@ -45,7 +45,8 @@ Game::Game() : mCurrentLevel(0), mScreen(0), ShowCollisions(false)
                mLevels.push_back(new Level(mScreen));
        else
                mLevels = l.levels;
-
+       // set start time for fps calc
+       startclock = SDL_GetTicks();
 }
 
 Game::~Game()
@@ -91,9 +92,9 @@ void Game::run()
                }
 
                switch (event.type) {
-               /** If the event is a click on the close button in the top
+                       /** If the event is a click on the close button in the top
                        right corner of the window, we kill the application
-               */
+                       */
                case SDL_QUIT:
                        done = 1;
                        break;
@@ -102,25 +103,34 @@ void Game::run()
                        getCurrentLevel()->drawScene();
                        break;
 
-               /** If our event reports a key being pressed down
-                       we process it
-                */
-               case SDL_KEYDOWN: {
-                       Uint8 *keys = SDL_GetKeyState(NULL);
-                       std::cout<<*keys<<std::endl;
-                       if (keys[SDLK_ESCAPE]) {
-                               done = 1;
-                               break;
-                       }
-                       if (keys[SDLK_F11]) {
-                               ShowCollisions = !ShowCollisions;
+                       /** If our event reports a key being pressed down
+                       we process it
+                       */
+               case SDL_KEYDOWN: 
+                       {
+                               Uint8 *keys = SDL_GetKeyState(NULL);
+                               std::cout<<*keys<<std::endl;
+                               if (keys[SDLK_ESCAPE]) {
+                                       done = 1;
+                                       break;
+                               }
+                               if (keys[SDLK_F11]) {
+                                       ShowCollisions = !ShowCollisions;
+                               }
+                               if (keys[SDLK_F12]) {
+                                       ShowFPS = !ShowFPS;
+                               }
                        }
-               }
                default: /* fallthrough if the key wasn't escape or control*/
                        getCurrentLevel()->postEvent(event);
                        break;
                }
                getCurrentLevel()->update();
+               //obtain the current fps data.
+               deltaclock = SDL_GetTicks() - startclock;
+               startclock = SDL_GetTicks();
+               if ( deltaclock != 0 )
+                       currentFPS = 1000 / deltaclock;
        }
 
        SDL_RemoveTimer(timer);
@@ -142,9 +152,10 @@ Uint32 Game::timerCallback(Uint32 interval, void* data)
                0, /* code */
                0, /* data1 */
                0 }; /* data2 */
-       event.user = uevent;
+               event.user = uevent;
 
-       SDL_PushEvent(&event);
+               SDL_PushEvent(&event);
 
-       return interval;
+               return interval;
 }
+
diff --git a/Game.h b/Game.h
index 802382a..2b467fe 100644 (file)
--- a/Game.h
+++ b/Game.h
@@ -23,6 +23,9 @@ public:
        /** Decides whether or not to draw bounding boxes*/
        bool ShowCollisions;
 
+       /** Decides whether or not to output FPS*/
+       bool ShowFPS;
+
        /**
          Gets the current level being played.
          \return current level
@@ -40,6 +43,10 @@ public:
 
        /** Returns the main screen to allow for drawing */
        SDL_Surface* Screen(){ return mScreen; }
+
+       /** Retrns the Current FPS of the game */
+       Uint32 getFPS() { return currentFPS;}
+
 protected:
        Game();
        ~Game();
@@ -55,6 +62,12 @@ private:
        void loadLevel(std::string levelName);/**< Loads a level by name. */
 
        static Uint32 timerCallback(Uint32 interval, void* data);
+       
+       //fps data calc
+       Uint32 startclock;
+       Uint32 deltaclock;
+       Uint32 currentFPS;
+
 };
 
 #endif
index 5860477..d5ae3e5 100644 (file)
--- a/Level.cpp
+++ b/Level.cpp
@@ -106,9 +106,12 @@ void Level::postEvent(SDL_Event event)
 
 /** Will handle all movement and dynamic triggers. */
 void Level::update(){
-       /// \todo fix this too
+       /// \todo fix this behavior too
        //mBehavior.update();
        
+       if(Game::game()->ShowFPS)
+               cout<<Game::game()->getFPS()<<endl;
+
        //check collision with sun sprite
        mSprites[0]->collisionWithSprite("sun");
 }
diff --git a/Level.h b/Level.h
index c7ecbd0..360c2b0 100644 (file)
--- a/Level.h
+++ b/Level.h
@@ -27,7 +27,18 @@ class Level
 {
 public:
        Level(SDL_Surface *screen);
+       /**
+               Level constructor
+               \param screen the Screen to be drawn to
+               \param name of the level
+       */
        Level(SDL_Surface *screen, string name);
+       /**
+               Level constructor
+               \param screen the Screen to be drawn to
+               \param name of the level
+               \param behavior the Behavior for this level.
+       */
        Level(SDL_Surface *screen, string name, string behavior);
        ~Level();
        void drawScene();/**< Draws everything that is set to draw on the screen. */
@@ -46,7 +57,7 @@ protected://allow inheritance
        Background* mBackground;/**< Pointer to the current Background. */
        SDL_Surface *mScreen;/**< Pointer to the screen. */
        //LevelBehavior mBehavior;/**< will be used to define the start actions, update, and leaving actions of the level */
-       vector<Sprite*> mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented. \todo add accessor or move to public*/
+       vector<Sprite*> mSprites;/**< Vector of all sprites on the level. \todo Maybe make into map? This should be a list of World objects once implemented. \todo add accessor or move to public \todo make a map by name (for collisions) \todo make a list ordered by Zorder (for drawing*/
        map<string,Actor> mActors;/**< This level's actors. */
        vector<Animation> mAnim;/**< This level's Animations */
        void DrawIMG();/**< Draws an image to the screen. (Not used) */