Some fixes
Feb 7
This commit is contained in:
parent
aa6d7bc236
commit
865526f4d0
3 changed files with 14 additions and 21 deletions
|
@ -1,18 +1,16 @@
|
||||||
package sznp.virtualcomputer;
|
package sznp.virtualcomputer;
|
||||||
|
|
||||||
|
import com.sun.jna.Pointer;
|
||||||
import net.minecraft.server.v1_12_R1.WorldMap;
|
import net.minecraft.server.v1_12_R1.WorldMap;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.v1_12_R1.map.RenderData;
|
import org.bukkit.craftbukkit.v1_12_R1.map.RenderData;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.map.MapCanvas;
|
import org.bukkit.map.MapCanvas;
|
||||||
import org.bukkit.map.MapPalette;
|
|
||||||
import org.bukkit.map.MapRenderer;
|
import org.bukkit.map.MapRenderer;
|
||||||
import org.bukkit.map.MapView;
|
import org.bukkit.map.MapView;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DirectRenderer implements IRenderer {
|
public class DirectRenderer implements IRenderer {
|
||||||
|
@ -52,23 +50,17 @@ public class DirectRenderer implements IRenderer {
|
||||||
private final class DummyRenderer extends MapRenderer {
|
private final class DummyRenderer extends MapRenderer {
|
||||||
@Override
|
@Override
|
||||||
public void render(MapView map, MapCanvas canvas, Player player) {
|
public void render(MapView map, MapCanvas canvas, Player player) {
|
||||||
if(allpixels != null)
|
DirectRenderer.this.render(x, y, width, height); //Render after zeroing whole map
|
||||||
DirectRenderer.this.render(allpixels, x, y, width, height); //Render after zeroing whole map
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Exception ex;
|
private Exception ex;
|
||||||
private ByteBuffer allpixels;
|
|
||||||
private long x, y, width, height;
|
private long x, y, width, height;
|
||||||
private long lastrender;
|
private long lastrender;
|
||||||
|
|
||||||
public void setAllpixels(ByteBuffer bb) {
|
|
||||||
allpixels = bb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void render(ByteBuffer allpixels, long x, long y, long width, long height) { // TODO
|
public void render(long x, long y, long width, long height) { // TODO
|
||||||
this.allpixels = allpixels; //TODO: |CRASH| Prevent trying to read memory after computer is stopped
|
//TODO: |CRASH| Prevent trying to read memory after computer is stopped
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
this.width=width;
|
this.width=width;
|
||||||
|
@ -76,12 +68,15 @@ public class DirectRenderer implements IRenderer {
|
||||||
if(System.nanoTime()-lastrender<100*1000*1000)
|
if(System.nanoTime()-lastrender<100*1000*1000)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
|
long p = PluginMain.pxc.updateAndGetMap((int) x, (int) y, (int) width, (int) height, null);
|
||||||
|
if (p == 0) return;
|
||||||
|
byte[] img = new Pointer(p).getByteArray(0, 128 * 128);
|
||||||
boolean hascolor=false;
|
boolean hascolor=false;
|
||||||
for (int i = startindex, j = 0; i < allpixels.limit() - 4 && j < buffer.length; i += 4, j++) {
|
for (int j = 0; j < buffer.length; j++) {
|
||||||
if (PluginMain.Instance.checkMachineNotRunning(null))
|
if (PluginMain.Instance.checkMachineNotRunning(null))
|
||||||
return;
|
return;
|
||||||
buffer[j] = MapPalette.matchColor(new Color(Byte.toUnsignedInt(allpixels.get(i)), Byte.toUnsignedInt(allpixels.get(i + 1)), Byte.toUnsignedInt(allpixels.get(i + 2))));
|
buffer[j] = img[j];
|
||||||
if(allpixels.get(i+2)>10)
|
if (img[j] != 0)
|
||||||
hascolor=true;
|
hascolor=true;
|
||||||
}
|
}
|
||||||
if(hascolor)
|
if(hascolor)
|
||||||
|
|
|
@ -2,9 +2,6 @@ package sznp.virtualcomputer;
|
||||||
|
|
||||||
import jnr.ffi.Pointer;
|
import jnr.ffi.Pointer;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.nio.Buffer;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface PXCLib {
|
public interface PXCLib {
|
||||||
/**
|
/**
|
||||||
|
@ -29,5 +26,5 @@ public interface PXCLib {
|
||||||
* Updates map and returns it's content, where affected
|
* Updates map and returns it's content, where affected
|
||||||
* @return Partial map data [mapc][data]
|
* @return Partial map data [mapc][data]
|
||||||
*/
|
*/
|
||||||
Buffer updateAndGetMap(int x, int y, int width, int height, Pointer out_changed); //TODO: Only update parts that actually updated and return them per-map (flagDirty)
|
long updateAndGetMap(int x, int y, int width, int height, Pointer out_changed); //TODO: Only update parts that actually updated and return them per-map (flagDirty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,17 +70,18 @@ public class PluginMain extends JavaPlugin {
|
||||||
vbox = manager.getVBox();
|
vbox = manager.getVBox();
|
||||||
session = manager.getSessionObject(); // TODO: Events
|
session = manager.getSessionObject(); // TODO: Events
|
||||||
ccs.sendMessage("§bLoading Screen...");
|
ccs.sendMessage("§bLoading Screen...");
|
||||||
pxc = LibraryLoader.create(PXCLib.class).search(getDataFolder().getAbsolutePath()).load("pxc");
|
|
||||||
try {
|
try {
|
||||||
//throw new NoClassDefFoundError("Test error pls ignore");
|
//throw new NoClassDefFoundError("Test error pls ignore");
|
||||||
for (short i = 0; i < 20; i++)
|
for (short i = 0; i < 20; i++)
|
||||||
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
|
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
|
||||||
|
pxc = LibraryLoader.create(PXCLib.class).search(getDataFolder().getAbsolutePath()).load("pxc");
|
||||||
direct=true;
|
direct=true;
|
||||||
ccs.sendMessage("§bUsing Direct Renderer, all good");
|
ccs.sendMessage("§bUsing Direct Renderer, all good");
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (NoClassDefFoundError | Exception e) {
|
||||||
for (short i = 0; i < 20; i++)
|
for (short i = 0; i < 20; i++)
|
||||||
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));
|
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));
|
||||||
direct=false;
|
direct=false;
|
||||||
|
e.printStackTrace();
|
||||||
ccs.sendMessage("§6Compatibility error, using slower renderer");
|
ccs.sendMessage("§6Compatibility error, using slower renderer");
|
||||||
}
|
}
|
||||||
ccs.sendMessage("§bLoaded!");
|
ccs.sendMessage("§bLoaded!");
|
||||||
|
|
Loading…
Reference in a new issue