Skip to content
Permalink
Browse files

A bunch of by value to by const reference changes to help performance…

… and be more idiomatic. NFC intended.
  • Loading branch information...
gmcode committed May 25, 2015
1 parent 033c4e9 commit 5f4a5416febf4611cb0fb691c8997d45bcfda61d
@@ -246,7 +246,7 @@ void trap_GettextPlural( char *buffer, const char *msgid, const char
void trap_notify_onTeamChange( int newTeam );

qhandle_t trap_RegisterVisTest();
void trap_AddVisTestToScene( qhandle_t hTest, vec3_t pos,
void trap_AddVisTestToScene( qhandle_t hTest, const vec3_t pos,
float depthAdjust, float area );
float trap_CheckVisibility( qhandle_t hTest );
void trap_UnregisterVisTest( qhandle_t hTest );
@@ -1548,7 +1548,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
{
switch (index) {
case CG_SENDCLIENTCOMMAND:
IPC::HandleMsg<SendClientCommandMsg>(channel, std::move(reader), [this] (std::string command) {
IPC::HandleMsg<SendClientCommandMsg>(channel, std::move(reader), [this] (const std::string& command) {
CL_AddReliableCommand(command.c_str());
});
break;
@@ -1642,7 +1642,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_PGETTEXT:
IPC::HandleMsg<PGettextMsg>(channel, std::move(reader), [this] (int len, std::string context, std::string input, std::string& output) {
IPC::HandleMsg<PGettextMsg>(channel, std::move(reader), [this] (int len, const std::string& context, const std::string& input, std::string& output) {
std::unique_ptr<char[]> buffer(new char[len]);
Q_strncpyz(buffer.get(), C__(context.c_str(), input.c_str()), len);
output.assign(buffer.get(), len);
@@ -1741,7 +1741,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_R_LERPTAG:
IPC::HandleMsg<Render::LerpTagMsg>(channel, std::move(reader), [this] (refEntity_t&& entity, std::string tagName, int startIndex, orientation_t& tag, int& res) {
IPC::HandleMsg<Render::LerpTagMsg>(channel, std::move(reader), [this] (const refEntity_t& entity, const std::string& tagName, int startIndex, orientation_t& tag, int& res) {
res = re.LerpTag(&tag, &entity, tagName.c_str(), startIndex);
});
break;
@@ -1753,7 +1753,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_R_INPVS:
IPC::HandleMsg<Render::InPVSMsg>(channel, std::move(reader), [this] (std::array<float, 3> p1, std::array<float, 3> p2, bool& res) {
IPC::HandleMsg<Render::InPVSMsg>(channel, std::move(reader), [this] (const std::array<float, 3>& p1, const std::array<float, 3>& p2, bool& res) {
res = re.inPVS(p1.data(), p2.data());
});
break;
@@ -1897,7 +1897,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_LAN_SERVERSTATUS:
IPC::HandleMsg<LAN::ServerStatusMsg>(channel, std::move(reader), [this] (std::string serverAddress, int len, std::string& status, int& res) {
IPC::HandleMsg<LAN::ServerStatusMsg>(channel, std::move(reader), [this] (const std::string& serverAddress, int len, std::string& status, int& res) {
std::unique_ptr<char[]> buffer(new char[len]);
res = LAN_GetServerStatus(serverAddress.c_str(), buffer.get(), len);
status.assign(buffer.get(), len);
@@ -1961,7 +1961,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_ROCKET_DSADDROW:
IPC::HandleMsg<Rocket::DSAddRowMsg>(channel, std::move(reader), [this] (const std::string& name, std::string table, const std::string& data) {
IPC::HandleMsg<Rocket::DSAddRowMsg>(channel, std::move(reader), [this] (const std::string& name, const std::string& table, const std::string& data) {
Rocket_DSAddRow(name.c_str(), table.c_str(), data.c_str());
});
break;
@@ -2001,7 +2001,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_ROCKET_SETPROPERTYBYID:
IPC::HandleMsg<Rocket::SetPropertyMsg>(channel, std::move(reader), [this] (const std::string property, const std::string& value) {
IPC::HandleMsg<Rocket::SetPropertyMsg>(channel, std::move(reader), [this] (const std::string& property, const std::string& value) {
Rocket_SetPropertyById("", property.c_str(), value.c_str());
});
break;
@@ -2119,7 +2119,7 @@ void CGameVM::QVMSyscall(int index, Util::Reader& reader, IPC::Channel& channel)
break;

case CG_ROCKET_SHOWSCOREBOARD:
IPC::HandleMsg<Rocket::ShowScoreboardMsg>(channel, std::move(reader), [this] (std::string name, bool show) {
IPC::HandleMsg<Rocket::ShowScoreboardMsg>(channel, std::move(reader), [this] (const std::string& name, bool show) {
Rocket_ShowScoreboard(name.c_str(), show);
});
break;
@@ -2203,13 +2203,13 @@ void CGameVM::CmdBuffer::HandleCommandBufferSyscall(int major, int minor, Util::
break;

case CG_S_RESPATIALIZE:
HandleMsg<Audio::RespatializeMsg>(std::move(reader), [this] (int entityNum, std::array<float, 9> axis) {
HandleMsg<Audio::RespatializeMsg>(std::move(reader), [this] (int entityNum, const std::array<float, 9>& axis) {
Audio::UpdateListener(entityNum, (vec3_t*) axis.data());
});
break;

case CG_S_STARTBACKGROUNDTRACK:
HandleMsg<Audio::StartBackgroundTrackMsg>(std::move(reader), [this] (std::string intro, std::string loop) {
HandleMsg<Audio::StartBackgroundTrackMsg>(std::move(reader), [this] (const std::string& intro, const std::string& loop) {
Audio::StartMusic(intro.c_str(), loop.c_str());
});
break;
@@ -2227,7 +2227,7 @@ void CGameVM::CmdBuffer::HandleCommandBufferSyscall(int major, int minor, Util::
break;

case CG_S_SETREVERB:
HandleMsg<Audio::SetReverbMsg>(std::move(reader), [this] (int slotNum, std::string name, float ratio) {
HandleMsg<Audio::SetReverbMsg>(std::move(reader), [this] (int slotNum, const std::string& name, float ratio) {
Audio::SetReverb(slotNum, name.c_str(), ratio);
});
break;
@@ -2271,37 +2271,37 @@ void CGameVM::CmdBuffer::HandleCommandBufferSyscall(int major, int minor, Util::
break;

case CG_R_ADDPOLYTOSCENE:
HandleMsg<Render::AddPolyToSceneMsg>(std::move(reader), [this] (int shader, std::vector<polyVert_t> verts) {
HandleMsg<Render::AddPolyToSceneMsg>(std::move(reader), [this] (int shader, const std::vector<polyVert_t>& verts) {
re.AddPolyToScene(shader, verts.size(), verts.data());
});
break;

case CG_R_ADDPOLYSTOSCENE:
HandleMsg<Render::AddPolysToSceneMsg>(std::move(reader), [this] (int shader, std::vector<polyVert_t> verts, int numVerts, int numPolys) {
HandleMsg<Render::AddPolysToSceneMsg>(std::move(reader), [this] (int shader, const std::vector<polyVert_t>& verts, int numVerts, int numPolys) {
re.AddPolysToScene(shader, numVerts, verts.data(), numPolys);
});
break;

case CG_R_ADDLIGHTTOSCENE:
HandleMsg<Render::AddLightToSceneMsg>(std::move(reader), [this] (std::array<float, 3> point, float radius, float intensity, float r, float g, float b, int shader, int flags) {
HandleMsg<Render::AddLightToSceneMsg>(std::move(reader), [this] (const std::array<float, 3>& point, float radius, float intensity, float r, float g, float b, int shader, int flags) {
re.AddLightToScene(point.data(), radius, intensity, r, g, b, shader, flags);
});
break;

case CG_R_ADDADDITIVELIGHTTOSCENE:
HandleMsg<Render::AddAdditiveLightToSceneMsg>(std::move(reader), [this] (std::array<float, 3> point, float intensity, float r, float g, float b) {
HandleMsg<Render::AddAdditiveLightToSceneMsg>(std::move(reader), [this] (const std::array<float, 3>& point, float intensity, float r, float g, float b) {
re.AddAdditiveLightToScene(point.data(), intensity, r, g, b);
});
break;

case CG_R_SETCOLOR:
HandleMsg<Render::SetColorMsg>(std::move(reader), [this] (std::array<float, 4> color) {
HandleMsg<Render::SetColorMsg>(std::move(reader), [this] (const std::array<float, 4>& color) {
re.SetColor(color.data());
});
break;

case CG_R_SETCLIPREGION:
HandleMsg<Render::SetClipRegionMsg>(std::move(reader), [this] (std::array<float, 4> region) {
HandleMsg<Render::SetClipRegionMsg>(std::move(reader), [this] (const std::array<float, 4>& region) {
re.SetClipRegion(region.data());
});
break;
@@ -2325,7 +2325,7 @@ void CGameVM::CmdBuffer::HandleCommandBufferSyscall(int major, int minor, Util::
break;

case CG_ADDVISTESTTOSCENE:
HandleMsg<Render::AddVisTestToSceneMsg>(std::move(reader), [this] (int handle, std::array<float, 3> pos, float depthAdjust, float area) {
HandleMsg<Render::AddVisTestToSceneMsg>(std::move(reader), [this] (int handle, const std::array<float, 3>& pos, float depthAdjust, float area) {
re.AddVisTestToScene(handle, pos.data(), depthAdjust, area);
});
break;
@@ -186,21 +186,22 @@ namespace VM {
}

void CommonVMServices::GetCvar(Util::Reader& reader, IPC::Channel& channel) {
IPC::HandleMsg<GetCvarMsg>(channel, std::move(reader), [&, this](std::string name, std::string& value){
IPC::HandleMsg<GetCvarMsg>(channel, std::move(reader), [&, this](const std::string& name, std::string& value){
//TODO check it is only looking at allowed cvars?
value = Cvar::GetValue(name);
});
}

void CommonVMServices::SetCvar(Util::Reader& reader, IPC::Channel& channel) {
IPC::HandleMsg<SetCvarMsg>(channel, std::move(reader), [this](std::string name, std::string value){
// Leaving value by value for now. May revist later.
IPC::HandleMsg<SetCvarMsg>(channel, std::move(reader), [this](const std::string& name, std::string value){
//TODO check it is only touching allowed cvars?
Cvar::SetValue(name, value);
});
}

void CommonVMServices::AddCvarFlags(Util::Reader& reader, IPC::Channel& channel) {
IPC::HandleMsg<AddCvarFlagsMsg>(channel, std::move(reader), [this](std::string name, int flags, bool& exists){
IPC::HandleMsg<AddCvarFlagsMsg>(channel, std::move(reader), [this](const std::string& name, int flags, bool& exists){
//TODO check it is only touching allowed cvars?
exists = Cvar::AddFlags(name, flags);
});
@@ -210,7 +211,7 @@ namespace VM {
void CommonVMServices::HandleLogSyscall(int minor, Util::Reader& reader, IPC::Channel& channel) {
switch(minor) {
case DISPATCH_EVENT:
IPC::HandleMsg<DispatchLogEventMsg>(channel, std::move(reader), [this](std::string text, int targetControl){
IPC::HandleMsg<DispatchLogEventMsg>(channel, std::move(reader), [this](const std::string& text, int targetControl){
Log::Dispatch(Log::Event(std::move(text)), targetControl);
});
break;
@@ -224,25 +225,25 @@ namespace VM {
void CommonVMServices::HandleCommonQVMSyscall(int minor, Util::Reader& reader, IPC::Channel& channel) {
switch (minor) {
case QVM_COMMON_PRINT:
IPC::HandleMsg<PrintMsg>(channel, std::move(reader), [this](std::string text) {
IPC::HandleMsg<PrintMsg>(channel, std::move(reader), [this](const std::string& text) {
Com_Printf("%s", text.c_str());
});
break;

case QVM_COMMON_ERROR:
IPC::HandleMsg<ErrorMsg>(channel, std::move(reader), [this](std::string text) {
IPC::HandleMsg<ErrorMsg>(channel, std::move(reader), [this](const std::string& text) {
Sys::Drop("%s VM: %s", vmName, text);
});
break;

case QVM_COMMON_SEND_CONSOLE_COMMAND:
IPC::HandleMsg<SendConsoleCommandMsg>(channel, std::move(reader), [this](std::string text) {
IPC::HandleMsg<SendConsoleCommandMsg>(channel, std::move(reader), [this](const std::string& text) {
Cmd::BufferCommandText(text);
});
break;

case QVM_COMMON_FS_FOPEN_FILE:
IPC::HandleMsg<FSFOpenFileMsg>(channel, std::move(reader), [this](std::string filename, bool open, int fsMode, int& success, int& handle) {
IPC::HandleMsg<FSFOpenFileMsg>(channel, std::move(reader), [this](const std::string& filename, bool open, int fsMode, int& success, int& handle) {
fsMode_t mode = static_cast<fsMode_t>(fsMode);
success = FS_Game_FOpenFileByMode(filename.c_str(), open ? &handle : nullptr, mode);
});
@@ -257,7 +258,7 @@ namespace VM {
break;

case QVM_COMMON_FS_WRITE:
IPC::HandleMsg<FSWriteMsg>(channel, std::move(reader), [this](int handle, std::string text, int& res) {
IPC::HandleMsg<FSWriteMsg>(channel, std::move(reader), [this](int handle, const std::string& text, int& res) {
res = FS_Write(text.c_str(), text.size(), handle);
});
break;
@@ -269,7 +270,7 @@ namespace VM {
break;

case QVM_COMMON_FS_RENAME:
IPC::HandleMsg<FSRenameMsg>(channel, std::move(reader), [this](std::string from, std::string to) {
IPC::HandleMsg<FSRenameMsg>(channel, std::move(reader), [this](const std::string& from, const std::string& to) {
FS_Rename(from.c_str(), to.c_str());
});
break;
@@ -281,7 +282,7 @@ namespace VM {
break;

case QVM_COMMON_FS_GET_FILE_LIST:
IPC::HandleMsg<FSGetFileListMsg>(channel, std::move(reader), [this](std::string path, std::string extension, int len, int& intRes, std::string& res) {
IPC::HandleMsg<FSGetFileListMsg>(channel, std::move(reader), [this](const std::string& path, std::string extension, int len, int& intRes, std::string& res) {
std::unique_ptr<char[]> buffer(new char[len]);
buffer[0] = '\0';
intRes = FS_GetFileList(path.c_str(), extension.c_str(), buffer.get(), len);
@@ -290,7 +291,7 @@ namespace VM {
break;

case QVM_COMMON_FS_GET_FILE_LIST_RECURSIVE:
IPC::HandleMsg<FSGetFileListRecursiveMsg>(channel, std::move(reader), [this](std::string path, std::string extension, int len, int& intRes, std::string& res) {
IPC::HandleMsg<FSGetFileListRecursiveMsg>(channel, std::move(reader), [this](const std::string& path, std::string extension, int len, int& intRes, std::string& res) {
std::unique_ptr<char[]> buffer(new char[len]);
buffer[0] = '\0';
intRes = FS_GetFileListRecursive(path.c_str(), extension.c_str(), buffer.get(), len);
@@ -299,13 +300,13 @@ namespace VM {
break;

case QVM_COMMON_FS_FIND_PAK:
IPC::HandleMsg<FSFindPakMsg>(channel, std::move(reader), [this](std::string pakName, bool& found) {
IPC::HandleMsg<FSFindPakMsg>(channel, std::move(reader), [this](const std::string& pakName, bool& found) {
found = FS::FindPak(pakName) != nullptr;
});
break;

case QVM_COMMON_FS_LOAD_PAK:
IPC::HandleMsg<FSLoadPakMsg>(channel, std::move(reader), [this](std::string pakName, std::string prefix, bool& found) {
IPC::HandleMsg<FSLoadPakMsg>(channel, std::move(reader), [this](const std::string& pakName, const std::string& prefix, bool& found) {
std::error_code err;
FS::PakPath::LoadPakPrefix(*FS::FindPak(pakName), prefix, err);
found = bool(err);
@@ -319,13 +320,13 @@ namespace VM {
break;

case QVM_COMMON_PARSE_ADD_GLOBAL_DEFINE:
IPC::HandleMsg<ParseAddGlobalDefineMsg>(channel, std::move(reader), [this](std::string define, int& res) {
IPC::HandleMsg<ParseAddGlobalDefineMsg>(channel, std::move(reader), [this](const std::string& define, int& res) {
res = Parse_AddGlobalDefine(define.c_str());
});
break;

case QVM_COMMON_PARSE_LOAD_SOURCE:
IPC::HandleMsg<ParseLoadSourceMsg>(channel, std::move(reader), [this](std::string name, int& res) {
IPC::HandleMsg<ParseLoadSourceMsg>(channel, std::move(reader), [this](const std::string& name, int& res) {
res = Parse_LoadSourceHandle(name.c_str());
});
break;
@@ -191,7 +191,7 @@ qhandle_t RE_RegisterVisTest()
{
return 1;
}
void RE_AddVisTestToScene( qhandle_t hTest, vec3_t pos, float depthAdjust, float area ) { }
void RE_AddVisTestToScene( qhandle_t hTest, const vec3_t pos, float depthAdjust, float area ) { }
float RE_CheckVisibility( qhandle_t hTest )
{
return 0.0f;
@@ -3609,7 +3609,7 @@ static inline void halfToFloat( const f16vec4_t in, vec4_t out )
void RE_RenderScene( const refdef_t *fd );

qhandle_t RE_RegisterVisTest();
void RE_AddVisTestToScene( qhandle_t hTest, vec3_t pos,
void RE_AddVisTestToScene( qhandle_t hTest, const vec3_t pos,
float depthAdjust, float area );
float RE_CheckVisibility( qhandle_t hTest );
void RE_UnregisterVisTest( qhandle_t hTest );
@@ -169,7 +169,7 @@ typedef struct

// VisTest API
qhandle_t ( *RegisterVisTest ) ();
void ( *AddVisTestToScene ) ( qhandle_t hTest, vec3_t pos,
void ( *AddVisTestToScene ) ( qhandle_t hTest, const vec3_t pos,
float depthAdjust, float area );
float ( *CheckVisibility ) ( qhandle_t hTest );
void ( *UnregisterVisTest ) ( qhandle_t hTest );
@@ -796,7 +796,7 @@ Add a VisTest to the current scene. If the VisTest is still
running from a prior scene, just noop.
================
*/
void RE_AddVisTestToScene( qhandle_t hTest, vec3_t pos, float depthAdjust,
void RE_AddVisTestToScene( qhandle_t hTest, const vec3_t pos, float depthAdjust,
float area )
{
visTest_t *test;
@@ -629,7 +629,7 @@ qhandle_t trap_RegisterVisTest()
return handle;
}

void trap_AddVisTestToScene( qhandle_t hTest, vec3_t pos, float depthAdjust, float area )
void trap_AddVisTestToScene( qhandle_t hTest, const vec3_t pos, float depthAdjust, float area )
{
std::array<float, 3> mypos;
VectorCopy(pos, mypos.data());

0 comments on commit 5f4a541

Please sign in to comment.
You can’t perform that action at this time.