shape_cache - ryzom/ryzomcore GitHub Wiki


title: Using the Shape Bank cache for time critical data description: published: true date: 2023-03-01T05:21:42.971Z tags: editor: markdown dateCreated: 2022-03-14T01:32:51.082Z

This is how Project Talaus uses the shape bank to cache time critical data.

3DTask.h

NL3D::UDriver &driver() const
{
  nlassert(driver_instance);
  return *driver_instance;
}
NL3D::UShapeBank &shapeBank() const
{
  nlassert(shape_bank_instance);
  return *shape_bank_instance;
}

3DTask.cpp

if(driver_name == "DirectX")
{
  driver_instance = NL3D::UDriver::createDriver(icon, true);
}
else if (driver_name == "OpenGL")
{
  driver_instance = NL3D::UDriver::createDriver(icon, false);
}
else
{
  nlerror("%s is an unknown driver name please use DirectX or OpenGL.", driver_name);
}
shape_bank_instance = driver_instance->getShapeBank();

Loading task

try
{
  progressBarAlter(0.95f, 0.96f, "Caching Shapes...");
  C3DTask::instance().shapeBank().addShapeCache("shapes");
  C3DTask::instance().shapeBank().setShapeCacheSize("shapes", 1048576);
  C3DTask::instance().shapeBank().preLoadShapesFromDirectory("shapes", "", "*.shape", true, smallprogress, true);
  nlinfo("Cached shapes sucessfully");
}
catch(...)
{
  nlerror("Could not cache shapes");
  CTalausTaskManager::instance().exit();
}

try
{
  progressBarAlter(0.96f, 0.97f, "Caching Skeletons...");
  C3DTask::instance().shapeBank().addShapeCache("skeletons");
  C3DTask::instance().shapeBank().setShapeCacheSize("skeletons", 1048576);
  C3DTask::instance().shapeBank().preLoadShapesFromDirectory("skeletons", "", "*.skel", true, smallprogress, true);
  nlinfo("Cached skeletons sucessfully");
}
catch(...)
{
  nlerror("Could not cache skeletons");
  CTalausTaskManager::instance().exit();
}

try
{
  progressBarAlter(0.97f, 0.98f, "Caching Particle Effects...");
  C3DTask::instance().shapeBank().addShapeCache("fx");
  C3DTask::instance().shapeBank().setShapeCacheSize("fx", 1048576);
  C3DTask::instance().shapeBank().preLoadShapesFromDirectory("fx", "", "*.ps", true, smallprogress, true);
  nlinfo("Cached particle effects sucessfully");
}
catch(...)
{
  nlerror("Could not cache particle effects");
  CTalausTaskManager::instance().exit();
}
⚠️ **GitHub.com Fallback** ⚠️