Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Inputs #986

Merged
merged 17 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import UpdateAvailableModal from "@/modals/UpdateAvailableModal"
import ViewModal from "@/modals/ViewModal"
import ConnectToMultiplayerModal from "@/modals/aether/ConnectToMultiplayerModal"
import ServerHostingModal from "@/modals/aether/ServerHostingModal"
import ChangeInputsModal from "@/modals/configuring/ChangeInputsModal"
import ChangeInputsModal from "@/ui/modals/configuring/ChangeInputsModal.tsx"
import ChooseMultiplayerModeModal from "@/modals/configuring/ChooseMultiplayerModeModal"
import ChooseSingleplayerModeModal from "@/modals/configuring/ChooseSingleplayerModeModal"
import ConfigMotorModal from "@/modals/configuring/ConfigMotorModal"
Expand All @@ -49,12 +49,13 @@ import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel"
import ZoneConfigPanel from "@/panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "@/panels/information/ScoreboardPanel"
import DriverStationPanel from "@/panels/simulation/DriverStationPanel"
import ManageAssembliesModal from '@/modals/spawning/ManageAssembliesModal.tsx';
import World from '@/systems/World.ts';
import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx';
import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx';
import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx"
import World from "@/systems/World.ts"
import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx"
import ImportMirabufModal from "@/modals/mirabuf/ImportMirabufModal.tsx"
import ImportLocalMirabufModal from "@/modals/mirabuf/ImportLocalMirabufModal.tsx"
import ResetAllInputsModal from "./ui/modals/configuring/ResetAllInputsModal.tsx"
import Skybox from './ui/components/Skybox.tsx';
import ImportLocalMirabufModal from '@/modals/mirabuf/ImportLocalMirabufModal.tsx';

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -110,10 +111,11 @@ function Synthesis() {
return
}

const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser))
const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser), miraAssembly.info!.name!)
World.SceneRenderer.RegisterSceneObject(mirabufSceneObject)
})()
}

setup()

let mainLoopHandle = 0
Expand Down Expand Up @@ -183,6 +185,7 @@ const initialModals = [
<ConnectToMultiplayerModal modalId="connect-to-multiplayer" />,
<ServerHostingModal modalId="server-hosting" />,
<ChangeInputsModal modalId="change-inputs" />,
<ResetAllInputsModal modalId="reset-inputs" />,
<ChooseMultiplayerModeModal modalId="multiplayer-mode" />,
<ChooseSingleplayerModeModal modalId="singleplayer-mode" />,
<PracticeSettingsModal modalId="practice-settings" />,
Expand Down
47 changes: 24 additions & 23 deletions fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ interface RnDebugMeshes {
}

class MirabufSceneObject extends SceneObject {
private _mirabufInstance: MirabufInstance
private _debugBodies: Map<string, RnDebugMeshes> | null
private _physicsLayerReserve: LayerReserve | undefined = undefined
private _assemblyName: string;
private _mirabufInstance: MirabufInstance;
private _mechanism: Mechanism;
private _brain: SynthesisBrain | undefined;

private _mechanism: Mechanism
private _debugBodies: Map<string, RnDebugMeshes> | null;
private _physicsLayerReserve: LayerReserve | undefined = undefined;

public constructor(mirabufInstance: MirabufInstance) {
public constructor(mirabufInstance: MirabufInstance, assemblyName: string) {
super()

this._mirabufInstance = mirabufInstance
this._assemblyName = assemblyName;

this._mechanism = World.PhysicsSystem.CreateMechanismFromParser(this._mirabufInstance.parser)
if (this._mechanism.layerReserve) {
Expand Down Expand Up @@ -60,10 +63,10 @@ class MirabufSceneObject extends SceneObject {
}

// Simulation
World.SimulationSystem.RegisterMechanism(this._mechanism)
const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)!
const brain = new SynthesisBrain(this._mechanism)
simLayer.SetBrain(brain)
World.SimulationSystem.RegisterMechanism(this._mechanism);
const simLayer = World.SimulationSystem.GetSimulationLayer(this._mechanism)!;
this._brain = new SynthesisBrain(this._mechanism, this._assemblyName);
simLayer.SetBrain(this._brain);
}

public Update(): void {
Expand Down Expand Up @@ -108,18 +111,16 @@ class MirabufSceneObject extends SceneObject {
World.PhysicsSystem.DestroyMechanism(this._mechanism)
this._mirabufInstance.Dispose(World.SceneRenderer.scene)
this._debugBodies?.forEach(x => {
World.SceneRenderer.scene.remove(x.colliderMesh, x.comMesh)
x.colliderMesh.geometry.dispose()
x.comMesh.geometry.dispose()
;(x.colliderMesh.material as THREE.Material).dispose()
;(x.comMesh.material as THREE.Material).dispose()
})
this._debugBodies?.clear()
this._physicsLayerReserve?.Release()
}

public GetRootNodeId(): Jolt.BodyID | undefined {
return this._mechanism.nodeToBody.get(this._mechanism.rootBody)
World.SceneRenderer.scene.remove(x.colliderMesh, x.comMesh);
x.colliderMesh.geometry.dispose();
x.comMesh.geometry.dispose();
(x.colliderMesh.material as THREE.Material).dispose();
(x.comMesh.material as THREE.Material).dispose();
});
this._debugBodies?.clear();
this._physicsLayerReserve?.Release();

this._brain?.clearControls();
}

private CreateMeshForShape(shape: Jolt.Shape): THREE.Mesh {
Expand Down Expand Up @@ -162,8 +163,8 @@ export async function CreateMirabuf(assembly: mirabuf.Assembly): Promise<Mirabuf
console.error(`Assembly Parser produced significant errors for '${assembly.info!.name!}'`)
return
}

return new MirabufSceneObject(new MirabufInstance(parser))
return new MirabufSceneObject(new MirabufInstance(parser), miraAssembly.info!.name!);
}

export default MirabufSceneObject
92 changes: 92 additions & 0 deletions fission/src/systems/input/DefaultInputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { AxisInput, Input, EmptyModifierState } from "./InputSystem"

export type InputScheme = {
schemeName: string,
usesGamepad: boolean,
inputs: Input[]
}

class DefaultInputs {
private static wasd: InputScheme = {
schemeName: "WASD",
usesGamepad: false,
inputs: [
new AxisInput("arcadeDrive", "KeyW", "KeyS"),
new AxisInput("arcadeTurn", "KeyD", "KeyA"),

new AxisInput("joint 1", "Digit1", "Digit1", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: true, meta: false }),
new AxisInput("joint 2", "Digit2", "Digit2", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: true, meta: false }),
new AxisInput("joint 3", "Digit3", "Digit3", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: true, meta: false }),
new AxisInput("joint 4", "Digit4", "Digit4", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: true, meta: false }),
new AxisInput("joint 5", "Digit5", "Digit5", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: true, meta: false })
]
};

