mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Updates to biomes
This commit is contained in:
parent
6e47e4bcd2
commit
8dee20295e
@ -4,6 +4,7 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.scaffold.engine.*;
|
import com.volmit.iris.scaffold.engine.*;
|
||||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||||
|
import com.volmit.iris.util.J;
|
||||||
import com.volmit.iris.util.PrecisionStopwatch;
|
import com.volmit.iris.util.PrecisionStopwatch;
|
||||||
import com.volmit.iris.util.RNG;
|
import com.volmit.iris.util.RNG;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -28,6 +29,9 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
@Getter
|
@Getter
|
||||||
private final EngineFramework framework;
|
private final EngineFramework framework;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final EngineEffects effects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final EngineWorldManager worldManager;
|
private final EngineWorldManager worldManager;
|
||||||
|
|
||||||
@ -47,6 +51,7 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
private boolean failing;
|
private boolean failing;
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private int cacheId;
|
private int cacheId;
|
||||||
|
private int art;
|
||||||
|
|
||||||
public IrisEngine(EngineTarget target, EngineCompound compound, int index)
|
public IrisEngine(EngineTarget target, EngineCompound compound, int index)
|
||||||
{
|
{
|
||||||
@ -61,11 +66,14 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
closed = false;
|
closed = false;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
cacheId = RNG.r.nextInt();
|
cacheId = RNG.r.nextInt();
|
||||||
|
effects = new IrisEngineEffects(this);
|
||||||
|
art = J.ar(effects::tickRandomPlayer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
|
J.car(art);
|
||||||
closed = true;
|
closed = true;
|
||||||
getWorldManager().close();
|
getWorldManager().close();
|
||||||
getFramework().close();
|
getFramework().close();
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.volmit.iris.generator;
|
||||||
|
|
||||||
|
import com.volmit.iris.scaffold.engine.Engine;
|
||||||
|
import com.volmit.iris.scaffold.engine.EngineAssignedComponent;
|
||||||
|
import com.volmit.iris.scaffold.engine.EngineEffects;
|
||||||
|
import com.volmit.iris.scaffold.engine.EnginePlayer;
|
||||||
|
import com.volmit.iris.util.KMap;
|
||||||
|
import com.volmit.iris.util.M;
|
||||||
|
import com.volmit.iris.util.PrecisionStopwatch;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
public class IrisEngineEffects extends EngineAssignedComponent implements EngineEffects {
|
||||||
|
private KMap<UUID, EnginePlayer> players;
|
||||||
|
private Semaphore limit;
|
||||||
|
|
||||||
|
public IrisEngineEffects(Engine engine) {
|
||||||
|
super(engine, "FX");
|
||||||
|
players = new KMap<>();
|
||||||
|
limit = new Semaphore(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePlayerMap() {
|
||||||
|
List<Player> pr = getEngine().getWorld().getPlayers();
|
||||||
|
for(Player i : pr)
|
||||||
|
{
|
||||||
|
Location l = i.getLocation();
|
||||||
|
boolean pcc = players.containsKey(i.getUniqueId());
|
||||||
|
if(getEngine().contains(l))
|
||||||
|
{
|
||||||
|
if(!pcc)
|
||||||
|
{
|
||||||
|
players.put(i.getUniqueId(), new EnginePlayer(getEngine(), i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(pcc)
|
||||||
|
{
|
||||||
|
players.remove(i.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(UUID i : players.k())
|
||||||
|
{
|
||||||
|
if(!pr.contains(players.get(i).getPlayer()))
|
||||||
|
{
|
||||||
|
players.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickRandomPlayer() {
|
||||||
|
if(limit.tryAcquire())
|
||||||
|
{
|
||||||
|
if(M.r(0.02))
|
||||||
|
{
|
||||||
|
updatePlayerMap();
|
||||||
|
limit.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(players.isEmpty())
|
||||||
|
{
|
||||||
|
limit.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double limitms = 1.5;
|
||||||
|
int max = players.size();
|
||||||
|
PrecisionStopwatch p = new PrecisionStopwatch();
|
||||||
|
|
||||||
|
while(max-- > 0 && M.ms() - p.getMilliseconds() < limitms)
|
||||||
|
{
|
||||||
|
players.v().getRandom().tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
limit.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ import com.volmit.iris.scaffold.parallax.ParallaxAccess;
|
|||||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.*;
|
import com.volmit.iris.util.*;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
@ -342,6 +343,8 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
|||||||
return getHeight() + getMinHeight();
|
return getHeight() + getMinHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EngineEffects getEffects();
|
||||||
|
|
||||||
public EngineCompound getCompound();
|
public EngineCompound getCompound();
|
||||||
|
|
||||||
public default boolean isStudio()
|
public default boolean isStudio()
|
||||||
@ -353,4 +356,19 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
|||||||
{
|
{
|
||||||
MultiBurst.burst.lazy(() -> getParallax().cleanup());
|
MultiBurst.burst.lazy(() -> getParallax().cleanup());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default IrisBiome getBiome(Location l)
|
||||||
|
{
|
||||||
|
return getBiome(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
default IrisRegion getRegion(Location l)
|
||||||
|
{
|
||||||
|
return getRegion(l.getBlockX(), l.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean contains(Location l)
|
||||||
|
{
|
||||||
|
return l.getBlockY() >= getMinHeight() && l.getBlockY() <= getMaxHeight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.volmit.iris.scaffold.engine;
|
||||||
|
|
||||||
|
public interface EngineEffects extends EngineComponent {
|
||||||
|
public void updatePlayerMap();
|
||||||
|
|
||||||
|
public void tickRandomPlayer();
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.volmit.iris.scaffold.engine;
|
||||||
|
|
||||||
|
import com.volmit.iris.object.IrisBiome;
|
||||||
|
import com.volmit.iris.object.IrisEffect;
|
||||||
|
import com.volmit.iris.object.IrisRegion;
|
||||||
|
import com.volmit.iris.util.J;
|
||||||
|
import com.volmit.iris.util.M;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EnginePlayer {
|
||||||
|
private final Engine engine;
|
||||||
|
private final Player player;
|
||||||
|
private IrisBiome biome;
|
||||||
|
private IrisRegion region;
|
||||||
|
private Location lastLocation;
|
||||||
|
private long lastSample;
|
||||||
|
|
||||||
|
public EnginePlayer(Engine engine, Player player)
|
||||||
|
{
|
||||||
|
this.engine = engine;
|
||||||
|
this.player = player;
|
||||||
|
lastLocation = player.getLocation().clone();
|
||||||
|
lastSample = -1;
|
||||||
|
sample();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
sample();
|
||||||
|
|
||||||
|
J.s(() -> {
|
||||||
|
if(region != null)
|
||||||
|
{
|
||||||
|
for(IrisEffect j : region.getEffects())
|
||||||
|
{
|
||||||
|
j.apply(player, getEngine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(biome != null)
|
||||||
|
{
|
||||||
|
for(IrisEffect j : biome.getEffects())
|
||||||
|
{
|
||||||
|
j.apply(player, getEngine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public long ticksSinceLastSample()
|
||||||
|
{
|
||||||
|
return M.ms() - lastSample;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sample() {
|
||||||
|
if(ticksSinceLastSample() > 55 && player.getLocation().distanceSquared(lastLocation) > 9 * 9)
|
||||||
|
{
|
||||||
|
lastLocation = player.getLocation().clone();
|
||||||
|
lastSample = M.ms();
|
||||||
|
sampleBiomeRegion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sampleBiomeRegion() {
|
||||||
|
Location l = player.getLocation();
|
||||||
|
biome = engine.getBiome(l);
|
||||||
|
region = engine.getRegion(l);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user