framestep work
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				studiorailgun/Renderer/pipeline/head There was a failure building this commit
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	studiorailgun/Renderer/pipeline/head There was a failure building this commit
				
			This commit is contained in:
		
							parent
							
								
									23f745c450
								
							
						
					
					
						commit
						e00eb85bcb
					
				| @ -1,3 +1,4 @@ | ||||
| import { engine } from "/Scripts/engine/engine-init"; | ||||
| import { Scene } from "/Scripts/types/scene"; | ||||
| import { Vector } from "/Scripts/types/spatial"; | ||||
| 
 | ||||
| @ -27,6 +28,7 @@ class TestScene1 extends Scene { | ||||
|             signal: "equipItem", | ||||
|             callback: (entityId: number) => { | ||||
|                 console.log("Item equipped to entity " + entityId) | ||||
|                 engine.classes.simulation.static.setFramestep(0) | ||||
|             } | ||||
|         }, | ||||
| 
 | ||||
| @ -47,6 +49,7 @@ class TestScene1 extends Scene { | ||||
|             signal: "itemPickup", | ||||
|             callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => { | ||||
|                 console.log(entityId + ' picked up an item, destroying ' + inWorldItemEntityId + ' and creating ' + inInventoryItemEntityId) | ||||
|                 engine.classes.simulation.static.setFramestep(2) | ||||
|             } | ||||
|         }, | ||||
| 
 | ||||
|  | ||||
| @ -8,8 +8,8 @@ import { Engine } from '/Scripts/types/engine' | ||||
|  * The core engine values | ||||
|  */ | ||||
| export const engine: Engine = { | ||||
|     classes: [], | ||||
|     singletons: [], | ||||
|     classes: {}, | ||||
|     singletons: {}, | ||||
|     hookManager: new HookManager(), | ||||
|     sceneLoader: new SceneLoader(), | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,7 @@ | ||||
| import { HookManager } from "/Scripts/engine/hooks/hook-manager"; | ||||
| import { SceneLoader } from "/Scripts/engine/scene/scene-loader"; | ||||
| import { SingletonsMap } from "/Scripts/types/host/singletons"; | ||||
| import { StaticClasses } from "/Scripts/types/host/static-classes"; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
| @ -10,12 +12,12 @@ export interface Engine { | ||||
|     /** | ||||
|      * The host's view of the scripting engine | ||||
|      */ | ||||
|     readonly classes: any, | ||||
|     readonly classes: StaticClasses, | ||||
| 
 | ||||
|     /** | ||||
|      * The singletons available to the script engine | ||||
|      */ | ||||
|     readonly singletons: any, | ||||
|     readonly singletons: SingletonsMap, | ||||
| 
 | ||||
|     /** | ||||
|      * Manages all script-defined hooks in the engine | ||||
| @ -29,32 +31,3 @@ export interface Engine { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * The singletons from the host that are accessible in scripts | ||||
|  */ | ||||
| export interface SingletonsMap { | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Timekeeper that tracks engine time and frame count | ||||
|      */ | ||||
|     timekeeper: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The object for the current player (if in single player non-headless client) | ||||
|      */ | ||||
|     currentPlayer: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The scripts logger | ||||
|      */ | ||||
|     loggerScripts: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The scripts engine | ||||
|      */ | ||||
|     scriptEngine: any, | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										28
									
								
								assets/Scripts/types/host/singletons.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								assets/Scripts/types/host/singletons.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| 
 | ||||
| /** | ||||
|  * The singletons from the host that are accessible in scripts | ||||
|  */ | ||||
| export interface SingletonsMap { | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Timekeeper that tracks engine time and frame count | ||||
|      */ | ||||
|     readonly timekeeper?: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The object for the current player (if in single player non-headless client) | ||||
|      */ | ||||
|     readonly currentPlayer?: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The scripts logger | ||||
|      */ | ||||
|     readonly loggerScripts?: any, | ||||
| 
 | ||||
|     /** | ||||
|      * The scripts engine | ||||
|      */ | ||||
|     readonly scriptEngine?: any, | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										46
									
								
								assets/Scripts/types/host/static-classes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								assets/Scripts/types/host/static-classes.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Static classes provided to the script environment | ||||
|  */ | ||||
| export interface StaticClasses { | ||||
| 
 | ||||
|     /** | ||||
|      * Utility functions for doing math | ||||
|      */ | ||||
|     readonly mathUtils?: any, | ||||
| 
 | ||||
|     /** | ||||
|      * Simulation processing related functions | ||||
|      */ | ||||
|     readonly simulation?: Class<SimulationClass>, | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * A class file | ||||
|  */ | ||||
| export interface Class<T> { | ||||
|     /** | ||||
|      * The static values of the class | ||||
|      */ | ||||
|     static: T, | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * The simulation processing class | ||||
|  */ | ||||
| export interface SimulationClass { | ||||
| 
 | ||||
|     /** | ||||
|      * Sets the simulation frame count | ||||
|      * 0 - Do not simulate any frames | ||||
|      * 1 - Simulate a single frame | ||||
|      * 2+ - Simulate indefinitely | ||||
|      * Values lower than 0 are ignored | ||||
|      * @param value The frame count | ||||
|      */ | ||||
|     readonly setFramestep: (value: number) => void, | ||||
| 
 | ||||
| } | ||||
| @ -3,8 +3,7 @@ | ||||
| + there is a sword lying on the ground | ||||
| + when you grab the sword, a tutorial popup appears to tell you how to use in | ||||
| + on clearing the tutorial, continue the game+ when the sword is equipped, create another popup to teach sword controls. it pauses the game | ||||
|   script ability to pause and unpause game | ||||
| + when popup is accepted, spawn an rnemy with an effect | ||||
| + when popup is accepted, spawn an enemy with an effect | ||||
|   enemy ai | ||||
|   review effects | ||||
|   review combat code (lifestate, damage calculation, etc) | ||||
|  | ||||
| @ -434,6 +434,10 @@ Hooks debugging | ||||
| On add item to inventory hook | ||||
| Hook manager debugging | ||||
| 
 | ||||
| (07/20/2024) | ||||
| Properly drill static classes to script context | ||||
| Expose framestep control to script side | ||||
| 
 | ||||
| 
 | ||||
| # TODO | ||||
| 
 | ||||
|  | ||||
| @ -6,6 +6,8 @@ import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose; | ||||
| import java.lang.management.ManagementFactory; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import org.graalvm.polyglot.HostAccess.Export; | ||||
| 
 | ||||
| import org.ode4j.ode.OdeHelper; | ||||
| 
 | ||||
| import electrosphere.audio.AudioEngine; | ||||
| @ -475,6 +477,7 @@ public class Main { | ||||
|      * Sets the framestep state (2 to resume automatic, 1 to make single step) | ||||
|      * @param framestep 2 - automatic framestep, 1 - single step, 0 - no step | ||||
|      */ | ||||
|     @Export | ||||
|     public static void setFramestep(int framestep){ | ||||
|         Main.framestep = framestep; | ||||
|     } | ||||
|  | ||||
| @ -14,6 +14,7 @@ import org.graalvm.polyglot.Source.Builder; | ||||
| import org.graalvm.polyglot.Value; | ||||
| 
 | ||||
| import electrosphere.engine.Globals; | ||||
| import electrosphere.engine.Main; | ||||
| import electrosphere.logger.LoggerInterface; | ||||
| import electrosphere.util.FileUtils; | ||||
| import electrosphere.util.MathUtils; | ||||
| @ -81,6 +82,7 @@ public class ScriptEngine { | ||||
|     //https://stackoverflow.com/a/65942034 | ||||
|     static final Object[][] staticClasses = new Object[][]{ | ||||
|         {"mathUtils",MathUtils.class}, | ||||
|         {"simulation",Main.class}, | ||||
|     }; | ||||
| 
 | ||||
|     //singletons from the host that are provided to the javascript context | ||||
| @ -124,9 +126,6 @@ public class ScriptEngine { | ||||
|             loadDependency(fileToLoad); | ||||
|         } | ||||
| 
 | ||||
|         //define host members | ||||
|         defineHostMembers(); | ||||
| 
 | ||||
|         //register engine files | ||||
|         registerFile("/Scripts/engine/engine-init.ts"); | ||||
| 
 | ||||
| @ -135,9 +134,15 @@ public class ScriptEngine { | ||||
| 
 | ||||
|         //run script for engine init | ||||
|         requireModule("/Scripts/engine/engine-init.ts"); | ||||
| 
 | ||||
|         //get the engine object | ||||
|         engineObject = topLevelValue.getMember("REQUIRE_CACHE").getMember("/Scripts/engine/engine-init.js").getMember("exports").getMember("engine"); | ||||
|         hookManager = engineObject.getMember("hookManager"); | ||||
| 
 | ||||
|         //define host members | ||||
|         defineHostMembers(); | ||||
| 
 | ||||
|         //init on script side | ||||
|         invokeModuleFunction("/Scripts/engine/engine-init.ts","ENGINE_onInit"); | ||||
| 
 | ||||
| 
 | ||||
| @ -382,7 +387,7 @@ public class ScriptEngine { | ||||
|     private void defineHostMembers(){ | ||||
|         hostObject = topLevelValue.getMember("HOST_ACCESS"); | ||||
|         //give guest access to static classes | ||||
|         Value classes = hostObject.getMember("classes"); | ||||
|         Value classes = engineObject.getMember("classes"); | ||||
|         for(Object[] currentClass : staticClasses){ | ||||
|             classes.putMember((String)currentClass[0], currentClass[1]); | ||||
|         } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user