started writing map background in menu

This commit is contained in:
SushiTee 2011-10-05 17:22:22 +02:00 committed by oy
parent b52144fef8
commit fcabed11b4
9 changed files with 117 additions and 34 deletions

View file

@ -45,6 +45,14 @@ public:
operator const T* () { return &x; }
};
template<typename T>
inline vector2_base<T> rotate(const vector2_base<T> &a, float angle)
{
angle = angle * 3.1415926535897932384626433f / 180.0f;
float s = sin(angle);
float c = cos(angle);
return vector2_base<T>((T)(c*a.x - s*a.y), (T)(s*a.x + c*a.y));
}
template<typename T>
inline T length(const vector2_base<T> &a)

View file

@ -19,6 +19,9 @@ protected:
float m_GameIntraTick;
float m_GameTickTime;
int m_CurMenuTick;
int64 m_MenuStartTime;
int m_PredTick;
float m_PredIntraTick;
@ -61,6 +64,7 @@ public:
// tick time access
inline int PrevGameTick() const { return m_PrevGameTick; }
inline int GameTick() const { return m_CurGameTick; }
inline int MenuTick() const { return m_CurMenuTick; }
inline int PredGameTick() const { return m_PredTick; }
inline float IntraGameTick() const { return m_GameIntraTick; }
inline float PredIntraGameTick() const { return m_PredIntraTick; }
@ -85,6 +89,8 @@ public:
// networking
virtual void EnterGame() = 0;
virtual void LoadBackgroundMap(const char *pName, const char *pFilename) = 0;
virtual bool MapLoaded() = 0;
//
virtual int MapDownloadAmount() = 0;
virtual int MapDownloadTotalsize() = 0;

View file

@ -497,6 +497,7 @@ void CClient::OnEnterGame()
m_CurrentRecvTick = 0;
m_CurGameTick = 0;
m_PrevGameTick = 0;
m_CurMenuTick = 0;
}
void CClient::EnterGame()
@ -774,6 +775,24 @@ void CClient::Render()
DebugRender();
}
bool CClient::MapLoaded()
{
return m_pMap->IsLoaded();
}
void CClient::LoadBackgroundMap(const char *pName, const char *pFilename)
{
if(!m_pMap->Load(pFilename))
return;
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "loaded map '%s'", pFilename);
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf);
str_copy(m_aCurrentMap, pName, sizeof(m_aCurrentMap));
m_CurrentMapCrc = m_pMap->Crc();
}
const char *CClient::LoadMap(const char *pName, const char *pFilename, unsigned WantedCrc)
{
static char aErrorMsg[128];
@ -1716,6 +1735,8 @@ void CClient::Run()
atexit(SDL_Quit); // ignore_convention
}
m_MenuStartTime = time_get();
// init graphics
{
if(g_Config.m_GfxThreaded)
@ -1935,6 +1956,14 @@ void CClient::Run()
if(State() == IClient::STATE_QUITING)
break;
// menu tick
if(State() == IClient::STATE_OFFLINE)
{
int64 t = time_get();
while(t > TickStartTime(m_CurMenuTick+1))
m_CurMenuTick++;
}
// beNice
if(g_Config.m_DbgStress)
thread_sleep(5);
@ -1980,6 +2009,10 @@ void CClient::Run()
}
}
int64 CClient::TickStartTime(int Tick)
{
return m_MenuStartTime + (time_freq()*Tick)/m_GameTickSpeed;
}
void CClient::Con_Connect(IConsole::IResult *pResult, void *pUserData)
{

View file

@ -181,6 +181,8 @@ class CClient : public IClient, public CDemoPlayer::IListner
static void GraphicsThreadProxy(void *pThis) { ((CClient*)pThis)->GraphicsThread(); }
void GraphicsThread();
int64 TickStartTime(int Tick);
public:
IEngine *Engine() { return m_pEngine; }
IEngineGraphics *Graphics() { return m_pGraphics; }
@ -252,6 +254,8 @@ public:
virtual const char *ErrorString();
bool MapLoaded();
void LoadBackgroundMap(const char *pName, const char *pFilename);
const char *LoadMap(const char *pName, const char *pFilename, unsigned WantedCrc);
const char *LoadMapSearch(const char *pMapName, int WantedCrc);

View file

@ -13,11 +13,13 @@
CCamera::CCamera()
{
m_CamType = CAMTYPE_UNDEFINED;
m_RotationCenter = vec2(0.0f, 0.0f);
}
void CCamera::OnRender()
{
//vec2 center;
if(Client()->State() != IClient::STATE_OFFLINE)
{
m_Zoom = 1.0f;
// update camera center
@ -56,6 +58,17 @@ void CCamera::OnRender()
else
m_Center = m_pClient->m_LocalCharacterPos + CameraOffset;
}
}
else
{
m_Zoom = 0.7f;
// do little rotation
static vec2 Dir = vec2(1.0f, 0.0f);
float RotPerTick = 18.0f * Client()->FrameTime(); // 20 sec for one rotation (18° per sec)
Dir = rotate(Dir, RotPerTick);
m_Center = m_RotationCenter+Dir*30.0f;
}
m_PrevCenter = m_Center;
}

View file

@ -19,6 +19,7 @@ class CCamera : public CComponent
public:
vec2 m_Center;
vec2 m_RotationCenter;
float m_Zoom;
CCamera();

View file

@ -98,7 +98,7 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
}
else
else if(pThis->Client()->State() != IClient::STATE_OFFLINE)
{
if(pThis->m_pClient->m_Snap.m_pGameInfoObj && !(pThis->m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED))
{
@ -114,11 +114,16 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
s_LastLocalTime = pThis->Client()->LocalTime();
}
else
{
Time = pThis->Client()->MenuTick() / (float)pThis->Client()->GameTickSpeed();
pThis->RenderTools()->RenderEvalEnvelope(pPoints+pItem->m_StartPoint, pItem->m_NumPoints, 4, Time, pChannels);
}
}
void CMapLayers::OnRender()
{
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK && !Client()->MapLoaded())
return;
CUIRect Screen;

View file

@ -21,6 +21,7 @@
#include <game/generated/protocol.h>
#include <game/generated/client_data.h>
#include <game/client/components/camera.h>
#include <game/client/components/sounds.h>
#include <game/client/gameclient.h>
#include <game/client/lineinput.h>
@ -541,6 +542,7 @@ int CMenus::RenderMenubar(CUIRect r)
static int s_InternetButton=0;
if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage==PAGE_INTERNET, &Button, CUI::CORNER_TL) && m_ActivePage!=PAGE_INTERNET)
{
m_pClient->m_pCamera->m_RotationCenter = vec2(500.0f, 500.0f);
ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
NewPage = PAGE_INTERNET;
}
@ -550,6 +552,7 @@ int CMenus::RenderMenubar(CUIRect r)
static int s_LanButton=0;
if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage==PAGE_LAN, &Button, 0) && m_ActivePage!=PAGE_LAN)
{
m_pClient->m_pCamera->m_RotationCenter = vec2(1000.0f, 1000.0f);
ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
NewPage = PAGE_LAN;
}
@ -559,6 +562,7 @@ int CMenus::RenderMenubar(CUIRect r)
static int s_FavoritesButton=0;
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage==PAGE_FAVORITES, &Button, CUI::CORNER_TR) && m_ActivePage!=PAGE_FAVORITES)
{
m_pClient->m_pCamera->m_RotationCenter = vec2(2000.0f, 500.0f);
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
NewPage = PAGE_FAVORITES;
}
@ -779,7 +783,7 @@ int CMenus::Render()
s_First = false;
}
if(Client()->State() == IClient::STATE_ONLINE)
if(Client()->State() == IClient::STATE_ONLINE || Client()->MapLoaded())
{
ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame;
ms_ColorTabbarActive = ms_ColorTabbarActiveIngame;

View file

@ -255,6 +255,8 @@ void CGameClient::OnInit()
for(int i = m_All.m_Num-1; i >= 0; --i)
m_All.m_paComponents[i]->OnInit();
Client()->LoadBackgroundMap("dm1", "maps/dm1.map");
// setup load amount// load textures
for(int i = 0; i < g_pData->m_NumImages; i++)
{
@ -265,6 +267,13 @@ void CGameClient::OnInit()
for(int i = 0; i < m_All.m_Num; i++)
m_All.m_paComponents[i]->OnReset();
m_Layers.Init(Kernel());
m_Collision.Init(Layers());
RenderTools()->RenderTilemapGenerateSkip(Layers());
m_pMapimages->OnMapLoad();
int64 End = time_get();
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "initialisation finished after %.2fms", ((End-Start)*1000)/(float)time_freq());