Skip to content

Commit

Permalink
Added documentation for gfx.map and ctr.qtm modules
Browse files Browse the repository at this point in the history
  • Loading branch information
firew0lf committed Sep 12, 2015
1 parent 0773992 commit e94da04
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
56 changes: 56 additions & 0 deletions source/map.c
@@ -1,3 +1,9 @@
/***
The `map` module.
@module ctr.gfx.map
@usage local map = require("ctr.gfx.map")
*/

#include <sf2d.h>

#include <lapi.h>
Expand Down Expand Up @@ -30,6 +36,16 @@ u16 getTile(map_userdata *map, int x, int y) {
}

// module functions

/***
Load a map from a file.
@function load
@tparam string path path to the .map
@tparam texture tileset containing the tileset
@tparam number tileWidth tile width
@tparam number tileHeight tile height
@treturn map loaded map object
*/
static int map_load(lua_State *L) {
const char *mapPath = luaL_checkstring(L, 1);
texture_userdata *texture = luaL_checkudata(L, 2, "LTexture");
Expand Down Expand Up @@ -91,6 +107,18 @@ static int map_load(lua_State *L) {
return 1;
}

/***
Map object
@section Methods
*/

/***
Draw a map.
@function :draw
@tparam number x X position
@tparam number y Y position
@within Methods
*/
static int map_draw(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);
Expand Down Expand Up @@ -120,13 +148,25 @@ static int map_draw(lua_State *L) {
return 0;
}

/***
Unload a map.
@function :unload
@within Methods
*/
static int map_unload(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
free(map->data);
free(map);
return 0;
}

/***
Return the size of a map.
@function :getSize
@treturn number width of the map, in tiles
@treturn number height of the map, in tiles
@within Methods
*/
static int map_getSize(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");

Expand All @@ -136,6 +176,14 @@ static int map_getSize(lua_State *L) {
return 2;
}

/***
Return the value of a tile.
@function :getTile
@tparam number x X position of the tile
@tparam number y Y position of the tile
@treturn number value of the tile
@within Methods
*/
static int map_getTile(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);
Expand All @@ -145,6 +193,14 @@ static int map_getTile(lua_State *L) {
return 1;
}

/***
Set the value of a tile.
@function :setTile
@tparam number x X position of the tile
@tparam number y Y position of the tile
@tparam number value New value for the tile
@within Methods
*/
static int map_setTile(lua_State *L) {
map_userdata *map = luaL_checkudata(L, 1, "LMap");
int x = luaL_checkinteger(L, 2);
Expand Down
67 changes: 67 additions & 0 deletions source/qtm.c
@@ -1,3 +1,9 @@
/***
The `qtm` module, for headtracking. New3ds only.
@module ctr.qtm
@usage local qtm = require("ctr.qtm")
@newonly
*/
#include <3ds.h>
#include <3ds/types.h>
#include <3ds/services/qtm.h>
Expand All @@ -13,6 +19,10 @@ typedef struct {

static const struct luaL_Reg qtm_methods[];

/***
Initialize the QTM module.
@function init
*/
static int qtm_init(lua_State *L) {
Result ret = qtmInit();
if (ret) {
Expand All @@ -25,19 +35,33 @@ static int qtm_init(lua_State *L) {
return 1;
}

/***
Disable the QTM module.
@function shutdown
*/
static int qtm_shutdown(lua_State *L) {
qtmExit();

return 0;
}

/***
Check if the module is initialized.
@function checkInitialized
@treturn boolean `true` if initialized.
*/
static int qtm_checkInitialized(lua_State *L) {
bool isInit = qtmCheckInitialized();

lua_pushboolean(L, isInit);
return 1;
}

/***
Return informations about the headtracking
@function getHeadTrackingInfo
@treturn qtmInfos QTM informations
*/
static int qtm_getHeadtrackingInfo(lua_State *L) {
qtm_userdata *data = lua_newuserdata(L, sizeof(*data));
luaL_getmetatable(L, "LQTM");
Expand All @@ -50,6 +74,12 @@ static int qtm_getHeadtrackingInfo(lua_State *L) {
return 1;
}

/***
Check if the head is fully detected
@function checkHeadFullyDetected
@tparam qtmInfos qtmInfos QTM informations
@treturn boolean `true` if fully detected
*/
static int qtm_checkHeadFullyDetected(lua_State *L) {
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
lua_pushboolean(L, qtmCheckHeadFullyDetected(info->info));
Expand Down Expand Up @@ -84,6 +114,16 @@ static int qtm___index(lua_State *L) {
return 1;
}

/***
Convert QTM coordinates to screen coordinates
@function convertCoordToScreen
@tparam qtmInfos qtmInfos QTM informations
@tparam number coordinates index
@tparam number [screenWidth] specify a screen width (default `400`)
@tparam number [screenHeight] specify a screen height (default `320`)
@treturn number screen X coordinate
@treturn number screen Y coordinate
*/
static int qtm_convertCoordToScreen(lua_State *L) {
qtm_userdata *info = luaL_checkudata(L, 1, "LQTM");
lua_Integer index = luaL_checkinteger(L, 2);
Expand All @@ -105,6 +145,33 @@ static int qtm_convertCoordToScreen(lua_State *L) {
return 2;
}

/***
qtmInfos object
@section Methods
*/

/***
Check if the head is fully detected
@function :checkHeadFullyDetected
@treturn boolean `true` if fully detected
*/

/***
Convert QTM coordinates to screen coordinates
@function :convertCoordToScreen
@tparam number coordinates index
@tparam number [screenWidth] specify a screen width (default `400`)
@tparam number [screenHeight] specify a screen height (default `320`)
@treturn number screen X coordinate
@treturn number screen Y coordinate
*/

/***
When the object is indexed with a number from 1 to 4, it returns a coordinate
of one of the headtracker point.
@tfield number index coordinates, as two numbers (not a table)
*/

// object
static const struct luaL_Reg qtm_methods[] = {
{"checkHeadFullyDetected", qtm_checkHeadFullyDetected},
Expand Down

0 comments on commit e94da04

Please sign in to comment.