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