Sfoglia il codice sorgente

Merge branch 'master' into cmake

Conflicts:
	panda/src/display/graphicsWindow_ext.cxx
	panda/src/mathutil/triangulator3.cxx
	panda/src/putil/pythonCallbackObject.cxx
Sam Edwards 11 anni fa
parent
commit
9ec74a0421

+ 1 - 0
direct/src/filter/FilterManager.py

@@ -298,6 +298,7 @@ class FilterManager(DirectObject):
         props.setBackBuffers(0)
         props.setRgbColor(1)
         props.setDepthBits(depthbits)
+        props.setStereo(self.win.isStereo())
         depthtex, colortex, auxtex0, auxtex1 = texgroup
         if (auxtex0 != None):
             props.setAuxRgba(1)

+ 1 - 0
direct/src/interval/ProjectileInterval.py

@@ -3,6 +3,7 @@
 __all__ = ['ProjectileInterval']
 
 from pandac.PandaModules import *
+from direct.directnotify.DirectNotifyGlobal import *
 from Interval import Interval
 from direct.showbase.PythonUtil import lerp
 from direct.showbase import PythonUtil

+ 6 - 1
dtool/src/dtoolbase/atomicAdjust.h

@@ -39,14 +39,19 @@ typedef AtomicAdjustI386Impl AtomicAdjust;
 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE 1
 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE_PTR 1
 
-#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
+#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (defined(__clang__) && (__clang_major__ >= 3))
 // GCC 4.7 and above has built-in __atomic functions for atomic operations.
+// Clang 3.0 and above also supports them.
 
 #include "atomicAdjustGccImpl.h"
 typedef AtomicAdjustGccImpl AtomicAdjust;
 
+#if (__GCC_ATOMIC_INT_LOCK_FREE + __GCC_ATOMIC_INT_LOCK_FREE) > 0
 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE 1
+#endif
+#if __GCC_ATOMIC_POINTER_LOCK_FREE > 0
 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE_PTR 1
+#endif
 
 #elif defined(THREAD_WIN32_IMPL)
 

+ 2 - 2
dtool/src/dtoolbase/atomicAdjustGccImpl.I

