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
#include "Headers/ParticleData.h"

#include "Core/Headers/Kernel.h"
#include "Core/Headers/TaskPool.h"

namespace Divide {

ParticleData::ParticleData(U32 particleCount, U32 optionsMask)
{
    _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_const_uint(Properties::PROPERTIES_POS))) {
            _position.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_const_uint(Properties::PROPERTIES_VEL))) {
            _velocity.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_const_uint(Properties::PROPERTIES_ACC))) {
            _acceleration.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_const_uint(Properties::PROPERTIES_COLOR))) {
            _colour.resize(_totalCount, vec4<F32>(0.0f));
        }
        if (BitCompare(_optionsMask,
                       to_const_uint(Properties::PROPERTIES_COLOR_TRANS))) {
            _startColour.resize(_totalCount, vec4<F32>(0.0f));
            _endColour.resize(_totalCount, vec4<F32>(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 = Application::instance().kernel().taskPool();
    TaskHandle updateTask = CreateTask(pool, DELEGATE_CBK<void, const Task&>());
    updateTask.addChildTask(CreateTask(pool, parsePositions)._task)->startTask(Task::TaskPriority::HIGH);
    updateTask.addChildTask(CreateTask(pool, parseColours)._task)->startTask(Task::TaskPriority::HIGH);
    updateTask.startTask(Task::TaskPriority::HIGH);
    updateTask.wait();

}

void ParticleData::swapData(U32 indexA, U32 indexB) {
    if (BitCompare(_optionsMask, to_const_uint(Properties::PROPERTIES_POS))) {
        _position[indexA].set(_position[indexB]);
    }
    if (BitCompare(_optionsMask, to_const_uint(Properties::PROPERTIES_VEL))) {
        _velocity[indexA].set(_velocity[indexB]);
    }
    if (BitCompare(_optionsMask, to_const_uint(Properties::PROPERTIES_ACC))) {
        _acceleration[indexA].set(_acceleration[indexB]);
    }
    if (BitCompare(_optionsMask, to_const_uint(Properties::PROPERTIES_COLOR))) {
        _colour[indexA].set(_colour[indexB]);
    }
    if (BitCompare(_optionsMask, to_const_uint(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
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 Diff Diff 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

799 Diff Diff IonutCava picture IonutCava Thu 24 Nov, 2016 22:55:23 +0000

[IonutCava]
- Performance analysis guided optimizations.

737 Diff Diff IonutCava picture IonutCava Thu 23 Jun, 2016 16:20:05 +0000

[IonutCava]
- Improved GenericVertexData structure (separate buffer data from attribute data entirely)
- Added a VAO pool for OpenGL so that all requested VAOs are allocated on the main thread
- Added a mainThreadTask system to queue a task to run on the main thread and optionally wait for it to complete
- Added the option to specify generic geometry for the particle system with an optional index buffer

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

669 Diff Diff IonutCava picture IonutCava Mon 04 Apr, 2016 16:15:35 +0000

[IonutCava]
- Move Task creation calls to TaskPool.h
- Allow tasks to use any pool, but default behaviour is to use the Kernel’s main task pool
- Change image transparency check to use the task pool instead of OpenMP
— Perfect place for future parallel_for implementation
- Warning fixes
- Some method renaming for improved readability

663 Diff Diff IonutCava picture IonutCava Tue 29 Mar, 2016 16:07:31 +0000

[IonutCava]
- Reworked task parent<->children system to allow child tasks to be started immediately after creation (to get adding and running to run in parallel)
- Added locked variable support to the debugging system

662 Diff Diff IonutCava picture IonutCava Mon 28 Mar, 2016 18:46:06 +0000

[Ionut]
- stopRequested param for Task callbacks should be an atomic const reference
- DebugInterface thread safety updates
- Initial code for locked Tasks (tasks that can’t be reset)

661 IonutCava picture IonutCava Wed 23 Mar, 2016 17:05:38 +0000

[Ionut]
- Added initial code for a debug variable system that will allow tracking, displaying and changing any registered variable in the code
- Replaced some particle async based jobs with tasks