void CollisionCylinderReaderWriter::writeOn(std::shared_ptr<XmlChunk> shapeChunk, const CollisionShape3D *collisionShape, XmlWriter &xmlWriter) const { shapeChunk->setAttribute(XmlAttribute(TYPE_ATTR, CYLINDER_VALUE)); const CollisionCylinderShape *cylinderShape = static_cast<const CollisionCylinderShape *>(collisionShape); std::shared_ptr<XmlChunk> orientationChunk = xmlWriter.createChunk(ORIENTATION_TAG, XmlAttribute(), shapeChunk); CylinderShape<float>::CylinderOrientation orientationValue = cylinderShape->getCylinderOrientation(); if(orientationValue==CylinderShape<float>::CylinderOrientation::CYLINDER_X) { orientationChunk->setStringValue(X_VALUE); }else if(orientationValue==CylinderShape<float>::CylinderOrientation::CYLINDER_Y) { orientationChunk->setStringValue(Y_VALUE); }else if(orientationValue==CylinderShape<float>::CylinderOrientation::CYLINDER_Z) { orientationChunk->setStringValue(Z_VALUE); }else { throw std::invalid_argument("Cylinder orientation type unknown: " + orientationValue); } std::shared_ptr<XmlChunk> radiusChunk = xmlWriter.createChunk(RADIUS_TAG, XmlAttribute(), shapeChunk); radiusChunk->setFloatValue(cylinderShape->getRadius()); std::shared_ptr<XmlChunk> heightChunk = xmlWriter.createChunk(HEIGHT_TAG, XmlAttribute(), shapeChunk); heightChunk->setFloatValue(cylinderShape->getHeight()); }
void Map::writeSceneSoundsOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> soundElementsListChunk = xmlWriter.createChunk(SOUND_ELEMENTS_TAG, XmlAttribute(), chunk); for (auto sceneSound : sceneSounds) { std::shared_ptr<XmlChunk> soundElementsChunk = xmlWriter.createChunk(SOUND_ELEMENT_TAG, XmlAttribute(), soundElementsListChunk); sceneSound->writeOn(soundElementsChunk, xmlWriter); } }
void Map::writeSceneTerrainsOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> terrainsListChunk = xmlWriter.createChunk(TERRAINS_TAG, XmlAttribute(), chunk); for (auto sceneTerrain : sceneTerrains) { std::shared_ptr<XmlChunk> terrainsChunk = xmlWriter.createChunk(TERRAIN_TAG, XmlAttribute(), terrainsListChunk); sceneTerrain->writeOn(terrainsChunk, xmlWriter); } }
void Map::writeSceneWatersOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> watersListChunk = xmlWriter.createChunk(WATERS_TAG, XmlAttribute(), chunk); for (auto sceneWater : sceneWaters) { std::shared_ptr<XmlChunk> watersChunk = xmlWriter.createChunk(WATER_TAG, XmlAttribute(), watersListChunk); sceneWater->writeOn(watersChunk, xmlWriter); } }
void Map::writeSceneLightsOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> lightsListChunk = xmlWriter.createChunk(LIGHTS_TAG, XmlAttribute(), chunk); for (auto sceneLight : sceneLights) { std::shared_ptr<XmlChunk> lightsChunk = xmlWriter.createChunk(LIGHT_TAG, XmlAttribute(), lightsListChunk); sceneLight->writeOn(lightsChunk, xmlWriter); } }
void Map::writeSceneObjectsOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> objectsListChunk = xmlWriter.createChunk(OBJECTS_TAG, XmlAttribute(), chunk); for (auto sceneObject : sceneObjects) { std::shared_ptr<XmlChunk> objectsChunk = xmlWriter.createChunk(OBJECT_TAG, XmlAttribute(), objectsListChunk); sceneObject->writeOn(objectsChunk, xmlWriter); } }
void RigidBodyReaderWriter::writeBodyPropertiesOn(const std::shared_ptr<XmlChunk> &physicsChunk, const RigidBody *rigidBody, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> massChunk = xmlWriter.createChunk(MASS_TAG, XmlAttribute(), physicsChunk); massChunk->setFloatValue(rigidBody->getMass()); std::shared_ptr<XmlChunk> restitutionChunk = xmlWriter.createChunk(RESTITUTION_TAG, XmlAttribute(), physicsChunk); restitutionChunk->setFloatValue(rigidBody->getRestitution()); std::shared_ptr<XmlChunk> frictionChunk = xmlWriter.createChunk(FRICTION_TAG, XmlAttribute(), physicsChunk); frictionChunk->setFloatValue(rigidBody->getFriction()); std::shared_ptr<XmlChunk> rollingFrictionChunk = xmlWriter.createChunk(ROLLING_FRICTION_TAG, XmlAttribute(), physicsChunk); rollingFrictionChunk->setFloatValue(rigidBody->getRollingFriction()); std::shared_ptr<XmlChunk> linearDampingChunk = xmlWriter.createChunk(LINEAR_DAMPING_TAG, XmlAttribute(), physicsChunk); linearDampingChunk->setFloatValue(rigidBody->getLinearDamping()); std::shared_ptr<XmlChunk> angularDampingChunk = xmlWriter.createChunk(ANGULAR_DAMPING_TAG, XmlAttribute(), physicsChunk); angularDampingChunk->setFloatValue(rigidBody->getAngularDamping()); std::shared_ptr<XmlChunk> linearFactorChunk = xmlWriter.createChunk(LINEAR_FACTOR_TAG, XmlAttribute(), physicsChunk); linearFactorChunk->setVector3Value(rigidBody->getLinearFactor()); std::shared_ptr<XmlChunk> angularFactorChunk = xmlWriter.createChunk(ANGULAR_FACTOR_TAG, XmlAttribute(), physicsChunk); angularFactorChunk->setVector3Value(rigidBody->getAngularFactor()); }
void SoundSphereReaderWriter::writeOn(std::shared_ptr<XmlChunk> shapeChunk, const SoundShape *soundShape, XmlWriter &xmlWriter) const { shapeChunk->setAttribute(XmlAttribute(TYPE_ATTR, SPHERE_VALUE)); const SoundSphere *sphereShape = static_cast<const SoundSphere *>(soundShape); std::shared_ptr<XmlChunk> radiusChunk = xmlWriter.createChunk(RADIUS_TAG, XmlAttribute(), shapeChunk); radiusChunk->setFloatValue(sphereShape->getRadius()); std::shared_ptr<XmlChunk> positionChunk = xmlWriter.createChunk(POSITION_TAG, XmlAttribute(), shapeChunk); positionChunk->setPoint3Value(sphereShape->getPosition()); std::shared_ptr<XmlChunk> marginChunk = xmlWriter.createChunk(MARGIN_TAG, XmlAttribute(), shapeChunk); marginChunk->setFloatValue(sphereShape->getMargin()); }
void RigidBodyReaderWriter::writeOn(const std::shared_ptr<XmlChunk> &physicsChunk, const RigidBody *rigidBody, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> shapeChunk = xmlWriter.createChunk(SHAPE_TAG, XmlAttribute(), physicsChunk); std::shared_ptr<CollisionShapeReaderWriter> shapeReaderWriter = CollisionShapeReaderWriterRetriever::retrieveShapeReaderWriter(rigidBody->getOriginalShape().get()); shapeReaderWriter->writeOn(shapeChunk, rigidBody->getOriginalShape().get(), xmlWriter); writeBodyPropertiesOn(physicsChunk, rigidBody, xmlWriter); }
void CollisionCompoundShapeReaderWriter::writeOn(std::shared_ptr<XmlChunk> shapeChunk, const CollisionShape3D *collisionShape, XmlWriter &xmlWriter) const { shapeChunk->setAttribute(XmlAttribute(TYPE_ATTR, COMPOUND_SHAPE_VALUE)); const CollisionCompoundShape *compoundShape = static_cast<const CollisionCompoundShape *>(collisionShape); std::shared_ptr<XmlChunk> localizedShapesListChunk = xmlWriter.createChunk(LOCALIZED_SHAPES, XmlAttribute(), shapeChunk); const std::vector<std::shared_ptr<const LocalizedCollisionShape>> &shapes = compoundShape->getLocalizedShapes(); for(unsigned int i=0; i<shapes.size(); ++i) { std::shared_ptr<XmlChunk> localizedShapeChunk = xmlWriter.createChunk(LOCALIZED_SHAPE, XmlAttribute(), localizedShapesListChunk); std::shared_ptr<XmlChunk> translationChunk = xmlWriter.createChunk(TRANSLATION, XmlAttribute(), localizedShapeChunk); translationChunk->setVector3Value(shapes[i]->translation); std::shared_ptr<XmlChunk> shapeChunk = xmlWriter.createChunk(SHAPE, XmlAttribute(), localizedShapeChunk); const CollisionShape3D *collisionShape = shapes[i]->shape.get(); CollisionShapeReaderWriterRetriever::retrieveShapeReaderWriter(collisionShape)->writeOn(shapeChunk, collisionShape, xmlWriter); } }
void LightReaderWriter::buildChunkFrom(std::shared_ptr<XmlChunk> lightChunk, const Light *light, XmlWriter &xmlWriter) const { if(light->getLightType()==Light::OMNIDIRECTIONAL) { const OmnidirectionalLight *omnidirectionalLight = static_cast<const OmnidirectionalLight *>(light); lightChunk->setAttribute(XmlAttribute(TYPE_ATTR, OMNIDIRECTIONAL_VALUE)); std::shared_ptr<XmlChunk> positionChunk = xmlWriter.createChunk(POSITION_TAG, XmlAttribute(), lightChunk); positionChunk->setPoint3Value(omnidirectionalLight->getPosition()); std::shared_ptr<XmlChunk> expenentialAttenuationChunk = xmlWriter.createChunk(EXPENENTIAL_ATTENUATION_TAG, XmlAttribute(), lightChunk); expenentialAttenuationChunk->setFloatValue(omnidirectionalLight->getExponentialAttenuation()); }else if(light->getLightType()==Light::SUN) { const SunLight *sunLight = static_cast<const SunLight *>(light); lightChunk->setAttribute(XmlAttribute(TYPE_ATTR, SUN_VALUE)); std::shared_ptr<XmlChunk> directionChunk = xmlWriter.createChunk(DIRECTION_TAG, XmlAttribute(), lightChunk); directionChunk->setVector3Value(sunLight->getDirections()[0]); }else { throw std::invalid_argument("Unknown light type to write in map: " + light->getLightType()); } }
void LightReaderWriter::writeFlagsOn(std::shared_ptr<XmlChunk> lightChunk, const Light *light, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> produceShadowChunk = xmlWriter.createChunk(PRODUCE_SHADOW_TAG, XmlAttribute(), lightChunk); produceShadowChunk->setBoolValue(light->isProduceShadow()); }
void LightReaderWriter::writePropertiesOn(std::shared_ptr<XmlChunk> lightChunk, const Light *light, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> ambientColorChunk = xmlWriter.createChunk(AMBIENT_COLOR_TAG, XmlAttribute(), lightChunk); ambientColorChunk->setPoint3Value(light->getAmbientColor()); }
void SceneAI::writeOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> navMeshConfigChunk = xmlWriter.createChunk(NAV_MESH_CONFIG_TAG, XmlAttribute(), chunk); NavMeshConfigWriter().writeOn(navMeshConfigChunk, navMeshConfig, xmlWriter); }
void Map::writeSceneAIOn(const std::shared_ptr<XmlChunk> &chunk, XmlWriter &xmlWriter) const { std::shared_ptr<XmlChunk> aiElementsListChunk = xmlWriter.createChunk(AI_ELEMENTS_TAG, XmlAttribute(), chunk); sceneAI->writeOn(aiElementsListChunk, xmlWriter); }