Panda3D
Loading...
Searching...
No Matches
paramNodePath.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file paramNodePath.cxx
10 * @author rdb
11 * @date 2015-02-25
12 */
13
14#include "paramNodePath.h"
15#include "dcast.h"
16#include "pandaNode.h"
17
18TypeHandle ParamNodePath::_type_handle;
19
20/**
21 *
22 */
23void ParamNodePath::
24output(std::ostream &out) const {
25 out << "node path " << _node_path;
26}
27
28/**
29 * Tells the BamReader how to create objects of type ParamValue.
30 */
33 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
34}
35
36/**
37 * Writes the contents of this object to the datagram for shipping out to a
38 * Bam file.
39 */
41write_datagram(BamWriter *manager, Datagram &dg) {
43
44 if (manager->get_file_minor_ver() < 40) {
45 // Before bam 6.40, we did not support writing NodePaths. Instaed, we
46 // write the PandaNode pointer and pray there is an unambiguous path.
47 if (_node_path.is_empty()) {
48 manager->write_pointer(dg, nullptr);
49 } else {
50 manager->write_pointer(dg, _node_path.node());
51 }
52 } else {
53 _node_path.write_datagram(manager, dg);
54 }
55}
56
57/**
58 * Receives an array of pointers, one for each time manager->read_pointer()
59 * was called in fillin(). Returns the number of pointers processed.
60 */
62complete_pointers(TypedWritable **p_list, BamReader *manager) {
63 int pi = ParamValueBase::complete_pointers(p_list, manager);
64
65 if (manager->get_file_minor_ver() >= 40) {
66 pi += _node_path.complete_pointers(p_list + pi, manager);
67 } else {
68 _node_path = NodePath(DCAST(PandaNode, p_list[pi++]));
69 }
70
71 return pi;
72}
73
74/**
75 * This function is called by the BamReader's factory when a new object of
76 * type ParamValue is encountered in the Bam file. It should create the
77 * ParamValue and extract its information from the file.
78 */
79TypedWritable *ParamNodePath::
80make_from_bam(const FactoryParams &params) {
81 ParamNodePath *param = new ParamNodePath;
83 BamReader *manager;
84
85 parse_params(params, scan, manager);
86 param->fillin(scan, manager);
87
88 return param;
89}
90
91/**
92 * This internal function is called by make_from_bam to read in all of the
93 * relevant data from the BamFile for the new ParamValue.
94 */
95void ParamNodePath::
96fillin(DatagramIterator &scan, BamReader *manager) {
97 ParamValueBase::fillin(scan, manager);
98
99 if (manager->get_file_minor_ver() >= 40) {
100 _node_path.fillin(scan, manager);
101 } else {
102 manager->read_pointer(scan);
103 }
104}
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition bamReader.I:83
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
Definition bamWriter.I:59
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition nodePath.I:188
int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PandaNode * node() const
Returns the referenced node of the path.
Definition nodePath.I:227
void write_datagram(BamWriter *manager, Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
A class object for storing a NodePath as a parameter.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.