wowcore.inc
wowcore.inc
CPP1/****p* PawnLibs/wowcore/SELF_ID2 * Summary3 * An ID of the module on which application copy is running.4 * Synopsis5 */6public const SELF_ID = 0;7/******/89/****d* PawnLibs/wowcore/MODULES_MAX10 * Summary11 * How many modules there are in the assembled cube.12 * Synopsis13 */14#define MODULES_MAX 815/******/1617/****d* PawnLibs/wowcore/SCREENS_MAX18 * Summary19 * How many screens there are on the each cube module.20 * Synopsis21 */22#define SCREENS_MAX 323/******/2425/****d* PawnLibs/wowcore/SENSITIVITY_MENU_CHANGE_SCRIPT26 * Summary27 * How many shakes required to trigger an application quit. Shake is a28 * continuous significant motion which direction has been changed since the29 * previous recent significant motion.30 * Synopsis31 */32#define SENSITIVITY_MENU_CHANGE_SCRIPT 633/******/3435/****d* PawnLibs/wowcore/GAME_SAVE_SIZE36 * Summary37 * Maximum allowed size of an application save data in cells.38 * Synopsis39 */40#define GAME_SAVE_SIZE 6441/******/4243/****d* PawnLibs/wowcore/MAX_PACKET_TYPES44 * Summary45 * Maximum number of an application packet types.46 * Synopsis47 */48#define MAX_PACKET_TYPES 3249/******/5051/****d* PawnLibs/wowcore/MAX_PACKET_SIZE52 * Summary53 * Maximum size of an application packet.54 * Synopsis55 */56#define MAX_PACKET_SIZE 2857/******/5859/****s* PawnLibs/wowcore/APP_VERSION60 * Summary61 * Array with named fields describing application version.62 * Synopsis63 */64#define APP_VERSION [.major, .minor, .patch]65/*66 * Description67 * Fields:68 * * major - increment when application significantly changed69 * * minor - increment when new feature added70 * * patch - increment when bugfix shipped71 * See also72 * * getAppVersion()73 * History74 * * v6.0 - added75 ******/7677/****e* PawnLibs/wowcore/ON_Init78 * Summary79 * Initialization handler.80 * Synopsis81 */82forward ON_Init(id, size, const pkt[]);83/*84 * Description85 * Public function with such signature will be called before the application86 * loop starts. Useful for a globals initializations, e.g. generating level,87 * baking backgrounds, etc. Additionaly save data is provided.88 * Inputs89 * * id - an id of the save data90 * * size - size of the save data in cells91 * * pkt[] - array with the save data92 * See also93 * * GAME_SAVE_SIZE94 * * loadState()95 * History96 * * v5.0 - provide save data in arguments97 ******/9899/****e* PawnLibs/wowcore/ON_Tick100 * Summary101 * Main application loop handler.102 * Synopsis103 */104forward ON_Tick();105/*106 * Description107 * Public function with such signature will be called on each iteration of an108 * application loop. Main application logic should be placed here. Frequency109 * of calls are not constant and depends on the configured framerate,110 * calculations and rendering complexities.111 * See also112 * * ON_PhysicsTick()113 * * ON_Render()114 ******/115116/****e* PawnLibs/wowcore/ON_PhysicsTick117 * Summary118 * Uniformly delayed loop handler.119 * Synopsis120 */121forward ON_PhysicsTick();122/*123 * Description124 * Public function with such signature will be called approximately each 30125 * milliseconds. However time interval between calls can be larger because the126 * application is single threaded and complex rendering or calculation can127 * delay events processing. Useful for calculations requiring a time delta,128 * e.g. sprite movement at a constant speed.129 ******/130131/****e* PawnLibs/wowcore/ON_Packet132 * Summary133 * Network packet handler.134 * Synopsis135 */136forward ON_Packet(type, size, const pkt[]);137/*138 * Description139 * Public function with such signature will be called to handle a received140 * application packet from an another module in the cube network.141 * Inputs142 * * type - an application packet type143 * * size - size of the received packet144 * * pkt[] - array with a message data145 * See also146 * * broadcastPacket()147 * History148 * * v6.0 - added149 ******/150151152/****e* PawnLibs/wowcore/ON_Load153 * Summary154 * Asynchronous application save data handler.155 * Synopsis156 */157forward ON_Load(id, size, const pkt[]);158/*159 * Description160 * Public function with such signature will be called to handle an application161 * save data. It is an asynchronous event so access to flash memory will not162 * affect an application performance.163 * Inputs164 * * id - an id of the save data165 * * size - size of the save data in cells166 * * pkt[] - array with the save data167 * See also168 * * GAME_SAVE_SIZE169 * * loadState()170 * * saveState()171 * History172 * * v5.0 - provide data header as arguments rather than first cell173 ******/174175/****e* PawnLibs/wowcore/ON_Quit176 * Summary177 * Application quit handler.178 * Synopsis179 */180forward ON_Quit();181/*182 * Description183 * Public function with such signature will be called to handle an application184 * quit event when user did triple shake. Application can shutdown gracefully,185 * e.g. save state on the flash memory. Application has 1000ms to run handler186 * and will be termintated after that period. No more handlers will be called.187 * See also188 * * saveState()189 * History190 * * v5.0 - added191 ******/192193/****n* PawnLibs/wowcore/getTime194 * Summary195 * Get time in milliseconds since the module start.196 * Synopsis197 */198native getTime();199/*200 * Return value201 * Time in milliseconds since the module start.202 ******/203204/****n* PawnLibs/wowcore/getUserName205 * Summary206 * Get the name of a user who is logined on the cube.207 * Synopsis208 */209native getUserName(userName[], size = sizeof(userName));210/*211 * Description212 * Get the user name configured in the WOWCube mobile application to save213 * results for.214 * Inputs215 * * size - size of string to keep a user name216 * Outputs217 * * userName - string to keep a user name218 * See also219 * * USER_NAME_LENGTH220 ******/221222/****n* PawnLibs/wowcore/quit223 * Summary224 * Quit from the application.225 * Synopsis226 */227native quit();228/*229 * See also230 * * SENSITIVITY_MENU_CHANGE_SCRIPT231 ******/232233/****n* PawnLibs/wowcore/toggleDebugInfo234 * Summary235 * Toggle overlay with debug information. TBD - move to GFX236 * Synopsis237 */238native toggleDebugInfo();239/*240 * Description241 * Debug information includes:242 * TBD - current information is obsolete243 ******/244245/****n* PawnLibs/wowcore/broadcastPacket246 * Summary247 * Broadcast a packet over the cube network.248 * Synopsis249 */250native broadcastPacket(type, const data[], size = sizeof(data));251/*252 * Description253 * TBD: routing, filtering. Packet delivery is not guaranteed. Packet types254 * equal or greater than MAX_PACKET_TYPES are discarded. Packet sizes greater255 * than MAX_PACKET_SIZE are discarded.256 * Inputs257 * * type - arbitrary packet type258 * * data[] - packet data to broadcast259 * * size - size of the packet data in cells260 * See also261 * * ON_Packet()262 * * MAX_PACKET_TYPES263 * * MAX_PACKET_SIZE264 * History265 * * v6.0 - added266 ******/267268/****n* PawnLibs/wowcore/saveState269 * Summary270 * Request to save an application data271 * Synopsis272 */273native bool:saveState(const data[], size = sizeof(data));274/*275 * Description276 * Save user settings and/or progress on the flash to restore next time. Each277 * save data has an incremental ID.278 * Inputs279 * * data [] - data to save280 * * size - size of data in cells to save281 * Return value282 * True if save was successful.283 * See also284 * * GAME_SAVE_SIZE285 * * ON_Load()286 * * loadState()287 * History288 * * v5.0 - fixed a bug in which only part of a data saved on the flash289 ******/290291/****n* PawnLibs/wowcore/loadState292 * Summary293 * Request to load an application save data from the flash.294 * Synopsis295 */296native loadState();297/*298 * Description299 * Trigger state load event. It is asynchronous so access to flash memory will300 * not affect an application performance.301 * See also302 * * ON_Load()303 * * saveState()304 ******/305306/****n* PawnLibs/wowcore/random307 * Summary308 * Generate random number in half-open range.309 * Synopsis310 */311native random(min, max);312/*313 * Description314 * Random number generator is initialized before each application start. Seed315 * for initialization is generated by TRNG (True Random Number Generator).316 * Inputs317 * * min - minimal value of range to generate random number318 * * max - maximum value of range to generate random number319 * Return value320 * Pseudo random value from requested range.321 * History322 * * v5.0 - fixed a bug in which random does not generate numbers in a given323 * range.324 ******/325326/****n* PawnLibs/wowcore/getAppVersion327 * Summary328 * Get application version.329 * Synopsis330 */331native getAppVersion(version[APP_VERSION]);332/*333 * Description334 * WOWCube applications follow semantic versioning scheme (see335 * https://semver.org). This interface allows to get version parts stored in336 * the cube application descriptor.337 * Outputs338 * * version - structure describing application version339 * See also340 * * APP_VERSION341 * History342 * * v6.0 - added343 ******/344345/****f* PawnLibs/wowcore/parseByte346 * Summary347 * Get arbitrary byte value from array.348 * Synopsis349 */350stock parseByte(const arr[], const n)351/*352 * Description353 * Pawn works with cells which has a size of 4 bytes. Native interfaces354 * handling generic data like network messages have size limits for that data.355 * If application does not need to work with a large numbers, several values356 * can be packed into a single cell. This function provides interface to357 * extract such values from array.358 * Inputs359 * * arr - array to read byte from360 * * n - number of byte to read361 * Return value362 * Requested byte value.363 * See also364 * * broadcastPacket()365 * * saveState()366 * * ON_Load()367 * * ON_Packet()368 * Source369 */370{371 return ((arr[n/4] >> (8*(n%4))) & 0xFF);372}373/******/374375
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.