mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-18 20:28:01 +00:00
Replaced raylib bindings with custom ones
This commit is contained in:
parent
11e3f91220
commit
678bcf2ad0
Binary file not shown.
@ -5,12 +5,26 @@ Raylib :: #import "raylib-jai";
|
||||
|
||||
#load "clay_renderer_raylib.jai";
|
||||
|
||||
window_width := 1024;
|
||||
window_height := 768;
|
||||
window_width: s32 = 1024;
|
||||
window_height: s32 = 768;
|
||||
|
||||
main :: () {
|
||||
min_memory_size := Clay.MinMemorySize();
|
||||
memory := alloc(min_memory_size);
|
||||
arena := Clay.CreateArenaWithCapacityAndMemory(min_memory_size, memory);
|
||||
Clay.SetMeasureTextFunction(measure_text);
|
||||
Clay.Initialize(arena, .{cast(float)Raylib.GetScreenWidth(), cast(float)Raylib.GetScreenHeight()});
|
||||
|
||||
Raylib.SetConfigFlags(.VSYNC_HINT | .WINDOW_RESIZABLE | .WINDOW_HIGHDPI | .MSAA_4X_HINT);
|
||||
Raylib.InitWindow(window_width, window_height, "raylib Jai Example");
|
||||
// Raylib.SetTargetFPS(60);
|
||||
|
||||
while !Raylib.WindowShouldClose() {
|
||||
Raylib.BeginDrawing();
|
||||
Raylib.ClearBackground(Raylib.RAYWHITE);
|
||||
Raylib.DrawText("HELLO", 190, 200, 20, Raylib.LIGHTGRAY);
|
||||
Raylib.EndDrawing();
|
||||
}
|
||||
|
||||
Raylib.CloseWindow();
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
.build
|
||||
raylib/
|
@ -1,41 +0,0 @@
|
||||
|
||||
Module by [Grouflon](https://github.com/Grouflon/raylib-jai).
|
||||
|
||||
# Raylib Module for Jai
|
||||
Module and generator script for [Raylib](https://www.raylib.com).
|
||||
Current version is **Raylib 5.1**.
|
||||
|
||||
## How to use
|
||||
- Checkout this repository and put it in the `modules` folder of your project.
|
||||
- Include the module with the `#import "raylib";` directive.
|
||||
|
||||
## Example
|
||||
```
|
||||
#import "raylib";
|
||||
|
||||
main :: ()
|
||||
{
|
||||
InitWindow(800, 600, "raylib example");
|
||||
SetTargetFPS(60);
|
||||
|
||||
while !WindowShouldClose()
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
```
|
||||
|
||||
## Supported Platforms
|
||||
- Windows
|
||||
- Wasm (Not working yet because of some 32bits/64bits mismatch)
|
||||
|
||||
## Contributing
|
||||
Feel free to submit pull requests if you want to add new platforms or any improvement.
|
||||
|
@ -3,27 +3,32 @@ AT_COMPILE_TIME :: true;
|
||||
RAYLIB_PATH :: "raylib";
|
||||
|
||||
DECLARATIONS_TO_OMIT :: string.[
|
||||
// These have custom declarations in module.jai
|
||||
"Vector2",
|
||||
"Vector3",
|
||||
"Vector4",
|
||||
"Quaternion",
|
||||
"Matrix",
|
||||
"PI",
|
||||
"TraceLogLevel",
|
||||
"PixelFormat",
|
||||
"TextureFilter",
|
||||
"BlendMode",
|
||||
"ShaderLocationIndex",
|
||||
"ShaderUniformDataType",
|
||||
"ShaderAttributeDataType",
|
||||
];
|
||||
|
||||
DUPLICATE_DECLARATIONS :: string.[
|
||||
"rlTraceLogLevel",
|
||||
"rlPixelFormat",
|
||||
"rlTextureFilter",
|
||||
"rlBlendMode",
|
||||
"rlShaderLocationIndex",
|
||||
"rlShaderAttributeDataType",
|
||||
"rlShaderUniformDataType",
|
||||
];
|
||||
|
||||
#if AT_COMPILE_TIME {
|
||||
#run,stallable {
|
||||
set_build_options_dc(.{do_output=false});
|
||||
root_options := get_build_options();
|
||||
Compiler.set_build_options_dc(.{do_output=false});
|
||||
root_options := Compiler.get_build_options();
|
||||
args := root_options.compile_time_command_line;
|
||||
if !generate_bindings(args) {
|
||||
compiler_set_workspace_status(.FAILED);
|
||||
Compiler.compiler_set_workspace_status(.FAILED);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -40,61 +45,126 @@ DECLARATIONS_TO_OMIT :: string.[
|
||||
|
||||
generate_bindings :: (args: [] string) -> bool
|
||||
{
|
||||
compile := array_find(args, "-compile");
|
||||
compile_debug := array_find(args, "-debug");
|
||||
|
||||
if compile {
|
||||
raylib_source_files: [..] string;
|
||||
array_add(*raylib_source_files, tprint("%/src/rcore.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/utils.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/rshapes.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/rtextures.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/rtext.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/rmodels.c", RAYLIB_PATH));
|
||||
array_add(*raylib_source_files, tprint("%/src/raudio.c", RAYLIB_PATH));
|
||||
|
||||
success := true;
|
||||
|
||||
#if OS == .WINDOWS {
|
||||
File.make_directory_if_it_does_not_exist("windows");
|
||||
|
||||
success &&= BuildCpp.build_cpp_static_lib(
|
||||
"windows/raylib",
|
||||
..raylib_source_files,
|
||||
extra = .[
|
||||
"/w",
|
||||
"/DSUPPORT_MODULE_RSHAPES",
|
||||
"/DSUPPORT_MODULE_RTEXTURES",
|
||||
"/DSUPPORT_MODULE_RTEXT",
|
||||
"/DSUPPORT_MODULE_RMODELS",
|
||||
"/DSUPPORT_MODULE_RAUDIO",
|
||||
"/D_CRT_SECURE_NO_WARNINGS",
|
||||
"/DPLATFORM_DESKTOP_RGFW",
|
||||
"/DGRAPHICS_API_OPENGL_43",
|
||||
]
|
||||
);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
output_filename: string;
|
||||
opts: Generate_Bindings_Options;
|
||||
opts: Generator.Generate_Bindings_Options;
|
||||
{
|
||||
using opts;
|
||||
|
||||
target_wasm: = false;
|
||||
if array_find(args, "-wasm") target_wasm = true;
|
||||
|
||||
if target_wasm
|
||||
{
|
||||
array_add(*libpaths, "wasm");
|
||||
output_filename = "wasm.jai";
|
||||
opts.static_library_suffix = ".a";
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OS == .WINDOWS {
|
||||
array_add(*libpaths, "windows");
|
||||
output_filename = "windows.jai";
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
array_add(*libnames, "raylib");
|
||||
array_add(*include_paths, RAYLIB_PATH);
|
||||
array_add(*source_files, tprint("%/src/raylib.h", RAYLIB_PATH));
|
||||
array_add(*source_files, tprint("%/src/raymath.h", RAYLIB_PATH));
|
||||
// Can't be compiled on windows because of missing math.h ? Leaving it out for now since Jai has the functions we need
|
||||
// array_add(*source_files, tprint("%/src/raymath.h", RAYLIB_PATH));
|
||||
array_add(*source_files, tprint("%/src/rlgl.h", RAYLIB_PATH));
|
||||
array_add(
|
||||
*extra_clang_arguments,
|
||||
"-c",
|
||||
"-DSUPPORT_MODULE_RSHAPES",
|
||||
"-DSUPPORT_MODULE_RTEXTURES",
|
||||
"-DSUPPORT_MODULE_RTEXT",
|
||||
"-DSUPPORT_MODULE_RMODELS",
|
||||
"-DSUPPORT_MODULE_RAUDIO",
|
||||
"-DPLATFORM_DESKTOP_RGFW",
|
||||
"-DGRAPHICS_API_OPENGL_43",
|
||||
);
|
||||
array_add(*strip_prefixes, "rl");
|
||||
auto_detect_enum_prefixes = false;
|
||||
log_stripped_declarations = false;
|
||||
generate_compile_time_struct_checks = false;
|
||||
|
||||
// auto_detect_enum_prefixes = true;
|
||||
// log_stripped_declarations = false;
|
||||
// generate_compile_time_struct_checks = true;
|
||||
|
||||
visitor = raylib_visitor;
|
||||
}
|
||||
|
||||
return generate_bindings(opts, output_filename);
|
||||
return Generator.generate_bindings(opts, output_filename);
|
||||
}
|
||||
|
||||
raylib_visitor :: (decl: *Declaration, parent_decl: *Declaration) -> Declaration_Visit_Result
|
||||
raylib_visitor :: (decl: *Generator.Declaration, parent_decl: *Generator.Declaration) -> Generator.Declaration_Visit_Result
|
||||
{
|
||||
if !parent_decl
|
||||
{
|
||||
if array_find(DECLARATIONS_TO_OMIT, decl.name)
|
||||
if !parent_decl && array_find(DECLARATIONS_TO_OMIT, decl.name)
|
||||
{
|
||||
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
||||
return .STOP;
|
||||
}
|
||||
|
||||
if decl.kind == .ENUM {
|
||||
en := cast(*Generator.Enum)decl;
|
||||
if String.contains(decl.name, "Flags") || decl.name == "Gesture" {
|
||||
en.flags |= .IS_ENUM_FLAGS;
|
||||
en.flags |= .VALUES_IN_HEX;
|
||||
}
|
||||
|
||||
if array_find(DUPLICATE_DECLARATIONS, decl.name) {
|
||||
decl.decl_flags |= .OMIT_FROM_OUTPUT;
|
||||
return .STOP;
|
||||
}
|
||||
|
||||
if en.type {
|
||||
if en.type.size == {
|
||||
case 1;
|
||||
en.type = context.generator.type_def_u8;
|
||||
case 2;
|
||||
en.type = context.generator.type_def_u16;
|
||||
case 4;
|
||||
en.type = context.generator.type_def_u32;
|
||||
case 8;
|
||||
en.type = context.generator.type_def_u64;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return .RECURSE;
|
||||
}
|
||||
|
||||
#import "Basic";
|
||||
#import "Bindings_Generator";
|
||||
#import "Compiler";
|
||||
#import "String";
|
||||
using Basic :: #import "Basic";
|
||||
Generator :: #import "Bindings_Generator";
|
||||
Compiler :: #import "Compiler";
|
||||
String :: #import "String";
|
||||
BuildCpp :: #import "BuildCpp";
|
||||
File :: #import "File";
|
||||
WindowsResources :: #import "Windows_Resources";
|
@ -1,4 +1,11 @@
|
||||
|
||||
Vector2 :: Math.Vector2;
|
||||
Vector3 :: Math.Vector3;
|
||||
Vector4 :: Math.Vector4;
|
||||
Quaternion :: Math.Quaternion;
|
||||
Matrix :: Math.Matrix4;
|
||||
PI :: Math.PI;
|
||||
|
||||
LIGHTGRAY :: Color.{ 200, 200, 200, 255 };
|
||||
GRAY :: Color.{ 130, 130, 130, 255 };
|
||||
DARKGRAY :: Color.{ 80, 80, 80, 255 };
|
||||
@ -38,14 +45,27 @@ IsKeyReleased :: (key: KeyboardKey) -> bool { return IsKeyReleased(cast(s32) key
|
||||
IsKeyUp :: (key: KeyboardKey) -> bool { return IsKeyUp(cast(s32) key); }
|
||||
SetExitKey :: (key: KeyboardKey) -> void { return SetExitKey(cast(s32) key); }
|
||||
|
||||
SetConfigFlags :: (flags: ConfigFlags) -> void { return SetConfigFlags(cast(u32) flags); }
|
||||
SetGesturesEnabled :: (flags: Gesture) -> void { return SetGesturesEnabled(cast(u32) flags); }
|
||||
IsGestureDetected :: (gesture: Gesture) -> bool { return IsGestureDetected(cast(u32) gesture); }
|
||||
IsWindowState :: (flag: ConfigFlags) -> bool { return IsWindowState(cast(u32) flag); }
|
||||
SetWindowState :: (flags: ConfigFlags) -> void { return SetWindowState(cast(u32) flags); }
|
||||
ClearWindowState :: (flags: ConfigFlags) -> void { return ClearWindowState(cast(u32) flags); }
|
||||
|
||||
#scope_module
|
||||
|
||||
#if OS == .WINDOWS {
|
||||
#load "windows.jai";
|
||||
}
|
||||
#if OS == .WASM {
|
||||
#load "wasm.jai";
|
||||
winmm :: #system_library,link_always "winmm";
|
||||
user32 :: #system_library,link_always "user32";
|
||||
opengl32 :: #system_library,link_always "opengl32";
|
||||
gdi32 :: #system_library,link_always "gdi32";
|
||||
shell32 :: #system_library,link_always "shell32";
|
||||
shcore :: #system_library,link_always "shcore";
|
||||
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
#import "Basic";
|
||||
#import "Math";
|
||||
Math :: #import "Math";
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -42,7 +42,7 @@ generate_bindings :: (args: [] string, minimum_os_version: type_of(Compiler.Buil
|
||||
File.make_directory_if_it_does_not_exist("clay-jai/windows", true);
|
||||
|
||||
command := ifx compile_debug {
|
||||
Process.break_command_into_strings("clang -c source\\clay.c");
|
||||
Process.break_command_into_strings("clang g -gcodeview -c source\\clay.c");
|
||||
} else {
|
||||
Process.break_command_into_strings("clang -O3 -c source\\clay.c");
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// This file was auto-generated using the following command:
|
||||
//
|
||||
// jai generate.jai - -compile
|
||||
// jai ./generate.jai - -compile
|
||||
//
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user