-
Notifications
You must be signed in to change notification settings - Fork 16
Add player count to scoreboard #274
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
Conversation
|
I do not really like its verbosity. I think it should have a console command. |
I don't think it's verbose at all. I've also tested with bighud on and off, all gamemodes - in no case is it even close to in danger of getting cut off. IMO this is a straight improvement over the original.
I'm not opposed to it being associated with a console command as toggle, but I also don't think it's necessary. Will wait to hear rafalh's take on this point - I'd be happy to tie it to a console command if he wants it that way. |
When I mentioned my scoreboard is altered (it is old code) it was about this ugly logo 😊. Moreover I tested a few variations and |
| game_type_name = rf::strings::team_deathmatch; | ||
| rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_type_name); | ||
| int num_players = rf::multi_num_players(); | ||
| std::string player_count_str = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could number of heap allocations be reduced? game_type_name don't have to be an std::string, it could be const char* or std::string_view. The string used for concatenation could have reserved memory before concatenation.
This code runs every frame so it should be fast and allocations are generally considered slow and can lead to micro-stutters. Also please consider using std::format_to
| std::string player_count_str = | ||
| " | " + std::to_string(num_players) + (num_players > 1 ? " PLAYERS" : " PLAYER"); | ||
|
|
||
| std::string game_type_name = (game_type == rf::NG_TYPE_DM) ? rf::strings::deathmatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like double ternary operator. Why did you change it? What if we added a forth game mode? It would look terrible.
Not to mention formatting is weird.
| int num_players = rf::multi_num_players(); | ||
| std::string player_count_str = | ||
| " | " + std::to_string(num_players) + (num_players > 1 ? " PLAYERS" : " PLAYER"); | ||
|
|
||
| std::string game_type_name = (game_type == rf::NG_TYPE_DM) ? rf::strings::deathmatch | ||
| : (game_type == rf::NG_TYPE_CTF) ? rf::strings::capture_the_flag | ||
| : rf::strings::team_deathmatch; | ||
|
|
||
| game_type_name += player_count_str; | ||
|
|
||
| rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_type_name.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I completely rewrote everything. It now ignores browsers. 1 allocation.
| int num_players = rf::multi_num_players(); | |
| std::string player_count_str = | |
| " | " + std::to_string(num_players) + (num_players > 1 ? " PLAYERS" : " PLAYER"); | |
| std::string game_type_name = (game_type == rf::NG_TYPE_DM) ? rf::strings::deathmatch | |
| : (game_type == rf::NG_TYPE_CTF) ? rf::strings::capture_the_flag | |
| : rf::strings::team_deathmatch; | |
| game_type_name += player_count_str; | |
| rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_type_name.c_str()); | |
| const std::string_view game_type_name = std::invoke([game_type] { | |
| if (game_type == rf::NG_TYPE_DM) { | |
| return rf::strings::deathmatch; | |
| } else if (game_type == rf::NG_TYPE_CTF) { | |
| return rf::strings::capture_the_flag; | |
| } else { | |
| return rf::strings::team_deathmatch; | |
| } | |
| }); | |
| int32_t num_players = 0; | |
| for (rf::Player& player : SinglyLinkedList{rf::player_list}) { | |
| if (!get_player_additional_data(&player).is_browser) { | |
| ++num_players; | |
| } | |
| } | |
| const std::string game_info = std::format( | |
| "{} | {} {}", | |
| game_type_name, | |
| num_players, | |
| num_players > 1 ? "PLAYERS" : "PLAYER" | |
| ); | |
| rf::gr::string_aligned(rf::gr::ALIGN_CENTER, x_center, cur_y, game_info.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not opposed to the rewrite, I am opposed to excluding browsers from this calculation, though, at least as long as they appear on the scoreboard without any clear identifier.
Having the count at the top of the scoreboard less than the number of names shown as players on the scoreboard would be very confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#306 paves the way for introducing an identifier for browser clients. Let's see what rafalh says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with Goober that without a clear indication what we count it will be confusing to skip browsers.
Still, even if we add some image besides browser clients it will still be a bit confusing if people see a different count in server list screen and after joining the server. Maybe we should display two counters: number of all players, and number of browsers or add some small hint that the counter does not include browsers?
Anyway why we want to skip browsers? If we care about players actively playing the game AFK players could also be treated differently?
I think we should prevent scope-creep in this PR and leave the browsers issue to another one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the proposed code, it looks ok, but I would prefer a standalone function over std::invoke with a lambda here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An idea could be to display a number of player slots occupied and separately, a number of currently spawned players?
I don't know how to appropriately communicate that on the UI though - there's not a lot of room to work with.
Agreed though that scope creep should be prevented here. Anything beyond displaying a number of occupied player slots should be out of scope for this simple change IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it could be num_spawned_players/num_players PLAYING e.g. 5/8 PLAYING.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, although I'm not sure if counting alive people "as is" is the best approach because people spawn and die all the time...
to be honest i'm not sure if clobbering panel with multiple statistics is worth it considering it can reduce readability. For me it's okay to just display total player count which in most cases is enough, but if you add "playing" I will accept that too


Adds the current server player count to the scoreboard for all gamemodes as shown in the screenshots below.
Resolves #27