Page 1 of 2

[Mod] Mini Sun, Pesudo Brighter Light Source [mini_sun]

PostPosted: Sun Jun 09, 2013 13:16
by bdjnk
Placed mini sun nodes generate square areas of powerful light against nearby terrain. It looks like this:

Image

Code license : GPLv2/later

Mod dependencies: default

The code can be found on GitHub, right here

Code: Select all
Current crafting recipe:

    copper_ingot  glass         copper_ingot
    glass         mese_crystal  glass
    copper_ingot  glass         copper_ingot

I'm open to suggestions


+ The Original 'Original Post'

PostPosted: Sun Jun 09, 2013 13:55
by bdjnk
I fixed the easier and less critical issue using node metadata. I also managed to make the more serious issue less serious by only placing a glow node every other block. Here is the relevant section of code:

Code: Select all
    on_construct = function(pos)
        local dist = 6
        for nx = pos.x-dist, pos.x+dist, 2 do
            for ny = pos.y-dist, pos.y+dist, 2 do
                for nz = pos.z-dist, pos.z+dist, 2 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "air" then
                        minetest.add_node(npos, {name = "mini_sun:glow"})
                        minetest.env:get_meta(npos):set_string("pos", minetest.pos_to_string(pos))
                    end
                end
            end
        end
    end,
    on_destruct = function(pos)
        local dist = 6
        for nx = pos.x-dist, pos.x+dist, 2 do
            for ny = pos.y-dist, pos.y+dist, 2 do
                for nz = pos.z-dist, pos.z+dist, 2 do
                    local npos = {x=nx, y=ny, z=nz}
                    if minetest.get_node(npos).name == "mini_sun:glow"
                    and minetest.pos_to_string(pos) == minetest.env:get_meta(npos):get_string("pos")
                    then
                        minetest.remove_node(npos)
                    end
                end
            end
        end
    end

PostPosted: Mon Jun 10, 2013 19:58
by bdjnk
I've changes pretty much everything about the way Mini Sun works. Here is the latest version:

Code: Select all
minetest.register_node("mini_sun:glow", {
    drawtype = "airlike",
    walkable = false,
    pointable = false,
    diggable = true,
    climbable = false,
    buildable_to = true,
    light_source = 14,
    paramtype = light
})

minetest.register_craft({
    output = '"mini_sun:source" 2',
    recipe = {
        {'default:glass', 'default:glass', 'default:glass'},
        {'default:glass', 'default:torch', 'default:glass'},
        {'default:glass', 'default:glass', 'default:glass'},
    }
})

minetest.register_node("mini_sun:source", {
  tiles = { "mini_sun.png" },
    drawtype = "glasslike",
    groups = { cracky=3, oddly_breakable_by_hand=3 },
    sounds = default.node_sound_glass_defaults(),
    drop = "mini_sun:source",
    light_source = 14,
    paramtype = light,
    after_place_node = function(pos, placer)
        minetest.get_node_timer(pos):start(1.1)
    end,
    on_destruct = function(pos)
        minetest.get_node_timer(pos):stop()
    end,
    after_destruct = function(pos, oldnode)
        local dist = 6
        local minp = { x=pos.x-dist, y=pos.y-dist, z=pos.z-dist }
        local maxp = { x=pos.x+dist, y=pos.y+dist, z=pos.z+dist }
        local glow_nodes = minetest.find_nodes_in_area(minp, maxp, "mini_sun:glow")
        for key, npos in pairs(glow_nodes) do
            minetest.remove_node(npos)
            end
    end,
    on_timer = function(pos, elapsed)
        local dist = 6
        local pmod = (pos.x + pos.y + pos.z) %2
        local minp = { x=pos.x-dist, y=pos.y-dist, z=pos.z-dist }
        local maxp = { x=pos.x+dist, y=pos.y+dist, z=pos.z+dist }
        local air_nodes = minetest.find_nodes_in_area(minp, maxp, "air")
        for key, npos in pairs(air_nodes) do
            if (npos.x + npos.y + npos.z) %2 == pmod then -- 3d checkerboard pattern
                if grounded(npos) then                    -- against lightable surfaces
                    minetest.add_node(npos, {name = "mini_sun:glow"})
                end
            end
        end
        return true
    end
})

