jackline

Just curious... but has anyone used XNA/C# to develop MOG's or even MMOG's



Re: XNA Framework Multiuser games?

Fluxtah

I doubt there is one available now, its very new and no one would have had the chance to build an MMOG! You could be the first to try :)

I believe its possible.





Re: XNA Framework Multiuser games?

SysErr

Correct me if I'm wrong, but I thought that networking code wasn't in XNA at this point, so multiplayer games are not presently possible...

Maybe I'm thinking of something else, though, so don't quote me on it ( :

-SysErr




Re: XNA Framework Multiuser games?

Jim Perry

XNA contains no network support. For Windows games however you can use the network pieces included in the .NET Framework. You cannot do networked games on the 360 at this time.




Re: XNA Framework Multiuser games?

jackline

I realize that XNA currently doesn't have mog support, but has anyone used the .NET framework, specifically C#, to program mog's or other realtime multiuser environments -- links to examples, if so, please!





Re: XNA Framework Multiuser games?

Nick Darnell

@jackline

Yes, lots of people have created C# multiuser environments. Just look up client/server projects over at The Code Project, example (http://www.codeproject.com/cs/media/mdxsnake.asp). Easy, and good for a small number of players.

That said...

I've seen some MMOG C# projects, but honestly they don't get far off the ground. Mostly because it's hard to get the kind of support you need to make an efficient MMOG system. But also because an MMOG server should never be written in anything other than C/C++ simply because of the amount of data you need to move and info you need to process.

One should never say never...but you do lose 15-20% performance moving to C/C++ to C#, possibly more depending on your code, and memory consumption is going to be a lot comparatively speaking.

There are few situations where performance must be maxed out, but an MMOG server is most definitely one of them. At least for now, until server hardware becomes so wicked sick that it just doesn't matter. (but don't hold your breath)

But don't let me stop you, go for it. Because at the very least you will have learned a great deal about MMOG server design.

For reading, I highly recommend these two books.

http://www.amazon.com/dp/1584502436 tag=hardcodedgame-20&camp=14573&creative=327641&linkCode=as1&creativeASIN=1584502436&adid=09H2VPH0YSVXGARZ43NY&
http://www.amazon.com/dp/1584503904 tag=hardcodedgame-20&camp=14573&creative=327641&linkCode=as1&creativeASIN=1584503904&adid=15R6GYP3DEK9TCTXGXDH&




Re: XNA Framework Multiuser games?

Jim Perry

Nick Darnell wrote:
One should never say never...but you do lose 15-20% performance moving to C/C++ to C#, possibly more depending on your code, and memory consumption is going to be a lot comparatively speaking.

If you're seeing that kind of performance hit, your code is very poorly written. C# performance is maybe 1-2% slower in some situations. In some situations it's actually faster than C++.






Re: XNA Framework Multiuser games?

AndyL

Jim Perry wrote:

Nick Darnell wrote:
One should never say never...but you do lose 15-20% performance moving to C/C++ to C#, possibly more depending on your code, and memory consumption is going to be a lot comparatively speaking.

If you're seeing that kind of performance hit, your code is very poorly written. C# performance is maybe 1-2% slower in some situations. In some situations it's actually faster than C++.

Or it could be that your C++ code is poorly optimised! The trouble with these comparisions is they only tell you the relative performance of a given scenario, and assume that both languages are coded equally well.

I've benchmarked performance using Scimark2 in C++, Java and C#. This only tests scalar numeric performance, but it does tell me that in the given test cases Java now outperforms C++ on many of the tests, and equals it on all the others. C# however clocks in at a lowly 65-75% of the performance of C++. So in this case, C# doesn't perform very well (and the test cases are well written in all 3 languages).

Back on topic - the performance of a MMORPG server is all about architecture and nothing about raw language performance. If you have the skill set to design such a system, and the time, it could be implemented equally well in C++, C# or Java. But you have to understand how to build a system that scales well across 50 to 100 servers if you are going to emulate something like Everquest.





Re: XNA Framework Multiuser games?

Nick Darnell

Jim Perry wrote:

Nick Darnell wrote:
One should never say never...but you do lose 15-20% performance moving to C/C++ to C#, possibly more depending on your code, and memory consumption is going to be a lot comparatively speaking.

If you're seeing that kind of performance hit, your code is very poorly written. C# performance is maybe 1-2% slower in some situations. In some situations it's actually faster than C++.


Not really. C# performance is only faster in those situations where the compiler has optimized the code beforehand to exclude something. C# by its nature of running through a VM given the same assembly level operations can NOT run faster because there is a middle man (the .Net framework). Nothing you can do is going to change the fact that having that middle man adds overhead to anything you do.

In the situations where it's 1-2% slower is where C# has offloaded the real work to the GPU, or to unmanaged code.

There is also the issue of dealing with managed memory. You can't control when the VM really deletes anything. You can try. But these garbage collections take time.

Yes, it does depend on how much time you spend optimizing your code. Sure Java, C#, and C++ can run close in certain situations. And for real applications it takes more time to make C++ run as efficiently as possible. But given that time C++ will work out better.

Plus...since most game companies use middle-ware these days, they don't need to devote that time to a math engine, they just buy one from a company who has.

Yes, architecture makes a lot of difference in MMOG servers. But that's only half of it. Much of the engine depends on lots of math calculations, predictions, and reading/writing to the network stream. These things C++ is very fast at. C# is much better at things where much of work can be offloaded to another unmanaged system. Desktop applications, graphics wrappers like XNA, or manged direct X, seeing as how all the real work is done by the GPU.




Re: XNA Framework Multiuser games?

AndyL

Nick,

IThe 'middle man' you mention doesn't have to take something away from performance. In the case of Java, it allows highly optimistic compilation to take place, which can be dynamically recompiled to work in a less optimistic manner when the highly optimistic case would break the program. This simply isn't possible in C++.

For instance, a program might provide several integration methods for rigid body simulation - Euler, Runge-Kutta etc. Now ordinarily you would access these via a function pointer in C, or via polymorphic classes in C++. In either case, the code will never be inlined, as we don't know which the user will choose at runtime. The JVM is sneaky - it sees that only one of the classes is called during profiling, and inlines the code giving a huge speedup. Clearly this would break the program if the user changed to the other integrator at some point later on, so the runtime detects this and recompiles the code if it happens.

Now if you add up enough of these type of optimisations you can exceed the speed of the 'pre-compiled' C++ code. Of course you won't believe me,  so I can only suggest you go and try it for yourself.

PS - In case I come across as a managed code evangelist/nutter(!), or something like that, I should point out I started out writing assembly language programs, and have been writing C for 18 years and C++ for 12 years. I take a lot of convincing about performance claims made by plaform vendors...





Re: XNA Framework Multiuser games?

Nick Darnell

