Give several additional classes constexpr constructors

This is useful because these types are created at static init time, and giving them a constexpr constructor and trivial destructor lets them be created during constant initialization, which helps to prevent static init ordering issues.
This commit is contained in:
rdb 2018-06-01 21:56:38 +02:00
parent 21d8c29645
commit 298147bb39
11 changed files with 29 additions and 119 deletions

View File

@ -11,21 +11,6 @@
* @date 2003-01-27 * @date 2003-01-27
*/ */
/**
*
*/
INLINE FrameBufferProperties::
FrameBufferProperties(const FrameBufferProperties &copy) {
(*this) = copy;
}
/**
*
*/
INLINE FrameBufferProperties::
~FrameBufferProperties() {
}
/** /**
* *
*/ */

View File

@ -17,28 +17,6 @@
#include "config_display.h" #include "config_display.h"
#include "texture.h" #include "texture.h"
/**
*
*/
FrameBufferProperties::
FrameBufferProperties() {
clear();
}
/**
*
*/
void FrameBufferProperties::
operator = (const FrameBufferProperties &copy) {
_flags_specified = copy._flags_specified;
_flags = copy._flags;
_specified = copy._specified;
for (int i = 0; i < FBP_COUNT; ++i) {
_property[i] = copy._property[i];
}
}
/** /**
* Returns true if this set of properties makes strictly greater or equal * Returns true if this set of properties makes strictly greater or equal
* demands of the framebuffer than the other set of framebuffer properties. * demands of the framebuffer than the other set of framebuffer properties.

View File

@ -63,11 +63,11 @@ private:
FBF_all = 0x100-1, FBF_all = 0x100-1,
}; };
int _property[FBP_COUNT]; int _property[FBP_COUNT] = {0};
int _specified; int _specified = 0;
int _flags; int _flags = 0;
int _flags_specified; int _flags_specified = 0;
PUBLISHED: PUBLISHED:
@ -145,10 +145,8 @@ PUBLISHED:
// Other. // Other.
FrameBufferProperties(); constexpr FrameBufferProperties() = default;
INLINE FrameBufferProperties(const FrameBufferProperties &copy);
INLINE ~FrameBufferProperties();
void operator = (const FrameBufferProperties &copy);
static const FrameBufferProperties &get_default(); static const FrameBufferProperties &get_default();
bool operator == (const FrameBufferProperties &other) const; bool operator == (const FrameBufferProperties &other) const;
INLINE bool operator != (const FrameBufferProperties &other) const; INLINE bool operator != (const FrameBufferProperties &other) const;

View File

@ -17,26 +17,3 @@
static EggParameters default_egg_parameters; static EggParameters default_egg_parameters;
EggParameters *egg_parameters = &default_egg_parameters; EggParameters *egg_parameters = &default_egg_parameters;
/**
* Initializes all the parameters with default values.
*/
EggParameters::
EggParameters() {
_pos_threshold = 0.0001;
_normal_threshold = 0.0001;
_uv_threshold = 0.0001;
_color_threshold = 1.0/256.0;
_table_threshold = 0.0001;
}
/**
*
*/
EggParameters::
EggParameters(const EggParameters &other) {
memcpy(this, &other, sizeof(EggParameters));
}

View File

@ -31,28 +31,27 @@
*/ */
class EXPCL_PANDAEGG EggParameters { class EXPCL_PANDAEGG EggParameters {
public: public:
EggParameters(); constexpr EggParameters() = default;
EggParameters(const EggParameters &copy);
// The per-component difference below which two vertices are deemed to be at // The per-component difference below which two vertices are deemed to be at
// the same position. // the same position.
double _pos_threshold; double _pos_threshold = 0.0001;
// The per-component difference below which two vertices are deemed to have // The per-component difference below which two vertices are deemed to have
// the same normal. // the same normal.
double _normal_threshold; double _normal_threshold = 0.0001;
// The per-component difference below which two vertices are deemed to have // The per-component difference below which two vertices are deemed to have
// the same texture coordinates. // the same texture coordinates.
double _uv_threshold; double _uv_threshold = 0.0001;
// The per-component difference below which two vertices are deemed to have // The per-component difference below which two vertices are deemed to have
// the same color. // the same color.
PN_stdfloat _color_threshold; PN_stdfloat _color_threshold = 1.0/256.0;
// The per-component difference below which two anim table values are deemed // The per-component difference below which two anim table values are deemed
// to be equivalent. // to be equivalent.
double _table_threshold; double _table_threshold = 0.0001;
}; };
extern EXPCL_PANDAEGG EggParameters *egg_parameters; extern EXPCL_PANDAEGG EggParameters *egg_parameters;

