本文整理汇总了C++中gd::Project::CreateBehaviorSharedDatas方法的典型用法代码示例。如果您正苦于以下问题:C++ Project::CreateBehaviorSharedDatas方法的具体用法?C++ Project::CreateBehaviorSharedDatas怎么用?C++ Project::CreateBehaviorSharedDatas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gd::Project
的用法示例。
在下文中一共展示了Project::CreateBehaviorSharedDatas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateBehaviorsSharedData
void Layout::UpdateBehaviorsSharedData(gd::Project & project)
{
std::vector < gd::String > allBehaviorsTypes;
std::vector < gd::String > allBehaviorsNames;
//Search in objects for the type and the name of every behaviors.
for (std::size_t i = 0;i<initialObjects.size();++i)
{
std::vector < gd::String > objectBehaviors = initialObjects[i]->GetAllBehaviorNames();
for (unsigned int j = 0;j<objectBehaviors.size();++j)
{
gd::Behavior & behavior = initialObjects[i]->GetBehavior(objectBehaviors[j]);
allBehaviorsTypes.push_back(behavior.GetTypeName());
allBehaviorsNames.push_back(behavior.GetName());
}
}
for (std::size_t i = 0;i<project.GetObjectsCount();++i)
{
std::vector < gd::String > objectBehaviors = project.GetObject(i).GetAllBehaviorNames();
for (std::size_t j = 0;j<objectBehaviors.size();++j)
{
gd::Behavior & behavior = project.GetObject(i).GetBehavior(objectBehaviors[j]);
allBehaviorsTypes.push_back(behavior.GetTypeName());
allBehaviorsNames.push_back(behavior.GetName());
}
}
//Create non existing shared data
for (std::size_t i = 0;i<allBehaviorsTypes.size() && i < allBehaviorsNames.size();++i)
{
if ( behaviorsInitialSharedDatas.find(allBehaviorsNames[i]) == behaviorsInitialSharedDatas.end() )
{
std::shared_ptr<gd::BehaviorsSharedData> behaviorsSharedDatas = project.CreateBehaviorSharedDatas(allBehaviorsTypes[i]);
if ( behaviorsSharedDatas )
{
behaviorsSharedDatas->SetName(allBehaviorsNames[i]);
behaviorsInitialSharedDatas[behaviorsSharedDatas->GetName()] = behaviorsSharedDatas;
}
}
}
//Remove useless shared data:
//First construct the list of existing shared data.
std::vector < gd::String > allSharedData;
for (std::map < gd::String, std::shared_ptr<gd::BehaviorsSharedData> >::const_iterator it = behaviorsInitialSharedDatas.begin();
it != behaviorsInitialSharedDatas.end();++it)
{
allSharedData.push_back(it->first);
}
//Then delete shared data not linked to a behavior
for (std::size_t i = 0;i<allSharedData.size();++i)
{
if ( std::find(allBehaviorsNames.begin(), allBehaviorsNames.end(), allSharedData[i]) == allBehaviorsNames.end() )
behaviorsInitialSharedDatas.erase(allSharedData[i]);
}
}
示例2: UnserializeFrom
void Layout::UnserializeFrom(gd::Project & project, const SerializerElement & element)
{
SetBackgroundColor(element.GetIntAttribute( "r" ), element.GetIntAttribute( "v" ), element.GetIntAttribute( "b" ));
SetWindowDefaultTitle( element.GetStringAttribute("title", "(No title)", "titre") );
oglFOV = element.GetDoubleAttribute("oglFOV");
oglZNear = element.GetDoubleAttribute("oglZNear");
oglZFar = element.GetDoubleAttribute("oglZFar");
standardSortMethod = element.GetBoolAttribute( "standardSortMethod" );
stopSoundsOnStartup = element.GetBoolAttribute( "stopSoundsOnStartup" );
disableInputWhenNotFocused = element.GetBoolAttribute( "disableInputWhenNotFocused" );
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
associatedSettings.UnserializeFrom(element.GetChild("uiSettings", 0, "UISettings"));
#endif
#if defined(GD_IDE_ONLY)
gd::ObjectGroup::UnserializeFrom(objectGroups, element.GetChild( "objectsGroups", 0, "GroupesObjets" ));
gd::EventsListSerialization::UnserializeEventsFrom(project, GetEvents(), element.GetChild("events", 0, "Events"));
#endif
UnserializeObjectsFrom(project, element.GetChild("objects", 0, "Objets"));
initialInstances.UnserializeFrom(element.GetChild("instances", 0, "Positions"));
variables.UnserializeFrom(element.GetChild("variables", 0, "Variables"));
initialLayers.clear();
SerializerElement & layersElement = element.GetChild("layers", 0, "Layers");
layersElement.ConsiderAsArrayOf("layer", "Layer");
for (std::size_t i = 0; i < layersElement.GetChildrenCount(); ++i)
{
gd::Layer layer;
layer.UnserializeFrom(layersElement.GetChild(i));
initialLayers.push_back(layer);
}
//Compatibility with GD <= 4
gd::String deprecatedTag1 = "automatismsSharedData";
gd::String deprecatedTag2 = "automatismSharedData";
if (!element.HasChild(deprecatedTag1))
{
deprecatedTag1 = "AutomatismsSharedDatas";
deprecatedTag2 = "AutomatismSharedDatas";
}
//end of compatibility code
SerializerElement & behaviorsDataElement = element.GetChild("behaviorsSharedData", 0, deprecatedTag1);
behaviorsDataElement.ConsiderAsArrayOf("behaviorSharedData", deprecatedTag2);
for (unsigned int i = 0; i < behaviorsDataElement.GetChildrenCount(); ++i)
{
SerializerElement & behaviorDataElement = behaviorsDataElement.GetChild(i);
gd::String type = behaviorDataElement.GetStringAttribute("type", "", "Type")
.FindAndReplace("Automatism", "Behavior"); //Compatibility with GD <= 4
std::shared_ptr<gd::BehaviorsSharedData> sharedData = project.CreateBehaviorSharedDatas(type);
if ( sharedData != std::shared_ptr<gd::BehaviorsSharedData>() )
{
sharedData->SetName( behaviorDataElement.GetStringAttribute("name", "", "Name") );
sharedData->UnserializeFrom(behaviorDataElement);
behaviorsInitialSharedDatas[sharedData->GetName()] = sharedData;
}
}
}