android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Terrain / RasterTile.hpp
blobca222ee66dc919344d20357599fccda6b4f90ba5
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_RASTERTILE_HPP
25 #define XCSOAR_RASTERTILE_HPP
27 #include "Terrain/RasterBuffer.hpp"
28 #include "Util/NonCopyable.hpp"
30 #include <stdio.h>
32 class RasterTile : private NonCopyable {
33 struct MetaData {
34 unsigned int xstart, ystart, xend, yend;
37 public:
38 unsigned int xstart, ystart, xend, yend;
39 unsigned int width, height;
41 /**
42 * The distance of this tile to the center of the screen. This
43 * attribute is used to determine which tiles should be loaded.
45 unsigned distance;
47 bool request;
49 RasterBuffer buffer;
51 public:
52 RasterTile()
53 :xstart(0), ystart(0), xend(0), yend(0),
54 width(0), height(0) {}
56 void Set(unsigned _xstart, unsigned _ystart,
57 unsigned _xend, unsigned _yend) {
58 xstart = _xstart;
59 ystart = _ystart;
60 xend = _xend;
61 yend = _yend;
62 width = xend - xstart;
63 height = yend - ystart;
66 /**
67 * Permanently disable this tile after a failure.
69 void Clear() {
70 width = height = 0;
71 request = false;
74 bool IsDefined() const {
75 return width > 0 && height > 0;
78 int GetDistance() const {
79 return distance;
82 bool IsRequested() const {
83 return request;
86 void SetRequest() {
87 request = true;
90 void ClearRequest() {
91 request = false;
94 bool SaveCache(FILE *file) const;
95 bool LoadCache(FILE *file);
97 bool CheckTileVisibility(int view_x, int view_y, unsigned view_radius);
99 void Disable() {
100 buffer.Reset();
103 void Enable();
104 bool IsEnabled() const {
105 return buffer.IsDefined();
107 bool IsDisabled() const {
108 return !buffer.IsDefined();
112 * Determine the non-interpolated height at the specified pixel
113 * location.
115 * @param x the pixel column within the tile; may be out of range
116 * @param y the pixel row within the tile; may be out of range
118 gcc_pure
119 short GetHeight(unsigned x, unsigned y) const;
122 * Determine the interpolated height at the specified sub-pixel
123 * location.
125 * @param x the pixel column within the tile; may be out of range
126 * @param y the pixel row within the tile; may be out of range
127 * @param ix the sub-pixel column for interpolation (0..255)
128 * @param iy the sub-pixel row for interpolation (0..255)
130 gcc_pure
131 short GetInterpolatedHeight(unsigned x, unsigned y,
132 unsigned ix, unsigned iy) const;
134 inline short* GetImageBuffer() {
135 return buffer.GetData();
138 bool VisibilityChanged(int view_x, int view_y, unsigned view_radius);
140 void ScanLine(unsigned ax, unsigned ay, unsigned bx, unsigned by,
141 short *dest, unsigned size, bool interpolate) const {
142 buffer.ScanLine(ax - (xstart << 8), ay - (ystart << 8),
143 bx - (xstart << 8), by - (ystart << 8),
144 dest, size, interpolate);
148 #endif