Example #1
0
 private void updateTerrainDestroy(WorldSector sector)
 {
     if (sector.is_rendered)
     {
         rTerrain.discardSector(sector);
     }
 }
Example #2
0
	public override void Init()
	{
		instance = this;
		clients = new ClientNode[CConstVar.MAX_CLIENTS];
		for(int i = 0; i < CConstVar.MAX_CLIENTS; i++){
			clients[i] = new ClientNode();
		}
		svEntities = new SvEntityState[CConstVar.MAX_GENTITIES];
		for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){
			svEntities[i] = new SvEntityState();
		}
		// gEntities = new SharedEntity[CConstVar.MAX_GENTITIES];
		// for(int i = 0; i < CConstVar.MAX_GENTITIES; i++){
		// 	gEntities[i] = new SharedEntity();
		// }
		worldSectors = new WorldSector[64];
		for(int i = 0; i < 64; i++){
			worldSectors[i] = new WorldSector();
		}

		configString = new string[CConstVar.MAX_CONFIGSTRINGS];
		serverRunning = false;

		challenges = new SvChallenge[CConstVar.MAX_CHALLENGES];
		for(int i = 0; i < CConstVar.MAX_CHALLENGES; i++){
			challenges[i] = new SvChallenge();
		}

		numSnapshotEntities = CConstVar.MAX_CLIENTS * CConstVar.PACKET_BACKUP * CConstVar.MAX_SNAPSHOT_ENTITIES;
		snapshotEntities = new EntityState[numSnapshotEntities];
		inited = true;
	}
Example #3
0
	public void UnLinkEntity(GameEntity gEnt){
		SvEntityState ent = GetSvEntityForGentity(gEnt);
		gEnt.sEnt.r.linked = false;

		WorldSector ws = ent.worldSector;
		if(ws == null){
			return;
		}

		ent.worldSector = null;

		if(ws.entities == ent){
			ws.entities = ent.nextEntityInWorldSector;
			return;
		}

		SvEntityState scan;
		for(scan = ws.entities; scan != null; scan = scan.nextEntityInWorldSector){
			if(scan.nextEntityInWorldSector == ent){
				scan.nextEntityInWorldSector = ent.nextEntityInWorldSector;
				return;
			}
		}
		CLog.Warning("UnlinkEntity: not found in worldSector!");
	}
Example #4
0
 public SectorLevels(int sector_x, int sector_z, WorldSector parent)
 {
     x = sector_x;
     z = sector_z;
     levels = new List<WorldSectorLevel>();
     this.parent = parent;
 }
Example #5
0
 public static WorldChunk GetChunkFromSector(WorldSector sector)
 {
     return World.GetChunk (
         sector.x / GameSettings.LoadedConfig.ChunkLength_Sectors,
         sector.z / GameSettings.LoadedConfig.ChunkLength_Sectors
     );
 }
Example #6
0
    private void UnloadSector(Vector2Int position)
    {
        WorldSector sector = loadedSectors[position];

        Destroy(sector.gameObject);
        loadedSectors.Remove(position);
    }
Example #7
0
 private void updateTerrainCreate(WorldSector sector)
 {
     if (!sector.is_rendered)
     {
         rTerrain.setupSector(sector);
     }
 }
Example #8
0
    /*
     *  Function: discardSector
     *
     *  Parameters: WorldSector:<sector>
     *
     * 	Returns: void
     *
     * 	-Returns <sector>s rendered GameObject to the <terrainObjectPool>.
     *  -Unlinks references between <sector> and the GameObject
     */
    public void discardSector(WorldSector sector)
    {
        terrainObjectPool.push (sector.terrainGameObject);
        sector.unlinkGameObject ();

        //TESTS
        TestUtils.active_r_trns--;
    }
Example #9
0
    /*
     *  Function: discardSector
     *
     *  Parameters: WorldSector:<sector>
     *
     *  Returns: void
     *
     *  -Returns <sector>s rendered GameObject to the <terrainObjectPool>.
     *  -Unlinks references between <sector> and the GameObject
     */
    public void discardSector(WorldSector sector)
    {
        terrainObjectPool.push(sector.terrainGameObject);
        sector.unlinkGameObject();

        //TESTS
        TestUtils.active_r_trns--;
    }
Example #10
0
 /*
  *  Function: moveObjToSector
  *
  *  Parameters: GActor:<obj>, WorldSector:<sector>
  *
  *  Returns: void
  *
  *  -Places the reference for <obj> into <sector>.
  *  -If <obj>s reference is already contained by another sector, it is first removed from the old sector.
  *  -The reference to <obj> is stored in <sector>s <Contained_Objects> property.
  *  -Since only GActors are stored in sectors, <obj> must be of type GActor. All other GObjects are stored in tiles.
  */
 public void moveObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector != null)
     {
         // object belongs to a sector
         removeObjFromSector(obj);
     }
     addObjToSector(obj, sector);
 }
Example #11
0
 void addObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector == null)
     {
         // object does not belong to a sector
         obj.sector = sector;
         sector.Contained_Objects.addObject(obj);
     }
 }
Example #12
0
    public WorldSectorLevel(int sector_x, int level_y, int sector_z, WorldSector parent)
    {
        x = sector_x;
        z = sector_z;
        y = level_y;
        this.parent = parent;

        initCells();
    }
Example #13
0
    /*
     *	END OF RENDER UPDATE OPERATIONS
     */

    public bool sectorIsContained(WorldSector needle, List <WorldSector> haystack)
    {
        for (int i = 0; i < haystack.Count; ++i)
        {
            if (needle == haystack[i])
            {
                return(true);
            }
        }
        return(false);
    }
Example #14
0
    private void setTileUvs(int tile_index, Vector2[] uvs, WorldSector sector, int tile_index_x, int tile_index_y)
    {
        Vector2 abs_indexes = new Vector2(sector.lower_boundary_x + tile_index_x, sector.lower_boundary_y + tile_index_y);
        GTile   tile        = GameData.GData.getTile(abs_indexes);

        Vector2[] uvCoords = texMan.getUvCoords(texMan.getRandomTexture(tile.biome.type));
        //Vector2[] uvCoords = texMan.getUvCoords(UnityEngine.Random.Range(0, texMan.grid_cells_x), UnityEngine.Random.Range (0, texMan.grid_cells_y));
        uvs [4 * tile_index + (int)TileVertices.topLeft]     = new Vector2(uvCoords[0].x, uvCoords[0].y);
        uvs [4 * tile_index + (int)TileVertices.topRight]    = new Vector2(uvCoords[0].x, uvCoords[1].y);
        uvs [4 * tile_index + (int)TileVertices.bottomRight] = new Vector2(uvCoords[1].x, uvCoords[1].y);
        uvs [4 * tile_index + (int)TileVertices.bottomLeft]  = new Vector2(uvCoords[1].x, uvCoords[0].y);
    }
Example #15
0
 /*
  * Attempts to place the GActor instance at <point>. If successful true is returned. False is returned otherwise.
  * If placement is succesful and the new point is part of a different sector, moves the GActor reference to the new sector.
  */
 public override bool placeAtPoint(Vector2 point)
 {
     if (base.placeAtPoint(point))
     {
         WorldSector sec = GameData.GData.getSectorFromWorldPoint(point);
         if (sec != sector)
         {
             GameData.GData.moveObjToSector(this, sec);
         }
         return(true);
     }
     return(false);
 }
Example #16
0
    /*
     *  Function: setupSector
     *
     *  Parameters: WorldSector:<sector>
     *
     * 	Returns: void
     *
     * 	-Obtains a new GameObject from the <terrainObjectPool>, which will be used to render <sector>s terrain.
     *  -Initializes the GameObjects attributes and links references between <sector> and the GameObject
     *  -Sets the GameObjects position.
     */
    public void setupSector(WorldSector sector)
    {
        float sector_width = GameController.DataSettings.sector_size * GameController.DataSettings.tile_width;
        GameObject obj = getNewTerrainObject();
        obj.name = sector.gameObjectName;
        setupObject(obj, sector);
        obj.transform.position = new Vector3 (
            sector.index_x * sector_width + sector_width,
            sector.index_y * sector_width,
            GameRenderer.GRenderer.getZUnitsTerrain()
        );
        sector.linkGameObject (obj);

        //TESTS
        TestUtils.active_r_trns++;
    }
Example #17
0
    /*
     *  Function: setupSector
     *
     *  Parameters: WorldSector:<sector>
     *
     *  Returns: void
     *
     *  -Obtains a new GameObject from the <terrainObjectPool>, which will be used to render <sector>s terrain.
     *  -Initializes the GameObjects attributes and links references between <sector> and the GameObject
     *  -Sets the GameObjects position.
     */
    public void setupSector(WorldSector sector)
    {
        float      sector_width = GameController.DataSettings.sector_size * GameController.DataSettings.tile_width;
        GameObject obj          = getNewTerrainObject();

        obj.name = sector.gameObjectName;
        setupObject(obj, sector);
        obj.transform.position = new Vector3(
            sector.index_x * sector_width + sector_width,
            sector.index_y * sector_width,
            GameRenderer.GRenderer.getZUnitsTerrain()
            );
        sector.linkGameObject(obj);

        //TESTS
        TestUtils.active_r_trns++;
    }
Example #18
0
	public void LinkEntity(GameEntity gEnt){
		int i,j,k;
		SvEntityState ent = GetSvEntityForGentity(gEnt);
		if(ent.worldSector != null){
			UnLinkEntity(gEnt);
		}
		if(gEnt.sEnt.r.bmodel){
			gEnt.sEnt.s.solid = CConstVar.SOLID_BMODEL;
		}else if((gEnt.sEnt.r.contents & (CConstVar.CONTENTS_SOLID | CConstVar.CONTENTS_BODY)) > 0){
			i = (int)gEnt.sEnt.r.maxs[0];
			if(i < 1){
				i = 1;
			}
			if(i > 255){
				i = 255;
			}
		}

		Vector3 origin = gEnt.sEnt.r.currentOrigin;
		Vector3 angles = gEnt.sEnt.r.currentAngles;

		// if(gEnt.sEnt.r.bmodel && (angles[0] > 0f || angles[1] > 0f || angles[2] > 0f)){
		// 	flo
		// }
		ent.numClusters = 0;
		// ent.lastclu
		gEnt.sEnt.r.linkCount++;
		WorldSector node = worldSectors[0];
		while(true){
			if(node.axis == -1){
				break;
			}
			if(gEnt.sEnt.r.absmin[node.axis] > node.dist){
				node = node.children[0];
			}else if(gEnt.sEnt.r.absmax[node.axis] < node.dist){
				node = node.children[1];
			}else
			{
				break;
			}
		}
		ent.worldSector = node;
		ent.nextEntityInWorldSector = node.entities;
		node.entities = ent;
		gEnt.sEnt.r.linked = true;
	}
Example #19
0
    private Mesh generateMesh(int tile_count, float tile_width, WorldSector sector)
    {
        Mesh mesh = new Mesh ();
        mesh.Clear ();
        mesh.name = "TerrainMesh";

        Vector3[] vertices = new Vector3[4 * tile_count];
        int[] triangles = new int[6 * tile_count];
        Vector2[] uvs = new Vector2[4 * tile_count];
        int side_length = (int)Mathf.Sqrt(tile_count);

        for(int i = 0; i < tile_count; ++i) {

            int index_y = i / side_length;
            int index_x = i % side_length;
            float origin_x = index_x * tile_width;
            float origin_y = index_y * tile_width;

            setTileVertices(i,
                new Vector3( origin_x, 				origin_y, 				0),
                new Vector3( origin_x + tile_width, origin_y, 				0),
                new Vector3( origin_x + tile_width, origin_y + tile_width, 	0),
                new Vector3( origin_x, 				origin_y + tile_width, 	0),
                vertices
            );

            setTileTriangles(i, triangles);

            setTileUvs(i, uvs, sector, index_x, index_y);

        }

        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.uv = uvs;

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.Optimize ();

        return mesh;
    }
Example #20
0
    private Mesh generateMesh(int tile_count, float tile_width, WorldSector sector)
    {
        Mesh mesh = new Mesh();

        mesh.Clear();
        mesh.name = "TerrainMesh";

        Vector3[] vertices    = new Vector3[4 * tile_count];
        int[]     triangles   = new int[6 * tile_count];
        Vector2[] uvs         = new Vector2[4 * tile_count];
        int       side_length = (int)Mathf.Sqrt(tile_count);

        for (int i = 0; i < tile_count; ++i)
        {
            int   index_y  = i / side_length;
            int   index_x  = i % side_length;
            float origin_x = index_x * tile_width;
            float origin_y = index_y * tile_width;

            setTileVertices(i,
                            new Vector3(origin_x, origin_y, 0),
                            new Vector3(origin_x + tile_width, origin_y, 0),
                            new Vector3(origin_x + tile_width, origin_y + tile_width, 0),
                            new Vector3(origin_x, origin_y + tile_width, 0),
                            vertices
                            );

            setTileTriangles(i, triangles);

            setTileUvs(i, uvs, sector, index_x, index_y);
        }

        mesh.vertices  = vertices;
        mesh.triangles = triangles;
        mesh.uv        = uvs;

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        mesh.Optimize();

        return(mesh);
    }
Example #21
0
    private void setupDataStructures()
    {
        // init tiles
        worldTiles = new GTile[GameController.DataSettings.world_size, GameController.DataSettings.world_size];
        for (int x = 0; x < GameController.DataSettings.world_size; ++x)
        {
            for (int y = 0; y < GameController.DataSettings.world_size; ++y)
            {
                worldTiles[x, y] = new GTile(x, y);
            }
        }

        // init sectors
        sectorsWithinRange = new List <WorldSector> ();
        if (GameController.DataSettings.world_size % GameController.DataSettings.sector_size != 0)
        {
            Debug.LogError("Invalid sector size: Must be multiple of world size");
        }
        else
        {
            worldSectors = new WorldSector[GameController.DataSettings.world_side_sectors, GameController.DataSettings.world_side_sectors];
            for (int x = 0; x < GameController.DataSettings.world_side_sectors; ++x)
            {
                for (int y = 0; y < GameController.DataSettings.world_side_sectors; ++y)
                {
                    worldSectors[x, y] = new WorldSector(
                        x,
                        y,
                        x * GameController.DataSettings.sector_size,
                        x * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size,
                        y * GameController.DataSettings.sector_size,
                        y * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size
                        );
                }
            }
        }
    }
