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
Refactor menus to package under client
Fix buffered scrollable regression in above work
Memory fix
Start proliferating audio through ui
# TODO

View File

@ -82,6 +82,17 @@ public class VirtualAudioSourceManager {
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
*/

View File

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

View File

@ -86,6 +86,7 @@ import electrosphere.controls.Control.ControlMethod;
import electrosphere.controls.Control.ControlType;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.attack.ClientAttackTree;
@ -965,7 +966,7 @@ public class ControlHandler {
Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU);
//play sound effect
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);
}});
@ -988,7 +989,7 @@ public class ControlHandler {
Globals.controlHandler.hintUpdateControlState(ControlsState.INVENTORY);
//play sound effect
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);
//
@ -1098,7 +1099,7 @@ public class ControlHandler {
ImGuiWindowMacros.toggleMainDebugMenu();
//play sound effect
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);

View File

@ -542,8 +542,6 @@ public class Globals {
String[] audioToInit = new String[]{
"/Audio/inventoryGrabItem.ogg",
"/Audio/inventorySlotItem.ogg",
"/Audio/openMenu.ogg",
"/Audio/closeMenu.ogg",
"/Audio/ambienceWind1SeamlessMono.ogg",
"/Audio/weapons/swordUnsheath1.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 D.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");
for(String path : audioToInit){

View File

@ -337,6 +337,18 @@ public class Main {
MainServerFunctions.simulate();
Globals.profiler.endCpuSample();
}
//
// 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();

View File

@ -16,5 +16,16 @@ public class AssetDataStrings {
public static final String UNITCYLINDER = "unitCylinder";
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 electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elements.Slider;
@ -22,6 +24,18 @@ public class InputMacros {
*/
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
* @param label The label for the text input

View File

@ -3,6 +3,7 @@ package electrosphere.renderer.ui.elements;
import org.joml.Vector3f;
import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState;
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);
/**
* Audio path played on clicking the button
*/
String audioPathOnClick = AssetDataStrings.UI_TONE_CONFIRM_PRIMARY;
public Button(){
super();
}
@ -73,12 +80,37 @@ public class Button extends StandardContainerElement implements DrawableElement,
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.Start);
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() {
return visible;
}
@ -261,5 +293,13 @@ public class Button extends StandardContainerElement implements DrawableElement,
public void setFocused(boolean 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;
import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.OpenGLState;
@ -58,6 +59,16 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
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
* @return The text input
@ -234,10 +245,21 @@ public class TextInput extends StandardContainerElement implements DrawableEleme
if(keyEvent.getKey().matches(Pattern.quote("bs"))){
if(this.text.length() > 0){
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 {
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
Globals.elementService.fireEventNoPosition(new ValueChangeEvent(text), this);
return false;