Pre-stream commit.
This commit is contained in:
parent
4cad6a574f
commit
53e4be0439
@ -144,39 +144,37 @@ func stop():
|
|||||||
func is_running():
|
func is_running():
|
||||||
return not (_worker_thread == null)
|
return not (_worker_thread == null)
|
||||||
|
|
||||||
func _normal_communication_loop(sock : StreamPeer, address):
|
func _normal_communication_loop_iteration(sock : StreamPeer, address):
|
||||||
|
|
||||||
while not _should_quit:
|
if sock.poll() != OK:
|
||||||
|
return FAILED
|
||||||
|
|
||||||
if sock.poll() != OK:
|
if sock.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||||
break
|
return FAILED
|
||||||
|
|
||||||
if sock.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
# Get new data.
|
||||||
break
|
_state_lock.lock()
|
||||||
|
var available_bytes = sock.get_available_bytes()
|
||||||
|
if available_bytes > 0:
|
||||||
|
var incoming_bytes = sock.get_data(available_bytes)
|
||||||
|
_packet_buffer.add_bytes(PackedByteArray(incoming_bytes[1]))
|
||||||
|
if incoming_bytes[0] != OK:
|
||||||
|
return FAILED
|
||||||
|
_state_lock.unlock()
|
||||||
|
|
||||||
# Get new data.
|
# Send all packets from queue.
|
||||||
_state_lock.lock()
|
_state_lock.lock()
|
||||||
var available_bytes = sock.get_available_bytes()
|
while len(self._outgoing_packet_queue):
|
||||||
if available_bytes > 0:
|
var next_outgoing_packet = _outgoing_packet_queue.pop_front()
|
||||||
var incoming_bytes = sock.get_data(available_bytes)
|
var len_to_send = len(next_outgoing_packet)
|
||||||
_packet_buffer.add_bytes(PackedByteArray(incoming_bytes[1]))
|
sock.put_u8((len_to_send & 0x000000ff) >> 0)
|
||||||
if incoming_bytes[0] != OK:
|
sock.put_u8((len_to_send & 0x0000ff00) >> 8)
|
||||||
break
|
sock.put_u8((len_to_send & 0x00ff0000) >> 16)
|
||||||
_state_lock.unlock()
|
sock.put_u8((len_to_send & 0xff000000) >> 24)
|
||||||
|
sock.put_data(next_outgoing_packet)
|
||||||
|
_state_lock.unlock()
|
||||||
|
|
||||||
# Send all packets from queue.
|
return OK
|
||||||
_state_lock.lock()
|
|
||||||
while len(self._outgoing_packet_queue):
|
|
||||||
var next_outgoing_packet = _outgoing_packet_queue.pop_front()
|
|
||||||
var len_to_send = len(next_outgoing_packet)
|
|
||||||
sock.put_u8((len_to_send & 0x000000ff) >> 0)
|
|
||||||
sock.put_u8((len_to_send & 0x0000ff00) >> 8)
|
|
||||||
sock.put_u8((len_to_send & 0x00ff0000) >> 16)
|
|
||||||
sock.put_u8((len_to_send & 0xff000000) >> 24)
|
|
||||||
sock.put_data(next_outgoing_packet)
|
|
||||||
_state_lock.unlock()
|
|
||||||
|
|
||||||
OS.delay_usec(1)
|
|
||||||
|
|
||||||
func _client_thread_func(address):
|
func _client_thread_func(address):
|
||||||
|
|
||||||
@ -189,7 +187,11 @@ func _client_thread_func(address):
|
|||||||
if connect_err == OK:
|
if connect_err == OK:
|
||||||
_set_state(KiriSocketState.CONNECTED)
|
_set_state(KiriSocketState.CONNECTED)
|
||||||
|
|
||||||
_normal_communication_loop(sock, address)
|
while not _should_quit:
|
||||||
|
var err = _normal_communication_loop_iteration(sock, address)
|
||||||
|
if err != OK:
|
||||||
|
break
|
||||||
|
OS.delay_usec(1)
|
||||||
|
|
||||||
# We are now disconnected.
|
# We are now disconnected.
|
||||||
_set_state(KiriSocketState.DISCONNECTED)
|
_set_state(KiriSocketState.DISCONNECTED)
|
||||||
@ -214,7 +216,12 @@ func _set_state(state : KiriSocketState, error_string=null):
|
|||||||
func _server_to_client_thread_func(connection : StreamPeerTCP, address):
|
func _server_to_client_thread_func(connection : StreamPeerTCP, address):
|
||||||
|
|
||||||
_set_state(KiriSocketState.CONNECTED)
|
_set_state(KiriSocketState.CONNECTED)
|
||||||
_normal_communication_loop(connection, address)
|
|
||||||
|
while not _should_quit:
|
||||||
|
var err = _normal_communication_loop_iteration(connection, address)
|
||||||
|
if err != OK:
|
||||||
|
break
|
||||||
|
OS.delay_usec(1)
|
||||||
|
|
||||||
# FIXME: Missing some error handling here due to exception differences
|
# FIXME: Missing some error handling here due to exception differences
|
||||||
# between Python and GDScript.
|
# between Python and GDScript.
|
||||||
|
@ -4,7 +4,6 @@ import importlib.util
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
# import psutil
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import KiriPacketSocket
|
import KiriPacketSocket
|
||||||
@ -22,7 +21,6 @@ if True:
|
|||||||
|
|
||||||
arg_parser.add_argument("--script", type=str, required=True)
|
arg_parser.add_argument("--script", type=str, required=True)
|
||||||
arg_parser.add_argument("--port", type=int, required=True)
|
arg_parser.add_argument("--port", type=int, required=True)
|
||||||
arg_parser.add_argument("--parent_pid", type=int, required=True)
|
|
||||||
|
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
@ -103,11 +101,6 @@ if True:
|
|||||||
packet_socket.stop()
|
packet_socket.stop()
|
||||||
raise Exception("Disconnected from RPC host.")
|
raise Exception("Disconnected from RPC host.")
|
||||||
|
|
||||||
# # Watch parent PID so we can clean up when needed.
|
|
||||||
# if not psutil.pid_exists(args.parent_pid):
|
|
||||||
# packet_socket.stop()
|
|
||||||
# raise Exception("RPC host process died")
|
|
||||||
|
|
||||||
next_packet = packet_socket.get_next_packet()
|
next_packet = packet_socket.get_next_packet()
|
||||||
while next_packet:
|
while next_packet:
|
||||||
this_packet = next_packet
|
this_packet = next_packet
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
try:
|
|
||||||
import KiriPythonRPCWrapper
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
@ -125,8 +125,7 @@ func start_process():
|
|||||||
python_exe_path,
|
python_exe_path,
|
||||||
wrapper_script_path,
|
wrapper_script_path,
|
||||||
"--script", python_script_path,
|
"--script", python_script_path,
|
||||||
"--port", open_port,
|
"--port", open_port]
|
||||||
"--parent_pid", OS.get_process_id()]
|
|
||||||
|
|
||||||
print("startup command: ", startup_command)
|
print("startup command: ", startup_command)
|
||||||
|
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
The big ones:
|
Done:
|
||||||
- Handle bundling of the actual Python modules we want to use.
|
x Handle bundling of the actual Python modules we want to use.
|
||||||
- First-time setup of requirements (pip, etc).
|
|
||||||
x Remove dependency on psutil.
|
x Remove dependency on psutil.
|
||||||
- Clean up removal of psutil.
|
x Clean up removal of psutil.
|
||||||
- Remove xterm dependency, or make it like a debug-only thing.
|
x remove parent_pid from wrapper script
|
||||||
- Test on WINE/Windows.
|
x remove KiriPythonRPCWrapper_start.py
|
||||||
- Documentation.
|
x remove test_rpc.py
|
||||||
- how to use .kiri_export_python
|
|
||||||
|
The big ones:
|
||||||
|
|
||||||
- Un-thread the GDScript side of PacketSocket.
|
- Un-thread the GDScript side of PacketSocket.
|
||||||
|
|
||||||
- Fix whatever this is:
|
- Fix whatever this is:
|
||||||
SCRIPT ERROR: Assertion failed.
|
SCRIPT ERROR: Assertion failed.
|
||||||
at: KiriPacketSocket._notification (res://addons/KiriPythonRPCWrapper/KiriPacketSocket/KiriPacketSocket.gd:70)
|
at: KiriPacketSocket._notification (res://addons/KiriPythonRPCWrapper/KiriPacketSocket/KiriPacketSocket.gd:70)
|
||||||
WARNING: A Thread object is being destroyed without its completion having been realized.
|
WARNING: A Thread object is being destroyed without its completion having been realized.
|
||||||
Please call wait_to_finish() on it to ensure correct cleanup.
|
Please call wait_to_finish() on it to ensure correct cleanup.
|
||||||
at: ~Thread (core/os/thread.cpp:102)
|
at: ~Thread (core/os/thread.cpp:102)
|
||||||
|
|
||||||
- remove KiriPythonRPCWrapper_start.py
|
- First-time setup of requirements (pip, etc).
|
||||||
- remove test_rpc.py
|
- Remove xterm dependency, or make it like a debug-only thing.
|
||||||
|
- Test on WINE/Windows.
|
||||||
|
- Documentation.
|
||||||
|
- how to use .kiri_export_python
|
||||||
|
|
||||||
|
|
||||||
|
- example Python module from OUTSIDE the addon
|
||||||
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
import KiriPacketSocket
|
|
||||||
|
|
||||||
ps = KiriPacketSocket.PacketSocket()
|
|
||||||
ps.start_server(("127.0.0.1", 9506))
|
|
||||||
|
|
||||||
connections = []
|
|
||||||
|
|
||||||
while True:
|
|
||||||
|
|
||||||
psc = ps.get_next_server_connection()
|
|
||||||
if psc:
|
|
||||||
print("Got connection.")
|
|
||||||
connections.append(psc)
|
|
||||||
psc.send_packet(b'ABCDEFGHIJ')
|
|
||||||
|
|
||||||
|
|
||||||
for conn in connections:
|
|
||||||
p = conn.get_next_packet()
|
|
||||||
while p:
|
|
||||||
print(p)
|
|
||||||
conn.send_packet(p + b'1')
|
|
||||||
p = conn.get_next_packet()
|
|
||||||
|
|
||||||
time.sleep(0.0001)
|
|
Loading…
Reference in New Issue
Block a user