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 * * ON_Shake()232 ******/233234/****n* PawnLibs/wowcore/toggleDebugInfo235 * Summary236 * Toggle overlay with debug information. TBD - move to GFX237 * Synopsis238 */239native toggleDebugInfo();240/*241 * Description242 * Debug information includes:243 * TBD - current information is obsolete244 ******/245246/****n* PawnLibs/wowcore/broadcastPacket247 * Summary248 * Broadcast a packet over the cube network.249 * Synopsis250 */251native broadcastPacket(type, const data[], size = sizeof(data));252/*253 * Description254 * TBD: routing, filtering. Packet delivery is not guaranteed. Packet types255 * equal or greater than MAX_PACKET_TYPES are discarded. Packet sizes greater256 * than MAX_PACKET_SIZE are discarded.257 * Inputs258 * * type - arbitrary packet type259 * * data[] - packet data to broadcast260 * * size - size of the packet data in cells261 * See also262 * * ON_Packet()263 * * MAX_PACKET_TYPES264 * * MAX_PACKET_SIZE265 * History266 * * v6.0 - added267 ******/268269/****n* PawnLibs/wowcore/saveState270 * Summary271 * Request to save an application data272 * Synopsis273 */274native bool:saveState(const data[], size = sizeof(data));275/*276 * Description277 * Save user settings and/or progress on the flash to restore next time. Each278 * save data has an incremental ID.279 * Inputs280 * * data [] - data to save281 * * size - size of data in cells to save282 * Return value283 * True if save was successful.284 * See also285 * * GAME_SAVE_SIZE286 * * ON_Load()287 * * loadState()288 * History289 * * v5.0 - fixed a bug in which only part of a data saved on the flash290 ******/291292/****n* PawnLibs/wowcore/loadState293 * Summary294 * Request to load an application save data from the flash.295 * Synopsis296 */297native loadState();298/*299 * Description300 * Trigger state load event. It is asynchronous so access to flash memory will301 * not affect an application performance.302 * See also303 * * ON_Load()304 * * saveState()305 ******/306307/****n* PawnLibs/wowcore/random308 * Summary309 * Generate random number in half-open range.310 * Synopsis311 */312native random(min, max);313/*314 * Description315 * Random number generator is initialized before each application start. Seed316 * for initialization is generated by TRNG (True Random Number Generator).317 * Inputs318 * * min - minimal value of range to generate random number319 * * max - maximum value of range to generate random number320 * Return value321 * Pseudo random value from requested range.322 * History323 * * v5.0 - fixed a bug in which random does not generate numbers in a given324 * range.325 ******/326327/****n* PawnLibs/wowcore/getAppVersion328 * Summary329 * Get application version.330 * Synopsis331 */332native getAppVersion(version[APP_VERSION]);333/*334 * Description335 * WOWCube applications follow semantic versioning scheme (see336 * https://semver.org). This interface allows to get version parts stored in337 * the cube application descriptor.338 * Outputs339 * * version - structure describing application version340 * See also341 * * APP_VERSION342 * History343 * * v6.0 - added344 ******/345346/****f* PawnLibs/wowcore/parseByte347 * Summary348 * Get arbitrary byte value from array.349 * Synopsis350 */351stock parseByte(const arr[], const n)352/*353 * Description354 * Pawn works with cells which has a size of 4 bytes. Native interfaces355 * handling generic data like network messages have size limits for that data.356 * If application does not need to work with a large numbers, several values357 * can be packed into a single cell. This function provides interface to358 * extract such values from array.359 * Inputs360 * * arr - array to read byte from361 * * n - number of byte to read362 * Return value363 * Requested byte value.364 * See also365 * * broadcastPacket()366 * * saveState()367 * * ON_Load()368 * * ON_Packet()369 * Source370 */371{372 return ((arr[n/4] >> (8*(n%4))) & 0xFF);373}374/******/375376
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.