Skip to content

Commit 1957686

Browse files
committed
Finished List except for reading and writing generic
1 parent a8ce784 commit 1957686

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

MLAPI/Data/NetworkedCollections/NetworkedList.cs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,56 @@ public bool CanClientRead(uint clientId)
8080

8181
public void WriteDeltaToWriter(BitWriter writer)
8282
{
83+
writer.WriteUShort((ushort)dirtyEvents.Count);
8384
for (int i = 0; i < dirtyEvents.Count; i++)
8485
{
85-
//TODO: Write event
86+
writer.WriteBits((byte)dirtyEvents[i].eventType, 3);
87+
switch (dirtyEvents[i].eventType)
88+
{
89+
//Fuck me these signatures are proper aids
90+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Add:
91+
{
92+
//TODO: Write dirtyEvents[i].value
93+
}
94+
break;
95+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Insert:
96+
{
97+
writer.WriteInt(dirtyEvents[i].index);
98+
//TODO: Write dirtyEvents[i].value
99+
}
100+
break;
101+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Remove:
102+
{
103+
//TODO: Write dirtyEvents[i].value
104+
}
105+
break;
106+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
107+
{
108+
writer.WriteInt(dirtyEvents[i].index);
109+
}
110+
break;
111+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Value:
112+
{
113+
writer.WriteInt(dirtyEvents[i].index);
114+
//TODO: Write dirtyEvents[i].value
115+
}
116+
117+
break;
118+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Clear:
119+
{
120+
//Nothing has to be written
121+
}
122+
break;
123+
}
86124
}
87125
}
88126

89127
public void WriteFieldToWriter(BitWriter writer)
90128
{
129+
writer.WriteUShort((ushort)list.Count);
91130
for (int i = 0; i < list.Count; i++)
92131
{
93-
//TODO: Write the field
132+
//TODO: Write the fieldValue
94133
}
95134
}
96135

@@ -108,7 +147,44 @@ public void SetDeltaFromReader(BitReader reader)
108147
ushort deltaCount = reader.ReadUShort();
109148
for (int i = 0; i < deltaCount; i++)
110149
{
111-
//TODO: Read the NetworkedListEvent and apply the instruction
150+
NetworkedListEvent<T>.NetworkedListEventType eventType = (NetworkedListEvent<T>.NetworkedListEventType)reader.ReadBits(3);
151+
switch (eventType)
152+
{
153+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Add:
154+
{
155+
//TODO: list.Add(readValue);
156+
}
157+
break;
158+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Insert:
159+
{
160+
int index = reader.ReadInt();
161+
//TODO: list.Insert(index, readValue);
162+
}
163+
break;
164+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Remove:
165+
{
166+
//TODO: list.Remove(readValue);
167+
}
168+
break;
169+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
170+
{
171+
int index = reader.ReadInt();
172+
list.RemoveAt(index);
173+
}
174+
break;
175+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Value:
176+
{
177+
int index = reader.ReadInt();
178+
//TODO: list[index] = readValue
179+
}
180+
break;
181+
case global::MLAPI.Data.NetworkedCollections.NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Clear:
182+
{
183+
//Read nothing
184+
list.Clear();
185+
}
186+
break;
187+
}
112188
}
113189
}
114190

0 commit comments

Comments
 (0)