diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2010-05-29 07:25:38 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2010-05-29 07:25:38 +0000 |
| commit | 72c06a258940696093f255fb1061beb58e1cdd0b (patch) | |
| tree | 36b9a7712eec2d4f07837eab9c38ef1c5af85319 /src/game/client/render_map.cpp | |
| parent | e56feb597bc743677633432f77513b02907fd169 (diff) | |
| download | zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.tar.gz zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.zip | |
copied refactor to trunk
Diffstat (limited to 'src/game/client/render_map.cpp')
| -rw-r--r-- | src/game/client/render_map.cpp | 273 |
1 files changed, 137 insertions, 136 deletions
diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index ea3b8420..0354b9d5 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -1,198 +1,198 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ +// copyright (c) 2007 magnus auvinen, see licence.txt for more info #include <math.h> -#include <base/math.hpp> -#include <engine/e_client_interface.h> -#include <engine/client/graphics.h> +#include <base/math.h> +#include <engine/graphics.h> -#include "render.hpp" +#include "render.h" -void CRenderTools::render_eval_envelope(ENVPOINT *points, int num_points, int channels, float time, float *result) +void CRenderTools::RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, float Time, float *pResult) { - if(num_points == 0) + if(NumPoints == 0) { - result[0] = 0; - result[1] = 0; - result[2] = 0; - result[3] = 0; + pResult[0] = 0; + pResult[1] = 0; + pResult[2] = 0; + pResult[3] = 0; return; } - if(num_points == 1) + if(NumPoints == 1) { - result[0] = fx2f(points[0].values[0]); - result[1] = fx2f(points[0].values[1]); - result[2] = fx2f(points[0].values[2]); - result[3] = fx2f(points[0].values[3]); + pResult[0] = fx2f(pPoints[0].m_aValues[0]); + pResult[1] = fx2f(pPoints[0].m_aValues[1]); + pResult[2] = fx2f(pPoints[0].m_aValues[2]); + pResult[3] = fx2f(pPoints[0].m_aValues[3]); return; } - time = fmod(time, points[num_points-1].time/1000.0f)*1000.0f; - for(int i = 0; i < num_points-1; i++) + Time = fmod(Time, pPoints[NumPoints-1].m_Time/1000.0f)*1000.0f; + for(int i = 0; i < NumPoints-1; i++) { - if(time >= points[i].time && time <= points[i+1].time) + if(Time >= pPoints[i].m_Time && Time <= pPoints[i+1].m_Time) { - float delta = points[i+1].time-points[i].time; - float a = (time-points[i].time)/delta; + float Delta = pPoints[i+1].m_Time-pPoints[i].m_Time; + float a = (Time-pPoints[i].m_Time)/Delta; - if(points[i].curvetype == CURVETYPE_SMOOTH) + if(pPoints[i].m_Curvetype == CURVETYPE_SMOOTH) a = -2*a*a*a + 3*a*a; // second hermite basis - else if(points[i].curvetype == CURVETYPE_SLOW) + else if(pPoints[i].m_Curvetype == CURVETYPE_SLOW) a = a*a*a; - else if(points[i].curvetype == CURVETYPE_FAST) + else if(pPoints[i].m_Curvetype == CURVETYPE_FAST) { a = 1-a; a = 1-a*a*a; } - else if (points[i].curvetype == CURVETYPE_STEP) + else if (pPoints[i].m_Curvetype == CURVETYPE_STEP) a = 0; else { // linear } - for(int c = 0; c < channels; c++) + for(int c = 0; c < Channels; c++) { - float v0 = fx2f(points[i].values[c]); - float v1 = fx2f(points[i+1].values[c]); - result[c] = v0 + (v1-v0) * a; + float v0 = fx2f(pPoints[i].m_aValues[c]); + float v1 = fx2f(pPoints[i+1].m_aValues[c]); + pResult[c] = v0 + (v1-v0) * a; } return; } } - result[0] = fx2f(points[num_points-1].values[0]); - result[1] = fx2f(points[num_points-1].values[1]); - result[2] = fx2f(points[num_points-1].values[2]); - result[3] = fx2f(points[num_points-1].values[3]); + pResult[0] = fx2f(pPoints[NumPoints-1].m_aValues[0]); + pResult[1] = fx2f(pPoints[NumPoints-1].m_aValues[1]); + pResult[2] = fx2f(pPoints[NumPoints-1].m_aValues[2]); + pResult[3] = fx2f(pPoints[NumPoints-1].m_aValues[3]); return; } -static void rotate(POINT *center, POINT *point, float rotation) +static void Rotate(CPoint *pCenter, CPoint *pPoint, float Rotation) { - int x = point->x - center->x; - int y = point->y - center->y; - point->x = (int)(x * cosf(rotation) - y * sinf(rotation) + center->x); - point->y = (int)(x * sinf(rotation) + y * cosf(rotation) + center->y); + int x = pPoint->x - pCenter->x; + int y = pPoint->y - pCenter->y; + pPoint->x = (int)(x * cosf(Rotation) - y * sinf(Rotation) + pCenter->x); + pPoint->y = (int)(x * sinf(Rotation) + y * cosf(Rotation) + pCenter->y); } -void CRenderTools::render_quads(QUAD *quads, int num_quads, int renderflags, void (*eval)(float time_offset, int env, float *channels, void *user), void *user) +void CRenderTools::RenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags, void (*pfnEval)(float TimeOffset, int Env, float *pChannels, void *pUser), void *pUser) { Graphics()->QuadsBegin(); - float conv = 1/255.0f; - for(int i = 0; i < num_quads; i++) + float Conv = 1/255.0f; + for(int i = 0; i < NumQuads; i++) { - QUAD *q = &quads[i]; + CQuad *q = &pQuads[i]; float r=1, g=1, b=1, a=1; - if(q->color_env >= 0) + if(q->m_ColorEnv >= 0) { - float channels[4]; - eval(q->color_env_offset/1000.0f, q->color_env, channels, user); - r = channels[0]; - g = channels[1]; - b = channels[2]; - a = channels[3]; + float aChannels[4]; + pfnEval(q->m_ColorEnvOffset/1000.0f, q->m_ColorEnv, aChannels, pUser); + r = aChannels[0]; + g = aChannels[1]; + b = aChannels[2]; + a = aChannels[3]; } - bool opaque = false; - if(a < 0.01f || (q->colors[0].a < 0.01f && q->colors[1].a < 0.01f && q->colors[2].a < 0.01f && q->colors[3].a < 0.01f)) - opaque = true; + bool Opaque = false; + if(a < 0.01f || (q->m_aColors[0].a < 0.01f && q->m_aColors[1].a < 0.01f && q->m_aColors[2].a < 0.01f && q->m_aColors[3].a < 0.01f)) + Opaque = true; - if(opaque && !(renderflags&LAYERRENDERFLAG_OPAQUE)) + if(Opaque && !(RenderFlags&LAYERRENDERFLAG_OPAQUE)) continue; - if(!opaque && !(renderflags&LAYERRENDERFLAG_TRANSPARENT)) + if(!Opaque && !(RenderFlags&LAYERRENDERFLAG_TRANSPARENT)) continue; Graphics()->QuadsSetSubsetFree( - fx2f(q->texcoords[0].x), fx2f(q->texcoords[0].y), - fx2f(q->texcoords[1].x), fx2f(q->texcoords[1].y), - fx2f(q->texcoords[2].x), fx2f(q->texcoords[2].y), - fx2f(q->texcoords[3].x), fx2f(q->texcoords[3].y) + fx2f(q->m_aTexcoords[0].x), fx2f(q->m_aTexcoords[0].y), + fx2f(q->m_aTexcoords[1].x), fx2f(q->m_aTexcoords[1].y), + fx2f(q->m_aTexcoords[2].x), fx2f(q->m_aTexcoords[2].y), + fx2f(q->m_aTexcoords[3].x), fx2f(q->m_aTexcoords[3].y) ); - float offset_x = 0; - float offset_y = 0; - float rot = 0; + float OffsetX = 0; + float OffsetY = 0; + float Rot = 0; // TODO: fix this - if(q->pos_env >= 0) + if(q->m_PosEnv >= 0) { - float channels[4]; - eval(q->pos_env_offset/1000.0f, q->pos_env, channels, user); - offset_x = channels[0]; - offset_y = channels[1]; - rot = channels[2]/360.0f*pi*2; + float aChannels[4]; + pfnEval(q->m_PosEnvOffset/1000.0f, q->m_PosEnv, aChannels, pUser); + OffsetX = aChannels[0]; + OffsetY = aChannels[1]; + Rot = aChannels[2]/360.0f*pi*2; } - - Graphics()->SetColorVertex(0, q->colors[0].r*conv*r, q->colors[0].g*conv*g, q->colors[0].b*conv*b, q->colors[0].a*conv*a); - Graphics()->SetColorVertex(1, q->colors[1].r*conv*r, q->colors[1].g*conv*g, q->colors[1].b*conv*b, q->colors[1].a*conv*a); - Graphics()->SetColorVertex(2, q->colors[2].r*conv*r, q->colors[2].g*conv*g, q->colors[2].b*conv*b, q->colors[2].a*conv*a); - Graphics()->SetColorVertex(3, q->colors[3].r*conv*r, q->colors[3].g*conv*g, q->colors[3].b*conv*b, q->colors[3].a*conv*a); + IGraphics::CColorVertex Array[4] = { + IGraphics::CColorVertex(0, q->m_aColors[0].r*Conv*r, q->m_aColors[0].g*Conv*g, q->m_aColors[0].b*Conv*b, q->m_aColors[0].a*Conv*a), + IGraphics::CColorVertex(1, q->m_aColors[1].r*Conv*r, q->m_aColors[1].g*Conv*g, q->m_aColors[1].b*Conv*b, q->m_aColors[1].a*Conv*a), + IGraphics::CColorVertex(2, q->m_aColors[2].r*Conv*r, q->m_aColors[2].g*Conv*g, q->m_aColors[2].b*Conv*b, q->m_aColors[2].a*Conv*a), + IGraphics::CColorVertex(3, q->m_aColors[3].r*Conv*r, q->m_aColors[3].g*Conv*g, q->m_aColors[3].b*Conv*b, q->m_aColors[3].a*Conv*a)}; + Graphics()->SetColorVertex(Array, 4); - POINT *points = q->points; + CPoint *pPoints = q->m_aPoints; - if(rot != 0) + if(Rot != 0) { - static POINT rotated[4]; - rotated[0] = q->points[0]; - rotated[1] = q->points[1]; - rotated[2] = q->points[2]; - rotated[3] = q->points[3]; - points = rotated; + static CPoint aRotated[4]; + aRotated[0] = q->m_aPoints[0]; + aRotated[1] = q->m_aPoints[1]; + aRotated[2] = q->m_aPoints[2]; + aRotated[3] = q->m_aPoints[3]; + pPoints = aRotated; - rotate(&q->points[4], &rotated[0], rot); - rotate(&q->points[4], &rotated[1], rot); - rotate(&q->points[4], &rotated[2], rot); - rotate(&q->points[4], &rotated[3], rot); + Rotate(&q->m_aPoints[4], &aRotated[0], Rot); + Rotate(&q->m_aPoints[4], &aRotated[1], Rot); + Rotate(&q->m_aPoints[4], &aRotated[2], Rot); + Rotate(&q->m_aPoints[4], &aRotated[3], Rot); } - Graphics()->QuadsDrawFreeform( - fx2f(points[0].x)+offset_x, fx2f(points[0].y)+offset_y, - fx2f(points[1].x)+offset_x, fx2f(points[1].y)+offset_y, - fx2f(points[2].x)+offset_x, fx2f(points[2].y)+offset_y, - fx2f(points[3].x)+offset_x, fx2f(points[3].y)+offset_y - ); + IGraphics::CFreeformItem Freeform( + fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY, + fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY, + fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, + fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); + Graphics()->QuadsDrawFreeform(&Freeform, 1); } Graphics()->QuadsEnd(); } -void CRenderTools::render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int renderflags) +void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags) { //Graphics()->TextureSet(img_get(tmap->image)); - float screen_x0, screen_y0, screen_x1, screen_y1; - Graphics()->GetScreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); + float ScreenX0, ScreenY0, ScreenX1, ScreenY1; + Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); //Graphics()->MapScreen(screen_x0-50, screen_y0-50, screen_x1+50, screen_y1+50); // calculate the final pixelsize for the tiles - float tile_pixelsize = 1024/32.0f; - float final_tilesize = scale/(screen_x1-screen_x0) * Graphics()->ScreenWidth(); - float final_tilesize_scale = final_tilesize/tile_pixelsize; + float TilePixelSize = 1024/32.0f; + float FinalTileSize = Scale/(ScreenX1-ScreenX0) * Graphics()->ScreenWidth(); + float FinalTilesetScale = FinalTileSize/TilePixelSize; Graphics()->QuadsBegin(); - Graphics()->SetColor(color.r, color.g, color.b, color.a); + Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a); - int starty = (int)(screen_y0/scale)-1; - int startx = (int)(screen_x0/scale)-1; - int endy = (int)(screen_y1/scale)+1; - int endx = (int)(screen_x1/scale)+1; + int StartY = (int)(ScreenY0/Scale)-1; + int StartX = (int)(ScreenX0/Scale)-1; + int EndY = (int)(ScreenY1/Scale)+1; + int EndX = (int)(ScreenX1/Scale)+1; // adjust the texture shift according to mipmap level - float texsize = 1024.0f; - float frac = (1.25f/texsize) * (1/final_tilesize_scale); - float nudge = (0.5f/texsize) * (1/final_tilesize_scale); + float TexSize = 1024.0f; + float Frac = (1.25f/TexSize) * (1/FinalTilesetScale); + float Nudge = (0.5f/TexSize) * (1/FinalTilesetScale); - for(int y = starty; y < endy; y++) - for(int x = startx; x < endx; x++) + for(int y = StartY; y < EndY; y++) + for(int x = StartX; x < EndX; x++) { int mx = x; int my = y; - if(renderflags&TILERENDERFLAG_EXTEND) + if(RenderFlags&TILERENDERFLAG_EXTEND) { if(mx<0) mx = 0; @@ -217,59 +217,60 @@ void CRenderTools::render_tilemap(TILE *tiles, int w, int h, float scale, vec4 c int c = mx + my*w; - unsigned char index = tiles[c].index; - if(index) + unsigned char Index = pTiles[c].m_Index; + if(Index) { - unsigned char flags = tiles[c].flags; + unsigned char Flags = pTiles[c].m_Flags; - bool render = false; - if(flags&TILEFLAG_OPAQUE) + bool Render = false; + if(Flags&TILEFLAG_OPAQUE) { - if(renderflags&LAYERRENDERFLAG_OPAQUE) - render = true; + if(RenderFlags&LAYERRENDERFLAG_OPAQUE) + Render = true; } else { - if(renderflags&LAYERRENDERFLAG_TRANSPARENT) - render = true; + if(RenderFlags&LAYERRENDERFLAG_TRANSPARENT) + Render = true; } - if(render) + if(Render) { - int tx = index%16; - int ty = index/16; - int px0 = tx*(1024/16); - int py0 = ty*(1024/16); - int px1 = (tx+1)*(1024/16)-1; - int py1 = (ty+1)*(1024/16)-1; + int tx = Index%16; + int ty = Index/16; + int Px0 = tx*(1024/16); + int Py0 = ty*(1024/16); + int Px1 = (tx+1)*(1024/16)-1; + int Py1 = (ty+1)*(1024/16)-1; - float u0 = nudge + px0/texsize+frac; - float v0 = nudge + py0/texsize+frac; - float u1 = nudge + px1/texsize-frac; - float v1 = nudge + py1/texsize-frac; + float u0 = Nudge + Px0/TexSize+Frac; + float v0 = Nudge + Py0/TexSize+Frac; + float u1 = Nudge + Px1/TexSize-Frac; + float v1 = Nudge + Py1/TexSize-Frac; - if(flags&TILEFLAG_VFLIP) + if(Flags&TILEFLAG_VFLIP) { - float tmp = u0; + float Tmp = u0; u0 = u1; - u1 = tmp; + u1 = Tmp; } - if(flags&TILEFLAG_HFLIP) + if(Flags&TILEFLAG_HFLIP) { - float tmp = v0; + float Tmp = v0; v0 = v1; - v1 = tmp; + v1 = Tmp; } Graphics()->QuadsSetSubset(u0,v0,u1,v1); - Graphics()->QuadsDrawTL(x*scale, y*scale, scale, scale); + IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale); + Graphics()->QuadsDrawTL(&QuadItem, 1); } } - x += tiles[c].skip; + x += pTiles[c].m_Skip; } Graphics()->QuadsEnd(); - Graphics()->MapScreen(screen_x0, screen_y0, screen_x1, screen_y1); + Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1); } |