Merge branch 'master' into cmake

This commit is contained in:
Sam Edwards 2016-03-15 18:30:55 -07:00
commit 441371e8d9
5653 changed files with 256834 additions and 355975 deletions

View File

@ -1,16 +1,15 @@
// Filename: aiBehaviors.cxx
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiBehaviors.cxx
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#include "aiBehaviors.h"
@ -47,12 +46,11 @@ AIBehaviors::~AIBehaviors() {
}
////////////////////////////////////////////////////////////////////
// Function: is_conflict
// Description: Checks for conflict between steering forces.
// If there is a conflict it returns 'true' and sets _conflict to 'true'.
// If there is no conflict it returns 'false' and sets _conflict to 'false'.
////////////////////////////////////////////////////////////////////
/**
* Checks for conflict between steering forces. If there is a conflict it
* returns 'true' and sets _conflict to 'true'. If there is no conflict it
* returns 'false' and sets _conflict to 'false'.
*/
bool AIBehaviors::is_conflict() {
int value = int(is_on(_seek)) + int(is_on(_flee)) + int(is_on(_pursue)) + int(is_on(_evade)) + int(is_on(_wander)) + int(is_on(_flock))+ int(is_on(_obstacle_avoidance));
@ -98,12 +96,11 @@ bool AIBehaviors::is_conflict() {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: accumulate_force
// Description: This function updates the individual steering forces for each of the ai characters.
// These accumulated forces are eventually what comprise the resultant
// steering force of the character.
////////////////////////////////////////////////////////////////////
/**
* This function updates the individual steering forces for each of the ai
* characters. These accumulated forces are eventually what comprise the
* resultant steering force of the character.
*/
void AIBehaviors::accumulate_force(string force_type, LVecBase3 force) {
@ -153,13 +150,12 @@ void AIBehaviors::accumulate_force(string force_type, LVecBase3 force) {
}
////////////////////////////////////////////////////////////////////
// Function: calculate_prioritized
// Description: This function updates the main steering force for the ai character using
// the accumulate function and checks for max force and arrival force.
// It finally returns this steering force which is accessed by the update
// function in the AICharacter class.
////////////////////////////////////////////////////////////////////
/**
* This function updates the main steering force for the ai character using
* the accumulate function and checks for max force and arrival force. It
* finally returns this steering force which is accessed by the update
* function in the AICharacter class.
*/
LVecBase3 AIBehaviors::calculate_prioritized() {
LVecBase3 force;
@ -305,10 +301,9 @@ LVecBase3 AIBehaviors::calculate_prioritized() {
return _steering_force;
}
////////////////////////////////////////////////////////////////////
// Function: remove_ai
// Description: This function removes individual or all the AIs.
////////////////////////////////////////////////////////////////////
/**
* This function removes individual or all the AIs.
*/
void AIBehaviors::remove_ai(string ai_type) {
switch(char_to_int(ai_type)) {
case 0: {
@ -422,10 +417,9 @@ void AIBehaviors::remove_ai(string ai_type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: pause_ai
// Description: This function pauses individual or all the AIs.
////////////////////////////////////////////////////////////////////
/**
* This function pauses individual or all the AIs.
*/
void AIBehaviors::pause_ai(string ai_type) {
switch(char_to_int(ai_type)) {
case 0: {
@ -521,10 +515,9 @@ void AIBehaviors::pause_ai(string ai_type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: resume_ai
// Description: This function resumes individual or all the AIs
////////////////////////////////////////////////////////////////////
/**
* This function resumes individual or all the AIs
*/
void AIBehaviors::resume_ai(string ai_type) {
switch(char_to_int(ai_type)) {
case 0: {
@ -615,12 +608,11 @@ void AIBehaviors::resume_ai(string ai_type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: seek
// Description: This function activates seek and makes an object of the Seek class.
// This is the function we want the user to call for seek to be done.
// This function is overloaded to accept a NodePath or an LVecBase3.
////////////////////////////////////////////////////////////////////
/**
* This function activates seek and makes an object of the Seek class. This
* is the function we want the user to call for seek to be done. This
* function is overloaded to accept a NodePath or an LVecBase3.
*/
void AIBehaviors::seek(NodePath target_object, float seek_wt) {
_seek_obj = new Seek(_ai_char, target_object, seek_wt);
turn_on("seek");
@ -631,11 +623,10 @@ void AIBehaviors::seek(LVecBase3 pos, float seek_wt) {
turn_on("seek");
}
////////////////////////////////////////////////////////////////////
// Function: flee
// Description: This function activates flee_activate and creates an object of the Flee class.
// This function is overloaded to accept a NodePath or an LVecBase3.
////////////////////////////////////////////////////////////////////
/**
* This function activates flee_activate and creates an object of the Flee
* class. This function is overloaded to accept a NodePath or an LVecBase3.
*/
void AIBehaviors::flee(NodePath target_object, double panic_distance, double relax_distance, float flee_wt) {
_flee_obj = new Flee(_ai_char, target_object, panic_distance, relax_distance, flee_wt);
_flee_list.insert(_flee_list.end(), *_flee_obj);
@ -650,21 +641,19 @@ void AIBehaviors::flee(LVecBase3 pos, double panic_distance, double relax_distan
turn_on("flee_activate");
}
////////////////////////////////////////////////////////////////////
// Function: pursue
// Description: This function activates pursue.
// This is the function we want the user to call for pursue to be done.
////////////////////////////////////////////////////////////////////
/**
* This function activates pursue. This is the function we want the user to
* call for pursue to be done.
*/
void AIBehaviors::pursue(NodePath target_object, float pursue_wt) {
_pursue_obj = new Pursue(_ai_char, target_object, pursue_wt);
turn_on("pursue");
}
////////////////////////////////////////////////////////////////////
// Function: evade
// Description: This function activates evade_activate.
////////////////////////////////////////////////////////////////////
/**
* This function activates evade_activate.
*/
void AIBehaviors::evade(NodePath target_object, double panic_distance, double relax_distance, float evade_wt) {
_evade_obj = new Evade(_ai_char, target_object, panic_distance, relax_distance, evade_wt);
_evade_list.insert(_evade_list.end(), *_evade_obj);
@ -672,11 +661,10 @@ void AIBehaviors::evade(NodePath target_object, double panic_distance, double re
turn_on("evade_activate");
}
////////////////////////////////////////////////////////////////////
// Function: arrival
// Description: This function activates arrival.
// This is the function we want the user to call for arrival to be done.
////////////////////////////////////////////////////////////////////
/**
* This function activates arrival. This is the function we want the user to
* call for arrival to be done.
*/
void AIBehaviors::arrival(double distance) {
if(_pursue_obj) {
_arrival_obj = new Arrival(_ai_char, distance);
@ -693,11 +681,10 @@ void AIBehaviors::arrival(double distance) {
}
}
////////////////////////////////////////////////////////////////////
// Function: flock
// Description: This function activates flock.
// This is the function we want the user to call for flock to be done.
////////////////////////////////////////////////////////////////////
/**
* This function activates flock. This is the function we want the user to
* call for flock to be done.
*/
void AIBehaviors::flock(float flock_wt) {
_flock_weight = flock_wt;
@ -705,11 +692,10 @@ void AIBehaviors::flock(float flock_wt) {
turn_on("flock_activate");
}
////////////////////////////////////////////////////////////////////
// Function: flock_activate
// Description: This function checks whether any other behavior exists to work with flock.
// When this is true, it calls the do_flock function.
////////////////////////////////////////////////////////////////////
/**
* This function checks whether any other behavior exists to work with flock.
* When this is true, it calls the do_flock function.
*/
void AIBehaviors::flock_activate() {
if(is_on(_seek) || is_on(_flee) || is_on(_pursue) || is_on(_evade) || is_on(_wander)) {
turn_off("flock_activate");
@ -717,18 +703,17 @@ void AIBehaviors::flock_activate() {
}
}
////////////////////////////////////////////////////////////////////
// Function: do_flock
// Description: This function contains the logic for flocking behavior. This is
// an emergent behavior and is obtained by combining three other
// behaviors which are separation, cohesion and alignment based on
// Craig Reynold's algorithm. Also, this behavior does not work by
// itself. It works only when combined with other steering behaviors
// such as wander, pursue, evade, seek and flee.
////////////////////////////////////////////////////////////////////
/**
* This function contains the logic for flocking behavior. This is an
* emergent behavior and is obtained by combining three other behaviors which
* are separation, cohesion and alignment based on Craig Reynold's algorithm.
* Also, this behavior does not work by itself. It works only when combined
* with other steering behaviors such as wander, pursue, evade, seek and flee.
*/
LVecBase3 AIBehaviors::do_flock() {
//! Initialize variables required to compute the flocking force on the ai char.
// ! Initialize variables required to compute the flocking force on the ai
// char.
unsigned int neighbor_count = 0;
LVecBase3 separation_force = LVecBase3(0.0, 0.0, 0.0);
LVecBase3 alignment_force = LVecBase3(0.0, 0.0, 0.0);
@ -738,38 +723,40 @@ LVecBase3 AIBehaviors::do_flock() {
LVecBase3 avg_center_of_mass = LVecBase3(0.0, 0.0, 0.0);
LVecBase3 total_center_of_mass = LVecBase3(0.0, 0.0, 0.0);
//! Loop through all the other AI units in the flock to check if they are neigbours.
// ! Loop through all the other AI units in the flock to check if they are
// neigbours.
for(unsigned int i = 0; i < _flock_group->_ai_char_list.size(); i++) {
if(_flock_group->_ai_char_list[i]->_name != _ai_char->_name) {
//! Using visibilty cone to detect neighbors.
// ! Using visibilty cone to detect neighbors.
LVecBase3 dist_vect = _flock_group->_ai_char_list[i]->_ai_char_np.get_pos() - _ai_char->_ai_char_np.get_pos();
LVecBase3 ai_char_heading = _ai_char->get_velocity();
ai_char_heading.normalize();
//! Check if the current unit is a neighbor.
// ! Check if the current unit is a neighbor.
if(dist_vect.dot(ai_char_heading) > ((dist_vect.length()) * (ai_char_heading.length()) * cos(_flock_group->_flock_vcone_angle * (_PI / 180)))
&& (dist_vect.length() < _flock_group->_flock_vcone_radius)) {
//! Separation force calculation.
// ! Separation force calculation.
LVecBase3 ai_char_to_units = _ai_char->_ai_char_np.get_pos() - _flock_group->_ai_char_list[i]->_ai_char_np.get_pos();
float to_units_dist = ai_char_to_units.length();
ai_char_to_units.normalize();
separation_force += (ai_char_to_units / to_units_dist);
//! Calculating the total heading and center of mass of all the neighbors.
// ! Calculating the total heading and center of mass of all the
// neighbors.
LVecBase3 neighbor_heading = _flock_group->_ai_char_list[i]->get_velocity();
neighbor_heading.normalize();
total_neighbor_heading += neighbor_heading;
total_center_of_mass += _flock_group->_ai_char_list[i]->_ai_char_np.get_pos();
//! Update the neighbor count.
// ! Update the neighbor count.
++neighbor_count;
}
}
}
if(neighbor_count > 0) {
//! Alignment force calculation
// ! Alignment force calculation
avg_neighbor_heading = total_neighbor_heading / neighbor_count;
LVector3 ai_char_heading = _ai_char->get_velocity();
ai_char_heading.normalize();
@ -777,7 +764,7 @@ LVecBase3 AIBehaviors::do_flock() {
avg_neighbor_heading.normalize();
alignment_force = avg_neighbor_heading;
//! Cohesion force calculation
// ! Cohesion force calculation
avg_center_of_mass = total_center_of_mass / neighbor_count;
LVecBase3 cohesion_dir = avg_center_of_mass - _ai_char->_ai_char_np.get_pos();
cohesion_dir.normalize();
@ -790,115 +777,105 @@ LVecBase3 AIBehaviors::do_flock() {
return(LVecBase3(0.0, 0.0, 0.0));
}
//! Calculate the resultant force on the ai character by taking into account the separation, alignment and cohesion
//! forces along with their corresponding weights.
// ! Calculate the resultant force on the ai character by taking into
// account the separation, alignment and cohesion ! forces along with their
// corresponding weights.
return (separation_force * _flock_group->_separation_wt + avg_neighbor_heading * _flock_group->_alignment_wt
+ cohesion_force * _flock_group->_cohesion_wt);
}
////////////////////////////////////////////////////////////////////
// Function: wander
// Description: This function activates wander.
// This is the function we want the user to call for flock to be done.
////////////////////////////////////////////////////////////////////
/**
* This function activates wander. This is the function we want the user to
* call for flock to be done.
*/
void AIBehaviors::wander(double wander_radius, int flag, double aoe, float wander_weight) {
_wander_obj = new Wander(_ai_char, wander_radius, flag, aoe, wander_weight);
turn_on("wander");
}
////////////////////////////////////////////////////////////////////
// Function: obstacle avoidance
// Description: This function activates obstacle avoidance for a given character.
// This is the function we want the user to call for
// obstacle avoidance to be performed.
////////////////////////////////////////////////////////////////////
/**
* This function activates obstacle avoidance for a given character. This is
* the function we want the user to call for obstacle avoidance to be
* performed.
*/
void AIBehaviors::obstacle_avoidance(float obstacle_avoidance_weight) {
_obstacle_avoidance_obj = new ObstacleAvoidance(_ai_char, obstacle_avoidance_weight);
turn_on("obstacle_avoidance_activate");
}
////////////////////////////////////////////////////////////////////
// Function: path_follow
// Description: This function activates path following.
// This is the function we want the user to call for path following.
////////////////////////////////////////////////////////////////////
/**
* This function activates path following. This is the function we want the
* user to call for path following.
*/
void AIBehaviors::path_follow(float follow_wt) {
_path_follow_obj = new PathFollow(_ai_char, follow_wt);
}
////////////////////////////////////////////////////////////////////
// Function: add_to_path
// Description: This function adds positions to the path to follow.
////////////////////////////////////////////////////////////////////
/**
* This function adds positions to the path to follow.
*/
void AIBehaviors::add_to_path(LVecBase3 pos) {
_path_follow_obj->add_to_path(pos);
}
////////////////////////////////////////////////////////////////////
// Function: start_follow
// Description: This function starts the path follower.
////////////////////////////////////////////////////////////////////
/**
* This function starts the path follower.
*/
void AIBehaviors::start_follow(string type) {
_path_follow_obj->start(type);
}
////////////////////////////////////////////////////////////////////
// Function: init_path_find
// Description: This function activates path finding in the character.
// This function accepts the meshdata in .csv format.
//
////////////////////////////////////////////////////////////////////
/**
* This function activates path finding in the character. This function
* accepts the meshdata in .csv format.
*
*/
void AIBehaviors::init_path_find(const char* navmesh_filename) {
_path_find_obj = new PathFind(_ai_char);
_path_find_obj->set_path_find(navmesh_filename);
}
////////////////////////////////////////////////////////////////////
// Function: path_find_to (for pathfinding towards a static position)
// Description: This function checks for the source and target in the navigation mesh
// for its availability and then finds the best path via the A* algorithm
// Then it calls the path follower to make the object follow the path.
////////////////////////////////////////////////////////////////////
/**
* This function checks for the source and target in the navigation mesh for
* its availability and then finds the best path via the A* algorithm Then it
* calls the path follower to make the object follow the path.
*/
void AIBehaviors::path_find_to(LVecBase3 pos, string type) {
_path_find_obj->path_find(pos, type);
}
////////////////////////////////////////////////////////////////////
// Function: path_find_to (for pathfinding towards a moving target (a NodePath))
// Description: This function checks for the source and target in the navigation mesh
// for its availability and then finds the best path via the A* algorithm
// Then it calls the path follower to make the object follow the path.
////////////////////////////////////////////////////////////////////
/**
* This function checks for the source and target in the navigation mesh for
* its availability and then finds the best path via the A* algorithm Then it
* calls the path follower to make the object follow the path.
*/
void AIBehaviors::path_find_to(NodePath target, string type) {
_path_find_obj->path_find(target, type);
}
////////////////////////////////////////////////////////////////////
// Function: add_static_obstacle
// Description: This function allows the user to dynamically add obstacles to the
// game environment. The function will update the nodes within the
// bounding volume of the obstacle as non-traversable. Hence will not be
// considered by the pathfinding algorithm.
////////////////////////////////////////////////////////////////////
/**
* This function allows the user to dynamically add obstacles to the game
* environment. The function will update the nodes within the bounding volume
* of the obstacle as non-traversable. Hence will not be considered by the
* pathfinding algorithm.
*/
void AIBehaviors::add_static_obstacle(NodePath obstacle) {
_path_find_obj->add_obstacle_to_mesh(obstacle);
}
////////////////////////////////////////////////////////////////////
// Function: add_dynamic_obstacle
// Description: This function starts the pathfinding obstacle navigation for the
// passed in obstacle.
////////////////////////////////////////////////////////////////////
/**
* This function starts the pathfinding obstacle navigation for the passed in
* obstacle.
*/
void AIBehaviors::add_dynamic_obstacle(NodePath obstacle) {
_path_find_obj->dynamic_avoid(obstacle);
}
////////////////////////////////////////////////////////////////////
// Function: behavior_status
// Description: This function returns the status of an AI Type whether it is active,
// paused or disabled. It returns -1 if an invalid string is passed.
////////////////////////////////////////////////////////////////////
/**
* This function returns the status of an AI Type whether it is active, paused
* or disabled. It returns -1 if an invalid string is passed.
*/
string AIBehaviors::behavior_status(string ai_type) {
switch(char_to_int(ai_type)) {
case 1:
@ -1113,11 +1090,10 @@ string AIBehaviors::behavior_status(string ai_type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: char_to_int
// Description: This function is used to derive int values from the ai types strings.
// Returns -1 if an invalid string is passed.
////////////////////////////////////////////////////////////////////
/**
* This function is used to derive int values from the ai types strings.
* Returns -1 if an invalid string is passed.
*/
int AIBehaviors::char_to_int(string ai_type) {
if(ai_type == "all") {
return 0;
@ -1174,10 +1150,9 @@ int AIBehaviors::char_to_int(string ai_type) {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: turn_on
// Description: This function turns on any aiBehavior which is passed as a string.
////////////////////////////////////////////////////////////////////
/**
* This function turns on any aiBehavior which is passed as a string.
*/
void AIBehaviors::turn_on(string ai_type) {
switch(char_to_int(ai_type)) {
case 1: {
@ -1237,10 +1212,9 @@ void AIBehaviors::turn_on(string ai_type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: turn_off
// Description: This function turns off any aiBehavior which is passed as a string.
////////////////////////////////////////////////////////////////////
/**
* This function turns off any aiBehavior which is passed as a string.
*/
void AIBehaviors::turn_off(string ai_type) {
switch(char_to_int(ai_type)) {
case 1: {
@ -1342,18 +1316,16 @@ switch(char_to_int(ai_type)) {
}
}
////////////////////////////////////////////////////////////////////
// Function: is_on
// Description: This function returns true if an aiBehavior is on
////////////////////////////////////////////////////////////////////
/**
* This function returns true if an aiBehavior is on
*/
bool AIBehaviors::is_on(_behavior_type bt) {
return (_behaviors_flags & bt) == bt;
}
////////////////////////////////////////////////////////////////////
// Function: is_on
// Description: This function returns true if pathfollow or pathfinding is on
////////////////////////////////////////////////////////////////////
/**
* This function returns true if pathfollow or pathfinding is on
*/
bool AIBehaviors::is_on(string ai_type) {
if(ai_type == "pathfollow") {
if(_path_follow_obj) {
@ -1376,18 +1348,16 @@ bool AIBehaviors::is_on(string ai_type) {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: is_off
// Description: This function returns true if an aiBehavior is off
////////////////////////////////////////////////////////////////////
/**
* This function returns true if an aiBehavior is off
*/
bool AIBehaviors::is_off(_behavior_type bt) {
return ((_behaviors_flags | bt) == bt);
}
////////////////////////////////////////////////////////////////////
// Function: is_off
// Description: This function returns true if pathfollow or pathfinding is off
////////////////////////////////////////////////////////////////////
/**
* This function returns true if pathfollow or pathfinding is off
*/
bool AIBehaviors::is_off(string ai_type) {
if(ai_type == "pathfollow") {
if(_path_follow_obj && _path_follow_obj->_start) {

View File

@ -1,16 +1,15 @@
// Filename: aiBehaviors.h
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiBehaviors.h
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#pragma warning (disable:4996)
#pragma warning (disable:4005)
@ -36,15 +35,16 @@ class ObstacleAvoidance;
typedef list<Flee, allocator<Flee> > ListFlee;
typedef list<Evade, allocator<Evade> > ListEvade;
////////////////////////////////////////////////////////////////////
// Class : AIBehaviors
// Description : This class implements all the steering behaviors of the AI framework, such as
// seek, flee, pursue, evade, wander and flock. Each steering behavior has a weight which is used when more than
// one type of steering behavior is acting on the same ai character. The weight decides the contribution of each
// type of steering behavior. The AICharacter class has a handle to an object of this class and this allows to
// invoke the steering behaviors via the AICharacter. This class also provides functionality such as pausing, resuming
// and removing the AI behaviors of an AI character at anytime.
////////////////////////////////////////////////////////////////////
/**
* This class implements all the steering behaviors of the AI framework, such
* as seek, flee, pursue, evade, wander and flock. Each steering behavior has
* a weight which is used when more than one type of steering behavior is
* acting on the same ai character. The weight decides the contribution of
* each type of steering behavior. The AICharacter class has a handle to an
* object of this class and this allows to invoke the steering behaviors via
* the AICharacter. This class also provides functionality such as pausing,
* resuming and removing the AI behaviors of an AI character at anytime.
*/
class EXPCL_PANDAAI AIBehaviors {
public:
enum _behavior_type {
@ -76,7 +76,8 @@ public:
Flee *_flee_obj;
LVecBase3 _flee_force;
//! This list is used if the ai character needs to flee from multiple onjects.
// ! This list is used if the ai character needs to flee from multiple
// onjects.
ListFlee _flee_list;
ListFlee::iterator _flee_itr;
@ -86,14 +87,16 @@ public:
Evade *_evade_obj;
LVecBase3 _evade_force;
//! This list is used if the ai character needs to evade from multiple onjects.
// ! This list is used if the ai character needs to evade from multiple
// onjects.
ListEvade _evade_list;
ListEvade::iterator _evade_itr;
Arrival *_arrival_obj;
LVecBase3 _arrival_force;
//! Since Flock is a collective behavior the variables are declared within the AIBehaviors class.
// ! Since Flock is a collective behavior the variables are declared within
// the AIBehaviors class.
float _flock_weight;
LVecBase3 _flock_force;
bool _flock_done;
@ -159,7 +162,7 @@ PUBLISHED:
void path_find_to(NodePath target, string type = "normal");
void add_static_obstacle(NodePath obstacle);
void add_dynamic_obstacle(NodePath obstacle);
//
void remove_ai(string ai_type);
void pause_ai(string ai_type);

View File

@ -1,16 +1,15 @@
// Filename: aiCharacter.cxx
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiCharacter.cxx
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#include "aiCharacter.h"
@ -34,13 +33,11 @@ AICharacter::AICharacter(string model_name, NodePath model_np, double mass, doub
AICharacter::~AICharacter() {
}
////////////////////////////////////////////////////////////////////
// Function: update
// Description: Each character's update will update its AI and
// physics based on his resultant steering force.
// This also makes the character look in the direction
// of the force.
////////////////////////////////////////////////////////////////////
/**
* Each character's update will update its AI and physics based on his
* resultant steering force. This also makes the character look in the
* direction of the force.
*/
void AICharacter::
update() {
if (!_steering->is_off(_steering->_none)) {

View File

@ -1,16 +1,15 @@
// Filename: aiCharacter.h
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiCharacter.h
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#pragma warning (disable:4996)
#pragma warning (disable:4005)
@ -22,14 +21,12 @@
#include "aiBehaviors.h"
////////////////////////////////////////////////////////////////////
// Class : AICharacter
// Description : This class is used for creating the AI characters.
// It assigns both physics and AI attributes to the
// character. It also has an update function which
// updates the physics and AI of the character.
// This update function is called by the AIWorld update.
////////////////////////////////////////////////////////////////////
/**
* This class is used for creating the AI characters. It assigns both physics
* and AI attributes to the character. It also has an update function which
* updates the physics and AI of the character. This update function is
* called by the AIWorld update.
*/
class AIBehaviors;
class AIWorld;

View File

@ -1,16 +1,15 @@
// Filename: aiGlobals.h
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiGlobals.h
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#pragma warning (disable:4996)
#pragma warning (disable:4005)

View File

@ -1,16 +1,15 @@
// Filename: aiNode.cxx
// Created by: Deepak, John, Navin (19Nov2009)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiNode.cxx
* @author Deepak, John, Navin
* @date 2009-11-19
*/
#include "aiNode.h"
@ -37,11 +36,10 @@ AINode::AINode(int grid_x, int grid_y, LVecBase3 pos, float w, float l, float h)
AINode::~AINode() {
}
////////////////////////////////////////////////////////////////////
// Function: contains
// Description: This is a handy function which returns true if the
// passed position is within the node's dimensions.
////////////////////////////////////////////////////////////////////
/**
* This is a handy function which returns true if the passed position is
* within the node's dimensions.
*/
bool AINode::contains(float x, float y) {
if (_position.get_x() - _width / 2 <= x && _position.get_x() + _width / 2 >= x &&
_position.get_y() - _length / 2 <= y && _position.get_y() + _length / 2 >= y) {

View File

@ -1,40 +1,33 @@
// Filename: aiNode.h
// Created by: Deepak, John, Navin (18Nov2009)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiNode.h
* @author Deepak, John, Navin
* @date 2009-11-18
*/
#ifndef AINODE_H
#define AINODE_H
#include "aiGlobals.h"
////////////////////////////////////////////////////////////////////
// Class : AINode
// Description : This class is used to assign the nodes on the mesh.
// It holds all the data necessary to compute A*
// algorithm. It also maintains a lot of vital
// information such as the neighbor nodes of each
// node and also its position on the mesh.
// Note: The Mesh Generator which is a standalone
// tool makes use of this class to generate the nodes
// on the mesh.
////////////////////////////////////////////////////////////////////
/**
* This class is used to assign the nodes on the mesh. It holds all the data
* necessary to compute A* algorithm. It also maintains a lot of vital
* information such as the neighbor nodes of each node and also its position
* on the mesh. Note: The Mesh Generator which is a standalone tool makes use
* of this class to generate the nodes on the mesh.
*/
class EXPCL_PANDAAI AINode {
public:
// This variable specifies the node status whether open, close
// or neutral.
// open = belongs to _open_list.
// close = belongs to _closed_list.
// neutral = unexamined node.
// This variable specifies the node status whether open, close or neutral.
// open = belongs to _open_list. close = belongs to _closed_list. neutral
// = unexamined node.
enum Status {
ST_open,
ST_close,
@ -42,15 +35,13 @@ public:
};
Status _status;
// This variable specifies whether the node is an obtacle or not.
// Used for dynamic obstacle addition to the environment.
// obstacle = false
// This variable specifies whether the node is an obtacle or not. Used for
// dynamic obstacle addition to the environment. obstacle = false
// navigational = true
bool _type;
// The score is used to compute the traversal expense to nodes
// when using A*.
// _score = _cost + heuristic
// The score is used to compute the traversal expense to nodes when using
// A*. _score = _cost + heuristic
int _score;
int _cost;
int _heuristic;
@ -64,16 +55,14 @@ public:
// Position of the node in 3D space.
LVecBase3 _position;
// Dimensions of each face / cell on the mesh.
// Height is given in case of expansion to a 3d mesh. Currently
// not used.
// Dimensions of each face cell on the mesh. Height is given in case of
// expansion to a 3d mesh. Currently not used.
float _width, _length ,_height;
AINode *_neighbours[8]; // anti-clockwise from top left corner.
// The _next pointer is used for traversal during mesh
// generation from the model.
// Note: The data in this member is discarded when mesh data
// is written into navmesh.csv file.
// The _next pointer is used for traversal during mesh generation from the
// model. Note: The data in this member is discarded when mesh data is
// written into navmesh.csv file.
AINode *_next;
PUBLISHED:

View File

@ -1,16 +1,15 @@
// Filename: aiPathFinder.cxx
// Created by: Deepak, John, Navin (10Nov09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiPathFinder.cxx
* @author Deepak, John, Navin
* @date 2009-11-10
*/
#include "aiPathFinder.h"
@ -21,17 +20,17 @@ PathFinder::PathFinder(NavMesh nav_mesh) {
PathFinder::~PathFinder() {
}
////////////////////////////////////////////////////////////////////
// Function: find_path
// Description: This function initializes the pathfinding process by accepting the
// source and destination nodes. It then calls the generate_path().
////////////////////////////////////////////////////////////////////
/**
* This function initializes the pathfinding process by accepting the source
* and destination nodes. It then calls the generate_path().
*/
void PathFinder::find_path(Node *src_node, Node *dest_node) {
_src_node = src_node;
_dest_node = dest_node;
// Add a dummy node as the first element of the open list with score = -1.
// Inorder to implement a binary heap the index of the elements should never be 0.
// Inorder to implement a binary heap the index of the elements should never
// be 0.
Node *_dummy_node = new Node(-1, -1, LVecBase3(0.0, 0.0, 0.0), 0, 0, 0);
_dummy_node->_status = _dummy_node->open;
_dummy_node->_score = -1;
@ -44,14 +43,13 @@ void PathFinder::find_path(Node *src_node, Node *dest_node) {
generate_path();
}
////////////////////////////////////////////////////////////////////
// Function: generate_path
// Description: This function performs the pathfinding process using the A* algorithm.
// It updates the openlist and closelist.
////////////////////////////////////////////////////////////////////
/**
* This function performs the pathfinding process using the A* algorithm. It
* updates the openlist and closelist.
*/
void PathFinder::generate_path() {
// All the A* algorithm is implemented here.
// The check is > 1 due to the existence of the dummy node.
// All the A* algorithm is implemented here. The check is > 1 due to the
// existence of the dummy node.
while(_open_list.size() > 1) {
// The first element of the open list will always be the optimal node.
// This is because the open list is a binary heap with element having the
@ -80,11 +78,10 @@ void PathFinder::generate_path() {
_closed_list.clear();
}
////////////////////////////////////////////////////////////////////
// Function: identify_neighbors
// Description: This function traverses through the 8 neigbors of the parent node and
// then adds the neighbors to the _open_list based on A* criteria.
////////////////////////////////////////////////////////////////////
/**
* This function traverses through the 8 neigbors of the parent node and then
* adds the neighbors to the _open_list based on A* criteria.
*/
void PathFinder::identify_neighbors(Node *parent_node) {
// Remove the parent node from the open_list so that it is not considered
// while adding new nodes to the open list heap.
@ -104,25 +101,21 @@ void PathFinder::identify_neighbors(Node *parent_node) {
}
}
////////////////////////////////////////////////////////////////////
// Function: calc_node_score
// Description: This function calculates the score of each node.
// Score = Cost + Heuristics.
////////////////////////////////////////////////////////////////////
/**
* This function calculates the score of each node. Score = Cost +
* Heuristics.
*/
void PathFinder::calc_node_score(Node *nd) {
nd->_cost = calc_cost_frm_src(nd);
nd->_heuristic = calc_heuristic(nd);
nd->_score = nd->_cost + nd->_heuristic;
}
////////////////////////////////////////////////////////////////////
// Function: calc_cost_frm_src
// Description: This function calculates the cost of each node by
// finding out the number of node traversals required
// to reach the source node. Diagonal traversals have
// cost = 14. Horizontal and vertical traversals have
// cost = 10.
////////////////////////////////////////////////////////////////////
/**
* This function calculates the cost of each node by finding out the number of
* node traversals required to reach the source node. Diagonal traversals
* have cost = 14. Horizontal and vertical traversals have cost = 10.
*/
int PathFinder::calc_cost_frm_src(Node *nd) {
int cost = 0;
Node *start_node = nd;
@ -145,14 +138,11 @@ int PathFinder::calc_cost_frm_src(Node *nd) {
return cost;
}
////////////////////////////////////////////////////////////////////
// Function: calc_heuristic
// Description: This function calculates the heuristic of the nodes
// using Manhattan method. All it does is predict the
// number of node traversals required to reach the
// target node. No diagonal traversals are allowed in
// this technique.
////////////////////////////////////////////////////////////////////
/**
* This function calculates the heuristic of the nodes using Manhattan method.
* All it does is predict the number of node traversals required to reach the
* target node. No diagonal traversals are allowed in this technique.
*/
int PathFinder::calc_heuristic(Node *nd) {
int row_diff = abs(_dest_node->_grid_x - nd->_grid_x);
int col_diff = abs(_dest_node->_grid_y - nd->_grid_y);
@ -161,10 +151,9 @@ int PathFinder::calc_heuristic(Node *nd) {
return heuristic;
}
////////////////////////////////////////////////////////////////////
// Function: is_diagonal_node
// Description: This function checks if the traversal from a node is diagonal.
////////////////////////////////////////////////////////////////////
/**
* This function checks if the traversal from a node is diagonal.
*/
bool PathFinder::is_diagonal_node(Node *nd) {
// Calculate the row and column differences between child and parent nodes.
float row_diff = nd->_grid_x - nd->_prv_node->_grid_x;
@ -179,11 +168,10 @@ bool PathFinder::is_diagonal_node(Node *nd) {
}
}
////////////////////////////////////////////////////////////////////
// Function: add_to_olist
// Description: This function adds a node to the open list heap.
// A binay heap is maintained to improve the search.
////////////////////////////////////////////////////////////////////
/**
* This function adds a node to the open list heap. A binay heap is
* maintained to improve the search.
*/
void PathFinder::add_to_olist(Node *nd) {
// Variables required to search the binary heap.
Node *child_node, *parent_node;
@ -195,9 +183,10 @@ void PathFinder::add_to_olist(Node *nd) {
_open_list.push_back(nd);
// Find the parent and child nodes and create temporary nodes out of them.
// In a binary heap the children of a parent node are always i*2 and i*2 + 1,
// where i is the index of the parent node in the heap. And hence, the parent
// of a node can be easily found out by dividing by 2 and rounding it.
// In a binary heap the children of a parent node are always i*2 and i*2 +
// 1, where i is the index of the parent node in the heap. And hence, the
// parent of a node can be easily found out by dividing by 2 and rounding
// it.
child_idx = _open_list.size() - 1;
parent_idx = child_idx / 2;
child_node = _open_list[child_idx];
@ -219,28 +208,29 @@ void PathFinder::add_to_olist(Node *nd) {
parent_node = _open_list[parent_idx];
}
// At this point the Node with the smallest score will be at the top of the heap.
// At this point the Node with the smallest score will be at the top of the
// heap.
}
////////////////////////////////////////////////////////////////////
// Function: remove_from_olist
// Description: This function removes a node from the open list.
// During the removal the binary heap is maintained.
////////////////////////////////////////////////////////////////////
/**
* This function removes a node from the open list. During the removal the
* binary heap is maintained.
*/
void PathFinder::remove_from_olist() {
// Variables for maintaining the binary heap.
Node *child_node, *child_node_1, *child_node_2;
int child_idx, child_idx_1, child_idx_2;
// Remove the Node at index 1 from the open list binary heap.
// Note: Node at index 0 of open list is a dummy node.
// Remove the Node at index 1 from the open list binary heap. Note: Node at
// index 0 of open list is a dummy node.
_open_list.erase(_open_list.begin() + 1);
if(_open_list.size() > 1) {
// Store the last element in the open list to a temp_node.
Node *temp_node = _open_list[_open_list.size() - 1];
// Shift the elements of the open list to the right by 1 element circularly, excluding element at 0 index.
// Shift the elements of the open list to the right by 1 element
// circularly, excluding element at 0 index.
for(int i = _open_list.size() - 1; i > 1; --i) {
_open_list[i] = _open_list[i - 1];
}
@ -251,7 +241,8 @@ void PathFinder::remove_from_olist() {
// Set the iterator for traversing the node from index 1 in the heap.
unsigned int k = 1;
// This loop traverses down the open list till the node reaches the correct position in the binary heap.
// This loop traverses down the open list till the node reaches the
// correct position in the binary heap.
while(true) {
if((k * 2 + 1) < _open_list.size()) {
// Two children exists for the parent node.
@ -311,13 +302,13 @@ void PathFinder::remove_from_olist() {
}
}
// At this point the Node was succesfully removed and the binary heap re-arranged.
// At this point the Node was succesfully removed and the binary heap re-
// arranged.
}
////////////////////////////////////////////////////////////////////
// Function: add_to_clist
// Description: This function adds a node to the closed list.
////////////////////////////////////////////////////////////////////
/**
* This function adds a node to the closed list.
*/
void PathFinder::add_to_clist(Node *nd) {
// Set the status as closed.
nd->_status = nd->close;
@ -325,10 +316,9 @@ void PathFinder::add_to_clist(Node *nd) {
_closed_list.push_back(nd);
}
////////////////////////////////////////////////////////////////////
// Function: remove_from_clist
// Description: This function removes a node from the closed list.
////////////////////////////////////////////////////////////////////
/**
* This function removes a node from the closed list.
*/
void PathFinder::remove_from_clist(int r, int c) {
for(unsigned int i = 0; i < _closed_list.size(); ++i) {
if(_closed_list[i]->_grid_x == r && _closed_list[i]->_grid_y == c) {
@ -338,12 +328,11 @@ void PathFinder::remove_from_clist(int r, int c) {
}
}
////////////////////////////////////////////////////////////////////
// Function: find_in_mesh
// Description: This function allows the user to pass a position and it returns the
// corresponding node on the navigation mesh. A very useful function as
// it allows for dynamic updation of the mesh based on position.
////////////////////////////////////////////////////////////////////
/**
* This function allows the user to pass a position and it returns the
* corresponding node on the navigation mesh. A very useful function as it
* allows for dynamic updation of the mesh based on position.
*/
Node* find_in_mesh(NavMesh nav_mesh, LVecBase3 pos, int grid_size) {
int size = grid_size;
float x = pos[0];

View File

@ -1,16 +1,15 @@
// Filename: aiPathFinder.h
// Created by: Deepak, John, Navin (10Nov09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiPathFinder.h
* @author Deepak, John, Navin
* @date 2009-11-10
*/
#ifndef _PATHFINDER_H
#define _PATHFINDER_H
@ -24,13 +23,11 @@ typedef vector<NodeArray> NavMesh;
Node* find_in_mesh(NavMesh nav_mesh, LVecBase3 pos, int grid_size);
////////////////////////////////////////////////////////////////////
// Class : PathFinder
// Description : This class implements pathfinding using A* algorithm.
// It also uses a Binary Heap search to search the
// open list. The heuristics are calculated using
// the manhattan method.
////////////////////////////////////////////////////////////////////
/**
* This class implements pathfinding using A* algorithm. It also uses a
* Binary Heap search to search the open list. The heuristics are calculated
* using the manhattan method.
*/
class EXPCL_PANDAAI PathFinder {
public:
Node *_src_node;

View File

@ -1,16 +1,15 @@
// Filename: aiWorld.cxx
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiWorld.cxx
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#include "aiWorld.h"
@ -55,11 +54,10 @@ void AIWorld::print_list() {
_ai_char_pool->print_list();
}
////////////////////////////////////////////////////////////////////
// Function: update
// Description: The AIWorld update function calls the update function of all the
// AI characters which have been added to the AIWorld.
////////////////////////////////////////////////////////////////////
/**
* The AIWorld update function calls the update function of all the AI
* characters which have been added to the AIWorld.
*/
void AIWorld::update() {
AICharPool::node *ai_pool;
ai_pool = _ai_char_pool->_head;
@ -70,12 +68,11 @@ void AIWorld::update() {
}
}
////////////////////////////////////////////////////////////////////
// Function: add_flock
// Description: This function adds all the AI characters in the Flock object to
// the AICharPool. This function allows adding the AI characetrs as
// part of a flock.
////////////////////////////////////////////////////////////////////
/**
* This function adds all the AI characters in the Flock object to the
* AICharPool. This function allows adding the AI characetrs as part of a
* flock.
*/
void AIWorld::add_flock(Flock *flock) {
// Add all the ai_characters in the flock to the AIWorld.
for(unsigned int i = 0; i < flock->_ai_char_list.size(); ++i) {
@ -85,10 +82,9 @@ void AIWorld::add_flock(Flock *flock) {
_flock_pool.push_back(flock);
}
////////////////////////////////////////////////////////////////////
// Function: get_flock
// Description: This function returns a handle to the Flock whose id is passed.
////////////////////////////////////////////////////////////////////
/**
* This function returns a handle to the Flock whose id is passed.
*/
Flock AIWorld::get_flock(unsigned int flock_id) {
for(unsigned int i=0; i < _flock_pool.size(); ++i) {
if(_flock_pool[i]->get_id() == flock_id) {
@ -99,10 +95,9 @@ Flock AIWorld::get_flock(unsigned int flock_id) {
return *null_flock;
}
////////////////////////////////////////////////////////////////////
// Function: remove_flock
// Description: This function removes the flock behavior completely.
////////////////////////////////////////////////////////////////////
/**
* This function removes the flock behavior completely.
*/
void AIWorld::remove_flock(unsigned int flock_id) {
for(unsigned int i = 0; i < _flock_pool.size(); ++i) {
if(_flock_pool[i]->get_id() == flock_id) {
@ -117,11 +112,10 @@ void AIWorld::remove_flock(unsigned int flock_id) {
}
}
////////////////////////////////////////////////////////////////////
// Function: flock_off
// Description: This function turns off the flock behavior temporarily. Similar to
// pausing the behavior.
////////////////////////////////////////////////////////////////////
/**
* This function turns off the flock behavior temporarily. Similar to pausing
* the behavior.
*/
void AIWorld::flock_off(unsigned int flock_id) {
for(unsigned int i = 0; i < _flock_pool.size(); ++i) {
if(_flock_pool[i]->get_id() == flock_id) {
@ -134,10 +128,9 @@ void AIWorld::flock_off(unsigned int flock_id) {
}
}
////////////////////////////////////////////////////////////////////
// Function: flock_on
// Description: This function turns on the flock behavior.
////////////////////////////////////////////////////////////////////
/**
* This function turns on the flock behavior.
*/
void AIWorld::flock_on(unsigned int flock_id) {
for(unsigned int i = 0; i < _flock_pool.size(); ++i) {
if(_flock_pool[i]->get_id() == flock_id) {
@ -216,11 +209,10 @@ void AICharPool::del(string name) {
}
}
////////////////////////////////////////////////////////////////////
// Function: print_list
// Description: This function prints the ai characters in the AICharPool. Used for
// debugging purposes.
////////////////////////////////////////////////////////////////////
/**
* This function prints the ai characters in the AICharPool. Used for
* debugging purposes.
*/
void AICharPool::print_list() {
node* q;
q = _head;
@ -230,20 +222,18 @@ void AICharPool::print_list() {
}
}
////////////////////////////////////////////////////////////////////
// Function: add_obstacle
// Description: This function adds the nodepath as an obstacle that is needed
// by the obstacle avoidance behavior.
////////////////////////////////////////////////////////////////////
/**
* This function adds the nodepath as an obstacle that is needed by the
* obstacle avoidance behavior.
*/
void AIWorld::add_obstacle(NodePath obstacle) {
_obstacles.push_back(obstacle);
}
////////////////////////////////////////////////////////////////////
// Function: remove_obstacle
// Description: This function removes the nodepath from the obstacles list that is needed
// by the obstacle avoidance behavior.
////////////////////////////////////////////////////////////////////
/**
* This function removes the nodepath from the obstacles list that is needed
* by the obstacle avoidance behavior.
*/
void AIWorld::remove_obstacle(NodePath obstacle) {
for(unsigned int i = 0; i <= _obstacles.size(); ++i) {
if(_obstacles[i] == obstacle) {

View File

@ -1,16 +1,15 @@
// Filename: aiWorld.h
// Created by: Deepak, John, Navin (08Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 aiWorld.h
* @author Deepak, John, Navin
* @date 2009-09-08
*/
#pragma warning (disable:4996)
#pragma warning (disable:4005)
@ -27,12 +26,11 @@
class AICharacter;
class Flock;
////////////////////////////////////////////////////////////////////
// Class : AICharPool
// Description : This class implements a linked list of AI Characters allowing
// the user to add and delete characters from the linked list.
// This will be used in the AIWorld class.
////////////////////////////////////////////////////////////////////
/**
* This class implements a linked list of AI Characters allowing the user to
* add and delete characters from the linked list. This will be used in the
* AIWorld class.
*/
class EXPCL_PANDAAI AICharPool {
public:
struct node {
@ -49,14 +47,13 @@ class EXPCL_PANDAAI AICharPool {
};
////////////////////////////////////////////////////////////////////
// Class : AIWorld
// Description : A class that implements the virtual AI world which keeps track
// of the AI characters active at any given time. It contains a linked
// list of AI characters, obstactle data and unique name for each
// character. It also updates each characters state. The AI characters
// can also be added to the world as flocks.
////////////////////////////////////////////////////////////////////
/**
* A class that implements the virtual AI world which keeps track of the AI
* characters active at any given time. It contains a linked list of AI
* characters, obstactle data and unique name for each character. It also
* updates each characters state. The AI characters can also be added to the
* world as flocks.
*/
class EXPCL_PANDAAI AIWorld {
private:
AICharPool * _ai_char_pool;

View File

@ -1,16 +1,15 @@
// Filename: arrival.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 arrival.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "arrival.h"
@ -24,14 +23,12 @@ Arrival::Arrival(AICharacter *ai_ch, double distance) {
Arrival::~Arrival() {
}
////////////////////////////////////////////////////////////////////
// Function: do_arrival
// Description: This function performs the arrival and returns an arrival force which is used
// in the calculate_prioritized function.
// In case the steering force = 0, it resets to arrival_activate.
// The arrival behavior works only when seek or pursue is active.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the arrival and returns an arrival force which is
* used in the calculate_prioritized function. In case the steering force =
* 0, it resets to arrival_activate. The arrival behavior works only when
* seek or pursue is active. This function is not to be used by the user.
*/
LVecBase3 Arrival::do_arrival() {
LVecBase3 direction_to_target;
double distance;
@ -84,12 +81,11 @@ LVecBase3 Arrival::do_arrival() {
return(LVecBase3(0.0, 0.0, 0.0));
}
////////////////////////////////////////////////////////////////////
// Function: arrival_activate
// Description: This function checks for whether the target is within the arrival distance.
// When this is true, it calls the do_arrival function and sets the arrival direction.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function checks for whether the target is within the arrival distance.
* When this is true, it calls the do_arrival function and sets the arrival
* direction. This function is not to be used by the user.
*/
void Arrival::arrival_activate() {
LVecBase3 dirn;
if(_arrival_type) {

View File

@ -1,16 +1,15 @@
// Filename: arrival.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 arrival.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _ARRIVAL_H
#define _ARRIVAL_H
@ -31,9 +30,8 @@ public:
LVecBase3 _arrival_direction;
bool _arrival_done;
// This flag specifies if the arrival behavior is being used with seek or pursue behavior.
// True = used with pursue.
// False = used with seek.
// This flag specifies if the arrival behavior is being used with seek or
// pursue behavior. True = used with pursue. False = used with seek.
bool _arrival_type;
Arrival(AICharacter *ai_ch, double distance = 10.0);

View File

@ -1,16 +1,15 @@
// Filename: config_ai.cxx
// Created by: Pandai (13Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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_ai.cxx
* @author Pandai
* @date 2009-09-13
*/
#include "config_ai.h"
#include "aiWorld.h"
@ -37,14 +36,12 @@ ConfigureFn(config_ai) {
init_libai();
}
////////////////////////////////////////////////////////////////////
// Function: init_libai
// 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.
////////////////////////////////////////////////////////////////////
/**
* 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_libai() {
static bool initialized = false;

View File

@ -1,16 +1,15 @@
// Filename: config_ai.h
// Created by: Pandai (13Sep09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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_ai.h
* @author Pandai
* @date 2009-09-13
*/
#ifndef CONFIG_AI_H
#define CONFIG_AI_H
@ -23,4 +22,3 @@ NotifyCategoryDecl(ai, EXPCL_PANDAAI, EXPTP_PANDAAI);
extern EXPCL_PANDAAI void init_libai();
#endif

View File

@ -1,16 +1,15 @@
// Filename: evade.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 evade.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "evade.h"
@ -30,14 +29,12 @@ Evade::Evade(AICharacter *ai_ch, NodePath target_object, double panic_distance,
Evade::~Evade() {
}
////////////////////////////////////////////////////////////////////
// Function: do_evade
// Description: This function performs the evade and returns an evade force which is used
// in the calculate_prioritized function.
// In case the AICharacter is past the (panic + relax) distance,
// it resets to evade_activate.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the evade and returns an evade force which is used
* in the calculate_prioritized function. In case the AICharacter is past the
* (panic + relax) distance, it resets to evade_activate. This function is
* not to be used by the user.
*/
LVecBase3 Evade::do_evade() {
assert(_evade_target && "evade target not assigned");
@ -62,12 +59,11 @@ LVecBase3 Evade::do_evade() {
}
}
////////////////////////////////////////////////////////////////////
// Function: evade_activate
// Description: This function checks for whether the target is within the panic distance.
// When this is true, it calls the do_evade function and sets the evade direction.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function checks for whether the target is within the panic distance.
* When this is true, it calls the do_evade function and sets the evade
* direction. This function is not to be used by the user.
*/
void Evade::evade_activate() {
_evade_direction = (_ai_char->_ai_char_np.get_pos(_ai_char->_window_render) - _evade_target.get_pos(_ai_char->_window_render));
double distance = _evade_direction.length();

View File

@ -1,16 +1,15 @@
// Filename: evade.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 evade.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _EVADE_H
#define _EVADE_H

View File

@ -1,16 +1,15 @@
// Filename: flee.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 flee.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "flee.h"
@ -45,14 +44,12 @@ Flee::Flee(AICharacter *ai_ch, LVecBase3 pos, double panic_distance,
Flee::~Flee() {
}
////////////////////////////////////////////////////////////////////
// Function: do_flee
// Description: This function performs the flee and returns a flee force which is used
// in the calculate_prioritized function.
// In case the AICharacter is past the (panic + relax) distance,
// it resets to flee_activate.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the flee and returns a flee force which is used in
* the calculate_prioritized function. In case the AICharacter is past the
* (panic + relax) distance, it resets to flee_activate. This function is not
* to be used by the user.
*/
LVecBase3 Flee::do_flee() {
LVecBase3 dirn;
double distance;
@ -76,12 +73,11 @@ LVecBase3 Flee::do_flee() {
}
}
////////////////////////////////////////////////////////////////////
// Function: flee_activate
// Description: This function checks for whether the target is within the panic distance.
// When this is true, it calls the do_flee function and sets the flee direction.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function checks for whether the target is within the panic distance.
* When this is true, it calls the do_flee function and sets the flee
* direction. This function is not to be used by the user.
*/
void Flee::flee_activate() {
LVecBase3 dirn;
double distance;

View File

@ -1,16 +1,15 @@
// Filename: flee.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 flee.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _FLEE_H
#define _FLEE_H

View File

@ -1,16 +1,15 @@
// Filename: flock.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 flock.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "flock.h"
@ -27,10 +26,9 @@ Flock::Flock(unsigned int flock_id, double vcone_angle, double vcone_radius, uns
Flock::~Flock() {
}
////////////////////////////////////////////////////////////////////
// Function: add_ai_char
// Description: This function adds AI characters to the flock.
////////////////////////////////////////////////////////////////////
/**
* This function adds AI characters to the flock.
*/
void Flock::add_ai_char(AICharacter *ai_char) {
ai_char->_ai_char_flock_id = _flock_id;
ai_char->_steering->_flock_group = this;

View File

@ -1,16 +1,15 @@
// Filename: flock.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 flock.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _FLOCK_H
#define _FLOCK_H
@ -20,22 +19,22 @@
class AICharacter;
////////////////////////////////////////////////////////////////////
// Class : Flock
// Description : This class is used to define the flock attributes and the AI characters
// which are part of the flock.
////////////////////////////////////////////////////////////////////
/**
* This class is used to define the flock attributes and the AI characters
* which are part of the flock.
*/
class EXPCL_PANDAAI Flock {
private:
unsigned int _flock_id;
public:
// Variables which will hold the parameters of the ai character's visibilty cone.
// Variables which will hold the parameters of the ai character's visibilty
// cone.
double _flock_vcone_angle;
double _flock_vcone_radius;
// Variables to specify weights of separation, cohesion and alignment behaviors and thus
// create variable flock behavior.
// Variables to specify weights of separation, cohesion and alignment
// behaviors and thus create variable flock behavior.
unsigned int _separation_wt;
unsigned int _cohesion_wt;
unsigned int _alignment_wt;

View File

@ -24,11 +24,10 @@ Node::Node(int grid_x, int grid_y, LVecBase3 pos, float w, float l, float h) {
Node::~Node() {
}
////////////////////////////////////////////////////////////////////
// Function: contains
// Description: This is a handy function which returns true if the passed position is
// within the node's dimensions.
////////////////////////////////////////////////////////////////////
/**
* This is a handy function which returns true if the passed position is
* within the node's dimensions.
*/
bool Node::contains(float x, float y) {
if(_position.get_x() - _width / 2 <= x && _position.get_x() + _width / 2 >= x &&
_position.get_y() - _length / 2 <= y && _position.get_y() + _length / 2 >= y) {

View File

@ -4,29 +4,24 @@
#include "aiGlobals.h"
////////////////////////////////////////////////////////////////////
// Class : Node
// Description : This class is used to assign the nodes on the mesh.
// It holds all the data necessary to compute A*
// algorithm. It also maintains a lot of vital
// information such as the neighbor nodes of each node
// and also its position on the mesh.
//
// Note: The Mesh Generator which is a stand alone tool
// makes use of this class to generate the nodes on the
// mesh.
////////////////////////////////////////////////////////////////////
/**
* This class is used to assign the nodes on the mesh. It holds all the data
* necessary to compute A* algorithm. It also maintains a lot of vital
* information such as the neighbor nodes of each node and also its position
* on the mesh.
*
* Note: The Mesh Generator which is a stand alone tool makes use of this
* class to generate the nodes on the mesh.
*/
class EXPCL_PANDAAI Node {
public:
// This variable specifies whether the node is an obtacle or not.
// Used for dynamic obstacle addition to the environment.
// obstacle = false
// This variable specifies whether the node is an obtacle or not. Used
// for dynamic obstacle addition to the environment. obstacle = false
// navigational = true
bool _type;
// This variable specifies the node status whether open, close or neutral.
// open = belongs to _open_list.
// close = belongs to _closed_list.
// open = belongs to _open_list. close = belongs to _closed_list.
// neutral = unexamined node.
enum Status {
open,
@ -35,8 +30,8 @@ public:
};
Status _status;
// The score is used to compute the traversal expense to nodes when using A*.
// _score = _cost + heuristic
// The score is used to compute the traversal expense to nodes when using
// A*. _score = _cost + heuristic
int _score;
int _cost;
int _heuristic;
@ -50,13 +45,14 @@ public:
// Position of the node in 3D space.
LVecBase3 _position;
// Dimensions of each face / cell on the mesh.
// Height is given in case of expansion to a 3d mesh. Currently not used.
// Dimensions of each face cell on the mesh. Height is given in case of
// expansion to a 3d mesh. Currently not used.
float _width, _length ,_height;
Node *_neighbours[8]; // anti-clockwise from top left corner.
// The _next pointer is used for traversal during mesh generation from the model.
// Note: The data in this member is discarded when mesh data is written into navmesh.csv file.
// The _next pointer is used for traversal during mesh generation from the
// model. Note: The data in this member is discarded when mesh data is
// written into navmesh.csv file.
Node *_next;
Node(int grid_x, int grid_y, LVecBase3 pos, float w, float l, float h);

View File

@ -1,16 +1,15 @@
// Filename: obstacleAvoidance.cxx
// Created by: Deepak, John, Navin (10Nov09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 obstacleAvoidance.cxx
* @author Deepak, John, Navin
* @date 2009-11-10
*/
#include "obstacleAvoidance.h"
@ -24,11 +23,10 @@ ObstacleAvoidance::
~ObstacleAvoidance() {
}
////////////////////////////////////////////////////////////////////
// Function: obstacle_detection
// Description: This function checks if an obstacle is near to the AICharacter and
// if an obstacle is detected returns true
////////////////////////////////////////////////////////////////////
/**
* This function checks if an obstacle is near to the AICharacter and if an
* obstacle is detected returns true
*/
bool ObstacleAvoidance::
obstacle_detection() {
// Calculate the volume of the AICharacter with respect to render
@ -43,7 +41,8 @@ obstacle_detection() {
PT(BoundingVolume) bounds = _ai_char->_world->_obstacles[i].get_bounds();
CPT(BoundingSphere) bsphere = bounds->as_bounding_sphere();
LVecBase3 near_obstacle = _ai_char->_world->_obstacles[i].get_pos() - _ai_char->get_node_path().get_pos();
// Check if it's the nearest obstacle, If so initialize as the nearest obstacle
// Check if it's the nearest obstacle, If so initialize as the nearest
// obstacle
if((near_obstacle.length() < distance) && (_ai_char->_world->_obstacles[i].get_pos() != _ai_char->get_node_path().get_pos())) {
_nearest_obstacle = _ai_char->_world->_obstacles[i];
distance = near_obstacle.length();
@ -59,18 +58,17 @@ obstacle_detection() {
LVecBase3 project = (to_obstacle.dot(line_vector) * line_vector) / line_vector.length_squared();
LVecBase3 perp = project - to_obstacle;
// If the nearest obstacle will collide with our AICharacter then send obstacle detection as true
// If the nearest obstacle will collide with our AICharacter then send
// obstacle detection as true
if (_nearest_obstacle && (perp.length() < expanded_radius - np_sphere->get_radius()) && (project.length() < feeler.length())) {
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function: obstacle_avoidance_activate
// Description: This function activates obstacle_avoidance if a obstacle
// is detected
////////////////////////////////////////////////////////////////////
/**
* This function activates obstacle_avoidance if a obstacle is detected
*/
void ObstacleAvoidance::
obstacle_avoidance_activate() {
if (obstacle_detection()) {
@ -79,13 +77,11 @@ obstacle_avoidance_activate() {
}
}
////////////////////////////////////////////////////////////////////
// Function: do_obstacle_avoidance
// Description: This function returns the force necessary by the AICharacter to
// avoid the nearest obstacle detected by obstacle_detection
// function
// NOTE : This assumes the obstacles are spherical
////////////////////////////////////////////////////////////////////
/**
* This function returns the force necessary by the AICharacter to avoid the
* nearest obstacle detected by obstacle_detection function NOTE : This
* assumes the obstacles are spherical
*/
LVecBase3 ObstacleAvoidance::
do_obstacle_avoidance() {
LVecBase3 offset = _ai_char->get_node_path().get_pos() - _nearest_obstacle.get_pos();

View File

@ -1,16 +1,15 @@
// Filename: obstacleAvoidance.h
// Created by: Deepak, John, Navin (10Nov09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 obstacleAvoidance.h
* @author Deepak, John, Navin
* @date 2009-11-10
*/
#ifndef OBSTACLE_AVOIDANCE_H
#define OBSTACLE_AVOIDANCE_H

View File

@ -1,3 +1,15 @@
/**
* 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 pathFind.cxx
* @author Deepak, John, Navin
* @date 2009-10-12
*/
#include "pathFind.h"
@ -18,10 +30,9 @@ PathFind::PathFind(AICharacter *ai_ch) {
PathFind::~PathFind() {
}
////////////////////////////////////////////////////////////////////
// Function: create_nav_mesh
// Description: This function recreates the navigation mesh from the .csv file
////////////////////////////////////////////////////////////////////
/**
* This function recreates the navigation mesh from the .csv file
*/
void PathFind::create_nav_mesh(const char* navmesh_filename) {
// Stage variables.
int grid_x, grid_y;
@ -59,8 +70,9 @@ void PathFind::create_nav_mesh(const char* navmesh_filename) {
getline(nav_mesh_file, line);
stringstream linestream (line);
// Stores all the data members in the line to the array.
// Data structure: NULL,NodeType,GridX,GridY,Length,Width,Height,PosX,PosY,PosZ
// Stores all the data members in the line to the array. Data
// structure:
// NULL,NodeType,GridX,GridY,Length,Width,Height,PosX,PosY,PosZ
for(int i = 0; i < 10; ++i) {
getline(linestream, fields[i], ',');
}
@ -83,7 +95,8 @@ void PathFind::create_nav_mesh(const char* navmesh_filename) {
// End of file reached at this point.
nav_mesh_file.close();
// Assign the neighbor nodes for each of the main nodes that just got populated into the stage mesh.
// Assign the neighbor nodes for each of the main nodes that just got
// populated into the stage mesh.
assign_neighbor_nodes(navmesh_filename);
}
}
@ -93,11 +106,10 @@ void PathFind::create_nav_mesh(const char* navmesh_filename) {
}
}
////////////////////////////////////////////////////////////////////
// Function: assign_neighbor_nodes
// Description: This function assigns the neighbor nodes for each
// main node present in _nav_mesh.
////////////////////////////////////////////////////////////////////
/**
* This function assigns the neighbor nodes for each main node present in
* _nav_mesh.
*/
void PathFind::assign_neighbor_nodes(const char* navmesh_filename){
ifstream nav_mesh_file (navmesh_filename);
@ -131,8 +143,9 @@ void PathFind::assign_neighbor_nodes(const char* navmesh_filename){
gd_yn = atoi(fields_n[3].c_str());
if(fields_n[0] == "0" && fields_n[1] == "1") {
// Usable neighbor for main node.
// TODO: The indices of the vector are inverted when compared to the values of the nodes on actual grid. Fix this!
// Usable neighbor for main node. TODO: The indices of the vector
// are inverted when compared to the values of the nodes on actual
// grid. Fix this!
_nav_mesh[gd_y][gd_x]->_neighbours[i] = _nav_mesh[gd_yn][gd_xn];
}
else if(fields_n[0] == "1" && fields_n[1] == "1") {
@ -155,11 +168,10 @@ void PathFind::assign_neighbor_nodes(const char* navmesh_filename){
}
}
////////////////////////////////////////////////////////////////////
// Function: set_path_find
// Description: This function starts the path finding process after reading the given
// navigation mesh.
////////////////////////////////////////////////////////////////////
/**
* This function starts the path finding process after reading the given
* navigation mesh.
*/
void PathFind::set_path_find(const char* navmesh_filename) {
create_nav_mesh(navmesh_filename);
@ -177,12 +189,11 @@ void PathFind::set_path_find(const char* navmesh_filename) {
_path_finder_obj = new PathFinder(_nav_mesh);
}
////////////////////////////////////////////////////////////////////
// Function: path_find (for pathfinding towards a static position)
// Description: This function checks for the source and target in the navigation mesh
// for its availability and then finds the best path via the A* algorithm
// Then it calls the path follower to make the object follow the path.
////////////////////////////////////////////////////////////////////
/**
* This function checks for the source and target in the navigation mesh for
* its availability and then finds the best path via the A* algorithm Then it
* calls the path follower to make the object follow the path.
*/
void PathFind::path_find(LVecBase3 pos, string type) {
if(type == "addPath") {
if(_ai_char->_steering->_path_follow_obj) {
@ -216,12 +227,11 @@ void PathFind::path_find(LVecBase3 pos, string type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: path_find (for pathfinding towards a moving target (a NodePath))
// Description: This function checks for the source and target in the navigation mesh
// for its availability and then finds the best path via the A* algorithm
// Then it calls the path follower to make the object follow the path.
////////////////////////////////////////////////////////////////////
/**
* This function checks for the source and target in the navigation mesh for
* its availability and then finds the best path via the A* algorithm Then it
* calls the path follower to make the object follow the path.
*/
void PathFind::path_find(NodePath target, string type) {
if(type == "addPath") {
if(_ai_char->_steering->_path_follow_obj) {
@ -260,10 +270,9 @@ void PathFind::path_find(NodePath target, string type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: clear_path
// Description: Helper function to restore the path and mesh to its initial state
////////////////////////////////////////////////////////////////////
/**
* Helper function to restore the path and mesh to its initial state
*/
void PathFind::clear_path() {
// Initialize to zero
for(int i = 0; i < _grid_size; ++i) {
@ -284,12 +293,11 @@ void PathFind::clear_path() {
}
}
////////////////////////////////////////////////////////////////////
// Function: trace_path
// Description: This function is the function which sends the path information one by
// one to the path follower so that it can store the path needed to be
// traversed by the pathfinding object
////////////////////////////////////////////////////////////////////
/**
* This function is the function which sends the path information one by one
* to the path follower so that it can store the path needed to be traversed
* by the pathfinding object
*/
void PathFind::trace_path(Node* src) {
if(_ai_char->_pf_guide) {
_parent->remove_all_children();
@ -313,13 +321,12 @@ void PathFind::trace_path(Node* src) {
}
}
////////////////////////////////////////////////////////////////////
// Function: add_obstacle_to_mesh
// Description: This function allows the user to dynamically add obstacles to the
// game environment. The function will update the nodes within the
// bounding volume of the obstacle as non-traversable. Hence will not be
// considered by the pathfinding algorithm.
////////////////////////////////////////////////////////////////////
/**
* This function allows the user to dynamically add obstacles to the game
* environment. The function will update the nodes within the bounding volume
* of the obstacle as non-traversable. Hence will not be considered by the
* pathfinding algorithm.
*/
void PathFind::add_obstacle_to_mesh(NodePath obstacle) {
PT(BoundingVolume) np_bounds = obstacle.get_bounds();
CPT(BoundingSphere) np_sphere = np_bounds->as_bounding_sphere();
@ -347,11 +354,10 @@ void PathFind::add_obstacle_to_mesh(NodePath obstacle) {
}
}
////////////////////////////////////////////////////////////////////
// Function: do_dynamic_avoid()
// Description: This function does the updation of the collisions to the mesh based
// on the new positions of the obstacles.
////////////////////////////////////////////////////////////////////
/**
* This function does the updation of the collisions to the mesh based on the
* new positions of the obstacles.
*/
void PathFind::do_dynamic_avoid() {
clear_previous_obstacles();
_previous_obstacles.clear();
@ -360,22 +366,20 @@ void PathFind::do_dynamic_avoid() {
}
}
////////////////////////////////////////////////////////////////////
// Function: clear_previous_obstacles()
// Description: Helper function to reset the collisions if the obstacle is not on the
// node anymore
////////////////////////////////////////////////////////////////////
/**
* Helper function to reset the collisions if the obstacle is not on the node
* anymore
*/
void PathFind::clear_previous_obstacles(){
for(unsigned int i = 0; i < _previous_obstacles.size(); i = i + 2) {
_nav_mesh[_previous_obstacles[i]][_previous_obstacles[i + 1]]->_type = true;
}
}
////////////////////////////////////////////////////////////////////
// Function: dynamic_avoid
// Description: This function starts the pathfinding obstacle navigation for the
// passed in obstacle.
////////////////////////////////////////////////////////////////////
/**
* This function starts the pathfinding obstacle navigation for the passed in
* obstacle.
*/
void PathFind::dynamic_avoid(NodePath obstacle) {
_dynamic_avoid = true;
_dynamic_obstacle.insert(_dynamic_obstacle.end(), obstacle);

View File

@ -1,16 +1,15 @@
// Filename: pathFind.h
// Created by: Deepak, John, Navin (12Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 pathFind.h
* @author Deepak, John, Navin
* @date 2009-10-12
*/
#ifndef _PATHFIND_H
#define _PATHFIND_H
@ -22,15 +21,12 @@
class AICharacter;
////////////////////////////////////////////////////////////////////
// Class : PathFind
// Description : This class contains all the members and functions
// that are required to form an interface between
// the AIBehaviors class and the PathFinder class.
// An object (pointer) of this class is provided in
// the AIBehaviors class. It is only via this object
// that the user can activate pathfinding.
////////////////////////////////////////////////////////////////////
/**
* This class contains all the members and functions that are required to form
* an interface between the AIBehaviors class and the PathFinder class. An
* object (pointer) of this class is provided in the AIBehaviors class. It is
* only via this object that the user can activate pathfinding.
*/
class EXPCL_PANDAAI PathFind {
public:
AICharacter *_ai_char;
@ -67,4 +63,3 @@ public:
};
#endif

View File

@ -12,19 +12,17 @@ PathFollow::PathFollow(AICharacter *ai_ch, float follow_wt) {
PathFollow::~PathFollow() {
}
////////////////////////////////////////////////////////////////////
// Function: add_to_path
// Description: This function adds the positions generated from a pathfind or a simple
// path follow behavior to the _path list.
////////////////////////////////////////////////////////////////////
/**
* This function adds the positions generated from a pathfind or a simple path
* follow behavior to the _path list.
*/
void PathFollow::add_to_path(LVecBase3 pos) {
_path.push_back(pos);
}
////////////////////////////////////////////////////////////////////
// Function: start
// Description: This function initiates the path follow behavior.
////////////////////////////////////////////////////////////////////
/**
* This function initiates the path follow behavior.
*/
void PathFollow::start(string type) {
_type = type;
_start = true;
@ -37,21 +35,20 @@ void PathFollow::start(string type) {
}
}
////////////////////////////////////////////////////////////////////
// Function: do_follow
// Description: This function allows continuous path finding by ai chars. There are 2
// ways in which this is implemented.
// 1. The character re-calculates the optimal path everytime the target
// changes its position. Less computationally expensive.
// 2. The character continuosly re-calculates its optimal path to the
// target. This is used in a scenario where the ai chars have to avoid
// other ai chars. More computationally expensive.
////////////////////////////////////////////////////////////////////
/**
* This function allows continuous path finding by ai chars. There are 2 ways
* in which this is implemented. 1. The character re-calculates the optimal
* path everytime the target changes its position. Less computationally
* expensive. 2. The character continuosly re-calculates its optimal path to
* the target. This is used in a scenario where the ai chars have to avoid
* other ai chars. More computationally expensive.
*/
void PathFollow::do_follow() {
if((_myClock->get_real_time() - _time) > 0.5) {
if(_type=="pathfind") {
// This 'if' statement when 'true' causes the path to be re-calculated irrespective of target position.
// This is done when _dynamice_avoid is active. More computationally expensive.
// This 'if' statement when 'true' causes the path to be re-calculated
// irrespective of target position. This is done when _dynamice_avoid
// is active. More computationally expensive.
if(_ai_char->_steering->_path_find_obj->_dynamic_avoid) {
_ai_char->_steering->_path_find_obj->do_dynamic_avoid();
if(check_if_possible()) {
@ -68,8 +65,9 @@ void PathFollow::do_follow() {
}
}
}
// This 'if' statement causes the path to be re-calculated only when there is a change in target position.
// Less computationally expensive.
// This 'if' statement causes the path to be re-calculated only when
// there is a change in target position. Less computationally
// expensive.
else if(_ai_char->_steering->_path_find_obj->_path_find_target.get_pos(_ai_char->_window_render)
!= _ai_char->_steering->_path_find_obj->_prev_position) {
if(check_if_possible()) {
@ -100,11 +98,10 @@ void PathFollow::do_follow() {
}
}
////////////////////////////////////////////////////////////////////
// Function: check_if_possible
// Description: This function checks if the current positions of the ai char and the
// target char can be used to generate an optimal path.
////////////////////////////////////////////////////////////////////
/**
* This function checks if the current positions of the ai char and the target
* char can be used to generate an optimal path.
*/
bool PathFollow::check_if_possible() {
Node* src = find_in_mesh(_ai_char->_steering->_path_find_obj->_nav_mesh, _ai_char->_ai_char_np.get_pos(_ai_char->_window_render), _ai_char->_steering->_path_find_obj->_grid_size);
LVecBase3 _prev_position = _ai_char->_steering->_path_find_obj->_path_find_target.get_pos(_ai_char->_window_render);

View File

@ -1,16 +1,15 @@
// Filename: pursue.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 pursue.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "pursue.h"
@ -28,13 +27,12 @@ Pursue::
~Pursue() {
}
////////////////////////////////////////////////////////////////////
// Function: do_pursue
// Description: This function performs the pursue and returns a pursue force which is used
// in the calculate_prioritized function.
// In case the target has been reached it resets the forces to 0 so that the character stops.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the pursue and returns a pursue force which is used
* in the calculate_prioritized function. In case the target has been reached
* it resets the forces to 0 so that the character stops. This function is
* not to be used by the user.
*/
LVecBase3 Pursue::
do_pursue() {
assert(_pursue_target && "pursue target not assigned");

View File

@ -1,16 +1,15 @@
// Filename: pursue.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 pursue.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _PURSUE_H
#define _PURSUE_H

View File

@ -1,16 +1,15 @@
// Filename: seek.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 seek.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "seek.h"
@ -41,12 +40,11 @@ Seek::Seek(AICharacter *ai_ch, LVecBase3 pos, float seek_wt) {
Seek::~Seek() {
}
////////////////////////////////////////////////////////////////////
// Function: do_seek
// Description: This function performs the seek and returns a seek force which is used
// in the calculate_prioritized function.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the seek and returns a seek force which is used in
* the calculate_prioritized function. This function is not to be used by the
* user.
*/
LVecBase3 Seek::do_seek() {
double target_distance = (_seek_position - _ai_char->_ai_char_np.get_pos(_ai_char->_window_render)).length();

View File

@ -1,16 +1,15 @@
// Filename: seek.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 seek.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _SEEK_H
#define _SEEK_H

View File

@ -1,33 +1,29 @@
// Filename: wander.cxx
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 wander.cxx
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#include "wander.h"
////////////////////////////////////////////////////////////////////
// Function: rand_float
// Description: This function creates a random float point number
////////////////////////////////////////////////////////////////////
/**
* This function creates a random float point number
*/
double rand_float() {
const static double rand_max = 0x7fff;
return ((rand()) / (rand_max + 1.0));
}
////////////////////////////////////////////////////////////////////
// Function: random_clamped
// Description: This function returns a random floating point number in the range
// -1 to 1.
////////////////////////////////////////////////////////////////////
/**
* This function returns a random floating point number in the range -1 to 1.
*/
double random_clamped() {
return (rand_float() - rand_float());
}
@ -42,12 +38,9 @@ Wander::Wander(AICharacter *ai_ch, double wander_radius,int flag, double aoe, fl
// Area around which the character should wander
_area_of_effect = aoe;
_init_pos = _ai_char->get_node_path().get_pos(_ai_char->get_char_render());
// _flag is used by Wander to wander in a given axis
// Value 0 - XY axes wander
// Value 1 - YZ axes wander
// Value 2 - XZ axes wander
// Value 3 - XYZ axes wander
// default is XY axes
// _flag is used by Wander to wander in a given axis Value 0 - XY axes
// wander Value 1 - YZ axes wander Value 2 - XZ axes wander Value 3 - XYZ
// axes wander default is XY axes
switch(_flag) {
case 0: {
_wander_target = LVecBase3(_wander_radius * cos(theta), _wander_radius * sin(theta),0);
@ -75,15 +68,15 @@ Wander::Wander(AICharacter *ai_ch, double wander_radius,int flag, double aoe, fl
Wander::~Wander() {
}
////////////////////////////////////////////////////////////////////
// Function: do_wander
// Description: This function performs the wander and returns the wander force which is used
// in the calculate_prioritized function.
// This function is not to be used by the user.
////////////////////////////////////////////////////////////////////
/**
* This function performs the wander and returns the wander force which is
* used in the calculate_prioritized function. This function is not to be
* used by the user.
*/
LVecBase3 Wander::do_wander() {
LVecBase3 present_pos = _ai_char->get_node_path().get_pos(_ai_char->get_char_render());
// Create the random slices to enable random movement of wander for x,y,z respectively
// Create the random slices to enable random movement of wander for x,y,z
// respectively
double time_slice_1 = random_clamped() * 1.5;
double time_slice_2 = random_clamped() * 1.5;
double time_slice_3 = random_clamped() * 1.5;

View File

@ -1,16 +1,15 @@
// Filename: wander.h
// Created by: Deepak, John, Navin (24Oct09)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 wander.h
* @author Deepak, John, Navin
* @date 2009-10-24
*/
#ifndef _WANDER_H
#define _WANDER_H

View File

@ -1,15 +1,14 @@
// Filename: contribbase.cxx
// Created by: rdb (26Apr10)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 contribbase.cxx
* @author rdb
* @date 2010-04-26
*/
#include "contribbase.h"

View File

@ -1,8 +1,4 @@
/* Filename: contribbase.h
* Created by: rdb (30Dec09)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contribbase.h
* @author rdb
* @date 2009-12-30
*/
/* This file is included at the beginning of every header file and/or
C or C++ file. It must be compilable for C as well as C++ files,
@ -23,4 +22,3 @@
#include "contribsymbols.h"
#endif

View File

@ -1,8 +1,4 @@
/* Filename: contribsymbols.h
* Created by: rdb (30Dec09)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
@ -10,7 +6,10 @@
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* @file contribsymbols.h
* @author rdb
* @date 2009-12-30
*/
#ifndef CONTRIBSYMBOLS_H
#define CONTRIBSYMBOLS_H

View File

@ -1,9 +1,10 @@
// Filename: direct.cxx
// Created by: drose (18May00)
//
////////////////////////////////////////////////////////////////////
/**
* @file direct.cxx
* @author drose
* @date 2000-05-18
*/
// This is a dummy file whose sole purpose is to give the compiler
// something to compile when making libdirect.so in NO_DEFER mode,
// which generates an empty library that itself links with all the
// other shared libraries that make up libdirect.
// This is a dummy file whose sole purpose is to give the compiler something
// to compile when making libdirect.so in NO_DEFER mode, which generates an
// empty library that itself links with all the other shared libraries that
// make up libdirect.

View File

@ -1,16 +1,15 @@
// Filename: dcparse.cxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcparse.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcbase.h"
#include "dcFile.h"
@ -22,7 +21,7 @@
void
usage() {
cerr <<
cerr <<
"\n"
"Usage:\n\n"
"dcparse [options] [file1 file2 ...]\n"
@ -32,7 +31,7 @@ usage() {
void
help() {
usage();
cerr <<
cerr <<
"This program reads one or more DC files, which are used to describe the\n"
"communication channels in the distributed class system. By default,\n"
"the file(s) are read and concatenated, and a single hash code is printed\n"
@ -58,7 +57,7 @@ help() {
}
void
write_class_hierarchy(int indent_level, const DCFile &file,
write_class_hierarchy(int indent_level, const DCFile &file,
const DCClass *this_dclass) {
indent(cout, indent_level)
<< this_dclass->get_name() << "\n";
@ -117,7 +116,7 @@ write_complete_field_list(const DCFile &file) {
int
main(int argc, char *argv[]) {
// extern char *optarg;
// extern char *optarg;
extern int optind;
const char *optstr = "bvcfh";

View File

@ -1,27 +1,24 @@
// Filename: dcArrayParameter.cxx
// Created by: drose (17Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcArrayParameter.cxx
* @author drose
* @date 2004-06-17
*/
#include "dcArrayParameter.h"
#include "dcSimpleParameter.h"
#include "dcClassParameter.h"
#include "hashGenerator.h"
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCArrayParameter::
DCArrayParameter(DCParameter *element_type, const DCUnsignedIntRange &size) :
_element_type(element_type),
@ -41,10 +38,10 @@ DCArrayParameter(DCParameter *element_type, const DCUnsignedIntRange &size) :
_has_fixed_byte_size = true;
_fixed_byte_size = _array_size * _element_type->get_fixed_byte_size();
_has_fixed_structure = true;
} else {
// We only need to store the length bytes if the array has a
// variable size.
// We only need to store the length bytes if the array has a variable
// size.
_num_length_bytes = 2;
}
@ -63,20 +60,18 @@ DCArrayParameter(DCParameter *element_type, const DCUnsignedIntRange &size) :
DCSimpleParameter *simple_type = _element_type->as_simple_parameter();
if (simple_type != (DCSimpleParameter *)NULL) {
if (simple_type->get_type() == ST_char) {
// We make a special case for char[] arrays: these we format as
// a string. (It will still accept an array of ints packed into
// it.) We don't make this special case for uint8[] or int8[]
// arrays, although we will accept a string packed in for them.
// We make a special case for char[] arrays: these we format as a
// string. (It will still accept an array of ints packed into it.) We
// don't make this special case for uint8[] or int8[] arrays, although
// we will accept a string packed in for them.
_pack_type = PT_string;
}
}
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCArrayParameter::
DCArrayParameter(const DCArrayParameter &copy) :
DCParameter(copy),
@ -86,91 +81,71 @@ DCArrayParameter(const DCArrayParameter &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCArrayParameter::
~DCArrayParameter() {
delete _element_type;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::as_array_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCArrayParameter *DCArrayParameter::
as_array_parameter() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::as_array_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCArrayParameter *DCArrayParameter::
as_array_parameter() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::make_copy
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCArrayParameter::
make_copy() const {
return new DCArrayParameter(*this);
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::is_valid
// Access: Published, Virtual
// Description: Returns false if the type is an invalid type
// (e.g. declared from an undefined typedef), true if
// it is valid.
////////////////////////////////////////////////////////////////////
/**
* Returns false if the type is an invalid type (e.g. declared from an
* undefined typedef), true if it is valid.
*/
bool DCArrayParameter::
is_valid() const {
return _element_type->is_valid();
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::get_element_type
// Access: Published
// Description: Returns the type of the individual elements of this
// array.
////////////////////////////////////////////////////////////////////
/**
* Returns the type of the individual elements of this array.
*/
DCParameter *DCArrayParameter::
get_element_type() const {
return _element_type;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::get_array_size
// Access: Published
// Description: Returns the fixed number of elements in this array,
// or -1 if the array may contain a variable number of
// elements.
////////////////////////////////////////////////////////////////////
/**
* Returns the fixed number of elements in this array, or -1 if the array may
* contain a variable number of elements.
*/
int DCArrayParameter::
get_array_size() const {
return _array_size;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::append_array_specification
// Access: Public, Virtual
// Description: Returns the type represented by this_type[size].
//
// In the case of a DCArrayParameter, this means it
// modifies the current type to append the array
// specification on the innermost type, and returns this
// same pointer again.
////////////////////////////////////////////////////////////////////
/**
* Returns the type represented by this_type[size].
*
* In the case of a DCArrayParameter, this means it modifies the current type
* to append the array specification on the innermost type, and returns this
* same pointer again.
*/
DCParameter *DCArrayParameter::
append_array_specification(const DCUnsignedIntRange &size) {
if (get_typedef() != (DCTypedef *)NULL) {
@ -183,16 +158,12 @@ append_array_specification(const DCUnsignedIntRange &size) {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::calc_num_nested_fields
// Access: Public, Virtual
// Description: This flavor of get_num_nested_fields is used during
// unpacking. It returns the number of nested fields to
// expect, given a certain length in bytes (as read from
// the get_num_length_bytes() stored in the stream on the
// pack). This will only be called if
// get_num_length_bytes() returns nonzero.
////////////////////////////////////////////////////////////////////
/**
* This flavor of get_num_nested_fields is used during unpacking. It returns
* the number of nested fields to expect, given a certain length in bytes (as
* read from the get_num_length_bytes() stored in the stream on the pack).
* This will only be called if get_num_length_bytes() returns nonzero.
*/
int DCArrayParameter::
calc_num_nested_fields(size_t length_bytes) const {
if (_element_type->has_fixed_byte_size()) {
@ -201,43 +172,34 @@ calc_num_nested_fields(size_t length_bytes) const {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCArrayParameter::
get_nested_field(int) const {
return _element_type;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::validate_num_nested_fields
// Access: Public, Virtual
// Description: After a number of fields have been packed via push()
// .. pack_*() .. pop(), this is called to confirm that
// the number of nested fields that were added is valid
// for this type. This is primarily useful for array
// types with dynamic ranges that can't validate the
// number of fields any other way.
////////////////////////////////////////////////////////////////////
/**
* After a number of fields have been packed via push() .. pack_*() .. pop(),
* this is called to confirm that the number of nested fields that were added
* is valid for this type. This is primarily useful for array types with
* dynamic ranges that can't validate the number of fields any other way.
*/
bool DCArrayParameter::
validate_num_nested_fields(int num_nested_fields) const {
bool range_error = false;
_array_size_range.validate(num_nested_fields, range_error);
return !range_error;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::output_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCArrayParameter::
output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const {
@ -246,22 +208,19 @@ output_instance(ostream &out, bool brief, const string &prename,
} else {
ostringstream strm;
strm << "[";
_array_size_range.output(strm);
strm << "]";
_element_type->output_instance(out, brief, prename, name,
_element_type->output_instance(out, brief, prename, name,
postname + strm.str());
}
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this type into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this type into the hash.
*/
void DCArrayParameter::
generate_hash(HashGenerator &hashgen) const {
DCParameter::generate_hash(hashgen);
@ -269,17 +228,13 @@ generate_hash(HashGenerator &hashgen) const {
_array_size_range.generate_hash(hashgen);
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::pack_string
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCArrayParameter::
pack_string(DCPackData &pack_data, const string &value,
bool &pack_error, bool &range_error) const {
// We can only pack a string if the array element type is char or
// int8.
// We can only pack a string if the array element type is char or int8.
DCSimpleParameter *simple_type = _element_type->as_simple_parameter();
if (simple_type == (DCSimpleParameter *)NULL) {
pack_error = true;
@ -305,27 +260,23 @@ pack_string(DCPackData &pack_data, const string &value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::pack_default_value
// Access: Public, Virtual
// Description: Packs the arrayParameter's specified default value (or a
// sensible default if no value is specified) into the
// stream. Returns true if the default value is packed,
// false if the arrayParameter doesn't know how to pack its
// default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the arrayParameter's specified default value (or a sensible default
* if no value is specified) into the stream. Returns true if the default
* value is packed, false if the arrayParameter doesn't know how to pack its
* default value.
*/
bool DCArrayParameter::
pack_default_value(DCPackData &pack_data, bool &pack_error) const {
// We only want to call up if the DCField can pack the value
// immediately--we don't trust the DCField to generate the default
// value (since it doesn't know how large the minimum length array
// is).
// We only want to call up if the DCField can pack the value immediately--we
// don't trust the DCField to generate the default value (since it doesn't
// know how large the minimum length array is).
if (_has_default_value && !_default_value_stale) {
return DCField::pack_default_value(pack_data, pack_error);
}
// If a default value is not specified for a variable-length array,
// the default is the minimum array.
// If a default value is not specified for a variable-length array, the
// default is the minimum array.
unsigned int minimum_length = 0;
if (!_array_size_range.is_empty()) {
minimum_length = _array_size_range.get_min(0);
@ -347,17 +298,13 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::unpack_string
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCArrayParameter::
unpack_string(const char *data, size_t length, size_t &p, string &value,
bool &pack_error, bool &range_error) const {
// We can only unpack a string if the array element type is char or
// int8.
// We can only unpack a string if the array element type is char or int8.
DCSimpleParameter *simple_type = _element_type->as_simple_parameter();
if (simple_type == (DCSimpleParameter *)NULL) {
pack_error = true;
@ -390,47 +337,38 @@ unpack_string(const char *data, size_t length, size_t &p, string &value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCArrayParameter::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_array_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::do_check_match_simple_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// simple parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated simple parameter, false
* otherwise.
*/
bool DCArrayParameter::
do_check_match_simple_parameter(const DCSimpleParameter *other) const {
return ((const DCPackerInterface *)other)->do_check_match_array_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::do_check_match_class_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// class parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated class parameter, false
* otherwise.
*/
bool DCArrayParameter::
do_check_match_class_parameter(const DCClassParameter *other) const {
return ((const DCPackerInterface *)other)->do_check_match_array_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCArrayParameter::do_check_match_array_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// array parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated array parameter, false
* otherwise.
*/
bool DCArrayParameter::
do_check_match_array_parameter(const DCArrayParameter *other) const {
if (_array_size != other->_array_size) {

View File

@ -1,16 +1,15 @@
// Filename: dcArrayParameter.h
// Created by: drose (17Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcArrayParameter.h
* @author drose
* @date 2004-06-17
*/
#ifndef DCARRAYPARAMETER_H
#define DCARRAYPARAMETER_H
@ -19,16 +18,14 @@
#include "dcParameter.h"
#include "dcNumericRange.h"
////////////////////////////////////////////////////////////////////
// Class : DCArrayParameter
// Description : This represents an array of some other kind of
// object, meaning this parameter type accepts an
// arbitrary (or possibly fixed) number of nested
// fields, all of which are of the same type.
////////////////////////////////////////////////////////////////////
/**
* This represents an array of some other kind of object, meaning this
* parameter type accepts an arbitrary (or possibly fixed) number of nested
* fields, all of which are of the same type.
*/
class EXPCL_DIRECT DCArrayParameter : public DCParameter {
public:
DCArrayParameter(DCParameter *element_type,
DCArrayParameter(DCParameter *element_type,
const DCUnsignedIntRange &size = DCUnsignedIntRange());
DCArrayParameter(const DCArrayParameter &copy);
virtual ~DCArrayParameter();
@ -49,13 +46,13 @@ public:
virtual DCPackerInterface *get_nested_field(int n) const;
virtual bool validate_num_nested_fields(int num_nested_fields) const;
virtual void output_instance(ostream &out, bool brief, const string &prename,
virtual void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
virtual void generate_hash(HashGenerator &hashgen) const;
virtual void pack_string(DCPackData &pack_data, const string &value,
bool &pack_error, bool &range_error) const;
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
virtual void unpack_string(const char *data, size_t length, size_t &p,
virtual void unpack_string(const char *data, size_t length, size_t &p,
string &value, bool &pack_error, bool &range_error) const;
protected:

View File

@ -1,14 +1,12 @@
// Filename: dcAtomicField.I
// Created by: drose (15Aug06)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcAtomicField.I
* @author drose
* @date 2006-08-15
*/

View File

@ -1,16 +1,15 @@
// Filename: dcAtomicField.cxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcAtomicField.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcAtomicField.h"
#include "hashGenerator.h"
@ -20,139 +19,110 @@
#include <math.h>
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCAtomicField::
DCAtomicField(const string &name, DCClass *dclass,
bool bogus_field) :
bool bogus_field) :
DCField(name, dclass)
{
_bogus_field = bogus_field;
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCAtomicField::
~DCAtomicField() {
Elements::iterator ei;
Elements::iterator ei;
for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
delete (*ei);
}
_elements.clear();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::as_atomic_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to an atomic
// field pointer, if this is in fact an atomic field;
// otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to an atomic field pointer, if
* this is in fact an atomic field; otherwise, returns NULL.
*/
DCAtomicField *DCAtomicField::
as_atomic_field() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::as_atomic_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to an atomic
// field pointer, if this is in fact an atomic field;
// otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to an atomic field pointer, if
* this is in fact an atomic field; otherwise, returns NULL.
*/
const DCAtomicField *DCAtomicField::
as_atomic_field() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_num_elements
// Access: Published
// Description: Returns the number of elements (parameters) of the
// atomic field.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of elements (parameters) of the atomic field.
*/
int DCAtomicField::
get_num_elements() const {
return _elements.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_element
// Access: Published
// Description: Returns the parameter object describing the
// nth element.
////////////////////////////////////////////////////////////////////
/**
* Returns the parameter object describing the nth element.
*/
DCParameter *DCAtomicField::
get_element(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), NULL);
return _elements[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_element_default
// Access: Published
// Description: Returns the pre-formatted default value associated
// with the nth element of the field. This is only
// valid if has_element_default() returns true, in which
// case this string represents the bytes that should be
// assigned to the field as a default value.
//
// If the element is an array-type element, the returned
// value will include the two-byte length preceding the
// array data.
//
// This is deprecated; use get_element() instead.
////////////////////////////////////////////////////////////////////
/**
* Returns the pre-formatted default value associated with the nth element of
* the field. This is only valid if has_element_default() returns true, in
* which case this string represents the bytes that should be assigned to the
* field as a default value.
*
* If the element is an array-type element, the returned value will include
* the two-byte length preceding the array data.
*
* This is deprecated; use get_element() instead.
*/
string DCAtomicField::
get_element_default(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), string());
return _elements[n]->get_default_value();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::has_element_default
// Access: Published
// Description: Returns true if the nth element of the field has a
// default value specified, false otherwise.
//
// This is deprecated; use get_element() instead.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the nth element of the field has a default value specified,
* false otherwise.
*
* This is deprecated; use get_element() instead.
*/
bool DCAtomicField::
has_element_default(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), false);
return _elements[n]->has_default_value();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_element_name
// Access: Published
// Description: Returns the name of the nth element of the field.
// This name is strictly for documentary purposes; it
// does not generally affect operation. If a name is
// not specified, this will be the empty string.
//
// This method is deprecated; use
// get_element()->get_name() instead.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of the nth element of the field. This name is strictly
* for documentary purposes; it does not generally affect operation. If a
* name is not specified, this will be the empty string.
*
* This method is deprecated; use get_element()->get_name() instead.
*/
string DCAtomicField::
get_element_name(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), string());
return _elements[n]->get_name();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_element_type
// Access: Published
// Description: Returns the numeric type of the nth element of the
// field. This method is deprecated; use
// get_element() instead.
////////////////////////////////////////////////////////////////////
/**
* Returns the numeric type of the nth element of the field. This method is
* deprecated; use get_element() instead.
*/
DCSubatomicType DCAtomicField::
get_element_type(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), ST_invalid);
@ -161,18 +131,14 @@ get_element_type(int n) const {
return simple_parameter->get_type();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_element_divisor
// Access: Published
// Description: Returns the divisor associated with the nth element
// of the field. This implements an implicit
// fixed-point system; floating-point values are to be
// multiplied by this value before encoding into a
// packet, and divided by this number after decoding.
//
// This method is deprecated; use
// get_element()->get_divisor() instead.
////////////////////////////////////////////////////////////////////
/**
* Returns the divisor associated with the nth element of the field. This
* implements an implicit fixed-point system; floating-point values are to be
* multiplied by this value before encoding into a packet, and divided by this
* number after decoding.
*
* This method is deprecated; use get_element()->get_divisor() instead.
*/
int DCAtomicField::
get_element_divisor(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), 1);
@ -181,11 +147,9 @@ get_element_divisor(int n) const {
return simple_parameter->get_divisor();
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCAtomicField::
output(ostream &out, bool brief) const {
out << _name << "(";
@ -205,12 +169,10 @@ output(ostream &out, bool brief) const {
output_keywords(out);
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::write
// Access: Public, Virtual
// Description: Generates a parseable description of the object to
// the indicated output stream.
////////////////////////////////////////////////////////////////////
/**
* Generates a parseable description of the object to the indicated output
* stream.
*/
void DCAtomicField::
write(ostream &out, bool brief, int indent_level) const {
indent(out, indent_level);
@ -222,12 +184,9 @@ write(ostream &out, bool brief, int indent_level) const {
out << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this field into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this field into the hash.
*/
void DCAtomicField::
generate_hash(HashGenerator &hashgen) const {
DCField::generate_hash(hashgen);
@ -241,28 +200,22 @@ generate_hash(HashGenerator &hashgen) const {
DCKeywordList::generate_hash(hashgen);
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCAtomicField::
get_nested_field(int n) const {
nassertr(n >= 0 && n < (int)_elements.size(), NULL);
return _elements[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::add_element
// Access: Public
// Description: Adds a new element (parameter) to the field.
// Normally this is called only during parsing. The
// DCAtomicField object becomes the owner of the new
// pointer and will delete it upon destruction.
////////////////////////////////////////////////////////////////////
/**
* Adds a new element (parameter) to the field. Normally this is called only
* during parsing. The DCAtomicField object becomes the owner of the new
* pointer and will delete it upon destruction.
*/
void DCAtomicField::
add_element(DCParameter *element) {
_elements.push_back(element);
@ -285,25 +238,20 @@ add_element(DCParameter *element) {
_default_value_stale = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCAtomicField::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_atomic_field(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::do_check_match_atomic_field
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// atomic field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated atomic field, false
* otherwise.
*/
bool DCAtomicField::
do_check_match_atomic_field(const DCAtomicField *other) const {
if (_elements.size() != other->_elements.size()) {
@ -318,11 +266,9 @@ do_check_match_atomic_field(const DCAtomicField *other) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCAtomicField::output_element
// Access: Private
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCAtomicField::
output_element(ostream &out, bool brief, DCParameter *element) const {
element->output(out, brief);

View File

@ -1,16 +1,15 @@
// Filename: dcAtomicField.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcAtomicField.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCATOMICFIELD_H
#define DCATOMICFIELD_H
@ -20,17 +19,14 @@
#include "dcSubatomicType.h"
#include "dcParameter.h"
// Must use math.h instead of cmath.h so this can compile outside of
// Panda.
// Must use math.h instead of cmath.h so this can compile outside of Panda.
#include <math.h>
////////////////////////////////////////////////////////////////////
// Class : DCAtomicField
// Description : A single atomic field of a Distributed Class, as read
// from a .dc file. This defines an interface to the
// Distributed Class, and is always implemented as a
// remote procedure method.
////////////////////////////////////////////////////////////////////
/**
* A single atomic field of a Distributed Class, as read from a .dc file.
* This defines an interface to the Distributed Class, and is always
* implemented as a remote procedure method.
*/
class EXPCL_DIRECT DCAtomicField : public DCField {
public:
DCAtomicField(const string &name, DCClass *dclass, bool bogus_field);

View File

@ -1,87 +1,68 @@
// Filename: dcClass.I
// Created by: drose (15Sep04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcClass.I
* @author drose
* @date 2004-09-15
*/
////////////////////////////////////////////////////////////////////
// Function: DCClass::get_dc_file
// Access: Published
// Description: Returns the DCFile object that contains the class.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCFile object that contains the class.
*/
INLINE DCFile *DCClass::
get_dc_file() const {
return _dc_file;
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::get_name
// Access: Published
// Description: Returns the name of this class.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of this class.
*/
INLINE const string &DCClass::
get_name() const {
return _name;
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::get_number
// Access: Published
// Description: Returns a unique index number associated with this
// class. This is defined implicitly when the .dc
// file(s) are read.
////////////////////////////////////////////////////////////////////
/**
* Returns a unique index number associated with this class. This is defined
* implicitly when the .dc file(s) are read.
*/
INLINE int DCClass::
get_number() const {
return _number;
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::is_struct
// Access: Published
// Description: Returns true if the class has been identified with
// the "struct" keyword in the dc file, false if it was
// declared with "dclass".
////////////////////////////////////////////////////////////////////
/**
* Returns true if the class has been identified with the "struct" keyword in
* the dc file, false if it was declared with "dclass".
*/
INLINE bool DCClass::
is_struct() const {
return _is_struct;
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::is_bogus_class
// Access: Published
// Description: Returns true if the class has been flagged as a bogus
// class. This is set for classes that are generated by
// the parser as placeholder for missing classes, as
// when reading a partial file; it should not occur in a
// normal valid dc file.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the class has been flagged as a bogus class. This is set
* for classes that are generated by the parser as placeholder for missing
* classes, as when reading a partial file; it should not occur in a normal
* valid dc file.
*/
INLINE bool DCClass::
is_bogus_class() const {
return _bogus_class;
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::start_generate
// Access: Published
// Description: Starts the PStats timer going on the "generate" task,
// that is, marks the beginning of the process of
// generating a new object, for the purposes of timing
// this process.
//
// This should balance with a corresponding call to
// stop_generate().
////////////////////////////////////////////////////////////////////
/**
* Starts the PStats timer going on the "generate" task, that is, marks the
* beginning of the process of generating a new object, for the purposes of
* timing this process.
*
* This should balance with a corresponding call to stop_generate().
*/
INLINE void DCClass::
start_generate() {
#ifdef WITHIN_PANDA
@ -89,13 +70,10 @@ start_generate() {
#endif
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::stop_generate
// Access: Published
// Description: Stops the PStats timer on the "generate" task.
// This should balance with a preceding call to
// start_generate().
////////////////////////////////////////////////////////////////////
/**
* Stops the PStats timer on the "generate" task. This should balance with a
* preceding call to start_generate().
*/
INLINE void DCClass::
stop_generate() {
#ifdef WITHIN_PANDA

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,15 @@
// Filename: dcClass.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcClass.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCCLASS_H
#define DCCLASS_H
@ -39,14 +38,12 @@ static const bool dc_sort_inheritance_by_file = false;
class HashGenerator;
class DCParameter;
////////////////////////////////////////////////////////////////////
// Class : DCClass
// Description : Defines a particular DistributedClass as read from an
// input .dc file.
////////////////////////////////////////////////////////////////////
/**
* Defines a particular DistributedClass as read from an input .dc file.
*/
class EXPCL_DIRECT DCClass : public DCDeclaration {
public:
DCClass(DCFile *dc_file, const string &name,
DCClass(DCFile *dc_file, const string &name,
bool is_struct, bool bogus_class);
~DCClass();
@ -61,7 +58,7 @@ PUBLISHED:
int get_num_parents() const;
DCClass *get_parent(int n) const;
bool has_constructor() const;
DCField *get_constructor() const;
@ -82,7 +79,7 @@ PUBLISHED:
INLINE void stop_generate();
virtual void output(ostream &out) const;
#ifdef HAVE_PYTHON
bool has_class_def() const;
void set_class_def(PyObject *class_def);
@ -97,40 +94,40 @@ PUBLISHED:
void receive_update_all_required(PyObject *distobj, DatagramIterator &di) const;
void receive_update_other(PyObject *distobj, DatagramIterator &di) const;
void direct_update(PyObject *distobj, const string &field_name,
void direct_update(PyObject *distobj, const string &field_name,
const string &value_blob);
void direct_update(PyObject *distobj, const string &field_name,
void direct_update(PyObject *distobj, const string &field_name,
const Datagram &datagram);
bool pack_required_field(Datagram &datagram, PyObject *distobj,
bool pack_required_field(Datagram &datagram, PyObject *distobj,
const DCField *field) const;
bool pack_required_field(DCPacker &packer, PyObject *distobj,
bool pack_required_field(DCPacker &packer, PyObject *distobj,
const DCField *field) const;
Datagram client_format_update(const string &field_name,
DOID_TYPE do_id, PyObject *args) const;
Datagram ai_format_update(const string &field_name, DOID_TYPE do_id,
Datagram ai_format_update(const string &field_name, DOID_TYPE do_id,
CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const;
Datagram ai_format_update_msg_type(const string &field_name, DOID_TYPE do_id,
Datagram ai_format_update_msg_type(const string &field_name, DOID_TYPE do_id,
CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const;
Datagram ai_format_generate(PyObject *distobj, DOID_TYPE do_id, ZONEID_TYPE parent_id, ZONEID_TYPE zone_id,
CHANNEL_TYPE district_channel_id, CHANNEL_TYPE from_channel_id,
PyObject *optional_fields) const;
Datagram client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id,
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
#endif
public:
virtual void output(ostream &out, bool brief) const;
virtual void write(ostream &out, bool brief, int indent_level) const;
void output_instance(ostream &out, bool brief, const string &prename,
void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
void generate_hash(HashGenerator &hashgen) const;
void clear_inherited_fields();

View File

@ -1,27 +1,24 @@
// Filename: dcClassParameter.cxx
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcClassParameter.cxx
* @author drose
* @date 2004-06-18
*/
#include "dcClassParameter.h"
#include "dcClass.h"
#include "dcArrayParameter.h"
#include "hashGenerator.h"
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClassParameter::
DCClassParameter(const DCClass *dclass) :
_dclass(dclass)
@ -48,9 +45,8 @@ DCClassParameter(const DCClass *dclass) :
}
_num_nested_fields = _nested_fields.size();
// If all of the nested fields have a fixed byte size, then so does
// the class (and its byte size is the sum of all of the nested
// fields).
// If all of the nested fields have a fixed byte size, then so does the
// class (and its byte size is the sum of all of the nested fields).
_has_fixed_byte_size = true;
_fixed_byte_size = 0;
_has_fixed_structure = true;
@ -64,11 +60,9 @@ DCClassParameter(const DCClass *dclass) :
}
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClassParameter::
DCClassParameter(const DCClassParameter &copy) :
DCParameter(copy),
@ -77,80 +71,64 @@ DCClassParameter(const DCClassParameter &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClassParameter *DCClassParameter::
as_class_parameter() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCClassParameter *DCClassParameter::
as_class_parameter() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::make_copy
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCClassParameter::
make_copy() const {
return new DCClassParameter(*this);
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::is_valid
// Access: Published, Virtual
// Description: Returns false if the type is an invalid type
// (e.g. declared from an undefined typedef), true if
// it is valid.
////////////////////////////////////////////////////////////////////
/**
* Returns false if the type is an invalid type (e.g. declared from an
* undefined typedef), true if it is valid.
*/
bool DCClassParameter::
is_valid() const {
return !_dclass->is_bogus_class();
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::get_class
// Access: Published
// Description: Returns the class object this parameter represents.
////////////////////////////////////////////////////////////////////
/**
* Returns the class object this parameter represents.
*/
const DCClass *DCClassParameter::
get_class() const {
return _dclass;
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCClassParameter::
get_nested_field(int n) const {
nassertr(n >= 0 && n < (int)_nested_fields.size(), NULL);
return _nested_fields[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::output_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCClassParameter::
output_instance(ostream &out, bool brief, const string &prename,
output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const {
if (get_typedef() != (DCTypedef *)NULL) {
output_typedef_name(out, brief, prename, name, postname);
@ -160,37 +138,29 @@ output_instance(ostream &out, bool brief, const string &prename,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this type into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this type into the hash.
*/
void DCClassParameter::
generate_hash(HashGenerator &hashgen) const {
DCParameter::generate_hash(hashgen);
_dclass->generate_hash(hashgen);
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCClassParameter::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_class_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::do_check_match_class_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// class parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated class parameter, false
* otherwise.
*/
bool DCClassParameter::
do_check_match_class_parameter(const DCClassParameter *other) const {
if (_nested_fields.size() != other->_nested_fields.size()) {
@ -205,17 +175,15 @@ do_check_match_class_parameter(const DCClassParameter *other) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCClassParameter::do_check_match_array_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// array parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated array parameter, false
* otherwise.
*/
bool DCClassParameter::
do_check_match_array_parameter(const DCArrayParameter *other) const {
if ((int)_nested_fields.size() != other->get_array_size()) {
// We can only match a fixed-size array whose size happens to
// exactly match our number of fields.
// We can only match a fixed-size array whose size happens to exactly
// match our number of fields.
return false;
}

View File

@ -1,16 +1,15 @@
// Filename: dcClassParameter.h
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcClassParameter.h
* @author drose
* @date 2004-06-18
*/
#ifndef DCCLASSPARAMETER_H
#define DCCLASSPARAMETER_H
@ -20,12 +19,10 @@
class DCClass;
////////////////////////////////////////////////////////////////////
// Class : DCClassParameter
// Description : This represents a class (or struct) object used as a
// parameter itself. This means that all the fields of
// the class get packed into the message.
////////////////////////////////////////////////////////////////////
/**
* This represents a class (or struct) object used as a parameter itself.
* This means that all the fields of the class get packed into the message.
*/
class EXPCL_DIRECT DCClassParameter : public DCParameter {
public:
DCClassParameter(const DCClass *dclass);
@ -42,7 +39,7 @@ PUBLISHED:
public:
virtual DCPackerInterface *get_nested_field(int n) const;
virtual void output_instance(ostream &out, bool brief, const string &prename,
virtual void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
virtual void generate_hash(HashGenerator &hashgen) const;

View File

@ -1,86 +1,69 @@
// Filename: dcDeclaration.cxx
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcDeclaration.cxx
* @author drose
* @date 2004-06-18
*/
#include "dcDeclaration.h"
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCDeclaration::
~DCDeclaration() {
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::as_class
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClass *DCDeclaration::
as_class() {
return (DCClass *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::as_class
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCClass *DCDeclaration::
as_class() const {
return (DCClass *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::as_switch
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch *DCDeclaration::
as_switch() {
return (DCSwitch *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::as_switch
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSwitch *DCDeclaration::
as_switch() const {
return (DCSwitch *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::output
// Access: Published, Virtual
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
void DCDeclaration::
output(ostream &out) const {
output(out, true);
}
////////////////////////////////////////////////////////////////////
// Function: DCDeclaration::
// Access: Published
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
void DCDeclaration::
write(ostream &out, int indent_level) const {
write(out, false, indent_level);

View File

@ -1,16 +1,15 @@
// Filename: dcDeclaration.h
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcDeclaration.h
* @author drose
* @date 2004-06-18
*/
#ifndef DCDECLARATION_H
#define DCDECLARATION_H
@ -20,16 +19,13 @@
class DCClass;
class DCSwitch;
////////////////////////////////////////////////////////////////////
// Class : DCDeclaration
// Description : This is a common interface for a declaration in a DC
// file. Currently, this is either a class or a typedef
// declaration (import declarations are still collected
// together at the top, and don't inherit from this
// object). Its only purpose is so that classes and
// typedefs can be stored in one list together so they
// can be ordered correctly on output.
////////////////////////////////////////////////////////////////////
/**
* This is a common interface for a declaration in a DC file. Currently, this
* is either a class or a typedef declaration (import declarations are still
* collected together at the top, and don't inherit from this object). Its
* only purpose is so that classes and typedefs can be stored in one list
* together so they can be ordered correctly on output.
*/
class EXPCL_DIRECT DCDeclaration {
public:
virtual ~DCDeclaration();
@ -54,4 +50,3 @@ INLINE ostream &operator << (ostream &out, const DCDeclaration &decl) {
}
#endif

View File

@ -1,61 +1,47 @@
// Filename: dcField.I
// Created by: drose (10Jan06)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcField.I
* @author drose
* @date 2006-01-10
*/
////////////////////////////////////////////////////////////////////
// Function: DCField::get_number
// Access: Published
// Description: Returns a unique index number associated with this
// field. This is defined implicitly when the .dc
// file(s) are read.
////////////////////////////////////////////////////////////////////
/**
* Returns a unique index number associated with this field. This is defined
* implicitly when the .dc file(s) are read.
*/
INLINE int DCField::
get_number() const {
return _number;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::get_class
// Access: Published
// Description: Returns the DCClass pointer for the class that
// contains this field.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCClass pointer for the class that contains this field.
*/
INLINE DCClass *DCField::
get_class() const {
return _dclass;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::has_default_value
// Access: Published
// Description: Returns true if a default value has been explicitly
// established for this field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if a default value has been explicitly established for this
* field, false otherwise.
*/
INLINE bool DCField::
has_default_value() const {
return _has_default_value;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::get_default_value
// Access: Published
// Description: Returns the default value for this field. If a
// default value has been explicitly set
// (e.g. has_default_value() returns true), returns that
// value; otherwise, returns an implicit default for the
// field.
////////////////////////////////////////////////////////////////////
/**
* Returns the default value for this field. If a default value has been
* explicitly set (e.g. has_default_value() returns true), returns that
* value; otherwise, returns an implicit default for the field.
*/
INLINE const string &DCField::
get_default_value() const {
if (_default_value_stale) {
@ -64,170 +50,127 @@ get_default_value() const {
return _default_value;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_bogus_field
// Access: Published
// Description: Returns true if the field has been flagged as a bogus
// field. This is set for fields that are generated by
// the parser as placeholder for missing fields, as
// when reading a partial file; it should not occur in a
// normal valid dc file.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the field has been flagged as a bogus field. This is set
* for fields that are generated by the parser as placeholder for missing
* fields, as when reading a partial file; it should not occur in a normal
* valid dc file.
*/
INLINE bool DCField::
is_bogus_field() const {
return _bogus_field;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_required
// Access: Published
// Description: Returns true if the "required" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "required" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_required() const {
return has_keyword("required");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_broadcast
// Access: Published
// Description: Returns true if the "broadcast" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "broadcast" flag is set for this field, false
* otherwise.
*/
INLINE bool DCField::
is_broadcast() const {
return has_keyword("broadcast");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_ram
// Access: Published
// Description: Returns true if the "ram" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "ram" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_ram() const {
return has_keyword("ram");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_db
// Access: Published
// Description: Returns true if the "db" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "db" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_db() const {
return has_keyword("db");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_clsend
// Access: Published
// Description: Returns true if the "clsend" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "clsend" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_clsend() const {
return has_keyword("clsend");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_clrecv
// Access: Published
// Description: Returns true if the "clrecv" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "clrecv" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_clrecv() const {
return has_keyword("clrecv");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_ownsend
// Access: Published
// Description: Returns true if the "ownsend" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "ownsend" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_ownsend() const {
return has_keyword("ownsend");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_ownrecv
// Access: Published
// Description: Returns true if the "ownrecv" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "ownrecv" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_ownrecv() const {
return has_keyword("ownrecv");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_airecv
// Access: Published
// Description: Returns true if the "airecv" flag is set for this
// field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the "airecv" flag is set for this field, false otherwise.
*/
INLINE bool DCField::
is_airecv() const {
return has_keyword("airecv");
}
////////////////////////////////////////////////////////////////////
// Function: DCField::output
// Access: Published
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
INLINE void DCField::
output(ostream &out) const {
output(out, true);
}
////////////////////////////////////////////////////////////////////
// Function: DCField::
// Access: Published
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
INLINE void DCField::
write(ostream &out, int indent_level) const {
write(out, false, indent_level);
}
////////////////////////////////////////////////////////////////////
// Function: DCField::set_number
// Access: Public
// Description: Assigns the unique number to this field. This is
// normally called only by the DCClass interface as the
// field is added.
////////////////////////////////////////////////////////////////////
/**
* Assigns the unique number to this field. This is normally called only by
* the DCClass interface as the field is added.
*/
INLINE void DCField::
set_number(int number) {
_number = number;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::set_class
// Access: Public
// Description: Assigns the class pointer to this field. This is
// normally called only by the DCClass interface as the
// field is added.
////////////////////////////////////////////////////////////////////
/**
* Assigns the class pointer to this field. This is normally called only by
* the DCClass interface as the field is added.
*/
INLINE void DCField::
set_class(DCClass *dclass) {
_dclass = dclass;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::set_default_value
// Access: Public
// Description: Establishes a default value for this field.
////////////////////////////////////////////////////////////////////
/**
* Establishes a default value for this field.
*/
INLINE void DCField::
set_default_value(const string &default_value) {
_default_value = default_value;

View File

@ -1,16 +1,15 @@
// Filename: dcField.cxx
// Created by: drose (11Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcField.cxx
* @author drose
* @date 2000-10-11
*/
#include "dcField.h"
#include "dcFile.h"
@ -27,13 +26,11 @@
#include "pStatTimer.h"
#endif
////////////////////////////////////////////////////////////////////
// Function: DCField::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCField::
DCField() :
DCField() :
_dclass(NULL)
#ifdef WITHIN_PANDA
,
@ -55,13 +52,11 @@ DCField() :
_has_fixed_structure = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCField::
DCField(const string &name, DCClass *dclass) :
DCField(const string &name, DCClass *dclass) :
DCPackerInterface(name),
_dclass(dclass)
#ifdef WITHIN_PANDA
@ -84,110 +79,86 @@ DCField(const string &name, DCClass *dclass) :
_has_fixed_structure = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCField::
~DCField() {
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_field
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCField *DCField::
as_field() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_field
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCField *DCField::
as_field() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_atomic_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to an atomic
// field pointer, if this is in fact an atomic field;
// otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to an atomic field pointer, if
* this is in fact an atomic field; otherwise, returns NULL.
*/
DCAtomicField *DCField::
as_atomic_field() {
return (DCAtomicField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_atomic_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to an atomic
// field pointer, if this is in fact an atomic field;
// otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to an atomic field pointer, if
* this is in fact an atomic field; otherwise, returns NULL.
*/
const DCAtomicField *DCField::
as_atomic_field() const {
return (DCAtomicField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_molecular_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to a
// molecular field pointer, if this is in fact a
// molecular field; otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to a molecular field pointer, if
* this is in fact a molecular field; otherwise, returns NULL.
*/
DCMolecularField *DCField::
as_molecular_field() {
return (DCMolecularField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_molecular_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to a
// molecular field pointer, if this is in fact a
// molecular field; otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to a molecular field pointer, if
* this is in fact a molecular field; otherwise, returns NULL.
*/
const DCMolecularField *DCField::
as_molecular_field() const {
return (DCMolecularField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCField::
as_parameter() {
return (DCParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::as_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCParameter *DCField::
as_parameter() const {
return (DCParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::format_data
// Access: Published
// Description: Given a blob that represents the packed data for this
// field, returns a string formatting it for human
// consumption. Returns empty string if there is an error.
////////////////////////////////////////////////////////////////////
/**
* Given a blob that represents the packed data for this field, returns a
* string formatting it for human consumption. Returns empty string if there
* is an error.
*/
string DCField::
format_data(const string &packed_data, bool show_field_names) {
DCPacker packer;
@ -200,15 +171,11 @@ format_data(const string &packed_data, bool show_field_names) {
return result;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::parse_string
// Access: Published
// Description: Given a human-formatted string (for instance, as
// returned by format_data(), above) that represents the
// value of this field, parse the string and return the
// corresponding packed data. Returns empty string if
// there is an error.
////////////////////////////////////////////////////////////////////
/**
* Given a human-formatted string (for instance, as returned by format_data(),
* above) that represents the value of this field, parse the string and return
* the corresponding packed data. Returns empty string if there is an error.
*/
string DCField::
parse_string(const string &formatted_string) {
DCPacker packer;
@ -225,14 +192,11 @@ parse_string(const string &formatted_string) {
return packer.get_string();
}
////////////////////////////////////////////////////////////////////
// Function: DCField::validate_ranges
// Access: Published
// Description: Verifies that all of the packed values in the field
// data are within the specified ranges and that there
// are no extra bytes on the end of the record. Returns
// true if all fields are valid, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Verifies that all of the packed values in the field data are within the
* specified ranges and that there are no extra bytes on the end of the
* record. Returns true if all fields are valid, false otherwise.
*/
bool DCField::
validate_ranges(const string &packed_data) const {
DCPacker packer;
@ -247,16 +211,12 @@ validate_ranges(const string &packed_data) const {
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::pack_args
// Access: Published
// Description: Packs the Python arguments from the indicated tuple
// into the packer. Returns true on success, false on
// failure.
//
// It is assumed that the packer is currently positioned
// on this field.
////////////////////////////////////////////////////////////////////
/**
* Packs the Python arguments from the indicated tuple into the packer.
* Returns true on success, false on failure.
*
* It is assumed that the packer is currently positioned on this field.
*/
bool DCField::
pack_args(DCPacker &packer, PyObject *sequence) const {
nassertr(!packer.had_error(), false);
@ -289,8 +249,7 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
}
} else {
// If it's a molecular or atomic field, the value should be a
// sequence.
// If it's a molecular or atomic field, the value should be a sequence.
PyObject *tuple = PySequence_Tuple(sequence);
if (tuple == (PyObject *)NULL) {
strm << "Value for " << get_name() << " not a sequence: " \
@ -307,7 +266,7 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
<< get_pystr(sequence);
exc_type = PyExc_ValueError;
}
Py_DECREF(tuple);
}
}
@ -320,16 +279,12 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::unpack_args
// Access: Published
// Description: Unpacks the values from the packer, beginning at
// the current point in the unpack_buffer, into a Python
// tuple and returns the tuple.
//
// It is assumed that the packer is currently positioned
// on this field.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the values from the packer, beginning at the current point in the
* unpack_buffer, into a Python tuple and returns the tuple.
*
* It is assumed that the packer is currently positioned on this field.
*/
PyObject *DCField::
unpack_args(DCPacker &packer) const {
nassertr(!packer.had_error(), NULL);
@ -364,11 +319,11 @@ unpack_args(DCPacker &packer) const {
exc_type = PyExc_RuntimeError;
} else {
strm << "Value outside specified range when unpacking field "
strm << "Value outside specified range when unpacking field "
<< get_name() << ": " << get_pystr(object);
exc_type = PyExc_ValueError;
}
string message = strm.str();
PyErr_SetString(exc_type, message.c_str());
}
@ -379,18 +334,14 @@ unpack_args(DCPacker &packer) const {
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::receive_update
// Access: Published
// Description: Extracts the update message out of the datagram and
// applies it to the indicated object by calling the
// appropriate method.
////////////////////////////////////////////////////////////////////
/**
* Extracts the update message out of the datagram and applies it to the
* indicated object by calling the appropriate method.
*/
void DCField::
receive_update(DCPacker &packer, PyObject *distobj) const {
if (as_parameter() != (DCParameter *)NULL) {
// If it's a parameter-type field, just store a new value on the
// object.
// If it's a parameter-type field, just store a new value on the object.
PyObject *value = unpack_args(packer);
if (value != (PyObject *)NULL) {
PyObject_SetAttrString(distobj, (char *)_name.c_str(), value);
@ -402,9 +353,8 @@ receive_update(DCPacker &packer, PyObject *distobj) const {
// corresponding method.
if (!PyObject_HasAttrString(distobj, (char *)_name.c_str())) {
// If there's no Python method to receive this message, don't
// bother unpacking it to a Python tuple--just skip past the
// message.
// If there's no Python method to receive this message, don't bother
// unpacking it to a Python tuple--just skip past the message.
packer.unpack_skip();
} else {
@ -415,7 +365,7 @@ receive_update(DCPacker &packer, PyObject *distobj) const {
if (args != (PyObject *)NULL) {
PyObject *func = PyObject_GetAttrString(distobj, (char *)_name.c_str());
nassertv(func != (PyObject *)NULL);
PyObject *result;
{
#ifdef WITHIN_PANDA
@ -433,13 +383,10 @@ receive_update(DCPacker &packer, PyObject *distobj) const {
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::client_format_update
// Access: Published
// Description: Generates a datagram containing the message necessary
// to send an update for the indicated distributed
// object from the client.
////////////////////////////////////////////////////////////////////
/**
* Generates a datagram containing the message necessary to send an update for
* the indicated distributed object from the client.
*/
Datagram DCField::
client_format_update(DOID_TYPE do_id, PyObject *args) const {
DCPacker packer;
@ -459,13 +406,10 @@ client_format_update(DOID_TYPE do_id, PyObject *args) const {
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::ai_format_update
// Access: Published
// Description: Generates a datagram containing the message necessary
// to send an update for the indicated distributed
// object from the AI.
////////////////////////////////////////////////////////////////////
/**
* Generates a datagram containing the message necessary to send an update for
* the indicated distributed object from the AI.
*/
Datagram DCField::
ai_format_update(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const {
DCPacker packer;
@ -488,14 +432,10 @@ ai_format_update(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyOb
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::ai_format_update_msg_type
// Access: Published
// Description: Generates a datagram containing the message necessary
// to send an update, with the msg type,
// for the indicated distributed
// object from the AI.
////////////////////////////////////////////////////////////////////
/**
* Generates a datagram containing the message necessary to send an update,
* with the msg type, for the indicated distributed object from the AI.
*/
Datagram DCField::
ai_format_update_msg_type(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const {
DCPacker packer;
@ -518,41 +458,33 @@ ai_format_update_msg_type(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from
#endif // HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this field into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this field into the hash.
*/
void DCField::
generate_hash(HashGenerator &hashgen) const {
// It shouldn't be necessary to explicitly add _number to the
// hash--this is computed based on the relative position of this
// field with the other fields, so adding it explicitly will be
// redundant. However, the field name is significant.
// It shouldn't be necessary to explicitly add _number to the hash--this is
// computed based on the relative position of this field with the other
// fields, so adding it explicitly will be redundant. However, the field
// name is significant.
hashgen.add_string(_name);
// Actually, we add _number anyway, since we need to ensure the hash
// code comes out different in the dc_multiple_inheritance case.
// Actually, we add _number anyway, since we need to ensure the hash code
// comes out different in the dc_multiple_inheritance case.
if (dc_multiple_inheritance) {
hashgen.add_int(_number);
}
}
////////////////////////////////////////////////////////////////////
// Function: DCField::pack_default_value
// Access: Public, Virtual
// Description: Packs the field's specified default value (or a
// sensible default if no value is specified) into the
// stream. Returns true if the default value is packed,
// false if the field doesn't know how to pack its
// default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the field's specified default value (or a sensible default if no
* value is specified) into the stream. Returns true if the default value is
* packed, false if the field doesn't know how to pack its default value.
*/
bool DCField::
pack_default_value(DCPackData &pack_data, bool &) const {
// The default behavior is to pack the default value if we got it;
// otherwise, to return false and let the packer visit our nested
// elements.
// otherwise, to return false and let the packer visit our nested elements.
if (!_default_value_stale) {
pack_data.append_data(_default_value.data(), _default_value.length());
return true;
@ -561,11 +493,9 @@ pack_default_value(DCPackData &pack_data, bool &) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::set_name
// Access: Public, Virtual
// Description: Sets the name of this field.
////////////////////////////////////////////////////////////////////
/**
* Sets the name of this field.
*/
void DCField::
set_name(const string &name) {
DCPackerInterface::set_name(name);
@ -575,12 +505,9 @@ set_name(const string &name) {
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::get_pystr
// Access: Public, Static
// Description: Returns the string representation of the indicated
// Python object.
////////////////////////////////////////////////////////////////////
/**
* Returns the string representation of the indicated Python object.
*/
string DCField::
get_pystr(PyObject *value) {
if (value == NULL) {
@ -626,12 +553,9 @@ get_pystr(PyObject *value) {
}
#endif // HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: DCField::refresh_default_value
// Access: Protected
// Description: Recomputes the default value of the field by
// repacking it.
////////////////////////////////////////////////////////////////////
/**
* Recomputes the default value of the field by repacking it.
*/
void DCField::
refresh_default_value() {
DCPacker packer;

View File

@ -1,16 +1,15 @@
// Filename: dcField.h
// Created by: drose (11Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcField.h
* @author drose
* @date 2000-10-11
*/
#ifndef DCFIELD_H
#define DCFIELD_H
@ -32,11 +31,9 @@ class DCSwitch;
class DCClass;
class HashGenerator;
////////////////////////////////////////////////////////////////////
// Class : DCField
// Description : A single field of a Distributed Class, either atomic
// or molecular.
////////////////////////////////////////////////////////////////////
/**
* A single field of a Distributed Class, either atomic or molecular.
*/
class EXPCL_DIRECT DCField : public DCPackerInterface, public DCKeywordList {
public:
DCField();
@ -90,7 +87,7 @@ PUBLISHED:
PyObject *args) const;
Datagram ai_format_update_msg_type(DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id,
int msg_type, PyObject *args) const;
#endif
#endif
public:
virtual void output(ostream &out, bool brief) const=0;

View File

@ -1,37 +1,29 @@
// Filename: dcFile.I
// Created by: drose (10Jan06)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcFile.I
* @author drose
* @date 2006-01-10
*/
////////////////////////////////////////////////////////////////////
// Function: DCFile::all_objects_valid
// Access: Published
// Description: Returns true if all of the classes read from the DC
// file were defined and valid, or false if any of them
// were undefined ("bogus classes"). If this is true,
// we might have read a partial file.
////////////////////////////////////////////////////////////////////
/**
* Returns true if all of the classes read from the DC file were defined and
* valid, or false if any of them were undefined ("bogus classes"). If this
* is true, we might have read a partial file.
*/
INLINE bool DCFile::
all_objects_valid() const {
return _all_objects_valid;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::check_inherited_fields
// Access: Public
// Description: Rebuilds all of the inherited fields tables, if
// necessary.
////////////////////////////////////////////////////////////////////
/**
* Rebuilds all of the inherited fields tables, if necessary.
*/
INLINE void DCFile::
check_inherited_fields() {
if (_inherited_fields_stale) {
@ -39,15 +31,11 @@ check_inherited_fields() {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::mark_inherited_fields_stale
// Access: Public
// Description: Indicates that something has changed in one or more
// of the inheritance chains or the set of fields; the
// next time check_inherited_fields() is called, the
// inherited fields tables of all classes will be
// rebuilt.
////////////////////////////////////////////////////////////////////
/**
* Indicates that something has changed in one or more of the inheritance
* chains or the set of fields; the next time check_inherited_fields() is
* called, the inherited fields tables of all classes will be rebuilt.
*/
INLINE void DCFile::
mark_inherited_fields_stale() {
_inherited_fields_stale = true;

View File

@ -1,16 +1,15 @@
// Filename: dcFile.cxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcFile.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcFile.h"
#include "dcClass.h"
@ -30,11 +29,9 @@
#endif
////////////////////////////////////////////////////////////////////
// Function: DCFile::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCFile::
DCFile() {
_all_objects_valid = true;
@ -43,22 +40,18 @@ DCFile() {
setup_default_keywords();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::Destructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCFile::
~DCFile() {
clear();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::clear
// Access: Published
// Description: Removes all of the classes defined within the DCFile
// and prepares it for reading a new file.
////////////////////////////////////////////////////////////////////
/**
* Removes all of the classes defined within the DCFile and prepares it for
* reading a new file.
*/
void DCFile::
clear() {
Declarations::iterator di;
@ -68,7 +61,7 @@ clear() {
for (di = _things_to_delete.begin(); di != _things_to_delete.end(); ++di) {
delete (*di);
}
_classes.clear();
_imports.clear();
_things_by_name.clear();
@ -85,13 +78,10 @@ clear() {
#ifdef WITHIN_PANDA
////////////////////////////////////////////////////////////////////
// Function: DCFile::read_all
// Access: Published
// Description: This special method reads all of the .dc files named
// by the "dc-file" config.prc variable, and loads them
// into the DCFile namespace.
////////////////////////////////////////////////////////////////////
/**
* This special method reads all of the .dc files named by the "dc-file"
* config.prc variable, and loads them into the DCFile namespace.
*/
bool DCFile::
read_all() {
static ConfigVariableList dc_files
@ -104,8 +94,8 @@ read_all() {
int size = dc_files.size();
// Load the DC files in opposite order, because we want to load the
// least-important (most fundamental) files first.
// Load the DC files in opposite order, because we want to load the least-
// important (most fundamental) files first.
for (int i = size - 1; i >= 0; --i) {
string dc_file = ExecutionEnvironment::expand_string(dc_files[i]);
Filename filename = Filename::from_os_specific(dc_file);
@ -119,18 +109,14 @@ read_all() {
#endif // WITHIN_PANDA
////////////////////////////////////////////////////////////////////
// Function: DCFile::read
// Access: Published
// Description: Opens and reads the indicated .dc file by name. The
// distributed classes defined in the file will be
// appended to the set of distributed classes already
// recorded, if any.
//
// Returns true if the file is successfully read, false
// if there was an error (in which case the file might
// have been partially read).
////////////////////////////////////////////////////////////////////
/**
* Opens and reads the indicated .dc file by name. The distributed classes
* defined in the file will be appended to the set of distributed classes
* already recorded, if any.
*
* Returns true if the file is successfully read, false if there was an error
* (in which case the file might have been partially read).
*/
bool DCFile::
read(Filename filename) {
#ifdef WITHIN_PANDA
@ -142,13 +128,13 @@ read(Filename filename) {
return false;
}
bool okflag = read(*in, filename);
// For some reason--compiler bug in gcc 3.2?--explicitly deleting
// the in pointer does not call the appropriate global delete
// function; instead apparently calling the system delete
// function. So we call the delete function by hand instead.
// For some reason--compiler bug in gcc 3.2?--explicitly deleting the in
// pointer does not call the appropriate global delete function; instead
// apparently calling the system delete function. So we call the delete
// function by hand instead.
vfs->close_read_file(in);
return okflag;
#else // WITHIN_PANDA
@ -166,22 +152,16 @@ read(Filename filename) {
#endif // WITHIN_PANDA
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::read
// Access: Published
// Description: Parses the already-opened input stream for
// distributed class descriptions. The filename
// parameter is optional and is only used when reporting
// errors.
//
// The distributed classes defined in the file will be
// appended to the set of distributed classes already
// recorded, if any.
//
// Returns true if the file is successfully read, false
// if there was an error (in which case the file might
// have been partially read).
////////////////////////////////////////////////////////////////////
/**
* Parses the already-opened input stream for distributed class descriptions.
* The filename parameter is optional and is only used when reporting errors.
*
* The distributed classes defined in the file will be appended to the set of
* distributed classes already recorded, if any.
*
* Returns true if the file is successfully read, false if there was an error
* (in which case the file might have been partially read).
*/
bool DCFile::
read(istream &in, const string &filename) {
cerr << "DCFile::read of " << filename << "\n";
@ -192,16 +172,12 @@ read(istream &in, const string &filename) {
return (dc_error_count() == 0);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::write
// Access: Published
// Description: Opens the indicated filename for output and writes a
// parseable description of all the known distributed
// classes to the file.
//
// Returns true if the description is successfully
// written, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Opens the indicated filename for output and writes a parseable description
* of all the known distributed classes to the file.
*
* Returns true if the description is successfully written, false otherwise.
*/
bool DCFile::
write(Filename filename, bool brief) const {
pofstream out;
@ -220,15 +196,12 @@ write(Filename filename, bool brief) const {
return write(out, brief);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::write
// Access: Published
// Description: Writes a parseable description of all the known
// distributed classes to the stream.
//
// Returns true if the description is successfully
// written, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Writes a parseable description of all the known distributed classes to the
* stream.
*
* Returns true if the description is successfully written, false otherwise.
*/
bool DCFile::
write(ostream &out, bool brief) const {
if (!_imports.empty()) {
@ -261,34 +234,27 @@ write(ostream &out, bool brief) const {
return !out.fail();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_num_classes
// Access: Published
// Description: Returns the number of classes read from the .dc
// file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the number of classes read from the .dc file(s).
*/
int DCFile::
get_num_classes() const {
return _classes.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_class
// Access: Published
// Description: Returns the nth class read from the .dc file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the nth class read from the .dc file(s).
*/
DCClass *DCFile::
get_class(int n) const {
nassertr(n >= 0 && n < (int)_classes.size(), NULL);
return _classes[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_class_by_name
// Access: Published
// Description: Returns the class that has the indicated name, or
// NULL if there is no such class.
////////////////////////////////////////////////////////////////////
/**
* Returns the class that has the indicated name, or NULL if there is no such
* class.
*/
DCClass *DCFile::
get_class_by_name(const string &name) const {
ThingsByName::const_iterator ni;
@ -300,12 +266,10 @@ get_class_by_name(const string &name) const {
return (DCClass *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_switch_by_name
// Access: Published
// Description: Returns the switch that has the indicated name, or
// NULL if there is no such switch.
////////////////////////////////////////////////////////////////////
/**
* Returns the switch that has the indicated name, or NULL if there is no such
* switch.
*/
DCSwitch *DCFile::
get_switch_by_name(const string &name) const {
ThingsByName::const_iterator ni;
@ -317,18 +281,14 @@ get_switch_by_name(const string &name) const {
return (DCSwitch *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_field_by_index
// Access: Published, Static
// Description: Returns a pointer to the one DCField that has the
// indicated index number, of all the DCFields across
// all classes in the file.
//
// This method is only valid if dc-multiple-inheritance
// is set true in the Config.prc file. Without this
// setting, different DCFields may share the same index
// number, so this global lookup is not possible.
////////////////////////////////////////////////////////////////////
/**
* Returns a pointer to the one DCField that has the indicated index number,
* of all the DCFields across all classes in the file.
*
* This method is only valid if dc-multiple-inheritance is set true in the
* Config.prc file. Without this setting, different DCFields may share the
* same index number, so this global lookup is not possible.
*/
DCField *DCFile::
get_field_by_index(int index_number) const {
nassertr(dc_multiple_inheritance, NULL);
@ -336,53 +296,42 @@ get_field_by_index(int index_number) const {
if (index_number >= 0 && index_number < (int)_fields_by_index.size()) {
return _fields_by_index[index_number];
}
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_num_import_modules
// Access: Published
// Description: Returns the number of import lines read from the .dc
// file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the number of import lines read from the .dc file(s).
*/
int DCFile::
get_num_import_modules() const {
return _imports.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_import_module
// Access: Published
// Description: Returns the module named by the nth import line read
// from the .dc file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the module named by the nth import line read from the .dc file(s).
*/
string DCFile::
get_import_module(int n) const {
nassertr(n >= 0 && n < (int)_imports.size(), string());
return _imports[n]._module;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_num_import_symbols
// Access: Published
// Description: Returns the number of symbols explicitly imported by
// the nth import line. If this is 0, the line is
// "import modulename"; if it is more than 0, the line
// is "from modulename import symbol, symbol ... ".
////////////////////////////////////////////////////////////////////
/**
* Returns the number of symbols explicitly imported by the nth import line.
* If this is 0, the line is "import modulename"; if it is more than 0, the
* line is "from modulename import symbol, symbol ... ".
*/
int DCFile::
get_num_import_symbols(int n) const {
nassertr(n >= 0 && n < (int)_imports.size(), 0);
return _imports[n]._symbols.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_import_symbol
// Access: Published
// Description: Returns the ith symbol named by the nth import line
// read from the .dc file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the ith symbol named by the nth import line read from the .dc
* file(s).
*/
string DCFile::
get_import_symbol(int n, int i) const {
nassertr(n >= 0 && n < (int)_imports.size(), string());
@ -390,34 +339,27 @@ get_import_symbol(int n, int i) const {
return _imports[n]._symbols[i];
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_num_typedefs
// Access: Published
// Description: Returns the number of typedefs read from the .dc
// file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the number of typedefs read from the .dc file(s).
*/
int DCFile::
get_num_typedefs() const {
return _typedefs.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_typedef
// Access: Published
// Description: Returns the nth typedef read from the .dc file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the nth typedef read from the .dc file(s).
*/
DCTypedef *DCFile::
get_typedef(int n) const {
nassertr(n >= 0 && n < (int)_typedefs.size(), NULL);
return _typedefs[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_typedef_by_name
// Access: Published
// Description: Returns the typedef that has the indicated name, or
// NULL if there is no such typedef name.
////////////////////////////////////////////////////////////////////
/**
* Returns the typedef that has the indicated name, or NULL if there is no
* such typedef name.
*/
DCTypedef *DCFile::
get_typedef_by_name(const string &name) const {
TypedefsByName::const_iterator ni;
@ -429,41 +371,34 @@ get_typedef_by_name(const string &name) const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_num_keywords
// Access: Published
// Description: Returns the number of keywords read from the .dc
// file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the number of keywords read from the .dc file(s).
*/
int DCFile::
get_num_keywords() const {
return _keywords.get_num_keywords();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_keyword
// Access: Published
// Description: Returns the nth keyword read from the .dc file(s).
////////////////////////////////////////////////////////////////////
/**
* Returns the nth keyword read from the .dc file(s).
*/
const DCKeyword *DCFile::
get_keyword(int n) const {
return _keywords.get_keyword(n);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_keyword_by_name
// Access: Published
// Description: Returns the keyword that has the indicated name, or
// NULL if there is no such keyword name.
////////////////////////////////////////////////////////////////////
/**
* Returns the keyword that has the indicated name, or NULL if there is no
* such keyword name.
*/
const DCKeyword *DCFile::
get_keyword_by_name(const string &name) const {
const DCKeyword *keyword = _keywords.get_keyword_by_name(name);
if (keyword == (const DCKeyword *)NULL) {
keyword = _default_keywords.get_keyword_by_name(name);
if (keyword != (const DCKeyword *)NULL) {
// One of the historical default keywords was used, but wasn't
// defined. Define it implicitly right now.
// One of the historical default keywords was used, but wasn't defined.
// Define it implicitly right now.
((DCFile *)this)->_keywords.add_keyword(keyword);
}
}
@ -471,15 +406,12 @@ get_keyword_by_name(const string &name) const {
return keyword;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::get_hash
// Access: Published
// Description: Returns a 32-bit hash index associated with this
// file. This number is guaranteed to be consistent if
// the contents of the file have not changed, and it is
// very likely to be different if the contents of the
// file do change.
////////////////////////////////////////////////////////////////////
/**
* Returns a 32-bit hash index associated with this file. This number is
* guaranteed to be consistent if the contents of the file have not changed,
* and it is very likely to be different if the contents of the file do
* change.
*/
unsigned long DCFile::
get_hash() const {
HashGenerator hashgen;
@ -487,12 +419,9 @@ get_hash() const {
return hashgen.get_hash();
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this file into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this file into the hash.
*/
void DCFile::
generate_hash(HashGenerator &hashgen) const {
if (dc_virtual_inheritance) {
@ -511,21 +440,18 @@ generate_hash(HashGenerator &hashgen) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_class
// Access: Public
// Description: Adds the newly-allocated distributed class definition
// to the file. The DCFile becomes the owner of the
// pointer and will delete it when it destructs.
// Returns true if the class is successfully added, or
// false if there was a name conflict.
////////////////////////////////////////////////////////////////////
/**
* Adds the newly-allocated distributed class definition to the file. The
* DCFile becomes the owner of the pointer and will delete it when it
* destructs. Returns true if the class is successfully added, or false if
* there was a name conflict.
*/
bool DCFile::
add_class(DCClass *dclass) {
if (!dclass->get_name().empty()) {
bool inserted = _things_by_name.insert
(ThingsByName::value_type(dclass->get_name(), dclass)).second;
if (!inserted) {
return false;
}
@ -549,21 +475,18 @@ add_class(DCClass *dclass) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_switch
// Access: Public
// Description: Adds the newly-allocated switch definition
// to the file. The DCFile becomes the owner of the
// pointer and will delete it when it destructs.
// Returns true if the switch is successfully added, or
// false if there was a name conflict.
////////////////////////////////////////////////////////////////////
/**
* Adds the newly-allocated switch definition to the file. The DCFile becomes
* the owner of the pointer and will delete it when it destructs. Returns
* true if the switch is successfully added, or false if there was a name
* conflict.
*/
bool DCFile::
add_switch(DCSwitch *dswitch) {
if (!dswitch->get_name().empty()) {
bool inserted = _things_by_name.insert
(ThingsByName::value_type(dswitch->get_name(), dswitch)).second;
if (!inserted) {
return false;
}
@ -574,14 +497,11 @@ add_switch(DCSwitch *dswitch) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_import_module
// Access: Public
// Description: Adds a new name to the list of names of Python
// modules that are to be imported by the client or AI
// to define the code that is associated with the class
// interfaces named within the .dc file.
////////////////////////////////////////////////////////////////////
/**
* Adds a new name to the list of names of Python modules that are to be
* imported by the client or AI to define the code that is associated with the
* class interfaces named within the .dc file.
*/
void DCFile::
add_import_module(const string &import_module) {
Import import;
@ -589,30 +509,24 @@ add_import_module(const string &import_module) {
_imports.push_back(import);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_import_symbol
// Access: Public
// Description: Adds a new name to the list of symbols that are to be
// explicitly imported from the most-recently added
// module, e.g. "from module_name import symbol". If
// the list of symbols is empty, the syntax is taken to
// be "import module_name".
////////////////////////////////////////////////////////////////////
/**
* Adds a new name to the list of symbols that are to be explicitly imported
* from the most-recently added module, e.g. "from module_name import
* symbol". If the list of symbols is empty, the syntax is taken to be
* "import module_name".
*/
void DCFile::
add_import_symbol(const string &import_symbol) {
nassertv(!_imports.empty());
_imports.back()._symbols.push_back(import_symbol);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_typedef
// Access: Public
// Description: Adds the newly-allocated distributed typedef definition
// to the file. The DCFile becomes the owner of the
// pointer and will delete it when it destructs.
// Returns true if the typedef is successfully added, or
// false if there was a name conflict.
////////////////////////////////////////////////////////////////////
/**
* Adds the newly-allocated distributed typedef definition to the file. The
* DCFile becomes the owner of the pointer and will delete it when it
* destructs. Returns true if the typedef is successfully added, or false if
* there was a name conflict.
*/
bool DCFile::
add_typedef(DCTypedef *dtypedef) {
bool inserted = _typedefs_by_name.insert
@ -638,14 +552,11 @@ add_typedef(DCTypedef *dtypedef) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_keyword
// Access: Public
// Description: Adds the indicated keyword string to the list of
// keywords known to the DCFile. These keywords may
// then be added to DCFields. It is not an error to add
// a particular keyword more than once.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated keyword string to the list of keywords known to the
* DCFile. These keywords may then be added to DCFields. It is not an error
* to add a particular keyword more than once.
*/
bool DCFile::
add_keyword(const string &name) {
DCKeyword *keyword = new DCKeyword(name);
@ -660,40 +571,31 @@ add_keyword(const string &name) {
return added;
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::add_thing_to_delete
// Access: Public
// Description: Adds the indicated declaration to the list of
// declarations that are not reported with the file, but
// will be deleted when the DCFile object destructs.
// That is, transfers ownership of the indicated pointer
// to the DCFile.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated declaration to the list of declarations that are not
* reported with the file, but will be deleted when the DCFile object
* destructs. That is, transfers ownership of the indicated pointer to the
* DCFile.
*/
void DCFile::
add_thing_to_delete(DCDeclaration *decl) {
_things_to_delete.push_back(decl);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::set_new_index_number
// Access: Public
// Description: Sets the next sequential available index number on
// the indicated field. This is only meant to be called
// by DCClass::add_field(), while the dc file is being
// parsed.
////////////////////////////////////////////////////////////////////
/**
* Sets the next sequential available index number on the indicated field.
* This is only meant to be called
*/
void DCFile::
set_new_index_number(DCField *field) {
field->set_number((int)_fields_by_index.size());
_fields_by_index.push_back(field);
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::setup_default_keywords
// Access: Private
// Description: Adds an entry for each of the default keywords that
// are defined for every DCFile for legacy reasons.
////////////////////////////////////////////////////////////////////
/**
* Adds an entry for each of the default keywords that are defined for every
* DCFile for legacy reasons.
*/
void DCFile::
setup_default_keywords() {
struct KeywordDef {
@ -715,21 +617,18 @@ setup_default_keywords() {
_default_keywords.clear_keywords();
for (int i = 0; default_keywords[i].name != NULL; ++i) {
DCKeyword *keyword =
new DCKeyword(default_keywords[i].name,
DCKeyword *keyword =
new DCKeyword(default_keywords[i].name,
default_keywords[i].flag);
_default_keywords.add_keyword(keyword);
_things_to_delete.push_back(keyword);
}
}
////////////////////////////////////////////////////////////////////
// Function: DCFile::rebuild_inherited_fields
// Access: Private
// Description: Reconstructs the inherited fields table of all
// classes.
////////////////////////////////////////////////////////////////////
/**
* Reconstructs the inherited fields table of all classes.
*/
void DCFile::
rebuild_inherited_fields() {
_inherited_fields_stale = false;

View File

@ -1,16 +1,15 @@
// Filename: dcFile.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcFile.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCFILE_H
#define DCFILE_H
@ -26,11 +25,10 @@ class DCTypedef;
class DCKeyword;
class DCDeclaration;
////////////////////////////////////////////////////////////////////
// Class : DCFile
// Description : Represents the complete list of Distributed Class
// descriptions as read from a .dc file.
////////////////////////////////////////////////////////////////////
/**
* Represents the complete list of Distributed Class descriptions as read from
* a .dc file.
*/
class EXPCL_DIRECT DCFile {
PUBLISHED:
DCFile();
@ -129,5 +127,3 @@ private:
#include "dcFile.I"
#endif

View File

@ -1,26 +1,23 @@
// Filename: dcKeyword.cxx
// Created by: drose (22Jul05)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcKeyword.cxx
* @author drose
* @date 2005-07-22
*/
#include "dcKeyword.h"
#include "hashGenerator.h"
#include "dcindent.h"
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCKeyword::
DCKeyword(const string &name, int historical_flag) :
_name(name),
@ -28,79 +25,61 @@ DCKeyword(const string &name, int historical_flag) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCKeyword::
~DCKeyword() {
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::get_name
// Access: Published
// Description: Returns the name of this keyword.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of this keyword.
*/
const string &DCKeyword::
get_name() const {
return _name;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::get_historical_flag
// Access: Public
// Description: Returns the bitmask associated with this keyword, if
// any. This is the value that was historically
// associated with this keyword, and was used to
// generate a hash code before we had user-customizable
// keywords. It will return ~0 if this is not an
// historical keyword.
////////////////////////////////////////////////////////////////////
/**
* Returns the bitmask associated with this keyword, if any. This is the
* value that was historically associated with this keyword, and was used to
* generate a hash code before we had user-customizable keywords. It will
* return ~0 if this is not an historical keyword.
*/
int DCKeyword::
get_historical_flag() const {
return _historical_flag;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::clear_historical_flag
// Access: Public
// Description: Resets the historical flag to ~0, as if the keyword
// were not one of the historically defined keywords.
////////////////////////////////////////////////////////////////////
/**
* Resets the historical flag to ~0, as if the keyword were not one of the
* historically defined keywords.
*/
void DCKeyword::
clear_historical_flag() {
_historical_flag = ~0;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::output
// Access: Public, Virtual
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
void DCKeyword::
output(ostream &out, bool brief) const {
out << "keyword " << _name;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::write
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCKeyword::
write(ostream &out, bool, int indent_level) const {
indent(out, indent_level)
<< "keyword " << _name << ";\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCKeyword::generate_hash
// Access: Public
// Description: Accumulates the properties of this keyword into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this keyword into the hash.
*/
void DCKeyword::
generate_hash(HashGenerator &hashgen) const {
hashgen.add_string(_name);

View File

@ -1,16 +1,15 @@
// Filename: dcKeyword.h
// Created by: drose (22Jul05)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcKeyword.h
* @author drose
* @date 2005-07-22
*/
#ifndef DCKEYWORD_H
#define DCKEYWORD_H
@ -21,13 +20,11 @@
class DCParameter;
class HashGenerator;
////////////////////////////////////////////////////////////////////
// Class : DCKeyword
// Description : This represents a single keyword declaration in the
// dc file. It is used to define a communication
// property associated with a field, for instance
// "broadcast" or "airecv".
////////////////////////////////////////////////////////////////////
/**
* This represents a single keyword declaration in the dc file. It is used to
* define a communication property associated with a field, for instance
* "broadcast" or "airecv".
*/
class EXPCL_DIRECT DCKeyword : public DCDeclaration {
public:
DCKeyword(const string &name, int historical_flag = ~0);
@ -47,8 +44,8 @@ public:
private:
const string _name;
// This flag is only kept for historical reasons, so we can preserve
// the file's hash code if no new flags are in use.
// This flag is only kept for historical reasons, so we can preserve the
// file's hash code if no new flags are in use.
int _historical_flag;
};

View File

@ -1,37 +1,32 @@
// Filename: dcKeywordList.cxx
// Created by: drose (25Jul05)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcKeywordList.cxx
* @author drose
* @date 2005-07-25
*/
#include "dcKeywordList.h"
#include "dcKeyword.h"
#include "hashGenerator.h"
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCKeywordList::
DCKeywordList() :
_flags(0)
{
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCKeywordList::
DCKeywordList(const DCKeywordList &copy) :
_keywords(copy._keywords),
@ -40,11 +35,9 @@ DCKeywordList(const DCKeywordList &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCKeywordList::
operator = (const DCKeywordList &copy) {
_keywords = copy._keywords;
@ -52,67 +45,52 @@ operator = (const DCKeywordList &copy) {
_flags = copy._flags;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCKeywordList::
~DCKeywordList() {
nassertv(_keywords_by_name.size() == _keywords.size());
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::has_keyword
// Access: Published
// Description: Returns true if this list includes the indicated
// keyword, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this list includes the indicated keyword, false otherwise.
*/
bool DCKeywordList::
has_keyword(const string &name) const {
return (_keywords_by_name.find(name) != _keywords_by_name.end());
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::has_keyword
// Access: Published
// Description: Returns true if this list includes the indicated
// keyword, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this list includes the indicated keyword, false otherwise.
*/
bool DCKeywordList::
has_keyword(const DCKeyword *keyword) const {
return has_keyword(keyword->get_name());
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::get_num_keywords
// Access: Published
// Description: Returns the number of keywords in the list.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of keywords in the list.
*/
int DCKeywordList::
get_num_keywords() const {
nassertr(_keywords_by_name.size() == _keywords.size(), 0);
return _keywords.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::get_keyword
// Access: Published
// Description: Returns the nth keyword in the list.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth keyword in the list.
*/
const DCKeyword *DCKeywordList::
get_keyword(int n) const {
nassertr(n >= 0 && n < (int)_keywords.size(), NULL);
return _keywords[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::get_keyword_by_name
// Access: Published
// Description: Returns the keyword in the list with the indicated
// name, or NULL if there is no keyword in the list with
// that name.
////////////////////////////////////////////////////////////////////
/**
* Returns the keyword in the list with the indicated name, or NULL if there
* is no keyword in the list with that name.
*/
const DCKeyword *DCKeywordList::
get_keyword_by_name(const string &name) const {
KeywordsByName::const_iterator ni;
@ -124,35 +102,27 @@ get_keyword_by_name(const string &name) const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::compare_keywords
// Access: Published
// Description: Returns true if this list has the same keywords
// as the other list, false if some keywords differ.
// Order is not considered important.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this list has the same keywords as the other list, false if
* some keywords differ. Order is not considered important.
*/
bool DCKeywordList::
compare_keywords(const DCKeywordList &other) const {
return _keywords_by_name == other._keywords_by_name;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::copy_keywords
// Access: Public
// Description: Replaces this keyword list with those from the other
// list.
////////////////////////////////////////////////////////////////////
/**
* Replaces this keyword list with those from the other list.
*/
void DCKeywordList::
copy_keywords(const DCKeywordList &other) {
(*this) = other;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::add_keyword
// Access: Public
// Description: Adds the indicated keyword to the list. Returns true
// if it is added, false if it was already there.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated keyword to the list. Returns true if it is added, false
* if it was already there.
*/
bool DCKeywordList::
add_keyword(const DCKeyword *keyword) {
bool inserted = _keywords_by_name.insert(KeywordsByName::value_type(keyword->get_name(), keyword)).second;
@ -164,11 +134,9 @@ add_keyword(const DCKeyword *keyword) {
return inserted;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::clear_keywords
// Access: Public
// Description: Removes all keywords from the field.
////////////////////////////////////////////////////////////////////
/**
* Removes all keywords from the field.
*/
void DCKeywordList::
clear_keywords() {
_keywords.clear();
@ -176,11 +144,9 @@ clear_keywords() {
_flags = 0;
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::output_keywords
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCKeywordList::
output_keywords(ostream &out) const {
Keywords::const_iterator ki;
@ -189,23 +155,19 @@ output_keywords(ostream &out) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCKeywordList::generate_hash
// Access: Public
// Description: Accumulates the properties of these keywords into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of these keywords into the hash.
*/
void DCKeywordList::
generate_hash(HashGenerator &hashgen) const {
if (_flags != ~0) {
// All of the flags are historical flags only, so add just the
// flags bitmask to keep the hash code the same as it has
// historically been.
// All of the flags are historical flags only, so add just the flags
// bitmask to keep the hash code the same as it has historically been.
hashgen.add_int(_flags);
} else {
// There is at least one custom flag, so go ahead and make the
// hash code reflect it.
// There is at least one custom flag, so go ahead and make the hash code
// reflect it.
hashgen.add_int(_keywords_by_name.size());
KeywordsByName::const_iterator ni;

View File

@ -1,16 +1,15 @@
// Filename: dcKeywordList.h
// Created by: drose (25Jul05)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcKeywordList.h
* @author drose
* @date 2005-07-25
*/
#ifndef DCKEYWORDLIST_H
#define DCKEYWORDLIST_H
@ -20,11 +19,10 @@
class DCKeyword;
class HashGenerator;
////////////////////////////////////////////////////////////////////
// Class : DCKeywordList
// Description : This is a list of keywords (see DCKeyword) that may
// be set on a particular field.
////////////////////////////////////////////////////////////////////
/**
* This is a list of keywords (see DCKeyword) that may be set on a particular
* field.
*/
class EXPCL_DIRECT DCKeywordList {
public:
DCKeywordList();

View File

@ -1,16 +1,15 @@
// Filename: dcLexerDefs.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcLexerDefs.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCLEXERDEFS_H
#define DCLEXERDEFS_H

View File

@ -1,16 +1,15 @@
// Filename: dcMolecularField.cxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcMolecularField.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcMolecularField.h"
#include "dcAtomicField.h"
@ -19,76 +18,58 @@
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCMolecularField::
DCMolecularField(const string &name, DCClass *dclass) : DCField(name, dclass) {
_got_keywords = false;
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::as_molecular_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to a
// molecular field pointer, if this is in fact a
// molecular field; otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to a molecular field pointer, if
* this is in fact a molecular field; otherwise, returns NULL.
*/
DCMolecularField *DCMolecularField::
as_molecular_field() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::as_molecular_field
// Access: Published, Virtual
// Description: Returns the same field pointer converted to a
// molecular field pointer, if this is in fact a
// molecular field; otherwise, returns NULL.
////////////////////////////////////////////////////////////////////
/**
* Returns the same field pointer converted to a molecular field pointer, if
* this is in fact a molecular field; otherwise, returns NULL.
*/
const DCMolecularField *DCMolecularField::
as_molecular_field() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::get_num_atomics
// Access: Published
// Description: Returns the number of atomic fields that make up this
// molecular field.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of atomic fields that make up this molecular field.
*/
int DCMolecularField::
get_num_atomics() const {
return _fields.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::get_atomic
// Access: Published
// Description: Returns the nth atomic field that makes up this
// molecular field. This may or may not be a field of
// this particular class; it might be defined in a
// parent class.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth atomic field that makes up this molecular field. This may
* or may not be a field of this particular class; it might be defined in a
* parent class.
*/
DCAtomicField *DCMolecularField::
get_atomic(int n) const {
nassertr(n >= 0 && n < (int)_fields.size(), NULL);
return _fields[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::add_atomic
// Access: Public
// Description: Adds the indicated atomic field to the end of the
// list of atomic fields that make up the molecular
// field. This is normally called only during parsing
// of the dc file. The atomic field should be fully
// defined by this point; you should not modify the
// atomic field (e.g. by adding more elements) after
// adding it to a molecular field.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated atomic field to the end of the list of atomic fields
* that make up the molecular field. This is normally called only during
* parsing of the dc file. The atomic field should be fully defined by this
* point; you should not modify the atomic field (e.g. by adding more
* elements) after adding it to a molecular field.
*/
void DCMolecularField::
add_atomic(DCAtomicField *atomic) {
if (!atomic->is_bogus_field()) {
@ -124,11 +105,9 @@ add_atomic(DCAtomicField *atomic) {
_default_value_stale = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCMolecularField::
output(ostream &out, bool brief) const {
out << _name;
@ -142,16 +121,14 @@ output(ostream &out, bool brief) const {
++fi;
}
}
out << ";";
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::write
// Access: Public, Virtual
// Description: Generates a parseable description of the object to
// the indicated output stream.
////////////////////////////////////////////////////////////////////
/**
* Generates a parseable description of the object to the indicated output
* stream.
*/
void DCMolecularField::
write(ostream &out, bool brief, int indent_level) const {
indent(out, indent_level);
@ -163,12 +140,9 @@ write(ostream &out, bool brief, int indent_level) const {
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this field into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this field into the hash.
*/
void DCMolecularField::
generate_hash(HashGenerator &hashgen) const {
DCField::generate_hash(hashgen);
@ -180,39 +154,31 @@ generate_hash(HashGenerator &hashgen) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCMolecularField::
get_nested_field(int n) const {
nassertr(n >= 0 && n < (int)_nested_fields.size(), NULL);
return _nested_fields[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCMolecularField::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_molecular_field(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCMolecularField::do_check_match_molecular_field
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// molecular field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated molecular field, false
* otherwise.
*/
bool DCMolecularField::
do_check_match_molecular_field(const DCMolecularField *other) const {
if (_nested_fields.size() != other->_nested_fields.size()) {

View File

@ -1,16 +1,15 @@
// Filename: dcMolecularField.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcMolecularField.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCMOLECULARFIELD_H
#define DCMOLECULARFIELD_H
@ -21,13 +20,11 @@
class DCAtomicField;
class DCParameter;
////////////////////////////////////////////////////////////////////
// Class : DCMolecularField
// Description : A single molecular field of a Distributed Class, as
// read from a .dc file. This represents a combination
// of two or more related atomic fields, that will often
// be treated as a unit.
////////////////////////////////////////////////////////////////////
/**
* A single molecular field of a Distributed Class, as read from a .dc file.
* This represents a combination of two or more related atomic fields, that
* will often be treated as a unit.
*/
class EXPCL_DIRECT DCMolecularField : public DCField {
public:
DCMolecularField(const string &name, DCClass *dclass);
@ -66,5 +63,3 @@ private:
};
#endif

View File

@ -1,44 +1,36 @@
// Filename: dcNumericRange.I
// Created by: drose (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcNumericRange.I
* @author drose
* @date 2004-06-21
*/
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
INLINE DCNumericRange<NUM>::
DCNumericRange() {
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
INLINE DCNumericRange<NUM>::
DCNumericRange(Number min, Number max) {
add_range(min, max);
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
INLINE DCNumericRange<NUM>::
DCNumericRange(const DCNumericRange<NUM> &copy) :
@ -46,23 +38,19 @@ DCNumericRange(const DCNumericRange<NUM> &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
INLINE void DCNumericRange<NUM>::
operator = (const DCNumericRange<NUM> &copy) {
_ranges = copy._ranges;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::is_in_range
// Access: Public
// Description: Returns true if the indicated number is within the
// specified range, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the indicated number is within the specified range, false
* otherwise.
*/
template <class NUM>
bool DCNumericRange<NUM>::
is_in_range(Number num) const {
@ -80,14 +68,11 @@ is_in_range(Number num) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::validate
// Access: Public
// Description: Convenience function to validate the indicated
// number. If the number is within the specified range,
// does nothing; otherwise, if it is outside the range,
// sets range_error to true.
////////////////////////////////////////////////////////////////////
/**
* Convenience function to validate the indicated number. If the number is
* within the specified range, does nothing; otherwise, if it is outside the
* range, sets range_error to true.
*/
template <class NUM>
INLINE void DCNumericRange<NUM>::
validate(Number num, bool &range_error) const {
@ -96,24 +81,20 @@ validate(Number num, bool &range_error) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::has_one_value
// Access: Public
// Description: Returns true if the numeric range specifies exactly
// one legal value, false if multiple values are legal.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the numeric range specifies exactly one legal value, false
* if multiple values are legal.
*/
template <class NUM>
INLINE bool DCNumericRange<NUM>::
has_one_value() const {
return _ranges.size() == 1 && _ranges[0]._min == _ranges[0]._max;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::get_one_value
// Access: Public
// Description: If has_one_value() returns true, this returns the one
// legal value accepted by the numeric range.
////////////////////////////////////////////////////////////////////
/**
* If has_one_value() returns true, this returns the one legal value accepted
* by the numeric range.
*/
template <class NUM>
INLINE TYPENAME DCNumericRange<NUM>::Number DCNumericRange<NUM>::
get_one_value() const {
@ -121,11 +102,9 @@ get_one_value() const {
return _ranges[0]._min;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::generate_hash
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
void DCNumericRange<NUM>::
generate_hash(HashGenerator &hashgen) const {
@ -133,19 +112,17 @@ generate_hash(HashGenerator &hashgen) const {
hashgen.add_int(_ranges.size());
TYPENAME Ranges::const_iterator ri;
for (ri = _ranges.begin(); ri != _ranges.end(); ++ri) {
// We don't account for the fractional part of floating-point
// ranges here. Shouldn't be a real issue.
// We don't account for the fractional part of floating-point ranges
// here. Shouldn't be a real issue.
hashgen.add_int((int)(*ri)._min);
hashgen.add_int((int)(*ri)._max);
}
}
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::output
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
void DCNumericRange<NUM>::
output(ostream &out, Number divisor) const {
@ -162,12 +139,10 @@ output(ostream &out, Number divisor) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::output_char
// Access: Public
// Description: Outputs the range, formatting the numeric values as
// quoted ASCII characters.
////////////////////////////////////////////////////////////////////
/**
* Outputs the range, formatting the numeric values as quoted ASCII
* characters.
*/
template <class NUM>
void DCNumericRange<NUM>::
output_char(ostream &out, Number divisor) const {
@ -189,30 +164,25 @@ output_char(ostream &out, Number divisor) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::clear
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
template <class NUM>
INLINE void DCNumericRange<NUM>::
clear() {
_ranges.clear();
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::add_range
// Access: Public
// Description: Adds a new minmax to the list of ranges. This is
// normally called only during dc file parsing. Returns
// true if successful, or false if the new minmax
// overlaps an existing minmax.
////////////////////////////////////////////////////////////////////
/**
* Adds a new minmax to the list of ranges. This is normally called only
* during dc file parsing. Returns true if successful, or false if the new
* minmax overlaps an existing minmax.
*/
template <class NUM>
bool DCNumericRange<NUM>::
add_range(Number min, Number max) {
// Check for an overlap. This is probably indicative of a typo and
// should be reported.
// Check for an overlap. This is probably indicative of a typo and should
// be reported.
if (max < min) {
return false;
}
@ -234,36 +204,28 @@ add_range(Number min, Number max) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::is_empty
// Access: Private
// Description: Returns true if the range contains no elements (and
// thus allows all numbers), false if it contains at
// least one.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the range contains no elements (and thus allows all
* numbers), false if it contains at least one.
*/
template <class NUM>
INLINE bool DCNumericRange<NUM>::
is_empty() const {
return _ranges.empty();
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::get_num_ranges
// Access: Private
// Description: Returns the number of minmax components in the range
// description.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of minmax components in the range description.
*/
template <class NUM>
INLINE int DCNumericRange<NUM>::
get_num_ranges() const {
return _ranges.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::get_min
// Access: Private
// Description: Returns the minimum value defined by the nth component.
////////////////////////////////////////////////////////////////////
/**
* Returns the minimum value defined by the nth component.
*/
template <class NUM>
INLINE TYPENAME DCNumericRange<NUM>::Number DCNumericRange<NUM>::
get_min(int n) const {
@ -271,11 +233,9 @@ get_min(int n) const {
return _ranges[n]._min;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::get_max
// Access: Private
// Description: Returns the maximum value defined by the nth component.
////////////////////////////////////////////////////////////////////
/**
* Returns the maximum value defined by the nth component.
*/
template <class NUM>
INLINE TYPENAME DCNumericRange<NUM>::Number DCNumericRange<NUM>::
get_max(int n) const {
@ -283,11 +243,9 @@ get_max(int n) const {
return _ranges[n]._max;
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::output_minmax
// Access: Private
// Description: Outputs a single element of the range description.
////////////////////////////////////////////////////////////////////
/**
* Outputs a single element of the range description.
*/
template <class NUM>
INLINE void DCNumericRange<NUM>::
output_minmax(ostream &out, Number divisor, const MinMax &range) const {
@ -308,11 +266,9 @@ output_minmax(ostream &out, Number divisor, const MinMax &range) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCNumericRange::output_minmax_char
// Access: Private
// Description: Outputs a single element of the range description.
////////////////////////////////////////////////////////////////////
/**
* Outputs a single element of the range description.
*/
template <class NUM>
INLINE void DCNumericRange<NUM>::
output_minmax_char(ostream &out, const MinMax &range) const {

View File

@ -1,16 +1,15 @@
// Filename: dcNumericRange.h
// Created by: drose (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcNumericRange.h
* @author drose
* @date 2004-06-21
*/
#ifndef DCNUMERICRANGE_H
#define DCNUMERICRANGE_H
@ -19,12 +18,10 @@
#include "hashGenerator.h"
#include "dcPacker.h"
////////////////////////////////////////////////////////////////////
// Class : DCNumericRange
// Description : Represents a range of legal integer or floating-point
// values. This is used to constrain simple numeric
// types, as well as array sizes.
////////////////////////////////////////////////////////////////////
/**
* Represents a range of legal integer or floating-point values. This is used
* to constrain simple numeric types, as well as array sizes.
*/
template <class NUM>
class DCNumericRange {
public:

View File

@ -1,23 +1,19 @@
// Filename: dcPackData.I
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackData.I
* @author drose
* @date 2004-06-15
*/
////////////////////////////////////////////////////////////////////
// Function: DCPackData::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE DCPackData::
DCPackData() {
_buffer = NULL;
@ -25,11 +21,9 @@ DCPackData() {
_used_length = 0;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::Destructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE DCPackData::
~DCPackData() {
if (_buffer != (const char *)NULL) {
@ -37,129 +31,100 @@ INLINE DCPackData::
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::clear
// Access: Published
// Description: Empties the contents of the data (without necessarily
// freeing its allocated memory).
////////////////////////////////////////////////////////////////////
/**
* Empties the contents of the data (without necessarily freeing its allocated
* memory).
*/
INLINE void DCPackData::
clear() {
_used_length = 0;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::append_data
// Access: Public
// Description: Adds the indicated bytes to the end of the data.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated bytes to the end of the data.
*/
INLINE void DCPackData::
append_data(const char *buffer, size_t size) {
set_used_length(_used_length + size);
memcpy(_buffer + _used_length - size, buffer, size);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::get_write_pointer
// Access: Public
// Description: Adds the indicated number of bytes to the end of the
// data without initializing them, and returns a pointer
// to the beginning of the new data.
////////////////////////////////////////////////////////////////////
/**
* Adds the indicated number of bytes to the end of the data without
* initializing them, and returns a pointer to the beginning of the new data.
*/
INLINE char *DCPackData::
get_write_pointer(size_t size) {
set_used_length(_used_length + size);
return _buffer + _used_length - size;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::append_junk
// Access: Public
// Description: Adds some uninitialized bytes to the end of the data.
////////////////////////////////////////////////////////////////////
/**
* Adds some uninitialized bytes to the end of the data.
*/
INLINE void DCPackData::
append_junk(size_t size) {
set_used_length(_used_length + size);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::rewrite_data
// Access: Public
// Description: Changes the data at the indicated position to the
// given value. It is an error if there are not at
// least position + size bytes in the data.
////////////////////////////////////////////////////////////////////
/**
* Changes the data at the indicated position to the given value. It is an
* error if there are not at least position + size bytes in the data.
*/
INLINE void DCPackData::
rewrite_data(size_t position, const char *buffer, size_t size) {
nassertv(position + size <= _used_length);
memcpy(_buffer + position, buffer, size);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::get_rewrite_pointer
// Access: Public
// Description: Returns a pointer into the middle of the data at the
// indicated point.
////////////////////////////////////////////////////////////////////
/**
* Returns a pointer into the middle of the data at the indicated point.
*/
INLINE char *DCPackData::
get_rewrite_pointer(size_t position, size_t size) {
nassertr(position + size <= _used_length, NULL);
return _buffer + position;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::get_string
// Access: Published
// Description: Returns the data buffer as a string. Also see
// get_data().
////////////////////////////////////////////////////////////////////
/**
* Returns the data buffer as a string. Also see get_data().
*/
INLINE string DCPackData::
get_string() const {
return string(_buffer, _used_length);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::get_length
// Access: Published
// Description: Returns the current length of the buffer. This is
// the number of useful bytes stored in the buffer, not
// the amount of memory it takes up.
////////////////////////////////////////////////////////////////////
/**
* Returns the current length of the buffer. This is the number of useful
* bytes stored in the buffer, not the amount of memory it takes up.
*/
INLINE size_t DCPackData::
get_length() const {
return _used_length;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::get_data
// Access: Public
// Description: Returns the beginning of the data buffer. The buffer
// is not null-terminated, but see also get_string().
// This may (or may not) return NULL if the buffer is
// empty.
//
// This may be used in conjunction with get_length() to
// copy all of the bytes out of the buffer.
////////////////////////////////////////////////////////////////////
/**
* Returns the beginning of the data buffer. The buffer is not null-
* terminated, but see also get_string(). This may (or may not) return NULL if
* the buffer is empty.
*
* This may be used in conjunction with get_length() to copy all of the bytes
* out of the buffer.
*/
INLINE const char *DCPackData::
get_data() const {
return _buffer;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackData::take_data
// Access: Public
// Description: Returns the pointer to the beginning of the data
// buffer, and transfers ownership of the buffer to the
// caller. The caller is now responsible for ultimately
// freeing the returned pointer with delete[], if it is
// non-NULL. This may (or may not) return NULL if the
// buffer is empty.
//
// This also empties the DCPackData structure, and sets
// its length to zero (so you should call get_length()
// before calling this method).
////////////////////////////////////////////////////////////////////
/**
* Returns the pointer to the beginning of the data buffer, and transfers
* ownership of the buffer to the caller. The caller is now responsible for
* ultimately freeing the returned pointer with delete[], if it is non-NULL.
* This may (or may not) return NULL if the buffer is empty.
*
* This also empties the DCPackData structure, and sets its length to zero (so
* you should call get_length() before calling this method).
*/
INLINE char *DCPackData::
take_data() {
char *data = _buffer;

View File

@ -1,28 +1,24 @@
// Filename: dcPackData.cxx
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackData.cxx
* @author drose
* @date 2004-06-15
*/
#include "dcPackData.h"
static const size_t extra_size = 50;
////////////////////////////////////////////////////////////////////
// Function: DCPackData::set_used_length
// Access: Private
// Description: Ensures that the buffer has at least size bytes, and
// sets the _used_length to the indicated value; grows
// the buffer if it does not.
////////////////////////////////////////////////////////////////////
/**
* Ensures that the buffer has at least size bytes, and sets the _used_length
* to the indicated value; grows the buffer if it does not.
*/
void DCPackData::
set_used_length(size_t size) {
if (size > _allocated_size) {

View File

@ -1,27 +1,24 @@
// Filename: dcPackData.h
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackData.h
* @author drose
* @date 2004-06-15
*/
#ifndef DCPACKDATA_H
#define DCPACKDATA_H
#include "dcbase.h"
////////////////////////////////////////////////////////////////////
// Class : DCPackData
// Description : This is a block of data that receives the results of
// DCPacker.
////////////////////////////////////////////////////////////////////
/**
* This is a block of data that receives the results of DCPacker.
*/
class EXPCL_DIRECT DCPackData {
PUBLISHED:
INLINE DCPackData();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,15 @@
// Filename: dcPacker.h
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPacker.h
* @author drose
* @date 2004-06-15
*/
#ifndef DCPACKER_H
#define DCPACKER_H
@ -25,16 +24,13 @@
class DCClass;
class DCSwitchParameter;
////////////////////////////////////////////////////////////////////
// Class : DCPacker
// Description : This class can be used for packing a series of
// numeric and string data into a binary stream,
// according to the DC specification.
//
// See also direct/src/doc/dcPacker.txt for a more
// complete description and examples of using this
// class.
////////////////////////////////////////////////////////////////////
/**
* This class can be used for packing a series of numeric and string data into
* a binary stream, according to the DC specification.
*
* See also direct/src/doc/dcPacker.txt for a more complete description and
* examples of using this class.
*/
class EXPCL_DIRECT DCPacker {
PUBLISHED:
DCPacker();
@ -47,7 +43,7 @@ PUBLISHED:
void set_unpack_data(const string &data);
public:
void set_unpack_data(const char *unpack_data, size_t unpack_length,
void set_unpack_data(const char *unpack_data, size_t unpack_length,
bool owns_unpack_data);
PUBLISHED:
@ -93,8 +89,8 @@ PUBLISHED:
void unpack_skip();
public:
// The following are variants on the above unpack() calls that pass
// the result back by reference instead of as a return value.
// The following are variants on the above unpack() calls that pass the
// result back by reference instead of as a return value.
INLINE void unpack_double(double &value);
INLINE void unpack_int(int &value);
INLINE void unpack_uint(unsigned int &value);
@ -138,9 +134,9 @@ public:
PUBLISHED:
INLINE static int get_num_stack_elements_ever_allocated();
// The following methods are used only for packing (or unpacking)
// raw data into the buffer between packing sessions (e.g. between
// calls to end_pack() and the next begin_pack()).
// The following methods are used only for packing (or unpacking) raw data
// into the buffer between packing sessions (e.g. between calls to
// end_pack() and the next begin_pack()).
INLINE void raw_pack_int8(int value);
INLINE void raw_pack_int16(int value);
@ -153,11 +149,11 @@ PUBLISHED:
INLINE void raw_pack_float64(double value);
INLINE void raw_pack_string(const string &value);
// this is a hack to allw me to get in and out of 32bit Mode Faster
// need to agree with channel_type in dcbase.h
// this is a hack to allw me to get in and out of 32bit Mode Faster need to
// agree with channel_type in dcbase.h
#define RAW_PACK_CHANNEL(in) raw_pack_uint64(in)
#define RAW_UNPACK_CHANNEL() raw_unpack_uint64()
INLINE int raw_unpack_int8();
INLINE int raw_unpack_int16();
@ -195,9 +191,9 @@ private:
#ifdef HAVE_PYTHON
void pack_class_object(const DCClass *dclass, PyObject *object);
PyObject *unpack_class_object(const DCClass *dclass);
void set_class_element(PyObject *class_def, PyObject *&object,
void set_class_element(PyObject *class_def, PyObject *&object,
const DCField *field);
void get_class_element(const DCClass *dclass, PyObject *object,
void get_class_element(const DCClass *dclass, PyObject *object,
const DCField *field);
#endif
@ -222,8 +218,8 @@ private:
class EXPCL_DIRECT StackElement {
public:
// As an optimization, we implement operator new and delete here
// to minimize allocation overhead during push() and pop().
// As an optimization, we implement operator new and delete here to
// minimize allocation overhead during push() and pop().
INLINE void *operator new(size_t size);
INLINE void operator delete(void *ptr);
@ -242,14 +238,12 @@ private:
const DCPackerInterface *_current_parent;
int _current_field_index;
// _push_marker marks the beginning of the push record (so we can go
// back and write in the length later, or figure out the switch
// parameter).
// _push_marker marks the beginning of the push record (so we can go back
// and write in the length later, or figure out the switch parameter).
size_t _push_marker;
// _pop_marker is used in unpack mode with certain data structures
// (like dynamic arrays) to mark the end of the push record (so we
// know when we've reached the end). It is zero when it is not in
// use.
// _pop_marker is used in unpack mode with certain data structures (like
// dynamic arrays) to mark the end of the push record (so we know when we've
// reached the end). It is zero when it is not in use.
size_t _pop_marker;
int _num_nested_fields;
const DCSwitchParameter *_last_switch;

View File

@ -1,104 +1,82 @@
// Filename: dcPackerCatalog.I
// Created by: drose (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerCatalog.I
* @author drose
* @date 2004-06-21
*/
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::get_begin
// Access: Public
// Description: Returns the beginning of the indicated field within
// the live data.
////////////////////////////////////////////////////////////////////
/**
* Returns the beginning of the indicated field within the live data.
*/
INLINE size_t DCPackerCatalog::LiveCatalog::
get_begin(int n) const {
nassertr(n >= 0 && n < (int)_live_entries.size(), 0);
return _live_entries[n]._begin;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::get_end
// Access: Public
// Description: Returns the end of the indicated field (the byte
// position of the first following field) within the
// live data.
////////////////////////////////////////////////////////////////////
/**
* Returns the end of the indicated field (the byte position of the first
* following field) within the live data.
*/
INLINE size_t DCPackerCatalog::LiveCatalog::
get_end(int n) const {
nassertr(n >= 0 && n < (int)_live_entries.size(), 0);
return _live_entries[n]._end;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::get_num_entries
// Access: Public
// Description: Returns the number of entries in the catalog.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of entries in the catalog.
*/
INLINE int DCPackerCatalog::LiveCatalog::
get_num_entries() const {
return _catalog->get_num_entries();
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::get_entry
// Access: Public
// Description: Returns the nth entry in the catalog.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth entry in the catalog.
*/
INLINE const DCPackerCatalog::Entry &DCPackerCatalog::LiveCatalog::
get_entry(int n) const {
return _catalog->get_entry(n);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::find_entry_by_name
// Access: Public
// Description: Returns the index number of the entry with the
// indicated name, or -1 if no entry has the indicated
// name. The return value is suitable for passing to
// get_entry().
////////////////////////////////////////////////////////////////////
/**
* Returns the index number of the entry with the indicated name, or -1 if no
* entry has the indicated name. The return value is suitable for passing to
* get_entry().
*/
int DCPackerCatalog::LiveCatalog::
find_entry_by_name(const string &name) const {
return _catalog->find_entry_by_name(name);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::LiveCatalog::find_entry_by_field
// Access: Public
// Description: Returns the index number of the entry with the
// indicated field, or -1 if no entry has the indicated
// field. The return value is suitable for passing to
// get_entry().
////////////////////////////////////////////////////////////////////
/**
* Returns the index number of the entry with the indicated field, or -1 if no
* entry has the indicated field. The return value is suitable for passing to
* get_entry().
*/
int DCPackerCatalog::LiveCatalog::
find_entry_by_field(const DCPackerInterface *field) const {
return _catalog->find_entry_by_field(field);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::get_num_entries
// Access: Public
// Description: Returns the number of entries in the catalog.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of entries in the catalog.
*/
INLINE int DCPackerCatalog::
get_num_entries() const {
return _entries.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::get_entry
// Access: Public
// Description: Returns the nth entry in the catalog.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth entry in the catalog.
*/
INLINE const DCPackerCatalog::Entry &DCPackerCatalog::
get_entry(int n) const {
nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]);

View File

@ -1,39 +1,32 @@
// Filename: dcPackerCatalog.cxx
// Created by: drose (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerCatalog.cxx
* @author drose
* @date 2004-06-21
*/
#include "dcPackerCatalog.h"
#include "dcPackerInterface.h"
#include "dcPacker.h"
#include "dcSwitchParameter.h"
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::Constructor
// Access: Private
// Description: The catalog is created only by
// DCPackerInterface::get_catalog().
////////////////////////////////////////////////////////////////////
/**
* The catalog is created only by DCPackerInterface::get_catalog().
*/
DCPackerCatalog::
DCPackerCatalog(const DCPackerInterface *root) : _root(root) {
_live_catalog = NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::Copy Constructor
// Access: Private
// Description: The copy constructor is used only internally, in
// update_switch_fields().
////////////////////////////////////////////////////////////////////
/**
* The copy constructor is used only internally, in update_switch_fields().
*/
DCPackerCatalog::
DCPackerCatalog(const DCPackerCatalog &copy) :
_root(copy._root),
@ -44,12 +37,9 @@ DCPackerCatalog(const DCPackerCatalog &copy) :
_live_catalog = NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::Destructor
// Access: Private
// Description: The catalog is destroyed only by
// ~DCPackerInterface().
////////////////////////////////////////////////////////////////////
/**
* The catalog is destroyed only by ~DCPackerInterface().
*/
DCPackerCatalog::
~DCPackerCatalog() {
if (_live_catalog != (LiveCatalog *)NULL) {
@ -62,14 +52,11 @@ DCPackerCatalog::
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::find_entry_by_name
// Access: Public
// Description: Returns the index number of the entry with the
// indicated name, or -1 if no entry has the indicated
// name. The return value is suitable for passing to
// get_entry().
////////////////////////////////////////////////////////////////////
/**
* Returns the index number of the entry with the indicated name, or -1 if no
* entry has the indicated name. The return value is suitable for passing to
* get_entry().
*/
int DCPackerCatalog::
find_entry_by_name(const string &name) const {
EntriesByName::const_iterator ni;
@ -80,14 +67,11 @@ find_entry_by_name(const string &name) const {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::find_entry_by_field
// Access: Public
// Description: Returns the index number of the entry with the
// indicated field, or -1 if no entry has the indicated
// field. The return value is suitable for passing to
// get_entry().
////////////////////////////////////////////////////////////////////
/**
* Returns the index number of the entry with the indicated field, or -1 if no
* entry has the indicated field. The return value is suitable for passing to
* get_entry().
*/
int DCPackerCatalog::
find_entry_by_field(const DCPackerInterface *field) const {
EntriesByField::const_iterator ni;
@ -98,23 +82,19 @@ find_entry_by_field(const DCPackerInterface *field) const {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::get_live_catalog
// Access: Public
// Description: Returns a LiveCatalog object indicating the positions
// within the indicated data record of each field within
// the catalog. If the catalog's fields are all
// fixed-width, this may return a statically-allocated
// LiveCatalog object that is the same for all data
// records; otherwise, it will allocate a new
// LiveCatalog object that must be freed with a later
// call to release_live_catalog().
////////////////////////////////////////////////////////////////////
/**
* Returns a LiveCatalog object indicating the positions within the indicated
* data record of each field within the catalog. If the catalog's fields are
* all fixed-width, this may return a statically-allocated LiveCatalog object
* that is the same for all data records; otherwise, it will allocate a new
* LiveCatalog object that must be freed with a later call to
* release_live_catalog().
*/
const DCPackerCatalog::LiveCatalog *DCPackerCatalog::
get_live_catalog(const char *data, size_t length) const {
if (_live_catalog != (LiveCatalog *)NULL) {
// Return the previously-allocated live catalog; it will be the
// same as this one since it's based on a fixed-length field.
// Return the previously-allocated live catalog; it will be the same as
// this one since it's based on a fixed-length field.
return _live_catalog;
}
@ -127,7 +107,7 @@ get_live_catalog(const char *data, size_t length) const {
for (size_t i = 0; i < _entries.size(); i++) {
live_catalog->_live_entries.push_back(zero_entry);
}
DCPacker packer;
packer.set_unpack_data(data, length, false);
packer.begin_unpack(_root);
@ -141,27 +121,23 @@ get_live_catalog(const char *data, size_t length) const {
}
if (_root->has_fixed_structure()) {
// If our root field has a fixed structure, then the live catalog
// will always be the same every time, so we might as well keep
// this one around as an optimization.
// If our root field has a fixed structure, then the live catalog will
// always be the same every time, so we might as well keep this one around
// as an optimization.
((DCPackerCatalog *)this)->_live_catalog = live_catalog;
}
return live_catalog;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::release_live_catalog
// Access: Public
// Description: Releases the LiveCatalog object that was returned by
// an earlier call to get_live_catalog(). If this
// represents a newly-allocated live catalog, it will
// free it; otherwise, it will do nothing.
//
// It is therefore always correct (and necessary) to
// match a call to get_live_catalog() with a later call
// to release_live_catalog().
////////////////////////////////////////////////////////////////////
/**
* Releases the LiveCatalog object that was returned by an earlier call to
* get_live_catalog(). If this represents a newly-allocated live catalog, it
* will free it; otherwise, it will do nothing.
*
* It is therefore always correct (and necessary) to match a call to
* get_live_catalog() with a later call to release_live_catalog().
*/
void DCPackerCatalog::
release_live_catalog(const DCPackerCatalog::LiveCatalog *live_catalog) const {
if (live_catalog != _live_catalog) {
@ -169,12 +145,10 @@ release_live_catalog(const DCPackerCatalog::LiveCatalog *live_catalog) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::add_entry
// Access: Private
// Description: Called only by DCPackerInterface::r_fill_catalog(),
// this adds a new entry to the catalog.
////////////////////////////////////////////////////////////////////
/**
* Called only by DCPackerInterface::r_fill_catalog(), this adds a new entry
* to the catalog.
*/
void DCPackerCatalog::
add_entry(const string &name, const DCPackerInterface *field,
const DCPackerInterface *parent, int field_index) {
@ -188,31 +162,27 @@ add_entry(const string &name, const DCPackerInterface *field,
_entries.push_back(entry);
_entries_by_field.insert(EntriesByField::value_type(field, entry_index));
// Add an entry for the fully-qualified field name
// (e.g. dna.topTex). If there was another entry for this name
// previously, completely replace it--the fully-qualified name is
// supposed to be unique and trumps the local field names (which are
// not necessarily unique).
// Add an entry for the fully-qualified field name (e.g. dna.topTex). If
// there was another entry for this name previously, completely replace it--
// the fully-qualified name is supposed to be unique and trumps the local
// field names (which are not necessarily unique).
_entries_by_name[name] = entry_index;
// We'll also add an entry for the local field name, for the user's
// convenience. This won't override a fully-qualified name that
// might already have been recorded, and a fully-qualified name
// discovered later that conflicts with this name will replace it.
// convenience. This won't override a fully-qualified name that might
// already have been recorded, and a fully-qualified name discovered later
// that conflicts with this name will replace it.
string local_name = field->get_name();
if (local_name != name) {
_entries_by_name.insert(EntriesByName::value_type(local_name, entry_index));
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::r_fill_catalog
// Access: Private
// Description: Called by DCPackerInterface to recursively fill up a
// newly-allocated reference catalog. Also called by
// update_switch_fields to append fields to a catalog
// after a DCSwitch node is selected.
////////////////////////////////////////////////////////////////////
/**
* Called by DCPackerInterface to recursively fill up a newly-allocated
* reference catalog. Also called by update_switch_fields to append fields to
* a catalog after a DCSwitch node is selected.
*/
void DCPackerCatalog::
r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
const DCPackerInterface *parent, int field_index) {
@ -230,9 +200,8 @@ r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
if (switch_parameter != (DCSwitchParameter *)NULL) {
// If we come upon a DCSwitch while building the catalog, save the
// name_prefix at this point so we'll have it again when we later
// encounter the switch while unpacking a live record (and so we
// can return to this point in the recursion from
// update_switch_fields).
// encounter the switch while unpacking a live record (and so we can
// return to this point in the recursion from update_switch_fields).
_switch_prefixes[switch_parameter] = next_name_prefix;
}
@ -249,13 +218,10 @@ r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::r_fill_live_catalog
// Access: Private
// Description: Recursively walks through all of the fields on the
// catalog and fills the live catalog with the
// appropriate offsets.
////////////////////////////////////////////////////////////////////
/**
* Recursively walks through all of the fields on the catalog and fills the
* live catalog with the appropriate offsets.
*/
void DCPackerCatalog::
r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
const DCSwitchParameter *&last_switch) const {
@ -267,7 +233,7 @@ r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
live_catalog->_live_entries[field_index]._begin = packer.get_num_unpacked_bytes();
}
if (packer.has_nested_fields() &&
if (packer.has_nested_fields() &&
(packer.get_pack_type() != PT_string && packer.get_pack_type() != PT_blob)) {
packer.push();
while (packer.more_nested_fields()) {
@ -284,48 +250,42 @@ r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
}
if (last_switch != packer.get_last_switch()) {
// We've just invoked a new DCSwitch. That means we must add the
// new fields revealed by the switch to the reference catalog.
// We've just invoked a new DCSwitch. That means we must add the new
// fields revealed by the switch to the reference catalog.
last_switch = packer.get_last_switch();
const DCPackerInterface *switch_case = packer.get_current_parent();
nassertv(switch_case != (DCPackerInterface *)NULL);
const DCPackerCatalog *switch_catalog =
const DCPackerCatalog *switch_catalog =
live_catalog->_catalog->update_switch_fields(last_switch, switch_case);
nassertv(switch_catalog != (DCPackerCatalog *)NULL);
live_catalog->_catalog = switch_catalog;
// And we also have to expand the live catalog to hold the new
// entries.
// And we also have to expand the live catalog to hold the new entries.
LiveCatalogEntry zero_entry;
zero_entry._begin = 0;
zero_entry._end = 0;
for (size_t i = live_catalog->_live_entries.size();
i < switch_catalog->_entries.size();
for (size_t i = live_catalog->_live_entries.size();
i < switch_catalog->_entries.size();
i++) {
live_catalog->_live_entries.push_back(zero_entry);
}
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerCatalog::update_switch_fields
// Access: Private
// Description: Returns a new DCPackerCatalog that includes all of
// the fields in this object, with the addition of the
// fields named by switch_case.
//
// This is used to implement switches, which change the
// set of fields they make available according to the
// data in the record, and therefore present a different
// catalog under different circumstances.
//
// This returned pointer is allocated one time for each
// different switch_case instance; if a given same
// switch_case is supplied twice, the same pointer is
// returned both times. The ownership of the returned
// pointer is kept by this object.
////////////////////////////////////////////////////////////////////
/**
* Returns a new DCPackerCatalog that includes all of the fields in this
* object, with the addition of the fields named by switch_case.
*
* This is used to implement switches, which change the set of fields they
* make available according to the data in the record, and therefore present a
* different catalog under different circumstances.
*
* This returned pointer is allocated one time for each different switch_case
* instance; if a given same switch_case is supplied twice, the same pointer
* is returned both times. The ownership of the returned pointer is kept by
* this object.
*/
const DCPackerCatalog *DCPackerCatalog::
update_switch_fields(const DCSwitchParameter *switch_parameter,
const DCPackerInterface *switch_case) const {
@ -334,28 +294,26 @@ update_switch_fields(const DCSwitchParameter *switch_parameter,
return (*si).second;
}
// Look up the name_prefix will we use for all of the fields that
// descend from this switch. This should be stored in this record
// because we must have come across the DCSwitch when building the
// catalog the first time.
// Look up the name_prefix will we use for all of the fields that descend
// from this switch. This should be stored in this record because we must
// have come across the DCSwitch when building the catalog the first time.
SwitchPrefixes::const_iterator pi = _switch_prefixes.find(switch_parameter);
if (pi == _switch_prefixes.end()) {
// If it's not stored in the record, the switch must be hidden
// within some non-seekable object, like an array; in this case,
// never mind.
// If it's not stored in the record, the switch must be hidden within some
// non-seekable object, like an array; in this case, never mind.
return this;
}
string name_prefix = (*pi).second;
// Start by creating a new DCPackerCatalog object that contains all
// of the fields that this one contains.
// Start by creating a new DCPackerCatalog object that contains all of the
// fields that this one contains.
DCPackerCatalog *switch_catalog = new DCPackerCatalog(*this);
// Now record all of the fields of the switch case in the new
// catalog. We start with the second field of the switch case,
// since the first field will be the switch parameter itself, which
// we would have already recorded the first time around.
// Now record all of the fields of the switch case in the new catalog. We
// start with the second field of the switch case, since the first field
// will be the switch parameter itself, which we would have already recorded
// the first time around.
int num_nested = switch_case->get_num_nested_fields();
for (int i = 1; i < num_nested; i++) {
DCPackerInterface *nested = switch_case->get_nested_field(i);
@ -364,8 +322,8 @@ update_switch_fields(const DCSwitchParameter *switch_parameter,
}
}
// Store the newly-generated switch catalog in the record so the
// same pointer can be returned in the future.
// Store the newly-generated switch catalog in the record so the same
// pointer can be returned in the future.
((DCPackerCatalog *)this)->_switch_catalogs[switch_case] = switch_catalog;
return switch_catalog;

View File

@ -1,16 +1,15 @@
// Filename: dcPackerCatalog.h
// Created by: drose (21Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerCatalog.h
* @author drose
* @date 2004-06-21
*/
#ifndef DCPACKERCATALOG_H
#define DCPACKERCATALOG_H
@ -21,14 +20,12 @@ class DCPackerInterface;
class DCPacker;
class DCSwitchParameter;
////////////////////////////////////////////////////////////////////
// Class : DCPackerCatalog
// Description : This object contains the names of all of the nested
// fields available within a particular field. It is
// created on demand when a catalog is first requested
// from a particular field; its ownership is retained by
// the field so it must not be deleted.
////////////////////////////////////////////////////////////////////
/**
* This object contains the names of all of the nested fields available within
* a particular field. It is created on demand when a catalog is first
* requested from a particular field; its ownership is retained by the field
* so it must not be deleted.
*/
class EXPCL_DIRECT DCPackerCatalog {
private:
DCPackerCatalog(const DCPackerInterface *root);
@ -36,8 +33,8 @@ private:
~DCPackerCatalog();
public:
// The Entry class records the static catalog data: the name of each
// field and its relationship to its parent.
// The Entry class records the static catalog data: the name of each field
// and its relationship to its parent.
class Entry {
public:
string _name;
@ -46,10 +43,9 @@ public:
int _field_index;
};
// The LiveCatalog class adds the dynamic catalog data: the actual
// location of each field within the data record. This might be
// different for different data records (since some data fields have
// a dynamic length).
// The LiveCatalog class adds the dynamic catalog data: the actual location
// of each field within the data record. This might be different for
// different data records (since some data fields have a dynamic length).
class LiveCatalogEntry {
public:
size_t _begin;
@ -84,7 +80,7 @@ public:
private:
void add_entry(const string &name, const DCPackerInterface *field,
const DCPackerInterface *parent, int field_index);
void r_fill_catalog(const string &name_prefix, const DCPackerInterface *field,
const DCPackerInterface *parent, int field_index);
void r_fill_live_catalog(LiveCatalog *live_catalog, DCPacker &packer,
@ -92,11 +88,11 @@ private:
const DCPackerCatalog *update_switch_fields(const DCSwitchParameter *dswitch,
const DCPackerInterface *switch_case) const;
const DCPackerInterface *_root;
LiveCatalog *_live_catalog;
typedef pvector<Entry> Entries;
Entries _entries;

View File

@ -1,172 +1,135 @@
// Filename: dcPackerInterface.I
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerInterface.I
* @author drose
* @date 2004-06-18
*/
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_name
// Access: Published
// Description: Returns the name of this field, or empty string
// if the field is unnamed.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of this field, or empty string if the field is unnamed.
*/
INLINE const string &DCPackerInterface::
get_name() const {
return _name;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::check_match
// Access: Published
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
INLINE bool DCPackerInterface::
check_match(const DCPackerInterface *other) const {
return do_check_match(other);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::has_fixed_byte_size
// Access: Public
// Description: Returns true if this field type always packs to the
// same number of bytes, false if it is variable.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field type always packs to the same number of bytes,
* false if it is variable.
*/
INLINE bool DCPackerInterface::
has_fixed_byte_size() const {
return _has_fixed_byte_size;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_fixed_byte_size
// Access: Public
// Description: If has_fixed_byte_size() returns true, this returns
// the number of bytes this field type will use.
////////////////////////////////////////////////////////////////////
/**
* If has_fixed_byte_size() returns true, this returns the number of bytes
* this field type will use.
*/
INLINE size_t DCPackerInterface::
get_fixed_byte_size() const {
return _fixed_byte_size;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::has_fixed_structure
// Access: Public
// Description: Returns true if this field type always has the same
// structure regardless of the data in the stream, or
// false if its structure may vary. This is almost, but
// not quite, the same thing as has_fixed_byte_size.
// The difference is that a DCSwitch may have multiple
// cases all with the same byte size, but they will
// still (presumably) have different structures, in the
// sense that the actual list of fields varies according
// to the live data.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field type always has the same structure regardless of
* the data in the stream, or false if its structure may vary. This is
* almost, but not quite, the same thing as has_fixed_byte_size. The
* difference is that a DCSwitch may have multiple cases all with the same
* byte size, but they will still (presumably) have different structures, in
* the sense that the actual list of fields varies according to the live data.
*/
INLINE bool DCPackerInterface::
has_fixed_structure() const {
return _has_fixed_structure;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::has_range_limits
// Access: Public
// Description: Returns true if this field, or any sub-field of this
// field, has a limit imposed in the DC file on its
// legal values. If this is false, then
// unpack_validate() is trivial.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field, or any sub-field of this field, has a limit
* imposed in the DC file on its legal values. If this is false, then
* unpack_validate() is trivial.
*/
INLINE bool DCPackerInterface::
has_range_limits() const {
return _has_range_limits;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_num_length_bytes
// Access: Public
// Description: Returns the number of bytes that should be written
// into the stream on a push() to record the number of
// bytes in the record up until the next pop(). This is
// only meaningful if _has_nested_fields is true.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of bytes that should be written into the stream on a
* push() to record the number of bytes in the record up until the next pop().
* This is only meaningful if _has_nested_fields is true.
*/
INLINE size_t DCPackerInterface::
get_num_length_bytes() const {
return _num_length_bytes;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::has_nested_fields
// Access: Public
// Description: Returns true if this field type has any nested fields
// (and thus expects a push() .. pop() interface to the
// DCPacker), or false otherwise. If this returns true,
// get_num_nested_fields() may be called to determine
// how many nested fields are expected.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field type has any nested fields (and thus expects a
* push() .. pop() interface to the DCPacker), or false otherwise. If this
* returns true, get_num_nested_fields() may be called to determine how many
* nested fields are expected.
*/
INLINE bool DCPackerInterface::
has_nested_fields() const {
return _has_nested_fields;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_num_nested_fields
// Access: Public
// Description: Returns the number of nested fields required by this
// field type. These may be array elements or structure
// elements. The return value may be -1 to indicate the
// number of nested fields is variable.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of nested fields required by this field type. These may
* be array elements or structure elements. The return value may be -1 to
* indicate the number of nested fields is variable.
*/
INLINE int DCPackerInterface::
get_num_nested_fields() const {
return _num_nested_fields;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_pack_type
// Access: Public
// Description: Returns the type of value expected by this field.
////////////////////////////////////////////////////////////////////
/**
* Returns the type of value expected by this field.
*/
INLINE DCPackType DCPackerInterface::
get_pack_type() const {
return _pack_type;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_int8
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_int8(char *buffer, int value) {
buffer[0] = (char)(value & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_int16
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_int16(char *buffer, int value) {
buffer[0] = (char)(value & 0xff);
buffer[1] = (char)((value >> 8) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_int32
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_int32(char *buffer, int value) {
buffer[0] = (char)(value & 0xff);
@ -175,11 +138,9 @@ do_pack_int32(char *buffer, int value) {
buffer[3] = (char)((value >> 24) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_int64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_int64(char *buffer, PN_int64 value) {
buffer[0] = (char)(value & 0xff);
@ -192,32 +153,26 @@ do_pack_int64(char *buffer, PN_int64 value) {
buffer[7] = (char)((value >> 56) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_uint8
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_uint8(char *buffer, unsigned int value) {
buffer[0] = (char)(value & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_uint16
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_uint16(char *buffer, unsigned int value) {
buffer[0] = (char)(value & 0xff);
buffer[1] = (char)((value >> 8) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_uint32
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_uint32(char *buffer, unsigned int value) {
buffer[0] = (char)(value & 0xff);
@ -226,11 +181,9 @@ do_pack_uint32(char *buffer, unsigned int value) {
buffer[3] = (char)((value >> 24) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_uint64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_uint64(char *buffer, PN_uint64 value) {
buffer[0] = (char)(value & 0xff);
@ -243,11 +196,9 @@ do_pack_uint64(char *buffer, PN_uint64 value) {
buffer[7] = (char)((value >> 56) & 0xff);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_pack_float64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE void DCPackerInterface::
do_pack_float64(char *buffer, double value) {
#ifdef WORDS_BIGENDIAN
@ -262,32 +213,26 @@ do_pack_float64(char *buffer, double value) {
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_int8
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE int DCPackerInterface::
do_unpack_int8(const char *buffer) {
return (int)(signed char)buffer[0];
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_int16
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE int DCPackerInterface::
do_unpack_int16(const char *buffer) {
return (int)((unsigned int)(unsigned char)buffer[0] |
((int)(signed char)buffer[1] << 8));
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_int32
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE int DCPackerInterface::
do_unpack_int32(const char *buffer) {
return (int)((unsigned int)(unsigned char)buffer[0] |
@ -296,11 +241,9 @@ do_unpack_int32(const char *buffer) {
((int)(signed char)buffer[3] << 24));
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_int64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE PN_int64 DCPackerInterface::
do_unpack_int64(const char *buffer) {
return (PN_int64)((PN_uint64)(unsigned char)buffer[0] |
@ -312,32 +255,26 @@ do_unpack_int64(const char *buffer) {
((PN_uint64)(unsigned char)buffer[6] << 48) |
((PN_int64)(signed char)buffer[7] << 54));
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_uint8
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE unsigned int DCPackerInterface::
do_unpack_uint8(const char *buffer) {
return (unsigned int)(unsigned char)buffer[0];
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_uint16
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE unsigned int DCPackerInterface::
do_unpack_uint16(const char *buffer) {
return ((unsigned int)(unsigned char)buffer[0] |
((unsigned int)(unsigned char)buffer[1] << 8));
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_uint32
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE unsigned int DCPackerInterface::
do_unpack_uint32(const char *buffer) {
return ((unsigned int)(unsigned char)buffer[0] |
@ -346,11 +283,9 @@ do_unpack_uint32(const char *buffer) {
((unsigned int)(unsigned char)buffer[3] << 24));
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_uint64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE PN_uint64 DCPackerInterface::
do_unpack_uint64(const char *buffer) {
return ((PN_uint64)(unsigned char)buffer[0] |
@ -364,16 +299,14 @@ do_unpack_uint64(const char *buffer) {
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_unpack_float64
// Access: Public, Static
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
INLINE double DCPackerInterface::
do_unpack_float64(const char *buffer) {
#ifdef WORDS_BIGENDIAN
char reverse[8];
// Reverse the byte ordering for big-endian machines.
for (size_t i = 0; i < 8; i++) {
reverse[i] = buffer[7 - i];
@ -381,37 +314,33 @@ do_unpack_float64(const char *buffer) {
return *(double *)reverse;
#else
return *(double *)buffer;
#endif // WORDS_BIGENDIAN
#endif // WORDS_BIGENDIAN
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::validate_int_limits
// Access: Public, Static
// Description: Confirms that the signed value fits within num_bits
// bits. Sets range_error true if it does not.
////////////////////////////////////////////////////////////////////
/**
* Confirms that the signed value fits within num_bits bits. Sets range_error
* true if it does not.
*/
INLINE void DCPackerInterface::
validate_int_limits(int value, int num_bits, bool &range_error) {
// What we're really checking is that all of the bits above the
// lower (num_bits - 1) bits are the same--either all 1 or all 0.
// What we're really checking is that all of the bits above the lower
// (num_bits - 1) bits are the same--either all 1 or all 0.
// First, turn on the lower (num_bits - 1).
int mask = ((int)1 << (num_bits - 1)) - 1;
value |= mask;
// The result should be either mask (all high bits are 0) or -1 (all
// high bits are 1). If it is anything else we have a range error.
// The result should be either mask (all high bits are 0) or -1 (all high
// bits are 1). If it is anything else we have a range error.
if (value != mask && value != -1) {
range_error = true;
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::validate_int64_limits
// Access: Public, Static
// Description: Confirms that the signed value fits within num_bits
// bits. Sets range_error true if it does not.
////////////////////////////////////////////////////////////////////
/**
* Confirms that the signed value fits within num_bits bits. Sets range_error
* true if it does not.
*/
INLINE void DCPackerInterface::
validate_int64_limits(PN_int64 value, int num_bits, bool &range_error) {
PN_int64 mask = ((PN_int64)1 << (num_bits - 1)) - 1;
@ -422,16 +351,14 @@ validate_int64_limits(PN_int64 value, int num_bits, bool &range_error) {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::validate_uint_limits
// Access: Public, Static
// Description: Confirms that the unsigned value fits within num_bits
// bits. Sets range_error true if it does not.
////////////////////////////////////////////////////////////////////
/**
* Confirms that the unsigned value fits within num_bits bits. Sets
* range_error true if it does not.
*/
INLINE void DCPackerInterface::
validate_uint_limits(unsigned int value, int num_bits, bool &range_error) {
// Here we're really checking that all of the bits above the lower
// num_bits bits are all 0.
// Here we're really checking that all of the bits above the lower num_bits
// bits are all 0.
unsigned int mask = ((unsigned int)1 << num_bits) - 1;
value &= ~mask;
@ -441,12 +368,10 @@ validate_uint_limits(unsigned int value, int num_bits, bool &range_error) {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::validate_uint64_limits
// Access: Public, Static
// Description: Confirms that the unsigned value fits within num_bits
// bits. Sets range_error true if it does not.
////////////////////////////////////////////////////////////////////
/**
* Confirms that the unsigned value fits within num_bits bits. Sets
* range_error true if it does not.
*/
INLINE void DCPackerInterface::
validate_uint64_limits(PN_uint64 value, int num_bits, bool &range_error) {
PN_uint64 mask = ((PN_uint64)1 << num_bits) - 1;

View File

@ -1,16 +1,15 @@
// Filename: dcPackerInterface.cxx
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerInterface.cxx
* @author drose
* @date 2004-06-15
*/
#include "dcPackerInterface.h"
#include "dcPackerCatalog.h"
@ -18,11 +17,9 @@
#include "dcParserDefs.h"
#include "dcLexerDefs.h"
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCPackerInterface::
DCPackerInterface(const string &name) :
_name(name)
@ -38,11 +35,9 @@ DCPackerInterface(const string &name) :
_catalog = NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCPackerInterface::
DCPackerInterface(const DCPackerInterface &copy) :
_name(copy._name),
@ -58,11 +53,9 @@ DCPackerInterface(const DCPackerInterface &copy) :
_catalog = NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCPackerInterface::
~DCPackerInterface() {
if (_catalog != (DCPackerCatalog *)NULL) {
@ -70,99 +63,78 @@ DCPackerInterface::
}
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::find_seek_index
// Access: Published
// Description: Returns the index number to be passed to a future
// call to DCPacker::seek() to seek directly to the
// named field without having to look up the field name
// in a table later, or -1 if the named field cannot be
// found.
//
// If the named field is nested within a switch or some
// similar dynamic structure that reveals different
// fields based on the contents of the data, this
// mechanism cannot be used to pre-fetch the field index
// number--you must seek for the field by name.
////////////////////////////////////////////////////////////////////
/**
* Returns the index number to be passed to a future call to DCPacker::seek()
* to seek directly to the named field without having to look up the field
* name in a table later, or -1 if the named field cannot be found.
*
* If the named field is nested within a switch or some similar dynamic
* structure that reveals different fields based on the contents of the data,
* this mechanism cannot be used to pre-fetch the field index number--you must
* seek for the field by name.
*/
int DCPackerInterface::
find_seek_index(const string &name) const {
return get_catalog()->find_entry_by_name(name);
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_field
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCField *DCPackerInterface::
as_field() {
return (DCField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_field
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCField *DCPackerInterface::
as_field() const {
return (DCField *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitchParameter *DCPackerInterface::
as_switch_parameter() {
return (DCSwitchParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSwitchParameter *DCPackerInterface::
as_switch_parameter() const {
return (DCSwitchParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClassParameter *DCPackerInterface::
as_class_parameter() {
return (DCClassParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCClassParameter *DCPackerInterface::
as_class_parameter() const {
return (DCClassParameter *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::check_match
// Access: Published
// Description: Returns true if this interface is bitwise the same as
// the interface described with the indicated formatted
// string, e.g. "(uint8, uint8, int16)", or false
// otherwise.
//
// If DCFile is not NULL, it specifies the DCFile that
// was previously loaded, from which some predefined
// structs and typedefs may be referenced in the
// description string.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this interface is bitwise the same as the interface
* described with the indicated formatted string, e.g. "(uint8, uint8,
* int16)", or false otherwise.
*
* If DCFile is not NULL, it specifies the DCFile that was previously loaded,
* from which some predefined structs and typedefs may be referenced in the
* description string.
*/
bool DCPackerInterface::
check_match(const string &description, DCFile *dcfile) const {
bool match = false;
@ -186,214 +158,158 @@ check_match(const string &description, DCFile *dcfile) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::set_name
// Access: Public, Virtual
// Description: Sets the name of this field.
////////////////////////////////////////////////////////////////////
/**
* Sets the name of this field.
*/
void DCPackerInterface::
set_name(const string &name) {
_name = name;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::calc_num_nested_fields
// Access: Public, Virtual
// Description: This flavor of get_num_nested_fields is used during
// unpacking. It returns the number of nested fields to
// expect, given a certain length in bytes (as read from
// the _num_length_bytes stored in the stream on the
// push). This will only be called if _num_length_bytes
// is nonzero.
////////////////////////////////////////////////////////////////////
/**
* This flavor of get_num_nested_fields is used during unpacking. It returns
* the number of nested fields to expect, given a certain length in bytes (as
* read from the _num_length_bytes stored in the stream on the push). This
* will only be called if _num_length_bytes is nonzero.
*/
int DCPackerInterface::
calc_num_nested_fields(size_t) const {
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCPackerInterface::
get_nested_field(int) const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::validate_num_nested_fields
// Access: Public, Virtual
// Description: After a number of fields have been packed via push()
// .. pack_*() .. pop(), this is called to confirm that
// the number of nested fields that were added is valid
// for this type. This is primarily useful for array
// types with dynamic ranges that can't validate the
// number of fields any other way.
////////////////////////////////////////////////////////////////////
/**
* After a number of fields have been packed via push() .. pack_*() .. pop(),
* this is called to confirm that the number of nested fields that were added
* is valid for this type. This is primarily useful for array types with
* dynamic ranges that can't validate the number of fields any other way.
*/
bool DCPackerInterface::
validate_num_nested_fields(int) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_double
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_double(DCPackData &, double, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_int
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_int(DCPackData &, int, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_uint
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_uint(DCPackData &, unsigned int, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_int64
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_int64(DCPackData &, PN_int64, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_uint64
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_uint64(DCPackData &, PN_uint64, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_string
// Access: Public, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCPackerInterface::
pack_string(DCPackData &, const string &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::pack_default_value
// Access: Public, Virtual
// Description: Packs the field's specified default value (or a
// sensible default if no value is specified) into the
// stream. Returns true if the default value is packed,
// false if the field doesn't know how to pack its
// default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the field's specified default value (or a sensible default if no
* value is specified) into the stream. Returns true if the default value is
* packed, false if the field doesn't know how to pack its default value.
*/
bool DCPackerInterface::
pack_default_value(DCPackData &, bool &) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_double
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_double(const char *, size_t, size_t &, double &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_int
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_int(const char *, size_t, size_t &, int &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_uint
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_uint(const char *, size_t, size_t &, unsigned int &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_int64
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_int64(const char *, size_t, size_t &, PN_int64 &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_uint64
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_uint64(const char *, size_t, size_t &, PN_uint64 &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_string
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCPackerInterface::
unpack_string(const char *, size_t, size_t &, string &, bool &pack_error, bool &) const {
pack_error = true;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_validate
// Access: Public, Virtual
// Description: Internally unpacks the current numeric or string
// value and validates it against the type range limits,
// but does not return the value. Returns true on
// success, false on failure (e.g. we don't know how to
// validate this field).
////////////////////////////////////////////////////////////////////
/**
* Internally unpacks the current numeric or string value and validates it
* against the type range limits, but does not return the value. Returns true
* on success, false on failure (e.g. we don't know how to validate this
* field).
*/
bool DCPackerInterface::
unpack_validate(const char *data, size_t length, size_t &p,
bool &pack_error, bool &) const {
@ -403,14 +319,11 @@ unpack_validate(const char *data, size_t length, size_t &p,
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::unpack_skip
// Access: Public, Virtual
// Description: Increments p to the end of the current field without
// actually unpacking any data or performing any range
// validation. Returns true on success, false on
// failure (e.g. we don't know how to skip this field).
////////////////////////////////////////////////////////////////////
/**
* Increments p to the end of the current field without actually unpacking any
* data or performing any range validation. Returns true on success, false on
* failure (e.g. we don't know how to skip this field).
*/
bool DCPackerInterface::
unpack_skip(const char *data, size_t length, size_t &p,
bool &pack_error) const {
@ -427,7 +340,7 @@ unpack_skip(const char *data, size_t length, size_t &p,
// If we have a length prefix, use that for skipping.
if (p + _num_length_bytes > length) {
pack_error = true;
} else {
if (_num_length_bytes == 4) {
size_t this_length = do_unpack_uint32(data + p);
@ -443,17 +356,15 @@ unpack_skip(const char *data, size_t length, size_t &p,
return true;
}
// Otherwise, we don't know how to skip this field (presumably it
// can be skipped by skipping over its nested fields individually).
// Otherwise, we don't know how to skip this field (presumably it can be
// skipped by skipping over its nested fields individually).
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::get_catalog
// Access: Public
// Description: Returns the DCPackerCatalog associated with this
// field, listing all of the nested fields by name.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerCatalog associated with this field, listing all of the
* nested fields by name.
*/
const DCPackerCatalog *DCPackerInterface::
get_catalog() const {
if (_catalog == (DCPackerCatalog *)NULL) {
@ -462,78 +373,63 @@ get_catalog() const {
return _catalog;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_simple_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// simple parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated simple parameter, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_simple_parameter(const DCSimpleParameter *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_class_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// class parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated class parameter, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_class_parameter(const DCClassParameter *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_switch_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// switch parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated switch parameter, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_switch_parameter(const DCSwitchParameter *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_array_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// array parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated array parameter, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_array_parameter(const DCArrayParameter *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_atomic_field
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// atomic field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated atomic field, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_atomic_field(const DCAtomicField *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::do_check_match_molecular_field
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// molecular field, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated molecular field, false
* otherwise.
*/
bool DCPackerInterface::
do_check_match_molecular_field(const DCMolecularField *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCPackerInterface::make_catalog
// Access: Private
// Description: Called internally to create a new DCPackerCatalog
// object.
////////////////////////////////////////////////////////////////////
/**
* Called internally to create a new DCPackerCatalog object.
*/
void DCPackerInterface::
make_catalog() {
nassertv(_catalog == (DCPackerCatalog *)NULL);

View File

@ -1,16 +1,15 @@
// Filename: dcPackerInterface.h
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPackerInterface.h
* @author drose
* @date 2004-06-15
*/
#ifndef DCPACKERINTERFACE_H
#define DCPACKERINTERFACE_H
@ -30,16 +29,16 @@ class DCPackData;
class DCPackerCatalog;
BEGIN_PUBLISH
// This enumerated type is returned by get_pack_type() and represents
// the best choice for a subsequent call to pack_*() or unpack_*().
// This enumerated type is returned by get_pack_type() and represents the best
// choice for a subsequent call to pack_*() or unpack_*().
enum DCPackType {
// This one should never be returned in a normal situation.
PT_invalid,
// These PackTypes are all fundamental types, and should be packed
// (or unpacked) with the corresponding call to pack_double(),
// pack_int(), etc. PT_blob is the same as PT_string, but implies
// that the string contains binary data.
// These PackTypes are all fundamental types, and should be packed (or
// unpacked) with the corresponding call to pack_double(), pack_int(), etc.
// PT_blob is the same as PT_string, but implies that the string contains
// binary data.
PT_double,
PT_int,
PT_uint,
@ -48,9 +47,9 @@ enum DCPackType {
PT_string,
PT_blob,
// The remaining PackTypes imply a need to call push() and pop().
// They are all variants on the same thing: a list of nested fields,
// but the PackType provides a bit of a semantic context.
// The remaining PackTypes imply a need to call push() and pop(). They are
// all variants on the same thing: a list of nested fields, but the PackType
// provides a bit of a semantic context.
PT_array,
PT_field,
PT_class,
@ -58,16 +57,13 @@ enum DCPackType {
};
END_PUBLISH
////////////////////////////////////////////////////////////////////
// Class : DCPackerInterface
// Description : This defines the internal interface for packing
// values into a DCField. The various different DC
// objects inherit from this.
//
// Normally these methods are called only by the
// DCPacker object; the user wouldn't normally call
// these directly.
////////////////////////////////////////////////////////////////////
/**
* This defines the internal interface for packing values into a DCField. The
* various different DC objects inherit from this.
*
* Normally these methods are called only by the DCPacker object; the user
* wouldn't normally call these directly.
*/
class EXPCL_DIRECT DCPackerInterface {
public:
DCPackerInterface(const string &name = string());
@ -119,26 +115,26 @@ public:
bool &pack_error, bool &range_error) const;
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
virtual void unpack_double(const char *data, size_t length, size_t &p,
virtual void unpack_double(const char *data, size_t length, size_t &p,
double &value, bool &pack_error, bool &range_error) const;
virtual void unpack_int(const char *data, size_t length, size_t &p,
virtual void unpack_int(const char *data, size_t length, size_t &p,
int &value, bool &pack_error, bool &range_error) const;
virtual void unpack_uint(const char *data, size_t length, size_t &p,
virtual void unpack_uint(const char *data, size_t length, size_t &p,
unsigned int &value, bool &pack_error, bool &range_error) const;
virtual void unpack_int64(const char *data, size_t length, size_t &p,
virtual void unpack_int64(const char *data, size_t length, size_t &p,
PN_int64 &value, bool &pack_error, bool &range_error) const;
virtual void unpack_uint64(const char *data, size_t length, size_t &p,
virtual void unpack_uint64(const char *data, size_t length, size_t &p,
PN_uint64 &value, bool &pack_error, bool &range_error) const;
virtual void unpack_string(const char *data, size_t length, size_t &p,
virtual void unpack_string(const char *data, size_t length, size_t &p,
string &value, bool &pack_error, bool &range_error) const;
virtual bool unpack_validate(const char *data, size_t length, size_t &p,
virtual bool unpack_validate(const char *data, size_t length, size_t &p,
bool &pack_error, bool &range_error) const;
virtual bool unpack_skip(const char *data, size_t length, size_t &p,
bool &pack_error) const;
// These are the low-level interfaces for packing and unpacking
// numbers from a buffer. You're responsible for making sure the
// buffer has enough room, and for incrementing the pointer.
// These are the low-level interfaces for packing and unpacking numbers from
// a buffer. You're responsible for making sure the buffer has enough room,
// and for incrementing the pointer.
INLINE static void do_pack_int8(char *buffer, int value);
INLINE static void do_pack_int16(char *buffer, int value);
INLINE static void do_pack_int32(char *buffer, int value);
@ -159,13 +155,13 @@ public:
INLINE static PN_uint64 do_unpack_uint64(const char *buffer);
INLINE static double do_unpack_float64(const char *buffer);
INLINE static void validate_int_limits(int value, int num_bits,
INLINE static void validate_int_limits(int value, int num_bits,
bool &range_error);
INLINE static void validate_int64_limits(PN_int64 value, int num_bits,
INLINE static void validate_int64_limits(PN_int64 value, int num_bits,
bool &range_error);
INLINE static void validate_uint_limits(unsigned int value, int num_bits,
INLINE static void validate_uint_limits(unsigned int value, int num_bits,
bool &range_error);
INLINE static void validate_uint64_limits(PN_uint64 value, int num_bits,
INLINE static void validate_uint64_limits(PN_uint64 value, int num_bits,
bool &range_error);
const DCPackerCatalog *get_catalog() const;
@ -174,8 +170,8 @@ protected:
virtual bool do_check_match(const DCPackerInterface *other) const=0;
public:
// These are declared public just so the derived classes can call
// them easily. They're not intended to be called directly.
// These are declared public just so the derived classes can call them
// easily. They're not intended to be called directly.
virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const;
virtual bool do_check_match_class_parameter(const DCClassParameter *other) const;

View File

@ -1,16 +1,15 @@
// Filename: dcParameter.cxx
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcParameter.cxx
* @author drose
* @date 2004-06-15
*/
#include "dcParameter.h"
#include "dcArrayParameter.h"
@ -18,11 +17,9 @@
#include "dcindent.h"
#include "dcTypedef.h"
////////////////////////////////////////////////////////////////////
// Function: DCParameter::Constructor
// Access: Protected
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter::
DCParameter() {
_typedef = NULL;
@ -31,11 +28,9 @@ DCParameter() {
_num_nested_fields = -1;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::Copy Constructor
// Access: Protected
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter::
DCParameter(const DCParameter &copy) :
DCField(copy),
@ -43,157 +38,125 @@ DCParameter(const DCParameter &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter::
~DCParameter() {
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCParameter::
as_parameter() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCParameter *DCParameter::
as_parameter() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_simple_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSimpleParameter *DCParameter::
as_simple_parameter() {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_simple_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSimpleParameter *DCParameter::
as_simple_parameter() const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCClassParameter *DCParameter::
as_class_parameter() {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_class_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCClassParameter *DCParameter::
as_class_parameter() const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitchParameter *DCParameter::
as_switch_parameter() {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSwitchParameter *DCParameter::
as_switch_parameter() const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_array_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCArrayParameter *DCParameter::
as_array_parameter() {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::as_array_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCArrayParameter *DCParameter::
as_array_parameter() const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::get_typedef
// Access: Published
// Description: If this type has been referenced from a typedef,
// returns the DCTypedef instance, or NULL if the
// type was declared on-the-fly.
////////////////////////////////////////////////////////////////////
/**
* If this type has been referenced from a typedef, returns the DCTypedef
* instance, or NULL if the type was declared on-the-fly.
*/
const DCTypedef *DCParameter::
get_typedef() const {
return _typedef;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::set_typedef
// Access: Public
// Description: Records the DCTypedef object that generated this
// parameter. This is normally called only from
// DCTypedef::make_new_parameter().
////////////////////////////////////////////////////////////////////
/**
* Records the DCTypedef object that generated this parameter. This is
* normally called only from DCTypedef::make_new_parameter().
*/
void DCParameter::
set_typedef(const DCTypedef *dtypedef) {
_typedef = dtypedef;
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::append_array_specification
// Access: Public, Virtual
// Description: Returns the type represented by this_type[size].
//
// In the case of a generic DCParameter, this means it
// returns a DCArrayParameter wrapped around this type.
////////////////////////////////////////////////////////////////////
/**
* Returns the type represented by this_type[size].
*
* In the case of a generic DCParameter, this means it returns a
* DCArrayParameter wrapped around this type.
*/
DCParameter *DCParameter::
append_array_specification(const DCUnsignedIntRange &size) {
return new DCArrayParameter(this, size);
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCParameter::
output(ostream &out, bool brief) const {
string name;
@ -203,28 +166,23 @@ output(ostream &out, bool brief) const {
output_instance(out, brief, "", name, "");
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::write
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCParameter::
write(ostream &out, bool brief, int indent_level) const {
// we must always output the name when the parameter occurs by
// itself within a class, so we pass get_name() even if brief is
// true.
// we must always output the name when the parameter occurs by itself within
// a class, so we pass get_name() even if brief is true.
write_instance(out, brief, indent_level, "", get_name(), "");
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::write_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCParameter::
write_instance(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
const string &prename, const string &name,
const string &postname) const {
indent(out, indent_level);
output_instance(out, brief, prename, name, postname);
@ -236,12 +194,10 @@ write_instance(ostream &out, bool brief, int indent_level,
out << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::output_typedef_name
// Access: Public
// Description: Formats the instance like output_instance, but uses
// the typedef name instead.
////////////////////////////////////////////////////////////////////
/**
* Formats the instance like output_instance, but uses the typedef name
* instead.
*/
void DCParameter::
output_typedef_name(ostream &out, bool, const string &prename,
const string &name, const string &postname) const {
@ -251,15 +207,13 @@ output_typedef_name(ostream &out, bool, const string &prename,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::write_typedef_name
// Access: Public
// Description: Formats the instance like write_instance, but uses
// the typedef name instead.
////////////////////////////////////////////////////////////////////
/**
* Formats the instance like write_instance, but uses the typedef name
* instead.
*/
void DCParameter::
write_typedef_name(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
write_typedef_name(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
const string &postname) const {
indent(out, indent_level)
<< get_typedef()->get_name();
@ -274,16 +228,13 @@ write_typedef_name(ostream &out, bool brief, int indent_level,
out << "\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCParameter::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this type into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this type into the hash.
*/
void DCParameter::
generate_hash(HashGenerator &hashgen) const {
// We specifically don't call up to DCField::generate_hash(), since
// the parameter name is not actually significant to the hash.
// We specifically don't call up to DCField::generate_hash(), since the
// parameter name is not actually significant to the hash.
if (get_num_keywords() != 0) {
DCKeywordList::generate_hash(hashgen);

View File

@ -1,16 +1,15 @@
// Filename: dcParameter.h
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcParameter.h
* @author drose
* @date 2004-06-15
*/
#ifndef DCPARAMETER_H
#define DCPARAMETER_H
@ -25,17 +24,14 @@ class DCArrayParameter;
class DCTypedef;
class HashGenerator;
////////////////////////////////////////////////////////////////////
// Class : DCParameter
// Description : Represents the type specification for a single
// parameter within a field specification. This may be
// a simple type, or it may be a class or an array
// reference.
//
// This may also be a typedef reference to another type,
// which has the same properties as the referenced type,
// but a different name.
////////////////////////////////////////////////////////////////////
/**
* Represents the type specification for a single parameter within a field
* specification. This may be a simple type, or it may be a class or an array
* reference.
*
* This may also be a typedef reference to another type, which has the same
* properties as the referenced type, but a different name.
*/
class EXPCL_DIRECT DCParameter : public DCField {
protected:
DCParameter();
@ -66,15 +62,15 @@ public:
virtual void output(ostream &out, bool brief) const;
virtual void write(ostream &out, bool brief, int indent_level) const;
virtual void output_instance(ostream &out, bool brief, const string &prename,
virtual void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const=0;
virtual void write_instance(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
const string &postname) const;
void output_typedef_name(ostream &out, bool brief, const string &prename,
void output_typedef_name(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
void write_typedef_name(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
const string &prename, const string &name,
const string &postname) const;
virtual void generate_hash(HashGenerator &hashgen) const;

View File

@ -1,7 +1,8 @@
// Filename: dcParser.yxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
/**
* @file dcParser.yxx
* @author drose
* @date 2000-10-05
*/
%{
#include "dcLexerDefs.h"

View File

@ -1,16 +1,15 @@
// Filename: dcParserDefs.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcParserDefs.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCPARSERDEFS_H
#define DCPARSERDEFS_H
@ -28,7 +27,7 @@ class DCKeyword;
class DCPacker;
void dc_init_parser(istream &in, const string &filename, DCFile &file);
void dc_init_parser_parameter_value(istream &in, const string &filename,
void dc_init_parser_parameter_value(istream &in, const string &filename,
DCPacker &packer);
void dc_init_parser_parameter_description(istream &in, const string &filename,
DCFile *file);
@ -38,12 +37,11 @@ int dcyyparse();
extern DCFile *dc_file;
// This structure holds the return value for each token.
// Traditionally, this is a union, and is declared with the %union
// declaration in the parser.y file, but unions are pretty worthless
// in C++ (you can't include an object that has member functions in a
// union), so we'll use a class instead. That means we need to
// declare it externally, here.
// This structure holds the return value for each token. Traditionally, this
// is a union, and is declared with the %union declaration in the parser.y
// file, but unions are pretty worthless in C++ (you can't include an object
// that has member functions in a union), so we'll use a class instead. That
// means we need to declare it externally, here.
class DCTokenType {
public:
@ -65,8 +63,8 @@ public:
string str;
};
// The yacc-generated code expects to use the symbol 'YYSTYPE' to
// refer to the above class.
// The yacc-generated code expects to use the symbol 'YYSTYPE' to refer to the
// above class.
#define YYSTYPE DCTokenType
#endif

View File

@ -1,22 +1,21 @@
// Filename: dcPython.h
// Created by: drose (22Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcPython.h
* @author drose
* @date 2004-06-22
*/
#ifndef DCPYTHON_H
#define DCPYTHON_H
// The only purpose of this file is to serve as a common place to put
// the nonsense associated with #including <Python.h>.
// The only purpose of this file is to serve as a common place to put the
// nonsense associated with #including <Python.h>.
#ifdef HAVE_PYTHON
@ -33,8 +32,8 @@ typedef int Py_ssize_t;
#define PY_SSIZE_T_MIN INT_MIN
#endif
// Several interfaces in this module that use Python also require
// these header files, so we might as well pick them up too.
// Several interfaces in this module that use Python also require these header
// files, so we might as well pick them up too.
#include "datagram.h"
#include "datagramIterator.h"

View File

@ -1,16 +1,15 @@
// Filename: dcSimpleParameter.cxx
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSimpleParameter.cxx
* @author drose
* @date 2004-06-15
*/
#include "dcSimpleParameter.h"
#include "dcPackData.h"
@ -24,11 +23,9 @@
DCSimpleParameter::NestedFieldMap DCSimpleParameter::_nested_field_map;
DCClassParameter *DCSimpleParameter::_uint32uint8_type = NULL;
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSimpleParameter::
DCSimpleParameter(DCSubatomicType type, unsigned int divisor) :
_type(type),
@ -41,9 +38,9 @@ DCSimpleParameter(DCSubatomicType type, unsigned int divisor) :
_bytes_per_element = 0;
_num_length_bytes = 2;
// Check for one of the built-in array types. For these types, we
// must present a packing interface that has a variable number of
// nested fields of the appropriate type.
// Check for one of the built-in array types. For these types, we must
// present a packing interface that has a variable number of nested fields
// of the appropriate type.
switch (_type) {
case ST_int8array:
_pack_type = PT_array;
@ -97,16 +94,15 @@ DCSimpleParameter(DCSubatomicType type, unsigned int divisor) :
_num_length_bytes = 4;
// fall through
case ST_blob:
// For blob and string, we will present an array interface
// as an array of uint8, but we will also accept a set_value()
// with a string parameter.
// For blob and string, we will present an array interface as an array of
// uint8, but we will also accept a set_value() with a string parameter.
_pack_type = PT_blob;
_nested_type = ST_uint8;
_has_nested_fields = true;
_bytes_per_element = 1;
break;
case ST_string:
case ST_string:
_pack_type = PT_string;
_nested_type = ST_char;
_has_nested_fields = true;
@ -185,9 +181,8 @@ DCSimpleParameter(DCSubatomicType type, unsigned int divisor) :
_nested_field = create_nested_field(_nested_type, _divisor);
} else if (_type == ST_uint32uint8array) {
// This one is a special case. We must create a special nested
// type that accepts a uint32 followed by a uint8 for each
// element.
// This one is a special case. We must create a special nested type that
// accepts a uint32 followed by a uint8 for each element.
_nested_field = create_uint32uint8_type();
} else {
@ -195,11 +190,9 @@ DCSimpleParameter(DCSubatomicType type, unsigned int divisor) :
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSimpleParameter::
DCSimpleParameter(const DCSimpleParameter &copy) :
DCParameter(copy),
@ -221,123 +214,94 @@ DCSimpleParameter(const DCSimpleParameter &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::as_simple_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSimpleParameter *DCSimpleParameter::
as_simple_parameter() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::as_simple_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSimpleParameter *DCSimpleParameter::
as_simple_parameter() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::make_copy
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCSimpleParameter::
make_copy() const {
return new DCSimpleParameter(*this);
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::is_valid
// Access: Published, Virtual
// Description: Returns false if the type is an invalid type
// (e.g. declared from an undefined typedef), true if
// it is valid.
////////////////////////////////////////////////////////////////////
/**
* Returns false if the type is an invalid type (e.g. declared from an
* undefined typedef), true if it is valid.
*/
bool DCSimpleParameter::
is_valid() const {
return _type != ST_invalid;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::get_type
// Access: Published
// Description: Returns the particular subatomic type represented by
// this instance.
////////////////////////////////////////////////////////////////////
/**
* Returns the particular subatomic type represented by this instance.
*/
DCSubatomicType DCSimpleParameter::
get_type() const {
return _type;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::has_modulus
// Access: Published
// Description: Returns true if there is a modulus associated, false
// otherwise.,
////////////////////////////////////////////////////////////////////
/**
* Returns true if there is a modulus associated, false otherwise.,
*/
bool DCSimpleParameter::
has_modulus() const {
return _has_modulus;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::get_modulus
// Access: Published
// Description: Returns the modulus associated with this type, if
// any. It is an error to call this if has_modulus()
// returned false.
//
// If present, this is the modulus that is used to
// constrain the numeric value of the field before it is
// packed (and range-checked).
////////////////////////////////////////////////////////////////////
/**
* Returns the modulus associated with this type, if any. It is an error to
* call this if has_modulus() returned false.
*
* If present, this is the modulus that is used to constrain the numeric value
* of the field before it is packed (and range-checked).
*/
double DCSimpleParameter::
get_modulus() const {
return _orig_modulus;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::get_divisor
// Access: Published
// Description: Returns the divisor associated with this type. This
// is 1 by default, but if this is other than one it
// represents the scale to apply when packing and
// unpacking numeric values (to store fixed-point values
// in an integer field). It is only meaningful for
// numeric-type fields.
////////////////////////////////////////////////////////////////////
/**
* Returns the divisor associated with this type. This is 1 by default, but
* if this is other than one it represents the scale to apply when packing and
* unpacking numeric values (to store fixed-point values in an integer field).
* It is only meaningful for numeric-type fields.
*/
int DCSimpleParameter::
get_divisor() const {
return _divisor;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::is_numeric_type
// Access: Public
// Description: Returns true if the type is a numeric type (and
// therefore can accept a divisor and/or a modulus), or
// false if it is some string-based type.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the type is a numeric type (and therefore can accept a
* divisor and/or a modulus), or false if it is some string-based type.
*/
bool DCSimpleParameter::
is_numeric_type() const {
return !(_pack_type == PT_string || _pack_type == PT_blob);
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::set_modulus
// Access: Public
// Description: Assigns the indicated modulus to the simple type.
// Any packed value will be constrained to be within [0,
// modulus).
//
// Returns true if assigned, false if this type cannot
// accept a modulus or if the modulus is invalid.
////////////////////////////////////////////////////////////////////
/**
* Assigns the indicated modulus to the simple type. Any packed value will be
* constrained to be within [0, modulus).
*
* Returns true if assigned, false if this type cannot accept a modulus or if
* the modulus is invalid.
*/
bool DCSimpleParameter::
set_modulus(double modulus) {
if (_pack_type == PT_string || _pack_type == PT_blob || modulus <= 0.0) {
@ -352,8 +316,8 @@ set_modulus(double modulus) {
_uint64_modulus = (PN_uint64)floor(_double_modulus + 0.5);
_uint_modulus = (unsigned int)_uint64_modulus;
// Check the range. The legitimate range for a modulus value is 1
// through (maximum_value + 1).
// Check the range. The legitimate range for a modulus value is 1 through
// (maximum_value + 1).
switch (_type) {
case ST_int8:
case ST_int8array:
@ -369,7 +333,7 @@ set_modulus(double modulus) {
case ST_int32array:
validate_uint64_limits(_uint64_modulus - 1, 31, range_error);
break;
case ST_int64:
validate_uint64_limits(_uint64_modulus - 1, 63, range_error);
break;
@ -389,7 +353,7 @@ set_modulus(double modulus) {
case ST_uint32array:
validate_uint64_limits(_uint64_modulus - 1, 32, range_error);
break;
case ST_uint64:
case ST_float64:
break;
@ -401,13 +365,11 @@ set_modulus(double modulus) {
return !range_error;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::set_divisor
// Access: Public
// Description: Assigns the indicated divisor to the simple type.
// Returns true if assigned, false if this type cannot
// accept a divisor or if the divisor is invalid.
////////////////////////////////////////////////////////////////////
/**
* Assigns the indicated divisor to the simple type. Returns true if
* assigned, false if this type cannot accept a divisor or if the divisor is
* invalid.
*/
bool DCSimpleParameter::
set_divisor(unsigned int divisor) {
if (_pack_type == PT_string || _pack_type == PT_blob || divisor == 0) {
@ -431,16 +393,12 @@ set_divisor(unsigned int divisor) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::set_range
// Access: Public
// Description: Sets the parameter with the indicated range. A
// DCDoubleRange is used for specification, since this
// is the most generic type; but it is converted to the
// appropriate type internally. The return value is
// true if successful, or false if the range is
// inappropriate for the type.
////////////////////////////////////////////////////////////////////
/**
* Sets the parameter with the indicated range. A DCDoubleRange is used for
* specification, since this is the most generic type; but it is converted to
* the appropriate type internally. The return value is true if successful,
* or false if the range is inappropriate for the type.
*/
bool DCSimpleParameter::
set_range(const DCDoubleRange &range) {
bool range_error = false;
@ -462,7 +420,7 @@ set_range(const DCDoubleRange &range) {
_int_range.add_range((int)min, (int)max);
}
break;
case ST_int16:
case ST_int16array:
_int_range.clear();
@ -474,7 +432,7 @@ set_range(const DCDoubleRange &range) {
_int_range.add_range((int)min, (int)max);
}
break;
case ST_int32:
case ST_int32array:
_int_range.clear();
@ -486,7 +444,7 @@ set_range(const DCDoubleRange &range) {
_int_range.add_range((int)min, (int)max);
}
break;
case ST_int64:
_int64_range.clear();
for (i = 0; i < num_ranges; i++) {
@ -495,7 +453,7 @@ set_range(const DCDoubleRange &range) {
_int64_range.add_range(min, max);
}
break;
case ST_char:
case ST_uint8:
case ST_uint8array:
@ -508,7 +466,7 @@ set_range(const DCDoubleRange &range) {
_uint_range.add_range((unsigned int)min, (unsigned int)max);
}
break;
case ST_uint16:
case ST_uint16array:
_uint_range.clear();
@ -520,7 +478,7 @@ set_range(const DCDoubleRange &range) {
_uint_range.add_range((unsigned int)min, (unsigned int)max);
}
break;
case ST_uint32:
case ST_uint32array:
_uint_range.clear();
@ -532,7 +490,7 @@ set_range(const DCDoubleRange &range) {
_uint_range.add_range((unsigned int)min, (unsigned int)max);
}
break;
case ST_uint64:
_uint64_range.clear();
for (i = 0; i < num_ranges; i++) {
@ -562,8 +520,8 @@ set_range(const DCDoubleRange &range) {
_uint_range.add_range((unsigned int)min, (unsigned int)max);
}
if (_uint_range.has_one_value()) {
// If we now have a fixed-length string requirement, we don't
// need a leading number of bytes.
// If we now have a fixed-length string requirement, we don't need a
// leading number of bytes.
_num_length_bytes = 0;
_has_fixed_byte_size = true;
_fixed_byte_size = _uint_range.get_one_value();
@ -585,8 +543,8 @@ set_range(const DCDoubleRange &range) {
_uint_range.add_range((unsigned int)min, (unsigned int)max);
}
if (_uint_range.has_one_value()) {
// If we now have a fixed-length string requirement, we don't
// need a leading number of bytes.
// If we now have a fixed-length string requirement, we don't need a
// leading number of bytes.
_num_length_bytes = 0;
_has_fixed_byte_size = true;
_fixed_byte_size = _uint_range.get_one_value();
@ -605,16 +563,12 @@ set_range(const DCDoubleRange &range) {
return !range_error;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::calc_num_nested_fields
// Access: Public, Virtual
// Description: This flavor of get_num_nested_fields is used during
// unpacking. It returns the number of nested fields to
// expect, given a certain length in bytes (as read from
// the _num_length_bytes stored in the stream on the
// push). This will only be called if _num_length_bytes
// is nonzero.
////////////////////////////////////////////////////////////////////
/**
* This flavor of get_num_nested_fields is used during unpacking. It returns
* the number of nested fields to expect, given a certain length in bytes (as
* read from the _num_length_bytes stored in the stream on the push). This
* will only be called if _num_length_bytes is nonzero.
*/
int DCSimpleParameter::
calc_num_nested_fields(size_t length_bytes) const {
if (_bytes_per_element != 0) {
@ -623,25 +577,19 @@ calc_num_nested_fields(size_t length_bytes) const {
return 0;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCSimpleParameter::
get_nested_field(int) const {
return _nested_field;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_double
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_double(DCPackData &pack_data, double value,
bool &pack_error, bool &range_error) const {
@ -675,7 +623,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_int16(pack_data.get_write_pointer(2), int_value);
}
break;
case ST_int32:
{
int int_value = (int)floor(real_value + 0.5);
@ -683,7 +631,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_int32(pack_data.get_write_pointer(4), int_value);
}
break;
case ST_int64:
{
PN_int64 int64_value = (PN_int64)floor(real_value + 0.5);
@ -691,7 +639,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_int64(pack_data.get_write_pointer(8), int64_value);
}
break;
case ST_char:
case ST_uint8:
{
@ -701,7 +649,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_uint8(pack_data.get_write_pointer(1), int_value);
}
break;
case ST_uint16:
{
unsigned int int_value = (unsigned int)floor(real_value + 0.5);
@ -710,7 +658,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_uint16(pack_data.get_write_pointer(2), int_value);
}
break;
case ST_uint32:
{
unsigned int int_value = (unsigned int)floor(real_value + 0.5);
@ -718,7 +666,7 @@ pack_double(DCPackData &pack_data, double value,
do_pack_uint32(pack_data.get_write_pointer(4), int_value);
}
break;
case ST_uint64:
{
PN_uint64 int64_value = (PN_uint64)floor(real_value + 0.5);
@ -737,20 +685,17 @@ pack_double(DCPackData &pack_data, double value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_int
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_int(DCPackData &pack_data, int value,
bool &pack_error, bool &range_error) const {
int int_value = value * _divisor;
if (value != 0 && (int_value / value) != (int)_divisor) {
// If we've experienced overflow after applying the divisor, pack
// it as an int64 instead.
// If we've experienced overflow after applying the divisor, pack it as an
// int64 instead.
pack_int64(pack_data, (PN_int64)value, pack_error, range_error);
return;
}
@ -831,12 +776,9 @@ pack_int(DCPackData &pack_data, int value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_uint
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_uint(DCPackData &pack_data, unsigned int value,
bool &pack_error, bool &range_error) const {
@ -913,12 +855,9 @@ pack_uint(DCPackData &pack_data, unsigned int value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_int64
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_int64(DCPackData &pack_data, PN_int64 value,
bool &pack_error, bool &range_error) const {
@ -1001,12 +940,9 @@ pack_int64(DCPackData &pack_data, PN_int64 value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_uint64
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_uint64(DCPackData &pack_data, PN_uint64 value,
bool &pack_error, bool &range_error) const {
@ -1085,12 +1021,9 @@ pack_uint64(DCPackData &pack_data, PN_uint64 value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_string
// Access: Published, Virtual
// Description: Packs the indicated numeric or string value into the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Packs the indicated numeric or string value into the stream.
*/
void DCSimpleParameter::
pack_string(DCPackData &pack_data, const string &value,
bool &pack_error, bool &range_error) const {
@ -1134,15 +1067,12 @@ pack_string(DCPackData &pack_data, const string &value,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::pack_default_value
// Access: Public, Virtual
// Description: Packs the simpleParameter's specified default value (or a
// sensible default if no value is specified) into the
// stream. Returns true if the default value is packed,
// false if the simpleParameter doesn't know how to pack its
// default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the simpleParameter's specified default value (or a sensible default
* if no value is specified) into the stream. Returns true if the default
* value is packed, false if the simpleParameter doesn't know how to pack its
* default value.
*/
bool DCSimpleParameter::
pack_default_value(DCPackData &pack_data, bool &pack_error) const {
if (has_default_value()) {
@ -1150,15 +1080,15 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
}
if (_has_nested_fields) {
// If the simple type is an array (or string) type, pack the
// appropriate length array, with code similar to
// If the simple type is an array (or string) type, pack the appropriate
// length array, with code similar to
// DCArrayParameter::pack_default_value().
unsigned int minimum_length = 0;
if (!_uint_range.is_empty()) {
minimum_length = _uint_range.get_min(0);
}
DCPacker packer;
packer.begin_pack(this);
packer.push();
@ -1168,14 +1098,14 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
packer.pop();
if (!packer.end_pack()) {
pack_error = true;
} else {
pack_data.append_data(packer.get_data(), packer.get_length());
}
} else {
// Otherwise, if it's just a simple numeric type, pack a zero or
// the minimum value.
// Otherwise, if it's just a simple numeric type, pack a zero or the
// minimum value.
switch (_type) {
case ST_int8:
case ST_int16:
@ -1213,7 +1143,7 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
pack_uint64(pack_data, _uint64_range.get_min(0), pack_error, pack_error);
}
break;
case ST_float64:
if (_double_range.is_in_range(0.0)) {
pack_double(pack_data, 0.0, pack_error, pack_error);
@ -1221,7 +1151,7 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
pack_double(pack_data, _double_range.get_min(0), pack_error, pack_error);
}
break;
default:
pack_error = true;
}
@ -1231,12 +1161,9 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_double
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_double(const char *data, size_t length, size_t &p, double &value,
bool &pack_error, bool &range_error) const {
@ -1370,12 +1297,9 @@ unpack_double(const char *data, size_t length, size_t &p, double &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_int
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_int(const char *data, size_t length, size_t &p, int &value,
bool &pack_error, bool &range_error) const {
@ -1511,12 +1435,9 @@ unpack_int(const char *data, size_t length, size_t &p, int &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_uint
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_uint(const char *data, size_t length, size_t &p, unsigned int &value,
bool &pack_error, bool &range_error) const {
@ -1660,12 +1581,9 @@ unpack_uint(const char *data, size_t length, size_t &p, unsigned int &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_int64
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value,
bool &pack_error, bool &range_error) const {
@ -1800,12 +1718,9 @@ unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_uint64
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_uint64(const char *data, size_t length, size_t &p, PN_uint64 &value,
bool &pack_error, bool &range_error) const {
@ -1949,12 +1864,9 @@ unpack_uint64(const char *data, size_t length, size_t &p, PN_uint64 &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_string
// Access: Public, Virtual
// Description: Unpacks the current numeric or string value from the
// stream.
////////////////////////////////////////////////////////////////////
/**
* Unpacks the current numeric or string value from the stream.
*/
void DCSimpleParameter::
unpack_string(const char *data, size_t length, size_t &p, string &value,
bool &pack_error, bool &range_error) const {
@ -1995,7 +1907,7 @@ unpack_string(const char *data, size_t length, size_t &p, string &value,
string_length = do_unpack_uint16(data + p);
p += 2;
break;
case ST_blob32:
if (p + 4 > length) {
pack_error = true;
@ -2004,7 +1916,7 @@ unpack_string(const char *data, size_t length, size_t &p, string &value,
string_length = do_unpack_uint32(data + p);
p += 4;
break;
default:
pack_error = true;
return;
@ -2023,18 +1935,15 @@ unpack_string(const char *data, size_t length, size_t &p, string &value,
return;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_validate
// Access: Public, Virtual
// Description: Internally unpacks the current numeric or string
// value and validates it against the type range limits,
// but does not return the value. Returns true on
// success, false on failure (e.g. we don't know how to
// validate this field).
////////////////////////////////////////////////////////////////////
/**
* Internally unpacks the current numeric or string value and validates it
* against the type range limits, but does not return the value. Returns true
* on success, false on failure (e.g. we don't know how to validate this
* field).
*/
bool DCSimpleParameter::
unpack_validate(const char *data, size_t length, size_t &p,
bool &pack_error, bool &range_error) const {
bool &pack_error, bool &range_error) const {
if (!_has_range_limits) {
return unpack_skip(data, length, p, pack_error);
}
@ -2186,16 +2095,13 @@ unpack_validate(const char *data, size_t length, size_t &p,
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::unpack_skip
// Access: Public, Virtual
// Description: Increments p to the end of the current field without
// actually unpacking any data or performing any range
// validation. Returns true on success, false on
// failure (e.g. we don't know how to skip this field).
////////////////////////////////////////////////////////////////////
/**
* Increments p to the end of the current field without actually unpacking any
* data or performing any range validation. Returns true on success, false on
* failure (e.g. we don't know how to skip this field).
*/
bool DCSimpleParameter::
unpack_skip(const char *data, size_t length, size_t &p,
unpack_skip(const char *data, size_t length, size_t &p,
bool &pack_error) const {
size_t string_length;
@ -2260,12 +2166,10 @@ unpack_skip(const char *data, size_t length, size_t &p,
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::output_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCSimpleParameter::
output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const {
@ -2291,7 +2195,7 @@ output_instance(ostream &out, bool brief, const string &prename,
out << ")";
}
break;
case ST_int64:
if (!_int64_range.is_empty()) {
out << "(";
@ -2299,7 +2203,7 @@ output_instance(ostream &out, bool brief, const string &prename,
out << ")";
}
break;
case ST_uint8:
case ST_uint16:
case ST_uint32:
@ -2317,7 +2221,7 @@ output_instance(ostream &out, bool brief, const string &prename,
out << ")";
}
break;
case ST_uint64:
if (!_uint64_range.is_empty()) {
out << "(";
@ -2351,12 +2255,9 @@ output_instance(ostream &out, bool brief, const string &prename,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this type into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this type into the hash.
*/
void DCSimpleParameter::
generate_hash(HashGenerator &hashgen) const {
DCParameter::generate_hash(hashgen);
@ -2374,25 +2275,20 @@ generate_hash(HashGenerator &hashgen) const {
_double_range.generate_hash(hashgen);
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCSimpleParameter::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_simple_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::do_check_match_simple_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// simple parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated simple parameter, false
* otherwise.
*/
bool DCSimpleParameter::
do_check_match_simple_parameter(const DCSimpleParameter *other) const {
if (_divisor != other->_divisor) {
@ -2403,8 +2299,7 @@ do_check_match_simple_parameter(const DCSimpleParameter *other) const {
return true;
}
// Check for certain types that are considered equivalent to each
// other.
// Check for certain types that are considered equivalent to each other.
switch (_type) {
case ST_uint8:
case ST_char:
@ -2435,12 +2330,10 @@ do_check_match_simple_parameter(const DCSimpleParameter *other) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::do_check_match_array_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// array parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated array parameter, false
* otherwise.
*/
bool DCSimpleParameter::
do_check_match_array_parameter(const DCArrayParameter *other) const {
if (other->get_array_size() != -1) {
@ -2455,13 +2348,10 @@ do_check_match_array_parameter(const DCArrayParameter *other) const {
return _nested_field->check_match(other->get_element_type());
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::create_nested_field
// Access: Private, Static
// Description: Creates the one instance of the DCSimpleParameter
// corresponding to this combination of type and divisor
// if it is not already created.
////////////////////////////////////////////////////////////////////
/**
* Creates the one instance of the DCSimpleParameter corresponding to this
* combination of type and divisor if it is not already created.
*/
DCSimpleParameter *DCSimpleParameter::
create_nested_field(DCSubatomicType type, unsigned int divisor) {
DivisorMap &divisor_map = _nested_field_map[type];
@ -2476,12 +2366,10 @@ create_nested_field(DCSubatomicType type, unsigned int divisor) {
return nested_field;
}
////////////////////////////////////////////////////////////////////
// Function: DCSimpleParameter::create_uint32uint8_type
// Access: Private, Static
// Description: Creates the one instance of the Uint32Uint8Type
// object if it is not already created.
////////////////////////////////////////////////////////////////////
/**
* Creates the one instance of the Uint32Uint8Type object if it is not already
* created.
*/
DCPackerInterface *DCSimpleParameter::
create_uint32uint8_type() {
if (_uint32uint8_type == NULL) {

View File

@ -1,16 +1,15 @@
// Filename: dcSimpleParameter.h
// Created by: drose (15Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSimpleParameter.h
* @author drose
* @date 2004-06-15
*/
#ifndef DCSIMPLEPARAMETER_H
#define DCSIMPLEPARAMETER_H
@ -20,15 +19,12 @@
#include "dcSubatomicType.h"
#include "dcNumericRange.h"
////////////////////////////////////////////////////////////////////
// Class : DCSimpleParameter
// Description : This is the most fundamental kind of parameter type:
// a single number or string, one of the DCSubatomicType
// elements. It may also optionally have a divisor,
// which is meaningful only for the numeric type
// elements (and represents a fixed-point numeric
// convention).
////////////////////////////////////////////////////////////////////
/**
* This is the most fundamental kind of parameter type: a single number or
* string, one of the DCSubatomicType elements. It may also optionally have a
* divisor, which is meaningful only for the numeric type elements (and
* represents a fixed-point numeric convention).
*/
class EXPCL_DIRECT DCSimpleParameter : public DCParameter {
public:
DCSimpleParameter(DCSubatomicType type, unsigned int divisor = 1);
@ -68,24 +64,24 @@ public:
bool &pack_error, bool &range_error) const;
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
virtual void unpack_double(const char *data, size_t length, size_t &p,
virtual void unpack_double(const char *data, size_t length, size_t &p,
double &value, bool &pack_error, bool &range_error) const;
virtual void unpack_int(const char *data, size_t length, size_t &p,
virtual void unpack_int(const char *data, size_t length, size_t &p,
int &value, bool &pack_error, bool &range_error) const;
virtual void unpack_uint(const char *data, size_t length, size_t &p,
virtual void unpack_uint(const char *data, size_t length, size_t &p,
unsigned int &value, bool &pack_error, bool &range_error) const;
virtual void unpack_int64(const char *data, size_t length, size_t &p,
virtual void unpack_int64(const char *data, size_t length, size_t &p,
PN_int64 &value, bool &pack_error, bool &range_error) const;
virtual void unpack_uint64(const char *data, size_t length, size_t &p,
virtual void unpack_uint64(const char *data, size_t length, size_t &p,
PN_uint64 &value, bool &pack_error, bool &range_error) const;
virtual void unpack_string(const char *data, size_t length, size_t &p,
virtual void unpack_string(const char *data, size_t length, size_t &p,
string &value, bool &pack_error, bool &range_error) const;
virtual bool unpack_validate(const char *data, size_t length, size_t &p,
virtual bool unpack_validate(const char *data, size_t length, size_t &p,
bool &pack_error, bool &range_error) const;
virtual bool unpack_skip(const char *data, size_t length, size_t &p,
bool &pack_error) const;
virtual void output_instance(ostream &out, bool brief, const string &prename,
virtual void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
virtual void generate_hash(HashGenerator &hashgen) const;
@ -95,7 +91,7 @@ protected:
virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const;
private:
static DCSimpleParameter *create_nested_field(DCSubatomicType type,
static DCSimpleParameter *create_nested_field(DCSubatomicType type,
unsigned int divisor);
static DCPackerInterface *create_uint32uint8_type();
@ -107,15 +103,15 @@ private:
DCPackerInterface *_nested_field;
size_t _bytes_per_element;
// The rest of this is to maintain the static list of
// DCPackerInterface objects for _nested_field, above. We allocate
// each possible object once, and don't delete it.
// The rest of this is to maintain the static list of DCPackerInterface
// objects for _nested_field, above. We allocate each possible object once,
// and don't delete it.
typedef pmap<unsigned int, DCSimpleParameter *> DivisorMap;
typedef pmap<DCSubatomicType, DivisorMap> NestedFieldMap;
static NestedFieldMap _nested_field_map;
// These are the range and modulus values as specified by the user,
// unscaled by the divisor.
// These are the range and modulus values as specified by the user, unscaled
// by the divisor.
DCDoubleRange _orig_range;
bool _has_modulus;
double _orig_modulus;
@ -127,8 +123,7 @@ private:
DCUnsignedInt64Range _uint64_range;
DCDoubleRange _double_range;
// All of these modulus values will be filled in, regardless of the
// type.
// All of these modulus values will be filled in, regardless of the type.
unsigned int _uint_modulus;
PN_uint64 _uint64_modulus;
double _double_modulus;

View File

@ -1,16 +1,15 @@
// Filename: dcSubatomicType.cxx
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSubatomicType.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcSubatomicType.h"

View File

@ -1,16 +1,15 @@
// Filename: dcSubatomicType.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSubatomicType.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCSUBATOMICTYPE_H
#define DCSUBATOMICTYPE_H
@ -18,13 +17,11 @@
#include "dcbase.h"
BEGIN_PUBLISH
////////////////////////////////////////////////////////////////////
// Enum : DCSubatomicType
// Description : This defines the numeric type of each element of a
// DCAtomicField; that is, the particular values that
// will get added to the message when the atomic field
// method is called.
////////////////////////////////////////////////////////////////////
/**
* This defines the numeric type of each element of a DCAtomicField; that is,
* the particular values that will get added to the message when the atomic
* field method is called.
*/
enum DCSubatomicType {
ST_int8,
ST_int16,
@ -49,16 +46,15 @@ enum DCSubatomicType {
ST_int8array,
ST_uint8array,
// A special-purpose array: a list of alternating uint32 and uint8
// values. In Python, this becomes a list of 2-tuples.
// A special-purpose array: a list of alternating uint32 and uint8 values.
// In Python, this becomes a list of 2-tuples.
ST_uint32uint8array,
// Equivalent to uint8, except that it suggests a pack_type of
// PT_string.
// Equivalent to uint8, except that it suggests a pack_type of PT_string.
ST_char,
// New additions should be added at the end to prevent the file hash
// code from changing.
// New additions should be added at the end to prevent the file hash code
// from changing.
ST_invalid
};
@ -67,5 +63,3 @@ END_PUBLISH
ostream &operator << (ostream &out, DCSubatomicType type);
#endif

View File

@ -1,16 +1,15 @@
// Filename: dcSwitch.cxx
// Created by: drose (23Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSwitch.cxx
* @author drose
* @date 2004-06-23
*/
#include "dcSwitch.h"
#include "dcField.h"
@ -19,13 +18,10 @@
#include "dcindent.h"
#include "dcPacker.h"
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::Constructor
// Access: Public
// Description: The key_parameter must be recently allocated via
// new; it will be deleted via delete when the switch
// destructs.
////////////////////////////////////////////////////////////////////
/**
* The key_parameter must be recently allocated via new; it will be deleted
* via delete when the switch destructs.
*/
DCSwitch::
DCSwitch(const string &name, DCField *key_parameter) :
_name(name),
@ -35,11 +31,9 @@ DCSwitch(const string &name, DCField *key_parameter) :
_fields_added = false;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch::
~DCSwitch() {
nassertv(_key_parameter != (DCField *)NULL);
@ -64,68 +58,53 @@ DCSwitch::
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::as_switch
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch *DCSwitch::
as_switch() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::as_switch
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSwitch *DCSwitch::
as_switch() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_name
// Access: Published
// Description: Returns the name of this switch.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of this switch.
*/
const string &DCSwitch::
get_name() const {
return _name;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_key_parameter
// Access: Published
// Description: Returns the key parameter on which the switch is
// based. The value of this parameter in the record
// determines which one of the several cases within the
// switch will be used.
////////////////////////////////////////////////////////////////////
/**
* Returns the key parameter on which the switch is based. The value of this
* parameter in the record determines which one of the several cases within
* the switch will be used.
*/
DCField *DCSwitch::
get_key_parameter() const {
return _key_parameter;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_num_cases
// Access: Published
// Description: Returns the number of different cases within the
// switch. The legal values for case_index range from 0
// to get_num_cases() - 1.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of different cases within the switch. The legal values
* for case_index range from 0 to get_num_cases() - 1.
*/
int DCSwitch::
get_num_cases() const {
return _cases.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_case_by_value
// Access: Published
// Description: Returns the index number of the case with the
// indicated packed value, or -1 if no case has this
// value.
////////////////////////////////////////////////////////////////////
/**
* Returns the index number of the case with the indicated packed value, or -1
* if no case has this value.
*/
int DCSwitch::
get_case_by_value(const string &case_value) const {
CasesByValue::const_iterator vi;
@ -137,56 +116,45 @@ get_case_by_value(const string &case_value) const {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_case
// Access: Published
// Description: Returns the DCPackerInterface that packs the nth case.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface that packs the nth case.
*/
DCPackerInterface *DCSwitch::
get_case(int n) const {
nassertr(n >= 0 && n < (int)_cases.size(), NULL);
return _cases[n]->_fields;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_default_case
// Access: Published
// Description: Returns the DCPackerInterface that packs the default
// case, or NULL if there is no default case.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface that packs the default case, or NULL if there
* is no default case.
*/
DCPackerInterface *DCSwitch::
get_default_case() const {
return _default_case;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_value
// Access: Published
// Description: Returns the packed value associated with the
// indicated case.
////////////////////////////////////////////////////////////////////
/**
* Returns the packed value associated with the indicated case.
*/
string DCSwitch::
get_value(int case_index) const {
nassertr(case_index >= 0 && case_index < (int)_cases.size(), string());
return _cases[case_index]->_value;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_num_fields
// Access: Published
// Description: Returns the number of fields in the indicated case.
////////////////////////////////////////////////////////////////////
/**
* Returns the number of fields in the indicated case.
*/
int DCSwitch::
get_num_fields(int case_index) const {
nassertr(case_index >= 0 && case_index < (int)_cases.size(), 0);
return _cases[case_index]->_fields->_fields.size();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_num_fields
// Access: Published
// Description: Returns the nth field in the indicated case.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth field in the indicated case.
*/
DCField *DCSwitch::
get_field(int case_index, int n) const {
nassertr(case_index >= 0 && case_index < (int)_cases.size(), NULL);
@ -194,12 +162,10 @@ get_field(int case_index, int n) const {
return _cases[case_index]->_fields->_fields[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_field_by_name
// Access: Published
// Description: Returns the field with the given name from the
// indicated case, or NULL if no field has this name.
////////////////////////////////////////////////////////////////////
/**
* Returns the field with the given name from the indicated case, or NULL if
* no field has this name.
*/
DCField *DCSwitch::
get_field_by_name(int case_index, const string &name) const {
nassertr(case_index >= 0 && case_index < (int)_cases.size(), NULL);
@ -214,26 +180,20 @@ get_field_by_name(int case_index, const string &name) const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::is_field_valid
// Access: Public
// Description: Returns true if it is valid to add a new field at
// this point (implying that a case or default has been
// added already), or false if not.
////////////////////////////////////////////////////////////////////
/**
* Returns true if it is valid to add a new field at this point (implying that
* a case or default has been added already), or false if not.
*/
bool DCSwitch::
is_field_valid() const {
return !_current_fields.empty();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::add_case
// Access: Public
// Description: Adds a new case to the switch with the indicated
// value, and returns the new case_index. If the value
// has already been used for another case, returns -1.
// This is normally called only by the parser.
////////////////////////////////////////////////////////////////////
/**
* Adds a new case to the switch with the indicated value, and returns the new
* case_index. If the value has already been used for another case, returns
* -1. This is normally called only by the parser.
*/
int DCSwitch::
add_case(const string &value) {
int case_index = (int)_cases.size();
@ -248,28 +208,22 @@ add_case(const string &value) {
return case_index;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::add_invalid_case
// Access: Public
// Description: Adds a new case to the switch that will never be
// matched. This is only used by the parser, to handle
// an error condition more gracefully without bitching
// the parsing (which behaves differently according to
// whether a case has been encountered or not).
////////////////////////////////////////////////////////////////////
/**
* Adds a new case to the switch that will never be matched. This is only
* used by the parser, to handle an error condition more gracefully without
* bitching the parsing (which behaves differently according to whether a case
* has been encountered or not).
*/
void DCSwitch::
add_invalid_case() {
start_new_case();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::add_default
// Access: Public
// Description: Adds a default case to the switch. Returns true if
// the case is successfully added, or false if it had
// already been added. This is normally called only by
// the parser.
////////////////////////////////////////////////////////////////////
/**
* Adds a default case to the switch. Returns true if the case is
* successfully added, or false if it had already been added. This is
* normally called only by the parser.
*/
bool DCSwitch::
add_default() {
if (_default_case != (SwitchFields *)NULL) {
@ -282,17 +236,13 @@ add_default() {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::add_field
// Access: Public
// Description: Adds a field to the currently active cases (those
// that have been added via add_case() or add_default(),
// since the last call to add_break()). Returns true if
// successful, false if the field duplicates a field
// already named within this case. It is an error to
// call this before calling add_case() or add_default().
// This is normally called only by the parser.
////////////////////////////////////////////////////////////////////
/**
* Adds a field to the currently active cases (those that have been added via
* add_case() or add_default(), since the last call to add_break()). Returns
* true if successful, false if the field duplicates a field already named
* within this case. It is an error to call this before calling add_case() or
* add_default(). This is normally called only by the parser.
*/
bool DCSwitch::
add_field(DCField *field) {
nassertr(!_current_fields.empty(), false);
@ -312,27 +262,21 @@ add_field(DCField *field) {
return all_ok;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::add_break
// Access: Public
// Description: Adds a break statement to the switch. This closes
// the currently open cases and prepares for a new,
// unrelated case.
////////////////////////////////////////////////////////////////////
/**
* Adds a break statement to the switch. This closes the currently open cases
* and prepares for a new, unrelated case.
*/
void DCSwitch::
add_break() {
_current_fields.clear();
_fields_added = false;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::apply_switch
// Access: Public
// Description: Returns the DCPackerInterface that presents the
// alternative fields for the case indicated by the
// given packed value string, or NULL if the value
// string does not match one of the expected cases.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface that presents the alternative fields for the
* case indicated by the given packed value string, or NULL if the value
* string does not match one of the expected cases.
*/
const DCPackerInterface *DCSwitch::
apply_switch(const char *value_data, size_t length) const {
CasesByValue::const_iterator vi;
@ -350,34 +294,27 @@ apply_switch(const char *value_data, size_t length) const {
return NULL;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::output
// Access: Public, Virtual
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
void DCSwitch::
output(ostream &out, bool brief) const {
output_instance(out, brief, "", "", "");
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::write
// Access: Public, Virtual
// Description: Generates a parseable description of the object to
// the indicated output stream.
////////////////////////////////////////////////////////////////////
/**
* Generates a parseable description of the object to the indicated output
* stream.
*/
void DCSwitch::
write(ostream &out, bool brief, int indent_level) const {
write_instance(out, brief, indent_level, "", "", "");
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::output_instance
// Access: Public
// Description: Generates a parseable description of the object to
// the indicated output stream.
////////////////////////////////////////////////////////////////////
/**
* Generates a parseable description of the object to the indicated output
* stream.
*/
void DCSwitch::
output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const {
@ -418,12 +355,10 @@ output_instance(ostream &out, bool brief, const string &prename,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::write_instance
// Access: Public, Virtual
// Description: Generates a parseable description of the object to
// the indicated output stream.
////////////////////////////////////////////////////////////////////
/**
* Generates a parseable description of the object to the indicated output
* stream.
*/
void DCSwitch::
write_instance(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
@ -470,12 +405,9 @@ write_instance(ostream &out, bool brief, int indent_level,
out << ";\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this switch into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this switch into the hash.
*/
void DCSwitch::
generate_hash(HashGenerator &hashgen) const {
hashgen.add_string(_name);
@ -506,30 +438,26 @@ generate_hash(HashGenerator &hashgen) const {
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::pack_default_value
// Access: Public
// Description: Packs the switchParameter's specified default value
// (or a sensible default if no value is specified) into
// the stream. Returns true if the default value is
// packed, false if the switchParameter doesn't know how
// to pack its default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the switchParameter's specified default value (or a sensible default
* if no value is specified) into the stream. Returns true if the default
* value is packed, false if the switchParameter doesn't know how to pack its
* default value.
*/
bool DCSwitch::
pack_default_value(DCPackData &pack_data, bool &pack_error) const {
SwitchFields *fields = NULL;
DCPacker packer;
packer.begin_pack(_key_parameter);
if (!_cases.empty()) {
// If we have any cases, the first case is always the default
// case, regardless of the default value specified by the key
// parameter. That's just the easiest to code.
// If we have any cases, the first case is always the default case,
// regardless of the default value specified by the key parameter. That's
// just the easiest to code.
packer.pack_literal_value(_cases[0]->_value);
fields = _cases[0]->_fields;
} else {
// If we don't have any cases, just pack the key parameter's
// default.
// If we don't have any cases, just pack the key parameter's default.
packer.pack_default_value();
fields = _default_case;
}
@ -557,15 +485,12 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::do_check_match_switch
// Access: Public
// Description: Returns true if this switch matches the indicated
// other switch--that is, the two switches are bitwise
// equivalent--false otherwise. This is only intended
// to be called internally from
// DCSwitchParameter::do_check_match_switch_parameter().
////////////////////////////////////////////////////////////////////
/**
* Returns true if this switch matches the indicated other switch--that is,
* the two switches are bitwise equivalent--false otherwise. This is only
* intended to be called internally from
* DCSwitchParameter::do_check_match_switch_parameter().
*/
bool DCSwitch::
do_check_match_switch(const DCSwitch *other) const {
if (!_key_parameter->check_match(other->_key_parameter)) {
@ -597,23 +522,19 @@ do_check_match_switch(const DCSwitch *other) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::start_new_case
// Access: Private
// Description: Creates a new field set for the new case, or shares
// the field set with the previous case, as appropriate.
// Returns the appropriate field set.
////////////////////////////////////////////////////////////////////
/**
* Creates a new field set for the new case, or shares the field set with the
* previous case, as appropriate. Returns the appropriate field set.
*/
DCSwitch::SwitchFields *DCSwitch::
start_new_case() {
SwitchFields *fields = NULL;
if (_current_fields.empty() || _fields_added) {
// If we have recently encountered a break (which removes all of
// the current field sets) or if we have already added at least
// one field to the previous case without an intervening break,
// then we can't share the field set with the previous case.
// Create a new one.
// If we have recently encountered a break (which removes all of the
// current field sets) or if we have already added at least one field to
// the previous case without an intervening break, then we can't share the
// field set with the previous case. Create a new one.
fields = new SwitchFields(_name);
fields->add_field(_key_parameter);
@ -631,11 +552,9 @@ start_new_case() {
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch::SwitchFields::
SwitchFields(const string &name) :
DCPackerInterface(name)
@ -651,40 +570,32 @@ SwitchFields(const string &name) :
_has_default_value = false;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch::SwitchFields::
~SwitchFields() {
// We don't delete any of the nested fields here, since they might
// be shared by multiple SwitchFields objects. Instead, we delete
// them in the DCSwitch destructor.
// We don't delete any of the nested fields here, since they might be shared
// by multiple SwitchFields objects. Instead, we delete them in the
// DCSwitch destructor.
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCSwitch::SwitchFields::
get_nested_field(int n) const {
nassertr(n >= 0 && n < (int)_fields.size(), NULL);
return _fields[n];
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::add_field
// Access: Public
// Description: Adds a field to this case. Returns true if
// successful, false if the field duplicates a field
// already named within this case. This is normally
// called only by the parser.
////////////////////////////////////////////////////////////////////
/**
* Adds a field to this case. Returns true if successful, false if the field
* duplicates a field already named within this case. This is normally called
* only by the parser.
*/
bool DCSwitch::SwitchFields::
add_field(DCField *field) {
if (!field->get_name().empty()) {
@ -717,14 +628,11 @@ add_field(DCField *field) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::do_check_match_switch_case
// Access: Public
// Description: Returns true if this case matches the indicated
// case, false otherwise. This is only intended to be
// called internally from
// DCSwitch::do_check_match_switch().
////////////////////////////////////////////////////////////////////
/**
* Returns true if this case matches the indicated case, false otherwise.
* This is only intended to be called internally from
* DCSwitch::do_check_match_switch().
*/
bool DCSwitch::SwitchFields::
do_check_match_switch_case(const DCSwitch::SwitchFields *other) const {
if (_fields.size() != other->_fields.size()) {
@ -739,11 +647,9 @@ do_check_match_switch_case(const DCSwitch::SwitchFields *other) const {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::output
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCSwitch::SwitchFields::
output(ostream &out, bool brief) const {
Fields::const_iterator fi;
@ -759,11 +665,9 @@ output(ostream &out, bool brief) const {
out << "break; ";
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::write
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCSwitch::SwitchFields::
write(ostream &out, bool brief, int indent_level) const {
Fields::const_iterator fi;
@ -779,14 +683,11 @@ write(ostream &out, bool brief, int indent_level) const {
<< "break;\n";
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchFields::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCSwitch::SwitchFields::
do_check_match(const DCPackerInterface *) const {
// This should never be called on a SwitchFields.
@ -794,11 +695,9 @@ do_check_match(const DCPackerInterface *) const {
return false;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchCase::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch::SwitchCase::
SwitchCase(const string &value, DCSwitch::SwitchFields *fields) :
_value(value),
@ -806,23 +705,18 @@ SwitchCase(const string &value, DCSwitch::SwitchFields *fields) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchCase::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitch::SwitchCase::
~SwitchCase() {
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::SwitchCase::do_check_match_switch_case
// Access: Public
// Description: Returns true if this case matches the indicated
// case, false otherwise. This is only intended to be
// called internally from
// DCSwitch::do_check_match_switch().
////////////////////////////////////////////////////////////////////
/**
* Returns true if this case matches the indicated case, false otherwise.
* This is only intended to be called internally from
* DCSwitch::do_check_match_switch().
*/
bool DCSwitch::SwitchCase::
do_check_match_switch_case(const DCSwitch::SwitchCase *other) const {
return _fields->do_check_match_switch_case(other->_fields);

View File

@ -1,16 +1,15 @@
// Filename: dcSwitch.h
// Created by: drose (23Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSwitch.h
* @author drose
* @date 2004-06-23
*/
#ifndef DCSWITCH_H
#define DCSWITCH_H
@ -23,13 +22,11 @@ class DCParameter;
class HashGenerator;
class DCField;
////////////////////////////////////////////////////////////////////
// Class : DCSwitch
// Description : This represents a switch statement, which can appear
// inside a class body and represents two or more
// alternative unpacking schemes based on the first
// field read.
////////////////////////////////////////////////////////////////////
/**
* This represents a switch statement, which can appear inside a class body
* and represents two or more alternative unpacking schemes based on the first
* field read.
*/
class EXPCL_DIRECT DCSwitch : public DCDeclaration {
public:
DCSwitch(const string &name, DCField *key_parameter);
@ -64,7 +61,7 @@ public:
virtual void output(ostream &out, bool brief) const;
virtual void write(ostream &out, bool brief, int indent_level) const;
void output_instance(ostream &out, bool brief, const string &prename,
void output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const;
void write_instance(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
@ -122,20 +119,20 @@ private:
Cases _cases;
SwitchFields *_default_case;
// All SwitchFields created and used by the DCSwitch object are also
// stored here; this is the vector that "owns" the pointers.
// All SwitchFields created and used by the DCSwitch object are also stored
// here; this is the vector that "owns" the pointers.
typedef pvector<SwitchFields *> CaseFields;
CaseFields _case_fields;
// All nested DCField objects that have been added to one or more of
// the above SwitchFields are also recorded here; this is the vector
// that "owns" these pointers.
// All nested DCField objects that have been added to one or more of the
// above SwitchFields are also recorded here; this is the vector that "owns"
// these pointers.
Fields _nested_fields;
// These are the SwitchFields that are currently being filled up
// during this stage of the parser. There might be more than one at
// a time, if we have multiple cases being introduced in the middle
// of a series of fields (without a break statement intervening).
// These are the SwitchFields that are currently being filled up during this
// stage of the parser. There might be more than one at a time, if we have
// multiple cases being introduced in the middle of a series of fields
// (without a break statement intervening).
CaseFields _current_fields;
bool _fields_added;

View File

@ -1,26 +1,23 @@
// Filename: dcSwitchParameter.cxx
// Created by: drose (18Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSwitchParameter.cxx
* @author drose
* @date 2004-06-18
*/
#include "dcSwitchParameter.h"
#include "dcSwitch.h"
#include "hashGenerator.h"
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitchParameter::
DCSwitchParameter(const DCSwitch *dswitch) :
_dswitch(dswitch)
@ -31,10 +28,10 @@ DCSwitchParameter(const DCSwitch *dswitch) :
_fixed_byte_size = 0;
_has_fixed_structure = false;
// The DCSwitch presents just one nested field initially, which is
// the key parameter. When we pack or unpack that, the DCPacker
// calls apply_switch(), which returns a new record that presents
// the remaining nested fields.
// The DCSwitch presents just one nested field initially, which is the key
// parameter. When we pack or unpack that, the DCPacker calls
// apply_switch(), which returns a new record that presents the remaining
// nested fields.
_has_nested_fields = true;
_num_nested_fields = 1;
@ -51,12 +48,12 @@ DCSwitchParameter(const DCSwitch *dswitch) :
// Consider each case for fixed size, etc.
for (int i = 0; i < num_cases; i++) {
const DCSwitch::SwitchFields *fields =
const DCSwitch::SwitchFields *fields =
(const DCSwitch::SwitchFields *)_dswitch->get_case(i);
if (!fields->has_fixed_byte_size() ||
if (!fields->has_fixed_byte_size() ||
fields->get_fixed_byte_size() != _fixed_byte_size) {
// Nope, we have a variable byte size.
_has_fixed_byte_size = false;
}
@ -67,24 +64,22 @@ DCSwitchParameter(const DCSwitch *dswitch) :
}
// Also consider the default case, if there is one.
const DCSwitch::SwitchFields *fields =
const DCSwitch::SwitchFields *fields =
(DCSwitch::SwitchFields *)_dswitch->get_default_case();
if (fields != (DCSwitch::SwitchFields *)NULL) {
if (!fields->has_fixed_byte_size() ||
if (!fields->has_fixed_byte_size() ||
fields->get_fixed_byte_size() != _fixed_byte_size) {
_has_fixed_byte_size = false;
}
_has_range_limits = _has_range_limits || fields->has_range_limits();
_has_default_value = _has_default_value || fields->_has_default_value;
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitchParameter::
DCSwitchParameter(const DCSwitchParameter &copy) :
DCParameter(copy),
@ -92,92 +87,73 @@ DCSwitchParameter(const DCSwitchParameter &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCSwitchParameter *DCSwitchParameter::
as_switch_parameter() {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::as_switch_parameter
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
const DCSwitchParameter *DCSwitchParameter::
as_switch_parameter() const {
return this;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::make_copy
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCParameter *DCSwitchParameter::
make_copy() const {
return new DCSwitchParameter(*this);
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::is_valid
// Access: Published, Virtual
// Description: Returns false if the type is an invalid type
// (e.g. declared from an undefined typedef), true if
// it is valid.
////////////////////////////////////////////////////////////////////
/**
* Returns false if the type is an invalid type (e.g. declared from an
* undefined typedef), true if it is valid.
*/
bool DCSwitchParameter::
is_valid() const {
return true; //_dswitch->is_valid();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::get_switch
// Access: Published
// Description: Returns the switch object this parameter represents.
////////////////////////////////////////////////////////////////////
/**
* Returns the switch object this parameter represents.
*/
const DCSwitch *DCSwitchParameter::
get_switch() const {
return _dswitch;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::get_nested_field
// Access: Public, Virtual
// Description: Returns the DCPackerInterface object that represents
// the nth nested field. This may return NULL if there
// is no such field (but it shouldn't do this if n is in
// the range 0 <= n < get_num_nested_fields()).
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface object that represents the nth nested field.
* This may return NULL if there is no such field (but it shouldn't do this if
* n is in the range 0 <= n < get_num_nested_fields()).
*/
DCPackerInterface *DCSwitchParameter::
get_nested_field(int) const {
return _dswitch->get_key_parameter();
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::apply_switch
// Access: Public
// Description: Returns the DCPackerInterface that presents the
// alternative fields for the case indicated by the
// given packed value string, or NULL if the value
// string does not match one of the expected cases.
////////////////////////////////////////////////////////////////////
/**
* Returns the DCPackerInterface that presents the alternative fields for the
* case indicated by the given packed value string, or NULL if the value
* string does not match one of the expected cases.
*/
const DCPackerInterface *DCSwitchParameter::
apply_switch(const char *value_data, size_t length) const {
return _dswitch->apply_switch(value_data, length);
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::output_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCSwitchParameter::
output_instance(ostream &out, bool brief, const string &prename,
output_instance(ostream &out, bool brief, const string &prename,
const string &name, const string &postname) const {
if (get_typedef() != (DCTypedef *)NULL) {
output_typedef_name(out, brief, prename, name, postname);
@ -187,15 +163,13 @@ output_instance(ostream &out, bool brief, const string &prename,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::write_instance
// Access: Public, Virtual
// Description: Formats the parameter in the C++-like dc syntax as a
// typename and identifier.
////////////////////////////////////////////////////////////////////
/**
* Formats the parameter in the C++-like dc syntax as a typename and
* identifier.
*/
void DCSwitchParameter::
write_instance(ostream &out, bool brief, int indent_level,
const string &prename, const string &name,
const string &prename, const string &name,
const string &postname) const {
if (get_typedef() != (DCTypedef *)NULL) {
write_typedef_name(out, brief, indent_level, prename, name, postname);
@ -205,27 +179,21 @@ write_instance(ostream &out, bool brief, int indent_level,
}
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::generate_hash
// Access: Public, Virtual
// Description: Accumulates the properties of this type into the
// hash.
////////////////////////////////////////////////////////////////////
/**
* Accumulates the properties of this type into the hash.
*/
void DCSwitchParameter::
generate_hash(HashGenerator &hashgen) const {
DCParameter::generate_hash(hashgen);
_dswitch->generate_hash(hashgen);
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::pack_default_value
// Access: Public, Virtual
// Description: Packs the switchParameter's specified default value (or a
// sensible default if no value is specified) into the
// stream. Returns true if the default value is packed,
// false if the switchParameter doesn't know how to pack its
// default value.
////////////////////////////////////////////////////////////////////
/**
* Packs the switchParameter's specified default value (or a sensible default
* if no value is specified) into the stream. Returns true if the default
* value is packed, false if the switchParameter doesn't know how to pack its
* default value.
*/
bool DCSwitchParameter::
pack_default_value(DCPackData &pack_data, bool &pack_error) const {
if (has_default_value()) {
@ -235,25 +203,20 @@ pack_default_value(DCPackData &pack_data, bool &pack_error) const {
return _dswitch->pack_default_value(pack_data, pack_error);
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::do_check_match
// Access: Protected, Virtual
// Description: Returns true if the other interface is bitwise the
// same as this one--that is, a uint32 only matches a
// uint32, etc. Names of components, and range limits,
// are not compared.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the other interface is bitwise the same as this one--that
* is, a uint32 only matches a uint32, etc. Names of components, and range
* limits, are not compared.
*/
bool DCSwitchParameter::
do_check_match(const DCPackerInterface *other) const {
return other->do_check_match_switch_parameter(this);
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitchParameter::do_check_match_switch_parameter
// Access: Protected, Virtual
// Description: Returns true if this field matches the indicated
// switch parameter, false otherwise.
////////////////////////////////////////////////////////////////////
/**
* Returns true if this field matches the indicated switch parameter, false
* otherwise.
*/
bool DCSwitchParameter::
do_check_match_switch_parameter(const DCSwitchParameter *other) const {
return _dswitch->do_check_match_switch(other->_dswitch);

View File

@ -1,16 +1,15 @@
// Filename: dcSwitchParameter.h
// Created by: drose (29Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcSwitchParameter.h
* @author drose
* @date 2004-06-29
*/
#ifndef DCSWITCHPARAMETER_H
#define DCSWITCHPARAMETER_H
@ -20,12 +19,10 @@
class DCSwitch;
////////////////////////////////////////////////////////////////////
// Class : DCSwitchParameter
// Description : This represents a switch object used as a
// parameter itself, which packs the appropriate fields
// of the switch into the message.
////////////////////////////////////////////////////////////////////
/**
* This represents a switch object used as a parameter itself, which packs the
* appropriate fields of the switch into the message.
*/
class EXPCL_DIRECT DCSwitchParameter : public DCParameter {
public:
DCSwitchParameter(const DCSwitch *dswitch);

View File

@ -1,29 +1,25 @@
// Filename: dcTypedef.cxx
// Created by: drose (17Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcTypedef.cxx
* @author drose
* @date 2004-06-17
*/
#include "dcTypedef.h"
#include "dcParameter.h"
#include "dcSimpleParameter.h"
#include "dcindent.h"
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::Constructor
// Access: Public
// Description: The DCTypedef object becomes the owner of the
// supplied parameter pointer and will delete it upon
// destruction.
////////////////////////////////////////////////////////////////////
/**
* The DCTypedef object becomes the owner of the supplied parameter pointer
* and will delete it upon destruction.
*/
DCTypedef::
DCTypedef(DCParameter *parameter, bool implicit) :
_parameter(parameter),
@ -33,11 +29,9 @@ DCTypedef(DCParameter *parameter, bool implicit) :
{
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::Constructor
// Access: Public
// Description: Creates a bogus typedef reference.
////////////////////////////////////////////////////////////////////
/**
* Creates a bogus typedef reference.
*/
DCTypedef::
DCTypedef(const string &name) :
_parameter(new DCSimpleParameter(ST_invalid)),
@ -48,44 +42,34 @@ DCTypedef(const string &name) :
_parameter->set_name(name);
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
DCTypedef::
~DCTypedef() {
delete _parameter;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::get_number
// Access: Published
// Description: Returns a unique index number associated with this
// typedef definition. This is defined implicitly when
// the .dc file(s) are read.
////////////////////////////////////////////////////////////////////
/**
* Returns a unique index number associated with this typedef definition.
* This is defined implicitly when the .dc file(s) are read.
*/
int DCTypedef::
get_number() const {
return _number;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::get_name
// Access: Published
// Description: Returns the name of this typedef.
////////////////////////////////////////////////////////////////////
/**
* Returns the name of this typedef.
*/
const string &DCTypedef::
get_name() const {
return _parameter->get_name();
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::get_description
// Access: Published
// Description: Returns a brief decription of the typedef, useful for
// human consumption.
////////////////////////////////////////////////////////////////////
/**
* Returns a brief decription of the typedef, useful for human consumption.
*/
string DCTypedef::
get_description() const {
ostringstream strm;
@ -93,38 +77,30 @@ get_description() const {
return strm.str();
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::is_bogus_typedef
// Access: Public
// Description: Returns true if the typedef has been flagged as a bogus
// typedef. This is set for typedefs that are generated by
// the parser as placeholder for missing typedefs, as
// when reading a partial file; it should not occur in a
// normal valid dc file.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the typedef has been flagged as a bogus typedef. This is
* set for typedefs that are generated by the parser as placeholder for
* missing typedefs, as when reading a partial file; it should not occur in a
* normal valid dc file.
*/
bool DCTypedef::
is_bogus_typedef() const {
return _bogus_typedef;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::is_implicit_typedef
// Access: Public
// Description: Returns true if the typedef has been flagged as an
// implicit typedef, meaning it was created for a
// DCClass that was referenced inline as a type.
////////////////////////////////////////////////////////////////////
/**
* Returns true if the typedef has been flagged as an implicit typedef,
* meaning it was created for a DCClass that was referenced inline as a type.
*/
bool DCTypedef::
is_implicit_typedef() const {
return _implicit_typedef;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::make_new_parameter
// Access: Public
// Description: Returns a newly-allocated DCParameter object that
// uses the same type as that named by the typedef.
////////////////////////////////////////////////////////////////////
/**
* Returns a newly-allocated DCParameter object that uses the same type as
* that named by the typedef.
*/
DCParameter *DCTypedef::
make_new_parameter() const {
DCParameter *new_parameter = _parameter->make_copy();
@ -133,42 +109,34 @@ make_new_parameter() const {
return new_parameter;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::set_number
// Access: Public
// Description: Assigns the unique number to this typedef. This is
// normally called only by the DCFile interface as the
// typedef is added.
////////////////////////////////////////////////////////////////////
/**
* Assigns the unique number to this typedef. This is normally called only by
* the DCFile interface as the typedef is added.
*/
void DCTypedef::
set_number(int number) {
_number = number;
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::output
// Access: Public, Virtual
// Description: Write a string representation of this instance to
// <out>.
////////////////////////////////////////////////////////////////////
/**
* Write a string representation of this instance to <out>.
*/
void DCTypedef::
output(ostream &out, bool brief) const {
out << "typedef ";
_parameter->output(out, false);
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::write
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
void DCTypedef::
write(ostream &out, bool brief, int indent_level) const {
indent(out, indent_level)
<< "typedef ";
// We need to preserve the parameter name in the typedef (this is
// the typedef name); hence, we pass brief = false to output().
// We need to preserve the parameter name in the typedef (this is the
// typedef name); hence, we pass brief = false to output().
_parameter->output(out, false);
out << ";";

View File

@ -1,16 +1,15 @@
// Filename: dcTypedef.h
// Created by: drose (17Jun04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcTypedef.h
* @author drose
* @date 2004-06-17
*/
#ifndef DCTYPEDEF_H
#define DCTYPEDEF_H
@ -20,12 +19,10 @@
class DCParameter;
////////////////////////////////////////////////////////////////////
// Class : DCTypedef
// Description : This represents a single typedef declaration in the
// dc file. It assigns a particular type to a new name,
// just like a C typedef.
////////////////////////////////////////////////////////////////////
/**
* This represents a single typedef declaration in the dc file. It assigns a
* particular type to a new name, just like a C typedef.
*/
class EXPCL_DIRECT DCTypedef : public DCDeclaration {
public:
DCTypedef(DCParameter *parameter, bool implicit = false);

View File

@ -1,30 +1,29 @@
// Filename: dcbase.h
// Created by: drose (05Oct00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcbase.h
* @author drose
* @date 2000-10-05
*/
#ifndef DCBASE_H
#define DCBASE_H
// This file defines a few headers and stuff necessary for compilation
// of the files in this directory. This is different from most of the
// other source directories within Panda, since the dcparser is
// designed to be compilable outside of Panda (for use by the server
// code). Therefore, it must not depend on including any of the Panda
// header files, and we have to duplicate some setup stuff here.
// This file defines a few headers and stuff necessary for compilation of the
// files in this directory. This is different from most of the other source
// directories within Panda, since the dcparser is designed to be compilable
// outside of Panda (for use by the server code). Therefore, it must not
// depend on including any of the Panda header files, and we have to duplicate
// some setup stuff here.
#ifdef WITHIN_PANDA
// On the other hand, if WITHIN_PANDA is defined, we *are* safely
// within the Panda environment.
// On the other hand, if WITHIN_PANDA is defined, we *are* safely within the
// Panda environment.
#include "directbase.h"
#include "pnotify.h"
@ -51,9 +50,9 @@
#include <string>
#include <assert.h>
// These header files are needed to compile dcLexer.cxx, the output
// from flex. flex doesn't create a perfectly windows-friendly source
// file right out of the box.
// These header files are needed to compile dcLexer.cxx, the output from flex.
// flex doesn't create a perfectly windows-friendly source file right out of
// the box.
#ifdef WIN32
#include <io.h>
#include <malloc.h>
@ -66,35 +65,35 @@ using namespace std;
#define INLINE inline
#define TYPENAME typename
// These symbols are used within the Panda environment for exporting
// classes and functions to the scripting language. They're largely
// meaningless if we're not compiling within Panda.
// These symbols are used within the Panda environment for exporting classes
// and functions to the scripting language. They're largely meaningless if
// we're not compiling within Panda.
#define PUBLISHED public
#define BEGIN_PUBLISH
#define END_PUBLISH
#define BLOCKING
// Panda defines some assert-type macros. We map those to the
// standard assert macro outside of Panda.
// Panda defines some assert-type macros. We map those to the standard assert
// macro outside of Panda.
#define nassertr(condition, return_value) assert(condition)
#define nassertr_always(condition, return_value) assert(condition)
#define nassertv(condition) assert(condition)
#define nassertv_always(condition) assert(condition)
// Panda defines these export symbols for building DLL's. Outside of
// Panda, we assume we're not putting this code in a DLL, so we define
// them to nothing.
// Panda defines these export symbols for building DLL's. Outside of Panda,
// we assume we're not putting this code in a DLL, so we define them to
// nothing.
#define EXPCL_DIRECT
#define EXPTP_DIRECT
// Panda defines a special Filename class. We'll use an ordinary
// string instead.
// Panda defines a special Filename class. We'll use an ordinary string
// instead.
typedef string Filename;
// Panda defines WORDS_BIGENDIAN on a bigendian machine; otherwise,
// the machine is assumed to be littleendian. Outside of Panda,
// you're responsible for defining this yourself if necessary.
//#define WORDS_BIGENDIAN
// Panda defines WORDS_BIGENDIAN on a bigendian machine; otherwise, the
// machine is assumed to be littleendian. Outside of Panda, you're
// responsible for defining this yourself if necessary. #define
// WORDS_BIGENDIAN
#include <vector>
#include <map>
@ -121,7 +120,7 @@ typedef fstream pfstream;
#endif // WITHIN_PANDA
//typedef unsigned long CHANNEL_TYPE;
// typedef unsigned long CHANNEL_TYPE;
typedef PN_uint64 CHANNEL_TYPE;
typedef PN_uint32 DOID_TYPE;
typedef PN_uint32 ZONEID_TYPE;

View File

@ -1,25 +1,23 @@
// Filename: dcindent.cxx
// Created by: drose (05May00)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcindent.cxx
* @author drose
* @date 2000-05-05
*/
#include "dcindent.h"
#ifndef WITHIN_PANDA
////////////////////////////////////////////////////////////////////
// Function: indent
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
ostream &
indent(ostream &out, int indent_level) {
for (int i = 0; i < indent_level; i++) {

View File

@ -1,16 +1,15 @@
// Filename: dcindent.h
// Created by: drose (16Jan99)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcindent.h
* @author drose
* @date 1999-01-16
*/
#ifndef DCINDENT_H
#define DCINDENT_H
@ -18,21 +17,18 @@
#include "dcbase.h"
#ifdef WITHIN_PANDA
// If we're compiling this within Panda, we use the function defined
// there.
// If we're compiling this within Panda, we use the function defined there.
#include "indent.h"
#else
// Otherwise, we must define it for ourselves.
////////////////////////////////////////////////////////////////////
// Function: indent
// Description: A handy function for doing text formatting. This
// function simply outputs the indicated number of
// spaces to the given output stream, returning the
// stream itself. Useful for indenting a series of
// lines of text by a given amount.
////////////////////////////////////////////////////////////////////
/**
* A handy function for doing text formatting. This function simply outputs
* the indicated number of spaces to the given output stream, returning the
* stream itself. Useful for indenting a series of lines of text by a given
* amount.
*/
ostream &
indent(ostream &out, int indent_level);

View File

@ -1,23 +1,21 @@
// Filename: dcmsgtypes.h
// Created by: drose (18May04)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 dcmsgtypes.h
* @author drose
* @date 2004-05-18
*/
#ifndef DCMSGTYPES_H
#define DCMSGTYPES_H
// This file defines the server message types used within this module.
// It duplicates some symbols defined in MsgTypes.py and
// AIMsgTypes.py.
// 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
@ -33,4 +31,3 @@
#define CLIENT_OBJECT_GENERATE_CMU 9002
#endif

View File

@ -1,47 +1,42 @@
// Filename: hashGenerator.cxx
// Created by: drose (22Mar01)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 hashGenerator.cxx
* @author drose
* @date 2001-03-22
*/
#include "hashGenerator.h"
#include "primeNumberGenerator.h"
// We multiply each consecutive integer by the next prime number and
// add it to the total. This will generate pretty evenly-distributed
// hash numbers for an arbitrary sequence of ints.
// We multiply each consecutive integer by the next prime number and add it to
// the total. This will generate pretty evenly-distributed hash numbers for
// an arbitrary sequence of ints.
// We do recycle the prime number table at some point, just to keep it
// from growing insanely large, however (and to avoid wasting time
// computing large prime numbers unnecessarily), and we also truncate
// the result to the low-order 32 bits.
// We do recycle the prime number table at some point, just to keep it from
// growing insanely large, however (and to avoid wasting time computing large
// prime numbers unnecessarily), and we also truncate the result to the low-
// order 32 bits.
static const int max_prime_numbers = 10000;
////////////////////////////////////////////////////////////////////
// Function: HashGenerator::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
HashGenerator::
HashGenerator() {
_hash = 0;
_index = 0;
}
////////////////////////////////////////////////////////////////////
// Function: HashGenerator::add_int
// Access: Public
// Description: Adds another integer to the hash so far.
////////////////////////////////////////////////////////////////////
/**
* Adds another integer to the hash so far.
*/
void HashGenerator::
add_int(int num) {
nassertv(_index >= 0 && _index < max_prime_numbers);
@ -49,12 +44,9 @@ add_int(int num) {
_index = (_index + 1) % max_prime_numbers;
}
////////////////////////////////////////////////////////////////////
// Function: HashGenerator::add_string
// Access: Public
// Description: Adds a string to the hash, by breaking it down into a
// sequence of integers.
////////////////////////////////////////////////////////////////////
/**
* Adds a string to the hash, by breaking it down into a sequence of integers.
*/
void HashGenerator::
add_string(const string &str) {
add_int(str.length());
@ -64,11 +56,9 @@ add_string(const string &str) {
}
}
////////////////////////////////////////////////////////////////////
// Function: HashGenerator::get_hash
// Access: Public
// Description: Returns the hash number generated.
////////////////////////////////////////////////////////////////////
/**
* Returns the hash number generated.
*/
unsigned long HashGenerator::
get_hash() const {
return (unsigned long)(_hash & 0xffffffff);

View File

@ -1,16 +1,15 @@
// Filename: hashGenerator.h
// Created by: drose (22Mar01)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 hashGenerator.h
* @author drose
* @date 2001-03-22
*/
#ifndef DCHASHGENERATOR_H
#define DCHASHGENERATOR_H
@ -18,11 +17,9 @@
#include "dcbase.h"
#include "primeNumberGenerator.h"
////////////////////////////////////////////////////////////////////
// Class : HashGenerator
// Description : This class generates an arbitrary hash number from a
// sequence of ints.
////////////////////////////////////////////////////////////////////
/**
* This class generates an arbitrary hash number from a sequence of ints.
*/
class HashGenerator {
public:
HashGenerator();

View File

@ -1,48 +1,41 @@
// Filename: primeNumberGenerator.cxx
// Created by: drose (22Mar01)
//
////////////////////////////////////////////////////////////////////
//
// 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."
//
////////////////////////////////////////////////////////////////////
/**
* 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 primeNumberGenerator.cxx
* @author drose
* @date 2001-03-22
*/
#include "primeNumberGenerator.h"
////////////////////////////////////////////////////////////////////
// Function: PrimeNumberGenerator::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
/**
*
*/
PrimeNumberGenerator::
PrimeNumberGenerator() {
_primes.push_back(2);
}
////////////////////////////////////////////////////////////////////
// Function: PrimeNumberGenerator::Indexing operator
// Access: Public
// Description: Returns the nth prime number. this[0] returns 2,
// this[1] returns 3; successively larger values of n
// return larger prime numbers, up to the largest prime
// number that can be represented in an int.
////////////////////////////////////////////////////////////////////
/**
* Returns the nth prime number. this[0] returns 2, this[1] returns 3;
* successively larger values of n return larger prime numbers, up to the
* largest prime number that can be represented in an int.
*/
int PrimeNumberGenerator::
operator [] (int n) {
nassertr(n >= 0, 0);
// Compute the prime numbers between the last-computed prime number
// and n.
// Compute the prime numbers between the last-computed prime number and n.
int candidate = _primes.back() + 1;
while ((int)_primes.size() <= n) {
// Is candidate prime? It is not if any one of the already-found
// prime numbers (up to its square root) divides it evenly.
// Is candidate prime? It is not if any one of the already-found prime
// numbers (up to its square root) divides it evenly.
bool maybe_prime = true;
int j = 0;
while (maybe_prime && _primes[j] * _primes[j] <= candidate) {

Some files were not shown because too many files have changed in this diff Show More