Partial refactor.

This commit is contained in:
2023-10-08 09:49:49 -04:00
parent 0ce9ec3ae2
commit 4b62517d99
5 changed files with 69 additions and 258 deletions
+48
View File
@@ -5,6 +5,7 @@
package engine.util;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.gameManager.ConfigManager;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
@@ -14,6 +15,10 @@ import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
public enum MapLoader {
@@ -87,4 +92,47 @@ public enum MapLoader {
g.dispose();
return dimg;
}
public static void loadAlHeightMaps() {
// Load pixel data for heightmaps
try (Stream<Path> filePathStream = Files.walk(Paths.get(ConfigManager.DEFAULT_DATA_DIR + "heightmaps/TARGA/"))) {
filePathStream.forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
File imageFile = filePath.toFile();
try {
BufferedImage heightmapImage = ImageIO.read(imageFile);
// Generate pixel data for this heightmap. RPG channels are all the same
// in this greyscale TGA heightmap. We will choose red.
short[][] colorData = new short[heightmapImage.getWidth()][heightmapImage.getHeight()];
for (int y = 0; y < heightmapImage.getHeight(); y++)
for (int x = 0; x < heightmapImage.getWidth(); x++) {
Color color = new Color(heightmapImage.getRGB(x, y));
colorData[x][y] = (short) color.getRed();
}
// Insert color data into lookup table
int heightMapID = Integer.parseInt(imageFile.getName().substring(0, imageFile.getName().lastIndexOf(".")));
Terrain._heightmap_pixel_cache.put(heightMapID, colorData);
} catch (IOException e) {
Logger.error(e);
}
}
}); // Try with resources block
} catch (IOException e) {
Logger.error(e);
}
}
}