OpenXRay / OpenXRay/xray-16

Getting rid of Microsoft specific types

Open
#23 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Help wanted Portability
Dominant language
C++
Stars
3.6k
Forks
536
Avg merge
6d 1h
Merged PRs (30d)
3

Description

Defines and typedefs such as BOOL, CONST, UINT and DWORD are used pretty much everywhere in the codebase.
Most of these defines where introduced a long time ago (BOOL was added before bool was thrown into C++) and now, most of them are meaningless.
Nowadays, every decent compiler should support C++'s fundamental types without any problem.
Of course, DirectX types and some other funky types (HWND, HHOOK and so on) can't be replaced but there's no excuse for more common types I've pointed out earlier.


Pros
  • Less error-prone (every Microsoft specific type names are upper case)
  • Makes high-level parts of the engine less dependent on MSVC / Windows API
  • Improves compile/runtime speed and makes debugging tasks easier (BOOL is a int typedef whereas bool is a true type)
  • Syntax highlighting / code readability is slightly improved; GitHub syntax highlighter (and probably many others) don't know about BOOL, HANDLE or DWORD but it does its job perfectly well on the standard types.

Cons
  • Nothing. Really, I can't think of any drawbacks.

What to do?

There's nothing hard. We just need to search for these types and replace them by their standard
equivalent.
If you _really_ have to use a non-standard type in a piece of code, it should be better to keep this code 'away (i.e. not in a header nor in the middle of a high-level source file)
To make things easier, here's a table with what should be considered for replacement and their equivalents.

Microsoft types Standard equivalents stdint types
INT8 signed char int8_t
PINT8 signed char * int8_t *
BYTE / UCHAR / UINT8 unsigned char uint8_t
LPBYTE / PBYTE unsigned char * uint8_t *
INT16 / SHORT signed short int16_t
PINT16 / PSHORT signed short * int16_t *
USHORT / WORD / UINT16 unsigned short uint16_t
LPWORD / PWORD unsigned short * uint16_t *
INT / INT32 / LONG / LONG32 signed int int32_t
LPINT / PINT / LPLONG / PLONG / PINT32 /PLONG32 / PLONG signed int * int32_t *
DWORD / DWORD32 / UINT / UINT32 / ULONG32 / ULONG unsigned int uint32_t
LPDWORD / PDWORD / PDWORD32 unsigned int * uint32_t *
INT64 / LONGLONG / LONG64 signed long long int64_t
PINT64 / PLONG64 / PLONGLONG signed long long * int64_t *
DWORDLONG / DWORD64 / QWORD / UINT64 / ULONGLONG / ULONG64 unsigned long long uint64_t
INT_PTR / LONG_PTR N/A1 intptr_t
DWORD_PTR / UINT_PTR N/A1 uintptr_t
BOOL / BOOLEAN bool N/A
LPBOOL / PBOOL / PBOOLEAN bool * N/A
CCHAR / CHAR char N/A
LPSTR / PCHAR char * N/A
LPCSTR / PCSTR const char * N/A
CONST const N/A
FLOAT float N/A
PFLOAT float * N/A
VOID void N/A
LPCVOID const void * N/A
WCHAR wchar_t N/A
LPWSTR / PWSTR / PWCHAR wchar_t * N/A
LPCWSTR / PCWSTR const wchar_t * N/A
1 - Representation of an integer type for pointer precision
  • INT_PTR / LONG_PTR are mapped to a 32-bit signed integer on 32-bits systems and to a 64-bit signed integer on 64-bits systems.
  • DWORD_PTR / UINT_PTR are mapped to a 32-bit unsigned integer on 32-bits systems and to a 64-bit unsigned integer on 64-bits systems.

It's clear that the easiest way to do that would be to use cstdint along with the standard types. Feel free to share anything, any ideas about all this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start with a repository-wide search for the listed Microsoft-specific types and separate replaceable fundamental types from DirectX and Windows API types that must remain. Done means the eligible uses are converted to standard or cstdint types without changing platform-specific interfaces, then the project still compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.