Example #22
0
    private void LoadSector(Vector2Int position)
    {
        WorldSector sector = Instantiate(sectorPrefab, new Vector3(position.x * 255, 0, position.y * 255), Quaternion.identity, transform)
                             .GetComponent <WorldSector>();

        sector.sectorPosition = position;
        Vector2 localHeightPosition = perlinPosition + position;

        localHeightPosition /= localHeightZoom;
        float newLocalHeight = Mathf.PerlinNoise(localHeightPosition.x, localHeightPosition.y);

        newLocalHeight = newLocalHeight * localHeightRange + localHeightMin;
        if (newLocalHeight < 0)
        {
            newLocalHeight *= yMultiplierUnder0;
        }
        sector.localHeight      = newLocalHeight;
        loadedSectors[position] = sector;

        sector.height = height;
        if (newLocalHeight < 0)
        {
            sector.yAdjust = yAdditionUnder0;
        }

        sector.perlinPosition = perlinPosition + position * 255;
        sector.zoom           = zoom;
        sector.octaves        = octaves;

        float[][] borders = new float[4][] { null, null, null, null };
        Mesh      borderMesh;

        if (loadedSectors.ContainsKey(position + Vector2Int.up))
        {
            borders[0] = new float[256];
            borderMesh = loadedSectors[position + Vector2Int.up].GetComponent <MeshFilter>().sharedMesh;
            for (int i = 0; i < 256; i++)
            {
                borders[0][i] = borderMesh.vertices[65280 + i].y;
            }
        }
        if (loadedSectors.ContainsKey(position + Vector2Int.left))
        {
            borders[1] = new float[256];
            borderMesh = loadedSectors[position + Vector2Int.left].GetComponent <MeshFilter>().sharedMesh;
            for (int i = 0; i < 256; i++)
            {
                borders[1][i] = borderMesh.vertices[256 * i].y;
            }
        }
        if (loadedSectors.ContainsKey(position + Vector2Int.right))
        {
            borders[2] = new float[256];
            borderMesh = loadedSectors[position + Vector2Int.right].GetComponent <MeshFilter>().sharedMesh;
            for (int i = 0; i < 256; i++)
            {
                borders[2][i] = borderMesh.vertices[255 + 256 * i].y;
            }
        }
        if (loadedSectors.ContainsKey(position + Vector2Int.down))
        {
            borders[3] = new float[256];
            borderMesh = loadedSectors[position + Vector2Int.down].GetComponent <MeshFilter>().sharedMesh;
            for (int i = 0; i < 256; i++)
            {
                borders[3][i] = borderMesh.vertices[i].y;
            }
        }

        sector.GenerateSectorMesh(borders);
    }
Example #23
0
 /*
  *  Function: setupObject
  *
  *  Parameters: GameObject:<obj>, WorldSector:<sector>
  *
  * 	Returns: void
  *
  * 	Assigns a material and mesh to <obj> in relation to the data contained in <sector>
  */
 private void setupObject(GameObject obj, WorldSector sector)
 {
     obj.GetComponent<MeshRenderer> ().material = texMan.terrain_material;
     //obj.GetComponent<MeshRenderer> ().material.mainTexture = texMan.terrain_sprite.texture;
     obj.GetComponent<MeshFilter> ().mesh = generateMesh (GameController.DataSettings.sector_size * GameController.DataSettings.sector_size, GameController.DataSettings.tile_width, sector);
 }
Example #24
0
 private void setTileUvs(int tile_index, Vector2[] uvs, WorldSector sector, int tile_index_x, int tile_index_y)
 {
     Vector2 abs_indexes = new Vector2 (sector.lower_boundary_x + tile_index_x, sector.lower_boundary_y + tile_index_y);
     GTile tile = GameData.GData.getTile (abs_indexes);
     Vector2[] uvCoords = texMan.getUvCoords (texMan.getRandomTexture(tile.biome.type));
     //Vector2[] uvCoords = texMan.getUvCoords(UnityEngine.Random.Range(0, texMan.grid_cells_x), UnityEngine.Random.Range (0, texMan.grid_cells_y));
     uvs [4 * tile_index + (int)TileVertices.topLeft] 		= new Vector2 (uvCoords[0].x, uvCoords[0].y);
     uvs [4 * tile_index + (int)TileVertices.topRight] 		= new Vector2 (uvCoords[0].x, uvCoords[1].y);
     uvs [4 * tile_index + (int)TileVertices.bottomRight] 	= new Vector2 (uvCoords[1].x, uvCoords[1].y);
     uvs [4 * tile_index + (int)TileVertices.bottomLeft] 	= new Vector2 (uvCoords[1].x, uvCoords[0].y);
 }
 static void GenerateSector(WorldSector sector)
 {
     for (int i = 0; i < sector.getAllLevels().Count; ++i) {
         GenerateSectorLevel(sector.getAllLevels()[i]);
     }
 }
Example #26
0
 private void updateTerrainTint(WorldSector sector)
 {
 }
Example #27
0
 private void updateTerrainTint(WorldSector sector)
 {
 }
