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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "stdafx.h"

#include "Headers/ParticleData.h"

#include "Core/Headers/Kernel.h"
#include "Core/Headers/TaskPool.h"
#include "Platform/Video/Headers/GFXDevice.h"

namespace Divide {

ParticleData::ParticleData(GFXDevice& context, U32 particleCount, U32 optionsMask)
    : _context(context)
{
    _isBillboarded = true;
    // Default particles are quad sprites.
    // To optimise fillrate we could provide geometry that tightly fits the particle's texture
    _particleGeometryVertices.resize(4);
    _particleGeometryVertices[0].set(-0.5f,  0.5f, 0.0f);
    _particleGeometryVertices[1].set(-0.5f, -0.5f, 0.0f);
    _particleGeometryVertices[2].set(0.5f,  0.5f, 0.0f);
    _particleGeometryVertices[3].set(0.5f, -0.5f, 0.0f);
    _particleGeometryType = PrimitiveType::TRIANGLE_STRIP;
    generateParticles(particleCount, optionsMask);
}

ParticleData::~ParticleData()
{
    generateParticles(0, _optionsMask);
}

void ParticleData::generateParticles(U32 particleCount, U32 optionsMask) {
    _totalCount = particleCount;
    _aliveCount = 0;
    _optionsMask = optionsMask;

    _indices.clear();
    _position.clear();
    _velocity.clear();
    _acceleration.clear();
    _misc.clear();
    _colour.clear();
    _startColour.clear();
    _endColour.clear();

    if (_totalCount > 0) {
        if (BitCompare(_optionsMask,
                       to_base(Properties::PROPERTIES_POS))) {
            _position.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_base(Properties::PROPERTIES_VEL))) {
            _velocity.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_base(Properties::PROPERTIES_ACC))) {
            _acceleration.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_base(Properties::PROPERTIES_COLOR))) {
            _colour.resize(_totalCount, FColour(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_base(Properties::PROPERTIES_COLOR_TRANS))) {
            _startColour.resize(_totalCount, FColour(0.0f));
            _endColour.resize(_totalCount, FColour(0.0f));
        }
        _misc.resize(_totalCount, vec4<F32>(0.0f));
    }
}

void ParticleData::kill(U32 index) {
    swapData(index, _aliveCount - 1);
    _aliveCount--;
}

void ParticleData::wake(U32 index) {
    //swapData(index, _aliveCount);
    _aliveCount++;
}

void ParticleData::sort(bool invalidateCache) {
    U32 count = aliveCount();

    if (count == 0) {
        return;
    }

    _indices.resize(count);
    _renderingPositions.resize(count);
    _renderingColours.resize(count);

    for (U32 i = 0; i < count; ++i) {
        std::pair<U32, F32>& idx = _indices[i];
        idx.first = i;
        idx.second = _misc[i].w;
    }
    

    std::sort(std::begin(_indices),
             std::end(_indices),
             [](const std::pair<U32, F32>& indexA, const std::pair<U32, F32>& indexB) {
                 return indexA.second > indexB.second;
             });

   auto parsePositions = [count, this](const Task& parentTask) -> void {
        for (U32 i = 0; i < count; ++i) {
            _renderingPositions[i].set(_position[_indices[i].first]);
        }
    };

    auto parseColours = [count, this](const Task& parentTask) -> void {
        for (U32 i = 0; i < count; ++i) {
            Util::ToByteColour(_colour[_indices[i].first], _renderingColours[i]);
        }
    };
    
    TaskPool& pool = _context.parent().taskPool();
    TaskHandle updateTask = CreateTask(pool, DELEGATE_CBK<void, const Task&>());
    updateTask.addChildTask(CreateTask(pool, parsePositions))->startTask(Task::TaskPriority::HIGH);
    updateTask.addChildTask(CreateTask(pool, parseColours))->startTask(Task::TaskPriority::HIGH);
    updateTask.startTask(Task::TaskPriority::HIGH).wait();
}

void ParticleData::swapData(U32 indexA, U32 indexB) {
    if (BitCompare(_optionsMask, to_base(Properties::PROPERTIES_POS))) {
        _position[indexA].set(_position[indexB]);
    }
    if (BitCompare(_optionsMask, to_base(Properties::PROPERTIES_VEL))) {
        _velocity[indexA].set(_velocity[indexB]);
    }
    if (BitCompare(_optionsMask, to_base(Properties::PROPERTIES_ACC))) {
        _acceleration[indexA].set(_acceleration[indexB]);
    }
    if (BitCompare(_optionsMask, to_base(Properties::PROPERTIES_COLOR))) {
        _colour[indexA].set(_colour[indexB]);
    }
    if (BitCompare(_optionsMask, to_base(Properties::PROPERTIES_COLOR_TRANS))) {
        _startColour[indexA].set(_startColour[indexB]);
        _endColour[indexA].set(_endColour[indexB]);
    }
    _misc[indexA].set(_misc[indexB]);
}

void ParticleData::setParticleGeometry(const vectorImpl<vec3<F32>>& particleGeometryVertices,
                                       const vectorImpl<U32>& particleGeometryIndices,
                                       PrimitiveType particleGeometryType) {
    _particleGeometryVertices = particleGeometryVertices;
    _particleGeometryIndices = particleGeometryIndices;
    _particleGeometryType = particleGeometryType;
}

void ParticleData::setBillboarded(const bool state) {
    _isBillboarded = state;
}
};

Commits for Divide-Framework/trunk/Source Code/Dynamics/Entities/Particles/ParticleData.cpp

Diff revisions: vs.
Revision Author Commited Message
1012 Diff Diff IonutCava picture IonutCava Mon 15 Jan, 2018 17:21:32 +0000

[Ionut]
- Update boost to v1.66
- Performance optimizations

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.

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

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

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

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

842 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 17:25:15 +0000

[IonutCava]
- Start to implement scripting support via ChaiScript: http://chaiscript.com/
- Cleanup DELEGATE_CBK alias

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

811 IonutCava picture IonutCava Wed 11 Jan, 2017 17:26:49 +0000

[IonutCava]
- Fix some threadpool cleanup bugs
- Fix terrain rendering (except underwater caustics)
- Fix terrain loading
- Fix terrain unloading