1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Pabloader f2fa4d7918 Service-worker & PWA 2025-05-24 15:27:10 +00:00
Pabloader 7a60d9d0bd Math c library & fixes for graphics 2025-05-20 09:57:19 +00:00
14 changed files with 332 additions and 55 deletions

View File

@ -25,12 +25,12 @@ typedef struct {
image_data_t image_create(uint16_t width, uint16_t height);
void image_free(image_data_t image);
void image_draw_point(image_data_t image, uint16_t x, uint16_t y, image_color_t color);
void image_draw_hline(image_data_t image, uint16_t x1, uint16_t x2, uint16_t y, image_color_t color);
void image_draw_vline(image_data_t image, uint16_t x, uint16_t y1, uint16_t y2, image_color_t color);
void image_draw_line(image_data_t image, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, image_color_t color);
void image_draw_rect(image_data_t image, uint16_t x, uint16_t y, uint16_t w, uint16_t h, image_color_t color);
void image_fill_rect(image_data_t image, uint16_t x, uint16_t y, uint16_t w, uint16_t h, image_color_t color);
void image_draw_point(image_data_t image, int16_t x, int16_t y, image_color_t color);
void image_draw_hline(image_data_t image, int16_t x1, int16_t x2, int16_t y, image_color_t color);
void image_draw_vline(image_data_t image, int16_t x, int16_t y1, int16_t y2, image_color_t color);
void image_draw_line(image_data_t image, int16_t x1, int16_t y1, int16_t x2, int16_t y2, image_color_t color);
void image_draw_rect(image_data_t image, int16_t x, int16_t y, uint16_t w, uint16_t h, image_color_t color);
void image_fill_rect(image_data_t image, int16_t x, int16_t y, uint16_t w, uint16_t h, image_color_t color);
#ifdef __cplusplus
}

View File

@ -1,5 +1,31 @@
#pragma once
#include <stdbool.h>
#include <stdlib.h>
#define M_PI 3.14159265359
#define M_PI_2 1.57079632679
#define abs(x) (((x) < 0) ? -(x) : (x))
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#ifdef __cplusplus
extern "C" {
#endif
static inline bool isnan(double x) {
return x != x;
}
static inline bool isinf(double x) {
return !isnan(x) && isnan(x - x);
}
IMPORT(Math_sin) double sin(double x);
static inline double cos(double x) {
return sin(x + M_PI_2);
}
#ifdef __cplusplus
}
#endif

View File

@ -6,7 +6,11 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include <limits.h>
#include <stddef.h>
#define RAND_MAX INT_MAX
extern unsigned char __heap_base;
#define IMPORT(name) __attribute__((import_module("env"), import_name(#name)))
@ -23,7 +27,7 @@ int memcmp(const void* s1, const void* s2, size_t n);
IMPORT(log) void printf(const char* format, ...);
EXPORT(__srand) void srand(uint64_t seed);
uint64_t rand(void);
int rand(void);
#ifdef __cplusplus
}

View File

@ -22,11 +22,21 @@
/*$STYLE$*/
</style>
<!--$MANIFEST$-->
<!--$ICON$-->
</head>
<body>
<!--$SCRIPT$-->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => console.log('SW registered'))
.catch(err => console.error('SW registration failed:', err));
});
}
</script>
</body>
</html>

View File

@ -24,46 +24,54 @@ static inline void set_point(image_data_t image, uint16_t x, uint16_t y, image_c
image.pixels[x + y * image.width] = color;
}
void image_draw_point(image_data_t image, uint16_t x, uint16_t y, image_color_t color) {
if (x >= image.width || y >= image.height) {
void image_draw_point(image_data_t image, int16_t x, int16_t y, image_color_t color) {
if (x >= image.width || y >= image.height || x < 0 || y < 0) {
return;
}
set_point(image, x, y, color);
}
void image_draw_hline(image_data_t image, uint16_t x1, uint16_t x2, uint16_t y, image_color_t color) {
void image_draw_hline(image_data_t image, int16_t x1, int16_t x2, int16_t y, image_color_t color) {
if (y < 0 || y >= image.height) {
return;
}
if (x1 > x2) {
uint16_t temp = x1;
x1 = x2;
x2 = temp;
}
if (x1 > image.width) {
if (x1 > image.width || x2 < 0) {
return;
}
x1 = max(0, x1);
x2 = min(x2, image.width);
do {
image_draw_point(image, x1++, y, color);
set_point(image, x1++, y, color);
} while (x1 < x2);
}
void image_draw_vline(image_data_t image, uint16_t x, uint16_t y1, uint16_t y2, image_color_t color) {
void image_draw_vline(image_data_t image, int16_t x, int16_t y1, int16_t y2, image_color_t color) {
if (x < 0 || x >= image.width) {
return;
}
if (y1 > y2) {
uint16_t temp = y1;
y1 = y2;
y2 = temp;
}
if (y1 > image.width) {
if (y1 > image.width || y2 < 0) {
return;
}
y1 = max(0, y1);
y2 = min(y2, image.height);
do {
image_draw_point(image, x, y1++, color);
set_point(image, x, y1++, color);
} while (y1 < y2);
}
void image_draw_line(image_data_t image, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, image_color_t color) {
void image_draw_line(image_data_t image, int16_t x1, int16_t y1, int16_t x2, int16_t y2, image_color_t color) {
int dx = abs(x2 - x1);
int dy = abs(y2 - y1);
int sx = (x1 < x2) ? 1 : -1;
@ -72,10 +80,13 @@ void image_draw_line(image_data_t image, uint16_t x1, uint16_t y1, uint16_t x2,
int e2;
while (1) {
if (x1 >= image.width || y1 >= image.height) {
if ((x1 >= image.width && x2 >= image.width) || (y1 >= image.height && y2 >= image.height)) {
break;
}
set_point(image, x1, y1, color);
if ((x1 < 0 && x2 < 0) || (y1 < 0 && y2 < 0)) {
break;
}
image_draw_point(image, x1, y1, color);
if (x1 == x2 && y1 == y2) {
break;
}
@ -91,7 +102,14 @@ void image_draw_line(image_data_t image, uint16_t x1, uint16_t y1, uint16_t x2,
}
}
void image_draw_rect(image_data_t image, uint16_t x, uint16_t y, uint16_t w, uint16_t h, image_color_t color) {
void image_draw_rect(image_data_t image, int16_t x, int16_t y, uint16_t w, uint16_t h, image_color_t color) {
if (w == 0 || h == 0) {
return;
}
w = min(image.width - x, w);
h = min(image.height - y, h);
image_draw_hline(image, x, x + w - 1, y, color);
image_draw_hline(image, x, x + w, y + h - 1, color);
@ -99,7 +117,15 @@ void image_draw_rect(image_data_t image, uint16_t x, uint16_t y, uint16_t w, uin
image_draw_vline(image, x + w - 1, y, y + h - 1, color);
}
void image_fill_rect(image_data_t image, uint16_t x, uint16_t y, uint16_t w, uint16_t h, image_color_t color) {
void image_fill_rect(image_data_t image, int16_t x, int16_t y, uint16_t w, uint16_t h, image_color_t color) {
if (w == 0 || h == 0) {
return;
}
x = max(0, x);
y = max(0, y);
w = min(image.width - x, w);
h = min(image.height - y, h);
while (h--) {
image_draw_hline(image, x, x + w, y++, color);
};

View File

@ -122,12 +122,14 @@ void* realloc(void* block, size_t size) {
header_t* header;
void* ret;
if (!block || !size)
if (!block || !size) {
return malloc(size);
}
header = (header_t*)block - 1;
if (header->size >= size)
if (header->size >= size) {
return block;
}
ret = malloc(size);
if (ret) {
@ -171,11 +173,14 @@ int memcmp(const void* s1, const void* s2, size_t n) {
static uint64_t rand_state;
void srand(uint64_t seed) { rand_state = seed; }
void srand(uint64_t seed) {
rand_state = seed;
}
uint64_t rand(void) {
int rand(void) {
uint64_t z = (rand_state += 0x9e3779b97f4a7c15);
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
return z ^ (z >> 31);
int r = (int)(z ^ (z >> 31));
return r < 0 ? -r : r;
}

BIN
build/assets/pwa_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -31,6 +31,6 @@ if (publish) {
console.log(`Publishing ${game}...`);
const result = await $`scp "${filePath}" "${publish}${game}.html"`;
if (result.exitCode === 0) {
console.log(`Build successful: ${process.env.PUBLISH_URL}${game}.html`);
console.log(`Build successful: ${process.env.PUBLISH_URL}${game}`);
}
}

View File

@ -51,6 +51,29 @@ export async function buildHTML(game: string, { production = false, portable = f
if (styleFile) {
style = await styleFile.text();
}
const title = game[0].toUpperCase() + game.slice(1).toLowerCase();
let pwaIconFile = Bun.file(path.resolve(import.meta.dir, '..', 'src', 'games', game, 'assets', 'pwa_icon.png'));
if (!await pwaIconFile.exists()) {
pwaIconFile = Bun.file(path.resolve(import.meta.dir, 'assets', 'pwa_icon.png'));
}
const pwaIcon = `data:;base64,${Buffer.from(await pwaIconFile.arrayBuffer()).toString('base64')}`;
const publishURL = process.env.PUBLISH_URL ? `${process.env.PUBLISH_URL}${game}`: '.';
const manifestJSON = JSON.stringify({
name: title,
short_name: title,
start_url: publishURL,
id: `/${game}`,
display_override: ["window-controls-overlay"],
display: "fullscreen",
background_color: "#ffffff",
theme_color: "#000000",
icons: [{
src: pwaIcon,
sizes: '192x192',
type: 'image/png'
}]
});
const manifest = `<link rel="manifest" href="data:;base64,${Buffer.from(manifestJSON).toString('base64')}" />`;
let script = await scriptFile.text();
const inits = new Set<string>();
script = script.replace(/var (init_[^ ]+) = __esm\(\(\)/g, (_, $1) => {
@ -80,8 +103,9 @@ export async function buildHTML(game: string, { production = false, portable = f
const resultHTML = html
.replace('<!--$SCRIPT$-->', () => `${scriptPrefix}<script type="module">${script}</script>`)
.replace('<!--$TITLE$-->', game[0].toUpperCase() + game.slice(1).toLowerCase())
.replace('<!--$TITLE$-->', title)
.replace('<!--$ICON$-->', icon)
.replace('<!--$MANIFEST$-->', manifest)
.replace('/*$STYLE$*/', style);
return minify(resultHTML, {

View File

@ -64,7 +64,12 @@ const wasmPlugin = ({ production, portable }: WasmLoaderConfig = {}): BunPlugin
memory.grow(blocks);
data = new DataView(memory.buffer);
}
}
},
Math_sin(x) { return Math.sin(x); },
Math_log(x) { return Math.log(x); },
Math_sqrt(x) { return Math.sqrt(x); },
Math_pow(x,y) { return Math.pow(x, y); },
Math_fmod(x,y) { return x % y; },
}
});

View File

@ -18,11 +18,10 @@
"@types/bun": "latest",
"@types/html-minifier": "4.0.5",
"@types/inquirer": "9.0.7",
"assemblyscript": "0.27.29",
"browser-detect": "0.2.28",
"eruda": "3.2.3",
"html-minifier": "4.0.0",
"typescript": "^5.8.2",
"typescript": "5.8.2",
"uglify-js": "3.19.3",
},
},
@ -112,7 +111,7 @@
"@protobufjs/utf8": ["@protobufjs/utf8@1.1.0", "", {}, "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw=="],
"@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="],
"@types/bun": ["@types/bun@1.2.14", "", { "dependencies": { "bun-types": "1.2.14" } }, "sha512-VsFZKs8oKHzI7zwvECiAJ5oSorWndIWEVhfbYqZd4HI/45kzW7PN2Rr5biAzvGvRuNmYLSANY+H59ubHq8xw7Q=="],
"@types/clean-css": ["@types/clean-css@4.2.11", "", { "dependencies": { "@types/node": "*", "source-map": "^0.6.0" } }, "sha512-Y8n81lQVTAfP2TOdtJJEsCoYl1AnOkqDqMvXb9/7pfgZZ7r8YrEyurrAvAoAjHOGXKRybay+5CsExqIH6liccw=="],
@ -132,8 +131,6 @@
"@types/wrap-ansi": ["@types/wrap-ansi@3.0.0", "", {}, "sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g=="],
"@types/ws": ["@types/ws@8.5.10", "", { "dependencies": { "@types/node": "*" } }, "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A=="],
"ace-builds": ["ace-builds@1.36.3", "", {}, "sha512-YcdwV2IIaJSfjkWAR1NEYN5IxBiXefTgwXsJ//UlaFrjXDX5hQpvPFvEePHz2ZBUfvO54RjHeRUQGX8MS5HaMQ=="],
"ansi-escapes": ["ansi-escapes@4.3.2", "", { "dependencies": { "type-fest": "^0.21.3" } }, "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ=="],
@ -142,17 +139,13 @@
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
"assemblyscript": ["assemblyscript@0.27.29", "", { "dependencies": { "binaryen": "116.0.0-nightly.20240114", "long": "^5.2.1" }, "bin": { "asc": "bin/asc.js", "asinit": "bin/asinit.js" } }, "sha512-pH6udb7aE2F0t6cTh+0uCepmucykhMnAmm7k0kkAU3SY7LvpIngEBZWM6p5VCguu4EpmKGwEuZpZbEXzJ/frHQ=="],
"balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="],
"binaryen": ["binaryen@116.0.0-nightly.20240114", "", { "bin": { "wasm2js": "bin/wasm2js", "wasm-opt": "bin/wasm-opt" } }, "sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A=="],
"brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],
"browser-detect": ["browser-detect@0.2.28", "", { "dependencies": { "core-js": "^2.5.7" } }, "sha512-KeWGHqYQmHDkCFG2dIiX/2wFUgqevbw/rd6wNi9N6rZbaSJFtG5kel0HtprRwCGp8sqpQP79LzDJXf/WCx4WAw=="],
"bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="],
"bun-types": ["bun-types@1.2.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-Kuh4Ub28ucMRWeiUUWMHsT9Wcbr4H3kLIO72RZZElSDxSu7vpetRvxIUDUaW6QtaIeixIpm7OXtNnZPf82EzwA=="],
"camel-case": ["camel-case@3.0.0", "", { "dependencies": { "no-case": "^2.2.0", "upper-case": "^1.1.1" } }, "sha512-+MbKztAYHXPr1jNTSKQF52VpcFjwY5RkR7fxksV8Doo4KAYc5Fl4UJRgthBbTmEx8C54DqahhbLJkDwjI3PI/w=="],
@ -310,8 +303,6 @@
"@types/through/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="],
"@types/ws/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="],
"html-minifier/uglify-js": ["uglify-js@3.18.0", "", { "bin": { "uglifyjs": "bin/uglifyjs" } }, "sha512-SyVVbcNBCk0dzr9XL/R/ySrmYf0s372K6/hFklzgcp2lBFyXtw4I7BOdDjlLhE1aVqaI/SHWXWmYdlZxuyF38A=="],
"onnxruntime-web/onnxruntime-common": ["onnxruntime-common@1.20.0-dev.20241016-2b8fc5529b", "", {}, "sha512-KZK8b6zCYGZFjd4ANze0pqBnqnFTS3GIVeclQpa2qseDpXrCQJfkWBixRcrZShNhm3LpFOZ8qJYFC5/qsJK9WQ=="],

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

View File

@ -1,23 +1,209 @@
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
static image_data_t image;
EXPORT(step) void step() {
// for (int i = 0; i < 1; i++) {
// int x1 = rand() % image.width;
// int y1 = rand() % image.height;
// int x2 = rand() % image.width;
// int y2 = rand() % image.height;
// D E F I N E S ///////////////////////////////////////////////////////////
// image_fill_rect(image, x1, y1, x2 - x1, y2 - y1, {(uint32_t)(rand() | 0xFF000000)});
// }
#define NUM_ASTEROIDS 10
#define ERASE 0
#define DRAW 1
// T Y P E D E F S ///////////////////////////////////////////////////////////
// the structure for a vertex
typedef struct vertex_typ {
float x, y; // a single point in the 2-D plane.
} vertex, *vertex_ptr;
// the structure for an object
typedef struct object_typ {
int num_vertices; // number of vertices in this object
uint32_t color; // color of object
float xo, yo; // position of object
float x_velocity; // x velocity of object
float y_velocity; // y velocity of object
float scale; // scale factor
float angle; // rotation rate
vertex vertices[16]; // 16 vertices
} object, *object_ptr;
object asteroids[NUM_ASTEROIDS];
void Scale_Object(object_ptr object, float scale) {
int index;
// for all vertices scale the x and y component
for (index = 0; index < object->num_vertices; index++) {
object->vertices[index].x *= scale;
object->vertices[index].y *= scale;
} // end for index
} // end Scale_Object
//////////////////////////////////////////////////////////////////////////////
void Rotate_Object(object_ptr object, float angle) {
int index;
float x_new, y_new, cs, sn;
// pre-compute sin and cos
cs = cos(angle);
sn = sin(angle);
// for each vertex rotate it by angle
for (index = 0; index < object->num_vertices; index++) {
// rotate the vertex
x_new = object->vertices[index].x * cs - object->vertices[index].y * sn;
y_new = object->vertices[index].y * cs + object->vertices[index].x * sn;
// store the rotated vertex back into structure
object->vertices[index].x = x_new;
object->vertices[index].y = y_new;
} // end for index
} // end Rotate_Object
//////////////////////////////////////////////////////////////////////////////
void Create_Field(void) {
int index;
for (index = 0; index < NUM_ASTEROIDS; index++) {
// fill in the fields
asteroids[index].num_vertices = 6;
asteroids[index].color = 0xFF000000 | (rand());
asteroids[index].xo = 21 + rand() % (image.width - 42);
asteroids[index].yo = 21 + rand() % (image.height - 42);
asteroids[index].x_velocity = -3 + rand() % 6;
asteroids[index].y_velocity = -3 + rand() % 6;
asteroids[index].scale = (float)(rand() % 30) / 10;
asteroids[index].angle = (float)(-5 + (float)(rand() % 10)) / 100;
asteroids[index].vertices[0].x = 4.0;
asteroids[index].vertices[0].y = 3.5;
asteroids[index].vertices[1].x = 8.5;
asteroids[index].vertices[1].y = -3.0;
asteroids[index].vertices[2].x = 6;
asteroids[index].vertices[2].y = -5;
asteroids[index].vertices[3].x = 2;
asteroids[index].vertices[3].y = -3;
asteroids[index].vertices[4].x = -4;
asteroids[index].vertices[4].y = -6;
asteroids[index].vertices[5].x = -3.5;
asteroids[index].vertices[5].y = 5.5;
// now scale the asteroid to proper size
Scale_Object((object_ptr)&asteroids[index], asteroids[index].scale);
} // end for index
} // end Create_Field
//////////////////////////////////////////////////////////////////////////////
void Draw_Asteroids(int erase) {
image_color_t color = {0xFF000000};
for (int index = 0; index < NUM_ASTEROIDS; index++) {
// draw the asteroid
if (erase == DRAW) {
color.color = asteroids[index].color;
}
// get position of object
float xo = asteroids[index].xo;
float yo = asteroids[index].yo;
// moveto first vertex
for (int startVertex = 0; startVertex < asteroids[index].num_vertices; startVertex++) {
int endVertex = (startVertex + 1) % asteroids[index].num_vertices;
int x1 = (int)(xo + asteroids[index].vertices[startVertex].x);
int y1 = (int)(yo + asteroids[index].vertices[startVertex].y);
int x2 = (int)(xo + asteroids[index].vertices[endVertex].x);
int y2 = (int)(yo + asteroids[index].vertices[endVertex].y);
image_draw_line(image, x1, y1, x2, y2, color);
} // end for vertex
} // end for index
} // end Draw_Asteroids
//////////////////////////////////////////////////////////////////////////////
void Translate_Asteroids() {
int index;
for (index = 0; index < NUM_ASTEROIDS; index++) {
// translate current asteroid
asteroids[index].xo += asteroids[index].x_velocity;
asteroids[index].yo += asteroids[index].y_velocity;
// collision detection i.e. bounds check
if (asteroids[index].xo > image.width - 20 || asteroids[index].xo < 20) {
asteroids[index].x_velocity = -asteroids[index].x_velocity;
asteroids[index].xo += asteroids[index].x_velocity;
}
if (asteroids[index].yo > image.height - 20 || asteroids[index].yo < 20) {
asteroids[index].y_velocity = -asteroids[index].y_velocity;
asteroids[index].yo += asteroids[index].y_velocity;
}
} // end for index
} // end Translate_Asteroids
//////////////////////////////////////////////////////////////////////////////
void Rotate_Asteroids(void) {
int index;
for (index = 0; index < NUM_ASTEROIDS; index++) {
// rotate current asteroid
Rotate_Object((object_ptr)&asteroids[index], asteroids[index].angle);
} // end for index
} // end Rotate_Asteroids
EXPORT(cpptest) image_data_t* cpptest(uint16_t w, uint16_t h) {
image = image_create(w, h);
image_fill_rect(image, 0, 0, w, h, {0xFF000000});
Create_Field();
return &image;
}
EXPORT(step) void step() {
Draw_Asteroids(ERASE);
// transform field
Rotate_Asteroids();
Translate_Asteroids();
// draw field
Draw_Asteroids(DRAW);
}

View File

@ -3,6 +3,6 @@ import awoo from "./awoo.cpp";
export default function main() {
const data = awoo.cpptest(window.innerWidth >> 2, window.innerHeight >> 2);
createWasmCanvas(awoo.data, data, awoo.step);
console.log(awoo);
const canvas = createWasmCanvas(awoo.data, data, awoo.step);
console.log(awoo, canvas.width, canvas.height);
}