Connect gdproject to vm
This commit is contained in:
16
memory_entry.tscn
Normal file
16
memory_entry.tscn
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[gd_scene format=3 uid="uid://dqwi5rekytyds"]
|
||||||
|
|
||||||
|
[node name="memory_entry" type="HBoxContainer"]
|
||||||
|
|
||||||
|
[node name="address" type="Label" parent="."]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "/0 = "
|
||||||
|
|
||||||
|
[node name="value" type="SpinBox" parent="."]
|
||||||
|
layout_mode = 2
|
||||||
|
value = 4.0
|
||||||
|
rounded = true
|
||||||
|
allow_greater = true
|
||||||
|
allow_lesser = true
|
||||||
|
alignment = 1
|
||||||
|
editable = false
|
||||||
54
scenes/code_runner.gd
Normal file
54
scenes/code_runner.gd
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
@onready var code_editor := $%Code as CodeEdit
|
||||||
|
@onready var memory := $%Memory as VBoxContainer
|
||||||
|
@onready var memory_entry := load("res://memory_entry.tscn") as PackedScene
|
||||||
|
var cobor_vm := CoborVirtualMachine.new()
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
cobor_vm.set_registers(8,[])
|
||||||
|
for i in range(8):
|
||||||
|
var entry := memory_entry.instantiate() as Control
|
||||||
|
(entry.get_node("address") as Label).text = "/" + str(i) + " = "
|
||||||
|
(entry.get_node("value") as SpinBox).value = 0
|
||||||
|
memory.add_child(entry)
|
||||||
|
|
||||||
|
func _tick() -> void:
|
||||||
|
if code_editor.editable: return
|
||||||
|
for line in code_editor.get_executing_lines():
|
||||||
|
code_editor.set_line_as_executing(line, false)
|
||||||
|
code_editor.set_line_as_executing(cobor_vm.get_program_counter(), true)
|
||||||
|
var err := cobor_vm.run_step()
|
||||||
|
if not err.is_empty():
|
||||||
|
print(err);
|
||||||
|
var registers := cobor_vm.get_registers()
|
||||||
|
for i in range(8):
|
||||||
|
var entry := memory.get_child(i) as Control
|
||||||
|
(entry.get_node("value") as SpinBox).value = registers[i]
|
||||||
|
|
||||||
|
func _on_compile_button_pressed() -> void:
|
||||||
|
var text := code_editor.text
|
||||||
|
var errors := cobor_vm.parse_source_code(text)
|
||||||
|
if errors.is_empty():
|
||||||
|
print("Compiling Ok!")
|
||||||
|
else:
|
||||||
|
for error in errors:
|
||||||
|
print(error)
|
||||||
|
|
||||||
|
func _on_stop_button_pressed() -> void:
|
||||||
|
code_editor.editable = true
|
||||||
|
$Timer.stop()
|
||||||
|
cobor_vm.set_registers(8,[])
|
||||||
|
|
||||||
|
func _on_play_button_pressed() -> void:
|
||||||
|
code_editor.editable = false
|
||||||
|
_on_compile_button_pressed();
|
||||||
|
$Timer.start()
|
||||||
|
|
||||||
|
func _on_pause_button_pressed() -> void:
|
||||||
|
$Timer.stop()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_step_button_pressed() -> void:
|
||||||
|
code_editor.editable = false
|
||||||
|
_tick()
|
||||||
1
scenes/code_runner.gd.uid
Normal file
1
scenes/code_runner.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://brnfd6h7eh0n7
|
||||||
123
scenes/main.tscn
123
scenes/main.tscn
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=11 format=3 uid="uid://7q00x01xdsal"]
|
[gd_scene load_steps=12 format=3 uid="uid://7q00x01xdsal"]
|
||||||
|
|
||||||
[ext_resource type="VoxelBlockyLibrary" uid="uid://bsue4rd3wdfsl" path="res://BlockLibrary.tres" id="1_0wfyh"]
|
[ext_resource type="VoxelBlockyLibrary" uid="uid://bsue4rd3wdfsl" path="res://BlockLibrary.tres" id="1_0wfyh"]
|
||||||
[ext_resource type="Material" uid="uid://de6s8en5fcyyw" path="res://BlockMaterial.tres" id="1_o5qli"]
|
[ext_resource type="Material" uid="uid://de6s8en5fcyyw" path="res://BlockMaterial.tres" id="1_o5qli"]
|
||||||
|
[ext_resource type="Script" uid="uid://brnfd6h7eh0n7" path="res://scenes/code_runner.gd" id="1_sugp2"]
|
||||||
|
|
||||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_o5qli"]
|
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_o5qli"]
|
||||||
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
|
||||||
@@ -32,34 +33,19 @@ noise = SubResource("FastNoiseLite_sgp6g")
|
|||||||
library = ExtResource("1_0wfyh")
|
library = ExtResource("1_0wfyh")
|
||||||
|
|
||||||
[node name="Main" type="Node"]
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource("1_sugp2")
|
||||||
|
|
||||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
environment = SubResource("Environment_sugp2")
|
|
||||||
|
|
||||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
|
||||||
transform = Transform3D(-0.866023, -0.433016, 0.250001, 0, 0.499998, 0.866027, -0.500003, 0.749999, -0.43301, 0, 0, 0)
|
|
||||||
shadow_enabled = true
|
|
||||||
|
|
||||||
[node name="Robot" type="Node3D" parent="."]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.5, 14, 2.5)
|
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Robot"]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
|
||||||
mesh = SubResource("BoxMesh_o5qli")
|
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="Robot"]
|
|
||||||
transform = Transform3D(-0.996038, -0.0493504, 0.0739856, 0, 0.831912, 0.554908, -0.0889344, 0.552709, -0.828616, 0.617269, 2.49481, -3.59337)
|
|
||||||
|
|
||||||
[node name="VoxelViewer" type="VoxelViewer" parent="Robot/Camera3D"]
|
|
||||||
|
|
||||||
[node name="Control" type="PanelContainer" parent="."]
|
[node name="Control" type="PanelContainer" parent="."]
|
||||||
anchors_preset = 9
|
anchors_preset = 9
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_right = 227.0
|
offset_right = 314.0
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="Control"]
|
[node name="VBoxContainer" type="VBoxContainer" parent="Control"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Control/VBoxContainer"]
|
[node name="Label" type="Label" parent="Control/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@@ -77,74 +63,70 @@ layout_mode = 2
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = " Source Code "
|
text = " Source Code "
|
||||||
|
|
||||||
[node name="CodeEdit" type="CodeEdit" parent="Control/VBoxContainer/HBoxContainer/VBoxContainer"]
|
[node name="Code" type="CodeEdit" parent="Control/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(200, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
text = "Move #1 0
|
text = "Set 1 /2
|
||||||
|
Cpy /2 /3
|
||||||
|
Add /2 /3 /3
|
||||||
|
|
||||||
"
|
"
|
||||||
|
placeholder_text = "Code here"
|
||||||
|
symbol_tooltip_on_hover = true
|
||||||
|
line_length_guidelines = Array[int]([5, 7, 9, 11])
|
||||||
|
gutters_draw_executing_lines = true
|
||||||
|
gutters_draw_line_numbers = true
|
||||||
|
gutters_zero_pad_line_numbers = true
|
||||||
|
|
||||||
[node name="ItemList" type="VBoxContainer" parent="Control/VBoxContainer/HBoxContainer"]
|
[node name="Memory" type="VBoxContainer" parent="Control/VBoxContainer/HBoxContainer"]
|
||||||
layout_mode = 2
|
unique_name_in_owner = true
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="Control/VBoxContainer/HBoxContainer/ItemList"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "#0"
|
|
||||||
|
|
||||||
[node name="SpinBox" type="SpinBox" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Control/VBoxContainer/HBoxContainer/ItemList"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer2"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "#1"
|
|
||||||
|
|
||||||
[node name="SpinBox" type="SpinBox" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer2"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="HBoxContainer3" type="HBoxContainer" parent="Control/VBoxContainer/HBoxContainer/ItemList"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer3"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "#2"
|
|
||||||
|
|
||||||
[node name="SpinBox" type="SpinBox" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer3"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="HBoxContainer4" type="HBoxContainer" parent="Control/VBoxContainer/HBoxContainer/ItemList"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer4"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "#3"
|
|
||||||
|
|
||||||
[node name="SpinBox" type="SpinBox" parent="Control/VBoxContainer/HBoxContainer/ItemList/HBoxContainer4"]
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Control/VBoxContainer"]
|
[node name="HBoxContainer2" type="HBoxContainer" parent="Control/VBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 10
|
||||||
alignment = 1
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="compileButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "[C]"
|
||||||
|
|
||||||
[node name="StopButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
[node name="StopButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Stop"
|
text = "[ ]"
|
||||||
|
|
||||||
[node name="PlayButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
[node name="PlayButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Play"
|
text = ">"
|
||||||
|
|
||||||
[node name="PauseButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
[node name="PauseButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Pause"
|
text = "||"
|
||||||
|
|
||||||
[node name="StepButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
[node name="StepButton" type="Button" parent="Control/VBoxContainer/HBoxContainer2"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Step"
|
text = ">|"
|
||||||
|
|
||||||
|
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||||
|
environment = SubResource("Environment_sugp2")
|
||||||
|
|
||||||
|
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||||
|
transform = Transform3D(-0.866024, -0.433016, 0.250001, 0, 0.499998, 0.866026, -0.500003, 0.749999, -0.43301, 0, 0, 0)
|
||||||
|
shadow_enabled = true
|
||||||
|
|
||||||
|
[node name="Robot" type="Node3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.5, 14, 2.5)
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="Robot"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
mesh = SubResource("BoxMesh_o5qli")
|
||||||
|
|
||||||
|
[node name="Camera3D" type="Camera3D" parent="Robot"]
|
||||||
|
transform = Transform3D(-0.996038, -0.0493504, 0.0739856, 0, 0.831912, 0.554908, -0.0889344, 0.552709, -0.828616, 0.617269, 2.49481, -3.59337)
|
||||||
|
|
||||||
|
[node name="VoxelViewer" type="VoxelViewer" parent="Robot/Camera3D"]
|
||||||
|
|
||||||
[node name="VoxelTerrain" type="VoxelTerrain" parent="."]
|
[node name="VoxelTerrain" type="VoxelTerrain" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0)
|
||||||
@@ -152,3 +134,10 @@ generator = SubResource("VoxelGeneratorNoise2D_o5qli")
|
|||||||
mesher = SubResource("VoxelMesherBlocky_tefeu")
|
mesher = SubResource("VoxelMesherBlocky_tefeu")
|
||||||
bounds = AABB(-1040, -32, -1040, 2080, 96, 2080)
|
bounds = AABB(-1040, -32, -1040, 2080, 96, 2080)
|
||||||
material_override = ExtResource("1_o5qli")
|
material_override = ExtResource("1_o5qli")
|
||||||
|
|
||||||
|
[connection signal="timeout" from="Timer" to="." method="_tick"]
|
||||||
|
[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer2/compileButton" to="." method="_on_compile_button_pressed"]
|
||||||
|
[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer2/StopButton" to="." method="_on_stop_button_pressed"]
|
||||||
|
[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer2/PlayButton" to="." method="_on_play_button_pressed"]
|
||||||
|
[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer2/PauseButton" to="." method="_on_pause_button_pressed"]
|
||||||
|
[connection signal="pressed" from="Control/VBoxContainer/HBoxContainer2/StepButton" to="." method="_on_step_button_pressed"]
|
||||||
|
|||||||
Reference in New Issue
Block a user