add named make_pipe()

This commit is contained in:
David Rose 2007-08-08 20:49:23 +00:00
parent e44724fc4b
commit 62e24ff632
2 changed files with 62 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include "filename.h" #include "filename.h"
#include "load_dso.h" #include "load_dso.h"
#include "config_display.h" #include "config_display.h"
#include "typeRegistry.h"
#include "pset.h" #include "pset.h"
#include <algorithm> #include <algorithm>
@ -149,6 +150,52 @@ print_pipe_types() const {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: GraphicsPipeSelection::make_pipe
// Access: Published
// Description: Creates a new GraphicsPipe of the indicated type (or
// a type more specific than the indicated type, if
// necessary) and returns it. Returns NULL if the type
// cannot be matched.
//
// If the type is not already defined, this will
// implicitly load the named module, or if module_name
// is empty, it will call load_aux_modules().
////////////////////////////////////////////////////////////////////
PT(GraphicsPipe) GraphicsPipeSelection::
make_pipe(const string &type_name, const string &module_name) {
TypeRegistry *type_reg = TypeRegistry::ptr();
// First, see if the type is already available.
TypeHandle type = type_reg->find_type(type_name);
// If it isn't, try the named module.
if (type == TypeHandle::none()) {
if (!module_name.empty()) {
load_named_module(module_name);
type = type_reg->find_type(type_name);
}
}
// If that didn't help, try the default module.
if (type == TypeHandle::none()) {
load_default_module();
type = type_reg->find_type(type_name);
}
// Still not enough, try all modules.
if (type == TypeHandle::none()) {
load_aux_modules();
type = type_reg->find_type(type_name);
}
if (type == TypeHandle::none()) {
return NULL;
}
return make_pipe(type);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GraphicsPipeSelection::make_pipe // Function: GraphicsPipeSelection::make_pipe
// Access: Published // Access: Published
@ -159,8 +206,6 @@ print_pipe_types() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PT(GraphicsPipe) GraphicsPipeSelection:: PT(GraphicsPipe) GraphicsPipeSelection::
make_pipe(TypeHandle type) { make_pipe(TypeHandle type) {
load_default_module();
MutexHolder holder(_lock); MutexHolder holder(_lock);
PipeTypes::const_iterator ti; PipeTypes::const_iterator ti;
@ -188,6 +233,19 @@ make_pipe(TypeHandle type) {
} }
} }
// Couldn't find any match; load the default module and try again.
load_default_module();
for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
const PipeType &ptype = (*ti);
if (ptype._type.is_derived_from(type)) {
// Here's an approximate match.
PT(GraphicsPipe) pipe = (*ptype._constructor)();
if (pipe != (GraphicsPipe *)NULL) {
return pipe;
}
}
}
// Couldn't find a matching pipe type. // Couldn't find a matching pipe type.
return NULL; return NULL;
} }

View File

@ -47,6 +47,8 @@ PUBLISHED:
TypeHandle get_pipe_type(int n) const; TypeHandle get_pipe_type(int n) const;
void print_pipe_types() const; void print_pipe_types() const;
PT(GraphicsPipe) make_pipe(const string &type_name,
const string &module_name = string());
PT(GraphicsPipe) make_pipe(TypeHandle type); PT(GraphicsPipe) make_pipe(TypeHandle type);
PT(GraphicsPipe) make_default_pipe(); PT(GraphicsPipe) make_default_pipe();