Avionics
Dropship Simulator
PFD.cpp
Go to the documentation of this file.
1 #include "Module.h"
2 
3 Pfd::Pfd(Bus* prmBus, Logger* prmLogger) : Module(prmBus)
4 {
5  logger = prmLogger;
6  for (int i = 0; i < 10; i++)
7  {
8  lights[i].currentState = false;
9  lights[i].requestedState = false;
10  lights[i].strategy = rand() % 10 == 0 ? 1 : 2;
11  switch (i)
12  {
13  case 0: lights[i].command = "pfd3";
14  break;
15  case 1: lights[i].command = "pfd4";
16  break;
17  case 2: lights[i].command = "pfd5";
18  break;
19  case 3: lights[i].command = "pfd6";
20  break;
21  case 4: lights[i].command = "pfd7";
22  break;
23  case 5: lights[i].command = "pfd11";
24  break;
25  case 6: lights[i].command = "pfd12";
26  break;
27  case 7: lights[i].command = "pfd13";
28  break;
29  case 8: lights[i].command = "pfd14";
30  break;
31  case 9: lights[i].command = "pfd15";
32  break;
33  }
34  }
35 }
36 
37 void Pfd::FrameMove(float fElapsedTime)
38 {
39  bool flip = false;
40  timer += fElapsedTime;
41  if (timer > 1.0f)
42  {
43  timer -= 1.0f;
44  flip = true;
45  if (rand() % 5) // every 5 seconds we will change one of the 10 lights' strategies
46  {
47  lights[rand() % 10].strategy = rand() % 10 == 0 ? 1 : 2;
48  }
49  }
50 
51  for (int i = 0; i < 10; i++)
52  {
53  switch (lights[i].strategy)
54  {
55  case 0: lights[i].requestedState = false;
56  break;
57  case 1: if (flip) lights[i].requestedState = !lights[i].requestedState;
58  break;
59  case 2: lights[i].requestedState = true;
60  break;
61  }
62 
63  if (lights[i].requestedState != lights[i].currentState)
64  {
66  Command command = Command();
67  command.bvalue = lights[i].currentState;
68  command.name = lights[i].command;
69  bus->commandStream.push_back(command);
70  }
71  }
72 }
void FrameMove(float fElapsedTime) override
Definition: PFD.cpp:37
bool currentState
Definition: Module.h:225
bool requestedState
Definition: Module.h:225
Pfd(Bus *prmBus, Logger *prmLogger)
Definition: PFD.cpp:3
std::vector< Command > commandStream
Definition: Bus.h:20
Definition: Logger.h:5
Definition: Bus.h:12
std::string name
command name
Definition: Command.h:11
std::string command
Definition: Module.h:224
Abstract base class for modules By definition, instruments don&#39;t do any of the work (they don&#39;t modif...
Definition: Module.h:11
Definition: Command.h:5
struct Pfd::SLight lights[10]
bool bvalue
Definition: Command.h:23
Bus * bus
Definition: Module.h:17
float timer
Definition: Module.h:229
int strategy
Definition: Module.h:226
Logger * logger
Definition: Module.h:220