Skip to content

Commit

Permalink
crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryMarkle committed Sep 10, 2024
1 parent 09e9823 commit 26a1a8d
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 17 deletions.
105 changes: 105 additions & 0 deletions Leditor.Renderer/Partial/Engine.Materials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3860,4 +3860,109 @@ in RenderTexture2D rt
}
}
}

protected virtual void DrawCeramicMaterial_MTX(
in MaterialDefinition mat,
int x,
int y,
int layer,
in RenderCamera camera,
in RenderTexture2D rt
) {
double chaos = 0;
var doColor = 0;

var eff = Level!.Effects.FirstOrDefault(e => e.Name == "Ceramic Chaos");

if (eff != null && eff.Options.Length > 1) {
var opt = eff.Options[2];

var (dmin, dmax) = (opt.Choice as string) switch {
"1" => (0, 0),
"2" => (1, 1),
"3" => (2, 2),
"1:st and 2:nd" => (0, 1),
"2:nd and 3:rd" => (1, 2),
_ => (0, 2)
};

if (layer <= dmax && layer >= dmin)
chaos = Data.Utils.InBounds(eff.Matrix, x, y) ? eff.Matrix[y, x] : 0;

doColor = Utils.BoolInt(eff.Options[1].Choice is "Colored");
}

if (doColor > 0) _anyDecals = true;

chaos *= 0.01;

var sublayer = layer * 10;
var pos = (new Vector2(x, y) - camera.Coords/20f) * 20 - Vector2.One * 10;
var color = new Color(239, 255, 255, 255);

int left = 0, top = 0, right = 0, bottom = 0;

var leftCell = Utils.GetGeoCellType(Level!.GeoMatrix, x - 1, y, layer);
var topCell = Utils.GetGeoCellType(Level!.GeoMatrix, x, y - 1, layer);
var rightCell = Utils.GetGeoCellType(Level!.GeoMatrix, x + 1, y, layer);
var bottomCell = Utils.GetGeoCellType(Level!.GeoMatrix, x, y + 1, layer);

if (leftCell != GeoType.Solid && (!Configuration.MaterialFixes || leftCell is not GeoType.SlopeNE or GeoType.SlopeNW or GeoType.SlopeES or GeoType.SlopeSW or GeoType.Platform))
{
left = 1;
}
if (topCell != GeoType.Solid && (!Configuration.MaterialFixes || topCell is not GeoType.SlopeNE or GeoType.SlopeNW or GeoType.SlopeES or GeoType.SlopeSW or GeoType.Platform))
{
top = 1;
}
if (rightCell != GeoType.Solid && (!Configuration.MaterialFixes || rightCell is not GeoType.SlopeNE or GeoType.SlopeNW or GeoType.SlopeES or GeoType.SlopeSW or GeoType.Platform))
{
right = 1;
}
if (bottomCell != GeoType.Solid && (!Configuration.MaterialFixes || bottomCell is not GeoType.SlopeNE or GeoType.SlopeNW or GeoType.SlopeES or GeoType.SlopeSW or GeoType.Platform))
{
bottom = 1;
}

var thisCell = Utils.GetGeoCellType(Level!.GeoMatrix, x, y, layer);

var socketTexture = thisCell switch {
GeoType.SlopeNE => State.ceramicTileSocketNE,
GeoType.SlopeNW => State.ceramicTileSocketNW,
GeoType.SlopeES => State.ceramicTileSocketSE,
GeoType.SlopeSW => State.ceramicTileSocketSW,
GeoType.Platform => State.ceramicTileSocketFL,
_ => State.ceramicTileSocket
};

var texture = thisCell switch {
GeoType.SlopeNE => State.ceramicTileSilhCPNE,
GeoType.SlopeNW => State.ceramicTileSilhCPNW,
GeoType.SlopeES => State.ceramicTileSilhCPSE,
GeoType.SlopeSW => State.ceramicTileSilhCPSW,
GeoType.Platform => State.ceramicTileSilhCPFL,
_ => State.ceramicTileSilhCPFL
};

if (thisCell is
GeoType.Solid or
GeoType.SlopeNE or
GeoType.SlopeNW or
GeoType.SlopeES or
GeoType.SlopeSW
) {
if (thisCell is GeoType.Solid) {
for (var q = 1; q <= 9; q++) {
BeginTextureMode(_layers[sublayer + q]);
DrawRectangleRec(
new Rectangle(-10+left, -10+top, 20-left-right, 20-top-bottom),
new Color(255 * (1 - doColor), 255*doColor, 0, 255)
);
EndTextureMode();
}
} else {

}
}
}
}
32 changes: 32 additions & 0 deletions Leditor.Renderer/Partial/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ protected class RenderState
public Texture2D circuitsImage;
public Texture2D densePipesImage;

