Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-11-13 14:25:39 +0000
committerStijn Buys <ingar@osirion.org>2010-11-13 14:25:39 +0000
commit871be21e83502a909620a5bcfcd09e3257ed0518 (patch)
tree8aee5b25fd5c3d43e55e1b92e114acca58c1172a /src/core
parent650cca5da5e15b9d4a85e7f734515f538b0cc0f3 (diff)
corrected a bug where ship names got erased,
made core::Entity::info() const, added core::Info::find() to get non-const *core::Info pointers
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc10
-rw-r--r--src/core/entity.h6
-rw-r--r--src/core/info.cc12
-rw-r--r--src/core/info.h25
-rw-r--r--src/core/parser.cc9
5 files changed, 42 insertions, 20 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 35164dc..013e66d 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -266,13 +266,9 @@ void Entity::clear_updates()
}
}
-void Entity::set_info(Info *info)
+void Entity::set_info(const Info *info)
{
entity_info = info;
- if (entity_info) {
- entity_info->set_model(model());
- entity_info->set_name(name());
- }
}
void Entity::set_inventory(Inventory *inventory)
@@ -318,10 +314,6 @@ void Entity::set_model(model::Model *model)
if (entity_model) {
entity_modelname.assign(entity_model->name());
}
-
- if (entity_info) {
- entity_info->set_model(entity_model);
- }
}
void Entity::set_modelname(const std::string &modelname)
diff --git a/src/core/entity.h b/src/core/entity.h
index 1996e10..5c34f97 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -194,7 +194,7 @@ public:
}
/// entity info
- inline Info *info() const {
+ inline const Info *info() const {
return entity_info;
}
@@ -328,7 +328,7 @@ public:
*/
void set_inventory(Inventory *inventory);
- void set_info(Info *info);
+ void set_info(const Info *info);
/// set the timestamp when the entity was last alive
void set_keepalive(unsigned long timestamp) {
@@ -492,7 +492,7 @@ private:
Menus entity_menus;
Inventory* entity_inventory;
- Info* entity_info;
+ const Info* entity_info;
Extension* entity_extension[4];
diff --git a/src/core/info.cc b/src/core/info.cc
index cc1720e..2ff6669 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -243,6 +243,18 @@ void Info::print() const
Info::Registry Info::info_registry;
+Info *Info::find(const Info *info)
+{
+ if (!info)
+ return 0;
+
+ for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
+ if (info == (*it));
+ return *it;
+ }
+ return 0;
+}
+
Info *Info::find(unsigned int id)
{
if (!id)
diff --git a/src/core/info.h b/src/core/info.h
index b8154d7..d32ccab 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -191,23 +191,38 @@ private:
/* ---- static info registry --------------------------------------- */
public:
- /// info registry type definition
+ /**
+ * @brief info registry type definition
+ */
typedef std::vector<Info*> Registry;
- /// the info registry
+ /**
+ * @brief the info registry
+ */
static inline Registry & registry() {
return info_registry;
}
- /// search the info registry for a record with the specified id
+ /**
+ * @brief search the info registry for a record with the specified id
+ */
static Info *find(const unsigned int id);
- /// search the info registry for a labeled item
+ /**
+ * @brief search the info registry for a labeled item
+ */
static Info *find(const char * label);
- /// search the info registry for a label
+ /**
+ * @brief search the info registry for a label
+ */
static Info *find(const std::string & label);
+ /**
+ * @brief search the info register for a pointer
+ */
+ static Info *find(const Info *info);
+
/// search the info registry for a record with a matching label or name
static Info *search(const std::string & searchstr);
diff --git a/src/core/parser.cc b/src/core/parser.cc
index 953cd50..22b2fc3 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -47,10 +47,13 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
}
} else if (inifile.got_key_string("info", strval)) {
- if (!entity->info()) {
- entity->set_info(new Info(Entity::infotype(), entity->label().c_str()));
+
+ Info *info = Info::find(entity->info());
+ if (!info) {
+ info = new Info(Entity::infotype(), entity->label().c_str());
+ entity->set_info(info);
}
- entity->info()->add_text(strval);
+ info->add_text(strval);
return true;
} else if (inifile.got_key_label("label", strval)) {