summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demos/misc/window_management/observer/observer.gd78
-rw-r--r--demos/misc/window_management/observer/observer.scnbin0 -> 1786 bytes
-rw-r--r--demos/misc/window_management/observer/observer_hud.gd98
3 files changed, 176 insertions, 0 deletions
diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd
new file mode 100644
index 0000000000..7bec0f5301
--- /dev/null
+++ b/demos/misc/window_management/observer/observer.gd
@@ -0,0 +1,78 @@
+
+extends Spatial
+
+var r_pos = Vector2()
+var state
+
+const STATE_MENU=0
+const STATE_GRAB=1
+
+func direction(vector):
+ var v = get_node("Camera").get_global_transform().basis * vector
+ v = v.normalized()
+
+ return v
+
+
+func impulse(event, action):
+ if(event.is_action(action) && event.is_pressed() && !event.is_echo()):
+ return true
+ else:
+ return false
+
+
+func _fixed_process(delta):
+
+ if(state != STATE_GRAB):
+ return
+
+ if(Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED):
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+
+ var dir = Vector3()
+ var cam = get_global_transform()
+ var org = get_translation()
+
+ if (Input.is_action_pressed("move_forward")):
+ dir += direction(Vector3(0,0,-1))
+ if (Input.is_action_pressed("move_backwards")):
+ dir += direction(Vector3(0,0,1))
+ if (Input.is_action_pressed("move_left")):
+ dir += direction(Vector3(-1,0,0))
+ if (Input.is_action_pressed("move_right")):
+ dir += direction(Vector3(1,0,0))
+
+ dir = dir.normalized()
+
+ move(dir * 10 * delta)
+ var d = delta * 0.1
+
+ var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x)
+ set_transform(yaw)
+
+ var cam = get_node("Camera")
+ var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y)
+ cam.set_transform(pitch)
+
+ r_pos.x = 0.0
+ r_pos.y = 0.0
+
+
+func _input( event ):
+ if(event.type == InputEvent.MOUSE_MOTION):
+ r_pos = event.relative_pos
+
+ if(impulse(event, "ui_cancel")):
+ if(state == STATE_GRAB):
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ state = STATE_MENU
+ else:
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+ state = STATE_GRAB
+
+
+func _ready():
+ set_fixed_process(true)
+ set_process_input(true)
+
+ state = STATE_MENU
diff --git a/demos/misc/window_management/observer/observer.scn b/demos/misc/window_management/observer/observer.scn
new file mode 100644
index 0000000000..da29ad62b8
--- /dev/null
+++ b/demos/misc/window_management/observer/observer.scn
Binary files differ
diff --git a/demos/misc/window_management/observer/observer_hud.gd b/demos/misc/window_management/observer/observer_hud.gd
new file mode 100644
index 0000000000..24e81b02ba
--- /dev/null
+++ b/demos/misc/window_management/observer/observer_hud.gd
@@ -0,0 +1,98 @@
+var parent
+
+func printdebug():
+
+ var s
+
+ if(parent.state == parent.STATE_GAME):
+ s = str( "TIME_FPS: ", Performance.get_monitor(Performance.TIME_FPS), "\n")
+ s += str("OBJECT_COUNT: ", Performance.get_monitor(Performance.OBJECT_COUNT), "\n")
+ s += str("OBJECT_RESOURCE_COUNT : ", Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT), "\n")
+ s += str("OBJECT_NODE_COUNT : ", Performance.get_monitor(Performance.OBJECT_NODE_COUNT), "\n")
+ s += str("RENDER_OBJECTS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_OBJECTS_IN_FRAME), "\n")
+ s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n")
+ s += str("RENDER_DRAW_CALLS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_DRAW_CALLS_IN_FRAME), "\n")
+ s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n")
+ # s += str("RENDER_USAGE_VIDEO_MEM_TOTAL : ", Performance.get_monitor(Performance.RENDER_USAGE_VIDEO_MEM_TOTAL), "\n")
+ # s += str("RENDER_VIDEO_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED), "\n")
+ # s += str("RENDER_TEXTURE_MEM_USED : ", Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED), "\n")
+ # s += str("RENDER_VERTEX_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VERTEX_MEM_USED), "\n")
+ s += str("CUBES: ", get_node("/root/World").world.size(), "\n")
+ else:
+ s = ""
+
+ get_node("Label_Debug").set_text(s)
+
+
+func _fixed_process(delta):
+ parent = get_parent()
+
+ printdebug()
+
+ if( parent.state == parent.STATE_MENU ):
+ get_node("Menu").show()
+ else:
+ get_node("Menu").hide()
+
+
+
+func _ready():
+ set_fixed_process(true)
+
+
+func _on_Fullscreen_toggled( pressed ):
+ if( pressed ):
+ OS.set_fullscreen(true)
+ else:
+ OS.set_fullscreen(false)
+
+
+func _on_DebugInfo_toggled( pressed ):
+ if( pressed ):
+ get_node("Label_Debug").show()
+ else:
+ get_node("Label_Debug").hide()
+
+
+func _on_Save_pressed():
+ var file_dialog = get_node("Menu/SaveDialog")
+ file_dialog.clear_filters()
+ file_dialog.add_filter("*.json")
+ file_dialog.set_mode(3)
+ file_dialog.show()
+ file_dialog._update_file_list()
+
+
+func _on_SaveDialog_file_selected( path ):
+ get_node("/root/World").save_world( path )
+
+
+func _on_Load_pressed():
+ var file_dialog = get_node("Menu/LoadDialog")
+ file_dialog.clear_filters()
+ file_dialog.add_filter("*.json")
+ file_dialog.set_mode(0)
+ file_dialog.show()
+ file_dialog._update_file_list()
+
+
+func _on_LoadDialog_file_selected( path ):
+ get_node("/root/World").load_world( path )
+
+
+func _on_Server_toggled( pressed ):
+ if pressed:
+ get_node("/root/World/Server").start()
+ get_node("Menu/Client").hide()
+ else:
+ get_node("/root/World/Server").stop()
+ get_node("Menu/Client").show()
+
+
+func _on_Client_toggled( pressed ):
+ if pressed:
+ get_node("/root/World/Client").start()
+ get_node("Menu/Server").hide()
+ else:
+ get_node("/root/World/Client").stop()
+ get_node("Menu/Server").show() \ No newline at end of file