Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jan 2, 2025
1 parent 1f8a029 commit 9906c2a
Show file tree
Hide file tree
Showing 101 changed files with 360 additions and 247 deletions.
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ namespace Jazz2::Actors
}
}

bool ActorBase::MoveInstantly(const Vector2f& pos, MoveType type, TileCollisionParams& params)
bool ActorBase::MoveInstantly(Vector2f pos, MoveType type, TileCollisionParams& params)
{
Vector2f newPos;
AABBf aabb;
Expand Down
8 changes: 4 additions & 4 deletions Sources/Jazz2/Actors/ActorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ namespace Jazz2::Actors
std::int32_t GetMaxHealth();
void DecreaseHealth(std::int32_t amount = 1, ActorBase* collider = nullptr);

bool MoveInstantly(const Vector2f& pos, MoveType type, Tiles::TileCollisionParams& params);
bool MoveInstantly(const Vector2f& pos, MoveType type)
bool MoveInstantly(Vector2f pos, MoveType type, Tiles::TileCollisionParams& params);
bool MoveInstantly(Vector2f pos, MoveType type)
{
Tiles::TileCollisionParams params = { Tiles::TileDestructType::None, _speed.Y >= 0.0f };
return MoveInstantly(pos, type, params);
Expand All @@ -189,11 +189,11 @@ namespace Jazz2::Actors
bool IsCollidingWith(const AABBf& aabb);
void UpdateAABB();

const Vector2f& GetPos() {
Vector2f GetPos() {
return _pos;
}

const Vector2f& GetSpeed() {
Vector2f GetSpeed() {
return _speed;
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Multiplayer/RemotablePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Jazz2::Actors::Multiplayer
}
}

void RemotablePlayer::OnWaterSplash(const Vector2f& pos, bool inwards)
void RemotablePlayer::OnWaterSplash(Vector2f pos, bool inwards)
{
// Already created and broadcasted by the server
}
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace Jazz2::Actors::Multiplayer
});
}

void RemotablePlayer::MoveRemotely(const Vector2f& pos, const Vector2f& speed)
void RemotablePlayer::MoveRemotely(Vector2f pos, Vector2f speed)
{
Vector2f posPrev = _pos;
MoveInstantly(pos, MoveType::Absolute | MoveType::Force);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Multiplayer/RemotablePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ namespace Jazz2::Actors::Multiplayer
void SetTeamId(std::uint8_t value);

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

protected:
Task<bool> OnActivatedAsync(const ActorActivationDetails& details) override;
bool OnPerish(ActorBase* collider) override;
void OnUpdate(float timeMult) override;

void OnWaterSplash(const Vector2f& pos, bool inwards) override;
void OnWaterSplash(Vector2f pos, bool inwards) override;

bool FireCurrentWeapon(WeaponType weaponType) override;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Multiplayer/RemoteActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace Jazz2::Actors::Multiplayer
ActorBase::OnUpdate(timeMult);
}

void RemoteActor::AssignMetadata(const StringView& path, AnimState anim, ActorState state)
void RemoteActor::AssignMetadata(StringView path, AnimState anim, ActorState state)
{
constexpr ActorState RemotedFlags = ActorState::Illuminated | ActorState::IsInvulnerable | ActorState::TriggersTNT |
ActorState::CollideWithOtherActors | ActorState::CollideWithSolidObjects | ActorState::IsSolidObject |
Expand All @@ -78,7 +78,7 @@ namespace Jazz2::Actors::Multiplayer
SetState((GetState() & ~RemotedFlags) | (state & RemotedFlags));
}

