Skip to content

Commit

Permalink
Fixed some breaking bugs that i must have added while being very tired
Browse files Browse the repository at this point in the history
Render can now react to updates of world
  • Loading branch information
sirati committed Dec 3, 2018
1 parent 744685b commit 4c3a8f6
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 154 deletions.
10 changes: 5 additions & 5 deletions Progression.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgressionUtil", "Progress
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YamlSupport", "YamlSupport\YamlSupport.csproj", "{8B34FFDB-8810-4369-9918-B9EADACBB760}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityTestRenderer", "UnityTestRenderer\UnityTestRenderer.csproj", "{6AC780C0-DDAD-02EE-B04C-C920766FD7B5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC};{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1}") = "UnityTestRenderer", "UnityTestRenderer\Assembly-CSharp.csproj", "{957D0551-F09D-A940-ED89-7167706A19F2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -144,10 +144,10 @@ Global
{8B34FFDB-8810-4369-9918-B9EADACBB760}.Release|x64.Build.0 = Release|Any CPU
{8B34FFDB-8810-4369-9918-B9EADACBB760}.Release|x86.ActiveCfg = Release|Any CPU
{8B34FFDB-8810-4369-9918-B9EADACBB760}.Release|x86.Build.0 = Release|Any CPU
{6AC780C0-DDAD-02EE-B04C-C920766FD7B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AC780C0-DDAD-02EE-B04C-C920766FD7B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AC780C0-DDAD-02EE-B04C-C920766FD7B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AC780C0-DDAD-02EE-B04C-C920766FD7B5}.Release|Any CPU.Build.0 = Release|Any CPU
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 12 additions & 10 deletions ProgressionCore/World/Features/Simple/ISimpleFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ public interface ISimpleFeature<T> : IFeature<T>, ISimpleFeature where T : class
new StaticFeatureResolver<T> Resolver { get; }
}

public interface ISimpleFeature
public interface ISimpleFeature : IFeature

