aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ttt.jai45
1 files changed, 26 insertions, 19 deletions
diff --git a/ttt.jai b/ttt.jai
index b40c744..52d22d2 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -29,6 +29,12 @@
#load "Integer_Saturating_Arithmetic.jai";
+// TODO List:
+// [ ] Decide once and for all if we're calling them entries or tasks.
+// [ ] Test shrinking mechanism... this may be done by using the coalescing function.
+// [ ] Every time we add or remove entries to the database, it may be reallocated,
+// thus making the selected_task and active_task pointers invalid. Check this is not messing up the app.
+
VERSION :: "2.0"; // Use only 3 chars (to fit layouts).
YEAR :: "2023";
FIRST_DAY_OF_WEEK :: 1; // (0-6, Sunday = 0).
@@ -307,9 +313,12 @@ is_valid_index :: inline(db: Database, index: s64) -> bool { return index >= 0 &
// Adds a task to the database and returns it.
// If necessary, expands database capacity.
-add_task :: (db: *Database, task: Task = .{}) -> task: *Task, index: s64 {
+add_task :: (db: *Database, task: *Task = null) -> task: *Task, index: s64 {
assert(db != null, ASSERT_NOT_NULL, "db");
- array_add(*db.tasks, task);
+
+ new_task: Task = .{};
+ if task != null new_task = <<task;
+ array_add(*db.tasks, new_task);
for * db.total_times {
<<it = add(<<it, task.times[it_index]);
@@ -350,13 +359,20 @@ delete_task :: (using db: *Database, index: s64) -> bool { // TODO Maybe use `us
}
// Try to shrink database capacity if using more than 2MB.
+ // TODO WIP WIP WIP
if (tasks.allocated >> 2) > tasks.count && tasks.allocated * SIZE_OF_TASK > 2_000_000 {
new_capacity := tasks.allocated >> 1;
+ msg := tprint("shrinking from % to %\n", tasks.allocated, new_capacity);
+ print_error(msg);
new_tasks_data := realloc(tasks.data, new_capacity * SIZE_OF_TASK, tasks.allocated * SIZE_OF_TASK, tasks.allocator);
if new_tasks_data != null {
+ msg = tprint("OH NOEWS");
+ print_error(msg);
tasks.data = new_tasks_data;
tasks.allocated = new_capacity;
}
+ msg = tprint("ALL OK");
+ print_error(msg);
}
return true;
@@ -1477,21 +1493,10 @@ main :: () {
for 0..input.count-1 {
ch := to_lower(input[it]);
if ch == {
- case #char "m";
- multiplier = xx SECONDS_IN_MINUTE;
- break;
-
- case #char "h";
- multiplier = xx SECONDS_IN_HOUR;
- break;
-
- case #char "d";
- multiplier = xx SECONDS_IN_DAY;
- break;
-
- case #char "y";
- multiplier = xx SECONDS_IN_YEAR;
- break;
+ case #char "m"; multiplier = xx SECONDS_IN_MINUTE;
+ case #char "h"; multiplier = xx SECONDS_IN_HOUR;
+ case #char "d"; multiplier = xx SECONDS_IN_DAY;
+ case #char "y"; multiplier = xx SECONDS_IN_YEAR;
}
}
@@ -1534,8 +1539,10 @@ main :: () {
continue;
}
- add_task(db, selected_task);
-
+ if (add_task(db, selected_task) == null) {
+ print_error("Failed to duplicate entry.");
+ continue;
+ }
trigger_autosave();
case KEY_F5;