Difference between revisions of "Variables"

From The Powder Toy
Jump to: navigation, search
m (1 revision)
(Replace pavg with tmp3/tmp4)
 
(27 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 +
{{Languages|Variables}}
 
This is a list of useful variables and usages of them inside the source.
 
This is a list of useful variables and usages of them inside the source.
  
  
  
^ General ^^
+
=== General ===
^ Variable ^ What it returns ^
+
{| class="wikitable"
| pmap[y][x] | Particle-map. Returns particle at [y][x] |
+
! Variable || What it returns
| bmap[y][x] | Block-map. Returns wall at [y][x]. |
+
|-
| emap[y][x] | Electronics-map. Used for conductive walls. |
+
| pmap[y][x] || Particle-map. TYP(pmap[y][x]) returns the particle type at (x,y), ID(pmap[y][x]) returns the index of the particle at (x,y). Energy particles are not stored in, here you need to use photons.
| r | usually preset to pmap[y][x] |
+
|-
| pv[y/CELL][x/CELL] | The pressure at x,y. Pressure is on a 4x4 grid like walls. Is a float(0.0f for 0). |
+
| sim->photons[y][x] || Photon-map. This works exactly like pmap, but only PHOT, NEUT, ELEC, and PROT are stored here (any particle with TYPE_ENERGY)
| hv[y/CELL][x/CELL] | The ambient heat at x,y. It is on a 4x4 grid like walls and pressure. Is a float(0.0f for 0). |
+
|-
| sl | Selected left. Means particle selected in menu by left mouse button. |
+
| sim->bmap[y][x] || Block-map. Returns wall at [y][x]. Wall constants are defined in src/simulation/SimulationData.h
| sr | Selected right. Means particle selected in menu by right mouse button. |
+
|-
| t | Current particle type. ex. PT_DUST |
+
| sim->emap[y][x] || Electronics-map. Used for conductive walls. If it is 1, that means the wall at that location is conducting.
^ Particle ^^
+
|-
^ Variable ^ What it returns ^
+
| r || usually preset to pmap[y][x]
| parts[i].<sup>1</sup> | Current Particle |
+
|-
| parts[r>>8].<sup>1</sup> | A property of particle 'r'. Is usually around(based on for loops) the current one(i). |
+
| parts[i] || the particle that has index i
| (r&0xFF) | Same as (parts[r>>8].type) |
+
|-
^ Particle Information ^^
+
| sim->pv[y/CELL][x/CELL] || The pressure at x,y. Pressure is on a 4x4 grid like walls. Is a float(0.0f for 0).
^ Variable ^ What it returns ^
+
|-
| parts[<sup>2</sup>].type | Contains the particles current type. |
+
| sim->vx[y/CELL][x/CELL] || The air velocity in the x direction at x,y. Uses a 4x4 grid like walls. Is a float(0.0f for 0).
| parts[<sup>2</sup>].ctype | Contains the particles previous type (for example LAVA) or the type of particle to clone with BCLN, PCLN or CLNE |
+
|-
| parts[<sup>2</sup>].life | Contains the particles life. |  
+
| sim->vy[y/CELL][x/CELL] || The air velocity in the y direction at x,y. Uses a 4x4 grid like walls. Is a float(0.0f for 0).
| parts[<sup>2</sup>].temp | Contains the particles Temperature. Is a float(0.0f for 0). |
+
|-
| parts[<sup>2</sup>].tmp | Contains the particles temporary values which can be used for anything. |
+
| sim->hv[y/CELL][x/CELL] || The ambient heat at x,y. It is on a 4x4 grid like walls and pressure. Is a float(0.0f for 0).
^^^
+
|-
 +
| t || Current particle type in some places. ex. PT_DUST
 +
|}
  
|<sup>1</sup> - use either type, ctype, life, temp or tmp||
+
=== Particle ===
 +
To get information from a particle, use parts[i].<sup>1</sup>, where i is the particle index. The index may also be stored as ID(r) instead of i. This is normally used in the update functions for particles. i is the index of the particle that is being updated, and ID(r) is the index of a particle surrounding it that it might react with or modify. To get the type of the particle from the variable r, use TYP(r).
  
|<sup>2</sup> - use either r>>8 or i||
+
=== Particle Information ===
 +
{| class="wikitable"
 +
! Variable || What it returns
 +
|-
 +
| parts[<sup>2</sup>].type || Contains the particle's current type.
 +
|-
 +
| parts[<sup>2</sup>].life || Contains the particle's life.
 +
|-
 +
| parts[<sup>2</sup>].ctype || Contains the particle's previous type (for example LAVA/SPRK) or the type of particle it is cloning (CLNE/...) usually.
 +
|-
 +
| parts[<sup>2</sup>].x || Contains the particle's x coordinate. It is not an integer, it's a float. To get the exact coordinate, add .5 to it before changing it to an int.
 +
|-
 +
| parts[<sup>2</sup>].y || Contains the particle's y coordinate. It is not an integer, it's a float. To get the exact coordinate, add .5 to it before changing it to an int.
 +
|-
 +
| parts[<sup>2</sup>].vx || Contains the particle's x velocity. It is a float.
 +
|-
 +
| parts[<sup>2</sup>].vy || Contains the particle's y velocity. It is a float
 +
|-
 +
| parts[<sup>2</sup>].temp || Contains the particle's temperature. It's a float(0.0f for 0K, which is -273.15C). All temps are stored in Kelvins.
 +
|-
 +
|  parts[<sup>2</sup>].flags || Rarely used; doesn't save.
 +
|-
 +
| parts[<sup>2</sup>].tmp || Contains a value which can be used for anything.
 +
|-
 +
| parts[<sup>2</sup>].tmp2 || Contains another value.
 +
|-
 +
| parts[<sup>2</sup>].dcolour || Contains the particle's decoration color, 32bit ARGB
 +
|-
 +
| parts[<sup>2</sup>].tmp3 || Used for elements that break under pressure or storing properties of particles inside PIPE/VIRS/STOR
 +
|-
 +
| parts[<sup>2</sup>].tmp4 || Used for storing properties of particles inside PIPE/VIRS/STOR
 +
|}
 +
 
 +
<sup>1</sup> - use type, ctype, life, temp, tmp, etc.
 +
 
 +
<sup>2</sup> - use either ID(r) or i. See above (Particle) for more info.
 +
 
 +
[[Category:Development]]

Latest revision as of 01:12, 30 December 2022

Language: English  • 한국어 • polski • русский

This is a list of useful variables and usages of them inside the source.


General

Variable What it returns
pmap[y][x] Particle-map. TYP(pmap[y][x]) returns the particle type at (x,y), ID(pmap[y][x]) returns the index of the particle at (x,y). Energy particles are not stored in, here you need to use photons.
sim->photons[y][x] Photon-map. This works exactly like pmap, but only PHOT, NEUT, ELEC, and PROT are stored here (any particle with TYPE_ENERGY)
sim->bmap[y][x] Block-map. Returns wall at [y][x]. Wall constants are defined in src/simulation/SimulationData.h
sim->emap[y][x] Electronics-map. Used for conductive walls. If it is 1, that means the wall at that location is conducting.
r usually preset to pmap[y][x]
parts[i] the particle that has index i
sim->pv[y/CELL][x/CELL] The pressure at x,y. Pressure is on a 4x4 grid like walls. Is a float(0.0f for 0).
sim->vx[y/CELL][x/CELL] The air velocity in the x direction at x,y. Uses a 4x4 grid like walls. Is a float(0.0f for 0).
sim->vy[y/CELL][x/CELL] The air velocity in the y direction at x,y. Uses a 4x4 grid like walls. Is a float(0.0f for 0).
sim->hv[y/CELL][x/CELL] The ambient heat at x,y. It is on a 4x4 grid like walls and pressure. Is a float(0.0f for 0).
t Current particle type in some places. ex. PT_DUST

Particle

To get information from a particle, use parts[i].1, where i is the particle index. The index may also be stored as ID(r) instead of i. This is normally used in the update functions for particles. i is the index of the particle that is being updated, and ID(r) is the index of a particle surrounding it that it might react with or modify. To get the type of the particle from the variable r, use TYP(r).

Particle Information

Variable What it returns
parts[2].type Contains the particle's current type.
parts[2].life Contains the particle's life.
parts[2].ctype Contains the particle's previous type (for example LAVA/SPRK) or the type of particle it is cloning (CLNE/...) usually.
parts[2].x Contains the particle's x coordinate. It is not an integer, it's a float. To get the exact coordinate, add .5 to it before changing it to an int.
parts[2].y Contains the particle's y coordinate. It is not an integer, it's a float. To get the exact coordinate, add .5 to it before changing it to an int.
parts[2].vx Contains the particle's x velocity. It is a float.
parts[2].vy Contains the particle's y velocity. It is a float
parts[2].temp Contains the particle's temperature. It's a float(0.0f for 0K, which is -273.15C). All temps are stored in Kelvins.
parts[2].flags Rarely used; doesn't save.
parts[2].tmp Contains a value which can be used for anything.
parts[2].tmp2 Contains another value.
parts[2].dcolour Contains the particle's decoration color, 32bit ARGB
parts[2].tmp3 Used for elements that break under pressure or storing properties of particles inside PIPE/VIRS/STOR
parts[2].tmp4 Used for storing properties of particles inside PIPE/VIRS/STOR

1 - use type, ctype, life, temp, tmp, etc.

2 - use either ID(r) or i. See above (Particle) for more info.