@@ -125,7 +125,7 @@ compare_and_exchange(TVOLATILE AtomicAdjustGccImpl::Integer &mem,
                      AtomicAdjustGccImpl::Integer old_value,
                      AtomicAdjustGccImpl::Integer new_value) {
 
-  __atomic_compare_exchange_n(&mem, &old_value, new_value, false,
+  __atomic_compare_exchange_n(&mem, &old_value, new_value, true,
                               __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
   return old_value;
 }
@@ -142,7 +142,7 @@ compare_and_exchange_ptr(TVOLATILE AtomicAdjustGccImpl::Pointer &mem,
                          AtomicAdjustGccImpl::Pointer old_value,
                          AtomicAdjustGccImpl::Pointer new_value) {
 
-  __atomic_compare_exchange_n(&mem, &old_value, new_value, false,
+  __atomic_compare_exchange_n(&mem, &old_value, new_value, true,
                               __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
   return old_value;
 }

+ 1 - 1
dtool/src/dtoolbase/atomicAdjustGccImpl.h

@@ -18,7 +18,7 @@
 #include "dtoolbase.h"
 #include "selectThreadImpl.h"
 
-#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
+#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (defined(__clang__) && (__clang_major__ >= 3))
 
 ////////////////////////////////////////////////////////////////////
 //       Class : AtomicAdjustGccImpl

+ 1 - 1
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -371,7 +371,7 @@ get_slotted_function_def(Object *obj, Function *func, SlottedFunctionDef &def) {
     return true;
   }
 
-  if (method_name == "operator << ") {
+  if (method_name == "operator <<") {
     def._answer_location = "tp_as_number->nb_lshift";
     def._wrapper_type = WT_numeric_operator;
     return true;

+ 0 - 2
panda/src/display/graphicsWindow_ext.cxx

@@ -21,7 +21,6 @@
 //       Access: Published
 //  Description: Adds a python event handler to be called
 //               when a window event occurs.
-//               
 ////////////////////////////////////////////////////////////////////
 void Extension<GraphicsWindow>::
 add_python_event_handler(PyObject* handler, PyObject* name){
@@ -34,7 +33,6 @@ add_python_event_handler(PyObject* handler, PyObject* name){
 //     Function: Extension<GraphicsWindow>::remove_custom_event_handler
 //       Access: Published
 //  Description: Removes the specified python event handler.
-//               
 ////////////////////////////////////////////////////////////////////
 void Extension<GraphicsWindow>::
 remove_python_event_handler(PyObject* name){

+ 2 - 0
panda/src/express/ca_bundle_data_src.c

@@ -11,6 +11,8 @@
  * in DER form, for compiling into OpenSSLWrapper.
  */
 
+#include <stddef.h>
+
 static const unsigned char ca_bundle_data[] = {
   0x30, 0x82, 0x02, 0x5a, 0x30, 0x82, 0x01, 0xc3, 0x02, 0x02, 0x01,
   0xa5, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,

+ 2 - 0
panda/src/framework/rock_floor.rgb_src.c

@@ -6,6 +6,8 @@
  * bin2c -static -string -n rock_floor -o rock_floor.rgb.c rock-floor.rgb
  */
 
+#include <stddef.h>
+
 static const unsigned char rock_floor[] = {
   0x01, 0xda, 0x01, 0x01, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00,
   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,

+ 2 - 0
panda/src/framework/shuttle_controls.bam_src.c

@@ -5,6 +5,8 @@
  * bin2c -static -string -n shuttle_controls -o shuttle_controls.bam.c shuttle_controls.bam
  */
 
+#include <stddef.h>
+
 static const unsigned char shuttle_controls[] = {
   0x70, 0x62, 0x6a, 0x00, 0x0a, 0x0d, 0x05, 0x00, 0x00, 0x00, 0x06,
   0x00, 0x12, 0x00, 0x01, 0x9c, 0x00, 0x00, 0x00, 0x43, 0x01, 0x09,

+ 1 - 1
panda/src/mathutil/triangulator3.cxx

@@ -13,7 +13,7 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "triangulator3.h"
-#include "look_at_src.h"
+#include "look_at.h"
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Triangulator3::Constructor

+ 2 - 0
panda/src/osxdisplay/resize_box.rgb.c

@@ -5,6 +5,8 @@
  * bin2c -static -string -n resize_box -o resize_box.rgb.c resize_box.rgb
  */
 
+#include <stddef.h>
+
 static const unsigned char resize_box[] = {
   0x01, 0xda, 0x01, 0x01, 0x00, 0x03, 0x00, 0x10, 0x00, 0x10, 0x00,
   0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,

+ 5 - 13
panda/src/putil/bamWriter.cxx

@@ -61,12 +61,7 @@ BamWriter::
   StateMap::iterator si;
   for (si = _state_map.begin(); si != _state_map.end(); ++si) {
     TypedWritable *object = (TypedWritable *)(*si).first;
-    LightMutexHolder holder(TypedWritable::_bam_writers_lock);
-    nassertv(object->_bam_writers != (TypedWritable::BamWriters *)NULL);
-    TypedWritable::BamWriters::iterator wi = 
-      find(object->_bam_writers->begin(), object->_bam_writers->end(), this);
-    nassertv(wi != object->_bam_writers->end());
-    object->_bam_writers->erase(wi);
+    object->remove_bam_writer(this);
   }
 }
 
@@ -633,13 +628,10 @@ enqueue_object(const TypedWritable *object) {
     bool inserted =
       _state_map.insert(StateMap::value_type(object, StoreState(_next_object_id))).second;
     nassertr(inserted, false);
-    {
-      LightMutexHolder holder(TypedWritable::_bam_writers_lock);
-      if (object->_bam_writers == ((TypedWritable::BamWriters *)NULL)) {
-        ((TypedWritable *)object)->_bam_writers = new TypedWritable::BamWriters;
-      }
-      object->_bam_writers->push_back(this);
-    }
+
+    // Store ourselves on the TypedWritable so that we get notified
+    // when it destructs.
+    (const_cast<TypedWritable*>(object))->add_bam_writer(this);
     _next_object_id++;
 
   } else {

+ 94 - 14
panda/src/putil/typedWritable.cxx

@@ -20,8 +20,6 @@
 #include "lightMutexHolder.h"
 #include "bam.h"
 
-LightMutex TypedWritable::_bam_writers_lock;
-
 TypeHandle TypedWritable::_type_handle;
 TypedWritable* const TypedWritable::Null = (TypedWritable*)0L;
 
@@ -33,19 +31,22 @@ TypedWritable* const TypedWritable::Null = (TypedWritable*)0L;
 TypedWritable::
 ~TypedWritable() {
   // Remove the object pointer from the BamWriters that reference it.
-  if (_bam_writers != (BamWriters *)NULL) {
-    BamWriters temp;
-    {
-      LightMutexHolder holder(_bam_writers_lock);
-      _bam_writers->swap(temp);
-      delete _bam_writers;
-      _bam_writers = NULL;
-    }
-    BamWriters::iterator wi;
-    for (wi = temp.begin(); wi != temp.end(); ++wi) {
-      BamWriter *writer = (*wi);
-      writer->object_destructs(this);
+  BamWriterLink *link;
+  do {
+    link = (BamWriterLink *)AtomicAdjust::get_ptr(_bam_writers);
+    if (link == (BamWriterLink *)NULL) {
+      // List is unlocked and empty - no writers to remove.
+      return;
     }
+    link = (BamWriterLink *)(((uintptr_t)link) & ~(uintptr_t)0x1);
+  } while (link != AtomicAdjust::
+    compare_and_exchange_ptr(_bam_writers, (void *)link, (void *)NULL));
+
+  while (link != (BamWriterLink *)NULL) {
+    BamWriterLink *next_link = link->_next;
+    link->_writer->object_destructs(this);
+    delete link;
+    link = next_link;
   }
 }
 
@@ -308,3 +309,82 @@ decode_raw_from_bam_stream(TypedWritable *&ptr, ReferenceCount *&ref_ptr,
   ref_ptr->unref();
   return true;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: TypedWritable::add_bam_writer
+//       Access: Private
+//  Description: Called by the BamWriter to add itself to this
+//               TypedWritable's list of BamWriters, so that it can
+//               receive notification whenever this object destructs.
+//               This method may be safely called from any thread.
+////////////////////////////////////////////////////////////////////
+void TypedWritable::
+add_bam_writer(BamWriter *writer) {
+  nassertv(writer != (BamWriter *)NULL);
+
+  BamWriterLink *begin;
+  BamWriterLink *new_link = new BamWriterLink;
+  new_link->_writer = writer;
+
+  // Assert that we got at least a 2-byte aligned pointer from new.
+  nassertv(((uintptr_t)new_link & (uintptr_t)0x1) == 0);
+
+  // This spins if the lower bit is 1, ie. if the pointer is locked.
+  do {
+    begin = (BamWriterLink *)AtomicAdjust::get_ptr(_bam_writers);
+    begin = (BamWriterLink *)(((uintptr_t)begin) & ~(uintptr_t)0x1);
+    new_link->_next = begin;
+  } while (begin != AtomicAdjust::
+    compare_and_exchange_ptr(_bam_writers, (void *)begin, (void *)new_link));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TypedWritable::remove_bam_writer
+//       Access: Private
+//  Description: The converse of add_bam_writer.
+//               This method may be safely called from any thread.
+////////////////////////////////////////////////////////////////////
+void TypedWritable::
+remove_bam_writer(BamWriter *writer) {
+  nassertv(writer != (BamWriter *)NULL);
+
+  BamWriterLink *begin;
+
+  // Grab the head pointer and lock it in one atomic operation.
+  // We lock it by tagging the pointer.
+  do {
+    begin = (BamWriterLink *)AtomicAdjust::get_ptr(_bam_writers);
+    begin = (BamWriterLink *)(((uintptr_t)begin) & ~(uintptr_t)0x1);
+    if (begin == NULL) {
+      // The list is empty, nothing to remove.
+      return;
+    }
+  } while (begin != AtomicAdjust::
+    compare_and_exchange_ptr(_bam_writers, (void *)begin,
+                       (void *)((uintptr_t)begin | (uintptr_t)0x1)));
+
+  // Find the writer in the list.
+  BamWriterLink *prev_link = (BamWriterLink *)NULL;
+  BamWriterLink *link = begin;
+
+  while (link != NULL && link->_writer != writer) {
+    prev_link = link;
+    link = link->_next;
+  }
+
+  if (link == (BamWriterLink *)NULL) {
+    // Not found.  Just unlock and leave.
+    _bam_writers = (void *)begin;
+    return;
+  }
+
+  if (prev_link == (BamWriterLink *)NULL) {
+    // It's the first link.  Replace and unlock in one atomic op.
+    _bam_writers = (void *)link->_next;
+  } else {
+    prev_link->_next = link->_next;
+    _bam_writers = (void *)begin; // Unlock
+  }
+
+  delete link;
+}

+ 9 - 4
panda/src/putil/typedWritable.h

@@ -69,13 +69,18 @@ PUBLISHED:
                                          const string &data,
                                          BamReader *reader = NULL);
 
-private:
+public:
+  void add_bam_writer(BamWriter *writer);
+  void remove_bam_writer(BamWriter *writer);
+
   // We may need to store a list of the BamWriter(s) that have a
   // reference to this object, so that we can remove the object from
   // those tables when it destructs.
-  typedef pvector<BamWriter *> BamWriters;
-  BamWriters *_bam_writers;
-  static LightMutex _bam_writers_lock;
+  struct BamWriterLink {
+    BamWriter *_writer;
+    BamWriterLink *_next;
+  };
+  AtomicAdjust::Pointer _bam_writers; // Tagged pointer
 
   UpdateSeq _bam_modified;
 

+ 2 - 0
panda/src/text/cmss12.bam.pz_src.c

@@ -5,6 +5,8 @@
  * bin2c -n default_font_data -o cmss12.bam.pz.c cmss12.bam.pz
  */
 
+#include <stddef.h>
+
 const unsigned char default_font_data[] = {
   0x78, 0x9c, 0xec, 0xbd, 0x0d, 0x5c, 0x54, 0xc5, 0xfe, 0x3f, 0x7e,
   0xe0, 0x78, 0x37, 0x30, 0x79, 0x30, 0x44, 0x41, 0x49, 0x44, 0x43,

+ 2 - 0
panda/src/text/cmss12.bam_src.c

@@ -5,6 +5,8 @@
  * bin2c -n default_font_data -o cmss12.bam.c cmss12.bam
  */
 
+#include <stddef.h>
+
 const unsigned char default_font_data[] = {
   0x70, 0x62, 0x6a, 0x00, 0x0a, 0x0d, 0x05, 0x00, 0x00, 0x00, 0x06,
   0x00, 0x12, 0x00, 0x01, 0x92, 0x00, 0x00, 0x00, 0x43, 0x01, 0x09,

+ 2 - 0
panda/src/text/persans.ttf_src.c

@@ -5,6 +5,8 @@
  * bin2c -n default_font_data -o persans.ttf.c persans.ttf
  */
 
+#include <stddef.h>
+
 const unsigned char default_font_data[] = {
   0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x03, 0x00,
   0x30, 0x4f, 0x53, 0x2f, 0x32, 0x13, 0xab, 0x02, 0x15, 0x00, 0x00,

+ 8 - 5
pandatool/src/miscprogs/binToC.cxx

@@ -40,12 +40,12 @@ BinToC() :
      "for portably importing binary data into a library or executable.");
 
   add_option
-    ("n", "name", 0, 
+    ("n", "name", 0,
      "Specify the name of the table that is generated.",
      &BinToC::dispatch_string, NULL, &_table_name);
 
   add_option
-    ("static", "", 0, 
+    ("static", "", 0,
      "Flag the table with the keyword 'static'.",
      &BinToC::dispatch_none, &_static_table);
 
@@ -55,7 +55,7 @@ BinToC() :
      &BinToC::dispatch_none, &_for_string);
 
   add_option
-    ("o", "filename", 0, 
+    ("o", "filename", 0,
      "Specify the filename to which the resulting C code will be written.  "
      "If this option is omitted, the last parameter name is taken to be the "
      "name of the output file, or standard output is used if there are no "
@@ -98,7 +98,10 @@ run() {
       << " * This table was generated by the command:\n"
       << " *\n"
       << " * " << get_exec_command() << "\n"
-      << " */\n\n"
+      << " */\n"
+      << "\n"
+      << "#include <stddef.h>\n"
+      << "\n"
       << static_keyword << table_type << _table_name << "[] = {";
   out << hex << setfill('0');
   int count = 0;
@@ -120,7 +123,7 @@ run() {
     ch = in.get();
   }
   out << "\n};\n\n"
-      << static_keyword << length_type << _table_name << "_len = " 
+      << static_keyword << length_type << _table_name << "_len = "
       << dec << count << ";\n\n";
 }
 

+ 2 - 0
pandatool/src/vrml/standardNodes.wrl.c

@@ -5,6 +5,8 @@
  * bin2c -n standard_nodes_data -o standardNodes.wrl.c standardNodes.wrl
  */
 
+#include <stddef.h>
+
 const unsigned char standard_nodes_data[] = {
   0x23, 0x56, 0x52, 0x4d, 0x4c, 0x20, 0x56, 0x32, 0x2e, 0x30, 0x20,
   0x75, 0x74, 0x66, 0x38, 0x0a, 0x23, 0x0a, 0x23, 0x20, 0x2a, 0x2a,

+ 2 - 0
pandatool/src/vrml/standardNodes.wrl.pz.c

@@ -5,6 +5,8 @@
  * bin2c -n standard_nodes_data -o standardNodes.wrl.pz.c standardNodes.wrl.pz
  */
 
+#include <stddef.h>
+
 const unsigned char standard_nodes_data[] = {
   0x78, 0x9c, 0xd5, 0x5b, 0x5b, 0x6f, 0xdb, 0x38, 0x16, 0x7e, 0xcf,
   0xaf, 0x20, 0xd2, 0x97, 0x76, 0xd1, 0x09, 0x62, 0x17, 0xbd, 0xcd,

+ 2 - 0
pandatool/src/xfile/standardTemplates.x.c

@@ -5,6 +5,8 @@
  * bin2c -n standard_templates_data -o standardTemplates.x.c standardTemplates.x
  */
 
+#include <stddef.h>
+
 const unsigned char standard_templates_data[] = {
   0x78, 0x6f, 0x66, 0x20, 0x30, 0x33, 0x30, 0x33, 0x74, 0x78, 0x74,
   0x20, 0x30, 0x30, 0x33, 0x32, 0x0a, 0x0a, 0x23, 0x20, 0x54, 0x68,

+ 2 - 0
pandatool/src/xfile/standardTemplates.x.pz.c

@@ -5,6 +5,8 @@
  * bin2c -n standard_templates_data -o standardTemplates.x.pz.c standardTemplates.x.pz
  */
 
+#include <stddef.h>
+
 const unsigned char standard_templates_data[] = {
   0x78, 0x9c, 0xa5, 0x58, 0x6b, 0x6f, 0xdb, 0x38, 0x16, 0xfd, 0xee,
   0x5f, 0x41, 0x4c, 0x80, 0x6e, 0x67, 0x11, 0x65, 0xf5, 0x7e, 0xac,