diff --git a/server.c3 b/server.c3 index 7bcce48..42c8d30 100644 --- a/server.c3 +++ b/server.c3 @@ -216,25 +216,21 @@ fn ItemsCollectedBatchMessage *collected_items_as_batch_message(Item[]* items) @ /// Bombs ////////////////////////////// -def ThrownBombs = List(); +List() thrown_bombs; -fn ThrownBombs *allocate_thrown_bombs() @extern("allocate_thrown_bombs") @wasm { - return mem::new(ThrownBombs); -} - -fn void throw_bomb_on_server_side(float player_position_x, float player_position_y, float player_direction, Bombs *bombs, ThrownBombs *thrown_bombs) @extern("throw_bomb_on_server_side") @wasm { +fn void throw_bomb_on_server_side(float player_position_x, float player_position_y, float player_direction, Bombs *bombs) @extern("throw_bomb_on_server_side") @wasm { int index = common::throw_bomb(player_position_x, player_position_y, player_direction, bombs); if (index >= 0) thrown_bombs.push(index); } -fn BombsSpawnedBatchMessage *thrown_bombs_as_batch_message(Bombs *bombs, ThrownBombs *thrown_bombs) @extern("thrown_bombs_as_batch_message") @wasm { +fn BombsSpawnedBatchMessage *thrown_bombs_as_batch_message(Bombs *bombs) @extern("thrown_bombs_as_batch_message") @wasm { if (thrown_bombs.size == 0) return null; int size = BombsSpawnedBatchMessage.sizeof + BombSpawned.sizeof*thrown_bombs.size; BombsSpawnedBatchMessage *message = mem::tcalloc(size); message.size = size; message.kind = MessageKind.BOMB_SPAWNED; - foreach (index, bombIndex: *thrown_bombs) { + foreach (index, bombIndex: thrown_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 df37cb8..b458474 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 thrownBombsPtr = wasmServer.allocate_thrown_bombs(); const explodedBombsPtr = wasmServer.allocate_exploded_bombs(); wss.on("connection", (ws, req) => { ws.binaryType = 'arraybuffer'; @@ -104,7 +103,7 @@ wss.on("connection", (ws, req) => { } } else if (common.AmmaThrowingStruct.verify(view)) { - wasmServer.throw_bomb_on_server_side(player.position.x, player.position.y, player.direction, level.bombsPtr, thrownBombsPtr); + wasmServer.throw_bomb_on_server_side(player.position.x, player.position.y, player.direction, level.bombsPtr); } else if (common.PingStruct.verify(view)) { pingIds.set(id, common.PingStruct.timestamp.read(view)); @@ -254,7 +253,7 @@ function tick() { } } const bufferBombsThrown = (() => { - const message = wasmServer.thrown_bombs_as_batch_message(level.bombsPtr, thrownBombsPtr); + const message = wasmServer.thrown_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); @@ -351,7 +350,6 @@ async function instantiateWasmServer(path) { reconstruct_state_of_items: wasm.instance.exports.reconstruct_state_of_items, collect_items_by_player_at: wasm.instance.exports.collect_items_by_player_at, collected_items_as_batch_message: wasm.instance.exports.collected_items_as_batch_message, - allocate_thrown_bombs: wasm.instance.exports.allocate_thrown_bombs, 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, diff --git a/server.mts b/server.mts index 8775bde..1d24ab0 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 thrownBombsPtr = wasmServer.allocate_thrown_bombs(); const explodedBombsPtr = wasmServer.allocate_exploded_bombs(); wss.on("connection", (ws, req) => { @@ -123,7 +122,7 @@ wss.on("connection", (ws, req) => { player.newMoving &= ~(1< { - const message = wasmServer.thrown_bombs_as_batch_message(level.bombsPtr, thrownBombsPtr); + const message = wasmServer.thrown_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); @@ -395,10 +394,9 @@ interface WasmServer extends common.WasmCommon { reconstruct_state_of_items: (items: number) => number, collect_items_by_player_at: (player_position_x: number, player_position_y: number, items: number) => void, collected_items_as_batch_message: (items: number) => number, - allocate_thrown_bombs: () => number, 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, thrown_bombs: number) => number, - thrown_bombs_as_batch_message: (bombs: number, thrown_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, @@ -429,10 +427,9 @@ async function instantiateWasmServer(path: string): Promise { reconstruct_state_of_items: wasm.instance.exports.reconstruct_state_of_items as (items: number) => number, collect_items_by_player_at: wasm.instance.exports.collect_items_by_player_at as (player_position_x: number, player_position_y: number, items: number) => void, collected_items_as_batch_message: wasm.instance.exports.collected_items_as_batch_message as (items: number) => number, - allocate_thrown_bombs: wasm.instance.exports.allocate_thrown_bombs as () => number, 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, thrown_bombs: number) => number, - thrown_bombs_as_batch_message: wasm.instance.exports.thrown_bombs_as_batch_message as (bombs: number, thrown_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 diff --git a/server.wasm b/server.wasm index 69f96ce..bbfcefc 100755 Binary files a/server.wasm and b/server.wasm differ