mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 00:17:15 +00:00
em
This commit is contained in:
parent
00c2a5245a
commit
6cfa593eee
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2024 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.engine.jvm;
|
||||
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
|
||||
public class VMJavaFX {
|
||||
private VolmitSender sender;
|
||||
|
||||
public VMJavaFX(VolmitSender user) {
|
||||
this.sender = user;
|
||||
|
||||
}
|
||||
|
||||
public void start() {
|
||||
try {
|
||||
// Start JavaFX in a new JVM
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(
|
||||
"java",
|
||||
"--module-path", "path/to/javafx-sdk/lib", // Set path to JavaFX SDK
|
||||
"--add-modules", "javafx.controls,javafx.fxml",
|
||||
"-jar", "path/to/javafx-application.jar"
|
||||
);
|
||||
processBuilder.inheritIO();
|
||||
processBuilder.start();
|
||||
sender.sendMessage("JavaFX application is launched!");
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("Failed to launch JavaFX application.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,24 +1,136 @@
|
||||
package com.volmit.iris.engine.service;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisEngineService;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.mobs.IrisMobDataHandler;
|
||||
import com.volmit.iris.util.mobs.IrisMobPiece;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EngineMobHandlerSVC extends IrisEngineService implements IrisMobDataHandler {
|
||||
|
||||
private int id;
|
||||
public double energy;
|
||||
private Supplier<IrisMobPiece> supplier;
|
||||
private ConcurrentLinkedQueue<IrisMobPiece> pieces;
|
||||
|
||||
public class EngineMobHandlerSVC extends IrisEngineService {
|
||||
|
||||
public EngineMobHandlerSVC(Engine engine) {
|
||||
super(engine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable(boolean hotload) {
|
||||
|
||||
this.id = engine.getCacheID();
|
||||
this.pieces = new ConcurrentLinkedQueue<>();
|
||||
this.supplier = null;
|
||||
|
||||
//new Ticker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(boolean hotload) {
|
||||
|
||||
}
|
||||
|
||||
public Ticker tick() {
|
||||
return new EngineMobHandlerSVC.Ticker(() -> {
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private class Ticker extends Looper {
|
||||
private final CountDownLatch exit = new CountDownLatch(1);
|
||||
|
||||
private Ticker(Supplier<IrisMobPiece> supplier) {
|
||||
setPriority(Thread.NORM_PRIORITY);
|
||||
start();
|
||||
Iris.debug("Started Mob Engine for: " + engine.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long loop() {
|
||||
long wait = -1;
|
||||
try {
|
||||
if (engine.isClosed() || engine.getCacheID() != id) {
|
||||
interrupt();
|
||||
}
|
||||
|
||||
PrecisionStopwatch stopwatch = new PrecisionStopwatch();
|
||||
stopwatch.begin();
|
||||
|
||||
fixEnergy();
|
||||
|
||||
|
||||
|
||||
stopwatch.end();
|
||||
double millis = stopwatch.getMilliseconds();
|
||||
int size = pieces.size();
|
||||
wait = size == 0 ? 50L : (long) Math.max(50d / size - millis, 0);
|
||||
} catch (Throwable notIgnored) {
|
||||
notIgnored.printStackTrace();
|
||||
}
|
||||
if (wait < 0) exit.countDown();
|
||||
return wait;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void on(PlayerChangedWorldEvent event) {
|
||||
if (!engine.getWorld().tryGetRealWorld()) {
|
||||
// todo Handle this
|
||||
return;
|
||||
}
|
||||
|
||||
var world = engine.getWorld().realWorld();
|
||||
if (world == null) return; //how is this even possible
|
||||
|
||||
var player = event.getPlayer();
|
||||
if (player.getWorld().equals(world)) {
|
||||
pieces.add(new IrisMobPiece(player, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFrom().equals(world)) {
|
||||
// pieces.removeIf(piece -> {
|
||||
// if (piece.getOwner().equals(player.getUniqueId())) {
|
||||
// piece.close();
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void fixEnergy() {
|
||||
energy = M.clip(energy, 1D, engine.getDimension().getEnergy().evaluate(null, engine.getData(), energy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy() {
|
||||
fixEnergy();
|
||||
return energy;
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ public class MantleCleanerSVC extends IrisEngineService {
|
||||
private static final AtomicInteger tectonicLimit = new AtomicInteger(30);
|
||||
|
||||
static {
|
||||
// todo: Redo this piece of garbage
|
||||
tectonicLimit.set(2);
|
||||
long t = getHardware.getProcessMemory();
|
||||
while (t > 200) {
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.volmit.iris.util.mobs;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
|
||||
public interface IrisMobDataHandler {
|
||||
|
||||
Engine getEngine();
|
||||
|
||||
double getEnergy();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.volmit.iris.util.mobs;
|
||||
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.service.EngineMobHandlerSVC;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import jakarta.activation.DataHandler;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class IrisMobPiece {
|
||||
@Getter
|
||||
private final Player player;
|
||||
private IrisMobDataHandler dataHandler;
|
||||
public long lastRanPlayer;
|
||||
|
||||
public IrisMobPiece(Player player, IrisMobDataHandler dh) {
|
||||
this.player = player;
|
||||
this.dataHandler = dh;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
lastRanPlayer = M.ms();
|
||||
|
||||
|
||||
|
||||
// Use the engine instance as needed, but without a direct reference
|
||||
// For example: engine.getDimension().getEnergy().evaluate(...)
|
||||
}
|
||||
|
||||
public UUID getOwner() {
|
||||
return player.getUniqueId();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user