grounded = function(pos)
    -- checks all nodes touching the edges and corners (but not faces) of the given pos
    for nx = -1, 1, 2 do
        for ny = -1, 1, 2 do
            for nz = -1, 1, 2 do
                local npos = { x=pos.x+nx, y=pos.y+ny, z=pos.z+nz }
                local name = minetest.get_node(npos).name
                if minetest.registered_nodes[name].walkable and name ~= "mini_sun:source" then
                    return true
                end
            end
        end
  end
    return false
end


As you can see, I'm trying to minimize the number of glow nodes created without compromising the brightness. Turns out, reams of really inefficient code is way faster than adding even a single glowing node. Every second, all that math gets chewed through with zero stutter. Add a couple extra glow nodes, and the whole machine seizes up and convulses wildly.

Anyway, I'm not a fan of the recipe I'm currently using, so feel free to drop some suggestions.

Oh, and here is the current source node (mini_sun.png) texture: [img=mini sun source texture]http://img580.imageshack.us/img580/1368/minisun.png[/img] (it matches the default theme)

PostPosted: Thu Jun 27, 2013 16:21
by DeepGaze
will there be link soon? for linux plz!!

PostPosted: Fri Jun 28, 2013 02:25
by bdjnk
DeepGaze wrote:will there be link soon? for linux plz!!


Even though it's in a decent state right now, I never got it working 100%. Honestly, certain things need to change in the game code and lua API (rather than a hacky solution like this one).

Aside from that, being as I was the only one commenting, I didn't realize anyone else was interested :)

Anyway, here's a link to the current version: mini_sun.zip

PostPosted: Fri Jun 28, 2013 05:32
by paramat
Yep i'm interested in this and have been experimenting with something similar. Perhaps to light the surface of a realm so it can be bright at night, for example a moon without atmosphere.

PostPosted: Fri Jun 28, 2013 07:00
by Jordach
If you wanted a proper sudo sun, just give the air node light_level = 14

PostPosted: Fri Jun 28, 2013 10:22
by bdjnk
Jordach wrote:If you wanted a proper sudo sun, just give the air node light_level = 14


Um, wait, I though "air nodes" were not actually nodes at all. Can they be given a light_level? If so, how? I haven't seen anything like that in any of the documentation...

PostPosted: Fri Jun 28, 2013 11:06
by Zeg9
bdjnk wrote:
Jordach wrote:If you wanted a proper sudo sun, just give the air node light_level = 14


Um, wait, I though "air nodes" were not actually nodes at all. Can they be given a light_level? If so, how? I haven't seen anything like that in any of the documentation...

I think you can override the air node like you would do with any other node.
Code: Select all
minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    light_source = 14,
})

PostPosted: Fri Jun 28, 2013 16:37
by LionsDen
Zeg9 wrote:I think you can override the air node like you would do with any other node.

Code: Select all
minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    light_source = 14,
})



Hi, I just tried this code in a test using the Minetest development from 6/22 and I didn't see any brightness in the sky but the ground, trees, grass and everything else turned black. There were no mods running except the little test I created that had only the code up above in it. I just thought I would let you know that it doesn't seem to work like you expected. Unless maybe you then have to place these nodes in the world to get them to work.

EDIT: It got to night and suddenly there were a few sparse patches on the ground and in the trees that were lit up. There were only a few though.

PostPosted: Fri Jun 28, 2013 17:22
by VanessaE
You also need: paramtype="light",

