Added support to set DT1 class to headless loading mode

This commit is contained in:
Collin Smith 2019-12-16 05:36:13 -08:00
parent 4ea338312c
commit c677ca415d
3 changed files with 29 additions and 13 deletions

View File

@ -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);

View File

@ -31,7 +31,7 @@ public class DT1Loader extends AsynchronousAssetLoader<DT1, DT1Loader.DT1LoaderP
}
dt1.prepareTextures();
if (params != null) params.dt1s.add(dt1);
// if (params != null) params.dt1s.add(dt1); // See below note
return dt1;
}
@ -41,13 +41,14 @@ public class DT1Loader extends AsynchronousAssetLoader<DT1, DT1Loader.DT1LoaderP
}
public static class DT1LoaderParameters extends AssetLoaderParameters<DT1> {
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;
// }
}
}

View File

@ -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();