I hate cmake

This commit is contained in:
2021-11-07 19:42:50 -08:00
parent b06099d11e
commit a2a839cbac
4 changed files with 124 additions and 1 deletions

6
.gitmodules vendored
View File

@ -10,3 +10,9 @@
[submodule "lib/glfw"]
path = lib/glfw
url = https://github.com/glfw/glfw
[submodule "lib/libzip"]
path = lib/libzip
url = https://github.com/nih-at/libzip
[submodule "lib/zlib"]
path = lib/zlib
url = https://github.com/madler/zlib

View File

@ -7,6 +7,8 @@
#include "game.h"
#define CHUNK 16384
bool sandboxGameInit(sandboxgame_t *game) {
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
@ -25,6 +27,8 @@ bool sandboxGameInit(sandboxgame_t *game) {
assetManagerStart(&game->manager);
return true;
}

72
src/save/save.c Normal file
View File

@ -0,0 +1,72 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "save.h"
void saveManagerInit(savemanager_t *man) {
man->count = 0;
}
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key) {
uint8_t i, j;
j = saveManagerGetKey(man, key);
if(j != 0xFF) return man->values + j;
// Find empty key
for(i = 0; i < man->count; i++) {
if(man->keys[i] != NULL) continue;
man->keys[i] = key;
return man->values + i;
}
// No empty key
man->keys[man->count] = key;
return man->values + man->count++;
}
uint8_t saveManagerGetKey(savemanager_t *man, char *key) {
uint8_t i;
for(i = 0; i < man->count; i++) {
if(strcmp(man->keys + i, key) == 0) return i;
}
return 0xFF;
}
void saveManagerRemove(savemanager_t *man, char *key) {
uint8_t i;
i = saveManagerGetKey(man, key);
if(i == 0xFF) return;
man->keys[i] = NULL;
}
// Setters
savevalue_t * saveManagerSetBool(savemanager_t *man, char *key, bool val) {
savevalue_t * v = saveManagerAddOrGet(man, key);
v->b = val;
return v;
}
savevalue_t * saveManagerSetUint8(savemanager_t *man, char *key, uint8_t val) {
savevalue_t * v = saveManagerAddOrGet(man, key);
v->u8 = val;
return v;
}
// Getters
bool saveManagerGetBool(savemanager_t *man, char *key) {
return saveManagerAddOrGet(man, key)->b;
}
uint8_t saveManagerGetUint8(savemanager_t *man, char *key) {
return saveManagerAddOrGet(man, key)->u8;
}

41
src/save/save.h Normal file
View File

@ -0,0 +1,41 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "../util/array.h"
#define SAVE_VALUES_MAX 200
typedef union {
// char *s;
bool b;
uint8_t u8;
int8_t i8;
int16_t i16;
int32_t i32;
} savevalue_t;
typedef struct {
char *keys[SAVE_VALUES_MAX];
savevalue_t values[SAVE_VALUES_MAX];
uint8_t count;
} savemanager_t;
void saveManagerInit(savemanager_t *man);
savevalue_t * saveManagerAddOrGet(savemanager_t *man, char *key);
uint8_t saveManagerGetKey(savemanager_t *man, char *key);
void saveManagerRemove(savemanager_t *man, char *key);
savevalue_t * saveManagerSetBool(savemanager_t *man, char *key, bool val);
savevalue_t * saveManagerSetUint8(savemanager_t *man, char *key, uint8_t val);
bool saveManagerGetBool(savemanager_t *man, char *key);
uint8_t saveManagerGetUint8(savemanager_t *man, char *key);