Skip to content

Commit 920a52f

Browse files
committed
Fix Windows build
1 parent 7e3d99c commit 920a52f

File tree

11 files changed

+76
-48
lines changed

11 files changed

+76
-48
lines changed

polymer/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ file(GLOB_RECURSE SOURCES *.cpp)
55
find_package(Vulkan REQUIRED)
66
find_package(CURL REQUIRED)
77

8+
list(FILTER SOURCES EXCLUDE REGEX "/platform/")
9+
810
if (UNIX)
911
find_package(glfw3 CONFIG REQUIRED)
1012

11-
list(FILTER SOURCES EXCLUDE REGEX "/platform/")
1213
file(GLOB_RECURSE UNIX_SOURCES ${PROJECT_SOURCE_DIR}/polymer/platform/unix/*.cpp)
1314
list(APPEND SOURCES ${UNIX_SOURCES})
1415

polymer/asset/block_assets.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ bool AssetParser::ParseBlocks(MemoryArena* perm_arena, const char* blocks_filena
551551
long total_read = 0;
552552

553553
while (total_read < file_size) {
554-
total_read += fread(buffer + total_read, 1, file_size - total_read, f);
554+
total_read += (long)fread(buffer + total_read, 1, file_size - total_read, f);
555555
}
556556

557557
fclose(f);
@@ -846,7 +846,8 @@ static bool HasPropertyValue(const String& properties, const String& name, const
846846
return false;
847847
}
848848

849-
static bool HasAnySplitPropertyValue(BlockRegistry* registry, size_t bid, const String& name, const String& value, char separator) {
849+
static bool HasAnySplitPropertyValue(BlockRegistry* registry, size_t bid, const String& name, const String& value,
850+
char separator) {
850851
String* properties = registry->properties + bid;
851852

852853
if (name.size == 0 && properties == nullptr || properties->size == 0) return true;

polymer/connection.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#ifdef _WIN32
1313
#define WIN32_LEAN_AND_MEAN
14-
#include <Windows.h>
1514
#include <WS2tcpip.h>
15+
#include <Windows.h>
1616
#define POLY_EWOULDBLOCK WSAEWOULDBLOCK
1717
#else
1818
#include <arpa/inet.h>
@@ -151,7 +151,8 @@ void Connection::SetBlocking(bool blocking) {
151151
#endif
152152
}
153153

154-
void Connection::SendHandshake(u32 version, const char* address, size_t address_size, u16 port, ProtocolState state_request) {
154+
void Connection::SendHandshake(u32 version, const char* address, size_t address_size, u16 port,
155+
ProtocolState state_request) {
155156
builder.WriteVarInt(version);
156157
builder.WriteString(address, address_size);
157158
builder.WriteU16(port);

polymer/memory.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#define WIN32_LEAN_AND_MEAN
99
#include <Windows.h>
1010
#else
11-
#include <unistd.h>
1211
#include <sys/mman.h>
12+
#include <unistd.h>
1313
#endif
1414

1515
namespace polymer {
@@ -126,26 +126,26 @@ u8* AllocateMirroredBuffer(size_t size) {
126126
return view;
127127
#else
128128
size_t pagesize = getpagesize();
129-
int fd = fileno(tmpfile());
130-
size_t paged_aligned_size = (size / pagesize) * pagesize;
129+
int fd = fileno(tmpfile());
130+
size_t paged_aligned_size = (size / pagesize) * pagesize;
131131

132-
assert((size / pagesize) == ((size + pagesize - 1) / pagesize));
132+
assert((size / pagesize) == ((size + pagesize - 1) / pagesize));
133133

134-
// Resize the file to the requested size so the buffer can be mapped to it.
135-
if (ftruncate(fd, paged_aligned_size) != 0) {
134+
// Resize the file to the requested size so the buffer can be mapped to it.
135+
if (ftruncate(fd, paged_aligned_size) != 0) {
136136
fprintf(stderr, "ftruncate() error\n");
137137
return nullptr;
138138
}
139139

140-
// Grab some virtual memory space for the full wrapped buffer.
141-
u8* buffer = (u8*)mmap(NULL, paged_aligned_size * 2, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
140+
// Grab some virtual memory space for the full wrapped buffer.
141+
u8* buffer = (u8*)mmap(NULL, paged_aligned_size * 2, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
142142

143-
// Map the beginning of the virtual memory to the tmpfile.
144-
mmap(buffer, paged_aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
145-
// Map the wrapping section of the buffer back to the tmpfile.
146-
mmap(buffer + paged_aligned_size, paged_aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
143+
// Map the beginning of the virtual memory to the tmpfile.
144+
mmap(buffer, paged_aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
145+
// Map the wrapping section of the buffer back to the tmpfile.
146+
mmap(buffer + paged_aligned_size, paged_aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
147147

148-
return buffer;
148+
return buffer;
149149
#endif
150150
}
151151

polymer/packet_interpreter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ void PacketInterpreter::InterpretPlay(RingBuffer* rb, u64 pkt_id, size_t pkt_siz
171171
u64 id = rb->ReadU64();
172172

173173
connection->SendKeepAlive(id);
174-
printf("Sending keep alive %lu\n", id);
175-
fflush(stdout);
176174
} break;
177175
case PlayProtocol::PlayerPositionAndLook: {
178176
double x = rb->ReadDouble();

polymer/platform/unix/unix_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ int run(const LaunchArgs& args) {
337337
const char* kAddress = "127.0.0.1";
338338
const char* kUsername = "Polymer";
339339

340-
connection->SendHandshake(kProtocolVersion, args.server.data, args.server.size, args.server_port, ProtocolState::Login);
340+
connection->SendHandshake(kProtocolVersion, args.server.data, args.server.size, args.server_port,
341+
ProtocolState::Login);
341342
connection->SendLoginStart(args.username.data, args.username.size);
342343

343344
memcpy(game->player_manager.client_name, args.username.data, args.username.size);

polymer/platform/win32/win32_main.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ static bool g_display_cursor = false;
5252

5353
namespace render {
5454

55-
const char* const kRequiredExtensions[] = {"VK_KHR_surface", "VK_KHR_win32_surface", "VK_EXT_debug_utils"};
56-
const char* const kDeviceExtensions[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
57-
const char* const kValidationLayers[] = {"VK_LAYER_KHRONOS_validation"};
58-
59-
#ifdef NDEBUG
60-
constexpr bool kEnableValidationLayers = false;
61-
constexpr size_t kRequiredExtensionCount = polymer_array_count(kRequiredExtensions) - 1;
62-
#else
63-
constexpr bool kEnableValidationLayers = true;
64-
constexpr size_t kRequiredExtensionCount = polymer_array_count(kRequiredExtensions);
65-
#endif
66-
6755
bool CreateWindowSurface(PolymerWindow window, VkSurfaceKHR* surface) {
6856
HWND hwnd = (HWND)window;
6957

@@ -72,12 +60,13 @@ bool CreateWindowSurface(PolymerWindow window, VkSurfaceKHR* surface) {
7260
surface_info.hinstance = GetModuleHandle(nullptr);
7361
surface_info.hwnd = hwnd;
7462

75-
return vkCreateWin32SurfaceKHR(instance, &surface_info, nullptr, surface) == VK_SUCCESS;
63+
return vkCreateWin32SurfaceKHR(vk_render.instance, &surface_info, nullptr, surface) == VK_SUCCESS;
7664
}
7765

7866
IntRect GetWindowRect(PolymerWindow window) {
7967
IntRect result;
8068
RECT rect;
69+
HWND hwnd = (HWND)window;
8170

8271
GetClientRect(hwnd, &rect);
8372

@@ -254,7 +243,7 @@ int run(const LaunchArgs& args) {
254243
printf("Polymer\n");
255244
fflush(stdout);
256245

257-
GameState* game = memory_arena_construct_type(&perm_arena, GameState, &vk_render, &perm_arena, &trans_arena);
246+
GameState* game = perm_arena.Construct<GameState>(&vk_render, &perm_arena, &trans_arena);
258247
PacketInterpreter interpreter(game);
259248
Connection* connection = &game->connection;
260249

@@ -301,7 +290,28 @@ int run(const LaunchArgs& args) {
301290
return 1;
302291
}
303292

304-
vk_render.Initialize(hwnd);
293+
render::ExtensionRequest extension_request;
294+
295+
const char* kRequiredExtensions[] = {"VK_KHR_surface", "VK_KHR_win32_surface", "VK_EXT_debug_utils"};
296+
const char* kDeviceExtensions[] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
297+
const char* kValidationLayers[] = {"VK_LAYER_KHRONOS_validation"};
298+
299+
#ifdef NDEBUG
300+
constexpr size_t kRequiredExtensionCount = polymer_array_count(kRequiredExtensions) - 1;
301+
constexpr size_t kValidationLayerCount = 0;
302+
#else
303+
constexpr size_t kRequiredExtensionCount = polymer_array_count(kRequiredExtensions);
304+
constexpr size_t kValidationLayerCount = polymer_array_count(kValidationLayers);
305+
#endif
306+
307+
extension_request.device_extensions = kDeviceExtensions;
308+
extension_request.device_extension_count = polymer_array_count(kDeviceExtensions);
309+
extension_request.extensions = kRequiredExtensions;
310+
extension_request.extension_count = kRequiredExtensionCount;
311+
extension_request.validation_layers = kValidationLayers;
312+
extension_request.validation_layer_count = kValidationLayerCount;
313+
314+
vk_render.Initialize(hwnd, extension_request);
305315

306316
{
307317

@@ -375,8 +385,9 @@ int run(const LaunchArgs& args) {
375385

376386
connection->SetBlocking(false);
377387

378-
connection->SendHandshake(kProtocolVersion, args.server, args.server_port, ProtocolState::Login);
379-
connection->SendLoginStart(args.username);
388+
connection->SendHandshake(kProtocolVersion, args.server.data, args.server.size, args.server_port,
389+
ProtocolState::Login);
390+
connection->SendLoginStart(args.username.data, args.username.size);
380391

381392
memcpy(game->player_manager.client_name, args.username.data, args.username.size);
382393
game->player_manager.client_name[args.username.size] = 0;

polymer/render/render.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void VulkanRenderer::RecreateSwapchain() {
705705
vkDeviceWaitIdle(device);
706706

707707
IntRect rect = GetWindowRect(hwnd);
708-
708+
709709
if (rect.right - rect.left == 0 || rect.bottom - rect.top == 0) {
710710
this->render_paused = true;
711711
return;

polymer/render/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <polymer/memory.h>
44

5-
#include <stdio.h>
65
#include <math.h>
6+
#include <stdio.h>
77

88
namespace polymer {
99
namespace render {
@@ -170,7 +170,7 @@ String ReadEntireFile(const char* filename, MemoryArena* arena) {
170170

171171
long total_read = 0;
172172
while (total_read < size) {
173-
total_read += fread(buffer + total_read, 1, size - total_read, f);
173+
total_read += (long)fread(buffer + total_read, 1, size - total_read, f);
174174
}
175175

176176
fclose(f);

polymer/ui/debug.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ struct DebugTextSystem {
2626
va_list args;
2727

2828
va_start(args, fmt);
29-
#ifdef _WIN32
29+
#ifdef _WIN32
3030
size_t size = vsprintf_s(buffer, fmt, args);
31-
#else
31+
#else
3232
size_t size = vsprintf(buffer, fmt, args);
33-
#endif
33+
#endif
3434
va_end(args);
3535

3636
render::FontStyleFlags style = render::FontStyle_Background | render::FontStyle_DropShadow;

0 commit comments

Comments
 (0)