• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cozzie

(solved) Main thread and d3d?

5 posts in this topic

Hi,

I'm trying to make sure I'm calling create, testcooperativelevel, reset and release on my d3d device, from the main thread (same one as the window messages are handled). I'm not sure I understand the definition of a thread, I believe I only have one thread. Here's a bit of my code to give you a better view.

I'm doing the following calls to create, reset, release and testcooperative level:

Create => part of private function in d3d class, class includes mHwnd and d3ddev vars
Reset => part of private function 'ResetDevice' in d3d class, triggered from winproc of d3d window/hwnd
TestCooperativelevel => both from the winproc handler of d3d window/hwnd as within several member functions of d3d class
(also from main program loop, through 'CheckDevice' function, member of d3d class)
Release => in the destructor of my d3d class, in which d3ddev is a public member

CD3d		_d3d; // object of own d3d wrapper/class including mHwnd and md3ddev membersint WINAPI WinMain(HINSTANCE hInstance,				   HINSTANCE hPrevInstance,				   LPSTR lpCmdLine,				   int nCmdShow){        _d3d.CreateWindow();        _d3d.InitD3ddevice();        // load scene etc.	PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);	while(msg.message != WM_QUIT)	{		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))			{			TranslateMessage(&msg);			DispatchMessage(&msg);		}		else		{			if(active)			{				if(_d3d.CheckDevice())				{					_timer.CalcFps();					SetWindowTextA(_d3d.mHwnd, _timer.mStrFramerate);										// render 3d scene					if(!_d3d.RenderFrame(&_d3dscene, &_d3dcam)) 					{						MessageBox(_d3d.mHwnd, err_render.c_str(), err_windowtext.c_str(), MB_ICONERROR);							return (INT)msg.wParam;					}				}			}		}	}	return (INT)msg.wParam;}// windowproc, which is linked to the mHwnd in the _d3d objectLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){	int sleeptime = 20;	switch(message)		{		case WM_ACTIVATE:			if(LOWORD(wParam) == WA_ACTIVE || WA_CLICKACTIVE)			{				active = true;				Sleep(sleeptime);				break;			}			else				active = false;				Sleep(sleeptime);				break;			break; 		case WM_ACTIVATEAPP:			if(!wParam)			{				active = false;				Sleep(sleeptime);			}			if(wParam)			{				if(_d3d.mD3ddev)				{					if(!_d3d.CheckDevice())					{						{							while(1)							{								Sleep(sleeptime);								switch (_d3d.mD3ddev->TestCooperativeLevel())								{								case D3D_OK:									return 0;								case D3DERR_DEVICELOST:									break;								case D3DERR_DEVICENOTRESET:									{										_d3d.OnLostDevice();										_d3dscene.OnLostDevice();										if(!_d3d.ResetDevice()) break;										else										{											_d3d.OnResetDevice(&_d3dscene, &_d3dcam);											_d3dscene.OnResetDevice(&_scene, &_d3d.mD3ddev);										}										active = true;										break;									}								case D3DERR_DRIVERINTERNALERROR:									PostQuitMessage(WM_QUIT);								}							}						}					}				}				else active = true;				Sleep(sleeptime);			}			break; 		case WM_DESTROY:				PostQuitMessage(WM_QUIT);			break;		default:			return DefWindowProc(hWnd, message, wParam, lParam);	}	return 0;}

Does anyone know if I'm using just one thread and if I follow the MSDN statement that the d3d device calls are executed from the main thread?
(or can I only call Create, Reset, Testcooperativelevel, Release from the Wndproc function of the d3d window?)

0

Share this post


Link to post
Share on other sites

A good rule of thumb for you is if you don't know what a thread is, then you probably aren't using more than one :)

 

The thread where you have your WinMain and TranslateMessage and DispatchMessage is called the "MainThread".

 

If you put a breakpoint in Visual Studio inside your WindowProc you will see that ultimately it gets called back from the MainThread via the DispatchMessage routine.

 

So unless you explicitly go out of your way to make a new thread, you are only using one thread (MainThread), so you are complying with MSDN's usage pattern of D3D.

1

Share this post


Link to post
Share on other sites

For legacy technology you could have 2 threads.

  • General thread for processing everyting in CPU, the logic of appplication
  • Renderer, the thread, which has access to Direcr3D9 API

Such application would be faster significantly.

Main thread is schedulling operations to renderer, and the comsumer is getting commands from such queue and processing them in D3D.

 

Please, consider reading a book "GPU Pro" - ISBN 978-1-56881-472-8.

0

Share this post


Link to post
Share on other sites

Thanks both, for the quick reaction. Good to know that I can proceed for now.

I'll see if I can check out the book, to prevent that i'll accidentally create a 2nd thread when expanding my engine rolleyes.gif

0

Share this post


Link to post
Share on other sites

Here you are.

 

The authors of book are more than professionals, they are experts and MVP.

 

In my application, I have added a thread pool from the ATL library.

This pool is used for loading resources divided into tasks.

You would even heve more threads.

It would be a boost.

 

Not easy, but good start would be here:

http://threadingbuildingblocks.org/

0

Share this post


Link to post
Share on other sites

Thanks, will get into it. Especially if it will give a boost (when I'm further in development of my engine).

 

Still struggling with something else d3d though, which I thought would be related (but probably not):

http://www.gamedev.net/topic/636233-present-possible-loader-texts-d3d/

(calling dev->present to early it seams, checking cooperative level is not sufficient enough it seems)

 

Might you have any suggestions...

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0