Speeding up scripts by processing -after- screen-write

Posted by Daniel P on Thu 08 Sep 2011 05:24 PM — 6 posts, 25,678 views.

USA #0
My example is such: currently working on a duplicate of the new Achaean Nexus tabs via miniwindows and Telnet Subnegotiation captures.

Currently my plugin which decodes the json line into variables and does stuff seems like it is being fully processed and updated before the 'visual' stuff (stat line, other server messages following the subnegotiation) is actually shown.

This also occurs with another plugin that processes a plain text line (ship status line in cryptic mode). I've written a plugin that routes that into another mw console which makes it all look rather pretty...but it still insists on processing the miniwindow before actually writing the line to the screen and effectively gives a noticeable delay.

Perhaps it's the glut of WindowDrawImage() calls I make (currently everything is in PNG format, which I thought didn't require much), but is there any way to possibly speed this up? Perhaps capture whatever I'm capturing into a single variable fairly quickly, then pass the text/subnegotiation messages to the window, and THEN process the variable?

I'm not wanting to put in any waits, because I'd also like the miniwindow to update as soon as it can, but that's not as high a priority as the screen write, which forces me to wait until it's done before I can enter a new command.
USA #1
http://www.gammon.com.au/forum/?id=11316 ... OnPluginTick() Hmm....probably not as relevant, since this delay seems to be up to about a half-second or so...
USA #2
Okay never mind me!! All of my WindowLoadImage() calls were WITHIN OnPluginBroadcast(). Sheesh. Gotta indent my stuff in better... Works great now. XP
USA Global Moderator #3
Uh...what?
USA #4
Sorry...I just got happy there for a minute.

Used to be:

<script><![CDATA[
idGMCP = "fd1317dca87167934e167aa2"

room_num = 0
room_name = ""
room_area = ""
room_environment = ""
room_coords = ""
room_map = ""
room_details = ""
tabs = "Tab_Selection"
room1 = "Info_Room"
room2 = "Inv_Room"
info_on = "false"

room_inv = {}
WindowCreate (tabs, 810, 0, 400, 25, 10, 2, ColourNameToRGB ("black"))
WindowCreate (room1, 810, 25, 400, 100, 10, 2, ColourNameToRGB ("black"))
WindowCreate (room2, 810, 127, 400, 400, 10, 2, ColourNameToRGB ("black"))
WindowFont (room1, "f", "Courier New", 10, true, false, false, false)
WindowFont (room2, "f", "Courier New", 10, true, false, false, false)
WindowFont (room1, "f2", "Times New Roman", 18, true, false, false, false)
WindowFont (room2, "f2", "Times New Roman", 18, true, false, false, false)

--WindowDrawImage (tabs, "tab_bg", 0, 0, 0, 0, 1)

OnPluginBroadcast = function (msg, id, name, text)

WindowLoadImage (tabs, "tab_bg", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Tabs.png")
WindowLoadImage (tabs, "tab_room", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Room.png")
WindowLoadImage (tabs, "tab_char", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Char.png")
WindowLoadImage (tabs, "tab_skills", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Skills.png")
WindowLoadImage (tabs, "tab_chat", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Chat.png")
WindowLoadImage (tabs, "tab_who", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Who.png")
WindowLoadImage (tabs, "tab_inv", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Inv.png")
WindowLoadImage (tabs, "tab_rift", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Rift.png")

WindowLoadImage (room1, "bg_image", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/400x100.png")
WindowLoadImage (room2, "bg_image", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/400x400.png")


  if (id == idGMCP) then
    json = require("json")
    if (msg == 5) then
      if info_tab == "room" then
        t = json.decode(text)
...
...


Fixed it to:

<script><![CDATA[
idGMCP = "fd1317dca87167934e167aa2"

room_num = 0
room_name = ""
room_area = ""
room_environment = ""
room_coords = ""
room_map = ""
room_details = ""
tabs = "Tab_Selection"
room1 = "Info_Room"
room2 = "Inv_Room"
info_on = "false"

room_inv = {}
WindowCreate (tabs, 810, 0, 400, 25, 10, 2, ColourNameToRGB ("black"))
WindowCreate (room1, 810, 25, 400, 100, 10, 2, ColourNameToRGB ("black"))
WindowCreate (room2, 810, 127, 400, 400, 10, 2, ColourNameToRGB ("black"))
WindowFont (room1, "f", "Courier New", 10, true, false, false, false)
WindowFont (room2, "f", "Courier New", 10, true, false, false, false)
WindowFont (room1, "f2", "Times New Roman", 18, true, false, false, false)
WindowFont (room2, "f2", "Times New Roman", 18, true, false, false, false)
WindowLoadImage (tabs, "tab_bg", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Tabs.png")
WindowLoadImage (tabs, "tab_room", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Room.png")
WindowLoadImage (tabs, "tab_char", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Char.png")
WindowLoadImage (tabs, "tab_skills", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Skills.png")
WindowLoadImage (tabs, "tab_chat", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Chat.png")
WindowLoadImage (tabs, "tab_who", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Who.png")
WindowLoadImage (tabs, "tab_inv", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Inv.png")
WindowLoadImage (tabs, "tab_rift", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/Rift.png")

WindowLoadImage (room1, "bg_image", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/400x100.png")
WindowLoadImage (room2, "bg_image", "C:/Program Files/MUSHClient/worlds/plugins/Custom/Tabs/400x400.png")

--WindowDrawImage (tabs, "tab_bg", 0, 0, 0, 0, 1)

OnPluginBroadcast = function (msg, id, name, text)

  if (id == idGMCP) then
    json = require("json")
    if (msg == 5) then
      if info_tab == "room" then
        t = json.decode(text)
...
...


Moral of the story is: if you plan to load images into your miniwindows, load them when the plugin loads, not while it is executing.
Australia Forum Administrator #5
I had to stare at that a while, even though I use Lua a lot.

This is why I prefer, instead of:


OnPluginBroadcast = function (msg, id, name, text)

...


end -- function OnPluginBroadcast


Use this:


function OnPluginBroadcast (msg, id, name, text)

...


end -- function OnPluginBroadcast


Visually it's clearer you are starting a function definition. Otherwise it looks like just another assignment statement in the middle of the others.

And whether or not it is a PNG file shouldn't matter - once the file is loaded into memory (an image) it is just a bitmap. Hopefully you only do this once in the plugin.

[EDIT] And yes, indent your stuff! The time you saved not bothering indenting was wasted with solving this problem.