Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Game.cpp
- #include <stdio.h>
- #include <allegro5/allegro.h>
- #include "Managers.hpp"
- int main(int argc, char **argv)
- {
- if(!al_init()) {
- fprintf(stderr, "Failed to initialize Allegro\n");
- return -1;
- }
- EventManager *emanager;
- DisplayManager *display;
- emanager->registerSources();
- display->registerDisplay();
- return 0;
- }
- // Managers.cpp
- #include <stdio.h>
- #include <allegro5/allegro.h>
- #include "Managers.hpp"
- /* Self built manager to seperate out into the MVC model as much as possible */
- EventManager::EventManager()
- {
- ALLEGRO_EVENT_QUEUE *event_queue = NULL; // The event queue declaration
- ALLEGRO_TIMER *timer = NULL;
- float FPS = 60;
- }
- EventManager::~EventManager()
- {
- al_destroy_event_queue(event_queue);
- al_destroy_timer(timer);
- }
- int EventManager::registerSources() // register all the sources for input: Mouse, Keyboard, Gamepad.
- {
- if(!al_install_mouse()){
- fprintf(stderr, "Failed to initialize the Mouse\n");
- return -1;
- }
- if(!al_install_keyboard()){
- fprintf(stderr, "Failed to initialize the Keyboard\n");
- return -1;
- }
- timer = al_create_timer(1.0 / FPS);
- if(!timer) {
- fprintf(stderr, "Failed to create timer \n");
- return -1;
- }
- event_queue = al_create_event_queue();
- if(!event_queue) {
- fprintf(stderr, "Failed to create the Event Queue\n");
- return -1;
- }
- al_register_event_source(event_queue, al_get_mouse_event_source());
- al_register_event_source(event_queue, al_get_keyboard_event_source());
- }
- /* Manager to handle the display end of things. Essentially the view. */
- Displaymanager::DisplayManager()
- {
- float FPS = 60;
- int SCREEN_W = 640;
- int SCREEN_H = 480;
- bool redraw = true;
- ALLEGRO_DISPLAY *display = NULL;
- ALLEGRO_TIMER *timer = NULL;
- ALLEGRO_EVENT_QUEUE *event_queue = NULL;
- }
- DisplayManager::~DisplayManager()
- {
- al_destroy_display(display);
- al_destory_timer(timer);
- al_destroy_event_queue(event_queue);
- }
- int DisplayManager::registerDisplay()
- {
- timer = al_create_timer(1.0/FPS);
- if(!timer) {
- fprintf(stderr, "Faile to Create DisplayManager Timer\n");
- al_destroy_timer(timer);
- return -1;
- }
- display = al_create_display();
- if(!display) {
- fprintf(stderr, "Failed to create the Display \n");
- al_destory_display(display);
- al_destory_timer(timer);
- return -1;
- }
- event_queue = al_create_event_queue();
- if(!event_queue) {
- fprintf(stderr, "Failed to create the Display Event_Queue/n");
- al_destory_event_queue(event_queue);
- al_destory_timer(timer);
- al_destory_display(display);
- return -1;
- }
- al_register_event_source(event_queue, al_get_display_event_source(display));
- al_regisger_event_source(event_queue, al_get_timer_event_source(timer));
- }
- void DisplayManager::Draw()
- {
- al_flip_display();
- }
- // Managers.hpp
- #ifndef ALL_MANAGER //if ALL_MANAGER hasn't been defnined yet
- #define ALL_MANAGER
- class EventManager
- /* Self built manager to separate out the program into the MVC model as much as possible. */
- {
- public:
- EventManager();
- ~EventManager();
- int registerSources();
- };
- class DisplayManager
- /* Display manager to handle the drawing methods. Essentially a view */
- {
- public:
- DisplayManager();
- ~DisplayManager();
- int registerDisplay();
- void Draw();
- };
- #endif // ALL_MANAGER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement