Ejemplo n.º 1
0
  public void update(final GameContainer c, final int delta) {
    if (!active) {
      return;
    }

    final int centerX = c.getWidth() >> 1;
    final int centerY = c.getHeight() >> 1;

    final int offX = (centerX - origin.getDcX()) + dX;
    final int offY = (centerY - origin.getDcY()) + dY;

    final Avatar av = World.getAvatar();
    if (av != null) {
      glueAvatarToOrigin(av);
      corridor.setCorridor(av);
    }

    Camera.getInstance().setViewport(-offX, -offY, c.getWidth(), c.getHeight());
    Camera.getInstance().clearDirtyAreas();

    if (legacyRendering) {
      Camera.getInstance().markEverythingDirty();
    }

    synchronized (display) {
      for (final Rectangle rect : removedAreaList) {
        Camera.getInstance().markAreaDirty(rect);
      }
      synchronized (GameMap.LIGHT_LOCK) {
        while (true) {
          final MapInteractionEvent event = eventQueue.poll();
          if (event == null) {
            break;
          }

          for (int i = display.size() - 1; i >= 0; i--) {
            if (display.get(i).processEvent(c, delta, event)) {
              break;
            }
          }
        }

        // update the items
        for (int i = 0, displaySize = display.size(); i < displaySize; i++) {
          display.get(i).update(c, delta);
        }
      }
    }

    if (fadeOutColor.getAlpha() > 0) {
      fadeOutColor.a = AnimationUtility.approach(fadeOutColor.getAlpha(), 0, 0, 255, delta) / 255.f;
    }
  }
Ejemplo n.º 2
0
  /**
   * Implementation of the core rendering function that just renders the map to the assigned graphic
   * context.
   *
   * @param g the graphics context used for the render operation
   */
  private void renderImpl(final Graphics g) {
    final Camera camera = Camera.getInstance();

    g.pushTransform();

    g.translate(-camera.getViewportOffsetX(), -camera.getViewportOffsetY());
    Camera.getInstance().clearDirtyAreas(g);

    synchronized (display) {
      synchronized (GameMap.LIGHT_LOCK) {
        // draw all items
        for (int i = 0, displaySize = display.size(); i < displaySize; i++) {
          display.get(i).draw(g);
        }
      }
    }

    g.popTransform();
  }
Ejemplo n.º 3
0
  /**
   * Scroll map
   *
   * @param x
   * @param y
   */
  @Override
  public void setPosition(final int x, final int y, final int z) {
    if ((dX == x) && (dY == y) && (dL == z)) {
      return;
    }

    dX = x;
    dY = y;
    dL = z;

    Camera.getInstance().markEverythingDirty();

    // Gui.getInstance().getManager().notifyMovement();
  }
Ejemplo n.º 4
0
 /**
  * Move the map origin to a new location
  *
  * @param location
  */
 public void setLocation(final Location location) {
   // origin.setSC(location.scX, location.scY, 0);
   origin.set(location);
   ani.stop();
   final Avatar avatar = World.getAvatar();
   if (avatar != null) {
     avatar.animationFinished(false);
   }
   elevation = World.getMap().getElevationAt(origin);
   dX = 0;
   dY = 0;
   dL = -elevation;
   Camera.getInstance().markEverythingDirty();
 }
Ejemplo n.º 5
0
  /**
   * Render all visible map items
   *
   * @param g the graphics component that is used to render the screen
   * @param c the game container the map is rendered in
   */
  public void render(final Graphics g, final GameContainer c) {
    if (!active) {
      return;
    }

    if (legacyRendering) {
      renderImpl(g);
    } else {
      Graphics usedGraphics = g;
      if (gameScreenImage == null) {
        try {
          gameScreenImage = new Image(c.getWidth(), c.getHeight(), SGL.GL_LINEAR);
        } catch (SlickException e) {
          legacyRendering = true;
          LOGGER.warn("Rendering to texture fails. Using legacy direct rendering.");
          render(g, c);
          return;
        }
      }

      try {
        usedGraphics = gameScreenImage.getGraphics();
      } catch (SlickException e) {
        legacyRendering = true;
        LOGGER.warn("Fetching render to texture context failed. Switching to legacy rendering.");
        render(g, c);
        return;
      }

      renderImpl(usedGraphics);

      if (gameScreenImage != null) {
        if (fogShader == null) {
          try {
            fogShader =
                ShaderProgram.loadProgram(
                    "illarion/client/graphics/shader/fog.vert",
                    "illarion/client/graphics/shader/fog.frag");
          } catch (SlickException e) {
            LOGGER.error("Error loading shader!", e);
          }
        }

        if (fogShader != null) {
          fogShader.bind();
          fogShader.setUniform1i("tex0", 0);

          final float x = 0.5f * gameScreenImage.getTextureWidth();
          final float y = 0.5f * gameScreenImage.getTextureHeight();
          fogShader.setUniform2f("center", x, y);
          fogShader.setUniform1f(
              "density",
              World.getWeather().getFog() * ((float) gameScreenImage.getHeight() / 200.f));

          g.drawImage(gameScreenImage, 0, 0);

          fogShader.unbind();
        } else {
          g.drawImage(gameScreenImage, 0, 0);
        }
        Camera.getInstance().renderDebug(g);
      }
    }

    if (fadeOutColor.getAlpha() > 0) {
      g.setColor(fadeOutColor);
      g.setLineWidth(3.f);
      g.fillRect(0, 0, c.getWidth(), c.getHeight());
    }
  }