File: InfoConsole.h

package info (click to toggle)
spring 106.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,260 kB
  • sloc: cpp: 543,946; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (104 lines) | stat: -rw-r--r-- 2,287 bytes parent folder | download | duplicates (3)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef INFO_CONSOLE_H
#define INFO_CONSOLE_H

#include "InputReceiver.h"
#include "System/float3.h"
#include "System/EventClient.h"
#include "System/Log/LogSinkHandler.h"
#include "System/Misc/SpringTime.h"
#include "System/Threading/SpringThreading.h"

#include <array>
#include <deque>
#include <string>

class CInfoConsole: public CInputReceiver, public CEventClient, public ILogSink
{
public:
	static void InitStatic();
	static void KillStatic();

	CInfoConsole(): CEventClient("InfoConsole", 999, false) { Init(); }
	~CInfoConsole() { Kill(); }

	void Init();
	void Kill();

	void Update() override;
	void Draw() override;
	void PushNewLinesToEventHandler();

	void RecordLogMessage(int level, const std::string& section, const std::string& message) override;

	bool WantsEvent(const std::string& eventName) override {
		return (eventName == "LastMessagePosition");
	}
	void LastMessagePosition(const float3& pos) override;
	const float3& GetMsgPos(const float3& defaultPos = ZeroVector);
	unsigned int GetMsgPosCount() const { return lastMsgPositions.size(); }

public:
	struct RawLine {
		RawLine(const std::string& text, const std::string& section, int level,
				int id)
			: text(text)
			, section(section)
			, level(level)
			, id(id)
			{}
		std::string text;
		std::string section;
		int level;
		int id;
	};

	size_t GetRawLines(std::vector<RawLine>& copy);

private:
	static constexpr size_t maxMsgCount = 10;
	static constexpr size_t maxRawLines = 1024;

	struct InfoLine {
		std::string text;
		spring_time timeout;
	};

	std::array<float3, maxMsgCount> lastMsgPositions;

	std::vector<RawLine> tmpLines;
	std::vector<InfoLine> tmpInfoLines;
	std::deque<RawLine> rawLines;
	std::deque<InfoLine> infoLines;

	std::string prvSection;
	std::string prvMessage;

	spring::recursive_mutex infoConsoleMutex;

	size_t maxLines = 1;
	size_t newLines = 0;

	size_t msgPosIndx = 0;
	size_t numPosMsgs = 0;

	int rawId = 0;
	int lifetime = 0;

	float xpos = 0.0f;
	float ypos = 0.0f;
	float width = 0.0f;
	float height = 0.0f;

	float fontScale = 1.0f;
	float fontSize = 0.0f;

public:
	bool enabled = true;
	bool inited = false;
};

extern CInfoConsole* infoConsole;

#endif /* INFO_CONSOLE_H */