Half of day 38 complete.
This commit is contained in:
@@ -1,7 +1,97 @@
|
||||
#ifndef CORE_H_SENTRY
|
||||
#define CORE_H_SENTRY
|
||||
|
||||
/* ---- Types ---------------------------------------------------------- */
|
||||
/* ---- Environment Detection ------------------------------------------ */
|
||||
|
||||
/* Architecture */
|
||||
|
||||
#ifndef ARCHITECTURE_X64
|
||||
#define ARCHITECTURE_X64 0
|
||||
#endif
|
||||
|
||||
#ifndef ARCHITECTURE_X86
|
||||
#define ARCHITECTURE_X86 0
|
||||
#endif
|
||||
|
||||
#ifndef ARCHITECTURE_ARM64
|
||||
#define ARCHITECTURE_ARM64 0
|
||||
#endif
|
||||
|
||||
#ifndef ARCHITECTURE_ARM32
|
||||
#define ARCHITECTURE_ARM32 0
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64)
|
||||
#undef ARCHITECTURE_X64
|
||||
#define ARCHITECTURE_X64 1
|
||||
#elif defined(i386) || defined(__i386) || defined(__i386__)
|
||||
#undef ARCHITECTURE_X86
|
||||
#define ARCHITECTURE_X86 1
|
||||
#elif defined(__aarch64__)
|
||||
#undef ARCHITECTURE_ARM64
|
||||
#define ARCHITECTURE_ARM64 1
|
||||
#elif defined(__arm__)
|
||||
#undef ARCHITECTURE_ARM32
|
||||
#define ARCHITECTURE_ARM32 1
|
||||
#else
|
||||
#error Unknown not architecture . . .
|
||||
#endif
|
||||
|
||||
/* OS */
|
||||
|
||||
#ifndef OS_WINDOWS
|
||||
#define OS_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#ifndef OS_MACOS
|
||||
#define OS_MACOS 0
|
||||
#endif
|
||||
|
||||
#ifndef OS_LINUX
|
||||
#define OS_LINUX 0
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#undef OS_WINDOWS
|
||||
#define OS_WINDOWS 1
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
#undef OS_MACOS
|
||||
#define OS_MACOS 1
|
||||
#elif defined(__linux__)
|
||||
#undef OS_LINUX
|
||||
#define OS_LINUX 1
|
||||
#else
|
||||
#error Unknown Operating System . . .
|
||||
#endif
|
||||
|
||||
/* Compiler */
|
||||
|
||||
#ifndef COMPILER_MSVC
|
||||
#define COMPILER_MSVC 0
|
||||
#endif
|
||||
|
||||
#ifndef COMPILER_CLANG
|
||||
#define COMPILER_CLANG 0
|
||||
#endif
|
||||
|
||||
#ifndef COMPILER_GCC
|
||||
#define COMPILER_GCC 0
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
#undef COMPILER_MSVC
|
||||
#define COMPILER_MSVC 1
|
||||
#elif __clang__
|
||||
#undef COMPILER_CLANG
|
||||
#define COMPILER_CLANG 1
|
||||
#elif __GNUC__
|
||||
#undef COMPILER_GCC
|
||||
#define COMPILER_GCC 1
|
||||
#else
|
||||
#error Unknown compiler . . .
|
||||
#endif
|
||||
|
||||
/* ---- Switches ------------------------------------------------------- */
|
||||
|
||||
#ifndef BUILD_DEBUG
|
||||
#define BUILD_DEBUG 1
|
||||
@@ -11,6 +101,8 @@
|
||||
#define BUILD_INTERNAL 1
|
||||
#endif
|
||||
|
||||
/* ---- Types ---------------------------------------------------------- */
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
@@ -51,7 +143,7 @@ typedef double F64;
|
||||
|
||||
/* ---- Asserts -------------------------------------------------------- */
|
||||
|
||||
#define TRAP() __builtin_trap()
|
||||
#define TRAP() __builtin_trap() // TODO: GCC and CLANG thing; not supported on MSVC.
|
||||
|
||||
#define ASSERT_ALWAYS(x) do { if(!(x)) { TRAP(); } } while(0)
|
||||
#if BUILD_DEBUG
|
||||
@@ -81,6 +173,11 @@ typedef double F64;
|
||||
#define MAX_U16 (U16)0xffff
|
||||
#define MAX_U8 (U8)0xff
|
||||
|
||||
#define MIN_U64 (U64)0x0
|
||||
#define MIN_U32 (U32)0x0
|
||||
#define MIN_U16 (U16)0x0
|
||||
#define MIN_U8 (U8)0x0
|
||||
|
||||
#define MAX_S64 (S64)0x7fffffffffffffff
|
||||
#define MAX_S32 (S32)0x7fffffff
|
||||
#define MAX_S16 (S16)0x7fff
|
||||
|
||||
+29
-11
@@ -110,7 +110,11 @@ static void DrawBitmap(game_offscreen_buffer *Buffer, loaded_bitmap *Bitmap, F32
|
||||
U32 *Dest = (U32 *)DestRow;
|
||||
U32 *Source = SourceRow;
|
||||
for(S32 X = MinX; X < MaxX; X++) {
|
||||
*Dest++ = *Source++;
|
||||
if((*Source >> 24) > 128)
|
||||
*Dest = *Source;
|
||||
|
||||
Dest++;
|
||||
Source++;
|
||||
}
|
||||
DestRow += Buffer->Pitch;
|
||||
SourceRow -= Bitmap->Width;
|
||||
@@ -147,29 +151,43 @@ static loaded_bitmap DEBUGLoadBMP(thread_context *Thread, debug_read_file_result
|
||||
loaded_bitmap Result;
|
||||
memset(&Result, 0, sizeof(Result));
|
||||
|
||||
// NOTE: Byte order in memory is AA BB GG RR, bottom up.
|
||||
// Littel-endian: 0xRRGGBBAA
|
||||
|
||||
debug_read_file_result ReadResult = DEBUGPlatformReadEntireFile(Thread, FileName);
|
||||
if(ReadResult.ContentsSize > 0) {
|
||||
bitmap_header *Header = (bitmap_header *)ReadResult.Contents;
|
||||
|
||||
U32 *Pixels = (U32 *)((U8 *)ReadResult.Contents + Header->BitmapOffset);
|
||||
Result.Pixels = Pixels;
|
||||
Result.Width = Header->Width;
|
||||
Result.Width = Header->Width;
|
||||
Result.Height = Header->Height;
|
||||
|
||||
// TODO: Is this too outdated? As of 2026, this loads fine on little-endian.
|
||||
// Maybe my BMP uses a newer format.
|
||||
/*
|
||||
// NOTE: The byte order in memory is determined by the Header.
|
||||
|
||||
U32 RedMask = Header->RedMask;
|
||||
U32 GreenMask = Header->GreenMask;
|
||||
U32 BlueMask = Header->BlueMask;
|
||||
U32 AlphaMask = ~(RedMask | GreenMask | BlueMask);
|
||||
|
||||
bit_scan_result RedShift = FindLeastSignificantSetBit(RedMask);
|
||||
bit_scan_result GreenShift = FindLeastSignificantSetBit(GreenMask);
|
||||
bit_scan_result BlueShift = FindLeastSignificantSetBit(BlueMask);
|
||||
bit_scan_result AlphaShift = FindLeastSignificantSetBit(AlphaMask);
|
||||
|
||||
ASSERT(RedShift.Found);
|
||||
ASSERT(GreenShift.Found);
|
||||
ASSERT(BlueShift.Found);
|
||||
ASSERT(AlphaShift.Found);
|
||||
|
||||
U32 *SourceDest = Pixels;
|
||||
for(S32 Y = 0; Y < Header->Height; Y++) {
|
||||
for(S32 X = 0; X < Header->Width; X++) {
|
||||
*SourceDest = (*SourceDest >> 8) | (*SourceDest << 24);
|
||||
SourceDest++;
|
||||
U32 C = *SourceDest;
|
||||
|
||||
*SourceDest = ((((C >> AlphaShift.Index) & 0xFF) << 24) |
|
||||
(((C >> RedShift.Index ) & 0xFF) << 16) |
|
||||
(((C >> GreenShift.Index) & 0xFF) << 8) |
|
||||
(((C >> BlueShift.Index ) & 0xFF) << 8));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return Result;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
math.h. */
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h> // memset
|
||||
|
||||
S32 RoundF32toS32(F32 Real32)
|
||||
{
|
||||
@@ -36,5 +37,38 @@ F32 ATan2(F32 Y, F32 X)
|
||||
return Result;
|
||||
}
|
||||
|
||||
typedef struct bit_scan_result {
|
||||
B32 Found;
|
||||
U32 Index;
|
||||
} bit_scan_result;
|
||||
|
||||
static bit_scan_result FindLeastSignificantSetBit(U32 Value)
|
||||
{
|
||||
bit_scan_result Result;
|
||||
memset(&Result, 0, sizeof(Result));
|
||||
|
||||
#if COMPILER_MSVC
|
||||
Result.Found = _BitScanForward(&Result.Index, Value); // TODO: I have not tested this.
|
||||
#elif COMPILER_CLANG
|
||||
Result.Index = __builtin_ffsll(Value); // NOTE: It is a GCC function, but is supported by clang compiler.
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Bit-Operation-Builtins.html
|
||||
if(Result.Index) {
|
||||
Result.Found = TRUE;
|
||||
if(Result.Index > 0)
|
||||
Result.Index--;
|
||||
}
|
||||
#else
|
||||
for(U32 Test = 0; Test < 32; Test++) {
|
||||
if(Value & (1 << Test)) {
|
||||
Result.Index = Test;
|
||||
Result.Found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+7
-5
@@ -16,12 +16,12 @@
|
||||
#include <unistd.h> /* close, write, read, readlink, unlink */
|
||||
#include <dlfcn.h> /* dlopen */
|
||||
#include <sys/stat.h> /* stat */
|
||||
#if __APPLE__ && __MACH__
|
||||
#if OS_MACOS
|
||||
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
||||
#endif
|
||||
|
||||
/* NOTE: This is so it compiles on ARM. */
|
||||
#if __x86_64__ || __i386__
|
||||
#if ARCHITECTURE_X64 || ARCHITECTURE_X86
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
@@ -447,7 +447,7 @@ static void SDLUnloadGameCode(sdl_game_code *GameCode)
|
||||
|
||||
void GetExecutablePath(char *path, size_t path_size)
|
||||
{
|
||||
#if __APPLE__ && __MACH__
|
||||
#if OS_MACOS
|
||||
U32 size;
|
||||
#else
|
||||
ssize_t size;
|
||||
@@ -456,7 +456,7 @@ void GetExecutablePath(char *path, size_t path_size)
|
||||
if(path_size > 0) {
|
||||
path[0] = '\0';
|
||||
|
||||
#if __APPLE__ && __MACH__
|
||||
#if OS_MACOS
|
||||
size = path_size;
|
||||
if(_NSGetExecutablePath(path, &size) != 0) { /* NOTE: Not an
|
||||
absolute
|
||||
@@ -490,7 +490,7 @@ static void SDLGetDLLPath(char *path, size_t path_size, char *exe_path)
|
||||
snprintf(path, path_size, "%s%s", exe_path, GAME_DLL_NAME);
|
||||
}
|
||||
|
||||
#if !(__x86_64__ || __i386__)
|
||||
#if !(ARCHITECTURE_X64 || ARCHITECTURE_X86)
|
||||
U64 __rdtsc()
|
||||
{
|
||||
return 0;
|
||||
@@ -529,8 +529,10 @@ void SDLSetProgramIcon(SDL_Window *Window)
|
||||
} else {
|
||||
/* TODO: This didn't work . . . SDL_GetError() */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "handmade_intrinsics.h"
|
||||
S32 main(S32 argc, char *argv[])
|
||||
{
|
||||
sdl_state SDLState;
|
||||
|
||||
Reference in New Issue
Block a user