The World’s Leading Microsoft .NET Magazine
   
 
The .NET Addict's Blog

My Top Tags

                                                           

My RSS Feeds








Latest Diggs - Programming

Internet Blogs - Blog Top Sites

Site Hits

Total: 2,551,710
since: 19 Jan 2005

Continuous LINQ - Can I write games with it?

posted Mon 13 Aug 07

In a previous blog post, I discussed something that I'm building on top of LINQ called CLINQ. CLINQ allows me to write a query once and without having to poll the result set to force a re-enumeration, the result set is automatically notified of changes to the source. For example, if I write a query that has a sort and a filter on a source collection, then using CLINQ, the result set will automatically place new items in the appropriate sort order, and the result set is automatically modified when the source collection loses items, and when it gains items that pass the result set's filter predicate.

So, this is fantastically cool in a business scenario and I'm working on some proof of concept stuff that will show off how CLINQ works as well as publish the source code for CLINQ. However, I thought - what would it look like if I could make some WPF games with CLINQ?

Take, for example, a space strategy game. Let's say you want to bind your radar display to a list of nearby ships. This is a pretty typical scenario, but instead of re-polling your underlying set of all ships (populated by your network messaging layer, of course), what if you could define a query indicating nearby ships and that would automatically update based on network messages received without you having to do any real work?

It might look something like this:

ContinousCollection<RadarBlip> _nearbyObjects = 
    from radarObject in _networkObjects
    where radarObject.3DDistance(this.Position) <= this.RadarScanRadius
    orderby radarObject.3DDistance(this.Position)
    select radarObject;

radarControl.DataContext = _nearbyObjects;

Knowing WPF, you know that you can do pretty much anything you want with data templates. You could have a data template for each type of radar object (using a DataTemplateSelector that switches on something like radarObject.ObjectType!) and display a different image or maybe even 3D model (not sure if that's possible yet in Orcas...). The fantastic part about this is that you can have multiple queries on the same source set that all update independently as the source set is modified - and you as a developer are relieved from the burden of data propagation.

tags:        

links: digg this    del.icio.us    technorati    reddit




1. DakotahNorth left...
Mon 13 Aug 07 10:01 pm

In your example, you use this.Position ... will the collection dynamically change as this.Position changes?

From prevoius posts it looks like new items will be evaluated against this.Postion, but will items already in the collection be kicked out if they fall outside the radarscanradius of this.Position?


2. Kevin Hoffman left...
Tue 14 Aug 07 6:52 am

Good point. Right now, "this.Position" isn't a part of the source data so it won't have any control over the result set. Basically if any property of any item in the source collection changes, then it is re-evaluated against the filter predicate to see if it belongs in the output. If that passes, it is sent down the chain to any attached grouping or sorting adapters, making sure that everything remains consistent even though the source data is in flux.

What you'll see happen is when the source item (a RadarBlip instance) changes _its_ position, it will then be re-evaluated against the filter predicate, which is using a pointer to my current position.

So, in the current implementation of CLINQ, my radar blips will all automatically appear and re-appear based on their distance from me as they move. I will have to manually re-enumerate the result set when _I_ move because my current position is not listened to by the CLINQ adapters.

To, to summarize even further. While my position remains fixed, I will automatically get updates on everyone else's position, including radar blips that have fallen off my radar that then come back onto my radar at a later time (because the source collection is still listened to). When I move, that small gap in time where I have moved and none of my enemies have moved will give me a stale radar reading. So, when I move, if I want to make sure that there is never a stale period of radar, I can simply re-enumerate the query at a fairly low cost.


Tag Related Posts

CLINQ v1.1.0.0 Released!

Fri 02 May 08 5:38 P GMT-05
tags:          

iPhone Underrated as a Gaming Device?

Fri 14 Mar 08 1:50 P GMT-05
tags:        

CLINQ v1 Demo - Network Message Filtering

Wed 09 Jan 08 7:47 P GMT-05
tags:        

Continuous LINQ v1.0.0.0 Released

Tue 08 Jan 08 4:53 P GMT-05

LINQ to REST - A much better name for Astoria

Tue 11 Dec 07 1:23 P GMT-05
tags:        

Unexpected and Unsafe behavior in LINQ

Wed 14 Nov 07 8:09 P GMT-05
tags:    

C# 3.0 - Are Object Initializers Evil, Useful, or Both?

Fri 26 Oct 07 10:53 A GMT-05
tags:    

Building a Ledger Style for WPF Grids

Tue 21 Aug 07 3:30 P GMT-05
tags:    

Continuous LINQ - Can I write games with it?

Mon 13 Aug 07 3:09 P GMT-05
tags:        

Silverlight 1.1 Alpha Refresh

Fri 10 Aug 07 2:09 P GMT-05
tags:    

Orcas Beta 2 - might as well be a CTP

Tue 07 Aug 07 1:15 A GMT-05
tags:  

Continuous LINQ

Mon 06 Aug 07 1:21 P GMT-05
tags:    

Dynamic, Observable LINQ Views

Tue 31 Jul 07 1:21 A GMT-05
tags:        

Acropolis or Acrapolis?

Thu 05 Jul 07 12:34 P GMT-05
tags:      

My 2008 Wishlist : A Transformers MMORPG

Tue 26 Jun 07 12:04 P GMT-05
tags:        

My first "Acropolis" Application

Mon 04 Jun 07 1:40 P GMT-05
tags:      

Orcas' Hidden Gem - The managed PNRP stack

Fri 11 May 07 6:45 P GMT-05
tags:        

Orcas EDM Wizard Patched

Fri 27 Apr 07 11:56 A GMT-05
tags:      

Installing Orcas Beta 1 - VMware Style

Mon 23 Apr 07 12:16 P GMT-05

Orcas Beta 1 Released

Fri 20 Apr 07 7:09 P GMT-05

On MUDs

Thu 08 Mar 07 5:00 A GMT-05
tags:                    

Visual Studio "Orcas" - March CTP is Available

Wed 28 Feb 07 12:28 P GMT-05
tags:            

Objective-C Categories vs C# 3.5 Language Extensions

Mon 26 Feb 07 1:05 P GMT-05
tags:                

Ulysses Agenda Makes Redmond Developer News

Wed 29 Nov 06 7:10 P GMT-05
tags:                

A visit to Nintendo World on "Wii Day"

Mon 20 Nov 06 12:37 P GMT-05
tags:          

Ulysses Agenda - Network Engine Test 1

Mon 09 Oct 06 2:26 A GMT-05
tags:              

Ulysses Agenda : First Cut Networking Design

Thu 14 Sep 06 12:46 A GMT-05
tags:                  

DLinq vs the ADO.NET Entity Framework

Fri 23 Jun 06 4:01 P GMT-05

WPF/XAML and LINQ - A match made in heaven

Tue 06 Jun 06 11:32 A GMT-05
tags:                  

Language Extensions in C# 3.0

Wed 31 May 06 2:17 P GMT-05

Lambda Lambda Lambda

Sun 21 May 06 1:01 A GMT-05

The Adventures of LINQ (Not Zelda)

Fri 19 May 06 11:21 P GMT-05
tags: