terraineer SourceForge.net Logo


terraineer api

this is a brief review of everything terraineer provides. it is supposed to be used as a sort of checklist.

for more descriptive information on how to write a plugin, please see the plugin tutorial and the heavily commented plugin template.

note: javascript is sort of required to view this page. sorry for that.
TerrHost



this is the interface that the host (i.e. terraineer) comforts to. examining it lets you know what you can and what you can't do through a plugin.

public interface TerrHost{
   //menu
   MenBar:MenuBar { get; }
   MGener:Menu { get; }
   MFilter:Menu { get; }
   MCols:Menu { get; }
   //progress bar
   ProgBar:ProgressBar { get; }
   //colours and map
   Cols:array[Gdk.Color] { get; }
   HMap:Terr.Map { get; }
   //methods
   Start(nr:int):void;
   Update():void;
}


MenBar:MenuBar { get; }
terraineer's menu bar. in case you find the menus listed below inadequate you can always add another top level menu.

MGener:Menu { get; } - the "generate" menu.

MFilter:Menu { get; } - the "filter" menu.

MCols:Menu { get; } - the "colours" menu (inside the "filter" menu).

ProgBar:ProgressBar { get; }
terraineer's progress bar. you will need to use functions from PBar to make it work.

Cols:array[Gdk.Color] { get; }
colours used by terraineer to display the heightmap. you can change them at will.

HMap:Terr.Map { get; }
map used by terraineer to dsiplay the heightmap. you can change it at will. read more about Terr.Map.

Start(nr:int):void;
this needs to be run when the plugins starts. it lets terraineer know that the plugin has been activated, and which plugin it was (by nr:int; required for the "rerun plugin" functionality).

Update():void;
this needs to be run when the plugin finishes it work. it makes terraineer update the view.
TerrPlugin



this is the interface that the plugins have to comfort to.

public interface TerrPlugin{
   Host:TerrHost { set; }
   Register(nr:int):void;
   Run():void;
}


Host:TerrHost { set; } - the way to communicate with terraineer.

Register(nr:int):void;
in this method the plugin receives it's "serial number" (required by the "rerun plugin" feature) and adds itself to the terraineer's menu (see here which menus are available).

Run():void;
in this method the plugin does its job. 2 things are important here:
1. that it begins with host.Start(serial_number) and ends with host.Update();
2. that it really does all the work here (otherwise "rerun plugin" won't work for this plugin.
TerrMap


constructor: Map(sizex:int,sizey:int,tileable=false)

properties:
Item[row:int,column:int]:double - the indexer
SizeX:int - the horizontal size
SizeY:int - the vertical size

methods:
Average
DrawCircle
DrawLine
Squeeze



this is a very nice class letting you create your plugins easily. basically, it's a two-dimensional array of double. but not just an ordinary one. it's written in such a way that you can't possibly get an "array index out of range" error. there are two ways it can react to an attempt at accessing a field beyond its range:
1. (tileable=false (default)) it returns a border field as close to the called one as possible;
2. (tileable=true) it return a border field from the opposite side.

imagine the following array map=Terr.Map(5,5):
0 1 2 3 4
001234
156789
21011121314
31516171819
42021222324
now, quite naturally, map[2,3]=17, map[4,4]=24 and so on.
the tileable part works the following way:
1. (not tileable) map[-3,3]=15, map[8,17]=24;
2. (tileable) map[-3,3]=19, map[8,17]=0;
TerrMap.Average


Average(x:int,y:int,middle:bool):double
returns the average value of the 8 fields surrounding the point at (x,y), including the point itself (middle=true) or not (middle=false).
TerrMap.DrawCircle


DrawCircle(centX:int,centY:int,rad:int,col:double,overlay=false):void
draws a circle on the Terr.Map using an accelerated bresenham's algorithm (read more at gamedev).

centX:int, centY:int - the centre of the circle;
rad:int - the radius of the circle;
col:double - the colour of the circle;
overlay:bool - sets whether the values of the appropriate points in the Terr.Map are changed to (overlay=false, default) or added to col.
TerrMap.DrawLine


DrawLine(x1:int,y1:int,x2:int,y2:int,col:double,overlay=false):void
draws a line on the Terr.Map using an accelerated bresenham's algorithm (read more at gamedev).

x1:int, y1:int, x2:int, y2:int - the starting and ending points of the line; col:double - the colour of the line;
overlay:bool - sets whether the values of the appropriate points in the Terr.Map are changed to (overlay=false, default) or added to col.
TerrMap.Squeeze


Squeeze():void
squeezes the entire Terr.Map into the range from 0 to 255.
as a matter of fact, there's no real need for you to use this method. it is run by terraineer anyway, during the Update() (which you're supposed to call at the very end of your plugin's Run()).
PBar.PulseResp


PulseResp(this progBar:ProgressBar):void
an extension method to gtk#'s ProgressBar class.

it works exactly the same as Gtk.ProgressBar.Pulse() plus it ensures that the progress bar reacts. it does it by calling while (Application.EventsPending()) Application.RunIteration().
unfortunately, simply putting the same line inside the plugin doesn't work.
PBar.FractionResp


FractionResp(this progBar:ProgressBar,fract:double):void
an extension method to gtk#'s ProgressBar class.

it works exactly the same as setting Gtk.ProgressBar.Fraction to fract:double plus it ensures that the progress bar reacts. it does it by calling while (Application.EventsPending()) Application.RunIteration().
unfortunately, simply putting the same line inside the plugin doesn't work.
PBar.FractionAddResp


FractionAddResp(this progBar:ProgressBar,fract:double):void
an extension method to gtk#'s ProgressBar class.

it works exactly the same as adding fract:double to Gtk.ProgressBar.Fraction plus it ensures that the progress bar reacts. it does it by calling while (Application.EventsPending()) Application.RunIteration().
unfortunately, simply putting the same line inside the plugin doesn't work.

konqueror  valid xhtml  valid css  nemerle  opensource  gpl