Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Sync Service #500

Merged
merged 6 commits into from Aug 14, 2018
Merged

Improvements to Sync Service #500

merged 6 commits into from Aug 14, 2018

Conversation

eos428
Copy link
Member

@eos428 eos428 commented Jul 30, 2018

Closes #498 .

Removed unused variables and functions, moved some of the public ones to private because they shouldn't be accessible to outsiders. And most importantly, improved the sync service's performance by giving it only players' entities.

So far it seems alright in testing, but as always - test again to ensure it's good for merging.

Some note: I cannot delete the pointer to entity because entity's destructor is private. Perhaps we should use a vector of smart pointers instead?

… to private because they shouldn't be accessible to outsiders. And most importantly, improved the sync service's performance by giving it only players' entities.
@broxen broxen added enhancement Enhancement to server functionality. needs testing Needs further testing on various platforms labels Jul 30, 2018
@dracc
Copy link
Contributor

dracc commented Jul 30, 2018

Smart pointers would probably be a good idea, yes. 👍

Copy link
Contributor

@dracc dracc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've yet to try and build + use this PR, but code-wise it looks good.

ACE_Guard<ACE_Thread_Mutex> guard_buffer(ref_entity_mgr.getEntitiesMutex());

for(Entity * e : ref_entity_mgr.m_live_entlist)
for(int i = 0; i < m_entities.size(); ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Why not a range based for-loop anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i < size/length/count whatever is what i nearly always use :P

@nemerle
Copy link
Contributor

nemerle commented Jul 30, 2018

Not at this point though, all Entity instances are be 'owned' only at a single point, so making those shared_ptr would muddle things a bit, I would even consider making most of Entity * into EntityHandles that are accessing EntityManager::m_store

EntityManager& ref_entity_mgr;
uint8_t m_game_server_id;
int m_update_interval = 5;
QVector<Entity *> m_entities;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd very much prefer we don't store Entity pointers here, since they can change ( underlying memory is owned by EntityManager, and is part of a std::vector)

@eos428
Copy link
Member Author

eos428 commented Jul 30, 2018

So I suppose we should make this EntityHandle class that uses the EntityManager's m_store... That makes sense because we'd want the entity to be put into m_free_entries back like some sort of 'entities pool'. The way I look at it, just having access to m_store is not enough, so should we make EntityHandler have a reference instead of a pointer to Entity, and if we have pointers, would the memory no longer be shared between it and EntityManager?

@broxen broxen added this to the Version 0.6: Name TBD milestone Jul 31, 2018
eos428 added 2 commits August 4, 2018 08:02
MapInstance does the serialization part SyncService did, SyncService simply reposts the message to the db handler.
Added a function in ClientManager.h to get all active sessions inside it.
@eos428
Copy link
Member Author

eos428 commented Aug 4, 2018

Ready for merge. Testing is okay with 2 characters on map. Seems I have to re-create the message in sync service because the original message probably got 'muddied' by being sent as a SEGSEvent to the sync service, and then casted back to a Character/PlayerUpdateMessage.

@broxen
Copy link
Collaborator

broxen commented Aug 8, 2018

Works great!

screenshot from 2018-08-07 19-12-18

@broxen broxen removed the in progress label Aug 8, 2018
Copy link
Collaborator

@broxen broxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great in testing.

@broxen
Copy link
Collaborator

broxen commented Aug 8, 2018

@nemerle I'll leave this to you to merge when you've had a chance to review.

vClients get_active_sessions()
{
return m_active_sessions;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the users of this function do not need to modify the active sessions ( the result is only used to find things ), I'd prefer us to use this form here:

const vClients &get_active_sessions() const { return m_active_sessions; }

void MapInstance::on_update_entities()
{
std::vector<MapClientSession *> active_sessions = m_session_store.get_active_sessions();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to copy the active_sessions vector here, if get_active_sessions returns reference:
const std::vector<MapClientSession *> &active_sessions(m_session_store.get_active_sessions())

// all active sessions are for player, so we don't need to verify if db_id != 0
for (size_t i = 0; i < active_sessions.size(); ++i)
{
Entity *e = active_sessions[i]->m_ent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could be using range-for here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is my huge preference for normal for-loops at work here :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a side-note, for performance work, compilers can have trouble optimizing plain for loops if the condition part has a function call in it ( like size() call above )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... I'll keep that in mind in the future. Thanks for the heads-up.
On another note, I just made the changes as advised. Should be okay now.

@@ -63,6 +63,11 @@ mutable std::mutex m_store_mutex;
}

public:
const vClients get_active_sessions()
{
return m_active_sessions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const vClients & plz, this still will return a copy of the vector :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I forgot to look at the ampersand, updated again

@nemerle nemerle merged commit 6e99c39 into Segs:develop Aug 14, 2018
@eos428 eos428 deleted the syncservice branch August 14, 2018 23:04
@broxen broxen modified the milestone: Version 0.6: Outbreak Oct 26, 2018
@broxen broxen modified the milestone: Version 0.6: Outbreak Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to server functionality. needs testing Needs further testing on various platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants