From bf8fb0e2a8bd35bfec3f3348d58367b9b6b54a54 Mon Sep 17 00:00:00 2001 From: dam Date: Tue, 28 Mar 2023 03:41:00 +0100 Subject: Playing with different hacks to store/load tasks. --- ttt.jai | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'ttt.jai') diff --git a/ttt.jai b/ttt.jai index 42c68d7..9e6af5f 100644 --- a/ttt.jai +++ b/ttt.jai @@ -711,36 +711,17 @@ load_database :: (db: *Database, path: string) -> success: bool { } // Read database structure. - read_success = file_read(file, db, size_of(Database)); - db.tasks.data = null; // Discard invalid pointer read into 'data'. + read_success = file_read(file, db, size_of(Database) - size_of([..] Task)); // HACK //if read_success == false print_error("Failed to read database info from '%'.", path); TODO - //file_open :: (name: string, for_writing := false, keep_existing_content := false, log_errors := true) -> File, bool - //file_read :: (f: File, vdata: *void, bytes_to_read: s64) -> (success: bool, total_read: s64) - - // Reserve database capacity for tasks. HACK - value := db.tasks.count; - d: [..] Task; - db.tasks = d; -// array_reserve(*db.tasks, value); -// db.tasks.count = value; - -// size_t capacity_bytes = db->capacity * SIZEOF_TASK_ST; -// db->tasks = malloc(capacity_bytes); -// if (db->tasks == NULL && capacity_bytes > 0) { -// print_error("Failed to allocate memory while loading database: %s.", strerror(errno)); -// return false; -// } -// - // Read database tasks. HACK - for 0..value-1 { - task: Task; - file_read(file, *task, size_of(Task)); - array_add(*db.tasks, task); - } -// file_read(file, db.tasks.data, size_of(Task)*db.tasks.count); - + tasks_count: s64; + file_read(file, *tasks_count, size_of(s64)); + t: [2048]u8; file_read(file, *t, size_of([..] Task) - size_of(s64)); // HACK + array_reserve(*db.tasks, tasks_count); + file_read(file, db.tasks.data, size_of(Task)*tasks_count); + db.tasks.count = tasks_count; + // Make sure we are reading all the file. buffer: [1] u8; success, bytes := file_read(file, *buffer, 1); -- cgit v1.2.3