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 style;
char display;
struct tart_vec2 screen_pos;
};
#endif
@@ -155,6 +156,7 @@ struct tart_buffer {
struct tart_vec2 size;
struct tart_vec2 position;
struct tart_cell* cells;
unsigned int current_idx;
};
/* 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++) {
if(window->buffers[b].cell_count == 0)
continue;
char bufferSetPre[16];
int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x);
for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) {
//window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
window->data[offset] = bufferSetPre[preIdx];
offset++;
}
offset++;
bufferWidth = window->buffers[b].size.x;
for (int y = 0; y < window->buffers[b].size.y; y++) {
char movePre[16];
int moveSize = sprintf(movePre, "\033[%dB\033[%dG", 1, window->buffers[b].position.x);
for(int preIdx = 0; preIdx < moveSize; preIdx++) {
//window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
window->data[offset] = movePre[preIdx];
//char bufferSetPre[16];
//int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x);
//for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) {
// //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
// window->data[offset] = bufferSetPre[preIdx];
// offset++;
//}
// offset++;
//bufferWidth = window->buffers[b].size.x;
for (int y = 0; y < window->buffers[b].current_idx; y++) {
// add data to window c buffer.
struct tart_cell cell = window->buffers[b].cells[y];
// puts cell drawing data in pre
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++;
}
for (int x = 0; x < window->buffers[b].size.x; x++) {
// add data to window c buffer.
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x];
// puts cell drawing data in pre
#ifdef TART_RGB_COLORS
char pre[TART_CELL_DATA_SIZE+4];
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",
// 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++;
}
}
#ifdef TART_RGB_COLORS
char pre[TART_CELL_DATA_SIZE+4];
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",
// TODO add rgb
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
#endif
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) {
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;
}
@@ -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) {
for (int i = 0; i < buffer->cell_count; i++) {
buffer->cells[i] = NULL_CELL;
buffer->current_idx = 0;
}
return TART_OK;
}