Skip to content

Commit

Permalink
Merge pull request #187 from Bigpet/master
Browse files Browse the repository at this point in the history
range-check and more explicit ownership with vector<ptr>
  • Loading branch information
AlexAltea committed Apr 14, 2014
2 parents 5dc9be6 + 8ef9414 commit aa8e854
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 49 deletions.
1 change: 1 addition & 0 deletions rpcs3/Emu/CPU/CPUThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CPUThread& CPUThreadManager::AddThread(CPUThreadType type)
return *new_thread;
}

//TODO: find out where the thread is actually deleted because it's sure as shit not here
void CPUThreadManager::RemoveThread(const u32 id)
{
std::lock_guard<std::mutex> lock(m_mtx_thread);
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/FS/VFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct VFSManagerEntry

struct VFS
{
//TODO: find out where these are supposed to be deleted or just make it shared_ptr
//and also make GetDevice and GetDeviceLocal return shared_ptr then.
std::vector<vfsDevice *> m_devices;
void Mount(const std::string& ps3_path, const std::string& local_path, vfsDevice* device);
void UnMount(const std::string& ps3_path);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/GS/GL/GLGSRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ void GLGSRender::Flip()

for(uint i=0; i<m_post_draw_objs.size(); ++i)
{
m_post_draw_objs[i]->Draw();
m_post_draw_objs[i].Draw();
}

m_frame->Flip(m_context);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/GS/GL/GLGSRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class GLGSRender
{
private:
std::vector<u8> m_vdata;
std::vector<PostDrawObj *> m_post_draw_objs;
std::vector<PostDrawObj> m_post_draw_objs;

GLProgram m_program;
int m_fp_buf_num;
Expand Down
25 changes: 14 additions & 11 deletions rpcs3/Emu/GS/GL/GLVertexProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ std::string GLVertexDecompilerThread::GetFunc()

for(uint i=0; i<m_funcs.size(); ++i)
{
if(m_funcs[i]->name.compare(name) == 0)
if(m_funcs[i].name.compare(name) == 0)
return name + "()";
}

m_funcs.push_back(new FuncInfo());
uint idx = m_funcs.size()-1;
m_funcs[idx]->offset = offset;
m_funcs[idx]->name = name;
m_funcs.emplace_back();
FuncInfo &idx = m_funcs.back();
idx.offset = offset;
idx.name = name;

return name + "()";
}
Expand All @@ -283,7 +283,7 @@ std::string GLVertexDecompilerThread::BuildFuncBody(const FuncInfo& func)
uint call_func = -1;
for(uint j=0; j<m_funcs.size(); ++j)
{
if(m_funcs[j]->offset == i)
if(m_funcs[j].offset == i)
{
call_func = j;
break;
Expand All @@ -292,7 +292,7 @@ std::string GLVertexDecompilerThread::BuildFuncBody(const FuncInfo& func)

if(call_func != -1)
{
result += '\t' + m_funcs[call_func]->name + "();\n";
result += '\t' + m_funcs[call_func].name + "();\n";
break;
}
}
Expand All @@ -316,17 +316,17 @@ std::string GLVertexDecompilerThread::BuildCode()

for(int i=m_funcs.size() - 1; i>0; --i)
{
fp += fmt::Format("void %s();\n", m_funcs[i]->name.c_str());
fp += fmt::Format("void %s();\n", m_funcs[i].name.c_str());
}

std::string f;

f += fmt::Format("void %s()\n{\n\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n\t%s();\n\tgl_Position = gl_Position * scaleOffsetMat;\n}\n",
m_funcs[0]->name.c_str(), m_funcs[1]->name.c_str());
m_funcs[0].name.c_str(), m_funcs[1].name.c_str());

for(uint i=1; i<m_funcs.size(); ++i)
{
f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i]->name.c_str(), BuildFuncBody(*m_funcs[i]).c_str());
f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.c_str(), BuildFuncBody(m_funcs[i]).c_str());
}

