Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / progress bar template

Author
Message
poisoned
19
Years of Service
User Offline
Joined: 6th Jun 2005
Location: the shadow realm
Posted: 23rd Jun 2005 15:44
here is my first attempt at a progress bar, it's only a template

Q1- what could i have done better?
Q2- is this code too long for its purpose?
Q3- how would you go about doing this?



Intel P4 3.6Ghz 1G PC3200 DDR
gpex
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 24th Jun 2005 10:39
well, i'm not a very experienced programmer but in my opinion you designed this very well, not too reader friendly, but still good. The only thing that i would work on is the choppines(maybe due to the sync rate...maybe) i would just use a series of sprites to fill up the bar, this may give a better appearance without the choppines.


-gpex-

PS: and using sprites may shorten up the code a bit also.

Your signature has been erased by a mod because it is larger than 600x120...
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 24th Jun 2005 11:55
1/ In a number of ways, but the principal your using is sound.

2/ No, don't be fooled. Code that is long doesn't mean it's bad, in-fact often you can achieve things quicker with more code than less.

3/ Pretty much the same way, although yes I may use a Sprite for speed means in DarkBASIC but in Professional with something like this it is just as quick to Lock the Pixels



A DarkBASIC Compatible version of how I would do it.

poisoned
19
Years of Service
User Offline
Joined: 6th Jun 2005
Location: the shadow realm
Posted: 24th Jun 2005 15:06
thanks for your insight raven and gpex!!!
btw Raven, I'm really new to DB-pro and have not done any work with functions is there any way you can comment your code? I would appreciate it!!!

Intel P4 3.6Ghz 1G PC3200 DDR
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 24th Jun 2005 15:35
Its worth noting that a progress bar can actually slow down loading because you are forcing the loop to run at your sync rate instead of the maximum processor speed when you call Sync. With big levels and stuff it can really become noticable too. This is why generally a static once-drawn-never-cleared image to inform you its loading is often used.

Howeverrrrrrrr, you can combat this by before the load set your sync rate to 0 which will uncap it and allow it to draw as fast as it can. This still isnt as fast as loading without any screen updates but its MUCH better than having the screen capped to 60 or even 100 fps. Dont forget to set it back to the desired fps after load.

another optimisation you can make is to only update the screen when a significant change in the percentage as occured. On its simplest (and very recommended) scale, check to see if the percentage value has changed AT ALL from what it was on the last time you have updated and if it hasnt then dont bother to redraw your loading screen because the old draw is still correct - this means less syncing (updating the screen) during the processes loop and more dedication to the processor. You can take this is a step further if you desire and only update the screen if say the percentage has changed by a value of 10. This makes it HUGELY faster with a grand total of only 10 screen updates for the entire duration of the load but on the flipside your bar will obviously jump up in 10's and that may not look so great.

Except for that there are only a few general optimisations that can be made. You can make up some globals for colours at the top of your program like

global Black as dword
global Red as dword

Black = 0
red = Rgb(255, 0, 0)

and then replace all your calls to rgb in your drawing loops with the variable to pass the colour instead of needing to recaclulate it with the rgb() command for every cycle of the loop. You can further enhance this by writing a program to output the numerical value of colours (text 10, 10, str$(rgb(255, 0, 0)) for red, etc), noting down their values and then using constants at the top of your program to store those values. This means a variable doesnt need to be looked up and evaluated when ever you pass a colour. Both techniques are small and probably for anything except the most taxing of programs unnoticiable optimisations - but they ARE optimisations and its never a bad thing.

you can I belive loose the ink command before the box commands and set the colours as an additional 4 parameters at the end of box (1 colour for each corner), ie - assuming you made a variable or constant called black like i suggested for a black box then do
box 10, 10, 20, 20, black, black, black, black

absolutly no idea if thats faster than using ink though, but I tend to do it out of prefrance because it means i dont have to reset the ink colour manually afterwards.

Except for those I see nothing else really except little nit-picking things that really arnt relevent. Good job, hope my optimisation suggestions arnt too overwhelming

[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu
[07:17:22-pm] « Mouse » he was hanging himself lol
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 24th Jun 2005 16:00
here are some more examples for DBpro using types.
http://forum.thegamecreators.com/?m=forum_view&t=37583&b=6

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself 
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 24th Jun 2005 17:17
oki here
is the code commented. Though now I know your using DarkBASIC Professional, I've gone and altered the code a bit, with some new comments to explain it for you.



Have a play

James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 25th Jun 2005 03:39 Edited at: 25th Jun 2005 03:39
No code examples from me but I do look your progress bar, if you are new to DB then this is by far excellent my friend.

The only things I would change are:
1. Instead of gosub, use functions
2. Dont use a fixed position for the loading bar, use a variable which can easily be changed i.e. top = 100 : left = 50 (or just x and y) this way if you want to ever reposition your bar you just have to change these two variables.
If you were to use functions, you could have something such as
Function runProgressBar(top,left,size)
Endfunction

(where size is the width, so also customizable)

Keep it up!

Hello!
poisoned
19
Years of Service
User Offline
Joined: 6th Jun 2005
Location: the shadow realm
Posted: 29th Jun 2005 11:45
@ Sephnroth thanks for taking the time to remind me to think of the processor. when implementing the progress bar into a game i will, more than likely, just have the progress bar increase by 10%. Even though it may look kind of jumpy it shows the user the program is still running and has not crashed.

@everyone - Thankyou for taking the time to help a new programer

Intel P4 3.6Ghz 1G PC3200 DDR

Login to post a reply

Server time is: 2024-11-27 22:27:02
Your offset time is: 2024-11-27 22:27:02