Code questions

  • savask
    27th Jul 2010 Developer 0 Permalink
    I think we can ask questions about code here.
    Mine:
    I'm very bad in C and I can't understand what is >>8 (for example "parts[r>>8].type = PT_SPRK). Can you explain?
  • Simon
    27th Jul 2010 Administrator 0 Permalink
    >> is a "bitwise" operator, it shifts all the bits 1 bit to the right, in the case of >>8, it shifts them 8 bits to the right. Each particle index is a 32bit integer, though actually 2 unsigned 8bit integers.
    Say if we have an index that is 1390, represented in binary, this is "00000101 01101110" if we shift all the bits to the right by 8, we get 0000101 or 5, that would be the Particle Type. If we want to get the particle ID, we use the "&" (AND) operator.
    For example we would do 1390&0xFF (255) to get the first 8 bits, 01101110 or 110.
  • savask
    27th Jul 2010 Developer 0 Permalink
    Thanks for explaining I was comparing this with my little C++ experience, so cout << "\n Hi!" is usual for me, but >>8 not.
  • Simon
    27th Jul 2010 Administrator 0 Permalink
    << serves a similar purpose, it does the same as >> but shifts the bits to the left.
  • savask
    27th Jul 2010 Developer 0 Permalink
    May I ask another questions?
    When I try to change particle type into ACID, I get dark-purple liquid which don't act as it. I do so: "parts[r>>8].type = PT_ACID". What I do wrong?
    And another one: How to delete current particle? "parts[pmap[y][x]>>8].life = 0" don't work.
  • Simon
    27th Jul 2010 Administrator 0 Permalink
    delete_part(x, y)
    ACID has a "life" you need to do parts[r>>8].life = 20 or something.
  • savask
    27th Jul 2010 Developer 0 Permalink
    "parts[r>>8].life = 20" don't work for me, still get purple liquid.
    Edit:
    I've solved my problem, acid needs 75 live points. Thanks for helping!
  • ssc4k
    27th Jul 2010 Member 0 Permalink
    Is there any way to get the type of particle on pixel x,y?
  • savask
    27th Jul 2010 Developer 0 Permalink
    Yes.
    "(pmap[y][x]&0xFF)==PT_SOMETHING" - is what you are asking for.