Panda3D
Loading...
Searching...
No Matches
loaderOptions.cxx
Go to the documentation of this file.
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 loaderOptions.cxx
10 * @author drose
11 * @date 2005-10-05
12 */
13
14#include "loaderOptions.h"
15#include "config_putil.h"
16#include "indent.h"
17
18using std::string;
19
20/**
21 *
22 */
23LoaderOptions::
24LoaderOptions(int flags) :
25 _flags(flags),
26 _texture_flags(0),
27 _texture_num_views(0),
28 _auto_texture_scale(ATS_unspecified)
29{
30 // Shadowing the variables in config_putil for static init ordering issues.
31 static ConfigVariableBool *preload_textures;
32 static ConfigVariableBool *preload_simple_textures;
33 static ConfigVariableBool *compressed_textures;
34 if (preload_textures == nullptr) {
35 preload_textures = new ConfigVariableBool("preload-textures", true);
36 }
37 if (preload_simple_textures == nullptr) {
38 preload_simple_textures = new ConfigVariableBool("preload-simple-textures", false);
39 }
40 if (compressed_textures == nullptr) {
41 compressed_textures = new ConfigVariableBool("compressed-textures", false);
42 }
43
44 if (*preload_textures) {
45 _texture_flags |= TF_preload;
46 }
47 if (*preload_simple_textures) {
48 _texture_flags |= TF_preload_simple;
49 }
50 if (*compressed_textures) {
51 _texture_flags |= TF_allow_compression;
52 }
53}
54
55/**
56 *
57 */
58void LoaderOptions::
59output(std::ostream &out) const {
60 out << "LoaderOptions(";
61
62 string sep = "";
63 write_flag(out, sep, "LF_search", LF_search);
64 write_flag(out, sep, "LF_report_errors", LF_report_errors);
65 if ((_flags & LF_convert_anim) == LF_convert_anim) {
66 write_flag(out, sep, "LF_convert_anim", LF_convert_anim);
67 } else {
68 write_flag(out, sep, "LF_convert_skeleton", LF_convert_skeleton);
69 write_flag(out, sep, "LF_convert_channels", LF_convert_channels);
70 }
71 if ((_flags & LF_no_cache) == LF_no_cache) {
72 write_flag(out, sep, "LF_no_cache", LF_no_cache);
73 } else {
74 write_flag(out, sep, "LF_no_disk_cache", LF_no_disk_cache);
75 write_flag(out, sep, "LF_no_ram_cache", LF_no_ram_cache);
76 }
77 write_flag(out, sep, "LF_allow_instance", LF_allow_instance);
78 if (sep.empty()) {
79 out << "0";
80 }
81
82 out << ", ";
83
84 sep = "";
85 write_texture_flag(out, sep, "TF_preload", TF_preload);
86 write_texture_flag(out, sep, "TF_preload_simple", TF_preload_simple);
87 write_texture_flag(out, sep, "TF_allow_1d", TF_allow_1d);
88 write_texture_flag(out, sep, "TF_generate_mipmaps", TF_generate_mipmaps);
89 write_texture_flag(out, sep, "TF_allow_compression", TF_allow_compression);
90 if (sep.empty()) {
91 out << "0";
92 }
93
94 if (_auto_texture_scale != ATS_unspecified) {
95 out << ", ATS_" << _auto_texture_scale;
96 }
97
98 out << ")";
99}
100
101/**
102 * Used to implement output().
103 */
104void LoaderOptions::
105write_flag(std::ostream &out, string &sep,
106 const string &flag_name, int flag) const {
107 if ((_flags & flag) == flag) {
108 out << sep << flag_name;
109 sep = " | ";
110 }
111}
112
113/**
114 * Used to implement output().
115 */
116void LoaderOptions::
117write_texture_flag(std::ostream &out, string &sep,
118 const string &flag_name, int flag) const {
119 if ((_texture_flags & flag) == flag) {
120 out << sep << flag_name;
121 sep = " | ";
122 }
123}
This is a convenience class to specialize ConfigVariable as a boolean type.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.