replace most std::map usage with more efficient std::unordered_map

This commit is contained in:
Eric Froemling 2020-10-25 15:46:34 -05:00
parent 804232589d
commit 3a6eb59d8a
31 changed files with 210 additions and 172 deletions

View File

@ -3932,24 +3932,24 @@
"assets/build/windows/Win32/ucrtbased.dll": "https://files.ballistica.net/cache/ba1/b5/85/f8b6d0558ddb87267f34254b1450",
"assets/build/windows/Win32/vc_redist.x86.exe": "https://files.ballistica.net/cache/ba1/1c/e1/4a1a2eddda2f4aebd5f8b64ab08e",
"assets/build/windows/Win32/vcruntime140d.dll": "https://files.ballistica.net/cache/ba1/50/8d/bc2600ac9491f1b14d659709451f",
"build/prefab/full/linux_x86_64/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/81/be/dd6f786f096520a5450b96b0efd9",
"build/prefab/full/linux_x86_64/release/ballisticacore": "https://files.ballistica.net/cache/ba1/b0/14/defa61c54179e1810f8308cac55c",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/89/2d/9c41cd7bba801f79906a397f9b23",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/78/bb/4656448316b4b5ff7bc348ede9f2",
"build/prefab/full/mac_x86_64/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/81/29/9ec99c71737474a1605181bef5c6",
"build/prefab/full/mac_x86_64/release/ballisticacore": "https://files.ballistica.net/cache/ba1/5b/52/1771901e2344bad49238986c80b2",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/24/59/abed30ff7c1966552a0dbfe56810",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/99/88/2ee8c18b63f64425516050c8a304",
"build/prefab/full/windows_x86/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/6c/6e/90e03410471ddd69aa2eafa7b3d6",
"build/prefab/full/windows_x86/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/1c/da/64018791c880f5ed095d6842c080",
"build/prefab/full/windows_x86_server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/44/c4/59ab73c66476bbbacf123db2f3f1",
"build/prefab/full/windows_x86_server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/e2/3f/5661800cf25e241eba4f0233192b",
"build/prefab/lib/linux_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/66/c9/3b04209f599dea8b8ca4be7d3404",
"build/prefab/lib/linux_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/0d/3b/b7b46c3131cff8a40dfaa001af38",
"build/prefab/lib/linux_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/57/40/0c1d88af3ce14e0f8870ab9ac7ad",
"build/prefab/lib/linux_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/8a/72/02b4eddf662001f05f98288d4ad4",
"build/prefab/lib/mac_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/e1/a1/4d2b0ad4013a93cf040451c17f55",
"build/prefab/lib/mac_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/3e/b3/3782cbf1a2d3910015eadd6299f0",
"build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/d5/cb/04953a61dd28871b139d5f7af8d1",
"build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/e6/52/2d87920dd7ebc63105afc784e7cd"
"build/prefab/full/linux_x86_64/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/5a/0e/c0d740728ec6a91c4058db0de580",
"build/prefab/full/linux_x86_64/release/ballisticacore": "https://files.ballistica.net/cache/ba1/b2/5e/fd7b9b92e62dd673b3f0b8bde257",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/1c/cf/0bcbafccaf1e7cc3e7f2e0fb1a51",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/39/82/ed8272b0ef178a7d625227729b93",
"build/prefab/full/mac_x86_64/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/1b/34/79ba915806f7984d2821c16e61aa",
"build/prefab/full/mac_x86_64/release/ballisticacore": "https://files.ballistica.net/cache/ba1/0d/80/f7277f55432bb4685f0605169d16",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/9c/d2/f2d25f1ede5d806a553ce1da129a",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/1b/42/b968b868eedd97b7be64a1728bfe",
"build/prefab/full/windows_x86/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/79/99/e8fa8f51f33ca94705a4eca05673",
"build/prefab/full/windows_x86/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/2d/dd/3deb44f89955ba8ffdd9ff1fec30",
"build/prefab/full/windows_x86_server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/cb/57/dd199c247cbd2a9651da09eaafcf",
"build/prefab/full/windows_x86_server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/85/a7/968e92f45eb512b0a6546fe64157",
"build/prefab/lib/linux_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/80/d2/d1c6766cf07f4c4828bbd5899f79",
"build/prefab/lib/linux_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/de/49/2cfc34ac856737d903954db5571b",
"build/prefab/lib/linux_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/17/9a/fa66aafdf31fc9bdd92ce382c619",
"build/prefab/lib/linux_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/86/de/7d9c9a2b7bba34c630130ed759c9",
"build/prefab/lib/mac_x86_64/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/de/16/c12809a8a4754329e6da3c1586ec",
"build/prefab/lib/mac_x86_64/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/71/51/edcfb82938dcd3410f2d31547db6",
"build/prefab/lib/mac_x86_64_server/debug/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/73/77/b5c1338380f41d341a799921fe69",
"build/prefab/lib/mac_x86_64_server/release/libballisticacore_internal.a": "https://files.ballistica.net/cache/ba1/0d/5c/c180e7a4d28600125e8dc2b1fbcc"
}

