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
|
||||
Out-of-context typescript compilation that falls back to in-context compilation
|
||||
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.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -218,27 +219,7 @@ public class ScriptContext {
|
||||
String content;
|
||||
try {
|
||||
content = FileUtils.getAssetFileAsString(path);
|
||||
Value dependentFilesValue = this.invokeMemberFunction("COMPILER", "registerFile", path, content);
|
||||
//
|
||||
//register dependent files if necessary
|
||||
long dependentFilesCount = dependentFilesValue.getArraySize();
|
||||
if(dependentFilesCount > 0){
|
||||
for(int i = 0; i < dependentFilesCount; i++){
|
||||
String dependentFilePath = dependentFilesValue.getArrayElement(i).asString();
|
||||
boolean shouldRegister = true;
|
||||
for(String ignorePath : ScriptEngine.registerIgnores){
|
||||
if(ignorePath.equals(dependentFilePath)){
|
||||
shouldRegister = false;
|
||||
}
|
||||
}
|
||||
if(shouldRegister){
|
||||
LoggerInterface.loggerScripts.INFO("[HOST - Script Engine] Should register file " + dependentFilePath);
|
||||
this.registerFile(dependentFilePath);
|
||||
} else {
|
||||
LoggerInterface.loggerScripts.DEBUG("[HOST - Script Engine] Skipping ignorepath file " + dependentFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.registerFile(path, content);
|
||||
} catch (IOException e) {
|
||||
LoggerInterface.loggerScripts.ERROR("FAILED TO LOAD SCRIPT", e);
|
||||
return false;
|
||||
@ -246,6 +227,34 @@ public class ScriptContext {
|
||||
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);
|
||||
//
|
||||
//register dependent files if necessary
|
||||
long dependentFilesCount = dependentFilesValue.getArraySize();
|
||||
if(dependentFilesCount > 0){
|
||||
for(int i = 0; i < dependentFilesCount; i++){
|
||||
String dependentFilePath = dependentFilesValue.getArrayElement(i).asString();
|
||||
boolean shouldRegister = true;
|
||||
for(String ignorePath : ScriptEngine.registerIgnores){
|
||||
if(ignorePath.equals(dependentFilePath)){
|
||||
shouldRegister = false;
|
||||
}
|
||||
}
|
||||
if(shouldRegister){
|
||||
LoggerInterface.loggerScripts.INFO("[HOST - Script Engine] Should register file " + dependentFilePath);
|
||||
this.registerFile(dependentFilePath);
|
||||
} else {
|
||||
LoggerInterface.loggerScripts.DEBUG("[HOST - Script Engine] Skipping ignorepath file " + dependentFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the project
|
||||
*/
|
||||
@ -317,10 +326,18 @@ public class ScriptContext {
|
||||
Files.walk(new File(".cache/tscache/src").toPath()).forEach((Path currPath) -> {
|
||||
if(!currPath.toFile().isDirectory()){
|
||||
String pathRaw = currPath.toString();
|
||||
pathRaw = pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/");
|
||||
File correspondingFile = new File(pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/"));
|
||||
pathRaw = pathRaw.replace(".cache\\tscache\\src\\", "./assets/");
|
||||
File correspondingFile = new File(pathRaw.replace(".cache\\tscache\\src\\", "./assets/"));
|
||||
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) {
|
||||
|
||||
@ -236,7 +236,7 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
}
|
||||
} else {
|
||||
//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()){
|
||||
this.checksumMap = FileUtils.loadObjectFromFile(hashMapFile, ScriptFileChecksumMap.class);
|
||||
}
|
||||
@ -297,6 +297,12 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
LoggerInterface.loggerScripts.DEBUG("Preload: " + normalizedPath);
|
||||
this.scriptContext.getTopLevelValue("COMPILER").invokeMember("preloadFile", normalizedPath, fileContent);
|
||||
} 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;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -319,7 +325,7 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
* Writes the checksum map to disk
|
||||
*/
|
||||
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
|
||||
FileUtils.serializeObjectToFilePath(hashMapFile, this.checksumMap);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user