From 123f741e3f5374b93ac39887b62bfa0d66762ae2 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 22 May 2022 23:05:03 -0700 Subject: Changeset: 36 Add basic machinery for levels (no saving/loading yet) --- source/Utils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/Utils.cpp') 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; +} -- cgit v1.2.3-70-g09d2