mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Replace the Swing studio with the studio app
- Open the app from map, noise and imagemap commands and from pregeneration - Delete the Swing windows, GPU renderers and their tests - Keep tile rendering, sampling, palettes and object sources as plain logic - Open files through FileOpener instead of AWT Desktop
This commit is contained in:
1 parent
98e296b666
commit
2cfb3d8dcc
23 files changed
+551
-618
No files matched your search
@@ -28,8 +28,7 @@ import art.arcane.volmlib.util.director.annotations.Director;
|
||||
import art.arcane.volmlib.util.director.annotations.Param;
|
||||
import art.arcane.iris.localization.C;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
|
||||
|
||||
import art.arcane.iris.localization.IrisLanguage;
|
||||
@@ -51,15 +50,10 @@ public class CommandEdit implements DirectorExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
if (!FileOpener.isDesktopAvailable()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_OPEN_FILES_HEADLESS_ENVIRONMENTS));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Desktop.isDesktopSupported()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_DESKTOP_IS_NOT_SUPPORTED_BY_THIS_ENVIRONMENT));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,7 +68,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(biome.getLoadFile());
|
||||
FileOpener.open(biome.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE, MessageArgument.untrusted("value", biome.getTypeName()), MessageArgument.untrusted("value2", biome.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
@@ -92,7 +86,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM_2));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(region.getLoadFile());
|
||||
FileOpener.open(region.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE_2, MessageArgument.untrusted("value", region.getTypeName()), MessageArgument.untrusted("value2", region.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
@@ -110,7 +104,7 @@ public class CommandEdit implements DirectorExecutor {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_CANNOT_FIND_FILE_PERHAPS_IT_WAS_NOT_LOADED_DIRECTLY_FROM_3));
|
||||
return;
|
||||
}
|
||||
Desktop.getDesktop().open(dimension.getLoadFile());
|
||||
FileOpener.open(dimension.getLoadFile());
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_EDIT_OPENING_VSCODE_3, MessageArgument.untrusted("value", dimension.getTypeName()), MessageArgument.untrusted("value2", dimension.getLoadFile().getName().split("\\Q.\\E")[0])));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
@@ -25,9 +25,6 @@ import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.bridge.StudioBridge;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
import art.arcane.iris.studio.bridge.StudioWindow;
|
||||
import art.arcane.iris.studio.map.MapWindow;
|
||||
import art.arcane.iris.studio.map.PaletteExplorerStart;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.workspace.IrisProject;
|
||||
import art.arcane.iris.studio.workspace.IrisCodeWorkspace;
|
||||
@@ -271,16 +268,12 @@ public class CommandStudio implements DirectorExecutor {
|
||||
|
||||
@Director(description = "Open the noise explorer (External GUI)", descriptionKey = "iris.director.commandstudio.director.open_noise_explorer_external_gui", aliases = {"nmap"})
|
||||
public void noise(
|
||||
@Param(description = "Optional pack generator to preview", descriptionKey = "iris.director.commandstudio.param.optional_pack_generator_preview", defaultValue = "null", contextual = true, contextualOverride = true)
|
||||
IrisGenerator generator,
|
||||
@Param(description = "The seed to preview the generator with", descriptionKey = "iris.director.commandstudio.param.seed_preview_generator_with", defaultValue = "12345")
|
||||
long seed
|
||||
@Param(name = "world", description = "The Iris world whose pack the noise explorer reads", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) return;
|
||||
VolmitSender commandSender = sender();
|
||||
UUID openerId = commandSender.isPlayer() ? commandSender.player().getUniqueId() : null;
|
||||
MapWindow.NoiseSelection selection = new MapWindow.NoiseSelection(generator == null ? null : generator.getLoadKey(), generator, seed);
|
||||
withPlayerContext(opener -> openNoiseAtPlayer(commandSender, openerId, opener, selection));
|
||||
if (openStudioApp(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_NOISE_EXPLORER));
|
||||
}
|
||||
}
|
||||
|
||||
@Director(description = "Open the image-map studio (External GUI)", descriptionKey = "iris.director.commandstudio.director.open_image_map_studio_external_gui", aliases = {"imap"})
|
||||
@@ -288,16 +281,9 @@ public class CommandStudio implements DirectorExecutor {
|
||||
@Param(name = "world", description = "The Iris world whose active pack receives image-map exports", descriptionKey = "iris.director.commandstudio.param.world_open_image_map_studio", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) {
|
||||
return;
|
||||
if (openStudioApp(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_IMAGE_MAP_STUDIO));
|
||||
}
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
}
|
||||
|
||||
requestMapStart(world, MapWindow::openImageMaps);
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_IMAGE_MAP_STUDIO));
|
||||
}
|
||||
|
||||
@Director(description = "Show loot if a chest were right here", descriptionKey = "iris.director.commandstudio.director.show_loot_if_chest_were_right_here", origin = DirectorOrigin.PLAYER, sync = true)
|
||||
@@ -429,15 +415,9 @@ public class CommandStudio implements DirectorExecutor {
|
||||
@Param(name = "world", description = "The world to open the generator for", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (noGUI()) return;
|
||||
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
if (openStudioApp(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP));
|
||||
}
|
||||
|
||||
requestMapStart(world, MapWindow::openMap);
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP));
|
||||
}
|
||||
|
||||
@Director(description = "Open the Iris Studio app on a world", descriptionKey = "iris.director.commandstudio.director.render_world_map_external_gui", aliases = "app")
|
||||
@@ -445,9 +425,16 @@ public class CommandStudio implements DirectorExecutor {
|
||||
@Param(name = "world", description = "The world to open the generator for", descriptionKey = "iris.director.commandstudio.param.world_open_generator", contextual = true, contextualOverride = true)
|
||||
World world
|
||||
) {
|
||||
if (openStudioApp(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP));
|
||||
}
|
||||
}
|
||||
|
||||
/** Opens the app on the world, or logs its link when no app is set up; false, after telling the sender why, when it could not. */
|
||||
private boolean openStudioApp(World world) {
|
||||
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
UUID openerId = sender().isPlayer() ? player().getUniqueId() : null;
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(world);
|
||||
@@ -456,60 +443,10 @@ public class CommandStudio implements DirectorExecutor {
|
||||
if (!StudioWindow.show(bridge)) {
|
||||
IrisLogging.info("Iris Studio link for %s: %s", world.getName(), bridge.link());
|
||||
}
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_MAP));
|
||||
return true;
|
||||
} catch (IOException error) {
|
||||
IrisLogging.warn("Could not open the studio bridge: %s", error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// The map opens where the player stands when they are in that world, otherwise at the world origin.
|
||||
private PaletteExplorerStart mapStartIn(World world, Player opener, UUID openerId) {
|
||||
Location center = opener != null && opener.getWorld().equals(world) ? opener.getLocation() : null;
|
||||
return new PaletteExplorerStart(
|
||||
IrisToolbelt.access(world).getEngine(),
|
||||
world.getUID(),
|
||||
openerId,
|
||||
null,
|
||||
center == null ? 0D : center.getX(),
|
||||
center == null ? 0D : center.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
private void requestMapStart(World world, Consumer<PaletteExplorerStart> launch) {
|
||||
UUID openerId = sender().isPlayer() ? player().getUniqueId() : null;
|
||||
withPlayerContext(opener -> launch.accept(mapStartIn(world, opener, openerId)));
|
||||
}
|
||||
|
||||
private void openNoiseAtPlayer(VolmitSender commandSender, UUID openerId, Player opener, MapWindow.NoiseSelection selection) {
|
||||
World world = opener == null ? null : opener.getWorld();
|
||||
PlatformChunkGenerator worldGenerator = world == null ? null : IrisToolbelt.access(world);
|
||||
Engine engine = worldGenerator == null ? GuiHost.get().findActiveEngine() : worldGenerator.getEngine();
|
||||
if (engine == null) {
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_NEED_BE_SPECIFY_IRIS_GENERATED_WORLD));
|
||||
return;
|
||||
}
|
||||
PaletteExplorerStart start = worldGenerator == null
|
||||
? new PaletteExplorerStart(engine, null, openerId, null, 0D, 0D)
|
||||
: mapStartIn(world, opener, openerId);
|
||||
MapWindow.openNoise(start, selection);
|
||||
commandSender.sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_OPENING_NOISE_EXPLORER));
|
||||
}
|
||||
|
||||
private void withPlayerContext(Consumer<Player> action) {
|
||||
Player opener = sender().isPlayer() ? player() : null;
|
||||
if (opener == null) {
|
||||
action.accept(null);
|
||||
return;
|
||||
}
|
||||
AtomicBoolean completed = new AtomicBoolean();
|
||||
Consumer<Player> complete = player -> {
|
||||
if (completed.compareAndSet(false, true)) {
|
||||
action.accept(player);
|
||||
}
|
||||
};
|
||||
Runnable retired = () -> complete.accept(null);
|
||||
if (!J.runEntity(opener, () -> complete.accept(opener.isOnline() ? opener : null), 0, retired)) {
|
||||
retired.run();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -979,21 +916,6 @@ public class CommandStudio implements DirectorExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if server GUIs are not enabled
|
||||
*/
|
||||
private boolean noGUI() {
|
||||
if (!IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_YOU_MUST_HAVE_SERVER_LAUNCHED_GUIS_ENABLED_SETTINGS));
|
||||
return true;
|
||||
}
|
||||
if (!GuiHost.isAvailable()) {
|
||||
sender().sendMessage(IrisLanguage.text(BukkitCommandMessagesExtended.COMMAND_STUDIO_DESKTOP_UNAVAILABLE));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if no studio is open or the player is not in one
|
||||
*/
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeCommandSource;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockPoint;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeEditPlayer;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
import java.io.File;
|
||||
|
||||
final class ModdedEditCommands {
|
||||
@@ -110,7 +110,7 @@ final class ModdedEditCommands {
|
||||
}
|
||||
|
||||
private static int openJson(NativeCommandSource source, IrisRegistrant registrant) {
|
||||
if (!GuiHost.isAvailable() || !Desktop.isDesktopSupported()) {
|
||||
if (!GuiHost.isAvailable() || !FileOpener.isDesktopAvailable()) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_CANNOT_OPEN_FILES_HERE, MessageArgument.untrusted("value", ModdedGuiHost.guiUnavailableReason())));
|
||||
return 0;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ final class ModdedEditCommands {
|
||||
}
|
||||
File file = registrant.getLoadFile();
|
||||
try {
|
||||
Desktop.getDesktop().open(file);
|
||||
FileOpener.open(file);
|
||||
} catch (Throwable e) {
|
||||
ModdedIrisLog.error("Iris edit failed to open {}", file, e);
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_COULD_NOT_OPEN, MessageArgument.untrusted("value", file.getName()), MessageArgument.untrusted("value2", e.getClass().getSimpleName())));
|
||||
|
||||
+36
-65
@@ -23,8 +23,10 @@ import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeWorldView;
|
||||
|
||||
import art.arcane.iris.modded.ModdedIrisLog;
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.studio.map.MapWindow;
|
||||
import art.arcane.iris.studio.map.PaletteExplorerStart;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.bridge.StudioBridge;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
import art.arcane.iris.studio.bridge.StudioWindow;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.StructurePackageClosure;
|
||||
@@ -74,7 +76,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeWorld;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeProtocolPlayer;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -226,11 +228,7 @@ public final class ModdedStudioCommands {
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> noiseTree(String name) {
|
||||
return NativeCommandRegistration.literal(name)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), null, 12345L)))
|
||||
.then(NativeCommandRegistration.argument("generator", StringArgumentType.word()).suggests(GENERATOR_KEYS)
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), StringArgumentType.getString(context, "generator"), 12345L)))
|
||||
.then(NativeCommandRegistration.argument("seed", LongArgumentType.longArg())
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource(), StringArgumentType.getString(context, "generator"), LongArgumentType.getLong(context, "seed"))))));
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> noise(context.getSource())));
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<NativeCommandSource> mapTree(String name) {
|
||||
@@ -243,85 +241,58 @@ public final class ModdedStudioCommands {
|
||||
.executes(ModdedCommandTree.localized((CommandContext<NativeCommandSource> context) -> imageMap(context.getSource())));
|
||||
}
|
||||
|
||||
private static int noise(NativeCommandSource source, String generatorKey, long seed) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
if (engine != null) {
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
}
|
||||
Engine mapEngine = engine != null ? engine : GuiHost.get().findActiveEngine();
|
||||
if ((generatorKey == null || generatorKey.isBlank()) && mapEngine != null) {
|
||||
MapWindow.openNoise(mapStart(mapEngine, source.player()), new MapWindow.NoiseSelection(null, null, seed));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_ON_SERVER_DISPLAY));
|
||||
return 1;
|
||||
}
|
||||
private static int noise(NativeCommandSource source) {
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_THIS_DIMENSION_IS_NOT_GENERATED_BY_IRIS_RUN_IRIS_STUDIO));
|
||||
return 0;
|
||||
}
|
||||
IrisGenerator generator = engine.getData().getGeneratorLoader().load(generatorKey.trim());
|
||||
if (generator == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_UNKNOWN_GENERATOR_PACK, MessageArgument.untrusted("generatorKey", generatorKey), MessageArgument.untrusted("value", engine.getDimension().getLoadKey())));
|
||||
return 0;
|
||||
}
|
||||
String selectedGeneratorKey = generatorKey.trim();
|
||||
MapWindow.openNoise(mapStart(engine, source.player()), new MapWindow.NoiseSelection(selectedGeneratorKey, generator, seed));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_GENERATOR_SEED, MessageArgument.untrusted("value", generatorKey.trim()), MessageArgument.untrusted("seed", seed)));
|
||||
return 1;
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_NOISE_EXPLORER_ON_SERVER_DISPLAY));
|
||||
}
|
||||
|
||||
private static int map(NativeCommandSource source) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_THIS_DIMENSION_IS_NOT_GENERATED_BY_IRIS_STAND_IRIS_STUDIO));
|
||||
return 0;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
MapWindow.openMap(mapStart(engine, player));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_VISION_MAP_ON_SERVER_DISPLAY, MessageArgument.untrusted("value", level.name())));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Modded worlds have no Bukkit world id; the map finds the engine again through the bound GUI context.
|
||||
private static PaletteExplorerStart mapStart(Engine engine, NativeProtocolPlayer player) {
|
||||
IrisWorld world = engine.getWorld();
|
||||
NativeWorld level = world == null ? null : world.platformWorld();
|
||||
boolean inWorld = player != null && player.connected() && level != null && player.inWorld(level);
|
||||
return new PaletteExplorerStart(engine, null, player == null ? null : player.id(), null,
|
||||
inWorld ? player.x() : 0D, inWorld ? player.z() : 0D);
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_VISION_MAP_ON_SERVER_DISPLAY, MessageArgument.untrusted("value", source.world().name())));
|
||||
}
|
||||
|
||||
private static int imageMap(NativeCommandSource source) {
|
||||
NativeWorld level = source.world();
|
||||
Engine engine = IrisModdedCommands.engineFor(level);
|
||||
Engine engine = IrisModdedCommands.engineFor(source.world());
|
||||
if (engine == null) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_IMAGE_MAP_REQUIRES_IRIS_DIMENSION
|
||||
));
|
||||
return 0;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
return openStudioApp(source, engine, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_IMAGE_MAP_STUDIO_ON_SERVER_DISPLAY,
|
||||
MessageArgument.untrusted("value", source.world().name())
|
||||
));
|
||||
}
|
||||
|
||||
/** Opens the studio app on the source's world, or logs its link when no app is set up. */
|
||||
private static int openStudioApp(NativeCommandSource source, Engine engine, String openedMessage) {
|
||||
if (GuiHost.isDesktopSuppressed()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
NativeWorld level = source.world();
|
||||
NativeProtocolPlayer player = source.player();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, player == null ? null : player.id());
|
||||
MapWindow.openImageMaps(mapStart(engine, player));
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(
|
||||
ModdedCommandMessages.MODDED_STUDIO_COMMANDS_OPENING_IMAGE_MAP_STUDIO_ON_SERVER_DISPLAY,
|
||||
MessageArgument.untrusted("value", level.name())
|
||||
));
|
||||
UUID openerId = player == null ? null : player.id();
|
||||
ModdedGuiHost.bindContext(worldView(source.server(), level), engine, openerId);
|
||||
try {
|
||||
StudioBridge bridge = StudioBridges.open(level.name(), () -> engine, openerId);
|
||||
if (!StudioWindow.show(bridge)) {
|
||||
IrisLogging.info("Iris Studio link for %s: %s", level.name(), bridge.link());
|
||||
}
|
||||
} catch (IOException error) {
|
||||
IrisModdedCommands.fail(source, "Could not open the studio bridge: " + error.getMessage());
|
||||
return 0;
|
||||
}
|
||||
IrisModdedCommands.ok(source, openedMessage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -349,12 +320,12 @@ public final class ModdedStudioCommands {
|
||||
if (!open) {
|
||||
return 1;
|
||||
}
|
||||
if (!GuiHost.isAvailable() || !Desktop.isDesktopSupported()) {
|
||||
if (!GuiHost.isAvailable() || !FileOpener.isDesktopAvailable()) {
|
||||
IrisModdedCommands.fail(source, guiUnavailableMessage());
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
Desktop.getDesktop().open(workspace);
|
||||
FileOpener.open(workspace);
|
||||
} catch (Throwable e) {
|
||||
ModdedIrisLog.error("Iris workspace open failed for {}", workspace, e);
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.MODDED_STUDIO_COMMANDS_COULD_NOT_OPEN, MessageArgument.untrusted("value", workspace.getName()), MessageArgument.untrusted("value2", e.getClass().getSimpleName())));
|
||||
|
||||
@@ -25,7 +25,8 @@ import art.arcane.iris.spi.IrisLogging;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import art.arcane.iris.studio.workspace.FileOpener;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Data
|
||||
@@ -64,7 +65,7 @@ public abstract class IrisRegistrant {
|
||||
|
||||
public File openInVSCode() {
|
||||
try {
|
||||
Desktop.getDesktop().open(getLoadFile());
|
||||
FileOpener.open(getLoadFile());
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -35,6 +34,7 @@ final class SchemaRegistryCatalog {
|
||||
/** Namespaced key or family/namespace prefix: "minecraft:village_plains", "minecraft:village", "nova_structures:". */
|
||||
static final String VANILLA_STRUCTURE_PREFIX_PATTERN = "^[a-z0-9_.-]+:[a-z0-9_./-]*$";
|
||||
private static final String MINECRAFT_NAMESPACE = "minecraft:";
|
||||
private static final String[] LOGICAL_FONT_FAMILIES = {"Dialog", "DialogInput", "Monospaced", "SansSerif", "Serif"};
|
||||
private static volatile JSONArray fontTypes;
|
||||
private final SchemaBuilder builder;
|
||||
private JSONArray potionTypes;
|
||||
@@ -44,18 +44,13 @@ final class SchemaRegistryCatalog {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Font families are only used for schema completion. Enumerating them touches AWT, which can fail outright on a
|
||||
* headless or mod-loader JVM - a failure degrades to no completion, never to a broken schema.
|
||||
*/
|
||||
/** The logical font families every Java runtime has; listing the installed ones would need AWT, which headless and mod-loader JVMs may lack. */
|
||||
static JSONArray fontTypes() {
|
||||
JSONArray cached = fontTypes;
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
JSONArray built = CapabilityProbe.attempt("java.awt font families",
|
||||
() -> new JSONArray(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()),
|
||||
new JSONArray());
|
||||
JSONArray built = new JSONArray(LOGICAL_FONT_FAMILIES);
|
||||
fontTypes = built;
|
||||
return built;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,14 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.map.StudioAssets;
|
||||
import art.arcane.iris.studio.map.StudioHover;
|
||||
import art.arcane.iris.studio.imagemap.ImageMapPreviews;
|
||||
import art.arcane.iris.studio.map.PalettePatterns;
|
||||
import art.arcane.iris.studio.noise.NoiseSources;
|
||||
import art.arcane.iris.studio.noise.NoiseTile;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
import art.arcane.iris.studio.view.GuiMarker;
|
||||
import art.arcane.iris.studio.view.PregenRenderSnapshot;
|
||||
import art.arcane.iris.studio.view.PregeneratorJob;
|
||||
import art.arcane.volmlib.util.function.NoiseProvider;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
@@ -78,6 +81,7 @@ public final class StudioBridge implements AutoCloseable {
|
||||
private static final double LARGEST_BLOCKS_PER_PIXEL = 4_096D;
|
||||
private static final double SMALLEST_NOISE_BLOCKS_PER_PIXEL = 1D / 64D;
|
||||
private static final int LARGEST_PATTERN_BLOCKS_PER_COLUMN = 64;
|
||||
private static final int DEFAULT_IMAGE_MAP_PREVIEW_PIXELS = 768;
|
||||
private static final ModuleViewInfo PALETTES_VIEW = new ModuleViewInfo("iris:terrain/palettes", "Palettes",
|
||||
"The blocks each biome's palette layers place");
|
||||
private static final long DROPPED_TILE_KEPT_MINUTES = 10;
|
||||
@@ -118,7 +122,12 @@ public final class StudioBridge implements AutoCloseable {
|
||||
new ViewInfo("decorator-load", "Decorator load", "Configuration estimate of decorator chance and stacks, not measured performance",
|
||||
GROUP_DIAGNOSTICS, "Diagnostics"),
|
||||
new ViewInfo("layer-load", "Layer load", "Configuration estimate of biome layer count, not measured performance",
|
||||
GROUP_DIAGNOSTICS, "Diagnostics"));
|
||||
GROUP_DIAGNOSTICS, "Diagnostics"),
|
||||
new ViewInfo("noise", "Noise", "The pack's generators and the built-in noise styles, from above or as terrain",
|
||||
"GENERATORS", "Generators"),
|
||||
new ViewInfo("pregen", "Pregeneration", "The chunks of the running pregeneration as they are generated, with its progress", GROUP_WORLD, "World"),
|
||||
new ViewInfo("imageMaps","Image maps", "Terrain height, biomes or masks painted from a PNG, previewed over the world area they cover",
|
||||
"GENERATORS", "Generators"));
|
||||
|
||||
private final StudioWorld world;
|
||||
private final String token;
|
||||
@@ -240,6 +249,12 @@ public final class StudioBridge implements AutoCloseable {
|
||||
case "patterns" -> sendJson(exchange, STATUS_OK, List.of(PALETTES_VIEW));
|
||||
case "pattern-entries" -> sendJson(exchange, STATUS_OK, patternEntries(get(exchange).engine(), query));
|
||||
case "pattern" -> sendBytes(exchange, "application/octet-stream", pattern(get(exchange).engine(), query));
|
||||
case "pregen" -> sendJson(exchange, STATUS_OK, pregenStatus(exchange));
|
||||
case "pregen-map" -> sendBytes(exchange, "image/png", pregenMap(exchange));
|
||||
case "pregen-pause" -> sendJson(exchange, STATUS_OK, pregenPause(exchange));
|
||||
case "image-maps" -> sendJson(exchange, STATUS_OK, ImageMapPreviews.entries(get(exchange).engine()));
|
||||
case "image-map" -> sendJson(exchange, STATUS_OK, profiling(() -> ImageMapPreviews.details(get(exchange).engine(), query.text("key"))));
|
||||
case "image-map-preview" -> sendBytes(exchange, "image/png", imageMapPreview(get(exchange).engine(), query));
|
||||
case "saved-worlds" -> sendJson(exchange, STATUS_OK, List.of());
|
||||
case "events" -> streamEvents(exchange);
|
||||
case "teleport" -> teleport(exchange, query);
|
||||
@@ -339,6 +354,40 @@ public final class StudioBridge implements AutoCloseable {
|
||||
return tile.encode(gson);
|
||||
}
|
||||
|
||||
private static PregenStatus pregenStatus(HttpExchange exchange) {
|
||||
requireMethod(exchange, "GET");
|
||||
PregeneratorJob job = PregeneratorJob.getInstance();
|
||||
if (job == null) {
|
||||
return new PregenStatus(false, null);
|
||||
}
|
||||
return new PregenStatus(true, job.renderSnapshot());
|
||||
}
|
||||
|
||||
private static byte[] pregenMap(HttpExchange exchange) {
|
||||
requireMethod(exchange, "GET");
|
||||
PregeneratorJob job = PregeneratorJob.getInstance();
|
||||
if (job == null) {
|
||||
throw new RequestError(STATUS_NOT_FOUND, "No pregeneration is running");
|
||||
}
|
||||
return job.renderMapState().png();
|
||||
}
|
||||
|
||||
private static MessageBody pregenPause(HttpExchange exchange) {
|
||||
requireMethod(exchange, "POST");
|
||||
if (!PregeneratorJob.pauseResume()) {
|
||||
throw new RequestError(STATUS_NOT_FOUND, "No pregeneration to pause or resume");
|
||||
}
|
||||
return new MessageBody(PregeneratorJob.isPaused() ? "Paused" : "Running");
|
||||
}
|
||||
|
||||
private static byte[] imageMapPreview(Engine engine, Query query) {
|
||||
try {
|
||||
return profiling(() -> ImageMapPreviews.preview(engine, query.text("key"), query.whole("size", DEFAULT_IMAGE_MAP_PREVIEW_PIXELS)));
|
||||
} catch (IllegalArgumentException refused) {
|
||||
throw new RequestError(STATUS_BAD_REQUEST, refused.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PalettePatterns.Entry> patternEntries(Engine engine, Query query) {
|
||||
requirePalettesView(query);
|
||||
return PalettePatterns.entries(engine);
|
||||
@@ -657,6 +706,10 @@ public final class StudioBridge implements AutoCloseable {
|
||||
boolean parts, StudioProfiles.Sizes sizes, boolean form) {
|
||||
}
|
||||
|
||||
/** @param snapshot null while no pregeneration runs */
|
||||
private record PregenStatus(boolean active, PregenRenderSnapshot snapshot) {
|
||||
}
|
||||
|
||||
/** A view the studio lists beside the scene and pattern views. */
|
||||
private record ModuleViewInfo(String id, String label, String description) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 art.arcane.iris.studio.imagemap;
|
||||
|
||||
import art.arcane.iris.generation.image.CompiledIrisImageMap;
|
||||
import art.arcane.iris.generation.image.IrisImageMap;
|
||||
import art.arcane.iris.generation.image.IrisImageMapOrigin;
|
||||
import art.arcane.iris.generation.image.IrisImageMapRotation;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.studio.workspace.ImageMapStudioExporter;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/** The pack's image-map presets as the studio lists, describes and previews them over the world area they cover. */
|
||||
public final class ImageMapPreviews {
|
||||
private static final int BACKGROUND_COLOR = 0x252936;
|
||||
private static final int MAP_ERROR_COLOR = 0xFF3DA8;
|
||||
private static final int SMALLEST_PREVIEW_PIXELS = 64;
|
||||
private static final int LARGEST_PREVIEW_PIXELS = 2048;
|
||||
|
||||
private ImageMapPreviews() {
|
||||
}
|
||||
|
||||
public record Entry(String key, String name, String group, int variants) {
|
||||
}
|
||||
|
||||
/** @param bounds the world area the map covers: minimum X, minimum Z, maximum X, maximum Z */
|
||||
public record Details(String key, String type, String source, int width, int height, double blocksPerPixel, double[] bounds,
|
||||
List<String> facts) {
|
||||
}
|
||||
|
||||
public static List<Entry> entries(Engine engine) {
|
||||
String[] keys = engine.getData().getImageMapLoader().getPossibleKeys();
|
||||
if (keys == null) {
|
||||
return List.of();
|
||||
}
|
||||
return Arrays.stream(keys).sorted().map(key -> new Entry(key, key.substring(key.lastIndexOf('/') + 1), folderOf(key), 1)).toList();
|
||||
}
|
||||
|
||||
public static Details details(Engine engine, String key) throws IOException {
|
||||
Loaded loaded = load(engine, key);
|
||||
IrisImageMap definition = loaded.definition();
|
||||
List<String> facts = new ArrayList<>();
|
||||
facts.add("Source " + definition.getSource() + ".png, " + loaded.compiled().getSourceWidth() + " × " + loaded.compiled().getSourceHeight() + " pixels");
|
||||
facts.add(definition.getBlocksPerPixel() + " blocks per pixel");
|
||||
if (definition.getType().name().endsWith("HEIGHT")) {
|
||||
facts.add("Heights " + definition.getMinimumHeight() + " to " + definition.getMaximumHeight());
|
||||
}
|
||||
if (loaded.compiled().getClippedPixelCount() > 0) {
|
||||
facts.add(loaded.compiled().getClippedPixelCount() + " pixels clipped to the height range");
|
||||
}
|
||||
if (loaded.compiled().getUnknownColorPixelCount() > 0) {
|
||||
facts.add(loaded.compiled().getUnknownColorPixelCount() + " pixels of a colour the legend does not name");
|
||||
}
|
||||
return new Details(key, readable(definition.getType().name()), definition.getSource(), loaded.compiled().getSourceWidth(),
|
||||
loaded.compiled().getSourceHeight(), definition.getBlocksPerPixel(), worldBounds(loaded), List.copyOf(facts));
|
||||
}
|
||||
|
||||
/** A PNG of the world area the map covers, {@code pixels} across its longer side. */
|
||||
public static byte[] preview(Engine engine, String key, int pixels) throws IOException {
|
||||
if (pixels < SMALLEST_PREVIEW_PIXELS || pixels > LARGEST_PREVIEW_PIXELS) {
|
||||
throw new IllegalArgumentException("A preview is " + SMALLEST_PREVIEW_PIXELS + " to " + LARGEST_PREVIEW_PIXELS + " pixels");
|
||||
}
|
||||
Loaded loaded = load(engine, key);
|
||||
double[] bounds = worldBounds(loaded);
|
||||
double spanX = bounds[2] - bounds[0];
|
||||
double spanZ = bounds[3] - bounds[1];
|
||||
double blocksPerPixel = Math.max(spanX, spanZ) / pixels;
|
||||
int width = Math.max(1, (int) Math.round(spanX / blocksPerPixel));
|
||||
int height = Math.max(1, (int) Math.round(spanZ / blocksPerPixel));
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
for (int row = 0; row < height; row++) {
|
||||
for (int column = 0; column < width; column++) {
|
||||
image.setRGB(column, row, colorAt(loaded, bounds[0] + column * blocksPerPixel, bounds[1] + row * blocksPerPixel));
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", bytes);
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
|
||||
private static int colorAt(Loaded loaded, double worldX, double worldZ) {
|
||||
CompiledIrisImageMap compiled = loaded.compiled();
|
||||
if (!compiled.containsWorld(worldX, worldZ)) {
|
||||
return BACKGROUND_COLOR;
|
||||
}
|
||||
try {
|
||||
return switch (loaded.definition().getType()) {
|
||||
case GRAYSCALE_HEIGHT, RGB_HEIGHT -> heightColor(compiled.sampleHeight(worldX, worldZ),
|
||||
loaded.definition().getMinimumHeight(), loaded.definition().getMaximumHeight());
|
||||
case COLOR_MAP -> targetColor(compiled.sampleTarget(worldX, worldZ));
|
||||
case BINARY_MASK, GRAYSCALE_MASK, ALPHA_MASK -> grayscale(compiled.sampleNormalized(worldX, worldZ));
|
||||
};
|
||||
} catch (RuntimeException unsampleable) {
|
||||
return MAP_ERROR_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
private static Loaded load(Engine engine, String key) throws IOException {
|
||||
IrisData data = engine.getData();
|
||||
IrisImageMap loaded = data.getImageMapLoader().load(key);
|
||||
if (loaded == null) {
|
||||
throw new NoSuchElementException("No image map " + key);
|
||||
}
|
||||
IrisImageMap definition = data.getGson().fromJson(data.getGson().toJson(loaded), IrisImageMap.class);
|
||||
File source = data.getImageLoader().findFile(definition.getSource());
|
||||
if (source == null || !source.isFile()) {
|
||||
throw new NoSuchElementException("The source PNG " + definition.getSource() + " is missing");
|
||||
}
|
||||
CompiledIrisImageMap compiled = ImageMapStudioExporter.preview(source.toPath(), definition).compiled();
|
||||
return new Loaded(definition, compiled);
|
||||
}
|
||||
|
||||
private static double[] worldBounds(Loaded loaded) {
|
||||
double[][] corners = {
|
||||
sourceToWorld(loaded.definition(), 0, 0),
|
||||
sourceToWorld(loaded.definition(), loaded.compiled().getSourceWidth(), 0),
|
||||
sourceToWorld(loaded.definition(), loaded.compiled().getSourceWidth(), loaded.compiled().getSourceHeight()),
|
||||
sourceToWorld(loaded.definition(), 0, loaded.compiled().getSourceHeight())
|
||||
};
|
||||
double[] bounds = {Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE};
|
||||
for (double[] corner : corners) {
|
||||
bounds[0] = Math.min(bounds[0], corner[0]);
|
||||
bounds[1] = Math.min(bounds[1], corner[1]);
|
||||
bounds[2] = Math.max(bounds[2], corner[0]);
|
||||
bounds[3] = Math.max(bounds[3], corner[1]);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private static double[] sourceToWorld(IrisImageMap definition, double sourceX, double sourceZ) {
|
||||
IrisImageMapOrigin origin = definition.getOrigin();
|
||||
IrisImageMapOrigin sourceOrigin = definition.getSourceOrigin();
|
||||
double x = sourceX - sourceOrigin.getX();
|
||||
double z = sourceZ - sourceOrigin.getZ();
|
||||
if (definition.isMirrorX()) {
|
||||
x = -x;
|
||||
}
|
||||
if (definition.isMirrorZ()) {
|
||||
z = -z;
|
||||
}
|
||||
double[] rotated = rotated(x, z, definition.getRotation());
|
||||
return new double[]{origin.getX() + rotated[0] * definition.getBlocksPerPixel(), origin.getZ() + rotated[1] * definition.getBlocksPerPixel()};
|
||||
}
|
||||
|
||||
private static double[] rotated(double x, double z, IrisImageMapRotation rotation) {
|
||||
return switch (rotation) {
|
||||
case DEG_0 -> new double[]{x, z};
|
||||
case DEG_90 -> new double[]{-z, x};
|
||||
case DEG_180 -> new double[]{-x, -z};
|
||||
case DEG_270 -> new double[]{z, -x};
|
||||
};
|
||||
}
|
||||
|
||||
private static int targetColor(String target) {
|
||||
if (target == null) {
|
||||
return BACKGROUND_COLOR;
|
||||
}
|
||||
int hash = target.hashCode();
|
||||
int red = 72 + Math.floorMod(hash, 152);
|
||||
int green = 72 + Math.floorMod(hash >>> 8, 152);
|
||||
int blue = 72 + Math.floorMod(hash >>> 16, 152);
|
||||
return (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
private static int heightColor(double height, double minimum, double maximum) {
|
||||
double range = maximum - minimum;
|
||||
double normalized = range == 0D ? 0.5D : Math.max(0D, Math.min(1D, (height - minimum) / range));
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
if (normalized < 0.5D) {
|
||||
double factor = normalized * 2D;
|
||||
red = 38D + (45D * factor);
|
||||
green = 77D + (111D * factor);
|
||||
blue = 132D - (42D * factor);
|
||||
} else {
|
||||
double factor = (normalized - 0.5D) * 2D;
|
||||
red = 83D + (169D * factor);
|
||||
green = 188D + (58D * factor);
|
||||
blue = 90D + (150D * factor);
|
||||
}
|
||||
return ((int) red << 16) | ((int) green << 8) | (int) blue;
|
||||
}
|
||||
|
||||
private static int grayscale(double normalized) {
|
||||
int level = (int) Math.round(Math.max(0D, Math.min(1D, normalized)) * 255D);
|
||||
return (level << 16) | (level << 8) | level;
|
||||
}
|
||||
|
||||
private static String folderOf(String key) {
|
||||
int slash = key.lastIndexOf('/');
|
||||
return slash < 0 ? "" : key.substring(0, slash);
|
||||
}
|
||||
|
||||
private static String readable(String constantName) {
|
||||
String lower = constantName.toLowerCase(Locale.ROOT).replace('_', ' ');
|
||||
return Character.toUpperCase(lower.charAt(0)) + lower.substring(1);
|
||||
}
|
||||
|
||||
private record Loaded(IrisImageMap definition, CompiledIrisImageMap compiled) {
|
||||
}
|
||||
}
|
||||
@@ -49,10 +49,8 @@ final class BlockTextures {
|
||||
private final ZipFile clientJar;
|
||||
private final MinecraftBiomeColors biomeColors;
|
||||
private final Map<String, Optional<ResolvedTexture>> resolvedTextures = new ConcurrentHashMap<>();
|
||||
private final Map<String, Optional<BlockModel>> resolvedModels = new ConcurrentHashMap<>();
|
||||
private final Map<String, Optional<BlockTexture>> faceTextures = new ConcurrentHashMap<>();
|
||||
private final Map<String, Optional<BlockTexture>> icons = new ConcurrentHashMap<>();
|
||||
private final BlockModelBuilder modelBuilder = new BlockModelBuilder(this);
|
||||
|
||||
private BlockTextures(ZipFile clientJar, MinecraftBiomeColors biomeColors) {
|
||||
this.clientJar = clientJar;
|
||||
@@ -134,13 +132,6 @@ final class BlockTextures {
|
||||
.filter(ResolvedTexture::isSideOnSprite).map(ResolvedTexture::texture);
|
||||
}
|
||||
|
||||
/**
|
||||
* What the block looks like from every side, for drawing it in 3D.
|
||||
*/
|
||||
Optional<BlockModel> model(NativeBlockState block) {
|
||||
return resolvedModels.computeIfAbsent(block.key(), modelBuilder::build);
|
||||
}
|
||||
|
||||
private static Optional<NativeBlockState> withHalf(NativeBlockState block, BlockHalf half) {
|
||||
String current = IrisProceduralBlocks.propertyValue(block, BlockHalf.PROPERTY);
|
||||
if (current == null) {
|
||||
|
||||
@@ -25,16 +25,9 @@ import java.util.OptionalInt;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
/**
|
||||
* Where an object explorer gets what it shows: the pack's object files, or the objects Iris generates from settings.
|
||||
* Both are called on the explorer's loader thread only.
|
||||
* Where the studio gets the objects it shows: the pack's object files, or the objects Iris generates from settings.
|
||||
*/
|
||||
public interface ObjectSource {
|
||||
/** What one entry is called, such as "object", for the browser's texts. */
|
||||
String noun();
|
||||
|
||||
/** What the view shows when the pack has no entries. */
|
||||
EmptyState emptyState();
|
||||
|
||||
/** The key of every entry, where a slash separates folders. */
|
||||
List<String> keys(IrisData data);
|
||||
|
||||
|
||||
@@ -27,19 +27,6 @@ import java.util.List;
|
||||
* The pack's object files, by their load keys.
|
||||
*/
|
||||
public final class PackObjectSource implements ObjectSource {
|
||||
private static final int EMPTY_ICON_SIZE = 40;
|
||||
|
||||
@Override
|
||||
public String noun() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyState emptyState() {
|
||||
return new EmptyState(MapViewIcon.large(MapView.OBJECTS, EMPTY_ICON_SIZE), "No objects yet",
|
||||
"Put the pack's .iob objects in", "objects/", "They appear here once the pack reloads.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> keys(IrisData data) {
|
||||
return Arrays.asList(data.getObjectLoader().getPossibleKeys());
|
||||
|
||||
@@ -32,25 +32,14 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Samples the map in view to measure how regions and biomes are picked; shared by the region and biome views.
|
||||
* Describes how regions and biomes are picked; shared by the region and biome views.
|
||||
*/
|
||||
final class PickMeasuring {
|
||||
static final List<InferredType> PLACED_TYPES = List.of(InferredType.LAND, InferredType.SHORE, InferredType.SEA);
|
||||
private static final int SAMPLES_PER_SIDE = 96;
|
||||
|
||||
private PickMeasuring() {
|
||||
}
|
||||
|
||||
static void forEachSample(MapCensus.ViewArea area, SampleVisitor visitor) {
|
||||
double stepX = (area.maximumX() - area.minimumX()) / SAMPLES_PER_SIDE;
|
||||
double stepZ = (area.maximumZ() - area.minimumZ()) / SAMPLES_PER_SIDE;
|
||||
for (int row = 0; row < SAMPLES_PER_SIDE; row++) {
|
||||
for (int column = 0; column < SAMPLES_PER_SIDE; column++) {
|
||||
visitor.visit(area.minimumX() + (column + 0.5D) * stepX, area.minimumZ() + (row + 0.5D) * stepZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Option regionOption(Engine engine, IrisRegion region) {
|
||||
return new Option(region.getLoadKey(), region.getName(), regionColor(engine, region), Rarity.get(region));
|
||||
}
|
||||
@@ -86,11 +75,6 @@ final class PickMeasuring {
|
||||
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface SampleVisitor {
|
||||
void visit(double x, double z);
|
||||
}
|
||||
|
||||
/**
|
||||
* The spread of the noise that picks from one of a region's biome lists.
|
||||
*/
|
||||
|
||||
@@ -42,24 +42,11 @@ import java.util.OptionalLong;
|
||||
* that declares it.
|
||||
*/
|
||||
public final class ProceduralObjectSource implements ObjectSource {
|
||||
private static final int EMPTY_ICON_SIZE = 40;
|
||||
private static final String BIOME_FOLDER = "biomes";
|
||||
private static final String REGION_FOLDER = "regions";
|
||||
|
||||
private volatile Map<String, IrisProceduralPlacement> placementsByKey = Map.of();
|
||||
|
||||
@Override
|
||||
public String noun() {
|
||||
return "procedural object";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyState emptyState() {
|
||||
return new EmptyState(MapViewIcon.large(MapView.PROCEDURAL, EMPTY_ICON_SIZE), "No procedural objects yet",
|
||||
"Add trees, ruins, formations, coral, fungi or crystals to",
|
||||
"a biome's or region's proceduralObjects", "They appear here once the pack reloads.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> keys(IrisData data) {
|
||||
Map<String, IrisProceduralPlacement> byKey = new LinkedHashMap<>();
|
||||
|
||||
@@ -18,34 +18,13 @@
|
||||
|
||||
package art.arcane.iris.studio.map.components;
|
||||
|
||||
import art.arcane.iris.studio.map.MapHost;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* One rendered square of the map. Besides its colours it remembers which biome or region and which region every pixel
|
||||
* shows, and optionally the terrain height, so highlighting, borders, shading and the legend never need a new render.
|
||||
* shows, and optionally the terrain height, so the studio can highlight, shade and count without a new render.
|
||||
* The label and height grids have a one pixel border taken from the neighbouring tiles, so edges and slopes line up
|
||||
* across tile boundaries.
|
||||
*/
|
||||
public final class MapTile {
|
||||
private static final double SHADING_EXAGGERATION = 1.2D;
|
||||
private static final double LIGHT_X = -1D;
|
||||
private static final double LIGHT_Y = 1.5D;
|
||||
private static final double LIGHT_Z = -1D;
|
||||
private static final double LIGHT_LENGTH = Math.sqrt(LIGHT_X * LIGHT_X + LIGHT_Y * LIGHT_Y + LIGHT_Z * LIGHT_Z);
|
||||
private static final double FLAT_LIGHT = LIGHT_Y / LIGHT_LENGTH;
|
||||
private static final double DARKEST_SHADE = 0.55D;
|
||||
private static final double BRIGHTEST_SHADE = 1.25D;
|
||||
private static final int DIM_TARGET = 0x1E1F22;
|
||||
private static final double DIM_AMOUNT = 0.72D;
|
||||
private static final double DIM_DESATURATION = 0.6D;
|
||||
private static final int HIGHLIGHT_EDGE = 0xFFFFFF;
|
||||
// A solid outline turns biomes that are scattered pixel by pixel into white noise, so the edge only tints.
|
||||
private static final double HIGHLIGHT_EDGE_STRENGTH = 0.55D;
|
||||
private static final int REGION_BORDER = 0x101114;
|
||||
private static final double REGION_BORDER_STRENGTH = 0.6D;
|
||||
|
||||
private final int size;
|
||||
private final double blocksPerPixel;
|
||||
private final MapLabels labels;
|
||||
@@ -55,11 +34,9 @@ public final class MapTile {
|
||||
private final short[] subjects;
|
||||
private final short[] regions;
|
||||
private final double[] heights;
|
||||
private MapStyle styledFor;
|
||||
private BufferedImage styledImage;
|
||||
|
||||
/**
|
||||
* @param colors the colour of every pixel, or null to colour the pixels by their height when they are drawn
|
||||
* @param colors the colour of every pixel, or null to colour the pixels by their height
|
||||
* @param defaultHeightRange the height colours to use until the map has measured the heights on screen
|
||||
*/
|
||||
MapTile(int size, double blocksPerPixel, MapLabels labels, MapLabels.Kind subjectKind, int[] colors,
|
||||
@@ -106,121 +83,23 @@ public final class MapTile {
|
||||
return heights[gridIndex(pixelX, pixelZ)];
|
||||
}
|
||||
|
||||
/** The pixel's plain colour as 0xRRGGBB, before any shading or highlight. */
|
||||
public int colorAt(int pixelX, int pixelZ) {
|
||||
if (colors == null) {
|
||||
return MapTileRenderer.heightColor(heightAt(pixelX, pixelZ), defaultHeightRange);
|
||||
}
|
||||
return colors[pixelZ * size + pixelX];
|
||||
}
|
||||
|
||||
public long bytes() {
|
||||
long styledBytes = (long) size * size * Integer.BYTES;
|
||||
long gridCells = (long) (size + 2) * (size + 2);
|
||||
long heightBytes = heights == null ? 0L : gridCells * Double.BYTES;
|
||||
long colorBytes = colors == null ? 0L : (long) colors.length * Integer.BYTES;
|
||||
return colorBytes + gridCells * Short.BYTES * 2L + heightBytes + styledBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tile as it looks in the given style; the last style's picture is kept, so redrawing an unchanged map is free.
|
||||
*/
|
||||
public synchronized BufferedImage image(MapStyle style) {
|
||||
if (styledImage == null || !style.equals(styledFor)) {
|
||||
styledImage = MapHost.uncachedImage(styledPixels(style), size, size);
|
||||
styledFor = style;
|
||||
}
|
||||
return styledImage;
|
||||
}
|
||||
|
||||
private int[] styledPixels(MapStyle style) {
|
||||
int[] pixels = new int[size * size];
|
||||
boolean shading = style.shading() && heights != null;
|
||||
short[] highlightGrid = highlightGrid(style.highlight());
|
||||
short highlighted = highlightGrid == null
|
||||
? MapLabels.NONE
|
||||
: labels.idOf(style.highlight().kind(), style.highlight().key());
|
||||
MapStyle.HeightRange heightRange = style.heightRange() == null ? defaultHeightRange : style.heightRange();
|
||||
for (int pixelZ = 0; pixelZ < size; pixelZ++) {
|
||||
for (int pixelX = 0; pixelX < size; pixelX++) {
|
||||
int color = colors == null
|
||||
? MapTileRenderer.heightColor(heightAt(pixelX, pixelZ), heightRange)
|
||||
: colors[pixelZ * size + pixelX];
|
||||
if (shading) {
|
||||
color = shade(color, pixelX, pixelZ);
|
||||
}
|
||||
if (highlightGrid != null) {
|
||||
color = highlight(color, highlightGrid, pixelX, pixelZ, highlighted);
|
||||
}
|
||||
if (style.regionBorders() && isRegionEdge(pixelX, pixelZ)) {
|
||||
color = blend(color, REGION_BORDER, REGION_BORDER_STRENGTH);
|
||||
}
|
||||
pixels[pixelZ * size + pixelX] = color;
|
||||
}
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
|
||||
// Lit from the north west like a relief map, so slopes read as hills and valleys at a glance.
|
||||
private int shade(int color, int pixelX, int pixelZ) {
|
||||
double slopeX = (height(pixelX + 1, pixelZ) - height(pixelX - 1, pixelZ)) / (2D * blocksPerPixel);
|
||||
double slopeZ = (height(pixelX, pixelZ + 1) - height(pixelX, pixelZ - 1)) / (2D * blocksPerPixel);
|
||||
double normalX = -slopeX * SHADING_EXAGGERATION;
|
||||
double normalZ = -slopeZ * SHADING_EXAGGERATION;
|
||||
double normalLength = Math.sqrt(normalX * normalX + 1D + normalZ * normalZ);
|
||||
double light = (normalX * LIGHT_X + LIGHT_Y + normalZ * LIGHT_Z) / (normalLength * LIGHT_LENGTH);
|
||||
double factor = Math.max(DARKEST_SHADE, Math.min(BRIGHTEST_SHADE, light / FLAT_LIGHT));
|
||||
return scale(color, factor);
|
||||
}
|
||||
|
||||
// Every view knows its regions, so a region can be highlighted in a biome view too.
|
||||
private short[] highlightGrid(MapStyle.Highlight highlight) {
|
||||
if (highlight == null) {
|
||||
return null;
|
||||
}
|
||||
if (highlight.kind() == subjectKind) {
|
||||
return subjects;
|
||||
}
|
||||
return highlight.kind() == MapLabels.Kind.REGION ? regions : null;
|
||||
}
|
||||
|
||||
private int highlight(int color, short[] grid, int pixelX, int pixelZ, short highlighted) {
|
||||
if (grid[gridIndex(pixelX, pixelZ)] != highlighted) {
|
||||
return dim(color);
|
||||
}
|
||||
boolean edge = grid[gridIndex(pixelX + 1, pixelZ)] != highlighted
|
||||
|| grid[gridIndex(pixelX - 1, pixelZ)] != highlighted
|
||||
|| grid[gridIndex(pixelX, pixelZ + 1)] != highlighted
|
||||
|| grid[gridIndex(pixelX, pixelZ - 1)] != highlighted;
|
||||
return edge ? blend(color, HIGHLIGHT_EDGE, HIGHLIGHT_EDGE_STRENGTH) : color;
|
||||
}
|
||||
|
||||
private boolean isRegionEdge(int pixelX, int pixelZ) {
|
||||
short region = regionAt(pixelX, pixelZ);
|
||||
return regions[gridIndex(pixelX + 1, pixelZ)] != region || regions[gridIndex(pixelX, pixelZ + 1)] != region;
|
||||
}
|
||||
|
||||
private double height(int pixelX, int pixelZ) {
|
||||
return heights[gridIndex(pixelX, pixelZ)];
|
||||
return colorBytes + gridCells * Short.BYTES * 2L + heightBytes;
|
||||
}
|
||||
|
||||
// Pixel coordinates run from -1 to size, the outer ring being the neighbouring tiles' edge pixels.
|
||||
private int gridIndex(int pixelX, int pixelZ) {
|
||||
return (pixelZ + 1) * (size + 2) + pixelX + 1;
|
||||
}
|
||||
|
||||
private static int dim(int color) {
|
||||
int red = (color >> 16) & 0xFF;
|
||||
int green = (color >> 8) & 0xFF;
|
||||
int blue = color & 0xFF;
|
||||
int gray = (red + green + blue) / 3;
|
||||
int desaturated = blend(color, (gray << 16) | (gray << 8) | gray, DIM_DESATURATION);
|
||||
return blend(desaturated, DIM_TARGET, DIM_AMOUNT);
|
||||
}
|
||||
|
||||
private static int scale(int color, double factor) {
|
||||
int red = Math.min(255, (int) (((color >> 16) & 0xFF) * factor));
|
||||
int green = Math.min(255, (int) (((color >> 8) & 0xFF) * factor));
|
||||
int blue = Math.min(255, (int) ((color & 0xFF) * factor));
|
||||
return (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
|
||||
static int blend(int first, int second, double amount) {
|
||||
int red = (int) Math.round(((first >> 16) & 0xFF) * (1D - amount) + ((second >> 16) & 0xFF) * amount);
|
||||
int green = (int) Math.round(((first >> 8) & 0xFF) * (1D - amount) + ((second >> 8) & 0xFF) * amount);
|
||||
int blue = (int) Math.round((first & 0xFF) * (1D - amount) + (second & 0xFF) * amount);
|
||||
return (red << 16) | (green << 8) | blue;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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
|
||||
@@ -19,29 +19,17 @@
|
||||
package art.arcane.iris.studio.view;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.desktop.QuitResponse;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/** What the studio app needs from the platform that hosts the engines, and the shutdown of what the studio opened. */
|
||||
public final class GuiHost {
|
||||
private static final AtomicBoolean DESKTOP_QUIT_GUARD_INSTALLED = new AtomicBoolean(false);
|
||||
private static final long WINDOW_CLOSE_WAIT_SECONDS = 5L;
|
||||
private static final Set<Runnable> SHUTDOWN_TASKS = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<JFrame> MANAGED_FRAMES = ConcurrentHashMap.newKeySet();
|
||||
private static volatile Provider provider = new Provider() {
|
||||
};
|
||||
private static volatile boolean desktopSuppressed = false;
|
||||
@@ -49,6 +37,7 @@ public final class GuiHost {
|
||||
private GuiHost() {
|
||||
}
|
||||
|
||||
/** Suppressed where the studio app must not open, such as inside a game client. */
|
||||
public static void suppressDesktop(boolean suppress) {
|
||||
desktopSuppressed = suppress;
|
||||
}
|
||||
@@ -88,57 +77,17 @@ public final class GuiHost {
|
||||
}
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return !desktopSuppressed && !GraphicsEnvironment.isHeadless();
|
||||
return !desktopSuppressed;
|
||||
}
|
||||
|
||||
public static void prepareFrame(JFrame frame) {
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
MANAGED_FRAMES.add(frame);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent event) {
|
||||
MANAGED_FRAMES.remove(frame);
|
||||
}
|
||||
});
|
||||
prepareServerDesktop();
|
||||
}
|
||||
|
||||
private static void prepareServerDesktop() {
|
||||
if (!isAvailable()
|
||||
|| !System.getProperty("os.name", "").toLowerCase(Locale.ROOT).contains("mac")
|
||||
|| !DESKTOP_QUIT_GUARD_INSTALLED.compareAndSet(false, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!Desktop.isDesktopSupported()) {
|
||||
return;
|
||||
}
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
if (!desktop.isSupported(Desktop.Action.APP_QUIT_HANDLER)) {
|
||||
return;
|
||||
}
|
||||
desktop.setQuitHandler((event, response) -> closeDesktopWindowsAndCancelQuit(response));
|
||||
} catch (Throwable error) {
|
||||
IrisLogging.reportError(error);
|
||||
IrisLogging.info("Unable to install the Iris desktop quit guard; use the server stop command instead of macOS Quit");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs {@code task} once the windows are closed at shutdown, for resources the windows share, such as the
|
||||
* graphics card.
|
||||
*/
|
||||
/** Runs {@code task} once the studio is closed at shutdown, for resources it shares. */
|
||||
public static void runAtShutdown(Runnable task) {
|
||||
SHUTDOWN_TASKS.add(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes every Iris window before the plugin stops, since windows would otherwise keep drawing with
|
||||
* threads and engines the shutdown takes away, then runs the shutdown tasks.
|
||||
*/
|
||||
/** Closes the studio's bridges and the app windows the server started before the plugin stops, then runs the shutdown tasks. */
|
||||
public static void shutdown() {
|
||||
closeWindows();
|
||||
StudioBridges.closeAll();
|
||||
for (Runnable task : SHUTDOWN_TASKS) {
|
||||
try {
|
||||
task.run();
|
||||
@@ -149,58 +98,26 @@ public final class GuiHost {
|
||||
SHUTDOWN_TASKS.clear();
|
||||
}
|
||||
|
||||
// Waits only so long, in case the AWT event thread is itself waiting on the server.
|
||||
private static void closeWindows() {
|
||||
if (MANAGED_FRAMES.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CountDownLatch closed = new CountDownLatch(1);
|
||||
EventQueue.invokeLater(() -> {
|
||||
try {
|
||||
for (JFrame frame : MANAGED_FRAMES) {
|
||||
frame.dispose();
|
||||
}
|
||||
} finally {
|
||||
closed.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
closed.await(WINDOW_CLOSE_WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
static void closeDesktopWindowsAndCancelQuit(QuitResponse response) {
|
||||
response.cancelQuit();
|
||||
EventQueue.invokeLater(() -> {
|
||||
for (JFrame frame : MANAGED_FRAMES) {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Outcome of a server triggered desktop gui launch request.
|
||||
* Outcome of a server triggered studio launch request.
|
||||
*/
|
||||
public enum ServerGuiLaunch {
|
||||
/**
|
||||
* The gui was asked for and a display environment exists.
|
||||
* The studio was asked for and may open.
|
||||
*/
|
||||
OPEN,
|
||||
/**
|
||||
* The gui was not asked for, or server launched guis are turned off in settings.
|
||||
* The studio was not asked for, or server launched guis are turned off in settings.
|
||||
*/
|
||||
DISABLED,
|
||||
/**
|
||||
* The gui was asked for but the jvm is headless or the desktop is suppressed.
|
||||
* The studio was asked for but the desktop is suppressed.
|
||||
*/
|
||||
UNAVAILABLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether a server triggered job may open a desktop gui. Callers must not attempt an
|
||||
* awt launch on anything other than {@link ServerGuiLaunch#OPEN}, since awt throws on a headless jvm.
|
||||
* Decides whether a server triggered job may open the studio app.
|
||||
*/
|
||||
public static ServerGuiLaunch serverGuiLaunch(boolean requested) {
|
||||
if (!requested || !IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 art.arcane.iris.studio.view;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/** The colour each state of a chunk has on the pregeneration map. */
|
||||
final class PregenChunkColors {
|
||||
static final Color GENERATING = new Color(204, 168, 107);
|
||||
static final Color GENERATED = new Color(101, 194, 149);
|
||||
static final Color EXISTS = new Color(93, 133, 112);
|
||||
static final Color NETWORK = new Color(157, 138, 176);
|
||||
static final Color NETWORK_GENERATING = new Color(129, 112, 145);
|
||||
|
||||
private PregenChunkColors() {
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
package art.arcane.iris.studio.view;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/** The pregeneration's chunks as one pixel each, scaled down when there are more than the raster holds. */
|
||||
public final class PregenMapState {
|
||||
private static final int MAX_RASTER_SIZE = 1024;
|
||||
static final Color WAITING = new Color(57, 59, 64);
|
||||
@@ -16,7 +19,6 @@ public final class PregenMapState {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int[] pixels;
|
||||
private final List<View> views = new ArrayList<>(1);
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
PregenMapState(PregenRenderSnapshot.Bounds bounds) {
|
||||
@@ -45,79 +47,29 @@ public final class PregenMapState {
|
||||
}
|
||||
int x = (int) (((long) chunkX - bounds.minX()) * width / bounds.width());
|
||||
int z = (int) (((long) chunkZ - bounds.minZ()) * height / bounds.height());
|
||||
int index = z * width + x;
|
||||
int rgb = color.getRGB();
|
||||
lock.lock();
|
||||
try {
|
||||
if (pixels[index] == rgb) {
|
||||
return;
|
||||
}
|
||||
pixels[index] = rgb;
|
||||
for (int viewIndex = 0; viewIndex < views.size(); viewIndex++) {
|
||||
View view = views.get(viewIndex);
|
||||
view.dirty.set(index);
|
||||
view.pending = true;
|
||||
}
|
||||
pixels[z * width + x] = color.getRGB();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
View attach(int[] target) {
|
||||
if (target.length != pixels.length) {
|
||||
throw new IllegalArgumentException("Map image must match the retained raster dimensions");
|
||||
}
|
||||
View view = new View(target);
|
||||
/** The map as a PNG, one pixel per raster cell. */
|
||||
public byte[] png() {
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
lock.lock();
|
||||
try {
|
||||
System.arraycopy(pixels, 0, target, 0, pixels.length);
|
||||
views.add(view);
|
||||
image.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
final class View {
|
||||
private final int[] target;
|
||||
private final BitSet dirty = new BitSet(pixels.length);
|
||||
private volatile boolean pending;
|
||||
private boolean disposed;
|
||||
|
||||
private View(int[] target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
boolean flush() {
|
||||
if (!pending) {
|
||||
return false;
|
||||
}
|
||||
lock.lock();
|
||||
try {
|
||||
if (disposed || !pending) {
|
||||
return false;
|
||||
}
|
||||
for (int index = dirty.nextSetBit(0); index >= 0; index = dirty.nextSetBit(index + 1)) {
|
||||
target[index] = pixels[index];
|
||||
}
|
||||
dirty.clear();
|
||||
pending = false;
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
lock.lock();
|
||||
try {
|
||||
disposed = true;
|
||||
pending = false;
|
||||
dirty.clear();
|
||||
views.remove(this);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(image, "png", bytes);
|
||||
} catch (IOException impossible) {
|
||||
throw new UncheckedIOException(impossible);
|
||||
}
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,9 @@ import art.arcane.iris.world.pregen.PregenSavedChunkStatus;
|
||||
import art.arcane.iris.world.pregen.PregenTask;
|
||||
import art.arcane.iris.world.pregen.PregeneratorMethod;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.studio.bridge.StudioBridge;
|
||||
import art.arcane.iris.studio.bridge.StudioBridges;
|
||||
import art.arcane.iris.studio.bridge.StudioWindow;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
|
||||
import art.arcane.volmlib.util.format.MemoryMonitor;
|
||||
@@ -41,8 +44,8 @@ import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.iris.world.task.J;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
@@ -73,7 +76,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
private final ExecutorService service;
|
||||
private final Thread worker;
|
||||
private final PregenPhaseTracker apiPhases = new PregenPhaseTracker();
|
||||
private volatile PregenRenderer renderer;
|
||||
private volatile boolean studioWatching;
|
||||
private volatile PregenRenderSnapshot renderSnapshot;
|
||||
private volatile boolean closed;
|
||||
private volatile boolean finished;
|
||||
@@ -122,7 +125,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
|
||||
switch (GuiHost.serverGuiLaunch(task.isGui())) {
|
||||
case OPEN -> open();
|
||||
case OPEN -> openInStudio();
|
||||
case UNAVAILABLE -> IrisLogging.info("Pregen GUI unavailable (headless), continuing");
|
||||
case DISABLED -> {
|
||||
}
|
||||
@@ -403,32 +406,26 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
closed = true;
|
||||
try {
|
||||
monitor.close();
|
||||
PregenRenderer activeRenderer = renderer;
|
||||
if (activeRenderer != null) {
|
||||
activeRenderer.close();
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
IrisLogging.reportError(error);
|
||||
IrisLogging.error("Error closing pregen gui");
|
||||
IrisLogging.error("Error closing pregen monitor");
|
||||
}
|
||||
}
|
||||
|
||||
public void open() {
|
||||
EventQueue.invokeLater(() -> {
|
||||
if (closed) {
|
||||
return;
|
||||
/** Opens the studio app on the pregeneration's world, or logs its link when no app is set up. */
|
||||
public void openInStudio() {
|
||||
if (closed || engine == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
StudioBridge bridge = StudioBridges.open(engine.getWorld().name(), () -> engine, null);
|
||||
studioWatching = true;
|
||||
if (!StudioWindow.show(bridge)) {
|
||||
IrisLogging.info("Iris Studio link for the pregeneration of %s: %s", engine.getWorld().name(), bridge.link());
|
||||
}
|
||||
try {
|
||||
PregenRenderer opened = PregenRenderer.open(IrisLanguage.plain(DesktopUiMessages.PREGEN_TITLE), this, this::togglePause);
|
||||
renderer = opened;
|
||||
if (closed) {
|
||||
opened.close();
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
IrisLogging.reportError(error);
|
||||
IrisLogging.error("Error opening pregen gui");
|
||||
}
|
||||
});
|
||||
} catch (IOException error) {
|
||||
IrisLogging.warn("Could not open the studio for the pregeneration: %s", error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -483,12 +480,12 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
|
||||
@Override
|
||||
public void onChunkGenerating(int x, int z) {
|
||||
draw(x, z, PregenRenderer.GENERATING);
|
||||
draw(x, z, PregenChunkColors.GENERATING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerated(int x, int z, boolean cached) {
|
||||
drawChunkPreview(x, z, PregenRenderer.GENERATED);
|
||||
drawChunkPreview(x, z, PregenChunkColors.GENERATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -523,7 +520,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
|
||||
@Override
|
||||
public void onNetworkStarted(int x, int z) {
|
||||
drawRegion(x, z, PregenRenderer.NETWORK);
|
||||
drawRegion(x, z, PregenChunkColors.NETWORK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -538,12 +535,12 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
|
||||
@Override
|
||||
public void onNetworkGeneratedChunk(int x, int z) {
|
||||
draw(x, z, PregenRenderer.NETWORK_GENERATING);
|
||||
draw(x, z, PregenChunkColors.NETWORK_GENERATING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkDownloaded(int x, int z) {
|
||||
drawRegion(x, z, PregenRenderer.NETWORK);
|
||||
drawRegion(x, z, PregenChunkColors.NETWORK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -571,7 +568,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
|
||||
@Override
|
||||
public void onChunkExistsInRegionGen(int x, int z) {
|
||||
drawChunkPreview(x, z, PregenRenderer.EXISTS);
|
||||
drawChunkPreview(x, z, PregenChunkColors.EXISTS);
|
||||
}
|
||||
|
||||
public boolean paused() {
|
||||
@@ -604,8 +601,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
|
||||
private void drawChunkPreview(int x, int z, Color statusColor) {
|
||||
draw(x, z, statusColor);
|
||||
PregenRenderer activeRenderer = renderer;
|
||||
if (activeRenderer == null || !activeRenderer.isVisibleFrame() || service.isShutdown()) {
|
||||
if (!studioWatching || service.isShutdown()) {
|
||||
return;
|
||||
}
|
||||
if (engine != null) {
|
||||
@@ -614,8 +610,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
}
|
||||
|
||||
private void renderChunkPreview(int x, int z) {
|
||||
PregenRenderer activeRenderer = renderer;
|
||||
if (activeRenderer == null || !activeRenderer.isVisibleFrame() || service.isShutdown() || engine.isClosing()) {
|
||||
if (!studioWatching || service.isShutdown() || engine.isClosing()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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 art.arcane.iris.studio.workspace;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/** Opens a file or folder in the program the desktop has for it. */
|
||||
public final class FileOpener {
|
||||
private FileOpener() {
|
||||
}
|
||||
|
||||
/** False on a machine without a display, such as a Linux server with no X or Wayland session. */
|
||||
public static boolean isDesktopAvailable() {
|
||||
String system = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
|
||||
if (system.contains("win") || system.contains("mac")) {
|
||||
return true;
|
||||
}
|
||||
return System.getenv("DISPLAY") != null || System.getenv("WAYLAND_DISPLAY") != null;
|
||||
}
|
||||
|
||||
/** @throws IOException when the desktop's opener could not be started */
|
||||
public static void open(File file) throws IOException {
|
||||
new ProcessBuilder(openerCommand(file.getAbsolutePath())).inheritIO().start();
|
||||
}
|
||||
|
||||
private static List<String> openerCommand(String path) {
|
||||
String system = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
|
||||
if (system.contains("win")) {
|
||||
return List.of("cmd", "/c", "start", "", path);
|
||||
}
|
||||
return List.of(system.contains("mac") ? "open" : "xdg-open", path);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,6 @@ import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -69,7 +67,7 @@ public class IrisCodeWorkspace {
|
||||
IrisLogging.warn("Could not refresh every schema for " + workspace.getAbsolutePath() + "; the editor will not be opened with stale autocomplete data.");
|
||||
return;
|
||||
}
|
||||
if (!IrisSettings.get().getStudio().isOpenVSCode() || GraphicsEnvironment.isHeadless()) {
|
||||
if (!IrisSettings.get().getStudio().isOpenVSCode() || !FileOpener.isDesktopAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ public class IrisCodeWorkspace {
|
||||
IrisLogging.msg("VSCode output always starts with: '(node:#####) electron'");
|
||||
Thread launcherThread = new Thread(() -> {
|
||||
try {
|
||||
Desktop.getDesktop().open(workspace);
|
||||
FileOpener.open(workspace);
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.studio.map.components.MapLayer;
|
||||
import art.arcane.iris.studio.map.components.MapStyle;
|
||||
import art.arcane.iris.studio.map.components.MapTile;
|
||||
import art.arcane.iris.studio.map.components.MapTileRenderer;
|
||||
import art.arcane.iris.studio.map.components.PickDisplay;
|
||||
@@ -41,9 +40,9 @@ public class MapHydrologyTest {
|
||||
MapTile tile = settled(renderer, MapLayer.of(TileType.BIOME));
|
||||
int expected = 0xFF000000 | overlaid(engine, 0x738249)[16 * 64 + 16];
|
||||
assertNotEquals(new Color(0x738249).getRGB(), expected);
|
||||
assertEquals(expected, tile.image(MapStyle.PLAIN).getRGB(16, 16));
|
||||
assertEquals(expected, 0xFF000000 | tile.colorAt(16, 16));
|
||||
MapTile dry = settled(renderer, MapLayer.biomes(PickDisplay.PICKS, false));
|
||||
assertEquals(new Color(0x738249).getRGB(), dry.image(MapStyle.PLAIN).getRGB(16, 16));
|
||||
assertEquals(new Color(0x738249).getRGB(), 0xFF000000 | dry.colorAt(16, 16));
|
||||
assertNotEquals(MapLayer.biomes(PickDisplay.PICKS, true), MapLayer.biomes(PickDisplay.PICKS, false));
|
||||
}
|
||||
}
|
||||
@@ -67,11 +66,8 @@ public class MapHydrologyTest {
|
||||
MapTileRenderer renderer = new MapTileRenderer(engine);
|
||||
for (String name : new String[]{"OBJECT_LOAD", "DECORATOR_LOAD", "LAYER_LOAD"}) {
|
||||
TileType type = TileType.valueOf(name);
|
||||
MapView view = MapView.valueOf(name);
|
||||
assertEquals("Diagnostics", view.group().label());
|
||||
assertTrue(view.description().contains("Configuration estimate"));
|
||||
MapTile tile = renderer.renderTile(0, 0, 1, 8, MapLayer.of(type), false, () -> false);
|
||||
assertEquals(biome.getColor(engine, RenderType.valueOf(name)).getRGB(), tile.image(MapStyle.PLAIN).getRGB(0, 0));
|
||||
assertEquals(biome.getColor(engine, RenderType.valueOf(name)).getRGB(), 0xFF000000 | tile.colorAt(0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +75,7 @@ public class MapHydrologyTest {
|
||||
public void disabledWaterPreservesBiomeColors() {
|
||||
Engine engine = engine(FakeHydrology.disabled(), biome());
|
||||
MapTile tile = new MapTileRenderer(engine).renderTile(0, 0, 1, 8, MapLayer.of(TileType.BIOME), false, () -> false);
|
||||
assertEquals(new Color(0x738249).getRGB(), tile.image(MapStyle.PLAIN).getRGB(0, 0));
|
||||
assertEquals(new Color(0x738249).getRGB(), 0xFF000000 | tile.colorAt(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -78,8 +78,7 @@ public class MapTileProgressTest {
|
||||
assertEquals(expected.heightAt(x, z), settled.heightAt(x, z), 0D);
|
||||
}
|
||||
}
|
||||
assertArrayEquals(pixels(expected.image(MapStyle.PLAIN.withShading(true))),
|
||||
pixels(settled.image(MapStyle.PLAIN.withShading(true))));
|
||||
assertArrayEquals(pixels(expected), pixels(settled));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,16 +103,16 @@ public class MapTileProgressTest {
|
||||
|
||||
MapTile first = progress.render(() -> false);
|
||||
assertFalse(progress.complete());
|
||||
assertNotEquals(0xFF738249, first.image(MapStyle.PLAIN).getRGB(0, 0));
|
||||
assertNotEquals(0xFF738249, 0xFF000000 | first.colorAt(0, 0));
|
||||
MapTile second = progress.render(() -> false);
|
||||
assertArrayEquals(pixels(first.image(MapStyle.PLAIN)), pixels(second.image(MapStyle.PLAIN)));
|
||||
assertArrayEquals(pixels(first), pixels(second));
|
||||
|
||||
pending.set(false);
|
||||
MapTile complete = progress.render(() -> false);
|
||||
assertTrue(progress.complete());
|
||||
assertTrue(progress.retainsWater());
|
||||
assertTrue(progress.bytes() > 0L);
|
||||
assertArrayEquals(pixels(first.image(MapStyle.PLAIN)), pixels(complete.image(MapStyle.PLAIN)));
|
||||
assertArrayEquals(pixels(first), pixels(complete));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,29 +149,27 @@ public class MapTileProgressTest {
|
||||
MapTileRenderer.TileRender progress = renderer.prepareTile(-16D, -16D, 2D, 16, layer, true);
|
||||
|
||||
MapTile first = progress.render(() -> false);
|
||||
int[] firstPixels = pixels(first.image(MapStyle.PLAIN.withShading(true)));
|
||||
int[] firstPixels = pixels(first);
|
||||
assertFalse(progress.complete());
|
||||
assertEquals(0xFF738249, first.image(MapStyle.PLAIN).getRGB(8, 8));
|
||||
assertEquals(0xFF738249, 0xFF000000 | first.colorAt(8, 8));
|
||||
MapTile waiting = progress.render(() -> false);
|
||||
assertFalse(progress.complete());
|
||||
assertArrayEquals(firstPixels, pixels(waiting.image(MapStyle.PLAIN.withShading(true))));
|
||||
assertArrayEquals(firstPixels, pixels(waiting));
|
||||
|
||||
pending.set(false);
|
||||
MapTile actual = progress.render(() -> false);
|
||||
assertTrue(progress.complete());
|
||||
assertTrue(progress.retainsWater());
|
||||
assertTrue(progress.bytes() > 0L);
|
||||
BufferedImage colors = actual.image(MapStyle.PLAIN);
|
||||
assertEquals(0xFF738249, colors.getRGB(14, 14));
|
||||
assertNotEquals(0xFF738249, colors.getRGB(8, 8));
|
||||
assertNotEquals(colors.getRGB(8, 8), colors.getRGB(11, 8));
|
||||
assertNotEquals(colors.getRGB(8, 8), colors.getRGB(8, 12));
|
||||
assertNotEquals(colors.getRGB(11, 8), colors.getRGB(8, 12));
|
||||
assertArrayEquals(firstPixels, pixels(first.image(MapStyle.PLAIN.withShading(true))));
|
||||
assertEquals(0x738249, actual.colorAt(14, 14));
|
||||
assertNotEquals(0x738249, actual.colorAt(8, 8));
|
||||
assertNotEquals(actual.colorAt(8, 8), actual.colorAt(11, 8));
|
||||
assertNotEquals(actual.colorAt(8, 8), actual.colorAt(8, 12));
|
||||
assertNotEquals(actual.colorAt(11, 8), actual.colorAt(8, 12));
|
||||
assertArrayEquals(firstPixels, pixels(first));
|
||||
|
||||
MapTile expected = renderer.renderTile(-16D, -16D, 2D, 16, layer, true, () -> false);
|
||||
assertArrayEquals(pixels(expected.image(MapStyle.PLAIN.withShading(true))),
|
||||
pixels(actual.image(MapStyle.PLAIN.withShading(true))));
|
||||
assertArrayEquals(pixels(expected), pixels(actual));
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
assertEquals(expected.heightAt(x, z), actual.heightAt(x, z), 0D);
|
||||
@@ -199,8 +196,7 @@ public class MapTileProgressTest {
|
||||
assertTrue(progress.complete());
|
||||
assertEquals(81, samples.get());
|
||||
MapTile expected = renderer.renderTile(-16D, -16D, 1D, 16, layer, true, () -> false);
|
||||
assertArrayEquals(pixels(expected.image(MapStyle.PLAIN.withShading(true))),
|
||||
pixels(actual.image(MapStyle.PLAIN.withShading(true))));
|
||||
assertArrayEquals(pixels(expected), pixels(actual));
|
||||
}
|
||||
|
||||
private static Engine engine(AtomicInteger biomeSamples) {
|
||||
@@ -220,7 +216,13 @@ public class MapTileProgressTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private static int[] pixels(BufferedImage image) {
|
||||
return image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
|
||||
private static int[] pixels(MapTile tile) {
|
||||
int[] colors = new int[tile.size() * tile.size()];
|
||||
for (int z = 0; z < tile.size(); z++) {
|
||||
for (int x = 0; x < tile.size(); x++) {
|
||||
colors[z * tile.size() + x] = tile.colorAt(x, z);
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import art.arcane.iris.spi.IrisLogging;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -33,7 +36,7 @@ public class PregeneratorJobSavedBiomeTest {
|
||||
fixture.job.onChunkGenerated(2, -3, false);
|
||||
assertEquals(1, fixture.tasks.size());
|
||||
fixture.tasks.removeFirst().run();
|
||||
assertEquals(PregenRenderer.GENERATED.getRGB(), fixture.mapPixels[0]);
|
||||
assertEquals(PregenChunkColors.GENERATED.getRGB() & 0xFFFFFF, fixture.mapPixel() & 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,7 +54,7 @@ public class PregeneratorJobSavedBiomeTest {
|
||||
@Test
|
||||
public void existingChunksDoNotResolveBiomesWhileThePreviewIsHidden() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
when(fixture.renderer.isVisibleFrame()).thenReturn(false);
|
||||
fixture.setField("studioWatching", false);
|
||||
|
||||
fixture.job.onChunkExistsInRegionGen(2, -3);
|
||||
|
||||
@@ -63,7 +66,7 @@ public class PregeneratorJobSavedBiomeTest {
|
||||
public void queuedPreviewSkipsReadsWhenTheFrameBecomesHidden() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.job.onChunkGenerated(2, -3, false);
|
||||
when(fixture.renderer.isVisibleFrame()).thenReturn(false);
|
||||
fixture.setField("studioWatching", false);
|
||||
|
||||
fixture.tasks.removeFirst().run();
|
||||
|
||||
@@ -90,26 +93,25 @@ public class PregeneratorJobSavedBiomeTest {
|
||||
private static final class Fixture {
|
||||
private final PregeneratorJob job = mock(PregeneratorJob.class, CALLS_REAL_METHODS);
|
||||
private final Engine engine = mock(Engine.class, CALLS_REAL_METHODS);
|
||||
private final PregenRenderer renderer = mock(PregenRenderer.class);
|
||||
private final ArrayList<Runnable> tasks = new ArrayList<>();
|
||||
private final int[] mapPixels = new int[1];
|
||||
private final PregenMapState state = new PregenMapState(new PregenRenderSnapshot.Bounds(2, -3, 2, -3));
|
||||
|
||||
private Fixture() throws Exception {
|
||||
PregenMapState state = new PregenMapState(new PregenRenderSnapshot.Bounds(2, -3, 2, -3));
|
||||
PregenMapState.View view = state.attach(mapPixels);
|
||||
setField("mapState", state);
|
||||
ExecutorService service = mock(ExecutorService.class);
|
||||
doAnswer(invocation -> {
|
||||
tasks.add(invocation.getArgument(0));
|
||||
view.flush();
|
||||
return null;
|
||||
}).when(service).execute(any(Runnable.class));
|
||||
when(renderer.isVisibleFrame()).thenReturn(true);
|
||||
setField("engine", engine);
|
||||
setField("renderer", renderer);
|
||||
setField("studioWatching", true);
|
||||
setField("service", service);
|
||||
}
|
||||
|
||||
private int mapPixel() throws IOException {
|
||||
return ImageIO.read(new ByteArrayInputStream(state.png())).getRGB(0, 0);
|
||||
}
|
||||
|
||||
private void setField(String name, Object value) throws Exception {
|
||||
Field field = PregeneratorJob.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
|
||||
Reference in new issue
Block a user