Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
planetis-m committed Oct 21, 2024
1 parent 73497d5 commit d74e5e4
Show file tree
Hide file tree
Showing 18 changed files with 413 additions and 131 deletions.
1 change: 1 addition & 0 deletions alternatives_table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ EncodeDataBase64 base64.encode
DecodeDataBase64 base64.decode
ComputeCRC32 crunchy.crc32 External package
ComputeMD5 checksums.md5 External package
ComputeSHA1 checksums.sha1 External package
================== ===================== ================

Misc
Expand Down
98 changes: 56 additions & 42 deletions mangle_names.patch

Large diffs are not rendered by default.

122 changes: 79 additions & 43 deletions src/raylib/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,40 @@ fn srcDir(b: *std.Build) []const u8 {
@compileError("Please take a look at this function again");
}

const src_file = std.fs.path.relative(b.allocator, @src().file, ".") catch @panic("OOM");
const src_file = std.fs.path.relative(b.allocator, ".", @src().file) catch @panic("OOM");
return std.fs.path.dirname(src_file) orelse ".";
}

/// A list of all flags from `src/config.h` that one may override
const config_h_flags = outer: {
// Set this value higher if compile errors happen as `src/config.h` gets larger
@setEvalBranchQuota(1 << 20);

const config_h = @embedFile("config.h");
var flags: [std.mem.count(u8, config_h, "\n") + 1][]const u8 = undefined;

var i = 0;
var lines = std.mem.tokenizeScalar(u8, config_h, '\n');
while (lines.next()) |line| {
if (!std.mem.containsAtLeast(u8, line, 1, "SUPPORT")) continue;
if (std.mem.startsWith(u8, line, "//")) continue;
if (std.mem.startsWith(u8, line, "#if")) continue;

var flag = std.mem.trimLeft(u8, line, " \t"); // Trim whitespace
flag = flag["#define ".len - 1 ..]; // Remove #define
flag = std.mem.trimLeft(u8, flag, " \t"); // Trim whitespace
flag = flag[0 .. std.mem.indexOf(u8, flag, " ") orelse continue]; // Flag is only one word, so capture till space
flag = "-D" ++ flag; // Prepend with -D

flags[i] = flag;
i += 1;
}

// Uncomment this to check what flags normally get passed
//@compileLog(flags[0..i].*);
break :outer flags[0..i].*;
};

fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
raylib_flags_arr.clearRetainingCapacity();

Expand All @@ -86,33 +116,36 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
});
if (options.config.len > 0) {
const file = b.pathJoin(&.{ srcDir(b), "config.h" });
const content = try std.fs.cwd().readFileAlloc(b.allocator, file, std.math.maxInt(usize));
defer b.allocator.free(content);

var lines = std.mem.splitScalar(u8, content, '\n');
while (lines.next()) |line| {
if (!std.mem.containsAtLeast(u8, line, 1, "SUPPORT")) continue;
if (std.mem.startsWith(u8, line, "//")) continue;
if (std.mem.startsWith(u8, line, "#if")) continue;

var flag = std.mem.trimLeft(u8, line, " \t"); // Trim whitespace
flag = flag["#define ".len - 1 ..]; // Remove #define
flag = std.mem.trimLeft(u8, flag, " \t"); // Trim whitespace
flag = flag[0 .. std.mem.indexOf(u8, flag, " ") orelse continue]; // Flag is only one word, so capture till space
flag = try std.fmt.allocPrint(b.allocator, "-D{s}", .{flag}); // Prepend with -D

// If user specifies the flag skip it
if (std.mem.containsAtLeast(u8, options.config, 1, flag)) continue;

// Append default value from config.h to compile flags
try raylib_flags_arr.append(b.allocator, flag);
}
// Sets a flag indiciating the use of a custom `config.h`
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");

// Append config flags supplied by user to compile flags
try raylib_flags_arr.append(b.allocator, options.config);
// Splits a space-separated list of config flags into multiple flags
//
// Note: This means certain flags like `-x c++` won't be processed properly.
// `-xc++` or similar should be used when possible
var config_iter = std.mem.tokenizeScalar(u8, options.config, ' ');

// Apply config flags supplied by the user
while (config_iter.next()) |config_flag|
try raylib_flags_arr.append(b.allocator, config_flag);

// Apply all relevant configs from `src/config.h` *except* the user-specified ones
//
// Note: Currently using a suboptimal `O(m*n)` time algorithm where:
// `m` corresponds roughly to the number of lines in `src/config.h`
// `n` corresponds to the number of user-specified flags
outer: for (config_h_flags) |flag| {
// If a user already specified the flag, skip it
while (config_iter.next()) |config_flag| {
// For a user-specified flag to match, it must share the same prefix and have the
// same length or be followed by an equals sign
if (!std.mem.startsWith(u8, config_flag, flag)) continue;
if (config_flag.len == flag.len or config_flag[flag.len] == '=') continue :outer;
}

try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
// Otherwise, append default value from config.h to compile flags
try raylib_flags_arr.append(b.allocator, flag);
}
}

