mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use ScriptObjectRef to handle Event reference counting.
This removes manual reference counting.pull/13003/head
parent
8360fab18a
commit
bacd3e83c6
|
@ -242,18 +242,15 @@
|
|||
|
||||
/* static */ void AI::NewEvent(CompanyID company, ScriptEvent *event)
|
||||
{
|
||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
||||
event->AddRef();
|
||||
ScriptObjectRef counter(event);
|
||||
|
||||
/* Clients should ignore events */
|
||||
if (_networking && !_network_server) {
|
||||
event->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Only AIs can have an event-queue */
|
||||
if (!Company::IsValidAiID(company)) {
|
||||
event->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -261,18 +258,14 @@
|
|||
Backup<CompanyID> cur_company(_current_company, company);
|
||||
Company::Get(_current_company)->ai_instance->InsertEvent(event);
|
||||
cur_company.Restore();
|
||||
|
||||
event->Release();
|
||||
}
|
||||
|
||||
/* static */ void AI::BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company)
|
||||
{
|
||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
||||
event->AddRef();
|
||||
ScriptObjectRef counter(event);
|
||||
|
||||
/* Clients should ignore events */
|
||||
if (_networking && !_network_server) {
|
||||
event->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -280,8 +273,6 @@
|
|||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
if (c != skip_company) AI::NewEvent(c, event);
|
||||
}
|
||||
|
||||
event->Release();
|
||||
}
|
||||
|
||||
/* static */ void AI::Save(CompanyID company)
|
||||
|
|
|
@ -145,18 +145,15 @@
|
|||
|
||||
/* static */ void Game::NewEvent(ScriptEvent *event)
|
||||
{
|
||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
||||
event->AddRef();
|
||||
ScriptObjectRef counter(event);
|
||||
|
||||
/* Clients should ignore events */
|
||||
if (_networking && !_network_server) {
|
||||
event->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if Game instance is alive */
|
||||
if (Game::instance == nullptr) {
|
||||
event->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -164,8 +161,6 @@
|
|||
Backup<CompanyID> cur_company(_current_company, OWNER_DEITY);
|
||||
Game::instance->InsertEvent(event);
|
||||
cur_company.Restore();
|
||||
|
||||
event->Release();
|
||||
}
|
||||
|
||||
/* static */ void Game::ResetConfig()
|
||||
|
|
Loading…
Reference in New Issue