MCPcopy Create free account
hub / github.com/defold/defold / SetAtlas

Function SetAtlas

engine/gamesys/src/gamesys/scripts/script_resource.cpp:2703–2744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2701 */
2702
2703static 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
2747static void PushGeometry(lua_State* L, int index, dmGameSystemDDF::SpriteGeometry& geom, float tex_width, float tex_height)

Callers

nothing calls this directly

Calls 14

CheckHashOrStringFunction · 0.85
CheckResourceFunction · 0.85
luaL_checktypeFunction · 0.85
lua_pushvalueFunction · 0.85
CheckTextureResourceFunction · 0.85
CheckAtlasArgumentsFunction · 0.85
MakeTextureSetFromLuaFunction · 0.85
SaveMessageToArrayFunction · 0.85
DestroyTextureSetFunction · 0.85
ReportPathErrorFunction · 0.85
assertFunction · 0.50
SetResourceFunction · 0.50

Tested by

no test coverage detected