Hi,

I've just created my first 2d game (c# XNA) - a car racing game. My problem is how to perform a multiplayer mode. I wanted to use MySQL server. I decided to try with a local database (SQLite) first. As i suspected it didn't work. The thing is that my game displays about 20 frames per second. It gives at least 40 queries to database each second. (in case of collision it may be even more). The game takes the data from database before calling the update function, than executes player's actions and finally updates database. The problem probably is the time a database needs to process queries.

The data which is sent is just a few variables ( x and y coordinates, rotation and 6 other integers related to damage)

Simple streams would probably be fast enough but they don't work without external IP.

Do you have any ideas how to fix the problem?

I don't think that SQL server (or any other database server) is suited for multiplayer purposes. Usually game devs for multiplayer mode writes it's own server and client. So I would recommend to you to write TCP/UDP server and client by using System.NET library. Check this out-
http://www.codeproject.com/KB/IP/socketsincsharp.aspx

As about SQL problems i could suggest only 2 things, because main perfomance problem is disk IO:

1. Read/write from/to SQL server as rarely as possible. (Maybe you can cache data localy for some miliseconds or so and after reaching cache limit - send data for update to SQL server. Reads you can perfom more frequently, but also should be lowered as possible)
2. Put all database files on RAM disk (transaction journal and temp files including) or use in-memory database (also may try other than SQLite.).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.