a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 679e5d0518fe118d61782c0fe8f6be4dae3ce0d3
parent 5b9156543a679ec0cd75a58ba96bd15ab6a5093a
Author: amin <dev@aminmesbah.com>
Date:   Mon, 10 Feb 2020 10:05:34 +0000

Confine wasm insanity to the wasm platform layer

FossilOrigin-Name: 05f6dceb7e206dd096d2ef1b7515e3e107df86b2e51e61cb2ea4b574c3895457
Diffstat:
Msrc/game.h | 60+-----------------------------------------------------------
Msrc/platform_wasm.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/platform_windows.c | 4++++
3 files changed, 67 insertions(+), 59 deletions(-)

diff --git a/src/game.h b/src/game.h @@ -1,9 +1,3 @@ -// NOTE(amin): On windows, even with clang and -std=c11, assert.h doesn't -// define static_assert. -#ifndef static_assert -#define static_assert _Static_assert -#endif - #include <limits.h> #include <stdalign.h> #include <stdbool.h> @@ -16,63 +10,11 @@ #include "platform_info.h" #if !defined(PLATFORM_WASM) - #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - -#else -// TODO: organize this stuff - -#define assert(x) (void)0 - -int32_t printf(const char *format, ...) -{ - // lol - return 0; -} - -// looooooooooool -#define exit(status) (void)0 - -void *memset(void *s, int32_t c, size_t n) -{ - uint8_t *p = s; - while(n > 0) - { - *p = (uint8_t)c; - p++; - n--; - } - return s; -} - -// TODO: assert no overlap -void *memcpy(void *dst, const void *src, size_t n) -{ - uint8_t *destination = (uint8_t *)dst; - uint8_t *source = (uint8_t *)src; - - while (n--) { - *destination = *source; - destination++; - source++; - } - - return dst; -} - -// TODO: actually implement -void *memmove(void *dst, const void *src, size_t n) -{ - return memcpy(dst, src, n); -} - -static_assert(__has_builtin(__builtin_sqrtf), "No builtin sqrtf builtin"); -#define sqrtf(x) __builtin_sqrtf((x)) - -#endif // PLATFORM_WASM +#endif // !PLATFORM_WASM #if defined(PLATFORM_WASM) #include "webgl.h" diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -1,3 +1,65 @@ +#include <limits.h> +#include <stdalign.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +// TODO: only include this in the non-wasm builds +#include <math.h> + +#define static_assert _Static_assert + +// Begin terrible libc substitutions +// TODO: make this libc replacement not shitty +#define assert(x) (void)0 + +int32_t printf(const char *format, ...) +{ + // lol + return 0; +} + +// looooooooooool +#define exit(status) (void)0 + +void *memset(void *s, int32_t c, size_t n) +{ + uint8_t *p = s; + while(n > 0) + { + *p = (uint8_t)c; + p++; + n--; + } + return s; +} + +// TODO: assert no overlap +void *memcpy(void *dst, const void *src, size_t n) +{ + uint8_t *destination = (uint8_t *)dst; + uint8_t *source = (uint8_t *)src; + + while (n--) + { + *destination = *source; + destination++; + source++; + } + + return dst; +} + +// TODO: actually implement +void *memmove(void *dst, const void *src, size_t n) +{ + return memcpy(dst, src, n); +} + +static_assert(__has_builtin(__builtin_sqrtf), "No builtin sqrtf builtin"); +#define sqrtf(x) __builtin_sqrtf((x)) +// End terrible libc substitutions + #include "game.c" #include "platform.h" #include "platform_wasm.h" diff --git a/src/platform_windows.c b/src/platform_windows.c @@ -1,3 +1,7 @@ +// NOTE(amin): On windows, even with clang and -std=c11, assert.h doesn't +// define static_assert. +#define static_assert _Static_assert + #include <time.h> #include <glad/glad.h>