blob: 9f1fab866aa833dac4a9583c33b306830723294c (
plain)
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
|
/*
core/info.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CORE_INFO_H__
#define __INCLUDED_CORE_INFO_H__
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include "model/model.h"
namespace core
{
/**
* @brief an information record
* An information record holds extended information about a specific entity or item class.
* This information isexchanged between server and the client, and can be used to build
* HUD widgets/
*/
class Info
{
public:
/// type definition for the text description
typedef std::deque<std::string> Text;
/// create a new labeled information record
Info();
/// create a new labeled information record
Info(const std::string & label);
Info(const unsigned int id);
/// delete the information record
~Info();
/* ---- inspectors ------------------------------------------------- */
inline const unsigned int id() const {
return info_id;
}
inline const std::string & label() const {
return info_label;
}
inline const std::string & name() const {
return info_name;
}
inline const std::string & modelname() const {
return info_modelname;
}
inline const model::Model *model() const {
return info_model;
}
inline const unsigned long ×tamp() const {
return info_timestamp;
}
/// text description
inline Text & text() {
return info_text;
}
/* ---- mutators --------------------------------------------------- */
void set_label(const std::string & name);
void set_label(const char *name);
void set_name(const std::string & name);
void set_name(const char *name);
void set_modelname(const std::string & modelname);
void set_modelname(const char *modelname);
void set_model(const model::Model *model);
/// set the timestamp
void set_timestamp(const unsigned long timestamp);
/// add a line of info text
void add_text(const std::string & text);
/// clear the info text
void clear_text();
/// print info to sys::con_out
void print() const;
/// clear the timestamp
void clear_timestamp();
/// add a line of info text
void add_text(const char *text);
/* ---- serializers ------------------------------------------------ */
/// serialize a server-to-client update on a stream
void serialize_server_update(std::ostream & os) const;
/// receive a server-to-client update from a stream
void receive_server_update(std::istream &is);
private:
unsigned int info_id;
std::string info_label;
std::string info_name;
std::string info_modelname;
const model::Model* info_model;
long info_credits;
unsigned long info_timestamp;
Text info_text;
/* ---- static info registry --------------------------------------- */
public:
/// info registry type definition
typedef std::vector<Info*> Registry;
/// the info registry
static inline Registry & registry() {
return info_registry;
}
/// search the info registry for a labeled item
static Info *find(const char * label);
/// search the info registry for a label
static Info *find(const std::string & label);
/// search the info registry for an id
static Info *find(const unsigned int id);
/// clear the info registry
static void clear();
/// list the info registry
static void list();
private:
/// add a record to the info registry
static void add(Info *info);
static Registry info_registry;
static unsigned int static_info_id_counter;
};
}
#endif // __INCLUDED_CORE_INFO_H__
|