aboutsummaryrefslogtreecommitdiff
path: root/karld
diff options
context:
space:
mode:
Diffstat (limited to 'karld')
-rw-r--r--karld/src/condition.rs1
-rw-r--r--karld/src/helper.rs12
-rw-r--r--karld/src/main.rs12
3 files changed, 14 insertions, 11 deletions
diff --git a/karld/src/condition.rs b/karld/src/condition.rs
index 81f7245..765e039 100644
--- a/karld/src/condition.rs
+++ b/karld/src/condition.rs
@@ -47,6 +47,7 @@ impl ConditionFind for Condition {
match self {
Condition::And(cs) => loop {
// TODO improve efficiency for backward search
+ // TODO fix endless search
let last_start = cs
.iter()
.map(|c| c.find_inverse_inclusive(Start, dir, from))
diff --git a/karld/src/helper.rs b/karld/src/helper.rs
index 2e601b0..f106df6 100644
--- a/karld/src/helper.rs
+++ b/karld/src/helper.rs
@@ -1,5 +1,5 @@
use crate::condition::{ConditionFind, Direction, Edge};
-use chrono::{NaiveDate, NaiveDateTime};
+use chrono::NaiveDateTime;
use karlcommon::{Schedule, Task};
use std::{collections::HashMap, ops::Range};
@@ -34,9 +34,17 @@ impl DiscreteCacheTask {
}
pub fn find(&mut self, from: NaiveDateTime, dir: Direction) -> Range<Option<NaiveDateTime>> {
- assert_eq!(dir, Direction::Forward);
// TODO cache
// if let Some(c) = self.cached {}
+ return self.find_uncached(from, dir);
+ }
+
+ pub fn find_uncached(
+ &mut self,
+ from: NaiveDateTime,
+ dir: Direction,
+ ) -> Range<Option<NaiveDateTime>> {
+ assert_eq!(dir, Direction::Forward); // TODO undefined behaviour if dir is not forward (maybe it even works backward)
match &self.inner.schedule {
Schedule::Condition(o) => {
let start = o.find(Edge::Start, dir, from);
diff --git a/karld/src/main.rs b/karld/src/main.rs
index 181c2be..35cca04 100644
--- a/karld/src/main.rs
+++ b/karld/src/main.rs
@@ -10,7 +10,7 @@ use crossbeam_channel::Sender;
use helper::Overlaps;
use interface::network_loop;
use karlcommon::{
- ClientboundPacket, Condition, Instance, Property, ProtoError, Schedule, ServerboundPacket, Task,
+ ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task,
};
use log::{debug, error, info};
use std::{collections::HashMap, sync::RwLock};
@@ -118,10 +118,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C
Schedule::Dynamic { .. } => (), // TODO
Schedule::Static(r) => {
if range.overlaps(r.clone()) {
- ocs.push(Instance {
- of: t.id,
- at: Some(r.start)..Some(r.end),
- })
+ ocs.push(Some(r.start)..Some(r.end))
}
}
Schedule::Condition(o) => {
@@ -131,10 +128,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C
let start =
o.find(condition::Edge::Start, condition::Direction::Forward, time);
let end = o.find(condition::Edge::End, condition::Direction::Forward, time);
- ocs.push(Instance {
- of: t.id,
- at: start.map(|e| e.timestamp())..end.map(|e| e.timestamp()),
- });
+ ocs.push(start.map(|e| e.timestamp())..end.map(|e| e.timestamp()));
if let Some(s) = end {
if let Some(e) = end_time {
if s > e {