Calculates the size of a struct, specified by the stream declarations. The sizes and offsets should mimic the sizes and offsets generated by C++
| 158 | // Calculates the size of a struct, specified by the stream declarations. |
| 159 | // The sizes and offsets should mimic the sizes and offsets generated by C++ |
| 160 | Result CalcStructSize(uint32_t num_streams, const StreamDeclaration* streams, uint32_t* out_size, uint32_t* offsets) |
| 161 | { |
| 162 | uint32_t biggestsize = 1; |
| 163 | uint32_t size = 0; |
| 164 | for (uint32_t i = 0; i < num_streams; ++i) { |
| 165 | if (streams[i].m_Count == 0) { |
| 166 | return RESULT_STREAM_SIZE_ERROR; |
| 167 | } |
| 168 | |
| 169 | uint32_t type_size = GetSizeForValueType(streams[i].m_Type); |
| 170 | if (type_size > biggestsize) { |
| 171 | biggestsize = type_size; |
| 172 | } |
| 173 | |
| 174 | size = DM_ALIGN(size, type_size); |
| 175 | if (offsets) |
| 176 | offsets[i] = size; |
| 177 | |
| 178 | size += streams[i].m_Count * type_size; |
| 179 | } |
| 180 | |
| 181 | size = DM_ALIGN(size, biggestsize); |
| 182 | *out_size = size; |
| 183 | return size != 0 ? RESULT_OK : RESULT_STREAM_SIZE_ERROR; |
| 184 | } |
| 185 | |
| 186 | #define _TOSTRING(_NAME) case _NAME: return #_NAME; |
| 187 | const char* GetResultString(Result result) |