(not paramtype2... whether the above is enough or the idea will work at all, I dunno, but it's needed either way)

PostPosted: Fri Jun 28, 2013 21:45
by bdjnk
This does very bad things. The entire system starts seizing up and visual glitches abound.

Code: Select all
minetest.register_node(":air", {
    drawtype = "airlike",
    walkable = false,
    paramtype = light,
    light_source = 14,
})


I'm not sure the reason, but I do know that glowing nodes are no joke for the system to process. That's why I reduced them as much as possible in my code.

PostPosted: Fri Jun 28, 2013 23:40
by bdjnk
I just pushed a fix for the issue where dirt_with_grass becomes just plain dirt beneath glow nodes. Oh, here's the github link.

PostPosted: Sat Jun 29, 2013 01:34
by VanessaE
Make that paramtype="light", with the quotes around "light". Not that this will fix the performance issue, however. (I don't think that's fixable, because basically you're spamming the engine's lighting code)

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Sun Apr 27, 2014 12:02
by dgm5555
Awesome mod! Any chance you could put the git link in the first post, it took me a while to notice it.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Mon Apr 28, 2014 01:35
by Sokomine
Regarding performance of the add_node calls: Why not use a schematic for that? place_schematic has a nice parameter that takes care that existing nodes are not replaced. place_schematic is very fast. What it will do to light sources I don't know. Might be worth a try?

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jun 26, 2014 04:49
by bdjnk
Sokomine wrote:Regarding performance of the add_node calls: Why not use a schematic for that? place_schematic has a nice parameter that takes care that existing nodes are not replaced. place_schematic is very fast. What it will do to light sources I don't know. Might be worth a try?


I would try schematics, but the documentation is very spotty. The best info I've found is the minetest.register decoration page on the dev wiki, and the lua_api.txt doc from the github repo. This might be enough for me to tinker and figure out how to use schematics, basically rediscovering fire (this is actually one of the reason I'm not messing with minetest anymore). If there are better docs, or code by others I can look at, or anything but disjointed and incomplete information that must be hunted up from all over hell, please redirect me to it.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jun 26, 2014 07:46
by rubenwardy
Or voxel manipulators.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jun 26, 2014 15:02
by Sokomine
bdjnk wrote:If there are better docs, or code by others I can look at, or anything but disjointed and incomplete information that must be hunted up from all over hell, please redirect me to it.

It's pretty easy and especially useful if you want your suns to be large. First off, build the thing you want to use in your local world. Install WorldEdit. Type "//p set" and punch two opposite corners of the building (or, in this case, the sun). Type "//mtschemcreate filename". You'll now find the schematic as a file in worlds/YourWorldName/schems/filename.mts Copy that to a new folder in the directory that contains your mod and which you name "schems".

In order to place it, use
Code: Select all
minetest.place_schematic( pos, minetest.get_modpath("yourmodname")..'/schems/' , "random", {}, false );

And that's it already.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jun 26, 2014 19:35
by bdjnk
Thanks. Sorry for being snippy before. I'll play around with schematics and look into voxel manipulators when I have some time.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jun 26, 2014 20:02
by Calinou
If you want light everywhere, edit the shader files (you only need to restart the game, shaders need to be enabled) or light.cpp (recompilation required, works with and without shaders).

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Thu Jul 03, 2014 04:40
by bdjnk
Okay, so after looking into both, it seems like voxel manipulators is probably the better bet. I did some messing around, and got lights to show up. It works instantly! The trouble is, sometimes the light doesn't entirely disappear, even though all the light generating nodes are gone.

If you want to try and help solve this issue, check out the voxel_manipulator branch at github.

Re: Mini Sun, Pesudo Brighter Light Source... Questions

PostPosted: Mon Aug 25, 2014 18:55
by bdjnk
bdjnk wrote:The trouble is, sometimes the light doesn't entirely disappear, even though all the light generating nodes are gone.

Okay, so it turns out my voxel_manip needed to read an area from the map which included all glow. This allows update_map() to correct all applicable light levels. Fixed.

With that out of the way, I've made some other progress in that mini suns now only remove glow they alone generate.

There's still one bug and one feature to go, as well some optimizations, before this is ready to be declared a mod. Oh, and a different recipe! Suggestions?

p.s. I'm back in master. The voxel_manipulator branch is gone.

Re: Mini Sun, Pesudo Brighter Light Source. Updated.

PostPosted: Wed Aug 27, 2014 19:28
by bdjnk
Glow now expands into dug areas and against newly placed nodes as necessary.

Also, as you may have noticed, the original post has been updated.

These are the only items remaining in my mind as possible additions:
  • Line of slight only glow node placement, which I'm not even sure is a good idea.
  • Glow working properly under water.

Re: Mini Sun, Pesudo Brighter Light Source. Updated.

PostPosted: Mon Sep 15, 2014 01:23
by Napiophelios
Basically you have had 3 three versions here;
The second was a pretty good improvement over the first,
but could still slow down the game at times,

the third [latest] works the best as far as gameplay goes
but unlike with the previous 2 releases,where the area is filled with light

Image

Now you can actually see the "glow" textures and its pretty annoying.
Image

Is there anyway to have it display as with previous versions?