// Filename: config_graph.cxx
// Created by:  drose (01Oct99)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////

#include "config_graph.h"
#include "arcChain.h"
#include "namedNode.h"
#include "node.h"
#include "nodeRelation.h"
#include "nodeTransition.h"
#include "nodeTransitionCache.h"
#include "onOffTransition.h"
#include "multiNodeTransition.h"
#include "immediateTransition.h"

#include <dconfig.h>

Configure(config_graph);
NotifyCategoryDef(graph, "");
NotifyCategoryDef(wrt, graph_cat);

ConfigureFn(config_graph) {
  init_libgraph();
}

// Set this true if you want to cache some of the work of computing
// wrt(), so that the second time wrt() is called on a particular
// node-node pair it will be much cheaper than the first time.  This
// is the default behavior; you'd only want to turn it off if for some
// reason it was broken.  This is true by default and cannot be turned
// off in optimized (NDEBUG) mode.
const bool cache_wrt = config_graph.GetBool("cache-wrt", true);

// Set this true to force abort() to be called if an ambiguous wrt()
// call is made.  This will hopefully allow the programmer to get a
// stack dump and determine who is issuing the ambiguous wrt().  This
// cannot be turned on in optimized (NDEBUG) mode.
const bool ambiguous_wrt_abort = config_graph.GetBool("ambiguous-wrt-abort", false);

// Set this true to double-check the cached value of wrt(), above, by
// performing an explicit uncached wrt() and comparing the results.
// Obviously very slow.  This cannot be turned on in optimized
// (NDEBUG) mode.
const bool paranoid_wrt = config_graph.GetBool("paranoid-wrt", false);

// This is similar to paranoid-wrt, above.  Set it true to
// double-check each parent/unparent operation, to make sure that it
// always places the arc in the correct position in the parent's arc
// list, and that the arc list always remains properly sorted.  Again,
// it cannot be turned on in NDEBUG mode.
const bool paranoid_graph = config_graph.GetBool("paranoid-graph", false);


////////////////////////////////////////////////////////////////////
//     Function: init_libgraph
//  Description: 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_libgraph() {
  static bool initialized = false;
  if (initialized) {
    return;
  }
  initialized = true;

  void init_last_graph_update();
  init_last_graph_update();

  ArcChain::init_type();
  BoundedObject::init_type();
  NamedNode::init_type();
  Node::init_type();
  NodeRelation::init_type();
  NodeTransition::init_type();
  NodeTransitionCache::init_type();
  OnOffTransition::init_type();
  MultiNodeTransition::init_type();
  ImmediateTransition::init_type();

  NodeRelation::register_with_factory();

  //Registration of writeable object's creation
  //functions with BamReader's factory
  Node::register_with_read_factory();
  NamedNode::register_with_read_factory();
  NodeRelation::register_with_read_factory();
}
