Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3    pos      = PlayerController.instance.transform.position;
        Vector3Int curBlock = PlayerController.GetCurrentBlock();

        int chunkX   = Mathf.FloorToInt(curBlock.x / 16f);
        int chunkY   = Mathf.FloorToInt(curBlock.y / 16f);
        int chunkZ   = Mathf.FloorToInt(curBlock.z / 16f);
        int xInChunk = curBlock.x - chunkX * 16;
        int yInChunk = curBlock.y - chunkY * 16;
        int zInChunk = curBlock.z - chunkZ * 16;

        Vector3Int posInt = pos.ToVector3Int();

        NBTHelper.GetLightsByte(posInt.x, posInt.y, posInt.z, out byte skyLight, out byte blockLight);
        byte maxLight = skyLight > blockLight ? skyLight : blockLight;

        UnityEngine.Profiling.Profiler.BeginSample("zstring");
        using (zstring.Block())
        {
            zstring text = zstring.Format(template, Application.version, GetFPS(), pos.x, pos.y, pos.z, curBlock.x, curBlock.y, curBlock.z);
            text += zstring.Format(template2, xInChunk, yInChunk, zInChunk, chunkX, chunkY, chunkZ, maxLight, skyLight, blockLight);
            if (WireFrameHelper.render)
            {
                text += zstring.Format(template3, WireFrameHelper.pos.x, WireFrameHelper.pos.y, WireFrameHelper.pos.z, WireFrameHelper.generator.name, WireFrameHelper.data);
            }
            label.text = text;

            label2.text = ChunkRefresher.GetChunkUpdatesCount() + (zstring)" chunk updates";
        }
        UnityEngine.Profiling.Profiler.EndSample();
    }
Beispiel #2
0
    static void ChunksEnterLeaveViewRes(object data)
    {
        CSChunksEnterLeaveViewRes rsp = NetworkManager.Deserialize <CSChunksEnterLeaveViewRes>(data);

        //Debug.Log("CSChunksEnterLeaveViewRes," + rsp.EnterViewChunks.Count + "," + rsp.LeaveViewChunks.Count);
        if (rsp.RetCode == 0)
        {
            foreach (CSVector2Int csv in rsp.LeaveViewChunks)
            {
                UnloadChunk(csv.x, csv.y);
            }
            foreach (CSChunk cschunk in rsp.EnterViewChunks)
            {
                LoadChunk(cschunk);
            }
            if (!PlayerController.isInitialized)
            {
                PlayerController.Init();
                LocalNavMeshBuilder.Init();
                ChunkRefresher.ForceRefreshAll();
            }
            ChunkChecker.FinishRefresh();
        }
        else
        {
            FastTips.Show(rsp.RetCode);
        }
    }
Beispiel #3
0
 void Update()
 {
     if (PlayerController.isInitialized)
     {
         ChunkChecker.Update();
         ChunkRefresher.Update();
     }
 }
Beispiel #4
0
 public static void PreloadChunks(List <Vector2Int> enterViewChunks)
 {
     foreach (Vector2Int chunkPos in enterViewChunks)
     {
         NBTChunk chunk = NBTHelper.LoadChunk(chunkPos.x, chunkPos.y);
         ChunkRefresher.Add(chunk);
     }
     ChunkRefresher.ForceRefreshAll();
 }
Beispiel #5
0
    public static void LoadChunk(CSChunk csChunk)
    {
        //Debug.Log("loadChunk,x=" + csChunk.Position.x + ",z=" + csChunk.Position.y);
        Chunk chunk = ChunkPool.GetChunk();

        chunk.SetData(csChunk.Position.x, csChunk.Position.y, csChunk.BlocksInBytes);
        AddToChunkDict(chunk);
        ChunkRefresher.Add(chunk);
    }
Beispiel #6
0
 public static void RemoveChunk(int chunkX, int chunkZ)
 {
     key.Set(chunkX, chunkZ);
     if (chunkDict.ContainsKey(key))
     {
         NBTChunk chunk = chunkDict[key];
         ChunkRefresher.Remove(chunk);
         chunk.ClearData();
         ChunkPool.Recover(chunk);
         chunkDict.Remove(key);
     }
 }
