Exemple #1
0
        internal CellData GetCell(MyLodTypeEnum lod, ref Vector3I cellCoord)
        {
            Int64 key = MySession.Static.VoxelMaps.GetCellHashCode(m_voxelMap.VoxelMapId, ref cellCoord, lod);

            CellData cachedCell;

            if (!m_cellsByCoordinate.TryGetValue(key, out cachedCell))
            {
                if (CellAffectsTriangles(m_voxelMap.Storage, lod, ref cellCoord))
                {
                    cachedCell = CellPool.AllocateOrCreate();
                    m_cellsByCoordinate.Add(key, cachedCell);

                    Profiler.Begin("Cell precalc");
                    MyVoxelPrecalc.PrecalcImmediatelly(
                        new MyVoxelPrecalcTaskItem(
                            lod,
                            m_voxelMap,
                            cachedCell,
                            new Vector3I(
                                cellCoord.X * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS,
                                cellCoord.Y * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS,
                                cellCoord.Z * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS)));
                    Profiler.End();
                }
            }

            return(cachedCell);
        }
Exemple #2
0
 public GenerationSystem(World world, CellPool cellPool, GameState initState)
     : base(world)
 {
     _gameState = initState;
     _cellPool  = cellPool;
     _world     = world;
     _world.Subscribe(this);
 }
Exemple #3
0
 internal void Clear()
 {
     foreach (var entry in m_cellsByCoordinate)
     {
         entry.Value.Reset();
         entry.Value.UnloadData();
         CellPool.Deallocate(entry.Value);
     }
     m_cellsByCoordinate.Clear();
 }
Exemple #4
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Debug.LogError("Already assigned an instance, " + (instance == this));
     }
 }
Exemple #5
0
        private void RemoveCell(ref Vector3I cellCoord)
        {
            Int64    key = MySession.Static.VoxelMaps.GetCellHashCode(m_voxelMap.VoxelMapId, ref cellCoord, MyLodTypeEnum.LOD0);
            CellData cell;

            m_cellsByCoordinate.TryGetValue(key, out cell);
            if (cell != null)
            {
                cell.Reset();
                cell.UnloadData();
                m_cellsByCoordinate.Remove(key);
                CellPool.Deallocate(cell);
            }
        }
 public override void Setup(World world, out ISystem <float> systems)
 {
     _imageFactory = new ImageFactory(world);
     _gridFactory  = new GridFactory(
         world,
         _game.GraphicsDevice,
         PlayerPrefs.Get <int>("Width"),
         PlayerPrefs.Get <int>("Height"),
         PlayerPrefs.Get <int>("CellSize")
         );
     _cellPool = new CellPool(new CellFactory(world, PlayerPrefs.Get <int>("CellSize")));
     InitLayers(world);
     InitializeSystems(world, out systems);
     SetupWorld(world);
     world.Subscribe(this);
 }
Exemple #7
0
        internal CellData GetCellLater(MyLodTypeEnum lod, ref Vector3I cellCoord)
        {
            Int64    key = MySession.Static.VoxelMaps.GetCellHashCode(m_voxelMap.VoxelMapId, ref cellCoord, lod);
            CellData cachedCell;

            if (!m_cellsByCoordinate.TryGetValue(key, out cachedCell))
            {
                if (CellAffectsTriangles(m_voxelMap.Storage, lod, ref cellCoord))
                {
                    cachedCell = CellPool.AllocateOrCreate();
                    m_cellsByCoordinate.Add(key, cachedCell);

                    MyVoxelPrecalc.AddToQueue(MyLodTypeEnum.LOD0, m_voxelMap, cachedCell,
                                              cellCoord.X * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS,
                                              cellCoord.Y * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS,
                                              cellCoord.Z * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_VOXELS);
                }
            }

            return(cachedCell);
        }
Exemple #8
0
    // The parent needs to be specified in advance for the CellPool
    public CellLayout InstantiateCellLayout(GameObject cellLayoutPrefab, int requiredPoolSize = 24)
    {
        // Get or create cell pool
        CellPool cellPool = null;

        CellLayoutPrefabsToCellPools.TryGetValue(cellLayoutPrefab, out cellPool);

        if (!cellPool)
        {
            // InstantiateCellPool()
            cellPool = ResourceCache.Inst.Create("CellPool").GetComponent <CellPool>();
            cellPool.gameObject.SetActive(true);
            cellPool.gameObject.name = cellPool.GetType().Name + "[" + cellLayoutPrefab.name + "](Clone)";
            cellPool.InitializePool();
            cellPool.ScrollRecycler = this;
            cellPool.transform.SetParent(ScrollRect.content.parent, false); // Sibling of ScrollRecycfler
            CellLayoutPrefabsToCellPools[cellLayoutPrefab] = cellPool;
        }
        cellPool.SetRequiredPoolSize(requiredPoolSize);

        // Initialize recycler layout
        GameObject  cellLayoutGO = UnityEngine.Object.Instantiate(cellLayoutPrefab);
        ICellLayout iCellLayout  = cellLayoutGO.GetComponent <ICellLayout>();

        ICellLayouts.Add(iCellLayout);

        cellLayoutGO.transform.SetParent(ScrollRect.content, false);
        iCellLayout.CellLayout.CellPool       = cellPool;
        iCellLayout.CellLayout.ScrollRecycler = this;
        if (iCellLayout.CellLayout.CellPool.CellPrefab == null)
        {
            iCellLayout.CellLayout.CellPool.CellPrefab = iCellLayout.CellLayout.CellPrefab;
        }
        cellLayoutGO.SetActive(true);

        if (!cellPool.CellProxy)
        {
            // TODO: Evaluate how we want to use this
            // InstantiateCellLayoutProxy()
            //var layoutProxyRoot = new GameObject();
            //{ // Copy the layout elements and rect size of the ScrollRect.content
            //    layoutProxyRoot.transform.SetParent(ScrollRect.content, false);
            //    var layoutProxyRootRtx = layoutProxyRoot.AddComponent<RectTransform>();
            //    layoutProxyRootRtx.CopyFromRectTransform(ScrollRect.content);
            //    layoutProxyRoot.AddComponent<LayoutElement>().ignoreLayout = true; // Ignores topmost layout calculations
            //    LayoutUtil.DuplicateLayoutElements(ScrollRect.content.gameObject, layoutProxyRoot);
            //    layoutProxyRoot.name += "(LayoutProxy)";
            //}

            cellPool.CellProxy = Instantiate(iCellLayout.CellLayout.CellPrefab);
            cellPool.CellProxy.gameObject.SetActive(true);
            cellPool.CellProxy.name = iCellLayout.CellLayout.CellPrefab.name + "(ProxyCell)";
            cellPool.CellProxy.transform.SetParent(cellLayoutGO.transform, false);
            cellPool.CellProxy.transform.localPosition = Vector2.zero;

            var cellProxyCG = cellPool.CellProxy.GetComponent <CanvasGroup>();
            if (!cellProxyCG)
            {
                cellProxyCG = cellPool.CellProxy.AddComponent <CanvasGroup>();
            }
            cellProxyCG.alpha = 0.0f;

            var cellProxyLE = cellPool.CellProxy.GetComponent <LayoutElement>();
            if (!cellProxyLE)
            {
                cellProxyLE = cellPool.CellProxy.AddComponent <LayoutElement>();
            }
        }

        return(iCellLayout.CellLayout);
    }