Add audiostate field and audio toggle ui button
This commit is contained in:
parent
90068d2c64
commit
6ec92358b2
@ -310,6 +310,7 @@ const i32 audio_streamPlayVorbis(MemoryArena *arena, AudioManager *audioManager,
|
||||
|
||||
audioRenderer->audio = copyAudio;
|
||||
audioRenderer->isStreaming = TRUE;
|
||||
audioRenderer->state = audiostate_playing;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -324,6 +325,7 @@ const i32 audio_stopVorbis(MemoryArena *arena, AudioManager *audioManager,
|
||||
alSourceStop(alSourceId);
|
||||
AL_CHECK_ERROR();
|
||||
result = rendererRelease(arena, audioManager, audioRenderer);
|
||||
audioRenderer->state = audiostate_stopped;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -350,6 +352,7 @@ const i32 audio_pauseVorbis(AudioManager *audioManager,
|
||||
{
|
||||
alSourcePause(alSourceId);
|
||||
AL_CHECK_ERROR();
|
||||
audioRenderer->state = audiostate_paused;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -368,6 +371,7 @@ const i32 audio_resumeVorbis(AudioManager *audioManager,
|
||||
{
|
||||
alSourcePlay(alSourceId);
|
||||
AL_CHECK_ERROR();
|
||||
audioRenderer->state = audiostate_playing;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -75,16 +75,6 @@ INTERNAL RenderQuad createTexQuad(Renderer *renderer, v4 quadRect,
|
||||
}
|
||||
|
||||
/* Form the quad */
|
||||
#if 0
|
||||
result.vertex[0] = V4(quadRectNdc.x, quadRectNdc.y, texRectNdc.x,
|
||||
texRectNdc.y); // Top left
|
||||
result.vertex[1] = V4(quadRectNdc.x, quadRectNdc.w, texRectNdc.x,
|
||||
texRectNdc.w); // Bottom left
|
||||
result.vertex[2] = V4(quadRectNdc.z, quadRectNdc.y, texRectNdc.z,
|
||||
texRectNdc.y); // Top right
|
||||
result.vertex[3] = V4(quadRectNdc.z, quadRectNdc.w, texRectNdc.z,
|
||||
texRectNdc.w); // Bottom right
|
||||
#else
|
||||
result.vertex[0] = V4(quadRectNdc.x, quadRectNdc.w, texRectNdc.x,
|
||||
texRectNdc.w); // Top left
|
||||
result.vertex[1] = V4(quadRectNdc.x, quadRectNdc.y, texRectNdc.x,
|
||||
@ -93,7 +83,6 @@ INTERNAL RenderQuad createTexQuad(Renderer *renderer, v4 quadRect,
|
||||
texRectNdc.w); // Top right
|
||||
result.vertex[3] = V4(quadRectNdc.z, quadRectNdc.y, texRectNdc.z,
|
||||
texRectNdc.y); // Bottom right
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -101,12 +90,7 @@ INTERNAL inline RenderQuad
|
||||
createDefaultTexQuad(Renderer *renderer, RenderTex renderTex)
|
||||
{
|
||||
RenderQuad result = {0};
|
||||
// TODO(doyle): We need to switch this so its xy bottom left, zw top right!!
|
||||
#if 0
|
||||
v4 defaultQuad = V4(0.0f, renderer->size.h, renderer->size.w, 0.0f);
|
||||
#else
|
||||
v4 defaultQuad = V4(0.0f, 0.0f, renderer->size.w, renderer->size.h);
|
||||
#endif
|
||||
v4 defaultQuad = V4(0.0f, 0.0f, renderer->size.w, renderer->size.h);
|
||||
result = createTexQuad(renderer, defaultQuad, renderTex);
|
||||
return result;
|
||||
}
|
||||
@ -210,7 +194,7 @@ void renderer_string(Renderer *const renderer, MemoryArena *arena, Rect camera,
|
||||
|
||||
v2 posInCameraSpace = v2_sub(pos, camera.pos);
|
||||
|
||||
pos = posInCameraSpace;
|
||||
pos = posInCameraSpace;
|
||||
|
||||
// TODO(doyle): Find why font is 1px off, might be arial font semantics
|
||||
f32 baseline = pos.y - font->verticalSpacing + 1;
|
||||
|
@ -64,7 +64,6 @@ i32 userInterface_button(UiState *const uiState,
|
||||
if (label)
|
||||
{
|
||||
v2 labelDim = asset_stringDimInPixels(font, label);
|
||||
DEBUG_PUSH_VAR("label dim: %4.2f, %4.2f", labelDim, "v2");
|
||||
v2 labelPos = rect.pos;
|
||||
if (labelDim.w < rect.size.w)
|
||||
{
|
||||
@ -85,11 +84,6 @@ i32 userInterface_button(UiState *const uiState,
|
||||
labelPos = v2_add(labelPos, buttonOffset);
|
||||
renderer_staticString(renderer, arena, font, label, labelPos, V2(0, 0),
|
||||
0, V4(0, 0, 0, 1));
|
||||
|
||||
v2 rulerPos = rect.pos;
|
||||
rulerPos.y -= 10;
|
||||
renderer_staticRect(renderer, rulerPos, V2(10, 10), V2(0, 0), 0,
|
||||
renderTex, V4(0.5f, 0.1f, 0.7f, 1));
|
||||
}
|
||||
|
||||
// After renderering before click check, see if we need to process keys
|
||||
|
@ -1048,17 +1048,33 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
||||
Entity *const entity = &world->entities[i];
|
||||
if (entity->state == entitystate_dead) continue;
|
||||
|
||||
#if 0
|
||||
if (entity->type == entitytype_soundscape)
|
||||
{
|
||||
AudioRenderer *audioRenderer = entity->audioRenderer;
|
||||
if (world->numEntitiesInBattle > 0)
|
||||
if (!state->config.playWorldAudio)
|
||||
{
|
||||
AudioVorbis *battleTheme =
|
||||
asset_getVorbis(assetManager, audiolist_battle);
|
||||
if (audioRenderer->audio)
|
||||
// TODO(doyle): Use is playing flag, not just streaming flag
|
||||
if (audioRenderer->state == audiostate_playing)
|
||||
{
|
||||
if (audioRenderer->audio->type != audiolist_battle)
|
||||
audio_pauseVorbis(&state->audioManager, audioRenderer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (world->numEntitiesInBattle > 0)
|
||||
{
|
||||
AudioVorbis *battleTheme =
|
||||
asset_getVorbis(assetManager, audiolist_battle);
|
||||
if (audioRenderer->audio)
|
||||
{
|
||||
if (audioRenderer->audio->type != audiolist_battle)
|
||||
{
|
||||
audio_streamPlayVorbis(arena, &state->audioManager,
|
||||
audioRenderer, battleTheme,
|
||||
AUDIO_REPEAT_INFINITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_streamPlayVorbis(arena, &state->audioManager,
|
||||
audioRenderer, battleTheme,
|
||||
@ -1067,33 +1083,32 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_streamPlayVorbis(arena, &state->audioManager,
|
||||
audioRenderer, battleTheme,
|
||||
AUDIO_REPEAT_INFINITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioVorbis *overworldTheme =
|
||||
asset_getVorbis(assetManager, audiolist_overworld);
|
||||
if (audioRenderer->audio)
|
||||
{
|
||||
if (audioRenderer->audio->type != audiolist_overworld)
|
||||
AudioVorbis *overworldTheme =
|
||||
asset_getVorbis(assetManager, audiolist_overworld);
|
||||
if (audioRenderer->audio)
|
||||
{
|
||||
if (audioRenderer->audio->type != audiolist_overworld)
|
||||
{
|
||||
audio_streamPlayVorbis(
|
||||
arena, &state->audioManager, audioRenderer,
|
||||
overworldTheme, AUDIO_REPEAT_INFINITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_streamPlayVorbis(arena, &state->audioManager,
|
||||
audioRenderer, overworldTheme,
|
||||
AUDIO_REPEAT_INFINITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (audioRenderer->state == audiostate_paused)
|
||||
{
|
||||
audio_streamPlayVorbis(arena, &state->audioManager,
|
||||
audioRenderer, overworldTheme,
|
||||
AUDIO_REPEAT_INFINITE);
|
||||
audio_resumeVorbis(&state->audioManager, audioRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
*****************************************************
|
||||
* Set mob to battle mode if within distance from hero
|
||||
@ -1296,34 +1311,27 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
|
||||
// INIT IMGUI
|
||||
state->uiState.hotItem = 0;
|
||||
|
||||
#if 0
|
||||
UiItem damageString = {0};
|
||||
damageString.id = 6;
|
||||
damageString.rect = {V2(500, 500), V2(font->maxSize.w * 30, font->maxSize.h)};
|
||||
damageString.type = uitype_string;
|
||||
#endif
|
||||
|
||||
/* Draw ui */
|
||||
Rect buttonRectA = {V2(300, 500), V2(100, 50)};
|
||||
userInterface_button(&state->uiState, &state->arena, assetManager, renderer,
|
||||
font, state->input, 1, buttonRectA, "HELLO WORLD");
|
||||
// TODO(doyle): Bug in font rendering once button reaches 700-800+ pixels
|
||||
Rect buttonRectA = {V2(1000, 800), V2(100, 50)};
|
||||
|
||||
Rect buttonRectB = {V2(500, 500), V2(100, 50)};
|
||||
userInterface_button(&state->uiState, &state->arena, assetManager, renderer,
|
||||
font, state->input, 2, buttonRectB, "button2");
|
||||
b32 isClicked = userInterface_button(
|
||||
&state->uiState, &state->arena, assetManager, renderer, font,
|
||||
state->input, 1, buttonRectA, "Toggle Music");
|
||||
|
||||
Rect buttonRectC = {V2(700, 500), V2(100, 50)};
|
||||
userInterface_button(&state->uiState, &state->arena, assetManager, renderer,
|
||||
font, state->input, 3, buttonRectC, "button3");
|
||||
if (isClicked)
|
||||
{
|
||||
state->config.playWorldAudio = ~state->config.playWorldAudio;
|
||||
}
|
||||
|
||||
LOCAL_PERSIST i32 scrollValue = 30;
|
||||
Rect scrollRectA = {V2(900, 500), V2(16, 255)};
|
||||
Rect scrollRectA = {V2(1500, 600), V2(16, 255)};
|
||||
userInterface_scrollBar(&state->uiState, assetManager, renderer,
|
||||
state->input, 4, scrollRectA, &scrollValue, 160);
|
||||
state->input, 2, scrollRectA, &scrollValue, 160);
|
||||
|
||||
LOCAL_PERSIST char fieldString[80] = "Hello world";
|
||||
userInterface_textField(&state->uiState, &state->arena, assetManager,
|
||||
renderer, font, state->input, 5, V2(1000, 500),
|
||||
renderer, font, state->input, 3, V2(1000, 750),
|
||||
fieldString);
|
||||
|
||||
// RESET IMGUI
|
||||
|
@ -23,7 +23,15 @@ typedef struct AudioManager
|
||||
AudioSourceEntry sourceList[AUDIO_MAX_SOURCES];
|
||||
} AudioManager;
|
||||
|
||||
enum AudioState
|
||||
{
|
||||
audiostate_stopped = 0,
|
||||
audiostate_paused,
|
||||
audiostate_playing,
|
||||
audiostate_count,
|
||||
};
|
||||
|
||||
// TODO(doyle): Add object pool for assets, in particular audio
|
||||
#define AUDIO_REPEAT_INFINITE -10
|
||||
#define AUDIO_SOURCE_UNASSIGNED -1
|
||||
typedef struct AudioRenderer
|
||||
@ -36,6 +44,7 @@ typedef struct AudioRenderer
|
||||
i32 numPlays;
|
||||
|
||||
b32 isStreaming;
|
||||
enum AudioState state;
|
||||
} AudioRenderer;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user