Fixes, update Aparapi, set layout command
This commit is contained in:
parent
86b8e363e2
commit
6058842b61
7 changed files with 82 additions and 67 deletions
|
@ -37,14 +37,6 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>9</source>
|
|
||||||
<target>9</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -56,7 +48,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aparapi</groupId>
|
<groupId>com.aparapi</groupId>
|
||||||
<artifactId>aparapi</artifactId>
|
<artifactId>aparapi</artifactId>
|
||||||
<version>1.10.0</version>
|
<version>2.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.NorbiPeti</groupId>
|
<groupId>io.github.NorbiPeti</groupId>
|
||||||
|
|
|
@ -137,9 +137,7 @@ public final class Computer {
|
||||||
|
|
||||||
public void PowerButton(CommandSender sender, int index) {
|
public void PowerButton(CommandSender sender, int index) {
|
||||||
sendMessage(sender, "§ePressing powerbutton...");
|
sendMessage(sender, "§ePressing powerbutton...");
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (session.getState() != SessionState.Locked || session.getMachine() == null) {
|
if (session.getState() != SessionState.Locked || session.getMachine() == null) {
|
||||||
Start(sender, index);
|
Start(sender, index);
|
||||||
} else {
|
} else {
|
||||||
|
@ -148,7 +146,6 @@ public final class Computer {
|
||||||
}
|
}
|
||||||
sendMessage(sender, "§ePowerbutton pressed.");
|
sendMessage(sender, "§ePowerbutton pressed.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +307,8 @@ public final class Computer {
|
||||||
sender.sendMessage("§bThe computer is stuck. Use /c stop.");
|
sender.sendMessage("§bThe computer is stuck. Use /c stop.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (session.getState() == SessionState.Locked && machine.getState() == MachineState.Running) {
|
if (session.getState() == SessionState.Locked) {
|
||||||
|
if (machine.getState() == MachineState.Running) {
|
||||||
var con = session.getConsole();
|
var con = session.getConsole();
|
||||||
Holder<Long> w = new Holder<>(), h = new Holder<>(), bpp = new Holder<>();
|
Holder<Long> w = new Holder<>(), h = new Holder<>(), bpp = new Holder<>();
|
||||||
Holder<Integer> xo = new Holder<>(), yo = new Holder<>();
|
Holder<Integer> xo = new Holder<>(), yo = new Holder<>();
|
||||||
|
@ -318,6 +316,9 @@ public final class Computer {
|
||||||
con.getDisplay().getScreenResolution(0L, w, h, bpp, xo, yo, gms);
|
con.getDisplay().getScreenResolution(0L, w, h, bpp, xo, yo, gms);
|
||||||
sender.sendMessage("§bScreen info: " + w.value + "x" + h.value + " (" + bpp.value + ") at " + xo.value + " " + yo.value + " - " + gms.value);
|
sender.sendMessage("§bScreen info: " + w.value + "x" + h.value + " (" + bpp.value + ") at " + xo.value + " " + yo.value + " - " + gms.value);
|
||||||
sender.sendMessage("§bKeyboard LEDs: " + con.getKeyboard().getKeyboardLEDs().stream().map(Enum::toString).collect(Collectors.joining(", ")));
|
sender.sendMessage("§bKeyboard LEDs: " + con.getKeyboard().getKeyboardLEDs().stream().map(Enum::toString).collect(Collectors.joining(", ")));
|
||||||
|
} else if (machine.getState().value() < MachineState.FirstOnline.value()
|
||||||
|
|| machine.getState().value() > MachineState.LastOnline.value())
|
||||||
|
sender.sendMessage("§bUse /c stop to fix the computer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,17 @@ import lombok.var;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.DyeColor;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.ItemFrame;
|
import org.bukkit.entity.ItemFrame;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.material.Wool;
|
|
||||||
import org.javatuples.Tuple;
|
|
||||||
import org.virtualbox_6_1.VBoxException;
|
import org.virtualbox_6_1.VBoxException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@CommandClass(helpText = {
|
@CommandClass(helpText = {
|
||||||
|
@ -158,20 +157,13 @@ public class ComputerCommand extends ICommand2MC {
|
||||||
})
|
})
|
||||||
public void spawn(Player player) {
|
public void spawn(Player player) {
|
||||||
var loc = player.getLocation();
|
var loc = player.getLocation();
|
||||||
System.out.println("Player location: " + loc);
|
|
||||||
var world = Objects.requireNonNull(loc.getWorld());
|
var world = Objects.requireNonNull(loc.getWorld());
|
||||||
short id = PluginMain.Instance.startID.get();
|
short id = PluginMain.Instance.startID.get();
|
||||||
for (int i = 0; i < PluginMain.MCX; i++) {
|
|
||||||
for (int j = PluginMain.MCY - 1; j >= 0; j--) {
|
for (int j = PluginMain.MCY - 1; j >= 0; j--) {
|
||||||
|
for (int i = 0; i < PluginMain.MCX; i++) {
|
||||||
var block = world.getBlockAt(loc.getBlockX() + i, loc.getBlockY() + j, loc.getBlockZ());
|
var block = world.getBlockAt(loc.getBlockX() + i, loc.getBlockY() + j, loc.getBlockZ());
|
||||||
block.setType(Material.BLACK_WOOL);
|
block.setType(Material.BLACK_WOOL);
|
||||||
/*var ws = block.getState();
|
|
||||||
var wool = (Wool) ws.getData();
|
|
||||||
wool.setColor(DyeColor.BLACK);
|
|
||||||
ws.setData(wool);
|
|
||||||
ws.update();*/
|
|
||||||
var frameLoc = block.getLocation().add(0, 0, 1);
|
var frameLoc = block.getLocation().add(0, 0, 1);
|
||||||
System.out.println("Setting " + frameLoc + " to " + id);
|
|
||||||
var map = new ItemStack(Material.FILLED_MAP, 1);
|
var map = new ItemStack(Material.FILLED_MAP, 1);
|
||||||
var meta = ((MapMeta) map.getItemMeta());
|
var meta = ((MapMeta) map.getItemMeta());
|
||||||
if (meta == null) throw new NullPointerException("Map meta is null for " + frameLoc);
|
if (meta == null) throw new NullPointerException("Map meta is null for " + frameLoc);
|
||||||
|
@ -181,4 +173,31 @@ public class ComputerCommand extends ICommand2MC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"Set layout",
|
||||||
|
"This command sets the keyboard layout used for /c show keyboard.",
|
||||||
|
"Valid options are files in the layouts folder in the plugin's directory."
|
||||||
|
})
|
||||||
|
public void set_layout(CommandSender sender, String layout) {
|
||||||
|
var lf = PluginMain.Instance.layoutFolder;
|
||||||
|
if (!lf.mkdirs()) {
|
||||||
|
sender.sendMessage("§cFailed to create layouts folder!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var l = new File(lf, layout + ".yml");
|
||||||
|
if (!l.exists()) {
|
||||||
|
sender.sendMessage("§cThe file " + l + " does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var yc = YamlConfiguration.loadConfiguration(l);
|
||||||
|
var list = yc.getList("keyboard");
|
||||||
|
if (list == null) {
|
||||||
|
sender.sendMessage("§cThe 'keyboard' key is missing.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var item : list) {
|
||||||
|
System.out.println("item: " + item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,11 @@ public class PluginMain extends ButtonPlugin {
|
||||||
* If true, uses the GPU to accelerate screen rendering. Requires root on Linux.
|
* If true, uses the GPU to accelerate screen rendering. Requires root on Linux.
|
||||||
*/
|
*/
|
||||||
private final ConfigData<Boolean> useGPU = getIConfig().getData("useGPU", true);
|
private final ConfigData<Boolean> useGPU = getIConfig().getData("useGPU", true);
|
||||||
|
/**
|
||||||
|
* Determines the keyboard layout to use for /c show keyboard. Layouts can be defined in VirtualComputer/layouts/.
|
||||||
|
*/
|
||||||
|
private final ConfigData<String> kbLayout = getIConfig().getData("kbLayout", "en");
|
||||||
|
public File layoutFolder = new File(getDataFolder(), "layouts");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pluginEnable() {
|
public void pluginEnable() {
|
||||||
|
|
|
@ -23,8 +23,13 @@ public class VBoxEventHandler extends EventHandlerBase {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSessionStateChange(ISessionStateChangedEvent event) {
|
public void onSessionStateChange(ISessionStateChangedEvent event) {
|
||||||
if (!event.getMachineId().equals(machineID)) return;
|
if (!event.getMachineId().equals(machineID)) return;
|
||||||
|
try {
|
||||||
if (event.getState() == SessionState.Locked) //Need to check here, because we can't access the console yet
|
if (event.getState() == SessionState.Locked) //Need to check here, because we can't access the console yet
|
||||||
Computer.getInstance().onLock(sender);
|
Computer.getInstance().onLock(sender);
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender.sendMessage("§cFailed to start computer! See the console for more details.");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(String machineID, CommandSender sender) {
|
public void setup(String machineID, CommandSender sender) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class GPURenderer extends MapRenderer implements IRenderer {
|
||||||
private static ArrayList<GPURenderer> renderers = new ArrayList<>();
|
private static ArrayList<GPURenderer> renderers = new ArrayList<>();
|
||||||
private static Method flagDirtyMethod;
|
private static Method flagDirtyMethod;
|
||||||
private static boolean enabled = true;
|
private static boolean enabled = true;
|
||||||
|
private static boolean warned = false;
|
||||||
|
|
||||||
public GPURenderer(short id, World world, int mapx, int mapy) throws Exception {
|
public GPURenderer(short id, World world, int mapx, int mapy) throws Exception {
|
||||||
MapView map = IRenderer.prepare(id, world);
|
MapView map = IRenderer.prepare(id, world);
|
||||||
|
@ -81,7 +82,8 @@ public class GPURenderer extends MapRenderer implements IRenderer {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
buffer = (byte[]) field.get(canvas);
|
buffer = (byte[]) field.get(canvas);
|
||||||
}
|
}
|
||||||
if (mapx == 0 && mapy == 0) { //Only print once
|
if (!warned) { //Only print once
|
||||||
|
warned = true;
|
||||||
if (kernel.getTargetDevice().getType() != Device.TYPE.GPU) {
|
if (kernel.getTargetDevice().getType() != Device.TYPE.GPU) {
|
||||||
PluginMain.Instance.getLogger().warning("Cannot use GPU! Target device: " + kernel.getTargetDevice().getShortDescription()
|
PluginMain.Instance.getLogger().warning("Cannot use GPU! Target device: " + kernel.getTargetDevice().getShortDescription()
|
||||||
+ " - Best device: " + KernelManager.instance().bestDevice().getShortDescription());
|
+ " - Best device: " + KernelManager.instance().bestDevice().getShortDescription());
|
||||||
|
|
|
@ -2,11 +2,7 @@ package sznp.virtualcomputer.renderer;
|
||||||
|
|
||||||
import com.aparapi.Kernel;
|
import com.aparapi.Kernel;
|
||||||
import com.aparapi.Range;
|
import com.aparapi.Range;
|
||||||
import com.aparapi.device.Device;
|
|
||||||
import com.aparapi.internal.kernel.KernelManager;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.var;
|
|
||||||
import sznp.virtualcomputer.PluginMain;
|
|
||||||
|
|
||||||
//Accessing the GPURenderer results in ArrayIndexOutOfBoundsExceptions - IT'S THE LAMBDAS
|
//Accessing the GPURenderer results in ArrayIndexOutOfBoundsExceptions - IT'S THE LAMBDAS
|
||||||
public class GPURendererInternal extends Kernel {
|
public class GPURendererInternal extends Kernel {
|
||||||
|
@ -28,12 +24,7 @@ public class GPURendererInternal extends Kernel {
|
||||||
this.mapx = mapx;
|
this.mapx = mapx;
|
||||||
this.mapy = mapy;
|
this.mapy = mapy;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
//range = Range.create2D(128, 128);
|
|
||||||
//var dev = KernelManager.instance().bestDevice();
|
|
||||||
range = Range.create2D(128, 128);
|
range = Range.create2D(128, 128);
|
||||||
/*var dev = getTargetDevice();
|
|
||||||
if (mapx == mapy && mapx == 0)
|
|
||||||
PluginMain.Instance.getLogger().info("Using device: " + dev.getShortDescription());*/
|
|
||||||
|
|
||||||
//Do an intial draw of a black screen with Aparapi so it doesn't lag at start
|
//Do an intial draw of a black screen with Aparapi so it doesn't lag at start
|
||||||
pixels = new byte[1];
|
pixels = new byte[1];
|
||||||
|
|
Loading…
Reference in a new issue