Selaa lähdekoodia

add AppRunner.p3dFilename etc

David Rose 14 vuotta sitten
vanhempi
sitoutus
35551fed85

+ 11 - 1
direct/src/p3d/AppRunner.py

@@ -111,6 +111,8 @@ class AppRunner(DirectObject):
         self.packedAppEnvironmentInitialized = False
         self.packedAppEnvironmentInitialized = False
         self.gotWindow = False
         self.gotWindow = False
         self.gotP3DFilename = False
         self.gotP3DFilename = False
+        self.p3dFilename = None
+        self.p3dUrl = None
         self.started = False
         self.started = False
         self.windowOpened = False
         self.windowOpened = False
         self.windowPrc = None
         self.windowPrc = None
@@ -872,7 +874,7 @@ class AppRunner(DirectObject):
             initAppForGui()
             initAppForGui()
 
 
     def setP3DFilename(self, p3dFilename, tokens, argv, instanceId,
     def setP3DFilename(self, p3dFilename, tokens, argv, instanceId,
-                       interactiveConsole, p3dOffset = 0):
+                       interactiveConsole, p3dOffset, p3dUrl):
         """ Called by the browser to specify the p3d file that
         """ Called by the browser to specify the p3d file that
         contains the application itself, along with the web tokens
         contains the application itself, along with the web tokens
         and/or command-line arguments.  Once this method has been
         and/or command-line arguments.  Once this method has been
@@ -913,6 +915,7 @@ class AppRunner(DirectObject):
             raise ArgumentError, "No such file: %s" % (p3dFilename)
             raise ArgumentError, "No such file: %s" % (p3dFilename)
 
 
         fname.makeAbsolute()
         fname.makeAbsolute()
+        fname.setBinary()
         mf = Multifile()
         mf = Multifile()
         if p3dOffset == 0:
         if p3dOffset == 0:
             if not mf.openRead(fname):
             if not mf.openRead(fname):
@@ -976,6 +979,13 @@ class AppRunner(DirectObject):
 
 
         self.loadMultifilePrcFiles(mf, self.multifileRoot)
         self.loadMultifilePrcFiles(mf, self.multifileRoot)
         self.gotP3DFilename = True
         self.gotP3DFilename = True
+        self.p3dFilename = fname
+        if p3dUrl:
+            # The url from which the p3d file was downloaded is
+            # provided if available.  It is only for documentation
+            # purposes; the actual p3d file has already been
+            # downloaded to p3dFilename.
+            self.p3dUrl = PandaModules.URLSpec(p3dUrl)
 
 
         # Send this call to the main thread; don't call it directly.
         # Send this call to the main thread; don't call it directly.
         messenger.send('AppRunner_startIfReady', taskChain = 'default')
         messenger.send('AppRunner_startIfReady', taskChain = 'default')

+ 12 - 2
direct/src/plugin/p3dFileParams.I

@@ -16,8 +16,8 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DFileParams::get_p3d_filename
 //     Function: P3DFileParams::get_p3d_filename
 //       Access: Public
 //       Access: Public
