From: fredb Date: Sun, 25 Apr 2010 10:47:37 +0000 (+0000) Subject: Stuart Buchanan: Fix a bug in the random object placement where the model selected... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=675c86582d8b25270897db0a36d0e02388f09bf4;p=simgear.git Stuart Buchanan: Fix a bug in the random object placement where the model selected in the case of multiple object definitions in material.xml was random, rather than seeded. --- diff --git a/simgear/scene/material/matmodel.cxx b/simgear/scene/material/matmodel.cxx index c625d9b0..93cbd494 100644 --- a/simgear/scene/material/matmodel.cxx +++ b/simgear/scene/material/matmodel.cxx @@ -135,15 +135,11 @@ SGMatModel::load_models( SGPropertyNode *prop_root ) } osg::Node* -SGMatModel::get_random_model( SGPropertyNode *prop_root ) +SGMatModel::get_random_model( SGPropertyNode *prop_root, mt seed ) { load_models( prop_root ); // comment this out if preloading models int nModels = _models.size(); - // int index = int(sg_random() * nModels); - static int index = -1; - if (++index >= nModels) - index = 0; - return _models[index].get(); + return _models[mt_rand(&seed) * nModels].get(); } double diff --git a/simgear/scene/material/matmodel.hxx b/simgear/scene/material/matmodel.hxx index 9d06427a..3e7d84a9 100644 --- a/simgear/scene/material/matmodel.hxx +++ b/simgear/scene/material/matmodel.hxx @@ -82,7 +82,7 @@ public: * * @return A randomly select model from the variants. */ - osg::Node *get_random_model( SGPropertyNode *prop_root ); + osg::Node *get_random_model( SGPropertyNode *prop_root, mt seed ); /** diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 74b4a071..001cbf71 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -610,7 +610,7 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool calc_lights, bool i < tileGeometryBin.randomModels.getNumModels(); i++) { SGMatModelBin::MatModel obj = tileGeometryBin.randomModels.getMatModel(i); - osg::Node* node = sgGetRandomModel(obj.model); + osg::Node* node = sgGetRandomModel(obj.model, seed); // Create a matrix to place the object in the correct // location, and then apply the rotation matrix created diff --git a/simgear/scene/tgdb/userdata.cxx b/simgear/scene/tgdb/userdata.cxx index 11d69e12..6aa71821 100644 --- a/simgear/scene/tgdb/userdata.cxx +++ b/simgear/scene/tgdb/userdata.cxx @@ -60,8 +60,8 @@ void sgUserDataInit( SGPropertyNode *p ) { root_props = p; } -osg::Node* sgGetRandomModel(SGMatModel *obj) { - return obj->get_random_model( root_props ); +osg::Node* sgGetRandomModel(SGMatModel *obj, mt seed) { + return obj->get_random_model( root_props, seed ); } namespace simgear diff --git a/simgear/scene/tgdb/userdata.hxx b/simgear/scene/tgdb/userdata.hxx index ab0a6a55..fa5209e6 100644 --- a/simgear/scene/tgdb/userdata.hxx +++ b/simgear/scene/tgdb/userdata.hxx @@ -26,6 +26,7 @@ #define _SG_USERDATA_HXX #include +#include #include @@ -42,7 +43,7 @@ void sgUserDataInit(SGPropertyNode *p); /** * Get a random model. */ -osg::Node* sgGetRandomModel(SGMatModel *obj); +osg::Node* sgGetRandomModel(SGMatModel *obj, mt seed); namespace simgear {