Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 12 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
name: Build On Changes
name: Build

on: [push, pull_request]

env:
BASE_URL: https://gitlab.sac-home.org/sac-group/sac-packages/-/raw/master/latest/weekly
on: [pull_request]

jobs:
build-ubuntu24:
runs-on: ubuntu-24.04
build-ubuntu:
runs-on: ubuntu-latest
container:
image: sacbase/sac-compiler
steps:
- name: Get HEAD and submodules
uses: actions/checkout@v2
- uses: actions/checkout@v5
with:
fetch-depth: 0
submodules: 'recursive'
- name: Install SDL
run: |
sudo apt update
sudo apt upgrade -y
sudo apt install -y libsdl1.2-dev libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev
- name: Install SaC
run: |
wget -q ${BASE_URL}/Ubl22/sac2c-basic.deb
sudo apt install ./sac2c-basic.deb
sac2c -V
- name: Install Stdlib
run: |
wget -q ${BASE_URL}/Ubl22/stdlib-basic.deb
sudo apt install ./stdlib-basic.deb
- name: Create build dir
run: |
cmake -E make_directory ${{runner.workspace}}/build
mkdir $HOME/.sac2crc
- name: Configure build-system
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE
- name: Configure sac2c
run: cp -r /root/.sac2crc $HOME/.sac2crc
- name: Install SDL3
run: apt install -y libsdl3-dev libsdl3-image-dev libsdl3-ttf-dev
- name: Build
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake --build . -j 4 2>&1 | tee build.log
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "!!! ERROR detected in build !!!";
exit 1;
fi
run: make
21 changes: 17 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,34 @@ SET (DLL_BUILD_DIR "${PROJECT_BINARY_DIR}/lib")
# For what targets we build modules
SET (TARGETS seq seq_checks mt_pth CACHE STRING "Build for these targets")
SET (SAC2C_EXEC CACHE STRING "Path to sac2c compiler")
OPTION (BUILDGENERIC "Do not use architecture-specific optimisations" OFF)

# Check whether sac2c is operational
LIST (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-common")
INCLUDE ("cmake-common/check-sac2c.cmake")
INCLUDE ("cmake-common/check-sac2c-feature-support.cmake")
INCLUDE ("cmake-common/misc-macros.cmake")

# NB: Despite the name SDL2.sac, the module still relies on the "old" libSDL1, not libSDL2.
SET (SDL_BUILDING_LIBRARY ON)
FIND_PACKAGE (SDL REQUIRED)
FIND_PACKAGE (SDL3 REQUIRED)
FIND_PACKAGE (X11 REQUIRED)

SET (SAC2C_EXTRA_INC "-I${SDL_INCLUDE_DIR}" "-I${X11_INCLUDE_DIR}"
CACHE STRING "Extra include files that should be used by sac2c")
SET (SAC2C_EXTRA_INC "-I${X11_INCLUDE_DIR}")
SET (SAC2C_CPP_INC "-Xl" "-lX11" "-Xtl" "-lX11")


# Check if sac2c suppports building generically
IF (BUILDGENERIC)
CHECK_SAC2C_SUPPORT_FLAG ("generic" "-generic")
IF (HAVE_FLAG_generic)
LIST (APPEND SAC2C_CPP_INC "-generic")
MESSAGE (STATUS "Building with *no* system-specific optimisations")
ELSE ()
MESSAGE (STATUS "Generic-build disabled as sac2c does not support this")
SET (BUILDGENERIC OFF)
ENDIF ()
ENDIF ()

# For every target run CMakeLists.txt in src
FOREACH (TARGET IN ITEMS ${TARGETS})
ADD_SUBDIRECTORY (src src-${TARGET})
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SAC2C ?= sac2c
TARGETS ?= "seq;seq_checks;mt_pth"
BUILD_DIR ?= build

.PHONY: all build clean

all: build

build:
cmake -DSAC2C_EXEC=$(SAC2C) -DTARGETS=$(TARGETS) -B $(BUILD_DIR)
cmake --build $(BUILD_DIR)

clean:
$(RM) -r $(BUILD_DIR)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
SAC SDL Module
==============

Note
----

Due to a bug in the private head manager, requires the `-noPHM` flag.

About
-----

Expand Down
122 changes: 122 additions & 0 deletions examples/mandelbrot.sac
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use SDLdisplay: all;
use Structures: all;
use Numerical: { log2 };
use StdIO: all;

#define XRES 16
#define YRES 9
#define EXPAND 64
#define DEPTH 1024

inline
complex[h,w] genComplexArray(int h, int w, complex cmin, complex cmax)
{
dR = real(cmax) - real(cmin);
dI = imag(cmax) - imag(cmin);
return { [y,x] -> cmin + toc(tod(x) * dR / tod(w),
tod(y) * dI / tod(h))
| [y,x] < [h,w] };
}

inline
int, complex escapeTimeAndValue(complex c, int depth)
{
i = 0;
z = c;

while (i < depth && normSq(z) <= 4d) {
z = z * z + c;
i += 1;
}

return (i, z);
}

inline
int[2:shp], complex[2:shp] escapeTimeAndValue(complex[2:shp] arr, int depth)
{
ts, vs = { iv -> escapeTimeAndValue(arr[iv], depth) | iv < shp };
return (ts, vs);
}

inline
double[2:shp] normalizeIterationCount(int[2:shp] ts, complex[2:shp] vs)
{
return where(norm(vs) <= 2d,
0d,
tod(ts + 1) - log2(log2(norm(vs))));
}

inline
Color8[2:shp] doubleToRgb(double[2:shp] arr)
{
min = minval(arr);
max = maxval(arr);
scaled = (arr - min) / (max - min);

//return Hsb2Rgb(toi(scaled * 360d), 60, 80);

scaled = toi(scaled * 255d);
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
return { iv -> clut[scaled[iv]] | iv < shp };
}

inline
Color8[2:shp] intToMonochrome(int[2:shp] a)
{
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());

a = (a * 255) / maxval(a);

return { iv -> clut[ a[ iv] ] };
}

inline
Color8[2:oshp] stretchRgb(Color8[2:shp] arr, int stretch)
{
return { iv -> arr[iv / stretch] | iv < shp * stretch };
}

int main() {
ctx = initDisplay(YRES*EXPAND+100, XRES*EXPAND+100);
cmin = [toc(-2.2, -1.0)];
cmax = [toc( 0.8, 1.0)];

while (isRunning(ctx)) {
xres = XRES;
yres = YRES;
expand = EXPAND;

do {
arr = genComplexArray(yres, xres, cmin[0], cmax[0]);

ts, vs = escapeTimeAndValue(arr, DEPTH);

nvs = normalizeIterationCount(ts, vs);
rgb = intToMonochrome(ts);
//rgb = doubleToRgb(nvs);
rgb = stretchRgb(rgb, expand);
ctx = drawPixelsOffset(ctx, toi(rgb), 150, 150);

xres *= 2;
yres *= 2;
expand /= 2;
} while (expand > 0);

printf("Waiting for selection...\n");
zoomCoords, ctx = getSelection(ctx);
if (all(zoomCoords >= 0)) {
printf("Received selection [[%d,%d],[%d,%d]]\n", zoomCoords[0,0], zoomCoords[0,1], zoomCoords[1,0], zoomCoords[1,1]);
cmin = [arr[zoomCoords[0]]] ++ cmin;
cmax = [arr[zoomCoords[1]]] ++ cmax;
} else if (shape(cmin)[0] > 1) {
// Undo the last selection, if any
printf("Undo last selection\n");
cmin = drop([1], cmin);
cmax = drop([1], cmax);
}
}

status = closeDisplay(ctx);
return status;
}
27 changes: 27 additions & 0 deletions examples/minimal.sac
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use SDLdisplay: all;

external uint sleep(uint x);
#pragma effect World::TheWorld
#pragma linksign [0,1]
#pragma linkname "sleep"
#pragma header "<unistd.h>"

int[w,h,3] makePixels(int w, int h)
{
return { [i,j] -> [_mod_SxS_(i, 256), _mod_SxS_(j, 256), 0]
| [i,j] < [w,h] };
}

int main() {
XRES = 640;
YRES = 480;

ctx = initDisplay(YRES, XRES);
pixels = makePixels(YRES, XRES);
ctx = drawPixels(ctx, pixels);

_ = sleep(5ui);

status = closeDisplay(ctx);
return status;
}
39 changes: 4 additions & 35 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,12 @@ ADD_CUSTOM_TARGET (${TARGET}-all-modules ALL)

# C files
SET (C_DEPS_SRC
src/SDL/destroyDisplay.c
src/SDL/drawArray.c
src/SDL/drawArrayOffset.c
src/SDL/drawPixel.c
src/SDL/getExtent.c
src/SDL/getSelection.c
src/SDL/initDisplay.c
src/SDL2/close.c
src/SDL2/color.c
src/SDL2/data.c
src/SDL2/display.c
src/SDL2/draw.c
src/SDL2/event.c
src/SDL2/extent.c
src/SDL2/font.c
src/SDL2/init.c
src/SDL2/invert.c
src/SDL2/line.c
src/SDL2/mouse.c
src/SDL2/names.c
src/SDL2/pixel.c
src/SDL2/sem.c
src/SDL2/rect.c
src/SDL2/resize.c
src/SDL2/select.c
src/SDL2/setup.c
src/SDL2/title.c
src/SDL2/update.c
src/SDL2/window.c
src/sdl3.c
)

# SaC files
SET (SAC_SRC
SDLdisplay.sac
SDL2.sac
)

# For every C source, compile an object file maintaining the right
Expand Down Expand Up @@ -77,9 +48,8 @@ FOREACH (name ${SAC_SRC})
SET (tree "${DLL_BUILD_DIR}/tree/${TARGET_ENV}/${SBI}/lib${dst}Tree${VARIANT}${TREE_DLLEXT}")

RESOLVE_SAC_DEPS_AS_TARGETS ("${name}" "<TARGET>-module-<NAME>" target_list object_list source_list)
#LIST (APPEND deps_list ${target_list} ${object_list} ${source_list})
LIST (APPEND deps_list ${object_list})
MESSAGE (DEBUG "Dependencies of ${name} are: ${deps_list}")
LIST (APPEND deps_list ${target_list} ${object_list} ${source_list})
MESSAGE (STATUS "Dependencies of ${name} are: ${deps_list}")
UNSET (target_list)
UNSET (object_list)
UNSET (source_list)
Expand All @@ -88,11 +58,10 @@ FOREACH (name ${SAC_SRC})
FILE (MAKE_DIRECTORY "${dir}")

ADD_CUSTOM_TARGET (${TARGET}-module-${dst} DEPENDS "${mod}" "${tree}")
ADD_DEPENDENCIES (${TARGET}-all-modules ${TARGET}-module-${dst})

ADD_CUSTOM_COMMAND (
OUTPUT ${mod} ${tree}
COMMAND ${SAC2C} -v0 -o ${DLL_BUILD_DIR} "${src}"
COMMAND ${SAC2C} -v0 -Xc "\"$(pkg-config --cflags --libs sdl3)\"" -o ${DLL_BUILD_DIR} "${src}"
WORKING_DIRECTORY "${dir}"
MAIN_DEPENDENCY "${src}"
DEPENDS ${deps_list}
Expand Down
Loading