diff --git a/server.c3 b/server.c3 index 42c8d30..754cc3a 100644 --- a/server.c3 +++ b/server.c3 @@ -245,13 +245,9 @@ fn BombsSpawnedBatchMessage *thrown_bombs_as_batch_message(Bombs *bombs) @extern return message; } -def ExplodedBombs = List(); +List() exploded_bombs; -fn ExplodedBombs *allocate_exploded_bombs() @extern("allocate_exploded_bombs") @wasm { - return mem::new(ExplodedBombs); -} - -fn void update_bombs_on_server_side(Scene *scene, float delta_time, ExplodedBombs *exploded_bombs, Bombs *bombs) @extern("update_bombs_on_server_side") @wasm { +fn void update_bombs_on_server_side(Scene *scene, float delta_time, Bombs *bombs) @extern("update_bombs_on_server_side") @wasm { foreach (bombIndex, &bomb: *bombs) { if (bomb.lifetime > 0) { common::update_bomb(bomb, scene, delta_time); @@ -262,14 +258,14 @@ fn void update_bombs_on_server_side(Scene *scene, float delta_time, ExplodedBomb } } -fn BombsExplodedBatchMessage* exploded_bombs_as_batch_message(ExplodedBombs* exploded_bombs, Bombs* bombs) @extern("exploded_bombs_as_batch_message") @wasm { +fn BombsExplodedBatchMessage* exploded_bombs_as_batch_message(Bombs* bombs) @extern("exploded_bombs_as_batch_message") @wasm { if (exploded_bombs.size == 0) return null; int size = BombsExplodedBatchMessage.sizeof + BombExploded.sizeof*exploded_bombs.size; BombsExplodedBatchMessage *message = mem::tcalloc(size); message.size = size; message.kind = MessageKind.BOMB_EXPLODED; - foreach (index, bombIndex: *exploded_bombs) { + foreach (index, bombIndex: exploded_bombs) { Bomb bomb = (*bombs)[bombIndex]; message.bombs[index].bombIndex = bombIndex; message.bombs[index].x = bomb.position.x; diff --git a/server.mjs b/server.mjs index b458474..274e94a 100644 --- a/server.mjs +++ b/server.mjs @@ -38,7 +38,6 @@ const joinedIds = new Set(); const leftIds = new Set(); const pingIds = new Map(); const level = common.createLevel(wasmServer); -const explodedBombsPtr = wasmServer.allocate_exploded_bombs(); wss.on("connection", (ws, req) => { ws.binaryType = 'arraybuffer'; if (players.size >= SERVER_TOTAL_LIMIT) { @@ -285,9 +284,9 @@ function tick() { messageSentCounter += 1; }); } - wasmServer.update_bombs_on_server_side(level.scenePtr, deltaTime, explodedBombsPtr, level.bombsPtr); + wasmServer.update_bombs_on_server_side(level.scenePtr, deltaTime, level.bombsPtr); const bufferBombsExploded = (() => { - const message = wasmServer.exploded_bombs_as_batch_message(explodedBombsPtr, level.bombsPtr); + const message = wasmServer.exploded_bombs_as_batch_message(level.bombsPtr); if (message === 0) return null; const size = new DataView(wasmServer.memory.buffer, message, common.UINT32_SIZE).getUint32(0, true); @@ -353,7 +352,6 @@ async function instantiateWasmServer(path) { throw_bomb: wasm.instance.exports.throw_bomb, throw_bomb_on_server_side: wasm.instance.exports.throw_bomb_on_server_side, thrown_bombs_as_batch_message: wasm.instance.exports.thrown_bombs_as_batch_message, - allocate_exploded_bombs: wasm.instance.exports.allocate_exploded_bombs, update_bombs_on_server_side: wasm.instance.exports.update_bombs_on_server_side, exploded_bombs_as_batch_message: wasm.instance.exports.exploded_bombs_as_batch_message }; diff --git a/server.mts b/server.mts index 1d24ab0..fa74545 100644 --- a/server.mts +++ b/server.mts @@ -47,7 +47,6 @@ const joinedIds = new Set() const leftIds = new Set() const pingIds = new Map() const level = common.createLevel(wasmServer); -const explodedBombsPtr = wasmServer.allocate_exploded_bombs(); wss.on("connection", (ws, req) => { ws.binaryType = 'arraybuffer'; @@ -334,9 +333,9 @@ function tick() { }); } - wasmServer.update_bombs_on_server_side(level.scenePtr, deltaTime, explodedBombsPtr, level.bombsPtr); + wasmServer.update_bombs_on_server_side(level.scenePtr, deltaTime, level.bombsPtr); const bufferBombsExploded = (() => { - const message = wasmServer.exploded_bombs_as_batch_message(explodedBombsPtr, level.bombsPtr); + const message = wasmServer.exploded_bombs_as_batch_message(level.bombsPtr); if (message === 0) return null; const size = new DataView(wasmServer.memory.buffer, message, common.UINT32_SIZE).getUint32(0, true); return new Uint8ClampedArray(wasmServer.memory.buffer, message + common.UINT32_SIZE, size - common.UINT32_SIZE); @@ -397,9 +396,8 @@ interface WasmServer extends common.WasmCommon { throw_bomb: (player_position_x: number, player_position_y: number, player_direction: number, bombs: number) => number, throw_bomb_on_server_side: (player_position_x: number, player_position_y: number, player_direction: number, bombs: number) => number, thrown_bombs_as_batch_message: (bombs: number) => number, - allocate_exploded_bombs: () => number, - update_bombs_on_server_side: (scene: number, delta_time: number, exploded_bombs: number, bombs: number) => void, - exploded_bombs_as_batch_message: (exploded_bombs: number, bombs: number) => number, + update_bombs_on_server_side: (scene: number, delta_time: number, bombs: number) => void, + exploded_bombs_as_batch_message: (bombs: number) => number, } function platform_now_secs(): number { @@ -430,9 +428,8 @@ async function instantiateWasmServer(path: string): Promise { throw_bomb: wasm.instance.exports.throw_bomb as (player_position_x: number, player_position_y: number, player_direction: number, bombs: number) => number, throw_bomb_on_server_side: wasm.instance.exports.throw_bomb_on_server_side as (player_position_x: number, player_position_y: number, player_direction: number, bombs: number) => number, thrown_bombs_as_batch_message: wasm.instance.exports.thrown_bombs_as_batch_message as (bombs: number) => number, - allocate_exploded_bombs: wasm.instance.exports.allocate_exploded_bombs as () => number, - update_bombs_on_server_side: wasm.instance.exports.update_bombs_on_server_side as (scene: number, delta_time: number, exploded_bombs: number, bombs: number) => void, - exploded_bombs_as_batch_message: wasm.instance.exports.exploded_bombs_as_batch_message as (exploded_bombs: number, bombs: number) => number + update_bombs_on_server_side: wasm.instance.exports.update_bombs_on_server_side as (scene: number, delta_time: number, bombs: number) => void, + exploded_bombs_as_batch_message: wasm.instance.exports.exploded_bombs_as_batch_message as (bombs: number) => number }; } diff --git a/server.wasm b/server.wasm index bbfcefc..3744aed 100755 Binary files a/server.wasm and b/server.wasm differ