Class GradientMapMode
ENGINE LAYER - Generic gradient-based map mode handler
Architecture:
- Pure mechanism, no game-specific knowledge
- Concrete GAME modes override: GetGradient(), GetValueForProvince()
- Uses GPU compute shader for fast colorization (~1ms vs 125ms CPU)
- Uses MapModeManager's texture array for instant mode switching
Performance:
- GPU compute shader processes 11.5M pixels in ~1ms
- Texture updates only when dirty (data changed)
- Mode switching is instant (just changes shader int)
Usage (GAME Layer): public class FarmDensityMapMode : GradientMapMode { protected override ColorGradient GetGradient() => new ColorGradient(...); protected override float GetValueForProvince(ushort id) => buildingSystem.GetFarmCount(id); }
public abstract class GradientMapMode : IMapModeHandler
- Inheritance
-
objectGradientMapMode
- Implements
- Derived
Properties
IsActive
Check if this map mode is currently the active one
public bool IsActive { get; }
Property Value
- bool
Mode
Map mode type this handler manages
public abstract MapMode Mode { get; }
Property Value
Name
Display name for UI
public abstract string Name { get; }
Property Value
- string
OceanColor
protected virtual Color32 OceanColor { get; }
Property Value
RequiresFrequentUpdates
Whether this mode requires frequent texture updates
public virtual bool RequiresFrequentUpdates { get; }
Property Value
- bool
ShaderModeID
Shader mode ID for the GPU
public abstract int ShaderModeID { get; }
Property Value
- int
UnownedColor
protected virtual Color32 UnownedColor { get; }
Property Value
Methods
DisableAllMapModeKeywords(Material)
Helper method for subclasses to disable all map mode keywords (legacy compatibility)
protected void DisableAllMapModeKeywords(Material mapMaterial)
Parameters
mapMaterialMaterial
Dispose()
Dispose resources
public void Dispose()
EnableMapModeKeyword(Material, string)
Helper method for subclasses to enable a specific keyword (legacy compatibility)
protected void EnableMapModeKeyword(Material mapMaterial, string keyword)
Parameters
mapMaterialMaterialkeywordstring
FormatValue(float)
Format value for display in tooltip Override for custom formatting (e.g., "10.5 gold", "1000 soldiers")
protected virtual string FormatValue(float value)
Parameters
valuefloat
Returns
- string
GetCategoryThreshold(int)
Override to provide custom category thresholds Default assumes 0-100 range
protected virtual float GetCategoryThreshold(int tier)
Parameters
tierint
Returns
- float
GetGradient()
Get the color gradient to use for this map mode
protected abstract ColorGradient GetGradient()
Returns
GetProvinceTooltip(ushort, ProvinceQueries, CountryQueries)
Get tooltip text for a specific province in this map mode
public abstract string GetProvinceTooltip(ushort provinceId, ProvinceQueries provinceQueries, CountryQueries countryQueries)
Parameters
provinceIdushortprovinceQueriesProvinceQueriescountryQueriesCountryQueries
Returns
- string
GetUpdateFrequency()
Get update frequency for this map mode's textures
public abstract UpdateFrequency GetUpdateFrequency()
Returns
GetValueCategory(float)
Get human-readable category name for a value (used in tooltips) Override for custom categorization
protected virtual string GetValueCategory(float value)
Parameters
valuefloat
Returns
- string
GetValueForProvince(ushort, ProvinceQueries, object)
Get the numeric value for a province (will be normalized and mapped to gradient) Return 0 or negative to skip the province
protected abstract float GetValueForProvince(ushort provinceId, ProvinceQueries provinceQueries, object gameProvinceSystem)
Parameters
provinceIdushortprovinceQueriesProvinceQueriesgameProvinceSystemobject
Returns
- float
LogActivation(string)
Helper method for subclasses to log activation
protected void LogActivation(string message)
Parameters
messagestring
LogDeactivation(string)
Helper method for subclasses to log deactivation
protected void LogDeactivation(string message = null)
Parameters
messagestring
MarkDirty()
Mark this map mode as dirty (needs recalculation) Call this when underlying data changes (province ownership, development, etc.) The texture will be updated on the next frame via RequestDeferredUpdate(), but ONLY if this map mode is currently active.
public void MarkDirty()
OnActivate(Material, MapModeDataTextures)
Called when this map mode becomes active Set up shader properties, enable keywords, etc.
public abstract void OnActivate(Material mapMaterial, MapModeDataTextures dataTextures)
Parameters
mapMaterialMaterialdataTexturesMapModeDataTextures
OnDeactivate(Material)
Called when this map mode becomes inactive Clean up, disable keywords, etc.
public abstract void OnDeactivate(Material mapMaterial)
Parameters
mapMaterialMaterial
OnMapModeActivated()
Called when map mode is activated. Subclasses should call base.OnMapModeActivated() if they override OnActivate.
protected void OnMapModeActivated()
RegisterWithMapModeManager(MapModeManager)
Register with MapModeManager to get a texture array slot. Called during initialization.
protected void RegisterWithMapModeManager(MapModeManager manager)
Parameters
managerMapModeManager
SetShaderMode(Material, int)
Helper method for subclasses to set shader mode (legacy compatibility)
protected void SetShaderMode(Material mapMaterial, int modeID)
Parameters
mapMaterialMaterialmodeIDint
UpdateTextures(MapModeDataTextures, ProvinceQueries, CountryQueries, ProvinceMapping, object)
Update the mode-specific data textures from Core simulation data Only called when data has changed or mode requires frequent updates
public virtual void UpdateTextures(MapModeDataTextures dataTextures, ProvinceQueries provinceQueries, CountryQueries countryQueries, ProvinceMapping provinceMapping, object gameProvinceSystem = null)
Parameters
dataTexturesMapModeDataTexturesprovinceQueriesProvinceQueriescountryQueriesCountryQueriesprovinceMappingProvinceMappinggameProvinceSystemobjectOptional game-specific province system - engine passes through without knowing type