Jump to content

[SOLVED] Loading and Initializing global Properties


photo

Recommended Posts

Posted

Hey guys,

 

I have some problems to create custom global classes with the property-library. I programmed for more than a year with Unreal and try to migrate my code to Unigine. In my case I have a class Items. Resources derived from Items and are needed to build my buildings. Stone is on type of resource and derived from Resources. Now I want to create some instances of stone in my property file, for example granite, hematite or graphite. They all have different values in capacity, value and need for different production branches. So I started to implement my Property-file for that.

 

First I want to iterate through each property and check, If they have the same parent class (Stone). I used properties.getProperty(library,Index) to get the single parameters of them but can't find any function to check, if they have the same parent. So how can I do that?

The idea is, that a level designer (or someone else) can easily create new sub-archetypes of stone by copy and paste the neccessary peace of code. And all those archetypes are available in each world, so I have to initialize them in my unigine.cpp-file.

 

Next, my buildings have different building steps to spawn different instances of Objects to simulate the build of the house. A building step holds an Object/Node for the step and a Time for how long the step will be visible. But each building can have different number of building steps. So are there any solution to fill my vector with different number of building steps from the property file on-rhe-fly. I attached a picture from the Unreal-Properties to show you what exactly I was looking for.

 

 

 

Beside that questions I have another engine-specific one. Are there any technical or other reasons why Unigine does not support any struct-data? It's only a personal interesting. I can deal with extra classes instead of my old struct-datas very well.

post-86-0-06351600-1357922984_thumb.png

Posted

Nevermind, I got it worked.

 

For all others with the same problem I show you my solution:

 

1. Solution to check the parent:

 

int ItemLibrary = engine.properties.load("/project/properties/ItemProperties.prop");

if (ItemLibrary == 0)
{
	log.error("Unable to load Item properties.");
}
else
{
	log.message("Item properties sucessfully loaded.");
	
	int LibraryIndex = engine.properties.findLibrary("/project/properties/ItemProperties.prop");
	int NumProperties = engine.properties.getNumProperties(LibraryIndex);
	
	Property LoadedProperty;
	Property ParentProperty;
	string ParentName;

	for (int i = 0; i < NumProperties; i++)
	{
		LoadedProperty = engine.properties.getProperty(LibraryIndex,i);
		ParentProperty = LoadedProperty.getParent();
		
		//check if there are a parent-class
		if (ParentProperty != NULL)
		{
			ParentName = ParentProperty.getName();
			
			if(ParentName == /*Post your string here*/)
			{
				....
			}
		}
	}
}

 

 

One comment to engine.properties.findLibrary() : If you load an property on-the-fly the needed string-name for that function will be the complete pathname to it. Maybe it will be better to add a comment at the documentation about that.

 

2. Vectors in Properties:

 

I found a workaround for that problem.

 

string ParameterIndex;
int ParameterIndexAmount;

for (int j = 1; j <= 10; j++)
{
	ParameterIndex = "Column" + j;
	ParameterIndexName = PropertyUtils::getParameterString(LoadedProperty,ParameterIndex);
	ParameterIndex = "ValueForColumn" + j;
	ParameterIndexAmount = PropertyUtils::getParameterInt(LoadedProperty,ParameterIndex);

	if (ParameterIndexName == "" || ParameterIndexAmount == 0)
	{
		//No more Properties in your "Vector"-Properties
		break;
	}
	else
	{
		//add your code here
	}
}

 

Use a while-loop instead a for-loop for "infinite" amount of data. For my need 10 values are enough.

  • 2 weeks later...
Posted

Cristian,

 

Nevermind, I got it worked. 

For all others with the same problem I show you my solution:

That's great. And it's good you've shared your code in case someone stumbles upon the same problem.

 

1. Solution to check the parent:

Yes, Property::getParent() is exactly what you need.

 

One comment to engine.properties.findLibrary() : If you load an property on-the-fly the needed string-name for that function will be the complete pathname to it. Maybe it will be better to add a comment at the documentation about that.

It depends on what you pass when loading a library. In case you find a library that belongs to the world (written in the world file), then yes, it should be a full pathname.

 

Thank you, I've updated the docs on that.

 

Beside that questions I have another engine-specific one. Are there any technical or other reasons why Unigine does not support any struct-data? It's only a personal interesting. I can deal with extra classes instead of my old struct-datas very well.

We do not support it since classes provide the same functionality and can be used in all cases instead of struct.
×
×
  • Create New...