Skip to content

Commit

Permalink
Imported changes post-7dfps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Succyboi committed Dec 19, 2023
1 parent e60d72b commit 873321f
Show file tree
Hide file tree
Showing 50 changed files with 1,318 additions and 451 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#if GODOT

using Godot;
using System;
using System;
using System.Collections.Generic;

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
Expand All @@ -27,7 +25,7 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public abstract partial class GodotNetworkObject : Node, INetworkObject {
public abstract partial class NetworkObject : INetworkObject {
#region NetworkObject Implementation

Action INetworkObject.OnOwnershipChanged { get; set; }
Expand All @@ -40,34 +38,33 @@ public abstract partial class GodotNetworkObject : Node, INetworkObject {

ushort? INetworkObject.ownerID { get; set; }
NetworkObjectAbandonmentPolicy INetworkObject.abandonmentPolicy { get; set; } = HiHiConfiguration.DEFAULT_ABANDONMENT_POLICY;
SyncObject[] INetworkObject.syncObjects { get; set; }
byte INetworkObject.syncObjectCount { get; set; }
Dictionary<byte, SyncObject> INetworkObject.syncObjects { get; set; }

void INetworkObject.OnRegister() => OnRegister();
void INetworkObject.OnUnregister() => OnUnregister();
void INetworkObject.DestroyLocally() => QueueFree();
void INetworkObject.Update() => Update();
void INetworkObject.Update() => UpdateInstance();

#endregion

#region Godot
#region Members

public INetworkObject Interface => this as INetworkObject;

public INetworkObject NetworkObject => this as INetworkObject;
public Action OnOwnershipChanged { get => Interface.OnOwnershipChanged; set => Interface.OnOwnershipChanged = value; }
public Action OnAbandonmentPolicyChanged { get => Interface.OnAbandonmentPolicyChanged; set => Interface.OnAbandonmentPolicyChanged = value; }
public ISpawnData OriginSpawnData { get => Interface.OriginSpawnData; }

public override void _ExitTree() {
base._ExitTree();
public bool Registered { get => Interface.Registered; }
public ushort UniqueID { get => Interface.UniqueID; }

if (NetworkObject.Registered) {
NetworkObject.UnRegister();
}
}
public ushort? OwnerID { get => Interface.OwnerID; }
public NetworkObjectAbandonmentPolicy AbandonmentPolicy { get => Interface.AbandonmentPolicy; set => Interface.AbandonmentPolicy = value; }

protected virtual void OnRegister() { }
protected virtual void OnUnregister() { }
protected virtual void Update() { }
protected virtual void UpdateInstance() { }

#endregion
}
}

#endif
}
8 changes: 4 additions & 4 deletions Bindings/Godot/GodotHelper.cs → Bindings/Godot/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public partial class GodotHelper : Node, IHelper {
public static GodotHelper Instance { get; private set; }
public partial class Helper : Node, IHelper {
public static Helper Instance { get; private set; }

[ExportGroup("Spawning")]
[Export] public Array<GodotSpawnData> SpawnDataRegistry = new Array<GodotSpawnData>();
[Export] public Array<SpawnData> SpawnDataRegistry = new Array<SpawnData>();

public override void _EnterTree() {
base._EnterTree();
Expand All @@ -49,7 +49,7 @@ ISpawnData IHelper.DeserializeSpawnData(BitBuffer buffer) {
byte spawnDataIndex = buffer.ReadByte();

if (SpawnDataRegistry.Count <= spawnDataIndex) {
throw new HiHiException($"Received spawn message referencing spawn index {spawnDataIndex}. Which doesn't exist in the {nameof(GodotHelper)}.{nameof(SpawnDataRegistry)}. Make sure your spawndata is the same across peers.");
throw new HiHiException($"Received spawn message referencing spawn index {spawnDataIndex}. Which doesn't exist in the {nameof(Helper)}.{nameof(SpawnDataRegistry)}. Make sure your spawndata is the same across peers.");
}

return SpawnDataRegistry[spawnDataIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public partial struct HiHiVector3 {
public static implicit operator HiHiVector3(Godot.Vector3 from) => new HiHiVector3(from.X, from.Y, from.Z);
}

public partial struct HiHiVector2 {
public static implicit operator Godot.Vector2(HiHiVector2 from) => new Godot.Vector2(from.X, from.Y);
public static implicit operator HiHiVector2(Godot.Vector2 from) => new HiHiVector2(from.X, from.Y);
}

public partial struct HiHiQuaternion {
public static implicit operator Godot.Quaternion(HiHiQuaternion from) => new Godot.Quaternion(from.X, from.Y, from.Z, from.W);
public static implicit operator HiHiQuaternion(Godot.Quaternion from) => new HiHiQuaternion(from.X, from.Y, from.Z, from.W);
Expand Down
45 changes: 45 additions & 0 deletions Bindings/Godot/NetworkObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#if GODOT

using Godot;
using System;

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
*
* Copyright © 2023 Pelle Bruinsma
*
* This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
*
* Permission is hereby granted, free of charge, to any person or organization (the "User") obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, distribute, and/or sell copies of the Software, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or modified versions of the Software.
*
* 2. The User is one of the following:
* a. An individual person, laboring for themselves
* b. A non-profit organization
* c. An educational institution
* d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
*
* 3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
*
* 4. If the User is an organization, then the User is not law enforcement or military, or working for or under either.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public abstract partial class NetworkObject : Node {
#region Godot

public override void _ExitTree() {
base._ExitTree();

if (Interface.Registered) {
Interface.UnRegister();
}
}

#endregion
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public partial class GodotSpawnData : Resource, ISpawnData {
public partial class SpawnData : Resource, ISpawnData {
public int Index => helper.SpawnDataRegistry.IndexOf(this);

[Export] public PackedScene Scene;

private GodotHelper helper => Peer.Helper as GodotHelper;
private Helper helper => Peer.Helper as Helper;

void ISpawnData.Serialize(BitBuffer buffer) {
buffer.AddByte((byte)Index);
Expand Down
57 changes: 57 additions & 0 deletions Bindings/Unity/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#if UNITY_EDITOR || UNITY_STANDALONE

using HiHi.Common;
using HiHi.Serialization;
using UnityEngine;

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
*
* Copyright © 2023 Pelle Bruinsma
*
* This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
*
* Permission is hereby granted, free of charge, to any person or organization (the "User") obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, distribute, and/or sell copies of the Software, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or modified versions of the Software.
*
* 2. The User is one of the following:
* a. An individual person, laboring for themselves
* b. A non-profit organization
* c. An educational institution
* d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
*
* 3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
*
* 4. If the User is an organization, then the User is not law enforcement or military, or working for or under either.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public class Helper : MonoBehaviour, IHelper {
public static UnityHelper Instance { get; private set; }

[Header("Spawning")]
[SerializeField] public SpawnData[] SpawnDataRegistry = new SpawnData[0];

public virtual void OnEnable() {
Instance = this;
}

void IHelper.SerializeSpawnData(ISpawnData spawnData, BitBuffer buffer) {
spawnData.Serialize(buffer);
}

ISpawnData IHelper.DeserializeSpawnData(BitBuffer buffer) {
byte spawnDataIndex = buffer.ReadByte();

if (SpawnDataRegistry.Length <= spawnDataIndex) {
throw new HiHiException($"Received spawn message referencing spawn index {spawnDataIndex}. Which doesn't exist in the {nameof(UnityHelper)}.{nameof(SpawnDataRegistry)}. Make sure your spawndata is the same across peers.");
}

return SpawnDataRegistry[spawnDataIndex];
}
}
}

#endif
38 changes: 38 additions & 0 deletions Bindings/Unity/MiscBindings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if UNITY_EDITOR || UNITY_STANDALONE

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
*
* Copyright © 2023 Pelle Bruinsma
*
* This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
*
* Permission is hereby granted, free of charge, to any person or organization (the "User") obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, distribute, and/or sell copies of the Software, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or modified versions of the Software.
*
* 2. The User is one of the following:
* a. An individual person, laboring for themselves
* b. A non-profit organization
* c. An educational institution
* d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
*
* 3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
*
* 4. If the User is an organization, then the User is not law enforcement or military, or working for or under either.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public partial struct HiHiVector3 {
public static implicit operator UnityEngine.Vector3(HiHiVector3 from) => new UnityEngine.Vector3(from.X, from.Y, from.Z);
public static implicit operator HiHiVector3(UnityEngine.Vector3 from) => new HiHiVector3(from.x, from.y, from.z);
}

public partial struct HiHiQuaternion {
public static implicit operator UnityEngine.Quaternion(HiHiQuaternion from) => new UnityEngine.Quaternion(from.X, from.Y, from.Z, from.W);
public static implicit operator HiHiQuaternion(UnityEngine.Quaternion from) => new HiHiQuaternion(from.x, from.y, from.z, from.w);
}
}

#endif
43 changes: 43 additions & 0 deletions Bindings/Unity/NetworkObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#if UNITY_EDITOR || UNITY_STANDALONE

using UnityEngine;
using System;

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
*
* Copyright © 2023 Pelle Bruinsma
*
* This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
*
* Permission is hereby granted, free of charge, to any person or organization (the "User") obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, distribute, and/or sell copies of the Software, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or modified versions of the Software.
*
* 2. The User is one of the following:
* a. An individual person, laboring for themselves
* b. A non-profit organization
* c. An educational institution
* d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
*
* 3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
*
* 4. If the User is an organization, then the User is not law enforcement or military, or working for or under either.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
public abstract partial class NetworkObject : MonoBehaviour, INetworkObject {
#region Unity

public virtual void OnDestroy() {
if (Interface.Registered) {
Interface.UnRegister();
}
}

#endregion
}
}

#endif
52 changes: 52 additions & 0 deletions Bindings/Unity/SpawnData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#if UNITY_EDITOR || UNITY_STANDALONE

using UnityEngine;
using HiHi.Serialization;
using System;

/*
* ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
*
* Copyright © 2023 Pelle Bruinsma
*
* This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
*
* Permission is hereby granted, free of charge, to any person or organization (the "User") obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, merge, distribute, and/or sell copies of the Software, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in all copies or modified versions of the Software.
*
* 2. The User is one of the following:
* a. An individual person, laboring for themselves
* b. A non-profit organization
* c. An educational institution
* d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
*
* 3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
*
* 4. If the User is an organization, then the User is not law enforcement or military, or working for or under either.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace HiHi {
[CreateAssetMenu(fileName = "SpawnData", menuName = "HiHi/SpawnData")]
public class SpawnData : ScriptableObject, ISpawnData {
public int Index => Array.IndexOf(helper.SpawnDataRegistry, this);

[SerializeField] public NetworkObject Prefab;

private UnityHelper helper => Peer.Helper as UnityHelper;

void ISpawnData.Serialize(BitBuffer buffer) {
buffer.AddByte((byte)Index);
}

INetworkObject ISpawnData.Spawn() {
UnityNetworkObject spawnedInstance = Instantiate(Prefab);
spawnedInstance.transform.parent = helper.transform;

return spawnedInstance as INetworkObject;
}
}
}

#endif
Loading

0 comments on commit 873321f

Please sign in to comment.