better Filename usage

This commit is contained in:
David Rose 2008-11-11 23:28:14 +00:00
parent 0ce8a5861d
commit 1462bee771
37 changed files with 251 additions and 176 deletions

View File

@ -230,6 +230,34 @@ substr(size_t begin, size_t end) const {
return _filename.substr(begin, end);
}
////////////////////////////////////////////////////////////////////
// Function: Filename::operator +=
// Access: Published
// Description: Appends the other filename onto the end of this one.
// This does not introduce an intervening slash, but see
// the Filename constructor that takes two parameters.
////////////////////////////////////////////////////////////////////
INLINE void Filename::
operator += (const string &other) {
_filename += other;
locate_basename();
locate_extension();
locate_hash();
}
////////////////////////////////////////////////////////////////////
// Function: Filename::operator +
// Access: Published
// Description: Returns a new Filename representing the concatenation
// of the two filenames.
////////////////////////////////////////////////////////////////////
INLINE Filename Filename::
operator + (const string &other) const {
Filename a(*this);
a += other;
return a;
}
////////////////////////////////////////////////////////////////////
// Function: Filename::get_fullpath

View File

@ -1666,7 +1666,9 @@ scan_directory(vector_string &contents) const {
}
DIR *root = opendir(dirname.c_str());
if (root == (DIR *)NULL) {
perror(dirname.c_str());
if (errno != ENOTDIR) {
perror(dirname.c_str());
}
return false;
}

View File

@ -101,6 +101,8 @@ PUBLISHED:
INLINE char operator [] (int n) const;
INLINE string substr(size_t begin, size_t end = string::npos) const;
INLINE void operator += (const string &other);
INLINE Filename operator + (const string &other) const;
// Or, you can use any of these.
INLINE string get_fullpath() const;

View File

@ -2658,8 +2658,10 @@ write_function_instance(ostream &out, InterfaceMaker::Object *obj,
if (!extra_cleanup.empty()) {
indent(out,extra_indent_level) << extra_cleanup << "\n";
}
return_expr = manage_return_value(out, extra_indent_level, remap, "return_value");
if (!is_inplace) {
return_expr = manage_return_value(out, extra_indent_level, remap, "return_value");
}
do_assert_init(out, extra_indent_level,is_constructor);
pack_return_value(out, extra_indent_level, remap, remap->_return_type->temporary_to_return(return_expr),ForwardDeclrs,is_inplace);
}

View File

