mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
make NodeTransitionCache use a vertex instead of a map
This commit is contained in:
parent
8cdb823957
commit
2af9c8b6a9
@ -44,26 +44,6 @@ size() const {
|
||||
return _cache.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodeTransitionCache::begin
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_GRAPH NodeTransitionCache::iterator NodeTransitionCache::
|
||||
begin() {
|
||||
return _cache.begin();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodeTransitionCache::end
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_GRAPH NodeTransitionCache::iterator NodeTransitionCache::
|
||||
end() {
|
||||
return _cache.end();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodeTransitionCache::begin
|
||||
// Access: Public
|
||||
@ -84,17 +64,6 @@ end() const {
|
||||
return _cache.end();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodeTransitionCache::end
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_GRAPH NodeTransitionCache::iterator NodeTransitionCache::
|
||||
insert(NodeTransitionCache::iterator position,
|
||||
const NodeTransitionCache::value_type &item) {
|
||||
return _cache.insert(position, item);
|
||||
}
|
||||
|
||||
INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionCache &ntc) {
|
||||
ntc.output(out);
|
||||
return out;
|
||||
|
@ -21,7 +21,9 @@
|
||||
#include "config_graph.h"
|
||||
#include "setTransitionHelpers.h"
|
||||
|
||||
#include <indent.h>
|
||||
#include "indent.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
TypeHandle NodeTransitionCache::_type_handle;
|
||||
|
||||
@ -75,7 +77,7 @@ NodeTransitionCache(const NodeTransitions &nt) {
|
||||
NodeTransition *trans = (*ti).second;
|
||||
|
||||
if (trans != (NodeTransition *)NULL) {
|
||||
_cache[handle] = NodeTransitionCacheEntry(trans);
|
||||
_cache.push_back(CacheEntry(handle, NodeTransitionCacheEntry(trans)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,15 +167,18 @@ set_transition(TypeHandle handle, NodeTransition *trans) {
|
||||
return clear_transition(handle);
|
||||
|
||||
} else {
|
||||
Cache::iterator ci;
|
||||
ci = _cache.find(handle);
|
||||
if (ci != _cache.end()) {
|
||||
Cache::iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(),
|
||||
CacheEntry(handle, NodeTransitionCacheEntry()),
|
||||
SortCache());
|
||||
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
PT(NodeTransition) result = (*ci).second.get_trans();
|
||||
(*ci).second = NodeTransitionCacheEntry(trans);
|
||||
return result;
|
||||
}
|
||||
|
||||
_cache.insert(Cache::value_type(handle, NodeTransitionCacheEntry(trans)));
|
||||
_cache.insert(ci, Cache::value_type(handle, trans));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -192,11 +197,14 @@ PT(NodeTransition) NodeTransitionCache::
|
||||
clear_transition(TypeHandle handle) {
|
||||
nassertr(handle != TypeHandle::none(), NULL);
|
||||
|
||||
Cache::iterator ci;
|
||||
ci = _cache.find(handle);
|
||||
if (ci != _cache.end()) {
|
||||
Cache::iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(),
|
||||
CacheEntry(handle, NodeTransitionCacheEntry()),
|
||||
SortCache());
|
||||
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
PT(NodeTransition) result = (*ci).second.get_trans();
|
||||
_cache.erase(ci);
|
||||
(*ci).second.clear_trans();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -213,9 +221,12 @@ clear_transition(TypeHandle handle) {
|
||||
bool NodeTransitionCache::
|
||||
has_transition(TypeHandle handle) const {
|
||||
nassertr(handle != TypeHandle::none(), false);
|
||||
Cache::const_iterator ci;
|
||||
ci = _cache.find(handle);
|
||||
if (ci != _cache.end()) {
|
||||
|
||||
Cache::const_iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(),
|
||||
CacheEntry(handle, NodeTransitionCacheEntry()),
|
||||
SortCache());
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
return (*ci).second.has_trans();
|
||||
}
|
||||
return false;
|
||||
@ -231,9 +242,12 @@ has_transition(TypeHandle handle) const {
|
||||
NodeTransition *NodeTransitionCache::
|
||||
get_transition(TypeHandle handle) const {
|
||||
nassertr(handle != TypeHandle::none(), NULL);
|
||||
Cache::const_iterator ci;
|
||||
ci = _cache.find(handle);
|
||||
if (ci != _cache.end()) {
|
||||
|
||||
Cache::const_iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(),
|
||||
CacheEntry(handle, NodeTransitionCacheEntry()),
|
||||
SortCache());
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
return (*ci).second.get_trans();
|
||||
}
|
||||
return NULL;
|
||||
@ -260,9 +274,11 @@ clear() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool NodeTransitionCache::
|
||||
lookup_entry(TypeHandle handle, NodeTransitionCacheEntry &entry) const {
|
||||
Cache::const_iterator ci;
|
||||
ci = _cache.find(handle);
|
||||
if (ci != _cache.end()) {
|
||||
Cache::const_iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(),
|
||||
CacheEntry(handle, NodeTransitionCacheEntry()),
|
||||
SortCache());
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
entry = (*ci).second;
|
||||
return true;
|
||||
}
|
||||
@ -279,7 +295,15 @@ lookup_entry(TypeHandle handle, NodeTransitionCacheEntry &entry) const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void NodeTransitionCache::
|
||||
store_entry(TypeHandle handle, const NodeTransitionCacheEntry &entry) {
|
||||
_cache[handle] = entry;
|
||||
CacheEntry search_entry(handle, entry);
|
||||
Cache::iterator ci =
|
||||
lower_bound(_cache.begin(), _cache.end(), search_entry,
|
||||
SortCache());
|
||||
if (ci != _cache.end() && (*ci).first == handle) {
|
||||
(*ci).second = entry;
|
||||
} else {
|
||||
_cache.insert(ci, search_entry);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -338,7 +362,7 @@ c_union(const NodeTransitionCache *a, const NodeTransitionCache *b) {
|
||||
|
||||
tmap_override_union(a->_cache.begin(), a->_cache.end(),
|
||||
b->_cache.begin(), b->_cache.end(),
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -374,7 +398,7 @@ compose(const NodeTransitionCache *a, const NodeTransitionCache *b) {
|
||||
|
||||
tmap_compose(a->_cache.begin(), a->_cache.end(),
|
||||
b->_cache.begin(), b->_cache.end(),
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -400,7 +424,7 @@ invert(const NodeTransitionCache *a) {
|
||||
NodeTransitionCache *result = new NodeTransitionCache;
|
||||
|
||||
tmap_invert(a->_cache.begin(), a->_cache.end(),
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -435,7 +459,7 @@ invert_compose(const NodeTransitionCache *a, const NodeTransitionCache *b) {
|
||||
|
||||
tmap_invert_compose(a->_cache.begin(), a->_cache.end(),
|
||||
b->_cache.begin(), b->_cache.end(),
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -479,14 +503,14 @@ cached_compose(const NodeTransitionCache *a,
|
||||
a->_cache.begin(), a->_cache.begin(),
|
||||
b->_cache.begin(), b->_cache.end(),
|
||||
now,
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
|
||||
} else {
|
||||
tmap_cached_compose(a->_cache.begin(), a->_cache.end(),
|
||||
cache->_cache.begin(), cache->_cache.end(),
|
||||
b->_cache.begin(), b->_cache.end(),
|
||||
now,
|
||||
inserter(result->_cache, result->_cache.begin()));
|
||||
back_inserter(result->_cache));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -19,14 +19,15 @@
|
||||
#ifndef NODETRANSITIONCACHE_H
|
||||
#define NODETRANSITIONCACHE_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include "nodeTransitionCacheEntry.h"
|
||||
#include "graphHashGenerator.h"
|
||||
#include "nodeTransitions.h"
|
||||
|
||||
#include <referenceCount.h>
|
||||
|
||||
#include "pmap.h"
|
||||
#include "referenceCount.h"
|
||||
#include "firstOfPairLess.h"
|
||||
#include "pvector.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : NodeTransitionCache
|
||||
@ -64,23 +65,23 @@ public:
|
||||
store_entry(TypeHandle handle, const NodeTransitionCacheEntry &entry);
|
||||
|
||||
private:
|
||||
typedef pmap<TypeHandle, NodeTransitionCacheEntry> Cache;
|
||||
typedef pair<TypeHandle, NodeTransitionCacheEntry> CacheEntry;
|
||||
typedef FirstOfPairLess<CacheEntry> SortCache;
|
||||
typedef pvector<CacheEntry> Cache;
|
||||
|
||||
public:
|
||||
// STL-like definitions to allow read-write traversal of the
|
||||
// STL-like definitions to allow read-only traversal of the
|
||||
// individual transitions. Note that each of these is a
|
||||
// NodeTransitionCacheEntry, not simply a PT(NodeTransition).
|
||||
// Beware! These are not safe to use outside of PANDA.DLL.
|
||||
typedef Cache::iterator iterator;
|
||||
typedef Cache::const_iterator iterator;
|
||||
typedef Cache::const_iterator const_iterator;
|
||||
typedef Cache::value_type value_type;
|
||||
typedef Cache::size_type size_type;
|
||||
|
||||
INLINE_GRAPH size_type size() const;
|
||||
INLINE_GRAPH iterator begin();
|
||||
INLINE_GRAPH iterator end();
|
||||
INLINE_GRAPH const_iterator begin() const;
|
||||
INLINE_GRAPH const_iterator end() const;
|
||||
INLINE_GRAPH iterator insert(iterator position, const value_type &item);
|
||||
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user