void InitZoomLevels() { for (int k = 0; k < zoomLevelsInfo.Length; k++) { ZoomLevelInfo zi = new ZoomLevelInfo(); zi.xMax = (int)Mathf.Pow(2, k); zi.yMax = zi.xMax; zoomLevelsInfo [k] = zi; } }
int GetTileHashCode(int x, int y, int zoomLevel) { ZoomLevelInfo zi = zoomLevelsInfo [zoomLevel]; if (zi == null) { return(0); } int hashCode = zi.zoomLevelHash + zi.yHash * y + x; return(hashCode); }
int GetTileHashCode(int x, int y, int zoomLevel) { ZoomLevelInfo zi = zoomLevelsInfo [zoomLevel]; if (zi == null) { return(0); } int xMax = zi.xMax; x = (x + xMax) % xMax; int hashCode = (int)Mathf.Pow(4, zoomLevel) + (int)Mathf.Pow(2, zoomLevel) * y + x; return(hashCode); }
void CreateTile(TileInfo ti) { Vector2 latLonTL = ti.latlons [0]; Vector2 latLonBR; ZoomLevelInfo zi = zoomLevelsInfo [ti.zoomLevel]; int tileCode = GetTileHashCode(ti.x + 1, ti.y + 1, ti.zoomLevel); TileInfo cachedTile; if (cachedTiles.TryGetValue(tileCode, out cachedTile)) { latLonBR = cachedTile.latlons [0]; } else { latLonBR = Conversion.GetLatLonFromTile(ti.x + 1, ti.y + 1, ti.zoomLevel); } // Create container GameObject parentObj; if (ti.parent == null) { parentObj = zi.tilesContainer; if (parentObj == null) { parentObj = new GameObject("Tiles" + ti.zoomLevel); parentObj.transform.SetParent(tilesRoot, false); parentObj.layer = tilesRoot.gameObject.layer; zi.tilesContainer = parentObj; } } else { parentObj = ti.parent.gameObject; } // Prepare mesh vertices Vector3[] tileCorners = new Vector3[4]; tileCorners [0] = Conversion.GetLocalPositionFromLatLon(latLonTL); tileCorners [1] = Conversion.GetLocalPositionFromLatLon(new Vector2(latLonTL.x, latLonBR.y)); tileCorners [2] = Conversion.GetLocalPositionFromLatLon(latLonBR); tileCorners [3] = Conversion.GetLocalPositionFromLatLon(new Vector2(latLonBR.x, latLonTL.y)); // Add small offset to avoid seams on higher zoom levels if (ti.zoomLevel > 150) { const float offset = 0.00000001f; tileCorners [1].x += offset; tileCorners [2].x += offset; tileCorners [2].y -= offset; tileCorners [3].y -= offset; } // Setup tile materials TileInfo parent = ti.parent != null ? ti.parent : ti; if (parent.normalMat == null) { parent.normalMat = Instantiate(tileMatRef); if (disposalManager != null) { disposalManager.MarkForDisposal(parent.normalMat); } } if (parent.transMat == null) { parent.transMat = Instantiate(tileMatTransRef); if (disposalManager != null) { disposalManager.MarkForDisposal(parent.transMat); } } Material tileMat = ti.zoomLevel < TILE_MIN_ZOOM_LEVEL ? parent.normalMat : parent.transMat; // UVs wrt Earth texture Vector2 tl = new Vector2((latLonTL.y + 180) / 360f, (latLonTL.x + 90) / 180f); Vector2 br = new Vector2((latLonBR.y + 180) / 360f, (latLonBR.x + 90) / 180f); if (tl.x > 0.5f && br.x < 0.5f) { br.x = 1f; } ti.worldTextureCoords = new Vector4(tl.x, br.y, br.x, tl.y); ti.ClearPlaceholderImage(); if (ti.zoomLevel < TILE_MIN_ZOOM_LEVEL) { ti.loadStatus = TILE_LOAD_STATUS.Loaded; } ti.texture = currentEarthTexture; ti.renderer = CreateObject(parentObj.transform, "Tile", tileCorners, tileIndices, tileUV, tileMat, ti.subquadIndex); ti.gameObject = ti.renderer.gameObject; ti.renderer.enabled = false; ti.created = true; #if DEBUG_TILES ti.gameObject.AddComponent <TileInfoEx> (); #endif }
void LateUpdateTiles() { if (!Application.isPlaying || cachedTiles == null) { return; } if (Time.time - lastDisposalTime > 3) { lastDisposalTime = Time.time; MonitorInactiveTiles(); } if (shouldCheckTiles || flyToActive) { shouldCheckTiles = false; currentCameraPosition = currentCamera.transform.position; _currentZoomLevel = GetTileZoomLevel(); int startingZoomLevel = TILE_MIN_ZOOM_LEVEL - 1; ZoomLevelInfo zi = zoomLevelsInfo [startingZoomLevel]; int currentLoadQueueSize = loadQueue.Count; int qCount = loadQueue.Count; for (int k = 0; k < qCount; k++) { loadQueue [k].visible = false; } GeometryUtility.CalculateFrustumPlanes(currentCamera.projectionMatrix * currentCamera.worldToCameraMatrix, cameraPlanes); if (_wrapHorizontally && _wrapCamera.enabled) { GeometryUtility.CalculateFrustumPlanes(_wrapCamera.projectionMatrix * _wrapCamera.worldToCameraMatrix, wrapCameraPlanes); } for (int k = 0; k < zi.xMax; k++) { for (int j = 0; j < zi.yMax; j++) { CheckTiles(null, _currentZoomLevel, k, j, startingZoomLevel, 0); } } if (currentLoadQueueSize != loadQueue.Count) { resortTiles = true; } if (resortTiles) { resortTiles = false; loadQueue.Sort((TileInfo x, TileInfo y) => { if (x.distToCamera < y.distToCamera) { return(-1); } else if (x.distToCamera > y.distToCamera) { return(1); } else { return(0); } }); } // Ensure local cache max size is not exceeded long maxLocalCacheSize = _tileMaxLocalCacheSize * 1024 * 1024; if (cachedFiles != null && _tileCurrentCacheUsage > maxLocalCacheSize) { for (int f = 0; f < cachedFiles.Length; f++) { if (cachedFiles [f] != null && cachedFiles [f].Exists) { if (_tilePreloadTiles && cachedFiles [f].Name.StartsWith(PREFIX_MIN_ZOOM_LEVEL)) { continue; } _tileCurrentCacheUsage -= cachedFiles [f].Length; cachedFiles [f].Delete(); } if (_tileCurrentCacheUsage <= maxLocalCacheSize) { break; } } } } CheckTilesContent(_currentZoomLevel); spreadLoadAmongFrames = _tileMaxTileLoadsPerFrame; }
public static bool ResearchNode_Draw_Prefix(object __instance, Rect visibleRect, bool forceDetailedMode = false) { //Reflected objects Rect rect = (Rect)RectInfo.GetValue(__instance); ResearchProjectDef Research = (ResearchProjectDef)ResearchInfo.GetValue(__instance); bool available = (bool)AvailableInfo.GetValue(__instance); bool completed = Research.IsFinished; //simplified // if (!(bool)IsVisibleInfo.Invoke(__instance, new object[] { visibleRect })) { HighlightedProxy(__instance, false); return(false); } bool detailedMode = forceDetailedMode || (float)ZoomLevelInfo.GetValue(InstanceInfo.GetValue(__instance)) < DetailedModeZoomLevelCutoff; bool mouseOver = Mouse.IsOver(rect); bool highlighted = HighlightedProxy(__instance); if (Event.current.type == EventType.Repaint) { //researches that are completed or could be started immediately, and that have the required building(s) available GUI.color = mouseOver ? BrightColor : (Color)ColorInfo.GetValue(__instance); if (mouseOver || highlighted) { GUI.DrawTexture(rect, ResearchTree_Assets.ButtonActive); } else { GUI.DrawTexture(rect, ResearchTree_Assets.Button); } //grey out center to create a progress bar effect, completely greying out research not started. if (available) { var progressBarRect = rect.ContractedBy(3f); GUI.color = ResearchTree_Assets.ColorAvailable[Research.techLevel]; progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width; GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex); } HighlightedProxy(__instance, interest == Research); //draw the research label if (!completed && !available) { GUI.color = Color.grey; } else { GUI.color = Color.white; } if (detailedMode) { Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = false; Text.Font = (bool)largeLabelInfo.GetValue(__instance) ? GameFont.Tiny : GameFont.Small; Widgets.Label((Rect)LabelRectInfo.GetValue(__instance), Research.LabelCap); } else { Text.Anchor = TextAnchor.MiddleCenter; Text.WordWrap = false; Text.Font = GameFont.Medium; Widgets.Label(rect, Research.LabelCap); } //draw research cost and icon if (detailedMode) { Text.Anchor = TextAnchor.UpperRight; Text.Font = Research.CostApparent > 1000000 ? GameFont.Tiny : GameFont.Small; Widgets.Label((Rect)CostLabelRectInfo.GetValue(__instance), Research.CostApparent.ToStringByStyle(ToStringStyle.Integer)); GUI.DrawTexture((Rect)CostIconRectInfo.GetValue(__instance), !completed && !available ? ResearchTree_Assets.Lock : ResearchTree_Assets.ResearchIcon, ScaleMode.ScaleToFit); } Text.WordWrap = true; //attach description and further info to a tooltip string root = HarmonyPatches.ResearchPal ? "ResearchPal" : "Fluffy.ResearchTree"; TooltipHandler.TipRegion(rect, new Func <string>(() => (string)GetResearchTooltipStringInfo.Invoke(__instance, new object[] { })), Research.GetHashCode()); if (!BuildingPresentProxy(Research)) { string languageKey = root + ".MissingFacilities"; TooltipHandler.TipRegion(rect, languageKey.Translate(string.Join(", ", MissingFacilities(Research).Select(td => td.LabelCap).ToArray()))); } else if (!TechprintAvailable(Research)) { string languageKey = root + ".MissingTechprints"; TooltipHandler.TipRegion(rect, languageKey.Translate(Research.TechprintsApplied, Research.techprintCount)); } //draw unlock icons if (detailedMode) { Rect IconsRect = (Rect)IconsRectInfo.GetValue(__instance); var unlocks = GetUnlockDefsAndDescs(Research); for (var i = 0; i < unlocks.Count; i++) { var iconRect = new Rect( IconsRect.xMax - (i + 1) * (IconSize.x + 4f), IconsRect.yMin + (IconsRect.height - IconSize.y) / 2f, IconSize.x, IconSize.y); if (iconRect.xMin - IconSize.x < IconsRect.xMin && i + 1 < unlocks.Count) { //stop the loop if we're about to overflow and have 2 or more unlocks yet to print. iconRect.x = IconsRect.x + 4f; GUI.DrawTexture(iconRect, ResearchTree_Assets.MoreIcon, ScaleMode.ScaleToFit); var tip = string.Join("\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second).ToArray()); TooltipHandler.TipRegion(iconRect, tip); //new TipSignal(tip, Settings.TipID, TooltipPriority.Pawn) ); break; } //draw icon unlocks[i].First.DrawColouredIcon(iconRect); //tooltip TooltipHandler.TipRegion(iconRect, unlocks[i].Second); } } if (mouseOver) { if (interest != null && interest != Research) { DeInterest(); } //highlight prerequisites if research available if (available) { HighlightedProxy(__instance, true); foreach (var prerequisite in (IEnumerable <object>)GetMissingRequiredRecursiveInfo.Invoke(__instance, new object[] { })) { HighlightedProxy(Convert.ChangeType(prerequisite, ResearchNodeType()), true); } } //highlight children if completed else if (completed) { foreach (var child in (IEnumerable <object>)ChildrenInfo.GetValue(__instance)) { HighlightedProxy(Convert.ChangeType(child, ResearchNodeType()), true); } } } } //CUSTOM: a bunch of things on top Research.DrawExtras(rect, mouseOver || highlighted); if (Widgets.ButtonInvisible(rect)) { //CUSTOM: replaced queue operations for assignment menu if (Event.current.button == 0) { Research.SelectMenu(completed); } if (DebugSettings.godMode && Prefs.DevMode && Event.current.button == 1 && !Research.IsFinished) { Find.ResearchManager.FinishProject(Research); Research.WipeAssignments(); } } return(false); }
void CreateTile(TileInfo ti) { Vector2 latLonTL = ti.latlons [0]; Vector2 latLonBR; ZoomLevelInfo zi = zoomLevelsInfo [ti.zoomLevel]; int tileCode = GetTileHashCode(ti.x + 1, ti.y + 1, ti.zoomLevel); if (cachedTiles.ContainsKey(tileCode)) { latLonBR = cachedTiles [tileCode].latlons [0]; } else { latLonBR = GetLatLonFromTile(ti.x + 1, ti.y + 1, ti.zoomLevel); } // Create container GameObject parentObj; if (ti.parent == null) { parentObj = zi.tilesContainer; if (parentObj == null) { parentObj = new GameObject("Tiles" + ti.zoomLevel); parentObj.transform.SetParent(tilesRoot, false); zi.tilesContainer = parentObj; } } else { parentObj = ti.parent.gameObject; } // Prepare mesh vertices Vector3[] tileCorners = new Vector3[4]; tileCorners [0] = Conversion.GetSpherePointFromLatLon(latLonTL); tileCorners [1] = Conversion.GetSpherePointFromLatLon(new Vector2(latLonTL.x, latLonBR.y)); tileCorners [2] = Conversion.GetSpherePointFromLatLon(latLonBR); tileCorners [3] = Conversion.GetSpherePointFromLatLon(new Vector2(latLonBR.x, latLonTL.y)); Vector2[] meshUV; if (ti.zoomLevel < TILE_MIN_ZOOM_LEVEL) { Vector2[] uv = new Vector2[4]; uv [0] = new Vector2((latLonTL.y + 180) / 360f, (latLonTL.x + 90) / 180f); uv [1] = new Vector2((latLonBR.y + 180) / 360f, (latLonTL.x + 90) / 180f); uv [2] = new Vector2((latLonBR.y + 180) / 360f, (latLonBR.x + 90) / 180f); uv [3] = new Vector2((latLonTL.y + 180) / 360f, (latLonBR.x + 90) / 180f); meshUV = uv; } else { meshUV = tileUV; } Material tileMat; if (ti.parent != null) { if (ti.parent.normalMat == null) { ti.parent.normalMat = Instantiate(tileMatRef); ti.parent.normalMat.hideFlags = HideFlags.DontSave; } if (ti.zoomLevel < TILE_MIN_ZOOM_LEVEL) { tileMat = ti.parent.normalMat; } else { if (ti.parent.transMat == null) { ti.parent.transMat = Instantiate(tileMatTransRef); ti.parent.transMat.hideFlags = HideFlags.DontSave; } tileMat = ti.parent.transMat; } } else { ti.normalMat = Instantiate(tileMatRef); ti.normalMat.hideFlags = HideFlags.DontSave; tileMat = ti.normalMat; } ti.renderer = CreateObject(parentObj.transform, "Tile", tileCorners, tileIndices, meshUV, tileMat, ti.subquadIndex); ti.gameObject = ti.renderer.gameObject; ti.created = true; }
// int visibleTiles, lastVisibleTiles; void LateUpdateTiles() { // Shader.SetGlobalVector ("_SunLightDirection", _earthScenicLightDirection.normalized); if (!Application.isPlaying || cachedTiles == null) { return; } if (shouldCheckTiles) { shouldCheckTiles = false; _currentZoomLevel = GetTileZoomLevel(); int startingZoomLevel = TILE_MIN_ZOOM_LEVEL - 1; ZoomLevelInfo zi = zoomLevelsInfo [startingZoomLevel]; int currentLoadQueueSize = loadQueue.Count; // visibleTiles = 0; int qCount = loadQueue.Count; for (int k = 0; k < qCount; k++) { loadQueue [k].visible = false; } for (int k = 0; k < zi.xMax; k++) { for (int j = 0; j < zi.yMax; j++) { CheckTiles(null, _currentZoomLevel, k, j, startingZoomLevel, 0); } } // if(lastVisibleTiles!=visibleTiles) { // lastVisibleTiles = visibleTiles; // Debug.Log (visibleTiles); // } if (currentLoadQueueSize != loadQueue.Count) { resortTiles = true; } if (resortTiles) { resortTiles = false; loadQueue.Sort((TileInfo x, TileInfo y) => { return(x.distToCamera.CompareTo(y.distToCamera)); }); } // Ensure local cache max size is not exceeded long maxLocalCacheSize = _tileMaxLocalCacheSize * 1024 * 1024; if (cachedFiles != null && _tileCurrentCacheUsage > maxLocalCacheSize) { for (int f = 0; f < cachedFiles.Length; f++) { if (cachedFiles [f] != null && cachedFiles [f].Exists) { if (_tilePreloadTiles && cachedFiles [f].Name.StartsWith(PREFIX_MIN_ZOOM_LEVEL)) { continue; } _tileCurrentCacheUsage -= cachedFiles [f].Length; cachedFiles [f].Delete(); } if (_tileCurrentCacheUsage <= maxLocalCacheSize) { break; } } } } CheckTilesContent(_currentZoomLevel); }