Skip to content

Commit 368bafe

Browse files
committed
Finalization for linux branch.
1 parent 1336f6a commit 368bafe

28 files changed

+193
-362
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if (LINUX)
77
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
88

99
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
10+
11+
option(VCPKG "Use vcpkg for dependencies" ON)
1012
endif()
1113

1214
if(WIN32)

src/Core/ByteStream.cpp

Lines changed: 16 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -55,94 +55,26 @@ void WriteStream::write(const void* in, int bytes)
5555
}
5656
}
5757

58-
void WriteStream::write8(const void* val)
59-
{
60-
if(current_size_ < capacity_)
61-
{
62-
buffer_[current_size_] = *(const uint8_t*)val;
63-
++current_size_;
64-
}
65-
else if(!is_external_buffer_)
66-
{
67-
capacity_ <<= 1;
68-
buffer_ = (uchar*)realloc(buffer_, capacity_);
69-
buffer_[current_size_] = *(const uint8_t*)val;
70-
++current_size_;
71-
}
72-
else
73-
{
74-
is_write_successful_ = false;
75-
}
76-
}
77-
78-
void WriteStream::write16(const void* val)
79-
{
80-
int newSize = current_size_ + sizeof(uint16_t);
81-
if(newSize <= capacity_)
82-
{
83-
*(uint16_t*)(buffer_ + current_size_) = *(const uint16_t*)val;
84-
current_size_ = newSize;
85-
}
86-
else if(!is_external_buffer_)
87-
{
88-
capacity_ <<= 1;
89-
buffer_ = (uchar*)realloc(buffer_, capacity_);
90-
*(uint16_t*)(buffer_ + current_size_) = *(const uint16_t*)val;
91-
current_size_ = newSize;
92-
}
93-
else
94-
{
95-
is_write_successful_ = false;
96-
}
97-
}
98-
99-
void WriteStream::write32(const void* val)
100-
{
101-
int newSize = current_size_ + sizeof(uint32_t);
102-
if(newSize <= capacity_)
103-
{
104-
*(uint32_t*)(buffer_ + current_size_) = *(const uint32_t*)val;
105-
current_size_ = newSize;
106-
}
107-
else if(!is_external_buffer_)
108-
{
109-
capacity_ <<= 1;
110-
buffer_ = (uchar*)realloc(buffer_, capacity_);
111-
*(uint32_t*)(buffer_ + current_size_) = *(const uint32_t*)val;
112-
current_size_ = newSize;
113-
}
114-
else
115-
{
116-
is_write_successful_ = false;
117-
}
118-
}
119-
120-
void WriteStream::write64(const void* val)
121-
{
122-
int newSize = current_size_ + sizeof(uint64_t);
123-
if(newSize <= capacity_)
124-
{
125-
*(uint64_t*)(buffer_ + current_size_) = *(const uint64_t*)val;
126-
current_size_ = newSize;
127-
}
128-
else if(!is_external_buffer_)
129-
{
130-
capacity_ <<= 1;
131-
buffer_ = (uchar*)realloc(buffer_, capacity_);
132-
*(uint64_t*)(buffer_ + current_size_) = *(const uint64_t*)val;
133-
current_size_ = newSize;
134-
}
135-
else
136-
{
137-
is_write_successful_ = false;
138-
}
139-
}
140-
14158
void WriteStream::writeNum(uint num)
14259
{
14360
if(num < 0x80)
14461
{
145-
write8(&num);
62+
if(current_size_ < capacity_)
63+
{
64+
buffer_[current_size_] = static_cast<uint8_t>(num);
65+
++current_size_;
66+
}
67+
else if(!is_external_buffer_)
68+
{
69+
capacity_ <<= 1;
70+
buffer_ = (uchar*)realloc(buffer_, capacity_);
71+
buffer_[current_size_] = static_cast<uint8_t>(num);
72+
++current_size_;
73+
}
74+
else
75+
{
76+
is_write_successful_ = false;
77+
}
14678
}
14779
else
14880
{
@@ -206,70 +138,6 @@ void ReadStream::read(void* out, int bytes)
206138
}
207139
}
208140

209-
void ReadStream::read8(void* out)
210-
{
211-
if(read_position_ != end_position_)
212-
{
213-
*(uint8_t*)out = *read_position_;
214-
++read_position_;
215-
}
216-
else
217-
{
218-
*(uint8_t*)out = 0;
219-
read_position_ = end_position_;
220-
is_read_successful_ = false;
221-
}
222-
}
223-
224-
void ReadStream::read16(void* out)
225-
{
226-
auto newPos = read_position_ + sizeof(uint16_t);
227-
if(newPos <= end_position_)
228-
{
229-
*(uint16_t*)out = *(const uint16_t*)read_position_;
230-
read_position_ = newPos;
231-
}
232-
else
233-
{
234-
*(uint16_t*)out = 0;
235-
read_position_ = end_position_;
236-
is_read_successful_ = false;
237-
}
238-
}
239-
240-
241-
void ReadStream::read32(void* out)
242-
{
243-
auto newPos = read_position_ + sizeof(uint32_t);
244-
if(newPos <= end_position_)
245-
{
246-
*(uint32_t*)out = *(const uint32_t*)read_position_;
247-
read_position_ = newPos;
248-
}
249-
else
250-
{
251-
*(uint32_t*)out = 0;
252-
read_position_ = end_position_;
253-
is_read_successful_ = false;
254-
}
255-
}
256-
257-
void ReadStream::read64(void* out)
258-
{
259-
auto newPos = read_position_ + sizeof(uint64_t);
260-
if(newPos <= end_position_)
261-
{
262-
*(uint64_t*)out = *(const uint64_t*)read_position_;
263-
read_position_ = newPos;
264-
}
265-
else
266-
{
267-
*(uint64_t*)out = 0;
268-
read_position_ = end_position_;
269-
is_read_successful_ = false;
270-
}
271-
}
272-
273141
uint ReadStream::readNum()
274142
{
275143
uint32_t out;

src/Core/ByteStream.h

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,13 @@ struct WriteStream
1414

1515
void write(const void* in, int bytes);
1616

17-
void write8(const void* val);
18-
void write16(const void* val);
19-
void write32(const void* val);
20-
void write64(const void* val);
21-
2217
void writeNum(uint num);
2318
void writeStr(StringRef str);
2419

25-
template <unsigned int S>
26-
inline void writeSz(const void* val)
27-
{
28-
write(val, S);
29-
}
30-
31-
template <>
32-
inline void writeSz<1>(const void* val)
33-
{
34-
write8(val);
35-
}
36-
37-
template <>
38-
inline void writeSz<2>(const void* val)
39-
{
40-
write16(val);
41-
}
42-
43-
template <>
44-
inline void writeSz<4>(const void* val)
45-
{
46-
write32(val);
47-
}
48-
49-
template <>
50-
inline void writeSz<8>(const void* val)
51-
{
52-
write64(val);
53-
}
54-
5520
template <typename T>
5621
inline void write(const T& val)
5722
{
58-
writeSz<sizeof(T)>(&val);
23+
write(&val, sizeof(T));
5924
}
6025

6126
// Returns true if all write operations have succeeded.
@@ -83,58 +48,23 @@ struct ReadStream
8348

8449
void read(void* out, int bytes);
8550

86-
void read8(void* out);
87-
void read16(void* out);
88-
void read32(void* out);
89-
void read64(void* out);
90-
9151
uint readNum();
9252
String readStr();
9353

9454
void readNum(uint& num);
9555
void readStr(String& str);
9656

97-
template <size_t S>
98-
inline void readSz(void* out)
99-
{
100-
read(out, S);
101-
}
102-
103-
template <>
104-
inline void readSz<1>(void* out)
105-
{
106-
read8(out);
107-
}
108-
109-
template <>
110-
inline void readSz<2>(void* out)
111-
{
112-
read16(out);
113-
}
114-
115-
template <>
116-
inline void readSz<4>(void* out)
117-
{
118-
read32(out);
119-
}
120-
121-
template <>
122-
inline void readSz<8>(void* out)
123-
{
124-
read64(out);
125-
}
126-
12757
template <typename T>
12858
inline void read(T& out)
12959
{
130-
readSz<sizeof(T)>(&out);
60+
read(&out, sizeof(T));
13161
}
13262

13363
template <typename T>
13464
inline T read()
13565
{
13666
T out = T();
137-
readSz<sizeof(T)>(&out);
67+
read(&out, sizeof(T));
13868
return out;
13969
}
14070

src/Core/Canvas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct GetPolyDist : public DistanceFunc
156156

157157
struct Canvas::Data
158158
{
159-
Canvas::Data();
159+
Data();
160160
void draw(float* buf, int w, int h, const areaf& area, DistanceFunc* func);
161161

162162
areai mask;

src/Core/FontData.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include <System/OpenGL.h>
1111

12+
#include <algorithm>
13+
#include <vector>
14+
1215
namespace Vortex {
1316

1417
static const int PADDING = 1;
@@ -59,7 +62,7 @@ static GlyphCache* CreateCache(FT_Face face, int size)
5962
{
6063
int texW = 128, texH = 128;
6164
while(texW < 1024 && texW < size * 8 + 64) texW *= 2;
62-
std::vector<uchar> pixels(texW * texH, 0);
65+
std::vector<uchar> pixels(texW * texH);
6366

6467
auto* cache = new GlyphCache;
6568
cache->tex = TextureManager::load(texW, texH, FORMAT, false, pixels.data());
@@ -217,7 +220,7 @@ static Glyph* PutGlyphInCache(GlyphCache* cache, FT_GlyphSlot slot)
217220
// Copy the glyph pixels to the cache texture.
218221
uchar* pixels = CopyGlyphBitmap(bitmapW, bitmapH, bitmap);
219222
cache->tex->modify(glyph->box.x, glyph->box.y, bitmapW, bitmapH, pixels);
220-
cache->shelfH = max(cache->shelfH, bitmapH);
223+
cache->shelfH = std::max(cache->shelfH, bitmapH);
221224
free(pixels);
222225

223226
// Set the glyph uvs.

src/Core/Polyfit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <math.h>
77

8+
#include <algorithm>
9+
810
namespace mathalgo {
911

1012
template <typename T>
@@ -307,4 +309,4 @@ void polyfit(int degree, T* outCoefs, const T* inValues, int numNonZeroValues, i
307309
}
308310
}
309311

310-
}; // namespace mathalgo
312+
}; // namespace mathalgo

src/Core/Renderer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <System/Debug.h>
1010
#include <System/OpenGL.h>
1111

12+
#include <algorithm>
13+
1214
namespace Vortex {
1315

1416
static const int BATCH_QUAD_LIMIT = 256;
@@ -206,7 +208,7 @@ void Renderer::pushScissorRect(const recti& r)
206208
void Renderer::pushScissorRect(int x, int y, int w, int h)
207209
{
208210
auto& stack = RI->scissorStack;
209-
w = max(w, 0), h = max(h, 0);
211+
w = std::max(w, 0), h = std::max(h, 0);
210212
if(stack.empty())
211213
{
212214
// The new scissor region is the first scissor region, use it as-is.
@@ -217,10 +219,10 @@ void Renderer::pushScissorRect(int x, int y, int w, int h)
217219
{
218220
// Calculate the intersection of the current and new scissor region.
219221
recti last = stack.back();
220-
int r = min(last.x + last.w, x + w);
221-
int b = min(last.y + last.h, y + h);
222-
x = max(last.x, x), w = max(0, r - x);
223-
y = max(last.y, y), h = max(0, b - y);
222+
int r = std::min(last.x + last.w, x + w);
223+
int b = std::min(last.y + last.h, y + h);
224+
x = std::max(last.x, x), w = std::max(0, r - x);
225+
y = std::max(last.y, y), h = std::max(0, b - y);
224226
stack.push_back({x, y, w, h});
225227
}
226228

src/Core/TextureImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <map>
1414

1515
#define WIN32_LEAN_AND_MEAN
16-
#include "windows.h"
17-
#include "gl/gl.h"
16+
#include <windows.h>
17+
#include <GL/gl.h>
1818

1919
namespace Vortex {
2020
namespace {

0 commit comments

Comments
 (0)