From 46d2e4124e218be4feebd86861fc06c716cf511d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 7 Jun 2025 23:02:13 +1000 Subject: [PATCH] PS2: Fix max texture size being wrong --- src/Audio.h | 9 ++++++++- src/Graphics_NDS.c | 12 ++++++------ src/Graphics_PS2.c | 2 +- src/_AudioBase.h | 32 ++++++++++++++++++++------------ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/Audio.h b/src/Audio.h index 041fffcc9..c04dd3c0b 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -55,7 +55,7 @@ void Audio_PlayStepSound(cc_uint8 type); cc_bool AudioBackend_Init(void); void AudioBackend_Tick(void); void AudioBackend_Free(void); -void AudioBackend_LoadSounds(); +void AudioBackend_LoadSounds(void); #define AUDIO_USAGE_BUFFER 0x01 #define AUDIO_USAGE_STREAM 0x02 @@ -95,6 +95,13 @@ cc_result AudioPool_Play(struct AudioData* data); void AudioPool_Close(void); +/*########################################################################################################################* +*------------------------------------------------------Sound context------------------------------------------------------* +*#########################################################################################################################*/ +/* Plays the given audio sound sample */ +cc_result SoundContext_Play(struct AudioContext* ctx, struct AudioData* data); + + /*########################################################################################################################* *---------------------------------------------------------Sounds---------------------------------------------------------* *#########################################################################################################################*/ diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index ace687162..eea891cb9 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -308,7 +308,7 @@ void Gfx_DisableTextureOffset(void) { UpdateTextureMatrix(); } -static CC_INLINE int FindInPalette(cc_uint16* pal, int pal_size, cc_uint16 color) { +static CC_INLINE int FindInPalette(BitmapCol* pal, int pal_size, BitmapCol color) { if ((color >> 15) == 0) return 0; for (int i = 1; i < pal_size; i++) @@ -320,7 +320,7 @@ static CC_INLINE int FindInPalette(cc_uint16* pal, int pal_size, cc_uint16 color static CC_INLINE int CalcPalette(cc_uint16* palette, struct Bitmap* bmp, int rowWidth) { int width = bmp->width, height = bmp->height; - cc_uint16* row = bmp->scan0; + BitmapCol* row = bmp->scan0; int pal_count = 1; palette[0] = 0; // entry 0 is transparent colour @@ -329,7 +329,7 @@ static CC_INLINE int CalcPalette(cc_uint16* palette, struct Bitmap* bmp, int row { for (int x = 0; x < width; x++) { - cc_uint16 color = row[x]; + BitmapCol color = row[x]; int idx = FindInPalette(palette, pal_count, color); if (idx >= 0) continue; @@ -349,7 +349,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, tex->width = bmp->width; tex->height = bmp->height; - cc_uint16 palette[256]; + BitmapCol palette[256]; int pal_count = CalcPalette(palette, bmp, rowWidth); int tex_size, tex_fmt; @@ -374,7 +374,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, } int offset = tex->texBase * TEX_BLOCK_SIZE; - u16* addr = (u16*) ((u8*)VRAM_A + offset); + u16* addr = (u16*)((u8*)VRAM_A + offset); u16* tmp_u16[128]; // 256 bytes char* tmp = (char*)tmp_u16; @@ -382,7 +382,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, int stride; int width = bmp->width, height = bmp->height; - cc_uint16* row = bmp->scan0; + BitmapCol* row = bmp->scan0; if (tex_fmt == GL_RGB4) { stride = width >> 3; diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 84594282c..0f2ff815a 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -152,7 +152,7 @@ void Gfx_Create(void) { Gfx.MinTexHeight = 4; Gfx.MaxTexWidth = 1024; Gfx.MaxTexHeight = 1024; - Gfx.MaxTexSize = 512 * 512; + Gfx.MaxTexSize = 256 * 256; Gfx.Created = true; Gfx_RestoreState(); diff --git a/src/_AudioBase.h b/src/_AudioBase.h index 6b41efb70..dfe071eb6 100644 --- a/src/_AudioBase.h +++ b/src/_AudioBase.h @@ -108,6 +108,24 @@ void Audio_FreeChunks(struct AudioChunk* chunks, int numChunks) { void AudioBackend_LoadSounds(void) { Sounds_LoadDefault(); } #endif + +/*########################################################################################################################* +*------------------------------------------------------Sound context------------------------------------------------------* +*#########################################################################################################################*/ +#ifndef CC_BUILD_NOSOUNDS +cc_result SoundContext_Play(struct AudioContext* ctx, struct AudioData* data) { + cc_result res; + Audio_SetVolume(ctx, data->volume); + + if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res; + if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res; + if ((res = Audio_Play(ctx))) return res; + + return 0; +} +#endif + + /*########################################################################################################################* *---------------------------------------------------Audio context code----------------------------------------------------* *#########################################################################################################################*/ @@ -116,16 +134,6 @@ struct AudioContext music_ctx; static struct AudioContext context_pool[POOL_MAX_CONTEXTS]; #ifndef CC_BUILD_NOSOUNDS -static cc_result PlayAudio(struct AudioContext* ctx, struct AudioData* data) { - cc_result res; - Audio_SetVolume(ctx, data->volume); - - if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res; - if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res; - if ((res = Audio_Play(ctx))) return res; - return 0; -} - cc_result AudioPool_Play(struct AudioData* data) { struct AudioContext* ctx; int inUse, i; @@ -140,7 +148,7 @@ cc_result AudioPool_Play(struct AudioData* data) { if (inUse > 0) continue; if (!Audio_FastPlay(ctx, data)) continue; - return PlayAudio(ctx, data); + return SoundContext_Play(ctx, data); } /* Try again with all contexts, even if need to recreate one (expensive) */ @@ -151,7 +159,7 @@ cc_result AudioPool_Play(struct AudioData* data) { if (res) return res; if (inUse > 0) continue; - return PlayAudio(ctx, data); + return SoundContext_Play(ctx, data); } return 0; }