Replaced most std::map's with std::unordered_map's for more scalability.

This commit is contained in:
2013-04-24 18:12:03 -07:00
parent 0c67ffbbd1
commit 9ef3f4590f
33 changed files with 130 additions and 85 deletions

View File

@@ -55,5 +55,18 @@ public:
KRVector3 nearestPoint(const KRVector3 & v) const; KRVector3 nearestPoint(const KRVector3 & v) const;
}; };
namespace std {
template<>
struct hash<KRAABB> {
public:
size_t operator()(const KRAABB &s) const
{
size_t h1 = std::hash<KRVector3>()(s.min);
size_t h2 = std::hash<KRVector3>()(s.max);
return h1 ^ ( h2 << 1 );
}
};
}
#endif /* defined(KRAABB_H) */ #endif /* defined(KRAABB_H) */

View File

@@ -47,7 +47,7 @@ KRAnimation::KRAnimation(KRContext &context, std::string name) : KRResource(cont
} }
KRAnimation::~KRAnimation() KRAnimation::~KRAnimation()
{ {
for(std::map<std::string, KRAnimationLayer *>::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){ for(std::unordered_map<std::string, KRAnimationLayer *>::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
} }
@@ -69,7 +69,7 @@ bool KRAnimation::save(KRDataBlock &data) {
animation_node->SetAttribute("auto_play", m_auto_play ? "true" : "false"); animation_node->SetAttribute("auto_play", m_auto_play ? "true" : "false");
animation_node->SetAttribute("duration", m_duration); animation_node->SetAttribute("duration", m_duration);
for(std::map<std::string, KRAnimationLayer *>::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){ for(std::unordered_map<std::string, KRAnimationLayer *>::iterator itr = m_layers.begin(); itr != m_layers.end(); ++itr){
(*itr).second->saveXML(animation_node); (*itr).second->saveXML(animation_node);
} }
@@ -120,7 +120,7 @@ KRAnimation *KRAnimation::Load(KRContext &context, const std::string &name, KRDa
} }
std::map<std::string, KRAnimationLayer *> &KRAnimation::getLayers() std::unordered_map<std::string, KRAnimationLayer *> &KRAnimation::getLayers()
{ {
return m_layers; return m_layers;
} }
@@ -139,7 +139,7 @@ void KRAnimation::update(float deltaTime)
m_local_time -= m_duration; m_local_time -= m_duration;
} }
for(std::map<std::string, KRAnimationLayer *>::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) { for(std::unordered_map<std::string, KRAnimationLayer *>::iterator layer_itr = m_layers.begin(); layer_itr != m_layers.end(); layer_itr++) {
KRAnimationLayer *layer = (*layer_itr).second; KRAnimationLayer *layer = (*layer_itr).second;
for(std::vector<KRAnimationAttribute *>::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) { for(std::vector<KRAnimationAttribute *>::iterator attribute_itr = layer->getAttributes().begin(); attribute_itr != layer->getAttributes().end(); attribute_itr++) {
KRAnimationAttribute *attribute = *attribute_itr; KRAnimationAttribute *attribute = *attribute_itr;

View File

@@ -51,7 +51,7 @@ public:
static KRAnimation *Load(KRContext &context, const std::string &name, KRDataBlock *data); static KRAnimation *Load(KRContext &context, const std::string &name, KRDataBlock *data);
void addLayer(KRAnimationLayer *layer); void addLayer(KRAnimationLayer *layer);
std::map<std::string, KRAnimationLayer *> &getLayers(); std::unordered_map<std::string, KRAnimationLayer *> &getLayers();
KRAnimationLayer *getLayer(const char *szName); KRAnimationLayer *getLayer(const char *szName);
void Play(); void Play();
void Stop(); void Stop();
@@ -62,7 +62,7 @@ public:
void setDuration(float duration); void setDuration(float duration);
bool isPlaying(); bool isPlaying();
private: private:
std::map<std::string, KRAnimationLayer *> m_layers; std::unordered_map<std::string, KRAnimationLayer *> m_layers;
bool m_auto_play; bool m_auto_play;
bool m_loop; bool m_loop;
bool m_playing; bool m_playing;

View File

@@ -38,7 +38,7 @@ KRAnimationCurveManager::KRAnimationCurveManager(KRContext &context) : KRContext
} }
KRAnimationCurveManager::~KRAnimationCurveManager() { KRAnimationCurveManager::~KRAnimationCurveManager() {
for(map<std::string, KRAnimationCurve *>::iterator itr = m_animationCurves.begin(); itr != m_animationCurves.end(); ++itr){ for(unordered_map<std::string, KRAnimationCurve *>::iterator itr = m_animationCurves.begin(); itr != m_animationCurves.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
} }
@@ -53,7 +53,7 @@ KRAnimationCurve *KRAnimationCurveManager::getAnimationCurve(const char *szName)
return m_animationCurves[szName]; return m_animationCurves[szName];
} }
std::map<std::string, KRAnimationCurve *> &KRAnimationCurveManager::getAnimationCurves() { std::unordered_map<std::string, KRAnimationCurve *> &KRAnimationCurveManager::getAnimationCurves() {
return m_animationCurves; return m_animationCurves;
} }

View File

@@ -48,10 +48,10 @@ public:
KRAnimationCurve *loadAnimationCurve(const char *szName, KRDataBlock *data); KRAnimationCurve *loadAnimationCurve(const char *szName, KRDataBlock *data);
KRAnimationCurve *getAnimationCurve(const char *szName); KRAnimationCurve *getAnimationCurve(const char *szName);
void addAnimationCurve(KRAnimationCurve *new_animation_curve); void addAnimationCurve(KRAnimationCurve *new_animation_curve);
std::map<std::string, KRAnimationCurve *> &getAnimationCurves(); std::unordered_map<std::string, KRAnimationCurve *> &getAnimationCurves();
private: private:
map<std::string, KRAnimationCurve *> m_animationCurves; unordered_map<std::string, KRAnimationCurve *> m_animationCurves;
}; };

View File

@@ -38,7 +38,7 @@ KRAnimationManager::KRAnimationManager(KRContext &context) : KRContextObject(con
} }
KRAnimationManager::~KRAnimationManager() { KRAnimationManager::~KRAnimationManager() {
for(map<std::string, KRAnimation *>::iterator itr = m_animations.begin(); itr != m_animations.end(); ++itr){ for(unordered_map<std::string, KRAnimation *>::iterator itr = m_animations.begin(); itr != m_animations.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
} }
@@ -67,7 +67,7 @@ KRAnimation *KRAnimationManager::getAnimation(const char *szName) {
return m_animations[szName]; return m_animations[szName];
} }
std::map<std::string, KRAnimation *> &KRAnimationManager::getAnimations() { std::unordered_map<std::string, KRAnimation *> &KRAnimationManager::getAnimations() {
return m_animations; return m_animations;
} }

View File

@@ -48,7 +48,7 @@ public:
KRAnimation *loadAnimation(const char *szName, KRDataBlock *data); KRAnimation *loadAnimation(const char *szName, KRDataBlock *data);
KRAnimation *getAnimation(const char *szName); KRAnimation *getAnimation(const char *szName);
void addAnimation(KRAnimation *new_animation); void addAnimation(KRAnimation *new_animation);
std::map<std::string, KRAnimation *> &getAnimations(); unordered_map<std::string, KRAnimation *> &getAnimations();
void startFrame(float deltaTime); void startFrame(float deltaTime);
void endFrame(float deltaTime); void endFrame(float deltaTime);
@@ -56,7 +56,7 @@ public:
void updateActiveAnimations(KRAnimation *animation); void updateActiveAnimations(KRAnimation *animation);
private: private:
map<std::string, KRAnimation *> m_animations; unordered_map<std::string, KRAnimation *> m_animations;
set<KRAnimation *>m_activeAnimations; set<KRAnimation *>m_activeAnimations;
}; };

View File

@@ -47,7 +47,7 @@ KRAudioManager::KRAudioManager(KRContext &context) : KRContextObject(context)
m_anticlick_block = true; m_anticlick_block = true;
mach_timebase_info(&m_timebase_info); mach_timebase_info(&m_timebase_info);
m_audio_engine = KRAKEN_AUDIO_SIREN; m_audio_engine = KRAKEN_AUDIO_NONE;
m_high_quality_hrtf = false; m_high_quality_hrtf = false;
m_listener_scene = NULL; m_listener_scene = NULL;
@@ -212,7 +212,7 @@ void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, in
int impulse_response_channels = 2; int impulse_response_channels = 2;
for(int channel=0; channel < impulse_response_channels; channel++) { for(int channel=0; channel < impulse_response_channels; channel++) {
bool first_sample = true; bool first_sample = true;
for(std::map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) { for(std::unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
siren_reverb_zone_weight_info zi = (*zone_itr).second; siren_reverb_zone_weight_info zi = (*zone_itr).second;
if(zi.reverb_sample) { if(zi.reverb_sample) {
if(impulse_response_offset < zi.reverb_sample->getFrameCount()) { // Optimization - when mixing multiple impulse responses (i.e. fading between reverb zones), do not process blocks past the end of a shorter impulse response sample when they differ in length if(impulse_response_offset < zi.reverb_sample->getFrameCount()) { // Optimization - when mixing multiple impulse responses (i.e. fading between reverb zones), do not process blocks past the end of a shorter impulse response sample when they differ in length
@@ -264,7 +264,7 @@ void KRAudioManager::renderReverb()
if(&source->getScene() == m_listener_scene) { if(&source->getScene() == m_listener_scene) {
float containment_factor = 0.0f; float containment_factor = 0.0f;
for(std::map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) { for(std::unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
siren_reverb_zone_weight_info zi = (*zone_itr).second; siren_reverb_zone_weight_info zi = (*zone_itr).second;
float gain = zi.weight * zi.reverb_zone->getReverbGain() * zi.reverb_zone->getContainment(source->getWorldTranslation()); float gain = zi.weight * zi.reverb_zone->getReverbGain() * zi.reverb_zone->getContainment(source->getWorldTranslation());
if(gain > containment_factor) containment_factor = gain; if(gain > containment_factor) containment_factor = gain;
@@ -283,7 +283,7 @@ void KRAudioManager::renderReverb()
// KRAudioSample *impulse_response = getContext().getAudioManager()->get("hrtf_kemar_H10e040a"); // KRAudioSample *impulse_response = getContext().getAudioManager()->get("hrtf_kemar_H10e040a");
int impulse_response_blocks = 0; int impulse_response_blocks = 0;
for(std::map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) { for(std::unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
siren_reverb_zone_weight_info zi = (*zone_itr).second; siren_reverb_zone_weight_info zi = (*zone_itr).second;
if(zi.reverb_sample) { if(zi.reverb_sample) {
int zone_sample_blocks = zi.reverb_sample->getFrameCount() / KRENGINE_AUDIO_BLOCK_LENGTH + 1; int zone_sample_blocks = zi.reverb_sample->getFrameCount() / KRENGINE_AUDIO_BLOCK_LENGTH + 1;
@@ -1208,7 +1208,7 @@ void KRAudioManager::cleanupOpenAL()
KRAudioManager::~KRAudioManager() KRAudioManager::~KRAudioManager()
{ {
for(map<std::string, KRAudioSample *>::iterator name_itr=m_sounds.begin(); name_itr != m_sounds.end(); name_itr++) { for(unordered_map<std::string, KRAudioSample *>::iterator name_itr=m_sounds.begin(); name_itr != m_sounds.end(); name_itr++) {
delete (*name_itr).second; delete (*name_itr).second;
} }
@@ -1272,7 +1272,7 @@ void KRAudioManager::add(KRAudioSample *sound)
std::string lower_name = sound->getName(); std::string lower_name = sound->getName();
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower); std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
map<std::string, KRAudioSample *>::iterator name_itr = m_sounds.find(lower_name); unordered_map<std::string, KRAudioSample *>::iterator name_itr = m_sounds.find(lower_name);
if(name_itr != m_sounds.end()) { if(name_itr != m_sounds.end()) {
delete (*name_itr).second; delete (*name_itr).second;
(*name_itr).second = sound; (*name_itr).second = sound;
@@ -1540,8 +1540,8 @@ void KRAudioManager::startFrame(float deltaTime)
// Click Removal - Add ramping of gain changes for audio sources that are continuing to play // Click Removal - Add ramping of gain changes for audio sources that are continuing to play
float gain_anticlick = 0.0f; float gain_anticlick = 0.0f;
std::pair<std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator, std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator> prev_range = m_prev_mapped_sources.equal_range(adjusted_source_dir); std::pair<std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator, std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator> prev_range = m_prev_mapped_sources.equal_range(adjusted_source_dir);
for(std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator prev_itr=prev_range.first; prev_itr != prev_range.second; prev_itr++) { for(std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator prev_itr=prev_range.first; prev_itr != prev_range.second; prev_itr++) {
if( (*prev_itr).second.first == source) { if( (*prev_itr).second.first == source) {
gain_anticlick = (*prev_itr).second.second.second; gain_anticlick = (*prev_itr).second.second.second;
break; break;
@@ -1553,7 +1553,7 @@ void KRAudioManager::startFrame(float deltaTime)
} }
// Click Removal - Map audio sources for ramp-down of gain for audio sources that have been squelched by attenuation // Click Removal - Map audio sources for ramp-down of gain for audio sources that have been squelched by attenuation
for(std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator itr=m_prev_mapped_sources.begin(); itr != m_prev_mapped_sources.end(); itr++) { for(std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator itr=m_prev_mapped_sources.begin(); itr != m_prev_mapped_sources.end(); itr++) {
KRAudioSource *source = (*itr).second.first; KRAudioSource *source = (*itr).second.first;
float source_prev_gain = (*itr).second.second.second; float source_prev_gain = (*itr).second.second.second;
@@ -1561,9 +1561,9 @@ void KRAudioManager::startFrame(float deltaTime)
// Only create ramp-down channels for 3d sources that have been squelched by attenuation; this is not necessary if the sample has completed playing // Only create ramp-down channels for 3d sources that have been squelched by attenuation; this is not necessary if the sample has completed playing
KRVector2 source_position = (*itr).first; KRVector2 source_position = (*itr).first;
std::pair<std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator, std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator> new_range = m_mapped_sources.equal_range(source_position); std::pair<std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator, std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator> new_range = m_mapped_sources.equal_range(source_position);
bool already_merged = false; bool already_merged = false;
for(std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator new_itr=new_range.first; new_itr != new_range.second; new_itr++) { for(std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator new_itr=new_range.first; new_itr != new_range.second; new_itr++) {
if( (*new_itr).second.first == source) { if( (*new_itr).second.first == source) {
already_merged = true; already_merged = true;
break; break;
@@ -1588,7 +1588,7 @@ void KRAudioManager::renderAmbient()
int output_offset = (m_output_accumulation_block_start) % (KRENGINE_REVERB_MAX_SAMPLES * KRENGINE_MAX_OUTPUT_CHANNELS); int output_offset = (m_output_accumulation_block_start) % (KRENGINE_REVERB_MAX_SAMPLES * KRENGINE_MAX_OUTPUT_CHANNELS);
float *buffer = m_workspace[0].realp; float *buffer = m_workspace[0].realp;
for(std::map<std::string, siren_ambient_zone_weight_info>::iterator zone_itr=m_ambient_zone_weights.begin(); zone_itr != m_ambient_zone_weights.end(); zone_itr++) { for(std::unordered_map<std::string, siren_ambient_zone_weight_info>::iterator zone_itr=m_ambient_zone_weights.begin(); zone_itr != m_ambient_zone_weights.end(); zone_itr++) {
siren_ambient_zone_weight_info zi = (*zone_itr).second; siren_ambient_zone_weight_info zi = (*zone_itr).second;
float gain = (*zone_itr).second.weight * zi.ambient_zone->getAmbientGain() * m_global_ambient_gain * m_global_gain; float gain = (*zone_itr).second.weight * zi.ambient_zone->getAmbientGain() * m_global_ambient_gain * m_global_gain;
@@ -1618,7 +1618,7 @@ void KRAudioManager::renderHRTF()
for(int channel=0; channel<impulse_response_channels; channel++) { for(int channel=0; channel<impulse_response_channels; channel++) {
bool first_source = true; bool first_source = true;
std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator itr=m_mapped_sources.begin(); std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > >::iterator itr=m_mapped_sources.begin();
while(itr != m_mapped_sources.end()) { while(itr != m_mapped_sources.end()) {
// Batch together sound sources that are emitted from the same direction // Batch together sound sources that are emitted from the same direction
KRVector2 source_direction = (*itr).first; KRVector2 source_direction = (*itr).first;

View File

@@ -139,7 +139,7 @@ private:
KRVector3 m_listener_forward; KRVector3 m_listener_forward;
KRVector3 m_listener_up; KRVector3 m_listener_up;
map<std::string, KRAudioSample *> m_sounds; unordered_map<std::string, KRAudioSample *> m_sounds;
std::vector<KRDataBlock *> m_bufferPoolIdle; std::vector<KRDataBlock *> m_bufferPoolIdle;
@@ -199,7 +199,7 @@ private:
std::vector<KRVector2> m_hrtf_sample_locations; std::vector<KRVector2> m_hrtf_sample_locations;
float *m_hrtf_data; float *m_hrtf_data;
map<KRVector2, DSPSplitComplex> m_hrtf_spectral[2]; unordered_map<KRVector2, DSPSplitComplex> m_hrtf_spectral[2];
KRVector2 getNearestHRTFSample(const KRVector2 &dir); KRVector2 getNearestHRTFSample(const KRVector2 &dir);
void getHRTFMix(const KRVector2 &dir, KRVector2 &hrtf1, KRVector2 &hrtf2, KRVector2 &hrtf3, KRVector2 &hrtf4, float &mix1, float &mix2, float &mix3, float &mix4); void getHRTFMix(const KRVector2 &dir, KRVector2 &hrtf1, KRVector2 &hrtf2, KRVector2 &hrtf3, KRVector2 &hrtf4, float &mix1, float &mix2, float &mix3, float &mix4);
@@ -207,17 +207,17 @@ private:
DSPSplitComplex getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel); DSPSplitComplex getHRTFSpectral(const KRVector2 &hrtf_dir, const int channel);
std::map<std::string, siren_ambient_zone_weight_info> m_ambient_zone_weights; std::unordered_map<std::string, siren_ambient_zone_weight_info> m_ambient_zone_weights;
float m_ambient_zone_total_weight = 0.0f; // For normalizing zone weights float m_ambient_zone_total_weight = 0.0f; // For normalizing zone weights
std::map<std::string, siren_reverb_zone_weight_info> m_reverb_zone_weights; std::unordered_map<std::string, siren_reverb_zone_weight_info> m_reverb_zone_weights;
float m_reverb_zone_total_weight = 0.0f; // For normalizing zone weights float m_reverb_zone_total_weight = 0.0f; // For normalizing zone weights
boost::signals2::mutex m_mutex; boost::signals2::mutex m_mutex;
mach_timebase_info_data_t m_timebase_info; mach_timebase_info_data_t m_timebase_info;
std::multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > > m_mapped_sources, m_prev_mapped_sources; std::unordered_multimap<KRVector2, std::pair<KRAudioSource *, std::pair<float, float> > > m_mapped_sources, m_prev_mapped_sources;
bool m_anticlick_block; bool m_anticlick_block;
bool m_high_quality_hrtf; // If true, 4 HRTF samples will be interpolated; if false, the nearest HRTF sample will be used without interpolation bool m_high_quality_hrtf; // If true, 4 HRTF samples will be interpolated; if false, the nearest HRTF sample will be used without interpolation
}; };

View File

@@ -38,7 +38,7 @@ KRBundleManager::KRBundleManager(KRContext &context) : KRContextObject(context)
} }
KRBundleManager::~KRBundleManager() { KRBundleManager::~KRBundleManager() {
for(map<std::string, KRBundle *>::iterator itr = m_bundles.begin(); itr != m_bundles.end(); ++itr){ for(unordered_map<std::string, KRBundle *>::iterator itr = m_bundles.begin(); itr != m_bundles.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
m_bundles.empty(); m_bundles.empty();
@@ -55,6 +55,6 @@ KRBundle *KRBundleManager::getBundle(const char *szName) {
return m_bundles[szName]; return m_bundles[szName];
} }
std::map<std::string, KRBundle *> KRBundleManager::getBundles() { std::unordered_map<std::string, KRBundle *> KRBundleManager::getBundles() {
return m_bundles; return m_bundles;
} }

View File

@@ -49,10 +49,10 @@ public:
KRBundle *getBundle(const char *szName); KRBundle *getBundle(const char *szName);
std::vector<std::string> getBundleNames(); std::vector<std::string> getBundleNames();
std::map<std::string, KRBundle *> getBundles(); std::unordered_map<std::string, KRBundle *> getBundles();
private: private:
std::map<std::string, KRBundle *> m_bundles; std::unordered_map<std::string, KRBundle *> m_bundles;
}; };
#endif /* defined(KRBUNDLEMANAGER_H) */ #endif /* defined(KRBUNDLEMANAGER_H) */

View File

@@ -440,7 +440,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector<KRLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector<KRLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, true, false, false, false, false, false, false, true); m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, NULL, 0, true, false, false, false, false, false, false, true);
for(std::map<KRAABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { for(std::unordered_map<KRAABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
KRMat4 matModel = KRMat4(); KRMat4 matModel = KRMat4();
matModel.scale((*itr).first.size() * 0.5f); matModel.scale((*itr).first.size() * 0.5f);
matModel.translate((*itr).first.center()); matModel.translate((*itr).first.center());

View File

@@ -22,6 +22,7 @@ float const D2R = PI * 2 / 360;
#include <set> #include <set>
#include <list> #include <list>
#include <map> #include <map>
#include <unordered_map>
#include <stack> #include <stack>
#include <queue> #include <queue>
#include <iostream> #include <iostream>
@@ -51,6 +52,9 @@ using std::string;
using std::set; using std::set;
using std::list; using std::list;
using std::map; using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::stack; using std::stack;
using std::queue; using std::queue;

View File

@@ -73,7 +73,7 @@ KRMaterial *KRMaterialManager::getMaterial(const char *szName) {
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
map<std::string, KRMaterial *>::iterator itr = m_materials.find(lowerName); unordered_map<std::string, KRMaterial *>::iterator itr = m_materials.find(lowerName);
if(itr == m_materials.end()) { if(itr == m_materials.end()) {
fprintf(stderr, "Material not found: %s\n", szName); fprintf(stderr, "Material not found: %s\n", szName);
// Not found // Not found

View File

@@ -55,7 +55,7 @@ public:
void configure(bool blend_enable, GLenum blend_src, GLenum blend_dest, bool depth_test_enable, GLenum depth_func, bool depth_write_enable); void configure(bool blend_enable, GLenum blend_src, GLenum blend_dest, bool depth_test_enable, GLenum depth_func, bool depth_write_enable);
private: private:
map<std::string, KRMaterial *> m_materials; std::unordered_map<std::string, KRMaterial *> m_materials;
KRTextureManager *m_pTextureManager; KRTextureManager *m_pTextureManager;
KRShaderManager *m_pShaderManager; KRShaderManager *m_pShaderManager;

View File

@@ -55,7 +55,7 @@ KRMeshManager::KRMeshManager(KRContext &context) : KRContextObject(context) {
} }
KRMeshManager::~KRMeshManager() { KRMeshManager::~KRMeshManager() {
for(std::multimap<std::string, KRMesh *>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){ for(std::unordered_multimap<std::string, KRMesh *>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
m_models.empty(); m_models.empty();
@@ -85,8 +85,8 @@ std::vector<KRMesh *> KRMeshManager::getModel(const char *szName) {
std::vector<KRMesh *> matching_models; std::vector<KRMesh *> matching_models;
std::pair<std::multimap<std::string, KRMesh *>::iterator, std::multimap<std::string, KRMesh *>::iterator> range = m_models.equal_range(lowerName); std::pair<std::unordered_multimap<std::string, KRMesh *>::iterator, std::unordered_multimap<std::string, KRMesh *>::iterator> range = m_models.equal_range(lowerName);
for(std::multimap<std::string, KRMesh *>::iterator itr_match = range.first; itr_match != range.second; itr_match++) { for(std::unordered_multimap<std::string, KRMesh *>::iterator itr_match = range.first; itr_match != range.second; itr_match++) {
matching_models.push_back(itr_match->second); matching_models.push_back(itr_match->second);
} }
@@ -99,7 +99,7 @@ std::vector<KRMesh *> KRMeshManager::getModel(const char *szName) {
return matching_models; return matching_models;
} }
std::multimap<std::string, KRMesh *> &KRMeshManager::getModels() { std::unordered_multimap<std::string, KRMesh *> &KRMeshManager::getModels() {
return m_models; return m_models;
} }
@@ -187,7 +187,7 @@ void KRMeshManager::bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, G
fprintf(stderr, "flushBuffers due to VBO exhaustion...\n"); fprintf(stderr, "flushBuffers due to VBO exhaustion...\n");
m_pContext->rotateBuffers(false); m_pContext->rotateBuffers(false);
} }
std::map<GLvoid *, vbo_info_type>::iterator first_itr = m_vbosPool.begin(); std::unordered_map<GLvoid *, vbo_info_type>::iterator first_itr = m_vbosPool.begin();
vbo_info_type firstVBO = first_itr->second; vbo_info_type firstVBO = first_itr->second;
#if GL_OES_vertex_array_object #if GL_OES_vertex_array_object
GLDEBUG(glDeleteVertexArraysOES(1, &firstVBO.vao_handle)); GLDEBUG(glDeleteVertexArraysOES(1, &firstVBO.vao_handle));
@@ -324,7 +324,7 @@ long KRMeshManager::getMemUsed()
long KRMeshManager::getMemActive() long KRMeshManager::getMemActive()
{ {
long mem_active = 0; long mem_active = 0;
for(std::map<GLvoid *, vbo_info_type>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) { for(std::unordered_map<GLvoid *, vbo_info_type>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
mem_active += (*itr).second.size; mem_active += (*itr).second.size;
} }
return mem_active; return mem_active;

View File

@@ -57,7 +57,7 @@ public:
void addModel(KRMesh *model); void addModel(KRMesh *model);
std::vector<std::string> getModelNames(); std::vector<std::string> getModelNames();
std::multimap<std::string, KRMesh *> &getModels(); std::unordered_multimap<std::string, KRMesh *> &getModels();
void bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights, bool static_vbo); void bindVBO(GLvoid *data, GLsizeiptr size, GLvoid *index_data, GLsizeiptr index_data_size, bool enable_vertex, bool enable_normal, bool enable_tangent, bool enable_uva, bool enable_uvb, bool enable_bone_indexes, bool enable_bone_weights, bool static_vbo);
@@ -113,7 +113,7 @@ public:
private: private:
std::multimap<std::string, KRMesh *> m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model std::unordered_multimap<std::string, KRMesh *> m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model
typedef struct vbo_info { typedef struct vbo_info {
GLuint vbo_handle; GLuint vbo_handle;
@@ -126,8 +126,8 @@ private:
long m_vboMemUsed; long m_vboMemUsed;
vbo_info_type m_currentVBO; vbo_info_type m_currentVBO;
std::map<GLvoid *, vbo_info_type> m_vbosActive; std::unordered_map<GLvoid *, vbo_info_type> m_vbosActive;
std::map<GLvoid *, vbo_info_type> m_vbosPool; std::unordered_map<GLvoid *, vbo_info_type> m_vbosPool;
RandomParticleVertexData *m_randomParticleVertexData; RandomParticleVertexData *m_randomParticleVertexData;
VolumetricLightingVertexData *m_volumetricLightingVertexData; VolumetricLightingVertexData *m_volumetricLightingVertexData;

View File

@@ -67,7 +67,7 @@ tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent)
void KRModel::loadModel() { void KRModel::loadModel() {
if(m_models.size() == 0) { if(m_models.size() == 0) {
std::vector<KRMesh *> models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first std::vector<KRMesh *> models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
std::map<KRMesh *, std::vector<KRBone *> > bones; std::unordered_map<KRMesh *, std::vector<KRBone *> > bones;
if(models.size() > 0) { if(models.size() > 0) {
bool all_bones_found = true; bool all_bones_found = true;
for(std::vector<KRMesh *>::iterator model_itr = models.begin(); model_itr != models.end(); model_itr++) { for(std::vector<KRMesh *>::iterator model_itr = models.begin(); model_itr != models.end(); model_itr++) {

View File

@@ -63,7 +63,7 @@ public:
private: private:
std::vector<KRMesh *> m_models; std::vector<KRMesh *> m_models;
std::map<KRMesh *, std::vector<KRBone *> > m_bones; // Outer std::map connects model to set of bones std::unordered_map<KRMesh *, std::vector<KRBone *> > m_bones; // Outer std::map connects model to set of bones
KRTexture *m_pLightMap; KRTexture *m_pLightMap;
std::string m_lightMap; std::string m_lightMap;
std::string m_model_name; std::string m_model_name;

View File

@@ -162,11 +162,11 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
} }
} }
for(std::map<std::string, KRTexture *>::iterator texture_itr = context.getTextureManager()->getTextures().begin(); texture_itr != context.getTextureManager()->getTextures().end(); texture_itr++) { for(std::unordered_map<std::string, KRTexture *>::iterator texture_itr = context.getTextureManager()->getTextures().begin(); texture_itr != context.getTextureManager()->getTextures().end(); texture_itr++) {
resources.push_back((*texture_itr).second); resources.push_back((*texture_itr).second);
} }
for(std::map<std::string, KRMesh *>::iterator mesh_itr = context.getModelManager()->getModels().begin(); mesh_itr != context.getModelManager()->getModels().end(); mesh_itr++) { for(std::unordered_map<std::string, KRMesh *>::iterator mesh_itr = context.getModelManager()->getModels().begin(); mesh_itr != context.getModelManager()->getModels().end(); mesh_itr++) {
resources.push_back((*mesh_itr).second); resources.push_back((*mesh_itr).second);
} }

View File

@@ -85,13 +85,13 @@ std::set<KRReverbZone *> &KRScene::getReverbZones()
return m_reverbZoneNodes; return m_reverbZoneNodes;
} }
void KRScene::render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) { void KRScene::render(KRCamera *pCamera, std::unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
if(new_frame) { if(new_frame) {
// Expire cached occlusion test results. // Expire cached occlusion test results.
// Cached "failed" results are expired on the next frame (marked with .second of -1) // Cached "failed" results are expired on the next frame (marked with .second of -1)
// Cached "success" results are expired after KRENGINE_OCCLUSION_TEST_EXPIRY frames (marked with .second of the last frame // Cached "success" results are expired after KRENGINE_OCCLUSION_TEST_EXPIRY frames (marked with .second of the last frame
std::set<KRAABB> expired_visible_bounds; std::set<KRAABB> expired_visible_bounds;
for(std::map<KRAABB, int>::iterator visible_bounds_itr = visibleBounds.begin(); visible_bounds_itr != visibleBounds.end(); visible_bounds_itr++) { for(std::unordered_map<KRAABB, int>::iterator visible_bounds_itr = visibleBounds.begin(); visible_bounds_itr != visibleBounds.end(); visible_bounds_itr++) {
if((*visible_bounds_itr).second == -1 || (*visible_bounds_itr).second + KRENGINE_OCCLUSION_TEST_EXPIRY < getContext().getCurrentFrame()) { if((*visible_bounds_itr).second == -1 || (*visible_bounds_itr).second + KRENGINE_OCCLUSION_TEST_EXPIRY < getContext().getCurrentFrame()) {
expired_visible_bounds.insert((*visible_bounds_itr).first); expired_visible_bounds.insert((*visible_bounds_itr).first);
} }
@@ -156,7 +156,7 @@ void KRScene::render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, co
} }
} }
void KRScene::render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly) void KRScene::render(KROctreeNode *pOctreeNode, std::unordered_map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
{ {
if(pOctreeNode) { if(pOctreeNode) {
@@ -226,7 +226,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBo
if(!bVisible) { if(!bVisible) {
// Check if a previous occlusion query has returned true, taking advantage of temporal consistency of visible elements from frame to frame // Check if a previous occlusion query has returned true, taking advantage of temporal consistency of visible elements from frame to frame
// If the previous frame rendered this octree, then attempt to render it in this frame without performing a pre-occlusion test // If the previous frame rendered this octree, then attempt to render it in this frame without performing a pre-occlusion test
std::map<KRAABB, int>::iterator match_itr = visibleBounds.find(octreeBounds); std::unordered_map<KRAABB, int>::iterator match_itr = visibleBounds.find(octreeBounds);
if(match_itr != visibleBounds.end()) { if(match_itr != visibleBounds.end()) {
if((*match_itr).second == -1) { if((*match_itr).second == -1) {
// We have already tested these bounds with a negative result // We have already tested these bounds with a negative result

View File

@@ -67,9 +67,9 @@ public:
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask);
void renderFrame(float deltaTime, int width, int height); void renderFrame(float deltaTime, int width, int height);
void render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame); void render(KRCamera *pCamera, std::unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
void render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly); void render(KROctreeNode *pOctreeNode, std::unordered_map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
void updateOctree(const KRViewport &viewport); void updateOctree(const KRViewport &viewport);

View File

@@ -36,7 +36,7 @@ KRSceneManager::KRSceneManager(KRContext &context) : KRContextObject(context){
} }
KRSceneManager::~KRSceneManager() { KRSceneManager::~KRSceneManager() {
for(map<std::string, KRScene *>::iterator itr = m_scenes.begin(); itr != m_scenes.end(); ++itr){ for(unordered_map<std::string, KRScene *>::iterator itr = m_scenes.begin(); itr != m_scenes.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
m_scenes.empty(); m_scenes.empty();
@@ -53,7 +53,7 @@ KRScene *KRSceneManager::getScene(const char *szName) {
} }
KRScene *KRSceneManager::getFirstScene() { KRScene *KRSceneManager::getFirstScene() {
static std::map<std::string, KRScene *>::iterator scene_itr = m_scenes.begin(); static std::unordered_map<std::string, KRScene *>::iterator scene_itr = m_scenes.begin();
if(scene_itr == m_scenes.end()) { if(scene_itr == m_scenes.end()) {
return NULL; return NULL;
} else { } else {
@@ -61,7 +61,7 @@ KRScene *KRSceneManager::getFirstScene() {
} }
} }
std::map<std::string, KRScene *> KRSceneManager::getScenes() { std::unordered_map<std::string, KRScene *> KRSceneManager::getScenes() {
return m_scenes; return m_scenes;
} }

View File

@@ -50,11 +50,11 @@ public:
KRScene *getFirstScene(); KRScene *getFirstScene();
std::vector<std::string> getSceneNames(); std::vector<std::string> getSceneNames();
std::map<std::string, KRScene *> getScenes(); std::unordered_map<std::string, KRScene *> getScenes();
private: private:
std::map<std::string, KRScene *> m_scenes; std::unordered_map<std::string, KRScene *> m_scenes;
}; };

View File

@@ -67,11 +67,11 @@ public:
long getShaderHandlesUsed(); long getShaderHandlesUsed();
private: private:
//std::map<std::string, KRShader *> m_shaders; //std::unordered_map<std::string, KRShader *> m_shaders;
std::map<std::pair<std::string, std::vector<int> >, KRShader *> m_shaders; std::map<std::pair<std::string, std::vector<int> >, KRShader *> m_shaders;
std::map<std::string, std::string> m_fragShaderSource; std::unordered_map<std::string, std::string> m_fragShaderSource;
std::map<std::string, std::string> m_vertShaderSource; std::unordered_map<std::string, std::string> m_vertShaderSource;
KRShader *m_pShader; KRShader *m_pShader;
char m_szCurrentShaderKey[256]; char m_szCurrentShaderKey[256];

View File

@@ -52,7 +52,7 @@ KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context
} }
KRTextureManager::~KRTextureManager() { KRTextureManager::~KRTextureManager() {
for(map<std::string, KRTexture *>::iterator itr = m_textures.begin(); itr != m_textures.end(); ++itr){ for(unordered_map<std::string, KRTexture *>::iterator itr = m_textures.begin(); itr != m_textures.end(); ++itr){
delete (*itr).second; delete (*itr).second;
} }
} }
@@ -132,7 +132,7 @@ KRTexture *KRTextureManager::getTextureCube(const char *szName) {
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName); unordered_map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName);
if(itr == m_textures.end()) { if(itr == m_textures.end()) {
KRTextureCube *pTexture = new KRTextureCube(getContext(), lowerName); KRTextureCube *pTexture = new KRTextureCube(getContext(), lowerName);
@@ -148,7 +148,7 @@ KRTexture *KRTextureManager::getTexture(const std::string &name) {
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName); unordered_map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName);
if(itr == m_textures.end()) { if(itr == m_textures.end()) {
if(lowerName.length() <= 8) { if(lowerName.length() <= 8) {
return NULL; return NULL;
@@ -328,7 +328,7 @@ void KRTextureManager::memoryChanged(long memoryDelta)
m_textureMemUsed += memoryDelta; m_textureMemUsed += memoryDelta;
} }
std::map<std::string, KRTexture *> &KRTextureManager::getTextures() std::unordered_map<std::string, KRTexture *> &KRTextureManager::getTextures()
{ {
return m_textures; return m_textures;
} }
@@ -338,7 +338,7 @@ void KRTextureManager::compress()
std::vector<KRTexture *> textures_to_remove; std::vector<KRTexture *> textures_to_remove;
std::vector<KRTexture *> textures_to_add; std::vector<KRTexture *> textures_to_add;
for(std::map<std::string, KRTexture *>::iterator itr=m_textures.begin(); itr != m_textures.end(); itr++) { for(std::unordered_map<std::string, KRTexture *>::iterator itr=m_textures.begin(); itr != m_textures.end(); itr++) {
KRTexture *texture = (*itr).second; KRTexture *texture = (*itr).second;
KRTexture *compressed_texture = texture->compress(); KRTexture *compressed_texture = texture->compress();
if(compressed_texture) { if(compressed_texture) {

View File

@@ -62,7 +62,7 @@ public:
void startFrame(float deltaTime); void startFrame(float deltaTime);
void endFrame(float deltaTime); void endFrame(float deltaTime);
std::map<std::string, KRTexture *> &getTextures(); std::unordered_map<std::string, KRTexture *> &getTextures();
void compress(); void compress();
@@ -81,7 +81,7 @@ private:
long m_memoryTransferredThisFrame; long m_memoryTransferredThisFrame;
std::map<std::string, KRTexture *> m_textures; std::unordered_map<std::string, KRTexture *> m_textures;
KRTexture *m_boundTextures[KRENGINE_MAX_TEXTURE_UNITS]; KRTexture *m_boundTextures[KRENGINE_MAX_TEXTURE_UNITS];
GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS]; GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS];

View File

@@ -30,6 +30,7 @@
// //
#include "KRUnknownManager.h" #include "KRUnknownManager.h"
#include <unordered_map>
KRUnknownManager::KRUnknownManager(KRContext &context) : KRContextObject(context) KRUnknownManager::KRUnknownManager(KRContext &context) : KRContextObject(context)
{ {
@@ -38,8 +39,8 @@ KRUnknownManager::KRUnknownManager(KRContext &context) : KRContextObject(context
KRUnknownManager::~KRUnknownManager() KRUnknownManager::~KRUnknownManager()
{ {
for(map<std::string, map<std::string, KRUnknown *> >::iterator extension_itr = m_unknowns.begin(); extension_itr != m_unknowns.end(); extension_itr++) { for(unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator extension_itr = m_unknowns.begin(); extension_itr != m_unknowns.end(); extension_itr++) {
for(map<std::string, KRUnknown *>::iterator name_itr=(*extension_itr).second.begin(); name_itr != (*extension_itr).second.end(); name_itr++) { for(unordered_map<std::string, KRUnknown *>::iterator name_itr=(*extension_itr).second.begin(); name_itr != (*extension_itr).second.end(); name_itr++) {
delete (*name_itr).second; delete (*name_itr).second;
} }
} }
@@ -53,13 +54,13 @@ void KRUnknownManager::add(KRUnknown *unknown)
std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower); std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), ::tolower);
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower); std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);
map<std::string, map<std::string, KRUnknown *> >::iterator extension_itr = m_unknowns.find(lower_extension); unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator extension_itr = m_unknowns.find(lower_extension);
if(extension_itr == m_unknowns.end()) { if(extension_itr == m_unknowns.end()) {
m_unknowns[lower_extension] = map<std::string, KRUnknown *>(); m_unknowns[lower_extension] = unordered_map<std::string, KRUnknown *>();
extension_itr = m_unknowns.find(lower_extension); extension_itr = m_unknowns.find(lower_extension);
} }
map<std::string, KRUnknown *>::iterator name_itr = (*extension_itr).second.find(lower_name); unordered_map<std::string, KRUnknown *>::iterator name_itr = (*extension_itr).second.find(lower_name);
if(name_itr != (*extension_itr).second.end()) { if(name_itr != (*extension_itr).second.end()) {
delete (*name_itr).second; delete (*name_itr).second;
(*name_itr).second = unknown; (*name_itr).second = unknown;
@@ -87,7 +88,7 @@ KRUnknown *KRUnknownManager::get(const std::string &name, const std::string &ext
} }
const map<std::string, KRUnknown *> &KRUnknownManager::get(const std::string &extension) const unordered_map<std::string, KRUnknown *> &KRUnknownManager::get(const std::string &extension)
{ {
std::string lower_extension = extension; std::string lower_extension = extension;
std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower); std::transform(lower_extension.begin(), lower_extension.end(), lower_extension.begin(), ::tolower);

View File

@@ -49,10 +49,10 @@ public:
KRUnknown *get(const std::string &name, const std::string &extension); KRUnknown *get(const std::string &name, const std::string &extension);
const map<std::string, KRUnknown *> &get(const std::string &extension); const unordered_map<std::string, KRUnknown *> &get(const std::string &extension);
private: private:
map<std::string, map<std::string, KRUnknown *> > m_unknowns; unordered_map<std::string, unordered_map<std::string, KRUnknown *> > m_unknowns;
}; };
#endif /* defined(KRUNKNOWN_MANAGER_H) */ #endif /* defined(KRUNKNOWN_MANAGER_H) */

View File

@@ -90,5 +90,18 @@ private:
}; };
namespace std {
template<>
struct hash<KRVector2> {
public:
size_t operator()(const KRVector2 &s) const
{
size_t h1 = std::hash<float>()(s.x);
size_t h2 = std::hash<float>()(s.y);
return h1 ^ ( h2 << 1 );
}
};
};
#endif #endif

View File

@@ -96,4 +96,18 @@ public:
void setUniform(GLint location) const; void setUniform(GLint location) const;
}; };
namespace std {
template<>
struct hash<KRVector3> {
public:
size_t operator()(const KRVector3 &s) const
{
size_t h1 = std::hash<float>()(s.x);
size_t h2 = std::hash<float>()(s.y);
size_t h3 = std::hash<float>()(s.z);
return h1 ^ ( h2 << 1 ) ^ (h3 << 2);
}
};
};
#endif #endif

View File

@@ -156,7 +156,7 @@ void KRViewport::calculateDerivedValues()
} }
std::map<KRAABB, int> &KRViewport::getVisibleBounds() std::unordered_map<KRAABB, int> &KRViewport::getVisibleBounds()
{ {
return m_visibleBounds; return m_visibleBounds;
} }

View File

@@ -41,7 +41,7 @@ public:
// Overload assignment operator // Overload assignment operator
KRViewport& operator=(const KRViewport &v); KRViewport& operator=(const KRViewport &v);
std::map<KRAABB, int> &getVisibleBounds(); std::unordered_map<KRAABB, int> &getVisibleBounds();
const std::set<KRLight *> &getVisibleLights(); const std::set<KRLight *> &getVisibleLights();
void setVisibleLights(const std::set<KRLight *> visibleLights); void setVisibleLights(const std::set<KRLight *> visibleLights);
@@ -68,7 +68,7 @@ private:
void calculateDerivedValues(); void calculateDerivedValues();
std::map<KRAABB, int> m_visibleBounds; // AABB's that output fragments in the last frame std::unordered_map<KRAABB, int> m_visibleBounds; // AABB's that output fragments in the last frame
}; };