28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/limits.h>
32 #include <sifteo/macros.h>
33 #include <sifteo/math.h>
34 #include <sifteo/array.h>
89 static const _SYSCubeID
NUM_SLOTS = _SYS_NUM_CUBE_SLOTS;
92 static const _SYSCubeID
UNDEFINED = _SYS_CUBE_ID_INVALID;
110 operator _SYSCubeID()
const {
121 _SYSCubeIDVector
bit()
const {
122 return 0x80000000 >> sys;
147 v.value = _SYS_getAccel(*
this);
148 return vec(v.x, v.y, v.z);
157 return _SYS_isTouching(*
this);
170 return _SYS_getCubeHWID(*
this);
184 _SYS_setVideoBuffer(*
this, 0);
196 _SYS_setMotionBuffer(*
this, 0);
215 return _SYS_cubeBatteryLevel(*
this) / float(_SYS_BATTERY_MAX);
228 CubeID operator ++() {
return ++sys; }
229 CubeID operator ++(
int) {
return sys++; }
230 CubeID operator --() {
return --sys; }
231 CubeID operator --(
int) {
return sys--; }
245 operator _SYSCubeIDVector()
const {
300 result.words[0] = _SYS_getConnectedCubes();
330 operator _SYSNeighborID()
const {
336 return sys < _SYS_NUM_CUBE_SLOTS;
341 return (sys & _SYS_NEIGHBOR_TYPE_MASK) == _SYS_NEIGHBOR_BASE;
346 return sys == _SYS_NEIGHBOR_NONE;
369 _SYSNeighborState sys;
385 operator _SYSNeighborState& () {
398 sys.value = _SYS_getNeighbors(cube);
406 return sys.sides[side];
444 if (sys.sides[side] == cube)
NeighborID()
Default constructor. Initializes an empty NeighborID.
Definition: cube.h:320
CubeSet()
Create an empty CubeSet.
Definition: cube.h:253
static const _SYSCubeID NUM_SLOTS
The maximum number of distinct CubeIDs.
Definition: cube.h:89
float batteryLevel() const
Get this cube's battery level.
Definition: cube.h:213
An unordered set of cubes.
Definition: cube.h:242
Byte3 accel() const
Return the physical accelerometer state, as a signed byte-vector.
Definition: cube.h:144
static CubeSet connected()
Return a CubeSet containing all connected cubes which are visible to the current application.
Definition: cube.h:298
bool hasCubeAt(Side side) const
Is there a cube at this side? This is equivalent to calling isCube() on the result of neighborAt()...
Definition: cube.h:431
CubeID cube() const
Convert this NeighborID to a CubeID.
Definition: cube.h:354
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
Neighborhood()
Default constructor. Leaves the Neighborhood uninitialized.
Definition: cube.h:374
bool hasNeighborAt(Side side) const
Is there a neighbor at this side? This is equivalent to calling !isEmpty() on the result of neighborA...
Definition: cube.h:423
CubeID(_SYSCubeID sys)
Initialize a CubeID with a concrete slot value. Slots are numbered from 0 to NUM_SLOTS - 1...
Definition: cube.h:105
void unpair() const
Remove the persistent pairing association between this cube and the current Base. ...
Definition: cube.h:223
Side
An enumeration which names the four sides of a Sifteo cube.
Definition: cube.h:54
uint64_t hwID() const
Return the cube's unique 64-bit hardware ID. This ID uniquely identifies the cube that this slot is p...
Definition: cube.h:168
void setMask(uint32_t mask)
Setter for the underlying bitmask.
Definition: cube.h:280
bool isEmpty() const
Is there nothing neighbored at all?
Definition: cube.h:345
A lightweight identifier for one neighbored object.
Definition: cube.h:314
Side sideOf(CubeID cube) const
Search for a CubeID in this Neighborhood.
Definition: cube.h:442
bool isTouching() const
Is this cube being touched right now? Return the current state of the touch sensor.
Definition: cube.h:155
CubeSet(CubeID begin, CubeID end)
Create a new CubeSet with a range of cubes.
Definition: cube.h:263
#define CUBE_ALLOCATION
Compile-time cube limit for the current application.
Definition: limits.h:54
Nil value (-1)
Definition: cube.h:60
Bottom side (Y+)
Definition: cube.h:57
NeighborID(_SYSNeighborID sys)
Initialize a NeighborID with a concrete value.
Definition: cube.h:325
A lightweight identifier for one Sifteo cube.
Definition: cube.h:85
_SYSCubeID PCubeID
Alternate POD type for CubeID storage.
Definition: cube.h:70
_SYSCubeIDVector bit() const
Return the _SYSCubeIDVector bit associated with this ID.
Definition: cube.h:121
Neighborhood(_SYSNeighborState sys)
Initialize a Neighborhood from a low-level _SYSNeighborState object.
Definition: cube.h:379
CubeID cubeAt(Side side) const
Return the neighbor at a particular side, as a CubeID.
Definition: cube.h:415
CubeSet(CubeID cube)
Create a CubeSet with a single CubeID in it.
Definition: cube.h:256
A Neighborhood is a description of all neighbors for a single cube, packed into a small value...
Definition: cube.h:368
CubeID()
Default constructor. By default, a CubeID is initialized to a special Undefined value. This value can be tested for with the isDefined() predicate.
Definition: cube.h:99
Left side (X-)
Definition: cube.h:56
Right side (X+)
Definition: cube.h:58
CubeSet(const BitArray< _SYS_NUM_CUBE_SLOTS > &bits)
Implicit conversion from a BitArray of the correct size.
Definition: cube.h:250
NeighborID neighborAt(Side side) const
Return the neighbor at a particular side, as a NeighborID.
Definition: cube.h:404
Total number of sides (4)
Definition: cube.h:59
iterator end() const
Return an STL-style iterator for this array.
Definition: array.h:499
bool isCube() const
Is this neighbor a cube?
Definition: cube.h:335
Top side (Y-)
Definition: cube.h:55
void detachMotionBuffer() const
Detach any motion buffer which was previously attached to this cube.
Definition: cube.h:194
void detachVideoBuffer() const
Detach any video buffer which was previously attached to this cube.
Definition: cube.h:181
bool isBase() const
Is this neighbor a base?
Definition: cube.h:340
iterator begin() const
Return an STL-style iterator for this array.
Definition: array.h:492
static const _SYSCubeID UNDEFINED
A reserved ID, used to mark undefined CubeIDs.
Definition: cube.h:92
bool isDefined() const
Is this a CubeID that was initialized with a valid slot number, and not one that was initialized as u...
Definition: cube.h:129
Neighborhood(CubeID cube)
Get a Neighborhood representing the physical neighbors for a cube.
Definition: cube.h:396
Vector2< T > vec(T x, T y)
Create a Vector2, from a set of (x,y) coordinates.
Definition: math.h:658
uint32_t mask() const
Getter for the underlying bitmask.
Definition: cube.h:270
A fixed-size array of bits, with compact storage and fast iteration.
Definition: array.h:231