# [erlang-questions] A function as an element of a list of action

Micheus <>
Mon Jan 28 20:55:18 CET 2013

```Thanks Jesper and Erik by your comments.

I'll give you more details about what I trying to do, but I believe that
the suggestion here will help me. :)

I'm coding a "terrain" maker for Wings3d (heightmap plugin). There are some
parameters in the form that will result in many different calculations. You
can see them in this picture: http://imageshack.us/f/820/density100.png/
As the list of vertices can be ~147K, I would like to minimize the calcs by
fragmenting the code.
If the density is changed, then the entire parameters (vertices and faces)
need to be recalculated. But if the used just decide to create or not the
side faces then I don't need to calculate everything again.

What I thought was to check for every field (parameter) in the form and
build an list of what I need to recalculate. I used to store in a
{key,data} format because some operations (function to be called) will be
repeated for different parameters, but - at the end - it would exists only
once in the list.

I've it implemented this way:

:
case changed_field(Old_Res,Res) of
{bf, _} ->
VsBottom0=create_normalized_bottom(W,H,What,VsTop),
FsBottom0=create_faces_bottom(W,H,What),
FsSide0=create_faces_side(W,H,What),
He0=create_hard_edges(W,H,What,HardEdges),
{{VsTop,VsBottom0},{FsTop,FsBottom0,FsSide0},He0};
{sf, _} ->
VsBottom0=create_normalized_bottom(W,H,What,VsTop),
FsBottom0=create_faces_bottom(W,H,What),
FsSide0=create_faces_side(W,H,What),
He0=create_hard_edges(W,H,What,HardEdges),
{{VsTop,VsBottom0},{FsTop,FsBottom0,FsSide0},He0};
{gv, _} ->
VsTop0=set_ground(CLo,VsTop),
{{VsTop0,VsBottom},{FsTop,FsBottom,FsSide},He};
{he, Value} ->
He0=create_hard_edges(W,H,What,Value),
{{VsTop,VsBottom},{FsTop,FsBottom,FsSide},He0};
{Fld, _} when Fld=:=density; Fld=:=ih; Fld=:=iw->
process_surface(Res);
{Fld, _} when Fld=:=scut_lo; Fld=:=scut_hi; Fld=:=es; Fld=:=hs;
Fld=:=ws; Fld=:=ar ->
Els=wings_pref:get_value(heightmap_elevation),
VsTop3=create_normalized_top(W,H,Els),
VsBottom1=create_normalized_bottom(W,H,What,VsTop3),
VsTop2=set_ground(CLo,VsTop3),
VsTop1=cut(CLo,CHi,VsTop2),
{VsTop0,VsBottom0}=scale(Wm,Em,Hm,{VsTop1,VsBottom1}),
{{VsTop0,VsBottom0},{FsTop,FsBottom,FsSide},He};
_ ->
Old_Data
end.
:

it's supposing that there is only one field being changed each time it is
processed, but it should check for a list. So, that "case" should be in a
lists:foreach and the code that has being ran for each option should be
processed only after I build this list of function I'm looking for.

I hope I could clarify about what I'm trying to do. (English is not my
first language)

/Micheus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130128/dd51b980/attachment.html>
```