Remove global variables.
Global variables are overall bad practice.
This commit is contained in:
parent
0faa83c162
commit
80113d51ff
@ -21,11 +21,9 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
#include <allegro5/allegro.h>
|
|
||||||
|
|
||||||
ALLEGRO_DISPLAY *display;
|
int create_display(ALLEGRO_DISPLAY *display,
|
||||||
|
unsigned int width, unsigned int height) {
|
||||||
int create_display(unsigned int width, unsigned int height) {
|
|
||||||
display = al_create_display(width, height);
|
display = al_create_display(width, height);
|
||||||
if(!display)
|
if(!display)
|
||||||
return 0;
|
return 0;
|
||||||
@ -35,7 +33,7 @@ int create_display(unsigned int width, unsigned int height) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_display() {
|
void destroy_display(ALLEGRO_DISPLAY *display) {
|
||||||
al_destroy_display(display);
|
al_destroy_display(display);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("Destroyed display.");
|
puts("Destroyed display.");
|
||||||
|
@ -18,17 +18,23 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <allegro5/allegro.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create an allegro 5 display with a given width and height.
|
* @brief Create an allegro 5 display with a given width and height.
|
||||||
*
|
*
|
||||||
|
* @param display The display to create.
|
||||||
* @param width The width of the display.
|
* @param width The width of the display.
|
||||||
* @param height The height of the display.
|
* @param height The height of the display.
|
||||||
*
|
*
|
||||||
* @return If successful it will return 1, else it will return 0.
|
* @return If successful it will return 1, else it will return 0.
|
||||||
*/
|
*/
|
||||||
int create_display(unsigned int width, unsigned int height);
|
int create_display(ALLEGRO_DISPLAY *display,
|
||||||
|
unsigned int width, unsigned int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the display (used for shutdown).
|
* @brief Destroy the display (used for shutdown).
|
||||||
|
*
|
||||||
|
* @param display The display to destroy.
|
||||||
*/
|
*/
|
||||||
void destroy_display();
|
void destroy_display(ALLEGRO_DISPLAY *display);
|
||||||
|
@ -29,7 +29,7 @@ static ALLEGRO_EVENT_QUEUE *event_queue;
|
|||||||
static ALLEGRO_TIMER *timer;
|
static ALLEGRO_TIMER *timer;
|
||||||
static int keys[KEY_MAX];
|
static int keys[KEY_MAX];
|
||||||
|
|
||||||
int evnt_mngr_init() {
|
int evnt_mngr_init(ALLEGRO_DISPLAY *display) {
|
||||||
if(!al_install_keyboard())
|
if(!al_install_keyboard())
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <allegro5/allegro.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
KEY_UP = 0x0,
|
KEY_UP = 0x0,
|
||||||
KEY_DOWN = 0x1,
|
KEY_DOWN = 0x1,
|
||||||
@ -33,7 +35,7 @@ enum {
|
|||||||
*
|
*
|
||||||
* @return 0 upon failure, 1 upon success.
|
* @return 0 upon failure, 1 upon success.
|
||||||
*/
|
*/
|
||||||
int evnt_mngr_init();
|
int evnt_mngr_init(ALLEGRO_DISPLAY *display);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Deinitialize the event handler.
|
* @brief Deinitialize the event handler.
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include <allegro5/allegro.h>
|
#include <allegro5/allegro.h>
|
||||||
|
|
||||||
extern ALLEGRO_DISPLAY *display; ///< The allegro display.
|
|
||||||
|
|
||||||
extern int redraw; ///< Whether or not to redraw the screen.
|
extern int redraw; ///< Whether or not to redraw the screen.
|
||||||
extern int run; ///< Whether or not to continue running the simulation.
|
extern int run; ///< Whether or not to continue running the simulation.
|
||||||
extern int show_help; ///< Whether or not to show the help info.
|
extern int show_help; ///< Whether or not to show the help info.
|
||||||
|
10
src/main.c
10
src/main.c
@ -43,16 +43,18 @@ int main() {
|
|||||||
fprintf(stderr, "alleg5: failed to initialize primitives addon.\n");
|
fprintf(stderr, "alleg5: failed to initialize primitives addon.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(!create_display(800, 600))
|
|
||||||
|
ALLEGRO_DISPLAY *display;
|
||||||
|
if(!create_display(display, 800, 600))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "alleg5: failed to create display.\n");
|
fprintf(stderr, "alleg5: failed to create display.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!evnt_mngr_init())
|
if(!evnt_mngr_init(display))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "alleg5: failed to initialize event queue.\n");
|
fprintf(stderr, "alleg5: failed to initialize event queue.\n");
|
||||||
destroy_display();
|
destroy_display(display);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +97,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
evnt_mngr_deinit();
|
evnt_mngr_deinit();
|
||||||
destroy_display();
|
destroy_display(display);
|
||||||
al_shutdown_primitives_addon();
|
al_shutdown_primitives_addon();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("Shutdown primitives addon.");
|
puts("Shutdown primitives addon.");
|
||||||
|
Loading…
Reference in New Issue
Block a user