Finish up serialization

This commit is contained in:
James Lambert 2023-05-07 20:51:26 -06:00
parent e1014a3924
commit 6d5110aac3
9 changed files with 126 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -20,7 +20,7 @@
#define SCREEN_SHOT_SRAM(slotIndex) (((slotIndex) + 1) * SAVE_SLOT_SIZE + MAX_CHECKPOINT_SIZE + SRAM_START_ADDR) #define SCREEN_SHOT_SRAM(slotIndex) (((slotIndex) + 1) * SAVE_SLOT_SIZE + MAX_CHECKPOINT_SIZE + SRAM_START_ADDR)
#define SAVEFILE_HEADER 0xDEA0 #define SAVEFILE_HEADER 0xDEAD
// first save slot is always reserved for auto save // first save slot is always reserved for auto save
#define MAX_SAVE_SLOTS ((int)(SRAM_SIZE / SAVE_SLOT_SIZE) - 1) #define MAX_SAVE_SLOTS ((int)(SRAM_SIZE / SAVE_SLOT_SIZE) - 1)

View file

@ -270,12 +270,110 @@ void boxDropperDeserialize(struct Serializer* serializer, struct Scene* scene) {
} }
} }
void elevatorSerializeRW(struct Serializer* serializer, SerializeAction action, struct Scene* scene) {
for (int i = 0; i < scene->elevatorCount; ++i) {
action(serializer, &scene->elevators[i].flags, sizeof(short));
}
}
void pedestalSerialize(struct Serializer* serializer, SerializeAction action, struct Scene* scene) {
for (int i = 0; i < scene->pedestalCount; ++i) {
action(serializer, &scene->pedestals[i].flags, sizeof(short));
}
}
void pedestalDeserialize(struct Serializer* serializer, struct Scene* scene) {
for (int i = 0; i < scene->pedestalCount; ++i) {
serializeRead(serializer, &scene->pedestals[i].flags, sizeof(short));
if (scene->pedestals[i].flags & PedestalFlagsDown) {
pedestalSetDown(&scene->pedestals[i]);
}
}
}
void launcherSerialize(struct Serializer* serializer, SerializeAction action, struct Scene* scene) {
for (int i = 0; i < scene->ballLancherCount; ++i) {
struct BallLauncher* launcher = &scene->ballLaunchers[i];
action(serializer, &launcher->currentBall.targetSpeed, sizeof(float));
action(serializer, &launcher->currentBall.flags, sizeof(short));
if (!ballIsActive(&launcher->currentBall) || ballIsCaught(&launcher->currentBall)) {
continue;
}
action(serializer, &launcher->currentBall.rigidBody.transform.position, sizeof (struct Vector3));
action(serializer, &launcher->currentBall.rigidBody.velocity, sizeof (struct Vector3));
action(serializer, &launcher->rigidBody.currentRoom, sizeof(short));
action(serializer, &launcher->ballLifetime, sizeof(float));
}
}
void launcherDeserialize(struct Serializer* serializer, struct Scene* scene) {
for (int i = 0; i < scene->ballLancherCount; ++i) {
struct BallLauncher* launcher = &scene->ballLaunchers[i];
serializeRead(serializer, &launcher->currentBall.targetSpeed, sizeof(float));
serializeRead(serializer, &launcher->currentBall.flags, sizeof(short));
if (!ballIsActive(&launcher->currentBall) || ballIsCaught(&launcher->currentBall)) {
continue;
}
struct Vector3 position;
struct Vector3 velocity;
short currentRoom;
float lifetime;
serializeRead(serializer, &position, sizeof (struct Vector3));
serializeRead(serializer, &velocity, sizeof (struct Vector3));
serializeRead(serializer, &currentRoom, sizeof(short));
serializeRead(serializer, &lifetime, sizeof(float));
ballInit(&launcher->currentBall, &position, &velocity, currentRoom, lifetime);
}
}
void catcherSerialize(struct Serializer* serializer, SerializeAction action, struct Scene* scene) {
for (int i = 0; i < scene->ballCatcherCount; ++i) {
struct BallCatcher* catcher = &scene->ballCatchers[i];
short caughtIndex = -1;
for (int launcherIndex = 0; launcherIndex < scene->ballLancherCount; ++launcherIndex) {
if (&scene->ballLaunchers[i].currentBall == catcher->caughtBall) {
caughtIndex = launcherIndex;
break;
}
}
action(serializer, &caughtIndex, sizeof(short));
}
}
void catcherDeserialize(struct Serializer* serializer, struct Scene* scene) {
for (int i = 0; i < scene->ballCatcherCount; ++i) {
short caughtIndex;
serializeRead(serializer, &caughtIndex, sizeof(short));
if (caughtIndex == -1) {
continue;
}
struct BallCatcher* catcher = &scene->ballCatchers[i];
catcher->caughtBall = &scene->ballLaunchers[caughtIndex].currentBall;
}
}
void sceneSerialize(struct Serializer* serializer, SerializeAction action, struct Scene* scene) { void sceneSerialize(struct Serializer* serializer, SerializeAction action, struct Scene* scene) {
playerSerialize(serializer, action, &scene->player); playerSerialize(serializer, action, &scene->player);
sceneSerializePortals(serializer, action, scene); sceneSerializePortals(serializer, action, scene);
buttonsSerializeRW(serializer, action, scene->buttons, scene->buttonCount); buttonsSerializeRW(serializer, action, scene->buttons, scene->buttonCount);
decorSerialize(serializer, action, scene); decorSerialize(serializer, action, scene);
boxDropperSerialize(serializer, action, scene); boxDropperSerialize(serializer, action, scene);
elevatorSerializeRW(serializer, action, scene);
pedestalSerialize(serializer, action, scene);
launcherSerialize(serializer, action, scene);
catcherSerialize(serializer, action, scene);
} }
void sceneDeserialize(struct Serializer* serializer, struct Scene* scene) { void sceneDeserialize(struct Serializer* serializer, struct Scene* scene) {
@ -284,4 +382,12 @@ void sceneDeserialize(struct Serializer* serializer, struct Scene* scene) {
buttonsSerializeRW(serializer, serializeRead, scene->buttons, scene->buttonCount); buttonsSerializeRW(serializer, serializeRead, scene->buttons, scene->buttonCount);
decorDeserialize(serializer, scene); decorDeserialize(serializer, scene);
boxDropperDeserialize(serializer, scene); boxDropperDeserialize(serializer, scene);
elevatorSerializeRW(serializer, serializeRead, scene);
pedestalDeserialize(serializer, scene);
launcherDeserialize(serializer, scene);
catcherDeserialize(serializer, scene);
for (int i = 0; i < scene->doorCount; ++i) {
doorCheckForOpenState(&scene->doors[i]);
}
} }

View file

@ -37,6 +37,7 @@ struct DoorTypeDefinition gDoorTypeDefinitions[] = {
&props_door_01_model_gfx[0], &props_door_01_model_gfx[0],
&props_door_01_Armature_open_clip, &props_door_01_Armature_open_clip,
&props_door_01_Armature_close_clip, &props_door_01_Armature_close_clip,
&props_door_01_Armature_opened_clip,
DOOR_01_INDEX, DOOR_01_INDEX,
-1, -1,
1.0f, 1.0f,
@ -46,6 +47,7 @@ struct DoorTypeDefinition gDoorTypeDefinitions[] = {
&props_door_02_model_gfx[0], &props_door_02_model_gfx[0],
&props_door_02_Armature_open_clip, &props_door_02_Armature_open_clip,
&props_door_02_Armature_close_clip, &props_door_02_Armature_close_clip,
&props_door_02_Armature_opened_clip,
DOOR_02_INDEX, DOOR_02_INDEX,
PROPS_DOOR_02_DOOR_BONE, PROPS_DOOR_02_DOOR_BONE,
3.0f, 3.0f,
@ -154,3 +156,12 @@ void doorUpdate(struct Door* door) {
door->armature.pose[typeDefinition->colliderBoneIndex].position.y * (1.0f / SCENE_SCALE); door->armature.pose[typeDefinition->colliderBoneIndex].position.y * (1.0f / SCENE_SCALE);
} }
} }
void doorCheckForOpenState(struct Door* door) {
struct DoorTypeDefinition* typeDefinition = &gDoorTypeDefinitions[door->doorDefinition->doorType];
int signal = signalsRead(door->signalIndex);
if (signal) {
skAnimatorRunClip(&door->animator, typeDefinition->openedClip, 0.0f, 0);
}
}

View file

@ -17,6 +17,7 @@ struct DoorTypeDefinition {
Gfx* model; Gfx* model;
struct SKAnimationClip* openClip; struct SKAnimationClip* openClip;
struct SKAnimationClip* closeClip; struct SKAnimationClip* closeClip;
struct SKAnimationClip* openedClip;
short materialIndex; short materialIndex;
short colliderBoneIndex; short colliderBoneIndex;
float closeSpeed; float closeSpeed;
@ -37,5 +38,6 @@ struct Door {
void doorInit(struct Door* door, struct DoorDefinition* doorDefinition, struct World* world); void doorInit(struct Door* door, struct DoorDefinition* doorDefinition, struct World* world);
void doorUpdate(struct Door* door); void doorUpdate(struct Door* door);
void doorCheckForOpenState(struct Door* door);
#endif #endif

View file

@ -119,3 +119,7 @@ void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target) {
pedestal->pointAt = *target; pedestal->pointAt = *target;
pedestal->flags |= PedestalFlagsIsPointing; pedestal->flags |= PedestalFlagsIsPointing;
} }
void pedestalSetDown(struct Pedestal* pedestal) {
skAnimatorRunClip(&pedestal->animator, &pedestal_Armature_Hidden_clip, 0.0f, 0);
}

View file

@ -33,4 +33,6 @@ void pedestalUpdate(struct Pedestal* pedestal);
void pedestalHide(struct Pedestal* pedestal); void pedestalHide(struct Pedestal* pedestal);
void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target); void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target);
void pedestalSetDown(struct Pedestal* pedestal);
#endif #endif