[Bf-committers] Code optimisation
Ton Roosendaal
bf-committers@blender.org
Fri, 23 Apr 2004 11:01:38 +0200
Hi,
I can understand the code change proposal. Not for speed reasons
though, in this button drawing code you won't notice that. More of a
point here is that the developer (broken) uses a style he considers
more readable (and maybe because of inexperience :).
You can see the same 'math' in the buttons he recoded for the
infowindow, in space.c.
In cases like this, I prefer to leave it that way, since it's more
important to have a single (enthusiast) maintainer for code who
understands it, and keeps it working. Allowing everyone to just change
parts because its 'better' for some reason, we won't improve
development really.
My priority would be rewarding responsibility more than enforcing 'good
coding' standards.
-Ton-
On Thursday, Apr 22, 2004, at 23:57 Europe/Amsterdam, Kenneth Styrberg
wrote:
> Hi, I did some optimisation in interface_draw.c. I havn't tested how
> much it improves performance, at least the code looks a tiny winy bit
> cleaner. Maybe all compilers do this optimisation at compile time?
>
> //styken
>
>
> RCS file:
> /cvsroot/bf-blender/blender/source/blender/src/interface_draw.c,v
> retrieving revision 1.14
> diff -u -r1.14 interface_draw.c
> --- interface_draw.c 28 Jan 2004 12:16:05 -0000 1.14
> +++ interface_draw.c 22 Apr 2004 21:55:45 -0000
> @@ -228,7 +228,8 @@
> * an alignment group or not. 0 = not middle, 1 = is in the middle.
> * Done to allow cleaner drawing
> */
> - + + float temp = y2 - (y2 - y1) / 3.0;
> /* *** SHADED BUTTON BASE *** */
> glShadeModel(GL_SMOOTH);
> glBegin(GL_QUADS);
> @@ -252,8 +253,8 @@
> else M_LIGHT;
> }
> - glVertex2f(x2,(y2-(y2-y1)/3));
> - glVertex2f(x1,(y2-(y2-y1)/3));
> + glVertex2f(x2,temp);
> + glVertex2f(x1,temp);
> glEnd();
> @@ -268,8 +269,8 @@
> else M_LIGHT;
> }
> - glVertex2f(x1,(y2-(y2-y1)/3));
> - glVertex2f(x2,(y2-(y2-y1)/3));
> + glVertex2f(x1, temp);
> + glVertex2f(x2, temp);
> glVertex2f(x2,y2);
> glVertex2f(x1,y2);
> @@ -390,21 +391,23 @@
> /* small side double arrow for iconrow */
> static void ui_default_iconrow_arrows(float x1, float y1, float x2,
> float y2)
> {
> + short temp = (short)(y2 - (y2 - y1) / 2.0);
> +
> glEnable( GL_POLYGON_SMOOTH );
> glEnable( GL_BLEND );
> glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
> glShadeModel(GL_FLAT);
> glBegin(GL_TRIANGLES);
> - glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2)+1);
> - glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2)+1);
> - glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2)+4);
> + glVertex2f((short)x2-2, temp + 1);
> + glVertex2f((short)x2-6, temp + 1);
> + glVertex2f((short)x2-4, temp + 4);
> glEnd();
> glBegin(GL_TRIANGLES);
> - glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2) -1);
> - glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2) -1);
> - glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2) -4);
> + glVertex2f((short)x2-2, temp - 1);
> + glVertex2f((short)x2-6, temp - 1);
> + glVertex2f((short)x2-4, temp - 4);
> glEnd();
> glDisable( GL_BLEND );
> @@ -438,6 +441,8 @@
> /* left/right arrows for number fields */
> static void ui_default_num_arrows(float x1, float y1, float x2, float
> y2)
> {
> + short temp = (short)(y2 - (y2 - y1) / 2.0);
> +
> glEnable( GL_POLYGON_SMOOTH );
> glEnable( GL_BLEND );
> glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
> @@ -445,18 +450,18 @@
> glShadeModel(GL_FLAT);
> glBegin(GL_TRIANGLES);
> - glVertex2f((short)x1+5,(short)(y2-(y2-y1)/2));
> - glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)+4);
> - glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)-4);
> + glVertex2f((short)x1 + 5, temp);
> + glVertex2f((short)x1 + 10, temp + 4);
> + glVertex2f((short)x1 + 10, temp - 4);
> glEnd();
> /* right */
> glShadeModel(GL_FLAT);
> glBegin(GL_TRIANGLES);
> - glVertex2f((short)x2-5,(short)(y2-(y2-y1)/2));
> - glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)-4);
> - glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)+4);
> + glVertex2f((short)x2 - 5, temp);
> + glVertex2f((short)x2 - 10, temp - 4);
> + glVertex2f((short)x2 - 10, temp + 4);
> glEnd();
> glDisable( GL_BLEND );
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers@blender.org
> http://www.blender.org/mailman/listinfo/bf-committers
>
>
------------------------------------------------------------------------
--
Ton Roosendaal Blender Foundation ton@blender.org
http://www.blender.org