-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParamEditor.hpp
830 lines (707 loc) · 22.9 KB
/
ParamEditor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#include <fstream>
#include <thread>
#include <mutex>
#include <Siv3D.hpp> // OpenSiv3D v0.3.0
#ifndef PMT_RELEASE_FLAG
#define PMT_RELEASE_FLAG false
#endif
namespace pmt
{
namespace detailImpl
{
static constexpr uint16 PortNumber = 52823;
static constexpr unsigned EditorVersion = 1;
struct ParameterData
{
template <class Archive>
void SIV3D_SERIALIZE(Archive& archive)
{
archive(colors);
}
std::unordered_map<String, ColorF> colors;
};
class ColorEditor
{
public:
ColorEditor() = default;
ColorEditor(const Color& color)
{
const HSV hsv(color);
currentHuePos = 1.0 - hsv.h / 360.0;
currentPos = Vec2(hsv.s, 1.0 - hsv.v);
}
void update()
{
const Vec2 satBoxTL = colorBoxTL + Vec2(colorBoxWidth + satBoxInterval, 0);
{
//明度と彩度の操作
if (RectF(colorBoxTL, colorBoxWidth, colorBoxWidth).stretched(10).leftPressed())
{
currentPos = Saturate((Cursor::PosF() - colorBoxTL) / colorBoxWidth);
}
//色相の操作
if (RectF(satBoxTL, satBoxWidth, colorBoxWidth).stretched(5).leftPressed())
{
currentHuePos = Saturate((Cursor::PosF().y - satBoxTL.y) / colorBoxWidth);
}
}
}
void draw()const
{
const Vec2 satBoxTL = colorBoxTL + Vec2(colorBoxWidth + satBoxInterval, 0);
getScope().draw(Color(128, 128, 128));
//左のボックスの描画
{
const double currentH = 360.0 - 360.0*currentHuePos;
//RectF(colorBoxTL, colorBoxWidth, colorBoxWidth).drawFrame(3.0, Palette::Black);
//RectF(colorBoxTL, colorBoxWidth, colorBoxWidth).draw({ HSV(currentH, 0.0, 1.0),HSV(currentH, 1.0, 1.0),HSV(currentH, 1.0, 0.0),HSV(currentH, 0.0, 0.0) });
int divNum = 4;
const int unitWidth = colorBoxWidth / divNum;
for (int y = 0; y < divNum; ++y)
{
const double topV = 1.0 - 1.0*y / divNum;
const double bottomV = 1.0 - 1.0*(y + 1) / divNum;
for (int x = 0; x < divNum; ++x)
{
const double leftS = 1.0*x / divNum;
const double rightS = 1.0*(x + 1) / divNum;
RectF(colorBoxTL + Vec2(x, y)*unitWidth, unitWidth, unitWidth).draw({
HSV(currentH, leftS, topV),HSV(currentH, rightS, topV),HSV(currentH, rightS, bottomV),HSV(currentH, leftS, bottomV)
});
}
}
const Color circleColor = currentPos.y < 0.3 ? Palette::Black : Palette::White;
getCircle().drawFrame(1.0, circleColor);
}
//右のボックスの描画
{
const int divNum = 6;
for (int i = 0; i < divNum; ++i)
{
const int unitHeight = colorBoxWidth / divNum;
const Vec2 currentSatBoxTL = satBoxTL + Vec2(0, i*unitHeight);
const double unitH = 360.0 / divNum;
const Color topColor = HSV(360.0 - unitH * i, 1.0, 1.0);
const Color bottomColor = HSV(360.0 - unitH * (i + 1), 1.0, 1.0);
RectF(currentSatBoxTL, satBoxWidth, unitHeight).draw({ topColor,topColor,bottomColor,bottomColor });
}
const Vec2 satLineLeft = satBoxTL + Vec2(0, colorBoxWidth*currentHuePos);
Line(satLineLeft, satLineLeft + Vec2(satBoxWidth, 0)).draw(1.0, Palette::Black);
}
}
HSV getHSV()const
{
return HSV(360.0 - 360.0*currentHuePos, currentPos.x, 1.0 - currentPos.y);
}
RectF getScope()const
{
const double width = colorBoxWidth + satBoxInterval + satBoxWidth;
return RectF(colorBoxTL, width, colorBoxWidth).stretched(1.0);
}
RectF getTabScope(const Vec2& offset = { 0, 0 })const
{
const Vec2 bottomLeft = getScope().tl() + offset;
const double tabHeight = 25;
return RectF(bottomLeft - Vec2(0, tabHeight), 70, tabHeight);
}
Vec2 colorBoxTL = Vec2(100.0, 100.0);
template <class Archive>
void SIV3D_SERIALIZE(Archive& archive)
{
archive(colorBoxTL, currentPos, currentHuePos, colorName);
}
private:
Circle getCircle()const
{
return Circle(colorBoxTL + currentPos * colorBoxWidth, 10.0);
}
int colorBoxWidth = 300;
int satBoxInterval = 10;
int satBoxWidth = 30;
Vec2 currentPos = Vec2(0.0, 0.0); //[0.0, 1.0]
double currentHuePos = 0.0; //[0.0, 1.0]
String colorName = U"Color";
};
class MultiColorEditors
{
public:
struct WindowIndex
{
size_t groupIndex;
size_t colorIndex;
WindowIndex() = default;
WindowIndex(size_t groupIndex, size_t colorIndex) :
groupIndex(groupIndex),
colorIndex(colorIndex)
{}
bool operator==(const WindowIndex& other)const
{
return groupIndex == other.groupIndex && colorIndex == other.colorIndex;
}
};
void add(const String& name, const Color& color)
{
colors[name] = color;
if (colorGroups.empty())
{
colorGroups.emplace_back();
groupPositions.push_back(Vec2(100, 100));
}
colorGroups.back().push_back(name);
}
void update()
{
currentUpdates.clear();
if (grabbingColor)
{
const auto& info = grabbingColor.value();
const WindowIndex index = searchByName(info.name).value();
//切り離された状態
if (colorGroups[index.groupIndex].size() == 1)
{
groupPositions[index.groupIndex] = Cursor::PosF() - info.posOffset;
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
if (groupIndex == index.groupIndex)
{
continue;
}
//既存のグループへのマージ
if (getGroupOuterScope(groupIndex).mouseOver())
{
colorGroups[groupIndex].push_back(info.name);
colorGroups.erase(colorGroups.begin() + index.groupIndex);
groupPositions.erase(groupPositions.begin() + index.groupIndex);
break;
}
}
}
//結合された状態
else
{
//グループからの切り離し
if (!getGroupOuterScope(index.groupIndex).mouseOver())
{
auto& currentGroup = colorGroups[index.groupIndex];
for (size_t colorIndex = 0; colorIndex < currentGroup.size(); ++colorIndex)
{
if (info.name == currentGroup[colorIndex])
{
currentGroup.erase(currentGroup.begin() + colorIndex);
break;
}
}
colorGroups.emplace_back();
colorGroups.back().push_back(info.name);
groupPositions.push_back(Cursor::PosF() - info.posOffset);
}
//グループ内での並べ替え
else
{
auto& currentGroup = colorGroups[index.groupIndex];
for (size_t colorIndex = 0; colorIndex < currentGroup.size(); ++colorIndex)
{
if (getColorScope({ index.groupIndex, colorIndex }).mouseOver() && index.colorIndex != colorIndex)
{
std::iter_swap(currentGroup.begin() + colorIndex, currentGroup.begin() + index.colorIndex);
}
}
}
}
if (MouseL.up())
{
grabbingColor = none;
}
}
else if (grabbingGroup)
{
groupPositions[grabbingGroup.value()] += Cursor::DeltaF();
if (MouseL.up())
{
grabbingGroup = none;
}
}
else if (edittingColor)
{
auto& edit = edittingColor.value();
edit.colorEditor.update();
colors[edit.name] = edit.colorEditor.getHSV();
currentUpdates.push_back(edit.name);
if (MouseL.down() && !(edit.colorEditor.getScope().mouseOver() || edit.colorEditor.getTabScope().mouseOver()))
{
edittingColor = none;
}
}
//クリック操作
if (!grabbingColor && !grabbingGroup && !edittingColor)
{
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
for (size_t colorIndex = 0; colorIndex < colorGroups[groupIndex].size(); ++colorIndex)
{
const RectF innerScope = getInnerColorScope(WindowIndex(groupIndex, colorIndex));
if (innerScope.leftClicked())
{
const String& name = colorGroups[groupIndex][colorIndex];
edittingColor = EditColorInfo(name, colors[name]);
edittingColor.value().colorEditor.colorBoxTL = getColorScope({ groupIndex, colorIndex }).tr();
}
}
}
if (!edittingColor)
{
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
for (size_t colorIndex = 0; colorIndex < colorGroups[groupIndex].size(); ++colorIndex)
{
const RectF scope = getColorScope({ groupIndex, colorIndex });
if (scope.leftClicked())
{
const Vec2 offset = Cursor::PosF() - scope.pos;
grabbingColor = GrabInfo(colorGroups[groupIndex][colorIndex], offset);
}
}
}
}
if (!edittingColor && !grabbingColor)
{
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
if (getGroupOuterScope(groupIndex).leftClicked() && !getGroupInnerScope(groupIndex).mouseOver())
{
grabbingGroup = groupIndex;
}
}
}
}
Optional<WindowIndex> grabbingColorIndex;
if (grabbingColor)
{
grabbingColorIndex = searchByName(grabbingColor.value().name);
}
//描画
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
const auto& currentGroup = colorGroups[groupIndex];
const Vec2& groupTLPos = groupPositions[groupIndex];
getGroupOuterScope(groupIndex).draw(Palette::Gray);
for (size_t colorIndex = 0; colorIndex < currentGroup.size(); ++colorIndex)
{
unsigned alpha = 255;
if (grabbingColorIndex && grabbingColorIndex.value() == WindowIndex(groupIndex, colorIndex))
{
alpha = 128;
}
const Vec2 pos = groupTLPos + Vec2(0, colorIndex)*unitHeight;
drawColorScope({ groupIndex, colorIndex }, pos, alpha);
}
}
if (grabbingColor)
{
getColorScope(searchByName(grabbingColor.value().name).value()).draw(Color(255, 255, 255, 64));
}
else if (edittingColor)
{
edittingColor.value().colorEditor.draw();
}
if (grabbingColorIndex)
{
const Vec2 drawPos = Cursor::PosF() - grabbingColor.value().posOffset;
drawColorScope(grabbingColorIndex.value(), drawPos);
}
}
bool exists(const String& name)const
{
return colors.find(name) != colors.end();
}
std::unordered_map<String, Color> getUpdates()const
{
std::unordered_map<String, Color> result;
for (const auto& name : currentUpdates)
{
result[name] = colors.find(name)->second;
}
return result;
}
const std::unordered_map<String, ColorF>& getColors()const
{
return colors;
}
template <class Archive>
void SIV3D_SERIALIZE(Archive& archive)
{
archive(colors, colorGroups, groupPositions);
}
private:
RectF getGroupOuterScope(size_t groupIndex)const
{
const Vec2 colorScopeTL = groupPositions[groupIndex];
const double colorScopesHeight = colorGroups[groupIndex].size()*unitHeight;
return RectF(colorScopeTL - Vec2(0, tabHeight) - Vec2(groupMargin, groupMargin), width + groupMargin * 2, tabHeight + colorScopesHeight + groupMargin * 2);
}
RectF getGroupInnerScope(size_t groupIndex)const
{
const Vec2 colorScopeTL = groupPositions[groupIndex];
const double colorScopesHeight = colorGroups[groupIndex].size()*unitHeight;
return RectF(colorScopeTL, width, colorScopesHeight);
}
RectF getColorScope(const WindowIndex& index)const
{
const Vec2 pos = groupPositions[index.groupIndex] + Vec2(0, index.colorIndex)*unitHeight;
return RectF(pos, width, unitHeight);
}
RectF getInnerColorScope(const WindowIndex& index)const
{
const Vec2 pos = groupPositions[index.groupIndex] + Vec2(0, index.colorIndex)*unitHeight;
const RectF scope(pos, width, unitHeight);
const double innerMergin = 5.0;
const double innerHeight = unitHeight - innerMergin * 2;
const double innerWidth = innerHeight * 2;
const Vec2 innerRectTL = scope.br() - Vec2(innerWidth, innerHeight) - Vec2(innerMergin, innerMergin);
return RectF(innerRectTL, innerWidth, innerHeight);
}
RectF getInnerColorScope(const Vec2& scopeTLPos)const
{
const RectF scope(scopeTLPos, width, unitHeight);
const double innerMergin = 5.0;
const double innerHeight = unitHeight - innerMergin * 2;
const double innerWidth = innerHeight * 2;
const Vec2 innerRectTL = scope.br() - Vec2(innerWidth, innerHeight) - Vec2(innerMergin, innerMergin);
return RectF(innerRectTL, innerWidth, innerHeight);
}
Optional<WindowIndex> searchByName(const String& name)const
{
for (size_t groupIndex = 0; groupIndex < colorGroups.size(); ++groupIndex)
{
for (size_t colorIndex = 0; colorIndex < colorGroups[groupIndex].size(); ++colorIndex)
{
if (name == colorGroups[groupIndex][colorIndex])
{
return WindowIndex(groupIndex, colorIndex);
}
}
}
return none;
}
void drawColorScope(const WindowIndex& index, const Vec2& pos, unsigned alpha = 255)const
{
const String& name = colorGroups[index.groupIndex][index.colorIndex];
RectF(pos, width, unitHeight).draw(Color(32, 32, 32, alpha));
RectF(pos, width, unitHeight).drawFrame(1.0, Color(128, 128, 128, alpha));
font(name).draw(pos, Color(255, 255, 255, alpha));
const RectF scope = getColorScope(index);
if (scope.mouseOver() && !grabbingColor && !grabbingGroup)
{
scope.draw(Color(255, 255, 255, 64));
}
const RectF innerScope = getInnerColorScope(pos);
innerScope.draw(Color(colors.find(name)->second).setA(alpha));
innerScope.drawFrame(1.0, Color(Palette::Gray).setA(alpha));
}
Font font = Font(20);
int unitHeight = 50;
int width = 400;
int tabHeight = 50;
int groupMargin = 1;
std::unordered_map<String, ColorF> colors;
std::vector<std::vector<String>> colorGroups;
std::vector<Vec2> groupPositions;
std::vector<String> currentUpdates;
struct GrabInfo
{
String name;
Vec2 posOffset;
GrabInfo() = default;
GrabInfo(const String& name, const Vec2& posOffset) :
name(name),
posOffset(posOffset)
{}
};
struct EditColorInfo
{
String name;
ColorEditor colorEditor;
EditColorInfo() = default;
EditColorInfo(const String& name, const Color& color) :
name(name),
colorEditor(color)
{}
};
Optional<GrabInfo> grabbingColor;
Optional<size_t> grabbingGroup;
Optional<EditColorInfo> edittingColor;
};
struct ServerState
{
template <class Archive>
void SIV3D_SERIALIZE(Archive& archive)
{
archive(receivedBuffer, editor);
}
ParameterData receivedBuffer;
MultiColorEditors editor;
};
class ParameterEditor
{
public:
static void Update()
{
auto& i = instance();
i.reportUpdate = true;
}
static const Color& GetColor(const String& name)
{
auto& i = instance();
if (i.colors.find(name) == i.colors.end())
{
std::lock_guard<std::mutex> lock(i.mtx);
i.colors[name] = RandomColor();
i.data1.colors[name] = i.colors[name];
}
return i.colors[name];
}
private:
ParameterEditor()
{
const String directoryName = U"ParameterEditor";
if (!FileSystem::Exists(directoryName))
{
FileSystem::CreateDirectories(directoryName);
}
{
const String versionFileName = directoryName + U"/version.dat";
const String saveFileName = directoryName + U"/save.dat";
if (FileSystem::Exists(versionFileName))
{
Deserializer<BinaryReader> versionDeserializer(versionFileName);
unsigned version;
versionDeserializer(version);
if (version == EditorVersion)
{
phase = Ready;
//データの復元はサーバー非依存に行える必要があるので初期化時にクライアントでも開く
if (FileSystem::Exists(saveFileName) && !FileSystem::IsEmpty(saveFileName))
{
Deserializer<BinaryReader> deserializer(saveFileName);
ServerState initialState;
deserializer(initialState);
//for (const auto& keyVal : initialState.receivedBuffer.colors)
for (const auto& keyVal : initialState.editor.getColors())
{
colors[keyVal.first] = keyVal.second;
}
}
else
{
BinaryWriter writer(saveFileName);
}
}
}
else
{
Serializer<BinaryWriter> serializer(versionFileName);
serializer(EditorVersion);
phase = Ready;
if (FileSystem::Exists(saveFileName))
{
phase = Beginning;
}
else
{
BinaryWriter writer(saveFileName);
}
}
}
//ここ以降での phase == Beginning はエラー状態として扱う
{
const String fileName = directoryName + U"/send.dat";
Serializer<BinaryWriter> serializer(fileName);
//phase が Ready になってない時は version.dat と EditorVersion が一致しない可能性がある
//サーバー側でクライアントの EditorVersion を把握するため送っておく
serializer(EditorVersion);
}
{
const String fileName = directoryName + U"/receive.dat";
BinaryWriter writer(fileName);
}
if (PMT_RELEASE_FLAG)
{
phase = Beginning;
}
else
{
const auto path = FileSystem::FullPath(directoryName);
std::array<char32_t, 256> filePath{};
for (auto ic : Indexed(path))
{
filePath[ic.first] = ic.second;
}
directoryPath = path;
directoryWatcher = DirectoryWatcher(directoryPath);
Serializer<MemoryWriter> serializer;
serializer(filePath);
const auto& writer = serializer.getWriter();
sendData = ByteArray(writer.data(), static_cast<size_t>(writer.size()));
worker1 = std::thread(ReportNewColors);
}
}
//新しく追加された色をサーバーに送る
static void ReportNewColors()
{
auto& i = instance();
i.client.connect(IPv4::localhost(), PortNumber);
while (!i.terminationRequest)
{
if (!i.reportUpdate)
{
continue;
}
i.reportUpdate = false;
switch (i.phase)
{
case ParameterEditor::Beginning:
{
Window::SetTitle(U"初期化に失敗");
break;
}
case ParameterEditor::Ready:
{
if (i.client.isConnected())
{
//Window::SetTitle(U"TCPClient: 接続完了!");
i.client.send(i.sendData.data(), 4 * 256);
i.sendData = ByteArray();
i.phase = WaitingServer;
break;
}
if (i.client.hasError())
{
i.client.disconnect();
//Window::SetTitle(U"TCPClient: 再接続待機中...");
i.client.connect(IPv4::localhost(), PortNumber);
}
break;
}
case ParameterEditor::WaitingServer:
{
const FilePath receiveFilePath = i.directoryPath + U"receive.dat";
const FilePath sendFilePath = i.directoryPath + U"send.dat";
/*
メインスレッドの方がこっちのスレッドより多く回る可能性がある
->DirectoryWatcherが捕捉を漏らす可能性がある?あるとしたらここでは使うべきでない
クライアント側では、send.dat にバージョン情報を書き込んだ後に通信を始める
サーバー側では、receive.dat にバージョン情報を書き込んだ後に send.dat の中身をクリアする
したがって、ここで send.dat の中身が空だった時は、確実に receive.dat には有効な値が入っているはず
*/
if (FileSystem::IsEmpty(sendFilePath))
{
{
Deserializer<BinaryReader> deserializer(receiveFilePath);
unsigned version;
deserializer(version);
if (version != EditorVersion)
{
i.phase = Beginning;
}
else
{
i.phase = Running;
i.client.disconnect();
}
}
BinaryWriter writer(receiveFilePath);
}
break;
}
case ParameterEditor::Running:
{
std::lock_guard<std::mutex> lock(i.mtx);
const FilePath receiveFilePath = i.directoryPath + U"receive.dat";
for (const auto& pathAction : i.directoryWatcher.retrieveChanges())
{
if (pathAction.first == receiveFilePath && !FileSystem::IsEmpty(receiveFilePath))
{
//ここのデシリアライズで失敗した(理由不明)
try
{
Deserializer<BinaryReader> deserializer(receiveFilePath);
ParameterData receivedData;
deserializer(receivedData);
for (const auto& keyVal : receivedData.colors)
{
i.colors[keyVal.first] = keyVal.second;
}
}
catch (std::exception& e)
{
Logger << Unicode::Widen(e.what());
}
BinaryWriter writer(receiveFilePath);
}
}
const FilePath sendFilePath = i.directoryPath + U"send.dat";
if (!i.data1.colors.empty() && FileSystem::IsEmpty(sendFilePath))
{
try
{
Serializer<BinaryWriter> serializer(sendFilePath);
serializer(i.data1);
i.data1 = ParameterData();
}
catch (std::exception& e)
{
Logger << Unicode::Widen(e.what());
}
}
break;
}
default: break;
}
}
}
ParameterEditor(const ParameterEditor&) = delete;
~ParameterEditor()
{
terminateAllThreads();
}
static ParameterEditor& instance()
{
static ParameterEditor obj;
return obj;
}
void terminateAllThreads()
{
terminationRequest = true;
if (worker1.joinable())
{
worker1.join();
}
}
enum Phase { Beginning, Ready, WaitingServer, Running };
//Beginning 初期状態(or初期化に失敗)
//Ready クライアントとセーブデータのバージョン番号の一致を確認(通信待機状態)
//WaitingServer ディレクトリ情報の送信完了(receive.datの更新待機状態)
//Running クライアントとサーバーのバージョン番号の一致を確認(通常状態)
TCPClient client;
uint32 receivedVal = 0;
std::unordered_map<String, Color> colors;
ParameterData data1;
ByteArray sendData;
String directoryPath;
DirectoryWatcher directoryWatcher;
std::thread worker1;
std::mutex mtx;
bool terminationRequest = false;
bool reportUpdate = false;
Phase phase = Beginning;
};
}
inline void Update()
{
detailImpl::ParameterEditor::Update();
}
inline const Color& GetColor(const String& name)
{
return detailImpl::ParameterEditor::GetColor(name);
}
}