mirror of
https://github.com/mwpenny/portal64-still-alive.git
synced 2024-10-19 22:27:36 -04:00
Finish up serialization
This commit is contained in:
parent
e1014a3924
commit
6d5110aac3
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -20,7 +20,7 @@
|
|||
|
||||
#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
|
||||
#define MAX_SAVE_SLOTS ((int)(SRAM_SIZE / SAVE_SLOT_SIZE) - 1)
|
||||
|
|
|
@ -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, ¤tRoom, 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) {
|
||||
playerSerialize(serializer, action, &scene->player);
|
||||
sceneSerializePortals(serializer, action, scene);
|
||||
buttonsSerializeRW(serializer, action, scene->buttons, scene->buttonCount);
|
||||
decorSerialize(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) {
|
||||
|
@ -284,4 +382,12 @@ void sceneDeserialize(struct Serializer* serializer, struct Scene* scene) {
|
|||
buttonsSerializeRW(serializer, serializeRead, scene->buttons, scene->buttonCount);
|
||||
decorDeserialize(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]);
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ struct DoorTypeDefinition gDoorTypeDefinitions[] = {
|
|||
&props_door_01_model_gfx[0],
|
||||
&props_door_01_Armature_open_clip,
|
||||
&props_door_01_Armature_close_clip,
|
||||
&props_door_01_Armature_opened_clip,
|
||||
DOOR_01_INDEX,
|
||||
-1,
|
||||
1.0f,
|
||||
|
@ -46,6 +47,7 @@ struct DoorTypeDefinition gDoorTypeDefinitions[] = {
|
|||
&props_door_02_model_gfx[0],
|
||||
&props_door_02_Armature_open_clip,
|
||||
&props_door_02_Armature_close_clip,
|
||||
&props_door_02_Armature_opened_clip,
|
||||
DOOR_02_INDEX,
|
||||
PROPS_DOOR_02_DOOR_BONE,
|
||||
3.0f,
|
||||
|
@ -153,4 +155,13 @@ void doorUpdate(struct Door* door) {
|
|||
door->doorDefinition->location.y +
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ struct DoorTypeDefinition {
|
|||
Gfx* model;
|
||||
struct SKAnimationClip* openClip;
|
||||
struct SKAnimationClip* closeClip;
|
||||
struct SKAnimationClip* openedClip;
|
||||
short materialIndex;
|
||||
short colliderBoneIndex;
|
||||
float closeSpeed;
|
||||
|
@ -37,5 +38,6 @@ struct Door {
|
|||
|
||||
void doorInit(struct Door* door, struct DoorDefinition* doorDefinition, struct World* world);
|
||||
void doorUpdate(struct Door* door);
|
||||
void doorCheckForOpenState(struct Door* door);
|
||||
|
||||
#endif
|
|
@ -118,4 +118,8 @@ void pedestalHide(struct Pedestal* pedestal) {
|
|||
void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target) {
|
||||
pedestal->pointAt = *target;
|
||||
pedestal->flags |= PedestalFlagsIsPointing;
|
||||
}
|
||||
|
||||
void pedestalSetDown(struct Pedestal* pedestal) {
|
||||
skAnimatorRunClip(&pedestal->animator, &pedestal_Armature_Hidden_clip, 0.0f, 0);
|
||||
}
|
|
@ -33,4 +33,6 @@ void pedestalUpdate(struct Pedestal* pedestal);
|
|||
void pedestalHide(struct Pedestal* pedestal);
|
||||
void pedestalPointAt(struct Pedestal* pedestal, struct Vector3* target);
|
||||
|
||||
void pedestalSetDown(struct Pedestal* pedestal);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue