//TODO: When editing chunk that spawns new chunk build neighbours of new chunk if existing
        public void RebuildAround(Vector3 offset, int radius, Vector3Int clickedIndex, float delta)
        {
            ///define loop ranges
            Vector3Int start;
            Vector3Int end;

            GetNoiseEditData(offset, radius, VectorExtension.ToVector3Int(clickedIndex - offset), out start, out end);

            bool rebuildChunk;

            if (!HasPoints)
            {
                ChunkHandler.RequestNoiseForChunk(this);
            }
            rebuildChunk = EditPointsOnCPU(start, end, clickedIndex + offset, radius, delta);

            //else
            //{
            //    rebuildChunk = true;
            //    ChunkHandler.SetEditedNoiseAtPosition(this, clickedIndex + offset, start,end,delta,radius);
            //}

            if (rebuildChunk)
            {
                //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
                //w.Start();
                StoreChunkState();
                storageLeaf.RemoveMipMapInHirachy();
                RebuildFromNoiseAroundOnGPU(start, end, clickedIndex, radius);
                //RebuildFromNoiseAround(start, end, clickedIndex, radius);
                //w.Stop();
                //Debug.Log("Time for rebuild only: " + w.Elapsed.TotalMilliseconds);
            }
        }
Example #2
0
    // Use this for initialization
    void Awake()
    {
        i          = this;
        numColumns = (int)(maxXYValue / gridWidth);
        numRows    = (int)(maxXYValue / gridHeight);

        allChunks = new WorldChunk[numColumns][];
        chunkRefs = new Dictionary <int, List <WorldChunk> >();

        startingChunkX = (numColumns / 2);
        startingChunkY = (numRows / 2);

        for (int i = 0; i < numColumns; i++)
        {
            allChunks[i] = new WorldChunk[numRows];
        }

        if (waitingAnchor != null)
        {
            MakeChunkForDefaultScene(waitingAnchor);
        }
        else
        {
            Debug.Log("No waiting chunk!");
        }
    }
Example #3
0
 public chunk(ChunkHandler _owner, int[] _coord)
 {
     coord = _coord;
     owner = _owner;
     ts    = new HashSet <Transform>();
     loadNeighbors();
 }
Example #4
0
    void Start()
    {
        chunkHandler = new ChunkHandler(chunkedObjectsParent);
        players      = new List <PlayerController>();
        setGravity(gravityStrength);
        fillControllerPlayerArray();
        checkControllers();
        var toAdd = 1;//PlayerPrefs.GetInt ("actualActive", 1);

        //cams = new GameObject[toAdd];
        for (int i = 0; i < toAdd; i++)
        {
            addPlayer(-1);
        }
        //currentUI = Instantiate(UIs[toAdd - 1]);
        initTracks();
        List <int[]> toLoad = new List <int[]>();

        foreach (PlayerController p in players)
        {
            toLoad.Add(getCoordsFromString(p.currentlyOn));
        }
        chunkHandler.unloadAll();
        chunkHandler.load(new int[2] {
            0, 1
        });
        //chunkHandler.load(new int[2] { 0, 2 });
    }
Example #5
0
 public LSequence(Game _assets, BinaryReader _reader)
 {
     Name              = _assets.GetString(_reader.ReadInt32());
     PlaybackType      = _reader.ReadInt32();
     PlaybackSpeed     = _reader.ReadSingle();
     PlaybackSpeedType = _reader.ReadInt32();
     Length            = _reader.ReadSingle();
     XOrigin           = _reader.ReadInt32();
     YOrigin           = _reader.ReadInt32();
     Volume            = _reader.ReadSingle();
     ChunkHandler.HandleZeus(_assets, _reader, delegate {
         LTrack _track = new LTrack(_assets, _reader);
         Tracks.Add(_track);
     });
     ChunkHandler.HandleZeus(_assets, _reader, delegate {
         LSeqEvent _evt = new LSeqEvent(_assets, _reader);
         Events.Add(_evt.Key, _evt);
     });
     ChunkHandler.HandleZeus(_assets, _reader, delegate {
         _reader.ReadSingle();
         _reader.ReadSingle();
         _reader.ReadInt32();
         _reader.ReadInt32();
         _reader.ReadInt32();
     });
 }
