scheduler work
This commit is contained in:
@@ -3,7 +3,7 @@ add_subdirectory(core)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(FRONTEND "qt" CACHE INTERNAL "")
|
||||
set(FRONTEND "sdl" CACHE INTERNAL "")
|
||||
|
||||
if(${FRONTEND} MATCHES "qt")
|
||||
add_subdirectory(frontend/qt)
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
#include <Scheduler.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace natsukashii::core {
|
||||
Event::Event(u128 time, EventHandler handler, void* ptr) : time(time), handler(handler), ptr(ptr) { }
|
||||
|
||||
Scheduler::Scheduler() {
|
||||
events.emplace_back(Event(UINT128_MAX, [](void*) {
|
||||
printf("Reached event at UINT128_MAX, wtf?!\n");
|
||||
exit(1);
|
||||
}, nullptr));
|
||||
}
|
||||
|
||||
void Scheduler::PushEvent(u128 time, EventHandler handler, void* ptr) {
|
||||
for(int i = 0; i < events.size(); i++) {
|
||||
if(time < events[i].time) { // if it's lower than the next event we can just insert it.
|
||||
events.emplace_back(Event(time, handler, ptr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scheduler::Dispatch() {
|
||||
for(auto& event : events) {
|
||||
event.handler(event.ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,24 @@
|
||||
#pragma once
|
||||
#include <common.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace natsukashii::core {
|
||||
using EventHandler = void(*)(void*);
|
||||
struct Event {
|
||||
Event(u128, EventHandler, void*);
|
||||
private:
|
||||
friend class Scheduler;
|
||||
u128 time;
|
||||
void* ptr;
|
||||
EventHandler handler;
|
||||
};
|
||||
|
||||
struct Scheduler {
|
||||
Scheduler();
|
||||
void PushEvent(u128, EventHandler, void*);
|
||||
void Dispatch();
|
||||
private:
|
||||
u128 currentTime = 0;
|
||||
std::vector<Event> events{};
|
||||
};
|
||||
}
|
||||
@@ -14,3 +14,7 @@ using s64 = int64_t;
|
||||
using u128 = __uint128_t;
|
||||
using s128 = __int128_t;
|
||||
using m128 = __m128i;
|
||||
#define UINT128_MAX ((u128)0xFFFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
||||
#define UINT128_MIN 0
|
||||
#define INT128_MAX ((u128)0x7FFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
||||
#define INT128_MIN (-INT128_MAX - 1LL)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <Frontend.hpp>
|
||||
|
||||
Window::~Window() {}
|
||||
namespace natsukashii::frontend {
|
||||
App::~App() {}
|
||||
|
||||
Window::Window() {}
|
||||
App::App() {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
struct Window {
|
||||
~Window();
|
||||
Window();
|
||||
namespace natsukashii::frontend {
|
||||
struct App {
|
||||
~App();
|
||||
App();
|
||||
void Run() {}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user