Changeset View
Standalone View
source/graphics/MapReader.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
Freagarach: ++ | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 26 Lines | |||||
#include "ps/LoaderThunks.h" | #include "ps/LoaderThunks.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "renderer/PostprocManager.h" | #include "renderer/PostprocManager.h" | ||||
#include "renderer/SkyManager.h" | #include "renderer/SkyManager.h" | ||||
#include "renderer/WaterManager.h" | #include "renderer/WaterManager.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpCinemaManager.h" | #include "simulation2/components/ICmpCinemaManager.h" | ||||
#include "simulation2/components/ICmpGarrisonHolder.h" | |||||
#include "simulation2/components/ICmpObstruction.h" | #include "simulation2/components/ICmpObstruction.h" | ||||
#include "simulation2/components/ICmpOwnership.h" | #include "simulation2/components/ICmpOwnership.h" | ||||
#include "simulation2/components/ICmpPlayer.h" | #include "simulation2/components/ICmpPlayer.h" | ||||
#include "simulation2/components/ICmpPlayerManager.h" | #include "simulation2/components/ICmpPlayerManager.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | #include "simulation2/components/ICmpTerrain.h" | ||||
#include "simulation2/components/ICmpVisual.h" | #include "simulation2/components/ICmpVisual.h" | ||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | private: | ||||
CXeromyces xmb_file; | CXeromyces xmb_file; | ||||
CMapReader& m_MapReader; | CMapReader& m_MapReader; | ||||
int el_entity; | int el_entity; | ||||
int el_tracks; | int el_tracks; | ||||
int el_template, el_player; | int el_template, el_player; | ||||
int el_position, el_orientation, el_obstruction; | int el_position, el_orientation, el_obstruction; | ||||
int el_garrison; | |||||
int el_actor; | int el_actor; | ||||
int at_x, at_y, at_z; | int at_x, at_y, at_z; | ||||
int at_group, at_group2; | int at_group, at_group2; | ||||
int at_angle; | int at_angle; | ||||
int at_uid; | int at_uid; | ||||
int at_seed; | int at_seed; | ||||
XMBElementList nodes; // children of root | XMBElementList nodes; // children of root | ||||
Show All 33 Lines | void CXMLReader::Init(const VfsPath& xml_filename) | ||||
// (Needs to be synchronised with the list in CXMLReader - ugh) | // (Needs to be synchronised with the list in CXMLReader - ugh) | ||||
#define EL(x) el_##x = xmb_file.GetElementID(#x) | #define EL(x) el_##x = xmb_file.GetElementID(#x) | ||||
#define AT(x) at_##x = xmb_file.GetAttributeID(#x) | #define AT(x) at_##x = xmb_file.GetAttributeID(#x) | ||||
EL(entity); | EL(entity); | ||||
EL(tracks); | EL(tracks); | ||||
EL(template); | EL(template); | ||||
EL(player); | EL(player); | ||||
EL(position); | EL(position); | ||||
EL(garrison); | |||||
EL(orientation); | EL(orientation); | ||||
Done Inline ActionsNot sure what to do with these? (And above.) Freagarach: Not sure what to do with these? (And above.) | |||||
EL(obstruction); | EL(obstruction); | ||||
EL(actor); | EL(actor); | ||||
AT(x); AT(y); AT(z); | AT(x); AT(y); AT(z); | ||||
AT(group); AT(group2); | AT(group); AT(group2); | ||||
AT(angle); | AT(angle); | ||||
AT(uid); | AT(uid); | ||||
AT(seed); | AT(seed); | ||||
#undef AT | #undef AT | ||||
▲ Show 20 Lines • Show All 464 Lines • ▼ Show 20 Lines | while (entity_idx < entities.size()) | ||||
XMBAttributeList attrs = entity.GetAttributes(); | XMBAttributeList attrs = entity.GetAttributes(); | ||||
CStr uid = attrs.GetNamedItem(at_uid); | CStr uid = attrs.GetNamedItem(at_uid); | ||||
ENSURE(!uid.empty()); | ENSURE(!uid.empty()); | ||||
int EntityUid = uid.ToInt(); | int EntityUid = uid.ToInt(); | ||||
CStrW TemplateName; | CStrW TemplateName; | ||||
int PlayerID = 0; | int PlayerID = 0; | ||||
std::vector<entity_id_t> Garrison; | |||||
CFixedVector3D Position; | CFixedVector3D Position; | ||||
Done Inline Actionsentity_id_t Freagarach: entity_id_t | |||||
CFixedVector3D Orientation; | CFixedVector3D Orientation; | ||||
long Seed = -1; | long Seed = -1; | ||||
// Obstruction control groups. | // Obstruction control groups. | ||||
entity_id_t ControlGroup = INVALID_ENTITY; | entity_id_t ControlGroup = INVALID_ENTITY; | ||||
entity_id_t ControlGroup2 = INVALID_ENTITY; | entity_id_t ControlGroup2 = INVALID_ENTITY; | ||||
XERO_ITER_EL(entity, setting) | XERO_ITER_EL(entity, setting) | ||||
Show All 31 Lines | XERO_ITER_EL(entity, setting) | ||||
} | } | ||||
// <obstruction> | // <obstruction> | ||||
else if (element_name == el_obstruction) | else if (element_name == el_obstruction) | ||||
{ | { | ||||
XMBAttributeList attrs = setting.GetAttributes(); | XMBAttributeList attrs = setting.GetAttributes(); | ||||
ControlGroup = attrs.GetNamedItem(at_group).ToInt(); | ControlGroup = attrs.GetNamedItem(at_group).ToInt(); | ||||
ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt(); | ControlGroup2 = attrs.GetNamedItem(at_group2).ToInt(); | ||||
} | } | ||||
// <garrison> | |||||
else if (element_name == el_garrison) | |||||
{ | |||||
XMBElementList garrison = setting.GetChildNodes(); | |||||
Done Inline ActionsThis is obviously incorrect, but I do not know yet how to convert the XML information to the array. Freagarach: This is obviously incorrect, but I do not know yet how to convert the XML information to the… | |||||
Garrison.resize(garrison.size()); | |||||
Done Inline Actions(resize -> reserve, makes it a bit faster as it doesnt init each element) elexis: (resize -> reserve, makes it a bit faster as it doesnt init each element) | |||||
Done Inline ActionsIs this code wrong? elexis: Is this code wrong?
resize creates N elements, and then N elements are appended using… | |||||
Done Inline ActionsTrue. Freagarach: True. | |||||
for (const XMBElement& garr_ent : garrison) | |||||
Done Inline ActionsI guess you could set the size of Garison to avoid resizing since you already know the definite size. Can you use a range for loop? Something along the lines of for (const XMBElement& garr_ent : garrison) { XMBAttributeList attrs = garr_ent.GetAttributes(); Garrison.insert(attrs.GetNamedItem(at_gid).ToInt()); } Stan: I guess you could set the size of `Garison` to avoid resizing since you already know the… | |||||
Done Inline Actions
Hmm, I could not find a way to set the size actually? Freagarach: > I guess you could set the size of Garison to avoid resizing since you already know the… | |||||
{ | |||||
XMBAttributeList attrs = garr_ent.GetAttributes(); | |||||
Garrison.push_back(attrs.GetNamedItem(at_uid).ToInt()); | |||||
} | |||||
} | |||||
// <actor> | // <actor> | ||||
else if (element_name == el_actor) | else if (element_name == el_actor) | ||||
{ | { | ||||
XMBAttributeList attrs = setting.GetAttributes(); | XMBAttributeList attrs = setting.GetAttributes(); | ||||
CStr seedStr = attrs.GetNamedItem(at_seed); | CStr seedStr = attrs.GetNamedItem(at_seed); | ||||
if (!seedStr.empty()) | if (!seedStr.empty()) | ||||
{ | { | ||||
Seed = seedStr.ToLong(); | Seed = seedStr.ToLong(); | ||||
Show All 19 Lines | else | ||||
cmpPosition->SetYRotation(Orientation.Y); | cmpPosition->SetYRotation(Orientation.Y); | ||||
// TODO: other parts of the position | // TODO: other parts of the position | ||||
} | } | ||||
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent); | CmpPtr<ICmpOwnership> cmpOwnership(sim, ent); | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
cmpOwnership->SetOwner(PlayerID); | cmpOwnership->SetOwner(PlayerID); | ||||
if (Garrison.size()) | |||||
Done Inline Actionscan be just if (Garrison.size()) Silier: can be just `if (Garrison.size())` | |||||
Done Inline Actions(.empty) elexis: (.empty) | |||||
{ | |||||
CmpPtr<ICmpGarrisonHolder> cmpGarrisonHolder(sim, ent); | |||||
if (cmpGarrisonHolder) | |||||
cmpGarrisonHolder->SetInitEntities(Garrison); | |||||
else | |||||
LOGERROR("Map error in MapReader: entity '%d' of player '%d' has no GarrisonHolder component and can thus not garrison units.", ent, PlayerID); | |||||
Done Inline ActionsMaybe it should state that it has no garrisonholder component. One could also display the player set above if available. Stan: Maybe it should state that it has no garrisonholder component. One could also display the… | |||||
Done Inline Actions(Map error in MapReader -> CXMLReader::ReadEntities, compare with other LOGERRORs) elexis: (Map error in MapReader -> CXMLReader::ReadEntities, compare with other LOGERRORs) | |||||
Done Inline Actions(Not in this file.) Freagarach: (Not in this file.) | |||||
Garrison.clear(); | |||||
} | |||||
CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | CmpPtr<ICmpObstruction> cmpObstruction(sim, ent); | ||||
if (cmpObstruction) | if (cmpObstruction) | ||||
{ | { | ||||
if (ControlGroup != INVALID_ENTITY) | if (ControlGroup != INVALID_ENTITY) | ||||
cmpObstruction->SetControlGroup(ControlGroup); | cmpObstruction->SetControlGroup(ControlGroup); | ||||
if (ControlGroup2 != INVALID_ENTITY) | if (ControlGroup2 != INVALID_ENTITY) | ||||
cmpObstruction->SetControlGroup2(ControlGroup2); | cmpObstruction->SetControlGroup2(ControlGroup2); | ||||
▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines |
++