From d1e23b545560b9f9ae1527ebcf4a9eb83efdf5da Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 14 Feb 2025 09:26:07 +0000 Subject: [PATCH] refactor platform and wall type declarations out into platform.sml and wall.sml --- fcore/enemy/enemy.sml | 12 ++++++++++++ fcore/game-type.sml | 17 ++++------------- fcore/physics.sml | 4 ++-- fcore/platform.sml | 1 + fcore/wall.sml | 2 ++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/fcore/enemy/enemy.sml b/fcore/enemy/enemy.sml index dfe5d65..de34279 100644 --- a/fcore/enemy/enemy.sml +++ b/fcore/enemy/enemy.sml @@ -15,6 +15,18 @@ struct structure EnemyMap = MakeGapMap(EnemyPair) + (* - Updating state of enemies per-frame - *) + (* + structure UpdateEnemies = MakeGapMapMapper (struct + structure Pair = EnemyPair + + type env = {walls: wall vector, wallTree: QuadTree.t, platforms: platform + vector, platformTree: QuadTree.t} + + (enemy, walls, wallTree, platforms, platformTree, player, graph) = + end) + *) + (* - Generating enemy tree - *) structure EnemyTree = MakeGapMapFolder diff --git a/fcore/game-type.sml b/fcore/game-type.sml index 9dbf68e..6734082 100644 --- a/fcore/game-type.sml +++ b/fcore/game-type.sml @@ -1,9 +1,5 @@ signature GAME_TYPE = sig - type wall = {id: int, x: int, y: int, width: int, height: int} - - type platform = {id: int, x: int, y: int, width: int} - datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int datatype player_attacked = NOT_ATTACKED | ATTACKED of int @@ -37,9 +33,9 @@ sig type game_type = { player: player - , walls: wall vector + , walls: Wall.t vector , wallTree: QuadTree.t - , platforms: platform vector + , platforms: Platform.t vector , platformTree: QuadTree.t , enemies: EnemyMap.t , graph: PlatSet.elem vector vector @@ -51,11 +47,6 @@ end structure GameType :> GAME_TYPE = struct - type wall = {id: int, x: int, y: int, width: int, height: int} - - (* all platforms have a fixed visual height and a fixed collision height *) - type platform = {id: int, x: int, y: int, width: int} - datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int datatype player_attacked = NOT_ATTACKED | ATTACKED of int @@ -89,9 +80,9 @@ struct type game_type = { player: player - , walls: wall vector + , walls: Wall.t vector , wallTree: QuadTree.t - , platforms: platform vector + , platforms: Platform.t vector , platformTree: QuadTree.t , enemies: EnemyMap.t , graph: PlatSet.elem vector vector diff --git a/fcore/physics.sml b/fcore/physics.sml index 80c4ce8..ecbdb4a 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -158,7 +158,7 @@ struct end fun getEnvironmentPatches - (input, walls: wall vector, wallTree, platforms, platformTree) = + (input, walls: Wall.t vector, wallTree, platforms, platformTree) = let (* react to platform and wall collisions *) val x = Fn.getX input @@ -185,7 +185,7 @@ struct let (* default case: * player will land on platform and stay on the ground there. *) - val {y = platY, ...}: GameType.platform = + val {y = platY, ...}: Platform.t = Vector.sub (platforms, standPlatID - 1) val newY = platY - Fn.entitySize diff --git a/fcore/platform.sml b/fcore/platform.sml index d21a7f1..50a2097 100644 --- a/fcore/platform.sml +++ b/fcore/platform.sml @@ -1,5 +1,6 @@ structure Platform = struct + type t = {id: int, x: int, y: int, width: int} (* collision height of a platform. * Visual height may (and probably will) be different. *) val platHeight = 5 diff --git a/fcore/wall.sml b/fcore/wall.sml index fbbea24..cf9fa6a 100644 --- a/fcore/wall.sml +++ b/fcore/wall.sml @@ -1,5 +1,7 @@ structure Wall = struct + type t = {id: int, x: int, y: int, width: int, height: int} + fun helpGenerateTree (pos, wallVec, acc) = if pos = Vector.length wallVec then acc