start proliferating audio across ui
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-09-17 20:31:28 -04:00
parent 21ed196993
commit b3af26b6a0
30 changed files with 138 additions and 64 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -787,6 +787,8 @@ Redesign inventory menu
Remove deprecated ui constructors Remove deprecated ui constructors
Refactor menus to package under client Refactor menus to package under client
Fix buffered scrollable regression in above work Fix buffered scrollable regression in above work
Memory fix
Start proliferating audio through ui
# TODO # TODO

View File

@ -82,6 +82,17 @@ public class VirtualAudioSourceManager {
return source; return source;
} }
/**
* Creates a non-spatial virtual audio source
* @param filePath The file path for the audio source
*/
public VirtualAudioSource createUI(String filePath){
VirtualAudioSource source = new VirtualAudioSource(filePath, VirtualAudioSourceType.UI, false);
LoggerInterface.loggerAudio.DEBUG("Create virtual audio source " + filePath);
this.virtualSourceQueue.add(source);
return source;
}
/** /**
* Updates all virtual audio sources this frame * Updates all virtual audio sources this frame
*/ */

View File

@ -82,14 +82,6 @@ public class ClientSimulation {
Globals.clientSceneWrapper.getHitboxManager().simulate(); Globals.clientSceneWrapper.getHitboxManager().simulate();
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
// //
//update audio engine
Globals.profiler.beginCpuSample("audio engine update");
if(Globals.audioEngine != null && Globals.audioEngine.initialized() && Globals.virtualAudioSourceManager != null){
Globals.audioEngine.update();
Globals.virtualAudioSourceManager.update((float)Globals.timekeeper.getSimFrameTime());
}
Globals.profiler.endCpuSample();
//
//update foliage //update foliage
if(Globals.clientFoliageManager != null){ if(Globals.clientFoliageManager != null){
Globals.clientFoliageManager.update(); Globals.clientFoliageManager.update();

View File

@ -8,11 +8,9 @@ import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
import electrosphere.renderer.ui.elements.Button; import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div; import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.Label; import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elementtypes.ClickableElement;
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification;
import electrosphere.renderer.ui.elementtypes.Element; import electrosphere.renderer.ui.elementtypes.Element;
import electrosphere.renderer.ui.events.ClickEvent;
/** /**
* Menu generators for the title menu * Menu generators for the title menu
@ -37,77 +35,42 @@ public class MenuGeneratorsTitleMenu {
rVal.addChild(titleLabel); rVal.addChild(titleLabel);
//button (multiplayer) //button (multiplayer)
Button singleplayerButton = new Button(); rVal.addChild(Button.createButtonCentered("Singleplayer", () -> {
Label singleplayerLabel = Label.createLabel("Singleplayer");
singleplayerButton.addChild(singleplayerLabel);
rVal.addChild(singleplayerButton);
singleplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu()); WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
return false; }));
}});
//button (multiplayer) //button (multiplayer)
Button multiplayerButton = new Button(); rVal.addChild(Button.createButtonCentered("Multiplayer", () -> {
Label multiplayerLabel = Label.createLabel("Multiplayer");
multiplayerButton.addChild(multiplayerLabel);
rVal.addChild(multiplayerButton);
multiplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu()); WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
return false; }));
}});
//button (static level) //button (static level)
Button staticLevelButton = new Button(); rVal.addChild(Button.createButtonCentered("Level Editor", () -> {
Label staticLevelLabel = Label.createLabel("Level Editor");
staticLevelButton.addChild(staticLevelLabel);
rVal.addChild(staticLevelButton);
staticLevelButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGeneratorsLevelEditor.createLevelEditorTopMenu()); WindowUtils.replaceMainMenuContents(MenuGeneratorsLevelEditor.createLevelEditorTopMenu());
return false; }));
}});
//button (options) //button (options)
Button optionsButton = new Button(); rVal.addChild(Button.createButtonCentered("Options", () -> {
Label optionsLabel = Label.createLabel("Options");
optionsButton.addChild(optionsLabel);
rVal.addChild(optionsButton);
optionsButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu()); WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu());
return false; }));
}});
//button (sp debug) //button (sp debug)
Button uiDebugSPQuickstartButton = new Button(); rVal.addChild(Button.createButtonCentered("Debug SP Quickstart", () -> {
Label uiDebugSPQuickstartLabel = Label.createLabel("Debug SP Quickstart");
uiDebugSPQuickstartButton.addChild(uiDebugSPQuickstartLabel);
rVal.addChild(uiDebugSPQuickstartButton);
uiDebugSPQuickstartButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread loadingThread = new LoadingThread(LoadingThreadType.DEBUG_RANDOM_SP_WORLD); LoadingThread loadingThread = new LoadingThread(LoadingThreadType.DEBUG_RANDOM_SP_WORLD);
Globals.RUN_CLIENT = true; Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true; Globals.RUN_SERVER = true;
Globals.threadManager.start(loadingThread); Globals.threadManager.start(loadingThread);
return false; }));
}});
//button (ui testing) //button (ui testing)
Button uiTestingButton = new Button(); rVal.addChild(Button.createButtonCentered("UI Testing", () -> {
Label uiTestingLabel = Label.createLabel("UI Testing");
uiTestingButton.addChild(uiTestingLabel);
rVal.addChild(uiTestingButton);
uiTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGeneratorsUITesting.createUITestMenu()); WindowUtils.replaceMainMenuContents(MenuGeneratorsUITesting.createUITestMenu());
return false; }));
}});
//button (Viewport Test) //button (Viewport Test)
Button viewportTestingButton = new Button(); rVal.addChild(Button.createButtonCentered("Viewport Test", () -> {
Label viewportTestingLabel = Label.createLabel("Viewport Test");
viewportTestingButton.addChild(viewportTestingLabel);
rVal.addChild(viewportTestingButton);
viewportTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
Globals.threadManager.start(new LoadingThread(LoadingThreadType.LOAD_VIEWPORT)); Globals.threadManager.start(new LoadingThread(LoadingThreadType.LOAD_VIEWPORT));
return false; }));
}});
return rVal; return rVal;
} }

View File

@ -86,6 +86,7 @@ import electrosphere.controls.Control.ControlMethod;
import electrosphere.controls.Control.ControlType; import electrosphere.controls.Control.ControlType;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.Main; import electrosphere.engine.Main;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.attack.ClientAttackTree;
@ -965,7 +966,7 @@ public class ControlHandler {
Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU);
//play sound effect //play sound effect
if(Globals.virtualAudioSourceManager != null){ if(Globals.virtualAudioSourceManager != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/openMenu.ogg", VirtualAudioSourceType.UI, false); Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false);
} }
Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true);
}}); }});
@ -988,7 +989,7 @@ public class ControlHandler {
Globals.controlHandler.hintUpdateControlState(ControlsState.INVENTORY); Globals.controlHandler.hintUpdateControlState(ControlsState.INVENTORY);
//play sound effect //play sound effect
if(Globals.virtualAudioSourceManager != null){ if(Globals.virtualAudioSourceManager != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/openMenu.ogg", VirtualAudioSourceType.UI, false); Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false);
} }
Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true);
// //
@ -1098,7 +1099,7 @@ public class ControlHandler {
ImGuiWindowMacros.toggleMainDebugMenu(); ImGuiWindowMacros.toggleMainDebugMenu();
//play sound effect //play sound effect
if(Globals.virtualAudioSourceManager != null){ if(Globals.virtualAudioSourceManager != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/openMenu.ogg", VirtualAudioSourceType.UI, false); Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false);
} }
}}); }});
controls.get(DEBUG_OPEN_DEBUG_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate); controls.get(DEBUG_OPEN_DEBUG_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate);

View File

@ -542,8 +542,6 @@ public class Globals {
String[] audioToInit = new String[]{ String[] audioToInit = new String[]{
"/Audio/inventoryGrabItem.ogg", "/Audio/inventoryGrabItem.ogg",
"/Audio/inventorySlotItem.ogg", "/Audio/inventorySlotItem.ogg",
"/Audio/openMenu.ogg",
"/Audio/closeMenu.ogg",
"/Audio/ambienceWind1SeamlessMono.ogg", "/Audio/ambienceWind1SeamlessMono.ogg",
"/Audio/weapons/swordUnsheath1.ogg", "/Audio/weapons/swordUnsheath1.ogg",
"/Audio/weapons/swoosh-03.ogg", "/Audio/weapons/swoosh-03.ogg",
@ -557,6 +555,14 @@ public class Globals {
"Audio/weapons/collisions/Sword Hit C.wav", "Audio/weapons/collisions/Sword Hit C.wav",
"Audio/weapons/collisions/Sword Hit D.wav", "Audio/weapons/collisions/Sword Hit D.wav",
"Audio/weapons/collisions/Sword Hit E.wav", "Audio/weapons/collisions/Sword Hit E.wav",
AssetDataStrings.UI_TONE_CONFIRM_PRIMARY,
AssetDataStrings.UI_TONE_CONFIRM_SECONDARY,
AssetDataStrings.UI_TONE_CURSOR_PRIMARY,
AssetDataStrings.UI_TONE_CURSOR_SECONDARY,
AssetDataStrings.UI_TONE_BACK_PRIMARY,
AssetDataStrings.UI_TONE_BACK_SECONDARY,
AssetDataStrings.UI_TONE_ERROR_PRIMARY,
AssetDataStrings.UI_TONE_ERROR_SECONDARY,
}; };
LoggerInterface.loggerStartup.INFO("Loading default audio resources"); LoggerInterface.loggerStartup.INFO("Loading default audio resources");
for(String path : audioToInit){ for(String path : audioToInit){

View File

@ -340,6 +340,18 @@ public class Main {
//
// M A I N A U D I O F U N C T I O N
//
Globals.profiler.beginCpuSample("audio engine update");
if(Globals.audioEngine != null && Globals.audioEngine.initialized() && Globals.virtualAudioSourceManager != null){
Globals.audioEngine.update();
Globals.virtualAudioSourceManager.update((float)Globals.timekeeper.getSimFrameTime());
}
Globals.profiler.endCpuSample();
/// ///
/// M A I N R E N D E R F U N C T I O N /// M A I N R E N D E R F U N C T I O N

View File

@ -16,5 +16,16 @@ public class AssetDataStrings {
public static final String UNITCYLINDER = "unitCylinder"; public static final String UNITCYLINDER = "unitCylinder";
public static final String UNITCUBE = "unitCube"; public static final String UNITCUBE = "unitCube";
/**
* UI audio
*/
public static final String UI_TONE_CONFIRM_PRIMARY = "Audio/ui/generic/confirm_style_4_001.wav";
public static final String UI_TONE_CONFIRM_SECONDARY = "Audio/ui/generic/confirm_style_4_003.wav";
public static final String UI_TONE_CURSOR_PRIMARY = "Audio/ui/generic/cursor_style_2.wav";
public static final String UI_TONE_CURSOR_SECONDARY = "Audio/ui/generic/cursor_style_4.wav";
public static final String UI_TONE_BACK_PRIMARY = "Audio/ui/generic/back_style_4_001.wav";
public static final String UI_TONE_BACK_SECONDARY = "Audio/ui/generic/back_style_4_003.wav";
public static final String UI_TONE_ERROR_PRIMARY = "Audio/ui/generic/error_style_4_002.wav";
public static final String UI_TONE_ERROR_SECONDARY = "Audio/ui/generic/error_style_4_001.wav";
} }

View File

@ -2,6 +2,8 @@ package electrosphere.renderer.ui.components;
import java.util.function.Consumer; import java.util.function.Consumer;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div; import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.Label; import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elements.Slider; import electrosphere.renderer.ui.elements.Slider;
@ -22,6 +24,18 @@ public class InputMacros {
*/ */
static final int LABEL_MARGIN = 10; static final int LABEL_MARGIN = 10;
/**
* Creates a back button
* @param onClick The action to perform on backing
* @return The button
*/
public static Button createBackButton(Runnable onClick){
Button rVal = Button.createButton("Back", onClick);
rVal.setOnClickAudio(AssetDataStrings.UI_TONE_BACK_PRIMARY);
return rVal;
}
/** /**
* Creates a text input that has a label and optional placeholder * Creates a text input that has a label and optional placeholder
* @param label The label for the text input * @param label The label for the text input

View File

@ -3,6 +3,7 @@ package electrosphere.renderer.ui.elements;
import org.joml.Vector3f; import org.joml.Vector3f;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.RenderPipelineState;
@ -41,6 +42,12 @@ public class Button extends StandardContainerElement implements DrawableElement,
static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f); static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f);
/**
* Audio path played on clicking the button
*/
String audioPathOnClick = AssetDataStrings.UI_TONE_CONFIRM_PRIMARY;
public Button(){ public Button(){
super(); super();
} }
@ -73,12 +80,37 @@ public class Button extends StandardContainerElement implements DrawableElement,
rVal.addChild(rValLabel); rVal.addChild(rValLabel);
rVal.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ rVal.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
callback.run(); callback.run();
if(Globals.virtualAudioSourceManager != null && rVal.audioPathOnClick != null){
Globals.virtualAudioSourceManager.createUI(rVal.audioPathOnClick);
}
return false; return false;
}}); }});
rVal.setAlignSelf(YogaAlignment.Start); rVal.setAlignSelf(YogaAlignment.Start);
return rVal; return rVal;
} }
/**
* Creates a button that fires a callback when clicked
* @param text The text for the button label
* @param callback The callback
* @return The button
*/
public static Button createButtonCentered(String text, Runnable callback){
Button rVal = new Button();
Label rValLabel = Label.createLabel(text);
rValLabel.setText(text);
rVal.addChild(rValLabel);
rVal.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
callback.run();
if(Globals.virtualAudioSourceManager != null && rVal.audioPathOnClick != null){
Globals.virtualAudioSourceManager.createUI(rVal.audioPathOnClick);
}
return false;
}});
rVal.setAlignSelf(YogaAlignment.Center);
return rVal;
}
public boolean getVisible() { public boolean getVisible() {
return visible; return visible;
} }
@ -262,4 +294,12 @@ public class Button extends StandardContainerElement implements DrawableElement,
this.focused = focused; this.focused = focused;
} }
/**
* Sets the audio path to play on click
* @param audioPath The audio path
*/
public void setOnClickAudio(String audioPath){
this.audioPathOnClick = audioPath;
}
} }

