diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 17f65a3a..1ddfe4bb 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1879,12 +1879,11 @@ Floating world origin - Separately simulated regions of physics that dynamically merge/unmerge based on chunk loading Bug Fixes - - Fix characters stored in db not saving items because the items aren't being stored to db - Fix hitbox placement does not scale with entity scale on server - Calculate bounding sphere for meshes by deforming vertices with bone default pose instead of no bone deform - Fix light cluster mapping for foliage shader - Fix flickering when applying yoga signal (may need to rethink arch here) - - Fix virtual scrollables not working + - Fix particles not placing correctly on spawning Startup Performance - Allow texture map to bind multiple model paths to a single set of mesh->textures diff --git a/src/main/java/electrosphere/script/ScriptContext.java b/src/main/java/electrosphere/script/ScriptContext.java index 07e45221..e2dd1dd2 100644 --- a/src/main/java/electrosphere/script/ScriptContext.java +++ b/src/main/java/electrosphere/script/ScriptContext.java @@ -247,7 +247,7 @@ public class ScriptContext { /** * Compiles the project */ - protected void compile(){ + protected void compileInContext(){ ScriptFileChecksumMap checksumMap = this.parent.getChecksumMap(); //actually compile this.invokeMemberFunction("COMPILER", "run"); @@ -286,6 +286,54 @@ public class ScriptContext { this.parent.writeChecksumMap(); } + /** + * Compiles the project + */ + protected void compileOutsideContext(){ + ScriptFileChecksumMap checksumMap = this.parent.getChecksumMap(); + //actually compile + this.invokeMemberFunction("COMPILER", "run"); + try { + Process process = Runtime.getRuntime().exec("tsc"); + process.wait(); + } catch (IOException | InterruptedException e) { + throw new Error("Failed to execute typescript!", e); + } + Value fileMap = this.topLevelValue.getMember("COMPILER").getMember("fileMap"); + //register new files, update cache where appropriate + for(String key : fileMap.getMemberKeys()){ + Value fileData = fileMap.getMember(key); + String content = fileData.getMember("content").asString(); + String cacheFilePath = ScriptEngine.TS_SOURCE_CACHE_DIR + key; + File toWriteFile = new File(cacheFilePath); + + //make sure all containing folders exist + try { + Files.createDirectories(toWriteFile.getParentFile().toPath()); + } catch (IOException e) { + LoggerInterface.loggerFileIO.ERROR(e); + } + + //update cached timestamp + { + String pathRaw = toWriteFile.toPath() + ""; + 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() + ""); + } + + //write the actual file + try { + Files.writeString(toWriteFile.toPath(), content); + } catch (IOException e) { + LoggerInterface.loggerFileIO.ERROR(e); + } + } + //write out cache map file + this.parent.writeChecksumMap(); + } + /** * Recompiles the scripting engine */ diff --git a/src/main/java/electrosphere/script/ScriptEngine.java b/src/main/java/electrosphere/script/ScriptEngine.java index 1f1848fb..6080e3eb 100644 --- a/src/main/java/electrosphere/script/ScriptEngine.java +++ b/src/main/java/electrosphere/script/ScriptEngine.java @@ -178,7 +178,7 @@ public class ScriptEngine extends SignalServiceImpl { //compile if(!readCache){ - scriptContext.compile(); + scriptContext.compileInContext(); } //post init logic