improve sw renderer
This commit is contained in:
parent
415d424057
commit
39ee0fefb7
89 changed files with 9380 additions and 2307 deletions
|
|
@ -1,14 +1,14 @@
|
|||
#include "pxl8_repl.h"
|
||||
#include "pxl8_mem.h"
|
||||
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <linenoise.h>
|
||||
|
||||
#define PXL8_MAX_REPL_COMMAND_SIZE 4096
|
||||
|
|
@ -29,7 +29,7 @@ struct pxl8_repl {
|
|||
atomic_uint log_read_idx;
|
||||
|
||||
atomic_bool should_quit;
|
||||
pthread_t thread;
|
||||
SDL_Thread* thread;
|
||||
char accumulator[PXL8_MAX_REPL_COMMAND_SIZE];
|
||||
pxl8_repl_command command;
|
||||
};
|
||||
|
|
@ -56,15 +56,15 @@ static void pxl8_repl_completion(const char* buf, linenoiseCompletions* lc) {
|
|||
"pxl8.error", "pxl8.debug", "pxl8.trace"
|
||||
};
|
||||
|
||||
size_t buf_len = strlen(buf);
|
||||
usize buf_len = strlen(buf);
|
||||
|
||||
for (size_t i = 0; i < sizeof(fennel_keywords) / sizeof(fennel_keywords[0]); i++) {
|
||||
for (usize i = 0; i < sizeof(fennel_keywords) / sizeof(fennel_keywords[0]); i++) {
|
||||
if (strncmp(buf, fennel_keywords[i], buf_len) == 0) {
|
||||
linenoiseAddCompletion(lc, fennel_keywords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(pxl8_functions) / sizeof(pxl8_functions[0]); i++) {
|
||||
for (usize i = 0; i < sizeof(pxl8_functions) / sizeof(pxl8_functions[0]); i++) {
|
||||
if (strncmp(buf, pxl8_functions[i], buf_len) == 0) {
|
||||
linenoiseAddCompletion(lc, pxl8_functions[i]);
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ static void pxl8_repl_flush_logs(pxl8_repl* repl) {
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void* pxl8_repl_thread(void* arg) {
|
||||
static int pxl8_repl_thread(void* arg) {
|
||||
pxl8_repl* repl = (pxl8_repl*)arg;
|
||||
|
||||
printf("[pxl8 REPL] Fennel 1.6.0 - Tab for completion, Ctrl-D to exit\n");
|
||||
|
|
@ -204,8 +204,7 @@ static void* pxl8_repl_thread(void* arg) {
|
|||
lw = atomic_load(&repl->log_write_idx);
|
||||
}
|
||||
fflush(stdout);
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000};
|
||||
nanosleep(&ts, NULL);
|
||||
SDL_Delay(1);
|
||||
}
|
||||
atomic_store(&repl->cmd_complete, false);
|
||||
}
|
||||
|
|
@ -214,11 +213,11 @@ static void* pxl8_repl_thread(void* arg) {
|
|||
|
||||
pxl8_repl_flush_logs(repl);
|
||||
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pxl8_repl* pxl8_repl_create(void) {
|
||||
pxl8_repl* repl = (pxl8_repl*)calloc(1, sizeof(pxl8_repl));
|
||||
pxl8_repl* repl = (pxl8_repl*)pxl8_calloc(1, sizeof(pxl8_repl));
|
||||
if (!repl) return NULL;
|
||||
|
||||
repl->accumulator[0] = '\0';
|
||||
|
|
@ -237,8 +236,9 @@ pxl8_repl* pxl8_repl_create(void) {
|
|||
|
||||
g_repl = repl;
|
||||
|
||||
if (pthread_create(&repl->thread, NULL, pxl8_repl_thread, repl) != 0) {
|
||||
free(repl);
|
||||
repl->thread = SDL_CreateThread(pxl8_repl_thread, "pxl8-repl", repl);
|
||||
if (!repl->thread) {
|
||||
pxl8_free(repl);
|
||||
g_repl = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -251,19 +251,18 @@ void pxl8_repl_destroy(pxl8_repl* repl) {
|
|||
|
||||
atomic_store(&repl->should_quit, true);
|
||||
|
||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 2000000};
|
||||
nanosleep(&ts, NULL);
|
||||
SDL_Delay(2);
|
||||
|
||||
printf("\r\033[K");
|
||||
fflush(stdout);
|
||||
|
||||
pthread_join(repl->thread, NULL);
|
||||
SDL_WaitThread(repl->thread, NULL);
|
||||
pxl8_repl_flush_logs(repl);
|
||||
|
||||
g_repl = NULL;
|
||||
|
||||
system("stty sane 2>/dev/null");
|
||||
free(repl);
|
||||
pxl8_free(repl);
|
||||
}
|
||||
|
||||
pxl8_repl_command* pxl8_repl_pop_command(pxl8_repl* repl) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue