Move in all directions is functional

This commit is contained in:
David Markowitz 2025-05-20 18:49:48 -07:00
parent 891b176b4f
commit a4a91f1e73
9 changed files with 139 additions and 20 deletions

View File

@ -1994,6 +1994,22 @@ void Entity::SetRotation(const NiQuaternion& rotation) {
Game::entityManager->SerializeEntity(this);
}
void Entity::SetVelocity(const NiPoint3& velocity) {
auto* controllable = GetComponent<ControllablePhysicsComponent>();
if (controllable != nullptr) {
controllable->SetVelocity(velocity);
}
auto* simple = GetComponent<SimplePhysicsComponent>();
if (simple != nullptr) {
simple->SetVelocity(velocity);
}
Game::entityManager->SerializeEntity(this);
}
bool Entity::GetBoolean(const std::u16string& name) const {
return GetVar<bool>(name);
}

View File

@ -148,6 +148,8 @@ public:
void SetRespawnRot(const NiQuaternion& rotation);
void SetVelocity(const NiPoint3& velocity);
/**
* Component management
*/

View File

@ -30,10 +30,16 @@ bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) {
unsmash.target = GetParent()->GetObjectID();
unsmash.duration = 0.0f;
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
m_Parent->SetPosition(m_OriginalPosition);
m_Parent->SetRotation(m_OriginalRotation);
m_Parent->SetVelocity(NiPoint3Constant::ZERO);
m_NumListeningInteract = 0;
m_NumActiveUnSmash = 0;
m_Dirty = true;
Game::entityManager->SerializeEntity(GetParent());
return true;
}

View File

