diff --git a/.efrocachemap b/.efrocachemap index d84f2ebd..527065e0 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -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" } \ No newline at end of file diff --git a/docs/ba_module.md b/docs/ba_module.md index 402190a2..c47b585d 100644 --- a/docs/ba_module.md +++ b/docs/ba_module.md @@ -1,5 +1,5 @@ -

last updated on 2020-10-21 for Ballistica version 1.5.27 build 20224

+

last updated on 2020-10-25 for Ballistica version 1.5.27 build 20224

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 let me know. Happy modding!


diff --git a/src/ballistica/app/app.h b/src/ballistica/app/app.h index 2313a445..32d03482 100644 --- a/src/ballistica/app/app.h +++ b/src/ballistica/app/app.h @@ -3,10 +3,10 @@ #ifndef BALLISTICA_APP_APP_H_ #define BALLISTICA_APP_APP_H_ -#include #include #include #include +#include #include "ballistica/core/module.h" @@ -139,7 +139,7 @@ class App : public Module { std::unique_ptr stress_test_; millisecs_t last_resize_draw_event_time_{}; millisecs_t last_app_resume_time_{}; - std::map product_prices_; + std::unordered_map product_prices_; std::mutex product_prices_mutex_; }; diff --git a/src/ballistica/app/app_globals.h b/src/ballistica/app/app_globals.h index 5a7e6ec5..68b565e9 100644 --- a/src/ballistica/app/app_globals.h +++ b/src/ballistica/app/app_globals.h @@ -3,10 +3,10 @@ #ifndef BALLISTICA_APP_APP_GLOBALS_H_ #define BALLISTICA_APP_APP_GLOBALS_H_ -#include #include #include #include +#include #include #include "ballistica/ballistica.h" @@ -31,9 +31,9 @@ class AppGlobals { /// Program argument values (on applicable platforms). char** argv{}; - std::map node_types; - std::map node_types_by_id; - std::map node_message_types; + std::unordered_map node_types; + std::unordered_map node_types_by_id; + std::unordered_map node_message_types; std::vector 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 thread_name_map; + std::unordered_map thread_name_map; #if BA_DEBUG_BUILD std::mutex object_list_mutex; Object* object_list_first{}; diff --git a/src/ballistica/audio/audio_server.h b/src/ballistica/audio/audio_server.h index 68f89598..4fd758db 100644 --- a/src/ballistica/audio/audio_server.h +++ b/src/ballistica/audio/audio_server.h @@ -119,6 +119,9 @@ class AudioServer : public Module { // Use sources, not this, for faster iterating. std::vector > 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 sound_fade_nodes_; // This mutex controls access to our list of media component shared ptrs to diff --git a/src/ballistica/ballistica.cc b/src/ballistica/ballistica.cc index 717a5a84..9fa746e4 100644 --- a/src/ballistica/ballistica.cc +++ b/src/ballistica/ballistica.cc @@ -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. diff --git a/src/ballistica/core/object.cc b/src/ballistica/core/object.cc index fe09a89c..d3dc69a2 100644 --- a/src/ballistica/core/object.cc +++ b/src/ballistica/core/object.cc @@ -3,9 +3,9 @@ #include "ballistica/core/object.h" #include -#include #include #include +#include #include #include "ballistica/app/app_globals.h" @@ -24,7 +24,7 @@ void Object::PrintObjects() { + std::to_string(GetRealTime()) + ";"; if (explicit_bool(true)) { - std::map obj_map; + std::unordered_map obj_map; // Tally up counts for all types. int count = 0; diff --git a/src/ballistica/core/thread.cc b/src/ballistica/core/thread.cc index c74ed90c..7d0c75e2 100644 --- a/src/ballistica/core/thread.cc +++ b/src/ballistica/core/thread.cc @@ -2,7 +2,7 @@ #include "ballistica/core/thread.h" -#include +#include #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 tally; + std::unordered_map tally; Log("Thread message tally (" + std::to_string(thread_messages_.size()) + " in list):"); for (auto&& m : thread_messages_) { diff --git a/src/ballistica/dynamics/dynamics.cc b/src/ballistica/dynamics/dynamics.cc index a8837a3e..463cf78f 100644 --- a/src/ballistica/dynamics/dynamics.cc +++ b/src/ballistica/dynamics/dynamics.cc @@ -93,8 +93,52 @@ class Dynamics::CollisionEvent { collision(collision_in) {} }; +class Dynamics::SrcPartCollideMap { + public: + std::unordered_map > dst_part_collisions; +}; + +class Dynamics::DstNodeCollideMap { + public: + std::unordered_map src_parts; + int collideDisabled; + DstNodeCollideMap() : collideDisabled(0) {} + ~DstNodeCollideMap() = default; +}; + +class Dynamics::SrcNodeCollideMap { + public: + std::unordered_map 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::iterator& k, + const std::unordered_map >::iterator& l) + -> void; + + private: + Dynamics* dynamics_{}; + // Contains in-progress collisions for current nodes. + std::unordered_map 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(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 > dst_part_collisions; -}; - -class Dynamics::DstNodeCollideMap { - public: - std::map src_parts; - int collideDisabled; - DstNodeCollideMap() : collideDisabled(0) {} - ~DstNodeCollideMap() = default; -}; - -class Dynamics::SrcNodeCollideMap { - public: - std::map 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 >::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())); + std::pair >::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* 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::iterator& - i, - const std::map::iterator& - j, - const std::map::iterator& k, - const std::map >::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::iterator& k, + const std::unordered_map >::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::iterator i_next; - std::map::iterator j_next; - std::map::iterator k_next; - std::map >::iterator l_next; - for (auto i = node_collisions_.begin(); i != node_collisions_.end(); - i = i_next) { + std::unordered_map::iterator i_next; + std::unordered_map::iterator j_next; + std::unordered_map::iterator k_next; + std::unordered_map >::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()); diff --git a/src/ballistica/dynamics/dynamics.h b/src/ballistica/dynamics/dynamics.h index 5db61a40..61584782 100644 --- a/src/ballistica/dynamics/dynamics.h +++ b/src/ballistica/dynamics/dynamics.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_DYNAMICS_DYNAMICS_H_ #define BALLISTICA_DYNAMICS_DYNAMICS_H_ -#include #include +#include #include #include "ballistica/core/object.h" @@ -82,6 +82,7 @@ class Dynamics : public Object { class SrcPartCollideMap; class CollisionEvent; class CollisionReset; + class Impl; std::vector 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 node_collisions_; std::vector collision_events_; - auto HandleDisconnect( - const std::map::iterator& i, - const std::map::iterator& j, - const std::map::iterator& k, - const std::map >::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_; bool processing_collisions_{}; dWorldID ode_world_{}; dJointGroupID ode_contact_group_{}; @@ -122,6 +116,7 @@ class Dynamics : public Object { Object::WeakRef active_collide_src_node_; Object::WeakRef active_collide_dst_node_; std::unique_ptr collision_cache_; + friend class Impl; }; } // namespace ballistica diff --git a/src/ballistica/game/account.h b/src/ballistica/game/account.h index 103ded74..a471b61a 100644 --- a/src/ballistica/game/account.h +++ b/src/ballistica/game/account.h @@ -3,9 +3,9 @@ #ifndef BALLISTICA_GAME_ACCOUNT_H_ #define BALLISTICA_GAME_ACCOUNT_H_ -#include #include #include +#include #include #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 product_purchases_; + std::unordered_map product_purchases_; int product_purchases_state_{}; std::string account_name_; std::string account_id_; diff --git a/src/ballistica/game/connection/connection.h b/src/ballistica/game/connection/connection.h index 3629ac85..d4565f66 100644 --- a/src/ballistica/game/connection/connection.h +++ b/src/ballistica/game/connection/connection.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_H_ #define BALLISTICA_GAME_CONNECTION_CONNECTION_H_ -#include #include +#include #include #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 in_messages_; - std::map out_messages_; + std::unordered_map in_messages_; + std::unordered_map out_messages_; bool can_communicate_{}; bool errored_{}; millisecs_t last_prune_time_{}; diff --git a/src/ballistica/game/connection/connection_set.h b/src/ballistica/game/connection/connection_set.h index 62e6ef18..50335629 100644 --- a/src/ballistica/game/connection/connection_set.h +++ b/src/ballistica/game/connection/connection_set.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_SET_H_ #define BALLISTICA_GAME_CONNECTION_CONNECTION_SET_H_ -#include #include +#include #include #include "ballistica/core/object.h" @@ -35,7 +35,7 @@ class ConnectionSet { auto GetConnectionToHostUDP() -> ConnectionToHostUDP*; auto connections_to_clients() - -> const std::map >& { + -> const std::unordered_map >& { 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 > connections_to_clients_; + std::unordered_map > + connections_to_clients_; Object::Ref connection_to_host_; ClientControllerInterface* client_controller_{}; @@ -126,8 +127,8 @@ class ConnectionSet { bool printed_host_disconnect_{}; #if BA_GOOGLE_BUILD - std::map google_play_id_to_client_id_map_; - std::map client_id_to_google_play_id_map_; + std::unordered_map google_play_id_to_client_id_map_; + std::unordered_map client_id_to_google_play_id_map_; #endif }; diff --git a/src/ballistica/game/connection/connection_to_client.h b/src/ballistica/game/connection/connection_to_client.h index c234bea5..2a509344 100644 --- a/src/ballistica/game/connection/connection_to_client.h +++ b/src/ballistica/game/connection/connection_to_client.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_GAME_CONNECTION_CONNECTION_TO_CLIENT_H_ #define BALLISTICA_GAME_CONNECTION_CONNECTION_TO_CLIENT_H_ -#include #include +#include #include #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 client_input_devices_; + std::unordered_map client_input_devices_; millisecs_t last_hand_shake_send_time_ = 0; int id_ = -1; int build_number_ = 0; diff --git a/src/ballistica/game/game.cc b/src/ballistica/game/game.cc index c6bd0b97..ce414e86 100644 --- a/src/ballistica/game/game.cc +++ b/src/ballistica/game/game.cc @@ -1530,7 +1530,8 @@ void Game::Process() { UpdateProcessTimer(); } -void Game::SetLanguageKeys(const std::map& language) { +void Game::SetLanguageKeys( + const std::unordered_map& language) { assert(InGameThread()); { std::lock_guard lock(language_mutex_); diff --git a/src/ballistica/game/game.h b/src/ballistica/game/game.h index 0409879c..5f9e0735 100644 --- a/src/ballistica/game/game.h +++ b/src/ballistica/game/game.h @@ -4,11 +4,11 @@ #define BALLISTICA_GAME_GAME_H_ #include -#include #include #include #include #include +#include #include #include @@ -129,8 +129,8 @@ class Game : public Module { const Object::Ref& runnable) -> int; auto DeleteRealTimer(int timer_id) -> void; auto SetRealTimerLength(int timer_id, millisecs_t length) -> void; - auto SetLanguageKeys(const std::map& language) - -> void; + auto SetLanguageKeys( + const std::unordered_map& 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 foreground_scene_; Object::WeakRef foreground_session_; std::mutex language_mutex_; - std::map language_; + std::unordered_map language_; std::mutex special_char_mutex_; - std::map special_char_strings_; + std::unordered_map special_char_strings_; bool ran_app_launch_commands_{}; bool kick_idle_players_{}; std::unique_ptr realtimers_; diff --git a/src/ballistica/game/host_activity.h b/src/ballistica/game/host_activity.h index 8983dcf1..4aebc6a2 100644 --- a/src/ballistica/game/host_activity.h +++ b/src/ballistica/game/host_activity.h @@ -4,8 +4,8 @@ #define BALLISTICA_GAME_HOST_ACTIVITY_H_ #include -#include #include +#include #include "ballistica/core/context.h" #include "ballistica/generic/timer_list.h" @@ -89,11 +89,12 @@ class HostActivity : public ContextTarget { Object::WeakRef globals_node_; bool allow_kick_idle_players_ = false; Timer* step_scene_timer_ = nullptr; - std::map > textures_; - std::map > sounds_; - std::map > datas_; - std::map > collide_models_; - std::map > models_; + std::unordered_map > textures_; + std::unordered_map > sounds_; + std::unordered_map > datas_; + std::unordered_map > + collide_models_; + std::unordered_map > models_; std::list > materials_; bool shutting_down_ = false; diff --git a/src/ballistica/game/player.h b/src/ballistica/game/player.h index c2594bfe..5ca89cec 100644 --- a/src/ballistica/game/player.h +++ b/src/ballistica/game/player.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_GAME_PLAYER_H_ #define BALLISTICA_GAME_PLAYER_H_ -#include #include +#include #include #include "ballistica/core/object.h" @@ -159,7 +159,7 @@ class Player : public Object { PythonRef py_color_; PythonRef py_highlight_; PythonRef py_activityplayer_; - std::map > calls_; + std::unordered_map > calls_; }; } // namespace ballistica diff --git a/src/ballistica/game/session/host_session.h b/src/ballistica/game/session/host_session.h index 812c9799..e594e52d 100644 --- a/src/ballistica/game/session/host_session.h +++ b/src/ballistica/game/session/host_session.h @@ -4,8 +4,8 @@ #define BALLISTICA_GAME_SESSION_HOST_SESSION_H_ #include -#include #include +#include #include #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 > textures_; - std::map > sounds_; - std::map > datas_; - std::map > models_; + std::unordered_map > textures_; + std::unordered_map > sounds_; + std::unordered_map > datas_; + std::unordered_map > models_; }; } // namespace ballistica diff --git a/src/ballistica/graphics/text/text_graphics.cc b/src/ballistica/graphics/text/text_graphics.cc index f0634e21..d0ee5ea8 100644 --- a/src/ballistica/graphics/text/text_graphics.cc +++ b/src/ballistica/graphics/text/text_graphics.cc @@ -17,7 +17,8 @@ class TextGraphics::TextSpanBoundsCacheEntry : public Object { std::string string; Rect r; float width{}; - std::map>::iterator + std::unordered_map>::iterator map_iterator_; std::list>::iterator list_iterator_; }; diff --git a/src/ballistica/graphics/text/text_graphics.h b/src/ballistica/graphics/text/text_graphics.h index aca2e9f2..b041f2e2 100644 --- a/src/ballistica/graphics/text/text_graphics.h +++ b/src/ballistica/graphics/text/text_graphics.h @@ -4,10 +4,10 @@ #define BALLISTICA_GRAPHICS_TEXT_TEXT_GRAPHICS_H_ #include -#include #include #include #include +#include #include #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::unordered_map > text_span_bounds_cache_map_; // List of entries for sorting by last-use-time diff --git a/src/ballistica/input/device/input_device.cc b/src/ballistica/input/device/input_device.cc index 66a7886a..68f18114 100644 --- a/src/ballistica/input/device/input_device.cc +++ b/src/ballistica/input/device/input_device.cc @@ -4,7 +4,7 @@ #include #include -#include +#include #include "ballistica/app/app_globals.h" #include "ballistica/game/connection/connection_to_host.h" @@ -18,7 +18,8 @@ namespace ballistica { -static std::map* g_rand_name_registry = nullptr; +static std::unordered_map* g_rand_name_registry = + nullptr; std::list 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(); + g_rand_name_registry = new std::unordered_map(); } auto i = g_rand_name_registry->find(full_name); diff --git a/src/ballistica/input/input.h b/src/ballistica/input/input.h index ad3f0f29..b1724af1 100644 --- a/src/ballistica/input/input.h +++ b/src/ballistica/input/input.h @@ -4,9 +4,9 @@ #define BALLISTICA_INPUT_INPUT_H_ #include -#include #include #include +#include #include #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 > reserved_identifiers_; + std::unordered_map > + reserved_identifiers_; int max_controller_count_so_far_{}; std::list newly_connected_controllers_; std::list newly_disconnected_controllers_; diff --git a/src/ballistica/media/media.cc b/src/ballistica/media/media.cc index ecc1a14a..c7cc9c3b 100644 --- a/src/ballistica/media/media.cc +++ b/src/ballistica/media/media.cc @@ -465,8 +465,9 @@ auto Media::GetCollideModelData(const std::string& file_name) } template -auto Media::GetComponentData(const std::string& file_name, - std::map >* c_list) +auto Media::GetComponentData( + const std::string& file_name, + std::unordered_map >* c_list) -> Object::Ref { assert(InGameThread()); assert(media_lists_locked_); @@ -703,7 +704,8 @@ auto Media::GetPendingLoadCount() -> int { template auto Media::GetComponentPendingLoadCount( - std::map >* t_list, MediaType type) -> int { + std::unordered_map >* t_list, MediaType type) + -> int { assert(InGameThread()); assert(media_lists_locked_); diff --git a/src/ballistica/media/media.h b/src/ballistica/media/media.h index 54d49e49..0d8c7b64 100644 --- a/src/ballistica/media/media.h +++ b/src/ballistica/media/media.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_MEDIA_MEDIA_H_ #define BALLISTICA_MEDIA_MEDIA_H_ -#include #include +#include #include #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 - static auto GetMedia(std::map >* list, - const std::string& name, Scene* scene) - -> Object::Ref { + static auto GetMedia( + std::unordered_map >* list, + const std::string& name, Scene* scene) -> Object::Ref { assert(InGameThread()); assert(list); auto i = list->find(name); @@ -166,16 +166,18 @@ class Media { template auto GetComponentPendingLoadCount( - std::map >* t_list, MediaType type) -> int; + std::unordered_map >* t_list, MediaType type) + -> int; template - auto GetComponentData(const std::string& file_name, - std::map >* c_list) + auto GetComponentData( + const std::string& file_name, + std::unordered_map >* c_list) -> Object::Ref; std::vector media_paths_; bool have_pending_loads_[static_cast(MediaType::kLast)]{}; - std::map packages_; + std::unordered_map packages_; // For use by MediaListsLock; don't manually acquire std::mutex media_lists_mutex_; @@ -193,13 +195,14 @@ class Media { std::vector > system_models_; // All existing media by filename (including internal). - std::map > textures_; - std::map > text_textures_; - std::map > qr_textures_; - std::map > models_; - std::map > sounds_; - std::map > datas_; - std::map > collide_models_; + std::unordered_map > textures_; + std::unordered_map > text_textures_; + std::unordered_map > qr_textures_; + std::unordered_map > models_; + std::unordered_map > sounds_; + std::unordered_map > datas_; + std::unordered_map > + collide_models_; // Components that have been preloaded but need to be loaded. std::mutex pending_load_list_mutex_; diff --git a/src/ballistica/networking/networking.h b/src/ballistica/networking/networking.h index 0bff150d..430c6198 100644 --- a/src/ballistica/networking/networking.h +++ b/src/ballistica/networking/networking.h @@ -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 scan_results_; std::mutex scan_results_mutex_; uint32_t next_scan_query_id_{}; diff --git a/src/ballistica/python/methods/python_methods_system.cc b/src/ballistica/python/methods/python_methods_system.cc index 3fc550c2..9967115a 100644 --- a/src/ballistica/python/methods/python_methods_system.cc +++ b/src/ballistica/python/methods/python_methods_system.cc @@ -4,8 +4,8 @@ #include #include -#include #include +#include #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 language; + std::unordered_map language; int size = static_cast(PyList_GET_SIZE(list_obj)); for (int i = 0; i < size; i++) { PyObject* entry = PyList_GET_ITEM(list_obj, i); diff --git a/src/ballistica/scene/node/node.h b/src/ballistica/scene/node/node.h index 67c1727a..ba8776a5 100644 --- a/src/ballistica/scene/node/node.h +++ b/src/ballistica/scene/node/node.h @@ -4,8 +4,8 @@ #define BALLISTICA_SCENE_NODE_NODE_H_ #include -#include #include +#include #include #include "ballistica/ballistica.h" @@ -168,7 +168,7 @@ class Node : public Object { return attribute_connections_; } auto attribute_connections_incoming() const - -> const std::map >& { + -> const std::unordered_map >& { return attribute_connections_incoming_; } @@ -215,7 +215,7 @@ class Node : public Object { std::list > attribute_connections_; // Incoming attr connections by attr index. - std::map > + std::unordered_map > attribute_connections_incoming_; friend class NodeAttributeUnbound; diff --git a/src/ballistica/scene/node/node_type.h b/src/ballistica/scene/node/node_type.h index 7237b500..106b77f7 100644 --- a/src/ballistica/scene/node/node_type.h +++ b/src/ballistica/scene/node/node_type.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_SCENE_NODE_NODE_TYPE_H_ #define BALLISTICA_SCENE_NODE_NODE_TYPE_H_ -#include #include +#include #include #include @@ -71,7 +71,7 @@ class NodeType { NodeCreateFunc* create_call_; int id_; std::string name_; - std::map attributes_by_name_; + std::unordered_map attributes_by_name_; std::vector attributes_by_index_; friend class NodeAttributeUnbound; friend class Node; diff --git a/src/ballistica/scene/scene.h b/src/ballistica/scene/scene.h index dd65277c..b55f4c97 100644 --- a/src/ballistica/scene/scene.h +++ b/src/ballistica/scene/scene.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_SCENE_SCENE_H_ #define BALLISTICA_SCENE_SCENE_H_ -#include #include +#include #include #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 > player_nodes_; + std::unordered_map > player_nodes_; int64_t stream_id_{-1}; Object::WeakRef output_stream_; bool use_fixed_vr_overlay_{}; diff --git a/src/ballistica/ui/ui.h b/src/ballistica/ui/ui.h index ac37e0f9..1c32bbab 100644 --- a/src/ballistica/ui/ui.h +++ b/src/ballistica/ui/ui.h @@ -3,8 +3,8 @@ #ifndef BALLISTICA_UI_UI_H_ #define BALLISTICA_UI_UI_H_ -#include #include +#include #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 > textures_; - std::map > sounds_; - std::map > datas_; - std::map > models_; + std::unordered_map > textures_; + std::unordered_map > sounds_; + std::unordered_map > datas_; + std::unordered_map > models_; }; } // namespace ballistica