Skip to content

Commit

Permalink
Code maintenance (etternagame#823)
Browse files Browse the repository at this point in the history
* modernize actor/base

* modernize actor/gameplay

* fix invalid comparator assert... i think?

* otherstuff and apparently relwithdebug is crashing on actor runcmds

* pragma vomit warnings so we can see important ones and some other stuff

* boo

* fix ragelog output being bogus

_

* more code maint

Co-authored-by: Barinade <poco0317@users.noreply.github.com>
  • Loading branch information
MinaciousGrace and poco0317 authored Jul 6, 2020
1 parent 94e319b commit 282325f
Show file tree
Hide file tree
Showing 118 changed files with 3,032 additions and 2,912 deletions.
150 changes: 77 additions & 73 deletions src/Etterna/Actor/Base/Actor.cpp

Large diffs are not rendered by default.

267 changes: 119 additions & 148 deletions src/Etterna/Actor/Base/Actor.h

Large diffs are not rendered by default.

159 changes: 80 additions & 79 deletions src/Etterna/Actor/Base/ActorFrame.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Etterna/Globals/global.h"
#include "ActorFrame.h"
#include "ActorUtil.h"
#include "Etterna/Models/Misc/Foreach.h"
#include "Etterna/Models/Lua/LuaBinding.h"
#include "RageUtil/Graphics/RageDisplay.h"
#include "RageUtil/Utils/RageUtil.h"
Expand Down Expand Up @@ -73,18 +72,20 @@ ActorFrame::ActorFrame(const ActorFrame& cpy)
* them. If not, the derived class owns the children. This must preserve
* the current order of m_SubActors. */
if (m_bDeleteChildren) {
for (auto m_SubActor : cpy.m_SubActors) {
Actor* pActor = m_SubActor->Copy();
this->AddChild(pActor);
for (auto* m_SubActor : cpy.m_SubActors) {
auto* pActor = m_SubActor->Copy();
this->ActorFrame::AddChild(pActor);
}
}
}

void
ActorFrame::InitState()
{
FOREACH(Actor*, m_SubActors, a)
(*a)->InitState();
for (auto& a : m_SubActors) {
a->InitState();
}

Actor::InitState();
}

Expand Down Expand Up @@ -121,8 +122,8 @@ ActorFrame::LoadChildrenFromNode(const XNode* pNode)
ASSERT(m_bDeleteChildren);

// Load children
const XNode* pChildren = pNode->GetChild("children");
bool bArrayOnly = false;
const auto* pChildren = pNode->GetChild("children");
auto bArrayOnly = false;
if (pChildren == nullptr) {
bArrayOnly = true;
pChildren = pNode;
Expand All @@ -133,7 +134,7 @@ ActorFrame::LoadChildrenFromNode(const XNode* pNode)
if (bArrayOnly && !IsAnInt(pChild->GetName()))
continue;

Actor* pChildActor = ActorUtil::LoadFromNode(pChild, this);
auto* pChildActor = ActorUtil::LoadFromNode(pChild, this);
if (pChildActor)
AddChild(pChildActor);
}
Expand Down Expand Up @@ -163,28 +164,29 @@ ActorFrame::AddChild(Actor* pActor)
void
ActorFrame::RemoveChild(Actor* pActor)
{
vector<Actor*>::iterator iter =
find(m_SubActors.begin(), m_SubActors.end(), pActor);
const auto iter = find(m_SubActors.begin(), m_SubActors.end(), pActor);
if (iter != m_SubActors.end())
m_SubActors.erase(iter);
}

void
ActorFrame::TransferChildren(ActorFrame* pTo)
{
FOREACH(Actor*, m_SubActors, i)
pTo->AddChild(*i);
for (auto* a : m_SubActors) {
pTo->AddChild(a);
}

RemoveAllChildren();
}

Actor*
ActorFrame::GetChild(const std::string& sName)
{
FOREACH(Actor*, m_SubActors, a)
{
if ((*a)->GetName() == sName)
return *a;
for (auto* a : m_SubActors) {
if (a->GetName() == sName)
return a;
}

return nullptr;
}

Expand All @@ -197,8 +199,7 @@ ActorFrame::RemoveAllChildren()
void
ActorFrame::MoveToTail(Actor* pActor)
{
vector<Actor*>::iterator iter =
find(m_SubActors.begin(), m_SubActors.end(), pActor);
const auto iter = find(m_SubActors.begin(), m_SubActors.end(), pActor);
if (iter == m_SubActors.end()) // didn't find
FAIL_M("Nonexistent actor");

Expand All @@ -209,8 +210,7 @@ ActorFrame::MoveToTail(Actor* pActor)
void
ActorFrame::MoveToHead(Actor* pActor)
{
vector<Actor*>::iterator iter =
find(m_SubActors.begin(), m_SubActors.end(), pActor);
const auto iter = find(m_SubActors.begin(), m_SubActors.end(), pActor);
if (iter == m_SubActors.end()) // didn't find
FAIL_M("Nonexistent actor");

Expand Down Expand Up @@ -253,7 +253,7 @@ ActorFrame::DrawPrimitives()
// Actor::DrawPrimitives();

if (unlikely(!m_DrawFunction.IsNil())) {
Lua* L = LUA->Get();
auto* L = LUA->Get();
m_DrawFunction.PushSelf(L);
if (lua_isnil(L, -1)) {
LUA->Release(L);
Expand All @@ -267,19 +267,19 @@ ActorFrame::DrawPrimitives()
return;
}

RageColor diffuse = m_pTempState->diffuse[0];
RageColor glow = m_pTempState->glow;
const auto diffuse = m_pTempState->diffuse[0];
const auto glow = m_pTempState->glow;

// Word of warning: Actor::Draw duplicates the structure of how an Actor
// is drawn inside of an ActorFrame for its wrapping feature. So if
// you're adding something new to ActorFrames that affects how Actors are
// drawn, make sure to also apply it in Actor::Draw's handling of the
// wrappers. -Kyz
// Word of warning: Actor::Draw duplicates the structure of how an
// Actor is drawn inside of an ActorFrame for its wrapping feature. So
// if you're adding something new to ActorFrames that affects how Actors
// are drawn, make sure to also apply it in Actor::Draw's handling of
// the wrappers. -Kyz

// draw all sub-ActorFrames while we're in the ActorFrame's local coordinate
// space
// draw all sub-ActorFrames while we're in the ActorFrame's local
// coordinate space
if (m_bDrawByZPosition) {
vector<Actor*> subs = m_SubActors;
auto subs = m_SubActors;
ActorUtil::SortByZPosition(subs);
for (auto& sub : subs) {
sub->SetInternalDiffuse(diffuse);
Expand Down Expand Up @@ -317,15 +317,15 @@ IdenticalChildrenSingleApplier(lua_State* L)
{
// First arg is the table of items, get the last object.
// It is the one that would have been in the children table in the old
// version. The other args are meant for the function. The upvalue for this
// function is the function the theme tried to call.
// version. The other args are meant for the function. The upvalue for
// this function is the function the theme tried to call.
lua_rawgeti(L, 1, lua_objlen(L, 1)); // stack: table, args, obj
lua_insert(L, 2); // stack: table, obj, args
lua_pushvalue(L, lua_upvalueindex(1)); // stack: table, obj, args, func
lua_insert(L, 2); // stack: table, func, obj, args
int args_count = lua_gettop(L) - 2;
// Not using RunScriptOnStack because we're inside a lua call already and
// we want an error to propagate up.
const auto args_count = lua_gettop(L) - 2;
// Not using RunScriptOnStack because we're inside a lua call already
// and we want an error to propagate up.
lua_call(L, args_count, LUA_MULTRET); // stack: table, return_values
return lua_gettop(L) - 1;
}
Expand All @@ -351,7 +351,8 @@ IdenticalChildrenIndexLayer(lua_State* L)
lua_gettable(L, 1); // stack: object
lua_getmetatable(L, -1); // stack: object, obj_meta
lua_getfield(L, -1, "__index"); // stack: object, obj_meta, obj_index
lua_pushvalue(L, 2); // stack: object, obj_meta, obj_index, func_name
lua_pushvalue(L,
2); // stack: object, obj_meta, obj_index, func_name
lua_gettable(L, -2); // stack: object, obj_meta, obj_index, obj_function
lua_pushcclosure(L,
IdenticalChildrenSingleApplier,
Expand All @@ -365,27 +366,28 @@ IdenticalChildrenIndexLayer(lua_State* L)
static void
CreateChildTable(lua_State* L, Actor* a)
{
// Old PushChildrenTable assumed that all children had unique names, so only
// the last one of a name ended up in the table that was returned. Create a
// table that will hold all the children that have this name and act as a
// pass through layer for function calls. stack: old_entry
// Old PushChildrenTable assumed that all children had unique names, so
// only the last one of a name ended up in the table that was returned.
// Create a table that will hold all the children that have this name
// and act as a pass through layer for function calls. stack: old_entry
lua_createtable(L, 0, 0); // stack: old_entry, table_entry
lua_insert(L, -2); // stack: table_entry, old_entry
lua_rawseti(L, -2, 1); // stack: table_entry
a->PushSelf(L); // stack: table_entry, new_entry
lua_rawseti(L, -2, 2); // stack: table_entry
lua_createtable(L, 0, 1); // stack: table_entry, table_meta
lua_pushcfunction(
L, IdenticalChildrenIndexLayer); // stack: table_entry, table_meta, ICIL
lua_setfield(L, -2, "__index"); // stack: table_entry, table_meta
lua_setmetatable(L, -2); // stack: table_entry
L,
IdenticalChildrenIndexLayer); // stack: table_entry, table_meta, ICIL
lua_setfield(L, -2, "__index"); // stack: table_entry, table_meta
lua_setmetatable(L, -2); // stack: table_entry
}

static void
AddToChildTable(lua_State* L, Actor* a)
{
// stack: table_entry
int next_index = lua_objlen(L, -1) + 1;
const int next_index = lua_objlen(L, -1) + 1;
a->PushSelf(L); // stack: table_entry, actor
lua_rawseti(L, -2, next_index); // stack: table_entry
}
Expand All @@ -394,28 +396,28 @@ void
ActorFrame::PushChildrenTable(lua_State* L)
{
lua_newtable(L); // stack: all_actors
FOREACH(Actor*, m_SubActors, a)
{
LuaHelpers::Push(L, (*a)->GetName()); // stack: all_actors, name
lua_gettable(L, -2); // stack: all_actors, entry
for (auto& a : m_SubActors) {
LuaHelpers::Push(L, a->GetName()); // stack: all_actors, name
lua_gettable(L, -2); // stack: all_actors, entry
if (lua_isnil(L, -1)) {
lua_pop(L, 1); // stack: all_actors
LuaHelpers::Push(L, (*a)->GetName()); // stack: all_actors, name
(*a)->PushSelf(L); // stack: all_actors, name, actor
lua_rawset(L, -3); // stack: all_actors
lua_pop(L, 1); // stack: all_actors
LuaHelpers::Push(L, a->GetName()); // stack: all_actors, name
a->PushSelf(L); // stack: all_actors, name, actor
lua_rawset(L, -3); // stack: all_actors
} else {
// Fun fact: PushSelf pushes a table.
if (lua_objlen(L, -1) > 0) {
// stack: all_actors, table_entry
AddToChildTable(L, *a); // stack: all_actors, table_entry
lua_pop(L, 1); // stack: all_actors
AddToChildTable(L, a); // stack: all_actors, table_entry
lua_pop(L, 1); // stack: all_actors
} else {
// stack: all_actors, old_entry
CreateChildTable(L, *a); // stack: all_actors, table_entry
CreateChildTable(L, a); // stack: all_actors, table_entry
LuaHelpers::Push(
L, (*a)->GetName()); // stack: all_actors, table_entry, name
lua_insert(L, -2); // stack: all_actors, name, table_entry
lua_rawset(L, -3); // stack: all_actors
L,
a->GetName()); // stack: all_actors, table_entry, name
lua_insert(L, -2); // stack: all_actors, name, table_entry
lua_rawset(L, -3); // stack: all_actors
}
}
}
Expand All @@ -424,19 +426,18 @@ ActorFrame::PushChildrenTable(lua_State* L)
void
ActorFrame::PushChildTable(lua_State* L, const std::string& sName)
{
int found = 0;
FOREACH(Actor*, m_SubActors, a)
{
if ((*a)->GetName() == sName) {
auto found = 0;
for (auto& a : m_SubActors) {
if (a->GetName() == sName) {
switch (found) {
case 0:
(*a)->PushSelf(L);
a->PushSelf(L);
break;
case 1:
CreateChildTable(L, *a);
CreateChildTable(L, a);
break;
default:
AddToChildTable(L, *a);
AddToChildTable(L, a);
break;
}
++found;
Expand All @@ -451,7 +452,7 @@ void
ActorFrame::PlayCommandOnChildren(const std::string& sCommandName,
const LuaReference* pParamTable)
{
const apActorCommands* pCmd = GetCommand(sCommandName);
const auto* pCmd = GetCommand(sCommandName);
if (pCmd != nullptr)
RunCommandsOnChildren(*pCmd, pParamTable);
}
Expand All @@ -460,8 +461,8 @@ void
ActorFrame::PlayCommandOnLeaves(const std::string& sCommandName,
const LuaReference* pParamTable)
{
const apActorCommands* pCmd = GetCommand(sCommandName);
if (pCmd != NULL)
const auto* pCmd = GetCommand(sCommandName);
if (pCmd != nullptr)
RunCommandsOnLeaves(**pCmd, pParamTable);
}

Expand Down Expand Up @@ -515,7 +516,7 @@ ActorFrame::UpdateInternal(float fDeltaTime)
secsSinceLuaUpdateFWasRun += fDeltaTime;
if (secsSinceLuaUpdateFWasRun >= m_fUpdateFInterval) {
secsSinceLuaUpdateFWasRun = 0;
Lua* L = LUA->Get();
auto* L = LUA->Get();
m_UpdateFunction.PushSelf(L);
if (lua_isnil(L, -1)) {
LUA->Release(L);
Expand Down Expand Up @@ -560,9 +561,9 @@ PropagateActorFrameCommand(FinishTweening)

float ActorFrame::GetTweenTimeLeft() const
{
float m = Actor::GetTweenTimeLeft();
auto m = Actor::GetTweenTimeLeft();

for (auto a : m_SubActors)
for (auto* a : m_SubActors)
m = max(m, a->GetTweenTimeLeft());
return m;
}
Expand Down Expand Up @@ -615,7 +616,7 @@ ActorFrame::HandleMessage(const Message& msg)
if (msg.IsBroadcast())
return;

for (auto pActor : m_SubActors) {
for (auto* pActor : m_SubActors) {
pActor->HandleMessage(msg);
}
}
Expand Down Expand Up @@ -678,7 +679,7 @@ class LunaActorFrame : public Luna<ActorFrame>
}
static int SetUpdateFunctionInterval(T* p, lua_State* L)
{
float seconds = FArg(1);
const auto seconds = FArg(1);
if (seconds <= 0) {
luaL_error(L,
"ActorFrame:SetUpdateRate(%f) Update interval must be "
Expand All @@ -690,7 +691,7 @@ class LunaActorFrame : public Luna<ActorFrame>
}
static int SetUpdateRate(T* p, lua_State* L)
{
float rate = FArg(1);
const auto rate = FArg(1);
if (rate <= 0) {
luaL_error(L,
"ActorFrame:SetUpdateRate(%f) Update rate must be "
Expand Down Expand Up @@ -811,14 +812,14 @@ class LunaActorFrame : public Luna<ActorFrame>
if (coords.size() != 3) {
// error
}
RageVector3 vTmp = RageVector3(coords[0], coords[1], coords[2]);
const auto vTmp = RageVector3(coords[0], coords[1], coords[2]);
p->SetLightDirection(vTmp);
COMMON_RETURN_SELF;
}
static int AddChildFromPath(T* p, lua_State* L)
{
// this one is tricky, we need to get an Actor from Lua.
Actor* pActor = ActorUtil::MakeActor(SArg(1));
auto* pActor = ActorUtil::MakeActor(SArg(1));
if (pActor == nullptr) {
lua_pushboolean(L, 0);
return 1;
Expand All @@ -830,7 +831,7 @@ class LunaActorFrame : public Luna<ActorFrame>

static int RemoveChild(T* p, lua_State* L)
{
Actor* child = p->GetChild(SArg(1));
auto* child = p->GetChild(SArg(1));
if (child != nullptr) {
p->RemoveChild(child);
SAFE_DELETE(child);
Expand Down
Loading

0 comments on commit 282325f

Please sign in to comment.