script recompilation work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-16 12:51:08 -04:00
parent 0b404723cc
commit dfd5932675
6 changed files with 59 additions and 9 deletions

View File

@ -66,9 +66,18 @@ export const clientHooks: Hook[] = [
engine.classes.areaUtils.static.selectAreaRectangular() engine.classes.areaUtils.static.selectAreaRectangular()
} }
}, },
{
signal: "ROOM_TOOL_TOGGLE",
callback: (engine: Engine) => {
engine.singletons.loggerScripts.WARNING('asdf')
engine.singletons.loggerScripts.WARNING(JSON.stringify(globalThis))
}
},
{ {
signal: "ROOM_TOOL_MENU", signal: "ROOM_TOOL_MENU",
callback: (engine: Engine) => { callback: (engine: Engine) => {
engine.singletons.loggerScripts.WARNING('asdf')
engine.singletons.loggerScripts.WARNING(JSON.stringify(globalThis))
engine.classes.menuUtils.static.openDialog('Data/menu/room/roomToolConfig.html') engine.classes.menuUtils.static.openDialog('Data/menu/room/roomToolConfig.html')
} }
}, },

View File

@ -0,0 +1,9 @@
/**
* The top level variable that should be used to store data
*/
let Document = {
}

View File

@ -19,6 +19,9 @@ export const engine: Engine = {
playerState: defaultPlayerState, playerState: defaultPlayerState,
} }
//store engine in globalThis
globalThis.engine = engine;
/** /**
* Called when the script engine first initializes * Called when the script engine first initializes
*/ */

View File

@ -1843,6 +1843,7 @@ 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 Fix typescript out-of-context compilation caching
Script recompilation work

View File

@ -281,9 +281,17 @@ public class ScriptContext {
{ {
String pathRaw = toWriteFile.toPath() + ""; String pathRaw = toWriteFile.toPath() + "";
pathRaw = 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("\\", "/"); String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
checksumMap.getFileLastModifyMap().put(cacheKey, correspondingFile.lastModified() + ""); long lastModified = 0;
try {
File correspondingSourceFile = new File(pathRaw.replace(".cache\\tscache\\src\\", "./assets/").replace(".js",".ts"));
FileTime time = Files.getLastModifiedTime(correspondingSourceFile.toPath());
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);
} }
//write the actual file //write the actual file
@ -327,11 +335,11 @@ public class ScriptContext {
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/"));
String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/"); String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
long lastModified = correspondingFile.lastModified(); long lastModified = 0;
try { try {
FileTime time = Files.getLastModifiedTime(currPath); File correspondingSourceFile = new File(pathRaw.replace(".cache\\tscache\\src\\", "./assets/").replace(".js",".ts"));
FileTime time = Files.getLastModifiedTime(correspondingSourceFile.toPath());
lastModified = time.toMillis(); lastModified = time.toMillis();
} catch (IOException e) { } catch (IOException e) {
throw new Error("Failed to gather last modified time! " + lastModified); throw new Error("Failed to gather last modified time! " + lastModified);

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import java.nio.file.FileSystem; import java.nio.file.FileSystem;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import java.nio.file.attribute.FileTime;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -96,6 +97,9 @@ public class ScriptEngine extends SignalServiceImpl {
"Scripts/compiler/file_resolution.js", "Scripts/compiler/file_resolution.js",
"Scripts/compiler/compiler.js", "Scripts/compiler/compiler.js",
"Scripts/compiler/host_access.js", "Scripts/compiler/host_access.js",
//global context
"Scripts/compiler/context.js",
}; };
/** /**
@ -178,9 +182,13 @@ public class ScriptEngine extends SignalServiceImpl {
//compile //compile
if(!readCache){ if(!readCache){
LoggerInterface.loggerScripts.WARNING("Recompiling scripts");
if(!scriptContext.compileOutsideContext()){ if(!scriptContext.compileOutsideContext()){
scriptContext.compileInContext(); scriptContext.compileInContext();
} }
if(!this.initCache()){
throw new Error("Failed to compile!");
}
} }
//post init logic //post init logic
@ -272,13 +280,25 @@ public class ScriptEngine extends SignalServiceImpl {
String relativePath = FileUtils.relativize(file, tsCache); String relativePath = FileUtils.relativize(file, tsCache);
String normalizedPath = "/" + relativePath; String normalizedPath = "/" + relativePath;
boolean shouldLoad = true; boolean shouldLoad = true;
File correspondingSourceFile = FileUtils.getAssetFile(compoundedPath + "/" + file.getName()); File correspondingSourceFile = FileUtils.getAssetFile(compoundedPath + "/" + file.getName().replace(".js", ".ts"));
long lastModified = 0;
if(correspondingSourceFile.exists()){
try {
FileTime time = Files.getLastModifiedTime(correspondingSourceFile.toPath());
lastModified = time.toMillis();
} catch (IOException e) {
throw new Error("Failed to gather last modified time! " + lastModified);
}
} else {
shouldLoad = false;
}
//determine if we should load the file //determine if we should load the file
if(!fileLastModifyMap.containsKey(normalizedPath)){ if(!fileLastModifyMap.containsKey(normalizedPath)){
//cache does not contain this file //cache does not contain this file
shouldLoad = false; shouldLoad = false;
} else if(!fileLastModifyMap.get(normalizedPath).contains(correspondingSourceFile.lastModified() + "")) { } else if(!fileLastModifyMap.get(normalizedPath).contains(lastModified + "")) {
//cache is up to date //cache is up to date
shouldLoad = false; shouldLoad = false;
} }
@ -300,9 +320,9 @@ public class ScriptEngine extends SignalServiceImpl {
boolean inMap = fileLastModifyMap.containsKey(normalizedPath); boolean inMap = fileLastModifyMap.containsKey(normalizedPath);
boolean timeMatch = false; boolean timeMatch = false;
if(inMap){ if(inMap){
timeMatch = fileLastModifyMap.get(normalizedPath).contains(correspondingSourceFile.lastModified() + ""); timeMatch = fileLastModifyMap.get(normalizedPath).contains(lastModified + "");
} }
LoggerInterface.loggerScripts.DEBUG("Skipping Preload: " + normalizedPath + " " + inMap + " " + timeMatch); LoggerInterface.loggerScripts.DEBUG("Skipping Preload: " + normalizedPath + " " + inMap + " " + timeMatch + " " + correspondingSourceFile.exists() + " " + lastModified + " " + correspondingSourceFile.toString());
rVal = false; rVal = false;
} }
} catch (IOException e) { } catch (IOException e) {