<commit_before>// Filename: physxManager.cxx
// Created by:  enn0x (01Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////

#include "physxManager.h"
#include "physxScene.h"
#include "physxSceneDesc.h"

PhysxManager *PhysxManager::_global_ptr;
PhysxManager::PhysxOutputStream PhysxManager::_outputStream;

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::Constructor
//       Access: Protected
//  Description: 
////////////////////////////////////////////////////////////////////
PhysxManager::
PhysxManager() {

  // Create PhysX SDK
  NxSDKCreateError error;
  NxPhysicsSDKDesc desc = NxPhysicsSDKDesc();

  _sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &_outputStream, desc, &error);

  if (error == NXCE_NO_ERROR) {
    physx_cat.info() << "PhysX subsystem initialized. Number of PPUs="
                     << _sdk->getNbPPUs() << endl;
  }
  else {
    physx_cat.error() << "Error when setting up the PhysX subsystem: "
                      << get_sdk_error_string(error) << endl;
  }

  nassertv_always(error == NXCE_NO_ERROR);
  nassertv_always(_sdk);
  
  // Set some default parameters
  _sdk->setParameter(NX_VISUALIZATION_SCALE, 0.0f);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES, true);
  _sdk->setParameter(NX_VISUALIZE_ACTOR_AXES, true);
  _sdk->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY, true);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_AABBS, false);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_VNORMALS, false);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, false);
  _sdk->setParameter(NX_VISUALIZE_FORCE_FIELDS, false);

  // Connect VDR
  if(physx_want_vrd) {
    physx_cat.info() << "Connecting to visual remote debugger at ("
                     << physx_vrd_host << ":"
                     << physx_vrd_port << ")" << endl;

    NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();

    debugger->connect(physx_vrd_host.c_str(),
                      physx_vrd_port);

    if (!debugger->isConnected()) {
      physx_cat.warning() << "Could not connect to visual remot debugger!" << endl;
    }
  }

}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::Destructor
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
PhysxManager::
~PhysxManager() {

  // Disconnect VRD
  if(physx_want_vrd) {
    NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
    if (!debugger->isConnected()) {
      debugger->disconnect();
    }
  }

  // Release PhysX SDK
  NxReleasePhysicsSDK(_sdk);
}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::get_global_ptr
//       Access: Published
//  Description: Returns a pointer to the global PhysxManager
//               object.
////////////////////////////////////////////////////////////////////
PhysxManager *PhysxManager::
get_global_ptr() {

  if (_global_ptr == (PhysxManager *)NULL) {
    _global_ptr = new PhysxManager;
  }

  return _global_ptr;
}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::get_num_scenes
//       Access: Published<commit_msg>PhysxManager.get_global_ptr now returns NULL is SDK initialization fails.<commit_after>// Filename: physxManager.cxx
// Created by:  enn0x (01Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////

#include "physxManager.h"
#include "physxScene.h"
#include "physxSceneDesc.h"

PhysxManager *PhysxManager::_global_ptr;
PhysxManager::PhysxOutputStream PhysxManager::_outputStream;

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::Constructor
//       Access: Protected
//  Description: 
////////////////////////////////////////////////////////////////////
PhysxManager::
PhysxManager() {

  // Create PhysX SDK
  NxSDKCreateError error;
  NxPhysicsSDKDesc desc = NxPhysicsSDKDesc();

  _sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, &_outputStream, desc, &error);

  if (error == NXCE_NO_ERROR) {
    physx_cat.info() << "PhysX subsystem initialized. Number of PPUs="
                     << _sdk->getNbPPUs() << endl;
  }
  else {
    physx_cat.error() << "Error when setting up the PhysX subsystem: "
                      << get_sdk_error_string(error) << endl;
    _sdk = NULL;
  }

  nassertv_always(error == NXCE_NO_ERROR);
  nassertv_always(_sdk);
  
  // Set some default parameters
  _sdk->setParameter(NX_VISUALIZATION_SCALE, 0.0f);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_SHAPES, true);
  _sdk->setParameter(NX_VISUALIZE_ACTOR_AXES, true);
  _sdk->setParameter(NX_VISUALIZE_BODY_LIN_VELOCITY, true);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_AABBS, false);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_VNORMALS, false);
  _sdk->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, false);
  _sdk->setParameter(NX_VISUALIZE_FORCE_FIELDS, false);

  // Connect VDR
  if(physx_want_vrd) {
    physx_cat.info() << "Connecting to visual remote debugger at ("
                     << physx_vrd_host << ":"
                     << physx_vrd_port << ")" << endl;

    NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();

    debugger->connect(physx_vrd_host.c_str(),
                      physx_vrd_port);

    if (!debugger->isConnected()) {
      physx_cat.warning() << "Could not connect to visual remot debugger!" << endl;
    }
  }

}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::Destructor
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
PhysxManager::
~PhysxManager() {

  // Disconnect VRD
  if(physx_want_vrd) {
    NxRemoteDebugger *debugger = _sdk->getFoundationSDK().getRemoteDebugger();
    if (!debugger->isConnected()) {
      debugger->disconnect();
    }
  }

  // Release PhysX SDK
  NxReleasePhysicsSDK(_sdk);
}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::get_global_ptr
//       Access: Published
//  Description: Returns a pointer to the global PhysxManager
//               object.
////////////////////////////////////////////////////////////////////
PhysxManager *PhysxManager::
get_global_ptr() {

  if (_global_ptr == (PhysxManager *)NULL) {
    _global_ptr = new PhysxManager;
  }

  if (_global_ptr->_sdk == NULL) {
    return NULL;
  }
  else {
    return _global_ptr;
  }
}

////////////////////////////////////////////////////////////////////
//     Function: PhysxManager::get_num_scenes
//       Access: Published
{'fraction_non_alphanumeric': 0.2632075471698113, 'fraction_numerical': 0.00215633423180593, 'mean_word_length': 1.8163187855787477, 'pattern_counts': {'":': 2, '<': 59, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7036737', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2120, 'n_words': 428}