if (options.shared) {
Expand Down Expand Up @@ -319,10 +352,28 @@ pub const Options = struct {
shared: bool = false,
linux_display_backend: LinuxDisplayBackend = .Both,
opengl_version: OpenglVersion = .auto,
/// config should be a list of cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL"
/// config should be a list of space-separated cflags, eg, "-DSUPPORT_CUSTOM_FRAME_CONTROL"
config: []const u8 = &.{},

raygui_dependency_name: []const u8 = "raygui",

const defaults = Options{};

fn getOptions(b: *std.Build) Options {
return .{
.platform = b.option(PlatformBackend, "platform", "Choose the platform backedn for desktop target") orelse defaults.platform,
.raudio = b.option(bool, "raudio", "Compile with audio support") orelse defaults.raudio,
.raygui = b.option(bool, "raygui", "Compile with raygui support") orelse defaults.raygui,
.rmodels = b.option(bool, "rmodels", "Compile with models support") orelse defaults.rmodels,
.rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext,
.rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures,
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
};
}
};

pub const OpenglVersion = enum {
Expand Down Expand Up @@ -371,22 +422,7 @@ pub fn build(b: *std.Build) !void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

const defaults = Options{};
const options = Options{
.platform = b.option(PlatformBackend, "platform", "Choose the platform backedn for desktop target") orelse defaults.platform,
.raudio = b.option(bool, "raudio", "Compile with audio support") orelse defaults.raudio,
.raygui = b.option(bool, "raygui", "Compile with raygui support") orelse defaults.raygui,
.rmodels = b.option(bool, "rmodels", "Compile with models support") orelse defaults.rmodels,
.rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext,
.rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures,
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.shared = b.option(bool, "shared", "Compile as shared library") orelse defaults.shared,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
};

const lib = try compileRaylib(b, target, optimize, options);
const lib = try compileRaylib(b, target, optimize, Options.getOptions(b));

lib.installHeader(b.path(b.pathJoin(&.{ srcDir(b), "raylib.h" })), "raylib.h");
lib.installHeader(b.path(b.pathJoin(&.{ srcDir(b), "raymath.h" })), "raymath.h");
Expand Down
13 changes: 10 additions & 3 deletions src/raylib/external/rl_gputex.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
if (header->ddspf.flags == 0x40) // No alpha channel
{
int data_size = image_pixel_size*sizeof(unsigned short);
if (header->mipmap_count > 1) data_size = data_size + data_size / 3;
image_data = RL_MALLOC(data_size);

memcpy(image_data, file_data_ptr, data_size);
Expand All @@ -196,6 +197,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
if (header->ddspf.a_bit_mask == 0x8000) // 1bit alpha
{
int data_size = image_pixel_size*sizeof(unsigned short);
if (header->mipmap_count > 1) data_size = data_size + data_size / 3;
image_data = RL_MALLOC(data_size);

memcpy(image_data, file_data_ptr, data_size);
Expand All @@ -215,6 +217,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
else if (header->ddspf.a_bit_mask == 0xf000) // 4bit alpha
{
int data_size = image_pixel_size*sizeof(unsigned short);
if (header->mipmap_count > 1) data_size = data_size + data_size / 3;
image_data = RL_MALLOC(data_size);

memcpy(image_data, file_data_ptr, data_size);
Expand All @@ -236,6 +239,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
else if ((header->ddspf.flags == 0x40) && (header->ddspf.rgb_bit_count == 24)) // DDS_RGB, no compressed
{
int data_size = image_pixel_size*3*sizeof(unsigned char);
if (header->mipmap_count > 1) data_size = data_size + data_size / 3;
image_data = RL_MALLOC(data_size);

memcpy(image_data, file_data_ptr, data_size);
Expand All @@ -245,6 +249,7 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
else if ((header->ddspf.flags == 0x41) && (header->ddspf.rgb_bit_count == 32)) // DDS_RGBA, no compressed
{
int data_size = image_pixel_size*4*sizeof(unsigned char);
if (header->mipmap_count > 1) data_size = data_size + data_size / 3;
image_data = RL_MALLOC(data_size);

memcpy(image_data, file_data_ptr, data_size);
Expand All @@ -265,9 +270,11 @@ void *rl_load_dds_from_memory(const unsigned char *file_data, unsigned int file_
}
else if (((header->ddspf.flags == 0x04) || (header->ddspf.flags == 0x05)) && (header->ddspf.fourcc > 0)) // Compressed
{
// NOTE: This forces only 1 mipmap to be loaded which is not really correct but it works
int data_size = (header->pitch_or_linear_size < file_size - 0x80) ? header->pitch_or_linear_size : file_size - 0x80;
*mips = 1;
int data_size = 0;

// Calculate data size, including all mipmaps
if (header->mipmap_count > 1) data_size = header->pitch_or_linear_size + header->pitch_or_linear_size / 3;
else data_size = header->pitch_or_linear_size;

image_data = RL_MALLOC(data_size*sizeof(unsigned char));

Expand Down
2 changes: 1 addition & 1 deletion src/raylib/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ const char *GetClipboardText(void)
}

// Show mouse cursor
void ShowCursor(void)
void rlShowCursor(void)
{
glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
CORE.Input.Mouse.cursorHidden = false;
Expand Down
1 change: 0 additions & 1 deletion src/raylib/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,6 @@ int InitPlatform(void)
//----------------------------------------------------------------------------
// Define base path for storage
CORE.Storage.basePath = SDL_GetBasePath(); // Alternative: GetWorkingDirectory();
CHDIR(CORE.Storage.basePath);
//----------------------------------------------------------------------------

TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (SDL): Initialized successfully");
Expand Down
46 changes: 40 additions & 6 deletions src/raylib/platforms/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
typedef struct {
GLFWwindow *handle; // GLFW window handle (graphic device)
bool ourFullscreen; // Internal var to filter our handling of fullscreen vs the user handling of fullscreen
int unmaximizedWidth; // Internal var to store the unmaximized window (canvas) width
int unmaximizedHeight; // Internal var to store the unmaximized window (canvas) height
} PlatformData;

//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -317,7 +319,18 @@ void ToggleBorderlessWindowed(void)
// Set window state: maximized, if resizable
void MaximizeWindow(void)
{
TRACELOG(LOG_WARNING, "MaximizeWindow() not available on target platform");
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
{
platform.unmaximizedWidth = CORE.Window.screen.width;
platform.unmaximizedHeight = CORE.Window.screen.height;

const int tabWidth = EM_ASM_INT( { return window.innerWidth; }, 0);
const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0);

if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);

CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED;
}
}

// Set window state: minimized
Expand All @@ -329,7 +342,12 @@ void MinimizeWindow(void)
// Set window state: not minimized/maximized
void RestoreWindow(void)
{
TRACELOG(LOG_WARNING, "RestoreWindow() not available on target platform");
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
{
if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);

CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED;
}
}

// Set window configuration state using flags
Expand Down Expand Up @@ -398,9 +416,20 @@ void SetWindowState(unsigned int flags)
}

// State change: FLAG_WINDOW_MAXIMIZED
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) != (flags & FLAG_WINDOW_MAXIMIZED)) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
{
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
{
platform.unmaximizedWidth = CORE.Window.screen.width;
platform.unmaximizedHeight = CORE.Window.screen.height;

const int tabWidth = EM_ASM_INT( { return window.innerWidth; }, 0);
const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0);

if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);

CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED;
}
}

// State change: FLAG_WINDOW_UNFOCUSED
Expand Down Expand Up @@ -516,9 +545,14 @@ void ClearWindowState(unsigned int flags)
}

// State change: FLAG_WINDOW_MAXIMIZED
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
{
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
{
if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);

CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED;
}
}

// State change: FLAG_WINDOW_UNDECORATED
Expand Down
2 changes: 2 additions & 0 deletions src/raylib/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outpu
RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize); // Decode Base64 string data, memory must be MemFree()
RLAPI unsigned int ComputeCRC32(unsigned char *data, int dataSize); // Compute CRC32 hash code
RLAPI unsigned int *ComputeMD5(unsigned char *data, int dataSize); // Compute MD5 hash code, returns static int[4] (16 bytes)
RLAPI unsigned int *ComputeSHA1(unsigned char *data, int dataSize); // Compute SHA1 hash code, returns static int[5] (20 bytes)


// Automation events functionality
RLAPI AutomationEventList LoadAutomationEventList(const char *fileName); // Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS
Expand Down
Loading

0 comments on commit d74e5e4

Please sign in to comment.