diff options
author | rtk0c <[email protected]> | 2022-05-22 23:05:03 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-22 23:05:03 -0700 |
commit | 123f741e3f5374b93ac39887b62bfa0d66762ae2 (patch) | |
tree | cedbc4b2dd87e2caadfde48a0c12a0336672bdd3 /source/Utils.cpp | |
parent | c568f0a8c9f0aef00c770b494ee1ff3a89ab48de (diff) |
Changeset: 36 Add basic machinery for levels (no saving/loading yet)
Diffstat (limited to 'source/Utils.cpp')
-rw-r--r-- | source/Utils.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/Utils.cpp b/source/Utils.cpp index 1062843..53b3863 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -73,3 +73,15 @@ bool Utils::LineContains(glm::ivec2 p1, glm::ivec2 p2, glm::ivec2 candidate) { bool Utils::IsColinear(glm::ivec2 p1, glm::ivec2 p2) { return p1.x == p2.x || p1.y == p2.y; } + +std::string Utils::MakeRandomNumberedName(const char* tag) { + int n = std::rand(); +#define RNG_NAME_PATTERN "Unnamed %s #%d", tag, n + // NOTE: does not include null-terminator + int size = snprintf(nullptr, 0, RNG_NAME_PATTERN); + std::string result; + result.resize(size); // std::string::resize handles storage for null-terminator alreaedy + snprintf(result.data(), size, RNG_NAME_PATTERN); +#undef RNG_NAME_PATTERN + return result; +} |