|
The problem with a global is that you can't debug it, or control it. At a minimum, create a class that has public static methods to get and set variables which are private. That way, you can set breakpoints if you need to debug access to the values. Even better, create a class with protected members, and make the classes you want to grant access, friends of that class.
Lord Kixdemp wrote: you do live here, don't you?
*grin* 14+ hours a day, yeah.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
That is all very nice and true only one problem: this guy said he used C and not C++..
I guess u could some OO implementation in C (header represents a class and each function takes a pointer to structure that represents 'this'), still u don't have encapsulation...
|
|
|
|
|
Oh, I missed that. Then, there's no way around it. C kind of sucks that way.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What would you do without global variables?
|
|
|
|
|
|
Write maintainable code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Maintainable code? What do you mean?
Windows Calculator told me I will die at 28.
|
|
|
|
|
It means, code that is easy to work on if you have to come back to it later.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.
void CNew1Dlg::OnBUTTONPick() <br />
{<br />
CString textSub;<br />
textSub.Format("%d %s", someNumber, someString);<br />
GetDlgItem(someEditBox)->SetWindowText(textSub); <br />
}
|
|
|
|
|
Oliver123 wrote: Is a separate CString textSub instance created each time the function executes?
Of course. You don't need to clean it up, it's not a pointer, it will clean itself up ( calling it's own destructor )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Unless you use a "new " operator explicitly,it gets cleaned up automatically once it looses it's scope (Once it returns back to the caller). If you had used "new " to instantiate the object,then you need to "delete " it mannualy.
Dario: How is "directory" in French? (I mean a file system directory).
John Simmons: "zee file holdaire thingie"
|
|
|
|
|
Another important thing is: sometimes you'll need to call GetBuffer() or another function of that kind, if you do that, you must remember to call also ReleaseBuffer() just before exiting the scope of the CString variable.
Hope this helps
|
|
|
|
|
Hi,
I've got implemented Windows Error Reporting for XP(faultrep.dll, ReportFault, SetUnhandledExceptionFilter), but it's not working for Vista.
Vista has a new DLL(wer.dll) and new API for that(WerReportCreate, WerReportSubmit, WerReportCloseHandle). I've tried search web for some code example, but unsuccesefully.
Is anybody can explain the proper way to implement it with new API or send some code examle.
I'll appreciate any info/code.
Thanks.
|
|
|
|
|
oleg63 wrote: I've tried search web for some code example, but unsuccesefully.
They hide that information in the documentation[^]
led mike
|
|
|
|
|
Thanks Mike for the prompt answer,
I've red that documentation but it's just API description without a real example.
Sometimes you need not just API but the way how to employ it in your application.
|
|
|
|
|
Okay, there's a game, a while loop, and a timer to make the game go at 60FPS
while(timer > 0) {
/* GAME STUFF */
timer--;
}
When the user presses ESC, it calls a function, or method, whatever you wanna call it. Anyway, inside it is a while loop, like this:
while(true) {
if(user clicks yes)
return 1;
if(user clicks no)
return 0;
}
So it will wait forever for the user to do something, i expected this to stop the game. But after selecting no, to continue the game, stuff has still happened. Falling to the floor for example.
The game also has a pause thing in place, so if Paused == true, nothing happens. I tried adding that to the above while loop, game didn't get paused, player still fell to the floor. Leaving me rather confused.
Anyone have any ideas on this? Anything at all.
|
|
|
|
|
The Undefeated wrote: Anyone have any ideas on this? Anything at all.
Yes, it sounds like you need some additional threads to handle the various events going on. With only one thread, it's busy running the game and has no time to handle mouse clicks and such.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
??? But its supposed to stop running the game while the while loop is in action.
The game still semi runs, gravity still carries on, and so does swinging, but some other thing don't, like collision checking. So what ends up happening is, you press ESC, as something is coming towards you, you decide you don't want to quit, and it tells you you just got hit. And all these things are all done after the check for the user pressing ESC as well, so they shouldn't happen at all. Id understand if i was actually using more than one thread, but, im not.
I am using allegro though, thats whats checking keys and the mouse, and the timer, but i'll probably get windows to do the timer later on.
Also when i debug the thing it says it stays in the loop, but stuff still changes.
|
|
|
|
|
Hello,
Just read “Idle Loop Processing” on MFC.
Regrads,
|
|
|
|
|
But i want the app to freeze while it waits...
*sigh* maybe i'll just change it so it works, and never know why this crazy stuff happened.
|
|
|
|
|
Are you new at this programming stuff?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Are you saying that because i want to freeze the game to wait for some input (which would probably mess up the timer, and the user wouldn't see the screen for a short while - not so fantastic i know, but not really the point of the topic)
Or because of something else?
|
|
|
|
|
The Undefeated wrote: Or because of something else?
McDonalds has Fish Filet
led mike
|
|
|
|
|
first how have you declared your timer variable and how are you updating it?
A basic game loop is like this:
volatile int timer = 0;
bool pause = false;
void mytimerfunc()
{
if ( pause == false )
timer++;
}
int main()
{
while ( userwantstoquit == false )
{
while ( pause == false && timer > 0 )
{
if ( userwantstopause )
pause = true;
timer--;
}
}
}
Now a short explanation:
look at the while( timer > 0 ) loop. You decrease the counter each time, your timer callback or thread will increase it at your fps rate. Your timer must run on it's own, outside that loop, which means the standard windows timer in no good ( it relies on windows messages ). Because you declare the timer var as a volatile, it means your loop will no stop it from being increased outside the loop.
Don't think of fps as how many times you draw to the screen. It is really how many times you run your logic. Do all your drawing, even offscreen drawing, outside that loop. Drawing takes a long time and should not intefere with the logic. The logic loop is only for calculating. IE if you have a person walking, you calculate their position in the next frame, then when you have to spare you render it to the screen.
-- modified at 17:51 Friday 9th February, 2007
|
|
|
|
|
I know this, and my loops are set up like that (or similar) and i don't have the if statement for pause on the timer, i still want that to run, i have this nice background for when i pause.
And yes, the timer will increase (hence the reason this isn't actually a fantasic idea), but while its running the looping waiting for the user to click yes or no, it still does some parts of the logic, but not others. Thats whats wierd.
-- modified at 18:15 Friday 9th February, 2007
|
|
|
|