Results 1 to 17 of 17

Thread: Threads & Painting

  1. #1
    Join Date
    May 2006
    Location
    Australia
    Posts
    370
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Threads & Painting

    Hey

    Is there any way I can continuously paint to the main screen (every 100ms or so), while my script is running. Most languages would use a thread for this - and I remember SCAR used to have a GUI thread you could use for things like that.

    Do we have any functionality like that in Simba?
    ------
    Strong Holder
    Kill Goblins and Zombies in (ex) bot free zones. Loot & Bank. Stable: 1.2b

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    I've tried looking for threading in simba and scar and the only virtual threading I've seen is SendInterScarMessage.. which is useless for what your looking to do.

    My attempting at doing this "Threading"

    Simba Code:
    Procedure PrintMainScreen;
    begin
    //Do printing here..
    end;
    Procedure1;
    begin
    //DoStuff
    PrintSmart;
    //DoStuff
    PrintSmart;
    end;

    procedure2;
    var
    PrevTime: Integer;
    begin
    PrevTime = GetsystemTime;
    //Do something.
    if(GetsystemTime - PrevTime >= 100)
    begin
    do another stuff;
    end;
    PrevTime = GetsystemTime;
    //Do something.
    if(GetsystemTime - PrevTime >= 100)
    begin
    do another stuff;
    end;
    PrevTime = GetsystemTime;
    //Do something.
    if(GetsystemTime - PrevTime >= 100)
    begin
    do another stuff;
    end;
    PrevTime = GetsystemTime;
    //Do something.
    if(GetsystemTime - PrevTime >= 100)
    begin
    do another stuff;
    end;

    end;

    //MainLoop
    begin
    Procedure1;
    PrintMainScreen;
    Procedure2;
    PrintMainScreen;

    end.

  3. #3
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Simba Code:
    program new;
    {$DEFINE SMART}
    {$i srl/srl.scar}
    {$i srl/srl/misc/paintsmart.scar}

    var
      i: integer;
    begin
      Smart_Server := 152;
      Smart_Members := False;
      Smart_Signed := True;
      Smart_SuperDetail := False;

      SetupSRL;
      ClearDebug;

      for i := 1 to 100 do
      begin
        smart_DrawBox(intToBox(10+random(100), 10+random(100), 100+random(100), 100+random(100)));
        wait(100);
      end;

      smart_FreeDebug();
    end.

  4. #4
    Join Date
    May 2006
    Location
    Australia
    Posts
    370
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol.
    Not what I meant Coh3n. I know how to draw to smart, maybe didn't phrase the question well.
    I want the painting to be in a separate thread to the rest of my script.
    But thanks anyway :P
    ------
    Strong Holder
    Kill Goblins and Zombies in (ex) bot free zones. Loot & Bank. Stable: 1.2b

  5. #5
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    In SCAR you could use TTimers but I haven't gotten them to work with Simba.
    Ce ne sont que des gueux


  6. #6
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    In SCAR you could use TTimers but I haven't gotten them to work with Simba.
    MSI's form uses a TTimer, so they do work. I don't know how to use them, really, but they work.

    And threading isn't possible with pascal script as far as I know.

  7. #7
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    I've tried to copy MSI's exact code and trim it down/modify it to WriteLn something every sec but it won't fricken work, so I gave up after like 20 tries :P
    Ce ne sont que des gueux


  8. #8
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    I've tried to copy MSI's exact code and trim it down/modify it to WriteLn something every sec but it won't fricken work, so I gave up after like 20 tries :P
    Simba Code:
    program new;

    var
      timer: TTimer;
      t: integer;

    begin
      clearDebug();

      timer := TTimer.Create(nil);
      timer.enabled := true;


      t := (getSystemTime + 5000);
      while timer.enabled do
      begin
        writeln('timer is enabled');
        wait(20);

        if (getSystemTime > t) then
          timer.enabled := false;
      end;

      timer.Free;
    end.

  9. #9
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Yeah but there you're in that loop eh...
    I'm talking about the way to 'multi-thread' using TTimers.
    Ce ne sont que des gueux


  10. #10
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Well how did you do it with SCAR?

  11. #11
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Iamadam View Post
    Lol.
    Not what I meant Coh3n. I know how to draw to smart, maybe didn't phrase the question well.
    I want the painting to be in a separate thread to the rest of my script.
    But thanks anyway :P
    There is no true multithreading. I'm unsure why you'd want to do it in a different thread. But you could use TTimer, I'm pretty sure it should work. Just don't expect it to also have the speed advantages of multiple threads.

    Floor: What Coh3n showed you should work fine for drawing in another ``thread''. Imagine replacing the wait(20); with the script mainloop. Recall that a TTimer event can occur during any moment in the script. (iow you don't need logic for it, I suppose that is why Iamadam wants it)



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  12. #12
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    Yeah but there you're in that loop eh...
    I'm talking about the way to 'multi-thread' using TTimers.
    Thats not multithreading.

    You can only use TTimers correctly in ThreadSafeCall!

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  13. #13
    Join Date
    May 2006
    Location
    Australia
    Posts
    370
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    My script loops through the paint procedure often, but not often enough. If you want to paint a crosshair that follows a target, without affecting the functionality of the script (and without significant overhead), the best way would be to use a separate thread. If I want the crosshair to move smoothly between targets, I NEED another thread (can't be sacrificing script running speed to paint something) :P

    Sad that we can't multithread, but no problem Doesn't matter really, just wanted to see what simba was capable of.

    <troll>/me moves back to SCAR. </troll>
    ------
    Strong Holder
    Kill Goblins and Zombies in (ex) bot free zones. Loot & Bank. Stable: 1.2b

  14. #14
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Iamadam View Post
    My script loops through the paint procedure often, but not often enough. If you want to paint a crosshair that follows a target, without affecting the functionality of the script (and without significant overhead), the best way would be to use a separate thread. If I want the crosshair to move smoothly between targets, I NEED another thread (can't be sacrificing script running speed to paint something) :P

    Sad that we can't multithread, but no problem Doesn't matter really, just wanted to see what simba was capable of.

    <troll>/me moves back to SCAR. </troll>
    Multi-threading isn't possible in SCAR either... They both use PS.

  15. #15
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    Thats not multithreading.

    You can only use TTimers correctly in ThreadSafeCall!
    Hence my quotation marks.
    Ce ne sont que des gueux


  16. #16
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    TTimers have a onTimer property which is a functional pointer. You could use this for pseudo-threading practice.

    It works, I've used it before.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  17. #17
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    I have too, Nava, just not in simba.

    @Wizzup,
    I'll play with it some more =p

    EDIT:
    So why won't this work? :/
    Simba Code:
    program new;

    var
      Thread: Array [0..1] of TTimer;
      t, c: integer;

    function ShitsEnabled: Boolean;
    begin
      Result := (Thread[0].Enabled and Thread[1].Enabled);
    end;

    procedure OnThread1(Sender: TObject);
    var
      i: Integer;
    begin
      for i := c downto 0 do
        c := c - 1;
    end;

    procedure OnThread2(Sender: TObject);
    begin
      WriteLn('Thread 2 reporting in: '+ ToStr(c));
    end;

    begin
      ClearDebug;
      c := 500;
      for t := 0 to High(Thread) do
      begin
        Thread[t] := TTimer.Create(nil);
        Thread[t].Enabled := True;
      end;

      Thread[0].OnTimer := @OnThread1;
      Thread[0].Interval := 250;
      Thread[1].OnTimer := @OnThread2;
      Thread[1].Interval := 1000;

      while ShitsEnabled do
      begin
        Wait(10);
      end;

      for t := 0 to High(Thread) do
        Thread[t].Free;
    end.

    Also, Coh3n, the script you posted doesn't use the OnTimer event :/ That's just what I need.
    Last edited by Floor66; 04-03-2011 at 08:45 AM.
    Ce ne sont que des gueux


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •