Ejemplo n.º 1
0
void THLuaRegisterUI(const THLuaRegisterState_t *pState)
{
    // WindowBase
    luaT_class(THWindowBase_t, l_window_base_new, "windowHelpers", MT_WindowBase);
    luaT_setfunction(l_town_map_draw, "townMapDraw", MT_Map, MT_Surface);
    luaT_endclass();
}
Ejemplo n.º 2
0
void THLuaRegisterStrings(const THLuaRegisterState_t *pState)
{
    lua_State *L = pState->L;

    // Create Value, and Cache weak tables for inside-out objects.
    for(int i = 0; i <= 1; ++i)
    {
        lua_pushlightuserdata(L, &g_aStringDummyGlobals[i]);
        lua_newtable(L);
        lua_createtable(L, 0, 1);
        lua_pushliteral(L, "__mode");
        lua_pushliteral(L, "k");
        lua_rawset(L, -3);
        if(i == 1)
        {
            // Have the cache weak table automatically create caches on demand
            lua_pushliteral(L, "__index");
            lua_createtable(L, 0, 1);
            lua_pushliteral(L, "__mode");
            lua_pushliteral(L, "kv");
            lua_rawset(L, -3);
            luaT_pushcclosure(L, l_mk_cache, 1);
            lua_rawset(L, -3);
        }
        lua_setmetatable(L, -2);
        lua_rawset(L, LUA_REGISTRYINDEX);
    }
    // Give the Value weak table a friendly name for Lua code to use
    lua_pushliteral(L, "StringProxyValues");
    lua_pushlightuserdata(L, &g_aStringDummyGlobals[0]);
    lua_rawget(L, LUA_REGISTRYINDEX);
    lua_rawset(L, LUA_REGISTRYINDEX);

    luaT_class(THStringProxy_t, l_str_new, "stringProxy", MT_StringProxy);
    // As we overwrite __index, move methods to MT_StringProxy[4]
    lua_getfield(L, pState->aiMetatables[MT_StringProxy], "__index");
    lua_rawseti(L, pState->aiMetatables[MT_StringProxy], 4);
    luaT_setmetamethod(l_str_index, "index");
    luaT_setmetamethod(l_str_newindex, "newindex");
    luaT_setmetamethod(l_str_concat, "concat");
    luaT_setmetamethod(l_str_len, "len");
    luaT_setmetamethod(l_str_tostring, "tostring");
    luaT_setmetamethod(l_str_persist, "persist");
    luaT_setmetamethod(l_str_depersist, "depersist");
    luaT_setmetamethod(l_str_call, "call");
    luaT_setmetamethod(l_str_lt, "lt");
    luaT_setmetamethod(l_str_pairs, "pairs");
    luaT_setmetamethod(l_str_ipairs, "ipairs");
    luaT_setmetamethod(l_str_next, "next");
    luaT_setmetamethod(l_str_inext, "inext");
    luaT_setfunction(l_str_func, "format" , MT_DummyString, "format");
    luaT_setfunction(l_str_func, "lower"  , MT_DummyString, "lower");
    luaT_setfunction(l_str_func, "rep"    , MT_DummyString, "rep");
    luaT_setfunction(l_str_func, "reverse", MT_DummyString, "reverse");
    luaT_setfunction(l_str_func, "upper"  , MT_DummyString, "upper");
    luaT_setfunction(l_str_unwrap, "_unwrap");
    luaT_setfunction(l_str_reload, "reload");
    luaT_endclass();
}
Ejemplo n.º 3
0
void THLuaRegisterSound(const THLuaRegisterState_t *pState)
{
    // Sound Archive
    luaT_class(THSoundArchive, l_soundarc_new, "soundArchive", MT_SoundArc);
    luaT_setmetamethod(l_soundarc_count, "len");
    luaT_setfunction(l_soundarc_load, "load");
    luaT_setfunction(l_soundarc_filename, "getFilename");
    luaT_setfunction(l_soundarc_duration, "getDuration");
    luaT_setfunction(l_soundarc_filedata, "getFileData");
    luaT_endclass();

    // Sound Effects
    luaT_class(THSoundEffects, l_soundfx_new, "soundEffects", MT_SoundFx);
    luaT_setfunction(l_soundfx_set_archive, "setSoundArchive", MT_SoundArc);
    luaT_setfunction(l_soundfx_play, "play");
    luaT_setfunction(l_soundfx_set_sound_volume, "setSoundVolume");
    luaT_setfunction(l_soundfx_set_sound_effects_on, "setSoundEffectsOn");
    luaT_setfunction(l_soundfx_set_camera, "setCamera");
    luaT_endclass();
}
Ejemplo n.º 4
0
void THLuaRegisterGfx(const THLuaRegisterState_t *pState)
{
    // Palette
    luaT_class(THPalette, l_palette_new, "palette", MT_Palette);
    luaT_setfunction(l_palette_load, "load");
    luaT_setfunction(l_palette_set_entry, "setEntry");
    luaT_endclass();

    // Raw bitmap
    luaT_class(THRawBitmap, l_rawbitmap_new, "bitmap", MT_Bitmap);
    luaT_setfunction(l_rawbitmap_load, "load", MT_Surface);
    luaT_setfunction(l_rawbitmap_set_pal, "setPalette", MT_Palette);
    luaT_setfunction(l_rawbitmap_draw, "draw", MT_Surface);
    luaT_endclass();

    // Sprite sheet
    luaT_class(THSpriteSheet, l_spritesheet_new, "sheet", MT_Sheet);
    luaT_setmetamethod(l_spritesheet_count, "len");
    luaT_setfunction(l_spritesheet_load, "load", MT_Surface);
    luaT_setfunction(l_spritesheet_set_pal, "setPalette", MT_Palette);
    luaT_setfunction(l_spritesheet_size, "size");
    luaT_setfunction(l_spritesheet_draw, "draw", MT_Surface);
    luaT_setfunction(l_spritesheet_hittest, "hitTest");
    luaT_setfunction(l_spritesheet_isvisible, "isVisible");
    luaT_endclass();

    // Font
    // Also adapt the font proxy meta table (font_proxy_mt) in graphics.lua.
    luaT_class(THFont, l_font_new, "font", MT_Font);
    luaT_setfunction(l_font_get_size, "sizeOf");
    luaT_setfunction(l_font_draw, "draw", MT_Surface);
    luaT_setfunction(l_font_draw_wrapped, "drawWrapped", MT_Surface);
    luaT_setfunction(l_font_draw_tooltip, "drawTooltip", MT_Surface);
    luaT_endclass();

    // BitmapFont
    luaT_class(THBitmapFont, l_bitmap_font_new, "bitmap_font", MT_BitmapFont);
    luaT_superclass(MT_Font);
    luaT_setfunction(l_bitmap_font_set_spritesheet, "setSheet", MT_Sheet);
    luaT_setfunction(l_bitmap_font_get_spritesheet, "getSheet", MT_Sheet);
    luaT_setfunction(l_bitmap_font_set_sep, "setSeparation");
    luaT_endclass();

#ifdef CORSIX_TH_USE_FREETYPE2
    // FreeTypeFont
    luaT_class(THFreeTypeFont, l_freetype_font_new, "freetype_font", MT_FreeTypeFont);
    luaT_superclass(MT_Font);
    luaT_setfunction(l_freetype_font_set_spritesheet, "setSheet", MT_Sheet);
    luaT_setfunction(l_freetype_font_set_face, "setFace");
    luaT_setfunction(l_freetype_font_get_copyright, "getCopyrightNotice");
    luaT_setfunction(l_freetype_font_clear_cache, "clearCache");
    luaT_endclass();
#endif

    // Layers
    luaT_class(THLayers_t, l_layers_new, "layers", MT_Layers);
    luaT_setmetamethod(l_layers_get, "index");
    luaT_setmetamethod(l_layers_set, "newindex");
    luaT_setmetamethod(l_layers_persist, "persist");
    luaT_setmetamethod(l_layers_depersist, "depersist");
    luaT_endclass();

    // Cursor
    luaT_class(THCursor, l_cursor_new, "cursor", MT_Cursor);
    luaT_setfunction(l_cursor_load, "load", MT_Sheet);
    luaT_setfunction(l_cursor_use, "use", MT_Surface);
    luaT_setfunction(l_cursor_position, "setPosition", MT_Surface);
    luaT_endclass();

    // Surface
    luaT_class(THRenderTarget, l_surface_new, "surface", MT_Surface);
    luaT_setfunction(l_surface_update, "update");
    luaT_setfunction(l_surface_destroy, "destroy");
    luaT_setfunction(l_surface_fill_black, "fillBlack");
    luaT_setfunction(l_surface_start_frame, "startFrame");
    luaT_setfunction(l_surface_end_frame, "endFrame");
    luaT_setfunction(l_surface_nonoverlapping, "nonOverlapping");
    luaT_setfunction(l_surface_map, "mapRGB");
    luaT_setfunction(l_surface_set_blue_filter_active, "setBlueFilterActive");
    luaT_setfunction(l_surface_rect, "drawRect");
    luaT_setfunction(l_surface_get_clip, "getClip");
    luaT_setfunction(l_surface_set_clip, "setClip");
    luaT_setfunction(l_surface_screenshot, "takeScreenshot");
    luaT_setfunction(l_surface_scale, "scale");
    luaT_setfunction(l_surface_set_caption, "setCaption");
    luaT_setfunction(l_surface_get_renderer_details, "getRendererDetails");
    luaT_endclass();

    // Line
    luaT_class(THLine, l_line_new, "line", MT_Line);
    luaT_setfunction(l_move_to, "moveTo");
    luaT_setfunction(l_line_to, "lineTo");
    luaT_setfunction(l_set_width, "setWidth");
    luaT_setfunction(l_set_colour, "setColour");
    luaT_setfunction(l_line_draw, "draw", MT_Surface);
    luaT_setmetamethod(l_line_persist, "persist");
    luaT_setmetamethod(l_line_depersist, "depersist");
    luaT_endclass();
}
Ejemplo n.º 5
0
void THLuaRegisterAnims(const THLuaRegisterState_t *pState)
{
    // Anims
    luaT_class(THAnimationManager, l_anims_new, "anims", MT_Anims);
    luaT_setfunction(l_anims_load, "load");
    luaT_setfunction(l_anims_set_spritesheet, "setSheet", MT_Sheet);
    luaT_setfunction(l_anims_getfirst, "getFirstFrame");
    luaT_setfunction(l_anims_getnext, "getNextFrame");
    luaT_setfunction(l_anims_set_alt_pal, "setAnimationGhostPalette");
    luaT_setfunction(l_anims_set_marker, "setFrameMarker");
    luaT_setfunction(l_anims_set_secondary_marker, "setFrameSecondaryMarker");
    luaT_setfunction(l_anims_draw, "draw", MT_Surface, MT_Layers);
    luaT_endclass();

    // Weak table at AnimMetatable[1] for light UD -> object lookup
    // For hitTest / setHitTestResult
    lua_newtable(pState->L);
    lua_createtable(pState->L, 0, 1);
    lua_pushliteral(pState->L, "v");
    lua_setfield(pState->L, -2, "__mode");
    lua_setmetatable(pState->L, -2);
    lua_rawseti(pState->L, pState->aiMetatables[MT_Anim], 1);

    // Weak table at AnimMetatable[2] for light UD -> full UD lookup
    // For persisting Map
    lua_newtable(pState->L);
    lua_createtable(pState->L, 0, 1);
    lua_pushliteral(pState->L, "v");
    lua_setfield(pState->L, -2, "__mode");
    lua_setmetatable(pState->L, -2);
    lua_rawseti(pState->L, pState->aiMetatables[MT_Anim], 2);

    // Anim
    luaT_class(THAnimation, l_anim_new<THAnimation>, "animation", MT_Anim);
    luaT_setmetamethod(l_anim_persist<THAnimation>, "persist");
    luaT_setmetamethod(l_anim_pre_depersist<THAnimation>, "pre_depersist");
    luaT_setmetamethod(l_anim_depersist<THAnimation>, "depersist");
    luaT_setfunction(l_anim_set_anim, "setAnimation", MT_Anims);
    luaT_setfunction(l_anim_set_crop, "setCrop");
    luaT_setfunction(l_anim_get_crop, "getCrop");
    luaT_setfunction(l_anim_set_morph, "setMorph");
    luaT_setfunction(l_anim_set_frame, "setFrame");
    luaT_setfunction(l_anim_get_frame, "getFrame");
    luaT_setfunction(l_anim_get_anim, "getAnimation");
    luaT_setfunction(l_anim_set_tile<THAnimation>, "setTile", MT_Map);
    luaT_setfunction(l_anim_get_tile, "getTile");
    luaT_setfunction(l_anim_set_parent, "setParent");
    luaT_setfunction(l_anim_set_flag<THAnimation>, "setFlag");
    luaT_setfunction(l_anim_set_flag_partial<THAnimation>, "setPartialFlag");
    luaT_setfunction(l_anim_get_flag<THAnimation>, "getFlag");
    luaT_setfunction(l_anim_make_visible<THAnimation>, "makeVisible");
    luaT_setfunction(l_anim_make_invisible<THAnimation>, "makeInvisible");
    luaT_setfunction(l_anim_set_tag, "setTag");
    luaT_setfunction(l_anim_get_tag, "getTag");
    luaT_setfunction(l_anim_set_position<THAnimation>, "setPosition");
    luaT_setfunction(l_anim_get_position, "getPosition");
    luaT_setfunction(l_anim_set_speed<THAnimation>, "setSpeed");
    luaT_setfunction(l_anim_set_layer<THAnimation>, "setLayer");
    luaT_setfunction(l_anim_set_layers_from, "setLayersFrom");
    luaT_setfunction(l_anim_set_hitresult, "setHitTestResult");
    luaT_setfunction(l_anim_get_marker, "getMarker");
    luaT_setfunction(l_anim_get_secondary_marker, "getSecondaryMarker");
    luaT_setfunction(l_anim_tick<THAnimation>, "tick");
    luaT_setfunction(l_anim_draw<THAnimation>, "draw", MT_Surface);
    luaT_setfunction(l_anim_set_drawable_layer, "setDrawingLayer");
    luaT_endclass();

    // Duplicate AnimMetatable[1,2] to SpriteListMetatable[1,2]
    lua_rawgeti(pState->L, pState->aiMetatables[MT_Anim], 1);
    lua_rawseti(pState->L, pState->aiMetatables[MT_SpriteList], 1);
    lua_rawgeti(pState->L, pState->aiMetatables[MT_Anim], 2);
    lua_rawseti(pState->L, pState->aiMetatables[MT_SpriteList], 2);

    // SpriteList
    luaT_class(THSpriteRenderList, l_anim_new<THSpriteRenderList>, "spriteList", MT_SpriteList);
    luaT_setmetamethod(l_anim_persist<THSpriteRenderList>, "persist");
    luaT_setmetamethod(l_anim_pre_depersist<THSpriteRenderList>, "pre_depersist");
    luaT_setmetamethod(l_anim_depersist<THSpriteRenderList>, "depersist");
    luaT_setfunction(l_srl_set_sheet, "setSheet", MT_Sheet);
    luaT_setfunction(l_srl_append, "append");
    luaT_setfunction(l_srl_set_lifetime, "setLifetime");
    luaT_setfunction(l_srl_is_dead, "isDead");
    luaT_setfunction(l_anim_set_tile<THSpriteRenderList>, "setTile", MT_Map);
    luaT_setfunction(l_anim_set_flag<THSpriteRenderList>, "setFlag");
    luaT_setfunction(l_anim_set_flag_partial<THSpriteRenderList>, "setPartialFlag");
    luaT_setfunction(l_anim_get_flag<THSpriteRenderList>, "getFlag");
    luaT_setfunction(l_anim_make_visible<THSpriteRenderList>, "makeVisible");
    luaT_setfunction(l_anim_make_invisible<THSpriteRenderList>, "makeInvisible");
    luaT_setfunction(l_anim_set_position<THSpriteRenderList>, "setPosition");
    luaT_setfunction(l_anim_set_speed<THSpriteRenderList>, "setSpeed");
    luaT_setfunction(l_anim_set_layer<THSpriteRenderList>, "setLayer");
    luaT_setfunction(l_anim_tick<THSpriteRenderList>, "tick");
    luaT_setfunction(l_anim_draw<THSpriteRenderList>, "draw", MT_Surface);
    luaT_endclass();
}
Ejemplo n.º 6
0
void lua_register_map(const lua_register_state *pState)
{
    // Map
    luaT_class(level_map, l_map_new, "map", lua_metatable::map);
    luaT_setmetamethod(l_map_persist, "persist", lua_metatable::anim);
    luaT_setmetamethod(l_map_depersist, "depersist", lua_metatable::anim);
    luaT_setfunction(l_map_load, "load");
    luaT_setfunction(l_map_loadblank, "loadBlank");
    luaT_setfunction(l_map_save, "save");
    luaT_setfunction(l_map_getsize, "size");
    luaT_setfunction(l_map_get_player_count, "getPlayerCount");
    luaT_setfunction(l_map_set_player_count, "setPlayerCount");
    luaT_setfunction(l_map_get_player_camera, "getCameraTile");
    luaT_setfunction(l_map_set_player_camera, "setCameraTile");
    luaT_setfunction(l_map_get_player_heliport, "getHeliportTile");
    luaT_setfunction(l_map_set_player_heliport, "setHeliportTile");
    luaT_setfunction(l_map_getcell, "getCell");
    luaT_setfunction(l_map_gettemperature, "getCellTemperature");
    luaT_setfunction(l_map_getcellflags, "getCellFlags");
    luaT_setfunction(l_map_setcellflags, "setCellFlags");
    luaT_setfunction(l_map_setcell, "setCell");
    luaT_setfunction(l_map_setwallflags, "setWallDrawFlags");
    luaT_setfunction(l_map_settemperaturedisplay, "setTemperatureDisplay");
    luaT_setfunction(l_map_updatetemperature, "updateTemperatures");
    luaT_setfunction(l_map_updateblueprint, "updateRoomBlueprint", lua_metatable::anims, lua_metatable::anim);
    luaT_setfunction(l_map_updateshadows, "updateShadows");
    luaT_setfunction(l_map_updatepathfinding, "updatePathfinding");
    luaT_setfunction(l_map_mark_room, "markRoom");
    luaT_setfunction(l_map_unmark_room, "unmarkRoom");
    luaT_setfunction(l_map_set_sheet, "setSheet", lua_metatable::sheet);
    luaT_setfunction(l_map_draw, "draw", lua_metatable::surface);
    luaT_setfunction(l_map_hittest, "hitTestObjects", lua_metatable::anim);
    luaT_setfunction(l_map_get_parcel_tilecount, "getParcelTileCount");
    luaT_setfunction(l_map_get_parcel_count, "getPlotCount");
    luaT_setfunction(l_map_set_parcel_owner, "setPlotOwner");
    luaT_setfunction(l_map_get_parcel_owner, "getPlotOwner");
    luaT_setfunction(l_map_is_parcel_purchasable, "isParcelPurchasable");
    luaT_setfunction(l_map_erase_thobs, "eraseObjectTypes");
    luaT_setfunction(l_map_remove_cell_thob, "removeObjectType");
    luaT_setfunction(l_map_get_litter_fraction, "getLitterFraction");
    luaT_endclass();

    // Pathfinder
    luaT_class(pathfinder, l_path_new, "pathfinder", lua_metatable::pathfinder);
    luaT_setmetamethod(l_path_persist, "persist");
    luaT_setmetamethod(l_path_depersist, "depersist");
    luaT_setfunction(l_path_distance, "findDistance");
    luaT_setfunction(l_path_is_reachable_from_hospital, "isReachableFromHospital");
    luaT_setfunction(l_path_path, "findPath");
    luaT_setfunction(l_path_idle, "findIdleTile");
    luaT_setfunction(l_path_visit, "findObject");
    luaT_setfunction(l_path_set_map, "setMap", lua_metatable::map);
    luaT_endclass();
}