More fixes and optimizations.

Originally committed to SVN as r2367.
This commit is contained in:
Rodrigo Braz Monteiro 2008-09-20 01:46:24 +00:00
parent bf9f2b50b7
commit 1397871e45
14 changed files with 105 additions and 138 deletions

View File

@ -96,7 +96,7 @@
Name="Release|Win32" Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)" OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2" ConfigurationType="4"
CharacterSet="1" CharacterSet="1"
WholeProgramOptimization="1" WholeProgramOptimization="1"
> >
@ -119,6 +119,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
AdditionalOptions="/MP" AdditionalOptions="/MP"
Optimization="2" Optimization="2"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="false" OmitFramePointers="false"
@ -146,15 +147,11 @@
Name="VCPreLinkEventTool" Name="VCPreLinkEventTool"
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLibrarianTool"
OutputFile="../bin/aegilib.dll"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
/> />
<Tool
Name="VCManifestTool"
/>
<Tool <Tool
Name="VCXDCMakeTool" Name="VCXDCMakeTool"
/> />
@ -164,9 +161,6 @@
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
/> />
<Tool
Name="VCAppVerifierTool"
/>
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
/> />
@ -279,10 +273,6 @@
RelativePath=".\include\aegilib\range.h" RelativePath=".\include\aegilib\range.h"
> >
</File> </File>
<File
RelativePath=".\include\aegilib\selection.h"
>
</File>
<File <File
RelativePath=".\include\aegilib\serialize.h" RelativePath=".\include\aegilib\serialize.h"
> >
@ -396,7 +386,7 @@
> >
</File> </File>
<File <File
RelativePath=".\include\aegilib\action.h" RelativePath=".\src\action.h"
> >
</File> </File>
<File <File
@ -415,26 +405,34 @@
RelativePath=".\src\section.cpp" RelativePath=".\src\section.cpp"
> >
</File> </File>
<File
RelativePath=".\src\section.h"
>
</File>
<File <File
RelativePath=".\src\section_entry.cpp" RelativePath=".\src\section_entry.cpp"
> >
</File> </File>
<File <File
RelativePath=".\include\aegilib\section_entry.h" RelativePath=".\src\section_entry.h"
> >
</File> </File>
<File <File
RelativePath=".\include\aegilib\section_entry_dialogue.h" RelativePath=".\src\section_entry_dialogue.h"
> >
</File> </File>
<File <File
RelativePath=".\include\aegilib\section_entry_style.h" RelativePath=".\src\section_entry_style.h"
> >
</File> </File>
<File <File
RelativePath=".\src\selection.cpp" RelativePath=".\src\selection.cpp"
> >
</File> </File>
<File
RelativePath=".\src\selection.h"
>
</File>
<File <File
RelativePath=".\src\stdint.h" RelativePath=".\src\stdint.h"
> >

View File

@ -33,7 +33,7 @@
// Contact: mailto:amz@aegisub.net // Contact: mailto:amz@aegisub.net
// //
#define ATHENA_DLL //#define ATHENA_DLL
#ifdef ATHENA_DLL #ifdef ATHENA_DLL
#ifdef ATHENA_EXPORTS #ifdef ATHENA_EXPORTS
#define ATHENA_API __declspec(dllexport) #define ATHENA_API __declspec(dllexport)

View File

@ -253,15 +253,6 @@ namespace Athenasub {
virtual String GetDefaultGroup() const = 0; virtual String GetDefaultGroup() const = 0;
virtual Entry Clone() const = 0; virtual Entry Clone() const = 0;
/*
static PlainText GetAsPlain(Entry ptr);
static Dialogue GetAsDialogue(Entry ptr);
static DialogueConst GetAsDialogue(EntryConst ptr);
static Style GetAsStyle(Entry ptr);
static Attachment GetAsFile(Entry ptr);
static RawEntry GetAsRaw(Entry ptr);
*/
}; };
@ -298,8 +289,8 @@ namespace Athenasub {
// Write accessors // Write accessors
virtual void SetText(const String& text) = 0; virtual void SetText(const String& text) = 0;
virtual void SetStartTime(Time start) = 0; virtual void SetStartTime(const ITime& start) = 0;
virtual void SetEndTime(Time end) = 0; virtual void SetEndTime(const ITime& end) = 0;
virtual void SetStartFrame(int start) = 0; virtual void SetStartFrame(int start) = 0;
virtual void SetEndFrame(int end) = 0; virtual void SetEndFrame(int end) = 0;
virtual void SetComment(bool isComment) = 0; virtual void SetComment(bool isComment) = 0;

View File

@ -49,7 +49,6 @@ namespace Athenasub {
public: public:
ActionInsert(Entry entry,int line,const String &section); ActionInsert(Entry entry,int line,const String &section);
~ActionInsert() {}
Action GetAntiAction(const IModel& model) const; Action GetAntiAction(const IModel& model) const;
void Execute(IModel& model); void Execute(IModel& model);
@ -63,7 +62,6 @@ namespace Athenasub {
public: public:
ActionRemove(int line,const String &section); ActionRemove(int line,const String &section);
~ActionRemove() {}
Action GetAntiAction(const IModel& model) const; Action GetAntiAction(const IModel& model) const;
void Execute(IModel& model); void Execute(IModel& model);
@ -81,7 +79,6 @@ namespace Athenasub {
public: public:
ActionModify(Entry entry,int line,const String &section,bool noTextFields); ActionModify(Entry entry,int line,const String &section,bool noTextFields);
ActionModify(shared_ptr<void> delta,int line,const String &section); ActionModify(shared_ptr<void> delta,int line,const String &section);
~ActionModify() {}
Action GetAntiAction(const IModel& model) const; Action GetAntiAction(const IModel& model) const;
void Execute(IModel& model); void Execute(IModel& model);
@ -98,7 +95,6 @@ namespace Athenasub {
public: public:
ActionModifyBatch(std::vector<Entry> entries,std::vector<VoidPtr> deltas,Selection selection,const String &section,bool noTextFields); ActionModifyBatch(std::vector<Entry> entries,std::vector<VoidPtr> deltas,Selection selection,const String &section,bool noTextFields);
~ActionModifyBatch() {}
Action GetAntiAction(const IModel& model) const; Action GetAntiAction(const IModel& model) const;
void Execute(IModel& model); void Execute(IModel& model);

View File

@ -40,7 +40,7 @@ using namespace Athenasub;
/////////////// ///////////////
// Constructor // Constructor
CActionList::CActionList(Model _model,String _actionName,const String _owner,bool _undoAble) CActionList::CActionList(weak_ptr<IModel> _model,String _actionName,const String _owner,bool _undoAble)
: model(_model), owner(_owner), undoAble(_undoAble) : model(_model), owner(_owner), undoAble(_undoAble)
{ {
valid = false; valid = false;
@ -96,7 +96,7 @@ void CActionList::Start(const String name)
void CActionList::Finish() void CActionList::Finish()
{ {
if (valid) { if (valid) {
model->ProcessActionList(*this); Model(model)->ProcessActionList(*this);
actions.clear(); actions.clear();
valid = false; valid = false;
} }
@ -125,7 +125,7 @@ void CActionList::RemoveLine(int position,const String section)
// Insert a "modify line" action // Insert a "modify line" action
Entry CActionList::ModifyLine(int position,const String section) Entry CActionList::ModifyLine(int position,const String section)
{ {
Section sect = model->GetSection(section); Section sect = Model(model)->GetSection(section);
Entry entry = sect->GetEntry(position)->Clone(); Entry entry = sect->GetEntry(position)->Clone();
Action action = Action (new ActionModify(entry,position,section,false)); Action action = Action (new ActionModify(entry,position,section,false));
AddAction(action); AddAction(action);
@ -138,7 +138,7 @@ Entry CActionList::ModifyLine(int position,const String section)
std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section) std::vector<Entry> CActionList::ModifyLines(Selection selection,const String section)
{ {
// Get section // Get section
Section sect = model->GetSection(section); Section sect = Model(model)->GetSection(section);
// Generate entries // Generate entries
std::vector<Entry> entries(selection->GetCount()); std::vector<Entry> entries(selection->GetCount());

View File

@ -56,12 +56,12 @@ namespace Athenasub {
private: private:
String actionName; String actionName;
String owner; String owner;
Model model; weak_ptr<IModel> model;
std::list<Action> actions; std::list<Action> actions;
bool valid; bool valid;
bool undoAble; bool undoAble;
CActionList(Model model,const String actionName,const String owner,bool undoAble); CActionList(weak_ptr<IModel>,const String actionName,const String owner,bool undoAble);
void Start(const String actionName); void Start(const String actionName);
void AddActionStart(const Action action); void AddActionStart(const Action action);

View File

@ -48,8 +48,8 @@ namespace Athenasub {
CTime() { ms = 0; } CTime() { ms = 0; }
CTime(int _ms) { ms = _ms; } CTime(int _ms) { ms = _ms; }
void SetMS(int milliseconds) { ms = milliseconds; } inline void SetMS(int milliseconds) { ms = milliseconds; }
int GetMS() const { return ms; } inline int GetMS() const { return ms; }
String GetString(int ms_precision,int h_precision) const; String GetString(int ms_precision,int h_precision) const;
void ParseString(const String &data); void ParseString(const String &data);

View File

@ -109,11 +109,15 @@ bool CController::CanRedo(const String owner) const
} }
void CController::Undo(const String owner) void CController::Undo(const String owner)
{ {
model->Undo(owner); if (CanUndo(owner)) {
model->Undo(owner);
}
} }
void CController::Redo(const String owner) void CController::Redo(const String owner)
{ {
model->Redo(owner); if (CanRedo(owner)) {
model->Redo(owner);
}
} }

View File

@ -142,91 +142,61 @@ bool DialogueASS::Parse(wxString rawData, int version)
// Serialize // Serialize
String DialogueASS::ToText(int version) const String DialogueASS::ToText(int version) const
{ {
// Old, slow code // Calculate size
if (false) { size_t size = 9+9+20+12+12; // 9 for "comment: " (+1 for dialogue below), 9 for commas,
// Prepare // 20 for times, 12 for margins, 12 just to be sure that layer fits
wxString final; if (!isComment) size++; // Comment->Dialogue
if (version == 0) size += 8; // "Marked=0"
else if (version == 2) size += 5; // Fourth margin
for (size_t i=0;i<4;i++) size += text[i].Length();
// Write comment or dialogue // Allocate string
if (isComment) final = _T("Comment: "); wxString final;
else final = _T("Dialogue: "); wxChar *buffer = final.GetWriteBuf(size);
wxChar temp[16];
// Write layer or marked // Write comment/dialogue
if (version >= 1) final += wxString::Format(_T("%01i,"),layer); size_t pos = 0;
else final += _T("Marked=0,"); if (isComment) WriteText(buffer,_T("Comment: "),9,pos);
else WriteText(buffer,_T("Dialogue: "),10,pos);
// Write times, style and actor // Write layer or marked
final += time[0].GetString(2,1) + _T(",") + time[1].GetString(2,1) + _T(",") + text[1] + _T(",") + text[2] + _T(","); if (version >= 1) {
WriteNumber(buffer,temp,layer,0,pos);
WriteChar(buffer,_T(','),pos);
}
else WriteText(buffer,_T("Marked=0,"),9,pos);
// Write margins // Write times
if (version <= 1) final += wxString::Format(_T("%04i,%04i,%04i,"),margin[0],margin[1],margin[2]); for (size_t i=0;i<2;i++) {
else final += wxString::Format(_T("%04i,%04i,%04i,%04i,"),margin[0],margin[1],margin[2],margin[3]); wxString tempStr = time[i].GetString(2,1);
WriteText(buffer,&tempStr[0],10,pos);
// Write effect and text WriteChar(buffer,_T(','),pos);
final += text[3] + _T(",") + text[0];
// Return final
return final;
} }
// New, faster code // Write style and actor
else { WriteText(buffer,&text[1][0],text[1].Length(),pos);
// Calculate size WriteChar(buffer,_T(','),pos);
size_t size = 9+9+20+12+12; // 9 for "comment: " (+1 for dialogue below), 9 for commas, WriteText(buffer,&text[2][0],text[2].Length(),pos);
// 20 for times, 12 for margins, 12 just to be sure that layer fits WriteChar(buffer,_T(','),pos);
if (!isComment) size++; // Comment->Dialogue
if (version == 0) size += 8; // "Marked=0"
else if (version == 2) size += 5; // Fourth margin
for (size_t i=0;i<4;i++) size += text[i].Length();
// Allocate string // Write margins
wxString final; size_t marCount = 3;
wxChar *buffer = final.GetWriteBuf(size); if (version == 2) marCount++;
wxChar temp[16]; for (size_t i=0;i<marCount;i++) {
WriteNumber(buffer,temp,margin[i],4,pos);
// Write comment/dialogue
size_t pos = 0;
if (isComment) WriteText(buffer,_T("Comment: "),9,pos);
else WriteText(buffer,_T("Dialogue: "),10,pos);
// Write layer or marked
if (version >= 1) {
WriteNumber(buffer,temp,layer,0,pos);
WriteChar(buffer,_T(','),pos);
}
else WriteText(buffer,_T("Marked=0,"),9,pos);
// Write times
for (size_t i=0;i<2;i++) {
wxString tempStr = time[i].GetString(2,1);
WriteText(buffer,&tempStr[0],10,pos);
WriteChar(buffer,_T(','),pos);
}
// Write style and actor
WriteText(buffer,&text[1][0],text[1].Length(),pos);
WriteChar(buffer,_T(','),pos); WriteChar(buffer,_T(','),pos);
WriteText(buffer,&text[2][0],text[2].Length(),pos);
WriteChar(buffer,_T(','),pos);
// Write margins
size_t marCount = 3;
if (version == 2) marCount++;
for (size_t i=0;i<marCount;i++) {
WriteNumber(buffer,temp,margin[i],4,pos);
WriteChar(buffer,_T(','),pos);
}
// Write effect and text
WriteText(buffer,&text[3][0],text[3].Length(),pos);
WriteChar(buffer,_T(','),pos);
WriteText(buffer,&text[0][0],text[0].Length(),pos);
// Write terminator
WriteText(buffer,_T("\0"),1,pos);
// Restore string's state
final.UngetWriteBuf(pos-1);
return final;
} }
// Write effect and text
WriteText(buffer,&text[3][0],text[3].Length(),pos);
WriteChar(buffer,_T(','),pos);
WriteText(buffer,&text[0][0],text[0].Length(),pos);
// Write terminator
WriteText(buffer,_T("\0"),1,pos);
// Restore string's state
final.UngetWriteBuf(pos-1);
return final;
} }

View File

@ -47,8 +47,8 @@ namespace Athenasub {
friend class DialogueASSDeltaCoder; friend class DialogueASSDeltaCoder;
private: private:
array<CTime,2> time;
array<String,4> text; // 0 = text, 1 = style, 2 = actor, 3 = effect array<String,4> text; // 0 = text, 1 = style, 2 = actor, 3 = effect
array<CTime,2> time;
array<short,4> margin; array<short,4> margin;
int layer; int layer;
bool isComment; bool isComment;
@ -84,8 +84,8 @@ namespace Athenasub {
const String& GetUserField() const { return text[3]; } const String& GetUserField() const { return text[3]; }
// Write acessors // Write acessors
void SetStartTime(Time setStart) { time[0].SetMS(setStart->GetMS()); } void SetStartTime(const ITime &setStart) { time[0].SetMS(setStart.GetMS()); }
void SetEndTime(Time setEnd) { time[1].SetMS(setEnd->GetMS()); } void SetEndTime(const ITime &setEnd) { time[1].SetMS(setEnd.GetMS()); }
void SetComment(bool _isComment) { isComment = _isComment; } void SetComment(bool _isComment) { isComment = _isComment; }
void SetLayer(int _layer) { layer = _layer; } void SetLayer(int _layer) { layer = _layer; }
void SetMargin(int _margin,int value) { margin.at(_margin) = value; } void SetMargin(int _margin,int value) { margin.at(_margin) = value; }

View File

@ -67,7 +67,7 @@ void CModel::ProcessActionList(CActionList &_actionList,int type)
shared_ptr<CActionList> actions = shared_ptr<CActionList>(new CActionList(_actionList)); shared_ptr<CActionList> actions = shared_ptr<CActionList>(new CActionList(_actionList));
// Setup undo // Setup undo
shared_ptr<CActionList> undo = shared_ptr<CActionList>(new CActionList(actions->model,actions->actionName,actions->owner,actions->undoAble)); shared_ptr<CActionList> undo = shared_ptr<CActionList>(new CActionList(Model(actions->model),actions->actionName,actions->owner,actions->undoAble));
ActionStack *stack; ActionStack *stack;
if (type == 1) stack = &redoStack; if (type == 1) stack = &redoStack;
else stack = &undoStack; else stack = &undoStack;

View File

@ -80,8 +80,8 @@ namespace Athenasub {
// Write accessors // Write accessors
virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); } virtual void SetText(const String& text) { (void) text; ThrowUnsupported(); }
virtual void SetStartTime(Time start) { (void) start; ThrowUnsupported(); } virtual void SetStartTime(const ITime& start) { (void) start; ThrowUnsupported(); }
virtual void SetEndTime(Time end) { (void) end; ThrowUnsupported(); } virtual void SetEndTime(const ITime& end) { (void) end; ThrowUnsupported(); }
virtual void SetStartFrame(int start) { (void) start; ThrowUnsupported(); } virtual void SetStartFrame(int start) { (void) start; ThrowUnsupported(); }
virtual void SetEndFrame(int end) { (void) end; ThrowUnsupported(); } virtual void SetEndFrame(int end) { (void) end; ThrowUnsupported(); }
virtual void SetComment(bool isComment) { (void) isComment; ThrowUnsupported(); } virtual void SetComment(bool isComment) { (void) isComment; ThrowUnsupported(); }

View File

@ -33,7 +33,7 @@
// Contact: mailto:amz@aegisub.net // Contact: mailto:amz@aegisub.net
// //
#define ATHENA_DLL //#define ATHENA_DLL
#include <wx/wfstream.h> #include <wx/wfstream.h>
#include <athenasub/athenawin.h> #include <athenasub/athenawin.h>
#include <iostream> #include <iostream>
@ -92,13 +92,13 @@ int main()
// Issue an action // Issue an action
#ifdef WXDEBUG #ifdef WXDEBUG
const int n = 1; int n = 1;
#else #else
const int n = 100; int n = 100;
#endif #endif
cout << "Executing action " << n << " times... "; cout << "Executing action " << n << " times... ";
timer.Start(); timer.Start();
for (size_t i=0;i<n;i++) { for (int i=0;i<n;i++) {
ActionList actions = control->CreateActionList(L"Test"); ActionList actions = control->CreateActionList(L"Test");
Selection selection = control->CreateSelection(); Selection selection = control->CreateSelection();
selection->AddRange(Range(0,5000)); selection->AddRange(Range(0,5000));
@ -108,8 +108,8 @@ int main()
size_t len = entries.size(); size_t len = entries.size();
for (size_t i=0;i<len;i++) { for (size_t i=0;i<len;i++) {
Dialogue diag = dynamic_pointer_cast<IDialogue> (entries[i]); Dialogue diag = dynamic_pointer_cast<IDialogue> (entries[i]);
diag->SetStartTime(diag->GetStartTime() - 55555); diag->SetStartTime(*(diag->GetStartTime() - 55555));
diag->SetEndTime(diag->GetEndTime() + 5555); diag->SetEndTime(*(diag->GetEndTime() + 5555));
} }
actions->Finish(); actions->Finish();
} }
@ -117,16 +117,19 @@ int main()
cout << "Done in " << timer.Time() << " ms.\n"; cout << "Done in " << timer.Time() << " ms.\n";
// Rollback // Rollback
cout << "Undoing " << n << " times... "; cout << "Undoing " << n-1 << " times... ";
for (size_t i=0;i<n-1;i++) { timer.Start();
for (int i=0;i<n-1;i++) {
control->Undo(); control->Undo();
} }
cout << "Done.\n"; timer.Pause();
cout << "Done in " << timer.Time() << " ms.\n";
// Undo // Undo
cout << "Undoing and redoing " << n*10 << " times... "; n = 100;
cout << "Undoing and redoing " << n << " times... ";
timer.Start(); timer.Start();
for (size_t i=0;i<n*10;i++) { for (int i=0;i<n;i++) {
control->Undo(); control->Undo();
control->Redo(); control->Redo();
} }
@ -149,5 +152,7 @@ int main()
cout << "\n\nException: " << e.what() << endl << endl; cout << "\n\nException: " << e.what() << endl << endl;
} }
system("pause");
return true; return true;
} }

View File

@ -118,6 +118,9 @@
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="../include" AdditionalIncludeDirectories="../include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2" RuntimeLibrary="2"