CS Code convertion: Difference between revisions

From PSwiki
Jump to navigation Jump to search
Line 19: Line 19:


csGetTicks() -> time(0)
csGetTicks() -> time(0)
csRandomGen -> FMath::FRandRange(low, high);
csPDelArray<PhonicEntry> -> TArray<PhonicEntry>;


=== Types conversion ===
=== Types conversion ===

Revision as of 16:32, 7 January 2017

Code convertion

Types

csString -> psString or FString

psStringArray with TArray<psString>

uint -> uint32

csHash<Value,Key> -> TMap<Key,Value> (notice the swap of Key and Value)

csArray<> -> TArray

csTicks -> time_t

csGetTicks() -> time(0)

csRandomGen -> FMath::FRandRange(low, high);

csPDelArray<PhonicEntry> -> TArray<PhonicEntry>;

Types conversion

FString to char* -> const char *myData = TCHAR_TO_ANSI(*NameString);

FString to TCHAR -> *myFString

char* to FString -> ANSI_TO_TCHAR(NameString);


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()

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:


  1. ifdef PLATFORM_WINDOWS

your stuff here

  1. endif