Jump to content

Bug Found In C# Wrapper: Vector3 Parse


Davaris
 Share

Recommended Posts

public override string ToString()
{
return string.Format("X:{0} Y:{1} Z:{2}", this.X, this.Y, this.Z);
}

public static Vector3 Parse(string value)
{
string[] values = value.Split(',');
return new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]));
}

 

The Parse function above is looking for ',' which doesn't exist. Here is the fix:

 

public static Vector3 Parse(string value)
{
char[] delimiterChars = { 'X', 'Y', 'Z', ':', ' ' };

string[] values = value.Value.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);

return new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]));
}                    

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

Although the Vector classes are currently being rewritten by Tyler, I doubt it was meant to be used this way.

 

A ToString is not necessarily an opposite to a Parse. Parse would Parse from the SBX in this comma separated way.

 

IF anything was to change, it would be the ToString, not the Parse.

 

Which would lead us to:

public override string ToString()
{
   return string.Format("{0},{1},{2}", this.X, this.Y, this.Z);
}

Link to comment
Share on other sites

We could have a FromString command that would take in the same format as is created with ToString, since it can be confusing, and them ofcourse have Parse to handle the actual engine-way of doing it.

 

The idea is that Parse is taking a working string, ToString is creating a super pretty string to use in message boxes, logs, etc. They are usually not the same, but we could accommodate both for both casting to and parsing from.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Why don't you do it like in gamelib, there you have as default separator whatever is in the current engine, and optionally you can specify as 2nd parameter a different separator.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

IF anything was to change, it would be the ToString, not the Parse.

 

Which would lead us to:

public override string ToString()
{
   return string.Format("{0},{1},{2}", this.X, this.Y, this.Z);
}

 

As long as it works in XML, that's fine by me. I am using what I assume is ToString to save and Parse when I'm loading.

 

This is how I'm using it:

 

// Saving

 

XElement entry_list = header.Element("Entries");

entry_list.Add(new XElement("Entry",
new XElement("Key", entry.Key),
new XElement("Value", entry.Value),
new XElement("Type", entry.Value.GetType().Name)));

 

// Loading

 

XElement key = x.Element("Key");
XElement value = x.Element("Value");
XElement type = x.Element("Type");

switch (type.Value)
{
case "String":
 mCurrSD.Put<string>(key.Value, (string)value.Value);
 break;
case "Boolean":
 mCurrSD.Put<bool>(key.Value, bool.Parse(value.Value));
 break;
case "Int32":
 mCurrSD.Put<int>(key.Value, int.Parse(value.Value));
 break;
case "Single":
 mCurrSD.Put<float>(key.Value, float.Parse(value.Value));
 break;
case "Vector3":
 mCurrSD.Put<Leadwerks.Vector3>(key.Value, Leadwerks.Vector3.Parse(value.Value));
 break;
}

Win 7 Pro 64 bit

AMD Phenom II X3 720 2.8GHz

GeForce 9800 GTX/9800 GTX+

4 GB RAM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...