Panda3D
 All Classes Functions Variables Enumerations
loaderOptions.cxx
1 // Filename: loaderOptions.cxx
2 // Created by: drose (05Oct05)
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 "loaderOptions.h"
16 #include "config_util.h"
17 #include "indent.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: LoaderOptions::Constructor
21 // Access: Published
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 LoaderOptions::
25 LoaderOptions(int flags) :
26  _flags(flags),
27  _texture_flags(0),
28  _texture_num_views(0),
29  _auto_texture_scale(ATS_unspecified)
30 {
31  // Shadowing the variables in config_util for static init ordering
32  // issues.
33  static ConfigVariableBool *preload_textures;
34  static ConfigVariableBool *preload_simple_textures;
35  if (preload_textures == NULL) {
36  preload_textures = new ConfigVariableBool("preload-textures", true);
37  }
38  if (preload_simple_textures == NULL) {
39  preload_simple_textures = new ConfigVariableBool("preload-simple-textures", false);
40  }
41 
42  if (*preload_textures) {
43  _texture_flags |= TF_preload;
44  }
45  if (*preload_simple_textures) {
46  _texture_flags |= TF_preload_simple;
47  }
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: LoaderOptions::output
52 // Access: Published
53 // Description:
54 ////////////////////////////////////////////////////////////////////
55 void LoaderOptions::
56 output(ostream &out) const {
57  out << "LoaderOptions(";
58 
59  string sep = "";
60  write_flag(out, sep, "LF_search", LF_search);
61  write_flag(out, sep, "LF_report_errors", LF_report_errors);
62  if ((_flags & LF_convert_anim) == LF_convert_anim) {
63  write_flag(out, sep, "LF_convert_anim", LF_convert_anim);
64  } else {
65  write_flag(out, sep, "LF_convert_skeleton", LF_convert_skeleton);
66  write_flag(out, sep, "LF_convert_channels", LF_convert_channels);
67  }
68  if ((_flags & LF_no_cache) == LF_no_cache) {
69  write_flag(out, sep, "LF_no_cache", LF_no_cache);
70  } else {
71  write_flag(out, sep, "LF_no_disk_cache", LF_no_disk_cache);
72  write_flag(out, sep, "LF_no_ram_cache", LF_no_ram_cache);
73  }
74  write_flag(out, sep, "LF_allow_instance", LF_allow_instance);
75  if (sep.empty()) {
76  out << "0";
77  }
78 
79  out << ", ";
80 
81  sep = "";
82  write_texture_flag(out, sep, "TF_preload", TF_preload);
83  write_texture_flag(out, sep, "TF_preload_simple", TF_preload_simple);
84  write_texture_flag(out, sep, "TF_allow_1d", TF_allow_1d);
85  write_texture_flag(out, sep, "TF_generate_mipmaps", TF_generate_mipmaps);
86  if (sep.empty()) {
87  out << "0";
88  }
89 
90  if (_auto_texture_scale != ATS_unspecified) {
91  out << ", ATS_" << _auto_texture_scale;
92  }
93 
94  out << ")";
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: LoaderOptions::write_flag
99 // Access: Private
100 // Description: Used to implement output().
101 ////////////////////////////////////////////////////////////////////
102 void LoaderOptions::
103 write_flag(ostream &out, string &sep,
104  const string &flag_name, int flag) const {
105  if ((_flags & flag) == flag) {
106  out << sep << flag_name;
107  sep = " | ";
108  }
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: LoaderOptions::write_texture_flag
113 // Access: Private
114 // Description: Used to implement output().
115 ////////////////////////////////////////////////////////////////////
116 void LoaderOptions::
117 write_texture_flag(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.