Skip to content

Commit

Permalink
all: support SDL2 v2.0.10
Browse files Browse the repository at this point in the history
larpon committed Dec 28, 2021
1 parent da7dfa4 commit 0e45301
Showing 24 changed files with 673 additions and 98 deletions.
27 changes: 6 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,27 +10,16 @@ on:

jobs:
v-compiles-sdl-examples:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
timeout-minutes: 30
env:
VFLAGS: -cc tcc -no-retry-compilation
SDL2_VERSION: 2.0.9
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --quiet -y libsdl2-ttf-dev
sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev
sudo apt-get install --quiet -y libsdl2-mixer-dev libsdl2-image-dev
curl -L https://www.libsdl.org/release/SDL2-${SDL2_VERSION}.tar.gz -o SDL2.tar.gz
tar -zxvf SDL2.tar.gz
- name: Build SDL
run: |
cd SDL2-${SDL2_VERSION}
mkdir build
cd build
../configure --prefix /tmp/sdl2-${SDL2_VERSION}
make
make install
- name: Checkout V
uses: actions/checkout@v2
@@ -43,7 +32,6 @@ jobs:
uses: actions/checkout@v2
with:
path: sdl
ref: ${{ env.SDL2_VERSION }}

- name: Link local SDL folder in ~/.vmodules/sdl
run: |
@@ -57,18 +45,15 @@ jobs:
v test-fmt
- name: Build sdl shared
run: |
export SDL_V_CFLAGS="$(/tmp/sdl2-${SDL2_VERSION}/bin/sdl2-config --cflags --libs)"
v -cflags "$SDL_V_CFLAGS" -shared -g sdl
run: v -shared -g sdl

- name: Run tests
run: v test sdl

- name: Build sdl examples
run: |
export SDL_V_CFLAGS="$(/tmp/sdl2-${SDL2_VERSION}/bin/sdl2-config --cflags --libs)"
v -cflags "$SDL_V_CFLAGS" run sdl/examples/versions
v run sdl/examples/versions
for example in sdl/examples/*; do
echo "v -cflags \"$SDL_V_CFLAGS\" $example"
v -cflags "$SDL_V_CFLAGS" "$example";
echo "v $example"
v "$example";
done
16 changes: 8 additions & 8 deletions .github/workflows/windows-install-sdl.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@echo off

curl -L https://www.libsdl.org/release/SDL2-devel-2.0.9-VC.zip -o SDL2.zip
curl -L https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.14-VC.zip -o SDL2_ttf.zip
curl -L https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.3-VC.zip -o SDL2_image.zip
curl -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.2-VC.zip -o SDL2_mixer.zip
curl -L https://www.libsdl.org/release/SDL2-devel-2.0.10-VC.zip -o SDL2.zip
curl -L https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.15-VC.zip -o SDL2_ttf.zip
curl -L https://www.libsdl.org/projects/SDL_image/release/SDL2_image-devel-2.0.5-VC.zip -o SDL2_image.zip
curl -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-devel-2.0.4-VC.zip -o SDL2_mixer.zip

unzip SDL2.zip -d thirdparty/
unzip SDL2_ttf.zip -d thirdparty/
unzip SDL2_image.zip -d thirdparty/
unzip SDL2_mixer.zip -d thirdparty/

move /y thirdparty/SDL2-2.0.9 thirdparty/SDL2
move /y thirdparty/SDL2_ttf-2.0.14 thirdparty/SDL2_ttf
move /y thirdparty/SDL2_image-2.0.3 thirdparty/SDL2_image
move /y thirdparty/SDL2_mixer-2.0.2 thirdparty/SDL2_mixer
move /y thirdparty/SDL2-2.0.10 thirdparty/SDL2
move /y thirdparty/SDL2_ttf-2.0.15 thirdparty/SDL2_ttf
move /y thirdparty/SDL2_image-2.0.5 thirdparty/SDL2_image
move /y thirdparty/SDL2_mixer-2.0.4 thirdparty/SDL2_mixer
59 changes: 46 additions & 13 deletions audio.c.v
Original file line number Diff line number Diff line change
@@ -419,24 +419,57 @@ pub fn pause_audio_device(dev AudioDeviceID, pause_on int) {

fn C.SDL_LoadWAV_RW(src &C.SDL_RWops, freesrc int, spec &C.SDL_AudioSpec, audio_buf &&byte, audio_len &u32) &C.SDL_AudioSpec

// load_wav_rw loads a WAVE from the data source, automatically freeing
// that source if `freesrc` is non-zero. For example, to load a WAVE file,
// you could do:
// load_wav_rw loads the audio data of a WAVE file into memory
//
// Loading a WAVE file requires `src`, `spec`, `audio_buf` and `audio_len`
// to be valid pointers. The entire data portion of the file is then loaded
// into memory and decoded if necessary.
//
// If `freesrc` is non-zero, the data source gets automatically closed and
// freed before the function returns.
//
// Supported are RIFF WAVE files with the formats PCM (8, 16, 24, and 32 bits),
// IEEE Float (32 bits), Microsoft ADPCM and IMA ADPCM (4 bits), and A-law and
// µ-law (8 bits). Other formats are currently unsupported and cause an error.
//
// If this function succeeds, the pointer returned by it is equal to `spec`
// and the pointer to the audio data allocated by the function is written to
// `audio_buf` and its length in bytes to `audio_len`. The `SDL_AudioSpec`
// members `freq`, `channels`, and `format` are set to the values of the
// audio data in the buffer. The `samples` member is set to a sane default and
// all others are set to zero.
//
// It's necessary to use SDL_FreeWAV() to free the audio data returned in
// `audio_buf` when it is no longer used.
//
// Because of the underspecification of the Waveform format, there are many
// problematic files in the wild that cause issues with strict decoders. To
// provide compatibility with these files, this decoder is lenient in regards
// to the truncation of the file, the fact chunk, and the size of the RIFF
// chunk. The hints SDL_HINT_WAVE_RIFF_CHUNK_SIZE, SDL_HINT_WAVE_TRUNCATION,
// and SDL_HINT_WAVE_FACT_CHUNK can be used to tune the behavior of the
// loading process.
//
// Any file that is invalid (due to truncation, corruption, or wrong values in
// the headers), too big, or unsupported causes an error. Additionally, any
// critical I/O error from the data source will terminate the loading process
// with an error. The function returns NULL on error and in all cases (with the
// exception of `src` being NULL), an appropriate error message will be set.
//
// It is required that the data source supports seeking.
//
// Example:
/*
```
SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
```
*/
// If this function succeeds, it returns the given SDL_AudioSpec,
// filled with the audio data format of the wave data, and sets
// `audio_buf` to a malloc()'d buffer containing the audio data,
// and sets `audio_len` to the length of that audio buffer, in bytes.
// You need to free the audio buffer with SDL_FreeWAV() when you are
// done with it.
//
// This function returns NULL and sets the SDL error message if the
// wave file cannot be opened, uses an unknown data format, or is
// corrupt. Currently raw and MS-ADPCM WAVE files are supported.
// `src` The data source with the WAVE data
// `freesrc` A integer value that makes the function close the data source if non-zero
// `spec` A pointer filled with the audio format of the audio data
// `audio_buf` A pointer filled with the audio data allocated by the function
// `audio_len` A pointer filled with the length of the audio data buffer in bytes
// returns NULL on error, or non-NULL on success.
pub fn load_wav_rw(src &RWops, freesrc int, spec &AudioSpec, audio_buf &&byte, audio_len &u32) &AudioSpec {
return C.SDL_LoadWAV_RW(src, freesrc, spec, audio_buf, audio_len)
}
12 changes: 6 additions & 6 deletions blendmode.c.v
Original file line number Diff line number Diff line change
@@ -47,12 +47,12 @@ fn C.SDL_ComposeCustomBlendMode(src_color_factor C.SDL_BlendFactor, dst_color_fa
// compose_custom_blend_mode creates a custom blend mode, which may
// or may not be supported by a given renderer
//
// `srcColorFactor`
// `dstColorFactor`
// `colorOperation`
// `srcAlphaFactor`
// `dstAlphaFactor`
// `alphaOperation`
// `srcColorFactor` source color factor
// `dstColorFactor` destination color factor
// `colorOperation` color operation
// `srcAlphaFactor` source alpha factor
// `dstAlphaFactor` destination alpha factor
// `alphaOperation` alpha operation
//
// The result of the blend mode operation will be:
// dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor
68 changes: 68 additions & 0 deletions cpuinfo.c.v
Original file line number Diff line number Diff line change
@@ -120,3 +120,71 @@ fn C.SDL_GetSystemRAM() int
pub fn get_system_ram() int {
return C.SDL_GetSystemRAM()
}

fn C.SDL_SIMDGetAlignment() usize

// simd_get_alignment reports the alignment this system needs for SIMD allocations.
//
// This will return the minimum number of bytes to which a pointer must be
// aligned to be compatible with SIMD instructions on the current machine.
// For example, if the machine supports SSE only, it will return 16, but if
// it supports AVX-512F, it'll return 64 (etc). This only reports values for
// instruction sets SDL knows about, so if your SDL build doesn't have
// SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
// not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
// Plan accordingly.
pub fn simd_get_alignment() usize {
return C.SDL_SIMDGetAlignment()
}

fn C.SDL_SIMDAlloc(len usize) voidptr

// simd_alloc allocates memory in a SIMD-friendly way.
//
// This will allocate a block of memory that is suitable for use with SIMD
// instructions. Specifically, it will be properly aligned and padded for
// the system's supported vector instructions.
//
// The memory returned will be padded such that it is safe to read or write
// an incomplete vector at the end of the memory block. This can be useful
// so you don't have to drop back to a scalar fallback at the end of your
// SIMD processing loop to deal with the final elements without overflowing
// the allocated buffer.
//
// You must free this memory with SDL_FreeSIMD(), not free() or SDL_free()
// or delete[], etc.
//
// Note that SDL will only deal with SIMD instruction sets it is aware of;
// for example, SDL 2.0.8 knows that SSE wants 16-byte vectors
// (SDL_HasSSE()), and AVX2 wants 32 bytes (SDL_HasAVX2()), but doesn't
// know that AVX-512 wants 64. To be clear: if you can't decide to use an
// instruction set with an SDL_Has*() function, don't use that instruction
// set with memory allocated through here.
//
// SDL_AllocSIMD(0) will return a non-NULL pointer, assuming the system isn't
// out of memory.
//
// `len` The length, in bytes, of the block to allocated. The actual
// allocated block might be larger due to padding, etc.
// returns Pointer to newly-allocated block, NULL if out of memory.
//
// See also: SDL_SIMDAlignment
// See also: SDL_SIMDFree
pub fn simd_alloc(len usize) voidptr {
return C.SDL_SIMDAlloc(len)
}

fn C.SDL_SIMDFree(ptr voidptr)

// simd_free deallocates memory obtained from SDL_SIMDAlloc
//
// It is not valid to use this function on a pointer from anything but
// SDL_SIMDAlloc(). It can't be used on pointers from malloc, realloc,
// SDL_malloc, memalign, new[], etc.
//
// However, SDL_SIMDFree(NULL) is a legal no-op.
//
// See also: SDL_SIMDAlloc
pub fn simd_free(ptr voidptr) {
C.SDL_SIMDFree(ptr)
}
20 changes: 20 additions & 0 deletions endian.c.v
Original file line number Diff line number Diff line change
@@ -12,3 +12,23 @@ pub const (
big_endian = C.SDL_BIG_ENDIAN
byteorder = C.SDL_BYTEORDER
)

fn C.SDL_Swap16(x u16) u16
pub fn swap16(x u16) u16 {
return C.SDL_Swap16(x)
}

fn C.SDL_Swap32(x u32) u32
pub fn swap32(x u32) u32 {
return C.SDL_Swap32(x)
}

fn C.SDL_Swap64(x u64) u64
pub fn swap64(x u64) u64 {
return C.SDL_Swap64(x)
}

fn C.SDL_SwapFloat(x f32) f32
pub fn swap_float(x f32) f32 {
return C.SDL_SwapFloat(x)
}
Loading
Oops, something went wrong.

0 comments on commit 0e45301

Please sign in to comment.