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
Copy file name to clipboardExpand all lines: README.md
+103-2Lines changed: 103 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,65 @@
1
1
# SimThreads v1.1.0
2
-
Parallel Execution in GameMaker
2
+
Parallel Execution for GameMaker 2022.5+
3
3
4
-
Example:
4
+
### Quick Disclaimer!
5
+
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
+
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!
9
+
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
+
SimThreads has two major kinds of support: Direct calling a method and passing in a function/method with arguments.
12
+
13
+
The use cases for SimThreads allows one to basically push any sort of function/functions and process each set of functions over the next couple of frames.
14
+
15
+
This can be applied to concepts such as:
16
+
17
+
-Reading/Writing from data structures/buffers/arrays<br>
18
+
-World Gen<br>
19
+
-Saving/Loading (within reason)<br>
20
+
-Anything that could be processed over the course of a couple frames.<br>
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:
51
+
52
+
```gml
53
+
thread.push({
54
+
callback: myGMLFunction
55
+
args: ["Hello World!"]
56
+
});
57
+
```
58
+
59
+
Giving you the ultimate flexibility in however you want to handle your games logic!
60
+
61
+
62
+
# Example:
5
63
```gml
6
64
// Create Event
7
65
thread = new SimThread();
@@ -28,4 +86,47 @@ thread.Push(function() {
28
86
```gml
29
87
// Game End Event
30
88
thread.Flush();
89
+
thread.Destroy();
31
90
```
91
+
92
+
# Methods:
93
+
94
+
## `.Pause()`
95
+
96
+
Pauses the SimThread execution.
97
+
98
+
## `.Resume()`
99
+
100
+
Resumes the SimThread execution.
101
+
102
+
## `.SetMaxTime(percent)`
103
+
104
+
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
+
## `.Insert(entry, position)`
111
+
112
+
Inserts a function/method or struct to a set position within the SimThread.
113
+
114
+
## `.Push(entry, [entry], [...])`
115
+
116
+
Pushes one or multiple functions/methods or structs, adding at the end of the queue.
117
+
118
+
## `.Clear()`
119
+
120
+
Clears the SimThread queue.
121
+
122
+
## `.Destroy()`
123
+
124
+
Frees the SimThread queue.
125
+
126
+
## `.GetQueueLength()`
127
+
128
+
Gets the length of the SimThread queue.
129
+
130
+
## `.Flush()`
131
+
132
+
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.
0 commit comments