posts tagged with: programming

Dev Log: SortedDictionaryList

Dev Log: SortedDictionaryList
As I transfer all of my framework making knowledge over to the land of FNA I've been trying to clean up a few things that turned out pretty dang messy in the original Otter.

In the Scene class of Otter it keeps track of Entities, and Entities have an Order and Layer. Multiple entities can be in the same layer, and can be in the same order as well. Order is the order in which they update every tick, and layer is the order in which they render. So what I usually do is have a sorted dictionary of lists. The dictionary sorts on an integer value that matches the value of the order or the layer, and the value is the list of entities that belong to that order or layer.

Old Otter has kind of a big mess of copied and pasted code for this system, so for new Otter I tried to make a cleaner version of it.
class SortedDictionaryList<TKey, TValue> : SortedDictionary<TKey, List<TValue>> {
public SortedDictionaryList(IComparer<TKey> comparer) : base(comparer) { }
public SortedDictionaryList() { }
public bool HasItem(TKey key, TValue item) {
if (!ContainsKey(key))
return false;
else
return this[key].Contains(item);
}
public TKey FindKey(TValue item) {
foreach(var key in Keys)
if (this[key].Contains(item)) return key;
return default(TKey);
}
public void AddItem(TKey key, TValue item) {
if (!ContainsKey(key))
Add(key, new List<TValue>());
this[key].Add(item);
}
public void RemoveItem(TKey key, TValue item) {
this[key].Remove(item);
}
}

Another thing I'm looking to implement is a generic version of a "buffered" list of items somehow. A lot of times in Otter I don't want to add or remove items in a list in the middle of the update, so I end up buffering adds and removes until I get to the end of the frame and then all of them execute. I end up doing this in both Scenes for Entities, and in Entities for Components, so I'm rewriting a lot of the same code in both spots, but I'm still questioning if its worth it to try a generic solution for this or if it's fine the way it is.

Anyway I'm still on "break" for another couple of days. At this point I'm looking forward to my vacation being over!

Dev Log: FNA Tiles

Dev Log: FNA Tiles
Been working a little bit on getting tile maps set up in the FNA version of Otter along with a quick platforming movement test.

Image


I'm still wrestling with some issues in FNA that I'm sure are totally my fault, but so far things have been working pretty nicely. Understanding the whole sprite batch drawing thing is still a little bit tricky for me, and I'm hoping that I can wrangle my familiar engine api into something that doesnt perform like garbage. Trying to manage when I should be calling End() and Begin() is a little bit more challenging than I hoped, and I don't want to just be calling them both for every single draw if I can help it.

I've hit a weird snag with my initialization process and render targets, and I think it's related to some kinda weird race condition that I can't pin down... but probably more on this in a future post.

Dev Log: FNA Font Stuff

Dev Log: FNA Font Stuff
I'm currently in the midst of an actual break from development but I'll try to catch up on some recent developments while I'm loungin' about.

I'm still developing my new version of Otter using FNA instead of SFML. I'm slowly but hopefully surely finding out the best way to go about certain things like rendering and input. Fonts and text graphics are working pretty well now and I also have some basic input stuff hooked up for things like keyboard, mouse, and text entry.

Image


I'm using a C# binding of freetype for rendering fonts and text, and recently I implemented a system to handle huge font sizes. I say system but all it's really just a list of textures for the font instead of just one texture. Unfortunately the upper limit of font sizes is still the maximum size of the texture though... so right now 2048 I think.

I've almost got enough in my FNA engine to make a simple game aside from a few missing collision overlap checks and a handful of bugs. As much as I hate to say it I think I actually like SFML's rendering system better because so far using SpriteBatch feels like a giant pain in the butt most of the time. I understand why SpriteBatch is so important, but it seems like it'd be easier just to pass my own vertices and textures into the renderer... but for some reason that's mega slow. Right now one of the bugs I have to look into is the fact that rendering 10 or so primitives already starts to take a toll on performance, and it's only rendering a bunch of untextured vertices! Nothin' makes sense.

Character Sheet Updates

Character Sheet Updates
Not really sure if any portion of my followers play Pathfinder, but I'm still working on my character sheet manager anyhow! It's actually been a lot of fun to work on since web development is way easier than game development, and I get instant feedback on it from my pathfinder group every time we play.

Here's how it looks now.

Image


Added fancy icons from the Bootstrap glyphicons and did some formatting work on some of the headers to make them readable.

Image


Also added a dropdown menu with a "hamburger" button to open it. The icons make it look even cooler than it actually is.

Behind the scenes I made the sheet auto ping the server every 15 seconds so that the player session will remain active and not get garbage collected by the server.

FNA and SDL Events

FNA and SDL Events
I've been poking away at the new version of Otter which will be using FNA instead of SFML. At first I thought it would be super easy and cool to use the XNA "state" systems for input. Stuff like KeyboardState, MouseState, etc. The problem with this though is that at lower framerates this way of detecting input can totally miss inputs.

I couldn't find any examples on how to plug into FNA's SDL event loop, but I eventually stumbled into something that worked. All I knew was that I had to use SDL_AddEventWatch. So here's a quick example on how to use SDL events with FNA:
SDL_AddEventWatch((data, ev) => {
var sdlEvent = (SDL_Event)System.Runtime.InteropServices.Marshal.PtrToStructure(ev, typeof(SDL_Event));
switch(sdlEvent.type) {
case SDL_EventType.SDL_KEYDOWN:
Console.WriteLine("keydown: {0}", sdlEvent.key.keysym.sym);
break;
case SDL_EventType.SDL_KEYUP:
Console.WriteLine("keyup: {0}", sdlEvent.key.keysym.sym);
break;
}
return 0;
}, IntPtr.Zero);
I added this code in the Initialize method of Game, and I'm now getting my own key up and down events. Eventually this will be hooked into my input classes and I should have the same input functionality that SFML Otter has.

Pathfinder Character Sheet

Pathfinder Character Sheet
Over the past two weeks I built a web based Pathfinder character sheet manager. It's all the way up to version 0.9.something which means that it's totally usable but may have a couple of new features added before it's called 1.0. Actually thinking about it now I have a really bad habit of calling things version 0.9.something forever instead of ever calling it version 1.0.

The entire source, readme, and license can be found on Github.

And now here are some cool screenshots.

Image


Image


Image


Image


I should be getting back to game dev soon! I hope?