static const std::string& prot =
Expand Down Expand Up @@ -437,7 +437,10 @@ void GLVertexDecompilerThread::Task()
m_shader = BuildCode();

m_body.clear();
m_funcs = std::vector<FuncInfo *>(m_funcs.begin(),m_funcs.begin()+3);
if (m_funcs.size() > 2)
{
m_funcs.erase(m_funcs.begin()+2, m_funcs.end());
}
}

GLVertexProgram::GLVertexProgram()
Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Emu/GS/GL/GLVertexProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct GLVertexDecompilerThread : public ThreadBase

std::vector<std::string> m_body;

std::vector<FuncInfo *> m_funcs;
std::vector<FuncInfo> m_funcs;

//wxString main;
std::string& m_shader;
Expand All @@ -148,12 +148,12 @@ struct GLVertexDecompilerThread : public ThreadBase
, m_shader(shader)
, m_parr(parr)
{
m_funcs.push_back(new FuncInfo());
m_funcs[0]->offset = 0;
m_funcs[0]->name = "main";
m_funcs.push_back(new FuncInfo());
m_funcs[1]->offset = 0;
m_funcs[1]->name = "func0";
m_funcs.emplace_back();
m_funcs[0].offset = 0;
m_funcs[0].name = "main";
m_funcs.emplace_back();
m_funcs[1].offset = 0;
m_funcs[1].name = "func0";
//m_cur_func->body = "\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n";
}

Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/SysCalls/Modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ __forceinline void Module::AddFuncSub(const char group[8], const u64 ops[], char
{
if (!ops[0]) return;

//TODO: track down where this is supposed to be deleted
SFunc* sf = new SFunc;
sf->ptr = (void *)func;
sf->func = bind_func(func);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const u16 bpdb_version = 0x1000;

ModuleInitializer::ModuleInitializer()
{
Emu.AddModuleInit(this);
Emu.AddModuleInit(std::move(std::unique_ptr<ModuleInitializer>(this)));
}

Emulator::Emulator()
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Emulator
u32 m_ppu_thr_exit;
MemoryViewerPanel* m_memory_viewer;
//ArrayF<CPUThread> m_cpu_threads;
std::vector<ModuleInitializer *> m_modules_init;
std::vector<std::unique_ptr<ModuleInitializer>> m_modules_init;

std::vector<u64> m_break_points;
std::vector<u64> m_marked_points;
Expand Down Expand Up @@ -123,9 +123,9 @@ class Emulator
CPUThread& GetCallbackThread() { return *m_ppu_callback_thr; }
EventManager& GetEventManager() { return *m_event_manager; }

void AddModuleInit(ModuleInitializer* m)
void AddModuleInit(std::unique_ptr<ModuleInitializer> m)
{
m_modules_init.push_back(m);
m_modules_init.push_back(std::move(m));
}

void SetTLSData(const u64 addr, const u64 filesz, const u64 memsz)
Expand Down
53 changes: 28 additions & 25 deletions rpcs3/Gui/GameViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ struct Column

struct ColumnsArr
{
std::vector<Column *> m_columns;
std::vector<Column> m_columns;

ColumnsArr()
{
Init();
}

std::vector<Column*>* GetSortedColumnsByPos()
std::vector<Column*> GetSortedColumnsByPos()
{
static std::vector<Column*> arr; arr.clear();
std::vector<Column*> arr;
for(u32 pos=0; pos<m_columns.size(); pos++)
{
for(u32 c=0; c<m_columns.size(); ++c)
{
if(m_columns[c]->pos != pos) continue;
arr.push_back(m_columns[c]);
if(m_columns[c].pos != pos) continue;
arr.push_back(&m_columns[c]);
}
}

return &arr;
return arr;
}

Column* GetColumnByPos(u32 pos)
{
std::vector<Column *>& columns = *GetSortedColumnsByPos();
std::vector<Column *> columns = GetSortedColumnsByPos();
for(u32 c=0; c<columns.size(); ++c)
{
if(!columns[c]->shown)
Expand All @@ -78,15 +78,18 @@ struct ColumnsArr
void Init()
{
m_columns.clear();

#define ADD_COLUMN(x, w, n) x = new Column(m_columns.size(), w, n); m_columns.push_back(x);
ADD_COLUMN(m_col_name, 160, "Name");
ADD_COLUMN(m_col_serial, 85, "Serial");
ADD_COLUMN(m_col_fw, 55, "FW");
ADD_COLUMN(m_col_app_ver, 55, "App version");
ADD_COLUMN(m_col_category, 55, "Category");
ADD_COLUMN(m_col_path, 160, "Path");
#undef ADD_COLUMN
m_columns.emplace_back(m_columns.size(), 160, "Name");
m_columns.emplace_back(m_columns.size(), 85, "Serial");
m_columns.emplace_back(m_columns.size(), 55, "FW");
m_columns.emplace_back(m_columns.size(), 55, "App version");
m_columns.emplace_back(m_columns.size(), 55, "Category");
m_columns.emplace_back(m_columns.size(), 160, "Path");
m_col_name = &m_columns[0];
m_col_serial = &m_columns[1];
m_col_fw = &m_columns[2];
m_col_app_ver = &m_columns[3];
m_col_category = &m_columns[4];
m_col_path = &m_columns[5];
}

void Update(std::vector<GameInfo>& game_data)
Expand Down Expand Up @@ -114,7 +117,7 @@ struct ColumnsArr
void Show(wxListView* list)
{
list->DeleteAllColumns();
std::vector<Column *>& c_col = *GetSortedColumnsByPos();
std::vector<Column *> c_col = GetSortedColumnsByPos();
for(u32 i=0, c=0; i<c_col.size(); ++i)
{
if(!c_col[i]->shown) continue;
Expand Down Expand Up @@ -158,19 +161,19 @@ struct ColumnsArr
#define ADD_COLUMN(v, dv, t, n, isshown) \
{ \
IniEntry<t> ini; \
ini.Init(m_columns[i]->name + "_" + n, path); \
if(isLoad) m_columns[i]->v = ini.LoadValue(dv); \
else if(isshown ? m_columns[i]->shown : 1) \
ini.Init(m_columns[i].name + "_" + n, path); \
if(isLoad) m_columns[i].v = ini.LoadValue(dv); \
else if(isshown ? m_columns[i].shown : 1) \
{ \
ini.SetValue(m_columns[i]->v); \
ini.SetValue(m_columns[i].v); \
ini.Save(); \
} \
}

for(u32 i=0; i<m_columns.size(); ++i)
{
ADD_COLUMN(pos, m_columns[i]->def_pos, int, "position", 1);
ADD_COLUMN(width, m_columns[i]->def_width, int, "width", 1);
ADD_COLUMN(pos, m_columns[i].def_pos, int, "position", 1);
ADD_COLUMN(width, m_columns[i].def_width, int, "width", 1);
ADD_COLUMN(shown, true, bool, "shown", 0);
}

Expand All @@ -181,7 +184,7 @@ struct ColumnsArr
{
for(u32 c2=c1+1; c2<m_columns.size(); ++c2)
{
if(m_columns[c1]->pos == m_columns[c2]->pos)
if(m_columns[c1].pos == m_columns[c2].pos)
{
ConLog.Error("Columns loaded with error!");
Init();
Expand All @@ -195,7 +198,7 @@ struct ColumnsArr
bool ishas = false;
for(u32 c=0; c<m_columns.size(); ++c)
{
if(m_columns[c]->pos != p) continue;
if(m_columns[c].pos != p) continue;
ishas = true;
break;
}
Expand Down

0 comments on commit aa8e854

Please sign in to comment.