Skip to content

Instantly share code, notes, and snippets.

View dorgonman's full-sized avatar
☯️
inner peace

dorgon chang dorgonman

☯️
inner peace
View GitHub Profile
@dorgonman
dorgonman / HorizonLog_windows.cpp
Created September 27, 2015 02:49
Horizon-WindowsLogImplement
#include "precompile/precompiled.h"
#include "HorizonLog.h"
#include <Windows.h>
#include <tchar.h>
namespace horizon{
void logMessageImplementInternal(const std::string& msg){
WCHAR wszBuf[HORIZON_LOG_MAX_LEN] = { 0 };
MultiByteToWideChar(CP_UTF8, 0, msg.c_str(), -1, wszBuf, sizeof(wszBuf));
OutputDebugStringW(wszBuf);
@dorgonman
dorgonman / gist:fdab8f1be4a11a4a4fbc
Last active March 26, 2016 14:26
HorizonCore::initDefaultLog
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
void HorizonCore::initDefaultLog(const std::string& fileLogFullPath,
horizon::HorizonLogImpFunc_t&& logFunc,
boost::log::trivial::severity_level logFilterLevel,
boost::log::trivial::severity_level fileLogFilterLevel){
@dorgonman
dorgonman / gist:aa3bcb24ba275ce9acc6
Last active March 26, 2016 14:27
HorizonLogBasicFormatedBackend
class HorizonLogBasicFormatedBackend : public boost::log::sinks::basic_formatted_sink_backend < char > {
public:
void consume(const boost::log::record_view& rec, string_type const& msg);
inline void setLogMessageImplemen(HorizonLogImpFunc_t&& impl) { logMessageImplement = std::move(impl); };
private:
void logMessage(const boost::log::record_view& rec, const std::string& msg);
private:
HorizonLogImpFunc_t logMessageImplement;
};
#define HORIZON_LOG_BUFFER_LEN 4*1024 //4KB
using HorizonLogImpFunc_t = std::function<void(const std::string&)>;
class HorizonLogBasicFormatedBackend : public boost::log::sinks::basic_formatted_sink_backend < char > {
public:
void consume(const boost::log::record_view& rec, string_type const& msg);
inline void setLogMessageImplemen(HorizonLogImpFunc_t&& impl) { logMessageImplement = std::move(impl); };
private:
void logMessage(const boost::log::record_view& rec, const std::string& msg);
private:
HorizonLogImpFunc_t logMessageImplement;
@dorgonman
dorgonman / gist:0db4138c2cee95b51582
Last active March 26, 2016 14:26
UE4_plus_horizon_log.init
void logMessageImplement(const std::string& msg) {
FString str = UTF8_TO_TCHAR(msg.c_str());
UE_LOG(LogTemp, Log, TEXT("%s"), *str);
// FPlatformMisc::LowLevelOutputDebugString(TEXT("HorizonLogBasicBackend test"));
//FPlatformMisc::LowLevelOutputDebugString(UTF8_TO_TCHAR(msg.c_str()));
}
FString savedPath = FPaths::ConvertRelativePathToFull(FPaths::GameLogDir());
std::string logFilePath = std::string(TCHAR_TO_UTF8(*savedPath)) + "HorizonLog.txt";
@dorgonman
dorgonman / gist:575f2e4a3c78621bcff8
Last active March 26, 2016 14:26
usage_horizon_log
static class HorizonDevNull
{
} horizon_dev_null;
//BOOST_LOG_FUNCTION()
//BOOST_LOG_FUNCTION()
#define HORIZON_LOG_FUNCTION " [" << __FILE__ << "(" << __LINE__ << ")" << ": " << BOOST_CURRENT_FUNCTION << "] "
#if defined(NDEBUG) || defined(_NDEBUG)
@dorgonman
dorgonman / gist:cbfe159a83ba07f1c66e
Last active May 30, 2016 03:05
UnrealEngine 4: dynamic load UMG from c++
// Fill out your copyright notice in the Description page of Project Settings.
UCLASS()
class HOPETOWERDEFENSE_API AHopePlayerController : public APlayerController
{
//GENERATED_BODY()
GENERATED_UCLASS_BODY()
public:
//AHopePlayerController(const FObjectInitializer& ObjectInitializer);
#if PLATFORM_WINDOWS
#include "windows/WindowsWindow.h"
#include "SharedPointer.h"
#endif //PLATFORM_WINDOWS
#include "AllowWindowsPlatformTypes.h"
void AHopePlayerController::AdjustWindow() {
AMyPlayerController::AMyPlayerController()
{
ConstructorHelpers::FClassFinder<UUserWidget> PutNameHere(TEXT("/Game/UMG/NewWidgetBlueprint"));
if (PutNameHere.Class) {
UserWidgetClass = PutNameHere.Class;
}
}
void AMyPlayerController::BeginPlay()
{
{
FStringAssetReference testAssetRef = "/Game/UMG/NewWidgetBlueprint";
UObject* pObject = testAssetRef.TryLoad();
UWidgetBlueprint* pWidgetBlueprint = Cast<UWidgetBlueprint>(pObject);
auto widget = CreateWidget<UUserWidget>(this, pWidgetBlueprint->GeneratedClass);
// do something
//widget->AddToViewport();
FString pathName1 = FPackageName::LongPackageNameToFilename(pObject->GetPathName(), FPackageName::GetAssetPackageExtension());
FString pathName2 = FPackageName::LongPackageNameToFilename(pObject->GetOutermost()->GetPathName(), FPackageName::GetAssetPackageExtension());
}