RSSAmplifier

Blog

F# for game development

About F#, game development and programming for .net in general.

sharp-gamedev.blogspot.comRSS feed ↗25 posts

Latest posts

The proper place for objects in code

When I worked at Prover Technology I took part in projects that involved automatically generating code that had to be reviewable by safety engineers who were not software specialists. This highlighted a number of cultural differences between the software development crowd and other technically-competent people. An interesting difference popped up when we discussed which Object-Oriented Programming…

Notes on creating large landscapes in Unreal Engine 5.3

I'm currently working on my next project, a skiing VR game using Unreal Engine. Note there's no .net or F# involved in this post. The process of creating a large landscape in Unreal Engine 5.3 wasn't a smooth experience for me for the following reasons: Shadow issues when moving around the terrain. Someone else has encountered that problem and described it here . Low-resolution textures, even…

A conversation with OpenAI's ChatGPT

I'm a bit late to the party when it comes to trying out ChatGPT. After seeing a somewhat provocative tweet on the subject of ChatGPT's effect on a programmer's productivity which basically claimed "use it and get 10 times faster, or don't and be pushed out of a job by the programmers who do", I decided I had to give it a go. I have a number of concerns regarding the use of ChatGPT to boost one's…

A type provider for IL-2 Sturmovik: Great Battles

Something that would have fit well in this blog is my work on writing a type provider for the mission files of combat flight simulator, IL-2 Sturmovik: Battle of Stalingrad . This game is the first in a series called IL-2 Sturmovik: Great Battles. The series is a reboot of a similarly named very popular game that came out at the turn of the century, I believe. One of the aspects of this game that…

Type providers confusion lifted

... at least partially. After looking at the FSharp.Data library and its source on github, I found that the Json type provider clarified the most important point. Namely: I'm not sure if this design-only type has inadvertently "leaked" into the runtime, or if any code used by the type provider must be present in the run-time component. It is not the case that all code in the type provider in the…

Frustration with type providers

I'm currently in the process of trying to port my type provider for IL-2 Sturmovik: Great Battles missions. It's a rather frustrating experience, so here is me ranting about it. Maybe writing down my thoughts will help clarify them, and might also help other people who are also feeling confused. Type providers have always confused me a bit, maybe because one must keep in mind the boundary between…

"F# Deep Dives" is out

Tomas Petricek gathered a team of authors to write a book about practical uses of F#. The result is " F# Deep Dives ", published by Manning. I contributed a chapter about programming games using XNA. It demonstrates a number of techniques, using a simple missile-interception game. The complete source code is available on github .

Understanding variance using functions

Statically typed languages that support parametrized types (generics) and types hierarchies (inheritance) sometimes support covariance and contravariance, concepts which many find confusing. I think I have finally understood these, thanks to a blog post by Tomas Petricek on the subject. In this post I'll try to formulate my own understanding, and how I got there using functions instead of classes.…

Recursive descent parsers using active patterns, part 2

In the previous post, I presented a method to implement a parser relying solely on core F# features, namely active patterns. In this post, I'll touch on some of advantages and limits of this approach. Recursive descent parsers are limited to LL(k) grammars, which means that left-recursive grammars cannot be directly handled. It is necessary to rewrite such grammars to remove left recursion.…

Recursive descent parser using active patterns

Today's post isn't specifically about games, but about parsing, which I find is a recurring task in many programming tasks, including game-related tasks. In F#, the most popular methods for writing parsers are FParsec and fslex/fsyacc . Although parser generators are very useful, I'm always a bit reluctant to depend on third-party software. In the past I have worked on a development tool for…

Problems with portable libraries and object-oriented APIs

I've got along well with inheritance for a long time, but this was not peace. Inheritance was preparing, in the dark, cowardly, waiting to byte me. And it just did that! In my last post , I presented a method to detach libraries from external assemblies and let applications take responsibility for the "linking". The key was to use interfaces to shadow the API of the external assemblies. Sadly, it…

Modular programming for portable F# libraries

I've been battling a few more rounds with F# portable class libraries. Getting them to work on PCs wasn't a walk in the park, but it seems I've got it working at last. Although this particular problem is not the main topic of this post, I expect many will run into the same issue, so I'll dedicate a few lines to its resolution. The setting I have a portable F# library which performs some physics…

Portable Class Libraries: Are they worth the trouble?

