Difference between revisions of "Functions"

From The Powder Toy
Jump to: navigation, search
m (1 revision)
m (Added the languages box.)
 
(20 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This is list of functions with their variables, every function is described. There is recommended to read article [[Hotkeys]], it's helpful to understand description of some functions.
+
{{Languages|Functions}}
 +
When you are modding TPT++ and come to writing the update routine, there are a few functions you will need to use. A reference of those is shown below.  
  
'''''clear_area(int area_x, int area_y, int area_w, int area_h)''''' - (like CTRL-Erase) Clears the area with height '''h''' and width '''w'''.  ('''x''','''y''') is the top left corner.
+
; sim->create_part(int p, int x, int y, int t);
 +
: What it does: Creates a particle at a given coordinate.
 +
: '''int p''' - How the particle is created. -1 means from the code (will only create a particle if the space is empty). This is the normal way to create a particle, -2 is from the brush (don't use this), -3 means it will ignore any particles in the space and draw it anyway, and any positive number will override the particle at that index with this newly created particle.
 +
: '''int x''' - Particle's x coordinate
 +
: '''int y''' - Particle's y coordinate
 +
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
  
'''''create_part(int p, int x, int y, int t)''''' - Creates particle which type is '''t''' at ['''x''','''y''']. For '''p''' use -1.
+
; sim->kill_part(int i) - Deletes particle with index i
 +
: What it does: Deletes a particle without the given x and y, using its index instead.
 +
: '''int i''' - The particle's index. Passed into the function as 'i'.
  
'''''create_box(int x1, int y1, int x2, int y2, int c)''''' - Creates rectangle (like CTRL in PT).
+
; sim->delete_part(int x, int y, int flags);
'''''x1''''', '''''y1''''' is first corner position, '''''x2''''','''''y2''''' is second corner position, '''c''' is particle type.
+
: What it does: Deletes a particle at location (x, y)
 +
: '''int x''' - Particle's x coordinate
 +
: '''int y''' - Particle's y coordinate
 +
: '''int flags''' - Un-useful value, leave it as 0
  
'''''create_line(int x1, int y1, int x2, int y2, int r, int c)''''' - Like '''''create_box''''', but '''''x1''''','''''y1''''','''''x2''''','''''y2''''' are line ends position.
+
; sim->part_change_type(int i, int x, int y, int t);
 +
: What it does: Changes type of particle i. Do not manually set parts[].type, use this function instead.
 +
: '''int i''' - The particle's index.
 +
: '''int x''' - Particle's x coordinate. Pass in parts[i].x here.
 +
: '''int y''' - Particle's y coordinate. Pass in parts[i].y here.
 +
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.
  
'''''delete_part(int x, int y)''''' - Deletes part at defined position.
+
; sim->clear_area(int x, int y, int w, int h);
 +
: What it does: Clears a rectangle with specified height and width.
 +
: '''int x''' - Top left corner's x coordinate (from left towards the right)
 +
: '''int y''' - Top left corner's y coordinate (from top downwards!)
 +
: '''int w''' - The width of the rectangle
 +
: '''int h''' - The height of the rectangle
  
'''''flood_parts(int x, int y, int c, int cm, int bm)''''' - Flood fill. ('''''x''''','''''y''''') is the location to start the fill. '''''c''''' is the particle type to fill(not the particle itself but the number ex. PT_DUST). set '''''cm''''' and '''''bm''''' to -1.
+
; sim->CreateBox(int x1, int y1, int x2, int y2, int t, int flags)
 +
: What it does:  Utility function, creates a rectangle of a given particle.
 +
: For some reason, this uses a different way to specify a rectangle than the deleting equivalent.
 +
: '''int x1''' - Top left corner's x coordinate
 +
: '''int y1''' - Top right corner's y coordinate
 +
: '''int x2''' - Bottom left corner's x coordinate (note: not the box's width!)
 +
: '''int y2''' - Bottom left corner's y coordinate (see note above)
 +
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.
 +
: '''int flags''' - Un-useful value, leave it as 0
  
'''''kill_part(int i)''''' - Deletes particle '''''i'''''.(Does not use x,y location like delete_part)
+
; sim->CreateLine(int x1, int y1, int x2, int y2, int c)
 +
: What it does: Draws a single pixel line of a specified element from two points.
 +
: '''int x1''' - Line start's x coordinate.
 +
: '''int y1''' - Line start's y coordinate.
 +
: '''int x2''' - Line end's x coordinate.
 +
: '''int y2''' - Line end's y coordinate.
 +
: '''int c''' - Particle's type. Use a pre-defined value, such as PT_INST.
  
'''''nearest_part(int ci,int t)''''' - Returns nearest particle of type '''''t'''''. '''''ci''''' is current particle.
+
; sim->FloodParts(int x, int y, int t, int cm, int bm, int flags);
 +
: What it does: Starts a flood-fill from a point. (like ctrl+shift+clicking in TPT)
 +
: '''int x''' - Particle's x coordinate
 +
: '''int y''' - Particle's y coordinate
 +
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.
 +
: '''int cm''' - used by recursion in the code, leave it as -1
 +
: '''int bm''' - used by recursion in the code, leave it as -1
 +
: '''int flags''' - Un-useful value, leave it as 0
  
'''''parts_avg(int ci, int ni)''''' - Returns the part in between the particles '''''ci''''' and '''''ni'''''.
+
; sim->flood_prop(int x, int y, size_t propoffset, PropertyValue propvalue, <nowiki>StructProperty::PropertyType</nowiki> proptype);
 +
: What it does: Sets a property via flood-fill. (Like PROP)
 +
: '''int x''' - Particle's x coordinate
 +
: '''int y''' - Particle's y coordinate
 +
: '''size_t propoffset''' - This is a value returned by the function <tt>offsetof(Particle, <property>)</tt>.
 +
: Replace <property> with what you want, for example <tt>tmp</tt> or <tt>ctype</tt>.
 +
: '''PropertyValue  propvalue''' - A c++ union, which holds the property you want to set. You may declare <tt>PropertyValue value;</tt>, then do <tt>value.Integer = 2;</tt> in order to use this. The other two properties you can set are .Float (if setting temperature or veloticy) and .UInteger (if setting decoration color)
 +
: '''StructProperty::PropertyType proptype''' - What kind of type the value you provided is.  
 +
: For example, if you had a temperature number (as an integer), then you could use <tt>StructProperty::Integer</tt>.
 +
: The types are: <tt>StructProperty::Integer</tt>, <tt>StructProperty::Float</tt> and <tt>StructProperty::Uinteger</tt>
  
'''''part_change_type(int i, int x, int y, int t)''''' - Changes type of particle '''''i'''''. '''''t''''' is new type, '''''x''''' is the x location of the particle, '''''y''''' is the y location of the particle.
+
; sim->parts_avg(int i, int ni, int t);
 +
: What it does: Checks if an element of type t is inbetween the two particles specified as indexes.
 +
: '''int i''' - The (first) particle's index. Passed into the function as 'i'.
 +
: '''int ni''' - The other particle's index.
 +
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.
 +
: It will actually only check the location directly in the middle
 +
: Returns: 0 if there isn't an element of type t in between the two, 1 if there is.
 +
 
 +
[[Category:Development]]

Latest revision as of 01:46, 27 March 2019

Language: English  • polski

When you are modding TPT++ and come to writing the update routine, there are a few functions you will need to use. A reference of those is shown below.

sim->create_part(int p, int x, int y, int t);
What it does: Creates a particle at a given coordinate.
int p - How the particle is created. -1 means from the code (will only create a particle if the space is empty). This is the normal way to create a particle, -2 is from the brush (don't use this), -3 means it will ignore any particles in the space and draw it anyway, and any positive number will override the particle at that index with this newly created particle.
int x - Particle's x coordinate
int y - Particle's y coordinate
int t - Particle's type. Use a pre-defined value, such as PT_INST.
sim->kill_part(int i) - Deletes particle with index i
What it does: Deletes a particle without the given x and y, using its index instead.
int i - The particle's index. Passed into the function as 'i'.
sim->delete_part(int x, int y, int flags);
What it does: Deletes a particle at location (x, y)
int x - Particle's x coordinate
int y - Particle's y coordinate
int flags - Un-useful value, leave it as 0
sim->part_change_type(int i, int x, int y, int t);
What it does: Changes type of particle i. Do not manually set parts[].type, use this function instead.
int i - The particle's index.
int x - Particle's x coordinate. Pass in parts[i].x here.
int y - Particle's y coordinate. Pass in parts[i].y here.
int t - Particle's type. Use a pre-defined value, such as PT_INST.
sim->clear_area(int x, int y, int w, int h);
What it does: Clears a rectangle with specified height and width.
int x - Top left corner's x coordinate (from left towards the right)
int y - Top left corner's y coordinate (from top downwards!)
int w - The width of the rectangle
int h - The height of the rectangle
sim->CreateBox(int x1, int y1, int x2, int y2, int t, int flags)
What it does: Utility function, creates a rectangle of a given particle.
For some reason, this uses a different way to specify a rectangle than the deleting equivalent.
int x1 - Top left corner's x coordinate
int y1 - Top right corner's y coordinate
int x2 - Bottom left corner's x coordinate (note: not the box's width!)
int y2 - Bottom left corner's y coordinate (see note above)
int t - Particle's type. Use a pre-defined value, such as PT_INST.
int flags - Un-useful value, leave it as 0
sim->CreateLine(int x1, int y1, int x2, int y2, int c)
What it does: Draws a single pixel line of a specified element from two points.
int x1 - Line start's x coordinate.
int y1 - Line start's y coordinate.
int x2 - Line end's x coordinate.
int y2 - Line end's y coordinate.
int c - Particle's type. Use a pre-defined value, such as PT_INST.
sim->FloodParts(int x, int y, int t, int cm, int bm, int flags);
What it does: Starts a flood-fill from a point. (like ctrl+shift+clicking in TPT)
int x - Particle's x coordinate
int y - Particle's y coordinate
int t - Particle's type. Use a pre-defined value, such as PT_INST.
int cm - used by recursion in the code, leave it as -1
int bm - used by recursion in the code, leave it as -1
int flags - Un-useful value, leave it as 0
sim->flood_prop(int x, int y, size_t propoffset, PropertyValue propvalue, StructProperty::PropertyType proptype);
What it does: Sets a property via flood-fill. (Like PROP)
int x - Particle's x coordinate
int y - Particle's y coordinate
size_t propoffset - This is a value returned by the function offsetof(Particle, <property>).
Replace <property> with what you want, for example tmp or ctype.
PropertyValue propvalue - A c++ union, which holds the property you want to set. You may declare PropertyValue value;, then do value.Integer = 2; in order to use this. The other two properties you can set are .Float (if setting temperature or veloticy) and .UInteger (if setting decoration color)
StructProperty::PropertyType proptype - What kind of type the value you provided is.
For example, if you had a temperature number (as an integer), then you could use StructProperty::Integer.
The types are: StructProperty::Integer, StructProperty::Float and StructProperty::Uinteger
sim->parts_avg(int i, int ni, int t);
What it does: Checks if an element of type t is inbetween the two particles specified as indexes.
int i - The (first) particle's index. Passed into the function as 'i'.
int ni - The other particle's index.
int t - Particle's type. Use a pre-defined value, such as PT_INST.
It will actually only check the location directly in the middle
Returns: 0 if there isn't an element of type t in between the two, 1 if there is.