mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 10:03:35 +00:00
Merge pull request #230 from MatthewBeshay/issue/64-remove-winapi-primitives
Issue/64 remove winapi primitives
This commit is contained in:
@@ -22,9 +22,11 @@ const float PistonBaseTile::PLATFORM_THICKNESS = 4.0f;
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
inline void* PistonTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* PistonTlsGetValue(PistonBaseTile::TlsKey key) {
|
||||
return TlsGetValue(key);
|
||||
}
|
||||
|
||||
inline void PistonTlsSetValue(DWORD key, void* value) {
|
||||
inline void PistonTlsSetValue(PistonBaseTile::TlsKey key, void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
#else
|
||||
@@ -45,9 +47,9 @@ inline void PistonTlsSetValue(pthread_key_t key, void* value) {
|
||||
} // namespace
|
||||
|
||||
#if defined(_WIN32)
|
||||
DWORD PistonBaseTile::tlsIdx = TlsAlloc();
|
||||
PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = TlsAlloc();
|
||||
#else
|
||||
pthread_key_t PistonBaseTile::tlsIdx = CreatePistonTlsKey();
|
||||
PistonBaseTile::TlsKey PistonBaseTile::tlsIdx = CreatePistonTlsKey();
|
||||
#endif
|
||||
|
||||
// 4J - NOTE - this ignoreUpdate stuff has been removed from the java version,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Tile.h"
|
||||
#include <cstdint>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
@@ -7,6 +8,12 @@
|
||||
|
||||
class PistonBaseTile : public Tile {
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
|
||||
static const int EXTENDED_BIT = 8;
|
||||
static const int UNDEFINED_FACING = 7;
|
||||
|
||||
@@ -28,11 +35,7 @@ private:
|
||||
Icon* iconBack;
|
||||
Icon* iconPlatform;
|
||||
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdx;
|
||||
#else
|
||||
static pthread_key_t tlsIdx;
|
||||
#endif
|
||||
static TlsKey tlsIdx;
|
||||
// 4J - was just a static but implemented with TLS for our version
|
||||
static bool ignoreUpdate();
|
||||
static void ignoreUpdate(bool set);
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
inline void* TheEndPortalTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* TheEndPortalTlsGetValue(TheEndPortal::TlsKey key) {
|
||||
return TlsGetValue(key);
|
||||
}
|
||||
|
||||
inline void TheEndPortalTlsSetValue(DWORD key, void* value) {
|
||||
inline void TheEndPortalTlsSetValue(TheEndPortal::TlsKey key, void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
#else
|
||||
@@ -34,9 +36,9 @@ inline void TheEndPortalTlsSetValue(pthread_key_t key, void* value) {
|
||||
} // namespace
|
||||
|
||||
#if defined(_WIN32)
|
||||
DWORD TheEndPortal::tlsIdx = TlsAlloc();
|
||||
TheEndPortal::TlsKey TheEndPortal::tlsIdx = TlsAlloc();
|
||||
#else
|
||||
pthread_key_t TheEndPortal::tlsIdx = CreateTheEndPortalTlsKey();
|
||||
TheEndPortal::TlsKey TheEndPortal::tlsIdx = CreateTheEndPortalTlsKey();
|
||||
#endif
|
||||
|
||||
// 4J - allowAnywhere is a static in java, implementing as TLS here to make
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "TileEntities/EntityTile.h"
|
||||
#include <cstdint>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
@@ -8,10 +9,11 @@
|
||||
class TheEndPortal : public EntityTile {
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdx;
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
static pthread_key_t tlsIdx;
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
static TlsKey tlsIdx;
|
||||
// 4J - was just a static but implemented with TLS for our version
|
||||
static bool allowAnywhere();
|
||||
static void allowAnywhere(bool set);
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
inline void* TileTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* TileTlsGetValue(Tile::TlsKey key) { return TlsGetValue(key); }
|
||||
|
||||
inline void TileTlsSetValue(DWORD key, void* value) { TlsSetValue(key, value); }
|
||||
inline void TileTlsSetValue(Tile::TlsKey key, void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
#else
|
||||
pthread_key_t CreateTileTlsKey() {
|
||||
pthread_key_t key;
|
||||
@@ -227,9 +229,9 @@ Tile* Tile::stairs_quartz = NULL;
|
||||
Tile* Tile::woolCarpet = NULL;
|
||||
|
||||
#if defined(_WIN32)
|
||||
DWORD Tile::tlsIdxShape = TlsAlloc();
|
||||
Tile::TlsKey Tile::tlsIdxShape = TlsAlloc();
|
||||
#else
|
||||
pthread_key_t Tile::tlsIdxShape = CreateTileTlsKey();
|
||||
Tile::TlsKey Tile::tlsIdxShape = CreateTileTlsKey();
|
||||
#endif
|
||||
|
||||
Tile::ThreadStorage::ThreadStorage() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../Util/Vec3.h"
|
||||
#include "../Util/Definitions.h"
|
||||
#include "../Util/SoundTypes.h"
|
||||
#include <cstdint>
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@@ -49,6 +50,12 @@ class Tile {
|
||||
friend class WallTile;
|
||||
|
||||
protected:
|
||||
#if defined(_WIN32)
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
|
||||
// 4J added so we can have separate shapes for different threads
|
||||
class ThreadStorage {
|
||||
public:
|
||||
@@ -56,11 +63,7 @@ protected:
|
||||
int tileId;
|
||||
ThreadStorage();
|
||||
};
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdxShape;
|
||||
#else
|
||||
static pthread_key_t tlsIdxShape;
|
||||
#endif
|
||||
static TlsKey tlsIdxShape;
|
||||
public:
|
||||
// Each new thread that needs to use Vec3 pools will need to call one of the
|
||||
// following 2 functions, to either create its own local storage, or share
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
inline void* EntityTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* EntityTlsGetValue(Entity::TlsKey key) { return TlsGetValue(key); }
|
||||
|
||||
inline void EntityTlsSetValue(DWORD key, void* value) {
|
||||
inline void EntityTlsSetValue(Entity::TlsKey key, void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
#else
|
||||
@@ -52,9 +52,9 @@ int Entity::entityCounter =
|
||||
2048; // 4J - changed initialiser to 2048, as we are using range 0 - 2047
|
||||
// as special unique smaller ids for things that need network tracked
|
||||
#if defined(_WIN32)
|
||||
DWORD Entity::tlsIdx = TlsAlloc();
|
||||
Entity::TlsKey Entity::tlsIdx = TlsAlloc();
|
||||
#else
|
||||
pthread_key_t Entity::tlsIdx = CreateEntityTlsKey();
|
||||
Entity::TlsKey Entity::tlsIdx = CreateEntityTlsKey();
|
||||
#endif
|
||||
|
||||
// 4J - added getSmallId & freeSmallId methods
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../IO/NBT/FloatTag.h"
|
||||
#include "../Util/Vec3.h"
|
||||
#include "../Util/Definitions.h"
|
||||
#include <cstdint>
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@@ -38,6 +39,12 @@ class Entity : public std::enable_shared_from_this<Entity> {
|
||||
// functions and constants, without making them publicly
|
||||
// available to everything
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
|
||||
// 4J-PB - added to replace (e instanceof Type), avoiding dynamic casts
|
||||
virtual eINSTANCEOF GetType() = 0;
|
||||
|
||||
@@ -401,11 +408,7 @@ private:
|
||||
static int extraWanderIds[EXTRA_WANDER_MAX];
|
||||
static int extraWanderCount;
|
||||
static int extraWanderTicks;
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdx;
|
||||
#else
|
||||
static pthread_key_t tlsIdx;
|
||||
#endif
|
||||
static TlsKey tlsIdx;
|
||||
public:
|
||||
static void tickExtraWandering();
|
||||
static void countFlagsForPIX();
|
||||
|
||||
@@ -45,9 +45,9 @@
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
inline void* LevelTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* LevelTlsGetValue(Level::TlsKey key) { return TlsGetValue(key); }
|
||||
|
||||
inline void LevelTlsSetValue(DWORD key, void* value) {
|
||||
inline void LevelTlsSetValue(Level::TlsKey key, void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
#else
|
||||
@@ -68,11 +68,11 @@ inline void LevelTlsSetValue(pthread_key_t key, void* value) {
|
||||
} // namespace
|
||||
|
||||
#if defined(_WIN32)
|
||||
DWORD Level::tlsIdx = TlsAlloc();
|
||||
DWORD Level::tlsIdxLightCache = TlsAlloc();
|
||||
Level::TlsKey Level::tlsIdx = TlsAlloc();
|
||||
Level::TlsKey Level::tlsIdxLightCache = TlsAlloc();
|
||||
#else
|
||||
pthread_key_t Level::tlsIdx = CreateLevelTlsKey();
|
||||
pthread_key_t Level::tlsIdxLightCache = CreateLevelTlsKey();
|
||||
Level::TlsKey Level::tlsIdx = CreateLevelTlsKey();
|
||||
Level::TlsKey Level::tlsIdxLightCache = CreateLevelTlsKey();
|
||||
#endif
|
||||
|
||||
// 4J : WESTY : Added for time played stats.
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../Util/ParticleTypes.h"
|
||||
#include "../WorldGen/Biomes/Biome.h"
|
||||
#include "../Util/C4JThread.h"
|
||||
#include <cstdint>
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@@ -48,6 +49,12 @@ class VillageSiege;
|
||||
|
||||
class Level : public LevelSource {
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
|
||||
static const int MAX_TICK_TILES_PER_TICK = 1000;
|
||||
|
||||
// 4J Added
|
||||
@@ -81,13 +88,8 @@ public:
|
||||
|
||||
// 4J - added, making instaTick flag use TLS so we can set it in the chunk
|
||||
// rebuilding thread without upsetting the main game thread
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdx;
|
||||
static DWORD tlsIdxLightCache;
|
||||
#else
|
||||
static pthread_key_t tlsIdx;
|
||||
static pthread_key_t tlsIdxLightCache;
|
||||
#endif
|
||||
static TlsKey tlsIdx;
|
||||
static TlsKey tlsIdxLightCache;
|
||||
static void enableLightingCache();
|
||||
static void destroyLightingCache();
|
||||
static bool getCacheTestEnabled();
|
||||
|
||||
@@ -10,14 +10,17 @@
|
||||
#include "OldChunkStorage.h"
|
||||
#if defined(_WIN32)
|
||||
namespace {
|
||||
inline void* OldChunkStorageTlsGetValue(DWORD key) { return TlsGetValue(key); }
|
||||
inline void* OldChunkStorageTlsGetValue(OldChunkStorage::TlsKey key) {
|
||||
return TlsGetValue(key);
|
||||
}
|
||||
|
||||
inline void OldChunkStorageTlsSetValue(DWORD key, void* value) {
|
||||
inline void OldChunkStorageTlsSetValue(OldChunkStorage::TlsKey key,
|
||||
void* value) {
|
||||
TlsSetValue(key, value);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DWORD OldChunkStorage::tlsIdx = TlsAlloc();
|
||||
OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = TlsAlloc();
|
||||
#else
|
||||
namespace {
|
||||
pthread_key_t CreateOldChunkStorageTlsKey() {
|
||||
@@ -36,7 +39,7 @@ inline void OldChunkStorageTlsSetValue(pthread_key_t key, void* value) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
pthread_key_t OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey();
|
||||
OldChunkStorage::TlsKey OldChunkStorage::tlsIdx = CreateOldChunkStorageTlsKey();
|
||||
#endif
|
||||
OldChunkStorage::ThreadStorage* OldChunkStorage::tlsDefault = NULL;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../../IO/Files/File.h"
|
||||
#include "../../IO/NBT/CompoundTag.h"
|
||||
#include "../../Headers/com.mojang.nbt.h"
|
||||
#include <cstdint>
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@@ -11,6 +12,13 @@
|
||||
class Level;
|
||||
|
||||
class OldChunkStorage : public ChunkStorage {
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
using TlsKey = std::uint32_t;
|
||||
#else
|
||||
using TlsKey = pthread_key_t;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// 4J added so we can have separate storage arrays for different threads
|
||||
class ThreadStorage {
|
||||
@@ -23,11 +31,7 @@ private:
|
||||
ThreadStorage();
|
||||
~ThreadStorage();
|
||||
};
|
||||
#if defined(_WIN32)
|
||||
static DWORD tlsIdx;
|
||||
#else
|
||||
static pthread_key_t tlsIdx;
|
||||
#endif
|
||||
static TlsKey tlsIdx;
|
||||
static ThreadStorage* tlsDefault;
|
||||
|
||||
public:
|
||||
|
||||
@@ -82,7 +82,7 @@ void AddPlayerPacket::read(DataInputStream* dis) // throws IOException
|
||||
m_playerIndex = dis->readByte();
|
||||
m_skinId = static_cast<std::uint32_t>(dis->readInt());
|
||||
m_capeId = static_cast<std::uint32_t>(dis->readInt());
|
||||
INT privileges = dis->readInt();
|
||||
int privileges = dis->readInt();
|
||||
m_uiGamePrivileges = static_cast<unsigned int>(privileges);
|
||||
MemSect(1);
|
||||
unpack = SynchedEntityData::unpack(dis);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "../Util/ArrayWithLength.h"
|
||||
|
||||
// 4J Jev, just thought it would be easier this way.
|
||||
@@ -39,5 +40,7 @@ public:
|
||||
};
|
||||
|
||||
#define MAKE_FOURCC(ch0, ch1, ch2, ch3) \
|
||||
((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
|
||||
((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24))
|
||||
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch0)) | \
|
||||
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch1)) << 8) | \
|
||||
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch2)) << 16) | \
|
||||
(static_cast<std::uint32_t>(static_cast<std::uint8_t>(ch3)) << 24))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <queue>
|
||||
|
||||
typedef int(C4JThreadStartFunc)(void* lpThreadParameter);
|
||||
@@ -215,4 +216,4 @@ private:
|
||||
static DWORD WINAPI entryPoint(LPVOID lpParam);
|
||||
#endif
|
||||
};
|
||||
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
|
||||
void SetThreadName(std::uint32_t threadId, const char* threadName);
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
#include "../Platform/stdafx.h"
|
||||
#include <cstdint>
|
||||
|
||||
// From Xbox documentation
|
||||
|
||||
typedef struct tagTHREADNAME_INFO {
|
||||
DWORD dwType; // Must be 0x1000
|
||||
LPCSTR szName; // Pointer to name (in user address space)
|
||||
DWORD dwThreadID; // Thread ID (-1 for caller thread)
|
||||
DWORD dwFlags; // Reserved for future use; must be zero
|
||||
std::uint32_t dwType; // Must be 0x1000
|
||||
const char* szName; // Pointer to name (in user address space)
|
||||
std::uint32_t dwThreadID; // Thread ID (-1 for caller thread)
|
||||
std::uint32_t dwFlags; // Reserved for future use; must be zero
|
||||
} THREADNAME_INFO;
|
||||
|
||||
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName) {
|
||||
void SetThreadName(std::uint32_t threadId, const char* threadName) {
|
||||
#ifndef __PS3__
|
||||
THREADNAME_INFO info;
|
||||
|
||||
info.dwType = 0x1000;
|
||||
info.szName = szThreadName;
|
||||
info.dwThreadID = dwThreadID;
|
||||
info.szName = threadName;
|
||||
info.dwThreadID = threadId;
|
||||
info.dwFlags = 0;
|
||||
|
||||
#if (defined _WINDOWS64 | defined _DURANGO)
|
||||
__try {
|
||||
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD),
|
||||
(ULONG_PTR*)&info);
|
||||
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(std::uint32_t),
|
||||
reinterpret_cast<ULONG_PTR*>(&info));
|
||||
} __except (GetExceptionCode() == 0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION
|
||||
: EXCEPTION_EXECUTE_HANDLER) {
|
||||
}
|
||||
#endif
|
||||
#ifdef _XBOX
|
||||
__try {
|
||||
RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD),
|
||||
(DWORD*)&info);
|
||||
RaiseException(
|
||||
0x406D1388, 0, sizeof(info) / sizeof(std::uint32_t),
|
||||
reinterpret_cast<std::uint32_t*>(&info));
|
||||
} __except (GetExceptionCode() == 0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION
|
||||
: EXCEPTION_EXECUTE_HANDLER) {
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName);
|
||||
void SetThreadName(std::uint32_t threadId, const char* threadName);
|
||||
|
||||
Reference in New Issue
Block a user