Mirage Source

Free ORPG making software.
It is currently Fri Apr 26, 2024 9:21 am

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Oct 11, 2006 3:28 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
By: William
Difficulty: 3/5 (Medium)
Improvement: Increases the speed in your game. The bigger maps and the more layers you have, the more this code will speed the game up.

Introduction
As it is now, the whole game screen is being covered with tiles every second. So I thought, wouldn't it be better if only the tiles that needs to be updated are redrawn. Thats basicly what this tutorial will do. It will blit the tiles around you, nothing else. If your game has a larger player/enemy size. Then you need to edit the xChange1-2 and yChange1-2. That might be a bit tricky if you dont understand the code. But just ask and I help you out.

Hopefully this will speed up the game :) Tell me if it dont.

Backup your source before adding this, you never know what things can do :P

But in order for this system to work, these things need to be changed/added:
  • BltTile Change [Completed]
  • BltFringe Change [Completed]
  • Blt tile to cover the text (if your using the inbuilt system with the text on the screen. You dont need to change this if you use a textbox instead). Add [Completed]
  • Blt tiles around the enemies when they move. Add [Completed]
  • When saving the map - refill the screen. Add [Completed]
  • Need to blit around the other players when they move.Add
  • Refresh the screen when you enter a new map Add [Completed]
  • /Respawn command needs to have bltTile and bltFringe. Add [Completed]
So that list is pretty big. A few things needs to be changed and a lot of things need to be added. This tutorial will only cover the parts in MSE, it will not include the other layers (from GSD's tutorial), so no Mask1, Fringe2 and such.

Start with adding this at the top of Public Sub GameLoop():
Code:
Dim xChange1 As Byte, xChange2 As Byte, yChange1 As Byte, yChange2 As Byte
Dim x1 As Long, y1 As Long


Replace:
Code:
' Blit out tiles layers ground/anim1/anim2
For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltTile(x, y)
                Next x
            Next y

With this code below. This basicly checks were your player is and we now blit the tiles around him instead of on the whole map.
Code:
If GraphicInput1 = 0 Then
            GraphicInput1 = 1
            For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltTile(x, y)
                Next x
            Next y
        Else
        If InEditor Then
            For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltTile(x, y)
                Next x
            Next y
        Else
            yChange1 = 2
            yChange2 = 2
            xChange1 = 2
            xChange2 = 2
           
            If GetPlayerY(MyIndex) - 2 < 0 Then yChange1 = 1
            If GetPlayerY(MyIndex) + 2 > MAX_MAPY Then yChange2 = 1
            If GetPlayerX(MyIndex) - 2 < 1 Then xChange1 = 1
            If GetPlayerX(MyIndex) + 2 > MAX_MAPX Then xChange2 = 1
           
            If GetPlayerY(MyIndex) - 1 < 0 Then yChange1 = 0
            If GetPlayerY(MyIndex) + 1 > MAX_MAPY Then yChange2 = 0
            If GetPlayerX(MyIndex) - 1 < 0 Then xChange1 = 0
            If GetPlayerX(MyIndex) + 1 > MAX_MAPX Then xChange2 = 0
           
            For y = GetPlayerY(MyIndex) - yChange1 To GetPlayerY(MyIndex) + yChange2
                For x = GetPlayerX(MyIndex) - xChange1 To GetPlayerX(MyIndex) + xChange2
                   Call BltTile(x, y)
                Next x
            Next y
        End If
        End If


Now, change this:
Code:
' Blit out tile layer fringe
For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltFringeTile(x, y)
                Next x
            Next y

To the code below. This part is pretty much as the above one, but this does it for the fringe layer instead.
Code:
' Blit out tile layer fringe
        If GraphicInput2 = 0 Then
            GraphicInput2 = 1
            For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltFringeTile(x, y)
                Next x
            Next y
        Else
        If InEditor Then
            For y = 0 To MAX_MAPY
                For x = 0 To MAX_MAPX
                    Call BltFringeTile(x, y)
                Next x
            Next y
        Else
            yChange1 = 2
            yChange2 = 2
            xChange1 = 2
            xChange2 = 2
           
            If GetPlayerY(MyIndex) - 2 < 0 Then yChange1 = 1
            If GetPlayerY(MyIndex) + 2 > MAX_MAPY Then yChange2 = 1
            If GetPlayerX(MyIndex) - 2 < 1 Then xChange1 = 1
            If GetPlayerX(MyIndex) + 2 > MAX_MAPX Then xChange2 = 1
           
            If GetPlayerY(MyIndex) - 1 < 0 Then yChange1 = 0
            If GetPlayerY(MyIndex) + 1 > MAX_MAPY Then yChange2 = 0
            If GetPlayerX(MyIndex) - 1 < 0 Then xChange1 = 0
            If GetPlayerX(MyIndex) + 1 > MAX_MAPX Then xChange2 = 0
           
            For y = GetPlayerY(MyIndex) - yChange1 To GetPlayerY(MyIndex) + yChange2
                For x = GetPlayerX(MyIndex) - xChange1 To GetPlayerX(MyIndex) + xChange2
                   Call BltFringeTile(x, y)
                Next x
            Next y
        End If
        End If

Now, above this line:
Code:
' Blit out tiles layers ground/anim1/anim2

Add the code below. This will make you able to write to the chat. If your using textboxes for your chat (both the writing part and the text part) then you dont need to add this.
Code:
' Blit Tile to cover text
        For x = 0 To MAX_MAPX
            Call BltTile(x, MAX_MAPY)
        Next x


Now remove:
Code:
' Blit out the items
        For i = 1 To MAX_MAP_ITEMS
            If MapItem(i).Num > 0 Then
                Call BltItem(i)
            End If
        Next i


So now above this:
Code:
' Blit out the npcs
        For i = 1 To MAX_MAP_NPCS
            Call BltNpc(i)
        Next i

Add the code below. This will blit the tiles around the enemy, similar to the technique used for the player before.
Code:
' Blit out the tiles around the npc
        For i = 1 To MAX_MAP_NPCS
            ' Make sure that theres an npc there, and if not exit the sub
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltTile(x1, y1)
                    Next x1
                Next y1
            End If
        Next i
       
        ' Blit out the tiles around the player
        For i = 1 To MAX_PLAYERS
            ' Make sure that theres a player here
            If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                ' Blit tiles around the player
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If GetPlayerY(i) - 2 < 0 Then yChange1 = 1
                If GetPlayerY(i) + 2 > MAX_MAPY Then yChange2 = 1
                If GetPlayerX(i) - 2 < 1 Then xChange1 = 1
                If GetPlayerX(i) + 2 > MAX_MAPX Then xChange2 = 1
           
                If GetPlayerY(i) - 1 < 0 Then yChange1 = 0
                If GetPlayerY(i) + 1 > MAX_MAPY Then yChange2 = 0
                If GetPlayerX(i) - 1 < 0 Then xChange1 = 0
                If GetPlayerX(i) + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = GetPlayerY(i) - yChange1 To GetPlayerY(i) + yChange2
                    For x1 = (GetPlayerX(i) - xChange1) To (GetPlayerX(i) + xChange2)
                       Call BltTile(x1, y1)
                    Next x1
                Next y1
            End If
        Next i
       
        ' Blit out the items
        For i = 1 To MAX_MAP_ITEMS
            If MapItem(i).Num > 0 Then
                Call BltItem(i)
            End If
        Next i

So now below this:
Code:
' Blit out the npcs
        For i = 1 To MAX_MAP_NPCS
            Call BltNpc(i)
        Next i

Add this code:
Code:
' Blit out the tiles around the npc
        For i = 1 To MAX_MAP_NPCS
            ' Make sure that theres an npc there, and if not exit the sub
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltFringeTile(x1, y1)
                    Next x1
                Next y1
            End If
        Next i


Find this:
Code:
' ::::::::::::::::::::::
    ' :: Npc spawn packet ::
    ' ::::::::::::::::::::::
    If LCase(Parse(0)) = "spawnnpc" Then

In the end of that (before exit sub) add the code below. This will make it so that the map is updated when the enemies is set to be respawned.
Code:
' Blit Tiles
        For x = 0 To MAX_MAPX
            For y = 0 To MAX_MAPY
                Call BltTile(x, y)
                Call BltFringeTile(x, y)
            Next y
        Next x

Now add these in a module (modGlobal):
Code:
' Checks if the map has been updated
Public GraphicInput1 As Byte ' For the first layer (bltTile)
Public GraphicInput2 As Byte ' for the other layer (bltFringeTile)

Now find:
Code:
' Play music
        Call StopMidi
        If Map.Music > 0 Then
            Call PlayMidi("music" & Trim(STR(Map.Music)) & ".mid")
        End If

Below that, add the code below:
Code:
GraphicInput1 = 0
GraphicInput2 = 0

Now, below this:
Code:
' Blit out players
        For i = 1 To MAX_PLAYERS
            If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                Call BltPlayer(i)
            End If
        Next i

Add this code:
Code:
' Blit out the tiles around the player
        For i = 1 To MAX_PLAYERS
            ' Make sure that theres an player there
            If IsPlaying(i) And GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                ' Blit tiles around the player
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If GetPlayerY(i) - 2 < 0 Then yChange1 = 1
                If GetPlayerY(i) + 2 > MAX_MAPY Then yChange2 = 1
                If GetPlayerX(i) - 2 < 1 Then xChange1 = 1
                If GetPlayerX(i) + 2 > MAX_MAPX Then xChange2 = 1
           
                If GetPlayerY(i) - 1 < 0 Then yChange1 = 0
                If GetPlayerY(i) + 1 > MAX_MAPY Then yChange2 = 0
                If GetPlayerX(i) - 1 < 0 Then xChange1 = 0
                If GetPlayerX(i) + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = GetPlayerY(i) - yChange1 To GetPlayerY(i) + yChange2
                    For x1 = (GetPlayerX(i) - xChange1) To (GetPlayerX(i) + xChange2)
                       Call BltFringeTile(x1, y1)
                    Next x1
                Next y1
            End If
        Next i


That covers 8 of the 8 points in the begining of the topic. Thats it :) Should be working fine.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Last edited by William on Thu Oct 12, 2006 7:52 pm, edited 27 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 4:03 pm 
Offline
Newbie

Joined: Tue Sep 26, 2006 9:34 pm
Posts: 1
hmm....would work good because the engine otherwise needs to redo everything a lot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 4:47 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
I think it will speed it up a bit. Eventhough it might seem like there are more things that needs to be blitted, thats not really the case. Since instead of blitting everything at one time all the time. Pieces are being blitted at different times.

The larger maps you have, the more effective it will be compared to the old system.

Still I want one of you guys who knows a lot about programming to answer if it's noticeable difference. :)

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:17 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
I've been toying with some ideas like this, and I have had a few thoughts on the subject..

I think the best, overall, way of speeding up the graphics would be to store all layers under the players/npcs/items/etc. in one surface.. Then blt that surface to the backbuffer, and blt your npcs/players/items/etc. over the top of that.. Then blt everything that goes over the players/npcs/items/etc on top of that.. (Maybe store those layers on a surface too?)

But if you have 32x64 sprites, you will run into issues where a tile may need to be blt under the player if they are standing below that tile, and on top of the player if s/he is on or above that tile.

This particular way will save a lot of for x = 0 to max_mapx/for y = 0 to max_mapy, because you'd blt most of the stuff when the player enters the map, and then only have to worry about the items/players/npcs/etc. as you loop.

That's just my take on it.. I'm not perfect.. But I don't think adding extra 'checks' to see if something needs changing is going to speed the blting up.. It could help a little, but I like to think of the big picture. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:22 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Well I don't really understand how to do the surfaces stuffs. But you said that the system I created checked if there should be a change.

My system only checks how far it should blt. For example, you can't blit outside the map, so when your standing on the very left side of the map, xChange1 will be 0 and not blit on the left side of him.

