Separate interfaces for entities that the clients/server can send updates for (+ placeholder implementations)
May or may not be useful
This commit is contained in:
@@ -151,6 +151,7 @@
|
||||
<Compile Include="Source\Networking\ChatMessage.cs" />
|
||||
<Compile Include="Source\Networking\Client.cs" />
|
||||
<Compile Include="Source\Networking\GameServerLogin.cs" />
|
||||
<Compile Include="Source\Networking\INetSerializable.cs" />
|
||||
<Compile Include="Source\Networking\NetBufferExtensions.cs" />
|
||||
<Compile Include="Source\Networking\NetConfig.cs" />
|
||||
<Compile Include="Source\Networking\NetStats.cs" />
|
||||
|
||||
@@ -15,12 +15,18 @@ using System.Xml.Linq;
|
||||
namespace Barotrauma
|
||||
{
|
||||
|
||||
class Character : Entity, IDamageable, IPropertyObject
|
||||
class Character : Entity, IDamageable, IPropertyObject, IClientSerializable, IServerSerializable
|
||||
{
|
||||
public static List<Character> CharacterList = new List<Character>();
|
||||
|
||||
public static bool DisableControls;
|
||||
|
||||
private ushort netStateID;
|
||||
public ushort NetStateID
|
||||
{
|
||||
get { return netStateID; }
|
||||
}
|
||||
|
||||
//the Character that the player is currently controlling
|
||||
private static Character controlled;
|
||||
|
||||
@@ -1567,5 +1573,25 @@ namespace Barotrauma
|
||||
if (AnimController!=null) AnimController.Remove();
|
||||
}
|
||||
|
||||
public virtual void ClientWrite(NetOutgoingMessage msg)
|
||||
{
|
||||
//TODO: write inputs
|
||||
}
|
||||
public virtual void ServerRead(NetIncomingMessage msg)
|
||||
{
|
||||
//TODO: read inputs
|
||||
}
|
||||
|
||||
public virtual void ServerWrite(NetOutgoingMessage msg)
|
||||
{
|
||||
//TODO: write position, health, etc
|
||||
}
|
||||
|
||||
public virtual void ClientRead(NetIncomingMessage msg)
|
||||
{
|
||||
//TODO: read positions health, etc
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Barotrauma.Items.Components
|
||||
/// <summary>
|
||||
/// The base class for components holding the different functionalities of the item
|
||||
/// </summary>
|
||||
class ItemComponent : IPropertyObject
|
||||
class ItemComponent : IPropertyObject, IClientSerializable, IServerSerializable
|
||||
{
|
||||
protected Item item;
|
||||
|
||||
@@ -74,6 +74,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private string msg;
|
||||
|
||||
protected ushort netStateID;
|
||||
public ushort NetStateID
|
||||
{
|
||||
get { return netStateID; }
|
||||
}
|
||||
|
||||
[HasDefaultValue(0.0f, false)]
|
||||
public float PickingTime
|
||||
{
|
||||
@@ -577,22 +583,6 @@ namespace Barotrauma.Items.Components
|
||||
return (average+100.0f)/2.0f;
|
||||
}
|
||||
|
||||
//public bool CheckFailure(Character Character)
|
||||
//{
|
||||
// foreach (Skill skill in requiredSkills)
|
||||
// {
|
||||
// int characterLevel = Character.GetSkillLevel(skill.Name);
|
||||
// if (characterLevel > skill.Level) continue;
|
||||
|
||||
// item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, Character);
|
||||
// //Item.ApplyStatusEffects();
|
||||
// return true;
|
||||
|
||||
// }
|
||||
|
||||
// return false;
|
||||
//}
|
||||
|
||||
public bool HasRequiredContainedItems(bool addMessage)
|
||||
{
|
||||
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
|
||||
@@ -668,6 +658,12 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ClientWrite(NetOutgoingMessage msg) { }
|
||||
public virtual void ServerRead(NetIncomingMessage msg) { }
|
||||
|
||||
public virtual void ServerWrite(NetOutgoingMessage msg) { }
|
||||
public virtual void ClientRead(NetIncomingMessage msg) { }
|
||||
|
||||
public virtual XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement componentElement = new XElement(name);
|
||||
@@ -681,26 +677,6 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
ObjectProperty.SaveProperties(this, componentElement);
|
||||
|
||||
//var saveProperties = ObjectProperty.GetProperties<Saveable>(this);
|
||||
//foreach (var property in saveProperties)
|
||||
//{
|
||||
// object value = property.GetValue();
|
||||
// if (value == null) continue;
|
||||
|
||||
// bool dontSave = false;
|
||||
// foreach (var ini in property.Attributes.OfType<Initable>())
|
||||
// {
|
||||
// if (ini.defaultValue != value) continue;
|
||||
|
||||
// dontSave = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (dontSave) continue;
|
||||
|
||||
// componentElement.Add(new XAttribute(property.Name.ToLower(), value));
|
||||
//}
|
||||
|
||||
parentElement.Add(componentElement);
|
||||
return componentElement;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Barotrauma
|
||||
OnImpact
|
||||
}
|
||||
|
||||
class Item : MapEntity, IDamageable, IPropertyObject
|
||||
class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable
|
||||
{
|
||||
public static List<Item> ItemList = new List<Item>();
|
||||
private ItemPrefab prefab;
|
||||
@@ -55,6 +55,12 @@ namespace Barotrauma
|
||||
//a dictionary containing lists of the status effects in all the components of the item
|
||||
private Dictionary<ActionType, List<StatusEffect>> statusEffectLists;
|
||||
|
||||
private ushort netStateID;
|
||||
public ushort NetStateID
|
||||
{
|
||||
get { return netStateID; }
|
||||
}
|
||||
|
||||
public readonly Dictionary<string, ObjectProperty> properties;
|
||||
public Dictionary<string, ObjectProperty> ObjectProperties
|
||||
{
|
||||
@@ -1383,12 +1389,6 @@ namespace Barotrauma
|
||||
|
||||
public void Drop(Character dropper = null)
|
||||
{
|
||||
//if (dropper == Character.Controlled)
|
||||
// new NetworkEvent(NetworkEventType.DropItem, ID, true);
|
||||
|
||||
|
||||
//if (dropper != null) GameServer.Log(dropper.Name + " dropped " + Name, Color.Orange);
|
||||
|
||||
foreach (ItemComponent ic in components) ic.Drop(dropper);
|
||||
|
||||
if (Container != null) Container.RemoveContained(this);
|
||||
@@ -1514,6 +1514,9 @@ namespace Barotrauma
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void ServerWrite(NetOutgoingMessage msg) { }
|
||||
public void ClientRead(NetIncomingMessage msg) { }
|
||||
|
||||
public static void Load(XElement element, Submarine submarine)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Barotrauma
|
||||
|
||||
public int GapIndex;
|
||||
|
||||
public float lastSentDamage;
|
||||
//public float lastSentDamage;
|
||||
|
||||
public bool isHighLighted;
|
||||
public ConvexHull hull;
|
||||
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
class Structure : MapEntity, IDamageable
|
||||
class Structure : MapEntity, IDamageable, IServerSerializable
|
||||
{
|
||||
public static int wallSectionSize = 100;
|
||||
public static List<Structure> WallList = new List<Structure>();
|
||||
@@ -58,7 +58,11 @@ namespace Barotrauma
|
||||
|
||||
bool isHorizontal;
|
||||
|
||||
public float lastUpdate;
|
||||
private ushort netStateID;
|
||||
public ushort NetStateID
|
||||
{
|
||||
get { return netStateID; }
|
||||
}
|
||||
|
||||
public override Sprite Sprite
|
||||
{
|
||||
@@ -570,10 +574,10 @@ namespace Barotrauma
|
||||
|
||||
if (!MathUtils.IsValid(damage)) return;
|
||||
|
||||
if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage)>5.0f)
|
||||
{
|
||||
//sections[sectionIndex].lastSentDamage = damage;
|
||||
}
|
||||
//if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage) > 5.0f)
|
||||
//{
|
||||
// sections[sectionIndex].lastSentDamage = damage;
|
||||
//}
|
||||
|
||||
if (damage < prefab.MaxHealth*0.5f)
|
||||
{
|
||||
@@ -685,6 +689,25 @@ namespace Barotrauma
|
||||
return newBody;
|
||||
}
|
||||
|
||||
public void ServerWrite(NetOutgoingMessage msg)
|
||||
{
|
||||
for (int i = 0; i < sections.Length; i++)
|
||||
{
|
||||
msg.WriteRangedSingle(sections[i].damage / Health, 0.0f, 1.0f, 8);
|
||||
|
||||
//sections[i].lastSentDamage = sections[i].damage;
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(NetIncomingMessage msg)
|
||||
{
|
||||
for (int i = 0; i < sections.Count(); i++)
|
||||
{
|
||||
float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
|
||||
|
||||
SetDamage(i, damage);
|
||||
}
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
{
|
||||
|
||||
26
Subsurface/Source/Networking/INetSerializable.cs
Normal file
26
Subsurface/Source/Networking/INetSerializable.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for entities that the clients can send information of to the server
|
||||
/// </summary>
|
||||
interface IClientSerializable
|
||||
{
|
||||
ushort NetStateID { get; }
|
||||
|
||||
void ClientWrite(NetOutgoingMessage msg);
|
||||
void ServerRead(NetIncomingMessage msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for entities that the server can send information of to the clients
|
||||
/// </summary>
|
||||
interface IServerSerializable
|
||||
{
|
||||
ushort NetStateID { get; }
|
||||
|
||||
void ServerWrite(NetOutgoingMessage msg);
|
||||
void ClientRead(NetIncomingMessage msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user