Jump to content
  • Advertisement
Sign in to follow this  
MrMark

Resolving circular dependencies in C#

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys

I'm writing a multi-player server for web based flash games. Each game instance has 2-4 players, and each instance is completely independent of other instances. Different game types (ie chess and poker) can be run on the same server. Server uses a worker thread pool that uses application instances for locking; ie only one worker thread may access an instance at a time.

In one project I have the server code that handles networking, scheduling, all the common low level stuff a game instance needs. It provides an abstract Application class that provides the interface* to the low level stuff that I want each different game type to inherent. *declared abstract application, not interface application as I wanted to put in some utility functions in there.

This works fine if each game lives in the same project as the server, but when I tried to refactor a game out into its own separate project I run into circular dependencies, since:
Server needs to be able to construct instances of a particular game type.
Each game type needs to be able to inherent Application.

I've been doing some googling, and it seems the 'standard' solution involves creating a third project that has an interface that both projects use...but that seems kinda hacky to me...is that really the best way to do what I'm trying to do ? Like if this was C++ I'd just make each game instance a static lib and link it in. Inversion of Control also comes up alot, but it seems very overcomplicated for what I'm trying to do. I don't need to be able to swap out server implementations, I just want each different game to live in its own project.

Thanks for any help, Hope I gave enough detail.

Share this post


Link to post
Share on other sites
Advertisement

I've been doing some googling, and it seems the 'standard' solution involves creating a third project that has an interface that both projects use...but that seems kinda hacky to me...is that really the best way to do what I'm trying to do ?
[/quote]

If I understand you correctly, you have a server project that has some networking stuff that games use. Each game project references (and uses) that networking stuff. And then you want the server project to be your entrypoint? Have it create the game instance?

Personally, I would have a small glue project that ties the game to the networking and spins things up. But it also seems really weird to me that the networking library is doing anything but providing networking capability.

Share this post


Link to post
Share on other sites
Thanks for your reply

The server needs to spinup each game instance as required. When players first connect they are given a list of games to pick from, they select one and if there isn't a game already waiting for players the server creates a new instance of that game and adds that player to it. When a second player comes along that also wants to play that game he is added the existing game instance, and the game begins.

The game instances don't know or care they are on a server, all they need to do is respond to events such piece X to position Y, ensuring the rules of the game are followed. If each game instance was its own server, each instance would need its own port and have much more overhead.

Hope that makes more sense.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!