Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 11 Mar 2010
Offline Last Active Oct 12 2012 06:48 PM

Topics I've Started

Proper way for server to save world data while active?

30 September 2012 - 10:53 AM

I'm not too sure how to go about this. I'd like to have the server save the game world and client data every so often but how would I do this while server is running and clients are connected to the server? Currently everything is saved in binary which I hope to keep doing. The world file + clients is roughly 160mb currently.

I'd rather try to spin off a thread to slowly save everything instead of stopping everything for a few seconds for it to do its thing, however I'm not sure if that's the best way or how I can do this without adding locks around every code that changes client/world data. Any tips?

Issue with scissorrectangle

27 August 2012 - 06:43 PM

I'm stumped on how to fix this issue.

I draw the map using a scissor rect during spriteBatch and later I draw my paperdoll however the scissor rect for the map is cutting off the paperdoll model somehow. Here's an example of it:



I'm drawing part of the map via:

[source lang="csharp"]sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.None, scissorRS);scissorRect.X = mapElementRect.X;scissorRect.Y = mapElementRect.Y;scissorRect.Width = mapElementRect.Width;scissorRect.Height = mapElementRect.Height;// Make sure rect doesn't go out of bounds of screenif (scissorRect.X + scissorRect.Width > screenWidth - 1) scissorRect.Width = screenWidth - scissorRect.X;if (scissorRect.Y + scissorRect.Height > screenHeight - 1) scissorRect.Height = screenHeight - scissorRect.Y;sb.GraphicsDevice.ScissorRectangle = scissorRect;[/source]

The paperdoll is drawn after the map. I believe it has to do with depth as setting device.DepthStencilState to none draws the model fully but of course it's inside out at that point. However I set depth to none when drawing the map.

Any ideas?

EDIT : Ok I feel silly. After combing my code for the past two hours there was one line when drawing the map outline that was setting DepthStencilState to Default during spritebatch.Begin() that I kept missing. Case closed!

My lock()s don't appear to be working.

22 July 2012 - 01:02 PM

I was fairly sure I had my locks correct until I had my network thread update the direction of players during state changes. So whenever players turn they get distorted for a bit when changing directions. My setup is briefly as follows:

[source lang="csharp"]public class UnitContainer{public static readonly object OtherPlayersLocker = new object(); // i tried non-static as wellList<Player> otherPlayers;// ...}[/source]

I pass the unitContainer to all the classes that contain threads so they can access the player list and any time a thread accesses and/or modifies player data they call the lock (such as)

[source lang="csharp"]lock (UnitContainer.OtherPlayersLocker){unitContainer.otherPlayers[index].Direction = msg.messageList[i].direction;unitContainer.otherPlayers[index].Direction.Normalize();}[/source]

The problem goes away when I normalize the direction before setting it to the otherplayer. But regardless, the way I have it set up, it shouldn't matter if I do or not.

My guess is either the Draw call is drawing while the world variable is being updated, or the world variable is being updated after direction was set but before it was normalized. However if everything is in that lock (including draw call)..how are the two threads modifying/accessing the player data at the same time?

In-game map techniques?

12 July 2012 - 06:16 PM

I'm having difficulty searching for any sort of tutorial for drawing interactive in-game maps as any search with "map" usually comes up with terrain and game level stuff. As the game world is procedurally generated I can't pre-fab maps so they'll have to be created during world generation.

Currently I just have a boring biome map being generated but I'm hoping for something with more pizzazz.

http://www.imageshack.us/photo/my-images/254/biomemap.png/ (Tried to make an image link but didn't seem to work)

Eventually other markers such as towns and forts would need to be drawn on the map as well. The map will start out with a fog-of-war and will fill in as the player moves around in the world. Does anyone know of any popular techniques/shaders for drawing in-game maps?

Using both TCP and UDP?

02 July 2012 - 04:01 PM

To learn both protocols I had recently made two server/client models each using the UPD/TCP to practice interpolating movement and chat message packet handling. Now that I understand both protocols more I'm curious how best to go about my actual game server architecture. The server generates the world procedurally and will need to send large chunks of data: when a player first logs in, or when a player moves to a new cell and needs that cell's height for vertices, and static models, etc. (Cells will be saved on client's computer once downloaded)

While making the two test server/clients I came to really like UDP more however I can't just stuff 80k+ worth of data into a single packet and I need reliablity for the packets. So I figured instead of trying to implement a layer over UDP to make sure I get several packets' worth of data for a single cell, I could use TCP for those packets and just stream the data.

However, I prefer UDP for movement and other details that are time sensitive so my question is - Can't I just use two separate ports, one for TCP traffic and one for UDP traffic? Have the client send requests for cell data on TCP port, and clients/server communicate over UDP for position, action responses, etc? Is there some none-obvious hurdles I might come across?