Before I begin this post, big thanks to Eibx and David over at the Community Forums for helping me find these methods. I have modified the CheckTexture method a bit, but its purpose remains unchanged.
As of the last FGF article, the Application class was implementing the IGame interface but was missing the ability to create a render target object on the PC and Xbox 360. For PC games this can be a troubling problem since different hardware can obviously require different formats and dimensions of render target. Rather than bake this functionality into the Application class itself, it is moved to a static helper class so that all developers can make good use of its functionality at any point in time.
To start off, a simple default creation method is included to give the basic functionality an easy access point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace FocusedGames.Xna.Graphics { public static class GraphicsHelper { public static RenderTarget2D CreateRenderTarget(GraphicsDevice device) { return CreateRenderTarget( device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, 1, device.PresentationParameters.BackBufferFormat ); } |
One of the requirements of the framework I am building (FGF) is cross platform support. For my XNA games this means support for not only Windows but also the Zune and the Xbox 360. For my Windows based projects I often find that X64 can be used (and in the case of IIS in 2008 R2, encouraged) so I also support X64 versions.
The problem is that when using an XNA project template to build a library for the simple fact that XNA projects can automatically synchronized (across platforms), Visual Studio blocks the creation of an X64 build target. Rather you are stuck with X86, Zune or Xbox 360.
The good news is that you can get around this! Open up the Windows project file (csproj) in a suitable text editor and copy the sections for both “Debug|x86″ and “Release|x86″ and paste them right after.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>..\Bin\x86\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <NoStdLib>true</NoStdLib> <UseVSHostingProcess>false</UseVSHostingProcess> <PlatformTarget>x86</PlatformTarget> <XnaCompressContent>false</XnaCompressContent> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>..\Bin\x86\Release\</OutputPath> <DefineConstants>TRACE;WINDOWS</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <NoStdLib>true</NoStdLib> <UseVSHostingProcess>false</UseVSHostingProcess> <PlatformTarget>x86</PlatformTarget> <XnaCompressContent>true</XnaCompressContent> </PropertyGroup> |
Next you simply replace the instances of x86 with x64 and change anything else you need.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>..\Bin\x64\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <NoStdLib>true</NoStdLib> <UseVSHostingProcess>false</UseVSHostingProcess> <PlatformTarget>x64</PlatformTarget> <XnaCompressContent>false</XnaCompressContent> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>..\Bin\x64\Release\</OutputPath> <DefineConstants>TRACE;WINDOWS</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <NoStdLib>true</NoStdLib> <UseVSHostingProcess>false</UseVSHostingProcess> <PlatformTarget>x64</PlatformTarget> <XnaCompressContent>true</XnaCompressContent> </PropertyGroup> |
One warning – this should only be used for projects that don’t require references to the XNA framework. At this time Microsoft has no support for x64 XNA references.
One of the major gripes I have with the Windows operating system is its inability to build decent event logs when an exception occurs. This is particularly annoying on the server builds because as a developer, I need to know what is causing a crash or a hang. Recently I have been developing a site using Sitecore and after a publish the site started crashing and bringing down the entire server. The following is an overview of how I solved the issue.
The first thing I did was check the Event Viewer on the server itself – notice the horrible information within the error. The one important code to write down is the exception code (0xE053534F).
After reading a tutorial on how to catch a crash I was able to catch the crash in a dump file. While the debug diag tool was useful for catching, I needed WinDbg to get to the root of the problem.
Note: I set the symbols location to SRV*c:\users\jsedlak\documents\websymbols*http://msdl.microsoft.com/download/symbols
As you can see, the debug view is fairly useless. Run the following commands:
Now you can see what is causing the stack overflow. Turns out it was an XSLT file that was doing a recursive climb up the Sitecore tree without a base case. The cause of the problem however was that I had just implemented Workflow on all items which corrupted their state and seemed to have removed their published version from the web database. By fixing the XSLT to have a base case and submitting all content through their workflow I was able to get the site back.
I run into these so much these days…
With the upcoming release of FGF/Thrust comes the return of a more traditional GUI. One of the most problematic requirements of a large GUI system is the notion of focus. The question remains how do you efficiently determine who has focus and how do you pass focus between controls? On Windows this is incredibly easy because we have the mouse pointer. Focus is changed whenever your mouse acts on a control. What about on the Zune or the Xbox 360 though? On both of these systems their is no mouse (although Thrust supports a virtual mouse).
The answer is to look at what Thrust currently supports. What built in system supports all three systems seamlessly? (~ means some support, X means full support)
| Event | Zune | Windows | Xbox 360 |
| Mouse | X | ||
| Keyboard | X | X | |
| GamePad | ~ | X | X |
| UniversalButton | X | X | X |
The problem is we can’t rely on each individual hardware controller being present and useable. For example we can’t rely on a keyboard being a focusing mechanism on the Xbox 360 because it isn’t a guarantee it exists. Likewise, we cannot rely on the GamePad on the Zune because of the lack of buttons.
To get to the point, the UniversalButton system was meant as a virtualization of the various hardware supported for each platform. It turns GamePad, Mouse, and Keyboard events into simple events like Up, Left, Down, Right, Select and Cancel. Because of this we can rely on it and implement a few more events.
You can consider local tabbing to be much like you would on a Windows form: hitting the tab key (or shift-tab) will move you from one control to another based on some order and only in the context of the global focus point (you never tab to a control in another window). The global tabbing can be considered like an Alt-Tab (or shift-alt-tab) where you can switch between windows.
So how do we implement this? We need a managing class (sorry Bjoern) to produce a bottleneck for the input events. As events are channeled through this class, it massages the data and figures out what to do. For instance if a global tab next event is received it has to switch focus to the next window in the system on the same level as the current window. If it receives a local tab event it will pass a message to the current focal point to tab to the next control.
What does this do for us? For one, it unifies the approach to focusing across all the UI subsystems. This means that a Window/Form implementation will focus in much the same way a simple screen will. Unfortunately it also means a complexity requirement for implementation developers. The age of the simple StateManager class is coming to an end. Elements on the screen now need to have a basic state for animation as well as a state for focus (or lack thereof). While it may still be possible to simply unload an element through the StateManager, the reality is that UI elements will have to do a little more management under the hood. Whether this is exposed to the user / developer is still to be decided.
I have a bone to pick with game developers and graphics artists out there using the term HDR incorrectly. I understand the notion that a word can mean something different under two different contexts. For HDR, however, the idea and term are rooted in how a scene is lit. Whether you are using it to describe a scene in a game or a photograph the term means the same thing. The H in HDR stands for High, not Low.
I am sick of seeing articles that explain how a developer can equalize tones in a scene by increasing or decreasing the exposure for each rendered object only to end up with the addition of glowing and blurring the scene. Bloom has nothing to do with HDR, it is an entirely different concept used to simulate the effect of an object appearing overly shiny. This is commonly done by downsizing the scene, blurring it and then pushing each pixel towards dark or bright. This effect works great if you are attempting to render a lightsaber, but not if you are attempting to use HDR.
The point of HDR, or High Dynamic Range, is to equally expose different parts of a scene. For example let’s say you had a dark room with a desk. On the desk is a lamp that is lighting the top of the desk. To the right of the desk is a chair that is dimly lit by the ambient light. Using HDR in this case would allow an artist (game developer, photographer, etc) to brighten the chair while darkening the desk (or leaving it alone). You can think of HDR as corrective lighting surgery for an image of a scene.
Even Wikipedia contradicts itself on this topic:
One of the primary features of HDR is that details in a scene with a large contrast ratio are preserved. Without HDR (for the purpose of this article, low dynamic range or LDR) areas that are too dark are clipped to black and areas that are too bright are clipped to white. These are represented by the hardware as a floating point value of 0.0 and 1.0 for pure black and pure white, respectively. Graphics processor company nVIDIA summarizes one of HDRR’s features in three points[4]:
The Wiki page is stating that HDR scenes provide a mechanism for preserving the details over the entire scene regardless of current exposure. It goes on to say that without HDR, you get over and under exposure problems. The contradiction occurs in the sample image (below) which depicts HDR incorrectly. On the side that is supposedly HDR, the scene contains hot spots of over exposure, a component of a LDR (low dynamic range) scene. Fortunately the right side of the image isn’t HDR either but simply the left side without the bloom applied.
It doesn’t stop there: one of the most commonly used examples is a person coming out of a tunnel. We all know the effect as we come out into the sun from being in the dark. Because our eyes adjusted to the relative darkness of the tunnel they are over compensating when they come out of the tunnel and thus it seems bright for a fraction of time. The problem is that people are attempting to use this as an example of HDR. Rather the desired effect is done through blooming (over exposing) the entire scene for a fraction of a second and then turning the exposure back down.
I am open to discussion (you will have to register to comment) to whether or not HDR means something different in terms of gaming but I will tell you right now that the term must be based on some idea. It isn’t valid for us to just use a term that has a meaning and change it because we need a word for that meaning. I am a firm believer that the term is rooted in how a scene is lit, as demonstrated by this other Wikipedia entry which actually uses 3D graphics to get the point across.
Tackling the problem in the previous post I have decided to rely on providing more options than necessary. I have to remember that because Vodka is not client software, I have to write it as if the client software will be as simple as possible. The goal of Vodka is to give developers a way of setting up a software based CMS with great ease.
To do this, I have built in services that can be implemented and exposed via WCF as well as built in implementations of these services. If you had the binaries for Vodka, you could reference FocusedGames.Vodka.Services, create a class in a Service project and inherit from ContentService or MembershipService. After deploying the project, you can treat it like any other WCF service reference.
The original question dealt with translation services however, is it a client or server responsibility? You would generally make it client side because you may wish to get a different template for the content or change how translation is done. This is on par with most CMS software installs out there but there is a problem. Templates in the Vodka backend are treated as standard items of content. It then would require two calls to the service: one for the template and one for the content. You would also have to know how the template is extracted from the content item. This is a bad idea as it increases server load unecessarily.
The answer is simple: abstract it and keep it server side. The idea here is that the developers can plugin their own template provider into the service when setting it up. This will allow them to point to another service, a local directory or hardcoded templates. If no plugin is used, the service will continue on its standard course, grabbing the template from the standard content data store.
You may be asking why you would ever want to use a custom provider to point to a second service. Let’s say you have a ton of websites that you all want to look the same. For instance Microsoft may have microsoft.com, msdn.microsoft.com, creators.xna.com, xbox.com, et cetera and may want them to all use the same templates for items. They could use a provider to point to a single template service removing the need to change 5+ templates on 5+ servers.
The Vodka Content Management System is a service based, multitier setup with the clients getting access to all content and member information via services. In turn, the services communicate with each other as well as their respective data stores. One of the goals of designing Vodka is to implement objects in a way that is easily extendable. To accomplish this, all content is managed in terms of the text data (XML) and its meta data (title, author, date stamps, et al).
The problem is how this data is transformed into its two main uses: HTML and .NET Objects. The question is where these transformations take place. In order to transform an XML file into HTML, the code needs access to an XSL file. The problem with this is that it too, is treated as a piece of content. It is regulated in exactly the same way with the same level of security. Thus it can be seen that this service should remain on the server. This is where it currently sits, so what is the problem?
The problem remains that it shouldn’t be a server side operation! That is slow! It requires more implementations than necessary and furthermore it builds a bad dependency on the server for specific implementation.
A new take on an old fable…
1 2 | while(!Activities.Contains(DefaultActivities.KissedByPrince)) sleep(0); |
So tonight I decided to have a drink and dive headfirst into coding. Seems to be going quite well actually as I have gotten a lot of work done on the Vodka front. I don’t mean the drink, of course, but rather my new Content Management System. Right now I am working on finishing up the Content Service and integrating it into FGDN.
But I digress, the point of this post is that I was discussing some refactoring decisions with a few friends and it came to me about how much I have grown. I never really thought about it until now; that I have changed so much in terms of how I see things. When I started coding when I was eleven years old I was using Visual Basic 5 and could see things only in terms of what they were on the most basic level. I understood that text belonged in a textbox for instance, but I didn’t know that the textbox was an object.
These days I can visualize data, problems, questions, designs, et cetera in terms of objects. If someone is speaking to me about a table in a database for example I see it not as a bunch of data but rather an object of sorts. Each row representing some part, whether it be whole or not, of an object. If someone gives me a problem, such as how to make sure UI controls follow certain rules for mouse events I see the entire UI as a tree of objects. It is instantaneous for me, instinct to put things in terms of concrete objects that I can play with and affect.
Of course it doesn’t stop with code! As I learn more about coding I learn more about life, the parallels can be drawn everywhere. There are certain things that are still to be explained but even emotions can be paralleled to an advanced choosing algorithm that works on many levels (conscious, sub-conscious). How do I see this? I see it as a producer-consumer relationship: the different levels of consciousness are providing input for the emotion algorithm. Each person an instance of some human class, acting on other objects, consuming objects.
This brings up a few questions:
1. Is thinking this way correct? Is programming in an object oriented manner correct? If not, what is?
2. What is the quickest way to corrupt a beginner so that he or she can think this way? How can we educate them quickly?