Skip to content

Commit

Permalink
Hook up the basic ES and networking support. Yep, that's it.
Browse files Browse the repository at this point in the history
Just that easy.
  • Loading branch information
pspeed42 committed Sep 10, 2016
1 parent 69acf71 commit 7d40baa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sim-eth-es/src/main/java/example/GameConstants.java
Expand Up @@ -61,6 +61,12 @@ public class GameConstants {
* avoids tying up the main connection.
*/
public static final int CHAT_CHANNEL = 0;

/**
* Send entity-related messages over a separate channel to avoid
* clogging up the main channels.
*/
public static final int ES_CHANNEL = 1;

public static final int GRID_CELL_SIZE = 32;

Expand Down
13 changes: 13 additions & 0 deletions sim-eth-es/src/main/java/example/net/client/GameClient.java
Expand Up @@ -49,6 +49,9 @@
import com.simsilica.ethereal.EtherealClient;
import com.simsilica.ethereal.TimeSource;

import com.simsilica.es.EntityData;
import com.simsilica.es.client.EntityDataClientService;

import example.GameConstants;
import example.net.chat.client.ChatClientService;

Expand All @@ -62,6 +65,7 @@ public class GameClient {
static Logger log = LoggerFactory.getLogger(GameClient.class);

private Client client;
private EntityData ed;

public GameClient( String host, int port ) throws IOException {
log.info("Connecting to:" + host + " " + port);
Expand All @@ -74,11 +78,16 @@ public GameClient( String host, int port ) throws IOException {
new RmiClientService(),
new AccountClientService(),
new GameSessionClientService(),
new EntityDataClientService(GameConstants.ES_CHANNEL),
new ChatClientService(GameConstants.CHAT_CHANNEL),
new EtherealClient(GameConstants.OBJECT_PROTOCOL,
GameConstants.ZONE_GRID,
GameConstants.ZONE_RADIUS)
);

// Can grab this even before started but you won't be able to retrieve
// entities until the connection has been fully setup.
this.ed = client.getServices().getService(EntityDataClientService.class).getEntityData();
}

public TimeSource getTimeSource() {
Expand All @@ -89,6 +98,10 @@ public Client getClient() {
return client;
}

public EntityData getEntityData() {
return ed;
}

public void start() {
log.info("start()");
client.start();
Expand Down
15 changes: 15 additions & 0 deletions sim-eth-es/src/main/java/example/net/server/GameServer.java
Expand Up @@ -49,6 +49,11 @@
import com.simsilica.ethereal.EtherealHost;
import com.simsilica.ethereal.NetworkStateListener;

import com.simsilica.es.EntityData;
import com.simsilica.es.base.DefaultEntityData;
import com.simsilica.es.server.EntityDataHostedService;
import com.simsilica.es.server.EntityUpdater; // from SiO2

import com.simsilica.sim.GameLoop;
import com.simsilica.sim.GameSystemManager;

Expand Down Expand Up @@ -87,6 +92,9 @@ public GameServer( int port, String description ) throws IOException {
// Create a separate channel to do chat stuff so it doesn't interfere
// with any real game stuff.
server.addChannel(port + 1);

// And a separate channel for ES stuff
server.addChannel(port + 2);

server.getServices().addServices(new RpcHostedService(),
new RmiHostedService(),
Expand All @@ -111,6 +119,13 @@ public GameServer( int port, String description ) throws IOException {
// Add a system that will forward physics changes to the Ethereal
// zone manager
systems.addSystem(new ZoneNetworkSystem(ethereal.getZones()));

// Setup our entity data and the hosting service
DefaultEntityData ed = new DefaultEntityData();
server.getServices().addService(new EntityDataHostedService(GameConstants.ES_CHANNEL, ed));

// Add it to the game systems so that we send updates properly
systems.addSystem(new EntityUpdater(server.getServices().getService(EntityDataHostedService.class)));

log.info("Initializing game systems...");
// Initialize the game system manager to prepare to start later
Expand Down

0 comments on commit 7d40baa

Please sign in to comment.