private void CreateSector(TilePosition posSector, bool inmediate) { TilePosition sectorOffset = new TilePosition(posSector.x << SECTOR_SIZE_BITS, posSector.y << SECTOR_SIZE_BITS, posSector.z << SECTOR_SIZE_BITS); Sector sector = new Sector(world, posSector, sectorOffset); sectors[posSector.x | (posSector.y << xSectorsBits) | (posSector.z << xySectorsBits)] = sector; if (inmediate == false) pendingSectorsUpdate.Add(sector); else sector.UpdateMesh(); }
private void CreateSector(TilePosition posSector, bool inmediate) { TilePosition sectorOffset = new TilePosition(posSector.x << SECTOR_SIZE_BITS, posSector.y << SECTOR_SIZE_BITS, posSector.z << SECTOR_SIZE_BITS); Sector sector = new Sector(world, posSector, sectorOffset); sectors[posSector.x | (posSector.y << xSectorsBits) | (posSector.z << xySectorsBits)] = sector; if (inmediate == false) { pendingSectorsUpdate.Add(sector); } else { sector.UpdateMesh(); } }
public void Update(float deltaTime) { long start = DateTime.Now.Ticks; long ticksInMillisecond = 10000; currentPlayerPositionForSort = Graphics.Vector3ToTilePosition(world.avatarManager.player.position); if (pendingSectorsUpdateOrderValid == false) { pendingSectorsUpdate.Sort(CompareSectorsByDistanceToPlayer); pendingSectorsUpdateOrderValid = true; } if (pendingSectorsUpdateLightOrderValid == false) { pendingSectorsUpdateLight.Sort(CompareSectorsByDistanceToPlayer); pendingSectorsUpdateLightOrderValid = true; } int updateRounds = 0; //Always update at leat 8 sectors (they could be the 8 sectors nearest to the player) while ((pendingSectorsUpdate.Count > 0 || pendingSectorsUpdateLight.Count > 0) && (DateTime.Now.Ticks - start < ticksInMillisecond * 10 || updateRounds < 8)) { if (pendingSectorsUpdate.Count > 0) { Sector sectorToUpdate = pendingSectorsUpdate[pendingSectorsUpdate.Count - 1]; pendingSectorsUpdate.RemoveAt(pendingSectorsUpdate.Count - 1); sectorToUpdate.UpdateMesh(); sectorToUpdate.insideInvalidateSectorQueue = false; } if (pendingSectorsUpdateLight.Count > 0) { Sector sectorToUpdate = pendingSectorsUpdateLight[pendingSectorsUpdateLight.Count - 1]; pendingSectorsUpdateLight.RemoveAt(pendingSectorsUpdateLight.Count - 1); sectorToUpdate.UpdateAmbientLight(); sectorToUpdate.insideInvalidateLightQueue = false; } updateRounds++; } }