@ -41,7 +41,7 @@ public:
* Returns the original position of the model
* @return the original position of the model
*/
const NiPoint3& GetPosition() { return m_OriginalPosition; }
const NiPoint3& GetOriginalPosition() { return m_OriginalPosition; }
/**
* Sets the original position of the model
@ -53,7 +53,7 @@ public:
* Returns the original rotation of the model
* @return the original rotation of the model
*/
const NiQuaternion& GetRotation() { return m_OriginalRotation; }
const NiQuaternion& GetOriginalRotation() { return m_OriginalRotation; }
/**
* Sets the original rotation of the model

View File

@ -696,8 +696,9 @@ void PropertyManagementComponent::Save() {
Database::Get()->AddBehavior(info);
}
const auto position = entity->GetPosition();
const auto rotation = entity->GetRotation();
// Always save the original position so we can move the model freely
const auto& position = modelComponent->GetOriginalPosition();
const auto& rotation = modelComponent->GetOriginalRotation();
if (std::find(present.begin(), present.end(), id) == present.end()) {
IPropertyContents::Model model;

View File

@ -33,6 +33,13 @@ SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, int32_t component
SimplePhysicsComponent::~SimplePhysicsComponent() {
}
void SimplePhysicsComponent::Update(const float deltaTime) {
if (m_Velocity == NiPoint3Constant::ZERO) return;
m_Position += m_Velocity * deltaTime;
m_DirtyPosition = true;
Game::entityManager->SerializeEntity(m_Parent);
}
void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) {
outBitStream.Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);

View File

@ -33,6 +33,8 @@ public:
SimplePhysicsComponent(Entity* parent, int32_t componentID);
~SimplePhysicsComponent() override;
void Update(const float deltaTime) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**

View File

@ -97,6 +97,8 @@ void Strip::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
m_WaitingForAction = false;
m_PausedTime = 0.0f;
m_NextActionIndex = 0;
m_InActionMove = NiPoint3Constant::ZERO;
m_PreviousFramePosition = NiPoint3Constant::ZERO;
}
void Strip::IncrementAction() {
@ -127,19 +129,37 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
auto number = nextAction.GetValueParameterDouble();
auto numberAsInt = static_cast<int32_t>(number);
auto nextActionType = GetNextAction().GetType();
if (nextActionType == "SpawnStromling") {
Spawn(10495, entity); // Stromling property
} else if (nextActionType == "SpawnPirate") {
Spawn(10497, entity); // Maelstrom Pirate property
} else if (nextActionType == "SpawnRonin") {
Spawn(10498, entity); // Dark Ronin property
} else if (nextActionType == "DropImagination") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
} else if (nextActionType == "DropHealth") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); // 1 Life powerup
} else if (nextActionType == "DropArmor") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
} else if (nextActionType == "Smash") {
// TODO replace with switch case and nextActionType with enum
/* BEGIN Move */
if (nextActionType == "FlyUp" || nextActionType == "FlyDown") {
bool isFlyDown = nextActionType == "FlyDown";
m_PreviousFramePosition = entity.GetPosition();
m_InActionMove.y = isFlyDown ? -number : number;
// Default velocity is 3 units per second.
entity.SetVelocity(NiPoint3{0.0f, isFlyDown ? -3.0f : 3.0f, 0.0f});
}
else if (nextActionType == "MoveRight" || nextActionType == "MoveLeft") {
bool isMoveLeft = nextActionType == "MoveLeft";
m_PreviousFramePosition = entity.GetPosition();
m_InActionMove.x = isMoveLeft ? -number : number;
// Default velocity is 3 units per second.
entity.SetVelocity(NiPoint3{isMoveLeft ? -3.0f : 3.0f, 0.0f, 0.0f});
}
else if (nextActionType == "MoveForward" || nextActionType == "MoveBackward") {
bool isMoveBackward = nextActionType == "MoveBackward";
m_PreviousFramePosition = entity.GetPosition();
m_InActionMove.z = isMoveBackward ? -number : number;
// Default velocity is 3 units per second.
entity.SetVelocity(NiPoint3{0.0f, 0.0f, isMoveBackward ? -3.0f : 3.0f});
}
/* END Move */
/* BEGIN Action */
else if (nextActionType == "Smash") {
if (!modelComponent.IsUnSmashing()) {
GameMessages::Smash smash{};
smash.target = entity.GetObjectID();
@ -162,7 +182,24 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
sound.target = modelComponent.GetParent()->GetObjectID();
sound.soundID = numberAsInt;
sound.Send(UNASSIGNED_SYSTEM_ADDRESS);
} else {
}
/* END Action */
/* BEGIN Gameplay */
else if (nextActionType == "SpawnStromling") {
Spawn(10495, entity); // Stromling property
} else if (nextActionType == "SpawnPirate") {
Spawn(10497, entity); // Maelstrom Pirate property
} else if (nextActionType == "SpawnRonin") {
Spawn(10498, entity); // Dark Ronin property
} else if (nextActionType == "DropImagination") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(935, entity); // 1 Imagination powerup
} else if (nextActionType == "DropHealth") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(177, entity); // 1 Life powerup
} else if (nextActionType == "DropArmor") {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
}
/* END Gameplay */
else {
static std::set<std::string> g_WarnedActions;
if (!g_WarnedActions.contains(nextActionType.data())) {
LOG("Tried to play action (%s) which is not supported.", nextActionType.data());
@ -187,7 +224,43 @@ void Strip::RemoveStates(ModelComponent& modelComponent) const {
}
}
bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
auto& entity = *modelComponent.GetParent();
const auto& currentPos = entity.GetPosition();
const auto diff = currentPos - m_PreviousFramePosition;
const auto [moveX, moveY, moveZ] = m_InActionMove;
m_PreviousFramePosition = currentPos;
// Only want to subtract from the move if one is being performed.
// Starts at true because we may not be doing a move at all.
// If one is being done, then one of the move_ variables will be non-zero
bool moveFinished = true;
if (moveX != 0.0f) {
m_InActionMove.x -= diff.x;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionMove.x) != std::signbit(moveX);
} else if (moveY != 0.0f) {
m_InActionMove.y -= diff.y;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionMove.y) != std::signbit(moveY);
} else if (moveZ != 0.0f) {
m_InActionMove.z -= diff.z;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionMove.z) != std::signbit(moveZ);
}
// once done, set the in action move & velocity to zero
if (moveFinished) {
entity.SetVelocity(NiPoint3Constant::ZERO);
m_InActionMove = NiPoint3Constant::ZERO;
}
return moveFinished;
}
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
if (!CheckMovement(deltaTime, modelComponent)) return;
m_PausedTime -= deltaTime;
if (m_PausedTime > 0.0f) return;
@ -200,7 +273,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
RemoveStates(modelComponent);
// Check for starting blocks and if not a starting block proc this blocks action
// Check for trigger blocks and if not a trigger block proc this blocks action
if (m_NextActionIndex == 0) {
if (nextAction.GetType() == "OnInteract") {
modelComponent.AddInteract();

View File

@ -29,6 +29,10 @@ public:
void IncrementAction();
void Spawn(LOT object, Entity& entity);
// Checks the movement logic for whether or not to proceed
// Returns true if the movement can continue, false if it needs to wait more.
bool CheckMovement(float deltaTime, ModelComponent& modelComponent);
void Update(float deltaTime, ModelComponent& modelComponent);
void SpawnDrop(LOT dropLOT, Entity& entity);
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent);
@ -38,6 +42,7 @@ private:
bool m_WaitingForAction{ false };
// The amount of time this strip is paused for. Any interactions with this strip should be bounced if this is greater than 0.
// Actions that do not use time do not use this (ex. positions).
float m_PausedTime{ 0.0f };
// The index of the next action to be played. This should always be within range of [0, m_Actions.size()).
@ -48,6 +53,13 @@ private:
// The location of this strip on the UGBehaviorEditor UI
StripUiPosition m_Position;
// The current actions remaining distance to the target
// Only 1 of these vertexs' will be active at once for any given strip.
NiPoint3 m_InActionMove{};
// The position of the parent model on the previous frame
NiPoint3 m_PreviousFramePosition{};
};
#endif //!__STRIP__H__