| 2211 | } |
| 2212 | |
| 2213 | Result GetComponent(HInstance instance, dmhash_t component_id, uint32_t* component_type, HComponent* out_component, HComponentWorld* out_world) |
| 2214 | { |
| 2215 | // TODO: We should probably not store user-data sparse. |
| 2216 | // A lot of loops just to find user-data such as the code below |
| 2217 | assert(instance != 0x0); |
| 2218 | const Prototype::Component* components = instance->m_Prototype->m_Components; |
| 2219 | uint32_t n = instance->m_Prototype->m_ComponentCount; |
| 2220 | uint32_t component_instance_data = 0; |
| 2221 | for (uint32_t i = 0; i < n; ++i) |
| 2222 | { |
| 2223 | const Prototype::Component* component = &components[i]; |
| 2224 | const ComponentType* type = component->m_Type; |
| 2225 | if (component->m_Id == component_id) |
| 2226 | { |
| 2227 | *component_type = component->m_TypeIndex; |
| 2228 | |
| 2229 | dmGameObject::HComponentInternal user_data = 0; |
| 2230 | if (type->m_InstanceHasUserData) |
| 2231 | { |
| 2232 | user_data = instance->m_ComponentInstanceUserData[component_instance_data]; |
| 2233 | } |
| 2234 | |
| 2235 | dmGameObject::HComponentWorld world = 0; |
| 2236 | if (type->m_GetFunction || (out_world != 0)) |
| 2237 | { |
| 2238 | world = GetWorld(GetCollection(instance), component->m_TypeIndex); |
| 2239 | } |
| 2240 | |
| 2241 | if (type->m_GetFunction) |
| 2242 | { |
| 2243 | ComponentGetParams params = {world, user_data}; |
| 2244 | *out_component = (dmGameObject::HComponent)type->m_GetFunction(params); |
| 2245 | } |
| 2246 | else |
| 2247 | { |
| 2248 | *out_component = (dmGameObject::HComponent)user_data; |
| 2249 | } |
| 2250 | |
| 2251 | if (out_world != 0) |
| 2252 | { |
| 2253 | *out_world = world; |
| 2254 | } |
| 2255 | return RESULT_OK; |
| 2256 | } |
| 2257 | |
| 2258 | if (type->m_InstanceHasUserData) |
| 2259 | { |
| 2260 | component_instance_data++; |
| 2261 | } |
| 2262 | } |
| 2263 | |
| 2264 | return RESULT_COMPONENT_NOT_FOUND; |
| 2265 | } |
| 2266 | |
| 2267 | void SetBone(HInstance instance, bool bone) |
| 2268 | { |