From 6573061fe45a481450506326a78569652337a4d3 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 13 Aug 2010 13:59:24 +0100 Subject: [PATCH] Calculate tile size of buildings Use it to connect anchor to all covered tiles --- include/IScenery.hpp | 3 ++- src/Building.cpp | 10 ++++++++-- src/Map.cpp | 19 ++++++++++++------- src/Tree.cpp | 6 ++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/IScenery.hpp b/include/IScenery.hpp index ff6cc62..6664d25 100644 --- a/include/IScenery.hpp +++ b/include/IScenery.hpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ struct IScenery : IXMLSerialisable { virtual void set_angle(float angle) = 0; virtual void merge(IMeshBufferPtr buf) = 0; virtual const string& name() const = 0; + virtual Point size() const = 0; }; typedef shared_ptr ISceneryPtr; diff --git a/src/Building.cpp b/src/Building.cpp index 2959d4f..a52c19f 100644 --- a/src/Building.cpp +++ b/src/Building.cpp @@ -35,6 +35,7 @@ public: void set_angle(float a) { angle = a; } void set_position(float x, float y, float z); void merge(IMeshBufferPtr buf); + Point size() const; // IXMLSerialisable interface xml::element to_xml() const; @@ -66,10 +67,15 @@ Building::Building(IResourcePtr a_res) model_ = load_model(a_res, parser_state->model_file, 1.0f, shift); + delete parser_state; +} + +Point Building::size() const +{ Vector dim = model_->dimensions(); - debug() << name_ << " " << dim; - delete parser_state; + return make_point(max(static_cast(round(dim.x)), 1), + max(static_cast(round(dim.z)), 1)); } void Building::set_position(float x, float y, float z) diff --git a/src/Map.cpp b/src/Map.cpp index 077ac02..df4e134 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -669,15 +669,14 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) for (int y = bot_left.y; y < top_right.y; y++) { Tile& tile = tile_at(x, y); - if (tile.scenery) + if (tile.scenery && tile.scenery->needs_rendering(frame_num)) { tile.scenery->get()->merge(buf); + tile.scenery->rendered_on(frame_num); + } // Draw the track, if any if (tile.track && tile.track->needs_rendering(frame_num)) { - // TODO: how will this work with track that spans - // multiple sectors? tile.track->get()->merge(buf); - tile.track->rendered_on(frame_num); } } @@ -1332,13 +1331,19 @@ void Map::add_scenery(Point where, ISceneryPtr s) warn() << "Cannot place scenery on track"; else { SceneryAnchor indirect(new Anchor(s, where)); + + const Point size = s->size(); + + for (int x = 0; x < size.x; x++) { + for (int y = 0; y < size.y; y++) { + tile_at(where.x + x, where.y + y).scenery = indirect; + dirty_tile(where.x, where.y); + } + } - tile_at(where.x, where.y).scenery = indirect; s->set_position(static_cast(where.x), height_at(where), static_cast(where.y)); - - dirty_tile(where.x, where.y); } } diff --git a/src/Tree.cpp b/src/Tree.cpp index cfd64dc..1164e85 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -40,6 +40,7 @@ public: void set_angle(float a) { angle = a; } const string& name() const { return name_; } void merge(IMeshBufferPtr buf); + Point size() const; // IXMLCallback interface void text(const string& local_name, const string& content); @@ -91,6 +92,11 @@ void Tree::text(const string& local_name, const string& content) } } +Point Tree::size() const +{ + return make_point(1, 1); +} + void Tree::set_position(float x, float y, float z) { position = make_vector(x, y, z); -- 2.39.2