public static bool DrawDynamicThings(DynamicDrawManager __instance) { if (!DebugViewSettings.drawThingsDynamic || null == map(__instance)) { return(false); } drawingNow(__instance) = true; try { bool[] fogGrid = map(__instance).fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(map(__instance)); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = map(__instance).cellIndices; SnowGrid snowGrid = map(__instance).snowGrid; /* * RimThreaded.fogGrid = map(__instance).fogGrid.fogGrid; * RimThreaded.cellRect = Find.CameraDriver.CurrentViewRect; * RimThreaded.cellRect.ClipInsideMap(map(__instance)); * RimThreaded.cellRect = RimThreaded.cellRect.ExpandedBy(1); * RimThreaded.cellIndices = map(__instance).cellIndices; * RimThreaded.snowGrid = map(__instance).snowGrid; * RimThreaded.drawQueue = new ConcurrentQueue<Thing>(drawThings(__instance)); * RimThreaded.startWorkerThreads(); */ //Thing drawThing; //Thing[] drawThingsArray; //for (int index = 0; index < drawThingsArray.Length; index++) foreach (Thing drawThing in drawThings(__instance).ToList()) { //drawThing = drawThingsArray[index]; IntVec3 position = drawThing.Position; if ((cellRect.Contains(position) || drawThing.def.drawOffscreen) && (!fogGrid[cellIndices.CellToIndex(position)] || drawThing.def.seeThroughFog) && ((double)drawThing.def.hideAtSnowDepth >= 1.0 || (double)snowGrid.GetDepth(position) <= (double)drawThing.def.hideAtSnowDepth)) { try { drawThing.Draw(); } catch (Exception ex) { Log.Error("Exception drawing " + (object)drawThing + ": " + ex.ToString(), false); } } } } catch (Exception ex) { Log.Error("Exception drawing dynamic things: " + (object)ex, false); } drawingNow(__instance) = false; return(false); }
public static bool DeRegisterDrawable(DynamicDrawManager __instance, Thing t) { if (t.def.drawerType != DrawerType.None) { if (drawingNow(__instance)) { Log.Warning("Cannot deregister drawable " + (object)t + " while drawing is in progress. Things shouldn't be despawned in Draw methods.", false); } drawThings.GetOrAdd(__instance, new ConcurrentDictionary <Thing, Thing>()).TryRemove(t, out _); } return(false); }
public static bool RegisterDrawable(DynamicDrawManager __instance, Thing t) { if (t.def.drawerType != DrawerType.None) { if (drawingNow(__instance)) { Log.Warning("Cannot register drawable " + t + " while drawing is in progress. Things shouldn't be spawned in Draw methods.", false); } lock (__instance) { drawThings(__instance).Add(t); } } return(false); }
public static bool DeRegisterDrawable(DynamicDrawManager __instance, Thing t) { if (t.def.drawerType != DrawerType.None) { if (drawingNow(__instance)) { Log.Warning("Cannot deregister drawable " + t + " while drawing is in progress. Things shouldn't be despawned in Draw methods.", false); } lock (__instance) { HashSet <Thing> newDrawThings = new HashSet <Thing>(drawThings(__instance)); newDrawThings.Remove(t); drawThings(__instance) = newDrawThings; } } return(false); }
public static bool DrawDynamicThings(DynamicDrawManager __instance) { if (!DebugViewSettings.drawThingsDynamic || null == map(__instance)) { return(false); } drawingNow(__instance) = true; try { bool[] fogGrid = map(__instance).fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(map(__instance)); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = map(__instance).cellIndices; foreach (Thing drawThing in drawThings.GetOrAdd(__instance, new ConcurrentDictionary <Thing, Thing>()).Values) { IntVec3 position = drawThing.Position; if ((cellRect.Contains(position) || drawThing.def.drawOffscreen) && (!fogGrid[cellIndices.CellToIndex(position)] || drawThing.def.seeThroughFog) && ((double)drawThing.def.hideAtSnowDepth >= 1.0 || (double)map(__instance).snowGrid.GetDepth(position) <= (double)drawThing.def.hideAtSnowDepth)) { try { drawThing.Draw(); } catch (Exception ex) { Log.Error("Exception drawing " + (object)drawThing + ": " + ex.ToString(), false); } } } } catch (Exception ex) { Log.Error("Exception drawing dynamic things: " + (object)ex, false); } drawingNow(__instance) = false; return(false); }
public static void DynamicDrawManagerPostfix(DynamicDrawManager __instance) { Map map = Traverse.Create(__instance).Field("map").GetValue <Map>(); var ZTracker = Current.Game.GetComponent <ZLevelsManager>(); foreach (var map2 in ZTracker.GetAllMaps(map.Tile) .OrderBy(x => ZTracker.GetZIndexFor(x))) { int curLevel = ZTracker.GetZIndexFor(map); int baseLevel = ZTracker.GetZIndexFor(map2); if (curLevel > baseLevel && baseLevel >= 0) { HashSet <Thing> drawThings = Traverse.Create(map2.dynamicDrawManager).Field("drawThings").GetValue <HashSet <Thing> >(); if (!DebugViewSettings.drawThingsDynamic) { return; } Traverse.Create(__instance).Field("drawingNow").SetValue(true); try { bool[] fogGrid = map2.fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(map2); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = map2.cellIndices; foreach (Thing thing in drawThings) { IntVec3 position = thing.Position; if (position.GetTerrain(map) == ZLevelsDefOf.ZL_OutsideTerrain) { if ((cellRect.Contains(position) || thing.def.drawOffscreen) //&& (!fogGrid[cellIndices.CellToIndex(position)] //|| thing.def.seeThroughFog) && (thing.def.hideAtSnowDepth >= 1f || map2.snowGrid.GetDepth(position) <= thing.def.hideAtSnowDepth)) { try { if (thing.Graphic is Graphic_Mote || thing.Graphic is Graphic_Linked) { } else if (thing.Graphic is Graphic_LinkedCornerFiller || thing.Graphic is Graphic_RandomRotated) { thing.Draw(); } else if (thing is Pawn pawn) { var newRenderer = new PawnRendererScaled(pawn); pawn.Drawer.renderer.graphics.ResolveAllGraphics(); newRenderer.graphics.nakedGraphic = pawn.Drawer.renderer.graphics.nakedGraphic; newRenderer.graphics.headGraphic = pawn.Drawer.renderer.graphics.headGraphic; newRenderer.graphics.hairGraphic = pawn.Drawer.renderer.graphics.hairGraphic; newRenderer.graphics.rottingGraphic = pawn.Drawer.renderer.graphics.rottingGraphic; newRenderer.graphics.dessicatedGraphic = pawn.Drawer.renderer.graphics.dessicatedGraphic; newRenderer.graphics.apparelGraphics = pawn.Drawer.renderer.graphics.apparelGraphics; newRenderer.graphics.packGraphic = pawn.Drawer.renderer.graphics.packGraphic; newRenderer.graphics.flasher = pawn.Drawer.renderer.graphics.flasher; newRenderer.RenderPawnAt(thing.DrawPos, curLevel, baseLevel); } else { Vector2 drawSize = thing.Graphic.drawSize; drawSize.x *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f); drawSize.y *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f); var newGraphic = thing.Graphic.GetCopy(drawSize); newGraphic.Draw(thing.DrawPos, thing.Rotation, thing); } } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception drawing ", thing, ": ", ex.ToString() }), false); } } } } } catch (Exception arg) { Log.Error("Exception drawing dynamic things: " + arg, false); } Traverse.Create(__instance).Field("drawingNow").SetValue(false); } } }
public static void DynamicDrawManagerPostfix(DynamicDrawManager __instance, Map ___map, ref bool ___drawingNow) { var ZTracker = ZUtils.ZTracker; int curLevel = ZTracker.GetZIndexFor(___map); if (curLevel > 0) { foreach (var map2 in ZTracker.GetAllMaps(___map.Tile)) //.OrderBy(x => ZTracker.GetZIndexFor(x))) { int baseLevel = ZTracker.GetZIndexFor(map2); if (curLevel > baseLevel && baseLevel >= 0) { ___drawingNow = true; bool[] fogGrid = map2.fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(map2); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = map2.cellIndices; foreach (Thing thing in map2.dynamicDrawManager.drawThings) { IntVec3 position = thing.Position; IntVec3 position2 = position + new IntVec3(0, 0, -1); if (position.GetTerrain(___map) == ZLevelsDefOf.ZL_OutsideTerrain || position2.InBounds(___map) && position.GetTerrain(___map) != ZLevelsDefOf.ZL_OutsideTerrain && position2.GetTerrain(___map) == ZLevelsDefOf.ZL_OutsideTerrain) { if ((cellRect.Contains(position) || thing.def.drawOffscreen) //&& (!fogGrid[cellIndices.CellToIndex(position)] //|| thing.def.seeThroughFog) && (thing.def.hideAtSnowDepth >= 1f || map2.snowGrid.GetDepth(position) <= thing.def.hideAtSnowDepth)) { DrawPos_Patch.ChangeDrawPos = true; DrawPos_Patch.zLevelOffset = (baseLevel - curLevel) / 3.5f; DrawPos_Patch.yLevelOffset = baseLevel - curLevel; try { var graphicType = thing.Graphic.GetType(); if (graphicType == typeof(Graphic_Mote)) { } else if (graphicType == typeof(Graphic_LinkedCornerFiller) || graphicType == typeof(Graphic_RandomRotated) || graphicType == typeof(Graphic_Linked)) { thing.Draw(); } else if (thing is Pawn pawn) { DrawPos_Patch.ChangeDrawPos = false; var newDrawPos = thing.DrawPos; newDrawPos.z += (baseLevel - curLevel) / 2f; newDrawPos.y -= baseLevel - curLevel; newDrawPos.y -= 4.1f; if (cachedPawnRenderers.ContainsKey(pawn)) { cachedPawnRenderers[pawn].RenderPawnAt(newDrawPos, curLevel, baseLevel); } else { var newRenderer = new PawnRendererScaled(pawn, pawn.Drawer.renderer.wiggler); pawn.Drawer.renderer.graphics.ResolveAllGraphics(); newRenderer.graphics.nakedGraphic = pawn.Drawer.renderer.graphics.nakedGraphic; newRenderer.graphics.headGraphic = pawn.Drawer.renderer.graphics.headGraphic; newRenderer.graphics.hairGraphic = pawn.Drawer.renderer.graphics.hairGraphic; newRenderer.graphics.rottingGraphic = pawn.Drawer.renderer.graphics.rottingGraphic; newRenderer.graphics.dessicatedGraphic = pawn.Drawer.renderer.graphics.dessicatedGraphic; newRenderer.graphics.apparelGraphics = pawn.Drawer.renderer.graphics.apparelGraphics; newRenderer.graphics.packGraphic = pawn.Drawer.renderer.graphics.packGraphic; newRenderer.graphics.flasher = pawn.Drawer.renderer.graphics.flasher; newRenderer.RenderPawnAt(newDrawPos, curLevel, baseLevel); cachedPawnRenderers[pawn] = newRenderer; } } else if (thing is Corpse corpse) { DrawPos_Patch.ChangeDrawPos = false; var newDrawPos = thing.DrawPos; newDrawPos.z += (baseLevel - curLevel) / 2f; newDrawPos.y -= baseLevel - curLevel; newDrawPos.y -= 4f; if (cachedCorpseRenderers.ContainsKey(corpse.InnerPawn)) { cachedCorpseRenderers[corpse.InnerPawn].RenderPawnAt(newDrawPos, curLevel, baseLevel); } else { var newRenderer = new PawnRendererScaled(corpse.InnerPawn, corpse.InnerPawn.Drawer.renderer.wiggler); corpse.InnerPawn.Drawer.renderer.graphics.ResolveAllGraphics(); newRenderer.graphics.nakedGraphic = corpse.InnerPawn.Drawer.renderer.graphics.nakedGraphic; newRenderer.graphics.headGraphic = corpse.InnerPawn.Drawer.renderer.graphics.headGraphic; newRenderer.graphics.hairGraphic = corpse.InnerPawn.Drawer.renderer.graphics.hairGraphic; newRenderer.graphics.rottingGraphic = corpse.InnerPawn.Drawer.renderer.graphics.rottingGraphic; newRenderer.graphics.dessicatedGraphic = corpse.InnerPawn.Drawer.renderer.graphics.dessicatedGraphic; newRenderer.graphics.apparelGraphics = corpse.InnerPawn.Drawer.renderer.graphics.apparelGraphics; newRenderer.graphics.packGraphic = corpse.InnerPawn.Drawer.renderer.graphics.packGraphic; newRenderer.graphics.flasher = corpse.InnerPawn.Drawer.renderer.graphics.flasher; newRenderer.RenderPawnAt(newDrawPos, curLevel, baseLevel); cachedCorpseRenderers[corpse.InnerPawn] = newRenderer; } } else if (thing.def.projectile == null && !thing.def.IsDoor) { Vector2 drawSize = thing.Graphic.drawSize; drawSize.x *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f); drawSize.y *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f); var newGraphic = thing.Graphic.GetCopy(drawSize); newGraphic.Draw(thing.DrawPos, thing.Rotation, thing); } else { if (thing is Building_Door door) { DrawPos_Patch.ChangeDrawPos = false; DrawDoor(door, baseLevel, curLevel); } else { thing.Draw(); } } } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception drawing ", thing, ": ", ex.ToString() }), false); } DrawPos_Patch.ChangeDrawPos = false; } } } ___drawingNow = false; } } } }
public static bool Prefix(DynamicDrawManager __instance) { if (!Active) { return(true); } __instance.drawingNow = true; try { var fogGrid = __instance.map.fogGrid.fogGrid; var cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(__instance.map); cellRect = cellRect.ExpandedBy(1); var cellIndices = __instance.map.cellIndices; foreach (var thing in __instance.drawThings) { var position = thing.Position; if (cellRect.Contains(position) || thing.def.drawOffscreen) { if (!fogGrid[cellIndices.CellToIndex(position)] || thing.def.seeThroughFog) { if (thing.def.hideAtSnowDepth >= 1f || __instance.map.snowGrid.GetDepth(thing.Position) <= thing.def.hideAtSnowDepth) { try { string Namer() { var n = string.Empty; if (ByDef) { n = $"{thing.def.defName} - {thing?.def?.modContentPack?.Name}"; } else { n = thing.GetType().ToString(); } return(n); } var name = string.Empty; if (ByDef) { name = thing.def.defName; } else { name = thing.GetType().Name; } Analyzer.Start(name, Namer, thing.GetType(), thing.def); thing.Draw(); Analyzer.Stop(name); } catch (Exception ex) { Log.Error(string.Concat("Exception drawing ", thing, ": ", ex.ToString())); } } } } } } catch (Exception arg) { Log.Error("Exception drawing dynamic things: " + arg); } __instance.drawingNow = false; return(false); }
static bool Prefix(ref DynamicDrawManager __instance) { Main.Instance?.Draw(); return(true); }
public static void Postfix(DynamicDrawManager __instance, Map ___map, ref bool ___drawingNow) { var ZTracker = ZUtils.ZTracker; int curLevel = ZTracker.GetZIndexFor(___map); if (curLevel > 0) { foreach (var map2 in ZTracker.GetAllMaps(___map.Tile)) //.OrderBy(x => ZTracker.GetZIndexFor(x))) { int baseLevel = ZTracker.GetZIndexFor(map2); if (curLevel > baseLevel && baseLevel >= 0) { ___drawingNow = true; bool[] fogGrid = map2.fogGrid.fogGrid; CellRect cellRect = Find.CameraDriver.CurrentViewRect; cellRect.ClipInsideMap(map2); cellRect = cellRect.ExpandedBy(1); CellIndices cellIndices = map2.cellIndices; foreach (Thing thing in map2.dynamicDrawManager.drawThings) { if (thing.def.drawerType != DrawerType.None && thing.def.drawerType != DrawerType.RealtimeOnly) { if (thing is Building_TurretGun turretGun) { var turretDrawPos = turretGun.DrawPos; turretDrawPos.y += Math.Abs(baseLevel - curLevel); turretDrawPos.z += (baseLevel - curLevel) / turretDrawZOffset; Vector3 b = new Vector3(turretGun.def.building.turretTopOffset.x, 0f, turretGun.def.building.turretTopOffset.y).RotatedBy(turretGun.top.CurRotation); float turretTopDrawSize = turretGun.top.parentTurret.def.building.turretTopDrawSize * (1f - (((float)(curLevel) - (float)baseLevel) / 5f)); Matrix4x4 matrix = default(Matrix4x4); matrix.SetTRS(turretDrawPos + Altitudes.AltIncVect + b, (turretGun.top.CurRotation + (float)TurretTop.ArtworkRotation).ToQuat(), new Vector3(turretTopDrawSize, 1f, turretTopDrawSize)); Graphics.DrawMesh(MeshPool.plane10, matrix, turretGun.def.building.turretTopMat, 0); } continue; } IntVec3 position = thing.Position; IntVec3 position2 = position + new IntVec3(0, 0, -1); var positionTerrain = position.GetTerrain(___map); if (positionTerrain == ZLevelsDefOf.ZL_OutsideTerrain || position2.InBounds(___map) && positionTerrain != ZLevelsDefOf.ZL_OutsideTerrain && position2.GetTerrain(___map) == ZLevelsDefOf.ZL_OutsideTerrain) { if ((cellRect.Contains(position) || thing.def.drawOffscreen) //&& (!fogGrid[cellIndices.CellToIndex(position)] //|| thing.def.seeThroughFog) && (thing.def.hideAtSnowDepth >= 1f || map2.snowGrid.GetDepth(position) <= thing.def.hideAtSnowDepth)) { DrawPos_Patch.ChangeDrawPos = true; DrawPos_Patch.zLevelOffset = (baseLevel - curLevel) / globalZOffset; DrawPos_Patch.yLevelOffset = baseLevel - curLevel; try { var graphicType = thing.Graphic.GetType(); if (graphicType == typeof(Graphic_LinkedCornerFiller) || graphicType == typeof(Graphic_Linked)) { thing.Draw(); } else if (thing is Pawn pawn) { DrawPos_Patch.ChangeDrawPos = false; var newDrawPos = thing.DrawPos; newDrawPos.z += (baseLevel - curLevel) / pawnZOffset; newDrawPos.y -= baseLevel - curLevel; newDrawPos.y -= pawnYOffset; // TODO Transpile PawnRenderer } else if (thing is Corpse corpse) { DrawPos_Patch.ChangeDrawPos = false; var newDrawPos = thing.DrawPos; newDrawPos.z += (baseLevel - curLevel) / pawnZOffset; newDrawPos.y -= baseLevel - curLevel; newDrawPos.y -= 4f; // TODO Transpile PawnRenderer } else if (thing.def.projectile == null && !thing.def.IsDoor) { if (!cachedGraphics.TryGetValue(thing, out var graphics)) { graphics = new Dictionary <int, Graphic>(); cachedGraphics[thing] = graphics; } if (!graphics.TryGetValue(curLevel, out var graphic) || true) { Vector2 drawSize = thing.Graphic.drawSize; drawSize.x *= 1f - ((curLevel - baseLevel) / thingDrawScale); drawSize.y *= 1f - ((curLevel - baseLevel) / thingDrawScale); if (thing.Graphic is Graphic_RandomRotated graphicRandomRotated) { graphic = graphicRandomRotated.subGraphic.GetCopy(drawSize, graphicRandomRotated.Shader); graphic.data = graphicRandomRotated.subGraphic.data; } else { graphic = thing.Graphic.GetCopy(drawSize, thing.Graphic.Shader); graphic.data = thing.Graphic.data; } graphic.data.drawSize = drawSize; graphics[curLevel] = graphic; } if (thing.def.mote != null) { DrawPos_Patch.zLevelOffset = (baseLevel - curLevel) / moteZOffset; } graphic.Draw(thing.DrawPos, thing.Rotation, thing); } else { if (thing is Building_Door door) { DrawPos_Patch.ChangeDrawPos = false; DrawDoor(door, baseLevel, curLevel); } else { thing.Draw(); } } } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception drawing ", thing, ": ", ex.ToString() })); } DrawPos_Patch.ChangeDrawPos = false; } } } ___drawingNow = false; } } } }
public static bool LogDynamicDrawThings(DynamicDrawManager __instance) { Log.Message(DebugLogsUtility.ThingListToUniqueCountString((IEnumerable <Thing>)drawThings.Values), false); return(false); }
public static bool LogDynamicDrawThings(DynamicDrawManager __instance) { Log.Message(DebugLogsUtility.ThingListToUniqueCountString(drawThings(__instance)), false); return(false); }