about summary refs log tree commit diff
path: root/src/game/client/render.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client/render.cpp')
-rw-r--r--src/game/client/render.cpp313
1 files changed, 163 insertions, 150 deletions
diff --git a/src/game/client/render.cpp b/src/game/client/render.cpp
index f271c7d2..ee4dc9d9 100644
--- a/src/game/client/render.cpp
+++ b/src/game/client/render.cpp
@@ -1,19 +1,19 @@
-/* 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 <base/math.h>
 
-#include <engine/e_client_interface.h>
-#include <engine/e_config.h>
-#include <engine/client/graphics.h>
-#include <game/generated/gc_data.hpp>
-#include <game/generated/g_protocol.hpp>
-#include <game/layers.hpp>
-#include "animstate.hpp"
-#include "render.hpp"
+#include <engine/shared/config.h>
+#include <engine/graphics.h>
+#include <engine/map.h>
+#include <game/generated/client_data.h>
+#include <game/generated/protocol.h>
+#include <game/layers.h>
+#include "animstate.h"
+#include "render.h"
 
-static float sprite_w_scale;
-static float sprite_h_scale;
+static float gs_SpriteWScale;
+static float gs_SpriteHScale;
 
 
 /*
@@ -36,133 +36,141 @@ static void layershot_end()
 	config.cl_layershot++;
 }*/
 
-void CRenderTools::select_sprite(SPRITE *spr, int flags, int sx, int sy)
+void CRenderTools::SelectSprite(SPRITE *pSpr, int Flags, int sx, int sy)
 {
-	int x = spr->x+sx;
-	int y = spr->y+sy;
-	int w = spr->w;
-	int h = spr->h;
-	int cx = spr->set->gridx;
-	int cy = spr->set->gridy;
+	int x = pSpr->m_X+sx;
+	int y = pSpr->m_Y+sy;
+	int w = pSpr->m_W;
+	int h = pSpr->m_H;
+	int cx = pSpr->m_pSet->m_Gridx;
+	int cy = pSpr->m_pSet->m_Gridy;
 
 	float f = sqrtf(h*h + w*w);
-	sprite_w_scale = w/f;
-	sprite_h_scale = h/f;
+	gs_SpriteWScale = w/f;
+	gs_SpriteHScale = h/f;
 	
 	float x1 = x/(float)cx;
 	float x2 = (x+w)/(float)cx;
 	float y1 = y/(float)cy;
 	float y2 = (y+h)/(float)cy;
-	float temp = 0;
+	float Temp = 0;
 
-	if(flags&SPRITE_FLAG_FLIP_Y)
+	if(Flags&SPRITE_FLAG_FLIP_Y)
 	{
-		temp = y1;
+		Temp = y1;
 		y1 = y2;
-		y2 = temp;
+		y2 = Temp;
 	}
 
-	if(flags&SPRITE_FLAG_FLIP_X)
+	if(Flags&SPRITE_FLAG_FLIP_X)
 	{
-		temp = x1;
+		Temp = x1;
 		x1 = x2;
-		x2 = temp;
+		x2 = Temp;
 	}
 	
 	Graphics()->QuadsSetSubset(x1, y1, x2, y2);
 }
 
-void CRenderTools::select_sprite(int id, int flags, int sx, int sy)
+void CRenderTools::SelectSprite(int Id, int Flags, int sx, int sy)
 {
-	if(id < 0 || id > data->num_sprites)
+	if(Id < 0 || Id > g_pData->m_NumSprites)
 		return;
-	select_sprite(&data->sprites[id], flags, sx, sy);
+	SelectSprite(&g_pData->m_aSprites[Id], Flags, sx, sy);
 }
 
-void CRenderTools::draw_sprite(float x, float y, float size)
+void CRenderTools::DrawSprite(float x, float y, float Size)
 {
-	Graphics()->QuadsDraw(x, y, size*sprite_w_scale, size*sprite_h_scale);
+	IGraphics::CQuadItem QuadItem(x, y, Size*gs_SpriteWScale, Size*gs_SpriteHScale);
+	Graphics()->QuadsDraw(&QuadItem, 1);
 }
 
