28 int LightAttrib::_attrib_slot;
35 class CompareLightPriorities {
41 nassertr(la !=
nullptr && lb !=
nullptr, a < b);
46 return la->get_class_priority() > lb->get_class_priority();
56 _on_lights(copy._on_lights),
57 _off_lights(copy._off_lights),
58 _off_all_lights(copy._off_all_lights),
62 Lights::const_iterator it;
63 for (it = _on_lights.begin(); it != _on_lights.end(); ++it) {
64 Light *lobj = (*it).node()->as_light();
65 nassertd(lobj !=
nullptr) continue;
76 Lights::const_iterator it;
77 for (it = _on_lights.begin(); it != _on_lights.end(); ++it) {
81 if (lobj !=
nullptr) {
95 make(LightAttrib::Operation op,
Light *light) {
97 <<
"Using deprecated LightAttrib interface.\n";
103 attrib = make_all_off();
118 nassert_raise(
"invalid operation");
129 make(LightAttrib::Operation op,
Light *light1,
Light *light2) {
131 <<
"Using deprecated LightAttrib interface.\n";
137 attrib = make_all_off();
155 nassert_raise(
"invalid operation");
166 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
169 <<
"Using deprecated LightAttrib interface.\n";
175 attrib = make_all_off();
196 nassert_raise(
"invalid operation");
207 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
210 <<
"Using deprecated LightAttrib interface.\n";
216 attrib = make_all_off();
240 nassert_raise(
"invalid operation");
267 <<
"Using deprecated LightAttrib interface.\n";
272 }
else if (get_num_off_lights() == 0) {
290 <<
"Using deprecated LightAttrib interface.\n";
292 if (get_num_off_lights() == 0) {
293 return get_num_on_lights();
295 return get_num_off_lights();
309 <<
"Using deprecated LightAttrib interface.\n";
311 if (get_num_off_lights() == 0) {
312 return get_on_light(n).node()->as_light();
314 return get_off_light(n).node()->as_light();
329 <<
"Using deprecated LightAttrib interface.\n";
331 if (get_num_off_lights() == 0) {
332 return has_on_light(
NodePath(light->as_node()));
334 return has_off_light(
NodePath(light->as_node()));
345 add_light(
Light *light)
const {
347 <<
"Using deprecated LightAttrib interface.\n";
349 if (get_num_off_lights() == 0) {
350 return add_on_light(
NodePath(light->as_node()));
352 return add_off_light(
NodePath(light->as_node()));
363 remove_light(
Light *light)
const {
365 <<
"Using deprecated LightAttrib interface.\n";
367 if (get_num_off_lights() == 0) {
368 return remove_on_light(
NodePath(light->as_node()));
370 return remove_off_light(
NodePath(light->as_node()));
381 if (_empty_attrib ==
nullptr) {
385 return _empty_attrib;
396 if (_all_off_attrib ==
nullptr) {
398 attrib->_off_all_lights =
true;
399 _all_off_attrib = return_new(attrib);
402 return _all_off_attrib;
410 add_on_light(
const NodePath &light)
const {
413 nassertr(lobj !=
nullptr,
this);
417 std::pair<Lights::iterator, bool> insert_result =
418 attrib->_on_lights.insert(Lights::value_type(light));
419 if (insert_result.second) {
423 attrib->_off_lights.erase(light);
426 return return_new(attrib);
434 remove_on_light(
const NodePath &light)
const {
437 nassertr(lobj !=
nullptr,
this);
440 if (attrib->_on_lights.erase(light)) {
443 return return_new(attrib);
452 if (source == dest) {
458 nassertr(slobj !=
nullptr,
this);
462 nassertr(dlobj !=
nullptr,
this);
466 auto it = attrib->_on_lights.find(source);
467 if (it != attrib->_on_lights.
end()) {
473 return return_new(attrib);
481 add_off_light(
const NodePath &light)
const {
484 nassertr(lobj !=
nullptr,
this);
487 if (!_off_all_lights) {
488 attrib->_off_lights.insert(light);
490 if (attrib->_on_lights.erase(light)) {
493 return return_new(attrib);
501 remove_off_light(
const NodePath &light)
const {
504 attrib->_off_lights.erase(light);
505 return return_new(attrib);
514 if (source == dest) {
520 nassertr(slobj !=
nullptr,
this);
524 nassertr(dlobj !=
nullptr,
this);
528 auto it = attrib->_off_lights.find(source);
529 if (it != attrib->_off_lights.
end()) {
535 return return_new(attrib);
544 get_most_important_light()
const {
547 if (_num_non_ambient_lights > 0) {
548 return _sorted_on_lights[0];
558 get_ambient_contribution()
const {
563 Lights::const_iterator li;
564 li = _sorted_on_lights.begin() + _num_non_ambient_lights;
565 for (; li != _sorted_on_lights.end(); ++li) {
580 output(std::ostream &out)
const {
581 out << get_type() <<
":";
582 if (_off_lights.empty()) {
583 if (_on_lights.empty()) {
584 if (_off_all_lights) {
590 if (_off_all_lights) {
599 Lights::const_iterator fi;
600 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
609 if (!_on_lights.empty()) {
614 Lights::const_iterator li;
615 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
629 write(std::ostream &out,
int indent_level)
const {
630 indent(out, indent_level) << get_type() <<
":";
631 if (_off_lights.empty()) {
632 if (_on_lights.empty()) {
633 if (_off_all_lights) {
639 if (_off_all_lights) {
648 Lights::const_iterator fi;
649 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
651 indent(out, indent_level + 2) << light <<
"\n";
654 if (!_on_lights.empty()) {
655 indent(out, indent_level) <<
"on\n";
659 Lights::const_iterator li;
660 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
662 indent(out, indent_level + 2) << light <<
"\n";
681 if (_off_all_lights != ta->_off_all_lights) {
682 return (
int)_off_all_lights - (int)ta->_off_all_lights;
685 Lights::const_iterator li = _on_lights.begin();
686 Lights::const_iterator oli = ta->_on_lights.
begin();
688 while (li != _on_lights.end() && oli != ta->_on_lights.
end()) {
701 if (li != _on_lights.end()) {
704 if (oli != ta->_on_lights.
end()) {
708 Lights::const_iterator fi = _off_lights.begin();
709 Lights::const_iterator ofi = ta->_off_lights.
begin();
711 while (fi != _off_lights.end() && ofi != ta->_off_lights.
end()) {
724 if (fi != _off_lights.end()) {
727 if (ofi != ta->_off_lights.
end()) {
741 get_hash_impl()
const {
744 Lights::const_iterator li;
745 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
754 for (li = _off_lights.begin(); li != _off_lights.end(); ++li) {
777 if (ta->_off_all_lights) {
785 Lights::const_iterator ai = _on_lights.begin();
786 Lights::const_iterator bi = ta->_on_lights.
begin();
787 Lights::const_iterator ci = ta->_off_lights.
begin();
791 std::back_insert_iterator<Lights> result =
792 std::back_inserter(new_attrib->_on_lights);
794 while (ai != _on_lights.end() &&
795 bi != ta->_on_lights.
end() &&
796 ci != ta->_off_lights.
end()) {
805 }
else if ((*ci) < (*ai)) {
817 }
else if ((*bi) < (*ai)) {
833 while (ai != _on_lights.end() && bi != ta->_on_lights.
end()) {
841 }
else if ((*bi) < (*ai)) {
857 while (ai != _on_lights.end() && ci != ta->_off_lights.
end()) {
865 }
else if ((*ci) < (*ai)) {
878 while (ai != _on_lights.end()) {
884 while (bi != ta->_on_lights.
end()) {
891 Lights::const_iterator it;
892 for (it = new_attrib->_on_lights.
begin(); it != new_attrib->_on_lights.
end(); ++it) {
893 Light *lobj = (*it).node()->as_light();
894 nassertd(lobj !=
nullptr) continue;
899 new_attrib->_sort_seq =
UpdateSeq::old();
901 return return_new(new_attrib);
927 _sorted_on_lights.clear();
928 OrderedLights ambient_lights;
930 Lights::const_iterator li;
931 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
936 _sorted_on_lights.push_back(np);
938 ambient_lights.push_back(np);
944 _num_non_ambient_lights = _sorted_on_lights.size();
947 sort(_sorted_on_lights.begin(), _sorted_on_lights.end(),
948 CompareLightPriorities());
953 _sorted_on_lights.insert(_sorted_on_lights.end(),
954 ambient_lights.begin(), ambient_lights.end());
979 Lights::const_iterator fi;
981 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
985 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
986 (*fi).write_datagram(manager, dg);
993 Lights::const_iterator nti;
995 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
999 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
1000 (*nti).write_datagram(manager, dg);
1014 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1015 pi += _off_lights[i].complete_pointers(p_list + pi, manager);
1018 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1019 pi += _on_lights[i].complete_pointers(p_list + pi, manager);
1024 nassertr(aux !=
nullptr, pi);
1027 aux->_off_list.reserve(aux->_num_off_lights);
1028 for (i = 0; i < aux->_num_off_lights; ++i) {
1030 DCAST_INTO_R(node, p_list[pi++], pi);
1031 aux->_off_list.push_back(node);
1034 aux->_on_list.reserve(aux->_num_on_lights);
1035 for (i = 0; i < aux->_num_on_lights; ++i) {
1037 DCAST_INTO_R(node, p_list[pi++], pi);
1038 aux->_on_list.push_back(node);
1057 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1058 int n = areg->
find_node(_off_lights[i]);
1061 _off_lights[i] = areg->
get_node(n);
1065 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1072 Light *lobj = _on_lights[i].node()->as_light();
1073 nassertd(lobj !=
nullptr)
continue;
1080 nassertv(aux !=
nullptr);
1081 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1082 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1086 _off_lights.reserve(aux->_off_list.size());
1087 NodeList::iterator ni;
1088 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1090 int n = areg->
find_node(node->get_type(), node->get_name());
1093 _off_lights.push_back(areg->
get_node(n));
1096 _off_lights.push_back(
NodePath(node));
1100 _on_lights.reserve(aux->_on_list.size());
1101 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1103 int n = areg->
find_node(node->get_type(), node->get_name());
1106 _on_lights.push_back(areg->
get_node(n));
1107 node = _on_lights.back().node();
1110 _on_lights.push_back(
NodePath(node));
1114 nassertd(lobj !=
nullptr)
continue;
1136 attrib->fillin(scan, manager);
1149 RenderAttrib::fillin(scan, manager);
1155 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1156 _off_lights[i].fillin(scan, manager);
1160 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1161 _on_lights[i].fillin(scan, manager);
1164 BamAuxData *aux =
new BamAuxData;
1174 _sorted_on_lights.clear();
1175 _sort_seq = UpdateSeq::old();