How do you put a C++ element into TPT?

  • TheScienceKid
    29th Dec 2016 Member 0 Permalink

    So i made a c++ element called METR, my lua codes are turning to paint so i cant use them, anyone know how to get it in the game or in a mod? here is the code:

    #include "simulation/Elements.h"
    //#TPT-Directive ElementClass Element_METR PT_METR {INSERT ID HERE}
    Element_METR::Element_METR()
    {
    Identifier = "DEFAULT_PT_METR";
    Name = "METR";
    Colour = PIXPACK(0x792b2b);
    MenuVisible = 1;
    MenuSection = SC_EXPLOSIVE;
    Enabled = 1;

    Advection = 1e-005f;
    AirDrag = 50f * CFDS;
    AirLoss = 0;
    Loss = 0.75f;
    Collision = 0f;
    Gravity = 1.5f;
    Diffusion = 0.1f;
    HotAir = 15f * CFDS;
    Falldown = 0;

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

    Weight = 100;

    Temperature = 9999f;
    HeatConduct = 251;
    Description = "The thing that killed the dinosaurs off! Use the pen size to determine the size of the meateor. Made by TSK";

    Properties = TYPE_ENERGY;

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

    Update = &Element_METR::update;
    Graphics = &Element_METR::graphics;
    }

    // #define UPDATE_FUNC_ARGS Simulation* sim, int i, int x, int y, int surround_space, int nt, Particle *parts, int pmap[YRES][XRES]

    //#TPT-Directive ElementHeader Element_METR static int update(UPDATE_FUNC_ARGS)
    int Element_METR::update(UPDATE_FUNC_ARGS)
    {

    }

    // #define GRAPHICS_FUNC_ARGS Renderer *ren, Particle *cpart, int nx, int ny,
    // int *pixel_mode, int* cola, int *colr, int *colg,
    // int *colb, int *firea, int *firer, int *fireg, int *fireb

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

    }

    Element_METR::~Element_METR() {}

     

    Please and thank you!

  • TPT_PL
    29th Dec 2016 Member 0 Permalink

    Well, you need a compiler. Then a source. Then an IDE. Then you use the IDE to edit the source and compile it. You get a version of TPT with the element.

    Wait, dinosaurs were killed by MEATeors? :P

  • QuanTech
    29th Dec 2016 Member 0 Permalink

    If you're on windows:

    1. Get SCons
    2. Read https://powdertoy.co.uk/Wiki/W/Compiling_for_Windows_with_scons.html
    3. Do whatever it says there ^
    4. If you have any questions, you can ask on the development assistance subforum

    Also, I don't think you need to #define UPDATE_FUNC_ARGS, bcuz it is defined in some other file, and nice graphics function :P

    Edited once by QuanTech. Last: 29th Dec 2016
  • TheScienceKid
    29th Jan 2017 Member 0 Permalink

    what the science is SCons?

    @TPT_PL .................................................... that................................. was..................................... BEAUTIFUL

     

    Edit:OH JEEZ, ERRRRRM................................. IM A NOOB AT CODE, DOES NOT COMPUTE, FDLFLBSDLFBGKDSFJFBDKJB *implosion*

    Edited once by TheScienceKid. Last: 29th Jan 2017
  • LBPHacker
    29th Jan 2017 Developer 0 Permalink

    Why would you need C++ for this? What do you mean by your scripts turning into paint? Anyway, if you really wish to go the native way, the wiki QuanTech linked is pretty straightforward.

  • QuanTech
    29th Jan 2017 Member 0 Permalink

    @LBPHacker (View Post)

     By turning scripts to paint he probably means that he selected MS Paint as the program to open all lua files with.

    @TheScienceKid

    If you want to run the lua file in tpt, just put it in the same file directory as Powder.exe and type dofile("potato.lua") (obviously potato.lua would be your filename) in le console. Magic. Unicorns. I do just shove any element scripts into autorun.lua, which is automatically loaded every time you open tpt, so you don't have to dofile or stuff.

    Edited 2 times by QuanTech. Last: 29th Jan 2017