コード例 #1
0
        private void OpenDimension(int dim)
        {
            string path = Path;

            if (dim == Dimension.DEFAULT)
            {
                path = IO.Path.Combine(path, _REGION_DIR);
            }
            else
            {
                path = IO.Path.Combine(path, "DIM" + dim);
                path = IO.Path.Combine(path, _REGION_DIR);
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            ChunkCache cc = new ChunkCache(_prefCacheSize);

            AnvilRegionManager rm = new AnvilRegionManager(path, cc);
            RegionChunkManager cm = new RegionChunkManager(rm, cc);
            BlockManager       bm = new AnvilBlockManager(cm);

            _regionMgrs[dim] = rm;
            _chunkMgrs[dim]  = cm;
            _blockMgrs[dim]  = bm;

            _caches[dim] = cc;
        }
コード例 #2
0
  public SelectRegion( AnvilRegionManager regs, Form main )
  {
   InitializeComponent( main );

   foreach( IRegion re in regs )
   {
    String insert = "Region ( " + re.X + ", " + re.Z + " )";
    cmbRegion.Items.Add( insert );

   }

   cmbRegion.SelectedIndex = 0;

  }
コード例 #3
0
ファイル: AnvilWorld.cs プロジェクト: tofurama3000/Substrate
        private void OpenDimension (string dim)
        {
            string path = Path;
            if (String.IsNullOrEmpty(dim)) {
                path = IO.Path.Combine(path, _REGION_DIR);
            }
            else {
                path = IO.Path.Combine(path, dim);
                path = IO.Path.Combine(path, _REGION_DIR);
            }

            if (!Directory.Exists(path)) {
                Directory.CreateDirectory(path);
            }

            ChunkCache cc = new ChunkCache(_prefCacheSize);

            AnvilRegionManager rm = new AnvilRegionManager(path, cc);
            RegionChunkManager cm = new RegionChunkManager(rm, cc);
            BlockManager bm = new AnvilBlockManager(cm);

            _regionMgrs[dim] = rm;
            _chunkMgrs[dim] = cm;
            _blockMgrs[dim] = bm;

            _caches[dim] = cc;
        }
コード例 #4
0
    public void LoadLevel()
    {
        int verticalOffset = 85;

        Debug.Log("About to load level folder: " + _fullMapPath + ".");

        Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath);

        Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager();

        BlockSet blockSet = _map.GetBlockSet();

        _map.GetSunLightmap().SetSunHeight(3, 3, 3);

        foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager)
        {
            // Loop through x-axis of chunks in this region
            for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
            {
                // Loop through z-axis of chunks in this region.
                for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
                {
                    // Retrieve the chunk at the current position in our 2D loop...
                    Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ);

                    if (mcChunkRef != null)
                    {
                        if (mcChunkRef.IsTerrainPopulated)
                        {
                            // Ok...now to stick the blocks in...

                            for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                            {
                                for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)
                                {
                                    for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                    {
                                        int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ);

                                        Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY + verticalOffset, iMCChunkInternalZ);

                                        if (iBlockID != 0)
                                        {
                                            switch (iBlockID)
                                            {
                                            case 3:                                             // Dirt to first grass
                                                iBlockID = 1;
                                                break;

                                            case 12:                                             // Grass to grass
                                                iBlockID = 1;
                                                break;

                                            case 13:                                             // Gravel to stone
                                                iBlockID = 4;
                                                break;

                                            case 1:                                             // Stone to second stone
                                                iBlockID = 5;
                                                break;

                                            case 16:                                             // Coal ore to fungus
                                                iBlockID = 17;
                                                break;

                                            case 15:                                             // Iron ore to pumpkin
                                                iBlockID = 20;
                                                break;

                                            case 9:                                             // Water to water
                                                iBlockID = 8;
                                                break;

                                            default:
                                                Debug.Log("Unmapped BlockID: " + iBlockID);
                                                break;
                                            }

                                            Block newBlock = blockSet.GetBlock(iBlockID);

                                            _map.SetBlock(new BlockData(newBlock), blockPos);

                                            Vector3i chunkPos = Chunk.ToChunkPosition(blockPos);

                                            _map.SetDirty(chunkPos);
                                        }
                                    } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                }     // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)
                            }         // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                        }             // End if (mcChunkRef.IsTerrainPopulated)
                    }                 // End if (mcChunkRef != null)
                }                     // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
            }                         // End for (int iMCChunkX  = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
        }                             // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager )

        Debug.Log("Loaded level: " + _fullMapPath + ".");

        _map.AddColliders();

