refactor: replace winapi_stubs with std::vector, std::atomic_ref and std::chrono

This commit is contained in:
MatthewBeshay
2026-04-09 00:29:33 +10:00
parent 1b9d27f4a0
commit aa515c5f3d
34 changed files with 121 additions and 477 deletions

View File

@@ -1,10 +1,10 @@
#include "MultiPlayerChunkCache.h"
#include <atomic>
#include <stdint.h>
#include <string.h>
#include "minecraft/network/INetworkService.h"
#include "app/linux/Stubs/winapi_stubs.h"
#include "util/StringHelpers.h"
#include "minecraft/server/MinecraftServer.h"
#include "minecraft/server/level/ServerChunkCache.h"
@@ -210,16 +210,10 @@ LevelChunk* MultiPlayerChunkCache::create(int x, int z) {
chunk->loaded = true;
}
#if (defined _WIN64 || defined __LP64__)
if (InterlockedCompareExchangeRelease64(
(int64_t*)&cache[idx], (int64_t)chunk, (int64_t)lastChunk) ==
(int64_t)lastChunk)
#else
if (InterlockedCompareExchangeRelease(
(int32_t*)&cache[idx], (int32_t)chunk, (int32_t)lastChunk) ==
(int32_t)lastChunk)
#endif // 0
{
LevelChunk* expected = lastChunk;
if (std::atomic_ref<LevelChunk*>(cache[idx])
.compare_exchange_strong(expected, chunk,
std::memory_order_release)) {
// If we're sharing with the server, we'll need to calculate our
// heightmap now, which isn't shared. If we aren't sharing with the
// server, then this will be calculated when the chunk data arrives.