Start engine sound

This commit is contained in:
Miloslav Ciz 2024-12-23 22:50:07 +01:00
parent d0db60c02a
commit e6c5283bf4
6 changed files with 128 additions and 3 deletions

38
game.h
View file

@ -42,6 +42,11 @@
- Implement the below described functions according to their description.
- Implement the main program and game loop.
- Call the below described functions as described.
- If you want to support music, make your frontend play music from the "music"
file in assets. It is in raw format, storing 8bit unsigned samples at 8000
Hz. Use the LCR_gameGetMusicVolume to check what the music volume is. If you
don't support music, set LCR_SETTING_MUSIC to 0 in your frontend code so
that the game knows music is disabled.
*/
/**
@ -93,6 +98,16 @@ void LCR_gameEnd(void);
*/
uint8_t LCR_gameStep(uint32_t timeMs);
/**
Gets the current music volume;
*/
uint8_t LCR_gameGetMusicVolume(void);
/**
Gets next audio sample (unsigned 8bit samples, 8 KHz).
*/
uint8_t LCR_gameGetNextAudioSample(void);
//------------------------------------------------------------------------------
#define LCR_LOG0(s) ;
@ -133,8 +148,19 @@ struct
uint8_t debugDraw;
uint8_t checkpointsTaken;
uint32_t runTime;
uint8_t musicVolume;
} LCR_game;
uint8_t LCR_gameGetMusicVolume(void)
{
#if LCR_SETTING_MUSIC
return LCR_game.musicVolume;
#else
return 0;
#endif
}
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color);
@ -149,6 +175,7 @@ static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
#include "racing.h"
#include "assets.h"
#include "renderer.h"
#include "audio.h"
uint8_t LCR_keyStates[LCR_KEYS_TOTAL]; /**< Assures unchanging key states
during a single frame, holds
@ -219,12 +246,12 @@ void LCR_gameInit(void)
LCR_rendererInit();
LCR_racingInit();
LCR_audioInit();
LCR_game.musicVolume = 255;
LCR_game.nextRenderFrameTime = 0;
LCR_game.nextRacingTickTime = 0;
LCR_game.controlMode = LCR_CONTROL_MODE_FREECAM;
LCR_gameStartRun(LCR_maps[0]);
}
@ -369,6 +396,8 @@ LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT -
int val = LCR_carSpeedKMH();
LCR_audioSetEngineIntensity(val < 256 ? val : 255);
if (val < 5) // don't show tiny oscillations when still
val = 0;
@ -424,4 +453,9 @@ LCR_GameUnit physicsInterpolationParam = LCR_GAME_UNIT -
return 1;
}
uint8_t LCR_gameGetNextAudioSample(void)
{
return LCR_audioGetNextSample();
}
#endif // guard