载入中...
搜索中...
未找到
Params.cpp
浏览该文件的文档.
1#include "procgen/Params.h"
2
3#include <cstdlib>
4
5namespace eve::procgen {
6
7void Params::setSeed(uint32_t seed) { seed_ = seed; }
8uint32_t Params::getSeed() const { return seed_; }
9
11 width_ = width > 0 ? width : 1;
12 height_ = height > 0 ? height : 1;
13}
14int Params::getWidth() const { return width_; }
15int Params::getHeight() const { return height_; }
16
17void Params::setInt(const std::string &key, int value) { values_[key] = std::to_string(value); }
18void Params::setFloat(const std::string &key, float value) { values_[key] = std::to_string(value); }
19void Params::setString(const std::string &key, const std::string &value) { values_[key] = value; }
20
21bool Params::has(const std::string &key) const { return values_.find(key) != values_.end(); }
22
23int Params::getInt(const std::string &key, int defaultValue) const {
24 auto it = values_.find(key);
25 if (it == values_.end()) return defaultValue;
26 char *end = nullptr;
27 long v = std::strtol(it->second.c_str(), &end, 10);
28 if (end == it->second.c_str()) return defaultValue;
29 return int(v);
30}
31
32float Params::getFloat(const std::string &key, float defaultValue) const {
33 auto it = values_.find(key);
34 if (it == values_.end()) return defaultValue;
35 char *end = nullptr;
36 float v = std::strtof(it->second.c_str(), &end);
37 if (end == it->second.c_str()) return defaultValue;
38 return v;
39}
40
41std::string Params::getString(const std::string &key, const std::string &defaultValue) const {
42 auto it = values_.find(key);
43 return it == values_.end() ? defaultValue : it->second;
44}
45
46} // namespace eve::procgen
uint32_t seed
std::string value
float height
Definition Grass.cpp:235
int width
int v
uint32_t getSeed() const
Definition Params.cpp:8
void setSize(int width, int height)
Definition Params.cpp:10
void setInt(const std::string &key, int value)
Definition Params.cpp:17
int getHeight() const
Definition Params.cpp:15
int getWidth() const
Definition Params.cpp:14
bool has(const std::string &key) const
Definition Params.cpp:21
float getFloat(const std::string &key, float defaultValue) const
Definition Params.cpp:32
void setSeed(uint32_t seed)
Definition Params.cpp:7
void setFloat(const std::string &key, float value)
Definition Params.cpp:18
std::string getString(const std::string &key, const std::string &defaultValue) const
Definition Params.cpp:41
int getInt(const std::string &key, int defaultValue) const
Definition Params.cpp:23
void setString(const std::string &key, const std::string &value)
Definition Params.cpp:19