Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-20 13:16:20 +0300
committerJacques Lucke <jacques@blender.org>2020-07-20 13:16:20 +0300
commit8cbbdedaf4dfec9e320e7e2be58b75d256950df1 (patch)
tree496b9620e11ac44e515b0bb4ca52c05834d557f9 /source/blender/simulation/intern
parent686ab4c9401a90b22fb17e46c992eb513fe4f693 (diff)
Refactor: Update integer type usage
This updates the usage of integer types in code I wrote according to our new style guides. Major changes: * Use signed instead of unsigned integers in many places. * C++ containers in blenlib use `int64_t` for size and indices now (instead of `uint`). * Hash values for C++ containers are 64 bit wide now (instead of 32 bit). I do hope that I broke no builds, but it is quite likely that some compiler reports slightly different errors. Please let me know when there are any errors. If the fix is small, feel free to commit it yourself. I compiled successfully on linux with gcc and on windows.
Diffstat (limited to 'source/blender/simulation/intern')
-rw-r--r--source/blender/simulation/intern/particle_allocator.cc14
-rw-r--r--source/blender/simulation/intern/particle_allocator.hh16
-rw-r--r--source/blender/simulation/intern/particle_function.cc14
-rw-r--r--source/blender/simulation/intern/particle_function.hh8
-rw-r--r--source/blender/simulation/intern/simulation_collect_influences.cc14
-rw-r--r--source/blender/simulation/intern/simulation_solver.cc31
6 files changed, 48 insertions, 49 deletions
diff --git a/source/blender/simulation/intern/particle_allocator.cc b/source/blender/simulation/intern/particle_allocator.cc
index b65c0197c76..eb1e998e63a 100644
--- a/source/blender/simulation/intern/particle_allocator.cc
+++ b/source/blender/simulation/intern/particle_allocator.cc
@@ -21,7 +21,7 @@ namespace blender::sim {
AttributesAllocator::~AttributesAllocator()
{
for (std::unique_ptr<AttributesBlock> &block : allocated_blocks_) {
- for (uint i : attributes_info_.index_range()) {
+ for (int i : attributes_info_.index_range()) {
const fn::CPPType &type = attributes_info_.type_of(i);
type.destruct_n(block->buffers[i], block->size);
MEM_freeN(block->buffers[i]);
@@ -29,13 +29,13 @@ AttributesAllocator::~AttributesAllocator()
}
}
-fn::MutableAttributesRef AttributesAllocator::allocate_uninitialized(uint size)
+fn::MutableAttributesRef AttributesAllocator::allocate_uninitialized(int size)
{
std::unique_ptr<AttributesBlock> block = std::make_unique<AttributesBlock>();
block->buffers = Array<void *>(attributes_info_.size(), nullptr);
block->size = size;
- for (uint i : attributes_info_.index_range()) {
+ for (int i : attributes_info_.index_range()) {
const fn::CPPType &type = attributes_info_.type_of(i);
void *buffer = MEM_mallocN_aligned(size * type.size(), type.alignment(), AT);
block->buffers[i] = buffer;
@@ -53,17 +53,17 @@ fn::MutableAttributesRef AttributesAllocator::allocate_uninitialized(uint size)
return attributes;
}
-fn::MutableAttributesRef ParticleAllocator::allocate(uint size)
+fn::MutableAttributesRef ParticleAllocator::allocate(int size)
{
const fn::AttributesInfo &info = attributes_allocator_.attributes_info();
fn::MutableAttributesRef attributes = attributes_allocator_.allocate_uninitialized(size);
- for (uint i : info.index_range()) {
+ for (int i : info.index_range()) {
const fn::CPPType &type = info.type_of(i);
StringRef name = info.name_of(i);
if (name == "ID") {
- uint start_id = next_id_.fetch_add(size);
+ int start_id = next_id_.fetch_add(size);
MutableSpan<int> ids = attributes.get<int>("ID");
- for (uint pindex : IndexRange(size)) {
+ for (int pindex : IndexRange(size)) {
ids[pindex] = start_id + pindex;
}
}
diff --git a/source/blender/simulation/intern/particle_allocator.hh b/source/blender/simulation/intern/particle_allocator.hh
index f854413c9aa..b742459b3c2 100644
--- a/source/blender/simulation/intern/particle_allocator.hh
+++ b/source/blender/simulation/intern/particle_allocator.hh
@@ -31,13 +31,13 @@ class AttributesAllocator : NonCopyable, NonMovable {
private:
struct AttributesBlock {
Array<void *> buffers;
- uint size;
+ int size;
};
const fn::AttributesInfo &attributes_info_;
Vector<std::unique_ptr<AttributesBlock>> allocated_blocks_;
Vector<fn::MutableAttributesRef> allocated_attributes_;
- uint total_allocated_ = 0;
+ int total_allocated_ = 0;
std::mutex mutex_;
public:
@@ -53,7 +53,7 @@ class AttributesAllocator : NonCopyable, NonMovable {
return allocated_attributes_;
}
- uint total_allocated() const
+ int total_allocated() const
{
return total_allocated_;
}
@@ -63,16 +63,16 @@ class AttributesAllocator : NonCopyable, NonMovable {
return attributes_info_;
}
- fn::MutableAttributesRef allocate_uninitialized(uint size);
+ fn::MutableAttributesRef allocate_uninitialized(int size);
};
class ParticleAllocator : NonCopyable, NonMovable {
private:
AttributesAllocator attributes_allocator_;
- std::atomic<uint> next_id_;
+ std::atomic<int> next_id_;
public:
- ParticleAllocator(const fn::AttributesInfo &attributes_info, uint next_id)
+ ParticleAllocator(const fn::AttributesInfo &attributes_info, int next_id)
: attributes_allocator_(attributes_info), next_id_(next_id)
{
}
@@ -82,12 +82,12 @@ class ParticleAllocator : NonCopyable, NonMovable {
return attributes_allocator_.get_allocations();
}
- uint total_allocated() const
+ int total_allocated() const
{
return attributes_allocator_.total_allocated();
}
- fn::MutableAttributesRef allocate(uint size);
+ fn::MutableAttributesRef allocate(int size);
};
} // namespace blender::sim
diff --git a/source/blender/simulation/intern/particle_function.cc b/source/blender/simulation/intern/particle_function.cc
index 3788fd17e36..e0de68d9b29 100644
--- a/source/blender/simulation/intern/particle_function.cc
+++ b/source/blender/simulation/intern/particle_function.cc
@@ -29,9 +29,9 @@ ParticleFunction::ParticleFunction(const fn::MultiFunction *global_fn,
per_particle_inputs_(per_particle_inputs),
output_is_global_(output_is_global)
{
- for (uint i : output_is_global_.index_range()) {
+ for (int i : output_is_global_.index_range()) {
if (output_is_global_[i]) {
- uint param_index = global_inputs_.size() + global_output_indices_.size();
+ int param_index = global_inputs_.size() + global_output_indices_.size();
fn::MFParamType param_type = global_fn_->param_type(param_index);
BLI_assert(param_type.is_output());
output_types_.append(param_type.data_type());
@@ -39,7 +39,7 @@ ParticleFunction::ParticleFunction(const fn::MultiFunction *global_fn,
global_output_indices_.append(i);
}
else {
- uint param_index = per_particle_inputs_.size() + per_particle_output_indices_.size();
+ int param_index = per_particle_inputs_.size() + per_particle_output_indices_.size();
fn::MFParamType param_type = per_particle_fn_->param_type(param_index);
BLI_assert(param_type.is_output());
output_types_.append(param_type.data_type());
@@ -60,7 +60,7 @@ ParticleFunctionEvaluator::ParticleFunctionEvaluator(
ParticleFunctionEvaluator::~ParticleFunctionEvaluator()
{
- for (uint output_index : outputs_.index_range()) {
+ for (int output_index : outputs_.index_range()) {
void *buffer = outputs_[output_index];
fn::MFDataType data_type = particle_fn_.output_types_[output_index];
BLI_assert(data_type.is_single()); /* For now. */
@@ -83,7 +83,7 @@ void ParticleFunctionEvaluator::compute()
is_computed_ = true;
}
-fn::GVSpan ParticleFunctionEvaluator::get(uint output_index, StringRef expected_name) const
+fn::GVSpan ParticleFunctionEvaluator::get(int output_index, StringRef expected_name) const
{
#ifdef DEBUG
StringRef real_name = particle_fn_.output_names_[output_index];
@@ -115,7 +115,7 @@ void ParticleFunctionEvaluator::compute_globals()
}
/* Add output parameters. */
- for (uint output_index : particle_fn_.global_output_indices_) {
+ for (int output_index : particle_fn_.global_output_indices_) {
fn::MFDataType data_type = particle_fn_.output_types_[output_index];
BLI_assert(data_type.is_single()); /* For now. */
@@ -142,7 +142,7 @@ void ParticleFunctionEvaluator::compute_per_particle()
}
/* Add output parameters. */
- for (uint output_index : particle_fn_.per_particle_output_indices_) {
+ for (int output_index : particle_fn_.per_particle_output_indices_) {
fn::MFDataType data_type = particle_fn_.output_types_[output_index];
BLI_assert(data_type.is_single()); /* For now. */
diff --git a/source/blender/simulation/intern/particle_function.hh b/source/blender/simulation/intern/particle_function.hh
index abed9063bae..bbb40efb388 100644
--- a/source/blender/simulation/intern/particle_function.hh
+++ b/source/blender/simulation/intern/particle_function.hh
@@ -41,8 +41,8 @@ class ParticleFunction {
Array<const ParticleFunctionInput *> global_inputs_;
Array<const ParticleFunctionInput *> per_particle_inputs_;
Array<bool> output_is_global_;
- Vector<uint> global_output_indices_;
- Vector<uint> per_particle_output_indices_;
+ Vector<int> global_output_indices_;
+ Vector<int> per_particle_output_indices_;
Vector<fn::MFDataType> output_types_;
Vector<StringRefNull> output_names_;
@@ -73,9 +73,9 @@ class ParticleFunctionEvaluator {
~ParticleFunctionEvaluator();
void compute();
- fn::GVSpan get(uint output_index, StringRef expected_name) const;
+ fn::GVSpan get(int output_index, StringRef expected_name) const;
- template<typename T> fn::VSpan<T> get(uint output_index, StringRef expected_name) const
+ template<typename T> fn::VSpan<T> get(int output_index, StringRef expected_name) const
{
return this->get(output_index, expected_name).typed<T>();
}
diff --git a/source/blender/simulation/intern/simulation_collect_influences.cc b/source/blender/simulation/intern/simulation_collect_influences.cc
index 98b055802c9..c1b936d9aa3 100644
--- a/source/blender/simulation/intern/simulation_collect_influences.cc
+++ b/source/blender/simulation/intern/simulation_collect_influences.cc
@@ -53,7 +53,7 @@ static Span<const nodes::DNode *> get_particle_simulation_nodes(const nodes::Der
static std::optional<Array<std::string>> compute_global_string_inputs(
nodes::MFNetworkTreeMap &network_map, Span<const fn::MFInputSocket *> sockets)
{
- uint amount = sockets.size();
+ int amount = sockets.size();
if (amount == 0) {
return Array<std::string>();
}
@@ -67,7 +67,7 @@ static std::optional<Array<std::string>> compute_global_string_inputs(
fn::MFParamsBuilder params{network_fn, 1};
Array<std::string> strings(amount, NoInitialization());
- for (uint i : IndexRange(amount)) {
+ for (int i : IndexRange(amount)) {
params.add_uninitialized_single_output(
fn::GMutableSpan(fn::CPPType::get<std::string>(), strings.data() + i, 1));
}
@@ -101,7 +101,7 @@ static void find_and_deduplicate_particle_attribute_nodes(nodes::MFNetworkTreeMa
Map<std::pair<std::string, fn::MFDataType>, Vector<fn::MFNode *>>
attribute_nodes_by_name_and_type;
- for (uint i : attribute_names->index_range()) {
+ for (int i : attribute_names->index_range()) {
attribute_nodes_by_name_and_type
.lookup_or_add_default(
{(*attribute_names)[i], name_sockets[i]->node().output(0).data_type()})
@@ -207,7 +207,7 @@ class ParticleFunctionForce : public ParticleForce {
evaluator.compute();
fn::VSpan<float3> forces = evaluator.get<float3>(0, "Force");
- for (uint i : mask) {
+ for (int64_t i : mask) {
r_combined_force[i] += forces[i];
}
}
@@ -273,13 +273,13 @@ class MyBasicEmitter : public ParticleEmitter {
}
fn::MutableAttributesRef attributes = allocator->allocate(10);
- RandomNumberGenerator rng{(uint)context.simulation_time_interval().start() ^
- DefaultHash<std::string>{}(name_)};
+ RandomNumberGenerator rng{(uint32_t)context.simulation_time_interval().start() ^
+ (uint32_t)DefaultHash<std::string>{}(name_)};
MutableSpan<float3> positions = attributes.get<float3>("Position");
MutableSpan<float3> velocities = attributes.get<float3>("Velocity");
- for (uint i : IndexRange(attributes.size())) {
+ for (int i : IndexRange(attributes.size())) {
positions[i] = rng.get_unit_float3();
velocities[i] = rng.get_unit_float3();
}
diff --git a/source/blender/simulation/intern/simulation_solver.cc b/source/blender/simulation/intern/simulation_solver.cc
index 310261f6c95..8460b9e148e 100644
--- a/source/blender/simulation/intern/simulation_solver.cc
+++ b/source/blender/simulation/intern/simulation_solver.cc
@@ -63,14 +63,14 @@ static const fn::CPPType &custom_to_cpp_data_type(CustomDataType type)
class CustomDataAttributesRef {
private:
Array<void *> buffers_;
- uint size_;
+ int64_t size_;
const fn::AttributesInfo &info_;
public:
- CustomDataAttributesRef(CustomData &custom_data, uint size, const fn::AttributesInfo &info)
+ CustomDataAttributesRef(CustomData &custom_data, int64_t size, const fn::AttributesInfo &info)
: buffers_(info.size(), nullptr), size_(size), info_(info)
{
- for (uint attribute_index : info.index_range()) {
+ for (int attribute_index : info.index_range()) {
StringRefNull name = info.name_of(attribute_index);
const fn::CPPType &cpp_type = info.type_of(attribute_index);
CustomDataType custom_type = cpp_to_custom_data_type(cpp_type);
@@ -108,7 +108,7 @@ static void ensure_attributes_exist(ParticleSimulationState *state, const fn::At
}
} while (found_layer_to_remove);
- for (uint attribute_index : info.index_range()) {
+ for (int attribute_index : info.index_range()) {
StringRefNull attribute_name = info.name_of(attribute_index);
const fn::CPPType &cpp_type = info.type_of(attribute_index);
CustomDataType custom_type = cpp_to_custom_data_type(cpp_type);
@@ -120,8 +120,7 @@ static void ensure_attributes_exist(ParticleSimulationState *state, const fn::At
nullptr,
state->tot_particles,
attribute_name.c_str());
- cpp_type.fill_uninitialized(
- info.default_of(attribute_index), data, (uint)state->tot_particles);
+ cpp_type.fill_uninitialized(info.default_of(attribute_index), data, state->tot_particles);
}
}
}
@@ -156,21 +155,21 @@ void solve_simulation_time_step(Simulation &simulation,
}
LISTBASE_FOREACH (ParticleSimulationState *, state, &simulation.states) {
+
const fn::AttributesInfo &attributes_info = *attribute_infos.lookup_as(state->head.name);
CustomDataAttributesRef custom_data_attributes{
- state->attributes, (uint)state->tot_particles, attributes_info};
+ state->attributes, state->tot_particles, attributes_info};
fn::MutableAttributesRef attributes = custom_data_attributes;
MutableSpan<float3> positions = attributes.get<float3>("Position");
MutableSpan<float3> velocities = attributes.get<float3>("Velocity");
- Array<float3> force_vectors{(uint)state->tot_particles, {0, 0, 0}};
+ Array<float3> force_vectors{state->tot_particles, {0, 0, 0}};
const Vector<const ParticleForce *> *forces = influences.particle_forces.lookup_ptr(
state->head.name);
if (forces != nullptr) {
- ParticleChunkContext particle_chunk_context{IndexMask((uint)state->tot_particles),
- attributes};
+ ParticleChunkContext particle_chunk_context{IndexMask(state->tot_particles), attributes};
ParticleForceContext particle_force_context{
solve_context, particle_chunk_context, force_vectors};
@@ -179,7 +178,7 @@ void solve_simulation_time_step(Simulation &simulation,
}
}
- for (uint i : positions.index_range()) {
+ for (int i : positions.index_range()) {
velocities[i] += force_vectors[i] * time_step;
positions[i] += velocities[i] * time_step;
}
@@ -195,9 +194,9 @@ void solve_simulation_time_step(Simulation &simulation,
const fn::AttributesInfo &attributes_info = *attribute_infos.lookup_as(state->head.name);
ParticleAllocator &allocator = *particle_allocators.lookup_as(state->head.name);
- const uint emitted_particle_amount = allocator.total_allocated();
- const uint old_particle_amount = state->tot_particles;
- const uint new_particle_amount = old_particle_amount + emitted_particle_amount;
+ const int emitted_particle_amount = allocator.total_allocated();
+ const int old_particle_amount = state->tot_particles;
+ const int new_particle_amount = old_particle_amount + emitted_particle_amount;
CustomData_realloc(&state->attributes, new_particle_amount);
@@ -205,11 +204,11 @@ void solve_simulation_time_step(Simulation &simulation,
state->attributes, new_particle_amount, attributes_info};
fn::MutableAttributesRef attributes = custom_data_attributes;
- uint offset = old_particle_amount;
+ int offset = old_particle_amount;
for (fn::MutableAttributesRef emitted_attributes : allocator.get_allocations()) {
fn::MutableAttributesRef dst_attributes = attributes.slice(
IndexRange(offset, emitted_attributes.size()));
- for (uint attribute_index : attributes.info().index_range()) {
+ for (int attribute_index : attributes.info().index_range()) {
fn::GMutableSpan emitted_data = emitted_attributes.get(attribute_index);
fn::GMutableSpan dst = dst_attributes.get(attribute_index);
const fn::CPPType &type = dst.type();