示例#1
0
  public void loadDoodads() {
    InputStream fis =
        game.getGameApplication()
            .getAssetManager()
            .locateAsset(new AssetKey("Scenes/" + map + "/doodads.jme"))
            .openStream();
    BinaryImporter importer = BinaryImporter.getInstance();
    importer.setAssetManager(assetManager);

    try {
      doodadNode = (Node) importer.load(new BufferedInputStream(fis));

      // this node is for buildings in fog (unsauber usw.....)
      doodadNode.attachChild(new Node());

      /*
      Node test =new Node();

      List list =doodadNode.getChildren();
        for(int i=0;i<list.size();i++)
        {
            BatchNode batch = new BatchNode();
            batch.attachChild((Node)list.get(i));
            batch.batch();
            test.attachChild(batch);
        }
      rootNode.attachChild(test);
       *
       */

      reflectNode.attachChild(doodadNode);
    } catch (IOException ex) {
      //  Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "No saved node loaded.", ex);
    }
  }
示例#2
0
  public void loadTerrain() {
    try {
      long start = System.currentTimeMillis();
      // remove the existing terrain and detach it from the root node.
      if (terrain != null) {
        Node existingTerrain = (Node) terrain;
        existingTerrain.removeFromParent();
        existingTerrain.removeControl(TerrainLodControl.class);
        existingTerrain.detachAllChildren();
        terrain = null;
      }

      InputStream fis =
          game.getGameApplication()
              .getAssetManager()
              .locateAsset(new AssetKey("Scenes/" + map + "/terrainsave.jme"))
              .openStream();
      BinaryImporter imp = BinaryImporter.getInstance();
      imp.setAssetManager(assetManager);

      terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
      terrain.setShadowMode(ShadowMode.CastAndReceive);

      clickableNode.attachChild((Node) terrain);

      float duration = (System.currentTimeMillis() - start) / 1000.0f;
      System.out.println("Load took " + duration + " seconds");
    } catch (Exception e) {
    }
  }
示例#3
0
  @Override
  public void simpleUpdate(float tpf) {
    if (loading) {
      if (loading_frames == 0) {
        if (game.isMultiplayer() && client.allConnected() == false) {
          return;
        }
      }

      if (loading_frames == 5) {
        if (game.isMultiplayer() && client.allLoaded() == false) {
          return;
        }
      }

      loading(loading_frames);
      loading_frames++;
    } else {

      loops = 0;

      while (System.currentTimeMillis() > next_game_tick
          && loops < MAX_FRAMESKIP
          && (game.isMultiplayer() == false || client.canContinue())) {

        if (game.isMultiplayer()) {
          client.update();
        }

        Timer.update(GAME_TPF);
        game.update(GAME_TPF);

        next_game_tick += SKIP_TICKS;
        loops++;
      }

      camera.update(tpf);
      listener.setLocation(cam.getLocation());
      listener.setRotation(cam.getRotation());
      gui.update(tpf); // nur wegen Kamera auf Minimap
    }
  }
示例#4
0
  @Override
  public void destroy() {
    super.destroy();

    if (client != null) {
      client.close();
    }

    if (server != null) {
      server.close();
    }

    game.getFogOfWar().destroy();
  }
示例#5
0
  public void loading(int pos) {
    if (pos == 0) {
      camera = new RTSCamera(getCamera());
      camera.registerWithInput(inputManager);

      loadingScreen.setProgress(0.1f, "Making Light");
    } else if (pos == 1) {

      loadShadow();
      loadLight();

      loadingScreen.setProgress(0.2f, "Loading Terrain");

    } else if (pos == 2) {
      reflectNode = new Node("reflect");
      rootNode.attachChild(reflectNode);
      nonreflectNode = new Node("non reflect");
      rootNode.attachChild(nonreflectNode);

      clickableNode = new Node("clickable");
      reflectNode.attachChild(clickableNode);
      //  clickableNode.attachChild(createTerrain());
      loadTerrain();
      loadWater();

      camera.addTerrain(terrain);
      camera.addWater(water);

      loadingScreen.setProgress(0.6f, "Loading Doodads");
    } else if (pos == 3) {
      loadDoodads();
      loadingScreen.setProgress(0.8f, "Init Game");
    } else if (pos == 4) {

      game.init();

      // gui=new GUI(game);

      game.getMyGame().init(game);

      if (game.isMultiplayer()) {
        client.finishedLoading();
      }

      loadingScreen.setProgress(1f, "Finished Loading");
    } else if (pos == 5) {
      loadingScreen.clear();
      camera.enable();

      gui = new GUI(game);
      gui.init();

      playerInput = new PlayerInput(game);
      // important input after nifty

      next_game_tick = System.currentTimeMillis();

      Timer.init();
      loading = false;
    }
  }