| 724 | } |
| 725 | |
| 726 | dmGameObject::CreateResult CompSpriteCreate(const dmGameObject::ComponentCreateParams& params) |
| 727 | { |
| 728 | SpriteWorld* sprite_world = (SpriteWorld*)params.m_World; |
| 729 | |
| 730 | if (sprite_world->m_Components.Full()) |
| 731 | { |
| 732 | ShowFullBufferError("Sprite", "sprite.max_count", sprite_world->m_Components.Capacity()); |
| 733 | return dmGameObject::CREATE_RESULT_UNKNOWN_ERROR; |
| 734 | } |
| 735 | uint32_t index = sprite_world->m_Components.Alloc(); |
| 736 | SpriteComponent* component = &sprite_world->m_Components.Get(index); |
| 737 | memset(component, 0, sizeof(SpriteComponent)); |
| 738 | |
| 739 | component->m_Instance = params.m_Instance; |
| 740 | component->m_Position = Vector3(params.m_Position); |
| 741 | component->m_Rotation = params.m_Rotation; |
| 742 | component->m_Scale = params.m_Scale; |
| 743 | SpriteResource* resource = (SpriteResource*)params.m_Resource; |
| 744 | component->m_Resource = resource; |
| 745 | // narrow to 8 bits because I don't believe that sprite can have more than 255 textures |
| 746 | component->m_NumTextures = (uint8_t)resource->m_NumTextures; |
| 747 | component->m_Overrides = 0; |
| 748 | |
| 749 | dmMessage::ResetURL(&component->m_Listener); |
| 750 | |
| 751 | component->m_VertexCount = 0; |
| 752 | component->m_VertexStride = 1; |
| 753 | component->m_IndexCount = 0; |
| 754 | component->m_ComponentIndex = params.m_ComponentIndex; |
| 755 | component->m_Enabled = 1; |
| 756 | component->m_FunctionRef = 0; |
| 757 | component->m_ReHash = 1; |
| 758 | component->m_AnimationReHash = 1; |
| 759 | component->m_Slice9 = component->m_Resource->m_DDF->m_Slice9; |
| 760 | component->m_UseSlice9 = sum(component->m_Slice9) != 0 && |
| 761 | component->m_Resource->m_DDF->m_SizeMode == dmGameSystemDDF::SpriteDesc::SIZE_MODE_MANUAL; |
| 762 | |
| 763 | component->m_DynamicVertexAttributeIndex = INVALID_DYNAMIC_ATTRIBUTE_INDEX; |
| 764 | component->m_Size = Vector3(0.0f, 0.0f, 0.0f); |
| 765 | component->m_AnimationID = 0; |
| 766 | component->m_AnimationPlayback = dmGameSystemDDF::PLAYBACK_NONE; |
| 767 | component->m_AnimationFrameCount = 1; |
| 768 | component->m_PivotX = 0.5f; |
| 769 | component->m_PivotY = 0.5f; |
| 770 | |
| 771 | if (component->m_Resource->m_DDF->m_SizeMode == dmGameSystemDDF::SpriteDesc::SIZE_MODE_MANUAL || component->m_NumTextures == 0) |
| 772 | { |
| 773 | component->m_Size[0] = component->m_Resource->m_DDF->m_Size.getX(); |
| 774 | component->m_Size[1] = component->m_Resource->m_DDF->m_Size.getY(); |
| 775 | } |
| 776 | |
| 777 | if (component->m_NumTextures > 0) |
| 778 | { |
| 779 | PlayAnimation(component, resource->m_DefaultAnimation, |
| 780 | component->m_Resource->m_DDF->m_Offset, component->m_Resource->m_DDF->m_PlaybackRate); |
| 781 | } |
| 782 | |
| 783 | *params.m_UserData = (uintptr_t)index; |
nothing calls this directly
no test coverage detected