3
« on: March 08, 2012, 02:32:45 am »
Well, as explained in the title I'm trying to do this abiding by the rules of the clock and sf::sleep, atm I have the following code.
/*
* main.cpp
*
* Created on: 5 Mar 2012
* Author: Lee
*/
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <vector>
#include "InGameHandle/inGame.hpp"
#include "InGameHandle/gameStateBase.hpp"
class EngineMain{
private:
sf::VideoMode myVideoMode;
sf::RenderWindow myWindow;
sf::Clock gameClock;
sf::Clock fpsClock;
sf::Clock lpsClock;
GameStateBase* applicationIsInPointer;
float constantFPS;
float constantLPS;
float lastTime;
bool draw;
public:
void init(float _fps, float _lps)
{
constantFPS = _fps;
constantLPS = _lps;
draw = false;
myVideoMode.Width = 1024;
myVideoMode.Height = 768;
myVideoMode.BitsPerPixel = 16;
myWindow.Create(myVideoMode, "hello");
applicationIsInPointer = new InGameHandler;
appRunning();
}
void appRunning()
{
//Game init
applicationIsInPointer->init();
while (myWindow.IsOpen())
{
sf::Event event;
while(myWindow.PollEvent(event))
{
switch(event.Type)
{
case sf::Event::Closed:
myWindow.Close();
break;
default:
break;
}
}
if(lpsClock.GetElapsedTime().AsMilliseconds() > constantLPS)
{
applicationIsInPointer->logic();
//Update the logic of the game
lastTime = lpsClock.GetElapsedTime().AsMilliseconds();
lpsClock.Restart();
}
if(fpsClock.GetElapsedTime().AsMilliseconds() > constantFPS)
{
myWindow.Clear();
//Return EVERYTHING that needs to be drawn from the game here
applicationIsInPointer->draw();
//Then for loop through it and draw it
myWindow.Display();
fpsClock.Restart();
}
sf::Sleep(sf::Milliseconds(lastTime));
}
}
};
int main()
{
EngineMain engine;
engine.init(60,60);
}
I know I'm doing a lot wrong here, but can someone help me out with this and explain the logical steps so I can learn?
You may be wondering why I'm not using "Set frame limit", this is because it doesn't appear to set the frame limit correctly or reliably on my PC.