-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmastercontrol.cpp
More file actions
117 lines (93 loc) · 2.83 KB
/
mastercontrol.cpp
File metadata and controls
117 lines (93 loc) · 2.83 KB
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
#include "effectmaster.h"
#include "inputmaster.h"
#include "player.h"
#include "spawnmaster.h"
#include "fishmaster.h"
#include "uimaster.h"
#include "localfisher.h"
#include "mastercontrol.h"
URHO3D_DEFINE_APPLICATION_MAIN(MasterControl);
MasterControl* MasterControl::instance_ = NULL;
MasterControl* MasterControl::GetInstance()
{
return MasterControl::instance_;
}
MasterControl::MasterControl(Context *context):
Application(context)
{
instance_ = this;
}
void MasterControl::Setup()
{
SetRandomSeed(TIME->GetSystemTime());
engineParameters_[EP_LOG_NAME] = GetSubsystem<FileSystem>()->GetAppPreferencesDir("luckey", "logs") + "theFin2.log";
engineParameters_[EP_WINDOW_TITLE] = "theFin2";
engineParameters_[EP_WINDOW_ICON] = "Textures/UrhoIcon.png";
engineParameters_[EP_WORKER_THREADS] = false;
engineParameters_[EP_RESOURCE_PATHS] = "Data;CoreData;Add1";
engineParameters_[EP_FULL_SCREEN] = false;
}
void MasterControl::Start()
{
RegisterSubsystem<EffectMaster>();
RegisterSubsystem<InputMaster>();
RegisterSubsystem<SpawnMaster>();
RegisterSubsystem<FishMaster>();
RegisterSubsystem<UIMaster>();
// Get actual environment from IDE...
char* local_fisher_path = getenv("LOCAL_FISH_PATH");
if (!local_fisher_path) {
// Otherwise assuming cross-compiling & running in target
local_fisher_path = strdup("/");
Log::Write(LOG_INFO, "Assuming target execution");
} else {
Log::Write(LOG_WARNING, "Assuming host execution");
}
LocalFisher* lf = new LocalFisher(context_, local_fisher_path);
GetSubsystem<FishMaster>()->RegisterFisher(*lf);
Vector<Fish> fishes = GetSubsystem<FishMaster>()->RetrieveFishes();
if (GRAPHICS)
ENGINE->SetMaxFps(GRAPHICS->GetRefreshRate());
GetSubsystem<UIMaster>()->CreateScene();
}
Scene*
MasterControl::GetScene() const
{
return GetSubsystem<UIMaster>()->GetScene();
}
void MasterControl::Stop()
{
engine_->DumpResources(true);
}
void MasterControl::Exit()
{
engine_->Exit();
}
Vector<SharedPtr<Player> > MasterControl::GetPlayers()
{
return players_;
}
Player* MasterControl::GetPlayer(int playerId) const
{
for (Player* p : players_) {
if (p->GetPlayerId() == playerId){
return p;
}
}
return nullptr;
}
Player* MasterControl::GetNearestPlayer(Vector3 pos)
{
Player* nearest{};
for (Player* p : players_){
if (p->IsAlive()){
if (!nearest
|| (LucKey::Distance(GetSubsystem<InputMaster>()->GetControllableByPlayer(p->GetPlayerId())->GetWorldPosition(), pos) <
LucKey::Distance(GetSubsystem<InputMaster>()->GetControllableByPlayer(nearest->GetPlayerId())->GetWorldPosition(), pos)))
{
nearest = p;
}
}
}
return nearest;
}