CS Code convertion
Code convertion
Types
csString -> psString or FString
psStringArray with TArray<psString>
uint -> uint32
uint32_t -> #include <stdint.h>
csHash<Value,Key> -> TMap<Key,Value> (notice the swap of Key and Value)
csArray<> -> TArray
csTicks -> time_t
csGetTicks() -> time(0) Need to #include <ctime>
csRandomGen -> FMath::FRandRange(low, high);
csPDelArray<PhonicEntry> -> TArray<PhonicEntry>;
csVector3 -> FVector
Types conversion
FString to char* -> const char *myData = TCHAR_TO_ANSI(*NameString);
FString to TCHAR -> *myFString
char* to FString -> ANSI_TO_TCHAR(NameString);
XML parsing
- include "XmlParser.h"
iDocumentNode -> FXmlNode
csRef<iDocument> doc=xml->CreateDocument(); const char* error =doc->Parse(buff);
becomes
FXmlFile File(FPaths::GameDir() + FString(PHONICS_LIST)); FXmlNode* root = File.GetRootNode();
csString skillName = tmp->GetAttributeValue("name"); -> tmp->GetAttribute(TEXT("name"));
float value = children[i]->GetAttributeValueAsFloat("value"); -> float value = FCString::Atof(*children[i]->GetAttribute("value"));
int cstr_id_material = node->GetAttributeValueAsInt( "mesh" ); -> int cstr_id_material = FCString::Atoi(*node->GetAttribute("mesh"));
Functions
Replace string.Format("hey %s", string) with string.Printf(TEXT("hey %s"), string)
csString.Truncate(5) -> FString.Left(5)
csString.DeleteAt(start,count) -> FString.RemoveAt(start,count)
csString.Downcase() -> FString.ToLower()
csString.Length() -> Len()
csString.Clear() -> Empty()
csString.GetAt(0) -> [0]
csString.GetData() -> TCHAR_TO_ANSI(*mystring)
csPDelArray.GetSize() -> TArray.Num()
output.Insert(0, time_buffer) -> output.InsertAt(0, time_buffer)
output.GetAt(output.Length()-1) -> output [ output.Len()-1 ]
Cross platform types are defined in Platform.h , like uint32. Those can be included with #include "EngineMinimal.h"
CS_ASSERT() -> check()
strcasecmp and strcmp, I added those two defines, so the code can stay as it is
#define strcasecmp(expr1,expr2) FCString::Strcmp( ANSI_TO_TCHAR(expr1), ANSI_TO_TCHAR(expr2)) == 0 #define strcmp(expr1,expr2) FCString::Stricmp( ANSI_TO_TCHAR(expr1), ANSI_TO_TCHAR(expr2)) == 0
CPrintf(CON_CMDOUTPUT,str.GetDataSafe()); -> UE_LOG(LogTemp, Warning, TEXT("%s"), str);
time(NULL) -> FString buf = FDateTime().GetDate().ToString();
FText and Localization
FText is Unreal's class for user viewable strings. It is localizable. See https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/StringHandling/FText/index.html
Platform specific includes
If you want to include some code for a specific platform you can use:
- ifdef PLATFORM_WINDOWS
your stuff here
- endif