MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_savedata_server.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_SAVEDATA_SERVER_H_1628122698
12#define INCGUARD_MGL_SAVEDATA_SERVER_H_1628122698
13
14#include <future>
15
21
22namespace MGL::Savedata
23{
25class Server final : public MGL::SharedSingleton<Server>
26{
27public:
28 static STL::unique_ptr<Server> &GetInstanceRef() noexcept;
29
30 Server() noexcept;
31
32 int32_t Initialize(STL::unique_ptr<ServerDelegate> &delegate) noexcept;
33
34 bool AddChunk(DataIdentifier identifier, Chunk *chunk) noexcept;
35 bool RemoveChunk(DataIdentifier identifier, Chunk *chunk) noexcept;
36
37 bool SaveRequest(const STL::vector<RequestInfo> &requests, bool async, bool haltOnError) noexcept;
38 bool LoadRequest(const STL::vector<RequestInfo> &requests, bool async, bool haltOnError, bool errorOnFileNotExist) noexcept;
39
40 /* ------------------------------------------------------------------------- */
46 /* ------------------------------------------------------------------------- */
47 bool IsLoading() const noexcept
48 {
49 return _state == State::Loading;
50 }
51
52 /* ------------------------------------------------------------------------- */
58 /* ------------------------------------------------------------------------- */
59 bool IsSaving() const noexcept
60 {
61 return _state == State::Saving;
62 }
63
64 /* ------------------------------------------------------------------------- */
70 /* ------------------------------------------------------------------------- */
71 bool IsReady() const noexcept
72 {
73 return _state == State::Ready;
74 }
75
76 /* ------------------------------------------------------------------------- */
82 /* ------------------------------------------------------------------------- */
83 bool IsProcessing() const noexcept
84 {
85 return IsLoading() || IsSaving();
86 }
87
88 /* ------------------------------------------------------------------------- */
94 /* ------------------------------------------------------------------------- */
95 bool IsSucceeded() const noexcept
96 {
97 return IsReady() && !_existError;
98 }
99
100 /* ------------------------------------------------------------------------- */
105 /* ------------------------------------------------------------------------- */
106 constexpr const STL::vector<Result> &GetLastResults() const noexcept
107 {
108 return _lastResults;
109 }
110
111 /* ------------------------------------------------------------------------- */
117 /* ------------------------------------------------------------------------- */
118 bool Wait() noexcept
119 {
120 return _future.get();
121 }
122
123private:
125 enum class State : uint8_t
126 {
127 PreInitialize,
128 Ready,
129 Loading,
130 Saving,
131 };
132
133 Result Save(DataIdentifier identifier, uint32_t index) noexcept;
134 Result Load(DataIdentifier identifier, uint32_t index) noexcept;
135
137
138 using ChunkList = STL::list<Chunk *>;
140
141 ChunkListMap _chunkListMap;
142
143 std::atomic<State> _state;
144 std::future<bool> _future;
145
146 STL::vector<RequestInfo> _requests;
147
148 STL::vector<Result> _lastResults;
149 std::atomic<bool> _existError;
150};
151} // namespace MGL::Savedata
152
153#endif // INCGUARD_MGL_SAVEDATA_SERVER_H_1628122698
154
155// vim: et ts=4 sw=4 sts=4
セーブデータチャンク
Definition mgl_savedata_chunk.h:21
セーブデータサーバ
Definition mgl_savedata_server.h:26
bool LoadRequest(const STL::vector< RequestInfo > &requests, bool async, bool haltOnError, bool errorOnFileNotExist) noexcept
ロード要求
Definition mgl_savedata_server.cc:210
bool IsReady() const noexcept
セーブ・ロードが可能な状態かを取得
Definition mgl_savedata_server.h:71
bool IsSaving() const noexcept
セーブ中かを取得
Definition mgl_savedata_server.h:59
int32_t Initialize(STL::unique_ptr< ServerDelegate > &delegate) noexcept
セーブデータサーバの初期化
Definition mgl_savedata_server.cc:56
bool SaveRequest(const STL::vector< RequestInfo > &requests, bool async, bool haltOnError) noexcept
セーブ要求
Definition mgl_savedata_server.cc:149
bool RemoveChunk(DataIdentifier identifier, Chunk *chunk) noexcept
チャンクの削除
Definition mgl_savedata_server.cc:118
bool IsSucceeded() const noexcept
前回の処理に成功したかを取得
Definition mgl_savedata_server.h:95
static STL::unique_ptr< Server > & GetInstanceRef() noexcept
インスタンスの取得
Definition mgl_savedata_server.cc:28
Server() noexcept
コンストラクタ
Definition mgl_savedata_server.cc:40
constexpr const STL::vector< Result > & GetLastResults() const noexcept
最後に発生した処理結果を取得
Definition mgl_savedata_server.h:106
bool IsProcessing() const noexcept
処理中かを取得
Definition mgl_savedata_server.h:83
bool Wait() noexcept
実行中の処理が完了するまで待機
Definition mgl_savedata_server.h:118
bool AddChunk(DataIdentifier identifier, Chunk *chunk) noexcept
チャンクの追加
Definition mgl_savedata_server.cc:93
bool IsLoading() const noexcept
ロード中かを取得
Definition mgl_savedata_server.h:47
シングルトンテンプレート(共有ライブラリ用)
Definition mgl_singleton.h:44
MGL セーブデータチャンク
uint32_t DataIdentifier
セーブデータ識別子
Definition mgl_savedata_defs.h:30
MGL セーブデータサーバのデリゲート
MGL シングルトンクラス
MGL STLコンテナの代替
std::list< T, Allocator< T > > list
std::listの代替
Definition mgl_stl_containers.h:47
std::unordered_map< Key, T, Hash, Pred, Allocator< std::pair< const Key, T > > > unordered_map
std::unordered_mapの代替
Definition mgl_stl_containers.h:71
std::vector< T, Allocator< T > > vector
std::vectorの代替
Definition mgl_stl_containers.h:51
MGL STLのメモリ関連の代替
std::unique_ptr< T, Deleter > unique_ptr
MGLのアロケータを利用するユニークポインタ
Definition mgl_stl_memory.h:247