Difference between revisions of "Functions"

From The Powder Toy
Jump to: navigation, search
m (Fixed formatting on StructProperty::PropertyType)
m (fix some info)
Line 5: Line 5:
 
: '''int x''' - Top left corner's x coordinate (from left towards the right)
 
: '''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 y''' - Top left corner's y coordinate (from top downwards!)
: '''int w''' - The width of the rectangle (towards the right)
+
: '''int w''' - The width of the rectangle
: '''int h''' - The height of the rectangle (downward)
+
: '''int h''' - The height of the rectangle
  
 
; sim->create_part(int p, int x, int y, int t);
 
; sim->create_part(int p, int x, int y, int t);
 
: What it does: Creates a particle at a given coordinate.
 
: What it does: Creates a particle at a given coordinate.
: '''int p''' - Unknown variable, best bet is to use -1 as its value for now.
+
: '''int p''' - How the particle is created. -1 means from the code, -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 overrite the particle at that index with this newly created particle.
 
: '''int x''' - Particle's x coordinate
 
: '''int x''' - Particle's x coordinate
 
: '''int y''' - Particle's y coordinate
 
: '''int y''' - Particle's y coordinate
Line 34: Line 34:
 
: '''int rx''' - The line's X radius
 
: '''int rx''' - The line's X radius
 
: '''int ry''' - The line's Y radius
 
: '''int ry''' - The line's Y radius
: Note: The function creates a Brush which is actually an oval with the specified X and Y radiuses.  
+
: Note: The function creates a Brush which is actually an oval with the specified X and Y radiuses.
 
: That's why those are needed.
 
: That's why those are needed.
 
: For a single pixel wide line, use 1 for both of the values.  
 
: For a single pixel wide line, use 1 for both of the values.  
Line 51: Line 51:
 
: '''int y''' - Particle's y coordinate
 
: '''int y''' - Particle's y coordinate
 
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
 
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
: '''int cm''' - Un-useful value, leave it as -1
+
: '''int cm''' - used by recursion in the code, leave it as -1
: '''int bm''' - Un-useful value, 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
 
: '''int flags''' - Un-useful value, leave it as 0
  
Line 68: Line 68:
  
 
; sim->kill_part(int i) - Deletes particle 'with index ''''i.(Does not use x,y location like delete_part)
 
; sim->kill_part(int i) - Deletes particle 'with index ''''i.(Does not use x,y location like delete_part)
: What it does: Deletes a particle without the given x and y, using its index instead.  
+
: 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'.
 
: '''int i''' - The particle's index. Passed into the function as 'i'.
  
Line 75: Line 75:
 
: '''int i''' - The particle's index. Passed into the function as 'i'.
 
: '''int i''' - The particle's index. Passed into the function as 'i'.
 
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
 
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
: '''int max_d''' - The maximum distance to look from. Set as -1 if you want it to be unlimited.  
+
: '''int max_d''' - The maximum distance to look from. Set as -1 if you want it to be unlimited.
: Returns: -1 if not found; particle index if found.  
+
: Returns: -1 if not found; particle index if found.
  
 
; sim->parts_avg(int i, int ni, int t);
 
; 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.
 
: 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 i''' - The (first) particle's index. Passed into the function as 'i'.
: '''int ni''' - The other particle's index.
+
: '''int ni''' - The other particle's index.
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.  
+
: '''int t''' - Particle's type. Use a pre-defined value, such as PT_INST.
: You can imagine it as this: a straight line is drawn from one particle to another, and any particle on that line will
+
: It will actually only check the location directly in the middle
be checked for whether it is of your specified type.
+
: Returns: 0 if there isn't an element of type t in between the two, 1 if there is.
: Returns: 0 if there isn't an element of type t inbetween the two, 1 if there is.  
 
  
 
; sim->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->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.

Revision as of 13:50, 16 April 2013

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->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->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, -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 overrite 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->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 rx, int ry, int c, int flags)
What it does: Draws a line of a specified element from two points. (The equivalent of Shift+drag)
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 rx - The line's X radius
int ry - The line's Y radius
Note: The function creates a Brush which is actually an oval with the specified X and Y radiuses.
That's why those are needed.
For a single pixel wide line, use 1 for both of the values.
int t - Particle's type. Use a pre-defined value, such as PT_INST.
int flags - Un-useful value, leave it as 0
sim->delete_part(int x, int y, int flags);
What it does: Deletes a particle (removes all the values associated it!)
int x - Particle's x coordinate
int y - Particle's y coordinate
int flags - Un-useful value, leave it as 0
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, void * 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.
void * propvalue - A reference to your property's value. One needs to define the value beforehand.
For example, when you've defined int temperature = 200;, then you should use &temperature.
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->kill_part(int i) - Deletes particle 'with index 'i.(Does not use x,y location like delete_part)
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->nearest_part(int i,int t, int max_d);
What it does: Finds the nearest particle of a certain type.
int i - The particle's index. Passed into the function as 'i'.
int t - Particle's type. Use a pre-defined value, such as PT_INST.
int max_d - The maximum distance to look from. Set as -1 if you want it to be unlimited.
Returns: -1 if not found; particle index if found.
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.
sim->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.