Exemplo n.º 1
0
    public void Execute()
    {
        lights.flags = 0;
        LightCalculator.ProcessSunlight(ref lights, ref blocks, blockData, lightBFS, lightBFS_U, lightRBFS, lightRBFS_U);

        LightCalculator.LightUpdate(ref lights, faces, colors);

        lightBFS.Enqueue(lights.flags);
    }
Exemplo n.º 2
0
    // also record list of who needs to update after this (if u edit their light)

    public void Execute()
    {
#if _DEBUG
        long initLightTime    = 0;
        long processLightTime = 0;
        long meshingTime      = 0;
        long colliderTime     = 0;
        System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
        watch.Restart();
        UnityEngine.Profiling.Profiler.BeginSample("Lighting");
#endif

        //LightCalculator.AddSunlightRemovals(ref lights, lightOps, lightRBFS);

        // if chunk hasnt been rendered before then check each block to see if it has any lights
        if (calcInitialLight)
        {
            LightCalculator.CalcInitialLightOps(blocks.c, blockData, lightOps);
#if _DEBUG
            initLightTime = watch.ElapsedMilliseconds;
            watch.Restart();
#endif
            LightCalculator.CalcInitialSunLight(blocks.c, blockData, lights.c, lights.u, lightBFS, upRendered, chunkWorldPos);
        }
        // always call this incase lightBFS comes with some data in it already
        LightCalculator.ProcessSunlight(ref lights, ref blocks, blockData, lightBFS, lightBFS_U, lightRBFS, lightRBFS_U);
        Assert.IsTrue(lightBFS.Count == 0 && lightRBFS.Count == 0);
        LightCalculator.ProcessTorchLightOpsOptimal(ref lights, ref blocks, blockData, lightOps, lightBFS, lightRBFS);
        Assert.IsTrue(lightBFS.Count == 0 && lightRBFS.Count == 0);
        int torchLightFlags = lights.flags;

        // add this so job controller can see after jobs done
        lightBFS.Enqueue(torchLightFlags);

        // also here maybe add nodes that weren't finished due to hitting bottom of chunks

#if _DEBUG
        UnityEngine.Profiling.Profiler.EndSample();
        processLightTime = watch.ElapsedMilliseconds;
        watch.Restart();
        UnityEngine.Profiling.Profiler.BeginSample("Meshing");
#endif

        NativeMeshData meshData = new NativeMeshData(vertices, normals, uvs, uv2s, colors, triangles, faces); // add faces to this
        MeshBuilder.BuildNaive(ref meshData, ref blocks, ref lights, blockData);

#if _DEBUG
        meshingTime = watch.ElapsedMilliseconds;
        watch.Restart();
        UnityEngine.Profiling.Profiler.EndSample();
#endif

#if GEN_COLLIDERS
#if _DEBUG
        UnityEngine.Profiling.Profiler.BeginSample("Collider");
#endif
        if (genCollider)
        {
            MeshBuilder.BuildGreedyCollider(ref blocks, colliderVerts, colliderTris);
        }
#if _DEBUG
        colliderTime = watch.ElapsedMilliseconds;
        UnityEngine.Profiling.Profiler.EndSample();
#endif
#endif

#if _DEBUG
        lightBFS.Enqueue((int)initLightTime);
        lightBFS.Enqueue((int)processLightTime);
        lightBFS.Enqueue((int)meshingTime);
        lightBFS.Enqueue((int)colliderTime);
#endif
    }