Squelch some of the type conversion warnings in MSVC

This commit is contained in:
rdb 2015-10-06 17:05:40 +02:00
parent cb7a0e2520
commit 706f6f7de5
12 changed files with 54 additions and 48 deletions

View File

@ -28,7 +28,7 @@ GetInt(const string &sym, int def) {
float DConfig::
GetFloat(const string &sym, float def) {
ConfigVariableDouble var(sym, def, "DConfig", ConfigFlags::F_dconfig);
return var.get_value();
return (float)var.get_value();
}
double DConfig::

View File

@ -142,7 +142,7 @@ cacos(float v) {
////////////////////////////////////////////////////////////////////
INLINE float
cmod(float x, float y) {
return x - cfloor(x / y) * y;
return x - floor(x / y) * y;
}
////////////////////////////////////////////////////////////////////

View File

@ -55,6 +55,8 @@
#pragma warning (disable : 4355)
/* C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data */
#pragma warning (disable : 4244)
/* C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data */
#pragma warning (disable : 4267)
#if _MSC_VER >= 1300
#if _MSC_VER >= 1310

View File

@ -64,5 +64,5 @@ look_up(TypeHandle handle, TypedObject *object) const {
return look_up_invalid(handle, object);
}
#endif
return _handle_registry[handle._index];
return _handle_registry[(size_t)handle._index];
}

View File

@ -311,7 +311,7 @@ set_int_word(int n, int value) {
INLINE void ConfigVariable::
set_int64_word(int n, PN_int64 value) {
nassertv(is_constructed());
_core->make_local_value()->set_int_word(n, value);
_core->make_local_value()->set_int64_word(n, value);
}
////////////////////////////////////////////////////////////////////

View File

@ -240,7 +240,7 @@ set_clear_stencil(const unsigned int stencil) {
////////////////////////////////////////////////////////////////////
INLINE unsigned int DrawableRegion::
get_clear_stencil() const {
return (int)(get_clear_value(RTP_stencil)[0]);
return (unsigned int)(get_clear_value(RTP_stencil)[0]);
}
////////////////////////////////////////////////////////////////////
@ -306,9 +306,9 @@ INLINE void DrawableRegion::
update_pixel_factor() {
PN_stdfloat new_pixel_factor;
if (supports_pixel_zoom()) {
new_pixel_factor = 1.0 / sqrt(max(_pixel_zoom, (PN_stdfloat)1.0));
new_pixel_factor = (PN_stdfloat)1 / sqrt(max(_pixel_zoom, (PN_stdfloat)1.0));
} else {
new_pixel_factor = 1.0;
new_pixel_factor = 1;
}
if (new_pixel_factor != _pixel_factor) {
_pixel_factor = new_pixel_factor;

View File

@ -353,7 +353,7 @@ add_string(const string &str) {
nassertv(str.length() <= (PN_uint16)0xffff);
// Strings always are preceded by their length
add_uint16(str.length());
add_uint16((PN_uint16)str.length());
// Add the string
append_data(str);
@ -368,7 +368,7 @@ add_string(const string &str) {
INLINE void Datagram::
add_string32(const string &str) {
// Strings always are preceded by their length
add_uint32(str.length());
add_uint32((PN_uint32)str.length());
// Add the string
append_data(str);

View File

@ -133,7 +133,7 @@ get_total_cpp_size() {
////////////////////////////////////////////////////////////////////
INLINE size_t MemoryUsage::
get_panda_heap_single_size() {
return AtomicAdjust::get(get_global_ptr()->_total_heap_single_size);
return (size_t)AtomicAdjust::get(get_global_ptr()->_total_heap_single_size);
}
////////////////////////////////////////////////////////////////////
@ -144,7 +144,7 @@ get_panda_heap_single_size() {
////////////////////////////////////////////////////////////////////
INLINE size_t MemoryUsage::
get_panda_heap_array_size() {
return AtomicAdjust::get(get_global_ptr()->_total_heap_array_size);
return (size_t)AtomicAdjust::get(get_global_ptr()->_total_heap_array_size);
}
////////////////////////////////////////////////////////////////////
@ -159,7 +159,7 @@ INLINE size_t MemoryUsage::
get_panda_heap_overhead() {
#if defined(USE_MEMORY_DLMALLOC) || defined(USE_MEMORY_PTMALLOC2)
MemoryUsage *mu = get_global_ptr();
return AtomicAdjust::get(mu->_requested_heap_size) - AtomicAdjust::get(mu->_total_heap_single_size) - AtomicAdjust::get(mu->_total_heap_array_size);
return (size_t)(AtomicAdjust::get(mu->_requested_heap_size) - AtomicAdjust::get(mu->_total_heap_single_size) - AtomicAdjust::get(mu->_total_heap_array_size));
#else
return 0;
#endif
@ -173,7 +173,7 @@ get_panda_heap_overhead() {
////////////////////////////////////////////////////////////////////
INLINE size_t MemoryUsage::
get_panda_mmap_size() {
return AtomicAdjust::get(get_global_ptr()->_total_mmap_size);
return (size_t)AtomicAdjust::get(get_global_ptr()->_total_mmap_size);
}
////////////////////////////////////////////////////////////////////
@ -206,7 +206,7 @@ get_external_size() {
#else
// Without alternative malloc, the Panda allocated memory is also
// included in total_size, so we have to subtract it out.
return mu->_total_size - mu->_total_heap_single_size - mu->_total_heap_array_size;
return mu->_total_size - (size_t)mu->_total_heap_single_size - (size_t)mu->_total_heap_array_size;
#endif
} else {
return 0;
@ -223,12 +223,12 @@ INLINE size_t MemoryUsage::
get_total_size() {
MemoryUsage *mu = get_global_ptr();
if (mu->_count_memory_usage) {
return mu->_total_size + mu->_requested_heap_size;
return mu->_total_size + (size_t)mu->_requested_heap_size;
} else {
#if defined(USE_MEMORY_DLMALLOC) || defined(USE_MEMORY_PTMALLOC2)
return mu->_requested_heap_size;
return (size_t)mu->_requested_heap_size;
#else
return AtomicAdjust::get(mu->_total_heap_single_size) + AtomicAdjust::get(mu->_total_heap_array_size);
return (size_t)(AtomicAdjust::get(mu->_total_heap_single_size) + AtomicAdjust::get(mu->_total_heap_array_size));
#endif
}
}

View File

@ -682,7 +682,7 @@ ShaderPtrData(const LVecBase2i &vec) :
INLINE void Shader::ShaderPtrData::
write_datagram(Datagram &dg) const {
dg.add_uint8(_type);
dg.add_uint32(_size);
dg.add_uint32((PN_uint32)_size);
if (_type == SPT_double) {
const double *data = (const double *) _ptr;
@ -867,7 +867,7 @@ get_filename_from_index(int index, ShaderType type) const {
}
} else if (glsl_preprocess && index >= 2048 &&
(index - 2048) < (int)_included_files.size()) {
return _included_files[index - 2048];
return _included_files[(size_t)index - 2048];
}
// Must be a mistake. Quietly put back the integer.
char str[32];

View File

@ -126,19 +126,23 @@ get_value() const {
switch (get_num_words()) {
case 1:
_cache.set(get_double_word(0), get_double_word(0), get_double_word(0), 1);
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
(PN_stdfloat)get_double_word(0), 1);
break;
case 2:
_cache.set(get_double_word(0), get_double_word(0), get_double_word(0), get_double_word(1));
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
(PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1));
break;
case 3:
_cache.set(get_double_word(0), get_double_word(1), get_double_word(2), 1);
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
(PN_stdfloat)get_double_word(2), 1);
break;
case 4:
_cache.set(get_double_word(0), get_double_word(1), get_double_word(2), get_double_word(3));
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
(PN_stdfloat)get_double_word(2), (PN_stdfloat)get_double_word(3));
break;
default:
@ -161,17 +165,17 @@ get_default_value() const {
if (decl != (ConfigDeclaration *)NULL) {
switch (decl->get_num_words()) {
case 1:
return LColor(decl->get_double_word(0), decl->get_double_word(0),
decl->get_double_word(0), 1);
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
(PN_stdfloat)decl->get_double_word(0), 1);
case 2:
return LColor(decl->get_double_word(0), decl->get_double_word(0),
decl->get_double_word(0), decl->get_double_word(1));
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
(PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1));
case 3:
return LColor(decl->get_double_word(0), decl->get_double_word(1),
decl->get_double_word(2), 1);
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
(PN_stdfloat)decl->get_double_word(2), 1);
case 4:
return LColor(decl->get_double_word(0), decl->get_double_word(1),
decl->get_double_word(2), decl->get_double_word(3));
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
(PN_stdfloat)decl->get_double_word(2), (PN_stdfloat)decl->get_double_word(3));
default:
prc_cat->warning()
<< "Invalid default color value for ConfigVariable "

View File

@ -74,47 +74,47 @@ lcast_to(FLOATTYPE *, const FLOATNAME(LMatrix4) &source) {
INLINE_LINMATH FLOATNAME2(LVecBase2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase2) &source) {
return FLOATNAME2(LVecBase2)(source[0], source[1]);
return FLOATNAME2(LVecBase2)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1]);
}
INLINE_LINMATH FLOATNAME2(LVecBase3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase3) &source) {
return FLOATNAME2(LVecBase3)(source[0], source[1], source[2]);
return FLOATNAME2(LVecBase3)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2]);
}
INLINE_LINMATH FLOATNAME2(LVecBase4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVecBase4) &source) {
return FLOATNAME2(LVecBase4)(source[0], source[1], source[2], source[3]);
return FLOATNAME2(LVecBase4)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2], (FLOATTYPE2)source[3]);
}
INLINE_LINMATH FLOATNAME2(LVector2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector2) &source) {
return FLOATNAME2(LVector2)(source[0], source[1]);
return FLOATNAME2(LVector2)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1]);
}
INLINE_LINMATH FLOATNAME2(LVector3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector3) &source) {
return FLOATNAME2(LVector3)(source[0], source[1], source[2]);
return FLOATNAME2(LVector3)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2]);
}
INLINE_LINMATH FLOATNAME2(LVector4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LVector4) &source) {
return FLOATNAME2(LVector4)(source[0], source[1], source[2], source[3]);
return FLOATNAME2(LVector4)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2], (FLOATTYPE2)source[3]);
}
INLINE_LINMATH FLOATNAME2(LPoint2)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint2) &source) {
return FLOATNAME2(LPoint2)(source[0], source[1]);
return FLOATNAME2(LPoint2)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1]);
}
INLINE_LINMATH FLOATNAME2(LPoint3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint3) &source) {
return FLOATNAME2(LPoint3)(source[0], source[1], source[2]);
return FLOATNAME2(LPoint3)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2]);
}
INLINE_LINMATH FLOATNAME2(LPoint4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LPoint4) &source) {
return FLOATNAME2(LPoint4)(source[0], source[1], source[2], source[3]);
return FLOATNAME2(LPoint4)((FLOATTYPE2)source[0], (FLOATTYPE2)source[1], (FLOATTYPE2)source[2], (FLOATTYPE2)source[3]);
}
INLINE_LINMATH FLOATNAME2(LQuaternion)
@ -125,16 +125,16 @@ lcast_to(FLOATTYPE2 *, const FLOATNAME(LQuaternion) &c) {
INLINE_LINMATH FLOATNAME2(LMatrix3)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix3) &source) {
return FLOATNAME2(LMatrix3)
(source(0, 0), source(0, 1), source(0, 2),
source(1, 0), source(1, 1), source(1, 2),
source(2, 0), source(2, 1), source(2, 2));
((FLOATTYPE2)source(0, 0), (FLOATTYPE2)source(0, 1), (FLOATTYPE2)source(0, 2),
(FLOATTYPE2)source(1, 0), (FLOATTYPE2)source(1, 1), (FLOATTYPE2)source(1, 2),
(FLOATTYPE2)source(2, 0), (FLOATTYPE2)source(2, 1), (FLOATTYPE2)source(2, 2));
}
INLINE_LINMATH FLOATNAME2(LMatrix4)
lcast_to(FLOATTYPE2 *, const FLOATNAME(LMatrix4) &source) {
return FLOATNAME2(LMatrix4)
(source(0, 0), source(0, 1), source(0, 2), source(0, 3),
source(1, 0), source(1, 1), source(1, 2), source(1, 3),
source(2, 0), source(2, 1), source(2, 2), source(2, 3),
source(3, 0), source(3, 1), source(3, 2), source(3, 3));
((FLOATTYPE2)source(0, 0), (FLOATTYPE2)source(0, 1), (FLOATTYPE2)source(0, 2), (FLOATTYPE2)source(0, 3),
(FLOATTYPE2)source(1, 0), (FLOATTYPE2)source(1, 1), (FLOATTYPE2)source(1, 2), (FLOATTYPE2)source(1, 3),
(FLOATTYPE2)source(2, 0), (FLOATTYPE2)source(2, 1), (FLOATTYPE2)source(2, 2), (FLOATTYPE2)source(2, 3),
(FLOATTYPE2)source(3, 0), (FLOATTYPE2)source(3, 1), (FLOATTYPE2)source(3, 2), (FLOATTYPE2)source(3, 3));
}

View File

@ -319,7 +319,7 @@ relative_angle_rad(const FLOATNAME(LVector3) &other) const {
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
relative_angle_deg(const FLOATNAME(LVector3) &other) const {
return relative_angle_rad(other)*180/3.1415926535;
return relative_angle_rad(other) * FLOATCONST(180.0) / FLOATCONST(3.1415926535);
}
#endif // FLOATTYPE_IS_INT