Skip to content

Commit

Permalink
Multiplayer fixes, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Oct 29, 2024
1 parent 5a69765 commit a599466
Show file tree
Hide file tree
Showing 45 changed files with 492 additions and 355 deletions.
11 changes: 10 additions & 1 deletion Sources/Jazz2/Actors/Multiplayer/RemotablePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ namespace Jazz2::Actors::Multiplayer
void RemotablePlayer::OnUpdate(float timeMult)
{
Player::OnUpdate(timeMult);

if (_levelExiting != LevelExitingState::None) {
OnLevelChanging(nullptr, ExitType::None);
}
}

void RemotablePlayer::OnWaterSplash(const Vector2f& pos, bool inwards)
Expand All @@ -52,8 +56,13 @@ namespace Jazz2::Actors::Multiplayer
_teamId = value;
}

void RemotablePlayer::WarpIn()
void RemotablePlayer::WarpIn(ExitType exitType)
{
if (exitType != (ExitType)0xFF) {
OnLevelChanging(this, exitType);
return;
}

EndDamagingMove();
SetState(ActorState::IsInvulnerable, true);
SetState(ActorState::ApplyGravitation, false);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Multiplayer/RemotablePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Jazz2::Actors::Multiplayer
std::uint8_t GetTeamId() const;
void SetTeamId(std::uint8_t value);

void WarpIn();
void WarpIn(ExitType exitType);
void MoveRemotely(const Vector2f& pos, const Vector2f& speed);

protected:
Expand Down
14 changes: 14 additions & 0 deletions Sources/Jazz2/Actors/Multiplayer/RemotePlayerOnServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,23 @@ namespace Jazz2::Actors::Multiplayer

bool RemotePlayerOnServer::OnHandleCollision(std::shared_ptr<ActorBase> other)
{
// TODO: Remove this override
return PlayerOnServer::OnHandleCollision(other);
}

bool RemotePlayerOnServer::OnLevelChanging(Actors::ActorBase* initiator, ExitType exitType)
{
LevelExitingState lastState = _levelExiting;
bool success = PlayerOnServer::OnLevelChanging(initiator, exitType);

if (lastState == LevelExitingState::None) {
// Level changing just started, send the request to the player as WarpIn packet
static_cast<Jazz2::Multiplayer::MultiLevelHandler*>(_levelHandler)->HandlePlayerLevelChanging(this, exitType);
}

return success;
}

void RemotePlayerOnServer::SyncWithServer(const Vector2f& pos, const Vector2f& speed, bool isVisible, bool isFacingLeft, bool isActivelyPushing)
{
Clock& c = nCine::clock();
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Multiplayer/RemotePlayerOnServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Jazz2::Actors::Multiplayer
RemotePlayerOnServer();

bool OnHandleCollision(std::shared_ptr<ActorBase> other) override;
bool OnLevelChanging(Actors::ActorBase* initiator, ExitType exitType) override;

void SyncWithServer(const Vector2f& pos, const Vector2f& speed, bool isVisible, bool isFacingLeft, bool isActivelyPushing);

Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Jazz2::Actors
bool CanBreakSolidObjects() const;
bool CanMoveVertically() const;

bool OnLevelChanging(Actors::ActorBase* initiator, ExitType exitType);
virtual bool OnLevelChanging(Actors::ActorBase* initiator, ExitType exitType);
void ReceiveLevelCarryOver(ExitType exitType, const PlayerCarryOver& carryOver);
PlayerCarryOver PrepareLevelCarryOver();
void InitializeFromStream(ILevelHandler* levelHandler, Stream& src);
Expand Down
Loading

0 comments on commit a599466

Please sign in to comment.