Started Rewriting Packet Handling
Started rewriting our packet handling code. Deleted PacketHandler in favor of using sided (Server-, Client-) packet handlers to make it easier to follow what's going on in our code. Added some event-based handling of updates which greatly simplified signaling that data needs to be sent, but it's not completely done yet.
This commit is contained in:
8
StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java
Normal file
8
StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
public interface IOpaqueMessage
|
||||
{
|
||||
void writeToStream(DataOutputStream stream);
|
||||
}
|
||||
8
StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java
Normal file
8
StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public interface IOpaqueReader
|
||||
{
|
||||
IOpaqueMessage read(ByteArrayDataInput source);
|
||||
}
|
||||
8
StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java
Normal file
8
StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
public interface IUpdateWatcher
|
||||
{
|
||||
public void onCreated(IOpaqueMessage message);
|
||||
public void onUpdated(IOpaqueMessage message);
|
||||
public void onDeleted(IOpaqueMessage message);
|
||||
}
|
||||
51
StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java
Normal file
51
StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package StevenDimDoors.mod_pocketDim.watcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateWatcherProxy implements IUpdateWatcher
|
||||
{
|
||||
private List<IUpdateWatcher> watchers;
|
||||
|
||||
public UpdateWatcherProxy()
|
||||
{
|
||||
watchers = new ArrayList<IUpdateWatcher>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(IOpaqueMessage message)
|
||||
{
|
||||
for (IUpdateWatcher receiver : watchers)
|
||||
{
|
||||
receiver.onCreated(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdated(IOpaqueMessage message)
|
||||
{
|
||||
for (IUpdateWatcher receiver : watchers)
|
||||
{
|
||||
receiver.onUpdated(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleted(IOpaqueMessage message)
|
||||
{
|
||||
for (IUpdateWatcher receiver : watchers)
|
||||
{
|
||||
receiver.onDeleted(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerReceiver(IUpdateWatcher receiver)
|
||||
{
|
||||
watchers.add(receiver);
|
||||
}
|
||||
|
||||
public boolean unregisterReceiver(IUpdateWatcher receiver)
|
||||
{
|
||||
return watchers.remove(receiver);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user