Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrw committed Jun 13, 2024
1 parent 2bfa0dc commit 7f0ce29
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 126 deletions.
23 changes: 21 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
"type": "lldb",
"request": "launch",
"name": "Client: Build and Debug",
"name": "Client: Build & Debug",
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
"env": {
"ENU_CONNECT_ADDRESS": "127.0.0.1",
Expand All @@ -48,7 +48,7 @@
{
"type": "lldb",
"request": "launch",
"name": "Host: Build and Debug",
"name": "Host: Build & Debug",
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
"env": {
"ENU_LISTEN_ADDRESS": "0.0.0.0",
Expand Down Expand Up @@ -130,6 +130,25 @@
"clear": true // <-- this line
}
},
{
"type": "lldb",
"request": "launch",
"name": "Enu: Build & Debug",
"program": "${workspaceFolder}/vendor/godot/bin/godot.osx.opt.tools.arm64",
"windows": {
"program": "${workspaceFolder}/vendor/godot/bin/godot.windows.opt.tools.64"
},
"args": [],
"cwd": "${workspaceFolder}/app",
"preLaunchTask": "Build enu",
"initCommands": [
"script import shutil;sys.path.append(os.path.join(shutil.which('nim'), '../../tools/debug'))",
"command script import nimlldb"
],
"presentation": {
"clear": true // <-- this line
}
},
{
"type": "lldb",
"request": "launch",
Expand Down
18 changes: 18 additions & 0 deletions app/build_lhdg3w19jcxua/build_lhdg3w19jcxua.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "build_lhdg3w19jcxua",
"start_transform": {
"basis": [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0]
],
"origin": [-1.0, 0.0, -6.0]
},
"start_color": "black",
"edits": {
"build_lhdg3w19jcxua": [
[[1.0, 2.0, 1.0], [0, "blue"]],
[[0.0, 25.0, 0.0], [0, ""]]
]
}
}
12 changes: 7 additions & 5 deletions app/components/Settings.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
[node name="Settings" type="MarginContainer"]
margin_left = 20.0
margin_top = 20.0
margin_right = 76.0
margin_bottom = 58.0
margin_right = 894.0
margin_bottom = 541.0
theme = ExtResource( 1 )
script = ExtResource( 2 )

Expand Down Expand Up @@ -43,6 +43,8 @@ margin_right = 874.0
margin_bottom = 521.0
rect_clip_content = true
mouse_filter = 1
size_flags_horizontal = 0
size_flags_vertical = 0

[node name="MainContainer" type="MarginContainer" parent="Window"]
margin_left = 20.0
Expand Down Expand Up @@ -93,7 +95,7 @@ size_flags_horizontal = 3
size_flags_stretch_ratio = 0.51
text = "Level Name"

[node name="LineEdit" type="LineEdit" parent="Window/MainContainer/RowContainer/NewLevelContainer/HBoxContainer"]
[node name="LevelName" type="LineEdit" parent="Window/MainContainer/RowContainer/NewLevelContainer/HBoxContainer"]
margin_left = 398.0
margin_right = 1288.0
margin_bottom = 82.0
Expand Down Expand Up @@ -139,7 +141,7 @@ margin_right = 160.0
margin_bottom = 37.0
text = "Level"

[node name="Level" type="OptionButton" parent="Window/MainContainer/RowContainer/SettingsContainer"]
[node name="Levels" type="OptionButton" parent="Window/MainContainer/RowContainer/SettingsContainer"]
margin_left = 180.0
margin_right = 397.0
margin_bottom = 37.0
Expand All @@ -150,7 +152,7 @@ margin_right = 587.0
margin_bottom = 37.0
text = " Player Color"

[node name="PlayerColor" type="OptionButton" parent="Window/MainContainer/RowContainer/SettingsContainer"]
[node name="PlayerColors" type="OptionButton" parent="Window/MainContainer/RowContainer/SettingsContainer"]
margin_left = 607.0
margin_right = 824.0
margin_bottom = 37.0
Expand Down
30 changes: 5 additions & 25 deletions app/scenes/GUI.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=2]
[gd_scene load_steps=16 format=2]

[ext_resource path="res://components/Editor.tscn" type="PackedScene" id=1]
[ext_resource path="res://components/Console.tscn" type="PackedScene" id=2]
Expand All @@ -15,22 +15,6 @@

[sub_resource type="ButtonGroup" id=1]

[sub_resource type="StyleBoxFlat" id=6]
resource_local_to_scene = true
content_margin_left = 20.0
content_margin_right = 20.0
content_margin_top = 20.0
content_margin_bottom = 20.0
bg_color = Color( 0.0784314, 0.0117647, 0.113725, 1 )
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10

[sub_resource type="StyleBoxFlat" id=8]
bg_color = Color( 0.6, 0.6, 0.6, 0 )
draw_center = false
Expand Down Expand Up @@ -117,19 +101,15 @@ mouse_filter = 2
columns = 2

