by Cameron Albert
7. May 2009 18:09
I have spent the last three days writing LINQ qeueries over object collections and have to come to rely on LINQ pretty heavily for most query operations. I have played around some with LINQ to SQL and LINQ to Entities but I mostly use it to just query over some good old fashion collections like so:
var groups = proposal.Lines.Where(kvp => kvp.Key.Equals(key.Quarter))
.Select(kvp => kvp.Value.Where(l => l.AvailType.Spot == "N" && l.AvailType.Type == "RE"))
.FirstOrDefault()
.GroupBy(l => new { l.NetworkId, l.UnitLength, l.BrandId });
List<TimePeriod> weeks = proposal.GetWeeksFromOrderFlightDates(key.Quarter);
foreach (var group in groups)
{
BudgetRow row = AddBudgetRow(budgetDefinition,
new List<string>(new string[] { group.Key.NetworkId.ToString(), group.Key.UnitLength.ToString(), group.Key.BrandId.ToString() }),
budgetRows, BudgetDefinitionType.WeeklyNetworkAvailTypeImps);
foreach (var week in weeks)
{
var units = group.SelectMany(l => l.Units.Where(u => week.contains(u.AirDate)));
row.setRawValue(week, units.Sum(u => (decimal?)u.Demo1Imps));
row.setLockedValue(week, units.Where(u => u.IsLockedOutOfUnitAllocation).Sum(u => (decimal?)u.Demo1Imps));
}
}
c73edb18-7fca-429d-9e72-27f8c0e9c7f9|0|.0
Tags: c#, linq
by Cameron Albert
2. March 2008 22:35
For my PBBG Engine I started off programming it all for the web and AJAX. Recently I added support for sockets by porting over my socket server code I wrote for a Flash server and incorporating the code into the PBBG Engine. In a previous post about my PBBG Engine Architecture I outlined my plans for how the socket and web pieces would work together. I spent some time today refining my command pipeline and server protocol for the socket side of the engine and will probably utilize that on the web side as well.
I decided on the following format for the data packets that will go to and from the server and client. Since it is just bytes going back and forth and I wanted to keep the data streams as small as possible I decided to abandon the string based command protocol and use this instead:
The first 2 bytes of the packet will be used to store an Int16 (short) value that indicates the command to execute. I have an event being raised from the game engine that allows the implementing libraries to set the game commands. This was a Dictionary<string, ICommand> but I am going to change it to a Dictionary<short, ICommand>. That will save me some bytes back and forth without passing the command names. I can have the clientsend the proper short value for the command typed into the console or just have the links and events in the client supply the proper short value.
The next 4 bytes will be the integer length value of the message. This will allow me to know when this message ends and the next one begins.
All the bytes following up to the length value will be the actual message sent to the client or sent to the server.
The server is already validating commands, I will just need to modify to validate these bytes and watch for buffer over runs. I still need to work out validating that a logged in user is sending the information but I will work out something, maybe have the client send the encrypted authentication key to the server after a connection is opened but before commands can be processed.
by Cameron Albert
27. February 2008 22:07
I built the following extension method in .NET 35. to XML serialize objects; thought it might be useful for someone else. I use to serialize collections to pass XML data to my stored procedures that save player skills and items in my PBBG engine.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace WebTools
{
public static class XmlHelper
{
public static string ToXml(this object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (StringWriter sw = new StringWriter())
{
serializer.Serialize(sw, obj);
return sw.ToString();
}
}
}
}
I wrote another extension method specific to retrieving the modified values of a collection. You have to control when the IsDirty flag is set yourself but my properties take care of that.
public interface IModifiable
{
bool IsDirty { get; }
void MarkClean();
void MarkDirty();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebTools
{
public static class ModifierHelpercs
{
public static List<TSource> Modified<TSource>(this IEnumerable<TSource> source) where TSource : IModifiable
{
return (from s in source where s.IsDirty select s).ToList();
}
}
}
by Cameron Albert
22. December 2007 22:35
I've been taking a little break from Perenthia and working on my first Silverlight game. I thought I would post a screen shot of what I have so far. My initial plans were quite grand but after playing around with it all I may end up scaling it down to just a game of battling ships. Anyway, I was positioning the cannons on the ships in this screenshot.
The game is being written in Silverlight 1.1/2.0 and will hopefully be complete by the time the 2.0 beta is released.
by Cameron Albert
30. October 2007 00:05
I am structuring my PBBG game engine to be as flexible as possible in order to build various types of games. In order to do that I need to abstract out the components of the engine. Since persistent browser based games are, well, browser based, I decided to follow the normal n-tier model. I am creating a data tier, my actuall database, an application tier which is the engine and will handle client connections, authentication, commands and reading and writing to the database. On top of the application layer will reside the game layer which will be customizable libraries that will use and access the application layer. This follows along the MUD driver and MUD lib pattern where my engine will be the driver which will persist data and handle all communications and my MUD libs or games will be written in an OO fashion to take advantage of the game engine.
The engine is being written in C# and in such a way to take advantage of features of ASP.NET such as HttpModules and HttpHandlers.
by Cameron Albert
17. October 2007 23:48
In between updating Perenthia and adding new features I have been pulling parts of the code base into a more generic PBBG Engine I am writing in C#. I started working on it when I upgraded the Knights of the Realm game and used parts of it for Perenthia. I am hoping to put Knights of the Realm Beta 2 on the new engine once I get it finished.
I am building the engine as generic as I can but it will incorporate a base rules set and some basic concepts. The base objects will be Avatars, Places and Things. These objects will contain the properties required to function within the rules set and all objects will derive from a base GameObject class that will provide a properties collection for creating custom properties on derived game objects.
The game will be driven by commands sent from the client. Some objects will handle the commands in the engine framework while other commands will cause events to be raised that deriving implementations can handle and provide custom execution or additional execution of the commands.
The egnine will basically be a commands/rules processor that I will hopefully be able to build a variety of games on. I have plans and ideas for several types of games and do not want to continually build the same thing over and over, hence the PBBG engine.
by Cameron Albert
11. September 2007 09:36
Here is a screenshot of the PBBG mapping tool I wrote for creating the Perenthia world. The screenshot is the City of Angarath, a starting point in the game. The mapper is a Windows application written in C# 2.0.
by Cameron Albert
7. September 2007 01:17
Making good progress toward the Beta release of my PBBG Perenthia on September 14th. Not sure what time of day I will open the site up, probably in the morning some time on the 14th. Anyway, the AJAX game interface is working great after I scaled it down a little. I am still working on a more advanced interface in Silverlight 1.1, might be a little while before that is finished though, I want to get the game up and running first.
by Cameron Albert
29. August 2007 17:19
I spent some time last night and today playing around in Silverlight to make a final decision on whether or not I will use it in my PBBG Perenthia. I had already started building out a Flash UI but just keep running into the same issues with Flash; the IDE sucks and I keep having to rebuild C# classes in ActionScript. So, I decided to dig a little more into Silverlight to see if using the 1.1 version would be feasible. The word from MS is that the beta 2 with a go live license should be available sometime later this year. That might work out pretty well for me and my current timeline. I have most of the server functionality for Perenthia complete but just can't find a UI combination that gives me what I want and keeps the overhead down. Anyway, I am going to spend the next few days playing around with a Silverlight UI and see if I can come up with something I can use in place of Flash.
by Cameron Albert
27. August 2007 13:13
Here is a screenshot of the UI (user interface) that I am building in Flash for my PBBG Perenthia. I am converting the AJAX/HTML elements to Flash so it it somewhat incomplete but does give you the overall feel of the interface. The place where that gray square is will be the map and next to the map will be displayed the name of the place/room you are in and a listing of other players, NPCs, etc. in that place/room.
I am going to do a write up with my findings in regards to the Perenthia PBBG UI using AJAX, Flash and Silverlight. Might do that sometime later today.