Rise
The Vieneo Province
Loading...
Searching...
No Matches
Bus.cpp
Go to the documentation of this file.
1#include "Bus.h"
2
3#include <algorithm>
4
5void Bus::AddCommand(const Command& command, bool onlyOne)
6{
7 if (onlyOne)
8 {
9 for (const auto& i : commandStream)
10 {
11 if (i.name == command.name)
12 return;
13 }
14 }
15
16 // rather than sorting we just insert it at the correct position in the stack
17 auto pos = std::upper_bound(commandStream.begin(), commandStream.end(), command);
18 commandStream.emplace(pos, command);
19}
20
21void Bus::FrameMove(float fElapsed)
22{
23 logger->AddToCallStack("Bus::FrameMove");
24
25 for (auto it = commandStream.begin(); it != commandStream.end(); )
26 {
27 Command& command = *it;
28 command.delay -= fElapsed;
29 if (command.delay <= 0)
30 {
31 command.timeOnStack += fElapsed;
32 if (command.timeOnStack > command.ttl)
33 {
34 char msg[199];
35 sprintf_s(msg, sizeof msg, "Bus::FrameMove Command sat on the stack for too long (%.1fs): %s", command.ttl, command.name.c_str());
36 logger->Log(msg, Logger::Warn);
37 it = commandStream.erase(it);
38 continue;
39 }
40
41 if (command.name == "ScanCargoBay")
42 {
44 it = commandStream.erase(it);
45 continue;
46 }
47 }
48
49 ++it;
50 }
51
52 logger->AddToCallStack("Bus::FrameMove DONE");
53}
54
55Bus::Bus(Logger* prmLogger)
56{
57 GetSystemTime(&Time);
58
59 logger = prmLogger;
60 commandStream.reserve(16);
61 ZeroMemory(CargoBays, sizeof CargoBays);
63 WPtargetC = 0L; // current selected, comes from server now
64 for (int i = 0; i < MAX_ENGINES; i++)
65 {
66 EngineThrustOutput[i] = 0.0f;
67 EngineThrustLever[i] = 0.0f;
68 ThrustReverserCommand[i] = false;
69 }
70 ZeroMemory(&assayGrid, sizeof SAssayGrid);
71}
#define MAX_ENGINES
scanDb Scanner
Definition Bus.h:484
float EngineThrustOutput[MAX_ENGINES]
Definition Bus.h:54
void FrameMove(float fElapsed)
Definition Bus.cpp:21
Bus(Logger *prmLogger)
Definition Bus.cpp:55
Logger * logger
Definition Bus.h:21
float EngineThrustLever[MAX_ENGINES]
Definition Bus.h:357
_SYSTEMTIME Time
Definition Bus.h:28
void AddCommand(const Command &command, bool onlyOne)
Definition Bus.cpp:5
SAssayGrid assayGrid
Definition Bus.h:494
int WPtargetC
Definition Bus.h:499
bool ThrustReverserCommand[MAX_ENGINES]
Definition Bus.h:72
unsigned short CargoBays[MAX_BAYSPERSHIP]
Definition Bus.h:465
std::vector< Command > commandStream
Definition Bus.h:442
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
@ Warn
Definition Logger.h:26
int CurrentScanTarget
Definition scanDb.h:66
scanDb()=default
float timeOnStack
Definition Command.h:14
int ivalues[2]
Definition Command.h:21
std::string name
Definition Command.h:11
float delay
Definition Command.h:8
float ttl
Definition Command.h:17