-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneNode.hpp
71 lines (54 loc) · 1.94 KB
/
SceneNode.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef SCENE_NODE_HPP
#define SCENE_NODE_HPP
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <vector>
#include <set>
#include <memory>
#include <cassert>
#include "Category.hpp"
#include "Command.hpp"
#include "CommandQueue.hpp"
#include "Utility.hpp"
class SceneNode : public sf::Transformable, public sf::Drawable, private sf::NonCopyable
{
public:
typedef std::unique_ptr<SceneNode> Ptr;
typedef std::pair<SceneNode *, SceneNode *> Pair;
public:
SceneNode(Category::Type category = Category::None);
void attachChild(Ptr child);
Ptr detachChild(const SceneNode &node);
void update(sf::Time dt, CommandQueue &commands);
sf::Vector2f getWorldPosition() const;
sf::Transform getWorldTransform() const;
virtual unsigned int getCategory() const;
void onCommand(const Command &command, sf::Time dt);
void removeWrecks();
virtual sf::FloatRect getBoundingRect() const;
virtual bool isDestroyed() const;
virtual bool isMarkedForRemoval() const;
void checkNodeCollision(SceneNode &node, std::set<Pair> &collisionPairs);
void checkSceneCollision(SceneNode &sceneGraph, std::set<Pair> &collisionPairs);
private:
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
virtual void drawCurrent(sf::RenderTarget &target, sf::RenderStates states) const;
virtual void updateCurrent(sf::Time dt, CommandQueue &commands);
void updateChildren(sf::Time dt, CommandQueue &commands);
void drawBoundingRect(sf::RenderTarget &target, sf::RenderStates) const;
private:
std::vector< Ptr > mChildren;
SceneNode *mParent;
Category::Type mDefaultCategory;
};
inline float distance(const SceneNode &lhs, const SceneNode &rhs)
{
return length(lhs.getWorldPosition() - rhs.getWorldPosition());
}
inline bool collision(const SceneNode &lhs, const SceneNode &rhs)
{
return lhs.getBoundingRect().intersects(rhs.getBoundingRect());
}
#endif