void TriangleBatch::Stripify( TriangleBatch& pNewBatch ) { #if GD_PLATFORM == GD_PLATFORM_WIN32 GD_ASSERT( mIndices ); PrimitiveGroup* strip; UInt16 numGroups; SetCacheSize(CACHESIZE_GEFORCE1_2); SetStitchStrips(true); SetMinStripSize(0); SetListsOnly(false); // Stripify! GenerateStrips( mIndices, mIndicesCount, &strip, &numGroups ); GD_ASSERT( numGroups == 1 ); // Copy the result in our triangle batch. pNewBatch.Allocate( TriangleStrip, strip->numIndices ); memcpy( pNewBatch.GetIndices(), strip->indices, strip->numIndices*sizeof(UInt16) ); //GD_DELETE_ARRAY(strip); #else debugBreak(); #endif }
void MemoryFile::Open( const String& pFilename, Bool pIsReadOnly ) { // Open file on disk UInt32 flags = pIsReadOnly ? GENERIC_READ : (GENERIC_READ|GENERIC_WRITE); mFileHandle = CreateFile( pFilename.c_str(), flags, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( mFileHandle == INVALID_HANDLE_VALUE ) { UInt32 error = GetLastError(); GD_ASSERT( error != S_OK ); } mFileSize = ::GetFileSize( mFileHandle, NULL ); // Create file mapping UInt32 accessFlags = pIsReadOnly ? PAGE_READONLY : PAGE_READWRITE; mMappingHandle = CreateFileMapping( mFileHandle, NULL, accessFlags, 0, mFileSize, 0 ); if( mMappingHandle == INVALID_HANDLE_VALUE ) { UInt32 error = GetLastError(); GD_ASSERT( error != S_OK ); } // Map view of file UInt32 viewFlag = pIsReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE; mMemory = (Byte*)MapViewOfFile( mMappingHandle, viewFlag, 0, 0, 0 ); if( !mMemory ) { UInt32 error = GetLastError(); GD_ASSERT( error != S_OK ); } }
Bool ModuleManager::LoadModule( const Char* pModuleName, const Char* pModuleDir ) { GD_ASSERT(pModuleName); GD_ASSERT(pModuleDir); Char fullPath[260]; if( IsModuleLoaded(pModuleName) ) return true; strcpy(fullPath, pModuleDir); strcat(fullPath, pModuleName); Handle libHandle = Core::OpenLibrary( fullPath ); if( !libHandle ) throw ModuleNotFoundException( pModuleName, Here ); Module* module = const_cast<Module*>(FindModule(pModuleName)); if( !module ) throw ModuleNotRegisteredException( pModuleName, Here ); module->mHandle = libHandle; module->mDynamicLoad = true; return true; }
void DragManipulator::OnMouseMove( Int32 /*pRelX*/, Int32 /*pRelY*/ ) { if(!IsActivated() || mEntities.size() == 0 || !HasFocus() || InputSubsystem::GetMouse().IsUp(Mouse::Button_Left)) { return; } mEditor->GetMainView()->MakeCurrent(); // Get the current camera. Camera* camera = mEditor->GetWorldManager().GetCurrentCamera(); // Get the renderer. Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); // Get the new widget and screen position. Int32 x, y; InputSubsystem::GetMouse().GetPos(x, y); Vector2f newScreenPos(x, y); QPoint widgetPos = mEditor->GetMainView()->mapFromGlobal(QPoint(x, y)); Vector2f newWidgetPos(widgetPos.x(), widgetPos.y()); // Calculate the origin screen position. Vector3f originWindowPos = renderer->WorldToScreen( mWorldPosition ); // Calculate the right offset. Vector3f rightWorldOffet = mWorldPosition + camera->GetRight(); Vector3f rightWindowOffset = renderer->WorldToScreen( rightWorldOffet ); // Calculate the up offset. Vector3f upWorldOffet = mWorldPosition + camera->GetUp(); Vector3f upWindowOffset = renderer->WorldToScreen( upWorldOffet ); // Get the offsets for 1 pixel. Float nbPixelRight = rightWindowOffset.x - originWindowPos.x; Float nbPixelUp = upWindowOffset.y - originWindowPos.y; // Get the nb. of pixels between the current mouse position and the click position. Float screenOffsetRight = newScreenPos.x - mScreenClickPos.x; Float screenOffsetUp = newScreenPos.y - mScreenClickPos.y; GD_ASSERT(mEntities.size() == mOriginPositions.size()); std::list<Entity*>::iterator itEntity = mEntities.begin(); std::list<Vector3f>::iterator itOriginPos = mOriginPositions.begin(); while(itEntity != mEntities.end()) { Vector3f newPosition = *itOriginPos + (camera->GetRight() * screenOffsetRight / nbPixelRight) + (camera->GetUp() * screenOffsetUp / -nbPixelUp); Vector3f oldPosition = (*itEntity)->GetPosition(); (*itEntity)->SetPosition(newPosition); ++itEntity; ++itOriginPos; } }
// ------------------------------------------------------------------------------------------ //! Function would be called on the global initialization step. //! @returns Non-negative value if the operation succeeded. GDAPI IResult IGraphicsOpenGLWindows::OnRuntimeInitialize() { _CheckNotInitialized(); ConsoleDevice->Log(GD_DLOG_CAT ": going to initialize graphics devices..."); IResult const _BaseResult = IGraphicsPlatform::OnRuntimeInitialize(); if (IFailed(_BaseResult)) return _BaseResult; // Loading the device context of the window.. HGLRCDeviceContext = GetDC(hwndMain); GD_ASSERT(HGLRCDeviceContext != nullptr , "'GetDC' error: failed to retrieve the device context of the main window."); // Choosing the pixel format.. PIXELFORMATDESCRIPTOR glPixelFormatDescriptor = {}; glPixelFormatDescriptor.nSize = sizeof(glPixelFormatDescriptor); glPixelFormatDescriptor.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; glPixelFormatDescriptor.iLayerType = PFD_MAIN_PLANE; glPixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA; glPixelFormatDescriptor.cColorBits = 32; glPixelFormatDescriptor.cDepthBits = 32; int const _OglPixelFormat = ChoosePixelFormat(HGLRCDeviceContext, &glPixelFormatDescriptor); SetPixelFormat(HGLRCDeviceContext, _OglPixelFormat, &glPixelFormatDescriptor); GD_ASSERT(_OglPixelFormat != 0 , "'ChoosePixelFormat' error: failed to select correct pixel format."); // Creating temporary OpenGL 2.1 context.. // We need it to load a function, that helps us to create an advanced context with // the support of the OpenGL 3.0 and above. HGLRC const HGLRCContextTemp = wglCreateContext(HGLRCDeviceContext); wglMakeCurrent(HGLRCDeviceContext, HGLRCContextTemp); auto const wglCreateContextAttribsARB = reinterpret_cast<HGLRC(*)(HDC hDC, HGLRC hGLRC , int const* Attributes)>(wglGetProcAddress("wglCreateContextAttribsARB")); GD_ASSERT(wglCreateContextAttribsARB != nullptr , "'wglGetProcAddress' error: failed to retrieve the address of the 'wglCreateContextAttribsARB' routine."); wglMakeCurrent(nullptr, nullptr); wglDeleteContext(HGLRCContextTemp); // Creating the full-featured OpenGL 4.3++ context.. int static const HGLRCContextVersionAttributes[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4, WGL_CONTEXT_MINOR_VERSION_ARB, 3, #if GD_DEBUG WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB | WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, #endif // if GD_DEBUG 0 }; HGLRCContext = wglCreateContextAttribsARB(HGLRCDeviceContext, nullptr, HGLRCContextVersionAttributes); wglMakeCurrent(HGLRCDeviceContext, HGLRCContext); if (WGLEW_EXT_swap_control) wglSwapIntervalEXT(0); ConsoleDevice->Log(GD_DLOG_CAT ": ... initialized."); return IResult::Ok; }
UInt64 SystemInfo::GetCpuCycles() { UInt64 ticks; int res = sceRtcGetCurrentTick(&ticks); GD_ASSERT(res == 0); res = sceRtcTickAddYears (&ticks,&ticks,-2000); GD_ASSERT(res == 0); return ticks; }
void Gamedesk::kDOPTree::DrawLevel( kDOPTree::kDOPNode* pNode, UInt32 pLevel ) { mDepth++; if( mDepth == pLevel || pNode->mTriangleIndices.size() != 0 ) { Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); // Render the bounding box. renderer->SetRenderState( Renderer::Lighting, false ); renderer->SetPolygonMode( Renderer::BothFace, Renderer::FillWireframe ); renderer->SetCulling( Renderer::NoCulling ); renderer->SetColor(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); renderer->DrawBox( pNode->mBoundingBox.Min(), pNode->mBoundingBox.Max() ); renderer->SetRenderState( Renderer::Lighting, true ); renderer->SetPolygonMode( Renderer::BothFace, Renderer::FillSolid ); renderer->SetCulling( Renderer::CullBackFace ); } else { kDOPNode* leftNode = mNodes[pNode->mChildsIndex + 0]; kDOPNode* rightNode = mNodes[pNode->mChildsIndex + 1]; DrawLevel( leftNode, pLevel ); DrawLevel( rightNode, pLevel ); } mDepth--; }
Vector3f TrackballManipulator::CursorToSpherePos() { // Get the renderer. Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); mEditor->GetMainView()->MakeCurrent(); // Get the camera. Camera* camera = mEditor->GetWorldManager().GetCurrentCamera(); Float farViewDistance = camera->GetFarView(); // Get the mouse position. Int32 x, y; InputSubsystem::GetMouse().GetPos(x, y); QPoint widgetPos = mEditor->GetMainView()->mapFromGlobal(QPoint(x, y)); Int32 viewport[4]; renderer->GetViewport(viewport); Vector2f screenRay( widgetPos.x(), viewport[3] - widgetPos.y() ); // Get the vector from the mouse positions. Vector3f worldRayStart = camera->GetPosition(); Vector3f worldRayEnd = renderer->ScreenToWorld( screenRay ) - camera->GetPosition(); worldRayEnd.Normalize(); worldRayEnd *= farViewDistance; Vector3f onSphere = SphereLineIntersection( worldRayStart, worldRayEnd, mBallPos, 1 ); return (onSphere-mBallPos).GetNormalized() + mBallPos; }
Sound* SoundManager::Create(const String& pSoundFileName, Bool pIs3DSound) { // Ask the sound subsystem to create a sound for us. Sound* sound = Cast<Sound>(SoundSubsystem::Instance()->Create(Sound::StaticClass())); std::map<String, SoundData*>::iterator itFind = mLoadedSounds.find(pSoundFileName); if(itFind != mLoadedSounds.end()) { itFind->second->AddRef(); sound->Create(itFind->second, pIs3DSound); } else { ResourceImporter* importer = ResourceManager::Instance()->GetImporterForFile(pSoundFileName, SoundData::StaticClass()); GD_ASSERT(importer); SoundData* soundData = Cast<SoundData>(importer->Import(pSoundFileName)); mLoadedSounds[pSoundFileName] = soundData; sound->Create(soundData, pIs3DSound); sound->AddRef(); } sound->Init(); return sound; }
void EditorTool::Show() { // Make sure the window as been created. GD_ASSERT(mWindow); mWindow->show(); }
Bool Mutex::IsLocked() const { DWORD result = ::WaitForSingleObject(mMutex, 0); GD_ASSERT(result != WAIT_FAILED); return result == WAIT_TIMEOUT; }
TrackballManipulator::TrackballManipulator(EditorBase* pEditor) : mActivationInputState(Keyboard::Key_R, Keyboard::Key_Pressed, Mouse::Button_None, Mouse::Button_Pressed), mDeactivationInputState(Keyboard::Key_R, Keyboard::Key_Pressed, Mouse::Button_None, Mouse::Button_Pressed), mEditor(pEditor) { GD_ASSERT(pEditor); }
void QPropertyDelegate::updateEditorGeometry(QWidget* pEditor, const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const { GD_ASSERT(pEditor == mActiveEditor); if( !pIndex.isValid() ) return; pEditor->setGeometry(pOption.rect); }
RotateCommand::RotateCommand(Entity* pEntity, const Quaternionf& pOldOrientation) : Command("Rotate"), mEntity(pEntity), mOldOrientation(pOldOrientation) { GD_ASSERT(mEntity); mNewOrientation = mEntity->GetOrientation(); }
bool QPropertyDelegate::eventFilter(QObject *object, QEvent *event) { QWidget *editor = ::qobject_cast<QWidget*>(object); if(!editor) return false; GD_ASSERT(editor == mActiveEditor); if(event->type() == QEvent::KeyPress) { switch(static_cast<QKeyEvent *>(event)->key()) { case Qt::Key_Tab: emit commitData(editor); emit closeEditor(editor, QAbstractItemDelegate::EditNextItem); mActiveEditor = 0; return true; case Qt::Key_Backtab: emit commitData(editor); emit closeEditor(editor, QAbstractItemDelegate::EditPreviousItem); mActiveEditor = 0; return true; case Qt::Key_Enter: case Qt::Key_Return: emit commitData(editor); emit closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); mActiveEditor = 0; return true; case Qt::Key_Escape: // don't commit data emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); mActiveEditor = 0; return true; default: break; } } else if(event->type() == QEvent::FocusOut && !editor->isActiveWindow()) { #ifndef QT_NO_DRAGANDDROP // The window may loose focus during an drag operation. // i.e when dragging involves the task bar on Windows. //if(QDragManager::self() && QDragManager::self()->object != 0) // return false; #endif if( QApplication::activeModalWidget() && QApplication::activeModalWidget()->parent() == editor ) return true; emit commitData(editor); emit closeEditor(editor, NoHint); mActiveEditor = 0; return true; } return false; }
void World::SetCurrentCamera( UInt32 pCameraIndex ) { GD_ASSERT( pCameraIndex >= 0 && pCameraIndex < mCameras.size() ); List<Camera*>::iterator itCamera = mCameras.begin(); for( UInt32 i = 0; i < pCameraIndex; i++) itCamera++; mCurrentCamera = *itCamera; }
Bool ModuleManager::UnregisterModule( Module* pModule ) { GD_ASSERT(pModule); if( !IsModuleLoaded(pModule->GetName()) ) return false; mModules.RemoveElement(*pModule); return true; }
void Model3D::Render() const { Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); if(mMesh) { (*mMesh)->Render(); } }
void QPropertyDelegate::setEditorData(QWidget* pEditor, const QModelIndex& pIndex) const { GD_ASSERT(pEditor == mActiveEditor); const QPropertyModel* model = reinterpret_cast<const QPropertyModel*>(pIndex.model()); Property* baseProp = QPropertyModel::GetProperty(pIndex); QPropertyHelper* propHelper = QPropertyHelpersManager::GetHelper(baseProp->GetID()); if( propHelper && model ) propHelper->SetEditorData(pEditor, model->GetEdited(), baseProp, QPropertyModel::GetComponentIndex(pIndex)); }
/////////////////////////////////////////////////////////////////////////////// // RegisterModule Bool ModuleManager::RegisterModule( Module* pModule ) { GD_ASSERT(pModule); if( IsModuleLoaded(pModule->GetName()) ) return false; mModules.AddTail(*pModule); return true; }
// ------------------------------------------------------------------------------------------ //! Changes the mode in which the graphics canvas device is running. //! @param GfxCanvasMode The new canvas mode that would be set. //! @param gfxForcelyReapply Do forcedly reapply mode, even if device is running is the same mode. //! @returns Non-negative value if the operation succeeded. GDAPI IResult IGraphicsSDL2::Canvas_SetMode(IGraphicsCanvasMode const gfxCanvasMode , bool const gfxForcelyReapply /*= false*/) { _CheckInitialized(); ConsoleDevice->LogFormat(GD_DLOG_CAT ": mode is going to be set to %d...", gfxCanvasMode); GfxCanvasMode = gfxCanvasMode; GD_ASSERT(SDL_SetWindowFullscreen(SDLWindow, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | gfxCanvasMode != IGRAPHICS_OUTPUT_MODE_WINDOWED ? SDL_WINDOW_FULLSCREEN : 0) == 0 , "'SDL_SetWindowFullscreen' function has failed."); return IResult::NothingWasDone; }
const Module* ModuleManager::FindModule( const Char* pModuleName ) const { GD_ASSERT(pModuleName); DList::Root<Module>::Iterator itModule(mModules); for( ; itModule.IsValid(); ++itModule ) { if( strcmp((*itModule)->GetName(), pModuleName) == 0 ) return *itModule; } return 0; }
// ------------------------------------------------------------------------------------------ //! Function would be called on the global initialization step. //! @returns Non-negative value if the operation succeeded. GDAPI IResult IGraphicsSDL2::OnRuntimeInitialize() { _CheckNotInitialized(); ConsoleDevice->LogFormat(GD_DLOG_CAT ": going to initialize canvas devices:" "\n\tMode - %d" "\n\tResolution - %dx%d@%d..." , GfxCanvasMode, GfxResolutionSelected->Width, GfxResolutionSelected->Height , GfxResolutionSelected->VsyncNumerator / GfxResolutionSelected->VsyncDenominator); #if GD_DEBUG if (GfxCanvasMode == IGRAPHICS_OUTPUT_MODE_FULLSCREEN) { // In some cases and GPUs debugging in fullscreen may cause driver crashes or // inability to switch back to the canvas window and continue executing the app. // Pseudo-fullscreen mode can save for us a lot of health points. // // P.S. You can still manually set mode to true fullscreen. Happy debugging then. GfxCanvasMode = IGRAPHICS_OUTPUT_MODE_PSEUDO_FULLSCREEN; ConsoleDevice->LogWarning(GD_DLOG_CAT ": ...default mode was set to be fullscreen - forcedly setting to pseudo-fullscreen for debug purposes."); } #endif // if GD_DEBUG // Initializing the SDL2 GD_ASSERT(SDL_Init(SDL_INIT_EVERYTHING) == 0 , "'SDL_Init' function has failed"); // Creating the output window.. SDLWindow = SDL_CreateWindow("(GoddamnEngine) Main window." , SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED // Position on screen. , static_cast<int>(GfxResolutionSelected->Width), static_cast<int>(GfxResolutionSelected->Height) , SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); GD_ASSERT(SDLWindow != nullptr, "'SDL_CreateWindow' function has failed."); ConsoleDevice->Log(GD_DLOG_CAT ": ... initialized."); return IResult::Ok; }
void QPropertyDelegate::setModelData(QWidget* pEditor, QAbstractItemModel* pModel, const QModelIndex& pIndex) const { GD_ASSERT(pEditor == mActiveEditor); if( !pIndex.isValid() ) return; QPropertyModel* model = reinterpret_cast<QPropertyModel*>(pModel); Property* baseProp = QPropertyModel::GetProperty(pIndex); QPropertyHelper* propHelper = QPropertyHelpersManager::GetHelper(baseProp->GetID()); if( propHelper && model ) propHelper->SetModelData(pEditor, model->GetEdited(), baseProp, QPropertyModel::GetComponentIndex(pIndex)); model->setData(pIndex, QVariant(), Qt::DisplayRole); }
void SoundManager::Release(Sound* pSound) { String soundFileName = pSound->GetSoundData().GetFileName(); std::map<String, SoundData*>::iterator itFind = mLoadedSounds.find(soundFileName); GD_ASSERT(itFind != mLoadedSounds.end()); if(itFind->second->RemoveRef()) { itFind->second->Kill(); GD_DELETE(itFind->second); mLoadedSounds.erase(itFind); } GD_DELETE(pSound); }
void ModelBrowserTool::Render() { Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); renderer->SetViewport( 0, 0, mModelBrowserWindow->mViewerFrame->width(), mModelBrowserWindow->mViewerFrame->height() ); renderer->SetClearColor( Color4f( 0.1f, 0.2f, 0.4f, 1.0f) ); renderer->SetCulling( Renderer::CullBackFace ); // Render. renderer->Clear( Renderer::ColorBuffer | Renderer::DepthBuffer ); renderer->SetRenderState( Renderer::DepthTest, true ); // Camera. renderer->SetMatrixMode(Renderer::ProjectionMatrix); renderer->LoadIdentity(); renderer->Perspective(mCamera.GetFovAngle(), (float)mModelBrowserWindow->mViewerFrame->width() / (float)mModelBrowserWindow->mViewerFrame->height(), mCamera.GetNearView(), mCamera.GetFarView()); renderer->SetMatrixMode(Renderer::ModelViewMatrix); renderer->LoadIdentity(); renderer->SetView( mCamera.GetPosition(), mObjectCenter - mCamera.GetPosition(), mCamera.GetUp() ); Light light; light.mPosition = mCamera.GetPosition(); light.mAmbient = Color4f(0.1f,0.1f, 0.1f,1.0f); light.mDiffuse = Color4f(0.9f,0.9f, 0.9f,1.0f); light.mType = Renderer::LightPoint; renderer->SetRenderState( Renderer::Light_i, true, 0 ); renderer->SetLight( 0, light ); renderer->SetRenderState( Renderer::Lighting, true ); renderer->SetColor(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); // Change the orientation. static Float pAngle = 0; pAngle += 0.05f; mModel->SetOrientation(Quaternionf( Vector3f(0,1,0), pAngle )); renderer->Translate(mModel->GetPosition()); renderer->Rotate(mModel->GetOrientation()); mModel->Render(); }
void Entity::RenderSelected() const { Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); // Render the bounding box. renderer->SetRenderState( Renderer::Lighting, false ); renderer->SetPolygonMode( Renderer::BothFace, Renderer::FillWireframe ); renderer->SetCulling( Renderer::NoCulling ); renderer->SetColor(Color4f(1.0f, 0.0f, 0.0f, 1.0f)); renderer->DrawBox( mBoundingBox.Min(), mBoundingBox.Max() ); renderer->SetColor(Color4f(1.0f, 1.0f, 1.0f, 1.0f)); renderer->SetRenderState( Renderer::Lighting, true ); renderer->SetPolygonMode( Renderer::BothFace, Renderer::FillSolid ); renderer->SetCulling( Renderer::CullBackFace ); }
void DragManipulator::OnMouseButtonPressed(const Mouse::Button& pButton) { if(pButton != Mouse::Button_Left || !HasFocus()) return; Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer(); GD_ASSERT(renderer); // Get the position of the mouse in the screen and widget. Int32 x, y; InputSubsystem::GetMouse().GetPos(x, y); mScreenClickPos = Vector2f(x, y); QPoint widgetPos = mEditor->GetMainView()->mapFromGlobal(QPoint(x, y)); mClickPos = Vector2f(widgetPos.x(), widgetPos.y()); // Calculate the center position of the manipulated objects. mWorldPosition = GetCenterPosition(); UpdateOriginPositions(); }
GD_NAMESPACE_BEGIN // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Runtime interface's functionality Implementation. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ------------------------------------------------------------------------------------------ //! Function would be called on the global initialization step, before all other interfaces //! are initialized. //! @returns Non-negative value if the operation succeeded. GDAPI IResult IGraphicsSDL2::OnRuntimePreInitialize() { IResult const _BaseResult = IGraphicsPlatform::OnRuntimePreInitialize(); if (IFailed(_BaseResult)) return _BaseResult; // Retrieving information about the list of supported screen resolutions. { int static const sdlCurrentDisplay = 0; // We have no support for multiple display systems. int const sdlDisplayModesCount = SDL_GetNumDisplayModes(sdlCurrentDisplay); GD_ASSERT(sdlDisplayModesCount > 0, "No display mods information was retrieved."); for (SizeTp sdlDisplayModeIndex = 0; sdlDisplayModeIndex < sdlDisplayModesCount; ++sdlDisplayModeIndex) { // Retrieving display lists in the reverse order.. SDL_DisplayMode sdlDisplayMode = {}; if (SDL_GetDisplayMode(sdlCurrentDisplay, sdlDisplayModesCount - sdlDisplayModeIndex - 1, &sdlDisplayMode) != GD_FALSE) { GfxResolutionsList.InsertLast({ static_cast<UInt32>(sdlDisplayMode.w), static_cast<UInt32>(sdlDisplayMode.w) , sdlDisplayMode.refresh_rate, 1 }); } } } //! @todo Load default parameters. GfxCanvasMode = IGRAPHICS_OUTPUT_MODE_WINDOWED; // Easier for debugging purposes. GfxResolutionSelected = &GfxResolutionsList.GetData()[8]; return IResult::Ok; }
Entity* World::SpawnEntity( Class* pEntityClass, const Vector3f& pPosition, const Quaternionf& pOrientation, const String& pName ) { GD_ASSERT( pEntityClass && pEntityClass->IsDerivedFrom(Entity::StaticClass()) ); {Profile("Spawn"); {Profile(pEntityClass->GetName()); Entity* spawnedObject = Cast<Entity>( pEntityClass->AllocateNew() ); spawnedObject->SetOwner(this); spawnedObject->SetName( pName ); spawnedObject->SetWorld(this); spawnedObject->Init(); spawnedObject->SetPosition( pPosition ); spawnedObject->SetOrientation( pOrientation ); InsertEntity( spawnedObject ); return spawnedObject; } } }