diff options
38 files changed, 170 insertions, 105 deletions
diff --git a/o3d/converter/cross/converter.cc b/o3d/converter/cross/converter.cc index 511b69f..981b129 100644 --- a/o3d/converter/cross/converter.cc +++ b/o3d/converter/cross/converter.cc @@ -298,7 +298,7 @@ bool Verify(const FilePath& in_filename, // shader to the given output file, if there is one. if (options.condition && !out_filename.empty()) { if (file_util::WriteFile(out_filename, shader_source_in.c_str(), - shader_source_in.size()) == -1) { + static_cast<int>(shader_source_in.size())) == -1) { O3D_ERROR(&service_locator) << "Warning: Could not write to output file '" << FilePathToUTF8(in_filename).c_str() << "'"; } diff --git a/o3d/core/cross/bitmap.cc b/o3d/core/cross/bitmap.cc index a5feafe..947d68ea 100644 --- a/o3d/core/cross/bitmap.cc +++ b/o3d/core/cross/bitmap.cc @@ -125,7 +125,7 @@ void Bitmap::Allocate(Texture::Format format, } DCHECK(!cube_map || (width == height)); DCHECK_LE(num_mipmaps, GetMipMapCount(width, height)); - DCHECK_GT(num_mipmaps, 0); + DCHECK_GT(num_mipmaps, 0u); format_ = format; width_ = width; @@ -223,7 +223,7 @@ bool Bitmap::LoadFromFile(const FilePath &filepath, DLOG(ERROR) << "bitmap file is too large \"" << filename << "\""; return false; } - size_t file_length = file_size64; + size_t file_length = static_cast<size_t>(file_size64); // Load the compressed image data into memory MemoryBuffer<uint8> file_contents(file_length); @@ -318,7 +318,7 @@ Bitmap::ImageFileType Bitmap::GetFileTypeFromMimeType(const char *mime_type) { void Bitmap::XYZToXYZA(unsigned char *image_data, int pixel_count) { // We do this pixel by pixel, starting from the end to avoid overlapping // problems. - for (unsigned int i = pixel_count - 1; i < pixel_count; --i) { + for (int i = pixel_count - 1; i >= 0; --i) { image_data[i*4+3] = 0xff; image_data[i*4+2] = image_data[i*3+2]; image_data[i*4+1] = image_data[i*3+1]; @@ -327,7 +327,7 @@ void Bitmap::XYZToXYZA(unsigned char *image_data, int pixel_count) { } void Bitmap::RGBAToBGRA(unsigned char *image_data, int pixel_count) { - for (unsigned int i = 0; i < pixel_count; ++i) { + for (int i = 0; i < pixel_count; ++i) { unsigned char c = image_data[i*4+0]; image_data[i*4+0] = image_data[i*4+2]; image_data[i*4+2] = c; @@ -384,7 +384,7 @@ static void FilterTexel(unsigned int x, // NOTE: all of our formats use at most 4 components per pixel. // Instead of dynamically allocating a buffer for each pixel on the heap, // just allocate the worst case on the stack. - DCHECK_LE(components, 4); + DCHECK_LE(components, 4u); uint64 accum[4] = {0}; for (unsigned int src_x = src_min_x; src_x <= src_max_x; ++src_x) { for (unsigned int src_y = src_min_y; src_y <= src_max_y; ++src_y) { @@ -429,7 +429,8 @@ static void FilterTexel(unsigned int x, for (unsigned int c = 0; c < components; ++c) { uint64 value = accum[c] / (src_height * src_width); DCHECK_LE(value, 255); - dst_data[(y * dst_width + x) * components + c] = value; + dst_data[(y * dst_width + x) * components + c] = + static_cast<unsigned char>(value); } } @@ -455,7 +456,7 @@ bool Bitmap::GenerateMipmaps(unsigned int base_width, DLOG(ERROR) << "Mip-map generation not supported for format: " << format; return false; } - DCHECK_GE(std::max(base_width, base_height) >> (num_mipmaps-1), 1); + DCHECK_GE(std::max(base_width, base_height) >> (num_mipmaps-1), 1u); unsigned char *mip_data = data; unsigned int mip_width = base_width; unsigned int mip_height = base_height; diff --git a/o3d/core/cross/bitmap_png.cc b/o3d/core/cross/bitmap_png.cc index a3e10b6..de86a5d 100644 --- a/o3d/core/cross/bitmap_png.cc +++ b/o3d/core/cross/bitmap_png.cc @@ -35,7 +35,6 @@ // precompiled header must appear before anything else. #include "core/cross/precompile.h" -#include <png.h> #include <fstream> #include "core/cross/bitmap.h" #include "core/cross/types.h" @@ -44,6 +43,7 @@ #include "base/file_util.h" #include "import/cross/memory_buffer.h" #include "import/cross/memory_stream.h" +#include "png.h" using file_util::OpenFile; using file_util::CloseFile; diff --git a/o3d/core/cross/buffer_test.cc b/o3d/core/cross/buffer_test.cc index fa11f46..002c955 100644 --- a/o3d/core/cross/buffer_test.cc +++ b/o3d/core/cross/buffer_test.cc @@ -482,10 +482,10 @@ TEST_F(BufferTest, TestVertexBufferFromRawData) { // Write out the data for each field float float_data[kNumElements * 3] = { - 1.2, 2.3, 4.7, - -4.1, 3.14, 17.8, - 17.3, -4.7, -1.1 , - -0.1, 0.123, 5.720 + 1.2f, 2.3f, 4.7f, + -4.1f, 3.14f, 17.8f, + 17.3f, -4.7f, -1.1f, + -0.1f, 0.123f, 5.720f }; uint32 int_data[kNumElements * 2] = { diff --git a/o3d/core/cross/canvas_shader.cc b/o3d/core/cross/canvas_shader.cc index 1ce3aa1..9a5cb93 100644 --- a/o3d/core/cross/canvas_shader.cc +++ b/o3d/core/cross/canvas_shader.cc @@ -105,7 +105,7 @@ SkShader* CanvasLinearGradient::MakeNativeShader() { return NULL; } scoped_ptr<SkColor> colors(new SkColor[colors_.size()]); - for (int ii = 0; ii < colors_.size(); ii++) { + for (std::vector<Float4>::size_type ii = 0; ii < colors_.size(); ii++) { (colors.get())[ii] = Float4ToSkColor(colors_[ii]); } scoped_ptr<SkScalar> positions; @@ -117,7 +117,7 @@ SkShader* CanvasLinearGradient::MakeNativeShader() { return NULL; } positions.reset(new SkScalar[positions_.size()]); - for (int ii = 0; ii < positions_.size(); ii++) { + for (std::vector<float>::size_type ii = 0; ii < positions_.size(); ii++) { (positions.get())[ii] = SkFloatToScalar(positions_[ii]); } } else { diff --git a/o3d/core/cross/client.cc b/o3d/core/cross/client.cc index daa4626..341ff915 100644 --- a/o3d/core/cross/client.cc +++ b/o3d/core/cross/client.cc @@ -224,7 +224,8 @@ void Client::RenderClient() { // If nothing was rendered and there are no render graph nodes then // clear the client area. if (!rendergraph_root || rendergraph_root->children().empty()) { - renderer_->Clear(Float4(0.4, 0.3, 0.3, 1), true, 1.0, true, 0, true); + renderer_->Clear(Float4(0.4f, 0.3f, 0.3f, 1.0f), + true, 1.0, true, 0, true); } else if (rendergraph_root) { RenderTree(rendergraph_root); } @@ -259,7 +260,8 @@ void Client::RenderClient() { // Update render metrics metric_render_elapsed_time.AddSample( // Convert to ms. static_cast<int>(1000 * render_event_.elapsed_time())); - metric_render_time_seconds += render_event_.render_time(); + metric_render_time_seconds += static_cast<uint64>( + render_event_.render_time()); metric_render_xforms_culled.AddSample(render_event_.transforms_culled()); metric_render_xforms_processed.AddSample( render_event_.transforms_processed()); diff --git a/o3d/core/cross/curve_test.cc b/o3d/core/cross/curve_test.cc index f258208..e1e25d6 100644 --- a/o3d/core/cross/curve_test.cc +++ b/o3d/core/cross/curve_test.cc @@ -635,15 +635,15 @@ struct KeyInfo { } // anonymous namespace static const BezierKey bezier_data_0[] = { - { 0.083333, 3, 0.013888, -2.66667, 0.152778, 8.66667, }, - { 0.291667, 20, 0.222222, -9.22377, 0.388889, 60.9133, }, - { 0.583333, -5, 0.486111, 3.33333, 0.680556, -13.3333, } + { 0.083333f, 3, 0.013888f, -2.66667f, 0.152778f, 8.66667f, }, + { 0.291667f, 20, 0.222222f, -9.22377f, 0.388889f, 60.9133f, }, + { 0.583333f, -5, 0.486111f, 3.33333f, 0.680556f, -13.3333f, } }; static const BezierKey bezier_data_1[] = { - { 0.083333, 3, 0.013888, -2.66667, 0.152778, 8.66667, }, - { 0.291667, 20, 0.222222, -9.22377, 0.740598, 19.9773, }, - { 0.583333, -5, 0.486111, 3.33333, 0.680556, -13.3333, }, + { 0.083333f, 3, 0.013888f, -2.66667f, 0.152778f, 8.66667f, }, + { 0.291667f, 20, 0.222222f, -9.22377f, 0.740598f, 19.9773f, }, + { 0.583333f, -5, 0.486111f, 3.33333f, 0.680556f, -13.3333f, }, }; static const ExpectedResult expected_results_0[] = { @@ -798,8 +798,8 @@ TEST_F(CurveTest, CurveRawDataIncomplete) { MemoryWriteStream write_stream(buffer, kDataLength); write_stream.WriteLittleEndianInt32(1); // version 1 write_stream.WriteByte(3); // bezier - write_stream.WriteLittleEndianFloat32(3.4); - write_stream.WriteLittleEndianFloat32(1.7); + write_stream.WriteLittleEndianFloat32(3.4f); + write_stream.WriteLittleEndianFloat32(1.7f); // but DON'T write the tangent data // make note of amount we've written @@ -834,7 +834,7 @@ TEST_F(CurveTest, CurveRawDataValid) { // Write out some bezier data (one that we tested above) size_t n = arraysize(bezier_data_0); - for (int i = 0; i < n; ++i) { + for (size_t i = 0; i < n; ++i) { const BezierKey &key = bezier_data_0[i]; write_stream.WriteByte(3); // bezier diff --git a/o3d/core/cross/effect_test.cc b/o3d/core/cross/effect_test.cc index 9913ffb..af028e6 100644 --- a/o3d/core/cross/effect_test.cc +++ b/o3d/core/cross/effect_test.cc @@ -285,22 +285,22 @@ TEST_F(EffectTest, CreateAndDestroyEffect) { ParamFloat3 *lightpos = shape->CreateParam<ParamFloat3>("lightworldPos"); EXPECT_TRUE(lightpos != NULL); - lightpos->set_value(Float3(0.2, 10.5, -3.14)); + lightpos->set_value(Float3(0.2f, 10.5f, -3.14f)); ParamFloat4 *lightcolor = shape->CreateParam<ParamFloat4>("lightColor"); EXPECT_TRUE(lightcolor != NULL); - lightcolor->set_value(Float4(0.8, 0.2, 0.655, 1.0)); + lightcolor->set_value(Float4(0.8f, 0.2f, 0.655f, 1.0f)); ParamFloat4 *emissive = shape->CreateParam<ParamFloat4>("emissive"); EXPECT_TRUE(emissive != NULL); - emissive->set_value(Float4(0.0, 0.0, 0.0, 1.0)); + emissive->set_value(Float4(0.0f, 0.0f, 0.0f, 1.0f)); ParamFloat4 *ambient = shape->CreateParam<ParamFloat4>("ambient"); EXPECT_TRUE(ambient != NULL); - ambient->set_value(Float4(0.25, 0.25, 0.35, 1.0)); + ambient->set_value(Float4(0.25f, 0.25f, 0.35f, 1.0f)); String filepath = *g_program_path + "/unittest_data/rock01.tga"; Texture *texture = pack->CreateTextureFromFile(filepath, @@ -332,7 +332,7 @@ TEST_F(EffectTest, GetEffectParameters) { fx->GetParameterInfo(&info); EXPECT_EQ(arraysize(expected_params), info.size()); - for (int ii = 0; ii < info.size(); ++ii) { + for (EffectParameterInfoArray::size_type ii = 0; ii < info.size(); ++ii) { EXPECT_TRUE(IsExpectedParam(info[ii])); } @@ -354,7 +354,7 @@ TEST_F(EffectTest, GetEffectStreams) { fx->GetStreamInfo(&info); EXPECT_EQ(arraysize(expected_streams), info.size()); - for (int ii = 0; ii < info.size(); ++ii) { + for (EffectStreamInfoArray::size_type ii = 0; ii < info.size(); ++ii) { EXPECT_TRUE(IsExpectedStream(info[ii])); } diff --git a/o3d/core/cross/param.cc b/o3d/core/cross/param.cc index 9e1e157..c5e7907 100644 --- a/o3d/core/cross/param.cc +++ b/o3d/core/cross/param.cc @@ -238,7 +238,7 @@ void Param::IncrementNotCachableCountOnParamChainForInput(Param* input) { ++not_cachable_count_; ParamVector params; GetOutputs(¶ms); - for (int ii = 0; ii < params.size(); ++ii) { + for (ParamVector::size_type ii = 0; ii < params.size(); ++ii) { ++params[ii]->not_cachable_count_; } } @@ -249,7 +249,7 @@ void Param::DecrementNotCachableCountOnParamChainForInput(Param* input) { --not_cachable_count_; ParamVector params; GetOutputs(¶ms); - for (int ii = 0; ii < params.size(); ++ii) { + for (ParamVector::size_type ii = 0; ii < params.size(); ++ii) { --params[ii]->not_cachable_count_; } } diff --git a/o3d/core/cross/ray_intersection_info.cc b/o3d/core/cross/ray_intersection_info.cc index 101fed7..42bd706 100644 --- a/o3d/core/cross/ray_intersection_info.cc +++ b/o3d/core/cross/ray_intersection_info.cc @@ -37,7 +37,7 @@ namespace o3d { -static const float kEpsilon = 0.000001; +static const float kEpsilon = 0.000001f; // TODO: Someone who is better at math, please optimize this. bool RayIntersectionInfo::IntersectTriangle(const Point3& start, diff --git a/o3d/core/cross/renderer.cc b/o3d/core/cross/renderer.cc index 7301945..43362f0 100644 --- a/o3d/core/cross/renderer.cc +++ b/o3d/core/cross/renderer.cc @@ -599,7 +599,7 @@ void Renderer::PushRenderStates(State *state) { // Pops rendering states to back to their previous settings. void Renderer::PopRenderStates() { - DCHECK_GT(state_stack_.size(), 1); + DCHECK_GT(state_stack_.size(), 1u); if (state_stack_.back() != state_stack_[state_stack_.size() - 2]) { State* state = state_stack_.back(); // restore the states the top state object set. diff --git a/o3d/core/cross/skin.cc b/o3d/core/cross/skin.cc index beb28c8..99387ca 100644 --- a/o3d/core/cross/skin.cc +++ b/o3d/core/cross/skin.cc @@ -594,7 +594,7 @@ bool Skin::LoadFromBinaryData(MemoryReadStream *stream) { if (num_influences > 0) { Skin::Influences influences(num_influences); - for (int i = 0; i < num_influences; ++i) { + for (Skin::Influences::size_type i = 0; i < num_influences; ++i) { uint32 matrix_index = stream->ReadLittleEndianInt32(); float weight = stream->ReadLittleEndianFloat32(); influences[i] = Skin::Influence(matrix_index, weight); diff --git a/o3d/core/cross/skin_test.cc b/o3d/core/cross/skin_test.cc index 2f67938..46a4358 100644 --- a/o3d/core/cross/skin_test.cc +++ b/o3d/core/cross/skin_test.cc @@ -692,7 +692,7 @@ TEST_F(SkinTest, SkinRawDataValid) { const Skin::Influences& influences = influences_array[0]; EXPECT_EQ(kNumInfluences, influences.size()); - for (int i = 0; i < influences.size(); ++i) { + for (Skin::Influences::size_type i = 0; i < influences.size(); ++i) { const Skin::Influence &influence = influences[i]; EXPECT_EQ(i, influence.matrix_index); float expected_weight = 1.0f + 0.2f * static_cast<float>(i); diff --git a/o3d/core/win/d3d9/buffer_d3d9.h b/o3d/core/win/d3d9/buffer_d3d9.h index dfce1bf..89c499e 100644 --- a/o3d/core/win/d3d9/buffer_d3d9.h +++ b/o3d/core/win/d3d9/buffer_d3d9.h @@ -37,6 +37,7 @@ #include <d3d9.h> #include <atlbase.h> +#include "base/scoped_ptr.h" #include "core/cross/buffer.h" namespace o3d { diff --git a/o3d/core/win/d3d9/stream_bank_d3d9.cc b/o3d/core/win/d3d9/stream_bank_d3d9.cc index 2405532..52868fc 100644 --- a/o3d/core/win/d3d9/stream_bank_d3d9.cc +++ b/o3d/core/win/d3d9/stream_bank_d3d9.cc @@ -90,7 +90,8 @@ bool StreamBankD3D9::CheckForMissingVertexStreams( DCHECK(missing_semantic_index); EffectStreamInfoArray streamInfos; effect->GetStreamInfo(&streamInfos); - for (int i = 0; i < streamInfos.size(); ++i) { + for (EffectStreamInfoArray::size_type i = 0; + i < streamInfos.size(); ++i) { Stream::Semantic semantic = streamInfos[i].semantic(); int semantic_index = streamInfos[i].semantic_index(); StreamParamVector::const_iterator iter; diff --git a/o3d/core/win/d3d9/texture_d3d9.cc b/o3d/core/win/d3d9/texture_d3d9.cc index 2364d74..1e8bad6 100644 --- a/o3d/core/win/d3d9/texture_d3d9.cc +++ b/o3d/core/win/d3d9/texture_d3d9.cc @@ -293,7 +293,7 @@ Texture2DD3D9::~Texture2DD3D9() { } bool Texture2DD3D9::UpdateBackedMipLevel(unsigned int level) { - DCHECK_LT(level, levels()); + DCHECK_LT(level, static_cast<unsigned int>(levels())); DCHECK(backing_bitmap_.image_data()); DCHECK_EQ(backing_bitmap_.width(), width()); DCHECK_EQ(backing_bitmap_.height(), height()); @@ -562,7 +562,7 @@ TextureCUBED3D9::~TextureCUBED3D9() { bool TextureCUBED3D9::UpdateBackedMipLevel(unsigned int level, TextureCUBE::CubeFace face) { - DCHECK_LT(level, levels()); + DCHECK_LT(level, static_cast<unsigned int>(levels())); DCHECK(backing_bitmap_.image_data()); DCHECK(backing_bitmap_.is_cubemap()); DCHECK_EQ(backing_bitmap_.width(), edge_length()); diff --git a/o3d/import/cross/archive_processor.cc b/o3d/import/cross/archive_processor.cc index f02ef6d..b3abd87 100644 --- a/o3d/import/cross/archive_processor.cc +++ b/o3d/import/cross/archive_processor.cc @@ -38,7 +38,7 @@ #include "base/logging.h" #include "import/cross/memory_buffer.h" -#include "third_party/zlib/files/zlib.h" +#include "zlib.h" const int kChunkSize = 16384; diff --git a/o3d/import/cross/archive_processor.h b/o3d/import/cross/archive_processor.h index 9bc5368..8380c37 100644 --- a/o3d/import/cross/archive_processor.h +++ b/o3d/import/cross/archive_processor.h @@ -62,7 +62,7 @@ class ArchiveCallbackClient { public: virtual ~ArchiveCallbackClient() {} virtual void ReceiveFileHeader(const ArchiveFileInfo &file_info) = 0; - virtual bool ReceiveFileData(MemoryReadStream *stream, int nbytes) = 0; + virtual bool ReceiveFileData(MemoryReadStream *stream, size_t nbytes) = 0; }; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/o3d/import/cross/archive_request.cc b/o3d/import/cross/archive_request.cc index 4ced695..fd75413 100644 --- a/o3d/import/cross/archive_request.cc +++ b/o3d/import/cross/archive_request.cc @@ -1,8 +1,33 @@ -// @@REWRITE(insert c-copyright) -// @@REWRITE(delete-start) -// Copyright 2009 Google Inc. All Rights Reserved. -// Author: crogers@google.com (Chris Rogers) -// @@REWRITE(delete-end) +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ // This file contains the definition of the ArchiveRequest class. @@ -142,7 +167,7 @@ void ArchiveRequest::ReceiveFileHeader(const ArchiveFileInfo &file_info) { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool ArchiveRequest::ReceiveFileData(MemoryReadStream *input_stream, - int nbytes) { + size_t nbytes) { assert(input_stream->GetRemainingByteCount() >= nbytes); assert(file_memory_stream_.GetRemainingByteCount() >= nbytes); diff --git a/o3d/import/cross/archive_request.h b/o3d/import/cross/archive_request.h index 2a29bde..0a73864 100644 --- a/o3d/import/cross/archive_request.h +++ b/o3d/import/cross/archive_request.h @@ -103,7 +103,7 @@ class ArchiveRequest : public ObjectBase, public ArchiveCallbackClient { // ArchiveCallbackClient methods virtual void ReceiveFileHeader(const ArchiveFileInfo &file_info); - virtual bool ReceiveFileData(MemoryReadStream *stream, int nbytes); + virtual bool ReceiveFileData(MemoryReadStream *stream, size_t nbytes); Pack *pack() { return pack_.Get(); // Set at creation time and never changed. diff --git a/o3d/import/cross/collada.cc b/o3d/import/cross/collada.cc index a9cc2e1..b62ae8f 100644 --- a/o3d/import/cross/collada.cc +++ b/o3d/import/cross/collada.cc @@ -344,7 +344,7 @@ bool Collada::ImportDAEDocument(FCDocument* doc, // TODO: Add option to skip this step if user just wants what's // actually used by models. The rest of the code already deals with this. FCDImageLibrary* image_library = doc->GetImageLibrary(); - for (int i = 0; i < image_library->GetEntityCount(); i++) { + for (uint32 i = 0; i < image_library->GetEntityCount(); i++) { FCDEntity* entity = image_library->GetEntity(i); LOG_ASSERT(entity); LOG_ASSERT(entity->GetType() == FCDEntity::IMAGE); @@ -358,7 +358,7 @@ bool Collada::ImportDAEDocument(FCDocument* doc, // TODO: Add option to skip this step if user just wants what's // actually used by models. The rest of the code already deals with this. FCDMaterialLibrary* material_library = doc->GetMaterialLibrary(); - for (int i = 0; i < material_library->GetEntityCount(); i++) { + for (uint32 i = 0; i < material_library->GetEntityCount(); i++) { FCDEntity* entity = material_library->GetEntity(i); LOG_ASSERT(entity); LOG_ASSERT(entity->GetType() == FCDEntity::MATERIAL); diff --git a/o3d/import/cross/collada_conditioner.cc b/o3d/import/cross/collada_conditioner.cc index 484865f..8ba9661 100644 --- a/o3d/import/cross/collada_conditioner.cc +++ b/o3d/import/cross/collada_conditioner.cc @@ -330,7 +330,7 @@ bool ColladaConditioner::HandleNVImport(FCDocument* doc, // For each material which uses this effect, FCDMaterialLibrary* lib = doc->GetMaterialLibrary(); - for (int i = 0; i < lib->GetEntityCount(); ++i) { + for (size_t i = 0; i < lib->GetEntityCount(); ++i) { FCDMaterial* material = lib->GetEntity(i); LOG_ASSERT(material != 0); if (material->GetEffect() == collada_effect) { diff --git a/o3d/import/cross/collada_zip_archive.cc b/o3d/import/cross/collada_zip_archive.cc index 45bc523..f150a4c 100644 --- a/o3d/import/cross/collada_zip_archive.cc +++ b/o3d/import/cross/collada_zip_archive.cc @@ -52,7 +52,7 @@ ColladaZipArchive::ColladaZipArchive(const std::string &zip_filename, GetInformationList(&infolist); bool dae_found = false; - for (int i = 0; i < infolist.size(); ++i) { + for (vector<ZipFileInfo>::size_type i = 0; i < infolist.size(); ++i) { const char *name = infolist[i].name.c_str(); int length = strlen(name); diff --git a/o3d/import/cross/gz_compressor.cc b/o3d/import/cross/gz_compressor.cc index 2352405..6c853e1 100644 --- a/o3d/import/cross/gz_compressor.cc +++ b/o3d/import/cross/gz_compressor.cc @@ -39,7 +39,7 @@ #include <assert.h> #include "import/cross/memory_buffer.h" #include "import/cross/memory_stream.h" -#include "third_party/zlib/files/zutil.h" +#include "zutil.h" const size_t kChunkSize = 16384; @@ -104,7 +104,7 @@ int GzCompressor::CompressBytes(MemoryReadStream *stream, int result = Z_OK; // Don't try to read more than our stream has - int remaining = stream->GetRemainingByteCount(); + size_t remaining = stream->GetRemainingByteCount(); if (bytes_to_process > remaining) { return Z_STREAM_ERROR; } diff --git a/o3d/import/cross/gz_compressor.h b/o3d/import/cross/gz_compressor.h index 7c88657..bdf13a1 100644 --- a/o3d/import/cross/gz_compressor.h +++ b/o3d/import/cross/gz_compressor.h @@ -38,7 +38,7 @@ #define O3D_IMPORT_CROSS_GZ_COMPRESSOR_H_ #include "base/basictypes.h" -#include "third_party/zlib/files/zlib.h" +#include "zlib.h" #include "import/cross/memory_stream.h" namespace o3d { diff --git a/o3d/import/cross/gz_decompressor.cc b/o3d/import/cross/gz_decompressor.cc index 333a999..7fa7fee 100644 --- a/o3d/import/cross/gz_decompressor.cc +++ b/o3d/import/cross/gz_decompressor.cc @@ -74,7 +74,7 @@ int GzDecompressor::ProcessBytes(MemoryReadStream *stream, size_t have; // Don't try to read more than our stream has - int remaining = stream->GetRemainingByteCount(); + size_t remaining = stream->GetRemainingByteCount(); if (bytes_to_process > remaining) { return Z_STREAM_ERROR; // could have our own error code, but good enough... } diff --git a/o3d/import/cross/gz_decompressor.h b/o3d/import/cross/gz_decompressor.h index 833a7b3..bd56687 100644 --- a/o3d/import/cross/gz_decompressor.h +++ b/o3d/import/cross/gz_decompressor.h @@ -38,7 +38,7 @@ #define O3D_IMPORT_CROSS_GZ_DECOMPRESSOR_H_ #include "base/basictypes.h" -#include "third_party/zlib/files/zlib.h" +#include "zlib.h" #include "import/cross/memory_stream.h" namespace o3d { diff --git a/o3d/import/cross/raw_data.cc b/o3d/import/cross/raw_data.cc index 067ff70..53039c2 100644 --- a/o3d/import/cross/raw_data.cc +++ b/o3d/import/cross/raw_data.cc @@ -145,7 +145,7 @@ const char* GetValidUTF8(const RawData& data, size_t* utf8_length) { // It's a multi-byte character if (c >= 0xC2 && c <= 0xF4) { uint32 codepoint; - int remaining_code_length = 0; + size_t remaining_code_length = 0; if ((c & 0xE0) == 0xC0) { codepoint = c & 0x1F; remaining_code_length = 1; @@ -161,7 +161,7 @@ const char* GetValidUTF8(const RawData& data, size_t* utf8_length) { return NULL; } length -= remaining_code_length; - for (int cc = 0; cc < remaining_code_length; ++cc) { + for (size_t cc = 0; cc < remaining_code_length; ++cc) { c = *s++; if ((c & 0xC0) != 0x80) { // Not valid UTF-8 @@ -268,6 +268,9 @@ static String GetUUIDString() { // and format into a wide-string char guid_string[37]; +#if defined(OS_WIN) +#define snprintf _snprintf +#endif snprintf( guid_string, sizeof(guid_string) / sizeof(guid_string[0]), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", diff --git a/o3d/import/cross/tar_generator.cc b/o3d/import/cross/tar_generator.cc index 019ec0e..f59306d 100644 --- a/o3d/import/cross/tar_generator.cc +++ b/o3d/import/cross/tar_generator.cc @@ -35,6 +35,10 @@ using std::string; +#if defined(OS_WIN) + #define snprintf _snprintf +#endif + namespace o3d { const int kMaxFilenameSize = 100; @@ -94,24 +98,24 @@ void TarGenerator::AddEntry(const String &file_name, strncpy(p, file_name.c_str(), kMaxFilenameSize - 1); // File mode - snprintf(p + kFileModeOffset, 8, "%07o", is_directory ? 0755 : 0644); + ::snprintf(p + kFileModeOffset, 8, "%07o", is_directory ? 0755 : 0644); // UserID - snprintf(p + kUserIDOffset, 8, "%07o", 0765); + ::snprintf(p + kUserIDOffset, 8, "%07o", 0765); // GroupID - snprintf(p + kGroupIDOffset, 8, "%07o", 0204); + ::snprintf(p + kGroupIDOffset, 8, "%07o", 0204); // File size - snprintf(p + kFileSizeOffset, 12, "%011o", file_size); + ::snprintf(p + kFileSizeOffset, 12, "%011o", file_size); // Modification time // TODO: write the correct current time here... - snprintf(p + kModifyTimeOffset, 12, "%07o", 011131753141); + ::snprintf(p + kModifyTimeOffset, 12, "%07o", 011131753141); // Initialize Header checksum so check sum can be computed // by ComputeCheckSum() which will fill in the value here - memset(p + kHeaderCheckSumOffset, 32, 8); + ::memset(p + kHeaderCheckSumOffset, 32, 8); // We only support ordinary files and directories, which is fine // for our use case @@ -119,13 +123,13 @@ void TarGenerator::AddEntry(const String &file_name, p[kLinkFlagOffset] = link_flag; // Magic offset - snprintf(p + kMagicOffset, 8, "ustar "); + ::snprintf(p + kMagicOffset, 8, "ustar "); // User name - snprintf(p + kUserNameOffset, 32, "guest"); + ::snprintf(p + kUserNameOffset, 32, "guest"); // Group name - snprintf(p + kGroupNameOffset, 32, "staff"); + ::snprintf(p + kGroupNameOffset, 32, "staff"); // This has to be done at the end diff --git a/o3d/import/cross/tar_processor_test.cc b/o3d/import/cross/tar_processor_test.cc index 120aef3..3e7afaa 100644 --- a/o3d/import/cross/tar_processor_test.cc +++ b/o3d/import/cross/tar_processor_test.cc @@ -60,7 +60,7 @@ class TarTestClient : public ArchiveCallbackClient { explicit TarTestClient() : file_count_(0), index_(0) {} // ArchiveCallbackClient methods virtual void ReceiveFileHeader(const ArchiveFileInfo &file_info); - virtual bool ReceiveFileData(MemoryReadStream *stream, int nbytes); + virtual bool ReceiveFileData(MemoryReadStream *stream, size_t nbytes); int GetFileCount() const { return file_count_; } size_t GetNumTotalBytesReceived() const { return index_; } @@ -91,7 +91,7 @@ void TarTestClient::ReceiveFileHeader(const ArchiveFileInfo &file_info) { } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bool TarTestClient::ReceiveFileData(MemoryReadStream *stream, int nbytes) { +bool TarTestClient::ReceiveFileData(MemoryReadStream *stream, size_t nbytes) { const char *p = reinterpret_cast<const char*>( stream->GetDirectMemoryPointer()); diff --git a/o3d/import/cross/targz_processor.h b/o3d/import/cross/targz_processor.h index 56b5427..ef83278 100644 --- a/o3d/import/cross/targz_processor.h +++ b/o3d/import/cross/targz_processor.h @@ -41,8 +41,7 @@ #include "import/cross/archive_processor.h" #include "import/cross/gz_decompressor.h" #include "import/cross/tar_processor.h" - -#include "third_party/zlib/files/zlib.h" +#include "zlib.h" namespace o3d { diff --git a/o3d/import/cross/targz_processor_test.cc b/o3d/import/cross/targz_processor_test.cc index fd98f27..5fc5914 100644 --- a/o3d/import/cross/targz_processor_test.cc +++ b/o3d/import/cross/targz_processor_test.cc @@ -59,7 +59,7 @@ class ArchiveTestClient : public ArchiveCallbackClient { explicit ArchiveTestClient() : file_count_(0), index_(0) {} // ArchiveCallbackClient methods virtual void ReceiveFileHeader(const ArchiveFileInfo &file_info); - virtual bool ReceiveFileData(MemoryReadStream *stream, int nbytes); + virtual bool ReceiveFileData(MemoryReadStream *stream, size_t nbytes); int GetFileCount() const { return file_count_; } size_t GetNumTotalBytesReceived() const { return index_; } @@ -90,7 +90,8 @@ void ArchiveTestClient::ReceiveFileHeader(const ArchiveFileInfo &file_info) { } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -bool ArchiveTestClient::ReceiveFileData(MemoryReadStream *stream, int nbytes) { +bool ArchiveTestClient::ReceiveFileData(MemoryReadStream *stream, + size_t nbytes) { const char *p = reinterpret_cast<const char*>( stream->GetDirectMemoryPointer()); diff --git a/o3d/import/cross/zip_archive.cc b/o3d/import/cross/zip_archive.cc index 275722f..cd7f0455 100644 --- a/o3d/import/cross/zip_archive.cc +++ b/o3d/import/cross/zip_archive.cc @@ -58,6 +58,11 @@ using std::vector; using std::string; +#if defined(OS_WIN) +// Windows #defines this... +#undef DeleteFile +#endif + #ifndef ALLOW_USER_QUERY #define ALLOW_USER_QUERY 0 // 1: ask before overwriting files #endif @@ -203,10 +208,17 @@ int ZipArchive::Extract() { const char *dirname = NULL; if (opt_do_extract == 1) { - if (opt_extractdir && chdir(dirname)) { +#if defined(OS_WIN) + if (opt_extractdir && ::_chdir(dirname)) { + DEBUGLOG("Error changing into %s, aborting\n", dirname); + exit(-1); + } +#else + if (opt_extractdir && ::chdir(dirname)) { DEBUGLOG("Error changing into %s, aborting\n", dirname); exit(-1); } +#endif if (filename_to_extract == NULL) { return DoExtract(opt_do_extract_withoutpath, @@ -221,6 +233,7 @@ int ZipArchive::Extract() { } unzCloseCurrentFile(zip_file_ref_); + return 1; } // Extracts a single file to disk @@ -294,9 +307,9 @@ char *ZipArchive::GetFileData(const string &filename, size_t *size) { // as string data and doesn't harm anything else buffer = reinterpret_cast<char*>(malloc(file_info.uncompressed_size + 1)); buffer[file_info.uncompressed_size] = 0; - int buffer_index = 0; + uint32 buffer_index = 0; - int nbytes; + uint32 nbytes; do { nbytes = unzReadCurrentFile(uf, temp_buffer, kBufferChunkSize); if (nbytes < 0) { @@ -511,7 +524,7 @@ int ZipArchive::DoExtract(int opt_extract_without_path, int result = unzGetGlobalInfo(zip_file_ref_, &gi); if (result != UNZ_OK) - DEBUGLOG("error %d with zipfile in unzGetGlobalInfo \n", result); + DEBUGLOG("error %d with zipfile in unzGetGlobalInfo \n", result) for (uLong i = 0; i < gi.number_entry; ++i) { if (ExtractCurrentFile(&opt_extract_without_path, @@ -522,7 +535,7 @@ int ZipArchive::DoExtract(int opt_extract_without_path, if ((i + 1) < gi.number_entry) { result = unzGoToNextFile(zip_file_ref_); if (result != UNZ_OK) { - DEBUGLOG("error %d with zipfile in unzGoToNextFile\n", result); + DEBUGLOG("error %d with zipfile in unzGoToNextFile\n", result) break; } } @@ -551,7 +564,7 @@ void ZipArchive::ChangeFileDate(const char *filename, SetFileTime(hFile, &ftm, &ftLastAcc, &ftm); CloseHandle(hFile); #else -#ifdef unix +#if defined(OS_LINUX) || defined(OS_MACOSX) struct utimbuf ut; struct tm newdate; newdate.tm_sec = tmu_date.tm_sec; @@ -577,11 +590,11 @@ void ZipArchive::ChangeFileDate(const char *filename, int ZipArchive::MyMkDir(const char *dirname) { int ret = 0; -#ifdef WIN32 - ret = mkdir(dirname); +#if defined(OS_WIN) + ret = ::_mkdir(dirname); #else -#ifdef unix - ret = mkdir(dirname, 0775); +#if defined(OS_LINUX) || defined(OS_MACOSX) + ret = ::mkdir(dirname, 0775); #endif #endif return ret; @@ -642,7 +655,7 @@ int ZipArchive::Print() { printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); - for (int i = 0; i < gi.number_entry; ++i) { + for (uint32 i = 0; i < gi.number_entry; ++i) { char filename_inzip[MAXFILENAME]; ZipFileInfo file_info; result = unzGetCurrentFileInfo(zip_file_ref_, @@ -801,7 +814,7 @@ bool ZipArchive::GetTempFileFromFile(const string &filename, char *data = GetFileData(filename, &data_size); if (data) { -#ifdef OS_WIN +#if defined(OS_WIN) // get the temp directory char temp_path[MAX_PATH]; if (!GetTempPathA(MAX_PATH, temp_path)) { @@ -814,7 +827,7 @@ bool ZipArchive::GetTempFileFromFile(const string &filename, // and format into a wide-string char guid_string[37]; - snprintf( + ::_snprintf( guid_string, sizeof(guid_string) / sizeof(guid_string[0]), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", guid.Data1, guid.Data2, guid.Data3, @@ -828,14 +841,14 @@ bool ZipArchive::GetTempFileFromFile(const string &filename, int dot_position = filename.rfind('.'); if (dot_position != string::npos) { // try to retain the original file suffix (.jpg, etc.) - snprintf(fullpath, MAX_PATH, "%s%s%s", - temp_path, - guid_string, - filename.substr(dot_position).c_str()); + ::_snprintf(fullpath, MAX_PATH, "%s%s%s", + temp_path, + guid_string, + filename.substr(dot_position).c_str()); } else { - snprintf(fullpath, MAX_PATH, "%s\\%s", - temp_path, - guid_string); + ::_snprintf(fullpath, MAX_PATH, "%s\\%s", + temp_path, + guid_string); } FILE *tempfile = fopen(fullpath, "wb"); @@ -872,5 +885,9 @@ bool ZipArchive::GetTempFileFromFile(const string &filename, } void ZipArchive::DeleteFile(const string &filename) { - unlink(filename.c_str()); +#if defined(OS_WIN) + ::_unlink(filename.c_str()); +#else + ::unlink(filename.c_str()); +#endif } diff --git a/o3d/import/cross/zip_archive.h b/o3d/import/cross/zip_archive.h index 4c55539..aa3f9bc 100644 --- a/o3d/import/cross/zip_archive.h +++ b/o3d/import/cross/zip_archive.h @@ -108,11 +108,12 @@ #include <string> #include <vector> -#ifdef OS_MACOSX -#define unix -#endif +#include "contrib/minizip/unzip.h" -#include "third_party/zlib/files/contrib/minizip/unzip.h" +#if defined(OS_WIN) +// Windows #defines this. +#undef DeleteFile +#endif // structure containing the unz_file_info information plus the file name struct ZipFileInfo : public unz_file_info { diff --git a/o3d/import/win/collada_conditioner_win.cc b/o3d/import/win/collada_conditioner_win.cc index e9d3ebb..0d99319 100644 --- a/o3d/import/win/collada_conditioner_win.cc +++ b/o3d/import/win/collada_conditioner_win.cc @@ -114,7 +114,7 @@ bool ColladaConditioner::PreprocessShaderFile(const FilePath& in_filename, // Have to dup the string because CreateProcessW might modify the // contents. - wchar_t* buf = ::wcsdup(cmd.c_str()); + wchar_t* buf = ::_wcsdup(cmd.c_str()); // Initialize structure to zero with default array initializer. PROCESS_INFORMATION process_info = {0}; diff --git a/o3d/utils/cross/file_text_reader.cc b/o3d/utils/cross/file_text_reader.cc index 39e5057..314be5e 100644 --- a/o3d/utils/cross/file_text_reader.cc +++ b/o3d/utils/cross/file_text_reader.cc @@ -171,7 +171,12 @@ std::string FileTextReader::ReadToEnd() { size_t FileTextReader::GetFileSize() const { struct stat file_info; - ::fstat(::fileno(input_), &file_info); +#if defined(OS_WIN) + int file_number = ::_fileno(input_); +#else + int file_number = ::fileno(input_); +#endif + ::fstat(file_number, &file_info); return file_info.st_size; } diff --git a/o3d/utils/cross/file_text_reader_test.cc b/o3d/utils/cross/file_text_reader_test.cc index b87e61d..3bf1415 100644 --- a/o3d/utils/cross/file_text_reader_test.cc +++ b/o3d/utils/cross/file_text_reader_test.cc @@ -95,7 +95,12 @@ class FileTextReaderTest : public testing::Test { if (file_pointers_[i]) { ::fclose(file_pointers_[i]); } - ::unlink((tmp_base + kFileInfo[i].file_name_).c_str()); + std::string path = tmp_base + kFileInfo[i].file_name_; +#if defined(OS_WIN) + ::_unlink(path.c_str()); +#else + ::unlink(path.c_str()); +#endif file_pointers_[i] = NULL; } } diff --git a/o3d/utils/cross/json_writer.cc b/o3d/utils/cross/json_writer.cc index 784d728..a49700e 100644 --- a/o3d/utils/cross/json_writer.cc +++ b/o3d/utils/cross/json_writer.cc @@ -210,7 +210,7 @@ void JsonWriter::WritePending() { } void JsonWriter::WriteEscapedString(const string& unescaped) { - for (int i = 0; i < unescaped.length(); ++i) { + for (string::size_type i = 0; i < unescaped.length(); ++i) { char c = unescaped[i]; switch (c) { case '\"': |