public void init(String receiveIPAddress, int receivePort) { network.init(this, receiveIPAddress, receivePort); commonWorld = new CommonWorld(); CommonWorldExtension extension = new CommonWorldExtension() { @Override public void registerSystems( SystemManager systemManager, GameTimeManager gameTimeManager) { renderSystem = (RenderSystem) systemManager.setSystem(new RenderSystem(container, commonWorld)); renderSystem.setMap(null); renderSystem.addRender(new SpriteRender((World) commonWorld)); entitySendNetworkSystem = systemManager.setSystem(new EntityPositionNetworkTransferSystem(commonWorld)); segmentMoveSystem = systemManager.setSystem(new SegmentMoveSystem(gameTimeManager, commonWorld)); expirationSystem = systemManager.setSystem(new ExpirationSystem(commonWorld)); collisionSystem = (CollisionSystem) systemManager.setSystem(new CollisionSystem(commonWorld)); positionHistorySystem = (PositionHistorySystem) systemManager.setSystem(new PositionHistorySystem()); storePositionHistorySystem = (StorePositionHistorySystem) systemManager.setSystem(new StorePositionHistorySystem(gameTimeManager)); } @Override public CommonNetwork getNetwork() { return network; } }; commonWorld.init(container, extension, gameTimeManager); commonWorld.setPlayfield( new Rectangle( 0, 0, gameWorld.getMap().getWidth() * gameWorld.getMap().getTileWidth(), gameWorld.getMap().getHeight() * gameWorld.getMap().getTileHeight())); botTest = new BotTest(this, commonWorld); commonWorld.setBotTest(botTest); EntityManager entityFactory = commonWorld.getSkillFullEntityManager(); ChatService chatService = new ChatService(commonWorld); chatService.registerServerMessageListener(); commonWorld.getGroupManager().set("camera", entityFactory.createCamera()); network.clearUserCompressedMessagePerTick(); initialized = true; }
public void update(int delta) { if (!initialized) return; commonWorld.loopStart(); commonWorld.setDelta(delta); commonWorld.getGameTimeManager().update(delta); if (worldSimulationTimer > GameTimeManager.SERVER_WORLD_SIMULATION_INTERVAL) { worldSimulationTimer -= GameTimeManager.SERVER_WORLD_SIMULATION_INTERVAL; botTest.update(delta); for (Message message = network.getNewMessage(); message != null; message = network.getNewMessage()) { commonWorld.getEventBusManager().publish(message); } storePositionHistorySystem.process(); expirationSystem.process(); positionHistorySystem.reward(); collisionSystem.setRewindMode(); collisionSystem.setTime(commonWorld.getGameTimeManager().getNetworkTime()); collisionSystem.process(); positionHistorySystem.forward(); positionHistorySystem.process(); } worldSimulationTimer += delta; serverNetworkTimer += delta; if (serverNetworkTimer > GameTimeManager.SERVER_NETWORK_INTERVAL) { serverNetworkTimer -= GameTimeManager.SERVER_WORLD_SIMULATION_INTERVAL; entitySendNetworkSystem.process(); for (User user : commonWorld.getUserManager().getUsers()) { network.sendMessages(user); } network.clearUserCompressedMessagePerTick(); } }
public User getUserByNetworkId(String networkId) { return commonWorld.getUserManager().findByNetworkId(networkId); }