Pioneer
Loading...
Searching...
No Matches
Galaxy.h
Go to the documentation of this file.
1// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _GALAXY_H
5#define _GALAXY_H
6
7#include "CustomSystem.h"
8#include "Factions.h"
9#include "GalaxyCache.h"
10#include "JsonFwd.h"
11#include "PerfStats.h"
12#include "RefCounted.h"
13#include <cstdio>
14
15struct SDL_Surface;
16class GalaxyGenerator;
17
18class Galaxy : public RefCounted {
19protected:
20 friend class GalaxyGenerator;
21 Galaxy(RefCountedPtr<GalaxyGenerator> galaxyGenerator, float radius, float sol_offset_x, float sol_offset_y,
22 const std::string &factionsDir, const std::string &customSysDir);
24 virtual void Init();
25
26public:
27 // lightyears
28 const float GALAXY_RADIUS;
29 const float SOL_OFFSET_X;
30 const float SOL_OFFSET_Y;
31
32 static RefCountedPtr<Galaxy> LoadFromJson(const Json &jsonObj);
33 void ToJson(Json &jsonObj);
34
35 ~Galaxy();
36
37 bool IsInitialized() const { return m_initialized; }
38 /* 0 - 255 */
39 virtual Uint8 GetSectorDensity(const int sx, const int sy, const int sz) const = 0;
40 FactionsDatabase *GetFactions() { return &m_factions; } // XXX const correctness
41 CustomSystemsDatabase *GetCustomSystems() { return &m_customSystems; } // XXX const correctness
42
43 RefCountedPtr<const Sector> GetSector(const SystemPath &path) { return m_sectorCache.GetCached(path); }
44 RefCountedPtr<Sector> GetMutableSector(const SystemPath &path) { return m_sectorCache.GetCached(path); }
46
47 RefCountedPtr<StarSystem> GetStarSystem(const SystemPath &path) { return m_starSystemCache.GetCached(path); }
49
50 void FlushCaches();
51 void Dump(FILE *file, Sint32 centerX, Sint32 centerY, Sint32 centerZ, Sint32 radius);
52
54 const std::string &GetGeneratorName() const;
55 int GetGeneratorVersion() const;
56
57 Perf::Stats &GetStats() { return m_stats; }
58 const Perf::Stats &GetStats() const { return m_stats; }
59
60private:
61 bool m_initialized;
62 Perf::Stats m_stats;
63 RefCountedPtr<GalaxyGenerator> m_galaxyGenerator;
64 SectorCache m_sectorCache;
65 StarSystemCache m_starSystemCache;
66 FactionsDatabase m_factions;
67 CustomSystemsDatabase m_customSystems;
68};
69
70class DensityMapGalaxy : public Galaxy {
71private:
72 friend class GalaxyGenerator;
73 DensityMapGalaxy(RefCountedPtr<GalaxyGenerator> galaxyGenerator, const std::string &mapfile,
74 float radius, float sol_offset_x, float sol_offset_y, const std::string &factionsDir, const std::string &customSysDir);
75
76public:
77 virtual Uint8 GetSectorDensity(const int sx, const int sy, const int sz) const;
78
79private:
80 std::unique_ptr<float[]> m_galaxyMap;
81 Sint32 m_mapWidth, m_mapHeight;
82};
83
84#endif /* _GALAXY_H */
nlohmann::json Json
Definition Json.h:8
Definition CustomSystem.h:99
Definition Galaxy.h:70
virtual Uint8 GetSectorDensity(const int sx, const int sy, const int sz) const
Definition Galaxy.cpp:156
Definition Factions.h:87
Definition GalaxyGenerator.h:17
RefCountedPtr< Slave > NewSlaveCache()
Definition GalaxyCache.cpp:97
RefCountedPtr< T > GetCached(const SystemPath &path)
Definition GalaxyCache.cpp:54
Definition Galaxy.h:18
RefCountedPtr< SectorCache::Slave > NewSectorSlaveCache()
Definition Galaxy.h:45
virtual void Init()
Definition Galaxy.cpp:54
void Dump(FILE *file, Sint32 centerX, Sint32 centerY, Sint32 centerZ, Sint32 radius)
Definition Galaxy.cpp:89
const float GALAXY_RADIUS
Definition Galaxy.h:28
~Galaxy()
Definition Galaxy.cpp:50
static RefCountedPtr< Galaxy > LoadFromJson(const Json &jsonObj)
Definition Galaxy.cpp:30
RefCountedPtr< StarSystem > GetStarSystem(const SystemPath &path)
Definition Galaxy.h:47
void ToJson(Json &jsonObj)
Definition Galaxy.cpp:40
RefCountedPtr< GalaxyGenerator > GetGenerator() const
Definition Galaxy.cpp:102
int GetGeneratorVersion() const
Definition Galaxy.cpp:112
void SetGalaxyGenerator(RefCountedPtr< GalaxyGenerator > galaxyGenerator)
Definition Galaxy.cpp:45
void FlushCaches()
Definition Galaxy.cpp:79
virtual Uint8 GetSectorDensity(const int sx, const int sy, const int sz) const =0
RefCountedPtr< StarSystemCache::Slave > NewStarSystemSlaveCache()
Definition Galaxy.h:48
FactionsDatabase * GetFactions()
Definition Galaxy.h:40
CustomSystemsDatabase * GetCustomSystems()
Definition Galaxy.h:41
RefCountedPtr< Sector > GetMutableSector(const SystemPath &path)
Definition Galaxy.h:44
const float SOL_OFFSET_X
Definition Galaxy.h:29
Perf::Stats & GetStats()
Definition Galaxy.h:57
const float SOL_OFFSET_Y
Definition Galaxy.h:30
const std::string & GetGeneratorName() const
Definition Galaxy.cpp:107
RefCountedPtr< const Sector > GetSector(const SystemPath &path)
Definition Galaxy.h:43
const Perf::Stats & GetStats() const
Definition Galaxy.h:58
bool IsInitialized() const
Definition Galaxy.h:37
Definition PerfStats.h:24
Definition RefCounted.h:36
Definition RefCounted.h:11
Definition SystemPath.h:13