mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
10
server/tso.common/Model/DynTuningEntry.cs
Executable file
10
server/tso.common/Model/DynTuningEntry.cs
Executable file
|
@ -0,0 +1,10 @@
|
|||
namespace FSO.Common.Model
|
||||
{
|
||||
public class DynTuningEntry
|
||||
{
|
||||
public string tuning_type { get; set; }
|
||||
public int tuning_table { get; set; }
|
||||
public int tuning_index { get; set; }
|
||||
public float value { get; set; }
|
||||
}
|
||||
}
|
148
server/tso.common/Model/DynamicTuning.cs
Executable file
148
server/tso.common/Model/DynamicTuning.cs
Executable file
|
@ -0,0 +1,148 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace FSO.Common.Model
|
||||
{
|
||||
public class DynamicTuning
|
||||
{
|
||||
//global tuning:
|
||||
// city -
|
||||
// 0: terrain
|
||||
// 0: forceSnow (0/1/null)
|
||||
public static DynamicTuning Global;
|
||||
|
||||
//string type/iff, int table, int index.
|
||||
public Dictionary<string, Dictionary<int, Dictionary<int, float>>> Tuning = new Dictionary<string, Dictionary<int, Dictionary<int, float>>>();
|
||||
public const int CURRENT_VERSION = 0;
|
||||
public int Version = CURRENT_VERSION;
|
||||
|
||||
public void SerializeInto(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(CURRENT_VERSION);
|
||||
writer.Write(Tuning.Count);
|
||||
foreach (var type in Tuning)
|
||||
{
|
||||
writer.Write(type.Key);
|
||||
writer.Write(type.Value.Count);
|
||||
foreach (var table in type.Value)
|
||||
{
|
||||
writer.Write(table.Key);
|
||||
writer.Write(table.Value.Count);
|
||||
foreach (var value in table.Value)
|
||||
{
|
||||
writer.Write(value.Key);
|
||||
writer.Write(value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DynamicTuning(IEnumerable<DynTuningEntry> entries)
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
AddTuning(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTuning(DynTuningEntry entry)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, float>> tables;
|
||||
if (!Tuning.TryGetValue(entry.tuning_type, out tables))
|
||||
{
|
||||
tables = new Dictionary<int, Dictionary<int, float>>();
|
||||
Tuning[entry.tuning_type] = tables;
|
||||
}
|
||||
Dictionary<int, float> data;
|
||||
if (!tables.TryGetValue(entry.tuning_table, out data))
|
||||
{
|
||||
data = new Dictionary<int, float>();
|
||||
tables[entry.tuning_table] = data;
|
||||
}
|
||||
data[entry.tuning_index] = entry.value;
|
||||
}
|
||||
|
||||
public DynamicTuning(DynamicTuning old)
|
||||
{
|
||||
foreach (var type in Tuning)
|
||||
{
|
||||
var newType = new Dictionary<int, Dictionary<int, float>>();
|
||||
foreach (var table in type.Value)
|
||||
{
|
||||
var newTable = new Dictionary<int, float>();
|
||||
foreach (var value in table.Value)
|
||||
{
|
||||
newTable[value.Key] = value.Value;
|
||||
}
|
||||
newType[table.Key] = newTable;
|
||||
}
|
||||
Tuning[type.Key] = newType;
|
||||
}
|
||||
}
|
||||
|
||||
public DynamicTuning(BinaryReader reader)
|
||||
{
|
||||
Version = reader.ReadInt32();
|
||||
var count = reader.ReadInt32();
|
||||
for (int i=0; i<count; i++)
|
||||
{
|
||||
var key = reader.ReadString();
|
||||
var count2 = reader.ReadInt32();
|
||||
var newType = new Dictionary<int, Dictionary<int, float>>();
|
||||
for (int j = 0; j < count2; j++)
|
||||
{
|
||||
var key2 = reader.ReadInt32();
|
||||
var count3 = reader.ReadInt32();
|
||||
var newTable = new Dictionary<int, float>();
|
||||
for (int k=0; k<count3; k++)
|
||||
{
|
||||
var key3 = reader.ReadInt32();
|
||||
newTable[key3] = reader.ReadSingle();
|
||||
}
|
||||
newType[key2] = newTable;
|
||||
}
|
||||
Tuning[key] = newType;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, float> GetTable(string type, int table)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, float>> tables;
|
||||
if (Tuning.TryGetValue(type, out tables))
|
||||
{
|
||||
Dictionary<int, float> data;
|
||||
if (tables.TryGetValue(table, out data))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dictionary<int, Dictionary<int, float>> GetTables(string type)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, float>> tables;
|
||||
if (Tuning.TryGetValue(type, out tables))
|
||||
{
|
||||
return tables;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public float? GetTuning(string type, int table, int index)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, float>> tables;
|
||||
if (Tuning.TryGetValue(type, out tables))
|
||||
{
|
||||
Dictionary<int, float> data;
|
||||
if (tables.TryGetValue(table, out data))
|
||||
{
|
||||
float result;
|
||||
if (data.TryGetValue(index, out result))
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
115
server/tso.common/Model/IntersectRectSet.cs
Executable file
115
server/tso.common/Model/IntersectRectSet.cs
Executable file
|
@ -0,0 +1,115 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace FSO.Common.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// A k-d Tree for looking up rectangle intersections
|
||||
/// TODO: balancing? could make performance gains more stable at the cost of some of the worst case.
|
||||
/// </summary>
|
||||
public class IntersectRectTree
|
||||
{
|
||||
public IntersectRectNode Root;
|
||||
|
||||
public void Add(Rectangle rect)
|
||||
{
|
||||
if (Root == null)
|
||||
{
|
||||
Root = new IntersectRectNode
|
||||
{
|
||||
Dimension = IntersectRectDimension.Left,
|
||||
Rect = rect
|
||||
};
|
||||
} else
|
||||
{
|
||||
Root.AddAsChild(rect);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchForIntersect(Rectangle rect)
|
||||
{
|
||||
if (Root == null) return false;
|
||||
else
|
||||
{
|
||||
return Root.SearchForIntersect(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IntersectRectNode
|
||||
{
|
||||
public IntersectRectNode LeftChild;
|
||||
public IntersectRectNode RightChild;
|
||||
public IntersectRectDimension Dimension;
|
||||
public Rectangle Rect;
|
||||
|
||||
public void AddAsChild(Rectangle rect)
|
||||
{
|
||||
bool rightSide = false;
|
||||
switch (Dimension)
|
||||
{
|
||||
case IntersectRectDimension.Top:
|
||||
rightSide = rect.Top > Rect.Top; break;
|
||||
case IntersectRectDimension.Left:
|
||||
rightSide = rect.Left > Rect.Left; break;
|
||||
case IntersectRectDimension.Bottom:
|
||||
rightSide = rect.Bottom > Rect.Bottom; break;
|
||||
case IntersectRectDimension.Right:
|
||||
rightSide = rect.Right > Rect.Right; break;
|
||||
}
|
||||
if (rightSide)
|
||||
{
|
||||
if (RightChild != null) RightChild.AddAsChild(rect);
|
||||
else
|
||||
{
|
||||
RightChild = new IntersectRectNode
|
||||
{
|
||||
Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
|
||||
Rect = rect
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LeftChild != null) LeftChild.AddAsChild(rect);
|
||||
else
|
||||
{
|
||||
LeftChild = new IntersectRectNode
|
||||
{
|
||||
Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
|
||||
Rect = rect
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchForIntersect(Rectangle rect)
|
||||
{
|
||||
if (rect.Intersects(Rect)) return true;
|
||||
//search in child nodes.
|
||||
int dontSearch = 0;
|
||||
switch (Dimension)
|
||||
{
|
||||
case IntersectRectDimension.Top:
|
||||
dontSearch = (rect.Bottom < Rect.Top)?2:0; break; //if true, do not have to search right (where top greater)
|
||||
case IntersectRectDimension.Left:
|
||||
dontSearch = (rect.Right < Rect.Left)?2:0; break; //if true, do not have to search right (where left greater)
|
||||
case IntersectRectDimension.Bottom:
|
||||
dontSearch = (rect.Top > Rect.Bottom)?1:0; break; //if true, do not have to search left (where bottom less)
|
||||
case IntersectRectDimension.Right:
|
||||
dontSearch = (rect.Left > Rect.Right)?1:0; break; //if true, do not have to search left (where right less)
|
||||
}
|
||||
|
||||
//may need to search both :'( won't happen often with our small rectangles over large space though.
|
||||
return ((dontSearch != 1 && LeftChild != null && LeftChild.SearchForIntersect(rect))
|
||||
|| (dontSearch != 2 && RightChild != null && RightChild.SearchForIntersect(rect)));
|
||||
}
|
||||
}
|
||||
|
||||
public enum IntersectRectDimension : byte
|
||||
{
|
||||
Top,
|
||||
Left,
|
||||
Bottom,
|
||||
Right
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue