From d4665c4e9bc2368d67b1d344282a717b2cc7f5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Thu, 5 Jun 2025 21:51:34 +0200 Subject: [PATCH] experiments --- CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++++++++---- player/player.c | 4 ++-- tiles/furnace.c | 4 +--- util/audio.c | 10 +++++----- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12fec65..6772f15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,19 @@ set(CMAKE_C_STANDARD 23) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) +# Allow setting the target platform manually +if (NOT DEFINED TARGET_PLATFORM) + if (WIN32) + set(TARGET_PLATFORM windows) + elseif (UNIX) + set(TARGET_PLATFORM linux) + else () + message(FATAL_ERROR "Unsupported platform. Please set TARGET_PLATFORM manually.") + endif () +endif () -add_executable(factorygame + +set(SOURCE_FILES tiles/tile.c tiles/tile.h util/font.c @@ -36,6 +47,43 @@ add_executable(factorygame tiles/miner.h ) +add_executable(factorygame ${SOURCE_FILES}) + + +message(STATUS "Target platform: ${TARGET_PLATFORM}") + +# Detect build type and configure SDL2 paths accordingly +if (TARGET_PLATFORM STREQUAL "windows") + find_package(SDL2 REQUIRED) + find_package(SDL2_ttf REQUIRED) + include_directories(${SDL2_INCLUDE_DIRS}) + link_directories(${SDL2_LIBRARY_DIRS}) + add_definitions(${SDL2_CFLAGS_OTHER}) + +elseif (TARGET_PLATFORM STREQUAL "mingw") + # Cross-compile dynamically linked Windows build + set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) + set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + find_package(SDL2 REQUIRED) + find_package(SDL2_ttf REQUIRED) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows") + target_link_libraries(factorygame mingw32 SDL2main SDL2 SDL2_ttf SDL2_image m) + include_directories(${SDL2_INCLUDE_DIRS}) + link_directories(${SDL2_LIBRARY_DIRS}) + add_definitions(${SDL2_CFLAGS_OTHER}) + +elseif (TARGET_PLATFORM STREQUAL "linux") + pkg_check_modules(SDL2 REQUIRED sdl2) + pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf) + pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image) + target_link_libraries(factorygame SDL2 SDL2_ttf SDL2_image m) + include_directories(${SDL2_INCLUDE_DIRS}) + add_definitions(${SDL2_CFLAGS_OTHER}) + +else () + message(FATAL_ERROR "Unsupported TARGET_PLATFORM: ${TARGET_PLATFORM}") +endif () + # Define the path to the assets folder set(ASSETS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/assets") set(ASSETS_BINARY_DIR "${CMAKE_BINARY_DIR}/assets") @@ -49,6 +97,3 @@ add_custom_target(copy_assets ALL # Make sure factorygame depends on the assets being copied add_dependencies(factorygame copy_assets) - - -target_link_libraries(factorygame SDL2 SDL2_ttf SDL2_image m) \ No newline at end of file diff --git a/player/player.c b/player/player.c index 30f4aef..6b74a74 100644 --- a/player/player.c +++ b/player/player.c @@ -113,11 +113,11 @@ void initPlayer(Player *plr) { plr->rect.h = TILE_SIZE; for (ItemType ui = 1; ui < tileTypeIndex; ui++) { - plr->inventory.slotCounts[ui] = 65535; + plr->inventory.slotCounts[ui] = 32; } for (ItemType ui = ITEMREGISTRY_SIZE / 2; ui < itemRegistryIndex; ui++) { - plr->inventory.slotCounts[ui] = 65535; + plr->inventory.slotCounts[ui] = 0; } hudTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, screenRect.w, diff --git a/tiles/furnace.c b/tiles/furnace.c index 7517107..e10ebac 100644 --- a/tiles/furnace.c +++ b/tiles/furnace.c @@ -35,9 +35,7 @@ void updateFurnace(Tile *tile) { audioData.synthVoices[tile->audioCh].frequency = 200; } } - if (tile->audioCh < NUM_SYNTH_VOICES) { - printf("frq: %d\n", ++audioData.synthVoices[tile->audioCh].frequency); - } + ++audioData.synthVoices[tile->audioCh].frequency; if (audioData.synthVoices[tile->audioCh].volume < 255) { audioData.synthVoices[tile->audioCh].volume++; } diff --git a/util/audio.c b/util/audio.c index 8657598..5ec9d75 100644 --- a/util/audio.c +++ b/util/audio.c @@ -58,8 +58,8 @@ void audio_callback(void *userdata, Uint8 *stream, int len) { MidiEvent *ev = &midiEvents[midiChannel][nextMidiEvent[midiChannel]]; - printf("Event at %f, %s, note: %d, velocity: %d\n", ev->timeSec, ev->type == MIDI_NOTE_ON ? "ON" : "OFF", - ev->note, ev->velocity); +// printf("Event at %f, %s, note: %d, velocity: %d\n", ev->timeSec, ev->type == MIDI_NOTE_ON ? "ON" : "OFF", +// ev->note, ev->velocity); uint16_t freq = (uint16_t)(440.0f * powf(2.0f, (ev->note - 69) / 12.0f)); uint8_t midiVoiceIndex = NUM_SYNTH_VOICES - midiChannel - 1; @@ -69,12 +69,12 @@ void audio_callback(void *userdata, Uint8 *stream, int len) { v->frequency = freq; v->volume = ev->velocity * 2; v->smoothedAmp = 0; - printf("Playing voice %d at freq %d hz, volume %d\n", midiVoiceIndex, v->frequency, - v->volume); +// printf("Playing voice %d at freq %d hz, volume %d\n", midiVoiceIndex, v->frequency, +// v->volume); } else if (ev->type == MIDI_NOTE_OFF || ev->velocity == 0) { // Note Off v->volume = 0; - printf("Stopping voice %d at freq %d hz, volume %d\n", midiVoiceIndex, v->frequency, v->volume); +// printf("Stopping voice %d at freq %d hz, volume %d\n", midiVoiceIndex, v->frequency, v->volume); } else if ((ev->type & 0xF0) == MIDI_PROGRAM_CHANGE) { if (ev->note == 0) { v->waveform = resolvePatch(ev->note);