mirror of
https://github.com/HarbourMasters/Starship.git
synced 2025-02-09 03:37:49 +03:00
audio work
This commit is contained in:
parent
4ae2fc22c1
commit
11a148a047
@ -387,7 +387,7 @@ typedef enum {
|
|||||||
* @param drumPtr (s32) the ptr to the `Drum` struct
|
* @param drumPtr (s32) the ptr to the `Drum` struct
|
||||||
*/
|
*/
|
||||||
#define AUDIOCMD_GLOBAL_SET_DRUM_FONT(fontId, drumId, drumPtr) \
|
#define AUDIOCMD_GLOBAL_SET_DRUM_FONT(fontId, drumId, drumPtr) \
|
||||||
AudioThread_QueueCmdS32(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT, fontId, drumId, 0), drumPtr)
|
AudioThread_QueueCmdPtr(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_DRUM_FONT, fontId, drumId, 0), drumPtr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a soundeffect ptr within a soundfont
|
* Set a soundeffect ptr within a soundfont
|
||||||
@ -397,7 +397,7 @@ typedef enum {
|
|||||||
* @param soundEffectPtr (s32) the ptr to the `SoundEffect` struct
|
* @param soundEffectPtr (s32) the ptr to the `SoundEffect` struct
|
||||||
*/
|
*/
|
||||||
#define AUDIOCMD_GLOBAL_SET_SFX_FONT(fontId, soundEffectId, soundEffectPtr) \
|
#define AUDIOCMD_GLOBAL_SET_SFX_FONT(fontId, soundEffectId, soundEffectPtr) \
|
||||||
AudioThread_QueueCmdS32(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_SFX_FONT, fontId, soundEffectId, 0), soundEffectPtr)
|
AudioThread_QueueCmdPtr(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_SFX_FONT, fontId, soundEffectId, 0), soundEffectPtr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an instrument ptr within a soundfont
|
* Set an instrument ptr within a soundfont
|
||||||
@ -407,7 +407,7 @@ typedef enum {
|
|||||||
* @param instPtr (s32) the ptr to the `Instrument` struct
|
* @param instPtr (s32) the ptr to the `Instrument` struct
|
||||||
*/
|
*/
|
||||||
#define AUDIOCMD_GLOBAL_SET_INSTRUMENT_FONT(fontId, instId, instPtr) \
|
#define AUDIOCMD_GLOBAL_SET_INSTRUMENT_FONT(fontId, instId, instPtr) \
|
||||||
AudioThread_QueueCmdS32(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_INSTRUMENT_FONT, fontId, instId, 0), instPtr)
|
AudioThread_QueueCmdPtr(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_INSTRUMENT_FONT, fontId, instId, 0), instPtr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pop the persistent cache of the specified table
|
* Pop the persistent cache of the specified table
|
||||||
@ -507,7 +507,7 @@ typedef enum {
|
|||||||
* @param functionPtr (s32) address of the function to run once every audio frame
|
* @param functionPtr (s32) address of the function to run once every audio frame
|
||||||
*/
|
*/
|
||||||
#define AUDIOCMD_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION(functionPtr) \
|
#define AUDIOCMD_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION(functionPtr) \
|
||||||
AudioThread_QueueCmdS32(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION, 0, 0, 0), functionPtr)
|
AudioThread_QueueCmdPtr(AUDIO_MK_CMD(AUDIOCMD_OP_GLOBAL_SET_CUSTOM_UPDATE_FUNCTION, 0, 0, 0), functionPtr)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously load a sequence
|
* Asynchronously load a sequence
|
||||||
|
@ -776,18 +776,10 @@ typedef struct {
|
|||||||
void* data;
|
void* data;
|
||||||
f32 asFloat;
|
f32 asFloat;
|
||||||
s32 asInt;
|
s32 asInt;
|
||||||
struct {
|
uintptr_t asPtr;
|
||||||
u8 pad2[2];
|
|
||||||
u16 asUShort;
|
u16 asUShort;
|
||||||
};
|
|
||||||
struct {
|
|
||||||
u8 pad1[3];
|
|
||||||
s8 asSbyte;
|
s8 asSbyte;
|
||||||
};
|
|
||||||
struct {
|
|
||||||
u8 pad0[3];
|
|
||||||
u8 asUbyte;
|
u8 asUbyte;
|
||||||
};
|
|
||||||
u32 asUInt;
|
u32 asUInt;
|
||||||
};
|
};
|
||||||
} AudioCmd; // size = 0x8
|
} AudioCmd; // size = 0x8
|
||||||
@ -1034,10 +1026,10 @@ Acmd* AudioSynth_Update(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLe
|
|||||||
|
|
||||||
// audio_effects
|
// audio_effects
|
||||||
void Audio_SequencePlayerProcessSound(SequencePlayer* seqplayer);
|
void Audio_SequencePlayerProcessSound(SequencePlayer* seqplayer);
|
||||||
void func_80013A18(Note* note);
|
void Audio_NoteVibratoUpdate(Note* note);
|
||||||
void Audio_NoteVibratoInit(Note* note);
|
void Audio_NoteVibratoInit(Note* note);
|
||||||
void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2);
|
void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2);
|
||||||
f32 func_80013B90(AdsrState* adsr);
|
f32 Audio_AdsrUpdate(AdsrState* adsr);
|
||||||
|
|
||||||
// audio_heap
|
// audio_heap
|
||||||
void AudioHeap_DiscardFont(s32 fontId);
|
void AudioHeap_DiscardFont(s32 fontId);
|
||||||
|
@ -361,15 +361,15 @@ func_80012ED4 = 0x80012ED4;
|
|||||||
func_80012F24 = 0x80012F24;
|
func_80012F24 = 0x80012F24;
|
||||||
Audio_AllocNote = 0x8001301C;
|
Audio_AllocNote = 0x8001301C;
|
||||||
func_800132E8 = 0x800132E8;
|
func_800132E8 = 0x800132E8;
|
||||||
func_80013400 = 0x80013400;
|
Audio_SequenceChannelProcessSound = 0x80013400;
|
||||||
Audio_SequencePlayerProcessSound = 0x800135A8;
|
Audio_SequencePlayerProcessSound = 0x800135A8;
|
||||||
func_80013708 = 0x80013708;
|
Audio_GetPortamentoFreqScale = 0x80013708;
|
||||||
func_800137DC = 0x800137DC;
|
Audio_GetVibratoPitchChange = 0x800137DC;
|
||||||
func_80013820 = 0x80013820;
|
Audio_GetVibratoFreqScale = 0x80013820;
|
||||||
func_80013A18 = 0x80013A18;
|
Audio_NoteVibratoUpdate = 0x80013A18;
|
||||||
Audio_NoteVibratoInit = 0x80013A84;
|
Audio_NoteVibratoInit = 0x80013A84;
|
||||||
func_80013B6C = 0x80013B6C;
|
Audio_AdsrInit = 0x80013B6C;
|
||||||
func_80013B90 = 0x80013B90;
|
Audio_AdsrUpdate = 0x80013B90;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,10 +209,10 @@ AudioSpec gAudioSpecs[] = {
|
|||||||
/* 21 */
|
/* 21 */
|
||||||
{ 32000, 2, 32, ARRAY_COUNT(D_800C7628), D_800C7628, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
|
{ 32000, 2, 32, ARRAY_COUNT(D_800C7628), D_800C7628, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
|
||||||
0x00000 },
|
0x00000 },
|
||||||
/* 22 */
|
/* 22 TITLE */
|
||||||
{ 32000, 1, 32, ARRAY_COUNT(D_800C7638), D_800C7638, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
|
{ 32000, 1, 32, ARRAY_COUNT(D_800C7638), D_800C7638, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
|
||||||
0x00000 },
|
0x00000 },
|
||||||
/* 23 */
|
/* 23 OPTION */
|
||||||
{ 32000, 1, 32, ARRAY_COUNT(D_800C7648), D_800C7648, 0x7FFF, 0x1200, 0xA000, 0, 0x5B00, 0x1D00, 0, 0x00000,
|
{ 32000, 1, 32, ARRAY_COUNT(D_800C7648), D_800C7648, 0x7FFF, 0x1200, 0xA000, 0, 0x5B00, 0x1D00, 0, 0x00000,
|
||||||
0x00000 },
|
0x00000 },
|
||||||
/* 24 */
|
/* 24 */
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
static const char devstr[] = "Audio:Envp: overflow %f\n";
|
static const char devstr[] = "Audio:Envp: overflow %f\n";
|
||||||
|
|
||||||
void func_80013400(SequenceChannel* channel, s32 updateVolume) {
|
void Audio_SequenceChannelProcessSound(SequenceChannel* channel, s32 updateVolume) {
|
||||||
s32 i;
|
s32 i;
|
||||||
|
|
||||||
if (channel->changes.s.volume || updateVolume) {
|
if (channel->changes.s.volume || updateVolume) {
|
||||||
f32 channelVolume = channel->volume * channel->volumeMod * channel->seqPlayer->appliedFadeVolume;
|
f32 channelVolume = channel->volume * channel->volumeMod * channel->seqPlayer->appliedFadeVolume;
|
||||||
|
|
||||||
if (channel->seqPlayer->muted && (channel->muteBehavior & 0x20)) {
|
if (channel->seqPlayer->muted && (channel->muteBehavior & MUTE_BEHAVIOR_SOFTEN)) {
|
||||||
channelVolume = channel->seqPlayer->muteVolumeMod * channelVolume;
|
channelVolume = channel->seqPlayer->muteVolumeMod * channelVolume;
|
||||||
}
|
}
|
||||||
channel->appliedVolume = SQ(channelVolume);
|
channel->appliedVolume = SQ(channelVolume);
|
||||||
@ -66,13 +66,13 @@ void Audio_SequencePlayerProcessSound(SequencePlayer* seqplayer) {
|
|||||||
}
|
}
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
if ((IS_SEQUENCE_CHANNEL_VALID(seqplayer->channels[i]) == 1) && (seqplayer->channels[i]->enabled == 1)) {
|
if ((IS_SEQUENCE_CHANNEL_VALID(seqplayer->channels[i]) == 1) && (seqplayer->channels[i]->enabled == 1)) {
|
||||||
func_80013400(seqplayer->channels[i], seqplayer->recalculateVolume);
|
Audio_SequenceChannelProcessSound(seqplayer->channels[i], seqplayer->recalculateVolume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
seqplayer->recalculateVolume = false;
|
seqplayer->recalculateVolume = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 func_80013708(Portamento* portamento) {
|
f32 Audio_GetPortamentoFreqScale(Portamento* portamento) {
|
||||||
u32 temp;
|
u32 temp;
|
||||||
f32 temp2;
|
f32 temp2;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ f32 func_80013708(Portamento* portamento) {
|
|||||||
return temp2;
|
return temp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 func_800137DC(VibratoState* vibrato) {
|
s16 Audio_GetVibratoPitchChange(VibratoState* vibrato) {
|
||||||
s32 index;
|
s32 index;
|
||||||
|
|
||||||
vibrato->time += (s32) vibrato->rate;
|
vibrato->time += (s32) vibrato->rate;
|
||||||
@ -93,7 +93,7 @@ s16 func_800137DC(VibratoState* vibrato) {
|
|||||||
return vibrato->curve[index] >> 8;
|
return vibrato->curve[index] >> 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 func_80013820(VibratoState* vibrato) {
|
f32 Audio_GetVibratoFreqScale(VibratoState* vibrato) {
|
||||||
s32 ret;
|
s32 ret;
|
||||||
f32 temp;
|
f32 temp;
|
||||||
f32 temp2;
|
f32 temp2;
|
||||||
@ -131,18 +131,18 @@ f32 func_80013820(VibratoState* vibrato) {
|
|||||||
if (vibrato->depth == 0.0f) {
|
if (vibrato->depth == 0.0f) {
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
ret = func_800137DC(vibrato);
|
ret = Audio_GetVibratoPitchChange(vibrato);
|
||||||
temp = vibrato->depth / 4096.0f;
|
temp = vibrato->depth / 4096.0f;
|
||||||
temp2 = 1.0f + temp * (gBendPitchOneOctaveFrequencies[0x80 + ret] - 1.0f);
|
temp2 = 1.0f + temp * (gBendPitchOneOctaveFrequencies[0x80 + ret] - 1.0f);
|
||||||
return temp2;
|
return temp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void func_80013A18(Note* note) {
|
void Audio_NoteVibratoUpdate(Note* note) {
|
||||||
if (note->playbackState.portamento.mode != 0) {
|
if (note->playbackState.portamento.mode != 0) {
|
||||||
note->playbackState.portamentoFreqMod = func_80013708(¬e->playbackState.portamento);
|
note->playbackState.portamentoFreqMod = Audio_GetPortamentoFreqScale(¬e->playbackState.portamento);
|
||||||
}
|
}
|
||||||
if ((note->playbackState.vibratoState.active != 0) && (note->playbackState.parentLayer != NO_LAYER)) {
|
if ((note->playbackState.vibratoState.active != 0) && (note->playbackState.parentLayer != NO_LAYER)) {
|
||||||
note->playbackState.vibratoFreqMod = func_80013820(¬e->playbackState.vibratoState);
|
note->playbackState.vibratoFreqMod = Audio_GetVibratoFreqScale(¬e->playbackState.vibratoState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ void Audio_NoteVibratoInit(Note* note) {
|
|||||||
noteState->portamento = noteState->parentLayer->portamento;
|
noteState->portamento = noteState->parentLayer->portamento;
|
||||||
}
|
}
|
||||||
|
|
||||||
void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) {
|
void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) {
|
||||||
adsr->action.asByte = 0;
|
adsr->action.asByte = 0;
|
||||||
adsr->state = 0;
|
adsr->state = 0;
|
||||||
adsr->delay = 0;
|
adsr->delay = 0;
|
||||||
@ -183,7 +183,7 @@ void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) {
|
|||||||
adsr->current = 0.0f;
|
adsr->current = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 func_80013B90(AdsrState* adsr) {
|
f32 Audio_AdsrUpdate(AdsrState* adsr) {
|
||||||
u8 action = adsr->action.asByte;
|
u8 action = adsr->action.asByte;
|
||||||
u8 state = adsr->state;
|
u8 state = adsr->state;
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ f32 func_80013B90(AdsrState* adsr) {
|
|||||||
adsr->state = ADSR_STATE_LOOP;
|
adsr->state = ADSR_STATE_LOOP;
|
||||||
case_ADSR_STATE_LOOP:
|
case_ADSR_STATE_LOOP:
|
||||||
case ADSR_STATE_LOOP:
|
case ADSR_STATE_LOOP:
|
||||||
adsr->delay = BSWAP16(adsr->envelope[adsr->envIndex].delay);
|
adsr->delay = (s16)BSWAP16(adsr->envelope[adsr->envIndex].delay);
|
||||||
switch (adsr->delay) {
|
switch (adsr->delay) {
|
||||||
case ADSR_DISABLE:
|
case ADSR_DISABLE:
|
||||||
adsr->state = ADSR_STATE_DISABLED;
|
adsr->state = ADSR_STATE_DISABLED;
|
||||||
@ -209,7 +209,7 @@ f32 func_80013B90(AdsrState* adsr) {
|
|||||||
adsr->state = ADSR_STATE_HANG;
|
adsr->state = ADSR_STATE_HANG;
|
||||||
break;
|
break;
|
||||||
case ADSR_GOTO:
|
case ADSR_GOTO:
|
||||||
adsr->envIndex = BSWAP16(adsr->envelope[adsr->envIndex].arg);
|
adsr->envIndex = (s16)BSWAP16(adsr->envelope[adsr->envIndex].arg);
|
||||||
goto case_ADSR_STATE_LOOP;
|
goto case_ADSR_STATE_LOOP;
|
||||||
case ADSR_RESTART:
|
case ADSR_RESTART:
|
||||||
adsr->state = ADSR_STATE_INITIAL;
|
adsr->state = ADSR_STATE_INITIAL;
|
||||||
|
@ -218,10 +218,10 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
|
|||||||
|
|
||||||
void func_80011EB8(Note* note) {
|
void func_80011EB8(Note* note) {
|
||||||
if (note->playbackState.parentLayer->adsr.decayIndex == 0) {
|
if (note->playbackState.parentLayer->adsr.decayIndex == 0) {
|
||||||
func_80013B6C(¬e->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope,
|
Audio_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope,
|
||||||
¬e->playbackState.adsrVolModUnused);
|
¬e->playbackState.adsrVolModUnused);
|
||||||
} else {
|
} else {
|
||||||
func_80013B6C(¬e->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope,
|
Audio_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope,
|
||||||
¬e->playbackState.adsrVolModUnused);
|
¬e->playbackState.adsrVolModUnused);
|
||||||
}
|
}
|
||||||
note->playbackState.adsr.state = 1;
|
note->playbackState.adsr.state = 1;
|
||||||
@ -323,8 +323,8 @@ void Audio_ProcessNotes(void) {
|
|||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_fs0 = func_80013B90(&playbackState->adsr);
|
temp_fs0 = Audio_AdsrUpdate(&playbackState->adsr);
|
||||||
func_80013A18(note);
|
Audio_NoteVibratoUpdate(note);
|
||||||
attr = &playbackState->attributes;
|
attr = &playbackState->attributes;
|
||||||
if ((playbackState->unk_04 == 1) || (playbackState->unk_04 == 2)) {
|
if ((playbackState->unk_04 == 1) || (playbackState->unk_04 == 2)) {
|
||||||
sp70.freqMod = attr->freqMod;
|
sp70.freqMod = attr->freqMod;
|
||||||
|
@ -1243,7 +1243,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) {
|
|||||||
s32 pad3;
|
s32 pad3;
|
||||||
|
|
||||||
// @port:
|
// @port:
|
||||||
gSeqLoadStatus[seqPlayer->seqId] = 2;
|
gSeqLoadStatus[seqPlayer->seqId] = LOAD_STATUS_COMPLETE;
|
||||||
|
|
||||||
if (!seqPlayer->enabled) {
|
if (!seqPlayer->enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -317,6 +317,14 @@ void AudioThread_QueueCmd(AudioCmd cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioThread_QueueCmdPtr(u32 opArgs, void* data) {
|
||||||
|
AudioCmd cmd = {
|
||||||
|
.opArgs = opArgs,
|
||||||
|
.asPtr = data,
|
||||||
|
};
|
||||||
|
AudioThread_QueueCmd(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void AudioThread_QueueCmdF32(u32 opArgs, f32 val) {
|
void AudioThread_QueueCmdF32(u32 opArgs, f32 val) {
|
||||||
AudioCmd cmd = { .opArgs = opArgs, .asFloat = val };
|
AudioCmd cmd = { .opArgs = opArgs, .asFloat = val };
|
||||||
AudioThread_QueueCmd(cmd);
|
AudioThread_QueueCmd(cmd);
|
||||||
|
@ -357,6 +357,7 @@ void Game_SetScene(void) {
|
|||||||
extern u8 gAudioSpecId;
|
extern u8 gAudioSpecId;
|
||||||
extern int audBuffer;
|
extern int audBuffer;
|
||||||
extern AudioBufferParameters gAudioBufferParams;
|
extern AudioBufferParameters gAudioBufferParams;
|
||||||
|
extern int countermin;
|
||||||
void Game_Update(void) {
|
void Game_Update(void) {
|
||||||
s32 i;
|
s32 i;
|
||||||
u8 partialFill;
|
u8 partialFill;
|
||||||
@ -625,6 +626,8 @@ void Game_Update(void) {
|
|||||||
}
|
}
|
||||||
RCP_SetupDL(&gMasterDisp, SETUPDL_83);
|
RCP_SetupDL(&gMasterDisp, SETUPDL_83);
|
||||||
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
|
gDPSetPrimColor(gMasterDisp++, 0, 0, 255, 255, 0, 255);
|
||||||
|
Graphics_DisplaySmallText(10, 190, 1.0f, 1.0f, "SEC:");
|
||||||
|
Graphics_DisplaySmallNumber(90, 190, countermin);
|
||||||
Graphics_DisplaySmallText(10, 200, 1.0f, 1.0f, "AUDIOBUF:");
|
Graphics_DisplaySmallText(10, 200, 1.0f, 1.0f, "AUDIOBUF:");
|
||||||
Graphics_DisplaySmallNumber(90, 200, audBuffer);
|
Graphics_DisplaySmallNumber(90, 200, audBuffer);
|
||||||
Graphics_DisplaySmallText(10, 210, 1.0f, 1.0f, "AUDIOSPEC:");
|
Graphics_DisplaySmallText(10, 210, 1.0f, 1.0f, "AUDIOSPEC:");
|
||||||
|
@ -41,22 +41,20 @@ void AudioThread_CreateNextAudioBuffer(int16_t *samples, uint32_t num_samples);
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameEngine* GameEngine::Instance;
|
GameEngine* GameEngine::Instance;
|
||||||
static GamePool MemoryPool = {
|
static GamePool MemoryPool = { .chunk = 1024 * 512, .cursor = 0, .length = 0, .memory = nullptr };
|
||||||
.chunk = 1024 * 512,
|
|
||||||
.cursor = 0,
|
|
||||||
.length = 0,
|
|
||||||
.memory = nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
GameEngine::GameEngine() {
|
GameEngine::GameEngine() {
|
||||||
std::vector<std::string> OTRFiles;
|
std::vector<std::string> OTRFiles;
|
||||||
if (const std::string cube_path = Ship::Context::GetPathRelativeToAppDirectory("starship.otr"); std::filesystem::exists(cube_path)) {
|
if (const std::string cube_path = Ship::Context::GetPathRelativeToAppDirectory("starship.otr");
|
||||||
|
std::filesystem::exists(cube_path)) {
|
||||||
OTRFiles.push_back(cube_path);
|
OTRFiles.push_back(cube_path);
|
||||||
}
|
}
|
||||||
if (const std::string sm64_otr_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.otr"); std::filesystem::exists(sm64_otr_path)) {
|
if (const std::string sm64_otr_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.otr");
|
||||||
|
std::filesystem::exists(sm64_otr_path)) {
|
||||||
OTRFiles.push_back(sm64_otr_path);
|
OTRFiles.push_back(sm64_otr_path);
|
||||||
}
|
}
|
||||||
if (const std::string patches_path = Ship::Context::GetPathRelativeToAppDirectory("mods"); !patches_path.empty() && std::filesystem::exists(patches_path)) {
|
if (const std::string patches_path = Ship::Context::GetPathRelativeToAppDirectory("mods");
|
||||||
|
!patches_path.empty() && std::filesystem::exists(patches_path)) {
|
||||||
if (std::filesystem::is_directory(patches_path)) {
|
if (std::filesystem::is_directory(patches_path)) {
|
||||||
for (const auto& p : std::filesystem::recursive_directory_iterator(patches_path)) {
|
for (const auto& p : std::filesystem::recursive_directory_iterator(patches_path)) {
|
||||||
if (StringHelper::IEquals(p.path().extension().string(), ".otr")) {
|
if (StringHelper::IEquals(p.path().extension().string(), ".otr")) {
|
||||||
@ -66,29 +64,53 @@ GameEngine::GameEngine() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->context = Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 32000, 1024, 2480 });
|
this->context =
|
||||||
|
Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 32000, 1024, 2480 });
|
||||||
|
|
||||||
auto loader = context->GetResourceManager()->GetResourceLoader();
|
auto loader = context->GetResourceManager()->GetResourceLoader();
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAnimV0>(), RESOURCE_FORMAT_BINARY, "Animation", static_cast<uint32_t>(SF64::ResourceType::AnimData), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAnimV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinarySkeletonV0>(), RESOURCE_FORMAT_BINARY, "Skeleton", static_cast<uint32_t>(SF64::ResourceType::Skeleton), 0);
|
"Animation", static_cast<uint32_t>(SF64::ResourceType::AnimData), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryLimbV0>(), RESOURCE_FORMAT_BINARY, "Limb", static_cast<uint32_t>(SF64::ResourceType::Limb), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinarySkeletonV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageV0>(), RESOURCE_FORMAT_BINARY, "Message", static_cast<uint32_t>(SF64::ResourceType::Message), 0);
|
"Skeleton", static_cast<uint32_t>(SF64::ResourceType::Skeleton), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageLookupV0>(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast<uint32_t>(SF64::ResourceType::MessageTable), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryLimbV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryEnvSettingsV0>(), RESOURCE_FORMAT_BINARY, "EnvSettings", static_cast<uint32_t>(SF64::ResourceType::Environment), 0);
|
"Limb", static_cast<uint32_t>(SF64::ResourceType::Limb), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryObjectInitV0>(), RESOURCE_FORMAT_BINARY, "ObjectInit", static_cast<uint32_t>(SF64::ResourceType::ObjectInit), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryHitboxV0>(), RESOURCE_FORMAT_BINARY, "Hitbox", static_cast<uint32_t>(SF64::ResourceType::Hitbox), 0);
|
"Message", static_cast<uint32_t>(SF64::ResourceType::Message), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptV0>(), RESOURCE_FORMAT_BINARY, "Script", static_cast<uint32_t>(SF64::ResourceType::Script), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryMessageLookupV0>(),
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptCMDV0>(), RESOURCE_FORMAT_BINARY, "ScriptCMD", static_cast<uint32_t>(SF64::ResourceType::ScriptCmd), 0);
|
RESOURCE_FORMAT_BINARY, "MessageTable",
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryColPolyV0>(), RESOURCE_FORMAT_BINARY, "ColPoly", static_cast<uint32_t>(SF64::ResourceType::ColPoly), 0);
|
static_cast<uint32_t>(SF64::ResourceType::MessageTable), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3fV0>(), RESOURCE_FORMAT_BINARY, "Vec3f", static_cast<uint32_t>(SF64::ResourceType::Vec3f), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryEnvSettingsV0>(),
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3sV0>(), RESOURCE_FORMAT_BINARY, "Vec3s", static_cast<uint32_t>(SF64::ResourceType::Vec3s), 0);
|
RESOURCE_FORMAT_BINARY, "EnvSettings",
|
||||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryGenericArrayV0>(), RESOURCE_FORMAT_BINARY, "GenericArray", static_cast<uint32_t>(SF64::ResourceType::GenericArray), 0);
|
static_cast<uint32_t>(SF64::ResourceType::Environment), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY, "Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryObjectInitV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY, "Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 1);
|
"ObjectInit", static_cast<uint32_t>(SF64::ResourceType::ObjectInit), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryVertexV0>(), RESOURCE_FORMAT_BINARY, "Vertex", static_cast<uint32_t>(LUS::ResourceType::Vertex), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryHitboxV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryDisplayListV0>(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast<uint32_t>(LUS::ResourceType::DisplayList), 0);
|
"Hitbox", static_cast<uint32_t>(SF64::ResourceType::Hitbox), 0);
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryMatrixV0>(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast<uint32_t>(LUS::ResourceType::Matrix), 0);
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY, "Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0);
|
"Script", static_cast<uint32_t>(SF64::ResourceType::Script), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptCMDV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"ScriptCMD", static_cast<uint32_t>(SF64::ResourceType::ScriptCmd), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryColPolyV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"ColPoly", static_cast<uint32_t>(SF64::ResourceType::ColPoly), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3fV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Vec3f", static_cast<uint32_t>(SF64::ResourceType::Vec3f), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3sV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Vec3s", static_cast<uint32_t>(SF64::ResourceType::Vec3s), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryGenericArrayV0>(),
|
||||||
|
RESOURCE_FORMAT_BINARY, "GenericArray",
|
||||||
|
static_cast<uint32_t>(SF64::ResourceType::GenericArray), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Texture", static_cast<uint32_t>(LUS::ResourceType::Texture), 1);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryVertexV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Vertex", static_cast<uint32_t>(LUS::ResourceType::Vertex), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryDisplayListV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"DisplayList", static_cast<uint32_t>(LUS::ResourceType::DisplayList), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryMatrixV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Matrix", static_cast<uint32_t>(LUS::ResourceType::Matrix), 0);
|
||||||
|
loader->RegisterResourceFactory(std::make_shared<LUS::ResourceFactoryBinaryBlobV0>(), RESOURCE_FORMAT_BINARY,
|
||||||
|
"Blob", static_cast<uint32_t>(LUS::ResourceType::Blob), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEngine::Create() {
|
void GameEngine::Create() {
|
||||||
@ -118,7 +140,8 @@ void GameEngine::StartFrame() const{
|
|||||||
ShouldClearTextureCacheAtEndOfFrame = true;
|
ShouldClearTextureCacheAtEndOfFrame = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
this->context->GetWindow()->StartFrame();
|
this->context->GetWindow()->StartFrame();
|
||||||
}
|
}
|
||||||
@ -134,7 +157,8 @@ extern "C" s32 audBuffer = 0;
|
|||||||
#include <sf64audio_provisional.h>
|
#include <sf64audio_provisional.h>
|
||||||
|
|
||||||
extern "C" volatile s32 gAudioTaskCountQ;
|
extern "C" volatile s32 gAudioTaskCountQ;
|
||||||
|
int frames = 0;
|
||||||
|
extern "C" int countermin = 0;
|
||||||
void GameEngine::HandleAudioThread() {
|
void GameEngine::HandleAudioThread() {
|
||||||
while (audio.running) {
|
while (audio.running) {
|
||||||
{
|
{
|
||||||
@ -153,11 +177,19 @@ void GameEngine::HandleAudioThread() {
|
|||||||
int samples_left = AudioPlayerBuffered();
|
int samples_left = AudioPlayerBuffered();
|
||||||
u32 num_audio_samples = samples_left < AudioPlayerGetDesiredBuffered() ? 560 : 528;
|
u32 num_audio_samples = samples_left < AudioPlayerGetDesiredBuffered() ? 560 : 528;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
frames++;
|
||||||
AudioThread_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples);
|
|
||||||
|
if (frames > 60) {
|
||||||
|
countermin++;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioPlayerPlayFrame((u8 *) audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
|
for (int i = 0; i < 2; i++) {
|
||||||
|
AudioThread_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS),
|
||||||
|
num_audio_samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioPlayerPlayFrame((u8*) audio_buffer,
|
||||||
|
num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
|
||||||
audio.processing = false;
|
audio.processing = false;
|
||||||
audio.cv_from_thread.notify_one();
|
audio.cv_from_thread.notify_one();
|
||||||
}
|
}
|
||||||
@ -343,7 +375,6 @@ struct TimedEntry {
|
|||||||
|
|
||||||
std::vector<TimedEntry> gTimerTasks;
|
std::vector<TimedEntry> gTimerTasks;
|
||||||
|
|
||||||
|
|
||||||
uint64_t Timer_GetCurrentMillis() {
|
uint64_t Timer_GetCurrentMillis() {
|
||||||
return SDL_GetTicks();
|
return SDL_GetTicks();
|
||||||
}
|
}
|
||||||
@ -470,7 +501,8 @@ extern "C" void* GameEngine_Malloc(size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MemoryPool.length += chunk;
|
MemoryPool.length += chunk;
|
||||||
MemoryPool.memory = MemoryPool.memory == nullptr ? malloc(MemoryPool.length) : realloc(MemoryPool.memory, MemoryPool.length);
|
MemoryPool.memory =
|
||||||
|
MemoryPool.memory == nullptr ? malloc(MemoryPool.length) : realloc(MemoryPool.memory, MemoryPool.length);
|
||||||
memset(static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.length, 0, MemoryPool.length - chunk);
|
memset(static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.length, 0, MemoryPool.length - chunk);
|
||||||
SPDLOG_INFO("Memory pool resized from {} to {}", MemoryPool.length - chunk, MemoryPool.length);
|
SPDLOG_INFO("Memory pool resized from {} to {}", MemoryPool.length - chunk, MemoryPool.length);
|
||||||
return GameEngine_Malloc(size);
|
return GameEngine_Malloc(size);
|
||||||
|
Loading…
Reference in New Issue
Block a user