Example #6
0
        public LObject(Game _assets, BinaryReader _reader)
        {
            this.Name = _assets.GetString(_reader.ReadInt32());
            Int32 _spriteIndex = _reader.ReadInt32();

            if (_spriteIndex != -1)
            {
                this.Sprite = _assets.SpriteMapping[_spriteIndex];
            }
            else
            {
                this.Sprite = null;
            }
            this.Visible    = _reader.ReadLBoolean();// (_reader.ReadInt32() == 1 ? true : false);
            this.Solid      = _reader.ReadLBoolean();
            this.Depth      = _reader.ReadInt32();
            this.Persistent = _reader.ReadLBoolean();
            Int32 _parentIndex = _reader.ReadInt32();

            if (_parentIndex != -100)
            {
                this.Parent = _assets.ObjectMapping[_parentIndex];
            }
            else
            {
                this.Parent = null;
            }
            Int32 _maskIndex = _reader.ReadInt32();

            if (_maskIndex != -1)
            {
                this.Mask = _assets.SpriteMapping[_maskIndex];
            }
            else
            {
                this.Mask = this.Sprite;
            }
            this.PhysObject         = _reader.ReadLBoolean();
            this.PhysSensor         = _reader.ReadLBoolean();
            this.PhysShape          = _reader.ReadInt32();
            this.PhysDensity        = _reader.ReadSingle();
            this.PhysResitution     = _reader.ReadSingle();
            this.PhysGroup          = _reader.ReadInt32();
            this.PhysLinearDamping  = _reader.ReadSingle();
            this.PhysAngularDamping = _reader.ReadSingle();
            this.PhysVertCount      = _reader.ReadInt32();
            this.PhysFriction       = _reader.ReadSingle();
            this.PhysAwake          = _reader.ReadLBoolean();
            this.PhysKinematic      = _reader.ReadLBoolean();
            _reader.BaseStream.Seek(sizeof(Single) * this.PhysVertCount, SeekOrigin.Current);
            ChunkHandler.HandleKVP(_assets, _reader, delegate(Int32 _eventOffset) {
                ChunkHandler.HandleKVP(_assets, _reader, delegate(Int32 _typeOffset) {
                    Int32 _eventSubtype = _reader.ReadInt32();
                    ChunkHandler.HandleKVP(_assets, _reader, delegate(Int32 _actionOffset) {
                        this.Events.Add(new LEvent(this, _assets, _reader, this, _eventSubtype));
                    });
                });
            });
        }
Example #7
0
        public virtual Shape GetShape(int x, int y, int z)
        {
            if (InRange(x, y, z, 0, CHUNKSIZE - 1))
            {
                return(GetShapeUnsafe(x + 1, y + 1, z + 1));
            }

            return(ChunkHandler.GetShape(_chunkPos, x, y, z));
        }
Example #8
0
    void Update()
    {
        if (handler == null)
        {
            handler = GetComponent <Handler>().handler;
        }

        chunk = GetComponent <Entity>().currrentChunk;
    }