-void CRenderTools::draw_round_rect_ext(float x, float y, float w, float h, float r, int corners)
+void CRenderTools::DrawRoundRectExt(float x, float y, float w, float h, float r, int Corners)
 {
-	int num = 8;
-	for(int i = 0; i < num; i+=2)
+	IGraphics::CFreeformItem ArrayF[32];
+	int NumItems = 0;
+	int Num = 8;
+	for(int i = 0; i < Num; i+=2)
 	{
-		float a1 = i/(float)num * pi/2;
-		float a2 = (i+1)/(float)num * pi/2;
-		float a3 = (i+2)/(float)num * pi/2;
-		float ca1 = cosf(a1);
-		float ca2 = cosf(a2);
-		float ca3 = cosf(a3);
-		float sa1 = sinf(a1);
-		float sa2 = sinf(a2);
-		float sa3 = sinf(a3);
-
-		if(corners&1) // TL
-		Graphics()->QuadsDrawFreeform(
+		float a1 = i/(float)Num * pi/2;
+		float a2 = (i+1)/(float)Num * pi/2;
+		float a3 = (i+2)/(float)Num * pi/2;
+		float Ca1 = cosf(a1);
+		float Ca2 = cosf(a2);
+		float Ca3 = cosf(a3);
+		float Sa1 = sinf(a1);
+		float Sa2 = sinf(a2);
+		float Sa3 = sinf(a3);
+
+		if(Corners&1) // TL
+		ArrayF[NumItems++] = IGraphics::CFreeformItem(
 			x+r, y+r,
-			x+(1-ca1)*r, y+(1-sa1)*r,
-			x+(1-ca3)*r, y+(1-sa3)*r,
-			x+(1-ca2)*r, y+(1-sa2)*r);
+			x+(1-Ca1)*r, y+(1-Sa1)*r,
+			x+(1-Ca3)*r, y+(1-Sa3)*r,
+			x+(1-Ca2)*r, y+(1-Sa2)*r);
 
-		if(corners&2) // TR
-		Graphics()->QuadsDrawFreeform(
+		if(Corners&2) // TR
+		ArrayF[NumItems++] = IGraphics::CFreeformItem(
 			x+w-r, y+r,
-			x+w-r+ca1*r, y+(1-sa1)*r,
-			x+w-r+ca3*r, y+(1-sa3)*r,
-			x+w-r+ca2*r, y+(1-sa2)*r);
+			x+w-r+Ca1*r, y+(1-Sa1)*r,
+			x+w-r+Ca3*r, y+(1-Sa3)*r,
+			x+w-r+Ca2*r, y+(1-Sa2)*r);
 
-		if(corners&4) // BL
-		Graphics()->QuadsDrawFreeform(
+		if(Corners&4) // BL
+		ArrayF[NumItems++] = IGraphics::CFreeformItem(
 			x+r, y+h-r,
-			x+(1-ca1)*r, y+h-r+sa1*r,
-			x+(1-ca3)*r, y+h-r+sa3*r,
-			x+(1-ca2)*r, y+h-r+sa2*r);
+			x+(1-Ca1)*r, y+h-r+Sa1*r,
+			x+(1-Ca3)*r, y+h-r+Sa3*r,
+			x+(1-Ca2)*r, y+h-r+Sa2*r);
 
-		if(corners&8) // BR
-		Graphics()->QuadsDrawFreeform(
+		if(Corners&8) // BR
+		ArrayF[NumItems++] = IGraphics::CFreeformItem(
 			x+w-r, y+h-r,
-			x+w-r+ca1*r, y+h-r+sa1*r,
-			x+w-r+ca3*r, y+h-r+sa3*r,
-			x+w-r+ca2*r, y+h-r+sa2*r);
+			x+w-r+Ca1*r, y+h-r+Sa1*r,
+			x+w-r+Ca3*r, y+h-r+Sa3*r,
+			x+w-r+Ca2*r, y+h-r+Sa2*r);
 	}
-
-	Graphics()->QuadsDrawTL(x+r, y+r, w-r*2, h-r*2); // center
-	Graphics()->QuadsDrawTL(x+r, y, w-r*2, r); // top
-	Graphics()->QuadsDrawTL(x+r, y+h-r, w-r*2, r); // bottom
-	Graphics()->QuadsDrawTL(x, y+r, r, h-r*2); // left
-	Graphics()->QuadsDrawTL(x+w-r, y+r, r, h-r*2); // right
+	Graphics()->QuadsDrawFreeform(ArrayF, NumItems);
+
+	IGraphics::CQuadItem ArrayQ[9];
+	NumItems = 0;
+	ArrayQ[NumItems++] = IGraphics::CQuadItem(x+r, y+r, w-r*2, h-r*2); // center
+	ArrayQ[NumItems++] = IGraphics::CQuadItem(x+r, y, w-r*2, r); // top
+	ArrayQ[NumItems++] = IGraphics::CQuadItem(x+r, y+h-r, w-r*2, r); // bottom
+	ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y+r, r, h-r*2); // left
+	ArrayQ[NumItems++] = IGraphics::CQuadItem(x+w-r, y+r, r, h-r*2); // right
 	
-	if(!(corners&1)) Graphics()->QuadsDrawTL(x, y, r, r); // TL
-	if(!(corners&2)) Graphics()->QuadsDrawTL(x+w, y, -r, r); // TR
-	if(!(corners&4)) Graphics()->QuadsDrawTL(x, y+h, r, -r); // BL
-	if(!(corners&8)) Graphics()->QuadsDrawTL(x+w, y+h, -r, -r); // BR
+	if(!(Corners&1)) ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y, r, r); // TL
+	if(!(Corners&2)) ArrayQ[NumItems++] = IGraphics::CQuadItem(x+w, y, -r, r); // TR
+	if(!(Corners&4)) ArrayQ[NumItems++] = IGraphics::CQuadItem(x, y+h, r, -r); // BL
+	if(!(Corners&8)) ArrayQ[NumItems++] = IGraphics::CQuadItem(x+w, y+h, -r, -r); // BR
+
+	Graphics()->QuadsDrawTL(ArrayQ, NumItems);
 }
 
-void CRenderTools::draw_round_rect(float x, float y, float w, float h, float r)
+void CRenderTools::DrawRoundRect(float x, float y, float w, float h, float r)
 {
-	draw_round_rect_ext(x,y,w,h,r,0xf);
+	DrawRoundRectExt(x,y,w,h,r,0xf);
 }
 
-void CRenderTools::DrawUIRect(const CUIRect *r, vec4 color, int corners, float rounding)
+void CRenderTools::DrawUIRect(const CUIRect *r, vec4 Color, int Corners, float Rounding)
 {
 	Graphics()->TextureSet(-1);
 	
 	// TODO: FIX US
 	Graphics()->QuadsBegin();
-	Graphics()->SetColor(color.r, color.g, color.b, color.a);
-	draw_round_rect_ext(r->x,r->y,r->w,r->h,rounding*UI()->Scale(), corners);
+	Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
+	DrawRoundRectExt(r->x,r->y,r->w,r->h,Rounding*UI()->Scale(), Corners);
 	Graphics()->QuadsEnd();
 }
 
