This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Casey Muratori's Handmade Ray tutorial, translated to Jai | |
// https://guide.handmadehero.org/ray/ray00/ | |
main :: () { | |
image := allocate_image(1920, 1080); | |
materials := Material.[ | |
.{emit_color = srgb_to_linear(.{0.3, 0.4, 0.5})}, | |
.{ref_color = srgb_to_linear(.{0.5, 0.5, 0.5})}, | |
.{ref_color = srgb_to_linear(.{0.7, 0.5, 0.3})}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
late_load_import :: ($module: Type) -> string #compile_time { | |
#insert -> string { | |
module_name := name_of_module(module); | |
return sprint("LIBRARIES :: Late_Load_Module_%.LIBRARIES;", module_name); | |
}; | |
using_statements: String_Builder; | |
for LIBRARIES { | |
print_to_builder(*using_statements, "using __late_load_library_%;\n", it); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ARM64 hack: Unlike x64, even though aligned reads are atomic, ARM64 doesn't guarantee acquire semantics with | |
// normal reads and release semantics with normal stores. There are separate instructions for those, | |
// and since we don't have ARM64 inline assembly yet, we must implement them with this very very spooky | |
// hack where we hardcode the machine instructions we want. The parameters are assumed to be passed | |
// according to Jai's current LLVM ABI! | |
// Thanks @ctpeepee! | |
atomic_read :: no_inline (pointer: *s64) -> s64 { | |
// ldr x1, [x1] x1 initially contains a pointer to "pointer", which itself is a pointer | |
// ldar x1, [x1] | |
// str x1, [x2] x2 here contains a pointer to the first return value. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simp :: #import "Simp"; | |
Input :: #import "Input"; | |
#import "Basic"; | |
#import "Random"; | |
#import "Math"; | |
#import "Window_Creation"; | |
#import "GL"; | |
Render_Texture :: struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tries to implement bitfields in the most ergonomic way I can think of. | |
// Inspired in part by what D's standard library did before the language supported bitfields. | |
#insert #run bitfields_struct( | |
"Thing", | |
bf("a", u32, 4), | |
bf("b", u32, 4), | |
bf("c", s32, 4), | |
bf("d", u32, 4), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG | |
trap 'echo FAILED COMMAND: $previous_command' EXIT | |
#------------------------------------------------------------------------------------------- | |
# This script will download packages for, configure, build and install a GCC cross-compiler. | |
# Customize the variables (INSTALL_PATH, TARGET, etc.) to your liking before running. | |
# If you get an error and need to resume the script from some point in the middle, | |
# just delete/comment the preceding lines before running it again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple citro2d sprite drawing example | |
// Images borrowed from: | |
// https://kenney.nl/assets/space-shooter-redux | |
#include <citro2d.h> | |
#include <assert.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void func(size_t size)() { | |
static foreach (p; 0..size) { | |
perform_some_action(p); | |
} | |
} | |
void perform_some_action(size_t p) { | |
import std.stdio : writeln; | |
writeln(p); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.string : format; | |
struct Soa(T, long n) { | |
static foreach (member; T.tupleof) { | |
mixin(format("typeof(member)[n] %s;", member.stringof)); | |
} | |
T opIndex(size_t index) const { | |
T result = void; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple citro2d sprite drawing example | |
// Images borrowed from: | |
// https://kenney.nl/assets/space-shooter-redux | |
#include <citro2d.h> | |
#include <assert.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> |
NewerOlder