Hi ^_^
I'm currently having problems in two areas, both resulting in slow down of one sort or another.
incidently, i didnt want to talk about both these things in the same post as it may lead to confusion ect ect.. but they are both pretty urgent to me and I didnt want to post this and then post another thing 2 seconds later.. seemed better to put them all in one, sorry if i shouldnt of :/
Problem A:
Literal game slowdown. My map editor is complete so i've started using it to make my maps (and also started creating more terrain models for it to use) - but already i've ground to a halt.. litrally. I decided to see what it could handle so I knew how liberal to be when making my maps, so i placed quite a large amount of trees down. It slowed right down to 23 fps.. but what is puzzling me is that it seems to be the amount of objects loaded rather than the amount of objects on screen slowing it down! To be honest, when I started whacking the trees in with no thought spared for my poor graphics card, i expected slow down. But i expected the kind of slow down that can be mapped around by say placing a big cliff through the center of my map to obstruct the view of half the objects and things like that, making sure that no matter how many objects i had they wernt all to be drawn at once. So, i made this test tree map.. loaded.. got the slow down i expected. I then turned the camera away from ALL the objects so it could only see blank space.. it still ran at 24fps T_T Any ideas why? I think there is roughly 400 objects in that map - if that truely becomes my limit then im in trouble, thats not really enough for me :/
**EDIT**
Forgot to mention, just incase anyone is wondering those trees are 72 polygons each (although like i said, polygon count doesnt seem to be the issue as I can look away from all the trees and it doesnt speed up at all)
**END EDIT**
Just incase your intrested:
http://www.spectural.com/storage/bts-slow.jpg
Ignore the dodgy first person view, the game is designed to be spent in 3rd person and i just added in that first person just now to get a better view of the map for a screen shot
Okay, now onto problem B..
This is about my map loading function. When i made my 400 tree map and then went to load it in the game engine, i noticed it took a little while to load (dont worry, thats expected and im not complaining about that
). I only used maps with 3 or 4 objects on for testing the engine upto now so i never noticed such loading times - but i decided right then, its time for a quick loading screen when maps are loading! Decided to do the works with a funky progress bar and percentage display. No worries there, it works fine - my problem is that it drasticly slows down the loading function
I decided to time it to see how much. Without loading screen the tree map takes 13.22 seconds to load, with the loading screen it takes 23.12 seconds, thats twice as long almost :/ and i think i know why, im just not sure what to do about it. I think its because of the need to use a sync command in the loading for loop to update the progress info - of course that forces the function to slow down to update the screen and what not.. I tried getting around this by setting the sync rate to 0 prior to uncap it for loading, didnt do squat :/ There has to be some way of doing a loading screen without killing the actual loading function? The reason why the loading screen is in the function is because i need to know how far through the map file it has got to calculate the percentage complete.. if anyone can help i would be SO thankful!
Heres the code for it (included as source for those who cant use code tags):
Function LoadMap(Fn As String)
Rem Set the active directory to the Maps directory
Rem RootDir$ is a global var set when the program is loaded
Set Dir RootDir$ + "Maps"
FileName = Fn
If File Exist(Filename)
Rem If theres already a map loaded, delete all objects in the map stack
If Header.MapSize > 0
For a = 0 to Header.MapSize
If Object Exist (MapStack(a).ObjID) then DeleteObject(MapStack(a).ObjID)
Next a
EndIf
Rem Open the map file
Open to Read 1, FileName
Rem Read in the map header
Read String 1, Header.Author
Read String 1, Header.MapName
Read String 1, Header.Players
Read String 1, Header.Desc
Read Long 1, Header.MapSize
Rem Clear the map stack
Empty Array MapStack(0)
Rem This sync rate is a futile effort to speed up the loading process...
sync rate 0
For a = 0 to Header.MapSize
Rem ******LOADING SCREEN START******
Rem Calculate how much percent of the map has been loaded
P = (a * 100) / Header.MapSize
Rem Set the text colour
ink rgb(0,0,0), rgb(255,255,255)
Rem Wipe the screen white with a box command (because no matter what i set with the ink command cls always clears black :/)
box 0, 0, screen width(), screen height(), rgb(255,255,255), rgb(255,255,255), rgb(255,255,255), rgb(255,255,255)
Rem Draw the progress bar and draw the loading and percentage text
box screen width() / 2 - 51, screen height() - 70, screen width() / 2 + 51, screen height() - 52, rgb(0,0,0), rgb(0,0,0), rgb(0,0,0), rgb(0,0,0)
box screen width() / 2 - 50, screen height() - 68, screen width() / 2 + 50, screen height() - 54, rgb(255,255,255), rgb(255,255,255), rgb(255,255,255), rgb(255,255,255)
box screen width() / 2 - 50, screen height() - 68, (screen width() / 2 - 50) + P, screen height() - 54, rgb(130,130,255), rgb(130,130,255), rgb(130,130,255), rgb(130,130,255)
Center Text Screen Width() / 2, Screen Height() / 2 - 25, "Loading"
Center Text Screen Width() / 2, Screen Height() - 68, Str$(P) + "%"
Rem Update load screen
sync
Rem ******LOADING SCREEN END******
Rem Add a new item to the map stack and then read in the object information
Array Insert At Bottom MapStack(0)
Read String 1, MapStack(a).ObjFN
Read Float 1, MapStack(a).ObjX
Read Float 1, MapStack(a).ObjY
Read Float 1, MapStack(a).ObjZ
Read Float 1, MapStack(a).ObjYR
MapStack(a).ObjID = LoadObject("resourcesMeshTerrain" + MapStack(a).ObjFN, 0)
Rem Turn the object transparency on (alot of objects like trees use this) and position rotate it according
rem to the settings read in from the map file
Set Object Transparency MapStack(A).ObjID, 1
Position Object MapStack(a).ObjID, MapStack(a).ObjX, MapStack(a).ObjY - 10, MapStack(a).ObjZ
YRotate Object MapStack(a).ObjID, MapStack(a).ObjYR
Next a
Ink rgb(255,255,255), rgb(0,0,0)
Rem Set the sync rate back to normal
sync rate 60
Rem Set the MapIndex (not used by game engine, used by map editor which uses this same loading function
MapIndex = Header.MapSize + 1
Close File 1
EndIf
Rem Set the dir back to the game root directory (otherwise my other file commands break :P)
Set Dir RootDir$
EndFunction
Dont worry about things that seem wrong, like DeleteObject() not being a dbp command - things like that are functions i wrote myself for the engine so i can load and delete objects without worrying about making sure its a free object number (function does that itself - loadobject returns the id it assigned the object to and delete object was written just to readjust vars used by loadobject)
ahh.. why are my posts always so long
Im sorry guys :/ Will be most thankful for any help you can offer though