hookmanager in scriptengine, upgrade to junit 5
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-07-12 17:56:23 -04:00
parent 94c19d7990
commit 068f3979b8
14 changed files with 246 additions and 155 deletions

View File

@ -1,30 +1,23 @@
import { Entity } from "/Scripts/engine/entity/entity"
/**
* Called every time an item is moved to a container
* A type of entity
*/
export const onMoveItemContainer: Array<Function> = [ ]
export type Item = Entity
/**
* Called every time an item is equipped
*/
export const onEquipItem: Array<Function> = [ ]
/**
* Called every time an item is unequipped
*/
export const onUnequipItem: Array<Function> = [ ]
/**
* Called every time the server commands the client to move items to another container
*/
export const onServerMoveItemContainer: Array<Function> = [ ]
/**
* Callbacks that fire every time the player's entity does specific actions
*/
export interface ClientInventory {
onMoveItemContainer: Array<Function>,
onEquipItem: Array<Function>,
onUnequipItem: Array<Function>,
export interface Inventory {
}
/**
* Fires any time an item changes containers
*/
export const SIGNAL_MOVE_ITEM: string = "moveItem"
/**
* A callback that fires when an item is moved from one container to another
*/
export type MoveItemCallback = (item: Item) => void

View File

@ -1,9 +1,16 @@
import { Engine } from '/Scripts/engine/engine-interface'
import { loggerScripts } from '/Scripts/compiler/host_access'
import { Client, NamespaceClient } from '/Scripts/client/client'
import { HookManager } from '/Scripts/engine/hook-manager'
//the core engine
let engine: Engine
/**
* The core engine values
*/
export const engine: Engine = {
classes: [],
singletons: [],
hookManager: new HookManager(),
}
/**
* Called when the script engine first initializes

View File

@ -1,9 +1,24 @@
import { HookManager } from "/Scripts/engine/hook-manager";
/**
* The host context that contains all core engine functions
*/
export interface Engine {
classes: any, //the host's view of the scripting engine
singletons: any, //the singletons available to the script engine
/**
* The host's view of the scripting engine
*/
classes: any,
/**
* The singletons available to the script engine
*/
singletons: any,
/**
* Manages all script-defined hooks in the engine
*/
hookManager: HookManager,
}

View File

@ -0,0 +1,10 @@
/**
* An entity
*/
export interface Entity {
id: number,
}

View File

@ -0,0 +1,170 @@
import { Hook } from "/Scripts/types/hook"
import { Scene } from "/Scripts/types/scene"
/**
* The scope that the hook is firing from
*/
export enum HookScope {
CORE,
SCRIPT,
SCENE_CLIENT,
SCENE_SERVER,
}
/**
* A hook that is tracked by the manager
*/
interface TrackedHook extends Hook {
/**
* The scope that this hook was defined at
*/
scope: HookScope,
/**
* The scene that added the hook
*/
scene?: TrackedScene,
}
/**
* A scene being tracked by the manager
*/
interface TrackedScene {
/**
* The id assigned to the scene
*/
sceneId: number,
/**
* The scene itself
*/
scene: Scene,
}
/**
* Manages hooks for the engine
*/
export class HookManager {
/**
* The list of all hooks currently tracked by this manager
*/
hooks: Array<TrackedHook> = []
/**
* A map of a scene to all hooks related to the scene
*/
sceneHookMap: Record<number,Array<TrackedHook>> = { }
/**
* A map of engine signal to the list of hooks that should be called when that signal fires
*/
signalHookMap: Record<string,Array<TrackedHook>> = { }
/**
* The list of all scenes tracked by the manager
*/
trackedScenes: Array<{ sceneId: number, scene: Scene }> = []
/**
* A scene
*/
sceneIdIncrementer: number = 0
/**
* Registers all hooks in a scene to the hook manager
* @param scene The scene
*/
registerScene(scene: Scene, isServerScene: boolean){
const shouldRegister: boolean = !this.containsScene(scene)
if(shouldRegister){
//add to the list of tracked scenes
const trackedScene: TrackedScene = {
sceneId: this.sceneIdIncrementer++,
scene: scene,
}
this.trackedScenes.push(trackedScene)
//load all hooks from the scene
scene.hooks.forEach((hook: Hook) => {
this.registerHook(trackedScene,hook,isServerScene)
})
}
}
/**
* Deregisters all hooks in a scene from the hook manager
* @param scene The scene
*/
deregisterScene(scene: Scene){
throw new Error("Unsupported Operation!")
}
/**
* Checks if the manager is tracking a given scene
* @param scene The scene
* @returns true if it is being tracked already, false otherwise
*/
containsScene(scene: Scene): boolean {
this.trackedScenes.forEach(trackedScene => {
if(trackedScene.scene === scene){
return true
}
})
return false
}
/**
* Registers a hook
* @param scene The scene introducing the hook
* @param hook The hook
*/
registerHook(scene: TrackedScene, hook: Hook, isServerScene: boolean){
const trackedHook: TrackedHook = {
...hook,
scope: isServerScene ? HookScope.SCENE_SERVER : HookScope.SCENE_CLIENT,
scene: scene,
}
//add to flat array
this.hooks.push(trackedHook)
//add to signal array
const hookSignal: string = hook.signal
const signalArray: Array<TrackedHook> = this.signalHookMap?.[hookSignal] ? this.signalHookMap?.[hookSignal] : []
signalArray.push(trackedHook)
this.signalHookMap[hookSignal] = signalArray
//add to scene array
const sceneArray: Array<TrackedHook> = this.sceneHookMap?.[scene.sceneId] ? this.sceneHookMap?.[scene.sceneId] : []
sceneArray.push(trackedHook)
this.sceneHookMap[scene.sceneId] = sceneArray
}
/**
* Deregisters a hook
* @param scene The scene which introduced the hook
* @param hook The hook
*/
deregisterHook(scene: Scene, hook: Hook){
throw new Error("Supported operation!")
}
/**
* Fires a signal
* @param signal The signal
* @param value The value associated with the signal
*/
fireSignal(signal: string, value: any){
const hooks: Array<TrackedHook> = this.signalHookMap[signal]
hooks.forEach(trackedHook => {
trackedHook.callback(value)
})
}
}

View File

@ -1,4 +1,3 @@
import { Scene } from "/Scripts/types/scene";
/**
@ -9,47 +8,11 @@ export interface Hook {
/**
* The signal that triggers this hook in particular
*/
signal: any,
signal: string,
/**
* The function to call when the signal is fired
*/
callback: Function,
}
/**
* The scope that the hook is firing from
*/
export enum HookScope {
CORE,
SCRIPT,
SCENE_CLIENT,
SCENE_SERVER,
}
/**
* A hook that is tracked by the manager
*/
export interface TrackedHook extends Hook {
/**
* The scope that this hook was defined at
*/
scope: HookScope,
/**
* The scene that added the hook
*/
scene?: Scene,
}
/**
* Manages hooks for the engine
*/
export class HookManager {
}

View File

@ -16,21 +16,6 @@ export function SynchronizedType() {
*/
export interface Scene extends Namespace {
/**
* Called when the current instance scene is first loaded
*/
onLoad?: Function
/**
* Called when the current instance of the scene is unloaded
*/
onUnload?: Function
/**
* Called when the current instance of the scene is saved -- either periodically or when the scene is being stored to disk
*/
onSave?: Function
/**
* Values that are synchronized between the client and server. They are also stored to disk when the scene saves
*/

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Sun Jul 07 21:24:47 EDT 2024
buildNumber=180
#Fri Jul 12 17:46:19 EDT 2024
buildNumber=182

View File

@ -14,6 +14,7 @@
<recast.version>1.5.7</recast.version>
<imgui.version>1.86.11</imgui.version>
<graalvm.version>23.1.3</graalvm.version>
<junit.version>5.10.3</junit.version>
</properties>
<!-- Used for build number plugin because it LITERALLY WONT LET YOU NOT HAVE SCM-->
@ -166,9 +167,9 @@
<!--JUnit-->
<!--License: Eclipse Public License-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
</dependency>
<!--GraalVM-->

View File

@ -3,23 +3,16 @@ package electrosphere.entity;
import electrosphere.engine.Globals;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.logger.LoggerInterface;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3d;
import org.joml.Vector3f;
/**
*
* @author satellite
* A game scene
*/
public class Scene {

View File

@ -1,50 +0,0 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import entity.SpawningCreaturesTest;
import startup.StartupTest;
import testutils.TestEngineUtils;
public class TestRunner {
/**
* The list of classes to run tests for
*/
static final List<Class<?>> classes = Arrays.asList(new Class[]{
StartupTest.class,
SpawningCreaturesTest.class,
});
/**
* Runs tests
* @param args Args provided
*/
public static void main(String[] args){
boolean success = true;
List<Failure> failures = new LinkedList<Failure>();
//run tests
for(Class<?> classObject : classes){
TestEngineUtils.log("CLASS " + classObject.getCanonicalName());
Result result = JUnitCore.runClasses(classObject);
for(Failure failure : result.getFailures()){
failures.add(failure);
}
success = success && result.wasSuccessful();
}
//print failures
for(Failure failure : failures){
TestEngineUtils.log(failure + "");
}
TestEngineUtils.log("Testing was successful: " + success);
}
}

View File

@ -2,9 +2,10 @@ package electrosphere.renderer.ui.elements;
import java.awt.image.BufferedImage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
@ -18,7 +19,8 @@ import testutils.TestEngineUtils;
*/
public class WindowIntegrationTest {
@Before
@BeforeEach
@Tag("integration")
/**
* Initializes the engine
*/
@ -27,6 +29,7 @@ public class WindowIntegrationTest {
}
@Test
@Tag("integration")
/**
* Tests creating a window
*/
@ -39,7 +42,8 @@ public class WindowIntegrationTest {
}
@After
@AfterEach
@Tag("integration")
/**
* Shuts down the engine
*/

View File

@ -1,7 +1,7 @@
package entity;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
@ -11,7 +11,7 @@ import electrosphere.net.NetUtils;
public class SpawningCreaturesTest {
@Before
@BeforeEach
public void initEngine(){
LoggerInterface.loggerEngine.INFO("[Test] Spawn many creatures");
Globals.RUN_CLIENT = true;

View File

@ -1,14 +1,14 @@
package startup;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.engine.profiler.Profiler;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.NetUtils;
import junit.framework.TestCase;
public class StartupTest extends TestCase {
public class StartupTest {
@Test
public void testStartupHeadless(){