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)
|
/* static */ void AI::NewEvent(CompanyID company, ScriptEvent *event)
|
||||||
{
|
{
|
||||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
ScriptObjectRef counter(event);
|
||||||
event->AddRef();
|
|
||||||
|
|
||||||
/* Clients should ignore events */
|
/* Clients should ignore events */
|
||||||
if (_networking && !_network_server) {
|
if (_networking && !_network_server) {
|
||||||
event->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only AIs can have an event-queue */
|
/* Only AIs can have an event-queue */
|
||||||
if (!Company::IsValidAiID(company)) {
|
if (!Company::IsValidAiID(company)) {
|
||||||
event->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,18 +258,14 @@
|
||||||
Backup<CompanyID> cur_company(_current_company, company);
|
Backup<CompanyID> cur_company(_current_company, company);
|
||||||
Company::Get(_current_company)->ai_instance->InsertEvent(event);
|
Company::Get(_current_company)->ai_instance->InsertEvent(event);
|
||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
|
|
||||||
event->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void AI::BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company)
|
/* static */ void AI::BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company)
|
||||||
{
|
{
|
||||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
ScriptObjectRef counter(event);
|
||||||
event->AddRef();
|
|
||||||
|
|
||||||
/* Clients should ignore events */
|
/* Clients should ignore events */
|
||||||
if (_networking && !_network_server) {
|
if (_networking && !_network_server) {
|
||||||
event->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,8 +273,6 @@
|
||||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||||
if (c != skip_company) AI::NewEvent(c, event);
|
if (c != skip_company) AI::NewEvent(c, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
event->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void AI::Save(CompanyID company)
|
/* static */ void AI::Save(CompanyID company)
|
||||||
|
|
|
@ -145,18 +145,15 @@
|
||||||
|
|
||||||
/* static */ void Game::NewEvent(ScriptEvent *event)
|
/* static */ void Game::NewEvent(ScriptEvent *event)
|
||||||
{
|
{
|
||||||
/* AddRef() and Release() need to be called at least once, so do it here */
|
ScriptObjectRef counter(event);
|
||||||
event->AddRef();
|
|
||||||
|
|
||||||
/* Clients should ignore events */
|
/* Clients should ignore events */
|
||||||
if (_networking && !_network_server) {
|
if (_networking && !_network_server) {
|
||||||
event->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if Game instance is alive */
|
/* Check if Game instance is alive */
|
||||||
if (Game::instance == nullptr) {
|
if (Game::instance == nullptr) {
|
||||||
event->Release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +161,6 @@
|
||||||
Backup<CompanyID> cur_company(_current_company, OWNER_DEITY);
|
Backup<CompanyID> cur_company(_current_company, OWNER_DEITY);
|
||||||
Game::instance->InsertEvent(event);
|
Game::instance->InsertEvent(event);
|
||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
|
|
||||||
event->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void Game::ResetConfig()
|
/* static */ void Game::ResetConfig()
|
||||||
|
|
Loading…
Reference in New Issue