It is currently Wed Aug 23, 2017 8:34 am

All times are UTC - 5 hours




 Page 2 of 4 [ 92 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Thu Oct 04, 2007 11:59 am 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
And yet I am here with another question, this class is just so big that there's a lot to ask. (personally I saw it fit to turn it into two classes :P)

In this class you store both a pointer to the WindowParameters structure (an instance of it actually and many of it's contents in different variables. Isn't this just redundancy?

PS I decided to double post because this is a couple of hours later than the last post and it's on a completely different topic.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Thu Oct 04, 2007 3:16 pm 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
I know I am being a pain, but I have internet again - which means I can finally ask all of those questions (even those I found earlier and put into my comments).

You define the member variable LONGLONG m_lCurrentTime, but you never use it. When you get into the getTimePerformance functions you use a local variable (LONGLONG lCurrentTime) instead. Is this intentional?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 5:48 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
About WindowParameters. Good catch, I didn't notice that earlier. Yes you can remove WindowParameters *m_pWndParam; from the class. You don't need to keep two copies.

About m_lCurrentTime. Another good find. You can remove LONGLONG m_lCurrentTime also.

A lot of times when I am developing stuff, I will first layout the class structure and variables, but then when I implement everything, I start to realize that I don't need certain items. It appears that I forgot to go back and remove the member variables that were not used in the end.

Keep up the good work, and let me know if you find anything else!


Last edited by Marek on Fri Jan 04, 2008 2:33 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 8:46 am 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
so my next questions:

in the countFPS function you static variables, why do you use static variables rather than member variables?

Also, wouldn't it save CPU time if you called displayFPSinTitle only when the framerate is updated? (that would be from within countFPS in the if-block)(Okey I guess this really isn't important as the fundtion is only temporary)

I really wonder what would happen if you gameState is say GS_MENU and you minimalise the game and then maximize it again. I haven't seen any code where you use a state other than GS_PLAY, GS_PAUSE or GS_STOP yet, but seeing the windowFocusRecieved function and windowFocusLost function, I think that either the computer continues to render (taking up unnecesary CPU time) or after the minimizing maximizing story gameState has become GS_PLAY. (once again I had to take these functions out completely (and I should reimplement their functions in some other way) because I am using glfw rather than window-specific libararies)

Last, but most certainly not least, why do you save deltaTime as a double and then cast it to a float when passing it to the updateGame function?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 8:56 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
static variables get declared once in memory. non static variables will get memory allocated and deallocated each time you run through the function. To avoid any slow downs, I use static variables inside functions that get used a lot. You can think of static variables as "globals" inside a class.

You won't see me using the game states very much early on. There is a separate VMK that discusses the window focus/lost issues and then you get to see what happens. Not until VMK39 will you really see the need for these other states, and by that time, the structure / functionality of the game states changed quite from what you are looking at in VMK 3.

about deltaTime. The function that gives me deltaTime, returns a double, so that is why I saved the variable as a double. I only use the "double" value when I render stuff inside UpdateGame so that is when I cast it. If I casted it earlier when I got the variable, the computation time to cast would be wasted for all the times that I don't actually use the value. Make sense?


Last edited by Marek on Fri Jan 04, 2008 2:34 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 9:16 am 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
static variables get declared once in memory. non static members
will get memory allocated and deallocated each time you run through the
function. To avoid any slow downs, I use static variables inside
functions that get used a lot. You can think of static variables
as "globals" inside a class.

That's just about how I think about member variable (or at least I can't make a distinction between what you said I should think of them like and member variables). I would have thought they would not be faster as the compiler can probably compile them in just the same way. I tried to google it, but I can not find any reference that static variables are faster than member variables.

about deltaTime. The function that gives me deltaTime, returns a
double, so that is why I saved the variable as a double. I only
use the "double" value when I render stuff inside UpdateGame so that is
when I cast it. If I casted it earlier when I got the variable,
the computation time to cast would be wasted for all the times that I
don't actually use the value. Make sense?

mostly... it just doesn't make sense to me why you don't just pass the function a double


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 10:14 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Re: Static variables. Sorry about that, I miss read your original question. I thought you were asking about static variables and regular variable. But now that I have re-read your question, you are asking about static member variables and regular member variables. Okay, there is a big difference here. Take a look at the C++ VMK 9b that describes static variables.

Re: double: If you want, feel free to pass a double, I'm sure it isn't going to make that much of a difference in the end anyway. The only thing that comes to mind is memory size. Passing a float (4 bytes) may be faster than passing a double (8 bytes) into a function. But then again it depends on the CPU that you are using.


Last edited by Marek on Fri Jan 04, 2008 2:34 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Fri Oct 05, 2007 12:49 pm 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
RE: static variables... that would take me about two weeks before I could download that VMK (and I also prefer to spend my downloads on the GameEngine as I really use that one, rather than spending two weeks of slots on getting one difference charted). I know, I know, that's bussiness.

I can see some small differences (okey one big one as well, but as there is supposed to only be one instance of this object that one should not matter), but none that matter in this case. I know that you can access static variables only in the function in which they were initialized. I know that there will only be one static variable (containing one value) even if there is more than one instance of the object. I know that being static prevents a variable from being re-initialised. I know that being static initialises your variable at 0, even you don't do that yourself (but you should, for clarity's sake). But none of these things provides me with a reason to use a static variable in this case rather than a member variable.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Sat Oct 06, 2007 7:31 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
I took a look at countFPS and I see what you mean now. Originally I was using just regular variables (non-member) inside this function. However since countFPS was going to be called many times, I decided to change the variables to be static so that I don't have to allocate and deallocate memory for them every time the function is called. I didn't want to make these two variables members of the class because the only place that dTotalTime and loops is used is inside the function.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Sun Oct 14, 2007 3:25 pm 

Joined: Fri Oct 12, 2007 4:41 pm
Posts: 24
(GameOGL::*GetDeltaTime)(void);

I have never seen something like this before, it looks rather different than the normal function. Could you explain it?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Sun Oct 14, 2007 4:44 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
This is a pointer to a function, not a regular function. I use GetDeltaTime to point to either the function GetTimePerformanceHigh(void) or GetTimePerformanceRegular(void).

This way in the code I can always just use GetDeltaTime but depending on how it was initialized, this will call either the High or Regular version of the code.


Last edited by Marek on Fri Jan 04, 2008 2:36 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Mon Oct 15, 2007 10:27 am 

Joined: Fri Oct 12, 2007 4:41 pm
Posts: 24
CS_HREDRAW | CS_VREDRAW | CS_CLASSDC | CS_DBLCLKS

What do these parameters mean?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Mon Oct 15, 2007 10:34 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Have a look at msdn: http://msdn2.microsoft.com/en-us/library/ms633574.aspx


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Mon Oct 15, 2007 9:54 pm 

Joined: Wed Sep 12, 2007 10:56 pm
Posts: 7
My hard drive died the other day and now going back through and redoing this, I have a question regarding how you arrived at setting m_dTimeScaleFactor = 0.001 for use in the GetTimePerformanceRegular function. Was this something you played around with, or is there a mathematical equation to get it, or most likely is it just a standard practice?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Mon Oct 15, 2007 10:29 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
0.001 = 1 millisecond. This is an arbitrary value right now because we don't have a physics engine. Once dynamics are being calculated, this value may need to be tweeked.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Sat Nov 10, 2007 11:21 am 

Joined: Tue Nov 06, 2007 7:37 am
Posts: 1
Hello,
@Marek : Thank you for this site. Great work !

Can you/anyone explain me the SetWindowLong function in GameOGL::WindowProc(...) ?

I've read the MSDN article and the definition in WinUser header about the function but it don't make sense to me. What is the aim for setting the GWL_USERDATA to LPCREATESTRUCT->lpCreateParams and wherefore the cast to GameOGL pointer (in switch:default) ???


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 3 - GameOGL class
PostPosted: Sat Nov 10, 2007 12:20 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
In a nutshell this is what happens.

When we go inside GameOGL::create we call CreateWindowEx with a pointer to this as the last parameter in the function call. This tells windows to create a new window for us.

When the windowProc is setup for us the first time through, we get a message called WM_NCCREATE. Using this message we can get the "this" pointer value that was passed into the CreateWindowEx function and save it as our own userData.

From now on, anytime that windowProc is executed, we use GetWindowLong to retreive the userData that was saved on initalization. We now have access to "this" which is really a pointer to GameOGL. This allows us to do what ever we like within the GameOGL class. (ie call messageHandler)


Last edited by Marek on Fri Jan 04, 2008 2:37 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 11:53 am 

Joined: Wed Jul 04, 2007 10:07 am
Posts: 3
Jasper, I don't think your question about the ? true : false was completely answered... in RenderPost there is the line:

return (SwapBuffers(m_hDC) ? true : false);

which as you said, if it is true, returns true. However, SwapBuffers returns a BOOL, and the RenderPost function returns a bool. VC treats these differently, but it knows how to convert between them. You can just use:

return SwapBuffers(m_hDC);

but the compiler might complain. (VC2005 warns "forcing value to bool 'true' or 'false' (performance warning)").

Derek.


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 2:02 am 

Joined: Tue Jan 08, 2008 9:25 pm
Posts: 5
Location: Utah
I finished working on VMK 3c and went to compile... 58 errors! :shock:

Mostly typos but I ran into one problem and I would like your opinion:

