diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2011-12-31 10:04:46 +0100 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2011-12-31 10:04:46 +0100 |
| commit | 7a36a103aec1c0aafc89a45a4c7fb82944e6baba (patch) | |
| tree | e698f27932240b7b6d7ddc357be02cf4f498d9d5 /src/engine | |
| parent | 8a91bfa1ddff0c99d65375b8b5c57e710169543a (diff) | |
| download | zcatch-7a36a103aec1c0aafc89a45a4c7fb82944e6baba.tar.gz zcatch-7a36a103aec1c0aafc89a45a4c7fb82944e6baba.zip | |
fixed so that the rendering can be done async from the input, network and update
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/client/client.cpp | 17 | ||||
| -rw-r--r-- | src/engine/client/graphics.cpp | 15 | ||||
| -rw-r--r-- | src/engine/client/graphics.h | 4 | ||||
| -rw-r--r-- | src/engine/client/graphics_threaded.cpp | 70 | ||||
| -rw-r--r-- | src/engine/client/graphics_threaded.h | 11 | ||||
| -rw-r--r-- | src/engine/graphics.h | 7 | ||||
| -rw-r--r-- | src/engine/shared/config_variables.h | 1 |
7 files changed, 106 insertions, 19 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index bb888c60..53f60fa8 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1853,19 +1853,22 @@ void CClient::Run() Update(); - if(g_Config.m_DbgStress) + if(!g_Config.m_GfxAsyncRender || m_pGraphics->IsIdle()) { - if((m_Frames%10) == 0) + if(g_Config.m_DbgStress) + { + if((m_Frames%10) == 0) + { + Render(); + m_pGraphics->Swap(); + } + } + else { Render(); m_pGraphics->Swap(); } } - else - { - Render(); - m_pGraphics->Swap(); - } } AutoScreenshot_Cleanup(); diff --git a/src/engine/client/graphics.cpp b/src/engine/client/graphics.cpp index b78e5387..03a6e7cd 100644 --- a/src/engine/client/graphics.cpp +++ b/src/engine/client/graphics.cpp @@ -963,4 +963,19 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes) return NumModes; } +// syncronization +void CGraphics_SDL::InsertSignal(semaphore *pSemaphore) +{ + pSemaphore->signal(); +} + +bool CGraphics_SDL::IsIdle() +{ + return true; +} + +void CGraphics_SDL::WaitForIdle() +{ +} + //extern IEngineGraphics *CreateEngineGraphics() { return new CGraphics_SDL(); } diff --git a/src/engine/client/graphics.h b/src/engine/client/graphics.h index d97513f3..37276d36 100644 --- a/src/engine/client/graphics.h +++ b/src/engine/client/graphics.h @@ -144,6 +144,10 @@ public: virtual int GetVideoModes(CVideoMode *pModes, int MaxModes); + // syncronization + virtual void InsertSignal(semaphore *pSemaphore); + virtual bool IsIdle(); + virtual void WaitForIdle(); }; #endif diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index ade77ef4..e702133a 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -45,6 +45,28 @@ static CVideoMode g_aFakeModes[] = { {2048,1536,5,6,5} }; +class CCommandProcessorFragment_General +{ +public: + bool RunCommand(const CCommandBuffer::SCommand * pBaseCommand) + { + + switch(pBaseCommand->m_Cmd) + { + case CCommandBuffer::CMD_SIGNAL: + { + const CCommandBuffer::SCommand_Signal *pCommand = static_cast<const CCommandBuffer::SCommand_Signal *>(pBaseCommand); + pCommand->m_pSemaphore->signal(); + } break; + default: + return false; + break; + } + + return true; + } +}; + class CCommandProcessorFragment_OpenGL { @@ -154,15 +176,15 @@ public: { case CCommandBuffer::CMD_TEXTURE_CREATE: { - Cmd_Texture_Create((const CCommandBuffer::SCommand_Texture_Create *)pBaseCommand); + Cmd_Texture_Create(static_cast<const CCommandBuffer::SCommand_Texture_Create *>(pBaseCommand)); } break; case CCommandBuffer::CMD_TEXTURE_DESTROY: { - Cmd_Texture_Destroy((const CCommandBuffer::SCommand_Texture_Destroy *)pBaseCommand); + Cmd_Texture_Destroy(static_cast<const CCommandBuffer::SCommand_Texture_Destroy *>(pBaseCommand)); } break; case CCommandBuffer::CMD_TEXTURE_UPDATE: { - Cmd_Texture_Update((const CCommandBuffer::SCommand_Texture_Update *)pBaseCommand); + Cmd_Texture_Update(static_cast<const CCommandBuffer::SCommand_Texture_Update *>(pBaseCommand)); } break; case CCommandBuffer::CMD_CLEAR: { @@ -172,7 +194,7 @@ public: } break; case CCommandBuffer::CMD_RENDER: { - const CCommandBuffer::SCommand_Render *pCommand = (CCommandBuffer::SCommand_Render *)pBaseCommand; + const CCommandBuffer::SCommand_Render *pCommand = static_cast<const CCommandBuffer::SCommand_Render *>(pBaseCommand); SetState(pCommand->m_State); glVertexPointer(3, GL_FLOAT, sizeof(CCommandBuffer::SVertex), (char*)pCommand->m_pVertices); @@ -354,7 +376,7 @@ public: break; case CCommandBuffer::CMD_INIT: { - const CCommandBuffer::SCommand_Init *pCommand = (CCommandBuffer::SCommand_Init *)pBaseCommand; + const CCommandBuffer::SCommand_Init *pCommand = static_cast<const CCommandBuffer::SCommand_Init *>(pBaseCommand); *pCommand->m_pResult = Init(); } break; case CCommandBuffer::CMD_SHUTDOWN: @@ -372,18 +394,18 @@ public: } }; - class CCommandProcessor_SDL_OpenGL : public ICommandProcessor { CCommandProcessorFragment_OpenGL m_OpenGL; CCommandProcessorFragment_SDL m_SDL; + CCommandProcessorFragment_General m_General; public: virtual void RunBuffer(CCommandBuffer *pBuffer) { unsigned CmdIndex = 0; while(1) { - CCommandBuffer::SCommand * const pBaseCommand = pBuffer->GetCommand(&CmdIndex); + const CCommandBuffer::SCommand *pBaseCommand = pBuffer->GetCommand(&CmdIndex); if(pBaseCommand == 0x0) break; @@ -392,6 +414,9 @@ class CCommandProcessor_SDL_OpenGL : public ICommandProcessor if(m_SDL.RunCommand(pBaseCommand)) continue; + + if(m_General.RunCommand(pBaseCommand)) + continue; dbg_msg("graphics", "unknown command %d", pBaseCommand->m_Cmd); } @@ -547,7 +572,10 @@ CGraphics_Threaded::CGraphics_Threaded() m_State.m_Texture = -1; m_State.m_BlendMode = CCommandBuffer::BLEND_NONE; - + m_CurrentCommandBuffer = 0; + m_pCommandBuffer = 0x0; + m_apCommandBuffers[0] = 0x0; + m_apCommandBuffers[1] = 0x0; m_NumVertices = 0; @@ -748,7 +776,7 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const // m_pCommandBuffer->AddCommand(Cmd); - + // calculate memory usage int MemUsage = MemSize; while(Width > 2 && Height > 2) @@ -1188,14 +1216,34 @@ void CGraphics_Threaded::Swap() m_DoScreenshot = false; }*/ + // add swap command CCommandBuffer::SCommand_Swap Cmd; m_pCommandBuffer->AddCommand(Cmd); - m_Handler.RunBuffer(m_pCommandBuffer); - m_Handler.WaitForIdle(); + + // swap buffer + m_CurrentCommandBuffer ^= 1; + m_pCommandBuffer = m_apCommandBuffers[m_CurrentCommandBuffer]; m_pCommandBuffer->Reset(); } +// syncronization +void CGraphics_Threaded::InsertSignal(semaphore *pSemaphore) +{ + CCommandBuffer::SCommand_Signal Cmd; + Cmd.m_pSemaphore = pSemaphore; + m_pCommandBuffer->AddCommand(Cmd); +} + +bool CGraphics_Threaded::IsIdle() +{ + return m_Handler.IsIdle(); +} + +void CGraphics_Threaded::WaitForIdle() +{ + m_Handler.WaitForIdle(); +} int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes) { diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 1ec8c61c..a4c4ab40 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -143,12 +143,17 @@ public: SColor m_Color; }; - struct SCommand_Init : public SCommand { SCommand_Init() : SCommand(CMD_INIT) {} volatile int *m_pResult; }; + + struct SCommand_Signal : public SCommand + { + SCommand_Signal() : SCommand(CMD_SIGNAL) {} + semaphore *m_pSemaphore; + }; struct SCommand_RunBuffer : public SCommand { @@ -393,4 +398,8 @@ public: virtual int GetVideoModes(CVideoMode *pModes, int MaxModes); + // syncronization + virtual void InsertSignal(semaphore *pSemaphore); + virtual bool IsIdle(); + virtual void WaitForIdle(); }; \ No newline at end of file diff --git a/src/engine/graphics.h b/src/engine/graphics.h index cbc6a331..1c79ee15 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -5,6 +5,8 @@ #include "kernel.h" +#include <base/tl/threading.h> + class CImageInfo { public: @@ -132,6 +134,11 @@ public: virtual int GetVideoModes(CVideoMode *pModes, int MaxModes) = 0; virtual void Swap() = 0; + + // syncronization + virtual void InsertSignal(semaphore *pSemaphore) = 0; + virtual bool IsIdle() = 0; + virtual void WaitForIdle() = 0; }; class IEngineGraphics : public IGraphics diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index c812063a..352cefd8 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -70,6 +70,7 @@ MACRO_CONFIG_INT(GfxTextureQuality, gfx_texture_quality, 1, 0, 1, CFGFLAG_SAVE|C MACRO_CONFIG_INT(GfxFsaaSamples, gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples") MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate") MACRO_CONFIG_INT(GfxFinish, gfx_finish, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") +MACRO_CONFIG_INT(GfxAsyncRender, gfx_asyncrender, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Do rendering async from the the update") MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") |