annotate semiconginev2/core/utils.nim @ 1257:e9b8d87b9883

fix: super stupid bug in perspective matrix X(
author sam <sam@basx.dev>
date Sun, 28 Jul 2024 18:55:46 +0700
parents 841e12f33c47
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
890
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
1 type
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
2 HorizontalAlignment* = enum
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
3 Left
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
4 Center
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
5 Right
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
6 VerticalAlignment* = enum
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
7 Top
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
8 Center
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
9 Bottom
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
10
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
11 func CleanString*(str: openArray[char]): string =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
12 for i in 0 ..< len(str):
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
13 if str[i] == char(0):
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
14 result = join(str[0 ..< i])
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
15 break
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
16
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
17 func ToCPointer*[T](list: openArray[T]): ptr T =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
18 if list.len > 0: addr(list[0]) else: nil
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
19
1234
841e12f33c47 add: text & font rendering, not tested yet
sam <sam@basx.dev>
parents: 1218
diff changeset
20 # required for some external libraries
841e12f33c47 add: text & font rendering, not tested yet
sam <sam@basx.dev>
parents: 1218
diff changeset
21 proc nativeFree(p: pointer) {.importc: "free".}
841e12f33c47 add: text & font rendering, not tested yet
sam <sam@basx.dev>
parents: 1218
diff changeset
22
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
23 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
24 let (output, exitcode) = gorgeEx(
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
25 command = command,
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
26 input = input)
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
27 if exitcode != 0:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
28 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
29 return output
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
30
984
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
31 proc AppName*(): string =
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
32 return string(Path(getAppFilename()).splitFile.name)
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
33
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
34 func Size*[T: seq](list: T): uint64 =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
35 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
36
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
37 template TimeAndLog*(body: untyped): untyped =
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
38 let t0 = getMonoTime()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
39 body
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
40 echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
41
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
42 template TimeAndLog*(name: string, body: untyped): untyped =
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
43 let t0 = getMonoTime()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
44 body
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
45 echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000