// * Rename to suggest this is a per-frame update, break out the initialization logic // * APPLICATION BOTTLENECK: focus optimization efforts here! // Since this is for visuals, could call on a fixed interval, e.g. 1/5 second public void InitializeRenderBuffers() { // * For testing var cursorCoords = theCursorCzar.GetScaledCursorCoords(360f, -720f); // Initialize world tree line data var worldTreeLines = new WorldTreeLineData[worldTreeBufferCount]; worldTreeLineDataCBuffer?.Release(); worldTreeLineDataCBuffer = new ComputeBuffer(worldTreeBufferCount, sizeof(float) * 7); // Create creature lines for (int line = 0; line < worldTreeNumCreatureLines; line++) { for (int i = 0; i < worldTreeNumPointsPerLine; i++) { CreateCreatureLine(line, i, cursorCoords, worldTreeLines); } } // Create species lines (on top) for (int line = 0; line < worldTreeNumSpeciesLines; line++) { for (int i = 0; i < worldTreeNumPointsPerLine; i++) { CreateSpeciesLine(line, i, cursorCoords, worldTreeLines); } } worldTreeLineDataCBuffer.SetData(worldTreeLines); }
void CreateCreatureLine(int line, int point, Vector2 cursorCoords, WorldTreeLineData[] worldTreeLines) { int index = (line + worldTreeNumSpeciesLines) * worldTreeNumPointsPerLine + point; SpeciesGenomePool pool = simManager.masterGenomePool.completeSpeciesPoolsList[selectionManager.currentSelection.historySelectedSpeciesID]; if (line >= pool.candidateGenomesList.Count) { return; } WorldTreeLineData data = new WorldTreeLineData(); CandidateAgentData cand = pool.candidateGenomesList[line]; float xCoord = (float)point / (float)worldTreeNumPointsPerLine; int numAgentsDisplayed = Mathf.Max(pool.GetNumberAgentsEvaluated(), 1); // Prevent divide by 0 float yCoord = 1f - (float)line / (float)numAgentsDisplayed; int timeStepStart = Mathf.RoundToInt(timelineStartTimeStep); float xStart = (float)(pool.candidateGenomesList[line].performanceData.timeStepHatched - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart); float xEnd = 1f; if (pool.isExtinct || cand.performanceData.timeStepDied > 1) { xEnd = (float)(cand.performanceData.timeStepDied - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart); } bool inXBounds = xStart <= xCoord && xEnd >= xCoord; Vector3 hue = pool.foundingCandidate.candidateGenome.bodyGenome.appearanceGenome.huePrimary * 1.5f; data.color = GetCreatureLineColor(hue, cand, inXBounds); // new Color(hue.x, hue.y, hue.z);// Color.HSVToRGB(lerp, 1f - lerp, 1f); // Color.Lerp(Color.white, Color.black, lineID * 0.11215f); xCoord = xCoord * displayWidth + marginLeft; // rescaling --> make this more robust yCoord = yCoord * displayHeight + marginBottom; data.worldPos = new Vector3(xCoord, yCoord, 0f); // Mouse hover highlight if ((new Vector2(xCoord, yCoord) - cursorCoords).magnitude < 0.05f) { data.color = Color.white; } if (isTimelineMode) //if (isPopulationMode || isTimelineMode) { { data.worldPos = Vector3.zero; data.color = new Color(0f, 0f, 0f, 0f); } worldTreeLines[index] = data; }
void CreateSpeciesLine(int line, int point, Vector2 cursorCoords, WorldTreeLineData[] worldTreeLines) { int index = line * worldTreeNumPointsPerLine + point; if (line >= simManager.masterGenomePool.completeSpeciesPoolsList.Count) { return; } SpeciesGenomePool pool = simManager.masterGenomePool.completeSpeciesPoolsList[line]; WorldTreeLineData data = new WorldTreeLineData(); if (isAllSpeciesMode) { if (isGraphMode) { int graphDataYearIndexStart = 0; int graphDataYearIndexEnd = 0; if (pool.avgCandidateDataYearList.Count == 0) { return; } float xCoord = (float)(point % worldTreeNumPointsPerLine) / (float)worldTreeNumPointsPerLine; int count = Mathf.Max(0, pool.avgCandidateDataYearList.Count - 1); graphDataYearIndexStart = Mathf.FloorToInt((float)count * xCoord); graphDataYearIndexEnd = Mathf.CeilToInt((float)count * xCoord); float frac = ((float)count * xCoord) % 1f; float valStart = (float)pool.avgCandidateDataYearList[graphDataYearIndexStart].performanceData.totalTicksAlive / uiManagerRef.speciesGraphPanelUI.maxValuesStatArray[0]; float valEnd = (float)pool.avgCandidateDataYearList[graphDataYearIndexEnd].performanceData.totalTicksAlive / uiManagerRef.speciesGraphPanelUI.maxValuesStatArray[0]; //valEnd = Mathf.Clamp(valEnd, 0, pool.avgCandidateDataYearList.Count - 1); float yCoord = Mathf.Lerp(valStart, valEnd, frac); // Mathf.Sin(xCoord / orbitalPeriod * (simManager.simAgeTimeSteps) * animTimeScale) * 0.075f * (float)lineID + 0.5f; float zCoord = 0f; Vector3 hue = pool.foundingCandidate.candidateGenome.bodyGenome.appearanceGenome.huePrimary; float alpha = 1f; int timeStepStart = Mathf.RoundToInt(timelineStartTimeStep); float xStart01 = (float)(pool.timeStepCreated - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart); float xEnd01 = pool.isExtinct ? (float)(pool.timeStepExtinct - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart) : 1f; if (pool.speciesID == selectionManager.currentSelection.historySelectedSpeciesID) { hue = Vector3.one; zCoord = -0.1f; } if (xStart01 > xCoord || xEnd01 < xCoord) { hue = Vector3.zero; alpha = 0f; } xCoord = xCoord * displayWidth + marginLeft; // rescaling --> make this more robust yCoord = yCoord * displayHeight + marginBottom; if ((new Vector2(xCoord, yCoord) - cursorCoords).magnitude < 0.05f) { //data.color = Color.white; hue = Vector3.Lerp(hue, Vector3.one, 0.8f); //alpha = 1f; } data.worldPos = new Vector3(xCoord, yCoord, zCoord); data.color = new Color(hue.x, hue.y, hue.z, alpha);// Color.HSVToRGB(lerp, 1f - lerp, 1f); // Color.Lerp(Color.white, Color.black, lineID * 0.11215f); } else { // LINEAGE: float xCoord = (float)point / (float)worldTreeNumPointsPerLine; float yCoord = 1f - ((float)pool.speciesID / (float)Mathf.Max(simManager.masterGenomePool.completeSpeciesPoolsList.Count - 1, 1)); // Mathf.Sin(xCoord / orbitalPeriod * (simManager.simAgeTimeSteps) * animTimeScale) * 0.075f * (float)lineID + 0.5f; float zCoord = 0f; Vector3 hue = pool.foundingCandidate.candidateGenome.bodyGenome.appearanceGenome.huePrimary; float alpha = 1f; int timeStepStart = Mathf.RoundToInt(timelineStartTimeStep); float xStart01 = (float)(pool.timeStepCreated - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart); float xEnd01 = 1f; if (pool.isExtinct) { xEnd01 = (float)(pool.timeStepExtinct - timeStepStart) / (float)(simManager.simAgeTimeSteps - timeStepStart); } if (xStart01 > xCoord || xEnd01 < xCoord) { hue = Vector3.zero; alpha = 0f; } if (pool.speciesID == selectionManager.currentSelection.historySelectedSpeciesID) { hue = Vector3.one; zCoord = -0.1f; } data.color = new Color(hue.x, hue.y, hue.z, alpha); // Color.HSVToRGB(lerp, 1f - lerp, 1f); // Color.Lerp(Color.white, Color.black, lineID * 0.11215f); xCoord = xCoord * displayWidth + marginLeft; // rescaling --> make this more robust yCoord = yCoord * displayHeight + marginBottom; if ((new Vector2(xCoord, yCoord) - cursorCoords).magnitude < 0.05f) { data.color = Color.white; } data.worldPos = new Vector3(xCoord, yCoord, zCoord); } } if (curPanelMode == HistoryPanelMode.SpeciesPopulation || curPanelMode == HistoryPanelMode.CreatureTimeline) { data.worldPos = Vector3.zero; data.color = new Color(0f, 0f, 0f, 0f); } worldTreeLines[index] = data; }