Results 1 to 13 of 13

Thread: Adding the (D) in (D)DTMs

  1. #1
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default Adding the (D) in (D)DTMs

    How To Put the (D) in (D)DTMs.

    DDTMs = Dynamic Deformable Template Models

    This Tutorial Assumes That You Understand How To Make Basic DDTMs.



    So, you heard of DDTMs now. Do they sound better than plain old DTMs? Want to give them a try? You have? Good. But there's something missing.

    Where's the (D), or Dynamic-ness in the DDTM?


    Let us take a look at the following function.

    SCAR Code:
    function DDTMOut: Integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..4] of TDTMPointDef;
      TempTDTM: TDTM;
    begin
      dtmMainPoint.x := 994;
      dtmMainPoint.y := 244;
      dtmMainPoint.AreaSize := 0;
      dtmMainPoint.AreaShape := 0;
      dtmMainPoint.Color := 7241098;
      dtmMainPoint.Tolerance := 20;
     
      dtmSubPoints[0].x := 994;
      dtmSubPoints[0].y := 244;
      dtmSubPoints[0].AreaSize := 0;
      dtmSubPoints[0].AreaShape := 0;
      dtmSubPoints[0].Color := 7241098;
      dtmSubPoints[0].Tolerance := 20;
     
      dtmSubPoints[1].x := 986;
      dtmSubPoints[1].y := 258;
      dtmSubPoints[1].AreaSize := 0;
      dtmSubPoints[1].AreaShape := 0;
      dtmSubPoints[1].Color := 7241098;
      dtmSubPoints[1].Tolerance := 20;
     
      dtmSubPoints[2].x := 987;
      dtmSubPoints[2].y := 227;
      dtmSubPoints[2].AreaSize := 0;
      dtmSubPoints[2].AreaShape := 0;
      dtmSubPoints[2].Color := 7241098;
      dtmSubPoints[2].Tolerance := 20;
     
      dtmSubPoints[3].x := 991;
      dtmSubPoints[3].y := 216;
      dtmSubPoints[3].AreaSize := 0;
      dtmSubPoints[3].AreaShape := 0;
      dtmSubPoints[3].Color := 7241098;
      dtmSubPoints[3].Tolerance := 20;
     
      dtmSubPoints[4].x := 984;
      dtmSubPoints[4].y := 267;
      dtmSubPoints[4].AreaSize := 0;
      dtmSubPoints[4].AreaShape := 0;
      dtmSubPoints[4].Color := 7241098;
      dtmSubPoints[4].Tolerance := 20;
     
      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;
      Result := AddDTM(TempTDTM);
    end;

    So, is anything missing from the DDTM? Yes. It uses nothing of the Dynamic-ness in DDTMs. Everything is so static, it is perfectly possible to make that a DTM instead.




    So how do you put the (D), I hear you ask?

    This is a type of Dynamicity that will add tolerance in steps of 5.

    SCAR Code:
    function DDTMOut: TPoint;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..4] of TDTMPointDef;
      TempTDTM: TDTM;
      t, Tole: Integer;

    begin
      repeat
        Tole:= Tole + 5;
        dtmMainPoint.x := 994;
        dtmMainPoint.y := 244;
        dtmMainPoint.AreaSize := 0;
        dtmMainPoint.AreaShape := 0;
        dtmMainPoint.Color := 7241098;
        dtmMainPoint.Tolerance := Tole;

        dtmSubPoints[0].x := 994;
        dtmSubPoints[0].y := 244;
        dtmSubPoints[0].AreaSize := 0;
        dtmSubPoints[0].AreaShape := 0;
        dtmSubPoints[0].Color := 7241098;
        dtmSubPoints[0].Tolerance := Tole;

        dtmSubPoints[1].x := 986;
        dtmSubPoints[1].y := 258;
        dtmSubPoints[1].AreaSize := 0;
        dtmSubPoints[1].AreaShape := 0;
        dtmSubPoints[1].Color := 7241098;
        dtmSubPoints[1].Tolerance := Tole;

        dtmSubPoints[2].x := 987;
        dtmSubPoints[2].y := 227;
        dtmSubPoints[2].AreaSize := 0;
        dtmSubPoints[2].AreaShape := 0;
        dtmSubPoints[2].Color := 7241098;
        dtmSubPoints[2].Tolerance := Tole;

        dtmSubPoints[3].x := 991;
        dtmSubPoints[3].y := 216;
        dtmSubPoints[3].AreaSize := 0;
        dtmSubPoints[3].AreaShape := 0;
        dtmSubPoints[3].Color := 7241098;
        dtmSubPoints[3].Tolerance := Tole;

        dtmSubPoints[4].x := 984;
        dtmSubPoints[4].y := 267;
        dtmSubPoints[4].AreaSize := 0;
        dtmSubPoints[4].AreaShape := 0;
        dtmSubPoints[4].Color := 7241098;
        dtmSubPoints[4].Tolerance := Tole;

        TempTDTM.MainPoint := dtmMainPoint;
        TempTDTM.SubPoints := dtmSubPoints;
        i := AddDTM(TempTDTM);
       
        if DTMRotated(i,Result.x, Result.y, MMX1,MMY1,MMX2,MMY2) then Exit;

        try
          FreeDTM(i);
        except
        end;
       
      until(tole > 50)
    end;

    What's Different? Well, there's Dynamicness in the form of the tolerance increasing in steps of 5! Lets take a look in more detail.

    SCAR Code:
    function DDTMOut: TPoint;

    Instead of a DTM resulting, we make it result a TPoint.

    SCAR Code:
    repeat
        Tole:= Tole + 5;

    This will start the loop, and make the integer variable (Tole) add 5;

    SCAR Code:
    dtmMainPoint.AreaShape := 0;
        dtmMainPoint.Color := 7241098;
        dtmMainPoint.Tolerance := Tole;

    This will make the Tolerance equal to Tole, so for each loop, tole will be 5 higher.

    SCAR Code:
    i := AddDTM(TempTDTM);
       
        if DTMRotated(i,Result.x, Result.y, MMX1,MMY1,MMX2,MMY2) then Exit;

    We make the variable (i) equal the Temporary DTM with tolerance Tole, and try to find it. If we find it, we make the result equal to the place we found the DDTM in, and exit the function.

    SCAR Code:
    try
          FreeDTM(i);
        except
        end;

    This will try to Free the DTM(i), so that it will not sue up memory in the computer. It is generally a good idea to free any DTMs you use.

    Tthe Try Except Finally End; is used to protect agains RunTime errors. Because Freeing a DTM in a variable that isn't a DTM will give a runtime error, this is just a "Just in case" thing.

    SCAR Code:
    try
        //RunTime Error?
      except
        //If RunTime error then do anything here
      finally
        //Will do this regardless of runtime or no runtime
      end;

    In case you didn't notice, finally is optional.

    SCAR Code:
    until(tole > 50)

    If Tole (Our Tolerance) is bigger than 50, it will quit the function, seeing as 50 tolerance is pretty high anyway.

    Yay! We made our first true (D)DTM!



    What are the other types of (D)s around?
    Dynamic-ness for the color is fine too.

    SCAR Code:
    function DDTMOut: Integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..4] of TDTMPointDef;
      TempTDTM: TDTM;
      i,tole:integer;
     
    begin
      i:= FindRoadColor;
     
      if not(i > 0) then
      begin
        i := 7241098;
        tole:= 30;
      end;
     
      dtmMainPoint.x := 994;
      dtmMainPoint.y := 244;
      dtmMainPoint.AreaSize := 0;
      dtmMainPoint.AreaShape := 0;
      dtmMainPoint.Color := i;
      dtmMainPoint.Tolerance := tole;

      dtmSubPoints[0].x := 994;
      dtmSubPoints[0].y := 244;
      dtmSubPoints[0].AreaSize := 0;
      dtmSubPoints[0].AreaShape := 0;
      dtmSubPoints[0].Color := i;
      dtmSubPoints[0].Tolerance := tole;

      dtmSubPoints[1].x := 986;
      dtmSubPoints[1].y := 258;
      dtmSubPoints[1].AreaSize := 0;
      dtmSubPoints[1].AreaShape := 0;
      dtmSubPoints[1].Color := i;
      dtmSubPoints[1].Tolerance := tole;

      dtmSubPoints[2].x := 987;
      dtmSubPoints[2].y := 227;
      dtmSubPoints[2].AreaSize := 0;
      dtmSubPoints[2].AreaShape := 0;
      dtmSubPoints[2].Color := i;
      dtmSubPoints[2].Tolerance := tole;

      dtmSubPoints[3].x := 991;
      dtmSubPoints[3].y := 216;
      dtmSubPoints[3].AreaSize := 0;
      dtmSubPoints[3].AreaShape := 0;
      dtmSubPoints[3].Color := i;
      dtmSubPoints[3].Tolerance := tole;

      dtmSubPoints[4].x := 984;
      dtmSubPoints[4].y := 267;
      dtmSubPoints[4].AreaSize := 0;
      dtmSubPoints[4].AreaShape := 0;
      dtmSubPoints[4].Color := i;
      dtmSubPoints[4].Tolerance := tole;

      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;
      Result := AddDTM(TempTDTM);
    end;

    More Detail. NAW!

    SCAR Code:
    i:= FindRoadColor;

    We make the variable (i) equal to the function in SRL, FindRoadColor, which attempts to autocolor the road.

    SCAR Code:
    if not(i > 0) then
      begin
        i := 7241098;
        tole:= 30;
      end;

    Because findRoadColor might occasionally fail, we check that i is bigger than 0. If not, we make i equal to a known road color, and make the tolerance 30.

    If we do find the roadcolor, tolerance will be 0. Since when integer variables are initialized, they start out as 0.

    SCAR Code:
    dtmMainPoint.Color := i;
      dtmMainPoint.Tolerance := tole;

    Here, we make the color equal to FindRoadColor, and tolerance = tole.


    Shortening DDTMs (With credits to Mixster)

    Scroll up to the color DDTM, and see it again. Its a bit long, no?

    What about this? This one is shortened considerably.

    SCAR Code:
    function DDTMOut: Integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..4] of TDTMPointDef;
      TempTDTM: TDTM;
      i,tole,t:integer;

    begin
      i:= FindRoadColor;

      if not(i > 0) then
      begin
        i := 7241098;
        tole:= 30;
      end;

      dtmMainPoint.x := 994;
      dtmMainPoint.y := 244;

      dtmSubPoints[0].x := 994;
      dtmSubPoints[0].y := 244;

      dtmSubPoints[1].x := 986;
      dtmSubPoints[1].y := 258;

      dtmSubPoints[2].x := 987;
      dtmSubPoints[2].y := 227;

      dtmSubPoints[3].x := 991;
      dtmSubPoints[3].y := 216;

      dtmSubPoints[4].x := 984;
      dtmSubPoints[4].y := 267;

     
      for t := 0 to 4 do
      with dtmSubPoints[t] do
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;

      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;
      Result := AddDTM(TempTDTM);
    end;

    Moar Detail?

    SCAR Code:
    dtmSubPoints[0].x := 994;
      dtmSubPoints[0].y := 244;

    Just sets the points like usual.

    SCAR Code:
    for t := 0 to 4 do
      with dtmSubPoints[t] do
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;

    Here's the nice part. For To Do loops will loop from x to y (For X to Y do) by adding 1 each time. Low returns the lowest in an array.

    With ? Do will make stuff in a record things.
    It's usually
    SCAR Code:
    dtmSubPoints[t].AreaSize:= 0;
    right? But because I have a with dtmSubPoints[t] do, it shortens the whole thing considerably

    So that's it!


    There are a lot of ways to put the (D) in (D)DTMS. It all comes down to your creativity. But if I ever see another DDTM without the (D) in another membership application, I will personally open a vendetta to exterminate you.

    DDTMs without the first D are just DTMs.

    Thank You.
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  2. #2
    Join Date
    Dec 2007
    Location
    Malaysia
    Posts
    430
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    simple yet effective tut nice lee even though i knew this rep++ will help alot of new ppl

    EDIT: first post

    EDIT2: also add more detail on like what ppl can do with the DDTMs and how they can be able to do that

  3. #3
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Lol, nice tutorial.

    People, look at this if you want to create a DDTM! If it's not Dynamic, a normal DTM is perfectly suitable instead of adding large amounts of code for nothing It'll make your script less shorter and faster
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  4. #4
    Join Date
    Sep 2008
    Location
    New Zealand
    Posts
    157
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Lee Lok Hin View Post
    But if I ever see another DDTM without the (D) in another membership application, I will personally open a vendetta to exterminate you.

    DDTMs without the first D are just DTMs.
    Nicely put

    Thanks Lee after reading today how to create DDTM's I already understood that but since I have little scripting experience I was unsure what exactly they could be used for, I now have a good idea of some sorts of ways they can be used and might be using DDTM's in my future scripts (I will make sure they have the (D)!)

  5. #5
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    May I suggest adding a for loop to the DDTM's to make them so much smaller - for some reason everyone thinks they have to be massive, but they don't Using your last as an example:
    SCAR Code:
    function DDTMOut: Integer;
    var
      dtmMainPoint: TDTMPointDef;
      dtmSubPoints: Array [0..4] of TDTMPointDef;
      TempTDTM: TDTM;
      i,tole, x:integer;
     
    begin
      i:= FindRoadColor;
     
      if not(i > 0) then
      begin
        i := 7241098;
        tole:= 30;
      end;
     
      dtmMainPoint.x := 994;
      dtmMainPoint.y := 244;
      dtmMainPoint.AreaSize := 0;
      dtmMainPoint.AreaShape := 0;
      dtmMainPoint.Color := i;
      dtmMainPoint.Tolerance := tole;
     
      for x := Low(dtmSubPoints) to High(dtmSubPoints) do
      begin
        dtmSubPoints[0].AreaSize := 0;
        dtmSubPoints[0].AreaShape := 0;
        dtmSubPoints[0].Color := i;
        dtmSubPoints[0].Tolerance := tole;
      end;

      dtmSubPoints[0].x := 994;
      dtmSubPoints[0].y := 244;
     
      dtmSubPoints[1].x := 986;
      dtmSubPoints[1].y := 258;
     
      dtmSubPoints[2].x := 987;
      dtmSubPoints[2].y := 227;
     
      dtmSubPoints[3].x := 991;
      dtmSubPoints[3].y := 216;
     
      dtmSubPoints[4].x := 984;
      dtmSubPoints[4].y := 267;
     
      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;
      Result := AddDTM(TempTDTM);
    end;
    Voila, shortened it by a lot and makes it so much easier to view the separate points Of course, you can put the for loop at the end and have the points before, but it makes no difference in the end.

    Otherwise, nice tutorial, though in your try except end DDTM procedure, if it finds the DTM then it doesn't free it which is very naughty of you!
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  6. #6
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Your answer on this question -->How To Put the (D) in (D)DTMs.

    Can be shortened to You have DTM then add a D to DTM so DDTM

    Not funny, but nice tutorial
    ~Hermen

  7. #7
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    for x := Low(dtmSubPoints) to High(dtmSubPoints) do
      begin
        dtmSubPoints[0].AreaSize := 0;
        dtmSubPoints[0].AreaShape := 0;
        dtmSubPoints[0].Color := i;
        dtmSubPoints[0].Tolerance := tole;
      end;


    You mean


    SCAR Code:
    for x := Low(dtmSubPoints) to High(dtmSubPoints) do
      begin
        dtmSubPoints[x].AreaSize := 0;
        dtmSubPoints[x].AreaShape := 0;
        dtmSubPoints[x].Color := i;
        dtmSubPoints[x].Tolerance := tole;
      end;

    or (HaH! Even shorter.)


    SCAR Code:
    for x := Low(dtmSubPoints) to High(dtmSubPoints) do
      with dtmSubPoints[x] do
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;



    But yup, will add that now.
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  8. #8
    Join Date
    Mar 2008
    Location
    ::1
    Posts
    915
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Nice Tut! Too many people just read the DDTM tutorials and then don't realize how much better you can make a DDTM. I.E. Me a few days ago........ .

    Records and Types Save Code (and make you look better)
    Quote Originally Posted by Wizzup? View Post
    Is it possible to make Runescape a 2D game with this?... That would greatly simplify... Just about anything.

  9. #9
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    for x := Low(dtmSubPoints) to High(dtmSubPoints) do
      with dtmSubPoints[x] do
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;

    ha this 0,0000000001 milisecs faster

    SCAR Code:
    x := Low(dtmSubPoints);
    H := (dtmSubPoints) ;
    for X to H do
      with dtmSubPoints[x] do
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;
    Should work
    ~Hermen

  10. #10
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    IRC LOG:

    <mixster> for X to H do
    <mixster> HE NEEDS TO DIE
    <mixster> I seriously think I should report for crimes against Scarmanity
    <LeeLokHin> That is actually faster, by a bit. He just forgot to add high(dtmSubPoints);
    <mixster> no, for x to h!
    <mixster> no, for x to h!
    <mixster> please tell me you don't see the flaw in that
    <LeeLokHin> for X to H do
    <mixster> for X := 0 to H do
    <LeeLokHin> I think he edited.
    <LeeLokHin> Oh
    <LeeLokHin> F*ck me
    <LeeLokHin> Mind me quoting this?
    <mixster> nope, go for it
    <mixster> Only fail by me was leaving it as 0 instead of changing to x, but he needs to be put down for that :s
    <mixster> Do you know what would rock as a Best Before date?
    <mixster> Just having it say "yesterday"
    <Narcle> "Scarmanity" rofl
    <mixster> It made me cringe and shout racial slurs at him
    SCAR Code:
    x := Low(dtmSubPoints);
    H := High(dtmSubPoints) ;  //Mistake Hear!
    for t:= X to H do  //Mistake Hear Too!
      with dtmSubPoints[t] do  
      begin
        AreaSize := 0;
        AreaShape := 0;
        Color := i;
        Tolerance := tole;
      end;

    /me hands epic phail to Hermpie




    EDIT:

    The more I think about it, the more I think that i'm an idiot, and mixster is correct.

    LeeLokHin: Please add "mixster thinks this is fastest" then have just the for loop with "for x := 0 to 4 do" followed by the with begin end crap
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  11. #11
    Join Date
    Oct 2008
    Location
    The Netherlands
    Posts
    29
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It's just kinda hard for me to try becouse I'm barely used to DTM's. Cool guide though...

  12. #12
    Join Date
    Nov 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ty very much

  13. #13
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    This is really neat, I found it informative. But why is it considered outdated? I'm bumping this.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


Thread Information

Users Browsing this Thread

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

Similar Threads

  1. DTMs
    By Jackrawl in forum OSR Help
    Replies: 6
    Last Post: 11-25-2007, 09:00 PM
  2. DTMs
    By HarryJames in forum OSR Help
    Replies: 12
    Last Post: 03-21-2007, 09:19 PM
  3. Need Help with DTMS!!!!
    By diamondhero6 in forum OSR Help
    Replies: 5
    Last Post: 03-17-2007, 02:42 AM
  4. dtms?
    By shadowblade in forum OSR Help
    Replies: 8
    Last Post: 12-06-2006, 12:03 PM

Posting Permissions

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