Repository navigation
Link TurningPlatform.cpp #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boebie-dev
wants to merge
2
commits into
1superchip:main
Choose a base branch
from
boebie-dev:turning-platform
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #ifndef TURNINGPLATFORM_H | ||
| #define TURNINGPLATFORM_H | ||
|
|
||
| #include "ty/props/Platform.h" | ||
| #include "ty/tools.h" | ||
|
|
||
| void TurningPlatform_LoadResources(KromeIni* pIni); | ||
|
|
||
| // A platform that turns to face its next waypoint when hit by a boomerang or activated | ||
| struct TurningPlatform : Platform { | ||
| float angles[MAX_WAYPOINTS]; // Unofficial: unkD4. Yaw facing each waypoint from the first waypoint | ||
| int numAngles; // Unofficial: unk114 | ||
| int targetAngle; // Unofficial: unk118 | ||
| int currAngle; // Unofficial: unk11C | ||
| float turnSpeed; | ||
| int turnStartFrame; // Unofficial: unk124 | ||
|
|
||
| static Tools_WayPoints loadPoints; | ||
|
|
||
| virtual bool LoadLine(KromeIniLine* pLine); | ||
| virtual void LoadDone(void); | ||
| virtual void Reset(void); | ||
| virtual void Update(void); | ||
| virtual void Message(MKMessage* pMsg); | ||
| virtual void Init(GameObjDesc* pDesc); | ||
| void TurnToNext(void); | ||
| }; | ||
|
|
||
| #endif // TURNINGPLATFORM_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #include "ty/props/TurningPlatform.h" | ||
| #include "ty/GameObjectManager.h" | ||
| #include "ty/global.h" | ||
| #include "common/StdMath.h" | ||
| #include "common/System_GC.h" | ||
|
|
||
| extern "C" double atan2(double, double); | ||
|
|
||
| static ModuleInfo<TurningPlatform> turnPlatformModuleInfo; | ||
| Tools_WayPoints TurningPlatform::loadPoints; | ||
|
|
||
| void TurningPlatform_LoadResources(KromeIni* pIni) { // Unofficial: pIni | ||
| PlatformDesc defaultTurningPlatformDesc; // Unofficial | ||
| defaultTurningPlatformDesc.Init(&turnPlatformModuleInfo, "", "", GOID_Platform, 1); | ||
| LoadDescriptors<PlatformDesc>(pIni, "TurningPlatforms", &defaultTurningPlatformDesc); | ||
| } | ||
|
|
||
| void TurningPlatform::Init(GameObjDesc* pDesc) { | ||
| Platform::Init(pDesc); | ||
| loadPoints.Init(); | ||
| mCurrRot.Set(0.0f, 0.0f, 0.0f); | ||
| targetAngle = 0; | ||
| currAngle = 0; | ||
| turnStartFrame = -1; | ||
| turnSpeed = 0.2f; | ||
| } | ||
|
|
||
| bool TurningPlatform::LoadLine(KromeIniLine* pLine) { | ||
| return loadPoints.LoadLine(pLine, Tools_WayPoints::LOAD_MODE_1) || | ||
| LoadLevel_LoadFloat(pLine, "turnSpeed", &turnSpeed) || | ||
| Platform::LoadLine(pLine); | ||
| } | ||
|
|
||
| void TurningPlatform::LoadDone(void) { | ||
| GetPos()->Copy(&loadPoints.vecs[0]); | ||
| GetPos()->w = 1.0f; | ||
|
|
||
| numAngles = loadPoints.unk104 - 1; | ||
|
|
||
| for (int i = 1; i < loadPoints.unk104; i++) { // Unofficial: i | ||
| angles[i - 1] = PI2 + (float)atan2(loadPoints.vecs[i].z - GetPos()->z, loadPoints.vecs[i].x - GetPos()->x); | ||
| } | ||
|
|
||
| if (numAngles > 0) { | ||
| StaticProp::loadInfo.defaultRot.y = angles[0]; | ||
| } | ||
|
|
||
| Platform::LoadDone(); | ||
| } | ||
|
|
||
| void TurningPlatform::Update(void) { | ||
| BeginUpdate(); | ||
| UpdateTilt(); | ||
|
|
||
| if (currAngle != targetAngle) { | ||
| float delta = GetSmallestAngle(angles[currAngle], angles[targetAngle]); // Unofficial | ||
|
|
||
| float t = (float)(gb.logicGameCount - turnStartFrame) / Abs<float>(gDisplay.fps * (delta / turnSpeed)); // Unofficial: t | ||
| t = Clamp<float>(0.0f, t, 1.0f); | ||
|
|
||
| mCurrRot.y = angles[currAngle] + delta * _table_sinf(PI * (0.5f * t)); | ||
|
|
||
| if (t == 1.0f) { | ||
| currAngle = targetAngle; | ||
| } | ||
| } | ||
|
|
||
| EndUpdate(); | ||
| } | ||
|
|
||
| void TurningPlatform::Reset(void) { | ||
| mCurrRot = mDefaultRot; | ||
| pModel->matrices[0].SetRotationPYR(&mCurrRot); | ||
| unk58 = NULL; | ||
| } | ||
|
|
||
| void TurningPlatform::Message(MKMessage* pMsg) { | ||
| switch (pMsg->unk0) { | ||
| case MSG_BoomerangMsg: | ||
| case MSG_Activate: | ||
| if (currAngle == targetAngle) { | ||
| TurnToNext(); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| Platform::Message(pMsg); | ||
| } | ||
|
|
||
| void TurningPlatform::TurnToNext(void) { | ||
| targetAngle = (targetAngle + 1) % numAngles; | ||
| turnStartFrame = gb.logicGameCount; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be verified