SceneEditOp.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // Erases a node from the edit op, return true if no other nodes in the operation
  55. bool EraseNode(Node *node);
  56. bool Commit();
  57. private:
  58. struct EditComponent
  59. {
  60. SharedPtr<Component> component_;
  61. SharedPtr<Node> nodeBegin_;
  62. SharedPtr<Node> nodeEnd_;
  63. VectorBuffer stateBegin_;
  64. VectorBuffer stateEnd_;
  65. };
  66. struct EditNode
  67. {
  68. SharedPtr<Node> node_;
  69. SharedPtr<Node> parentBegin_;
  70. SharedPtr<Node> parentEnd_;
  71. VectorBuffer stateBegin_;
  72. VectorBuffer stateEnd_;
  73. PODVector<EditComponent*> components_;
  74. };
  75. PODVector<EditNode*> editNodes_;
  76. };
  77. }