-//  Description: Returns the p3d filename that was passed to the
-//               constructor.
+//  Description: Returns the filename that was passed to
+//               set_p3d_filename().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 inline const string &P3DFileParams::
 inline const string &P3DFileParams::
 get_p3d_filename() const {
 get_p3d_filename() const {
@@ -35,6 +35,16 @@ get_p3d_offset() const {
   return _p3d_offset;
   return _p3d_offset;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DFileParams::get_p3d_url
+//       Access: Public
+//  Description: Returns the string that was passed to set_p3d_url().
+////////////////////////////////////////////////////////////////////
+inline const string &P3DFileParams::
+get_p3d_url() const {
+  return _p3d_url;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DFileParams::get_num_tokens
 //     Function: P3DFileParams::get_num_tokens
 //       Access: Public
 //       Access: Public

+ 16 - 1
direct/src/plugin/p3dFileParams.cxx

@@ -33,6 +33,7 @@ P3DFileParams::
 P3DFileParams(const P3DFileParams &copy) :
 P3DFileParams(const P3DFileParams &copy) :
   _p3d_filename(copy._p3d_filename),
   _p3d_filename(copy._p3d_filename),
   _p3d_offset(copy._p3d_offset),
   _p3d_offset(copy._p3d_offset),
+  _p3d_url(copy._p3d_url),
   _tokens(copy._tokens),
   _tokens(copy._tokens),
   _args(copy._args)
   _args(copy._args)
 {
 {
@@ -47,6 +48,7 @@ void P3DFileParams::
 operator = (const P3DFileParams &other) {
 operator = (const P3DFileParams &other) {
   _p3d_filename = other._p3d_filename;
   _p3d_filename = other._p3d_filename;
   _p3d_offset = other._p3d_offset;
   _p3d_offset = other._p3d_offset;
+  _p3d_url = other._p3d_url;
   _tokens = other._tokens;
   _tokens = other._tokens;
   _args = other._args;
   _args = other._args;
 }
 }
@@ -62,7 +64,7 @@ set_p3d_filename(const string &p3d_filename) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: P3DFileParams::set_p3d_filename
+//     Function: P3DFileParams::set_p3d_offset
 //       Access: Public
 //       Access: Public
 //  Description: Specifies the location in the file where
 //  Description: Specifies the location in the file where
 //               the p3d file data starts.
 //               the p3d file data starts.
@@ -72,6 +74,18 @@ set_p3d_offset(const int &p3d_offset) {
   _p3d_offset = p3d_offset;
   _p3d_offset = p3d_offset;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DFileParams::set_p3d_url
+//       Access: Public
+//  Description: Specifies the original URL that hosted the p3d file,
+//               if any.  This is for documentation purposes only; it
+//               is communicated to the child Panda3D process.
+////////////////////////////////////////////////////////////////////
+void P3DFileParams::
+set_p3d_url(const string &p3d_url) {
+  _p3d_url = p3d_url;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DFileParams::set_tokens
 //     Function: P3DFileParams::set_tokens
 //       Access: Public
 //       Access: Public
@@ -179,6 +193,7 @@ make_xml() {
 
 
   xfparams->SetAttribute("p3d_filename", _p3d_filename);
   xfparams->SetAttribute("p3d_filename", _p3d_filename);
   xfparams->SetAttribute("p3d_offset", _p3d_offset);
   xfparams->SetAttribute("p3d_offset", _p3d_offset);
+  xfparams->SetAttribute("p3d_url", _p3d_url);
 
 
   Tokens::const_iterator ti;
   Tokens::const_iterator ti;
   for (ti = _tokens.begin(); ti != _tokens.end(); ++ti) {
   for (ti = _tokens.begin(); ti != _tokens.end(); ++ti) {

+ 3 - 0
direct/src/plugin/p3dFileParams.h

@@ -32,11 +32,13 @@ public:
 
 
   void set_p3d_filename(const string &p3d_filename);
   void set_p3d_filename(const string &p3d_filename);
   void set_p3d_offset(const int &p3d_offset);
   void set_p3d_offset(const int &p3d_offset);
+  void set_p3d_url(const string &p3d_url);
   void set_tokens(const P3D_token tokens[], size_t num_tokens);
   void set_tokens(const P3D_token tokens[], size_t num_tokens);
   void set_args(int argc, const char *argv[]);
   void set_args(int argc, const char *argv[]);
 
 
   inline const string &get_p3d_filename() const;
   inline const string &get_p3d_filename() const;
   inline int get_p3d_offset() const;
   inline int get_p3d_offset() const;
+  inline const string &get_p3d_url() const;
   string lookup_token(const string &keyword) const;
   string lookup_token(const string &keyword) const;
   int lookup_token_int(const string &keyword) const;
   int lookup_token_int(const string &keyword) const;
   bool has_token(const string &keyword) const;
   bool has_token(const string &keyword) const;
@@ -58,6 +60,7 @@ private:
 
 
   string _p3d_filename;
   string _p3d_filename;
   int _p3d_offset;
   int _p3d_offset;
+  string _p3d_url;
   Tokens _tokens;
   Tokens _tokens;
   Args _args;
   Args _args;
 };
 };

+ 5 - 0
direct/src/plugin/p3dInstance.cxx

@@ -228,6 +228,8 @@ P3DInstance(P3D_request_ready_func *func,
   _main_object->set_string_property("coreapiTimestampString", timestamp_string);
   _main_object->set_string_property("coreapiTimestampString", timestamp_string);
   _main_object->set_string_property("coreapiVersionString", inst_mgr->get_coreapi_set_ver());
   _main_object->set_string_property("coreapiVersionString", inst_mgr->get_coreapi_set_ver());
 
 
+  _main_object->set_bool_property("trustedEnvironment", (int)inst_mgr->get_trusted_environment());
+  _main_object->set_bool_property("consoleEnvironment", (int)inst_mgr->get_console_environment());
 
 
   // We'll start off with the "download" image displayed in the splash
   // We'll start off with the "download" image displayed in the splash
   // window (when it opens), until we get stuff downloaded.
   // window (when it opens), until we get stuff downloaded.
@@ -409,6 +411,7 @@ set_p3d_url(const string &p3d_url) {
     set_failed();
     set_failed();
     return;
     return;
   }
   }
+  _fparams.set_p3d_url(p3d_url);
 
 
   // Save the last part of the URL as the p3d_basename, for reporting
   // Save the last part of the URL as the p3d_basename, for reporting
   // purposes or whatever.
   // purposes or whatever.
@@ -452,6 +455,8 @@ set_p3d_url(const string &p3d_url) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int P3DInstance::
 int P3DInstance::
 make_p3d_stream(const string &p3d_url) {
 make_p3d_stream(const string &p3d_url) {
+  _fparams.set_p3d_url(p3d_url);
+
   // Save the last part of the URL as the p3d_basename, for reporting
   // Save the last part of the URL as the p3d_basename, for reporting
   // purposes or whatever.
   // purposes or whatever.
   determine_p3d_basename(p3d_url);
   determine_p3d_basename(p3d_url);

+ 9 - 2
direct/src/plugin/p3dPythonRun.cxx

@@ -1324,6 +1324,12 @@ set_p3d_filename(P3DCInstance *inst, TiXmlElement *xfparams) {
   int p3d_offset = 0;
   int p3d_offset = 0;
   xfparams->Attribute("p3d_offset", &p3d_offset);
   xfparams->Attribute("p3d_offset", &p3d_offset);
 
 
+  string p3d_url;
+  const char *p3d_url_c = xfparams->Attribute("p3d_url");
+  if (p3d_url_c != NULL) {
+    p3d_url = p3d_url_c;
+  }
+
   PyObject *token_list = PyList_New(0);
   PyObject *token_list = PyList_New(0);
   TiXmlElement *xtoken = xfparams->FirstChildElement("token");
   TiXmlElement *xtoken = xfparams->FirstChildElement("token");
   while (xtoken != NULL) {
   while (xtoken != NULL) {
@@ -1363,8 +1369,9 @@ set_p3d_filename(P3DCInstance *inst, TiXmlElement *xfparams) {
   }
   }
 
 
   PyObject *result = PyObject_CallMethod
   PyObject *result = PyObject_CallMethod
-    (_runner, (char *)"setP3DFilename", (char *)"sOOiii", p3d_filename.c_str(),
-     token_list, arg_list, inst->get_instance_id(), _interactive_console, p3d_offset);
+    (_runner, (char *)"setP3DFilename", (char *)"sOOiiis", p3d_filename.c_str(),
+     token_list, arg_list, inst->get_instance_id(), _interactive_console, p3d_offset,
+     p3d_url.c_str());
   Py_DECREF(token_list);
   Py_DECREF(token_list);
   Py_DECREF(arg_list);
   Py_DECREF(arg_list);