ISystemComponent* NetworkSystemScene::CreateComponent( const std::string& name, const std::string& type ) { ISystemComponent* component = new NetworkSystemComponent( ); component->SetAttribute( System::Attributes::Name, name ); component->SetAttribute( System::Attributes::SystemType, System::Types::NETWORK ); component->SetAttribute( System::Attributes::Parent, this ); m_components.insert( std::make_pair( name, component ) ); return component; }
ISystemComponent* AnimationComponentSerializer::DeSerialize( const std::string entityName, ticpp::Element* componentElement, const ISystemScene::SystemSceneMap& systemScenes ) { std::string system; componentElement->GetAttribute( System::Attributes::SystemType, &system ); ISystemScene::SystemSceneMap::const_iterator systemScene = systemScenes.find( System::SystemTypeMapper::StringToType( system ) ); std::string type; componentElement->GetAttribute( System::Attributes::ComponentType, &type ); ISystemComponent* systemComponent = ( *systemScene ).second->CreateComponent( entityName, type ); std::map< std::string, std::string > animations; ticpp::Element* attributesElement = componentElement->FirstChildElement( "attributes" ); for( Iterator< Element > attribute = attributesElement->FirstChildElement( false ); attribute != attribute.end( ); attribute++ ) { std::string key; attribute->GetAttribute( "key", &key ); if ( key == "animation" ) { std::string animationName; attribute->GetAttribute( "v1", &animationName ); std::string animationPath; attribute->GetAttribute( "v2", &animationPath ); animations.insert( std::make_pair( animationName, animationPath ) ); } if ( key == System::Attributes::Animation::BindPose ) { std::string animationPath; attribute->GetAttribute( "v1", &animationPath ); systemComponent->SetAttribute( System::Attributes::Animation::BindPose, animationPath ); } if ( key == System::Attributes::Animation::DefaultAnimation ) { std::string animationPath; attribute->GetAttribute( "v1", &animationPath ); systemComponent->SetAttribute( System::Attributes::Animation::DefaultAnimation, animationPath ); } } systemComponent->SetAttribute( System::Attributes::Animation::Animations , animations ); return systemComponent; }
ISystemComponent* GraphicsComponentSerializer::DeSerialize( const std::string entityName, ticpp::Element* componentElement, const ISystemScene::SystemSceneMap& systemScenes ) { std::string system; componentElement->GetAttribute( System::Attributes::SystemType, &system ); ISystemScene::SystemSceneMap::const_iterator systemScene = systemScenes.find( System::SystemTypeMapper::StringToType( system ) ); std::string type; componentElement->GetAttribute( System::Attributes::ComponentType, &type ); ISystemComponent* systemComponent = ( *systemScene ).second->CreateComponent( entityName, type ); ticpp::Element* attributesElement = componentElement->FirstChildElement( "attributes" ); for( Iterator< Element > attribute = attributesElement->FirstChildElement( false ); attribute != attribute.end( ); attribute++ ) { std::string key; attribute->GetAttribute( "key", &key ); if ( key == System::Parameters::Model ) { std::string modelPath; attribute->GetAttribute( "v1", &modelPath ); systemComponent->SetAttribute( System::Parameters::Model, modelPath ); } } return systemComponent; }
AnyType::AnyTypeMap ScriptSystem::ProcessMessage(const System::MessageType& message, AnyType::AnyTypeMap parameters) { AnyType::AnyTypeMap results; if(message == System::Messages::PostInitialize) { m_auxScene->Initialize(); m_scene->Initialize(); } if(message == System::Messages::LoadScript) { ISystemComponent* component = m_auxScene->CreateComponent(parameters[ System::Attributes::Name ].As<std::string>(), "default"); component->SetAttribute(System::Parameters::ScriptPath, parameters[ System::Parameters::ScriptPath ].As<std::string>()); component->Initialize(); results[ "component" ] = component; } if (message == System::Messages::UnloadComponent) { m_auxScene->UnloadComponent(parameters[ System::Attributes::Name ].As<std::string>()); } /*from AI if (message == "getMasterState") { //results[ "masterState" ] = m_auxScene->GetState(); }*/ if (message == System::Messages::RegisterScriptFunctions) { scope luaScope = ( class_<ScriptConfiguration>("Config") .property("isFullScreen", &ScriptConfiguration::IsFullScreen, &ScriptConfiguration::SetFullScreen) .property("displayWidth", &ScriptConfiguration::GetDisplayWidth, &ScriptConfiguration::SetDisplayWidth) .property("displayHeight", &ScriptConfiguration::GetDisplayHeight, &ScriptConfiguration::SetDisplayHeight) .property("isConsole", &ScriptConfiguration::IsConsole, &ScriptConfiguration::SetConsole) .property("isInvertY", &ScriptConfiguration::IsInvertY, &ScriptConfiguration::SetInvertY) .property("isSmoothMouse", &ScriptConfiguration::IsSmoothMouse, &ScriptConfiguration::SetSmoothMouse) .property("mouseSmoothAmount", &ScriptConfiguration::GetMouseSmoothAmount, &ScriptConfiguration::SetMouseSmoothAmount) .property("sfxVolume", &ScriptConfiguration::GetSFXVolume, &ScriptConfiguration::SetSFXVolume) .property("musicVolume", &ScriptConfiguration::GetMusicVolume, &ScriptConfiguration::SetMusicVolume) .property("serverPort", &ScriptConfiguration::GetServerPort, &ScriptConfiguration::SetServerPort) .property("serverBotCount", &ScriptConfiguration::GetServerBotCount, &ScriptConfiguration::SetServerBotCount) .property("serverName", &ScriptConfiguration::GetServerName, &ScriptConfiguration::SetServerName) .property("serverTimeLimit", &ScriptConfiguration::GetServerTimeLimit, &ScriptConfiguration::SetServerTimeLimit) .property("serverFragLimit", &ScriptConfiguration::GetServerFragLimit, &ScriptConfiguration::SetServerFragLimit) .property("serverMaxPlayers", &ScriptConfiguration::GetServerMaxPlayers, &ScriptConfiguration::SetServerMaxPlayers), class_<ScriptComponent>("ScriptComponent") .def("include", &ScriptComponent::IncludeScript) .def("registerEventHandler", (void (ScriptComponent::*) (const std::string&, const luabind::object&)) &ScriptComponent::RegisterEventHandler) .def("registerUpdateHandler", &ScriptComponent::RegisterUpdateHandler) .def("unregisterUpdateHandler", &ScriptComponent::UnRegisterUpdateHandler) .def("subscribeMessage", &ScriptComponent::SubscribeMessage) .def("unsubscribeMessage", &ScriptComponent::UnSubscribeMessage) .def("getName", &ScriptComponent::GetName) .def("getLookAt", &ScriptComponent::GetLookAt) .def("getPosition", &ScriptComponent::GetPosition) .def("setPosition", &ScriptComponent::SetPosition), class_<MathVector3>("Vector") .def(constructor<float, float, float>()) .def(self + MathVector3()), class_<MathQuaternion>("Quaternion") .def(constructor<float, float, float, float>()), class_<AnyType::AnyTypeMap>("AnyType") ); results[ System::TypeStrings::SCRIPT ] = luaScope; } return results; }