summaryrefslogtreecommitdiff
path: root/src/main/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/engine')
-rw-r--r--src/main/engine/engine.c19
-rw-r--r--src/main/engine/ui/x11/ui.c33
2 files changed, 42 insertions, 10 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c
index 0a4d81d..ab19785 100644
--- a/src/main/engine/engine.c
+++ b/src/main/engine/engine.c
@@ -22,8 +22,8 @@
#include <time.h>
#include <GL/gl.h>
#include <math.h>
+#include <log.h>
#include "engine.h"
-#include "../util.h"
#include "ui/ui.h"
#include "../util/list.h"
#include "types.h"
@@ -34,6 +34,15 @@
#define RANGE_GL 2.0f
+static Log *_log = NULL;
+
+static void
+init_log(void)
+{
+ if (_log != NULL) return;
+ _log = log_create("Engine");
+}
+
static int width;
static int height;
@@ -69,9 +78,11 @@ MouseButtonEvent *mouse_button_event;
void
engine_init(int w, int h)
{
+ init_log();
+
engine = malloc(sizeof(Engine));
if (engine == NULL) {
- log_error("Error allocating memory for engine");
+ log_error(_log, "Error allocating memory for engine");
exit(EXIT_FAILURE);
}
engine->circles = list_create();
@@ -266,9 +277,11 @@ mouse_button_press_event(UIMouseButtonPressed *mbp)
void
engine_set_mouse_button_listener(void (*event)(float x, float y, void *data), void *data)
{
+ init_log();
+
mouse_button_event = malloc(sizeof(MouseButtonEvent));
if (mouse_button_event == NULL) {
- log_error("Error allocating mouse button event");
+ log_error(_log, "Error allocating mouse button event");
exit(EXIT_FAILURE);
}
diff --git a/src/main/engine/ui/x11/ui.c b/src/main/engine/ui/x11/ui.c
index cd35edf..b1086a9 100644
--- a/src/main/engine/ui/x11/ui.c
+++ b/src/main/engine/ui/x11/ui.c
@@ -24,7 +24,7 @@
#include <X11/Xlib.h>
#include <unistd.h>
#include <time.h>
-#include "../../../util.h"
+#include <log.h>
#include "../types.h"
static Display *display;
@@ -40,12 +40,23 @@ void (*on_generic_event)(int);
void cleanup(void);
+static Log *log = NULL;
+
+static void
+init_log(void)
+{
+ if (log != NULL) return;
+ log = log_create("UI");
+}
+
static Display *
ui_open_display(void)
{
+ init_log();
+
Display *display = XOpenDisplay(NULL);
if (!display) {
- log_error("Can't open X11 display");
+ log_error(log, "Can't open X11 display");
exit(1);
}
@@ -55,10 +66,12 @@ ui_open_display(void)
static XVisualInfo *
gl_choose_visual(int screen)
{
+ init_log();
+
GLint attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
XVisualInfo *vi = glXChooseVisual(display, screen, attribs);
if (!vi) {
- log_error("No compatible Visual found");
+ log_error(log, "No compatible Visual found");
exit(1);
}
@@ -96,9 +109,11 @@ ui_set_title(const char *title)
UI *
ui_init(int width, int height)
{
+ init_log();
+
UI *ui = malloc(sizeof(UI));
if (ui == NULL) {
- log_error("Error allocating UI");
+ log_error(log, "Error allocating UI");
exit(1);
}
@@ -113,7 +128,7 @@ ui_init(int width, int height)
gl_context = glXCreateContext(display, vi, NULL, GL_TRUE);
if (!glXMakeCurrent(display, window, gl_context)) {
- log_error("Error on making GLX context");
+ log_error(log, "Error on making GLX context");
exit(1);
}
@@ -135,11 +150,13 @@ ui_on_expose(XEvent event)
static void
ui_on_resize(XEvent event)
{
+ init_log();
+
if (event.type != ConfigureNotify) return;
if (on_resize_event != NULL) {
UIEventResize *er = malloc(sizeof(UIEventResize));
if (er == NULL) {
- log_error("Error allocating UIEventResize");
+ log_error(log, "Error allocating UIEventResize");
exit(EXIT_FAILURE);
}
er->width = event.xconfigure.width;
@@ -168,11 +185,13 @@ ui_get_mouse_position(Display *display, Window window, int *x, int *y) {
static void
ui_on_mouse_press(XEvent event)
{
+ init_log();
+
if (event.type != ButtonPress) return;
if (on_mouse_press_event != NULL) {
UIMouseButtonPressed *mbp = malloc(sizeof(UIMouseButtonPressed));
if (mbp == NULL) {
- log_error("Error allocating UIMouseButtonPressed");
+ log_error(log, "Error allocating UIMouseButtonPressed");
exit(EXIT_FAILURE);
}
ui_get_mouse_position(display, window, &mbp->x, &mbp->y);