Try to free vertex buffer memory if possible

This commit is contained in:
Benau 2018-09-12 16:29:41 +08:00
parent 37cf5ac459
commit f39946347f
8 changed files with 51 additions and 18 deletions

View File

@ -55,7 +55,7 @@
-->
<item name="rubber-ball" icon="rubber_ball-icon.png"
model="rubber_ball.spm" speed="35.0"
scale="1 1 1" interval="1"
interval="1"
max-height="4.0" min-height="0"
fast-ping-distance="50"
early-target-factor="1"

View File

@ -23,6 +23,7 @@
#include "graphics/material_manager.hpp"
#include "graphics/sp/sp_base.hpp"
#include "io/file_manager.hpp"
#include "modes/profile_world.hpp"
AttachmentManager *attachment_manager = 0;
@ -98,7 +99,8 @@ void AttachmentManager::loadModels()
/* full_path */ true,
/*make_permanent */ true);
}
if (ProfileWorld::isNoGraphics())
mesh->freeMeshVertexBuffer();
} // for
} // reInit

View File

@ -192,13 +192,6 @@ void Flyable::init(const XMLNode &node, scene::IMesh *model,
node.get("min-height", &(m_st_min_height[type]) );
node.get("max-height", &(m_st_max_height[type]) );
node.get("force-updown", &(m_st_force_updown[type]));
core::vector3df scale(1.0f, 1.0f, 1.0f);
if(node.get("scale", &scale))
{
irr::scene::IMeshManipulator *mani =
irr_driver->getVideoDriver()->getMeshManipulator();
mani->scale(model, scale);
}
// Store the size of the model
Vec3 min, max;

View File

@ -32,7 +32,7 @@
#include "items/cake.hpp"
#include "items/plunger.hpp"
#include "items/rubber_ball.hpp"
#include "modes/world.hpp"
#include "modes/profile_world.hpp"
#include "utils/constants.hpp"
#include "utils/string_utils.hpp"
@ -130,7 +130,7 @@ void PowerupManager::loadPowerupsModels()
PowerupType type = getPowerupType(name);
// The weight nodes will be also included in this list, so ignore those
if(type!=POWERUP_NOTHING)
LoadPowerup(type, *node);
loadPowerup(type, *node);
else
{
Log::fatal("PowerupManager",
@ -148,6 +148,19 @@ void PowerupManager::loadPowerupsModels()
delete root;
if (ProfileWorld::isNoGraphics())
{
for (unsigned i = POWERUP_FIRST; i <= POWERUP_LAST; i++)
{
scene::IMesh *mesh = m_all_meshes[(PowerupType)i];
if (mesh)
{
// After minMax3D from loadPowerup mesh can free its vertex
// buffer
mesh->freeMeshVertexBuffer();
}
}
}
} // loadPowerupsModels
//-----------------------------------------------------------------------------
@ -431,7 +444,7 @@ int PowerupManager::WeightsData::getRandomItem(int rank, uint64_t random_number)
* \param type The type of the powerup.
* \param node The XML node with the data for this powerup.
*/
void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node)
void PowerupManager::loadPowerup(PowerupType type, const XMLNode &node)
{
std::string icon_file("");
node.get("icon", &icon_file);
@ -482,9 +495,9 @@ void PowerupManager::LoadPowerup(PowerupType type, const XMLNode &node)
Cake::init(node, m_all_meshes[type]); break;
case POWERUP_RUBBERBALL:
RubberBall::init(node, m_all_meshes[type]); break;
default:;
default: break;
} // switch
} // LoadNode
} // loadPowerup
// ----------------------------------------------------------------------------
/** Create a (potentially interpolated) WeightsData objects for the current

View File

@ -160,7 +160,7 @@ public:
void loadWeights(const XMLNode *node, const std::string &category);
void unloadPowerups ();
void computeWeightsForRace(int num_karts);
void LoadPowerup (PowerupType type, const XMLNode &node);
void loadPowerup (PowerupType type, const XMLNode &node);
PowerupManager::PowerupType
getRandomPowerup(unsigned int pos, unsigned int *n,
uint64_t random_number);

View File

@ -40,6 +40,7 @@
#include "karts/abstract_kart.hpp"
#include "karts/ghost_kart.hpp"
#include "karts/kart_properties.hpp"
#include "modes/profile_world.hpp"
#include "physics/btKart.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp"
@ -628,6 +629,9 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
m_kart_lowest_point = kart_min.getY();
initInverseBoneMatrices();
if (ProfileWorld::isNoGraphics())
m_mesh->freeMeshVertexBuffer();
// Load the speed weighted object models. We need to do that now because it can affect the dimensions of the kart
for(size_t i=0 ; i < m_speed_weighted_objects.size() ; i++)
{
@ -664,12 +668,15 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
// Update min/max, speed weight can be scaled
Vec3 obj_min, obj_max;
MeshTools::minMax3D(obj.m_model->getMesh(0), &obj_min, &obj_max);
scene::IMesh* mesh = obj.m_model->getMesh(0);
MeshTools::minMax3D(mesh, &obj_min, &obj_max);
core::vector3df transformed_min, transformed_max;
obj.m_location.transformVect(transformed_min, obj_min.toIrrVector());
obj.m_location.transformVect(transformed_max, obj_max.toIrrVector());
kart_min.min(transformed_min);
kart_max.max(transformed_max);
if (ProfileWorld::isNoGraphics())
mesh->freeMeshVertexBuffer();
}
for (unsigned int i = 0; i < m_headlight_objects.size(); i++)
@ -682,6 +689,8 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
#endif
obj.getModel()->grab();
irr_driver->grabAllTextures(obj.getModel());
if (ProfileWorld::isNoGraphics())
obj.getModel()->freeMeshVertexBuffer();
}
Vec3 size = kart_max-kart_min;
@ -730,6 +739,8 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
// the destructor will only free the textures if a master
// copy is freed.
irr_driver->grabAllTextures(m_wheel_model[i]);
if (ProfileWorld::isNoGraphics())
m_wheel_model[i]->freeMeshVertexBuffer();
} // for i<4
return true;

View File

@ -1198,7 +1198,7 @@ bool Track::loadMainTrack(const XMLNode &root)
#ifdef SERVER_ONLY
if (false)
#else
if (m_version < 7 && !CVS->isGLSL())
if (m_version < 7 && !CVS->isGLSL() && !ProfileWorld::isNoGraphics())
#endif
{
// The mesh as returned does not have all mesh buffers with the same
@ -1447,6 +1447,9 @@ bool Track::loadMainTrack(const XMLNode &root)
convertTrackToBullet(m_all_nodes[i]);
uploadNodeVertexBuffer(m_all_nodes[i]);
}
// Free the tangent (track mesh) after converting to physics
if (ProfileWorld::isNoGraphics())
tangent_mesh->freeMeshVertexBuffer();
if (m_track_mesh == NULL)
{
@ -1460,6 +1463,16 @@ bool Track::loadMainTrack(const XMLNode &root)
return true;
} // loadMainTrack
// ----------------------------------------------------------------------------
void Track::freeCachedMeshVertexBuffer()
{
if (ProfileWorld::isNoGraphics())
{
for (unsigned i = 0; i < m_all_cached_meshes.size(); i++)
m_all_cached_meshes[i]->freeMeshVertexBuffer();
}
} // freeCachedMeshVertexBuffer
// ----------------------------------------------------------------------------
/** Handles animated textures.
* \param node The scene node for which animated textures are handled.
@ -2081,6 +2094,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
#endif
createPhysicsModel(main_track_count);
freeCachedMeshVertexBuffer();
const bool arena_random_item_created =
ItemManager::get()->randomItemsForArena(m_start_transforms);

View File

@ -400,7 +400,7 @@ private:
std::vector<MusicInformation*>& m_music );
void loadCurves(const XMLNode &node);
void handleSky(const XMLNode &root, const std::string &filename);
void freeCachedMeshVertexBuffer();
public:
/** Static function to get the current track. NULL if no current