changed how buffers work a buffer now renders as a stream

This commit is contained in:
2025-11-13 15:01:04 -08:00
parent 3d755bd9a7
commit ee10de863d
2 changed files with 38 additions and 36 deletions

View File

@@ -118,6 +118,7 @@ struct tart_cell {
tart_byte background; tart_byte background;
tart_byte style; tart_byte style;
char display; char display;
struct tart_vec2 screen_pos;
}; };
#endif #endif
@@ -155,6 +156,7 @@ struct tart_buffer {
struct tart_vec2 size; struct tart_vec2 size;
struct tart_vec2 position; struct tart_vec2 position;
struct tart_cell* cells; struct tart_cell* cells;
unsigned int current_idx;
}; };
/* Tart Window /* Tart Window

View File

@@ -108,43 +108,40 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
for (int b = 0;b < 0xFF; b++) { for (int b = 0;b < 0xFF; b++) {
if(window->buffers[b].cell_count == 0) if(window->buffers[b].cell_count == 0)
continue; continue;
char bufferSetPre[16]; //char bufferSetPre[16];
int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x); //int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x);
for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) { //for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) {
//window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; // //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
window->data[offset] = bufferSetPre[preIdx]; // window->data[offset] = bufferSetPre[preIdx];
offset++; // offset++;
} //}
offset++; // offset++;
bufferWidth = window->buffers[b].size.x; //bufferWidth = window->buffers[b].size.x;
for (int y = 0; y < window->buffers[b].size.y; y++) { for (int y = 0; y < window->buffers[b].current_idx; y++) {
char movePre[16]; // add data to window c buffer.
int moveSize = sprintf(movePre, "\033[%dB\033[%dG", 1, window->buffers[b].position.x); struct tart_cell cell = window->buffers[b].cells[y];
for(int preIdx = 0; preIdx < moveSize; preIdx++) { // puts cell drawing data in pre
//window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
window->data[offset] = movePre[preIdx];
char pre[TART_CELL_DATA_SIZE+20];
int size = sprintf(pre, "\033[%d;%dH\033[0m\033[%d;%d;%dm%c\033[0;0m",
cell.screen_pos.y+1,cell.screen_pos.x+1,
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
for(int preIdx = 0; preIdx < size; preIdx++) {
window->data[offset] = pre[preIdx];
offset++; offset++;
} }
for (int x = 0; x < window->buffers[b].size.x; x++) { #ifdef TART_RGB_COLORS
// add data to window c buffer. char pre[TART_CELL_DATA_SIZE+4];
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m",
// puts cell drawing data in pre // TODO add rgb
#ifdef TART_RGB_COLORS (int)cell.style, cell.foreground,
char pre[TART_CELL_DATA_SIZE+4]; cell.background, cell.display) -1;
int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m", #endif
// TODO add rgb
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
#endif
char pre[TART_CELL_DATA_SIZE+4];
int size = sprintf(pre, "\033[0m\033[%d;%d;%dm%c\033[0;0m",
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
for(int preIdx = 0; preIdx < size; preIdx++) {
window->data[offset] = pre[preIdx];
offset++;
}
}
offset++; offset++;
@@ -225,7 +222,9 @@ tart_byte tart_csprite_free(struct tart_csprite* sprite) {
tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) { tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) {
if(buffer->size.x > position.x && buffer->size.y > position.y) { if(buffer->size.x > position.x && buffer->size.y > position.y) {
buffer->cells[(buffer->size.x * position.y) + position.x] = cell; cell.screen_pos = position;
buffer->cells[buffer->current_idx] = cell;
buffer->current_idx++;
} }
return TART_OK; return TART_OK;
} }
@@ -250,6 +249,7 @@ tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_cs
tart_byte tart_restore_buffer(struct tart_buffer *buffer) { tart_byte tart_restore_buffer(struct tart_buffer *buffer) {
for (int i = 0; i < buffer->cell_count; i++) { for (int i = 0; i < buffer->cell_count; i++) {
buffer->cells[i] = NULL_CELL; buffer->cells[i] = NULL_CELL;
buffer->current_idx = 0;
} }
return TART_OK; return TART_OK;
} }