summaryrefslogtreecommitdiffstats
path: root/include/system.hpp
blob: c907f1a139d4e57e48a094459e00547637244c55 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
#ifndef SYSTEM_HPP
#define SYSTEM_HPP 1

#include "ecs.hpp"
#include "camera.hpp"
#include "window.hpp"

#include <list>

class System {
private:
    friend class SystemView;
    struct SystemTreeNode {
        int entityId;
        std::list<SystemTreeNode> children;
    };
    SystemTreeNode m_systemTree;
    ecs::EntityMan m_entityMan;

    void addOrbital(const std::string &name, const std::string &orbitingName, unsigned long a, double e, unit::Mass m, unsigned r, double M, double w);
    void tickOrbitals(unit::Time time);

    SystemTreeNode *traverseSystemTree(SystemTreeNode &node, const std::string &name);
    SystemTreeNode *getNode(const std::string &name);
public:
    System(const std::string &name);

    void update();

    ecs::Entity &getBody(std::size_t id);
};

class SystemView {
private:
    System *m_system;
    System::SystemTreeNode *m_focus;

    class Search {
    private:
        struct SystemTreeDisplayNode {
            System::SystemTreeNode *node;
            std::list<SystemTreeDisplayNode> children;
            SystemTreeDisplayNode *parent;

            unsigned index;
            bool collapsed;
            bool hidden;
        };
        SystemView *m_systemView;
        SystemTreeDisplayNode m_displayTree;
        std::vector<SystemTreeDisplayNode*> m_displayTreeFlat;

        unsigned m_selectionIndex;
        std::string m_query;
        bool m_dirty;

        void addNodeToTree(SystemTreeDisplayNode &root, System::SystemTreeNode *node);
        void drawNode(SystemTreeDisplayNode &root, Window &searchWindow, unsigned indent);
        void rebuild();
    public:
        Search(SystemView *systemView);

        void finish();
        void keypress(int key);
        void draw();
    };
    std::unique_ptr<Search> m_focusSearch;
public:
    SystemView(System *system) : m_system(system), m_focusSearch(nullptr) {}

    void keypress(Camera *camera, int key);
    void update(Camera *camera);
    void draw(Camera *camera);
    void drawOver(Camera *camera);

    void view(System *system);

    ecs::Entity &getBody(int id) const;
    int getBodyIdByName(const std::string &name);
};

#endif