void RemoteActor::SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType)
void RemoteActor::SyncWithServer(Vector2f pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType)
{
Clock& c = nCine::clock();
std::int64_t now = c.now() * 1000 / c.frequency();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/Multiplayer/RemoteActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Jazz2::Actors::Multiplayer
public:
RemoteActor();

void AssignMetadata(const StringView& path, AnimState anim, ActorState state);
void SyncWithServer(const Vector2f& pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType);
void AssignMetadata(StringView path, AnimState anim, ActorState state);
void SyncWithServer(Vector2f pos, AnimState anim, float rotation, bool isVisible, bool isFacingLeft, bool animPaused, Actors::ActorRendererType rendererType);

protected:
struct StateFrame {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Jazz2/Actors/Multiplayer/RemotePlayerOnServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Jazz2::Actors::Multiplayer
return success;
}

void RemotePlayerOnServer::SyncWithServer(const Vector2f& pos, const Vector2f& speed, bool isVisible, bool isFacingLeft, bool isActivelyPushing)
void RemotePlayerOnServer::SyncWithServer(Vector2f pos, const Vector2f& speed, bool isVisible, bool isFacingLeft, bool isActivelyPushing)
{
if (_health <= 0) {
// Don't sync dead players to avoid cheating
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace Jazz2::Actors::Multiplayer
_speed = speed;
}

void RemotePlayerOnServer::OnHitSpring(const Vector2f& pos, const Vector2f& force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove)
void RemotePlayerOnServer::OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove)
{
if (!static_cast<Jazz2::Multiplayer::MultiLevelHandler*>(_levelHandler)->HandlePlayerSpring(this, pos, force, keepSpeedX, keepSpeedY)) {
return;
Expand All @@ -142,7 +142,7 @@ namespace Jazz2::Actors::Multiplayer
PlayerOnServer::OnHitSpring(pos, force, keepSpeedX, keepSpeedY, removeSpecialMove);
}

void RemotePlayerOnServer::WarpToPosition(const Vector2f& pos, WarpFlags flags)
void RemotePlayerOnServer::WarpToPosition(Vector2f pos, WarpFlags flags)
{
PlayerOnServer::WarpToPosition(pos, flags);

Expand Down
6 changes: 3 additions & 3 deletions Sources/Jazz2/Actors/Multiplayer/RemotePlayerOnServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Jazz2::Actors::Multiplayer
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);
void SyncWithServer(Vector2f pos, const Vector2f& speed, bool isVisible, bool isFacingLeft, bool isActivelyPushing);

protected:
struct StateFrame {
Expand All @@ -34,9 +34,9 @@ namespace Jazz2::Actors::Multiplayer
bool OnPerish(ActorBase* collider) override;
void OnUpdate(float timeMult) override;

void OnHitSpring(const Vector2f& pos, const Vector2f& force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove) override;
void OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove) override;

void WarpToPosition(const Vector2f& pos, WarpFlags flags) override;
void WarpToPosition(Vector2f pos, WarpFlags flags) override;
bool TakeDamage(std::int32_t amount, float pushForce) override;

bool AddAmmo(WeaponType weaponType, std::int16_t count) override;
Expand Down
10 changes: 5 additions & 5 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ namespace Jazz2::Actors
}
}

void Player::OnHitSpring(const Vector2f& pos, const Vector2f& force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove)
void Player::OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove)
{
std::int32_t sign = ((force.X + force.Y) > std::numeric_limits<float>::epsilon() ? 1 : -1);
if (std::abs(force.X) > 0.0f) {
Expand Down Expand Up @@ -1832,7 +1832,7 @@ namespace Jazz2::Actors
}
}

void Player::OnWaterSplash(const Vector2f& pos, bool inwards)
void Player::OnWaterSplash(Vector2f pos, bool inwards)
{
Explosion::Create(_levelHandler, Vector3i((std::int32_t)pos.X, (std::int32_t)pos.Y, _renderer.layer() + 2), Explosion::Type::WaterSplash);
_levelHandler->PlayCommonSfx("WaterSplash"_s, Vector3f(pos.X, pos.Y, 0.0f), inwards ? 0.7f : 1.0f, 0.5f);
Expand Down Expand Up @@ -2554,7 +2554,7 @@ namespace Jazz2::Actors
}
}

std::shared_ptr<AudioBufferPlayer> Player::PlayPlayerSfx(const StringView identifier, float gain, float pitch)
std::shared_ptr<AudioBufferPlayer> Player::PlayPlayerSfx(StringView identifier, float gain, float pitch)
{
#if defined(WITH_AUDIO)
auto it = _metadata->Sounds.find(String::nullTerminatedView(identifier));
Expand Down Expand Up @@ -3366,7 +3366,7 @@ namespace Jazz2::Actors
dest.Write(_weaponUpgradesCheckpoint, sizeof(_weaponUpgradesCheckpoint));
}

