-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
System.ew
212 lines (118 loc) · 4.95 KB
/
System.ew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
--EuSFML 2.5.1
--Written by Andy P.
--System routines (for csfml-system-2.dll)
--Clock,Time,Mutex,Sleep,Thread
--Vector2 and Vector3 structs are declared as separate
--For Example: sfVector2f would be C_FLOAT,C_FLOAT for x and y
--Copyright (c) 2022
include std/machine.e
include std/dll.e
include std/os.e
include flags.e
--load the DLL
atom sys = 0
ifdef WINDOWS then
sys = open_dll("csfml-system-2.dll")
elsifdef LINUX or FREEBSD then
sys = open_dll("csfml-system-2.dll")
elsif sys = -1 then
puts(1,"Failed to open csfml-system-2.dll!\n")
abort(1)
end ifdef
--Clock Functions
--Create a clock
public constant xsfClock_create = define_c_func(sys,"+sfClock_create",{},C_POINTER)
public function sfClock_create()
return c_func(xsfClock_create,{})
end function
--Copy a clock
public constant xsfClock_copy = define_c_func(sys,"+sfClock_copy",{C_POINTER},C_POINTER)
public function sfClock_copy(atom clock)
return c_func(xsfClock_copy,{clock})
end function
--Destroy a clock
public constant xsfClock_destroy = define_c_proc(sys,"+sfClock_destroy",{C_POINTER})
public procedure sfClock_destroy(atom clock)
c_proc(xsfClock_destroy,{clock})
end procedure
--Get elapsed time for clock since sfClock_restart had been called
public constant xsfClock_getElapsedTime = define_c_func(sys,"+sfClock_getElapsedTime",{C_POINTER},C_POINTER)
public function sfClock_getElapsedTime(atom clock)
return c_func(xsfClock_getElapsedTime,{clock})
end function
--Restart a clock
public constant xsfClock_restart = define_c_func(sys,"+sfClock_restart",{C_POINTER},C_POINTER)
public function sfClock_restart(atom clock)
return c_func(xsfClock_restart,{clock})
end function
--Time Functions
--Note time has struct that contains sfInt64 microseconds
--This will be referred to as C_LONG
public constant xsfTime_asSeconds = define_c_func(sys,"+sfTime_asSeconds",{C_LONG},C_FLOAT)
public function sfTime_asSeconds(atom xtime)
return c_func(xsfTime_asSeconds,{xtime})
end function
public constant xsfTime_asMilliseconds = define_c_func(sys,"+sfTime_asMilliseconds",{C_LONG},C_INT)
public function sfTime_asMilliseconds(atom xtime)
return c_func(xsfTime_asMilliseconds,{xtime})
end function
public constant xsfTime_asMicroseconds = define_c_func(sys,"+sfTime_asMicroseconds",{C_LONG},C_LONG)
public function sfTime_asMicroseconds(atom xtime)
return c_func(xsfTime_asMicroseconds,{xtime})
end function
public constant xsfSeconds = define_c_func(sys,"+sfSeconds",{C_FLOAT},C_LONG)
public function sfSeconds(atom amount)
return c_func(xsfSeconds,{amount})
end function
public constant xsfMilliseconds = define_c_func(sys,"+sfMilliseconds",{C_INT},C_LONG)
public function sfMilliseconds(atom amount)
return c_func(xsfMilliseconds,{amount})
end function
public constant xsfMicroseconds = define_c_func(sys,"+sfMicroseconds",{C_LONG},C_LONG)
public function sfMicroseconds(atom amount)
return c_func(xsfMicroseconds,{amount})
end function
--Sleep Function
public constant xsfSleep = define_c_proc(sys,"+sfSleep",{C_LONG})
public procedure sfSleep(atom duration)
c_proc(xsfSleep,{duration})
end procedure
--Thread Functions
public constant xsfThread_create = define_c_func(sys,"+sfThread_create",{C_POINTER,C_POINTER},C_POINTER)
public function sfThread_create(atom v,atom d)
return c_func(xsfThread_create,{v,d})
end function
public constant xsfThread_destroy = define_c_proc(sys,"+sfThread_destroy",{C_POINTER})
public procedure sfThread_destroy(atom thread)
c_proc(xsfThread_destroy,{thread})
end procedure
public constant xsfThread_launch = define_c_proc(sys,"+sfThread_launch",{C_POINTER})
public procedure sfThread_launch(atom thread)
c_proc(xsfThread_launch,{thread})
end procedure
public constant xsfThread_wait = define_c_proc(sys,"+sfThread_wait",{C_POINTER})
public procedure sfThread_wait(atom thread)
c_proc(xsfThread_wait,{thread})
end procedure
public constant xsfThread_terminate = define_c_proc(sys,"+sfThread_terminate",{C_POINTER})
public procedure sfThread_terminate(atom thread)
c_proc(xsfThread_terminate,{thread})
end procedure
--Mutex Functions
public constant xsfMutex_create = define_c_func(sys,"+sfMutex_create",{},C_POINTER)
public function sfMutex_create()
return c_func(xsfMutex_create,{})
end function
public constant xsfMutex_destroy = define_c_proc(sys,"+sfMutex_destroy",{C_POINTER})
public procedure sfMutex_destroy(atom mutex)
c_proc(xsfMutex_destroy,{mutex})
end procedure
public constant xsfMutex_lock = define_c_proc(sys,"+sfMutex_lock",{C_POINTER})
public procedure sfMutex_lock(atom mutex)
c_proc(xsfMutex_lock,{mutex})
end procedure
public constant xsfMutex_unlock = define_c_proc(sys,"+sfMutex_unlock",{C_POINTER})
public procedure sfMutex_unlock(atom mutex)
c_proc(xsfMutex_unlock,{mutex})
end procedure
7.20