sdl and misc. function additions

Open motion blur as an experimental function and open more existing SDL
functions to Lua for use in this fork/branch
This commit is contained in:
yellowtd 2016-04-15 07:38:55 -04:00
parent 9208cc33a5
commit 4741ae718a
9 changed files with 294 additions and 5 deletions

View file

@ -2128,7 +2128,7 @@ static void Command_connect(void)
server = false;
// RedEnchilada: host a game from connect
// mirmiru RedEnchilada: host a game from connect
if (!stricmp(COM_Argv(1), "HOST"))
{
const char *mapname;

View file

@ -229,6 +229,48 @@ void I_StopDigSong(void);
*/
void I_SetDigMusicVolume(UINT8 volume);
//miru: Let's open up and add some music functions to SDL
/** \brief Sets the position in the current song.
\param position How many seconds into the song to seek to
\return void
*/
void I_SetMusicPosition(float position);
/** \brief Gets the position in the current song.
\return position value
*/
float I_GetMusicPosition(void);
/** \brief Fade in Music
\param ms How long the effect should last
\return void
*/
void I_FadeInMusic(int ms);
/** \brief Fade in Music at position
\param ms How long the effect should last
\param position the position the song should start at
\return void
*/
void I_FadeInMusicPos(int ms, float position);
//void I_VolumeMusic(int volume);
/** \brief Fade out Music
\param ms How long the effect should last
\return void
*/
void I_FadeOutMusic(int ms);
//
// CD MUSIC I/O
//

View file

@ -1654,6 +1654,71 @@ static int lib_sChangeMusic(lua_State *L)
return 0;
}
//=====================================================================
//miru: A block where I can put my open functions to Lua...they can be organized later
//(or just shoved into a future mir_lua.c like before)
static int lib_sPositionMusic(lua_State *L)
{
fixed_t fixedspeed = luaL_checkfixed(L, 1);
float position = fixedspeed*0.001f;
//CONS_Printf("set music pos %f\n", position);
player_t *player = NULL;
//NOHUD
if (!lua_isnone(L, 2) && lua_isuserdata(L, 2))
{
player = *((player_t **)luaL_checkudata(L, 2, META_PLAYER));
if (!player)
return LUA_ErrInvalid(L, "player_t");
}
if (!player || P_IsLocalPlayer(player))
S_PositionMusic(position);
return 0;
}
static int lib_sGetPositionMusic(lua_State *L)
{
float fpos = S_GetPositionMusic();
lua_pushnumber(L, (lua_Number)(fpos*1000));
//CONS_Printf("GetPositionMusic: %05f\n\n\n",fpos);
return 1;
}
static int lib_sFadeOutMusic(lua_State *L)
{
int millisecond = luaL_checkint(L, 1);
player_t *player = NULL;
//NOHUD
if (!lua_isnone(L, 2) && lua_isuserdata(L, 2))
{
player = *((player_t **)luaL_checkudata(L, 2, META_PLAYER));
if (!player)
return LUA_ErrInvalid(L, "player_t");
}
if (!player || P_IsLocalPlayer(player))
S_FadeOutMusic(millisecond);
return 0;
}
static int lib_pSetActiveMotionBlur(lua_State *L)
{
boolean active = (boolean)lua_opttrueboolean(L, 1);
INT32 param = luaL_checkint(L, 2);
player_t *player = NULL;
//NOHUD
if (!lua_isnone(L, 3) && lua_isuserdata(L, 3))
{
player = *((player_t **)luaL_checkudata(L, 3, META_PLAYER));
if (!player)
return LUA_ErrInvalid(L, "player_t");
}
if (!player || P_IsLocalPlayer(player))
P_SetActiveMotionBlur(active, param);
return 0;
}
//=====================================================================
static int lib_sSpeedMusic(lua_State *L)
{
fixed_t fixedspeed = luaL_checkfixed(L, 1);
@ -2000,6 +2065,8 @@ static luaL_Reg lib[] = {
{"S_StartSoundAtVolume",lib_sStartSoundAtVolume},
{"S_StopSound",lib_sStopSound},
{"S_ChangeMusic",lib_sChangeMusic},
//{"S_PositionMusic",lib_sPositionMusic},
//{"S_GetPositionMusic",lib_sGetPositionMusic},
{"S_SpeedMusic",lib_sSpeedMusic},
{"S_StopMusic",lib_sStopMusic},
{"S_OriginPlaying",lib_sOriginPlaying},
@ -2023,6 +2090,12 @@ static luaL_Reg lib[] = {
{"G_TicsToCentiseconds",lib_gTicsToCentiseconds},
{"G_TicsToMilliseconds",lib_gTicsToMilliseconds},
//miru: Put everything added here, categorizing right now isn't something I want to wander through
{"S_PositionMusic",lib_sPositionMusic},
{"S_GetPositionMusic",lib_sGetPositionMusic},
{"S_FadeOutMusic",lib_sFadeOutMusic},
{"P_SetActiveMotionBlur",lib_pSetActiveMotionBlur},
{NULL, NULL}
};

View file

@ -3376,6 +3376,25 @@ void P_DestroyRobots(void)
}
}
//miru: motion blur exists so I'll use it
//Note: motion blur should never ever be used excessively
void P_SetActiveMotionBlur(boolean active, INT32 param)
{
camera_motionblur = active;
forward_postimgparam = param;
}
boolean P_CheckMotionBlur(void)
{
if (camera_motionblur == true)
return true;
return false;
}
// P_CameraThinker
//
// Process the mobj-ish required functions of the camera
@ -3403,6 +3422,13 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled
postimg = postimg_water;
else if (P_CameraCheckHeat(&dummycam))
postimg = postimg_heat;
// miru: Check for Motion Blur Activation
else if (P_CheckMotionBlur())
postimg = postimg_motion;
if (!forward_postimgparam)
forward_postimgparam = 1;
else
postimgparam = forward_postimgparam;
}
else
{
@ -3411,6 +3437,13 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled
postimg = postimg_water;
else if (P_CameraCheckHeat(thiscam))
postimg = postimg_heat;
// miru: Check for Motion Blur Activation
else if (P_CheckMotionBlur())
postimg = postimg_motion;
if (!forward_postimgparam)
forward_postimgparam = 1;
else
postimgparam = forward_postimgparam;
}
if (postimg != postimg_none)

View file

@ -451,3 +451,8 @@ extern INT32 numhuntemeralds;
extern boolean runemeraldmanager;
extern INT32 numstarposts;
#endif
boolean camera_motionblur;
INT32 forward_postimgparam;
boolean P_CheckMotionBlur();
void P_SetActiveMotionBlur(boolean active, INT32 param);

View file

@ -8573,6 +8573,17 @@ static void P_CalcPostImg(player_t *player)
if (player->mo->eflags & MFE_VERTICALFLIP)
*type = postimg_flip;
//miru: Motion blur won't work without this i guess, either way its enabled
//TODO: Opengl motion blur
// Motion blur
if (player->mo)
{
*type = postimg_motion;
*param = 5;
}
(void)param;
/*
#if 1
(void)param;
#else
@ -8585,7 +8596,7 @@ static void P_CalcPostImg(player_t *player)
if (*param > 5)
*param = 5;
}
#endif
#endif*/
}
void P_DoPityCheck(player_t *player)

View file

@ -1249,6 +1249,21 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
I_SetSongTrack(mflags & MUSIC_TRACKMASK);
}
void S_PositionMusic(float position)
{
I_SetMusicPosition(position);
}
float S_GetPositionMusic(void)
{
return I_GetMusicPosition();
}
void S_FadeOutMusic(int ms)
{
I_FadeOutMusic(ms);
}
boolean S_SpeedMusic(float speed)
{
return I_SetSongSpeed(speed);

View file

@ -104,6 +104,32 @@ void S_StopSound(void *origin);
#define S_ChangeMusicInternal(a,b) S_ChangeMusic(a,0,b)
void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping);
//miru: Let's open and add some music functions in SDL,
//PositionMusic and GetMusicPosition aka SetMusicPosition
//(because I'm not allowed to name it to not be as sloppily named the way it is)
// Seek to a point in the current song
void S_PositionMusic(float position);
// Get the current music position
float S_GetPositionMusic(void);
// Fade in over milliseconds of time
void S_FadeInMusic(int ms);
// Fade in over ms milliseconds of time, at position
void S_FadeInMusicPos(int ms, float position);
// Set the volume, to volume
//void S_VolumeMusic(void);
// Gradually fade out the music over time starting from now
void S_FadeOutMusic(int ms);
// Set Speed of Music
boolean S_SpeedMusic(float speed);

