Browse Source

Still WIP, but compiling, running, and displaying text (without font effects).

Michael Ragazzon 6 years ago
parent
commit
42ac8ad4d2

+ 1 - 1
Include/Rocket/Core/FontEffectInstancer.h

@@ -89,7 +89,7 @@ private:
 	PropertySpecification properties;
 	PropertySpecification properties;
 
 
 	// Properties that define the geometry.
 	// Properties that define the geometry.
-	std::unordered_set< String > volatile_properties;
+	std::unordered_set< PropertyId > volatile_properties;
 
 
 	friend class Factory;
 	friend class Factory;
 };
 };

+ 6 - 2
Include/Rocket/Core/PropertySpecification.h

@@ -49,7 +49,7 @@ class IdNameMap {
 protected:
 protected:
 	IdNameMap(size_t num_ids_to_reserve) {
 	IdNameMap(size_t num_ids_to_reserve) {
 		static_assert((int)ID::Invalid == 0, "Invalid id must be zero");
 		static_assert((int)ID::Invalid == 0, "Invalid id must be zero");
-		name_map.resize(num_ids_to_reserve);
+		name_map.reserve(num_ids_to_reserve);
 		reverse_map.reserve(num_ids_to_reserve);
 		reverse_map.reserve(num_ids_to_reserve);
 		AddPair(ID::Invalid, "invalid");
 		AddPair(ID::Invalid, "invalid");
 	}
 	}
@@ -57,7 +57,8 @@ protected:
 public:
 public:
 	void AddPair(ID id, const String& name) {
 	void AddPair(ID id, const String& name) {
 		// Should only be used for defined IDs
 		// Should only be used for defined IDs
-		ROCKET_ASSERT((size_t)id < name_map.size());
+		if ((size_t)id >= name_map.size())
+			name_map.resize(1 + (size_t)id);
 		name_map[(size_t)id] = name;
 		name_map[(size_t)id] = name;
 		bool inserted = reverse_map.emplace(name, id).second;
 		bool inserted = reverse_map.emplace(name, id).second;
 		ROCKET_ASSERT(inserted);
 		ROCKET_ASSERT(inserted);
@@ -84,6 +85,9 @@ public:
 
 
 	ID GetOrCreateId(const String& name)
 	ID GetOrCreateId(const String& name)
 	{
 	{
+		// All predefined properties must be set before adding custom properties here
+		ROCKET_ASSERT(name_map.size() == reverse_map.size());
+
 		ID next_id = static_cast<ID>(name_map.size());
 		ID next_id = static_cast<ID>(name_map.size());
 
 
 		// Only insert if not already in list
 		// Only insert if not already in list

+ 9 - 0
Include/Rocket/Core/Types.h

@@ -48,6 +48,10 @@
 #include "Platform.h"
 #include "Platform.h"
 #include "Debug.h"
 #include "Debug.h"
 
 
+#ifdef ROCKET_DEBUG
+#include <unordered_map>
+#endif
+
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 
 
@@ -106,8 +110,13 @@ typedef uintptr_t CompiledGeometryHandle;
 typedef uintptr_t DecoratorDataHandle;
 typedef uintptr_t DecoratorDataHandle;
 
 
 // Common containers
 // Common containers
+#ifdef ROCKET_DEBUG
+template < typename Key, typename Value>
+using UnorderedMap = std::unordered_map< Key, Value >;
+#else
 template < typename Key, typename Value>
 template < typename Key, typename Value>
 using UnorderedMap = robin_hood::unordered_flat_map< Key, Value >;
 using UnorderedMap = robin_hood::unordered_flat_map< Key, Value >;
+#endif
 template < typename Key, typename Value>
 template < typename Key, typename Value>
 using SmallUnorderedMap = chobo::flat_map< Key, Value >;
 using SmallUnorderedMap = chobo::flat_map< Key, Value >;
 template < typename T >
 template < typename T >

+ 2 - 2
Samples/basic/benchmark/src/main.cpp

@@ -57,8 +57,8 @@ public:
 		{
 		{
 			{
 			{
 				document->GetElementById("title")->SetInnerRML(title);
 				document->GetElementById("title")->SetInnerRML(title);
-				document->SetProperty("left", Property(position.x, Property::PX));
-				document->SetProperty("top", Property(position.y, Property::PX));
+				document->SetProperty(PropertyId::Left, Property(position.x, Property::PX));
+				document->SetProperty(PropertyId::Top, Property(position.y, Property::PX));
 			}
 			}
 
 
 			document->Show();
 			document->Show();

+ 10 - 2
Source/Core/ElementTextDefault.cpp

@@ -377,12 +377,20 @@ bool ElementTextDefault::UpdateFontConfiguration()
 
 
 	// Build up a list of all applicable font effects set by our parent nodes.
 	// Build up a list of all applicable font effects set by our parent nodes.
 	FontEffectMap font_effects;
 	FontEffectMap font_effects;
+
+	// @hack/todo: Only using the "none" font-effect for now
+	static FontEffect* font_effect = nullptr;
+	if(!font_effect)
+		font_effect = FontDatabase::GetFontEffect("none", PropertyDictionary());
+	ROCKET_ASSERT(font_effect);
+	font_effects.emplace("", font_effect);
+
 	Element* element = GetParentNode();
 	Element* element = GetParentNode();
 	while (element != NULL)
 	while (element != NULL)
 	{
 	{
 		const ElementDefinition* element_definition = element->GetDefinition();
 		const ElementDefinition* element_definition = element->GetDefinition();
-		if (element_definition != NULL)
-			element_definition->GetFontEffects(font_effects, element->GetStyle()->GetActivePseudoClasses());
+		//if (element_definition != NULL)
+		//	element_definition->GetFontEffects(font_effects, element->GetStyle()->GetActivePseudoClasses());
 
 
 		element = element->GetParentNode();
 		element = element->GetParentNode();
 	}
 	}

+ 19 - 23
Source/Core/Factory.cpp

@@ -372,11 +372,7 @@ Decorator* Factory::InstanceDecorator(const String& name, const PropertyDictiona
 	{
 	{
 		specificity = Math::Max(specificity, (*i).second.specificity);
 		specificity = Math::Max(specificity, (*i).second.specificity);
 
 
-		// Check for the 'z-index' property; we don't want to send this through.
-		if ((*i).first == Z_INDEX)
-			z_index = (*i).second.value.Get< float >();
-		else
-			property_specification.ParsePropertyDeclaration(parsed_properties, (*i).first, (*i).second.value.Get< String >(), (*i).second.source, (*i).second.source_line_number);
+		property_specification.ParsePropertyDeclaration(parsed_properties, (*i).first, (*i).second.value.Get< String >(), (*i).second.source, (*i).second.source_line_number);
 	}
 	}
 
 
 	// Set the property defaults for all unset properties.
 	// Set the property defaults for all unset properties.
@@ -433,23 +429,23 @@ FontEffect* Factory::InstanceFontEffect(const String& name, const PropertyDictio
 		specificity = Math::Max(specificity, i->second.specificity);
 		specificity = Math::Max(specificity, i->second.specificity);
 
 
 		// Check for the 'z-index' property; we don't want to send this through.
 		// Check for the 'z-index' property; we don't want to send this through.
-		if (i->first == Z_INDEX)
-		{
-			set_z_index = true;
-			z_index = i->second.value.Get< float >();
-		}
-		else if (i->first == COLOR)
-		{
-			static PropertyParserColour colour_parser;
-
-			Property colour_property;
-			if (colour_parser.ParseValue(colour_property, i->second.value.Get< String >(), ParameterMap()))
-			{
-				colour = colour_property.value.Get< Colourb >();
-				set_colour = true;
-			}
-		}
-		else
+		//if (i->first == Z_INDEX)
+		//{
+		//	set_z_index = true;
+		//	z_index = i->second.value.Get< float >();
+		//}
+		//else if (i->first == COLOR)
+		//{
+		//	static PropertyParserColour colour_parser;
+
+		//	Property colour_property;
+		//	if (colour_parser.ParseValue(colour_property, i->second.value.Get< String >(), ParameterMap()))
+		//	{
+		//		colour = colour_property.value.Get< Colourb >();
+		//		set_colour = true;
+		//	}
+		//}
+		//else
 		{
 		{
 			property_specification.ParsePropertyDeclaration(parsed_properties, (*i).first, (*i).second.value.Get< String >(), (*i).second.source, (*i).second.source_line_number);
 			property_specification.ParsePropertyDeclaration(parsed_properties, (*i).first, (*i).second.value.Get< String >(), (*i).second.source, (*i).second.source_line_number);
 		}
 		}
@@ -460,7 +456,7 @@ FontEffect* Factory::InstanceFontEffect(const String& name, const PropertyDictio
 
 
 	// Compile an ordered list of the values of the properties used to generate the effect's
 	// Compile an ordered list of the values of the properties used to generate the effect's
 	// textures and geometry.
 	// textures and geometry.
-	typedef std::list< std::pair< String, String > > GenerationPropertyList;
+	typedef std::list< std::pair< PropertyId, String > > GenerationPropertyList;
 	GenerationPropertyList generation_properties;
 	GenerationPropertyList generation_properties;
 	for (PropertyMap::const_iterator i = parsed_properties.GetProperties().begin(); i != parsed_properties.GetProperties().end(); ++i)
 	for (PropertyMap::const_iterator i = parsed_properties.GetProperties().begin(); i != parsed_properties.GetProperties().end(); ++i)
 	{
 	{

+ 8 - 4
Source/Core/FontDatabase.cpp

@@ -190,13 +190,13 @@ FontEffect* FontDatabase::GetFontEffect(const String& name, const PropertyDictio
 	//  * could be shared with decorators as well
 	//  * could be shared with decorators as well
 
 
 	// Generate a key so we can distinguish unique property sets quickly.
 	// Generate a key so we can distinguish unique property sets quickly.
-	typedef std::list< std::pair< String, String > > PropertyList;
+	typedef std::list< std::pair< PropertyId, String > > PropertyList;
 	PropertyList sorted_properties;
 	PropertyList sorted_properties;
 	for (PropertyMap::const_iterator property_iterator = properties.GetProperties().begin(); property_iterator != properties.GetProperties().end(); ++property_iterator)
 	for (PropertyMap::const_iterator property_iterator = properties.GetProperties().begin(); property_iterator != properties.GetProperties().end(); ++property_iterator)
 	{
 	{
 		// Skip the font-effect declaration.
 		// Skip the font-effect declaration.
-		if (property_iterator->first == "font-effect")
-			continue;
+		//if (property_iterator->first == "font-effect")
+		//	continue;
 
 
 		PropertyList::iterator insert = sorted_properties.begin();
 		PropertyList::iterator insert = sorted_properties.begin();
 		while (insert != sorted_properties.end() &&
 		while (insert != sorted_properties.end() &&
@@ -208,8 +208,12 @@ FontEffect* FontDatabase::GetFontEffect(const String& name, const PropertyDictio
 
 
 	// Generate the font effect's key from the properties.
 	// Generate the font effect's key from the properties.
 	String key = name + ";";
 	String key = name + ";";
+	String str_id;
 	for (PropertyList::iterator i = sorted_properties.begin(); i != sorted_properties.end(); ++i)
 	for (PropertyList::iterator i = sorted_properties.begin(); i != sorted_properties.end(); ++i)
-		key += i->first + ":" + i->second + ";";
+	{
+		TypeConverter<int, String>::Convert((int)i->first, str_id);
+		key += str_id + ":" + i->second + ";";
+	}
 
 
 	// Check if we have a previously instanced effect.
 	// Check if we have a previously instanced effect.
 	FontEffectCache::iterator i = font_effect_cache.find(key);
 	FontEffectCache::iterator i = font_effect_cache.find(key);

+ 3 - 2
Source/Core/FontEffectInstancer.cpp

@@ -48,10 +48,11 @@ const PropertySpecification& FontEffectInstancer::GetPropertySpecification() con
 // Registers a property for the font effect.
 // Registers a property for the font effect.
 PropertyDefinition& FontEffectInstancer::RegisterProperty(const String& property_name, const String& default_value, bool affects_generation)
 PropertyDefinition& FontEffectInstancer::RegisterProperty(const String& property_name, const String& default_value, bool affects_generation)
 {
 {
+	PropertyDefinition& definition = properties.RegisterProperty(ToLower(property_name), default_value, false, false);
 	if (affects_generation)
 	if (affects_generation)
-		volatile_properties.insert(ToLower(property_name));
+		volatile_properties.insert(definition.GetId());
 
 
-	return properties.RegisterProperty(property_name, default_value, false, false);
+	return definition;
 }
 }
 
 
 // Registers a shorthand property definition.
 // Registers a shorthand property definition.

+ 1 - 1
Source/Core/PropertySpecification.cpp

@@ -355,7 +355,7 @@ void PropertySpecification::SetPropertyDefaults(PropertyDictionary& dictionary)
 {
 {
 	for (PropertyDefinition* property : properties)
 	for (PropertyDefinition* property : properties)
 	{
 	{
-		if (dictionary.GetProperty(property->GetId()) == NULL)
+		if (property && dictionary.GetProperty(property->GetId()) == NULL)
 			dictionary.SetProperty(property->GetId(), *property->GetDefaultValue());
 			dictionary.SetProperty(property->GetId(), *property->GetDefaultValue());
 	}
 	}
 }
 }