But I got a feeling that you dont like the idea. So is it a waste of time then to complete it?

Edit: If you try it out with a blank MSE you will notice how it works.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:31 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
Here's what I suggest..

Create 3 new surfaces..

DD_GroundLevelSurface
DD_PlayerLevelSurface
DD_OverPlayerSurface

Obviously you'll still need your DDSDs for those..

Initialize your new 3 surfaces with a width and height of whatever you plan to keep in memory.. If you are doing surrounding maps, then you might do:
Code:
DDSD_GroundLevelSurface.lWidth = 3 * MAX_MAPX * PIC_X
DDSD_GroundLevelSurface.lHeight = 3 * MAX_MAPY * PIC_Y

Set DD_GroundLevelSurface = DD.CreateSurface(DDSD_GroundLevelSurface)

Obviously there is some stuff missing, which you can find in modDirectX.bas where the other surfaces are initialized..

Then, when the player enters the game or changes map, reblt the ground, and aboveplayer surfaces for whatever they might be able to see.. (blt each tile once...) Then, in your game loop, blt the items/npcs/players/etc. on the playerlevel surface, and then all you have to do is blt the x/y/w/h of the surfaces (in order... ground, playerlevel, aboveplayer) to the backbuffer, and blt as normal.. You'll save yourself about (guesstimate) 10,000 loops per second at 24 FPS..

All of that was to explain the surface thing for ya a bit better.

I don't think your concept is bad.. I think you just need to put a little more thought into it. I also don't necessarily think mine is the 'end all, be all' way to do it.. But I do believe it could be.. I just need to test it out and stuff, and perfect it. :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:34 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Okay, so you are currently working to optimize the graphic output? Sounds good.

Well I might finish my system, just to prove to myself I can :P And then I might release it since it abviously helping some :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:36 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
I think you should. It is a great idea!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:37 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Verrigan wrote:
I think you should. It is a great idea!


Okay well I finish it then :) Thanks for all the information :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 7:41 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
I think the most efficient way would be to store the 32x32 pixels underneath the character, then blit the player. The next time around, you blit what you stored, then move the character in memory, grab the area underneath the player, and then blit the player, etc.


You have two loops For i = 1 To MAX_MAP_NPCS, consolidate them to one, you don't need to do those loops twice.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 8:26 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Dave wrote:
You have two loops For i = 1 To MAX_MAP_NPCS, consolidate them to one, you don't need to do those loops twice.


Well, the first one is for bltTile and the other one is after the bltNpc, that is bltFringeTile.

And two of those are needed so it works like this:
bltTile - Normal, mask around the npc
bltNPC - Blits the NPC
bltFringeTile - Blits the upper layer around the npc.

If I combine them to one the npc will walk on fringe or below normal.

The further I came to complete this system, the more I started to thinking if this will actually improve the speed. Cause it all became so much coding, compared to so little before (the default).

So the code is ready for testing, I might have missed something. But I dont think so. Also, it would be good if anybody could go through it and compare it with the old to see if it is faster now than before. So I can geet a true statement that this tutorial is good or if it sucks.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 9:00 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
Quote:
So now above this:
Code:
' Blit out the npcs
For i = 1 To MAX_MAP_NPCS
Call BltNpc(i)
Next i

Add the code below. This will blit the tiles around the enemy, similar to the technique used for the player before.
Code:
' Blit out the tiles around the npc
For i = 1 To MAX_MAP_NPCS
' Make sure that theres an npc there, and if not exit the sub
If MapNpc(i).Num > 0 Then
' Blit tiles around the npc
yChange1 = 2
yChange2 = 1
xChange1 = 1
xChange2 = 1

If MapNpc(i).y - 2 < 0 Then yChange1 = 1
If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
If MapNpc(i).x - 2 < 1 Then xChange1 = 1
If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1

If MapNpc(i).y - 1 < 0 Then yChange1 = 0
If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
If MapNpc(i).x - 1 < 0 Then xChange1 = 0
If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0

For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
Call BltTile(x1, y1)
Next x1
Next y1
End If
Next i

So now below this:
Code:
' Blit out the npcs
For i = 1 To MAX_MAP_NPCS
Call BltNpc(i)
Next i

Add this code:
Code:
' Blit out the tiles around the npc
For i = 1 To MAX_MAP_NPCS
' Make sure that theres an npc there, and if not exit the sub
If MapNpc(i).Num > 0 Then
' Blit tiles around the npc
yChange1 = 2
yChange2 = 1
xChange1 = 1
xChange2 = 1

If MapNpc(i).y - 2 < 0 Then yChange1 = 1
If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
If MapNpc(i).x - 2 < 1 Then xChange1 = 1
If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1

If MapNpc(i).y - 1 < 0 Then yChange1 = 0
If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
If MapNpc(i).x - 1 < 0 Then xChange1 = 0
If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0

For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
Call BltFringeTile(x1, y1)
Next x1
Next y1
End If
Next i



IS this not the same?
Code:
For i = 1 To MAX_MAP_NPCS
' Make sure that theres an npc there, and if not exit the sub
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltTile(x1, y1)
                    Next x1
                Next y1
            End If

Call BltNpc(i)

' Blit out the tiles around the npc
        For i = 1 To MAX_MAP_NPCS
            ' Make sure that theres an npc there, and if not exit the sub
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltFringeTile(x1, y1)
                    Next x1
                Next y1
            End If
        Next i

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 9:52 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Well, the code you posted is wrong. So please make sure you post the correct code before posting it.

You still using two For Loops.. I think this is what you mean:
Code:
For i = 1 To MAX_MAP_NPCS
' Make sure that theres an npc there, and if not exit the sub
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltTile(x1, y1)
                    Next x1
                Next y1
            End If

Call BltNpc(i)

            ' Make sure that theres an npc there
            If MapNpc(i).Num > 0 Then
                ' Blit tiles around the npc
                yChange1 = 2
                yChange2 = 1
                xChange1 = 1
                xChange2 = 1
           
                If MapNpc(i).y - 2 < 0 Then yChange1 = 1
                If MapNpc(i).y + 2 > MAX_MAPY Then yChange2 = 1
                If MapNpc(i).x - 2 < 1 Then xChange1 = 1
                If MapNpc(i).x + 2 > MAX_MAPX Then xChange2 = 1
           
                If MapNpc(i).y - 1 < 0 Then yChange1 = 0
                If MapNpc(i).y + 1 > MAX_MAPY Then yChange2 = 0
                If MapNpc(i).x - 1 < 0 Then xChange1 = 0
                If MapNpc(i).x + 1 > MAX_MAPX Then xChange2 = 0
           
                For y1 = MapNpc(i).y - yChange1 To MapNpc(i).y + yChange2
                    For x1 = (MapNpc(i).x - xChange1) To (MapNpc(i).x + xChange2)
                       Call BltFringeTile(x1, y1)
                    Next x1
                Next y1
            End If
Next i


I think I tested that, and it didn't work. But I can test it when I get home. Cause if it works, then I can optimize the MAX_PLAYERS too.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 12:52 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
That code does not work. It will blit it wrong. Here is the source with it installed. Feel free to try it out. You wont notice a different with the new system. Only a small speed difference.

http://www.key2heaven.net/MSEOptimizeGFXOutput.rar

Investigation To Prove the Optimization
Okay, so imagine this: MAX_MAPX * MAX_MAPY
In the unedited version of MSE, the MAX_MAPX = 15 and the MAX_MAPY = 11.

11*15=165 That value shows us how many tiles that are being blit out all the time from bltTile.
165+165=330 That is the value for both (bltTile and bltFringe) of them. And this happens all the time the GameLoop runs.

So I think that value is pretty high. So we will compare 330 with the new value:

First we have: ' Blit Tile to cover text
That is 1*MAX_MAPX = 15.
After that we have:
Code:
For y = GetPlayerY(MyIndex) - yChange1 To GetPlayerY(MyIndex) + yChange2
                For x = GetPlayerX(MyIndex) - xChange1 To GetPlayerX(MyIndex) + xChange2
                   Call BltTile(x, y)
                Next x
            Next y

The largest range on that code is -2 to 2 which is 4 and we have two loops which makes it 4*4=16.

So far, we have 15+16=31. Thats still below 330.
After that we have the same loop 4 times. Which makes it 16*4=64
Now we have 64+31= 95. Still a lot less than 330.

And for the final, we have one more of that loop. That makes it 95+16= 111.

So the difference is 330-111=219 in difference. Thats pretty much, isn't it?

So, now we need to take into account that the code is a little bit longer, and this might slow it down a tiny bit. So lets say it slows it down with 69.

That still gives us a difference of 150. Which is a very good result. :)

And the more layers you have of mask and fringe the more it will help. And also for a bigger map, it will help even more!

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 1:38 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
I dont really understand how you got your numbers. Tiles * Layers is not how much you are drawing, and the speed really wont slow down much if you arn't drawing. Most optimizations in a game such as this come from the drawing, since it sure as hell ain't going to come from the calculations (rare you'd ever need an intensive calculation in such a game).

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 2:07 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Well I simply just used the for loops for it. To show that they got a lot smaller :P

Guess the code doesn't really do much anyway then ..

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 3:33 pm 
Offline
Regular
User avatar

Joined: Mon May 29, 2006 5:33 pm
Posts: 30
Verrigan, I currently use the same system you stated in a project of mine. I did this just for the simplicity of having the entire map drawing routines in one sub.

I have LowerBuffer which would hold the mirage ground & mask, a Middlebuffer which would hold mirages items, players, & npcs, and a UpperBuffer which would hold mirages Fringe layer. I then blt each of them in order to the BackBuffer which in turn is blted to the primary surface.

It keeps everything so much neater, and even better, you only need to update the lower and upper buffer (depending on what you draw to it) whenever you enter a new map. I then designed the middle buffer to only update if there is a change to that specific surface which I believe is somewhat equivalent to Williams system.

I haven't tested your system william, but the one Verrigan stated does help a lot and to me is the ideal way of gaining some speed when it comes to the graphical side of an engine/game.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 4:22 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
I understand exactly how yours work. Although I can't code it. it would be good if you could provide with some code from it ;)

My system is kinda the easy way to do a thing. And it simply just makes the For Loops smaller so less is being blitted..

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 4:27 pm 
Offline
Persistant Poster
User avatar

Joined: Tue May 30, 2006 2:07 am
Posts: 836
Location: Nashville, Tennessee, USA
Google Talk: rs.ruggles@gmail.com
William, you might wanna go back through your tutorial. You've left a couple instances of graphicinput, which I'm pretty sure need to be either graphicinput1 or graphicinput2

_________________
I'm on Facebook! Google Plus My Youtube Channel My Steam Profile

Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 7:50 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Okay, ill check it out.

Edit: yes you were right. I fixed it now. Thanks :)

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 2:05 am 
Offline
Regular
User avatar

Joined: Mon May 29, 2006 5:33 pm
Posts: 30
Hey william, I created a text tutorial for what I was talking about (very little code), would you care to test the tutorial for me? It makes sense to me, but just wanted to make sure it makes sense to everyone else. If so, contact me on any of my instant messengers below, or GTalk (same as my MSN).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:11 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Of course I can. I think I have you already. So add me instead on msn:
mailto:johansson_tk@hotmail.com

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
PostPosted: Fri Sep 21, 2007 11:43 am 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Brining this topic back to life
I just tested to see what FPS change there was in adding this system. I used 4 full layers of ground, mask, anim and fringe. And removed the fps lock. And the fps on a unedited MSE1 was around 300. When my system was added, the FPS was around 900. So I'd say that a pretty big difference.

This optimization do help, however there might be a few glitches using it so it might need a little bit more programming.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
PostPosted: Fri Sep 21, 2007 1:32 pm 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
I got that without this tutorial :P

_________________
Quote:
Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?


Image


Top
 Profile  
 
PostPosted: Fri Sep 21, 2007 1:38 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
The surface tutorial? :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group