fix bug where screenspace cygnets crash program if moved to fast

This commit is contained in:
Michael Nilsson
2016-05-02 10:03:07 -04:00
parent b2725000e8
commit aa40e3a8b3
4 changed files with 77 additions and 39 deletions

View File

@@ -42,15 +42,7 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(int cygnetId)
setName("iSWACygnet" + std::to_string(_cygnetId));
addProperty(_updateInterval);
OsEng.gui()._iSWAproperty.registerProperty(&_enabled);
OsEng.gui()._iSWAproperty.registerProperty(&_useFlatScreen);
OsEng.gui()._iSWAproperty.registerProperty(&_euclideanPosition);
OsEng.gui()._iSWAproperty.registerProperty(&_sphericalPosition);
OsEng.gui()._iSWAproperty.registerProperty(&_depth);
OsEng.gui()._iSWAproperty.registerProperty(&_scale);
OsEng.gui()._iSWAproperty.registerProperty(&_alpha);
OsEng.gui()._iSWAproperty.registerProperty(&_updateInterval);
OsEng.gui()._iSWAproperty.registerProperty(&_delete);
registerProperties();
}
ScreenSpaceCygnet::~ScreenSpaceCygnet(){}
@@ -61,11 +53,6 @@ bool ScreenSpaceCygnet::initialize(){
createShaders();
updateTexture();
// Setting spherical/euclidean onchange handler
_useFlatScreen.onChange([this](){
useEuclideanCoordinates(_useFlatScreen.value());
});
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
_lastUpdateRealTime = _realTime;

View File

@@ -43,7 +43,8 @@ namespace gui {
class GuiPropertyComponent : public GuiComponent {
public:
//void registerProperty(const std::string& propertyDescription);
void registerProperty(properties::Property* prop);
void registerProperty(properties::Property* prop, properties::Property* sibling = nullptr);
void unregisterProperty(properties::Property* prop);
void unregisterProperties(std::string owner);
void render();

View File

@@ -336,7 +336,7 @@ namespace gui {
//}
void GuiPropertyComponent::registerProperty(properties::Property* prop) {
void GuiPropertyComponent::registerProperty(properties::Property* prop, properties::Property* sibling) {
//void GuiPropertyComponent::registerProperty(const std::string& propertyDescription) {
using namespace properties;
@@ -372,10 +372,16 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) {
std::string owner = fullyQualifiedId.substr(0, pos);
auto it = _propertiesByOwner.find(owner);
if (it == _propertiesByOwner.end())
if (it == _propertiesByOwner.end()){
_propertiesByOwner[owner] = { prop };
else
it->second.push_back(prop);
} else {
std::vector<properties::Property*>::iterator position = std::find(it->second.begin(), it->second.end(), sibling);
if (position != it->second.end()){
it->second.insert(++position, prop);
} else {
it->second.push_back(prop);
}
}
//ghoul::Dictionary dictionary;
//ghoul::lua::loadDictionaryFromString(propertyDescription, dictionary);
@@ -383,31 +389,77 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) {
//handleProperty(dictionary);
}
void GuiPropertyComponent::unregisterProperty(properties::Property* prop) {
using namespace properties;
std::string className = prop->className();
if (className == "BoolProperty")
_boolProperties.erase(prop);
else if (className == "IntProperty")
_intProperties.erase(prop);
else if (className == "FloatProperty")
_floatProperties.erase(prop);
else if (className == "StringProperty")
_stringProperties.erase(prop);
else if (className == "Vec2Property")
_vec2Properties.erase(prop);
else if (className == "Vec3Property")
_vec3Properties.erase(prop);
else if (className == "Vec4Property")
_vec4Properties.erase(prop);
else if (className == "OptionProperty")
_optionProperties.erase(prop);
else if (className == "TriggerProperty")
_triggerProperties.erase(prop);
else if (className == "SelectionProperty")
_selectionProperties.erase(prop);
else {
LWARNING("Class name '" << className << "' not handled in GUI generation");
return;
}
std::string fullyQualifiedId = prop->fullyQualifiedIdentifier();
size_t pos = fullyQualifiedId.find('.');
std::string owner = fullyQualifiedId.substr(0, pos);
auto it = _propertiesByOwner.find(owner);
if (it == _propertiesByOwner.end()){
LWARNING("Cannot find owner for " + className);
}
else{
std::vector<properties::Property*>::iterator position = std::find(it->second.begin(), it->second.end(), prop);
if (position != it->second.end())
it->second.erase(position);
}
}
void GuiPropertyComponent::unregisterProperties(std::string owner){
auto it = _propertiesByOwner.find(owner);
if(it != _propertiesByOwner.end()){
for(auto prop : it->second){
std::string className = prop->className();
if (className == "BoolProperty")
_boolProperties.insert(prop);
_boolProperties.erase(prop);
else if (className == "IntProperty")
_intProperties.insert(prop);
_intProperties.erase(prop);
else if (className == "FloatProperty")
_floatProperties.insert(prop);
_floatProperties.erase(prop);
else if (className == "StringProperty")
_stringProperties.insert(prop);
_stringProperties.erase(prop);
else if (className == "Vec2Property")
_vec2Properties.insert(prop);
_vec2Properties.erase(prop);
else if (className == "Vec3Property")
_vec3Properties.insert(prop);
_vec3Properties.erase(prop);
else if (className == "Vec4Property")
_vec4Properties.insert(prop);
_vec4Properties.erase(prop);
else if (className == "OptionProperty")
_optionProperties.insert(prop);
_optionProperties.erase(prop);
else if (className == "TriggerProperty")
_triggerProperties.insert(prop);
_triggerProperties.erase(prop);
else if (className == "SelectionProperty")
_selectionProperties.insert(prop);
_selectionProperties.erase(prop);
}
it->second.clear();
_propertiesByOwner.erase(it);

View File

@@ -60,16 +60,15 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
useEuclideanCoordinates(_useFlatScreen.value());
_euclideanPosition.onChange([this](){
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
});
_sphericalPosition.onChange([this](){
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
});
// Setting spherical/euclidean onchange handler
_useFlatScreen.onChange([this](){
_useFlatScreen.onChange([this](){
if(_useFlatScreen.value()){
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition, &_useFlatScreen);
OsEng.gui()._screenSpaceProperty.unregisterProperty(&_sphericalPosition);
} else {
OsEng.gui()._screenSpaceProperty.unregisterProperty(&_euclideanPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition, &_useFlatScreen);
}
useEuclideanCoordinates(_useFlatScreen.value());
});
@@ -135,7 +134,6 @@ void ScreenSpaceRenderable::registerProperties(){
OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled);
OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen);
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition);
OsEng.gui()._screenSpaceProperty.registerProperty(&_depth);
OsEng.gui()._screenSpaceProperty.registerProperty(&_scale);
OsEng.gui()._screenSpaceProperty.registerProperty(&_alpha);