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
#include "Headers/Quadtree.h"
#include "Headers/QuadtreeNode.h"
#include "Environment/Terrain/Headers/Terrain.h"
#include "Platform/Video/Headers/GFXDevice.h"

namespace Divide {

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

Quadtree::~Quadtree() {}

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

void Quadtree::createDrawCommands(
    const SceneRenderState& sceneRenderState,
    vectorImpl<GenericDrawCommand>& drawCommandsOut) {
    assert(_root);
    U32 options = CHUNK_BIT_TESTCHILDREN;
    if (GFX_DEVICE.isCurrentRenderStage(RenderStage::REFLECTION_STAGE)) {
        options |= CHUNK_BIT_WATERREFLECTION;
    } else if (GFX_DEVICE.isCurrentRenderStage(RenderStage::SHADOW_STAGE)) {
        options |= CHUNK_BIT_SHADOWMAP;
    }
    _root->createDrawCommand(options, sceneRenderState, drawCommandsOut);
}

void Quadtree::drawBBox() const {
    assert(_root);
    _root->drawBBox();
    GFX_DEVICE.drawBox3D(_root->getBoundingBox().getMin(),
                         _root->getBoundingBox().getMax(),
                         vec4<U8>(0, 64, 255, 255));
}

QuadtreeNode* Quadtree::findLeaf(const vec2<F32>& pos) {
    assert(_root);
    QuadtreeNode* node = _root.get();
    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(BoundingBox& terrainBBox, const vec2<U32>& HMsize,
                     U32 minHMSize, Terrain* const terrain) {
    _root.reset(new QuadtreeNode());
    _root->setBoundingBox(terrainBBox);

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

    // Generate index buffer
    const U32 terrainWidth = HMsize.x;
    const U32 terrainHeight = HMsize.y;
    vec3<U32> firstTri, secondTri;
    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)
            firstTri.set(vertexIndex, vertexIndex + terrainWidth + 1,
                         vertexIndex + 1);
            // Bottom triangle (T1)
            secondTri.set(vertexIndex, vertexIndex + terrainWidth,
                          vertexIndex + terrainWidth + 1);
            terrain->addTriangle(firstTri);
            terrain->addTriangle(secondTri);
        }
    }
}

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
365 Diff Diff IonutCava picture IonutCava Sun 08 Mar, 2015 21:26:10 +0000

[Ionut]
- More enum-related type safety changes

354 Diff Diff IonutCava picture IonutCava Fri 20 Feb, 2015 17:17:37 +0000

[Ionut]
- Replaced GLEW with glbinding (requires a CEGUI recompile. It currently crashes)
- Replaced most “SceneGraphNode* const sgn” expressions with "SceneGraphNode& sgn"
- Replaced some pointers to kernel to references to kernel
- Fixed compilation issues with EASTL
- Removed NPOT -> POT texture conversion code. Modern GPUs handle NPOT textures perfectly fine

350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

349 Diff Diff IonutCava picture IonutCava Fri 06 Feb, 2015 17:11:39 +0000

[Ionut]
- More raw pointer replacements
- Removed some redundant parameters to a few scene and application functions

334 Diff Diff IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

330 Diff Diff IonutCava picture IonutCava Fri 10 Oct, 2014 17:19:11 +0000

[Ionut]
- New rendering algorithm :
— Perform second pass for visible nodes gathering all render commands and uploading them to an indirect draw buffer
— Render geometry with indirect draw commands
— Removed per-node range binding of the node buffer. Instead, bind the entire buffer once and index data in shaders
— Use “baseInstance” parameter from IndirectDrawCommand as a node buffer index
— Prefer DSA extensions for updating buffer data where applicable
- Moved all rendering specific code from SceneGraphNode to a new RenderingComponent
- Optimized “toString” utility function

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

304 IonutCava picture IonutCava Sun 10 Aug, 2014 21:10:54 +0000

[Ionut]
- Redesigned the WorldEditor (dummy functions added for every button/option)
- Improved debug rendering performance by using static IMPrimitives for axis gizmo rendering
- Simplified skeleton rendering