Skip to content

Commit

Permalink
fix map script caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Frotty committed Mar 3, 2024
1 parent e17502c commit 55812d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public Object execute(ModelManager modelManager) throws IOException {
throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
}

MapRequest.mapLastModified = map.get().lastModified();
MapRequest.mapPath = map.get().getAbsolutePath();

gui.sendProgress("Copying map");

// first we copy in same location to ensure validity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public abstract class MapRequest extends UserRequest<Object> {
protected final W3InstallationData w3data;
protected final TimeTaker timeTaker;

public static long mapLastModified = 0L;
public static String mapPath = "";

private static Long lastMapModified = 0L;
private static String lastMapPath = "";

/**
* makes the compilation slower, but more safe by discarding results from the editor and working on a copy of the model
*/
Expand Down Expand Up @@ -378,7 +384,6 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
return result;
}

private static Long lastMapModified = 0L;

private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, WurstGui gui) throws Exception {
File scriptFile = new File(new File(workspaceRoot.getFile(), "wurst"), "war3map.j");
Expand All @@ -393,10 +398,10 @@ private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, Wu
"RunArg noExtractMapScript is set but no mapscript is provided inside the wurst folder");
}
}
long mapLastModified = mapCopy.get().lastModified();
if (mapLastModified > lastMapModified) {
lastMapModified = mapLastModified;
WLogger.info("extracting mapscript");
if (MapRequest.mapLastModified > lastMapModified || !MapRequest.mapPath.equals(lastMapPath)) {
lastMapModified = MapRequest.mapLastModified;
lastMapPath = MapRequest.mapPath;
System.out.println("Map not cached yet, extracting script");
byte[] extractedScript = null;
try (@Nullable MpqEditor mpqEditor = MpqEditorFactory.getEditor(mapCopy, true)) {
if (mpqEditor.hasFile("war3map.j")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectC

// first we copy in same location to ensure validity
File buildDir = getBuildDir();
mapLastModified = map.get().lastModified();
mapPath = map.get().getAbsolutePath();
Optional<File> testMap = map.map($ -> new File(buildDir, "WurstRunMap.w3x"));
CompilationResult result = compileScript(modelManager, gui, testMap, projectConfig, buildDir, false);

Expand Down

0 comments on commit 55812d7

Please sign in to comment.