Created
March 2, 2014 12:29
-
-
Save jdiez17/9305867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics/RenderWindow.hpp> | |
#include <SFML/System/Clock.hpp> | |
#include <SFML/Window/Event.hpp> | |
#include <dlfcn.h> | |
#include <iostream> | |
#include "game.hpp" | |
void* handle; | |
Game* create_game() { | |
if(handle) | |
dlclose(handle); | |
handle = dlopen("./libgame.so", RTLD_LAZY); | |
Game* (*create)(); | |
create = (Game* (*)())dlsym(handle, "create_game"); | |
return create(); | |
} | |
int main() { | |
Game* game = create_game(); | |
sf::RenderWindow window(sf::VideoMode(200, 200), "Particles"); | |
sf::Clock clock; | |
window.setFramerateLimit(60); | |
window.setVerticalSyncEnabled(true); | |
while(window.isOpen()) { | |
sf::Event ev; | |
while(window.pollEvent(ev)) { | |
if(ev.type == sf::Event::Closed) { | |
window.close(); | |
} | |
if(ev.type == sf::Event::KeyPressed) { | |
game = create_game(); | |
} | |
} | |
game->MouseUpdate(window.mapPixelToCoords(sf::Mouse::getPosition(window))); | |
sf::Time dt = clock.restart(); | |
game->Update(dt); | |
window.clear(); | |
window.draw(*game); | |
window.display(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment