MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
anonymous_namespace{main.cpp}::HighScores Class Reference

Public Member Functions

void add (std::string name, int score)
void add (std::string name, int score)
void addScore (const std::string &name, int shots)
 HighScores (std::filesystem::path file_path)
 HighScores (std::filesystem::path file_path)
 HighScores (std::string filePath)
const std::vector< ScoreEntry > & list () const
const std::vector< ScoreEntry > & list () const
const std::vector< Score > & list () const
bool qualifies (int score) const
bool qualifies (int score) const
bool qualifies (int shots) const
void write () const
 ~HighScores ()

Detailed Description

Definition at line 153 of file main.cpp.

Constructor & Destructor Documentation

◆ HighScores() [1/3]

anonymous_namespace{main.cpp}::HighScores::HighScores ( std::filesystem::path file_path)
inlineexplicit

Definition at line 155 of file main.cpp.

155: file_path(std::move(file_path)) { load(); }

◆ HighScores() [2/3]

anonymous_namespace{main.cpp}::HighScores::HighScores ( std::filesystem::path file_path)
inlineexplicit

Definition at line 104 of file main.cpp.

104: file_path(std::move(file_path)) { load(); }

◆ HighScores() [3/3]

anonymous_namespace{main.cpp}::HighScores::HighScores ( std::string filePath)
inlineexplicit

Definition at line 155 of file main.cpp.

155: filePath(std::move(filePath)) { read(); }

◆ ~HighScores()

anonymous_namespace{main.cpp}::HighScores::~HighScores ( )
inline

Definition at line 157 of file main.cpp.

Member Function Documentation

◆ add() [1/2]

void anonymous_namespace{main.cpp}::HighScores::add ( std::string name,
int score )
inline

Definition at line 157 of file main.cpp.

157 {
158 normalize(name);
159 entries.push_back({std::move(name), score});
160 sortAndTrim();
161 save();
162 }

◆ add() [2/2]

void anonymous_namespace{main.cpp}::HighScores::add ( std::string name,
int score )
inline

Definition at line 106 of file main.cpp.

106 {
107 normalize(name);
108 entries.push_back({std::move(name), score});
109 sortAndTrim();
110 save();
111 }

◆ addScore()

void anonymous_namespace{main.cpp}::HighScores::addScore ( const std::string & name,
int shots )
inline

Definition at line 159 of file main.cpp.

159 {
160 entries.push_back({name, shots});
161 sort();
162 if (entries.size() > 10) {
163 entries.resize(10);
164 }
165 }

◆ list() [1/3]

const std::vector< ScoreEntry > & anonymous_namespace{main.cpp}::HighScores::list ( ) const
inlinenodiscard

Definition at line 171 of file main.cpp.

171{ return entries; }

◆ list() [2/3]

const std::vector< ScoreEntry > & anonymous_namespace{main.cpp}::HighScores::list ( ) const
inlinenodiscard

Definition at line 120 of file main.cpp.

120{ return entries; }

◆ list() [3/3]

const std::vector< Score > & anonymous_namespace{main.cpp}::HighScores::list ( ) const
inlinenodiscard

Definition at line 174 of file main.cpp.

174{ return entries; }

◆ qualifies() [1/3]

bool anonymous_namespace{main.cpp}::HighScores::qualifies ( int score) const
inlinenodiscard

Definition at line 164 of file main.cpp.

164 {
165 if (entries.size() < max_scores) {
166 return true;
167 }
168 return score > entries.back().score;
169 }
constexpr int max_scores
Definition main.cpp:33

◆ qualifies() [2/3]

bool anonymous_namespace{main.cpp}::HighScores::qualifies ( int score) const
inlinenodiscard

Definition at line 113 of file main.cpp.

113 {
114 if (entries.size() < max_scores) {
115 return true;
116 }
117 return score > entries.back().score;
118 }

◆ qualifies() [3/3]

bool anonymous_namespace{main.cpp}::HighScores::qualifies ( int shots) const
inlinenodiscard

Definition at line 167 of file main.cpp.

167 {
168 if (entries.size() < 10) {
169 return true;
170 }
171 return shots < entries.back().shots;
172 }

◆ write()

void anonymous_namespace{main.cpp}::HighScores::write ( ) const
inline

Definition at line 176 of file main.cpp.

176 {
177 std::ofstream out(filePath);
178 if (!out.is_open()) {
179 return;
180 }
181 for (const auto &entry : entries) {
182 out << entry.name << ':' << entry.shots << '\n';
183 }
184 }

The documentation for this class was generated from the following files: