Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a spawned player count to the scoreboard #316

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ Version 1.9.0 (not released yet)
[@GooberRF](https://github.com/GooberRF)
- Fix crash when `verify_level` command is run without a level being loaded
- Fix cockpit not rendering for any jeeps after the first one entered each level load
- Add current server player count to scoreboard
- Add `server_password` command
- Add `$DF CTF Flag Return Time` option in dedicated server config
- Add mod name to main menu
- Make value of `spectate_mode_minimal_ui` persist between game launches
- Add `version` command

[@is-this-c](https://github.com/is-this-c)
- Support `©` in TrueType fonts
- Support `©` and `•` in TrueType fonts
- Improve frag message format
- Search command descriptions in `.` command
- Improve PF network protocol compatibility
- Add a spawned player count to the scoreboard

[@Mystyle-48](https://github.com/Mystyle-48)
- Simplify installation detection in setup and launcher
Expand Down
1 change: 1 addition & 0 deletions game_patch/graphics/gr_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ GrNewFont::GrNewFont(std::string_view name) :
static std::pair<int, int> win_1252_char_ranges[]{
{0x20, 0x7E},
{0x8C, 0x8C},
{0x95, 0x95},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work if someone plays with resolution 1024x768 or less? Do we always use TTF font for that header? If not how separator will look like in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it will not render for the small hud I think. But does it really matter?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I sometimes use that resolution myself to test things in window. It can't crash, that's obvious. But it would be nice to also look good. If it looks okayish I guess we can leave it like this. Ultimately if we want to introduce more characters in the future (e.g. unicode?) we may want to fully stop using builtin fonts, then the problem will solve itself

{0x99, 0x99},
{0x9C, 0x9C},
{0x9F, 0x9F},
Expand Down
15 changes: 7 additions & 8 deletions game_patch/hud/multi_scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ int draw_scoreboard_header(int x, int y, int w, rf::NetGameType game_type, bool

// Draw Game Type name
if (!dry_run) {
const char* game_type_name;
if (game_type == rf::NG_TYPE_DM)
game_type_name = rf::strings::deathmatch;
else if (game_type == rf::NG_TYPE_CTF)
game_type_name = rf::strings::capture_the_flag;
else
game_type_name = rf::strings::team_deathmatch;
rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_type_name);
const std::string game_info = std::format(
"{} \x95 {}/{} PLAYING",
rf::multi_game_type_name(game_type),
rf::multi_num_spawned_players(),
rf::multi_num_players()
);
rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_info.c_str());
}
int font_h = rf::gr::get_font_height(-1);
cur_y += font_h + 8;
Expand Down
18 changes: 18 additions & 0 deletions game_patch/rf/multi.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#pragma once

#include <algorithm>
#include <patch_common/MemUtils.h>
#include "localize.h"
#include "player/player.h"
#include "os/vtypes.h"
#include "os/timestamp.h"
#include "os/string.h"
#include "os/array.h"
#include <common/utils/list-utils.h>

namespace rf
{
Expand Down Expand Up @@ -88,6 +92,16 @@ namespace rf
NG_TYPE_TEAMDM = 2,
};

inline std::string_view multi_game_type_name(const NetGameType game_type) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you put those functions (multi_game_type_name and multi_num_spawned_players) into rf directory? This directory is supposed to only contain addresses/type definitions for RF. Please move them to multi_scoreboard.cpp

Copy link
Contributor Author

@is-this-c is-this-c Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rf should be like an sdk or library e.g. if rf were a crate it would contain these small and simple functions. These functions should be expected in rf from a developer's point of view because it is intuitive and consistent. It also works well with intellisense. They do not properly belong to the implicit namespace dash.

if (game_type == NG_TYPE_DM) {
return std::string_view{strings::deathmatch};
} else if (game_type == NG_TYPE_CTF) {
return std::string_view{strings::capture_the_flag};
} else {
return std::string_view{strings::team_deathmatch};
}
};

enum NetGameFlags
{
NG_FLAG_DEBUG_SCOREBOARD = 0x1,
Expand Down Expand Up @@ -151,6 +165,10 @@ namespace rf
static auto& multi_tdm_get_red_team_score = addr_as_ref<int()>(0x004828F0); // returns ubyte in vanilla game
static auto& multi_tdm_get_blue_team_score = addr_as_ref<int()>(0x00482900); // returns ubyte in vanilla game
static auto& multi_num_players = addr_as_ref<int()>(0x00484830);
[[nodiscard]] inline int32_t multi_num_spawned_players() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a name multi_num_alive_players, because alive is opposite to dead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True but no one speaks like that. It is not idiomatic.

const auto f = [] (auto& p) { return !player_is_dead(&p) && !player_is_dying(&p); };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f is not very descriptive, maybe is_alive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not want to split this line. It works better in a single line imo.

return std::ranges::count_if(SinglyLinkedList{player_list}, f);
}
static auto& multi_kick_player = addr_as_ref<void(Player *player)>(0x0047BF00);
static auto& multi_ban_ip = addr_as_ref<void(const NetAddr& addr)>(0x0046D0F0);
static auto& multi_set_next_weapon = addr_as_ref<void(int weapon_type)>(0x0047FCA0);
Expand Down