Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "stdafx.h"

#include "Headers/Quadtree.h"
#include "Headers/QuadtreeNode.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Video/Headers/IMPrimitive.h"
#include "Platform/Video/Headers/RenderStateBlock.h"

namespace Divide {

Quadtree::Quadtree() : _parentVB(nullptr),
                       _root(nullptr),
                       _bbPrimitive(nullptr)
{
    _chunkCount = 0;
}

Quadtree::~Quadtree()
{
    MemoryManager::DELETE(_root);
}

void Quadtree::sceneUpdate(const U64 deltaTimeUS, SceneGraphNode& sgn,
                           SceneState& sceneState) {
    assert(_root);
    _root->sceneUpdate(deltaTimeUS, sgn, sceneState);
}

void Quadtree::drawBBox(GFXDevice& context, RenderPackage& packageOut) {
    assert(_root);
    _root->drawBBox(context, packageOut);
    
    if (!_bbPrimitive) {
        _bbPrimitive = context.newIMP();
        _bbPrimitive->name("QuadtreeBoundingBox");
        RenderStateBlock primitiveRenderState;
        PipelineDescriptor pipeDesc;
        pipeDesc._stateHash = primitiveRenderState.getHash();
        _bbPrimitive->pipeline(context.newPipeline(pipeDesc));
    }

    _bbPrimitive->fromBox(_root->getBoundingBox().getMin(),
                          _root->getBoundingBox().getMax(),
                          UColour(0, 64, 255, 255));

    packageOut.addCommandBuffer(_bbPrimitive->toCommandBuffer());
}

QuadtreeNode* Quadtree::findLeaf(const vec2<F32>& pos) {
    assert(_root);

    QuadtreeNode* node = _root;
    QuadtreeNode* child = nullptr;
    while (!node->isALeaf()) {
        U32 i = 0;
        for (i = 0; i < 4; i++) {
            child = &(node->getChild(i));
            const BoundingBox& bb = child->getBoundingBox();
            if (bb.containsPoint(vec3<F32>(pos.x, bb.getCenter().y, pos.y))) {
                node = child;
                break;
            }
        }

        if (i >= 4) {
            return nullptr;
        }
    }

    return node;
}

void Quadtree::Build(GFXDevice& context,
                     BoundingBox& terrainBBox,
                     const vec2<U32>& HMsize,
                     U32 targetChunkDimension,
                     Terrain* const terrain) {
    _root = MemoryManager_NEW QuadtreeNode();
    _root->setBoundingBox(terrainBBox);

    _root->Build(context, 0, vec2<U32>(0, 0), HMsize, targetChunkDimension, terrain, _chunkCount);

    // Generate index buffer
    const U32 terrainWidth = HMsize.x;
    const U32 terrainHeight = HMsize.y;
    vectorImpl<vec3<U32>>& triangles = terrain->getTriangles();
    triangles.reserve(terrainHeight * terrainWidth * 2);

    I32 vertexIndex = -1;
    for (U32 j = 0; j < (terrainHeight - 1); ++j) {
        for (U32 i = 0; i < (terrainWidth - 1); ++i) {
            vertexIndex = (j * terrainWidth) + i;
            // Top triangle (T0)
            triangles.emplace_back(vertexIndex, vertexIndex + terrainWidth + 1, vertexIndex + 1);
            // Bottom triangle (T1)
            triangles.emplace_back(vertexIndex, vertexIndex + terrainWidth, vertexIndex + terrainWidth + 1);
        }
    }
}

BoundingBox& Quadtree::computeBoundingBox() {
    assert(_root);
    _root->computeBoundingBox();
    return _root->getBoundingBox();
}
};

Commits for Divide-Framework/trunk/Source Code/Environment/Terrain/Quadtree/Quadtree.cpp

Diff revisions: vs.
Revision Author Commited Message
1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

943 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 11:38:52 +0000

[IonutCava]
- Rework ThreadPool/Task system for clearer parent<->child relationship between tasks
— Disable Prio pool since it doesn’t work properly with the newest boost libraries
— Modify the C++11 threadpool to remove the boost dependency
- Reduce memory usage by allocating command buffers on use instead of on creation

933 Diff Diff IonutCava picture IonutCava Tue 15 Aug, 2017 00:02:05 +0000

[Ionut]
- CommandBuffer Part 2/3: code compiles and splash screen renders and application doesn’t crash (still has drawing issues)

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

893 Diff Diff IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

880 Diff Diff IonutCava picture IonutCava Mon 20 Mar, 2017 17:27:13 +0000

[IonutCava]
- New tessellated terrain system based on this: http://victorbush.com/2015/01/tessellated-terrain/
— Work in progress: hardcoded values, new code is in Test namespace
- Split terrain geometry in two:
— tessellated rendering data
— physics verts + indices (used for collisions, vegetation, etc)
- Old Chunk system is used only for culling objects and speeding up collision detection

874 IonutCava picture IonutCava Mon 13 Mar, 2017 17:29:45 +0000

[IonutCava]
- Fix boundingbox skewing bug.
- Optimise frustum collision checks by adding a plane-cache system.
— ToDo: solve mutable status of _frustPlaneCache
— ToDo: TRIPLE check results to avoid false-positives
- Speedup terrain by not stack-allocating QuadtreeNodes in a QuadtreeChildren container instead of new-ing each one of them.