feat: started resource management & dice

This commit is contained in:
Sara Gerretsen 2025-10-27 20:30:07 +01:00
parent 3a5b55cc06
commit 451c71254c
6 changed files with 141 additions and 4 deletions

36
src/dice_data.cpp Normal file
View file

@ -0,0 +1,36 @@
#include "dice_data.h"
#include <cstddef>
#include <cstring>
namespace active_dice {
constexpr size_t maxActiveDice{16};
Die activeDice[maxActiveDice];
size_t numActiveDice{0};
void Add(Die die) {
if(numActiveDice < maxActiveDice) {
activeDice[numActiveDice] = die;
++numActiveDice;
}
}
void Remove(size_t at) {
if(at >= numActiveDice) {
return;
}
if(at < numActiveDice - 1) {
std::memmove(activeDice + at, activeDice + at + 1, numActiveDice - at);
}
--numActiveDice;
}
Die Get(size_t at) {
if(at < numActiveDice) {
return activeDice[at];
} else return D_COIN;
}
size_t Count() {
return numActiveDice;
}
}