Fixed: Scenographic Editor crash the client

--HG--
branch : compatibility-develop
This commit is contained in:
ulukyn@gmail.com 2017-01-10 12:32:44 +01:00
parent 47ac7ddd94
commit 56c4674d10
4 changed files with 158 additions and 52 deletions

View file

@ -281,16 +281,16 @@ public:
// HashMapTraits for NLMISC::TKey
struct CTKeyHashMapTraits
{
enum { bucket_size = 4, min_buckets = 8, };
CTKeyHashMapTraits() { }
//enum { bucket_size = 4, min_buckets = 8, };
//CTKeyHashMapTraits() { }
size_t operator() (NLMISC::TKey key) const
{
return (size_t)key;
return static_cast<std::size_t>(key);
}
bool operator() (NLMISC::TKey key1, NLMISC::TKey key2) const
/*bool operator() (NLMISC::TKey key1, NLMISC::TKey key2) const
{
return key1 < key2;
}
}*/
};
/**

View file

@ -60,8 +60,7 @@ CLFECOMMON::TCLEntityId SlotUnderCursor;
uint32 MissionId = 0;
uint32 MissionRingId = 0;
sint32 InstanceId = 0;
UInstance selectedInstance;
const UInstance noSelectedInstance;
sint32 selectedInstance = -1;
string selectedInstanceURL;
static NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> s_UserCharFade;
@ -129,7 +128,7 @@ void initContextualCursor()
ContextCur.add(true, "MISSION", string(""), 0.0f, checkUnderCursor, contextMission);
ContextCur.add(true, "WEB PAGE", string(""), 0.0f, checkUnderCursor, contextWebPage);
ContextCur.add(true, "WEBIG", string(""), 0.0f, checkUnderCursor, contextWebIG);
ContextCur.add(false, "ARKITECT", string("curs_pick.tga"), 0.0f, checkUnderCursor, contextARKitect);
ContextCur.add(false, "ARKITECT", string("curs_create.tga"), 0.0f, checkUnderCursor, contextARKitect);
ContextCur.add(true, "OUTPOST", string(""), 0.0f, checkUnderCursor, contextOutpost);
ContextCur.add(true, "RING MISSION", string(""), 0.0f, checkUnderCursor, contextRingMission);
ContextCur.add(true, "BUILD_TOTEM", string("uimGcmChooseBuilding"), 0.0f, checkUnderCursor, contextBuildTotem);
@ -346,7 +345,6 @@ void checkUnderCursor()
// Entity Under the cursor is the entity selected.
else
{
// Wait for the target is up to date. Do not display context cursor if the user is mounted.
if( (UserEntity->selection() == UserEntity->targetSlot()) &&
(! UserEntity->isRiding()) )
@ -536,59 +534,49 @@ void checkUnderCursor()
sint32 instance_idx;
CShapeInstanceReference instref = EntitiesMngr.getShapeInstanceUnderPos(cursX, cursY, instance_idx);
if (EntitiesMngr.instancesRemoved())
selectedInstance = noSelectedInstance;
std::vector<string> keys;
keys.push_back("colorize");
if (instance_idx != selectedInstance && selectedInstance != -1) {
std::vector<string> values;
values.push_back("0");
EntitiesMngr.setupInstance((uint32)selectedInstance, keys, values);
}
UInstance instance = instref.Instance;
if (!instance.empty())
if (!instance.empty() && !instref.ContextURL.empty())
{
if (instance.getObjectPtr() != selectedInstance.getObjectPtr())
{
for(uint j=0;j<selectedInstance.getNumMaterials();j++)
{
// unhighlight
selectedInstance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
selectedInstance.getMaterial(j).setShininess( 10.0f );
}
selectedInstance = instance;
// For all materials
for(uint j=0;j<selectedInstance.getNumMaterials();j++)
{
// highlight
selectedInstance.getMaterial(j).setEmissive(CRGBA(255,0,0,255));
selectedInstance.getMaterial(j).setShininess( 1000.0f );
}
}
selectedInstanceURL = instref.ContextURL;
if (instref.ContextText.empty())
{
if (instance_idx != -1) {
std::vector<string> values;
values.push_back("#FF0000FF");
EntitiesMngr.setupInstance((uint32)instance_idx, keys, values);
selectedInstance = instance_idx;
}
cursor->setCursor("r2ed_tool_select_move_over.tga");
InstanceId = instance_idx;
if(ContextCur.context("ARKITECT", 0.f, ucstring()))
if (ContextCur.context("ARKITECT", 0.f, ucstring("Edit")))
return;
}
else
{
cursor->setCursor("curs_pick.tga");
ucstring contextText;
contextText.fromUtf8(instref.ContextText);
if (ContextCur.context("WEBIG", 0.f, contextText))
return;
}
}
else
{
if (!selectedInstance.empty())
{
for(uint j=0;j<selectedInstance.getNumMaterials();j++)
{
//unhighlight
selectedInstance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
selectedInstance.getMaterial(j).setShininess( 10.0f );
}
selectedInstance = noSelectedInstance;
} else {
if (!selectedInstanceURL.empty()) {
cursor->setCursor("curs_default.tga");
selectedInstanceURL.clear();
}
}
SlotUnderCursor = CLFECOMMON::INVALID_SLOT;
}
}
@ -896,7 +884,8 @@ void contextWebIG(bool rightClick, bool dblClick)
CInterface3DShape *el= dynamic_cast<CInterface3DShape*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:bot_chat_object:scene3d:object_1"));
if (el != NULL)
{
el->setName(selectedInstance.getShapeName());
//TODO: Fix that
//el->setName(selectedInstance.getShapeName());
el->setPosX(0.0f);
}
if (selectedInstanceURL.empty())

View file

@ -703,6 +703,57 @@ double CEntityManager::getInstanceColOrient(uint32 idx)
return primitive->getOrientation(dynamicWI);
}
CVector CEntityManager::getInstanceBBoxMin(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UInstance instance = _ShapeInstances[idx].Instance;
if (instance.empty())
return CVector(0,0,0);
NLMISC::CAABBox bbox;
_ShapeInstances[idx].Instance.getShapeAABBox(bbox);
CVector bbox_min;
if (bbox.getCenter() == CVector::Null)
bbox_min = CVector(-0.5f, -0.5f, -0.5f);
else
bbox_min = bbox.getMin();
bbox_min.x *= _ShapeInstances[idx].Instance.getScale().x;
bbox_min.y *= _ShapeInstances[idx].Instance.getScale().y;
bbox_min.z *= _ShapeInstances[idx].Instance.getScale().z;
return bbox_min+_ShapeInstances[idx].Instance.getPos();
}
CVector CEntityManager::getInstanceBBoxMax(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
return CVector(0,0,0);
UInstance instance = _ShapeInstances[idx].Instance;
if(instance.empty())
return CVector(0,0,0);
NLMISC::CAABBox bbox;
_ShapeInstances[idx].Instance.getShapeAABBox(bbox);
CVector bbox_max;
if (bbox.getCenter() == CVector::Null)
bbox_max = CVector(-0.5f, -0.5f, -0.5f);
else
bbox_max = bbox.getMax();
bbox_max.x *= _ShapeInstances[idx].Instance.getScale().x;
bbox_max.y *= _ShapeInstances[idx].Instance.getScale().y;
bbox_max.z *= _ShapeInstances[idx].Instance.getScale().z;
return bbox_max+_ShapeInstances[idx].Instance.getPos();
}
bool CEntityManager::removeInstances()
{
@ -755,6 +806,18 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
}
}
else if (param == "colorize")
{
if (values[i] == "0")
{
for(uint j=0;j<instance.getNumMaterials();j++)
{
instance.getMaterial(j).setShininess( 10.0f );
instance.getMaterial(j).setEmissive(CRGBA(255,255,255,255));
instance.getMaterial(j).setAmbient(CRGBA(0,0,0,255));
instance.getMaterial(j).setDiffuse(CRGBA(255,255,255,255));
}
}
else
{
CRGBA c;
if( fromString( values[i], c ) )
@ -763,10 +826,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
{
instance.getMaterial(j).setShininess( 1000.0f );
instance.getMaterial(j).setEmissive(c);
instance.getMaterial(j).setAmbient(c);
instance.getMaterial(j).setDiffuse(c);
}
}
}
}
else if (param == "texture")
{
if (!values[i].empty())
@ -782,6 +847,43 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
}
}
}
else if (param == "skeleton")
{
// TODO
}
else if (param == "context")
{
_ShapeInstances[idx].ContextText = values[i];
}
else if (param == "url")
{
_ShapeInstances[idx].ContextURL = values[i];
}
else if (param == "move x" || param == "move y" || param == "move z")
{
float v;
CVector pos = getInstancePos(idx);
if( getRelativeFloatFromString( values[i], v ) ) {
updateVector(param, pos, v, true);
} else {
updateVector(param, pos, v, false);
}
setInstancePos(idx, pos);
}
else if (param == "rot x" || param == "rot y" || param == "rot z")
{
float v;
CVector rot = getInstanceRot(idx);
if( getRelativeFloatFromString( values[i], v ) ) {
updateVector(param, rot, v, true);
} else {
updateVector(param, rot, v, false);
}
setInstanceRot(idx, rot);
}
else if (param == "scale x" || param == "scale y" || param == "scale z")
{
float v;
@ -879,6 +981,10 @@ bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const
fromString(values[i], active);
primitive->setObstacle(active);
}
else if (param == "col obstacle")
{
}
}
return true;
@ -933,7 +1039,16 @@ CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float
bbox_max = bbox.getMax();
}
bbox.setMinMax((bbox_min*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos(), (bbox_max*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos());
bbox_min.x *= _ShapeInstances[i].Instance.getScale().x;
bbox_min.y *= _ShapeInstances[i].Instance.getScale().y;
bbox_min.z *= _ShapeInstances[i].Instance.getScale().z;
bbox_max.x *= _ShapeInstances[i].Instance.getScale().x;
bbox_max.y *= _ShapeInstances[i].Instance.getScale().y;
bbox_max.z *= _ShapeInstances[i].Instance.getScale().z;
bbox.setMinMax(bbox_min+_ShapeInstances[i].Instance.getPos(), bbox_max+_ShapeInstances[i].Instance.getPos());
if(bbox.intersect(pos, pos+dir*100.0f))
{

View file

@ -236,6 +236,8 @@ public:
CVector getInstanceColPos(uint32 idx);
CVector getInstanceColScale(uint32 idx);
double getInstanceColOrient(uint32 idx);
CVector getInstanceBBoxMin(uint32 idx);
CVector getInstanceBBoxMax(uint32 idx);
bool setInstanceRot(uint32 idx, CVector pos);
bool instancesRemoved();
bool setupInstance(uint32 idx, const std::vector<std::string> &keys, const std::vector<std::string> &values);