XJ music engine
1.9.6
In-game runtime engine for XJ music.
|
#include <MarbleBag.h>
Classes | |
class | Group |
Public Member Functions | |
MarbleBag ()=default | |
MarbleBag (const MarbleBag &other) | |
MarbleBag & | operator= (const MarbleBag &other) |
UUID | pick () |
void | addAll (int phase, const std::map< UUID, int > &toAdd) |
void | add (int phase, const UUID &id) |
void | add (int phase, const UUID &id, int qty) |
int | size () const |
std::string | toString () const |
bool | empty () const |
bool | isPresent () const |
std::optional< UUID > | pickPhase (int phase) |
Static Public Member Functions | |
static int | quickPick (int total) |
static bool | quickBooleanChanceOf (float probability) |
Bag of Marbles
Choices should be random https://github.com/xjmusic/xjmusic/issues/291
The current implementation literally places one of each object in a bag in memory. However, this is inefficient compared to:
Marble bag has phases https://github.com/xjmusic/xjmusic/issues/291
This will consolidate the logic around "choose this if available, else that, else that" XJ’s marble bag is actually divided into phases. When a marble is put into the bag, it is assigned a phase. For example, if the phase 1 bag contains any marbles, we will pick from only the phase 1 bag and skip phases 2 and beyond. This supports functionality such as “XJ always chooses a directly-bound program or instrument when available”
|
default |
Construct a new Marble Bag
MarbleBag::MarbleBag | ( | const MarbleBag & | other | ) |
Construct a new Marble Bag from a copy of another Marble Bag
void MarbleBag::add | ( | int | phase, |
const UUID & | id | ||
) |
Add one marble to the bag; increments the count of this marble +1
phase | of selection |
id | of the marble to add |
void MarbleBag::add | ( | int | phase, |
const UUID & | id, | ||
int | qty | ||
) |
Add a quantity of marbles to the bag; increments the count of the specified marble by the specified quantity.
phase | of selection |
id | of the marble to add |
qty | quantity of this marble to add |
void MarbleBag::addAll | ( | int | phase, |
const std::map< UUID, int > & | toAdd | ||
) |
Add all marbles from another object mapping marble -> quantity
phase | of selection |
toAdd | map of marble id to quantity |
bool MarbleBag::empty | ( | ) | const |
bool MarbleBag::isPresent | ( | ) | const |
Assignment operator
other | marble bag |
UUID MarbleBag::pick | ( | ) |
std::optional< UUID > MarbleBag::pickPhase | ( | int | phase | ) |
Pick a marble from the specified phase
phase | from which to pick a marble |
|
static |
Make a tremendously random boolean selection based on probability
probability | 0 <= n < limit |
|
static |
Quick pick an integer from 0 to total - 1
int MarbleBag::size | ( | ) | const |
Number of marbles in the bag
std::string MarbleBag::toString | ( | ) | const |
Display as string