Page 1 of 1

How to trap win32 event (WM_TIMECHANGE) in ogre

Posted: Mon Jan 24, 2005 3:19 pm
by ritz
Hello ,

I need to trap WM_TIMECHANGE event in ogre application.
As their is no direct support for this.

How can i trap this event in any ogre application

rgds,
Ritz

Posted: Mon Jan 24, 2005 3:54 pm
by DWORD
You can make your own rendering loop, and process windows messages in it.

Trapping win32 event

Posted: Fri Jan 28, 2005 8:21 am
by ritz
Hello,

Thanks for reply.
Can any body please give me any code sample for the same.


rgds
Ritz

Posted: Fri Jan 28, 2005 2:40 pm
by sinbad
This is not exactly a common Ogre requirement. Use the Windows SDK docs, man :)

Posted: Fri Jan 28, 2005 11:30 pm
by jacmoe
Or post it in the "Back to Basics" area ?

Posted: Sat Jan 29, 2005 12:14 am
by Silent
Here is the 0.15 Root::startRendering loop:
//-----------------------------------------------------------------------
void Root::startRendering(void)
{
assert(mActiveRenderer != 0);

mActiveRenderer->_initRenderTargets();

// Clear event times
for(int i=0; i!=3; ++i)
mEventTimes.clear();

// Infinite loop, until broken out of by frame listeners
// or break out by calling queueEndRendering()
mQueuedEnd = false;
while( !mQueuedEnd )
{
#if OGRE_PLATFORM == PLATFORM_WIN32
// Pump events on Win32
MSG msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
#endif

if (!renderOneFrame())
break;
}



However, nothing requires you to use this method. You can write your own, duplicating most of the logic and adding any of your own. I believe you can simply add an if statement like the following:

MSG msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
if (msg.message == WM_TIMECHANGE)
{
; // anything you want here
}

}


Not sure if that's what you're looking for. Hope it helps.

Edit:

Not sure how to handle this part of the code though.

// Clear event times
for(int i=0; i!=3; ++i)
mEventTimes.clear();

Posted: Sat Jan 29, 2005 10:10 pm
by Kristian
Alternatively you could hook into the ogre render window message proc by writing a bypass and redirecting back to the original proc. and then process your window message here instead of having to rewrite the render plugin every time you have update ogre.

Posted: Sun Jan 30, 2005 1:11 am
by Silent
Sorry, I guess my intention wasn't clear. I was proposing that the new rendering loop be implemented in the App code, not by modifying Ogre. I consider the Ogre startRendering method to be a convenience routine, to be used or not used as you see fit.

As an aside, I think the goal in writing a good library is that it should stand on it's own without the need for modification. So I tend to look for solutions that don't rely on changes in the core Ogre code. Of course, if a change is really needed ... :-)

Posted: Sun Jan 30, 2005 12:00 pm
by jacmoe
The startRendering() method really is convenience!
If you don't call it, you are free make your own rendering loop.
No need to touch the Ogre core.
And the example framework is just an example. Feel free to do your own thing. And take a peek at meshviewer, Yake, etc. for hints on how to code.

capturing WM_TIMECHANGE

Posted: Wed Feb 02, 2005 9:54 am
by ritz
Hello,

Thanks for responsind.

I tried using the first approach .

a) replacing startRendering method.

I am not able to undertand how do i replace the complete code of this methiod.

Can any body plese tell me siginificance of the code written above and after the loop.

I do not want to touch any default functionality except for catching WM_TIMECHANGE event.


Code for startRendering
------------------------------
assert(mActiveRenderer != 0);

mActiveRenderer->_initRenderTargets();

// Clear event times
for(int i=0; i!=3; ++i)
mEventTimes.clear();

// Infinite loop, until broken out of by frame listeners
// or break out by calling queueEndRendering()
mQueuedEnd = false;
while( !mQueuedEnd )
{

#if OGRE_PLATFORM == PLATFORM_WIN32
// Pump events on Win32
MSG msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
#endif

if (!renderOneFrame())
break;
}



Approach -2 ) hook to ogre render window message proc - Can i get more details about th eproc. where i can get this.

I am not able to reach to the windowproc in ogre code.


rgds,
Ritz

Trapping WM_TIMECHANGE

Posted: Wed Feb 02, 2005 10:09 am
by ritz
Hello All,

Here is the Objective of doing ALL this

I am creating a Calender widget using CEGUI library.

I need to update the current date in the calender when ever user changes the date in the system.

In order to reflect the change i need a notification for the system date change in my widget.

Is their any other way to know about the date change.

Most important is i donot want to touch the nase ogre or CEGUI code.

rgds,
Ritz



Tried Approach - 2 Also.
--------------------------
I did tried trapping event in render window proc, i am able to trap it.

But again the issue is i do not want to touch the base code

----
LRESULT D3D7RenderWindow::WndProc(
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )

-----

Is their any way to do it so that the changes remain in my code onle.

Posted: Thu Feb 03, 2005 4:12 am
by Silent
Silent wrote:Sorry, I guess my intention wasn't clear. I was proposing that the new rendering loop be implemented in the App code, not by modifying Ogre. I consider the Ogre startRendering method to be a convenience routine, to be used or not used as you see fit.
Here are some fragments from my own code (modified somewhat):

Code: Select all

void Application::start()
{
  if (setup())
    startRendering();  // call our rendering loop, not Ogre's
}


void Application::startRendering()
{
  renderSys->_initRenderTargets();

  while (true) {

#ifdef WIN32
    MSG msg;
    while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
#endif

    if (!root->renderOneFrame())
      break;
  }
}
The Application class is based loosely on code from the Ogre tutorials, so it should look familier. I added the startRendering method and call it from the start method after setup has been called. The setup method does what you would expect, it creates the Ogre root object, etc..

I haven't rung out this section of code yet, in case someone spots any issues :-)

Hope this helps.

Thanks

Posted: Thu Feb 03, 2005 6:09 am
by ritz
Hello Silent,

Thanks a Lot.

Now I am able to understand and implement it.

rgds,
Ritz