|
27 | 27 | import java.util.stream.Collectors;
|
28 | 28 |
|
29 | 29 | public class ChunkyMapTile extends HDMapTile {
|
30 |
| - private final ChunkyMap map; |
31 | 30 |
|
32 |
| - public ChunkyMapTile(DynmapWorld world, HDPerspective perspective, ChunkyMap map, int tx, int ty) { |
33 |
| - super(world, perspective, tx, ty, map.getBoostZoom()); |
34 |
| - this.map = map; |
35 |
| - } |
36 |
| - |
37 |
| - public ChunkyMapTile(DynmapWorld world, String parm) throws Exception { |
38 |
| - super(world, parm); |
39 |
| - map = (ChunkyMap) world.maps.stream().filter(m -> m instanceof ChunkyMap).findFirst().get(); |
40 |
| - } |
41 |
| - |
42 |
| - @Override |
43 |
| - public boolean render(MapChunkCache mapChunkCache, String s) { |
44 |
| - IsoHDPerspective perspective = (IsoHDPerspective) this.perspective; |
45 |
| - |
46 |
| - final int scaled = (boostzoom > 0 && MarkerAPIImpl.testTileForBoostMarkers(world, perspective, (double) (tx * 128), (double) (ty * 128), 128.0D)) ? boostzoom : 0; |
47 |
| - |
48 |
| - // Mark the tiles we're going to render as validated |
49 |
| - MapTypeState mts = world.getMapState(map); |
50 |
| - if (mts != null) { |
51 |
| - mts.validateTile(tx, ty); |
| 31 | + private final ChunkyMap map; |
| 32 | + |
| 33 | + public ChunkyMapTile(DynmapWorld world, HDPerspective perspective, ChunkyMap map, int tx, |
| 34 | + int ty) { |
| 35 | + super(world, perspective, tx, ty, map.getBoostZoom()); |
| 36 | + this.map = map; |
| 37 | + } |
| 38 | + |
| 39 | + public ChunkyMapTile(DynmapWorld world, String parm) throws Exception { |
| 40 | + // Do not remove this constructor! It is used by Dynmap to de-serialize tiles from the queue. |
| 41 | + // The serialization happens in the inherited saveTileData() method. |
| 42 | + super(world, parm); |
| 43 | + map = (ChunkyMap) world.maps.stream().filter(m -> m instanceof ChunkyMap).findFirst().get(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean render(MapChunkCache mapChunkCache, String s) { |
| 48 | + IsoHDPerspective perspective = (IsoHDPerspective) this.perspective; |
| 49 | + |
| 50 | + final int scaled = (boostzoom > 0 && MarkerAPIImpl |
| 51 | + .testTileForBoostMarkers(world, perspective, (double) (tx * 128), (double) (ty * 128), |
| 52 | + 128.0D)) ? boostzoom : 0; |
| 53 | + |
| 54 | + // Mark the tiles we're going to render as validated |
| 55 | + MapTypeState mts = world.getMapState(map); |
| 56 | + if (mts != null) { |
| 57 | + mts.validateTile(tx, ty); |
| 58 | + } |
| 59 | + |
| 60 | + FileBufferRenderContext context = new FileBufferRenderContext(); |
| 61 | + try { |
| 62 | + Renderer renderer = map.getRenderer(); |
| 63 | + renderer.setDefaultTexturepack(map.getDefaultTexturepackPath()); |
| 64 | + renderer.render(context, map.getTexturepackPath(), (scene) -> { |
| 65 | + org.bukkit.World bukkitWorld = Bukkit.getWorld(world.getRawName()); |
| 66 | + World chunkyWorld = World.loadWorld(bukkitWorld.getWorldFolder(), |
| 67 | + getChunkyDimension(bukkitWorld.getEnvironment()), LoggedWarnings.SILENT); |
| 68 | + // Bukkit.getScheduler().runTask(ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class), Bukkit.getWorld(world.getRawName())::save); |
| 69 | + map.applyTemplateScene(scene); |
| 70 | + scene.setName(tx + "_" + ty); |
| 71 | + scene.setCanvasSize(128 * (1 << scaled), 128 * (1 << scaled)); |
| 72 | + scene.setTransparentSky(true); |
| 73 | + scene.setYClipMin((int) perspective.minheight); |
| 74 | + if (perspective.maxheight > 0) { |
| 75 | + scene.setYClipMax((int) perspective.maxheight); |
52 | 76 | }
|
53 |
| - |
54 |
| - FileBufferRenderContext context = new FileBufferRenderContext(); |
| 77 | + map.cameraAdapter.apply(scene.camera(), tx, ty, map.getMapZoomOutLevels(), |
| 78 | + world.getExtraZoomOutLevels()); |
| 79 | + |
| 80 | + scene.loadChunks(SilentTaskTracker.INSTANCE, chunkyWorld, |
| 81 | + perspective.getRequiredChunks(this).stream() |
| 82 | + .flatMap(c -> getChunksAround(c.x, c.z, map.getChunkPadding()).stream()) |
| 83 | + .collect(Collectors.toList())); |
| 84 | + }).thenApply((image) -> { |
| 85 | + MapStorage var52 = world.getMapStorage(); |
| 86 | + MapStorageTile mtile = var52.getTile(world, map, tx, ty, 0, ImageVariant.STANDARD); |
55 | 87 | try {
|
56 |
| - Renderer renderer = map.getRenderer(); |
57 |
| - renderer.setDefaultTexturepack(map.getDefaultTexturepackPath()); |
58 |
| - renderer.render(context, map.getTexturepackPath(), (scene) -> { |
59 |
| - org.bukkit.World bukkitWorld = Bukkit.getWorld(world.getRawName()); |
60 |
| - World chunkyWorld = World.loadWorld(bukkitWorld.getWorldFolder(), getChunkyDimension(bukkitWorld.getEnvironment()), LoggedWarnings.SILENT); |
61 |
| - // Bukkit.getScheduler().runTask(ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class), Bukkit.getWorld(world.getRawName())::save); |
62 |
| - map.applyTemplateScene(scene); |
63 |
| - scene.setName(tx + "_" + ty); |
64 |
| - scene.setCanvasSize(128 * (1 << scaled), 128 * (1 << scaled)); |
65 |
| - scene.setTransparentSky(true); |
66 |
| - scene.setYClipMin((int) perspective.minheight); |
67 |
| - if (perspective.maxheight > 0) { |
68 |
| - scene.setYClipMax((int) perspective.maxheight); |
69 |
| - } |
70 |
| - map.cameraAdapter.apply(scene.camera(), tx, ty, map.getMapZoomOutLevels(), world.getExtraZoomOutLevels()); |
71 |
| - |
72 |
| - scene.loadChunks(SilentTaskTracker.INSTANCE, chunkyWorld, |
73 |
| - perspective.getRequiredChunks(this).stream() |
74 |
| - .flatMap(c -> getChunksAround(c.x, c.z, map.getChunkPadding()).stream()) |
75 |
| - .collect(Collectors.toList())); |
76 |
| - }).thenApply((image) -> { |
77 |
| - MapStorage var52 = world.getMapStorage(); |
78 |
| - MapStorageTile mtile = var52.getTile(world, map, tx, ty, 0, ImageVariant.STANDARD); |
79 |
| - try { |
80 |
| - mtile.getWriteLock(); |
81 |
| - mtile.write(image.hashCode(), image); |
82 |
| - MapManager.mapman.pushUpdate(getDynmapWorld(), new Client.Tile(mtile.getURI())); |
83 |
| - } finally { |
84 |
| - mtile.releaseWriteLock(); |
85 |
| - MapManager.mapman.updateStatistics(this, map.getPrefix(), true, true, false); |
86 |
| - } |
87 |
| - return true; |
88 |
| - }).get(); |
89 |
| - return true; |
90 |
| - } catch (Exception e) { |
91 |
| - ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger().log(Level.WARNING, "Rendering tile failed", e); |
92 |
| - return false; |
93 |
| - } |
94 |
| - } |
95 |
| - |
96 |
| - private static int getChunkyDimension(Environment environment) { |
97 |
| - switch(environment) { |
98 |
| - case NETHER: |
99 |
| - return World.NETHER_DIMENSION; |
100 |
| - case THE_END: |
101 |
| - return World.END_DIMENSION; |
102 |
| - case NORMAL: |
103 |
| - default: |
104 |
| - return World.OVERWORLD_DIMENSION; |
| 88 | + mtile.getWriteLock(); |
| 89 | + mtile.write(image.hashCode(), image); |
| 90 | + MapManager.mapman.pushUpdate(getDynmapWorld(), new Client.Tile(mtile.getURI())); |
| 91 | + } finally { |
| 92 | + mtile.releaseWriteLock(); |
| 93 | + MapManager.mapman.updateStatistics(this, map.getPrefix(), true, true, false); |
105 | 94 | }
|
106 |
| - } |
107 |
| - |
108 |
| - private static Collection<ChunkPosition> getChunksAround(int centerX, int centerZ, int radius) { |
109 |
| - ArrayList<ChunkPosition> chunks = new ArrayList<>((radius + 1) * (radius + 1)); |
110 |
| - for (int x = -radius; x <= radius; x++) { |
111 |
| - for (int z = -radius; z <= radius; z++) { |
112 |
| - chunks.add(ChunkPosition.get(centerX + x, centerZ + z)); |
113 |
| - } |
114 |
| - } |
115 |
| - return chunks; |
116 |
| - } |
117 |
| - |
118 |
| - @Override |
119 |
| - public List<DynmapChunk> getRequiredChunks() { |
120 |
| - return map.getRequiredChunks(this); |
121 |
| - } |
122 |
| - |
123 |
| - @Override |
124 |
| - public MapTile[] getAdjecentTiles() { |
125 |
| - return map.getAdjecentTiles(this); |
126 |
| - } |
127 |
| - |
128 |
| - @Override |
129 |
| - public int hashCode() { |
130 |
| - return tx ^ ty ^ world.hashCode(); |
131 |
| - } |
132 |
| - |
133 |
| - @Override |
134 |
| - public boolean equals(Object o) { |
135 |
| - if (o instanceof ChunkyMapTile) { |
136 |
| - return ((ChunkyMapTile) o).tx == tx && ((ChunkyMapTile) o).ty == ty; |
137 |
| - } |
138 |
| - return false; |
139 |
| - } |
140 |
| - |
141 |
| - @Override |
142 |
| - public boolean isBiomeDataNeeded() { |
143 |
| - return false; |
144 |
| - } |
145 |
| - |
146 |
| - @Override |
147 |
| - public boolean isHightestBlockYDataNeeded() { |
148 |
| - return false; |
149 |
| - } |
150 |
| - |
151 |
| - @Override |
152 |
| - public boolean isRawBiomeDataNeeded() { |
153 |
| - return false; |
154 |
| - } |
155 |
| - |
156 |
| - @Override |
157 |
| - public boolean isBlockTypeDataNeeded() { |
158 | 95 | return true;
|
159 |
| - } |
160 |
| - |
161 |
| - @Override |
162 |
| - public int tileOrdinalX() { |
163 |
| - return tx; |
164 |
| - } |
165 |
| - |
166 |
| - @Override |
167 |
| - public int tileOrdinalY() { |
168 |
| - return ty; |
169 |
| - } |
170 |
| - |
171 |
| - @Override |
172 |
| - protected String saveTileData() { |
173 |
| - return String.format("%d,%d", tx, ty); |
174 |
| - } |
| 96 | + }).get(); |
| 97 | + return true; |
| 98 | + } catch (Exception e) { |
| 99 | + ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger() |
| 100 | + .log(Level.WARNING, "Rendering tile failed", e); |
| 101 | + return false; |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + private static int getChunkyDimension(Environment environment) { |
| 106 | + switch (environment) { |
| 107 | + case NETHER: |
| 108 | + return World.NETHER_DIMENSION; |
| 109 | + case THE_END: |
| 110 | + return World.END_DIMENSION; |
| 111 | + case NORMAL: |
| 112 | + default: |
| 113 | + return World.OVERWORLD_DIMENSION; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + private static Collection<ChunkPosition> getChunksAround(int centerX, int centerZ, int radius) { |
| 118 | + ArrayList<ChunkPosition> chunks = new ArrayList<>((radius + 1) * (radius + 1)); |
| 119 | + for (int x = -radius; x <= radius; x++) { |
| 120 | + for (int z = -radius; z <= radius; z++) { |
| 121 | + chunks.add(ChunkPosition.get(centerX + x, centerZ + z)); |
| 122 | + } |
| 123 | + } |
| 124 | + return chunks; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public List<DynmapChunk> getRequiredChunks() { |
| 129 | + return map.getRequiredChunks(this); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public MapTile[] getAdjecentTiles() { |
| 134 | + return map.getAdjecentTiles(this); |
| 135 | + } |
| 136 | + |
| 137 | + public int hashCode() { |
| 138 | + return this.tx ^ this.ty ^ this.perspective.hashCode() ^ this.world.hashCode() ^ this.boostzoom; |
| 139 | + } |
| 140 | + |
| 141 | + public boolean equals(Object obj) { |
| 142 | + return obj instanceof ChunkyMapTile && this.equals((ChunkyMapTile) obj); |
| 143 | + } |
| 144 | + |
| 145 | + public boolean equals(ChunkyMapTile o) { |
| 146 | + return o.tx == this.tx && o.ty == this.ty && this.perspective == o.perspective |
| 147 | + && o.world == this.world && o.boostzoom == this.boostzoom; |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public boolean isBiomeDataNeeded() { |
| 152 | + return false; |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public boolean isHightestBlockYDataNeeded() { |
| 157 | + return false; |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public boolean isRawBiomeDataNeeded() { |
| 162 | + return false; |
| 163 | + } |
| 164 | + |
| 165 | + @Override |
| 166 | + public boolean isBlockTypeDataNeeded() { |
| 167 | + return true; |
| 168 | + } |
175 | 169 | }
|
0 commit comments