Categories
Apple Coding Fun Nerd Sniped Retro Computing

DOOM on the Apple Watch

I know this has been done, but I hadn’t done it, so it was my weekend nerd snipe. (no game audio)

This was a lot easier thanks to doomgeneric!

Basic breakdown

Since doomgeneric exposes the framebuffer, I throw that into an SKTexture and that gets added to a node in the SpriteKit scene, which is subclassed to override the update method to call doomgeneric_Tick(). Objective-C is used for interop between C and Swift, and fulfills most of the functions listed here. SwiftUI ultimately outputs the scene.

Very few tweaks needed to be made in doomgeneric itself.

They were basically:

  • Conditional compilation for a few calls that watchOS didn’t support (and we didn’t need).
  • Tweaking the 32-bit color bit offsets.
  • Handling a crash related to passing in arguments.
    • On watchOS we pass the absolute path of the WAD file in the main bundle to the engine.
  • Adjusting some SDL2 includes so headers could be found.

GitHub repo: https://github.com/twstokes/AppleGenericDoom

Categories
iOS Nerd Sniped Swift

UITextView, autocorrect, and custom attributes

For this week’s “Nerd Snipe”, I spent way too much time at work trying to track down a pesky bug related to our editor. Long story short, we send some custom NSAttributedString.Keys to signify differences in rich text. For instance, a heading attribute with an integer value may tell a parser to wrap text in an <h2> when converting the string to HTML.

Oddly, sometimes that special attribute wouldn’t be included when text was autocorrected, so the generated HTML wasn’t always what we expected. After a lot of digging I believe this could be a bug in UITextView (or maybe NSTextStorage).

Inspecting the value of attrString in the NSTextStorage function func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) after autocorrecting some text shows that it only seems to include attributes that were defined in Foundation (e.g. NSFont, etc.), but not our custom ones.

Regular typing works fine – you see all the expected attributes set in textView.typingAttributes.

In scenarios like these I like to make the simplest example to help confirm I understand it, so I’ve made a repo demonstrating the issue in case it’s helpful for anyone.

Categories
Coding Nerd Sniped Processing

Nerd Sniped

When I saw https://cacheflowe.com/art/digital/deepflat I was “nerd sniped”. I had to figure out how to do it. A bunch of coffees later…

What’s better? I have source code!

https://github.com/twstokes/labs/tree/master/viz/depth_grid