Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1] 2   Go Down

Author Topic: How do you speed up executables?  (Read 4638 times)

0 Members and 1 Guest are viewing this topic.

Koh

How do you speed up executables?
« on: August 02, 2006, 03:03:52 am »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
I notice everytime when I put in the HUD in any zelda game I make, it lags very badly.  How do you prevent this or speed the game up?
Logged
  • Megaclipse Games
Re: How do you speed up executables?
« Reply #1 on: August 02, 2006, 12:37:59 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
How are you making your HUD? Give us some details like:

What program - Obvious
Transperency - How transparent is it, this can cause lag.
How does your HUD work - objects, drawing etc


 Now to speed the game up, use external resources.
Logged

Koh

Re: How do you speed up executables?
« Reply #2 on: August 02, 2006, 01:24:34 pm »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
Draw Event:
execute code:

draw_sprite(sprLinkShadow,0,x,y)


var tspr;
tspr=sprite_index

if instance_exists(holding_pot){ //Mask the sprite with the one of him holding it
    switch sprite_index {
    case sprLinkD: tspr=sprLinkCarryD; image_index=0; break;
    case sprLinkU: tspr=sprLinkCarryU; image_index=0; break;
    case sprLinkR: tspr=sprLinkCarryR; image_index=0; break;
    case sprLinkL: tspr=sprLinkCarryL; image_index=0; break;
    case sprLinkD: tspr=sprLinkCarryD; break;
    case sprLinkU: tspr=sprLinkCarryU; break;
    case sprLinkR: tspr=sprLinkCarryR; break;
    case sprLinkL: tspr=sprLinkCarryL; break;
    }
}


draw_sprite(tspr,-1,x,y)

draw_sprite(sprIH,-1,view_xview[0]+140,view_yview[0]+0)


if global.select="bow"
draw_sprite(bowHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="boomerang"
draw_sprite(boomerangHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="hookshot"
draw_sprite(hookshotHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="bomb"
draw_sprite(bombHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="firerod"
draw_sprite(firerodHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="icerod"
draw_sprite(icerodHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="bombos"
draw_sprite(bombosHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="ether"
draw_sprite(etherHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="quake"
draw_sprite(quakeHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="torch"
draw_sprite(torchHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="hammer"
draw_sprite(hammerHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="flute"
draw_sprite(fluteHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="net"
draw_sprite(netHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="book"
draw_sprite(bookHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="bottle"
draw_sprite(bottleHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="somaria"
draw_sprite(somariaHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="byrna"
draw_sprite(byrnaHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="cape"
draw_sprite(capeHUD,-1, view_xview[0]+144,view_yview[0]+4)

if global.select="mirror"
draw_sprite(mirrorHUD,-1, view_xview[0]+144,view_yview[0]+4)



Key Press Event for <Enter> Key:
execute code:

if global.pause=0 && !jumping && !usingsword{
instance_create(view_xview[0],view_yview[0]+20,Menu)
instance_create(view_xview[0],view_yview[0]+20,objSelector)
instance_create(view_xview[0],view_yview[0]+20,bow_menu)
instance_create(view_xview[0],view_yview[0]+20,boomerang_menu)
instance_create(view_xview[0],view_yview[0]+20,hookshot_menu)
instance_create(view_xview[0],view_yview[0]+20,bomb_menu)
instance_create(view_xview[0],view_yview[0]+20,powder_menu)
instance_create(view_xview[0],view_yview[0]+20,firerod_menu)
instance_create(view_xview[0],view_yview[0]+20,icerod_menu)
instance_create(view_xview[0],view_yview[0]+20,bombos_menu)
instance_create(view_xview[0],view_yview[0]+20,ether_menu)
instance_create(view_xview[0],view_yview[0]+20,quake_menu)
instance_create(view_xview[0],view_yview[0]+20,torch_menu)
instance_create(view_xview[0],view_yview[0]+20,hammer_menu)
instance_create(view_xview[0],view_yview[0]+20,flute_menu)
instance_create(view_xview[0],view_yview[0]+20,net_menu)
instance_create(view_xview[0],view_yview[0]+20,book_menu)
instance_create(view_xview[0],view_yview[0]+20,bottle_menu)
instance_create(view_xview[0],view_yview[0]+20,somaria_menu)
instance_create(view_xview[0],view_yview[0]+20,byrna_menu)
instance_create(view_xview[0],view_yview[0]+20,cape_menu)
instance_create(view_xview[0],view_yview[0]+20,mirror_menu)
global.pause=1
}
else if global.pause=1{

with Menu instance_destroy()
with bow_menu instance_destroy()
with boomerang_menu instance_destroy()
with hookshot_menu instance_destroy()
with bomb_menu instance_destroy()
with powder_menu instance_destroy()
with firerod_menu instance_destroy()
with icerod_menu instance_destroy()
with bombos_menu instance_destroy()
with ether_menu instance_destroy()
with quake_menu instance_destroy()
with torch_menu instance_destroy()
with hammer_menu instance_destroy()
with flute_menu instance_destroy()
with net_menu instance_destroy()
with book_menu instance_destroy()
with bottle_menu instance_destroy()
with somaria_menu instance_destroy()
with byrna_menu instance_destroy()
with cape_menu instance_destroy()
with mirror_menu instance_destroy()
with objSelector instance_destroy()
with selected instance_destroy()

global.pause=0
}
Logged
  • Megaclipse Games

Ben

Re: How do you speed up executables?
« Reply #3 on: August 02, 2006, 01:28:10 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
It shouldn't slow it that much, but try replacing all of your if's with a switch case statement, this works as follows:

switch (global.select){
case "bow": //Draw Bow break;
case "boomerang" //Draw Boomerang break;
}

At least I think it does, lol. I haven't used a switch statement for so long, cause more often than not there really is no need for it :).
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: How do you speed up executables?
« Reply #4 on: August 02, 2006, 04:57:18 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
Or, have one sprite with a sub-image for each sprite.

So have like this:

draw_sprite(spr_HUD,global.HUDbutton,0,0)
Logged
Re: How do you speed up executables?
« Reply #5 on: August 02, 2006, 05:00:09 pm »
  • 笑い男
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 2124
it's probably because you have so much stuff for the game to do in the hud's draw event, try to find out a way to have as little as possible in the draw event
Logged

この世に悪があるとすれば、それは人の心だ
  • .hack//The World
Re: How do you speed up executables?
« Reply #6 on: August 02, 2006, 06:50:13 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Here's a little secret that sped up my game 400%:

Instead of rendering the hud every frame, render the hud once to another surface, and then draw that one surface instead. Then, whenever you need to update the hud, redraw it just once to that seperate surface.
Logged

Ben

Re: How do you speed up executables?
« Reply #7 on: August 02, 2006, 06:53:52 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Fish, if he doesn't know how to use switch case he won't know how to use GM's surface functions.
Besides GM renders the room every frame anyway, it's slow as hell but it's for beginners really.

(Don't hate me.)
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: How do you speed up executables?
« Reply #8 on: August 02, 2006, 06:56:59 pm »
  • 笑い男
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 2124
there is also a little cheat:
frame skipping, just turn of automatic drawing (set_automatic_draw or something) and then redraw the screen (screen_redraw ors omething) every other step (alarm set to 2), but you will notice it get slightly more choppy or whatever
but, if you unlimit the fps, then if that makes the fps at least double, the choppyness will be totally gone and you increase the fps with no extra charge, but then you'd have to do all speed controlled stuff multiplyed by a multiplyer that is proportional to the fps, so the speed of the stuff stays the same when the fps doesnt
if you get me :P
Logged

この世に悪があるとすれば、それは人の心だ
  • .hack//The World
Re: How do you speed up executables?
« Reply #9 on: August 02, 2006, 07:24:53 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Fish, if he doesn't know how to use switch case he won't know how to use GM's surface functions.
Who said I was talking about GM? This is a technique that would work well in every reasonable graphics API out there. =) Eventually, he'll figure it all out, and we'll all bow down to him as a programming god. Or not. Either way, at least now he knows a good way to speed up drawing his GUI. =)

(Don't hate me.)
I hate you. >:( Not for any reason, just because. >:( Please die in a fire. >:(
Logged

Ben

Re: How do you speed up executables?
« Reply #10 on: August 02, 2006, 07:28:24 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
I don't quite understand how it works.
You said render it to a surface and then render that surface to the screen.
Surely that would slow it down?
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: How do you speed up executables?
« Reply #11 on: August 02, 2006, 07:54:54 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Surely not!

Imagine, for example, world of warcraft. Here's a screenshot so you don't have to tax your imagination too hard:


Note the cr*pload of icons dancing up the bottom and right side of the screen. For each one of those icons, you have to determine the correct texture to draw, then retrieve the index of that texture, then tell the graphics card to render that texture. Now, do that forty times in a row. Wow, took a bit of time, didn't it?

So, as an alternative, render all these textures to simple 'block textures'. You'll need one for each major segment of the gui; in this case, one down at the bottom of the screen and one on the right side. Now, instead of drawing each one of those individual textures (neccesiting a cpu hit for each icon), you just render the blocks.

Yes, you will end up overdrawing a wee bit, but a reasonably modern graphics card is not going to be slowed down by drawing a simple square texture (actually, for a 3D game you'll need to split the blocks up into blocks of the power of two, so instead of having a 500x90pixel block, you'll need a 512x128 pixel block).

Overdrawing pixels with hardware acceleration is cheap, cheap, cheap!

PS: still hate you. >:(
Logged

Ben

Re: How do you speed up executables?
« Reply #12 on: August 02, 2006, 07:57:39 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
So you mean draw the hud as static until it changes and then draw that surface. Once the hud changes redraw onto the "hud" surface and then draw that.

I guess it could work, but a Zelda hud isn't that dynamic. Though if you are coding for a handheld console, it's always good to be efficient.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: How do you speed up executables?
« Reply #13 on: August 02, 2006, 08:23:32 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Ben, you are right. Now that I think of it, my method is completely unsuitable for a zelda-style game.

Here's a better way for a zelda game, that would totally get rid of that mess of item-select-draw-icon code. Now, I don't know GML, so this will be in pseudo code, but I'm sure you'll be able to handle it.

First, set it up:
Code: [Select]
//define the item indexes...
define item_bomb = 0
define item_bow = 1
define item_boomerang = 2
define item_maxitems = 3

//create the item icon array
dim item_icons(0 to item_maxitems) as sprite

//load the icon sprites
set item_icons(item_bomb) = loadsprite("bombicon.bmp")
set item_icons(item_bow) = loadsprite("bowicon.bmp")
set item_icons(item_boomerang) = loadsprite("boomerangicon.bmp")
And then, in your draw routine, instead of doing if...elseif...elseif... ad infinitum, you could simply do this:
Code: [Select]
draw_sprite(item_icons(global.selecteditem)),-1, view_xview[0]+144,view_yview[0]+4)
Logged

Hikij

Re: How do you speed up executables?
« Reply #14 on: August 03, 2006, 05:14:54 am »
Fish, that wouldn't work. You would need to change it alot for it to be suitable for Game Maker.
Logged
Re: How do you speed up executables?
« Reply #15 on: August 03, 2006, 05:29:13 am »
  • The Broken King
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1259
Now, I don't know GML, so this will be in pseudo code, but I'm sure you'll be able to handle it.

He knows that. It's pseudocode, not real code.
Logged
  • Broken Kings [Temp Site]
Re: How do you speed up executables?
« Reply #16 on: August 03, 2006, 05:40:02 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Fish, that wouldn't work. You would need to change it alot for it to be suitable for Game Maker.
Are you saying that GM can't do arrays of sprites? Can't load sprites at runtime? Or that you can't think a way around your language of choice's limits?

Unless GML is severely crippled, I'm sure you can think of a way to make work what I gave you. Or, alternatively, you could feign ignorance and make me do your work for you. Here you go:

If GM can't do arrays of sprites, then you should do it this way:

1. Preload all the sprites. iconBomb, iconNet, iconBow, etc. Also have an iconClear, for no item. And you'll need a SPECIAL AWESOME SPRITE, which we'll call hudCurrentIcon.
2. When you select an item in the menu screen, set hudCurrentIcon equal to the correct sprite. So, if you select the bow, then
Code: [Select]
set hudCurrentIcon = iconBowThen, in the main hud drawing routine, instead of all that if...elseif... cr*p, do this:

Code: [Select]
draw_sprite(hudCurrentIcon,-1, view_xview[0]+144,view_yview[0]+4)
Woah, devilishly simple! A few facts to finish up this example.

Fact 1. I am awesome.
Fact 2. You bore me.
Fact 3. ....?
Fact 4. Profit!!!

Logged
Re: How do you speed up executables?
« Reply #17 on: August 03, 2006, 05:55:07 am »
  • The Broken King
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1259
You can do array of sprites in GM.

Simply go ...

sprItem
  • = <spritename1>

sprItem[y] = <spritename2>
...
sprItem[q] = <spritenameN>

sprite names in GM are just numbers anyways [if I recall]. Which is why if you go draw_sprite(x, y, 0), it always draws the first sprite added to your game. (This may have changed since I last worked in GM though)
Logged
  • Broken Kings [Temp Site]

Ben

Re: How do you speed up executables?
« Reply #18 on: August 03, 2006, 09:44:37 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
They are  just numbers, because in debug mode it never gives you the name of the sprite that is sprite_index, only the number.

GM is a little different to most professional things, Fish. You add resources to your game (which are automatically loaded) and then they're all given a number or name. The easiest way to do this (which I have done myself) is to have every item icon in a sprite as seperate frames, define constants for each of the frames and then have a variable called "global.select" (if we're going his way) which you set to each constant and then do the whole draw_sprite(sprHud, global.select, 0, 0); which will draw the correct frame.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: How do you speed up executables?
« Reply #19 on: August 03, 2006, 12:29:40 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
They are  just numbers, because in debug mode it never gives you the name of the sprite that is sprite_index, only the number.

GM is a little different to most professional things, Fish. You add resources to your game (which are automatically loaded) and then they're all given a number or name. The easiest way to do this (which I have done myself) is to have every item icon in a sprite as seperate frames, define constants for each of the frames and then have a variable called "global.select" (if we're going his way) which you set to each constant and then do the whole draw_sprite(sprHud, global.select, 0, 0); which will draw the correct frame.
Exactly what I said at the beggining but no one pays attention to Piers.
Logged
Pages: [1] 2   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.167 seconds with 75 queries.