Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jan 4, 2025
1 parent ad4a162 commit d7be341
Show file tree
Hide file tree
Showing 46 changed files with 226 additions and 132 deletions.
24 changes: 21 additions & 3 deletions Docs/CommonBase.dox → Docs/Death.dox
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** @file
@brief Proxy definitions for documentation purposes

Definitions from this file are usually supplied via a compiler flag by CMake
or by including @ref CommonBase.h, which should be included everywhere. Don't
include this proxy file directly, it's not present in the include directory.
Definitions from this package are usually supplied via a compiler flag by CMake
or by including @ref CommonBase.h.
*/

namespace Death {
Expand Down Expand Up @@ -140,6 +139,7 @@ namespace Death {
@brief Windows RT target

Defined if the library is built for Universal Windows Platform (Windows Store, Phone or Xbox).
In this case, @ref DEATH_TARGET_WINDOWS is also defined.
*/
#define DEATH_TARGET_WINDOWS_RT
#undef DEATH_TARGET_WINDOWS_RT
Expand Down Expand Up @@ -255,6 +255,24 @@ namespace Death {
#define DEATH_TARGET_WASM
#undef DEATH_TARGET_WASM

/**
@brief Whether the library is built for a 32-bit target

Defined if the library is built for a 32-bit target. Not defined on 64-bit platforms.
*/
#define DEATH_TARGET_32BIT
#undef DEATH_TARGET_32BIT

/**
@brief Whether the platform defaults to big-endian

Defined when the platform defaults to big-endian (such as HP/PA RISC, Motorola 68k,
Big-Endian MIPS, PowerPC and SPARC). Not defined on little-endian platforms (such
as x86 and ARM). This macro only reflects the usual architecture default.
*/
#define DEATH_TARGET_BIG_ENDIAN
#undef DEATH_TARGET_BIG_ENDIAN

/**
@brief GCC compiler

Expand Down
2 changes: 1 addition & 1 deletion Docs/Namespaces.dox
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This project is licensed under the terms of the [GNU General Public License v3.0
/** @file Shared/CommonBase.h
@brief Basic definitions

Some configuration-specific and platform-specific definitions are also @ref CommonBase.dox "listed separately".
Some configuration-specific and platform-specific definitions, including `DEATH_TARGET_*`, are @ref Death.dox "listed separately".
Some of them are supplied via a compiler flag by CMake, the rest of them also requires this header file to work properly.
*/
/** @file Shared/Common.h
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/Actors/ActorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace Jazz2::Actors
ExcludeSimilar = 0x8000000,
};

DEFINE_ENUM_OPERATORS(ActorState);
DEATH_ENUM_FLAGS(ActorState);

/** @brief Description how to initialize an actor */
struct ActorActivationDetails {
Expand All @@ -136,7 +136,7 @@ namespace Jazz2::Actors
Force = 0x02
};

DEFINE_ENUM_OPERATORS(MoveType);
DEATH_ENUM_FLAGS(MoveType);

/** @brief Actor renderer type */
enum class ActorRendererType {
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Multiplayer/LocalPlayerOnServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Jazz2::Actors::Multiplayer
{
/** @brief Local player in online session */
class LocalPlayerOnServer : public PlayerOnServer
{
DEATH_RUNTIME_OBJECT(PlayerOnServer);
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Multiplayer/PlayerOnServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Jazz2::Actors::Multiplayer
{
/** @brief Player in online session */
class PlayerOnServer : public Player
{
DEATH_RUNTIME_OBJECT(Player);
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Multiplayer/RemotablePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Jazz2::Actors::Multiplayer
{
/** @brief Remotable player in online session */
class RemotablePlayer : public Player
{
DEATH_RUNTIME_OBJECT(Player);
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Multiplayer/RemoteActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Jazz2::Actors::Multiplayer
{
/** @brief Remote object in online session */
class RemoteActor : public ActorBase
{
DEATH_RUNTIME_OBJECT(ActorBase);
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 @@ -6,6 +6,7 @@

namespace Jazz2::Actors::Multiplayer
{
/** @brief Remote player in online session */
class RemotePlayerOnServer : public PlayerOnServer
{
DEATH_RUNTIME_OBJECT(PlayerOnServer);
Expand Down
12 changes: 6 additions & 6 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ namespace Jazz2::Actors
if (_activeShieldTime > (5.0f * FrameTimer::FramesPerSecond)) {
_activeShieldTime -= (5.0f * FrameTimer::FramesPerSecond);
}
float invulnerableTime = (_levelHandler->Difficulty() == GameDifficulty::Multiplayer ? 80.0f : 180.0f);
float invulnerableTime = (!_levelHandler->IsLocalSession() ? 80.0f : 180.0f);
SetInvulnerability(invulnerableTime, InvulnerableType::Blinking);
PlayPlayerSfx("HurtSoft"_s);
} else {
Expand Down Expand Up @@ -1585,7 +1585,7 @@ namespace Jazz2::Actors
if (_activeShieldTime > (5.0f * FrameTimer::FramesPerSecond)) {
_activeShieldTime -= (5.0f * FrameTimer::FramesPerSecond);
}
float invulnerableTime = (_levelHandler->Difficulty() == GameDifficulty::Multiplayer ? 80.0f : 180.0f);
float invulnerableTime = (!_levelHandler->IsLocalSession() ? 80.0f : 180.0f);
SetInvulnerability(invulnerableTime, InvulnerableType::Blinking);
PlayPlayerSfx("HurtSoft"_s);
} else {
Expand Down Expand Up @@ -1635,7 +1635,7 @@ namespace Jazz2::Actors
if (_activeShieldTime > (5.0f * FrameTimer::FramesPerSecond)) {
_activeShieldTime -= (5.0f * FrameTimer::FramesPerSecond);
}
float invulnerableTime = (_levelHandler->Difficulty() == GameDifficulty::Multiplayer ? 80.0f : 180.0f);
float invulnerableTime = (!_levelHandler->IsLocalSession() ? 80.0f : 180.0f);
SetInvulnerability(invulnerableTime, InvulnerableType::Blinking);
PlayPlayerSfx("HurtSoft"_s);
} else {
Expand All @@ -1659,7 +1659,7 @@ namespace Jazz2::Actors
if (_activeShieldTime > (5.0f * FrameTimer::FramesPerSecond)) {
_activeShieldTime -= (5.0f * FrameTimer::FramesPerSecond);
}
float invulnerableTime = (_levelHandler->Difficulty() == GameDifficulty::Multiplayer ? 80.0f : 180.0f);
float invulnerableTime = (!_levelHandler->IsLocalSession() ? 80.0f : 180.0f);
SetInvulnerability(invulnerableTime, InvulnerableType::Blinking);
PlayPlayerSfx("HurtSoft"_s);
} else {
Expand Down Expand Up @@ -2631,7 +2631,7 @@ namespace Jazz2::Actors
_keepRunningTime = 0.0f;
_carryingObject = nullptr;

if (_lives > 1 || _levelHandler->Difficulty() == GameDifficulty::Multiplayer) {
if (_lives > 1 || !_levelHandler->IsLocalSession()) {
if (_lives > 1 && _lives < UINT8_MAX) {
_lives--;
}
Expand Down Expand Up @@ -3713,7 +3713,7 @@ namespace Jazz2::Actors
_controllable = true;
});

float invulnerableTime = (_levelHandler->Difficulty() == GameDifficulty::Multiplayer ? 80.0f : 180.0f);
float invulnerableTime = (!_levelHandler->IsLocalSession() ? 80.0f : 180.0f);
SetInvulnerability(invulnerableTime, InvulnerableType::Blinking);
PlayPlayerSfx("Hurt"_s);
_levelHandler->PlayerExecuteRumble(_playerIndex, "Hurt"_s);
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Actors/Solid/GenericContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Jazz2::Actors::Solid
{
/** @brief Base class of an item container */
class GenericContainer : public SolidObjectBase
{
DEATH_RUNTIME_OBJECT(SolidObjectBase);
Expand Down
3 changes: 2 additions & 1 deletion Sources/Jazz2/AnimState.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Jazz2
{
/** @brief Well-known animation state */
enum class AnimState
{
// Bits 0, 1: Horizontal speed (none, low, med, high)
Expand Down Expand Up @@ -94,5 +95,5 @@ namespace Jazz2
Default = 0
};

DEFINE_ENUM_OPERATORS(AnimState);
DEATH_ENUM_FLAGS(AnimState);
}
2 changes: 1 addition & 1 deletion Sources/Jazz2/Compatibility/JJ2Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ namespace Jazz2::Compatibility
All = 0xffff
};

DEFINE_ENUM_OPERATORS(JJ2Version);
DEATH_ENUM_FLAGS(JJ2Version);
}
2 changes: 1 addition & 1 deletion Sources/Jazz2/Direction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ namespace Jazz2
Any = Up | Down | Left | Right
};

DEFINE_ENUM_OPERATORS(Direction);
DEATH_ENUM_FLAGS(Direction);
}
2 changes: 1 addition & 1 deletion Sources/Jazz2/ExitType.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ namespace Jazz2
FastTransition = 0x80
};

DEFINE_ENUM_OPERATORS(ExitType);
DEATH_ENUM_FLAGS(ExitType);
}
4 changes: 1 addition & 3 deletions Sources/Jazz2/GameDifficulty.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Jazz2

Easy,
Normal,
Hard,

Multiplayer
Hard
};
}
9 changes: 9 additions & 0 deletions Sources/Jazz2/ILevelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ namespace Jazz2
static constexpr std::int32_t SpritePlaneZ = MainPlaneZ + 10;
static constexpr std::int32_t PlayerZ = MainPlaneZ + 20;

/** @brief Initializes the level handler from @ref LevelInitialization */
virtual bool Initialize(const LevelInitialization& levelInit) = 0;
/** @brief Initializes the level handler from resumable state */
virtual bool Initialize(Stream& src, std::uint16_t version) = 0;

/** @brief Returns event spawner for the level */
virtual Events::EventSpawner* EventSpawner() = 0;
/** @brief Returns event map for the level */
virtual Events::EventMap* EventMap() = 0;
/** @brief Returns tile map for the level */
virtual Tiles::TileMap* TileMap() = 0;

/** @brief Return current difficulty */
virtual GameDifficulty Difficulty() const = 0;
/** @brief Return `true` if the level handler is on a local session */
virtual bool IsLocalSession() const = 0;
/** @brief Return `true` if the level handler is pausable */
virtual bool IsPausable() const = 0;
virtual bool IsReforged() const = 0;
virtual bool CanPlayersCollide() const = 0;
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/IResumable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Jazz2
public:
IResumable() {}

/** @brief Serializes object state to a stream */
virtual bool SerializeResumableToStream(Stream& dest) = 0;
};
}
16 changes: 15 additions & 1 deletion Sources/Jazz2/IRootController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Jazz2
class IRootController
{
public:
/** @brief State flags of root controller, supports a bitwise combination of its member values */
enum class Flags {
None = 0x00,

Expand All @@ -26,32 +27,45 @@ namespace Jazz2
#endif
};

DEFINE_PRIVATE_ENUM_OPERATORS(Flags);
DEATH_PRIVATE_ENUM_FLAGS(Flags);

IRootController() { }
virtual ~IRootController() { }

IRootController(const IRootController&) = delete;
IRootController& operator=(const IRootController&) = delete;

/** @brief Invokes the specified callback asynchronously, usually at the end of current frame */
virtual void InvokeAsync(Function<void()>&& callback, const char* sourceFunc = nullptr) = 0;
/** @brief Sets current state handler to main menu */
virtual void GoToMainMenu(bool afterIntro) = 0;
/** @brief Sets current state handler to level described by @ref LevelInitialization */
virtual void ChangeLevel(LevelInitialization&& levelInit) = 0;
/** @brief Returns `true` if any resumable state exists */
virtual bool HasResumableState() const = 0;
/** @brief Resumes saved resumable state */
virtual void ResumeSavedState() = 0;
/** @brief Saves current state if it's resumable */
virtual bool SaveCurrentStateIfAny() = 0;

#if defined(WITH_MULTIPLAYER)
/** @brief Sets current state handler to remove multiplayer session */
virtual bool ConnectToServer(StringView address, std::uint16_t port) = 0;
/** @brief Creates a multiplayer server */
virtual bool CreateServer(LevelInitialization&& levelInit, std::uint16_t port) = 0;

/** @brief Returns name of the server */
virtual StringView GetServerName() const = 0;
/** @brief Sets name of the server */
virtual void SetServerName(StringView value) = 0;
#endif

/** @brief Returns current state flags */
virtual Flags GetFlags() const = 0;
/** @brief Returns version of the latest update */
virtual StringView GetNewestVersion() const = 0;

/** @brief Recreates level cache from `Source` directory */
virtual void RefreshCacheLevels() = 0;
};
}
2 changes: 1 addition & 1 deletion Sources/Jazz2/LevelFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ namespace Jazz2
HasMultiplayerSpawnPoints = 0x100
};

DEFINE_ENUM_OPERATORS(LevelFlags);
DEATH_ENUM_FLAGS(LevelFlags);
}
Loading

0 comments on commit d7be341

Please sign in to comment.