You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not "true multithreading". This is merely allowing code to be broken down and spread across several of frames, as oppose to having a massive for loop and manipulating lots of data all within a step.
6
6
7
7
If you need any assistance, I'd recommend that you join [My Discord Server, TabularElf's Treehouse](https://discord.gg/ThW5exp6r4) under `💻│gamemaker-libraries`.<br>
8
-
Or if you're in [GameMaker Kitchen](https://discord.gg/8krYCqr), check out `your_libraries🧶` for the thread discussion!
8
+
Or if you're in [GameMaker Kitchen](https://discord.gg/8krYCqr), check out `other_tubularelf_repos`!
9
9
10
10
Allows multiple execution of functions/methods or block of codes, with arguments provided optionally! This is done by having a handy dandy time_source implementation and custom function to execute functions with arguments (as `script_execute_ext` only works for GML functions and methods, not runtime functions.)
11
11
SimThreads has two major kinds of support: Direct calling a method and passing in a function/method with arguments.
@@ -19,160 +19,4 @@ This can be applied to concepts such as:
19
19
-Saving/Loading (within reason)<br>
20
20
-Anything that could be processed over the course of a couple frames.<br>
21
21
22
-
Ues case:
23
-
24
-
`thread = new SimThread([MaxExecutions]);`
25
-
26
-
By default, SimThreads has a MaxExecution of `infinity` and will process every function/method in its queue until it hits the max thread time (as set by `.SetMaxTime(percent)`, which is default to `100%`, or `1`).
27
-
28
-
SimThreads can have a function, method or struct passed as a valid argument for both `.Push()` and `.Insert()` (see down below more for the arguments on those functions)
29
-
30
-
To push a function to a SimThread, you can do.
31
-
```gml
32
-
thread.Push(myGMLFunction);
33
-
```
34
-
35
-
To push a method to a SimThread, you can do.
36
-
```gml
37
-
thread.Push(myMethod);
38
-
39
-
// Or
40
-
41
-
thread.Push(method(self, myGMLFunction));
42
-
43
-
// Or
44
-
45
-
thread.Push(function() {
46
-
show_debug_message("Hello World from " + string(self)));
47
-
});
48
-
```
49
-
50
-
To push a function/method to a SimThread with arguments, you provide:
Sets the max time a given SimThread can execute (with `percent` being a value between `0` to `1`) per step.
105
-
106
-
## `.SetMaxExecution(number)`
107
-
108
-
Sets the max amount of executions per step. `infinity` is set by default. Any number above `0` will limit the SimThread to that number of function executions.
109
-
110
-
## `.Loop(size, callback)`
111
-
112
-
Begins looping a callback until X size is reached. This hooks onto the `.While()` method of `__SimResponseClass`.
113
-
114
-
Returns: Instance of `__SimResponseClass`.
115
-
116
-
## `.Insert(position, callback)`
117
-
118
-
Inserts a function/method or struct to a set position within the SimThread.
119
-
120
-
Returns: Instance of `__SimResponseClass`.
121
-
122
-
## `.Push(callback)`
123
-
124
-
Pushes one or multiple functions/methods or structs, adding at the end of the queue.
125
-
126
-
Returns: Instance of `__SimResponseClass`.
127
-
128
-
## `.PushNext(callback)`
129
-
130
-
Pushes the next callback immediately behind this one.
131
-
132
-
Returns: Instance of `__SimResponseClass`.
133
-
134
-
## `.Clear()`
135
-
136
-
Clears the SimThread queue.
137
-
138
-
## `.Destroy()`
139
-
140
-
Frees the SimThread queue.
141
-
142
-
## `.GetQueueLength()`
143
-
144
-
Gets the length of the SimThread queue.
145
-
146
-
## `.Flush()`
147
-
148
-
Flushes all functions (aka executes all functions/methods) within the queue, regardless of the settings of `.SetMaxTime()` and `.SetMaxExecutions()`, and regardless if it's paused or not.
149
-
150
-
## `.Break()`
151
-
152
-
Forces the Simthread to stop whatever code is being executed during the response (in the case of a loop).<br>
153
-
Note: This only interrupts the loop, but not the current callback that's still processing. You will need to call `return;` or `exit;` to exit out of the callback.
154
-
155
-
156
-
# `__SimResponseClass` methods.
157
-
158
-
## `.While(callback)`
159
-
160
-
Used to indicate whether it should rerun the callback or not, before the callback is executed.
161
-
162
-
Return: `self`
163
-
164
-
## `.Until(callback)`
165
-
166
-
Used to indicate whether it should rerun the callback or not, after the callback is executed.
167
-
168
-
Return: `self`
169
-
170
-
## `.Catch(callback)`
171
-
172
-
Used to handle errors (if any).
173
-
174
-
## `.Finally(callback)`
175
-
176
-
Used to fire off an additional callback after the main callback has finished either successfully, has errored out or has called `.Break()`.
0 commit comments