Panda3D
|
00001 // Filename: config_express.cxx 00002 // Created by: drose (28Mar06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "config_express.h" 00016 #include "datagram.h" 00017 #include "nodeReferenceCount.h" 00018 #include "referenceCount.h" 00019 #include "textEncoder.h" 00020 #include "typedObject.h" 00021 #include "typedReferenceCount.h" 00022 #include "virtualFile.h" 00023 #include "virtualFileComposite.h" 00024 #include "virtualFileMount.h" 00025 #include "virtualFileMountMultifile.h" 00026 #include "virtualFileMountRamdisk.h" 00027 #include "virtualFileMountSystem.h" 00028 #include "virtualFileSimple.h" 00029 #include "fileReference.h" 00030 #include "temporaryFile.h" 00031 #include "pandaSystem.h" 00032 #include "numeric_types.h" 00033 #include "namable.h" 00034 #include "export_dtool.h" 00035 #include "dconfig.h" 00036 #include "streamWrapper.h" 00037 00038 ConfigureDef(config_express); 00039 NotifyCategoryDef(express, ""); 00040 NotifyCategoryDef(clock, ":express"); 00041 00042 ConfigureFn(config_express) { 00043 init_libexpress(); 00044 } 00045 00046 ConfigVariableInt patchfile_window_size 00047 ("patchfile-window-size", 16); 00048 00049 ConfigVariableInt patchfile_increment_size 00050 ("patchfile-increment-size", 8); 00051 00052 ConfigVariableInt patchfile_buffer_size 00053 ("patchfile-buffer-size", 4096); 00054 00055 ConfigVariableInt patchfile_zone_size 00056 ("patchfile-zone-size", 10000); 00057 00058 ConfigVariableBool keep_temporary_files 00059 ("keep-temporary-files", false, 00060 PRC_DESC("Set this true to keep around the temporary files from " 00061 "downloading, decompressing, and patching, or false (the " 00062 "default) to delete these. Mainly useful for debugging " 00063 "when the process goes wrong.")); 00064 00065 ConfigVariableBool multifile_always_binary 00066 ("multifile-always-binary", false, 00067 PRC_DESC("This is a temporary transition variable. Set this true " 00068 "to enable the old behavior for multifiles: all subfiles are " 00069 "always added to and extracted from the multifile in binary mode. " 00070 "Set it false to enable the new behavior: subfiles may be added " 00071 "or extracted in either binary or text mode, according to the " 00072 "set_binary() or set_text() flag on the Filename.")); 00073 00074 ConfigVariableBool collect_tcp 00075 ("collect-tcp", false, 00076 PRC_DESC("Set this true to enable accumulation of several small consecutive " 00077 "TCP datagrams into one large datagram before sending it, to reduce " 00078 "overhead from the TCP/IP protocol. See " 00079 "Connection::set_collect_tcp() or SocketStream::set_collect_tcp().")); 00080 00081 ConfigVariableDouble collect_tcp_interval 00082 ("collect-tcp-interval", 0.2); 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: init_libexpress 00086 // Description: Initializes the library. This must be called at 00087 // least once before any of the functions or classes in 00088 // this library can be used. Normally it will be 00089 // called by the static initializers and need not be 00090 // called explicitly, but special cases exist. 00091 //////////////////////////////////////////////////////////////////// 00092 void 00093 init_libexpress() { 00094 static bool initialized = false; 00095 if (initialized) { 00096 return; 00097 } 00098 initialized = true; 00099 00100 Datagram::init_type(); 00101 Namable::init_type(); 00102 NodeReferenceCount::init_type(); 00103 ReferenceCount::init_type(); 00104 TypedObject::init_type(); 00105 TypedReferenceCount::init_type(); 00106 VirtualFile::init_type(); 00107 VirtualFileComposite::init_type(); 00108 VirtualFileMount::init_type(); 00109 VirtualFileMountMultifile::init_type(); 00110 VirtualFileMountRamdisk::init_type(); 00111 VirtualFileMountSystem::init_type(); 00112 VirtualFileSimple::init_type(); 00113 FileReference::init_type(); 00114 TemporaryFile::init_type(); 00115 00116 init_system_type_handles(); 00117 00118 #ifdef HAVE_ZLIB 00119 { 00120 PandaSystem *ps = PandaSystem::get_global_ptr(); 00121 ps->add_system("zlib"); 00122 } 00123 #endif 00124 00125 // This is a fine place to ensure that the numeric types have been 00126 // chosen correctly. 00127 nassertv(sizeof(PN_int8) == 1 && sizeof(PN_uint8) == 1); 00128 nassertv(sizeof(PN_int16) == 2 && sizeof(PN_uint16) == 2); 00129 nassertv(sizeof(PN_int32) == 4 && sizeof(PN_uint32) == 4); 00130 nassertv(sizeof(PN_int64) == 8 && sizeof(PN_uint64) == 8); 00131 nassertv(sizeof(PN_float32) == 4); 00132 nassertv(sizeof(PN_float64) == 8); 00133 00134 // Also, ensure that we have the right endianness. 00135 PN_uint32 word; 00136 memcpy(&word, "\1\2\3\4", 4); 00137 #ifdef WORDS_BIGENDIAN 00138 nassertv(word == 0x01020304); 00139 #else 00140 nassertv(word == 0x04030201); 00141 #endif 00142 } 00143 00144 bool 00145 get_use_high_res_clock() { 00146 static ConfigVariableBool *use_high_res_clock = NULL; 00147 00148 if (use_high_res_clock == (ConfigVariableBool *)NULL) { 00149 use_high_res_clock = new ConfigVariableBool 00150 ("use-high-res-clock", true, 00151 PRC_DESC("Set this to false to avoid using the high-precision clock, even if " 00152 "it is available.")); 00153 } 00154 00155 return *use_high_res_clock; 00156 } 00157 00158 bool 00159 get_paranoid_clock() { 00160 static ConfigVariableBool *paranoid_clock = NULL; 00161 00162 if (paranoid_clock == (ConfigVariableBool *)NULL) { 00163 paranoid_clock = new ConfigVariableBool 00164 ("paranoid-clock", false, 00165 PRC_DESC("Set this to true to double-check the results of the high-resolution " 00166 "clock against the system clock.")); 00167 } 00168 00169 return *paranoid_clock; 00170 } 00171 00172 bool 00173 get_verify_dcast() { 00174 static ConfigVariableBool *verify_dcast = NULL; 00175 00176 if (verify_dcast == (ConfigVariableBool *)NULL) { 00177 verify_dcast = new ConfigVariableBool 00178 ("verify-dcast", true, 00179 PRC_DESC("Set this to true to verify that every attempted DCAST operation in " 00180 "fact references the correct type, or false otherwise. This has no " 00181 "effect if NDEBUG is defined, in which case it is never tested.")); 00182 } 00183 00184 return *verify_dcast; 00185 } 00186 00187 // Returns the configure object for accessing config variables from a 00188 // scripting language. 00189 DConfig & 00190 get_config_express() { 00191 static DConfig config_express; 00192 return config_express; 00193 }