AGS: Store DialogTopics in std::vector

From upstream 2609c0d1ee43a4f997021ce48ca2a4f70ca1a6c7
This commit is contained in:
Thierry Crozat 2022-06-20 23:31:36 +01:00
parent e960e831b0
commit fe80834639
10 changed files with 19 additions and 19 deletions

View File

@ -23,6 +23,7 @@
#define AGS_ENGINE_AC_DIALOG_H
#include "ags/lib/std/vector.h"
#include "ags/shared/ac/dialog_topic.h"
#include "ags/engine/ac/dynobj/script_dialog.h"
namespace AGS3 {

View File

@ -26,7 +26,7 @@
#include "ags/engine/ac/audio_channel.h"
#include "ags/engine/ac/button.h"
#include "ags/engine/ac/character.h"
#include "ags/shared/ac/dialog_topic.h"
#include "ags/engine/ac/dialog.h"
#include "ags/engine/ac/draw.h"
#include "ags/engine/ac/dynamic_sprite.h"
#include "ags/engine/ac/event.h"
@ -418,13 +418,11 @@ void unload_game_file() {
_G(curLipLine) = -1;
}
for (int i = 0; i < _GP(game).numdialog; ++i) {
if (_G(dialog)[i].optionscripts != nullptr)
free(_G(dialog)[i].optionscripts);
_G(dialog)[i].optionscripts = nullptr;
for (auto &dlg : _G(dialog)) {
if (dlg.optionscripts != nullptr)
free(dlg.optionscripts);
}
free(_G(dialog));
_G(dialog) = nullptr;
_G(dialog).clear();
delete[] _G(scrDialog);
_G(scrDialog) = nullptr;

View File

@ -363,6 +363,9 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
_GP(views) = std::move(ents.Views);
_GP(play).charProps.resize(game.numcharacters);
_G(dialog) = std::move(ents.Dialogs);
_G(old_dialog_scripts) = std::move(ents.OldDialogScripts);
_G(old_speech_lines) = std::move(ents.OldSpeechLines);
_G(old_dialog_scripts) = ents.OldDialogScripts;
_G(old_speech_lines) = ents.OldSpeechLines;

View File

@ -23,7 +23,7 @@
#include "ags/engine/game/savegame_components.h"
#include "ags/shared/ac/audio_clip_type.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/dialog_topic.h"
#include "ags/engine/ac/dialog.h"
#include "ags/engine/ac/button.h"
#include "ags/engine/ac/character.h"
#include "ags/engine/ac/draw.h"

View File

@ -32,7 +32,7 @@
#include "ags/shared/core/types.h"
#include "ags/engine/ac/character_extras.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/dialog_topic.h"
#include "ags/engine/ac/dialog.h"
#include "ags/engine/ac/button.h"
#include "ags/engine/ac/dynamic_sprite.h"
#include "ags/engine/ac/game.h"

View File

@ -169,7 +169,7 @@ HError LoadGameScripts(LoadedGameEntities &ents) {
HError load_game_file() {
MainGameSource src;
LoadedGameEntities ents(_GP(game), _G(dialog));
LoadedGameEntities ents(_GP(game));
HError err = (HError)OpenMainGameFileFromDefaultAsset(src, _GP(AssetMgr).get());
if (err) {
err = (HError)ReadGameData(ents, src.InputStream.get(), src.DataVersion);

View File

@ -22,6 +22,7 @@
#include "ags/globals.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/shared/ac/sprite_cache.h"
#include "ags/shared/ac/dialog_topic.h"
#include "ags/shared/core/asset_manager.h"
#include "ags/shared/debugging/debug_manager.h"
#include "ags/shared/font/fonts.h"

View File

@ -523,7 +523,7 @@ public:
* @{
*/
DialogTopic *_dialog = nullptr;
std::vector<DialogTopic> _dialog;
ScriptDialogOptionsRendering *_ccDialogOptionsRendering;
ScriptDrawingSurface *_dialogOptionsRenderingSurface = nullptr;

View File

@ -96,9 +96,8 @@ String GetMainGameFileErrorText(MainGameFileErrorType err) {
return "Unknown error.";
}
LoadedGameEntities::LoadedGameEntities(GameSetupStruct &game, DialogTopic *&dialogs)
LoadedGameEntities::LoadedGameEntities(GameSetupStruct &game)
: Game(game)
, Dialogs(dialogs)
, SpriteCount(0) {
}
@ -266,14 +265,12 @@ void ReadViews(GameSetupStruct &game, std::vector<ViewStruct> &views, Stream *in
}
}
void ReadDialogs(DialogTopic *&dialog,
void ReadDialogs(std::vector<DialogTopic> &dialog,
std::vector< std::shared_ptr<unsigned char> > &old_dialog_scripts,
std::vector<String> &old_dialog_src,
std::vector<String> &old_speech_lines,
Stream *in, GameDataVersion data_ver, int dlg_count) {
// TODO: I suspect +5 was a hacky way to "supress" memory access mistakes;
// double check and remove if proved unnecessary
dialog = (DialogTopic *)malloc(sizeof(DialogTopic) * dlg_count + 5);
dialog.resize(dlg_count);
for (int i = 0; i < dlg_count; ++i) {
dialog[i].ReadFromFile(in);
}

View File

@ -111,7 +111,7 @@ struct MainGameSource {
// code refactoring.
struct LoadedGameEntities {
GameSetupStruct &Game;
DialogTopic *&Dialogs;
std::vector<DialogTopic> Dialogs;
std::vector<ViewStruct> Views;
PScript GlobalScript;
PScript DialogScript;
@ -131,7 +131,7 @@ struct LoadedGameEntities {
// speech texts displayed during dialog
std::vector<String> OldSpeechLines;
LoadedGameEntities(GameSetupStruct &game, DialogTopic *&dialogs);
LoadedGameEntities(GameSetupStruct &game);
~LoadedGameEntities();
};