-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmastercontrol.h
198 lines (175 loc) · 6.43 KB
/
mastercontrol.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* heXon
// Copyright (C) 2015 LucKey Productions (luckeyproductions.nl)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MASTERCONTROL_H
#define MASTERCONTROL_H
#include <Urho3D/Urho3D.h>
#include <Urho3D/Scene/LogicComponent.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Container/HashMap.h>
#include <Urho3D/Engine/Application.h>
#include <Urho3D/Graphics/Viewport.h>
#include <Urho3D/Graphics/Renderer.h>
#include <Urho3D/UI/UI.h>
#include <Urho3D/Physics/RigidBody.h>
#include <Urho3D/Physics/PhysicsWorld.h>
#include <Urho3D/Engine/Engine.h>
#include <Urho3D/Engine/Console.h>
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/DebugRenderer.h>
#include <Urho3D/Engine/DebugHud.h>
#include <Urho3D/DebugNew.h>
#include <Urho3D/UI/Text.h>
#include <Urho3D/UI/Font.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/Physics/PhysicsWorld.h>
#include <Urho3D/Physics/CollisionShape.h>
#include <Urho3D/Graphics/Model.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Light.h>
#include <Urho3D/Graphics/Camera.h>
#include <Urho3D/Graphics/Material.h>
#include <Urho3D/Graphics/RenderPath.h>
#include <Urho3D/IO/FileSystem.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Resource/XMLFile.h>
#include <Urho3D/Resource/Resource.h>
#include <Urho3D/Audio/Sound.h>
#include <Urho3D/Audio/SoundSource.h>
#include <Urho3D/IO/Log.h>
#include <Urho3D/Scene/SceneEvents.h>
#include <Urho3D/Core/CoreEvents.h>
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Graphics/OctreeQuery.h>
#include <Urho3D/Graphics/Zone.h>
namespace Urho3D {
class Drawable;
class Node;
class Scene;
class Sprite;
}
using namespace Urho3D;
class heXoCam;
class InputMaster;
class TileMaster;
class SpawnMaster;
class Razor;
class Player;
class Apple;
class Heart;
typedef struct GameWorld
{
SharedPtr<heXoCam> camera;
SharedPtr<Scene> scene;
float lastReset;
SharedPtr<Octree> octree;
SharedPtr<Node> backdropNode;
SharedPtr<Node> voidNode;
struct {
SharedPtr<Node> sceneCursor;
SharedPtr<Cursor> uiCursor;
PODVector<RayQueryResult> hitResults;
} cursor;
} GameWorld;
typedef struct HitInfo
{
Vector3 position_;
Vector3 hitNormal_;
Node* hitNode_;
Drawable* drawable_;
} HitInfo;
namespace {
StringHash const N_VOID = StringHash("Void");
StringHash const N_ARENAEDGE = StringHash("ArenaEdge");
StringHash const N_CURSOR = StringHash("Cursor");
StringHash const N_TILE = StringHash("Tile");
StringHash const N_PLAYER = StringHash("Player");
StringHash const N_APPLE = StringHash("Apple");
StringHash const N_HEART = StringHash("Heart");
StringHash const N_SEEKER = StringHash("Seeker");
StringHash const N_SPIRE = StringHash("Spire");
StringHash const N_RAZOR = StringHash("Razor");
}
enum JoyStickButton {JB_SELECT, JB_LEFTSTICK, JB_RIGHTSTICK, JB_START, JB_DPAD_UP, JB_DPAD_RIGHT, JB_DPAD_DOWN, JB_DPAD_LEFT, JB_L2, JB_R2, JB_L1, JB_R1, JB_TRIANGLE, JB_CIRCLE, JB_CROSS, JB_SQUARE};
class MasterControl : public Application
{
/// Enable type information.
OBJECT(MasterControl);
public:
/// Constructor.
MasterControl(Context* context);
GameWorld world;
SharedPtr<PhysicsWorld> physicsWorld_;
SharedPtr<ResourceCache> cache_;
SharedPtr<Graphics> graphics_;
SharedPtr<UI> ui_;
SharedPtr<Renderer> renderer_;
SharedPtr<XMLFile> defaultStyle_;
SharedPtr<TileMaster> tileMaster_;
SharedPtr<InputMaster> inputMaster_;
SharedPtr<SpawnMaster> spawnMaster_;
SharedPtr<Player> player_;
SharedPtr<Apple> apple_;
SharedPtr<Heart> heart_;
/// Setup before engine initialization. Modifies the engine paramaters.
virtual void Setup();
/// Setup after engine initialization.
virtual void Start();
/// Cleanup after the main loop. Called by Application.
virtual void Stop();
void Exit();
void CreateSineLookupTable();
double Sine(double x) { return sine_[(int)round(sine_.Length() * Cycle(x/M_PI, 0.0, 1.0))%sine_.Length()]; }
float Sine(float x) { return sine_[(int)round(sine_.Length() * Cycle(x/M_PI, 0.0, 1.0))%sine_.Length()]; }
double Sine(double freq, double min, double max, double shift = 0.0);
float Sine(float freq, float min, float max, float shift = 0.0f);
bool GetPaused() { return paused_; }
void SetPaused(bool paused) { paused_ = paused; world.scene->SetUpdateEnabled(!paused);}
void Pause() { SetPaused(true);}
void Unpause() { SetPaused(false); }
/// Edit-mode flag
bool editMode_;
bool PhysicsRayCast(PODVector<PhysicsRaycastResult> &hitResults, Urho3D::Ray ray, float distance, unsigned collisionMask);
bool PhysicsSphereCast(PODVector<RigidBody *> &hitResults, Vector3 center, float radius, unsigned collisionMask);
void Restart();
private:
/// Set custom window title and icon
void SetWindowTitleAndIcon();
/// Create console and debug HUD
void CreateConsoleAndDebugHud();
/// Construct the scene content.
void CreateScene();
/// Construct user interface elements.
void CreateUI();
/// Subscribe to application-wide logic update and post-render update events.
void SubscribeToEvents();
/// Handle scene update event to control camera's pitch and yaw.
void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
/// Handle the logic update event.
void HandleUpdate(StringHash eventType, VariantMap& eventData);
/// Handle the post-render update event.
void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
/// Update the cursor
void UpdateCursor(double timeStep);
/// Utility function to raycast to the cursor position. Return true if hit.
bool CursorRayCast(double maxDistance, PODVector<RayQueryResult> &hitResults);
/// Pause flag
bool paused_;
///Sine lookup table
Vector<double> sine_;
};
#endif