Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/includes/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ENGINE_EXPORT Log {
Log &operator<<(double d);

Log &operator<<(const char *s);
Log &operator<<(const string &value);

Log &operator<<(const void *value);

private:
std::stringstream m_stream;
Expand Down
2 changes: 1 addition & 1 deletion engine/includes/systems/resourcesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ENGINE_EXPORT ResourceSystem : public System {
unordered_map<string, Resource *> m_resourceCache;
unordered_map<Resource *, string> m_referenceCache;

set<Resource *> m_deleteList;
list<Resource *> m_deleteList;

};

Expand Down
17 changes: 15 additions & 2 deletions engine/src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void Log::setLogLevel(LogTypes level) {
Writes the boolean value, \a b, to the stream and returns a reference to the stream.
*/
Log &Log::operator<<(bool b) {
m_stream << " " << b;
to_string(b);
m_stream << " " << b;
return *this;
}
/*!
Expand Down Expand Up @@ -148,3 +147,17 @@ Log &Log::operator<<(const char *string) {
m_stream << " " << string;
return *this;
}
/*!
Writes the text \a string, to the stream and returns a reference to the stream.
*/
Log &Log::operator<<(const string &string) {
m_stream << " " << string;
return *this;
}
/*!
Writes the pointer \a value, to the stream and returns a reference to the stream.
*/
Log &Log::operator<<(const void *value) {
m_stream << " " << value;
return *this;
}
9 changes: 6 additions & 3 deletions engine/src/resources/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ void Resource::setState(State state) {
Notifies subscribers about the current state of the resource.
*/
void Resource::notifyCurrentState() {
unique_lock<mutex> locker(m_mutex);
for(auto it : m_observers) {
(*it.first)(m_state, it.second);
unique_lock<mutex> locker(m_mutex, std::defer_lock);

if(locker.try_lock()) {
for(auto it : m_observers) {
(*it.first)(m_state, it.second);
}
}
}
/*!
Expand Down
26 changes: 22 additions & 4 deletions engine/src/systems/resourcesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ void ResourceSystem::update(World *) {
++it;
}

for(auto it : m_deleteList) {
delete it;
while(m_deleteList.empty()) {
Resource *res = m_deleteList.back();
m_deleteList.pop_back();

delete res;
}
m_deleteList.clear();
}

int ResourceSystem::threadPolicy() const {
Expand Down Expand Up @@ -136,6 +138,13 @@ void ResourceSystem::deleteFromCahe(Resource *resource) {
}
m_referenceCache.erase(ref);
}

for(auto it : m_deleteList) {
if(it == resource) {
m_deleteList.remove(it);
break;
}
}
}

void ResourceSystem::processState(Resource *resource) {
Expand Down Expand Up @@ -211,7 +220,16 @@ void ResourceSystem::processState(Resource *resource) {
resource->switchState(Resource::Unloading);
} break;
case Resource::ToBeDeleted: {
m_deleteList.insert(resource);
bool found = false;
for(auto it : m_deleteList) {
if(it == resource) {
found = true;
break;
}
}
if(!found) {
m_deleteList.push_back(resource);
}
} break;
default: break;
}
Expand Down