| 2701 | */ |
| 2702 | |
| 2703 | static int SetAtlas(lua_State* L) |
| 2704 | { |
| 2705 | DM_LUA_STACK_CHECK(L, 0); |
| 2706 | |
| 2707 | dmhash_t path_hash = dmScript::CheckHashOrString(L, 1); |
| 2708 | CheckResource(L, g_ResourceModule.m_Factory, path_hash, "texturesetc"); |
| 2709 | |
| 2710 | dmGameSystemDDF::TextureSet texture_set_ddf = {}; |
| 2711 | uint32_t num_geometries = 0; |
| 2712 | uint32_t num_animations = 0; |
| 2713 | uint32_t num_animation_frames = 0; |
| 2714 | |
| 2715 | luaL_checktype(L, 2, LUA_TTABLE); |
| 2716 | lua_pushvalue(L, 2); |
| 2717 | |
| 2718 | dmGraphics::HTexture texture; |
| 2719 | dmhash_t texture_path; |
| 2720 | CheckTextureResource(L, -1, "texture", &texture_path, &texture); |
| 2721 | |
| 2722 | // Note: We do a separate pass over the lua state to validate the data in the args table, |
| 2723 | // this is because we need to allocate dynamic memory and can't use luaL_check** functions |
| 2724 | // since they longjmp away so we can't release the memory.. |
| 2725 | CheckAtlasArguments(L, &num_geometries, &num_animations, &num_animation_frames); |
| 2726 | |
| 2727 | MakeTextureSetFromLua(L, texture_path, texture, num_geometries, num_animations, num_animation_frames, &texture_set_ddf); |
| 2728 | lua_pop(L, 1); // args table |
| 2729 | |
| 2730 | dmArray<uint8_t> ddf_buffer; |
| 2731 | dmDDF::Result ddf_result = dmDDF::SaveMessageToArray(&texture_set_ddf, dmGameSystemDDF::TextureSet::m_DDFDescriptor, ddf_buffer); |
| 2732 | assert(ddf_result == dmDDF::RESULT_OK); |
| 2733 | |
| 2734 | dmResource::Result r = dmResource::SetResource(g_ResourceModule.m_Factory, path_hash, ddf_buffer.Begin(), ddf_buffer.Size()); |
| 2735 | |
| 2736 | DestroyTextureSet(texture_set_ddf); |
| 2737 | |
| 2738 | if(r != dmResource::RESULT_OK) |
| 2739 | { |
| 2740 | return ReportPathError(L, r, path_hash); |
| 2741 | } |
| 2742 | |
| 2743 | return 0; |
| 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | static void PushGeometry(lua_State* L, int index, dmGameSystemDDF::SpriteGeometry& geom, float tex_width, float tex_height) |
nothing calls this directly
no test coverage detected