Beispiel #7
0
    public static void UnloadChunk(int x, int z)
    {
        //Debug.Log("UnloadChunk,x=" + x + ",z=" + z);
        Chunk chunk = GetChunk(x, z);

        if (chunk != null)
        {
            ChunkRefresher.Remove(chunk);
            chunk.ClearData();
            RemoveFromChunkDict(chunk);
            ChunkPool.Recover(chunk);
        }
    }
Beispiel #8
0
    void Start()
    {
        ChunkChecker.Init();
        ChunkRefresher.Init();
        ChunkManager.Init();
        ChunkPool.Init();
        OtherPlayerManager.Init();
        ItemSelectPanel.Show();
        ChatPanel.ShowChatPanel();

        List <Vector2Int> preloadChunks = Utilities.GetSurroudingChunks(PlayerController.GetCurrentChunk());

        ChunkManager.ChunksEnterLeaveViewReq(preloadChunks);
    }
Beispiel #9
0
    void Update()
    {
        if (PlayerController.isInitialized)
        {
            ChunkChecker.Update();
            ChunkRefresher.Update();
        }

        Texture2D day = Resources.Load <Texture2D>("GUI/Day");

        Shader.SetGlobalTexture("_DayLightTexture", day);
        Texture2D night = Resources.Load <Texture2D>("GUI/Night");

        Shader.SetGlobalTexture("_NightLightTexture", night);
    }
Beispiel #10
0
 public static void ChunksEnterLeaveViewReq(List <Vector2Int> enterViewChunks, List <Vector2Int> leaveViewChunks = null)
 {
     foreach (Vector2Int chunkPos in enterViewChunks)
     {
         NBTChunk chunk = NBTHelper.LoadChunk(chunkPos.x, chunkPos.y);
         ChunkRefresher.Add(chunk);
     }
     if (leaveViewChunks != null)
     {
         foreach (Vector2Int chunk in leaveViewChunks)
         {
             UnloadChunk(chunk.x, chunk.y);
         }
     }
     ChunkChecker.FinishRefresh();
 }
Beispiel #11
0
    public static void RespawnRefreshChunks()
    {
        var preloadChunks = Utilities.GetSurroudingChunks(PlayerController.GetCurrentChunkPos(), 1);
        var unloadChunks  = chunkDict.Keys.Except(preloadChunks).ToList();

        foreach (Vector2Int chunk in unloadChunks)
        {
            NBTHelper.RemoveChunk(chunk.x, chunk.y);
        }
        foreach (Vector2Int chunkPos in preloadChunks)
        {
            NBTChunk chunk = NBTHelper.LoadChunk(chunkPos.x, chunkPos.y);
            ChunkRefresher.Add(chunk);
        }
        ChunkRefresher.ForceRefreshAll();
    }
Beispiel #12
0
    void Start()
    {
        SettingsPanel.Init();
        ChunkRefresher.Init();
        ChunkPool.Init();
        ItemSelectPanel.Show();
        ChatPanel.ShowChatPanel();
        InventorySystem.Init();
        GameModeManager.Init();

        // load chunk here
        ChunkChecker.Init();

        PlayerController.Init();
        LocalNavMeshBuilder.Init();
        ChunkRefresher.ForceRefreshAll();
    }
Beispiel #13
0
    public async static void ChunksEnterLeaveViewReq(List <Vector2Int> enterViewChunks, List <Vector2Int> leaveViewChunks = null)
    {
        List <NBTChunk> chunks = new List <NBTChunk>();

        foreach (Vector2Int chunkPos in enterViewChunks)
        {
            NBTChunk chunk = await NBTHelper.LoadChunkAsync(chunkPos.x, chunkPos.y);

            chunks.Add(chunk);
        }
        ChunkRefresher.Add(chunks);
        ChunkChecker.FinishRefresh();

        if (leaveViewChunks != null)
        {
            foreach (Vector2Int chunk in leaveViewChunks)
            {
                UnloadChunk(chunk.x, chunk.y);
            }
        }
    }