Пример #1
0
 @Override
 public boolean step() {
   NetworkSystemImpl networkSystem = (NetworkSystemImpl) context.get(NetworkSystem.class);
   EntityRef client = networkSystem.getServer().getClientEntity();
   if (client.exists()) {
     context.get(LocalPlayer.class).setClientEntity(client);
     return true;
   }
   return false;
 }
  @Override
  public boolean step() {
    EntityManager entityManager = context.get(EntityManager.class);
    WorldRenderer worldRenderer = context.get(WorldRenderer.class);

    Iterator<EntityRef> worldEntityIterator =
        entityManager.getEntitiesWith(WorldComponent.class).iterator();
    // TODO: Move the world renderer bits elsewhere
    if (worldEntityIterator.hasNext()) {
      EntityRef worldEntity = worldEntityIterator.next();
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // get the world generator config from the world entity
      // replace the world generator values from the components in the world entity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = worldEntity.getComponent(clazz);
        if (comp != null) {
          worldConfigurator.setProperty(entry.getKey(), comp);
        }
      }
    } else {
      EntityRef worldEntity = entityManager.create();
      worldEntity.addComponent(new WorldComponent());
      worldRenderer.getChunkProvider().setWorldEntity(worldEntity);

      // transfer all world generation parameters from Config to WorldEntity
      WorldGenerator worldGenerator = context.get(WorldGenerator.class);
      SimpleUri generatorUri = worldGenerator.getUri();
      Config config = context.get(Config.class);

      // get the map of properties from the world generator.
      // Replace its values with values from the config set by the UI.
      // Also set all the components to the world entity.
      WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
      Map<String, Component> params = worldConfigurator.getProperties();
      for (Map.Entry<String, Component> entry : params.entrySet()) {
        Class<? extends Component> clazz = entry.getValue().getClass();
        Component comp = config.getModuleConfig(generatorUri, entry.getKey(), clazz);
        if (comp != null) {
          worldEntity.addComponent(comp);
          worldConfigurator.setProperty(entry.getKey(), comp);
        } else {
          worldEntity.addComponent(entry.getValue());
        }
      }
    }

    return true;
  }
Пример #3
0
  @Override
  public boolean step() {
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    WorldAtlas atlas =
        new WorldAtlasImpl(context.get(Config.class).getRendering().getMaxTextureAtlasResolution());
    context.put(WorldAtlas.class, atlas);

    BlockManagerImpl blockManager;
    if (networkSystem.getMode().isAuthority()) {
      blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), true);
      blockManager.subscribe(context.get(NetworkSystem.class));
    } else {
      blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), false);
    }
    context.put(BlockManager.class, blockManager);
    context
        .get(TypeSerializationLibrary.class)
        .add(Block.class, new BlockTypeHandler(blockManager));
    context
        .get(TypeSerializationLibrary.class)
        .add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));

    blockManager.initialise(
        gameManifest.getRegisteredBlockFamilies(), gameManifest.getBlockIdMap());

    return true;
  }
Пример #4
0
 @Override
 public boolean step() {
   if (worldRenderer.pregenerateChunks()) {
     return true;
   }
   EngineTime time = (EngineTime) context.get(Time.class);
   long totalTime = time.getRawTimeInMs() - startTime;
   return totalTime > 5000;
 }
Пример #5
0
 private void switchState(GameState newState) {
   if (currentState != null) {
     currentState.dispose();
   }
   currentState = newState;
   LoggingContext.setGameState(newState);
   newState.init(this);
   for (StateChangeSubscriber subscriber : stateChangeSubscribers) {
     subscriber.onStateChange();
   }
   // drain input queues
   InputSystem inputSystem = rootContext.get(InputSystem.class);
   inputSystem.getMouseDevice().getInputQueue();
   inputSystem.getKeyboard().getInputQueue();
 }
Пример #6
0
 /**
  * Updates a config with any binds that it may be missing, through reflection over
  * RegisterBindButton annotations
  */
 public void updateForChangedMods(Context context) {
   ModuleManager moduleManager = context.get(ModuleManager.class);
   DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
   for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
     if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
       ResolutionResult result = resolver.resolve(moduleId);
       if (result.isSuccess()) {
         try (ModuleEnvironment environment =
             moduleManager.loadEnvironment(result.getModules(), false)) {
           updateInputsFor(
               moduleId,
               environment.getTypesAnnotatedWith(
                   RegisterBindButton.class, new FromModule(environment, moduleId)));
         }
       }
     }
   }
 }
Пример #7
0
 /**
  * @return A new BindsConfig, with inputs set from the DefaultBinding annotations on bind classes
  */
 public static BindsConfig createDefault(Context context) {
   ModuleManager moduleManager = context.get(ModuleManager.class);
   BindsConfig config = new BindsConfig();
   DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
   for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
     if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
       ResolutionResult result = resolver.resolve(moduleId);
       if (result.isSuccess()) {
         try (ModuleEnvironment environment =
             moduleManager.loadEnvironment(result.getModules(), false)) {
           config.addDefaultsFor(
               moduleId,
               environment.getTypesAnnotatedWith(
                   RegisterBindButton.class, new FromModule(environment, moduleId)));
         }
       }
     }
   }
   return config;
 }
Пример #8
0
 /**
  * Updates a config with any binds that it may be missing, through reflection over
  * RegisterBindButton annotations
  */
 public void updateForChangedMods(Context context) {
   ModuleManager moduleManager = context.get(ModuleManager.class);
   DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
   for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
     if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
       ResolutionResult result = resolver.resolve(moduleId);
       if (result.isSuccess()) {
         try (ModuleEnvironment environment =
             moduleManager.loadEnvironment(result.getModules(), false)) {
           FromModule filter = new FromModule(environment, moduleId);
           Iterable<Class<?>> buttons =
               environment.getTypesAnnotatedWith(RegisterBindButton.class, filter);
           Iterable<Class<?>> axes =
               environment.getTypesAnnotatedWith(RegisterRealBindAxis.class, filter);
           updateButtonInputsFor(moduleId, buttons);
           updateAxisInputsFor(moduleId, axes);
         }
       }
     }
   }
 }
 public EntityAwareWorldProvider(WorldProviderCore base, Context context) {
   super(base);
   entityManager = (EngineEntityManager) context.get(EntityManager.class);
   context.get(ComponentSystemManager.class).register(getTime());
 }
Пример #10
0
 /**
  * Allows it to obtain objects directly from the context of the game engine. It exists only for
  * situations in which no child context exists yet. If there is a child context then it
  * automatically contains the objects of the engine context. Thus normal code should just work
  * with the (child) context that is available to it instead of using this method.
  *
  * @return a object directly from the context of the game engine
  */
 public <T> T getFromEngineContext(Class<? extends T> type) {
   return rootContext.get(type);
 }
Пример #11
0
 /**
  * Verifies that a required class is available through the core registry.
  *
  * @param clazz The required type, i.e. Time.class
  * @throws IllegalStateException Details the required system that has not been registered.
  */
 private void verifyRequiredSystemIsRegistered(Class<?> clazz) {
   if (rootContext.get(clazz) == null) {
     throw new IllegalStateException(clazz.getSimpleName() + " not registered as a core system.");
   }
 }
Пример #12
0
 @Override
 public void begin() {
   worldRenderer = context.get(WorldRenderer.class);
   EngineTime time = (EngineTime) context.get(Time.class);
   startTime = time.getRawTimeInMs();
 }
 public StunAlterationEffect(Context context) {
   this.delayManager = context.get(DelayManager.class);
 }