Browse Source

have to limit p3d_plugin to C API, which means no default arguments allowed

David Rose 16 years ago
parent
commit
ff93698ce6

+ 14 - 0
direct/src/plugin/p3dInstanceManager.I

@@ -51,6 +51,20 @@ reset_verify_contents() {
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DInstanceManager::get_api_version
+//       Access: Public
+//  Description: Returns the api_version number which was passed to
+//               P3D_initialize().  Client code may use this to
+//               determine how to interpret parameters to various
+//               functions whose interface may have changed over
+//               different versions.
+////////////////////////////////////////////////////////////////////
+inline int P3DInstanceManager::
+get_api_version() const {
+  return _api_version;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DInstanceManager::get_host_url
 //       Access: Public

+ 4 - 2
direct/src/plugin/p3dInstanceManager.cxx

@@ -58,6 +58,7 @@ P3DInstanceManager() {
   init_xml();
 
   _is_initialized = false;
+  _api_version = 0;
   _next_temp_filename_counter = 1;
   _unique_id = 0;
   _trusted_environment = false;
@@ -180,11 +181,12 @@ P3DInstanceManager::
 //               redownloaded.
 ////////////////////////////////////////////////////////////////////
 bool P3DInstanceManager::
-initialize(const string &contents_filename, const string &host_url,
-           bool verify_contents,
+initialize(int api_version, const string &contents_filename, 
+           const string &host_url, bool verify_contents,
            const string &platform, const string &log_directory,
            const string &log_basename, bool trusted_environment,
            bool console_environment) {
+  _api_version = api_version;
   _trusted_environment = trusted_environment;
   _console_environment = console_environment;
   _verify_contents = verify_contents;

+ 3 - 1
direct/src/plugin/p3dInstanceManager.h

@@ -50,7 +50,7 @@ private:
   ~P3DInstanceManager();
 
 public:
-  bool initialize(const string &contents_filename,
+  bool initialize(int api_version, const string &contents_filename,
                   const string &host_url,
                   bool verify_contents,
                   const string &platform,
@@ -63,6 +63,7 @@ public:
   inline bool get_verify_contents() const;
   inline void reset_verify_contents();
 
+  inline int get_api_version() const;
   inline const string &get_host_url() const;
   inline const string &get_root_dir() const;
   inline const string &get_platform() const;
@@ -148,6 +149,7 @@ private:
 
 private:
   bool _is_initialized;
+  int _api_version;
   string _host_url;
   string _root_dir;
   string _certs_dir;

+ 9 - 3
direct/src/plugin/p3d_plugin.cxx

@@ -39,7 +39,7 @@ P3D_initialize(int api_version, const char *contents_filename,
                const char *platform,
                const char *log_directory, const char *log_basename,
                bool trusted_environment, bool console_environment) {
-  if (api_version != P3D_API_VERSION) {
+  if (api_version < 10 || api_version > P3D_API_VERSION) {
     // Can't accept an incompatible version.
     return false;
   }
@@ -71,7 +71,7 @@ P3D_initialize(int api_version, const char *contents_filename,
   }
 
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
-  bool result = inst_mgr->initialize(contents_filename, host_url,
+  bool result = inst_mgr->initialize(api_version, contents_filename, host_url,
                                      verify_contents, platform,
                                      log_directory, log_basename,
                                      trusted_environment, console_environment);
@@ -132,13 +132,19 @@ P3D_new_instance(P3D_request_ready_func *func,
 
 bool
 P3D_instance_start(P3D_instance *instance, bool is_local, 
-                   const char *p3d_filename, const int p3d_offset) {
+                   const char *p3d_filename, int p3d_offset) {
   assert(P3DInstanceManager::get_global_ptr()->is_initialized());
   if (p3d_filename == NULL) {
     p3d_filename = "";
   }
   ACQUIRE_LOCK(_api_lock);
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
+  if (inst_mgr->get_api_version() < 11) {
+    // Prior to version 11, there was no p3d_offset parameter.  So, we
+    // default it to 0.
+    p3d_offset = 0;
+  }
+
   P3DInstance *inst = inst_mgr->validate_instance(instance);
   bool result = false;
   if (inst != NULL) {

+ 7 - 2
direct/src/plugin/p3d_plugin.h

@@ -79,7 +79,7 @@ extern "C" {
    (below). This number will be incremented whenever there are changes
    to any of the interface specifications defined in this header
    file. */
-#define P3D_API_VERSION 10
+#define P3D_API_VERSION 11
 
 /************************ GLOBAL FUNCTIONS **************************/
 
@@ -339,10 +339,15 @@ P3D_new_instance_func(P3D_request_ready_func *func,
    should be downloaded to retrieve the p3d file.  Also see
    P3D_instance_start_stream(), below.
 
+   p3d_offset is the offset within p3d_filename at which the p3d data
+   actually begins.  It is normally 0 for an ordinary p3d file, but it
+   may be nonzero to indicate a p3d file embedded within another file
+   (such as is created by pdeploy).
+
    The return value is true on success, false on failure. */
 typedef bool
 P3D_instance_start_func(P3D_instance *instance, bool is_local,
-                        const char *p3d_filename, const int p3d_offset = 0);
+                        const char *p3d_filename, int p3d_offset);
 
 /* This function is an alternative to P3D_instance_start(); it
    indicates an intention to feed the p3d file data to the instance as

+ 1 - 1
direct/src/plugin_activex/PPInstance.cpp

@@ -536,7 +536,7 @@ int PPInstance::Start( const std::string& p3dFilename  )
 
     nout << "Starting new P3D instance " << p3dFilename << "\n";
 
-    if ( !P3D_instance_start( m_p3dInstance, false, p3dFilename.c_str() ) )
+    if ( !P3D_instance_start( m_p3dInstance, false, p3dFilename.c_str(), 0 ) )
     {
         nout << "Error starting P3D instance: " << GetLastError() << "\n";
         return 1;