From: Laszlo T. <ave...@us...> - 2004-09-22 19:37:21
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15376/plugins/Core Modified Files: GameScript.cpp GameScript.h Log Message: fixed displaystring to not crash when playing sound Index: GameScript.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.cpp,v retrieving revision 1.196 retrieving revision 1.197 diff -C2 -d -r1.196 -r1.197 *** GameScript.cpp 13 Sep 2004 16:53:15 -0000 1.196 --- GameScript.cpp 22 Sep 2004 19:36:59 -0000 1.197 *************** *** 1713,1716 **** --- 1713,1740 ---- } + void GameScript::DisplayStringCore(Scriptable* Sender, int Strref, int flags) + { + printf( "Displaying string on: %s\n", Sender->GetScriptName() ); + if (flags & DS_CONST ) { + Actor* actor = ( Actor* ) Sender; + Strref=actor->StrRefs[Strref]; + } + StringBlock sb = core->strings->GetStringBlock( Strref ); + if (flags & DS_HEAD) { + Sender->DisplayHeadText( sb.text ); + } + if (flags & DS_CONSOLE) { + GameControl *gc=core->GetGameControl(); + if (gc) { + gc->DisplayString( sb.text ); + } + } + if (sb.Sound[0] ) { + ieDword len = core->GetSoundMgr()->Play( sb.Sound ); + ieDword counter = ( AI_UPDATE_TIME * len ) / 1000; + if ((counter != 0) && (flags &DS_WAIT) ) + Sender->SetWait( counter ); + } + } /* this function was lifted from GenerateAction, to make it clearer */ Action*GameScript::GenerateActionCore(const char *src, const char *str, int acIndex, bool autoFree) *************** *** 5422,5434 **** return; } ! Actor* actor = ( Actor* ) tar; ! printf( "Displaying string on: %s\n", actor->GetScriptName() ); ! char *str=core->GetString( actor->StrRefs[parameters->int0Parameter], 2 ); ! GameControl *gc=core->GetGameControl(); ! if (gc) { ! gc->DisplayString( str); ! } ! //this will free the string, no need of freeing it up! ! actor->DisplayHeadText( str); } --- 5446,5450 ---- return; } ! DisplayStringCore( tar, parameters->int0Parameter, DS_HEAD|DS_CONSOLE|DS_CONST); } *************** *** 5439,5450 **** return; } ! Actor* actor = ( Actor* ) tar; ! printf( "Displaying string on: %s\n", actor->GetScriptName() ); ! GameControl *gc=core->GetGameControl(); ! char *str = core->GetString( actor->StrRefs[parameters->int0Parameter], 2 ); ! if (gc) { ! gc->DisplayString(str); ! } ! free(str); } --- 5455,5459 ---- return; } ! DisplayStringCore( tar, parameters->int0Parameter, DS_CONSOLE|DS_CONST); } *************** *** 5709,5734 **** void GameScript::DisplayStringNoNameHead(Scriptable* Sender, Action* parameters) { ! if (Sender) { ! printf( "Displaying string on: %s (without name)\n", Sender->GetScriptName() ); ! //no need of freeing this string up!!! ! Sender->DisplayHeadText( core->GetString( parameters->int0Parameter, 2 ) ); ! } } void GameScript::DisplayStringHead(Scriptable* Sender, Action* parameters) { ! if (Sender) { ! printf( "Displaying string on: %s\n", Sender->GetScriptName() ); ! //no need of freeing this string up!!! ! Sender->DisplayHeadText( core->GetString( parameters->int0Parameter, 2 ) ); ! } } void GameScript::FloatMessageFixed(Scriptable* Sender, Action* parameters) { ! printf( "Displaying string on: %s\n", Sender->GetScriptName() ); ! //no need of freeing this string up!!! ! GameControl *gc = core->GetGameControl(); ! gc->DisplayString( parameters->pointParameter, core->GetString( parameters->int0Parameter, 2 ) ); } --- 5718,5732 ---- void GameScript::DisplayStringNoNameHead(Scriptable* Sender, Action* parameters) { ! DisplayStringCore( Sender, parameters->int0Parameter, DS_HEAD|DS_CONSOLE|DS_NONAME); } void GameScript::DisplayStringHead(Scriptable* Sender, Action* parameters) { ! DisplayStringCore(Sender, parameters->int0Parameter, DS_CONSOLE|DS_HEAD ); } void GameScript::FloatMessageFixed(Scriptable* Sender, Action* parameters) { ! DisplayStringCore(Sender, parameters->int0Parameter, DS_CONSOLE|DS_HEAD); } *************** *** 5792,5811 **** } void GameScript::DisplayStringWait(Scriptable* Sender, Action* parameters) { ! if (Sender->Type != ST_ACTOR) { ! Sender->CurrentAction = NULL; ! return; ! } ! Actor* actor = ( Actor* ) Sender; ! printf( "Displaying string on: %s\n", actor->GetScriptName() ); ! StringBlock sb = core->strings->GetStringBlock( parameters->int0Parameter ); ! actor->DisplayHeadText( sb.text ); ! if (sb.Sound[0]) { ! ieDword len = core->GetSoundMgr()->Play( sb.Sound ); ! ieDword counter = ( AI_UPDATE_TIME * len ) / 1000; ! if (counter != 0) ! actor->SetWait( counter ); ! } } --- 5790,5797 ---- } + void GameScript::DisplayStringWait(Scriptable* Sender, Action* parameters) { ! DisplayStringCore( Sender, parameters->int0Parameter, DS_HEAD|DS_WAIT); } *************** *** 6097,6107 **** void GameScript::DisplayString(Scriptable* Sender, Action* parameters) { ! //no need of freeing this string ! Sender->DisplayHeadText( core->GetString( parameters->int0Parameter) ); ! Sender->textDisplaying = 0; //why? ! GameControl* gc = core->GetGameControl(); ! if (gc) { ! gc->DisplayString( Sender ); ! } } --- 6083,6087 ---- void GameScript::DisplayString(Scriptable* Sender, Action* parameters) { ! DisplayStringCore( Sender, parameters->int0Parameter, DS_CONSOLE); } Index: GameScript.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.h,v retrieving revision 1.139 retrieving revision 1.140 diff -C2 -d -r1.139 -r1.140 *** GameScript.h 12 Sep 2004 21:58:48 -0000 1.139 --- GameScript.h 22 Sep 2004 19:36:59 -0000 1.140 *************** *** 32,35 **** --- 32,42 ---- #include <list> + //displaystring flags + #define DS_WAIT 1 + #define DS_HEAD 2 + #define DS_CONSOLE 4 + #define DS_CONST 8 + #define DS_NONAME 16 + #define BM_SET 0 //gemrb extension #define BM_AND 1 *************** *** 699,702 **** --- 706,710 ---- static int ParseInt(const char*& src); static void ParseString(const char*& src, char* tmp); + static void DisplayStringCore(Scriptable* Sender, int Strref, int flags); static int ValidForDialogCore(Scriptable* Sender, Actor* target); private: |