summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/engine.c8
-rw-r--r--src/input.c22
-rw-r--r--src/input.h7
-rw-r--r--src/junkcraft.c4
5 files changed, 35 insertions, 7 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f86a139..2b88db2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,4 +8,5 @@ add_executable(junkcraft
engine.c
chunk.c
world.c
+ input.c
)
diff --git a/src/engine.c b/src/engine.c
index 08f4852..84db967 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -1,6 +1,7 @@
#include "engine.h"
#include "block.h"
#include "chunk.h"
+#include "input.h"
#include "window.h"
#include "world.h"
#include <junk/vector.h>
@@ -65,13 +66,6 @@ void _engine_insert_chunk_ptrs(struct engine* engine, struct chunk* chunk) {
void engine_draw(struct engine* engine) {
while (engine->game_loop) {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- // Quit game
- if (event.type == SDL_QUIT) {
- engine->game_loop = 0;
- }
- }
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.529f, 0.808f, 0.922f, 1.0f);
glEnable(GL_DEPTH_TEST);
diff --git a/src/input.c b/src/input.c
new file mode 100644
index 0000000..68722e7
--- /dev/null
+++ b/src/input.c
@@ -0,0 +1,22 @@
+#include "input.h"
+#include "pthread.h"
+
+pthread_t input_init(struct engine* engine) {
+ pthread_t thread;
+ pthread_create(&thread, NULL, (void*)input_handle, engine);
+ return thread;
+}
+void input_join(pthread_t thread, struct engine* engine) {
+ pthread_join(thread, NULL);
+}
+void input_handle(struct engine *engine) {
+ SDL_Event event;
+ while (engine->game_loop) {
+ // Quit game
+ // TODO: Locks?
+ SDL_PollEvent(&event);
+ if (event.type == SDL_QUIT) {
+ engine->game_loop = 0;
+ }
+ }
+}
diff --git a/src/input.h b/src/input.h
new file mode 100644
index 0000000..3d8fe14
--- /dev/null
+++ b/src/input.h
@@ -0,0 +1,7 @@
+#pragma once
+#include "SDL2/SDL.h"
+#include "engine.h"
+
+void input_handle(struct engine* engine);
+pthread_t input_init(struct engine* engine);
+void input_join(pthread_t thread, struct engine* engine);
diff --git a/src/junkcraft.c b/src/junkcraft.c
index 4a1a96a..e3e5260 100644
--- a/src/junkcraft.c
+++ b/src/junkcraft.c
@@ -1,12 +1,16 @@
#include "engine.h"
+#include "input.h"
#include <time.h>
+
int main() {
struct engine engine = { 0 };
if (engine_init(&engine) != 0) {
return -1;
}
+ pthread_t input_thread = input_init(&engine);
engine_draw(&engine);
+ input_join(input_thread, &engine);
window_cleanup(engine.window);
return 0;
}