Skip to content

Instantly share code, notes, and snippets.

@jdiez17
Created March 2, 2014 12:29
Show Gist options
  • Save jdiez17/9305867 to your computer and use it in GitHub Desktop.
Save jdiez17/9305867 to your computer and use it in GitHub Desktop.
#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