Added: A way to run lua per ZONE wiht ZONE_ID.lua files (usefull to spawn shapes)

--HG--
branch : ark
hg/ark
Nuno Gonçalves 5 years ago
parent e3fbe18162
commit a4d2f80579

@ -415,7 +415,7 @@ void CMoveContainer::updateCells (CMovePrimitive *primitive, uint8 worldImage)
CPrimitiveWorldImage *wI=primitive->getWorldImage (worldImage);
#if !FINAL_VERSION
// Check BB width not too large
/* // Check BB width not too large
if (wI->getBBXMax() - wI->getBBXMin() > _CellWidth)
{
nlwarning ("Primitives have moved more than a cell.");
@ -426,6 +426,7 @@ void CMoveContainer::updateCells (CMovePrimitive *primitive, uint8 worldImage)
{
nlwarning ("Primitives have moved more than a cell.");
}
*/
#endif
// Get coordinate in the cell array

@ -38,6 +38,8 @@
#include "nel/georges/u_form.h"
#include "nel/georges/u_form_elm.h"
#include "nel/georges/u_form_loader.h"
// Gui
#include "nel/gui/lua_manager.h"
// Client
#include "global.h"
#include "continent.h"
@ -108,7 +110,7 @@ extern UVisualCollisionManager *CollisionManager;
extern bool InitCloudScape;
extern bool FirstFrame;
extern CContinentManager ContinentMngr;
extern CEntityManager EntitiesMngr;
//-----------------------------------------------
// CUserLandMark
@ -385,6 +387,23 @@ static uint getNumZones()
return (uint)zoneLoaded.size();
}
static uint16 getZoneIdFromName(const string &zoneName)
{
uint16 zoneId = 0;
CVector2f pos;
if (getPosFromZoneName(zoneName, pos))
{
uint x = (uint)pos.x / 160;
uint y = -(uint)pos.y / 160;
zoneId = (x&255) + (y<<8);
}
else
{
nlinfo("no zone...");
}
return zoneId;
}
//-----------------------------------------------
// select :
// Update global parameters like the texture for the micro veget.
@ -717,6 +736,26 @@ void CContinent::select(const CVectorD &pos, NLMISC::IProgressCallback &progress
vector<string> zonesRemoved;
completeIsland = R2::CScenarioEntryPoints::getInstance().getCompleteIslandFromCoords(CVector2f((float) UserEntity->pos().x, (float) UserEntity->pos().y));
Landscape->refreshAllZonesAround(pos, ClientCfg.Vision + ExtraZoneLoadingVision, zonesAdded, zonesRemoved, progress, completeIsland ? &(completeIsland->ZoneIDs) : NULL);
for (uint i = 0; i < zonesRemoved.size(); i++)
EntitiesMngr.removeInstancesInIgZone(getZoneIdFromName(zonesRemoved[i]));
for (uint i = 0; i < zonesAdded.size(); i++)
{
CSString luaScript;
string luaScriptName = CPath::lookup(zonesAdded[i]+".lua", false);
if (!luaScriptName.empty())
{
luaScript.readFromFile(luaScriptName);
CLuaManager::getInstance().executeLuaScript(luaScript, true);
nlinfo("loading %s", luaScriptName.c_str());
}
else
{
nlinfo("file not found %s", luaScriptName.c_str());
}
}
LandscapeIGManager.unloadArrayZoneIG(zonesRemoved);
LandscapeIGManager.loadArrayZoneIG(zonesAdded, &igAdded);
}

@ -529,7 +529,7 @@ void CEntityManager::reinit()
initialize(_NbMaxEntity);
}
CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool haveCollisions, sint32& idx)
CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool haveCollisions, uint16 inIgZone, sint32& idx)
{
idx = -1;
CShapeInstanceReference nullinstref(UInstance(), string(""), string(""));
@ -557,17 +557,42 @@ CShapeInstanceReference CEntityManager::createInstance(const string& shape, cons
_ShapeInstances[idx].ContextURL = url;
_ShapeInstances[idx].BboxActive = !text.empty() || !url.empty();
_ShapeInstances[idx].Deleted = false;
_ShapeInstances[idx].InIGZone = inIgZone > 0;
_LastRemovedInstance = _ShapeInstances[idx].LastDeleted;
_ShapeInstances[idx].LastDeleted = -1;
TIGZoneShapes::iterator it = _IgZoneShapes.find(inIgZone);
if (it == _IgZoneShapes.end())
{
vector<uint32> shapes;
shapes.push_back(idx);
_IgZoneShapes.insert(make_pair(inIgZone, shapes));
}
else
{
vector<uint32> &shapes = (*it).second;
shapes.push_back(idx);
}
return _ShapeInstances[idx];
}
else
{
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, !text.empty() || !url.empty());
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, !text.empty() || !url.empty(), inIgZone > 0);
instref.Primitive = primitive;
idx = _ShapeInstances.size();
_ShapeInstances.push_back(instref);
TIGZoneShapes::iterator it = _IgZoneShapes.find(inIgZone);
if (it == _IgZoneShapes.end())
{
vector<uint32> shapes;
shapes.push_back(idx);
_IgZoneShapes.insert(make_pair(inIgZone, shapes));
}
else
{
vector<uint32> &shapes = (*it).second;
shapes.push_back(idx);
}
return instref;
}
}
@ -583,9 +608,7 @@ bool CEntityManager::deleteInstance(uint32 idx)
Scene->deleteInstance(_ShapeInstances[idx].Instance);
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
if (primitive)
{
PACS->removePrimitive(primitive);
}
if (!_ShapeInstances[idx].Deleted)
{
@ -598,6 +621,22 @@ bool CEntityManager::deleteInstance(uint32 idx)
return true;
}
void CEntityManager::removeInstancesInIgZone(uint16 igZone)
{
if (!Scene)
return;
TIGZoneShapes::iterator it = _IgZoneShapes.find(igZone);
if (it != _IgZoneShapes.end())
{
vector<uint32> &shapes = (*it).second;
for (uint i = 0; i < shapes.size(); i++)
deleteInstance(shapes[i]);
_IgZoneShapes.erase(it);
}
}
CVector CEntityManager::getInstancePos(uint32 idx)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
@ -758,31 +797,15 @@ CVector CEntityManager::getInstanceBBoxMax(uint32 idx)
bool CEntityManager::removeInstances()
{
if (!Scene) return false;
// Remove all instances.
for(uint i=0; i<_ShapeInstances.size(); ++i)
{
if (!_ShapeInstances[i].Instance.empty())
Scene->deleteInstance(_ShapeInstances[i].Instance);
UMovePrimitive *primitive = _ShapeInstances[i].Primitive;
if (primitive)
{
PACS->removePrimitive(primitive);
}
if (!_ShapeInstances[i].InIGZone)
deleteInstance(i);
}
_ShapeInstances.clear();
_InstancesRemoved = true;
_LastRemovedInstance = -1;
return true;
}
bool CEntityManager::instancesRemoved()
{
bool instRemoved = _InstancesRemoved;
_InstancesRemoved = false;
return instRemoved;
}
bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const vector<string> &values)
{
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)

