diff --git a/src/cdogs/cwolfmap/audio.c b/src/cdogs/cwolfmap/audio.c index cb766d501..4a9ee34d1 100644 --- a/src/cdogs/cwolfmap/audio.c +++ b/src/cdogs/cwolfmap/audio.c @@ -421,6 +421,8 @@ int CWAudioGetLevelMusic(const CWMapType type, const int level) return CWAudioWL6GetLevelMusic(level); case CWMAPTYPE_SOD: return CWAudioSODGetLevelMusic(level); + case CWMAPTYPE_N3D: + return CWAudioN3DGetLevelMusic(level); default: return -1; } @@ -435,6 +437,8 @@ int CWAudioGetSong(const CWMapType type, const CWSongType song) return CWAudioWL6GetSong(song); case CWMAPTYPE_SOD: return CWAudioSODGetSong(song); + case CWMAPTYPE_N3D: + return CWAudioN3DGetSong(song); default: return -1; } diff --git a/src/cdogs/cwolfmap/audion3d.h b/src/cdogs/cwolfmap/audion3d.h index a6ec5478a..7ca1e1d7b 100644 --- a/src/cdogs/cwolfmap/audion3d.h +++ b/src/cdogs/cwolfmap/audion3d.h @@ -6,11 +6,11 @@ // Base offsets // #define STARTPCSOUNDS 0 -#define STARTADLIBSOUNDS 100 -#define STARTDIGISOUNDS 200 -#define STARTMUSIC 300 +#define STARTADLIBSOUNDS 43 +#define STARTDIGISOUNDS 86 +#define STARTMUSIC 119 -#define LASTSOUND 100 +#define LASTSOUND 43 #define SONG1_MUS 0 #define ALLGOOD_MUS 1 diff --git a/src/cdogs/cwolfmap/wad/wad.c b/src/cdogs/cwolfmap/wad/wad.c index 33315429e..703c18214 100644 --- a/src/cdogs/cwolfmap/wad/wad.c +++ b/src/cdogs/cwolfmap/wad/wad.c @@ -147,7 +147,7 @@ static int WAD_ExpandBuffer(wad_t *wad, int newsize) { wad->handle.buffer = oldarray; return 1; - } + } if (oldarray) { @@ -859,7 +859,7 @@ static wadentry_t* wi_buffer_add_entry_at(wad_t *wad, const char *name, int inde unsigned char *dest = &(wad->handle.buffer[wad->buffer_size]); memcpy(dest, buffer, size); - wadentry_t* entry; + wadentry_t* entry; if (!(entry = WAD_AddEntryCommon(wad, name, size, wad->buffer_size, index))) { waderrno = WADERROR_OUT_OF_MEMORY; @@ -1068,7 +1068,7 @@ wad_t* WAD_Open(const char *filename) } out->type = WI_FILE; - out->handle.file = fp; + out->handle.file = fp; return out; } diff --git a/src/cdogs/map_wolf.c b/src/cdogs/map_wolf.c index 12f69f3d0..d7e063069 100644 --- a/src/cdogs/map_wolf.c +++ b/src/cdogs/map_wolf.c @@ -162,19 +162,18 @@ static const char *soundsSOD[] = { "chars/die/trans", "chars/alert/bill", "chars/die/bill", "chars/die/ubermutant", "chars/alert/knight", "chars/die/knight", "chars/alert/angel", "chars/die/angel", "chaingun_pickup", "spear"}; -// TODO: map unknown sounds static const char *soundsN3D[] = { // 0-9 - "chars/alert/antelope", "somesortofooohsound?", "bullet_pickup", "oooh?", - "door_close", "cantaloupe", "cantaloupe_feeder", "goat_kick", "gulp?", - "chars/die/animal", + "chars/alert/antelope", "chars/alert/bear", "bullet_pickup", + "chars/alert/camel", "door_close", "cantaloupe", "cantaloupe_feeder", + "goat_kick", "gulp?", "chars/die/animal", // 10-19 "chars/alert/elephant", "1up", "super_feeder", "chars/alert/giraffe", "chars/alert/goat", "small_feeder", "doof?", "chars/alert/kangaroo", "whistle", "hand_feed", // 20-29 - "chars/alert/monkey", "chars/alert/bear", "door", "chars/alert/ostrich", - "chars/alert/ox", "hurt", "dundundun?", "secret_door", "chars/alert/sheep", + "chars/alert/monkey", "footsteps/bear", "door", "chars/alert/ostrich", + "chars/alert/ox", "hurt", "hahaha", "secret_door", "chars/alert/sheep", "large_feeder", // 30-32 "spit", "watermelon", "watermelon_feeder"}; // TODO BS6: @@ -454,7 +453,7 @@ static const char *GetAdlibSound(const CWMapType type, const int i) case CWMAPTYPE_SOD: return adlibSoundsSOD[i]; case CWMAPTYPE_N3D: - // N3D has no adlib sounds + // Not using any adlib sounds return NULL; default: CASSERT(false, "unknown map type"); @@ -470,19 +469,23 @@ static const CWSongType songsCampaign[] = { SONG_ROSTER, // lose SONG_VICTORY, // victory }; -static Mix_Chunk *LoadMusic(CWolfMap *map, const int i) +static bool LoadMusic(CWolfMap *map, MusicChunk *chunk, const int i) { char *data; size_t len; const int err = CWAudioGetMusic(&map->audio, map->type, i, &data, &len); if (err != 0) { - goto bail; + return false; } - return Mix_QuickLoad_RAW((Uint8 *)data, (Uint32)len); - -bail: - return NULL; + if (map->type == CWMAPTYPE_N3D) + { + SDL_RWops *rwops = SDL_RWFromMem(data, (int)len); + chunk->u.Music = Mix_LoadMUS_RW(rwops, 1); + return true; + } + chunk->u.Chunk = Mix_QuickLoad_RAW((Uint8 *)data, (Uint32)len); + return false; } static bool IsDefaultMap(const char *filename) @@ -638,11 +641,12 @@ typedef struct CWolfMap *Map; MusicType Type; } CampaignSongData; -static Mix_Chunk *GetCampaignSong(void *data) +static bool GetCampaignSong(MusicChunk *chunk, void *data) { CampaignSongData *csd = data; const int songIndex = songsCampaign[csd->Type]; - return LoadMusic(csd->Map, CWAudioGetSong(csd->Map->type, songIndex)); + return LoadMusic( + csd->Map, chunk, CWAudioGetSong(csd->Map->type, songIndex)); } int MapWolfLoad( const char *filename, const int spearMission, CampaignSetting *c) @@ -676,7 +680,8 @@ int MapWolfLoad( csd->Type = i; c->CustomSongs[i].Data = csd; c->CustomSongs[i].GetData = GetCampaignSong; - c->CustomSongs[i].Chunk = NULL; + c->CustomSongs[i].isMusic = false; + c->CustomSongs[i].u.Chunk = NULL; } char buf[CDOGS_PATH_MAX]; @@ -914,11 +919,12 @@ typedef struct CWolfMap *Map; int MissionIndex; } MissionSongData; -static Mix_Chunk *GetMissionSong(void *data) +static bool GetMissionSong(MusicChunk *chunk, void *data) { MissionSongData *msd = data; return LoadMusic( - msd->Map, CWAudioGetLevelMusic(msd->Map->type, msd->MissionIndex)); + msd->Map, chunk, + CWAudioGetLevelMusic(msd->Map->type, msd->MissionIndex)); } static void LoadMission( CampaignSetting *c, const map_t tileClasses, CWolfMap *map, @@ -965,7 +971,8 @@ static void LoadMission( msd->MissionIndex = missionIndex; m.Music.Data.Chunk.Data = msd; m.Music.Data.Chunk.GetData = GetMissionSong; - m.Music.Data.Chunk.Chunk = NULL; + m.Music.Data.Chunk.isMusic = false; + m.Music.Data.Chunk.u.Chunk = NULL; MissionStaticInit(&m.u.Static); diff --git a/src/cdogs/music.c b/src/cdogs/music.c index de65361a5..e32580fb7 100644 --- a/src/cdogs/music.c +++ b/src/cdogs/music.c @@ -2,7 +2,7 @@ C-Dogs SDL A port of the legendary (and fun) action/arcade cdogs. - Copyright (c) 2013-2016, 2019, 2021 Cong Xu + Copyright (c) 2013-2016, 2019, 2021, 2024 Cong Xu All rights reserved. Redistribution and use in source and binary forms, with or without @@ -204,18 +204,25 @@ void MusicPlayFile( MusicPlayGeneral(mp, type); } } -void MusicPlayChunk(MusicPlayer *mp, const MusicType type, Mix_Chunk *chunk) +void MusicPlayChunk(MusicPlayer *mp, const MusicType type, MusicChunk *chunk) { MusicStop(mp); - bool played = false; if (chunk != NULL) { - mp->type = MUSIC_SRC_CHUNK; - mp->u.chunk.chunk = chunk; - mp->u.chunk.channel = Mix_PlayChannel(-1, chunk, -1); - played = true; + if (chunk->isMusic) + { + mp->type = MUSIC_SRC_DYNAMIC; + mp->u.dynamic = chunk->u.Music; + PlayMusic(mp); + } + else + { + mp->type = MUSIC_SRC_CHUNK; + mp->u.chunk.chunk = chunk->u.Chunk; + mp->u.chunk.channel = Mix_PlayChannel(-1, chunk->u.Chunk, -1); + } } - if (!played) + else { MusicPlayGeneral(mp, type); } @@ -262,7 +269,6 @@ void MusicPause(MusicPlayer *mp) Mix_Pause(mp->u.chunk.channel); break; } - } void MusicResume(MusicPlayer *mp) @@ -322,9 +328,9 @@ const char *MusicGetErrorMessage(const MusicPlayer *mp) void MusicChunkTerminate(MusicChunk *chunk) { - if (chunk->Chunk) + if (!chunk->isMusic && chunk->u.Chunk) { - Mix_FreeChunk(chunk->Chunk); + Mix_FreeChunk(chunk->u.Chunk); } CFREE(chunk->Data); memset(chunk, 0, sizeof *chunk); @@ -333,13 +339,13 @@ void MusicChunkTerminate(MusicChunk *chunk) void MusicPlayFromChunk( MusicPlayer *mp, const MusicType type, MusicChunk *chunk) { - if (chunk->Chunk == NULL && chunk->GetData) + if ((chunk->isMusic ? chunk->u.Music == NULL : chunk->u.Chunk == NULL) && + chunk->GetData) { - chunk->Chunk = - chunk->GetData(chunk->Data); + chunk->isMusic = chunk->GetData(chunk, chunk->Data); CFREE(chunk->Data); chunk->Data = NULL; chunk->GetData = NULL; } - MusicPlayChunk(mp, type, chunk->Chunk); + MusicPlayChunk(mp, type, chunk); } diff --git a/src/cdogs/music.h b/src/cdogs/music.h index aebcc7bb5..f2f09a000 100644 --- a/src/cdogs/music.h +++ b/src/cdogs/music.h @@ -92,11 +92,15 @@ typedef struct char errorMessage[128]; } MusicPlayer; -typedef struct +typedef struct _MusicChunk { void *Data; - Mix_Chunk *(*GetData)(void *); - Mix_Chunk *Chunk; + bool (*GetData)(struct _MusicChunk *, void *); + bool isMusic; + union { + Mix_Chunk *Chunk; + Mix_Music *Music; + } u; } MusicChunk; void MusicPlayerInit(MusicPlayer *mp); @@ -106,7 +110,7 @@ void MusicPlayGeneral(MusicPlayer *mp, const MusicType type); void MusicPlayFile( MusicPlayer *mp, const MusicType type, const char *missionPath, const char *music); -void MusicPlayChunk(MusicPlayer *mp, const MusicType type, Mix_Chunk *chunk); +void MusicPlayChunk(MusicPlayer *mp, const MusicType type, MusicChunk *chunk); void MusicStop(MusicPlayer *mp); void MusicPause(MusicPlayer *mp); void MusicResume(MusicPlayer *mp);