diff --git a/build/plugins/wasmPlugin.ts b/build/plugins/wasmPlugin.ts index 07295d3..eb4ae89 100644 --- a/build/plugins/wasmPlugin.ts +++ b/build/plugins/wasmPlugin.ts @@ -145,13 +145,20 @@ async function instantiate(url: string) { } return 0; }, + clock_time_get: (_id: number, _precision: bigint, timePtr: number) => { + const now = Date.now(); + const nanosecondNow = BigInt(now) * 1_000_000n; + const data = new DataView(memory.buffer); + data.setBigInt64(timePtr, nanosecondNow, true); + return 0; + } }, { get(target, p) { if (p in target) { console.debug(`[${String(p)}] exists`); return target[p as keyof typeof target]; } - return (...args: any[]) => { console.debug(`[${String(p)}]`, args); return 0; } + return (...args: any[]) => { console.warn(`[${String(p)}]`, args); return 0; } }, }), }); diff --git a/src/games/life/life.c b/src/games/life/life.c index 2a04600..f66bb6d 100644 --- a/src/games/life/life.c +++ b/src/games/life/life.c @@ -2,6 +2,7 @@ #include #include #include +#include #define WIDTH 512 #define HEIGHT 512 @@ -18,13 +19,15 @@ GRAPHICS_FRAME { int count = count_neighbours(x, y); uint8_t current_cell = field[x + y * WIDTH]; uint8_t next_cell = current_cell; - if (current_cell && count < 2) { - next_cell = 0; - } else if (current_cell && count > 3) { - next_cell = 0; - } else if (!current_cell && count == 3) { - next_cell = 1; - } + // if (current_cell && count < 2) { + // next_cell = 0; + // } else if (current_cell && count > 3) { + // next_cell = 0; + // } else if (!current_cell && count == 3) { + // next_cell = 1; + // } + + next_cell = (count + current_cell) >= 5; next_field[x + y * WIDTH] = next_cell; } @@ -60,6 +63,7 @@ static int count_neighbours(int x, int y) { } GRAPHICS_INIT { + srand((uint32_t)time(NULL)); field = malloc(WIDTH * HEIGHT); next_field = malloc(WIDTH * HEIGHT); image_data = image_create(WIDTH, HEIGHT); diff --git a/src/games/playground/awoo.cpp b/src/games/playground/awoo.cpp index 6ef9b72..16b0455 100644 --- a/src/games/playground/awoo.cpp +++ b/src/games/playground/awoo.cpp @@ -1,11 +1,11 @@ #include +#include #include #include #include #include #include #include -#include #include class bit { @@ -77,7 +77,7 @@ constexpr bit bit::nor(const bit& a, const bit& b) { return result; } -uint64_t EXPORT(awoo) { +JS_EXPORT uint64_t awoo() { bit a{1, "a"}; bit b{1, "b"}; @@ -88,7 +88,12 @@ uint64_t EXPORT(awoo) { return sum; } -void EXPORT(play) { +JS_EXPORT void play() { auto awoo = std::format("{2} {1}{0}!\n", 23, "C++", "Hello"); std::puts(awoo.c_str()); } + +int main() { + awoo(); + play(); +}