I was reading that in a Mac OS X, i'm only able to run window and handle events within the main thread. I'm not sure i understand that! According to the wiki, the main thread is main function. What classifies another form of thread? I havent touch that topic of threads in my C++ book, nor do i think they talk about it.
Here is my code and how i have it orientated.
//
// Engine.hpp
// RetroPongGame
//
// Created by Jonathan Vazquez on 3/22/17.
// Copyright © 2017 Jonathan Vazquez. All rights reserved.
//
#ifndef Engine_hpp
#define Engine_hpp
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
class Engine{
public:
Engine();
~Engine();
void gameLoop();
void eventHandler();
void render();
private:
std::string winTitle;
unsigned int winHeight, winWidth;
sf::RenderWindow window;
};
#endif /* Engine_hpp */
//
// Engine.cpp
// RetroPongGame
//
// Created by Jonathan Vazquez on 3/22/17.
// Copyright © 2017 Jonathan Vazquez. All rights reserved.
//
#include "Engine.hpp"
Engine::Engine(): winTitle("Retro Pong Game v2.0"),winHeight(800),winWidth(1200){
window.create(sf::VideoMode(winWidth, winHeight), winTitle, sf::Style::Titlebar | sf::Style::Close);
window.setVerticalSyncEnabled(true);
}
Engine::~Engine(){
}
void Engine::gameLoop(){
while(window.isOpen()){
eventHandler();
}
// Clear screen
window.clear();
//rendering
render();
// Update the window
window.display();
}
void Engine::eventHandler(){
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed)
window.close();
// Escape pressed: exit
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
window.close();
}
}
void Engine::render(){
// Draw the sprite
//window.draw(sprite);
// Draw the string
// window.draw(text);
}
#include "Engine.hpp"
// Here is a small helper for you! Have a look.
#include "ResourcePath.hpp"
int main(int, char const**)
{
Engine engine;
engine.gameLoop();
return EXIT_SUCCESS;
}
Which is the main thread and which isnt? Is the thread classified by a function or by extra files?