diff --git a/.gitignore b/.gitignore index b7603fc..6147442 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ haxe-fmod.zip # Generated code *raw.js +faxe/obj +test/out/* diff --git a/faxe/Build.xml b/faxe/Build.xml new file mode 100644 index 0000000..2d15e63 --- /dev/null +++ b/faxe/Build.xml @@ -0,0 +1,33 @@ + +
+ +
+ + + + + + + + + + + + + + +
+ + +
+ +
+ + +
+ + + + +
+
\ No newline at end of file diff --git a/faxe/libhl32.lib b/faxe/libhl32.lib new file mode 100644 index 0000000..4f3cc1c Binary files /dev/null and b/faxe/libhl32.lib differ diff --git a/faxe/linc_faxe.cpp b/faxe/linc_faxe.cpp index ddc5e15..ab2d0ba 100644 --- a/faxe/linc_faxe.cpp +++ b/faxe/linc_faxe.cpp @@ -1,460 +1,611 @@ /** -* Faxe - FMOD bindings for Haxe -* -* The MIT License (MIT) -* -* Copyright (c) 2016 Aaron M. Shea -* Copyright (c) 2020 Tanner Moore -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - + * Faxe - FMOD bindings for Haxe + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Aaron M. Shea + * Copyright (c) 2020 Tanner Moore + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #include -#include + +#include "linc_faxe.h" + +#include #include +#include #include -#include -#include +#include -#include "linc_faxe.h" +char *faxe_to_cstring(faxe_string s) { +#ifdef FAXE_HL + return hl_to_utf8(s->bytes); +#else + return (char *)s.c_str(); +#endif +} -namespace linc +int faxe_string_length(faxe_string s) { - namespace faxe +#ifdef FAXE_HL + return s->length; +#else + return s.length; +#endif +} + +faxe_string faxe_string_from_c(char *s, int len) { +#ifdef FAXE_HL + faxe_string str = (faxe_string)hl_alloc_dynamic(&hlt_dynobj); + str->bytes = (uchar*)s; + str->length = len; + return (faxe_string)str; +#else + return faxe_string(s,len); +#endif + +} + +// FMOD Sound System +FMOD::Studio::System *fmodSoundSystem; +FMOD::System *fmodCoreSoundSystem; + +// Maps to track what has been loaded already +std::map loadedBanks; +std::map loadedSounds; +std::map loadedEventInstances; + +// Callbacks +std::map eventCallbacksFlagsMap; + +// Background thread to automatically call FMOD's Update() function +std::thread autoUpdaterThread; +bool autoUpdaterThreadShouldExit; + +//// FMOD System + +bool fmod_debug = false; +HL_PRIM void HL_NAME(fmod_set_debug)(bool onOff) { fmod_debug = onOff; } + +HL_PRIM bool HL_NAME(fmod_is_initialized)() { return true; } + +HL_PRIM void HL_NAME(fmod_init)(int numChannels) +{ + if (fmod_debug) + printf("Initializing HaxeFmod\n"); + // Choose a reasonable default if 0 is passed in + if (numChannels == 0) { - // FMOD Sound System - FMOD::Studio::System* fmodSoundSystem; - FMOD::System* fmodCoreSoundSystem; + numChannels = 36; + } - // Maps to track what has been loaded already - std::map<::String, FMOD::Studio::Bank*> loadedBanks; - std::map<::String, FMOD::Sound*> loadedSounds; - std::map<::String, FMOD::Studio::EventInstance*> loadedEventInstances; - - // Callbacks - std::map<::String, unsigned int> eventCallbacksFlagsMap; + // Create our new fmod system + if (FMOD::Studio::System::create(&fmodSoundSystem) != FMOD_OK) + { + if (fmod_debug) + printf("Failure starting FMOD sound system!\n"); + return; + } + + // Initialize system with channel count and startup flags + auto result = fmodSoundSystem->initialize( + numChannels, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_INIT_NORMAL, nullptr); + if (result != FMOD_OK) + { + printf("FMOD failed to initialize: %s\n", FMOD_ErrorString(result)); + return; + } + result = fmodSoundSystem->getCoreSystem(&fmodCoreSoundSystem); + if (result != FMOD_OK) + { + printf("FMOD failed to get core system: %s\n", FMOD_ErrorString(result)); + return; + } - // Background thread to automatically call FMOD's Update() function - std::thread autoUpdaterThread; - bool autoUpdaterThreadShouldExit; + autoUpdaterThread = std::thread(update_fmod_async); - //// FMOD System + if (fmod_debug) + printf("FMOD Sound System Started with %d channels!\n", numChannels); +}; - bool fmod_debug = false; - void fmod_set_debug(bool onOff){ - fmod_debug = onOff; - } - - bool fmod_is_initialized() { - return true; - } +HL_PRIM void HL_NAME(fmod_update)() +{ + auto result = fmodSoundSystem->update(); + if (result != FMOD_OK) + { + printf("FMOD failed to self-update: %s\n", FMOD_ErrorString(result)); + return; + } +} - void fmod_init(int numChannels) - { - if (fmod_debug) printf("Initializing HaxeFmod\n"); - // Choose a reasonable default if 0 is passed in - if (numChannels == 0){ - numChannels = 36; - } - - // Create our new fmod system - if (FMOD::Studio::System::create(&fmodSoundSystem) != FMOD_OK) - { - if(fmod_debug) printf("Failure starting FMOD sound system!\n"); - return; - } - - // Initialize system with channel count and startup flags - auto result = fmodSoundSystem->initialize(numChannels, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_INIT_NORMAL, nullptr); - if (result != FMOD_OK) - { - printf("FMOD failed to initialize: %s\n", FMOD_ErrorString(result)); - return; - } - result = fmodSoundSystem->getCoreSystem(&fmodCoreSoundSystem); - if (result != FMOD_OK) - { - printf("FMOD failed to get core system: %s\n", FMOD_ErrorString(result)); - return; - } - - autoUpdaterThread = std::thread(update_fmod_async); - - if(fmod_debug) printf("FMOD Sound System Started with %d channels!\n", numChannels); - }; - - void fmod_update() - { - auto result = fmodSoundSystem->update(); - if (result != FMOD_OK) - { - printf("FMOD failed to self-update: %s\n", FMOD_ErrorString(result)); - return; - } - } +void update_fmod_async() +{ + signal(SIGTERM, [](int signum) { autoUpdaterThreadShouldExit = true; }); - void update_fmod_async() - { - signal(SIGTERM, [](int signum){autoUpdaterThreadShouldExit = true;}); + while (!autoUpdaterThreadShouldExit) + { + faxe_fmod_update(); + std::this_thread::sleep_for(std::chrono::milliseconds(16)); + } +} - while (!autoUpdaterThreadShouldExit){ - fmod_update(); - std::this_thread::sleep_for (std::chrono::milliseconds(16)); - } - } +//// Sound Banks - //// Sound Banks +HL_PRIM void HL_NAME(fmod_load_bank)(faxe_string bankFilePath) +{ + if (loadedBanks.find(bankFilePath) != loadedBanks.end()) + { + return; + } - void fmod_load_bank(const ::String& bankFilePath) - { - if (loadedBanks.find(bankFilePath) != loadedBanks.end()) - { - return; - } - - FMOD::Studio::Bank* tempBank; - auto result = fmodSoundSystem->loadBankFile(bankFilePath.c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &tempBank); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to LOAD sound bank %s: %s\n", bankFilePath.c_str(), FMOD_ErrorString(result)); - return; - } - - loadedBanks[bankFilePath] = tempBank; - } + FMOD::Studio::Bank *tempBank; + auto result = fmodSoundSystem->loadBankFile( + faxe_to_cstring(bankFilePath), FMOD_STUDIO_LOAD_BANK_NORMAL, &tempBank); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to LOAD sound bank %s: %s\n", + faxe_to_cstring(bankFilePath), FMOD_ErrorString(result)); + return; + } - void fmod_unload_bank(const ::String& bankName) - { - auto found = loadedBanks.find(bankName); - if (found != loadedBanks.end()) - { - loadedBanks.erase(bankName); - found->second->unload(); - } - } + loadedBanks[bankFilePath] = tempBank; +} - //// Events +HL_PRIM void HL_NAME(fmod_unload_bank)(faxe_string bankName) +{ + auto found = loadedBanks.find(bankName); + if (found != loadedBanks.end()) + { + loadedBanks.erase(bankName); + found->second->unload(); + } +} - void fmod_create_event_instance_one_shot(const ::String& eventPath) - { - FMOD::Studio::EventDescription* eventDescription; - auto result = fmodSoundSystem->getEvent(eventPath.c_str(), &eventDescription); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to load event description %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - - FMOD::Studio::EventInstance* tempEvnInst; - result = eventDescription->createInstance(&tempEvnInst); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to create instance of event %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - - result = tempEvnInst->start(); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to start instance of event %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - - // Tell FMOD API to clean up memory as soon as the event is over - result = tempEvnInst->release(); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to release instance of event %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - } +//// Events - void fmod_create_event_instance_named(const ::String& eventPath, const ::String& eventInstanceName) - { - auto existingEventInstance = loadedEventInstances.find(eventInstanceName); - if (existingEventInstance != loadedEventInstances.end()) - { - // Id conflict. Destroy existing sound and create new one in its place - loadedEventInstances.erase(eventInstanceName); - existingEventInstance->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); - existingEventInstance->second->release(); - if(fmod_debug) printf("FMOD request to create a new event instance %s with an existing instance name: %s. Destorying the old instance in preparation for the new one.\n", eventPath.c_str(), eventInstanceName.c_str()); - } - - FMOD::Studio::EventDescription* eventDescription; - auto result = fmodSoundSystem->getEvent(eventPath.c_str(), &eventDescription); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to load event description %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - } - - FMOD::Studio::EventInstance* eventInstance; - result = eventDescription->createInstance(&eventInstance); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to create event instance %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - - result = eventInstance->start(); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to start event instance %s: %s\n", eventPath.c_str(), FMOD_ErrorString(result)); - return; - } - - // Storing the event instance in a cache. There is no implicit cleanup of these instances. - loadedEventInstances[eventInstanceName] = eventInstance; - if (loadedEventInstances.size() > 25){ - printf("Warn: FMOD - The number of cached sounds is now %zu. ", loadedEventInstances.size()); - printf("Remember to release a sound after it is no longer needed. "); - printf("If you do not need a reference to a sound after playing it, create it as a one shot. "); - printf("When the cached sound count gets too high, sound reference corruption can occur\n"); - // https://github.com/Tanz0rz/faxe2/issues/3 - } - } +HL_PRIM void + HL_NAME(fmod_create_event_instance_one_shot)(faxe_string eventPath) +{ + FMOD::Studio::EventDescription *eventDescription; + auto result = + fmodSoundSystem->getEvent(faxe_to_cstring(eventPath), &eventDescription); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to load event description %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } + + FMOD::Studio::EventInstance *tempEvnInst; + result = eventDescription->createInstance(&tempEvnInst); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to create instance of event %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } + + result = tempEvnInst->start(); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to start instance of event %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } + + // Tell FMOD API to clean up memory as soon as the event is over + result = tempEvnInst->release(); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to release instance of event %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } +} + +HL_PRIM void + HL_NAME(fmod_create_event_instance_named)(faxe_string eventPath, + faxe_string eventInstanceName) +{ + auto existingEventInstance = loadedEventInstances.find(eventInstanceName); + if (existingEventInstance != loadedEventInstances.end()) + { + // Id conflict. Destroy existing sound and create new one in its place + loadedEventInstances.erase(eventInstanceName); + existingEventInstance->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); + existingEventInstance->second->release(); + if (fmod_debug) + printf("FMOD request to create a new event instance %s with an existing " + "instance name: %s. Destorying the old instance in preparation " + "for the new one.\n", + faxe_to_cstring(eventPath), faxe_to_cstring(eventInstanceName)); + } + + FMOD::Studio::EventDescription *eventDescription; + auto result = + fmodSoundSystem->getEvent(faxe_to_cstring(eventPath), &eventDescription); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to load event description %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + } + + FMOD::Studio::EventInstance *eventInstance; + result = eventDescription->createInstance(&eventInstance); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to create event instance %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } + + result = eventInstance->start(); + if (result != FMOD_OK) + { + if (fmod_debug) + printf("FMOD failed to start event instance %s: %s\n", + faxe_to_cstring(eventPath), FMOD_ErrorString(result)); + return; + } + + // Storing the event instance in a cache. There is no implicit cleanup of + // these instances. + loadedEventInstances[eventInstanceName] = eventInstance; + if (loadedEventInstances.size() > 25) + { + printf("Warn: FMOD - The number of cached sounds is now %zu. ", + loadedEventInstances.size()); + printf("Remember to release a sound after it is no longer needed. "); + printf("If you do not need a reference to a sound after playing it, create " + "it as a one shot. "); + printf("When the cached sound count gets too high, sound reference " + "corruption can occur\n"); + // https://github.com/Tanz0rz/faxe2/issues/3 + } +} + +HL_PRIM bool + HL_NAME(fmod_is_event_instance_loaded)(faxe_string eventInstanceName) +{ + if (loadedEventInstances.find(eventInstanceName) != + loadedEventInstances.end()) + { + return true; + } + return false; +} - bool fmod_is_event_instance_loaded(const ::String& eventInstanceName) - { - if (loadedEventInstances.find(eventInstanceName) != loadedEventInstances.end()) - { - return true; - } - return false; - } +HL_PRIM void HL_NAME(fmod_play_event_instance)(faxe_string eventInstanceName) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + targetEvent->second->start(); + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + } +} + +HL_PRIM void + HL_NAME(fmod_set_pause_on_event_instance)(faxe_string eventInstanceName, + bool shouldBePaused) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + targetEvent->second->setPaused(shouldBePaused); + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + } +} - void fmod_play_event_instance(const ::String& eventInstanceName) - { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - targetEvent->second->start(); - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - } - } +HL_PRIM void HL_NAME(fmod_stop_event_instance)(faxe_string eventInstanceName) +{ + auto targetStopEvent = loadedEventInstances.find(eventInstanceName); + if (targetStopEvent != loadedEventInstances.end()) + { + targetStopEvent->second->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + } +} - void fmod_set_pause_on_event_instance(const ::String& eventInstanceName, bool shouldBePaused) - { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - targetEvent->second->setPaused(shouldBePaused); - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - } - } +HL_PRIM void + HL_NAME(fmod_stop_event_instance_immediately)(faxe_string eventInstanceName) +{ + auto targetStopEvent = loadedEventInstances.find(eventInstanceName); + if (targetStopEvent != loadedEventInstances.end()) + { + targetStopEvent->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + } +} - void fmod_stop_event_instance(const ::String& eventInstanceName) +HL_PRIM void + HL_NAME(fmod_release_event_instance)(faxe_string eventInstanceName) +{ + auto existingEventInstance = loadedEventInstances.find(eventInstanceName); + if (existingEventInstance != loadedEventInstances.end()) + { + auto result = + existingEventInstance->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); + if (result != FMOD_OK) { - auto targetStopEvent = loadedEventInstances.find(eventInstanceName); - if (targetStopEvent != loadedEventInstances.end()) - { - targetStopEvent->second->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - } + if (fmod_debug) + printf("FMOD failed to stop event instance %s: %s\n", + faxe_to_cstring(eventInstanceName), FMOD_ErrorString(result)); + return; } - void fmod_stop_event_instance_immediately(const ::String& eventInstanceName) + result = existingEventInstance->second->release(); + if (result != FMOD_OK) { - auto targetStopEvent = loadedEventInstances.find(eventInstanceName); - if (targetStopEvent != loadedEventInstances.end()) - { - targetStopEvent->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - } + if (fmod_debug) + printf("FMOD failed to release event instance %s: %s\n", + faxe_to_cstring(eventInstanceName), FMOD_ErrorString(result)); + return; } - void fmod_release_event_instance(const ::String& eventInstanceName) - { - auto existingEventInstance = loadedEventInstances.find(eventInstanceName); - if (existingEventInstance != loadedEventInstances.end()) - { - auto result = existingEventInstance->second->stop(FMOD_STUDIO_STOP_IMMEDIATE); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to stop event instance %s: %s\n", eventInstanceName.c_str(), FMOD_ErrorString(result)); - return; - } - - result = existingEventInstance->second->release(); - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to release event instance %s: %s\n", eventInstanceName.c_str(), FMOD_ErrorString(result)); - return; - } - - loadedEventInstances.erase(eventInstanceName); - } - } + loadedEventInstances.erase(eventInstanceName); + } +} + +HL_PRIM bool + HL_NAME(fmod_is_event_instance_playing)(faxe_string eventInstanceName) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + FMOD_STUDIO_PLAYBACK_STATE currentState; + auto result = targetEvent->second->getPlaybackState(¤tState); - bool fmod_is_event_instance_playing(const ::String& eventInstanceName) + if (result != FMOD_OK) { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - FMOD_STUDIO_PLAYBACK_STATE currentState; - auto result = targetEvent->second->getPlaybackState(¤tState); - - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to get playback state of event instance %s: %s\n", eventInstanceName.c_str(), FMOD_ErrorString(result)); - return false; - } - - return (currentState == FMOD_STUDIO_PLAYBACK_PLAYING); - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - return false; - } + if (fmod_debug) + printf("FMOD failed to get playback state of event instance %s: %s\n", + faxe_to_cstring(eventInstanceName), FMOD_ErrorString(result)); + return false; } - FMOD_STUDIO_PLAYBACK_STATE fmod_get_event_instance_playback_state(const ::String& eventInstanceName) + return (currentState == FMOD_STUDIO_PLAYBACK_PLAYING); + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + return false; + } +} + +HL_PRIM FMOD_STUDIO_PLAYBACK_STATE + HL_NAME(fmod_get_event_instance_playback_state)(faxe_string eventInstanceName) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + FMOD_STUDIO_PLAYBACK_STATE currentState; + auto result = targetEvent->second->getPlaybackState(¤tState); + + if (result != FMOD_OK) { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - FMOD_STUDIO_PLAYBACK_STATE currentState; - auto result = targetEvent->second->getPlaybackState(¤tState); - - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to get playback state of event instance %s: %s\n", eventInstanceName.c_str(), FMOD_ErrorString(result)); - return FMOD_STUDIO_PLAYBACK_FORCEINT; - } - - return currentState; - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - return FMOD_STUDIO_PLAYBACK_FORCEINT; - } + if (fmod_debug) + printf("FMOD failed to get playback state of event instance %s: %s\n", + faxe_to_cstring(eventInstanceName), FMOD_ErrorString(result)); + return FMOD_STUDIO_PLAYBACK_FORCEINT; } - float fmod_get_event_instance_param(const ::String& eventInstanceName, const ::String& paramName) + return currentState; + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + return FMOD_STUDIO_PLAYBACK_FORCEINT; + } +} + +HL_PRIM float + HL_NAME(fmod_get_event_instance_param)(faxe_string eventInstanceName, + faxe_string paramName) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + float currentValue; + auto result = targetEvent->second->getParameterByName( + faxe_to_cstring(paramName), ¤tValue); + + if (result != FMOD_OK) { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - float currentValue; - auto result = targetEvent->second->getParameterByName(paramName.c_str(), ¤tValue); - - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to get param %s of event instance %s: %s\n", paramName.c_str(), eventInstanceName.c_str(), FMOD_ErrorString(result)); - return -1; - } - - return currentValue; - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - return -1; - } + if (fmod_debug) + printf("FMOD failed to get param %s of event instance %s: %s\n", + faxe_to_cstring(paramName), faxe_to_cstring(eventInstanceName), + FMOD_ErrorString(result)); + return -1; } - void fmod_set_event_instance_param(const ::String& eventInstanceName, const ::String& paramName, float value) + return currentValue; + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + return -1; + } +} + +HL_PRIM void + HL_NAME(fmod_set_event_instance_param)(faxe_string eventInstanceName, + faxe_string paramName, float value) +{ + auto targetEvent = loadedEventInstances.find(eventInstanceName); + if (targetEvent != loadedEventInstances.end()) + { + auto result = targetEvent->second->setParameterByName( + faxe_to_cstring(paramName), value); + + if (result != FMOD_OK) { - auto targetEvent = loadedEventInstances.find(eventInstanceName); - if (targetEvent != loadedEventInstances.end()) - { - auto result = targetEvent->second->setParameterByName(paramName.c_str(), value); - - if (result != FMOD_OK) - { - if(fmod_debug) printf("FMOD failed to SET PARAM %s of event instance %s: %s\n", paramName.c_str(), eventInstanceName.c_str(), FMOD_ErrorString(result)); - } - } else { - if(fmod_debug) printf("Event %s is not loaded!\n", eventInstanceName.c_str()); - } + if (fmod_debug) + printf("FMOD failed to SET PARAM %s of event instance %s: %s\n", + faxe_to_cstring(paramName), faxe_to_cstring(eventInstanceName), + FMOD_ErrorString(result)); } + } + else + { + if (fmod_debug) + printf("Event %s is not loaded!\n", faxe_to_cstring(eventInstanceName)); + } +} - //// Callbacks +//// Callbacks - ::String GetEventInstancePath(FMOD::Studio::EventInstance* eventInstance) { - char *path = new char [100]; - int *retrieved = new int; - FMOD::Studio::EventDescription* eventDescription; - eventInstance->getDescription(&eventDescription); - eventDescription->getPath(path, 100, retrieved); - if (path == NULL){ - printf("Fmod Callback could not find description of event\n"); - } +faxe_string GetEventInstancePath(FMOD::Studio::EventInstance *eventInstance) +{ + char *path = new char[100]; + int *retrieved = new int; + FMOD::Studio::EventDescription *eventDescription; + eventInstance->getDescription(&eventDescription); + eventDescription->getPath(path, 100, retrieved); + if (path == NULL) + { + printf("Fmod Callback could not find description of event\n"); + } - // Haxe has a dedicated String class that must be used to convert char* to a string - ::String pathAsString(path, *retrieved); + return faxe_string_from_c(path, *retrieved); +} - return pathAsString; - } +// Callback definitions must be defined before they are used in functions +FMOD_RESULT F_CALLBACK GetCallbackType(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, + FMOD_STUDIO_EVENTINSTANCE *event, + void *parameters) +{ + auto eventInstancePath = + GetEventInstancePath((FMOD::Studio::EventInstance *)event); + auto eventWithCallback = eventCallbacksFlagsMap.find(eventInstancePath); + if (eventWithCallback != eventCallbacksFlagsMap.end()) + { + eventWithCallback->second = eventWithCallback->second | type; + return FMOD_OK; + } + return FMOD_ERR_EVENT_NOTFOUND; +} + +HL_PRIM void HL_NAME(fmod_set_callback_tracking_for_event_instance)( + faxe_string eventInstanceName) +{ + auto existingEventInstance = loadedEventInstances.find(eventInstanceName); + if (existingEventInstance != loadedEventInstances.end()) + { + existingEventInstance->second->setCallback(GetCallbackType); - // Callback definitions must be defined before they are used in functions - FMOD_RESULT F_CALLBACK GetCallbackType(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE *event, void *parameters) + auto eventInstancePath = + GetEventInstancePath(existingEventInstance->second); + if (faxe_string_length(eventInstancePath) == 0) { - auto eventInstancePath = GetEventInstancePath((FMOD::Studio::EventInstance*) event); - auto eventWithCallback = eventCallbacksFlagsMap.find(eventInstancePath); - if (eventWithCallback != eventCallbacksFlagsMap.end()) { - eventWithCallback->second = eventWithCallback->second | type; - return FMOD_OK; - } - return FMOD_ERR_EVENT_NOTFOUND; + printf( + "Haxefmod-cpp - Fmod Callback could not find description of event\n"); } - - void fmod_set_callback_tracking_for_event_instance(const ::String& eventInstanceName) { - auto existingEventInstance = loadedEventInstances.find(eventInstanceName); - if (existingEventInstance != loadedEventInstances.end()) - { - existingEventInstance->second->setCallback(GetCallbackType); - - auto eventInstancePath = GetEventInstancePath(existingEventInstance->second); - if (eventInstancePath.length == 0) - { - printf("Haxefmod-cpp - Fmod Callback could not find description of event\n"); - } else { - eventCallbacksFlagsMap[eventInstancePath] = 0; - } - } - else - { - if(fmod_debug) printf("Could not set callback tracking on %s because it wasn't found\n", eventInstanceName.c_str()); - } + else + { + eventCallbacksFlagsMap[eventInstancePath] = 0; } - - bool fmod_check_callbacks_for_event_instance(const ::String& eventInstanceName, unsigned int callbackEventMask){ - auto existingEventInstance = loadedEventInstances.find(eventInstanceName); - if (existingEventInstance != loadedEventInstances.end()) - { - auto eventInstancePath = GetEventInstancePath(existingEventInstance->second); - if (eventInstancePath.length == 0) - { - printf("Fmod Callback could not find description of event\n"); - } else { - bool eventHappened = eventCallbacksFlagsMap[eventInstancePath] & callbackEventMask; - eventCallbacksFlagsMap[eventInstancePath] &= ~callbackEventMask; - return eventHappened; - } - } - else - { - if(fmod_debug) printf("Could not check callback on %s because it wasn't found\n", eventInstanceName.c_str()); - } - return false; + } + else + { + if (fmod_debug) + printf("Could not set callback tracking on %s because it wasn't found\n", + faxe_to_cstring(eventInstanceName)); + } +} + +HL_PRIM bool HL_NAME(fmod_check_callbacks_for_event_instance)( + faxe_string eventInstanceName, unsigned int callbackEventMask) +{ + auto existingEventInstance = loadedEventInstances.find(eventInstanceName); + if (existingEventInstance != loadedEventInstances.end()) + { + auto eventInstancePath = + GetEventInstancePath(existingEventInstance->second); + if (faxe_string_length(eventInstancePath) == 0) + { + printf("Fmod Callback could not find description of event\n"); } - - } // faxe + fmod namespace -} // linc namespace + else + { + bool eventHappened = + eventCallbacksFlagsMap[eventInstancePath] & callbackEventMask; + eventCallbacksFlagsMap[eventInstancePath] &= ~callbackEventMask; + return eventHappened; + } + } + else + { + if (fmod_debug) + printf("Could not check callback on %s because it wasn't found\n", + faxe_to_cstring(eventInstanceName)); + } + return false; +} + +#ifdef FAXE_HL +DEFINE_PRIM(_VOID, fmod_set_debug, _BOOL) +DEFINE_PRIM(_BOOL, fmod_is_initialized, _NO_ARG) +DEFINE_PRIM(_VOID, fmod_init, _I32) +DEFINE_PRIM(_VOID, fmod_update, _NO_ARG) +DEFINE_PRIM(_VOID, fmod_load_bank, _STRING) +DEFINE_PRIM(_VOID, fmod_unload_bank, _STRING) +DEFINE_PRIM(_VOID, fmod_create_event_instance_one_shot, _STRING) +DEFINE_PRIM(_VOID, fmod_create_event_instance_named, _STRING _STRING) +DEFINE_PRIM(_BOOL, fmod_is_event_instance_loaded, _STRING) +DEFINE_PRIM(_VOID, fmod_play_event_instance, _STRING) +DEFINE_PRIM(_VOID, fmod_set_pause_on_event_instance, _STRING _BOOL) +DEFINE_PRIM(_VOID, fmod_stop_event_instance, _STRING) +DEFINE_PRIM(_VOID, fmod_stop_event_instance_immediately, _STRING) +DEFINE_PRIM(_VOID, fmod_release_event_instance, _STRING) +DEFINE_PRIM(_BOOL, fmod_is_event_instance_playing, _STRING) +DEFINE_PRIM(_I32, fmod_get_event_instance_playback_state, _STRING) +DEFINE_PRIM(_F32, fmod_get_event_instance_param, _STRING _STRING) +DEFINE_PRIM(_VOID, fmod_set_event_instance_param, _STRING _STRING _F32) +DEFINE_PRIM(_VOID, fmod_set_callback_tracking_for_event_instance, _STRING) +DEFINE_PRIM(_BOOL, fmod_check_callbacks_for_event_instance, _STRING _I32) +// _STRING +#endif \ No newline at end of file diff --git a/faxe/linc_faxe.h b/faxe/linc_faxe.h index 9e45372..39cdd5e 100644 --- a/faxe/linc_faxe.h +++ b/faxe/linc_faxe.h @@ -25,6 +25,16 @@ * THE SOFTWARE. */ #pragma once +#define HL_NAME(n) faxe_##n +#ifdef FAXE_HL +#include +#define faxe_string vstring* +#else +#define HL_PRIM +// #define faxe_string const char* +// typedef const char *faxe_string; +#define faxe_string ::String +#endif #define IMPLEMENT_API @@ -33,55 +43,50 @@ #endif #include - -namespace linc -{ - namespace faxe - { - //// FMOD System + // FMOD System /** * Turns on print statements for any errors happening within the FMOD integration * \param[onOff] turns debug messages on or off */ - extern void fmod_set_debug(bool onOff); + HL_PRIM extern void HL_NAME(fmod_set_debug)(bool onOff); /** * Only needed for the html5 API. Will always return true here */ - extern bool fmod_is_initialized(); + HL_PRIM extern bool HL_NAME(fmod_is_initialized)(); /** * Initialization of FMOD sound system * \param[numChannels] number of channels to allocate for this sound system */ - extern void fmod_init(int numChannels = 32); + HL_PRIM extern void HL_NAME(fmod_init)(int numChannels = 32); /** * Update the FMOD command buffer, should be called once per "tick" */ - extern void fmod_update(); + HL_PRIM extern void HL_NAME(fmod_update)(); /** * Should be called by a background thread. Updates FMOD 60 times per second until a SIGTERM is received */ extern void update_fmod_async(); - //// Sound Banks + // Sound Banks /** * Load a FMOD sound bank file * \param[bankName] ::String the file path of the sound bank to load */ - extern void fmod_load_bank(const ::String& bankName); + HL_PRIM extern void HL_NAME(fmod_load_bank)(faxe_string bankName); /** * Unload a FMOD sound bank file * \param[bankName] ::String the file path of the sound bank to unload */ - extern void fmod_unload_bank(const ::String& bankName); + HL_PRIM extern void HL_NAME(fmod_unload_bank)(faxe_string bankName); - //// Event Descriptions + // Event Descriptions /** * Load an event description from a loaded bank @@ -89,15 +94,15 @@ namespace linc * Event descriptions are loaded automatically when creating event instances * \param[eventPath] ::String the path of the event */ - extern void fmod_load_event_description(const ::String& eventPath); + HL_PRIM extern void HL_NAME(fmod_load_event_description)(faxe_string eventPath); /** * Check if an event description is currently loaded * \param[eventDescriptionName] ::String the event description to check */ - extern bool fmod_is_event_description_loaded(const ::String& eventDescriptionName); + HL_PRIM extern bool HL_NAME(fmod_is_event_description_loaded)(faxe_string eventDescriptionName); - //// Events + // Events /** * Create and play an event instance in a fire-and-forget fashion @@ -105,7 +110,7 @@ namespace linc * Follows the Master Track rules set in the Event's settings in FMOD Studio (Max Instances, Stealing, and probably more) * \param[eventPath] ::String the bank path of the event */ - extern void fmod_create_event_instance_one_shot(const ::String& eventPath); + HL_PRIM extern void HL_NAME(fmod_create_event_instance_one_shot)(faxe_string eventPath); /** * Create and play an event instance and store a reference to it @@ -113,57 +118,57 @@ namespace linc * \param[eventPath] ::String the bank path of the event * \param[eventInstanceName] ::String the name to assign to the new event instance */ - extern void fmod_create_event_instance_named(const ::String& eventPath, const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_create_event_instance_named)(faxe_string eventPath, faxe_string eventInstanceName); /** * Check if an event instance is currently loaded * \param[eventInstanceName] ::String the event instance to check */ - extern bool fmod_is_event_instance_loaded(const ::String& eventInstanceName); + HL_PRIM extern bool HL_NAME(fmod_is_event_instance_loaded)(faxe_string eventInstanceName); /** * Sends the "play" command to an existing event instance * \param[eventInstanceName] ::String the name of the event instance */ - extern void fmod_play_event_instance(const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_play_event_instance)(faxe_string eventInstanceName); /** * Sends the "pause" or "unpause" command to an existing event instance * \param[eventInstanceName] ::String the name of the event instance * \param[shouldBePaused] bool if the event instance should be paused */ - extern void fmod_set_pause_on_event_instance(const ::String& eventInstanceName, bool shouldBePaused); + HL_PRIM extern void HL_NAME(fmod_set_pause_on_event_instance)(faxe_string eventInstanceName, bool shouldBePaused); /** * Sends the "stop" command to an existing event instance * \param[eventInstanceName] ::String the name of the event instance */ - extern void fmod_stop_event_instance(const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_stop_event_instance)(faxe_string eventInstanceName); /** * Immediately stops an existing event instance * \param[eventInstanceName] ::String the name of the event instance */ - extern void fmod_stop_event_instance_immediately(const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_stop_event_instance_immediately)(faxe_string eventInstanceName); /** * Release a loaded event instance from memory * \param[eventInstanceName] ::String the name of the event instance */ - extern void fmod_release_event_instance(const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_release_event_instance)(faxe_string eventInstanceName); /** * Check to see if an event instance is currently playing * \param[eventInstanceName] ::String the name of the event instance * \return ::Bool if the event is currently playing */ - extern bool fmod_is_event_instance_playing(const ::String& eventInstanceName); + HL_PRIM extern bool HL_NAME(fmod_is_event_instance_playing)(faxe_string eventInstanceName); /** * Get the playback state of an existing event instance * \param[eventInstanceName] ::String the name of the event instance */ - extern FMOD_STUDIO_PLAYBACK_STATE fmod_get_event_instance_playback_state(const ::String& eventInstanceName); + HL_PRIM extern FMOD_STUDIO_PLAYBACK_STATE HL_NAME(fmod_get_event_instance_playback_state)(faxe_string eventInstanceName); /** * Check to see if an event is currently playing @@ -171,7 +176,7 @@ namespace linc * \param[paramName] ::String the name of the param to GET * \return float the current value of the param from the specified event */ - extern float fmod_get_event_instance_param(const ::String& eventInstanceName, const ::String& paramName); + HL_PRIM extern float HL_NAME(fmod_get_event_instance_param)(faxe_string eventInstanceName, faxe_string paramName); /** * Set the parameter value of a loaded event @@ -179,9 +184,9 @@ namespace linc * \param[paramName] ::String the name of the param to SET * \param[value] float the new value to set the param to */ - extern void fmod_set_event_instance_param(const ::String& eventInstanceName, const ::String& paramName, float value); + HL_PRIM extern void HL_NAME(fmod_set_event_instance_param)(faxe_string eventInstanceName, faxe_string paramName, float value); - //// Callbacks + // Callbacks /** * Tracks playback callback events for a given event instance @@ -189,7 +194,7 @@ namespace linc * \param[eventInstanceName] ::String the name of the loaded event instance to track * \see https://tanneris.me/FMOD-Callback-Types */ - extern void fmod_set_callback_tracking_for_event_instance(const ::String& eventInstanceName); + HL_PRIM extern void HL_NAME(fmod_set_callback_tracking_for_event_instance)(faxe_string eventInstanceName); /** * Can only be used after assigning the event listener to an event instance @@ -199,7 +204,4 @@ namespace linc * \param[callbackEventMask] ::unsigned int the bitmask that corresponds to the underlying callback type you want to check * \see https://tanneris.me/FMOD-Callback-Types */ - extern bool fmod_check_callbacks_for_event_instance(const ::String& eventInstanceName, unsigned int callbackEventMask); - - } // faxe + fmod namespace -} // linc namespace + HL_PRIM extern bool HL_NAME(fmod_check_callbacks_for_event_instance)(faxe_string eventInstanceName, unsigned int callbackEventMask); diff --git a/faxe/misc/hxcpp.h b/faxe/misc/hxcpp.h new file mode 100644 index 0000000..d85a84f --- /dev/null +++ b/faxe/misc/hxcpp.h @@ -0,0 +1 @@ +// this file is here because I can't lock hxcpp.h out with defines. \ No newline at end of file diff --git a/haxefmod/HaxeFmod.cpp.hx b/haxefmod/HaxeFmod.cpp.hx new file mode 100644 index 0000000..a02080d --- /dev/null +++ b/haxefmod/HaxeFmod.cpp.hx @@ -0,0 +1,59 @@ +package haxefmod; + +import haxefmod.FmodInternalEnums; + +@:keep +@:include('linc_faxe.h') +#if !display +@:build(faxe.Linc.touch()) +@:build(faxe.Linc.xml('faxe')) +#end +extern class HaxeFmod { + // FMOD System + @:native("faxe_fmod_set_debug") + public static function fmod_set_debug(onOff:Bool):Void; + @:native("faxe_fmod_is_initialized") + public static function fmod_is_initialized():Bool; + @:native("faxe_fmod_init") + public static function fmod_init(numChannels:Int = 128):Void; + @:native("faxe_fmod_update") + public static function fmod_update():Void; + + // Sound Banks + @:native("faxe_fmod_load_bank") + public static function fmod_load_bank(bankFilePath:String):Void; + @:native("faxe_fmod_unload_bank") + public static function fmod_unload_bank(bankFilePath:String):Void; + + // Events + @:native("faxe_fmod_create_event_instance_one_shot") + public static function fmod_create_event_instance_one_shot(eventPath:String):Void; + @:native("faxe_fmod_create_event_instance_named") + public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; + @:native("faxe_fmod_is_event_instance_loaded") + public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; + @:native("faxe_fmod_play_event_instance") + public static function fmod_play_event_instance(eventInstanceName:String):Void; + @:native("faxe_fmod_set_pause_on_event_instance") + public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; + @:native("faxe_fmod_stop_event_instance") + public static function fmod_stop_event_instance(eventInstanceName:String):Void; + @:native("faxe_fmod_stop_event_instance") + public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; + @:native("faxe_fmod_release_event_instance") + public static function fmod_release_event_instance(eventInstanceName:String):Void; + @:native("faxe_fmod_is_event_instance_playing") + public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; + @:native("faxe_fmod_get_event_instance_playback_state") + public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; + @:native("faxe_fmod_get_event_instance_param") + public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):Float; + @:native("faxe_fmod_set_event_instance_param") + public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:Float):Void; + + // Callbacks + @:native("faxe_fmod_set_callback_tracking_for_event_instance") + public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; + @:native("faxe_fmod_check_callbacks_for_event_instance") + public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; +} diff --git a/haxefmod/HaxeFmod.hl.hx b/haxefmod/HaxeFmod.hl.hx new file mode 100644 index 0000000..5e1cd2e --- /dev/null +++ b/haxefmod/HaxeFmod.hl.hx @@ -0,0 +1,53 @@ +package haxefmod; + +import haxefmod.FmodInternalEnums; + +extern class HaxeFmod { + // FMOD System + @:hlNative("faxe", "fmod_set_debug") + public static function fmod_set_debug(onOff:Bool):Void; + @:hlNative("faxe", "fmod_is_initialized") + public static function fmod_is_initialized():Bool; + @:hlNative("faxe", "fmod_init") + public static function fmod_init(numChannels:Int):Void; + @:hlNative("faxe", "fmod_update") + public static function fmod_update():Void; + + // Sound Banks + @:hlNative("faxe", "fmod_load_bank") + public static function fmod_load_bank(bankFilePath:String):Void; + @:hlNative("faxe", "fmod_unload_bank") + public static function fmod_unload_bank(bankFilePath:String):Void; + + // Events + @:hlNative("faxe", "fmod_create_event_instance_one_shot") + public static function fmod_create_event_instance_one_shot(eventPath:String):Void; + @:hlNative("faxe", "fmod_create_event_instance_named") + public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_is_event_instance_loaded") + public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; + @:hlNative("faxe", "fmod_play_event_instance") + public static function fmod_play_event_instance(eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_set_pause_on_event_instance") + public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; + @:hlNative("faxe", "fmod_stop_event_instance") + public static function fmod_stop_event_instance(eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_stop_event_instance") + public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_release_event_instance") + public static function fmod_release_event_instance(eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_is_event_instance_playing") + public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; + @:hlNative("faxe", "fmod_get_event_instance_playback_state") + public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; + @:hlNative("faxe", "fmod_get_event_instance_param") + public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):hl.F32; + @:hlNative("faxe", "fmod_set_event_instance_param") + public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:hl.F32):Void; + + // Callbacks + @:hlNative("faxe", "fmod_set_callback_tracking_for_event_instance") + public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; + @:hlNative("faxe", "fmod_check_callbacks_for_event_instance") + public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; +} diff --git a/haxefmod/HaxeFmod.hx b/haxefmod/HaxeFmod.hx index 13c8e20..08f2d04 100644 --- a/haxefmod/HaxeFmod.hx +++ b/haxefmod/HaxeFmod.hx @@ -2,102 +2,32 @@ package haxefmod; import haxefmod.FmodInternalEnums; -#if windows -@:keep -@:include('linc_faxe.h') -#if !display -@:build(faxe.Linc.touch()) -@:build(faxe.Linc.xml('faxe')) -#end extern class HaxeFmod { - - //// FMOD System - - @:native("linc::faxe::fmod_set_debug") - public static function fmod_set_debug(onOff:Bool):Void; - @:native("linc::faxe::fmod_is_initialized") - public static function fmod_is_initialized():Bool; - @:native("linc::faxe::fmod_init") - public static function fmod_init(numChannels:Int = 128):Void; - @:native("linc::faxe::fmod_update") - public static function fmod_update():Void; - - //// Sound Banks - - @:native("linc::faxe::fmod_load_bank") - public static function fmod_load_bank(bankFilePath:String):Void; - @:native("linc::faxe::fmod_unload_bank") - public static function fmod_unload_bank(bankFilePath:String):Void; - - //// Events - - @:native("linc::faxe::fmod_create_event_instance_one_shot") - public static function fmod_create_event_instance_one_shot(eventPath:String):Void; - @:native("linc::faxe::fmod_create_event_instance_named") - public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; - @:native("linc::faxe::fmod_is_event_instance_loaded") - public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; - @:native("linc::faxe::fmod_play_event_instance") - public static function fmod_play_event_instance(eventInstanceName:String):Void; - @:native("linc::faxe::fmod_set_pause_on_event_instance") - public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; - @:native("linc::faxe::fmod_stop_event_instance") - public static function fmod_stop_event_instance(eventInstanceName:String):Void; - @:native("linc::faxe::fmod_stop_event_instance") - public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; - @:native("linc::faxe::fmod_release_event_instance") - public static function fmod_release_event_instance(eventInstanceName:String):Void; - @:native("linc::faxe::fmod_is_event_instance_playing") - public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; - @:native("linc::faxe::fmod_get_event_instance_playback_state") - public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; - @:native("linc::faxe::fmod_get_event_instance_param") - public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):Float; - @:native("linc::faxe::fmod_set_event_instance_param") - public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:Float):Void; - - //// Callbacks - - @:native("linc::faxe::fmod_set_callback_tracking_for_event_instance") - public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; - @:native("linc::faxe::fmod_check_callbacks_for_event_instance") - public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; -} - -#elseif html5 -@:native("jaxe") -extern class HaxeFmod { - - //// FMOD System - - public static function fmod_set_debug(onOff:Bool):Void; - public static function fmod_is_initialized():Bool; - public static function fmod_init(numChannels:Int = 128):Void; - public static function fmod_update():Void; - - //// Sound Banks - - public static function fmod_load_bank(bankFilePath:String):Void; - public static function fmod_unload_bank(bankFilePath:String):Void; - - //// Events - - public static function fmod_create_event_instance_one_shot(eventPath:String):Void; - public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; - public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; - public static function fmod_play_event_instance(eventInstanceName:String):Void; - public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; - public static function fmod_stop_event_instance(eventInstanceName:String):Void; - public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; - public static function fmod_release_event_instance(eventInstanceName:String):Void; - public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; - public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; - public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):Float; - public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:Float):Void; - - //// Callbacks - - public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; - public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; + // FMOD System + public static function fmod_set_debug(onOff:Bool):Void; + public static function fmod_is_initialized():Bool; + public static function fmod_init(numChannels:Int = 128):Void; + public static function fmod_update():Void; + + // Sound Banks + public static function fmod_load_bank(bankFilePath:String):Void; + public static function fmod_unload_bank(bankFilePath:String):Void; + + // Events + public static function fmod_create_event_instance_one_shot(eventPath:String):Void; + public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; + public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; + public static function fmod_play_event_instance(eventInstanceName:String):Void; + public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; + public static function fmod_stop_event_instance(eventInstanceName:String):Void; + public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; + public static function fmod_release_event_instance(eventInstanceName:String):Void; + public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; + public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; + public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):Float; + public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:Float):Void; + + // Callbacks + public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; + public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; } -#end \ No newline at end of file diff --git a/haxefmod/HaxeFmod.js.hx b/haxefmod/HaxeFmod.js.hx new file mode 100644 index 0000000..361a629 --- /dev/null +++ b/haxefmod/HaxeFmod.js.hx @@ -0,0 +1,34 @@ +package haxefmod; + +import haxefmod.FmodInternalEnums; + +@:native("jaxe") +extern class HaxeFmod { + // FMOD System + public static function fmod_set_debug(onOff:Bool):Void; + public static function fmod_is_initialized():Bool; + public static function fmod_init(numChannels:Int = 128):Void; + public static function fmod_update():Void; + + // Sound Banks + public static function fmod_load_bank(bankFilePath:String):Void; + public static function fmod_unload_bank(bankFilePath:String):Void; + + // Events + public static function fmod_create_event_instance_one_shot(eventPath:String):Void; + public static function fmod_create_event_instance_named(eventPath:String, eventInstanceName:String):Void; + public static function fmod_is_event_instance_loaded(eventInstanceName:String):Bool; + public static function fmod_play_event_instance(eventInstanceName:String):Void; + public static function fmod_set_pause_on_event_instance(eventInstanceName:String, shouldBePaused:Bool):Void; + public static function fmod_stop_event_instance(eventInstanceName:String):Void; + public static function fmod_stop_event_instance_immediately(eventInstanceName:String):Void; + public static function fmod_release_event_instance(eventInstanceName:String):Void; + public static function fmod_is_event_instance_playing(eventInstanceName:String):Bool; + public static function fmod_get_event_instance_playback_state(eventInstanceName:String):FmodStudioPlaybackState; + public static function fmod_get_event_instance_param(eventInstanceName:String, paramName:String):Float; + public static function fmod_set_event_instance_param(eventInstanceName:String, paramName:String, value:Float):Void; + + // Callbacks + public static function fmod_set_callback_tracking_for_event_instance(eventInstanceName:String):Void; + public static function fmod_check_callbacks_for_event_instance(eventInstanceName:String, callbackEventMask:UInt):Bool; +} diff --git a/include.xml b/include.xml index 7b1d7da..0e3b13e 100644 --- a/include.xml +++ b/include.xml @@ -2,13 +2,25 @@ - - - - - - - - - +
+ + + + + + +
+ +
+ + + + +
+ +
+ + + +
\ No newline at end of file diff --git a/ndll/Windows/faxe.dll.hash b/ndll/Windows/faxe.dll.hash new file mode 100644 index 0000000..e2874b7 --- /dev/null +++ b/ndll/Windows/faxe.dll.hash @@ -0,0 +1 @@ +d1ebe785ce52bb8aab5c40eec40223a4 \ No newline at end of file diff --git a/ndll/Windows/faxe.hdll b/ndll/Windows/faxe.hdll new file mode 100644 index 0000000..8f6c5d8 Binary files /dev/null and b/ndll/Windows/faxe.hdll differ diff --git a/update-hashlink-hdll.bat b/update-hashlink-hdll.bat new file mode 100644 index 0000000..4d08b38 --- /dev/null +++ b/update-hashlink-hdll.bat @@ -0,0 +1,26 @@ +@echo off +IF NOT EXIST "update-hashlink-hdll.bat" ( + echo This script can only be run from inside the same directory + pause + exit -1 +) + +echo. +cd faxe +echo Building faxe dll +:: -DHASHLINK needs to point to the local 1.10 HashLink installation +haxelib run hxcpp Build.xml -DHASHLINK=C:\HaxeToolkit\HashLink +echo. + +cd .. +echo removing old dll +del "ndll\Windows\faxe.hdll" +del "ndll\Windows\faxe.dll.hash" +echo. + +echo moving dll and hash file into hashlink directory +move "faxe\faxe.dll" "ndll\Windows\faxe.hdll" +move "faxe\faxe.dll.hash" "ndll\Windows\" +echo. + +pause