| 194 | } |
| 195 | |
| 196 | Sprite* getSprite(const char* name) |
| 197 | { |
| 198 | SpriteMap::iterator iSprite = s_sprites.find(name); |
| 199 | if (iSprite != s_sprites.end()) |
| 200 | { |
| 201 | return iSprite->second; |
| 202 | } |
| 203 | |
| 204 | // It doesn't exist yet, try to load the sprite. |
| 205 | if (!TFE_AssetSystem::readAssetFromArchive(c_defaultGob, ARCHIVE_GOB, name, s_buffer)) |
| 206 | { |
| 207 | return nullptr; |
| 208 | } |
| 209 | s32 len = (s32)s_buffer.size(); |
| 210 | |
| 211 | Sprite* sprite = new Sprite; |
| 212 | |
| 213 | const u8* data = s_buffer.data(); |
| 214 | const WaxHeader* header = (WaxHeader*)data; |
| 215 | |
| 216 | //load the first wax for now... |
| 217 | // Get the number of animations. |
| 218 | s32 animationCount = 0; |
| 219 | for (animationCount = 0; header->WAXES[animationCount] != 0 && header->WAXES[animationCount] < len; ) { animationCount++; } |
| 220 | sprite->animationCount = animationCount; |
| 221 | |
| 222 | s_tempFrames.clear(); |
| 223 | s_tempCells.clear(); |
| 224 | s_tempFrames.reserve(128); |
| 225 | s_tempCells.reserve(128); |
| 226 | |
| 227 | // Go through the data and compute the allocation size. |
| 228 | for (s32 i = 0; i < animationCount; i++) |
| 229 | { |
| 230 | const Wax* wax = (Wax*)(data + header->WAXES[i]); |
| 231 | for (u32 a = 0; a < 32; a++) |
| 232 | { |
| 233 | if (!wax->SEQS[a]) { break; } |
| 234 | const Sequence* seq = (Sequence *)(data + wax->SEQS[a]); |
| 235 | |
| 236 | for (u32 f = 0; f < 32; f++) |
| 237 | { |
| 238 | if (!seq->FRAMES[f]) { break; } |
| 239 | addFrame(seq->FRAMES[f]); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | const s32 totalFrameCount = (s32)s_tempFrames.size(); |
| 244 | const s32* frameIndex = s_tempFrames.data(); |
| 245 | for (s32 i = 0; i < totalFrameCount; i++) |
| 246 | { |
| 247 | FME_Frame* frame = (FME_Frame*)(data + frameIndex[i]); |
| 248 | addCell(frame->Cell); |
| 249 | } |
| 250 | |
| 251 | // Now allocate memory and get offsets. |
| 252 | s32 memorySize = sizeof(SpriteAnim) * animationCount; |
| 253 | s32 frameOffset = memorySize; |
nothing calls this directly
no test coverage detected