Skip to content

Overall features

Kigs-framework edited this page Apr 23, 2020 · 19 revisions

Modular architecture

The Kigs framework is divided into different modules, each grouping functionalities in a particular domain (Input, Rendering, GUI...). There is two main module type : Generic and Specific.

Generic modules

A generic module define API/SDK/System independent classes, and/or base classes (interface) for API/SDK/System dependent classes.

Specific modules

Of course, specific modules do the exact opposite : they define API/SDK/System dependent classes, often inheriting from generic classes.

base modules

The main modules are Core, FileManager, Timer, XML. Then Input ( with specific InputWindows, InputWUP...), GUI (GuiWindows, GUIWUP...), SceneGraph, Renderer ( RendererOpenGL3, RendererDirectX11)...

Core features

Core features are mainly supported by KigsCore and CoreModifiable classes.

Instance factory

Classes with CoreModifiable inheritance can be registered to instance factory. Ask KigsCore to create a new instance of the wanted class is then easy :

// Ask for an instance of class Timer called "localtimer"
CMSP localtimer = KigsCore::GetInstanceOf("localtimer", "Timer");

Here localtimer is returned as a CMSP (CoreModifiable SmartPointer). If no more reference are retained, the localtimer instance will be deleted when code exits localtimer scope.

CoreModifiable instances can be organized in parent/sons trees like this :

// add localtimer instance to this (this must inherit CoreModifiable too of course)
addItem(localtimer);

addItem add a reference to the reference count of the instance. localtimer instance will be destroyed when its references count reach 0, so in our case when parent class is destroyed.

CoreModifiable should be initialized before use :

// init localtimer (timer is started)
localtimer->Init();

then localtimer can then be retrieved in another part of the code with different kind of research functions :

// search son with given name
Timer* localtimer=GetFirstSonByName("Timer", "localtimer")->as<Timer>();

or

// search first instance found with given name
CMSP localtimer = GetFirstInstanceByName("Timer", "localtimer");

All instances of a given type can also be retreived in one call :

// search all instances of Timer
std::vector<CMSP> alltimers = GetInstances("Timer");

CoreModifiable can have "compile time" attributes that can be get or set by their names :

// retreive "Sample1Value" value on this
int _value;
testInstance->getValue("Sample1Value", _value);
_value = 4 * _value - 12;
// change "Sample1Value" value with _value
testInstance->setValue("Sample1Value",  _value);

Attributes can also be added or removed at runtime :

// add a dynamic attribute on instance of localtimer
localtimer->AddDynamicAttribute(ATTRIBUTE_TYPE::FLOAT, "floatValue", 12.0f);
// retrieve dynamic attribute value on localtimer
float timervalue=localtimer->getValue<float>("floatValue");
// set dynamic float attribute with string
localtimer->setValue("floatValue","24");

Serialisation

CoreModifiable trees with all their attributes can be exported in XML files :

// export this and its sons in "Sample1.xml" file
CoreModifiable::Export("Sample1.xml", this, true);

And of course, import CoreModifiable trees from an XML file is also possible :

// import instances from file "Sample1.xml"
CMSP imported=CoreModifiable::Import("Sample1.xml");

Methods can be added to CoreModifiable and then accessed at runtime only by their names (without knowing the exact type of the instance the method is called on).

The easy way to call such a method is :

// call SimpleSampleClass AddValue method directly on CoreModifiable
float result = simpleclass->SimpleCall<float>("AddValue", 10, 12.0f);
printf("result of calling AddValue = %f\n", result);

Find all the sample code from this wiki page in Sample1 project (browse the code)