| 2745 | |
| 2746 | |
| 2747 | static void PushGeometry(lua_State* L, int index, dmGameSystemDDF::SpriteGeometry& geom, float tex_width, float tex_height) |
| 2748 | { |
| 2749 | #define SET_LUA_TABLE_FIELD(set_fn, key, val) \ |
| 2750 | set_fn(L, val); \ |
| 2751 | lua_setfield(L, -2, key); |
| 2752 | |
| 2753 | #define SET_LUA_TABLE_RAW(set_fn, key, val) \ |
| 2754 | set_fn(L, val); \ |
| 2755 | lua_rawseti(L, -2, key); |
| 2756 | |
| 2757 | lua_pushinteger(L, (lua_Integer) (index + 1)); |
| 2758 | lua_newtable(L); |
| 2759 | { |
| 2760 | assert(geom.m_Vertices.m_Count % 2 == 0); |
| 2761 | assert(geom.m_Uvs.m_Count % 2 == 0); |
| 2762 | assert(geom.m_Indices.m_Count % 3 == 0); |
| 2763 | |
| 2764 | SET_LUA_TABLE_FIELD(lua_pushnumber, "width", geom.m_Width); |
| 2765 | SET_LUA_TABLE_FIELD(lua_pushnumber, "height", geom.m_Height); |
| 2766 | // Transform back to image space (0,0) is top left corner, (1,1) is bottom right |
| 2767 | SET_LUA_TABLE_FIELD(lua_pushnumber, "pivot_x", geom.m_PivotX + 0.5); |
| 2768 | SET_LUA_TABLE_FIELD(lua_pushnumber, "pivot_y", 1.0f - (geom.m_PivotY + 0.5f)); |
| 2769 | SET_LUA_TABLE_FIELD(lua_pushboolean, "rotated", geom.m_Rotated); |
| 2770 | |
| 2771 | lua_pushliteral(L, "vertices"); |
| 2772 | lua_newtable(L); |
| 2773 | for (int j = 0; j < geom.m_Vertices.m_Count; j += 2) |
| 2774 | { |
| 2775 | float x = (geom.m_Vertices[j] + 0.5) * geom.m_Width; |
| 2776 | float y = (0.5 - geom.m_Vertices[j+1]) * geom.m_Height; |
| 2777 | |
| 2778 | SET_LUA_TABLE_RAW(lua_pushnumber, j + 1, x); |
| 2779 | SET_LUA_TABLE_RAW(lua_pushnumber, j + 2, y); |
| 2780 | } |
| 2781 | lua_rawset(L, -3); |
| 2782 | |
| 2783 | lua_pushliteral(L, "uvs"); |
| 2784 | lua_newtable(L); |
| 2785 | for (int j = 0; j < geom.m_Uvs.m_Count; j += 2) |
| 2786 | { |
| 2787 | float s = geom.m_Uvs[j] * tex_width; |
| 2788 | float t = (1.0 - geom.m_Uvs[j + 1]) * tex_height; |
| 2789 | |
| 2790 | SET_LUA_TABLE_RAW(lua_pushnumber, j + 1, s); |
| 2791 | SET_LUA_TABLE_RAW(lua_pushnumber, j + 2, t); |
| 2792 | } |
| 2793 | lua_rawset(L, -3); |
| 2794 | |
| 2795 | lua_pushliteral(L, "indices"); |
| 2796 | lua_newtable(L); |
| 2797 | for (int j = 0; j < geom.m_Indices.m_Count; ++j) |
| 2798 | { |
| 2799 | SET_LUA_TABLE_RAW(lua_pushinteger, j + 1, geom.m_Indices[j]); |
| 2800 | } |
| 2801 | lua_rawset(L, -3); |
| 2802 | } |
| 2803 | lua_rawset(L, -3); |
| 2804 |
no test coverage detected