I am using VS2005 Professional Edition and it kept issuing the following warning when off of this code:

GetDeltaTime = GameOGL::GetTimePerformanceHigh;


Output:
error C3867: 'GameOGL::GetTimePerformanceHigh': function call missing argument list; use '&GameOGL::GetTimePerformanceHigh' to create a pointer to member


http://msdn2.microsoft.com/en-us/library/b0x1aatf(VS.80).aspx

So I followed it's suggestion and did this:

GetDeltaTime = &GameOGL::GetTimePerformanceHigh;

Which makes the compiler happy but do you think this will muck things up?

Also, it issued the following warning:

warning C4715: 'GameOGL::Create' : not all control paths return a value


Am I up in the night worrying about stuff and/or is VS2005 just very picky?

The entire solution up to this point complies (with exception to points above) but when ran, it loads an 8mb .exe into memory that consumes roughly 50 cpu cycles consistently but shows no window and I have to kill it manually through the task manager. Does any one have any thoughts?

Thanks in advance!


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 7:35 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
When writing this code in VS 2005, you will need to use GetDeltaTime = &GameOGL::GetTimePerformanceHigh; The compiler has changed syntax for defining function pointers. So this is correct.

This warning C4715: 'GameOGL::Create' : not all control paths return a value, means that your function has an if statement inside of it and at least one of the paths that exit your function are missing a return value.

For example, if I had this written:

bool myFunction(int i) {
   if ( i > 0) {
      printf("true");
      return true;
   }
   else {
      printf("false");
      // return false; //This will cause warning C4715.  Uncomment this line!
   }
}


Offline
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 11:26 pm 

Joined: Tue Jan 08, 2008 9:25 pm
Posts: 5
Location: Utah
figured out my C4715 error and it was directly related to the fact that the .exe would run and show no window... i closed the last if statement in GameOGL::Create too late (after the last return statement).

viola! white window with title bar... my FPS jumped all over like crazy from 150 to 220 very rapidly the first time i ran it. each time thereafter it was at a consistent 100 fps.

thanks! :D


Offline
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 6:57 am 

Joined: Sat Jan 12, 2008 6:01 am
Posts: 2
Hello,

Thank you really much for your work.

I notice something strange in void GameOGL::Initialize() in VMK3c with this line :
glEnable( GL_PERSPECTIVE_CORRECTION_HINT );

it compile with no problem under windows and mac os x but with mac os x, I have a warning when i launch the application
=> An internal OpenGL call failed in RenderWindow.cpp (133) : GL_INVALID_ENUM, an unacceptable value has been specified for an enumerated argument

It seem that glEnable can't take the parameter GL_PERSPECTIVE_CORRECTION_HINT


Thanks.


Offline
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 7:43 am 

Joined: Sat Jun 23, 2007 7:56 pm
Posts: 145
Hi,
from this link http://developer.apple.com/documentation/Darwin/Reference/Manpages/man3/glHint.3.html

GL_PERSPECTIVE_CORRECTION_HINT is NOT used in glEnable(). It is used in glHint(GLenum target, GLenum mode ) as a target.

This link is for glEnable and its accepted parameters
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/glEnable.3.html

Hope that helps.


Offline
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 7:15 am 

Joined: Tue Feb 26, 2008 3:30 am
Posts: 3
about the warnings you couldn't figure out:

SetWindowLong(hWindow, GWL_USERDATA, (long)(LONG_PTR)(((LPCREATESTRUCT)lParam)->lpCreateParams));


and

pWnd = (GameOGL*)(LONG_PTR)GetWindowLong(hWindow, GWL_USERDATA);


will solve those, so you won't need the #pragma warning code


Last edited by LostBinary on Tue Mar 11, 2008 2:06 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject: error when compiling GameOGL
PostPosted: Thu Mar 20, 2008 1:19 am 

Joined: Fri Jan 04, 2008 2:11 pm
Posts: 72
using vc++2005..

i get these two errors but can't fix them....maybe you can help me with this

..\gameogl\gameogl.cpp(38) : error C3867: 'GameOGL::GetTimePerformanceHigh': function call missing argument list; use '&GameOGL::GetTimePerformanceHigh' to create a pointer to member

..\gameogl\gameogl.cpp(49) : error C3867: 'GameOGL::GetTimePerformanceRegular': function call missing argument list; use '&GameOGL::GetTimePerformanceRegular' to create a pointer to member

these errors are removed when i use '&' in front of the function calls ...but
after compiling the game crashes and the log has a error:

"Date(M/D/Y):03/20/08
Time:11:46:33

Engine initialised
Could not find suitable OpenGL pixel format to use.

plus the showerror() dialogue box doesn't appear ..just an error sound and then nothing..


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 2 of 4 [ 92 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron