Advertisement
Zgragselus

benzin

Jan 4th, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1.         /// <summary>
  2.         /// Create a single component.
  3.         ///
  4.         /// Built-in components are handled separately, custom components are first searched and
  5.         /// then created (if component was registered).
  6.         /// </summary>
  7.         /// <param name="component">Component type ID</param>
  8.         /// <returns>Pointer to newly created component (null in case of failure)</returns>
  9.         static Component* CreateComponent(ComponentId component)
  10.         {
  11.             if (component == ComponentTypeId::Get<SkinnedAnimatorComponent>())
  12.             {
  13.                 return new SkinnedAnimatorComponent(nullptr);
  14.             }
  15.             else if (component == ComponentTypeId::Get<CameraComponent>())
  16.             {
  17.                 return new CameraComponent(new PerspectiveCamera(float4(0.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 0.0f), Math::DegToRad(45.0f), 1.0f, 1.0f, 1000.0f, 1.0f));
  18.             }
  19.             else if (component == ComponentTypeId::Get<CollisionComponent>())
  20.             {
  21.                 return new CollisionComponent(new Box(float4(1.0f, 1.0f, 1.0f, 0.0f)));
  22.             }
  23.             else if (component == ComponentTypeId::Get<LightComponent>())
  24.             {
  25.                 return new LightComponent(new PointLight(float4(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 0.00001f));
  26.             }
  27.             else if (component == ComponentTypeId::Get<MaterialComponent>())
  28.             {
  29.                 return new MaterialComponent(nullptr, nullptr, nullptr, nullptr, nullptr, mTextureManager);
  30.             }
  31.             else if (component == ComponentTypeId::Get<MeshComponent>())
  32.             {
  33.                 return new MeshComponent(nullptr, mMeshManager);
  34.             }
  35.             else if (component == ComponentTypeId::Get<SkinnedMeshComponent>())
  36.             {
  37.                 return new SkinnedMeshComponent(nullptr, mMeshManager);
  38.             }
  39.             else if (component == ComponentTypeId::Get<RigidBodyComponent>())
  40.             {
  41.                 return new RigidBodyComponent(new RigidBody(0.0f));
  42.             }
  43.             else if (component == ComponentTypeId::Get<CharacterComponent>())
  44.             {
  45.                 return new CharacterComponent(new Character(), 1.0f, 1.0f, 1.0f);
  46.             }
  47.             else if (component == ComponentTypeId::Get<AudioListenerComponent>())
  48.             {
  49.                 return new AudioListenerComponent(new AudioListener());
  50.             }
  51.             else if (component == ComponentTypeId::Get<AudioSourceComponent>())
  52.             {
  53.                 return new AudioSourceComponent(nullptr, mSoundManager);
  54.             }
  55.             else
  56.             {
  57.                 std::map<ComponentId, ComponentInterface*>::iterator it = mScriptComponents.find(component);
  58.                 if (it == mScriptComponents.end())
  59.                 {
  60.                     return nullptr;
  61.                 }
  62.                 else
  63.                 {
  64.                     return it->second->CreateComponent();
  65.                 }
  66.             }
  67.         }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement