Show / Hide Table of Contents

Class PlantCache

This clase provides access to plants by species acording cell size. It allows fast lookup by area and plant species for most cases. Internally it saves plants in cells of diferent sizes: by example 0-5, 5-10 and 0-10. It helps to be able provide fast access for areas of diferent sizes: in case if area match some cell, it can just return data inside of it.

Inheritance
System.Object
PlantCache
Namespace: Eco.Simulation.Plants
Assembly: Eco.Simulation.dll
Syntax
public class PlantCache : Object

Constructors

PlantCache(IEnumerable<Int32>)

Accepts an enumerable of cell sizes that will be saved in the cache. Something like 5,10,20,40 should cover most requests. It will represent the cell sizes in which it saves the data, by example for 5, 10 it will save plants in cells 0-5, 5-10, 0-10.

Declaration
public PlantCache(IEnumerable<int> cellSizes)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Int32> cellSizes

Methods

AddPlant(Plant)

Adds plant to all cells that match it, by example position 4 would match cell 0-5, 0-10 and 0-20. It uses lock instead of thread-safe collection in order to sacrify a little performance but have gain in less memory allocations.

Declaration
public void AddPlant(Plant plant)
Parameters
Type Name Description
Plant plant

CollectPlantsInArea(WorldArea, PoolableListWrapper<Plant>, PlantSpecies)

Entry method to cache. Area may match or not internal cells, it will automaticly make all transformations requiered, the area can be not-wraped.

Declaration
public void CollectPlantsInArea(WorldArea area, PoolableListWrapper<Plant> list, PlantSpecies species = null)
Parameters
Type Name Description
WorldArea area
PoolableListWrapper<Plant> list
PlantSpecies species

EnumerableOfArea(WorldArea, PlantSpecies)

Use this as low-memory allocation option for iterating over plants in area. Internally it will use a lock and pooled list to get plants and release the pooled list in the end of iteration. Can be used with linq methods, like Sum

Declaration
public PlantsInAreaEnumerable EnumerableOfArea(WorldArea area, PlantSpecies plantSpecies)
Parameters
Type Name Description
WorldArea area
PlantSpecies plantSpecies
Returns
Type Description
PlantsInAreaEnumerable

RemovePlant(Plant)

Removes plant from all cells that match it. As AddPlant, it uses lock aproach instead of thread-safe collections.

Declaration
public void RemovePlant(Plant plant)
Parameters
Type Name Description
Plant plant
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