示例#1
0
        void Begin(){
            ScreenManager::GetInstance().SetScreenName("Test pool");
            /*
            If the first parameter was false. The object 2 would not be added.
            This object 2 will be added to an list, not to a pool. Basically an std::vector<GameObject*>
            */

            /*
                Pre alloc 10 test objects.
            */
            Pool.Register<TestObject>(10);

            Pool.AddInstance(TestObject2(Point(90,90)));





            Pool.AddInstance(TestObject(Point(32,32)));
            TestObject obj = TestObject({55,55});
            Pool.AddInstance(obj);

            Camera::Initiate();

        };
int FAR PASCAL WinMain(HINSTANCE hInstance,	HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	InitTotalStatistics();
	InitEmptyString();
	FastFunctionsInit();

	TestStackPointers();
	TestClass();
	TestClassStorage();
	TestUnknowns();
	TestArrayUnknown();
	TestSetUnknown();
	TestArrayType();
	TestSetType();
	TestMapStringUnknown();
	TestEvent();
	TestActionEvent();
	TestExternalChannels();
	TestExternalChannelPadder();
	TestChannels();
	TestChannelsAccessor();
	TestSingleChannelAccessor();
	TestChunkFileNames();
	TestParameters();
	TestDistToRoot();
	TestDistToStack();
	TestObjectsSimple();
	TestRoot();
	TestObject();
	TestPointer();
	TestArrayCommonObject();
	TestNamedObject();
	TestObjectAllocator();
	TestObjectWriterChunked();
	TestObjectGraphSerialiser();
	TestObjectReaderSimple();
	TestObjectReaderChunked();
	TestObjectStackPointers();
	TestNamedIndexes();
	TestObjectGraphDeserialiser();
	TestObjectConverter();
	TestObjects();
	TestDehollowfication();
	TestUsage();
	TestArray();
	TestSet();
	TestKill();
	TestEmbedded();
	TestEmbeddedObjectRemapTos();

	FastFunctionsKill();
	KillEmptyString();
	return TestTotalStatistics();
}
示例#3
0
        void Update(float dt){
            UpdateInstances(dt);
            //duration -= dt;
            objAdder -= dt;
            if (objAdder <= 0){
                Pool.AddInstance(TestObject(Point(90,90)));
                objAdder = 10.0f;
            }
            if( InputManager::GetInstance().IsAnyKeyPressed() != -1 || duration <= 0 ) {
                requestDelete = true;
            }

        };
示例#4
0
void main()
{
    // using a bit of random here.
    srand(time(nullptr)); //initialize random seed based on time

    // Where will this object live? Is this a good choice? Why or why not?
    TestObject anObject = TestObject(30);

    // Name differences between pointers and references
    TestObject *anotherObject =  new TestObject(2); //error: new returns a pointer-> '*'

    // When should we use pointers, references and values? why?
    TestObject &referenceToAnObject = anObject;  //error: no &

    TestObject &referenceToAnotherObject = *anotherObject;  //error  original adress called with '*'

    TestObject* pointerToAnObject = &anObject;	//error: for pointer,adress of obj. is needed with &

    TestObject* pointerToAnotherObject = &referenceToAnotherObject; // error fix: for pointer, adress of Obj. is needed with '&'
    

    // Testing if the correct strings are being printed.
    referenceToAnotherObject.printAllStrings();
    std::cout << "The Following should be the same as above: " << std::endl;
    pointerToAnotherObject->printAllStrings();

    std::cout << std::endl << "total number of strings:" << std::endl;
   
    int& TotalElementNumber = sumTheElements(referenceToAnObject.elementCount(), referenceToAnotherObject.elementCount());
    std::cout << TotalElementNumber << std::endl;
    std::cout << "Do calculations in another scope and display the same value again inside that scope: " << std::endl; 
    { 
        //this isn't really doing anything, just for testing purposes
        int ignoreMe = 20; 
        ignoreMe *= TotalElementNumber;
        std::cout << TotalElementNumber << std::endl;
    }

    std::cout << "And again outside the scope: " << std::endl;
    std::cout << TotalElementNumber << std::endl;


    delete anotherObject;
	//cant delete objects with stack
    //delete pointerToAnObject;
    //delete pointerToAnotherObject;


}
示例#5
0
bool C_coretestBase::TestObject(int callbackID, const Json::Value& parameters)
{
    Json::Value testObject_JSON;
    FetchObject(parameters, "testObject", testObject_JSON);

    Json::Value param_JSON;
    FetchObject(testObject_JSON, "param", param_JSON);

    int32 param;
    FetchInt(param_JSON, param);




    TestObject(callbackID, param);
    return true;
}
示例#6
0
void TestScriptBindMetaData4()
{
	GDefineMetaClass<BasicA>
		::define(REG_NAME_BasicA)
		._class(
			GDefineMetaClass<BasicA::Inner>::declare("Inner")
				._field("x", &BasicA::Inner::x)
				._method("add", &BasicA::Inner::add)
		)
		._enum<BasicA::BasicEnum>("BasicEnum")
			._element("a", BasicA::a)
			._element("b", BasicA::b)
			._element("c", BasicA::c)
	;

	GDefineMetaGlobal()
		._method("scriptTrace", &scriptTrace)
		._method("scriptAssert", &scriptAssert)
		._method("scriptNot", &scriptNot)
		._method("testAdd2", &testAdd2)
		._method("testAddN", &testAddN)
		._method("testAddCallback2", &testAddCallback2)
		._method("testAddCallback", &testAddCallback)
		._method("testExecAddCallback", &testExecAddCallback)
		
		._method("writeNumberToByteArray", &writeNumberToByteArray)
		._method("writeNumberToByteArrayMemory", &writeNumberToByteArrayMemory)

		._method("testDefaultParam", &testDefaultParam)
			._default(copyVariantFromCopyable(TestObject(8)))
			._default(copyVariantFromCopyable(string("abc")))
			._default(5)
			
		._method("testWideStringParam", &testWideStringParam)
		
		._enum<TestEnum>(REG_NAME_TestEnum)
			._element("teCpp", teCpp)
			._element("teLua", teLua)
			._element("teV8", teV8)
		._property("testScriptFunction", &testScriptFunctionGetter, &testScriptFunctionSetter)
	;
}
示例#7
0
文件: program.cpp 项目: finartist/CG1
void main()
{
    // using a bit of random here.
    srand(time(nullptr)); //initialize random seed based on time

    // Where will this object live? Is this a good choice? Why or why not?
	 // This Object will be on the Stack. Not so good, because we have a pointer to it later
	 // its not so bad here, but normally it is bad to have a pointer to something on the stack 
	 // because if the scope ends and the pointer continues to exist, it can point to something useless
    TestObject anObject = TestObject(30);

    // Name differences between pointers and references
	 // Pointer can be changed, references not after initialization. pointer can be null, refer. not. References can be used like the object and need no dereference
    TestObject* anotherObject = new TestObject(2);

    // When should we use pointers, references and values? why?
	 // pointers for optional parameters
	 // references for any none-elemental datatypes
	 // values for small (32/64Bit) datatype and no change

	//reference is initialized with variable name, not adress
    TestObject& referenceToAnObject = anObject;

	// same here, so we have to dereference the pointer "anotherObject" first
    TestObject& referenceToAnotherObject = *anotherObject;

	// pointer is initialized with adress, so we have to get ADRESS from "anObject"
    TestObject* pointerToAnObject = &anObject;

	// same here, although referenceToAnotherObject is a reference(basically a adress too) 
	// it is used like the object itself, so we need to GET the ADRESS here too
    TestObject* pointerToAnotherObject = &referenceToAnotherObject;
    

    // Testing if the correct strings are being printed.
    referenceToAnotherObject.printAllStrings();
    std::cout << "The Following should be the same as above: " << std::endl;
    pointerToAnotherObject->printAllStrings();

    std::cout << std::endl << "total number of strings:" << std::endl;
   
    int& TotalElementNumber = sumTheElements(referenceToAnObject.elementCount(), referenceToAnotherObject.elementCount());
    std::cout << TotalElementNumber << std::endl;
    std::cout << "Do calculations in another scope and display the same value again inside that scope: " << std::endl; 
    { 
        //this isn't really doing anything, just for testing purposes
        int ignoreMe = 20; 
        ignoreMe *= TotalElementNumber;
        std::cout << TotalElementNumber << std::endl;
    }

    std::cout << "And again outside the scope: " << std::endl;
    std::cout << TotalElementNumber << std::endl;


    delete anotherObject;
	// these pointers have not been initialized with new, so cannot be deleted
    //delete pointerToAnObject;
    //delete pointerToAnotherObject;


}
示例#8
0
int main()
{
    // using a bit of random here.
    srand(time(nullptr)); //initialize random seed based on time

    // Where will this object live? Is this a good choice? Why or why not?
    // stack. the stack/heap choice does not really matter here, because the object itself allocates the bulk of its space on the heap.
    TestObject anObject = TestObject(30);

    // Name differences between pointers and references
    // # References:
    // * cannot point to unknown space
    // * cannot be changed after definition
    // * behave like the variable they reference most of the time
    // * immutable
    // # Pointers:
    // * can point to whatever
    // * can be changed whenever
    // * behave like a pointer
    // * mutable
    TestObject anotherObject = TestObject(2);

    // When should we use pointers, references and values? why?
    // use the value if it is very small, and changes in the function are not required out of it
    // use a pointer if the object does exist at definition time, or when a parameter may be null
    // use a reference whenever you can
    TestObject &referenceToAnObject = anObject;

    TestObject &referenceToAnotherObject = anotherObject;

    TestObject* pointerToAnObject = &anObject;

    TestObject* pointerToAnotherObject = &referenceToAnotherObject;
    

    // Testing if the correct strings are being printed.
    referenceToAnotherObject.printAllStrings();
    std::cout << "The Following should be the same as above: " << std::endl;
    pointerToAnotherObject->printAllStrings();

    std::cout << std::endl << "total number of strings:" << std::endl;
   
    const int& TotalElementNumber = sumTheElements(referenceToAnObject.elementCount(), referenceToAnotherObject.elementCount());
    std::cout << TotalElementNumber << std::endl;


    std::cout << "Do calculations in another scope and display the same value again inside that scope: " << std::endl;
    {
        //this isn't really doing anything, just for testing purposes
        int ignoreMe = 20;
        ignoreMe *= TotalElementNumber;
        std::cout << TotalElementNumber << std::endl;
    }

    std::cout << "And again outside the scope: " << std::endl;
    std::cout << TotalElementNumber << std::endl;

    // everything is on the stack, nothing needs to be deleted
    //delete pointerToAnObject;
    //delete pointerToAnotherObject;

    return 0;
}