From 6bd044f9be56d325c77f6279d269046a82c82b19 Mon Sep 17 00:00:00 2001 From: Sacha Date: Mon, 14 Jul 2014 17:26:31 +1000 Subject: [PATCH] c++11 fixups. Initialise to zero where possible. note: cellAudio looks quite messed up. --- rpcs3/Emu/GS/GL/GLVertexProgram.cpp | 3 +- rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp | 12 ++--- rpcs3/Emu/SysCalls/Modules/cellAudio.cpp | 57 +++++++++------------- rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp | 12 ++--- rpcs3/Emu/SysCalls/Modules/cellVpost.cpp | 20 +++----- 5 files changed, 39 insertions(+), 65 deletions(-) diff --git a/rpcs3/Emu/GS/GL/GLVertexProgram.cpp b/rpcs3/Emu/GS/GL/GLVertexProgram.cpp index 82f08dc5b7..665f564c24 100644 --- a/rpcs3/Emu/GS/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/GS/GL/GLVertexProgram.cpp @@ -643,9 +643,8 @@ void GLVertexProgram::Compile() if(r) { - char* buf = new char[r+1]; + char* buf = new char[r+1](); GLsizei len; - memset(buf, 0, r+1); glGetShaderInfoLog(id, r, &len, buf); LOG_ERROR(RSX, "Failed to compile vertex shader: %s", buf); delete[] buf; diff --git a/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp b/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp index 5a4dbf2123..fc0989e528 100644 --- a/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp +++ b/rpcs3/Emu/SysCalls/Modules/SC_Pad.cpp @@ -110,8 +110,7 @@ int cellPadGetData(u32 port_no, u32 data_addr) if(port_no >= rinfo.now_connect) return CELL_PAD_ERROR_NO_DEVICE; Pad& pad = pads[port_no]; - CellPadData data; - memset(&data, 0, sizeof(CellPadData)); + CellPadData data = {}; u16 d1Initial, d2Initial; d1Initial = pad.m_digital_1; @@ -301,8 +300,7 @@ int cellPadGetInfo(u32 info_addr) sys_io->Log("cellPadGetInfo(info_addr=0x%x)", info_addr); if(!Emu.GetPadManager().IsInited()) return CELL_PAD_ERROR_UNINITIALIZED; - CellPadInfo info; - memset(&info, 0, sizeof(CellPadInfo)); + CellPadInfo info = {}; const PadInfo& rinfo = Emu.GetPadManager().GetInfo(); info.max_connect = rinfo.max_connect; @@ -333,8 +331,7 @@ int cellPadGetInfo2(u32 info_addr) sys_io->Log("cellPadGetInfo2(info_addr=0x%x)", info_addr); if(!Emu.GetPadManager().IsInited()) return CELL_PAD_ERROR_UNINITIALIZED; - CellPadInfo2 info; - memset(&info, 0, sizeof(CellPadInfo2)); + CellPadInfo2 info = {}; const PadInfo& rinfo = Emu.GetPadManager().GetInfo(); info.max_connect = rinfo.max_connect; @@ -370,8 +367,7 @@ int cellPadGetCapabilityInfo(u32 port_no, mem32_t info_addr) const std::vector& pads = Emu.GetPadManager().GetPads(); - CellCapabilityInfo data; - memset(&data, 0, sizeof(CellCapabilityInfo)); + CellCapabilityInfo data = {}; //Should return the same as device capability mask, psl1ght has it backwards in pad.h data.info[0] = pads[port_no].m_device_capability; diff --git a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp index 9ff294a1aa..8a275aed96 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp @@ -21,6 +21,8 @@ static const bool g_is_u16 = Ini.AudioConvertToU16.GetValue(); // libaudio Functions +#define BUFFER_NUM 32 +#define BUFFER_SIZE 256 int cellAudioInit() { cellAudio->Warning("cellAudioInit()"); @@ -57,30 +59,25 @@ int cellAudioInit() if (Ini.AudioDumpToFile.GetValue()) m_dump.WriteHeader(); - float buf2ch[2 * 256]; // intermediate buffer for 2 channels - float buf8ch[8 * 256]; // intermediate buffer for 8 channels + float buf2ch[2 * BUFFER_SIZE]; // intermediate buffer for 2 channels + float buf8ch[8 * BUFFER_SIZE]; // intermediate buffer for 8 channels uint oal_buffer_offset = 0; - const uint oal_buffer_size = sizeof(buf2ch) / sizeof(float); + const uint oal_buffer_size = 2 * BUFFER_SIZE; - std::unique_ptr oal_buffer[32]; - SQueue queue; + std::unique_ptr oal_buffer[BUFFER_NUM]; + std::unique_ptr oal_buffer_float[BUFFER_NUM]; - std::unique_ptr oal_buffer_float[32]; - SQueue queue_float; - - for (u32 i = 0; i < sizeof(oal_buffer) / sizeof(oal_buffer[0]); i++) + for (u32 i = 0; i < BUFFER_NUM; i++) { - oal_buffer[i] = std::unique_ptr(new s16[oal_buffer_size]); - memset(oal_buffer[i].get(), 0, oal_buffer_size * sizeof(s16)); + oal_buffer[i] = std::unique_ptr(new s16[oal_buffer_size] {} ); + oal_buffer_float[i] = std::unique_ptr(new float[oal_buffer_size] {} ); } + + SQueue queue; queue.Clear(); - for (u32 i = 0; i < sizeof(oal_buffer_float) / sizeof(oal_buffer_float[0]); i++) - { - oal_buffer_float[i] = std::unique_ptr(new float[oal_buffer_size]); - memset(oal_buffer_float[i].get(), 0, oal_buffer_size * sizeof(float)); - } + SQueue queue_float; queue_float.Clear(); std::vector keys; @@ -89,10 +86,11 @@ int cellAudioInit() { m_audio_out->Init(); + // Note: What if the ini value changes? if (g_is_u16) m_audio_out->Open(oal_buffer[0].get(), oal_buffer_size * sizeof(s16)); - - m_audio_out->Open(oal_buffer_float[0].get(), oal_buffer_size * sizeof(float)); + else + m_audio_out->Open(oal_buffer_float[0].get(), oal_buffer_size * sizeof(float)); } m_config.start_time = get_system_time(); @@ -108,34 +106,27 @@ int cellAudioInit() if (g_is_u16) queue.Pop(oal_buffer); + else + queue_float.Pop(oal_buffer_float); - queue_float.Pop(oal_buffer_float); - if (g_is_u16) { if (oal_buffer) { m_audio_out->AddData(oal_buffer, oal_buffer_size * sizeof(s16)); - } - else - { - internal_finished = true; - return; + continue; } } - else { if (oal_buffer_float) { m_audio_out->AddData(oal_buffer_float, oal_buffer_size * sizeof(float)); - } - else - { - internal_finished = true; - return; + continue; } } + internal_finished = true; + return; } }); iat.detach(); @@ -161,8 +152,8 @@ int cellAudioInit() m_config.counter++; - const u32 oal_pos = m_config.counter % (sizeof(oal_buffer) / sizeof(oal_buffer[0])); - const u32 oal_pos_float = m_config.counter % (sizeof(oal_buffer_float) / sizeof(oal_buffer_float[0])); + const u32 oal_pos = m_config.counter % BUFFER_NUM; + const u32 oal_pos_float = m_config.counter % BUFFER_NUM; if (Emu.IsPaused()) { diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp index caa363b96d..9d6512de52 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp @@ -148,8 +148,7 @@ int cellVideoOutGetState(u32 videoOut, u32 deviceIndex, u32 state_addr) if(deviceIndex) return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND; - CellVideoOutState state; - memset(&state, 0, sizeof(CellVideoOutState)); + CellVideoOutState state = {}; switch(videoOut) { @@ -246,8 +245,7 @@ int cellVideoOutGetConfiguration(u32 videoOut, u32 config_addr, u32 option_addr) if(!Memory.IsGoodAddr(config_addr, sizeof(CellVideoOutConfiguration))) return CELL_EFAULT; - CellVideoOutConfiguration config; - memset(&config, 0, sizeof(CellVideoOutConfiguration)); + CellVideoOutConfiguration config = {}; switch(videoOut) { @@ -471,8 +469,7 @@ int cellAudioOutGetSoundAvailability2(u32 audioOut, u32 type, u32 fs, u32 ch, u3 int cellAudioOutGetState(u32 audioOut, u32 deviceIndex, u32 state_addr) { cellSysutil->Warning("cellAudioOutGetState(audioOut=0x%x,deviceIndex=0x%x,state_addr=0x%x)",audioOut,deviceIndex,state_addr); - CellAudioOutState state; - memset(&state, 0, sizeof(CellAudioOutState)); + CellAudioOutState state = {}; switch(audioOut) { @@ -541,8 +538,7 @@ int cellAudioOutGetConfiguration(u32 audioOut, u32 config_addr, u32 option_addr) if(!Memory.IsGoodAddr(config_addr, sizeof(CellAudioOutConfiguration))) return CELL_EFAULT; - CellAudioOutConfiguration config; - memset(&config, 0, sizeof(CellAudioOutConfiguration)); + CellAudioOutConfiguration config = {}; switch(audioOut) { diff --git a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp index ae26d1a07c..b08dda80f4 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp @@ -159,13 +159,11 @@ int cellVpostExec(u32 handle, const u32 inPicBuff_addr, const mem_ptr_treserved2 = 0; u64 stamp0 = get_system_time(); - - u8* pY = (u8*)malloc(w*h); // color planes - u8* pU = (u8*)malloc(w*h/4); - u8* pV = (u8*)malloc(w*h/4); - u8* pA = (u8*)malloc(w*h); - u32* res = (u32*)malloc(ow*oh*4); // RGBA interleaved output - const u8 alpha = ctrlParam->outAlpha; + auto pY = std::unique_ptr{ new u8[w*h] }.get(); // color planes + auto pU = std::unique_ptr{ new u8[w*h/4] }.get(); + auto pV = std::unique_ptr{ new u8[w*h/4] }.get(); + auto pA = std::unique_ptr{ new u8[w*h] }.get(); + auto res = std::unique_ptr{ new u32[ow*oh*4] }.get(); // RGBA interleaved output if (!Memory.CopyToReal(pY, inPicBuff_addr, w*h)) { @@ -185,7 +183,7 @@ int cellVpostExec(u32 handle, const u32 inPicBuff_addr, const mem_ptr_toutAlpha, w*h); u64 stamp1 = get_system_time(); @@ -210,12 +208,6 @@ int cellVpostExec(u32 handle, const u32 inPicBuff_addr, const mem_ptr_t