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.

Dark GDK / Trouble with a function in game loop

Author
Message
tuttle 4077
13
Years of Service
User Offline
Joined: 12th Nov 2010
Location:
Posted: 12th Nov 2010 20:15
Hello, sorry if this is a nooby question but I for the life of me cannot figure this out. I have a program I'm making which is essentially a lunar lander kind of program. I have a high score list I'm trying to work into the program. I have an array and a for loop that sorts everything fine. However, when I let the user enter their name for the high score list, the entire screen goes blue. My background disappears and I don't even see any prompts, but I can type, and whatever I do type will show up in the high score list after I hit enter. But nothing else shows besides the high score list. The background shows whenever I don't run the for loop to do the high score list, so I'm assuming the problem lies in there somewhere, but beyond that I'm stumped. Any help that you can provide, or even cleaning up the code, is greatly appreciated.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Nov 2010 02:57
I've just experimented with it and got it working this way.

dbDrawToFront(); dbSync();

dbPrint( anything );
foo=dbInput();

This showed what was printed and what I was typing on the screen before the next dbSync() command.

I was looking for just drawing on the front buffer originally.

Warning! May contain Nuts!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Nov 2010 03:17
Dur... I should have realised... Turn the Sync off... dbSyncOff()

Warning! May contain Nuts!
tuttle 4077
13
Years of Service
User Offline
Joined: 12th Nov 2010
Location:
Posted: 15th Nov 2010 15:42
Thank you so much for your help, however I still seem to be having problems with it :-(

I tried turning the sync off and back on around the part where I'm looking for input, and it actually made it worse. I still had no picture and the text on the screen actually flashed on and off, almost like blinking. I tried the dbDrawToFront() function but I'm not necessarily sure I understand the context in which it should be used. I looked in the documentation for DarkGDK and I didn't see it there either. Could you explain this one to me?
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 28th Nov 2010 23:25
The dbDrawToFront() function turns all drawing commands to the front buffer only. The screen has by default on Syncing a back buffer and a front one. The front one is the current displayed whilst the back buffer is where all drawing takes place before it is flipped with the screen.
Whilst using sprite commands and 3D commands you don't usually have to be careful when using the print command. But when using the input command you may have to freeze all drawing commands whilst the input command is being used. I'm assuming this as most engine api's are the same unless you implement your own input function.

Warning! May contain Nuts!
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 29th Nov 2010 04:57
I like using dbGetEntry(). It has plenty of "what was typed" functionallity and you can use it to update a string:

Simply declare a string like:
and call the function:

This gives you a way to do it while still rendering the scene. The second para is the maximum number of letters.

The fastest code is the code never written.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 30th Nov 2010 01:55
Quote: "dbGetEntry()"


You have to use it like this:


Or else it will cause a memory leak every time it is called.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Nov 2010 04:10
Quote: "You have to use it like this:
"

When you call
it "clears" the entry buffer. I don't know if that deletes the section of memory that dbGetEntry() uses or if it just clears it, but I haven't seen any memory leaks on my machine using the method I posted.

The fastest code is the code never written.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 1st Dec 2010 00:41
After testing, dbEntry does not allocate a new string, so you're fine.

But most functions returning a char* dynamically allocate a string using new, so delete must be called afterward when you're done. (Especially dbStr)

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 1st Dec 2010 18:29
Quote: "But most functions returning a char* dynamically allocate a string using new, so delete must be called afterward when you're done. (Especially dbStr)"

I use dbStr() in my loop with no destruction EVER. I have not seen any leaks. I am confident that those with char* as a return value have a pointer set up that is checked for NULL each time and is released if not NULL before reallocating for the return.
Something like this:

I know there are C/C++ methods for the obove "methods", but I don't have access to that info at this pc.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-09-28 14:09:23
Your offset time is: 2024-09-28 14:09:23