@ -95,7 +95,7 @@ public:
class CShapeInstanceReference
{
public:
CShapeInstanceReference (NL3D::UInstance instance, const string &text, const string &url, bool bbox_active=true)
CShapeInstanceReference (NL3D::UInstance instance, const string &text, const string &url, bool bbox_active=true, bool in_ig_zone = false)
{
Instance = instance;
ContextText = text;
@ -103,6 +103,7 @@ public:
BboxActive = bbox_active;
Deleted = false;
LastDeleted = -1;
InIGZone = in_ig_zone;
Primitive = NULL;
PrimSize = CVector(1.f, 1.f, 1.f);
PrimHeight = 1.f;
@ -118,6 +119,7 @@ public:
string ContextURL;
bool BboxActive;
bool Deleted;
bool InIGZone;
sint32 LastDeleted;
};
@ -143,6 +145,8 @@ private:
std::vector<CEntityReference> _VisibleEntities;
/// Shapes Instances caches
typedef std::map<uint16, std::vector<uint32>> TIGZoneShapes;
TIGZoneShapes _IgZoneShapes;
std::vector<CShapeInstanceReference> _ShapeInstances;
sint32 _LastRemovedInstance;
bool _InstancesRemoved;
@ -226,9 +230,10 @@ public:
void reinit();
CShapeInstanceReference createInstance(const string& shape, const CVector &pos, const string &text, const string &url, bool haveCollisions, sint32 &idx);
CShapeInstanceReference createInstance(const string& shape, const CVector &pos, const string &text, const string &url, bool haveCollisions, uint16 inIgZone, sint32 &idx);
bool deleteInstance(uint32 idx);
bool removeInstances();
void removeInstancesInIgZone(uint16 igZone);
CVector getInstancePos(uint32 idx);
bool setInstancePos(uint32 idx, CVector pos);
CVector getInstanceRot(uint32 idx);
@ -239,7 +244,6 @@ public:
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);
CShapeInstanceReference getShapeInstanceUnderPos(float x, float y, sint32 &idx);

@ -2555,7 +2555,7 @@ class CAHAddShape : public IActionHandler
}
sint32 idx;
CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, false, idx);
CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector((float)x, (float)y, (float)z), c, u, false, 0, idx);
UInstance instance = instref.Instance;
if(!instance.empty())

@ -2070,14 +2070,14 @@ int CLuaIHMRyzom::getIslandId(CLuaState &ls)
// ***************************************************************************
//
// addShape("shape", .x, .y, .z, "angle", .scale, collision?, "context", "url", highlight?, transparency?, "texture", "skeleton")
// addShape("shape", .x, .y, .z, "angle", .scale, collision?, "context", "url", highlight?, transparency?, "texture", "skeleton", "inIgZone?")
//
//********
int CLuaIHMRyzom::addShape(CLuaState &ls)
{
const char* funcName = "addShape";
CLuaIHM::checkArgMin(ls, funcName, 1);
CLuaIHM::checkArgMax(ls, funcName, 13);
CLuaIHM::checkArgMax(ls, funcName, 14);
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
sint32 idx = -1;
@ -2097,6 +2097,7 @@ int CLuaIHMRyzom::addShape(CLuaState &ls)
bool highlight = false;
bool transparency = false;
bool collision = true;
bool inIgZone = false;
if (ls.getTop() >= 2)
{
@ -2187,7 +2188,13 @@ int CLuaIHMRyzom::addShape(CLuaState &ls)
skeleton = ls.toString(13);
}
CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector(x, y, z), context, url, collision, idx);
if (ls.getTop() >= 14)
{
CLuaIHM::checkArgType(ls, funcName, 14, LUA_TBOOLEAN);
inIgZone = ls.toBoolean(14);
}
CShapeInstanceReference instref = EntitiesMngr.createInstance(shape, CVector(x, y, z), context, url, collision, inIgZone, idx);
UInstance instance = instref.Instance;
if(!instance.empty())

Loading…
Cancel
Save