summaryrefslogtreecommitdiff
path: root/src/main/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/engine')
-rw-r--r--src/main/engine/engine.c12
-rw-r--r--src/main/engine/ui/types.h28
-rw-r--r--src/main/engine/ui/ui.h5
-rw-r--r--src/main/engine/ui/x11/ui.c2
4 files changed, 40 insertions, 7 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c
index 46b34cb..b4d70b0 100644
--- a/src/main/engine/engine.c
+++ b/src/main/engine/engine.c
@@ -22,6 +22,7 @@
#include <time.h>
#include <GL/gl.h>
#include "engine.h"
+#include "../util.h"
#include "ui/ui.h"
#include "../util/list.h"
@@ -43,10 +44,11 @@ typedef struct Line {
} Line;
typedef struct Engine {
+ UI *ui;
void (*draw_frame)();
} Engine;
-static Engine engine;
+static Engine *engine;
/* FPS */
static time_t start;
@@ -59,9 +61,15 @@ void (*on_mouse_pressed)();
void
engine_init(int w, int h)
{
+ engine = malloc(sizeof(Engine));
+ if (engine == NULL) {
+ log_error("Error allocating memory for engine");
+ exit(EXIT_FAILURE);
+ }
+
width = w;
height = h;
- ui_init(w, h);
+ engine->ui = ui_init(w, h);
xstep = RANGE_GL / (float) w;
ystep = RANGE_GL / (float) h;
diff --git a/src/main/engine/ui/types.h b/src/main/engine/ui/types.h
new file mode 100644
index 0000000..dafefd9
--- /dev/null
+++ b/src/main/engine/ui/types.h
@@ -0,0 +1,28 @@
+/*-
+* Copyright (C) 2025 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it>
+ *
+ * This file is part of Tris Game.
+ *
+ * Tris Game is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tris Game is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Tris Game. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+typedef struct UI {
+ int width;
+ int height;
+} UI;
+
+#endif /* __TYPES_H__ */
diff --git a/src/main/engine/ui/ui.h b/src/main/engine/ui/ui.h
index 2cb8d32..03d5913 100644
--- a/src/main/engine/ui/ui.h
+++ b/src/main/engine/ui/ui.h
@@ -20,10 +20,7 @@
#ifndef __UI_H__
#define __UI_H__
-typedef struct UI {
- int width;
- int height;
-} UI;
+#include "types.h"
UI *ui_init(int w, int h);
void ui_loop(void);
diff --git a/src/main/engine/ui/x11/ui.c b/src/main/engine/ui/x11/ui.c
index 89004c8..98a94b1 100644
--- a/src/main/engine/ui/x11/ui.c
+++ b/src/main/engine/ui/x11/ui.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include <time.h>
#include "../../../util.h"
-#include "../ui.h"
+#include "../types.h"
static Display *display;
static Window window;