Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Feb 4, 2025
1 parent f5efef1 commit a33d935
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ concurrency:

jobs:
Build:
#runs-on: 'ubuntu-latest'
runs-on: 'ubuntu-22.04'
runs-on: 'ubuntu-latest'
#runs-on: 'ubuntu-22.04'

steps:
- name: 'Checkout Repository'
Expand Down
3 changes: 3 additions & 0 deletions Docs/Death.dox
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace Death {
by checking the @cpp _CPPUNWIND @ce and @cpp __EXCEPTIONS @ce defines. If
@cpp DEATH_SUPPRESS_EXCEPTIONS @ce is defined, exception support is explicitly
disabled. In this case, @cpp throw @ce is usually replaced with asserts.

No need to @cpp #include @ce anything for this macro to be defined,
it's supplied via a compiler flag by CMake.
*/
#define DEATH_SUPPRESS_EXCEPTIONS
#undef DEATH_SUPPRESS_EXCEPTIONS
Expand Down
2 changes: 1 addition & 1 deletion Docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOXYFILE = 'Doxyfile'
FAVICON = 'favicon.ico'
#FAVICON = 'favicon.ico'
MAIN_PROJECT_URL = 'https://deat.tk/jazz2/'
SHOW_UNDOCUMENTED = True
VERSION_LABELS = True
Expand Down
33 changes: 20 additions & 13 deletions Sources/Jazz2/Collisions/DynamicTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,32 @@ namespace Jazz2::Collisions
*/
struct TreeNode
{
/// Enlarged AABB
/** @brief Enlarged AABB */
AABBf Aabb;

/** @brief Opaque pointer to user-supplied data */
void* UserData;

union
{
/** @brief Node ID of parent node */
std::int32_t Parent;
/** @brief Node ID of next node */
std::int32_t Next;
};

/** @brief Node ID of the first child */
std::int32_t Child1;
/** @brief Node ID of the second child */
std::int32_t Child2;

// leaf = 0, free node = -1
/** @brief Height (leaf = 0, free node = -1) */
std::int32_t Height;

/** @brief Whether node has been moved */
bool Moved;

/** @brief Returns whether the node is leaf */
bool IsLeaf() const
{
return (Child1 == NullNode);
Expand Down Expand Up @@ -118,7 +125,7 @@ namespace Jazz2::Collisions
*/
void* GetUserData(std::int32_t proxyId) const;

/** @brief Returns `true` if a proxy was moved */
/** @brief Returns `true` if a proxy has been moved */
bool WasMoved(std::int32_t proxyId) const;
/** @brief Clears moved status of a proxy */
void ClearMoved(std::int32_t proxyId);
Expand All @@ -130,15 +137,15 @@ namespace Jazz2::Collisions
template<typename T>
void Query(T* callback, const AABBf& aabb) const;

///* @brief Ray-cast against the proxies in the tree
// *
// * This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape.
// * The callback also performs the any collision filtering. This has performance
// * roughly equal to @f$ k * log(n) @f$, where k is the number of collisions and n is the
// * number of proxies in the tree.
// * @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
// * @param callback a callback class that is called for each proxy that is hit by the ray.
// */
// @brief Ray-cast against the proxies in the tree
//
// This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape.
// The callback also performs the any collision filtering. This has performance
// roughly equal to @f$ k * log(n) @f$, where k is the number of collisions and n is the
// number of proxies in the tree.
// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
// @param callback a callback class that is called for each proxy that is hit by the ray.
//
//template <typename T>
//void RayCast(T* callback, const b2RayCastInput& input) const;

Expand All @@ -157,7 +164,7 @@ namespace Jazz2::Collisions
/** @brief Returns the ratio of the sum of the node areas to the root area */
float GetAreaRatio() const;

/** @brief Build an optimal tree, very expensive --- for testing only */
/** @brief Builds an optimal tree, very expensive --- for testing only */
void RebuildBottomUp();

/**
Expand Down
2 changes: 2 additions & 0 deletions Sources/Jazz2/Collisions/DynamicTreeBroadPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace Jazz2::Collisions
{
/** @brief Collided pair of objects found by collision detection */
struct CollisionPair {
/** @brief Proxy ID of the first node */
std::int32_t ProxyIdA;
/** @brief Proxy ID of the second node */
std::int32_t ProxyIdB;
};

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

bool ServerDiscovery::ProcessResponses(ENetSocket socket, ServerDesc& discoveredServer, std::int32_t timeoutMs)
bool ServerDiscovery::ProcessResponses(ENetSocket socket, ServerDescription& discoveredServer, std::int32_t timeoutMs)
{
ENetSocketSet set;
ENET_SOCKETSET_EMPTY(set);
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace Jazz2::Multiplayer
TrySendRequest(socket, _this->_address);
}

ServerDesc discoveredServer;
ServerDescription discoveredServer;
if (ProcessResponses(socket, discoveredServer, 0)) {
observer->OnServerFound(std::move(discoveredServer));
} else {
Expand Down
9 changes: 5 additions & 4 deletions Sources/Jazz2/Multiplayer/ServerDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#undef far

#include <Containers/SmallVector.h>
#include <Containers/StaticArray.h>
#include <Containers/String.h>
#include <Containers/StringView.h>

Expand All @@ -29,7 +30,7 @@ using namespace nCine;
namespace Jazz2::Multiplayer
{
/** @brief Server description */
struct ServerDesc
struct ServerDescription
{
#ifndef DOXYGEN_GENERATING_OUTPUT
/** @brief Server endpoint */
Expand All @@ -38,7 +39,7 @@ namespace Jazz2::Multiplayer
/** @brief Server endpoint in text format */
String EndpointString;
/** @brief Server unique identifier */
std::uint8_t UniqueIdentifier[16];
StaticArray<16, std::uint8_t> UniqueIdentifier;
/** @brief Server name */
String Name;
/** @brief Game mode and flags */
Expand All @@ -63,7 +64,7 @@ namespace Jazz2::Multiplayer
{
public:
/** @brief Called when a server is discovered */
virtual void OnServerFound(ServerDesc&& desc) = 0;
virtual void OnServerFound(ServerDescription&& desc) = 0;
};

/**
Expand Down Expand Up @@ -102,7 +103,7 @@ namespace Jazz2::Multiplayer
static ENetSocket TryCreateSocket(const char* multicastAddress, ENetAddress& parsedAddress);

static void TrySendRequest(ENetSocket socket, const ENetAddress& address);
static bool ProcessResponses(ENetSocket socket, ServerDesc& discoveredServer, std::int32_t timeoutMs = 0);
static bool ProcessResponses(ENetSocket socket, ServerDescription& discoveredServer, std::int32_t timeoutMs = 0);
static bool ProcessRequests(ENetSocket socket, std::int32_t timeoutMs = 0);

static void OnClientThread(void* param);
Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/UI/Menu/ServerSelectSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace Jazz2::UI::Menu
}
}

void ServerSelectSection::OnServerFound(Multiplayer::ServerDesc&& desc)
void ServerSelectSection::OnServerFound(Multiplayer::ServerDescription&& desc)
{
for (auto& item : _items) {
if (item.Desc.EndpointString == desc.EndpointString) {
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace Jazz2::UI::Menu
}
}

ServerSelectSection::ItemData::ItemData(Multiplayer::ServerDesc&& desc)
ServerSelectSection::ItemData::ItemData(Multiplayer::ServerDescription&& desc)
: Desc(std::move(desc))
{
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Jazz2/UI/Menu/ServerSelectSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace Jazz2::UI::Menu
void OnDrawClipped(Canvas* canvas) override;
void OnTouchEvent(const TouchEvent& event, Vector2i viewSize) override;

void OnServerFound(Multiplayer::ServerDesc&& desc) override;
void OnServerFound(Multiplayer::ServerDescription&& desc) override;

private:
struct ItemData {
Multiplayer::ServerDesc Desc;
Multiplayer::ServerDescription Desc;
float Y;

ItemData(Multiplayer::ServerDesc&& desc);
ItemData(Multiplayer::ServerDescription&& desc);
};

static constexpr std::int32_t ItemHeight = 20;
Expand Down
2 changes: 1 addition & 1 deletion Sources/nCine/Base/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace nCine
/// Faster but less uniform version of `real()`
float FastFloat(float min, float max) noexcept;

/// Gnerates a 128-bit unique UUID
/// Gnerates a 128-bit unique identifier
void Uuid(Containers::StaticArrayView<16, std::uint8_t> result);

template<class T>
Expand Down

0 comments on commit a33d935

Please sign in to comment.