void SDLShell::CreatePointer() { if (pPointer.get() == NULL) { pPointer = auto_ptr<Pointer>(NewPointer()); } }
void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, TArray<FName> *argnames, PStruct *cls, DWORD funcflags, int useflags) { // Must be called before adding any other arguments. assert(args == nullptr || args->Size() == 0); assert(argflags == nullptr || argflags->Size() == 0); if (funcflags & VARF_Method) { // implied self pointer if (args != nullptr) args->Push(NewPointer(cls)); if (argflags != nullptr) argflags->Push(VARF_Implicit | VARF_ReadOnly); if (argnames != nullptr) argnames->Push(NAME_self); } if (funcflags & VARF_Action) { // implied caller and callingstate pointers if (args != nullptr) { // Special treatment for weapons and CustomInventory flagged functions: 'self' is not the defining class but the actual user of the item, so this pointer must be of type 'Actor' if (useflags & (SUF_WEAPON|SUF_ITEM)) { args->Insert(0, NewPointer(RUNTIME_CLASS(AActor))); // this must go in before the real pointer to the containing class. } else { args->Push(NewPointer(cls)); } args->Push(NewPointer(NewStruct("FStateParamInfo", nullptr))); } if (argflags != nullptr) { argflags->Push(VARF_Implicit | VARF_ReadOnly); argflags->Push(VARF_Implicit | VARF_ReadOnly); } if (argnames != nullptr) { argnames->Push(NAME_invoker); argnames->Push(NAME_stateinfo); } } }
// Method PTDB TDBVCT::CopyOne(PTABS t) { PTDB tp; PVCTCOL cp1, cp2; PGLOBAL g = t->G; // Is this really useful ??? tp = new(g) TDBVCT(g, this); for (cp1 = (PVCTCOL)Columns; cp1; cp1 = (PVCTCOL)cp1->Next) { cp2 = new(g) VCTCOL(cp1, tp); // Make a copy NewPointer(t, cp1, cp2); } // endfor cp1 return tp; } // end of CopyOne
// Is this really useful ??? PTDB TDBXIN::CopyOne(PTABS t) { PTDB tp; PXINCOL cp1, cp2; PGLOBAL g = t->G; tp = new(g) TDBXIN(this); for (cp1 = (PXINCOL)Columns; cp1; cp1 = (PXINCOL)cp1->GetNext()) { cp2 = new(g) XINCOL(cp1, tp); // Make a copy NewPointer(t, cp1, cp2); } // endfor cp1 return tp; } // end of CopyOne
static void ParseNativeFunction(FScanner &sc, PClassActor *cls) { TArray<PType *> rets(1); if (sc.LumpNum == -1 || Wads.GetLumpFile(sc.LumpNum) > 0) { sc.ScriptMessage ("functions can only be declared by native actors!"); FScriptPosition::ErrorCounter++; } // Read the type and make sure it's int or float. sc.MustGetAnyToken(); switch (sc.TokenType) { case TK_Int: case TK_Bool: rets.Push(TypeSInt32); break; case TK_Float: rets.Push(TypeFloat64); break; case TK_Angle_t: rets.Push(TypeAngle); break; case TK_Fixed_t: rets.Push(TypeFixed); break; case TK_State: rets.Push(TypeState); break; case TK_Identifier: rets.Push(NewPointer(RUNTIME_CLASS(DObject))); // Todo: Object type sc.ScriptError("Object type variables not implemented yet!"); break; default: sc.ScriptError("Invalid return type %s", sc.String); return; } sc.MustGetToken(TK_Identifier); ParseFunctionDef(sc, cls, sc.String, rets, VARF_Method); }
// Method PTDB TDBFMT::CopyOne(PTABS t) { PTDB tp; PCSVCOL cp1, cp2; //PFMTCOL cp1, cp2; PGLOBAL g = t->G; // Is this really useful ??? tp = new(g) TDBFMT(g, this); for (cp1 = (PCSVCOL)Columns; cp1; cp1 = (PCSVCOL)cp1->GetNext()) { //for (cp1 = (PFMTCOL)Columns; cp1; cp1 = (PFMTCOL)cp1->GetNext()) { cp2 = new(g) CSVCOL(cp1, tp); // Make a copy // cp2 = new(g) FMTCOL(cp1, tp); // Make a copy NewPointer(t, cp1, cp2); } // endfor cp1 return tp; } // end of CopyOne
PTDB TDB::Copy(PTABS t) { PTDB tp, tdb1, tdb2 = NULL, outp = NULL; //PGLOBAL g = t->G; // Is this really useful ??? for (tdb1 = this; tdb1; tdb1 = tdb1->Next) { tp = tdb1->CopyOne(t); if (!outp) outp = tp; else tdb2->Next = tp; tdb2 = tp; NewPointer(t, tdb1, tdb2); } // endfor tdb1 return outp; } // end of Copy
void InitThingdef() { PType *TypeActor = NewPointer(RUNTIME_CLASS(AActor)); PStruct *sstruct = NewNativeStruct("Sector", nullptr); auto sptr = NewPointer(sstruct); sstruct->AddNativeField("soundtarget", TypeActor, myoffsetof(sector_t, SoundTarget)); // expose the global validcount variable. PField *vcf = new PField("validcount", TypeSInt32, VARF_Native | VARF_Static, (intptr_t)&validcount); GlobalSymbols.AddSymbol(vcf); // expose the global Multiplayer variable. PField *multif = new PField("multiplayer", TypeBool, VARF_Native | VARF_ReadOnly | VARF_Static, (intptr_t)&multiplayer); GlobalSymbols.AddSymbol(multif); // set up a variable for the global level data structure PStruct *lstruct = NewNativeStruct("LevelLocals", nullptr); PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level); GlobalSymbols.AddSymbol(levelf); // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); PField *dehf = new PField("deh", dstruct, VARF_Native | VARF_Static, (intptr_t)&deh); GlobalSymbols.AddSymbol(dehf); // set up a variable for the global players array. PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr); pstruct->Size = sizeof(player_t); pstruct->Align = alignof(player_t); PArray *parray = NewArray(pstruct, MAXPLAYERS); PField *playerf = new PField("players", parray, VARF_Native | VARF_Static, (intptr_t)&players); GlobalSymbols.AddSymbol(playerf); // set up the lines array in the sector struct. This is a bit messy because the type system is not prepared to handle a pointer to an array of pointers to a native struct even remotely well... // As a result, the size has to be set to something large and arbritrary because it can change between maps. This will need some serious improvement when things get cleaned up. pstruct = NewNativeStruct("Sector", nullptr); pstruct->AddNativeField("lines", NewPointer(NewArray(NewPointer(NewNativeStruct("line", nullptr), false), 0x40000), false), myoffsetof(sector_t, lines), VARF_Native); parray = NewArray(TypeBool, MAXPLAYERS); playerf = new PField("playeringame", parray, VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&playeringame); GlobalSymbols.AddSymbol(playerf); playerf = new PField("gameaction", TypeUInt8, VARF_Native | VARF_Static, (intptr_t)&gameaction); GlobalSymbols.AddSymbol(playerf); playerf = new PField("consoleplayer", TypeSInt32, VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&consoleplayer); GlobalSymbols.AddSymbol(playerf); // Argh. It sucks when bad hacks need to be supported. WP_NOCHANGE is just a bogus pointer but it used everywhere as a special flag. // It cannot be defined as constant because constants can either be numbers or strings but nothing else, so the only 'solution' // is to create a static variable from it and reference that in the script. Yuck!!! static AWeapon *wpnochg = WP_NOCHANGE; playerf = new PField("WP_NOCHANGE", NewPointer(RUNTIME_CLASS(AWeapon), false), VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&wpnochg); GlobalSymbols.AddSymbol(playerf); // this needs to be done manually until it can be given a proper type. RUNTIME_CLASS(AActor)->AddNativeField("DecalGenerator", NewPointer(TypeVoid), myoffsetof(AActor, DecalGenerator)); // synthesize a symbol for each flag from the flag name tables to avoid redundant declaration of them. for (auto &fl : FlagLists) { if (fl.Use & 2) { for(int i=0;i<fl.NumDefs;i++) { if (fl.Defs[i].structoffset > 0) // skip the deprecated entries in this list { const_cast<PClass*>(*fl.Type)->AddNativeField(FStringf("b%s", fl.Defs[i].name), (fl.Defs[i].fieldsize == 4 ? TypeSInt32 : TypeSInt16), fl.Defs[i].structoffset, fl.Defs[i].varflags, fl.Defs[i].flagbit); } } } } FAutoSegIterator probe(CRegHead, CRegTail); while (*++probe != NULL) { if (((ClassReg *)*probe)->InitNatives) ((ClassReg *)*probe)->InitNatives(); } // Sort the flag lists for (size_t i = 0; i < NUM_FLAG_LISTS; ++i) { qsort (FlagLists[i].Defs, FlagLists[i].NumDefs, sizeof(FFlagDef), flagcmp); } // Create a sorted list of properties if (properties.Size() == 0) { FAutoSegIterator probe(GRegHead, GRegTail); while (*++probe != NULL) { properties.Push((FPropertyInfo *)*probe); } properties.ShrinkToFit(); qsort(&properties[0], properties.Size(), sizeof(properties[0]), propcmp); } // Create a sorted list of native action functions AFTable.Clear(); if (AFTable.Size() == 0) { FAutoSegIterator probe(ARegHead, ARegTail); while (*++probe != NULL) { AFuncDesc *afunc = (AFuncDesc *)*probe; assert(afunc->VMPointer != NULL); *(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->FuncName); (*(afunc->VMPointer))->PrintableName.Format("%s.%s [Native]", afunc->ClassName+1, afunc->FuncName); AFTable.Push(*afunc); } AFTable.ShrinkToFit(); qsort(&AFTable[0], AFTable.Size(), sizeof(AFTable[0]), funccmp); } FieldTable.Clear(); if (FieldTable.Size() == 0) { FAutoSegIterator probe(FRegHead, FRegTail); while (*++probe != NULL) { FieldDesc *afield = (FieldDesc *)*probe; FieldTable.Push(*afield); } FieldTable.ShrinkToFit(); qsort(&FieldTable[0], FieldTable.Size(), sizeof(FieldTable[0]), fieldcmp); } }