diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 513d13fd90..d11a116415 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -514,15 +514,9 @@ receive_update_broadcast_required_owner(PyObject *distobj, for (int i = 0; i < num_fields && !PyErr_Occurred(); ++i) { DCField *field = get_inherited_field(i); if (field->as_molecular_field() == (DCMolecularField *)NULL && - field->is_required()) { + field->is_required() && (field->is_ownrecv() || field->is_broadcast())) { packer.begin_unpack(field); - if (field->is_ownrecv()) { - field->receive_update(packer, distobj); - } else { - // It's not an ownrecv field; skip over it. It's difficult to filter - // this on the server, ask Roger for the reason. - packer.unpack_skip(); - } + field->receive_update(packer, distobj); if (!packer.end_unpack()) { break; } @@ -946,19 +940,17 @@ ai_format_generate(PyObject *distobj, DOID_TYPE do_id, bool has_optional_fields = (PyObject_IsTrue(optional_fields) != 0); if (has_optional_fields) { - packer.raw_pack_uint16(STATESERVER_OBJECT_GENERATE_WITH_REQUIRED_OTHER); + packer.raw_pack_uint16(STATESERVER_CREATE_OBJECT_WITH_REQUIRED_OTHER); } else { - packer.raw_pack_uint16(STATESERVER_OBJECT_GENERATE_WITH_REQUIRED); + packer.raw_pack_uint16(STATESERVER_CREATE_OBJECT_WITH_REQUIRED); } + packer.raw_pack_uint32(do_id); // Parent is a bit overloaded; this parent is not about inheritance, this // one is about the visibility container parent, i.e. the zone parent: - if (parent_id) { - packer.raw_pack_uint32(parent_id); - } + packer.raw_pack_uint32(parent_id); packer.raw_pack_uint32(zone_id); packer.raw_pack_uint16(_number); - packer.raw_pack_uint32(do_id); // Specify all of the required fields. int num_fields = get_num_inherited_fields(); @@ -1009,77 +1001,6 @@ ai_format_generate(PyObject *distobj, DOID_TYPE do_id, return Datagram(packer.get_data(), packer.get_length()); } #endif // HAVE_PYTHON -#ifdef HAVE_PYTHON -/** - * Generates a datagram containing the message necessary to create a new - * database distributed object from the AI. - * - * First Pass is to only include required values (with Defaults). - */ -Datagram DCClass:: -ai_database_generate_context( - unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, - CHANNEL_TYPE owner_channel, - CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const -{ - DCPacker packer; - packer.raw_pack_uint8(1); - packer.RAW_PACK_CHANNEL(database_server_id); - packer.RAW_PACK_CHANNEL(from_channel_id); - // packer.raw_pack_uint8('A'); - packer.raw_pack_uint16(STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT); - packer.raw_pack_uint32(parent_id); - packer.raw_pack_uint32(zone_id); - packer.RAW_PACK_CHANNEL(owner_channel); - packer.raw_pack_uint16(_number); // DCD class ID - packer.raw_pack_uint32(context_id); - - // Specify all of the required fields. - int num_fields = get_num_inherited_fields(); - for (int i = 0; i < num_fields; ++i) { - DCField *field = get_inherited_field(i); - if (field->is_required() && field->as_molecular_field() == NULL) { - packer.begin_pack(field); - packer.pack_default_value(); - packer.end_pack(); - } - } - - return Datagram(packer.get_data(), packer.get_length()); -} -#endif // HAVE_PYTHON - -#ifdef HAVE_PYTHON -Datagram DCClass:: -ai_database_generate_context_old( - unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, - CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const -{ - DCPacker packer; - packer.raw_pack_uint8(1); - packer.RAW_PACK_CHANNEL(database_server_id); - packer.RAW_PACK_CHANNEL(from_channel_id); - // packer.raw_pack_uint8('A'); - packer.raw_pack_uint16(STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT); - packer.raw_pack_uint32(parent_id); - packer.raw_pack_uint32(zone_id); - packer.raw_pack_uint16(_number); // DCD class ID - packer.raw_pack_uint32(context_id); - - // Specify all of the required fields. - int num_fields = get_num_inherited_fields(); - for (int i = 0; i < num_fields; ++i) { - DCField *field = get_inherited_field(i); - if (field->is_required() && field->as_molecular_field() == NULL) { - packer.begin_pack(field); - packer.pack_default_value(); - packer.end_pack(); - } - } - - return Datagram(packer.get_data(), packer.get_length()); -} -#endif // HAVE_PYTHON /** * Write a string representation of this instance to . diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index 9e981a0097..73ad9e43d3 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -117,11 +117,6 @@ PUBLISHED: Datagram client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id, ZONEID_TYPE zone_id, PyObject *optional_fields) const; - Datagram ai_database_generate_context(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, CHANNEL_TYPE owner_channel, - CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const; - Datagram ai_database_generate_context_old(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, - CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const; - #endif public: diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 88b9786f51..a44412638a 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -391,7 +391,7 @@ Datagram DCField:: client_format_update(DOID_TYPE do_id, PyObject *args) const { DCPacker packer; - packer.raw_pack_uint16(CLIENT_OBJECT_UPDATE_FIELD); + packer.raw_pack_uint16(CLIENT_OBJECT_SET_FIELD); packer.raw_pack_uint32(do_id); packer.raw_pack_uint16(_number); @@ -417,7 +417,7 @@ ai_format_update(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyOb packer.raw_pack_uint8(1); packer.RAW_PACK_CHANNEL(to_id); packer.RAW_PACK_CHANNEL(from_id); - packer.raw_pack_uint16(STATESERVER_OBJECT_UPDATE_FIELD); + packer.raw_pack_uint16(STATESERVER_OBJECT_SET_FIELD); packer.raw_pack_uint32(do_id); packer.raw_pack_uint16(_number); diff --git a/direct/src/dcparser/dcmsgtypes.h b/direct/src/dcparser/dcmsgtypes.h index e5bbe81614..0e83f384c0 100644 --- a/direct/src/dcparser/dcmsgtypes.h +++ b/direct/src/dcparser/dcmsgtypes.h @@ -17,16 +17,13 @@ // This file defines the server message types used within this module. It // duplicates some symbols defined in MsgTypes.py and AIMsgTypes.py. -#define CLIENT_OBJECT_UPDATE_FIELD 24 -#define CLIENT_CREATE_OBJECT_REQUIRED 34 -#define CLIENT_CREATE_OBJECT_REQUIRED_OTHER 35 +#define CLIENT_OBJECT_SET_FIELD 120 +#define CLIENT_ENTER_OBJECT_REQUIRED 142 +#define CLIENT_ENTER_OBJECT_REQUIRED_OTHER 143 -#define STATESERVER_OBJECT_GENERATE_WITH_REQUIRED 2001 -#define STATESERVER_OBJECT_GENERATE_WITH_REQUIRED_OTHER 2003 -#define STATESERVER_OBJECT_UPDATE_FIELD 2004 -#define STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT 2050 -#define STATESERVER_OBJECT_CREATE_WITH_REQUIR_OTHER_CONTEXT 2051 -#define STATESERVER_BOUNCE_MESSAGE 2086 +#define STATESERVER_CREATE_OBJECT_WITH_REQUIRED 2000 +#define STATESERVER_CREATE_OBJECT_WITH_REQUIRED_OTHER 2001 +#define STATESERVER_OBJECT_SET_FIELD 2020 #define CLIENT_OBJECT_GENERATE_CMU 9002 diff --git a/direct/src/directtools/DirectSelection.py b/direct/src/directtools/DirectSelection.py index ef14fb429b..49410656b3 100644 --- a/direct/src/directtools/DirectSelection.py +++ b/direct/src/directtools/DirectSelection.py @@ -623,8 +623,8 @@ class SelectionRay(SelectionQueue): def pickBitMask(self, bitMask = BitMask32.allOff(), targetNodePath = None, skipFlags = SKIP_ALL): - if parentNodePath is None: - parentNodePath = render + if targetNodePath is None: + targetNodePath = render self.collideWithBitMask(bitMask) self.pick(targetNodePath) # Determine collision entry diff --git a/direct/src/distributed/CRDataCache.py b/direct/src/distributed/CRDataCache.py index 85036544de..b28453c0a3 100755 --- a/direct/src/distributed/CRDataCache.py +++ b/direct/src/distributed/CRDataCache.py @@ -2,6 +2,8 @@ from direct.distributed.CachedDOData import CachedDOData from panda3d.core import ConfigVariableInt +__all__ = ["CRDataCache"] + class CRDataCache: # Stores cached data for DistributedObjects between instantiations on the client diff --git a/direct/src/distributed/ClientRepositoryBase.py b/direct/src/distributed/ClientRepositoryBase.py index 826d3058fd..5aa7c3fa94 100644 --- a/direct/src/distributed/ClientRepositoryBase.py +++ b/direct/src/distributed/ClientRepositoryBase.py @@ -175,7 +175,7 @@ class ClientRepositoryBase(ConnectionRepository): "generate" messages when they are replayed(). """ - if msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER: + if msgType == CLIENT_ENTER_OBJECT_REQUIRED_OTHER: # It's a generate message. doId = extra if doId in self.deferredDoIds: @@ -263,7 +263,7 @@ class ClientRepositoryBase(ConnectionRepository): distObj.setLocation(parentId, zoneId) distObj.updateRequiredFields(dclass, di) # updateRequiredFields calls announceGenerate - print("New DO:%s, dclass:%s"%(doId, dclass.getName())) + self.notify.debug("New DO:%s, dclass:%s" % (doId, dclass.getName())) return distObj def generateWithRequiredOtherFields(self, dclass, doId, di, @@ -381,7 +381,7 @@ class ClientRepositoryBase(ConnectionRepository): # The object had been deferred. Great; we don't even have # to generate it now. del self.deferredDoIds[doId] - i = self.deferredGenerates.index((CLIENT_CREATE_OBJECT_REQUIRED_OTHER, doId)) + i = self.deferredGenerates.index((CLIENT_ENTER_OBJECT_REQUIRED_OTHER, doId)) del self.deferredGenerates[i] if len(self.deferredGenerates) == 0: taskMgr.remove('deferredGenerate') diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index 105b77a9a9..4d6dec5b81 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -10,6 +10,7 @@ from .PyDatagramIterator import PyDatagramIterator import types import gc +__all__ = ["ConnectionRepository", "GCTrigger"] class ConnectionRepository( DoInterestManager, DoCollectionManager, CConnectionRepository): diff --git a/direct/src/distributed/DistributedNode.py b/direct/src/distributed/DistributedNode.py index 1b0c3412dc..1a88fcc02a 100644 --- a/direct/src/distributed/DistributedNode.py +++ b/direct/src/distributed/DistributedNode.py @@ -15,6 +15,8 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath): self.DistributedNode_initialized = 1 self.gotStringParentToken = 0 DistributedObject.DistributedObject.__init__(self, cr) + if not self.this: + NodePath.__init__(self, "DistributedNode") # initialize gridParent self.gridParent = None diff --git a/direct/src/distributed/DistributedNodeUD.py b/direct/src/distributed/DistributedNodeUD.py index 21d6a2dbbb..39c0489f5e 100755 --- a/direct/src/distributed/DistributedNodeUD.py +++ b/direct/src/distributed/DistributedNodeUD.py @@ -1,4 +1,3 @@ -#from otp.ai.AIBaseGlobal import * from .DistributedObjectUD import DistributedObjectUD class DistributedNodeUD(DistributedObjectUD): diff --git a/direct/src/distributed/DistributedObjectAI.py b/direct/src/distributed/DistributedObjectAI.py index efe5cd02bf..847c0d7657 100644 --- a/direct/src/distributed/DistributedObjectAI.py +++ b/direct/src/distributed/DistributedObjectAI.py @@ -146,8 +146,6 @@ class DistributedObjectAI(DistributedObjectBase): barrier.cleanup() self.__barriers = {} - self.air.stopTrackRequestDeletedDO(self) - # DCR: I've re-enabled this block of code so that Toontown's # AI won't leak channels. # Let me know if it causes trouble. @@ -155,10 +153,9 @@ class DistributedObjectAI(DistributedObjectBase): ### block until a solution is thought out of how to prevent ### this delete message or to handle this message better # TODO: do we still need this check? - if not hasattr(self, "doNotDeallocateChannel"): - if self.air and not hasattr(self.air, "doNotDeallocateChannel"): - if self.air.minChannel <= self.doId <= self.air.maxChannel: - self.air.deallocateChannel(self.doId) + if not getattr(self, "doNotDeallocateChannel", False): + if self.air: + self.air.deallocateChannel(self.doId) self.air = None self.parentId = None @@ -200,9 +197,6 @@ class DistributedObjectAI(DistributedObjectBase): """ pass - def addInterest(self, zoneId, note="", event=None): - self.air.addInterest(self.doId, zoneId, note, event) - def b_setLocation(self, parentId, zoneId): self.d_setLocation(parentId, zoneId) self.setLocation(parentId, zoneId) @@ -274,9 +268,6 @@ class DistributedObjectAI(DistributedObjectBase): dclass.receiveUpdateOther(self, di) - def sendSetZone(self, zoneId): - self.air.sendSetZone(self, zoneId) - def startMessageBundle(self, name): self.air.startMessageBundle(name) def sendMessageBundle(self): @@ -349,10 +340,10 @@ class DistributedObjectAI(DistributedObjectBase): self.air.sendUpdate(self, fieldName, args) def GetPuppetConnectionChannel(self, doId): - return doId + (1 << 32) + return doId + (1001L << 32) def GetAccountConnectionChannel(self, doId): - return doId + (3 << 32) + return doId + (1003L << 32) def GetAccountIDFromChannelCode(self, channel): return channel >> 32 @@ -482,7 +473,6 @@ class DistributedObjectAI(DistributedObjectBase): (self.__class__, doId)) return self.air.requestDelete(self) - self.air.startTrackRequestDeletedDO(self) self._DOAI_requestedDelete = True def taskName(self, taskString): @@ -581,3 +571,5 @@ class DistributedObjectAI(DistributedObjectBase): """ This is a no-op on the AI. """ pass + def setAI(self, aiChannel): + self.air.setAI(self.doId, aiChannel) diff --git a/direct/src/distributed/DistributedObjectBase.py b/direct/src/distributed/DistributedObjectBase.py index af5f2678f3..3d9b525067 100755 --- a/direct/src/distributed/DistributedObjectBase.py +++ b/direct/src/distributed/DistributedObjectBase.py @@ -1,4 +1,3 @@ - from direct.showbase.DirectObject import DirectObject from direct.directnotify.DirectNotifyGlobal import directNotify @@ -93,3 +92,11 @@ class DistributedObjectBase(DirectObject): def hasParentingRules(self): return self.dclass.getFieldByName('setParentingRules') != None + + def delete(self): + """ + Override this to handle cleanup right before this object + gets deleted. + """ + + pass diff --git a/direct/src/distributed/DistributedObjectUD.py b/direct/src/distributed/DistributedObjectUD.py index c67d0004cc..e9e717a557 100755 --- a/direct/src/distributed/DistributedObjectUD.py +++ b/direct/src/distributed/DistributedObjectUD.py @@ -270,10 +270,10 @@ class DistributedObjectUD(DistributedObjectBase): self.air.sendUpdate(self, fieldName, args) def GetPuppetConnectionChannel(self, doId): - return doId + (1 << 32) + return doId + (1001L << 32) def GetAccountConnectionChannel(self, doId): - return doId + (3 << 32) + return doId + (1003L << 32) def GetAccountIDFromChannelCode(self, channel): return channel >> 32 diff --git a/direct/src/distributed/DoInterestManager.py b/direct/src/distributed/DoInterestManager.py index eb616d3f26..08a2f21657 100755 --- a/direct/src/distributed/DoInterestManager.py +++ b/direct/src/distributed/DoInterestManager.py @@ -111,7 +111,7 @@ class DoInterestManager(DirectObject.DirectObject): self._allInterestsCompleteCallbacks = [] def __verbose(self): - return self.InterestDebug or self.getVerbose() + return self.InterestDebug.getValue() or self.getVerbose() def _getAnonymousEvent(self, desc): return 'anonymous-%s-%s' % (desc, DoInterestManager._SerialGen.next()) @@ -504,18 +504,23 @@ class DoInterestManager(DirectObject.DirectObject): 'trying to set interest to invalid parent: %s' % parentId) datagram = PyDatagram() # Add message type - datagram.addUint16(CLIENT_ADD_INTEREST) - datagram.addUint16(handle) - datagram.addUint32(contextId) - datagram.addUint32(parentId) if isinstance(zoneIdList, list): vzl = list(zoneIdList) vzl.sort() uniqueElements(vzl) + datagram.addUint16(CLIENT_ADD_INTEREST_MULTIPLE) + datagram.addUint32(contextId) + datagram.addUint16(handle) + datagram.addUint32(parentId) + datagram.addUint16(len(vzl)) for zone in vzl: datagram.addUint32(zone) else: - datagram.addUint32(zoneIdList) + datagram.addUint16(CLIENT_ADD_INTEREST) + datagram.addUint32(contextId) + datagram.addUint16(handle) + datagram.addUint32(parentId) + datagram.addUint32(zoneIdList) self.send(datagram) def _sendRemoveInterest(self, handle, contextId): @@ -530,9 +535,8 @@ class DoInterestManager(DirectObject.DirectObject): datagram = PyDatagram() # Add message type datagram.addUint16(CLIENT_REMOVE_INTEREST) + datagram.addUint32(contextId) datagram.addUint16(handle) - if contextId != 0: - datagram.addUint32(contextId) self.send(datagram) if __debug__: state = DoInterestManager._interests[handle] @@ -583,8 +587,8 @@ class DoInterestManager(DirectObject.DirectObject): This handles the interest done messages and may dispatch an event """ assert DoInterestManager.notify.debugCall() - handle = di.getUint16() contextId = di.getUint32() + handle = di.getUint16() if self.__verbose(): print('CR::INTEREST.interestDone(handle=%s)' % handle) DoInterestManager.notify.debug( diff --git a/direct/src/distributed/MsgTypes.py b/direct/src/distributed/MsgTypes.py index b5e5d260df..14ce6ba55e 100644 --- a/direct/src/distributed/MsgTypes.py +++ b/direct/src/distributed/MsgTypes.py @@ -3,104 +3,140 @@ from direct.showbase.PythonUtil import invertDictLossless MsgName2Id = { - # 2 new params: passwd, char bool 0/1 1 = new account - # 2 new return values: 129 = not found, 12 = bad passwd, - 'CLIENT_LOGIN': 1, - 'CLIENT_LOGIN_RESP': 2, - 'CLIENT_GET_AVATARS': 3, + 'CLIENT_HELLO': 1, + 'CLIENT_HELLO_RESP': 2, + + # Sent by the client when it's leaving. + 'CLIENT_DISCONNECT': 3, + # Sent by the server when it is dropping the connection deliberately. - 'CLIENT_GO_GET_LOST': 4, - 'CLIENT_GET_AVATARS_RESP': 5, - 'CLIENT_CREATE_AVATAR': 6, - 'CLIENT_CREATE_AVATAR_RESP': 7, - 'CLIENT_GET_FRIEND_LIST': 10, - 'CLIENT_GET_FRIEND_LIST_RESP': 11, - 'CLIENT_GET_AVATAR_DETAILS': 14, - 'CLIENT_GET_AVATAR_DETAILS_RESP': 15, - 'CLIENT_LOGIN_2': 16, - 'CLIENT_LOGIN_2_RESP': 17, + 'CLIENT_EJECT': 4, - 'CLIENT_OBJECT_UPDATE_FIELD': 24, - 'CLIENT_OBJECT_UPDATE_FIELD_RESP': 24, - 'CLIENT_OBJECT_DISABLE': 25, - 'CLIENT_OBJECT_DISABLE_RESP': 25, - 'CLIENT_OBJECT_DISABLE_OWNER': 26, - 'CLIENT_OBJECT_DISABLE_OWNER_RESP': 26, - 'CLIENT_OBJECT_DELETE': 27, - 'CLIENT_OBJECT_DELETE_RESP': 27, - 'CLIENT_SET_ZONE_CMU': 29, - 'CLIENT_REMOVE_ZONE': 30, - 'CLIENT_SET_AVATAR': 32, - 'CLIENT_CREATE_OBJECT_REQUIRED': 34, - 'CLIENT_CREATE_OBJECT_REQUIRED_RESP': 34, - 'CLIENT_CREATE_OBJECT_REQUIRED_OTHER': 35, - 'CLIENT_CREATE_OBJECT_REQUIRED_OTHER_RESP': 35, - 'CLIENT_CREATE_OBJECT_REQUIRED_OTHER_OWNER': 36, - 'CLIENT_CREATE_OBJECT_REQUIRED_OTHER_OWNER_RESP':36, + 'CLIENT_HEARTBEAT': 5, - 'CLIENT_REQUEST_GENERATES': 36, + 'CLIENT_OBJECT_SET_FIELD': 120, + 'CLIENT_OBJECT_SET_FIELDS': 121, + 'CLIENT_OBJECT_LEAVING': 132, + 'CLIENT_OBJECT_LEAVING_OWNER': 161, + 'CLIENT_ENTER_OBJECT_REQUIRED': 142, + 'CLIENT_ENTER_OBJECT_REQUIRED_OTHER': 143, + 'CLIENT_ENTER_OBJECT_REQUIRED_OWNER': 172, + 'CLIENT_ENTER_OBJECT_REQUIRED_OTHER_OWNER': 173, - 'CLIENT_DISCONNECT': 37, + 'CLIENT_DONE_INTEREST_RESP': 204, - 'CLIENT_GET_STATE_RESP': 47, - 'CLIENT_DONE_INTEREST_RESP': 48, - - 'CLIENT_DELETE_AVATAR': 49, - - 'CLIENT_DELETE_AVATAR_RESP': 5, - - 'CLIENT_HEARTBEAT': 52, - 'CLIENT_FRIEND_ONLINE': 53, - 'CLIENT_FRIEND_OFFLINE': 54, - 'CLIENT_REMOVE_FRIEND': 56, - - 'CLIENT_CHANGE_PASSWORD': 65, - - 'CLIENT_SET_NAME_PATTERN': 67, - 'CLIENT_SET_NAME_PATTERN_ANSWER': 68, - - 'CLIENT_SET_WISHNAME': 70, - 'CLIENT_SET_WISHNAME_RESP': 71, - 'CLIENT_SET_WISHNAME_CLEAR': 72, - 'CLIENT_SET_SECURITY': 73, - - 'CLIENT_SET_DOID_RANGE': 74, - - 'CLIENT_GET_AVATARS_RESP2': 75, - 'CLIENT_CREATE_AVATAR2': 76, - 'CLIENT_SYSTEM_MESSAGE': 78, - 'CLIENT_SET_AVTYPE': 80, - - 'CLIENT_GET_PET_DETAILS': 81, - 'CLIENT_GET_PET_DETAILS_RESP': 82, - - 'CLIENT_ADD_INTEREST': 97, - 'CLIENT_REMOVE_INTEREST': 99, - 'CLIENT_OBJECT_LOCATION': 102, - - 'CLIENT_LOGIN_3': 111, - 'CLIENT_LOGIN_3_RESP': 110, - - 'CLIENT_GET_FRIEND_LIST_EXTENDED': 115, - 'CLIENT_GET_FRIEND_LIST_EXTENDED_RESP': 116, - - 'CLIENT_SET_FIELD_SENDABLE': 120, - - 'CLIENT_SYSTEMMESSAGE_AKNOWLEDGE': 123, - 'CLIENT_CHANGE_GENERATE_ORDER': 124, - - # new toontown specific login message, adds last logged in, and if child account has parent acount - 'CLIENT_LOGIN_TOONTOWN': 125, - 'CLIENT_LOGIN_TOONTOWN_RESP': 126, + 'CLIENT_ADD_INTEREST': 200, + 'CLIENT_ADD_INTEREST_MULTIPLE': 201, + 'CLIENT_REMOVE_INTEREST': 203, + 'CLIENT_OBJECT_LOCATION': 140, + # These are sent internally inside the Astron cluster. - 'STATESERVER_OBJECT_GENERATE_WITH_REQUIRED': 2001, - 'STATESERVER_OBJECT_GENERATE_WITH_REQUIRED_OTHER': 2003, - 'STATESERVER_OBJECT_UPDATE_FIELD': 2004, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT': 2050, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIR_OTHER_CONTEXT': 2051, - 'STATESERVER_BOUNCE_MESSAGE': 2086, + # Message Director control messages: + 'CONTROL_CHANNEL': 1, + 'CONTROL_ADD_CHANNEL': 9000, + 'CONTROL_REMOVE_CHANNEL': 9001, + 'CONTROL_ADD_RANGE': 9002, + 'CONTROL_REMOVE_RANGE': 9003, + 'CONTROL_ADD_POST_REMOVE': 9010, + 'CONTROL_CLEAR_POST_REMOVES': 9011, + + # State Server control messages: + 'STATESERVER_CREATE_OBJECT_WITH_REQUIRED': 2000, + 'STATESERVER_CREATE_OBJECT_WITH_REQUIRED_OTHER': 2001, + 'STATESERVER_DELETE_AI_OBJECTS': 2009, + 'STATESERVER_OBJECT_GET_FIELD': 2010, + 'STATESERVER_OBJECT_GET_FIELD_RESP': 2011, + 'STATESERVER_OBJECT_GET_FIELDS': 2012, + 'STATESERVER_OBJECT_GET_FIELDS_RESP': 2013, + 'STATESERVER_OBJECT_GET_ALL': 2014, + 'STATESERVER_OBJECT_GET_ALL_RESP': 2015, + 'STATESERVER_OBJECT_SET_FIELD': 2020, + 'STATESERVER_OBJECT_SET_FIELDS': 2021, + 'STATESERVER_OBJECT_DELETE_FIELD_RAM': 2030, + 'STATESERVER_OBJECT_DELETE_FIELDS_RAM': 2031, + 'STATESERVER_OBJECT_DELETE_RAM': 2032, + 'STATESERVER_OBJECT_SET_LOCATION': 2040, + 'STATESERVER_OBJECT_CHANGING_LOCATION': 2041, + 'STATESERVER_OBJECT_ENTER_LOCATION_WITH_REQUIRED': 2042, + 'STATESERVER_OBJECT_ENTER_LOCATION_WITH_REQUIRED_OTHER': 2043, + 'STATESERVER_OBJECT_GET_LOCATION': 2044, + 'STATESERVER_OBJECT_GET_LOCATION_RESP': 2045, + 'STATESERVER_OBJECT_SET_AI': 2050, + 'STATESERVER_OBJECT_CHANGING_AI': 2051, + 'STATESERVER_OBJECT_ENTER_AI_WITH_REQUIRED': 2052, + 'STATESERVER_OBJECT_ENTER_AI_WITH_REQUIRED_OTHER': 2053, + 'STATESERVER_OBJECT_GET_AI': 2054, + 'STATESERVER_OBJECT_GET_AI_RESP': 2055, + 'STATESERVER_OBJECT_SET_OWNER': 2060, + 'STATESERVER_OBJECT_CHANGING_OWNER': 2061, + 'STATESERVER_OBJECT_ENTER_OWNER_WITH_REQUIRED': 2062, + 'STATESERVER_OBJECT_ENTER_OWNER_WITH_REQUIRED_OTHER': 2063, + 'STATESERVER_OBJECT_GET_OWNER': 2064, + 'STATESERVER_OBJECT_GET_OWNER_RESP': 2065, + 'STATESERVER_OBJECT_GET_ZONE_OBJECTS': 2100, + 'STATESERVER_OBJECT_GET_ZONES_OBJECTS': 2102, + 'STATESERVER_OBJECT_GET_CHILDREN': 2104, + 'STATESERVER_OBJECT_GET_ZONE_COUNT': 2110, + 'STATESERVER_OBJECT_GET_ZONE_COUNT_RESP': 2111, + 'STATESERVER_OBJECT_GET_ZONES_COUNT': 2112, + 'STATESERVER_OBJECT_GET_ZONES_COUNT_RESP': 2113, + 'STATESERVER_OBJECT_GET_CHILD_COUNT': 2114, + 'STATESERVER_OBJECT_GET_CHILD_COUNT_RESP': 2115, + 'STATESERVER_OBJECT_DELETE_ZONE': 2120, + 'STATESERVER_OBJECT_DELETE_ZONES': 2122, + 'STATESERVER_OBJECT_DELETE_CHILDREN': 2124, + # DBSS-backed-object messages: + 'DBSS_OBJECT_ACTIVATE_WITH_DEFAULTS': 2200, + 'DBSS_OBJECT_ACTIVATE_WITH_DEFAULTS_OTHER': 2201, + 'DBSS_OBJECT_GET_ACTIVATED': 2207, + 'DBSS_OBJECT_GET_ACTIVATED_RESP': 2208, + 'DBSS_OBJECT_DELETE_FIELD_DISK': 2230, + 'DBSS_OBJECT_DELETE_FIELDS_DISK': 2231, + 'DBSS_OBJECT_DELETE_DISK': 2232, + + # Database Server control messages: + 'DBSERVER_CREATE_OBJECT': 3000, + 'DBSERVER_CREATE_OBJECT_RESP': 3001, + 'DBSERVER_OBJECT_GET_FIELD': 3010, + 'DBSERVER_OBJECT_GET_FIELD_RESP': 3011, + 'DBSERVER_OBJECT_GET_FIELDS': 3012, + 'DBSERVER_OBJECT_GET_FIELDS_RESP': 3013, + 'DBSERVER_OBJECT_GET_ALL': 3014, + 'DBSERVER_OBJECT_GET_ALL_RESP': 3015, + 'DBSERVER_OBJECT_SET_FIELD': 3020, + 'DBSERVER_OBJECT_SET_FIELDS': 3021, + 'DBSERVER_OBJECT_SET_FIELD_IF_EQUALS': 3022, + 'DBSERVER_OBJECT_SET_FIELD_IF_EQUALS_RESP': 3023, + 'DBSERVER_OBJECT_SET_FIELDS_IF_EQUALS': 3024, + 'DBSERVER_OBJECT_SET_FIELDS_IF_EQUALS_RESP': 3025, + 'DBSERVER_OBJECT_SET_FIELD_IF_EMPTY': 3026, + 'DBSERVER_OBJECT_SET_FIELD_IF_EMPTY_RESP': 3027, + 'DBSERVER_OBJECT_DELETE_FIELD': 3030, + 'DBSERVER_OBJECT_DELETE_FIELDS': 3031, + 'DBSERVER_OBJECT_DELETE': 3032, + + # Client Agent control messages: + 'CLIENTAGENT_SET_STATE': 1000, + 'CLIENTAGENT_SET_CLIENT_ID': 1001, + 'CLIENTAGENT_SEND_DATAGRAM': 1002, + 'CLIENTAGENT_EJECT': 1004, + 'CLIENTAGENT_DROP': 1005, + 'CLIENTAGENT_GET_NETWORK_ADDRESS': 1006, + 'CLIENTAGENT_GET_NETWORK_ADDRESS_RESP': 1007, + 'CLIENTAGENT_DECLARE_OBJECT': 1010, + 'CLIENTAGENT_UNDECLARE_OBJECT': 1011, + 'CLIENTAGENT_ADD_SESSION_OBJECT': 1012, + 'CLIENTAGENT_REMOVE_SESSION_OBJECT': 1013, + 'CLIENTAGENT_SET_FIELDS_SENDABLE': 1014, + 'CLIENTAGENT_OPEN_CHANNEL': 1100, + 'CLIENTAGENT_CLOSE_CHANNEL': 1101, + 'CLIENTAGENT_ADD_POST_REMOVE': 1110, + 'CLIENTAGENT_CLEAR_POST_REMOVES': 1111, + 'CLIENTAGENT_ADD_INTEREST': 1200, + 'CLIENTAGENT_ADD_INTEREST_MULTIPLE': 1201, + 'CLIENTAGENT_REMOVE_INTEREST': 1203, } # create id->name table for debugging diff --git a/direct/src/distributed/MsgTypesCMU.py b/direct/src/distributed/MsgTypesCMU.py index c0d1ccd4ca..e7c7501730 100644 --- a/direct/src/distributed/MsgTypesCMU.py +++ b/direct/src/distributed/MsgTypesCMU.py @@ -19,7 +19,7 @@ MsgName2Id = { 'CLIENT_HEARTBEAT_CMU' : 9011, 'CLIENT_OBJECT_UPDATE_FIELD_TARGETED_CMU' : 9011, - 'CLIENT_OBJECT_UPDATE_FIELD' : 24, # Matches MsgTypes.CLIENT_OBJECT_UPDATE_FIELD + 'CLIENT_OBJECT_UPDATE_FIELD' : 120, # Matches MsgTypes.CLIENT_OBJECT_SET_FIELD } # create id->name table for debugging diff --git a/direct/src/distributed/OldClientRepository.py b/direct/src/distributed/OldClientRepository.py deleted file mode 100644 index daeb4af628..0000000000 --- a/direct/src/distributed/OldClientRepository.py +++ /dev/null @@ -1,208 +0,0 @@ -"""OldClientRepository module: contains the OldClientRepository class""" - -from .ClientRepositoryBase import * - -class OldClientRepository(ClientRepositoryBase): - """ - This is the open-source ClientRepository as provided by CMU. It - communicates with the ServerRepository in this same directory. - - If you are looking for the VR Studio's implementation of the - client repository, look to OTPClientRepository (elsewhere). - """ - notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository") - - def __init__(self, dcFileNames = None): - ClientRepositoryBase.__init__(self, dcFileNames = dcFileNames) - - # The DOID allocator. The CMU LAN server may choose to - # send us a block of DOIDs. If it chooses to do so, then we - # may create objects, using those DOIDs. - self.DOIDbase = 0 - self.DOIDnext = 0 - self.DOIDlast = 0 - - def handleSetDOIDrange(self, di): - self.DOIDbase = di.getUint32() - self.DOIDlast = self.DOIDbase + di.getUint32() - self.DOIDnext = self.DOIDbase - - def handleRequestGenerates(self, di): - # When new clients join the zone of an object, they need to hear - # about it, so we send out all of our information about objects in - # that particular zone. - - assert self.DOIDnext < self.DOIDlast - zone = di.getUint32() - for obj in self.doId2do.values(): - if obj.zone == zone: - id = obj.doId - if (self.isLocalId(id)): - self.send(obj.dclass.clientFormatGenerate(obj, id, zone, [])) - - def createWithRequired(self, className, zoneId = 0, optionalFields=None): - if self.DOIDnext >= self.DOIDlast: - self.notify.error( - "Cannot allocate a distributed object ID: all IDs used up.") - return None - id = self.DOIDnext - self.DOIDnext = self.DOIDnext + 1 - dclass = self.dclassesByName[className] - classDef = dclass.getClassDef() - if classDef == None: - self.notify.error("Could not create an undefined %s object." % ( - dclass.getName())) - obj = classDef(self) - obj.dclass = dclass - obj.zone = zoneId - obj.doId = id - self.doId2do[id] = obj - obj.generateInit() - obj._retrieveCachedData() - obj.generate() - obj.announceGenerate() - datagram = dclass.clientFormatGenerate(obj, id, zoneId, optionalFields) - self.send(datagram) - return obj - - def sendDisableMsg(self, doId): - datagram = PyDatagram() - datagram.addUint16(CLIENT_OBJECT_DISABLE) - datagram.addUint32(doId) - self.send(datagram) - - def sendDeleteMsg(self, doId): - datagram = PyDatagram() - datagram.addUint16(CLIENT_OBJECT_DELETE) - datagram.addUint32(doId) - self.send(datagram) - - def sendRemoveZoneMsg(self, zoneId, visibleZoneList=None): - datagram = PyDatagram() - datagram.addUint16(CLIENT_REMOVE_ZONE) - datagram.addUint32(zoneId) - - # if we have an explicit list of visible zones, add them - if visibleZoneList is not None: - vzl = list(visibleZoneList) - vzl.sort() - assert PythonUtil.uniqueElements(vzl) - for zone in vzl: - datagram.addUint32(zone) - - # send the message - self.send(datagram) - - def sendUpdateZone(self, obj, zoneId): - id = obj.doId - assert self.isLocalId(id) - self.sendDeleteMsg(id, 1) - obj.zone = zoneId - self.send(obj.dclass.clientFormatGenerate(obj, id, zoneId, [])) - - def sendSetZoneMsg(self, zoneId, visibleZoneList=None): - datagram = PyDatagram() - # Add message type - datagram.addUint16(CLIENT_SET_ZONE_CMU) - # Add zone id - datagram.addUint32(zoneId) - - # if we have an explicit list of visible zones, add them - if visibleZoneList is not None: - vzl = list(visibleZoneList) - vzl.sort() - assert PythonUtil.uniqueElements(vzl) - for zone in vzl: - datagram.addUint32(zone) - - # send the message - self.send(datagram) - - def isLocalId(self, id): - return ((id >= self.DOIDbase) and (id < self.DOIDlast)) - - def haveCreateAuthority(self): - return (self.DOIDlast > self.DOIDnext) - - def handleDatagram(self, di): - if self.notify.getDebug(): - print("ClientRepository received datagram:") - di.getDatagram().dumpHex(ostream) - - msgType = self.getMsgType() - - # These are the sort of messages we may expect from the public - # Panda server. - - if msgType == CLIENT_SET_DOID_RANGE: - self.handleSetDOIDrange(di) - elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_RESP: - self.handleGenerateWithRequired(di) - elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER_RESP: - self.handleGenerateWithRequiredOther(di) - elif msgType == CLIENT_OBJECT_UPDATE_FIELD_RESP: - self.handleUpdateField(di) - elif msgType == CLIENT_OBJECT_DELETE_RESP: - self.handleDelete(di) - elif msgType == CLIENT_OBJECT_DISABLE_RESP: - self.handleDisable(di) - elif msgType == CLIENT_REQUEST_GENERATES: - self.handleRequestGenerates(di) - else: - self.handleMessageType(msgType, di) - - # If we're processing a lot of datagrams within one frame, we - # may forget to send heartbeats. Keep them coming! - self.considerHeartbeat() - - def handleGenerateWithRequired(self, di): - # Get the class Id - classId = di.getUint16() - # Get the DO Id - doId = di.getUint32() - # Look up the dclass - dclass = self.dclassesByNumber[classId] - dclass.startGenerate() - # Create a new distributed object, and put it in the dictionary - distObj = self.generateWithRequiredFields(dclass, doId, di) - dclass.stopGenerate() - - def generateWithRequiredFields(self, dclass, doId, di): - if doId in self.doId2do: - # ...it is in our dictionary. - # Just update it. - distObj = self.doId2do[doId] - assert distObj.dclass == dclass - distObj.generate() - distObj.updateRequiredFields(dclass, di) - # updateRequiredFields calls announceGenerate - elif self.cache.contains(doId): - # ...it is in the cache. - # Pull it out of the cache: - distObj = self.cache.retrieve(doId) - assert distObj.dclass == dclass - # put it in the dictionary: - self.doId2do[doId] = distObj - # and update it. - distObj.generate() - distObj.updateRequiredFields(dclass, di) - # updateRequiredFields calls announceGenerate - else: - # ...it is not in the dictionary or the cache. - # Construct a new one - classDef = dclass.getClassDef() - if classDef == None: - self.notify.error("Could not create an undefined %s object." % ( - dclass.getName())) - distObj = classDef(self) - distObj.dclass = dclass - # Assign it an Id - distObj.doId = doId - # Put the new do in the dictionary - self.doId2do[doId] = distObj - # Update the required fields - distObj.generateInit() # Only called when constructed - distObj.generate() - distObj.updateRequiredFields(dclass, di) - # updateRequiredFields calls announceGenerate - return distObj diff --git a/direct/src/distributed/PyDatagram.py b/direct/src/distributed/PyDatagram.py index 74e73fbf28..eebc06e440 100755 --- a/direct/src/distributed/PyDatagram.py +++ b/direct/src/distributed/PyDatagram.py @@ -7,7 +7,7 @@ from panda3d.core import Datagram from panda3d.direct import * # Import the type numbers -#from otp.ai.AIMsgTypes import * +from direct.distributed.MsgTypes import * class PyDatagram(Datagram): @@ -47,13 +47,10 @@ class PyDatagram(Datagram): self.addUint16(code) -# def addServerControlHeader(self, code): -# self.addInt8(1) -# self.addChannel(CONTROL_MESSAGE) -# self.addUint16(code) -# def addOldServerControlHeader(self, code): -# self.addChannel(CONTROL_MESSAGE) -# self.addUint16(code) + def addServerControlHeader(self, code): + self.addInt8(1) + self.addChannel(CONTROL_CHANNEL) + self.addUint16(code) def putArg(self, arg, subatomicType, divisor=1): if (divisor == 1): diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index a19491d825..67d6ec1658 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -301,8 +301,8 @@ check_datagram() { switch (_msg_type) { #ifdef HAVE_PYTHON - case CLIENT_OBJECT_UPDATE_FIELD: - case STATESERVER_OBJECT_UPDATE_FIELD: + case CLIENT_OBJECT_SET_FIELD: + case STATESERVER_OBJECT_SET_FIELD: if (_handle_c_updates) { if (_has_owner_view) { if (!handle_update_field_owner()) { @@ -494,7 +494,7 @@ send_message_bundle(unsigned int channel, unsigned int sender_channel) { dg.add_int8(1); dg.add_uint64(channel); dg.add_uint64(sender_channel); - dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); + //dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); // add each bundled message BundledMsgVector::const_iterator bmi; for (bmi = _bundle_msgs.begin(); bmi != _bundle_msgs.end(); bmi++) { @@ -899,11 +899,11 @@ describe_message(ostream &out, const string &prefix, packer.RAW_UNPACK_CHANNEL(); // msg_sender msg_type = packer.raw_unpack_uint16(); - is_update = (msg_type == STATESERVER_OBJECT_UPDATE_FIELD); + is_update = (msg_type == STATESERVER_OBJECT_SET_FIELD); } else { msg_type = packer.raw_unpack_uint16(); - is_update = (msg_type == CLIENT_OBJECT_UPDATE_FIELD); + is_update = (msg_type == CLIENT_OBJECT_SET_FIELD); } if (!is_update) { diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.cxx b/direct/src/distributed/cDistributedSmoothNodeBase.cxx index 70a50f33f5..14a665d9b9 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.cxx +++ b/direct/src/distributed/cDistributedSmoothNodeBase.cxx @@ -278,12 +278,12 @@ begin_send_update(DCPacker &packer, const string &field_name) { packer.RAW_PACK_CHANNEL(_do_id); packer.RAW_PACK_CHANNEL(_ai_id); // packer.raw_pack_uint8('A'); - packer.raw_pack_uint16(STATESERVER_OBJECT_UPDATE_FIELD); + packer.raw_pack_uint16(STATESERVER_OBJECT_SET_FIELD); packer.raw_pack_uint32(_do_id); packer.raw_pack_uint16(field->get_number()); } else { - packer.raw_pack_uint16(CLIENT_OBJECT_UPDATE_FIELD); + packer.raw_pack_uint16(CLIENT_OBJECT_SET_FIELD); packer.raw_pack_uint32(_do_id); packer.raw_pack_uint16(field->get_number()); } diff --git a/direct/src/gui/DirectGuiBase.py b/direct/src/gui/DirectGuiBase.py index 6836f7465f..3180d0dfce 100644 --- a/direct/src/gui/DirectGuiBase.py +++ b/direct/src/gui/DirectGuiBase.py @@ -80,7 +80,8 @@ __all__ = ['DirectGuiBase', 'DirectGuiWidget'] from panda3d.core import * -from panda3d.direct import get_config_showbase +from direct.showbase import ShowBaseGlobal +from direct.showbase.ShowBase import ShowBase from . import DirectGuiGlobals as DGG from .OnscreenText import * from .OnscreenGeom import * @@ -633,7 +634,7 @@ class DirectGuiBase(DirectObject.DirectObject): """ # Need to tack on gui item specific id gEvent = event + self.guiId - if get_config_showbase().GetBool('debug-directgui-msgs', False): + if ShowBase.config.GetBool('debug-directgui-msgs', False): from direct.showbase.PythonUtil import StackTrace print(gEvent) print(StackTrace()) @@ -662,7 +663,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath): # Determine the default initial state for inactive (or # unclickable) components. If we are in edit mode, these are # actually clickable by default. - guiEdit = get_config_showbase().GetBool('direct-gui-edit', 0) + guiEdit = ShowBase.config.GetBool('direct-gui-edit', False) if guiEdit: inactiveInitState = DGG.NORMAL else: @@ -723,21 +724,24 @@ class DirectGuiWidget(DirectGuiBase, NodePath): if self['guiId']: self.guiItem.setId(self['guiId']) self.guiId = self.guiItem.getId() - if __dev__: + + if ShowBaseGlobal.__dev__: guiObjectCollector.addLevel(1) guiObjectCollector.flushLevel() # track gui items by guiId for tracking down leaks - if hasattr(base, 'guiItems'): - if self.guiId in base.guiItems: - base.notify.warning('duplicate guiId: %s (%s stomping %s)' % - (self.guiId, self, - base.guiItems[self.guiId])) - base.guiItems[self.guiId] = self - if hasattr(base, 'printGuiCreates'): - printStack() + if ShowBase.config.GetBool('track-gui-items', False): + if not hasattr(ShowBase, 'guiItems'): + ShowBase.guiItems = {} + if self.guiId in ShowBase.guiItems: + ShowBase.notify.warning('duplicate guiId: %s (%s stomping %s)' % + (self.guiId, self, + ShowBase.guiItems[self.guiId])) + ShowBase.guiItems[self.guiId] = self + # Attach button to parent and make that self - if (parent == None): - parent = aspect2d + if parent is None: + parent = ShowBaseGlobal.aspect2d + self.assign(parent.attachNewNode(self.guiItem, self['sortOrder'])) # Update pose to initial values if self['pos']: @@ -1024,17 +1028,12 @@ class DirectGuiWidget(DirectGuiBase, NodePath): def destroy(self): if hasattr(self, "frameStyle"): - if __dev__: + if ShowBaseGlobal.__dev__: guiObjectCollector.subLevel(1) guiObjectCollector.flushLevel() - if hasattr(base, 'guiItems'): - if self.guiId in base.guiItems: - del base.guiItems[self.guiId] - else: - base.notify.warning( - 'DirectGuiWidget.destroy(): ' - 'gui item %s not in base.guiItems' % - self.guiId) + if hasattr(ShowBase, 'guiItems'): + ShowBase.guiItems.pop(self.guiId, None) + # Destroy children for child in self.getChildren(): childGui = self.guiDict.get(child.getName()) diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 580f2b6ce7..42ee315909 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -47,10 +47,6 @@ if __debug__: from . import OnScreenDebug from . import AppRunnerGlobal -def legacyRun(): - assert builtins.base.notify.warning("run() is deprecated, use base.run() instead") - builtins.base.run() - @atexit.register def exitfunc(): if getattr(builtins, 'base', None) is not None: @@ -369,7 +365,6 @@ class ShowBase(DirectObject.DirectObject): builtins.bboard = self.bboard # Config needs to be defined before ShowBase is constructed #builtins.config = self.config - builtins.run = legacyRun builtins.ostream = Notify.out() builtins.directNotify = directNotify builtins.giveNotify = giveNotify @@ -391,7 +386,9 @@ class ShowBase(DirectObject.DirectObject): # Now add this instance to the ShowBaseGlobal module scope. from . import ShowBaseGlobal + builtins.run = ShowBaseGlobal.run ShowBaseGlobal.base = self + ShowBaseGlobal.__dev__ = self.__dev__ if self.__dev__: ShowBase.notify.debug('__dev__ == %s' % self.__dev__) @@ -400,10 +397,10 @@ class ShowBase(DirectObject.DirectObject): self.createBaseAudioManagers() - if self.__dev__ or self.config.GetBool('want-e3-hacks', False): - if self.config.GetBool('track-gui-items', True): - # dict of guiId to gui item, for tracking down leaks - self.guiItems = {} + if self.__dev__ and self.config.GetBool('track-gui-items', False): + # dict of guiId to gui item, for tracking down leaks + if not hasattr(ShowBase, 'guiItems'): + ShowBase.guiItems = {} # optionally restore the default gui sounds from 1.7.2 and earlier if ConfigVariableBool('orig-gui-sounds', False).getValue(): @@ -515,6 +512,7 @@ class ShowBase(DirectObject.DirectObject): # Remove the built-in base reference if getattr(builtins, 'base', None) is self: + del builtins.run del builtins.base del builtins.loader del builtins.taskMgr @@ -522,6 +520,8 @@ class ShowBase(DirectObject.DirectObject): if ShowBaseGlobal: del ShowBaseGlobal.base + self.aspect2d.node().removeAllChildren() + # [gjeon] restore sticky key settings if self.config.GetBool('disable-sticky-keys', 0): allowAccessibilityShortcutKeys(True) @@ -1104,13 +1104,18 @@ class ShowBase(DirectObject.DirectObject): self.render2d.setMaterialOff(1) self.render2d.setTwoSided(1) + # We've already created aspect2d in ShowBaseGlobal, for the + # benefit of creating DirectGui elements before ShowBase. + from . import ShowBaseGlobal + ## The normal 2-d DisplayRegion has an aspect ratio that ## matches the window, but its coordinate system is square. ## This means anything we parent to render2d gets stretched. ## For things where that makes a difference, we set up ## aspect2d, which scales things back to the right aspect ## ratio along the X axis (Z is still from -1 to 1) - self.aspect2d = self.render2d.attachNewNode(PGTop("aspect2d")) + self.aspect2d = ShowBaseGlobal.aspect2d + self.aspect2d.reparentTo(self.render2d) aspectRatio = self.getAspectRatio() self.aspect2d.setScale(1.0 / aspectRatio, 1.0, 1.0) diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index 1f1c81af1a..459d5f708f 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -11,9 +11,11 @@ from .ShowBase import ShowBase, WindowControls from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem from panda3d.core import ConfigPageManager, ConfigVariableManager +from panda3d.core import NodePath, PGTop from panda3d.direct import get_config_showbase config = get_config_showbase() +__dev__ = config.GetBool('want-dev', __debug__) vfs = VirtualFileSystem.getGlobalPtr() ostream = Notify.out() @@ -22,9 +24,16 @@ cpMgr = ConfigPageManager.getGlobalPtr() cvMgr = ConfigVariableManager.getGlobalPtr() pandaSystem = PandaSystem.getGlobalPtr() +# This is defined here so GUI elements can be instantiated before ShowBase. +aspect2d = NodePath(PGTop("aspect2d")) + # Set direct notify categories now that we have config directNotify.setDconfigLevels() +def run(): + assert ShowBase.notify.warning("run() is deprecated, use base.run() instead") + base.run() + def inspect(anObject): # Don't use a regular import, to prevent ModuleFinder from picking # it up as a dependency when building a .p3d package. @@ -41,6 +50,4 @@ builtins.inspect = inspect # this also appears in AIBaseGlobal if (not __debug__) and __dev__: - notify = directNotify.newCategory('ShowBaseGlobal') - notify.error("You must set 'want-dev' to false in non-debug mode.") - del notify + ShowBase.notify.error("You must set 'want-dev' to false in non-debug mode.") diff --git a/makepanda/makepanda.vcproj b/makepanda/makepanda.vcproj index a787653e1e..c21322f94a 100644 --- a/makepanda/makepanda.vcproj +++ b/makepanda/makepanda.vcproj @@ -3736,18 +3736,6 @@ - - - - - - - - - - - - diff --git a/panda/src/audiotraits/openalAudioManager.cxx b/panda/src/audiotraits/openalAudioManager.cxx index 8d38eeec49..cbdaadbfa1 100644 --- a/panda/src/audiotraits/openalAudioManager.cxx +++ b/panda/src/audiotraits/openalAudioManager.cxx @@ -471,6 +471,12 @@ get_sound(MovieAudio *sound, bool positional, int mode) { PT(OpenALAudioSound) oas = new OpenALAudioSound(this, sound, positional, mode); + if(!oas->_manager) { + // The sound cleaned itself up immediately. It pretty clearly didn't like + // something, so we should just return a null sound instead. + return get_null_sound(); + } + _all_sounds.insert(oas); PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas; return res; @@ -500,6 +506,12 @@ get_sound(const string &file_name, bool positional, int mode) { PT(OpenALAudioSound) oas = new OpenALAudioSound(this, mva, positional, mode); + if(!oas->_manager) { + // The sound cleaned itself up immediately. It pretty clearly didn't like + // something, so we should just return a null sound instead. + return get_null_sound(); + } + _all_sounds.insert(oas); PT(AudioSound) res = (AudioSound*)(OpenALAudioSound*)oas; return res; diff --git a/panda/src/audiotraits/openalAudioSound.I b/panda/src/audiotraits/openalAudioSound.I index a68d36ee12..1b7e56a82c 100644 --- a/panda/src/audiotraits/openalAudioSound.I +++ b/panda/src/audiotraits/openalAudioSound.I @@ -37,16 +37,19 @@ get_calibrated_clock(double rtc) const { /** * Makes sure the sound data record is present, and if not, obtains it. + * + * Returns true on success, false on failure. */ -void OpenALAudioSound:: +bool OpenALAudioSound:: require_sound_data() { if (_sd==0) { _sd = _manager->get_sound_data(_movie, _desired_mode); if (_sd==0) { audio_error("Could not open audio " << _movie->get_filename()); - cleanup(); + return false; } } + return true; } /** diff --git a/panda/src/audiotraits/openalAudioSound.cxx b/panda/src/audiotraits/openalAudioSound.cxx index 9abaf24036..d3c5ff7291 100644 --- a/panda/src/audiotraits/openalAudioSound.cxx +++ b/panda/src/audiotraits/openalAudioSound.cxx @@ -69,8 +69,8 @@ OpenALAudioSound(OpenALAudioManager* manager, ReMutexHolder holder(OpenALAudioManager::_lock); - require_sound_data(); - if (_manager == NULL) { + if (!require_sound_data()) { + cleanup(); return; } @@ -130,10 +130,12 @@ play() { stop(); - require_sound_data(); - if (_manager == 0) return; - _manager->starting_sound(this); + if (!require_sound_data()) { + cleanup(); + return; + } + _manager->starting_sound(this); if (!_source) { return; } diff --git a/panda/src/audiotraits/openalAudioSound.h b/panda/src/audiotraits/openalAudioSound.h index 3442acb4f2..f5b02667e5 100644 --- a/panda/src/audiotraits/openalAudioSound.h +++ b/panda/src/audiotraits/openalAudioSound.h @@ -116,7 +116,7 @@ private: int read_stream_data(int bytelen, unsigned char *data); void pull_used_buffers(); void push_fresh_buffers(); - INLINE void require_sound_data(); + INLINE bool require_sound_data(); INLINE void release_sound_data(); private: diff --git a/panda/src/bullet/bulletBaseCharacterControllerNode.h b/panda/src/bullet/bulletBaseCharacterControllerNode.h index e7abe41886..eafc561c67 100644 --- a/panda/src/bullet/bulletBaseCharacterControllerNode.h +++ b/panda/src/bullet/bulletBaseCharacterControllerNode.h @@ -43,8 +43,8 @@ public: virtual btPairCachingGhostObject *get_ghost() const = 0; virtual btCharacterControllerInterface *get_character() const = 0; - virtual void sync_p2b(PN_stdfloat dt, int num_substeps) = 0; - virtual void sync_b2p() = 0; + virtual void do_sync_p2b(PN_stdfloat dt, int num_substeps) = 0; + virtual void do_sync_b2p() = 0; public: static TypeHandle get_class_type() { diff --git a/panda/src/bullet/bulletBodyNode.I b/panda/src/bullet/bulletBodyNode.I index 01e62e8bd6..6f9aac9f45 100644 --- a/panda/src/bullet/bulletBodyNode.I +++ b/panda/src/bullet/bulletBodyNode.I @@ -84,51 +84,6 @@ get_collision_response() const { return !get_collision_flag(btCollisionObject::CF_NO_CONTACT_RESPONSE); } -/** - * - */ -INLINE void BulletBodyNode:: -set_collision_flag(int flag, bool value) { - - int flags = get_object()->getCollisionFlags(); - - if (value == true) { - flags |= flag; - } - else { - flags &= ~(flag); - } - - get_object()->setCollisionFlags(flags); -} - -/** - * - */ -INLINE bool BulletBodyNode:: -get_collision_flag(int flag) const { - - return (get_object()->getCollisionFlags() & flag) ? true : false; -} - -/** - * - */ -INLINE bool BulletBodyNode:: -is_static() const { - - return get_object()->isStaticObject(); -} - -/** - * - */ -INLINE bool BulletBodyNode:: -is_kinematic() const { - - return get_object()->isKinematicObject(); -} - /** * */ @@ -147,90 +102,6 @@ set_kinematic(bool value) { set_collision_flag(btCollisionObject::CF_KINEMATIC_OBJECT, value); } -/** - * - */ -INLINE PN_stdfloat BulletBodyNode:: -get_restitution() const { - - return get_object()->getRestitution(); -} - -/** - * - */ -INLINE void BulletBodyNode:: -set_restitution(PN_stdfloat restitution) { - - return get_object()->setRestitution(restitution); -} - -/** - * - */ -INLINE PN_stdfloat BulletBodyNode:: -get_friction() const { - - return get_object()->getFriction(); -} - -/** - * - */ -INLINE void BulletBodyNode:: -set_friction(PN_stdfloat friction) { - - return get_object()->setFriction(friction); -} - -#if BT_BULLET_VERSION >= 281 -/** - * - */ -INLINE PN_stdfloat BulletBodyNode:: -get_rolling_friction() const { - - return get_object()->getRollingFriction(); -} - -/** - * - */ -INLINE void BulletBodyNode:: -set_rolling_friction(PN_stdfloat friction) { - - return get_object()->setRollingFriction(friction); -} -#endif - -/** - * - */ -INLINE bool BulletBodyNode:: -has_anisotropic_friction() const { - - return get_object()->hasAnisotropicFriction(); -} - -/** - * - */ -INLINE int BulletBodyNode:: -get_num_shapes() const { - - return _shapes.size(); -} - -/** - * - */ -INLINE BulletShape *BulletBodyNode:: -get_shape(int idx) const { - - nassertr(idx >= 0 && idx < (int)_shapes.size(), NULL); - return _shapes[idx]; -} - /** * Enables or disables the debug visualisation for this collision object. By * default the debug visualisation is enabled. diff --git a/panda/src/bullet/bulletBodyNode.cxx b/panda/src/bullet/bulletBodyNode.cxx index b078864ccc..f02641cd96 100644 --- a/panda/src/bullet/bulletBodyNode.cxx +++ b/panda/src/bullet/bulletBodyNode.cxx @@ -41,9 +41,11 @@ BulletBodyNode(const char *name) : PandaNode(name) { */ BulletBodyNode:: BulletBodyNode(const BulletBodyNode ©) : - PandaNode(copy), - _shapes(copy._shapes) + PandaNode(copy) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shapes = copy._shapes; if (copy._shape && copy._shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) { // btCompoundShape does not define a copy constructor. Manually copy. btCompoundShape *shape = new btCompoundShape; @@ -148,16 +150,168 @@ safe_to_flatten_below() const { * */ void BulletBodyNode:: -output(ostream &out) const { +do_output(ostream &out) const { PandaNode::output(out); - out << " (" << get_num_shapes() << " shapes)"; + out << " (" << _shapes.size() << " shapes)"; - out << (is_active() ? " active" : " inactive"); + out << (get_object()->isActive() ? " active" : " inactive"); - if (is_static()) out << " static"; - if (is_kinematic()) out << " kinematic"; + if (get_object()->isStaticObject()) out << " static"; + if (get_object()->isKinematicObject()) out << " kinematic"; +} + +/** + * + */ +void BulletBodyNode:: +output(ostream &out) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_output(out); +} + +/** + * + */ +void BulletBodyNode:: +set_collision_flag(int flag, bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + int flags = get_object()->getCollisionFlags(); + + if (value == true) { + flags |= flag; + } + else { + flags &= ~(flag); + } + + get_object()->setCollisionFlags(flags); +} + +/** + * + */ +bool BulletBodyNode:: +get_collision_flag(int flag) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (get_object()->getCollisionFlags() & flag) ? true : false; +} + +/** + * + */ +bool BulletBodyNode:: +is_static() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->isStaticObject(); +} + +/** + * + */ +bool BulletBodyNode:: +is_kinematic() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->isKinematicObject(); +} + +/** + * + */ +PN_stdfloat BulletBodyNode:: +get_restitution() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->getRestitution(); +} + +/** + * + */ +void BulletBodyNode:: +set_restitution(PN_stdfloat restitution) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->setRestitution(restitution); +} + +/** + * + */ +PN_stdfloat BulletBodyNode:: +get_friction() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->getFriction(); +} + +/** + * + */ +void BulletBodyNode:: +set_friction(PN_stdfloat friction) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->setFriction(friction); +} + +#if BT_BULLET_VERSION >= 281 +/** + * + */ +PN_stdfloat BulletBodyNode:: +get_rolling_friction() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->getRollingFriction(); +} + +/** + * + */ +void BulletBodyNode:: +set_rolling_friction(PN_stdfloat friction) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->setRollingFriction(friction); +} +#endif + +/** + * + */ +bool BulletBodyNode:: +has_anisotropic_friction() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return get_object()->hasAnisotropicFriction(); +} + +/** + * + */ +int BulletBodyNode:: +get_num_shapes() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _shapes.size(); +} + +/** + * + */ +BulletShape *BulletBodyNode:: +get_shape(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_shapes.size(), NULL); + return _shapes[idx]; } /** @@ -165,6 +319,16 @@ output(ostream &out) const { */ void BulletBodyNode:: add_shape(BulletShape *bullet_shape, const TransformState *ts) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_add_shape(bullet_shape, ts); +} + +/** + * Assumes the lock(bullet global lock) is held by the caller + */ +void BulletBodyNode:: +do_add_shape(BulletShape *bullet_shape, const TransformState *ts) { nassertv(get_object()); nassertv(ts); @@ -246,7 +410,7 @@ add_shape(BulletShape *bullet_shape, const TransformState *ts) { // Restore the local scaling again np.set_scale(scale); - shape_changed(); + do_shape_changed(); } /** @@ -254,6 +418,7 @@ add_shape(BulletShape *bullet_shape, const TransformState *ts) { */ void BulletBodyNode:: remove_shape(BulletShape *shape) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(get_object()); @@ -312,7 +477,7 @@ remove_shape(BulletShape *shape) { compound->removeChildShape(shape->ptr()); } - shape_changed(); + do_shape_changed(); } } @@ -333,6 +498,7 @@ is_identity(btTransform &trans) { */ LPoint3 BulletBodyNode:: get_shape_pos(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(idx >= 0 && idx < (int)_shapes.size(), LPoint3::zero()); @@ -352,14 +518,17 @@ get_shape_pos(int idx) const { */ LMatrix4 BulletBodyNode:: get_shape_mat(int idx) const { - return get_shape_transform(idx)->get_mat(); + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_shape_transform(idx)->get_mat(); } /** * */ CPT(TransformState) BulletBodyNode:: -get_shape_transform(int idx) const { +do_get_shape_transform(int idx) const { + nassertr(idx >= 0 && idx < (int)_shapes.size(), TransformState::make_identity()); btCollisionShape *root = get_object()->getCollisionShape(); @@ -386,13 +555,25 @@ get_shape_transform(int idx) const { return TransformState::make_identity(); } +/** + * + */ +CPT(TransformState) BulletBodyNode:: +get_shape_transform(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_shape_transform(idx); +} + + /** * Hook which will be called whenever the total shape of a body changed. Used * for example to update the mass properties (inertia) of a rigid body. The * default implementation does nothing. + * Assumes the lock(bullet global lock) is held */ void BulletBodyNode:: -shape_changed() { +do_shape_changed() { } @@ -401,6 +582,7 @@ shape_changed() { */ void BulletBodyNode:: set_deactivation_time(PN_stdfloat dt) { + LightMutexHolder holder(BulletWorld::get_global_lock()); get_object()->setDeactivationTime(dt); } @@ -410,6 +592,7 @@ set_deactivation_time(PN_stdfloat dt) { */ PN_stdfloat BulletBodyNode:: get_deactivation_time() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->getDeactivationTime(); } @@ -419,6 +602,7 @@ get_deactivation_time() const { */ bool BulletBodyNode:: is_active() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->isActive(); } @@ -428,6 +612,7 @@ is_active() const { */ void BulletBodyNode:: set_active(bool active, bool force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); if (active) { get_object()->activate(force); @@ -457,10 +642,12 @@ force_active(bool active) { */ void BulletBodyNode:: set_deactivation_enabled(bool enabled) { + LightMutexHolder holder(BulletWorld::get_global_lock()); // Don't change the state if it's currently active and we enable // deactivation. - if (enabled != is_deactivation_enabled()) { + bool is_enabled = get_object()->getActivationState() != DISABLE_DEACTIVATION; + if (enabled != is_enabled) { // It's OK to set to ACTIVE_TAG even if we don't mean to activate it; it // will be disabled right away if the deactivation timer has run out. @@ -474,6 +661,7 @@ set_deactivation_enabled(bool enabled) { */ bool BulletBodyNode:: is_deactivation_enabled() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (get_object()->getActivationState() != DISABLE_DEACTIVATION); } @@ -483,6 +671,7 @@ is_deactivation_enabled() const { */ bool BulletBodyNode:: check_collision_with(PandaNode *node) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btCollisionObject *obj = BulletWorld::get_collision_object(node); @@ -499,6 +688,7 @@ check_collision_with(PandaNode *node) { */ LVecBase3 BulletBodyNode:: get_anisotropic_friction() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVecBase3(get_object()->getAnisotropicFriction()); } @@ -508,6 +698,7 @@ get_anisotropic_friction() const { */ void BulletBodyNode:: set_anisotropic_friction(const LVecBase3 &friction) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!friction.is_nan()); get_object()->setAnisotropicFriction(LVecBase3_to_btVector3(friction)); @@ -518,6 +709,7 @@ set_anisotropic_friction(const LVecBase3 &friction) { */ bool BulletBodyNode:: has_contact_response() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->hasContactResponse(); } @@ -527,7 +719,8 @@ has_contact_response() const { */ PN_stdfloat BulletBodyNode:: get_contact_processing_threshold() const { - + LightMutexHolder holder(BulletWorld::get_global_lock()); + return get_object()->getContactProcessingThreshold(); } @@ -537,6 +730,7 @@ get_contact_processing_threshold() const { */ void BulletBodyNode:: set_contact_processing_threshold(PN_stdfloat threshold) { + LightMutexHolder holder(BulletWorld::get_global_lock()); get_object()->setContactProcessingThreshold(threshold); } @@ -546,6 +740,7 @@ set_contact_processing_threshold(PN_stdfloat threshold) { */ PN_stdfloat BulletBodyNode:: get_ccd_swept_sphere_radius() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->getCcdSweptSphereRadius(); } @@ -555,6 +750,7 @@ get_ccd_swept_sphere_radius() const { */ void BulletBodyNode:: set_ccd_swept_sphere_radius(PN_stdfloat radius) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->setCcdSweptSphereRadius(radius); } @@ -564,6 +760,7 @@ set_ccd_swept_sphere_radius(PN_stdfloat radius) { */ PN_stdfloat BulletBodyNode:: get_ccd_motion_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->getCcdMotionThreshold(); } @@ -573,6 +770,7 @@ get_ccd_motion_threshold() const { */ void BulletBodyNode:: set_ccd_motion_threshold(PN_stdfloat threshold) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return get_object()->setCcdMotionThreshold(threshold); } @@ -582,6 +780,7 @@ set_ccd_motion_threshold(PN_stdfloat threshold) { */ void BulletBodyNode:: add_shapes_from_collision_solids(CollisionNode *cnode) { + LightMutexHolder holder(BulletWorld::get_global_lock()); PT(BulletTriangleMesh) mesh = NULL; @@ -594,7 +793,7 @@ add_shapes_from_collision_solids(CollisionNode *cnode) { CPT(CollisionSphere) sphere = DCAST(CollisionSphere, solid); CPT(TransformState) ts = TransformState::make_pos(sphere->get_center()); - add_shape(BulletSphereShape::make_from_solid(sphere), ts); + do_add_shape(BulletSphereShape::make_from_solid(sphere), ts); } // CollisionBox @@ -602,14 +801,14 @@ add_shapes_from_collision_solids(CollisionNode *cnode) { CPT(CollisionBox) box = DCAST(CollisionBox, solid); CPT(TransformState) ts = TransformState::make_pos(box->get_center()); - add_shape(BulletBoxShape::make_from_solid(box), ts); + do_add_shape(BulletBoxShape::make_from_solid(box), ts); } // CollisionPlane else if (CollisionPlane::get_class_type() == type) { CPT(CollisionPlane) plane = DCAST(CollisionPlane, solid); - add_shape(BulletPlaneShape::make_from_solid(plane)); + do_add_shape(BulletPlaneShape::make_from_solid(plane)); } // CollisionGeom @@ -625,13 +824,13 @@ add_shapes_from_collision_solids(CollisionNode *cnode) { LPoint3 p2 = polygon->get_point(i-1); LPoint3 p3 = polygon->get_point(i); - mesh->add_triangle(p1, p2, p3, true); + mesh->do_add_triangle(p1, p2, p3, true); } } } - if (mesh && mesh->get_num_triangles() > 0) { - add_shape(new BulletTriangleMeshShape(mesh, true)); + if (mesh && mesh->do_get_num_triangles() > 0) { + do_add_shape(new BulletTriangleMeshShape(mesh, true)); } } @@ -651,6 +850,7 @@ set_transform_dirty() { */ BoundingSphere BulletBodyNode:: get_shape_bounds() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); /* btTransform tr; diff --git a/panda/src/bullet/bulletBodyNode.h b/panda/src/bullet/bulletBodyNode.h index 562e88c7fb..55f8583938 100644 --- a/panda/src/bullet/bulletBodyNode.h +++ b/panda/src/bullet/bulletBodyNode.h @@ -42,8 +42,8 @@ PUBLISHED: void add_shape(BulletShape *shape, const TransformState *xform=TransformState::make_identity()); void remove_shape(BulletShape *shape); - INLINE int get_num_shapes() const; - INLINE BulletShape *get_shape(int idx) const; + int get_num_shapes() const; + BulletShape *get_shape(int idx) const; MAKE_SEQ(get_shapes, get_num_shapes, get_shape); LPoint3 get_shape_pos(int idx) const; @@ -54,8 +54,8 @@ PUBLISHED: void add_shapes_from_collision_solids(CollisionNode *cnode); // Static and kinematic - INLINE bool is_static() const; - INLINE bool is_kinematic() const; + bool is_static() const; + bool is_kinematic() const; INLINE void set_static(bool value); INLINE void set_kinematic(bool value); @@ -92,19 +92,19 @@ PUBLISHED: INLINE bool is_debug_enabled() const; // Friction and Restitution - INLINE PN_stdfloat get_restitution() const; - INLINE void set_restitution(PN_stdfloat restitution); + PN_stdfloat get_restitution() const; + void set_restitution(PN_stdfloat restitution); - INLINE PN_stdfloat get_friction() const; - INLINE void set_friction(PN_stdfloat friction); + PN_stdfloat get_friction() const; + void set_friction(PN_stdfloat friction); #if BT_BULLET_VERSION >= 281 - INLINE PN_stdfloat get_rolling_friction() const; - INLINE void set_rolling_friction(PN_stdfloat friction); + PN_stdfloat get_rolling_friction() const; + void set_rolling_friction(PN_stdfloat friction); MAKE_PROPERTY(rolling_friction, get_rolling_friction, set_rolling_friction); #endif - INLINE bool has_anisotropic_friction() const; + bool has_anisotropic_friction() const; void set_anisotropic_friction(const LVecBase3 &friction); LVecBase3 get_anisotropic_friction() const; @@ -151,10 +151,11 @@ public: virtual bool safe_to_flatten_below() const; virtual void output(ostream &out) const; + virtual void do_output(ostream &out) const; protected: - INLINE void set_collision_flag(int flag, bool value); - INLINE bool get_collision_flag(int flag) const; + void set_collision_flag(int flag, bool value); + bool get_collision_flag(int flag) const; btCollisionShape *_shape; @@ -162,7 +163,9 @@ protected: BulletShapes _shapes; private: - virtual void shape_changed(); + virtual void do_shape_changed(); + void do_add_shape(BulletShape *shape, const TransformState *xform=TransformState::make_identity()); + CPT(TransformState) do_get_shape_transform(int idx) const; static bool is_identity(btTransform &trans); diff --git a/panda/src/bullet/bulletBoxShape.I b/panda/src/bullet/bulletBoxShape.I index 384aace8b6..f432db4a69 100644 --- a/panda/src/bullet/bulletBoxShape.I +++ b/panda/src/bullet/bulletBoxShape.I @@ -28,20 +28,3 @@ INLINE BulletBoxShape:: delete _shape; } - -/** - * - */ -INLINE BulletBoxShape:: -BulletBoxShape(const BulletBoxShape ©) : - _shape(copy._shape), _half_extents(copy._half_extents) { -} - -/** - * - */ -INLINE void BulletBoxShape:: -operator = (const BulletBoxShape ©) { - _shape = copy._shape; - _half_extents = copy._half_extents; -} diff --git a/panda/src/bullet/bulletBoxShape.cxx b/panda/src/bullet/bulletBoxShape.cxx index f523184993..9ae2e16a11 100644 --- a/panda/src/bullet/bulletBoxShape.cxx +++ b/panda/src/bullet/bulletBoxShape.cxx @@ -28,6 +28,28 @@ BulletBoxShape(const LVecBase3 &halfExtents) : _half_extents(halfExtents) { _shape->setUserPointer(this); } +/** + * + */ +BulletBoxShape:: +BulletBoxShape(const BulletBoxShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _half_extents = copy._half_extents; +} + +/** + * + */ +void BulletBoxShape:: +operator = (const BulletBoxShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _half_extents = copy._half_extents; +} + /** * */ @@ -42,6 +64,7 @@ ptr() const { */ LVecBase3 BulletBoxShape:: get_half_extents_without_margin() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVecBase3(_shape->getHalfExtentsWithoutMargin()); } @@ -51,6 +74,7 @@ get_half_extents_without_margin() const { */ LVecBase3 BulletBoxShape:: get_half_extents_with_margin() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVecBase3(_shape->getHalfExtentsWithMargin()); } diff --git a/panda/src/bullet/bulletBoxShape.h b/panda/src/bullet/bulletBoxShape.h index d7fa1c5169..bfb9207e61 100644 --- a/panda/src/bullet/bulletBoxShape.h +++ b/panda/src/bullet/bulletBoxShape.h @@ -33,8 +33,8 @@ private: PUBLISHED: explicit BulletBoxShape(const LVecBase3 &halfExtents); - INLINE BulletBoxShape(const BulletBoxShape ©); - INLINE void operator = (const BulletBoxShape ©); + BulletBoxShape(const BulletBoxShape ©); + void operator = (const BulletBoxShape ©); INLINE ~BulletBoxShape(); LVecBase3 get_half_extents_without_margin() const; diff --git a/panda/src/bullet/bulletCapsuleShape.I b/panda/src/bullet/bulletCapsuleShape.I index feb6cdff57..2491d55d0d 100644 --- a/panda/src/bullet/bulletCapsuleShape.I +++ b/panda/src/bullet/bulletCapsuleShape.I @@ -30,26 +30,6 @@ INLINE BulletCapsuleShape:: delete _shape; } -/** - * - */ -INLINE BulletCapsuleShape:: -BulletCapsuleShape(const BulletCapsuleShape ©) : - _shape(copy._shape), - _radius(copy._radius), - _height(copy._height) { -} - -/** - * - */ -INLINE void BulletCapsuleShape:: -operator = (const BulletCapsuleShape ©) { - _shape = copy._shape; - _radius = copy._radius; - _height = copy._height; -} - /** * Returns the radius that was used to construct this capsule. */ diff --git a/panda/src/bullet/bulletCapsuleShape.cxx b/panda/src/bullet/bulletCapsuleShape.cxx index 9f389985e3..1c396bbdfb 100644 --- a/panda/src/bullet/bulletCapsuleShape.cxx +++ b/panda/src/bullet/bulletCapsuleShape.cxx @@ -38,9 +38,35 @@ BulletCapsuleShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) : break; } + nassertv(_shape); _shape->setUserPointer(this); } +/** + * + */ +BulletCapsuleShape:: +BulletCapsuleShape(const BulletCapsuleShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; + _height = copy._height; +} + +/** + * + */ +void BulletCapsuleShape:: +operator = (const BulletCapsuleShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; + _height = copy._height; +} + + /** * */ @@ -122,6 +148,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { break; } + nassertv(_shape); _shape->setUserPointer(this); _shape->setMargin(margin); } diff --git a/panda/src/bullet/bulletCapsuleShape.h b/panda/src/bullet/bulletCapsuleShape.h index 5b031cc548..e376674976 100644 --- a/panda/src/bullet/bulletCapsuleShape.h +++ b/panda/src/bullet/bulletCapsuleShape.h @@ -30,8 +30,8 @@ private: PUBLISHED: explicit BulletCapsuleShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up); - INLINE BulletCapsuleShape(const BulletCapsuleShape ©); - INLINE void operator = (const BulletCapsuleShape ©); + BulletCapsuleShape(const BulletCapsuleShape ©); + void operator = (const BulletCapsuleShape ©); INLINE ~BulletCapsuleShape(); INLINE PN_stdfloat get_radius() const; diff --git a/panda/src/bullet/bulletCharacterControllerNode.I b/panda/src/bullet/bulletCharacterControllerNode.I index 391e387e67..8017857312 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.I +++ b/panda/src/bullet/bulletCharacterControllerNode.I @@ -17,6 +17,8 @@ INLINE BulletCharacterControllerNode:: ~BulletCharacterControllerNode() { + delete _character; + delete _ghost; } /** diff --git a/panda/src/bullet/bulletCharacterControllerNode.cxx b/panda/src/bullet/bulletCharacterControllerNode.cxx index c6af3842e9..d65948a824 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.cxx +++ b/panda/src/bullet/bulletCharacterControllerNode.cxx @@ -77,6 +77,7 @@ BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const */ void BulletCharacterControllerNode:: set_linear_movement(const LVector3 &movement, bool is_local) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!movement.is_nan()); @@ -89,18 +90,19 @@ set_linear_movement(const LVector3 &movement, bool is_local) { */ void BulletCharacterControllerNode:: set_angular_movement(PN_stdfloat omega) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _angular_movement = omega; } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletCharacterControllerNode:: -sync_p2b(PN_stdfloat dt, int num_substeps) { +do_sync_p2b(PN_stdfloat dt, int num_substeps) { // Synchronise global transform - transform_changed(); + do_transform_changed(); // Angular rotation btScalar angle = dt * deg_2_rad(_angular_movement); @@ -131,10 +133,10 @@ sync_p2b(PN_stdfloat dt, int num_substeps) { } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletCharacterControllerNode:: -sync_b2p() { +do_sync_b2p() { NodePath np = NodePath::any_path((PandaNode *)this); LVecBase3 scale = np.get_net_transform()->get_scale(); @@ -154,10 +156,10 @@ sync_b2p() { } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletCharacterControllerNode:: -transform_changed() { +do_transform_changed() { if (_sync_disable) return; @@ -187,10 +189,23 @@ transform_changed() { _ghost->getWorldTransform().setBasis(m); // Set scale - _shape->set_local_scale(scale); + _shape->do_set_local_scale(scale); } } +/** + * + */ +void BulletCharacterControllerNode:: +transform_changed() { + + if (_sync_disable) return; + + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_transform_changed(); +} + /** * */ @@ -205,6 +220,7 @@ get_shape() const { */ bool BulletCharacterControllerNode:: is_on_ground() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _character->onGround(); } @@ -214,6 +230,7 @@ is_on_ground() const { */ bool BulletCharacterControllerNode:: can_jump() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _character->canJump(); } @@ -223,6 +240,7 @@ can_jump() const { */ void BulletCharacterControllerNode:: do_jump() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _character->jump(); } @@ -232,6 +250,7 @@ do_jump() { */ void BulletCharacterControllerNode:: set_fall_speed(PN_stdfloat fall_speed) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _character->setFallSpeed((btScalar)fall_speed); } @@ -241,6 +260,7 @@ set_fall_speed(PN_stdfloat fall_speed) { */ void BulletCharacterControllerNode:: set_jump_speed(PN_stdfloat jump_speed) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _character->setJumpSpeed((btScalar)jump_speed); } @@ -250,6 +270,7 @@ set_jump_speed(PN_stdfloat jump_speed) { */ void BulletCharacterControllerNode:: set_max_jump_height(PN_stdfloat max_jump_height) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _character->setMaxJumpHeight((btScalar)max_jump_height); } @@ -259,6 +280,7 @@ set_max_jump_height(PN_stdfloat max_jump_height) { */ void BulletCharacterControllerNode:: set_max_slope(PN_stdfloat max_slope) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _character->setMaxSlope((btScalar)max_slope); } @@ -268,6 +290,7 @@ set_max_slope(PN_stdfloat max_slope) { */ PN_stdfloat BulletCharacterControllerNode:: get_max_slope() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_character->getMaxSlope(); } @@ -277,6 +300,8 @@ get_max_slope() const { */ PN_stdfloat BulletCharacterControllerNode:: get_gravity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + #if BT_BULLET_VERSION >= 285 return -(PN_stdfloat)_character->getGravity()[_up]; #else @@ -289,6 +314,8 @@ get_gravity() const { */ void BulletCharacterControllerNode:: set_gravity(PN_stdfloat gravity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + #if BT_BULLET_VERSION >= 285 _character->setGravity(up_vectors[_up] * -(btScalar)gravity); #else @@ -301,6 +328,7 @@ set_gravity(PN_stdfloat gravity) { */ void BulletCharacterControllerNode:: set_use_ghost_sweep_test(bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _character->setUseGhostSweepTest(value); -} \ No newline at end of file +} diff --git a/panda/src/bullet/bulletCharacterControllerNode.h b/panda/src/bullet/bulletCharacterControllerNode.h index 0b8574c709..b2c43d8bb4 100644 --- a/panda/src/bullet/bulletCharacterControllerNode.h +++ b/panda/src/bullet/bulletCharacterControllerNode.h @@ -64,8 +64,8 @@ public: INLINE virtual btPairCachingGhostObject *get_ghost() const; INLINE virtual btCharacterControllerInterface *get_character() const; - virtual void sync_p2b(PN_stdfloat dt, int num_substeps); - virtual void sync_b2p(); + virtual void do_sync_p2b(PN_stdfloat dt, int num_substeps); + virtual void do_sync_b2p(); protected: virtual void transform_changed(); @@ -85,6 +85,8 @@ private: bool _linear_movement_is_local; PN_stdfloat _angular_movement; + void do_transform_changed(); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/bullet/bulletConeShape.I b/panda/src/bullet/bulletConeShape.I index bf618a862b..b9c05664b7 100644 --- a/panda/src/bullet/bulletConeShape.I +++ b/panda/src/bullet/bulletConeShape.I @@ -30,26 +30,6 @@ INLINE BulletConeShape:: delete _shape; } -/** - * - */ -INLINE BulletConeShape:: -BulletConeShape(const BulletConeShape ©) : - _shape(copy._shape), - _radius(copy._radius), - _height(copy._height) { -} - -/** - * - */ -INLINE void BulletConeShape:: -operator = (const BulletConeShape ©) { - _shape = copy._shape; - _radius = copy._radius; - _height = copy._height; -} - /** * Returns the radius that was passed into the constructor. */ diff --git a/panda/src/bullet/bulletConeShape.cxx b/panda/src/bullet/bulletConeShape.cxx index 80e91a038f..30b24a5a18 100644 --- a/panda/src/bullet/bulletConeShape.cxx +++ b/panda/src/bullet/bulletConeShape.cxx @@ -38,9 +38,34 @@ BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) : break; } + nassertv(_shape); _shape->setUserPointer(this); } +/** + * + */ +BulletConeShape:: +BulletConeShape(const BulletConeShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; + _height = copy._height; +} + +/** + * + */ +void BulletConeShape:: +operator = (const BulletConeShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; + _height = copy._height; +} + /** * */ @@ -122,6 +147,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { break; } + nassertv(_shape); _shape->setUserPointer(this); _shape->setMargin(margin); } diff --git a/panda/src/bullet/bulletConeShape.h b/panda/src/bullet/bulletConeShape.h index 081367449b..4d40c61da9 100644 --- a/panda/src/bullet/bulletConeShape.h +++ b/panda/src/bullet/bulletConeShape.h @@ -30,8 +30,8 @@ private: PUBLISHED: explicit BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up); - INLINE BulletConeShape(const BulletConeShape ©); - INLINE void operator = (const BulletConeShape ©); + BulletConeShape(const BulletConeShape ©); + void operator = (const BulletConeShape ©); INLINE ~BulletConeShape(); INLINE PN_stdfloat get_radius() const; diff --git a/panda/src/bullet/bulletConeTwistConstraint.I b/panda/src/bullet/bulletConeTwistConstraint.I index a29277462d..9f50b20783 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.I +++ b/panda/src/bullet/bulletConeTwistConstraint.I @@ -19,21 +19,3 @@ INLINE BulletConeTwistConstraint:: delete _constraint; } - -/** - * - */ -INLINE CPT(TransformState) BulletConeTwistConstraint:: -get_frame_a() const { - - return btTrans_to_TransformState(_constraint->getAFrame()); -} - -/** - * - */ -INLINE CPT(TransformState) BulletConeTwistConstraint:: -get_frame_b() const { - - return btTrans_to_TransformState(_constraint->getBFrame()); -} diff --git a/panda/src/bullet/bulletConeTwistConstraint.cxx b/panda/src/bullet/bulletConeTwistConstraint.cxx index 93505b33fc..9b60ab31ce 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.cxx +++ b/panda/src/bullet/bulletConeTwistConstraint.cxx @@ -63,6 +63,7 @@ ptr() const { */ void BulletConeTwistConstraint:: set_limit(int index, PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); value = deg_2_rad(value); @@ -74,6 +75,7 @@ set_limit(int index, PN_stdfloat value) { */ void BulletConeTwistConstraint:: set_limit(PN_stdfloat swing1, PN_stdfloat swing2, PN_stdfloat twist, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) { + LightMutexHolder holder(BulletWorld::get_global_lock()); swing1 = deg_2_rad(swing1); swing2 = deg_2_rad(swing2); @@ -87,6 +89,7 @@ set_limit(PN_stdfloat swing1, PN_stdfloat swing2, PN_stdfloat twist, PN_stdfloat */ void BulletConeTwistConstraint:: set_damping(PN_stdfloat damping) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setDamping(damping); } @@ -96,6 +99,7 @@ set_damping(PN_stdfloat damping) { */ PN_stdfloat BulletConeTwistConstraint:: get_fix_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _constraint->getFixThresh(); } @@ -105,6 +109,7 @@ get_fix_threshold() const { */ void BulletConeTwistConstraint:: set_fix_threshold(PN_stdfloat threshold) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setFixThresh(threshold); } @@ -114,6 +119,7 @@ set_fix_threshold(PN_stdfloat threshold) { */ void BulletConeTwistConstraint:: enable_motor(bool enable) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->enableMotor(enable); } @@ -123,6 +129,7 @@ enable_motor(bool enable) { */ void BulletConeTwistConstraint:: set_max_motor_impulse(PN_stdfloat max_impulse) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMaxMotorImpulse(max_impulse); } @@ -132,6 +139,7 @@ set_max_motor_impulse(PN_stdfloat max_impulse) { */ void BulletConeTwistConstraint:: set_max_motor_impulse_normalized(PN_stdfloat max_impulse) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMaxMotorImpulseNormalized(max_impulse); } @@ -141,6 +149,7 @@ set_max_motor_impulse_normalized(PN_stdfloat max_impulse) { */ void BulletConeTwistConstraint:: set_motor_target(const LQuaternion &quat) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMotorTarget(LQuaternion_to_btQuat(quat)); } @@ -150,6 +159,7 @@ set_motor_target(const LQuaternion &quat) { */ void BulletConeTwistConstraint:: set_motor_target_in_constraint_space(const LQuaternion &quat) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMotorTargetInConstraintSpace(LQuaternion_to_btQuat(quat)); } @@ -159,9 +169,30 @@ set_motor_target_in_constraint_space(const LQuaternion &quat) { */ void BulletConeTwistConstraint:: set_frames(const TransformState *ts_a, const TransformState *ts_b) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btTransform frame_a = TransformState_to_btTrans(ts_a); btTransform frame_b = TransformState_to_btTrans(ts_b); _constraint->setFrames(frame_a, frame_b); } + +/** + * + */ +CPT(TransformState) BulletConeTwistConstraint:: +get_frame_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getAFrame()); +} + +/** + * + */ +CPT(TransformState) BulletConeTwistConstraint:: +get_frame_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getBFrame()); +} diff --git a/panda/src/bullet/bulletConeTwistConstraint.h b/panda/src/bullet/bulletConeTwistConstraint.h index bc4f548dfb..d7fabee508 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.h +++ b/panda/src/bullet/bulletConeTwistConstraint.h @@ -53,8 +53,8 @@ PUBLISHED: void set_motor_target_in_constraint_space(const LQuaternion &quat); void set_frames(const TransformState *ts_a, const TransformState *ts_b); - INLINE CPT(TransformState) get_frame_a() const; - INLINE CPT(TransformState) get_frame_b() const; + CPT(TransformState) get_frame_a() const; + CPT(TransformState) get_frame_b() const; MAKE_PROPERTY(fix_threshold, get_fix_threshold, set_fix_threshold); MAKE_PROPERTY(frame_a, get_frame_a); diff --git a/panda/src/bullet/bulletConvexHullShape.I b/panda/src/bullet/bulletConvexHullShape.I index 71fa3cd190..2016b38e4d 100644 --- a/panda/src/bullet/bulletConvexHullShape.I +++ b/panda/src/bullet/bulletConvexHullShape.I @@ -19,19 +19,3 @@ INLINE BulletConvexHullShape:: delete _shape; } - -/** - * - */ -INLINE BulletConvexHullShape:: -BulletConvexHullShape(const BulletConvexHullShape ©) : - _shape(copy._shape) { -} - -/** - * - */ -INLINE void BulletConvexHullShape:: -operator = (const BulletConvexHullShape ©) { - _shape = copy._shape; -} diff --git a/panda/src/bullet/bulletConvexHullShape.cxx b/panda/src/bullet/bulletConvexHullShape.cxx index 9b3df8dfe2..c796072b4a 100644 --- a/panda/src/bullet/bulletConvexHullShape.cxx +++ b/panda/src/bullet/bulletConvexHullShape.cxx @@ -29,6 +29,26 @@ BulletConvexHullShape() { _shape->setUserPointer(this); } +/** + * + */ +BulletConvexHullShape:: +BulletConvexHullShape(const BulletConvexHullShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + +/** + * + */ +void BulletConvexHullShape:: +operator = (const BulletConvexHullShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + /** * */ @@ -43,6 +63,7 @@ ptr() const { */ void BulletConvexHullShape:: add_point(const LPoint3 &p) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _shape->addPoint(LVecBase3_to_btVector3(p)); } @@ -52,6 +73,10 @@ add_point(const LPoint3 &p) { */ void BulletConvexHullShape:: add_array(const PTA_LVecBase3 &points) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + if (_shape) + delete _shape; _shape = new btConvexHullShape(NULL, 0); _shape->setUserPointer(this); @@ -75,6 +100,7 @@ add_array(const PTA_LVecBase3 &points) { */ void BulletConvexHullShape:: add_geom(const Geom *geom, const TransformState *ts) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(geom); nassertv(ts); diff --git a/panda/src/bullet/bulletConvexHullShape.h b/panda/src/bullet/bulletConvexHullShape.h index f74489bd0e..653c044952 100644 --- a/panda/src/bullet/bulletConvexHullShape.h +++ b/panda/src/bullet/bulletConvexHullShape.h @@ -29,8 +29,8 @@ class EXPCL_PANDABULLET BulletConvexHullShape : public BulletShape { PUBLISHED: BulletConvexHullShape(); - INLINE BulletConvexHullShape(const BulletConvexHullShape ©); - INLINE void operator = (const BulletConvexHullShape ©); + BulletConvexHullShape(const BulletConvexHullShape ©); + void operator = (const BulletConvexHullShape ©); INLINE ~BulletConvexHullShape(); void add_point(const LPoint3 &p); diff --git a/panda/src/bullet/bulletConvexPointCloudShape.I b/panda/src/bullet/bulletConvexPointCloudShape.I index 909dfd2d7e..47e0b62704 100644 --- a/panda/src/bullet/bulletConvexPointCloudShape.I +++ b/panda/src/bullet/bulletConvexPointCloudShape.I @@ -28,30 +28,3 @@ INLINE BulletConvexPointCloudShape:: delete _shape; } - -/** - * - */ -INLINE BulletConvexPointCloudShape:: -BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©) : - _scale(copy._scale), - _shape(copy._shape) { -} - -/** - * - */ -INLINE void BulletConvexPointCloudShape:: -operator = (const BulletConvexPointCloudShape ©) { - _scale = copy._scale; - _shape = copy._shape; -} - -/** - * - */ -INLINE int BulletConvexPointCloudShape:: -get_num_points() const { - - return _shape->getNumPoints(); -} diff --git a/panda/src/bullet/bulletConvexPointCloudShape.cxx b/panda/src/bullet/bulletConvexPointCloudShape.cxx index 1527a712b3..fb7f62287b 100644 --- a/panda/src/bullet/bulletConvexPointCloudShape.cxx +++ b/panda/src/bullet/bulletConvexPointCloudShape.cxx @@ -84,6 +84,38 @@ BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale) { _shape->setUserPointer(this); } +/** + * + */ +BulletConvexPointCloudShape:: +BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _scale = copy._scale; + _shape = copy._shape; +} + +/** + * + */ +void BulletConvexPointCloudShape:: +operator = (const BulletConvexPointCloudShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _scale = copy._scale; + _shape = copy._shape; +} + +/** + * + */ +int BulletConvexPointCloudShape:: +get_num_points() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _shape->getNumPoints(); +} + /** * Tells the BamReader how to create objects of type BulletShape. */ diff --git a/panda/src/bullet/bulletConvexPointCloudShape.h b/panda/src/bullet/bulletConvexPointCloudShape.h index 293ece996b..da403d8794 100644 --- a/panda/src/bullet/bulletConvexPointCloudShape.h +++ b/panda/src/bullet/bulletConvexPointCloudShape.h @@ -33,11 +33,11 @@ private: PUBLISHED: explicit BulletConvexPointCloudShape(const PTA_LVecBase3 &points, LVecBase3 scale=LVecBase3(1.)); explicit BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale=LVecBase3(1.)); - INLINE BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©); - INLINE void operator = (const BulletConvexPointCloudShape ©); + BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©); + void operator = (const BulletConvexPointCloudShape ©); INLINE ~BulletConvexPointCloudShape(); - INLINE int get_num_points() const; + int get_num_points() const; MAKE_PROPERTY(num_points, get_num_points); diff --git a/panda/src/bullet/bulletCylinderShape.I b/panda/src/bullet/bulletCylinderShape.I index c389813444..54616905f9 100644 --- a/panda/src/bullet/bulletCylinderShape.I +++ b/panda/src/bullet/bulletCylinderShape.I @@ -28,47 +28,3 @@ INLINE BulletCylinderShape:: delete _shape; } - -/** - * - */ -INLINE BulletCylinderShape:: -BulletCylinderShape(const BulletCylinderShape ©) : - _shape(copy._shape), _half_extents(copy._half_extents) { -} - -/** - * - */ -INLINE void BulletCylinderShape:: -operator = (const BulletCylinderShape ©) { - _shape = copy._shape; - _half_extents = copy._half_extents; -} - -/** - * - */ -INLINE PN_stdfloat BulletCylinderShape:: -get_radius() const { - - return (PN_stdfloat)_shape->getRadius(); -} - -/** - * - */ -INLINE LVecBase3 BulletCylinderShape:: -get_half_extents_without_margin() const { - - return btVector3_to_LVecBase3(_shape->getHalfExtentsWithoutMargin()); -} - -/** - * - */ -INLINE LVecBase3 BulletCylinderShape:: -get_half_extents_with_margin() const { - - return btVector3_to_LVecBase3(_shape->getHalfExtentsWithMargin()); -} diff --git a/panda/src/bullet/bulletCylinderShape.cxx b/panda/src/bullet/bulletCylinderShape.cxx index fec07ce484..8f95bc5591 100644 --- a/panda/src/bullet/bulletCylinderShape.cxx +++ b/panda/src/bullet/bulletCylinderShape.cxx @@ -39,6 +39,7 @@ BulletCylinderShape(const LVector3 &half_extents, BulletUpAxis up) : break; } + nassertv(_shape); _shape->setUserPointer(this); } @@ -66,9 +67,32 @@ BulletCylinderShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) { break; } + nassertv(_shape); _shape->setUserPointer(this); } +/** + * + */ +BulletCylinderShape:: +BulletCylinderShape(const BulletCylinderShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _half_extents = copy._half_extents; +} + +/** + * + */ +void BulletCylinderShape:: +operator = (const BulletCylinderShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _half_extents = copy._half_extents; +} + /** * */ @@ -78,6 +102,36 @@ ptr() const { return _shape; } +/** + * + */ +PN_stdfloat BulletCylinderShape:: +get_radius() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_shape->getRadius(); +} + +/** + * + */ +LVecBase3 BulletCylinderShape:: +get_half_extents_without_margin() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVecBase3(_shape->getHalfExtentsWithoutMargin()); +} + +/** + * + */ +LVecBase3 BulletCylinderShape:: +get_half_extents_with_margin() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVecBase3(_shape->getHalfExtentsWithMargin()); +} + /** * Tells the BamReader how to create objects of type BulletShape. */ @@ -150,6 +204,7 @@ fillin(DatagramIterator &scan, BamReader *manager) { break; } + nassertv(_shape); _shape->setUserPointer(this); _shape->setMargin(margin); } diff --git a/panda/src/bullet/bulletCylinderShape.h b/panda/src/bullet/bulletCylinderShape.h index 2cdd854ac4..f53962ec6f 100644 --- a/panda/src/bullet/bulletCylinderShape.h +++ b/panda/src/bullet/bulletCylinderShape.h @@ -31,13 +31,13 @@ private: PUBLISHED: explicit BulletCylinderShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up); explicit BulletCylinderShape(const LVector3 &half_extents, BulletUpAxis up=Z_up); - INLINE BulletCylinderShape(const BulletCylinderShape ©); - INLINE void operator = (const BulletCylinderShape ©); + BulletCylinderShape(const BulletCylinderShape ©); + void operator = (const BulletCylinderShape ©); INLINE ~BulletCylinderShape(); - INLINE PN_stdfloat get_radius() const; - INLINE LVecBase3 get_half_extents_without_margin() const; - INLINE LVecBase3 get_half_extents_with_margin() const; + PN_stdfloat get_radius() const; + LVecBase3 get_half_extents_without_margin() const; + LVecBase3 get_half_extents_with_margin() const; MAKE_PROPERTY(radius, get_radius); MAKE_PROPERTY(half_extents_without_margin, get_half_extents_without_margin); diff --git a/panda/src/bullet/bulletDebugNode.cxx b/panda/src/bullet/bulletDebugNode.cxx index 9b8c9c0bfb..743b5163ff 100644 --- a/panda/src/bullet/bulletDebugNode.cxx +++ b/panda/src/bullet/bulletDebugNode.cxx @@ -169,7 +169,7 @@ add_for_draw(CullTraverser *trav, CullTraverserData &data) { PT(Geom) debug_triangles; { - LightMutexHolder holder(_lock); + LightMutexHolder holder(BulletWorld::get_global_lock()); if (_debug_world == nullptr) { return; } @@ -270,8 +270,7 @@ add_for_draw(CullTraverser *trav, CullTraverserData &data) { * */ void BulletDebugNode:: -sync_b2p(btDynamicsWorld *world) { - LightMutexHolder holder(_lock); +do_sync_b2p(btDynamicsWorld *world) { _debug_world = world; _debug_stale = true; diff --git a/panda/src/bullet/bulletDebugNode.h b/panda/src/bullet/bulletDebugNode.h index dabe9d13fa..c780429a79 100644 --- a/panda/src/bullet/bulletDebugNode.h +++ b/panda/src/bullet/bulletDebugNode.h @@ -17,7 +17,6 @@ #include "pandabase.h" #include "bullet_includes.h" -#include "lightMutex.h" /** * @@ -55,7 +54,7 @@ public: virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data); private: - void sync_b2p(btDynamicsWorld *world); + void do_sync_b2p(btDynamicsWorld *world); struct Line { LVecBase3 _p0; @@ -101,7 +100,6 @@ private: int _mode; }; - LightMutex _lock; DebugDraw _drawer; bool _debug_stale; diff --git a/panda/src/bullet/bulletGenericConstraint.I b/panda/src/bullet/bulletGenericConstraint.I index 08ee24ccba..da9a6fbc49 100644 --- a/panda/src/bullet/bulletGenericConstraint.I +++ b/panda/src/bullet/bulletGenericConstraint.I @@ -19,21 +19,3 @@ INLINE BulletGenericConstraint:: delete _constraint; } - -/** - * - */ -INLINE CPT(TransformState) BulletGenericConstraint:: -get_frame_a() const { - - return btTrans_to_TransformState(_constraint->getFrameOffsetA()); -} - -/** - * - */ -INLINE CPT(TransformState) BulletGenericConstraint:: -get_frame_b() const { - - return btTrans_to_TransformState(_constraint->getFrameOffsetB()); -} diff --git a/panda/src/bullet/bulletGenericConstraint.cxx b/panda/src/bullet/bulletGenericConstraint.cxx index a68a345ce6..de98b5d40b 100644 --- a/panda/src/bullet/bulletGenericConstraint.cxx +++ b/panda/src/bullet/bulletGenericConstraint.cxx @@ -63,6 +63,7 @@ ptr() const { */ LVector3 BulletGenericConstraint:: get_axis(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(axis >= 0, LVector3::zero()); nassertr(axis <= 3, LVector3::zero()); @@ -76,6 +77,7 @@ get_axis(int axis) const { */ PN_stdfloat BulletGenericConstraint:: get_pivot(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(axis >= 0, 0.0f); nassertr(axis <= 3, 0.0f); @@ -89,6 +91,7 @@ get_pivot(int axis) const { */ PN_stdfloat BulletGenericConstraint:: get_angle(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(axis >= 0, 0.0f); nassertr(axis <= 3, 0.0f); @@ -102,6 +105,7 @@ get_angle(int axis) const { */ void BulletGenericConstraint:: set_linear_limit(int axis, PN_stdfloat low, PN_stdfloat high) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(axis >= 0); nassertv(axis <= 3); @@ -115,6 +119,7 @@ set_linear_limit(int axis, PN_stdfloat low, PN_stdfloat high) { */ void BulletGenericConstraint:: set_angular_limit(int axis, PN_stdfloat low, PN_stdfloat high) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(axis >= 0); nassertv(axis <= 3); @@ -126,11 +131,32 @@ set_angular_limit(int axis, PN_stdfloat low, PN_stdfloat high) { _constraint->setLimit(axis + 3, low, high); } +/** + * + */ +CPT(TransformState) BulletGenericConstraint:: +get_frame_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getFrameOffsetA()); +} + +/** + * + */ +CPT(TransformState) BulletGenericConstraint:: +get_frame_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getFrameOffsetB()); +} + /** * */ BulletRotationalLimitMotor BulletGenericConstraint:: get_rotational_limit_motor(int axis) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return BulletRotationalLimitMotor(*_constraint->getRotationalLimitMotor(axis)); } @@ -140,6 +166,7 @@ get_rotational_limit_motor(int axis) { */ BulletTranslationalLimitMotor BulletGenericConstraint:: get_translational_limit_motor() { + LightMutexHolder holder(BulletWorld::get_global_lock()); return BulletTranslationalLimitMotor(*_constraint->getTranslationalLimitMotor()); } @@ -149,6 +176,7 @@ get_translational_limit_motor() { */ void BulletGenericConstraint:: set_frames(const TransformState *ts_a, const TransformState *ts_b) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btTransform frame_a = TransformState_to_btTrans(ts_a); btTransform frame_b = TransformState_to_btTrans(ts_b); diff --git a/panda/src/bullet/bulletGenericConstraint.h b/panda/src/bullet/bulletGenericConstraint.h index a2446ffcd4..f571df1ad6 100644 --- a/panda/src/bullet/bulletGenericConstraint.h +++ b/panda/src/bullet/bulletGenericConstraint.h @@ -57,8 +57,8 @@ PUBLISHED: // Frames void set_frames(const TransformState *ts_a, const TransformState *ts_b); - INLINE CPT(TransformState) get_frame_a() const; - INLINE CPT(TransformState) get_frame_b() const; + CPT(TransformState) get_frame_a() const; + CPT(TransformState) get_frame_b() const; MAKE_PROPERTY(translational_limit_motor, get_translational_limit_motor); MAKE_PROPERTY(frame_a, get_frame_a); diff --git a/panda/src/bullet/bulletGhostNode.I b/panda/src/bullet/bulletGhostNode.I index c4620097a8..d9b24a0950 100644 --- a/panda/src/bullet/bulletGhostNode.I +++ b/panda/src/bullet/bulletGhostNode.I @@ -20,23 +20,3 @@ INLINE BulletGhostNode:: delete _ghost; } -/** - * - */ -INLINE int BulletGhostNode:: -get_num_overlapping_nodes() const { - - return _ghost->getNumOverlappingObjects(); -} - -/** - * - */ -INLINE PandaNode *BulletGhostNode:: -get_overlapping_node(int idx) const { - - nassertr(idx >=0 && idx < _ghost->getNumOverlappingObjects(), NULL); - - btCollisionObject *object = _ghost->getOverlappingObject(idx); - return (object) ? (PandaNode *)object->getUserPointer() : NULL; -} diff --git a/panda/src/bullet/bulletGhostNode.cxx b/panda/src/bullet/bulletGhostNode.cxx index ddead41067..39740ff5a1 100644 --- a/panda/src/bullet/bulletGhostNode.cxx +++ b/panda/src/bullet/bulletGhostNode.cxx @@ -53,6 +53,7 @@ get_object() const { */ void BulletGhostNode:: parents_changed() { + LightMutexHolder holder(BulletWorld::get_global_lock()); Parents parents = get_parents(); for (size_t i = 0; i < parents.get_num_parents(); ++i) { @@ -73,10 +74,10 @@ parents_changed() { } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletGhostNode:: -transform_changed() { +do_transform_changed() { if (_sync_disable) return; @@ -98,27 +99,60 @@ transform_changed() { if (!scale.almost_equal(LVecBase3(1.0f, 1.0f, 1.0f))) { for (int i=0; iset_local_scale(scale); + shape->do_set_local_scale(scale); } } } } } -/** - * - */ void BulletGhostNode:: -sync_p2b() { +transform_changed() { - transform_changed(); + if (_sync_disable) return; + + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_transform_changed(); } /** * */ +int BulletGhostNode:: +get_num_overlapping_nodes() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _ghost->getNumOverlappingObjects(); +} + +/** + * + */ +PandaNode *BulletGhostNode:: +get_overlapping_node(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr(idx >=0 && idx < _ghost->getNumOverlappingObjects(), NULL); + + btCollisionObject *object = _ghost->getOverlappingObject(idx); + return (object) ? (PandaNode *)object->getUserPointer() : NULL; +} + +/** + * Assumes the lock(bullet global lock) is held by the caller + */ void BulletGhostNode:: -sync_b2p() { +do_sync_p2b() { + + do_transform_changed(); +} + +/** + * Assumes the lock(bullet global lock) is held by the caller + */ +void BulletGhostNode:: +do_sync_b2p() { NodePath np = NodePath::any_path((PandaNode *)this); LVecBase3 scale = np.get_net_transform()->get_scale(); diff --git a/panda/src/bullet/bulletGhostNode.h b/panda/src/bullet/bulletGhostNode.h index 87a1624f3d..a76c0ce8a1 100644 --- a/panda/src/bullet/bulletGhostNode.h +++ b/panda/src/bullet/bulletGhostNode.h @@ -34,8 +34,8 @@ PUBLISHED: INLINE ~BulletGhostNode(); // Overlapping - INLINE int get_num_overlapping_nodes() const; - INLINE PandaNode *get_overlapping_node(int idx) const; + int get_num_overlapping_nodes() const; + PandaNode *get_overlapping_node(int idx) const; MAKE_SEQ(get_overlapping_nodes, get_num_overlapping_nodes, get_overlapping_node); MAKE_SEQ_PROPERTY(overlapping_nodes, get_num_overlapping_nodes, get_overlapping_node); @@ -43,8 +43,8 @@ PUBLISHED: public: virtual btCollisionObject *get_object() const; - void sync_p2b(); - void sync_b2p(); + void do_sync_p2b(); + void do_sync_b2p(); protected: virtual void parents_changed(); @@ -57,6 +57,8 @@ private: btPairCachingGhostObject *_ghost; + void do_transform_changed(); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/bullet/bulletHeightfieldShape.I b/panda/src/bullet/bulletHeightfieldShape.I index 5bfceb1e5b..5a2702be9a 100644 --- a/panda/src/bullet/bulletHeightfieldShape.I +++ b/panda/src/bullet/bulletHeightfieldShape.I @@ -32,33 +32,3 @@ INLINE BulletHeightfieldShape:: delete _shape; delete [] _data; } - -/** - * - */ -INLINE BulletHeightfieldShape:: -BulletHeightfieldShape(const BulletHeightfieldShape ©) : - _shape(copy._shape), - _num_rows(copy._num_rows), - _num_cols(copy._num_cols), - _max_height(copy._max_height), - _up(copy._up) { - - size_t size = (size_t)_num_rows * (size_t)_num_cols; - _data = new btScalar[size]; - memcpy(_data, copy._data, size * sizeof(btScalar)); -} - -/** - * - */ -INLINE void BulletHeightfieldShape:: -operator = (const BulletHeightfieldShape ©) { - _shape = copy._shape; - _num_rows = copy._num_rows; - _num_cols = copy._num_cols; - - size_t size = (size_t)_num_rows * (size_t)_num_cols; - _data = new btScalar[size]; - memcpy(_data, copy._data, size * sizeof(btScalar)); -} diff --git a/panda/src/bullet/bulletHeightfieldShape.cxx b/panda/src/bullet/bulletHeightfieldShape.cxx index 6ff476c0a6..1a01876401 100644 --- a/panda/src/bullet/bulletHeightfieldShape.cxx +++ b/panda/src/bullet/bulletHeightfieldShape.cxx @@ -61,6 +61,7 @@ ptr() const { */ void BulletHeightfieldShape:: set_use_diamond_subdivision(bool flag) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _shape->setUseDiamondSubdivision(flag); } @@ -104,6 +105,42 @@ BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up) : _shape->setUserPointer(this); } +/** + * + */ +BulletHeightfieldShape:: +BulletHeightfieldShape(const BulletHeightfieldShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _num_rows = copy._num_rows; + _num_cols = copy._num_cols; + _max_height = copy._max_height; + _up = copy._up; + + size_t size = (size_t)_num_rows * (size_t)_num_cols; + _data = new btScalar[size]; + memcpy(_data, copy._data, size * sizeof(btScalar)); +} + +/** + * + */ +void BulletHeightfieldShape:: +operator = (const BulletHeightfieldShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _num_rows = copy._num_rows; + _num_cols = copy._num_cols; + _max_height = copy._max_height; + _up = copy._up; + + size_t size = (size_t)_num_rows * (size_t)_num_cols; + _data = new btScalar[size]; + memcpy(_data, copy._data, size * sizeof(btScalar)); +} + /** * Tells the BamReader how to create objects of type BulletShape. */ @@ -169,8 +206,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { _num_cols = scan.get_int32(); size_t size = (size_t)_num_rows * (size_t)_num_cols; - delete[] _data; + delete [] _data; _data = new float[size]; + for (size_t i = 0; i < size; ++i) { _data[i] = scan.get_stdfloat(); } diff --git a/panda/src/bullet/bulletHeightfieldShape.h b/panda/src/bullet/bulletHeightfieldShape.h index 2f70fddac8..1bfc6c41c3 100644 --- a/panda/src/bullet/bulletHeightfieldShape.h +++ b/panda/src/bullet/bulletHeightfieldShape.h @@ -34,8 +34,8 @@ private: PUBLISHED: explicit BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up=Z_up); explicit BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up=Z_up); - INLINE BulletHeightfieldShape(const BulletHeightfieldShape ©); - INLINE void operator = (const BulletHeightfieldShape ©); + BulletHeightfieldShape(const BulletHeightfieldShape ©); + void operator = (const BulletHeightfieldShape ©); INLINE ~BulletHeightfieldShape(); void set_use_diamond_subdivision(bool flag=true); diff --git a/panda/src/bullet/bulletHingeConstraint.I b/panda/src/bullet/bulletHingeConstraint.I index 01614f603a..e5753a5947 100644 --- a/panda/src/bullet/bulletHingeConstraint.I +++ b/panda/src/bullet/bulletHingeConstraint.I @@ -19,21 +19,3 @@ INLINE BulletHingeConstraint:: delete _constraint; } - -/** - * - */ -INLINE CPT(TransformState) BulletHingeConstraint:: -get_frame_a() const { - - return btTrans_to_TransformState(_constraint->getAFrame()); -} - -/** - * - */ -INLINE CPT(TransformState) BulletHingeConstraint:: -get_frame_b() const { - - return btTrans_to_TransformState(_constraint->getBFrame()); -} diff --git a/panda/src/bullet/bulletHingeConstraint.cxx b/panda/src/bullet/bulletHingeConstraint.cxx index a262be88e8..5cbfa44d94 100644 --- a/panda/src/bullet/bulletHingeConstraint.cxx +++ b/panda/src/bullet/bulletHingeConstraint.cxx @@ -111,6 +111,7 @@ ptr() const { */ void BulletHingeConstraint:: set_angular_only(bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _constraint->setAngularOnly(value); } @@ -120,6 +121,7 @@ set_angular_only(bool value) { */ bool BulletHingeConstraint:: get_angular_only() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _constraint->getAngularOnly(); } @@ -129,6 +131,7 @@ get_angular_only() const { */ void BulletHingeConstraint:: set_limit(PN_stdfloat low, PN_stdfloat high, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) { + LightMutexHolder holder(BulletWorld::get_global_lock()); low = deg_2_rad(low); high = deg_2_rad(high); @@ -141,6 +144,7 @@ set_limit(PN_stdfloat low, PN_stdfloat high, PN_stdfloat softness, PN_stdfloat b */ void BulletHingeConstraint:: set_axis(const LVector3 &axis) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!axis.is_nan()); @@ -153,6 +157,7 @@ set_axis(const LVector3 &axis) { */ PN_stdfloat BulletHingeConstraint:: get_lower_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return rad_2_deg(_constraint->getLowerLimit()); } @@ -162,6 +167,7 @@ get_lower_limit() const { */ PN_stdfloat BulletHingeConstraint:: get_upper_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return rad_2_deg(_constraint->getUpperLimit()); } @@ -171,6 +177,7 @@ get_upper_limit() const { */ PN_stdfloat BulletHingeConstraint:: get_hinge_angle() { + LightMutexHolder holder(BulletWorld::get_global_lock()); return rad_2_deg(_constraint->getHingeAngle()); } @@ -184,6 +191,7 @@ get_hinge_angle() { */ void BulletHingeConstraint:: enable_angular_motor(bool enable, PN_stdfloat target_velocity, PN_stdfloat max_impulse) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->enableAngularMotor(enable, target_velocity, max_impulse); } @@ -193,6 +201,7 @@ enable_angular_motor(bool enable, PN_stdfloat target_velocity, PN_stdfloat max_i */ void BulletHingeConstraint:: enable_motor(bool enable) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->enableMotor(enable); } @@ -203,6 +212,7 @@ enable_motor(bool enable) { */ void BulletHingeConstraint:: set_max_motor_impulse(PN_stdfloat max_impulse) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMaxMotorImpulse(max_impulse); } @@ -212,6 +222,7 @@ set_max_motor_impulse(PN_stdfloat max_impulse) { */ void BulletHingeConstraint:: set_motor_target(const LQuaternion &quat, PN_stdfloat dt) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMotorTarget(LQuaternion_to_btQuat(quat), dt); } @@ -221,6 +232,7 @@ set_motor_target(const LQuaternion &quat, PN_stdfloat dt) { */ void BulletHingeConstraint:: set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMotorTarget(target_angle, dt); } @@ -230,9 +242,30 @@ set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt) { */ void BulletHingeConstraint:: set_frames(const TransformState *ts_a, const TransformState *ts_b) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btTransform frame_a = TransformState_to_btTrans(ts_a); btTransform frame_b = TransformState_to_btTrans(ts_b); _constraint->setFrames(frame_a, frame_b); } + +/** + * + */ +CPT(TransformState) BulletHingeConstraint:: +get_frame_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getAFrame()); +} + +/** + * + */ +CPT(TransformState) BulletHingeConstraint:: +get_frame_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getBFrame()); +} diff --git a/panda/src/bullet/bulletHingeConstraint.h b/panda/src/bullet/bulletHingeConstraint.h index 12a1b1b2c2..dc6768490b 100644 --- a/panda/src/bullet/bulletHingeConstraint.h +++ b/panda/src/bullet/bulletHingeConstraint.h @@ -69,8 +69,8 @@ PUBLISHED: void set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt); void set_frames(const TransformState *ts_a, const TransformState *ts_b); - INLINE CPT(TransformState) get_frame_a() const; - INLINE CPT(TransformState) get_frame_b() const; + CPT(TransformState) get_frame_a() const; + CPT(TransformState) get_frame_b() const; MAKE_PROPERTY(hinge_angle, get_hinge_angle); MAKE_PROPERTY(lower_limit, get_lower_limit); diff --git a/panda/src/bullet/bulletManifoldPoint.I b/panda/src/bullet/bulletManifoldPoint.I index 6730d2f349..4347bad4f4 100644 --- a/panda/src/bullet/bulletManifoldPoint.I +++ b/panda/src/bullet/bulletManifoldPoint.I @@ -18,228 +18,3 @@ INLINE BulletManifoldPoint:: ~BulletManifoldPoint() { } - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_lateral_friction_initialized(bool value) { -#if BT_BULLET_VERSION >= 285 - if (value) { - _pt.m_contactPointFlags |= BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED; - } else { - _pt.m_contactPointFlags &= ~BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED; - } -#else - _pt.m_lateralFrictionInitialized = value; -#endif -} - -/** - * - */ -INLINE bool BulletManifoldPoint:: -get_lateral_friction_initialized() const { -#if BT_BULLET_VERSION >= 285 - return (_pt.m_contactPointFlags & BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED) != 0; -#else - return _pt.m_lateralFrictionInitialized; -#endif -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_lateral_friction_dir1(const LVecBase3 &dir) { - - _pt.m_lateralFrictionDir1 = LVecBase3_to_btVector3(dir); -} - -/** - * - */ -INLINE LVector3 BulletManifoldPoint:: -get_lateral_friction_dir1() const { - - return btVector3_to_LVector3(_pt.m_lateralFrictionDir1); -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_lateral_friction_dir2(const LVecBase3 &dir) { - - _pt.m_lateralFrictionDir2 = LVecBase3_to_btVector3(dir); -} - -/** - * - */ -INLINE LVector3 BulletManifoldPoint:: -get_lateral_friction_dir2() const { - - return btVector3_to_LVector3(_pt.m_lateralFrictionDir2); -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_contact_motion1(PN_stdfloat value) { - - _pt.m_contactMotion1 = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_contact_motion1() const { - - return (PN_stdfloat)_pt.m_contactMotion1; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_contact_motion2(PN_stdfloat value) { - - _pt.m_contactMotion2 = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_contact_motion2() const { - - return (PN_stdfloat)_pt.m_contactMotion2; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_combined_friction(PN_stdfloat value) { - - _pt.m_combinedFriction = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_combined_friction() const { - - return (PN_stdfloat)_pt.m_combinedFriction; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_combined_restitution(PN_stdfloat value) { - - _pt.m_combinedRestitution = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_combined_restitution() const { - - return (PN_stdfloat)_pt.m_combinedRestitution; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_applied_impulse(PN_stdfloat value) { - - _pt.m_appliedImpulse = (btScalar)value; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_applied_impulse_lateral1(PN_stdfloat value) { - - _pt.m_appliedImpulseLateral1 = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_applied_impulse_lateral1() const { - - return (PN_stdfloat)_pt.m_appliedImpulseLateral1; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_applied_impulse_lateral2(PN_stdfloat value) { - - _pt.m_appliedImpulseLateral2 = (btScalar)value; -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_applied_impulse_lateral2() const { - - return (PN_stdfloat)_pt.m_appliedImpulseLateral2; -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_contact_cfm1(PN_stdfloat value) { -#if BT_BULLET_VERSION < 285 - _pt.m_contactCFM1 = (btScalar)value; -#endif -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_contact_cfm1() const { -#if BT_BULLET_VERSION < 285 - return (PN_stdfloat)_pt.m_contactCFM1; -#else - return 0; -#endif -} - -/** - * - */ -INLINE void BulletManifoldPoint:: -set_contact_cfm2(PN_stdfloat value) { -#if BT_BULLET_VERSION < 285 - _pt.m_contactCFM2 = (btScalar)value; -#endif -} - -/** - * - */ -INLINE PN_stdfloat BulletManifoldPoint:: -get_contact_cfm2() const { -#if BT_BULLET_VERSION < 285 - return (PN_stdfloat)_pt.m_contactCFM2; -#else - return 0; -#endif -} diff --git a/panda/src/bullet/bulletManifoldPoint.cxx b/panda/src/bullet/bulletManifoldPoint.cxx index 00651186f0..b56244ed29 100644 --- a/panda/src/bullet/bulletManifoldPoint.cxx +++ b/panda/src/bullet/bulletManifoldPoint.cxx @@ -46,6 +46,7 @@ operator=(const BulletManifoldPoint& other) { */ int BulletManifoldPoint:: get_life_time() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _pt.getLifeTime(); } @@ -55,6 +56,7 @@ get_life_time() const { */ PN_stdfloat BulletManifoldPoint:: get_distance() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_pt.getDistance(); } @@ -64,6 +66,7 @@ get_distance() const { */ PN_stdfloat BulletManifoldPoint:: get_applied_impulse() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_pt.getAppliedImpulse(); } @@ -73,6 +76,7 @@ get_applied_impulse() const { */ LPoint3 BulletManifoldPoint:: get_position_world_on_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_pt.getPositionWorldOnA()); } @@ -82,6 +86,7 @@ get_position_world_on_a() const { */ LPoint3 BulletManifoldPoint:: get_position_world_on_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_pt.getPositionWorldOnB()); } @@ -91,6 +96,7 @@ get_position_world_on_b() const { */ LVector3 BulletManifoldPoint:: get_normal_world_on_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_pt.m_normalWorldOnB); } @@ -100,6 +106,7 @@ get_normal_world_on_b() const { */ LPoint3 BulletManifoldPoint:: get_local_point_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_pt.m_localPointA); } @@ -109,6 +116,7 @@ get_local_point_a() const { */ LPoint3 BulletManifoldPoint:: get_local_point_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_pt.m_localPointB); } @@ -118,6 +126,7 @@ get_local_point_b() const { */ int BulletManifoldPoint:: get_part_id0() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _pt.m_partId0; } @@ -127,6 +136,7 @@ get_part_id0() const { */ int BulletManifoldPoint:: get_part_id1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _pt.m_partId1; } @@ -136,6 +146,7 @@ get_part_id1() const { */ int BulletManifoldPoint:: get_index0() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _pt.m_index0; } @@ -145,6 +156,261 @@ get_index0() const { */ int BulletManifoldPoint:: get_index1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _pt.m_index1; } + +/** + * + */ +void BulletManifoldPoint:: +set_lateral_friction_initialized(bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION >= 285 + if (value) { + _pt.m_contactPointFlags |= BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED; + } else { + _pt.m_contactPointFlags &= ~BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED; + } +#else + _pt.m_lateralFrictionInitialized = value; +#endif +} + +/** + * + */ +bool BulletManifoldPoint:: +get_lateral_friction_initialized() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION >= 285 + return (_pt.m_contactPointFlags & BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED) != 0; +#else + return _pt.m_lateralFrictionInitialized; +#endif +} + +/** + * + */ +void BulletManifoldPoint:: +set_lateral_friction_dir1(const LVecBase3 &dir) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_lateralFrictionDir1 = LVecBase3_to_btVector3(dir); +} + +/** + * + */ +LVector3 BulletManifoldPoint:: +get_lateral_friction_dir1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_pt.m_lateralFrictionDir1); +} + +/** + * + */ +void BulletManifoldPoint:: +set_lateral_friction_dir2(const LVecBase3 &dir) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_lateralFrictionDir2 = LVecBase3_to_btVector3(dir); +} + +/** + * + */ +LVector3 BulletManifoldPoint:: +get_lateral_friction_dir2() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_pt.m_lateralFrictionDir2); +} + +/** + * + */ +void BulletManifoldPoint:: +set_contact_motion1(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_contactMotion1 = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_contact_motion1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_contactMotion1; +} + +/** + * + */ +void BulletManifoldPoint:: +set_contact_motion2(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_contactMotion2 = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_contact_motion2() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_contactMotion2; +} + +/** + * + */ +void BulletManifoldPoint:: +set_combined_friction(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_combinedFriction = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_combined_friction() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_combinedFriction; +} + +/** + * + */ +void BulletManifoldPoint:: +set_combined_restitution(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_combinedRestitution = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_combined_restitution() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_combinedRestitution; +} + +/** + * + */ +void BulletManifoldPoint:: +set_applied_impulse(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_appliedImpulse = (btScalar)value; +} + +/** + * + */ +void BulletManifoldPoint:: +set_applied_impulse_lateral1(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_appliedImpulseLateral1 = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_applied_impulse_lateral1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_appliedImpulseLateral1; +} + +/** + * + */ +void BulletManifoldPoint:: +set_applied_impulse_lateral2(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _pt.m_appliedImpulseLateral2 = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_applied_impulse_lateral2() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_pt.m_appliedImpulseLateral2; +} + +/** + * + */ +void BulletManifoldPoint:: +set_contact_cfm1(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION < 285 + _pt.m_contactCFM1 = (btScalar)value; +#endif +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_contact_cfm1() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION < 285 + return (PN_stdfloat)_pt.m_contactCFM1; +#else + return 0; +#endif +} + +/** + * + */ +void BulletManifoldPoint:: +set_contact_cfm2(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION < 285 + _pt.m_contactCFM2 = (btScalar)value; +#endif +} + +/** + * + */ +PN_stdfloat BulletManifoldPoint:: +get_contact_cfm2() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + +#if BT_BULLET_VERSION < 285 + return (PN_stdfloat)_pt.m_contactCFM2; +#else + return 0; +#endif +} diff --git a/panda/src/bullet/bulletManifoldPoint.h b/panda/src/bullet/bulletManifoldPoint.h index a7bc271599..bc4c0f9486 100644 --- a/panda/src/bullet/bulletManifoldPoint.h +++ b/panda/src/bullet/bulletManifoldPoint.h @@ -43,30 +43,30 @@ PUBLISHED: int get_index0() const; int get_index1() const; - INLINE void set_lateral_friction_initialized(bool value); - INLINE void set_lateral_friction_dir1(const LVecBase3 &dir); - INLINE void set_lateral_friction_dir2(const LVecBase3 &dir); - INLINE void set_contact_motion1(PN_stdfloat value); - INLINE void set_contact_motion2(PN_stdfloat value); - INLINE void set_combined_friction(PN_stdfloat value); - INLINE void set_combined_restitution(PN_stdfloat value); - INLINE void set_applied_impulse(PN_stdfloat value); - INLINE void set_applied_impulse_lateral1(PN_stdfloat value); - INLINE void set_applied_impulse_lateral2(PN_stdfloat value); - INLINE void set_contact_cfm1(PN_stdfloat value); - INLINE void set_contact_cfm2(PN_stdfloat value); + void set_lateral_friction_initialized(bool value); + void set_lateral_friction_dir1(const LVecBase3 &dir); + void set_lateral_friction_dir2(const LVecBase3 &dir); + void set_contact_motion1(PN_stdfloat value); + void set_contact_motion2(PN_stdfloat value); + void set_combined_friction(PN_stdfloat value); + void set_combined_restitution(PN_stdfloat value); + void set_applied_impulse(PN_stdfloat value); + void set_applied_impulse_lateral1(PN_stdfloat value); + void set_applied_impulse_lateral2(PN_stdfloat value); + void set_contact_cfm1(PN_stdfloat value); + void set_contact_cfm2(PN_stdfloat value); - INLINE bool get_lateral_friction_initialized() const; - INLINE LVector3 get_lateral_friction_dir1() const; - INLINE LVector3 get_lateral_friction_dir2() const; - INLINE PN_stdfloat get_contact_motion1() const; - INLINE PN_stdfloat get_contact_motion2() const; - INLINE PN_stdfloat get_combined_friction() const; - INLINE PN_stdfloat get_combined_restitution() const; - INLINE PN_stdfloat get_applied_impulse_lateral1() const; - INLINE PN_stdfloat get_applied_impulse_lateral2() const; - INLINE PN_stdfloat get_contact_cfm1() const; - INLINE PN_stdfloat get_contact_cfm2() const; + bool get_lateral_friction_initialized() const; + LVector3 get_lateral_friction_dir1() const; + LVector3 get_lateral_friction_dir2() const; + PN_stdfloat get_contact_motion1() const; + PN_stdfloat get_contact_motion2() const; + PN_stdfloat get_combined_friction() const; + PN_stdfloat get_combined_restitution() const; + PN_stdfloat get_applied_impulse_lateral1() const; + PN_stdfloat get_applied_impulse_lateral2() const; + PN_stdfloat get_contact_cfm1() const; + PN_stdfloat get_contact_cfm2() const; MAKE_PROPERTY(life_time, get_life_time); MAKE_PROPERTY(distance, get_distance); diff --git a/panda/src/bullet/bulletMinkowskiSumShape.I b/panda/src/bullet/bulletMinkowskiSumShape.I index ed4a356f9a..b99d0c7561 100644 --- a/panda/src/bullet/bulletMinkowskiSumShape.I +++ b/panda/src/bullet/bulletMinkowskiSumShape.I @@ -30,64 +30,6 @@ INLINE BulletMinkowskiSumShape:: delete _shape; } -/** - * - */ -INLINE BulletMinkowskiSumShape:: -BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©) : - _shape(copy._shape), - _shape_a(copy._shape_a), - _shape_b(copy._shape_b) { -} - -/** - * - */ -INLINE void BulletMinkowskiSumShape:: -operator = (const BulletMinkowskiSumShape ©) { - _shape = copy._shape; - _shape_a = copy._shape_a; - _shape_b = copy._shape_b; -} - -/** - * - */ -INLINE void BulletMinkowskiSumShape:: -set_transform_a(const TransformState *ts) { - - nassertv(ts); - _shape->setTransformA(TransformState_to_btTrans(ts)); -} - -/** - * - */ -INLINE void BulletMinkowskiSumShape:: -set_transform_b(const TransformState *ts) { - - nassertv(ts); - _shape->setTransformB(TransformState_to_btTrans(ts)); -} - -/** - * - */ -INLINE CPT(TransformState) BulletMinkowskiSumShape:: -get_transform_a() const { - - return btTrans_to_TransformState(_shape->getTransformA()); -} - -/** - * - */ -INLINE CPT(TransformState) BulletMinkowskiSumShape:: -get_transform_b() const { - - return btTrans_to_TransformState(_shape->GetTransformB()); -} - /** * */ diff --git a/panda/src/bullet/bulletMinkowskiSumShape.cxx b/panda/src/bullet/bulletMinkowskiSumShape.cxx index 3dc618adac..cc56d39884 100644 --- a/panda/src/bullet/bulletMinkowskiSumShape.cxx +++ b/panda/src/bullet/bulletMinkowskiSumShape.cxx @@ -33,6 +33,30 @@ BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b) _shape->setUserPointer(this); } +/** + * + */ +BulletMinkowskiSumShape:: +BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _shape_a = copy._shape_a; + _shape_b = copy._shape_b; +} + +/** + * + */ +void BulletMinkowskiSumShape:: +operator = (const BulletMinkowskiSumShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _shape_a = copy._shape_a; + _shape_b = copy._shape_b; +} + /** * */ @@ -42,6 +66,48 @@ ptr() const { return _shape; } +/** + * + */ +void BulletMinkowskiSumShape:: +set_transform_a(const TransformState *ts) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(ts); + _shape->setTransformA(TransformState_to_btTrans(ts)); +} + +/** + * + */ +void BulletMinkowskiSumShape:: +set_transform_b(const TransformState *ts) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(ts); + _shape->setTransformB(TransformState_to_btTrans(ts)); +} + +/** + * + */ +CPT(TransformState) BulletMinkowskiSumShape:: +get_transform_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_shape->getTransformA()); +} + +/** + * + */ +CPT(TransformState) BulletMinkowskiSumShape:: +get_transform_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_shape->GetTransformB()); +} + /** * Tells the BamReader how to create objects of type BulletShape. */ diff --git a/panda/src/bullet/bulletMinkowskiSumShape.h b/panda/src/bullet/bulletMinkowskiSumShape.h index 2e66ab9cae..c8629f2e33 100644 --- a/panda/src/bullet/bulletMinkowskiSumShape.h +++ b/panda/src/bullet/bulletMinkowskiSumShape.h @@ -32,14 +32,14 @@ private: PUBLISHED: explicit BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b); - INLINE BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©); - INLINE void operator = (const BulletMinkowskiSumShape ©); + BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©); + void operator = (const BulletMinkowskiSumShape ©); INLINE ~BulletMinkowskiSumShape(); - INLINE void set_transform_a(const TransformState *ts); - INLINE void set_transform_b(const TransformState *ts); - INLINE CPT(TransformState) get_transform_a() const; - INLINE CPT(TransformState) get_transform_b() const; + void set_transform_a(const TransformState *ts); + void set_transform_b(const TransformState *ts); + CPT(TransformState) get_transform_a() const; + CPT(TransformState) get_transform_b() const; INLINE const BulletShape *get_shape_a() const; INLINE const BulletShape *get_shape_b() const; diff --git a/panda/src/bullet/bulletMultiSphereShape.I b/panda/src/bullet/bulletMultiSphereShape.I index 1024dce7dc..e4f95c7bf1 100644 --- a/panda/src/bullet/bulletMultiSphereShape.I +++ b/panda/src/bullet/bulletMultiSphereShape.I @@ -19,48 +19,3 @@ INLINE BulletMultiSphereShape:: delete _shape; } - -/** - * - */ -INLINE BulletMultiSphereShape:: -BulletMultiSphereShape(const BulletMultiSphereShape ©) : - _shape(copy._shape) { -} - -/** - * - */ -INLINE void BulletMultiSphereShape:: -operator = (const BulletMultiSphereShape ©) { - _shape = copy._shape; -} - -/** - * - */ -INLINE int BulletMultiSphereShape:: -get_sphere_count() const { - - return _shape->getSphereCount(); -} - -/** - * - */ -INLINE LPoint3 BulletMultiSphereShape:: -get_sphere_pos(int index) const { - - nassertr(index >=0 && index <_shape->getSphereCount(), LPoint3::zero()); - return btVector3_to_LPoint3(_shape->getSpherePosition(index)); -} - -/** - * - */ -INLINE PN_stdfloat BulletMultiSphereShape:: -get_sphere_radius(int index) const { - - nassertr(index >=0 && index <_shape->getSphereCount(), 0.0); - return (PN_stdfloat)_shape->getSphereRadius(index); -} diff --git a/panda/src/bullet/bulletMultiSphereShape.cxx b/panda/src/bullet/bulletMultiSphereShape.cxx index 9defaedc51..ffaed8bafb 100644 --- a/panda/src/bullet/bulletMultiSphereShape.cxx +++ b/panda/src/bullet/bulletMultiSphereShape.cxx @@ -42,6 +42,26 @@ BulletMultiSphereShape(const PTA_LVecBase3 &points, const PTA_stdfloat &radii) { _shape->setUserPointer(this); } +/** + * + */ +BulletMultiSphereShape:: +BulletMultiSphereShape(const BulletMultiSphereShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + +/** + * + */ +void BulletMultiSphereShape:: +operator = (const BulletMultiSphereShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + /** * */ @@ -51,6 +71,38 @@ ptr() const { return _shape; } +/** + * + */ +int BulletMultiSphereShape:: +get_sphere_count() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _shape->getSphereCount(); +} + +/** + * + */ +LPoint3 BulletMultiSphereShape:: +get_sphere_pos(int index) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr(index >=0 && index <_shape->getSphereCount(), LPoint3::zero()); + return btVector3_to_LPoint3(_shape->getSpherePosition(index)); +} + +/** + * + */ +PN_stdfloat BulletMultiSphereShape:: +get_sphere_radius(int index) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr(index >=0 && index <_shape->getSphereCount(), 0.0); + return (PN_stdfloat)_shape->getSphereRadius(index); +} + /** * Tells the BamReader how to create objects of type BulletShape. */ diff --git a/panda/src/bullet/bulletMultiSphereShape.h b/panda/src/bullet/bulletMultiSphereShape.h index 11d3ee936f..d6fd7af7b7 100644 --- a/panda/src/bullet/bulletMultiSphereShape.h +++ b/panda/src/bullet/bulletMultiSphereShape.h @@ -31,13 +31,13 @@ private: PUBLISHED: explicit BulletMultiSphereShape(const PTA_LVecBase3 &points, const PTA_stdfloat &radii); - INLINE BulletMultiSphereShape(const BulletMultiSphereShape ©); - INLINE void operator = (const BulletMultiSphereShape ©); + BulletMultiSphereShape(const BulletMultiSphereShape ©); + void operator = (const BulletMultiSphereShape ©); INLINE ~BulletMultiSphereShape(); - INLINE int get_sphere_count() const; - INLINE LPoint3 get_sphere_pos(int index) const; - INLINE PN_stdfloat get_sphere_radius(int index) const; + int get_sphere_count() const; + LPoint3 get_sphere_pos(int index) const; + PN_stdfloat get_sphere_radius(int index) const; MAKE_PROPERTY(sphere_count, get_sphere_count); MAKE_SEQ_PROPERTY(sphere_pos, get_sphere_count, get_sphere_pos); diff --git a/panda/src/bullet/bulletPersistentManifold.cxx b/panda/src/bullet/bulletPersistentManifold.cxx index 3a4024f8d2..e42ea3c6f8 100644 --- a/panda/src/bullet/bulletPersistentManifold.cxx +++ b/panda/src/bullet/bulletPersistentManifold.cxx @@ -27,6 +27,7 @@ BulletPersistentManifold(btPersistentManifold *manifold) : _manifold(manifold) { */ PN_stdfloat BulletPersistentManifold:: get_contact_breaking_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_manifold->getContactBreakingThreshold(); } @@ -36,6 +37,7 @@ get_contact_breaking_threshold() const { */ PN_stdfloat BulletPersistentManifold:: get_contact_processing_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_manifold->getContactProcessingThreshold(); } @@ -45,6 +47,7 @@ get_contact_processing_threshold() const { */ void BulletPersistentManifold:: clear_manifold() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _manifold->clearManifold(); } @@ -54,6 +57,7 @@ clear_manifold() { */ PandaNode *BulletPersistentManifold:: get_node0() { + LightMutexHolder holder(BulletWorld::get_global_lock()); #if BT_BULLET_VERSION >= 281 const btCollisionObject *obj = _manifold->getBody0(); @@ -69,6 +73,7 @@ get_node0() { */ PandaNode *BulletPersistentManifold:: get_node1() { + LightMutexHolder holder(BulletWorld::get_global_lock()); #if BT_BULLET_VERSION >= 281 const btCollisionObject *obj = _manifold->getBody1(); @@ -84,6 +89,7 @@ get_node1() { */ int BulletPersistentManifold:: get_num_manifold_points() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _manifold->getNumContacts(); } @@ -93,6 +99,7 @@ get_num_manifold_points() const { */ BulletManifoldPoint *BulletPersistentManifold:: get_manifold_point(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(idx < _manifold->getNumContacts(), NULL) diff --git a/panda/src/bullet/bulletPlaneShape.I b/panda/src/bullet/bulletPlaneShape.I index f6a4c1e752..0b080ab986 100644 --- a/panda/src/bullet/bulletPlaneShape.I +++ b/panda/src/bullet/bulletPlaneShape.I @@ -19,37 +19,3 @@ INLINE BulletPlaneShape:: delete _shape; } - -/** - * - */ -INLINE BulletPlaneShape:: -BulletPlaneShape(const BulletPlaneShape ©) : - _shape(copy._shape) { -} - -/** - * - */ -INLINE void BulletPlaneShape:: -operator = (const BulletPlaneShape ©) { - _shape = copy._shape; -} - -/** - * - */ -INLINE PN_stdfloat BulletPlaneShape:: -get_plane_constant() const { - - return (PN_stdfloat)_shape->getPlaneConstant(); -} - -/** - * - */ -INLINE LVector3 BulletPlaneShape:: -get_plane_normal() const { - - return btVector3_to_LVector3(_shape->getPlaneNormal()); -} diff --git a/panda/src/bullet/bulletPlaneShape.cxx b/panda/src/bullet/bulletPlaneShape.cxx index 2b410fb0e9..a7804290cd 100644 --- a/panda/src/bullet/bulletPlaneShape.cxx +++ b/panda/src/bullet/bulletPlaneShape.cxx @@ -27,6 +27,26 @@ BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant) { _shape->setUserPointer(this); } +/** + * + */ +BulletPlaneShape:: +BulletPlaneShape(const BulletPlaneShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + +/** + * + */ +void BulletPlaneShape:: +operator = (const BulletPlaneShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; +} + /** * */ @@ -36,6 +56,26 @@ ptr() const { return _shape; } +/** + * + */ +PN_stdfloat BulletPlaneShape:: +get_plane_constant() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_shape->getPlaneConstant(); +} + +/** + * + */ +LVector3 BulletPlaneShape:: +get_plane_normal() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_shape->getPlaneNormal()); +} + /** * */ diff --git a/panda/src/bullet/bulletPlaneShape.h b/panda/src/bullet/bulletPlaneShape.h index 4455328f10..610c5d2412 100644 --- a/panda/src/bullet/bulletPlaneShape.h +++ b/panda/src/bullet/bulletPlaneShape.h @@ -33,12 +33,12 @@ private: PUBLISHED: explicit BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant); - INLINE BulletPlaneShape(const BulletPlaneShape ©); - INLINE void operator = (const BulletPlaneShape ©); + BulletPlaneShape(const BulletPlaneShape ©); + void operator = (const BulletPlaneShape ©); INLINE ~BulletPlaneShape(); - INLINE LVector3 get_plane_normal() const; - INLINE PN_stdfloat get_plane_constant() const; + LVector3 get_plane_normal() const; + PN_stdfloat get_plane_constant() const; static BulletPlaneShape *make_from_solid(const CollisionPlane *solid); diff --git a/panda/src/bullet/bulletRigidBodyNode.I b/panda/src/bullet/bulletRigidBodyNode.I index de1d5eea05..02c9b5dc6d 100644 --- a/panda/src/bullet/bulletRigidBodyNode.I +++ b/panda/src/bullet/bulletRigidBodyNode.I @@ -20,38 +20,3 @@ INLINE BulletRigidBodyNode:: delete _rigid; } -/** - * - */ -INLINE void BulletRigidBodyNode:: -set_linear_damping(PN_stdfloat value) { - - _rigid->setDamping(value, _rigid->getAngularDamping()); -} - -/** - * - */ -INLINE void BulletRigidBodyNode:: -set_angular_damping(PN_stdfloat value) { - - _rigid->setDamping(_rigid->getLinearDamping(), value); -} - -/** - * - */ -INLINE PN_stdfloat BulletRigidBodyNode:: -get_linear_damping() const { - - return (PN_stdfloat)_rigid->getLinearDamping(); -} - -/** - * - */ -INLINE PN_stdfloat BulletRigidBodyNode:: -get_angular_damping() const { - - return (PN_stdfloat)_rigid->getAngularDamping(); -} diff --git a/panda/src/bullet/bulletRigidBodyNode.cxx b/panda/src/bullet/bulletRigidBodyNode.cxx index b8c921e99d..ab8c4327f9 100644 --- a/panda/src/bullet/bulletRigidBodyNode.cxx +++ b/panda/src/bullet/bulletRigidBodyNode.cxx @@ -48,9 +48,11 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) { */ BulletRigidBodyNode:: BulletRigidBodyNode(const BulletRigidBodyNode ©) : - BulletBodyNode(copy), - _motion(copy._motion) + BulletBodyNode(copy) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motion = copy._motion; _rigid = new btRigidBody(*copy._rigid); _rigid->setUserPointer(this); _rigid->setCollisionShape(_shape); @@ -64,6 +66,7 @@ BulletRigidBodyNode(const BulletRigidBodyNode ©) : */ PandaNode *BulletRigidBodyNode:: make_copy() const { + return new BulletRigidBodyNode(*this); } @@ -72,10 +75,11 @@ make_copy() const { */ void BulletRigidBodyNode:: output(ostream &out) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); - BulletBodyNode::output(out); + BulletBodyNode::do_output(out); - out << " mass=" << get_mass(); + out << " mass=" << do_get_mass(); } /** @@ -93,10 +97,10 @@ get_object() const { * The default implementation does nothing. */ void BulletRigidBodyNode:: -shape_changed() { +do_shape_changed() { - set_mass(get_mass()); - transform_changed(); + do_set_mass(do_get_mass()); + do_transform_changed(); } /** @@ -104,9 +108,10 @@ shape_changed() { * automatically computed from the shape of the body. Setting a value of zero * for mass will make the body static. A value of zero can be considered an * infinite mass. + * Assumes the lock(bullet global lock) is held by the caller */ void BulletRigidBodyNode:: -set_mass(PN_stdfloat mass) { +do_set_mass(PN_stdfloat mass) { btScalar bt_mass = mass; btVector3 bt_inertia(0.0, 0.0, 0.0); @@ -119,12 +124,26 @@ set_mass(PN_stdfloat mass) { _rigid->updateInertiaTensor(); } +/** + * Sets the mass of a rigid body. This also modifies the inertia, which is + * automatically computed from the shape of the body. Setting a value of zero + * for mass will make the body static. A value of zero can be considered an + * infinite mass. + */ +void BulletRigidBodyNode:: +set_mass(PN_stdfloat mass) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_set_mass(mass); +} + /** * Returns the total mass of a rigid body. A value of zero means that the * body is staic, i.e. has an infinite mass. + * Assumes the lock(bullet global lock) is held by the caller */ PN_stdfloat BulletRigidBodyNode:: -get_mass() const { +do_get_mass() const { btScalar inv_mass = _rigid->getInvMass(); btScalar mass = (inv_mass == btScalar(0.0)) ? btScalar(0.0) : btScalar(1.0) / inv_mass; @@ -132,11 +151,24 @@ get_mass() const { return mass; } +/** + * Returns the total mass of a rigid body. A value of zero means that the + * body is staic, i.e. has an infinite mass. + */ +PN_stdfloat BulletRigidBodyNode:: +get_mass() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_mass(); +} + + /** * Returns the inverse mass of a rigid body. */ PN_stdfloat BulletRigidBodyNode:: get_inv_mass() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_rigid->getInvMass(); } @@ -153,6 +185,7 @@ get_inv_mass() const { */ void BulletRigidBodyNode:: set_inertia(const LVecBase3 &inertia) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btVector3 inv_inertia( inertia.get_x() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_x()), @@ -171,6 +204,7 @@ set_inertia(const LVecBase3 &inertia) { */ LVector3 BulletRigidBodyNode:: get_inertia() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); btVector3 inv_inertia = _rigid->getInvInertiaDiagLocal(); LVector3 inertia( @@ -187,6 +221,7 @@ get_inertia() const { */ LVector3 BulletRigidBodyNode:: get_inv_inertia_diag_local() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getInvInertiaDiagLocal()); } @@ -196,6 +231,7 @@ get_inv_inertia_diag_local() const { */ LMatrix3 BulletRigidBodyNode:: get_inv_inertia_tensor_world() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btMatrix3x3_to_LMatrix3(_rigid->getInvInertiaTensorWorld()); } @@ -205,6 +241,7 @@ get_inv_inertia_tensor_world() const { */ void BulletRigidBodyNode:: apply_force(const LVector3 &force, const LPoint3 &pos) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!force.is_nan()); nassertv_always(!pos.is_nan()); @@ -218,6 +255,7 @@ apply_force(const LVector3 &force, const LPoint3 &pos) { */ void BulletRigidBodyNode:: apply_central_force(const LVector3 &force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!force.is_nan()); @@ -229,6 +267,7 @@ apply_central_force(const LVector3 &force) { */ void BulletRigidBodyNode:: apply_torque(const LVector3 &torque) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!torque.is_nan()); @@ -240,6 +279,7 @@ apply_torque(const LVector3 &torque) { */ void BulletRigidBodyNode:: apply_torque_impulse(const LVector3 &torque) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!torque.is_nan()); @@ -251,6 +291,7 @@ apply_torque_impulse(const LVector3 &torque) { */ void BulletRigidBodyNode:: apply_impulse(const LVector3 &impulse, const LPoint3 &pos) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!impulse.is_nan()); nassertv_always(!pos.is_nan()); @@ -264,6 +305,7 @@ apply_impulse(const LVector3 &impulse, const LPoint3 &pos) { */ void BulletRigidBodyNode:: apply_central_impulse(const LVector3 &impulse) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!impulse.is_nan()); @@ -271,10 +313,10 @@ apply_central_impulse(const LVector3 &impulse) { } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletRigidBodyNode:: -transform_changed() { +do_transform_changed() { if (_motion.sync_disabled()) return; @@ -289,7 +331,7 @@ transform_changed() { _motion.set_net_transform(ts); // For dynamic or static bodies we directly apply the new transform. - if (!is_kinematic()) { + if (!(get_object()->isKinematicObject())) { btTransform trans = TransformState_to_btTrans(ts); _rigid->setCenterOfMassTransform(trans); } @@ -317,18 +359,31 @@ transform_changed() { * */ void BulletRigidBodyNode:: -sync_p2b() { +transform_changed() { - if (is_kinematic()) { - transform_changed(); + if (_motion.sync_disabled()) return; + + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_transform_changed(); +} + +/** + * Assumes the lock(bullet global lock) is held by the caller + */ +void BulletRigidBodyNode:: +do_sync_p2b() { + + if (get_object()->isKinematicObject()) { + do_transform_changed(); } } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletRigidBodyNode:: -sync_b2p() { +do_sync_b2p() { _motion.sync_b2p((PandaNode *)this); } @@ -338,6 +393,7 @@ sync_b2p() { */ LVector3 BulletRigidBodyNode:: get_linear_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getLinearVelocity()); } @@ -347,6 +403,7 @@ get_linear_velocity() const { */ LVector3 BulletRigidBodyNode:: get_angular_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getAngularVelocity()); } @@ -356,6 +413,7 @@ get_angular_velocity() const { */ void BulletRigidBodyNode:: set_linear_velocity(const LVector3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!velocity.is_nan()); @@ -367,17 +425,59 @@ set_linear_velocity(const LVector3 &velocity) { */ void BulletRigidBodyNode:: set_angular_velocity(const LVector3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!velocity.is_nan()); _rigid->setAngularVelocity(LVecBase3_to_btVector3(velocity)); } +/** + * + */ +void BulletRigidBodyNode:: +set_linear_damping(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _rigid->setDamping(value, _rigid->getAngularDamping()); +} + +/** + * + */ +void BulletRigidBodyNode:: +set_angular_damping(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _rigid->setDamping(_rigid->getLinearDamping(), value); +} + +/** + * + */ +PN_stdfloat BulletRigidBodyNode:: +get_linear_damping() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_rigid->getLinearDamping(); +} + +/** + * + */ +PN_stdfloat BulletRigidBodyNode:: +get_angular_damping() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_rigid->getAngularDamping(); +} + /** * */ void BulletRigidBodyNode:: clear_forces() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _rigid->clearForces(); } @@ -387,6 +487,7 @@ clear_forces() { */ PN_stdfloat BulletRigidBodyNode:: get_linear_sleep_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _rigid->getLinearSleepingThreshold(); } @@ -396,6 +497,7 @@ get_linear_sleep_threshold() const { */ PN_stdfloat BulletRigidBodyNode:: get_angular_sleep_threshold() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _rigid->getAngularSleepingThreshold(); } @@ -405,6 +507,7 @@ get_angular_sleep_threshold() const { */ void BulletRigidBodyNode:: set_linear_sleep_threshold(PN_stdfloat threshold) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _rigid->setSleepingThresholds(threshold, _rigid->getAngularSleepingThreshold()); } @@ -414,6 +517,7 @@ set_linear_sleep_threshold(PN_stdfloat threshold) { */ void BulletRigidBodyNode:: set_angular_sleep_threshold(PN_stdfloat threshold) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _rigid->setSleepingThresholds(_rigid->getLinearSleepingThreshold(), threshold); } @@ -423,6 +527,7 @@ set_angular_sleep_threshold(PN_stdfloat threshold) { */ void BulletRigidBodyNode:: set_gravity(const LVector3 &gravity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv_always(!gravity.is_nan()); @@ -434,6 +539,7 @@ set_gravity(const LVector3 &gravity) { */ LVector3 BulletRigidBodyNode:: get_gravity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getGravity()); } @@ -443,6 +549,7 @@ get_gravity() const { */ LVector3 BulletRigidBodyNode:: get_linear_factor() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getLinearFactor()); } @@ -452,6 +559,7 @@ get_linear_factor() const { */ LVector3 BulletRigidBodyNode:: get_angular_factor() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getAngularFactor()); } @@ -461,6 +569,7 @@ get_angular_factor() const { */ void BulletRigidBodyNode:: set_linear_factor(const LVector3 &factor) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _rigid->setLinearFactor(LVecBase3_to_btVector3(factor)); } @@ -470,6 +579,7 @@ set_linear_factor(const LVector3 &factor) { */ void BulletRigidBodyNode:: set_angular_factor(const LVector3 &factor) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _rigid->setAngularFactor(LVecBase3_to_btVector3(factor)); } @@ -479,6 +589,7 @@ set_angular_factor(const LVector3 &factor) { */ LVector3 BulletRigidBodyNode:: get_total_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getTotalForce()); } @@ -488,6 +599,7 @@ get_total_force() const { */ LVector3 BulletRigidBodyNode:: get_total_torque() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_rigid->getTotalTorque()); } diff --git a/panda/src/bullet/bulletRigidBodyNode.h b/panda/src/bullet/bulletRigidBodyNode.h index c8afaeb8bb..641fdc9fd9 100644 --- a/panda/src/bullet/bulletRigidBodyNode.h +++ b/panda/src/bullet/bulletRigidBodyNode.h @@ -50,10 +50,10 @@ PUBLISHED: void set_angular_velocity(const LVector3 &velocity); // Damping - INLINE PN_stdfloat get_linear_damping() const; - INLINE PN_stdfloat get_angular_damping() const; - INLINE void set_linear_damping(PN_stdfloat value); - INLINE void set_angular_damping(PN_stdfloat value); + PN_stdfloat get_linear_damping() const; + PN_stdfloat get_angular_damping() const; + void set_linear_damping(PN_stdfloat value); + void set_angular_damping(PN_stdfloat value); // Forces void clear_forces(); @@ -108,14 +108,18 @@ public: virtual void output(ostream &out) const; - void sync_p2b(); - void sync_b2p(); + void do_sync_p2b(); + void do_sync_b2p(); protected: virtual void transform_changed(); private: - virtual void shape_changed(); + virtual void do_shape_changed(); + void do_transform_changed(); + + void do_set_mass(PN_stdfloat mass); + PN_stdfloat do_get_mass() const; // The motion state is used for synchronisation between Bullet and the // Panda3D scene graph. diff --git a/panda/src/bullet/bulletRotationalLimitMotor.I b/panda/src/bullet/bulletRotationalLimitMotor.I index 10ed68435c..35b923a9d3 100644 --- a/panda/src/bullet/bulletRotationalLimitMotor.I +++ b/panda/src/bullet/bulletRotationalLimitMotor.I @@ -14,162 +14,7 @@ /** * */ -INLINE bool BulletRotationalLimitMotor:: -is_limited() const { +INLINE BulletRotationalLimitMotor:: +~BulletRotationalLimitMotor() { - return _motor.isLimited(); -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_motor_enabled(bool enabled) { - - _motor.m_enableMotor = enabled; -} - -/** - * - */ -INLINE bool BulletRotationalLimitMotor:: -get_motor_enabled() const { - - return _motor.m_enableMotor; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_low_limit(PN_stdfloat limit) { - - _motor.m_loLimit = (btScalar)limit; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_high_limit(PN_stdfloat limit) { - - _motor.m_hiLimit = (btScalar)limit; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_target_velocity(PN_stdfloat velocity) { - - _motor.m_targetVelocity = (btScalar)velocity; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_max_motor_force(PN_stdfloat force) { - - _motor.m_maxMotorForce = (btScalar)force; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_max_limit_force(PN_stdfloat force) { - - _motor.m_maxLimitForce = (btScalar)force; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_damping(PN_stdfloat damping) { - - _motor.m_damping = (btScalar)damping; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_softness(PN_stdfloat softness) { - - _motor.m_limitSoftness = (btScalar)softness; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_bounce(PN_stdfloat bounce) { - - _motor.m_bounce = (btScalar)bounce; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_normal_cfm(PN_stdfloat cfm) { - - _motor.m_normalCFM = (btScalar)cfm; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_stop_cfm(PN_stdfloat cfm) { - - _motor.m_stopCFM = (btScalar)cfm; -} - -/** - * - */ -INLINE void BulletRotationalLimitMotor:: -set_stop_erp(PN_stdfloat erp) { - - _motor.m_stopERP = (btScalar)erp; -} - -/** - * Retrieves the current value of angle: 0 = free, 1 = at low limit, 2 = at - * high limit. - */ -INLINE int BulletRotationalLimitMotor:: -get_current_limit() const { - - return _motor.m_currentLimit; -} - -/** - * - */ -INLINE PN_stdfloat BulletRotationalLimitMotor:: -get_current_error() const { - - return (PN_stdfloat)_motor.m_currentLimitError; -} - -/** - * - */ -INLINE PN_stdfloat BulletRotationalLimitMotor:: -get_current_position() const { - - return (PN_stdfloat)_motor.m_currentPosition; -} - -/** - * - */ -INLINE PN_stdfloat BulletRotationalLimitMotor:: -get_accumulated_impulse() const { - - return (PN_stdfloat)_motor.m_accumulatedImpulse; } diff --git a/panda/src/bullet/bulletRotationalLimitMotor.cxx b/panda/src/bullet/bulletRotationalLimitMotor.cxx index ce95a1f8d7..d521b7ad94 100644 --- a/panda/src/bullet/bulletRotationalLimitMotor.cxx +++ b/panda/src/bullet/bulletRotationalLimitMotor.cxx @@ -34,7 +34,179 @@ BulletRotationalLimitMotor(const BulletRotationalLimitMotor ©) /** * */ -BulletRotationalLimitMotor:: -~BulletRotationalLimitMotor() { +bool BulletRotationalLimitMotor:: +is_limited() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + return _motor.isLimited(); +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_motor_enabled(bool enabled) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_enableMotor = enabled; +} + +/** + * + */ +bool BulletRotationalLimitMotor:: +get_motor_enabled() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _motor.m_enableMotor; +} +/** + * + */ +void BulletRotationalLimitMotor:: +set_low_limit(PN_stdfloat limit) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_loLimit = (btScalar)limit; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_high_limit(PN_stdfloat limit) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_hiLimit = (btScalar)limit; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_target_velocity(PN_stdfloat velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_targetVelocity = (btScalar)velocity; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_max_motor_force(PN_stdfloat force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_maxMotorForce = (btScalar)force; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_max_limit_force(PN_stdfloat force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_maxLimitForce = (btScalar)force; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_damping(PN_stdfloat damping) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_damping = (btScalar)damping; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_softness(PN_stdfloat softness) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_limitSoftness = (btScalar)softness; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_bounce(PN_stdfloat bounce) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_bounce = (btScalar)bounce; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_normal_cfm(PN_stdfloat cfm) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_normalCFM = (btScalar)cfm; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_stop_cfm(PN_stdfloat cfm) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_stopCFM = (btScalar)cfm; +} + +/** + * + */ +void BulletRotationalLimitMotor:: +set_stop_erp(PN_stdfloat erp) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_stopERP = (btScalar)erp; +} + +/** + * Retrieves the current value of angle: 0 = free, 1 = at low limit, 2 = at + * high limit. + */ +int BulletRotationalLimitMotor:: +get_current_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _motor.m_currentLimit; +} + +/** + * + */ +PN_stdfloat BulletRotationalLimitMotor:: +get_current_error() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_motor.m_currentLimitError; +} + +/** + * + */ +PN_stdfloat BulletRotationalLimitMotor:: +get_current_position() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_motor.m_currentPosition; +} + +/** + * + */ +PN_stdfloat BulletRotationalLimitMotor:: +get_accumulated_impulse() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_motor.m_accumulatedImpulse; } diff --git a/panda/src/bullet/bulletRotationalLimitMotor.h b/panda/src/bullet/bulletRotationalLimitMotor.h index a1cce18ff4..d046cd9171 100644 --- a/panda/src/bullet/bulletRotationalLimitMotor.h +++ b/panda/src/bullet/bulletRotationalLimitMotor.h @@ -28,27 +28,27 @@ class EXPCL_PANDABULLET BulletRotationalLimitMotor { PUBLISHED: BulletRotationalLimitMotor(const BulletRotationalLimitMotor ©); - ~BulletRotationalLimitMotor(); + INLINE ~BulletRotationalLimitMotor(); - INLINE void set_motor_enabled(bool enable); - INLINE void set_low_limit(PN_stdfloat limit); - INLINE void set_high_limit(PN_stdfloat limit); - INLINE void set_target_velocity(PN_stdfloat velocity); - INLINE void set_max_motor_force(PN_stdfloat force); - INLINE void set_max_limit_force(PN_stdfloat force); - INLINE void set_damping(PN_stdfloat damping); - INLINE void set_softness(PN_stdfloat softness); - INLINE void set_bounce(PN_stdfloat bounce); - INLINE void set_normal_cfm(PN_stdfloat cfm); - INLINE void set_stop_cfm(PN_stdfloat cfm); - INLINE void set_stop_erp(PN_stdfloat erp); + void set_motor_enabled(bool enable); + void set_low_limit(PN_stdfloat limit); + void set_high_limit(PN_stdfloat limit); + void set_target_velocity(PN_stdfloat velocity); + void set_max_motor_force(PN_stdfloat force); + void set_max_limit_force(PN_stdfloat force); + void set_damping(PN_stdfloat damping); + void set_softness(PN_stdfloat softness); + void set_bounce(PN_stdfloat bounce); + void set_normal_cfm(PN_stdfloat cfm); + void set_stop_cfm(PN_stdfloat cfm); + void set_stop_erp(PN_stdfloat erp); - INLINE bool is_limited() const; - INLINE bool get_motor_enabled() const; - INLINE int get_current_limit() const; - INLINE PN_stdfloat get_current_error() const; - INLINE PN_stdfloat get_current_position() const; - INLINE PN_stdfloat get_accumulated_impulse() const; + bool is_limited() const; + bool get_motor_enabled() const; + int get_current_limit() const; + PN_stdfloat get_current_error() const; + PN_stdfloat get_current_position() const; + PN_stdfloat get_accumulated_impulse() const; MAKE_PROPERTY(limited, is_limited); MAKE_PROPERTY(motor_enabled, get_motor_enabled, set_motor_enabled); diff --git a/panda/src/bullet/bulletShape.I b/panda/src/bullet/bulletShape.I index 35123a868f..c408ccb95b 100644 --- a/panda/src/bullet/bulletShape.I +++ b/panda/src/bullet/bulletShape.I @@ -18,66 +18,3 @@ INLINE BulletShape:: ~BulletShape() { } - -/** - * - */ -INLINE bool BulletShape:: -is_polyhedral() const { - - return ptr()->isPolyhedral(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_convex() const { - - return ptr()->isConvex(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_convex_2d() const { - - return ptr()->isConvex2d(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_concave() const { - - return ptr()->isConcave(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_infinite() const { - - return ptr()->isInfinite(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_non_moving() const { - - return ptr()->isNonMoving(); -} - -/** - * - */ -INLINE bool BulletShape:: -is_soft_body() const { - - return ptr()->isSoftBody(); -} diff --git a/panda/src/bullet/bulletShape.cxx b/panda/src/bullet/bulletShape.cxx index daf8c1e623..49bd6e4f92 100644 --- a/panda/src/bullet/bulletShape.cxx +++ b/panda/src/bullet/bulletShape.cxx @@ -21,6 +21,7 @@ TypeHandle BulletShape::_type_handle; */ const char *BulletShape:: get_name() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return ptr()->getName(); } @@ -30,6 +31,7 @@ get_name() const { */ PN_stdfloat BulletShape:: get_margin() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return ptr()->getMargin(); } @@ -39,6 +41,7 @@ get_margin() const { */ void BulletShape:: set_margin(PN_stdfloat margin) { + LightMutexHolder holder(BulletWorld::get_global_lock()); ptr()->setMargin(margin); } @@ -48,18 +51,29 @@ set_margin(PN_stdfloat margin) { */ LVecBase3 BulletShape:: get_local_scale() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVecBase3(ptr()->getLocalScaling()); } +/** + * Assumes the lock(bullet global lock) is held by the caller + */ +void BulletShape:: +do_set_local_scale(const LVecBase3 &scale) { + + nassertv(!scale.is_nan()); + ptr()->setLocalScaling(LVecBase3_to_btVector3(scale)); +} + /** * */ void BulletShape:: set_local_scale(const LVecBase3 &scale) { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertv(!scale.is_nan()); - ptr()->setLocalScaling(LVecBase3_to_btVector3(scale)); + do_set_local_scale(scale); } /** @@ -67,6 +81,7 @@ set_local_scale(const LVecBase3 &scale) { */ BoundingSphere BulletShape:: get_shape_bounds() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); /* btTransform tr; @@ -87,3 +102,73 @@ cout << "origin " << aabbMin.x() << " " << aabbMin.y() << " " << aabbMin.z() << return bounds; } + +/** + * + */ +bool BulletShape:: +is_polyhedral() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isPolyhedral(); +} + +/** + * + */ +bool BulletShape:: +is_convex() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isConvex(); +} + +/** + * + */ +bool BulletShape:: +is_convex_2d() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isConvex2d(); +} + +/** + * + */ +bool BulletShape:: +is_concave() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isConcave(); +} + +/** + * + */ +bool BulletShape:: +is_infinite() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isInfinite(); +} + +/** + * + */ +bool BulletShape:: +is_non_moving() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isNonMoving(); +} + +/** + * + */ +bool BulletShape:: +is_soft_body() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return ptr()->isSoftBody(); +} diff --git a/panda/src/bullet/bulletShape.h b/panda/src/bullet/bulletShape.h index 8ebeaf9290..e9dd08bf14 100644 --- a/panda/src/bullet/bulletShape.h +++ b/panda/src/bullet/bulletShape.h @@ -31,13 +31,13 @@ protected: PUBLISHED: INLINE virtual ~BulletShape(); - INLINE bool is_polyhedral() const; - INLINE bool is_convex() const; - INLINE bool is_convex_2d() const; - INLINE bool is_concave() const; - INLINE bool is_infinite() const; - INLINE bool is_non_moving() const; - INLINE bool is_soft_body() const; + bool is_polyhedral() const; + bool is_convex() const; + bool is_convex_2d() const; + bool is_concave() const; + bool is_infinite() const; + bool is_non_moving() const; + bool is_soft_body() const; void set_margin(PN_stdfloat margin); const char *get_name() const; @@ -61,6 +61,7 @@ public: virtual btCollisionShape *ptr() const = 0; LVecBase3 get_local_scale() const; void set_local_scale(const LVecBase3 &scale); + void do_set_local_scale(const LVecBase3 &scale); public: static TypeHandle get_class_type() { diff --git a/panda/src/bullet/bulletSliderConstraint.I b/panda/src/bullet/bulletSliderConstraint.I index 4035f1399f..3eca50b143 100644 --- a/panda/src/bullet/bulletSliderConstraint.I +++ b/panda/src/bullet/bulletSliderConstraint.I @@ -19,21 +19,3 @@ INLINE BulletSliderConstraint:: delete _constraint; } - -/** - * - */ -INLINE CPT(TransformState) BulletSliderConstraint:: -get_frame_a() const { - - return btTrans_to_TransformState(_constraint->getFrameOffsetA()); -} - -/** - * - */ -INLINE CPT(TransformState) BulletSliderConstraint:: -get_frame_b() const { - - return btTrans_to_TransformState(_constraint->getFrameOffsetB()); -} diff --git a/panda/src/bullet/bulletSliderConstraint.cxx b/panda/src/bullet/bulletSliderConstraint.cxx index cda213b8c2..c803f509cd 100644 --- a/panda/src/bullet/bulletSliderConstraint.cxx +++ b/panda/src/bullet/bulletSliderConstraint.cxx @@ -65,6 +65,7 @@ ptr() const { */ PN_stdfloat BulletSliderConstraint:: get_lower_linear_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getLowerLinLimit(); } @@ -74,6 +75,7 @@ get_lower_linear_limit() const { */ PN_stdfloat BulletSliderConstraint:: get_upper_linear_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getUpperLinLimit(); } @@ -83,6 +85,7 @@ get_upper_linear_limit() const { */ PN_stdfloat BulletSliderConstraint:: get_lower_angular_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return rad_2_deg(_constraint->getLowerAngLimit()); } @@ -92,6 +95,7 @@ get_lower_angular_limit() const { */ PN_stdfloat BulletSliderConstraint:: get_upper_angular_limit() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return rad_2_deg(_constraint->getUpperAngLimit()); } @@ -101,6 +105,7 @@ get_upper_angular_limit() const { */ void BulletSliderConstraint:: set_lower_linear_limit(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setLowerLinLimit((btScalar)value); } @@ -110,6 +115,7 @@ set_lower_linear_limit(PN_stdfloat value) { */ void BulletSliderConstraint:: set_upper_linear_limit(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setUpperLinLimit((btScalar)value); } @@ -119,6 +125,7 @@ set_upper_linear_limit(PN_stdfloat value) { */ void BulletSliderConstraint:: set_lower_angular_limit(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setLowerAngLimit((btScalar)deg_2_rad(value)); } @@ -128,6 +135,7 @@ set_lower_angular_limit(PN_stdfloat value) { */ void BulletSliderConstraint:: set_upper_angular_limit(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setUpperAngLimit((btScalar)deg_2_rad(value)); } @@ -137,6 +145,7 @@ set_upper_angular_limit(PN_stdfloat value) { */ PN_stdfloat BulletSliderConstraint:: get_linear_pos() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getLinearPos(); } @@ -146,6 +155,7 @@ get_linear_pos() const { */ PN_stdfloat BulletSliderConstraint:: get_angular_pos() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getAngularPos(); } @@ -155,6 +165,7 @@ get_angular_pos() const { */ void BulletSliderConstraint:: set_powered_linear_motor(bool on) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setPoweredLinMotor(on); } @@ -164,6 +175,7 @@ set_powered_linear_motor(bool on) { */ void BulletSliderConstraint:: set_target_linear_motor_velocity(PN_stdfloat target_velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setTargetLinMotorVelocity((btScalar)target_velocity); } @@ -173,6 +185,7 @@ set_target_linear_motor_velocity(PN_stdfloat target_velocity) { */ void BulletSliderConstraint:: set_max_linear_motor_force(PN_stdfloat max_force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMaxLinMotorForce((btScalar)max_force); } @@ -182,6 +195,7 @@ set_max_linear_motor_force(PN_stdfloat max_force) { */ bool BulletSliderConstraint:: get_powered_linear_motor() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _constraint->getPoweredLinMotor(); } @@ -191,6 +205,7 @@ get_powered_linear_motor() const { */ PN_stdfloat BulletSliderConstraint:: get_target_linear_motor_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getTargetLinMotorVelocity(); } @@ -200,6 +215,7 @@ get_target_linear_motor_velocity() const { */ PN_stdfloat BulletSliderConstraint:: get_max_linear_motor_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getMaxLinMotorForce(); } @@ -209,6 +225,7 @@ get_max_linear_motor_force() const { */ void BulletSliderConstraint:: set_powered_angular_motor(bool on) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setPoweredAngMotor(on); } @@ -218,6 +235,7 @@ set_powered_angular_motor(bool on) { */ void BulletSliderConstraint:: set_target_angular_motor_velocity(PN_stdfloat target_velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setTargetAngMotorVelocity((btScalar)target_velocity); } @@ -227,6 +245,7 @@ set_target_angular_motor_velocity(PN_stdfloat target_velocity) { */ void BulletSliderConstraint:: set_max_angular_motor_force(PN_stdfloat max_force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _constraint->setMaxAngMotorForce((btScalar)max_force); } @@ -236,6 +255,7 @@ set_max_angular_motor_force(PN_stdfloat max_force) { */ bool BulletSliderConstraint:: get_powered_angular_motor() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _constraint->getPoweredAngMotor(); } @@ -245,6 +265,7 @@ get_powered_angular_motor() const { */ PN_stdfloat BulletSliderConstraint:: get_target_angular_motor_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getTargetAngMotorVelocity(); } @@ -254,6 +275,7 @@ get_target_angular_motor_velocity() const { */ PN_stdfloat BulletSliderConstraint:: get_max_angular_motor_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_constraint->getMaxAngMotorForce(); } @@ -263,9 +285,30 @@ get_max_angular_motor_force() const { */ void BulletSliderConstraint:: set_frames(const TransformState *ts_a, const TransformState *ts_b) { + LightMutexHolder holder(BulletWorld::get_global_lock()); btTransform frame_a = TransformState_to_btTrans(ts_a); btTransform frame_b = TransformState_to_btTrans(ts_b); _constraint->setFrames(frame_a, frame_b); } + +/** + * + */ +CPT(TransformState) BulletSliderConstraint:: +get_frame_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getFrameOffsetA()); +} + +/** + * + */ +CPT(TransformState) BulletSliderConstraint:: +get_frame_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btTrans_to_TransformState(_constraint->getFrameOffsetB()); +} diff --git a/panda/src/bullet/bulletSliderConstraint.h b/panda/src/bullet/bulletSliderConstraint.h index 931e51ec80..6a670867c5 100644 --- a/panda/src/bullet/bulletSliderConstraint.h +++ b/panda/src/bullet/bulletSliderConstraint.h @@ -70,8 +70,8 @@ PUBLISHED: // Frames void set_frames(const TransformState *ts_a, const TransformState *ts_b); - INLINE CPT(TransformState) get_frame_a() const; - INLINE CPT(TransformState) get_frame_b() const; + CPT(TransformState) get_frame_a() const; + CPT(TransformState) get_frame_b() const; MAKE_PROPERTY(linear_pos, get_linear_pos); MAKE_PROPERTY(angular_pos, get_angular_pos); diff --git a/panda/src/bullet/bulletSoftBodyConfig.I b/panda/src/bullet/bulletSoftBodyConfig.I index eed9499bbb..dfd2b36514 100644 --- a/panda/src/bullet/bulletSoftBodyConfig.I +++ b/panda/src/bullet/bulletSoftBodyConfig.I @@ -18,439 +18,3 @@ INLINE BulletSoftBodyConfig:: ~BulletSoftBodyConfig() { } - -/** - * Getter for property kVCF. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_velocities_correction_factor() const { - - return (PN_stdfloat)_cfg.kVCF; -} - -/** - * Setter for property kVCF. - */ -INLINE void BulletSoftBodyConfig:: -set_velocities_correction_factor(PN_stdfloat value) { - - _cfg.kVCF = (btScalar)value; -} - -/** - * Getter for property kDP. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_damping_coefficient() const { - - return (PN_stdfloat)_cfg.kDP; -} - -/** - * Setter for property kDP. - */ -INLINE void BulletSoftBodyConfig:: -set_damping_coefficient(PN_stdfloat value) { - - _cfg.kDP = (btScalar)value; -} - -/** - * Getter for property kDG. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_drag_coefficient() const { - - return (PN_stdfloat)_cfg.kDG; -} - -/** - * Setter for property kDG. - */ -INLINE void BulletSoftBodyConfig:: -set_drag_coefficient(PN_stdfloat value) { - - _cfg.kDG = (btScalar)value; -} - -/** - * Getter for property kLF. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_lift_coefficient() const { - - return (PN_stdfloat)_cfg.kLF; -} - -/** - * Setter for property kLF. - */ -INLINE void BulletSoftBodyConfig:: -set_lift_coefficient(PN_stdfloat value) { - - _cfg.kLF = (btScalar)value; -} - -/** - * Getter for property kPR. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_pressure_coefficient() const { - - return (PN_stdfloat)_cfg.kPR; -} - -/** - * Setter for property kPR. - */ -INLINE void BulletSoftBodyConfig:: -set_pressure_coefficient(PN_stdfloat value) { - - _cfg.kPR = (btScalar)value; -} - -/** - * Getter for property kVC. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_volume_conservation_coefficient() const { - - return (PN_stdfloat)_cfg.kVC; -} - -/** - * Setter for property kVC. - */ -INLINE void BulletSoftBodyConfig:: -set_volume_conservation_coefficient(PN_stdfloat value) { - - _cfg.kVC = (btScalar)value; -} - -/** - * Getter for property kDF. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_dynamic_friction_coefficient() const { - - return (PN_stdfloat)_cfg.kDF; -} - -/** - * Setter for property kDF. - */ -INLINE void BulletSoftBodyConfig:: -set_dynamic_friction_coefficient(PN_stdfloat value) { - - _cfg.kDF = (btScalar)value; -} - -/** - * Getter for property kMT. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_pose_matching_coefficient() const { - - return (PN_stdfloat)_cfg.kMT; -} - -/** - * Setter for property kMT. - */ -INLINE void BulletSoftBodyConfig:: -set_pose_matching_coefficient(PN_stdfloat value) { - - _cfg.kMT = (btScalar)value; -} - -/** - * Getter for property kCHR. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_rigid_contacts_hardness() const { - - return (PN_stdfloat)_cfg.kCHR; -} - -/** - * Setter for property kCHR. - */ -INLINE void BulletSoftBodyConfig:: -set_rigid_contacts_hardness(PN_stdfloat value) { - - _cfg.kCHR = (btScalar)value; -} - -/** - * Getter for property kKHR. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_kinetic_contacts_hardness() const { - - return (PN_stdfloat)_cfg.kKHR; -} - -/** - * Setter for property kKHR. - */ -INLINE void BulletSoftBodyConfig:: -set_kinetic_contacts_hardness(PN_stdfloat value) { - - _cfg.kKHR = (btScalar)value; -} - -/** - * Getter for property kSHR. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_contacts_hardness() const { - - return (PN_stdfloat)_cfg.kSHR; -} - -/** - * Setter for property kSHR. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_contacts_hardness(PN_stdfloat value) { - - _cfg.kSHR = (btScalar)value; -} - -/** - * Getter for property kAHR. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_anchors_hardness() const { - - return (PN_stdfloat)_cfg.kAHR; -} - -/** - * Setter for property kAHR. - */ -INLINE void BulletSoftBodyConfig:: -set_anchors_hardness(PN_stdfloat value) { - - _cfg.kAHR = (btScalar)value; -} - -/** - * Getter for property kSRHR_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_rigid_hardness() const { - - return (PN_stdfloat)_cfg.kSRHR_CL; -} - -/** - * Setter for property kSRHR_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_rigid_hardness(PN_stdfloat value) { - - _cfg.kSRHR_CL = (btScalar)value; -} - -/** - * Getter for property kSKHR_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_kinetic_hardness() const { - - return (PN_stdfloat)_cfg.kSKHR_CL; -} - -/** - * Setter for property kSKHR_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_kinetic_hardness(PN_stdfloat value) { - - _cfg.kSKHR_CL = (btScalar)value; -} - -/** - * Getter for property kSSHR_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_soft_hardness() const { - - return (PN_stdfloat)_cfg.kSSHR_CL; -} - -/** - * Setter for property kSSHR_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_soft_hardness(PN_stdfloat value) { - - _cfg.kSSHR_CL = (btScalar)value; -} - -/** - * Getter for property kSR_SPLT_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_rigid_impulse_split() const { - - return (PN_stdfloat)_cfg.kSR_SPLT_CL; -} - -/** - * Setter for property kSR_SPLT_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_rigid_impulse_split(PN_stdfloat value) { - - _cfg.kSR_SPLT_CL = (btScalar)value; -} - -/** - * Getter for property kSK_SPLT_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_kinetic_impulse_split() const { - - return (PN_stdfloat)_cfg.kSK_SPLT_CL; -} - -/** - * Setter for property kSK_SPLT_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_kinetic_impulse_split(PN_stdfloat value) { - - _cfg.kSK_SPLT_CL = (btScalar)value; -} - -/** - * Getter for property kSS_SPLT_CL. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_soft_vs_soft_impulse_split() const { - - return (PN_stdfloat)_cfg.kSS_SPLT_CL; -} - -/** - * Setter for property kSS_SPLT_CL. - */ -INLINE void BulletSoftBodyConfig:: -set_soft_vs_soft_impulse_split(PN_stdfloat value) { - - _cfg.kSS_SPLT_CL = (btScalar)value; -} - -/** - * Getter for property maxvolume. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_maxvolume() const { - - return (PN_stdfloat)_cfg.maxvolume; -} - -/** - * Setter for property maxvolume. - */ -INLINE void BulletSoftBodyConfig:: -set_maxvolume(PN_stdfloat value) { - - _cfg.maxvolume = (btScalar)value; -} - -/** - * Getter for property timescale. - */ -INLINE PN_stdfloat BulletSoftBodyConfig:: -get_timescale() const { - - return (PN_stdfloat)_cfg.timescale; -} - -/** - * Setter for property timescale. - */ -INLINE void BulletSoftBodyConfig:: -set_timescale(PN_stdfloat value) { - - _cfg.timescale = (btScalar)value; -} - -/** - * Getter for property piterations. - */ -INLINE int BulletSoftBodyConfig:: -get_positions_solver_iterations() const { - - return _cfg.piterations; -} - -/** - * Setter for property piterations. - */ -INLINE void BulletSoftBodyConfig:: -set_positions_solver_iterations(int value) { - - nassertv(value > 0); - _cfg.piterations = value; -} - -/** - * Getter for property viterations. - */ -INLINE int BulletSoftBodyConfig:: -get_velocities_solver_iterations() const { - - return _cfg.viterations; -} - -/** - * Setter for property viterations. - */ -INLINE void BulletSoftBodyConfig:: -set_velocities_solver_iterations(int value) { - - nassertv(value > 0); - _cfg.viterations = value; -} - -/** - * Getter for property diterations. - */ -INLINE int BulletSoftBodyConfig:: -get_drift_solver_iterations() const { - - return _cfg.diterations; -} - -/** - * Setter for property diterations. - */ -INLINE void BulletSoftBodyConfig:: -set_drift_solver_iterations(int value) { - - nassertv(value > 0); - _cfg.diterations = value; -} - -/** - * Getter for property citerations. - */ -INLINE int BulletSoftBodyConfig:: -get_cluster_solver_iterations() const { - - return _cfg.citerations; -} - -/** - * Setter for property citerations. - */ -INLINE void BulletSoftBodyConfig:: -set_cluster_solver_iterations(int value) { - - nassertv(value > 0); - _cfg.citerations = value; -} diff --git a/panda/src/bullet/bulletSoftBodyConfig.cxx b/panda/src/bullet/bulletSoftBodyConfig.cxx index dc12fde309..a6db77cb96 100644 --- a/panda/src/bullet/bulletSoftBodyConfig.cxx +++ b/panda/src/bullet/bulletSoftBodyConfig.cxx @@ -26,6 +26,7 @@ BulletSoftBodyConfig(btSoftBody::Config &cfg) : _cfg(cfg) { */ void BulletSoftBodyConfig:: clear_all_collision_flags() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _cfg.collisions = 0; } @@ -35,6 +36,7 @@ clear_all_collision_flags() { */ void BulletSoftBodyConfig:: set_collision_flag(CollisionFlag flag, bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); if (value == true) { _cfg.collisions |= flag; @@ -49,6 +51,7 @@ set_collision_flag(CollisionFlag flag, bool value) { */ bool BulletSoftBodyConfig:: get_collision_flag(CollisionFlag flag) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (_cfg.collisions & flag) ? true : false; } @@ -58,6 +61,7 @@ get_collision_flag(CollisionFlag flag) const { */ void BulletSoftBodyConfig:: set_aero_model(AeroModel value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _cfg.aeromodel = (btSoftBody::eAeroModel::_)value; } @@ -67,6 +71,491 @@ set_aero_model(AeroModel value) { */ BulletSoftBodyConfig::AeroModel BulletSoftBodyConfig:: get_aero_model() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (AeroModel)_cfg.aeromodel; } + +/** + * Getter for property kVCF. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_velocities_correction_factor() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kVCF; +} + +/** + * Setter for property kVCF. + */ +void BulletSoftBodyConfig:: +set_velocities_correction_factor(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kVCF = (btScalar)value; +} + +/** + * Getter for property kDP. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_damping_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kDP; +} + +/** + * Setter for property kDP. + */ +void BulletSoftBodyConfig:: +set_damping_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kDP = (btScalar)value; +} + +/** + * Getter for property kDG. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_drag_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kDG; +} + +/** + * Setter for property kDG. + */ +void BulletSoftBodyConfig:: +set_drag_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kDG = (btScalar)value; +} + +/** + * Getter for property kLF. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_lift_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kLF; +} + +/** + * Setter for property kLF. + */ +void BulletSoftBodyConfig:: +set_lift_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kLF = (btScalar)value; +} + +/** + * Getter for property kPR. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_pressure_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kPR; +} + +/** + * Setter for property kPR. + */ +void BulletSoftBodyConfig:: +set_pressure_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kPR = (btScalar)value; +} + +/** + * Getter for property kVC. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_volume_conservation_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kVC; +} + +/** + * Setter for property kVC. + */ +void BulletSoftBodyConfig:: +set_volume_conservation_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kVC = (btScalar)value; +} + +/** + * Getter for property kDF. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_dynamic_friction_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kDF; +} + +/** + * Setter for property kDF. + */ +void BulletSoftBodyConfig:: +set_dynamic_friction_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kDF = (btScalar)value; +} + +/** + * Getter for property kMT. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_pose_matching_coefficient() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kMT; +} + +/** + * Setter for property kMT. + */ +void BulletSoftBodyConfig:: +set_pose_matching_coefficient(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kMT = (btScalar)value; +} + +/** + * Getter for property kCHR. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_rigid_contacts_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kCHR; +} + +/** + * Setter for property kCHR. + */ +void BulletSoftBodyConfig:: +set_rigid_contacts_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kCHR = (btScalar)value; +} + +/** + * Getter for property kKHR. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_kinetic_contacts_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kKHR; +} + +/** + * Setter for property kKHR. + */ +void BulletSoftBodyConfig:: +set_kinetic_contacts_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kKHR = (btScalar)value; +} + +/** + * Getter for property kSHR. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_contacts_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSHR; +} + +/** + * Setter for property kSHR. + */ +void BulletSoftBodyConfig:: +set_soft_contacts_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSHR = (btScalar)value; +} + +/** + * Getter for property kAHR. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_anchors_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kAHR; +} + +/** + * Setter for property kAHR. + */ +void BulletSoftBodyConfig:: +set_anchors_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kAHR = (btScalar)value; +} + +/** + * Getter for property kSRHR_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_rigid_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSRHR_CL; +} + +/** + * Setter for property kSRHR_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_rigid_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSRHR_CL = (btScalar)value; +} + +/** + * Getter for property kSKHR_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_kinetic_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSKHR_CL; +} + +/** + * Setter for property kSKHR_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_kinetic_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSKHR_CL = (btScalar)value; +} + +/** + * Getter for property kSSHR_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_soft_hardness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSSHR_CL; +} + +/** + * Setter for property kSSHR_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_soft_hardness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSSHR_CL = (btScalar)value; +} + +/** + * Getter for property kSR_SPLT_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_rigid_impulse_split() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSR_SPLT_CL; +} + +/** + * Setter for property kSR_SPLT_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_rigid_impulse_split(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSR_SPLT_CL = (btScalar)value; +} + +/** + * Getter for property kSK_SPLT_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_kinetic_impulse_split() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSK_SPLT_CL; +} + +/** + * Setter for property kSK_SPLT_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_kinetic_impulse_split(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSK_SPLT_CL = (btScalar)value; +} + +/** + * Getter for property kSS_SPLT_CL. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_soft_vs_soft_impulse_split() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.kSS_SPLT_CL; +} + +/** + * Setter for property kSS_SPLT_CL. + */ +void BulletSoftBodyConfig:: +set_soft_vs_soft_impulse_split(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.kSS_SPLT_CL = (btScalar)value; +} + +/** + * Getter for property maxvolume. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_maxvolume() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.maxvolume; +} + +/** + * Setter for property maxvolume. + */ +void BulletSoftBodyConfig:: +set_maxvolume(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.maxvolume = (btScalar)value; +} + +/** + * Getter for property timescale. + */ +PN_stdfloat BulletSoftBodyConfig:: +get_timescale() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_cfg.timescale; +} + +/** + * Setter for property timescale. + */ +void BulletSoftBodyConfig:: +set_timescale(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _cfg.timescale = (btScalar)value; +} + +/** + * Getter for property piterations. + */ +int BulletSoftBodyConfig:: +get_positions_solver_iterations() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _cfg.piterations; +} + +/** + * Setter for property piterations. + */ +void BulletSoftBodyConfig:: +set_positions_solver_iterations(int value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(value > 0); + _cfg.piterations = value; +} + +/** + * Getter for property viterations. + */ +int BulletSoftBodyConfig:: +get_velocities_solver_iterations() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _cfg.viterations; +} + +/** + * Setter for property viterations. + */ +void BulletSoftBodyConfig:: +set_velocities_solver_iterations(int value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(value > 0); + _cfg.viterations = value; +} + +/** + * Getter for property diterations. + */ +int BulletSoftBodyConfig:: +get_drift_solver_iterations() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _cfg.diterations; +} + +/** + * Setter for property diterations. + */ +void BulletSoftBodyConfig:: +set_drift_solver_iterations(int value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(value > 0); + _cfg.diterations = value; +} + +/** + * Getter for property citerations. + */ +int BulletSoftBodyConfig:: +get_cluster_solver_iterations() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _cfg.citerations; +} + +/** + * Setter for property citerations. + */ +void BulletSoftBodyConfig:: +set_cluster_solver_iterations(int value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(value > 0); + _cfg.citerations = value; +} diff --git a/panda/src/bullet/bulletSoftBodyConfig.h b/panda/src/bullet/bulletSoftBodyConfig.h index 2411797146..18bbd49dfa 100644 --- a/panda/src/bullet/bulletSoftBodyConfig.h +++ b/panda/src/bullet/bulletSoftBodyConfig.h @@ -51,55 +51,55 @@ PUBLISHED: void set_aero_model(AeroModel value); AeroModel get_aero_model() const; - INLINE void set_velocities_correction_factor(PN_stdfloat value); - INLINE void set_damping_coefficient(PN_stdfloat value); - INLINE void set_drag_coefficient(PN_stdfloat value); - INLINE void set_lift_coefficient(PN_stdfloat value); - INLINE void set_pressure_coefficient(PN_stdfloat value); - INLINE void set_volume_conservation_coefficient(PN_stdfloat value); - INLINE void set_dynamic_friction_coefficient(PN_stdfloat value); - INLINE void set_pose_matching_coefficient(PN_stdfloat value); - INLINE void set_rigid_contacts_hardness(PN_stdfloat value); - INLINE void set_kinetic_contacts_hardness(PN_stdfloat value); - INLINE void set_soft_contacts_hardness(PN_stdfloat value); - INLINE void set_anchors_hardness(PN_stdfloat value); - INLINE void set_soft_vs_rigid_hardness(PN_stdfloat value); - INLINE void set_soft_vs_kinetic_hardness(PN_stdfloat value); - INLINE void set_soft_vs_soft_hardness(PN_stdfloat value); - INLINE void set_soft_vs_rigid_impulse_split(PN_stdfloat value); - INLINE void set_soft_vs_kinetic_impulse_split(PN_stdfloat value); - INLINE void set_soft_vs_soft_impulse_split(PN_stdfloat value); - INLINE void set_maxvolume(PN_stdfloat value); - INLINE void set_timescale(PN_stdfloat value); - INLINE void set_positions_solver_iterations(int value); - INLINE void set_velocities_solver_iterations(int value); - INLINE void set_drift_solver_iterations( int value); - INLINE void set_cluster_solver_iterations(int value); + void set_velocities_correction_factor(PN_stdfloat value); + void set_damping_coefficient(PN_stdfloat value); + void set_drag_coefficient(PN_stdfloat value); + void set_lift_coefficient(PN_stdfloat value); + void set_pressure_coefficient(PN_stdfloat value); + void set_volume_conservation_coefficient(PN_stdfloat value); + void set_dynamic_friction_coefficient(PN_stdfloat value); + void set_pose_matching_coefficient(PN_stdfloat value); + void set_rigid_contacts_hardness(PN_stdfloat value); + void set_kinetic_contacts_hardness(PN_stdfloat value); + void set_soft_contacts_hardness(PN_stdfloat value); + void set_anchors_hardness(PN_stdfloat value); + void set_soft_vs_rigid_hardness(PN_stdfloat value); + void set_soft_vs_kinetic_hardness(PN_stdfloat value); + void set_soft_vs_soft_hardness(PN_stdfloat value); + void set_soft_vs_rigid_impulse_split(PN_stdfloat value); + void set_soft_vs_kinetic_impulse_split(PN_stdfloat value); + void set_soft_vs_soft_impulse_split(PN_stdfloat value); + void set_maxvolume(PN_stdfloat value); + void set_timescale(PN_stdfloat value); + void set_positions_solver_iterations(int value); + void set_velocities_solver_iterations(int value); + void set_drift_solver_iterations( int value); + void set_cluster_solver_iterations(int value); - INLINE PN_stdfloat get_velocities_correction_factor() const; - INLINE PN_stdfloat get_damping_coefficient() const; - INLINE PN_stdfloat get_drag_coefficient() const; - INLINE PN_stdfloat get_lift_coefficient() const; - INLINE PN_stdfloat get_pressure_coefficient() const; - INLINE PN_stdfloat get_volume_conservation_coefficient() const; - INLINE PN_stdfloat get_dynamic_friction_coefficient() const; - INLINE PN_stdfloat get_pose_matching_coefficient() const; - INLINE PN_stdfloat get_rigid_contacts_hardness() const; - INLINE PN_stdfloat get_kinetic_contacts_hardness() const; - INLINE PN_stdfloat get_soft_contacts_hardness() const; - INLINE PN_stdfloat get_anchors_hardness() const; - INLINE PN_stdfloat get_soft_vs_rigid_hardness() const; - INLINE PN_stdfloat get_soft_vs_kinetic_hardness() const; - INLINE PN_stdfloat get_soft_vs_soft_hardness() const; - INLINE PN_stdfloat get_soft_vs_rigid_impulse_split() const; - INLINE PN_stdfloat get_soft_vs_kinetic_impulse_split() const; - INLINE PN_stdfloat get_soft_vs_soft_impulse_split() const; - INLINE PN_stdfloat get_maxvolume() const; - INLINE PN_stdfloat get_timescale() const; - INLINE int get_positions_solver_iterations() const; - INLINE int get_velocities_solver_iterations() const; - INLINE int get_drift_solver_iterations() const; - INLINE int get_cluster_solver_iterations() const; + PN_stdfloat get_velocities_correction_factor() const; + PN_stdfloat get_damping_coefficient() const; + PN_stdfloat get_drag_coefficient() const; + PN_stdfloat get_lift_coefficient() const; + PN_stdfloat get_pressure_coefficient() const; + PN_stdfloat get_volume_conservation_coefficient() const; + PN_stdfloat get_dynamic_friction_coefficient() const; + PN_stdfloat get_pose_matching_coefficient() const; + PN_stdfloat get_rigid_contacts_hardness() const; + PN_stdfloat get_kinetic_contacts_hardness() const; + PN_stdfloat get_soft_contacts_hardness() const; + PN_stdfloat get_anchors_hardness() const; + PN_stdfloat get_soft_vs_rigid_hardness() const; + PN_stdfloat get_soft_vs_kinetic_hardness() const; + PN_stdfloat get_soft_vs_soft_hardness() const; + PN_stdfloat get_soft_vs_rigid_impulse_split() const; + PN_stdfloat get_soft_vs_kinetic_impulse_split() const; + PN_stdfloat get_soft_vs_soft_impulse_split() const; + PN_stdfloat get_maxvolume() const; + PN_stdfloat get_timescale() const; + int get_positions_solver_iterations() const; + int get_velocities_solver_iterations() const; + int get_drift_solver_iterations() const; + int get_cluster_solver_iterations() const; MAKE_PROPERTY(aero_model, get_aero_model, set_aero_model); MAKE_PROPERTY(velocities_correction_factor, get_velocities_correction_factor, set_velocities_correction_factor); diff --git a/panda/src/bullet/bulletSoftBodyMaterial.I b/panda/src/bullet/bulletSoftBodyMaterial.I index ff8182f6ed..7514fc7cbf 100644 --- a/panda/src/bullet/bulletSoftBodyMaterial.I +++ b/panda/src/bullet/bulletSoftBodyMaterial.I @@ -30,66 +30,3 @@ empty() { return BulletSoftBodyMaterial(material); } - -/** - * - */ -INLINE btSoftBody::Material &BulletSoftBodyMaterial:: -get_material() const { - - return _material; -} - -/** - * Getter for the property m_kLST. - */ -INLINE PN_stdfloat BulletSoftBodyMaterial:: -get_linear_stiffness() const { - - return (PN_stdfloat)_material.m_kLST; -} - -/** - * Setter for the property m_kLST. - */ -INLINE void BulletSoftBodyMaterial:: -set_linear_stiffness(PN_stdfloat value) { - - _material.m_kLST = (btScalar)value; -} - -/** - * Getter for the property m_kAST. - */ -INLINE PN_stdfloat BulletSoftBodyMaterial:: -get_angular_stiffness() const { - - return (PN_stdfloat)_material.m_kAST; -} - -/** - * Setter for the property m_kAST. - */ -INLINE void BulletSoftBodyMaterial:: -set_angular_stiffness(PN_stdfloat value) { - - _material.m_kAST = (btScalar)value; -} - -/** - * Getter for the property m_kVST. - */ -INLINE PN_stdfloat BulletSoftBodyMaterial:: -get_volume_preservation() const { - - return (PN_stdfloat)_material.m_kVST; -} - -/** - * Setter for the property m_kVST. - */ -INLINE void BulletSoftBodyMaterial:: -set_volume_preservation(PN_stdfloat value) { - - _material.m_kVST = (btScalar)value; -} diff --git a/panda/src/bullet/bulletSoftBodyMaterial.cxx b/panda/src/bullet/bulletSoftBodyMaterial.cxx index 1767513a27..d40a7bd984 100644 --- a/panda/src/bullet/bulletSoftBodyMaterial.cxx +++ b/panda/src/bullet/bulletSoftBodyMaterial.cxx @@ -20,3 +20,72 @@ BulletSoftBodyMaterial:: BulletSoftBodyMaterial(btSoftBody::Material &material) : _material(material) { } + +/** + * + */ +btSoftBody::Material &BulletSoftBodyMaterial:: +get_material() const { + + return _material; +} + +/** + * Getter for the property m_kLST. + */ +PN_stdfloat BulletSoftBodyMaterial:: +get_linear_stiffness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_material.m_kLST; +} + +/** + * Setter for the property m_kLST. + */ +void BulletSoftBodyMaterial:: +set_linear_stiffness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _material.m_kLST = (btScalar)value; +} + +/** + * Getter for the property m_kAST. + */ +PN_stdfloat BulletSoftBodyMaterial:: +get_angular_stiffness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_material.m_kAST; +} + +/** + * Setter for the property m_kAST. + */ +void BulletSoftBodyMaterial:: +set_angular_stiffness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _material.m_kAST = (btScalar)value; +} + +/** + * Getter for the property m_kVST. + */ +PN_stdfloat BulletSoftBodyMaterial:: +get_volume_preservation() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_material.m_kVST; +} + +/** + * Setter for the property m_kVST. + */ +void BulletSoftBodyMaterial:: +set_volume_preservation(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _material.m_kVST = (btScalar)value; +} diff --git a/panda/src/bullet/bulletSoftBodyMaterial.h b/panda/src/bullet/bulletSoftBodyMaterial.h index 3f1c07a7aa..bf8c8589a9 100644 --- a/panda/src/bullet/bulletSoftBodyMaterial.h +++ b/panda/src/bullet/bulletSoftBodyMaterial.h @@ -27,14 +27,14 @@ PUBLISHED: INLINE ~BulletSoftBodyMaterial(); INLINE static BulletSoftBodyMaterial empty(); - INLINE PN_stdfloat get_linear_stiffness() const; - INLINE void set_linear_stiffness(PN_stdfloat value); + PN_stdfloat get_linear_stiffness() const; + void set_linear_stiffness(PN_stdfloat value); - INLINE PN_stdfloat get_angular_stiffness() const; - INLINE void set_angular_stiffness(PN_stdfloat value); - - INLINE PN_stdfloat get_volume_preservation() const; - INLINE void set_volume_preservation(PN_stdfloat value); + PN_stdfloat get_angular_stiffness() const; + void set_angular_stiffness(PN_stdfloat value); + + PN_stdfloat get_volume_preservation() const; + void set_volume_preservation(PN_stdfloat value); MAKE_PROPERTY(linear_stiffness, get_linear_stiffness, set_linear_stiffness); MAKE_PROPERTY(angular_stiffness, get_angular_stiffness, set_angular_stiffness); diff --git a/panda/src/bullet/bulletSoftBodyNode.I b/panda/src/bullet/bulletSoftBodyNode.I index 086c3396e7..6a60de43f1 100644 --- a/panda/src/bullet/bulletSoftBodyNode.I +++ b/panda/src/bullet/bulletSoftBodyNode.I @@ -40,56 +40,3 @@ empty() { return BulletSoftBodyNodeElement(node); } -/** - * - */ -INLINE LPoint3 BulletSoftBodyNodeElement:: -get_pos() const { - - return btVector3_to_LPoint3(_node.m_x); -} - -/** - * - */ -INLINE LVector3 BulletSoftBodyNodeElement:: -get_normal() const { - - return btVector3_to_LVector3(_node.m_n); -} - -/** - * - */ -INLINE LVector3 BulletSoftBodyNodeElement:: -get_velocity() const { - - return btVector3_to_LVector3(_node.m_v); -} - -/** - * - */ -INLINE PN_stdfloat BulletSoftBodyNodeElement:: -get_inv_mass() const { - - return (PN_stdfloat)_node.m_im; -} - -/** - * - */ -INLINE PN_stdfloat BulletSoftBodyNodeElement:: -get_area() const { - - return (PN_stdfloat)_node.m_area; -} - -/** - * - */ -INLINE int BulletSoftBodyNodeElement:: -is_attached() const { - - return (PN_stdfloat)_node.m_battach; -} diff --git a/panda/src/bullet/bulletSoftBodyNode.cxx b/panda/src/bullet/bulletSoftBodyNode.cxx index 1d5a70d93f..c4094af652 100644 --- a/panda/src/bullet/bulletSoftBodyNode.cxx +++ b/panda/src/bullet/bulletSoftBodyNode.cxx @@ -66,6 +66,7 @@ get_object() const { */ BulletSoftBodyConfig BulletSoftBodyNode:: get_cfg() { + LightMutexHolder holder(BulletWorld::get_global_lock()); return BulletSoftBodyConfig(_soft->m_cfg); } @@ -75,6 +76,7 @@ get_cfg() { */ BulletSoftBodyWorldInfo BulletSoftBodyNode:: get_world_info() { + LightMutexHolder holder(BulletWorld::get_global_lock()); return BulletSoftBodyWorldInfo(*(_soft->m_worldInfo)); } @@ -84,6 +86,7 @@ get_world_info() { */ int BulletSoftBodyNode:: get_num_materials() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->m_materials.size(); } @@ -93,8 +96,9 @@ get_num_materials() const { */ BulletSoftBodyMaterial BulletSoftBodyNode:: get_material(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertr(idx >= 0 && idx < get_num_materials(), BulletSoftBodyMaterial::empty()); + nassertr(idx >= 0 && idx < _soft->m_materials.size(), BulletSoftBodyMaterial::empty()); btSoftBody::Material *material = _soft->m_materials[idx]; return BulletSoftBodyMaterial(*material); @@ -105,6 +109,7 @@ get_material(int idx) const { */ BulletSoftBodyMaterial BulletSoftBodyNode:: append_material() { + LightMutexHolder holder(BulletWorld::get_global_lock()); btSoftBody::Material *material = _soft->appendMaterial(); nassertr(material, BulletSoftBodyMaterial::empty()); @@ -117,6 +122,7 @@ append_material() { */ int BulletSoftBodyNode:: get_num_nodes() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->m_nodes.size(); } @@ -126,6 +132,7 @@ get_num_nodes() const { */ BulletSoftBodyNodeElement BulletSoftBodyNode:: get_node(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertr(idx >=0 && idx < get_num_nodes(), BulletSoftBodyNodeElement::empty()); return BulletSoftBodyNodeElement(_soft->m_nodes[idx]); @@ -136,6 +143,7 @@ get_node(int idx) const { */ void BulletSoftBodyNode:: generate_bending_constraints(int distance, BulletSoftBodyMaterial *material) { + LightMutexHolder holder(BulletWorld::get_global_lock()); if (material) { _soft->generateBendingConstraints(distance, &(material->get_material())); @@ -150,6 +158,7 @@ generate_bending_constraints(int distance, BulletSoftBodyMaterial *material) { */ void BulletSoftBodyNode:: randomize_constraints() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->randomizeConstraints(); } @@ -159,9 +168,10 @@ randomize_constraints() { */ void BulletSoftBodyNode:: transform_changed() { - if (_sync_disable) return; + LightMutexHolder holder(BulletWorld::get_global_lock()); + NodePath np = NodePath::any_path((PandaNode *)this); CPT(TransformState) ts = np.get_net_transform(); @@ -174,7 +184,7 @@ transform_changed() { btTransform trans = TransformState_to_btTrans(ts); // Offset between current approx center and current initial transform - btVector3 pos = LVecBase3_to_btVector3(this->get_aabb().get_approx_center()); + btVector3 pos = LVecBase3_to_btVector3(this->do_get_aabb().get_approx_center()); btVector3 origin = _soft->m_initialWorldTransform.getOrigin(); btVector3 offset = pos - origin; @@ -205,16 +215,16 @@ transform_changed() { * */ void BulletSoftBodyNode:: -sync_p2b() { +do_sync_p2b() { // transform_changed(); Disabled for now... } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletSoftBodyNode:: -sync_b2p() { +do_sync_b2p() { // Render softbody if (_geom) { @@ -266,7 +276,7 @@ sync_b2p() { // Update the synchronized transform with the current approximate center of // the soft body - LVecBase3 pos = this->get_aabb().get_approx_center(); + LVecBase3 pos = this->do_get_aabb().get_approx_center(); CPT(TransformState) ts = TransformState::make_pos(pos); NodePath np = NodePath::any_path((PandaNode *)this); @@ -291,6 +301,19 @@ sync_b2p() { */ int BulletSoftBodyNode:: get_closest_node_index(LVecBase3 point, bool local) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_closest_node_index(point, local); +} + +/** + * Returns the index of the node which is closest to the given point. The + * distance between each node and the given point is computed in world space + * if local=false, and in local space if local=true. + * Assumes the lock(bullet global lock) is held by the caller + */ +int BulletSoftBodyNode:: +do_get_closest_node_index(LVecBase3 point, bool local) { btScalar max_dist_sqr = 1e30; btVector3 point_x = LVecBase3_to_btVector3(point); @@ -322,11 +345,12 @@ get_closest_node_index(LVecBase3 point, bool local) { */ void BulletSoftBodyNode:: link_geom(Geom *geom) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(geom->get_vertex_data()->has_column(InternalName::get_vertex())); nassertv(geom->get_vertex_data()->has_column(InternalName::get_normal())); - sync_p2b(); + do_sync_p2b(); _geom = geom; @@ -349,7 +373,7 @@ link_geom(Geom *geom) { while (!vertices.is_at_end()) { LVecBase3 point = vertices.get_data3(); - int node_idx = get_closest_node_index(point, true); + int node_idx = do_get_closest_node_index(point, true); indices.set_data1i(node_idx); } } @@ -359,6 +383,7 @@ link_geom(Geom *geom) { */ void BulletSoftBodyNode:: unlink_geom() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _geom = NULL; } @@ -368,6 +393,7 @@ unlink_geom() { */ void BulletSoftBodyNode:: link_curve(NurbsCurveEvaluator *curve) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(curve->get_num_vertices() == _soft->m_nodes.size()); @@ -379,6 +405,7 @@ link_curve(NurbsCurveEvaluator *curve) { */ void BulletSoftBodyNode:: unlink_curve() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _curve = NULL; } @@ -388,6 +415,7 @@ unlink_curve() { */ void BulletSoftBodyNode:: link_surface(NurbsSurfaceEvaluator *surface) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(surface->get_num_u_vertices() * surface->get_num_v_vertices() == _soft->m_nodes.size()); @@ -399,6 +427,7 @@ link_surface(NurbsSurfaceEvaluator *surface) { */ void BulletSoftBodyNode:: unlink_surface() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _surface = NULL; } @@ -408,6 +437,16 @@ unlink_surface() { */ BoundingBox BulletSoftBodyNode:: get_aabb() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_aabb(); +} + +/** + * + */ +BoundingBox BulletSoftBodyNode:: +do_get_aabb() const { btVector3 pMin; btVector3 pMax; @@ -425,6 +464,7 @@ get_aabb() const { */ void BulletSoftBodyNode:: set_volume_mass(PN_stdfloat mass) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setVolumeMass(mass); } @@ -434,6 +474,7 @@ set_volume_mass(PN_stdfloat mass) { */ void BulletSoftBodyNode:: set_total_mass(PN_stdfloat mass, bool fromfaces) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setTotalMass(mass, fromfaces); } @@ -443,6 +484,7 @@ set_total_mass(PN_stdfloat mass, bool fromfaces) { */ void BulletSoftBodyNode:: set_volume_density(PN_stdfloat density) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setVolumeDensity(density); } @@ -452,6 +494,7 @@ set_volume_density(PN_stdfloat density) { */ void BulletSoftBodyNode:: set_total_density(PN_stdfloat density) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setTotalDensity(density); } @@ -461,6 +504,7 @@ set_total_density(PN_stdfloat density) { */ void BulletSoftBodyNode:: set_mass(int node, PN_stdfloat mass) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setMass(node, mass); } @@ -470,6 +514,7 @@ set_mass(int node, PN_stdfloat mass) { */ PN_stdfloat BulletSoftBodyNode:: get_mass(int node) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->getMass(node); } @@ -479,6 +524,7 @@ get_mass(int node) const { */ PN_stdfloat BulletSoftBodyNode:: get_total_mass() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->getTotalMass(); } @@ -488,6 +534,7 @@ get_total_mass() const { */ PN_stdfloat BulletSoftBodyNode:: get_volume() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->getVolume(); } @@ -497,6 +544,7 @@ get_volume() const { */ void BulletSoftBodyNode:: add_force(const LVector3 &force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!force.is_nan()); _soft->addForce(LVecBase3_to_btVector3(force)); @@ -507,6 +555,7 @@ add_force(const LVector3 &force) { */ void BulletSoftBodyNode:: add_force(const LVector3 &force, int node) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!force.is_nan()); _soft->addForce(LVecBase3_to_btVector3(force), node); @@ -517,6 +566,7 @@ add_force(const LVector3 &force, int node) { */ void BulletSoftBodyNode:: set_velocity(const LVector3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!velocity.is_nan()); _soft->setVelocity(LVecBase3_to_btVector3(velocity)); @@ -527,6 +577,7 @@ set_velocity(const LVector3 &velocity) { */ void BulletSoftBodyNode:: add_velocity(const LVector3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!velocity.is_nan()); _soft->addVelocity(LVecBase3_to_btVector3(velocity)); @@ -537,6 +588,7 @@ add_velocity(const LVector3 &velocity) { */ void BulletSoftBodyNode:: add_velocity(const LVector3 &velocity, int node) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!velocity.is_nan()); _soft->addVelocity(LVecBase3_to_btVector3(velocity), node); @@ -547,6 +599,7 @@ add_velocity(const LVector3 &velocity, int node) { */ void BulletSoftBodyNode:: generate_clusters(int k, int maxiterations) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->generateClusters(k, maxiterations); } @@ -556,6 +609,7 @@ generate_clusters(int k, int maxiterations) { */ void BulletSoftBodyNode:: release_clusters() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->releaseClusters(); } @@ -565,6 +619,7 @@ release_clusters() { */ void BulletSoftBodyNode:: release_cluster(int index) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->releaseCluster(index); } @@ -574,6 +629,7 @@ release_cluster(int index) { */ int BulletSoftBodyNode:: get_num_clusters() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _soft->clusterCount(); } @@ -583,6 +639,7 @@ get_num_clusters() const { */ LVecBase3 BulletSoftBodyNode:: cluster_com(int cluster) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVecBase3(_soft->clusterCom(cluster)); } @@ -592,6 +649,7 @@ cluster_com(int cluster) const { */ void BulletSoftBodyNode:: set_pose(bool bvolume, bool bframe) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _soft->setPose(bvolume, bframe); } @@ -601,11 +659,12 @@ set_pose(bool bvolume, bool bframe) { */ void BulletSoftBodyNode:: append_anchor(int node, BulletRigidBodyNode *body, bool disable) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(node < _soft->m_nodes.size()) nassertv(body); - body->sync_p2b(); + body->do_sync_p2b(); btRigidBody *ptr = (btRigidBody *)body->get_object(); _soft->appendAnchor(node, ptr, disable); @@ -616,12 +675,13 @@ append_anchor(int node, BulletRigidBodyNode *body, bool disable) { */ void BulletSoftBodyNode:: append_anchor(int node, BulletRigidBodyNode *body, const LVector3 &pivot, bool disable) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(node < _soft->m_nodes.size()) nassertv(body); nassertv(!pivot.is_nan()); - body->sync_p2b(); + body->do_sync_p2b(); btRigidBody *ptr = (btRigidBody *)body->get_object(); _soft->appendAnchor(node, ptr, LVecBase3_to_btVector3(pivot), disable); @@ -642,6 +702,7 @@ BulletSoftBodyNodeElement(btSoftBody::Node &node) : _node(node) { */ int BulletSoftBodyNode:: get_point_index(LVecBase3 p, PTA_LVecBase3 points) { + LightMutexHolder holder(BulletWorld::get_global_lock()); PN_stdfloat eps = 1.0e-6f; // TODO make this a config option @@ -979,6 +1040,7 @@ make_tet_mesh(BulletSoftBodyWorldInfo &info, const char *ele, const char *face, */ void BulletSoftBodyNode:: append_linear_joint(BulletBodyNode *body, int cluster, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(body); @@ -998,6 +1060,7 @@ append_linear_joint(BulletBodyNode *body, int cluster, PN_stdfloat erp, PN_stdfl */ void BulletSoftBodyNode:: append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(body); @@ -1017,6 +1080,7 @@ append_linear_joint(BulletBodyNode *body, const LPoint3 &pos, PN_stdfloat erp, P */ void BulletSoftBodyNode:: append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp, PN_stdfloat cfm, PN_stdfloat split, BulletSoftBodyControl *control) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(body); @@ -1037,6 +1101,7 @@ append_angular_joint(BulletBodyNode *body, const LVector3 &axis, PN_stdfloat erp */ void BulletSoftBodyNode:: set_wind_velocity(const LVector3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!velocity.is_nan()); _soft->setWindVelocity(LVecBase3_to_btVector3(velocity)); @@ -1047,6 +1112,67 @@ set_wind_velocity(const LVector3 &velocity) { */ LVector3 BulletSoftBodyNode:: get_wind_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_soft->getWindVelocity()); } + +/** + * + */ +LPoint3 BulletSoftBodyNodeElement:: +get_pos() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LPoint3(_node.m_x); +} + +/** + * + */ +LVector3 BulletSoftBodyNodeElement:: +get_normal() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_node.m_n); +} + +/** + * + */ +LVector3 BulletSoftBodyNodeElement:: +get_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_node.m_v); +} + +/** + * + */ +PN_stdfloat BulletSoftBodyNodeElement:: +get_inv_mass() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_node.m_im; +} + +/** + * + */ +PN_stdfloat BulletSoftBodyNodeElement:: +get_area() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_node.m_area; +} + +/** + * + */ +int BulletSoftBodyNodeElement:: +is_attached() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_node.m_battach; +} diff --git a/panda/src/bullet/bulletSoftBodyNode.h b/panda/src/bullet/bulletSoftBodyNode.h index 0f37217dfe..600e185fac 100644 --- a/panda/src/bullet/bulletSoftBodyNode.h +++ b/panda/src/bullet/bulletSoftBodyNode.h @@ -43,12 +43,12 @@ PUBLISHED: INLINE ~BulletSoftBodyNodeElement(); INLINE static BulletSoftBodyNodeElement empty(); - INLINE LPoint3 get_pos() const; - INLINE LVector3 get_velocity() const; - INLINE LVector3 get_normal() const; - INLINE PN_stdfloat get_inv_mass() const; - INLINE PN_stdfloat get_area() const; - INLINE int is_attached() const; + LPoint3 get_pos() const; + LVector3 get_velocity() const; + LVector3 get_normal() const; + PN_stdfloat get_inv_mass() const; + PN_stdfloat get_area() const; + int is_attached() const; MAKE_PROPERTY(pos, get_pos); MAKE_PROPERTY(velocity, get_velocity); @@ -221,8 +221,8 @@ PUBLISHED: public: virtual btCollisionObject *get_object() const; - void sync_p2b(); - void sync_b2p(); + void do_sync_p2b(); + void do_sync_b2p(); protected: virtual void transform_changed(); @@ -240,6 +240,9 @@ private: static int get_point_index(LVecBase3 p, PTA_LVecBase3 points); static int next_line(const char *buffer); + BoundingBox do_get_aabb() const; + int do_get_closest_node_index(LVecBase3 point, bool local); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/bullet/bulletSoftBodyShape.cxx b/panda/src/bullet/bulletSoftBodyShape.cxx index f28050ae3b..9e6aa2929b 100644 --- a/panda/src/bullet/bulletSoftBodyShape.cxx +++ b/panda/src/bullet/bulletSoftBodyShape.cxx @@ -40,6 +40,7 @@ ptr() const { */ BulletSoftBodyNode *BulletSoftBodyShape:: get_body() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); if (_shape->m_body) { return (BulletSoftBodyNode *)_shape->m_body->getUserPointer(); diff --git a/panda/src/bullet/bulletSoftBodyWorldInfo.cxx b/panda/src/bullet/bulletSoftBodyWorldInfo.cxx index ee1fddbc96..2fb6957c29 100644 --- a/panda/src/bullet/bulletSoftBodyWorldInfo.cxx +++ b/panda/src/bullet/bulletSoftBodyWorldInfo.cxx @@ -26,6 +26,7 @@ BulletSoftBodyWorldInfo(btSoftBodyWorldInfo &info) : _info(info) { */ void BulletSoftBodyWorldInfo:: garbage_collect(int lifetime) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_sparsesdf.GarbageCollect(lifetime); } @@ -35,6 +36,7 @@ garbage_collect(int lifetime) { */ void BulletSoftBodyWorldInfo:: set_air_density(PN_stdfloat density) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.air_density = (btScalar)density; } @@ -44,6 +46,7 @@ set_air_density(PN_stdfloat density) { */ void BulletSoftBodyWorldInfo:: set_water_density(PN_stdfloat density) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.water_density = (btScalar)density; } @@ -53,6 +56,7 @@ set_water_density(PN_stdfloat density) { */ void BulletSoftBodyWorldInfo:: set_water_offset(PN_stdfloat offset) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.water_offset = (btScalar)offset; } @@ -62,6 +66,7 @@ set_water_offset(PN_stdfloat offset) { */ void BulletSoftBodyWorldInfo:: set_water_normal(const LVector3 &normal) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!normal.is_nan()); _info.water_normal.setValue(normal.get_x(), normal.get_y(), normal.get_z()); @@ -72,6 +77,7 @@ set_water_normal(const LVector3 &normal) { */ void BulletSoftBodyWorldInfo:: set_gravity(const LVector3 &gravity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!gravity.is_nan()); _info.m_gravity.setValue(gravity.get_x(), gravity.get_y(), gravity.get_z()); @@ -82,6 +88,7 @@ set_gravity(const LVector3 &gravity) { */ PN_stdfloat BulletSoftBodyWorldInfo:: get_air_density() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.air_density; } @@ -91,6 +98,7 @@ get_air_density() const { */ PN_stdfloat BulletSoftBodyWorldInfo:: get_water_density() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.water_density; } @@ -100,6 +108,7 @@ get_water_density() const { */ PN_stdfloat BulletSoftBodyWorldInfo:: get_water_offset() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.water_offset; } @@ -109,6 +118,7 @@ get_water_offset() const { */ LVector3 BulletSoftBodyWorldInfo:: get_water_normal() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_info.water_normal); } @@ -118,6 +128,7 @@ get_water_normal() const { */ LVector3 BulletSoftBodyWorldInfo:: get_gravity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_info.m_gravity); } diff --git a/panda/src/bullet/bulletSphereShape.I b/panda/src/bullet/bulletSphereShape.I index a5177c572a..d410322298 100644 --- a/panda/src/bullet/bulletSphereShape.I +++ b/panda/src/bullet/bulletSphereShape.I @@ -20,24 +20,6 @@ INLINE BulletSphereShape:: delete _shape; } -/** - * - */ -INLINE BulletSphereShape:: -BulletSphereShape(const BulletSphereShape ©) : - _shape(copy._shape), - _radius(copy._radius) { -} - -/** - * - */ -INLINE void BulletSphereShape:: -operator = (const BulletSphereShape ©) { - _shape = copy._shape; - _radius = copy._radius; -} - /** * Returns the radius that was used to construct this sphere. */ diff --git a/panda/src/bullet/bulletSphereShape.cxx b/panda/src/bullet/bulletSphereShape.cxx index 4cda14882b..7b3fee62a4 100644 --- a/panda/src/bullet/bulletSphereShape.cxx +++ b/panda/src/bullet/bulletSphereShape.cxx @@ -25,6 +25,29 @@ BulletSphereShape(PN_stdfloat radius) : _radius(radius) { _shape->setUserPointer(this); } +/** + * + */ +BulletSphereShape:: +BulletSphereShape(const BulletSphereShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; +} + +/** + * + */ +void BulletSphereShape:: +operator = (const BulletSphereShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _shape = copy._shape; + _radius = copy._radius; +} + + /** * */ diff --git a/panda/src/bullet/bulletSphereShape.h b/panda/src/bullet/bulletSphereShape.h index c16a1279a6..b11d1c4a32 100644 --- a/panda/src/bullet/bulletSphereShape.h +++ b/panda/src/bullet/bulletSphereShape.h @@ -32,8 +32,8 @@ private: PUBLISHED: explicit BulletSphereShape(PN_stdfloat radius); - INLINE BulletSphereShape(const BulletSphereShape ©); - INLINE void operator = (const BulletSphereShape ©); + BulletSphereShape(const BulletSphereShape ©); + void operator = (const BulletSphereShape ©); INLINE ~BulletSphereShape(); INLINE PN_stdfloat get_radius() const; diff --git a/panda/src/bullet/bulletSphericalConstraint.cxx b/panda/src/bullet/bulletSphericalConstraint.cxx index 021dd69777..8686e1d546 100644 --- a/panda/src/bullet/bulletSphericalConstraint.cxx +++ b/panda/src/bullet/bulletSphericalConstraint.cxx @@ -61,6 +61,7 @@ ptr() const { */ void BulletSphericalConstraint:: set_pivot_a(const LPoint3 &pivot_a) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!pivot_a.is_nan()); _constraint->setPivotA(LVecBase3_to_btVector3(pivot_a)); @@ -71,6 +72,7 @@ set_pivot_a(const LPoint3 &pivot_a) { */ void BulletSphericalConstraint:: set_pivot_b(const LPoint3 &pivot_b) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!pivot_b.is_nan()); _constraint->setPivotB(LVecBase3_to_btVector3(pivot_b)); @@ -81,6 +83,7 @@ set_pivot_b(const LPoint3 &pivot_b) { */ LPoint3 BulletSphericalConstraint:: get_pivot_in_a() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_constraint->getPivotInA()); } @@ -90,6 +93,7 @@ get_pivot_in_a() const { */ LPoint3 BulletSphericalConstraint:: get_pivot_in_b() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_constraint->getPivotInB()); } diff --git a/panda/src/bullet/bulletTranslationalLimitMotor.I b/panda/src/bullet/bulletTranslationalLimitMotor.I index 2972994e39..7b41ab9618 100644 --- a/panda/src/bullet/bulletTranslationalLimitMotor.I +++ b/panda/src/bullet/bulletTranslationalLimitMotor.I @@ -14,164 +14,7 @@ /** * */ -INLINE bool BulletTranslationalLimitMotor:: -is_limited(int axis) const { +INLINE BulletTranslationalLimitMotor:: +~BulletTranslationalLimitMotor() { - nassertr((0 <= axis) && (axis <= 2), false); - return _motor.isLimited(axis); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_motor_enabled(int axis, bool enabled) { - - nassertv((0 <= axis) && (axis <= 2)); - _motor.m_enableMotor[axis] = enabled; -} - -/** - * - */ -INLINE bool BulletTranslationalLimitMotor:: -get_motor_enabled(int axis) const { - - nassertr((0 <= axis) && (axis <= 2), false); - return _motor.m_enableMotor[axis]; -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_low_limit(const LVecBase3 &limit) { - - nassertv(!limit.is_nan()); - _motor.m_lowerLimit = LVecBase3_to_btVector3(limit); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_high_limit(const LVecBase3 &limit) { - - nassertv(!limit.is_nan()); - _motor.m_upperLimit = LVecBase3_to_btVector3(limit); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_target_velocity(const LVecBase3 &velocity) { - - nassertv(!velocity.is_nan()); - _motor.m_targetVelocity = LVecBase3_to_btVector3(velocity); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_max_motor_force(const LVecBase3 &force) { - - nassertv(!force.is_nan()); - _motor.m_maxMotorForce = LVecBase3_to_btVector3(force); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_damping(PN_stdfloat damping) { - - _motor.m_damping = (btScalar)damping; -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_softness(PN_stdfloat softness) { - - _motor.m_limitSoftness = (btScalar)softness; -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_restitution(PN_stdfloat restitution) { - - _motor.m_restitution = (btScalar)restitution; -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_normal_cfm(const LVecBase3 &cfm) { - - nassertv(!cfm.is_nan()); - _motor.m_normalCFM = LVecBase3_to_btVector3(cfm); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_stop_cfm(const LVecBase3 &cfm) { - - nassertv(!cfm.is_nan()); - _motor.m_stopCFM = LVecBase3_to_btVector3(cfm); -} - -/** - * - */ -INLINE void BulletTranslationalLimitMotor:: -set_stop_erp(const LVecBase3 &erp) { - - nassertv(!erp.is_nan()); - _motor.m_stopERP = LVecBase3_to_btVector3(erp); -} - -/** - * Retrieves the current value of angle: 0 = free, 1 = at low limit, 2 = at - * high limit. - */ -INLINE int BulletTranslationalLimitMotor:: -get_current_limit(int axis) const { - - nassertr((0 <= axis) && (axis <= 2), false); - return _motor.m_currentLimit[axis]; -} - -/** - * - */ -INLINE LVector3 BulletTranslationalLimitMotor:: -get_current_error() const { - - return btVector3_to_LVector3(_motor.m_currentLimitError); -} - -/** - * - */ -INLINE LPoint3 BulletTranslationalLimitMotor:: -get_current_diff() const { - - return btVector3_to_LPoint3(_motor.m_currentLinearDiff); -} - -/** - * - */ -INLINE LVector3 BulletTranslationalLimitMotor:: -get_accumulated_impulse() const { - - return btVector3_to_LVector3(_motor.m_accumulatedImpulse); } diff --git a/panda/src/bullet/bulletTranslationalLimitMotor.cxx b/panda/src/bullet/bulletTranslationalLimitMotor.cxx index fdf0b55501..48dd7ae3e8 100644 --- a/panda/src/bullet/bulletTranslationalLimitMotor.cxx +++ b/panda/src/bullet/bulletTranslationalLimitMotor.cxx @@ -34,7 +34,182 @@ BulletTranslationalLimitMotor(const BulletTranslationalLimitMotor ©) /** * */ -BulletTranslationalLimitMotor:: -~BulletTranslationalLimitMotor() { +bool BulletTranslationalLimitMotor:: +is_limited(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + nassertr((0 <= axis) && (axis <= 2), false); + return _motor.isLimited(axis); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_motor_enabled(int axis, bool enabled) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv((0 <= axis) && (axis <= 2)); + _motor.m_enableMotor[axis] = enabled; +} + +/** + * + */ +bool BulletTranslationalLimitMotor:: +get_motor_enabled(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr((0 <= axis) && (axis <= 2), false); + return _motor.m_enableMotor[axis]; +} + + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_low_limit(const LVecBase3 &limit) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!limit.is_nan()); + _motor.m_lowerLimit = LVecBase3_to_btVector3(limit); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_high_limit(const LVecBase3 &limit) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!limit.is_nan()); + _motor.m_upperLimit = LVecBase3_to_btVector3(limit); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_target_velocity(const LVecBase3 &velocity) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!velocity.is_nan()); + _motor.m_targetVelocity = LVecBase3_to_btVector3(velocity); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_max_motor_force(const LVecBase3 &force) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!force.is_nan()); + _motor.m_maxMotorForce = LVecBase3_to_btVector3(force); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_damping(PN_stdfloat damping) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_damping = (btScalar)damping; +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_softness(PN_stdfloat softness) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_limitSoftness = (btScalar)softness; +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_restitution(PN_stdfloat restitution) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _motor.m_restitution = (btScalar)restitution; +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_normal_cfm(const LVecBase3 &cfm) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!cfm.is_nan()); + _motor.m_normalCFM = LVecBase3_to_btVector3(cfm); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_stop_cfm(const LVecBase3 &cfm) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!cfm.is_nan()); + _motor.m_stopCFM = LVecBase3_to_btVector3(cfm); +} + +/** + * + */ +void BulletTranslationalLimitMotor:: +set_stop_erp(const LVecBase3 &erp) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertv(!erp.is_nan()); + _motor.m_stopERP = LVecBase3_to_btVector3(erp); +} + +/** + * Retrieves the current value of angle: 0 = free, 1 = at low limit, 2 = at + * high limit. + */ +int BulletTranslationalLimitMotor:: +get_current_limit(int axis) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr((0 <= axis) && (axis <= 2), false); + return _motor.m_currentLimit[axis]; +} + +/** + * + */ +LVector3 BulletTranslationalLimitMotor:: +get_current_error() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_motor.m_currentLimitError); +} + +/** + * + */ +LPoint3 BulletTranslationalLimitMotor:: +get_current_diff() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LPoint3(_motor.m_currentLinearDiff); +} + +/** + * + */ +LVector3 BulletTranslationalLimitMotor:: +get_accumulated_impulse() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_motor.m_accumulatedImpulse); } diff --git a/panda/src/bullet/bulletTranslationalLimitMotor.h b/panda/src/bullet/bulletTranslationalLimitMotor.h index f339daefef..97c9909ede 100644 --- a/panda/src/bullet/bulletTranslationalLimitMotor.h +++ b/panda/src/bullet/bulletTranslationalLimitMotor.h @@ -28,26 +28,26 @@ class EXPCL_PANDABULLET BulletTranslationalLimitMotor { PUBLISHED: BulletTranslationalLimitMotor(const BulletTranslationalLimitMotor ©); - ~BulletTranslationalLimitMotor(); + INLINE ~BulletTranslationalLimitMotor(); - INLINE void set_motor_enabled(int axis, bool enable); - INLINE void set_low_limit(const LVecBase3 &limit); - INLINE void set_high_limit(const LVecBase3 &limit); - INLINE void set_target_velocity(const LVecBase3 &velocity); - INLINE void set_max_motor_force(const LVecBase3 &force); - INLINE void set_damping(PN_stdfloat damping); - INLINE void set_softness(PN_stdfloat softness); - INLINE void set_restitution(PN_stdfloat restitution); - INLINE void set_normal_cfm(const LVecBase3 &cfm); - INLINE void set_stop_erp(const LVecBase3 &erp); - INLINE void set_stop_cfm(const LVecBase3 &cfm); + void set_motor_enabled(int axis, bool enable); + void set_low_limit(const LVecBase3 &limit); + void set_high_limit(const LVecBase3 &limit); + void set_target_velocity(const LVecBase3 &velocity); + void set_max_motor_force(const LVecBase3 &force); + void set_damping(PN_stdfloat damping); + void set_softness(PN_stdfloat softness); + void set_restitution(PN_stdfloat restitution); + void set_normal_cfm(const LVecBase3 &cfm); + void set_stop_erp(const LVecBase3 &erp); + void set_stop_cfm(const LVecBase3 &cfm); - INLINE bool is_limited(int axis) const; - INLINE bool get_motor_enabled(int axis) const; - INLINE int get_current_limit(int axis) const; - INLINE LVector3 get_current_error() const; - INLINE LPoint3 get_current_diff() const; - INLINE LVector3 get_accumulated_impulse() const; + bool is_limited(int axis) const; + bool get_motor_enabled(int axis) const; + int get_current_limit(int axis) const; + LVector3 get_current_error() const; + LPoint3 get_current_diff() const; + LVector3 get_accumulated_impulse() const; MAKE_PROPERTY(current_error, get_current_error); MAKE_PROPERTY(current_diff, get_current_diff); diff --git a/panda/src/bullet/bulletTriangleMesh.I b/panda/src/bullet/bulletTriangleMesh.I index b6965303aa..33b9b9bf47 100644 --- a/panda/src/bullet/bulletTriangleMesh.I +++ b/panda/src/bullet/bulletTriangleMesh.I @@ -19,34 +19,6 @@ ptr() const { return (btStridingMeshInterface *)&_mesh; } -/** - * Returns the number of vertices in this triangle mesh. - */ -INLINE size_t BulletTriangleMesh:: -get_num_vertices() const { - return _vertices.size(); -} - -/** - * Returns the vertex at the given vertex index. - */ -INLINE LPoint3 BulletTriangleMesh:: -get_vertex(size_t index) const { - nassertr(index < _vertices.size(), LPoint3::zero()); - const btVector3 &vertex = _vertices[index]; - return LPoint3(vertex[0], vertex[1], vertex[2]); -} - -/** - * Returns the vertex indices making up the given triangle index. - */ -INLINE LVecBase3i BulletTriangleMesh:: -get_triangle(size_t index) const { - index *= 3; - nassertr(index + 2 < _indices.size(), LVecBase3i::zero()); - return LVecBase3i(_indices[index], _indices[index + 1], _indices[index + 2]); -} - /** * */ diff --git a/panda/src/bullet/bulletTriangleMesh.cxx b/panda/src/bullet/bulletTriangleMesh.cxx index 3138e28efd..e2d3e0b242 100644 --- a/panda/src/bullet/bulletTriangleMesh.cxx +++ b/panda/src/bullet/bulletTriangleMesh.cxx @@ -36,12 +36,58 @@ BulletTriangleMesh() _mesh.addIndexedMesh(mesh); } +/** + * Returns the number of vertices in this triangle mesh. + */ +size_t BulletTriangleMesh:: +get_num_vertices() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _vertices.size(); +} + +/** + * Returns the vertex at the given vertex index. + */ +LPoint3 BulletTriangleMesh:: +get_vertex(size_t index) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + nassertr(index < _vertices.size(), LPoint3::zero()); + const btVector3 &vertex = _vertices[index]; + return LPoint3(vertex[0], vertex[1], vertex[2]); +} + +/** + * Returns the vertex indices making up the given triangle index. + */ +LVecBase3i BulletTriangleMesh:: +get_triangle(size_t index) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + index *= 3; + nassertr(index + 2 < _indices.size(), LVecBase3i::zero()); + return LVecBase3i(_indices[index], _indices[index + 1], _indices[index + 2]); +} + +/** + * Returns the number of triangles in this triangle mesh. + * Assumes the lock(bullet global lock) is held by the caller + */ +size_t BulletTriangleMesh:: +do_get_num_triangles() const { + + return _indices.size() / 3; +} + /** * Returns the number of triangles in this triangle mesh. */ size_t BulletTriangleMesh:: get_num_triangles() const { - return _indices.size() / 3; + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return do_get_num_triangles(); } /** @@ -51,6 +97,8 @@ get_num_triangles() const { */ void BulletTriangleMesh:: preallocate(int num_verts, int num_indices) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + _vertices.reserve(num_verts); _indices.reserve(num_indices); @@ -66,9 +114,11 @@ preallocate(int num_verts, int num_indices) { * add duplicate vertices if they already exist in the triangle mesh, within * the tolerance specified by set_welding_distance(). This comes at a * significant performance cost, especially for large meshes. + * Assumes the lock(bullet global lock) is held by the caller */ void BulletTriangleMesh:: -add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices) { +do_add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices) { + nassertv(!p0.is_nan()); nassertv(!p1.is_nan()); nassertv(!p2.is_nan()); @@ -96,6 +146,21 @@ add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remov mesh.m_triangleIndexBase = (unsigned char *)&_indices[0]; } +/** + * Adds a triangle with the indicated coordinates. + * + * If remove_duplicate_vertices is true, it will make sure that it does not + * add duplicate vertices if they already exist in the triangle mesh, within + * the tolerance specified by set_welding_distance(). This comes at a + * significant performance cost, especially for large meshes. + */ +void BulletTriangleMesh:: +add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + do_add_triangle(p0, p1, p2, remove_duplicate_vertices); +} + /** * Sets the square of the distance at which vertices will be merged * together when adding geometry with remove_duplicate_vertices set to true. @@ -105,6 +170,8 @@ add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remov */ void BulletTriangleMesh:: set_welding_distance(PN_stdfloat distance) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + _welding_distance = distance; } @@ -114,6 +181,8 @@ set_welding_distance(PN_stdfloat distance) { */ PN_stdfloat BulletTriangleMesh:: get_welding_distance() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + return _welding_distance; } @@ -129,6 +198,8 @@ get_welding_distance() const { */ void BulletTriangleMesh:: add_geom(const Geom *geom, bool remove_duplicate_vertices, const TransformState *ts) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + nassertv(geom); nassertv(ts); @@ -241,6 +312,8 @@ add_geom(const Geom *geom, bool remove_duplicate_vertices, const TransformState */ void BulletTriangleMesh:: add_array(const PTA_LVecBase3 &points, const PTA_int &indices, bool remove_duplicate_vertices) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + btIndexedMesh &mesh = _mesh.getIndexedMeshArray()[0]; _indices.reserve(_indices.size() + indices.size()); @@ -279,7 +352,9 @@ add_array(const PTA_LVecBase3 &points, const PTA_int &indices, bool remove_dupli */ void BulletTriangleMesh:: output(ostream &out) const { - out << get_type() << ", " << get_num_triangles() << " triangles"; + LightMutexHolder holder(BulletWorld::get_global_lock()); + + out << get_type() << ", " << _indices.size() / 3 << " triangles"; } /** diff --git a/panda/src/bullet/bulletTriangleMesh.h b/panda/src/bullet/bulletTriangleMesh.h index 64973d83e8..0f9cb8174b 100644 --- a/panda/src/bullet/bulletTriangleMesh.h +++ b/panda/src/bullet/bulletTriangleMesh.h @@ -55,10 +55,16 @@ PUBLISHED: virtual void write(ostream &out, int indent_level) const; public: - INLINE size_t get_num_vertices() const; - INLINE LPoint3 get_vertex(size_t index) const; + size_t get_num_vertices() const; + LPoint3 get_vertex(size_t index) const; - INLINE LVecBase3i get_triangle(size_t index) const; + LVecBase3i get_triangle(size_t index) const; + + size_t do_get_num_triangles() const; + void do_add_triangle(const LPoint3 &p0, + const LPoint3 &p1, + const LPoint3 &p2, + bool remove_duplicate_vertices=false); PUBLISHED: MAKE_PROPERTY(welding_distance, get_welding_distance, set_welding_distance); diff --git a/panda/src/bullet/bulletTriangleMeshShape.I b/panda/src/bullet/bulletTriangleMeshShape.I index abb51607b4..f178723ebc 100644 --- a/panda/src/bullet/bulletTriangleMeshShape.I +++ b/panda/src/bullet/bulletTriangleMeshShape.I @@ -11,27 +11,6 @@ * @date 2010-02-09 */ -/** - * - */ -INLINE BulletTriangleMeshShape:: -BulletTriangleMeshShape(const BulletTriangleMeshShape ©) : - _bvh_shape(copy._bvh_shape), - _gimpact_shape(copy._gimpact_shape), - _mesh(copy._mesh) { -} - -/** - * - */ -INLINE void BulletTriangleMeshShape:: -operator = (const BulletTriangleMeshShape ©) { - - _bvh_shape = copy._bvh_shape; - _gimpact_shape = copy._gimpact_shape; - _mesh = copy._mesh; -} - /** * */ diff --git a/panda/src/bullet/bulletTriangleMeshShape.cxx b/panda/src/bullet/bulletTriangleMeshShape.cxx index 22775a6e0a..61905a406a 100644 --- a/panda/src/bullet/bulletTriangleMeshShape.cxx +++ b/panda/src/bullet/bulletTriangleMeshShape.cxx @@ -36,6 +36,7 @@ BulletTriangleMeshShape() : /** * The parameters 'compress' and 'bvh' are only used if 'dynamic' is set to * FALSE. + * Assumes the lock(bullet global lock) is held by the caller */ BulletTriangleMeshShape:: BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) : @@ -50,7 +51,7 @@ BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, b } // Assert that mesh has at least one triangle - if (mesh->get_num_triangles() == 0) { + if (mesh->do_get_num_triangles() == 0) { bullet_cat.warning() << "mesh has zero triangles! adding degenerated triangle." << endl; mesh->add_triangle(LPoint3::zero(), LPoint3::zero(), LPoint3::zero()); } @@ -78,6 +79,30 @@ BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, b } } +/** + * + */ +BulletTriangleMeshShape:: +BulletTriangleMeshShape(const BulletTriangleMeshShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _bvh_shape = copy._bvh_shape; + _gimpact_shape = copy._gimpact_shape; + _mesh = copy._mesh; +} + +/** + * + */ +void BulletTriangleMeshShape:: +operator = (const BulletTriangleMeshShape ©) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _bvh_shape = copy._bvh_shape; + _gimpact_shape = copy._gimpact_shape; + _mesh = copy._mesh; +} + /** * */ @@ -100,6 +125,7 @@ ptr() const { */ void BulletTriangleMeshShape:: refit_tree(const LPoint3 &aabb_min, const LPoint3 &aabb_max) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!aabb_max.is_nan()); nassertv(!aabb_max.is_nan()); diff --git a/panda/src/bullet/bulletTriangleMeshShape.h b/panda/src/bullet/bulletTriangleMeshShape.h index b76227b46e..079fb2aeb1 100644 --- a/panda/src/bullet/bulletTriangleMeshShape.h +++ b/panda/src/bullet/bulletTriangleMeshShape.h @@ -32,8 +32,8 @@ private: PUBLISHED: explicit BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress=true, bool bvh=true); - INLINE BulletTriangleMeshShape(const BulletTriangleMeshShape ©); - INLINE void operator = (const BulletTriangleMeshShape ©); + BulletTriangleMeshShape(const BulletTriangleMeshShape ©); + void operator = (const BulletTriangleMeshShape ©); INLINE ~BulletTriangleMeshShape(); void refit_tree(const LPoint3 &aabb_min, const LPoint3 &aabb_max); diff --git a/panda/src/bullet/bulletVehicle.I b/panda/src/bullet/bulletVehicle.I index b167ab5303..f4599a63e4 100644 --- a/panda/src/bullet/bulletVehicle.I +++ b/panda/src/bullet/bulletVehicle.I @@ -18,6 +18,7 @@ INLINE BulletVehicle:: ~BulletVehicle() { delete _vehicle; + delete _raycaster; } /** @@ -40,119 +41,3 @@ get_tuning() { return _tuning; } -/** - * Returns the number of wheels this vehicle has. - */ -INLINE int BulletVehicle:: -get_num_wheels() const { - - return _vehicle->getNumWheels(); -} - -/** - * - */ -void BulletVehicleTuning:: -set_suspension_stiffness(PN_stdfloat value) { - - _.m_suspensionStiffness = (btScalar)value; -} - -/** - * - */ -void BulletVehicleTuning:: -set_suspension_compression(PN_stdfloat value) { - - _.m_suspensionCompression = (btScalar)value; -} - -/** - * - */ -void BulletVehicleTuning:: -set_suspension_damping(PN_stdfloat value) { - - _.m_suspensionDamping = (btScalar)value; -} - -/** - * - */ -void BulletVehicleTuning:: -set_max_suspension_travel_cm(PN_stdfloat value) { - - _.m_maxSuspensionTravelCm = (btScalar)value; -} - -/** - * - */ -void BulletVehicleTuning:: -set_friction_slip(PN_stdfloat value) { - - _.m_frictionSlip = (btScalar)value; -} - -/** - * - */ -void BulletVehicleTuning:: -set_max_suspension_force(PN_stdfloat value) { - - _.m_maxSuspensionForce = (btScalar)value; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_suspension_stiffness() const { - - return (PN_stdfloat)_.m_suspensionStiffness; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_suspension_compression() const { - - return (PN_stdfloat)_.m_suspensionCompression; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_suspension_damping() const { - - return (PN_stdfloat)_.m_suspensionDamping; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_max_suspension_travel_cm() const { - - return (PN_stdfloat)_.m_maxSuspensionTravelCm; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_friction_slip() const { - - return (PN_stdfloat)_.m_frictionSlip; -} - -/** - * - */ -PN_stdfloat BulletVehicleTuning:: -get_max_suspension_force() const { - - return (PN_stdfloat)_.m_maxSuspensionForce; -} diff --git a/panda/src/bullet/bulletVehicle.cxx b/panda/src/bullet/bulletVehicle.cxx index 381f8ab6c8..e2d74c131d 100644 --- a/panda/src/bullet/bulletVehicle.cxx +++ b/panda/src/bullet/bulletVehicle.cxx @@ -39,6 +39,7 @@ BulletVehicle(BulletWorld *world, BulletRigidBodyNode *chassis) { */ void BulletVehicle:: set_coordinate_system(BulletUpAxis up) { + LightMutexHolder holder(BulletWorld::get_global_lock()); switch (up) { case X_up: @@ -62,18 +63,30 @@ set_coordinate_system(BulletUpAxis up) { */ LVector3 BulletVehicle:: get_forward_vector() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_vehicle->getForwardVector()); } +/** + * Returns the chassis of this vehicle. The chassis is a rigid body node. + * Assumes the lock(bullet global lock) is held by the caller + */ +BulletRigidBodyNode *BulletVehicle:: +do_get_chassis() { + + btRigidBody *bodyPtr = _vehicle->getRigidBody(); + return (bodyPtr) ? (BulletRigidBodyNode *)bodyPtr->getUserPointer() : NULL; +} + /** * Returns the chassis of this vehicle. The chassis is a rigid body node. */ BulletRigidBodyNode *BulletVehicle:: get_chassis() { + LightMutexHolder holder(BulletWorld::get_global_lock()); - btRigidBody *bodyPtr = _vehicle->getRigidBody(); - return (bodyPtr) ? (BulletRigidBodyNode *)bodyPtr->getUserPointer() : NULL; + return do_get_chassis(); } /** @@ -82,6 +95,7 @@ get_chassis() { */ PN_stdfloat BulletVehicle:: get_current_speed_km_hour() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_vehicle->getCurrentSpeedKmHour(); } @@ -91,6 +105,7 @@ get_current_speed_km_hour() const { */ void BulletVehicle:: reset_suspension() { + LightMutexHolder holder(BulletWorld::get_global_lock()); _vehicle->resetSuspension(); } @@ -100,8 +115,9 @@ reset_suspension() { */ PN_stdfloat BulletVehicle:: get_steering_value(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertr(idx < get_num_wheels(), 0.0f); + nassertr(idx < _vehicle->getNumWheels(), 0.0f); return rad_2_deg(_vehicle->getSteeringValue(idx)); } @@ -110,8 +126,9 @@ get_steering_value(int idx) const { */ void BulletVehicle:: set_steering_value(PN_stdfloat steering, int idx) { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertv(idx < get_num_wheels()); + nassertv(idx < _vehicle->getNumWheels()); _vehicle->setSteeringValue(deg_2_rad(steering), idx); } @@ -120,8 +137,9 @@ set_steering_value(PN_stdfloat steering, int idx) { */ void BulletVehicle:: apply_engine_force(PN_stdfloat force, int idx) { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertv(idx < get_num_wheels()); + nassertv(idx < _vehicle->getNumWheels()); _vehicle->applyEngineForce(force, idx); } @@ -130,8 +148,9 @@ apply_engine_force(PN_stdfloat force, int idx) { */ void BulletVehicle:: set_brake(PN_stdfloat brake, int idx) { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertv(idx < get_num_wheels()); + nassertv(idx < _vehicle->getNumWheels()); _vehicle->setBrake(brake, idx); } @@ -140,6 +159,7 @@ set_brake(PN_stdfloat brake, int idx) { */ void BulletVehicle:: set_pitch_control(PN_stdfloat pitch) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _vehicle->setPitchControl(pitch); } @@ -149,6 +169,7 @@ set_pitch_control(PN_stdfloat pitch) { */ BulletWheel BulletVehicle:: create_wheel() { + LightMutexHolder holder(BulletWorld::get_global_lock()); btVector3 pos(0.0, 0.0, 0.0); btVector3 direction = get_axis(_vehicle->getUpAxis()); @@ -182,24 +203,35 @@ get_axis(int idx) { } } +/** + * Returns the number of wheels this vehicle has. + */ +int BulletVehicle:: +get_num_wheels() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _vehicle->getNumWheels(); +} + /** * Returns the BulletWheel with index idx. Causes an AssertionError if idx is * equal or larger than the number of wheels. */ BulletWheel BulletVehicle:: get_wheel(int idx) const { + LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertr(idx < get_num_wheels(), BulletWheel::empty()); + nassertr(idx < _vehicle->getNumWheels(), BulletWheel::empty()); return BulletWheel(_vehicle->getWheelInfo(idx)); } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletVehicle:: -sync_b2p() { +do_sync_b2p() { - for (int i=0; i < get_num_wheels(); i++) { + for (int i=0; i < _vehicle->getNumWheels(); i++) { btWheelInfo info = _vehicle->getWheelInfo(i); PandaNode *node = (PandaNode *)info.m_clientInfo; @@ -216,3 +248,124 @@ sync_b2p() { } } } + +/** + * + */ +void BulletVehicleTuning:: +set_suspension_stiffness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_suspensionStiffness = (btScalar)value; +} + +/** + * + */ +void BulletVehicleTuning:: +set_suspension_compression(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_suspensionCompression = (btScalar)value; +} + +/** + * + */ +void BulletVehicleTuning:: +set_suspension_damping(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_suspensionDamping = (btScalar)value; +} + +/** + * + */ +void BulletVehicleTuning:: +set_max_suspension_travel_cm(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_maxSuspensionTravelCm = (btScalar)value; +} + +/** + * + */ +void BulletVehicleTuning:: +set_friction_slip(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_frictionSlip = (btScalar)value; +} + +/** + * + */ +void BulletVehicleTuning:: +set_max_suspension_force(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + _.m_maxSuspensionForce = (btScalar)value; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_suspension_stiffness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_suspensionStiffness; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_suspension_compression() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_suspensionCompression; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_suspension_damping() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_suspensionDamping; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_max_suspension_travel_cm() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_maxSuspensionTravelCm; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_friction_slip() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_frictionSlip; +} + +/** + * + */ +PN_stdfloat BulletVehicleTuning:: +get_max_suspension_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return (PN_stdfloat)_.m_maxSuspensionForce; +} + diff --git a/panda/src/bullet/bulletVehicle.h b/panda/src/bullet/bulletVehicle.h index 8b7f7862c6..9f9da751c3 100644 --- a/panda/src/bullet/bulletVehicle.h +++ b/panda/src/bullet/bulletVehicle.h @@ -32,19 +32,19 @@ class BulletWheel; class EXPCL_PANDABULLET BulletVehicleTuning { PUBLISHED: - INLINE void set_suspension_stiffness(PN_stdfloat value); - INLINE void set_suspension_compression(PN_stdfloat value); - INLINE void set_suspension_damping(PN_stdfloat value); - INLINE void set_max_suspension_travel_cm(PN_stdfloat value); - INLINE void set_friction_slip(PN_stdfloat value); - INLINE void set_max_suspension_force(PN_stdfloat value); + void set_suspension_stiffness(PN_stdfloat value); + void set_suspension_compression(PN_stdfloat value); + void set_suspension_damping(PN_stdfloat value); + void set_max_suspension_travel_cm(PN_stdfloat value); + void set_friction_slip(PN_stdfloat value); + void set_max_suspension_force(PN_stdfloat value); - INLINE PN_stdfloat get_suspension_stiffness() const; - INLINE PN_stdfloat get_suspension_compression() const; - INLINE PN_stdfloat get_suspension_damping() const; - INLINE PN_stdfloat get_max_suspension_travel_cm() const; - INLINE PN_stdfloat get_friction_slip() const; - INLINE PN_stdfloat get_max_suspension_force() const; + PN_stdfloat get_suspension_stiffness() const; + PN_stdfloat get_suspension_compression() const; + PN_stdfloat get_suspension_damping() const; + PN_stdfloat get_max_suspension_travel_cm() const; + PN_stdfloat get_friction_slip() const; + PN_stdfloat get_max_suspension_force() const; MAKE_PROPERTY(suspension_stiffness, get_suspension_stiffness, set_suspension_stiffness); MAKE_PROPERTY(suspension_compression, get_suspension_compression, set_suspension_compression); @@ -87,7 +87,7 @@ PUBLISHED: // Wheels BulletWheel create_wheel(); - INLINE int get_num_wheels() const; + int get_num_wheels() const; BulletWheel get_wheel(int idx) const; MAKE_SEQ(get_wheels, get_num_wheels, get_wheel); @@ -102,8 +102,9 @@ PUBLISHED: public: INLINE btRaycastVehicle *get_vehicle() const; + BulletRigidBodyNode *do_get_chassis(); - void sync_b2p(); + void do_sync_b2p(); private: btRaycastVehicle *_vehicle; diff --git a/panda/src/bullet/bulletWheel.I b/panda/src/bullet/bulletWheel.I index ed724e184b..cbf82a40bc 100644 --- a/panda/src/bullet/bulletWheel.I +++ b/panda/src/bullet/bulletWheel.I @@ -40,74 +40,3 @@ empty() { return BulletWheel(info); } -/** - * - */ -INLINE bool BulletWheelRaycastInfo:: -is_in_contact() const { - - return _info.m_isInContact; -} - -/** - * - */ -INLINE PN_stdfloat BulletWheelRaycastInfo:: -get_suspension_length() const { - - return _info.m_suspensionLength; -} - -/** - * - */ -INLINE LPoint3 BulletWheelRaycastInfo:: -get_contact_point_ws() const { - - return btVector3_to_LPoint3(_info.m_contactPointWS); -} - -/** - * - */ -INLINE LPoint3 BulletWheelRaycastInfo:: -get_hard_point_ws() const { - - return btVector3_to_LPoint3(_info.m_hardPointWS); -} - -/** - * - */ -INLINE LVector3 BulletWheelRaycastInfo:: -get_contact_normal_ws() const { - - return btVector3_to_LVector3(_info.m_contactNormalWS); -} - -/** - * - */ -INLINE LVector3 BulletWheelRaycastInfo:: -get_wheel_direction_ws() const { - - return btVector3_to_LVector3(_info.m_wheelDirectionWS); -} - -/** - * - */ -INLINE LVector3 BulletWheelRaycastInfo:: -get_wheel_axle_ws() const { - - return btVector3_to_LVector3(_info.m_wheelAxleWS); -} - -/** - * - */ -INLINE PandaNode *BulletWheelRaycastInfo:: -get_ground_object() const { - - return _info.m_groundObject ? (PandaNode *)_info.m_groundObject : NULL; -} diff --git a/panda/src/bullet/bulletWheel.cxx b/panda/src/bullet/bulletWheel.cxx index 687e5ea892..149dbd8bf5 100644 --- a/panda/src/bullet/bulletWheel.cxx +++ b/panda/src/bullet/bulletWheel.cxx @@ -34,6 +34,7 @@ BulletWheelRaycastInfo(btWheelInfo::RaycastInfo &info) : _info(info) { */ BulletWheelRaycastInfo BulletWheel:: get_raycast_info() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return BulletWheelRaycastInfo(_info.m_raycastInfo); } @@ -43,6 +44,7 @@ get_raycast_info() const { */ PN_stdfloat BulletWheel:: get_suspension_rest_length() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.getSuspensionRestLength(); } @@ -52,6 +54,7 @@ get_suspension_rest_length() const { */ void BulletWheel:: set_suspension_stiffness(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_suspensionStiffness = (btScalar)value; } @@ -61,6 +64,7 @@ set_suspension_stiffness(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_suspension_stiffness() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_suspensionStiffness; } @@ -71,6 +75,7 @@ get_suspension_stiffness() const { */ void BulletWheel:: set_max_suspension_travel_cm(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_maxSuspensionTravelCm = (btScalar)value; } @@ -80,6 +85,7 @@ set_max_suspension_travel_cm(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_max_suspension_travel_cm() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_maxSuspensionTravelCm; } @@ -89,6 +95,7 @@ get_max_suspension_travel_cm() const { */ void BulletWheel:: set_friction_slip(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_frictionSlip = (btScalar)value; } @@ -98,6 +105,7 @@ set_friction_slip(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_friction_slip() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_frictionSlip; } @@ -107,6 +115,7 @@ get_friction_slip() const { */ void BulletWheel:: set_max_suspension_force(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_maxSuspensionForce = (btScalar)value; } @@ -116,6 +125,7 @@ set_max_suspension_force(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_max_suspension_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_maxSuspensionForce; } @@ -125,6 +135,7 @@ get_max_suspension_force() const { */ void BulletWheel:: set_wheels_damping_compression(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_wheelsDampingCompression = (btScalar)value; } @@ -134,6 +145,7 @@ set_wheels_damping_compression(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_wheels_damping_compression() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_wheelsDampingCompression; } @@ -143,6 +155,7 @@ get_wheels_damping_compression() const { */ void BulletWheel:: set_wheels_damping_relaxation(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_wheelsDampingRelaxation = (btScalar)value; } @@ -152,6 +165,7 @@ set_wheels_damping_relaxation(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_wheels_damping_relaxation() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_wheelsDampingRelaxation; } @@ -164,6 +178,7 @@ get_wheels_damping_relaxation() const { */ void BulletWheel:: set_roll_influence(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_rollInfluence = (btScalar)value; } @@ -174,6 +189,7 @@ set_roll_influence(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_roll_influence() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_rollInfluence; } @@ -183,6 +199,7 @@ get_roll_influence() const { */ void BulletWheel:: set_wheel_radius(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_wheelsRadius = (btScalar)value; } @@ -192,6 +209,7 @@ set_wheel_radius(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_wheel_radius() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_wheelsRadius; } @@ -201,6 +219,7 @@ get_wheel_radius() const { */ void BulletWheel:: set_steering(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_steering = (btScalar)value; } @@ -210,6 +229,7 @@ set_steering(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_steering() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_steering; } @@ -219,6 +239,7 @@ get_steering() const { */ void BulletWheel:: set_rotation(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_rotation = (btScalar)value; } @@ -228,6 +249,7 @@ set_rotation(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_rotation() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_rotation; } @@ -237,6 +259,7 @@ get_rotation() const { */ void BulletWheel:: set_delta_rotation(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_deltaRotation = (btScalar)value; } @@ -246,6 +269,7 @@ set_delta_rotation(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_delta_rotation() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_deltaRotation; } @@ -255,6 +279,7 @@ get_delta_rotation() const { */ void BulletWheel:: set_engine_force(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_engineForce = (btScalar)value; } @@ -264,6 +289,7 @@ set_engine_force(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_engine_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_engineForce; } @@ -273,6 +299,7 @@ get_engine_force() const { */ void BulletWheel:: set_brake(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_brake = (btScalar)value; } @@ -282,6 +309,7 @@ set_brake(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_brake() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_brake; } @@ -291,6 +319,7 @@ get_brake() const { */ void BulletWheel:: set_skid_info(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_skidInfo = (btScalar)value; } @@ -300,6 +329,7 @@ set_skid_info(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_skid_info() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_skidInfo; } @@ -309,6 +339,7 @@ get_skid_info() const { */ void BulletWheel:: set_wheels_suspension_force(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_wheelsSuspensionForce = (btScalar)value; } @@ -318,6 +349,7 @@ set_wheels_suspension_force(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_wheels_suspension_force() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_wheelsSuspensionForce; } @@ -327,6 +359,7 @@ get_wheels_suspension_force() const { */ void BulletWheel:: set_suspension_relative_velocity(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_suspensionRelativeVelocity = (btScalar)value; } @@ -336,6 +369,7 @@ set_suspension_relative_velocity(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_suspension_relative_velocity() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_suspensionRelativeVelocity; } @@ -345,6 +379,7 @@ get_suspension_relative_velocity() const { */ void BulletWheel:: set_clipped_inv_connection_point_cs(PN_stdfloat value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_clippedInvContactDotSuspension = (btScalar)value; } @@ -354,6 +389,7 @@ set_clipped_inv_connection_point_cs(PN_stdfloat value) { */ PN_stdfloat BulletWheel:: get_clipped_inv_connection_point_cs() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (PN_stdfloat)_info.m_clippedInvContactDotSuspension; } @@ -363,6 +399,7 @@ get_clipped_inv_connection_point_cs() const { */ void BulletWheel:: set_chassis_connection_point_cs(const LPoint3 &pos) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!pos.is_nan()); _info.m_chassisConnectionPointCS = LVecBase3_to_btVector3(pos); @@ -373,6 +410,7 @@ set_chassis_connection_point_cs(const LPoint3 &pos) { */ LPoint3 BulletWheel:: get_chassis_connection_point_cs() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LPoint3(_info.m_chassisConnectionPointCS); } @@ -383,6 +421,7 @@ get_chassis_connection_point_cs() const { */ void BulletWheel:: set_wheel_direction_cs(const LVector3 &dir) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!dir.is_nan()); _info.m_wheelDirectionCS = LVecBase3_to_btVector3(dir); @@ -393,6 +432,7 @@ set_wheel_direction_cs(const LVector3 &dir) { */ LVector3 BulletWheel:: get_wheel_direction_cs() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_info.m_wheelDirectionCS); } @@ -402,6 +442,7 @@ get_wheel_direction_cs() const { */ void BulletWheel:: set_wheel_axle_cs(const LVector3 &axle) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!axle.is_nan()); _info.m_wheelAxleCS = LVecBase3_to_btVector3(axle); @@ -412,6 +453,7 @@ set_wheel_axle_cs(const LVector3 &axle) { */ LVector3 BulletWheel:: get_wheel_axle_cs() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btVector3_to_LVector3(_info.m_wheelAxleCS); } @@ -421,6 +463,7 @@ get_wheel_axle_cs() const { */ void BulletWheel:: set_world_transform(const LMatrix4 &mat) { + LightMutexHolder holder(BulletWorld::get_global_lock()); nassertv(!mat.is_nan()); _info.m_worldTransform = LMatrix4_to_btTrans(mat); @@ -431,6 +474,7 @@ set_world_transform(const LMatrix4 &mat) { */ LMatrix4 BulletWheel:: get_world_transform() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return btTrans_to_LMatrix4(_info.m_worldTransform); } @@ -440,6 +484,7 @@ get_world_transform() const { */ void BulletWheel:: set_front_wheel(bool value) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_bIsFrontWheel = value; } @@ -449,6 +494,7 @@ set_front_wheel(bool value) { */ bool BulletWheel:: is_front_wheel() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return _info.m_bIsFrontWheel; } @@ -458,6 +504,7 @@ is_front_wheel() const { */ void BulletWheel:: set_node(PandaNode *node) { + LightMutexHolder holder(BulletWorld::get_global_lock()); _info.m_clientInfo = (void *)node; } @@ -468,6 +515,87 @@ set_node(PandaNode *node) { */ PandaNode *BulletWheel:: get_node() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); return (_info.m_clientInfo == NULL) ? NULL : (PandaNode *)_info.m_clientInfo; } + +/** + * + */ +bool BulletWheelRaycastInfo:: +is_in_contact() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _info.m_isInContact; +} + +/** + * + */ +PN_stdfloat BulletWheelRaycastInfo:: +get_suspension_length() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _info.m_suspensionLength; +} + +/** + * + */ +LPoint3 BulletWheelRaycastInfo:: +get_contact_point_ws() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LPoint3(_info.m_contactPointWS); +} + +/** + * + */ +LPoint3 BulletWheelRaycastInfo:: +get_hard_point_ws() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LPoint3(_info.m_hardPointWS); +} + +/** + * + */ +LVector3 BulletWheelRaycastInfo:: +get_contact_normal_ws() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_info.m_contactNormalWS); +} + +/** + * + */ +LVector3 BulletWheelRaycastInfo:: +get_wheel_direction_ws() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_info.m_wheelDirectionWS); +} + +/** + * + */ +LVector3 BulletWheelRaycastInfo:: +get_wheel_axle_ws() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return btVector3_to_LVector3(_info.m_wheelAxleWS); +} + +/** + * + */ +PandaNode *BulletWheelRaycastInfo:: +get_ground_object() const { + LightMutexHolder holder(BulletWorld::get_global_lock()); + + return _info.m_groundObject ? (PandaNode *)_info.m_groundObject : NULL; +} diff --git a/panda/src/bullet/bulletWheel.h b/panda/src/bullet/bulletWheel.h index 2b6ecd8a80..414ecd94f3 100644 --- a/panda/src/bullet/bulletWheel.h +++ b/panda/src/bullet/bulletWheel.h @@ -30,14 +30,14 @@ class EXPCL_PANDABULLET BulletWheelRaycastInfo { PUBLISHED: INLINE ~BulletWheelRaycastInfo(); - INLINE bool is_in_contact() const; - INLINE PN_stdfloat get_suspension_length() const; - INLINE LVector3 get_contact_normal_ws() const; - INLINE LVector3 get_wheel_direction_ws() const; - INLINE LVector3 get_wheel_axle_ws() const; - INLINE LPoint3 get_contact_point_ws() const; - INLINE LPoint3 get_hard_point_ws() const; - INLINE PandaNode *get_ground_object() const; + bool is_in_contact() const; + PN_stdfloat get_suspension_length() const; + LVector3 get_contact_normal_ws() const; + LVector3 get_wheel_direction_ws() const; + LVector3 get_wheel_axle_ws() const; + LPoint3 get_contact_point_ws() const; + LPoint3 get_hard_point_ws() const; + PandaNode *get_ground_object() const; MAKE_PROPERTY(in_contact, is_in_contact); MAKE_PROPERTY(suspension_length, get_suspension_length); diff --git a/panda/src/bullet/bulletWorld.I b/panda/src/bullet/bulletWorld.I index c2ecd2cec3..61893a1531 100644 --- a/panda/src/bullet/bulletWorld.I +++ b/panda/src/bullet/bulletWorld.I @@ -50,19 +50,6 @@ INLINE BulletWorld:: delete _broadphase; } -/** - * - */ -INLINE void BulletWorld:: -set_debug_node(BulletDebugNode *node) { - nassertv(node); - if (node != _debug) { - clear_debug_node(); - _debug = node; - _world->setDebugDrawer(&(_debug->_drawer)); - } -} - /** * */ @@ -108,125 +95,3 @@ get_dispatcher() const { return _dispatcher; } -/** - * - */ -INLINE int BulletWorld:: -get_num_rigid_bodies() const { - - return _bodies.size(); -} - -/** - * - */ -INLINE BulletRigidBodyNode *BulletWorld:: -get_rigid_body(int idx) const { - - nassertr(idx >= 0 && idx < (int)_bodies.size(), NULL); - return _bodies[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_soft_bodies() const { - - return _softbodies.size(); -} - -/** - * - */ -INLINE BulletSoftBodyNode *BulletWorld:: -get_soft_body(int idx) const { - - nassertr(idx >= 0 && idx < (int)_softbodies.size(), NULL); - return _softbodies[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_ghosts() const { - - return _ghosts.size(); -} - -/** - * - */ -INLINE BulletGhostNode *BulletWorld:: -get_ghost(int idx) const { - - nassertr(idx >= 0 && idx < (int)_ghosts.size(), NULL); - return _ghosts[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_characters() const { - - return _characters.size(); -} - -/** - * - */ -INLINE BulletBaseCharacterControllerNode *BulletWorld:: -get_character(int idx) const { - - nassertr(idx >= 0 && idx < (int)_characters.size(), NULL); - return _characters[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_vehicles() const { - - return _vehicles.size(); -} - -/** - * - */ -INLINE BulletVehicle *BulletWorld:: -get_vehicle(int idx) const { - - nassertr(idx >= 0 && idx < (int)_vehicles.size(), NULL); - return _vehicles[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_constraints() const { - - return _constraints.size(); -} - -/** - * - */ -INLINE BulletConstraint *BulletWorld:: -get_constraint(int idx) const { - - nassertr(idx >= 0 && idx < (int)_constraints.size(), NULL); - return _constraints[idx]; -} - -/** - * - */ -INLINE int BulletWorld:: -get_num_manifolds() const { - - return _world->getDispatcher()->getNumManifolds(); -} diff --git a/panda/src/bullet/bulletWorld.cxx b/panda/src/bullet/bulletWorld.cxx index d60339f360..f3d48e3c74 100644 --- a/panda/src/bullet/bulletWorld.cxx +++ b/panda/src/bullet/bulletWorld.cxx @@ -118,6 +118,17 @@ BulletWorld() { _world->getSolverInfo().m_numIterations = bullet_solver_iterations; } +/** + * + */ +LightMutex &BulletWorld:: +get_global_lock() { + + static LightMutex lock; + + return lock; +} + /** * */ @@ -127,13 +138,33 @@ get_world_info() { return BulletSoftBodyWorldInfo(_info); } +/** + * + */ +void BulletWorld:: +set_debug_node(BulletDebugNode *node) { + LightMutexHolder holder(get_global_lock()); + + nassertv(node); + if (node != _debug) { + if (_debug != nullptr) { + _debug->_debug_stale = false; + _debug->_debug_world = nullptr; + } + + _debug = node; + _world->setDebugDrawer(&(_debug->_drawer)); + } +} + /** * Removes a debug node that has been assigned to this BulletWorld. */ void BulletWorld:: clear_debug_node() { + LightMutexHolder holder(get_global_lock()); + if (_debug != nullptr) { - LightMutexHolder holder(_debug->_lock); _debug->_debug_stale = false; _debug->_debug_world = nullptr; _world->setDebugDrawer(nullptr); @@ -146,6 +177,7 @@ clear_debug_node() { */ void BulletWorld:: set_gravity(const LVector3 &gravity) { + LightMutexHolder holder(get_global_lock()); _world->setGravity(LVecBase3_to_btVector3(gravity)); _info.m_gravity.setValue(gravity.get_x(), gravity.get_y(), gravity.get_z()); @@ -156,6 +188,7 @@ set_gravity(const LVector3 &gravity) { */ void BulletWorld:: set_gravity(PN_stdfloat gx, PN_stdfloat gy, PN_stdfloat gz) { + LightMutexHolder holder(get_global_lock()); _world->setGravity(btVector3((btScalar)gx, (btScalar)gy, (btScalar)gz)); _info.m_gravity.setValue((btScalar)gx, (btScalar)gy, (btScalar)gz); @@ -166,6 +199,7 @@ set_gravity(PN_stdfloat gx, PN_stdfloat gy, PN_stdfloat gz) { */ const LVector3 BulletWorld:: get_gravity() const { + LightMutexHolder holder(get_global_lock()); return btVector3_to_LVector3(_world->getGravity()); } @@ -175,6 +209,7 @@ get_gravity() const { */ int BulletWorld:: do_physics(PN_stdfloat dt, int max_substeps, PN_stdfloat stepsize) { + LightMutexHolder holder(get_global_lock()); _pstat_physics.start(); @@ -182,7 +217,7 @@ do_physics(PN_stdfloat dt, int max_substeps, PN_stdfloat stepsize) { // Synchronize Panda to Bullet _pstat_p2b.start(); - sync_p2b(dt, num_substeps); + do_sync_p2b(dt, num_substeps); _pstat_p2b.stop(); // Simulation @@ -192,13 +227,13 @@ do_physics(PN_stdfloat dt, int max_substeps, PN_stdfloat stepsize) { // Synchronize Bullet to Panda _pstat_b2p.start(); - sync_b2p(); + do_sync_b2p(); _info.m_sparsesdf.GarbageCollect(bullet_gc_lifetime); _pstat_b2p.stop(); // Render debug if (_debug) { - _debug->sync_b2p(_world); + _debug->do_sync_b2p(_world); } _pstat_physics.stop(); @@ -207,52 +242,52 @@ do_physics(PN_stdfloat dt, int max_substeps, PN_stdfloat stepsize) { } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -sync_p2b(PN_stdfloat dt, int num_substeps) { +do_sync_p2b(PN_stdfloat dt, int num_substeps) { - for (int i=0; i < get_num_rigid_bodies(); i++) { - get_rigid_body(i)->sync_p2b(); + for (int i=0; i < _bodies.size(); i++) { + _bodies[i]->do_sync_p2b(); } - for (int i=0; i < get_num_soft_bodies(); i++) { - get_soft_body(i)->sync_p2b(); + for (int i=0; i < _softbodies.size(); i++) { + _softbodies[i]->do_sync_p2b(); } - for (int i=0; i < get_num_ghosts(); i++) { - get_ghost(i)->sync_p2b(); + for (int i=0; i < _ghosts.size(); i++) { + _ghosts[i]->do_sync_p2b(); } - for (int i=0; i < get_num_characters(); i++) { - get_character(i)->sync_p2b(dt, num_substeps); + for (int i=0; i < _characters.size(); i++) { + _characters[i]->do_sync_p2b(dt, num_substeps); } } /** - * + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -sync_b2p() { +do_sync_b2p() { - for (int i=0; i < get_num_vehicles(); i++) { - get_vehicle(i)->sync_b2p(); + for (int i=0; i < _vehicles.size(); i++) { + _vehicles[i]->do_sync_b2p(); } - for (int i=0; i < get_num_rigid_bodies(); i++) { - get_rigid_body(i)->sync_b2p(); + for (int i=0; i < _bodies.size(); i++) { + _bodies[i]->do_sync_b2p(); } - for (int i=0; i < get_num_soft_bodies(); i++) { - get_soft_body(i)->sync_b2p(); + for (int i=0; i < _softbodies.size(); i++) { + _softbodies[i]->do_sync_b2p(); } - for (int i=0; i < get_num_ghosts(); i++) { - get_ghost(i)->sync_b2p(); + for (int i=0; i < _ghosts.size(); i++) { + _ghosts[i]->do_sync_b2p(); } - for (int i=0; i < get_num_characters(); i++) { - get_character(i)->sync_b2p(); + for (int i=0; i < _characters.size(); i++) { + _characters[i]->do_sync_b2p(); } } @@ -261,24 +296,25 @@ sync_b2p() { */ void BulletWorld:: attach(TypedObject *object) { + LightMutexHolder holder(get_global_lock()); if (object->is_of_type(BulletGhostNode::get_class_type())) { - attach_ghost(DCAST(BulletGhostNode, object)); + do_attach_ghost(DCAST(BulletGhostNode, object)); } else if (object->is_of_type(BulletRigidBodyNode::get_class_type())) { - attach_rigid_body(DCAST(BulletRigidBodyNode, object)); + do_attach_rigid_body(DCAST(BulletRigidBodyNode, object)); } else if (object->is_of_type(BulletSoftBodyNode::get_class_type())) { - attach_soft_body(DCAST(BulletSoftBodyNode, object)); + do_attach_soft_body(DCAST(BulletSoftBodyNode, object)); } else if (object->is_of_type(BulletBaseCharacterControllerNode::get_class_type())) { - attach_character(DCAST(BulletBaseCharacterControllerNode, object)); + do_attach_character(DCAST(BulletBaseCharacterControllerNode, object)); } else if (object->is_of_type(BulletVehicle::get_class_type())) { - attach_vehicle(DCAST(BulletVehicle, object)); + do_attach_vehicle(DCAST(BulletVehicle, object)); } else if (object->is_of_type(BulletConstraint::get_class_type())) { - attach_constraint(DCAST(BulletConstraint, object)); + do_attach_constraint(DCAST(BulletConstraint, object)); } else { bullet_cat->error() << "not a bullet world object!" << endl; @@ -290,24 +326,25 @@ attach(TypedObject *object) { */ void BulletWorld:: remove(TypedObject *object) { + LightMutexHolder holder(get_global_lock()); if (object->is_of_type(BulletGhostNode::get_class_type())) { - remove_ghost(DCAST(BulletGhostNode, object)); + do_remove_ghost(DCAST(BulletGhostNode, object)); } else if (object->is_of_type(BulletRigidBodyNode::get_class_type())) { - remove_rigid_body(DCAST(BulletRigidBodyNode, object)); + do_remove_rigid_body(DCAST(BulletRigidBodyNode, object)); } else if (object->is_of_type(BulletSoftBodyNode::get_class_type())) { - remove_soft_body(DCAST(BulletSoftBodyNode, object)); + do_remove_soft_body(DCAST(BulletSoftBodyNode, object)); } else if (object->is_of_type(BulletBaseCharacterControllerNode::get_class_type())) { - remove_character(DCAST(BulletBaseCharacterControllerNode, object)); + do_remove_character(DCAST(BulletBaseCharacterControllerNode, object)); } else if (object->is_of_type(BulletVehicle::get_class_type())) { - remove_vehicle(DCAST(BulletVehicle, object)); + do_remove_vehicle(DCAST(BulletVehicle, object)); } else if (object->is_of_type(BulletConstraint::get_class_type())) { - remove_constraint(DCAST(BulletConstraint, object)); + do_remove_constraint(DCAST(BulletConstraint, object)); } else { bullet_cat->error() << "not a bullet world object!" << endl; @@ -319,6 +356,127 @@ remove(TypedObject *object) { */ void BulletWorld:: attach_rigid_body(BulletRigidBodyNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_attach_rigid_body(node); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_rigid_body(BulletRigidBodyNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_remove_rigid_body(node); +} + +/** + * Deprecated! Please use BulletWorld::attach + */ +void BulletWorld:: +attach_soft_body(BulletSoftBodyNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_attach_soft_body(node); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_soft_body(BulletSoftBodyNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_remove_soft_body(node); +} + +/** + * Deprecated! Please use BulletWorld::attach + */ +void BulletWorld:: +attach_ghost(BulletGhostNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_attach_ghost(node); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_ghost(BulletGhostNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_remove_ghost(node); +} + +/** + * Deprecated! Please use BulletWorld::attach + */ +void BulletWorld:: +attach_character(BulletBaseCharacterControllerNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_attach_character(node); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_character(BulletBaseCharacterControllerNode *node) { + LightMutexHolder holder(get_global_lock()); + + do_remove_character(node); +} + +/** + * Deprecated! Please use BulletWorld::attach + */ +void BulletWorld:: +attach_vehicle(BulletVehicle *vehicle) { + LightMutexHolder holder(get_global_lock()); + + do_attach_vehicle(vehicle); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_vehicle(BulletVehicle *vehicle) { + LightMutexHolder holder(get_global_lock()); + + do_remove_vehicle(vehicle); +} + +/** + * Attaches a single constraint to a world. Collision checks between the + * linked objects will be disabled if the second parameter is set to TRUE. + */ +void BulletWorld:: +attach_constraint(BulletConstraint *constraint, bool linked_collision) { + LightMutexHolder holder(get_global_lock()); + + do_attach_constraint(constraint, linked_collision); +} + +/** + * Deprecated.! Please use BulletWorld::remove + */ +void BulletWorld:: +remove_constraint(BulletConstraint *constraint) { + LightMutexHolder holder(get_global_lock()); + + do_remove_constraint(constraint); +} + +/** + * Assumes the lock(bullet global lock) is held by the caller + */ +void BulletWorld:: +do_attach_rigid_body(BulletRigidBodyNode *node) { nassertv(node); @@ -338,10 +496,10 @@ attach_rigid_body(BulletRigidBodyNode *node) { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_rigid_body(BulletRigidBodyNode *node) { +do_remove_rigid_body(BulletRigidBodyNode *node) { nassertv(node); @@ -361,10 +519,10 @@ remove_rigid_body(BulletRigidBodyNode *node) { } /** - * Deprecated! Please use BulletWorld::attach + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -attach_soft_body(BulletSoftBodyNode *node) { +do_attach_soft_body(BulletSoftBodyNode *node) { nassertv(node); @@ -388,10 +546,10 @@ attach_soft_body(BulletSoftBodyNode *node) { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_soft_body(BulletSoftBodyNode *node) { +do_remove_soft_body(BulletSoftBodyNode *node) { nassertv(node); @@ -411,10 +569,10 @@ remove_soft_body(BulletSoftBodyNode *node) { } /** - * Deprecated! Please use BulletWorld::attach + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -attach_ghost(BulletGhostNode *node) { +do_attach_ghost(BulletGhostNode *node) { nassertv(node); @@ -452,10 +610,10 @@ enum CollisionFilterGroups { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_ghost(BulletGhostNode *node) { +do_remove_ghost(BulletGhostNode *node) { nassertv(node); @@ -475,10 +633,10 @@ remove_ghost(BulletGhostNode *node) { } /** - * Deprecated! Please use BulletWorld::attach + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -attach_character(BulletBaseCharacterControllerNode *node) { +do_attach_character(BulletBaseCharacterControllerNode *node) { nassertv(node); @@ -501,10 +659,10 @@ attach_character(BulletBaseCharacterControllerNode *node) { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_character(BulletBaseCharacterControllerNode *node) { +do_remove_character(BulletBaseCharacterControllerNode *node) { nassertv(node); @@ -523,10 +681,10 @@ remove_character(BulletBaseCharacterControllerNode *node) { } /** - * Deprecated! Please use BulletWorld::attach + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -attach_vehicle(BulletVehicle *vehicle) { +do_attach_vehicle(BulletVehicle *vehicle) { nassertv(vehicle); @@ -544,14 +702,14 @@ attach_vehicle(BulletVehicle *vehicle) { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_vehicle(BulletVehicle *vehicle) { +do_remove_vehicle(BulletVehicle *vehicle) { nassertv(vehicle); - remove_rigid_body(vehicle->get_chassis()); + do_remove_rigid_body(vehicle->do_get_chassis()); BulletVehicles::iterator found; PT(BulletVehicle) ptvehicle = vehicle; @@ -569,9 +727,10 @@ remove_vehicle(BulletVehicle *vehicle) { /** * Attaches a single constraint to a world. Collision checks between the * linked objects will be disabled if the second parameter is set to TRUE. + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -attach_constraint(BulletConstraint *constraint, bool linked_collision) { +do_attach_constraint(BulletConstraint *constraint, bool linked_collision) { nassertv(constraint); @@ -589,10 +748,10 @@ attach_constraint(BulletConstraint *constraint, bool linked_collision) { } /** - * Deprecated.! Please use BulletWorld::remove + * Assumes the lock(bullet global lock) is held by the caller */ void BulletWorld:: -remove_constraint(BulletConstraint *constraint) { +do_remove_constraint(BulletConstraint *constraint) { nassertv(constraint); @@ -609,11 +768,148 @@ remove_constraint(BulletConstraint *constraint) { } } +/** + * + */ +int BulletWorld:: +get_num_rigid_bodies() const { + LightMutexHolder holder(get_global_lock()); + + return _bodies.size(); +} + +/** + * + */ +BulletRigidBodyNode *BulletWorld:: +get_rigid_body(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_bodies.size(), NULL); + return _bodies[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_soft_bodies() const { + LightMutexHolder holder(get_global_lock()); + + return _softbodies.size(); +} + +/** + * + */ +BulletSoftBodyNode *BulletWorld:: +get_soft_body(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_softbodies.size(), NULL); + return _softbodies[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_ghosts() const { + LightMutexHolder holder(get_global_lock()); + + return _ghosts.size(); +} + +/** + * + */ +BulletGhostNode *BulletWorld:: +get_ghost(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_ghosts.size(), NULL); + return _ghosts[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_characters() const { + LightMutexHolder holder(get_global_lock()); + + return _characters.size(); +} + +/** + * + */ +BulletBaseCharacterControllerNode *BulletWorld:: +get_character(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_characters.size(), NULL); + return _characters[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_vehicles() const { + LightMutexHolder holder(get_global_lock()); + + return _vehicles.size(); +} + +/** + * + */ +BulletVehicle *BulletWorld:: +get_vehicle(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_vehicles.size(), NULL); + return _vehicles[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_constraints() const { + LightMutexHolder holder(get_global_lock()); + + return _constraints.size(); +} + +/** + * + */ +BulletConstraint *BulletWorld:: +get_constraint(int idx) const { + LightMutexHolder holder(get_global_lock()); + + nassertr(idx >= 0 && idx < (int)_constraints.size(), NULL); + return _constraints[idx]; +} + +/** + * + */ +int BulletWorld:: +get_num_manifolds() const { + LightMutexHolder holder(get_global_lock()); + + return _world->getDispatcher()->getNumManifolds(); +} + /** * */ BulletClosestHitRayResult BulletWorld:: ray_test_closest(const LPoint3 &from_pos, const LPoint3 &to_pos, const CollideMask &mask) const { + LightMutexHolder holder(get_global_lock()); nassertr(!from_pos.is_nan(), BulletClosestHitRayResult::empty()); nassertr(!to_pos.is_nan(), BulletClosestHitRayResult::empty()); @@ -631,6 +927,7 @@ ray_test_closest(const LPoint3 &from_pos, const LPoint3 &to_pos, const CollideMa */ BulletAllHitsRayResult BulletWorld:: ray_test_all(const LPoint3 &from_pos, const LPoint3 &to_pos, const CollideMask &mask) const { + LightMutexHolder holder(get_global_lock()); nassertr(!from_pos.is_nan(), BulletAllHitsRayResult::empty()); nassertr(!to_pos.is_nan(), BulletAllHitsRayResult::empty()); @@ -648,13 +945,16 @@ ray_test_all(const LPoint3 &from_pos, const LPoint3 &to_pos, const CollideMask & */ BulletClosestHitSweepResult BulletWorld:: sweep_test_closest(BulletShape *shape, const TransformState &from_ts, const TransformState &to_ts, const CollideMask &mask, PN_stdfloat penetration) const { + LightMutexHolder holder(get_global_lock()); nassertr(shape, BulletClosestHitSweepResult::empty()); - nassertr(shape->is_convex(), BulletClosestHitSweepResult::empty()); + + const btConvexShape *convex = (const btConvexShape *) shape->ptr(); + nassertr(convex->isConvex(), BulletClosestHitSweepResult::empty()); + nassertr(!from_ts.is_invalid(), BulletClosestHitSweepResult::empty()); nassertr(!to_ts.is_invalid(), BulletClosestHitSweepResult::empty()); - const btConvexShape *convex = (const btConvexShape *) shape->ptr(); const btVector3 from_pos = LVecBase3_to_btVector3(from_ts.get_pos()); const btVector3 to_pos = LVecBase3_to_btVector3(to_ts.get_pos()); const btTransform from_trans = LMatrix4_to_btTrans(from_ts.get_mat()); @@ -671,6 +971,7 @@ sweep_test_closest(BulletShape *shape, const TransformState &from_ts, const Tran */ bool BulletWorld:: filter_test(PandaNode *node0, PandaNode *node1) const { + LightMutexHolder holder(get_global_lock()); nassertr(node0, false); nassertr(node1, false); @@ -702,6 +1003,7 @@ filter_test(PandaNode *node0, PandaNode *node1) const { */ BulletContactResult BulletWorld:: contact_test(PandaNode *node, bool use_filter) const { + LightMutexHolder holder(get_global_lock()); btCollisionObject *obj = get_collision_object(node); @@ -727,6 +1029,7 @@ contact_test(PandaNode *node, bool use_filter) const { */ BulletContactResult BulletWorld:: contact_test_pair(PandaNode *node0, PandaNode *node1) const { + LightMutexHolder holder(get_global_lock()); btCollisionObject *obj0 = get_collision_object(node0); btCollisionObject *obj1 = get_collision_object(node1); @@ -746,6 +1049,7 @@ contact_test_pair(PandaNode *node0, PandaNode *node1) const { */ BulletPersistentManifold *BulletWorld:: get_manifold(int idx) const { + LightMutexHolder holder(get_global_lock()); nassertr(idx < get_num_manifolds(), NULL); @@ -780,6 +1084,7 @@ get_collision_object(PandaNode *node) { */ void BulletWorld:: set_group_collision_flag(unsigned int group1, unsigned int group2, bool enable) { + LightMutexHolder holder(get_global_lock()); if (bullet_filter_algorithm != FA_groups_mask) { bullet_cat.warning() << "filter algorithm is not 'groups-mask'" << endl; @@ -794,6 +1099,7 @@ set_group_collision_flag(unsigned int group1, unsigned int group2, bool enable) */ bool BulletWorld:: get_group_collision_flag(unsigned int group1, unsigned int group2) const { + LightMutexHolder holder(get_global_lock()); return _filter_cb2._collide[group1].get_bit(group2); } @@ -803,6 +1109,7 @@ get_group_collision_flag(unsigned int group1, unsigned int group2) const { */ void BulletWorld:: set_contact_added_callback(CallbackObject *obj) { + LightMutexHolder holder(get_global_lock()); _world->getSolverInfo().m_solverMode |= SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION; _world->getSolverInfo().m_solverMode |= SOLVER_USE_2_FRICTION_DIRECTIONS; @@ -816,6 +1123,7 @@ set_contact_added_callback(CallbackObject *obj) { */ void BulletWorld:: clear_contact_added_callback() { + LightMutexHolder holder(get_global_lock()); _world->getSolverInfo().m_solverMode &= ~SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION; _world->getSolverInfo().m_solverMode &= ~SOLVER_USE_2_FRICTION_DIRECTIONS; @@ -829,6 +1137,7 @@ clear_contact_added_callback() { */ void BulletWorld:: set_tick_callback(CallbackObject *obj, bool is_pretick) { + LightMutexHolder holder(get_global_lock()); nassertv(obj != NULL); _tick_callback_obj = obj; @@ -840,6 +1149,7 @@ set_tick_callback(CallbackObject *obj, bool is_pretick) { */ void BulletWorld:: clear_tick_callback() { + LightMutexHolder holder(get_global_lock()); _tick_callback_obj = NULL; _world->setInternalTickCallback(NULL); @@ -866,6 +1176,7 @@ tick_callback(btDynamicsWorld *world, btScalar timestep) { */ void BulletWorld:: set_filter_callback(CallbackObject *obj) { + LightMutexHolder holder(get_global_lock()); nassertv(obj != NULL); @@ -881,6 +1192,7 @@ set_filter_callback(CallbackObject *obj) { */ void BulletWorld:: clear_filter_callback() { + LightMutexHolder holder(get_global_lock()); _filter_cb3._filter_callback_obj = NULL; } diff --git a/panda/src/bullet/bulletWorld.h b/panda/src/bullet/bulletWorld.h index 558d086b37..021b6ee268 100644 --- a/panda/src/bullet/bulletWorld.h +++ b/panda/src/bullet/bulletWorld.h @@ -37,6 +37,7 @@ #include "callbackObject.h" #include "collideMask.h" #include "luse.h" +#include "lightMutex.h" class BulletPersistentManifold; class BulletShape; @@ -62,48 +63,43 @@ PUBLISHED: BulletSoftBodyWorldInfo get_world_info(); // Debug - INLINE void set_debug_node(BulletDebugNode *node); + void set_debug_node(BulletDebugNode *node); void clear_debug_node(); INLINE BulletDebugNode *get_debug_node() const; INLINE bool has_debug_node() const; // AttachRemove void attach(TypedObject *object); + void remove(TypedObject *object); void attach_constraint(BulletConstraint *constraint, bool linked_collision=false); - void remove(TypedObject *object); - // Ghost object - INLINE int get_num_ghosts() const; - INLINE BulletGhostNode *get_ghost(int idx) const; + int get_num_ghosts() const; + BulletGhostNode *get_ghost(int idx) const; MAKE_SEQ(get_ghosts, get_num_ghosts, get_ghost); // Rigid body - INLINE int get_num_rigid_bodies() const; - INLINE BulletRigidBodyNode *get_rigid_body(int idx) const; + int get_num_rigid_bodies() const; + BulletRigidBodyNode *get_rigid_body(int idx) const; MAKE_SEQ(get_rigid_bodies, get_num_rigid_bodies, get_rigid_body); // Soft body - INLINE int get_num_soft_bodies() const; - INLINE BulletSoftBodyNode *get_soft_body(int idx) const; + int get_num_soft_bodies() const; + BulletSoftBodyNode *get_soft_body(int idx) const; MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body); // Character controller - INLINE int get_num_characters() const; - INLINE BulletBaseCharacterControllerNode *get_character(int idx) const; + int get_num_characters() const; + BulletBaseCharacterControllerNode *get_character(int idx) const; MAKE_SEQ(get_characters, get_num_characters, get_character); - // Vehicle - void attach_vehicle(BulletVehicle *vehicle); - void remove_vehicle(BulletVehicle *vehicle); - - INLINE int get_num_vehicles() const; - INLINE BulletVehicle *get_vehicle(int idx) const; + int get_num_vehicles() const; + BulletVehicle *get_vehicle(int idx) const; MAKE_SEQ(get_vehicles, get_num_vehicles, get_vehicle); // Constraint - INLINE int get_num_constraints() const; - INLINE BulletConstraint *get_constraint(int idx) const; + int get_num_constraints() const; + BulletConstraint *get_constraint(int idx) const; MAKE_SEQ(get_constraints, get_num_constraints, get_constraint); // Raycast and other queries @@ -130,7 +126,7 @@ PUBLISHED: bool filter_test(PandaNode *node0, PandaNode *node1) const; // Manifolds - INLINE int get_num_manifolds() const; + int get_num_manifolds() const; BulletPersistentManifold *get_manifold(int idx) const; MAKE_SEQ(get_manifolds, get_num_manifolds, get_manifold); @@ -171,7 +167,7 @@ PUBLISHED: MAKE_SEQ_PROPERTY(constraints, get_num_constraints, get_constraint); MAKE_SEQ_PROPERTY(manifolds, get_num_manifolds, get_manifold); -PUBLISHED: // Deprecated methods, will become private soon +PUBLISHED: // Deprecated methods, will be removed soon void attach_ghost(BulletGhostNode *node); void remove_ghost(BulletGhostNode *node); @@ -184,6 +180,9 @@ PUBLISHED: // Deprecated methods, will become private soon void attach_character(BulletBaseCharacterControllerNode *node); void remove_character(BulletBaseCharacterControllerNode *node); + void attach_vehicle(BulletVehicle *vehicle); + void remove_vehicle(BulletVehicle *vehicle); + void remove_constraint(BulletConstraint *constraint); public: @@ -193,9 +192,29 @@ public: INLINE btBroadphaseInterface *get_broadphase() const; INLINE btDispatcher *get_dispatcher() const; + static LightMutex &get_global_lock(); + private: - void sync_p2b(PN_stdfloat dt, int num_substeps); - void sync_b2p(); + void do_sync_p2b(PN_stdfloat dt, int num_substeps); + void do_sync_b2p(); + + void do_attach_ghost(BulletGhostNode *node); + void do_remove_ghost(BulletGhostNode *node); + + void do_attach_rigid_body(BulletRigidBodyNode *node); + void do_remove_rigid_body(BulletRigidBodyNode *node); + + void do_attach_soft_body(BulletSoftBodyNode *node); + void do_remove_soft_body(BulletSoftBodyNode *node); + + void do_attach_character(BulletBaseCharacterControllerNode *node); + void do_remove_character(BulletBaseCharacterControllerNode *node); + + void do_attach_vehicle(BulletVehicle *vehicle); + void do_remove_vehicle(BulletVehicle *vehicle); + + void do_attach_constraint(BulletConstraint *constraint, bool linked_collision=false); + void do_remove_constraint(BulletConstraint *constraint); static void tick_callback(btDynamicsWorld *world, btScalar timestep); diff --git a/panda/src/cftalk/cfChannel.I b/panda/src/cftalk/cfChannel.I deleted file mode 100644 index 4bb6a1c3fa..0000000000 --- a/panda/src/cftalk/cfChannel.I +++ /dev/null @@ -1,12 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfChannel.I - * @author drose - * @date 2009-03-26 - */ diff --git a/panda/src/cftalk/cfChannel.cxx b/panda/src/cftalk/cfChannel.cxx deleted file mode 100644 index e63ba79077..0000000000 --- a/panda/src/cftalk/cfChannel.cxx +++ /dev/null @@ -1,62 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfChannel.cxx - * @author drose - * @date 2009-03-26 - */ - -#include "cfChannel.h" - -/** - * The DatagramGenerator and DatagramSink should be newly created on the free - * store (via the new operator). The CFChannel will take ownership of these - * pointers, and will delete them when it destructs. - */ -CFChannel:: -CFChannel(DatagramGenerator *dggen, DatagramSink *dgsink) : - _dggen(dggen), - _dgsink(dgsink), - _reader(dggen), - _writer(dgsink) -{ - bool ok1 = _reader.init(); - bool ok2 = _writer.init(); - nassertv(ok1 && ok2); -} - -/** - * - */ -CFChannel:: -~CFChannel() { - delete _dggen; - delete _dgsink; -} - -/** - * Delivers a single command to the process at the other end of the channel. - */ -void CFChannel:: -send_command(CFCommand *command) { - bool ok = _writer.write_object(command); - nassertv(ok); -} - -/** - * Receives a single command from the process at the other end of the channel. - * If no command is ready, the thread will block until one is. Returns NULL - * when the connection has been closed. - */ -PT(CFCommand) CFChannel:: -receive_command() { - TypedWritable *obj = _reader.read_object(); - CFCommand *command; - DCAST_INTO_R(command, obj, NULL); - return command; -} diff --git a/panda/src/cftalk/cfChannel.h b/panda/src/cftalk/cfChannel.h deleted file mode 100644 index e549327efa..0000000000 --- a/panda/src/cftalk/cfChannel.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfChannel.h - * @author drose - * @date 2009-03-26 - */ - -#ifndef CFCHANNEL_H -#define CFCHANNEL_H - -#include "pandabase.h" -#include "referenceCount.h" -#include "bamReader.h" -#include "bamWriter.h" -#include "cfCommand.h" - -/** - * Represents an open communication channel in the connected-frame protocol. - * Commands may be sent and received on this channel. - */ -class EXPCL_CFTALK CFChannel : public ReferenceCount { -public: - CFChannel(DatagramGenerator *dggen, DatagramSink *dgsink); - ~CFChannel(); - - void send_command(CFCommand *command); - PT(CFCommand) receive_command(); - -private: - DatagramGenerator *_dggen; - DatagramSink *_dgsink; - BamReader _reader; - BamWriter _writer; -}; - -#include "cfChannel.I" - -#endif diff --git a/panda/src/cftalk/cfCommand.I b/panda/src/cftalk/cfCommand.I deleted file mode 100644 index fea651c96f..0000000000 --- a/panda/src/cftalk/cfCommand.I +++ /dev/null @@ -1,41 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfCommand.I - * @author drose - * @date 2009-02-19 - */ - -/** - * - */ -INLINE CFCommand:: -CFCommand() { -} - -/** - * - */ -INLINE CFDoCullCommand:: -CFDoCullCommand() { -} - -/** - * - */ -INLINE CFDoCullCommand:: -CFDoCullCommand(PandaNode *scene) : _scene(scene) { -} - -/** - * - */ -INLINE PandaNode *CFDoCullCommand:: -get_scene() const { - return _scene; -} diff --git a/panda/src/cftalk/cfCommand.cxx b/panda/src/cftalk/cfCommand.cxx deleted file mode 100644 index ca58163242..0000000000 --- a/panda/src/cftalk/cfCommand.cxx +++ /dev/null @@ -1,93 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfCommand.cxx - * @author drose - * @date 2009-02-19 - */ - -#include "cfCommand.h" - -TypeHandle CFCommand::_type_handle; -TypeHandle CFDoCullCommand::_type_handle; - -/** - * - */ -CFCommand:: -~CFCommand() { -} - -/** - * Tells the BamReader how to create objects of type CFDoCullCommand. - */ -void CFDoCullCommand:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); -} - -/** - * Writes the contents of this object to the datagram for shipping out to a - * Bam file. - */ -void CFDoCullCommand:: -write_datagram(BamWriter *manager, Datagram &dg) { - TypedWritable::write_datagram(manager, dg); - manager->write_pointer(dg, _scene); -} - -/** - * Called by the BamWriter when this object has not itself been modified - * recently, but it should check its nested objects for updates. - */ -void CFDoCullCommand:: -update_bam_nested(BamWriter *manager) { - manager->consider_update(_scene); -} - -/** - * Receives an array of pointers, one for each time manager->read_pointer() - * was called in fillin(). Returns the number of pointers processed. - */ -int CFDoCullCommand:: -complete_pointers(TypedWritable **p_list, BamReader *manager) { - int pi = TypedWritable::complete_pointers(p_list, manager); - - PandaNode *scene; - DCAST_INTO_R(scene, p_list[pi++], pi); - _scene = scene; - - return pi; -} - -/** - * This function is called by the BamReader's factory when a new object of - * type CFDoCullCommand is encountered in the Bam file. It should create the - * CFDoCullCommand and extract its information from the file. - */ -TypedWritable *CFDoCullCommand:: -make_from_bam(const FactoryParams ¶ms) { - CFDoCullCommand *node = new CFDoCullCommand; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - node->fillin(scan, manager); - - return node; -} - -/** - * This internal function is called by make_from_bam to read in all of the - * relevant data from the BamFile for the new CFDoCullCommand. - */ -void CFDoCullCommand:: -fillin(DatagramIterator &scan, BamReader *manager) { - TypedWritable::fillin(scan, manager); - manager->read_pointer(scan); -} diff --git a/panda/src/cftalk/cfCommand.h b/panda/src/cftalk/cfCommand.h deleted file mode 100644 index 84e7e1421c..0000000000 --- a/panda/src/cftalk/cfCommand.h +++ /dev/null @@ -1,98 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file cfCommand.h - * @author drose - * @date 2009-02-19 - */ - -#ifndef CFCOMMAND_H -#define CFCOMMAND_H - -#include "pandabase.h" - -#include "typedWritableReferenceCount.h" -#include "pandaNode.h" - -/** - * A single command in the Connected-Frame protocol. This can be sent client- - * to-server or server-to-client. - * - * This is an abstract base class. Individual commands will specialize from - * this. - */ -class EXPCL_CFTALK CFCommand : public TypedWritableReferenceCount { -protected: - CFCommand(); - -PUBLISHED: - virtual ~CFCommand(); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedWritableReferenceCount::init_type(); - register_type(_type_handle, "CFCommand", - TypedWritableReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -/** - * Starts the cull process for a particular DisplayRegion. - */ -class EXPCL_CFTALK CFDoCullCommand : public CFCommand { -protected: - INLINE CFDoCullCommand(); -PUBLISHED: - INLINE CFDoCullCommand(PandaNode *scene); - - INLINE PandaNode *get_scene() const; - -private: - PT(PandaNode) _scene; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &dg); - virtual void update_bam_nested(BamWriter *manager); - virtual int complete_pointers(TypedWritable **plist, BamReader *manager); - -protected: - static TypedWritable *make_from_bam(const FactoryParams ¶ms); - void fillin(DatagramIterator &scan, BamReader *manager); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CFCommand::init_type(); - register_type(_type_handle, "CFDoCullCommand", - CFCommand::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "cfCommand.I" - -#endif diff --git a/panda/src/cftalk/config_cftalk.cxx b/panda/src/cftalk/config_cftalk.cxx deleted file mode 100644 index 42c5054526..0000000000 --- a/panda/src/cftalk/config_cftalk.cxx +++ /dev/null @@ -1,46 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file config_cftalk.cxx - * @author drose - * @date 2009-03-26 - */ - -#include "config_cftalk.h" -#include "cfCommand.h" -#include "pandaSystem.h" - -ConfigureDef(config_cftalk); -NotifyCategoryDef(cftalk, ""); - -ConfigureFn(config_cftalk) { - init_libcftalk(); -} - -/** - * Initializes the library. This must be called at least once before any of - * the functions or classes in this library can be used. Normally it will be - * called by the static initializers and need not be called explicitly, but - * special cases exist. - */ -void -init_libcftalk() { - static bool initialized = false; - if (initialized) { - return; - } - initialized = true; - - CFCommand::init_type(); - CFDoCullCommand::init_type(); - - CFDoCullCommand::register_with_read_factory(); - - PandaSystem *ps = PandaSystem::get_global_ptr(); - ps->add_system("cftalk"); -} diff --git a/panda/src/cftalk/config_cftalk.h b/panda/src/cftalk/config_cftalk.h deleted file mode 100644 index 707c5f182d..0000000000 --- a/panda/src/cftalk/config_cftalk.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file config_cftalk.h - * @author drose - * @date 2009-03-26 - */ - -#ifndef CONFIG_CFTALK_H -#define CONFIG_CFTALK_H - -#include "pandabase.h" -#include "windowProperties.h" -#include "notifyCategoryProxy.h" -#include "configVariableBool.h" -#include "configVariableString.h" -#include "configVariableList.h" -#include "configVariableInt.h" -#include "configVariableEnum.h" -#include "configVariableFilename.h" -#include "coordinateSystem.h" -#include "dconfig.h" - -#include "pvector.h" - -ConfigureDecl(config_cftalk, EXPCL_CFTALK, EXPTP_CFTALK); -NotifyCategoryDecl(cftalk, EXPCL_CFTALK, EXPTP_CFTALK); - -extern EXPCL_CFTALK void init_libcftalk(); - -#endif /* CONFIG_CFTALK_H */ diff --git a/panda/src/cftalk/p3cftalk_composite1.cxx b/panda/src/cftalk/p3cftalk_composite1.cxx deleted file mode 100644 index 49525d942d..0000000000 --- a/panda/src/cftalk/p3cftalk_composite1.cxx +++ /dev/null @@ -1 +0,0 @@ -#include "cfCommand.cxx" diff --git a/panda/src/cftalk/p3cftalk_composite2.cxx b/panda/src/cftalk/p3cftalk_composite2.cxx deleted file mode 100644 index 79c8aa9fa6..0000000000 --- a/panda/src/cftalk/p3cftalk_composite2.cxx +++ /dev/null @@ -1 +0,0 @@ -#include "cfChannel.cxx" diff --git a/panda/src/express/datagram.I b/panda/src/express/datagram.I index 0ad4007b26..fa6063805b 100644 --- a/panda/src/express/datagram.I +++ b/panda/src/express/datagram.I @@ -408,6 +408,17 @@ get_array() const { */ INLINE PTA_uchar Datagram:: modify_array() { + if (_data == (uchar *)NULL) { + // Create a new array. + _data = PTA_uchar::empty_array(0); + + } else if (_data.get_ref_count() != 1) { + // Copy on write. + PTA_uchar new_data = PTA_uchar::empty_array(0); + new_data.v() = _data.v(); + _data = new_data; + } + return _data; } diff --git a/panda/src/grutil/shaderTerrainMesh.cxx b/panda/src/grutil/shaderTerrainMesh.cxx index a7f6b1d8af..8aac5f0e9a 100644 --- a/panda/src/grutil/shaderTerrainMesh.cxx +++ b/panda/src/grutil/shaderTerrainMesh.cxx @@ -150,6 +150,8 @@ void ShaderTerrainMesh::do_extract_heightfield() { } _heightfield_tex->set_minfilter(SamplerState::FT_linear); _heightfield_tex->set_magfilter(SamplerState::FT_linear); + _heightfield_tex->set_wrap_u(SamplerState::WM_clamp); + _heightfield_tex->set_wrap_v(SamplerState::WM_clamp); } /** diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 0d64cb0828..96b94dd0c2 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -3798,9 +3798,13 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) { int pi = CycleData::complete_pointers(p_list, manager); // Get the state and transform pointers. - _state = DCAST(RenderState, p_list[pi++]); - _transform = DCAST(TransformState, p_list[pi++]); - _prev_transform = _transform; + RenderState *state; + DCAST_INTO_R(state, p_list[pi++], pi); + _state = state; + + TransformState *transform; + DCAST_INTO_R(transform, p_list[pi++], pi); + _prev_transform = _transform = transform; /* * Finalize these pointers now to decrement their artificially-held reference @@ -3817,7 +3821,9 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) { // Get the effects pointer. - _effects = DCAST(RenderEffects, p_list[pi++]); + RenderEffects *effects; + DCAST_INTO_R(effects, p_list[pi++], pi); + _effects = effects; /* * Finalize these pointers now to decrement their artificially-held reference diff --git a/panda/src/putil/bamReader.cxx b/panda/src/putil/bamReader.cxx index 8831a1ca7e..30ad07415a 100644 --- a/panda/src/putil/bamReader.cxx +++ b/panda/src/putil/bamReader.cxx @@ -1159,6 +1159,16 @@ p_read_object() { // This object had already existed; thus, we are just receiving an // update for it. + if (_object_pointers.find(object_id) != _object_pointers.end()) { + // Aieee! This object isn't even complete from the last time we + // encountered it in the stream! This should never happen. Something's + // corrupt or the stream was maliciously crafted. + bam_cat.error() + << "Found object " << object_id << " in bam stream again while " + << "trying to resolve its own pointers.\n"; + return 0; + } + // Update _now_creating during this call so if this function calls // read_pointer() or register_change_this() we'll match it up properly. // This might recursively call back into this p_read_object(), so be @@ -1345,35 +1355,39 @@ resolve_object_pointers(TypedWritable *object, if (child_id == 0) { // A NULL pointer is a NULL pointer. references.push_back((TypedWritable *)NULL); - - } else { - // See if we have the pointer available now. - CreatedObjs::const_iterator oi = _created_objs.find(child_id); - if (oi == _created_objs.end()) { - // No, too bad. - is_complete = false; - - } else { - const CreatedObj &child_obj = (*oi).second; - if (!child_obj._created) { - // The child object hasn't yet been created. - is_complete = false; - } else if (child_obj._change_this != NULL || child_obj._change_this_ref != NULL) { - // It's been created, but the pointer might still change. - is_complete = false; - } else { - if (require_fully_complete && - _object_pointers.find(child_id) != _object_pointers.end()) { - // It's not yet complete itself. - is_complete = false; - - } else { - // Yes, it's ready. - references.push_back(child_obj._ptr); - } - } - } + continue; } + + // See if we have the pointer available now. + CreatedObjs::const_iterator oi = _created_objs.find(child_id); + if (oi == _created_objs.end()) { + // No, too bad. + is_complete = false; + break; + } + + const CreatedObj &child_obj = (*oi).second; + if (!child_obj._created) { + // The child object hasn't yet been created. + is_complete = false; + break; + } + + if (child_obj._change_this != NULL || child_obj._change_this_ref != NULL) { + // It's been created, but the pointer might still change. + is_complete = false; + break; + } + + if (require_fully_complete && + _object_pointers.find(child_id) != _object_pointers.end()) { + // It's not yet complete itself. + is_complete = false; + break; + } + + // Yes, it's ready. + references.push_back(child_obj._ptr); } if (is_complete) { @@ -1433,33 +1447,33 @@ resolve_cycler_pointers(PipelineCyclerBase *cycler, if (child_id == 0) { // A NULL pointer is a NULL pointer. references.push_back((TypedWritable *)NULL); - - } else { - // See if we have the pointer available now. - CreatedObjs::const_iterator oi = _created_objs.find(child_id); - if (oi == _created_objs.end()) { - // No, too bad. - is_complete = false; - - } else { - const CreatedObj &child_obj = (*oi).second; - if (child_obj._change_this != NULL || child_obj._change_this_ref != NULL) { - // It's been created, but the pointer might still change. - is_complete = false; - - } else { - if (require_fully_complete && - _object_pointers.find(child_id) != _object_pointers.end()) { - // It's not yet complete itself. - is_complete = false; - - } else { - // Yes, it's ready. - references.push_back(child_obj._ptr); - } - } - } + continue; } + + // See if we have the pointer available now. + CreatedObjs::const_iterator oi = _created_objs.find(child_id); + if (oi == _created_objs.end()) { + // No, too bad. + is_complete = false; + break; + } + + const CreatedObj &child_obj = (*oi).second; + if (child_obj._change_this != NULL || child_obj._change_this_ref != NULL) { + // It's been created, but the pointer might still change. + is_complete = false; + break; + } + + if (require_fully_complete && + _object_pointers.find(child_id) != _object_pointers.end()) { + // It's not yet complete itself. + is_complete = false; + break; + } + + // Yes, it's ready. + references.push_back(child_obj._ptr); } if (is_complete) { diff --git a/panda/src/putil/datagramInputFile.cxx b/panda/src/putil/datagramInputFile.cxx index 1ac14b58ed..f3bd8a081e 100644 --- a/panda/src/putil/datagramInputFile.cxx +++ b/panda/src/putil/datagramInputFile.cxx @@ -147,37 +147,34 @@ get_datagram(Datagram &data) { // Make sure we have a reasonable datagram size for putting into memory. nassertr(num_bytes == (size_t)num_bytes, false); - // Now, read the datagram itself. + // Now, read the datagram itself. We construct an empty datagram, use + // pad_bytes to make it big enough, and read *directly* into the datagram's + // internal buffer. Doing this saves us a copy operation. + data = Datagram(); - // If the number of bytes is large, we will need to allocate a temporary - // buffer from the heap. Otherwise, we can get away with allocating it on - // the stack, via alloca(). - if (num_bytes > 65536) { - char *buffer = (char *)PANDA_MALLOC_ARRAY(num_bytes); - nassertr(buffer != (char *)NULL, false); + streamsize bytes_read = 0; + while (bytes_read < num_bytes) { + streamsize bytes_left = num_bytes - bytes_read; - _in->read(buffer, num_bytes); - if (_in->fail() || _in->eof()) { - _error = true; - PANDA_FREE_ARRAY(buffer); - return false; - } + // Hold up a second - datagrams >4MB are pretty large by bam/network + // standards. Let's take it 4MB at a time just in case the length is + // corrupt, so we don't allocate potentially a few GBs of RAM only to + // find a truncated file. + bytes_left = min(bytes_left, (streamsize)4*1024*1024); - data = Datagram(buffer, num_bytes); - PANDA_FREE_ARRAY(buffer); + PTA_uchar buffer = data.modify_array(); + buffer.resize(buffer.size() + bytes_left); + unsigned char *ptr = &buffer.p()[bytes_read]; - } else { - char *buffer = (char *)alloca(num_bytes); - nassertr(buffer != (char *)NULL, false); - - _in->read(buffer, num_bytes); + _in->read((char *)ptr, bytes_left); if (_in->fail() || _in->eof()) { _error = true; return false; } - data = Datagram(buffer, num_bytes); + bytes_read += bytes_left; } + Thread::consider_yield(); return true; diff --git a/tests/audio/conftest.py b/tests/audio/conftest.py new file mode 100644 index 0000000000..60636e6d6e --- /dev/null +++ b/tests/audio/conftest.py @@ -0,0 +1,6 @@ +import pytest +from panda3d.core import * + +@pytest.fixture(scope='module') +def audiomgr(): + return AudioManager.create_AudioManager() diff --git a/tests/audio/test_loading.py b/tests/audio/test_loading.py new file mode 100644 index 0000000000..ea3bdb2cd9 --- /dev/null +++ b/tests/audio/test_loading.py @@ -0,0 +1,5 @@ +import pytest + +def test_missing_file(audiomgr): + sound = audiomgr.get_sound('/not/a/valid/file.ogg') + assert str(sound).startswith('NullAudioSound') diff --git a/tests/pgraph/test_light.py b/tests/pgraph/test_light.py new file mode 100644 index 0000000000..f303080b33 --- /dev/null +++ b/tests/pgraph/test_light.py @@ -0,0 +1,20 @@ +from panda3d import core + +def luminance(col): + return 0.2126 * col[0] + 0.7152 * col[1] + 0.0722 * col[2] + + +def test_light_colortemp(): + # Default is all white, assuming a D65 white point. + light = core.PointLight("light") + assert light.color == (1, 1, 1, 1) + assert light.color_temperature == 6500 + + # When setting color temp, it should preserve luminance. + for temp in range(2000, 15000): + light.color_temperature = temp + assert abs(luminance(light.color) - 1.0) < 0.001 + + # Setting it to the white point will make a white color. + light.color_temperature = 6500 + assert light.color.almost_equal((1, 1, 1, 1), 0.001) diff --git a/tests/prc/test_config_page.py b/tests/prc/test_config_page.py new file mode 100644 index 0000000000..5ca6cdb6ef --- /dev/null +++ b/tests/prc/test_config_page.py @@ -0,0 +1,12 @@ +from panda3d import core + +def test_load_unload_page(): + var = core.ConfigVariableInt("test-var", 1) + assert var.value == 1 + + page = core.load_prc_file_data("test_load_unload_page", "test-var 2") + assert page + assert var.value == 2 + + assert core.unload_prc_file(page) + assert var.value == 1 diff --git a/tests/putil/test_datagram.py b/tests/putil/test_datagram.py new file mode 100644 index 0000000000..4a34bc88a2 --- /dev/null +++ b/tests/putil/test_datagram.py @@ -0,0 +1,149 @@ +import pytest +from panda3d import core + +# Fixtures for generating interesting datagrams (and verification functions) on +# the fly... + +@pytest.fixture(scope='module', + params=[False, True], + ids=['stdfloat_float', 'stdfloat_double']) +def datagram_small(request): + """Returns a small datagram, along with a verification function.""" + dg = core.Datagram() + + dg.set_stdfloat_double(request.param) + + dg.add_uint8(3) + dg.add_uint16(14159) + dg.add_uint32(0xDEADBEEF) + dg.add_uint64(0x0123456789ABCDEF) + + dg.add_int8(-77) + dg.add_int16(-1) + dg.add_int32(-972965890) + dg.add_int64(-1001001001001001) + + dg.add_string('this is a string') + dg.add_string32('this is another string') + dg.add_string('this is yet a third string') + + dg.add_stdfloat(800.2) + dg.add_stdfloat(3.1415926) + dg.add_stdfloat(2.7182818) + + def readback_function(dgi): + assert dgi.get_remaining_size() > 0 + + assert dgi.get_uint8() == 3 + assert dgi.get_uint16() == 14159 + assert dgi.get_uint32() == 0xDEADBEEF + assert dgi.get_uint64() == 0x0123456789ABCDEF + + assert dgi.get_int8() == -77 + assert dgi.get_int16() == -1 + assert dgi.get_int32() == -972965890 + assert dgi.get_int64() == -1001001001001001 + + assert dgi.get_string() == 'this is a string' + assert dgi.get_string32() == 'this is another string' + assert dgi.get_string() == 'this is yet a third string' + + assert dgi.get_stdfloat() == pytest.approx(800.2) + assert dgi.get_stdfloat() == pytest.approx(3.1415926) + assert dgi.get_stdfloat() == pytest.approx(2.7182818) + + assert dgi.get_remaining_size() == 0 + + return dg, readback_function + +@pytest.fixture(scope='module') +def datagram_large(): + """Returns a big datagram, along with a verification function.""" + + dg = core.Datagram() + for x in range(2000000): + dg.add_uint32(x) + dg.add_string('the magic words are squeamish ossifrage') + + def readback_function(dgi): + assert dgi.get_remaining_size() > 0 + + for x in range(2000000): + assert dgi.get_uint32() == x + assert dgi.get_string() == 'the magic words are squeamish ossifrage' + + assert dgi.get_remaining_size() == 0 + + return dg, readback_function + +def test_iterator(datagram_small): + """This tests Datagram/DatagramIterator, and sort of serves as a self-check + of the test fixtures too.""" + dg, verify = datagram_small + + dgi = core.DatagramIterator(dg) + verify(dgi) + + +# These test DatagramInputFile/DatagramOutputFile: + +def do_file_test(dg, verify, filename): + dof = core.DatagramOutputFile() + dof.open(filename) + dof.put_datagram(dg) + dof.close() + + dg2 = core.Datagram() + dif = core.DatagramInputFile() + dif.open(filename) + assert dif.get_datagram(dg2) + dif.close() + + # This is normally saved by the DatagramOutputFile header. We cheat here. + dg2.set_stdfloat_double(dg.get_stdfloat_double()) + + dgi = core.DatagramIterator(dg2) + verify(dgi) + +def test_file_small(datagram_small, tmpdir): + """This tests DatagramOutputFile/DatagramInputFile on small datagrams.""" + dg, verify = datagram_small + + p = tmpdir.join('datagram.bin') + filename = core.Filename.from_os_specific(str(p)) + + do_file_test(dg, verify, filename) + +def test_file_large(datagram_large, tmpdir): + """This tests DatagramOutputFile/DatagramInputFile on very large datagrams.""" + dg, verify = datagram_large + + p = tmpdir.join('datagram.bin') + filename = core.Filename.from_os_specific(str(p)) + + do_file_test(dg, verify, filename) + +def test_file_corrupt(datagram_small, tmpdir): + """This tests DatagramInputFile's handling of a corrupt size header.""" + dg, verify = datagram_small + + p = tmpdir.join('datagram.bin') + filename = core.Filename.from_os_specific(str(p)) + + dof = core.DatagramOutputFile() + dof.open(filename) + dof.put_datagram(dg) + dof.close() + + # Corrupt the size header to 4GB + with p.open(mode='wb') as f: + f.seek(0) + f.write(b'\xFF\xFF\xFF\xFF') + + dg2 = core.Datagram() + dif = core.DatagramInputFile() + dif.open(filename) + assert not dif.get_datagram(dg2) + dif.close() + + # Should we test that dg2 is unmodified?