freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShredStorage.h
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #ifndef SHRED_STORAGE_H
21 #define SHRED_STORAGE_H
22 
23 #include <QHash>
24 #include <QThread>
25 
26 class QByteArray;
27 
28 struct LongLat final {
29  LongLat(long longitude, long latitude);
30  bool operator==(const LongLat &) const;
31 
32  LongLat & operator=(const LongLat &) = delete;
33 
34  const long longitude;
35  const long latitude;
36 };
37 
38 class PreloadThread;
39 
40 class ShredStorage final {
41 public:
42  ShredStorage(ushort size, long longi_center, long lati_center);
43  ~ShredStorage();
44 
45  ShredStorage & operator=(const ShredStorage &) = delete;
46  ShredStorage(const ShredStorage &) = delete;
47 
48  QByteArray * GetShredData(long longi, long lati) const;
49  void SetShredData(QByteArray *, long longi, long lati);
50  void Shift(int direction, long longitude, long latitude);
51 
52  void AddShredData(long longi, long lati);
53  void WriteToFileShredData(long longi, long lati);
54 
55  void Remove(long longi, long lati);
56 
57 private:
58  QHash<LongLat, QByteArray *> storage;
59  const ushort size;
61 }; // class ShredStorage
62 
63 class PreloadThread final : public QThread {
64  Q_OBJECT
65 public:
67  long longi_center, long lati_center, ushort size);
68 
69 protected:
70  void run() override;
71 
72 private:
74  PreloadThread(PreloadThread &) = delete;
75 
77  const int direction;
78  const long longi_center;
79  const long lati_center;
80  const ushort size;
81 }; // class PreloadThread
82 
83 #endif // SHRED_STORAGE_H
PreloadThread * preloadThread
Definition: ShredStorage.h:60
ShredStorage *const storage
Definition: ShredStorage.h:76
void run() override
ShredStorage(ushort size, long longi_center, long lati_center)
void Shift(int direction, long longitude, long latitude)
const long latitude
Definition: ShredStorage.h:35
const long lati_center
Definition: ShredStorage.h:79
LongLat(long longitude, long latitude)
void WriteToFileShredData(long longi, long lati)
void SetShredData(QByteArray *, long longi, long lati)
PreloadThread(ShredStorage *, int direction, long longi_center, long lati_center, ushort size)
LongLat & operator=(const LongLat &)=delete
PreloadThread & operator=(PreloadThread &)=delete
bool operator==(const LongLat &) const
const long longi_center
Definition: ShredStorage.h:78
QByteArray * GetShredData(long longi, long lati) const
void AddShredData(long longi, long lati)
const long longitude
Definition: ShredStorage.h:34
const int direction
Definition: ShredStorage.h:77
ShredStorage & operator=(const ShredStorage &)=delete
const ushort size
Definition: ShredStorage.h:80
void Remove(long longi, long lati)
QHash< LongLat, QByteArray * > storage
Definition: ShredStorage.h:58
const ushort size
Definition: ShredStorage.h:59