|
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
|
|
|
|
|
This[^] seems like a nice set of tutorials to help you get started.
But I think you'll find no better site than CodeProject[^] when you have questions or need help or want to dive deeper into the wonders and quagmire of MFC.
/ravi
|
|
|
|
|
|
I'm working on a GUI editor for a video game. The GUI items (buttons, images, etc) are simply a hierarchy of simple rectangle regions.
I need to create a C++ MFC Tool Window that displays the hierarchy. I know what you're thinking "use a tree control". The problem is that:
1) the hierarchy may get very deep; which causes ugly horizontal scrolling.
2) each item needs custom display options to toggle visibility of the item in the main view.
3) It also needs to render additional icons next to the text to show status information. Some status icons might be things like "item has script attached to it", or "item has events attached to it".
4) I need to select multiple items from the control at a time (like a list box)
The closest thing I can relate it to would be Photoshop's Layer View Window. The key difference would be that I need to display the items as a hierarchy.
I implemented a version of this control as a list box and simply inserted space characters for child items to display the hierarchy (based on recursive depth). This worked OK but had all kinds of update issues and bad refreshes, and inaccurate displays of which items were actually "selected". It sucked...
I also couldn't use any of my accelerators that were attached to the main window frame because the tool window had focus.. But that's likely another issue all together..
HELP! Has anyone implemented something like this?
-- modified at 12:40 Friday 9th February, 2007
|
|
|
|
|
Taking each problem separately, you can adjust the indent width with the TVM_SETINDENT message, which may help the display of deeper trees.
If by you mean toggling visiblity, you mean removing an item and its subtree entirely, or just hiding its label and child items? You might be able to get away with just collapsing the item, or you can even remove the entire subtree of necessary, adding it back and redrawing as necessary.
Each tree item can have its own icon. A little "Custom Draw" magic can be used to render additional visual information as well.
Multiple selection can be simulated by using the TVIS_DROPHILITED item style (setting and later checking for it).
There are a few articles here that talk about using a custom TreeView control, as well as one or two ways to use a ListView control as a multi-column tree control.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks for the help!
By the way,
What I meant by visibility is more like the the EYE icon you see in Photoshop, where it acts like a Check Box. If you enable the box, it will cause that layer to be rendered (elsewhere in the main window; not directly related to tree view). If disabled, then that branch of the hierarchy will be ignored when rendering the items in the main window.
ex: GUI navigator
[] = icon / bitmap
# = a check box to determine if the branch should be rendered in the main frame
> = collapsed node
V = expanded node
Y = (optional) item has script assigned to it
Z = (optional) item has mouse/key events that it's listening for
-------------------------------
| Navigator |
-------------------------------
| [#]V ROOT [ ][ ] |
| [#]> CHILD 1 [ ][Z] |
| [#]V CHILD 2 [Y][ ] |
| [ ] SUB-CHILD [Y][Z] |
-------------------------------
I appreciate the help, it definitely gives me a solid direction to take now.
If only I could have done it in ASCII I'd be done by now. hehe.
|
|
|
|
|
TVM_SETINDENT seems to be clamping the results to 15 or larger for some reason. This is not a huge issue as I've decided to write a custom owner draw for the tree; based on the VividTree article. I nudge the RECT region back by a fixed indent; based on the results I get back from GetItemRect() for each item.
TVIS_DROPHILITED worked great! I got it to behave exactly as I intended.
Going the route of Owner-Draw was a bit more of a hassle but it really let me tweak the visuals.
[ question ]
Does TreeCtrl not support double clicking?
<br />
...<br />
afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);<br />
afx_msg void OnDblClick(NMHDR* pNMHDR, LRESULT* pResult);<br />
<br />
...<br />
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblClick)
END_MESSAGE_MAP()<br />
Thanks again,
- Ben
|
|
|
|