Andy,
You're right, the JVM is sneaky as is .Net with it's ability to emit entire assemblies at runtime (that's so wicked sick). But you're talking about an MMOG server. Lots and lots of data is being move around, lots of new objects and memory are being declared all the time. But not having control over the memory doesn't allow you the ability to insure the JVM doesn't suddenly decide to garbage collect 100mb every 5 minutes, and cause all the users in the zone to get a huge lag spike. Hopefully your memory consumption isn't nearly that large...but you see the point i hope garbage collection is good, but given a programmer that knows how to properly perform it in C++, you're not going to have to worry about the JVM or .Net deciding to clear memory when it thinks it is okay. when it may not be okay.

Take a look at 2 engines. Ogre3D and Axiom. Ogre3d is a C++ game engine. Axiom is port of that same engine. Both have been in development for over 2 years (if memory serves). But Axiom just isn't as fast as Ogre3D, and it eats up much more memory.

Now, Axiom isn't a direct port. It started that way, but they do their best to follow C# standards, properties vs. getter/setter methods. And all the optimizations of managed direct x. Unless they switched to that Opengl Tao engine. I think they support both...but anyway.

Maybe bad programming. But I've got at least a little faith this is a typical project, with competent developers.

Now you can talk all day long about compile time optimizations, but what about the added memory consumption, and the overhead of moving between managed and unmanged code Which is going to occur in almost anything you do that isn't something that purely happens in the JVM/CLR. And interacting with network streams most definitely falls in that category.

Now, my tiny 6 years of C/C++ doesn't come close to your years of experience, but I've been using C# since it came out, and Java since 1.4 and I've yet to see a .Net or Java program (that wasn't some stupid tech demo specially designed to outperform the unmanaged equivalent) that was a port of an unmanaged real world application that outperformed it across the board.

I mean, if what you say is true, and as we all are aware C# and Java take light years less time to develop an application compared to C/C++. Why isn't the Unreal engine written in Java Or any other game engine that is worth a crap.  You know, the real block buster engines.  Or how about the Havok physics engine   You had better believe that thing is written in C/C++, and its calculations are amazingly fast.

Take a look at Neverwinter Nights 2. They have a toolkit program that you use to build levels/stories with. That toolkit is written in .Net. Compared to their old toolkit which was written in C++. The new one runs horribly, and that's just one example off the top of my head of a real world application.

Edit: Managed vs. Unmanaged (Not even outperformed, but even came close to the same performance.)  I mean we can play Theory-Development all day long, but until I see some real world applications that match or come within that (1..2% slower claim) in terms of performance with an unmanaged version.  I can't help but maintain my position.




Re: XNA Framework Multiuser games?

Ben Vanik

AndyL wrote:

Back on topic - the performance of a MMORPG server is all about architecture and nothing about raw language performance. If you have the skill set to design such a system, and the time, it could be implemented equally well in C++, C# or Java. But you have to understand how to build a system that scales well across 50 to 100 servers if you are going to emulate something like Everquest.

Agreed completely - just look at Second Life - they have their own interpreted language that is used for the server-side scripting of every object in the game world!

I'm interested in that kind of stuff, so I found this video particularly fun and recommend it to anyone else who may be looking at this area:

http://download.microsoft.com/download/9/4/1/94138e2a-d9dc-435a-9240-bcd985bf5bd7/Jim-Cory-SecondLife.wmv

(note that the first half is all about Second Life, and the second half is all the technical details) - if the link doesn't work, find it on http://www.langnetsymposium.com/speakers.asp





Re: XNA Framework Multiuser games?

AndyL

Nick Darnell wrote:

Edit: Managed vs. Unmanaged (Not even outperformed, but even came close to the same performance.) I mean we can play Theory-Development all day long, but until I see some real world applications that match or come within that (1..2% slower claim) in terms of performance with an unmanaged version. I can't help but maintain my position.

Nick,

Good to see you have a healthy degree of scepticism as well! I can't show you the stuff I have, but it's physics engine code and runs just as fast in Java - this isn't the case in .NET by the way. I also suspect you overestimate the degree of optimisation of games and middleware code - those companes want you to believe they have perfect and amazingly fast code.

Like I said, you just have to see for yourself.





Re: XNA Framework Multiuser games?

Fluxtah

I am really not sure about using properties in a game, sure they are great for business apps where encapsulation could be important but for a game engine... im really unsure.

Infact I did a little test to see if setting a public field directly is faster than setting a private field through a public property. For 1000000000 iterations of getting and setting a property VS the same iterations for getting and setting a value of a public field.

it took approx 12ns for each iteration of the property and approx 3ns for each iteration of the field.

of course my test might be innacurate with only me judging it and the code I used may not be a legitimate test but they are the results I got.

So considering Axiom uses properties everywhere, this might be a problem when performance is a concern.

Here is the test code, someone tell me if I am going about it the wrong way :)

using System;
using System.Collections.Generic;
using System.Text;

namespace PropertyVsFields
{
  class Program
  {
    static void Main(string[] args)
    {
      PropertyVsField obj = new PropertyVsField();

      int loopCount = 1000000000;
      long startTime, endTime;
      double nanoseconds;

      Console.WriteLine("Public Property");
      startTime = DateTime.Now.Ticks * 100;
      for (int x = 0; x < loopCount; x++)
      {
        // put the code to be tested here


        // set

        obj.PublicProperty = x;

        // get 

        x = obj.PublicProperty;
      }
      endTime = DateTime.Now.Ticks * 100;
      nanoseconds = ((double)(endTime - startTime)) / ((double)loopCount);
      Console.WriteLine(nanoseconds.ToString("F") + " ns per operation");

      Console.WriteLine("Public Field");

      startTime = DateTime.Now.Ticks * 100;
      for (int x = 0; x < loopCount; x++)
      {
        // put the code to be tested here


        // set

        obj.PublicField = x;

        // get

        x = obj.PublicField;
      }
      endTime = DateTime.Now.Ticks * 100;
      nanoseconds = ((double)(endTime - startTime)) / ((double)loopCount);
      Console.WriteLine(nanoseconds.ToString("F") + " ns per operation");
    }
  }

  public class PropertyVsField
  {
    private int privateField;

    public int PublicProperty
    {
      get { return privateField; }
      set { privateField = value; }
    }

    public int PublicField;
  }
}




Re: XNA Framework Multiuser games?

Dodger_

AndyL wrote:
Good to see you have a healthy degree of scepticism as well! I can't show you the stuff I have, but it's physics engine code and runs just as fast in Java - this isn't the case in .NET by the way. I also suspect you overestimate the degree of optimisation of games and middleware code - those companes want you to believe they have perfect and amazingly fast code.
Even though you can't show us source, if you've done accurate profiling, you could easily tell us exactly where your engine is slower and probably why if you disassemble those sections and look at the IL. Give us real data and not handwaving and excuses.