Wrapping DirectPlay in an Object
Hey,
I''m part of a group writing a video game for a final project in a graphics class I''m taking. We want to network our game and we don''t want to spend time writing a network library. We want to use DirectPlay. Right now I''m trying to take the DirectPlay code out of the TERRIBLE DX9SDK Client/Server demo chat program. I want to make two classes, DPServer and DPClient that can send messages to each other. The problem I''m running into is that some of the prototypes for the DPlay callback functions are hardcoded (like PFNDPNMESSAGEHANDLER) and thus can''t be given a function that is in an object.
The problem is that the type of:
HRESULT WINAPI DPServer::LoginDirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer )
isn''t the expected type:
HRESULT WINAPI LoginDirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer )
How can I make this work? Why is DPlay code in C++ so ugly?! We need DPlay because we don''t have time to build a network library with support for things like gauranteed UPD packet delivery.
Has anyone separated out the bare-bones DPlay code from the tutorials for their own projects? It really bothers me that in the demos all the DPlay code has windows GUI code mixed in with it.
----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------
Coding:
http://www.stanford.edu/~jjshed/coding
Miscellany:
http://www.stanford.edu/~jjshed
Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...
> Has anyone separated out the bare-bones DPlay code
> from the tutorials for their own projects?
http://pages.infinit.net/cbenoi1/r_1_1_28.zip
DPlay/Peer is encapsulated as a self-contained object. To use it you create a class that derives from the ''Notify'' virtual base class interface and you control it via the ''Control'' virtual base class interface.
-cb
> from the tutorials for their own projects?
http://pages.infinit.net/cbenoi1/r_1_1_28.zip
DPlay/Peer is encapsulated as a self-contained object. To use it you create a class that derives from the ''Notify'' virtual base class interface and you control it via the ''Control'' virtual base class interface.
-cb
The message handler should be a static function. Pass the this pointer in as your user context value to Initialize() and cast to the correct type in the static handler. Here's the basic idea:
gamesrv.h
gamesrv.cpp
[edited by - jonstelly on November 12, 2003 5:01:26 PM]
gamesrv.h
class CGameSrv{private: IDirectPlay8Server *m_piSrv; static HRESULT WINAPI MSG_HANDLER(LPVOID pvSrv, DWORD dwMsgType, LPVOID pvMsg); virtual HRESULT OnAddPlayerToGroup(PDPNMSG_ADD_PLAYER_TO_GROUP pdpMsg) {return DPN_OK;}};
gamesrv.cpp
HRESULT WINAPI CGameSrv::MSG_HANDLER(LPVOID pvSrv, DWORD dwMsgType, PVOID pvMsg){ CGameSrv *pSrv = static_cast<CGameSrv*>(pvSrv); switch(dwMsgType) { case DPN_MSGID_ADD_PLAYER_TO_GROUP: { CLog::Log(LOG_DBG, "CGameSrv::OnAddPlayerToGroup();"); return pSrv->OnAddPlayerToGroup(static_cast<DPNMSG_ADD_PLAYER_TO_GROUP*>(pvMsg)); }}bool CGameSrv::HostTcpIp(...){ //Some initialization hr = m_piSrv->Initialize(this, MSG_HANDLER, 0);}
[edited by - jonstelly on November 12, 2003 5:01:26 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement