Skip to content

Commit

Permalink
rudimentary tree working (ish... its also taken from another project).
Browse files Browse the repository at this point in the history
for some reason the cell data stuff isn't working...

I also need to make updating cells if their data objects moved, but that is not a priority (at all. In fact I should NOT be focusing on that because I most likely will never use it in this project (although it's nice to have))
  • Loading branch information
AIP21 committed May 10, 2023
1 parent 0071727 commit c2d7928
Show file tree
Hide file tree
Showing 48 changed files with 2,617 additions and 396 deletions.
136 changes: 84 additions & 52 deletions Assets/DataStructure/Data/AbstractCellData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,98 @@ namespace SimDataStructure.Data
[Serializable]
public abstract class AbstractCellData
{
public CellDataType type;
/**
<summary>
Whether this cell data is static.
public AbstractCellData()
{
}
A static cell data means that it's gameObject does not move around, and so would always in the same cell.
</summary>
**/
private bool isStatic;

public CellDataType DataType()
{
return type;
}
private GameObject gameObject;

private Transform transform;

public string DataTypeName()
public AbstractCellData(GameObject gameObject)
{
return type.ToString();
this.gameObject = gameObject;
this.transform = gameObject.transform;
}
}

// [CreateAssetMenu(menuName = "Data Structure/Cell Data")]
public class CellData<T> : AbstractCellData
{
public T data;
#region Getters and Setters
/**
<summary>
Whether this cell data is static.
public CellData(T data) : base()
{
this.data = data;

if (typeof(T) == typeof(float))
{
type = CellDataType.Float;
}
else if (typeof(T) == typeof(int))
{
type = CellDataType.Int;
}
else if (typeof(T) == typeof(bool))
{
type = CellDataType.Bool;
}
else if (typeof(T) == typeof(Vector2))
{
type = CellDataType.Vector2;
}
else
{
type = CellDataType.Object;
}
}
A static cell data means that it's gameObject does not move around, and so would always in the same cell.
</summary>
**/
public bool IsStatic { get { return isStatic; } }

public override string ToString()
{
return data.ToString();
}
}
public GameObject GameObject { get { return gameObject; } }

public enum CellDataType
{
Float,
Int,
Bool,
Vector2,
Object
public Transform Transform { get { return transform; } }

public Vector3 Position { get { return transform.position; } }
#endregion
}

// // [CreateAssetMenu(menuName = "Data Structure/Cell Data")]
// public class CellData<T> : AbstractCellData
// {
// public CellDataType type;

// public T data;

// public CellData(T data) : base()
// {
// this.data = data;

// if (typeof(T) == typeof(float))
// {
// type = CellDataType.Float;
// }
// else if (typeof(T) == typeof(int))
// {
// type = CellDataType.Int;
// }
// else if (typeof(T) == typeof(bool))
// {
// type = CellDataType.Bool;
// }
// else if (typeof(T) == typeof(Vector2))
// {
// type = CellDataType.Vector2;
// }
// else
// {
// type = CellDataType.Object;
// }
// }

// public override string ToString()
// {
// return data.ToString();
// }

// public CellDataType DataType()
// {
// return type;
// }

// public string DataTypeName()
// {
// return type.ToString();
// }
// }

// public enum CellDataType
// {
// Float,
// Int,
// Bool,
// Vector2,
// Object
// }
}
11 changes: 0 additions & 11 deletions Assets/DataStructure/Interfaces/IAccessibleData.cs

This file was deleted.

28 changes: 28 additions & 0 deletions Assets/DataStructure/Interfaces/IReadCellData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using SimDataStructure.Data;
using UnityEngine;

namespace SimDataStructure.Interfaces
{
/**
<summary>
For a class to be able to read cell data, it needs to implement the IReadCellData interface.
</summary>
*/
public interface IReadCellData
{
Dictionary<string, int> ReadDataNames { get; } // The levels and names of the data to receive from the data structure

/**
<summary>
Called by the data structure at the beginning of every tick to send the requested list of cell data to the implementing class.
The receiving class should copy the data contained by the AbstractGridData objects in the list, as the data structure will reuse the same AbstractGridData objects for the next tick.
It is recommended for the implementing class to cache the received list of data for use only during the tick, to avoid memory bloat, but the received data list can also be cached for data deltas, etc.
</summary>
*/
void receiveCellData(List<List<AbstractCellData>> sentData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace SimDataStructure.Interfaces
{
/**
<summary>
For a class to be able to read the data, it needs to implement the IReadDataStructure interface.
For a class to be able to read grid data, it needs to implement the IReadGridData interface.
</summary>
*/
public interface IReadDataStructure
public interface IReadGridData
{
Dictionary<string, int> ReadDataNames { get; } // The levels and names of the data to receive from the data structure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is called by the data structure when it is initialized.
An implementing class should initialize only the data that it or its corresponding system will use.
</summary>
*/
public interface ISetupDataStructure
public interface ISetupGridData
{
/**
<summary>
Expand Down
35 changes: 35 additions & 0 deletions Assets/DataStructure/Interfaces/IWriteCellData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using SimDataStructure.Data;
using UnityEngine;

namespace SimDataStructure.Interfaces
{
/**
<summary>
For a class to be able to write cell data to the data structure, it needs to implement the IWriteCellData interface.
</summary>
*/
public interface IWriteCellData
{
/**
<summary>
Called by the data structure at the end of every tick to ADD NEW cell data to the data structure.
This function should return a list of the data that the implementing class wants to write to the data structure.
Return a dictionary of data to add.
</summary>
*/
Dictionary<Tuple<string, int>, List<AbstractCellData>> writeCellDataToAdd();

/**
<summary>
Called by the data structure at the end of every tick to REMOVE cell data from the data structure.
This function should return a list of the data that the implementing class wants to write to the data structure.
Return a dictionary of data to delete.
</summary>
*/
Dictionary<Tuple<string, int>, List<AbstractCellData>> writeCellDataToRemove();
}
}
11 changes: 11 additions & 0 deletions Assets/DataStructure/Interfaces/IWriteCellData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace SimDataStructure.Interfaces
{
/**
<summary>
For a class to be able to write data to the data structure, it needs to implement the IWriteDataStructure interface.
For a class to be able to write data to the data structure, it needs to implement the IWriteGridData interface.
</summary>
*/
public interface IWriteDataStructure
public interface IWriteGridData
{
Dictionary<string, int> WriteDataNames { get; } // The levels and names of the data you are writing to the data structure

Expand Down
Loading

0 comments on commit c2d7928

Please sign in to comment.