Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

(EO 2.0) RMXP Autotiles


MeteorRain
 Share

Recommended Posts

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_Count
End 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 Long
Dim 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 Sub

errorhandler:
    HandleError "BltMapTile", "modDirectDraw7", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End 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 If
End Function

Public 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_Count
End Enum
```
Now go to frmEditors_Map

Go to the Layers frame and add an options button. Call it optLayer and caption it Autotile.

Now give mask an index number of 2
mask2 index 4
fringe 5
fringe2 6
and autotile 3
leave ground on 1

Now autotiles should work.
Link to comment
Share on other sites

@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. :p

It's not overhead at all. It just comes down to my really, really shitty maths. xD

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.

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

@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 correctly

If 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

  • 2 months later...
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

@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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...