Apr 192013
 

I’m writing a plugin in .NET that’s hosted on a windows service running in the background. There I want to display a WPF modal window that should be activated and stay on top as soon as it gets shown. This is the only way I found that worked for me:

using System;
using System.Threading;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Interop;
using System.Windows.Threading;

public static class UiHelper
{
    public static void ShowDialogInNewThread<T>(object dataContext, Action<T> onComplete) where T : Window, new()
    {
        Thread thread = new Thread(() =>
        {
            SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
            var window = new T();
            window.DataContext = dataContext;
            window.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
            window.Show();

            IntPtr handle = new WindowInteropHelper(window).Handle;
            AutomationElement element = AutomationElement.FromHandle(handle);
            if (element != null)
            {
                element.SetFocus();
            }

            System.Windows.Threading.Dispatcher.Run();
            onComplete(window);
        });

        thread.SetApartmentState(ApartmentState.STA);
        thread.IsBackground = true;
        thread.Start();
        thread.Join();
    }
}

 Posted by at 2:50 pm
Sep 142012
 

I’ve had this idea for quite some time, and now it seems like I’m going to be able to accomplish it.

Since the last Devmania I’ve been quite satisfied with the tools I’ve used to develop Angry Pirates, but it was a single player game. I want to use C#, XNA, Farseer Physics and eventually GLEED2D again, and I want to develop a PvP (player versus player) game on one single machine. Forcing two players to squeeze their fingers on one keyboard or splitting controls to two different input devices (one keyboard, one mouse) was never appealing to me.

When I found out about the PlayStation Move Controller, I fell in love with it. A friend of mine had two unused ones at home, and he kindly borrowed them to me. Summed up quickly, it has a RGB LED, vibration support, 8 buttons, accelerometer, gyroscope and many other features. It can be connected to the PC via 5-pole USB mini-B cables and via Bluetooth.

In theory, yes. And in practice, too, after a lot of googling, debugging and trial&error. Suffice to say, that thanks to Thomas Perl and MotionJoy I now have a working C# sample application displaying me live sensor data and allowing me to control the LED and vibration of both PS Move controllers at the same time.

First milestone accomplished. Now it’s time to think about possible game mechanics!

 Posted by at 9:25 pm
Jun 092012
 

Today I’ve spent several hours trying to create a Domain Service for Windows Azure and having a Metro-style App consume that service.

Creating the Domain Service is easy, just add a new Domain Service class, create a public method inside it, build, done. You can open it with the well-known URL scheme http://servername/namespace-servicename.svc. But doing that is not enough so that clients can consume it. The default “you have created a service” page offers you a link to the WSDL version of the service, where the URL scheme is like this: http://servername/namespace-servicename.svc?wsdl. But there is the problem. Visiting that URL doesn’t show any WSDL, it shows the “you have created a service” page again.

After hanging around in google for a few hours, I finally found the missing puzzle piece… you have to create a SOAP endpoint, in order to get the automatic WSDL generation working! Just add the following lines to your Web.Config file:

<system.serviceModel>
  <domainServices>
    <endpoints>
      <add name="Soap" transmitMetadata="true" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </endpoints>
  </domainServices>
</system.serviceModel>

After having done that, you can go to your client app, Add Service Reference, give the URL to the .svc file, and you’re done.

 Posted by at 11:12 am
Apr 092012
 

I visited Revision 2012, a demoparty held in Saarbrücken, Germany. The winner of the PC 64k compo was an intro by Approximate. I must say that I’m astonished by the level of detail and love they put into this production. This is what I was hoping for since I know the demoscene. Do more nature demos/intros! Nature is beautiful, and this beauty can be seen in just 64 kilobytes!

The video cannot be shown at the moment. Please try again later.

 Posted by at 11:40 pm
Mar 262012
 

I’m working on a 64k intro and decided to render scenes, where most of their content is based on triangle meshes. I also want to display some raytraced objects at the same time. Both rendering methods should use multisampling, and the painter’s algorithm should be simulated correctly as expected using Z-Tests. Before we enter into details, here is the picture of the result (click for a larger version):

The terrain and the hollow cube are triangle meshes, and the white sphere is raytraced. I want to explain how I set up the rendering pipeline. Continue reading »

 Posted by at 6:02 pm
Sep 302011
 

I just spent much time refactoring my recently released Silverlight 4 project at work to use Silverlight 5, with in-browser elevated trust enabled. We want to get rid of having to use Isolated Storage for temporary storage, instead we want to use a folder inside of the client’s My Documents folder. After going through every assembly, ensuring that they’re all signed with their private key, that the XAP gets signed with its certificate and fixing assembly references to use strong-names, a run-time error occurs:

A first chance exception of type 'System.Reflection.
   ReflectionTypeLoadException' occurred in mscorlib.dll
Additional information: Unable to load one or more of the 
   requested types. Retrieve the LoaderExceptions property 
   for more information.

This came when calling:

CompositionInitializer.SatisfyImports(this);

I couldn’t get that fixed no matter what I tried. After having googled around a bit, I found this (TypeLoadException in MEF, SL5 RC) and this (Silverlight 5 RC TypeLoadException). Seems to me that I can’t continue working, because my Silverlight app won’t start. Unless I comment out almost the half of it (we use MEF in many places), or I temporarily implement some manual loading. This error wasn’t there in Silverlight 5 Beta, and only happens in elevated trust scenarios.

Why can’t we still download the Silverlight 5 Beta? When is Silverlight 5 going to be released?

 Posted by at 12:23 am
Sep 232011
 

I’m working on a Silverlight project, where I wanted to enable my users to send private messages to each other, while enjoying the features of the RichTextBox. I also wanted to implement a search feature, so that my users could find their messages easily.

It turns out, that the only way, that I could easily get a serialized string out of the RichTextBox, was to use the RichTextBox.Xaml property. Continue reading »

 Posted by at 3:29 pm