mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- avoid using plain char pointers to store script data for FraggleScript.
This commit is contained in:
parent
5865c4dcca
commit
3db56651f4
11 changed files with 37 additions and 44 deletions
|
@ -71,12 +71,12 @@ enum
|
|||
//Info given to bots when they're spawned.
|
||||
struct botinfo_t
|
||||
{
|
||||
botinfo_t *next;
|
||||
botinfo_t *next = nullptr;
|
||||
FString Name;
|
||||
FString Info;
|
||||
botskill_t skill;
|
||||
int inuse;
|
||||
int lastteam;
|
||||
botskill_t skill = {};
|
||||
int inuse = 0;
|
||||
int lastteam = 0;
|
||||
};
|
||||
|
||||
struct BotInfoData
|
||||
|
|
|
@ -500,8 +500,6 @@ bool FCajunMaster::LoadBots ()
|
|||
botinfo_t *newinfo = new botinfo_t;
|
||||
bool gotclass = false;
|
||||
|
||||
memset (newinfo, 0, sizeof(*newinfo));
|
||||
|
||||
newinfo->Info = "\\autoaim\\0\\movebob\\.25";
|
||||
|
||||
for (;;)
|
||||
|
|
|
@ -264,7 +264,8 @@ bool FScriptLoader::ParseInfo(MapData * map)
|
|||
}
|
||||
|
||||
auto th = Level->CreateThinker<DFraggleThinker>();
|
||||
th->LevelScript->data = copystring(scriptsrc.GetChars());
|
||||
th->LevelScript->Data.Resize((unsigned)scriptsrc.Len() + 1);
|
||||
memcpy(th->LevelScript->Data.Data(), scriptsrc.GetChars(), scriptsrc.Len() + 1);
|
||||
Level->FraggleScriptThinker = th;
|
||||
|
||||
if (drownflag==-1) drownflag = (Level->maptype != MAPTYPE_DOOM || fsglobal);
|
||||
|
|
|
@ -709,10 +709,10 @@ void FParser::ErrorMessage(FString msg)
|
|||
int linenum = 0;
|
||||
|
||||
// find the line number
|
||||
if(Rover >= Script->data && Rover <= Script->data+Script->len)
|
||||
if(Rover >= Script->Data.Data() && Rover <= Script->Data.Data() +Script->len)
|
||||
{
|
||||
char *temp;
|
||||
for(temp = Script->data; temp<LineStart; temp++)
|
||||
for(temp = Script->Data.Data(); temp<LineStart; temp++)
|
||||
if(*temp == '\n') linenum++; // count EOLs
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ void DFsSection::Serialize(FSerializer &arc)
|
|||
|
||||
char *DFsScript::SectionStart(const DFsSection *sec)
|
||||
{
|
||||
return data + sec->start_index;
|
||||
return Data.Data() + sec->start_index;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -99,7 +99,7 @@ char *DFsScript::SectionStart(const DFsSection *sec)
|
|||
|
||||
char *DFsScript::SectionEnd(const DFsSection *sec)
|
||||
{
|
||||
return data + sec->end_index;
|
||||
return Data.Data() + sec->end_index;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -110,7 +110,7 @@ char *DFsScript::SectionEnd(const DFsSection *sec)
|
|||
|
||||
char *DFsScript::SectionLoop(const DFsSection *sec)
|
||||
{
|
||||
return data + sec->loop_index;
|
||||
return Data.Data() + sec->loop_index;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -335,8 +335,8 @@ char *DFsScript::ProcessFindChar(char *datap, char find)
|
|||
|
||||
void DFsScript::DryRunScript(FLevelLocals *Level)
|
||||
{
|
||||
char *end = data + len;
|
||||
char *rover = data;
|
||||
char *end = Data.Data() + len;
|
||||
char *rover = Data.Data();
|
||||
|
||||
// allocate space for the tokens
|
||||
FParser parse(Level, this);
|
||||
|
@ -389,8 +389,8 @@ void DFsScript::DryRunScript(FLevelLocals *Level)
|
|||
|
||||
void DFsScript::Preprocess(FLevelLocals *Level)
|
||||
{
|
||||
len = (int)strlen(data);
|
||||
ProcessFindChar(data, 0); // fill in everything
|
||||
len = (int)Data.Size() - 1;
|
||||
ProcessFindChar(Data.Data(), 0); // fill in everything
|
||||
DryRunScript(Level);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,6 @@ DFsScript::DFsScript()
|
|||
for(i=0; i<VARIABLESLOTS; i++) variables[i] = nullptr;
|
||||
for(i=0; i<MAXSCRIPTS; i++) children[i] = nullptr;
|
||||
|
||||
data = nullptr;
|
||||
scriptnum = -1;
|
||||
len = 0;
|
||||
parent = nullptr;
|
||||
|
@ -135,19 +134,6 @@ DFsScript::DFsScript()
|
|||
lastiftrue = false;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// This is here to delete the locally allocated buffer in case this
|
||||
// gets forcibly destroyed
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
DFsScript::~DFsScript()
|
||||
{
|
||||
if (data != nullptr) delete[] data;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -160,8 +146,7 @@ void DFsScript::OnDestroy()
|
|||
ClearSections();
|
||||
ClearChildren();
|
||||
parent = nullptr;
|
||||
if (data != nullptr) delete [] data;
|
||||
data = nullptr;
|
||||
Data.Reset(); // lose the buffer now and don't wait until getting collected.
|
||||
parent = nullptr;
|
||||
trigger = nullptr;
|
||||
Super::OnDestroy();
|
||||
|
@ -177,7 +162,7 @@ void DFsScript::Serialize(FSerializer &arc)
|
|||
{
|
||||
Super::Serialize(arc);
|
||||
|
||||
arc("data", data)
|
||||
arc("data", Data)
|
||||
("scriptnum", scriptnum)
|
||||
("len", len)
|
||||
("parent", parent)
|
||||
|
@ -201,11 +186,11 @@ void DFsScript::ParseScript(char *position, DFraggleThinker *th)
|
|||
if (position == nullptr)
|
||||
{
|
||||
lastiftrue = false;
|
||||
position = data;
|
||||
position = Data.Data();
|
||||
}
|
||||
|
||||
// check for valid position
|
||||
if(position < data || position > data+len)
|
||||
if(position < Data.Data() || position > Data.Data() +len)
|
||||
{
|
||||
Printf("script %d: trying to continue from point outside script!\n", scriptnum);
|
||||
return;
|
||||
|
@ -216,7 +201,7 @@ void DFsScript::ParseScript(char *position, DFraggleThinker *th)
|
|||
try
|
||||
{
|
||||
FParser parse(th->Level, this);
|
||||
parse.Run(position, data, data + len);
|
||||
parse.Run(position, Data.Data(), Data.Data() + len);
|
||||
}
|
||||
catch (CFraggleScriptError &err)
|
||||
{
|
||||
|
@ -528,7 +513,7 @@ void DFraggleThinker::Tick()
|
|||
next = current->next; // save before freeing
|
||||
|
||||
// continue the script
|
||||
current->script->ParseScript (current->script->data + current->save_point, this);
|
||||
current->script->ParseScript (current->script->Data.Data() + current->save_point, this);
|
||||
|
||||
// free
|
||||
current->Destroy();
|
||||
|
|
|
@ -303,7 +303,7 @@ class DFsScript : public DObject
|
|||
public:
|
||||
// script data
|
||||
|
||||
char *data;
|
||||
TArray<char> Data;
|
||||
int scriptnum; // this script's number
|
||||
int len;
|
||||
|
||||
|
@ -335,7 +335,6 @@ public:
|
|||
// true or false
|
||||
|
||||
DFsScript();
|
||||
~DFsScript();
|
||||
void OnDestroy() override;
|
||||
void Serialize(FSerializer &ar);
|
||||
|
||||
|
@ -354,7 +353,7 @@ public:
|
|||
void ClearSections();
|
||||
void ClearChildren();
|
||||
|
||||
int MakeIndex(const char *p) { return int(p-data); }
|
||||
int MakeIndex(const char *p) { return int(p-Data.Data()); }
|
||||
|
||||
// preprocessor
|
||||
int section_hash(const char *b) { return MakeIndex(b) % SECTIONSLOTS; }
|
||||
|
|
|
@ -416,14 +416,14 @@ void FParser::spec_script()
|
|||
datasize = (Section->end_index - Section->start_index - 2);
|
||||
|
||||
// alloc extra 10 for safety
|
||||
newscript->data = (char *)malloc(datasize+10);
|
||||
newscript->Data.Resize(datasize+1);
|
||||
|
||||
// copy from parent newscript (levelscript)
|
||||
// ignore first char which is {
|
||||
memcpy(newscript->data, Script->SectionStart(Section) + 1, datasize);
|
||||
memcpy(newscript->Data.Data(), Script->SectionStart(Section) + 1, datasize);
|
||||
|
||||
// tack on a 0 to end the string
|
||||
newscript->data[datasize] = '\0';
|
||||
newscript->Data.Data()[datasize] = '\0';
|
||||
|
||||
newscript->scriptnum = scriptnum;
|
||||
newscript->parent = Script; // remember parent
|
||||
|
|
|
@ -428,7 +428,7 @@ void DFsScript::ClearVariables(bool complete)
|
|||
|
||||
char *DFsScript::LabelValue(const svalue_t &v)
|
||||
{
|
||||
if (v.type == svt_label) return data + v.value.i;
|
||||
if (v.type == svt_label) return Data.Data() + v.value.i;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -1281,6 +1281,15 @@ FSerializer &Serialize(FSerializer &arc, const char *key, uint32_t &value, uint3
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FSerializer& Serialize(FSerializer& arc, const char* key, char& value, char* defval)
|
||||
{
|
||||
int32_t vv = value;
|
||||
int32_t vvd = defval ? *defval : value - 1;
|
||||
Serialize(arc, key, vv, &vvd);
|
||||
value = (int8_t)vv;
|
||||
return arc;
|
||||
}
|
||||
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, int8_t &value, int8_t *defval)
|
||||
{
|
||||
int32_t vv = value;
|
||||
|
|
|
@ -186,6 +186,7 @@ public:
|
|||
int mErrors = 0;
|
||||
};
|
||||
|
||||
FSerializer& Serialize(FSerializer& arc, const char* key, char& value, char* defval);
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, bool &value, bool *defval);
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, int64_t &value, int64_t *defval);
|
||||
FSerializer &Serialize(FSerializer &arc, const char *key, uint64_t &value, uint64_t *defval);
|
||||
|
|
Loading…
Reference in a new issue