From daf56bc296ed61dfd305151e9936e3a0251a2b8e Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Thu, 9 Apr 2026 23:30:51 -0500 Subject: [PATCH] nuke old Miles SoundEngine, more ifdef removal --- targets/app/common/Audio/SoundEngine.cpp | 1057 ----------------- targets/app/common/Audio/SoundEngine.h | 2 - .../app/common/GameRules/GameRuleManager.cpp | 4 +- targets/minecraft/client/Minecraft.cpp | 4 +- targets/platform/stubs.h | 142 +-- 5 files changed, 7 insertions(+), 1202 deletions(-) diff --git a/targets/app/common/Audio/SoundEngine.cpp b/targets/app/common/Audio/SoundEngine.cpp index c782ae6de..7b769ffad 100644 --- a/targets/app/common/Audio/SoundEngine.cpp +++ b/targets/app/common/Audio/SoundEngine.cpp @@ -24,7 +24,6 @@ #include "platform/PlatformTypes.h" #include "platform/fs/fs.h" -#if defined(__linux__) #define STB_VORBIS_HEADER_ONLY #include "stb_vorbis.c" @@ -55,10 +54,6 @@ int strcasecmp(const char* a, const char* b) { #undef R #undef TRUE #undef FALSE -#endif -#if defined(_WINDOWS64) -#include "app/windows/WindowsGame.h" -#endif // ASSETS const char* SoundEngine::m_szStreamFileA[eStream_Max] = {"calm1", @@ -101,21 +96,13 @@ const char* SoundEngine::m_szStreamFileA[eStream_Max] = {"calm1", "strad", "ward", "where_are_we_now"}; -#if defined(__linux__) char SoundEngine::m_szSoundPath[] = {"app/common/Sound/"}; char SoundEngine::m_szMusicPath[] = {"app/common/"}; char SoundEngine::m_szRedistName[] = {"redist64"}; -#endif -#if defined(_WINDOWS64) -char SoundEngine::m_szSoundPath[] = {"Durango\\Sound\\"}; -char SoundEngine::m_szMusicPath[] = {"music\\"}; -char SoundEngine::m_szRedistName[] = {"redist64"}; -#endif // END ASSETS // Linux specific functions -#if defined(__linux__) // PIMPL'd state for the miniaudio backend. Defined here so SoundEngine.h // stays free of miniaudio.h. @@ -805,1050 +792,6 @@ void SoundEngine::tick(std::shared_ptr* players, float a) { m_validListenerCount = listenerCount; updateMiniAudio(); } -// Classic sound module -#else -void SoundEngine::init(Options* pOptions) { - app.DebugPrintf("---SoundEngine::init\n"); -#if defined(__DISABLE_MILES__) - return; -#endif - - char* redistpath; - -#if defined(_WINDOWS64) - redistpath = AIL_set_redist_directory(m_szRedistName); -#endif - - app.DebugPrintf("---SoundEngine::init - AIL_startup\n"); - S32 ret = AIL_startup(); - - int iNumberOfChannels = initAudioHardware(8); - - // Create a driver to render our audio - 44khz, 16 bit, - m_hDriver = AIL_open_digital_driver(44100, 16, MSS_MC_USE_SYSTEM_CONFIG, 0); - if (m_hDriver == 0) { - app.DebugPrintf("Couldn't open digital sound driver. (%s)\n", - AIL_last_error()); - AIL_shutdown(); - return; - } - app.DebugPrintf("---SoundEngine::init - driver opened\n"); - - AIL_set_event_error_callback(ErrorCallback); - - AIL_set_3D_rolloff_factor(m_hDriver, 1.0); - - // Create an event system tied to that driver - let Miles choose memory - // defaults. - // if (AIL_startup_event_system(m_hDriver, 0, 0, 0) == 0) - // 4J-PB - Durango complains that the default memory (64k)isn't enough - // Error: MilesEvent: Out of event system memory (pool passed to event - // system startup exhausted). AP - increased command buffer from the default - // 5K to 20K for Vita - - if (AIL_startup_event_system(m_hDriver, 1024 * 20, 0, 1024 * 128) == 0) { - app.DebugPrintf("Couldn't init event system (%s).\n", AIL_last_error()); - AIL_close_digital_driver(m_hDriver); - AIL_shutdown(); - app.DebugPrintf( - "---SoundEngine::init - AIL_startup_event_system failed\n"); - return; - } - char szBankName[255]; - strcpy((char*)szBankName, m_szSoundPath); - - strcat((char*)szBankName, "Minecraft.msscmp"); - - m_hBank = AIL_add_soundbank(szBankName, 0); - - if (m_hBank == nullptr) { - char* Error = AIL_last_error(); - app.DebugPrintf("Couldn't open soundbank: %s (%s)\n", szBankName, - Error); - AIL_close_digital_driver(m_hDriver); - AIL_shutdown(); - return; - } - - // #ifdef _DEBUG - HMSSENUM token = MSS_FIRST; - char const* Events[1] = {0}; - S32 EventCount = 0; - while (AIL_enumerate_events(m_hBank, &token, 0, &Events[0])) { - app.DebugPrintf(4, "%d - %s\n", EventCount, Events[0]); - - EventCount++; - } - // #endif - - U64 u64Result; - u64Result = AIL_enqueue_event_by_name("Minecraft/CacheSounds"); - - m_MasterMusicVolume = 1.0f; - m_MasterEffectsVolume = 1.0f; - - // AIL_set_variable_float(0,"UserEffectVol",1); - - m_bSystemMusicPlaying = false; - - m_openStreamThread = nullptr; -} - -// AP - moved to a separate function so it can be called from the mixer callback -// on Vita -void SoundEngine::updateMiles() { - if (m_validListenerCount == 1) { - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - // set the listener as the first player we find - if (m_ListenerA[i].bValid) { - AIL_set_listener_3D_position( - m_hDriver, m_ListenerA[i].vPosition.x, - m_ListenerA[i].vPosition.y, - -m_ListenerA[i] - .vPosition.z); // Flipped sign of z as Miles is - // expecting left handed coord system - AIL_set_listener_3D_orientation( - m_hDriver, -m_ListenerA[i].vOrientFront.x, - m_ListenerA[i].vOrientFront.y, - m_ListenerA[i].vOrientFront.z, 0, 1, - 0); // Flipped sign of z as Miles is expecting left handed - // coord system - break; - } - } - } else { - // 4J-PB - special case for splitscreen - // the shortest distance between any listener and a sound will be used - // to play a sound a set distance away down the z axis. The listener - // position will be set to 0,0,0, and the orientation will be facing - // down the z axis - - AIL_set_listener_3D_position(m_hDriver, 0, 0, 0); - AIL_set_listener_3D_orientation(m_hDriver, 0, 0, 1, 0, 1, 0); - } - - AIL_begin_event_queue_processing(); - - // Iterate over the sounds - S32 StartedCount = 0, CompletedCount = 0, TotalCount = 0; - HMSSENUM token = MSS_FIRST; - MILESEVENTSOUNDINFO SoundInfo; - int Playing = 0; - while (AIL_enumerate_sound_instances(0, &token, 0, 0, 0, &SoundInfo)) { - AUDIO_INFO* game_data = (AUDIO_INFO*)(SoundInfo.UserBuffer); - - if (SoundInfo.Status == MILESEVENT_SOUND_STATUS_PLAYING) { - Playing += 1; - } - - if (SoundInfo.Status != MILESEVENT_SOUND_STATUS_COMPLETE) { - // apply the master volume - // watch for the 'special' volume levels - bool isThunder = false; - if (game_data->volume == 10000.0f) { - isThunder = true; - } - if (game_data->volume > 1) { - game_data->volume = 1; - } - AIL_set_sample_volume_levels( - SoundInfo.Sample, game_data->volume * m_MasterEffectsVolume, - game_data->volume * m_MasterEffectsVolume); - - float distanceScaler = 16.0f; - switch (SoundInfo.Status) { - case MILESEVENT_SOUND_STATUS_PENDING: - // 4J-PB - causes the falloff to be calculated on the PPU - // instead of the SPU, and seems to resolve our distorted - // sound issue - AIL_register_falloff_function_callback( - SoundInfo.Sample, &custom_falloff_function); - - if (game_data->bIs3D) { - AIL_set_sample_is_3D(SoundInfo.Sample, 1); - - int iSound = game_data->iSound - eSFX_MAX; - switch (iSound) { - // Is this the Dragon? - case eSoundType_MOB_ENDERDRAGON_GROWL: - case eSoundType_MOB_ENDERDRAGON_MOVE: - case eSoundType_MOB_ENDERDRAGON_END: - case eSoundType_MOB_ENDERDRAGON_HIT: - distanceScaler = 100.0f; - break; - case eSoundType_FIREWORKS_BLAST: - case eSoundType_FIREWORKS_BLAST_FAR: - case eSoundType_FIREWORKS_LARGE_BLAST: - case eSoundType_FIREWORKS_LARGE_BLAST_FAR: - distanceScaler = 100.0f; - break; - case eSoundType_MOB_GHAST_MOAN: - case eSoundType_MOB_GHAST_SCREAM: - case eSoundType_MOB_GHAST_DEATH: - case eSoundType_MOB_GHAST_CHARGE: - case eSoundType_MOB_GHAST_FIREBALL: - distanceScaler = 30.0f; - break; - } - - // Set a special distance scaler for thunder, which we - // respond to by having no attenutation - if (isThunder) { - distanceScaler = 10000.0f; - } - } else { - AIL_set_sample_is_3D(SoundInfo.Sample, 0); - } - - AIL_set_sample_3D_distances(SoundInfo.Sample, - distanceScaler, 1, 0); - // set the pitch - if (!game_data->bUseSoundsPitchVal) { - AIL_set_sample_playback_rate_factor(SoundInfo.Sample, - game_data->pitch); - } - - if (game_data->bIs3D) { - if (m_validListenerCount > 1) { - float fClosest = 10000.0f; - int iClosestListener = 0; - float fClosestX = 0.0f, fClosestY = 0.0f, - fClosestZ = 0.0f, fDist; - // need to calculate the distance from the sound to - // the nearest listener - use Manhattan Distance as - // the decision - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (m_ListenerA[i].bValid) { - float x, y, z; - - x = fabs(m_ListenerA[i].vPosition.x - - game_data->x); - y = fabs(m_ListenerA[i].vPosition.y - - game_data->y); - z = fabs(m_ListenerA[i].vPosition.z - - game_data->z); - fDist = x + y + z; - - if (fDist < fClosest) { - fClosest = fDist; - fClosestX = x; - fClosestY = y; - fClosestZ = z; - iClosestListener = i; - } - } - } - - // our distances in the world aren't very big, so - // floats rather than casts to doubles should be - // fine - fDist = sqrtf((fClosestX * fClosestX) + - (fClosestY * fClosestY) + - (fClosestZ * fClosestZ)); - AIL_set_sample_3D_position(SoundInfo.Sample, 0, 0, - fDist); - - // app.DebugPrintf("Playing sound %d %f from nearest - // listener - // [%d]\n",SoundInfo.EventID,fDist,iClosestListener); - } else { - AIL_set_sample_3D_position( - SoundInfo.Sample, game_data->x, game_data->y, - -game_data->z); // Flipped sign of z as Miles - // is expecting left handed - // coord system - } - } - break; - - default: - if (game_data->bIs3D) { - if (m_validListenerCount > 1) { - float fClosest = 10000.0f; - int iClosestListener = 0; - float fClosestX = 0.0f, fClosestY = 0.0f, - fClosestZ = 0.0f, fDist; - // need to calculate the distance from the sound to - // the nearest listener - use Manhattan Distance as - // the decision - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (m_ListenerA[i].bValid) { - float x, y, z; - - x = fabs(m_ListenerA[i].vPosition.x - - game_data->x); - y = fabs(m_ListenerA[i].vPosition.y - - game_data->y); - z = fabs(m_ListenerA[i].vPosition.z - - game_data->z); - fDist = x + y + z; - - if (fDist < fClosest) { - fClosest = fDist; - fClosestX = x; - fClosestY = y; - fClosestZ = z; - iClosestListener = i; - } - } - } - // our distances in the world aren't very big, so - // floats rather than casts to doubles should be - // fine - fDist = sqrtf((fClosestX * fClosestX) + - (fClosestY * fClosestY) + - (fClosestZ * fClosestZ)); - AIL_set_sample_3D_position(SoundInfo.Sample, 0, 0, - fDist); - - // app.DebugPrintf("Playing sound %d %f from nearest - // listener - // [%d]\n",SoundInfo.EventID,fDist,iClosestListener); - } else { - AIL_set_sample_3D_position( - SoundInfo.Sample, game_data->x, game_data->y, - -game_data->z); // Flipped sign of z as Miles - // is expecting left handed - // coord system - } - } - break; - } - } - } - AIL_complete_event_queue_processing(); -} - -// #define DISTORTION_TEST -#if defined(DISTORTION_TEST) -static float fVal = 0.0f; -#endif -///////////////////////////////////////////// -// -// tick -// -///////////////////////////////////////////// - -void SoundEngine::tick(std::shared_ptr* players, float a) { -#if defined(__DISABLE_MILES__) - return; -#endif - - // update the listener positions - int listenerCount = 0; -#if defined(DISTORTION_TEST) - float fX, fY, fZ; -#endif - if (players) { - bool bListenerPostionSet = false; - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (players[i] != nullptr) { - m_ListenerA[i].bValid = true; - F32 x, y, z; - x = players[i]->xo + (players[i]->x - players[i]->xo) * a; - y = players[i]->yo + (players[i]->y - players[i]->yo) * a; - z = players[i]->zo + (players[i]->z - players[i]->zo) * a; - - float yRot = players[i]->yRotO + - (players[i]->yRot - players[i]->yRotO) * a; - float yCos = - (float)cos(-yRot * Mth::DEG_TO_RAD - std::numbers::pi); - float ySin = - (float)sin(-yRot * Mth::DEG_TO_RAD - std::numbers::pi); - - // store the listener positions for splitscreen - m_ListenerA[i].vPosition.x = x; - m_ListenerA[i].vPosition.y = y; - m_ListenerA[i].vPosition.z = z; - - m_ListenerA[i].vOrientFront.x = ySin; - m_ListenerA[i].vOrientFront.y = 0; - m_ListenerA[i].vOrientFront.z = yCos; - - listenerCount++; - } else { - m_ListenerA[i].bValid = false; - } - } - } - - // If there were no valid players set, make up a default listener - if (listenerCount == 0) { - m_ListenerA[0].vPosition.x = 0; - m_ListenerA[0].vPosition.y = 0; - m_ListenerA[0].vPosition.z = 0; - m_ListenerA[0].vOrientFront.x = 0; - m_ListenerA[0].vOrientFront.y = 0; - m_ListenerA[0].vOrientFront.z = 1.0f; - listenerCount++; - } - m_validListenerCount = listenerCount; - - updateMiles(); -} -SoundEngine::SoundEngine() { - random = new Random(); - m_hStream = 0; - m_StreamState = eMusicStreamState_Idle; - m_iMusicDelay = 0; - m_validListenerCount = 0; - - m_bHeardTrackA = nullptr; - - // Start the streaming music playing some music from the overworld - SetStreamingSounds(eStream_Overworld_Calm1, eStream_Overworld_piano3, - eStream_Nether1, eStream_Nether4, eStream_end_dragon, - eStream_end_end, eStream_CD_1); - - m_musicID = getMusicID(LevelData::DIMENSION_OVERWORLD); - - m_StreamingAudioInfo.bIs3D = false; - m_StreamingAudioInfo.x = 0; - m_StreamingAudioInfo.y = 0; - m_StreamingAudioInfo.z = 0; - m_StreamingAudioInfo.volume = 1; - m_StreamingAudioInfo.pitch = 1; - - memset(CurrentSoundsPlaying, 0, sizeof(int) * (eSoundType_MAX + eSFX_MAX)); - memset(m_ListenerA, 0, sizeof(AUDIO_LISTENER) * XUSER_MAX_COUNT); -} - -void SoundEngine::destroy() {} -#if defined(_DEBUG) -void SoundEngine::GetSoundName(char* szSoundName, int iSound) { - strcpy((char*)szSoundName, "Minecraft/"); - std::string name = wchSoundNames[iSound]; - char* SoundName = (char*)ConvertSoundPathToName(name); - strcat((char*)szSoundName, SoundName); -} -#endif -///////////////////////////////////////////// -// -// play -// -///////////////////////////////////////////// -void SoundEngine::play(int iSound, float x, float y, float z, float volume, - float pitch) { - U8 szSoundName[256]; - - if (iSound == -1) { - app.DebugPrintf(6, "PlaySound with sound of -1 !!!!!!!!!!!!!!!\n"); - return; - } - - // AP removed old counting system. Now relying on Miles' Play Count Limit - /* // if we are already playing loads of this sounds ignore this one - if(CurrentSoundsPlaying[iSound+eSFX_MAX]>MAX_SAME_SOUNDS_PLAYING) - { - // std::string name = wchSoundNames[iSound]; - // char *SoundName = (char *)ConvertSoundPathToName(name); - // app.DebugPrintf("Too many %s sounds playing!\n",SoundName); - return; - }*/ - - // if (iSound != eSoundType_MOB_IRONGOLEM_WALK) return; - - // build the name - strcpy((char*)szSoundName, "Minecraft/"); - -#if defined(DISTORTION_TEST) - std::string name = wchSoundNames[eSoundType_MOB_ENDERDRAGON_GROWL]; -#else - std::string name = wchSoundNames[iSound]; -#endif - - char* SoundName = (char*)ConvertSoundPathToName(name); - strcat((char*)szSoundName, SoundName); - - // app.DebugPrintf(6,"PlaySound - %d - %s - %s (%f %f %f, vol %f, pitch - //%f)\n",iSound, SoundName, szSoundName,x,y,z,volume,pitch); - - AUDIO_INFO AudioInfo; - AudioInfo.x = x; - AudioInfo.y = y; - AudioInfo.z = z; - AudioInfo.volume = volume; - AudioInfo.pitch = pitch; - AudioInfo.bIs3D = true; - AudioInfo.bUseSoundsPitchVal = false; - AudioInfo.iSound = iSound + eSFX_MAX; -#if defined(_DEBUG) - strncpy(AudioInfo.chName, (char*)szSoundName, 64); -#endif - - S32 token = AIL_enqueue_event_start(); - AIL_enqueue_event_buffer(&token, &AudioInfo, sizeof(AUDIO_INFO), 0); - AIL_enqueue_event_end_named(token, (char*)szSoundName); -} - -///////////////////////////////////////////// -// -// playUI -// -///////////////////////////////////////////// -void SoundEngine::playUI(int iSound, float volume, float pitch) { - U8 szSoundName[256]; - std::string name; - // we have some game sounds played as UI sounds... - // Not the best way to do this, but it seems to only be the portal sounds - - if (iSound >= eSFX_MAX) { - // AP removed old counting system. Now relying on Miles' Play Count - // Limit - /* // if we are already playing loads of this sounds ignore - this one - if(CurrentSoundsPlaying[iSound+eSFX_MAX]>MAX_SAME_SOUNDS_PLAYING) - return;*/ - - // build the name - strcpy((char*)szSoundName, "Minecraft/"); - name = wchSoundNames[iSound]; - } else { - // AP removed old counting system. Now relying on Miles' Play Count - // Limit - /* // if we are already playing loads of this sounds ignore - this one if(CurrentSoundsPlaying[iSound]>MAX_SAME_SOUNDS_PLAYING) - return;*/ - - // build the name - strcpy((char*)szSoundName, "Minecraft/UI/"); - name = wchUISoundNames[iSound]; - } - - char* SoundName = (char*)ConvertSoundPathToName(name); - strcat((char*)szSoundName, SoundName); - // app.DebugPrintf("UI: Playing %s, volume %f, pitch - //%f\n",SoundName,volume,pitch); - - // app.DebugPrintf("PlaySound - %d - %s\n",iSound, SoundName); - - AUDIO_INFO AudioInfo; - memset(&AudioInfo, 0, sizeof(AUDIO_INFO)); - AudioInfo.volume = volume; // will be multiplied by the master volume - AudioInfo.pitch = pitch; - AudioInfo.bUseSoundsPitchVal = true; - if (iSound >= eSFX_MAX) { - AudioInfo.iSound = iSound + eSFX_MAX; - } else { - AudioInfo.iSound = iSound; - } -#if defined(_DEBUG) - strncpy(AudioInfo.chName, (char*)szSoundName, 64); -#endif - - // 4J-PB - not going to stop UI events happening based on the number of - // currently playing sounds - S32 token = AIL_enqueue_event_start(); - AIL_enqueue_event_buffer(&token, &AudioInfo, sizeof(AUDIO_INFO), 0); - AIL_enqueue_event_end_named(token, (char*)szSoundName); -} -///////////////////////////////////////////// -// -// playStreaming -// -///////////////////////////////////////////// -void SoundEngine::playStreaming(const std::string& name, float x, float y, - float z, float volume, float pitch, - bool bMusicDelay) { - // This function doesn't actually play a streaming sound, just sets states - // and an id for the music tick to play it Level audio will be played when a - // play with an empty name comes in CD audio will be played when a named - // stream comes in - - m_StreamingAudioInfo.x = x; - m_StreamingAudioInfo.y = y; - m_StreamingAudioInfo.z = z; - m_StreamingAudioInfo.volume = volume; - m_StreamingAudioInfo.pitch = pitch; - - if (m_StreamState == eMusicStreamState_Playing) { - m_StreamState = eMusicStreamState_Stop; - } else if (m_StreamState == eMusicStreamState_Opening) { - m_StreamState = eMusicStreamState_OpeningCancel; - } - - if (name.empty()) { - // music, or stop CD - m_StreamingAudioInfo.bIs3D = false; - - // we need a music id - // random delay of up to 3 minutes for music - m_iMusicDelay = random->nextInt( - 20 * 60 * 3); // random->nextInt(20 * 60 * 10) + 20 * 60 * 10; - -#if defined(_DEBUG) - m_iMusicDelay = 0; -#endif - Minecraft* pMinecraft = Minecraft::GetInstance(); - - bool playerInEnd = false; - bool playerInNether = false; - - for (unsigned int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (pMinecraft->localplayers[i] != nullptr) { - if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_END) { - playerInEnd = true; - } else if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_NETHER) { - playerInNether = true; - } - } - } - if (playerInEnd) { - m_musicID = getMusicID(LevelData::DIMENSION_END); - } else if (playerInNether) { - m_musicID = getMusicID(LevelData::DIMENSION_NETHER); - } else { - m_musicID = getMusicID(LevelData::DIMENSION_OVERWORLD); - } - } else { - // jukebox - m_StreamingAudioInfo.bIs3D = true; - m_musicID = getMusicID(name); - m_iMusicDelay = 0; - } -} -int SoundEngine::OpenStreamThreadProc(void* lpParameter) { -#if defined(__DISABLE_MILES__) - return 0; -#endif - SoundEngine* soundEngine = (SoundEngine*)lpParameter; - soundEngine->m_hStream = - AIL_open_stream(soundEngine->m_hDriver, soundEngine->m_szStreamName, 0); - return 0; -} -///////////////////////////////////////////// -// -// playMusicTick -// -///////////////////////////////////////////// -void SoundEngine::playMusicTick() { - // AP - vita will update the music during the mixer callback - playMusicUpdate(); -} - -// AP - moved to a separate function so it can be called from the mixer callback -// on Vita -void SoundEngine::playMusicUpdate() { - // return; - static bool firstCall = true; - static float fMusicVol = 0.0f; - if (firstCall) { - fMusicVol = getMasterMusicVolume(); - firstCall = false; - } - - switch (m_StreamState) { - case eMusicStreamState_Idle: - - // start a stream playing - if (m_iMusicDelay > 0) { - m_iMusicDelay--; - return; - } - - if (m_musicID != -1) { - // start playing it - - strcpy((char*)m_szStreamName, m_szMusicPath); - // are we using a mash-up pack? - // if(pMinecraft && !pMinecraft->skins->isUsingDefaultSkin() && - // pMinecraft->skins->getSelected()->hasAudio()) - if (Minecraft::GetInstance() - ->skins->getSelected() - ->hasAudio()) { - // It's a mash-up - need to use the DLC path for the music - TexturePack* pTexPack = - Minecraft::GetInstance()->skins->getSelected(); - DLCTexturePack* pDLCTexPack = (DLCTexturePack*)pTexPack; - DLCPack* pack = pDLCTexPack->getDLCInfoParentPack(); - DLCAudioFile* dlcAudioFile = (DLCAudioFile*)pack->getFile( - DLCManager::e_DLCType_Audio, 0); - - app.DebugPrintf("Mashup pack \n"); - - // build the name - - // if the music ID is beyond the end of the texture pack - // music files, then it's a CD - if (m_musicID < m_iStream_CD_1) { - SetIsPlayingStreamingGameMusic(true); - SetIsPlayingStreamingCDMusic(false); - m_MusicType = eMusicType_Game; - m_StreamingAudioInfo.bIs3D = false; - - std::string& wstrSoundName = - dlcAudioFile->GetSoundName(m_musicID); - char szName[255]; - strncpy(szName, wstrSoundName.c_str(), 255); - - std::string strFile = - "TPACK:\\Data\\" + string(szName) + ".binka"; - std::string mountedPath = - PlatformStorage.GetMountedPath(strFile); - strcpy(m_szStreamName, mountedPath.c_str()); - } else { - SetIsPlayingStreamingGameMusic(false); - SetIsPlayingStreamingCDMusic(true); - m_MusicType = eMusicType_CD; - m_StreamingAudioInfo.bIs3D = true; - - // Need to adjust to index into the cds in the game's - // m_szStreamFileA - strcat((char*)m_szStreamName, "cds/"); - strcat((char*)m_szStreamName, - m_szStreamFileA[m_musicID - m_iStream_CD_1 + - eStream_CD_1]); - strcat((char*)m_szStreamName, ".binka"); - } - } else { - // 4J-PB - if this is a PS3 disc patch, we have to check if - // the music file is in the patch data - if (m_musicID < m_iStream_CD_1) { - SetIsPlayingStreamingGameMusic(true); - SetIsPlayingStreamingCDMusic(false); - m_MusicType = eMusicType_Game; - m_StreamingAudioInfo.bIs3D = false; - // build the name - strcat((char*)m_szStreamName, "music/"); - } else { - SetIsPlayingStreamingGameMusic(false); - SetIsPlayingStreamingCDMusic(true); - m_MusicType = eMusicType_CD; - m_StreamingAudioInfo.bIs3D = true; - // build the name - strcat((char*)m_szStreamName, "cds/"); - } - strcat((char*)m_szStreamName, m_szStreamFileA[m_musicID]); - strcat((char*)m_szStreamName, ".binka"); - } - - // std::string name = - // m_szStreamFileA[m_musicID];char*SoundName=(char - // *)ConvertSoundPathToName(name);strcat((char - // *)szStreamName,SoundName); - - app.DebugPrintf("Starting streaming - %s\n", m_szStreamName); - - // Don't actually open in this thread, as it can block for - // ~300ms. - m_openStreamThread = new C4JThread(OpenStreamThreadProc, this, - "OpenStreamThreadProc"); - m_openStreamThread->run(); - m_StreamState = eMusicStreamState_Opening; - } - break; - - case eMusicStreamState_Opening: - // If the open stream thread is complete, then we are ready to - // proceed to actually playing - if (!m_openStreamThread->isRunning()) { - delete m_openStreamThread; - m_openStreamThread = nullptr; - - HSAMPLE hSample = AIL_stream_sample_handle(m_hStream); - - // 4J-PB - causes the falloff to be calculated on the PPU - // instead of the SPU, and seems to resolve our distorted sound - // issue - AIL_register_falloff_function_callback( - hSample, &custom_falloff_function); - - if (m_StreamingAudioInfo.bIs3D) { - AIL_set_sample_3D_distances( - hSample, 64.0f, 1, - 0); // Larger distance scaler for music discs - if (m_validListenerCount > 1) { - float fClosest = 10000.0f; - int iClosestListener = 0; - float fClosestX = 0.0f, fClosestY = 0.0f, - fClosestZ = 0.0f, fDist; - // need to calculate the distance from the sound to the - // nearest listener - use Manhattan Distance as the - // decision - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (m_ListenerA[i].bValid) { - float x, y, z; - - x = fabs(m_ListenerA[i].vPosition.x - - m_StreamingAudioInfo.x); - y = fabs(m_ListenerA[i].vPosition.y - - m_StreamingAudioInfo.y); - z = fabs(m_ListenerA[i].vPosition.z - - m_StreamingAudioInfo.z); - fDist = x + y + z; - - if (fDist < fClosest) { - fClosest = fDist; - fClosestX = x; - fClosestY = y; - fClosestZ = z; - iClosestListener = i; - } - } - } - - // our distances in the world aren't very big, so floats - // rather than casts to doubles should be fine - fDist = sqrtf((fClosestX * fClosestX) + - (fClosestY * fClosestY) + - (fClosestZ * fClosestZ)); - AIL_set_sample_3D_position(hSample, 0, 0, fDist); - } else { - AIL_set_sample_3D_position( - hSample, m_StreamingAudioInfo.x, - m_StreamingAudioInfo.y, - -m_StreamingAudioInfo - .z); // Flipped sign of z as Miles is - // expecting left handed coord system - } - } else { - // clear the 3d flag on the stream after a jukebox finishes - // and streaming music starts - AIL_set_sample_is_3D(hSample, 0); - } - // set the pitch - app.DebugPrintf("Sample rate:%d\n", - AIL_sample_playback_rate(hSample)); - AIL_set_sample_playback_rate_factor(hSample, - m_StreamingAudioInfo.pitch); - // set the volume - AIL_set_sample_volume_levels( - hSample, - m_StreamingAudioInfo.volume * getMasterMusicVolume(), - m_StreamingAudioInfo.volume * getMasterMusicVolume()); - - AIL_start_stream(m_hStream); - - m_StreamState = eMusicStreamState_Playing; - } - break; - case eMusicStreamState_OpeningCancel: - if (!m_openStreamThread->isRunning()) { - delete m_openStreamThread; - m_openStreamThread = nullptr; - m_StreamState = eMusicStreamState_Stop; - } - break; - case eMusicStreamState_Stop: - // should gradually take the volume down in steps - AIL_pause_stream(m_hStream, 1); - AIL_close_stream(m_hStream); - m_hStream = 0; - SetIsPlayingStreamingCDMusic(false); - SetIsPlayingStreamingGameMusic(false); - m_StreamState = eMusicStreamState_Idle; - break; - case eMusicStreamState_Stopping: - break; - case eMusicStreamState_Play: - break; - case eMusicStreamState_Playing: - if (GetIsPlayingStreamingGameMusic()) { - // if(m_MusicInfo.pCue!=nullptr) - { - bool playerInEnd = false; - bool playerInNether = false; - Minecraft* pMinecraft = Minecraft::GetInstance(); - for (unsigned int i = 0; i < MAX_LOCAL_PLAYERS; ++i) { - if (pMinecraft->localplayers[i] != nullptr) { - if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_END) { - playerInEnd = true; - } else if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_NETHER) { - playerInNether = true; - } - } - } - - if (playerInEnd && !GetIsPlayingEndMusic()) { - m_StreamState = eMusicStreamState_Stop; - - // Set the end track - m_musicID = getMusicID(LevelData::DIMENSION_END); - SetIsPlayingEndMusic(true); - SetIsPlayingNetherMusic(false); - } else if (!playerInEnd && GetIsPlayingEndMusic()) { - if (playerInNether) { - m_StreamState = eMusicStreamState_Stop; - - // Set the end track - m_musicID = getMusicID(LevelData::DIMENSION_NETHER); - SetIsPlayingEndMusic(false); - SetIsPlayingNetherMusic(true); - } else { - m_StreamState = eMusicStreamState_Stop; - - // Set the end track - m_musicID = - getMusicID(LevelData::DIMENSION_OVERWORLD); - SetIsPlayingEndMusic(false); - SetIsPlayingNetherMusic(false); - } - } else if (playerInNether && !GetIsPlayingNetherMusic()) { - m_StreamState = eMusicStreamState_Stop; - // set the Nether track - m_musicID = getMusicID(LevelData::DIMENSION_NETHER); - SetIsPlayingNetherMusic(true); - SetIsPlayingEndMusic(false); - } else if (!playerInNether && GetIsPlayingNetherMusic()) { - if (playerInEnd) { - m_StreamState = eMusicStreamState_Stop; - // set the Nether track - m_musicID = getMusicID(LevelData::DIMENSION_END); - SetIsPlayingNetherMusic(false); - SetIsPlayingEndMusic(true); - } else { - m_StreamState = eMusicStreamState_Stop; - // set the Nether track - m_musicID = - getMusicID(LevelData::DIMENSION_OVERWORLD); - SetIsPlayingNetherMusic(false); - SetIsPlayingEndMusic(false); - } - } - - // volume change required? - if (fMusicVol != getMasterMusicVolume()) { - fMusicVol = getMasterMusicVolume(); - HSAMPLE hSample = AIL_stream_sample_handle(m_hStream); - // AIL_set_sample_3D_position( hSample, - // m_StreamingAudioInfo.x, m_StreamingAudioInfo.y, - // m_StreamingAudioInfo.z ); - AIL_set_sample_volume_levels(hSample, fMusicVol, - fMusicVol); - } - } - } else { - // Music disc playing - if it's a 3D stream, then set the - // position - we don't have any streaming audio in the world - // that moves, so this isn't required unless we have more than - // one listener, and are setting the listening position to the - // origin and setting a fake position for the sound down the z - // axis - if (m_StreamingAudioInfo.bIs3D) { - if (m_validListenerCount > 1) { - float fClosest = 10000.0f; - int iClosestListener = 0; - float fClosestX = 0.0f, fClosestY = 0.0f, - fClosestZ = 0.0f, fDist; - - // need to calculate the distance from the sound to the - // nearest listener - use Manhattan Distance as the - // decision - for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (m_ListenerA[i].bValid) { - float x, y, z; - - x = fabs(m_ListenerA[i].vPosition.x - - m_StreamingAudioInfo.x); - y = fabs(m_ListenerA[i].vPosition.y - - m_StreamingAudioInfo.y); - z = fabs(m_ListenerA[i].vPosition.z - - m_StreamingAudioInfo.z); - fDist = x + y + z; - - if (fDist < fClosest) { - fClosest = fDist; - fClosestX = x; - fClosestY = y; - fClosestZ = z; - iClosestListener = i; - } - } - } - - // our distances in the world aren't very big, so floats - // rather than casts to doubles should be fine - HSAMPLE hSample = AIL_stream_sample_handle(m_hStream); - fDist = sqrtf((fClosestX * fClosestX) + - (fClosestY * fClosestY) + - (fClosestZ * fClosestZ)); - AIL_set_sample_3D_position(hSample, 0, 0, fDist); - } - } - } - - break; - - case eMusicStreamState_Completed: { - // random delay of up to 3 minutes for music - m_iMusicDelay = random->nextInt( - 20 * 60 * 3); // random->nextInt(20 * 60 * 10) + 20 * 60 * 10; - // Check if we have a local player in The Nether or in The End, and - // play that music if they are - Minecraft* pMinecraft = Minecraft::GetInstance(); - bool playerInEnd = false; - bool playerInNether = false; - - for (unsigned int i = 0; i < MAX_LOCAL_PLAYERS; i++) { - if (pMinecraft->localplayers[i] != nullptr) { - if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_END) { - playerInEnd = true; - } else if (pMinecraft->localplayers[i]->dimension == - LevelData::DIMENSION_NETHER) { - playerInNether = true; - } - } - } - if (playerInEnd) { - m_musicID = getMusicID(LevelData::DIMENSION_END); - SetIsPlayingEndMusic(true); - SetIsPlayingNetherMusic(false); - } else if (playerInNether) { - m_musicID = getMusicID(LevelData::DIMENSION_NETHER); - SetIsPlayingNetherMusic(true); - SetIsPlayingEndMusic(false); - } else { - m_musicID = getMusicID(LevelData::DIMENSION_OVERWORLD); - SetIsPlayingNetherMusic(false); - SetIsPlayingEndMusic(false); - } - - m_StreamState = eMusicStreamState_Idle; - } break; - } - - // check the status of the stream - this is for when a track completes - // rather than is stopped by the user action - - if (m_hStream != 0) { - if (AIL_stream_status(m_hStream) == SMP_DONE) // SMP_DONE - { - AIL_close_stream(m_hStream); - m_hStream = 0; - SetIsPlayingStreamingCDMusic(false); - SetIsPlayingStreamingGameMusic(false); - - m_StreamState = eMusicStreamState_Completed; - } - } -} -F32 AILCALLBACK custom_falloff_function(HSAMPLE S, F32 distance, - F32 rolloff_factor, F32 min_dist, - F32 max_dist) { - F32 result; - - // This is now emulating the linear fall-off function that we used on the - // Xbox 360. The parameter which is passed as "max_dist" is the only one - // actually used, and is generally used as CurveDistanceScaler is used on - // XACT on the Xbox. A special value of 10000.0f is passed for thunder, - // which has no attenuation - - if (max_dist == 10000.0f) { - return 1.0f; - } - - result = 1.0f - (distance / max_dist); - if (result < 0.0f) result = 0.0f; - if (result > 1.0f) result = 1.0f; - - return result; -} -#endif // Universal, these functions shouldn't need platform specific // implementations diff --git a/targets/app/common/Audio/SoundEngine.h b/targets/app/common/Audio/SoundEngine.h index f00833434..8642b6ad4 100644 --- a/targets/app/common/Audio/SoundEngine.h +++ b/targets/app/common/Audio/SoundEngine.h @@ -142,9 +142,7 @@ private: float getMasterMusicVolume(); // platform specific functions int initAudioHardware(int iMinSpeakers) { return iMinSpeakers; } -#if defined(__linux__) void updateMiniAudio(); -#endif int GetRandomishTrack(int iStart, int iEnd); diff --git a/targets/app/common/GameRules/GameRuleManager.cpp b/targets/app/common/GameRules/GameRuleManager.cpp index a8c66c0d6..0faab72ad 100644 --- a/targets/app/common/GameRules/GameRuleManager.cpp +++ b/targets/app/common/GameRules/GameRuleManager.cpp @@ -640,7 +640,7 @@ void GameRuleManager::processSchematicsLighting(LevelChunk* levelChunk) { } void GameRuleManager::loadDefaultGameRules() { -#if !defined(__linux__) +#if 0 #if defined(_WINDOWS64) File packedTutorialFile("Windows64Media\\Tutorial\\Tutorial.pck"); if (!packedTutorialFile.exists()) @@ -656,6 +656,8 @@ void GameRuleManager::loadDefaultGameRules() { app.GetString(IDS_TUTORIALSAVENAME)); } #else + // 4jcraft: brought over from TU18 so the tutorial world loads from assets + // TODO clean this up std::string fpTutorial = "Tutorial.pck"; if (app.getArchiveFileSize(fpTutorial) >= 0) { DLCPack* pack = new DLCPack("", 0xffffffff); diff --git a/targets/minecraft/client/Minecraft.cpp b/targets/minecraft/client/Minecraft.cpp index 025965413..f4890ddb3 100644 --- a/targets/minecraft/client/Minecraft.cpp +++ b/targets/minecraft/client/Minecraft.cpp @@ -471,9 +471,7 @@ File Minecraft::getWorkingDirectory(const std::string& applicationName) { // 4jcraft: ported to C++ std::string userHome = getenv("HOME"); File* workingDirectory; -#if defined(__linux__) - workingDirectory = new File(userHome, '.' + applicationName + '/'); -#elif defined(_WINDOWS64) +#if defined(_WINDOWS64) std::string applicationData = getenv("APPDATA"); if (!applicationData.empty()) { workingDirectory = diff --git a/targets/platform/stubs.h b/targets/platform/stubs.h index 5ef9a019f..8d4fd8721 100644 --- a/targets/platform/stubs.h +++ b/targets/platform/stubs.h @@ -1,11 +1,11 @@ #pragma once -#include - -#ifdef __linux__ #include #include +#include + +#include "java/File.h" #include "renderer/gl/gl_compat.h" #undef GL_SMOOTH @@ -42,125 +42,6 @@ void glEndQueryARB(int); void glGetQueryObjectuARB(int, int, IntBuffer*); void glReadPixels(int, int, int, int, int, int, ByteBuffer*); -#else - -const int GL_BYTE = 0; -const int GL_FLOAT = 0; -const int GL_UNSIGNED_BYTE = 0; - -const int GL_COLOR_ARRAY = 0; -const int GL_VERTEX_ARRAY = 0; -const int GL_NORMAL_ARRAY = 0; -const int GL_TEXTURE_COORD_ARRAY = 0; - -const int GL_COMPILE = 0x1300; - -const int GL_NORMALIZE = 0; - -const int GL_RESCALE_NORMAL = 0; - -const int GL_SMOOTH = 0; -const int GL_FLAT = 0; - -const int GL_RGBA = 0; -const int GL_BGRA = 1; -const int GL_BGR = 0; - -const int GL_SAMPLES_PASSED_ARB = 0; -const int GL_QUERY_RESULT_AVAILABLE_ARB = 0; -const int GL_QUERY_RESULT_ARB = 0; - -const int GL_POLYGON_OFFSET_FILL = 0; - -const int GL_FRONT = 0; -const int GL_BACK = 1; -const int GL_FRONT_AND_BACK = 2; - -const int GL_COLOR_MATERIAL = 0; - -const int GL_AMBIENT_AND_DIFFUSE = 0; - -const int GL_TEXTURE1 = 0; -const int GL_TEXTURE0 = 1; - -void glFlush(); -void glTexGeni(int, int, int); -void glTexGen(int, int, FloatBuffer*); -void glReadPixels(int, int, int, int, int, int, ByteBuffer*); -void glClearDepth(double); -void glCullFace(int); -void glDeleteLists(int, int); -void glGenTextures(IntBuffer*); -int glGenTextures(); -int glGenLists(int); -void glLight(int, int, FloatBuffer*); -void glLightModel(int, FloatBuffer*); -void glGetFloat(int a, FloatBuffer* b); -void glTexCoordPointer(int, int, int, int); -void glTexCoordPointer(int, int, FloatBuffer*); -void glNormalPointer(int, int, int); -void glNormalPointer(int, ByteBuffer*); -void glEnableClientState(int); -void glDisableClientState(int); -void glColorPointer(int, bool, int, ByteBuffer*); -void glColorPointer(int, int, int, int); -void glVertexPointer(int, int, int, int); -void glVertexPointer(int, int, FloatBuffer*); -void glDrawArrays(int, int, int); -void glTranslatef(float, float, float); -void glRotatef(float, float, float, float); -void glNewList(int, int); -void glEndList(int vertexCount = 0); -void glCallList(int); -void glPopMatrix(); -void glPushMatrix(); -void glColor3f(float, float, float); -void glScalef(float, float, float); -void glMultMatrixf(float*); -void glColor4f(float, float, float, float); -void glDisable(int); -void glEnable(int); -void glBlendFunc(int, int); -void glDepthMask(bool); -void glNormal3f(float, float, float); -void glDepthFunc(int); -void glMatrixMode(int); -void glLoadIdentity(); -void glBindTexture(int, int); -void glTexParameteri(int, int, int); -void glTexImage2D(int, int, int, int, int, int, int, int, ByteBuffer*); -void glDeleteTextures(IntBuffer*); -void glDeleteTextures(int); -void glCallLists(IntBuffer*); -void glGenQueriesARB(IntBuffer*); -void glColorMask(bool, bool, bool, bool); -void glBeginQueryARB(int, int); -void glEndQueryARB(int); -void glGetQueryObjectuARB(int, int, IntBuffer*); -void glShadeModel(int); -void glPolygonOffset(float, float); -void glLineWidth(float); -void glScaled(double, double, double); -void gluPerspective(float, float, float, float); -void glClear(int); -void glViewport(int, int, int, int); -void glAlphaFunc(int, float); -void glOrtho(float, float, float, float, float, float); -void glClearColor(float, float, float, float); -void glFogi(int, int); -void glFogf(int, float); -void glFog(int, FloatBuffer*); -void glColorMaterial(int, int); -void glMultiTexCoord2f(int, float, float); - -void glClientActiveTexture(int); -void glActiveTexture(int); - -#endif - -#ifdef __linux__ -#include "java/File.h" - class GL11 { public: static const int GL_SMOOTH = 0x1D01; @@ -179,23 +60,6 @@ public: static void glBufferDataARB(int, ByteBuffer*, int) {} static void glGenBuffersARB(IntBuffer*) {} }; -#else -class GL11 { -public: - static const int GL_SMOOTH = 0; - static const int GL_FLAT = 0; - static void glShadeModel(int) {}; -}; - -class ARBVertexBufferObject { -public: - static const int GL_ARRAY_BUFFER_ARB = 0; - static const int GL_STREAM_DRAW_ARB = 0; - static void glBindBufferARB(int, int) {} - static void glBufferDataARB(int, ByteBuffer*, int) {} - static void glGenBuffersARB(IntBuffer*) {} -}; -#endif class Level; class Player;