Example #9
0
    void CreateChunk(float positionX, float positionZ)
    {
        GameObject instance;

        instance = Instantiate(chunk, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
        instance.transform.SetParent(this.transform);
        ChunkHandler ch = instance.GetComponent <ChunkHandler>();

        ch.InitChunk(positionX, positionZ, sizeChunk, nbSquare);
    }
    public virtual void OnCollide()
    {
        Camera.main.GetComponent <CameraShake>().enabled       = true;
        Camera.main.GetComponent <CameraShake>().shakeDuration = 2.5f;
        ChunkHandler theHandler = GameObject.FindGameObjectWithTag("ChunkHandler").GetComponent <ChunkHandler>();

        theHandler.SpeedIncreaseFactor = 0;
        GameObject.FindGameObjectWithTag("Car").GetComponent <CarMovement>().Die();
        Time.timeScale = 0.1f;
    }
Example #11
0
        protected override void Build(IHttpStreamable httpStream, bool prepare)
        {
            fileSize = 0;
            bool lastEntryWasFile = false;

            foreach (AttributeKeyValuePair kvp in kvpContainer.Kvps)
            {
                string key = Encoding.UTF8.GetString(Encoding.Default.GetBytes(kvp.Key));
                lastEntryWasFile = true;

                httpStream.WriteLine("--" + Boundary);

                if (kvp.Value is null)
                {
                    WriteOctetStreamPart(httpStream, key);
                    continue;
                }
                if (kvp.Value is byte[])
                {
                    WriteOctetStreamPart(httpStream, prepare, key, (byte[])kvp.Value);
                    fileSize += ((byte[])kvp.Value).Length;
                    continue;
                }
                if (kvp.Value is FileLink)
                {
                    if (Chunked)
                    {
                        if (ChunkHandler is null)
                        {
                            ChunkHandler = new ChunkHandler((FileLink)kvp.Value);
                        }
                        ChunkHandler.PrepareTransfer();
                        fileSize += ChunkHandler.ChunkSize;
                    }
                    else
                    {
                        fileSize += ((FileInfo)((FileLink)kvp.Value).GetInfo()).Length;
                    }
                    WriteFilePart(httpStream, prepare, key, (FileLink)kvp.Value);
                    continue;
                }
                string value = kvp.Value is string?(string)kvp.Value : kvp.Value.ToString();
                value = Encoding.UTF8.GetString(Encoding.Default.GetBytes(value));

                lastEntryWasFile = false;

                WriteStringPart(httpStream, key, value);
            }
            if (lastEntryWasFile)
            {
                httpStream.WriteLine();
                httpStream.FlushUnderlying();
            }
            httpStream.WriteLine("--" + Boundary + "--");
        }
Example #12
0
 public virtual Block GetBlock(int x, int y, int z)
 {
     if (InRange(x, y, z, 0, CHUNKSIZE - 1))
     {
         return(GetBlockUnsafe(x + 1, y + 1, z + 1));
     }
     else
     {
         return(ChunkHandler.GetBlock(_chunkPos, x, y, z));
     }
 }
 void Start()
 {
     Handler = new ChunkHandler(chunkSize);
     Handler.AutoDestroyRight = true;
     Handler.AutoDestroyLeft  = true;
     trackObject          = Camera.main.transform;
     cloudSep             = gameObject.AddComponent <CloudSeperator>();
     cloudSep.handler     = handler;
     cloudSep.trackObject = trackObject;
     cloudSep.minDistance = minDistance;
 }
Example #14
0
        void UpdatePlayerChunkPos()
        {
            Vector3 cPos = Chunk.GetChunkPos(transform.position);

            cPos.y = 0;

            if (cPos != lastPos)
            {
                ChunkHandler.UpdatePlayerPosition(cPos);
                lastPos = cPos;
            }
        }
Example #15
0
        static void ReadCompletedWork(CompletedThreadedWork ctw)
        {
            switch (ctw.Identifier)
            {
            case 2:
            {
                ChunkHandler.ReadCompletedThreadedChunkWork(ctw as CompletedThreadedChunkWork);
                break;
            }
            }

            ctw.Dispose();
        }
 void Start()
 {
     handler                  = new ChunkHandler(chunkSize);
     trackObject              = Camera.main.transform;
     maxTime                  = Random.Range(1f, 2f);
     handler.AutoDestroyLeft  = true;
     handler.AutoDestroyDown  = true;
     handler.AutoDestroyRight = true;
     handler.AutoDestroyUp    = true;
     cloudSep                 = gameObject.AddComponent <CloudSeperator>();
     cloudSep.handler         = handler;
     cloudSep.trackObject     = trackObject;
     cloudSep.minDistance     = 3;
 }
Example #17
0
    void Awake()
    {
        if (chunkHandler != null)
        {
            GameObject.Destroy(chunkHandler);
        }
        else
        {
            chunkHandler = this;
        }

        DontDestroyOnLoad(this);

        ChunkReader chunkReader = new ChunkReader(chunkTextFile);
    }
	void Awake()
	{
		if (chunkHandler != null)
		{
			GameObject.Destroy(chunkHandler);
		}
		else
		{
			chunkHandler = this;
		}
		
		DontDestroyOnLoad(this);

		ChunkReader chunkReader = new ChunkReader(chunkTextFile);

	}
Example #19
0
    public void TestChunkGeneration(Vector3 cPos)
    {
        ThreadedChunkGeneration tcg = new ThreadedChunkGeneration(cPos);

        System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

        watch.Start();
        CompletedChunkGenerationWork ccgw = tcg.Work() as CompletedChunkGenerationWork;

        watch.Stop();

        Debug.Log("Completed generation of chunk " + cPos.ToString() + " in " + ((double)watch.Elapsed.Ticks / (double)System.TimeSpan.TicksPerMillisecond).ToString() + "ms");


        ChunkHandler.TryAddChunk(ccgw.Chunk);
    }
Example #20
0
        public LRoom(Game _game, BinaryReader _reader)
        {
            this.Name       = _game.GetString(_reader.ReadInt32());
            this.Caption    = _game.GetString(_reader.ReadInt32());
            this.Width      = _reader.ReadInt32();
            this.Height     = _reader.ReadInt32();
            this.Speed      = _reader.ReadInt32();
            this.Persistent = _reader.ReadLBoolean();
            this.Colour     = _reader.ReadInt32();
            this.ShowColour = _reader.ReadLBoolean();
            Int32 _codeIndex = _reader.ReadInt32();

            if (_codeIndex != -1)
            {
                this.CreationCode = _game.CodeMapping[_codeIndex];
            }
            else
            {
                this.CreationCode = null;
            }
            Int32 _flagGet = _reader.ReadInt32() & 0xF;

            this.EnableViews   = ((_flagGet & 1) == 1 ? true : false);
            this.ClearViewport = (((_flagGet >> 1) & 1) == 1 ? true : false);
            this.ClearBuffer   = (((_flagGet >> 2) & 1) == 1 ? true : false);
            _reader.ReadInt32(); // Backgrounds
            int _i = 0;

            ChunkHandler.HandleList(_game, _reader, delegate(Int32 _offset) {
                Views[_i++] = new LRoomView(_game, _reader);
            });
            ChunkHandler.HandleList(_game, _reader, delegate(Int32 _offset) {
                this.Instances.Add(new LRoomInstance(_game, _reader));
            });
            _reader.ReadInt32(); // TILES
            this.PhysWorld       = _reader.ReadLBoolean();
            this.PhysWorldTop    = _reader.ReadInt32();
            this.PhysWorldLeft   = _reader.ReadInt32();
            this.PhysWorldRight  = _reader.ReadInt32();
            this.PhysWorldBottom = _reader.ReadInt32();
            this.PhysGravityX    = _reader.ReadSingle();
            this.PhysGravityY    = _reader.ReadSingle();
            this.PhysConversion  = _reader.ReadSingle();
            _reader.ReadInt32(); // LAYERS
            _reader.ReadInt32(); // SEQUENCES
            // TODO: Parse remaining data, such as phyiscs and layer data.
        }
Example #21
0
    // Use this for initialization
    void Start()
    {
        ChunkHandler.ViewDistance = 15;

        ThreadHandler.InitThreads(threads);
        Debug.Log($"Initiated {threads} thread{((threads > 1) ? "s" : "")}");
        ThreadHandler.StartThreads();

        ThreadHandler.AllowWorkerThreadsToCollectWork = true;

        BlockCollection.CreateCollection();
        ShapeCollection.CreateCollection();

        ChunkHandler.DrawAllChunksWithinViewDistance();

        //TestEverything();
        //TestSettingAndGettingBlock(2, 2, 2, 1);
    }
Example #22
0
    void Update()
    {
        if (handler == null)
        {
            handler = GetComponent <Handler>().handler;
        }

        if ((transform.position != lastPos || currrentChunk == null))
        {
            if (currrentChunk != null && currrentChunk != handler.getChunk(transform.position))
            {
                currrentChunk.Objects.Remove(gameObject);
                currrentChunk = handler.getChunk(transform.position);
                currrentChunk.Objects.Add(gameObject);
                if (handler.AutoDestroyLeft)
                {
                    handler.destoryChunksDirection("left", GetComponent <Handler>().trackObject.position);
                }

                if (handler.AutoDestroyRight)
                {
                    handler.destoryChunksDirection("right", GetComponent <Handler>().trackObject.position);
                }

                if (handler.AutoDestroyDown)
                {
                    handler.destoryChunksDirection("down", GetComponent <Handler>().trackObject.position);
                }

                if (handler.AutoDestroyUp)
                {
                    handler.destoryChunksDirection("up", GetComponent <Handler>().trackObject.position);
                }
            }
            else
            {
                currrentChunk = handler.getChunk(transform.position);
            }
        }

        lastPos = transform.position;
    }
Example #23
0
        internal void SetShape(int x, int y, int z, int shapeID)
        {
            if (InRange(x, y, z, 0, CHUNKSIZE - 1))
            {
                SetShapeUnsafe(x + 1, y + 1, z + 1, shapeID);

                //Check if at edge of chunk.
                Vector3 bPos, cPos;
                if (OutOfRange(x, y, z, 1, CHUNKSIZE - 2, out bPos, out cPos))
                {
                    Chunk c;
                    ChunkHandler.TryGetChunk(_chunkPos + cPos, out c);
                    c.SetShapeUnsafe((int)bPos.x, (int)bPos.y, (int)bPos.z, shapeID);
                }
            }
            else
            {
                ChunkHandler.SetShape(_chunkPos, x, y, z, shapeID);
            }
        }
Example #24
0
        public virtual void SetBlock(int x, int y, int z, int blockID)
        {
            if (InRange(x, y, z, 0, CHUNKSIZE - 1))
            {
                SetBlockUnsafe(x + 1, y + 1, z + 1, blockID);

                //Check if at edge of chunk.
                Vector3 bPos, cPos;

                if (OutOfRange(x, y, z, 1, CHUNKSIZE - 2, out bPos, out cPos))
                {
                    Chunk c;
                    ChunkHandler.TryGetChunk(_chunkPos + cPos, out c);
                    c.SetBlockUnsafe((int)bPos.x, (int)bPos.y, (int)bPos.z, blockID);
                }
            }
            else
            {
                ChunkHandler.SetBlock(_chunkPos, x, y, z, blockID);
            }
        }
Example #25
0
        public WorldDataHandler GetWorldHandling()
        {
            var ret = new WorldDataHandler();

            ItemGeneratorDictionary = new ItemGeneratorDictionary();
            RegisterItemGenerators(ItemGeneratorDictionary);


            var generator = new WorldGenerator(1337, 2, Engine);
            var provider  = new SerialWorldProvider();

            if (UseFileDataStore)
            {
                var entityHandler = new EntityHandler(this, Engine, _inventoryCache);
                var chunkHandler  = new ChunkHandler(this);
                //var triggerHandler = new TriggerHandler(this);

                chunkHandler.Init();
                entityHandler.Init();

                provider.AddChunkLoader(chunkHandler);
                provider.AddEntityLoader(entityHandler);
                //provider.AddTriggerLoader(triggerHandler);

                ret.WorldSaver = new WorldSaverWrapper(entityHandler, chunkHandler, null);
                _entityHandler = entityHandler;
            }
            else
            {
                ret.WorldSaver = new WorldSaverWrapper();
            }

            provider.AddChunkLoader(generator);
            provider.AddEntityLoader(generator);
            provider.AddTriggerLoader(generator);
            ret.WorldProvider = provider;

            return(ret);
        }
        protected void RebuildFromNoiseAroundOnGPU(Vector3Int start, Vector3Int end, Vector3Int clickedIndex, float radius)
        {
            float marchDistance = Vector3.one.magnitude + radius + 1;
            float marchSquare   = marchDistance * marchDistance;
            int   voxelMinus    = chunkSize - 1;

            Vector3 startVec = new Vector3(
                Mathf.Max(0, start.x - 1),
                Mathf.Max(0, start.y - 1),
                Mathf.Max(0, start.z - 1));

            Vector3 endVec = new Vector3(
                Mathf.Min(voxelMinus, end.x + 1),
                Mathf.Min(voxelMinus, end.y + 1),
                Mathf.Min(voxelMinus, end.z + 1));

            //TODO: Remove to array from native array

            MeshData result = ChunkHandler.DispatchRebuildAround(this, clickedIndex, startVec, endVec, marchSquare);

            FreeAllMeshes();
            InitializeWithMeshData(result);
        }
Example #27
0
        public LSprite(Game _assets, BinaryReader _reader)
        {
            this.Name          = _assets.GetString(_reader.ReadInt32());
            this.Width         = _reader.ReadInt32();
            this.Height        = _reader.ReadInt32();
            this.BoundsLeft    = _reader.ReadInt32();
            this.BoundsRight   = _reader.ReadInt32();
            this.BoundsBottom  = _reader.ReadInt32();
            this.BoundsTop     = _reader.ReadInt32();
            this.Transparent   = _reader.ReadLBoolean();
            this.Smooth        = _reader.ReadLBoolean();
            this.Preload       = _reader.ReadLBoolean();
            this.BoundsType    = _reader.ReadInt32();
            this.CollisionType = (CollisionType)_reader.ReadInt32();
            this.XOrigin       = _reader.ReadInt32();
            this.YOrigin       = _reader.ReadInt32();
            _reader.BaseStream.Seek(sizeof(Int32) * 2, SeekOrigin.Current);
            this.SpriteType    = (SpriteType)_reader.ReadInt32();
            this.PlaybackType  = (PlaybackType)_reader.ReadInt32();
            this.PlaybackSpeed = _reader.ReadSingle();
            _reader.ReadInt32(); // TODO: Read sequence data @ position
            switch (this.SpriteType)
            {
            case SpriteType.Bitmap: {
                this.TextureEntries = new List <LTexturePageEntry>();
                ChunkHandler.HandleKVP(_assets, _reader, delegate(Int32 _offset) {
                        this.TextureEntries.Add(_assets.TextureEntries.Find(tpe => tpe.Base == _offset));
                    });
                break;
            }

            default: {
                throw new Exception(String.Format("Could not read unsupported sprite type: {0}", this.SpriteType));
            }
            }
        }
Example #28
0
        private void WriteFile(IHttpStreamable httpStream, FileLink fileLink)
        {
            if (Chunked)
            {
                ChunkHandler.WriteChunk(httpStream);
                httpStream.FlushUnderlying();

                if (ChunkHandler.IsFinished)
                {
                    ChunkHandler.Dispose();
                }
                return;
            }
            using (FileStream fis = new FileStream(fileLink.Path, FileMode.Open)) {
                int    bytesRead = -1;
                byte[] buffer    = new byte[HttpConfig.ChunkSize];

                while ((bytesRead = fis.Read(buffer)) != -1)
                {
                    httpStream.WriteUnderlying(buffer, 0, bytesRead);
                }
                httpStream.FlushUnderlying();
            }
        }
Example #29
0
 /// <summary>
 /// Adds the request id.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="handler">The handler.</param>
 public void AddRequestId( int id, ChunkHandler handler )
 {
     throw new NotImplementedException ( );
 }
Example #30
0
 public ChunkHandlerWrapper(ChunkHandler handler)
 {
     this.handler = handler;
 }
Example #31
0
 public void ReadChunk(ChunkHandler handler)
 {
     ReadChunk(new ChunkHandlerWrapper(handler));
 }
Example #32
0
 public void ReadAllChunks(ChunkHandler handler)
 {
     ReadAllChunks(new ChunkHandlerWrapper(handler));
 }
    void OnDestroy()
    {
        ChunkHandler theHandler = GameObject.FindGameObjectWithTag("ChunkHandler").GetComponent <ChunkHandler>();

        theHandler.Speed = 0;
    }
Example #34
0
        /// <summary>
        /// Set everything up that has to do with the user
        /// </summary>
        private async void SetUser()
        {
            // Try to get our user
            await AccountManager.LoadCurrentUser();

            // Update music (if we're dead for example)
            PlayMusic();

            // Get health bar and heart
            var healthBar      = FindViewById <ProgressBar>(Resource.Id.barHealth);
            var healthBarHeart = FindViewById <ImageView>(Resource.Id.barHeart);

            // Initial health bar progress
            healthBar.Progress = AccountManager.CurrentUser.HealthPercentage;

            // Update health bar when changing health
            AccountManager.CurrentUser.HealthChange += health =>
                                                       healthBar.Progress = AccountManager.CurrentUser.HealthPercentage;

            // When the player died
            AccountManager.CurrentUser.DeadChange += isAlive =>
            {
                // Update health bar alpha
                healthBar.Alpha = healthBarHeart.Alpha = isAlive ? 1f : 0.5f;

                // Play map or dead music depending on if we died or not
                PlayMusic();
            };

            // Set name on profile
            profileView.FindViewById <TextView>(Resource.Id.textProfileName).Text = AccountManager.Name;

            // Set equipped companion icons
            equippedCubes[0].SetImageBitmap(AssetLoader.GetCompanionBitmap(AccountManager.CurrentUser.EquippedCompanions[0]));
            equippedCubes[1].SetImageBitmap(AssetLoader.GetCompanionBitmap(AccountManager.CurrentUser.EquippedCompanions[1]));
            equippedCubes[2].SetImageBitmap(AssetLoader.GetCompanionBitmap(AccountManager.CurrentUser.EquippedCompanions[2]));

            equippedCubeNames[0].Text = AccountManager.CurrentUser.EquippedCompanions[0].Name;
            equippedCubeNames[1].Text = AccountManager.CurrentUser.EquippedCompanions[1].Name;
            equippedCubeNames[2].Text = AccountManager.CurrentUser.EquippedCompanions[2].Name;

            // Create recyclerView for companions
            companionRecycler = FindViewById <RecyclerView>(Resource.Id.companion_list);
            companionAdapter  = new CompanionViewAdapter(AccountManager.CurrentUser.Companions, this);
            var companionLayoutManager = new LinearLayoutManager(this);

            companionRecycler.SetAdapter(companionAdapter);
            companionRecycler.SetLayoutManager(companionLayoutManager);

            companionAdapter.EquippedCompanionChanged += CompanionChanged;

            /*
             * Load chunk loader
             * (This is needed here since the monsters are based on the user level)
             */
            chunkHandler = new ChunkHandler();

            if (userLocation != null)
            {
                chunkHandler.UpdateCoordinate(userLocation.Latitude, userLocation.Longitude);
            }
        }
Example #35
0
        public override CompletedThreadedWork Work()
        {
            Queue <ChunkToCheck> chunksToCheck = new Queue <ChunkToCheck>();
            Dictionary <Vector3, DiscoveredChunk> DiscoveredChunks = new Dictionary <Vector3, DiscoveredChunk>();

            //Update the player chunk pos since it may have change since this was enqueued.
            pChunkPos = ChunkHandler.PlayerPosition;

            #region CacheStuff

            //Add previously cached chunks to be checked again (Chunks that needed to be generated).
            foreach (Vector3 v3 in cachedChunksToCheck)
            {
                int cost = CalcCost(v3);

                if (cost < viewDist)
                {
                    chunksToCheck.Enqueue(new ChunkToCheck(v3, cost));
                }
            }

            cachedChunksToCheck.Clear();


            #region Clean Cached DiscoveredChunks
            List <Vector3> cachedChunksToRemove = new List <Vector3>();
            //Clean up the cached DiscoveredChunks (Chunks that were drawn the last time we ran this check).
            if (hasMoved)
            {
                int altViewDist = (int)((rawViewDist - 2) * (rawViewDist - 2));
                foreach (DiscoveredChunk dc in cachedChunks.Values)
                {
                    //Check if the cached chunk is within viewdistance, if it isn't remove it.
                    int cost = CalcCost(dc.Position);

                    if (cost > viewDist)
                    {
                        cachedChunksToRemove.Add(dc.Position);
                    }
                    else if (cost > altViewDist) //Grabs the chunks at the edge of the viewdistance so that we can quickly find which chunks to load in when the player has moved.
                    {
                        chunksToCheck.Enqueue(new ChunkToCheck(dc.Position, cost));
                    }
                }

                //Remove the cached chunks that are now out of viewdistance.
                foreach (Vector3 v3 in cachedChunksToRemove)
                {
                    cachedChunks.Remove(v3);
                }
            }
            #endregion
            #endregion

            Chunk c;
            ChunkHandler.TryGetChunk(pChunkPos, out c);

            if (c != null && c.IsGenerated)
            {
                if (chunksToCheck.Count == 0)
                {
                    DiscoveredChunks.Add(pChunkPos, new DiscoveredChunk(pChunkPos, DiscoveredChunk.DiscoveryResult.Draw));

                    if (!c.IsSolid(Direction.East))
                    {
                        chunksToCheck.Enqueue(new ChunkToCheck(pChunkPos + new Vector3(1, 0, 0), 1));
                    }

                    if (!c.IsSolid(Direction.West))
                    {
                        chunksToCheck.Enqueue(new ChunkToCheck(pChunkPos + new Vector3(-1, 0, 0), 1));
                    }

                    if (!c.IsSolid(Direction.North))
                    {
                        chunksToCheck.Enqueue(new ChunkToCheck(pChunkPos + new Vector3(0, 0, 1), 1));
                    }

                    if (!c.IsSolid(Direction.South))
                    {
                        chunksToCheck.Enqueue(new ChunkToCheck(pChunkPos + new Vector3(0, 0, -1), 1));
                    }
                }

                ChunkToCheck current;
                Chunk        currChunk;
                Vector3      vec;
                bool         cachePos;
                //This is really slow, we could probably try and cache the discovered chunks that we should draw though and enqueue them for checking aswell.
                //So that we don't need to check them all over again unless the player has moved.

                while (true)
                {
                    cachePos = false;
                    //Try to fetch from cached chunks to check first.
                    if (chunksToCheck.Count == 0)
                    {
                        break;
                    }

                    current = chunksToCheck.Dequeue();

                    ChunkHandler.TryGetChunk(current.Position, out currChunk);

                    if (currChunk == null)
                    {
                        DiscoveredChunks.Add(current.Position, new DiscoveredChunk(current.Position, DiscoveredChunk.DiscoveryResult.Generate));
                        continue;
                    }

                    if (!DiscoveredChunks.Keys.Contains(current.Position))
                    {
                        DiscoveredChunks.Add(current.Position, new DiscoveredChunk(current.Position, DiscoveredChunk.DiscoveryResult.Draw));
                    }

                    if (current.Cost < viewDist)
                    {
                        vec = current.Position + new Vector3(1, 0, 0);
                        DiscoveredChunk dc;
                        //Try to find x+1
                        if (!currChunk.IsSolid(Direction.East) && !DiscoveredChunks.TryGetValue(vec, out dc) && !cachedChunks.TryGetValue(vec, out dc))
                        {
                            ChunkHandler.TryGetChunk(vec, out c);
                            if (c != null && c.IsGenerated)
                            {
                                chunksToCheck.Enqueue(new ChunkToCheck(vec, CalcCost(vec)));
                            }
                            else
                            {
                                cachePos = true;
                                DiscoveredChunks.Add(vec, new DiscoveredChunk(vec, DiscoveredChunk.DiscoveryResult.Generate));
                            }
                        }

                        vec = current.Position + new Vector3(-1, 0, 0);
                        //Try to find x-1
                        if (!currChunk.IsSolid(Direction.West) && !DiscoveredChunks.TryGetValue(vec, out dc) && !cachedChunks.TryGetValue(vec, out dc))
                        {
                            ChunkHandler.TryGetChunk(vec, out c);
                            if (c != null && c.IsGenerated)
                            {
                                chunksToCheck.Enqueue(new ChunkToCheck(vec, CalcCost(vec)));
                            }
                            else
                            {
                                cachePos = true;
                                DiscoveredChunks.Add(vec, new DiscoveredChunk(vec, DiscoveredChunk.DiscoveryResult.Generate));
                            }
                        }

                        vec = current.Position + new Vector3(0, 0, 1);
                        //Try to find z+1
                        if (!currChunk.IsSolid(Direction.North) && !DiscoveredChunks.TryGetValue(vec, out dc) && !cachedChunks.TryGetValue(vec, out dc))
                        {
                            ChunkHandler.TryGetChunk(vec, out c);
                            if (c != null && c.IsGenerated)
                            {
                                chunksToCheck.Enqueue(new ChunkToCheck(vec, CalcCost(vec)));
                            }
                            else
                            {
                                cachePos = true;
                                DiscoveredChunks.Add(vec, new DiscoveredChunk(vec, DiscoveredChunk.DiscoveryResult.Generate));
                            }
                        }
                        vec = current.Position + new Vector3(0, 0, -1);
                        //Try to find z-1
                        if (!currChunk.IsSolid(Direction.South) && !DiscoveredChunks.TryGetValue(vec, out dc) && !cachedChunks.TryGetValue(vec, out dc))
                        {
                            ChunkHandler.TryGetChunk(vec, out c);
                            if (c != null && c.IsGenerated)
                            {
                                chunksToCheck.Enqueue(new ChunkToCheck(vec, CalcCost(vec)));
                            }
                            else
                            {
                                cachePos = true;
                                DiscoveredChunks.Add(vec, new DiscoveredChunk(vec, DiscoveredChunk.DiscoveryResult.Generate));
                            }
                        }
                    }

                    if (cachePos)
                    {
                        cachedChunksToCheck.Add(current.Position);
                    }
                    //Check if we can reach chunk x+1, if we can check if the cost of it is within viewdist.
                }
            }
            else
            {
                //The chunk at the players position was null.
                DiscoveredChunks.Add(pChunkPos, new DiscoveredChunk(pChunkPos, DiscoveredChunk.DiscoveryResult.Generate));
            }

            #region SortResults
            List <Vector3> chunksToDraw     = new List <Vector3>();
            List <Vector3> chunksToGenerate = new List <Vector3>();


            //ReEnqueue chunks that need to be generated to be checked.
            DiscoveredChunk dcTemp;
            foreach (DiscoveredChunk dc in DiscoveredChunks.Values)
            {
                if (dc.Result == DiscoveredChunk.DiscoveryResult.Generate)
                {
                    chunksToGenerate.Add(dc.Position);
                }
                else if (dc.Result == DiscoveredChunk.DiscoveryResult.Draw)
                {
                    chunksToDraw.Add(dc.Position);
                    if (!cachedChunks.TryGetValue(dc.Position, out dcTemp))
                    {
                        cachedChunks.Add(dc.Position, dc);
                    }
                }
            }

            #endregion
            //Make life easier for the GC.
            DiscoveredChunks.Clear();
            DiscoveredChunks = null;

            //Sort which chunks to generate and which ones to draw.
            //If the number of chunks to generate is greater than one, flag this for being done again.
            return(new CompletedViewDistanceLoaderWork(chunksToDraw.ToArray(), chunksToGenerate.ToArray(), Isvalid));
        }
Example #36
0
 /* Start or continue processing the XML document. */
 private void DoParse()
 {
     if (ParsingSuspended)
     reader.Resume();
       else {
     fileStm = new FileStream(fileBox.Text, FileMode.Open, FileAccess.Read);
     errorHandler.Reset();
     reader.ErrorHandler = errorHandler;
     // turn on namespaces and tell parser to process external entities
     try {
       reader.SetFeature(SaxConsts.NamespacesFeature, true);
       reader.SetFeature(SaxConsts.ExternalGeneralFeature, true);
       reader.SetFeature(SaxConsts.ExternalParameterFeature, true);
     }
     catch (Exception e) {
       MessageBox.Show(e.Message);
     }
     CntHandler handler;
     // create content/lexical handler depending on processing mode
     if (IncrementalMode) {
       int chunkSize = (int)sizeUpDown.Value;
       int activeLevel = (int)levelUpDown.Value;
       handler = new ChunkHandler(reader, treeView, chunkSize, activeLevel);
     }
     else {
       handler = new CntHandler(treeView);
     }
     // set content handler - this is straightforward
     reader.ContentHandler = handler;
     // set lexical handler, if possible
     try {
       reader.LexicalHandler = handler;
     }
     catch (Exception e) {
       errorHandler.AddMessage("Cannot set lexical handler: " + e.Message);
     }
     // set declaration handler, if possible
     try {
       reader.DeclHandler = handler;
     }
     catch (Exception e) {
       errorHandler.AddMessage("Cannot set declaration handler: " + e.Message);
     }
     // finally, process the document
     reader.Parse(new InputSource<Stream>(fileStm));
       }
 }
 void Start()
 {
     handler = new ChunkHandler(chunkSize);
 }
Example #38
0
    void Start ()
    {
        chunkHandler = new ChunkHandler(chunkedObjectsParent);
        players = new List<PlayerController>();
        setGravity(gravityStrength);
        fillControllerPlayerArray();
        checkControllers();
        var toAdd = 1;//PlayerPrefs.GetInt ("actualActive", 1);
		//cams = new GameObject[toAdd];
		for (int i = 0; i < toAdd; i++) {
			addPlayer (-1);
		}
        //currentUI = Instantiate(UIs[toAdd - 1]);
        initTracks();
        List<int[]> toLoad = new List<int[]>();
        foreach(PlayerController p in players)
        {
            toLoad.Add(getCoordsFromString(p.currentlyOn));
        }
        chunkHandler.unloadAll();
        chunkHandler.load(new int[2] { 0, 1 });
        //chunkHandler.load(new int[2] { 0, 2 });
    }
Example #39
0
 /// <summary>
 /// Sends the and consume.
 /// </summary>
 /// <param name="packet">The packet.</param>
 /// <param name="replyHandler">The reply handler.</param>
 public void SendAndConsume( object packet, ChunkHandler replyHandler )
 {
     throw new NotImplementedException ( );
 }
Example #40
0
 public chunk(ChunkHandler _owner,int[] _coord)
 {
     coord = _coord;
     owner = _owner;
     ts = new HashSet<Transform>();
     loadNeighbors();
 }