Skip to content

Instantly share code, notes, and snippets.

View define-private-public's full-sized avatar
🔮
(´・ω・`)

Benjamin Summerton define-private-public

🔮
(´・ω・`)
View GitHub Profile
@define-private-public
define-private-public / analytical_in_unit_disk_gcc_14.2_O0.asm
Last active January 19, 2025 06:12
PSRT Rejection vs. Analytical sampling
RNG::analytical_in_unit_disk(): ; 49 instructions
push rbp
mov rbp, rsp
sub rsp, 64
mov QWORD PTR [rbp-56], rdi
movsd xmm0, QWORD PTR .LC1[rip]
mov rax, QWORD PTR [rbp-56]
movapd xmm1, xmm0
mov rdx, QWORD PTR .LC2[rip]
movq xmm0, rdx
@define-private-public
define-private-public / CMakeLists.txt
Last active August 1, 2024 22:55
C++ `noexcept` keyword experiment with PSRayTracing
option(WITH_NOEXCEPT "Use the `noexcept` annotation for various functions (faster?)" OFF)
# ...
if (WITH_NOEXCEPT)
message(STATUS "Using `noexcept` annotations (faster?)")
target_compile_definitions(PSRayTracing_StaticLibrary PUBLIC USE_NOEXCEPT)
else()
message(STATUS "Turned off use of `noexcept` (slower?)")
endif()
@define-private-public
define-private-public / CMakeLists.txt
Last active April 16, 2024 23:30
C++ `final` keyword experiment (TODO blog link)
option(WITH_FINAL "Use the `final` specifier on derived classes (faster?)" OFF)
# ...
if (WITH_FINAL)
message(STATUS "Using `final` spicifer (faster?)")
target_compile_definitions(PSRayTracing_StaticLibrary PUBLIC USE_FINAL)
else()
message(STATUS "Turned off use of `final` (slower?)")
endif()
# `Linguist` is required
find_package(Qt6 COMPONENTS Linguist REQUIRED)
# ...
# Have your app specified
qt_add_executable(myapp ...
# ...
@define-private-public
define-private-public / 1.CMakeLists.txt
Last active August 21, 2022 17:45
PSRayTracing Qt GUI Blog Post
# Check if we're building for iOS (and put it into a more friendly variable)
set(IOS FALSE)
if (${CMAKE_SYSTEM_NAME} STREQUAL iOS)
set(IOS TRUE)
endif()
# If we're building for Android or iOS, turn on the UI
set(IS_MOBILE FALSE)
if (ANDROID OR IOS)
set(IS_MOBILE TRUE)
@define-private-public
define-private-public / main.cpp.diff
Last active July 7, 2021 19:24
Automated Testing of a Ray Tracer
@@ -157,8 +166,15 @@ int main(int argc, char *argv[]) {
}
// Print some info
- const rreal renderTime = rreal(chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count()) / 1000.0f;
- cout << "Render took " << renderTime << " seconds" << endl;
+ if (run_in_testing_mode) {
+ // For machines, we show nanoseconds (as integers)
+ const auto render_time_us = chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count();
+ cout << render_time_us << " ns" << endl;
#!/usr/bin/python3
import sys
import random
import math
import matplotlib.pyplot as plt
class Vec3:
__slots__ = (
@define-private-public
define-private-public / setup-osx-partial.py
Created March 15, 2020 18:52
Fix ids and rpaths for some OS X dylibs
# If on OS, we need to fix some issues with the dylibs
# namely the rpath stuff & dylib IDs, it's a bit of a pain
if is_osx:
cmds = []
# First fix Ids
dylibs = ['ogg', 'vorbis', 'vorbisenc', 'vorbisfile', 'sndfile']
for lib in dylibs:
lib_filename = 'lib%s.dylib' % (lib)
cmd = 'install_name_tool -id "@rpath/{0}" lib/{0}'.format(lib_filename)
@define-private-public
define-private-public / guess.nim
Last active September 14, 2017 16:41
Guess my number [from rosetta code]
import random, rdstdin, strutils
randomize()
let iRange = 1..100
echo "Guess my target number that is between ", iRange.a, " and ", iRange.b, " (inclusive)."
let target = random(iRange)
var answer, i = 0
while answer != target:
@define-private-public
define-private-public / auto_compile.nim
Last active March 13, 2017 02:27
For an article on hot loading w/ Nim
import osproc
# Where your Nim compiler is located
const nimEXE = "/home/ben/bin/Nim/bin/nim"
# Compile and wait for it to be done
let
compile = startProcess(nimEXE, "", ["c", "--app:lib", "game"])
compileStatus = waitForExit(compile)
close(compile)