SceneEditOp.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #pragma once
  8. #include <Atomic/Core/Object.h>
  9. #include <Atomic/IO/VectorBuffer.h>
  10. namespace Atomic
  11. {
  12. class Node;
  13. class Component;
  14. }
  15. using namespace Atomic;
  16. namespace AtomicEditor
  17. {
  18. enum SceneEditType
  19. {
  20. SCENEEDIT_UNKNOWN = 0,
  21. SCENEEDIT_SELECTION
  22. };
  23. class SceneEditOp
  24. {
  25. public:
  26. SceneEditOp(Scene* scene, SceneEditType type) { type_ = type; scene_ = scene;}
  27. virtual ~SceneEditOp() { }
  28. virtual bool Undo() = 0;
  29. virtual bool Redo() = 0;
  30. /// Returns true if the states are identical
  31. bool CompareStates(const VectorBuffer& stateOne, const VectorBuffer& stateTwo) const
  32. {
  33. if (stateOne.GetSize() != stateTwo.GetSize())
  34. return false;
  35. if (memcmp(stateOne.GetData(), stateTwo.GetData(), stateOne.GetSize()))
  36. return false;
  37. return true;
  38. }
  39. SharedPtr<Scene> scene_;
  40. SceneEditType type_;
  41. };
  42. class SelectionEditOp : public SceneEditOp
  43. {
  44. public:
  45. SelectionEditOp(Scene* scene);
  46. ~SelectionEditOp();
  47. bool Undo();
  48. bool Redo();
  49. void RegisterEdit();
  50. void SetNodes(Vector<SharedPtr<Node>>& nodes);
  51. void AddNode(Node* node);
  52. void NodeAdded(Node* node, Node* parent);
  53. void NodeRemoved(Node* node, Node* parent);
  54. bool Commit();
  55. private:
  56. struct EditComponent
  57. {
  58. SharedPtr<Component> component_;
  59. SharedPtr<Node> nodeBegin_;
  60. SharedPtr<Node> nodeEnd_;
  61. VectorBuffer stateBegin_;
  62. VectorBuffer stateEnd_;
  63. };
  64. struct EditNode
  65. {
  66. SharedPtr<Node> node_;
  67. SharedPtr<Node> parentBegin_;
  68. SharedPtr<Node> parentEnd_;
  69. VectorBuffer stateBegin_;
  70. VectorBuffer stateEnd_;
  71. PODVector<EditComponent*> components_;
  72. };
  73. PODVector<EditNode*> editNodes_;
  74. };
  75. }