Example #28
0
 private void updateTerrainBrightness(WorldSector sector)
 {
 }
Example #29
0
 /*
  *	END OF RENDER UPDATE OPERATIONS
  */
 public bool sectorIsContained(WorldSector needle, List<WorldSector> haystack)
 {
     for (int i = 0; i < haystack.Count; ++i) {
         if(needle == haystack[i]) {
             return true;
         }
     }
     return false;
 }
Example #30
0
    /*
     * Add operation on all objects in sector to a render update queue
     */
    public void ScheduleUpdateOnSectorObjects(RenderObjectUpdateOperations operation, WorldSector sector)
    {
        for (int x = sector.lower_boundary_x; x < sector.upper_boundary_x; ++x)
        {
            for (int y = sector.lower_boundary_y; y < sector.upper_boundary_y; ++y)
            {
                GTile tile = GameData.GData.getTile(new Vector2(x, y));
                // schedule structures
                for (int i = 0; i < tile.Contained_Objects.structures.all.count(); ++i)
                {
                    ScheduleObjectUpdate(operation, tile.Contained_Objects.structures.all.getObjectAt(i));
                }
                // schedule items
                for (int i = 0; i < tile.Contained_Objects.items.all.count(); ++i)
                {
                    ScheduleObjectUpdate(operation, tile.Contained_Objects.items.all.getObjectAt(i));
                }
            }
        }

        // schedule actors
        for (int i = 0; i < sector.Contained_Objects.actors.all.count(); ++i)
        {
            ScheduleObjectUpdate(operation, sector.Contained_Objects.actors.all.getObjectAt(i));
        }
    }
Example #31
0
 /*
  * Add operation on terrain sector to a render update queue
  */
 public void ScheduleTerrainUpdate(RenderTerrainUpdateOperations operation, WorldSector sector)
 {
     TerrainUpdateQueues.getOperationQueue(operation).Enqueue(sector);
 }
Example #32
0
 /*
  *  Function: moveObjToSector
  *
  *  Parameters: GActor:<obj>, WorldSector:<sector>
  *
  * 	Returns: void
  *
  * 	-Places the reference for <obj> into <sector>.
  *  -If <obj>s reference is already contained by another sector, it is first removed from the old sector.
  *  -The reference to <obj> is stored in <sector>s <Contained_Objects> property.
  *  -Since only GActors are stored in sectors, <obj> must be of type GActor. All other GObjects are stored in tiles.
  */
 public void moveObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector != null) {
         // object belongs to a sector
         removeObjFromSector(obj);
     }
     addObjToSector (obj, sector);
 }
Example #33
0
 private void updateTerrainCreate(WorldSector sector)
 {
     if (!sector.is_rendered) {
         rTerrain.setupSector (sector);
     }
 }
Example #34
0
 /*
  *  Function: setupObject
  *
  *  Parameters: GameObject:<obj>, WorldSector:<sector>
  *
  *  Returns: void
  *
  *  Assigns a material and mesh to <obj> in relation to the data contained in <sector>
  */
 private void setupObject(GameObject obj, WorldSector sector)
 {
     obj.GetComponent <MeshRenderer> ().material = texMan.terrain_material;
     //obj.GetComponent<MeshRenderer> ().material.mainTexture = texMan.terrain_sprite.texture;
     obj.GetComponent <MeshFilter> ().mesh = generateMesh(GameController.DataSettings.sector_size * GameController.DataSettings.sector_size, GameController.DataSettings.tile_width, sector);
 }