void Player::Respawn(const Vector2f& pos)
void Player::Respawn(Vector2f pos)
{
if ((GetState() & (ActorState::IsInvulnerable | ActorState::ApplyGravitation | ActorState::CollideWithTileset | ActorState::CollideWithOtherActors)) != ActorState::IsInvulnerable) {
return;
Expand All @@ -3382,7 +3382,7 @@ namespace Jazz2::Actors
SetState(ActorState::ApplyGravitation | ActorState::CollideWithTileset | ActorState::CollideWithOtherActors, true);
}

void Player::WarpToPosition(const Vector2f& pos, WarpFlags flags)
void Player::WarpToPosition(Vector2f pos, WarpFlags flags)
{
if ((flags & WarpFlags::Fast) == WarpFlags::Fast) {
Vector2f posPrev = _pos;
Expand Down
10 changes: 5 additions & 5 deletions Sources/Jazz2/Actors/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ namespace Jazz2::Actors
void InitializeFromStream(ILevelHandler* levelHandler, Stream& src, std::uint16_t version);
void SerializeResumableToStream(Stream& dest);

void Respawn(const Vector2f& pos);
virtual void WarpToPosition(const Vector2f& pos, WarpFlags flags);
void Respawn(Vector2f pos);
virtual void WarpToPosition(Vector2f pos, WarpFlags flags);
void WarpToCheckpoint();
Modifier GetModifier() const;
bool SetModifier(Modifier modifier, const std::shared_ptr<ActorBase>& decor = nullptr);
Expand Down Expand Up @@ -294,10 +294,10 @@ namespace Jazz2::Actors
void OnHitCeiling(float timeMult) override;
void OnHitWall(float timeMult) override;

virtual void OnHitSpring(const Vector2f& pos, const Vector2f& force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove);
virtual void OnWaterSplash(const Vector2f& pos, bool inwards);
virtual void OnHitSpring(Vector2f pos, Vector2f force, bool keepSpeedX, bool keepSpeedY, bool& removeSpecialMove);
virtual void OnWaterSplash(Vector2f pos, bool inwards);

std::shared_ptr<AudioBufferPlayer> PlayPlayerSfx(const StringView identifier, float gain = 1.0f, float pitch = 1.0f);
std::shared_ptr<AudioBufferPlayer> PlayPlayerSfx(StringView identifier, float gain = 1.0f, float pitch = 1.0f);
bool SetPlayerTransition(AnimState state, bool cancellable, bool removeControl, SpecialMoveType specialMove, Function<void()>&& callback = {});
bool CanFreefall();
void EndDamagingMove();
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Collisions/DynamicTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace Jazz2::Collisions
FreeNode(proxyId);
}

bool DynamicTree::MoveProxy(std::int32_t proxyId, const AABBf& aabb, const Vector2f& displacement)
bool DynamicTree::MoveProxy(std::int32_t proxyId, const AABBf& aabb, Vector2f displacement)
{
//b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);

Expand Down
6 changes: 3 additions & 3 deletions Sources/Jazz2/Collisions/DynamicTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Jazz2::Collisions
constexpr float AabbMultiplier = 4.0f;

/**
@brief A node in the dynamic tree
@brief Node in the dynamic tree
The client does not interact with this directly.
*/
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace Jazz2::Collisions
};

/**
@brief A dynamic AABB tree broad-phase
@brief Dynamic AABB tree broad-phase
A dynamic tree arranges data in a binary tree to accelerate
queries such as volume queries and ray casts. Leafs are proxies
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace Jazz2::Collisions
/// then the proxy is removed from the tree and re-inserted. Otherwise
/// the function returns immediately.
/// @return true if the proxy was re-inserted.
bool MoveProxy(std::int32_t proxyId, const AABBf& aabb1, const Vector2f& displacement);
bool MoveProxy(std::int32_t proxyId, const AABBf& aabb1, Vector2f displacement);

/// Get proxy user data.
/// @return the proxy user data or 0 if the id is invalid.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Compatibility/AnimSetMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ namespace Jazz2::Compatibility
}
}

void AnimSetMapping::Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette)
void AnimSetMapping::Add(JJ2Version appliesTo, StringView category, StringView name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette)
{
if ((_version & appliesTo) != JJ2Version::Unknown) {
Entry entry;
Expand All @@ -2005,7 +2005,7 @@ namespace Jazz2::Compatibility
}
}

void AnimSetMapping::Add(const StringView& category, const StringView& name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette)
void AnimSetMapping::Add(StringView category, StringView name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette)
{
Entry entry;
entry.Category = category;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Compatibility/AnimSetMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Jazz2::Compatibility
void DiscardItems(std::uint32_t advanceBy, JJ2Version appliesTo = JJ2Version::All);
void SkipItems(std::uint32_t advanceBy = 1);
void NextSet(std::uint32_t advanceBy = 1, JJ2Version appliesTo = JJ2Version::All);
void Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
void Add(const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
void Add(JJ2Version appliesTo, StringView category, StringView name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
void Add(StringView category, StringView name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
};
}
4 changes: 2 additions & 2 deletions Sources/Jazz2/Compatibility/JJ2Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace Jazz2::Compatibility
}
}

void JJ2Level::LoadMlleData(JJ2Block& block, std::uint32_t version, const StringView& path, bool strictParser)
void JJ2Level::LoadMlleData(JJ2Block& block, std::uint32_t version, StringView path, bool strictParser)
{
if (version > 0x106) {
LOGW("MLLE stream version 0x%x in level \"%s\" is not supported", version, LevelName.data());
Expand Down Expand Up @@ -1076,7 +1076,7 @@ namespace Jazz2::Compatibility
}
}

bool JJ2Level::StringHasSuffixIgnoreCase(const StringView value, const StringView suffix)
bool JJ2Level::StringHasSuffixIgnoreCase(StringView value, StringView suffix)
{
const std::size_t size = value.size();
const std::size_t suffixSize = suffix.size();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Compatibility/JJ2Level.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ namespace Jazz2::Compatibility
void LoadLayerMetadata(JJ2Block& block, bool strictParser);
void LoadEvents(JJ2Block& block, bool strictParser);
void LoadLayers(JJ2Block& dictBlock, std::int32_t dictLength, JJ2Block& layoutBlock, bool strictParser);
void LoadMlleData(JJ2Block& block, uint32_t version, const StringView& path, bool strictParser);
void LoadMlleData(JJ2Block& block, std::uint32_t version, StringView path, bool strictParser);

static void WriteLevelName(Stream& so, MutableStringView value, Function<LevelToken(StringView)>&& levelTokenConversion = {});
static bool StringHasSuffixIgnoreCase(const StringView value, const StringView suffix);
static bool StringHasSuffixIgnoreCase(StringView value, StringView suffix);
};
}
Loading

0 comments on commit 9906c2a

Please sign in to comment.