diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml index 43424c8..c42b410 100644 --- a/.github/workflows/blank.yml +++ b/.github/workflows/blank.yml @@ -38,7 +38,7 @@ jobs: for file in examples/*.nim; do filename=$(basename "$file" .nim) echo "Compiling $filename" - nim c -f -d:danger -d:lto --mm:arc --passC:"-march=native" -o:"build/${filename}_${{ runner.os }}" "$file" + nim c -f -d:danger -d:lto -d:strip --mm:arc --passC:"-march=native" -o:"build/${filename}_${{ runner.os }}" "$file" done shell: bash diff --git a/.gitmodules b/.gitmodules index 9804d9c..2290267 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "src/fenster"] - path = src/fenster - url = https://github.com/zserge/fenster +[submodule "src/fensterb"] + path = src/fensterb + url = https://github.com/CardealRusso/fensterb/ diff --git a/examples/performance_test/README.md b/examples/performance_test/README.md deleted file mode 100644 index d517447..0000000 --- a/examples/performance_test/README.md +++ /dev/null @@ -1,14 +0,0 @@ -| Compiler Options | Min | Max | Avg | -|-------------------------------|-----|-----|-------| -| gcc | 33 | 34 | 33.5 | -| gcc danger | 34 | 45 | 40.5 | -| gcc danger lto | 40 | 58 | 51.5 | -| gcc danger lto pgo -O3 | 45 | 66 | 58.3 | -| | | | | -| clang | 30 | 31 | 30.5 | -| clang danger | 47 | 50 | 48.5 | -| clang danger lto | 26 | 47 | 41.5 | -| clang danger pgo | 47 | 50 | 48.7 | -| clang danger lto pgo | 35 | 50 | 43.7 | - -clang 19.1, gcc 13.2 \ No newline at end of file diff --git a/examples/performance_test/config.nims b/examples/performance_test/config.nims deleted file mode 100644 index 77bc40a..0000000 --- a/examples/performance_test/config.nims +++ /dev/null @@ -1 +0,0 @@ -switch("path", "$projectDir/../../src") diff --git a/examples/performance_test/plasma_with_fps.nim b/examples/performance_test/plasma_with_fps.nim deleted file mode 100644 index 6309368..0000000 --- a/examples/performance_test/plasma_with_fps.nim +++ /dev/null @@ -1,18 +0,0 @@ -import fenstim, math - -var - app = init(Fenster, "Plasma with FPS", 800, 600, 999) - t = 0.0 - lastFpsUpdate = app.time - -while app.loop and app.keys[27] == 0: - if app.time - lastFpsUpdate >= 1000: - echo "FPS: ", app.fps.int - lastFpsUpdate = app.time - - t += 0.1 - for i in 0..= 1.0.0" -srcDir = "src" \ No newline at end of file +srcDir = "src" diff --git a/src/fenster b/src/fenster deleted file mode 160000 index e700581..0000000 --- a/src/fenster +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e700581dfb7956dd161aee44fc0cff0663e789a1 diff --git a/src/fenster_modified/fenster_audio.h b/src/fenster_modified/fenster_audio.h deleted file mode 100644 index 3ba1fb3..0000000 --- a/src/fenster_modified/fenster_audio.h +++ /dev/null @@ -1,200 +0,0 @@ -#ifndef FENSTER_AUDIO_H -#define FENSTER_AUDIO_H - -#ifndef FENSTER_SAMPLE_RATE -#define FENSTER_SAMPLE_RATE 44100 -#endif - -#ifndef FENSTER_AUDIO_BUFSZ -#define FENSTER_AUDIO_BUFSZ 8192 -#endif - -// Platform-agnostic structure -struct fenster_audio { - void *audio_data; - float buf[FENSTER_AUDIO_BUFSZ]; - size_t pos; -}; - -#ifndef FENSTER_API -#define FENSTER_API extern -#endif - -FENSTER_API int fenster_audio_open(struct fenster_audio *f); -FENSTER_API int fenster_audio_available(struct fenster_audio *f); -FENSTER_API void fenster_audio_write(struct fenster_audio *f, float *buf, size_t n); -FENSTER_API void fenster_audio_close(struct fenster_audio *f); - -#ifndef FENSTER_HEADER - -#if defined(__APPLE__) -#include -#include - -typedef struct { - AudioQueueRef queue; - dispatch_semaphore_t drained; - dispatch_semaphore_t full; -} MacAudioData; - -static void fenster_audio_cb(void *p, AudioQueueRef q, AudioQueueBufferRef b) { - struct fenster_audio *fa = (struct fenster_audio *)p; - MacAudioData *mad = (MacAudioData *)fa->audio_data; - dispatch_semaphore_wait(mad->full, DISPATCH_TIME_FOREVER); - memmove(b->mAudioData, fa->buf, sizeof(fa->buf)); - dispatch_semaphore_signal(mad->drained); - AudioQueueEnqueueBuffer(q, b, 0, NULL); -} - -FENSTER_API int fenster_audio_open(struct fenster_audio *fa) { - MacAudioData *mad = (MacAudioData *)malloc(sizeof(MacAudioData)); - if (!mad) return -1; - fa->audio_data = mad; - - AudioStreamBasicDescription format = {0}; - format.mSampleRate = FENSTER_SAMPLE_RATE; - format.mFormatID = kAudioFormatLinearPCM; - format.mFormatFlags = kLinearPCMFormatFlagIsFloat | kAudioFormatFlagIsPacked; - format.mBitsPerChannel = 32; - format.mFramesPerPacket = format.mChannelsPerFrame = 1; - format.mBytesPerPacket = format.mBytesPerFrame = 4; - mad->drained = dispatch_semaphore_create(1); - mad->full = dispatch_semaphore_create(0); - AudioQueueNewOutput(&format, fenster_audio_cb, fa, NULL, NULL, 0, &mad->queue); - for (int i = 0; i < 2; i++) { - AudioQueueBufferRef buffer = NULL; - AudioQueueAllocateBuffer(mad->queue, FENSTER_AUDIO_BUFSZ * 4, &buffer); - buffer->mAudioDataByteSize = FENSTER_AUDIO_BUFSZ * 4; - memset(buffer->mAudioData, 0, buffer->mAudioDataByteSize); - AudioQueueEnqueueBuffer(mad->queue, buffer, 0, NULL); - } - AudioQueueStart(mad->queue, NULL); - return 0; -} - -FENSTER_API void fenster_audio_close(struct fenster_audio *fa) { - MacAudioData *mad = (MacAudioData *)fa->audio_data; - AudioQueueStop(mad->queue, false); - AudioQueueDispose(mad->queue, false); - free(mad); -} - -FENSTER_API int fenster_audio_available(struct fenster_audio *fa) { - MacAudioData *mad = (MacAudioData *)fa->audio_data; - if (dispatch_semaphore_wait(mad->drained, DISPATCH_TIME_NOW)) - return 0; - return FENSTER_AUDIO_BUFSZ - fa->pos; -} - -FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf, size_t n) { - MacAudioData *mad = (MacAudioData *)fa->audio_data; - while (fa->pos < FENSTER_AUDIO_BUFSZ && n > 0) { - fa->buf[fa->pos++] = *buf++, n--; - } - if (fa->pos >= FENSTER_AUDIO_BUFSZ) { - fa->pos = 0; - dispatch_semaphore_signal(mad->full); - } -} - -#elif defined(_WIN32) -#include -#include - -typedef struct { - HWAVEOUT wo; - WAVEHDR hdr[2]; - int16_t bufs[2][FENSTER_AUDIO_BUFSZ]; -} WindowsAudioData; - -FENSTER_API int fenster_audio_open(struct fenster_audio *fa) { - WindowsAudioData *wad = (WindowsAudioData *)malloc(sizeof(WindowsAudioData)); - if (!wad) return -1; - fa->audio_data = wad; - - WAVEFORMATEX wfx = {WAVE_FORMAT_PCM, 1, FENSTER_SAMPLE_RATE, FENSTER_SAMPLE_RATE * 2, 2, 16, 0}; - waveOutOpen(&wad->wo, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL); - for (int i = 0; i < 2; i++) { - wad->hdr[i].lpData = (LPSTR)wad->bufs[i]; - wad->hdr[i].dwBufferLength = FENSTER_AUDIO_BUFSZ * 2; - waveOutPrepareHeader(wad->wo, &wad->hdr[i], sizeof(WAVEHDR)); - waveOutWrite(wad->wo, &wad->hdr[i], sizeof(WAVEHDR)); - } - return 0; -} - -FENSTER_API int fenster_audio_available(struct fenster_audio *fa) { - WindowsAudioData *wad = (WindowsAudioData *)fa->audio_data; - for (int i = 0; i < 2; i++) - if (wad->hdr[i].dwFlags & WHDR_DONE) - return FENSTER_AUDIO_BUFSZ; - return 0; -} - -FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf, size_t n) { - WindowsAudioData *wad = (WindowsAudioData *)fa->audio_data; - for (int i = 0; i < 2; i++) { - if (wad->hdr[i].dwFlags & WHDR_DONE) { - for (unsigned j = 0; j < n; j++) { - wad->bufs[i][j] = (int16_t)(buf[j] * 32767); - } - waveOutWrite(wad->wo, &wad->hdr[i], sizeof(WAVEHDR)); - return; - } - } -} - -FENSTER_API void fenster_audio_close(struct fenster_audio *fa) { - WindowsAudioData *wad = (WindowsAudioData *)fa->audio_data; - waveOutClose(wad->wo); - free(wad); -} - -#elif defined(__linux__) -int snd_pcm_open(void **, const char *, int, int); -int snd_pcm_set_params(void *, int, int, int, int, int, int); -int snd_pcm_avail(void *); -int snd_pcm_writei(void *, const void *, unsigned long); -int snd_pcm_recover(void *, int, int); -int snd_pcm_close(void *); - -typedef struct { - void *pcm; -} LinuxAudioData; - -FENSTER_API int fenster_audio_open(struct fenster_audio *fa) { - LinuxAudioData *lad = (LinuxAudioData *)malloc(sizeof(LinuxAudioData)); - if (!lad) return -1; - fa->audio_data = lad; - - if (snd_pcm_open(&lad->pcm, "default", 0, 0)) - return -1; - int fmt = (*(unsigned char *)(&(uint16_t){1})) ? 14 : 15; - return snd_pcm_set_params(lad->pcm, fmt, 3, 1, FENSTER_SAMPLE_RATE, 1, 100000); -} - -FENSTER_API int fenster_audio_available(struct fenster_audio *fa) { - LinuxAudioData *lad = (LinuxAudioData *)fa->audio_data; - int n = snd_pcm_avail(lad->pcm); - if (n < 0) - snd_pcm_recover(lad->pcm, n, 0); - return n; -} - -FENSTER_API void fenster_audio_write(struct fenster_audio *fa, float *buf, size_t n) { - LinuxAudioData *lad = (LinuxAudioData *)fa->audio_data; - int r = snd_pcm_writei(lad->pcm, buf, n); - if (r < 0) - snd_pcm_recover(lad->pcm, r, 0); -} - -FENSTER_API void fenster_audio_close(struct fenster_audio *fa) { - LinuxAudioData *lad = (LinuxAudioData *)fa->audio_data; - snd_pcm_close(lad->pcm); - free(lad); -} - -#endif - -#endif /* FENSTER_HEADER */ -#endif /* FENSTER_AUDIO_H */ diff --git a/src/fensterb b/src/fensterb new file mode 160000 index 0000000..7eb7a85 --- /dev/null +++ b/src/fensterb @@ -0,0 +1 @@ +Subproject commit 7eb7a85b7df13ea4df46f7c547bee3429b6cc07e diff --git a/src/fenstim.nim b/src/fenstim.nim index 7d572a8..f138b3c 100644 --- a/src/fenstim.nim +++ b/src/fenstim.nim @@ -1,6 +1,6 @@ import os -const fensterHeader = currentSourcePath().parentDir() / "fenster/fenster.h" +const fensterHeader = currentSourcePath().parentDir() / "fensterb/src/fenster/fenster.h" when defined(linux): {.passl: "-lX11".} elif defined(windows): {.passl: "-lgdi32".} @@ -114,4 +114,4 @@ proc getFonts*(self: Fenster): seq[string] = result = newSeq[string]() for pattern in searchPatterns: for entry in walkPattern(pattern): - result.add(entry) \ No newline at end of file + result.add(entry) diff --git a/src/fenstim_audio.nim b/src/fenstim_audio.nim index a770be9..7310eb9 100644 --- a/src/fenstim_audio.nim +++ b/src/fenstim_audio.nim @@ -1,6 +1,6 @@ import os -const fensterAudioHeader = currentSourcePath().parentDir() / "fenster_modified/fenster_audio.h" +const fensterAudioHeader = currentSourcePath().parentDir() / "fensterb/src/fenster_audio/fenster_audio.h" when defined(linux): {.passL: "-lasound".} elif defined(windows): {.passL: "-lwinmm".}