Skip to content

Commit

Permalink
Fixed quadtree demo, disabled collisions for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoimar committed Jul 26, 2023
1 parent 5555a13 commit a6626b9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ noise_generators = [SubResource("1")]

[resource]
script = ExtResource("1")
resolution = 100
resolution = 10
radius = 100.0
has_water = false
has_atmosphere = false
Expand Down
2 changes: 1 addition & 1 deletion addons/hoimar.planetgen/scripts/constants.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Defines some constants for the quadtree and terrain patches.

const COLLISIONS_ENABLED := true # Whether planets generate collision shapes.
const COLLISIONS_ENABLED := false # Whether planets generate collision shapes.
const GRAVITY_ENABLED := true # TODO: Implement gravity.
const THREADS_ENABLED := true

Expand Down
15 changes: 11 additions & 4 deletions addons/hoimar.planetgen/scripts/gui/gui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ extends Node
@onready var lbl_status := $Root/MarginContainer/HBoxContainer/LabelStatus
@onready var lbl_speedscale := $Root/MarginContainer/HBoxContainer/Control/LabelSpeedScale
@onready var slider_speedscale := $Root/MarginContainer/HBoxContainer/Control/HSlider
@onready var ship : Node3D = get_tree().get_nodes_in_group("player")[0]
var ship : Node3D


func _ready():
ship.connect("speed_scale_changed", Callable(self, "update_speed_scale"))
var player_nodes = get_tree().get_nodes_in_group("player")
if player_nodes.size() > 0:
ship = player_nodes[0]
ship.connect("speed_scale_changed", Callable(self, "update_speed_scale"))


func _process(_delta):
Expand Down Expand Up @@ -42,9 +45,13 @@ func check_input():


func _on_HSlider_value_changed(value):
lbl_speedscale.text = str(value)
ship.speed_scale = value
update_speed_scale(value)
if ship:
ship.speed_scale = value


func update_speed_scale(value):
lbl_speedscale.text = str(value)
slider_speedscale.value = value
PGGlobals.speed_scale = value

3 changes: 2 additions & 1 deletion addons/hoimar.planetgen/scripts/terrain/terrain_patch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func _process(_delta):


func _notification(what):
if what == NOTIFICATION_TRANSFORM_CHANGED:
if Const.COLLISIONS_ENABLED and what == NOTIFICATION_TRANSFORM_CHANGED:
update_transform() # Manually update physics shape position.


Expand Down Expand Up @@ -127,6 +127,7 @@ func init_physics():


func update_transform():
print(_body_rid)
var transform: Transform3D = data.settings._planet.global_transform
PhysicsServer3D.body_set_state(_body_rid, PhysicsServer3D.BODY_STATE_TRANSFORM,
transform)
Expand Down
1 change: 1 addition & 0 deletions addons/hoimar.planetgen/scripts/utils/pg_globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var colored_patches: bool # Colors patches of terrain randomly.
var benchmark_mode: bool # re-generates planets even if there are still active threads.
var solar_systems: Array = []
var job_queue := JobQueue.new() # Global queue for TerrainJobs.
var speed_scale: float = 0.001


func _ready():
Expand Down
7 changes: 4 additions & 3 deletions demos/quadtree_terrain_demo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ extends Node3D


@export var _play_in_editor: bool = true: set = set_play_in_editor
@export var _rotation_speed: float = 0.2
@export var _rotation_speed: float = 200
@onready var _view_position_rig := $ViewPositionRig
@onready var _view_position := $ViewPositionRig/ViewPosition
@onready var _planet := $TestPlanet
@onready var _planet := $SolarSystem/TestPlanet


func _ready():
PGGlobals.wireframe = true
#PGGlobals.colored_patches = true
_planet._terrain.set_viewer(_view_position)


func _process(delta):
if Engine.is_editor_hint() and not _play_in_editor:
return
_view_position_rig.rotate_y(_rotation_speed*delta)
_view_position_rig.rotate_y(_rotation_speed * PGGlobals.speed_scale * delta)


func set_play_in_editor(new: bool):
Expand Down
12 changes: 8 additions & 4 deletions demos/quadtree_terrain_demo.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://cv3jth7u5rno3"]
[gd_scene load_steps=12 format=3 uid="uid://cv3jth7u5rno3"]

[ext_resource type="Script" path="res://demos/quadtree_terrain_demo.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://btubuuiux53j4" path="res://addons/hoimar.planetgen/scenes/gui/gui.tscn" id="2"]
[ext_resource type="Script" path="res://addons/hoimar.planetgen/scripts/celestial_bodies/solar_system.gd" id="3_hi6yo"]
[ext_resource type="PackedScene" uid="uid://dtmgyl1uf7auy" path="res://addons/hoimar.planetgen/scenes/celestial_bodies/planet.tscn" id="4"]
[ext_resource type="Resource" uid="uid://kono1hjgsisy" path="res://addons/hoimar.planetgen/planet_presets/test_planet_settings.tres" id="6"]

Expand Down Expand Up @@ -32,16 +33,19 @@ glow_blend_mode = 1
[node name="QuadTreeTerrainDemo" type="Node3D"]
script = ExtResource("1")
_play_in_editor = false
_rotation_speed = 0.1

[node name="Gui" parent="." instance=ExtResource("2")]

[node name="TestPlanet" parent="." instance=ExtResource("4")]
[node name="SolarSystem" type="Node3D" parent="."]
script = ExtResource("3_hi6yo")

[node name="TestPlanet" parent="SolarSystem" instance=ExtResource("4")]
settings = ExtResource("6")
material = SubResource("3")
solar_system_path = NodePath("..")

[node name="ViewPositionRig" type="Node3D" parent="."]
transform = Transform3D(1.00011, 0, 0, 0, 1, 0, 0, 0, 1.00011, 0, 0, 0)
transform = Transform3D(-0.786847, 0, -0.6176, 0, 1, 0, 0.6176, 0, -0.786847, 0, 0, 0)

[node name="ViewPosition" type="MeshInstance3D" parent="ViewPositionRig"]
transform = Transform3D(1, 0, 0, 0, 1, 0, -1.42109e-14, 0, 1, -105, 0, 0)
Expand Down

0 comments on commit a6626b9

Please sign in to comment.