From 569ea396c044560e12e5d768baf97e8e93047989 Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Tue, 28 Jan 2025 21:01:24 -0800 Subject: [PATCH] added tart main tools --- includes/tart.h | 5 +- source/tart.cpp | 35 ++++++++------ source/term.cpp | 0 source/term.h | 8 +++ testing/Temporary/CTestCostData.txt | 1 + testing/Temporary/LastTest.log | 3 ++ testing/test_tart.cpp | 75 +++++++++++++++++++++++++++-- 7 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 source/term.cpp create mode 100644 source/term.h create mode 100644 testing/Temporary/CTestCostData.txt create mode 100644 testing/Temporary/LastTest.log diff --git a/includes/tart.h b/includes/tart.h index f1f198f..5cb0535 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -14,6 +14,8 @@ // | over each cell. // #========================================================================# +#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0} + typedef unsigned char tart_byte; typedef unsigned short tart_id; @@ -72,6 +74,7 @@ struct tart_window { tart_byte buffer_count; }; +struct tart_window tart_create_window(); struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position); struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background); tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer); @@ -80,6 +83,6 @@ tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte); struct tart_buffer* tart_get_buffer(struct tart_window*, tart_byte); struct tart_cell* tart_get_cell(struct tart_buffer*, int); -struct tart_cell* tart_set_cell(struct tart_buffer*, struct tart_cell*,int); +struct tart_cell tart_set_cell(struct tart_buffer*, struct tart_cell,int); #endif diff --git a/source/tart.cpp b/source/tart.cpp index 69d3e2e..bf52eea 100644 --- a/source/tart.cpp +++ b/source/tart.cpp @@ -1,13 +1,23 @@ #include "../includes/tart.h" -#include +#include struct tart_cell tart_test() { return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't'}; } +struct tart_window tart_create_window() { + struct tart_window window; + window.buffer_count = 0; + for(int i = 0; i < 0xFF; i++) { + window.buffers[i] = tart_create_buffer(0, {0,0}, {0,0}); + } + return window; +} + struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) { unsigned int cell_count = position.x * position.y; - struct tart_cell* cells = (struct tart_cell*)malloc(sizeof(struct tart_cell[cell_count])); - struct tart_buffer buf = {cell_count,0,id,size,position,0}; + struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell)); + tart_cell cell = NULL_CELL; + struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer return buf; } struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) { @@ -15,12 +25,9 @@ struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb return b; } tart_byte tart_add_buffer(struct tart_window* window, struct tart_buffer buffer) { - if(window->buffer_count < 0xFF) { - window->buffers[window->buffer_count] = buffer; - window->buffer_count++; - return window->buffer_count; - } - return 0; + window->buffers[window->buffer_count] = buffer; + window->buffer_count++; + return window->buffer_count; } tart_byte tart_set_buffer(struct tart_window* window, struct tart_buffer buffer, tart_byte layer) { if(layer <= 0xFF) { @@ -37,10 +44,8 @@ struct tart_buffer* tart_get_buffer(struct tart_window* window, tart_byte layer) struct tart_cell* tart_get_cell(struct tart_buffer* buffer, int idx) { return &buffer->cells[idx]; } -struct tart_cell* tart_set_cell(struct tart_buffer* buffer, struct tart_cell* cell,int idx) { - if(buffer->cell_count >= idx) { - buffer->cells[idx] = *cell; - return cell; - } - return 0; + +struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell,int idx) { + buffer->cells[idx] = cell; + return NULL_CELL; } diff --git a/source/term.cpp b/source/term.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/term.h b/source/term.h new file mode 100644 index 0000000..54b5ded --- /dev/null +++ b/source/term.h @@ -0,0 +1,8 @@ +#ifndef TERM_H +#define TERM_H +#include "tart.h" + +int tart_draw(struct tart_window); +int tart_draw_buffer(struct tart_buffer); + +#endif diff --git a/testing/Temporary/CTestCostData.txt b/testing/Temporary/CTestCostData.txt new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/testing/Temporary/LastTest.log b/testing/Temporary/LastTest.log new file mode 100644 index 0000000..a08c3eb --- /dev/null +++ b/testing/Temporary/LastTest.log @@ -0,0 +1,3 @@ +Start testing: Jan 28 14:11 Pacific Standard Time (Mexico) +---------------------------------------------------------- +End testing: Jan 28 14:11 Pacific Standard Time (Mexico) diff --git a/testing/test_tart.cpp b/testing/test_tart.cpp index 95976bc..5e0fe70 100644 --- a/testing/test_tart.cpp +++ b/testing/test_tart.cpp @@ -1,5 +1,6 @@ #include "test_tart.h" #include "../includes/tart.h" +#include "Pickler.h" bool rgb_test(struct tart_rgb* lhs, struct tart_rgb* rhs) { if(lhs->r != rhs->r) {return false;} if(lhs->g != rhs->g) {return false;} @@ -55,14 +56,82 @@ void tart_run(struct pickle_shelf* shelf) { ASSERT("GOOD",true); }(); - PICKLE(Test_Add_buffer) { + PICKLE(Test_create_window) { struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0}); - - ASSERT("GOOD",true); + struct tart_window window = tart_create_window(); + for(int i = 0; i < 0xFF + 1; i++) { + if(DIFFERENT(window.buffers[i].id, 0)) + ASSERT("buffer not same", false); + } + ASSERT("GOOD", true); }(); + PICKLE(Test_add_buffer) { + struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0}); + struct tart_window window = tart_create_window(); + tart_add_buffer(&window, buffer); + if(SAME(window.buffer_count, 0)) + ASSERT("index has not indexed", false); + if(DIFFERENT(window.buffers[0].id, buffer.id)) + ASSERT("buffer not same", false); + ASSERT("GOOD", true); + }(); + + PICKLE(Test_set_buffer) { + struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0}); + struct tart_window window = tart_create_window(); + tart_set_buffer(&window, buffer, 0); + if(DIFFERENT(window.buffers[0].id, buffer.id)) + ASSERT("buffer not same", false); + ASSERT("GOOD", true); + }(); + + PICKLE(Test_get_buffer) { + struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0}); + struct tart_window window = tart_create_window(); + tart_set_buffer(&window, buffer, 0); + if(DIFFERENT(tart_get_buffer(&window, 0)->id, buffer.id)) + ASSERT("buffer not same", false); + ASSERT("GOOD", true); + }(); + + PICKLE(Test_set_cell) { + tart_rgb foreground = {90,90,90}; + tart_rgb background = {80,80,80}; + + struct tart_cell cell = tart_create_cell('0',10,foreground, background); + struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20}); + struct tart_window window = tart_create_window(); + + tart_set_cell(&buffer, cell, 0); + if(DIFFERENT(buffer.cells[0].display, cell.display)) + ASSERT("buffer not same", false); + ASSERT("GOOD", true); + }(); + + PICKLE(Test_get_cell) { + tart_rgb foreground = {90,90,90}; + tart_rgb background = {80,80,80}; + + struct tart_cell cell = tart_create_cell('0',10,foreground, background); + struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20}); + struct tart_window window = tart_create_window(); + + tart_set_cell(&buffer, cell, 0); + if(DIFFERENT(tart_get_cell(&buffer,0)->display, cell.display)) + ASSERT("buffer not same", false); + ASSERT("GOOD", true); + }(); + + ADDPICKLE(tart_objects_test,Test_create_buffer); ADDPICKLE(tart_objects_test,Test_create_cell); + ADDPICKLE(tart_objects_test,Test_create_buffer); + ADDPICKLE(tart_objects_test,Test_add_buffer); + ADDPICKLE(tart_objects_test,Test_set_buffer); + ADDPICKLE(tart_objects_test,Test_get_buffer); + ADDPICKLE(tart_objects_test,Test_set_cell); + ADDPICKLE(tart_objects_test,Test_get_cell); PUTJARONSHELF(tart_objects_test); *shelf = __pickle_shelf__; }