A Corny Plug-in

As soon as I saw Gus Mueller’s offer of a free license for anyone writing a decent plug-in for Acorn, I felt moved to exploit his generosity contribute to the nascent plug-in community. So I quickly slapped together a possibly-useful filter, which ended up being a simple wrapper for a Core Image kernel (my first). Obviously that should be repackaged as an Image Unit. However, it did crash in a confusing way for a while, which is good, because it inspired me to write (most of) a test rig: a command-line tool which loads a given Acorn plug-in and runs each action it registers.

Then I started on a new plug-in, which is UI-centric and therefore can’t usefully be tested on the command line.

As such, the test rig isn’t ready, but the new plug-in is. It adds an Export… menu item to Acorn’s File menu, allowing the export of any file format supported by ImageIO – currently BMP, GIF, JPEG, JPEG 2000, OpenEXR, PDF, Photoshop, PICT, PNG, SGI, TGA and TIFF. Some of these are already supported by Acorn. But hey, some aren’t.

Plug-in and source code (MIT/X11 license) available here.

Posted in Cocoa, Code | 2 Comments

Priority Queue

The Foundation framework: it has some collections. It doesn’t have others.

In particular, it doesn’t have a priority queue, which I need. CoreFoundation does, but this is for Oolite so it needs to work with GNUstep. Yes, I could bring in all of CFLite, but without the toll-free-bridging it’s not particularly attractive.

Mike Ash (who seems to be getting an indecent amount of exposure in this blog, to the extent that it counts as an exposed location) wrote about the issue last year. His solution was to use the C++ Standard Template Library, but I don’t like that solution much because a) GNUstep doesn’t play nice with Objective-C++ (its headers aren’t C++-clean) and b) it’s C++.

So, as you may have guessed, I’ve gone and written one. Here it is, with the small amount of Oolite dependency ripped out. MIT/X11 license.

Operations supported:

  • Add object.
  • Add all objects in a collection (anything that responds to -objectEnumerator or -nextObject).
  • Retrieve highest-priority object. Priority is defined by a comparison method specified when creating the priority queue. Priority is defined such that the NSOrderedDescendingmost object has the highest priority; as such, using caseInsensitiveCompare: as the comparator will cause strings to be retrieved in lexicographic order.
  • Delete highest-priority object.
  • Delete specific object.
  • Delete equal object (i.e., delete one object such that the comparator returns NSOrderedSame).
  • Retrieve all objects in sorted order, emptying the queue.
  • Equality testing and (low-quality) hashing.
  • Copying of the entire queue.
Posted in Cocoa, Code, Oolite | 5 Comments

Performance Comparisons of Common Operations, PPC Edition

Mike Ash has written some microbenchmarks to test the speed of operations like Objective-C message dispatch and object creation, in response to people’s premature optimizations based on unfound assumptions. This is one of those issues that comes up rather often. The numbers are interesting – especially the Objective-C message send vs. floating point division – but I wanted some numbers for PowerPC, since ABI and hardware differences could be expected to reorder the list somewhat.
Continue reading

Posted in Cocoa, Code | 2 Comments

GLSL uniform bindings for Cocoa

Executive summary: This article demonstrates the use of Objective-C’s dynamic object model and the Foundation framework to extract attributes from objects using information not available at compile time. This is done on the context of implementing OpenGL Shader Language support in a cross-platform game.

Introduction

A major feature of the current development line of Oolite is support for GLSL shaders. Shaders need to be able to reflect the state of the object they’re attached to – for instance, by having spaceship engines glow in proportion to engine power. The mechanism GLSL provides for this is uniform variables, attributes set by the host application and read by the shader.

A screen shot of Oolite.

Debris model with per-pixel lighting and heat glow which fades over time from glow_alloy.oxp. Model by Arexack_Heretic, textures by Griff, shaders by Ahruman.

Continue reading

Posted in Cocoa, Oolite, OpenGL | Leave a comment