-void CRenderTools::RenderTee(ANIMSTATE *anim, TEE_RENDER_INFO *info, int emote, vec2 dir, vec2 pos)
+void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos)
 {
-	vec2 direction = dir;
-	vec2 position = pos;
+	vec2 Direction = Dir;
+	vec2 Position = Pos;
 
 	//Graphics()->TextureSet(data->images[IMAGE_CHAR_DEFAULT].id);
-	Graphics()->TextureSet(info->texture);
+	Graphics()->TextureSet(pInfo->m_Texture);
 	
 	// TODO: FIX ME
 	Graphics()->QuadsBegin();
@@ -172,75 +180,79 @@ void CRenderTools::RenderTee(ANIMSTATE *anim, TEE_RENDER_INFO *info, int emote,
 	// second pass we draw the filling
 	for(int p = 0; p < 2; p++)
 	{
-		int outline = p==0 ? 1 : 0;
+		int OutLine = p==0 ? 1 : 0;
 
 		for(int f = 0; f < 2; f++)
 		{
-			float animscale = info->size * 1.0f/64.0f;
-			float basesize = info->size;
+			float AnimScale = pInfo->m_Size * 1.0f/64.0f;
+			float BaseSize = pInfo->m_Size;
 			if(f == 1)
 			{
-				Graphics()->QuadsSetRotation(anim->body.angle*pi*2);
+				Graphics()->QuadsSetRotation(pAnim->GetBody()->m_Angle*pi*2);
 
 				// draw body
-				Graphics()->SetColor(info->color_body.r, info->color_body.g, info->color_body.b, 1.0f);
-				vec2 body_pos = position + vec2(anim->body.x, anim->body.y)*animscale;
-				select_sprite(outline?SPRITE_TEE_BODY_OUTLINE:SPRITE_TEE_BODY, 0, 0, 0);
-				Graphics()->QuadsDraw(body_pos.x, body_pos.y, basesize, basesize);
+				Graphics()->SetColor(pInfo->m_ColorBody.r, pInfo->m_ColorBody.g, pInfo->m_ColorBody.b, 1.0f);
+				vec2 BodyPos = Position + vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y)*AnimScale;
+				SelectSprite(OutLine?SPRITE_TEE_BODY_OUTLINE:SPRITE_TEE_BODY, 0, 0, 0);
+				IGraphics::CQuadItem QuadItem(BodyPos.x, BodyPos.y, BaseSize, BaseSize);
+				Graphics()->QuadsDraw(&QuadItem, 1);
 
 				// draw eyes
 				if(p == 1)
 				{
-					switch (emote)
+					switch (Emote)
 					{
 						case EMOTE_PAIN:
-							select_sprite(SPRITE_TEE_EYE_PAIN, 0, 0, 0);
+							SelectSprite(SPRITE_TEE_EYE_PAIN, 0, 0, 0);
 							break;
 						case EMOTE_HAPPY:
-							select_sprite(SPRITE_TEE_EYE_HAPPY, 0, 0, 0);
+							SelectSprite(SPRITE_TEE_EYE_HAPPY, 0, 0, 0);
 							break;
 						case EMOTE_SURPRISE:
-							select_sprite(SPRITE_TEE_EYE_SURPRISE, 0, 0, 0);
+							SelectSprite(SPRITE_TEE_EYE_SURPRISE, 0, 0, 0);
 							break;
 						case EMOTE_ANGRY:
-							select_sprite(SPRITE_TEE_EYE_ANGRY, 0, 0, 0);
+							SelectSprite(SPRITE_TEE_EYE_ANGRY, 0, 0, 0);
 							break;
 						default:
-							select_sprite(SPRITE_TEE_EYE_NORMAL, 0, 0, 0);
+							SelectSprite(SPRITE_TEE_EYE_NORMAL, 0, 0, 0);
 							break;
 					}
 					
-					float eyescale = basesize*0.40f;
-					float h = emote == EMOTE_BLINK ? basesize*0.15f : eyescale;
-					float eyeseparation = (0.075f - 0.010f*fabs(direction.x))*basesize;
-					vec2 offset = vec2(direction.x*0.125f, -0.05f+direction.y*0.10f)*basesize;
-					Graphics()->QuadsDraw(body_pos.x-eyeseparation+offset.x, body_pos.y+offset.y, eyescale, h);
-					Graphics()->QuadsDraw(body_pos.x+eyeseparation+offset.x, body_pos.y+offset.y, -eyescale, h);
+					float EyeScale = BaseSize*0.40f;
+					float h = Emote == EMOTE_BLINK ? BaseSize*0.15f : EyeScale;
+					float EyeSeparation = (0.075f - 0.010f*absolute(Direction.x))*BaseSize;
+					vec2 Offset = vec2(Direction.x*0.125f, -0.05f+Direction.y*0.10f)*BaseSize;
+					IGraphics::CQuadItem Array[2] = {
+						IGraphics::CQuadItem(BodyPos.x-EyeSeparation+Offset.x, BodyPos.y+Offset.y, EyeScale, h),
+						IGraphics::CQuadItem(BodyPos.x+EyeSeparation+Offset.x, BodyPos.y+Offset.y, -EyeScale, h)};
+					Graphics()->QuadsDraw(Array, 2);
 				}
 			}
 
 			// draw feet
-			ANIM_KEYFRAME *foot = f ? &anim->front_foot : &anim->back_foot;
+			ANIM_KEYFRAME *pFoot = f ? pAnim->GetFrontFoot() : pAnim->GetBackFoot();
 
-			float w = basesize;
-			float h = basesize/2;
+			float w = BaseSize;
+			float h = BaseSize/2;
 
-			Graphics()->QuadsSetRotation(foot->angle*pi*2);
+			Graphics()->QuadsSetRotation(pFoot->m_Angle*pi*2);
 			
-			bool indicate = !info->got_airjump && config.cl_airjumpindicator;
+			bool Indicate = !pInfo->m_GotAirJump && g_Config.m_ClAirjumpindicator;
 			float cs = 1.0f; // color scale
 			
-			if(outline)
-				select_sprite(SPRITE_TEE_FOOT_OUTLINE, 0, 0, 0);
+			if(OutLine)
+				SelectSprite(SPRITE_TEE_FOOT_OUTLINE, 0, 0, 0);
 			else
 			{
-				select_sprite(SPRITE_TEE_FOOT, 0, 0, 0);
-				if(indicate)
+				SelectSprite(SPRITE_TEE_FOOT, 0, 0, 0);
+				if(Indicate)
 					cs = 0.5f;
 			}
 				
-			Graphics()->SetColor(info->color_feet.r*cs, info->color_feet.g*cs, info->color_feet.b*cs, 1.0f);
-			Graphics()->QuadsDraw(position.x+foot->x*animscale, position.y+foot->y*animscale, w, h);
+			Graphics()->SetColor(pInfo->m_ColorFeet.r*cs, pInfo->m_ColorFeet.g*cs, pInfo->m_ColorFeet.b*cs, 1.0f);
+			IGraphics::CQuadItem QuadItem(Position.x+pFoot->m_X*AnimScale, Position.y+pFoot->m_Y*AnimScale, w, h);
+			Graphics()->QuadsDraw(&QuadItem, 1);
 		}
 	}
 
@@ -249,67 +261,68 @@ void CRenderTools::RenderTee(ANIMSTATE *anim, TEE_RENDER_INFO *info, int emote,
 	
 }
 
-static void calc_screen_params(float amount, float wmax, float hmax, float aspect, float *w, float *h)
+static void CalcScreenParams(float Amount, float WMax, float HMax, float Aspect, float *w, float *h)
 {
-	float f = sqrt(amount) / sqrt(aspect);
-	*w = f*aspect;
+	float f = sqrtf(Amount) / sqrtf(Aspect);
+	*w = f*Aspect;
 	*h = f;
 	
 	// limit the view
-	if(*w > wmax)
+	if(*w > WMax)
 	{
-		*w = wmax;
-		*h = *w/aspect;
+		*w = WMax;
+		*h = *w/Aspect;
 	}
 	
-	if(*h > hmax)
+	if(*h > HMax)
 	{
-		*h = hmax;
-		*w = *h*aspect;
+		*h = HMax;
+		*w = *h*Aspect;
 	}
 }
 
-void CRenderTools::mapscreen_to_world(float center_x, float center_y, float parallax_x, float parallax_y,
-	float offset_x, float offset_y, float aspect, float zoom, float *points)
+void CRenderTools::MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
+	float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints)
 {
-	float width, height;
-	calc_screen_params(1150*1000, 1500, 1050, aspect, &width, &height);
-	center_x *= parallax_x;
-	center_y *= parallax_y;
-	width *= zoom;
-	height *= zoom;
-	points[0] = offset_x+center_x-width/2;
-	points[1] = offset_y+center_y-height/2;
-	points[2] = offset_x+center_x+width/2;
-	points[3] = offset_y+center_y+height/2;
+	float Width, Height;
+	CalcScreenParams(1150*1000, 1500, 1050, Aspect, &Width, &Height);
+	CenterX *= ParallaxX;
+	CenterY *= ParallaxY;
+	Width *= Zoom;
+	Height *= Zoom;
+	pPoints[0] = OffsetX+CenterX-Width/2;
+	pPoints[1] = OffsetY+CenterY-Height/2;
+	pPoints[2] = OffsetX+CenterX+Width/2;
+	pPoints[3] = OffsetY+CenterY+Height/2;
 }
 