public Texture2D ceramicTileSocket;
public Texture2D ceramicTileSocketNE;
public Texture2D ceramicTileSocketNW;
public Texture2D ceramicTileSocketSW;
public Texture2D ceramicTileSocketSE;
public Texture2D ceramicTileSocketFL;

public Texture2D ceramicTileSilhCPSW;
public Texture2D ceramicTileSilhCPNW;
public Texture2D ceramicTileSilhCPSE;
public Texture2D ceramicTileSilhCPNE;
public Texture2D ceramicTileSilhCPFL;


public virtual void Initialize(Registry registry)
{
if (Initialized) return;
Expand Down Expand Up @@ -315,6 +329,21 @@ public virtual void Initialize(Registry registry)
.ToDictionary(m => m.Item1, m => m.Item2, StringComparer.OrdinalIgnoreCase);
});

var ceramicTilesTask = Task.Run(() => {
ceramicTileSocket = internalLib["ceramicTileSocket"].Texture;
ceramicTileSocketNE = droughtLib["ceramicTileSocketNE"].Texture;
ceramicTileSocketNW = droughtLib["ceramicTileSocketNW"].Texture;
ceramicTileSocketSW = droughtLib["ceramicTileSocketSW"].Texture;
ceramicTileSocketSE = droughtLib["ceramicTileSocketSE"].Texture;
ceramicTileSocketFL = droughtLib["ceramicTileSocketFL"].Texture;

ceramicTileSilhCPSW = droughtLib["ceramicTileSilhCPSW"].Texture;
ceramicTileSilhCPNW = droughtLib["ceramicTileSilhCPNW"].Texture;
ceramicTileSilhCPSE = droughtLib["ceramicTileSilhCPSE"].Texture;
ceramicTileSilhCPNE = droughtLib["ceramicTileSilhCPNE"].Texture;
ceramicTileSilhCPFL = droughtLib["ceramicTileSilhCPFL"].Texture;
});

var memberTask = Task.Run(() => {
registry.Tiles?.Names.TryGetValue("Temple Stone Wedge", out TempleStoneWedge);
registry.Tiles?.Names.TryGetValue("Temple Stone Slope SE", out TempleStoneSlopeSE);
Expand Down Expand Up @@ -446,6 +475,7 @@ public virtual void Initialize(Registry registry)
wvTilesTask.Wait();
desnsePipesImagesTask.Wait();
desnsePipesImages2Task.Wait();
ceramicTilesTask.Wait();

Initialized = true;
}
Expand Down Expand Up @@ -538,6 +568,7 @@ public class Config
protected const int Height = 1200;

protected bool _tinySignsDrawn;
protected bool _anyDecals;

protected int _currentLayer;

Expand Down Expand Up @@ -698,6 +729,7 @@ protected virtual void Clear()

Level = null;
_tinySignsDrawn = false;
_anyDecals = false;
_currentLayer = 0;
}