//		List3D<Chunk> chunkList = _map.GetChunks ();
//
//		for (int minX = chunkList.GetMinX(); minX < chunkList.GetMaxX(); minX++)
//		{
//			for (int minY = chunkList.GetMinY(); minY < chunkList.GetMaxY(); minY++)
//			{
//				for (int minZ = chunkList.GetMinZ(); minZ < chunkList.GetMaxZ(); minZ++)
//				{
//					Vector3i chunkPos = new Vector3i(minX, minY, minZ);
//
//					Chunk mapChunk = _map.GetChunk (chunkPos);
//
//					Debug.Log ("LOL [" + minX + ", " + minY + ", " + minZ + "].");
//				}
//			}
//		}
//
//		foreach (Chunk loadedChunk in _map.Get
//		{
//			Vector3i loadedChunkPos = loadedChunk.GetPosition();
//			Debug.Log ("MOG A CHUNK!!! [" + loadedChunkPos.x + ", " + loadedChunkPos.y + ", " + loadedChunkPos.z + "].");
//		}
    }     // End public void LoadLevel()
コード例 #5
0
ファイル: AnvilRegion.cs プロジェクト: pkmnfrk/Substrate
 public AnvilRegion(AnvilRegionManager rm, ChunkCache cache, int rx, int rz)
     : base(rm, cache, rx, rz)
 {
 }
