diff --git a/.vscode/settings.json b/.vscode/settings.json index 2dac349..7960908 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -48,6 +48,9 @@ "xstddef": "cpp", "xtr1common": "cpp", "xutility": "cpp", - "iostream": "cpp" + "iostream": "cpp", + "list": "cpp", + "unordered_set": "cpp", + "xhash": "cpp" } } \ No newline at end of file diff --git a/3DTest/SynGame.hpp b/3DTest/SynGame.hpp new file mode 100644 index 0000000..ef4c81a --- /dev/null +++ b/3DTest/SynGame.hpp @@ -0,0 +1,12 @@ +#ifndef SynClasses + #define SynClasses + + #define DegToRad 0.0174533 + + #include + #include + #include + #include + #include "Timer.hpp" + #include "Window.hpp" +#endif diff --git a/3DTest/Timer.hpp b/3DTest/Timer.hpp new file mode 100644 index 0000000..f390413 --- /dev/null +++ b/3DTest/Timer.hpp @@ -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; +} diff --git a/3DTest/Window.hpp b/3DTest/Window.hpp new file mode 100644 index 0000000..8d0ab56 --- /dev/null +++ b/3DTest/Window.hpp @@ -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(); +} diff --git a/3DTest/main.cpp b/3DTest/main.cpp new file mode 100644 index 0000000..b072ccb --- /dev/null +++ b/3DTest/main.cpp @@ -0,0 +1,11 @@ +#include "SynGame.hpp" + +int main() +{ + Window window; + + while (window.IsOpen()) + window.Update(); + + return 0; +} diff --git a/3DTest/makefile b/3DTest/makefile new file mode 100644 index 0000000..57b0d83 --- /dev/null +++ b/3DTest/makefile @@ -0,0 +1,2 @@ +main.exe : *.cpp + g++ -o main.exe *.cpp ../SFML/*.a \ No newline at end of file