// Constructor
FGMaterialLib::FGMaterialLib ( void ) {
+ set_step(0);
}
} else {
return true;
}
-
-#if 0
- cout << path << " ";
- FILE *fp = fopen( path.c_str(), "r" );
- if ( fp == NULL ) {
- cout << " doesn't exist\n";
- return false;
- } else {
- cout << " exists\n";
- return true;
- }
-#endif
}
FGNewMat *m = matlib[src_mat];
if ( m != NULL ) {
matlib[dst_mat] = m;
+ m->ref();
} else {
SG_LOG( SG_GENERAL, SG_ALERT,
"Bad material alias pointing to nonexistant material" );
in >> token;
if ( token == '{' ) {
+ // Read the data into a temporary but stack allocated
+ // copy of the structure
+ FGNewMat tmp;
+ in >> tmp;
+
+ // create a pointer to a heap allocated copy of the structure
FGNewMat *m = new FGNewMat;
- in >> *m;
+ *m = tmp;
+ m->ref();
// build the ssgSimpleState
SGPath tex_path( globals->get_fg_root() );
// Free up all the material entries first
for ( material_map_iterator it = begin(); it != end(); it++ ) {
FGNewMat *slot = it->second;
- if ( slot != NULL ) {
+ slot->deRef();
+ if ( slot->getRef() <= 0 ) {
delete slot;
}
}
}
+// Get the step for the state selectors
+int FGMaterialLib::get_step ()
+{
+ material_map_iterator it = begin();
+ return it->second->get_state()->getSelectStep();
+}
+
+
// Load one pending "deferred" texture. Return true if a texture
// loaded successfully, false if no pending, or error.
void FGMaterialLib::load_next_deferred() {