Exemplo n.º 1
0
Ptr<CTestDoubleNamedString> SetupObjectsForDehollowfication(void)
{
	Ptr<CTestNamedString>			cNS1;
	Ptr<CTestNamedString>			cNS2;
	Ptr<CTestNamedString>			cNS3;
	Ptr<CTestNamedString>			cDiamond;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;
	Ptr<CString>					cS1;
	Ptr<CString>					cS2;

	pRoot = ORoot();

	cDiamond = ONMalloc(CTestNamedString, "Diamond")->Init();

	cS1 = OMalloc(CString)->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, cDiamond, "NS1");

	cNS2 = ONMalloc(CTestNamedString, "NS2")->Init(ONull, cDiamond, "NS2");

	cNS3 = ONMalloc(CTestNamedString, "NS3")->Init(ONull, cNS1, "NS3");

	cS2 = OMalloc(CString)->Init("CS2");
	cDiamond->Init(cS2, ONull, "Diamond");

	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init(ONull, cNS2, cNS3);

	pRoot->Add(pDouble);
	return pDouble;
}
void TestObjectGraphDeserialiserBuildGraph1(void)
{
	Ptr<CTestSaveableObject2>	cStart1;
	Ptr<CTestSaveableObject2>	cStart2;
	Ptr<CRoot>					cRoot;
	Ptr<CTestSaveableObject1>	cShared;
	Ptr<CString>				cString1;
	Ptr<CString>				cString2;
	Ptr<CTestInteger>			cIgnored;

	cRoot = ORoot();
	cStart1 = ONMalloc(CTestSaveableObject2, "Ow/Start 1")->Init("Battery");
	cStart2 = ONMalloc(CTestSaveableObject2, "Ow/Start 2")->Init("Charger");
	cShared = ONMalloc(CTestSaveableObject1, "Ow/Shared")->Init();
	cString1 = OMalloc(CString)->Init("Black");
	cString2 = OMalloc(CString)->Init("Jack");
	cIgnored = OMalloc(CTestInteger)->Init(0, 1, 0);
	
	cRoot->Add(cStart1);
	cRoot->Add(cStart2);

	cStart1->mp1 = cShared;
	cStart2->mp1 = cShared;

	cShared->miInt = 89;
	cShared->mpObject = cShared;

	cStart1->mp2 = cString1;
	cStart2->mp2 = cString2;

	cRoot->Add(cIgnored);
}
CPointer SetupObjectReaderSimpleFile(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CTestNamedString>	cNS2;

	cNS2 = ONMalloc(CTestNamedString, "Dog")->Init(ONull, ONull, "NS2");
	cNS1 = ONMalloc(CTestNamedString, "Waggy")->Init(ONull, cNS2, "NS1");


	return cNS1;
}
void TestEmbeddedObjectAddDistToRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot = ORoot();
	Ptr<CGameWorld>			pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile>	pMissile = ONMalloc(CClusterMissile, "Frank")->Init(pWorld);
	Ptr<CHarrier>			pHarrier = OMalloc(CHarrier)->Init(pWorld);
	
	pWorld->AddPlayer(pHarrier);
	AssertInt(3, pHarrier->GetDistToRoot());

	pRoot->Add(pMissile);

	AssertInt(2, pMissile->GetDistToRoot());
	AssertInt(2, pMissile->mcMissile1.GetDistToRoot());
	AssertInt(2, pMissile->mcMissile2.GetDistToRoot());

	pMissile->mcMissile1.SetTarget(pHarrier);

	AssertInt(3, pHarrier->GetDistToRoot());

	ObjectsKill();
}
Exemplo n.º 5
0
void TestObjectsFlushRemovesStackPointers(void)
{
	CFileUtil						cFileUtil;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/ClearPointers");

	ObjectsInit("Output/ClearPointers");
	SetupObjectsConstructors();

	pRoot = ORoot();

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(2, gcObjects.NumDatabaseObjects());

	AssertNull(&pRoot);

	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	AssertString("CTestDoubleNamedString", pDouble.ClassName());

	pRoot = ORoot();
	AssertString("CRoot", pRoot.ClassName());

	ObjectsKill();
}
Exemplo n.º 6
0
void TestObjectsFlushClearGetByName(void)
{
	CFileUtil						cFileUtil;
	CPointer						pObject;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();

	pRoot = ORoot();
	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	pRoot->Add(pDouble);
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pObject = gcObjects.Get(3);
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(3, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumDatabaseNames());

	pObject = gcObjects.Get("Double");
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	ObjectsKill();
}
Ptr<CImage> CImageCelsSource::Combine(int iFirstCelIndex)
{
	CImageCombiner	cImageCombiner;
	Ptr<CImage>		pcDest;
	int				i;
	CImageCel*		pcCel;

	pcDest = ONMalloc(CImage, "");
	cImageCombiner.Init(ICL_Best, ICS_Arbitrary);

	for (i = iFirstCelIndex; i < macImageCels.NumElements(); i++)
	{
		pcCel = (CImageCel*)macImageCels.Get(i);
		cImageCombiner.AddCel(pcCel);
	}
	pcDest = cImageCombiner.Combine();
	if (pcDest.IsNotNull())
	{
		macImageCels.RemoveEnd(iFirstCelIndex);
		macImageCels.AddAll(&cImageCombiner.mcDestCels);
		cImageCombiner.Kill();
		return pcDest;
	}
	else
	{
		return ONull;
	}
}
BOOL CImageCelsSource::Load(void)
{
	SSetIterator				sIter;
	CImageSourceWithCelSources*	pcImageSourceWithCelSources;
	BOOL						bResult;
	Ptr<CImage>					pcMask;
	CImageSource*				pcImageSource;
	CImageCelSource*			pcCelsSource;
	int							iFirstCelIndex;
	Ptr<CImage>					pcCombined;

	pcImageSourceWithCelSources = (CImageSourceWithCelSources*)macImageSources.StartIteration(&sIter);
	while (pcImageSourceWithCelSources)
	{
		pcMask = NULL;
		pcImageSource = pcImageSourceWithCelSources->GetImageSource();
		pcCelsSource = pcImageSourceWithCelSources->GetCelsSource();

		bResult = pcImageSource->LoadImage();
		if (!bResult)
		{
			return FALSE;
		}

		mcModifiers.SetImage((CImage*)pcImageSource->GetImage().Object());  //Not sure if this is a hack or not.
		mcModifiers.ApplyAll();

		if (pcCelsSource->NeedsMask())
		{
			pcMask = ONMalloc(CImage, NULL);
			macFillMasks.Add(pcMask);
		}
		iFirstCelIndex = macImageCels.NumElements();
		pcCelsSource->Divide((CImage*)pcImageSource->GetImage().Object(), &macImageCels, (CImage*)pcMask.Object());

		if (mbPackOnLoad)
		{
			pcCombined = Combine(iFirstCelIndex);
			pcImageSource->GetImage()->Kill();
			pcImageSource->SetImage(pcCombined);
			if (pcMask.IsNotNull())
			{
				macFillMasks.Remove(pcMask);
			}
		}

		pcImageSourceWithCelSources = (CImageSourceWithCelSources*)macImageSources.Iterate(&sIter);
	}

	mcModifiers.SetImage(NULL);

	PopulateImageArray();

	return TRUE;
}
Exemplo n.º 9
0
void TestObjectsObjectKillInGraph(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CTestNamedString>	cNS2;
	Ptr<CRoot>				pRoot;
	Ptr<CString>			cS1;
	Ptr<CString>			cS2;
	CTestNamedString*		pcNS2;
	CString*				pcS2;

	ObjectsInit();

	pRoot = ORoot();

	cS1 = OMalloc(CString);
	cS1->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1");

	cS2 = OMalloc(CString)->Init("CS2");
	cNS2 = ONMalloc(CTestNamedString, "NS2")->Init(cS2, cNS1, "NS2");

	pRoot->Add(cNS2);
	
	AssertPointer(cNS2->mpAnother.Object(), cNS1.Object());
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());
	pcNS2 = &cNS2;
	cNS2 = NULL;
	pRoot = NULL;
	cS1 = NULL;
	pcS2 = &cS2;
	cS2 = NULL;
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());

	cNS1->Kill();

	AssertNull(pcNS2->mpAnother.Object());
	AssertLongLongInt(4, gcObjects.NumMemoryIndexes());
	AssertPointer(pcNS2->mszString.Object(), pcS2);

	ObjectsKill();
}
BOOL CImageCelsSourceXML::ImportCels(CMarkupTag* pcCelsTag, char* szFileName)
{
	STagIterator				sIter;
	CSubImageXML				cSubImageXML;
	CMarkupTag*					pcCelTag;
	CArraySubImage				acSubImages;
	CSubImage*					pcSubImage;
	BOOL						bResult;
	CImageCelSourceSubImages	cSubImagesSource;
	CImageCelsSource			cCelsSource;
	CChars						szGroupName;
	CFileUtil					cFileUtil;
	Ptr<CImageCelGroup>			pcGroup;

	acSubImages.Init();
	pcCelTag = pcCelsTag->GetTag("Cel", &sIter);
	while (pcCelTag)
	{
		pcSubImage = acSubImages.Add();

		bResult = cSubImageXML.Import(pcCelTag, pcSubImage);
		if (!bResult)
		{
			acSubImages.Kill();
			return FALSE;
		}
		pcCelTag = pcCelsTag->GetNextTag(&sIter);
	}

	cSubImagesSource.Init(&acSubImages);

	szGroupName.Init(szFileName);
	cFileUtil.RemovePath(&szGroupName);

	cCelsSource.Init();
	cCelsSource.AddDiskFileSource(szFileName, szGroupName.Text(), &cSubImagesSource);
	cCelsSource.Load();

	mpcWorld->AddImages(cCelsSource.GetImages());

	pcGroup = ONMalloc(CImageCelGroup, szGroupName.Text());
	mpcWorld->AddGroup(pcGroup);
	pcGroup->AddCels(cCelsSource.GetImageCels());

	szGroupName.Kill();
	cSubImagesSource.Kill();
	cCelsSource.Kill();
	acSubImages.Kill();
	return TRUE;
}
Exemplo n.º 11
0
void TestEmbeddedObjectRemoveDistToRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot = ORoot();
	Ptr<CGameWorld>			pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile>	pMissile = ONMalloc(CClusterMissile, "Frank")->Init(pWorld);
	Ptr<CHarrier>			pHarrier = OMalloc(CHarrier)->Init(pWorld);
	Ptr<CMissile>			pHolder = OMalloc(CMissile)->Init(pWorld);
	
	pWorld->AddTickable(pHolder);
	AssertInt(4, pHolder->GetDistToRoot());

	pHolder->SetTarget(pHarrier);
	AssertInt(5, pHarrier->GetDistToRoot());

	Ptr<CClusterLauncher>	pLauncher = OMalloc(CClusterLauncher)->Init();

	pRoot->Add(pLauncher);
	AssertInt(2, pLauncher->GetDistToRoot());

	pLauncher->mpMissile = pMissile;

	AssertInt(3, pMissile->GetDistToRoot());
	AssertInt(3, pMissile->mcMissile1.GetDistToRoot());
	AssertInt(3, pMissile->mcMissile2.GetDistToRoot());
	AssertInt(5, pHarrier->GetDistToRoot());
	AssertInt(1, pHarrier->NumHeapFroms());

	pMissile->mcMissile1.SetTarget(pHarrier);
	AssertInt(4, pHarrier->GetDistToRoot());
	AssertInt(2, pHarrier->NumHeapFroms());

	pWorld->RemoveTickable(pHolder);
	pHolder = NULL;

	AssertInt(4, pHarrier->GetDistToRoot());
	AssertInt(1, pHarrier->NumHeapFroms());

	pRoot->Add(pHarrier);
	AssertInt(2, pHarrier->GetDistToRoot());

	pRoot->Remove(pHarrier);
	AssertInt(4, pHarrier->GetDistToRoot());

	ObjectsKill();
}
CPointer SetupObjectReaderChunkedChunkFile(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CTestNamedString>	cNS2;
	Ptr<CTestNamedString>	cNS3;
	Ptr<CTestNamedString>	cNS4;
	Ptr<CTestInteger>		cI1;
	Ptr<CTestInteger>		cI2;
	Ptr<CTestInteger>		cI3;
	Ptr<CTestWithArray>		cA1;
	Ptr<CTestWithArray>		cA2;
	Ptr<CString>			sz1;
	Ptr<CString>			sz2;
	Ptr<CString>			sz3;

	cNS1 = ONMalloc(CTestNamedString, "NamedString 1")->Init();
	cNS2 = ONMalloc(CTestNamedString, "NamedString 2")->Init();
	cNS3 = ONMalloc(CTestNamedString, "NamedString 3")->Init();
	cNS4 = ONMalloc(CTestNamedString, "NamedString 4")->Init();

	cI1 = OMalloc(CTestInteger)->Init(3, 2, 1);
	AssertLongLongInt(5LL, cI1->GetOI());
	cI2 = OMalloc(CTestInteger)->Init(543, 3, 4);
	AssertLongLongInt(6LL, cI2->GetOI());
	cI3 = OMalloc(CTestInteger)->Init(10, 8192, 7);
	AssertLongLongInt(7LL, cI3->GetOI());

	cA1 = ONMalloc(CTestWithArray, "Array 1")->Init("Something with One", 1);
	cA2 = ONMalloc(CTestWithArray, "Array X")->Init("An with 2", 2);

	sz1 = OMalloc(CString)->Init("String 1");
	sz2 = OMalloc(CString)->Init("Ye!");
	sz3 = OMalloc(CString)->Init("3");

	cNS1->Init(sz1, cNS2, "In Named 1");
	cNS2->Init(sz1, cNS3, "Another in 2");
	cNS3->Init(sz3, cNS1, "Three");
	cNS4->Init(ONull, ONull, "Nulloid!");

	cA1->Add(sz2);
	cA1->Add(cNS1);
	cA1->Add(cI1);
	cA1->Add(cNS3);
	cA1->Add(cI2);
	cA1->Add(cA2);

	cA2->Add(cI3);
	cA2->Add(cNS2);
	cA2->Add(cI1);
	cA2->Add(cNS4);

	return cA1;
}
Exemplo n.º 13
0
void TestEmbeddedOjectIsAllocatedInObjects()
{
	MemoryInit();
	ObjectsInit();

	Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Gerbil")->Init(NULL);
	AssertTrue(pClusterMissile->IsAllocatedInObjects());
	AssertTrue(pClusterMissile->mcMissile1.IsAllocatedInObjects());
	AssertTrue(pClusterMissile->mcMissile2.IsAllocatedInObjects());
	pClusterMissile = NULL;

	CClusterMissile cClusterMissile;
	cClusterMissile.Class();
	cClusterMissile.Init(NULL);
	AssertFalse(cClusterMissile.IsAllocatedInObjects());
	AssertFalse(cClusterMissile.mcMissile1.IsAllocatedInObjects());
	AssertFalse(cClusterMissile.mcMissile2.IsAllocatedInObjects());

	ObjectsKill();
	MemoryKill();
}
Exemplo n.º 14
0
void TestObjectsObjectKillInArrayInGraph(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CArrayObject>		cA1;
	Ptr<CArrayObject>		cA2;
	Ptr<CRoot>				pRoot;
	Ptr<CString>			cS1;

	ObjectsInit();

	pRoot = ORoot();

	cS1 = OMalloc(CString)->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1");

	cA1 = OMalloc(CArrayObject)->Init();
	cA2 = OMalloc(CArrayObject)->Init();

	cA1->Add(cNS1);
	cA2->Add(cNS1);

	pRoot->Add(cA1);
	pRoot->Add(cA2);

	AssertInt(1, cA1->NumPointerTos());
	AssertInt(1, cA2->NumPointerTos());
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());
	pRoot = NULL;
	cS1 = NULL;
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());

	cNS1->Kill();
	AssertLongLongInt(4, gcObjects.NumMemoryIndexes());

	AssertInt(0, cA1->NumPointerTos());
	AssertInt(0, cA2->NumPointerTos());


	ObjectsKill();
}
Exemplo n.º 15
0
void TestKillCanFindRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>			pRoot;
	Ptr<CGameWorld>		pWorld;
	CGameWorld*			pcWorld;

	pRoot = ORoot();

	pWorld = OMalloc(CGameWorld);
	pWorld->Init();

	pRoot->Add(pWorld);

	Ptr<CHarrier> pHarrier = ONMalloc(CHarrier, "Harrier");
	pHarrier->Init(pWorld);

	Ptr<CJeep> pJeep = ONMalloc(CJeep, "Jeep");
	pJeep->Init(pWorld);

	pWorld->AddPlayer(pHarrier);
	pWorld->AddPlayer(pJeep);

	SStateOnKill	sHarrierBefore;
	SStateOnKill	sHarrierAfter;
	SStateOnKill	sJeepBefore;
	SStateOnKill	sJeepAfter;

	pHarrier->SetKillHook(&sHarrierBefore, &sHarrierAfter);
	pJeep->SetKillHook(&sJeepBefore, &sJeepAfter);

	SStateOnKill	sGooseBefore;
	SStateOnKill	sGooseAfter;
	SStateOnKill	sMaverickBefore;
	SStateOnKill	sMaverickAfter;

	Ptr<CRedJet>	pRedJetGoose = ONMalloc(CRedJet, "Goose");
	Ptr<CRedJet>	pRedJetMaverick = ONMalloc(CRedJet, "Maverick");

	pRedJetGoose->Init(pWorld);
	pRedJetMaverick->Init(pWorld);

	pRedJetGoose->SetKillHook(&sGooseBefore, &sGooseAfter);
	pRedJetMaverick->SetKillHook(&sMaverickBefore, &sMaverickAfter);

	AssertTrue(pJeep->CanFindRoot());
	AssertTrue(pRedJetMaverick->CanFindRoot());
	AssertTrue(pHarrier->CanFindRoot());
	AssertTrue(pHarrier->GetMissiles()->CanFindRoot());
	AssertTrue(pRedJetGoose->CanFindRoot());
	AssertTrue(pWorld->CanFindRoot());
	AssertTrue(pWorld->GetTickables()->CanFindRoot());
	AssertTrue(pRoot->CanFindRoot());
	AssertTrue(pRoot->TestGetSet()->CanFindRoot());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());

	//     
	// 4        ArrayObject[6](4)
	// 4                 ^
	// 4                 |                     pRedJetGoose[8,Goose](4)
	// 4                 |                            ^/
	//                   |                           //  pRedJetMaverick[9,Maverick](4)
	// 3  pHarrier[5,Harrier](3)   pJeep[7,Jeep](3) //   ^/  
	// 3                |^     ^   /^     ^        //   //
	// 3                ||      \ //      |       //   //
	// 3                ||       //       |      //   //
	// 3                ||      //\       |     //   //
	// 3                ||     //  \      |    /.   //
	// 3                ||    //   ArrayObject[4](3)/
	//                  ||   //    ^          .    /
	// 2                ||  //    /          /    /
	// 2                v| v/    /          v    v 
	// 2               pWorld[3](2)---------------
	//                   ^
	// 1                 |
	// 1             SetObject[2](1)
	//                   ^
	// 0                 |
	// 0              pRoot[1,GraphRoot](0)
	//  

	pRoot->Remove(pWorld);
	AssertFalse(pJeep->CanFindRoot());
	AssertFalse(pRedJetMaverick->CanFindRoot());
	AssertFalse(pHarrier->CanFindRoot());
	AssertFalse(pHarrier->GetMissiles()->CanFindRoot());  //The destruction of the pointer created by pHarrier->GetMissiles() set a lot of the root distances to -2.
	AssertFalse(pRedJetGoose->CanFindRoot());
	AssertFalse(pWorld->CanFindRoot());
	AssertFalse(pWorld->GetTickables()->CanFindRoot());
	AssertTrue(pRoot->CanFindRoot());
	AssertTrue(pRoot->TestGetSet()->CanFindRoot());
	AssertInt(-1, pJeep->GetDistToRoot());
	AssertInt(-1, pRedJetMaverick->GetDistToRoot());
	AssertInt(-1, pHarrier->GetDistToRoot());
	AssertInt(-1, pHarrier->GetMissiles()->GetDistToRoot());
	AssertInt(-1, pRedJetGoose->GetDistToRoot());
	AssertInt(-1, pWorld->GetDistToRoot());
	AssertInt(-1, pWorld->GetTickables()->GetDistToRoot());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());

	pJeep = NULL;
	pRedJetMaverick = NULL;
	pHarrier = NULL;
	pRedJetGoose = NULL;
	pcWorld = &pWorld;
	pWorld = NULL;

	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(1, gcObjects.NumMemoryNames());

	AssertInt('X', sHarrierBefore.sPoint.x);
	AssertInt('Y', sHarrierBefore.sPoint.y);
	AssertInt('Z', sHarrierBefore.sPoint.z);
	AssertString("012345678901234", sHarrierBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sHarrierAfter.cPicture.mszPretenedImAPicture);
	AssertString("012345678901234", sJeepBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sJeepAfter.cPicture.mszPretenedImAPicture);

	ObjectsKill();
}
Ptr<CTestDoubleNamedString> SetupDehollowficationScene(void)
{
	Ptr<CTestNamedString>			cNS1;
	Ptr<CTestNamedString>			cNS2;
	Ptr<CTestNamedString>			cDiamond;
	Ptr<CTestDoubleNamedString>	cDouble;
	Ptr<CString>					sz1;
	Ptr<CString>					sz3;
	Ptr<CString>					sz2;
	Ptr<CString>					sz4;
	Ptr<CRoot>						cRoot;
	Ptr<CTestNamedString>			cNS3;

	cRoot = ORoot();

	cDiamond = ONMalloc(CTestNamedString, "Diamond End");
	sz1 = OMalloc(CString);

	cNS1 = ONMalloc(CTestNamedString, "NamedString 1");
	cNS1->Init(sz1, cDiamond, "Hello");
	sz1->Init("World");

	cNS2 = ONMalloc(CTestNamedString, "NamedString 2");
	sz2 = OMalloc(CString);

	cNS2->Init(sz2, cDiamond, "12345");
	sz2->Init("6789");

	sz3 = OMalloc(CString);
	sz3->Init("End");
	cDiamond->Init(sz3, ONull, "Before Swine");

	sz4 = OMalloc(CString);
	sz4->Init("Start");
	cDouble = ONMalloc(CTestDoubleNamedString, "Double Start");
	cDouble->Init(sz4, cNS1, ONull);

	cRoot->Add(cDouble);

	cDouble->mpSplit1 = cNS2;

	cNS3 = ONMalloc(CTestNamedString, "NamedString 3");
	cNS3->Init(sz1, ONull, "Random");

	cRoot->Add(cNS3);

//
//      sz3
//       |
//    cDiamond
//      / \
// sz2 /   \  sz1
//  | /     \  |
//  cNS2    cNS1
//    \     /
//     \   / sz4
//      \ /  /
//    cDouble   sz1 
//       \       |
//        \    cNS3
//         \   /
//          \ /
//          Set
//           |
//         cRoot
//       

	return cDouble;
}
void TestObjectWriterChunkedSerialised(void)
{	
	ObjectsInit();

	CObjectWriterChunked		cWriter;
	CObjectGraphSerialiser		cGraphSerialiser;

	Ptr<CTestWithArray>			pcObject1;
	Ptr<CTestInteger>			pcObject2;
	Ptr<CTestInteger>			pcObject3;
	Ptr<CTestInteger>			pcObject4;
	CChunkFileNames				cChunkFile;
	int							iLength;
	char						szTest[4];

	pcObject1 = ONMalloc(CTestWithArray, "Base/Level 1/Warning");
	pcObject1->Init("Talking Clock", 17);

	pcObject2 = OMalloc(CTestInteger);
	pcObject2->Init(2, 9, 937);
	pcObject1->Add(pcObject2);

	pcObject3 = OMalloc(CTestInteger);
	pcObject3->Init(3, 7321, 7);
	pcObject1->Add(pcObject3);

	pcObject4 = OMalloc(CTestInteger);
	pcObject4->Init(4, 5, 6);
	pcObject1->Add(pcObject4);

	cWriter.Init("Output\\ObjectWriterChunked\\Test\\", "Base/Level 1", "ChunkFile");

	cGraphSerialiser.Init(&cWriter);
	AssertTrue(cGraphSerialiser.Write(&pcObject1));
	cGraphSerialiser.Kill();

	cWriter.Kill();

	AssertFile("Input/ChunkFile.DRG", "Output/ObjectWriterChunked/Test/Base/Level 1/ChunkFile.DRG");

	cChunkFile.Init(DiskFile("Output/ObjectWriterChunked/Test/Base/Level 1/ChunkFile.DRG"));
	AssertTrue(cChunkFile.ReadOpen());

	//CTestWithArray pcObject1
	AssertTrue(cChunkFile.ReadChunkBegin("Warning"));
	AssertTrue(cChunkFile.ReadInt(&iLength));
	AssertInt(106, iLength);
	AssertTrue(cChunkFile.ReadData(szTest, 4));
	AssertString("NAM", szTest);
	AssertTrue(cChunkFile.ReadChunkEnd());

	//CArrayObject
	AssertTrue(cChunkFile.ReadChunkBegin("Unnamed/0000000000000002"));
	AssertTrue(cChunkFile.ReadInt(&iLength));
	AssertInt(101, iLength);
	AssertTrue(cChunkFile.ReadData(szTest, 4));
	AssertString("IDX", szTest);
	AssertTrue(cChunkFile.ReadChunkEnd());

	//CTestInteger pcObject2
	AssertTrue(cChunkFile.ReadChunkBegin("Unnamed/0000000000000003"));
	AssertTrue(cChunkFile.ReadInt(&iLength));
	AssertInt(45, iLength);
	AssertTrue(cChunkFile.ReadData(szTest, 4));
	AssertString("IDX", szTest);
	AssertTrue(cChunkFile.ReadChunkEnd());

	//CTestInteger pcObject3
	AssertTrue(cChunkFile.ReadChunkBegin("Unnamed/0000000000000004"));
	AssertTrue(cChunkFile.ReadInt(&iLength));
	AssertInt(45, iLength);
	AssertTrue(cChunkFile.ReadData(szTest, 4));
	AssertString("IDX", szTest);
	AssertTrue(cChunkFile.ReadChunkEnd());

	//CTestInteger pcObject4
	AssertTrue(cChunkFile.ReadChunkBegin("Unnamed/0000000000000005"));
	AssertTrue(cChunkFile.ReadInt(&iLength));
	AssertInt(45, iLength);
	AssertTrue(cChunkFile.ReadData(szTest, 4));
	AssertString("IDX", szTest);
	AssertTrue(cChunkFile.ReadChunkEnd());

	AssertTrue(cChunkFile.ReadClose());
	cChunkFile.Kill();

	ObjectsKill();
}
Exemplo n.º 18
0
void TestKillBestPractice(void)
{
	ObjectsInit();

	//Generally an object will be killed if all pointers to it a removed.
	//Sometimes we'd rather not try and remove all the pointers we just want the object to die.
	//In the example below if a missile hits a jet then both objects should be removed;
	//regardless of whether anything else points to them.
	//Those objects that did point to them will be updated to point to NULL.

	Ptr<CRoot>			pRoot;
	Ptr<CGameWorld>		pWorld;

	pRoot = ORoot();

	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pWorld = OMalloc(CGameWorld);
	pWorld->Init();

	pRoot->Add(pWorld);

	Ptr<CHarrier> pHarrier = ONMalloc(CHarrier, "Harrier");
	pHarrier->Init(pWorld);

	Ptr<CJeep> pJeep = ONMalloc(CJeep, "Jeep");
	pJeep->Init(pWorld);

	pWorld->AddPlayer(pHarrier);
	pWorld->AddPlayer(pJeep);

	SStateOnKill	sHarrierBefore;
	SStateOnKill	sHarrierAfter;
	SStateOnKill	sJeepBefore;
	SStateOnKill	sJeepAfter;

	pHarrier->SetKillHook(&sHarrierBefore, &sHarrierAfter);
	pJeep->SetKillHook(&sJeepBefore, &sJeepAfter);

	SStateOnKill	sGooseBefore;
	SStateOnKill	sGooseAfter;
	SStateOnKill	sMaverickBefore;
	SStateOnKill	sMaverickAfter;

	Ptr<CRedJet>	pRedJetGoose = ONMalloc(CRedJet, "Goose");
	Ptr<CRedJet>	pRedJetMaverick = ONMalloc(CRedJet, "Maverick");

	pRedJetGoose->Init(pWorld);
	pRedJetMaverick->Init(pWorld);

	pRedJetGoose->SetKillHook(&sGooseBefore, &sGooseAfter);
	pRedJetMaverick->SetKillHook(&sMaverickBefore, &sMaverickAfter);

	Ptr<CMissile> pMissile1 = pHarrier->FireMissile(pRedJetGoose);
	Ptr<CMissile> pMissile2 = pHarrier->FireMissile(pRedJetGoose);
	Ptr<CMissile> pMissile3 = pHarrier->FireMissile(pRedJetMaverick);

	AssertString("Kill not called", sMaverickBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sMaverickAfter.cPicture.mszPretenedImAPicture);
	AssertLongLongInt(12, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetGoose.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());
	AssertInt(4, pMissile3.GetDistToRoot());
	AssertInt(2, pRedJetMaverick->NumHeapFroms());
	AssertInt(3, pHarrier->GetMissiles()->NumElements());

	OIndex oiMissile3 = pMissile3->GetOI();
	AssertLongLongInt(12LL, oiMissile3);

	pMissile3->Kill();  //<-- This is what is being tested.
	pMissile3 = gcObjects.TestGetFromMemory(oiMissile3);
	AssertTrue(pMissile3.IsNull());

	AssertString("Kill not called", sMaverickBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sMaverickAfter.cPicture.mszPretenedImAPicture);
	AssertLongLongInt(11, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetGoose.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());
	AssertInt(1, pRedJetMaverick->NumHeapFroms());
	AssertInt(2, pHarrier->GetMissiles()->NumElements());

	AssertString("Kill not called", sGooseBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sGooseAfter.cPicture.mszPretenedImAPicture);

	pRedJetGoose->Kill();
	AssertString("012345678901234", sGooseBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sGooseAfter.cPicture.mszPretenedImAPicture);
	AssertInt(1, pMissile1->NumTos());
	CPointer pTarget1(pMissile1->GetTarget());
	AssertTrue(pTarget1.IsNull());
	AssertInt(1, pMissile2->NumTos());
	CPointer pTarget2 = pMissile2->GetTarget();
	AssertTrue(pTarget2.IsNull());
	AssertLongLongInt(10, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(4, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());

	pMissile1->Kill();
	pMissile2->Kill();
	AssertInt(0, pHarrier->GetMissiles()->NumElements());
	AssertTrue(pMissile1.IsNull());
	AssertTrue(pMissile2.IsNull());

	pJeep = NULL;
	pRedJetMaverick = NULL;
	pHarrier = NULL;

	//pHarrier.maMissiles.moi == 6
	//pWorld.maTickables.moi == 4
	//pWorld is pointed to from:
	//  pRoot.mpObjects
	//  pHarrier
	//  pJeep
	//  pRedJetMaverick

	pRoot->Remove(pWorld);
	//ERROR: (baseobject.cpp:1159) void __thiscall CBaseObject::ValidateCanFindRoot(void) Object {02596128 [ 4]:CArrayObject(128) 6} has a positive dist to root and should be able to find the Root object.

	AssertLongLongInt(8, gcObjects.NumMemoryIndexes());
	pWorld = NULL;

	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(1, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());

	AssertInt('X', sHarrierBefore.sPoint.x);
	AssertInt('Y', sHarrierBefore.sPoint.y);
	AssertInt('Z', sHarrierBefore.sPoint.z);
	AssertString("012345678901234", sHarrierBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sHarrierAfter.cPicture.mszPretenedImAPicture);
	AssertString("012345678901234", sJeepBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sJeepAfter.cPicture.mszPretenedImAPicture);

	ObjectsKill();
}
Exemplo n.º 19
0
void TestEmbeddedObjectKill(void)
{
	char	szClusterMissileState[64];
	char	szMissile1State[64];

	ObjectsInit();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CGameWorld> pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Anna")->Init(pWorld);
	pWorld = NULL;

	Ptr<CPointerContainer> pPointerPointer = OMalloc(CPointerContainer);
	pRoot->Add(pPointerPointer);
	pPointerPointer->Init(&pClusterMissile->mcMissile1);

	Ptr<CPointerContainer> pPointerPointer2 = OMalloc(CPointerContainer);
	pRoot->Add(pPointerPointer2);
	pPointerPointer2->Init(&pClusterMissile);

	//The number of allocated object shouldn't change until all the froms are removed
	//both from the embedded object and the 'normal' object.
	AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(7, gcUnknowns.NumElements());

	pClusterMissile->SetKillString(szClusterMissileState);
	pClusterMissile->mcMissile1.SetKillString(szMissile1State);

	AssertInt(2, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());
	strcpy(szClusterMissileState, "Alive");
	strcpy(szMissile1State, "Alive");

	pPointerPointer->Clear();

	AssertInt(1, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(0, pClusterMissile->mcMissile1.NumHeapFroms());
	AssertString("Alive", szClusterMissileState);
	AssertString("Alive", szMissile1State);

	pPointerPointer->mp = &pClusterMissile->mcMissile1;

	AssertInt(2, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());

	pPointerPointer2->Clear();

	AssertInt(1, pClusterMissile->NumHeapFroms());
	AssertInt(0, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());
	AssertString("Alive", szClusterMissileState);
	AssertString("Alive", szMissile1State);

	pClusterMissile = NULL;

	//Make sure nothing has been de-allocated.
	AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(7, gcUnknowns.NumElements());

	pPointerPointer->Clear();

	AssertString("Killed", szClusterMissileState);
	AssertString("Killed", szMissile1State);

	AssertLongLongInt(6, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(6, gcUnknowns.NumElements());

	gcObjects.Flush(TRUE, FALSE);

	AssertLongLongInt(0, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(0, gcUnknowns.NumElements());

	ObjectsKill();
}