new idea
This commit is contained in:
+23
-10
@@ -5,21 +5,30 @@ void Scheduler::EnqueueRelative(const u64 t, const EventType type) { EnqueueAbso
|
||||
|
||||
void Scheduler::EnqueueAbsolute(const u64 t, const EventType type) { events.push({t, type}); }
|
||||
|
||||
u64 Scheduler::Remove(const EventType eventType) const {
|
||||
for (auto &[time, type] : events) {
|
||||
if (type == eventType) {
|
||||
const u64 ret = time - ticks;
|
||||
type = NONE;
|
||||
time = ticks;
|
||||
return ret;
|
||||
Event *Scheduler::Find(const EventType eventType) const {
|
||||
for (auto &event : events) {
|
||||
if (event.type == eventType) {
|
||||
const u64 ret = event.time - ticks;
|
||||
return &event;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
u64 Scheduler::Remove(const EventType eventType) const {
|
||||
auto event = Find(eventType);
|
||||
if (!event)
|
||||
return 0;
|
||||
|
||||
const u64 ret = event->time - ticks;
|
||||
event->type = NONE;
|
||||
event->time = ticks;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Scheduler::Tick(const u64 t) {
|
||||
n64::Mem& mem = n64::Core::GetMem();
|
||||
n64::Mem &mem = n64::Core::GetMem();
|
||||
ticks += t;
|
||||
n64::MI &mi = mem.mmio.mi;
|
||||
n64::SI &si = mem.mmio.si;
|
||||
@@ -40,10 +49,14 @@ void Scheduler::Tick(const u64 t) {
|
||||
case NONE:
|
||||
break;
|
||||
case IMPOSSIBLE:
|
||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE}, {Util::Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unrecognized rom endianness");
|
||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE},
|
||||
{Util::Error::Type::ROM_LOAD_ERROR}, {}, {},
|
||||
"Unrecognized rom endianness");
|
||||
return;
|
||||
default:
|
||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE}, {Util::Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unknown scheduler event type {}", static_cast<int>(type));
|
||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE},
|
||||
{Util::Error::Type::ROM_LOAD_ERROR}, {}, {},
|
||||
"Unknown scheduler event type {}", static_cast<int>(type));
|
||||
return;
|
||||
}
|
||||
events.pop();
|
||||
|
||||
@@ -38,6 +38,7 @@ struct Scheduler {
|
||||
void EnqueueRelative(u64, EventType);
|
||||
void EnqueueAbsolute(u64, EventType);
|
||||
[[nodiscard]] u64 Remove(EventType) const;
|
||||
[[nodiscard]] Event *Find(EventType) const;
|
||||
void Tick(u64 t);
|
||||
|
||||
u8 index = 0;
|
||||
|
||||
Reference in New Issue
Block a user