3D Render First Files
This commit is contained in:
parent
d45db29f4e
commit
84eb390803
|
@ -48,6 +48,9 @@
|
|||
"xstddef": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xutility": "cpp",
|
||||
"iostream": "cpp"
|
||||
"iostream": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"xhash": "cpp"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef SynClasses
|
||||
#define SynClasses
|
||||
|
||||
#define DegToRad 0.0174533
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "Timer.hpp"
|
||||
#include "Window.hpp"
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
#include "SynGame.hpp"
|
||||
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
sf::Clock clock;
|
||||
float deltaTime;
|
||||
float timePassed;
|
||||
public:
|
||||
Timer();
|
||||
void ResetTimer();
|
||||
void UpdateTime();
|
||||
float GetDeltaTime();
|
||||
float GetTimePassed();
|
||||
};
|
||||
|
||||
Timer::Timer()
|
||||
{
|
||||
clock.restart();
|
||||
timePassed = 0.0;
|
||||
deltaTime = 0.0;
|
||||
}
|
||||
|
||||
void Timer::ResetTimer()
|
||||
{
|
||||
clock.restart();
|
||||
timePassed = 0.0;
|
||||
deltaTime = 0.0;
|
||||
}
|
||||
|
||||
void Timer::UpdateTime()
|
||||
{
|
||||
float newTimePassed = clock.getElapsedTime().asSeconds();
|
||||
|
||||
deltaTime = newTimePassed - timePassed;
|
||||
timePassed = newTimePassed;
|
||||
}
|
||||
|
||||
float Timer::GetDeltaTime()
|
||||
{
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
float Timer::GetTimePassed()
|
||||
{
|
||||
return timePassed;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
#include "SynGame.hpp"
|
||||
|
||||
class Window
|
||||
{
|
||||
private:
|
||||
sf::RenderWindow window;
|
||||
sf::Event event;
|
||||
sf::Vector2u size;
|
||||
std::string title;
|
||||
sf::Uint32 style;
|
||||
Timer timer;
|
||||
bool isFocused;
|
||||
public:
|
||||
Window(unsigned int = 960, unsigned int = 540, std::string = "Window", sf::Uint32 = 7U);
|
||||
void CreateWindow();
|
||||
void CloseWindow();
|
||||
void Update();
|
||||
void SetFrameRate(int = 0);
|
||||
void SetTitle(std::string);
|
||||
void SetSize(unsigned int, unsigned int);
|
||||
bool IsOpen();
|
||||
};
|
||||
|
||||
void Window::Update()
|
||||
{
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
CloseWindow();
|
||||
else if (event.type == sf::Event::LostFocus)
|
||||
isFocused = false;
|
||||
else if (event.type == sf::Event::GainedFocus)
|
||||
isFocused = true;
|
||||
}
|
||||
|
||||
if(!isFocused)
|
||||
return;
|
||||
|
||||
timer.UpdateTime();
|
||||
}
|
||||
|
||||
Window::Window(unsigned int width, unsigned int height, std::string title, sf::Uint32 style)
|
||||
{
|
||||
this -> size.x = width;
|
||||
this -> size.y = height;
|
||||
this -> title = title;
|
||||
this -> style = style;
|
||||
isFocused = true;
|
||||
SetFrameRate();
|
||||
CreateWindow();
|
||||
}
|
||||
|
||||
void Window::CreateWindow()
|
||||
{
|
||||
if(window.isOpen())
|
||||
return;
|
||||
|
||||
sf::VideoMode videoMode(size.x, size.y);
|
||||
window.create(videoMode, title, style);
|
||||
timer.ResetTimer();
|
||||
}
|
||||
|
||||
void Window::CloseWindow()
|
||||
{
|
||||
if(!window.isOpen())
|
||||
return;
|
||||
|
||||
window.close();
|
||||
}
|
||||
|
||||
void Window::SetFrameRate(int rate)
|
||||
{
|
||||
if(rate == 0)
|
||||
{
|
||||
window.setVerticalSyncEnabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(rate < 0)
|
||||
window.setFramerateLimit(10000);
|
||||
else
|
||||
window.setFramerateLimit(rate);
|
||||
|
||||
window.setVerticalSyncEnabled(false);
|
||||
}
|
||||
|
||||
void Window::SetTitle(std::string title)
|
||||
{
|
||||
this -> title = title;
|
||||
window.setTitle(title);
|
||||
}
|
||||
|
||||
void Window::SetSize(unsigned int width, unsigned int height)
|
||||
{
|
||||
size = sf::Vector2u(width, height);
|
||||
window.setSize(size);
|
||||
}
|
||||
|
||||
bool Window::IsOpen()
|
||||
{
|
||||
return window.isOpen();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include "SynGame.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Window window;
|
||||
|
||||
while (window.IsOpen())
|
||||
window.Update();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
main.exe : *.cpp
|
||||
g++ -o main.exe *.cpp ../SFML/*.a
|
Loading…
Reference in New Issue