• 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) 3d engine classes and the basics?

2 posts in this topic

Hi, I'm working for a 3d engine (D3D) for quite a while and now rethinking some basics, like windows message handling (because of alt+tab causing troubles). What I'd like to know, is if my choices on the basic layout of my classes, is logical looking at windows programming. I've added some parts of my source to illustrate. I'm not 100% sure of the usage of my HWND variable is correct, same for 'hinstance' etc. Debugging shows that the HWND variable sometimes has a logical value, i.e.: (unused = 327680000) and sometimes (unused=????; CXX0030: error: expression cannot be evaluated). Might this have to do with my choices on the hwnd variable (in d3d class)? These basics might also affect basic message handling like WM_ACTIVEAPP etc. (Which is acting weird at the moment, I think). I also don't pass 'hwnd' yet as a pointer the DirectInput (initialization). Any help and hints are appreciated. [source lang="cpp"]/** SOURCE FILE D3D.H **/ class CD3d { public: HWND mHwnd; LPDIRECT3DDEVICE9 mD3ddev; // other vars deleted for forum/ prevent too much source bool InitWindowClass(WNDPROC pWindowProc, int *pNcmdShow, HINSTANCE *pHinstance, int pSw, int pSh, bool pWindowed); bool InitD3dDevice(int pAa); CD3d(); ~CD3d(); private: WNDCLASSEX mWc; LPDIRECT3D9 mD3d; D3DPRESENT_PARAMETERS mD3dpp; D3DDEVTYPE mDevType; D3DFORMAT mAdapterFormat; DWORD mVertexProcessing; D3DFORMAT mDepthStencilFormat; // other vars deleted for forum/ prevent too much source bool FindMaxDeviceSettings(); //D3DDEVTYPE *pDevType, D3DFORMAT *pAdapterFormat, D3DFORMAT *pDepthStencilFormat, DWORD *pVertexProcessing, bool pWindowed); bool ChooseMSAASettings(int pAa); }; /** SOURCE FILE D3D.CPP **/ CD3d::CD3d() { mHwnd = NULL; mD3ddev = NULL; mD3d = NULL; // other code removed for forum/ prevent too much source } bool CD3d::InitWindowClass(WNDPROC pWindowProc, int *pNcmdShow, HINSTANCE *pHinstance, int pSw, int pSh, bool pWindowed) { DWORD style; mScreenWidth = pSw; mScreenHeight = pSh; if(pWindowed) mWindowed = true; else mWindowed = false; ZeroMemory(&mWc, sizeof(WNDCLASSEX)); mWc.cbSize = sizeof(WNDCLASSEX); mWc.style = CS_HREDRAW | CS_VREDRAW; mWc.lpfnWndProc = (WNDPROC)pWindowProc; mWc.hInstance = *pHinstance; ShowCursor(FALSE); mWc.lpszClassName = L"WindowClass"; if(!mWindowed) { mWc.hbrBackground = (HBRUSH)COLOR_WINDOW; style = WS_EX_TOPMOST | WS_POPUP | WS_OVERLAPPEDWINDOW; } style = WS_OVERLAPPEDWINDOW; if(0 == (RegisterClassEx(&mWc))) return false; if(NULL == (mHwnd = CreateWindow(L"WindowClass", L"Crealysm", style, 0, 0, mScreenWidth, mScreenHeight, NULL, NULL, *pHinstance, NULL))) return false; ShowWindow(mHwnd, *pNcmdShow); return true; } bool CD3d::InitD3dDevice(int pAa) { // check capabilities and select adapter format settings if(!FindMaxDeviceSettings()) return false; // d3dpp present parameters setup ZeroMemory(&mD3dpp, sizeof(mD3dpp)); if(!ChooseMSAASettings(pAa)) return false; mD3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; mD3dpp.hDeviceWindow = mHwnd; mD3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; if(!mWindowed) { mD3dpp.Windowed = false; mD3dpp.BackBufferWidth = mScreenWidth; mD3dpp.BackBufferHeight = mScreenHeight; } else mD3dpp.Windowed = true; mD3dpp.BackBufferFormat = mAdapterFormat; mD3dpp.BackBufferCount = 1; mD3dpp.EnableAutoDepthStencil = TRUE; mD3dpp.AutoDepthStencilFormat = mDepthStencilFormat; HRESULT hr = mD3d->CreateDevice(D3DADAPTER_DEFAULT, mDevType, mHwnd, mVertexProcessing, &mD3dpp, &mD3ddev); if(hr != D3D_OK) return false; return true; } /** SOURCE FILE MAIN.H **/ LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); MSG msg; CD3d _d3d; // other code removed for forum/ prevent too much source bool Start(HINSTANCE *pInstance, int *pCmdShow, int pScreenWidth, int pScreenHeight, bool pWindowed, int pFsaa, char *pSceneFile); /** SOURCE FILE MAIN.CPP **/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int width = 1600; int height = 900; int fsaa = NO_MSAA; bool windowed = true; char *scene1 = "data/scn4/test.scn"; if(!Start(&hInstance, &nCmdShow, width, height, windowed, fsaa, scene1)) return (INT)msg.wParam; _timer.Init(50.0f); // main loop 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 { _timer.CalcFps(); SetWindowTextA(_d3d.mHwnd, _timer.mStrFramerate); // other code removed for forum/ prevent too much source // render 3d scene if(!_d3d.RenderFrame(&_d3dscene, &_d3dcam)) { MessageBox(_d3d.mHwnd, err_render, err_windowtext, MB_ICONERROR); return (INT)msg.wParam; } } } return (INT)msg.wParam; } bool Start(HINSTANCE *pInstance, int *pCmdShow, int pScreenWidth, int pScreenHeight, bool pWindowed, int pFsaa, char *pSceneFile) { if(!_d3d.InitWindowClass(WindowProc, pCmdShow, pInstance, pScreenWidth, pScreenHeight, pWindowed)) { MessageBox(NULL, err_wc, err_windowtext, MB_ICONERROR); return false; } if(!_d3d.InitD3dDevice(pFsaa)) { MessageBox(NULL, err_initd3d, err_windowtext, MB_ICONERROR); return false; } if(!_dinput.Init(*pInstance, _d3d.mHwnd, pScreenWidth, pScreenHeight)) { MessageBox(NULL, err_initdi, err_windowtext, MB_ICONERROR); return false; } return true; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { // case WM_ACTIVATE: // break; case WM_DESTROY: PostQuitMessage(WM_QUIT); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } } [/source]

Edited by cozzie
0

Share this post


Link to post
Share on other sites
Addition;
going back in time/ documentation reminds me that handles like HWND and hInstance can be passed without threating them as a spointer with * / &, because they are already pointers and never changed during runtime. Is this correct? (and if so, is this the same for intcmdshow)
0

Share this post


Link to post
Share on other sites
I just pass: HWND, HINSTANCE and other pointer Win32 defines as they are defined.
Example:
[code]
void Foo( HWND hWnd, HINSTANCE hInst, int nCMDShow )
{
// do something here
}
[/code]

Although i do try to use the "const" keyword wherever applicable.
so i would make "nCMDShow" "const int nCMDShow"

Hope that helps.
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