No life

  • GreenFireDragon
    20th Apr 2013 Member 0 Permalink

    I made a new element POSP(https://powdertoy.co.uk/Discussions/Thread/View.html?Thread=16558).

    When I draw in pause it works, bu if I unpause it disappears.

    This is the code:

     

    #include "simulation/Elements.h"
    //#TPT-Directive ElementClass Element_POSP PT_POSP 170
    Element_POSP::Element_POSP()
    {
    Identifier = "DEFAULT_PT_POSP";
    Name = "POSP";
    Colour = PIXPACK(0xDC143C);
    MenuVisible = 1;
    MenuSection = SC_GAS;
    Enabled = 1;

    Advection = 0.9f;
    AirDrag = 0.04f * CFDS;
    AirLoss = 0.97f;
    Loss = 0.20f;
    Collision = 0.0f;
    Gravity = -0.1f;
    Diffusion = 0.30f;
    HotAir = 0.001f * CFDS;
    Falldown = 0;

    Flammable = 0;
    Explosive = 0;
    Meltable = 0;
    Hardness = 0;

    Weight = 1;

    Temperature = 10000.0f +273.15f;
    HeatConduct = 5;
    Description = "Positive plasma.";

    State = ST_NONE;
    Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL;

    LowPressure = IPL;
    LowPressureTransition = NT;
    HighPressure = IPH;
    HighPressureTransition = NT;
    LowTemperature = ITL;
    LowTemperatureTransition = NT;
    HighTemperature = ITH;
    HighTemperatureTransition = NT;

    Graphics = &Element_POSP::graphics;
    }

    //#TPT-Directive ElementHeader Element_POSP static int graphics(GRAPHICS_FUNC_ARGS)
    int Element_POSP::graphics(GRAPHICS_FUNC_ARGS)

    {
    int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
    *colr = (unsigned char)ren->plasma_data[caddress];
    *colg = (unsigned char)ren->plasma_data[caddress+1];
    *colb = (unsigned char)ren->plasma_data[caddress+2];

    *firea = 255;
    *firer = *colr;
    *fireg = *colg;
    *fireb = *colb;

    *pixel_mode = PMODE_GLOW | PMODE_ADD; //Clear default, don't draw pixel
    *pixel_mode |= FIRE_ADD;
    //Returning 0 means dynamic, do not cache
    return 0;
    }

    Element_POSP::~Element_POSP() {}

  • GreenFireDragon
    22nd Apr 2013 Member 0 Permalink

    bump

  • boxmein
    22nd Apr 2013 Former Staff 0 Permalink
    PROP_LIFE_KILL means it'll die when it's at life 0...
    Are you spawning it with life 0?
  • GreenFireDragon
    22nd Apr 2013 Member 0 Permalink

    I copied the whole code from PLSM so I don't know

  • boxmein
    22nd Apr 2013 Former Staff 0 Permalink
    Probably you are...
  • cyberdragon
    23rd Apr 2013 Member 0 Permalink

    It might be worse than that...it looks like life was not defined in this scope. So it can't have any life and the code simply fails.

  • GreenFireDragon
    23rd Apr 2013 Member 0 Permalink

    But why is PLSM working?

  • boxmein
    23rd Apr 2013 Former Staff 0 Permalink
    PLSM gets set a LIFE value somewhere along the way.
  • jacksonmj
    23rd Apr 2013 Developer 0 Permalink

    In src/simulation/Simulation.cpp, find the create_part function.

    In that function, find the code that sets the default properties for PLSM when PLSM is created.

    case PT_PLSM:
        parts[i].life = rand()%150+50;
        break;

    Add something similar nearby for your element (or just add "case PT_POSP:" at the start of the code above to give your element the same default properties as PLSM).

  • GreenFireDragon
    23rd Apr 2013 Member 0 Permalink

    It works, thanks