Add draft audio change concept on mob proximity

This commit is contained in:
Doyle Thai 2016-07-28 13:36:16 +10:00
parent ac775b39c2
commit 1427ee3fde
3 changed files with 29 additions and 57 deletions

View File

@ -181,20 +181,11 @@ INTERNAL const i32 rendererRelease(AudioManager *audioManager,
return result; return result;
} }
for (i32 i = 0; i < ARRAY_COUNT(audioRenderer->bufferId); i++) alSourceUnqueueBuffers(alSourceId, ARRAY_COUNT(audioRenderer->bufferId),
{ audioRenderer->bufferId);
if (alIsBuffer(audioRenderer->bufferId[i]) == AL_TRUE) alDeleteBuffers(ARRAY_COUNT(audioRenderer->bufferId),
{ audioRenderer->bufferId);
alSourceUnqueueBuffers(alSourceId, 1, &audioRenderer->bufferId[i]); AL_CHECK_ERROR();
alDeleteBuffers(1, &audioRenderer->bufferId[i]);
AL_CHECK_ERROR();
}
else
{
DEBUG_LOG("rendererRelease(): Invalid buffer identified in renderer");
result = -1;
}
}
for (i32 i = 0; i < ARRAY_COUNT(audioRenderer->bufferId); i++) for (i32 i = 0; i < ARRAY_COUNT(audioRenderer->bufferId); i++)
{ {
@ -212,7 +203,6 @@ INTERNAL const i32 rendererRelease(AudioManager *audioManager,
audioManager->freeSourceIndex = sourceIndexToFree; audioManager->freeSourceIndex = sourceIndexToFree;
return result; return result;
} }
#define AUDIO_CHUNK_SIZE_ 65536 #define AUDIO_CHUNK_SIZE_ 65536

View File

@ -25,7 +25,7 @@ void debug_init(MemoryArena *arena, v2 windowSize, Font font)
// TODO(doyle): Font max size not entirely correct? using 1 * font.maxSize.w // TODO(doyle): Font max size not entirely correct? using 1 * font.maxSize.w
// reveals around 4 characters .. // reveals around 4 characters ..
f32 consoleXPos = windowSize.x - (font.maxSize.w * 38); f32 consoleXPos = font.maxSize.w * 20;
f32 consoleYPos = windowSize.h - 1.8f * GLOBAL_debug.stringLineGap; f32 consoleYPos = windowSize.h - 1.8f * GLOBAL_debug.stringLineGap;
GLOBAL_debug.initialConsoleP = V2(consoleXPos, consoleYPos); GLOBAL_debug.initialConsoleP = V2(consoleXPos, consoleYPos);
} }

View File

@ -369,12 +369,8 @@ void worldTraveller_gameInit(GameState *state, v2 windowSize)
addEntity(arena, world, pos, size, type, dir, tex, collides); addEntity(arena, world, pos, size, type, dir, tex, collides);
world->soundscape = soundscape; world->soundscape = soundscape;
soundscape->audio = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer); soundscape->audio = PLATFORM_MEM_ALLOC(arena, 1, AudioRenderer);
soundscape->audio->sourceIndex = AUDIO_SOURCE_UNASSIGNED; soundscape->audio->sourceIndex = AUDIO_SOURCE_UNASSIGNED;
audio_streamPlayVorbis(&state->audioManager, soundscape->audio,
asset_getVorbis(assetManager, audiolist_battle),
AUDIO_REPEAT_INFINITE);
/* Init hero entity */ /* Init hero entity */
world->heroIndex = world->freeEntityIndex; world->heroIndex = world->freeEntityIndex;
@ -502,49 +498,12 @@ INTERNAL void parseInput(GameState *state, const f32 dt)
// TODO(doyle): Revisit key input with state checking for last ended down // TODO(doyle): Revisit key input with state checking for last ended down
if (state->keys[GLFW_KEY_SPACE] && spaceBarWasDown == FALSE) if (state->keys[GLFW_KEY_SPACE] && spaceBarWasDown == FALSE)
{ {
#if 0
Renderer *renderer = &state->renderer; Renderer *renderer = &state->renderer;
f32 yPos = CAST(f32)(rand() % CAST(i32)renderer->size.h); f32 yPos = CAST(f32)(rand() % CAST(i32)renderer->size.h);
f32 xModifier = 5.0f - CAST(f32)(rand() % 3); f32 xModifier = 5.0f - CAST(f32)(rand() % 3);
v2 pos = V2(renderer->size.w - (renderer->size.w / xModifier), yPos); v2 pos = V2(renderer->size.w - (renderer->size.w / xModifier), yPos);
addGenericMob(&state->arena, &state->assetManager, world, pos); addGenericMob(&state->arena, &state->assetManager, world, pos);
#endif
#if 0
if (world->soundscape->audio->sourceIndex == AUDIO_SOURCE_UNASSIGNED)
{
audio_streamPlayVorbis(
&state->audioManager, world->soundscape->audio,
asset_getVorbis(&state->assetManager, audiolist_battle),
AUDIO_REPEAT_INFINITE);
}
else
{
audio_streamStopVorbis(&state->audioManager,
world->soundscape->audio);
audio_streamPauseVorbis(&state->audioManager,
world->soundscape->audio);
}
#endif
if (toggleFlag)
{
audio_streamPauseVorbis(&state->audioManager,
world->soundscape->audio);
toggleFlag = FALSE;
}
else
{
audio_streamResumeVorbis(&state->audioManager,
world->soundscape->audio);
#if 0
audio_streamPlayVorbis(
&state->audioManager, world->soundscape->audio,
asset_getVorbis(&state->assetManager, audiolist_battle),
AUDIO_REPEAT_INFINITE);
#endif
toggleFlag = TRUE;
}
spaceBarWasDown = TRUE; spaceBarWasDown = TRUE;
} }
else if (!state->keys[GLFW_KEY_SPACE]) else if (!state->keys[GLFW_KEY_SPACE])
@ -999,6 +958,29 @@ void worldTraveller_gameUpdateAndRender(GameState *state, f32 dt)
if (entity->audio) if (entity->audio)
{ {
AudioRenderer *audioRenderer = entity->audio;
if (world->numEntitiesInBattle > 0)
{
AudioVorbis *battleTheme =
asset_getVorbis(assetManager, audiolist_battle);
if (audioRenderer->audio != battleTheme)
{
audio_streamPlayVorbis(&state->audioManager, audioRenderer,
battleTheme, AUDIO_REPEAT_INFINITE);
}
}
else
{
AudioVorbis *overworldTheme =
asset_getVorbis(assetManager, audiolist_overworld);
if (audioRenderer->audio != overworldTheme)
{
audio_streamPlayVorbis(&state->audioManager, audioRenderer,
overworldTheme,
AUDIO_REPEAT_INFINITE);
}
}
audio_updateAndPlay(&state->audioManager, entity->audio); audio_updateAndPlay(&state->audioManager, entity->audio);
} }