2025-04-10 21:24:32 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-06-20 09:13:29 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-06-20 09:13:29 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-06-20 09:13:29 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-20 09:13:29 -07:00
|
|
|
*/
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "MessagePasserImpl.h"
|
|
|
|
|
|
2025-08-09 12:17:38 -07:00
|
|
|
#include "lib/debug.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "lib/timer.h"
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
#include "ps/CLogger.h"
|
2025-08-09 12:17:38 -07:00
|
|
|
#include "tools/atlas/GameInterface/Handlers/MessageHandler.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/Messages.h"
|
|
|
|
|
#include "tools/atlas/GameInterface/SharedMemory.h"
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
using namespace AtlasMessage;
|
|
|
|
|
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
double last_user_activity = 0.0;
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
void MessagePasserImpl::Add(IMessage* msg)
|
|
|
|
|
{
|
2011-04-30 06:01:45 -07:00
|
|
|
ENSURE(msg);
|
|
|
|
|
ENSURE(msg->GetType() == IMessage::Message);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
if (m_Trace)
|
2015-02-13 17:45:13 -08:00
|
|
|
debug_printf("%8.3f add message: %s\n", timer_Time(), msg->GetName());
|
2006-04-23 16:14:18 -07:00
|
|
|
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
msgHandlers::const_iterator it = GetMsgHandlers().find(msg->GetName());
|
|
|
|
|
if (it != GetMsgHandlers().end())
|
2010-10-31 15:00:28 -07:00
|
|
|
{
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
it->second(msg);
|
2010-10-31 15:00:28 -07:00
|
|
|
}
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
else
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2025-04-10 21:24:32 -07:00
|
|
|
debug_warn(L"Unrecognized message");
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
// CLogger might not be initialised, but this error will be sent
|
|
|
|
|
// to the debug output window anyway so people can still see it
|
2025-04-10 21:24:32 -07:00
|
|
|
LOGERROR("Unrecognized message (%s)", msg->GetName());
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
// Delete the object - we took ownership of it.
|
|
|
|
|
AtlasMessage::ShareableDelete(msg);
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2025-06-03 05:13:41 -07:00
|
|
|
void MessagePasserImpl::Query(QueryMessage* msg, void(* /*timeoutCallback*/ )())
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
ENSURE(msg);
|
|
|
|
|
ENSURE(msg->GetType() == IMessage::Query);
|
2006-04-23 16:14:18 -07:00
|
|
|
|
|
|
|
|
if (m_Trace)
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
debug_printf("%8.3f add query: %s\n", timer_Time(), msg->GetName());
|
2006-04-23 16:14:18 -07:00
|
|
|
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
msgHandlers::const_iterator it = GetMsgHandlers().find(msg->GetName());
|
|
|
|
|
if (it != GetMsgHandlers().end())
|
2010-10-31 15:00:28 -07:00
|
|
|
{
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
it->second(msg);
|
2010-10-31 15:00:28 -07:00
|
|
|
}
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
else
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2025-04-10 21:24:32 -07:00
|
|
|
debug_warn(L"Unrecognized message");
|
Remove the Engine threading when using Atlas
MacOS requires some UI-related API calls to happen on the main thread.
There are several SDL functions that call UI-things, and those were,
since #500 / 08b4d96cf2, in a separate thread.
This crashes on Catalina, instead of simply warning (see #5470).
It is not the first time we had such issues, as originally the Engine
was on the main thread and AtlasUI on a separate thread.
That didn't work on MacOS, so the threading was inverted in #500 /
08b4d96cf2, with AtlasUI on the main thread and the Engine in another
thread.
Unfortunately, this still wasn't enough.
This formally unthreads the engine, running it on a wxTimer, to avoid
these issues.
Future work should focus on:
- Further decoupling the simulation from the engine itself, as what
Atlas really needs is a threaded simulation, not a threaded engine.
- Making the simulation itself more threaded
- Making it possible to do tasks asynchronously under Atlas.
Refs #500
Fixes #5470
Differential Revision: https://code.wildfiregames.com/D2752
This was SVN commit r24361.
2020-12-10 01:42:58 -08:00
|
|
|
// CLogger might not be initialised, but this error will be sent
|
|
|
|
|
// to the debug output window anyway so people can still see it
|
2025-04-10 21:24:32 -07:00
|
|
|
LOGERROR("Unrecognized message (%s)", msg->GetName());
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MessagePasserImpl::SetTrace(bool t)
|
|
|
|
|
{
|
|
|
|
|
m_Trace = t;
|
|
|
|
|
}
|