[node name="Label" type="Label" parent="CenterContainer"]
margin_right = 1042.0
margin_bottom = 521.0
margin_right = 1916.0
margin_bottom = 14.0
size_flags_horizontal = 3
size_flags_vertical = 1

[node name="Settings" parent="CenterContainer" instance=ExtResource( 12 )]
margin_left = 1046.0
margin_top = 0.0
margin_left = 1920.0
margin_right = 1920.0
margin_bottom = 521.0

[node name="Window" parent="CenterContainer/Settings" index="1"]
custom_styles/panel = SubResource( 6 )
margin_bottom = 0.0

[node name="LeftPanel" type="MarginContainer" parent="."]
anchor_right = 0.5
Expand Down
2 changes: 1 addition & 1 deletion app/themes/DarkTheme.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7917,7 +7917,7 @@ LineEdit/colors/cursor_color = Color( 0.772549, 0.772549, 0.772549, 1 )
LineEdit/colors/font_color = Color( 1, 1, 1, 1 )
LineEdit/colors/font_color_selected = Color( 1, 1, 1, 1 )
LineEdit/colors/font_color_uneditable = Color( 0.964706, 0.952941, 0.909804, 1 )
LineEdit/colors/read_only = Color( 0.964706, 0.952941, 0.909804, 1 )
LineEdit/colors/read_only = Color( 0.486275, 0.486275, 0.486275, 1 )
LineEdit/colors/selection_color = Color( 0.207843, 0, 0.321569, 1 )
LineEdit/fonts/font = SubResource( 2913 )
LineEdit/icons/clear = SubResource( 269 )
Expand Down
10 changes: 6 additions & 4 deletions src/controllers/script_controllers/host_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,14 @@ proc `open_sign=`(self: Unit, value: Sign) =
# World bindings

proc environment(_: PNode): string =
state.config.environment
if ?state.config.environment_override:
state.config.environment_override
else:
state.config.environment

proc `environment=`(_: PNode, mode: string) =
state.config_value.value:
environment = mode
environment_override = mode

proc megapixels(_: PNode): float =
state.config.megapixels
Expand Down Expand Up @@ -599,8 +602,7 @@ proc bridge_to_vm*(worker: Worker) =

result.bridged_from_vm "players",
playing, `playing=`, god, `god=`, flying, `flying=`, tool, `tool=`, coding,
`coding=`, running, `running=`, open_sign, `open_sign=`, environment,
`environment=`
`coding=`, running, `running=`, open_sign, `open_sign=`

result.bridged_from_vm "worlds",
environment, `environment=`, megapixels, `megapixels=`
2 changes: 1 addition & 1 deletion src/controllers/script_controllers/scripting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc script_error*(self: Worker, unit: Unit, e: ref VMQuit) =
var msg = e.msg
if ?e.parent:
msg = e.parent.msg
logger("err", \"[color=#FF0000][url=unit://{unit.id}]{msg}[/url][/color]")
state.err(\"[url=unit://{unit.id}]{msg}[/url]")
unit.local_flags += HighlightError
unit.global_flags -= ScriptInitializing
unit.ensure_visible
Expand Down
23 changes: 16 additions & 7 deletions src/controllers/script_controllers/worker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
worker.init_interpreter("")
worker.bridge_to_vm

if Server in state.local_flags:
let load_level = proc() =
var level_dir = state.config.level_dir
player.script_ctx.interpreter = worker.interpreter
worker.load_script_and_dependents(player)
Expand All @@ -244,21 +244,30 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
level_dir = change.item.level_dir
if level_dir != "":
worker.load_level(level_dir)

if Server in state.local_flags:
load_level()
else:
var timeout_at = get_mono_time() + 30.seconds
var timeout_at = get_mono_time() + 10.seconds
var connected = false
while not connected and get_mono_time() < timeout_at:
try:
Zen.thread_ctx.subscribe(connect_address)
connected = true
except ConnectionError:
discard
if not connected:
fail \"Unable to connect to server at {connect_address}"

state.pop_flag(Connecting)
state.units.add player
player.script_ctx.interpreter = worker.interpreter
worker.load_script_and_dependents(player)
if not connected:
state.err \"Unable to connect to server at {connect_address}"
state.config_value.value:
connect_address = ""
state.push_flag Server
load_level()
else:
worker.load_script_and_dependents(player)

