mirror of
https://github.com/godotengine/godot.git
synced 2025-10-24 10:23:28 +00:00
[HTML5] Port JavaScript inline code to libraries.
The API is implemented in javascript, and generates C functions that can be called from godot. This allows much cleaner code replacing all `EM_ASM` calls in our C++ code with plain C function calls. This also gets rid of few hacks and comes with few optimizations (e.g. custom cursor shapes should be much faster now).
This commit is contained in:
parent
54cda5c3b8
commit
e2083871eb
33 changed files with 1995 additions and 1461 deletions
|
|
@ -55,33 +55,33 @@ void AudioDriverJavaScript::_audio_thread_func(void *p_data) {
|
|||
OS::get_singleton()->delay_usec(1000); // Give the browser some slack.
|
||||
continue;
|
||||
}
|
||||
obj->_js_driver_process();
|
||||
obj->_audio_driver_process();
|
||||
obj->needs_process = false;
|
||||
obj->unlock();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_start() {
|
||||
void AudioDriverJavaScript::_audio_driver_process_start() {
|
||||
#ifndef NO_THREADS
|
||||
AudioDriverJavaScript::singleton->lock();
|
||||
singleton->lock();
|
||||
#else
|
||||
AudioDriverJavaScript::singleton->_js_driver_process();
|
||||
singleton->_audio_driver_process();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_end() {
|
||||
void AudioDriverJavaScript::_audio_driver_process_end() {
|
||||
#ifndef NO_THREADS
|
||||
AudioDriverJavaScript::singleton->needs_process = true;
|
||||
AudioDriverJavaScript::singleton->unlock();
|
||||
singleton->needs_process = true;
|
||||
singleton->unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_capture(float sample) {
|
||||
AudioDriverJavaScript::singleton->process_capture(sample);
|
||||
void AudioDriverJavaScript::_audio_driver_process_capture(float p_sample) {
|
||||
singleton->process_capture(p_sample);
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::_js_driver_process() {
|
||||
void AudioDriverJavaScript::_audio_driver_process() {
|
||||
int sample_count = memarr_len(internal_buffer) / channel_count;
|
||||
int32_t *stream_buffer = reinterpret_cast<int32_t *>(internal_buffer);
|
||||
audio_server_process(sample_count, stream_buffer);
|
||||
|
|
@ -122,7 +122,7 @@ void AudioDriverJavaScript::start() {
|
|||
#ifndef NO_THREADS
|
||||
thread = Thread::create(_audio_thread_func, this);
|
||||
#endif
|
||||
godot_audio_start(internal_buffer);
|
||||
godot_audio_start(internal_buffer, &_audio_driver_process_start, &_audio_driver_process_end, &_audio_driver_process_capture);
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::resume() {
|
||||
|
|
@ -153,18 +153,12 @@ void AudioDriverJavaScript::unlock() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::finish_async() {
|
||||
#ifndef NO_THREADS
|
||||
quit = true; // Ask thread to quit.
|
||||
#endif
|
||||
godot_audio_finish_async();
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::finish() {
|
||||
#ifndef NO_THREADS
|
||||
quit = true; // Ask thread to quit.
|
||||
Thread::wait_to_finish(thread);
|
||||
memdelete(thread);
|
||||
thread = NULL;
|
||||
thread = nullptr;
|
||||
#endif
|
||||
if (internal_buffer) {
|
||||
memdelete_arr(internal_buffer);
|
||||
|
|
@ -173,13 +167,13 @@ void AudioDriverJavaScript::finish() {
|
|||
}
|
||||
|
||||
Error AudioDriverJavaScript::capture_start() {
|
||||
godot_audio_capture_stop();
|
||||
input_buffer_init(buffer_length);
|
||||
godot_audio_capture_start();
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error AudioDriverJavaScript::capture_stop() {
|
||||
godot_audio_capture_stop();
|
||||
input_buffer.clear();
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue