fix PandaSystem.hasSystem() etc.

This commit is contained in:
David Rose 2005-02-19 00:00:47 +00:00
parent ff642fe771
commit 2a39759b85
49 changed files with 357 additions and 239 deletions

View File

@ -235,6 +235,7 @@ class ShowBase(DirectObject.DirectObject):
__builtins__["vfs"] = vfs
__builtins__["cpMgr"] = ConfigPageManager.getGlobalPtr()
__builtins__["cvMgr"] = ConfigVariableManager.getGlobalPtr()
__builtins__["pandaSystem"] = PandaSystem.getGlobalPtr()
__builtins__["__dev__"] = base.config.GetBool('want-dev', 0)
__builtins__["wantOtpServer"] = base.config.GetBool('want-otp-server', 0)
if __debug__:

View File

@ -169,7 +169,7 @@ get_num_systems() const {
////////////////////////////////////////////////////////////////////
string PandaSystem::
get_system(int n) const {
if (n < 0 || n >= (int)_system_names.size()) {
if (n < 0 || n >= (int)_systems.size()) {
return string();
}
@ -241,6 +241,38 @@ set_system_tag(const string &system, const string &tag,
SystemTags &tags = (*result.first).second;
tags[tag] = value;
}
////////////////////////////////////////////////////////////////////
// Function: PandaSystem::output
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void PandaSystem::
output(ostream &out) const {
out << "Panda version " << get_version_string();
}
////////////////////////////////////////////////////////////////////
// Function: PandaSystem::write
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void PandaSystem::
write(ostream &out) const {
out << *this << ":\n";
for (Systems::const_iterator si = _systems.begin();
si != _systems.end();
++si) {
out << " " << (*si).first << "\n";
const SystemTags &tags = (*si).second;
SystemTags::const_iterator ti;
for (ti = tags.begin(); ti != tags.end(); ++ti) {
out << " " << (*ti).first << " " << (*ti).second << "\n";
}
}
}
////////////////////////////////////////////////////////////////////
// Function: PandaSystem::get_global_ptr

View File

@ -54,6 +54,9 @@ PUBLISHED:
void set_system_tag(const string &system, const string &tag,
const string &value);
void output(ostream &out) const;
void write(ostream &out) const;
static PandaSystem *get_global_ptr();
private:
@ -70,6 +73,11 @@ private:
static PandaSystem *_global_ptr;
};
inline ostream &operator << (ostream &out, const PandaSystem &ps) {
ps.output(out);
return out;
}
#endif

View File

@ -6,14 +6,12 @@
#include "pandagl.h"
#ifndef LINK_IN_GL
#include <config_glgsg.h>
// Temporarily commented out for development on wgldisplay
/*
#include "config_glgsg.h"
#ifdef HAVE_WGL
#include <config_wgldisplay.h>
#endif
*/
#endif
#include "config_wgldisplay.h"
#endif // HAVE_WGL
#endif // LINK_IN_GL
// By including checkPandaVersion.h, we guarantee that runtime
// attempts to load libpandagl.so/.dll will fail if they inadvertently
@ -33,11 +31,8 @@ void
init_libpandagl() {
#ifndef LINK_IN_GL
init_libglgsg();
// Temporarily commented out for development on wgldisplay
/*
#ifdef HAVE_WGL
init_libwgldisplay();
#endif
*/
#endif
#endif // HAVE_GL
#endif // LINK_IN_GL
}

View File

@ -23,6 +23,7 @@
#include "config_fmodAudio.h"
#include "fmodAudioManager.h"
#include "fmodAudioSound.h"
#include "pandaSystem.h"
#include "dconfig.h"
ConfigureDef(config_fmodAudio);
@ -50,6 +51,11 @@ init_libFmodAudio() {
initialized = true;
AudioManager::register_AudioManager_creator(Create_AudioManager);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("FMOD");
ps->add_system("audio");
ps->set_system_tag("audio", "implementation", "FMOD");
}
#endif //]

View File

@ -22,6 +22,7 @@
#include "config_milesAudio.h"
#include "milesAudioManager.h"
#include "milesAudioSound.h"
#include "pandaSystem.h"
#include "dconfig.h"
ConfigureDef(config_milesAudio);
@ -72,6 +73,11 @@ init_libMilesAudio() {
MilesAudioManager::init_type();
MilesAudioSound::init_type();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("Miles");
ps->add_system("audio");
ps->set_system_tag("audio", "implementation", "Miles");
}
#endif //]

View File

@ -19,6 +19,7 @@
#include "dconfig.h"
#include "config_downloader.h"
#include "httpChannel.h"
#include "pandaSystem.h"
ConfigureDef(config_downloader);
@ -157,5 +158,8 @@ ConfigVariableList http_username
ConfigureFn(config_downloader) {
#ifdef HAVE_SSL
HTTPChannel::init_type();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("OpenSSL");
#endif
}

View File

@ -23,6 +23,7 @@
#include "wdxGraphicsPipe7.h"
#include "wdxGraphicsWindow7.h"
#include "graphicsPipeSelection.h"
#include "pandaSystem.h"
#include "dconfig.h"
@ -126,4 +127,7 @@ init_libdxgsg7() {
GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
selection->add_pipe_type(wdxGraphicsPipe7::get_class_type(),
wdxGraphicsPipe7::pipe_constructor);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("DirectX7");
}

View File

@ -23,6 +23,7 @@
#include "graphicsPipeSelection.h"
#include "wdxGraphicsWindow8.h"
#include "wdxGraphicsPipe8.h"
#include "pandaSystem.h"
#include "dconfig.h"
@ -152,4 +153,6 @@ init_libdxgsg8() {
selection->add_pipe_type(wdxGraphicsPipe8::get_class_type(),
wdxGraphicsPipe8::pipe_constructor);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("DirectX8");
}

View File

@ -23,6 +23,7 @@
#include "graphicsPipeSelection.h"
#include "wdxGraphicsWindow9.h"
#include "wdxGraphicsPipe9.h"
#include "pandaSystem.h"
#include "dconfig.h"
@ -152,4 +153,6 @@ init_libdxgsg9() {
selection->add_pipe_type(wdxGraphicsPipe9::get_class_type(),
wdxGraphicsPipe9::pipe_constructor);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("DirectX9");
}

View File

@ -21,6 +21,7 @@
#include "cgShaderAttrib.h"
#include "cgShaderContext.h"
#include "lensFlareNode.h"
#include "pandaSystem.h"
#include "dconfig.h"
@ -46,6 +47,9 @@ init_libeffects() {
CgShader::init_type();
CgShaderAttrib::init_type();
CgShaderContext::init_type();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("Cg");
#endif
#if 0 // temporarily disabled until we can port to new scene graph.
LensFlareNode::init_type();

View File

@ -155,7 +155,7 @@ init_libegg2pg() {
LoaderFileTypeEgg::init_type();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
reg->register_type(new LoaderFileTypeEgg);
}

View File

@ -561,13 +561,13 @@ load_model(const NodePath &parent, Filename filename) {
bool is_image = false;
string extension = filename.get_extension();
if (!extension.empty()) {
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
LoaderFileType *model_type =
reg->get_type_from_extension(extension);
if (model_type == (LoaderFileType *)NULL) {
// The extension isn't a known model file type, is it a known
// image extension?
PNMFileTypeRegistry *reg = PNMFileTypeRegistry::get_ptr();
PNMFileTypeRegistry *reg = PNMFileTypeRegistry::get_global_ptr();
PNMFileType *image_type =
reg->get_type_from_extension(extension);
if (image_type != (PNMFileType *)NULL) {

View File

@ -31,6 +31,7 @@
#define CLP(name) GL##name
#define GLPREFIX_QUOTED "gl"
#define CLASSPREFIX_QUOTED "GL"
#define GLSYSTEM_NAME "OpenGL"
#define CONFIGOBJ config_glgsg
#define GLCAT glgsg_cat
#define EXPCL_GL EXPCL_PANDAGL

View File

@ -16,6 +16,7 @@
//
////////////////////////////////////////////////////////////////////
#include "pandaSystem.h"
ConfigVariableBool CLP(cheap_textures)
("gl-cheap-textures", false,
@ -63,5 +64,12 @@ void CLP(init_classes)() {
CLP(SavedFrameBuffer)::init_type();
CLP(TextureContext)::init_type();
CLP(GeomContext)::init_type();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system(GLSYSTEM_NAME);
// We can't add any tags defining the available OpenGL capabilities,
// since we won't know those until we create a graphics context (and
// the answer may be different for different contexts).
}

View File

@ -23,6 +23,7 @@
#include "glxGraphicsStateGuardian.h"
#include "graphicsPipeSelection.h"
#include "dconfig.h"
#include "pandaSystem.h"
Configure(config_glxdisplay);
NotifyCategoryDef(glxdisplay, "display");
@ -63,4 +64,7 @@ init_libglxdisplay() {
GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
selection->add_pipe_type(glxGraphicsPipe::get_class_type(),
glxGraphicsPipe::pipe_constructor);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->set_system_tag("OpenGL", "window_system", "GLX");
}

View File

@ -31,16 +31,16 @@ ConfigureFn(config_linmath) {
ConfigVariableBool paranoid_hpr_quat
("paranoid-hpr-quat", false,
"Set this true to doublecheck the quaternion-hpr compose and "
"decompose operations against the quaternion-matrix and matrix-hpr "
"operations. This only has effect if NDEBUG is not defined.");
PRC_DESC("Set this true to doublecheck the quaternion-hpr compose and "
"decompose operations against the quaternion-matrix and matrix-hpr "
"operations. This only has effect if NDEBUG is not defined."));
ConfigVariableBool temp_hpr_fix
("temp-hpr-fix", true,
"Set this true to compute hpr's correctly. Historically, Panda has "
"applied these in the wrong order, and roll was backwards relative "
"to the other two. Set this false if you need compatibility with "
"Panda's old hpr calculations.");
PRC_DESC("Set this true to compute hpr's correctly. Historically, Panda has "
"applied these in the wrong order, and roll was backwards relative "
"to the other two. Set this false if you need compatibility with "
"Panda's old hpr calculations."));
////////////////////////////////////////////////////////////////////
// Function: init_liblinmath

View File

@ -26,6 +26,7 @@
#include "boundingLine.h"
#include "linmath_events.h"
#include "dconfig.h"
#include "pandaSystem.h"
Configure(config_mathutil);
NotifyCategoryDef(mathutil, "");
@ -57,5 +58,10 @@ ConfigureFn(config_mathutil) {
EventStoreVec2::register_with_read_factory();
EventStoreVec3::register_with_read_factory();
EventStoreMat4::register_with_read_factory();
#ifdef HAVE_FFTW
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("fftw");
#endif // FFTW
}

View File

@ -38,6 +38,7 @@
#endif
#define CLP(name) Mesa##name
#define CLASSPREFIX_QUOTED "Mesa"
#define GLSYSTEM_NAME "Mesa"
#define CONFIGOBJ config_mesadisplay
#define GLCAT mesadisplay_cat
#define EXPCL_GL EXPCL_PANDAMESA

View File

@ -19,6 +19,7 @@
#include "config_net.h"
#include "netDatagram.h"
#include "pandaSystem.h"
#include "dconfig.h"
@ -47,9 +48,13 @@ init_libnet() {
initialized = true;
NetDatagram::init_type();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("NSPR");
}
// The following two maximum queue sizes are totally arbitrary and
// serve only to provide sanity caps on the various queues in the net
// package. You can set them to any sane values you like. Also see

View File

@ -343,6 +343,6 @@ init_libpgraph() {
TransformState::register_with_read_factory();
TransparencyAttrib::register_with_read_factory();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
reg->register_type(new LoaderFileTypeBam);
}

View File

@ -104,7 +104,7 @@ find_all_files(const Filename &filename, const DSearchPath &search_path,
if (!extension.empty()) {
// If the extension is not empty, it specifies a single file type.
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
LoaderFileType *requested_type =
reg->get_type_from_extension(extension);
@ -132,7 +132,7 @@ find_all_files(const Filename &filename, const DSearchPath &search_path,
} else {
// If the extension *is* empty, we have to search for all possible
// file types.
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
int num_types = reg->get_num_types();
if (!filename.is_local()) {
@ -332,7 +332,7 @@ load_file_types() {
// Multiple words: the first n words are filename extensions,
// and the last word is the name of the library to load should
// any of those filename extensions be encountered.
LoaderFileTypeRegistry *registry = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *registry = LoaderFileTypeRegistry::get_global_ptr();
size_t num_extensions = words.size() - 1;
string library_name = words[num_extensions];
@ -424,7 +424,7 @@ load_file(const Filename &filename, bool search) const {
// unknown file type. Report a useful message either way.
string extension = filename.get_extension();
if (!extension.empty()) {
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
LoaderFileType *requested_type =
reg->get_type_from_extension(extension);
if (requested_type == (LoaderFileType *)NULL) {
@ -433,7 +433,7 @@ load_file(const Filename &filename, bool search) const {
<< " is unrecognized; cannot load.\n";
loader_cat.error(false)
<< "Currently known scene file types are:\n";
reg->write_types(loader_cat.error(false), 2);
reg->write(loader_cat.error(false), 2);
return NULL;
}
}

View File

@ -41,7 +41,7 @@ LoaderFileType::
////////////////////////////////////////////////////////////////////
// Function: LoaderFileType::get_additional_extensions
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Returns a space-separated list of extension, in
// addition to the one returned by get_extension(), that
// are recognized by this loader.

View File

@ -41,10 +41,12 @@ protected:
public:
virtual ~LoaderFileType();
PUBLISHED:
virtual string get_name() const=0;
virtual string get_extension() const=0;
virtual string get_additional_extensions() const;
public:
virtual PT(PandaNode) load_file(const Filename &path, bool report_errors) const;
public:

View File

@ -46,124 +46,6 @@ LoaderFileTypeRegistry::
~LoaderFileTypeRegistry() {
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_ptr
// Access: Public, Static
// Description: Returns a pointer to the global LoaderFileTypeRegistry
// object.
////////////////////////////////////////////////////////////////////
LoaderFileTypeRegistry *LoaderFileTypeRegistry::
get_ptr() {
if (_global_ptr == (LoaderFileTypeRegistry *)NULL) {
_global_ptr = new LoaderFileTypeRegistry;
}
return _global_ptr;
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_num_types
// Access: Public
// Description: Returns the total number of types registered.
////////////////////////////////////////////////////////////////////
int LoaderFileTypeRegistry::
get_num_types() const {
return _types.size();
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_type
// Access: Public
// Description: Returns the nth type registered.
////////////////////////////////////////////////////////////////////
LoaderFileType *LoaderFileTypeRegistry::
get_type(int n) const {
nassertr(n >= 0 && n < (int)_types.size(), NULL);
return _types[n];
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_type_from_extension
// Access: Public
// Description: Determines the type of the file based on the indicated
// extension (without a leading dot). Returns NULL if
// the extension matches no known file types.
////////////////////////////////////////////////////////////////////
LoaderFileType *LoaderFileTypeRegistry::
get_type_from_extension(const string &extension) {
string dcextension = downcase(extension);
Extensions::const_iterator ei;
ei = _extensions.find(dcextension);
if (ei == _extensions.end()) {
// Nothing matches that extension. Do we have a deferred type?
DeferredTypes::iterator di;
di = _deferred_types.find(dcextension);
if (di != _deferred_types.end()) {
// We do! Try to load the deferred library on-the-fly. Note
// that this is a race condition if we support threaded loading;
// this whole function needs to be protected from multiple
// entry.
string name = (*di).second;
Filename dlname = Filename::dso_filename("lib" + name + ".so");
_deferred_types.erase(di);
loader_cat->info()
<< "loading file type module: " << name << endl;
void *tmp = load_dso(dlname);
if (tmp == (void *)NULL) {
loader_cat->warning()
<< "Unable to load " << dlname.to_os_specific() << ": "
<< load_dso_error() << endl;
return NULL;
}
// Now try again to find the LoaderFileType.
ei = _extensions.find(dcextension);
}
}
if (ei == _extensions.end()) {
// Nothing matches that extension, even after we've checked for a
// deferred type description.
return NULL;
}
return (*ei).second;
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::write_types
// Access: Public
// Description: Writes a list of supported file types to the
// indicated output stream, one per line.
////////////////////////////////////////////////////////////////////
void LoaderFileTypeRegistry::
write_types(ostream &out, int indent_level) const {
if (_types.empty()) {
indent(out, indent_level) << "(No file types are known).\n";
} else {
Types::const_iterator ti;
for (ti = _types.begin(); ti != _types.end(); ++ti) {
LoaderFileType *type = (*ti);
string name = type->get_name();
indent(out, indent_level) << name;
indent(out, max(30 - (int)name.length(), 0))
<< " ." << type->get_extension() << "\n";
}
}
if (!_deferred_types.empty()) {
indent(out, indent_level) << "Also available:";
DeferredTypes::const_iterator di;
for (di = _deferred_types.begin(); di != _deferred_types.end(); ++di) {
const string &extension = (*di).first;
out << " ." << extension;
}
out << "\n";
}
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::register_type
// Access: Public
@ -234,6 +116,124 @@ register_deferred_type(const string &extension, const string &library) {
_deferred_types[dcextension] = library;
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_num_types
// Access: Published
// Description: Returns the total number of types registered.
////////////////////////////////////////////////////////////////////
int LoaderFileTypeRegistry::
get_num_types() const {
return _types.size();
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_type
// Access: Published
// Description: Returns the nth type registered.
////////////////////////////////////////////////////////////////////
LoaderFileType *LoaderFileTypeRegistry::
get_type(int n) const {
nassertr(n >= 0 && n < (int)_types.size(), NULL);
return _types[n];
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_type_from_extension
// Access: Published
// Description: Determines the type of the file based on the indicated
// extension (without a leading dot). Returns NULL if
// the extension matches no known file types.
////////////////////////////////////////////////////////////////////
LoaderFileType *LoaderFileTypeRegistry::
get_type_from_extension(const string &extension) {
string dcextension = downcase(extension);
Extensions::const_iterator ei;
ei = _extensions.find(dcextension);
if (ei == _extensions.end()) {
// Nothing matches that extension. Do we have a deferred type?
DeferredTypes::iterator di;
di = _deferred_types.find(dcextension);
if (di != _deferred_types.end()) {
// We do! Try to load the deferred library on-the-fly. Note
// that this is a race condition if we support threaded loading;
// this whole function needs to be protected from multiple
// entry.
string name = (*di).second;
Filename dlname = Filename::dso_filename("lib" + name + ".so");
_deferred_types.erase(di);
loader_cat->info()
<< "loading file type module: " << name << endl;
void *tmp = load_dso(dlname);
if (tmp == (void *)NULL) {
loader_cat->warning()
<< "Unable to load " << dlname.to_os_specific() << ": "
<< load_dso_error() << endl;
return NULL;
}
// Now try again to find the LoaderFileType.
ei = _extensions.find(dcextension);
}
}
if (ei == _extensions.end()) {
// Nothing matches that extension, even after we've checked for a
// deferred type description.
return NULL;
}
return (*ei).second;
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::write
// Access: Published
// Description: Writes a list of supported file types to the
// indicated output stream, one per line.
////////////////////////////////////////////////////////////////////
void LoaderFileTypeRegistry::
write(ostream &out, int indent_level) const {
if (_types.empty()) {
indent(out, indent_level) << "(No file types are known).\n";
} else {
Types::const_iterator ti;
for (ti = _types.begin(); ti != _types.end(); ++ti) {
LoaderFileType *type = (*ti);
string name = type->get_name();
indent(out, indent_level) << name;
indent(out, max(30 - (int)name.length(), 0))
<< " ." << type->get_extension() << "\n";
}
}
if (!_deferred_types.empty()) {
indent(out, indent_level) << "Also available:";
DeferredTypes::const_iterator di;
for (di = _deferred_types.begin(); di != _deferred_types.end(); ++di) {
const string &extension = (*di).first;
out << " ." << extension;
}
out << "\n";
}
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::get_global_ptr
// Access: Published, Static
// Description: Returns a pointer to the global LoaderFileTypeRegistry
// object.
////////////////////////////////////////////////////////////////////
LoaderFileTypeRegistry *LoaderFileTypeRegistry::
get_global_ptr() {
if (_global_ptr == (LoaderFileTypeRegistry *)NULL) {
_global_ptr = new LoaderFileTypeRegistry;
}
return _global_ptr;
}
////////////////////////////////////////////////////////////////////
// Function: LoaderFileTypeRegistry::record_extension
// Access: Private

View File

@ -39,18 +39,18 @@ protected:
public:
~LoaderFileTypeRegistry();
static LoaderFileTypeRegistry *get_ptr();
int get_num_types() const;
LoaderFileType *get_type(int n) const;
LoaderFileType *get_type_from_extension(const string &extension);
void write_types(ostream &out, int indent_level = 0) const;
void register_type(LoaderFileType *type);
void register_deferred_type(const string &extension, const string &library);
PUBLISHED:
int get_num_types() const;
LoaderFileType *get_type(int n) const;
LoaderFileType *get_type_from_extension(const string &extension);
void write(ostream &out, int indent_level = 0) const;
static LoaderFileTypeRegistry *get_global_ptr();
private:
void record_extension(const string &extension, LoaderFileType *type);

View File

@ -46,7 +46,7 @@ PNMFileType::
////////////////////////////////////////////////////////////////////
// Function: PNMFileType::get_num_extensions
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Returns the number of different possible filename
// extensions associated with this particular file type.
////////////////////////////////////////////////////////////////////
@ -57,7 +57,7 @@ get_num_extensions() const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileType::get_extension
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Returns the nth possible filename extension
// associated with this particular file type, without a
// leading dot.
@ -70,7 +70,7 @@ get_extension(int) const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileType::get_suggested_extension
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Returns a suitable filename extension (without a
// leading dot) to suggest for files of this type, or
// empty string if no suggestions are available.

View File

@ -43,12 +43,14 @@ protected:
public:
virtual ~PNMFileType();
PUBLISHED:
virtual string get_name() const=0;
virtual int get_num_extensions() const;
virtual string get_extension(int n) const;
virtual string get_suggested_extension() const;
public:
virtual bool has_magic_number() const;
virtual bool matches_magic_number(const string &magic_number) const;

View File

@ -48,22 +48,49 @@ PNMFileTypeRegistry::
}
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_ptr
// Access: Public, Static
// Description: Returns a pointer to the global PNMFileTypeRegistry
// object.
// Function: PNMFileTypeRegistry::register_type
// Access: Public
// Description: Defines a new PNMFileType in the universe.
////////////////////////////////////////////////////////////////////
PNMFileTypeRegistry *PNMFileTypeRegistry::
get_ptr() {
if (_global_ptr == (PNMFileTypeRegistry *)NULL) {
_global_ptr = new PNMFileTypeRegistry;
void PNMFileTypeRegistry::
register_type(PNMFileType *type) {
// Make sure we haven't already registered this type.
Handles::iterator hi = _handles.find(type->get_type());
if (hi != _handles.end()) {
pnmimage_cat.warning()
<< "Attempt to register PNMFileType " << type->get_name()
<< " (" << type->get_type() << ") more than once.\n";
return;
}
return _global_ptr;
_types.push_back(type);
_handles.insert(Handles::value_type(type->get_type(), type));
// Collect the unique extensions associated with the type.
pset<string> unique_extensions;
int num_extensions = type->get_num_extensions();
for (int i = 0; i < num_extensions; i++) {
string extension = downcase(type->get_extension(i));
if (!unique_extensions.insert(extension).second) {
pnmimage_cat.warning()
<< "PNMFileType " << type->get_name()
<< " (" << type->get_type() << ") defined extension "
<< extension << " more than once.\n";
}
}
pset<string>::iterator ui;
for (ui = unique_extensions.begin(); ui != unique_extensions.end(); ++ui) {
_extensions[*ui].push_back(type);
}
_requires_sort = true;
}
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_num_types
// Access: Public
// Access: Published
// Description: Returns the total number of types registered.
////////////////////////////////////////////////////////////////////
int PNMFileTypeRegistry::
@ -76,7 +103,7 @@ get_num_types() const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_type
// Access: Public
// Access: Published
// Description: Returns the nth type registered.
////////////////////////////////////////////////////////////////////
PNMFileType *PNMFileTypeRegistry::
@ -87,7 +114,7 @@ get_type(int n) const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_type_from_extension
// Access: Public
// Access: Published
// Description: Tries to determine what the PNMFileType is likely to
// be for a particular image file based on its
// extension. Returns a suitable PNMFileType pointer,
@ -132,7 +159,7 @@ get_type_from_extension(const string &filename) const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_type_from_magic_number
// Access: Public
// Access: Published
// Description: Tries to determine what the PNMFileType is likely to
// be for a particular image file based on its
// magic number, the first two bytes read from the
@ -159,7 +186,7 @@ get_type_from_magic_number(const string &magic_number) const {
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::get_type_by_handle
// Access: Public
// Access: Published
// Description: Returns the PNMFileType instance stored in the
// registry for the given TypeHandle, e.g. as retrieved
// by a previous call to get_type() on the type
@ -177,13 +204,13 @@ get_type_by_handle(TypeHandle handle) const {
}
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::write_types
// Access: Public
// Function: PNMFileTypeRegistry::write
// Access: Published
// Description: Writes a list of supported image file types to the
// indicated output stream, one per line.
////////////////////////////////////////////////////////////////////
void PNMFileTypeRegistry::
write_types(ostream &out, int indent_level) const {
write(ostream &out, int indent_level) const {
if (_types.empty()) {
indent(out, indent_level) << "(No image types are known).\n";
} else {
@ -209,44 +236,17 @@ write_types(ostream &out, int indent_level) const {
}
////////////////////////////////////////////////////////////////////
// Function: PNMFileTypeRegistry::register_type
// Access: Public
// Description: Defines a new PNMFileType in the universe.
// Function: PNMFileTypeRegistry::get_global_ptr
// Access: Published, Static
// Description: Returns a pointer to the global PNMFileTypeRegistry
// object.
////////////////////////////////////////////////////////////////////
void PNMFileTypeRegistry::
register_type(PNMFileType *type) {
// Make sure we haven't already registered this type.
Handles::iterator hi = _handles.find(type->get_type());
if (hi != _handles.end()) {
pnmimage_cat.warning()
<< "Attempt to register PNMFileType " << type->get_name()
<< " (" << type->get_type() << ") more than once.\n";
return;
PNMFileTypeRegistry *PNMFileTypeRegistry::
get_global_ptr() {
if (_global_ptr == (PNMFileTypeRegistry *)NULL) {
_global_ptr = new PNMFileTypeRegistry;
}
_types.push_back(type);
_handles.insert(Handles::value_type(type->get_type(), type));
// Collect the unique extensions associated with the type.
pset<string> unique_extensions;
int num_extensions = type->get_num_extensions();
for (int i = 0; i < num_extensions; i++) {
string extension = downcase(type->get_extension(i));
if (!unique_extensions.insert(extension).second) {
pnmimage_cat.warning()
<< "PNMFileType " << type->get_name()
<< " (" << type->get_type() << ") defined extension "
<< extension << " more than once.\n";
}
}
pset<string>::iterator ui;
for (ui = unique_extensions.begin(); ui != unique_extensions.end(); ++ui) {
_extensions[*ui].push_back(type);
}
_requires_sort = true;
return _global_ptr;
}
////////////////////////////////////////////////////////////////////

View File

@ -37,8 +37,9 @@ protected:
public:
~PNMFileTypeRegistry();
static PNMFileTypeRegistry *get_ptr();
void register_type(PNMFileType *type);
PUBLISHED:
int get_num_types() const;
PNMFileType *get_type(int n) const;
@ -46,9 +47,9 @@ public:
PNMFileType *get_type_from_magic_number(const string &magic_number) const;
PNMFileType *get_type_by_handle(TypeHandle handle) const;
void write_types(ostream &out, int indent_level = 0) const;
void write(ostream &out, int indent_level = 0) const;
void register_type(PNMFileType *type);
static PNMFileTypeRegistry *get_global_ptr();
private:
void sort_preferences();

View File

@ -144,7 +144,7 @@ make_reader(istream *file, bool owns_file, const Filename &filename,
return NULL;
}
type = PNMFileTypeRegistry::get_ptr()->
type = PNMFileTypeRegistry::get_global_ptr()->
get_type_from_magic_number(magic_number);
if (pnmimage_cat.is_debug()) {
@ -162,7 +162,7 @@ make_reader(istream *file, bool owns_file, const Filename &filename,
if (type == (PNMFileType *)NULL && !filename.empty()) {
// We still don't know the type; attempt to guess it from the
// filename extension.
type = PNMFileTypeRegistry::get_ptr()->get_type_from_extension(filename);
type = PNMFileTypeRegistry::get_global_ptr()->get_type_from_extension(filename);
if (pnmimage_cat.is_debug()) {
if (type != (PNMFileType *)NULL) {
@ -192,8 +192,8 @@ make_reader(istream *file, bool owns_file, const Filename &filename,
pnmimage_cat.error()
<< "Cannot determine type of image file " << filename << ".\n"
<< "Currently supported image types:\n";
PNMFileTypeRegistry::get_ptr()->
write_types(pnmimage_cat.error(false), 2);
PNMFileTypeRegistry::get_global_ptr()->
write(pnmimage_cat.error(false), 2);
}
if (owns_file) {
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
@ -306,7 +306,7 @@ make_writer(ostream *file, bool owns_file, const Filename &filename,
if (type == (PNMFileType *)NULL && !filename.empty()) {
// We don't know the type; attempt to guess it from the filename
// extension.
type = PNMFileTypeRegistry::get_ptr()->get_type_from_extension(filename);
type = PNMFileTypeRegistry::get_global_ptr()->get_type_from_extension(filename);
if (pnmimage_cat.is_debug()) {
if (type != (PNMFileType *)NULL) {

View File

@ -32,6 +32,7 @@
#include "pnmFileTypeRegistry.h"
#include "string_utils.h"
#include "dconfig.h"
#include "pandaSystem.h"
Configure(config_pnmimagetypes);
NotifyCategoryDefName(pnmimage_sgi, "sgi", pnmimage_cat);
@ -209,7 +210,7 @@ init_libpnmimagetypes() {
#endif
// Register each type with the PNMFileTypeRegistry.
PNMFileTypeRegistry *tr = PNMFileTypeRegistry::get_ptr();
PNMFileTypeRegistry *tr = PNMFileTypeRegistry::get_global_ptr();
tr->register_type(new PNMFileTypeSGI);
tr->register_type(new PNMFileTypeAlias);
@ -243,4 +244,17 @@ init_libpnmimagetypes() {
#ifdef HAVE_TIFF
PNMFileTypeTIFF::register_with_read_factory();
#endif
// And register with the PandaSystem.
PandaSystem *ps = PandaSystem::get_global_ptr();
#ifdef HAVE_JPEG
ps->add_system("libjpeg");
#endif
#ifdef HAVE_PNG
ps->add_system("libpng");
#endif
#ifdef HAVE_TIFF
ps->add_system("libtiff");
#endif
}

View File

@ -416,5 +416,5 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeAlias::
make_PNMFileTypeAlias(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}

View File

@ -161,5 +161,5 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeBMP::
make_PNMFileTypeBMP(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}

View File

@ -375,5 +375,5 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeIMG::
make_PNMFileTypeIMG(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}

View File

@ -165,7 +165,7 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeJPG::
make_PNMFileTypeJPG(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}
#endif // HAVE_JPEG

View File

@ -183,7 +183,7 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypePNG::
make_PNMFileTypePNG(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}
////////////////////////////////////////////////////////////////////

View File

@ -165,5 +165,5 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeSGI::
make_PNMFileTypeSGI(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}

View File

@ -789,5 +789,5 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeSoftImage::
make_PNMFileTypeSoftImage(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}

View File

@ -593,7 +593,7 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeTGA::
make_PNMFileTypeTGA(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}
void PNMFileTypeTGA::Reader::

View File

@ -1091,7 +1091,7 @@ register_with_read_factory() {
////////////////////////////////////////////////////////////////////
TypedWritable *PNMFileTypeTIFF::
make_PNMFileTypeTIFF(const FactoryParams &params) {
return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
}
#endif // HAVE_TIFF

View File

@ -25,6 +25,7 @@
#include "dynamicTextPage.h"
#include "geomTextGlyph.h"
#include "unicodeLatinMap.h"
#include "pandaSystem.h"
#include "dconfig.h"
#include "config_express.h"
@ -167,5 +168,8 @@ init_libtext() {
DynamicTextPage::init_type();
GeomTextGlyph::init_type();
GeomTextGlyph::register_with_read_factory();
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("Freetype");
#endif
}

View File

@ -23,6 +23,7 @@
#include "wglGraphicsWindow.h"
#include "graphicsPipeSelection.h"
#include "dconfig.h"
#include "pandaSystem.h"
Configure(config_wgldisplay);
NotifyCategoryDef(wgldisplay, "windisplay");
@ -70,4 +71,7 @@ init_libwgldisplay() {
GraphicsPipeSelection *selection = GraphicsPipeSelection::get_global_ptr();
selection->add_pipe_type(wglGraphicsPipe::get_class_type(),
wglGraphicsPipe::pipe_constructor);
PandaSystem *ps = PandaSystem::get_global_ptr();
ps->set_system_tag("OpenGL", "window_system", "WGL");
}

View File

@ -50,7 +50,7 @@ init_libmayaloader() {
LoaderFileTypePandatool::init_type();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
init_libmayaegg();
MayaToEggConverter *maya = new MayaToEggConverter;

View File

@ -55,7 +55,7 @@ extract_param_value(const string &str, string &param, string &value) {
bool
parse_image_type_request(const string &word, PNMFileType *&color_type,
PNMFileType *&alpha_type) {
PNMFileTypeRegistry *registry = PNMFileTypeRegistry::get_ptr();
PNMFileTypeRegistry *registry = PNMFileTypeRegistry::get_global_ptr();
color_type = (PNMFileType *)NULL;
alpha_type = (PNMFileType *)NULL;

View File

@ -112,7 +112,7 @@ Palettizer() {
_coverage_threshold = 2.5;
_aggressively_clean_mapdir = true;
_force_power_2 = true;
_color_type = PNMFileTypeRegistry::get_ptr()->get_type_from_extension("rgb");
_color_type = PNMFileTypeRegistry::get_global_ptr()->get_type_from_extension("rgb");
_alpha_type = (PNMFileType *)NULL;
_shadow_color_type = (PNMFileType *)NULL;
_shadow_alpha_type = (PNMFileType *)NULL;

View File

@ -413,7 +413,7 @@ parse_imagetype_line(const vector_string &words) {
const string &imagetype = words[1];
if (!parse_image_type_request(imagetype, pal->_color_type, pal->_alpha_type)) {
nout << "\nKnown image types are:\n";
PNMFileTypeRegistry::get_ptr()->write_types(nout, 2);
PNMFileTypeRegistry::get_global_ptr()->write(nout, 2);
nout << "\n";
return false;
}
@ -439,7 +439,7 @@ parse_shadowtype_line(const vector_string &words) {
if (!parse_image_type_request(shadowtype, pal->_shadow_color_type,
pal->_shadow_alpha_type)) {
nout << "\nKnown image types are:\n";
PNMFileTypeRegistry::get_ptr()->write_types(nout, 2);
PNMFileTypeRegistry::get_global_ptr()->write(nout, 2);
nout << "\n";
return false;
}

View File

@ -1168,14 +1168,14 @@ bool ProgramBase::
dispatch_image_type(const string &opt, const string &arg, void *var) {
PNMFileType **ip = (PNMFileType **)var;
PNMFileTypeRegistry *reg = PNMFileTypeRegistry::get_ptr();
PNMFileTypeRegistry *reg = PNMFileTypeRegistry::get_global_ptr();
(*ip) = reg->get_type_from_extension(arg);
if ((*ip) == (PNMFileType *)NULL) {
nout << "Invalid image type for -" << opt << ": " << arg << "\n"
<< "The following image types are known:\n";
reg->write_types(nout, 2);
reg->write(nout, 2);
return false;
}

View File

@ -68,7 +68,7 @@ init_libptloader() {
LoaderFileTypePandatool::init_type();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr();
LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr();
init_liblwo();
FltToEggConverter *flt = new FltToEggConverter;