View File

@ -1,5 +1,5 @@
<!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND -->
<h4><em>last updated on 2020-10-21 for Ballistica version 1.5.27 build 20224</em></h4>
<h4><em>last updated on 2020-10-25 for Ballistica version 1.5.27 build 20224</em></h4>
<p>This page documents the Python classes and functions in the 'ba' module,
which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p>
<hr>

View File

@ -3,10 +3,10 @@
#ifndef BALLISTICA_APP_APP_H_
#define BALLISTICA_APP_APP_H_
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include "ballistica/core/module.h"
@ -139,7 +139,7 @@ class App : public Module {
std::unique_ptr<StressTest> stress_test_;
millisecs_t last_resize_draw_event_time_{};
millisecs_t last_app_resume_time_{};
std::map<std::string, std::string> product_prices_;
std::unordered_map<std::string, std::string> product_prices_;
std::mutex product_prices_mutex_;
};

View File

@ -3,10 +3,10 @@
#ifndef BALLISTICA_APP_APP_GLOBALS_H_
#define BALLISTICA_APP_APP_GLOBALS_H_
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
#include "ballistica/ballistica.h"
@ -31,9 +31,9 @@ class AppGlobals {
/// Program argument values (on applicable platforms).
char** argv{};
std::map<std::string, NodeType*> node_types;
std::map<int, NodeType*> node_types_by_id;
std::map<std::string, NodeMessageType> node_message_types;
std::unordered_map<std::string, NodeType*> node_types;
std::unordered_map<int, NodeType*> node_types_by_id;
std::unordered_map<std::string, NodeMessageType> node_message_types;
std::vector<std::string> node_message_formats;
bool have_mods{};
bool replay_open{};
@ -82,7 +82,7 @@ class AppGlobals {
millisecs_t last_real_time_ticks{};
std::mutex real_time_mutex;
std::mutex thread_name_map_mutex;
std::map<std::thread::id, std::string> thread_name_map;
std::unordered_map<std::thread::id, std::string> thread_name_map;
#if BA_DEBUG_BUILD
std::mutex object_list_mutex;
Object* object_list_first{};

View File

@ -119,6 +119,9 @@ class AudioServer : public Module {
// Use sources, not this, for faster iterating.
std::vector<Object::Ref<ThreadSource> > sound_source_refs_;
struct SoundFadeNode;
// NOTE: would use unordered_map here but gcc doesn't seem to allow
// forward-declared template params with them.
std::map<int, SoundFadeNode> sound_fade_nodes_;
// This mutex controls access to our list of media component shared ptrs to

View File

@ -21,7 +21,7 @@
namespace ballistica {
// These are set automatically via script; don't change here.
const int kAppBuildNumber = 20224;
const int kAppBuildNumber = 20227;
const char* kAppVersion = "1.5.27";
// Our standalone globals.

View File

@ -3,9 +3,9 @@
#include "ballistica/core/object.h"
#include <algorithm>
#include <map>
#include <mutex>
#include <string>
#include <unordered_map>
#include <utility>
#include "ballistica/app/app_globals.h"
@ -24,7 +24,7 @@ void Object::PrintObjects() {
+ std::to_string(GetRealTime()) + ";";
if (explicit_bool(true)) {
std::map<std::string, int> obj_map;
std::unordered_map<std::string, int> obj_map;
// Tally up counts for all types.
int count = 0;

View File

@ -2,7 +2,7 @@
#include "ballistica/core/thread.h"
#include <map>
#include <unordered_map>
#include "ballistica/app/app.h"
#include "ballistica/core/fatal_error.h"
@ -446,7 +446,7 @@ void Thread::LogThreadMessageTally() {
if (!writing_tally_) {
writing_tally_ = true;
std::map<std::string, int> tally;
std::unordered_map<std::string, int> tally;
Log("Thread message tally (" + std::to_string(thread_messages_.size())
+ " in list):");
for (auto&& m : thread_messages_) {

View File

@ -93,8 +93,52 @@ class Dynamics::CollisionEvent {
collision(collision_in) {}
};
class Dynamics::SrcPartCollideMap {
public:
std::unordered_map<int, Object::Ref<Collision> > dst_part_collisions;
};
class Dynamics::DstNodeCollideMap {
public:
std::unordered_map<int, SrcPartCollideMap> src_parts;
int collideDisabled;
DstNodeCollideMap() : collideDisabled(0) {}
~DstNodeCollideMap() = default;
};
class Dynamics::SrcNodeCollideMap {
public:
std::unordered_map<int64_t, DstNodeCollideMap> dst_nodes;
};
class Dynamics::Impl {
public:
explicit Impl(Dynamics* dynamics) : dynamics_(dynamics) {}
// NOTE: we need to implement this here in an Impl class because
// gcc currently chokes on unordered_maps with forward-declared types,
// so we can't have this in our header without pushing all our map/collision
// types there too.
auto HandleDisconnect(
const std::unordered_map<
int64_t, ballistica::Dynamics::SrcNodeCollideMap>::iterator& i,
const std::unordered_map<
int64_t, ballistica::Dynamics::DstNodeCollideMap>::iterator& j,
const std::unordered_map<int, SrcPartCollideMap>::iterator& k,
const std::unordered_map<int, Object::Ref<Collision> >::iterator& l)
-> void;
private:
Dynamics* dynamics_{};
// Contains in-progress collisions for current nodes.
std::unordered_map<int64_t, SrcNodeCollideMap> node_collisions_;
friend class Dynamics;
};
Dynamics::Dynamics(Scene* scene_in)
: scene_(scene_in), collision_cache_(new CollisionCache()) {
: scene_(scene_in),
collision_cache_(new CollisionCache()),
impl_(std::make_unique<Impl>(this)) {
ResetODE();
}
@ -107,7 +151,7 @@ Dynamics::~Dynamics() {
}
void Dynamics::Draw(FrameDef* frame_def) {
// draw collisions if desired..
// draw collisions if desired..
#if BA_DEBUG_BUILD && 0
SimpleComponent c(frame_def->overlay_3d_pass());
c.SetColor(1, 0, 0);
@ -162,24 +206,6 @@ void Dynamics::RemoveTrimesh(dGeomID g) {
throw Exception("trimesh not found");
}
class Dynamics::SrcPartCollideMap {
public:
std::map<int, Object::Ref<Collision> > dst_part_collisions;
};
class Dynamics::DstNodeCollideMap {
public:
std::map<int, SrcPartCollideMap> src_parts;
int collideDisabled;
DstNodeCollideMap() : collideDisabled(0) {}
~DstNodeCollideMap() = default;
};
class Dynamics::SrcNodeCollideMap {
public:
std::map<int64_t, DstNodeCollideMap> dst_nodes;
};
auto Dynamics::AreColliding(const Part& p1_in, const Part& p2_in) -> bool {
const Part* p1;
const Part* p2;
@ -194,8 +220,8 @@ auto Dynamics::AreColliding(const Part& p1_in, const Part& p2_in) -> bool {
// Go down the hierarchy until we either find a missing level or
// find the collision.
auto i = node_collisions_.find(p1->node()->id());
if (i != node_collisions_.end()) {
auto i = impl_->node_collisions_.find(p1->node()->id());
if (i != impl_->node_collisions_.end()) {
auto j = i->second.dst_nodes.find(p2->node()->id());
if (j != i->second.dst_nodes.end()) {
auto k = j->second.src_parts.find(p1->id());
@ -222,12 +248,12 @@ auto Dynamics::GetCollision(Part* p1_in, Part* p2_in, MaterialContext** cc1,
p2 = p1_in;
}
std::pair<std::map<int, Object::Ref<Collision> >::iterator, bool> i =
node_collisions_[p1->node()->id()]
.dst_nodes[p2->node()->id()]
.src_parts[p1->id()]
.dst_part_collisions.insert(
std::make_pair(p2->id(), Object::Ref<Collision>()));
std::pair<std::unordered_map<int, Object::Ref<Collision> >::iterator, bool>
i = impl_->node_collisions_[p1->node()->id()]
.dst_nodes[p2->node()->id()]
.src_parts[p1->id()]
.dst_part_collisions.insert(
std::make_pair(p2->id(), Object::Ref<Collision>()));
Collision* new_collision;
@ -257,7 +283,7 @@ auto Dynamics::GetCollision(Part* p1_in, Part* p2_in, MaterialContext** cc1,
// If either disabled collisions between these two nodes, store that.
DstNodeCollideMap* dncm =
&node_collisions_[p1->node()->id()].dst_nodes[p2->node()->id()];
&impl_->node_collisions_[p1->node()->id()].dst_nodes[p2->node()->id()];
if (!(*cc1)->node_collide || !(*cc2)->node_collide) {
dncm->collideDisabled = true;
}
@ -296,13 +322,13 @@ auto Dynamics::GetCollision(Part* p1_in, Part* p2_in, MaterialContext** cc1,
return &(*(i.first->second));
}
void Dynamics::HandleDisconnect(
const std::map<int64_t, ballistica::Dynamics::SrcNodeCollideMap>::iterator&
i,
const std::map<int64_t, ballistica::Dynamics::DstNodeCollideMap>::iterator&
j,
const std::map<int, SrcPartCollideMap>::iterator& k,
const std::map<int, Object::Ref<Collision> >::iterator& l) {
void Dynamics::Impl::HandleDisconnect(
const std::unordered_map<
int64_t, ballistica::Dynamics::SrcNodeCollideMap>::iterator& i,
const std::unordered_map<
int64_t, ballistica::Dynamics::DstNodeCollideMap>::iterator& j,
const std::unordered_map<int, SrcPartCollideMap>::iterator& k,
const std::unordered_map<int, Object::Ref<Collision> >::iterator& l) {
// Handle disconnect equivalents if they were colliding.
if (l->second->collide) {
// Add the contexts' disconnect commands to be executed.
@ -310,18 +336,18 @@ void Dynamics::HandleDisconnect(
m != l->second->src_context.disconnect_actions.end(); m++) {
Part* src_part = l->second->src_part.get();
Part* dst_part = l->second->dst_part.get();
collision_events_.emplace_back(src_part ? src_part->node() : nullptr,
dst_part ? dst_part->node() : nullptr, *m,
l->second);
dynamics_->collision_events_.emplace_back(
src_part ? src_part->node() : nullptr,
dst_part ? dst_part->node() : nullptr, *m, l->second);
}
for (auto m = l->second->dst_context.disconnect_actions.begin();
m != l->second->dst_context.disconnect_actions.end(); m++) {
Part* src_part = l->second->src_part.get();
Part* dst_part = l->second->dst_part.get();
collision_events_.emplace_back(dst_part ? dst_part->node() : nullptr,
src_part ? src_part->node() : nullptr, *m,
l->second);
dynamics_->collision_events_.emplace_back(
dst_part ? dst_part->node() : nullptr,
src_part ? src_part->node() : nullptr, *m, l->second);
}
// Now see if either of the two parts involved still exist and if they do,
@ -375,8 +401,8 @@ void Dynamics::ProcessCollisions() {
// Go down the hierarchy until we either find a missing level or
// find the collision to reset.
{
auto i = node_collisions_.find(n1);
if (i != node_collisions_.end()) {
auto i = impl_->node_collisions_.find(n1);
if (i != impl_->node_collisions_.end()) {
auto j = i->second.dst_nodes.find(n2);
if (j != i->second.dst_nodes.end()) {
auto k = j->second.src_parts.find(p1);
@ -384,7 +410,7 @@ void Dynamics::ProcessCollisions() {
auto l = k->second.dst_part_collisions.find(p2);
if (l != k->second.dst_part_collisions.end()) {
// They were colliding - separate them.
HandleDisconnect(i, j, k, l);
impl_->HandleDisconnect(i, j, k, l);
}
// Erase if none left.
@ -398,7 +424,7 @@ void Dynamics::ProcessCollisions() {
}
// Erase if none left.
if (i->second.dst_nodes.empty()) node_collisions_.erase(i);
if (i->second.dst_nodes.empty()) impl_->node_collisions_.erase(i);
}
}
}
@ -407,7 +433,7 @@ void Dynamics::ProcessCollisions() {
// Reset our claim counts. When we run collision tests, claim counts
// will be incremented for things that are still in contact.
for (auto& node_collision : node_collisions_) {
for (auto& node_collision : impl_->node_collisions_) {
for (auto& dst_node : node_collision.second.dst_nodes) {
for (auto& src_part : dst_node.second.src_parts) {
for (auto& dst_part_collision : src_part.second.dst_part_collisions) {
@ -432,12 +458,12 @@ void Dynamics::ProcessCollisions() {
// setting parts' currently-colliding-with lists
// based on current info,
// removing unclaimed collisions and empty groups.
std::map<int64_t, SrcNodeCollideMap>::iterator i_next;
std::map<int64_t, DstNodeCollideMap>::iterator j_next;
std::map<int, SrcPartCollideMap>::iterator k_next;
std::map<int, Object::Ref<Collision> >::iterator l_next;
for (auto i = node_collisions_.begin(); i != node_collisions_.end();
i = i_next) {
std::unordered_map<int64_t, SrcNodeCollideMap>::iterator i_next;
std::unordered_map<int64_t, DstNodeCollideMap>::iterator j_next;
std::unordered_map<int, SrcPartCollideMap>::iterator k_next;
std::unordered_map<int, Object::Ref<Collision> >::iterator l_next;
for (auto i = impl_->node_collisions_.begin();
i != impl_->node_collisions_.end(); i = i_next) {
i_next = i;
i_next++;
for (auto j = i->second.dst_nodes.begin(); j != i->second.dst_nodes.end();
@ -455,7 +481,7 @@ void Dynamics::ProcessCollisions() {
// Not claimed; separating.
if (!l->second->claim_count) {
HandleDisconnect(i, j, k, l);
impl_->HandleDisconnect(i, j, k, l);
}
}
if (k->second.dst_part_collisions.empty()) {
@ -467,7 +493,7 @@ void Dynamics::ProcessCollisions() {
}
}
if (i->second.dst_nodes.empty()) {
node_collisions_.erase(i);
impl_->node_collisions_.erase(i);
}
}
@ -532,8 +558,8 @@ void Dynamics::CollideCallback(dGeomID o1, dGeomID o2) {
p1 = p2_in;
p2 = p1_in;
}
auto i = node_collisions_.find(p1->node()->id());
if (i != node_collisions_.end()) {
auto i = impl_->node_collisions_.find(p1->node()->id());
if (i != impl_->node_collisions_.end()) {
auto j = i->second.dst_nodes.find(p2->node()->id());
if (j != i->second.dst_nodes.end()) {
auto k = j->second.src_parts.find(p1->id());

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_DYNAMICS_DYNAMICS_H_
#define BALLISTICA_DYNAMICS_DYNAMICS_H_
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -82,6 +82,7 @@ class Dynamics : public Object {
class SrcPartCollideMap;
class CollisionEvent;
class CollisionReset;
class Impl;
std::vector<CollisionReset> collision_resets_;
// Return a collision object between these two parts,
@ -89,21 +90,14 @@ class Dynamics : public Object {
auto GetCollision(Part* p1, Part* p2, MaterialContext** cc1,
MaterialContext** cc2) -> Collision*;
// Contains in-progress collisions for current nodes.
std::map<int64_t, SrcNodeCollideMap> node_collisions_;
std::vector<CollisionEvent> collision_events_;
auto HandleDisconnect(
const std::map<int64_t,
ballistica::Dynamics::SrcNodeCollideMap>::iterator& i,
const std::map<int64_t,
ballistica::Dynamics::DstNodeCollideMap>::iterator& j,
const std::map<int, SrcPartCollideMap>::iterator& k,
const std::map<int, Object::Ref<Collision> >::iterator& l) -> void;
auto ResetODE() -> void;
auto ShutdownODE() -> void;
static auto DoCollideCallback(void* data, dGeomID o1, dGeomID o2) -> void;
auto CollideCallback(dGeomID o1, dGeomID o2) -> void;
auto ProcessCollisions() -> void;
std::unique_ptr<Impl> impl_;
bool processing_collisions_{};
dWorldID ode_world_{};
dJointGroupID ode_contact_group_{};
@ -122,6 +116,7 @@ class Dynamics : public Object {
Object::WeakRef<Node> active_collide_src_node_;
Object::WeakRef<Node> active_collide_dst_node_;
std::unique_ptr<CollisionCache> collision_cache_;
friend class Impl;
};
} // namespace ballistica

View File

@ -3,9 +3,9 @@
#ifndef BALLISTICA_GAME_ACCOUNT_H_
#define BALLISTICA_GAME_ACCOUNT_H_
#include <map>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/ballistica.h"
@ -49,7 +49,7 @@ class Account {
private:
// Protects all access to this account (we're thread-safe).
std::mutex mutex_;
std::map<std::string, bool> product_purchases_;
std::unordered_map<std::string, bool> product_purchases_;
int product_purchases_state_{};
std::string account_name_;
std::string account_id_;

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_H_
#define BALLISTICA_GAME_CONNECTION_CONNECTION_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -126,8 +126,8 @@ class Connection : public Object {
millisecs_t last_average_update_time_{};
millisecs_t creation_time_{};
PlayerSpec peer_spec_; // Name of the account/device on the other end.
std::map<uint16_t, ReliableMessageIn> in_messages_;
std::map<uint16_t, ReliableMessageOut> out_messages_;
std::unordered_map<uint16_t, ReliableMessageIn> in_messages_;
std::unordered_map<uint16_t, ReliableMessageOut> out_messages_;
bool can_communicate_{};
bool errored_{};
millisecs_t last_prune_time_{};

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_SET_H_
#define BALLISTICA_GAME_CONNECTION_CONNECTION_SET_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -35,7 +35,7 @@ class ConnectionSet {
auto GetConnectionToHostUDP() -> ConnectionToHostUDP*;
auto connections_to_clients()
-> const std::map<int, Object::Ref<ConnectionToClient> >& {
-> const std::unordered_map<int, Object::Ref<ConnectionToClient> >& {
return connections_to_clients_;
}
auto client_controller() -> ClientControllerInterface* {
@ -114,7 +114,8 @@ class ConnectionSet {
private:
// Try to minimize the chance a garbage packet will have this id.
int next_connection_to_client_id_{113};
std::map<int, Object::Ref<ConnectionToClient> > connections_to_clients_;
std::unordered_map<int, Object::Ref<ConnectionToClient> >
connections_to_clients_;
Object::Ref<ConnectionToHost> connection_to_host_;
ClientControllerInterface* client_controller_{};
@ -126,8 +127,8 @@ class ConnectionSet {
bool printed_host_disconnect_{};
#if BA_GOOGLE_BUILD
std::map<int, int> google_play_id_to_client_id_map_;
std::map<int, int> client_id_to_google_play_id_map_;
std::unordered_map<int, int> google_play_id_to_client_id_map_;
std::unordered_map<int, int> client_id_to_google_play_id_map_;
#endif
};

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_TO_CLIENT_H_
#define BALLISTICA_GAME_CONNECTION_CONNECTION_TO_CLIENT_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/game/connection/connection.h"
@ -52,7 +52,7 @@ class ConnectionToClient : public Connection {
std::string our_handshake_salt_;
std::string peer_public_account_id_;
ClientControllerInterface* controller_ = nullptr;
std::map<int, ClientInputDevice*> client_input_devices_;
std::unordered_map<int, ClientInputDevice*> client_input_devices_;
millisecs_t last_hand_shake_send_time_ = 0;
int id_ = -1;
int build_number_ = 0;

View File

@ -1530,7 +1530,8 @@ void Game::Process() {
UpdateProcessTimer();
}
void Game::SetLanguageKeys(const std::map<std::string, std::string>& language) {
void Game::SetLanguageKeys(
const std::unordered_map<std::string, std::string>& language) {
assert(InGameThread());
{
std::lock_guard<std::mutex> lock(language_mutex_);

View File

@ -4,11 +4,11 @@
#define BALLISTICA_GAME_GAME_H_
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@ -129,8 +129,8 @@ class Game : public Module {
const Object::Ref<Runnable>& runnable) -> int;
auto DeleteRealTimer(int timer_id) -> void;
auto SetRealTimerLength(int timer_id, millisecs_t length) -> void;
auto SetLanguageKeys(const std::map<std::string, std::string>& language)
-> void;
auto SetLanguageKeys(
const std::unordered_map<std::string, std::string>& language) -> void;
auto GetResourceString(const std::string& key) -> std::string;
auto CharStr(SpecialChar id) -> std::string;
auto CompileResourceString(const std::string& s, const std::string& loc,
@ -309,9 +309,9 @@ class Game : public Module {
Object::WeakRef<Scene> foreground_scene_;
Object::WeakRef<Session> foreground_session_;
std::mutex language_mutex_;
std::map<std::string, std::string> language_;
std::unordered_map<std::string, std::string> language_;
std::mutex special_char_mutex_;
std::map<SpecialChar, std::string> special_char_strings_;
std::unordered_map<SpecialChar, std::string> special_char_strings_;
bool ran_app_launch_commands_{};
bool kick_idle_players_{};
std::unique_ptr<TimerList> realtimers_;

View File

@ -4,8 +4,8 @@
#define BALLISTICA_GAME_HOST_ACTIVITY_H_
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include "ballistica/core/context.h"
#include "ballistica/generic/timer_list.h"
@ -89,11 +89,12 @@ class HostActivity : public ContextTarget {
Object::WeakRef<GlobalsNode> globals_node_;
bool allow_kick_idle_players_ = false;
Timer* step_scene_timer_ = nullptr;
std::map<std::string, Object::WeakRef<Texture> > textures_;
std::map<std::string, Object::WeakRef<Sound> > sounds_;
std::map<std::string, Object::WeakRef<Data> > datas_;
std::map<std::string, Object::WeakRef<CollideModel> > collide_models_;
std::map<std::string, Object::WeakRef<Model> > models_;
std::unordered_map<std::string, Object::WeakRef<Texture> > textures_;
std::unordered_map<std::string, Object::WeakRef<Sound> > sounds_;
std::unordered_map<std::string, Object::WeakRef<Data> > datas_;
std::unordered_map<std::string, Object::WeakRef<CollideModel> >
collide_models_;
std::unordered_map<std::string, Object::WeakRef<Model> > models_;
std::list<Object::WeakRef<Material> > materials_;
bool shutting_down_ = false;

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_GAME_PLAYER_H_
#define BALLISTICA_GAME_PLAYER_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -159,7 +159,7 @@ class Player : public Object {
PythonRef py_color_;
PythonRef py_highlight_;
PythonRef py_activityplayer_;
std::map<int, Object::Ref<PythonContextCall> > calls_;
std::unordered_map<int, Object::Ref<PythonContextCall> > calls_;
};
} // namespace ballistica

View File

@ -4,8 +4,8 @@
#define BALLISTICA_GAME_SESSION_HOST_SESSION_H_
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/context.h"
@ -120,10 +120,10 @@ class HostSession : public Session {
bool kick_idle_players_ = false;
millisecs_t last_kick_idle_players_decrement_time_;
millisecs_t next_prune_time_ = 0;
std::map<std::string, Object::WeakRef<Texture> > textures_;
std::map<std::string, Object::WeakRef<Sound> > sounds_;
std::map<std::string, Object::WeakRef<Data> > datas_;
std::map<std::string, Object::WeakRef<Model> > models_;
std::unordered_map<std::string, Object::WeakRef<Texture> > textures_;
std::unordered_map<std::string, Object::WeakRef<Sound> > sounds_;
std::unordered_map<std::string, Object::WeakRef<Data> > datas_;
std::unordered_map<std::string, Object::WeakRef<Model> > models_;
};
} // namespace ballistica

View File

@ -17,7 +17,8 @@ class TextGraphics::TextSpanBoundsCacheEntry : public Object {
std::string string;
Rect r;
float width{};
std::map<std::string, Object::Ref<TextSpanBoundsCacheEntry>>::iterator
std::unordered_map<std::string,
Object::Ref<TextSpanBoundsCacheEntry>>::iterator
map_iterator_;
std::list<Object::Ref<TextSpanBoundsCacheEntry>>::iterator list_iterator_;
};

View File

@ -4,10 +4,10 @@
#define BALLISTICA_GRAPHICS_TEXT_TEXT_GRAPHICS_H_
#include <list>
#include <map>
#include <mutex>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -96,7 +96,7 @@ class TextGraphics {
void LoadGlyphPage(uint32_t index);
// Map of entries for fast lookup.
std::map<std::string, Object::Ref<TextSpanBoundsCacheEntry> >
std::unordered_map<std::string, Object::Ref<TextSpanBoundsCacheEntry> >
text_span_bounds_cache_map_;
// List of entries for sorting by last-use-time

View File

@ -4,7 +4,7 @@
#include <cstring>
#include <list>
#include <map>
#include <unordered_map>
#include "ballistica/app/app_globals.h"
#include "ballistica/game/connection/connection_to_host.h"
@ -18,7 +18,8 @@
namespace ballistica {
static std::map<std::string, std::string>* g_rand_name_registry = nullptr;
static std::unordered_map<std::string, std::string>* g_rand_name_registry =
nullptr;
std::list<std::string> g_default_names;
InputDevice::InputDevice() = default;
@ -46,7 +47,7 @@ static auto GetRandomName(const std::string& full_name) -> std::string {
// Hmm; statically allocating this is giving some crashes on shutdown :-(
if (g_rand_name_registry == nullptr) {
g_rand_name_registry = new std::map<std::string, std::string>();
g_rand_name_registry = new std::unordered_map<std::string, std::string>();
}
auto i = g_rand_name_registry->find(full_name);

View File

@ -4,9 +4,9 @@
#define BALLISTICA_INPUT_INPUT_H_
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -153,7 +153,8 @@ class Input {
auto DestroyKeyboardInputDevices() -> void;
int local_active_input_device_count_{};
millisecs_t last_have_many_local_active_input_devices_check_time_{};
std::map<std::string, std::map<std::string, int> > reserved_identifiers_;
std::unordered_map<std::string, std::unordered_map<std::string, int> >
reserved_identifiers_;
int max_controller_count_so_far_{};
std::list<std::string> newly_connected_controllers_;
std::list<std::string> newly_disconnected_controllers_;

View File

@ -465,8 +465,9 @@ auto Media::GetCollideModelData(const std::string& file_name)
}
template <class T>
auto Media::GetComponentData(const std::string& file_name,
std::map<std::string, Object::Ref<T> >* c_list)
auto Media::GetComponentData(
const std::string& file_name,
std::unordered_map<std::string, Object::Ref<T> >* c_list)
-> Object::Ref<T> {
assert(InGameThread());
assert(media_lists_locked_);
@ -703,7 +704,8 @@ auto Media::GetPendingLoadCount() -> int {
template <class T>
auto Media::GetComponentPendingLoadCount(
std::map<std::string, Object::Ref<T> >* t_list, MediaType type) -> int {
std::unordered_map<std::string, Object::Ref<T> >* t_list, MediaType type)
-> int {
assert(InGameThread());
assert(media_lists_locked_);

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_MEDIA_MEDIA_H_
#define BALLISTICA_MEDIA_MEDIA_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/context.h"
@ -19,12 +19,12 @@ class Media {
static void Init();
~Media();
/// Handy function to try to return a bit of media from a std::map
/// Handy function to try to return a bit of media from a std::unordered_map
/// of weak-refs, loading/adding it if need be.
template <typename T>
static auto GetMedia(std::map<std::string, Object::WeakRef<T> >* list,
const std::string& name, Scene* scene)
-> Object::Ref<T> {
static auto GetMedia(
std::unordered_map<std::string, Object::WeakRef<T> >* list,
const std::string& name, Scene* scene) -> Object::Ref<T> {
assert(InGameThread());
assert(list);
auto i = list->find(name);
@ -166,16 +166,18 @@ class Media {
template <class T>
auto GetComponentPendingLoadCount(
std::map<std::string, Object::Ref<T> >* t_list, MediaType type) -> int;
std::unordered_map<std::string, Object::Ref<T> >* t_list, MediaType type)
-> int;
template <class T>
auto GetComponentData(const std::string& file_name,
std::map<std::string, Object::Ref<T> >* c_list)
auto GetComponentData(
const std::string& file_name,
std::unordered_map<std::string, Object::Ref<T> >* c_list)
-> Object::Ref<T>;
std::vector<std::string> media_paths_;
bool have_pending_loads_[static_cast<int>(MediaType::kLast)]{};
std::map<std::string, std::string> packages_;
std::unordered_map<std::string, std::string> packages_;
// For use by MediaListsLock; don't manually acquire
std::mutex media_lists_mutex_;
@ -193,13 +195,14 @@ class Media {
std::vector<Object::Ref<ModelData> > system_models_;
// All existing media by filename (including internal).
std::map<std::string, Object::Ref<TextureData> > textures_;
std::map<std::string, Object::Ref<TextureData> > text_textures_;
std::map<std::string, Object::Ref<TextureData> > qr_textures_;
std::map<std::string, Object::Ref<ModelData> > models_;
std::map<std::string, Object::Ref<SoundData> > sounds_;
std::map<std::string, Object::Ref<DataData> > datas_;
std::map<std::string, Object::Ref<CollideModelData> > collide_models_;
std::unordered_map<std::string, Object::Ref<TextureData> > textures_;
std::unordered_map<std::string, Object::Ref<TextureData> > text_textures_;
std::unordered_map<std::string, Object::Ref<TextureData> > qr_textures_;
std::unordered_map<std::string, Object::Ref<ModelData> > models_;
std::unordered_map<std::string, Object::Ref<SoundData> > sounds_;
std::unordered_map<std::string, Object::Ref<DataData> > datas_;
std::unordered_map<std::string, Object::Ref<CollideModelData> >
collide_models_;
// Components that have been preloaded but need to be loaded.
std::mutex pending_load_list_mutex_;

View File

@ -140,6 +140,9 @@ class Networking {
private:
void PruneScanResults();
struct ScanResultsEntryPriv;
// Note: would use an unordered_map here but gcc doesn't seem to allow
// forward declarations of their template params.
std::map<std::string, ScanResultsEntryPriv> scan_results_;
std::mutex scan_results_mutex_;
uint32_t next_scan_query_id_{};

View File

@ -4,8 +4,8 @@
#include <algorithm>
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include "ballistica/app/app.h"
#include "ballistica/app/app_config.h"
@ -620,7 +620,7 @@ auto PySetInternalLanguageKeys(PyObject* self, PyObject* args) -> PyObject* {
}
BA_PRECONDITION(PyList_Check(list_obj));
BA_PRECONDITION(PyList_Check(random_names_list_obj));
std::map<std::string, std::string> language;
std::unordered_map<std::string, std::string> language;
int size = static_cast<int>(PyList_GET_SIZE(list_obj));
for (int i = 0; i < size; i++) {
PyObject* entry = PyList_GET_ITEM(list_obj, i);

View File

@ -4,8 +4,8 @@
#define BALLISTICA_SCENE_NODE_NODE_H_
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/ballistica.h"
@ -168,7 +168,7 @@ class Node : public Object {
return attribute_connections_;
}
auto attribute_connections_incoming() const
-> const std::map<int, Object::Ref<NodeAttributeConnection> >& {
-> const std::unordered_map<int, Object::Ref<NodeAttributeConnection> >& {
return attribute_connections_incoming_;
}
@ -215,7 +215,7 @@ class Node : public Object {
std::list<Object::Ref<NodeAttributeConnection> > attribute_connections_;
// Incoming attr connections by attr index.
std::map<int, Object::Ref<NodeAttributeConnection> >
std::unordered_map<int, Object::Ref<NodeAttributeConnection> >
attribute_connections_incoming_;
friend class NodeAttributeUnbound;

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_SCENE_NODE_NODE_TYPE_H_
#define BALLISTICA_SCENE_NODE_NODE_TYPE_H_
#include <map>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@ -71,7 +71,7 @@ class NodeType {
NodeCreateFunc* create_call_;
int id_;
std::string name_;
std::map<std::string, NodeAttributeUnbound*> attributes_by_name_;
std::unordered_map<std::string, NodeAttributeUnbound*> attributes_by_name_;
std::vector<NodeAttributeUnbound*> attributes_by_index_;
friend class NodeAttributeUnbound;
friend class Node;

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_SCENE_SCENE_H_
#define BALLISTICA_SCENE_SCENE_H_
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "ballistica/core/object.h"
@ -89,7 +89,7 @@ class Scene : public Object {
const std::string& format) -> void;
GlobalsNode* globals_node_{}; // Current globals node (if any).
std::map<int, Object::WeakRef<PlayerNode> > player_nodes_;
std::unordered_map<int, Object::WeakRef<PlayerNode> > player_nodes_;
int64_t stream_id_{-1};
Object::WeakRef<GameStream> output_stream_;
bool use_fixed_vr_overlay_{};

View File

@ -3,8 +3,8 @@
#ifndef BALLISTICA_UI_UI_H_
#define BALLISTICA_UI_UI_H_
#include <map>
#include <string>
#include <unordered_map>
#include "ballistica/core/context.h"
#include "ballistica/generic/timer_list.h"
@ -138,10 +138,10 @@ class UI : public ContextTarget {
int ui_lock_count_{};
// Media loaded in the UI context.
std::map<std::string, Object::WeakRef<Texture> > textures_;
std::map<std::string, Object::WeakRef<Sound> > sounds_;
std::map<std::string, Object::WeakRef<Data> > datas_;
std::map<std::string, Object::WeakRef<Model> > models_;
std::unordered_map<std::string, Object::WeakRef<Texture> > textures_;
std::unordered_map<std::string, Object::WeakRef<Sound> > sounds_;
std::unordered_map<std::string, Object::WeakRef<Data> > datas_;
std::unordered_map<std::string, Object::WeakRef<Model> > models_;
};
} // namespace ballistica