The (initial) problem Everyone who's been developing games using XNA for the Xbox360, WP7 and the PC platforms knows managing projects and solutions is a bit troublesome. Here is the problem: in theory, all you would need is to have a single solution with three platforms: x86, xbox and wp7. However, that's not how it works in practice. The various DLLs that you need to reference vary from one…

Units of measure for array indices

In F#, arrays play an important part in optimizing performance-critical parts of your code. This is especially true on Xbox 360, where arrays of value types can help avoid snags due to slow garbage collection. Unfortunately, index out-of-bound exceptions are common when working with arrays. This post shows a little trick to help detect cases where the wrong variable is used as the index. /// An…

Units of measure to the rescue!

Physics can really improve immersion in a game, regardless of how faithful they are to reality. That's why I always enjoyed writing simple physics engine. Even though I have stuck to really simple physics engine, I always end up mixing accelerations and forces. That usually doesn't lead to much trouble in the final result, as masses tend to be constant, and physical properties of game objects are…

Parallel draw-update XNA game component

Video games are often demanding when it comes to computation power, especially simulations and 3d games. The Xbox 360 has 3 cores with two hardware threads each. Of these 2 are reserved for the system, leaving 4 available to the programmer. This article describes an easy to use custom XNA game component that allows to run computations in parallel with rendering. The typical game loop is often…

Converting FS project files to target Xbox 360

Of interest to anyone using F# and XNA to make games targeting the Xbox 360: I'm working on a script to convert fsproj files for the PC platform to the Xbox platform. https://bitbucket.org/johdex/xnautils/src/a2cc6e8c7455/WinPc/ConvertFsProj.fsx It's not 100% ready yet, the converted files need some manual editing before they are usable. The advantage of using a script over using the project…

Defeating the blank page

Programmers have two ways to approach implementation of complex programs: Start by building bricks, combine them to build larger bricks, repeat until the brick is actually a house. Work the other way around. The second approach is actually the more sensible one for new problems. In general, you know what is the problem you want to solve, not how to solve it. It's therefore easier to write the…

An example of inheritance gone wrong

In an earlier post entitled Why inheritance for code reuse should be avoided I pointed out that the key problem was conforming to the Liskov Substitution Principle. Although I guess there is nothing controversial in what I wrote, I fear I probably did not convince anyone who wasn't already convinced. Today at work, I had the pleasure of being hit by a bug that is a wonderful example of inheritance…

New e-book: FRIENDLY F# with game development and XNA

I received a mail from Giuseppe Maggiore, one of the authors of a new book: FRIENDLY F# with game development and XNA. Giuseppe helped me put together the project templates for F# and XNA on the Xbox 360. The main subject of the book is the F# language and its various constructs, but every single chapter is centered around a game-related problem. Each one of the first 5 chapters describes a…

The forgotten control flow construct

There is a truly powerful control flow construct that many programmers have forgotten. It helps implement complex flows that ifs, whiles and matches can't handle. Not even throwing and catching exceptions can measure itself to this construct. You may wonder what kind of situation would require something that traditional constructs can't handle. Here is an example taken from Go To Statement…

Is it worth it?

In my previous post, I explained why inheritance for code reuse is a bad idea . The blog was a bit on the theoretical side, and I wanted to know if I wasn't sitting in an ivory tower. For this reason, I have decided to rewrite one of my uses of inheritance by composition. The piece of code in question is the BaseScreen class in XnaUtils. Before I go any further, I need to give you a bit of…

Why inheritance for code reuse should be avoided

The question of when to use inheritance and when not to has been asked many times. I have noticed answers can be put in one of three categories: 1. Use as much as you can. It's a convenient way to maximize code reuse with very few keystrokes. Actually, this answer is seldom explicitly given, but if I judge by the code I see, this is a wide-spread opinion. 2. There are situations when inheritance…

OOP without classes in F#

Did you know that F# allows to use some object-oriented features with types that are not classes? This includes methods, dynamic dispatch, open recursion and encapsulation. Methods are functions or procedures which are tightly coupled to a type of object. Dynamic dispatch is the ability to execute different implementations of an operation depending on the concrete types of arguments. A special…

Reference-counting just isn't enough and actually is harmful

I recently came across a blog entry titled "Why Garbage Collection is not Necessary and actually Harmful" . I used to share the same opinion in my C++ days, when I used to think no better language could be written. A few years later, I have drastically changed my opinion on the subject. I am not going to address all points made against garbage collection, and instead will focus on one issue: The…