I'm working on a little light casting algorithm for my 4k entry (yes, starting early ).

These rays (actually just bounds of a 2d light cone [sector]) are being projected through a mesh of triangles.

When the ray hits an edge, it either drops a clip vertex & moves along the edge, or it passes into the next triangle.This is all done through a neat recursive algorithm to minimize code size.

When passing into the next triangle, it passes with it knowledge (the index) of the edge from which it entered.Thus each triangle will be just a single intersection "enters from edge0; does it intersect edge1? no. Must intersect edge2 then."

This is an optimization over my previous O(n) intersection tests when using convex polygons; though the reasons for my optimization are code size motivated, not performance.

Anyhow, this is all entirely besides the point.My question is quite trivial really; I'm struggling to think of a 'code size optimal' way of alternating between the values 0, 1 & 2 using just 2 operations.e.g.

If:entering from edge '0', I want to check edge '1' or '2' for collision and use the other if appropriate.entering from edge '1', I want to check edge '0' or '2' for collision and use the other if appropriate.entering from edge '2', I want to check edge '0' or '1' for collision and use the other if appropriate.

Doing "(x+1)%3" twice works of course, but that's 2*2 operations and was hoping for something a little smaller/smarter.

- The operations could work off the initial input, or the result of the first op.e.g.input -OP1-> output1 -OP2-> output2orinput -OP1-> output1input -OP2-> output2

- OP1 and OP2 do not have to be the same operation (though extra points if they are!).

I suppose it is marginally better as it's the same operand being pushed onto the stack, so might compress a little better.Though by that logic, chaining 2 invocations of (x+1)%3 will probably be just as good.

I should probably stop thinking about this; it's a horrible distraction.

Abuse's is likely to be best unless the REP of the compression wins out. Otherwise option that comes to mind is to put the four data values at the start of data or state array and do the array lookup. Test these combos at the end is my suggestion.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org