void GetWindowText(HWindow *pwnd, SimpleString &str) { int len = pwnd->GetWindowTextLength() + 1; str.SetSize(len); pwnd->GetWindowTextA(str, len); }
bool SimpleString::containsNoCase(const SimpleString& other) const { return toLower().contains(other.toLower()); }
bool SimpleString::equalsNoCase(const SimpleString& str) const { return toLower() == str.toLower(); }
bool easyunit::operator== (const SimpleString& left, const SimpleString& right) { return !strcmp (left.asCharString (), right.asCharString ()); }
bool operator==(const SimpleString& left, const SimpleString& right) { return 0 == SimpleString::StrCmp(left.asCharString(), right.asCharString()); }
ContainsFailure::ContainsFailure(UtestShell* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual) : TestFailure(test, fileName, lineNumber) { message_ = StringFromFormat("actual <%s>\n\tdid not contain <%s>", actual.asCharString(), expected.asCharString()); }
bool TestFilter::match(const SimpleString& name) const { if (strictMatching_) return name == filter_; return name.contains(filter_); }
void UtestShell::print(const SimpleString& text, const char* fileName, int lineNumber) { print(text.asCharString(), fileName, lineNumber); }
/*virtual*/ void EldritchFramework::Initialize() { XTRACE_FUNCTION; XTRACE_BEGIN(PreFramework3D); ReverseHash::Initialize(); PackStream::StaticAddPackageFile("eldritch-base.cpk"); FrameworkUtil::MinimalLoadConfigFiles("Config/default.ccf"); InitializePackages(); InitializeDLC(); // Load prefs over anything in the defaults. LoadPrefsConfig(); LOADPRINTLEVELS; STATICHASH(Version); STATICHASH(ContentSyncer); SimpleString LocalVersion = ConfigManager::GetString(sVersion, "", sContentSyncer); PRINTF("Version: %s\n", LocalVersion.CStr()); XTRACE_BEGIN(InitializeFactories); PRINTF("Initializing factories...\n"); PRINTF("Initializing SDP factories.\n"); SDPFactory::InitializeBaseFactories(); #define ADDSDPFACTORY(type) \ SDPFactory::RegisterSDPFactory(#type, SDP##type::Factory); #include "eldritchsdps.h" #undef ADDSDPFACTORY PRINTF("Initializing UI factories.\n"); UIFactory::InitializeBaseFactories(); #define ADDUISCREENFACTORY(type) \ UIFactory::RegisterUIScreenFactory(#type, UIScreen##type::Factory); #include "eldritchuiscreens.h" #undef ADDUISCREENFACTORY PRINTF("Initializing anim event factories.\n"); #define ADDANIMEVENTFACTORY(type) \ AnimEventFactory::GetInstance()->Register(#type, AnimEvent##type::Factory); #include "eldritchanimevents.h" #undef ADDANIMEVENTFACTORY PRINTF("Initializing PE factories.\n"); WBParamEvaluatorFactory::InitializeBaseFactories(); #define ADDWBPEFACTORY(type) \ WBParamEvaluatorFactory::RegisterFactory(#type, WBPE##type::Factory); #include "rodinwbpes.h" #include "eldritchwbpes.h" #undef ADDWBPEFACTORY PRINTF("Initializing action factories.\n"); WBActionFactory::InitializeBaseFactories(); #define ADDWBACTIONFACTORY(type) \ WBActionFactory::RegisterFactory(#type, WBAction##type::Factory); #include "uiwbactions.h" #include "rodinwbactions.h" #include "eldritchwbactions.h" #undef ADDWBPEFACTORY PRINTF("Initializing BT factories.\n"); RodinBTNodeFactory::InitializeBaseFactories(); #define ADDRODINBTNODEFACTORY(type) \ RodinBTNodeFactory::RegisterFactory(#type, RodinBTNode##type::Factory); #include "eldritchrodinbtnodes.h" #undef ADDRODINBTNODEFACTORY // Initialize core and Eldritch Workbench component factories. PRINTF("Initializing component factories.\n"); WBComponent::InitializeBaseFactories(); #define ADDWBCOMPONENT(type) \ WBComponent::RegisterWBCompFactory(#type, WBComp##type::Factory); #include "rodinwbcomponents.h" #include "eldritchwbcomponents.h" #undef ADDWBCOMPONENT XTRACE_END; PRINTF("Factories initialized.\n"); // Create input system before framework so it will exist for UI. But don't // attach devices yet, as they don't exist. PRINTF("Initializing input system.\n"); m_InputSystem = new InputSystem; m_InputSystem->Initialize("EldritchInput"); XTRACE_END; Framework3D::Initialize(); STATICHASH(DisplayWidth); STATICHASH(DisplayHeight); m_DisplayWidth = ConfigManager::GetInt(sDisplayWidth); m_DisplayHeight = ConfigManager::GetInt(sDisplayHeight); #if BUILD_WINDOWS m_CheckForUpdates = new CheckForUpdates(m_UIManager); #endif m_Controller = new XInputController; m_TargetManager = new EldritchTargetManager(m_Renderer); m_TargetManager->CreateTargets(m_Display->m_Width, m_Display->m_Height); m_Audio3DListener = new EldritchSound3DListener; m_Audio3DListener->Initialize(); ASSERT(m_AudioSystem); m_AudioSystem->Set3DListener(m_Audio3DListener); STATICHASH(FOV); const float FOV = ConfigManager::GetFloat(sFOV, 90.0f); STATICHASH(ForegroundFOV); const float FGFOV = ConfigManager::GetFloat(sForegroundFOV, 60.0f); STATICHASH(NearClip); const float NearClip = ConfigManager::GetFloat(sNearClip, 0.1f); STATICHASH(FarClip); const float FarClip = ConfigManager::GetFloat(sFarClip, 0.1f); const float fDisplayWidth = static_cast<float>(m_DisplayWidth); const float fDisplayHeight = static_cast<float>(m_DisplayHeight); const float AspectRatio = fDisplayWidth / fDisplayHeight; m_MainView = new View(Vector(), Angles(), FOV, AspectRatio, NearClip, FarClip); m_FGView = new View(Vector(), Angles(), FGFOV, AspectRatio, NearClip, FarClip); CreateHUDView(); CreateMirrorView(); CreateMinimapView(); CreateBuckets(); m_InputSystem->SetKeyboard(m_Keyboard); m_InputSystem->SetMouse(m_Mouse); m_InputSystem->SetController(m_Controller); m_InputSystem->SetClock(m_Clock); WBActionStack::Initialize(); PRINTF("Initializing Eldritch.\n"); InitializeWorld(HashedString(), false); m_Game = new EldritchGame; m_Game->RefreshRTDependentSystems(); m_Game->Initialize(); // Initialize config stuff { STATICHASH(InvertY); const bool InvertY = ConfigManager::GetBool(sInvertY); STATIC_HASHED_STRING(TurnY); m_InputSystem->SetMouseInvert(sTurnY, InvertY); m_InputSystem->SetControllerInvert(sTurnY, InvertY); STATICHASH(ControllerPower); const float ControllerPower = ConfigManager::GetFloat(sControllerPower); STATIC_HASHED_STRING(MoveX); m_InputSystem->SetControllerPower(sMoveX, ControllerPower); STATIC_HASHED_STRING(MoveY); m_InputSystem->SetControllerPower(sMoveY, ControllerPower); STATIC_HASHED_STRING(TurnX); m_InputSystem->SetControllerPower(sTurnX, ControllerPower); m_InputSystem->SetControllerPower(sTurnY, ControllerPower); } // Initialize UI sliders. This could be neater. // This also pushes the initial values to their respective systems, which is // pret-ty terrible design. { WBEventManager* pEventManager = WBWorld::GetInstance()->GetEventManager(); { STATICHASH(MouseSpeed); const float MouseSpeed = ConfigManager::GetFloat(sMouseSpeed, 1.0f); STATIC_HASHED_STRING(ControlsOptionsScreen); STATIC_HASHED_STRING(MouseSpeedSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sControlsOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sMouseSpeedSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromMouseSpeed(MouseSpeed)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(ControllerSpeed); const float ControllerSpeed = ConfigManager::GetFloat(sControllerSpeed, 1.0f); STATIC_HASHED_STRING(ControlsOptionsScreen); STATIC_HASHED_STRING(ControllerSpeedSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sControlsOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sControllerSpeedSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromControllerSpeed(ControllerSpeed)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(Brightness); const float Brightness = ConfigManager::GetFloat(sBrightness, 1.0f); STATIC_HASHED_STRING(BrightnessScreen); STATIC_HASHED_STRING(BrightnessSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sBrightnessScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sBrightnessSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromBrightness(Brightness)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATIC_HASHED_STRING(DisplayOptionsScreen); STATIC_HASHED_STRING(FOVSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sDisplayOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sFOVSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromFOV(FOV)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(MasterVolume); const float MasterVolume = ConfigManager::GetFloat(sMasterVolume); STATIC_HASHED_STRING(AudioOptionsScreen); STATIC_HASHED_STRING(VolumeSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sAudioOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sVolumeSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, MasterVolume); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(MusicVolume); const float MusicVolume = ConfigManager::GetFloat(sMusicVolume); STATIC_HASHED_STRING(AudioOptionsScreen); STATIC_HASHED_STRING(MusicVolumeSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sAudioOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sMusicVolumeSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, MusicVolume); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } } // Initialize UI callbacks { UIScreenEldSetRes* pSetRes = m_UIManager->GetScreen<UIScreenEldSetRes>("SetResScreen"); pSetRes->SetUICallback(SUICallback(EldritchFramework::OnSetRes, nullptr)); UIScreenFade* pFade = m_UIManager->GetScreen<UIScreenFade>("Fade"); pFade->SetFadeCallback( SUICallback(EldritchFramework::OnFadeFinished, nullptr)); } WB_MAKE_EVENT(ResetToInitialScreens, NULL); WB_DISPATCH_EVENT(WBWorld::GetInstance()->GetEventManager(), ResetToInitialScreens, NULL); { // HACK: Too content aware STATIC_HASHED_STRING(MKGLogoScreen); WB_MAKE_EVENT(PushUIScreen, NULL); WB_SET_AUTO(PushUIScreen, Hash, Screen, sMKGLogoScreen); WB_DISPATCH_EVENT(WBWorld::GetInstance()->GetEventManager(), PushUIScreen, NULL); } // Tick world once to pump the event queue. Fixes title screen bugs. m_World->Tick(0.0f); // All done, show the window finally. SafeDelete(m_SplashWindow); #if BUILD_WINDOWS_NO_SDL m_Window->Show(m_CmdShow); #elif BUILD_SDL m_Window->Show(); #endif // Reattach GL context if needed. m_Renderer->Refresh(); PRINTF("Eldritch initialization complete.\n"); }
MockUnexpectedObjectFailure::MockUnexpectedObjectFailure(UtestShell* test, const SimpleString& functionName, const void* actual, const MockExpectedCallsList& expectations) : MockFailure(test) { message_ = StringFromFormat ("MockFailure: Function called on an unexpected object: %s\n" "\tActual object for call has address: <%p>\n", functionName.asCharString(),actual); addExpectationsAndCallHistoryRelatedTo(functionName, expectations); }
MockExpectedObjectDidntHappenFailure::MockExpectedObjectDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations) : MockFailure(test) { message_ = StringFromFormat("Mock Failure: Expected call on object for function \"%s\" but it did not happen.\n", functionName.asCharString()); addExpectationsAndCallHistoryRelatedTo(functionName, expectations); }
MockNoWayToCopyCustomTypeFailure::MockNoWayToCopyCustomTypeFailure(UtestShell* test, const SimpleString& typeName) : MockFailure(test) { message_ = StringFromFormat("MockFailure: No way to copy type <%s>. Please install a MockNamedValueCopier.", typeName.asCharString()); }
/*virtual*/ void Framework3D::Initialize() { XTRACE_FUNCTION; m_IsInitializing = true; #if BUILD_SDL const int Error = SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE); ASSERT(0 == Error); Unused(Error); if (0 != Error) { PRINTF("SDL_Init: %s\n", SDL_GetError()); } SDL_DisableScreenSaver(); #ifdef HAVE_GLES SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); // SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); #endif #endif STATICHASH(Framework); #if BUILD_WINDOWS #if BUILD_FINAL STATICHASH(ShowConsole); const bool ShowConsole = ConfigManager::GetBool(sShowConsole, false, sFramework); if (ShowConsole) #endif { Console::GetInstance()->SetPos(0, 0); } #endif STATICHASH(UseRandomSeed); const bool UseRandomSeed = ConfigManager::GetBool(sUseRandomSeed, false, sFramework); STATICHASH(RandomSeed); const int RandomSeed = ConfigManager::GetInt(sRandomSeed, 0, sFramework); if (UseRandomSeed) { Math::SeedGenerator(RandomSeed); } else { Math::SeedGenerator(); } STATICHASH(UseFixedFrameTime); m_UseFixedFrameTime = ConfigManager::GetBool(sUseFixedFrameTime, true, sFramework); #ifdef HAVE_GLES0 m_UseFixedFrameTime = false; // GLES hardware are less powerfull than Desktop #endif STATICHASH(FixedFrameTime); m_FixedFrameTime = ConfigManager::GetFloat(sFixedFrameTime, 1.0f / 60.0f, sFramework); #ifdef PANDORA m_FixedFrameTime = 1.0f / 14.0f; // 60fps cannot be sustained on the Pandora #endif STATICHASH(FramesLimit); const int FramesLimit = ConfigManager::GetInt(sFramesLimit, 5, sFramework); m_FrameTimeLimit = m_FixedFrameTime * static_cast<float>(FramesLimit); STATICHASH(DoVideoCapture); m_DoVideoCapture = ConfigManager::GetBool(sDoVideoCapture, false, sFramework); STATICHASH(VideoCaptureFixedFrameTime); m_VideoCaptureFixedFrameTime = ConfigManager::GetFloat( sVideoCaptureFixedFrameTime, 1.0f / 30.0f, sFramework); #ifdef PANDORA sVideoCaptureFixedFrameTime = 1.0f / 8.0f; // 30fps cannot be sustained on the Pandora (even 10fps I'm not sure) #endif uint DisplayWidth = 0; uint DisplayHeight = 0; SimpleString WindowTitle; // Loads display parameters from config, so GetInitialDisplaySize can use // that. m_Display = new Display; // Make sure that we use a supported resolution regardless of what the config // file said. const SDisplayMode BestDisplayMode = m_Display->GetBestDisplayMode(m_Display->m_Width, m_Display->m_Height); m_Display->SetResolution(BestDisplayMode.Width, BestDisplayMode.Height); uint WindowIcon = 0; GetInitialWindowIcon(WindowIcon); GetInitialDisplaySize(DisplayWidth, DisplayHeight); GetInitialWindowTitle(WindowTitle); CreateSplashWindow(WindowIcon, WindowTitle.CStr()); m_Window = new Window; #if BUILD_WINDOWS_NO_SDL DWORD WindowStyle = 0; if (m_Display->m_Fullscreen || (m_Display->m_ScreenWidth == m_Display->m_Width && m_Display->m_ScreenHeight == m_Display->m_Height)) { WindowStyle = WS_POPUP; } else { WindowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; } m_Window->Init(WindowTitle.CStr(), "Class1", WindowStyle, 0, DisplayWidth, DisplayHeight, m_hInstance, WindowProc, WindowIcon, m_Display->m_ScreenWidth, m_Display->m_ScreenHeight); #elif BUILD_SDL uint WindowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN; if (m_Display->m_Fullscreen || (m_Display->m_ScreenWidth == m_Display->m_Width && m_Display->m_ScreenHeight == m_Display->m_Height)) { WindowFlags |= SDL_WINDOW_BORDERLESS; } // TODO SDL: Unify interface? m_Window->Init(WindowTitle.CStr(), WindowFlags, DisplayWidth, DisplayHeight); STATICHASH(IconImage); const char* const pIconImage = ConfigManager::GetString(sIconImage, nullptr, sFramework); if(pIconImage) { ASSERT(pIconImage); const Surface IconSurface = Surface(PackStream(pIconImage), Surface::ESFT_BMP); SDL_SetWindowIcon(m_Window->GetSDLWindow(), IconSurface.GetSDLSurface()); } #endif m_Window->SetFullscreen(m_Display->m_Fullscreen); if (m_Display->m_Fullscreen) { m_Window->SetPosition(0, 0); } m_Clock = new Clock; XTRACE_BEGIN(InitializeDevices); m_Keyboard = new Keyboard; #if BUILD_WINDOWS_NO_SDL m_Mouse = new Mouse(m_hInstance, m_Window->GetHWnd()); #elif BUILD_SDL m_Mouse = new Mouse(m_Window); #endif XTRACE_END; InitializeUIInputMap(); XTRACE_BEGIN(InitializeAudioSystem); InitializeAudioSystem(); XTRACE_END; XTRACE_BEGIN(InitializeRenderer); #if BUILD_WINDOWS_NO_SDL STATICHASH(OpenGL); const bool OpenGL = ConfigManager::GetBool(sOpenGL); if (OpenGL) #endif { PRINTF("Using OpenGL renderer.\n"); m_Renderer = CreateGL2Renderer(m_Window); } #if BUILD_WINDOWS_NO_SDL else { PRINTF("Using Direct3D renderer.\n"); m_Renderer = CreateD3D9Renderer(m_Window->GetHWnd(), m_Display->m_Fullscreen); } #endif IRenderer::SRestoreDeviceCallback Callback; Callback.m_Callback = &Framework3D::RendererRestoreDeviceCallback; Callback.m_Void = this; m_Renderer->SetRestoreDeviceCallback(Callback); InitializeRender(); m_Renderer->Initialize(); m_Renderer->SetDisplay(m_Display); m_Renderer->SetClock(m_Clock); XTRACE_END; if (ShowWindowASAP()) { SafeDelete(m_SplashWindow); #if BUILD_WINDOWS_NO_SDL m_Window->Show(m_CmdShow); #elif BUILD_SDL m_Window->Show(); #endif // Reattach GL context if needed. m_Renderer->Refresh(); } if (UseClassicTargetManager()) { m_TargetManager = new TargetManager(m_Renderer, DisplayWidth, DisplayHeight); } XTRACE_BEGIN(InitializeUI); SimpleString UIManagerDefinitionName; GetUIManagerDefinitionName(UIManagerDefinitionName); m_UIManager = new UIManagerFramework(this); m_UIManager->InitializeFromDefinition(UIManagerDefinitionName); m_UIManager->GetUIStack()->SetFadeOverlay(m_UIManager->GetScreen("Fade")); UIScreen::UpdateMouseButtonsSwapped(); XTRACE_END; m_IsInitializing = false; }
void UIScreenEldSetRes::InitializeFromDefinition( const SimpleString& DefinitionName) { FlushWidgets(); m_ResMap.Clear(); UIScreen::InitializeFromDefinition(DefinitionName); Display* const pDisplay = m_UIManager->GetDisplay(); Array<SDisplayMode> DisplayModes; m_UIManager->GetRenderer()->EnumerateDisplayModes(DisplayModes); DisplayModes.InsertionSort(); ASSERT(DisplayModes.Size()); MAKEHASH(DefinitionName); // Dynamically create definitions for each text button STATICHASH(Rules); SimpleString UsingRules = ConfigManager::GetString(sRules, "", sDefinitionName); MAKEHASH(UsingRules); STATICHASH(Archetype); const char* const ArchetypeName = ConfigManager::GetString(sArchetype, "", sUsingRules); STATICHASH(Parent); const char* const Parent = ConfigManager::GetString(sParent, "", sUsingRules); STATICHASH(PixelYBase); const float YBase = ConfigManager::GetFloat(sPixelYBase, 0.0f, sUsingRules); STATICHASH(PixelYStep); const float YStep = ConfigManager::GetFloat(sPixelYStep, 0.0f, sUsingRules); STATICHASH(Column0PixelX); const float Column0X = ConfigManager::GetFloat(sColumn0PixelX, 0.0f, sUsingRules); STATICHASH(Column1PixelX); const float Column1X = ConfigManager::GetFloat(sColumn1PixelX, 0.0f, sUsingRules); #if DEBUG_SETRES PRINTF("UIScreenEldSetRes info:\n"); PRINTF(" ScreenWidth: %d\n", pDisplay->m_ScreenWidth); PRINTF(" ScreenHeight: %d\n", pDisplay->m_ScreenHeight); #endif FOR_EACH_ARRAY_REVERSE(DisplayIter, DisplayModes, SDisplayMode) { const SDisplayMode& DisplayMode = DisplayIter.GetValue(); if (!pDisplay->m_Fullscreen && (DisplayMode.Width > pDisplay->m_ScreenWidth || DisplayMode.Height > pDisplay->m_ScreenHeight)) { #if DEBUG_SETRES PRINTF(" Skipping mode %dx%d:\n", DisplayMode.Width, DisplayMode.Height); #endif DisplayModes.FastRemove(DisplayIter); } } const int NumDisplayModes = static_cast<int>(DisplayModes.Size()); const int LeftColumnSize = (NumDisplayModes + 1) / 2; const int RightColumnSize = (NumDisplayModes + 1) - LeftColumnSize; // Add one for the Back button for (int DisplayModeIndex = 0; DisplayModeIndex < NumDisplayModes; ++DisplayModeIndex) { const SDisplayMode& DisplayMode = DisplayModes[DisplayModeIndex]; float ScreenX = 0.0f; float ScreenY = 0.0f; int FocusShiftUp = 0; int FocusShiftDown = 0; int FocusShiftLeft = 0; int FocusShiftRight = 0; if (DisplayModeIndex < LeftColumnSize) { // Display mode is in left column ScreenY = YBase + DisplayModeIndex * YStep; ScreenX = Column0X; FocusShiftLeft = -RightColumnSize; FocusShiftRight = LeftColumnSize; } else { // Display mode is in right column ScreenY = YBase + (DisplayModeIndex - LeftColumnSize) * YStep; ScreenX = Column1X; FocusShiftLeft = -LeftColumnSize; FocusShiftRight = RightColumnSize; } if (DisplayModeIndex == 0) { // Display mode is on top left FocusShiftUp = -(RightColumnSize + 1); } else if (DisplayModeIndex == (LeftColumnSize - 1)) { // Display mode is on bottom left FocusShiftDown = (RightColumnSize + 1); // If columns are the same size (*including* the back button), // this widget doesn't have a pair in the right column. if (LeftColumnSize == RightColumnSize) { // Setting focus override to 0 uses the screen's shift values, so loop // instead. FocusShiftLeft = -(NumDisplayModes + 1); FocusShiftRight = (NumDisplayModes + 1); } } else if (DisplayModeIndex == LeftColumnSize) { // Display mode is on top right left FocusShiftUp = -(LeftColumnSize + 1); } // Back button shift down is handled below this loop. const SimpleString NewDefinitionName = SimpleString::PrintF("_Res%d", DisplayModeIndex); // HACKHACK: Insert the UTF-8 codes for the U+00D7 (multiplication sign) const SimpleString ResolutionString = SimpleString::PrintF( "%d \xc3\x97 %d", DisplayMode.Width, DisplayMode.Height); MAKEHASH(NewDefinitionName); STATICHASH(UIWidgetType); ConfigManager::SetString(sUIWidgetType, "Text", sNewDefinitionName); ConfigManager::SetString(sArchetype, ArchetypeName, sNewDefinitionName); ConfigManager::SetString(sParent, Parent, sNewDefinitionName); STATICHASH(String); ConfigManager::SetString(sString, ResolutionString.CStr(), sNewDefinitionName); STATICHASH(PixelX); ConfigManager::SetFloat(sPixelX, ScreenX, sNewDefinitionName); STATICHASH(PixelY); ConfigManager::SetFloat(sPixelY, ScreenY, sNewDefinitionName); STATICHASH(FocusShiftUp); ConfigManager::SetInt(sFocusShiftUp, FocusShiftUp, sNewDefinitionName); STATICHASH(FocusShiftDown); ConfigManager::SetInt(sFocusShiftDown, FocusShiftDown, sNewDefinitionName); STATICHASH(FocusShiftLeft); ConfigManager::SetInt(sFocusShiftLeft, FocusShiftLeft, sNewDefinitionName); STATICHASH(FocusShiftRight); ConfigManager::SetInt(sFocusShiftRight, FocusShiftRight, sNewDefinitionName); UIWidget* const pResWidget = UIFactory::CreateWidget(NewDefinitionName, this); ASSERT(pResWidget); pResWidget->m_Callback = m_Callback; AddWidget(pResWidget); m_ResMap[NewDefinitionName] = DisplayMode; } STATIC_HASHED_STRING(SetResBackButton); UIWidget* const pBackButtonWidget = GetWidget(sSetResBackButton); ASSERT(pBackButtonWidget); pBackButtonWidget->m_FocusShiftLeft = -(NumDisplayModes + 1); pBackButtonWidget->m_FocusShiftRight = (NumDisplayModes + 1); pBackButtonWidget->m_FocusShiftDown = (LeftColumnSize + 1); UpdateRender(); // Initialize focus to the first element (so that we're never unfocused, // because that doesn't make sense for controllers). if (m_FocusWidgets.Size() > 0) { m_FocusedWidget = m_FocusWidgets[0]; // NOTE: Intentionally not calling SetFocus here, so effects don't happen; // we // just need an initial focus for controllers, it's not really *getting* // focus } }
void MsgSocket::Receive() { SmartLocker SL_CallbackObjects(CallbackObjects, false); try { if(socket->Select()) { int nb_read = socket->Recv(bufferSize-occupiedSize, (buffer+occupiedSize)); // OmiscidTrace( "%d %d \n ",nb_read, occupiedSize); if(nb_read == 0) { if ( connected ) { // Send disconnected message SL_CallbackObjects.Lock(); // Send info to all listener for( CallbackObjects.First(); CallbackObjects.NotAtEnd(); CallbackObjects.Next() ) { try { CallbackObjects.GetCurrent()->Disconnected(*this,GetPeerPid()); } catch(SocketException&) {} // Discard it } SL_CallbackObjects.Unlock(); connected = false; } return ; } occupiedSize += nb_read; // DevOmiscidTrace( "occupiedSize %d\n", occupiedSize ); // For printing stuff... buffer[occupiedSize] = '\0'; bool stop = false; unsigned int length_msg, pid, mid; int length_header; int offset = 0; int size = occupiedSize; while ( connected == true && stop == false ) { length_msg = pid = mid = 0; if((length_header = GoodBeginning(buffer+offset, size, length_msg, pid, mid)) != 0) { //cerr << "good beginning "; //cerr.write(aBuffer+offset, keyword_min); //cerr << endl; if ( (unsigned int)size < length_header + length_msg + tag_end_size ) { // OmiscidTrace( "wait more byte\n"); int total = (int)(length_header + length_msg + tag_end_size); if ( total >= bufferSize ) { OmiscidTrace( "buffer too small : new buffer allocation\n"); //allocation new buffer bufferSize = (total+1023)&~1023; // bufferSize = rouded to the KB over unsigned char* tmp_buffer = new OMISCID_TLM unsigned char[bufferSize+1]; if ( tmp_buffer ) { memcpy(tmp_buffer, buffer+offset, size*sizeof(unsigned char)); offset = 0; occupiedSize = size; delete [] buffer; buffer = tmp_buffer; } } stop = true; } else if ( mid == 0 ) { #ifdef DEBUG if ( Debug & DBG_LINKSYNC ) { // buffer[offset+offset+length_msg+tag_size] = '\0'; fprintf( stderr, "MsgSocket::Receive: %s\n", buffer+offset ); } #endif peer_pid = pid; SmartLocker SL_mutex(mutex); if ( callbackSyncLinkFct ) { *(buffer+offset+tag_size+length_msg)='\0'; callbackSyncLinkData.Msg.len = length_msg; if ( length_msg != 0 ) { callbackSyncLinkData.Msg.buffer = (char*)buffer+offset+tag_size; } else { callbackSyncLinkData.Msg.buffer = NULL; } callbackSyncLinkData.Msg.origine = FromTCP; callbackSyncLinkData.Msg.pid = pid; callbackSyncLinkData.Msg.mid = mid; try { (*callbackSyncLinkFct)( &callbackSyncLinkData, this ); } catch( SocketException& e ) { throw e; } } SL_mutex.Unlock(); //std::cout << "Link connexion Msg from "<<pid<<"\n"; receivedSyncLinkMsg = true; if( SyncLinkMsgSent() == false ) { SendSyncLinkMsg(); } if ( length_msg != 0 ) { SetPeerSyncLinkData( (char*)(buffer+offset+length_header), length_msg ); } // Let's say we have a new connected peer SL_CallbackObjects.Lock(); // Send info to all listener for( CallbackObjects.First(); CallbackObjects.NotAtEnd(); CallbackObjects.Next() ) { try { CallbackObjects.GetCurrent()->Connected(*this,pid); } catch(SocketException& e) { // Unlock the list SL_CallbackObjects.Unlock(); // Thow the exception throw e; } } SL_CallbackObjects.Unlock(); offset += length_header + length_msg + tag_end_size; size = occupiedSize - offset; // Ok, we have someone connected } // else if(length_msg == 0) // { // //std::cout << "Empty Msg from "<<pid<<"\n"; // offset += length_header; // size = occupiedSize - offset; // } else { offset += length_header; unsigned char* msgptr = (buffer+offset); //verif end tag if( memcmp(tag_end, (msgptr + length_msg), tag_end_size)) { OmiscidTrace( "warning end tag\n"); size = occupiedSize - offset; } else { offset += length_msg + tag_end_size; size = occupiedSize - offset; #ifdef DEBUG if ( Debug & DBG_RECV ) { if ( length_msg != 0 ) { SimpleString SFormat = "MsgSocket::Recv: %"; SFormat += length_msg; SFormat += "."; SFormat += length_msg; SFormat += "s\n"; fprintf( stderr, SFormat.GetStr(), msgptr ); } else { fprintf( stderr, "MsgSocket::Recv: <empty>\n" ); } } #endif // Send info to all receiver SL_CallbackObjects.Lock(); if ( CallbackObjects.GetNumberOfElements() ) { // Prepare data *(msgptr+length_msg)='\0'; callbackData.Msg.len = length_msg; if ( length_msg != 0 ) { callbackData.Msg.buffer = (char*)msgptr; } else { callbackData.Msg.buffer = (char*)NULL; } callbackData.Msg.origine = FromTCP; callbackData.Msg.pid = pid; callbackData.Msg.mid = mid; // Send info to all listener for( CallbackObjects.First(); CallbackObjects.NotAtEnd(); CallbackObjects.Next() ) { try { CallbackObjects.GetCurrent()->Receive(*this, callbackData); } catch(SocketException& e) { // Unlock the list SL_CallbackObjects.Unlock(); // Throw the exception throw e; } } } SL_CallbackObjects.Unlock(); } } } else { //cerr << "Decalage\n"; int dec; if(!MoveToMessage(buffer+offset, size, dec)) { stop = true; size -= dec; offset += dec; } else { offset += dec; size -= dec; } } } occupiedSize = size; if ( occupiedSize != 0 && offset != 0 ) { memmove(buffer, buffer+offset, occupiedSize); // offset is local. It will be set to 0 again. } } } catch(SocketException& e) { OmiscidTrace( "SocketException: %s %d\n", e.msg.GetStr(), e.err); if ( connected ) { // Send disconnected message SL_CallbackObjects.Lock(); // Send info to all listener for( CallbackObjects.First(); CallbackObjects.NotAtEnd(); CallbackObjects.Next() ) { try { CallbackObjects.GetCurrent()->Disconnected(*this,GetPeerPid()); } catch(SocketException&) {} // Discard } SL_CallbackObjects.Unlock(); connected = false; } } }
SimpleString::SimpleString(const SimpleString& other) { buffer = new char [other.size() + 1]; strcpy(buffer, other.buffer); }
SimpleString TestFailure::createButWasString(const SimpleString& expected, const SimpleString& actual) { return StringFromFormat("expected <%s>\n\tbut was <%s>", expected.asCharString(), actual.asCharString()); }
void UIWidgetImage::InitializeFromDefinition( const SimpleString& DefinitionName ) { UIWidget::InitializeFromDefinition( DefinitionName ); MAKEHASH( DefinitionName ); MAKEHASH( m_Archetype ); STATICHASH( DisplayWidth ); const float DisplayWidth = ConfigManager::GetFloat( sDisplayWidth ); const float ParentWidth = m_OriginParent ? m_OriginParent->GetWidth() : DisplayWidth; const float ParentX = m_OriginParent ? Ceiling( m_OriginParent->GetX() ) : 0.0f; STATICHASH( DisplayHeight ); const float DisplayHeight = ConfigManager::GetFloat( sDisplayHeight ); const float ParentHeight = m_OriginParent ? m_OriginParent->GetHeight() : DisplayHeight; const float ParentY = m_OriginParent ? Ceiling( m_OriginParent->GetY() ) : 0.0f; STATICHASH( PixelX ); STATICHASH( ScreenX ); float X = Pick( ConfigManager::GetArchetypeFloat( sPixelX, sm_Archetype, 0.0f, sDefinitionName ), ParentWidth * ConfigManager::GetArchetypeFloat( sScreenX, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelY ); STATICHASH( ScreenY ); float Y = Pick( ConfigManager::GetArchetypeFloat( sPixelY, sm_Archetype, 0.0f, sDefinitionName ), ParentHeight * ConfigManager::GetArchetypeFloat( sScreenY, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelWidth ); STATICHASH( ScreenWidth ); float Width = Pick( ConfigManager::GetArchetypeFloat( sPixelWidth, sm_Archetype, 0.0f, sDefinitionName ), ParentWidth * ConfigManager::GetArchetypeFloat( sScreenWidth, sm_Archetype, 0.0f, sDefinitionName ) ); STATICHASH( PixelHeight ); STATICHASH( ScreenHeight ); float Height = Pick( ConfigManager::GetArchetypeFloat( sPixelHeight, sm_Archetype, 0.0f, sDefinitionName ), ParentHeight * ConfigManager::GetArchetypeFloat( sScreenHeight, sm_Archetype, 0.0f, sDefinitionName ) ); // Adjust for desired aspect ratio if one dimension is not given // (This is used to size images using ScreenWidth or ScreenHeight // properly regardless of screen aspect ratio. STATICHASH( AspectRatio ); const float AspectRatio = ConfigManager::GetArchetypeFloat( sAspectRatio, sm_Archetype, 1.0f, sDefinitionName ); if( Width == 0.0f ) { Width = Height * AspectRatio; } else if( Height == 0.0f ) { Height = Width / AspectRatio; } // Offset relative to resolved image dimensions if specified STATICHASH( ImageX ); X = Pick( X, ConfigManager::GetArchetypeFloat( sImageX, sm_Archetype, 0.0f, sDefinitionName ) * Width ); STATICHASH( ImageY ); Y = Pick( Y, ConfigManager::GetArchetypeFloat( sImageY, sm_Archetype, 0.0f, sDefinitionName ) * Height ); AdjustDimensionsToParent( X, Y, Width, Height, ParentX, ParentY, ParentWidth, ParentHeight ); GetPositionFromOrigin( X, Y, Width, Height ); STATICHASH( ClampToPixelGrid ); if( ConfigManager::GetArchetypeBool( sClampToPixelGrid, sm_Archetype, true, sDefinitionName ) ) { m_TopLeft.x = Round( m_TopLeft.x ); m_TopLeft.y = Round( m_TopLeft.y ); } // Offset to properly align on pixel grid. const float PixelGridOffset = GetPixelGridOffset(); m_TopLeft.x -= PixelGridOffset; m_TopLeft.y -= PixelGridOffset; // If LoadImage is false, we're expecting to dynamically set the texture in code somewhere STATICHASH( LoadImage ); if( ConfigManager::GetArchetypeBool( sLoadImage, sm_Archetype, true, sDefinitionName ) ) { STATICHASH( Image ); SetTexture( ConfigManager::GetArchetypeString( sImage, sm_Archetype, DEFAULT_TEXTURE, sDefinitionName ) ); } m_Dimensions = Vector2( Width, Height ); STATICHASH( Calibration ); m_Calibration = ConfigManager::GetArchetypeBool( sCalibration, sm_Archetype, false, sDefinitionName ); STATICHASH( MaterialOverride ); const SimpleString DefaultMaterial( "Material_HUD" ); m_Material = ConfigManager::GetArchetypeString( sMaterialOverride, sm_Archetype, DefaultMaterial.CStr(), sDefinitionName ); UpdateRender(); }
void EldritchGame::LaunchRIPTweet() { STATICHASH( RIPFormat ); const SimpleString RIPFormat = ConfigManager::GetLocalizedString( sRIPFormat, "" ); STATICHASH( RIPURL ); const SimpleString RIPURL = ConfigManager::GetLocalizedString( sRIPURL, "" ); STATICHASH( RIPHashtags ); const SimpleString RIPHashtags = ConfigManager::GetLocalizedString( sRIPHashtags, "" ); STATICHASH( RIPTwitter ); const SimpleString RIPTwitter = ConfigManager::GetLocalizedString( sRIPTwitter, "" ); const SimpleString RIPDamage = GetRIPDamage(); const SimpleString RIPLevel = GetRIPLevel(); const SimpleString RIPFormatted = SimpleString::PrintF( RIPFormat.CStr(), RIPDamage.CStr(), RIPLevel.CStr() ); const SimpleString RIPEncoded = RIPFormatted.URLEncodeUTF8(); const SimpleString RIPTweet = SimpleString::PrintF( RIPTwitter.CStr(), RIPEncoded.CStr(), RIPHashtags.CStr(), RIPURL.CStr() ); #if BUILD_WINDOWS ShellExecute( NULL, "open", RIPTweet.CStr(), NULL, NULL, SW_SHOWNORMAL ); #elif BUILD_MAC const SimpleString Command = SimpleString::PrintF( "open %s", RIPTweet.CStr() ); system( Command.CStr() ); #elif BUILD_LINUX const SimpleString Command = SimpleString::PrintF( "xdg-open %s", RIPTweet.CStr() ); system( Command.CStr() ); #endif }
void JUnitTestOutput::openFileForWrite(const SimpleString& fileName) { impl_->file_ = PlatformSpecificFOpen(fileName.asCharString(), "w"); }
SimpleString::SimpleString (const SimpleString& other) { buffer = NEW_BUFFER(other.size() + 1); strcpy(buffer, other.buffer); }
void JUnitTestOutput::writeToFile(const SimpleString& buffer) { PlatformSpecificFPuts(buffer.asCharString(), impl_->file_); }
bool SimpleString::containsNoCase(const SimpleString& other) const { return lowerCase().contains(other.lowerCase()); }
SimpleString StringFrom(double value, int precision) { SimpleString format = StringFromFormat("%%.%df", precision); return StringFromFormat(format.asCharString(), value); }
bool SimpleString::equalsNoCase(const SimpleString& str) const { return lowerCase() == str.lowerCase(); }
SimpleString::SimpleString(const SimpleString& other) { size_t len = other.size() + 1; buffer_ = allocStringBuffer(len); PlatformSpecificStrCpy(buffer_, other.buffer_); }
bool operator==(const SimpleString& left, const SimpleString& right) { return 0 == PlatformSpecificStrCmp(left.asCharString(), right.asCharString()); }
void TestOutput::printFailureInTest(SimpleString testName) { print(" Failure in "); print(testName.asCharString()); }
void Patcher_GetNextPatchFile() { ASSERT( g_FilesInManifest.Size() ); // Iterate to find the next valid patch file for( ; g_NextPatchFileIndex < g_FilesInManifest.Size(); ++g_NextPatchFileIndex ) { SManifestFile& PatchFile = g_FilesInManifest[ g_NextPatchFileIndex ]; SimpleString PatchFilename = PatchFile.m_Filename; if( FileUtil::Exists( PatchFilename.CStr() ) ) { FileStream ExtantFile( PatchFilename.CStr(), FileStream::EFM_Read ); int ExtantSize = ExtantFile.Size(); uint32 ExtantChecksum = Checksum::Adler32( ExtantFile ); SimpleString ExtantLengthString = SimpleString::PrintF( "%d", ExtantSize ); SimpleString ExtantChecksumString = SimpleString::PrintF( "0x%08X", ExtantChecksum ); if( ExtantLengthString == PatchFile.m_Length && ExtantChecksumString == PatchFile.m_Checksum ) { AddStatus( SimpleString::PrintF( "%s is up to date.", PatchFilename.CStr() ), g_StatusColor ); } else { // This file isn't up to date. Patch it! break; } } else { // This file isn't on disk. Get it! break; } } if( g_NextPatchFileIndex < g_FilesInManifest.Size() ) { SimpleString PatchFile = g_FilesInManifest[ g_NextPatchFileIndex ].m_Filename; AddStatus( SimpleString::PrintF( "Getting %s...", PatchFile.CStr() ), g_StatusColor ); STATICHASH( ContentSyncer ); STATICHASH( PatcherHost ); STATICHASH( PatcherContentPath ); g_Patcher_GettingVersionNumber = false; g_Patcher_GettingManifestFile = false; g_Patcher_GettingNextPatchFile = true; g_Patcher_WaitingToConnect = true; g_Patcher_WaitingToReceive = false; HTTPSocket::SSocketInit SocketInit; SocketInit.m_CloseConnection = true; SocketInit.m_HostName = ConfigManager::GetString( sPatcherHost, "", sContentSyncer ); SocketInit.m_Path = SimpleString::PrintF( "%s%s", ConfigManager::GetString( sPatcherContentPath, "", sContentSyncer ), PatchFile.CStr() ); SocketInit.m_Async = true; g_HTTPSocket->Connect( SocketInit ); } else { // Nothing left to patch! Handle the wrap up. FinishPatching(); } }
/*static*/ HashedString ConfigManager::GetInheritedSequenceHash( const SimpleString& FormatName, int Index, const HashedString& Default /*= HashedString::NullString*/, const STRING_TYPE& Context /*= EmptyContext*/ ) { return GetInheritedHash( SimpleString::PrintF( FormatName.CStr(), Index ), Default, Context ); }