diff --git a/assets/models/pedestal.blend b/assets/models/pedestal.blend index 1edd40c..bd67ec0 100644 Binary files a/assets/models/pedestal.blend and b/assets/models/pedestal.blend differ diff --git a/assets/models/props/door_01.blend b/assets/models/props/door_01.blend index 519fe85..095d68d 100644 Binary files a/assets/models/props/door_01.blend and b/assets/models/props/door_01.blend differ diff --git a/assets/models/props/door_02.blend b/assets/models/props/door_02.blend index f8da9f9..475456d 100644 Binary files a/assets/models/props/door_02.blend and b/assets/models/props/door_02.blend differ diff --git a/src/savefile/savefile.h b/src/savefile/savefile.h index 5e7f432..0d5fa09 100755 --- a/src/savefile/savefile.h +++ b/src/savefile/savefile.h @@ -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) diff --git a/src/savefile/scene_serialize.c b/src/savefile/scene_serialize.c index 1dec421..2e9ef97 100644 --- a/src/savefile/scene_serialize.c +++ b/src/savefile/scene_serialize.c @@ -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]); + } } \ No newline at end of file diff --git a/src/scene/door.c b/src/scene/door.c index 07e78ee..a5d4277 100644 --- a/src/scene/door.c +++ b/src/scene/door.c @@ -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); + } } \ No newline at end of file diff --git a/src/scene/door.h b/src/scene/door.h index eec1d54..3b6ca9b 100644 --- a/src/scene/door.h +++ b/src/scene/door.h @@ -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 \ No newline at end of file diff --git a/src/scene/pedestal.c b/src/scene/pedestal.c index be48ffa..6e549d4 100644 --- a/src/scene/pedestal.c +++ b/src/scene/pedestal.c @@ -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); } \ No newline at end of file diff --git a/src/scene/pedestal.h b/src/scene/pedestal.h index 3dfede4..34a8986 100644 --- a/src/scene/pedestal.h +++ b/src/scene/pedestal.h @@ -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 \ No newline at end of file