* observer scene for the demo
This commit is contained in:
parent
94d94a0855
commit
2204914abf
3 changed files with 176 additions and 0 deletions
78
demos/misc/window_management/observer/observer.gd
Normal file
78
demos/misc/window_management/observer/observer.gd
Normal file
|
@ -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
|
BIN
demos/misc/window_management/observer/observer.scn
Normal file
BIN
demos/misc/window_management/observer/observer.scn
Normal file
Binary file not shown.
98
demos/misc/window_management/observer/observer_hud.gd
Normal file
98
demos/misc/window_management/observer/observer_hud.gd
Normal file
|
@ -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()
|
Loading…
Reference in a new issue