Panda3D
Loading...
Searching...
No Matches
logicOpAttrib.cxx
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 logicOpAttrib.I
10 * @author rdb
11 * @date 2016-03-24
12 */
13
14#include "logicOpAttrib.h"
16#include "dcast.h"
17#include "bamReader.h"
18#include "bamWriter.h"
19#include "datagram.h"
20#include "datagramIterator.h"
21
22TypeHandle LogicOpAttrib::_type_handle;
23int LogicOpAttrib::_attrib_slot;
24
25/**
26 * Constructs a new LogicOpAttrib object that disables special-effect
27 * blending, allowing normal transparency to be used instead.
28 */
29CPT(RenderAttrib) LogicOpAttrib::
30make_off() {
32}
33
34/**
35 * Constructs a new LogicOpAttrib object with the given logic operation.
36 */
37CPT(RenderAttrib) LogicOpAttrib::
38make(LogicOpAttrib::Operation op) {
39 LogicOpAttrib *attrib = new LogicOpAttrib(op);
40 return return_new(attrib);
41}
42
43/**
44 * Returns a RenderAttrib that corresponds to whatever the standard default
45 * properties for render attributes of this type ought to be.
46 */
47CPT(RenderAttrib) LogicOpAttrib::
48make_default() {
50}
51
52/**
53 *
54 */
55void LogicOpAttrib::
56output(std::ostream &out) const {
57 out << get_type() << ":" << get_operation();
58}
59
60/**
61 * Intended to be overridden by derived LogicOpAttrib types to return a
62 * unique number indicating whether this LogicOpAttrib is equivalent to the
63 * other one.
64 *
65 * This should return 0 if the two LogicOpAttrib objects are equivalent, a
66 * number less than zero if this one should be sorted before the other one,
67 * and a number greater than zero otherwise.
68 *
69 * This will only be called with two LogicOpAttrib objects whose get_type()
70 * functions return the same.
71 */
72int LogicOpAttrib::
73compare_to_impl(const RenderAttrib *other) const {
74 const LogicOpAttrib *la = (const LogicOpAttrib *)other;
75 return (int)_op - (int)la->_op;
76}
77
78/**
79 * Intended to be overridden by derived RenderAttrib types to return a unique
80 * hash for these particular properties. RenderAttribs that compare the same
81 * with compare_to_impl(), above, should return the same hash; RenderAttribs
82 * that compare differently should return a different hash.
83 */
84size_t LogicOpAttrib::
85get_hash_impl() const {
86 size_t hash = 0;
87 hash = int_hash::add_hash(hash, (int)_op);
88 return hash;
89}
90
91/**
92 * Tells the BamReader how to create objects of type LogicOpAttrib.
93 */
96 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
97}
98
99/**
100 * Writes the contents of this object to the datagram for shipping out to a
101 * Bam file.
102 */
104write_datagram(BamWriter *manager, Datagram &dg) {
105 RenderAttrib::write_datagram(manager, dg);
106
107 dg.add_uint8(_op);
108}
109
110/**
111 * This function is called by the BamReader's factory when a new object of
112 * type LogicOpAttrib is encountered in the Bam file. It should create the
113 * LogicOpAttrib and extract its information from the file.
114 */
115TypedWritable *LogicOpAttrib::
116make_from_bam(const FactoryParams &params) {
117 LogicOpAttrib *attrib = new LogicOpAttrib(O_none);
118 DatagramIterator scan;
119 BamReader *manager;
120
121 parse_params(params, scan, manager);
122 attrib->fillin(scan, manager);
123
124 return attrib;
125}
126
127/**
128 * This internal function is called by make_from_bam to read in all of the
129 * relevant data from the BamFile for the new LogicOpAttrib.
130 */
131void LogicOpAttrib::
132fillin(DatagramIterator &scan, BamReader *manager) {
133 RenderAttrib::fillin(scan, manager);
134
135 _op = (Operation)scan.get_uint8();
136}
137
138/**
139 *
140 */
141std::ostream &
142operator << (std::ostream &out, LogicOpAttrib::Operation op) {
143 switch (op) {
144 case LogicOpAttrib::O_none:
145 return out << "none";
146
147 case LogicOpAttrib::O_clear:
148 return out << "clear";
149
150 case LogicOpAttrib::O_and:
151 return out << "and";
152
153 case LogicOpAttrib::O_and_reverse:
154 return out << "and_reverse";
155
156 case LogicOpAttrib::O_copy:
157 return out << "copy";
158
159 case LogicOpAttrib::O_and_inverted:
160 return out << "and_inverted";
161
162 case LogicOpAttrib::O_noop:
163 return out << "noop";
164
165 case LogicOpAttrib::O_xor:
166 return out << "xor";
167
168 case LogicOpAttrib::O_or:
169 return out << "or";
170
171 case LogicOpAttrib::O_nor:
172 return out << "nor";
173
174 case LogicOpAttrib::O_equivalent:
175 return out << "equivalent";
176
177 case LogicOpAttrib::O_invert:
178 return out << "invert";
179
180 case LogicOpAttrib::O_or_reverse:
181 return out << "or_reverse";
182
183 case LogicOpAttrib::O_copy_inverted:
184 return out << "copy_inverted";
185
186 case LogicOpAttrib::O_or_inverted:
187 return out << "or_inverted";
188
189 case LogicOpAttrib::O_nand:
190 return out << "nand";
191
192 case LogicOpAttrib::O_set:
193 return out << "set";
194 }
195
196 return out << "**invalid LogicOpAttrib::Operation(" << (int)op << ")**";
197}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
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
A class to retrieve the individual data elements previously stored in a Datagram.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition datagram.I:50
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
If enabled, specifies that a custom logical operation be performed instead of any color blending.
get_operation
Returns the logic operation specified by this attribute.
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 LogicOpAttrib.
const RenderAttrib * get_slot_default(int slot) const
Returns the default RenderAttrib object associated with slot n.
static RenderAttribRegistry * quick_get_global_ptr()
Returns the global_ptr without first ensuring it has been initialized.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.