View File

@ -17,7 +17,7 @@
INLINE void CacheStats:: INLINE void CacheStats::
maybe_report(const char *name) { maybe_report(const char *name) {
#ifndef NDEBUG #ifndef NDEBUG
if (_cache_report) { if (UNLIKELY(_cache_report)) {
double now = ClockObject::get_global_clock()->get_real_time(); double now = ClockObject::get_global_clock()->get_real_time();
if (now - _last_reset < _cache_report_interval) { if (now - _last_reset < _cache_report_interval) {
return; return;

View File

@ -22,10 +22,7 @@ void CacheStats::
init() { init() {
#ifndef NDEBUG #ifndef NDEBUG
// Let's not use the clock at static init time. // Let's not use the clock at static init time.
reset(0.0); //reset(ClockObject::get_global_clock()->get_real_time());
// reset(ClockObject::get_global_clock()->get_real_time());
_total_cache_size = 0;
_num_states = 0;
_cache_report = ConfigVariableBool("cache-report", false); _cache_report = ConfigVariableBool("cache-report", false);
_cache_report_interval = ConfigVariableDouble("cache-report-interval", 5.0); _cache_report_interval = ConfigVariableDouble("cache-report-interval", 5.0);

View File

@ -24,6 +24,7 @@
*/ */
class EXPCL_PANDA_PGRAPH CacheStats { class EXPCL_PANDA_PGRAPH CacheStats {
public: public:
constexpr CacheStats() = default;
void init(); void init();
void reset(double now); void reset(double now);
void write(ostream &out, const char *name) const; void write(ostream &out, const char *name) const;
@ -38,17 +39,17 @@ public:
private: private:
#ifndef NDEBUG #ifndef NDEBUG
int _cache_hits; int _cache_hits = 0;
int _cache_misses; int _cache_misses = 0;
int _cache_adds; int _cache_adds = 0;
int _cache_new_adds; int _cache_new_adds = 0;
int _cache_dels; int _cache_dels = 0;
int _total_cache_size; int _total_cache_size = 0;
int _num_states; int _num_states = 0;
double _last_reset; double _last_reset = 0.0;
bool _cache_report; bool _cache_report = false;
double _cache_report_interval; double _cache_report_interval = 0.0;
#endif // NDEBUG #endif // NDEBUG
}; };

View File

@ -16,9 +16,9 @@
*/ */
INLINE NodePath:: INLINE NodePath::
NodePath() : NodePath() :
_error_type(ET_ok) _error_type(ET_ok),
_backup_key(0)
{ {
_backup_key = 0;
} }
/** /**

View File

@ -14,7 +14,7 @@
/** /**
* *
*/ */
INLINE LoaderOptions:: constexpr LoaderOptions::
LoaderOptions(int flags, int texture_flags) : LoaderOptions(int flags, int texture_flags) :
_flags(flags), _flags(flags),
_texture_flags(texture_flags), _texture_flags(texture_flags),
@ -23,29 +23,6 @@ LoaderOptions(int flags, int texture_flags) :
{ {
} }
/**
*
*/
INLINE LoaderOptions::
LoaderOptions(const LoaderOptions &copy) :
_flags(copy._flags),
_texture_flags(copy._texture_flags),
_texture_num_views(copy._texture_num_views),
_auto_texture_scale(copy._auto_texture_scale)
{
}
/**
*
*/
INLINE void LoaderOptions::
operator = (const LoaderOptions &copy) {
_flags = copy._flags;
_texture_flags = copy._texture_flags;
_texture_num_views = copy._texture_num_views;
_auto_texture_scale = copy._auto_texture_scale;
}
/** /**
* *
*/ */

View File

@ -49,9 +49,7 @@ PUBLISHED:
}; };
LoaderOptions(int flags = LF_search | LF_report_errors); LoaderOptions(int flags = LF_search | LF_report_errors);
INLINE LoaderOptions(int flags, int texture_flags); constexpr LoaderOptions(int flags, int texture_flags);
INLINE LoaderOptions(const LoaderOptions &copy);
INLINE void operator = (const LoaderOptions &copy);
INLINE void set_flags(int flags); INLINE void set_flags(int flags);
INLINE int get_flags() const; INLINE int get_flags() const;