Example #35
0
    /*
     * Add operation on all objects in sector to a render update queue
     */
    public void ScheduleUpdateOnSectorObjects(RenderObjectUpdateOperations operation, WorldSector sector)
    {
        for (int x = sector.lower_boundary_x; x < sector.upper_boundary_x; ++x) {
            for (int y = sector.lower_boundary_y; y < sector.upper_boundary_y; ++y) {
                GTile tile = GameData.GData.getTile(new Vector2(x, y));
                // schedule structures
                for(int i = 0; i < tile.Contained_Objects.structures.all.count(); ++i) {
                    ScheduleObjectUpdate(operation, tile.Contained_Objects.structures.all.getObjectAt(i));
                }
                // schedule items
                for(int i = 0; i < tile.Contained_Objects.items.all.count(); ++i) {
                    ScheduleObjectUpdate(operation, tile.Contained_Objects.items.all.getObjectAt(i));
                }
            }
        }

        // schedule actors
        for (int i = 0; i < sector.Contained_Objects.actors.all.count(); ++i) {
            ScheduleObjectUpdate(operation, sector.Contained_Objects.actors.all.getObjectAt(i));
        }
    }
Example #36
0
 private void updateTerrainBrightness(WorldSector sector)
 {
 }
Example #37
0
    private void setupDataStructures()
    {
        // init tiles
        worldTiles = new GTile[GameController.DataSettings.world_size, GameController.DataSettings.world_size];
        for (int x = 0; x < GameController.DataSettings.world_size; ++x) {
            for (int y = 0; y < GameController.DataSettings.world_size; ++y) {
                worldTiles[x, y] = new GTile(x, y);
            }
        }

        // init sectors
        sectorsWithinRange = new List<WorldSector> ();
        if (GameController.DataSettings.world_size % GameController.DataSettings.sector_size != 0) {
            Debug.LogError ("Invalid sector size: Must be multiple of world size");
        }
        else {
            worldSectors = new WorldSector[GameController.DataSettings.world_side_sectors, GameController.DataSettings.world_side_sectors];
            for (int x = 0; x < GameController.DataSettings.world_side_sectors; ++x) {
                for (int y = 0; y < GameController.DataSettings.world_side_sectors; ++y) {
                    worldSectors[x, y] = new WorldSector(
                        x,
                        y,
                        x * GameController.DataSettings.sector_size,
                        x * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size,
                        y * GameController.DataSettings.sector_size,
                        y * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size
                        );
                }
            }
        }
    }
Example #38
0
 /*
  * Add operation on terrain sector to a render update queue
  */
 public void ScheduleTerrainUpdate(RenderTerrainUpdateOperations operation, WorldSector sector)
 {
     TerrainUpdateQueues.getOperationQueue (operation).Enqueue(sector);
 }
Example #39
0
 void addObjToSector(GActor obj, WorldSector sector)
 {
     if (obj.sector == null) {
         // object does not belong to a sector
         obj.sector = sector;
         sector.Contained_Objects.addObject(obj);
     }
 }
Example #40
0
    void initSectors()
    {
        // declare sectors
        sectors = new WorldSector[
            GameSettings.LoadedConfig.ChunkLength_Sectors,
            GameSettings.LoadedConfig.ChunkLength_Sectors
        ];

        // init sectors
        for (int sector_x = 0; sector_x < GameSettings.LoadedConfig.ChunkLength_Sectors; ++sector_x) {
            for (int sector_z = 0; sector_z < GameSettings.LoadedConfig.ChunkLength_Sectors; ++sector_z) {
                sectors[sector_x, sector_z] = new WorldSector(
                    x * GameSettings.LoadedConfig.ChunkLength_Sectors + sector_x,
                    z * GameSettings.LoadedConfig.ChunkLength_Sectors + sector_z,
                    this
                );
            }
        }
    }
Example #41
0
    void serializeSectorData(SerializableSector copyTo, WorldSector copyFrom)
    {
        // save indexes
        copyTo.x = copyFrom.x;
        copyTo.z = copyFrom.z;

        // save sector levels
        List<WorldSectorLevel> levels = copyFrom.levels.getAllLevels();
        for (int i = 0; i < levels.Count; ++i) {
            copyTo.levels.Add(new SerializableLevel());

            serializeLevelData(copyTo.levels[i], levels[i]);
        }
    }
Example #42
0
 private void updateTerrainDestroy(WorldSector sector)
 {
     if (sector.is_rendered) {
         rTerrain.discardSector (sector);
     }
 }