-void CRenderTools::render_tilemap_generate_skip()
+void CRenderTools::RenderTilemapGenerateSkip(class CLayers *pLayers)
 {
-	for(int g = 0; g < layers_num_groups(); g++)
+	
+	for(int g = 0; g < pLayers->NumGroups(); g++)
 	{
-		MAPITEM_GROUP *group = layers_get_group(g);
+		CMapItemGroup *pGroup = pLayers->GetGroup(g);
 		
-		for(int l = 0; l < group->num_layers; l++)
+		for(int l = 0; l < pGroup->m_NumLayers; l++)
 		{
-			MAPITEM_LAYER *layer = layers_get_layer(group->start_layer+l);
+			CMapItemLayer *pLayer = pLayers->GetLayer(pGroup->m_StartLayer+l);
 
-			if(layer->type == LAYERTYPE_TILES)
+			if(pLayer->m_Type == LAYERTYPE_TILES)
 			{
-				MAPITEM_LAYER_TILEMAP *tmap = (MAPITEM_LAYER_TILEMAP *)layer;
-				TILE *tiles = (TILE *)map_get_data(tmap->data);
-				for(int y = 0; y < tmap->height; y++)
+				CMapItemLayerTilemap *pTmap = (CMapItemLayerTilemap *)pLayer;
+				CTile *pTiles = (CTile *)pLayers->Map()->GetData(pTmap->m_Data);
+				for(int y = 0; y < pTmap->m_Height; y++)
 				{
-					for(int x = 1; x < tmap->width; x++)
+					for(int x = 1; x < pTmap->m_Width; x++)
 					{
 						int sx;
-						for(sx = 1; x+sx < tmap->width && sx < 255; sx++)
+						for(sx = 1; x+sx < pTmap->m_Width && sx < 255; sx++)
 						{
-							if(tiles[y*tmap->width+x+sx].index)
+							if(pTiles[y*pTmap->m_Width+x+sx].m_Index)
 								break;
 						}
 						
-						tiles[y*tmap->width+x].skip = sx-1;
+						pTiles[y*pTmap->m_Width+x].m_Skip = sx-1;
 					}
 				}
 			}