fix out-of-context tsc caching
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
b58e96f315
commit
0b404723cc
@ -1842,6 +1842,7 @@ Physics numbers reworked
|
|||||||
Capsule-BlockChunk collision correction in collidable trees
|
Capsule-BlockChunk collision correction in collidable trees
|
||||||
Out-of-context typescript compilation that falls back to in-context compilation
|
Out-of-context typescript compilation that falls back to in-context compilation
|
||||||
Fix opengl bug
|
Fix opengl bug
|
||||||
|
Fix typescript out-of-context compilation caching
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.lang.ProcessBuilder.Redirect;
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@ -218,6 +219,19 @@ public class ScriptContext {
|
|||||||
String content;
|
String content;
|
||||||
try {
|
try {
|
||||||
content = FileUtils.getAssetFileAsString(path);
|
content = FileUtils.getAssetFileAsString(path);
|
||||||
|
this.registerFile(path, content);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LoggerInterface.loggerScripts.ERROR("FAILED TO LOAD SCRIPT", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a file with the scripting engine to be compiled into the full binary
|
||||||
|
* @param path The path to the script file
|
||||||
|
*/
|
||||||
|
protected void registerFile(String path, String content){
|
||||||
Value dependentFilesValue = this.invokeMemberFunction("COMPILER", "registerFile", path, content);
|
Value dependentFilesValue = this.invokeMemberFunction("COMPILER", "registerFile", path, content);
|
||||||
//
|
//
|
||||||
//register dependent files if necessary
|
//register dependent files if necessary
|
||||||
@ -239,11 +253,6 @@ public class ScriptContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
LoggerInterface.loggerScripts.ERROR("FAILED TO LOAD SCRIPT", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -317,10 +326,18 @@ public class ScriptContext {
|
|||||||
Files.walk(new File(".cache/tscache/src").toPath()).forEach((Path currPath) -> {
|
Files.walk(new File(".cache/tscache/src").toPath()).forEach((Path currPath) -> {
|
||||||
if(!currPath.toFile().isDirectory()){
|
if(!currPath.toFile().isDirectory()){
|
||||||
String pathRaw = currPath.toString();
|
String pathRaw = currPath.toString();
|
||||||
pathRaw = pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/");
|
pathRaw = pathRaw.replace(".cache\\tscache\\src\\", "./assets/");
|
||||||
File correspondingFile = new File(pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/"));
|
File correspondingFile = new File(pathRaw.replace(".cache\\tscache\\src\\", "./assets/"));
|
||||||
String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
|
String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
|
||||||
checksumMap.getFileLastModifyMap().put(cacheKey, correspondingFile.lastModified() + "");
|
long lastModified = correspondingFile.lastModified();
|
||||||
|
try {
|
||||||
|
FileTime time = Files.getLastModifiedTime(currPath);
|
||||||
|
lastModified = time.toMillis();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error("Failed to gather last modified time! " + lastModified);
|
||||||
|
}
|
||||||
|
checksumMap.getFileLastModifyMap().put(cacheKey, lastModified + "");
|
||||||
|
LoggerInterface.loggerScripts.DEBUG("Putting file in cache " + cacheKey + " " + lastModified);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@ -236,7 +236,7 @@ public class ScriptEngine extends SignalServiceImpl {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//read file checksum map from disk if it exists
|
//read file checksum map from disk if it exists
|
||||||
File hashMapFile = new File(ScriptEngine.TS_SOURCE_CACHE_DIR + "/hashmap.json");
|
File hashMapFile = new File(ScriptEngine.TS_CACHE_DIR + "/hashmap.json");
|
||||||
if(hashMapFile.exists()){
|
if(hashMapFile.exists()){
|
||||||
this.checksumMap = FileUtils.loadObjectFromFile(hashMapFile, ScriptFileChecksumMap.class);
|
this.checksumMap = FileUtils.loadObjectFromFile(hashMapFile, ScriptFileChecksumMap.class);
|
||||||
}
|
}
|
||||||
@ -297,6 +297,12 @@ public class ScriptEngine extends SignalServiceImpl {
|
|||||||
LoggerInterface.loggerScripts.DEBUG("Preload: " + normalizedPath);
|
LoggerInterface.loggerScripts.DEBUG("Preload: " + normalizedPath);
|
||||||
this.scriptContext.getTopLevelValue("COMPILER").invokeMember("preloadFile", normalizedPath, fileContent);
|
this.scriptContext.getTopLevelValue("COMPILER").invokeMember("preloadFile", normalizedPath, fileContent);
|
||||||
} else {
|
} else {
|
||||||
|
boolean inMap = fileLastModifyMap.containsKey(normalizedPath);
|
||||||
|
boolean timeMatch = false;
|
||||||
|
if(inMap){
|
||||||
|
timeMatch = fileLastModifyMap.get(normalizedPath).contains(correspondingSourceFile.lastModified() + "");
|
||||||
|
}
|
||||||
|
LoggerInterface.loggerScripts.DEBUG("Skipping Preload: " + normalizedPath + " " + inMap + " " + timeMatch);
|
||||||
rVal = false;
|
rVal = false;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -319,7 +325,7 @@ public class ScriptEngine extends SignalServiceImpl {
|
|||||||
* Writes the checksum map to disk
|
* Writes the checksum map to disk
|
||||||
*/
|
*/
|
||||||
protected void writeChecksumMap(){
|
protected void writeChecksumMap(){
|
||||||
File hashMapFile = new File(ScriptEngine.TS_SOURCE_CACHE_DIR + "/hashmap.json");
|
File hashMapFile = new File(ScriptEngine.TS_CACHE_DIR + "/hashmap.json");
|
||||||
//write cache map out
|
//write cache map out
|
||||||
FileUtils.serializeObjectToFilePath(hashMapFile, this.checksumMap);
|
FileUtils.serializeObjectToFilePath(hashMapFile, this.checksumMap);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user