Best design pattern for complex silverlight games - c#

What patterns do you think are best for silverlight games? Some main areas of focus are game performance, maximum number of objects reasonably updated in real time, ease of development and testing.

Actually the blog Shawn mentioned should be http://www.bluerosegames.com/silverlight-games-101/
I've been fighting this one for a while, and in XNA games I am leaning towards a Model-View pattern but in Silverlight I like using a combination of inheritance and composition that I detail here:
http://www.bluerosegames.com/silverlight-games-101/post/An-improved-Silverlight-Sprite-class.aspx
It just seemed that when I went to implement a Model-View pattern in Silverlight for games that it got in the way more than it helped. It could also be that I just don't understand the pattern well enough and I'd love to see if someone who's better at it to see if what I do is applicable to that pattern.

For ease of dev and testing, applying the MVVM pattern (which is widely used in the WPF community) will be of great help. But as for the the other pieces, I would read Bill Reiss' blog (http://www.bluerosegames.com/silverlightbrasstacks/) as he has done a lot in that area.

Related

ReactiveUI and Caliburn Micro together?

I've been doing some prototype work on a new Silverlight application using Caliburn Micro as our MVVM Framework. The team has generally been happy with it. In order to address some issues with throttling requests to services, it was suggested that I look into ReactiveUI's ReactiveCollections and their implementation of INotifyPropertyChanged.
Does anyone have any experience around using the two together? Since they are both primarily MVVM Frameworks, there's a good bit of overlap, so I wonder if it might be more trouble than it's worth to try and make them work together.
Some of the things we really like about Caliburn Micro are:
The Convention based binding, etc...Very nicely done in our opinion.
Bootstrapping. We like the way this is handled, it's easy to extend when you need to, but the out of the box stuff works well for many of our use cases.
Composition/Screen Management. We really like Rob's notion of conductors, screens, etc. It flows very nicely for us.
The ReactiveUI stuff that has drawn us to it (at least initially).
The Reactive Collections and INotifyPropertyChanged stuff. Particularly
the ability to throttle the reactions.
Reactive's asynchronous stuff seems a bit cleaner to deal with than Rob's Co-routine implementation.
I've barely had a chance to play with ReactiveUI yet, but as I was looking at it and seeing the overlap between the two, I wondered who might have tried to work both into a project. I haven't been able to find anything via Google (which could well be my fault).
I'd love to know if you tried this; what issues did you have? Which parts of each framework did you use and why? Are there any good examples or blog posts out there on using them together?
Cheers,
Steve
Use both! This blog post should get you most of the way there - it's actually very easy to take existing ViewModels that use other frameworks and "RxUI'ify them". This way you can try out ReactiveUI on a single ViewModel without having to pick either Caliburn Micro or RxUI.

MVVM Light + Unity or Prism?

