static void SlowSwapBufferParts(char* begin1, char* end1, char* begin2, char* end2) { unsigned len1, len2, difference; assert(begin1 && end1 && begin2 && end2); len1 = (unsigned)(end1-begin1); len2 = (unsigned)(end2-begin2); if (len1 < len2) { difference = len2-len1; RotateBufRight(end1, begin2+difference, difference); SwapBuffer(begin1, begin2+difference, len1); RotateBufRight(begin1, end1+difference, difference); } else if (len1 > len2) { difference = len1-len2; RotateBufLeft(end1-difference, begin2, difference); SwapBuffer(begin1, begin2, len2); RotateBufLeft(begin2-difference, end2, difference); } else /* len1 == len2 */ { SwapBuffer(begin1, begin2, len1); } }
CPLErr SAGARasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { if( nBlockYOff < 0 || nBlockYOff > nRasterYSize - 1 || nBlockXOff != 0 ) return CE_Failure; SAGADataset *poGDS = dynamic_cast<SAGADataset *>(poDS); vsi_l_offset offset = (vsi_l_offset) (m_nBits / 8) * nRasterXSize * (nRasterYSize - nBlockYOff - 1); if( VSIFSeekL( poGDS->fp, offset, SEEK_SET ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Unable to seek to beginning of grid row.\n" ); return CE_Failure; } if( VSIFReadL( pImage, m_nBits / 8, nBlockXSize, poGDS->fp ) != static_cast<unsigned>(nBlockXSize) ) { CPLError( CE_Failure, CPLE_FileIO, "Unable to read block from grid file.\n" ); return CE_Failure; } SwapBuffer(pImage); return CE_None; }
void DiRenderWindow::Render() { if (!mEnable) return; DI_PROFILE(RenderWindow_Render); if (mWindow) mWindow->Update(); mCurrentPrimitivesNum = 0; mCurrentBatchesNum = 0; // cull and update DiCamera* mainCam = mSceneManager->GetCamera(); mSceneManager->PreUpdate(); mSceneManager->Cull(mainCam); mSceneManager->GetVisibleObjects().UpdateAll(mainCam); Driver->BeginFrame(); // TODO: update RTs DiRenderPipeline* rp = Driver->GetPipeline(); rp->ClearGroup(); mSceneManager->GetVisibleObjects().AddToBatch(rp); rp->Render(mSceneManager, mainCam, mSceneCanvas); Driver->EndFrame(); SwapBuffer(); }
// Is the game running bool Device::IsRunning() { #ifdef WIN32 MSG msg = { 0 }; int gotMsg = (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0); if ( gotMsg ) { if (msg.message == WM_QUIT) { isRunning = false; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { SendMessage(windowHandler, WM_PAINT, 0, 0); } #endif GameTime::Update(); SwapBuffer(); return isRunning; }
void SwapBuffers (void) { int i; for (i = 0; i < MAX_BUFFER; i++) SwapBuffer (&Buffers[i]); SetCrosshairRangeToBuffer (); }
/* If the current machine is big-endian, swap the buffer. * Otherwise do nothing. * BTW: big-endian is "network byte order" */ static void *AdjustBuffer(void *p, unsigned num_items, unsigned item_size) { /* int z=1; */ /* unsigned char *c=(unsigned char *)&z; */ /* ^ is xor */ /* if((c[0]==0) ^ swap_override) */ if(swap_override) return SwapBuffer(p, num_items, item_size); return p; }
CPLErr SAGARasterBand::IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage ) { if( eAccess == GA_ReadOnly ) { CPLError( CE_Failure, CPLE_NoWriteAccess, "Unable to write block, dataset opened read only.\n" ); return CE_Failure; } if( nBlockYOff < 0 || nBlockYOff > nRasterYSize - 1 || nBlockXOff != 0 ) return CE_Failure; vsi_l_offset offset = (vsi_l_offset) (m_nBits / 8) * nRasterXSize * (nRasterYSize - nBlockYOff - 1); SAGADataset *poGDS = dynamic_cast<SAGADataset *>(poDS); assert( poGDS != NULL ); if( VSIFSeekL( poGDS->fp, offset, SEEK_SET ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Unable to seek to beginning of grid row.\n" ); return CE_Failure; } SwapBuffer(pImage); int bSuccess = ( VSIFWriteL( pImage, m_nBits / 8, nBlockXSize, poGDS->fp ) == static_cast<unsigned>(nBlockXSize) ); SwapBuffer(pImage); if (!bSuccess) { CPLError( CE_Failure, CPLE_FileIO, "Unable to write block to grid file.\n" ); return CE_Failure; } return CE_None; }
/* --------------------------------------------------------------------------- * loads element data from file/library into buffer * parse the file with disabled 'PCB mode' (see parser) * returns false on error * if successful, update some other stuff and reposition the pastebuffer */ bool LoadElementToBuffer (BufferType *Buffer, char *Name, bool FromFile) { ElementType *element; ClearBuffer (Buffer); if (FromFile) { if (!ParseElementFile (Buffer->Data, Name)) { if (Settings.ShowSolderSide) SwapBuffer (Buffer); SetBufferBoundingBox (Buffer); if (Buffer->Data->ElementN) { element = Buffer->Data->Element->data; Buffer->X = element->MarkX; Buffer->Y = element->MarkY; } else { Buffer->X = 0; Buffer->Y = 0; } return (true); } } else { if (!ParseLibraryEntry (Buffer->Data, Name) && Buffer->Data->ElementN != 0) { element = Buffer->Data->Element->data; /* always add elements using top-side coordinates */ if (Settings.ShowSolderSide) MirrorElementCoordinates (Buffer->Data, element, 0); SetElementBoundingBox (Buffer->Data, element, &PCB->Font); /* set buffer offset to 'mark' position */ Buffer->X = element->MarkX; Buffer->Y = element->MarkY; SetBufferBoundingBox (Buffer); return (true); } } /* release memory which might have been acquired */ ClearBuffer (Buffer); return (false); }
//====================================================================== RVNET_DATATYPE WriteNWords(unsigned char *pxPack) { volatile uint16 base, wnum; // ���������� ��������� ������ � ����������� ���� base = *(pxPack) << 8; base += *(pxPack + 1); wnum = *(pxPack + 2) << 8; wnum += *(pxPack + 3); if (wnum > 123) { return ErrorAddress(pxPack); } SwapBuffer(pxPack + 5, wnum); if (MemSetWords(base, pxPack + 5, wnum) == 0) { return ErrorAddress(pxPack); } return 4; }
//====================================================================== RVNET_DATATYPE ReadNWords(uint8 *pxPack) { volatile uint16 base, wnum; // ���������� ��������� ������ � ����������� ���� base = *(pxPack) << 8; base += *(pxPack + 1); wnum = *(pxPack + 2) << 8; wnum += *(pxPack + 3); if (wnum > 123) { return ErrorAddress(pxPack); } *pxPack = (unsigned char) (wnum * 2); if (MemGetWords(base, (uint16*)(pxPack + 1), wnum) == 0) { return ErrorAddress(pxPack); } SwapBuffer(pxPack + 1, wnum); return (RVNET_DATATYPE)(wnum * 2 + 1); }
DWORD CViewGame::ThreadRenderScene() { float factor=4; glClearColor(0.0f,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glColor3ub(255,0,0); /* glColor3ub(255,0,0); glBegin(GL_LINE_LOOP); for (int i=0;i<360;i+=45) { glVertex3d(Game_ColX+0.05*cos(i),Game_ColY+0.05*sin(i),Game_ColZ); } glEnd(); */ Fly(); glFinish(); SwapBuffer(); glPopMatrix(); return 0; }
// int main(int argc, char* argv[]) int GameMain() { // assert(argc || argv[0]); // Fixes the compiler complaining about unused values; GameState* game_state = CreateNewGameState("EnGen", 1600, 900); Renderer* renderer = game_state->renderer; game_state->active_scene = PushScene(&game_state->permanent_memory, MAX_GAME_ENTITES); TileMap* tilemap = game_state->active_scene->tilemap; for (int32 i = 0; i < 10; ++i) { Vec2 pos = { (float)i, 2.f }; AddTileToMap(tilemap, pos); } for (int32 i = 0; i < 10; ++i) { Vec2 pos = { 0, (float)i }; AddTileToMap(tilemap, pos); } for (int32 i = 0; i < 10; ++i) { Vec2 pos = { 10.f, (float)i }; AddTileToMap(tilemap, pos); } UIWindow* ui = PushStruct(&game_state->permanent_memory, UIWindow); SetTitle(ui, "Editor UI!"); SetSize(ui, { 0.1f, 0.3f, 0.2f, 0.2f }, 0.05f); UIWindow* ui2 = PushStruct(&game_state->permanent_memory, UIWindow); SetTitle(ui2, "Editor UI2!"); SetSize(ui2, { 0.2f, 0.3f, 0.2f, 0.2f }, 0.05f); InitializeDebugConsole(); #if 0 InitializeAudio(); char* test_sound_file = "C:\\projects\\imperial_march.wav"; bool test_sound_loaded = LoadWavFile(test_sound_file); if(test_sound_loaded) { printf("Loaded File\n"); } PauseAudio(false); #endif Camera default_camera = {}; // maybe put this in game_state? default_camera.position = vec2(0, 0); default_camera.viewport_size.x = 16; default_camera.viewport_size.y = 9; uint32 frame_count = 0; uint32 fps = 0; double last_fps_time = 0; bool running = true; while (running) { ProfileBeginFrame(); ProfileBeginSection(Profile_Frame); ProfileBeginSection(Profile_Input); Platform_RunMessageLoop(game_state->input); Camera* draw_camera = game_state->active_camera ? game_state->active_camera : &default_camera; game_state->window.resolution = Platform_GetResolution(); UpdateMouseWorldPosition(game_state->input, game_state->window.resolution, draw_camera->viewport_size, draw_camera->position); ProfileEndSection(Profile_Input); Vec2i mouse_pos = MousePosition(game_state->input); //DebugPrintf("Mouse World Position: (%.2f, %.2f)", mouse_pos.x, mouse_pos.y); DebugPrintf("Mouse World Position: (%d, %d)", mouse_pos.x, mouse_pos.y); DebugPrintf("Main Camera Position: (%.2f, %.2f)", default_camera.position.x, default_camera.position.y); DebugPrintf("Key Pressed: %s", IsDown(game_state->input, KeyCode_a) ? "TRUE" : "FALSE"); if (OnDown(game_state->input, KeyCode_ESCAPE)) { running = false; break; } #if 0 // TODO: Platform layer if (OnDown(game_state->input, KeyCode_z)) { ForceColorClear(); SwapBuffer(game_state); //WindowSetScreenMode(&game_state->window, ScreenMode_Windowed); } else if (OnDown(game_state->input, KeyCode_c)) { ForceColorClear(); SwapBuffer(game_state); //WindowSetScreenMode(&game_state->window, ScreenMode_Borderless); } #endif static bool draw_debug = true; if (OnDown(game_state->input, KeyCode_BACKQUOTE)) { draw_debug = !draw_debug; } Renderer* debug_renderer = draw_debug ? renderer : 0; TimeBeginFrame(game_state); // Update the scene first, pushing draw calls if necessary. // Then call begin_frame which builds matrices and clears buffers; float current_time = CurrentTime(game_state); if (current_time - last_fps_time > 1.0f) { last_fps_time = current_time; fps = frame_count; frame_count = 0; } frame_count++; DebugPrintf("FPS: \t\t%d \tFrames: \t%d", fps, FrameCount(game_state)); DebugControlCamera(game_state, &default_camera); // TODO(cgenova): separate update and render calls so that things can be set up when rendering begins; BeginFrame(renderer, &game_state->window); ProfileBeginSection(Profile_SceneUpdate); DebugPrintPushColor(vec4(1.0f, 0, 0, 1.0f)); DebugPrintf("Active scene entity usage: (%d / %d)", game_state->active_scene->active_entities, MAX_GAME_ENTITES); DebugPrintPopColor(); UpdateSceneEntities(game_state, game_state->active_scene); DrawSceneEntities(game_state->active_scene, renderer); ProfileEndSection(Profile_SceneUpdate); #if 1 // Spaghetti test const size_t num_verts = 200; static SimpleVertex v[num_verts]; static bool initialized = false; if (!initialized) { initialized = true; for (uint32 i = 0; i < num_verts; ++i) { SimpleVertex verts = {}; verts.position = vec2((float)(i / 50.f) - 2.f, (float)i); verts.color = vec4(1, 1, 0, 1.f); v[i] = verts; } } else { for (uint32 i = 0; i < num_verts; ++i) { v[i].position.y = sin(CurrentTime(game_state) + i / (PI * 20)); } } PrimitiveDrawParams spaghetti_params = {}; spaghetti_params.line_draw_flags |= PrimitiveDraw_Smooth; // spaghetti_params.line_draw_flags |= Draw_ScreenSpace; spaghetti_params.line_width = 0; DrawLine(renderer, v, num_verts, spaghetti_params); #endif DrawTileMap(game_state, game_state->active_scene->tilemap); UpdateUIWindow(game_state, ui); UpdateUIWindow(game_state, ui2); RenderDrawBuffer(renderer, draw_camera); ProfileEndSection(Profile_Frame); ProfileEndFrame(debug_renderer, TARGET_FPS); DebugDrawConsole(debug_renderer); // NOTE: // For drawing Debug info, the profiling in this section will be discarded, // but it is only drawing text and the debug graph. RenderDrawBuffer(renderer, draw_camera); SwapBuffer(game_state); // TODO(cgenova): High granularity sleep function! ResetArena(&game_state->temporary_memory); }// End main loop return 1; }
//---------------------------------------------------------------------------- //! @brief A sample has been delivered. Copy it to the texture. //! @param pSample : サンプルの IMediaSample インターフェイスへのポインタ //! @return エラーコード //---------------------------------------------------------------------------- HRESULT TBufferRenderer::DoRenderSample( IMediaSample * pSample ) { DWORD *pBmpBuffer, *pTxtBuffer; // Bitmap buffer, texture buffer BYTE *pTxtOrgPos; // if( m_bEOS ) return S_OK; CAutoLock cAutoLock(&m_BufferLock); // クリティカルセクション // Get the video bitmap buffer pSample->GetPointer( reinterpret_cast<BYTE**>(&pBmpBuffer) ); // Get the texture buffer & pitch pTxtBuffer = reinterpret_cast<DWORD*>(GetBackBuffer()); pTxtOrgPos = reinterpret_cast<BYTE*>(pTxtBuffer); HRESULT hr; LONG EventParam1 = -1; LONGLONG TimeStart = 0; LONGLONG TimeEnd = 0; if( SUCCEEDED(hr = pSample->GetMediaTime( &TimeStart, &TimeEnd )) ) { EventParam1 = (LONG)TimeStart; } if( m_StopFrame && EventParam1 >= m_StopFrame ) return S_OK; // 再生しないフレーム if( pTxtBuffer == pBmpBuffer ) // 自前のアロケーターが使われている { SwapBuffer( pSample ); // FrontとBackバッファを入れ替える if( m_pSink ) m_pSink->Notify( EC_UPDATE, EventParam1, NULL ); return S_OK; } // 自前のアロケーターではないのでメモリをコピーする #if 0 // 下から上にコピー(上下反転化) { int height = m_VideoHeight; int width = m_VideoWidth; pBmpBuffer += width * (height-1); for( int j = 0; j < height; j++ ) { for( int i = 0; i < width; i++ ) { pTxtBuffer[i] = pBmpBuffer[i]; } pBmpBuffer -= width; pTxtBuffer += width; } } #else // 上から下にコピー { int height = m_VideoHeight; int width = m_VideoWidth; for( int j = 0; j < height; j++ ) { for( int i = 0; i < width; i++ ) { pTxtBuffer[i] = pBmpBuffer[i]; } pBmpBuffer += width; pTxtBuffer += width; } } #endif if( m_pSink ) m_pSink->Notify( EC_UPDATE, EventParam1, NULL ); SwapBuffer( pSample ); // FrontとBackバッファを入れ替える return S_OK; }
HRESULT CDXUTSDKMesh::CreateFromMemory(ID3D11Device* pDev11, BYTE* pData, UINT /*DataBytes*/, bool /*bCreateAdjacencyIndices*/, bool bCopyStatic) { HRESULT hr = E_FAIL; m_pDev11 = pDev11; m_bCopyStatic = bCopyStatic; // Set outstanding resources to zero m_NumOutstandingResources = 0; if (bCopyStatic) { SDKMESH_HEADER* pHeader = (SDKMESH_HEADER*)pData; SIZE_T StaticSize = (SIZE_T)(pHeader->HeaderSize + pHeader->NonBufferDataSize); m_pHeapData = new BYTE[StaticSize]; if (!m_pHeapData) return hr; m_pStaticMeshData = m_pHeapData; CopyMemory(m_pStaticMeshData, pData, StaticSize); } else { m_pHeapData = pData; m_pStaticMeshData = pData; } // Pointer fixup m_pMeshHeader = (SDKMESH_HEADER*)m_pStaticMeshData; #ifdef _XBOX SwapSDKMeshHeader(m_pMeshHeader); #endif m_pVertexBufferArray = (SDKMESH_VERTEX_BUFFER_HEADER*)(m_pStaticMeshData + m_pMeshHeader->VertexStreamHeadersOffset); #ifdef _XBOX SwapVertexBufferHeaderArray(m_pVertexBufferArray, m_pMeshHeader->NumVertexBuffers); #endif m_pIndexBufferArray = (SDKMESH_INDEX_BUFFER_HEADER*)(m_pStaticMeshData + m_pMeshHeader->IndexStreamHeadersOffset); #ifdef _XBOX SwapIndexBufferHeaderArray(m_pIndexBufferArray, m_pMeshHeader->NumIndexBuffers); #endif m_pMeshArray = (SDKMESH_MESH*)(m_pStaticMeshData + m_pMeshHeader->MeshDataOffset); #ifdef _XBOX SwapMeshArray(m_pMeshArray, m_pMeshHeader->NumMeshes); #endif m_pSubsetArray = (SDKMESH_SUBSET*)(m_pStaticMeshData + m_pMeshHeader->SubsetDataOffset); #ifdef _XBOX SwapSubsetArray(m_pSubsetArray, m_pMeshHeader->NumTotalSubsets); #endif m_pFrameArray = (SDKMESH_FRAME*)(m_pStaticMeshData + m_pMeshHeader->FrameDataOffset); #ifdef _XBOX SwapFrameArray(m_pFrameArray, m_pMeshHeader->NumFrames); #endif m_pMaterialArray = (SDKMESH_MATERIAL*)(m_pStaticMeshData + m_pMeshHeader->MaterialDataOffset); #ifdef _XBOX SwapMaterialArray(m_pMaterialArray, m_pMeshHeader->NumMaterials); #endif // Setup subsets for (UINT i = 0; i < m_pMeshHeader->NumMeshes; i++) { m_pMeshArray[i].pSubsets = (UINT*)(m_pStaticMeshData + m_pMeshArray[i].SubsetOffset); m_pMeshArray[i].pFrameInfluences = (UINT*)(m_pStaticMeshData + m_pMeshArray[i].FrameInfluenceOffset); } // error condition if (m_pMeshHeader->Version != SDKMESH_FILE_VERSION) { hr = E_NOINTERFACE; goto Error; } // Setup buffer data pointer BYTE* pBufferData = pData + m_pMeshHeader->HeaderSize + m_pMeshHeader->NonBufferDataSize; // Get the start of the buffer data UINT64 BufferDataStart = m_pMeshHeader->HeaderSize + m_pMeshHeader->NonBufferDataSize; // Create VBs m_ppVertices = new BYTE*[m_pMeshHeader->NumVertexBuffers]; for (UINT i = 0; i < m_pMeshHeader->NumVertexBuffers; i++) { BYTE* pVertices = NULL; pVertices = (BYTE*)(pBufferData + (m_pVertexBufferArray[i].DataOffset - BufferDataStart)); #ifdef _XBOX SwapBuffer((DWORD *)pVertices, m_pVertexBufferArray[i].SizeBytes); #endif if (pDev11) CreateVertexBuffer(pDev11, &m_pVertexBufferArray[i], pVertices); m_ppVertices[i] = pVertices; } // Create IBs m_ppIndices = new BYTE*[m_pMeshHeader->NumIndexBuffers]; for (UINT i = 0; i < m_pMeshHeader->NumIndexBuffers; i++) { BYTE* pIndices = NULL; pIndices = (BYTE*)(pBufferData + (m_pIndexBufferArray[i].DataOffset - BufferDataStart)); #ifdef _XBOX SwapBuffer((DWORD *)pIndices, m_pIndexBufferArray[i].SizeBytes); #endif if (pDev11) CreateIndexBuffer(pDev11, &m_pIndexBufferArray[i], pIndices); m_ppIndices[i] = pIndices; } // Create a place to store our bind pose frame matrices m_pBindPoseFrameMatrices = new MATRIX[m_pMeshHeader->NumFrames]; if (!m_pBindPoseFrameMatrices) goto Error; // Create a place to store our transformed frame matrices m_pTransformedFrameMatrices = new MATRIX[m_pMeshHeader->NumFrames]; if (!m_pTransformedFrameMatrices) goto Error; m_pWorldPoseFrameMatrices = new MATRIX[m_pMeshHeader->NumFrames]; if (!m_pWorldPoseFrameMatrices) goto Error; hr = S_OK; Error: return hr; }
int main() { int i, j; long k; char buffer[] = {'0', '1','2','3','4','5','6','7','8','9'}; time_t t1, t2; clrscr(); time (&t1); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); for (j = 0; j < 10; j++) { RotateBufRight(buffer, &buffer[10], j); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); } time(&t2); printf("\n%f\n", difftime(t2, t1)); getch();puts("\n\n"); clrscr(); for (j = 0; j < 10; j++) { RotateBufLeft(buffer, &buffer[10], j); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); } puts("\n\n"); SwapBuffer(&buffer[0], &buffer[5], 5); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); puts("\n\n"); SwapBuffer(&buffer[0], &buffer[5], 5); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); puts("\n\n"); RotateBufLeft(&buffer[0], &buffer[10], 2); SlowSwapBufferParts(&buffer[1], &buffer[5], &buffer[7], &buffer[9]); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); SwapBufferParts(&buffer[1], &buffer[5], &buffer[7], &buffer[9]); for (i = 0; i < 10; i++) printf("%c", buffer[i]); puts(""); }