コード例 #6
0
    public void LoadLevel()
    {
        int verticalOffset = 85;

        Debug.Log("About to load level folder: " + _fullMapPath + ".");

        Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath);

        Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager();

        OpenCog.BlockSet.OCBlockSet blockSet = _map.GetBlockSet();

        //_map.GetSunLightmap().SetSunHeight(20, 4, 4);

        int createCount = 0;

        System.Collections.Generic.Dictionary <int, int> unmappedBlockTypes = new System.Collections.Generic.Dictionary <int, int>();

        //Debug.Log("In LoadLevel, there are " + blockSet.BlockCount + " blocks available.");

        foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager)
        {
            // Loop through x-axis of chunks in this region
            for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
            {
                // Loop through z-axis of chunks in this region.
                for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
                {
                    // Retrieve the chunk at the current position in our 2D loop...
                    Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ);

                    if (mcChunkRef != null)
                    {
                        if (mcChunkRef.IsTerrainPopulated)
                        {
                            // Ok...now to stick the blocks in...

                            int iMCChunkY = 0;

                            OCChunk chunk     = null;                //new OCChunk(_map, new Vector3i(iMCChunkX, iMCChunkY, iMCChunkZ));
                            OCChunk lastChunk = null;


                            Vector3i chunkPos     = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), iMCChunkY + verticalOffset, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ));
                            Vector3i lastChunkPos = Vector3i.zero;
                            chunk = _map.GetChunkInstance(chunkPos);

                            for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)
                            {
                                if (iMCChunkInternalY / OCChunk.SIZE_Y > iMCChunkY)
                                {
                                    lastChunk    = chunk;
                                    lastChunkPos = chunkPos;
                                    chunkPos     = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), (iMCChunkInternalY + verticalOffset) / OCChunk.SIZE_Y, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ));
                                    chunk        = _map.GetChunkInstance(chunkPos);
                                }

                                for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                                {
                                    for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                    {
                                        int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ);

                                        if (iBlockID != 0)
                                        {
                                            Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY % OCChunk.SIZE_Y, iMCChunkInternalZ);

                                            int ourBlockID = -1;

//											switch (iBlockID)
//											{
//											case 3: // Dirt to first grass
//												ourBlockID = 1;
//												break;
//											case 12: // Grass to grass
//												ourBlockID = 1;
//												break;
//											case 13: // Gravel to stone
//												ourBlockID = 4;
//												break;
//											case 1: // Stone to second stone
//												ourBlockID = 5;
//												break;
//											case 16: // Coal ore to fungus
//												ourBlockID = 17;
//												break;
//											case 15: // Iron ore to pumpkin
//												ourBlockID = 20;
//												break;
//											case 9: // Water to water
//												ourBlockID = 8;
//												//Debug.Log ("Creating some water at [" + blockPos.x + ", " + blockPos.y + ", " + blockPos.z + "]");
//												break;
////											case 2:
////												iBlockID = 16;
////												break;
////											case 4:
////												iBlockID = 16;
////												break;
////											case 18:
////												iBlockID = 16;
////												break;
//											default:
//											{
//												//Debug.Log ("Unmapped BlockID: " + iBlockID);
//
//												if (!unmappedBlockTypes.ContainsKey (iBlockID))
//												{
//													unmappedBlockTypes.Add (iBlockID, 1);
//												}
//												else
//												{
//													unmappedBlockTypes[iBlockID] += 1;
//												}
//
//												break;
//												}
//											}

                                            if (mcToOCBlockDictionary.ContainsKey(iBlockID))
                                            {
                                                ourBlockID = mcToOCBlockDictionary[iBlockID];
                                            }
                                            else
                                            {
                                                if (!unmappedBlockTypes.ContainsKey(iBlockID))
                                                {
                                                    unmappedBlockTypes.Add(iBlockID, 1);
                                                }
                                                else
                                                {
                                                    unmappedBlockTypes[iBlockID] += 1;
                                                }
                                            }

                                            if (ourBlockID != -1)
                                            {
                                                OCBlock newBlock = blockSet.GetBlock(ourBlockID);

                                                //OCBlockData block = new OpenCog.Map.OCBlockData(newBlock, blockPos);
                                                OCBlockData block = (OCBlockData)OCScriptableObject.CreateInstance <OCBlockData>();
                                                block.Init(newBlock, blockPos);

                                                chunk.SetBlock(block, blockPos);
                                                OpenCog.Map.Lighting.OCLightComputer.RecomputeLightAtPosition(_map, blockPos);

                                                if (block.block.GetName() == "Battery")
                                                {
                                                    GameObject batteryPrefab = OCMap.Instance.BatteryPrefab;
                                                    if (batteryPrefab == null)
                                                    {
                                                        UnityEngine.Debug.Log("OCBuilder::Update, batteryPrefab == null");
                                                    }
                                                    else
                                                    {
                                                        GameObject battery = (GameObject)GameObject.Instantiate(batteryPrefab);
                                                        battery.transform.position = blockPos;
                                                        battery.name             = "Battery";
                                                        battery.transform.parent = OCMap.Instance.BatteriesSceneObject.transform;
                                                    }
                                                }

                                                if (block.block.GetName() == "Hearth")
                                                {
                                                    GameObject hearthPrefab = OCMap.Instance.HearthPrefab;
                                                    if (hearthPrefab == null)
                                                    {
                                                        UnityEngine.Debug.Log("OCBuilder::Update, hearthPrefab == null");
                                                    }
                                                    else
                                                    {
                                                        GameObject hearth = (GameObject)GameObject.Instantiate(hearthPrefab);
                                                        hearth.transform.position = blockPos;
                                                        hearth.name             = "Hearth";
                                                        hearth.transform.parent = OCMap.Instance.HearthsSceneObject.transform;
                                                    }
                                                }

                                                createCount += 1;
                                            }
                                        }
                                    }                     // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                }                         // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)

                                string chunkCoord = chunkPos.x + ", " + chunkPos.z;

                                if (!chunkList.ContainsKey(chunkCoord))
                                {
                                    chunkList.Add(chunkCoord, chunkPos);
                                }

                                if (iMCChunkY < iMCChunkInternalY / OCChunk.SIZE_Y)
                                {
                                    _map.Chunks.AddOrReplace(lastChunk, lastChunkPos);
                                    _map.UpdateChunkLimits(lastChunkPos);
                                    _map.SetDirty(lastChunkPos);
                                    iMCChunkY = iMCChunkInternalY / OCChunk.SIZE_Y;
                                }
                            } // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                        }     // End if (mcChunkRef.IsTerrainPopulated)
                    }         // End if (mcChunkRef != null)
                }             // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
            }                 // End for (int iMCChunkX  = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
        } // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager )

        foreach (Vector3i chunkToLight in chunkList.Values)
        {
            OpenCog.Map.Lighting.OCChunkSunLightComputer.ComputeRays(_map, chunkToLight.x, chunkToLight.z);
            OpenCog.Map.Lighting.OCChunkSunLightComputer.Scatter(_map, null, chunkToLight.x, chunkToLight.z);
        }

        foreach (System.Collections.Generic.KeyValuePair <int, int> unmappedBlockData in unmappedBlockTypes)
        {
            UnityEngine.Debug.Log("Unmapped BlockID '" + unmappedBlockData.Key + "' found " + unmappedBlockData.Value + " times.");
        }

        Debug.Log("Loaded level: " + _fullMapPath + ", created " + createCount + " blocks.");

        _map.AddColliders();
    } // End public void LoadLevel()
コード例 #7
0
ファイル: MystWorld.cs プロジェクト: BangRocket/BlockReplace
        private void OpenMystDimension(int dim)
        {
            string path = Path;
            if (dim == Dimension.DEFAULT) {
                path = IO.Path.Combine(path, _REGION_DIR);
            }
            else {
                path = IO.Path.Combine(path, "DIM_MYST" + dim);
                path = IO.Path.Combine(path, _REGION_DIR);
            }

            if (!Directory.Exists(path)) {
                Directory.CreateDirectory(path);
            }

            ChunkCache cc = new ChunkCache(_prefCacheSize);

            AnvilRegionManager rm = new AnvilRegionManager(path, cc);
            RegionChunkManager cm = new RegionChunkManager(rm, cc);
            BlockManager bm = new AnvilBlockManager(cm);

            _regionMgrs[dim] = rm;
            _chunkMgrs[dim] = cm;
            _blockMgrs[dim] = bm;

            _caches[dim] = cc;
        }
コード例 #8
0
ファイル: AnvilRegion.cs プロジェクト: hach-que/Substrate
 public AnvilRegion(AnvilRegionManager rm, ChunkCache cache, int rx, int rz)
     : base(rm, cache, rx, rz)
 {
 }