var sign = Sign.init(
"",
Expand All @@ -277,6 +286,8 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
sign.local_flags += Hide

var running = true
if NeedsRestart in state.local_flags:
running = false

state.local_flags.changes:
if Quitting.added:
Expand All @@ -286,12 +297,10 @@ proc worker_thread(params: (ZenContext, GameState)) {.gcsafe.} =
elif NeedsRestart.added:
running = false

# var user_config = UserConfig.init()
state.config_value.changes:
if added:
let uc = state.config.build_user_config
save_user_config(uc)
# for field in

const max_time = (1.0 / 120.0).seconds
const min_time = (1.0 / 120.0).seconds
Expand Down
1 change: 1 addition & 0 deletions src/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export utils, sequtils, strutils, sugar, importutils

const enu_version* = static_exec("git describe --tags HEAD")
var state* {.threadvar.}: GameState
var saved_state* {.threadvar.}: SavedState
const animation_duration* = 0.3

### Sugar ###
Expand Down
64 changes: 33 additions & 31 deletions src/game.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ const savable_flags = {
ConsoleVisible, MouseCaptured, Flying, God, AltWalkSpeed, AltFlySpeed
}

type SavedState = object
transform: Transform
rotation: float
flags: set[LocalStateFlags]
restarting: bool
connect_address: string

var saved_state {.threadvar.}: SavedState
var environment_cache {.threadvar.}: Table[string, Environment]

gdobj Game of Node:
Expand Down Expand Up @@ -95,6 +87,7 @@ gdobj Game of Node:
state.push_flag SceneReady

proc rescale*() =
warn "rescale", config = state.config
let vp = self.get_viewport().size
let megapixels =
if ?state.config.megapixels_override:
Expand All @@ -107,9 +100,7 @@ gdobj Game of Node:
self.scaled_viewport.get_texture.flags =
if megapixels >= 1.0: FLAG_FILTER else: 0

echo \"full screen: {is_window_fullscreen()} maximizied: {is_window_maximized()}"

logger("info", \"Rescaled to {self.scaled_viewport.size}")
info "Rescaled viewport", size = self.scaled_viewport.size

method notification*(what: int) =
if what == main_loop.NOTIFICATION_WM_QUIT_REQUEST:
Expand Down Expand Up @@ -215,7 +206,8 @@ gdobj Game of Node:
mouse_sensitivity = uc.mouse_sensitivity ||= 5.0
gamepad_sensitivity = uc.gamepad_sensitivity ||= 2.5
invert_gamepad_y_axis = uc.invert_gamepad_y_axis ||= false
environment = "default"
environment = uc.environment ||= "default"
megapixels_override = environments[value.environment]

state.set_flag(God, uc.god_mode ||= false)

Expand Down Expand Up @@ -291,6 +283,25 @@ gdobj Game of Node:
else:
warn "Couldn't focus control", name

method load_environment(environment: string) =
let env =
state.nodes.game.find_node("Level").get_node("WorldEnvironment") as
WorldEnvironment
if environment notin environment_cache:
let res = \"res://environments/{environment}.tres"

var environment_res: Environment = nil
if environment != "none":
environment_res = load(res) as Environment
if not ?environment_res:
logger("err", \"Environment {environment} not found")
return
environment_cache[environment] = environment_res
env.environment = environment_cache[environment]
state.config_value.value:
megapixels_override = environments[environment]
info "Changed game mode", environment

method ready*() =
state.nodes.data = state.nodes.game.find_node("Level").get_node("data")
assert not state.nodes.data.is_nil
Expand All @@ -301,33 +312,24 @@ gdobj Game of Node:
self.bind_signals(self.get_tree(), "global_menu_action")
assert not self.scaled_viewport.is_nil
self.get_tree().auto_accept_quit = false
self.set_font_size state.config.font_size

self.set_font_size(state.config.font_size)
self.load_environment(state.config.environment)
info "config", config = state.config
self.reticle = self.find_node("Reticle").as(Control)
self.stats = self.find_node("stats").as(Label)
self.stats.visible = state.config.show_stats

state.config_value.changes:
if change.item.full_screen != state.config.full_screen:
set_window_fullscreen state.config.full_screen
if change.item.environment != state.config.environment:
if change.item.environment != state.config.environment or
change.item.environment_override != state.config.environment_override:
let env =
state.nodes.game.find_node("Level").get_node("WorldEnvironment") as
WorldEnvironment
if state.config.environment notin environment_cache:
let res = \"res://environments/{state.config.environment}.tres"

var environment: Environment = nil
if state.config.environment != "none":
environment = load(res) as Environment
if not ?environment:
logger("err", \"Environment {state.config.environment} not found")
return
environment_cache[state.config.environment] = environment
env.environment = environment_cache[state.config.environment]
state.config_value.value:
megapixels_override = environments[state.config.environment]
logger("info", \"Changed game mode to {state.config.environment}")
if ?state.config.environment_override:
state.config.environment_override
else:
state.config.environment
self.load_environment(env)

if change.item.megapixels != state.config.megapixels:
state.config_value.value:
Expand Down
Loading

0 comments on commit 7f0ce29

Please sign in to comment.