public static Material CalculateMaterial(Material material, ushort nodeID, ushort segmentID)
 {
     if (ShouldHideCrossing(nodeID, segmentID))
     {
         NetInfo netInfo = segmentID.ToSegment().Info;
         material = MaterialUtils.HideCrossings(material, null, netInfo, lod: false);
     }
     return(material);
 }
Ejemplo n.º 2
0
            public static void MaterialCache()
            {
                Log.Info("BENCHMARK> MaterialCache started ... ");
                materialList = new List <Material>();
                int count = PrefabCollection <NetInfo> .PrefabCount();

                int loadedCount = PrefabCollection <NetInfo> .LoadedCount();

                for (uint i = 0; i < loadedCount; ++i)
                {
                    NetInfo info = PrefabCollection <NetInfo> .GetLoaded(i);

                    if (info?.m_netAI != null && NetInfoExt.GetCanHideCrossings(info))
                    {
                        foreach (var nodeInfo in info.m_nodes)
                        {
                            if (nodeInfo?.m_nodeMaterial == null || nodeInfo.m_directConnect)
                            {
                                continue;
                            }
                            var nodeMaterial = nodeInfo.m_nodeMaterial;

                            // processed and cache material
                            var material2 = MaterialUtils.HideCrossings(nodeMaterial, null, info);

                            // add to cached material list.
                            materialList.Add(nodeMaterial);
                        }
                    }
                } // end for

                int totalCollisions = 0;

                foreach (var material in materialList)
                {
                    totalCollisions += CountCollisions(material);
                }
                float averageCollisions = totalCollisions / (float)materialList.Count;

                Log.Info($"BENCHMARK> totalCollisions={totalCollisions} averageCollisions={averageCollisions}");

                Log.Info($"BENCHMARK> peforming cache speed benchmark:");
                for (int i = 0; i < 1000; ++i)
                {
                    foreach (var material in materialList)
                    {
                        // its possible for some arguments to be null only if the material is cached already.
                        var material2 = MaterialUtils.HideCrossings(material, null, null);
                    }
                }
                Log.Info($"BENCHMARK> Done peforming cache speed benchmark {1000 * materialList.Count} times ");
            }