Mykre Posted September 13, 2004 Posted September 13, 2004 I have started to watch the threads here as there seems to be movement on these DirectX groups. I am starting to work on a RPG (I know every one seems to be) that would convert the Old MUD Code and text based game to a graphic based system. To do this I need to start working with the DirectX classes. I have a good start and understanding of the DirectPlay Networking system and how to use it, Now I need to start on the main interface and graphics systems. At the moment I am looking for sample classes in 2d and tile based systemsso that I can rip apart so that I may understand the graphics systems involved. Does any one have any examples that they would be willing to share? Thanks in advance for the Help. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Loffen Posted September 13, 2004 Posted September 13, 2004 (edited) I would be willing to share my two classes (Sprite class and TileMap class) if youd be willing to share some DirectPlay knowledge... EDIT: I just figured that whith the summerupdate 2004 there is a whole bunch of documentation... Just press Ctrl + Alt + F1, then in the little menu to the left(?), expand the DirectX Summer... -> DirectX Summer Managed -> Introduction -> Direct3d Graphics ... Not looked through, but there should be enough to start with... :p Edited September 13, 2004 by Loffen Quote Erutangis a si tahw
Mykre Posted September 13, 2004 Author Posted September 13, 2004 Not a problem, anything to help the community grow. I have mainly been working with the client server model, but have done some playing with the peer to peer model. As there is not much doco in the mDx documentation, I was thinking of writing my notes up so others can learn. I have found most of what I have learn't from Toms book, and some apress books, but most I have gotten is from disecting and converting c++ code. With the graphics side of things, First I started getting the server communications together, now that I have that running (Connecting and talking to a test client, basic chat functions) now I need to get the clients working as a proper client app for the game. The first step is to get characters walking on the device, with a chat window. Then I will work on combat code and updating stats on the server. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Loffen Posted September 14, 2004 Posted September 14, 2004 (edited) Ok... I am NO DirectX guru, but i can learn you how i did create a tilemap engine like this (see attached image) and render transparent sprites (no, not the whole sprite, just the bg :p)... and then how to move it i guess... (still trying to figure out an efficent way.) Well first: Do you know how to init a device?? You said it would be enough with some code to rip apart. I will document my engine and swap it with a documented DP (you guessed it, DirectPlay) class... --Loffen This picture shows WHY i am NO artist and WHY i AM a programmer :P (yes thats my map (currently with 2 different tiles, but you can add up to 999999999999 tiles also: infinite). + i made this map of pure boredom. No the windows buttons in the upper-right corner are secret :p) Edited September 14, 2004 by Loffen Quote Erutangis a si tahw
Mykre Posted September 14, 2004 Author Posted September 14, 2004 I will put together a documented DP Class for you. At the moment it is enbeded inside a windows form application, but I am working on seperating it to a seperate class that can be used as an engine... Will get backto you with it. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Loffen Posted September 15, 2004 Posted September 15, 2004 (edited) Ok.. here it is.. Had very short time, so if i missed a part just tell me.. Rendering the transparent sprite is not included though...EngineDocumented.zip Edited September 15, 2004 by PlausiblyDamp Quote Erutangis a si tahw
ThePentiumGuy Posted September 15, 2004 Posted September 15, 2004 You could check out the DirectX tutorials in the tutors section (the same ones from my site, www.vbprogramming.8k.com) The code is very similar to loffen's code :). (hmmmmmmm guess where HE learned DirectX from hehe). If you need any more help - feel free to post here :). By the way dude: Just out of curiosity, where did you learn DPlay from? I've been wanting to buy a networking book for a while -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Aragorn7 Posted September 17, 2004 Posted September 17, 2004 By the way dude: Just out of curiosity, where did you learn DPlay from? I've been wanting to buy a networking book for a while I guess I would rather do Winsock than DirectPlay. Although DirectPlay is nice, it has one flaw: You have to open so many ports to get it to work! Although Winsock might be harder to learn, it has its advantages in optimizeability (because you code it all yourself :D) and less overhead. http://www.vbip.com/winsock-api/default.asp Quote
Mykre Posted September 18, 2004 Author Posted September 18, 2004 I guess I would rather do Winsock than DirectPlay. Although DirectPlay is nice, it has one flaw: You have to open so many ports to get it to work! Although Winsock might be harder to learn, it has its advantages in optimizeability (because you code it all yourself :D) and less overhead. http://www.vbip.com/winsock-api/default.asp I have been DPlay for a good six months now, and have only had to open 1 port on the server. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Mykre Posted September 18, 2004 Author Posted September 18, 2004 You could check out the DirectX tutorials in the tutors section (the same ones from my site' date=' www.vbprogramming.8k.com) The code is very similar to loffen's code :). (hmmmmmmm guess where HE learned DirectX from hehe). If you need any more help - feel free to post here :). By the way dude: Just out of curiosity, where did you learn DPlay from? I've been wanting to buy a networking book for a while -The Pentium Guy I picked up Toms book on Managed Direct X to learn the main classes, But as there is not much on Managed DX I have started to convert a lot of C++ code over to managed DirectX. The problem is that I like to do most of my stuff in C# and I have found that most examples in the community are based on VB.net. So I have learnt to code in both and then convert to C# when I have the idea grounded. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Mykre Posted September 18, 2004 Author Posted September 18, 2004 I have almost finished the example for you and documenting it, I am trying to add as many features as I can so that you can get an overview of the DPlay system. Working on a chat system. In the first version I will not have any charater conrtrol on the server, it will be so that all users can log on and use the system through the client. Next version will have log on and security systems, as well as an information store for the information that is need to run the server. Should have it completed this weekend, Been a busy time at work... :( Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Aragorn7 Posted September 18, 2004 Posted September 18, 2004 I have been DPlay for a good six months now' date=' and have only had to open 1 port on the server.[/quote'] I just like having more direct control over the flow of the program. DirectPlay uses TCP right? I would like to use UDP because it is faster. :D Quote
Mykre Posted September 19, 2004 Author Posted September 19, 2004 I just like having more direct control over the flow of the program. DirectPlay uses TCP right? I would like to use UDP because it is faster. :D From what I understand the DirectPlay System uses both.. (IWill have to check.. Outcomes the packet Sniffer, and will get back to you), The problem I have with UDP, is that the packets are not garentied to get there and the order of arivale can be all over the place. Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Aragorn7 Posted September 19, 2004 Posted September 19, 2004 From what I understand the DirectPlay System uses both.. (IWill have to check.. Outcomes the packet Sniffer' date=' and will get back to you), The problem I have with UDP, is that the packets are not garentied to get there and the order of arivale can be all over the place.[/quote'] Yes, that is one problem. But it can be easily fixed with timestamps/framestamps placed on every packet. If the packet is old, it will not display it, if it is new, it will. The speed increase is absolutely amazing though, and most likely worth the toil and trouble you have to go through to get it working. TCP is a simple and effective way of transmitting data. For making sure that your client and server can talk to each other it is very good. However, it carries with it a lot of overhead and extra network lag so once you feel you are ready you should make the jump to UDP. The big problems you will face with UDP include: -You won't have an individual socket for each client. In fact FD_ACCEPT will never be called. There won't be any clear notice that the client now sending you data wants to join the game unless you make the client say as much. -Given that clients don't need to open a unique socket in order to transmit data there is the very real possibility that a client who is not logged into the game will start sending all kinds of garbage to your server in some kind of attack. It becomes much more difficult to stop them at this point. -Likewise, you won't have a clear disconnect/leave game message unless you write one yourself. -Some data may not reach the other machine, so you may have to send important stuff many times. -Some data may arrive in the wrong order. Imagine that you got snapshot 5 before snapshot 4. Snapshot 4 would have to be suppressed (rejected). http://www.flipcode.com/network/issue07.shtml Quote
iMuYa Posted September 22, 2004 Posted September 22, 2004 Well guys, I think I'll join your community. I have a good sample of tile based game and a good knowledge in Computer Networks. I've been working with MDX for 3 months and has good knowledge in D3D 2D Graphics, DSOUND, and DP (client server). Currently, i'm developing a games which has all the features. I learned all my DirectX knowledge from 2 books. 1st Tom Miller's MDX 9 Graphics and Game Programming (C#). 2nd Games Programming with VB.NET. The 2nd book is greater cause it has many sample games and teach us the game concept such as collision detection, AI, etc. What i'm interested now is how to make the MDX application to consume less memory and render at the best performance. Below is the game engine which I extracted from the 2nd book for Device Initialisation. Well, I wonder how many sprites that the attached tilebased game created? Thank you. /******************************************************* Imports Microsoft.DirectX.Direct3D Imports Microsoft.DirectX Public Class clsGameEngine Protected Shared objDirect3DDevice As Device = Nothing ' Simple textured vertices constant and structure Public Const FVF_CUSTOMVERTEX As VertexFormats = VertexFormats.Position Or VertexFormats.Texture1 ' defines the default background color as black Public BackgroundColor As Color = Color.FromArgb(255, 0, 0, 0) ' Images path, to be used by the child classes Protected Const IMAGE_PATH As String = "Images" Public Structure CUSTOMVERTEX Public X As Single Public Y As Single Public Z As Single Public tu As Single Public tv As Single End Structure Public Width As Integer = 25 Public Height As Integer = 25 'Controls the game end Public Shared GameOver As Boolean Public Shared Paused As Boolean Sub Run() Do While Not GameOver If (objDirect3DDevice Is Nothing) Then GameOver = True Exit Sub End If objDirect3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, BackgroundColor, 1.0F, 0) objDirect3DDevice.BeginScene() ' Calls the Render sub - which must be implemented on the derived classes Render() objDirect3DDevice.EndScene() Try objDirect3DDevice.Present() Catch ' Some error ocurred, possibly in the Render procedure End Try Application.DoEvents() Loop End Sub Public Overridable Sub Render() ' This sub is specific for each game, and must be provided by the game engine derived class End Sub Public Function Initialize(ByVal owner As Windows.Forms.Control) As Boolean Dim WinHandle As IntPtr = owner.Handle Dim DispMode As DisplayMode Dim objDirect3Dpp As PresentParameters Initialize = True Try DispMode = Manager.Adapters(Manager.Adapters.Default.Adapter).CurrentDisplayMode DispMode.Width = 800 DispMode.Height = 600 ' Define the presentation parameters objDirect3Dpp = New PresentParameters objDirect3Dpp.BackBufferFormat = DispMode.Format objDirect3Dpp.BackBufferWidth = DispMode.Width objDirect3Dpp.BackBufferHeight = DispMode.Height objDirect3Dpp.SwapEffect = SwapEffect.Discard ' Enable the stencil depth, since we are working with ' non-transformed vertices objDirect3Dpp.EnableAutoDepthStencil = True objDirect3Dpp.AutoDepthStencilFormat = DepthFormat.D16 objDirect3Dpp.Windowed = True ' Create the device objDirect3DDevice = New Device(Manager.Adapters.Default.Adapter, _ DeviceType.Hardware, owner, CreateFlags.SoftwareVertexProcessing, _ objDirect3Dpp) ' Turn on ZBuffer objDirect3DDevice.RenderState.ZBufferEnable = True ' Tells the device which is the format of our custom vertices objDirect3DDevice.VertexFormat = FVF_CUSTOMVERTEX ' Turn off culling => front and back of the triangles are visible objDirect3DDevice.RenderState.CullMode = Cull.None ' Turn off lighting objDirect3DDevice.RenderState.Lighting = False ' Turn on alpha blending, for transparent colors in sprites objDirect3DDevice.RenderState.SourceBlend = Blend.SourceAlpha objDirect3DDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha ' The sprite objects must turn on alpha blending only if needed, using the following line: 'objDirect3DDevice.RenderState.AlphaBlendEnable = True ' Set the Projection Matrix to use a orthogonal view objDirect3DDevice.Transform.Projection = Matrix.OrthoOffCenterLH(0, DispMode.Width, 0, DispMode.Height, -200, 200) Catch de As Exception MessageBox.Show("Could not initialize Direct3D. Error: " & de.Message, "3D Initialization.", MessageBoxButtons.OK, MessageBoxIcon.Error) Initialize = False End Try ' Dispose the used objects DispMode = Nothing objDirect3Dpp = Nothing End Function Protected Overrides Sub Finalize() On Error Resume Next ' We are leaving, ignore any errors If Not (objDirect3DDevice Is Nothing) Then objDirect3DDevice.Dispose() objDirect3DDevice = Nothing GC.Collect() MyBase.Finalize() End Sub End Class /******************************************************** This is a good start to learn anyway. Quote
Loffen Posted September 22, 2004 Posted September 22, 2004 I have till now loaded 40x20 = 800 tiles... EDIT: BTW.. that is no game yet... :p What i'm interested now is how to make the MDX application to consume less memory and render at the best performance Just download a copy and look how i did it (didn't notice any noticable FPS/Performance drops..) Quote Erutangis a si tahw
ThePentiumGuy Posted September 22, 2004 Posted September 22, 2004 Loffen: You want performance? Here's a tip: [i'm assuming that you're using code similar to mine in the Tutor's Corner] Take out the render loop, so Public Sub RenderScene should just say: Clear Begin Scene ' Render Objects End Scene Present If GameOver = True Then Terminate() End If Application.DoEvents So there should be no loop. Now, in Overrides form1_onPaint (use the drop down menu and select Overrides instead of BaseClass Events and look for onPaint), type in: Game.Render() Me.Invalidate In form1_load, add this code: Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) Comment that line and see what happens :). The form will flicker like CRAZY. You should now see a major performance increase. Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Aragorn7 Posted September 23, 2004 Posted September 23, 2004 Yes, windows playing the "paint" game isn't fun. That trick is very nice if you have a windowed app. It won't optimize fullscreen however. :D Quote
ThePentiumGuy Posted September 23, 2004 Posted September 23, 2004 Lol are you sure? I'll run an FPS test tomorow and see if I get a performance increase or not... -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
iMuYa Posted September 23, 2004 Posted September 23, 2004 40x20, that means u use 800 sprite objects to come out the background. How's the memory consumption? Consumed lots of memory? ThePentiumGuy, can you tell the reason why using Paint - Invalidate is better than using WHILE LOOP? Any recommendation from you guys, how to compact the use of memory. .NET used up too much memory I think. Thanks. Quote
Aragorn7 Posted September 23, 2004 Posted September 23, 2004 40x20, that means u use 800 sprite objects to come out the background. How's the memory consumption? Consumed lots of memory? ThePentiumGuy, can you tell the reason why using Paint - Invalidate is better than using WHILE LOOP? Any recommendation from you guys, how to compact the use of memory. .NET used up too much memory I think. Thanks. The trick is to DELETE all of those objects once they are created and just "think" of the map as one object. My map object is a class that holds all of the data for the map and all of the map can be drawn from this class alone. So there is a little less consumption here if you aren't storing all of that data somewhere. But, either way works too. Quote
ThePentiumGuy Posted September 23, 2004 Posted September 23, 2004 ThePentiumGuy, can you tell the reason why using Paint - Invalidate is better than using WHILE LOOP? Any recommendation from you guys, how to compact the use of memory. .NET used up too much memory I think. Thanks. Using loops take up a LOT more resources, the Paint trick is another way of doign a loop (becuase Me.Invalidate calls the paint event again :D). I'm not too sure how to compact the memory :s, im developing on a good computer (3.0c, 1 gb ram)- its actually sort of bad to develop on a good computer as opposed to an average computer becuase you assume that your program is fast enough :-D. -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Aragorn7 Posted September 24, 2004 Posted September 24, 2004 Using loops take up a LOT more resources, the Paint trick is another way of doign a loop (becuase Me.Invalidate calls the paint event again :D). I'm not too sure how to compact the memory :s, im developing on a good computer (3.0c, 1 gb ram)- its actually sort of bad to develop on a good computer as opposed to an average computer becuase you assume that your program is fast enough :-D. -The Pentium Guy You are correct on both points. Testing on a REALLY nice computer is sort of worthless...that is why you should work on optimization later on in the project when you can test it on a different computer. BTW, I would like to point out that VB.NET has AWESOME memory management. It is like 2.33 times better than VB6. Don't believe me? http://216.5.163.53/DirectX4VB/Tutorials/GeneralVB/GM_NETvsVB6.asp Quote
iMuYa Posted September 24, 2004 Posted September 24, 2004 Here, I attached a Sprite class, quite similiar to the one used in this forum. Anyway, this is not my original job. I extracted from the Tutorial game The RiverPlanet V.I. It supports transparency. Thanks.clsSprite.zip Quote
ThePentiumGuy Posted September 24, 2004 Posted September 24, 2004 You got this from ".NET Game Programming with DirectX 9" eh? I love that book :). Hey btw, there are a couple problems with the sprite class from that book, and it has to do with creating the vertex buffer: First of all, the FVF_CUSTOMVERTEX in the class you attached is not defined :p. Second of all: Dim Vertices as CustomVertex() is not a good way to code... this is because you must specify the type of CustomVertex... for example Dim Vertices As CustomVertex.PositionTextured(). In either case, Dim Vertices as CustomVertex() would not work becuase in the book, it is defined in another class (GameClass I beleive) 3rd of all, in public sub Draw: If transparent then objDirect3DDevice.Alphablend = True End If would not work :), in the book they turn on the SourceBlend and the InvSourceBlend in the Initialize sub in the GameClass. 4th of all, CreateFlexVertex (arguments) as CUSTOMVERTEX would not work, becuase CUSTOMVERTEX is defined in GameClass in the book (or something like that).. The easiest thing to do is rather than use that function, just say Vertices(0) = new CustomVertex.<whatever>(arguments) The book is great(that's what my tutorials are mainly based off of), but its got a few quirks here and there :P) Just remember, don't define anything as "CustomVertex"... becuase CustomVertex is a DirectX class, -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.