Skip to content

Commit 6d6e6b8

Browse files
committed
Get asset store working on Linux
- Fix cursor delta on chat window close.
1 parent dd8cf73 commit 6d6e6b8

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

polymer/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3131
endif()
3232

3333
if (UNIX)
34-
target_link_libraries(polymer PRIVATE glfw)
34+
target_link_libraries(polymer PRIVATE glfw ${VCPKG_INSTALLED_DIR}/x64-linux/lib/libtomcrypt.a)
3535
elseif (WIN32)
3636
add_compile_definitions(WIN32_LEAN_AND_MEAN VK_USE_PLATFORM_WIN32_KHR)
37-
37+
3838
target_link_libraries(polymer PRIVATE ../vcpkg_installed/x64-windows-static/lib/tomcrypt)
3939
endif()
4040

polymer/asset/asset_store.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ void AssetStore::Initialize() {
118118

119119
// Check local store for version descriptor file
120120
if (HasAsset(version_info)) {
121-
char* filename = GetAbsolutePath(trans_arena, path, "versions\\%s", kVersionDescriptor);
121+
char* filename = GetAbsolutePath(trans_arena, path, "versions/%s", kVersionDescriptor);
122122

123123
ProcessVersionDescriptor(filename);
124124
} else {
125125
net_queue.PushRequest(kVersionDescriptorUrl, this, [](NetworkRequest* request, NetworkResponse* response) {
126126
AssetStore* store = (AssetStore*)request->userp;
127127

128-
char* filename = GetAbsolutePath(store->trans_arena, store->path, "versions\\%s", kVersionDescriptor);
128+
char* filename = GetAbsolutePath(store->trans_arena, store->path, "versions/%s", kVersionDescriptor);
129129

130130
response->SaveToFile(filename);
131131
store->ProcessVersionDescriptor(filename);
@@ -178,7 +178,7 @@ void AssetStore::ProcessVersionDescriptor(const char* path) {
178178
net_queue.PushRequest(url, this, [](NetworkRequest* request, NetworkResponse* response) {
179179
AssetStore* store = (AssetStore*)request->userp;
180180

181-
char* filename = GetAbsolutePath(store->trans_arena, store->path, "versions\\%s", kVersionJar);
181+
char* filename = GetAbsolutePath(store->trans_arena, store->path, "versions/%s", kVersionJar);
182182

183183
response->SaveToFile(filename);
184184
});
@@ -208,13 +208,13 @@ void AssetStore::ProcessVersionDescriptor(const char* path) {
208208
net_queue.PushRequest(url, this, [](NetworkRequest* request, NetworkResponse* response) {
209209
AssetStore* store = (AssetStore*)request->userp;
210210

211-
char* filename = GetAbsolutePath(store->trans_arena, store->path, "index\\%s", kVersionIndex);
211+
char* filename = GetAbsolutePath(store->trans_arena, store->path, "index/%s", kVersionIndex);
212212

213213
response->SaveToFile(filename);
214214
store->ProcessIndex(filename);
215215
});
216216
} else {
217-
char* filename = GetAbsolutePath(trans_arena, this->path, "index\\%s", kVersionIndex);
217+
char* filename = GetAbsolutePath(trans_arena, this->path, "index/%s", kVersionIndex);
218218

219219
ProcessIndex(filename);
220220
}
@@ -275,7 +275,7 @@ void AssetStore::ProcessIndex(const char* filename) {
275275
AssetStore* store = (AssetStore*)request->userp;
276276

277277
char* relative_name = request->url + kResourceApi.size;
278-
char* filename = GetAbsolutePath(store->trans_arena, store->path, "objects\\%s", relative_name);
278+
char* filename = GetAbsolutePath(store->trans_arena, store->path, "objects/%s", relative_name);
279279

280280
response->SaveToFile(filename);
281281
});
@@ -296,14 +296,14 @@ String AssetStore::LoadObject(MemoryArena& arena, String name) {
296296

297297
char* objects_folder = GetAbsolutePath(trans_arena, path, "objects");
298298
if (platform.FolderExists(objects_folder)) {
299-
char* hash_folder = GetAbsolutePath(trans_arena, path, "objects\\%s", hash_str);
299+
char* hash_folder = GetAbsolutePath(trans_arena, path, "objects/%s", hash_str);
300300

301301
if (platform.FolderExists(hash_folder)) {
302302
char fullhash[41];
303303

304304
hash->ToString(fullhash);
305305

306-
char* filename = GetAbsolutePath(trans_arena, path, "objects\\%s\\%s", hash_str, fullhash);
306+
char* filename = GetAbsolutePath(trans_arena, path, "objects/%s/%s", hash_str, fullhash);
307307

308308
return ReadEntireFile(filename, arena);
309309
}
@@ -324,19 +324,19 @@ bool AssetStore::HasAsset(AssetInfo& info) {
324324
char* versions_folder = GetAbsolutePath(trans_arena, path, "versions");
325325
if (!platform.FolderExists(versions_folder)) return false;
326326

327-
filename = GetAbsolutePath(trans_arena, path, "versions\\%s", kVersionJar);
327+
filename = GetAbsolutePath(trans_arena, path, "versions/%s", kVersionJar);
328328
} break;
329329
case AssetType::VersionDescriptor: {
330330
char* index_folder = GetAbsolutePath(trans_arena, path, "versions");
331331
if (!platform.FolderExists(index_folder)) return false;
332332

333-
filename = GetAbsolutePath(trans_arena, path, "versions\\%s", kVersionDescriptor);
333+
filename = GetAbsolutePath(trans_arena, path, "versions/%s", kVersionDescriptor);
334334
} break;
335335
case AssetType::Index: {
336336
char* index_folder = GetAbsolutePath(trans_arena, path, "index");
337337
if (!platform.FolderExists(index_folder)) return false;
338338

339-
filename = GetAbsolutePath(trans_arena, path, "index\\%s", kVersionIndex);
339+
filename = GetAbsolutePath(trans_arena, path, "index/%s", kVersionIndex);
340340
} break;
341341
case AssetType::Object: {
342342
char minihash[3] = {};
@@ -349,10 +349,10 @@ bool AssetStore::HasAsset(AssetInfo& info) {
349349
char* objects_folder = GetAbsolutePath(trans_arena, path, "objects");
350350
if (!platform.FolderExists(objects_folder)) return false;
351351

352-
char* hash_folder = GetAbsolutePath(trans_arena, path, "objects\\%s", minihash);
352+
char* hash_folder = GetAbsolutePath(trans_arena, path, "objects/%s", minihash);
353353
if (!platform.FolderExists(hash_folder)) return false;
354354

355-
filename = GetAbsolutePath(trans_arena, path, "objects\\%s\\%s", minihash, fullhash);
355+
filename = GetAbsolutePath(trans_arena, path, "objects/%s/%s", minihash, fullhash);
356356
} break;
357357
default: {
358358
} break;
@@ -371,7 +371,7 @@ bool AssetStore::HasAsset(AssetInfo& info) {
371371
}
372372

373373
char* AssetStore::GetClientPath(MemoryArena& arena) {
374-
return GetAbsolutePath(arena, path, "versions\\%s", kVersionJar);
374+
return GetAbsolutePath(arena, path, "versions/%s", kVersionJar);
375375
}
376376

377377
} // namespace asset

polymer/platform/unix/unix_main.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#define VOLK_IMPLEMENTATION
1717
#include <volk.h>
1818

19+
#include <pwd.h>
20+
#include <sys/stat.h>
21+
#include <sys/types.h>
22+
#include <unistd.h>
23+
1924
namespace polymer {
2025

2126
static Polymer* g_application;
@@ -38,6 +43,15 @@ inline void ToggleCursor() {
3843
glfwSetInputMode(window, GLFW_CURSOR, mode);
3944
}
4045

46+
static void ResetLastCursor(GLFWwindow* window) {
47+
double xpos, ypos;
48+
49+
glfwGetCursorPos(window, &xpos, &ypos);
50+
51+
g_last_cursor.x = (int)xpos;
52+
g_last_cursor.y = (int)ypos;
53+
}
54+
4155
static void OnWindowResize(GLFWwindow* window, int width, int height) {
4256
g_application->renderer.invalid_swapchain = true;
4357
}
@@ -77,6 +91,7 @@ static void OnKeyDown(GLFWwindow* window, int key, int scancode, int action, int
7791
game->chat_window.ToggleDisplay();
7892
g_frame_chat_open = true;
7993
memset(&g_input, 0, sizeof(g_input));
94+
ResetLastCursor(window);
8095
}
8196
} break;
8297
}
@@ -131,6 +146,7 @@ static void OnKeyDown(GLFWwindow* window, int key, int scancode, int action, int
131146
ToggleCursor();
132147
game->chat_window.SendInput(game->connection);
133148
game->chat_window.ToggleDisplay();
149+
ResetLastCursor(window);
134150
} break;
135151
case GLFW_KEY_LEFT: {
136152
game->chat_window.MoveCursor(ui::ChatMoveDirection::Left);
@@ -227,15 +243,42 @@ static ExtensionRequest UnixGetExtensionRequest() {
227243
}
228244

229245
static String UnixGetAssetStorePath(MemoryArena& arena) {
230-
return {};
246+
const char* homedir;
247+
248+
if ((homedir = getenv("HOME")) == NULL) {
249+
homedir = getpwuid(getuid())->pw_dir;
250+
}
251+
252+
if (!homedir) {
253+
fprintf(stderr, "Failed to get home directory.\n");
254+
exit(1);
255+
}
256+
257+
size_t length = strlen(homedir);
258+
259+
const char* kAssetStoreName = "/.polymer/";
260+
size_t name_length = sizeof(kAssetStoreName);
261+
262+
size_t total_size = length + name_length + 2;
263+
char* path_storage = memory_arena_push_type_count(&arena, char, total_size);
264+
265+
sprintf(path_storage, "%s%s/", homedir, kAssetStoreName);
266+
267+
return String(path_storage, total_size);
231268
}
232269

233270
static bool UnixFolderExists(const char* path) {
234-
return false;
271+
struct stat s = {};
272+
273+
if (stat(path, &s)) {
274+
return false;
275+
}
276+
277+
return (s.st_mode & S_IFDIR);
235278
}
236279

237280
static bool UnixCreateFolder(const char* path) {
238-
return false;
281+
return mkdir(path, 0700) == 0;
239282
}
240283

241284
static u8* UnixAllocate(size_t size) {

0 commit comments

Comments
 (0)