Mercurial > games > semicongine
annotate semiconginev2/core/utils.nim @ 1251:3f98ad20a9d3
add: render by-node instead of by-mesh
author | sam <sam@basx.dev> |
---|---|
date | Fri, 26 Jul 2024 20:34:02 +0700 |
parents | 841e12f33c47 |
children |
rev | line source |
---|---|
890 | 1 type |
2 HorizontalAlignment* = enum | |
3 Left | |
4 Center | |
5 Right | |
6 VerticalAlignment* = enum | |
7 Top | |
8 Center | |
9 Bottom | |
10 | |
1137 | 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 | 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 | 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 | 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 |