Exemplo n.º 1
0
  /**
   * @see
   *     org.newdawn.slick.particles.ParticleEmitter#updateParticle(org.newdawn.slick.particles.Particle,
   *     int)
   */
  @SuppressWarnings("null")
  @Override
  public void updateParticle(Particle particle, int delta) {
    particleCount++;

    // adjust the particles if required
    particle.x += adjustx;
    particle.y += adjusty;

    particle.adjustVelocity(
        windFactor.getValue(0) * 0.00005f * delta, gravityFactor.getValue(0) * 0.00005f * delta);

    float offset = particle.getLife() / particle.getOriginalLife();
    float inv = 1 - offset;
    float colOffset = 0;
    float colInv = 1;

    Color startColor = null;
    Color endColor = null;
    for (int i = 0; i < colors.size() - 1; i++) {
      ColorRecord rec1 = colors.get(i);
      ColorRecord rec2 = colors.get(i + 1);

      if ((inv >= rec1.pos) && (inv <= rec2.pos)) {
        startColor = rec1.col;
        endColor = rec2.col;

        float step = rec2.pos - rec1.pos;
        colOffset = inv - rec1.pos;
        colOffset /= step;
        colOffset = 1 - colOffset;
        colInv = 1 - colOffset;
      }
    }

    if (startColor != null) {
      float r = (startColor.r * colOffset) + (endColor.r * colInv);
      float g = (startColor.g * colOffset) + (endColor.g * colInv);
      float b = (startColor.b * colOffset) + (endColor.b * colInv);

      float a;
      if (alpha.isActive()) a = alpha.getValue(inv) / 255.0f;
      else
        a = ((startAlpha.getValue(0) / 255.0f) * offset) + ((endAlpha.getValue(0) / 255.0f) * inv);
      particle.setColor(r, g, b, a);
    }

    if (size.isActive()) {
      float s = size.getValue(inv);
      particle.setSize(s);
    } else particle.adjustSize(delta * growthFactor.getValue(0) * 0.001f);

    if (velocity.isActive()) particle.setSpeed(velocity.getValue(inv));

    if (scaleY.isActive()) particle.setScaleY(scaleY.getValue(inv));
  }
Exemplo n.º 2
0
  @Test
  public void testReplaceValue() {
    ConcurrentMap<SimpleKey, SimpleValue> map = redisson.getMap("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"));

    SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
    Assert.assertEquals("2", res.getValue());

    SimpleValue val1 = map.get(new SimpleKey("1"));
    Assert.assertEquals("3", val1.getValue());
  }
Exemplo n.º 3
0
  @Test
  public void testPutGet() {
    Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"));
    map.put(new SimpleKey("33"), new SimpleValue("44"));
    map.put(new SimpleKey("5"), new SimpleValue("6"));

    SimpleValue val1 = map.get(new SimpleKey("33"));
    Assert.assertEquals("44", val1.getValue());

    SimpleValue val2 = map.get(new SimpleKey("5"));
    Assert.assertEquals("6", val2.getValue());
  }
Exemplo n.º 4
0
  @Test
  public void testReplaceOldValueFail() {
    ConcurrentMap<SimpleKey, SimpleValue> map = redisson.getMap("simple");
    map.put(new SimpleKey("1"), new SimpleValue("2"));

    boolean res = map.replace(new SimpleKey("1"), new SimpleValue("43"), new SimpleValue("31"));
    Assert.assertFalse(res);

    SimpleValue val1 = map.get(new SimpleKey("1"));
    Assert.assertEquals("2", val1.getValue());
  }
Exemplo n.º 5
0
  /**
   * @see
   *     org.newdawn.slick.particles.ParticleEmitter#update(org.newdawn.slick.particles.ParticleSystem,
   *     int)
   */
  @Override
  public void update(ParticleSystem system, int delta) {
    this.engine = system;

    if (!adjust) {
      adjustx = 0;
      adjusty = 0;
    } else adjust = false;

    if (updateImage) {
      updateImage = false;
      try {
        image = new Image(relativePath + imageName);
      } catch (SlickException e) {
        image = null;
        Log.error(e);
      }
    }

    if (((wrapUp)
            || ((length.isEnabled()) && (timeout < 0))
            || ((emitCount.isEnabled() && (leftToEmit <= 0))))
        && (particleCount == 0)) {
      completed = true;
    }
    particleCount = 0;

    if (wrapUp) return;

    if (length.isEnabled()) {
      if (timeout < 0) return;
      timeout -= delta;
    }
    if (emitCount.isEnabled() && leftToEmit <= 0) return;

    nextSpawn -= delta;
    if (nextSpawn < 0) {
      nextSpawn = (int) spawnInterval.random();
      int count = (int) spawnCount.random();

      for (int i = 0; i < count; i++) {
        Particle p = system.getNewParticle(this, initialLife.random());
        p.setSize(initialSize.random());
        p.setPosition(x + xOffset.random(), y + yOffset.random());
        p.setVelocity(0, 0, 0);

        float dist = initialDistance.random();
        float power = speed.random();
        if ((dist != 0) || (power != 0)) {
          float s = spread.getValue(0);
          float ang = (s + angularOffset.getValue(0) - (spread.getValue() / 2)) - 90;
          float xa = (float) FastTrig.cos(Math.toRadians(ang)) * dist;
          float ya = (float) FastTrig.sin(Math.toRadians(ang)) * dist;
          p.adjustPosition(xa, ya);

          float xv = (float) FastTrig.cos(Math.toRadians(ang));
          float yv = (float) FastTrig.sin(Math.toRadians(ang));
          p.setVelocity(xv, yv, power * 0.001f);
        }

        if (image != null) p.setImage(image);

        ColorRecord start = colors.get(0);
        p.setColor(start.col.r, start.col.g, start.col.b, startAlpha.getValue(0) / 255.0f);
        p.setUsePoint(usePoints);
        p.setOriented(useOriented);

        if (emitCount.isEnabled()) {
          leftToEmit--;
          if (leftToEmit <= 0) break;
        }
      }
    }
  }