Skip to content

Commit c38ca28

Browse files
authored
Merge branch 'beta' into faster-rebuilds
2 parents fcb373f + f63a733 commit c38ca28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1969
-1693
lines changed

src/Core/ByteStream.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ namespace Vortex {
1111
// WriteStream.
1212

1313
WriteStream::WriteStream() {
14-
buffer_ = (uint8_t*)malloc(128);
14+
buffer_ = static_cast<uint8_t*>(malloc(128));
1515
current_size_ = 0;
1616
capacity_ = 128;
1717
is_external_buffer_ = false;
1818
is_write_successful_ = true;
1919
}
2020

2121
WriteStream::WriteStream(void* out, int bytes) {
22-
buffer_ = (uint8_t*)out;
22+
buffer_ = static_cast<uint8_t*>(out);
2323
current_size_ = 0;
2424
capacity_ = bytes;
2525
is_external_buffer_ = true;
@@ -37,7 +37,7 @@ void WriteStream::write(const void* in, int bytes) {
3737
current_size_ = newSize;
3838
} else if (!is_external_buffer_) {
3939
capacity_ = max(capacity_ << 1, newSize);
40-
buffer_ = (uint8_t*)realloc(buffer_, capacity_);
40+
buffer_ = static_cast<uint8_t*>(realloc(buffer_, capacity_));
4141
memcpy(buffer_ + current_size_, in, bytes);
4242
current_size_ = newSize;
4343
} else {
@@ -47,12 +47,12 @@ void WriteStream::write(const void* in, int bytes) {
4747

4848
void WriteStream::write8(const void* val) {
4949
if (current_size_ < capacity_) {
50-
buffer_[current_size_] = *(const uint8_t*)val;
50+
buffer_[current_size_] = *static_cast<const uint8_t*>(val);
5151
++current_size_;
5252
} else if (!is_external_buffer_) {
5353
capacity_ <<= 1;
54-
buffer_ = (uint8_t*)realloc(buffer_, capacity_);
55-
buffer_[current_size_] = *(const uint8_t*)val;
54+
buffer_ = static_cast<uint8_t*>(realloc(buffer_, capacity_));
55+
buffer_[current_size_] = *static_cast<const uint8_t*>(val);
5656
++current_size_;
5757
} else {
5858
is_write_successful_ = false;
@@ -62,12 +62,14 @@ void WriteStream::write8(const void* val) {
6262
void WriteStream::write16(const void* val) {
6363
int newSize = current_size_ + sizeof(uint16_t);
6464
if (newSize <= capacity_) {
65-
*(uint16_t*)(buffer_ + current_size_) = *(const uint16_t*)val;
65+
*reinterpret_cast<uint16_t*>(buffer_ + current_size_) =
66+
*static_cast<const uint16_t*>(val);
6667
current_size_ = newSize;
6768
} else if (!is_external_buffer_) {
6869
capacity_ <<= 1;
69-
buffer_ = (uint8_t*)realloc(buffer_, capacity_);
70-
*(uint16_t*)(buffer_ + current_size_) = *(const uint16_t*)val;
70+
buffer_ = static_cast<uint8_t*>(realloc(buffer_, capacity_));
71+
*reinterpret_cast<uint16_t*>(buffer_ + current_size_) =
72+
*static_cast<const uint16_t*>(val);
7173
current_size_ = newSize;
7274
} else {
7375
is_write_successful_ = false;
@@ -77,12 +79,14 @@ void WriteStream::write16(const void* val) {
7779
void WriteStream::write32(const void* val) {
7880
int newSize = current_size_ + sizeof(uint32_t);
7981
if (newSize <= capacity_) {
80-
*(uint32_t*)(buffer_ + current_size_) = *(const uint32_t*)val;
82+
*reinterpret_cast<uint32_t*>(buffer_ + current_size_) =
83+
*static_cast<const uint32_t*>(val);
8184
current_size_ = newSize;
8285
} else if (!is_external_buffer_) {
8386
capacity_ <<= 1;
84-
buffer_ = (uint8_t*)realloc(buffer_, capacity_);
85-
*(uint32_t*)(buffer_ + current_size_) = *(const uint32_t*)val;
87+
buffer_ = static_cast<uint8_t*>(realloc(buffer_, capacity_));
88+
*reinterpret_cast<uint32_t*>(buffer_ + current_size_) =
89+
*static_cast<const uint32_t*>(val);
8690
current_size_ = newSize;
8791
} else {
8892
is_write_successful_ = false;
@@ -92,12 +96,14 @@ void WriteStream::write32(const void* val) {
9296
void WriteStream::write64(const void* val) {
9397
int newSize = current_size_ + sizeof(uint64_t);
9498
if (newSize <= capacity_) {
95-
*(uint64_t*)(buffer_ + current_size_) = *(const uint64_t*)val;
99+
*reinterpret_cast<uint64_t*>(buffer_ + current_size_) =
100+
*static_cast<const uint64_t*>(val);
96101
current_size_ = newSize;
97102
} else if (!is_external_buffer_) {
98103
capacity_ <<= 1;
99-
buffer_ = (uint8_t*)realloc(buffer_, capacity_);
100-
*(uint64_t*)(buffer_ + current_size_) = *(const uint64_t*)val;
104+
buffer_ = static_cast<uint8_t*>(realloc(buffer_, capacity_));
105+
*reinterpret_cast<uint64_t*>(buffer_ + current_size_) =
106+
*static_cast<const uint64_t*>(val);
101107
current_size_ = newSize;
102108
} else {
103109
is_write_successful_ = false;
@@ -129,12 +135,12 @@ void WriteStream::writeStr(const std::string& str) {
129135
// ReadStream.
130136

131137
ReadStream::ReadStream(const void* in, int bytes) {
132-
read_position_ = (const uint8_t*)in;
138+
read_position_ = static_cast<const uint8_t*>(in);
133139
end_position_ = read_position_ + bytes;
134140
is_read_successful_ = true;
135141
}
136142

137-
ReadStream::~ReadStream() {}
143+
ReadStream::~ReadStream() = default;
138144

139145
void ReadStream::skip(int bytes) {
140146
if (read_position_ + bytes <= end_position_) {
@@ -157,10 +163,10 @@ void ReadStream::read(void* out, int bytes) {
157163

158164
void ReadStream::read8(void* out) {
159165
if (read_position_ != end_position_) {
160-
*(uint8_t*)out = *read_position_;
166+
*static_cast<uint8_t*>(out) = *read_position_;
161167
++read_position_;
162168
} else {
163-
*(uint8_t*)out = 0;
169+
*static_cast<uint8_t*>(out) = 0;
164170
read_position_ = end_position_;
165171
is_read_successful_ = false;
166172
}
@@ -169,10 +175,11 @@ void ReadStream::read8(void* out) {
169175
void ReadStream::read16(void* out) {
170176
auto newPos = read_position_ + sizeof(uint16_t);
171177
if (newPos <= end_position_) {
172-
*(uint16_t*)out = *(const uint16_t*)read_position_;
178+
*static_cast<uint16_t*>(out) =
179+
*reinterpret_cast<const uint16_t*>(read_position_);
173180
read_position_ = newPos;
174181
} else {
175-
*(uint16_t*)out = 0;
182+
*static_cast<uint16_t*>(out) = 0;
176183
read_position_ = end_position_;
177184
is_read_successful_ = false;
178185
}
@@ -181,10 +188,11 @@ void ReadStream::read16(void* out) {
181188
void ReadStream::read32(void* out) {
182189
auto newPos = read_position_ + sizeof(uint32_t);
183190
if (newPos <= end_position_) {
184-
*(uint32_t*)out = *(const uint32_t*)read_position_;
191+
*static_cast<uint32_t*>(out) =
192+
*reinterpret_cast<const uint32_t*>(read_position_);
185193
read_position_ = newPos;
186194
} else {
187-
*(uint32_t*)out = 0;
195+
*static_cast<uint32_t*>(out) = 0;
188196
read_position_ = end_position_;
189197
is_read_successful_ = false;
190198
}
@@ -193,10 +201,11 @@ void ReadStream::read32(void* out) {
193201
void ReadStream::read64(void* out) {
194202
auto newPos = read_position_ + sizeof(uint64_t);
195203
if (newPos <= end_position_) {
196-
*(uint64_t*)out = *(const uint64_t*)read_position_;
204+
*static_cast<uint64_t*>(out) =
205+
*reinterpret_cast<const uint64_t*>(read_position_);
197206
read_position_ = newPos;
198207
} else {
199-
*(uint64_t*)out = 0;
208+
*static_cast<uint64_t*>(out) = 0;
200209
read_position_ = end_position_;
201210
is_read_successful_ = false;
202211
}
@@ -241,7 +250,7 @@ std::string ReadStream::readStr() {
241250
if (newPos <= end_position_) {
242251
auto str = read_position_;
243252
read_position_ = newPos;
244-
return std::string((const char*)str, len);
253+
return std::string(reinterpret_cast<const char*>(str), len);
245254
}
246255
read_position_ = end_position_;
247256
is_read_successful_ = false;

src/Core/Canvas.cpp

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ struct GetLineDist : public DistanceFunc {
6161
GetLineDist(float ax, float ay, float bx, float by, float size)
6262
: ax(ax), ay(ay), bx(bx), by(by), size(size) {}
6363

64-
float Get(float px, float py) const {
64+
float Get(float px, float py) const override {
6565
float num = (px - ax) * (bx - ax) + (py - ay) * (by - ay);
6666
float den = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
6767
float rdn = 1 / den, r = num * rdn;
6868
float s = ((ay - py) * (bx - ax) - (ax - px) * (by - ay)) * rdn;
69-
if (r >= 0 && r <= 1) return (float)fabs(s * sqrt(den)) - size;
69+
if (r >= 0 && r <= 1) return fabs(s * sqrt(den)) - size;
7070

7171
float d1sq = (px - ax) * (px - ax) + (py - ay) * (py - ay);
7272
float d2sq = (px - bx) * (px - bx) + (py - by) * (py - by);
73-
return (float)sqrt(d1sq < d2sq ? d1sq : d2sq) - size;
73+
return sqrt(d1sq < d2sq ? d1sq : d2sq) - size;
7474
}
7575
};
7676

@@ -80,9 +80,9 @@ struct GetCircleDist : public DistanceFunc {
8080

8181
GetCircleDist(float x, float y, float r) : x(x), y(y), r(r) {}
8282

83-
float Get(float px, float py) const {
83+
float Get(float px, float py) const override {
8484
float dx = px - x, dy = py - y;
85-
return (float)sqrt(dx * dx + dy * dy) - r;
85+
return sqrt(dx * dx + dy * dy) - r;
8686
}
8787
};
8888

@@ -93,7 +93,7 @@ struct GetRoundRectDist : public DistanceFunc {
9393
GetRoundRectDist(float x1, float y1, float x2, float y2, float r)
9494
: x1(x1), y1(y1), x2(x2), y2(y2), r(r) {}
9595

96-
float Get(float px, float py) const {
96+
float Get(float px, float py) const override {
9797
float x = min(max(px, x1 + r), x2 - r);
9898
float y = min(max(py, y1 + r), y2 - r);
9999
if (x == px && y == py) {
@@ -102,7 +102,7 @@ struct GetRoundRectDist : public DistanceFunc {
102102
return -min(dx, dy);
103103
} else {
104104
float dx = px - x, dy = py - y;
105-
return (float)sqrt(dx * dx + dy * dy) - r;
105+
return sqrt(dx * dx + dy * dy) - r;
106106
}
107107
}
108108
};
@@ -124,7 +124,7 @@ struct GetPolyDist : public DistanceFunc {
124124
return (numIntersects & 1);
125125
}
126126

127-
float Get(float px, float py) const {
127+
float Get(float px, float py) const override {
128128
float d = 1e10;
129129
for (int i = 0, j = count - 1; i < count; j = i, ++i) {
130130
GetLineDist ld(x[i], y[i], x[j], y[j], 0);
@@ -163,28 +163,28 @@ void Canvas::Data::draw(float* buf, int w, int h, const areaf& area,
163163
if (blendMode == Canvas::BM_ALPHA) blendfunc = BlendAlpha;
164164
if (blendMode == Canvas::BM_ADD) blendfunc = BlendAdd;
165165

166-
int x1 = max(mask.l, (int)(area.l - outerGlow - 1 + 0.5f));
167-
int y1 = max(mask.t, (int)(area.t - outerGlow - 1 + 0.5f));
168-
int x2 = min(mask.r, (int)(area.r + outerGlow + 1 + 0.5f));
169-
int y2 = min(mask.b, (int)(area.b + outerGlow + 1 + 0.5f));
166+
int x1 = max(mask.l, static_cast<int>(area.l - outerGlow - 1 + 0.5f));
167+
int y1 = max(mask.t, static_cast<int>(area.t - outerGlow - 1 + 0.5f));
168+
int x2 = min(mask.r, static_cast<int>(area.r + outerGlow + 1 + 0.5f));
169+
int y2 = min(mask.b, static_cast<int>(area.b + outerGlow + 1 + 0.5f));
170170

171171
float rh = 1.f / max(1, y2 - y1);
172172
float rw = 1.f / max(1, x2 - x1);
173173
float ig = 1.f / (innerGlow + 1);
174174
float og = 1.f / (outerGlow + 1);
175175

176-
float yf = (float)y1 + 0.5f;
176+
float yf = static_cast<float>(y1) + 0.5f;
177177
for (int y = y1; y < y2; ++y, yf += 1) {
178178
RGBA l = tl;
179179
BlendLinear(l, bl, yf * rh);
180180
RGBA r = tr;
181181
BlendLinear(r, br, yf * rh);
182182

183-
float xf = (float)x1 + 0.5f;
183+
float xf = static_cast<float>(x1) + 0.5f;
184184
for (int x = x1; x < x2; ++x, xf += 1) {
185185
float dist = func->Get(xf, yf);
186186
if (dist >= outerGlow + 1) continue;
187-
RGBA* dst = (RGBA*)(buf + ((y * w + x) * 4));
187+
RGBA* dst = reinterpret_cast<RGBA*>(buf + ((y * w + x) * 4));
188188
RGBA src = l;
189189
BlendLinear(src, r, xf * rw);
190190
if (outline && dist < -0.5f) {
@@ -219,7 +219,7 @@ Canvas::Canvas(int w, int h, float lum)
219219
canvas_width_(w),
220220
canvas_height_(h),
221221
data_(new Canvas::Data) {
222-
canvas_data_ = (float*)malloc(w * h * 4 * sizeof(float));
222+
canvas_data_ = static_cast<float*>(malloc(w * h * 4 * sizeof(float)));
223223
data_->mask = {0, 0, canvas_width_, canvas_height_};
224224
clear(lum);
225225
}
@@ -303,21 +303,24 @@ void Canvas::box(float x1, float y1, float x2, float y2, float radius) {
303303
}
304304

305305
void Canvas::box(int x1, int y1, int x2, int y2, float radius) {
306-
box((float)x1, (float)y1, (float)x2, (float)y2, radius);
306+
box(static_cast<float>(x1), static_cast<float>(y1), static_cast<float>(x2),
307+
static_cast<float>(y2), radius);
307308
}
308309

309310
void Canvas::polygon(const float* x, const float* y, int vertexCount) {
310311
if (vertexCount < 3) return;
311312
GetPolyDist func(x, y, vertexCount);
312313
data_->draw(canvas_data_, canvas_width_, canvas_height_,
313-
{0, 0, (float)canvas_width_, (float)canvas_height_}, &func);
314+
{0, 0, static_cast<float>(canvas_width_),
315+
static_cast<float>(canvas_height_)},
316+
&func);
314317
}
315318

316319
Texture Canvas::createTexture(bool mipmap) const {
317-
uint8_t* dst =
318-
(uint8_t*)malloc(canvas_width_ * canvas_height_ * 4 * sizeof(uint8_t));
320+
uint8_t* dst = static_cast<uint8_t*>(
321+
malloc(canvas_width_ * canvas_height_ * 4 * sizeof(uint8_t)));
319322
for (int i = 0; i < canvas_width_ * canvas_height_ * 4; ++i) {
320-
int v = (int)(canvas_data_[i] * 255.f + 0.5f);
323+
int v = static_cast<int>(canvas_data_[i] * 255.f + 0.5f);
321324
dst[i] = min(max(v, 0), 255);
322325
}
323326
Texture result(canvas_width_, canvas_height_, dst, mipmap);
@@ -331,8 +334,8 @@ Canvas& Canvas::operator=(const Canvas& other) {
331334
canvas_width_ = other.canvas_width_, canvas_height_ = other.canvas_height_,
332335
canvas_data_ = nullptr;
333336
if (other.canvas_data_)
334-
canvas_data_ =
335-
(float*)malloc(canvas_width_ * canvas_height_ * 4 * sizeof(float));
337+
canvas_data_ = static_cast<float*>(
338+
malloc(canvas_width_ * canvas_height_ * 4 * sizeof(float)));
336339
memcpy(canvas_data_, other.canvas_data_,
337340
canvas_width_ * canvas_height_ * 4 * sizeof(float));
338341
return *this;

0 commit comments

Comments
 (0)