Merge pull request #187 from Bigpet/master

range-check and more explicit ownership with vector<ptr>
This commit is contained in:
Alexandro Sánchez Bach 2014-04-15 00:55:07 +02:00
commit aa8e854be2
10 changed files with 59 additions and 49 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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 + "()";
}
@ -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;
@ -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;
}
}
@ -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 =
@ -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()

View File

@ -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;
@ -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";
}

View File

@ -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);

View File

@ -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()

View File

@ -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;
@ -123,9 +123,9 @@ public:
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)

View File

@ -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)
@ -78,15 +78,18 @@ public:
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)
@ -114,7 +117,7 @@ public:
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;
@ -158,19 +161,19 @@ public:
#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);
}
@ -181,7 +184,7 @@ public:
{
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();
@ -195,7 +198,7 @@ public:
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;
}