diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-11-13 00:53:12 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-11-13 00:53:12 -0300 |
commit | abbea4d945bbb1114570c3b6c7f649e01ca8ebb8 (patch) | |
tree | d2b131b32705bbcf118efa72d5d9a21618c1227e /demos | |
parent | d02953c5963ca080d26500ea8250e0632a80b234 (diff) |
UDP Fixes
-=-=-=-=-
Curse the day I decided to port UDP code, as it ended up
being two nights of work. At least It's done now (I hope).
-Fixed UDP Support, API seems stable
-Added UDP Chat demo (chat that can lose your packets, heh)
-Added helpers to areas and bodies to get list of collided bodies and contained bodies.
-Sped up screen/viewport capture code.
-Added code to save an image as PNG
-Small fix so scripts register their singletons after modules did.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/misc/udp_chat/chat.gd | 72 | ||||
-rw-r--r-- | demos/misc/udp_chat/chat.scn | bin | 0 -> 3198 bytes | |||
-rw-r--r-- | demos/misc/udp_chat/engine.cfg | 5 | ||||
-rw-r--r-- | demos/misc/udp_chat/icon.png | bin | 0 -> 2388 bytes |
4 files changed, 77 insertions, 0 deletions
diff --git a/demos/misc/udp_chat/chat.gd b/demos/misc/udp_chat/chat.gd new file mode 100644 index 0000000000..3270eebbfe --- /dev/null +++ b/demos/misc/udp_chat/chat.gd @@ -0,0 +1,72 @@ + +extends Panel + +# Really simple UDP chat client, not intended as a chat example!! +# (UDP can lose packets and you won't normally find out, so don't do a chat this way) +# This is just a demo that shows how to use the UDP class. + +var udp = PacketPeerUDP.new() + +func _process(delta): + + if (not udp.is_listening()): + return + + while(udp.get_available_packet_count()>0): + var packet = udp.get_var() + if (typeof(packet)==TYPE_STRING): + var host = udp.get_packet_ip() + var port = udp.get_packet_port() + get_node("chat/text").add_text("("+host+":"+str(port)+":) "+packet) + get_node("chat/text").newline() + + + +func _ready(): + # Initalization here + get_node("chat").add_style_override("panel",get_stylebox("bg","Tree")) + set_process(true) + + + +func send_message(text): + if (udp.is_listening()): + udp.put_var(text) + + +func _on_connect_toggled( pressed ): + + + if (pressed): + var err = udp.listen( get_node("listen_port").get_val() ) + if (err!=OK): + get_node("status").set_text("Error:\nCan't Listen.") + get_node("connect").set_pressed(false) + else: + get_node("status").set_text("Connected.") + get_node("connect").set_text("Disconnect") + err = udp.set_send_address(get_node("remote_host").get_text(),get_node("remote_port").get_val()) + if (err!=OK): + get_node("status").set_text("Error:\nCan't Resolve.") + get_node("connect").set_pressed(false) + else: + send_message("* "+get_node("user_name").get_text()+" entered chat.") + else: + + udp.close() + get_node("status").set_text("Disconnected.") + get_node("connect").set_text("Connect") + + + + +func _on_entry_line_text_entered( text ): + _on_entry_button_pressed(); + +func _on_entry_button_pressed(): + var msg = get_node("entry_line").get_text() + if (msg==""): + return + send_message(get_node("user_name").get_text()+"> "+msg) + + get_node("entry_line").set_text("") diff --git a/demos/misc/udp_chat/chat.scn b/demos/misc/udp_chat/chat.scn Binary files differnew file mode 100644 index 0000000000..efa4b799a0 --- /dev/null +++ b/demos/misc/udp_chat/chat.scn diff --git a/demos/misc/udp_chat/engine.cfg b/demos/misc/udp_chat/engine.cfg new file mode 100644 index 0000000000..584841ea83 --- /dev/null +++ b/demos/misc/udp_chat/engine.cfg @@ -0,0 +1,5 @@ +[application] + +name="UDP Chat" +main_scene="res://chat.scn" +icon="res://icon.png" diff --git a/demos/misc/udp_chat/icon.png b/demos/misc/udp_chat/icon.png Binary files differnew file mode 100644 index 0000000000..db6e21cce1 --- /dev/null +++ b/demos/misc/udp_chat/icon.png |