-
Notifications
You must be signed in to change notification settings - Fork 175
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
[Codechange] Implemented a thread-safe truck deletion queue #895
Conversation
… to prevent creating dummy trucks
Removed duplicate code
You probably wanted to say "Deleting trucks now possible while sim-thread is running". 😄 Thought I'm happy this fixes a bug, I don't like the design much. It adds another explicit "sync me now!" call + new mutex guard instead of using the existing infrastructure, i.e. processing queued deletes as a rudimentary game task in frameStarted() I'm probably too lost in my 'proper-mt' vision, but here's how I imagine truck delete mechanism:
|
You are right, we don't need that call, because
The issue is that delete requests can come from both the main thread and the network thread. |
Then make an extra queue for the network. When synced, transfer the requests to main delete queue. Though I'm not sure how this fits in our current design - who and where synces with network thread, anyway? Further, how is spawning over network handled this time around? Spawning and deleting should be treated as essentialy the same operation: add or remove a vehicle from simulation/rendering. |
I just realized that the truck deletes are already queued in the network thread. called by: called by:
called by: |
In Which is indirectly called in the
|
Hmm... the whole How about being punks and rewriting the whole StreamMess into one compilation unit (Networking.{h/cpp}), which would look like this: /// @file Networking.h
namespace RoR {
namespace Networking {
struct Stream { ... };
// Stuff from class Network, known as gEnv->network.
// It's pseudo-singleton anyway, so why not global functions?
SendMessageRaw()
SendMessage()
ReceiveMessage()
Connect()
Disconnect()
SenderThreadStart()
ReceiverThreadStart()
// etc... from Network.h
// EDIT: Right, we need a substitute for `if (gEnv->network != nullptr)`:
IsMultiplayerActive();
// Stuff from NetworkStreamManager -- was a singleton
// For the time being, we can preserve the abstract stream principle
AddLocalStream()
AddRemoteStream()
RemoveStream()
SendStreams()
ReceiveStreams()
// StreamableFactory => eliminate!
// Use `#include "Networking.h"` and the function calls directly, please!
} // namespace Networking
} // namespace RoR and this // Networking.cpp
namespace RoR {
namespace Networking {
static container<> s_streams;
static socket_t s_socket;
static whatever_t s_whatever;
void SendMessage(message_t msg)
{
s_socket.send_message(msg);
}
} // namespace Networking
} // namespace RoR |
Trucks can no longer be deleted while the sim thread is running.
Singleplayer:
Multiplayer: