ENIGMA Forums

Contributing to ENIGMA => Proposals => Topic started by: Goombert on August 02, 2014, 07:21:57 PM

Title: Threading
Post by: Goombert on August 02, 2014, 07:21:57 PM
This is just a quick opinion topic I want to get you guys thoughts on some things.

First, script_thread should not automatically execute, like any other programming language we should be able to create the thread and then execute when want, so I propose the addition of the following function.
thread_start(threadid);

I would also like to propose syntax handling to allow inline threads like Java.
Code: (EDL) [Select]
thread_create() {
  show_message("Thread Running");
}.start();

// also the following
var thread = thread_create() {
  show_message("Thread Running");
}
thread_start(thread);
Title: Re: Threading
Post by: Josh @ Dreamland on August 02, 2014, 08:05:11 PM
I don't like the idea of a new syntax for threads. The new parser supports anonymous functions. If it doesn't, it will briefly.

Code: (EDL) [Select]
function my_thread() {
  for (int i = 0; i < 10; ++i) {
    show_message("Thread Running");
    sleep(1000);
  }
  show_message("Thread Done");
}

var thread = thread_function(my_thread);

Basically, leave the syntax modifications to supporting dynamic functions in general. A thread_start, thread_join, and thread_signal will follow from there.
Title: Re: Threading
Post by: Goombert on August 02, 2014, 08:08:23 PM
Alright that all sounds good to me, so I should just not worry about the additional thread functions right now?
Title: Re: Threading
Post by: Darkstar2 on August 02, 2014, 09:31:56 PM
@Robert:

I like the idea.  I'd like the ability to use threading for loading big assets into the background whilst in an animated game menu or during a game, or animated load screen,
currently script thread in ENIGMA only works with show message, it is broken for everything else.
Title: Re: Threading
Post by: Josh @ Dreamland on August 03, 2014, 11:25:12 AM
Worry about them all you like. I doubt you would have much luck implementing either of those right now.
Title: Re: Threading
Post by: Goombert on August 10, 2014, 11:50:13 PM
Threading has been seriously revamped in my latest commit, I was able to fully implement the threading functions and the implementation now more correctly mirrors most thread API's. I also fixed existing bugs in the thread functions.
http://enigma-dev.org/docs/Wiki/Game_State_Functions
https://github.com/enigma-dev/enigma-dev/pull/788