Component.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #include "Component.h"
  9. #include "Actor.h"
  10. #include "LevelLoader.h"
  11. const char* Component::TypeNames[NUM_COMPONENT_TYPES] = {
  12. "Component",
  13. "AudioComponent",
  14. "BallMove",
  15. "BoxComponent",
  16. "CameraComponent",
  17. "FollowCamera",
  18. "MeshComponent",
  19. "MoveComponent",
  20. "SkeletalMeshComponent",
  21. "SpriteComponent",
  22. "MirrorCamera",
  23. "PointLightComponent",
  24. "TargetComponent"
  25. };
  26. Component::Component(Actor* owner, int updateOrder)
  27. :mOwner(owner)
  28. ,mUpdateOrder(updateOrder)
  29. {
  30. // Add to actor's vector of components
  31. mOwner->AddComponent(this);
  32. }
  33. Component::~Component()
  34. {
  35. mOwner->RemoveComponent(this);
  36. }
  37. void Component::Update(float deltaTime)
  38. {
  39. }
  40. void Component::OnUpdateWorldTransform()
  41. {
  42. }
  43. void Component::LoadProperties(const rapidjson::Value& inObj)
  44. {
  45. JsonHelper::GetInt(inObj, "updateOrder", mUpdateOrder);
  46. }
  47. void Component::SaveProperties(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& inObj) const
  48. {
  49. JsonHelper::AddInt(alloc, inObj, "updateOrder", mUpdateOrder);
  50. }