textures are case-insensitive

This commit is contained in:
David Rose 2005-08-01 23:14:33 +00:00
parent 6a007813a2
commit 916bce3009
4 changed files with 72 additions and 7 deletions

View File

@ -41,14 +41,15 @@ Palettizer *pal = (Palettizer *)NULL;
// allows us to easily update egg-palettize to write out additional
// information to its pi file, without having it increment the bam
// version number for all bam and boo files anywhere in the world.
int Palettizer::_pi_version = 14;
int Palettizer::_pi_version = 15;
// Updated to version 8 on 3/20/03 to remove extensions from texture key names.
// Updated to version 9 on 4/13/03 to add a few properties in various places.
// Updated to version 10 on 4/15/03 to add _alpha_file_channel.
// Updated to version 11 on 4/30/03 to add TextureReference::_tref_name.
// Updated to version 12 on 9/11/03 to add _generated_image_pattern.
// Updated to version 13 on 9/13/03 to add _keep_format and _background.
// Updated to version 14 on 7/26/06 to add _omit_everything.
// Updated to version 14 on 7/26/05 to add _omit_everything.
// Updated to version 15 on 8/01/05 to make TextureImages be case-insensitive.
int Palettizer::_min_pi_version = 8;
// Dropped support for versions 7 and below on 7/14/03.
@ -1088,13 +1089,68 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) {
TextureImage *texture;
DCAST_INTO_R(texture, p_list[index], index);
_textures.insert(Textures::value_type(texture->get_name(), texture));
string name = downcase(texture->get_name());
pair<Textures::iterator, bool> result = _textures.insert(Textures::value_type(name, texture));
if (!result.second) {
// Two textures mapped to the same slot--probably a case error
// (since we just changed this rule).
_texture_conflicts.push_back(texture);
}
index++;
}
return index;
}
////////////////////////////////////////////////////////////////////
// Function: Palettizer::finalize
// Access: Public, Virtual
// Description: Called by the BamReader to perform any final actions
// needed for setting up the object after all objects
// have been read and all pointers have been completed.
////////////////////////////////////////////////////////////////////
void Palettizer::
finalize(BamReader *manager) {
// Walk through the list of texture names that were in conflict.
// These can only happen if there were two different names that
// different only in case, which means the textures.boo file was
// created before we introduced the rule that case is insignificant.
TextureConflicts::iterator ci;
for (ci = _texture_conflicts.begin();
ci != _texture_conflicts.end();
++ci) {
TextureImage *texture_b = (*ci);
string name = downcase(texture_b->get_name());
Textures::iterator ti = _textures.find(name);
nassertv(ti != _textures.end());
TextureImage *texture_a = (*ti).second;
_textures.erase(ti);
if (!texture_b->is_used() || !texture_a->is_used()) {
// If either texture is not used, there's not really a
// conflict--the other one wins.
if (texture_a->is_used()) {
bool inserted1 = _textures.insert(Textures::value_type(texture_a->get_name(), texture_a)).second;
nassertd(inserted1) { }
} else if (texture_b->is_used()) {
bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second;
nassertd(inserted2) { }
}
} else {
// If both textures are used, there *is* a conflict.
nout << "Texture name conflict: \"" << texture_a->get_name()
<< "\" vs. \"" << texture_b->get_name() << "\"\n";
bool inserted1 = _textures.insert(Textures::value_type(texture_a->get_name(), texture_a)).second;
bool inserted2 = _textures.insert(Textures::value_type(texture_b->get_name(), texture_b)).second;
nassertd(inserted1 && inserted2) { }
}
}
}
////////////////////////////////////////////////////////////////////
// Function: Palettizer::make_Palettizer
// Access: Protected
@ -1111,6 +1167,8 @@ make_Palettizer(const FactoryParams &params) {
parse_params(params, scan, manager);
me->fillin(scan, manager);
manager->register_finalize(me);
return me;
}
@ -1174,4 +1232,3 @@ fillin(DatagramIterator &scan, BamReader *manager) {
_num_textures = scan.get_int32();
manager->read_pointers(scan, _num_textures);
}

View File

@ -144,6 +144,8 @@ private:
typedef pmap<string, TextureImage *> Textures;
Textures _textures;
typedef pvector<TextureImage *> TextureConflicts;
TextureConflicts _texture_conflicts;
// The TypedWritable interface follows.
@ -153,6 +155,8 @@ public:
virtual int complete_pointers(TypedWritable **p_list,
BamReader *manager);
virtual void finalize(BamReader *manager);
protected:
static TypedWritable *make_Palettizer(const FactoryParams &params);
void fillin(DatagramIterator &scan, BamReader *manager);

View File

@ -108,7 +108,7 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) {
_properties._magfilter = _egg_tex->get_magfilter();
_properties._anisotropic_degree = _egg_tex->get_anisotropic_degree();
string name = filename.get_basename_wo_extension();
string name = downcase(filename.get_basename_wo_extension());
TextureImage *texture = pal->get_texture(name);
_source_texture = texture->get_source(filename, alpha_filename,
alpha_file_channel);

View File

@ -83,7 +83,9 @@ parse(const string &line) {
// deemed a texture pattern and will only be tested against
// textures.
if (word.length() > 4 && word.substr(word.length() - 4) == ".egg") {
_egg_patterns.push_back(GlobPattern(word));
GlobPattern pattern(word);
pattern.set_case_sensitive(false);
_egg_patterns.push_back(pattern);
} else {
// However, the filename extension, if any, is stripped off
@ -92,7 +94,9 @@ parse(const string &line) {
if (dot != string::npos) {
word = word.substr(0, dot);
}
_texture_patterns.push_back(GlobPattern(word));
GlobPattern pattern(word);
pattern.set_case_sensitive(false);
_texture_patterns.push_back(pattern);
}
}