All pastes #2106649 Raw Edit

Miscellany

public cpp v1 · immutable
#2106649 ·published 2012-01-26 23:43 UTC
rendered paste body
#include "game.hpp"Game::Game () :    display (NULL),    equeue  (NULL),    running (true){}Game::~Game (){}void Game::Init (){    if (!_al_init(OPT_AL_ALL)) {        throw std::runtime_error (std::string("An error has occured whitin _al_init(OPT_AL_ALL)"));    }    display = al_create_display (1024, 768);    if (!display) {        throw std::runtime_error ("Could not create display.");    }    equeue = al_create_event_queue ();    al_register_event_source (equeue, al_get_keyboard_event_source());    al_register_event_source (equeue, al_get_mouse_event_source());    al_register_event_source (equeue, al_get_display_event_source(display));    al_set_window_title (display, "Mazer!");    grid = new Grid(10, 10, 16);    grid->Start ();}void Game::Run (){    const float fixedDelta = 0.01f;    float currentTime = al_current_time ();    float accumulator = 0.0f;    float _time = 0.0f;    ALLEGRO_EVENT event;    while (running)    {        float newTime   = al_current_time ();        float deltaTime = newTime - currentTime;        al_rest (fixedDelta - deltaTime);        deltaTime   = newTime - currentTime;        currentTime = newTime;        accumulator += deltaTime;        while (accumulator >= fixedDelta)        {            while (al_get_next_event(equeue, &event))            {                switch (event.type)                {                    case ALLEGRO_EVENT_DISPLAY_CLOSE:                        running = false;                        break;                    case ALLEGRO_EVENT_KEY_DOWN:                        if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {                            running = false;                        }                        break;                }                /**                * Event handling                */            }            /**            * Logic            */            //            _time       += fixedDelta;            accumulator -= fixedDelta;            grid->Update();        }        /**        * Drawing        */        al_clear_to_color (al_map_rgb(255, 255, 255));        grid->Draw();        al_flip_display ();    }}void Game::Deinit (){    delete grid;    if (al_is_system_installed()) {        al_uninstall_system ();    }}