From 04b87fe82a231e2e731aac6da152f73cb41b8dcf Mon Sep 17 00:00:00 2001 From: Ne1gb Date: Thu, 19 Feb 2026 18:36:01 +0500 Subject: [PATCH 1/3] Fixes. --- Monofoxe/Monofoxe.Tiled/MapBuilder.cs | 10 +++++----- .../{Misc => Components}/ActorComponent.cs | 0 .../{Misc => Components}/PositionComponent.cs | 0 .../{Misc => Components}/TileCollisionComponent.cs | 0 Samples/Monofoxe.Samples/{Misc => Entities}/Ball.cs | 0 Samples/Monofoxe.Samples/{Misc => Entities}/Bot.cs | 0 Samples/Monofoxe.Samples/{Misc => Entities}/Player.cs | 0 Samples/Monofoxe.Samples/Game1.cs | 2 ++ Samples/Monofoxe.Samples/GameController.cs | 1 + Samples/Monofoxe.Samples/SceneSwitcher.cs | 2 +- .../Monofoxe.Samples/{Misc => }/Tiled/BotFactory.cs | 0 .../Monofoxe.Samples/{Misc => }/Tiled/PlayerFactory.cs | 0 .../{Misc => }/Tiled/SolidMapBuilder.cs | 6 +++--- .../{Misc => }/Tiled/SolidTilesetTile.cs | 0 14 files changed, 12 insertions(+), 9 deletions(-) rename Samples/Monofoxe.Samples/{Misc => Components}/ActorComponent.cs (100%) rename Samples/Monofoxe.Samples/{Misc => Components}/PositionComponent.cs (100%) rename Samples/Monofoxe.Samples/{Misc => Components}/TileCollisionComponent.cs (100%) rename Samples/Monofoxe.Samples/{Misc => Entities}/Ball.cs (100%) rename Samples/Monofoxe.Samples/{Misc => Entities}/Bot.cs (100%) rename Samples/Monofoxe.Samples/{Misc => Entities}/Player.cs (100%) rename Samples/Monofoxe.Samples/{Misc => }/Tiled/BotFactory.cs (100%) rename Samples/Monofoxe.Samples/{Misc => }/Tiled/PlayerFactory.cs (100%) rename Samples/Monofoxe.Samples/{Misc => }/Tiled/SolidMapBuilder.cs (95%) rename Samples/Monofoxe.Samples/{Misc => }/Tiled/SolidTilesetTile.cs (100%) diff --git a/Monofoxe/Monofoxe.Tiled/MapBuilder.cs b/Monofoxe/Monofoxe.Tiled/MapBuilder.cs index 965080a..90afa6d 100644 --- a/Monofoxe/Monofoxe.Tiled/MapBuilder.cs +++ b/Monofoxe/Monofoxe.Tiled/MapBuilder.cs @@ -161,11 +161,6 @@ protected Tileset GetTilesetFromTileIndex(int index) /// protected virtual List BuildLayers(List tilesets) { - if (TiledMap.GetLayers().Length != 0) - { - CreateTileLookupTable(tilesets); - } - var layers = new List(); foreach (var mapLayer in TiledMap.Layers) @@ -175,6 +170,11 @@ protected virtual List BuildLayers(List tilesets) if (mapLayer is TiledMapTileLayer) { + if (_tilesetLookupMap == null) + { + CreateTileLookupTable(tilesets); + } + BuildTileLayer((TiledMapTileLayer)mapLayer, layer); } if (mapLayer is TiledMapObjectLayer) diff --git a/Samples/Monofoxe.Samples/Misc/ActorComponent.cs b/Samples/Monofoxe.Samples/Components/ActorComponent.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/ActorComponent.cs rename to Samples/Monofoxe.Samples/Components/ActorComponent.cs diff --git a/Samples/Monofoxe.Samples/Misc/PositionComponent.cs b/Samples/Monofoxe.Samples/Components/PositionComponent.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/PositionComponent.cs rename to Samples/Monofoxe.Samples/Components/PositionComponent.cs diff --git a/Samples/Monofoxe.Samples/Misc/TileCollisionComponent.cs b/Samples/Monofoxe.Samples/Components/TileCollisionComponent.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/TileCollisionComponent.cs rename to Samples/Monofoxe.Samples/Components/TileCollisionComponent.cs diff --git a/Samples/Monofoxe.Samples/Misc/Ball.cs b/Samples/Monofoxe.Samples/Entities/Ball.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Ball.cs rename to Samples/Monofoxe.Samples/Entities/Ball.cs diff --git a/Samples/Monofoxe.Samples/Misc/Bot.cs b/Samples/Monofoxe.Samples/Entities/Bot.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Bot.cs rename to Samples/Monofoxe.Samples/Entities/Bot.cs diff --git a/Samples/Monofoxe.Samples/Misc/Player.cs b/Samples/Monofoxe.Samples/Entities/Player.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Player.cs rename to Samples/Monofoxe.Samples/Entities/Player.cs diff --git a/Samples/Monofoxe.Samples/Game1.cs b/Samples/Monofoxe.Samples/Game1.cs index f8e9432..115712a 100644 --- a/Samples/Monofoxe.Samples/Game1.cs +++ b/Samples/Monofoxe.Samples/Game1.cs @@ -44,6 +44,8 @@ protected override void Initialize() GraphicsMgr.VertexBatch.DepthStencilState = depth; + InactiveSleepTime = new System.TimeSpan(0); // Makes game not drop frames when window is inactive. + new GameController(); } diff --git a/Samples/Monofoxe.Samples/GameController.cs b/Samples/Monofoxe.Samples/GameController.cs index fab4371..2297c12 100644 --- a/Samples/Monofoxe.Samples/GameController.cs +++ b/Samples/Monofoxe.Samples/GameController.cs @@ -21,6 +21,7 @@ public class GameController : Entity private Stopwatch _stopwatch = new Stopwatch(); + // It is recommended to reuse random objects. public static RandomExt Random = new RandomExt(); public GameController() : base(SceneMgr.GetScene("default")["default"]) diff --git a/Samples/Monofoxe.Samples/SceneSwitcher.cs b/Samples/Monofoxe.Samples/SceneSwitcher.cs index 14e9bde..f8cef08 100644 --- a/Samples/Monofoxe.Samples/SceneSwitcher.cs +++ b/Samples/Monofoxe.Samples/SceneSwitcher.cs @@ -22,7 +22,7 @@ public class SceneSwitcher : Entity new SceneFactory(typeof(ECDemo), ECDemo.Description), new SceneFactory(typeof(SceneSystemDemo), SceneSystemDemo.Description), new SceneFactory(typeof(UtilsDemo)), - new SceneFactory(typeof(TiledDemo)), + new SceneFactory(typeof(TiledDemo), TiledDemo.Description), new SceneFactory(typeof(VertexBatchDemo)), new SceneFactory(typeof(CoroutinesDemo)), new SceneFactory(typeof(CollisionsDemo)), diff --git a/Samples/Monofoxe.Samples/Misc/Tiled/BotFactory.cs b/Samples/Monofoxe.Samples/Tiled/BotFactory.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Tiled/BotFactory.cs rename to Samples/Monofoxe.Samples/Tiled/BotFactory.cs diff --git a/Samples/Monofoxe.Samples/Misc/Tiled/PlayerFactory.cs b/Samples/Monofoxe.Samples/Tiled/PlayerFactory.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Tiled/PlayerFactory.cs rename to Samples/Monofoxe.Samples/Tiled/PlayerFactory.cs diff --git a/Samples/Monofoxe.Samples/Misc/Tiled/SolidMapBuilder.cs b/Samples/Monofoxe.Samples/Tiled/SolidMapBuilder.cs similarity index 95% rename from Samples/Monofoxe.Samples/Misc/Tiled/SolidMapBuilder.cs rename to Samples/Monofoxe.Samples/Tiled/SolidMapBuilder.cs index 167f09b..ad3bff6 100644 --- a/Samples/Monofoxe.Samples/Misc/Tiled/SolidMapBuilder.cs +++ b/Samples/Monofoxe.Samples/Tiled/SolidMapBuilder.cs @@ -14,7 +14,7 @@ namespace Monofoxe.Samples.Misc.Tiled public class SolidMapBuilder : MapBuilder { - public SolidMapBuilder(TiledMap tiledMap) : base(tiledMap) {} + public SolidMapBuilder(TiledMap tiledMap) : base(tiledMap) { } public override void Build() { @@ -63,11 +63,11 @@ ITilesetTile[] ConvertTiles(TiledMapTileset tiledTileset, Tileset tileset) // Getting solid property from the tile. var solid = false; - try + + if (tiledTile.Properties.ContainsKey("Solid")) { solid = bool.Parse(tiledTile.Properties["Solid"]); } - catch (Exception) {} // Getting solid property from the tile. SolidTilesetTile tilesetTile; diff --git a/Samples/Monofoxe.Samples/Misc/Tiled/SolidTilesetTile.cs b/Samples/Monofoxe.Samples/Tiled/SolidTilesetTile.cs similarity index 100% rename from Samples/Monofoxe.Samples/Misc/Tiled/SolidTilesetTile.cs rename to Samples/Monofoxe.Samples/Tiled/SolidTilesetTile.cs From 0afe41ceddfbdbefedca3d4b96dd2e01c27252c7 Mon Sep 17 00:00:00 2001 From: Ne1gb Date: Thu, 19 Feb 2026 18:47:00 +0500 Subject: [PATCH 2/3] Fixed some issues with Perlin noise. --- Monofoxe/Monofoxe.Engine/GameMgr.cs | 1 - Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs | 61 ++++++++++++------- Samples/Monofoxe.Samples/GameController.cs | 2 + 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Monofoxe/Monofoxe.Engine/GameMgr.cs b/Monofoxe/Monofoxe.Engine/GameMgr.cs index 7c1bed2..47dde8b 100644 --- a/Monofoxe/Monofoxe.Engine/GameMgr.cs +++ b/Monofoxe/Monofoxe.Engine/GameMgr.cs @@ -99,7 +99,6 @@ public static void Init(Game game) var keyboardBind = StuffResolver.GetStuff(); keyboardBind?.Init(); - Input.MaxGamepadCount = 2; WindowManager = new WindowMgr(game); diff --git a/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs b/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs index 8a542a8..755f42b 100644 --- a/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs +++ b/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs @@ -12,17 +12,22 @@ public enum NoiseType public static class PerlinNoise { - // Random seed - private static int _seed = new Random((int)DateTime.Now.Ticks).Next(); + private static int _seed = -1; public static int Seed { get => _seed; - set - { - _seed = value; - _reseed(); // Carmody - _recalculatePermutations(); // Gustavson - } + } + + /// + /// Updates seed and creating cache for Carmody and Gustavson simplexes. + /// + /// + public static void SetSeed(int seed) + { + _seed = seed; + + _reseed(); // Carmody + _recalculatePermutations(); // Gustavson } @@ -185,7 +190,8 @@ public static float CarmodyNoise(float x, float y, float z, bool doReseed = fals s = (i + j + k) * onesixth; u = x - i + s; v = y - j + s; - w = z - k + s; ; + w = z - k + s; + ; A[0] = A[1] = A[2] = 0; @@ -217,7 +223,7 @@ public static float GustavsonNoise(float xin, float yin, bool doRecalculate = fa _recalculatePermutations(); float n0, n1, n2; // Noise contributions from the three corners - // Skew the input space to determine which simplex cell we're in + // Skew the input space to determine which simplex cell we're in float F2 = 0.5f * ((float)Math.Sqrt(3.0f) - 1.0f); float s = (xin + yin) * F2; // Hairy factor for 2D int i = _fastfloor(xin + s); @@ -231,11 +237,13 @@ public static float GustavsonNoise(float xin, float yin, bool doRecalculate = fa // For the 2D case, the simplex shape is an equilateral triangle. // Determine which simplex we are in. int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords - if (x0 > y0) { i1 = 1; j1 = 0; } // lower triangle, XY order: (0,0)->(1,0)->(1,1) - else { i1 = 0; j1 = 1; } // upper triangle, YX order: (0,0)->(0,1)->(1,1) - // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and - // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where - // c = (3-Sqrt(3))/6 + if (x0 > y0) + { i1 = 1; j1 = 0; } // lower triangle, XY order: (0,0)->(1,0)->(1,1) + else + { i1 = 0; j1 = 1; } // upper triangle, YX order: (0,0)->(0,1)->(1,1) + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-Sqrt(3))/6 float x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords float y1 = y0 - j1 + G2; float x2 = x0 - 1.0f + 2.0f * G2; // Offsets for last corner in (x,y) unskewed coords @@ -295,7 +303,7 @@ public static float GustavsonNoise(float xin, float yin, float zin, bool doRecal _recalculatePermutations(); float n0, n1, n2, n3; // Noise contributions from the four corners - // Skew the input space to determine which simplex cell we're in + // Skew the input space to determine which simplex cell we're in float F3 = 1.0f / 3.0f; float s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D int i = _fastfloor(xin + s); @@ -317,14 +325,19 @@ public static float GustavsonNoise(float xin, float yin, float zin, bool doRecal { if (y0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; } // X Y Z order - else if (x0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order - else { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order + else if (x0 >= z0) + { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order + else + { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order } else { // x0> 5 & 1; int b4 = h >> 4 & 1; int b3 = h >> 3 & 1; diff --git a/Samples/Monofoxe.Samples/GameController.cs b/Samples/Monofoxe.Samples/GameController.cs index 2297c12..8afe7bd 100644 --- a/Samples/Monofoxe.Samples/GameController.cs +++ b/Samples/Monofoxe.Samples/GameController.cs @@ -29,6 +29,8 @@ public GameController() : base(SceneMgr.GetScene("default")["default"]) GameMgr.MaxGameSpeed = 60; GameMgr.MinGameSpeed = 60; // Fixing framerate on 60. + PerlinNoise.SetSeed(RandomExt.Global.Next()); + MainCamera.BackgroundColor = new Color(38, 38, 38); GameMgr.WindowManager.CanvasSize = MainCamera.Size; From 634f77e1f88eaa612439d6a5c3cad895c36e4863 Mon Sep 17 00:00:00 2001 From: Ne1gb Date: Fri, 20 Feb 2026 10:17:07 +0500 Subject: [PATCH 3/3] Fixes. --- Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs b/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs index 755f42b..0c1dde9 100644 --- a/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs +++ b/Monofoxe/Monofoxe.Engine/Utils/PerlinNoise.cs @@ -191,7 +191,6 @@ public static float CarmodyNoise(float x, float y, float z, bool doReseed = fals u = x - i + s; v = y - j + s; w = z - k + s; - ; A[0] = A[1] = A[2] = 0; @@ -223,7 +222,7 @@ public static float GustavsonNoise(float xin, float yin, bool doRecalculate = fa _recalculatePermutations(); float n0, n1, n2; // Noise contributions from the three corners - // Skew the input space to determine which simplex cell we're in + // Skew the input space to determine which simplex cell we're in float F2 = 0.5f * ((float)Math.Sqrt(3.0f) - 1.0f); float s = (xin + yin) * F2; // Hairy factor for 2D int i = _fastfloor(xin + s); @@ -237,13 +236,11 @@ public static float GustavsonNoise(float xin, float yin, bool doRecalculate = fa // For the 2D case, the simplex shape is an equilateral triangle. // Determine which simplex we are in. int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords - if (x0 > y0) - { i1 = 1; j1 = 0; } // lower triangle, XY order: (0,0)->(1,0)->(1,1) - else - { i1 = 0; j1 = 1; } // upper triangle, YX order: (0,0)->(0,1)->(1,1) - // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and - // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where - // c = (3-Sqrt(3))/6 + if (x0 > y0) { i1 = 1; j1 = 0; } // lower triangle, XY order: (0,0)->(1,0)->(1,1) + else { i1 = 0; j1 = 1; } // upper triangle, YX order: (0,0)->(0,1)->(1,1) + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-Sqrt(3))/6 float x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords float y1 = y0 - j1 + G2; float x2 = x0 - 1.0f + 2.0f * G2; // Offsets for last corner in (x,y) unskewed coords @@ -303,7 +300,7 @@ public static float GustavsonNoise(float xin, float yin, float zin, bool doRecal _recalculatePermutations(); float n0, n1, n2, n3; // Noise contributions from the four corners - // Skew the input space to determine which simplex cell we're in + // Skew the input space to determine which simplex cell we're in float F3 = 1.0f / 3.0f; float s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D int i = _fastfloor(xin + s); @@ -325,19 +322,14 @@ public static float GustavsonNoise(float xin, float yin, float zin, bool doRecal { if (y0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; } // X Y Z order - else if (x0 >= z0) - { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order - else - { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order + else if (x0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order + else { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order } else { // x0> 5 & 1; int b4 = h >> 4 & 1; int b3 = h >> 3 & 1;