{
/// <summary>
/// Id can start with 1 - this is because 0 may represent absense of feature
/// </summary>
int Id { get; }
/// <summary>
/// Id can start with 1 - this is because 0 may represent absense of feature
/// </summary>
int Id { get; }
int DataRepresentation { get; set; }

bool HasFeature(Tile tile);
void AddFeature(Tile tile);
void RemoveFeature(Tile tile);
bool HasFeature(Tile tile);
void AddFeature(Tile tile, bool sync = false);
void RemoveFeature(Tile tile, bool sync = false);

DataIdentifier DataIdentifier { get; set; }
//StaticFeatureResolver<T> Resolver { get; }
DataIdentifier DataIdentifier { get; set; }
//StaticFeatureResolver<T> Resolver { get; }
}
}
24 changes: 17 additions & 7 deletions ProgressionCore/World/Features/Simple/SimpleFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Progression.Engine.Core.World.Features.Simple
public class SimpleFeature<T> : ISimpleFeature<T> where T : SimpleFeature<T>
{
private DataIdentifier _dataIdentifier;
private int _dataRepresentation;

public SimpleFeature(string name, StaticFeatureResolver<T> resolver)
{
Expand All @@ -17,7 +18,6 @@ public SimpleFeature(string name, StaticFeatureResolver<T> resolver)
}

public int Id { get; }
internal int Value=0;

public DataIdentifier DataIdentifier {
get => _dataIdentifier;
Expand All @@ -27,6 +27,15 @@ public DataIdentifier DataIdentifier {
_dataIdentifier = value;
}
}

public int DataRepresentation {
get => _dataRepresentation;
set {
if (Resolver.IsFrozen)
throw new FeatureResolverLockedException("DataOffset has only to be changed by FeatureManager");
_dataRepresentation = value;
}
}

public string Name => Key.Name;
public Key Key { get; }
Expand All @@ -35,21 +44,22 @@ public DataIdentifier DataIdentifier {

public bool HasFeature(Tile tile)
{
return tile[DataIdentifier] == Value;
return tile[DataIdentifier] == _dataRepresentation;
}

public void AddFeature(Tile tile)
public void AddFeature(Tile tile, bool sync=false)
{
if (!Resolver.ValidateData(tile, (T) this, true)) throw new InvalidOperationException();
tile[DataIdentifier] = Value;
tile.InvokeTileUpdate((T) this, true);
Console.WriteLine($"{Name} value={_dataRepresentation}");
tile[DataIdentifier] = _dataRepresentation;
if (!sync)tile.InvokeTileUpdate((T) this, true);
}

public void RemoveFeature(Tile tile)
public void RemoveFeature(Tile tile, bool sync=false)
{
if (!Resolver.ValidateData(tile, (T) this, true)) throw new InvalidOperationException();
tile[DataIdentifier] = 0;
tile.InvokeTileUpdate((T) this, false);
if (!sync)tile.InvokeTileUpdate((T) this, false);
}

IFeatureResolver IFeature.Resolver => Resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override DataIdentifier[] GenerateIdentifiers()
if (DataIdentifier != null || IsFrozen) {
throw new InvalidOperationException("GenerateIdentifiers should only be called by FeatureWorld");
}
DataIdentifier = new DataIdentifier(this, 0, (int)Math.Ceiling(Math.Log((int)Math.Ceiling(Math.Log(Count+IdOffset, 2)), 2)), WorldType);
DataIdentifier = new DataIdentifier(this, 0, (int)Math.Ceiling(Math.Log(Count+IdOffset, 2)), WorldType);
foreach (var feature in Features) {
feature.DataIdentifier = DataIdentifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public int Register(T feature)
feature.Key.Flavour = FeatureKeyFlavour;

var id = Features.Count - 1 + IdOffset; //id may not match index
//feature.Value = GetSettingValue(id);
feature.DataRepresentation = GetSettingValue(id);
return id;
}

Expand Down
4 changes: 2 additions & 2 deletions ProgressionCore/World/Threading/WorldInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public virtual Tile GenericFeatureUpdate<TSimpleFeature>(Coordinate coordinate,
#endif
var tile = World[coordinate];
if (set) {
feature.AddFeature(tile);
feature.AddFeature(tile, true);
} else {

feature.AddFeature(tile);
feature.AddFeature(tile, true);
}

return tile;
Expand Down
112 changes: 57 additions & 55 deletions TestLauncher/GameEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,47 @@ namespace TestLauncher
{
public class GameEnv
{
private RootKey _keysRoot;
private YieldType _yieldFood;
private YieldType _yieldProduction;
private YieldType _yieldCommerce;
private YieldModifyingSSFR<TerrainBiome> _wfeatureBiome;
private YieldModifyingSMFR<TerrainVegetation> _wfeatureVegetation;
private YieldModifyingSSFR<TerrainLandform> _wfeatureLandform;
private TerrainBiome _wfeatureGlassland;
private TerrainBiome _wfeaturePlains;
private TerrainBiome _wfeatureDesert;
private TerrainBiome _wfeatureTundra;
private TerrainBiome _wfeatureIce;
private TerrainVegetation _wfeatureJungle;
private TerrainVegetation _wfeatureForest;
private TerrainVegetation _wfeaturePineForest;
private TerrainLandform _wfeatureFlatland;
private TerrainLandform _wfeatureHills;
private TerrainLandform _wfeatureMountains;
private TerrainLandform _wfeatureHighMountains;
private CivilizationManager _civilizationManager;
private Civilization _civilizationRome;
private Civilization _civilizationEgypt;
private YieldManager _yieldManager;

public CivilizationManager CivilisationManager => _civilizationManager;
public RootKey KeysRoot;
public YieldType YieldFood;
public YieldType YieldProduction;
public YieldType YieldCommerce;
public YieldModifyingSSFR<TerrainBiome> WFeatureBiome;
public YieldModifyingSMFR<TerrainVegetation> WFeatureVegetation;
public YieldModifyingSSFR<TerrainLandform> WFeatureLandform;
public TerrainBiome WFeatureGlassland;
public TerrainBiome WFeaturePlains;
public TerrainBiome WFeatureDesert;
public TerrainBiome WFeatureTundra;
public TerrainBiome WFeatureIce;
public TerrainVegetation WFeatureJungle;
public TerrainVegetation WFeatureForest;
public TerrainVegetation WFeaturePineForest;
public TerrainLandform WFeatureFlatland;
public TerrainLandform WFeatureHills;
public TerrainLandform WFeatureMountains;
public TerrainLandform WFeatureHighMountains;
public CivilizationManager CivilizationManager;
public Civilization CivilizationRome;
public Civilization CivilizationEgypt;
public YieldManager YieldManager;

public CivilizationManager CivilisationManager => CivilizationManager;
public FeatureWorld FeatureWorld;

private void InitWorldContent()
{

//game data
_keysRoot = new RootKey("root");
KeysRoot = new RootKey("root");

_yieldManager = new YieldManagerImpl(new Key(_keysRoot, "yield"));
YieldManager = new YieldManagerImpl(new Key(KeysRoot, "yield"));

_wfeatureBiome = new YieldModifyingSSFR<TerrainBiome>(WorldType.World, new Key(_keysRoot, "tb"), false, Terrain);
_wfeatureVegetation = new YieldModifyingSMFR<TerrainVegetation>(WorldType.World, new Key(_keysRoot, "tv"), Terrain);
_wfeatureLandform = new YieldModifyingSSFR<TerrainLandform>(WorldType.World, new Key(_keysRoot, "tl"), false, Terrain);
WFeatureBiome = new YieldModifyingSSFR<TerrainBiome>(WorldType.World, new Key(KeysRoot, "tb"), false, Terrain);
WFeatureVegetation = new YieldModifyingSMFR<TerrainVegetation>(WorldType.World, new Key(KeysRoot, "tv"), Terrain);
WFeatureLandform = new YieldModifyingSSFR<TerrainLandform>(WorldType.World, new Key(KeysRoot, "tl"), false, Terrain);

//civs
_civilizationManager = new CivilizationManager(new Key(_keysRoot, "civs"), 4);
CivilizationManager = new CivilizationManager(new Key(KeysRoot, "civs"), 4);



Expand All @@ -63,28 +64,28 @@ private void LoadWorldContent()

//game data

_yieldFood = new YieldType("food", _yieldManager);
_yieldProduction = new YieldType("production", _yieldManager);
_yieldCommerce = new YieldType("commerce", _yieldManager);
YieldFood = new YieldType("food", YieldManager);
YieldProduction = new YieldType("production", YieldManager);
YieldCommerce = new YieldType("commerce", YieldManager);

_wfeatureGlassland = new TerrainBiome("grassland", _wfeatureBiome, _yieldManager, Addition, new double[] {2, 0, 0});
_wfeaturePlains = new TerrainBiome("plains", _wfeatureBiome, _yieldManager, Addition, new double[] {1, 1, 0});
_wfeatureDesert = new TerrainBiome("desert", _wfeatureBiome, _yieldManager, Addition, new double[] {0, 1, 0});
_wfeatureTundra = new TerrainBiome("tundra", _wfeatureBiome, _yieldManager, Addition, new double[] {1, 0, 0});
_wfeatureIce = new TerrainBiome("ice", _wfeatureBiome, _yieldManager, Addition, new double[] {0, 0, 0});
WFeatureGlassland = new TerrainBiome("grassland", WFeatureBiome, YieldManager, Addition, new double[] {2, 0, 0});
WFeaturePlains = new TerrainBiome("plains", WFeatureBiome, YieldManager, Addition, new double[] {1, 1, 0});
WFeatureDesert = new TerrainBiome("desert", WFeatureBiome, YieldManager, Addition, new double[] {0, 1, 0});
WFeatureTundra = new TerrainBiome("tundra", WFeatureBiome, YieldManager, Addition, new double[] {1, 0, 0});
WFeatureIce = new TerrainBiome("ice", WFeatureBiome, YieldManager, Addition, new double[] {0, 0, 0});

_wfeatureJungle = new TerrainVegetation("jungle", _wfeatureVegetation, _yieldManager, Addition, new double[] {0, -1, -1});
_wfeatureForest = new TerrainVegetation("forest", _wfeatureVegetation, _yieldManager, Addition, new double[] {0, 1, 0});
_wfeaturePineForest = new TerrainVegetation("pine forest", _wfeatureVegetation, _yieldManager, Addition, new double[] {0, 1, 0});
WFeatureJungle = new TerrainVegetation("jungle", WFeatureVegetation, YieldManager, Addition, new double[] {0, -1, -1});
WFeatureForest = new TerrainVegetation("forest", WFeatureVegetation, YieldManager, Addition, new double[] {0, 1, 0});
WFeaturePineForest = new TerrainVegetation("pine forest", WFeatureVegetation, YieldManager, Addition, new double[] {0, 1, 0});

_wfeatureFlatland = new TerrainLandform("flatland", _wfeatureLandform, _yieldManager, Addition, new double[] {0, 0, 0});
_wfeatureHills = new TerrainLandform("hills", _wfeatureLandform, _yieldManager, Addition, new double[] {-1, 1, 0});
_wfeatureMountains = new TerrainLandform("mountains", _wfeatureLandform, _yieldManager, Addition, new double[] {-2, 1, 0});
_wfeatureHighMountains = new TerrainLandform("high mountains", _wfeatureLandform, _yieldManager, Addition, new double[] {-2, 0, -1});
WFeatureFlatland = new TerrainLandform("flatland", WFeatureLandform, YieldManager, Addition, new double[] {0, 0, 0});
WFeatureHills = new TerrainLandform("hills", WFeatureLandform, YieldManager, Addition, new double[] {-1, 1, 0});
WFeatureMountains = new TerrainLandform("mountains", WFeatureLandform, YieldManager, Addition, new double[] {-2, 1, 0});
WFeatureHighMountains = new TerrainLandform("high mountains", WFeatureLandform, YieldManager, Addition, new double[] {-2, 0, -1});

//civs
_civilizationRome = new Civilization("Rome", CivilisationManager);
_civilizationEgypt = new Civilization("Egypt", CivilisationManager);
CivilizationRome = new Civilization("Rome", CivilisationManager);
CivilizationEgypt = new Civilization("Egypt", CivilisationManager);



Expand All @@ -93,21 +94,22 @@ private void LoadWorldContent()
private void LockFeatureWorld()
{
//init
var fw = new FeatureWorld(2, _yieldManager);
fw.Register(_wfeatureBiome);
fw.Register(_wfeatureVegetation);
fw.Register(_wfeatureLandform);
var fw = new FeatureWorld(2, YieldManager);
fw.Register(WFeatureBiome);
fw.Register(WFeatureVegetation);
fw.Register(WFeatureLandform);
fw.Register(CivilisationManager.Resolver);
fw.Lock();
FeatureWorld = fw;

InitTexture();
}

private void AddResourceHooks()
{
ResourceManager.Instance.AddHook(_wfeatureBiome, TerrainHook);
ResourceManager.Instance.AddHook(_wfeatureLandform, TerrainHook);
ResourceManager.Instance.AddHook(_wfeatureVegetation, TerrainHook);
ResourceManager.Instance.AddHook(WFeatureBiome, TerrainHook);
ResourceManager.Instance.AddHook(WFeatureLandform, TerrainHook);
ResourceManager.Instance.AddHook(WFeatureVegetation, TerrainHook);
ResourceManager.Instance.AddHook(CivilisationManager.Resolver, TerrainHook);
}

Expand Down
14 changes: 14 additions & 0 deletions TestLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@ private static void Main()
env.Load();
Console.WriteLine("Done");
new Civilization("Kappaland", env.CivilisationManager);


//world creation
var world = new TileWorld(env.FeatureWorld, 5, 5);

// ReSharper disable once InconsistentNaming
var tile3_3 = world[3, 3];

Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3).Name);
env.WFeatureDesert.AddFeature(tile3_3);
Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3).Name);
env.WFeatureHighMountains.AddFeature(tile3_3);
Console.WriteLine(env.WFeatureBiome.GetFeature(tile3_3).Name);
}



private static void TestResourceManPlugins()
Expand Down
Loading

0 comments on commit 4c3a8f6

Please sign in to comment.