bool RenderObject::render(RectangleList *updateRects, const Common::Array<int> &updateRectsMinZ) { // Falls das Objekt nicht sichtbar ist, muss gar nichts gezeichnet werden if (!_visible) return true; // Objekt zeichnen. bool needRender = false; int index = 0; // Only draw if the bounding box intersects any update rectangle and // the object is in front of the minimum Z value. for (RectangleList::iterator rectIt = updateRects->begin(); !needRender && rectIt != updateRects->end(); ++rectIt, ++index) needRender = (_bbox.contains(*rectIt) || _bbox.intersects(*rectIt)) && getAbsoluteZ() >= updateRectsMinZ[index]; if (needRender) doRender(updateRects); // Dann müssen die Kinder gezeichnet werden RENDEROBJECT_ITER it = _children.begin(); for (; it != _children.end(); ++it) if (!(*it)->render(updateRects, updateRectsMinZ)) return false; return true; }
bool RenderObject::render() { // Objektänderungen validieren validateObject(); // Falls das Objekt nicht sichtbar ist, muss gar nichts gezeichnet werden if (!_visible) return true; // Falls notwendig, wird die Renderreihenfolge der Kinderobjekte aktualisiert. if (_childChanged) { sortRenderObjects(); _childChanged = false; } // Objekt zeichnen. doRender(); // Dann müssen die Kinder gezeichnet werden RENDEROBJECT_ITER it = _children.begin(); for (; it != _children.end(); ++it) if (!(*it)->render()) return false; return true; }
void SDLMainLoop::run() { loop->construct(); LOG2(GLOBAL, PROGRESS, "Entering main loop"); Uint32 lastTime = SDL_GetTicks(); accelControl = boost::shared_ptr<Timing::AccelControl>( new Timing::AccelControl()); accelControl->setPauseSkipDirectly(lastTime); inputManager = boost::shared_ptr<Input::GlobalInputManager>( new Input::GlobalInputManager()); while(!quit) { handleEvents(); loop->miscellaneous(); doRender(); { static const int RATE = 10; Uint32 thisTime = SDL_GetTicks(); int timeTakenSoFar = static_cast<int>(thisTime - lastTime); if(timeTakenSoFar < RATE) { SDL_Delay(RATE - timeTakenSoFar); } while(lastTime < thisTime) lastTime += RATE; } accelControl->clearPauseSkip(); } LOG2(GLOBAL, PROGRESS, "Exiting main loop"); }
void element::Render() { lock(); if (m_parent) { m_parent->lock(); if (GetHide() == 0) { log_d("%s doRender",GetName()); doRender(); } else { log_d("Render %s hide\r\n", GetName()); } //printf("draw %s parent %s %d %d %d %d\n",m_parent->GetName(),GetName(),GetWidth(), GetHeight(), GetX(), GetY()); m_parent->RenderFrom(this, 0, 0, GetWidth(), GetHeight(), GetX(), GetY()); //控件输出到父亲 m_parent->unlock(); //m_parent->Flush(); } else { RenderEB(); if (GetHide() == 0) { log_d("%s doRender\n",GetName()); doRender(); } else { log_d("Render %s hide\r\n", GetName()); } //printf("draw %s %d %d %d %d\n",GetName(),GetWidth(), GetHeight(), GetX(), GetY()); m_proc->Draw(this, 0, 0, GetWidth(), GetHeight(), GetX(), GetY());//控件输出到容器 RenderET(); } unlock(); }
void QgsMapRendererCustomPainterJob::start() { if ( isActive() ) return; mRenderingStart.start(); mActive = true; mErrors.clear(); QgsDebugMsg( "QPAINTER run!" ); QgsDebugMsg( "Preparing list of layer jobs for rendering" ); QTime prepareTime; prepareTime.start(); // clear the background mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() ); mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) ); #ifndef QT_NO_DEBUG QPaintDevice* thePaintDevice = mPainter->device(); QString errMsg = QStringLiteral( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() ); Q_ASSERT_X( qgsDoubleNear( thePaintDevice->logicalDpiX(), mSettings.outputDpi() ), "Job::startRender()", errMsg.toLatin1().data() ); #endif delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngineV2 = new QgsLabelingEngine(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); } mLayerJobs = prepareJobs( mPainter, mLabelingEngineV2 ); QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) ); if ( mRenderSynchronously ) { // do the rendering right now! doRender(); return; } // now we are ready to start rendering! connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) ); mFuture = QtConcurrent::run( staticRender, this ); mFutureWatcher.setFuture( mFuture ); }
void FTFont::render( const wchar_t* string, const FTGLRenderContext *context) { const wchar_t* c = string; pen.x = 0; pen.y = 0; while( *c) { doRender( *c, *(c + 1), context); ++c; } }
void FTFont::render( const char* string, const FTGLRenderContext *context) { const unsigned char* c = (unsigned char*)string; pen.x = 0; pen.y = 0; while( *c) { doRender( *c, *(c + 1), context); ++c; } }
void AquariumRenderer::render( uint32_t turn ) { doPreRender( turn ); ActionArray actions = doSwapActions(); for ( auto action : actions ) { action(); } doRender(); }
void Init(std::function<bool()> setup) { bool done = false; MSG msg; DWORD lastFrameTime; GLenum err = glewInit(); if (!setup()) return; // render initial frame before loop lastFrameTime = timeGetTime(); doRender(0.0f); while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { done = true; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { DWORD now = timeGetTime(); float dt = (now - lastFrameTime) / 1000.0f; doRender(dt); lastFrameTime = now; } } }
int main(int argc, char **argv) { SDL_Window *window = NULL; // Declare a window SDL_Renderer *renderer = NULL; // Declare a renderer if (SDL_Init(SDL_INIT_VIDEO) < 0) { // Initialize SDL2 printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); } Man man; man.x = 220; man.y = 110; // Create an application window with the following settings: window = SDL_CreateWindow("Game Window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position SCREEN_WIDTH, // width, in pixels SCREEN_HEIGHT, // height, in pixels 0); // flags if (window == NULL) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); // The window is open: enter program loop (see SDL_PollEvent) int done = 0; // Event loop while (!done) { // Check for events done = processEvents(window, &man); // Render display doRender(renderer, &man); // don't burn up the CPU ;-) SDL_Delay(10); } // Close and destroy the window SDL_DestroyWindow(window); SDL_DestroyRenderer(renderer); // Quit SDL subsystems SDL_Quit(); return 0; }
void Engine:: enterMainLoop() { doCapGtimeCalcDt(); m_delayTime = gameTime; while ( ! quit ) { doCapGtimeCalcDt(); doScripts(); doInput(); doUpdate(); doCollision(); doDelay(); doRender(); } }
// set up local coords void Geometry::render() { // store current matrix glPushMatrix(); glTranslatef(x, y, z); glRotatef(roll, 0, 0, 1); glRotatef(pitch, 1, 0, 0); glRotatef(yaw, 0, 1, 0); glScalef(scale, scale, scale); // go go gadget implementor doRender(); // restore matrix glPopMatrix(); }
void element::Render() { lock(); RenderEB(); if (hide == 0) { doRender(); } else { printf("Render %s hide\r\n", name.c_str()); } xml_mgr->Draw(this, 0, 0, width, height, x, y); RenderET(); unlock(); }
void View::doUpdate() { if (g_gameSystem->isRunning()) { return; } uint_t now = OsUtil::milliseconds(); m_frameTime = now - m_frameOldTime; m_frameOldTime = now; if (m_frameTime > 2000) { // Printf("DEBUG"); } preUpdate(); m_camera.setTarget(m_frame->getRenderTarget()); m_camera.setViewRect(m_frame->getRenderTarget()->getRect()); m_camera.setOrigin(m_eyeMatrix.origin); m_camera.setViewAxis(m_eyeMatrix.axis); m_camera.setFov(0, 60); m_camera.setTime(now); g_renderSystem->beginFrame(m_camera.getTarget()); #if 0 gRenderSystem->beginScene(m_camera); #endif if (!m_context->isLoading()) { doRender(); } #if 0 gRenderSystem->endScene(); #endif drawAxis(); //t = Milliseconds(); g_renderSystem->endFrame(); m_frameNumCur++; }
void RenderCommand::onRender() { doRender(false); }
QPixmap KCardCachePrivate::renderSvg( const QString& element ) { kDebug() << "Renderering" << element << "in main thread."; QMutexLocker l( rendererMutex ); return doRender( element, renderer(), size ); }
QImage HTMLRenderer::render() { doRender(); return m_image; }
void SeaweedRenderer::render( Seaweed const & seaweed ) { doRender( seaweed ); }
void OverlayCategory::render() { doRender( getOverlay().getEngine()->getOverlayCache().getRenderer() ); }
bool SceneLoader::buildScene(string filename) { buildEndlineTable(filename); ifstream file(filename.c_str()); string line; int lastPos = 0; while (findOpenParen(file)) { cout << "found open paren" << endl; file.tellg(); if (readCommand(file, line)) { if (line == "Include") { string instName; if (doInclude(file, instName)) { cout << "included " << instName << endl; } else { cout << "mangled include at "; curPos(cout, file.tellg()); cout << endl; } } else if (line == "Sphere") { string gname; if (doSphere(file, gname)) { cout << "read sphere " << gname << endl; } else { *err << "mangled sphere command at "; errLine(file.tellg()); } } else if (line == "Material") { string gname; if (doMaterial(file, gname)) { cout << "read material " << gname << endl; } else { *err << "mangled material command at "; errLine(file.tellg()); } } else if (line == "Light") { string gname; if (doLight(file, gname)) { cout << "read light " << gname << endl; } else { *err << "mangled light command at "; errLine(file.tellg()); } } else if (line == "Camera") { string gname; if (doCamera(file, gname)) { cout << "read camera " << gname << endl; } else { *err << "mangled camera command at "; errLine(file.tellg()); } } else if (line == "I") { *err << "Error: Instance commands must belong to a group, but I found in global scope at "; errLine(file.tellg()); /*string iname; // code to handle I at global scope (doesn't make much sense now that instance names skip the names table) if (doI(file, iname)) { cout << "got an instance named " << iname << endl; }*/ } else if (line == "G") { string iname; if (doG(file, iname)) { cout << "got a group named " << iname << endl; } } else if (line == "Render") { string iname; if (doRender(file, iname)) { cout << "did render " << iname << endl; } } else { *err << "command not recognized: " << line << endl; } findCloseParen(file); } else { } lastPos = file.tellg(); } return true; }
void RenderCommand::onPreview() { doRender(true); }
void SceneRenderer::render( bool _lastFrame, bool _sameFrame, bool fullWindow) { static const GLfloat blindnessColor[4] = { 1.0f, 1.0f, 0.0f, 1.0f }; static const GLfloat dimnessColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; static const float dimDensity = 0.75f; bool lighting = BZDB.isTrue("lighting"); lastFrame = _lastFrame; sameFrame = _sameFrame; // avoid OpenGL calls as long as possible -- there's a good // chance we're waiting on the vertical retrace. // set the view frustum if (sceneIterator) sceneIterator->resetFrustum(&frustum); // get the important lights in the scene int i; int numLights = 0; if (!sameFrame) { clearLights(); if (sceneIterator && !blank && lighting) { // add lights sceneIterator->reset(); SceneNode* node; while ((node = sceneIterator->getNext()) != NULL) node->addLight(*this); numLights = lights.size(); // pick maxLights most important light sources // should go by full lighting function but we'll just go by distance if (numLights > maxLights) { const GLfloat* eye = frustum.getEye(); for (i = 0; i < maxLights; i++) { GLfloat maxImportance = lights[i]->getImportance(eye); for (int j = i + 1; j < numLights; j++) { GLfloat importance = lights[j]->getImportance(eye); if (importance > maxImportance) { OpenGLLight* temp = lights[i]; lights[j] = lights[i]; lights[i] = temp; maxImportance = importance; } } } numLights = maxLights; } } } // get the nodes to draw if (!blank) { // empty the render node lists in preparation for the next frame OpenGLGState::clearLists(); orderedList.clear(); shadowList.clear(); flareLightList.clear(); // make the lists of render nodes sorted in optimal rendering order if (sceneIterator) { sceneIterator->reset(); SceneNode* node; while ((node = sceneIterator->getNext()) != NULL) node->getRenderNodes(*this); } // sort ordered list in reverse depth order if (!inOrder) orderedList.sort(frustum.getEye()); } // prepare transforms // note -- lights should not be positioned before view is set frustum.executeDeepProjection(); glPushMatrix(); frustum.executeView(); // turn sunlight on -- the ground needs it if (lighting && sunOrMoonUp) { theSun.execute(SunLight); theSun.enableLight(SunLight); } // turn on fog for teleporter blindness if close to a teleporter float teleporterProximity = 0.0f; if (!blank && LocalPlayer::getMyTank() && (LocalPlayer::getMyTank()->getTeam() != ObserverTeam)) teleporterProximity = LocalPlayer::getMyTank()->getTeleporterProximity(); float worldSize = BZDB.eval(StateDatabase::BZDB_WORLDSIZE); bool reallyUseFogHack = useFogHack && (useQualityValue >= 2); if (reallyUseFogHack) { if (useDimming) { const float density = dimDensity; glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, -density * 1000.0f * worldSize); glFogf(GL_FOG_END, (1.0f - density) * 1000.0f * worldSize); glFogfv(GL_FOG_COLOR, dimnessColor); glEnable(GL_FOG); } else if (teleporterProximity > 0.0f && useFogHack) { const float density = (teleporterProximity > 0.75f) ? 1.0f : teleporterProximity / 0.75f; glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, -density * 1000.0f * worldSize); glFogf(GL_FOG_END, (1.0f - density) * 1000.0f * worldSize); glFogfv(GL_FOG_COLOR, blindnessColor); glEnable(GL_FOG); } } // set scissor glScissor(window.getOriginX(), window.getOriginY() + window.getHeight() - window.getViewHeight(), window.getWidth(), window.getViewHeight()); if (useDepthComplexityOn) { // glEnable(GL_STENCIL_TEST); // glClear(GL_STENCIL_BUFFER_BIT); // glStencilFunc(GL_ALWAYS, 0, 0xf); // glStencilOp(GL_KEEP, GL_INCR, GL_INCR); } if (useHiddenLineOn) { //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // glClear(GL_COLOR_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); } else if (useWireframeOn) { //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } // prepare z buffer /* if (BZDB.isTrue("zbuffer")) { if (sameFrame && ++depthRange == numDepthRanges) depthRange = 0; if (exposed || useHiddenLineOn || --depthRange < 0) { depthRange = numDepthRanges - 1; glClear(GL_DEPTH_BUFFER_BIT); exposed = false; } if (!sameFrame && numDepthRanges != 1) { if (useHiddenLineOn) { glDepthRange(0.0, 1.0); } else { GLclampd x_near = (GLclampd)depthRange * depthRangeSize; glDepthRange(x_near, x_near + depthRangeSize); } } } */ // draw start of background (no depth testing) OpenGLGState::resetState(); if (background) { background->setBlank(blank); background->setInvert(invert); background->renderSkyAndGround(*this, fullWindow); } // prepare the other lights but don't turn them on yet -- // we may need to turn them on when drawing the background. if (lighting) { for (i = 0; i < numLights; i++) lights[i]->execute(i + reservedLights); } // draw rest of background if (background) background->render(*this); if (!blank) { if (lighting) { // now turn on the remaining lights for (i = 0; i < numLights; i++) OpenGLLight::enableLight(i + reservedLights); } frustum.executeProjection(); if (BZDB.isTrue("zbuffer")) glEnable(GL_DEPTH_TEST); if (useHiddenLineOn) { #if defined(GL_VERSION_1_1) glEnable(GL_POLYGON_OFFSET_FILL); #elif defined(GL_EXT_polygon_offset) glEnable(GL_POLYGON_OFFSET_EXT); #endif } // render the normal stuff doRender(); if (useHiddenLineOn) { #if defined(GL_VERSION_1_1) glDisable(GL_POLYGON_OFFSET_FILL); #elif defined(GL_EXT_polygon_offset) glDisable(GL_POLYGON_OFFSET_EXT); #endif glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); doRender(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } OpenGLGState::resetState(); // shut off lights if (lighting) { theSun.enableLight(SunLight, false); for (i = 0; i < numLights; i++) OpenGLLight::enableLight(i + reservedLights, false); } if (BZDB.isTrue("zbuffer")) glDisable(GL_DEPTH_TEST); // FIXME -- must do post-rendering: flare lights, etc. // flare lights are in world coordinates. trace ray to that world // position and calculate opacity. if opaque then don't render // flare, otherwise modulate input color by opacity and draw a // billboard texture (constant size in screen space). } // back to original state if (!useHiddenLineOn && useWireframeOn) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPopMatrix(); if ((reallyUseFogHack && (teleporterProximity > 0.0f || useDimming))) glDisable(GL_FOG); if (!reallyUseFogHack) { float density = 0.0f; const GLfloat* color = NULL; if (useDimming) { density = dimDensity; color = dimnessColor; } else if (teleporterProximity > 0.0f) { density = (teleporterProximity > 0.75f) ? 1.0f : teleporterProximity / 0.75f; color = blindnessColor; } if (density > 0.0f && color != NULL) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glColor4f(color[0], color[1], color[2], density); glRectf(-1.0f, -1.0f, 1.0f, 1.0f); } } if (useDepthComplexityOn) { static const GLfloat depthColors[][3] = { { 0.0f, 0.0f, 0.0f }, // black -- 0 times { 0.5f, 0.0f, 1.0f }, // purple -- 1 time { 0.0f, 0.0f, 1.0f }, // blue -- 2 times { 0.0f, 1.0f, 1.0f }, // cyan -- 3 times { 0.0f, 1.0f, 0.0f }, // green -- 4 times { 1.0f, 1.0f, 0.0f }, // yellow -- 5 times { 1.0f, 0.5f, 0.0f }, // orange -- 6 times { 1.0f, 0.0f, 0.0f } // red -- 7 or more }; static const int numColors = countof(depthColors); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); for (i = 0; i < numColors; i++) { glStencilFunc(i == numColors - 1 ? GL_LEQUAL : GL_EQUAL, i, 0xf); glColor3fv(depthColors[i]); glRectf(-1.0f, -1.0f, 1.0f, 1.0f); } glDisable(GL_STENCIL_TEST); } }
void DirectShowPlayerService::run() { QMutexLocker locker(&m_mutex); for (;;) { ::ResetEvent(m_taskHandle); while (m_pendingTasks == 0) { DWORD result = 0; locker.unlock(); if (m_eventHandle) { HANDLE handles[] = { m_taskHandle, m_eventHandle }; result = ::WaitForMultipleObjects(2, handles, false, INFINITE); } else { result = ::WaitForSingleObject(m_taskHandle, INFINITE); } locker.relock(); if (result == WAIT_OBJECT_0 + 1) { graphEvent(&locker); } } if (m_pendingTasks & ReleaseGraph) { m_pendingTasks ^= ReleaseGraph; m_executingTask = ReleaseGraph; doReleaseGraph(&locker); } else if (m_pendingTasks & Shutdown) { return; } else if (m_pendingTasks & ReleaseAudioOutput) { m_pendingTasks ^= ReleaseAudioOutput; m_executingTask = ReleaseAudioOutput; doReleaseAudioOutput(&locker); } else if (m_pendingTasks & ReleaseVideoOutput) { m_pendingTasks ^= ReleaseVideoOutput; m_executingTask = ReleaseVideoOutput; doReleaseVideoOutput(&locker); } else if (m_pendingTasks & SetUrlSource) { m_pendingTasks ^= SetUrlSource; m_executingTask = SetUrlSource; doSetUrlSource(&locker); } else if (m_pendingTasks & SetStreamSource) { m_pendingTasks ^= SetStreamSource; m_executingTask = SetStreamSource; doSetStreamSource(&locker); } else if (m_pendingTasks & Render) { m_pendingTasks ^= Render; m_executingTask = Render; doRender(&locker); } else if (!(m_executedTasks & Render)) { m_pendingTasks &= ~(FinalizeLoad | SetRate | Stop | Pause | Seek | Play); } else if (m_pendingTasks & FinalizeLoad) { m_pendingTasks ^= FinalizeLoad; m_executingTask = FinalizeLoad; doFinalizeLoad(&locker); } else if (m_pendingTasks & Stop) { m_pendingTasks ^= Stop; m_executingTask = Stop; doStop(&locker); } else if (m_pendingTasks & SetRate) { m_pendingTasks ^= SetRate; m_executingTask = SetRate; doSetRate(&locker); } else if (m_pendingTasks & Pause) { m_pendingTasks ^= Pause; m_executingTask = Pause; doPause(&locker); } else if (m_pendingTasks & Seek) { m_pendingTasks ^= Seek; m_executingTask = Seek; doSeek(&locker); } else if (m_pendingTasks & Play) { m_pendingTasks ^= Play; m_executingTask = Play; doPlay(&locker); } m_executingTask = 0; } }
int main(int argc, char *argv[]) { pthread_t recvThread; srand(time(NULL)); GameState gamestate; SDL_Window *window=NULL; // Declare a window SDL_Renderer *renderer=NULL; // Declare a renderer Entity tempEntity; SDL_Init(SDL_INIT_EVERYTHING); // Initialize SDL2 //srandom((int)time(NULL)); //Create an application window with the following settings: window = SDL_CreateWindow("Game Window", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position SCREEN_WIDTH, // width, in pixels SCREEN_HEIGHT, // height, in pixels 0 // flags ); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); gamestate.renderer=renderer; SDL_Rect cameraScene= {0,0,SCREEN_WIDTH,SCREEN_HEIGHT}; gamestate.nrOfAi=0; loadMedia(&gamestate); ///load images to textures // The window is open: enter program loop (see SDL_PollEvent) /**Event loop*/ int done = 0; // NEDANSTÅENDE SKA BLI EN FUNKTION SOM LIGGER I GAMENET // TODO GÖR 96x96 for(int i = 0;i<100;i++) // initializera ai token listan gamestate.aiEntityToken[i]=0; //Event loop while(1){ for(int i = 0;i<100;i++) // initializera ai token listan gamestate.aiEntityToken[i]=0; threadJoinQuerry = 0; startMenu(renderer,&gamestate); gamestate.castle=createEntity(&tempEntity,896,508,96,96,500.0); while(!done) ///main game loop { for(int i=0;i<maxPlayers;i++){ if(gamestate.playerEntityToken[i]!=0){ gamestate.playerEntity[i].mPosX=getAIPositionX(&gamestate.playerEntity[i]); /// get last mainplayers position gamestate.playerEntity[i].mPosY=getAIPositionY(&gamestate.playerEntity[i]); //coPlayerControll(&gamestate.playerEntity[i]); } } for(int i=0;i<=highestId;i++){ if(gamestate.aiEntityToken[i]!=0){ if(gamestate.AiEntity[i].hpData.currentHp <= 0){ gamestate.aiEntityToken[i] = 0; } } } for(int i=0;i<=highestId;i++){ gamestate.AiEntity[i].mPosX=getAIPositionX(&gamestate.AiEntity[i]); ///AI data gamestate.AiEntity[i].mPosY=getAIPositionY(&gamestate.AiEntity[i]); AITTick(&gamestate.AiEntity[i]); /// AI changes position and checks collision if(gamestate.aiEntityToken[i]!=0){ if(checkIFObjectHit(&gamestate.playerEntity[gamestate.mySlot].attack, &gamestate.AiEntity[i].object.rect)){//Kollar om spelarens attack kolliderar med AIn giveDamage(&gamestate,i); resetAttack(&gamestate.playerEntity[gamestate.mySlot].attack); } } } done = processEvents(window, &gamestate); cameraScene.x=(getmPosX(&gamestate.playerEntity[gamestate.mySlot])+ 20/2)-SCREEN_WIDTH/2; cameraScene.y=(getmPosY(&gamestate.playerEntity[gamestate.mySlot])+20/2)-SCREEN_HEIGHT/2; if( cameraScene.x < 0 ) /// cameraScren follows main player { cameraScene.x = 0; } if( cameraScene.y < 0 ) { cameraScene.y = 0; } if( cameraScene.x > LEVEL_WIDTH - cameraScene.w ) { cameraScene.x = LEVEL_WIDTH - cameraScene.w; } if( cameraScene.y > LEVEL_HEIGHT - cameraScene.h ) { cameraScene.y = LEVEL_HEIGHT - cameraScene.h; } //Render display doRender(renderer, &gamestate,cameraScene); /// renderer Ai , players and map //don't burn up the CPU //SDL_Delay(10); ///***************if players position x,y changes -> send to server***********/// if(getmPosX(&gamestate.playerEntity[gamestate.mySlot])!=gamestate.playerEntity[gamestate.mySlot].mPosX || getmPosY(&gamestate.playerEntity[gamestate.mySlot])!=gamestate.playerEntity[gamestate.mySlot].mPosY){ printf("Attempting to update player movement\n"); updatePlayerMovement(&gamestate); } ///*******'LOSS CONDITION*****//// if(gamestate.castle.hpData.currentHp<=0){ done=1; } } //TODO Rensa upp alla textures osv threadJoinQuerry = 1; pthread_join(recvThread,NULL); SDLNet_TCP_Close(gamestate.socket); lossMenu(renderer); } // Close and destroy the window SDL_DestroyTexture(gamestate.gTileTexture.mTexture); SDL_DestroyTexture(gamestate.mAiTexture); SDL_DestroyTexture(gamestate.playerEntity[0].object.mTexture); ///clear Textures SDL_DestroyTexture(gamestate.playerEntity[1].object.mTexture); SDL_DestroyWindow(window); SDL_DestroyRenderer(renderer); // Clean up SDL_Quit(); //pthread_join(recvThread,NULL); // close(gamestate.socket); return 0; }
int main(void) { gamestate game; SDL_Window* window = NULL; game.renderer = NULL; SDL_Init(SDL_INIT_VIDEO); time_t t; srand(time(&t)); window = SDL_CreateWindow( "Game Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 ); if (window == NULL) { printf("Window initialization failed: %s\n", SDL_GetError()); return 1; } game.renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); TTF_Init(); if (game.renderer == NULL) { printf("Rendering failed: %s\n", SDL_GetError()); return 1; } loadGame(&game); int done = 0; while (!done) { processEvents(window, &done, &game); process(&game); collisionDetect(&game); doRender(&game); } SDL_DestroyTexture(game.spook[0]); SDL_DestroyTexture(game.spook[1]); SDL_DestroyTexture(game.spook[2]); SDL_DestroyTexture(game.tile); if (game.label != NULL) { SDL_DestroyTexture(game.label); } TTF_CloseFont(game.font); SDL_DestroyWindow(window); SDL_DestroyRenderer(game.renderer); TTF_Quit(); SDL_Quit(); return 0; }
void ClusterServer::render(RenderActionBase *action) { doSync (false ); doRender(action); doSwap ( ); }
void QgsMapRendererCustomPainterJob::start() { if ( isActive() ) return; mRenderingStart.start(); mActive = true; mErrors.clear(); QgsDebugMsg( "QPAINTER run!" ); QgsDebugMsg( "Preparing list of layer jobs for rendering" ); QTime prepareTime; prepareTime.start(); // clear the background mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() ); mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) ); #ifndef QT_NO_DEBUG QPaintDevice* thePaintDevice = mPainter->device(); QString errMsg = QString( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() ); Q_ASSERT_X( qgsDoubleNear( thePaintDevice->logicalDpiX(), mSettings.outputDpi() ), "Job::startRender()", errMsg.toAscii().data() ); #endif delete mLabelingEngine; mLabelingEngine = nullptr; delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { #ifdef LABELING_V2 mLabelingEngineV2 = new QgsLabelingEngineV2(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); #else mLabelingEngine = new QgsPalLabeling; mLabelingEngine->loadEngineSettings(); mLabelingEngine->init( mSettings ); #endif } mLayerJobs = prepareJobs( mPainter, mLabelingEngine, mLabelingEngineV2 ); // prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider, // whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a // QEventLoop waiting for the network request to complete. If unluckily someone calls // mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is // called, deleting the QgsMapRendererCustomPainterJob while this function is running. // Hence we need to check whether the job is still active before proceeding if ( !isActive() ) return; QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) ); if ( mRenderSynchronously ) { // do the rendering right now! doRender(); return; } // now we are ready to start rendering! connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) ); mFuture = QtConcurrent::run( staticRender, this ); mFutureWatcher.setFuture( mFuture ); }