From 8d3e59576ac1f184095e1eb4c0bf9cf5370feb4e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 27 Feb 2010 17:27:18 +0000 Subject: [PATCH] Make buildings implement IScenery and remove IBuilding --- include/IBuilding.hpp | 44 ------------------------------------- include/IBuildingPicker.hpp | 4 ++-- include/IMap.hpp | 3 +-- include/IScenery.hpp | 7 +++--- src/Building.cpp | 12 +++++----- src/BuildingPicker.cpp | 6 ++--- src/Editor.cpp | 1 - src/Map.cpp | 6 ++--- src/Tree.cpp | 8 +++---- 9 files changed, 23 insertions(+), 68 deletions(-) delete mode 100644 include/IBuilding.hpp diff --git a/include/IBuilding.hpp b/include/IBuilding.hpp deleted file mode 100644 index 9bce3e9..0000000 --- a/include/IBuilding.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// -// Copyright (C) 2009 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 -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#ifndef INC_IBUILDING_HPP -#define INC_IBUILDING_HPP - -#include "Platform.hpp" -#include "IModel.hpp" -#include "IXMLSerialisable.hpp" - -#include - -// Interface to buildings and other bits of scenery -struct IBuilding : IXMLSerialisable { - virtual ~IBuilding() {} - - virtual const string& name() const = 0; - virtual void render() const = 0; - virtual void setAngle(float a) = 0; - virtual void setPosition(float x, float y, float z) = 0; -}; - -typedef shared_ptr IBuildingPtr; - -class AttributeSet; - -IBuildingPtr loadBuilding(const string& aResId, float angle); -IBuildingPtr loadBuilding(const AttributeSet& attrs); - -#endif diff --git a/include/IBuildingPicker.hpp b/include/IBuildingPicker.hpp index 76ed10d..8a8b9b1 100644 --- a/include/IBuildingPicker.hpp +++ b/include/IBuildingPicker.hpp @@ -20,13 +20,13 @@ #include "Platform.hpp" #include "gui/ILayout.hpp" -#include "IBuilding.hpp" +#include "IScenery.hpp" // A dialog box for picking buildings in the editor struct IBuildingPicker { virtual ~IBuildingPicker() {} - virtual IBuildingPtr get() const = 0; + virtual ISceneryPtr get() const = 0; }; typedef shared_ptr IBuildingPickerPtr; diff --git a/include/IMap.hpp b/include/IMap.hpp index e73ba15..a2b6857 100644 --- a/include/IMap.hpp +++ b/include/IMap.hpp @@ -22,7 +22,6 @@ #include "ITrackSegment.hpp" #include "IStation.hpp" #include "IResource.hpp" -#include "IBuilding.hpp" #include "IScenery.hpp" #include "Colour.hpp" @@ -105,7 +104,7 @@ public: Point aFinishPos) = 0; // Place a building at this location - virtual void placeBuilding(Point point, IBuildingPtr building) = 0; + virtual void placeBuilding(Point point, ISceneryPtr building) = 0; // Get the height above ground at a particular point virtual float heightAt(float x, float y) const = 0; diff --git a/include/IScenery.hpp b/include/IScenery.hpp index 2bcff4e..4c26e75 100644 --- a/include/IScenery.hpp +++ b/include/IScenery.hpp @@ -27,10 +27,8 @@ struct IScenery : IXMLSerialisable { virtual void render() const = 0; virtual void setPosition(float x, float y, float z) = 0; - - // Don't need these: what about buildings??? virtual void setAngle(float angle) = 0; - virtual const string& resId() const = 0; + virtual const string& name() const = 0; }; typedef shared_ptr ISceneryPtr; @@ -40,4 +38,7 @@ class AttributeSet; ISceneryPtr loadTree(const string& name); ISceneryPtr loadTree(const AttributeSet& attrs); +ISceneryPtr loadBuilding(const string& aResId, float angle); +ISceneryPtr loadBuilding(const AttributeSet& attrs); + #endif diff --git a/src/Building.cpp b/src/Building.cpp index 5ff1728..92c0ce9 100644 --- a/src/Building.cpp +++ b/src/Building.cpp @@ -15,22 +15,22 @@ // along with this program. If not, see . // -#include "IBuilding.hpp" +#include "IScenery.hpp" #include "IResource.hpp" #include "ResourceCache.hpp" #include "ILogger.hpp" #include "IXMLParser.hpp" #include "XMLBuilder.hpp" #include "OpenGLHelper.hpp" +#include "IModel.hpp" // Concrete implementation of buildings -class Building : public IBuilding, public IXMLCallback { +class Building : public IScenery, public IXMLCallback { public: Building(IResourcePtr aRes); // IBuildingInterface const string& name() const { return name_; } - string resId() const { return resource->name(); } void render() const; void setAngle(float a) { angle = a; } void setPosition(float x, float y, float z); @@ -97,17 +97,17 @@ namespace { } } -IBuildingPtr loadBuilding(const string& aResId, float angle) +ISceneryPtr loadBuilding(const string& aResId, float angle) { static ResourceCache cache(loadBuildingXml, "buildings"); shared_ptr bld = cache.loadCopy(aResId); bld->setAngle(angle); - return IBuildingPtr(bld); + return ISceneryPtr(bld); } -IBuildingPtr loadBuilding(const AttributeSet& attrs) +ISceneryPtr loadBuilding(const AttributeSet& attrs) { float angle; string name; diff --git a/src/BuildingPicker.cpp b/src/BuildingPicker.cpp index 3fd9cf5..ccc2ce9 100644 --- a/src/BuildingPicker.cpp +++ b/src/BuildingPicker.cpp @@ -29,7 +29,7 @@ private: void next(); void prev(); void rotate(); - IBuildingPtr get() const; + ISceneryPtr get() const; void renderBuildingPreview(gui::Widget& canvas); void show(); void hide(); @@ -38,7 +38,7 @@ private: ResourceList buildingList; ResourceList::const_iterator buildingIt; - IBuildingPtr activeBuilding; + ISceneryPtr activeBuilding; gui::ILayoutPtr layout; float rotation; string resName; @@ -103,7 +103,7 @@ void BuildingPicker::hide() layout->get("/building_wnd").visible(false); } -IBuildingPtr BuildingPicker::get() const +ISceneryPtr BuildingPicker::get() const { return loadBuilding(resName, rotation); } diff --git a/src/Editor.cpp b/src/Editor.cpp index 894a682..8f3889b 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -21,7 +21,6 @@ #include "IMap.hpp" #include "Maths.hpp" #include "ILight.hpp" -#include "IBuilding.hpp" #include "gui/ILayout.hpp" #include "IBuildingPicker.hpp" diff --git a/src/Map.cpp b/src/Map.cpp index cd0167a..359b25d 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -108,7 +108,7 @@ public: IStationPtr extendStation(Point aStartPos, Point aFinishPos); - void placeBuilding(Point point, IBuildingPtr building); + void placeBuilding(Point point, ISceneryPtr building); float heightAt(float x, float y) const; void addScenery(Point where, ISceneryPtr s); @@ -124,7 +124,7 @@ private: // TODO: Better to use a boost::variant here? TrackNodePtr track; // Track at this location, if any IStationPtr station; // Station on this tile, if any - IBuildingPtr building; // Building on this tile, if any + ISceneryPtr building; // Building on this tile, if any ISceneryPtr tree; // Tree, if any } *tiles; @@ -1022,7 +1022,7 @@ void Map::lowerArea(const Point& aStartPos, changeAreaHeight(aStartPos, aFinishPos, -0.1f); } -void Map::placeBuilding(Point point, IBuildingPtr building) +void Map::placeBuilding(Point point, ISceneryPtr building) { // TODO: level? if (tileAt(point).track) diff --git a/src/Tree.cpp b/src/Tree.cpp index 9a35789..419bf45 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -38,7 +38,7 @@ public: void render() const; void setPosition(float x, float y, float z); void setAngle(float a) { angle = a; } - const string& resId() const { return name; } + const string& name() const { return name_; } // IXMLCallback interface void text(const string& localName, const string& content); @@ -50,7 +50,7 @@ private: Vector position; IModelPtr model; float angle; - string name; + string name_; struct ParserState { string modelFile; @@ -86,7 +86,7 @@ void Tree::text(const string& localName, const string& content) "Expected tree name to be '" + expectedName + "' but found'" + content + "' in XML"); else - name = content; + name_ = content; } } @@ -110,7 +110,7 @@ xml::element Tree::toXml() const { return xml::element("tree") .addAttribute("angle", angle) - .addAttribute("name", name); + .addAttribute("name", name_); } namespace { -- 2.39.2