yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
wasm_config.h
Go to the documentation of this file.
1#ifndef YAZE_APP_PLATFORM_WASM_CONFIG_H_
2#define YAZE_APP_PLATFORM_WASM_CONFIG_H_
3
4#ifdef __EMSCRIPTEN__
5
6#include <emscripten.h>
7
8#include <atomic>
9#include <mutex>
10#include <string>
11
12namespace yaze {
13namespace app {
14namespace platform {
15
51struct WasmConfig {
52 // Collaboration settings
53 struct Collaboration {
54 std::string server_url;
55 double user_timeout_seconds = 30.0;
56 double cursor_send_interval_seconds = 0.1; // 100ms
57 size_t max_change_size_bytes = 1024;
59
60 // Autosave settings
61 struct Autosave {
62 int interval_seconds = 60;
63 int max_recovery_slots = 5;
64 } autosave;
65
66 // Terminal settings
67 struct Terminal {
68 int max_history_items = 50;
69 int max_output_lines = 1000;
70 } terminal;
71
72 // UI settings
73 struct UI {
74 float min_zoom = 0.25f;
75 float max_zoom = 4.0f;
77 } ui;
78
79 // Cache settings
80 struct Cache {
81 std::string version = "v1";
82 int max_rom_cache_size_mb = 100;
83 } cache;
84
85 // AI service settings (for terminal AI commands)
86 struct AI {
87 bool enabled = true;
88 std::string model = "gemini-2.5-flash";
89 std::string endpoint; // Empty = use collaboration server
90 int max_response_length = 4096;
91 } ai;
92
93 // Server deployment info
94 struct Deployment {
95 std::string server_repo = "https://github.com/scawful/yaze-server";
96 int default_port = 8765;
97 std::string protocol_version = "2.0";
98 } deployment;
99
100 // Server status (populated by FetchServerStatus)
101 struct ServerStatus {
102 bool fetched = false;
103 bool reachable = false;
104 bool ai_enabled = false;
105 bool ai_configured = false;
106 std::string ai_provider; // "gemini", "external", "none"
107 bool tls_detected = false;
108 std::string persistence_type; // "memory", "file"
109 int active_sessions = 0;
110 int total_connections = 0;
111 std::string server_version;
112 std::string error_message;
114
121 void LoadFromJavaScript();
122
129 void FetchServerStatus();
130
135 static WasmConfig& Get();
136
141 bool IsLoaded() const { return loaded_.load(std::memory_order_acquire); }
142
147 bool IsLoading() const { return loading_.load(std::memory_order_acquire); }
148
161 std::unique_lock<std::mutex> GetReadLock() const {
162 return std::unique_lock<std::mutex>(config_mutex_);
163 }
164
165 private:
166 std::atomic<bool> loaded_{false};
167 std::atomic<bool> loading_{false};
168 mutable std::mutex config_mutex_;
169};
170
171// External C declarations for functions implemented in .cc
172extern "C" {
173 char* WasmConfig_GetString(const char* path, const char* defaultVal);
174 double WasmConfig_GetNumber(const char* path, double defaultVal);
175 int WasmConfig_GetInt(const char* path, int defaultVal);
176}
177
178} // namespace platform
179} // namespace app
180} // namespace yaze
181
182#else // !__EMSCRIPTEN__
183
184// Stub for non-WASM builds - provides defaults
185#include <mutex>
186#include <string>
187
188namespace yaze {
189namespace app {
190namespace platform {
191
199
204
209
210 struct UI {
211 float min_zoom = 0.25f;
212 float max_zoom = 4.0f;
214 } ui;
215
216 struct Cache {
217 std::string version = "v1";
220
221 struct AI {
222 bool enabled = true;
223 std::string model = "gemini-2.5-flash";
224 std::string endpoint;
226 } ai;
227
228 struct Deployment {
229 std::string server_repo = "https://github.com/scawful/yaze-server";
230 int default_port = 8765;
231 std::string protocol_version = "2.0";
233
235 bool fetched = false;
236 bool reachable = false;
237 bool ai_enabled = false;
238 bool ai_configured = false;
239 std::string ai_provider;
240 bool tls_detected = false;
241 std::string persistence_type;
244 std::string server_version;
245 std::string error_message;
247
250 static WasmConfig& Get() {
251 static WasmConfig instance;
252 return instance;
253 }
254 bool IsLoaded() const { return true; }
255 bool IsLoading() const { return false; }
256 std::unique_lock<std::mutex> GetReadLock() const {
257 return std::unique_lock<std::mutex>(config_mutex_);
258 }
259
260 private:
261 mutable std::mutex config_mutex_;
262};
263
264} // namespace platform
265} // namespace app
266} // namespace yaze
267
268#endif // __EMSCRIPTEN__
269
270#endif // YAZE_APP_PLATFORM_WASM_CONFIG_H_
struct yaze::app::platform::WasmConfig::ServerStatus server_status
struct yaze::app::platform::WasmConfig::Terminal terminal
static WasmConfig & Get()
struct yaze::app::platform::WasmConfig::UI ui
struct yaze::app::platform::WasmConfig::AI ai
std::unique_lock< std::mutex > GetReadLock() const
struct yaze::app::platform::WasmConfig::Autosave autosave
struct yaze::app::platform::WasmConfig::Collaboration collaboration
struct yaze::app::platform::WasmConfig::Deployment deployment
struct yaze::app::platform::WasmConfig::Cache cache