Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
liquidFun from C++ to Lua — Gideros Forum

liquidFun from C++ to Lua

HubertRonaldHubertRonald Member
edited September 2017 in Bugs and issues
I'm reading some information about liquidFun and this script has "b2DestructionListener"

When I was checking gideros source
"Line 73"
"Line 484"

functions
virtual void 	SayGoodbye (b2ParticleGroup *group)
virtual void 	SayGoodbye (b2ParticleSystem *particleSystem, int32 index)
 
virtual bool 	ShouldCollide (b2Fixture *fixture, b2ParticleSystem *particleSystem, int32 particleIndex)
virtual bool 	ShouldCollide (b2ParticleSystem *particleSystem, int32 particleIndexA, int32 particleIndexB)
don't exist, but you can call it with Flags (this functionality is ready on gideros "Line 31")
--b2.ParticleSystem.FLAG_PARTICLE_CONTACT_FILTER = 2^17
--b2.ParticleSystem.FLAG_FIXTURE_CONTACT_FILTER = 2^16
--b2.ParticleSystem.FLAG_PARTICLE_CONTACT_LISTENER = 2^15 --EXPENSIVE
--b2.ParticleSystem.FLAG_FIXTURE_CONTACT_LISTENER = 2^14 --EXPENSIVE
--b2.ParticleSystem.FLAG_REPULSIVE = 2^13 = 8192				--With high repulsive force.
--b2.ParticleSystem.FLAG_REACTIVE = 2^12 = 4096					--Makes pairs or triads with other particles.
--b2.ParticleSystem.FLAG_STATIC_PRESSURE = 2^11	= 2048			--Less compressibility.
--b2.ParticleSystem.FLAG_BARRIER = 2^10	= 1024					--Prevents other particles from leaking.
--b2.ParticleSystem.FLAG_DESTRUCTION_LISTENER = 2^9 = 512		--Call b2DestructionListener on destruction.
--b2.ParticleSystem.FLAG_COLOR_MIXING = 2^8 = 256						--Mix color between contacting particles.
 
 
 
--b2.ParticleSystem.FLAG_TENSILE = 2^7 = 128	--like a ocean, scum
--b2.ParticleSystem.FLAG_POWDER = 2^6 = 64	--like a boiled	// Without isotropic pressure.
--b2.ParticleSystem.FLAG_VISCOUS = 2^5 = 32	--like a rice
--b2.ParticleSystem.FLAG_ELASTIC = 2^4 = 16	--stable jelly (if on the world doesn't exist strength)
--b2.ParticleSystem.FLAG_SPRING = 2^3 = 8		--really jelly
--b2.ParticleSystem.FLAG_WALL = 2^2 = 4		--like a sponge or water drops on surface // Zero velocity
										--(it only works with two Particles group like
										--minium but another particles group must have different Flag)
--b2.ParticleSystem.FLAG_ZOMBIE = 2^1 =  2		--Removed after next simulation step.
--b2.ParticleSystem.FLAG_WATER = 0		--water
Sample: b2.ParticleSystem.FLAG_COLOR_MIXING | b2.ParticleSystem.FLAG_WALL
The particle type. Can be combined with the | operator


image

It would be interesting than we have
b2ContactFilter -Line 99-
as event Read more information here) so when we'll use lifespan, we can do something in that event specific

