Can anyone optimise this code chunk?
Blitz3D Forums/Blitz3D Beginners Area/Can anyone optimise this code chunk?
| ||
; ***************************** ; ONLY FOR DEBUGGING PURPOSES ; ***************************** Function print_debug_info() r=0 : g=0 : b=0 r=ColorRed() g=ColorGreen() b=ColorBlue() Cls Print "PlayField Width " + GraphicsWidth() Print "PlayField Height " + GraphicsHeight() Print "PlayField Depth " + GraphicsDepth() Print "PlayField Memory " + GraphicsBuffer() Print "PlayField Drawing Color (DEC) " + ColorRed() + " " + ColorGreen() + " " + ColorBlue() Print "PlayField Drawing Color (HEX) " + Hex$(r) + " " + Hex$(g) + " " + Hex$(b) End Function |
| ||
No reason to set r,g,b to zero. They are initialized zero. No reason to call ColorRed(), ColorGreen(), ColorBlue() in your decimal (DEC) statement because the values are already stored in r, g, b. So your function could look like: Function print_debug_info() r=ColorRed() g=ColorGreen() b=ColorBlue() Cls Print "PlayField Width " + GraphicsWidth() Print "PlayField Height " + GraphicsHeight() Print "PlayField Depth " + GraphicsDepth() Print "PlayField Memory " + GraphicsBuffer() Print "PlayField Drawing Color (DEC) " + r + " " + g + " " + b Print "PlayField Drawing Color (HEX) " + Hex$(r) + " " + Hex$(g) + " " + Hex$(b) End Function |
| ||
Wolron! Good input! Haven't used the "hex$" command before. I find it interesting that it defaults to 16-bit hex-output, and not 8-bit hex-output. Since "any" color can only be between "$00-$FF", I guess you could just truncate the "R", "G", and "B" variables so they only include 2 hex-digits each. Ah well, you learn something new every day :-) |
| ||
Lastly: 1) Don't use print, as it is slower. Instead use the Text command. 2) Are you using a back buffer ? Depending on how the main loop is set up you might want to drop the CLS command. If the area where the debug text is being displayed (print always prints to the FrontBuffer, Text prints to the current active buffer)is always being redrawn by other images/blocks then CLS is probally not necessary. Just call your Debug function AFTER all other graphic drawing commands but BEFORE the Flip command. 3) After you create your Graphics screen do something like this: Global screen_width = GraphicsWidth() Global screen_height = GraphicsHeight() Global screen_depth = GraphicsDepth() Global screen_buffer = GraphicsBuffer() Finally in your function: [ oh, out of personnal preference, I opt to term my functions which output text with 'display' as oppossed to print... that's just me though ;^) ] Function display_debug_info() r = ColorRed() g = ColorGreen() b = ColorBlue() Text 0,00,"PlayField Width: " + Screen_Width Text 0,14,"PlayField Height: " + Screen_Height Text 0,28,"PlayField Depth: " + Screen_Depth Text 0,32,"PlayField Memory: " + Screen_Buffer Text 0,46,"PlayField Drawing Color (DEC) " + r + " " + g + " " + b Text 0,60,"PlayField Drawing Color (HEX) " + Hex$(r) + " " + Hex$(g) + " " + Hex$(b) End Function I only guessing that your playfield is the Screen Buffer, so change whatever you use accordingly. Hope some of that helps. If I am wrong on anything, I am pretty sure it will get corrected. Happy Coding ! |
| ||
Dr. Delirium Tremens Thanks! Excellent feedback! |
| ||
The new version of the code actually looks like this - subject to change with the input from Delirium Tremens: ********************* ; ***************************** ; ONLY FOR DEBUGGING PURPOSES ; ***************************** Function print_debug_info() totalDrivers%=CountGfxDrivers() r_dec%=0 : g_dec%=0 : b_dec%=0 r_hex$=0 : g_hex$=0 : b_hex$=0 r_dec=ColorRed() : g_dec=ColorGreen() : b_dec=ColorBlue() r_hex=Hex$(r_dec) : g_Hex=Hex$(g_dec) : b_Hex=Hex$(b_dec) Cls Print "Date : " + CurrentDate() Print "Time : " + CurrentTime() Print "PlayField Width : " + GraphicsWidth() Print "PlayField Height : " + GraphicsHeight() Print "PlayField Depth : " + GraphicsDepth() Print "PlayField Memory : " + GraphicsBuffer() Print "PlayField Drawing Color (DEC) : " + r_dec + " " + g_dec + " " + b_dec Print "PlayField Drawing Color (HEX) : " + Right$(r_hex,2) + " " + Right$(g_hex,2) + " " + Right$(b_Hex,2) Select JoyType() Case 0 Print "Joystick : None" Case 1 Print "Joystick : Digital" Case 2 Print "Joystick : Analog" End Select For t = 1 To totalDrivers Print "Installed GFX driver(s) : " + GfxDriverName$(t) Next Print "Total GFX memory on card : " + TotalVidMem() + " " + "(Bytes)" + " " + (TotalVidMem() / 1024) + " " + "(Mb)" Print "Avail GFX memory : " + AvailVidMem() + " " + "(Bytes)" + " " + (AvailVidMem() / 1024) + " " + "(Mb)" Print "Operating system installed : " + SystemProperty("OS") Print "CPU installed : " + SystemProperty("CPU") End Function |