From c677ca415d8526724309146f5be49af535e4ce7c Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Mon, 16 Dec 2019 05:36:13 -0800 Subject: [PATCH] Added support to set DT1 class to headless loading mode --- core/src/com/riiablo/map/DT1.java | 8 ++++++++ core/src/com/riiablo/map/DT1Loader.java | 17 +++++++++-------- .../d2gs/src/com/riiablo/server/d2gs/D2GS.java | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/core/src/com/riiablo/map/DT1.java b/core/src/com/riiablo/map/DT1.java index 7075ae6a..a60baf0f 100644 --- a/core/src/com/riiablo/map/DT1.java +++ b/core/src/com/riiablo/map/DT1.java @@ -34,6 +34,9 @@ public class DT1 implements Disposable { private static final int X_JUMP[] = { 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14 }; private static final int PIXEL_WIDTH[] = { 4, 8, 12, 16, 20, 24, 28, 32, 28, 24, 20, 16, 12, 8, 4 }; + // Used to disable loading GL data for textures in headless mode + public static boolean loadData = true; + String fileName; Header header; Tile tiles[]; @@ -54,16 +57,19 @@ public class DT1 implements Disposable { } public TextureRegion getTexture(int i) { + assert loadData : "GL function called in non-GL mode"; return tiles[i].texture; } @Override public void dispose() { + if (!loadData) return; if (textures == null) return; for (Texture texture : textures) texture.dispose(); } public void prepareTextures() { + if (!loadData) return; Validate.validState(textures == null, "textures have already been prepared"); textures = new Texture[header.numTiles]; for (int i = 0; i < header.numTiles; i++) { @@ -94,6 +100,7 @@ public class DT1 implements Disposable { if (DEBUG_TILE_HEADERS) Gdx.app.debug(TAG, tile.toString()); } + if (loadData) { for (Tile tile : tiles) { Block[] blockHeaders = tile.blocks = new Block[tile.numBlocks]; for (int i = 0; i < tile.numBlocks; i++) { @@ -109,6 +116,7 @@ public class DT1 implements Disposable { } assert in.available() == 0; + } return new DT1(fileName, header, tiles); } catch (Throwable t) { throw new GdxRuntimeException("Couldn't read DT1", t); diff --git a/core/src/com/riiablo/map/DT1Loader.java b/core/src/com/riiablo/map/DT1Loader.java index 86c9be98..7932e87f 100644 --- a/core/src/com/riiablo/map/DT1Loader.java +++ b/core/src/com/riiablo/map/DT1Loader.java @@ -31,7 +31,7 @@ public class DT1Loader extends AsynchronousAssetLoader { - public DT1s dt1s; - - public static DT1LoaderParameters newInstance(DT1s dt1s) { - DT1LoaderParameters params = new DT1LoaderParameters(); - params.dt1s = dt1s; - return params; - } +// This was never implemented -- should be handled by map -- kept in case it is eventually needed +// public DT1s dt1s; +// +// public static DT1LoaderParameters newInstance(DT1s dt1s) { +// DT1LoaderParameters params = new DT1LoaderParameters(); +// params.dt1s = dt1s; +// return params; +// } } } diff --git a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java index 83bbf223..3840e8f3 100644 --- a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java +++ b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java @@ -36,6 +36,10 @@ import com.riiablo.engine.server.ObjectInitializer; import com.riiablo.engine.server.ServerEntityFactory; import com.riiablo.engine.server.ServerNetworkIdManager; import com.riiablo.engine.server.component.Networked; +import com.riiablo.map.DS1; +import com.riiablo.map.DS1Loader; +import com.riiablo.map.DT1; +import com.riiablo.map.DT1Loader; import com.riiablo.map.Map; import com.riiablo.mpq.MPQFileHandleResolver; import com.riiablo.net.packet.d2gs.Connection; @@ -186,6 +190,11 @@ public class D2GS extends ApplicationAdapter { Riiablo.cofs = new COFs(Riiablo.assets); // TODO: not needed in prod Riiablo.anim = D2.loadFromFile(Riiablo.mpqs.resolve("data\\global\\eanimdata.d2")); + // set DT1 to headless mode + DT1.loadData = false; + Riiablo.assets.setLoader(DS1.class, new DS1Loader(Riiablo.mpqs)); + Riiablo.assets.setLoader(DT1.class, new DT1Loader(Riiablo.mpqs)); + if (seed == 0) { Gdx.app.log(TAG, "Generating seed..."); seed = 0; @@ -199,11 +208,9 @@ public class D2GS extends ApplicationAdapter { map.generate(0); Gdx.app.log(TAG, " act 1 generated in " + (TimeUtils.millis() - start) + "ms"); -// Gdx.app.log(TAG, "Loading act 1..."); -// Riiablo.assets.setLoader(DS1.class, new DS1Loader(Riiablo.mpqs)); -// Riiablo.assets.setLoader(DT1.class, new DT1Loader(Riiablo.mpqs)); -// map.load(); -// map.finishLoading(); + Gdx.app.log(TAG, "Loading act 1..."); + map.load(); + map.finishLoading(); factory = new ServerEntityFactory(); sync = new NetworkSynchronizer();