Problem with not knowing size on old textures

This commit is contained in:
David Rose 2001-05-30 01:01:33 +00:00
parent f27f662b82
commit c68fd64442
9 changed files with 75 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include "texturePlacement.h"
#include "textureImage.h"
#include "palettizer.h"
#include "paletteImage.h"
#include <indent.h>
#include <datagram.h>
@ -430,6 +431,7 @@ place_all() {
Placements::iterator pli;
for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
TexturePlacement *placement = (*pli);
if (placement->get_omit_reason() == OR_working) {
PalettePage *page = get_page(placement->get_properties());
page->assign(placement);
@ -444,6 +446,36 @@ place_all() {
}
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroup::update_unknown_textures
// Access: Public
// Description: Checks for new information on any textures within the
// group for which some of the saved information is
// incomplete. This may be necessary before we can
// properly place all of the textures.
////////////////////////////////////////////////////////////////////
void PaletteGroup::
update_unknown_textures(const TxaFile &txa_file) {
Placements::iterator pli;
for (pli = _placements.begin(); pli != _placements.end(); ++pli) {
TexturePlacement *placement = (*pli);
if (!placement->is_size_known()) {
// This texture's size isn't known; we have to determine its
// size.
TextureImage *texture = placement->get_texture();
if (!texture->got_txa_file()) {
// But first, we need to look up the texture in the .txa file.
texture->pre_txa_file();
txa_file.match_texture(texture);
texture->post_txa_file();
}
placement->determine_size();
}
}
}
////////////////////////////////////////////////////////////////////
// Function: PaletteGroup::write_image_info
// Access: Public

View File

@ -34,6 +34,7 @@ class EggFile;
class TexturePlacement;
class PalettePage;
class TextureImage;
class TxaFile;
////////////////////////////////////////////////////////////////////
// Class : PaletteGroup
@ -80,6 +81,7 @@ public:
void unplace(TexturePlacement *placement);
void place_all();
void update_unknown_textures(const TxaFile &txa_file);
void write_image_info(ostream &out, int indent_level = 0) const;
void optimal_resize();

View File

@ -293,6 +293,8 @@ count_coverage() const {
////////////////////////////////////////////////////////////////////
bool PaletteImage::
place(TexturePlacement *placement) {
nassertr(placement->is_size_known(), true);
int x, y;
if (find_hole(x, y, placement->get_x_size(), placement->get_y_size())) {
placement->place_at(this, x, y);

View File

@ -104,7 +104,8 @@ place_all() {
Assigned::const_iterator ai;
for (ai = _assigned.begin(); ai != _assigned.end(); ++ai) {
place(*ai);
TexturePlacement *placement = (*ai);
place(placement);
}
_assigned.clear();

View File

@ -206,10 +206,9 @@ report_pi() const {
if (si != sorted_groups.begin()) {
cout << "\n";
}
cout << " " << group->get_name() << " ("
<< group->get_dirname_order() << ","
<< group->get_dependency_order() << "): "
<< group->get_groups() << "\n";
cout << " " << group->get_name()
// << " (" << group->get_dirname_order() << "," << group->get_dependency_order() << ")"
<< ": " << group->get_groups() << "\n";
group->write_image_info(cout, 4);
}
@ -455,6 +454,7 @@ process_command_line_eggs(bool force_texture_read) {
Groups::iterator gi;
for (gi = _groups.begin(); gi != _groups.end(); ++gi) {
PaletteGroup *group = (*gi).second;
group->update_unknown_textures(_txa_file);
group->place_all();
}
}
@ -539,6 +539,7 @@ process_all(bool force_texture_read) {
Groups::iterator gi;
for (gi = _groups.begin(); gi != _groups.end(); ++gi) {
PaletteGroup *group = (*gi).second;
group->update_unknown_textures(_txa_file);
group->place_all();
}
}

View File

@ -47,6 +47,7 @@ TextureImage() {
_ever_read_image = false;
_forced_grayscale = false;
_forced_unalpha = false;
_got_txa_file = false;
}
////////////////////////////////////////////////////////////////////
@ -260,6 +261,8 @@ pre_txa_file() {
////////////////////////////////////////////////////////////////////
void TextureImage::
post_txa_file() {
_got_txa_file = true;
// First, get the actual size of the texture.
SourceTextureImage *source = get_preferred_source();
if (source != (SourceTextureImage *)NULL) {
@ -323,6 +326,17 @@ post_txa_file() {
}
}
////////////////////////////////////////////////////////////////////
// Function: TextureImage::got_txa_file
// Access: Public
// Description: Returns true if this TextureImage has been looked up
// in the .txa file this session, false otherwise.
////////////////////////////////////////////////////////////////////
bool TextureImage::
got_txa_file() const {
return _got_txa_file;
}
////////////////////////////////////////////////////////////////////
// Function: TextureImage::determine_placement_size
// Access: Public

View File

@ -64,6 +64,7 @@ public:
void pre_txa_file();
void post_txa_file();
bool got_txa_file() const;
void determine_placement_size();
bool get_omit() const;
@ -127,6 +128,7 @@ private:
bool _read_source_image;
PNMImage _source_image;
bool _got_txa_file;
// The TypedWritable interface follows.

View File

@ -379,6 +379,21 @@ determine_size() {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: TexturePlacement::is_size_known
// Access: Public
// Description: Returns true if the texture's size is known, false
// otherwise. Usually this can only be false after
// determine_size() has been called there is something
// wrong with the texture (in which case the placement
// will automatically omit itself from the palette
// anyway).
////////////////////////////////////////////////////////////////////
bool TexturePlacement::
is_size_known() const {
return _size_known;
}
////////////////////////////////////////////////////////////////////
// Function: TexturePlacement::get_omit_reason
// Access: Public

View File

@ -66,6 +66,7 @@ public:
DestTextureImage *get_dest() const;
bool determine_size();
bool is_size_known() const;
OmitReason get_omit_reason() const;
int get_x_size() const;
int get_y_size() const;