private static arrowKeys: InputScheme = {
schemeName: "Arrow Keys",
usesGamepad: false,
inputs: [
new AxisInput("arcadeDrive", "ArrowUp", "ArrowDown"),
new AxisInput("arcadeTurn", "ArrowRight", "ArrowLeft"),

new AxisInput("joint 1", "Slash", "Slash", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: true, alt: false, shift: false, meta: false }),
new AxisInput("joint 2", "Period", "Period", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: true, alt: false, shift: false, meta: false }),
new AxisInput("joint 3", "Comma", "Comma", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: true, alt: false, shift: false, meta: false }),
new AxisInput("joint 4", "KeyM", "KeyM", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: true, alt: false, shift: false, meta: false }),
new AxisInput("joint 5", "KeyN", "true", -1, false, false, -1, -1, false,
EmptyModifierState, { ctrl: false, alt: false, shift: false, meta: false })
]
};

private static fullController: InputScheme = {
schemeName: "Full Controller",
usesGamepad: true,
inputs: [
new AxisInput("arcadeDrive", "", "", 1, true),
new AxisInput("arcadeTurn", "", "", 2, false),

new AxisInput("joint 1", "", "", -1, false, true, 3, 0),
new AxisInput("joint 2", "", "", -1, false, true, 1, 2),
new AxisInput("joint 3", "", "", -1, false, true, 4, 5),
new AxisInput("joint 3", "", "", -1, false, true, 15, 14),
new AxisInput("joint 3", "", "", -1, false, true, 12, 13)
]
}

private static leftStick: InputScheme = {
schemeName: "Left Stick",
usesGamepad: true,
inputs: [
new AxisInput("arcadeDrive", "", "", 1, true),
new AxisInput("arcadeTurn", "", "", 0, false),

new AxisInput("joint 2", "", "", -1, false, true, 15, 14),
new AxisInput("joint 1", "", "", -1, false, true, 12, 13)
]
}

private static rightStick: InputScheme = {
schemeName: "Right Stick",
usesGamepad: true,
inputs: [
new AxisInput("arcadeDrive", "", "", 3, true),
new AxisInput("arcadeTurn", "", "", 2, false),

new AxisInput("joint 1", "", "", -1, false, true, 3, 0),
new AxisInput("joint 2", "", "", -1, false, true, 1, 2)
]
}

public static ALL_INPUT_SCHEMES: InputScheme[] = [this.wasd, this.arrowKeys, this.fullController, this.leftStick, this.rightStick];
}

export default DefaultInputs;
Loading
Loading