From c49b34ba442768bbb366d840427001d9137f6967 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 26 Jan 2001 19:38:49 +0000 Subject: [PATCH] *** empty log message *** --- panda/metalibs/panda/panda.cxx | 8 ++- panda/src/display/Sources.pp | 1 + panda/src/display/config_display.cxx | 77 +++++++++++++++---------- panda/src/display/config_display.h | 2 + panda/src/pstatclient/config_pstats.cxx | 19 ++++++ panda/src/pstatclient/config_pstats.h | 2 + panda/src/putil/buttonRegistry.I | 24 ++++---- panda/src/putil/buttonRegistry.cxx | 37 ++++++++---- panda/src/putil/buttonRegistry.h | 16 ++--- panda/src/putil/keyboardButton.cxx | 2 +- 10 files changed, 126 insertions(+), 62 deletions(-) diff --git a/panda/metalibs/panda/panda.cxx b/panda/metalibs/panda/panda.cxx index d028eff062..5016af4927 100644 --- a/panda/metalibs/panda/panda.cxx +++ b/panda/metalibs/panda/panda.cxx @@ -6,9 +6,11 @@ #include "panda.h" #include +#include #include -#include #include +#include +#include //////////////////////////////////////////////////////////////////// // Function: init_libpanda @@ -21,7 +23,9 @@ void init_libpanda() { init_libdevice(); + init_libdisplay(); init_libgraph(); - init_libsgraph(); init_libpnmimagetypes(); + init_libpstatclient(); + init_libsgraph(); } diff --git a/panda/src/display/Sources.pp b/panda/src/display/Sources.pp index 83fcdb57d1..2f9f29cd7b 100644 --- a/panda/src/display/Sources.pp +++ b/panda/src/display/Sources.pp @@ -25,6 +25,7 @@ textureContext.cxx textureContext.h #define INSTALL_HEADERS \ + config_display.h \ displayRegion.I displayRegion.h displayRegionStack.I \ displayRegionStack.h frameBufferStack.I frameBufferStack.h \ graphicsChannel.I graphicsChannel.h graphicsLayer.I graphicsLayer.h \ diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index 48d33b4efa..bb93a59b50 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -25,35 +25,7 @@ static Config::ConfigTable::Symbol *preferred_window; static Config::ConfigTable::Symbol *preferred_gsg; ConfigureFn(config_display) { - GraphicsStateGuardian::init_type(); - GraphicsStateGuardian::GsgParam::init_type(); - GraphicsStateGuardian::GsgWindow::init_type(); - SavedFrameBuffer::init_type(); - GraphicsPipe::init_type(); - GraphicsPipe::PipeParam::init_type(); - GraphicsPipe::PipeSpec::init_type(); - InteractiveGraphicsPipe::init_type(); - NoninteractiveGraphicsPipe::init_type(); - GraphicsWindow::init_type(); - GraphicsWindow::WindowParam::init_type(); - GraphicsWindow::WindowProps::init_type(); - GraphicsWindow::WindowPipe::init_type(); - GraphicsChannel::init_type(); - HardwareChannel::init_type(); - TextureContext::init_type(); - - disp = new Config::ConfigTable::Symbol; - guard = new Config::ConfigTable::Symbol; - preferred_pipe = new Config::ConfigTable::Symbol; - preferred_window = new Config::ConfigTable::Symbol; - preferred_gsg = new Config::ConfigTable::Symbol; - - config_display.GetAll("load-display", *disp); - config_display.GetAll("load-gsg", *guard); - - config_display.GetAll("preferred-pipe", *preferred_pipe); - config_display.GetAll("preferred-window", *preferred_window); - config_display.GetAll("preferred-gsg", *preferred_gsg); + init_libdisplay(); } const string pipe_spec_machine = config_display.GetString("pipe-machine", ""); @@ -111,3 +83,50 @@ Config::ConfigTable::Symbol::iterator preferred_gsg_begin(void) { Config::ConfigTable::Symbol::iterator preferred_gsg_end(void) { return preferred_gsg->end(); } + +//////////////////////////////////////////////////////////////////// +// Function: init_libdisplay +// Description: Initializes the library. This must be called at +// least once before any of the functions or classes in +// this library can be used. Normally it will be +// called by the static initializers and need not be +// called explicitly, but special cases exist. +//////////////////////////////////////////////////////////////////// +void +init_libdisplay() { + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; + + GraphicsStateGuardian::init_type(); + GraphicsStateGuardian::GsgParam::init_type(); + GraphicsStateGuardian::GsgWindow::init_type(); + SavedFrameBuffer::init_type(); + GraphicsPipe::init_type(); + GraphicsPipe::PipeParam::init_type(); + GraphicsPipe::PipeSpec::init_type(); + InteractiveGraphicsPipe::init_type(); + NoninteractiveGraphicsPipe::init_type(); + GraphicsWindow::init_type(); + GraphicsWindow::WindowParam::init_type(); + GraphicsWindow::WindowProps::init_type(); + GraphicsWindow::WindowPipe::init_type(); + GraphicsChannel::init_type(); + HardwareChannel::init_type(); + TextureContext::init_type(); + + disp = new Config::ConfigTable::Symbol; + guard = new Config::ConfigTable::Symbol; + preferred_pipe = new Config::ConfigTable::Symbol; + preferred_window = new Config::ConfigTable::Symbol; + preferred_gsg = new Config::ConfigTable::Symbol; + + config_display.GetAll("load-display", *disp); + config_display.GetAll("load-gsg", *guard); + + config_display.GetAll("preferred-pipe", *preferred_pipe); + config_display.GetAll("preferred-window", *preferred_window); + config_display.GetAll("preferred-gsg", *preferred_gsg); +} diff --git a/panda/src/display/config_display.h b/panda/src/display/config_display.h index 211222522d..3d9056f103 100644 --- a/panda/src/display/config_display.h +++ b/panda/src/display/config_display.h @@ -38,4 +38,6 @@ extern Config::ConfigTable::Symbol::iterator preferred_window_end(); extern Config::ConfigTable::Symbol::iterator preferred_gsg_begin(); extern Config::ConfigTable::Symbol::iterator preferred_gsg_end(); +extern EXPCL_PANDA void init_libdisplay(); + #endif /* CONFIG_DISPLAY_H */ diff --git a/panda/src/pstatclient/config_pstats.cxx b/panda/src/pstatclient/config_pstats.cxx index 4d4d73606c..28fc501e70 100644 --- a/panda/src/pstatclient/config_pstats.cxx +++ b/panda/src/pstatclient/config_pstats.cxx @@ -11,6 +11,7 @@ Configure(config_pstats); NotifyCategoryDef(pstats, ""); ConfigureFn(config_pstats) { + init_libpstatclient(); } string get_pstats_name() { @@ -29,3 +30,21 @@ const double pstats_target_frame_rate = config_pstats.GetDouble("pstats-target-f // not the client. const bool pstats_scroll_mode = config_pstats.GetBool("pstats-scroll-mode", true); const double pstats_history = config_pstats.GetDouble("pstats-history", 30.0); + +//////////////////////////////////////////////////////////////////// +// Function: init_libpstatclient +// Description: Initializes the library. This must be called at +// least once before any of the functions or classes in +// this library can be used. Normally it will be +// called by the static initializers and need not be +// called explicitly, but special cases exist. +//////////////////////////////////////////////////////////////////// +void +init_libpstatclient() { + static bool initialized = false; + if (initialized) { + return; + } + initialized = true; +} + diff --git a/panda/src/pstatclient/config_pstats.h b/panda/src/pstatclient/config_pstats.h index 79c4c51d2d..e6e01919a1 100644 --- a/panda/src/pstatclient/config_pstats.h +++ b/panda/src/pstatclient/config_pstats.h @@ -23,4 +23,6 @@ extern EXPCL_PANDA const double pstats_target_frame_rate; extern EXPCL_PANDA const bool pstats_scroll_mode; extern EXPCL_PANDA const double pstats_history; +extern EXPCL_PANDA void init_libpstatclient(); + #endif diff --git a/panda/src/putil/buttonRegistry.I b/panda/src/putil/buttonRegistry.I index cead64476e..1ff6b16a1f 100644 --- a/panda/src/putil/buttonRegistry.I +++ b/panda/src/putil/buttonRegistry.I @@ -15,18 +15,6 @@ RegistryNode(ButtonHandle handle, const string &name) : _handle(handle), _name(name) { } -//////////////////////////////////////////////////////////////////// -// Function: ButtonRegistry::get_name -// Access: Public -// Description: Returns the name of the indicated button. -//////////////////////////////////////////////////////////////////// -INLINE string ButtonRegistry:: -get_name(ButtonHandle button) const { - RegistryNode *rnode = look_up(button); - nassertr(rnode != (RegistryNode *)NULL, ""); - return rnode->_name; -} - //////////////////////////////////////////////////////////////////// // Function: ButtonRegistry::ptr // Access: Public, Static @@ -40,3 +28,15 @@ ptr() { } return _global_pointer; } + +//////////////////////////////////////////////////////////////////// +// Function: ButtonRegistry::get_name +// Access: Public +// Description: Returns the name of the indicated button. +//////////////////////////////////////////////////////////////////// +INLINE string ButtonRegistry:: +get_name(ButtonHandle button) const { + RegistryNode *rnode = look_up(button); + nassertr(rnode != (RegistryNode *)NULL, ""); + return rnode->_name; +} diff --git a/panda/src/putil/buttonRegistry.cxx b/panda/src/putil/buttonRegistry.cxx index ddb29e1faa..c93643be16 100644 --- a/panda/src/putil/buttonRegistry.cxx +++ b/panda/src/putil/buttonRegistry.cxx @@ -17,9 +17,17 @@ ButtonRegistry *ButtonRegistry::_global_pointer = NULL; //////////////////////////////////////////////////////////////////// -// Function: ButtonRegistry::register_type +// Function: ButtonRegistry::register_button // Access: Public -// Description: +// Description: Registers a new ButtonHandle with the indicated name, +// and if specified, the indicated ASCII equivalent. +// Returns true if the button was registered, or false +// it was already registered; in either case, the new +// ButtonHandle is loaded into the first parameter. +// +// This defines a new kind of button matching the +// indicated name. The ButtonHandle can then be passed +// around to devices as a button in its own right. //////////////////////////////////////////////////////////////////// bool ButtonRegistry:: register_button(ButtonHandle &button_handle, const string &name, @@ -82,28 +90,35 @@ register_button(ButtonHandle &button_handle, const string &name, } //////////////////////////////////////////////////////////////////// -// Function: ButtonRegistry::find_button +// Function: ButtonRegistry::get_button // Access: Public -// Description: +// Description: Finds a ButtonHandle in the registry matching the +// indicated name. If there is no such ButtonHandle, +// registers a new one and returns it. //////////////////////////////////////////////////////////////////// ButtonHandle ButtonRegistry:: -find_button(const string &name) const { +get_button(const string &name) { NameRegistry::const_iterator ri; ri = _name_registry.find(name); - if (ri == _name_registry.end()) { - return ButtonHandle::none(); - } else { + + if (ri != _name_registry.end()) { return (*ri).second->_handle; } + + ButtonHandle button; + register_button(button, name); + return button; } //////////////////////////////////////////////////////////////////// -// Function: ButtonRegistry::find_button +// Function: ButtonRegistry::find_ascii_button // Access: Public -// Description: +// Description: Finds a ButtonHandle in the registry matching the +// indicated ASCII equivalent character. If there is no +// such ButtonHandle, returns ButtonHandle::none(). //////////////////////////////////////////////////////////////////// ButtonHandle ButtonRegistry:: -find_button(char ascii_equivalent) const { +find_ascii_button(char ascii_equivalent) const { if (_handle_registry[ascii_equivalent] == (RegistryNode *)NULL) { return ButtonHandle::none(); } diff --git a/panda/src/putil/buttonRegistry.h b/panda/src/putil/buttonRegistry.h index 5e97a1b3ad..aa68c3295f 100644 --- a/panda/src/putil/buttonRegistry.h +++ b/panda/src/putil/buttonRegistry.h @@ -31,20 +31,22 @@ protected: string _name; }; -PUBLISHED: +public: bool register_button(ButtonHandle &button_handle, const string &name, char ascii_equivalent = '\0'); - ButtonHandle find_button(const string &name) const; - ButtonHandle find_button(char ascii_equivalent) const; - - INLINE string get_name(ButtonHandle button) const; - - void write(ostream &out) const; +PUBLISHED: + ButtonHandle get_button(const string &name); + ButtonHandle find_ascii_button(char ascii_equivalent) const; // ptr() returns the pointer to the global ButtonRegistry object. INLINE static ButtonRegistry *ptr(); +public: + INLINE string get_name(ButtonHandle button) const; + + void write(ostream &out) const; + private: // The ButtonRegistry class should never be constructed by user code. // There is only one in the universe, and it constructs itself! diff --git a/panda/src/putil/keyboardButton.cxx b/panda/src/putil/keyboardButton.cxx index 5bcd000567..0202c56453 100644 --- a/panda/src/putil/keyboardButton.cxx +++ b/panda/src/putil/keyboardButton.cxx @@ -55,7 +55,7 @@ static ButtonHandle _shift_lock; //////////////////////////////////////////////////////////////////// ButtonHandle KeyboardButton:: ascii_key(char ascii_equivalent) { - return ButtonRegistry::ptr()->find_button(ascii_equivalent); + return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent); } ////////////////////////////////////////////////////////////////////