bool InitEditorEngine() { guard; GMemory = new FStdMemDevice(); GLog = new FLog( L"EoverseEd.log" ); #if defined (_WIN32) SYSTEMTIME SystemTime = { 0 }; GetLocalTime( &SystemTime ); Logf( LOG_INIT, L"Log file created at %02i:%02i:%02i on %02i/%02i/%i", SystemTime.wHour + 1, SystemTime.wMinute + 1, SystemTime.wSecond + 1, SystemTime.wDay, SystemTime.wMonth, SystemTime.wYear ); #endif GConfig = new FConfig(); GConfig->LoadConfig(L"Eoverse.cfg"); GEngine = new FEditorEngine(); //This is so we can allocate stuff for C# to redundantly free so it doesn't crash ProcessMemory = new FWindowsMemDevice( GetProcessHeap() ); Logf( LOG_INIT, L"Successfully hooked into the .NET memory heap" ); return GEngine->Init(); unguard; }
// Upload the framebuffer for the current frame... should be called once a frame! void FrameBuffer(UInt64 timestamp, FrameBufferFormat format, UInt32 width, UInt32 height, const void *buffer) { if(TryLockConnection(Enable_FrameBuffer_Capture)) { UInt32 pixelSize = 0; switch(format) { case FrameBuffer_RGB_565: pixelSize=16; break; case FrameBuffer_RGBA_8888: pixelSize=32; break; case FrameBuffer_DXT1: pixelSize=4; if(width&3 || height&3) { Logf(Log_Warning, "OVR::Capture::FrameBuffer(): requires DXT1 texture dimensions to be multiples of 4"); return; } break; } if(!pixelSize) { Logf(Log_Warning, "OVR::Capture::FrameBuffer(): Format (%u) not supported!", (UInt32)format); return; } const UInt32 payloadSize = (pixelSize * width * height) >> 3; // pixelSize is in bits, divide by 8 to give us payload byte size FrameBufferPacket packet; packet.format = format; packet.width = width; packet.height = height; packet.timestamp = timestamp; // TODO: we should probably just send framebuffer packets directly over the network rather than // caching them due to their size and to reduce latency. AsyncStream::Acquire()->WritePacket(packet, buffer, payloadSize); UnlockConnection(); } }
size_t Inflate( uint8* In, uint8* Out, size_t InSize, size_t OutSize ) { z_stream ZLibStream; int r; ZLibStream.zalloc = Z_NULL; ZLibStream.zfree = Z_NULL; ZLibStream.opaque = Z_NULL; ZLibStream.avail_in = 0; ZLibStream.next_in = Z_NULL; if(inflateInit2( &ZLibStream, 15 ) != Z_OK) { Logf( LOG_ERR, L"inflateInit2() failed (error message: %s)", ZLibStream.msg ); return 0; } do { ZLibStream.avail_in = InSize; ZLibStream.next_in = In; ZLibStream.avail_out = OutSize; ZLibStream.next_out = Out; r = inflate( &ZLibStream, Z_NO_FLUSH ); if(r == Z_STREAM_ERROR) { Logf( LOG_ERR, L"inflate() returned Z_STREAM_ERROR (error message: %s)", ZLibStream.msg ); inflateEnd( &ZLibStream ); return 0; } switch(r) { case Z_NEED_DICT: { Logf( LOG_ERR, L"inflate() returned Z_NEED_DICT (error message: %s)", ZLibStream.msg ); inflateEnd( &ZLibStream ); return 0; } case Z_DATA_ERROR: { Logf( LOG_ERR, L"inflate() returned Z_DATA_ERROR (error message: %s)", ZLibStream.msg ); inflateEnd( &ZLibStream ); return 0; } case Z_MEM_ERROR: { Logf( LOG_ERR, L"inflate() returned Z_MEM_ERROR (error message: %s)", ZLibStream.msg ); inflateEnd( &ZLibStream ); return 0; } } } while(ZLibStream.avail_out == 0); inflateEnd( &ZLibStream ); return ZLibStream.total_out; }
bool FFolderPackage::LoadPackage( FStringConst& Path ) { Logf( LOG_ENGINE, L"Switching to folder package '%s'", Path.Data ); if(SetCurrentDirectory( Path.Data )) { //TODO: Index all assets in the specified path return true; } Logf( LOG_ERR, L"Folder '%s' does not exist", Path.Data ); return false; }
bool FEditorEngine::Exit() { Logf( LOG_EXIT, L"Shutting down" ); Instance->Exit(); //Clean up delete GConfig; Logf( LOG_EXIT, L"Configuration system closed" ); Logf( LOG_EXIT, L"%s shut down successfully", APP_NAME ); return true; }
int MicroHttpMain(int npar,char **par) { int i,Limit=1000000; if (npar==1) { printf("microHttp.exe -p[port] -r[rootDir] -d[debugLevel] -m[ext=mime[&..]]) -L[limitPPS:1000000]\n"); return 0; } for(i=1;i<npar;i++) { char *cmd = par[i]; if (*cmd=='-') cmd++; switch(*cmd) { case 'p': sscanf(cmd+1,"%d",&port); break; //case 'S': sscanf(cmd+1,"%d",&sleepTime); break; case 'd': sscanf(cmd+1,"%d",&logLevel); break; case 'k': sscanf(cmd+1,"%d",&keepAlive); break; case 'T': sscanf(cmd+1,"%d",&runTill); break; case 'L': sscanf(cmd+1,"%d",&Limit); break; case 'r': rootDir=cmd+1; break; case 'm': mimes = cmd+1; break; } } net_init(); TimeUpdate(); httpSrv *srv = httpSrvCreate(0); // New Instance, no ini srv->log = srv->srv.log = logOpen("microHttp.log"); // Create a logger srv->logLevel = srv->srv.logLevel = logLevel; srv->keepAlive=keepAlive; srv->readLimit.Limit = Limit; IFLOG(srv,0,"...starting microHttp {port:%d,logLevel:%d,rootDir:'%s',keepAlive:%d,Limit:%d},\n mimes:'%s'\n", port,logLevel,rootDir,keepAlive,Limit, mimes); //printf("...Creating a http server\n"); srv->defmime= vssCreate("text/plain;charset=windows-1251",-1); httpSrvAddMimes(srv,mimes); //httpMime *m = httpSrvGetMime(srv,vssCreate("1.HHtm",-1));printf("Mime here %*.*s\n",VSS(m->mime)); //httpSrvAddFS(srv,"/c/","c:/",0); // Adding some FS mappings httpSrvAddFS(srv,"/",rootDir,0); // Adding some FS mappings httpSrvAddMap(srv, strNew("/.stat",-1), onHttpStat, 0); if (httpSrvListen(srv,port)<=0) { // Starts listen port Logf("-FAIL start listener on port %d\n",port); return 1; } Logf(".. listener is ready, Ctrl+C to abort\n"); if (runTill) srv->runTill = TimeNow + runTill; httpSrvProcess(srv); // Run All messages till CtrlC... TimeUpdate(); IFLOG(srv,0,"...stop microHttp, done:{connects:%d,requests:%d,runtime:%d}\n", srv->srv.connects,srv->srv.requests,TimeNow - srv->created); return 0; }
bool FEditorViewport::Construct( FClient* InOwner, FRenderDevice* InRender, FAudioDevice* InAudio, void* Parent, uint32 Width, uint32 Height ) { guard; Owner = InOwner; Render = InRender; Res.X = Width; Res.Y = Height; if (Parent == nullptr) { Throw( L"NULL parent not allowed for FEditorViewport", false ); } Props.WindowHandle = (HWND)Parent; if (Context = Render->CreateContext( this, Width, Height )) { return true; } else { Logf( LOG_EDITOR, L"Editor viewport construction failed." ); } unguard; }
void FZipPackage::LoadAsset( FZipAsset* Asset ) { guard; Seek( Asset->Location, Begin ); Asset->Ptr = new uint8[Asset->Size]; switch (Asset->CompressType) { case 0: { //No compression Read( Asset->Ptr, Asset->Size ); break; } case 8: { //Deflate uint8* CompressData = new uint8[Asset->CompressSize]; Read( CompressData, Asset->CompressSize ); Inflate( CompressData, Asset->Ptr, Asset->CompressSize, Asset->Size ); if (Asset->Type == AT_Text || Asset->Type == AT_Script) { //Null terminate the data if it has formatted text Asset->Ptr[Asset->Size] = 0; } break; } default: { Logf( LOG_ERR, L"Asset '%s' is compressed with an unknown method.", Asset->Name ); } } unguard; }
bool JobSheduler::Queue(Job job) { // Can't queue jobs twice if(job->IsQueued()) { Logf("Tried to register a job twice", Logger::Warning); return false; } // Can't queue finished jobs if(job->IsFinished()) { Logf("Tried to register a finished job", Logger::Warning); return false; } return m_impl->QueueUnchecked(job); }
virtual void OnKeyPressed(Key key) { if(key == Key::ArrowDown) { m_selectionWheel->AdvanceSelection(1); } else if(key == Key::ArrowUp) { m_selectionWheel->AdvanceSelection(-1); } else if(key == Key::PageDown) { m_selectionWheel->AdvanceSelection(5); } else if(key == Key::PageUp) { m_selectionWheel->AdvanceSelection(-5); } else if(key == Key::ArrowLeft) { m_selectionWheel->AdvanceDifficultySelection(-1); } else if(key == Key::ArrowRight) { m_selectionWheel->AdvanceDifficultySelection(1); } else if(key == Key::Return) { bool autoplay = (g_gameWindow->GetModifierKeys() & ModifierKeys::Ctrl) == ModifierKeys::Ctrl; MapIndex* map = m_selectionWheel->GetSelection(); if(map) { DifficultyIndex* diff = m_selectionWheel->GetSelectedDifficulty(); Game* game = Game::Create(diff->path); if(!game) { Logf("Failed to start game", Logger::Error); return; } game->GetScoring().autoplay = autoplay; // Transition to game TransitionScreen* transistion = TransitionScreen::Create(game); g_application->AddTickable(transistion); } } else if(key == Key::F5) { m_mapDatabase.StartSearching(); } else if(key == Key::F2) { m_selectionWheel->SelectRandom(); } }
void Log::LogPrintf(std::string str, ...) { char Buffer[2048]; va_list vl; va_start(vl, str); vsnprintf(Buffer, 2048, str.c_str(), vl); va_end(vl); Printf(Buffer); Logf(Buffer); }
bool FOpenGL3Context::Construct( FViewport* InOwner, uint32 Width, uint32 Height ) { guard; Owner = InOwner; Res.X = Width; Res.Y = Height; #if defined (_WIN32) if ((GLWndProps.hDC = GetDC( Owner->GetWindowProps().WindowHandle )) == NULL) { Throw( L"OpenGL3 Error : GetDC() returned NULL", true ); return false; } GLWndProps.PFD = { sizeof( PIXELFORMATDESCRIPTOR ), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0,0,0,0,0,0,0,0,0,0,0,0,0, 32, 0,0,0,0,0,0,0 }; GLWndProps.PixelFormat = ChoosePixelFormat( GLWndProps.hDC, &GLWndProps.PFD ); SetPixelFormat( GLWndProps.hDC, GLWndProps.PixelFormat, &GLWndProps.PFD ); if ((GLWndProps.hRC = wglCreateContext( GLWndProps.hDC )) == NULL) { Throw( L"OpenGL3 Error : wglCreateContext() returned NULL", true ); return false; } wglMakeCurrent( GLWndProps.hDC, GLWndProps.hRC ); OnSize( Width, Height ); #endif if (glewInit() != GLEW_OK) { Throw( L"glewInit() failed.", true ); } if (!GLEW_VERSION_3_3) { Throw( L"Minimum version of OpenGL 3.3 is not supported", true ); } Logf( LOG_ENGINE, L"OpenGL 3.x viewport constructed" ); return true; unguard; }
bool UiSystem::InitializeResources() { mUiResources = std::make_unique<UiResources>(GfxRenderDevice::Instance(), FileSystem::Instance()); if (!mUiResources->InitializeWithConfiguration("Configurations/Ui.json")) { Logf("Warning: Cannot load ui configuration"); return false; } return true; }
/** * Closes output device and cleans up. This can't happen in the destructor * as we have to call "delete" which cannot be done for static/ global * objects. */ void FOutputDeviceFile::TearDown() { if( LogAr ) { if (!bSuppressEventTag) { Logf( TEXT("Log file closed, %s"), FPlatformTime::StrTimestamp() ); } delete LogAr; LogAr = NULL; } }
void FFolderPackage::SavePackage( FStringConst& Path ) { Logf( LOG_ENGINE, L"Saving package to '%s'", Path.Data ); FAsset* Asset; for(uint64 i = 0; i < Assets.GetSize(); i++) { Asset = Assets[i]; if(Asset->Ptr != nullptr) { Open( Asset->Path->Data, WriteOnly, Create ); Write( Asset->Ptr, Asset->Size ); Close(); } } }
//TODO: Multi-thread this void FZipPackage::LoadAsset( FStringConst& Path ) { guard; //Check that the asset exists FZipAsset* Asset = (FZipAsset*)FindAsset( Path ); if(!Asset) { FString Err = FString( L"Asset '" ) + Path.Data + FString( L"' could not be read." ); Throw( (wchar_t*)Err.Data, false ); } Seek( Asset->Location, Begin ); Asset->Ptr = new uint8[Asset->Size]; switch (Asset->CompressType) { case 0: { //No compression Read( Asset->Ptr, Asset->Size ); break; } case 8: { //Deflate uint8* CompressData = new uint8[Asset->CompressSize]; Read( CompressData, Asset->CompressSize ); Inflate( CompressData, Asset->Ptr, Asset->CompressSize, Asset->Size ); if(Asset->Type == AT_Text || Asset->Type == AT_Script) { //Null terminate the data if it has formatted text Asset->Ptr[Asset->Size] = 0; } break; } default: { Logf( LOG_ERR, L"Asset '%s' is compressed with an unknown method.", Asset->Name ); } } unguard; }
void ClientConnection::_threadEntry() { try { while (_continueRunning) { auto txn = _getTransaction(); auto result = _db->processTransaction(txn); _sendResult(result); } } catch(std::exception &e) { if (_continueRunning) { Logf(kLogLevelDebug, e.what()); } } // this thread needs to finish before the client can destruct. Kill the client from the service thread. _service.post([=]() { _db->removeClient(shared_from_this()); }); }
Datastore::Datastore(std::istream& in) { try { auto pos = in.tellg(); in.seekg(0, in.end); if (in.tellg() - pos == 0) { // empty input stream return; } in.seekg(pos); DatastoreInputArchiveType iarch(in); iarch >> _root; } catch (std::exception& e) { Logf(kLogLevelInfo, "unable to parse datastore input stream"); _good = false; } }
bool GfxReadAnimationDescFrom(const JsonElement& jsonSource, GfxAnimationDesc& animationDesc) { assert(!!jsonSource); if (!jsonSource) { return false; } animationDesc = {}; if (!jsonSource.GetElementName(animationDesc.animationName)) { Logf("Warning: cannot find animation name"); return false; } // parse common animation propertices animationDesc.animationDuration = JsonGet(jsonSource, "duration", 0.0f); animationDesc.spriteSheetImageName = JsonGet(jsonSource, "sprite_sheet", ""); animationDesc.directionCount = JsonGet(jsonSource, "direction_count", 0); // read frame size std::vector<int32_t> intArray; JsonReadArray(jsonSource.FindElement("frame_size"), intArray); if (intArray.size() > 1) { animationDesc.frameWidth = intArray[0]; animationDesc.frameHeight = intArray[1]; } // read frame indices JsonReadArray(jsonSource.FindElement("frames"), intArray); animationDesc.frameCount = intArray.size(); if (animationDesc.frameCount > MAX_ANIMATION_FRAME_COUNT) animationDesc.frameCount = MAX_ANIMATION_FRAME_COUNT; for (int32_t iframe = 0; iframe < animationDesc.frameCount; ++iframe) { animationDesc.frameIndices[iframe] = intArray[iframe]; } return true; }
// When a map is selected in the song wheel void OnMapSelected(MapIndex* map) { if(map == m_currentPreviewAudio) return; // Set current preview audio DifficultyIndex* previewDiff = map->difficulties[0]; String audioPath = map->path + Path::sep + previewDiff->settings.audioNoFX; AudioStream previewAudio = g_audio->CreateStream(audioPath); if(previewAudio) { previewAudio->SetPosition(previewDiff->settings.previewOffset); m_previewPlayer.FadeTo(previewAudio); } else { Logf("Failed to load preview audio from [%s]", Logger::Warning, audioPath); m_previewPlayer.FadeTo(AudioStream()); } m_currentPreviewAudio = map; }
int main( int argc, char** argv ) { guard; //InitSignalHandler(); //Create the base memory device GMemory = new FStdMemDevice(); GTempMemory = new FLinearMemDevice(); //Initialize logging GLog = new FLog(L"EoverseEngine.log"); #if defined (_WIN32) SYSTEMTIME SystemTime = { 0 }; GetLocalTime( &SystemTime ); Logf( LOG_INIT, L"Log file created at %02i:%02i:%02i on %02i/%02i/%i", SystemTime.wHour + 1, SystemTime.wMinute + 1, SystemTime.wSecond + 1, SystemTime.wDay, SystemTime.wMonth, SystemTime.wYear ); #endif //Load the config in GConfig = new FConfig(); GConfig->LoadConfig(); //Create the engine class GEngine = new FGameEngine(argc, argv); GEngine->Init(); //Engine loop GEngine->MainLoop(); //Should the engine loop exit, close the application GEngine->Exit(); return 0; unguard; }
bool InitEditorEngine() { guard; GMemory = new FStdMemDevice(); GLog = new FLog( L"EoverseEd.log" ); #if defined (_WIN32) SYSTEMTIME SystemTime = { 0 }; GetLocalTime( &SystemTime ); Logf( LOG_INIT, L"Log file created at %02i:%02i:%02i on %02i/%02i/%i", SystemTime.wHour + 1, SystemTime.wMinute + 1, SystemTime.wSecond + 1, SystemTime.wDay, SystemTime.wMonth, SystemTime.wYear ); #endif GConfig = new FConfig(); GConfig->LoadConfig(L"Eoverse.cfg"); GEngine = new FEditorEngine(); return GEngine->Init(); unguard; }
bool FEditorEngine::Init() { guard; RegisterWindowClasses(); Instance = new FInstance( this ); Instance->Init(); RenderPlugin = new FPlugin(); RenderPlugin->LoadPlugin( GConfig->ReadString( L"RenderDevice" ) ); if (!RenderPlugin->LoadInterface()) { Logf( LOG_CRIT, L"Cannot load DeviceInterfacePtr() in render plugin '%s", RenderPlugin->GetFilepath() ); Throw( L"Cannot load DeviceInterfacePtr() in render plugin", true ); } Render = (FRenderDevice*)(RenderPlugin->GetInterface())(); Render->Init(); return true; unguard; }
void Datastore::removeRecord(const std::string& path) { auto tokens = _tokenizePath(path); if (tokens.empty()) { return; } // invalid path auto records = _recordsOnPath(tokens); if (records.empty()) { return; } if (!records.back()) { return; } // records array now has no null pointers // records and tokens correlate 1:1. // _root -> records[0] -> records[1] -> ... // tokens[0] -> tokens[1] -> ... // The associations between parent and child are named. // The names are the tokens. records.pop_back(); Record* parent = records.empty() ? &_root : records.back(); parent->removeChild(tokens.back().c_str()); tokens.pop_back(); try { while (tokens.size() > 0) { if (parent->numChildren() == 0) { records.pop_back(); parent = records.empty() ? &_root : records.back(); parent->removeChild(tokens.back().c_str()); tokens.pop_back(); } else { break; } } } catch (std::exception& e) { Logf("%s", e.what()); } }
TEST(Logging, Logging__LogF_Enabled) { Log_SetEnable(1); Logf("Test", "Module"); TEST_ASSERT_NOT_EQUAL(0, strlen(LogBuffer)); }
TEST(Logging, Logging__LogF_Module_MSG) { Logf("Test", "Module"); TEST_ASSERT_NOT_EQUAL(0, strlen(LogBuffer)); }
TEST(Logging, Logging__LogF_NULL_Module_MSG) { Logf(NULL, "Msg"); TEST_ASSERT_NOT_EQUAL(0, strlen(LogBuffer)); }
/** * Serializes the passed in data unless the current event is suppressed. * * @param Data Text to log * @param Event Event name used for suppression purposes */ void FOutputDeviceFile::Serialize( const TCHAR* Data, ELogVerbosity::Type Verbosity, const class FName& Category, const double Time ) { #if ALLOW_LOG_FILE && !NO_LOGGING static bool Entry=false; if( !GIsCriticalError || Entry ) { if( !LogAr && !Dead ) { // Make log filename. if( !Filename[0] ) { FCString::Strcpy(Filename, *FPlatformOutputDevices::GetAbsoluteLogFilename()); } // if the file already exists, create a backup as we are going to overwrite it if (!bDisableBackup && !Opened) { CreateBackupCopy(Filename); } // Open log file. LogAr = CreateArchive(); if( LogAr ) { Opened = 1; WriteByteOrderMarkToArchive(EByteOrderMark::UTF8); if (!bSuppressEventTag) { Logf( TEXT("Log file open, %s"), FPlatformTime::StrTimestamp() ); } } else { Dead = true; } } if( LogAr && Verbosity != ELogVerbosity::SetColor ) { WriteDataToArchive(Data, Verbosity, Category, Time); static bool GForceLogFlush = false; static bool GTestedCmdLine = false; if (!GTestedCmdLine) { GTestedCmdLine = true; // Force a log flush after each line GForceLogFlush = FParse::Param( FCommandLine::Get(), TEXT("FORCELOGFLUSH") ); } if( GForceLogFlush ) { LogAr->Flush(); } } } else { Entry=true; Serialize( Data, Verbosity, Category, Time ); Entry=false; } #endif }
void FZipPackage::ClosePackage() { Logf( LOG_ENGINE, L"Releasing package '%s'", Filepath.Data ); }
void FFolderPackage::ClosePackage() { Logf( LOG_ENGINE, L"Switching back to original working directory." ); SetCurrentDirectory( GEngine->GetPath().Data ); }