-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
65 lines (50 loc) · 1.72 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <SFML/Graphics.hpp>
#include "ParticleEngine.h"
#include <Windows.h>
//Constant Game Speed indepenent of Variable FPS Game Loop implementation
//USING: http://www.koonsolo.com/news/dewitters-gameloop/
//TICKS_PER_SECOND = Update Speed
const int TICKS_PER_SECOND = 60;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Initialize variables to regulate update speed
sf::Clock clock;
int nextGameTick = clock.getElapsedTime().asMilliseconds();
int loops;
float interpolation;
//--------------------------------------------
sf::RenderWindow window(sf::VideoMode(640, 480), "Particle Engine Test!");
ParticleEngine particleEngine(sf::Vector2f(-300,300),500, sf::Color::Black);
particleEngine.setSize(10);
while (window.isOpen())
{
particleEngine.setDrawType(eRANDOM);
loops = 0;
window.clear();
sf::Vector2i mouse = sf::Mouse::getPosition(window);
particleEngine.setEmitterLocation(window.mapPixelToCoords(mouse));
sf::Event event;
//input here
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
//controls update speed
while (clock.getElapsedTime().asMilliseconds() > nextGameTick && loops < MAX_FRAMESKIP)
{
//updates here
particleEngine.Update(0.15f);
nextGameTick += SKIP_TICKS;
loops++;
}
//calculate interpolation to (try to) smooth rendering between update
interpolation = float(clock.getElapsedTime().asMilliseconds() + SKIP_TICKS - nextGameTick)
/ float(SKIP_TICKS);
//draw methods here
particleEngine.Draw(&window, interpolation);
window.display();
}
}