void Selection::saveGame(XmlNode *rootNode) const { std::map<string,string> mapTagReplacements; XmlNode *selectionNode = rootNode->addChild("Selection"); selectionNode->addAttribute("factionIndex",intToStr(factionIndex), mapTagReplacements); selectionNode->addAttribute("teamIndex",intToStr(teamIndex), mapTagReplacements); selectionNode->addAttribute("allowSharedTeamUnits",intToStr(allowSharedTeamUnits), mapTagReplacements); for(unsigned int i = 0; i < selectedUnits.size(); i++) { Unit *unit = selectedUnits[i]; XmlNode *selectedUnitsNode = selectionNode->addChild("selectedUnits"); selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements); } for(unsigned int x = 0; x < (unsigned int)maxGroups; ++x) { XmlNode *groupsNode = selectionNode->addChild("groups"); for(unsigned int i = 0; i < (unsigned int)groups[x].size(); ++i) { Unit *unit = groups[x][i]; XmlNode *selectedUnitsNode = groupsNode->addChild("selectedUnits"); selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements); } } }
void Upgrade::saveGame(XmlNode *rootNode) { std::map<string,string> mapTagReplacements; XmlNode *upgradeNode = rootNode->addChild("Upgrade"); upgradeNode->addAttribute("state",intToStr(state), mapTagReplacements); upgradeNode->addAttribute("factionIndex",intToStr(factionIndex), mapTagReplacements); upgradeNode->addAttribute("type",type->getName(), mapTagReplacements); }
void Resource::saveGame(XmlNode *rootNode) const { std::map<string,string> mapTagReplacements; XmlNode *resourceNode = rootNode->addChild("Resource"); // int amount; resourceNode->addAttribute("amount",intToStr(amount), mapTagReplacements); // const ResourceType *type; resourceNode->addAttribute("type",type->getName(), mapTagReplacements); // Vec2i pos; resourceNode->addAttribute("pos",pos.getString(), mapTagReplacements); // int balance; resourceNode->addAttribute("balance",intToStr(balance), mapTagReplacements); }
void Object::saveGame(XmlNode *rootNode) { std::map<string,string> mapTagReplacements; XmlNode *objectNode = rootNode->addChild("Object"); // ObjectType *objectType; if(objectType != NULL) { objectNode->addAttribute("objectType",intToStr(objectType->getClass()), mapTagReplacements); } // vector<UnitParticleSystem*> unitParticleSystems; for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) { UnitParticleSystem *ptr= unitParticleSystems[i]; if(ptr != NULL) { ptr->saveGame(objectNode); } } // Resource *resource; if(resource != NULL) { resource->saveGame(objectNode); } // Vec3f pos; objectNode->addAttribute("pos",pos.getString(), mapTagReplacements); // float rotation; objectNode->addAttribute("rotation",floatToStr(rotation,6), mapTagReplacements); // int variation; objectNode->addAttribute("variation",intToStr(variation), mapTagReplacements); // int lastRenderFrame; objectNode->addAttribute("lastRenderFrame",intToStr(lastRenderFrame), mapTagReplacements); // Vec2i mapPos; objectNode->addAttribute("mapPos",mapPos.getString(), mapTagReplacements); // bool visible; objectNode->addAttribute("visible",intToStr(visible), mapTagReplacements); }
void Display::saveGame(XmlNode *rootNode) const { std::map<string,string> mapTagReplacements; XmlNode *displayNode = rootNode->addChild("Display"); // string title; displayNode->addAttribute("title",title, mapTagReplacements); // string text; displayNode->addAttribute("text",text, mapTagReplacements); // string infoText; displayNode->addAttribute("infoText",infoText, mapTagReplacements); // const Texture2D *upImages[upCellCount]; // const Texture2D *downImages[downCellCount]; // bool downLighted[downCellCount]; // const CommandType *commandTypes[downCellCount]; // CommandClass commandClasses[downCellCount]; // int progressBar; displayNode->addAttribute("progressBar",intToStr(progressBar), mapTagReplacements); // int downSelectedPos; displayNode->addAttribute("downSelectedPos",intToStr(downSelectedPos), mapTagReplacements); // Vec4f colors[colorCount]; // int currentColor; displayNode->addAttribute("currentColor",intToStr(currentColor), mapTagReplacements); // int upCellSideCount; // int upImageSize; // int maxUpIndex; }
XmlNode * XmlReader::parseTag (char c) { c = skipSpaces (); // '<' has been eaten to check for a comment bool closing = false; if (c == '/') { // ending tag closing = true; c = getNextChar (); } char * name = getNextToken (); if (name == NULL) { MESSAGE ("Error: XML tags must start with an alpha caracter !'"); m_failure = true; return NULL; } XmlNode * e = new XmlNode (name, closing ? CLOSE_TAG : OPEN_TAG); if (!closing) { // may have some attributes XmlAttribute * attr = parseAttribute (); while (attr != NULL) { e->addAttribute (attr); attr = parseAttribute (); } } // final '>' c = getChar (); if (c == '/') { // self tag if (closing) { delete e; MESSAGE ("Error: closing is also self closing: %s", e->m_name); m_failure = true; return NULL; } e->m_type = SELF_TAG; c = getNextChar (); } // check for nodes that shoudl be self closing: BR, HR, IMG // if (m_htmlMode && e->m_type == OPEN_TAG) { // e.m_type = checkHtmlSelfClosing(e.m_name); // } if (c != '>') { // ending tag delete e; MESSAGE ("Error: got '%c' instead of '>'", c); m_failure = true; return NULL; } getNextChar (); // eat '>' return e; }
void XmlReader::readAttribute(char** ipp) { char* ip = *ipp; readAttributeName(&ip, attrName); char quote = ip[1]; if (*ip != '=' || (quote != '\'' && quote != '"')) error("error in tag attribute, expected ' or \""); ip += 2; readAttributeValue(&ip, attrValue, quote); if (*ip != quote) error(string("error in tag value, expected: ") + quote); ++ip; XmlNode* current = stack.top(); if (current->hasAttribute(attrName)) error(string("duplicate attribute: ") + attrName); current->addAttribute(attrName, attrValue); *ipp = ip; }
XmlNode * parseNode () { int type = fgetc (m_fp); if (type == 3) { char * data = decodeString (); return new XmlNode (data, CDATA); } else if (type > 0) { int index = decodeSize (); XmlNode * n = new XmlNode (m_tags[index], type == 1 ? OPEN_TAG : SELF_TAG); // parse attribute int attrIdx = decodeSize (); // index of first attibute while (attrIdx != 0) { char * value = decodeString (); n->addAttribute (new XmlAttribute (m_tags[attrIdx-1], value)); attrIdx = decodeSize (); // index of next attibute } XmlNode * child = parseNode (); while (child != NULL) { n->addChild (child); child = parseNode (); } return n; } return NULL; }
/////////////////////////////////////////////////////////////////////////////////////////////////// //parse data schema from node //src data node //dst schema node bool XmlSchema::parseNodeStruct(XmlNode* dst, XmlNode* src) { assert(dst != NULL); assert(src != NULL); NodeIterator nodeIterator; AttributeIterator attriIterator; for (XmlAttribute* attribute = src->getFirstAttribute(attriIterator); attribute != NULL; attribute = src->getNextAttribute(attriIterator)) { XmlNode* structure = dst->findChild(attribute->getName()); if (structure == NULL) { //first time show up structure = dst->addChild(attribute->getName()); structure->addAttribute(ATTR_TYPE, guessType(attribute->getString())); structure->addAttribute(ATTR_ATTRIBUTE, T("true")); } } for (XmlNode* child = src->getFirstChild(nodeIterator); child != NULL; child = src->getNextChild(nodeIterator)) { if (child->getType() != ELEMENT) { continue; } XmlNode* structure = dst->findChild(child->getName()); if (structure == NULL) { //first time show up bool recursive = false; const XmlNode* parent = dst; while (parent != NULL) { if (Strcmp(parent->getName(), child->getName()) == 0) { recursive = true; break; } parent = parent->getParent(); } structure = dst->addChild(child->getName()); if (recursive) { structure->addAttribute(ATTR_RECURSIVE, T("true")); } else if (!child->hasChild() && !child->hasAttribute()) { //simple type, must have a type attribute structure->addAttribute(ATTR_TYPE, guessType(child->getString())); } } else if (structure->findAttribute(ATTR_ATTRIBUTE) != NULL) { //child and attribute can't have same name return false; } XmlAttribute* multiple = structure->findAttribute(ATTR_MULTIPLE); if (multiple == NULL || !multiple->getBool()) { NodeIterator iter; if (src->findFirstChild(child->getName(), iter) != NULL && src->findNextChild(child->getName(), iter) != NULL) { if (multiple == NULL) { multiple = structure->addAttribute(ATTR_MULTIPLE); } multiple->setBool(true); } } if (!structure->findAttribute(ATTR_RECURSIVE) && (child->hasChild() || child->hasAttribute())) { parseNodeStruct(structure, child); } } return true; }
XmlNode * NetworkCommand::saveGame(XmlNode *rootNode) { std::map<string,string> mapTagReplacements; XmlNode *networkCommandNode = rootNode->addChild("NetworkCommand"); // int16 networkCommandType; networkCommandNode->addAttribute("networkCommandType",intToStr(networkCommandType), mapTagReplacements); // int32 unitId; networkCommandNode->addAttribute("unitId",intToStr(unitId), mapTagReplacements); // int16 unitTypeId; networkCommandNode->addAttribute("unitTypeId",intToStr(unitTypeId), mapTagReplacements); // int16 commandTypeId; networkCommandNode->addAttribute("commandTypeId",intToStr(commandTypeId), mapTagReplacements); // int16 positionX; networkCommandNode->addAttribute("positionX",intToStr(positionX), mapTagReplacements); // int16 positionY; networkCommandNode->addAttribute("positionY",intToStr(positionY), mapTagReplacements); // int32 targetId; networkCommandNode->addAttribute("targetId",intToStr(targetId), mapTagReplacements); // int8 wantQueue; networkCommandNode->addAttribute("wantQueue",intToStr(wantQueue), mapTagReplacements); // int8 fromFactionIndex; networkCommandNode->addAttribute("fromFactionIndex",intToStr(fromFactionIndex), mapTagReplacements); // uint16 unitFactionUnitCount; networkCommandNode->addAttribute("unitFactionUnitCount",intToStr(unitFactionUnitCount), mapTagReplacements); // int8 unitFactionIndex; networkCommandNode->addAttribute("unitFactionIndex",intToStr(unitFactionIndex), mapTagReplacements); // int8 commandStateType; networkCommandNode->addAttribute("commandStateType",intToStr(commandStateType), mapTagReplacements); // int32 commandStateValue; networkCommandNode->addAttribute("commandStateValue",intToStr(commandStateValue), mapTagReplacements); // int32 unitCommandGroupId; networkCommandNode->addAttribute("unitCommandGroupId",intToStr(unitCommandGroupId), mapTagReplacements); return networkCommandNode; }
void Stats::saveGame(XmlNode *rootNode) { std::map<string,string> mapTagReplacements; XmlNode *statsNode = rootNode->addChild("Stats"); // PlayerStats playerStats[GameConstants::maxPlayers]; for(unsigned int i = 0; i < (unsigned int)GameConstants::maxPlayers; ++i) { PlayerStats &stat = playerStats[i]; XmlNode *statsNodePlayer = statsNode->addChild("Player"); // ControlType control; statsNodePlayer->addAttribute("control",intToStr(stat.control), mapTagReplacements); // float resourceMultiplier; statsNodePlayer->addAttribute("resourceMultiplier",floatToStr(stat.resourceMultiplier,6), mapTagReplacements); // string factionTypeName; statsNodePlayer->addAttribute("factionTypeName",stat.factionTypeName, mapTagReplacements); // FactionPersonalityType personalityType; statsNodePlayer->addAttribute("personalityType",intToStr(stat.personalityType), mapTagReplacements); // int teamIndex; statsNodePlayer->addAttribute("teamIndex",intToStr(stat.teamIndex), mapTagReplacements); // bool victory; statsNodePlayer->addAttribute("victory",intToStr(stat.victory), mapTagReplacements); // int kills; statsNodePlayer->addAttribute("kills",intToStr(stat.kills), mapTagReplacements); // int enemykills; statsNodePlayer->addAttribute("enemykills",intToStr(stat.enemykills), mapTagReplacements); // int deaths; statsNodePlayer->addAttribute("deaths",intToStr(stat.deaths), mapTagReplacements); // int unitsProduced; statsNodePlayer->addAttribute("unitsProduced",intToStr(stat.unitsProduced), mapTagReplacements); // int resourcesHarvested; statsNodePlayer->addAttribute("resourcesHarvested",intToStr(stat.resourcesHarvested), mapTagReplacements); // string playerName; statsNodePlayer->addAttribute("playerName",stat.playerName, mapTagReplacements); // Vec3f playerColor; statsNodePlayer->addAttribute("playerColor",stat.playerColor.getString(), mapTagReplacements); } // string description; statsNode->addAttribute("description",description, mapTagReplacements); // int factionCount; statsNode->addAttribute("factionCount",intToStr(factionCount), mapTagReplacements); // int thisFactionIndex; statsNode->addAttribute("thisFactionIndex",intToStr(thisFactionIndex), mapTagReplacements); // // float worldTimeElapsed; statsNode->addAttribute("worldTimeElapsed",floatToStr(worldTimeElapsed,6), mapTagReplacements); // int framesPlayed; statsNode->addAttribute("framesPlayed",intToStr(framesPlayed), mapTagReplacements); // int framesToCalculatePlaytime; statsNode->addAttribute("framesToCalculatePlaytime",intToStr(framesToCalculatePlaytime), mapTagReplacements); // int maxConcurrentUnitCount; statsNode->addAttribute("maxConcurrentUnitCount",intToStr(maxConcurrentUnitCount), mapTagReplacements); // int totalEndGameConcurrentUnitCount; statsNode->addAttribute("totalEndGameConcurrentUnitCount",intToStr(totalEndGameConcurrentUnitCount), mapTagReplacements); // bool isMasterserverMode; }
void GameCamera::saveGame(XmlNode *rootNode) { std::map<string,string> mapTagReplacements; XmlNode *gamecameraNode = rootNode->addChild("GameCamera"); // Vec3f pos; gamecameraNode->addAttribute("pos",pos.getString(), mapTagReplacements); // Vec3f destPos; gamecameraNode->addAttribute("destPos",destPos.getString(), mapTagReplacements); // // float hAng; //YZ plane positive -Z axis gamecameraNode->addAttribute("hAng",floatToStr(hAng,16), mapTagReplacements); // float vAng; //XZ plane positive +Z axis gamecameraNode->addAttribute("vAng",floatToStr(vAng,16), mapTagReplacements); // float lastHAng; gamecameraNode->addAttribute("lastHAng",floatToStr(lastHAng,16), mapTagReplacements); // float lastVAng; gamecameraNode->addAttribute("lastVAng",floatToStr(lastVAng,16), mapTagReplacements); // Vec2f destAng; gamecameraNode->addAttribute("destAng",destAng.getString(), mapTagReplacements); // float rotate; gamecameraNode->addAttribute("rotate",floatToStr(rotate,16), mapTagReplacements); // Vec3f move; gamecameraNode->addAttribute("move",move.getString(), mapTagReplacements); // State state; gamecameraNode->addAttribute("state",intToStr(state), mapTagReplacements); // int limitX; gamecameraNode->addAttribute("limitX",intToStr(limitX), mapTagReplacements); // int limitY; gamecameraNode->addAttribute("limitY",intToStr(limitY), mapTagReplacements); // //config // float speed; gamecameraNode->addAttribute("speed",floatToStr(speed,16), mapTagReplacements); // bool clampBounds; gamecameraNode->addAttribute("clampBounds",intToStr(clampBounds), mapTagReplacements); // //float maxRenderDistance; // float maxHeight; gamecameraNode->addAttribute("maxHeight",floatToStr(maxHeight,16), mapTagReplacements); // float minHeight; gamecameraNode->addAttribute("minHeight",floatToStr(minHeight,16), mapTagReplacements); // //float maxCameraDist; // //float minCameraDist; // float minVAng; gamecameraNode->addAttribute("minVAng",floatToStr(minVAng,16), mapTagReplacements); // float maxVAng; gamecameraNode->addAttribute("maxVAng",floatToStr(maxVAng,16), mapTagReplacements); // float fov; gamecameraNode->addAttribute("fov",floatToStr(fov,16), mapTagReplacements); // float calculatedDefault; gamecameraNode->addAttribute("calculatedDefault",floatToStr(calculatedDefault,16), mapTagReplacements); // std::map<float, std::map<float, std::map<Vec3f, Quad2i> > > cacheVisibleQuad; // int MaxVisibleQuadItemCache; gamecameraNode->addAttribute("MaxVisibleQuadItemCache",intToStr(MaxVisibleQuadItemCache), mapTagReplacements); }
void UnitParticleSystemType::saveGame(XmlNode *rootNode) { ParticleSystemType::saveGame(rootNode); std::map<string,string> mapTagReplacements; XmlNode *unitParticleSystemTypeNode = rootNode->addChild("UnitParticleSystemType"); // UnitParticleSystem::Shape shape; unitParticleSystemTypeNode->addAttribute("shape",intToStr(shape), mapTagReplacements); // float angle; unitParticleSystemTypeNode->addAttribute("angle",floatToStr(angle,16), mapTagReplacements); // float radius; unitParticleSystemTypeNode->addAttribute("radius",floatToStr(radius,16), mapTagReplacements); // float minRadius; unitParticleSystemTypeNode->addAttribute("minRadius",floatToStr(minRadius,16), mapTagReplacements); // float emissionRateFade; unitParticleSystemTypeNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade,16), mapTagReplacements); // Vec3f direction; unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements); // bool relative; unitParticleSystemTypeNode->addAttribute("relative",intToStr(relative), mapTagReplacements); // bool relativeDirection; unitParticleSystemTypeNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements); // bool fixed; unitParticleSystemTypeNode->addAttribute("fixed",intToStr(fixed), mapTagReplacements); // int staticParticleCount; unitParticleSystemTypeNode->addAttribute("staticParticleCount",intToStr(staticParticleCount), mapTagReplacements); // bool isVisibleAtNight; unitParticleSystemTypeNode->addAttribute("isVisibleAtNight",intToStr(isVisibleAtNight), mapTagReplacements); // bool isVisibleAtDay; unitParticleSystemTypeNode->addAttribute("isVisibleAtDay",intToStr(isVisibleAtDay), mapTagReplacements); // bool isDaylightAffected; unitParticleSystemTypeNode->addAttribute("isDaylightAffected",intToStr(isDaylightAffected), mapTagReplacements); // bool radiusBasedStartenergy; unitParticleSystemTypeNode->addAttribute("radiusBasedStartenergy",intToStr(radiusBasedStartenergy), mapTagReplacements); // int delay; unitParticleSystemTypeNode->addAttribute("delay",intToStr(delay), mapTagReplacements); // int lifetime; unitParticleSystemTypeNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); // float startTime; unitParticleSystemTypeNode->addAttribute("startTime",floatToStr(startTime,16), mapTagReplacements); // float endTime; unitParticleSystemTypeNode->addAttribute("endTime",floatToStr(endTime,16), mapTagReplacements); }