diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-29 11:44:03 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-03-29 11:44:03 +0000 |
| commit | 7a3874745ca370a799d95b5f86e85fcc8eadefbb (patch) | |
| tree | 16f1e28f2f499279496866a63cabf88e2f2ad6c4 /src/game/client | |
| parent | 171d6b1c206c0488b59d157bc266319bf4ab482b (diff) | |
| download | zcatch-7a3874745ca370a799d95b5f86e85fcc8eadefbb.tar.gz zcatch-7a3874745ca370a799d95b5f86e85fcc8eadefbb.zip | |
fixed loads of graphical optimizations
Diffstat (limited to 'src/game/client')
| -rw-r--r-- | src/game/client/gc_client.cpp | 12 | ||||
| -rw-r--r-- | src/game/client/gc_render.cpp | 118 | ||||
| -rw-r--r-- | src/game/client/gc_render.h | 7 | ||||
| -rw-r--r-- | src/game/client/gc_render_map.cpp | 103 |
4 files changed, 116 insertions, 124 deletions
diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index 4fe312c5..6bc83af9 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -983,10 +983,7 @@ void render_game() // render the world float zoom = 1.0f; - if(inp_key_pressed('E')) - zoom = 0.5f; - - gfx_clear(0.65f,0.78f,0.9f); + if(spectate) render_world(mouse_pos.x, mouse_pos.y, zoom); else @@ -1485,7 +1482,12 @@ void render_game() float ramp = velocity_ramp(velspeed, tuning.velramp_start, tuning.velramp_range, tuning.velramp_curvature); char buf[512]; - str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d %s", velspeed, velspeed*ramp, ramp, netobj_num_corrections(), netobj_corrected_on()); + str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d %s\n%d %d", + velspeed, velspeed*ramp, ramp, + netobj_num_corrections(), netobj_corrected_on(), + netobjects.local_character->x, + netobjects.local_character->y + ); gfx_text(0, 150, 50, 12, buf, -1); } diff --git a/src/game/client/gc_render.cpp b/src/game/client/gc_render.cpp index 8cbc3b2e..33187f62 100644 --- a/src/game/client/gc_render.cpp +++ b/src/game/client/gc_render.cpp @@ -297,10 +297,26 @@ static void envelope_eval(float time_offset, int env, float *channels) void render_layers(float center_x, float center_y, int pass) { bool passed_gamelayer = false; + for(int g = 0; g < layers_num_groups(); g++) { MAPITEM_GROUP *group = layers_get_group(g); + if(group->version >= 2 && group->use_clipping) + { + // set clipping + float points[4]; + mapscreen_to_group(center_x, center_y, layers_game_group()); + gfx_getscreen(&points[0], &points[1], &points[2], &points[3]); + float x0 = (group->clip_x - points[0]) / (points[2]-points[0]); + float y0 = (group->clip_y - points[1]) / (points[3]-points[1]); + float x1 = ((group->clip_x+group->clip_w) - points[0]) / (points[2]-points[0]); + float y1 = ((group->clip_y+group->clip_h) - points[1]) / (points[3]-points[1]); + + gfx_clip_enable((int)(x0*gfx_screenwidth()), (int)(y0*gfx_screenheight()), + (int)((x1-x0)*gfx_screenwidth()), (int)((y1-y0)*gfx_screenheight())); + } + mapscreen_to_group(center_x, center_y, group); for(int l = 0; l < group->num_layers; l++) @@ -319,7 +335,9 @@ void render_layers(float center_x, float center_y, int pass) passed_gamelayer = 1; } - if(pass == 0) + if(pass == -1) + render = true; + else if(pass == 0) { if(passed_gamelayer) return; @@ -331,7 +349,7 @@ void render_layers(float center_x, float center_y, int pass) render = true; } - if(render) + if(render && !is_game_layer) { if(layer->type == LAYERTYPE_TILES) { @@ -340,8 +358,12 @@ void render_layers(float center_x, float center_y, int pass) gfx_texture_set(-1); else gfx_texture_set(img_get(tmap->image)); + TILE *tiles = (TILE *)map_get_data(tmap->data); - render_tilemap(tiles, tmap->width, tmap->height, 32.0f, vec4(1,1,1,1), 1); + gfx_blend_none(); + render_tilemap(tiles, tmap->width, tmap->height, 32.0f, vec4(1,1,1,1), TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE); + gfx_blend_normal(); + render_tilemap(tiles, tmap->width, tmap->height, 32.0f, vec4(1,1,1,1), TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); } else if(layer->type == LAYERTYPE_QUADS) { @@ -350,11 +372,19 @@ void render_layers(float center_x, float center_y, int pass) gfx_texture_set(-1); else gfx_texture_set(img_get(qlayer->image)); + QUAD *quads = (QUAD *)map_get_data_swapped(qlayer->data); - render_quads(quads, qlayer->num_quads, envelope_eval); + + gfx_blend_none(); + render_quads(quads, qlayer->num_quads, envelope_eval, LAYERRENDERFLAG_OPAQUE); + gfx_blend_normal(); + render_quads(quads, qlayer->num_quads, envelope_eval, LAYERRENDERFLAG_TRANSPARENT); + } } } + + gfx_clip_disable(); } } @@ -464,10 +494,11 @@ static void render_players() // renders the complete game world void render_world(float center_x, float center_y, float zoom) -{ +{ // render background layers render_layers(center_x, center_y, 0); - + gfx_clip_disable(); + // render trails particle_render(PARTGROUP_PROJECTILE_TRAIL); @@ -486,81 +517,8 @@ void render_world(float center_x, float center_y, float zoom) // render foreground layers render_layers(center_x, center_y, 1); + gfx_clip_disable(); // render damage indications render_damage_indicators(); - - - - // render screen sizes - if(false) - { - gfx_texture_set(-1); - gfx_lines_begin(); - - float last_points[4]; - float start = 1.0f; //9.0f/16.0f; - float end = 16.0f/9.0f; - const int num_steps = 20; - for(int i = 0; i <= num_steps; i++) - { - float points[4]; - float aspect = start + (end-start)*(i/(float)num_steps); - - mapscreen_to_world( - center_x, center_y, - 1.0f, 1.0f, 0.0f, 0.0f, aspect, 1.0f, points); - - if(i == 0) - { - gfx_lines_draw(points[0], points[1], points[2], points[1]); - gfx_lines_draw(points[0], points[3], points[2], points[3]); - } - - if(i != 0) - { - gfx_lines_draw(points[0], points[1], last_points[0], last_points[1]); - gfx_lines_draw(points[2], points[1], last_points[2], last_points[1]); - gfx_lines_draw(points[0], points[3], last_points[0], last_points[3]); - gfx_lines_draw(points[2], points[3], last_points[2], last_points[3]); - } - - if(i == num_steps) - { - gfx_lines_draw(points[0], points[1], points[0], points[3]); - gfx_lines_draw(points[2], points[1], points[2], points[3]); - } - - mem_copy(last_points, points, sizeof(points)); - } - - if(1) - { - gfx_setcolor(1,0,0,1); - for(int i = 0; i < 2; i++) - { - float points[4]; - float aspects[] = {4.0f/3.0f, 16.0f/10.0f, 5.0f/4.0f, 16.0f/9.0f}; - float aspect = aspects[i]; - - mapscreen_to_world( - center_x, center_y, - 1.0f, 1.0f, 0.0f, 0.0f, aspect, 1.0f, points); - - RECT r; - r.x = points[0]; - r.y = points[1]; - r.w = points[2]-points[0]; - r.h = points[3]-points[1]; - - gfx_lines_draw(r.x, r.y, r.x+r.w, r.y); - gfx_lines_draw(r.x+r.w, r.y, r.x+r.w, r.y+r.h); - gfx_lines_draw(r.x+r.w, r.y+r.h, r.x, r.y+r.h); - gfx_lines_draw(r.x, r.y+r.h, r.x, r.y); - gfx_setcolor(0,1,0,1); - } - } - - gfx_lines_end(); - } } diff --git a/src/game/client/gc_render.h b/src/game/client/gc_render.h index 53b6510a..b3439e93 100644 --- a/src/game/client/gc_render.h +++ b/src/game/client/gc_render.h @@ -29,6 +29,11 @@ enum { SPRITE_FLAG_FLIP_Y=1, SPRITE_FLAG_FLIP_X=2, + + LAYERRENDERFLAG_OPAQUE=1, + LAYERRENDERFLAG_TRANSPARENT=2, + + TILERENDERFLAG_EXTEND=4, }; typedef struct sprite; @@ -66,7 +71,7 @@ void render_player( // map render methods (gc_render_map.cpp) void render_eval_envelope(ENVPOINT *points, int num_points, int channels, float time, float *result); -void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels)); +void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels), int flags); void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int flags); // helpers diff --git a/src/game/client/gc_render_map.cpp b/src/game/client/gc_render_map.cpp index 8693ed18..2ad3ad94 100644 --- a/src/game/client/gc_render_map.cpp +++ b/src/game/client/gc_render_map.cpp @@ -75,7 +75,7 @@ static void rotate(POINT *center, POINT *point, float rotation) point->y = (int)(x * sinf(rotation) + y * cosf(rotation) + center->y); } -void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels)) +void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels), int renderflags) { gfx_quads_begin(); float conv = 1/255.0f; @@ -83,6 +83,27 @@ void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, in { QUAD *q = &quads[i]; + float r=1, g=1, b=1, a=1; + + if(q->color_env >= 0) + { + float channels[4]; + eval(q->color_env_offset/1000.0f, q->color_env, channels); + r = channels[0]; + g = channels[1]; + b = channels[2]; + a = channels[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; + + if(opaque && !(renderflags&LAYERRENDERFLAG_OPAQUE)) + continue; + if(!opaque && !(renderflags&LAYERRENDERFLAG_TRANSPARENT)) + continue; + gfx_quads_setsubset_free( fx2f(q->texcoords[0].x), fx2f(q->texcoords[0].y), fx2f(q->texcoords[1].x), fx2f(q->texcoords[1].y), @@ -90,7 +111,6 @@ void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, in fx2f(q->texcoords[3].x), fx2f(q->texcoords[3].y) ); - float r=1, g=1, b=1, a=1; float offset_x = 0; float offset_y = 0; float rot = 0; @@ -105,15 +125,6 @@ void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, in rot = channels[2]/360.0f*pi*2; } - if(q->color_env >= 0) - { - float channels[4]; - eval(q->color_env_offset/1000.0f, q->color_env, channels); - r = channels[0]; - g = channels[1]; - b = channels[2]; - a = channels[3]; - } gfx_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); gfx_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); @@ -147,12 +158,12 @@ void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, in gfx_quads_end(); } - -void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int flags) +void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int renderflags) { - //gfx_texture_set(img_get(tmap->image)); + //gfx_texture_set(img_get(tmap->image)); float screen_x0, screen_y0, screen_x1, screen_y1; gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); + //gfx_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; @@ -178,7 +189,7 @@ void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int flag int mx = x; int my = y; - if(flags) + if(renderflags&TILERENDERFLAG_EXTEND) { if(mx<0) mx = 0; @@ -207,39 +218,55 @@ void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int flag if(index) { unsigned char flags = tiles[c].flags; - 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; - if(flags&TILEFLAG_VFLIP) + bool render = false; + if(flags&TILEFLAG_OPAQUE) { - float tmp = u0; - u0 = u1; - u1 = tmp; + if(renderflags&LAYERRENDERFLAG_OPAQUE) + render = true; } - - if(flags&TILEFLAG_HFLIP) + else { - float tmp = v0; - v0 = v1; - v1 = tmp; + if(renderflags&LAYERRENDERFLAG_TRANSPARENT) + render = true; } - gfx_quads_setsubset(u0,v0,u1,v1); + 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; + + 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) + { + float tmp = u0; + u0 = u1; + u1 = tmp; + } - gfx_quads_drawTL(x*scale, y*scale, scale, scale); + if(flags&TILEFLAG_HFLIP) + { + float tmp = v0; + v0 = v1; + v1 = tmp; + } + + gfx_quads_setsubset(u0,v0,u1,v1); + gfx_quads_drawTL(x*scale, y*scale, scale, scale); + } } - x += tiles[c].skip; } gfx_quads_end(); + gfx_mapscreen(screen_x0, screen_y0, screen_x1, screen_y1); } |