PDA

View Full Version : Latest Delphi for .NET managed DirectX 9 Demos.



savage
25-01-2004, 07:30 PM
Ported C# DirectX 9 Managed Examples to Delphi for .NET can be
downloaded from....
http://codecentral.borland.com/codecentral/ccWeb.exe/listing?id=21147

Now includes the Text3D demo from the SDK and 2 new Demos not from the
SDK. Which are an X-File Viewer that show's animations if they exist, A
D3DSprite Animation Demo. Both include classes that you should be able
to use in your own demos/games. These are not perfect, but should
hopefully get you started.

The PointSprites demos still causes an AV at funtime when
VertexBuffer.Create is called. I believe this to be a compiler issue.
Any help in tracking down this bug would be appreciated.

There are now 33 Examples, which are...
AudioVideo : 2
Texture
Player

Direct3D : 16
AnimatedSprites
Billboard
DolphinVS
Fractal
Lighting
Meshes : 2
ProgressiveMesh
XFileViewer
PointSprites
StencilBuffer : 1
ShadowVolume
Text3D
Tutorials : 6

DirectDraw : 1

DirectInput : 4
Joystick
Keyboard
Mouse
Scrawl

DirectPlay : 7
Tutorials
Tut01_GetServiceProviders
Tut02_Host
Tut03_FindHosts
Tut04_Connect
Tut05_Send
Tut06_HostMigration
Tut07_LobbyLaunch

DirectSound : 3
EnumSoundDevices
Play3DSound
SoundFX


If you have any other Delphi.NET managed DirectX 9 demo that you would
like included in this archive, just let me know.


Dominique
http://www.DelphiGamer.com := go on, write a game instead;

tux
26-11-2004, 03:09 PM
are there any win32 delphi examples? i dont even have directplay in my directx9 sdk :?


mainly im looking at how to create a connection and send some data, is it right to use IDirectPlay8Peer ? i cant find out how to create the instance, i found i should use CoCreateInstance but i cant find the unit the procedure is in :(

savage
26-11-2004, 08:25 PM
Pure Win32 DirectX 9 examples that have been ported to Delphi can always be found @ http://clootie.narod.ru/ and downloaded from http://sourceforge.net/projects/delphi-dx9sdk/.

Unfortunately, I think most of them are Direct3D ports and not DirectPlay, but check just in case.

If I have time over christmas I may port some, I remember doing some DirectPlay demos back in the days when I thought DirectXPress would be a good idea, but I can't seem to find them on my HD, so a new port is probably best.

tux
26-11-2004, 08:40 PM
ive looked on clootie's site and its d3d/ddraw and a few dsound :(

much aprieciated if you manage to find them but theres no rush :)

tux
28-11-2004, 05:30 PM
ive got the peer working but it wont enum the service providers.

i found this on msdn http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/play/tut/tutorial1_enumeratesp.asp

and came up with this

Peer: IDirectPlay8Peer;


function DirectPlayMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;

implementation

{$R *.dfm}

function DirectPlayMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT;
Begin
end;

procedure TForm1.FormCreate(Sender: TObject);
var
pdnSPInfo: PDPN_SERVICE_PROVIDER_INFO;
pdnSPInfoEnum: PDPN_SERVICE_PROVIDER_INFO;
dwItems: DWord;
dwSize: DWord;
i: DWord;

strBuf: PAnsiChar;

begin
pdnSPInfo := nil;
pdnSPInfoEnum := nil;
dwItems := 0;
dwSize := 0;
i := 0;
strBuf := nil;


CoCreateInstance(CLSID_DirectPlay8Peer, nil, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Peer, peer);
Peer.Initialize(nil, @DirectPlayMessageHandler, 0);

//Determine the required buffer size
Peer.EnumServiceProviders(nil, nil, nil, dwSize, dwItems, 0);

//pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize]; ????????

//Fill the buffer with service provider information
Peer.EnumServiceProviders(nil, nil, pdnSPInfo, dwSize, dwItems, 0);

// Print the provider descriptions
pdnSPInfoEnum := pdnSPInfo;

for i:=0 to dwItems {-1} do
Begin
try
DXUtil_ConvertAnsiStringToGenericCch(strBuf, @pdnSPInfoEnum.pwszName, 256);
ListBox1.Items.Add(strBuf);
Inc(pdnSPInfoEnum);
except
Break;
end;
end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Peer.Close(0);
Peer._Release;
end;

but it doesnt work :( also causes access violations on closing the app

savage
29-11-2004, 10:09 PM
Hi Tux,
Ok you twisted my arm :)


the following works for me without any AVs...

procedure TForm1.FormCreate( Sender : TObject );
var
pdnSPInfo : PDPN_SERVICE_PROVIDER_INFO;
pdnSPInfoEnum : PDPN_SERVICE_PROVIDER_INFO;
dwItems : DWord;
dwSize : DWord;
i : DWord;
strBuf : WideString;
hr : Cardinal;
begin
dwItems := 0;
dwSize := 0;

hr := CoCreateInstance( CLSID_DirectPlay8Peer, nil,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
peer );
if hr = S_OK then
begin
hr := Peer.Initialize( nil, @DirectPlayMessageHandler, 0 );

if hr = S_OK then
begin
//Determine the required buffer size
Peer.EnumServiceProviders( nil, nil, nil, dwSize, dwItems, 0 );

GetMem( pdnSPInfo, dwSize );
try
//Fill the buffer with service provider information
Peer.EnumServiceProviders( nil, nil, pdnSPInfo, dwSize, dwItems, 0 );

// Print the provider descriptions
pdnSPInfoEnum := pdnSPInfo;

for i := 0 to dwItems - 1 do
begin
strBuf := WideString( pdnSPInfoEnum.pwszName );

ListBox1.Items.Add( strBuf );
Inc( pdnSPInfoEnum );
end;
finally
FreeMem( pdnSPInfo );
end;
end;
end;
if hr <> S_OK then
ShowMessage( DXErrorString( hr ) );
end;

procedure TForm1.FormDestroy( Sender : TObject );
begin
Peer.Close( 0 );
Peer := nil;
end;


Delphi shields you from a lot of COM's nastiness so setting Peer to nil should be all that is necessary ( in this case ) for it to decrement the reference count and free the appropriate COM interface memory.

Also I would suggest checking the return values from most DirectX calls just to make sure your system is set up correctly, or that there is something else causing the error.

tux
29-11-2004, 11:17 PM
*bowes down to savage*

works great thanks a lot :D

savage
30-11-2004, 12:34 AM
Well if you port/create any DirectPlay demos in Pascal, let me or Clootie know, so I they can be added to the other Win32 demos as part of the http://sourceforge.net/projects/delphi-dx9sdk/ project.

tux
30-11-2004, 08:27 AM
do you know where to get the full c demos? there not included in the dx9 summer sdk

savage
30-11-2004, 11:47 PM
You will have to check with clootie.

Clootie
01-12-2004, 07:12 PM
do you know where to get the full c demos? there not included in the dx9 summer sdk
Well, if you didn't knew DirectPlay is "freezed" by Microsoft and will not be enhanced.
New network API initiatives will be in XNA (X-box forked API)
If I've not mistaken last DirectX SDK including DirectPlay samples is "Summer 2003" one.

tux
01-12-2004, 07:19 PM
i didnt know it was freezed, ill download the summer 2003 thanks :)

tux
02-12-2004, 03:07 PM
i downloaded the 2003 sdk and i got tutorial 2 - hosts working in delphi and moved on to the next tutorial, finding hosts.

thats nearly done except im not too confident with the directplay message callback. ive uploaded what i have so far to here (http://www.vadertrophy.com/files/dplay.zip)

what i want to finish with is something that will find all hosts on a lan, join the host and send a custom packet containing the user data, then 5 times a second send another custom packet containing position data etc

am i going the right way to get that? :)

savage
03-12-2004, 01:41 PM
Just had a quick play with the code and one problem arises. Nothing is displayed in the listbox.

This is caused because you are not calling CoInitialize( nil );. so your constructor and destructor need to look a little like..


procedure TForm1.FormCreate( Sender : TObject );
begin
CoInitialize( nil );
// other init code here
end;

procedure TForm1.FormDestroy( Sender : TObject );
begin
// Other CleanUp code here
CoUninitialize;
end;


It seems that in DirectPlay8 the callback is not used much. At least I could not get it to fire, but then I don't have the SDK in the office :)

NOTE : CoInitialize( nil ); & CoUninitialize; MUST be paired.

tux
10-12-2004, 06:24 PM
i had another try at it today, i fixed one of the problems but i still have another :(

first ill explain what im trying to do.

i have a "master server", this is what the game connects to to get a list of hosts or add a host.

a game connects to this, sends a "request host list" packet and then disconnects after it receives the packet. the game can now connect to a host.

a host can connect to it, send a "add new host" packet, containing server details and game settings (selected track etc)



the master server seems to be functioning ok but when i try to connect to it a message is sent to the DirectPlayMessageHandler about 4 seconds into the connection and then streight after that message is sent an access violation happens.

ive uploaded the master server and the connection test to http://www.vadertrophy.com/files/racer/dplay.zip

please help (again) :)