MeteorRain Posted December 31, 2011 Author Share Posted December 31, 2011 Note: this is a fixed version of this (or atleast how I got it working): http://www.touchofdeathforums.com/smf/index.php/topic,75210.msg812308.html#msg812308**Server Side:**Open **modEnumerations**Search for **Public Enum Maplayer** and replace it with the following:```Public Enum MapLayer  Ground = 1  Autotile  Mask  Mask2  Fringe  Fringe2  ' Make sure Layer_Count is below everything else  Layer_CountEnd Enum```**Client Side:**Open **modGameLogic**Search for **If tmr25 < Tick** in **modGameLoop**Before "If tmr25 < Tick Then" add:```    If tmr250 < Tick Then     If autoAnim < 3 Then        autoAnim = autoAnim + 1      Else        autoAnim = 0      End If      tmr250 = GetTickCount + 250    End If```In the same sub, below```Dim tmr10000 As Long```add:```Dim tmr250 As LongDim Autoanim As Long```Open **modGameEditors**Search for **If EditorTileWidth = 1 And EditorTileHeight = 1 Then**Replace it with:```If (EditorTileWidth = 1 And EditorTileHeight = 1) Or CurLayer = MapLayer.Autotile Then 'single tile```Search for **frmEditor_Map.shpSelected.height = PIC_Y**add below```If frmEditor_Map.optLayer(MapLayer.Autotile) Then      EditorTileX = (X \ 32)      EditorTileY = (Y \ 32)      EditorTileWidth = 3      EditorTileHeight = 4      frmEditor_Map.shpSelected.top = EditorTileY * PIC_Y      frmEditor_Map.shpSelected.Left = EditorTileX * PIC_X      frmEditor_Map.shpSelected.width = 96      frmEditor_Map.shpSelected.height = 128    End If```Open **modDirectDraw7**Open **modDirectDraw7**Search for **BltMapTile**and replace it with the following```Public Sub BltMapTile(ByVal X As Long, ByVal Y As Long)  Dim rec As DxVBLib.RECT  Dim i As Long  With Map.Tile(X, Y)    For i = MapLayer.Ground To MapLayer.Mask2      ' skip tile if tileset isn't set      If i = MapLayer.Autotile Then        BltAutotile X, Y      Else        If .Layer(i).Tileset > 0 And .Layer(i).Tileset <= NumTileSets Then          ' sort out rec          rec.top = .Layer(i).Y * PIC_Y          rec.Bottom = rec.top + PIC_Y          rec.Left = .Layer(i).X * PIC_X          rec.Right = rec.Left + PIC_X          ' render          Call Engine_BltFast(ConvertMapX(X * PIC_X), ConvertMapY(Y * PIC_Y), DDS_Tileset(.Layer(i).Tileset), rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)        End If      End If    Next  End With  ' Error handler  Exit Suberrorhandler:  HandleError "BltMapTile", "modDirectDraw7", Err.Number, Err.Description, Err.Source, Err.HelpContext  Err.Clear  Exit SubEnd Sub```Now go to the bottom of the **modDirectDraw7** and put the following code:```Public Function isAutotileMatch(ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Boolean  isAutotileMatch = False  ' end of the map, pretend there's a tile there :3  If x1 < 0 Or x1 > Map.MaxX Or x2 < 0 Or x2 > Map.MaxX Or y1 < 0 Or y1 > Map.MaxY Or y2 < 0 Or y2 > Map.MaxY Then    isAutotileMatch = True  Else    If Map.Tile(x1, y1).Layer(MapLayer.Autotile).X = Map.Tile(x2, y2).Layer(MapLayer.Autotile).X Then      If Map.Tile(x1, y1).Layer(MapLayer.Autotile).Y = Map.Tile(x2, y2).Layer(MapLayer.Autotile).Y Then        If Map.Tile(x1, y1).Layer(MapLayer.Autotile).Tileset = Map.Tile(x2, y2).Layer(MapLayer.Autotile).Tileset Then          isAutotileMatch = True        End If      End If    End If  End IfEnd FunctionPublic Sub BltAutotile(ByVal X As Long, ByVal Y As Long)  Dim rec As DxVBLib.RECT  Dim AutoSet As Long  Dim bTop As Long  Dim bLeft As Long  AutoSet = Map.Tile(X, Y).Layer(MapLayer.Autotile).Tileset  If AutoSet <= 0 Or AutoSet > NumTileSets Then Exit Sub  bTop = Map.Tile(X, Y).Layer(MapLayer.Autotile).Y * 32  bLeft = Map.Tile(X, Y).Layer(MapLayer.Autotile).X * 32  ' animate  If DDSD_Tileset(AutoSet).lWidth = 384 Then bLeft = autoAnim * 96  ' ########################  ' ########################  ' ###  top left  ###  ' ########################  ' ########################  With rec    .top = bTop + 32    .Bottom = .top + 16    .Left = bLeft + 0    .Right = .Left + 16  End With  ' 1-dir horizontal join  If isAutotileMatch(X, Y, X - 1, Y) Then    With rec      .top = bTop + 32      .Bottom = .top + 16      .Left = bLeft + 64      .Right = .Left + 16    End With    ' 2-dir horizontal join    If isAutotileMatch(X, Y, X + 1, Y) Then      With rec        .top = bTop + 32        .Bottom = .top + 16        .Left = bLeft + 32        .Right = .Left + 16      End With    End If  End If  ' 1-dir vertical join  If isAutotileMatch(X, Y, X, Y - 1) Then    With rec      .top = bTop + 96      .Bottom = .top + 16      .Left = bLeft + 0      .Right = .Left + 16    End With    ' 2-dir vertical join    If isAutotileMatch(X, Y, X, Y + 1) Then      With rec        .top = bTop + 64        .Bottom = .top + 16        .Left = bLeft + 0        .Right = .Left + 16      End With    End If  End If  ' 1-dir corner join  If isAutotileMatch(X, Y, X - 1, Y) And isAutotileMatch(X, Y, X, Y - 1) Then    With rec      .top = bTop + 0      .Bottom = .top + 16      .Left = bLeft + 64      .Right = .Left + 16    End With    ' 2-dir corner join    If isAutotileMatch(X, Y, X - 1, Y - 1) Then      With rec        .top = bTop + 96        .Bottom = .top + 16        .Left = bLeft + 64        .Right = .Left + 16      End With    End If  End If  ' surrounded to the left or top  If (isAutotileMatch(X, Y, X - 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X, Y + 1) And isAutotileMatch(X, Y, X - 1, Y - 1) And _  isAutotileMatch(X, Y, X - 1, Y + 1)) Or (isAutotileMatch(X, Y, X - 1, Y) And _  isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X + 1, Y - 1) And isAutotileMatch(X, Y, X - 1, Y - 1)) Then    With rec      .top = bTop + 64      .Bottom = .top + 16      .Left = bLeft + 32      .Right = .Left + 16    End With  End If  Call Engine_BltFast(ConvertMapX((X * PIC_X)), ConvertMapY((Y * PIC_Y)), DDS_Tileset(AutoSet), rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)  ' ########################  ' ########################  ' ###  top right  ###  ' ########################  ' ########################  With rec    .top = bTop + 32    .Bottom = .top + 16    .Left = bLeft + 80    .Right = .Left + 16  End With  ' 1-dir horizontal join  If isAutotileMatch(X, Y, X + 1, Y) Then    With rec      .top = bTop + 32      .Bottom = .top + 16      .Left = bLeft + 16      .Right = .Left + 16    End With    ' 2-dir horizontal join    If isAutotileMatch(X, Y, X - 1, Y) Then      With rec        .top = bTop + 32        .Bottom = .top + 16        .Left = bLeft + 48        .Right = .Left + 16      End With    End If  End If  ' 1-dir vertical join  If isAutotileMatch(X, Y, X, Y - 1) Then    With rec      .top = bTop + 96      .Bottom = .top + 16      .Left = bLeft + 80      .Right = .Left + 16    End With    ' 2-dir vertical join    If isAutotileMatch(X, Y, X, Y + 1) Then      With rec        .top = bTop + 64        .Bottom = .top + 16        .Left = bLeft + 80        .Right = .Left + 16      End With    End If  End If  ' 1-dir corner join  If isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y - 1) Then    With rec      .top = bTop + 0      .Bottom = .top + 16      .Left = bLeft + 80      .Right = .Left + 16    End With    ' 2-dir corner join    If isAutotileMatch(X, Y, X + 1, Y - 1) Then      With rec        .top = bTop + 96        .Bottom = .top + 16        .Left = bLeft + 16        .Right = .Left + 16      End With    End If  End If  ' surrounded to the right or top  If (isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X, Y + 1) And isAutotileMatch(X, Y, X + 1, Y - 1) And _  isAutotileMatch(X, Y, X + 1, Y + 1)) Or (isAutotileMatch(X, Y, X - 1, Y) And _  isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X + 1, Y - 1) And isAutotileMatch(X, Y, X - 1, Y - 1)) Then    With rec      .top = bTop + 64      .Bottom = .top + 16      .Left = bLeft + 48      .Right = .Left + 16    End With  End If  Call Engine_BltFast(ConvertMapX((X * PIC_X) + 16), ConvertMapY((Y * PIC_Y)), DDS_Tileset(AutoSet), rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)  ' ########################  ' ########################  ' ### bottom left  ###  ' ########################  ' ########################  With rec    .top = bTop + 112    .Bottom = .top + 16    .Left = bLeft + 0    .Right = .Left + 16  End With  ' 1-dir horizontal join  If isAutotileMatch(X, Y, X - 1, Y) Then    With rec      .top = bTop + 112      .Bottom = .top + 16      .Left = bLeft + 64      .Right = .Left + 16    End With    ' 2-dir horizontal join    If isAutotileMatch(X, Y, X + 1, Y) Then      With rec        .top = bTop + 112        .Bottom = .top + 16        .Left = bLeft + 32        .Right = .Left + 16      End With    End If  End If  ' 1-dir vertical join  If isAutotileMatch(X, Y, X, Y + 1) Then    With rec      .top = bTop + 48      .Bottom = .top + 16      .Left = bLeft + 0      .Right = .Left + 16    End With    ' 2-dir vertical join    If isAutotileMatch(X, Y, X, Y - 1) Then      With rec        .top = bTop + 80        .Bottom = .top + 16        .Left = bLeft + 0        .Right = .Left + 16      End With    End If  End If  ' 1-dir corner join  If isAutotileMatch(X, Y, X - 1, Y) And isAutotileMatch(X, Y, X, Y + 1) Then    With rec      .top = bTop + 16      .Bottom = .top + 16      .Left = bLeft + 64      .Right = .Left + 16    End With    ' 2-dir corner join    If isAutotileMatch(X, Y, X - 1, Y + 1) Then      With rec        .top = bTop + 48        .Bottom = .top + 16        .Left = bLeft + 64        .Right = .Left + 16      End With    End If  End If  ' surrounded to the left or top  If (isAutotileMatch(X, Y, X - 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X, Y + 1) And isAutotileMatch(X, Y, X - 1, Y - 1) And _  isAutotileMatch(X, Y, X - 1, Y + 1)) Or (isAutotileMatch(X, Y, X - 1, Y) And _  isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y + 1) And _  isAutotileMatch(X, Y, X + 1, Y + 1) And isAutotileMatch(X, Y, X - 1, Y + 1)) Then    With rec      .top = bTop + 80      .Bottom = .top + 16      .Left = bLeft + 64      .Right = .Left + 16    End With  End If  Call Engine_BltFast(ConvertMapX((X * PIC_X)), ConvertMapY((Y * PIC_Y) + 16), DDS_Tileset(AutoSet), rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)  ' ########################  ' ########################  ' ### bottom right ###  ' ########################  ' ########################  With rec    .top = bTop + 112    .Bottom = .top + 16    .Left = bLeft + 80    .Right = .Left + 16  End With  ' 1-dir horizontal join  If isAutotileMatch(X, Y, X + 1, Y) Then    With rec      .top = bTop + 112      .Bottom = .top + 16      .Left = bLeft + 16      .Right = .Left + 16    End With    ' 2-dir horizontal join    If isAutotileMatch(X, Y, X - 1, Y) Then      With rec        .top = bTop + 112        .Bottom = .top + 16        .Left = bLeft + 48        .Right = .Left + 16      End With    End If  End If  ' 1-dir vertical join  If isAutotileMatch(X, Y, X, Y + 1) Then    With rec      .top = bTop + 48      .Bottom = .top + 16      .Left = bLeft + 80      .Right = .Left + 16    End With    ' 2-dir vertical join    If isAutotileMatch(X, Y, X, Y - 1) Then      With rec        .top = bTop + 80        .Bottom = .top + 16        .Left = bLeft + 80        .Right = .Left + 16      End With    End If  End If  ' 1-dir corner join  If isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y + 1) Then    With rec      .top = bTop + 16      .Bottom = .top + 16      .Left = bLeft + 80      .Right = .Left + 16    End With    ' 2-dir corner join    If isAutotileMatch(X, Y, X + 1, Y + 1) Then      With rec        .top = bTop + 48        .Bottom = .top + 16        .Left = bLeft + 16        .Right = .Left + 16      End With    End If  End If  ' surrounded to the left or top  If (isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y - 1) And _  isAutotileMatch(X, Y, X, Y + 1) And isAutotileMatch(X, Y, X + 1, Y - 1) And _  isAutotileMatch(X, Y, X + 1, Y + 1)) Or (isAutotileMatch(X, Y, X - 1, Y) And _  isAutotileMatch(X, Y, X + 1, Y) And isAutotileMatch(X, Y, X, Y + 1) And _  isAutotileMatch(X, Y, X + 1, Y + 1) And isAutotileMatch(X, Y, X - 1, Y + 1)) Then    With rec      .top = bTop + 80      .Bottom = .top + 16      .Left = bLeft + 48      .Right = .Left + 16    End With  End If  Call Engine_BltFast(ConvertMapX((X * PIC_X) + 16), ConvertMapY((Y * PIC_Y) + 16), DDS_Tileset(AutoSet), rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)End Sub```Open **modEnumerations**Search for **Public Enum MapLayer**And replace it by the following```Public Enum MapLayer  Ground = 1  Autotile  Mask  Mask2  Fringe  Fringe2  ' Make sure Layer_Count is below everything else  Layer_CountEnd Enum```Now go to frmEditors_MapGo to the Layers frame and add an options button. Call it optLayer and caption it Autotile.Now give mask an index number of 2mask2 index 4fringe 5fringe2 6and autotile 3leave ground on 1Now autotiles should work. Link to comment Share on other sites More sharing options...
Robin Posted December 31, 2011 Share Posted December 31, 2011 Stop doing half-arsed rips of my work. The caching system was there for a **_very_** important reason. Link to comment Share on other sites More sharing options...
emblem Posted January 2, 2012 Share Posted January 2, 2012 @Scrooge:> The caching system was there for a **_very_** important reason.Because the way you coded the autotiles caused massive amounts of overhead? :)Haha, I'm just poking fun at you Robin, don't take it too seriously. :p Link to comment Share on other sites More sharing options...
Robin Posted January 2, 2012 Share Posted January 2, 2012 @Scootaloo:> Because the way you coded the autotiles caused massive amounts of overhead? :)> > Haha, I'm just poking fun at you Robin, don't take it too seriously. :pIt's not overhead at all. It just comes down to my really, really shitty maths. xDBut seriously, no matter how you program it you need a minimum of 4 calculations per tile 4 times per loop. In a 30x30 map with 5 layers that's at least 72,000 calculations per loop.You either stagger it or cache it. I chose to cache it. If people want to do it a different way then so be it, but you can't take a system which is designed one way and then just dump it in to a render function and expect it to work. Link to comment Share on other sites More sharing options...
emblem Posted January 2, 2012 Share Posted January 2, 2012 @Scrooge:> But seriously, no matter how you program it you need a minimum of 4 calculations per tile 4 times per loop. In a 30x30 map with 5 layers that's at least 72,000 calculations per loop.The way I did it was honestly pretty fast. I created a checksum of the tiles around it by setting bits in a byte depending on if there was an autotile or not in a specific square around the tile you're placing.So, bit 1 is the top left tile, bit 2 is the tile directly above, etc.This gave me a value from 0 to 255, which I then used to look up the four subtiles in a pre-calculated subtile array cache thing.So basically every frame all I was doing was 8 bitwise or's per autotile, and a CopyMemory call if I remember correctlyIf I added actual caching to that, oh my.. xD> If people want to do it a different way then so be it, but you can't take a system which is designed one way and then just dump it in to a render function and expect it to work.Okay I have to agree with this though. As much fun as making fun of your crappy maths is (it really is!), ripping out code yet leaving behind a very important part of it is just plain stupid.I wrote this post while half asleep.. I'm going to look back at it and facepalm in about 7 hours probably. :D Link to comment Share on other sites More sharing options...
PVJsquad Posted January 3, 2012 Share Posted January 3, 2012 whether to remove the entire map? Link to comment Share on other sites More sharing options...
Wortel Angels Posted March 25, 2012 Share Posted March 25, 2012 I got an compile error :([![](http://www7.pic-upload.de/thumb/25.03.12/gsiybk1wsbnw.png)](http://www.pic-upload.de/view-13481266/Unbenannt.png.html) Link to comment Share on other sites More sharing options...
Zexion Posted March 26, 2012 Share Posted March 26, 2012 @Mortal:> I got an compile error :(probably forgot/added this in the wrong place:```Dim tmr250 As LongDim Autoanim As Long``` Link to comment Share on other sites More sharing options...
Justn Posted March 26, 2012 Share Posted March 26, 2012 Mortal angel why are you going to mess up you game with a shitty tutorial like this? If u read any of the post under it you would clearly see why you shouldn't use this… Sometimes less is more if u can't code it or pay someone to do it right :\ Link to comment Share on other sites More sharing options...
Wortel Angels Posted March 26, 2012 Share Posted March 26, 2012 I dont use it anymore xD i think i make it on the old way.. without autotiles :DOfftopi–-Justn do you know how can i fix this ->http://www.touchofdeathforums.com/smf/index.php/topic,78990.new.html#new Link to comment Share on other sites More sharing options...
minipimp Posted March 30, 2012 Share Posted March 30, 2012 okay, so I have one question, does this work? Robin made it sound like this isnt the correct way to implement auto tiles in the engine.. I want to know if this code will work.Anyone know if this is the correct code? Link to comment Share on other sites More sharing options...
Ruins of Hell Posted March 30, 2012 Share Posted March 30, 2012 @Hey880:> okay, so I have one question, does this work? Robin made it sound like this isnt the correct way to implement auto tiles in the engine.. I want to know if this code will work.> Anyone know if this is the correct code?It will work, but there will be a massive overhead because there is no caching system. So yes, it will work, but no, it is not the correct way to do it. Link to comment Share on other sites More sharing options...
minipimp Posted March 31, 2012 Share Posted March 31, 2012 Is there an actual tutorial on how to add the auto tiles correctly?That would be more helpful then the junk code in this thread I bet for alot of people.Ill search for one, but if you know a tutorial please could you give a link if you would , I sure would appreciate it. Link to comment Share on other sites More sharing options...
erkro1 Posted March 31, 2012 Share Posted March 31, 2012 Does the Map Animation system in WN has caching? Link to comment Share on other sites More sharing options...
minipimp Posted March 31, 2012 Share Posted March 31, 2012 It has ResourceCache, but I dont see anything for map animation. Link to comment Share on other sites More sharing options...
erkro1 Posted April 1, 2012 Share Posted April 1, 2012 @Hey880:> It has ResourceCache, but I dont see anything for map animation.It has map animation, in Map Editor go to Animation under Attributes, I'm only wondering if thats builded good. Link to comment Share on other sites More sharing options...
minipimp Posted April 1, 2012 Share Posted April 1, 2012 Yeah I see it.I have a version of WN with autotiles working. but I want them in a custom edited version I have.I copied the codes needed to be copied, they work, but when I try to "fill" the layer with a tile and when i try to change map size and click save it gives me an RTE error 9.and goes to this line of code```Sprite = NPC(MapNpc(MapNpcNum).num).Sprite```Anyone know what I could do? I mean, there was only a little bit more code that I copied that wasnt in this tutorial , so its pretty much on this topic of the thread, but any answer would be great! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now