refactor SDL out of core files
This commit is contained in:
parent
82ed6b4ea9
commit
9d183341ae
21 changed files with 1419 additions and 1028 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#include <ctype.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pxl8_io.h"
|
||||
#include "pxl8_types.h"
|
||||
|
||||
pxl8_result pxl8_io_read_file(const char* path, char** content, size_t* size) {
|
||||
if (!path || !content || !size) return PXL8_ERROR_NULL_POINTER;
|
||||
|
|
@ -20,7 +22,7 @@ pxl8_result pxl8_io_read_file(const char* path, char** content, size_t* size) {
|
|||
return PXL8_ERROR_SYSTEM_FAILURE;
|
||||
}
|
||||
|
||||
*content = SDL_malloc(file_size + 1);
|
||||
*content = malloc(file_size + 1);
|
||||
if (!*content) {
|
||||
fclose(file);
|
||||
return PXL8_ERROR_OUT_OF_MEMORY;
|
||||
|
|
@ -88,21 +90,48 @@ pxl8_result pxl8_io_create_directory(const char* path) {
|
|||
|
||||
void pxl8_io_free_file_content(char* content) {
|
||||
if (content) {
|
||||
SDL_free(content);
|
||||
free(content);
|
||||
}
|
||||
}
|
||||
|
||||
void pxl8_io_free_binary_data(u8* data) {
|
||||
if (data) {
|
||||
SDL_free(data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
static i32 pxl8_key_code(const char* key_name) {
|
||||
if (!key_name || !key_name[0]) return 0;
|
||||
|
||||
SDL_Scancode scancode = SDL_GetScancodeFromName(key_name);
|
||||
return (i32)scancode;
|
||||
typedef struct { const char* name; i32 code; } KeyMapping;
|
||||
static const KeyMapping keys[] = {
|
||||
{"a", 4}, {"b", 5}, {"c", 6}, {"d", 7}, {"e", 8}, {"f", 9}, {"g", 10}, {"h", 11},
|
||||
{"i", 12}, {"j", 13}, {"k", 14}, {"l", 15}, {"m", 16}, {"n", 17}, {"o", 18}, {"p", 19},
|
||||
{"q", 20}, {"r", 21}, {"s", 22}, {"t", 23}, {"u", 24}, {"v", 25}, {"w", 26}, {"x", 27},
|
||||
{"y", 28}, {"z", 29},
|
||||
{"1", 30}, {"2", 31}, {"3", 32}, {"4", 33}, {"5", 34},
|
||||
{"6", 35}, {"7", 36}, {"8", 37}, {"9", 38}, {"0", 39},
|
||||
{"return", 40}, {"escape", 41}, {"backspace", 42}, {"tab", 43}, {"space", 44},
|
||||
{"left", 80}, {"right", 79}, {"up", 82}, {"down", 81},
|
||||
{"f1", 58}, {"f2", 59}, {"f3", 60}, {"f4", 61}, {"f5", 62}, {"f6", 63},
|
||||
{"f7", 64}, {"f8", 65}, {"f9", 66}, {"f10", 67}, {"f11", 68}, {"f12", 69},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
char lower_name[64];
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(lower_name) - 1 && key_name[i]; i++) {
|
||||
lower_name[i] = (char)tolower((unsigned char)key_name[i]);
|
||||
}
|
||||
lower_name[i] = '\0';
|
||||
|
||||
for (i = 0; keys[i].name; i++) {
|
||||
if (strcmp(lower_name, keys[i].name) == 0) {
|
||||
return keys[i].code;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool pxl8_key_down(const pxl8_input_state* input, const char* key_name) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue