mirror of
https://github.com/mwpenny/portal64-still-alive.git
synced 2024-10-20 10:37:37 -04:00
Work on checkpoint saving
This commit is contained in:
parent
cd22140bf1
commit
4e06edb345
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
79
src/scene/checkpoint.c
Normal 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
13
src/scene/checkpoint.h
Normal 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);
|
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __SCENE_SIGNALS_H__
|
||||
#define __SCENE_SIGNALS_H__
|
||||
|
||||
#define SIGNAL_BIN_COUNT(signalCount) (((signalCount) + 63) >> 6)
|
||||
|
||||
enum SignalOperatorType {
|
||||
SignalOperatorTypeAnd,
|
||||
SignalOperatorTypeOr,
|
||||
|
|
Loading…
Reference in a new issue