Panda3D
 All Classes Functions Variables Enumerations
texturePosition.cxx
1 // Filename: texturePosition.cxx
2 // Created by: drose (04Dec00)
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 #include "texturePosition.h"
16 
17 #include "datagram.h"
18 #include "datagramIterator.h"
19 #include "bamReader.h"
20 #include "bamWriter.h"
21 
22 TypeHandle TexturePosition::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: TexturePosition::Constructor
26 // Access: Public
27 // Description:
28 ////////////////////////////////////////////////////////////////////
29 TexturePosition::
30 TexturePosition() {
31  _margin = 0;
32  _x = 0;
33  _y = 0;
34  _x_size = 0;
35  _y_size = 0;
36  _min_uv.set(0.0, 0.0);
37  _max_uv.set(0.0, 0.0);
38  _wrap_u = EggTexture::WM_unspecified;
39  _wrap_v = EggTexture::WM_unspecified;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: TexturePosition::Copy Constructor
44 // Access: Public
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 TexturePosition::
48 TexturePosition(const TexturePosition &copy) :
49  _margin(copy._margin),
50  _x(copy._x),
51  _y(copy._y),
52  _x_size(copy._x_size),
53  _y_size(copy._y_size),
54  _min_uv(copy._min_uv),
55  _max_uv(copy._max_uv),
56  _wrap_u(copy._wrap_u),
57  _wrap_v(copy._wrap_v)
58 {
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: TexturePosition::Copy Assignment Operator
63 // Access: Public
64 // Description:
65 ////////////////////////////////////////////////////////////////////
66 void TexturePosition::
67 operator = (const TexturePosition &copy) {
68  _margin = copy._margin;
69  _x = copy._x;
70  _y = copy._y;
71  _x_size = copy._x_size;
72  _y_size = copy._y_size;
73  _min_uv = copy._min_uv;
74  _max_uv = copy._max_uv;
75  _wrap_u = copy._wrap_u;
76  _wrap_v = copy._wrap_v;
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: TexturePosition::register_with_read_factory
81 // Access: Public, Static
82 // Description: Registers the current object as something that can be
83 // read from a Bam file.
84 ////////////////////////////////////////////////////////////////////
88  register_factory(get_class_type(), make_TexturePosition);
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: TexturePosition::write_datagram
93 // Access: Public, Virtual
94 // Description: Fills the indicated datagram up with a binary
95 // representation of the current object, in preparation
96 // for writing to a Bam file.
97 ////////////////////////////////////////////////////////////////////
99 write_datagram(BamWriter *writer, Datagram &datagram) {
100  TypedWritable::write_datagram(writer, datagram);
101  datagram.add_int32(_margin);
102  datagram.add_int32(_x);
103  datagram.add_int32(_y);
104  datagram.add_int32(_x_size);
105  datagram.add_int32(_y_size);
106  datagram.add_float64(_min_uv[0]);
107  datagram.add_float64(_min_uv[1]);
108  datagram.add_float64(_max_uv[0]);
109  datagram.add_float64(_max_uv[1]);
110  datagram.add_int32((int)_wrap_u);
111  datagram.add_int32((int)_wrap_v);
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: TexturePosition::make_TexturePosition
116 // Access: Protected
117 // Description: This method is called by the BamReader when an object
118 // of this type is encountered in a Bam file; it should
119 // allocate and return a new object with all the data
120 // read.
121 ////////////////////////////////////////////////////////////////////
122 TypedWritable* TexturePosition::
123 make_TexturePosition(const FactoryParams &params) {
125  DatagramIterator scan;
126  BamReader *manager;
127 
128  parse_params(params, scan, manager);
129  me->fillin(scan, manager);
130  return me;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: TexturePosition::fillin
135 // Access: Protected
136 // Description: Reads the binary data from the given datagram
137 // iterator, which was written by a previous call to
138 // write_datagram().
139 ////////////////////////////////////////////////////////////////////
142  TypedWritable::fillin(scan, manager);
143  _margin = scan.get_int32();
144  _x = scan.get_int32();
145  _y = scan.get_int32();
146  _x_size = scan.get_int32();
147  _y_size = scan.get_int32();
148  _min_uv[0] = scan.get_float64();
149  _min_uv[1] = scan.get_float64();
150  _max_uv[0] = scan.get_float64();
151  _max_uv[1] = scan.get_float64();
152  _wrap_u = (EggTexture::WrapMode)scan.get_int32();
153  _wrap_v = (EggTexture::WrapMode)scan.get_int32();
154 }
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
Definition: datagram.I:228
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
This represents a particular position of a texture within a PaletteImage.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
PN_int32 get_int32()
Extracts a signed 32-bit integer.
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.
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43