-
Notifications
You must be signed in to change notification settings - Fork 17
/
MsgSetBounds.h
64 lines (51 loc) · 1.56 KB
/
MsgSetBounds.h
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
#pragma once
#include "MsgHandlerBase.h"
#include "MsgFrameBuffer.h"
#include "Logging.h"
#include "MathUtils.h"
#include "Preferences.h"
#include "TrapezoidSampler.h"
class MsgSetBounds : public MsgHandlerBase
{
public:
virtual bool Read(Connection* sender, NetIncomingMessage& msg)
{
if (msg.BodyLength() == 0)
return false;
// Read the body as json
json_error_t error;
json_t* root = json_loads(msg.Body(), 0, &error);
if (!root)
{
LOG_ERROR("MsgSetBounds.Read: error on line " << error.line << ":" << error.text);
return false;
}
LOG_INFO("Processing MsgSetBounds message");
// Read bounds
Vector2 topLeft, topRight, bottomRight, bottomLeft;
json_t* vec;
vec = json_object_get(root, "boundsTopLeft");
if (json_is_vector2(vec))
topLeft = json_vector2_value(vec);
vec = json_object_get(root, "boundsTopRight");
if (json_is_vector2(vec))
topRight = json_vector2_value(vec);
vec = json_object_get(root, "boundsBottomRight");
if (json_is_vector2(vec))
bottomRight = json_vector2_value(vec);
vec = json_object_get(root, "boundsBottomLeft");
if (json_is_vector2(vec))
bottomLeft = json_vector2_value(vec);
// Set bounds
Preferences::Instance->BoundsTopLeft = topLeft;
Preferences::Instance->BoundsTopRight = topRight;
Preferences::Instance->BoundsBottomRight = bottomRight;
Preferences::Instance->BoundsBottomLeft = bottomLeft;
TrapezoidSampler::Instance->UpdatePoints(topLeft, topRight, bottomRight, bottomLeft);
// Save
Preferences::Instance->Save();
// Cleanup
json_decref(root);
return true;
}
};