Expand Down
23 changes: 23 additions & 0 deletions Leditor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,29 @@ void main() {
CloseWindow();
break;
}
catch (InvalidCastException ice)
{
Console.WriteLine(ice);
logger.Fatal($"Bruh Moment detected: loop try-catch block has caught an unexpected error: {ice}");

if (GLOBALS.Settings.Misc.FunnyDeathScreen)
{
var screenshot = LoadImageFromScreen();
screenshotTexture = LoadTextureFromImage(screenshot);
UnloadImage(screenshot);
}

deathScreen = new()
{
Screenshot = screenshotTexture,
Exception = ice,
Logger = logger
};



GLOBALS.Page = 99; // game over
}
catch (Exception e)
{
logger.Fatal($"Bruh Moment detected: loop try-catch block has caught an unexpected error: {e}");
Expand Down
4 changes: 2 additions & 2 deletions Leditor/Serialization/Importers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ public static ((string category, Color color)[] categories, InitPropBase[][] ini
/// <exception cref="MissingInitPropertyException">retrieved prop is missing a setting</exception>
public static List<Prop_Legacy>GetProps(AstNode.Base? @base)
{
if (@base is null) {
if (@base is null || @base is not AstNode.PropertyList pl) {
return [];
}

var list = (AstNode.List)((AstNode.PropertyList)@base).Values.Single(p => ((AstNode.Symbol)p.Key).Value == "props").Value;
var list = (AstNode.List)(pl).Values.Single(p => ((AstNode.Symbol)p.Key).Value == "props").Value;

List<Prop_Legacy> props = [];

Expand Down
24 changes: 13 additions & 11 deletions Leditor/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,26 @@ internal static async Task<LoadFileResult> LoadProjectAsync(string filePath)

if (text.Length < 7) return new LoadFileResult();

var objTask = Task.Factory.StartNew(() =>
var objTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[0]));
var tilesObjTask = Task.Factory.StartNew(() =>
var tilesObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[1]));
var terrainObjTask = Task.Factory.StartNew(() =>
var terrainObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[4]));
var obj2Task = Task.Factory.StartNew(() =>
var obj2Task = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[5]));
var effObjTask = Task.Factory.StartNew(() =>
var effObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[2]));
var lightObjTask = Task.Factory.StartNew(() =>
var lightObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[3]));
var camsObjTask = Task.Factory.StartNew(() =>
var camsObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[6]));
var waterObjTask = Task.Factory.StartNew(() =>
var waterObjTask = Task.Run(() =>
LingoParser.Expression.ParseOrThrow(text[7]));

var propsObjTask = string.IsNullOrEmpty(text[8]) ? null : Task.Factory.StartNew(() =>
LingoParser.Expression.ParseOrThrow(text[8]));
var propsObjTask = string.IsNullOrEmpty(text[8])
? null
: Task.Run(() => LingoParser.Expression.Parse(text[8]));

AstNode.Base obj;
AstNode.Base tilesObj;
Expand Down Expand Up @@ -274,7 +275,8 @@ internal static async Task<LoadFileResult> LoadProjectAsync(string filePath)
}

try {
propsObj = propsObjTask is null ? null : await propsObjTask;
var parseRes = propsObjTask is null ? null : await propsObjTask;
propsObj = parseRes?.Success == true ? parseRes.Value : null;
} catch (Exception e) {
propsObj = null;
propsLoadException = e;
Expand Down
4 changes: 2 additions & 2 deletions Leditor/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Collapsed=0

[Window][WindowOverViewport_11111111]
Pos=0,19
Size=1920,972
Size=1300,831
Collapsed=0

[Window][Shortcuts##EditorShortcuts]
Expand All @@ -196,7 +196,7 @@ Size=256,477
Collapsed=0

[Docking][Data]
DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1920,972 CentralNode=1
DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1300,831 CentralNode=1
DockSpace ID=0x8B93E3BD Pos=0,19 Size=1280,781 Split=X
DockNode ID=0x0000001B Parent=0x8B93E3BD SizeRef=939,800 Split=X
DockNode ID=0x00000011 Parent=0x0000001B SizeRef=887,991 Split=X
Expand Down
2 changes: 1 addition & 1 deletion Release_Notes.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fixed cameras snapping back afteer dragging them.
- Midigated the chances of the program crashing when loading levels with malformed props line.
2 changes: 1 addition & 1 deletion Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.99-6
0.9.99-7

0 comments on commit 26a1a8d

Please sign in to comment.