I am a little out-of-date in WPF right now and would be interested to hear peoples opinions on the latest version of Prism (which I used a couple of versions ago) vs an MVVM Light + Unity approach (which I have never done - decent examples URLs would be good).
My project will be a large one comprising multiple modules written by several developers. There is also the funds to bring in a 3rd party control suite in order to set up a nice workspace using one of the fancy Docking/Workspace layout managers out there (and I know some play better with the Prism regions than others).
If you were starting a project from scratch right now, what would you go with and why?
Details on specific recommended architecture patterns would be useful (e.g. auto discovery of module dlls? Injecting logging service?).
Basically, any thoughts and advice would be good. I'd like to get a good discussion going. Perhaps there is another direction entirely that you would suggest going in? I'm very much in the research phase and would like as much input as possible.
I put this on here because I thought it would get less biased points of view than the Prism/MVVM Light forums but, if there is a more suitable place for this question, please point me in that direction.
If you need modularity, you'd want to look at Prism. Prism has some elements that can help you with MVVM (DelegateCommand and CompositeCommand, for example), but I think it's more complete with another MVVM framework.
There was a question a few days ago about how to model Prism. Check that out for a detailed explanation of how to consider Prism's functionality.
High Level Modelling Advice for Prism MVVM
Unity is an implementation of an inversion of control container and it's definitely good, but Prism has the ability to use other containers. It has builtin support for MEF (which, in turn, is builtin to .NET 4.0), but it's not your only choice. Look at some of the samples included in Prism and decide what approach you like better. Unity is not complete on its own for UI compositing in my opinion. MEF might be a closer choice if you wanted to try to composite a UI with the MVVM Framework + IoC Framework approach.
MVVM Light is actually a complimentary framework to Prism. Other MVVM frameworks to consider:
MVVM Foundation (very lightweight... good for small projects)
Caliburn (very robust framework)
Caliburn Micro (shares a name and an author from Caliburn, but it's akin to MVVM Light with some nice conventions)
ReactiveUI (Formerly "ReactiveXAML". This is a bit of a brain melter, but if you learn Reactive Extensions for .NET (Rx), this framework is simply amazing... magical in my opinion.)
If I were going to start a new project: I would go with Prism and ReactiveUI.
Prism because you have to have modularity with large projects and I like the ability to remove and add large units of functionality to an app just by deleting or adding DLLs (and you don't have to implement the DLL sniffing feature like you would with just an IoC + MVVM approach). Easier to test, easier to debug, easier to develop separately. Nice all around.
ReactiveUI because with UI programming these days, most of your time is spent managing your time on the UI thread. Blocking is a no-no... users don't want to see a UI freeze; they want to see that animated GIF wait symbol spinning so they know they can work on something else while your data is loading. In addition, so much of the value applications provide these days is taking data from disparate systems and putting them together in the UI... not only will you need a good compositing system (Prism), but you will also need a good MVVM framework that treats asynchronous operations as its bread and butter... ReactiveUI is it.

C# architecture for large application

Can you please tell me some tutorials/books about thinking a large application in c#.
I have worked with 3 tier, but i need something more specific:
a way to design panels, so that for specific users specific panels will load and specific dlls
a database management so that when a user modifies an entry, others can not modify that entry
should i use entity framework or should i go old school with db and class creation
any links on the above will be greatly appreciated
thanks a lot!
Kind of a broad subject but two books I would recommend giving a read regardless of what language you are doing or the specifics of your project:
Code Complete
Design Patterns
If you have specific questions about how to accomplish something I would post it on here or google it.
Sharp Architecture is just such an architecture. It's pretty detailed and a lot of work has gone into it.
NDepend documentation comes with two white books and also online blog posts and articles concerning the architecture for large .NET application:
Partitioning code base through .NET assemblies and Visual Studio projects (8 pages)
Defining .NET Components with Namespaces (7 pages)
Control Components Dependencies to gain Clean Architecture
Re-factoring, Re-Structuring and the cost of Levelizing
Evolutionary Design and Acyclic componentization
Layering, the Level metric and the Discourse of Method
Fighting Fabricated Complexity
That's not gonna be covered by a single book or tutorial.
You need to decide a UI framework, data access technology, patterns and the overall architecture. And of course you need an in-depth knowledge on .NET framework, & how the CLR works. It's nothing C# specific. Since you have UI customization (Panels) requirements, WPF is definitely a better candidate for UI framework, than WinForms.
That being said, my recommendations -
For C#: Pro C# 2010 and the .NET 4 Platform
.NET & CLR: CLR via C#
UI Framework - WPF: Pro WPF in C# 2010
Use MVVM with WPF. MVVM will keep you on track maintaining the Separation of Concern. You can follow Microsoft's Prism guideline. For large applications with sophisticated UI requirements Prism is a better choice. You might need to use Dependency Injection. MEF is there to go hand-to-hand with MVVM & Prism.
Yes, Entity Framework can handle concurrency issues, but such feature is available in almost any other data access framework. Entity Framework provides lots of other facilities, but when using it you should have clear idea of what you're doing. Otherwise you might end up with performance issues. Programming Entity Framework is definitely gonna help.
With respect to the panels/UI architecture, it might be useful to look at Prism (from Microsoft patterns & practices). It's an architecture/set of libraries to handle composite UI, where the UI is loaded at runtime and composed of independent communicating parts. One note, it is built for use with WPF or Silverlight; there is an older library with similar functionality for WinForms, called "CAB", that is no longer supported.
As far as data access, it sounds like you are looking to implement active record locking while a record is open for editing in the UI; this is an independent feature from the actual data access code you use. It might be easier to implement database-level locking if you are using straight ADO.NET versus EF, which adds layers of abstraction.
Microsoft .NET: Architecting Applications for the Enterprise - with a very good code example and there is a chapter on concurrency
Professional Enterprise .NET
ASP.NET 3.5 Website Programming: Problem - Design - Solution
I guess, there are not any online recources that could compete the complexity of these books.
My go to book with these kinds of questions is Jeffrey Richter's CLR via C# book. It takes you all the way from how your class construction impacts memory on the stack/heap to best practices for these types of discussions. Especially loading assemblies on the fly and the best way to accomplish this.
It will also bring your skills up a notch and Jeff is a great writer.
I recommend this book to EVERY C# developer I know and they always come away better. Is that what we all hope for?
Good luck!
If you want to learn fast and get to the meat of the technology fast, I would recommend getting a Pluralsight account as that would cover the technologies you would need and highlight others you may not have heard about. A monthly subscription would be about the same cost as a decent book.
Pluralsight.com

C# XNA: AI Engine?

I'm developing a game with zombie running around in a swamp. I want AIs to have functionality like "chase this target" or "run away". A major stumbling block is pathfinding. Is there a good pathfinding/AI engine in XNA, or should I roll my own?
Does anyone have any experience with this: http://www.codeplex.com/simpleAI?
you may want to look for A-Star algorithms... here is an article that talks about it in the context of a winform, but mentions XNA.
Roll your own! Seriously.
I take it you're making this game as much for the enjoyment of coding, as you are hoping for fame and riches? Pathfinding is one of the staples of AI, and is a well studied and documented topic. It is an excellent introduction to a field you'll need knowledge of in future game endeavours.
The A* Algorithm (as mentioned by others) is the standard solution to this problem - but try other approaches: line-of-sight, scripted movement, flocking... often you can derive interesting behaviour from combining a few techniques.
For a book on the subject, try AI For Game Developers - not the best in the field, but certainly an accessible introduction for the lay-coder.
Have fun mucking about with the zombies!
http://xnapathfindinglib.codeplex.com/
http://swampthingtom.blogspot.com/2007/07/pathfinding-sample-using.html
To everyone that's suggesting A*: you generally wouldn't put vanilla A* into a game. There are a lot of improvements and extensions for A* including (but not limited to) IDA* and transposition tables, that improve performance with A*-based search.
You might want to use a library to get you started but you may ultimately benefit more from your own custom implementation, using your own data types native to your app, instead of having to marshall data back and forth. But you'll need to profile to be sure.
The XNA Creators club has samples for Chase and Evade and Flocking.
I've just started down the path, but they seem to have some good resources on the creators.xna site.
I'll be using some pathfinding logic in my game, the A* Algorithm seems to be the winner for me.

Developing a new application with .NET?

I have to develop a basic "line of business" application with the usual functionality like orders, stock control, sales, reports, etc.
I will use WPF to develop this application to run on Windows but I want to develop it "open" so I can do a Windows Forms application using the same structure (maybe to run over Mono) or even a Silverlight module. Can someone that did something like that (and survived) give me a sugestion on a guideline or something like that where I can find good practices? I'm a Delphi developer with some intermediate knowledge on C# but there are so many "amazing" libraries, frameworks and patterns that I'm a little lost on what would be good for that project.
Something like: Use EF (maybe wait for ef4?) or nHibernate, or ADO.NET, and expose your data using WCF, or webservices, or forget Mono because of the flexibility loss, etc. Can someone give me a tip on how you would do it? If someone has a bad experience in this type of project, it would be nice to hear from you as well. There is a lot of learning in the wrong decisions too :)
Mono doesn't implement WPF, it's not even on the roadmap. I'm not sure about Entity Framework...
You could probably do it in Silverlight (which has an open source implementation), but it's not ideal for creating desktop (although it is possible since Silverlight 3)
Where do I start?
First, from your description, you're in over your head.
Second, you're trying to pick a technology stack when everything is new to you.
In the best situation, I'd recommend a good training class in a few of the technologies you mentioned so you get a better understanding of them. I'd also recommend a mentor, someone who's done this before.
Reality though, may not allow for training or a mentor. In that case I'd recommend writing several real-life throw away programs. Take one piece of business functionality and try to write it in a few of the technologies you mentioned. If one feels better, and gives you what you want DECISION MADE! Don't stop with the first one that seems to work, try some more.
You should also listen to some good podcasts. I recommend Dot Net Rocks for a good grasp of the technology. The earlier podcasts for this site were also a very good source for some design discussions StackOverflow podcast
Best of luck.
I had to do something very similar recently in WPF. I have an ASP.NET background, but I have never worked with WPF (or WinForms for that matter), and it had me stumped for a while, but the longer I have been working on it (about 3 weeks now), the easier it has gotten. I really just searched Stack Overflow and Google for code snippets similar to what I was doing, and worked through them and changed them as needed. My company bought a book that helped me out as well (It was WPF Unleashed published by Sams), and it was pretty good. I do wish you luck on your first WPF app.
If you separate the business model and business logic from the user interface,
using MVC (Model View Controller) or MVVM (Model View View-Model) or a simular design pattern,
then you can have multiple user interfaces connected to the same business model + business logic and even connect the same user interface to other business models + business logic.
Thank you all for your suport... Brad, I'm already following your advices, doing some test cases to see what looks good... my problem is that altough I can develop an application in WPF and have a intermediate understanding in using the wpf databindings, generics, linq, anonymous objects, all the cool stuff, I always hear about this and that as the solution for all the worlds problems (like mvvm, or parallel programming, or functional languages, etc) and makes me feel "wrong" in my decisions and a bad developer if I do not use any of this nice technologies. I know the concepts but do not dominate it, and seems a lot of things to learn, sadly I do not have that much time.
Thomas, exactly because mono do not support WPF i want to make the application as isolated as i can, so I can do a simple winform layer to manipulate the data.
darthnosaj, thank you, I'm doing that too, searching internet and found much information (and this nice site full of hellpful people :) )
And Danny, thats what i think i need... will take a look on some sample applications using mvvm and see if that works for me. For what i heard is almost a crime not to use in that case in wich I want that kind of isolation.
Again, thanks all :)
I would suggest you keep your application N-Tier. Make all the entities, data adapter, and business logic separated from the actual desktop application. This way you can use WPF on the Windows platform and use Mono/GTK# on the Linux/Mac platforms.
You will only need to write duplicate code to support the actual GUI application functionality, while your code from the separate entity/data access/business logic library (e.g. DLL/class library) can be used in both your WPF and Mono/GTK# projects. Just add the DLL as a reference to the WPF and Mono/GTK# projects.
There is a good video from Channel 9 on building N-Tier applications
There is also MSDN documentation and guidelines on building N-Tier applications

Categories