mirror of https://github.com/dsrw/enu.git
Metrics. Faster sync.
This commit is contained in:
parent
c54a95ceb7
commit
cfb5089f47
|
@ -10,7 +10,7 @@
|
|||
"request": "launch",
|
||||
"name": "Client: Build and Debug",
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
|
||||
"env": {"ENU_CONNECT_ADDRESS": "127.0.0.1"},
|
||||
"env": {"ENU_CONNECT_ADDRESS": "127.0.0.1", "ENU_METRICS_PORT": "8001"},
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.windows.opt.tools.64"
|
||||
},
|
||||
|
@ -28,7 +28,7 @@
|
|||
"request": "launch",
|
||||
"name": "Host: Build and Debug",
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
|
||||
"env": {"ENU_LISTEN_ADDRESS": "0.0.0.0"},
|
||||
"env": {"ENU_LISTEN_ADDRESS": "0.0.0.0", "ENU_METRICS_PORT": "8000"},
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.windows.opt.tools.64"
|
||||
},
|
||||
|
@ -46,7 +46,7 @@
|
|||
"request": "launch",
|
||||
"name": "Client: Debug",
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
|
||||
"env": {"ENU_CONNECT_ADDRESS": "127.0.0.1"},
|
||||
"env": {"ENU_CONNECT_ADDRESS": "127.0.0.1", "ENU_METRICS_PORT": "8001"},
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.windows.opt.tools.64"
|
||||
},
|
||||
|
@ -62,7 +62,7 @@
|
|||
"request": "launch",
|
||||
"name": "Host: Debug",
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
|
||||
"env": {"ENU_LISTEN_ADDRESS": "0.0.0.0"},
|
||||
"env": {"ENU_LISTEN_ADDRESS": "0.0.0.0", "ENU_METRICS_PORT": "8000"},
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/vendor/godot/bin/godot.windows.opt.tools.64"
|
||||
},
|
||||
|
|
|
@ -31,7 +31,7 @@ else:
|
|||
requires "nim >= 1.6.10",
|
||||
"https://github.com/arnetheduck/nim-results#f3c666a",
|
||||
"https://github.com/dsrw/godot-nim#892c482",
|
||||
"https://github.com/dsrw/model_citizen 0.18.13",
|
||||
"https://github.com/dsrw/model_citizen 0.18.15",
|
||||
"https://github.com/dsrw/nanoid.nim 0.2.1",
|
||||
"cligen 1.6.0",
|
||||
"https://github.com/treeform/pretty",
|
||||
|
@ -39,7 +39,8 @@ requires "nim >= 1.6.10",
|
|||
"markdown",
|
||||
"chronicles",
|
||||
"dotenv",
|
||||
"nimibook"
|
||||
"nimibook",
|
||||
"metrics"
|
||||
|
||||
proc godot_bin(target = target): string =
|
||||
result = this_dir() & &"/vendor/godot/bin/godot.{target}.opt.tools.{cpu}{exe_ext}"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
--threads:on
|
||||
--mm:orc
|
||||
--tls_emulation:off
|
||||
--deepcopy:on
|
||||
|
||||
if host_os == "windows":
|
||||
--pass_l:"-static"
|
||||
|
|
|
@ -153,8 +153,8 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
|
|||
|
||||
var listen_address = main_thread_state.config.listen_address
|
||||
let worker_ctx = ZenContext.init(id = \"work-{generate_id()}",
|
||||
chan_size = 500, buffer = true,
|
||||
listen_address = listen_address)
|
||||
chan_size = 500, buffer = false, listen_address = listen_address,
|
||||
label = "worker")
|
||||
|
||||
Zen.thread_ctx = worker_ctx
|
||||
ctx.subscribe(Zen.thread_ctx)
|
||||
|
@ -266,7 +266,7 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
|
|||
let timeout = frame_start + max_time
|
||||
let wait_until = frame_start + min_time
|
||||
|
||||
Zen.thread_ctx.boop(max_duration = (1.0 / 30).seconds)
|
||||
Zen.thread_ctx.boop
|
||||
inc state.frame_count
|
||||
for ctx_name in Zen.thread_ctx.unsubscribed:
|
||||
var i = 0
|
||||
|
@ -283,15 +283,15 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
|
|||
|
||||
var batched: HashSet[Unit]
|
||||
|
||||
while to_process.len > 0 and get_mono_time() < timeout and
|
||||
Zen.thread_ctx.pressure < 0.5:
|
||||
while Zen.thread_ctx.pressure < 0.9 and to_process.len > 0 and
|
||||
get_mono_time() < timeout:
|
||||
|
||||
let units = to_process
|
||||
to_process = @[]
|
||||
for unit in units:
|
||||
if Ready in unit.global_flags:
|
||||
if unit.batch_changes:
|
||||
batched.incl unit
|
||||
batched.incl unit
|
||||
if worker.advance_unit(unit, timeout):
|
||||
to_process.add(unit)
|
||||
|
||||
|
@ -308,7 +308,8 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
|
|||
|
||||
Zen.thread_ctx.boop
|
||||
|
||||
proc launch_worker*(ctx: ZenContext, state: GameState): Thread[tuple[ctx: ZenContext, state: GameState]] =
|
||||
proc launch_worker*(ctx: ZenContext, state: GameState): Thread[tuple[
|
||||
ctx: ZenContext, state: GameState]] =
|
||||
worker_lock.acquire
|
||||
result.create_thread(worker_thread, (ctx, state))
|
||||
work_done.wait(worker_lock)
|
||||
|
|
26
src/game.nim
26
src/game.nim
|
@ -1,5 +1,5 @@
|
|||
import std / [monotimes, os, jsonutils, json, math, locks, random]
|
||||
import pkg / [godot]
|
||||
import std / [monotimes, os, jsonutils, json, math, locks, random, net]
|
||||
import pkg / [godot, metrics, metrics / stdlib_httpserver]
|
||||
from dotenv import nil
|
||||
import godotapi / [input, input_event, gd_os, node, scene_tree, packed_scene,
|
||||
sprite, control, viewport, viewport_texture, performance, label, theme,
|
||||
|
@ -11,6 +11,11 @@ import core, types, globals, controllers, models / [serializers, units, colors]
|
|||
if file_exists(".env"):
|
||||
dotenv.overload()
|
||||
|
||||
when defined(metrics):
|
||||
set_system_metrics_automatic_update(false)
|
||||
|
||||
ZenContext.init_metrics "main", "worker"
|
||||
|
||||
gdobj Game of Node:
|
||||
var
|
||||
reticle: Control
|
||||
|
@ -21,13 +26,18 @@ gdobj Game of Node:
|
|||
last_tool = BlueBlock
|
||||
saved_mouse_position: Vector2
|
||||
rescale_at = get_mono_time()
|
||||
update_metrics_at = get_mono_time()
|
||||
node_controller: NodeController
|
||||
script_controller: ScriptController
|
||||
|
||||
method process*(delta: float) =
|
||||
Zen.thread_ctx.boop(max_duration = (1.0 / 30.0).seconds)
|
||||
Zen.thread_ctx.boop
|
||||
inc state.frame_count
|
||||
let time = get_mono_time()
|
||||
when defined(metrics):
|
||||
if self.update_metrics_at < time:
|
||||
update_thread_metrics()
|
||||
self.update_metrics_at = time + 10.seconds
|
||||
if state.config.show_stats:
|
||||
let fps = get_monitor(TIME_FPS)
|
||||
|
||||
|
@ -90,7 +100,7 @@ world: {state.world_name}
|
|||
var initial_user_config = load_user_config(get_user_data_dir())
|
||||
|
||||
Zen.thread_ctx = ZenContext.init(id = \"main-{generate_id()}",
|
||||
chan_size = 100, buffer = false)
|
||||
chan_size = 2000, buffer = true, label = "main")
|
||||
|
||||
state = GameState.init
|
||||
state.nodes.game = self
|
||||
|
@ -140,6 +150,14 @@ world: {state.world_name}
|
|||
state.set_flag(God, uc.god_mode ||= false)
|
||||
|
||||
set_window_fullscreen state.config.start_full_screen
|
||||
when defined(metrics):
|
||||
let metrics_port = if ?get_env("ENU_METRICS_PORT"):
|
||||
get_env("ENU_METRICS_PORT").parse_int
|
||||
else:
|
||||
8000
|
||||
|
||||
{.cast(gcsafe).}:
|
||||
start_metrics_http_server("0.0.0.0", Port(metrics_port))
|
||||
|
||||
self.add_platform_input_actions()
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# --define:"chronicles_log_level=DEBUG"
|
||||
# --define:"chronicles_disabled_topics=networking,scripting,publishing"
|
||||
# --define:"metrics"
|
||||
|
||||
# --define:"zen_trace"
|
||||
# --define:"dump_zen_objects"
|
||||
|
||||
|
|
Loading…
Reference in New Issue