diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d29431226869bd6ba04d21969e297cad2a826092..ac59605c147f8f55f313decf7d5cee19b0adb8b5 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -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; diff --git a/src/i_sound.h b/src/i_sound.h index b3811df8f8de0b22d1c44de5cfbdfcc5fc45d10b..56ed98bba1d28545ed7896b88e37c5d112e0aba8 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -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 // diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 3862709593b4e907b0cf7b04db6514d07c6b7052..09a7a6cfa9a52f2d59908ff582c7668d643d1edf 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -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} }; diff --git a/src/p_mobj.c b/src/p_mobj.c index 25ae8815a17392564337926ef0e5630d908ebd92..b1ba1f43847f5c693be5fc680bf427c88c4fd3d3 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -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) diff --git a/src/p_mobj.h b/src/p_mobj.h index 224a8ca5b93fa873f0a7352af82d08f90685368e..1c69e259796a8ea7f1939f905639c4363331c65f 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -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); diff --git a/src/p_user.c b/src/p_user.c index ef281406f1aeda3fe6334c19809923fc65ec9cd9..1c2e16de877fd02f16836adaece5838c96c98647 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -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) diff --git a/src/s_sound.c b/src/s_sound.c index 1e5f79aa03493ec1daf1955e3b1d4b82b234ade2..e7964fcd9d1862c3c393b66970ccf427484d30bd 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -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); diff --git a/src/s_sound.h b/src/s_sound.h index 12787536b768ca05ea87036abc4e2fc5e16b2b3c..b3f67c795e8e0e8006da1b58249b2820bb28941e 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -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); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 2ce546153d4dbd553d2be488594f303a562084dd..5a1b6c0dbf25b96feaae37fdf9f2e25768d7587c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -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; }