@ -180,7 +180,7 @@ is_regular_file(const Filename &) const {
// used to read it.
////////////////////////////////////////////////////////////////////
PT(VirtualFile) VirtualFileMountHTTP::
make_virtual_file(const string &local_filename,
make_virtual_file(const Filename &local_filename,
const Filename &original_filename, bool implicit_pz_file,
bool status_only) {
PT(VirtualFileHTTP) vfile =

View File

@ -42,7 +42,7 @@ PUBLISHED:
static void reload_vfs_mount_url();
public:
virtual PT(VirtualFile) make_virtual_file(const string &local_filename,
virtual PT(VirtualFile) make_virtual_file(const Filename &local_filename,
const Filename &original_filename,
bool implicit_pz_file,
bool status_only);

View File

@ -66,7 +66,7 @@ PUBLISHED:
void set_coordinate_system(CoordinateSystem coordsys);
INLINE CoordinateSystem get_coordinate_system() const;
INLINE void set_egg_filename(const Filename &egg_filenamea);
INLINE void set_egg_filename(const Filename &egg_filename);
INLINE const Filename &get_egg_filename() const;
INLINE void recompute_vertex_normals(double threshold);

View File

@ -28,7 +28,7 @@ TypeHandle EggTexture::_type_handle;
// Description:
////////////////////////////////////////////////////////////////////
EggTexture::
EggTexture(const string &tref_name, const string &filename)
EggTexture(const string &tref_name, const Filename &filename)
: EggFilenameNode(tref_name, filename)
{
_texture_type = TT_unspecified;

View File

@ -32,7 +32,7 @@
////////////////////////////////////////////////////////////////////
class EXPCL_PANDAEGG EggTexture : public EggFilenameNode, public EggRenderMode, public EggTransform {
PUBLISHED:
EggTexture(const string &tref_name, const string &filename);
EggTexture(const string &tref_name, const Filename &filename);
EggTexture(const EggTexture &copy);
EggTexture &operator = (const EggTexture &copy);
virtual ~EggTexture();

View File

@ -12,6 +12,12 @@
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: EggTextureCollection::begin
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE EggTextureCollection::iterator EggTextureCollection::
begin() const {
nassertr(_ordered_textures.size() == _textures.size(),
@ -19,16 +25,41 @@ begin() const {
return _ordered_textures.begin();
}
////////////////////////////////////////////////////////////////////
// Function: EggTextureCollection::end
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE EggTextureCollection::iterator EggTextureCollection::
end() const {
return _ordered_textures.end();
}
////////////////////////////////////////////////////////////////////
// Function: EggTextureCollection::empty
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool EggTextureCollection::
empty() const {
return _ordered_textures.empty();
}
////////////////////////////////////////////////////////////////////
// Function: EggTextureCollection::operator []
// Access: Published
// Description: Returns the nth EggTexture in the collection.
////////////////////////////////////////////////////////////////////
EggTexture *EggTextureCollection::
operator [] (size_type n) const {
return get_texture(n);
}
////////////////////////////////////////////////////////////////////
// Function: EggTextureCollection::size
// Access: Published
// Description: Returns the number of EggTextures in the collection.
////////////////////////////////////////////////////////////////////
INLINE EggTextureCollection::size_type EggTextureCollection::
size() const {
nassertr(_ordered_textures.size() == _textures.size(), 0);

View File

@ -88,9 +88,11 @@ public:
INLINE iterator begin() const;
INLINE iterator end() const;
INLINE bool empty() const;
INLINE size_type size() const;
PUBLISHED:
INLINE EggTexture *operator [](size_type n) const;
INLINE size_type size() const;
bool add_texture(EggTexture *texture);
bool remove_texture(EggTexture *texture);

View File

@ -68,9 +68,10 @@ load_from_loader(EggLoader &loader) {
// required.
////////////////////////////////////////////////////////////////////
PT(PandaNode)
load_egg_file(const string &filename, CoordinateSystem cs,
load_egg_file(const Filename &filename, CoordinateSystem cs,
BamCacheRecord *record) {
Filename egg_filename = Filename::text_filename(filename);
Filename egg_filename = filename;
egg_filename.set_text();
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
if (record != (BamCacheRecord *)NULL) {

View File

@ -35,7 +35,7 @@ BEGIN_PUBLISH
// bit more manual control over the loading process.
////////////////////////////////////////////////////////////////////
EXPCL_PANDAEGG PT(PandaNode)
load_egg_file(const string &filename, CoordinateSystem cs = CS_default,
load_egg_file(const Filename &filename, CoordinateSystem cs = CS_default,
BamCacheRecord *record = NULL);
////////////////////////////////////////////////////////////////////

View File

@ -82,3 +82,26 @@ INLINE int VirtualFileList::
size() const {
return _files.size();
}
////////////////////////////////////////////////////////////////////
// Function: VirtualFileList::operator +=
// Access: Published
// Description: Appends the other list onto the end of this one.
////////////////////////////////////////////////////////////////////
INLINE void VirtualFileList::
operator += (const VirtualFileList &other) {
_files.insert(_files.end(), other._files.begin(), other._files.end());
}
////////////////////////////////////////////////////////////////////
// Function: VirtualFileList::operator +
// Access: Published
// Description: Returns a VirtualFileList representing the
// concatenation of the two lists.
////////////////////////////////////////////////////////////////////
INLINE VirtualFileList VirtualFileList::
operator + (const VirtualFileList &other) const {
VirtualFileList a(*this);
a += other;
return a;
}

View File

@ -42,6 +42,8 @@ PUBLISHED:
INLINE VirtualFile *operator [](int n) const;
INLINE int size() const;
INLINE void operator += (const VirtualFileList &other);
INLINE VirtualFileList operator + (const VirtualFileList &other) const;
private:
typedef pvector< PT(VirtualFile) > Files;

View File

@ -39,7 +39,7 @@ VirtualFileMount::
// used to read it.
////////////////////////////////////////////////////////////////////
PT(VirtualFile) VirtualFileMount::
make_virtual_file(const string &local_filename,
make_virtual_file(const Filename &local_filename,
const Filename &original_filename, bool implicit_pz_file,
bool) {
Filename local(local_filename);

View File

@ -40,7 +40,7 @@ PUBLISHED:
INLINE int get_mount_flags() const;
public:
virtual PT(VirtualFile) make_virtual_file(const string &local_filename,
virtual PT(VirtualFile) make_virtual_file(const Filename &local_filename,
const Filename &original_filename,
bool implicit_pz_file,
bool status_only);

View File

@ -48,16 +48,33 @@ is_regular_file(const Filename &filename) const {
return (file != (VirtualFile *)NULL && file->is_regular_file());
}
////////////////////////////////////////////////////////////////////
// Function: VirtualFileSystem::scan_directory
// Access: Published
// Description: If the file represents a directory (that is,
// is_directory() returns true), this returns the list
// of files within the directory at the current time.
// Returns NULL if the file is not a directory or if the
// directory cannot be read.
////////////////////////////////////////////////////////////////////
INLINE PT(VirtualFileList) VirtualFileSystem::
scan_directory(const Filename &filename) const {
PT(VirtualFile) file = get_file(filename, true);
if (file == (VirtualFile *)NULL) {
return NULL;
}
return file->scan_directory();
}
////////////////////////////////////////////////////////////////////
// Function: VirtualFileSystem::ls
// Access: Published
// Description: Convenience function; lists the files within the
// indicated directory. This accepts a string instead
// of a Filename purely for programmer convenience at
// the Python prompt.
// indicated directory.
////////////////////////////////////////////////////////////////////
INLINE void VirtualFileSystem::
ls(const string &filename) const {
ls(const Filename &filename) const {
PT(VirtualFile) file = get_file(filename, true);
if (file == (VirtualFile *)NULL) {
express_cat.info()
@ -72,12 +89,10 @@ ls(const string &filename) const {
// Access: Published
// Description: Convenience function; lists the files within the
// indicated directory, and all files below,
// recursively. This accepts a string instead of a
// Filename purely for programmer convenience at the
// Python prompt.
// recursively.
////////////////////////////////////////////////////////////////////
INLINE void VirtualFileSystem::
ls_all(const string &filename) const {
ls_all(const Filename &filename) const {
PT(VirtualFile) file = get_file(filename, true);
if (file == (VirtualFile *)NULL) {
express_cat.info()

View File

@ -80,7 +80,7 @@ VirtualFileSystem::
// point.
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
mount(Multifile *multifile, const string &mount_point, int flags) {
mount(Multifile *multifile, const Filename &mount_point, int flags) {
PT(VirtualFileMountMultifile) new_mount =
new VirtualFileMountMultifile(multifile);
return mount(new_mount, mount_point, flags);
@ -108,7 +108,7 @@ mount(Multifile *multifile, const string &mount_point, int flags) {
// file system with exactly the right case.
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
mount(const Filename &physical_filename, const string &mount_point,
mount(const Filename &physical_filename, const Filename &mount_point,
int flags, const string &password) {
if (!physical_filename.exists()) {
express_cat.warning()
@ -145,7 +145,7 @@ mount(const Filename &physical_filename, const string &mount_point,
// VirtualFileMount object specifically.
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
mount(VirtualFileMount *mount, const string &mount_point, int flags) {
mount(VirtualFileMount *mount, const Filename &mount_point, int flags) {
_lock.acquire();
bool result = do_mount(mount, mount_point, flags);
_lock.release();
@ -287,7 +287,7 @@ unmount(VirtualFileMount *mount) {
// appearances unmounted.
////////////////////////////////////////////////////////////////////
int VirtualFileSystem::
unmount_point(const string &mount_point) {
unmount_point(const Filename &mount_point) {
_lock.acquire();
Filename nmp = normalize_mount_point(mount_point);
Mounts::iterator ri, wi;
@ -373,12 +373,9 @@ get_mount(int n) const {
// resolve relative pathnames in get_file() and/or
// find_file(). Returns true if successful, false
// otherwise.
//
// This accepts a string rather than a Filename simply
// for programmer convenience from the Python prompt.
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
chdir(const string &new_directory) {
chdir(const Filename &new_directory) {
_lock.acquire();
if (new_directory == "/") {
// We can always return to the root.
@ -803,7 +800,7 @@ parse_option(const string &option, int &flags, string &password) {
// Assumes the lock is already held.
////////////////////////////////////////////////////////////////////
Filename VirtualFileSystem::
normalize_mount_point(const string &mount_point) const {
normalize_mount_point(const Filename &mount_point) const {
Filename nmp = mount_point;
if (nmp.is_local()) {
nmp = Filename(_cwd, mount_point);
@ -820,7 +817,7 @@ normalize_mount_point(const string &mount_point) const {
// lock is already held.
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
do_mount(VirtualFileMount *mount, const string &mount_point, int flags) {
do_mount(VirtualFileMount *mount, const Filename &mount_point, int flags) {
nassertr(mount->_file_system == NULL, false);
mount->_file_system = this;
mount->_mount_point = normalize_mount_point(mount_point);
@ -847,9 +844,9 @@ do_get_file(const Filename &filename, bool status_only) const {
}
}
pathname.standardize();
string strpath = pathname.get_filename_index(0).get_fullpath().substr(1);
Filename strpath = pathname.get_filename_index(0).get_fullpath().substr(1);
// Also transparently look for a regular file suffixed .pz.
string strpath_pz = strpath + ".pz";
Filename strpath_pz = strpath + ".pz";
// Now scan all the mount points, from the back (since later mounts
// override more recent ones), until a match is found.
@ -864,7 +861,7 @@ do_get_file(const Filename &filename, bool status_only) const {
while (i > 0) {
--i;
VirtualFileMount *mount = _mounts[i];
string mount_point = mount->get_mount_point();
Filename mount_point = mount->get_mount_point();
if (strpath == mount_point) {
// Here's an exact match on the mount point. This filename is
// the root directory of this mount object.
@ -888,7 +885,7 @@ do_get_file(const Filename &filename, bool status_only) const {
#endif // HAVE_ZLIB
} else if (strpath.length() > mount_point.length() &&
strpath.substr(0, mount_point.length()) == mount_point &&
mount_point == strpath.substr(0, mount_point.length()) &&
strpath[mount_point.length()] == '/') {
// This pathname falls within this mount system.
Filename local_filename = strpath.substr(mount_point.length() + 1);
@ -947,7 +944,7 @@ do_get_file(const Filename &filename, bool status_only) const {
////////////////////////////////////////////////////////////////////
bool VirtualFileSystem::
consider_match(PT(VirtualFile) &found_file, VirtualFileComposite *&composite_file,
VirtualFileMount *mount, const string &local_filename,
VirtualFileMount *mount, const Filename &local_filename,
const Filename &original_filename, bool implicit_pz_file,
bool status_only) const {
PT(VirtualFile) vfile =

View File

@ -19,6 +19,7 @@
#include "virtualFile.h"
#include "virtualFileMount.h"
#include "virtualFileList.h"
#include "filename.h"
#include "dSearchPath.h"
#include "pointerTo.h"
@ -49,20 +50,20 @@ PUBLISHED:
MF_read_only = 0x0002,
};
BLOCKING bool mount(Multifile *multifile, const string &mount_point, int flags);
BLOCKING bool mount(const Filename &physical_filename, const string &mount_point,
BLOCKING bool mount(Multifile *multifile, const Filename &mount_point, int flags);
BLOCKING bool mount(const Filename &physical_filename, const Filename &mount_point,
int flags, const string &password = "");
bool mount(VirtualFileMount *mount, const string &mount_point, int flags);
bool mount(VirtualFileMount *mount, const Filename &mount_point, int flags);
BLOCKING int unmount(Multifile *multifile);
BLOCKING int unmount(const Filename &physical_filename);
int unmount(VirtualFileMount *mount);
BLOCKING int unmount_point(const string &mount_point);
BLOCKING int unmount_point(const Filename &mount_point);
BLOCKING int unmount_all();
int get_num_mounts() const;
PT(VirtualFileMount) get_mount(int n) const;
BLOCKING bool chdir(const string &new_directory);
BLOCKING bool chdir(const Filename &new_directory);
BLOCKING Filename get_cwd() const;
BLOCKING PT(VirtualFile) get_file(const Filename &filename, bool status_only = false) const;
@ -78,8 +79,10 @@ PUBLISHED:
BLOCKING INLINE bool is_directory(const Filename &filename) const;
BLOCKING INLINE bool is_regular_file(const Filename &filename) const;
INLINE void ls(const string &filename) const;
INLINE void ls_all(const string &filename) const;
BLOCKING INLINE PT(VirtualFileList) scan_directory(const Filename &filename) const;
INLINE void ls(const Filename &filename) const;
INLINE void ls_all(const Filename &filename) const;
void write(ostream &out) const;
@ -107,11 +110,11 @@ public:
ConfigVariableBool vfs_implicit_mf;
private:
Filename normalize_mount_point(const string &mount_point) const;
bool do_mount(VirtualFileMount *mount, const string &mount_point, int flags);
Filename normalize_mount_point(const Filename &mount_point) const;
bool do_mount(VirtualFileMount *mount, const Filename &mount_point, int flags);
PT(VirtualFile) do_get_file(const Filename &filename, bool status_only) const;
bool consider_match(PT(VirtualFile) &found_file, VirtualFileComposite *&composite_file,
VirtualFileMount *mount, const string &local_filename,
VirtualFileMount *mount, const Filename &local_filename,
const Filename &original_filename, bool implicit_pz_file,
bool status_only) const;
bool consider_mount_mf(const Filename &filename);

View File

@ -5208,6 +5208,8 @@ write_datagram(BamWriter *manager, Datagram &me) {
Filename filename = _filename;
Filename alpha_filename = _alpha_filename;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
switch (file_texture_mode) {
case BTM_unchanged:
case BTM_rawdata:
@ -5221,7 +5223,7 @@ write_datagram(BamWriter *manager, Datagram &me) {
case BTM_relative:
filename = _fullpath;
alpha_filename = _alpha_fullpath;
bam_dir.make_absolute();
bam_dir.make_absolute(vfs->get_cwd());
if (!has_bam_dir || !filename.make_relative_to(bam_dir, true)) {
filename.find_on_searchpath(get_model_path());
}

View File

@ -20,7 +20,7 @@
// false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool TexturePool::
has_texture(const string &filename) {
has_texture(const Filename &filename) {
return get_global_ptr()->ns_has_texture(filename);
}
@ -35,7 +35,7 @@ has_texture(const string &filename) {
// return a valid Texture pointer.
////////////////////////////////////////////////////////////////////
INLINE bool TexturePool::
verify_texture(const string &filename) {
verify_texture(const Filename &filename) {
return load_texture(filename) != (Texture *)NULL;
}
@ -54,7 +54,7 @@ verify_texture(const string &filename) {
// with a series of images, one for each mipmap level.
////////////////////////////////////////////////////////////////////
INLINE Texture *TexturePool::
load_texture(const string &filename, int primary_file_num_channels,
load_texture(const Filename &filename, int primary_file_num_channels,
bool read_mipmaps, const LoaderOptions &options) {
return get_global_ptr()->ns_load_texture(filename, primary_file_num_channels,
read_mipmaps, options);
@ -76,7 +76,7 @@ load_texture(const string &filename, int primary_file_num_channels,
// level.
////////////////////////////////////////////////////////////////////
INLINE Texture *TexturePool::
load_texture(const string &filename, const string &alpha_filename,
load_texture(const Filename &filename, const Filename &alpha_filename,
int primary_file_num_channels, int alpha_file_channel,
bool read_mipmaps, const LoaderOptions &options) {
return get_global_ptr()->ns_load_texture(filename, alpha_filename,
@ -100,7 +100,7 @@ load_texture(const string &filename, const string &alpha_filename,
// second with the index number of each 3-d level.
////////////////////////////////////////////////////////////////////
INLINE Texture *TexturePool::
load_3d_texture(const string &filename_pattern, bool read_mipmaps,
load_3d_texture(const Filename &filename_pattern, bool read_mipmaps,
const LoaderOptions &options) {
return get_global_ptr()->ns_load_3d_texture(filename_pattern, read_mipmaps,
options);
@ -121,7 +121,7 @@ load_3d_texture(const string &filename_pattern, bool read_mipmaps,
// second with the face number, 0 through 5.
////////////////////////////////////////////////////////////////////
INLINE Texture *TexturePool::
load_cube_map(const string &filename_pattern, bool read_mipmaps,
load_cube_map(const Filename &filename_pattern, bool read_mipmaps,
const LoaderOptions &options) {
return get_global_ptr()->ns_load_cube_map(filename_pattern, read_mipmaps,
options);
@ -255,7 +255,7 @@ list_contents() {
// any textures requested from this point on.
////////////////////////////////////////////////////////////////////
INLINE void TexturePool::
set_fake_texture_image(const string &filename) {
set_fake_texture_image(const Filename &filename) {
get_global_ptr()->_fake_texture_image = filename;
}
@ -287,7 +287,7 @@ has_fake_texture_image() {
// Description: Returns the filename that was specified with a
// previous call to set_fake_texture_image().
////////////////////////////////////////////////////////////////////
INLINE const string &TexturePool::
INLINE const Filename &TexturePool::
get_fake_texture_image() {
return get_global_ptr()->_fake_texture_image;
}

View File

@ -189,7 +189,7 @@ get_global_ptr() {
////////////////////////////////////////////////////////////////////
TexturePool::
TexturePool() {
ConfigVariableString fake_texture_image
ConfigVariableFilename fake_texture_image
("fake-texture-image", "",
PRC_DESC("Set this to enable a speedy-load mode in which you don't care "
"what the world looks like, you just want it to load in minimal "
@ -830,8 +830,8 @@ ns_list_contents(ostream &out) const {
////////////////////////////////////////////////////////////////////
// Function: TexturePool::resolve_filename
// Access: Private
// Description: Searches for the indicated filename along the texture
// and model path. If the filename was previously
// Description: Searches for the indicated filename along the
// model path. If the filename was previously
// searched for, doesn't search again, as an
// optimization. Assumes _lock is held.
////////////////////////////////////////////////////////////////////

View File

@ -37,25 +37,22 @@ class BamCacheRecord;
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_GOBJ TexturePool {
PUBLISHED:
// These functions take string parameters instead of Filenames
// because that's somewhat more convenient to the scripting
// language.
INLINE static bool has_texture(const string &filename);
INLINE static bool verify_texture(const string &filename);
INLINE static Texture *load_texture(const string &filename,
INLINE static bool has_texture(const Filename &filename);
INLINE static bool verify_texture(const Filename &filename);
INLINE static Texture *load_texture(const Filename &filename,
int primary_file_num_channels = 0,
bool read_mipmaps = false,
const LoaderOptions &options = LoaderOptions());
INLINE static Texture *load_texture(const string &filename,
const string &alpha_filename,
INLINE static Texture *load_texture(const Filename &filename,
const Filename &alpha_filename,
int primary_file_num_channels = 0,
int alpha_file_channel = 0,
bool read_mipmaps = false,
const LoaderOptions &options = LoaderOptions());
INLINE static Texture *load_3d_texture(const string &filename_pattern,
INLINE static Texture *load_3d_texture(const Filename &filename_pattern,
bool read_mipmaps = false,
const LoaderOptions &options = LoaderOptions());
INLINE static Texture *load_cube_map(const string &filename_pattern,
INLINE static Texture *load_cube_map(const Filename &filename_pattern,
bool read_mipmaps = false,
const LoaderOptions &options = LoaderOptions());
@ -72,10 +69,10 @@ PUBLISHED:
INLINE static void list_contents(ostream &out);
INLINE static void list_contents();
INLINE static void set_fake_texture_image(const string &filename);
INLINE static void set_fake_texture_image(const Filename &filename);
INLINE static void clear_fake_texture_image();
INLINE static bool has_fake_texture_image();
INLINE static const string &get_fake_texture_image();
INLINE static const Filename &get_fake_texture_image();
static void write(ostream &out);
@ -145,7 +142,7 @@ private:
typedef pmap<Filename, Filename> RelpathLookup;
RelpathLookup _relpath_lookup;
string _fake_texture_image;
Filename _fake_texture_image;
PT(Texture) _normalization_cube_map;
PT(Texture) _alpha_scale_map;

View File

@ -20,7 +20,7 @@
// false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool ModelPool::
has_model(const string &filename) {
has_model(const Filename &filename) {
return get_ptr()->ns_has_model(filename);
}
@ -35,7 +35,7 @@ has_model(const string &filename) {
// return a valid Node pointer.
////////////////////////////////////////////////////////////////////
INLINE bool ModelPool::
verify_model(const string &filename) {
verify_model(const Filename &filename) {
return load_model(filename) != (ModelRoot *)NULL;
}
@ -49,7 +49,7 @@ verify_model(const string &filename) {
// file cannot be found, returns NULL.
////////////////////////////////////////////////////////////////////
INLINE ModelRoot *ModelPool::
load_model(const string &filename, const LoaderOptions &options) {
load_model(const Filename &filename, const LoaderOptions &options) {
return get_ptr()->ns_load_model(filename, options);
}
@ -66,7 +66,7 @@ load_model(const string &filename, const LoaderOptions &options) {
// instead.
////////////////////////////////////////////////////////////////////
INLINE void ModelPool::
add_model(const string &filename, ModelRoot *model) {
add_model(const Filename &filename, ModelRoot *model) {
get_ptr()->ns_add_model(filename, model);
}
@ -83,7 +83,7 @@ add_model(const string &filename, ModelRoot *model) {
// release_model(model) instead.
////////////////////////////////////////////////////////////////////
INLINE void ModelPool::
release_model(const string &filename) {
release_model(const Filename &filename) {
get_ptr()->ns_release_model(filename);
}

View File

@ -38,7 +38,7 @@ write(ostream &out) {
// Description: The nonstatic implementation of has_model().
////////////////////////////////////////////////////////////////////
bool ModelPool::
ns_has_model(const string &filename) {
ns_has_model(const Filename &filename) {
LightMutexHolder holder(_lock);
Models::const_iterator ti;
ti = _models.find(filename);
@ -56,7 +56,7 @@ ns_has_model(const string &filename) {
// Description: The nonstatic implementation of load_model().
////////////////////////////////////////////////////////////////////
ModelRoot *ModelPool::
ns_load_model(const string &filename, const LoaderOptions &options) {
ns_load_model(const Filename &filename, const LoaderOptions &options) {
{
LightMutexHolder holder(_lock);
Models::const_iterator ti;
@ -114,7 +114,7 @@ ns_load_model(const string &filename, const LoaderOptions &options) {
// Description: The nonstatic implementation of add_model().
////////////////////////////////////////////////////////////////////
void ModelPool::
ns_add_model(const string &filename, ModelRoot *model) {
ns_add_model(const Filename &filename, ModelRoot *model) {
LightMutexHolder holder(_lock);
// We blow away whatever model was there previously, if any.
_models[filename] = model;
@ -126,7 +126,7 @@ ns_add_model(const string &filename, ModelRoot *model) {
// Description: The nonstatic implementation of release_model().
////////////////////////////////////////////////////////////////////
void ModelPool::
ns_release_model(const string &filename) {
ns_release_model(const Filename &filename) {
LightMutexHolder holder(_lock);
Models::iterator ti;
ti = _models.find(filename);

View File

@ -47,13 +47,13 @@
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PGRAPH ModelPool {
PUBLISHED:
INLINE static bool has_model(const string &filename);
INLINE static bool verify_model(const string &filename);
INLINE static ModelRoot *load_model(const string &filename,
INLINE static bool has_model(const Filename &filename);
INLINE static bool verify_model(const Filename &filename);
INLINE static ModelRoot *load_model(const Filename &filename,
const LoaderOptions &options = LoaderOptions());
INLINE static void add_model(const string &filename, ModelRoot *model);
INLINE static void release_model(const string &filename);
INLINE static void add_model(const Filename &filename, ModelRoot *model);
INLINE static void release_model(const Filename &filename);
INLINE static void add_model(ModelRoot *model);
INLINE static void release_model(ModelRoot *model);
@ -69,11 +69,11 @@ PUBLISHED:
private:
INLINE ModelPool();
bool ns_has_model(const string &filename);
ModelRoot *ns_load_model(const string &filename,
bool ns_has_model(const Filename &filename);
ModelRoot *ns_load_model(const Filename &filename,
const LoaderOptions &options);
void ns_add_model(const string &filename, ModelRoot *model);
void ns_release_model(const string &filename);
void ns_add_model(const Filename &filename, ModelRoot *model);
void ns_release_model(const Filename &filename);
void ns_add_model(ModelRoot *model);
void ns_release_model(ModelRoot *model);
@ -87,7 +87,7 @@ private:
static ModelPool *_global_ptr;
LightMutex _lock;
typedef pmap<string, PT(ModelRoot) > Models;
typedef pmap<Filename, PT(ModelRoot) > Models;
Models _models;
};

View File

@ -20,7 +20,7 @@
// false otherwise.
////////////////////////////////////////////////////////////////////
INLINE bool ShaderPool::
has_shader(const string &filename) {
has_shader(const Filename &filename) {
return get_ptr()->ns_has_shader(filename);
}
@ -35,7 +35,7 @@ has_shader(const string &filename) {
// return a valid Shader pointer.
////////////////////////////////////////////////////////////////////
INLINE bool ShaderPool::
verify_shader(const string &filename) {
verify_shader(const Filename &filename) {
return load_shader(filename) != (Shader *)NULL;
}
@ -49,7 +49,7 @@ verify_shader(const string &filename) {
// file cannot be found, returns NULL.
////////////////////////////////////////////////////////////////////
INLINE CPT(Shader) ShaderPool::
load_shader(const string &filename) {
load_shader(const Filename &filename) {
return get_ptr()->ns_load_shader(filename);
}
@ -62,7 +62,7 @@ load_shader(const string &filename) {
// same filename.
////////////////////////////////////////////////////////////////////
INLINE void ShaderPool::
add_shader(const string &filename, Shader *shader) {
add_shader(const Filename &filename, Shader *shader) {
get_ptr()->ns_add_shader(filename, shader);
}
@ -76,7 +76,7 @@ add_shader(const string &filename, Shader *shader) {
// every loaded, and shaders will never be freed.
////////////////////////////////////////////////////////////////////
INLINE void ShaderPool::
release_shader(const string &filename) {
release_shader(const Filename &filename) {
get_ptr()->ns_release_shader(filename);
}

View File

@ -38,16 +38,13 @@ write(ostream &out) {
// Description: The nonstatic implementation of has_shader().
////////////////////////////////////////////////////////////////////
bool ShaderPool::
ns_has_shader(const string &str) {
LightMutexHolder holder(_lock);
string index_str;
ns_has_shader(const Filename &orig_filename) {
Filename filename;
int face_index;
lookup_filename(str, index_str, filename, face_index);
resolve_filename(filename, orig_filename);
LightMutexHolder holder(_lock);
Shaders::const_iterator ti;
ti = _shaders.find(index_str);
ti = _shaders.find(filename);
if (ti != _shaders.end()) {
// This shader was previously loaded.
return true;
@ -62,17 +59,15 @@ ns_has_shader(const string &str) {
// Description: The nonstatic implementation of load_shader().
////////////////////////////////////////////////////////////////////
CPT(Shader) ShaderPool::
ns_load_shader(const string &str) {
string index_str;
ns_load_shader(const Filename &orig_filename) {
Filename filename;
int face_index;
lookup_filename(str, index_str, filename, face_index);
resolve_filename(filename, orig_filename);
{
LightMutexHolder holder(_lock);
Shaders::const_iterator ti;
ti = _shaders.find(index_str);
ti = _shaders.find(filename);
if (ti != _shaders.end()) {
// This shader was previously loaded.
return (*ti).second;
@ -93,8 +88,6 @@ ns_load_shader(const string &str) {
// this does nothing for now
}
// ***** face_index ???
if (shader == (CPT(Shader)) NULL) {
shader = Shader::load (filename);
}
@ -110,13 +103,13 @@ ns_load_shader(const string &str) {
// Now try again. Someone may have loaded the shader in another
// thread.
Shaders::const_iterator ti;
ti = _shaders.find(index_str);
ti = _shaders.find(filename);
if (ti != _shaders.end()) {
// This shader was previously loaded.
return (*ti).second;
}
_shaders[index_str] = shader;
_shaders[filename] = shader;
}
return shader;
@ -128,16 +121,13 @@ ns_load_shader(const string &str) {
// Description: The nonstatic implementation of add_shader().
////////////////////////////////////////////////////////////////////
void ShaderPool::
ns_add_shader(const string &str, Shader *shader) {
LightMutexHolder holder(_lock);
string index_str;
ns_add_shader(const Filename &orig_filename, Shader *shader) {
Filename filename;
int face_index;
lookup_filename(str, index_str, filename, face_index);
resolve_filename(filename, orig_filename);
LightMutexHolder holder(_lock);
// We blow away whatever shader was there previously, if any.
_shaders[index_str] = shader;
_shaders[filename] = shader;
}
////////////////////////////////////////////////////////////////////
@ -146,7 +136,7 @@ ns_add_shader(const string &str, Shader *shader) {
// Description: The nonstatic implementation of release_shader().
////////////////////////////////////////////////////////////////////
void ShaderPool::
ns_release_shader(const string &filename) {
ns_release_shader(const Filename &filename) {
LightMutexHolder holder(_lock);
Shaders::iterator ti;
@ -218,43 +208,18 @@ ns_list_contents(ostream &out) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: ShaderPool::lookup_filename
// Access: Private, Static
// Description: Accepts a shader "filename", which might consist of a
// filename followed by an optional colon and a face
// index, and splits it out into its two components.
// Then it looks up the filename on the model path.
// Sets the filename and face index accordingly. Also
// sets index_str to be the concatenation of the
// found filename with the face index, thus restoring
// the original input (but normalized to contain the
// full path.)
// Function: ShaderPool::resolve_filename
// Access: Private
// Description: Searches for the indicated filename along the
// model path.
////////////////////////////////////////////////////////////////////
void ShaderPool::
lookup_filename(const string &str, string &index_str,
Filename &filename, int &face_index) {
int colon = (int)str.length() - 1;
// Scan backwards over digits for a colon.
while (colon >= 0 && isdigit(str[colon])) {
--colon;
}
if (colon >= 0 && str[colon] == ':') {
string digits = str.substr(colon + 1);
filename = str.substr(0, colon);
face_index = atoi(digits.c_str());
} else {
filename = str;
face_index = 0;
}
// Now look up the filename on the model path.
resolve_filename(Filename &new_filename, const Filename &orig_filename) {
new_filename = orig_filename;
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
vfs->resolve_filename(filename, get_model_path());
ostringstream strm;
strm << filename << ":" << face_index;
index_str = strm.str();
vfs->resolve_filename(new_filename, get_model_path());
}
////////////////////////////////////////////////////////////////////

View File

@ -30,14 +30,11 @@
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PGRAPH ShaderPool {
PUBLISHED:
// These functions take string parameters instead of Filenames
// because that's somewhat more convenient to the scripting
// language.
INLINE static bool has_shader(const string &filename);
INLINE static bool verify_shader(const string &filename);
INLINE static CPT(Shader) load_shader(const string &filename);
INLINE static void add_shader(const string &filename, Shader *shader);
INLINE static void release_shader(const string &filename);
INLINE static bool has_shader(const Filename &filename);
INLINE static bool verify_shader(const Filename &filename);
INLINE static CPT(Shader) load_shader(const Filename &filename);
INLINE static void add_shader(const Filename &filename, Shader *shader);
INLINE static void release_shader(const Filename &filename);
INLINE static void release_all_shaders();
INLINE static int garbage_collect();
@ -48,22 +45,21 @@ PUBLISHED:
private:
INLINE ShaderPool();
bool ns_has_shader(const string &str);
CPT(Shader) ns_load_shader(const string &str);
void ns_add_shader(const string &str, Shader *shader);
void ns_release_shader(const string &filename);
bool ns_has_shader(const Filename &orig_filename);
CPT(Shader) ns_load_shader(const Filename &orig_filename);
void ns_add_shader(const Filename &orig_filename, Shader *shader);
void ns_release_shader(const Filename &orig_filename);
void ns_release_all_shaders();
int ns_garbage_collect();
void ns_list_contents(ostream &out) const;
static void lookup_filename(const string &str, string &index_str,
Filename &filename, int &face_index);
void resolve_filename(Filename &new_filename, const Filename &orig_filename);
static ShaderPool *get_ptr();
static ShaderPool *_global_ptr;
LightMutex _lock;
typedef pmap<string, CPT(Shader) > Shaders;
typedef pmap<Filename, CPT(Shader) > Shaders;
Shaders _shaders;
};

View File

@ -24,6 +24,7 @@
#include "configVariableInt.h"
#include "configVariableString.h"
#include "configVariableFilename.h"
#include "virtualFileSystem.h"
BamCache *BamCache::_global_ptr = NULL;
@ -159,9 +160,11 @@ set_root(const Filename &root) {
PT(BamCacheRecord) BamCache::
lookup(const Filename &source_filename, const string &cache_extension) {
consider_flush_index();
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
Filename source_pathname(source_filename);
source_pathname.make_absolute();
source_pathname.make_absolute(vfs->get_cwd());
Filename rel_pathname(source_pathname);
rel_pathname.make_relative_to(_root, false);

View File

@ -89,6 +89,7 @@ public:
static BamReader *const Null;
static WritableFactory *const NullFactory;
PUBLISHED:
// The primary interface for a caller.
BamReader(DatagramGenerator *generator, const Filename &name = "");
~BamReader();

View File

@ -17,6 +17,7 @@
#include "pandabase.h"
BEGIN_PUBLISH
// This enum is used to control how textures are written to a bam
// stream.
enum BamTextureMode {
@ -26,6 +27,8 @@ enum BamTextureMode {
BTM_basename,
BTM_rawdata
};
END_PUBLISH
EXPCL_PANDA_PUTIL ostream &operator << (ostream &out, BamTextureMode btm);
EXPCL_PANDA_PUTIL istream &operator >> (istream &in, BamTextureMode &btm);

View File

@ -72,12 +72,10 @@
// interface to read and write Bam files on disk.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PUTIL BamWriter {
public:
PUBLISHED:
BamWriter(DatagramSink *sink, const Filename &name = "");
~BamWriter();
// The primary interface for a caller.
bool init();
INLINE const Filename &get_filename() const;
bool write_object(const TypedWritable *obj);

View File

@ -39,7 +39,7 @@
// putil).
////////////////////////////////////////////////////////////////////
ConfigPage *
load_prc_file(const string &filename) {
load_prc_file(const Filename &filename) {
Filename path = filename;
path.set_text();

View File

@ -16,6 +16,7 @@
#define LOAD_PRC_FILE_H
#include "pandabase.h"
#include "filename.h"
class ConfigPage;
class HashVal;
@ -40,7 +41,7 @@ BEGIN_PUBLISH
// putil).
////////////////////////////////////////////////////////////////////
EXPCL_PANDA_PUTIL ConfigPage *
load_prc_file(const string &filename);
load_prc_file(const Filename &filename);
////////////////////////////////////////////////////////////////////
// Function: load_prc_file_data

View File

@ -33,8 +33,9 @@
class EXPCL_PANDA_TEXT FontPool {
PUBLISHED:
// These functions take string parameters instead of Filenames
// because that's somewhat more convenient to the scripting
// language.
// because the parameters may not be entirely an actual filename:
// they may be a filename followed by a face index.
INLINE static bool has_font(const string &filename);
INLINE static bool verify_font(const string &filename);
INLINE static TextFont *load_font(const string &filename);