Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <SFML/Window.hpp>
- // ============================================================================
- bool gameActive = true;
- sf::Mutex mutexWindow;
- // ============================================================================
- class GameThread: public sf::Thread
- {
- public:
- GameThread(sf::Window& window)
- :window(window)
- {
- }
- virtual ~GameThread() {}
- private:
- sf::Window& window;
- virtual void Run()
- {
- const sf::Input& input = window.GetInput();
- sf::Clock clock;
- while (gameActive) {
- float elapsedTime = clock.GetElapsedTime();
- if (elapsedTime < .01f) {
- sf::Sleep(.01f - elapsedTime);
- }
- elapsedTime = clock.GetElapsedTime();
- clock.Reset();
- }
- }
- };
- // ============================================================================
- class RenderThread: public sf::Thread
- {
- public:
- RenderThread(sf::Window& window)
- :window(window)
- {
- }
- virtual ~RenderThread() {}
- private:
- sf::Window& window;
- virtual void Run()
- {
- while (gameActive) {
- // sf::Lock lock(mutexWindow);
- window.SetActive(true);
- glClear(GL_COLOR_BUFFER_BIT);
- window.Display();
- // window.SetActive(false);
- }
- }
- };
- // ============================================================================
- int main(int argc, char **argv)
- {
- sf::Window window(sf::VideoMode(1024, 768, 32), "Gaya", sf::Style::Close);
- window.SetActive(false);
- window.UseVerticalSync(true);
- bool mouseCaptured = false;
- int windowWidthHalf = window.GetWidth() >> 1;
- int windowHeightHalf = window.GetHeight() >> 1;
- // GameThread gameThread(window);
- // gameThread.Launch();
- RenderThread renderThread(window);
- renderThread.Launch();
- sf::Clock clock;
- sf::Event event;
- while (gameActive) {
- float elapsedTime = clock.GetElapsedTime();
- if (elapsedTime < .01f) {
- sf::Sleep(.01f - elapsedTime);
- }
- elapsedTime = clock.GetElapsedTime();
- clock.Reset();
- {
- // sf::Lock lock(mutexWindow);
- // window.SetActive(true);
- while (window.GetEvent(event)) {
- if (event.Type == sf::Event::Closed) {
- gameActive = false;
- }
- // if (mouseCaptured) {
- // if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Escape) {
- // window.ShowMouseCursor(true);
- // mouseCaptured = false;
- // }
- // } else {
- // if (event.Type == sf::Event::MouseButtonPressed && event.MouseButton.Button == 0) {
- // window.ShowMouseCursor(false);
- // mouseCaptured = true;
- // }
- // }
- }
- // if (mouseCaptured) {
- // window.SetCursorPosition(windowWidthHalf, windowHeightHalf);
- // }
- // window.SetActive(false);
- }
- }
- // gameThread.Wait();
- renderThread.Wait();
- window.Close();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement