|
??? 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
|
|
|
|
|
Hi all,
I'm new to C++. I've a stupid problem. This is the code I used:
<br />
class A<br />
{<br />
int x;<br />
};<br />
<br />
class B<br />
{<br />
template<class T> void temp(void){ };<br />
void test(void);<br />
};<br />
<br />
void B::test(void)<br />
{ <br />
temp<A>(); <br />
};<br />
Why can't I compile this code? The error message is:
test.cpp(23) :error C2275: 'A' : illegal use of this type as an expression
test.cpp(23) : error C2059: syntax error : ')'
If I move the template function temp() out from class B, then it is ok. Could someone help me? Thanks a lot.
|
|
|
|
|
Which compiler do you use?
|
|
|
|
|
Sorry for missing the platform. I use VC6.0. I also try on VC Express, it is ok. So, it is compiler problem?
|
|
|
|
|
it works fine in VS 2005, but fails in VC6.
not sure why it fails.
|
|
|
|
|
VC6 has problems when a template type parameter doesn't appear in the function's parameter list, as is the case in hsuch's sample code. The usual workaround is to add a dummy T* param that defauls to NULL .
|
|
|
|
|
you mean like this?
class A
{
int x;
};
class B
{
template < class T > void temp(T *)
{
}
void test(void);
};
void B::test(void)
{
A z;
temp< A >(&z);
};
that doesn't work either.
edit: adding the "T* = NULL" works, though
|
|
|
|
|
|
Are you wanting something like:
class A
{
int x;
};
class B
{
template<class T> void temp(const T& data){ }
void test(void);
};
void B::test(void)
{
A a;
temp(&a);
};
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
If you're using VC6, change it to
template<class T> void temp(T* = NULL) { } to work around a compiler bug.
|
|
|
|
|
class A
{
int x;
};
class B
{
template<class T> void temp(T* = NULL){}
void test(void);
};
void B::test(void)
{
temp<A>();
};
Still doesn't work.
|
|
|
|
|
Does anyone know of a book or of a website that explains MFC in easy terms ?
I'm pretty much of a begginer in C++ (although i know C very good ).
Anyway, I'm looking for some examples in MFC and their solutions, that will give me a good base to start learning advanced MFC programming.
Thanks
Alessandra
|
|
|
|
|
if you want a site www.codeproject.com and www.cplusplus.com are helpfuls
|
|
|
|
|
Thanks
Alessandra
|
|
|
|
|
You're welcome
|
|
|
|
|
Since much of MFC is an object-oriented wrapper around Windows APIs, I think it's important
to know the basics of Windows programming - windows, messages, etc. MFC then provides a nice
C++ wrapper for that functionality.
Mark
|
|
|
|
|
Mark Salsbery wrote: I think it's important to know the basics of Windows programming
Agreed 100%!
/ravi
|
|
|
|
|
Sure but that's a lot of trouble to go through for a Fish Filet
led mike
|
|
|
|