diff options
Diffstat (limited to 'src/engine/client')
| -rw-r--r-- | src/engine/client/client.c | 290 | ||||
| -rw-r--r-- | src/engine/client/gfx.c | 141 | ||||
| -rw-r--r-- | src/engine/client/inp.c | 10 | ||||
| -rw-r--r-- | src/engine/client/snd.c | 82 | ||||
| -rw-r--r-- | src/engine/client/srvbrowse.c | 24 | ||||
| -rw-r--r-- | src/engine/client/ui.c | 22 |
6 files changed, 284 insertions, 285 deletions
diff --git a/src/engine/client/client.c b/src/engine/client/client.c index 066e9236..f8ccf6e5 100644 --- a/src/engine/client/client.c +++ b/src/engine/client/client.c @@ -53,26 +53,26 @@ static int snapcrcerrors = 0; static int ack_game_tick = -1; static int current_recv_tick = 0; -// current time +/* current time */ static int current_tick = 0; static float intratick = 0; -// predicted time +/* predicted time */ static int current_predtick = 0; static float intrapredtick = 0; -static struct // TODO: handle input better +static struct /* TODO: handle input better */ { - int data[MAX_INPUT_SIZE]; // the input data - int tick; // the tick that the input is for - int64 game_time; // prediction latency when we sent this input + int data[MAX_INPUT_SIZE]; /* the input data */ + int tick; /* the tick that the input is for */ + int64 game_time; /* prediction latency when we sent this input */ int64 time; } inputs[200]; static int current_input = 0; enum { - GRAPH_MAX=256, + GRAPH_MAX=256 }; typedef struct @@ -139,20 +139,22 @@ static void st_init(SMOOTHTIME *st, int64 target) static int64 st_get(SMOOTHTIME *st, int64 now) { + float adjust_speed, a; int64 c = st->current + (now - st->snap); int64 t = st->target + (now - st->snap); + int64 r; - // it's faster to adjust upward instead of downward - // we might need to adjust these abit - float adjust_speed = 0.3f; + /* it's faster to adjust upward instead of downward */ + /* we might need to adjust these abit */ + adjust_speed = 0.3f; if(t < c) adjust_speed *= 5.0f; - float a = ((now-st->snap)/(float)time_freq())*adjust_speed; + a = ((now-st->snap)/(float)time_freq())*adjust_speed; if(a > 1) a = 1; - int64 r = c + (int64)((t-c)*a); + r = c + (int64)((t-c)*a); { int64 drt = now - st->rlast; @@ -183,7 +185,7 @@ SMOOTHTIME predicted_time; GRAPH intra_graph; -// --- input snapping --- +/* --- input snapping --- */ static int input_data[MAX_INPUT_SIZE] = {0}; static int input_data_size; static int input_is_changed = 1; @@ -195,10 +197,10 @@ void snap_input(void *data, int size) input_data_size = size; } -// -- snapshot handling --- +/* -- snapshot handling --- */ enum { - NUM_SNAPSHOT_TYPES=2, + NUM_SNAPSHOT_TYPES=2 }; SNAPSTORAGE snapshot_storage; @@ -206,12 +208,13 @@ static SNAPSTORAGE_HOLDER *snapshots[NUM_SNAPSHOT_TYPES]; static int recived_snapshots; static char snapshot_incomming_data[MAX_SNAPSHOT_SIZE]; -// --- +/* --- */ const void *snap_get_item(int snapid, int index, SNAP_ITEM *item) { + SNAPSHOT_ITEM *i; dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); - SNAPSHOT_ITEM *i = snapshot_get_item(snapshots[snapid]->snap, index); + i = snapshot_get_item(snapshots[snapid]->snap, index); item->type = snapitem_type(i); item->id = snapitem_id(i); return (void *)snapitem_data(i); @@ -219,7 +222,7 @@ const void *snap_get_item(int snapid, int index, SNAP_ITEM *item) const void *snap_find_item(int snapid, int type, int id) { - // TODO: linear search. should be fixed. + /* TODO: linear search. should be fixed. */ int i; for(i = 0; i < snapshots[snapid]->snap->num_items; i++) { @@ -236,7 +239,7 @@ int snap_num_items(int snapid) return snapshots[snapid]->snap->num_items; } -// ------ time functions ------ +/* ------ time functions ------ */ float client_intratick() { return intratick; } float client_intrapredtick() { return intrapredtick; } int client_tick() { return current_tick; } @@ -245,7 +248,7 @@ int client_tickspeed() { return SERVER_TICK_SPEED; } float client_frametime() { return frametime; } float client_localtime() { return (time_get()-local_start_time)/(float)(time_freq()); } -// ----- send functions ----- +/* ----- send functions ----- */ int client_send_msg() { const MSG_INFO *info = msg_get_info(); @@ -288,8 +291,6 @@ static void client_send_error(const char *error) packet p(NETMSG_CLIENT_ERROR); p.write_str(error); send_packet(&p); - //send_packet(&p); - //send_packet(&p); */ } @@ -305,6 +306,9 @@ void client_rcon(const char *cmd) static void client_send_input() { + int64 now = time_get(); + int i; + if(current_predtick <= 0) return; @@ -313,12 +317,10 @@ static void client_send_input() msg_pack_int(current_predtick); msg_pack_int(input_data_size); - int64 now = time_get(); inputs[current_input].tick = current_predtick; inputs[current_input].game_time = st_get(&predicted_time, now); inputs[current_input].time = now; - int i; for(i = 0; i < input_data_size/4; i++) { inputs[current_input].data[i] = input_data[i]; @@ -348,14 +350,14 @@ int *client_get_input(int tick) return 0; } -// ------ state handling ----- +/* ------ state handling ----- */ static int state; int client_state() { return state; } static void client_set_state(int s) { + int old = state; if(config.debug) dbg_msg("client", "state change. last=%d current=%d", state, s); - int old = state; state = s; if(old != s) modc_statechange(state, old); @@ -364,13 +366,13 @@ static void client_set_state(int s) /* called when the map is loaded and we should init for a new round */ static void client_on_enter_game() { - // reset input + /* reset input */ int i; for(i = 0; i < 200; i++) inputs[i].tick = -1; current_input = 0; - // reset snapshots + /* reset snapshots */ snapshots[SNAP_CURRENT] = 0; snapshots[SNAP_PREV] = 0; snapstorage_purge_all(&snapshot_storage); @@ -381,12 +383,15 @@ static void client_on_enter_game() void client_connect(const char *server_address_str) { - dbg_msg("client", "connecting to '%s'", server_address_str); char buf[512]; - strncpy(buf, server_address_str, 512); - const char *port_str = 0; int k; + int port = 8303; + + dbg_msg("client", "connecting to '%s'", server_address_str); + + strncpy(buf, server_address_str, 512); + for(k = 0; buf[k]; k++) { if(buf[k] == ':') @@ -397,7 +402,6 @@ void client_connect(const char *server_address_str) } } - int port = 8303; if(port_str) port = atoi(port_str); @@ -424,6 +428,11 @@ static int client_load_data() static void client_debug_render() { + static NETSTATS prev, current; + static int64 last_snap = 0; + static float frametime_avg = 0; + char buffer[512]; + if(!config.debug) return; @@ -431,8 +440,6 @@ static void client_debug_render() gfx_texture_set(debug_font); gfx_mapscreen(0,0,gfx_screenwidth(),gfx_screenheight()); - static NETSTATS prev, current; - static int64 last_snap = 0; if(time_get()-last_snap > time_freq()/10) { last_snap = time_get(); @@ -440,9 +447,7 @@ static void client_debug_render() netclient_stats(net, ¤t); } - static float frametime_avg = 0; frametime_avg = frametime_avg*0.9f + frametime*0.1f; - char buffer[512]; sprintf(buffer, "ticks: %8d %8d send: %6d recv: %6d snaploss: %d mem %dk gfxmem: %dk fps: %3d", current_tick, current_predtick, (current.send_bytes-prev.send_bytes)*10, @@ -454,7 +459,7 @@ static void client_debug_render() gfx_quads_text(2, 2, 16, buffer); - // render graphs + /* render graphs */ gfx_mapscreen(0,0,400.0f,300.0f); graph_render(&game_time.graph, 300, 10, 90, 50); graph_render(&predicted_time.graph, 300, 10+50+10, 90, 50); @@ -482,14 +487,14 @@ static void client_error(const char *msg) { dbg_msg("client", "error: %s", msg); client_send_error(msg); - client_set_state(CLIENTSTATE_QUITING); + client_set_state(CLIENTSTATE_OFFLINE); } static void client_process_packet(NETPACKET *packet) { if(packet->client_id == -1) { - // connectionlesss + /* connectionlesss */ if(packet->data_size >= (int)sizeof(SERVERBROWSE_LIST) && memcmp(packet->data, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST)) == 0) { @@ -523,10 +528,12 @@ static void client_process_packet(NETPACKET *packet) if(packet->data_size >= (int)sizeof(SERVERBROWSE_INFO) && memcmp(packet->data, SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO)) == 0) { - // we got ze info + /* we got ze info */ UNPACKER up; - unpacker_reset(&up, (unsigned char*)packet->data+sizeof(SERVERBROWSE_INFO), packet->data_size-sizeof(SERVERBROWSE_INFO)); SERVER_INFO info = {0}; + int i; + + unpacker_reset(&up, (unsigned char*)packet->data+sizeof(SERVERBROWSE_INFO), packet->data_size-sizeof(SERVERBROWSE_INFO)); strncpy(info.version, unpacker_get_string(&up), 32); strncpy(info.name, unpacker_get_string(&up), 64); @@ -537,7 +544,6 @@ static void client_process_packet(NETPACKET *packet) info.num_players = atol(unpacker_get_string(&up)); info.max_players = atol(unpacker_get_string(&up)); - int i; for(i = 0; i < info.num_players; i++) { strncpy(info.player_names[i], unpacker_get_string(&up), 48); @@ -550,12 +556,12 @@ static void client_process_packet(NETPACKET *packet) } else { - int sys; int msg = msg_unpack_start(packet->data, packet->data_size, &sys); + if(sys) { - // system message + /* system message */ if(msg == NETMSG_MAP) { const char *map = msg_unpack_string(); @@ -567,8 +573,8 @@ static void client_process_packet(NETPACKET *packet) modc_entergame(); client_send_entergame(); dbg_msg("client/network", "loading done"); - // now we will wait for two snapshots - // to finish the connection + /* now we will wait for two snapshots */ + /* to finish the connection */ client_on_enter_game(); } @@ -579,7 +585,7 @@ static void client_process_packet(NETPACKET *packet) } else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPEMPTY) { - //dbg_msg("client/network", "got snapshot"); + /*dbg_msg("client/network", "got snapshot"); */ int game_tick = msg_unpack_int(); int delta_tick = game_tick-msg_unpack_int(); int input_predtick = msg_unpack_int(); @@ -603,7 +609,7 @@ static void client_process_packet(NETPACKET *packet) { if(inputs[k].tick == input_predtick) { - //-1000/50 + /*-1000/50 */ int64 target = inputs[k].game_time + (time_get() - inputs[k].time); st_update(&predicted_time, target - (int64)(((time_left-prediction_margin)/1000.0f)*time_freq())); break; @@ -613,47 +619,52 @@ static void client_process_packet(NETPACKET *packet) if(snapshot_part == part && game_tick > current_recv_tick) { - // TODO: clean this up abit + /* TODO: clean this up abit */ const char *d = (const char *)msg_unpack_raw(part_size); mem_copy((char*)snapshot_incomming_data + part*MAX_SNAPSHOT_PACKSIZE, d, part_size); snapshot_part++; if(snapshot_part == num_parts) { + static SNAPSHOT emptysnap; + SNAPSHOT *deltashot = &emptysnap; + int purgetick; + void *deltadata; + int deltasize; + unsigned char tmpbuffer[MAX_SNAPSHOT_SIZE]; + unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE]; + unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE]; + int snapsize; + snapshot_part = 0; - // find snapshot that we should use as delta - static SNAPSHOT emptysnap; + /* find snapshot that we should use as delta */ emptysnap.data_size = 0; emptysnap.num_items = 0; - SNAPSHOT *deltashot = &emptysnap; - - // find delta + /* find delta */ if(delta_tick >= 0) { int deltashot_size = snapstorage_get(&snapshot_storage, delta_tick, 0, &deltashot); if(deltashot_size < 0) { - // couldn't find the delta snapshots that the server used - // to compress this snapshot. force the server to resync + /* couldn't find the delta snapshots that the server used */ + /* to compress this snapshot. force the server to resync */ if(config.debug) dbg_msg("client", "error, couldn't find the delta snapshot"); - // ack snapshot - // TODO: combine this with the input message + /* ack snapshot */ + /* TODO: combine this with the input message */ ack_game_tick = -1; return; } } - // decompress snapshot - void *deltadata = snapshot_empty_delta(); - int deltasize = sizeof(int)*3; + /* decompress snapshot */ + deltadata = snapshot_empty_delta(); + deltasize = sizeof(int)*3; - unsigned char tmpbuffer[MAX_SNAPSHOT_SIZE]; - unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE]; if(part_size) { int compsize = zerobit_decompress(snapshot_incomming_data, part_size, tmpbuffer); @@ -662,10 +673,10 @@ static void client_process_packet(NETPACKET *packet) deltasize = intsize; } - //dbg_msg("UNPACK", "%d unpacked with %d", game_tick, delta_tick); + /*dbg_msg("UNPACK", "%d unpacked with %d", game_tick, delta_tick); */ - unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE]; - int snapsize = snapshot_unpack_delta(deltashot, (SNAPSHOT*)tmpbuffer3, deltadata, deltasize); + purgetick = delta_tick; + snapsize = snapshot_unpack_delta(deltashot, (SNAPSHOT*)tmpbuffer3, deltadata, deltasize); if(msg != NETMSG_SNAPEMPTY && snapshot_crc((SNAPSHOT*)tmpbuffer3) != crc) { if(config.debug) @@ -673,7 +684,7 @@ static void client_process_packet(NETPACKET *packet) snapcrcerrors++; if(snapcrcerrors > 10) { - // to many errors, send reset + /* to many errors, send reset */ ack_game_tick = -1; client_send_input(); snapcrcerrors = 0; @@ -686,24 +697,24 @@ static void client_process_packet(NETPACKET *packet) snapcrcerrors--; } - // purge old snapshots - int purgetick = delta_tick; + /* purge old snapshots */ + purgetick = delta_tick; if(snapshots[SNAP_PREV] && snapshots[SNAP_PREV]->tick < purgetick) purgetick = snapshots[SNAP_PREV]->tick; if(snapshots[SNAP_CURRENT] && snapshots[SNAP_CURRENT]->tick < purgetick) purgetick = snapshots[SNAP_PREV]->tick; snapstorage_purge_until(&snapshot_storage, purgetick); - //client_snapshot_purge_until(game_tick-50); + /*client_snapshot_purge_until(game_tick-50); */ - // add new + /* add new */ snapstorage_add(&snapshot_storage, game_tick, time_get(), snapsize, (SNAPSHOT*)tmpbuffer3); - //SNAPSTORAGE_HOLDER *snap = client_snapshot_add(game_tick, time_get(), tmpbuffer3, snapsize); + /*SNAPSTORAGE_HOLDER *snap = client_snapshot_add(game_tick, time_get(), tmpbuffer3, snapsize); */ - //int ncrc = snapshot_crc((snapshot*)tmpbuffer3); - //if(crc != ncrc) - // dbg_msg("client", "client snapshot crc failure %d %d", crc, ncrc); + /*int ncrc = snapshot_crc((snapshot*)tmpbuffer3); */ + /*if(crc != ncrc) */ + /* dbg_msg("client", "client snapshot crc failure %d %d", crc, ncrc); */ - // apply snapshot, cycle pointers + /* apply snapshot, cycle pointers */ recived_snapshots++; @@ -711,10 +722,10 @@ static void client_process_packet(NETPACKET *packet) snaploss += game_tick-current_recv_tick-1; current_recv_tick = game_tick; - // we got two snapshots until we see us self as connected + /* we got two snapshots until we see us self as connected */ if(recived_snapshots == 2) { - // start at 200ms and work from there + /* start at 200ms and work from there */ st_init(&predicted_time, (game_tick+10)*time_freq()/50); st_init(&game_time, (game_tick-1)*time_freq()/50); snapshots[SNAP_PREV] = snapshot_storage.first; @@ -725,7 +736,7 @@ static void client_process_packet(NETPACKET *packet) st_update(&game_time, (game_tick-1)*time_freq()/50); - // ack snapshot + /* ack snapshot */ ack_game_tick = game_tick; } } @@ -738,7 +749,7 @@ static void client_process_packet(NETPACKET *packet) } else { - // game message + /* game message */ modc_message(msg); } } @@ -746,78 +757,81 @@ static void client_process_packet(NETPACKET *packet) static void client_pump_network() { + NETPACKET packet; + netclient_update(net); - // check for errors + /* check for errors */ if(client_state() != CLIENTSTATE_OFFLINE && netclient_state(net) == NETSTATE_OFFLINE) { client_set_state(CLIENTSTATE_OFFLINE); dbg_msg("client", "offline error='%s'", netclient_error_string(net)); } - // + /* */ if(client_state() == CLIENTSTATE_CONNECTING && netclient_state(net) == NETSTATE_ONLINE) { - // we switched to online + /* we switched to online */ dbg_msg("client", "connected, sending info"); client_set_state(CLIENTSTATE_LOADING); client_send_info(); } - // process packets - NETPACKET packet; + /* process packets */ while(netclient_recv(net, &packet)) client_process_packet(&packet); } static void client_run(const char *direct_connect_server) { + NETADDR4 bindaddr; + int64 reporttime = time_get(); + int64 reportinterval = time_freq()*1; + int frames = 0; + local_start_time = time_get(); snapshot_part = 0; - // init graphics and sound + /* init graphics and sound */ if(!gfx_init()) return; - snd_init(); // sound is allowed to fail + snd_init(); /* sound is allowed to fail */ - // load data + /* load data */ if(!client_load_data()) return; - // init menu - modmenu_init(); // TODO: remove + /* init menu */ + modmenu_init(); /* TODO: remove */ - // init the mod + /* init the mod */ modc_init(); dbg_msg("client", "version %s", modc_net_version()); - // open socket - NETADDR4 bindaddr; + /* open socket */ mem_zero(&bindaddr, sizeof(bindaddr)); net = netclient_open(bindaddr, 0); - // connect to the server if wanted + /* connect to the server if wanted */ if(direct_connect_server) client_connect(direct_connect_server); - int64 reporttime = time_get(); - int64 reportinterval = time_freq()*1; - int frames = 0; - inp_mouse_mode_relative(); while (1) { - frames++; int64 frame_start_time = time_get(); - // switch snapshot + /* switch snapshot */ if(recived_snapshots >= 3) { int repredict = 0; - //int64 now = time_get(); int64 now = st_get(&game_time, time_get()); + + frames++; + + /*int64 now = time_get(); */ while(1) { SNAPSTORAGE_HOLDER *cur = snapshots[SNAP_CURRENT]; @@ -831,7 +845,7 @@ static void client_run(const char *direct_connect_server) snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT]; snapshots[SNAP_CURRENT] = next; - // set tick + /* set tick */ current_tick = snapshots[SNAP_CURRENT]->tick; if(snapshots[SNAP_CURRENT] && snapshots[SNAP_PREV]) @@ -851,14 +865,15 @@ static void client_run(const char *direct_connect_server) { int64 curtick_start = (snapshots[SNAP_CURRENT]->tick)*time_freq()/50; int64 prevtick_start = (snapshots[SNAP_PREV]->tick)*time_freq()/50; - intratick = (now - prevtick_start) / (float)(curtick_start-prevtick_start); - - graph_add(&intra_graph, intratick*0.25f); - int64 pred_now = st_get(&predicted_time, time_get()); - //tg_add(&predicted_time_graph, pred_now, 0); + /*tg_add(&predicted_time_graph, pred_now, 0); */ int prev_pred_tick = (int)(pred_now*50/time_freq()); int new_pred_tick = prev_pred_tick+1; + + intratick = (now - prevtick_start) / (float)(curtick_start-prevtick_start); + + graph_add(&intra_graph, intratick*0.25f); + curtick_start = new_pred_tick*time_freq()/50; prevtick_start = prev_pred_tick*time_freq()/50; intrapredtick = (pred_now - prevtick_start) / (float)(curtick_start-prevtick_start); @@ -868,14 +883,14 @@ static void client_run(const char *direct_connect_server) current_predtick = new_pred_tick; repredict = 1; - // send input + /* send input */ client_send_input(); } } - //intrapredtick = current_predtick + /*intrapredtick = current_predtick */ - // only do sane predictions + /* only do sane predictions */ if(repredict) { if(current_predtick > current_tick && current_predtick < current_tick+50) @@ -883,14 +898,14 @@ static void client_run(const char *direct_connect_server) } } - // STRESS TEST: join the server again + /* STRESS TEST: join the server again */ if(client_state() == CLIENTSTATE_OFFLINE && config.stress && (frames%100) == 0) client_connect(config.cl_stress_server); - // update input + /* update input */ inp_update(); - // refocus + /* refocus */ if(!gfx_window_active()) { if(window_must_refocus == 0) @@ -913,11 +928,11 @@ static void client_run(const char *direct_connect_server) } } - // screenshot button + /* screenshot button */ if(inp_key_down(config.key_screenshot)) gfx_screenshot(); - // panic button + /* panic button */ if(config.debug) { if(inp_key_pressed(KEY_F1)) @@ -932,23 +947,16 @@ static void client_run(const char *direct_connect_server) { ack_game_tick = -1; client_send_input(); - /* - // ack snapshot - msg_pack_start_system(NETMSG_SNAPACK, 0); - msg_pack_int(-1); - msg_pack_end(); - client_send_msg(); - */ } } - // pump the network + /* pump the network */ client_pump_network(); - // update the server browser + /* update the server browser */ client_serverbrowse_update(); - // render + /* render */ if(config.stress) { if((frames%10) == 0) @@ -963,11 +971,11 @@ static void client_run(const char *direct_connect_server) gfx_swap(); } - // check conditions + /* check conditions */ if(client_state() == CLIENTSTATE_QUITING) break; - // be nice + /* be nice */ if(config.cpu_throttle || !gfx_window_active()) thread_sleep(1); @@ -982,14 +990,14 @@ static void client_run(const char *direct_connect_server) reporttime += reportinterval; } - // update frametime + /* update frametime */ frametime = (time_get()-frame_start_time)/(float)time_freq(); } modc_shutdown(); client_disconnect(); - modmenu_shutdown(); // TODO: remove this + modmenu_shutdown(); /* TODO: remove this */ gfx_shutdown(); snd_shutdown(); @@ -998,21 +1006,23 @@ static void client_run(const char *direct_connect_server) int editor_main(int argc, char **argv); -//client main_client; +/*client main_client; */ int main(int argc, char **argv) { - dbg_msg("client", "starting..."); - - config_reset(); - #ifdef CONF_PLATFORM_MACOSX const char *config_filename = "~/.teewars"; #else const char *config_filename = "default.cfg"; #endif - int i; + const char *direct_connect_server = 0x0; + int editor = 0; + + dbg_msg("client", "starting..."); + + config_reset(); + for(i = 1; i < argc; i++) { if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1) @@ -1024,19 +1034,17 @@ int main(int argc, char **argv) config_load(config_filename); - const char *direct_connect_server = 0x0; snd_set_master_volume(config.volume / 255.0f); - int editor = 0; - // init network, need to be done first so we can do lookups + /* init network, need to be done first so we can do lookups */ net_init(); - // parse arguments + /* parse arguments */ for(i = 1; i < argc; i++) { if(argv[i][0] == '-' && argv[i][1] == 'c' && argv[i][2] == 0 && argc - i > 1) { - // -c SERVER:PORT + /* -c SERVER:PORT */ i++; direct_connect_server = argv[i]; } @@ -1052,7 +1060,7 @@ int main(int argc, char **argv) editor_main(argc, argv); else { - // start the client + /* start the client */ client_run(direct_connect_server); } return 0; diff --git a/src/engine/client/gfx.c b/src/engine/client/gfx.c index 05ebcb1c..c34ac0cb 100644 --- a/src/engine/client/gfx.c +++ b/src/engine/client/gfx.c @@ -1,4 +1,3 @@ - #include <engine/external/glfw/include/GL/glfw.h> #include <engine/external/pnglite/pnglite.h> @@ -11,17 +10,17 @@ #include <stdio.h> #include <math.h> -// compressed textures +/* compressed textures */ #define GL_COMPRESSED_RGB_ARB 0x84ED #define GL_COMPRESSED_RGBA_ARB 0x84EE enum { DRAWING_QUADS=1, - DRAWING_LINES=2, + DRAWING_LINES=2 }; -// +/* */ typedef struct { float x, y, z; } VEC3; typedef struct { float u, v; } TEXCOORD; typedef struct { float r, g, b, a; } COLOR; @@ -103,7 +102,7 @@ static void flush() else if(drawing == DRAWING_LINES) glDrawArrays(GL_LINES, 0, num_vertices); - // Reset pointer + /* Reset pointer */ num_vertices = 0; } @@ -123,6 +122,8 @@ static void draw_quad() int gfx_init() { + int i; + screen_width = config.gfx_screen_width; screen_height = config.gfx_screen_height; @@ -155,11 +156,11 @@ int gfx_init() glfwSetWindowTitle("Teewars"); - // We don't want to see the window when we run the stress testing + /* We don't want to see the window when we run the stress testing */ if(config.stress) glfwIconifyWindow(); - // Init vertices + /* Init vertices */ if (vertices) mem_free(vertices); vertices = (VERTEX*)mem_alloc(sizeof(VERTEX) * vertex_buffer_size, 1); @@ -172,36 +173,32 @@ int gfx_init() context.version_rev());*/ gfx_mapscreen(0,0,config.gfx_screen_width, config.gfx_screen_height); - - // TODO: make wrappers for this + + /* set some default settings */ glEnable(GL_BLEND); - - // model glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - // Set all z to -5.0f - int i; + /* Set all z to -5.0f */ for (i = 0; i < vertex_buffer_size; i++) vertices[i].pos.z = -5.0f; - // init textures + /* init textures */ first_free_texture = 0; for(i = 0; i < MAX_TEXTURES; i++) textures[i].next = i+1; textures[MAX_TEXTURES-1].next = -1; - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - // init input + /* init input */ inp_init(); - // create null texture, will get id=0 + /* create null texture, will get id=0 */ gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data); - // set vsync as needed + /* set vsync as needed */ gfx_set_vsync(config.gfx_vsync); return 1; @@ -242,8 +239,8 @@ int gfx_get_video_modes(VIDEO_MODE *list, int maxcount) { if(config.gfx_display_all_modes) { - mem_copy(list, fakemodes, sizeof(fakemodes)); int count = sizeof(fakemodes)/sizeof(VIDEO_MODE); + mem_copy(list, fakemodes, sizeof(fakemodes)); if(maxcount < count) count = maxcount; return count; @@ -268,13 +265,11 @@ int gfx_unload_texture(int index) void gfx_blend_normal() { - // TODO: wrapper for this glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } void gfx_blend_additive() { - // TODO: wrapper for this glBlendFunc(GL_SRC_ALPHA, GL_ONE); } @@ -291,24 +286,29 @@ static unsigned char sample(int w, int h, const unsigned char *data, int u, int int gfx_load_texture_raw(int w, int h, int format, const void *data) { int mipmap = 1; + unsigned char *texdata = (unsigned char *)data; + unsigned char *tmpdata = 0; + int oglformat = 0; - // grab texture + /* grab texture */ int tex = first_free_texture; first_free_texture = textures[tex].next; textures[tex].next = -1; - // resample if needed - unsigned char *texdata = (unsigned char *)data; - unsigned char *tmpdata = 0; + /* resample if needed */ if(config.gfx_texture_quality==0) { if(w > 16 && h > 16 && format == IMG_RGBA) { - w/=2; - h/=2; - unsigned char *tmpdata = (unsigned char *)mem_alloc(w*h*4, 1); + unsigned char *tmpdata; int c = 0; int x, y; + + tmpdata = (unsigned char *)mem_alloc(w*h*4, 1); + + w/=2; + h/=2; + for(y = 0; y < h; y++) for(x = 0; x < w; x++, c++) { @@ -324,8 +324,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data) if(config.debug) dbg_msg("gfx", "%d = %dx%d", tex, w, h); - // upload texture - int oglformat = 0; + /* upload texture */ if(config.gfx_texture_compression) { oglformat = GL_COMPRESSED_RGBA_ARB; @@ -345,7 +344,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, oglformat, w, h, oglformat, GL_UNSIGNED_BYTE, texdata); - // calculate memory usage + /* calculate memory usage */ textures[tex].memsize = w*h*4; if(mipmap) { @@ -390,13 +389,14 @@ int gfx_load_mip_texture_raw(int w, int h, int format, const void *data) return tex; } */ -// simple uncompressed RGBA loaders + +/* simple uncompressed RGBA loaders */ int gfx_load_texture(const char *filename) { int l = strlen(filename); + IMAGE_INFO img; if(l < 3) return 0; - IMAGE_INFO img; if(gfx_load_png(&img, filename)) { int id = gfx_load_texture_raw(img.width, img.height, img.format, img.data); @@ -409,10 +409,12 @@ int gfx_load_texture(const char *filename) int gfx_load_png(IMAGE_INFO *img, const char *filename) { - // open file for reading + unsigned char *buffer; + png_t png; + + /* open file for reading */ png_init(0,0); - png_t png; if(png_open_file(&png, filename) != PNG_NO_ERROR) { dbg_msg("game/png", "failed to open file. filename='%s'", filename); @@ -425,7 +427,7 @@ int gfx_load_png(IMAGE_INFO *img, const char *filename) png_close_file(&png); } - unsigned char *buffer = (unsigned char *)mem_alloc(png.width * png.height * png.bpp, 1); + buffer = (unsigned char *)mem_alloc(png.width * png.height * png.bpp, 1); png_get_data(&png, buffer); png_close_file(&png); @@ -456,15 +458,15 @@ void gfx_swap() { if(do_screenshot) { - // fetch image data + /* fetch image data */ + int y; int w = screen_width; int h = screen_height; unsigned char *pixel_data = (unsigned char *)mem_alloc(w*(h+1)*3, 1); unsigned char *temp_row = pixel_data+w*h*3; glReadPixels(0,0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixel_data); - // flip the pixel because opengl works from bottom left corner - int y; + /* flip the pixel because opengl works from bottom left corner */ for(y = 0; y < h/2; y++) { mem_copy(temp_row, pixel_data+y*w*3, w*3); @@ -472,28 +474,29 @@ void gfx_swap() mem_copy(pixel_data+(h-y-1)*w*3, temp_row,w*3); } - // find filename - char filename[64]; + /* find filename */ { + char filename[64]; static int index = 1; + png_t png; + for(; index < 1000; index++) { - sprintf(filename, "screenshot%04d.png", index); IOHANDLE io = io_open(filename, IOFLAG_READ); + sprintf(filename, "screenshot%04d.png", index); if(io) io_close(io); else break; } - } - // save png - png_t png; - png_open_file_write(&png, filename); - png_set_data(&png, w, h, 8, PNG_TRUECOLOR, (unsigned char *)pixel_data); - png_close_file(&png); + /* save png */ + png_open_file_write(&png, filename); + png_set_data(&png, w, h, 8, PNG_TRUECOLOR, (unsigned char *)pixel_data); + png_close_file(&png); + } - // clean up + /* clean up */ mem_free(pixel_data); do_screenshot = 0; } @@ -551,13 +554,6 @@ void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y) void gfx_setoffset(float x, float y) { - //const float scale = 1.0f; - //mat4 mat = mat4::identity; - //mat.m[0] = scale; - //mat.m[5] = scale; - //mat.m[10] = scale; - //mat.m[12] = x*scale; - //mat.m[13] = y*scale; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(x, y, 0); @@ -612,23 +608,15 @@ void gfx_quads_setsubset(float tl_u, float tl_v, float br_u, float br_v) texture[0].u = tl_u; texture[0].v = tl_v; - //g_pVertices[g_iVertexEnd].tex.u = tl_u; - //g_pVertices[g_iVertexEnd].tex.v = tl_v; texture[1].u = br_u; texture[1].v = tl_v; - //g_pVertices[g_iVertexEnd + 2].tex.u = br_u; - //g_pVertices[g_iVertexEnd + 2].tex.v = tl_v; texture[2].u = br_u; texture[2].v = br_v; - //g_pVertices[g_iVertexEnd + 1].tex.u = tl_u; - //g_pVertices[g_iVertexEnd + 1].tex.v = br_v; texture[3].u = tl_u; texture[3].v = br_v; - //g_pVertices[g_iVertexEnd + 3].tex.u = br_u; - //g_pVertices[g_iVertexEnd + 3].tex.v = br_v; } static void rotate(VEC3 *center, VEC3 *point) @@ -646,9 +634,10 @@ void gfx_quads_draw(float x, float y, float w, float h) void gfx_quads_drawTL(float x, float y, float width, float height) { - dbg_assert(drawing == DRAWING_QUADS, "called quads_draw without begin"); - VEC3 center; + + dbg_assert(drawing == DRAWING_QUADS, "called quads_draw without begin"); + center.x = x + width/2; center.y = y + height/2; center.z = 0; @@ -713,8 +702,10 @@ void gfx_quads_draw_freeform( void gfx_quads_text(float x, float y, float size, const char *text) { - gfx_quads_begin(); float startx = x; + + gfx_quads_begin(); + while(*text) { char c = *text; @@ -836,21 +827,21 @@ float gfx_pretty_text_raw(float x, float y, float size, const char *text_, int l while(length) { const int c = *text; - text++; - const float width = current_font->m_CharEndTable[c] - current_font->m_CharStartTable[c]; + double x_nudge = 0; + + text++; x -= size * current_font->m_CharStartTable[c]; gfx_quads_setsubset( - (c%16)/16.0f, // startx - (c/16)/16.0f, // starty - (c%16)/16.0f+1.0f/16.0f, // endx - (c/16)/16.0f+1.0f/16.0f); // endy + (c%16)/16.0f, /* startx */ + (c/16)/16.0f, /* starty */ + (c%16)/16.0f+1.0f/16.0f, /* endx */ + (c/16)/16.0f+1.0f/16.0f); /* endy */ gfx_quads_drawTL(x, y, size, size); - double x_nudge = 0; if(length > 1 && text[1]) x_nudge = extra_kerning[text[0] + text[1] * 256]; @@ -894,8 +885,8 @@ float gfx_pretty_text_width(float size, const char *text_, int length) const float spacing = 0.05f; float w = 0.0f; const unsigned char *text = (unsigned char *)text_; - const unsigned char *stop; + if (length == -1) stop = text + strlen((char*)text); else diff --git a/src/engine/client/inp.c b/src/engine/client/inp.c index 55cebbfe..6b0ba829 100644 --- a/src/engine/client/inp.c +++ b/src/engine/client/inp.c @@ -3,7 +3,7 @@ #include <engine/system.h> #include <engine/interface.h> -static int keyboard_state[2][1024]; // TODO: fix this!! +static int keyboard_state[2][1024]; /* TODO: fix this!! */ static int keyboard_current = 0; static int keyboard_first = 1; @@ -66,7 +66,6 @@ void inp_mouse_mode_relative() glfwDisable(GLFW_MOUSE_CURSOR); } -//int inp_mouse_scroll() { return input::mouse_scroll(); } int inp_key_pressed(int key) { return keyboard_state[keyboard_current][key]; } int inp_key_was_pressed(int key) { return keyboard_state[keyboard_current^1][key]; } int inp_key_down(int key) { return inp_key_pressed(key)&&!inp_key_was_pressed(key); } @@ -74,15 +73,16 @@ int inp_button_pressed(int button) { return keyboard_state[keyboard_current][but void inp_update() { + int i, v; + if(keyboard_first) { - // make sure to reset + /* make sure to reset */ keyboard_first = 0; inp_update(); } keyboard_current = keyboard_current^1; - int i, v; for(i = 0; i < KEY_LAST; i++) { if (i >= KEY_MOUSE_FIRST) @@ -92,7 +92,7 @@ void inp_update() keyboard_state[keyboard_current][i] = v; } - // handle mouse wheel + /* handle mouse wheel */ i = glfwGetMouseWheel(); keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_UP] = 0; keyboard_state[keyboard_current][KEY_MOUSE_WHEEL_DOWN] = 0; diff --git a/src/engine/client/snd.c b/src/engine/client/snd.c index 77844367..0fe82e14 100644 --- a/src/engine/client/snd.c +++ b/src/engine/client/snd.c @@ -13,10 +13,7 @@ enum NUM_SOUNDS = 512, NUM_VOICES = 64, NUM_CHANNELS = 4, -}; -enum -{ MAX_FRAMES = 1024 }; @@ -116,8 +113,8 @@ static inline void fill_stereo(int *out, unsigned frames, struct voice *v, float { int ivol = (int) (31.0f * fvol); int ipan = (int) (31.0f * ipan); - unsigned i; + for(i = 0; i < frames; i++) { unsigned j = i<<1; @@ -131,10 +128,11 @@ static void mix(short *out, unsigned frames) { static int main_buffer[MAX_FRAMES*2]; unsigned locked = 0; + unsigned i; + unsigned cid; dbg_assert(frames <= MAX_FRAMES, "too many frames to fill"); - unsigned i; for(i = 0; i < frames; i++) { unsigned j = i<<1; @@ -142,7 +140,6 @@ static void mix(short *out, unsigned frames) main_buffer[j+1] = 0; } - unsigned cid; for(cid = 0; cid < NUM_CHANNELS; cid++) { struct channel *c = &channels[cid]; @@ -155,24 +152,24 @@ static void mix(short *out, unsigned frames) while(v && v->sound && filled < frames) { - // calculate maximum frames to fill + /* calculate maximum frames to fill */ unsigned frames_left = (v->sound->num_samples - v->tick) >> (v->sound->channels-1); unsigned long to_fill = frames>frames_left?frames_left:frames; float vol = 1.0f; float pan = 0.0f; - // clamp to_fill if voice should stop + /* clamp to_fill if voice should stop */ if(v->stop >= 0) to_fill = (unsigned)v->stop>frames_left?frames:v->stop; - // clamp to_fill if we are about to loop + /* clamp to_fill if we are about to loop */ if(v->loop >= 0 && v->sound->loop_start >= 0) { unsigned tmp = v->sound->loop_end - v->tick; to_fill = tmp>to_fill?to_fill:tmp; } - // calculate voice volume and delta + /* calculate voice volume and delta */ if(c->flags & CHANNEL_POSITION_VOLUME) { float dx = v->x - center_x; @@ -181,14 +178,14 @@ static void mix(short *out, unsigned frames) if(dist < volume_deadzone*volume_deadzone) vol = master_vol * c->vol; else - vol = master_vol * c->vol / ((dist - volume_deadzone*volume_deadzone)*volume_falloff); //TODO: use some fast 1/x^2 + vol = master_vol * c->vol / ((dist - volume_deadzone*volume_deadzone)*volume_falloff); /*TODO: use some fast 1/x^2 */ } else { vol = master_vol * c->vol * v->vol; } - // calculate voice pan and delta + /* calculate voice pan and delta */ if(c->flags & CHANNEL_POSITION_PAN) { float dx = v->x - center_x; @@ -202,24 +199,24 @@ static void mix(short *out, unsigned frames) pan = master_pan + c->pan + v->pan; } - // fill the main buffer + /* fill the main buffer */ if(v->sound->channels == 1) fill_mono(&main_buffer[filled], to_fill, v, vol, pan); else fill_stereo(&main_buffer[filled], to_fill, v, vol, pan); - // reset tick of we hit loop point + /* reset tick of we hit loop point */ if(v->loop >= 0 && v->sound->loop_start >= 0 && v->tick >= v->sound->loop_end) v->tick = v->sound->loop_start; - // stop sample if nessecary + /* stop sample if nessecary */ if(v->stop >= 0) v->stop -= to_fill; if(v->tick >= v->sound->num_samples || v->stop == 0) { - struct voice *vn = v->next; + struct voice *vn = (struct voice *)v->next; if(!locked) { lock_wait(sound_lock); @@ -253,7 +250,7 @@ static void mix(short *out, unsigned frames) if(locked) lock_release(sound_lock); - // clamp accumulated values + /* clamp accumulated values */ for(i = 0; i < frames; i++) { int j = i<<1; @@ -345,21 +342,26 @@ int snd_load_wv(const char *filename) struct sound *snd; int sid = -1; char error[100]; + WavpackContext *context; sid = snd_alloc_id(); if(sid < 0) return -1; snd = &sounds[sid]; - file = fopen(filename, "rb"); // TODO: use system.h stuff for this + file = fopen(filename, "rb"); /* TODO: use system.h stuff for this */ - WavpackContext *context = WavpackOpenFileInput(read_data, error); + context = WavpackOpenFileInput(read_data, error); if (context) { int samples = WavpackGetNumSamples(context); int bitspersample = WavpackGetBitsPerSample(context); unsigned int samplerate = WavpackGetSampleRate(context); int channels = WavpackGetNumChannels(context); + int *data; + int *src; + short *dst; + int i; snd->channels = channels; snd->rate = samplerate; @@ -382,14 +384,13 @@ int snd_load_wv(const char *filename) return -1; } - int *data = (int *)mem_alloc(4*samples*channels, 1); - WavpackUnpackSamples(context, data, samples); // TODO: check return value - int *src = data; + data = (int *)mem_alloc(4*samples*channels, 1); + WavpackUnpackSamples(context, data, samples); /* TODO: check return value */ + src = data; snd->data = (short *)mem_alloc(2*samples*channels, 1); - short *dst = snd->data; + dst = snd->data; - int i; for (i = 0; i < samples*channels; i++) *dst++ = (short)*src++; @@ -413,10 +414,15 @@ int snd_load_wv(const char *filename) return sid; } +#if 0 int snd_load_wav(const char *filename) { - // open file for reading + /* open file for reading */ IOHANDLE file; + struct sound *snd; + int sid = -1; + int state = 0; + file = io_open(filename, IOFLAG_READ); if(!file) { @@ -424,37 +430,35 @@ int snd_load_wav(const char *filename) return -1; } - struct sound *snd; - int sid = -1; - sid = snd_alloc_id(); if(sid < 0) return -1; snd = &sounds[sid]; - int state = 0; while(1) { - // read chunk header + /* read chunk header */ unsigned char head[8]; + int chunk_size; if(io_read(file, head, sizeof(head)) != 8) { break; } - int chunk_size = head[4] | (head[5]<<8) | (head[6]<<16) | (head[7]<<24); + chunk_size = head[4] | (head[5]<<8) | (head[6]<<16) | (head[7]<<24); head[4] = 0; if(state == 0) { - // read the riff and wave headers + unsigned char type[4]; + + /* read the riff and wave headers */ if(head[0] != 'R' || head[1] != 'I' || head[2] != 'F' || head[3] != 'F') { dbg_msg("sound/wav", "not a RIFF file. filename='%s'", filename); return -1; } - unsigned char type[4]; io_read(file, type, 4); if(type[0] != 'W' || type[1] != 'A' || type[2] != 'V' || type[3] != 'E') @@ -467,7 +471,7 @@ int snd_load_wav(const char *filename) } else if(state == 1) { - // read the format chunk + /* read the format chunk */ if(head[0] == 'f' && head[1] == 'm' && head[2] == 't' && head[3] == ' ') { unsigned char fmt[16]; @@ -477,7 +481,7 @@ int snd_load_wav(const char *filename) return -1; } - // decode format + /* decode format */ int compression_code = fmt[0] | (fmt[1]<<8); snd->channels = fmt[2] | (fmt[3]<<8); snd->rate = fmt[4] | (fmt[5]<<8) | (fmt[6]<<16) | (fmt[7]<<24); @@ -507,7 +511,7 @@ int snd_load_wav(const char *filename) return -1; } - // next state + /* next state */ state++; } else @@ -515,7 +519,7 @@ int snd_load_wav(const char *filename) } else if(state == 2) { - // read the data + /* read the data */ if(head[0] == 'd' && head[1] == 'a' && head[2] == 't' && head[3] == 'a') { snd->data = (short*)mem_alloc(chunk_size, 1); @@ -571,6 +575,8 @@ int snd_load_wav(const char *filename) return sid; } +#endif + int snd_play(int cid, int sid, int loop, float x, float y) { @@ -611,7 +617,7 @@ void snd_set_master_volume(float val) void snd_stop(int vid) { - //TODO: lerp volume to 0 + /*TODO: lerp volume to 0*/ voices[vid].stop = 0; } diff --git a/src/engine/client/srvbrowse.c b/src/engine/client/srvbrowse.c index cf0a4467..471fdfd6 100644 --- a/src/engine/client/srvbrowse.c +++ b/src/engine/client/srvbrowse.c @@ -23,9 +23,9 @@ struct SERVERENTRY_t int got_info; SERVER_INFO info; - SERVERENTRY *next_ip; // ip hashed list + SERVERENTRY *next_ip; /* ip hashed list */ - SERVERENTRY *prev_req; // request list + SERVERENTRY *prev_req; /* request list */ SERVERENTRY *next_req; }; @@ -33,9 +33,9 @@ static HEAP *serverlist_heap = 0; static SERVERENTRY **serverlist = 0; static int *sorted_serverlist = 0; -static SERVERENTRY *serverlist_ip[256] = {0}; // ip hash list +static SERVERENTRY *serverlist_ip[256] = {0}; /* ip hash list */ -static SERVERENTRY *first_req_server = 0; // request list +static SERVERENTRY *first_req_server = 0; /* request list */ static SERVERENTRY *last_req_server = 0; static int num_requests = 0; @@ -228,8 +228,9 @@ void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *info) if(num_servers == num_server_capacity) { + SERVERENTRY **newlist; num_server_capacity += 100; - SERVERENTRY **newlist = mem_alloc(num_server_capacity*sizeof(SERVERENTRY*), 1); + newlist = mem_alloc(num_server_capacity*sizeof(SERVERENTRY*), 1); memcpy(newlist, serverlist, num_servers*sizeof(SERVERENTRY*)); mem_free(serverlist); serverlist = newlist; @@ -314,6 +315,8 @@ void client_serverbrowse_refresh(int lan) static void client_serverbrowse_request(SERVERENTRY *entry) { + NETPACKET p; + if(config.debug) { dbg_msg("client", "requesting server info from %d.%d.%d.%d:%d", @@ -321,7 +324,6 @@ static void client_serverbrowse_request(SERVERENTRY *entry) entry->addr.ip[3], entry->addr.port); } - NETPACKET p; p.client_id = -1; p.address = entry->addr; p.flags = PACKETFLAG_CONNLESS; @@ -336,14 +338,13 @@ void client_serverbrowse_update() int64 timeout = time_freq(); int64 now = time_get(); int count; - SERVERENTRY *entry, *next; /* do timeouts */ entry = first_req_server; while(1) { - if(!entry) // no more entries + if(!entry) /* no more entries */ break; next = entry->next_req; @@ -363,10 +364,11 @@ void client_serverbrowse_update() count = 0; while(1) { - if(!entry) // no more entries + if(!entry) /* no more entries */ break; - - if(count == config.b_max_requests) // no more then 10 concurrent requests + + /* no more then 10 concurrent requests */ + if(count == config.b_max_requests) break; if(entry->request_time == 0) diff --git a/src/engine/client/ui.c b/src/engine/client/ui.c index eb07e7b5..434f776f 100644 --- a/src/engine/client/ui.c +++ b/src/engine/client/ui.c @@ -5,7 +5,6 @@ /******************************************************** UI *********************************************************/ -//static unsigned mouse_buttons_last = 0; struct pretty_font { @@ -20,8 +19,8 @@ static void *hot_item = 0; static void *active_item = 0; static void *last_active_item = 0; static void *becomming_hot_item = 0; -static float mouse_x, mouse_y; // in gui space -static float mouse_wx, mouse_wy; // in world space +static float mouse_x, mouse_y; /* in gui space */ +static float mouse_wx, mouse_wy; /* in world space */ static unsigned mouse_buttons = 0; float ui_mouse_x() { return mouse_x; } @@ -39,7 +38,6 @@ void *ui_last_active_item() { return last_active_item; } int ui_update(float mx, float my, float mwx, float mwy, int buttons) { - //mouse_buttons_last = mouse_buttons; mouse_x = mx; mouse_y = my; mouse_wx = mwx; @@ -52,12 +50,6 @@ int ui_update(float mx, float my, float mwx, float mwy, int buttons) return 0; } -/* -static int ui_mouse_button_released(int index) -{ - return ((mouse_buttons_last>>index)&1) && !(); -}*/ - int ui_mouse_inside(float x, float y, float w, float h) { if(mouse_x >= x && mouse_x <= x+w && mouse_y >= y && mouse_y <= y+h) @@ -72,10 +64,10 @@ void ui_do_image(int texture, float x, float y, float w, float h) gfx_quads_begin(); gfx_setcolor(1,1,1,1); gfx_quads_setsubset( - 0.0f, // startx - 0.0f, // starty - 1.0f, // endx - 1.0f); // endy + 0.0f, /* startx */ + 0.0f, /* starty */ + 1.0f, /* endx */ + 1.0f); /* endy */ gfx_quads_drawTL(x,y,w,h); gfx_quads_end(); } @@ -89,7 +81,7 @@ void ui_do_label(float x, float y, const char *text, float size) int ui_do_button(void *id, const char *text, int checked, float x, float y, float w, float h, draw_button_callback draw_func, void *extra) { - // logic + /* logic */ int r = 0; int inside = ui_mouse_inside(x,y,w,h); |