View file

@ -74,6 +74,17 @@ static Music_Emu *gme;
static INT32 current_track;
#endif
//miru: new variables for use involving music infos
int const SAMPLE_RATE = 44100;
static double music_pos = 0.0;
static long music_pos_time = -1;
//static int music_frequency = 0;
//static Uint16 music_format = 0;
//static int music_channels = 0;
void I_StartupSound(void)
{
I_Assert(!sound_started);
@ -86,7 +97,7 @@ void I_StartupSound(void)
#if SDL_MIXER_VERSION_ATLEAST(1,2,11)
Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG);
#endif
Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 2048);
Mix_OpenAudio(SAMPLE_RATE, AUDIO_S16LSB, 2, 2048);
Mix_AllocateChannels(256);
}
@ -420,8 +431,31 @@ static void music_loop(void)
{
Mix_PlayMusic(music, 0);
Mix_SetMusicPosition(loop_point);
music_pos = (int)(loop_point * SAMPLE_RATE);
}
//miru: some music hooks and callbacks (including music_pos above)
/*static void music_fadeloop(void)
{
Mix_HookMusicFinished(NULL);
// Mix_PlayMusic(music, 0);
//if (music_pos >= I_GetMusicPosition() - 1000)
// Mix_SetMusicPosition(loop_point);
music_pos = (int)(loop_point * SAMPLE_RATE);
}*/
static void mixmusic_callback(void *udata, Uint8 *stream, int len)
{
if(!Mix_PausedMusic()) {
music_pos += len/4;
music_pos_time = SDL_GetTicks();
}
//I_OutputMsg("MusicPos: %.3f", music_pos);
//HU_DoCEcho(va("MusicPos: %.3f\\Stream: %d\\Length: %i", music_pos,stream,len));
}
#ifdef HAVE_LIBGME
static void mix_gme(void *udata, Uint8 *stream, int len)
{
@ -660,7 +694,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
}
}
if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1)
if (Mix_PlayMusic(music, /*looping && loop_point == 0.0f ? -1 :*/ 0) == -1)
{
CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError());
return true;
@ -670,7 +704,15 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
else
Mix_VolumeMusic((UINT32)music_volume*128/31);
if (loop_point != 0.0f)
Mix_SetPostMix(mixmusic_callback, NULL);
music_pos = 0;
music_pos_time = SDL_GetTicks();
//Mix_Chunk* lengthmusic;
//HU_SetCEchoDuration(4);
//HU_DoCEcho(va("Length: %d\\", lengthmusic->alen));
if (looping)//if (loop_point != 0.0f)
Mix_HookMusicFinished(music_loop);
return true;
}
@ -704,6 +746,47 @@ void I_SetDigMusicVolume(UINT8 volume)
Mix_VolumeMusic((UINT32)volume*128/31);
}
void I_SetMusicPosition(float position)
{
Mix_SetMusicPosition(position);
music_pos = (int)(position * SAMPLE_RATE);
}
float I_GetMusicPosition(void)
{
float const pos = SAMPLE_RATE;
return (
(music_pos-2048) / pos
) + (
(SDL_GetTicks() - music_pos_time) * 0.001f
);
}
void I_FadeInMusic(int ms)
{
Mix_FadeInMusic(music, 0, ms);
}
void I_FadeInMusicPos(int ms, float position)
{
Mix_FadeInMusicPos(music, 0, ms, position);
//music_pos = (int)(position * SAMPLE_RATE);
}
/*
void I_VolumeMusic(int volume)
{
}
*/
void I_FadeOutMusic(int ms)
{
//TODO: music ends if fading before a loop point, fix it
Mix_PlayMusic(music, -1);
Mix_SetMusicPosition(I_GetMusicPosition());
Mix_FadeOutMusic(ms);
Mix_HookMusicFinished(NULL);
//Mix_HookMusicFinished(music_fadeloop);
}
boolean I_SetSongSpeed(float speed)
{
if (speed > 250.0f)
@ -799,6 +882,7 @@ boolean I_PlaySong(INT32 handle, boolean looping)
CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError());
return false;
}
music_pos = 0;
Mix_VolumeMusic((UINT32)music_volume*128/31);
return true;
}