Mercurial > games > semicongine
comparison semiconginev2/contrib/settings.nim @ 1252:01e9f41d35b1
add:support for push constants
| author | sam <sam@basx.dev> |
|---|---|
| date | Fri, 26 Jul 2024 23:04:01 +0700 |
| parents | c8e3037aca66 |
| children |
comparison
equal
deleted
inserted
replaced
| 1251:3f98ad20a9d3 | 1252:01e9f41d35b1 |
|---|---|
| 1 const CONFIGROOT: string = "." | 1 const CONFIGHOTRELOAD {.booldefine.}: bool = not defined(release) |
| 2 const CONFIGEXTENSION: string = "ini" | 2 const CONFIGHOTRELOADINTERVAL {.intdefine.}: int = 1000 |
| 3 # by default enable hot-reload of runtime-configuration only in debug builds | 3 const CONFIGROOT {.strdefine.}: string = "." |
| 4 const CONFIGHOTRELOAD: bool = not defined(release) | 4 const CONFIGEXTENSION {.strdefine.}: string = "ini" |
| 5 # milliseconds to wait between checks for settings hotreload | 5 |
| 6 const CONFIGHOTRELOADINTERVAL: int = 1000 | |
| 7 | 6 |
| 8 when CONFIGHOTRELOAD: | 7 when CONFIGHOTRELOAD: |
| 9 var | 8 var |
| 10 configUpdates: Channel[(string, string)] | 9 configUpdates: Channel[(string, string)] |
| 11 configUpdates.open() | 10 configUpdates.open() |
| 75 result = configUpdates.peek() > 0 | 74 result = configUpdates.peek() > 0 |
| 76 | 75 |
| 77 allsettings = loadAllConfig() | 76 allsettings = loadAllConfig() |
| 78 | 77 |
| 79 when CONFIGHOTRELOAD == true: | 78 when CONFIGHOTRELOAD == true: |
| 80 import std/times | |
| 81 | |
| 82 proc configFileWatchdog() {.thread.} = | 79 proc configFileWatchdog() {.thread.} = |
| 83 var configModTimes: Table[string, times.Time] | 80 var configModTimes: Table[string, times.Time] |
| 84 while true: | 81 while true: |
| 85 for namespace in walkConfigNamespaces(): | 82 for namespace in walkConfigNamespaces(): |
| 86 if not (namespace in configModTimes): | 83 if not (namespace in configModTimes): |
| 91 let configStr = newFileStream(namespace.getFile()).readAll() | 88 let configStr = newFileStream(namespace.getFile()).readAll() |
| 92 configUpdates.send((namespace, configStr)) | 89 configUpdates.send((namespace, configStr)) |
| 93 sleep CONFIGHOTRELOADINTERVAL | 90 sleep CONFIGHOTRELOADINTERVAL |
| 94 var thethread: Thread[void] | 91 var thethread: Thread[void] |
| 95 createThread(thethread, configFileWatchdog) | 92 createThread(thethread, configFileWatchdog) |
| 96 | |
| 97 if not defined(release): | |
| 98 setLogFilter(lvlAll) | |
| 99 else: | |
| 100 setLogFilter(lvlWarn) |
