XJ music engine  1.9.6
In-game runtime engine for XJ music.
Classes | Public Member Functions | Static Public Member Functions | List of all members
XJ::MarbleBag Class Reference

#include <MarbleBag.h>

Classes

class  Group
 

Public Member Functions

 MarbleBag ()=default
 
 MarbleBag (const MarbleBag &other)
 
MarbleBagoperator= (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< UUIDpickPhase (int phase)
 

Static Public Member Functions

static int quickPick (int total)
 
static bool quickBooleanChanceOf (float probability)
 

Detailed Description

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”

Constructor & Destructor Documentation

◆ MarbleBag() [1/2]

XJ::MarbleBag::MarbleBag ( )
default

Construct a new Marble Bag

◆ MarbleBag() [2/2]

MarbleBag::MarbleBag ( const MarbleBag other)

Construct a new Marble Bag from a copy of another Marble Bag

Member Function Documentation

◆ add() [1/2]

void MarbleBag::add ( int  phase,
const UUID id 
)

Add one marble to the bag; increments the count of this marble +1

Parameters
phaseof selection
idof the marble to add

◆ add() [2/2]

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.

Parameters
phaseof selection
idof the marble to add
qtyquantity of this marble to add

◆ addAll()

void MarbleBag::addAll ( int  phase,
const std::map< UUID, int > &  toAdd 
)

Add all marbles from another object mapping marble -> quantity

Parameters
phaseof selection
toAddmap of marble id to quantity

◆ empty()

bool MarbleBag::empty ( ) const
Returns
true if the marble bag is completely empty

◆ isPresent()

bool MarbleBag::isPresent ( ) const
Returns
true if there are any marbles in the bag

◆ operator=()

MarbleBag& XJ::MarbleBag::operator= ( const MarbleBag other)
inline

Assignment operator

Parameters
othermarble bag
Returns
marble bag

◆ pick()

UUID MarbleBag::pick ( )
Returns
{std::string} marble picked at random from bag

◆ pickPhase()

std::optional< UUID > MarbleBag::pickPhase ( int  phase)

Pick a marble from the specified phase

Parameters
phasefrom which to pick a marble
Returns
marble if available

◆ quickBooleanChanceOf()

bool MarbleBag::quickBooleanChanceOf ( float  probability)
static

Make a tremendously random boolean selection based on probability

Parameters
probability0 <= n < limit
Returns
random integer n, where 0 <= n < limit

◆ quickPick()

int MarbleBag::quickPick ( int  total)
static

Quick pick an integer from 0 to total - 1

Returns
The picked integer

◆ size()

int MarbleBag::size ( ) const

Number of marbles in the bag

Returns
{number}

◆ toString()

std::string MarbleBag::toString ( ) const

Display as string


The documentation for this class was generated from the following files: