Sorry Nother Problem
Blitz3D Forums/Blitz3D Beginners Area/Sorry Nother Problem
| ||
When I run my game (debug off) it goes really slow. The processor in my computer isn't too bad (AMD Athlon 3700+) but I highly doubt it is because my proc. is too slow. Can anyone shead some light on this? It could always be a problem in my code that's making it slow, but I highly doubt... |
| ||
Well, thats a lot of informations to work with isnt it. How many surfaces do you have? What size textures are you using, and whats the max size for you GPU? How many Entities do you have? How many Lights do you have? Im going to stick my neck out, and say it because you have too many surfaces. Lookup the code archive for code to make two things into one Surface, or how to make two surfces on one mesh into one surface |
| ||
Do you load stuff in main loop? Do you load oversized and non power of 2 textures like 4200x1100? |
| ||
Well, It's really only a 2D game that i made w/B+ demo than executed it on my real version of B3d, so we can scratch off all of those and think a little more 2D. Sorry i didnt mention this earlier. Just to let you know, it's like a ripoff of Space Invaders. |
| ||
B+ should be able to handle that without even breaking a sweat. We're going to need some source code to sort this. |
| ||
Ok, then reason is probably, cos youve done something really stupid, like Delay inside a loop inside your game loop, or such. (And no offence, Everyone makes stupid mistakes, its the good programmers that remember the results for next time ;) 1) MAke sure All initialization happens in the initialization phase. 2) Make sure that anything that can be moved out of the Game loop, is moved out of the game loop 3) Look at any other loops that you have, and again move anything out of them, that doesnt need to be in them. 4) Look for any Pause/Delay or waits and make sure they have the right value 5) GO back to your loops and make sure you have the correct conditions to leave the loop. A simple error is "While x<>10", when x has the range 1-10, but... youve made it a float, so instead of the loop finishing 1 in 10 times, it finishes 1 in 2^14 times (ish) 6) Post a flow description of your game |
| ||
Well... I do have it delay 500 when the game starts. My programming teacher (I took a class) said that helps the game in some sort of way. My Gameloop is before my func. and after the Globals (the types are behind the globals). Do you want all of the code or just some of it? |
| ||
A delay after initialization just let the OS catch up with the program, so as long as it not in a loop, Delay 500 is OK, (it just means wait 1/2 a second). Im loath to say post all the code, because it bodes badly if you cannot at least see where the bottle neck might be. Post the main game loop first, and probably well ask for other functions. |
| ||
Function GameLoop() CreateStars createenemy 1 createenemy 2 Repeat Cls updatepause updatestars updateshots updateplayer updateenemies updatescreen updatedelete updateexp GameOver Flip Until KeyHit(1) End Function |
| ||
lol I suppose I asked for that. Can you post UpdatePause(), UpdateDelete() and UpdateExp() Also square bracket [ then code then ] no spaces, then at the end [/code] |
| ||
Function UpdateDelete() For s.typshot = Each typshot If s\x < 0 Or s\x > screenx Or s\y < 0 Or s\y > screeny Delete s updatedelete Exit End If If s\sType = 2 If shields > 0 If ImagesCollide(imgshield, shieldx, shieldy, 0, s\img, s\x, s\y, 0) shields = shields - 10 Delete s PlaySound sndexp updateDelete Exit End If End If End If If ImagesOverlap(imghero, x, y, s\img, s\x, s\y) If health > 0 health = health - 10 Delete s PlaySound sndExp updateDelete Exit End If End If If health < 10 PlaySound sndlowhlth Exit End If ecount = 0 For e.typEnemy = Each typEnemy ecount = ecount + 1 If s\sType <> 2 If ImagesOverlap(s\img, s\x, s\y, e\img, e\x, e\y) score = score + 10 createExp e Delete s Delete e updatedelete Exit End If End If Next If ecount = 0 createlevel updatedelete Exit End If Next End Function Function UpdateExp() For e.typExp = Each typexp e\currentframe = e\currentframe + 0.1 If e\currentframe => e\frames Delete e updateexp Exit End If DrawImage e\img, e\x, e\y, e\currentframe Next End Function Function UpdatePause() If KeyHit(25) Repeat Until KeyHit(25) End If End Function Sorry! I tried the bracket thing; it wouldn't work. |
| ||
That code][/code] thing only works when you post it Right.... Ok for example Function UpdateDelete() For s.typshot = Each typshot If s\x < 0 Or s\x > screenx Or s\y < 0 Or s\y > screeny Delete s updatedelete Exit End If 1) Makes a loop of all the TypShots 2) Looks to see if S should be deleted 3) If so Delete s 4) Restart at Number 1 Now the question is, WHY ARE YOU CALLING UNDATEDELETE everytime you delete something. Just delete it, thats it. GO through your code, find all the times you do this Delete somthing Updatesomething Exitand change them to Delete SomthingThat is remove the exit and the call back to the upadate Then go and look where the Nexts should be, because at the moment it looks like the For each loops are nested, and they shouldnt be |
| ||
It didn't seem like the game went any faster when I deleted all the 'updatedelete's. Should I loop everytime typshot is in the code? |
| ||
...add some print statements which checks the time on entry and exit of a function and stores the time in a 'TFuncTime' type and keep track of the number of times the function is called. At the end of the program output the total, average and lognest time for each function. Concentrate on the longest and those called often. |
| ||
Function UpdateDelete() For s.typshot = Each typshot If s\x < 0 Or s\x > screenx Or s\y < 0 Or s\y > screeny Delete s Else if s\sType = 2 and shields > 0 and ImagesCollide(imgshield, shieldx, shieldy, 0, s\img, s\x, s\y, 0) shields = shields - 10 Delete s PlaySound sndexp ELse if ImagesOverlap(imghero, x, y, s\img, s\x, s\y ) and health > 0 health = health - 10 Delete s PlaySound sndExp If health < 10 PlaySound sndlowhlth End If Else ecount = 0 For e.typEnemy = Each typEnemy ecount = ecount + 1 If s\sType <> 2 and ImagesOverlap(s\img, s\x, s\y, e\img, e\x, e\y) score = score + 10 createExp e Delete s Delete e End If Next If ecount = 0 createlevel End If End if Next End Function |
| ||
Well, I have to stop for now. I got a jam-packed scedule. Promise i will fix tomorrow. |
| ||
I've found in my programming (without reading much of the above), that often in my UpdateEnemies or UpdateBullets functions, when I test each enemy or bullet in a for-each loop, often after I delete one I use Return to prevent trying to do something with the deleted entity. Don't do that. It seems to slow down the game, because all of the entity checks [i]after[i/] the deleted one don't get done until the next game loop because of the Return command. I hope that made some sort of sense, and I hope it helped, too. |
| ||
Yep, what buggy said wasnt the problem that you had, but was similar. What you were/are doing is after you deleted an entity, starting the list again, rather than just continuing to the next. |