diff --git a/defnet/http_server.lua b/defnet/http_server.lua index bbb836d..c91434d 100644 --- a/defnet/http_server.lua +++ b/defnet/http_server.lua @@ -139,7 +139,11 @@ function M.create(port) local request_handlers = {} - local ss = tcp_server.create(port, function() end) + local options = { binary = false } + local on_data = function() end + local on_client_connected = function() end + local on_client_disconnected = function() end + local ss = tcp_server.create(port, on_data, on_client_connected, on_client_disconnected, options) -- Replace the underlying socket server's receive function -- Read lines until end of request diff --git a/defnet/tcp_client.lua b/defnet/tcp_client.lua index e69b364..bbee76a 100644 --- a/defnet/tcp_client.lua +++ b/defnet/tcp_client.lua @@ -25,7 +25,7 @@ -- self.client.send("Sending this to the server\n") -- end -local tcp_send_queue = require "defnet.tcp_send_queue" +local tcp_data_queue = require "defnet.tcp_data_queue" local M = {} @@ -40,7 +40,7 @@ local log = function(...) M.log(...) end -- @param server_port -- @param on_data Function to call when data is received from the server -- @param on_disconnect Function to call when the connection to the server ends --- @param options Table with options (keys: connection_timeout (s)) +-- @param options Table with options (keys: connection_timeout (s), binary, chunk_size) -- @return client -- @return error function M.create(server_ip, server_port, on_data, on_disconnect, options) @@ -51,14 +51,16 @@ function M.create(server_ip, server_port, on_data, on_disconnect, options) log("Creating TCP client", server_ip, server_port) - local client = { - pattern = "*l", - } + local client = {} local client_socket = nil - local send_queue = nil + local data_queue = nil local client_socket_table = nil local connection_timeout = options and options.connection_timeout or nil + local data_queue_options = { + chunk_size = options and options.chunk_size or M.TCP_SEND_CHUNK_SIZE, + binary = options and options.binary or false, + } local ok, err = pcall(function() client_socket = socket.tcp() @@ -66,9 +68,9 @@ function M.create(server_ip, server_port, on_data, on_disconnect, options) assert(client_socket:connect(server_ip, server_port)) assert(client_socket:settimeout(0)) client_socket_table = { client_socket } - send_queue = tcp_send_queue.create(client_socket, M.TCP_SEND_CHUNK_SIZE) + data_queue = tcp_data_queue.create(client_socket, data_queue_options) end) - if not ok or not client_socket or not send_queue then + if not ok or not client_socket or not data_queue then log("tcp_client.create() error", err) return nil, ("Unable to connect to %s:%d"):format(server_ip, server_port) end @@ -82,11 +84,9 @@ function M.create(server_ip, server_port, on_data, on_disconnect, options) end client.send = function(data) - send_queue.add(data) + data_queue.add(data) end - local loaded_data = "" - client.update = function() if not client_socket then return @@ -96,7 +96,7 @@ function M.create(server_ip, server_port, on_data, on_disconnect, options) local receivet, sendt = socket.select(client_socket_table, client_socket_table, 0) if sendt[client_socket] then - local ok, err = send_queue.send() + local ok, err = data_queue.send() if not ok and err == "closed" then client.destroy() on_disconnect() @@ -106,13 +106,9 @@ function M.create(server_ip, server_port, on_data, on_disconnect, options) if receivet[client_socket] then while client_socket do - local data, err, partial = client_socket:receive(client.pattern or "*l") - if partial then - loaded_data = loaded_data..partial - end + local data, err = data_queue.receive() if data then - local response = on_data(loaded_data..data) - loaded_data = "" + local response = on_data(data) if response then client.send(response) end diff --git a/defnet/tcp_data_queue.lua b/defnet/tcp_data_queue.lua new file mode 100644 index 0000000..5ec86ed --- /dev/null +++ b/defnet/tcp_data_queue.lua @@ -0,0 +1,148 @@ +local M = {} + +local BxFF000000 = bit.lshift(255, 24) +local Bx00FF0000 = bit.lshift(255, 16) +local Bx0000FF00 = bit.lshift(255, 8) +local Bx000000FF = bit.lshift(255, 0) + +local function encode_size(data) + local length = #data + -- split length into four bytes + local b1 = bit.rshift(bit.band(length, BxFF000000), 24) + local b2 = bit.rshift(bit.band(length, Bx00FF0000), 16) + local b3 = bit.rshift(bit.band(length, Bx0000FF00), 8) + local b4 = bit.rshift(bit.band(length, Bx000000FF), 0) + -- convert the four bytes to a string + return string.char(b1, b2, b3, b4) +end + +local function decode_size(data) + local b1, b2, b3, b4 = data:byte(1, 4) + return bit.lshift(b1, 24) + bit.lshift(b2, 16) + bit.lshift(b3, 8) + b4 +end + +--- Create a TCP data queue instance +-- @param client The TCP client used when sending and receiving data +-- @param options Table with data options. Accepted options: +-- * chunk_size - The maximum size of any data that will be +-- sent. Defaults to 10000. If data is added that is larger than this value +-- it will be split into multiple "chunks". Note that there is no guarantee +-- that all data in a chunk is sent in a single call. Individual chunks may +-- still be split into multiple TCP send calls. +-- * binary - Data that is received and sent will be prefixed with the data +-- length. Use this mode when working with binary data (including 0x00). +-- @return The created data queue instance +function M.create(client, options) + assert(client, "You must provide a TCP client") + + local chunk_size = options and options.chunk_size or 10000 + local binary = options and options.binary or false + + local instance = {} + + local send_queue = {} + local received_data = "" + local received_data_size = nil + + function instance.clear() + send_queue = {} + end + + function instance.add(data) + assert(data, "You must provide some data") + if binary then + data = encode_size(data) .. data + else + data = data + end + for i=1,#data,chunk_size do + table.insert(send_queue, { data = data:sub(i, i + chunk_size - 1), sent_index = 0 }) + end + end + + function instance.send() + while true do + local first = send_queue[1] + if not first then + return true + end + + local sent_index, err, sent_index_on_err = client:send(first.data, first.sent_index + 1, #first.data) + if err then + first.sent_index = sent_index_on_err + return false, err + end + + first.sent_index = sent_index + if first.sent_index == #first.data then + table.remove(send_queue, 1) + end + end + end + + + local function receive_binary() + -- calculate number of bytes to receive + -- 1) size: read 4 bytes to get the size of the data + -- 2) data: read the data itself + local n = nil + if not received_data_size then + n = 4 - #received_data + else + n = received_data_size - #received_data + end + + -- receive some bytes (partially or all) + local data, err, partial = client:receive(n) + if partial then + received_data = received_data .. partial + end + + -- exepected number of bytes received + if data then + data = received_data .. data + received_data = "" + if not received_data_size then + received_data_size = decode_size(data) + else + received_data_size = nil + return data, nil + end + elseif err == "closed" then + return nil, err + end + return nil, nil + end + + local function receive_lines() + -- receive some bytes (partially or all) + local data, err, partial = client:receive("*l") + if partial then + received_data = received_data .. partial + end + + -- all bytes received? + if data then + print("received ALL data") + data = received_data .. data + received_data = "" + return data, nil + elseif err == "closed" then + return nil, err + end + return nil, nil + end + + function instance.receive() + if binary then + return receive_binary() + else + return receive_lines() + end + end + + return instance +end + + +return M diff --git a/defnet/tcp_send_queue.lua b/defnet/tcp_send_queue.lua deleted file mode 100644 index 1178aca..0000000 --- a/defnet/tcp_send_queue.lua +++ /dev/null @@ -1,55 +0,0 @@ -local M = {} - ---- Create a TCP send queue --- @param client The TCP client used when sending data --- @param chunk_size The maximum size of any data that will be --- sent. Defaults to 10000. If data is added that is larger than this value it will --- be split into multiple "chunks". Note that there is no guarantee --- that all data in a chunk is sent in a single call. Individual --- chunks may still be split into multiple TCP send calls. --- @return The created queue instance -function M.create(client, chunk_size) - assert(client, "You must provide a TCP client") - - chunk_size = chunk_size or 10000 - - local instance = {} - - local queue = {} - - function instance.clear() - queue = {} - end - - function instance.add(data) - assert(data, "You must provide some data") - for i=1,#data,chunk_size do - table.insert(queue, { data = data:sub(i, i + chunk_size - 1), sent_index = 0 }) - end - end - - function instance.send() - while true do - local first = queue[1] - if not first then - return true - end - - local sent_index, err, sent_index_on_err = client:send(first.data, first.sent_index + 1, #first.data) - if err then - first.sent_index = sent_index_on_err - return false, err - end - - first.sent_index = sent_index - if first.sent_index == #first.data then - table.remove(queue, 1) - end - end - end - - return instance -end - - -return M diff --git a/defnet/tcp_server.lua b/defnet/tcp_server.lua index 3dbdb84..b24fb1e 100644 --- a/defnet/tcp_server.lua +++ b/defnet/tcp_server.lua @@ -31,7 +31,7 @@ -- end -- -local tcp_send_queue = require "defnet.tcp_send_queue" +local tcp_data_queue = require "defnet.tcp_data_queue" local socket = require "builtins.scripts.socket" local M = {} @@ -51,8 +51,9 @@ local log = function(...) M.log(...) end -- connected. The function will be called with the following args: ip -- @param on_client_disconnected Function to call when a client has -- disconnected. The function will be called with the following args: ip +-- @param options Table with options (keys: binary, chunk_size) -- @return Server instance -function M.create(port, on_data, on_client_connected, on_client_disconnected) +function M.create(port, on_data, on_client_connected, on_client_disconnected, options) assert(port, "You must provide a port") assert(on_data, "You must provide an on_data function") @@ -65,6 +66,10 @@ function M.create(port, on_data, on_client_connected, on_client_disconnected) local clients = {} local queues = {} + local queue_options = { + chunk_size = options and options.chunk_size or M.TCP_SEND_CHUNK_SIZE, + binary = options and options.binary or false, + } local function remove_client(connection_to_remove) for i,connection in pairs(clients) do @@ -118,11 +123,11 @@ function M.create(port, on_data, on_client_connected, on_client_disconnected) client:close() end end - + server.receive = function(client) - return client:receive("*l") + return queues[client].receive() end - + server.broadcast = function(data) log("Broadcasting") for client,queue in pairs(queues) do @@ -150,7 +155,7 @@ function M.create(port, on_data, on_client_connected, on_client_disconnected) if client then client:settimeout(0) table.insert(clients, client) - queues[client] = tcp_send_queue.create(client, M.TCP_SEND_CHUNK_SIZE) + queues[client] = tcp_data_queue.create(client, queue_options) if on_client_connected then local client_ip, client_port = client:getpeername() on_client_connected(client_ip, client_port, client) diff --git a/examples/discovery/discovery.gui b/examples/discovery/discovery.gui index 5ce6d0a..aaf486e 100644 --- a/examples/discovery/discovery.gui +++ b/examples/discovery/discovery.gui @@ -3,381 +3,64 @@ textures { name: "ui" texture: "/examples/assets/ui.atlas" } -background_color { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 -} nodes { position { - x: 320.0 - y: 591.434 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 128.0 - y: 128.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 582.0 + y: 442.43402 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA texture: "ui/logo" id: "logo" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT - layer: "" inherit_alpha: true - slice9 { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 - template_node_child: false size_mode: SIZE_MODE_AUTO } nodes { position { - x: 320.0 - y: 450.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 582.0 + y: 301.0 } type: TYPE_TEMPLATE id: "broadcast" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 220.0 - y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "broadcast/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "broadcast" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "BROADCAST" - font: "dirtylarry" id: "broadcast/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "broadcast/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 364.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 582.0 + y: 215.0 } type: TYPE_TEMPLATE id: "discover" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 220.0 - y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "discover/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "discover" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "DISCOVER" - font: "dirtylarry" id: "discover/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "discover/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } layers { name: "below" @@ -390,4 +73,3 @@ layers { } material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT -max_nodes: 512 diff --git a/examples/examples.gui b/examples/examples.gui index 170e690..3ca755b 100644 --- a/examples/examples.gui +++ b/examples/examples.gui @@ -1,804 +1,214 @@ script: "/examples/examples.gui_script" -background_color { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 -} nodes { position { - x: 320.0 - y: 646.0 - z: 0.0 - w: 1.0 + x: 62.0 + y: 572.0 } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 + type: TYPE_TEMPLATE + id: "back" + inherit_alpha: true + template: "/gooey/themes/dirtylarry/components/button.gui" +} +nodes { + size { + x: 64.0 + y: 64.0 } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + type: TYPE_BOX + id: "back/bg" + parent: "back" + overridden_fields: 4 + template_node_child: true +} +nodes { + type: TYPE_TEXT + text: "<" + id: "back/label" + parent: "back/bg" + overridden_fields: 8 + template_node_child: true +} +nodes { + position { + x: 568.0 + y: 320.0 } size { x: 200.0 y: 100.0 - z: 0.0 - w: 1.0 } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + type: TYPE_BOX + id: "buttons" + inherit_alpha: true + size_mode: SIZE_MODE_AUTO + visible: false +} +nodes { + position { + y: 150.0 } type: TYPE_TEMPLATE id: "discovery" - layer: "" + parent: "buttons" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 250.0 + x: 240.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "discovery/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "discovery" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "DISCOVERY" - font: "dirtylarry" id: "discovery/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "discovery/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 563.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 75.0 } type: TYPE_TEMPLATE id: "http_server" - layer: "" + parent: "buttons" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 250.0 + x: 240.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "http_server/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "http_server" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "HTTP SERVER" - font: "dirtylarry" id: "http_server/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "http_server/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { - position { - x: 320.0 - y: 485.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } type: TYPE_TEMPLATE id: "tcp_client" - layer: "" + parent: "buttons" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 250.0 + x: 240.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "tcp_client/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "tcp_client" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "TCP CLIENT" - font: "dirtylarry" id: "tcp_client/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "tcp_client/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 401.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: -75.0 } type: TYPE_TEMPLATE id: "tcp_server" - layer: "" + parent: "buttons" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 250.0 + x: 240.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "tcp_server/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "tcp_server" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "TCP SERVER" - font: "dirtylarry" id: "tcp_server/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "tcp_server/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 62.0 - y: 1081.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: -154.0 } type: TYPE_TEMPLATE - id: "back" - layer: "" + id: "tcp_cs" + parent: "buttons" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 64.0 + x: 240.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" - id: "back/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT - parent: "back" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + id: "tcp_cs/bg" + parent: "tcp_cs" overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA - text: "<" - font: "dirtylarry" - id: "back/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false - parent: "back/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + text: "TCP C+S" + id: "tcp_cs/label" + parent: "tcp_cs/bg" + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } layers { name: "below" @@ -808,4 +218,3 @@ layers { } material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT -max_nodes: 512 diff --git a/examples/examples.gui_script b/examples/examples.gui_script index 68abdfb..ab28649 100644 --- a/examples/examples.gui_script +++ b/examples/examples.gui_script @@ -6,6 +6,7 @@ local function set_enabled_on_buttons(enabled) dirtylarry.set_enabled(dirtylarry.button("http_server"), enabled) dirtylarry.set_enabled(dirtylarry.button("tcp_client"), enabled) dirtylarry.set_enabled(dirtylarry.button("tcp_server"), enabled) + dirtylarry.set_enabled(dirtylarry.button("tcp_cs"), enabled) end local function hide_buttons() @@ -19,16 +20,14 @@ end function init(self) msg.post(".", "acquire_input_focus") msg.post("@render:", "clear_color", { color = vmath.vector4(0.4, 0.5, 0.8, 1.0) }) + self.proxies = {} show_buttons() end function on_message(self, message_id, message, sender) if message_id == hash("proxy_loaded") then msg.post(sender, "enable") - self.current_proxy = sender - elseif message_id == hash("proxy_unloaded") then - show_buttons() - self.current_proxy = nil + self.proxies[sender] = true end end @@ -49,7 +48,15 @@ function on_input(self, action_id, action) hide_buttons() msg.post("#tcp_serverproxy", "async_load") end) + dirtylarry.button("tcp_cs", action_id, action, function() + hide_buttons() + msg.post("#tcp_clientproxy", "async_load") + msg.post("#tcp_serverproxy", "async_load") + end) dirtylarry.button("back", action_id, action, function() - msg.post(self.current_proxy, "unload") + for proxy,_ in pairs(self.proxies) do + msg.post(proxy, "unload") + end + show_buttons() end) end diff --git a/examples/http_server/http_server.gui b/examples/http_server/http_server.gui index 39bf90d..2500aa3 100644 --- a/examples/http_server/http_server.gui +++ b/examples/http_server/http_server.gui @@ -3,225 +3,50 @@ textures { name: "ui" texture: "/examples/assets/ui.atlas" } -background_color { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 -} nodes { position { - x: 320.0 - y: 591.434 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 128.0 - y: 128.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 566.0 + y: 415.43402 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA texture: "ui/logo" id: "logo" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT - layer: "" inherit_alpha: true - slice9 { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 - template_node_child: false size_mode: SIZE_MODE_AUTO } nodes { position { - x: 320.0 - y: 425.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 566.0 + y: 249.0 } type: TYPE_TEMPLATE id: "open_browser" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 320.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "open_browser/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "open_browser" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 300.0 y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "OPEN BROWSER" - font: "dirtylarry" id: "open_browser/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "open_browser/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } layers { name: "below" @@ -234,4 +59,3 @@ layers { } material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT -max_nodes: 512 diff --git a/examples/http_server/http_server.gui_script b/examples/http_server/http_server.gui_script index ffaf9a2..9ae1041 100644 --- a/examples/http_server/http_server.gui_script +++ b/examples/http_server/http_server.gui_script @@ -32,7 +32,7 @@ function init(self) return self.http_server.html("Got post data: " .. tostring(body)) end) self.http_server.router.get("/$", function(matches, stream, headers, body) - local index = sys.load_resource("/examples/assets/www/index.html") + local index = sys.load_resource("/examples/assets/www/index.html") return self.http_server.html(index) end) self.http_server.router.get("^/logo$", function(matches, stream, headers, body) diff --git a/examples/tcp_client/tcp_client.gui b/examples/tcp_client/tcp_client.gui index 3cbb173..8afe208 100644 --- a/examples/tcp_client/tcp_client.gui +++ b/examples/tcp_client/tcp_client.gui @@ -3,381 +3,84 @@ textures { name: "ui" texture: "/examples/assets/ui.atlas" } -background_color { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 -} nodes { position { - x: 320.0 - y: 591.434 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 128.0 - y: 128.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 120.0 + y: 417.43402 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA texture: "ui/logo" id: "logo" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT - layer: "" inherit_alpha: true - slice9 { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 - template_node_child: false size_mode: SIZE_MODE_AUTO } nodes { position { - x: 320.0 - y: 337.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 120.0 + y: 163.0 } type: TYPE_TEMPLATE id: "send" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 220.0 + x: 200.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "send/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "send" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "SEND" - font: "dirtylarry" id: "send/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "send/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 433.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 120.0 + y: 259.0 } type: TYPE_TEMPLATE id: "connect" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 220.0 + x: 200.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "connect/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "connect" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "CONNECT" - font: "dirtylarry" id: "connect/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "connect/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } layers { name: "below" @@ -390,4 +93,3 @@ layers { } material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT -max_nodes: 512 diff --git a/examples/tcp_client/tcp_client.gui_script b/examples/tcp_client/tcp_client.gui_script index cdfac67..5c42c60 100644 --- a/examples/tcp_client/tcp_client.gui_script +++ b/examples/tcp_client/tcp_client.gui_script @@ -24,14 +24,16 @@ end function on_input(self, action_id, action) dirtylarry.button("send", action_id, action, function() for i=math.random(1,3),1,-1 do - self.client.send("foobar " .. tostring(os.time() .. "_" .. i) .. "\r\n") + local data = "foobar " .. tostring(os.time() .. "_" .. i) + self.client.send(data) end end) dirtylarry.button("connect", action_id, action, function() local address = "127.0.0.1" + local options = { binary = true } local client, err = tcp_client.create(address, SERVER_PORT, function(data) - print(data) + print("TCP client received data '" .. data .. "' from server") local logo = gui.get_node("logo") gui.animate(logo, "euler.z", gui.get_rotation(logo).z -360, gui.EASING_INOUTEXPO, 2, 0, nil, gui.PLAYBACK_ONCE_FORWARD) end, @@ -39,7 +41,8 @@ function on_input(self, action_id, action) self.client = nil dirtylarry.set_enabled(dirtylarry.button("connect"), true) dirtylarry.set_enabled(dirtylarry.button("send"), false) - end) + end, + options) if client then self.client = client diff --git a/examples/tcp_server/tcp_server.gui b/examples/tcp_server/tcp_server.gui index cf39fc4..3b670c5 100644 --- a/examples/tcp_server/tcp_server.gui +++ b/examples/tcp_server/tcp_server.gui @@ -3,539 +3,118 @@ textures { name: "ui" texture: "/examples/assets/ui.atlas" } -background_color { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 -} nodes { position { - x: 320.0 - y: 591.434 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 128.0 - y: 128.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 970.0 + y: 415.43402 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA texture: "ui/logo" id: "logo" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT - layer: "" inherit_alpha: true - slice9 { - x: 0.0 - y: 0.0 - z: 0.0 - w: 0.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 - template_node_child: false size_mode: SIZE_MODE_AUTO } nodes { position { - x: 320.0 - y: 350.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 970.0 + y: 174.0 } type: TYPE_TEMPLATE id: "broadcast" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 220.0 + x: 200.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "broadcast/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "broadcast" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "BROADCAST" - font: "dirtylarry" id: "broadcast/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "broadcast/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 454.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 970.0 + y: 278.0 } type: TYPE_TEMPLATE id: "stop" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 220.0 + x: 200.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "stop/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "stop" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "STOP" - font: "dirtylarry" id: "stop/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "stop/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } nodes { position { - x: 320.0 - y: 454.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - size { - x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + x: 970.0 + y: 278.0 } type: TYPE_TEMPLATE id: "start" - layer: "" inherit_alpha: true - alpha: 1.0 template: "/gooey/themes/dirtylarry/components/button.gui" - template_node_child: false } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { - x: 220.0 + x: 200.0 y: 64.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 } type: TYPE_BOX - blend_mode: BLEND_MODE_ALPHA - texture: "dirtylarry/button_normal" id: "start/bg" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - adjust_mode: ADJUST_MODE_FIT parent: "start" - layer: "below" - inherit_alpha: true - slice9 { - x: 12.0 - y: 12.0 - z: 12.0 - w: 12.0 - } - clipping_mode: CLIPPING_MODE_NONE - clipping_visible: true - clipping_inverted: false - alpha: 1.0 + overridden_fields: 4 template_node_child: true - size_mode: SIZE_MODE_MANUAL } nodes { - position { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - rotation { - x: 0.0 - y: 0.0 - z: 0.0 - w: 1.0 - } - scale { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } size { x: 200.0 - y: 100.0 - z: 0.0 - w: 1.0 - } - color { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 + y: 40.0 } type: TYPE_TEXT - blend_mode: BLEND_MODE_ALPHA text: "START" - font: "dirtylarry" id: "start/label" - xanchor: XANCHOR_NONE - yanchor: YANCHOR_NONE - pivot: PIVOT_CENTER - outline { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - shadow { - x: 1.0 - y: 1.0 - z: 1.0 - w: 1.0 - } - adjust_mode: ADJUST_MODE_FIT - line_break: false parent: "start/bg" - layer: "text" - inherit_alpha: true - alpha: 1.0 - outline_alpha: 1.0 - shadow_alpha: 1.0 + overridden_fields: 4 overridden_fields: 8 template_node_child: true - text_leading: 1.0 - text_tracking: 0.0 } layers { name: "below" @@ -548,4 +127,3 @@ layers { } material: "/builtins/materials/gui.material" adjust_reference: ADJUST_REFERENCE_PARENT -max_nodes: 512 diff --git a/examples/tcp_server/tcp_server.gui_script b/examples/tcp_server/tcp_server.gui_script index f3a4101..3a88795 100644 --- a/examples/tcp_server/tcp_server.gui_script +++ b/examples/tcp_server/tcp_server.gui_script @@ -22,8 +22,9 @@ function init(self) dirtylarry.set_enabled(dirtylarry.button("stop"), false) dirtylarry.set_enabled(dirtylarry.button("broadcast"), false) - - self.tcp_server = tcp_server.create(TCP_SERVER_PORT, on_data, on_client_connected, on_client_disconnected) + + local options = { binary = true } + self.tcp_server = tcp_server.create(TCP_SERVER_PORT, on_data, on_client_connected, on_client_disconnected, options) end function final(self) @@ -53,6 +54,7 @@ function on_input(self, action_id, action) self.tcp_server.stop() end) dirtylarry.button("broadcast", action_id, action, function() - self.tcp_server.broadcast("tcp from sever to client foobar\n") + local data = "foobar " .. tostring(os.time()) + self.tcp_server.broadcast(data) end) end diff --git a/game.project b/game.project index 4c17446..5a3ffe1 100644 --- a/game.project +++ b/game.project @@ -11,8 +11,8 @@ main_collection = /examples/examples.collectionc game_binding = /input/game.input_bindingc [display] -width = 640 -height = 1136 +width = 1136 +height = 640 [physics] scale = 0.02