本文整理汇总了C++中PClass类的典型用法代码示例。如果您正苦于以下问题:C++ PClass类的具体用法?C++ PClass怎么用?C++ PClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: P_SetupWeapons_ntohton
void P_SetupWeapons_ntohton()
{
unsigned int i;
const PClass *cls;
Weapons_ntoh.Clear();
Weapons_hton.Clear();
cls = NULL;
Weapons_ntoh.Push(cls); // Index 0 is always NULL.
for (i = 0; i < PClass::m_Types.Size(); ++i)
{
PClass *cls = PClass::m_Types[i];
if (cls->ActorInfo != NULL && cls->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
{
Weapons_ntoh.Push(cls);
}
}
qsort(&Weapons_ntoh[1], Weapons_ntoh.Size() - 1, sizeof(Weapons_ntoh[0]), ntoh_cmp);
for (i = 0; i < Weapons_ntoh.Size(); ++i)
{
Weapons_hton[Weapons_ntoh[i]] = i;
}
}
示例2: emit
void UCContext::emit_native_function_call(Function *pfn, CALLFN fn)
{
Type rt = pfn->return_type();
// *change 1.2.0 Moved from compile_function_call()
// for cdecl-style method imports,
if (pfn->is_cdecl() && pfn->is_method()) {
// push mOP onto exec stack
emit(PUSH_THIS,0);
// do note that returned objects are by a another hidden arg
// *fix 1.1.4 The return type must specifically be an _object_, not a pointer to an object!
if (rt.is_object()) emit(SWAP,0);
}
emit(CALLN,DIRECT,NFBlock::create(pfn,fn));
pfn->fun_block()->data = (void *)fn; // convenient place to keep this!
// We need to check imported class object ptrs to see if they have a VMT....
// Any imported class ptrs need their UC VMT patched with CHKVMT
// *fix 1.1.0 Imported references as well as pointers!
if (rt.is_class() && rt.is_ref_or_ptr()) {
PClass pc = pc = rt.as_class();
if (pc->imported() && pc->has_VMT())
out(CodeGenerator::instruction_with_pointer(CHKVMT,pc));
}
// *add 1.2.9 Sometimes necessary to clear out upper 3bytes of 32-bit boolean values
else
if (rt == t_bool) {
emit(I2B);
}
}
示例3: SetKeyTypes
static void SetKeyTypes()
{
for(unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); i++)
{
PClass *ti = PClassActor::AllActorClasses[i];
if (ti->IsDescendantOf(RUNTIME_CLASS(AKey)))
{
PClassActor *tia = static_cast<PClassActor *>(ti);
AKey *key = (AKey*)GetDefaultByType(tia);
if (key->Icon.isValid() && key->KeyNumber>0)
{
KeyTypes.Push(tia);
}
else
{
UnassignedKeyTypes.Push(tia);
}
}
}
if (KeyTypes.Size())
{
qsort(&KeyTypes[0], KeyTypes.Size(), sizeof(KeyTypes[0]), ktcmp);
}
else
{
// Don't leave the list empty
PClassActor *ti = RUNTIME_CLASS(AKey);
KeyTypes.Push(ti);
}
}
示例4: SetKeyTypes
static void SetKeyTypes()
{
for(unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); i++)
{
PClass *ti = PClassActor::AllActorClasses[i];
auto kt = PClass::FindActor(NAME_Key);
if (ti->IsDescendantOf(kt))
{
PClassActor *tia = static_cast<PClassActor *>(ti);
AInventory *key = (AInventory*)(GetDefaultByType(tia));
if (key->Icon.isValid() && key->special1 > 0)
{
KeyTypes.Push(tia);
}
else
{
UnassignedKeyTypes.Push(tia);
}
}
}
if (KeyTypes.Size())
{
qsort(&KeyTypes[0], KeyTypes.Size(), sizeof(KeyTypes[0]), ktcmp);
}
else
{
// Don't leave the list empty
KeyTypes.Push(PClass::FindActor(NAME_Key));
}
}
示例5:
// miscelaneous output routines
ostream& operator << (ostream& os, Signature& sig)
{
Signature::iterator si;
StringList::iterator sli;
StringList *args = sig.get_arg_names();
if (args && args->size()==0) args = NULL;
if (!s_ctor && !s_dtor) // *fix 1.1.2 these don't have return types!
os << sig.return_type() << ' ';
string na = s_fun_name;
char first = na[0];
// *fix 1.2.7 wasn't outputing 'operator' in front of '()'
if (!isalpha(first) && first != '_' /*&& first != '('*/) na = "operator" + na;
PClass pc = sig.class_ptr();
if (pc != NULL) {
string classn = pc->name();
if (! s_full_names && pc->is_template()) classn = pc->get_template()->name();
if (s_ctor) na = classn; else
if (s_dtor) na = "~" + classn;
if (s_full_names) na = classn + "::" + na;
}
os << na << '(';
if (args != NULL) sli = args->begin();
for(si = sig.begin(); si != sig.end(); ) {
os << *si++;
if (args != NULL) os << ' ' << *sli++;
if (si != sig.end()) os << ',';
}
os << ')';
if (sig.is_const()) os << " const";
return os;
}
示例6: dissemble
void dissemble(PFBlock fb)
{
Opcodes opcode;
int rmode,rdata, k = 0;
string name;
Instruction *pi = fb->pstart;
while (pi != end_of_code) {
opcode = (Opcodes)pi->opcode;
// *add 1.2.4 HALT+data is not always a breakpoint!
// (it is used as a NOP + <any useful tag data>)
if (opcode == HALT) {
if (pi->data < MAX_BREAKPOINTS) {
Breakpoint *pb = Breakpoint::from_id(pi->data);
Instruction ai = pb->saved_instruction();
std::cout << "*";
opcode = (Opcodes)ai.opcode;
rmode = ai.rmode; rdata = ai.data;
} else { opcode = NOP; rdata = pi->data; }
} else {
rmode = pi->rmode; rdata = pi->data;
}
name = get_opcode_name(opcode);
std::cout << k++ << ' ' << name << '\t';
if (opcode == CCALL || opcode == CALL || opcode == CALLD || opcode == CALLN) {
FBlock* pfb;
void *data = data_ptr(rdata);
if (opcode == CALLN)
pfb = Builtin::imported_fblock_from_function((void*)((NFBlock *)data)->pfn);
else pfb = PFBlock(data_ptr(rdata));
if (pfb) Function::from_fun_block(pfb)->dump(std::cout);
} else
if (opcode == JSWITCH) {
int *swb = (int *)data_ptr(rdata);
int sz = *swb++;
int def = *swb++;
std::cout << '(' << sz << ',' << def << ") ";
for (int i = 0; i < sz; i++) std::cout << *swb++ << ' ' << *swb++ << ' ';
}
else
if (opcode == TOSD || opcode == TPODS) {
PClass pc = *(PClass *)data_ptr(rdata);
std::cout << pc->name();
}
else {
if (rmode)
switch(rmode) {
case DIRECT: std::cout << "D "; break;
case SREL: std::cout << "R "; break;
case OREL: std::cout << "S "; break;
}
if (rdata != 0) std::cout << rdata;
}
std::cout << std::endl;
if (opcode == RET || opcode == RETI || opcode == RETD) break;
pi++;
}
}
示例7: GetClass
DObject::~DObject ()
{
if (!PClass::bShutdown)
{
PClass *type = GetClass();
if (!(ObjectFlags & OF_Cleanup) && !PClass::bShutdown)
{
DObject **probe;
if (!(ObjectFlags & OF_YesReallyDelete))
{
Printf("Warning: '%s' is freed outside the GC process.\n",
type != NULL ? type->TypeName.GetChars() : "==some object==");
}
// Find all pointers that reference this object and NULL them.
StaticPointerSubstitution(this, NULL);
// Now unlink this object from the GC list.
for (probe = &GC::Root; *probe != NULL; probe = &((*probe)->ObjNext))
{
if (*probe == this)
{
*probe = ObjNext;
if (&ObjNext == GC::SweepPos)
{
GC::SweepPos = probe;
}
break;
}
}
// If it's gray, also unlink it from the gray list.
if (this->IsGray())
{
for (probe = &GC::Gray; *probe != NULL; probe = &((*probe)->GCNext))
{
if (*probe == this)
{
*probe = GCNext;
break;
}
}
}
}
if (nullptr != type)
{
type->DestroySpecials(this);
}
}
}
示例8: assert
PClass *PClass::CreateDerivedClass(FName name, unsigned int size)
{
assert(size >= Size);
PClass *type;
bool notnew;
const PClass *existclass = FindClass(name);
if (existclass != nullptr)
{
// This is a placeholder so fill it in
if (existclass->Size == TentativeClass)
{
type = const_cast<PClass*>(existclass);
if (!IsDescendantOf(type->ParentClass))
{
I_Error("%s must inherit from %s but doesn't.", name.GetChars(), type->ParentClass->TypeName.GetChars());
}
DPrintf(DMSG_SPAMMY, "Defining placeholder class %s\n", name.GetChars());
notnew = true;
}
else
{
// a different class with the same name already exists. Let the calling code deal with this.
return nullptr;
}
}
else
{
type = new PClass;
notnew = false;
}
type->TypeName = name;
type->bRuntimeClass = true;
Derive(type, name);
type->Size = size;
if (size != TentativeClass)
{
NewClassType(type);
type->InitializeDefaults();
type->Virtuals = Virtuals;
}
else
type->bOptional = false;
if (!notnew)
{
type->InsertIntoHash(false);
}
return type;
}
示例9:
PClass *ClassReg::RegisterClass()
{
// Skip classes that have already been registered
if (MyClass != nullptr)
{
return MyClass;
}
// Add type to list
PClass *cls = new PClass;
SetupClass(cls);
cls->InsertIntoHash(true);
if (ParentType != nullptr)
{
cls->ParentClass = ParentType->RegisterClass();
}
return cls;
}
示例10: FindClass
PClass *PClass::FindClassTentative(FName name)
{
if (name == NAME_None)
{
return nullptr;
}
PClass *found = FindClass(name);
if (found != nullptr) return found;
PClass *type = new PClass;
DPrintf(DMSG_SPAMMY, "Creating placeholder class %s : %s\n", name.GetChars(), TypeName.GetChars());
Derive(type, name);
type->Size = TentativeClass;
type->InsertIntoHash(false);
return type;
}
示例11: assert
// Create a new class based on an existing class
PClass *PClass::CreateDerivedClass (FName name, unsigned int size)
{
assert (size >= Size);
PClass *type = new PClass;
type->TypeName = name;
type->ParentClass = this;
type->Size = size;
type->Pointers = NULL;
type->ConstructNative = ConstructNative;
type->ClassIndex = m_Types.Push (type);
type->Meta = Meta;
type->Defaults = new BYTE[size];
memcpy (type->Defaults, Defaults, Size);
if (size > Size)
{
memset (type->Defaults + Size, 0, size - Size);
}
type->FlatPointers = NULL;
type->bRuntimeClass = true;
type->ActorInfo = NULL;
type->InsertIntoHash();
// If this class has an actor info, then any classes derived from it
// also need an actor info.
if (this->ActorInfo != NULL)
{
FActorInfo *info = type->ActorInfo = new FActorInfo;
info->Class = type;
info->GameFilter = GAME_Any;
info->SpawnID = 0;
info->DoomEdNum = -1;
info->OwnedStates = NULL;
info->NumOwnedStates = 0;
info->Replacement = NULL;
info->Replacee = NULL;
m_RuntimeActors.Push (type);
}
return type;
}
示例12: while
// Like FindClass but creates a placeholder if no class
// is found. CreateDerivedClass will automatcally fill in
// the placeholder when the actual class is defined.
const PClass *PClass::FindClassTentative (FName name)
{
if (name == NAME_None)
{
return NULL;
}
PClass *cls = TypeHash[name % HASH_SIZE];
while (cls != 0)
{
int lexx = int(name) - int(cls->TypeName);
if (lexx > 0)
{
cls = cls->HashNext;
}
else if (lexx == 0)
{
return cls;
}
else
{
break;
}
}
PClass *type = new PClass;
DPrintf("Creating placeholder class %s : %s\n", name.GetChars(), TypeName.GetChars());
type->TypeName = name;
type->ParentClass = this;
type->Size = -1;
type->Pointers = NULL;
type->ConstructNative = NULL;
type->ClassIndex = m_Types.Push (type);
type->Defaults = NULL;
type->FlatPointers = NULL;
type->bRuntimeClass = true;
type->ActorInfo = NULL;
type->InsertIntoHash();
return type;
}
示例13: AddExtraWeapons
void FWeaponSlots::AddExtraWeapons()
{
unsigned int i;
// Set fractional positions for current weapons.
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
{
Slots[i].SetInitialPositions();
}
// Append extra weapons to the slots.
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
{
PClass *cls = PClassActor::AllActorClasses[i];
if (!cls->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
{
continue;
}
PClassWeapon *acls = static_cast<PClassWeapon *>(cls);
if ((acls->GameFilter == GAME_Any || (acls->GameFilter & gameinfo.gametype)) &&
acls->Replacement == NULL && // Replaced weapons don't get slotted.
!(((AWeapon *)(acls->Defaults))->WeaponFlags & WIF_POWERED_UP) &&
!LocateWeapon(acls, NULL, NULL) // Don't duplicate it if it's already present.
)
{
int slot = acls->SlotNumber;
if ((unsigned)slot < NUM_WEAPON_SLOTS)
{
FWeaponSlot::WeaponInfo info = { acls, acls->SlotPriority };
Slots[slot].Weapons.Push(info);
}
}
}
// Now resort every slot to put the new weapons in their proper places.
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
{
Slots[i].Sort();
}
}
示例14: FinishThingdef
static void FinishThingdef()
{
int errorcount = StateParams.ResolveAll();
for (unsigned i = 0;i < PClass::m_Types.Size(); i++)
{
PClass * ti = PClass::m_Types[i];
// Skip non-actors
if (!ti->IsDescendantOf(RUNTIME_CLASS(AActor))) continue;
if (ti->Size == (unsigned)-1)
{
Printf("Class %s referenced but not defined\n", ti->TypeName.GetChars());
errorcount++;
continue;
}
AActor *def = GetDefaultByType(ti);
if (!def)
{
Printf("No ActorInfo defined for class '%s'\n", ti->TypeName.GetChars());
errorcount++;
continue;
}
}
if (errorcount > 0)
{
I_Error("%d errors during actor postprocessing", errorcount);
}
// Since these are defined in DECORATE now the table has to be initialized here.
for(int i=0;i<31;i++)
{
char fmt[20];
mysnprintf(fmt, countof(fmt), "QuestItem%d", i+1);
QuestItemClasses[i] = PClass::FindClass(fmt);
}
}
示例15: AddExtraWeapons
void FWeaponSlots::AddExtraWeapons()
{
unsigned int i;
// Set fractional positions for current weapons.
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
{
Slots[i].SetInitialPositions();
}
// Append extra weapons to the slots.
for (unsigned int i = 0; i < PClass::m_Types.Size(); ++i)
{
PClass *cls = PClass::m_Types[i];
if (cls->ActorInfo != NULL &&
(cls->ActorInfo->GameFilter == GAME_Any || (cls->ActorInfo->GameFilter & gameinfo.gametype)) &&
cls->ActorInfo->Replacement == NULL && // Replaced weapons don't get slotted.
cls->IsDescendantOf(RUNTIME_CLASS(AWeapon)) &&
!(static_cast<AWeapon*>(GetDefaultByType(cls))->WeaponFlags & WIF_POWERED_UP) &&
!LocateWeapon(cls, NULL, NULL) // Don't duplicate it if it's already present.
)
{
int slot = cls->Meta.GetMetaInt(AWMETA_SlotNumber, -1);
if ((unsigned)slot < NUM_WEAPON_SLOTS)
{
fixed_t position = cls->Meta.GetMetaFixed(AWMETA_SlotPriority, INT_MAX);
FWeaponSlot::WeaponInfo info = { cls, position };
Slots[slot].Weapons.Push(info);
}
}
}
// Now resort every slot to put the new weapons in their proper places.
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
{
Slots[i].Sort();
}
}