MCPcopy Create free account
hub / github.com/devosoft/avida / LoadGradientResource

Method LoadGradientResource

avida-core/source/main/cEnvironment.cc:831–1039  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

829}
830
831bool cEnvironment::LoadGradientResource(cString desc, Feedback& feedback)
832{
833 if (desc.GetSize() == 0) {
834 feedback.Error("gradient resource line with no resources listed");
835 return false;
836 }
837
838 while (desc.GetSize() > 0) {
839 cString cur_resource = desc.PopWord();
840 const cString name = cur_resource.Pop(':');
841
842 /* If resource does not already exist create it, however if it already
843 exists (for instance was created as a cell resource) return an error*/
844
845 cResource* new_resource;
846 if (!resource_lib.DoesResourceExist(name)) {
847 new_resource = resource_lib.AddResource(name);
848 } else {
849 new_resource = resource_lib.GetResource(name);
850 }
851
852 new_resource->SetGeometry("grid");
853 new_resource->SetInitial(0.0);
854 new_resource->SetOutflow(1.0);
855 new_resource->SetXDiffuse(0.0);
856 new_resource->SetYDiffuse(0.0);
857 new_resource->SetXGravity(0.0);
858 new_resource->SetYGravity(0.0);
859 new_resource->SetGradient(true);
860
861 while (cur_resource.GetSize() != 0) {
862 cString var_entry = cur_resource.Pop(':');
863 cString var_name;
864 cString var_value;
865 const cString var_type = cStringUtil::Stringf("gradient resource '%s'", static_cast<const char*>(name));
866 // Parse this entry.
867 if (!ParseSetting(var_entry, var_name, var_value, var_type, feedback)) {
868 return false;
869 }
870
871 if (var_name == "peakx") {
872 if (!AssertInputInt(var_value, "peakx", var_type, feedback)) return false;
873 new_resource->SetPeakX( var_value.AsInt() );
874 }
875 else if (var_name == "peaky") {
876 if (!AssertInputInt(var_value, "peaky", var_type, feedback)) return false;
877 new_resource->SetPeakY( var_value.AsInt() );
878 }
879 else if (var_name == "height") {
880 if (!AssertInputInt(var_value, "height", var_type, feedback)) return false;
881 new_resource->SetHeight( var_value.AsInt() );
882 }
883 else if (var_name == "spread") {
884 if (!AssertInputInt(var_value, "spread", var_type, feedback)) return false;
885 new_resource->SetSpread( var_value.AsInt() );
886 }
887 else if (var_name == "plateau") {
888 if (!AssertInputDouble(var_value, "plateau", var_type, feedback)) return false;

Callers

nothing calls this directly

Calls 15

PopWordMethod · 0.80
DoesResourceExistMethod · 0.80
AddResourceMethod · 0.80
SetXDiffuseMethod · 0.80
SetYDiffuseMethod · 0.80
SetXGravityMethod · 0.80
SetYGravityMethod · 0.80
SetGradientMethod · 0.80
SetPeakXMethod · 0.80
SetPeakYMethod · 0.80
SetHeightMethod · 0.80
SetSpreadMethod · 0.80

Tested by

no test coverage detected