Work on checkpoint saving

This commit is contained in:
James Lambert 2023-02-06 22:08:11 -07:00
parent cd22140bf1
commit 4e06edb345
6 changed files with 128 additions and 8 deletions

View file

@ -362,3 +362,20 @@ void cutscenesUpdate() {
}
}
}
void cutsceneSerialize(struct CutsceneRunner* runner, struct CutsceneSerialized* result) {
result->cutsceneIndex = runner->currentCutscene - gCurrentLevel->cutscenes;
result->currentStep = runner->currentStep;
struct CutsceneStep* step = &runner->currentCutscene->steps[runner->currentStep];
switch (step->type) {
case CutsceneStepTypePlaySound:
case CutsceneStepTypeStartSound:
result->state.playSound.soundId = SOUND_ID_NONE;
break;
default:
result->state = runner->state;
break;
}
}

View file

@ -4,16 +4,23 @@
#include <ultra64.h>
#include "level_definition.h"
union CutsceneStepState {
struct {
ALSndId soundId;
} playSound;
float delay;
};
struct CutsceneSerialized {
u16 cutsceneIndex;
u16 currentStep;
union CutsceneStepState state;
};
struct CutsceneRunner {
struct Cutscene* currentCutscene;
u16 currentStep;
union {
struct {
ALSndId soundId;
} playSound;
float delay;
} state;
union CutsceneStepState state;
struct CutsceneRunner* nextRunner;
};
@ -24,4 +31,6 @@ void cutsceneStop(struct Cutscene* cutscene);
int cutsceneIsRunning(struct Cutscene* cutscene);
void cutscenesUpdate();
void cutsceneSerialize(struct CutsceneRunner* runner, struct CutsceneSerialized* result);
#endif

79
src/scene/checkpoint.c Normal file
View file

@ -0,0 +1,79 @@
#include "checkpoint.h"
#include "../util/memory.h"
#include "../levels/cutscene_runner.h"
void* checkpointWrite(void* dst, int size, void* src) {
memCopy(dst, src, size);
return (char*)dst + size;
}
extern unsigned long long* gSignals;
extern unsigned long long* gDefaultSignals;
extern unsigned gSignalCount;
extern struct CutsceneRunner* gRunningCutscenes;
extern u64 gTriggeredCutscenes;
int checkpointCutsceneCount() {
struct CutsceneRunner* curr = gRunningCutscenes;
int result = 0;
while (curr) {
curr = curr->nextRunner;
++result;
}
return result;
}
int checkpointEstimateSize(struct Scene* scene) {
int result = 0;
int binCount = SIGNAL_BIN_COUNT(gSignalCount);
result += sizeof(unsigned long long) * binCount * 2;
result += sizeof(struct CutsceneSerialized) * checkpointCutsceneCount();
result += sizeof(gTriggeredCutscenes);
return result;
}
Checkpoint checkpointNew(struct Scene* scene) {
int size = checkpointEstimateSize(scene);
void* result = malloc(size);
void* curr = result;
int binCount = SIGNAL_BIN_COUNT(gSignalCount);
curr = checkpointWrite(curr, sizeof(unsigned long long) * binCount, gSignals);
curr = checkpointWrite(curr, sizeof(unsigned long long) * binCount, gDefaultSignals);
short cutsceneCount = (short)checkpointCutsceneCount();
curr = checkpointWrite(curr, sizeof(short), &cutsceneCount);
struct CutsceneRunner* currCutscene = gRunningCutscenes;
while (currCutscene) {
struct CutsceneSerialized cutscene;
cutsceneSerialize(currCutscene, &cutscene);
curr = checkpointWrite(curr, sizeof(struct CutsceneSerialized), &cutscene);
}
curr = checkpointWrite(curr, sizeof(struct PartialTransform), &scene->player.body.transform);
curr = checkpointWrite(curr, sizeof (gTriggeredCutscenes), &gTriggeredCutscenes);
return result;
}
void checkpointLoad(struct Scene* scene, Checkpoint checkpoint) {
}
void checkpointDelete(Checkpoint checkpoint) {
free(checkpoint);
}

13
src/scene/checkpoint.h Normal file
View file

@ -0,0 +1,13 @@
#include "scene.h"
typedef void* Checkpoint;
struct PartialTransform {
struct Vector3 position;
struct Quaternion rotation;
};
Checkpoint checkpointNew(struct Scene* scene);
void checkpointLoad(struct Scene* scene, Checkpoint checkpoint);
void checkpointDelete(Checkpoint checkpoint);

View file

@ -14,7 +14,7 @@ void signalsInit(unsigned signalCount) {
return;
}
int binCount = (signalCount + 63) >> 6;
int binCount = SIGNAL_BIN_COUNT(signalCount);
gSignals = malloc(sizeof(unsigned long long) * binCount);
gDefaultSignals = malloc(sizeof(unsigned long long) * binCount);
gSignalCount = signalCount;

View file

@ -1,6 +1,8 @@
#ifndef __SCENE_SIGNALS_H__
#define __SCENE_SIGNALS_H__
#define SIGNAL_BIN_COUNT(signalCount) (((signalCount) + 63) >> 6)
enum SignalOperatorType {
SignalOperatorTypeAnd,
SignalOperatorTypeOr,