Skip to content

Commit

Permalink
work on data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
AIP21 committed May 8, 2023
1 parent cc7c9c0 commit ffb6dd4
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 286 deletions.
2 changes: 1 addition & 1 deletion Assets/DataStructure/Data/AbstractGridData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SimDataStructure.Data
{
// Data for whole grid (one instance per grid)
// Data for whole grid (one instance per grid).
[Serializable]
public abstract class AbstractGridData
{
Expand Down
21 changes: 16 additions & 5 deletions Assets/DataStructure/Data/BufferGridData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ public class BufferGridData : AbstractGridData

private ComputeBuffer computeBuffer;

public BufferGridData()
{
}

public void InitBuffer(int width, int height, int contentSize = sizeof(float) * 4)
public BufferGridData(int width, int height, int contentSize = sizeof(float) * 4)
{
this.width = width;
this.height = height;
Expand Down Expand Up @@ -50,5 +46,20 @@ public override void Release()
this.computeBuffer = null;
}
}

public int GetWidth()
{
return this.width;
}

public int GetHeight()
{
return this.height;
}

public int GetContentSize()
{
return this.contentSize;
}
}
}
6 changes: 3 additions & 3 deletions Assets/DataStructure/Data/TextureGridData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class TextureGridData : AbstractGridData
public TextureGridData(int resolution, RenderTextureFormat format, FilterMode filterMode = FilterMode.Point)
{
this.resolution = resolution;
this.renderTexture = this.CreateTexture(format, filterMode);
this.renderTexture = this.createTexture(format, filterMode);
}

// Return a copy of the texture
public RenderTexture GetData()
{
RenderTexture copy = CreateTexture(this.renderTexture.format, this.renderTexture.filterMode);
RenderTexture copy = createTexture(this.renderTexture.format, this.renderTexture.filterMode);

Graphics.Blit(this.renderTexture, copy);

Expand All @@ -41,7 +41,7 @@ public override void Release()
}
}

public RenderTexture CreateTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point)
private RenderTexture createTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point)
{
RenderTexture rt = new RenderTexture(resolution, resolution, 24, format);
rt.filterMode = filterMode;
Expand Down
5 changes: 3 additions & 2 deletions Assets/DataStructure/Scripts/DataStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ private void sendRequestedData(IReadDataStructure reader)
for (int e = 0; e < reader.ReadDataNames.Count; e++)
{
string dataName = reader.ReadDataNames[e];

if (cachedData.ContainsKey(dataName))
{
data.Add(cachedData[dataName]);
print("A system has requested data that has already been requested. Please avoid this by making sure data is used by only one system per tick.");
// print("A system has requested data that has already been requested. Please avoid this by making sure data is used by only one system per tick.");
}
else
{
Expand All @@ -170,7 +171,7 @@ private void sendRequestedData(IReadDataStructure reader)
reader.recieveData(data);
}

// Reads the new data from a writing class and writes it to the data structure
// Recieves the new data from a writing class and writes it to the data structure
// TODO: Make it only write ONCE, not once for every data name. It'll override it anyways so it is currently wasting writes just for them to be overriden
private void recieveDataFromWriter(IWriteDataStructure writer)
{
Expand Down
120 changes: 118 additions & 2 deletions Assets/Scenes/Testing.unity
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 638825940}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &282096877
MonoBehaviour:
Expand All @@ -172,6 +172,53 @@ MonoBehaviour:
- {fileID: 11400000, guid: 36751346e59f29e409b3874b0603be45, type: 2}
- {fileID: 11400000, guid: a8156ca0bf27694458adbefdae0a24e1, type: 2}
- {fileID: 11400000, guid: 5d57596dba7f4ac4582655b943c0fedc, type: 2}
--- !u!1 &582991950
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 582991951}
- component: {fileID: 582991952}
m_Layer: 0
m_Name: Systems Manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &582991951
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 582991950}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 638825940}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &582991952
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 582991950}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 36b1f1d4fbabb9444bb1305de913d34a, type: 3}
m_Name:
m_EditorClassIdentifier:
tickableObjects:
- {fileID: 282096875}
- {fileID: 1364809028}
--- !u!1 &638825939
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -200,11 +247,80 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 582991951}
- {fileID: 282096876}
- {fileID: 1597987556}
- {fileID: 1364809027}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1364809026
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 638825940}
m_Modifications:
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6456605025595122871, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
propertyPath: m_Name
value: Water Simulation
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
--- !u!4 &1364809027 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
m_PrefabInstance: {fileID: 1364809026}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1364809028 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6456605025595122871, guid: 2203fda62e853af4a909b4477943d7e9, type: 3}
m_PrefabInstance: {fileID: 1364809026}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1597987555
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -235,7 +351,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 638825940}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1597987557
MonoBehaviour:
Expand Down
19 changes: 17 additions & 2 deletions Assets/SystemsManagement/Managers/SystemsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,31 @@ namespace Managers {
public class SystemsManager : MonoBehaviour {
public static SystemsManager Instance { get; private set; }

public List<ITickableSystem> tickableSystems = new List<ITickableSystem>();
public List<GameObject> tickableObjects = new List<GameObject>();
private List<ITickableSystem> tickableSystems = new List<ITickableSystem>();


private List<ITickableSystem> toTick = new List<ITickableSystem>();

public void Awake() {
Instance = this;
}

public void Start() {
for (int i = 0; i < tickableObjects.Count; i++) {
ITickableSystem system = tickableObjects[i].GetComponent<ITickableSystem>();
if (system == null) {
Debug.LogError("SystemsManager: GameObject " + tickableObjects[i].name + " does not have a component that implements ITickableSystem");
}

tickableSystems.Add(system);
}
}

public void FixedUpdate() {
float deltaT = Time.fixedDeltaTime;

List<ITickableSystem> toTick = new List<ITickableSystem>(tickableSystems);
toTick.Clear();

// Figure out which systems need to be ticked this frame
int currentTick = Time.frameCount;
Expand Down
Loading

0 comments on commit ffb6dd4

Please sign in to comment.