View File

@ -1,6 +1,7 @@
package electrosphere.renderer.ui.elements; package electrosphere.renderer.ui.elements;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.engine.signal.Signal.SignalType; import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState; import electrosphere.renderer.OpenGLState;
@ -58,6 +59,16 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
Font font; Font font;
/**
* Audio path played when typing into the input
*/
String audioPathOnType = AssetDataStrings.UI_TONE_CURSOR_SECONDARY;
/**
* Audio path played when typing into the input
*/
String audioPathOnTypeError = AssetDataStrings.UI_TONE_ERROR_SECONDARY;
/** /**
* Creates a text input element using the default font size * Creates a text input element using the default font size
* @return The text input * @return The text input
@ -234,10 +245,21 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
if(keyEvent.getKey().matches(Pattern.quote("bs"))){ if(keyEvent.getKey().matches(Pattern.quote("bs"))){
if(this.text.length() > 0){ if(this.text.length() > 0){
this.setText(this.text.substring(0, this.text.length() - 1)); this.setText(this.text.substring(0, this.text.length() - 1));
if(Globals.virtualAudioSourceManager != null && this.audioPathOnType != null){
Globals.virtualAudioSourceManager.createUI(this.audioPathOnType);
}
} else {
if(Globals.virtualAudioSourceManager != null && this.audioPathOnTypeError != null){
Globals.virtualAudioSourceManager.createUI(this.audioPathOnTypeError);
}
} }
} else { } else {
this.setText(this.text + keyEvent.getKey()); this.setText(this.text + keyEvent.getKey());
if(Globals.virtualAudioSourceManager != null && this.audioPathOnType != null){
Globals.virtualAudioSourceManager.createUI(this.audioPathOnType);
} }
}
Globals.signalSystem.post(SignalType.YOGA_APPLY, this);
//fire value change event //fire value change event
Globals.elementService.fireEventNoPosition(new ValueChangeEvent(text), this); Globals.elementService.fireEventNoPosition(new ValueChangeEvent(text), this);
return false; return false;