Comments

  • HubertRonaldHubertRonald Member
    edited September 2017
    Ok review some information here
    Event.BEGIN_CONTACT_PARTICLE

    and here too
    see lines from 346 to 422

    I Tried the next code
    require "box2d"
     
    application:setScaleMode("letterbox")
    application:setOrientation(application.LANDSCAPE_LEFT)
    application:setLogicalDimensions(600,800)
     
    local cw=application:getContentWidth()
    local ch=application:getContentHeight()
     
    -- this table holds the dynamic bodies and their sprites
    local actors = {}
     
    -- create world
    local world = b2.World.new(0, 9.8)
     
    -- create ground body
    local ground = world:createBody({})
     
    -- create an edge shape, and attach it to the ground body as a fixture
    local shapeb = b2.EdgeShape.new(0, ch, cw, ch)
    local shapet = b2.EdgeShape.new(0, 0, cw, 0)
    local shapel = b2.EdgeShape.new(0, 0, 0, ch)
    local shaper = b2.EdgeShape.new(cw, 0, cw, ch)
    ground:createFixture({shape = shapeb, density = 0})
    ground:createFixture({shape = shaper, density = 0})
    ground:createFixture({shape = shapel, density = 0})
    ground:createFixture({shape = shapet, density = 0})
     
     
    local shape1 = b2.PolygonShape.new()
    shape1:setAsBox(200, 50)
    local shape2 = b2.PolygonShape.new()
    shape2:setAsBox(200, 100)
     
    local ps1= world:createParticleSystem({ radius=5})
    stage:addChild(ps1)
     
    ps1:createParticle({ 
    position={x=200,y=450},
    color = 0xFFFF00,
    alpha=1,
    flags=4|256|2^15 --on BeginContactParticle and on BeginContactParticle 2, I suppose in the first case too
    })
     
    --Doesn't Work or maybe I missed something
    local function onBeginContactParticle(e) 
        local fixture = e.fixture
        local index = e.index
        local system = e.system
        print("Hello Particle",fixture,index,system)
    end
     
    --VERY EXPENSIVE (*/)
    local function onBeginContactParticle2(e) 
        local indexA = e.indexA
        local indexB = e.indexB
        ---------------------------------------
        local system = e.system --<-- I get nil value
        ---------------------------------------
        print("Hello Particle 2",indexA,indexB,system)
    end
     
    world:addEventListener(Event.BEGIN_CONTACT_PARTICLE,onBeginContactParticle)
    world:addEventListener(Event.BEGIN_CONTACT_PARTICLE2,onBeginContactParticle2)
     
     
    ps1:createParticleGroup({shape=shape2, 
    position={x=500,y=250},
    color = 0xFF0000,
    stride=0,
    alpha=1,
    flags=4|256
    })
     
    ps1:createParticleGroup({shape=shape1, 
    position={x=400,y=50},
    color = 0x0000FF,
    alpha=1,
    flags=0|256
    })
     
    local function onEnterFrame(e) world:step(1/60, 8, 3) end
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    (*/ Read More Information Here)

    As I said in my first post better are
    b2.ParticleSystem.FLAG_PARTICLE_CONTACT_FILTER = 2^17
    b2.ParticleSystem.FLAG_FIXTURE_CONTACT_FILTER = 2^16

    But these functions are not yet available on Gideros I don't know if core team will implementation these function

    On another hand something had tried Event.BEGIN_CONTACT_PARTICLE 'cos it doesn't work for me but maybe I'm doing It Wrong

  • Gideros is open source, we need someone to update to the latest LiquidFun and add all the missing and new api commands. Do you want to do it?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • HubertRonaldHubertRonald Member
    edited September 2017
    Well, If I'll try this may happen much later 'cos my cpp knowdelege are minimal (a lot time without write in this programing language) , added to the above never I've tried the Lua C API so I couldn't give you a certain end date.

    On the other hand, How Can I test these changes? How Can I know if I'm on the right way? :-/
    I remember asking these matters when Gideros changed to open source, but nobody told me how to create the installation files if you changed something on the source code...
    Currently Does exist some tutorial for it?
  • snookssnooks Member
    edited September 2017
    This is a interesting one, the flags are there so if you change your code to...
    flags = b2.ParticleSystem.FLAG_PARTICLE_CONTACT_LISTENER | b2.ParticleSystem.FLAG_FIXTURE_CONTACT_LISTENER
    ... then the events trigger - BUT only one of them can be active at one time. So if you comment out your Particle2 listener then the first one should work. Same if you add two end contact listeners, only one of the four will work.

    Also neither of them get e.system, even though it looks like it's pushed to Lua by Gideros. On lines 488-489 here..

    https://github.com/gideros/gideros/blob/master/luabinding/box2dbinder2.cpp

    ... and getb2 looks like it's working for world and fixture, but not the particle system.
  • Are you doing anything with this? I ask because I've been playing around with it, but there's no point both of us doing the same thing.
  • I'm sorry @snooks but the problem with liquidFun currently it's when you want to integrate it with camera... it doesn't work :(
    Here I posted this problem: http://giderosmobile.com/forum/discussion/7061/liquid-fun#Item_2

    So I haven't took this matter again because I wanted make levels puzzles more big so it is a limitation for me.

    Dirty solution is create liquid in default position (when camera is (0,0)) and without move the camera but if you want to follow liquid with the camera you can't do. :(
  • Ah, I see that... when the particle system sprite has a parent sprite, when the parent is moved the radius of the particles increase or decrease depending on the position of the parent. It looks like a bug, but I haven't learned enough about Gideros inner workings to see what's causing it.
    particles.gif
    484 x 320 - 203K
Sign In or Register to comment.