Overhaul of MovieRecord class so it has a default contructor that initializes everything to 0, A deconstructor, and a get method for savestate vector. Fixes my timeline issues, but creates crash problems in TASEdit related to the deconstructor.

This commit is contained in:
adelikat 2010-05-15 01:05:42 +00:00
parent 691662f4c9
commit ddcd8f3566
3 changed files with 60 additions and 20 deletions

View File

@ -105,11 +105,11 @@ static LONG CustomDraw(NMLVCUSTOMDRAW* msg)
SelectObject(msg->nmcd.hdc,debugSystem->hFixedFont); SelectObject(msg->nmcd.hdc,debugSystem->hFixedFont);
if((msg->iSubItem-2)/8==0) if((msg->iSubItem-2)/8==0)
if((int)msg->nmcd.dwItemSpec < currMovieData.greenZoneCount && if((int)msg->nmcd.dwItemSpec < currMovieData.greenZoneCount &&
!currMovieData.records[msg->nmcd.dwItemSpec].savestate.empty()) !currMovieData.records[msg->nmcd.dwItemSpec].GetSavestate().empty())
msg->clrTextBk = RGB(192,255,192); msg->clrTextBk = RGB(192,255,192);
else {} else {}
else if((int)msg->nmcd.dwItemSpec < currMovieData.greenZoneCount && else if((int)msg->nmcd.dwItemSpec < currMovieData.greenZoneCount &&
!currMovieData.records[msg->nmcd.dwItemSpec].savestate.empty()) !currMovieData.records[msg->nmcd.dwItemSpec].GetSavestate().empty())
msg->clrTextBk = RGB(144,192,144); msg->clrTextBk = RGB(144,192,144);
else msg->clrTextBk = RGB(192,192,192); else msg->clrTextBk = RGB(192,192,192);
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
@ -233,7 +233,7 @@ void LockGreenZone(int newstart)
{ {
for (int i=1; i<newstart; ++i) for (int i=1; i<newstart; ++i)
{ {
currMovieData.records[i].savestate.clear(); currMovieData.records[i].GetSavestate().clear();
} }
} }
@ -268,8 +268,9 @@ bool JumpToFrame(int index)
} }
if (static_cast<unsigned int>(index)<currMovieData.records.size() && if (static_cast<unsigned int>(index)<currMovieData.records.size() &&
!currMovieData.records[index].savestate.empty() && !currMovieData.records[index].GetSavestate().empty() &&
MovieData::loadSavestateFrom(&currMovieData.records[index].savestate)) MovieData::loadSavestateFrom(&currMovieData.records[index].GetSavestate()))
//MovieData::loadSavestateFrom(&currMovieData.records[index].savestate))
{ {
currFrameCounter = index; currFrameCounter = index;
return true; return true;
@ -287,8 +288,8 @@ bool JumpToFrame(int index)
/* Search for an earlier frame, and try warping to the current. */ /* Search for an earlier frame, and try warping to the current. */
for (; i>0; --i) for (; i>0; --i)
{ {
if (!currMovieData.records[i].savestate.empty() && if (!currMovieData.records[i].GetSavestate().empty() &&
MovieData::loadSavestateFrom(&currMovieData.records[i].savestate)) MovieData::loadSavestateFrom(&currMovieData.records[i].GetSavestate()))
{ {
currFrameCounter=i; currFrameCounter=i;
turbo=i+60<index; // turbo unless close turbo=i+60<index; // turbo unless close
@ -299,7 +300,7 @@ bool JumpToFrame(int index)
poweron(true); poweron(true);
currFrameCounter=0; currFrameCounter=0;
MovieData::dumpSavestateTo(&currMovieData.records[0].savestate,0); MovieData::dumpSavestateTo(&currMovieData.records[0].GetSavestate(),0);
turbo = index>60; turbo = index>60;
pauseframe=index+1; pauseframe=index+1;
} }
@ -309,7 +310,7 @@ bool JumpToFrame(int index)
{ {
poweron(false); poweron(false);
currFrameCounter=0; currFrameCounter=0;
MovieData::dumpSavestateTo(&currMovieData.records[0].savestate,0); MovieData::dumpSavestateTo(&currMovieData.records[0].GetSavestate(),0);
return true; return true;
} }

View File

@ -130,7 +130,7 @@ void MovieData::TryDumpIncremental()
{ {
if (turbo && pauseframe-256>currFrameCounter && ((currFrameCounter-pauseframe)&0xff)) if (turbo && pauseframe-256>currFrameCounter && ((currFrameCounter-pauseframe)&0xff))
return; return;
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_DEFAULT_COMPRESSION); MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].GetSavestate(),Z_DEFAULT_COMPRESSION);
} }
if(currFrameCounter == currMovieData.greenZoneCount) if(currFrameCounter == currMovieData.greenZoneCount)
{ {
@ -139,20 +139,50 @@ void MovieData::TryDumpIncremental()
currMovieData.insertEmpty(-1,1); currMovieData.insertEmpty(-1,1);
} }
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_DEFAULT_COMPRESSION); MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].GetSavestate(),Z_DEFAULT_COMPRESSION);
currMovieData.greenZoneCount++; currMovieData.greenZoneCount++;
} else if (currFrameCounter < currMovieData.greenZoneCount || !movie_readonly) } else if (currFrameCounter < currMovieData.greenZoneCount || !movie_readonly)
{ {
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_DEFAULT_COMPRESSION); MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].GetSavestate(),Z_DEFAULT_COMPRESSION);
} else if (currFrameCounter > currMovieData.greenZoneCount && static_cast<unsigned int>(currMovieData.greenZoneCount)<currMovieData.records.size()) } else if (currFrameCounter > currMovieData.greenZoneCount && static_cast<unsigned int>(currMovieData.greenZoneCount)<currMovieData.records.size())
{ {
/* May be required in some malformed TAS projects. */ /* May be required in some malformed TAS projects. */
MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].savestate,Z_DEFAULT_COMPRESSION); MovieData::dumpSavestateTo(&currMovieData.records[currFrameCounter].GetSavestate(),Z_DEFAULT_COMPRESSION);
currMovieData.greenZoneCount= currFrameCounter+1; currMovieData.greenZoneCount= currFrameCounter+1;
} }
} }
} }
MovieRecord::MovieRecord()
{
joysticks.data[0] = 0;
joysticks.data[1] = 0;
joysticks.data[2] = 0;
joysticks.data[3] = 0;
commands = 0;
zappers[0].b = 0;
zappers[0].bogo = 0;
zappers[0].x = 0;
zappers[0].y = 0;
zappers[0].zaphit = 0;
zappers[1].b = 0;
zappers[1].bogo = 0;
zappers[1].x = 0;
zappers[1].y = 0;
zappers[1].zaphit = 0;
savestate = NULL;
}
MovieRecord::~MovieRecord()
{
if (savestate != NULL)
delete savestate;
}
void MovieRecord::clear() void MovieRecord::clear()
{ {
commands = 0; commands = 0;
@ -170,6 +200,7 @@ bool MovieRecord::Compare(MovieRecord& compareRec)
//if (this->commands != compareRec.commands) //if (this->commands != compareRec.commands)
// return false; // return false;
//if new commands are ever recordable, they need to be added here if we go with this method
if(this->command_reset() != compareRec.command_reset()) return false; if(this->command_reset() != compareRec.command_reset()) return false;
if(this->command_power() != compareRec.command_reset()) return false; if(this->command_power() != compareRec.command_reset()) return false;
if(this->command_fds_insert() != compareRec.command_fds_insert()) return false; if(this->command_fds_insert() != compareRec.command_fds_insert()) return false;
@ -497,14 +528,14 @@ int MovieData::dumpGreenzone(std::ostream *os, bool binary)
int frame, size; int frame, size;
for (int i=0; i<(int)records.size(); ++i) for (int i=0; i<(int)records.size(); ++i)
{ {
if (records[i].savestate.empty()) if (records[i].GetSavestate().empty())
continue; continue;
frame=i; frame=i;
size=records[i].savestate.size(); size=records[i].GetSavestate().size();
write32le(frame, os); write32le(frame, os);
write32le(size, os); write32le(size, os);
os->write(&records[i].savestate[0], size); os->write(&records[i].GetSavestate()[0], size);
} }
frame=-1; frame=-1;
size=currMovieData.greenZoneCount; size=currMovieData.greenZoneCount;
@ -1269,7 +1300,7 @@ bool FCEUMOV_ReadState(std::istream* is, uint32 size)
if(movie_readonly) if(movie_readonly)
{ {
bool sameTimeline = true; //= CheckTimelines(tempMovieData, currMovieData); bool sameTimeline = CheckTimelines(tempMovieData, currMovieData);
if (sameTimeline) if (sameTimeline)
{ {

View File

@ -96,6 +96,8 @@ class MovieRecord
{ {
public: public:
MovieRecord();
~MovieRecord();
ValueArray<uint8,4> joysticks; ValueArray<uint8,4> joysticks;
struct { struct {
@ -141,9 +143,6 @@ public:
bool Compare(MovieRecord& compareRec); bool Compare(MovieRecord& compareRec);
void clear(); void clear();
//a waste of memory in lots of cases.. maybe make it a pointer later?
std::vector<char> savestate;
void parse(MovieData* md, std::istream* is); void parse(MovieData* md, std::istream* is);
bool parseBinary(MovieData* md, std::istream* is); bool parseBinary(MovieData* md, std::istream* is);
void dump(MovieData* md, std::ostream* os, int index); void dump(MovieData* md, std::ostream* os, int index);
@ -153,7 +152,16 @@ public:
static const char mnemonics[8]; static const char mnemonics[8];
std::vector<char>& GetSavestate()
{
if (savestate == NULL)
savestate = new std::vector<char>;
return *savestate;
}
private: private:
//a waste of memory in lots of cases.. maybe make it a pointer later?
std::vector<char> *savestate;
int mask(int bit) { return 1<<bit; } int mask(int bit) { return 1<<bit; }
}; };