Panda3D
config_express.cxx
1 // Filename: config_express.cxx
2 // Created by: drose (28Mar06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_express.h"
16 #include "datagram.h"
17 #include "datagramIterator.h"
18 #include "nodeReferenceCount.h"
19 #include "referenceCount.h"
20 #include "textEncoder.h"
21 #include "typedObject.h"
22 #include "typedReferenceCount.h"
23 #include "virtualFile.h"
24 #include "virtualFileComposite.h"
25 #include "virtualFileMount.h"
26 #include "virtualFileMountAndroidAsset.h"
27 #include "virtualFileMountMultifile.h"
28 #include "virtualFileMountRamdisk.h"
29 #include "virtualFileMountSystem.h"
30 #include "virtualFileSimple.h"
31 #include "fileReference.h"
32 #include "temporaryFile.h"
33 #include "pandaSystem.h"
34 #include "numeric_types.h"
35 #include "namable.h"
36 #include "export_dtool.h"
37 #include "dconfig.h"
38 #include "streamWrapper.h"
39 
40 ConfigureDef(config_express);
41 NotifyCategoryDef(express, "");
42 NotifyCategoryDef(clock, ":express");
43 
44 ConfigureFn(config_express) {
45  init_libexpress();
46 }
47 
48 ConfigVariableInt patchfile_window_size
49 ("patchfile-window-size", 16);
50 
51 ConfigVariableInt patchfile_increment_size
52 ("patchfile-increment-size", 8);
53 
54 ConfigVariableInt patchfile_buffer_size
55 ("patchfile-buffer-size", 4096);
56 
57 ConfigVariableInt patchfile_zone_size
58 ("patchfile-zone-size", 10000);
59 
60 ConfigVariableBool keep_temporary_files
61 ("keep-temporary-files", false,
62  PRC_DESC("Set this true to keep around the temporary files from "
63  "downloading, decompressing, and patching, or false (the "
64  "default) to delete these. Mainly useful for debugging "
65  "when the process goes wrong."));
66 
67 ConfigVariableBool multifile_always_binary
68 ("multifile-always-binary", false,
69  PRC_DESC("This is a temporary transition variable. Set this true "
70  "to enable the old behavior for multifiles: all subfiles are "
71  "always added to and extracted from the multifile in binary mode. "
72  "Set it false to enable the new behavior: subfiles may be added "
73  "or extracted in either binary or text mode, according to the "
74  "set_binary() or set_text() flag on the Filename."));
75 
76 ConfigVariableBool collect_tcp
77 ("collect-tcp", false,
78  PRC_DESC("Set this true to enable accumulation of several small consecutive "
79  "TCP datagrams into one large datagram before sending it, to reduce "
80  "overhead from the TCP/IP protocol. See "
81  "Connection::set_collect_tcp() or SocketStream::set_collect_tcp()."));
82 
83 ConfigVariableDouble collect_tcp_interval
84 ("collect-tcp-interval", 0.2);
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: init_libexpress
88 // Description: Initializes the library. This must be called at
89 // least once before any of the functions or classes in
90 // this library can be used. Normally it will be
91 // called by the static initializers and need not be
92 // called explicitly, but special cases exist.
93 ////////////////////////////////////////////////////////////////////
94 void
95 init_libexpress() {
96  static bool initialized = false;
97  if (initialized) {
98  return;
99  }
100  initialized = true;
101 
102  Datagram::init_type();
103  DatagramIterator::init_type();
104  Namable::init_type();
105  NodeReferenceCount::init_type();
106  ReferenceCount::init_type();
108  TypedReferenceCount::init_type();
109  VirtualFile::init_type();
110  VirtualFileComposite::init_type();
111  VirtualFileMount::init_type();
112 #ifdef ANDROID
113  VirtualFileMountAndroidAsset::init_type();
114 #endif
115  VirtualFileMountMultifile::init_type();
116  VirtualFileMountRamdisk::init_type();
117  VirtualFileMountSystem::init_type();
118  VirtualFileSimple::init_type();
119  FileReference::init_type();
120  TemporaryFile::init_type();
121 
122  init_system_type_handles();
123 
124 #ifdef HAVE_ZLIB
125  {
127  ps->add_system("zlib");
128  }
129 #endif
130 
131  // This is a fine place to ensure that the numeric types have been
132  // chosen correctly.
133  nassertv(sizeof(PN_int8) == 1 && sizeof(PN_uint8) == 1);
134  nassertv(sizeof(PN_int16) == 2 && sizeof(PN_uint16) == 2);
135  nassertv(sizeof(PN_int32) == 4 && sizeof(PN_uint32) == 4);
136  nassertv(sizeof(PN_int64) == 8 && sizeof(PN_uint64) == 8);
137  nassertv(sizeof(PN_float32) == 4);
138  nassertv(sizeof(PN_float64) == 8);
139 
140  // Also, ensure that we have the right endianness.
141  PN_uint32 word;
142  memcpy(&word, "\1\2\3\4", 4);
143 #ifdef WORDS_BIGENDIAN
144  nassertv(word == 0x01020304);
145 #else
146  nassertv(word == 0x04030201);
147 #endif
148 }
149 
150 bool
151 get_use_high_res_clock() {
152  static ConfigVariableBool *use_high_res_clock = NULL;
153 
154  if (use_high_res_clock == (ConfigVariableBool *)NULL) {
155  use_high_res_clock = new ConfigVariableBool
156  ("use-high-res-clock", true,
157  PRC_DESC("Set this to false to avoid using the high-precision clock, even if "
158  "it is available."));
159  }
160 
161  return *use_high_res_clock;
162 }
163 
164 bool
165 get_paranoid_clock() {
166  static ConfigVariableBool *paranoid_clock = NULL;
167 
168  if (paranoid_clock == (ConfigVariableBool *)NULL) {
169  paranoid_clock = new ConfigVariableBool
170  ("paranoid-clock", false,
171  PRC_DESC("Set this to true to double-check the results of the high-resolution "
172  "clock against the system clock."));
173  }
174 
175  return *paranoid_clock;
176 }
177 
178 bool
179 get_verify_dcast() {
180  static ConfigVariableBool *verify_dcast = NULL;
181 
182  if (verify_dcast == (ConfigVariableBool *)NULL) {
183  verify_dcast = new ConfigVariableBool
184  ("verify-dcast", true,
185  PRC_DESC("Set this to true to verify that every attempted DCAST operation in "
186  "fact references the correct type, or false otherwise. This has no "
187  "effect if NDEBUG is defined, in which case it is never tested."));
188  }
189 
190  return *verify_dcast;
191 }
192 
193 // Returns the configure object for accessing config variables from a
194 // scripting language.
195 DConfig &
196 get_config_express() {
197  static DConfig config_express;
198  return config_express;
199 }
200 
201 #ifdef ANDROID
202 static JavaVM *panda_jvm = NULL;
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: JNI_OnLoad
206 // Description: Called by Java when loading this library.
207 ////////////////////////////////////////////////////////////////////
208 jint JNI_OnLoad(JavaVM *jvm, void *reserved) {
209  panda_jvm = jvm;
210  return JNI_VERSION_1_4;
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: get_java_vm
215 // Description: Returns a pointer to the JavaVM object.
216 ////////////////////////////////////////////////////////////////////
217 JavaVM *get_java_vm() {
218  nassertr(panda_jvm != NULL, NULL);
219  return panda_jvm;
220 }
221 
222 ////////////////////////////////////////////////////////////////////
223 // Function: get_jni_env
224 // Description: Returns a JNIEnv object for the current thread.
225 // If it doesn't already exist, attaches the JVM
226 // to this thread.
227 ////////////////////////////////////////////////////////////////////
228 JNIEnv *get_jni_env() {
229  nassertr(panda_jvm != NULL, NULL);
230  JNIEnv *env = NULL;
231  int status = panda_jvm->GetEnv((void**) &env, JNI_VERSION_1_4);
232 
233  if (status < 0 || env == NULL) {
234  express_cat.error() << "JVM is not available in this thread!\n";
235  return NULL;
236  }
237 
238  return env;
239 }
240 #endif
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:52
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:29
This is a convenience class to specialize ConfigVariable as a boolean type.
This class emulates the old dconfig-style interface to our Panda config system.
Definition: dconfig.h:37
void add_system(const string &system)
Intended for use by each subsystem to register itself at startup.
This is a convenience class to specialize ConfigVariable as a floating-point type.
This is a convenience class to specialize ConfigVariable as an integer type.