Monday, March 24, 2014

Another way to post code snippets!

Bam.

A great way to host/post code snippets is to use Github+Gist.

In short, you create a file with some code formatting, and then copy the embed link to post on your blog. It's really simple and really fast.

Here's my steps for getting from A to Z:

  1. Sign up or sign in to github.
  2. Go to the uber top of the page and click "gist".
  3. Write your code into the file.
  4. Select the file type to match your code.
  5. Save.
  6. On the left of the page will be the embed link.
  7. Copy that link and paste it as HTML in your blog post.
That's it.

In Blogger, I don't see the Gist until I "Preview", so keep that in mind.

Wednesday, May 1, 2013

Spidermonkey Nightly [March 1st, 2013]: Windows7 VS2012

I built and packaged the dependencies for playing with spidermonkey (I think it's ionmonkey at the moment) within VS2012 on Windows 7.

I'm not sure if it's 32 or 64 but I basically built the Firefox nightly from source and then pulled out the Spidermonkey stuff for use.

Hopefully it runs for you right away! Took me a while to get it right:
https://bitbucket.org/brownw1/spidermonkey_vs2012

Thursday, April 18, 2013

Why singletons are "Bad Patterns"

I made a point for my new years resolution of 2013 to use more design patterns. I wanted to start making more conscious and judicious design decisions and to stop "slinging code".

So I started using the singleton pattern for things like caches and input in my projects.

Of course, I then find out that these convenient things are "bad practice" and that I should stop using them. I didn't really get why they are bad though until I crawled around some Stack Overflow posts on the topic.

What it boils down to is...

  1. Singletons hide dependencies
  2. Singletons make it hard to test
  3. Singletons aren't automatically cleaned up and are thus liabilities
I really do enjoy the concept of keeping things scoped so that they can just get destructed and neatly go away.

That being said, a decent "solution" to the "problem" seems to be to create your potential singleton object high up in the design hierarchy as a scoped object. Then, just have every object below it in the hierarchy that needs it receive a reference to it in their construction.

Doing that, you have a clear dependency, a scoped object, and defined initialization order (I believe that's the right way to say it?).

Maybe you could just define a base class that constructs to take reference of potential singleton resources like a cache manager or input manager. Then, the dependency would just be a way normal thing in your design.

Monday, March 4, 2013

GLFX Build with VS2012

If you get an error about a version 1600 not being 1700 when you use MSVC2012 to build a project with GLFX, then it means you need to compile GLFX for yourself.

So, here is how I did it (like 1 minute ago).


  1. Grab the glfx source.
  2. Open the vs2010 project in vs2012.
  3. In the solution, right click on the bold project "glfx".
  4. Goto "Resources".
  5. Note the project referenced, "glew_static".
  6. You'll need to get the glew source and add the project to the glfw solution, then add it as a reference.
  7. So, remove the old glew static reference inside of glfx references.
  8. Add your own, "my_glu\build\vc10\glew_static.vcxproj".
  9. Add a glfx reference to the project you just added to the solution.
  10. Your build should now work.
  11. Goto glfx/Debug (or Release if you built that?), and grab a copy of the .lib to use in your project.
Whamo, that should do it.

Wednesday, February 20, 2013

iOS Note: Panoramic Hotspots

This is just a note on some of the solutions I've implemented for features on a project we are doing at my job.

So we have a panoramic viewer on the iPad. There is an image mapped to a sphere and a camera in the center of the sphere. You can rotate around and zoom in on things.

The designers wanted the functionality to click on specifically designated areas to trigger events. For instance, touch this painting and you get info on the piece.

In the legacy code I inherited for the project( it was already roughed out in prototype ), these triggers were detected via point-radius calculations. Here is an XYZ-position, here is it's radius, do BLAH when a touch hits in that radius. This works fine to some level of accuracy but they quickly found that they needed not only more accuracy but a more flexible way for other designers on the team to author these areas without reaching into the compiled code.

So they asked me, and I said to move the problem from model space to image space. Drop the positions and distances and just work with the pixels since that's what you are interacting with anyway.

My solution was basically to modify the rendering pipeline a bit, and to add a message queue.

For the pipeline, setup framebuffer rendering so that you aren't only writing to the screen but also to an offscreen buffer. Note that this will be a framebuffer not a renderbuffer. What do we draw to this offscreen buffer? We will have the artists/designers copy the panoramic texture and draw, in solid 1 color colors (no gradients or whatnot) the areas they would like to respond to touch. They will paint on their touch areas. With rgb 255-255-255 you get around 16,000,000 colors? That's 16 million unique touch areas. Plenty.

Now you can just glReadPixels a single pixel at the touch screen position from the offscreen bufer to get the color they touched.

What I do is, on a touch, I push a "request" for a sampling into queue-A. Queue-Ais the "request mailbox", the renderer's "inbox". The renderer checks this when it's submitting render calls and if it see's any requests in it's inbox it it calls glReadPixels and puts the result into queue-B, the "response mainbox", this is the renderer's "outgoing box". The rest of the application checks this outgoing box regularly to see if anything is in it. It will take any mail from it, which will be an rgb color, and will check a table it has to see what event trigger given the color. And that is it.

The users don't see this rainbow collision map because it's drawn offscreen. You don't have to transform any coordinates because all of that is done in the shaders. The transforms are the exact same as those performed on the screen image also so the collisions match up 1-1 regardless of any zoom or w/e features you do. The designers get per-pixel accuracy. It's a solid solution (has been so far at least ).

Caveats include not working in the simulator. I believe this is because the technique is hardware accelerated and thus dependent on. well. hardware and not just simulated architecture.

Tuesday, February 19, 2013

UDK Note: Take Damage Events

<This note is intended for people who know about UDK Kismet TakeDamageEvents but can't seem to get the thing to work>...

Let's say you want to shoot a light to turn hide a light shaft, or shoot a barrel to make it explode into flames.

Right click your object to shoot, and if it's a static mesh convert it to a mover (Convert>Mover). With the object selected go to it's properties (press F4), go to Collision, set "Collision Type" to "Block All".

Now your object should get hit and the event's target should process.

Moral of the story is to make sure your static meshes are at least movers with block all collision so the take damage event triggers.

Wednesday, February 6, 2013

How To: Obj-C Set Mouse Position

Reference: http://stackoverflow.com/questions/8059667/set-the-mouse-location

Code:
 CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
  CGEventRef mouse = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, CGPointMake( X, Y), 0);
  CGEventPost(kCGHIDEventTap, mouse);
  CFRelease(mouse);
  CFRelease(source);
Include:
 #include <ApplicationServices/ApplicationServices.h>

You just set the X and Y.