[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Speeding up scripts by processing -after- screen-write

Speeding up scripts by processing -after- screen-write

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Thu 08 Sep 2011 05:24 PM (UTC)
Message
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.
[Go to top] top

Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Reply #1 on Thu 08 Sep 2011 05:33 PM (UTC)
Message
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...
[Go to top] top

Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Reply #2 on Thu 08 Sep 2011 05:49 PM (UTC)
Message
Okay never mind me!! All of my WindowLoadImage() calls were WITHIN OnPluginBroadcast(). Sheesh. Gotta indent my stuff in better... Works great now. XP
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Thu 08 Sep 2011 08:09 PM (UTC)
Message
Uh...what?

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Reply #4 on Thu 08 Sep 2011 08:22 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 08 Sep 2011 09:10 PM (UTC)

Amended on Thu 08 Sep 2011 09:11 PM (UTC) by Nick Gammon

Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,703 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]