// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// bool Pool3dGameEventListener::VHandleEvent(IEventData const &eventObj) { bool result = true; // NB. Note to self, the event will not be propagated anymore if you return TRUE from this method. // Take care you return FALSE for events that might have script listeners... // Log receipt of the event and its type. GF_LOG_TRACE_TRC(VGetName(), string("Recevied event type = ") + string(eventObj.VGetEventType().getStr())); // Check what event has occurred and handle it appropriately. if(eventObj.VGetEventType() == EvtData_Graphics_Config_Change::sk_EventType) { const EvtData_Graphics_Config_Change &castEvent = static_cast<const EvtData_Graphics_Config_Change &>(eventObj); result = OnGraphicsConfigChange(castEvent); } else if(eventObj.VGetEventType() == EvtData_Sound_Config_Change::sk_EventType) { const EvtData_Sound_Config_Change &castEvent = static_cast<const EvtData_Sound_Config_Change &>(eventObj); result = OnSoundConfigChange(castEvent); } // TODO: Handle other UI view events here... else { GF_LOG_DEB(string("View: Unknown game event received: ") + eventObj.VGetEventType().getStr()); result = false; } return (result); }
tinyxml2::XMLElement* TransformComponent::VGenerateXml(tinyxml2::XMLDocument* pDoc) { tinyxml2::XMLElement* pBaseElement = pDoc->NewElement(VGetName()); // initial transform -> position tinyxml2::XMLElement* pPosition = pDoc->NewElement("Position"); glm::vec3 pos = ::GetPosition(m_transform); pPosition->SetAttribute("x", ToStr(pos.x).c_str()); pPosition->SetAttribute("y", ToStr(pos.y).c_str()); pPosition->SetAttribute("z", ToStr(pos.z).c_str()); pBaseElement->LinkEndChild(pPosition); // initial transform -> LookAt tinyxml2::XMLElement* pDirection = pDoc->NewElement("YawPitchRoll"); glm::vec3 eulerDegs = ::GetYawPitchRoll(m_transform); eulerDegs.x = RADIANS_TO_DEGREES(eulerDegs.x); eulerDegs.y = RADIANS_TO_DEGREES(eulerDegs.y); eulerDegs.z = RADIANS_TO_DEGREES(eulerDegs.z); pDirection->SetAttribute("x", ToStr(eulerDegs.x).c_str()); pDirection->SetAttribute("y", ToStr(eulerDegs.y).c_str()); pDirection->SetAttribute("z", ToStr(eulerDegs.z).c_str()); pBaseElement->LinkEndChild(pDirection); return pBaseElement; }
tinyxml2::XMLElement* AudioComponent::VGenerateXml(tinyxml2::XMLDocument* pDoc) { tinyxml2::XMLElement* pBaseElement = pDoc->NewElement(VGetName()); tinyxml2::XMLElement* pSoundNode = pDoc->NewElement("Sound"); tinyxml2::XMLText* pSoundText = pDoc->NewText(m_audioResource.c_str()); pSoundNode->LinkEndChild(pSoundText); pBaseElement->LinkEndChild(pSoundNode); tinyxml2::XMLElement* pLoopingNode = pDoc->NewElement("Looping"); tinyxml2::XMLText* pLoopingText = pDoc->NewText(m_looping ? "1" : "0"); pLoopingNode->LinkEndChild(pLoopingText); pBaseElement->LinkEndChild(pLoopingNode); tinyxml2::XMLElement* pFadeInNode = pDoc->NewElement("FadeIn"); tinyxml2::XMLText* pFadeInText = pDoc->NewText(ToStr(m_fadeInTime).c_str()); pFadeInNode->LinkEndChild(pFadeInText); pBaseElement->LinkEndChild(pFadeInNode); tinyxml2::XMLElement* pVolumeNode = pDoc->NewElement("Volume"); tinyxml2::XMLText* pVolumeText = pDoc->NewText(ToStr(m_volume).c_str()); pVolumeNode->LinkEndChild(pVolumeText); pBaseElement->LinkEndChild(pVolumeNode); return pBaseElement; }
TiXmlElement* TransformComponent::VGenerateXml(void) { TiXmlElement* pBaseElement = AC_NEW TiXmlElement(VGetName()); // initial transform -> position TiXmlElement* pPosition = AC_NEW TiXmlElement("Position"); Vec3 pos(m_transform.GetPosition()); pPosition->SetAttribute("x", ToStr(pos.x).c_str()); pPosition->SetAttribute("y", ToStr(pos.y).c_str()); pPosition->SetAttribute("z", ToStr(pos.z).c_str()); pBaseElement->LinkEndChild(pPosition); // initial transform -> LookAt TiXmlElement* pDirection = AC_NEW TiXmlElement("YawPitchRoll"); Vec3 orient(m_transform.GetYawPitchRoll()); orient.x = RADIANS_TO_DEGREES(orient.x); orient.y = RADIANS_TO_DEGREES(orient.y); orient.z = RADIANS_TO_DEGREES(orient.z); pDirection->SetAttribute("x", ToStr(orient.x).c_str()); pDirection->SetAttribute("y", ToStr(orient.y).c_str()); pDirection->SetAttribute("z", ToStr(orient.z).c_str()); pBaseElement->LinkEndChild(pDirection); /*** // This is not supported yet // initial transform -> position TiXmlElement* pScale = AC_NEW TiXmlElement("Scale"); pPosition->SetAttribute("x", ToStr(m_scale.x).c_str()); pPosition->SetAttribute("y", ToStr(m_scale.y).c_str()); pPosition->SetAttribute("z", ToStr(m_scale.z).c_str()); pBaseElement->LinkEndChild(pScale); **/ return pBaseElement; }
TiXmlElement* PhysicsComponent::VGenerateXml(void) { TiXmlElement* pBaseElement = GCC_NEW TiXmlElement(VGetName()); // shape TiXmlElement* pShape = GCC_NEW TiXmlElement("Shape"); TiXmlText* pShapeText = GCC_NEW TiXmlText(m_shape.c_str()); pShape->LinkEndChild(pShapeText); pBaseElement->LinkEndChild(pShape); // density TiXmlElement* pDensity = GCC_NEW TiXmlElement("Density"); TiXmlText* pDensityText = GCC_NEW TiXmlText(m_density.c_str()); pDensity->LinkEndChild(pDensityText); pBaseElement->LinkEndChild(pDensity); // material TiXmlElement* pMaterial = GCC_NEW TiXmlElement("Material"); TiXmlText* pMaterialText = GCC_NEW TiXmlText(m_material.c_str()); pMaterial->LinkEndChild(pMaterialText); pBaseElement->LinkEndChild(pMaterial); // rigid body transform TiXmlElement* pInitialTransform = GCC_NEW TiXmlElement("RigidBodyTransform"); // initial transform -> position TiXmlElement* pPosition = GCC_NEW TiXmlElement("Position"); pPosition->SetAttribute("x", ToStr(m_RigidBodyLocation.x).c_str()); pPosition->SetAttribute("y", ToStr(m_RigidBodyLocation.y).c_str()); pPosition->SetAttribute("z", ToStr(m_RigidBodyLocation.z).c_str()); pInitialTransform->LinkEndChild(pPosition); // initial transform -> orientation TiXmlElement* pOrientation = GCC_NEW TiXmlElement("Orientation"); pOrientation->SetAttribute("yaw", ToStr(m_RigidBodyOrientation.x).c_str()); pOrientation->SetAttribute("pitch", ToStr(m_RigidBodyOrientation.y).c_str()); pOrientation->SetAttribute("roll", ToStr(m_RigidBodyOrientation.z).c_str()); pInitialTransform->LinkEndChild(pOrientation); // initial transform -> scale TiXmlElement* pScale = GCC_NEW TiXmlElement("Scale"); pScale->SetAttribute("x", ToStr(m_RigidBodyScale.x).c_str()); pScale->SetAttribute("y", ToStr(m_RigidBodyScale.y).c_str()); pScale->SetAttribute("z", ToStr(m_RigidBodyScale.z).c_str()); pInitialTransform->LinkEndChild(pScale); pBaseElement->LinkEndChild(pInitialTransform); return pBaseElement; }
tinyxml2::XMLElement* PhysicsComponent::VGenerateXml(tinyxml2::XMLDocument* pDoc) { tinyxml2::XMLElement* pBaseElement = pDoc->NewElement(VGetName()); // shape tinyxml2::XMLElement* pShape = pDoc->NewElement("Shape"); tinyxml2::XMLText* pShapeText = pDoc->NewText(m_shape.c_str()); pShape->LinkEndChild(pShapeText); pBaseElement->LinkEndChild(pShape); // density tinyxml2::XMLElement* pDensity = pDoc->NewElement("Density"); tinyxml2::XMLText* pDensityText = pDoc->NewText(m_density.c_str()); pDensity->LinkEndChild(pDensityText); pBaseElement->LinkEndChild(pDensity); // material tinyxml2::XMLElement* pMaterial = pDoc->NewElement("GLMaterial"); tinyxml2::XMLText* pMaterialText = pDoc->NewText(m_material.c_str()); pMaterial->LinkEndChild(pMaterialText); pBaseElement->LinkEndChild(pMaterial); // rigid body transform tinyxml2::XMLElement* pInitialTransform = pDoc->NewElement("RigidBodyTransform"); // initial transform -> position tinyxml2::XMLElement* pPosition = pDoc->NewElement("Position"); pPosition->SetAttribute("x", ToStr(m_RigidBodyLocation.x).c_str()); pPosition->SetAttribute("y", ToStr(m_RigidBodyLocation.y).c_str()); pPosition->SetAttribute("z", ToStr(m_RigidBodyLocation.z).c_str()); pInitialTransform->LinkEndChild(pPosition); // initial transform -> orientation tinyxml2::XMLElement* pOrientation = pDoc->NewElement("Orientation"); pOrientation->SetAttribute("yaw", ToStr(m_RigidBodyOrientation.x).c_str()); pOrientation->SetAttribute("pitch", ToStr(m_RigidBodyOrientation.y).c_str()); pOrientation->SetAttribute("roll", ToStr(m_RigidBodyOrientation.z).c_str()); pInitialTransform->LinkEndChild(pOrientation); // initial transform -> scale tinyxml2::XMLElement* pScale = pDoc->NewElement("Scale"); pScale->SetAttribute("x", ToStr(m_RigidBodyScale.x).c_str()); pScale->SetAttribute("y", ToStr(m_RigidBodyScale.y).c_str()); pScale->SetAttribute("z", ToStr(m_RigidBodyScale.z).c_str()); pInitialTransform->LinkEndChild(pScale); pBaseElement->LinkEndChild(pInitialTransform); return pBaseElement; }
TiXmlElement* BaseScriptComponent::VGenerateXml(void) { TiXmlElement* pBaseElement = AC_NEW TiXmlElement(VGetName()); // ScriptObject TiXmlElement* pScriptObjectElement = AC_NEW TiXmlElement("ScriptObject"); if (!m_scriptObjectName.empty()) pScriptObjectElement->SetAttribute("var", m_scriptObjectName.c_str()); if (!m_constructorName.empty()) pScriptObjectElement->SetAttribute("constructor", m_constructorName.c_str()); if (!m_destructorName.empty()) pScriptObjectElement->SetAttribute("destructor", m_destructorName.c_str()); pBaseElement->LinkEndChild(pScriptObjectElement); return pBaseElement; }