summaryrefslogtreecommitdiffstats
path: root/tools/statepropbuilder/apps/spbuilder/code/sp/engine/context.hpp
blob: faf88c0dafe5e3ecf3701fda08c67cfce7edc3d7 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * sp/engine/context.hpp
 */


#ifndef SP_ENGINE_CONTEXT_HPP
#define SP_ENGINE_CONTEXT_HPP


#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>

#include <radmath/radmath.hpp>
#include <p3d/p3dtypes.hpp>


class tEntity;
class tContext;
class tView;
class tPointCamera;
class tDirectionalLight;
class tPose;
class pddiShader;


//---------------------------------------------------------------------------
// class SPContext
//---------------------------------------------------------------------------

class SPContext
{
public:

    enum
    {
        MAX_FPS_COUNT = 10
    };

    SPContext(HWND hwnd);
    virtual ~SPContext();

    tContext* GetContext()
        { return m_Context; }

    bool Open();
    bool Close();

    bool ViewResize(int w, int h);

    bool Advance();
    bool Display();

    void MouseDown(int button, int shift, int x, int y);
    void MouseMove(int button, int shift, int x, int y);
    void MouseUp(int button, int shift, int x, int y);
    void MouseWheel(int scroll);

    float SimulationGetFPS() const;
    float SimulationGetRate() const
        { return m_SimRate; }
    void SimulationSetRate(float simRate);

    bool IsCameraLocked() const
        { return m_IsCameraLocked; }
    void SetIsCameraLocked(bool cameraLock)
        { m_IsCameraLocked = cameraLock; }
    tPointCamera* GetCamera() const
        { return m_Camera; }

    static bool GetEntityName(tEntity* entity, char* name, int maxLen);

    void InventoryClear();
    int InventoryGetEntityCount() const;
    bool InventoryGetEntityName(int index,
                                char* name, int nameLen,
                                char* type, int typeLen) const;

    void RenderPose(tPose* pose);
    void DrawAxes(const rmt::Matrix& m, float radius);
    void DrawLine(const rmt::Vector& a, const rmt::Vector& b, tColour c);

	void SetBackgroundColour( int r , int g , int b );

private:

    void CameraPan(int dx, int dy);
    void CameraZoom(int dz);
    void CameraRotate(int dx, int dy);

    HWND m_HWnd;

    tContext* m_Context;
    tView* m_View;
    tPointCamera* m_Camera;
    tDirectionalLight* m_Light;
    pddiShader* m_Shader;

    float m_CurrentTime;
    float m_FPS[MAX_FPS_COUNT];
    int m_FPSIndex;
    float m_SimRate;

    rmt::Vector m_CameraTarget;
    float m_CameraRotateX;
    float m_CameraRotateY;
    float m_CameraDistance;
    bool m_IsCameraLocked;

    int m_MouseCapture;
    int m_MouseX;
    int m_MouseY;
};


extern SPContext* g_SPContext;


#endif // SP_ENGINE_CONTEXT_HPP