Speed problems
Blitz3D Forums/Blitz3D Programming/Speed problems
| ||
Read then Code below: ; Sub - NewGame ; This sub is called when a new game needs processing and rendering .Do_NewGame ; RENDER If d2 = True Then For players.playertype = Each playertype SetBuffer ImageBuffer(TempNameImage) DrawImage box001, 0, 0 If players\index = playercreating Then If nameing = True Then colText 17, 10, "Name: " + players\name + "_", False, False, 255, 0, 0 If nameing = False Then colText 17, 10, "Name: " + players\name, False, False, 255, 0, 0 EndIf SetBuffer BackBuffer() DrawImage TempNameImage, 300, 230 SetBuffer ImageBuffer(TempNameImage2) DrawImage box001, 0, 0 If players\index = playercreating Then colText 17, 10, "Skin: " + skinname, False, False, 255, 0, 0 SetBuffer BackBuffer() DrawImage TempNameImage2, 300, (230+(45*1)) SetBuffer ImageBuffer(TempNameImage3) DrawImage box001, 0, 0 If players\index = playercreating Then colText 17, 10, "Body: " + body, False, False, 255, 0, 0 SetBuffer BackBuffer() DrawImage TempNameImage3, 300, (230+(45*2)) SetBuffer ImageBuffer(TempNameImage4) DrawImage box001, 0, 0 If players\index = playercreating Then colText 17, 10, "Gender: " + gender, False, False, 255, 0, 0 SetBuffer BackBuffer() DrawImage TempNameImage4, 300, (230+(45*3)) SetBuffer ImageBuffer(TempNameImage5) DrawImage box001, 0, 0 If players\index = playercreating Then colText 17, 10, "Color: " + bcolor, False, False, 255, 0, 0 SetBuffer BackBuffer() DrawImage TempNameImage5, 300, (230+(45*4)) Next DrawImage mousepic, MouseX(), MouseY(); Draw the mouse image last (over everything) EndIf ; PROCESS If d2 = False Then If KeyHit(1) Then For players.playertype = Each playertype deleteplayer(players.playertype) Next game_status = 1 ; Go back ,if the user presses ESC, to the main menu End If curkey = GetKey() If nameing = True Then FlushKeys() lastletter = letter If curkey = 13 Then nameing = False lastletter = "" letter = "" curkey = 0 bob = 0 name = "" tname = "" templetter = "" Goto endnaming End If If curkey > 0 Then letter = Chr(curkey) If curkey = 8 Then If name > "" Then For bob = 1 To Len(name) - 1 templetter = Mid(name, bob, 1) tname = tname + templetter Next .Stop2 name = tname tname = "" EndIf Else name = name + letter EndIf EndIf For players.playertype = Each playertype If players\index = 1 Then players\name = name Next EndIf .endnaming god001 = ImagesCollide(mousepic, MouseX(), MouseY(), 0, TempNameImage, 300, 230, 0) If god001 = True Then If MouseHit(1) Then nameing = True EndIf god001 = False EndIf If ImagesCollide(mousepic, MouseX(), MouseY(), 0, TempNameImage2, 300, (230+(45*1)), 0) Then If MouseHit(1) Then skin = skin + 1 If skin => noofskins Then skin = 1 EndIf EndIf If ImagesCollide(mousepic, MouseX(), MouseY(), 0, TempNameImage3, 300, (230+(45*2)), 0) Then If MouseHit(1) Then nameing = True EndIf EndIf If ImagesCollide(mousepic, MouseX(), MouseY(), 0, TempNameImage4, 300, (230+(45*3)), 0) Then If MouseHit(1) Then nameing = True EndIf EndIf If ImagesCollide(mousepic, MouseX(), MouseY(), 0, TempNameImage5, 300, (230+(45*4)), 0) Then If MouseHit(1) Then nameing = True EndIf EndIf playercreating = 1 statge =1 Select playercreating Case 1: Select statge Case 1: coltext(10, 10, "PLAYER 1: CrEaTe YoUr ChArAcTeR YoU SwInE", False, False, 155, 0, 0) For players.playertype = Each playertype If players\index = 1 Then TurnEntity players\modle, 0, 2, 0 Next End Select End Select For bbeams.bbeamtype = Each bbeamtype updatebbeam(bbeams.bbeamtype) Next EndIf Return i'm having problems with the speed of the above code. for some reson it works fine speed wise until the user moves the mouse over one of the 'TempNameImages' thats when the speed problems happeren. I thought it might be todo with the buffer swapping so i took it out but still the problem happerend. i eventally found out that it had somthing todo with when the user mouse pic collides with the 'TempNameImages' but i don't know what???? plz help!!! |
| ||
Dude, if the above code works, it would be a miracle !!! (with no offense at all !) ;-) A game program is (usually) made of these sections: Initialisation Intro Menu Main game loop Score End The Initialisation section takes care of loading the media, such sounds, images, models, maps, and so on. It set also the graphics up. The intro would display some cute scene and gfx to introduce the player to the game Menu: here is where the player can choose some options, like difficulty levels, maps, characters, missions, sound on/off, and the like The main loop is the game itself, is where the player interacts with the game - ex. guides an astroship through a tunnel, and shoots to asteroids. Score: here the game has ended, and the player is prompted to enter his score in the hall of fame End: the player has quit the game; so all the resources - sounds, gfx, models - should be freed. Some suggestion for you: 1) try to mantain a modular aspect of your code. I still can't understand where it starts and where it ends !!! 2) Avoid 'GoTo' commands 3) You don't have any Flip command in your code; so I guess your proggy works only with front buffer, hence it could be slow 4) try to follow a structure like this: ;initialization: include files, graphics mode setting, variable settings ;timer - this will mantain the render speed running at a costant rate global mytimer = createtimer(60) ;main loop: while not keydown(1) ;do this until esc is pressed k = waittimer(mytimer) for n = 0 to k updategame() next rendergame() flip wend end ;========================== function updategame() ;========================== ;put here all the stuff related to movement, update frames, game controls, sound control, ecc. end function ;========================== function rendergame() ;========================== ;here put everything that should be displayed; should only contain all the DrawImage commands, if you get my drift. end function I suggest you to read some tutorial; have a look at www.blitzcoder.com for example. Some further note to the code you've posted: 1) you don't need to set the buffer to the imagebuffer each time you want to display some text on it. This could really slow down your application. Instead, just do this: --- display the image at x,y: drawimage image,x,y --- display a filled rectangle on it: rect x+50,y+50,150,100,true --- display some text on the rectangle: text x+100,y+100,"Dude !" --- DONE 2) If you need to display 50 images, would you do something like in your code: drawimage image1,x,y drawimage image2,x,y . . drawimage image50,x,y ? This is simply crazy, dude ! Just make an array of images, and : for n = 1 to 50 drawimage my_array(n),x,y next See ? You save space and time !!! 3) Say you want to delete all your types; you wrote: For players.playertype = Each playertype deleteplayer(players.playertype) Next This is (quite) correct; shouldn't be deleteplayer(players) ? Anyway, for your info, there's a simple command that will wype out all the type element in a simple statement: Delete Each players.playertype:-) Have fun, Sergio. |
| ||
k I tried what you said and it kinda works but its still a little slow - It doesn't bother me to muchnow though as i can just take away some of the special effects. P.S. I know about the program flow and just incase u thought that was all of it, it isn't :) :). P.S. I always thought that a sub would be faster than a function. :) :) :) :) :) :) :) :) :) :) :) :) thx Sergio |