group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
PlayerName.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <array>
7#include <cstddef>
8#include <cstring>
9#include <type_traits>
10
28{
29 static constexpr std::size_t k_maxLen = 23;
30
31 std::array<char, k_maxLen + 1> name{};
32 bool isCustom = false;
33
36 void set(const char* src)
37 {
38 if (src == nullptr) {
39 name[0] = '\0';
40 return;
41 }
42 std::size_t i = 0;
43 for (; i < k_maxLen && src[i] != '\0'; ++i)
44 name[i] = src[i];
45 name[i] = '\0';
46 }
47
49 [[nodiscard]] const char* c_str() const { return name.data(); }
50
52 [[nodiscard]] bool empty() const { return name[0] == '\0'; }
53};
54
55static_assert(std::is_trivially_copyable_v<PlayerName>,
56 "PlayerName must stay trivially copyable for the existing snapshot serializer.");
Replicated player display name.
Definition PlayerName.hpp:28
static constexpr std::size_t k_maxLen
Definition PlayerName.hpp:29
void set(const char *src)
Copy a NUL-terminated source into the bounded buffer.
Definition PlayerName.hpp:36
bool isCustom
True once the player picks their own name.
Definition PlayerName.hpp:32
std::array< char, k_maxLen+1 > name
NUL-terminated UTF-8. All zeros = unset.
Definition PlayerName.hpp:31
const char * c_str() const
Read the name as a C string. Always NUL-terminated.
Definition PlayerName.hpp:49
bool empty() const
Whether this nickname slot has any text in it.
Definition PlayerName.hpp:52