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);
451 add_off_light(
const NodePath &light)
const {
454 nassertr(lobj !=
nullptr,
this);
457 if (!_off_all_lights) {
458 attrib->_off_lights.insert(light);
460 if (attrib->_on_lights.erase(light)) {
463 return return_new(attrib);
471 remove_off_light(
const NodePath &light)
const {
474 attrib->_off_lights.erase(light);
475 return return_new(attrib);
484 get_most_important_light()
const {
487 if (_num_non_ambient_lights > 0) {
488 return _sorted_on_lights[0];
498 get_ambient_contribution()
const {
503 Lights::const_iterator li;
504 li = _sorted_on_lights.begin() + _num_non_ambient_lights;
505 for (; li != _sorted_on_lights.end(); ++li) {
520 output(std::ostream &out)
const {
521 out << get_type() <<
":";
522 if (_off_lights.empty()) {
523 if (_on_lights.empty()) {
524 if (_off_all_lights) {
530 if (_off_all_lights) {
539 Lights::const_iterator fi;
540 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
549 if (!_on_lights.empty()) {
554 Lights::const_iterator li;
555 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
569 write(std::ostream &out,
int indent_level)
const {
570 indent(out, indent_level) << get_type() <<
":";
571 if (_off_lights.empty()) {
572 if (_on_lights.empty()) {
573 if (_off_all_lights) {
579 if (_off_all_lights) {
588 Lights::const_iterator fi;
589 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
591 indent(out, indent_level + 2) << light <<
"\n";
594 if (!_on_lights.empty()) {
595 indent(out, indent_level) <<
"on\n";
599 Lights::const_iterator li;
600 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
602 indent(out, indent_level + 2) << light <<
"\n";
621 if (_off_all_lights != ta->_off_all_lights) {
622 return (
int)_off_all_lights - (int)ta->_off_all_lights;
625 Lights::const_iterator li = _on_lights.begin();
626 Lights::const_iterator oli = ta->_on_lights.
begin();
628 while (li != _on_lights.end() && oli != ta->_on_lights.
end()) {
641 if (li != _on_lights.end()) {
644 if (oli != ta->_on_lights.
end()) {
648 Lights::const_iterator fi = _off_lights.begin();
649 Lights::const_iterator ofi = ta->_off_lights.
begin();
651 while (fi != _off_lights.end() && ofi != ta->_off_lights.
end()) {
664 if (fi != _off_lights.end()) {
667 if (ofi != ta->_off_lights.
end()) {
681 get_hash_impl()
const {
684 Lights::const_iterator li;
685 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
694 for (li = _off_lights.begin(); li != _off_lights.end(); ++li) {
717 if (ta->_off_all_lights) {
725 Lights::const_iterator ai = _on_lights.begin();
726 Lights::const_iterator bi = ta->_on_lights.
begin();
727 Lights::const_iterator ci = ta->_off_lights.
begin();
731 std::back_insert_iterator<Lights> result =
732 std::back_inserter(new_attrib->_on_lights);
734 while (ai != _on_lights.end() &&
735 bi != ta->_on_lights.
end() &&
736 ci != ta->_off_lights.
end()) {
745 }
else if ((*ci) < (*ai)) {
757 }
else if ((*bi) < (*ai)) {
773 while (ai != _on_lights.end() && bi != ta->_on_lights.
end()) {
781 }
else if ((*bi) < (*ai)) {
797 while (ai != _on_lights.end() && ci != ta->_off_lights.
end()) {
805 }
else if ((*ci) < (*ai)) {
818 while (ai != _on_lights.end()) {
824 while (bi != ta->_on_lights.
end()) {
831 Lights::const_iterator it;
832 for (it = new_attrib->_on_lights.
begin(); it != new_attrib->_on_lights.
end(); ++it) {
833 Light *lobj = (*it).node()->as_light();
834 nassertd(lobj !=
nullptr) continue;
839 new_attrib->_sort_seq =
UpdateSeq::old();
841 return return_new(new_attrib);
867 _sorted_on_lights.clear();
868 OrderedLights ambient_lights;
870 Lights::const_iterator li;
871 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
876 _sorted_on_lights.push_back(np);
878 ambient_lights.push_back(np);
884 _num_non_ambient_lights = _sorted_on_lights.size();
887 sort(_sorted_on_lights.begin(), _sorted_on_lights.end(),
888 CompareLightPriorities());
893 _sorted_on_lights.insert(_sorted_on_lights.end(),
894 ambient_lights.begin(), ambient_lights.end());
919 Lights::const_iterator fi;
921 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
925 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
926 (*fi).write_datagram(manager, dg);
933 Lights::const_iterator nti;
935 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
939 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
940 (*nti).write_datagram(manager, dg);
954 for (
size_t i = 0; i < _off_lights.size(); ++i) {
955 pi += _off_lights[i].complete_pointers(p_list + pi, manager);
958 for (
size_t i = 0; i < _on_lights.size(); ++i) {
959 pi += _on_lights[i].complete_pointers(p_list + pi, manager);
964 nassertr(aux !=
nullptr, pi);
967 aux->_off_list.reserve(aux->_num_off_lights);
968 for (i = 0; i < aux->_num_off_lights; ++i) {
970 DCAST_INTO_R(node, p_list[pi++], pi);
971 aux->_off_list.push_back(node);
974 aux->_on_list.reserve(aux->_num_on_lights);
975 for (i = 0; i < aux->_num_on_lights; ++i) {
977 DCAST_INTO_R(node, p_list[pi++], pi);
978 aux->_on_list.push_back(node);
997 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1001 _off_lights[i] = areg->
get_node(n);
1005 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1012 Light *lobj = _on_lights[i].node()->as_light();
1013 nassertd(lobj !=
nullptr)
continue;
1020 nassertv(aux !=
nullptr);
1021 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1022 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1026 _off_lights.reserve(aux->_off_list.size());
1027 NodeList::iterator ni;
1028 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1030 int n = areg->
find_node(node->get_type(), node->get_name());
1033 _off_lights.push_back(areg->
get_node(n));
1036 _off_lights.push_back(
NodePath(node));
1040 _on_lights.reserve(aux->_on_list.size());
1041 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1043 int n = areg->
find_node(node->get_type(), node->get_name());
1046 _on_lights.push_back(areg->
get_node(n));
1047 node = _on_lights.back().node();
1050 _on_lights.push_back(
NodePath(node));
1054 nassertd(lobj !=
nullptr)
continue;
1076 attrib->fillin(scan, manager);
1089 RenderAttrib::fillin(scan, manager);
1095 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1096 _off_lights[i].fillin(scan, manager);
1100 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1101 _on_lights[i].fillin(scan, manager);
1104 BamAuxData *aux =
new BamAuxData;
1114 _sorted_on_lights.clear();
1115 _sort_seq = UpdateSeq::old();