]> git.lizzy.rs Git - dragonblocks-bedrock.git/blobdiff - src/threads.cpp
Upload Files
[dragonblocks-bedrock.git] / src / threads.cpp
index b4471a4a875e2ffe143f497a23fa4a3fb1ea6419..8fce6ffaf177949b5094daf880f753bab4be6eea 100644 (file)
@@ -3,33 +3,38 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <GL/glut.h>
-#include <iostream>
-#include <algorithm>
 #include "threads.h"
 #include "graphics.h"
 #include "game.h"
-
-
 using namespace std;
-
-void Threads::startMapBackupThread(){
-       Game::log("Starting Map Backup Thread");
+void Threads::add_signal_handlers(){
+       Game::log("Adding Signal Handlers");
+       struct sigaction sa_sigterm;
+       sa_sigterm.sa_handler = &signal_handler;
+       sigaction(SIGTERM, &sa_sigterm, NULL);
+       struct sigaction sa_sigint;
+       sa_sigint.sa_handler = &signal_handler;
+       sigaction(SIGINT, &sa_sigint, NULL);
+}
+void Threads::signal_handler(int signal_number){
+       Game::log((string)"Got "+sys_siglist[signal_number]+" Signal, Exiting.");
+       Game::save();
+       exit(0);
+}
+void Threads::start(void *(*callback)(void *)){
        pthread_t thread_id;
-       pthread_create(&thread_id, NULL, &mapBackupThread, NULL);
+       pthread_create(&thread_id, NULL, callback, NULL);
 }
-void *Threads::mapBackupThread(void *unused){
+void *Threads::worldBackupThread(void *unused){
+       Game::log("Starting World Backup");
        while(true){
-               sleep(MAP_BACKUP_INTERVAL);
-               Game::map -> save();
+               sleep(BACKUP_INTERVAL);
+               Game::save();
        }
        return NULL;
 }
-void Threads::startGraphicUpdateThread(){
-       Game::log("Starting Graphic Update Thread");
-       pthread_t thread_id;
-       pthread_create(&thread_id, NULL, &graphicUpdateThread, NULL);
-}
-void *Threads::graphicUpdateThread(void *unused){
+void *Threads::graphicRedrawThread(void *unused){
+       Game::log("Starting Graphic Redraw");
        while(true){
                usleep(1);
                if(glutGetWindow())
@@ -37,21 +42,21 @@ void *Threads::graphicUpdateThread(void *unused){
        }
        return NULL;
 }
-void Threads::addSignalHandlers(){
-#ifndef _WIN32
-       struct sigaction sa_sigterm;
-       sa_sigterm.sa_handler = &signal_handler;
-       sigaction(SIGTERM, &sa_sigterm, NULL);
-       
-       struct sigaction sa_sigint;
-       sa_sigint.sa_handler = &signal_handler;
-       sigaction(SIGINT, &sa_sigint, NULL);
-#endif
+void *Threads::modRuntimeThread(void *unused){
+       Game::log("Starting Mod Runtime");
+       while(true){
+               usleep(10);
+               // Mods::runtime();
+       }
+       return NULL;
 }
-void Threads::signal_handler(int signal_number){
-#ifndef _WIN32
-       Game::log((string)"Got "+sys_siglist[signal_number]+" Signal, Exiting.");
-       Game::map -> save();
-       exit(0);
-#endif 
+void *Threads::entityPhysicsThread(void *unused){
+       Game::log("Starting Entity Physics");
+       while(true){
+               usleep(PHYSIC_TIME_TICK);
+               Entity::t += (double)PHYSIC_TIME_TICK / 1000000;
+               Entity::physics_all();
+               Graphics::ajustScroll();
+       }
+       return NULL;
 }