topology.inc
topology.inc
CPP1/****h* PawnLibs/topology2 * Description3 * Topology provides a set of interfaces to detect how the modules are4 * connected to each other and how a cube is oriented in the space.5 *6 * Cube has 8 modules and 6 faces. Module is a piece of cube, which has 37 * screens. Each cube face has 4 screens and a space orientation8 * characteristic (up, front, left, etc). Thereby each screen in an entire9 * cube system can be addressed in two ways: statically and dynamically (or in10 * other words: physical and logical "coordinates").11 *12 * TBD: figure of disassembled cube with labels should be embedded here13 *14 * Facelet is a static address of the screen. It is a pair of the module ID15 * and the screen number. Module ID determined during the cube startup and16 * based on the module hardware ID and how big it is comparing with other17 * modules in a system. Screen number corresponds to the order number of the18 * display on a bus. Therefore facelet address represents physical19 * "coordinates" of the particular screen and guarantee to be immutable for20 * that particular hardware setup.21 *22 * Place is a dynamic address of the screen. It is a pair of the face number23 * and the screen position on that face. Faces are always have the same24 * relationship one to each other. Basically their numbers always corresponds25 * to the screen numbers of a master module (module with ID 0) and its26 * diagonal counterpart. Positions on the face are always enumerated in the27 * same order. Positions order based on the orientation mode, there are 3 of28 * them:29 * * menu - default, position on the face enumerates counter clockwise from30 * the master module or its diagonal counterpart31 * * splash - TBD: check32 * * gravity - position on side faces enumerates from a top left module, TBD:33 * check34 * After each cube permutation places are recalculated for the entire system.35 * One can think of a place as a logical "coordinates" on the cube surface.36 *37 * Actually topology purpose is a function from the set of facelets to the set38 * of places. Topology assigns each facelet to the exactly one place and vice39 * versa. Several interfaces provided for convenient application development.40 ******/4142/****d* PawnLibs/topology/TOPOLOGY_FACES_MAX43 * Summary44 * How many faces the cube has.45 * Synopsis46 */47#define TOPOLOGY_FACES_MAX 648/******/4950/****d* PawnLibs/topology/TOPOLOGY_POSITIONS_MAX51 * Summary52 * How many screens there are on a single cube face.53 * Synopsis54 */55#define TOPOLOGY_POSITIONS_MAX 456/******/5758/****s* PawnLibs/topology/TOPOLOGY_FACELET59 * Summary60 * Array with named fields which represents a single facelet.61 * Synopsis62 */63#define TOPOLOGY_FACELET [ .module, .screen ]64/*65 * Description66 * Fields:67 * * module - an ID of the module on which facelet is located68 * * screen - a number of the module screen which corresponds to the facelet69 * See also70 * * TOPOLOGY_FACELET_INFO71 * * TOPOLOGY_getAdjacentFacelet()72 * * TOPOLOGY_getPlace()73 * * TOPOLOGY_getOppositeFacelet()74 * * TOPOLOGY_getAngle()75 * * TOPOLOGY_getFaceletOrientation()76 ******/7778/****s* PawnLibs/topology/TOPOLOGY_FACELET_INFO79 * Summary80 * Array with named fields with meta information about a single facelet.81 * Synopsis82 */83#define TOPOLOGY_FACELET_INFO [ TOPOLOGY_FACELET, .connected ]84/*85 * Description86 * Fields:87 * * module - an ID of the module on which the facelet is located88 * * screen - a number of the module screen which corresponds to the facelet89 * * connected - connection status, depends on the context90 * See also91 * * TOPOLOGY_FACELET92 * * TOPOLOGY_getFacelet()93 * * TOPOLOGY_getAdjacentFacelet()94 * * TOPOLOGY_getOppositeFacelet()95 ******/9697/****s* PawnLibs/topology/TOPOLOGY_PLACE98 * Summary99 * Array with named fields which represents screens place on the cube surface.100 * Synopsis101 */102#define TOPOLOGY_PLACE [ .face, .position ]103/*104 * Description105 * Fields:106 * * face - a face number on which screen is located107 * * position - a position on the face on which screen is located108 * See also109 * * TOPOLOGY_getFacelet()110 * * TOPOLOGY_getPlace()111 * * TOPOLOGY_getPlaceOrientation()112 ******/113114/****s* PawnLibs/topology/TOPOLOGY_TWIST_INFO115 * Summary116 * Array with named fields with twist parameters.117 * Synopsis118 */119#define TOPOLOGY_TWIST_INFO [ .screen, .count, TOPOLOGY_twist: .direction ]120/*121 * Description122 * Fields:123 * * screen - a number of the screen around which a twist was detected124 * * count - how many twists happened from the application start125 * * direction - a twist direction126 * See also127 * * TOPOLOGY_twist128 * * ON_Twist()129 ******/130131/****c* PawnLibs/topology/TOPOLOGY_neighbor132 * Summary133 * Enumeration of a facelet neighbor directions.134 * Synopsis135 */136const TOPOLOGY_neighbor: {137 NEIGHBOR_SELF = 0,138 NEIGHBOR_LEFT,139 NEIGHBOR_DIAGONAL,140 NEIGHBOR_TOP,141 NEIGHBOR_RIGHT,142 NEIGHBOR_BOTTOM,143 NEIGHBOR_MAX,144};145/******/146147/****c* PawnLibs/topology/TOPOLOGY_orientation148 * Summary149 * Enumeration of a face orientations.150 * Synopsis151 */152const TOPOLOGY_orientation: {153 ORIENTATION_UP = 0,154 ORIENTATION_DOWN,155 ORIENTATION_FRONT,156 ORIENTATION_BACK,157 ORIENTATION_LEFT,158 ORIENTATION_RIGHT,159 ORIENTATION_MAX,160};161/*162 * History163 * * v5.0 - renamed from TOPOLOGY_location to the TOPOLOGY_orientation164 ******/165166/****c* PawnLibs/topology/TOPOLOGY_orientation_mode167 * Summary168 * Enumeration of an orientation modes.169 * Synopsis170 */171const TOPOLOGY_orientation_mode: {172 ORIENTATION_MODE_MENU = 0,173 ORIENTATION_MODE_GRAVITY,174 ORIENTATION_MODE_SPLASH,175 ORIENTATION_MODE_MAX,176};177/*178 * History179 * * v5.0 - renamed from TOPOLOGY_orientation to TOPOLOGY_orientation_mode180 ******/181182/****c* PawnLibs/topology/TOPOLOGY_twist183 * Summary184 * Enumeration of twist directions.185 * Synopsis186 */187const TOPOLOGY_twist: {188 TWIST_UNINDENTIFIED = 0,189 TWIST_LEFT,190 TWIST_RIGHT,191 TWIST_DOUBLE,192 TWIST_MAX,193};194/******/195196/****c* PawnLibs/topology/TOPOLOGY_reverseFaces197 * Summary198 * Array with opposite cube faces.199 * Synopsis200 */201stock const TOPOLOGY_reverseFaces { TOPOLOGY_FACES_MAX } = { 3, 5, 4, 0, 2, 1 };202/*203 * Description204 * Value at a face position corresponds its opposite face, e.g. face opposite205 * to 0 is 3 and vice versa.206 ******/207208/****e* PawnLibs/topology/ON_Twist209 * Summary210 * Twist handler.211 * Synopsis212 */213forward ON_Twist(twist[TOPOLOGY_TWIST_INFO]);214/*215 * Description216 * Public function with such signature will be called when a cube twist217 * detected.218 * Inputs219 * * twist - a twist description220 * See also221 * * TOPOLOGY_TWIST_INFO222 ******/223224/****n* PawnLibs/topology/TOPOLOGY_getAdjacentFacelet225 * Summary226 * Get a facelet neighbor in the given direction.227 * Synopsis228 */229native TOPOLOGY_getAdjacentFacelet[TOPOLOGY_FACELET_INFO](facelet[TOPOLOGY_FACELET], TOPOLOGY_neighbor: direction = NEIGHBOR_DIAGONAL);230/*231 * Description232 * Facelet can have neighbors on the same cube face or neighbors by module.233 * This function provide a neighbor of the given facelet in the given234 * direction. Connection status indicates if there is a connection between235 * modules on which given facelet and its neighbor are located.236 * Inputs237 * * facelet - a facelet which neighbor is requested238 * * direction - a direction in which neighbor is requested239 * Return value240 * Neighbor facelet in a given direction with its connection status. The241 * module ID will be MODULES_MAX and the screen number will be SCREENS_MAX in242 * case of an error (e.g. incorrect arguments or the topology malfunction).243 * See also244 * * TOPOLOGY_FACELET245 * * TOPOLOGY_FACELET_INFO246 * * MODULES_MAX247 * * SCREENS_MAX248 * * TOPOLOGY_neighbor249 ******/250251/****n* PawnLibs/topology/TOPOLOGY_getFacelet252 * Summary253 * Get a facelet located in the given place.254 * Synopsis255 */256native TOPOLOGY_getFacelet[TOPOLOGY_FACELET_INFO](place[TOPOLOGY_PLACE], TOPOLOGY_orientation_mode: mode = ORIENTATION_MODE_MENU);257/*258 * Inputs259 * * place - a place on a cube surface which corresponding facelet is260 * requested261 * * mode - the place position orientation mode262 * Return value263 * Facelet located in the given place, connection status indicates if there264 * any connection to the module on which this facelet resides. The module ID265 * will be MODULES_MAX and the screen screen will be SCREENS_MAX in case of an266 * error (e.g. incorrect arguments or the topology malfunction).267 * See also268 * * TOPOLOGY_FACELET269 * * TOPOLOGY_FACELET_INFO270 * * TOPOLOGY_PLACE271 * * MODULES_MAX272 * * SCREENS_MAX273 * * TOPOLOGY_orientation_mode274 ******/275276/****n* PawnLibs/topology/TOPOLOGY_getPlace277 * Summary278 * Get a place of the facelet.279 * Synopsis280 */281native TOPOLOGY_getPlace[TOPOLOGY_PLACE](facelet[TOPOLOGY_FACELET], TOPOLOGY_orientation_mode: mode = ORIENTATION_MODE_MENU);282/*283 * Inputs284 * * facelet - facelet which place on cube surface is requested285 * * mode - place position orientation mode286 * Return value287 * Place on cube surface where the given facelet located. Face will be288 * TOPOLOGY_FACES_MAX and position will be TOPOLOGY_POSITIONS_MAX in case of289 * an error (e.g. incorrect arguments or topology malfunction)290 * See also291 * * TOPOLOGY_FACELET292 * * TOPOLOGY_PLACE293 * * TOPOLOGY_FACES_MAX294 * * TOPOLOGY_POSITIONS_MAX295 * * TOPOLOGY_orientation_mode296 ******/297298/****n* PawnLibs/topology/TOPOLOGY_getOppositeFacelet299 * Summary300 * Get an opposite facelet located on a diagonal counterpart module.301 * Synopsis302 */303native TOPOLOGY_getOppositeFacelet[TOPOLOGY_FACELET_INFO](facelet[TOPOLOGY_FACELET]);304/*305 * Inputs306 * * facelet - a facelet for which opposite diagonal counterpart is requested307 * Return value308 * Diagonal opposite counterpart facelet. Connection status indicates if there309 * any connection to the module on which that facelet resides. The module ID310 * will be MODULES_MAX and the screen number will be SCREENS_MAX in case of an311 * error (e.g. incorrect arguments or topology malfunction).312 * See also313 * * TOPOLOGY_FACELET_INFO314 * * TOPOLOGY_FACELET315 * * MODULES_MAX316 * * SCREENS_MAX317 ******/318319/****n* PawnLibs/topology/TOPOLOGY_getAngle320 * Summary321 * Get an angle to align images on a face according to the orientation mode.322 * Synopsis323 */324native TOPOLOGY_getAngle(facelet[TOPOLOGY_FACELET], TOPOLOGY_orientation_mode: mode = ORIENTATION_MODE_MENU);325/*326 * Description327 * Display coordinates system is persistent on a module screen. Different328 * angles are needed to align images on all modules with screens on the same329 * face. This function returns the angle for the screen specified by the330 * facelet. The angle is relative to the position 0 on the same face where the331 * facelet is located in the given orientation mode.332 * Inputs333 * * facelet - a facelet for which screen an angle is requested334 * * mode - an orientation mode in which an angle is requested335 * Return value336 * Angle to align images on the same face according to the orientation mode, 0337 * in case of an error (e.g. incorrect arguments or the topology malfunction).338 * See also339 * * TOPOLOGY_FACELET340 * * TOPOLOGY_orientation_mode341 * * PawnLibs/GFX module342 ******/343344/****n* PawnLibs/topology/TOPOLOGY_getFaceletOrientation345 * Summary346 * Get a face orientation on which the given facelet resides.347 * Synopsis348 */349native TOPOLOGY_orientation: TOPOLOGY_getFaceletOrientation(facelet[TOPOLOGY_FACELET]);350/*351 * Inputs352 * * facelet - a facelet for which the face orientation is requested353 * Return value354 * Face orientation on which the given facelet resides, ORIENTATION_MAX in355 * case of an error (e.g. incorrect arguments or the topology malfunction).356 * See also357 * * TOPOLOGY_FACELET358 * * TOPOLOGY_orientation359 * History360 * * v5.0 - renamed from TOPOLOGY_getFaceletLocation() to the361 * TOPOLOGY_getFaceletOrientation()362 ******/363364/****n* PawnLibs/topology/TOPOLOGY_getPlaceOrientation365 * Summary366 * Get a face orientation on which the given place resides.367 * Synopsis368 */369native TOPOLOGY_orientation: TOPOLOGY_getPlaceOrientation(place[TOPOLOGY_PLACE]);370/*371 * Inputs372 * * place - a place for which the face orientation is requested373 * Return value374 * Face orientation on which the given place resides, ORIENTATION_MAX in case375 * of an error (e.g. incorrect arguments or the topology malfunction).376 * See also377 * * TOPOLOGY_PLACE378 * * TOPOLOGY_orientation379 * History380 * * v5.0 - renamed from TOPOLOGY_getPlaceLocation() to the381 * TOPOLOGY_getPlaceOrientation()382 ******/383384/****n* PawnLibs/topology/TOPOLOGY_getFace385 * Summary386 * Get a face number which has the given orientation.387 * Synopsis388 */389native TOPOLOGY_getFace(TOPOLOGY_orientation: orientation = ORIENTATION_UP);390/*391 * Inputs392 * * orientation - a orientation of the requested face393 * Return value394 * Face number which has the given orientation, TOPOLOGY_FACES_MAX in case of395 * an error (e.g. incorrect arguments or the topology malfunction).396 * See also397 * * TOPOLOGY_orientation398 * * TOPOLOGY_FACES_MAX399 ******/400401/****n* PawnLibs/topology/TOPOLOGY_isAssembled402 * Summary403 * Check that all modules in a system are connected to each other.404 * Synopsis405 */406native bool: TOPOLOGY_isAssembled();407/*408 * Return value409 * True if all modules in a system are connected to each other, false410 * otherwise.411 ******/412
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.