Panda3D
modelRoot.I
1 // Filename: modelRoot.I
2 // Created by: drose (16Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ModelRoot::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ModelRoot::
22 ModelRoot(const string &name) :
23  ModelNode(name),
24  _fullpath(name),
25  _timestamp(0),
26  _reference(new ModelRoot::ModelReference)
27 {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: ModelRoot::Constructor
32 // Access: Published
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 INLINE ModelRoot::
36 ModelRoot(const Filename &fullpath, time_t timestamp) :
37  ModelNode(fullpath.get_basename()),
38  _fullpath(fullpath),
39  _timestamp(timestamp),
40  _reference(new ModelRoot::ModelReference)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: ModelRoot::get_model_ref_count
46 // Access: Published
47 // Description: Returns the number of copies that exist of this
48 // particular ModelRoot node. Each time
49 // ModelRoot::copy_subgraph() or make_copy() is called
50 // (or some other copying mechanism, such as
51 // NodePath.copy_to(), is used), this count will
52 // increment by one in all copies; when one of the
53 // copies is destructed, this count will decrement.
54 ////////////////////////////////////////////////////////////////////
55 INLINE int ModelRoot::
57  return _reference->get_ref_count();
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: ModelRoot::get_fullpath
62 // Access: Published
63 // Description: Returns the full pathname of the model represented by
64 // this node, as found on disk. This is mainly useful
65 // for reference purposes, but is also used to index the
66 // ModelRoot into the ModelPool.
67 ////////////////////////////////////////////////////////////////////
68 INLINE const Filename &ModelRoot::
69 get_fullpath() const {
70  return _fullpath;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: ModelRoot::set_fullpath
75 // Access: Published
76 // Description: Sets the full pathname of the model represented by
77 // this node, as found on disk. This is mainly useful
78 // for reference purposes, but is also used to index the
79 // ModelRoot into the ModelPool.
80 //
81 // This is normally set automatically when a model is
82 // loaded, and should not be set directly by the user.
83 // If you change this on a loaded model, then
84 // ModelPool::release_model() may fail.
85 ////////////////////////////////////////////////////////////////////
86 INLINE void ModelRoot::
87 set_fullpath(const Filename &fullpath) {
88  _fullpath = fullpath;
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: ModelRoot::get_timestamp
93 // Access: Published
94 // Description: Returns the timestamp of the file on disk that was
95 // read for this model, at the time it was read, if it
96 // is known. Returns 0 if the timestamp is not known or
97 // could not be provided. This can be used as a quick
98 // (but fallible) check to verify whether the file might
99 // have changed since the model was read.
100 ////////////////////////////////////////////////////////////////////
101 INLINE time_t ModelRoot::
102 get_timestamp() const {
103  return _timestamp;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: ModelRoot::set_timestamp
108 // Access: Published
109 // Description: Sets the timestamp of the file on disk that was read
110 // for this model. This is normally set automatically
111 // when a model is loaded, and should not be set
112 // directly by the user.
113 ////////////////////////////////////////////////////////////////////
114 INLINE void ModelRoot::
115 set_timestamp(time_t timestamp) {
116  _timestamp = timestamp;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: ModelRoot::get_reference
121 // Access: Published
122 // Description: Returns the pointer that represents the object shared
123 // between all copies of this ModelRoot. Since there's
124 // not much associated with this object other than a
125 // reference count, normally there's not much reason to
126 // get the pointer (though it may be compared
127 // pointerwise with other ModelRoot objects).
128 ////////////////////////////////////////////////////////////////////
130 get_reference() const {
131  return _reference;
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: ModelRoot::set_reference
136 // Access: Published
137 // Description: Changes the pointer that represents the object shared
138 // between all copies of this ModelRoot. This will
139 // disassociate this ModelRoot from all of its copies.
140 // Normally, there's no reason to do this.
141 ////////////////////////////////////////////////////////////////////
142 INLINE void ModelRoot::
144  _reference = ref;
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ModelRoot::Copy Constructor
149 // Access: Protected
150 // Description:
151 ////////////////////////////////////////////////////////////////////
152 INLINE ModelRoot::
153 ModelRoot(const ModelRoot &copy) :
154  ModelNode(copy),
155  _fullpath(copy._fullpath),
156  _timestamp(copy._timestamp),
157  _reference(copy._reference)
158 {
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: ModelRoot::ModelReference::Constructor
163 // Access: Published
164 // Description:
165 ////////////////////////////////////////////////////////////////////
166 INLINE ModelRoot::ModelReference::
167 ModelReference() {
168 }
A node of this type is created automatically at the root of each model file that is loaded...
Definition: modelRoot.h:31
const Filename & get_fullpath() const
Returns the full pathname of the model represented by this node, as found on disk.
Definition: modelRoot.I:69
void set_reference(ModelReference *ref)
Changes the pointer that represents the object shared between all copies of this ModelRoot.
Definition: modelRoot.I:143
void set_fullpath(const Filename &fullpath)
Sets the full pathname of the model represented by this node, as found on disk.
Definition: modelRoot.I:87
int get_model_ref_count() const
Returns the number of copies that exist of this particular ModelRoot node.
Definition: modelRoot.I:56
void set_timestamp(time_t timestamp)
Sets the timestamp of the file on disk that was read for this model.
Definition: modelRoot.I:115
This node is placed at key points within the scene graph to indicate the roots of "models": subtrees ...
Definition: modelNode.h:34
ModelReference * get_reference() const
Returns the pointer that represents the object shared between all copies of this ModelRoot.
Definition: modelRoot.I:130
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
time_t get_timestamp() const
Returns the timestamp of the file on disk that was read for this model, at the time it was read...
Definition: modelRoot.I:102
void ref() const
Explicitly increments the reference count.