From 1802cace77d9773785cb8e512e7658735c46ab86 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sun, 5 Nov 2006 17:41:27 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@472 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/Makefile | 29 +- source/src/bot/bot_ai.cpp | 6 +- source/src/bot/bot_util.cpp | 6 +- source/src/bot/bot_waypoint.cpp | 6 +- source/src/bot/botmanager.cpp | 26 +- source/src/client.cpp | 12 +- source/src/clientextras.cpp | 20 +- source/src/clientgame.cpp | 80 +++--- source/src/clients2c.cpp | 14 +- source/src/command.cpp | 36 +-- source/src/console.cpp | 37 +-- source/src/cube.h | 72 +++-- source/src/entities.cpp | 24 +- source/src/main.cpp | 186 ++++++++++++- source/src/menus.cpp | 14 +- source/src/physics.cpp | 10 +- source/src/protos.h | 10 +- source/src/renderextras.cpp | 36 +-- source/src/rendergl.cpp | 8 +- source/src/rendermd2.cpp | 10 +- source/src/rendermd3.cpp | 14 +- source/src/rendertext.cpp | 44 ++- source/src/savegamedemo.cpp | 12 +- source/src/server.cpp | 34 +-- source/src/serverbrowser.cpp | 182 +++++++----- source/src/serverms.cpp | 16 +- source/src/serverutil.cpp | 2 +- source/src/sound.cpp | 8 +- source/src/tools.cpp | 108 +------- source/src/tools.h | 474 ++++++++++++++++++++++---------- source/src/weapon.cpp | 4 +- source/src/world.cpp | 6 +- source/src/worldio.cpp | 20 +- source/src/worldlight.cpp | 6 +- source/src/worldocull.cpp | 8 +- 35 files changed, 960 insertions(+), 620 deletions(-) diff --git a/source/src/Makefile b/source/src/Makefile index 901e7324..c4194528 100644 --- a/source/src/Makefile +++ b/source/src/Makefile @@ -19,7 +19,7 @@ CLIENT_OBJS= \ renderextras.o \ rendergl.o \ rendermd2.o \ - rendermd3.o \ + rendermd3.o \ renderparticles.o \ rendertext.o \ rndmap.o \ @@ -36,13 +36,13 @@ CLIENT_OBJS= \ worldlight.o \ worldocull.o \ worldrender.o \ - bot/bot.o \ - bot/botmanager.o \ - bot/bot_ai.o \ - bot/bot_util.o \ - bot/bot_waypoint.o \ - bot/ac_bot.o \ - bot/ac_bot_ai.o + bot/bot.o \ + bot/botmanager.o \ + bot/bot_ai.o \ + bot/bot_util.o \ + bot/bot_waypoint.o \ + bot/ac_bot.o \ + bot/ac_bot_ai.o SERVER_LIBS=-L../enet -lenet @@ -54,14 +54,17 @@ SERVER_FILES= \ default: all -all: enet client server +all: libenet client server -enet: - -make -C ../enet all +../enet/Makefile: + cd ../enet; ./configure + +libenet: ../enet/Makefile + -$(MAKE) -C ../enet all clean: - -rm -f $(SERVER_OBJS) $(CLIENT_OBJS) ac_server ac_client -# -make -C ../enet/ clean + -$(RM) -f $(SERVER_OBJS) $(CLIENT_OBJS) ac_server ac_client +# -$(MAKE) -C ../enet/ clean client: $(CLIENT_OBJS) $(CXX) $(CXXFLAGS) -o ac_client $(CLIENT_OBJS) $(CLIENT_LIBS) diff --git a/source/src/bot/bot_ai.cpp b/source/src/bot/bot_ai.cpp index 44afd59e..28ce2100 100644 --- a/source/src/bot/bot_ai.cpp +++ b/source/src/bot/bot_ai.cpp @@ -1876,7 +1876,7 @@ void CBot::CheckFOV() TraceLine(origin, dest, m_pMyEnt, false, &tr); - int cx = fast_f2nat(tr.end.x), cy = fast_f2nat(tr.end.y); + int cx = int(tr.end.x), cy = int(tr.end.y); short CubesInWater=0; for(int x=cx-1;x<=(cx+1);x++) { @@ -1954,8 +1954,8 @@ bool CBot::WaterNav() AddDebugText("WaterNav"); // Find the nearest and reachable cube which isn't underwater - int cx = fast_f2nat(m_pMyEnt->o.x); - int cy = fast_f2nat(m_pMyEnt->o.y); + int cx = int(m_pMyEnt->o.x); + int cy = int(m_pMyEnt->o.y); float flNearestDist = 9999.0f, flDist; if (OUTBORD(cx, cy)) return false; diff --git a/source/src/bot/bot_util.cpp b/source/src/bot/bot_util.cpp index 6ca78b6a..ea53a0ae 100644 --- a/source/src/bot/bot_util.cpp +++ b/source/src/bot/bot_util.cpp @@ -293,8 +293,8 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult if (GetDistance(from, to) < flNearestDist) { tr->end = to; - sqr *s = S(fast_f2nat(from.x), fast_f2nat(from.y)); - float flr = GetCubeFloor(fast_f2nat(from.x), fast_f2nat(from.y)); + sqr *s = S(int(from.x), int(from.y)); + float flr = GetCubeFloor(int(from.x), int(from.y)); solid = ((!SkipTags || !s->tag) && SOLID(s)); if (solid || (to.z < flr) || (to.z > s->ceil)) { @@ -315,7 +315,7 @@ void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult { if(OUTBORD((int)x, (int)y)) break; if (GetDistance(from, endcube) >= flNearestDist) break; - sqr *s = S(fast_f2nat(x), fast_f2nat(y)); + sqr *s = S(int(x), int(y)); solid = ((!SkipTags || !s->tag) && SOLID(s)); if(solid) break; float floor = s->floor; diff --git a/source/src/bot/bot_waypoint.cpp b/source/src/bot/bot_waypoint.cpp index 9169def3..e928dce5 100644 --- a/source/src/bot/bot_waypoint.cpp +++ b/source/src/bot/bot_waypoint.cpp @@ -614,7 +614,7 @@ void CWaypointClass::DrawNearWaypoints() { TLinkedList::node_s *pNode; node_s *pNearest = NULL; - short i, j, MinI, MaxI, MinJ, MaxJ, Offset = ceil(15.0f / MAX_MAP_GRIDS); + short i, j, MinI, MaxI, MinJ, MaxJ, Offset = (short)ceilf(15.0f / MAX_MAP_GRIDS); float flNearestDist = 9999.99, flDist; GetNodeIndexes(player1->o, &i, &j); @@ -1413,8 +1413,8 @@ bool CWaypointClass::CanPlaceNodeHere(const vec &from) static traceresult_s tr; static vec to, v1, v2; - x = fast_f2nat(from.x); - y = fast_f2nat(from.y); + x = short(from.x); + y = short(from.y); sqr *s = S(x, y); if (SOLID(s)) diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index 50aa75f8..098704b1 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -175,7 +175,7 @@ void CBotManager::LoadBotNamesFile() { conoutf("Warning: bot name \"%s\" has to many characters(16 is max)", szNameBuffer); } - strn0cpy(m_szBotNames[m_sBotNameCount], szNameBuffer, 16); + s_strncpy(m_szBotNames[m_sBotNameCount], szNameBuffer, 16); m_sBotNameCount++; } } @@ -270,7 +270,7 @@ void CBotManager::LoadBotTeamsFile() if (szNameBuffer[0] != 0) { - strn0cpy(m_szBotTeams[m_sBotTeamCount], szNameBuffer, 5); + s_strncpy(m_szBotTeams[m_sBotTeamCount], szNameBuffer, 5); m_sBotTeamCount++; } } @@ -319,7 +319,7 @@ extern void renderplayer(dynent *d); void CBotManager::RenderBots() { - static bool drawblue; + //static bool drawblue; loopv(bots) { @@ -934,14 +934,14 @@ dynent *CBotManager::CreateBot(const char *team, const char *skill, const char * m->pBot->m_bSendC2SInit = false; if (name && *name) - strn0cpy(m->name, name, 16); + s_strncpy(m->name, name, 16); else - strn0cpy(m->name, BotManager.GetBotName(), 16); + s_strncpy(m->name, BotManager.GetBotName(), 16); if (team && *team && strcmp(team, "random")) - strn0cpy(m->team, team, 5); + s_strncpy(m->team, team, 5); else - strn0cpy(m->team, BotManager.GetBotTeam(), 5); + s_strncpy(m->team, BotManager.GetBotTeam(), 5); if (skill && *skill && strcmp(skill, "random")) { @@ -989,7 +989,7 @@ bool botmode() void addbot(char *arg1, char *arg2, char *arg3) { - if(!botmode) return; + if(!botmode()) return; if (ishost()) { conoutf("Creating bot...\n"); @@ -1039,7 +1039,7 @@ COMMAND(addbot, ARG_3STR); void addnbot(char *arg1, char *arg2, char *arg3) { - if(!botmode) return; + if(!botmode()) return; if (!arg1 || !arg1[0]) return; int i = atoi(arg1); @@ -1123,7 +1123,7 @@ COMMAND(idlebots, ARG_1INT); void drawbeamtobots() { - if(!botmode) return; + if(!botmode()) return; loopv(bots) { if (bots[i]) @@ -1135,7 +1135,7 @@ COMMAND(drawbeamtobots, ARG_NONE); void kickbot(const char *szName) { - if(!botmode) return; + if(!botmode()) return; if (!szName || !(*szName)) return; @@ -1221,7 +1221,7 @@ COMMAND(kickallbots, ARG_NONE); void togglegrap() { - if(!botmode) return; + if(!botmode()) return; if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GrabMode(0)) SDL_WM_GrabInput(SDL_GRAB_ON); else @@ -1232,7 +1232,7 @@ COMMAND(togglegrap, ARG_NONE); void togglebotview(char *bot) { - if(!botmode) return; + if(!botmode()) return; if (BotManager.m_pBotToView) BotManager.DisableBotView(); else if (bot && *bot) diff --git a/source/src/client.cpp b/source/src/client.cpp index 91288921..d70c3084 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -36,7 +36,7 @@ VARF(throttle_decel, 0, 2, 32, throttle()); void throttle() { if(!clienthost || connecting) return; - assert(ENET_PEER_PACKET_THROTTLE_SCALE==32); + ASSERT(ENET_PEER_PACKET_THROTTLE_SCALE==32); enet_peer_throttle_configure(clienthost->peers, throttle_interval*1000, throttle_accel, throttle_decel); }; @@ -52,12 +52,12 @@ void ctf_team(char *name) player1->state = CS_DEAD; }; -void newname(char *name) { c2sinit = false; strn0cpy(player1->name, name, 16); }; +void newname(char *name) { c2sinit = false; s_strncpy(player1->name, name, 16); }; void newskin(int skin) { player1->nextskin = max(0, min(skin, (rb_team_int(player1->team)==TEAM_CLA ? 3 : 5))); }; void newteam(char *name) { if(m_teammode) ctf_team(name); - else { strn0cpy(player1->team, name, 5); c2sinit=false; }; + else { s_strncpy(player1->team, name, 5); c2sinit=false; }; }; COMMANDN(team, newteam, ARG_1STR); @@ -144,7 +144,7 @@ void trydisconnect() }; string ctext; -void toserver(char *text) { conoutf("%s:\f %s", player1->name, text); strn0cpy(ctext, text, 80); }; +void toserver(char *text) { conoutf("%s:\f %s", player1->name, text); s_strncpy(ctext, text, 80); }; void echo(char *text) { conoutf("%s", text); }; COMMAND(echo, ARG_VARI); @@ -159,7 +159,7 @@ vector messages; void addmsg(int rel, int num, int type, ...) { if(demoplayback) return; - if(num!=msgsizelookup(type)) { sprintf_sd(s)("inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); fatal(s); }; + if(num!=msgsizelookup(type)) { s_sprintfd(s)("inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); fatal(s); }; if(messages.length()==100) { conoutf("command flood protection (type %d)", type); return; }; ivector &msg = messages.add(); msg.add(num); @@ -183,7 +183,7 @@ bool senditemstoserver = false; // after a map change, since server doesn't string clientpassword; char *toserverpwd = NULL; -void password(char *p) { strcpy_s(clientpassword, p); }; +void password(char *p) { s_strcpy(clientpassword, p); }; COMMAND(password, ARG_1STR); bool netmapstart() { senditemstoserver = true; return clienthost!=NULL; }; diff --git a/source/src/clientextras.cpp b/source/src/clientextras.cpp index 365c9996..5e8edd71 100644 --- a/source/src/clientextras.cpp +++ b/source/src/clientextras.cpp @@ -61,12 +61,12 @@ void renderplayer(dynent *d) if(!d) return; int team = rb_team_int(d->team); - sprintf_sd(mdl)("playermodels/%s/0%i", team==TEAM_CLA ? "terrorist" : "counterterrorist", 1 + max(0, min(d->skin, (team==TEAM_CLA ? 3 : 5)))); + s_sprintfd(mdl)("playermodels/%s/0%i", team==TEAM_CLA ? "terrorist" : "counterterrorist", 1 + max(0, min(d->skin, (team==TEAM_CLA ? 3 : 5)))); renderclient(d, isteam(player1->team, d->team), mdl, 1.55f); if(d->gunselect>=0 && d->gunselectgunselect]); + s_sprintfd(vwep)("weapons/%s/world", hudgunnames[d->gunselect]); renderclient(d, isteam(player1->team, d->team), vwep, 1.55f); }; } @@ -106,10 +106,10 @@ int menu = 0; void renderscore(dynent *d) { - sprintf_sd(lag)("%d", d->plag); - sprintf_sd(name) ("(%s)", d->name); - if(m_ctf) sprintf_s(scorelines.add().s)("%d\t%d\t%s\t%d\t%s\t%s", d->flagscore, d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, d->team, d->state==CS_DEAD ? name : d->name); - else sprintf_s(scorelines.add().s)("%d\t%s\t%d\t%s\t%s", d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, m_teammode ? d->team : "", d->state==CS_DEAD ? name : d->name); + s_sprintfd(lag)("%d", d->plag); + s_sprintfd(name) ("(%s)", d->name); + if(m_ctf) s_sprintf(scorelines.add().s)("%d\t%d\t%s\t%d\t%s\t%s", d->flagscore, d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, d->team, d->state==CS_DEAD ? name : d->name); + else s_sprintf(scorelines.add().s)("%d\t%s\t%d\t%s\t%s", d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, m_teammode ? d->team : "", d->state==CS_DEAD ? name : d->name); menumanual(menu, scorelines.length()-1, scorelines.last().s); }; @@ -158,9 +158,9 @@ void renderscores() loopj(teamsused) { string sc; - if(m_ctf) sprintf_s(sc)("[ %s: %d flags %d frags ]", teamname[j], teamflagscore[j], teamscore[j]); - else sprintf_s(sc)("[ %s: %d ]", teamname[j], teamscore[j]); - strcat_s(teamscores, sc); + if(m_ctf) s_sprintf(sc)("[ %s: %d flags %d frags ]", teamname[j], teamflagscore[j], teamscore[j]); + else s_sprintf(sc)("[ %s: %d ]", teamname[j], teamscore[j]); + s_strcat(teamscores, sc); }; menumanual(menu, scorelines.length(), ""); menumanual(menu, scorelines.length()+1, teamscores); @@ -197,7 +197,7 @@ void sendmap(char *mapname) enet_packet_resize(packet, p-start); sendpackettoserv(packet); conoutf("sending map %s to server...", mapname); - sprintf_sd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname); + s_sprintfd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname); toserver(msg); } diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 025faa0e..d8e1fda5 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -80,7 +80,7 @@ void spawnstate(dynent *d) // reset player state not persistent acc dynent *newdynent() // create a new blank player or monster { - dynent *d = (dynent *)gp()->alloc(sizeof(dynent)); + dynent *d = new dynent; d->o.x = 0; d->o.y = 0; d->o.z = 0; @@ -231,8 +231,7 @@ void checkakimbo() void zapdynent(dynent *&d) { - if(d) gp()->dealloc(d, sizeof(dynent)); - d = NULL; + DELETEP(d); }; extern int democlientnum; @@ -265,7 +264,7 @@ struct scriptsleep { int wait; string cmd; - scriptsleep(int msec, char *command) { wait = msec+lastmillis; strcpy_s(cmd, command); }; + scriptsleep(int msec, char *command) { wait = msec+lastmillis; s_strcpy(cmd, command); }; }; vector sleeps; @@ -276,52 +275,47 @@ string sleepcmd;*/ void addsleep(char *msec, char *cmd) { scriptsleep s(atoi(msec), cmd); sleeps.add(s); }; COMMANDN(sleep, addsleep, ARG_2STR); -void updateworld(int millis) // main game update loop +void updateworld(int curtime, int lastmillis) // main game update loop { - if(lastmillis) - { - curtime = millis - lastmillis; - //if(sleepwait && lastmillis>sleepwait) { sleepwait = 0; execute(sleepcmd); }; - loopv(sleeps) if(sleeps[i].wait && lastmillis > sleeps[i].wait) { execute(sleeps[i].cmd); sleeps.remove(i); i--; }; - physicsframe(); - checkakimbo(); - checkweaponswitch(); + //if(sleepwait && lastmillis>sleepwait) { sleepwait = 0; execute(sleepcmd); }; + loopv(sleeps) if(sleeps[i].wait && lastmillis > sleeps[i].wait) { execute(sleeps[i].cmd); sleeps.remove(i); i--; }; + physicsframe(); + checkakimbo(); + checkweaponswitch(); //if(m_arena) arenarespawn(); - arenarespawn(); - moveprojectiles((float)curtime); - demoplaybackstep(); - if(!demoplayback) + arenarespawn(); + moveprojectiles((float)curtime); + demoplaybackstep(); + if(!demoplayback) + { + if(getclientnum()>=0) shoot(player1, worldpos); // only shoot when connected to server + gets2c(); // do this first, so we have most accurate information when our player moves + }; + mphysents(); + otherplayers(); + if(!demoplayback) + { + //monsterthink(); + + // Added by Rick: let bots think + BotManager.Think(); + + //put game mode extra call here + if(player1->state==CS_DEAD) { - if(getclientnum()>=0) shoot(player1, worldpos); // only shoot when connected to server - gets2c(); // do this first, so we have most accurate information when our player moves - }; - mphysents(); - otherplayers(); - if(!demoplayback) - { - //monsterthink(); - - // Added by Rick: let bots think - BotManager.Think(); - - //put game mode extra call here - if(player1->state==CS_DEAD) - { if(lastmillis-player1->lastaction<2000) { player1->move = player1->strafe = 0; moveplayer(player1, 10, false); }; - } - else if(!intermission) - { - moveplayer(player1, 20, true); + } + else if(!intermission) + { + moveplayer(player1, 20, true); checkitems(); - }; - c2sinfo(player1); // do this last, to reduce the effective frame lag }; + c2sinfo(player1); // do this last, to reduce the effective frame lag }; - lastmillis = millis; }; void entinmap(dynent *d) // brute force but effective way to find a free spawn spot in the map @@ -358,7 +352,7 @@ int nearestenemy(vec *v, string team) else if(distsquared < nearestPlayerDistSquared) nearestPlayerDistSquared = distsquared; // if a player is closer }; if(nearestPlayerDistSquared >= securespawndist * securespawndist || nearestPlayerDistSquared == -1) return -1; // a distance more than securespawndist means the place is free - else return (int) sqrt(nearestPlayerDistSquared); + else return (int)sqrtf(nearestPlayerDistSquared); }; int spawncycle = -1; @@ -618,7 +612,7 @@ void startmap(char *name) // called just after a map load player1->flagscore = 0; loopv(players) if(players[i]) players[i]->frags = 0; resetspawns(); - strcpy_s(clientmap, name); + s_strcpy(clientmap, name); if(editmode) toggleedit(); setvar("gamespeed", 100); setvar("fog", 180); @@ -694,7 +688,7 @@ void getmaster(char *pwd) { if(!pwd[0]) return; if(strlen(pwd)>15) { conoutf("the master password has a maximum length of 15 characters"); return; }; - strcpy_s(masterpwd, pwd); + s_strcpy(masterpwd, pwd); }; void mastercommand(int cmd, int a) @@ -716,4 +710,4 @@ void showmastermenu(int m) // 0=kick, 1=ban COMMANDN(masterlogin, getmaster, ARG_1STR); COMMAND(mastercommand, ARG_2INT); -COMMAND(showmastermenu, ARG_1INT); \ No newline at end of file +COMMAND(showmastermenu, ARG_1INT); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 1ee7e1cc..7eb32fad 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -22,7 +22,7 @@ void changemapserv(char *name, int mode) // forced map change from the se void changemap(char *name) // request map change, server may ignore { - strcpy_s(toservermap, name); + s_strcpy(toservermap, name); }; // Added by Rick @@ -122,7 +122,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th { conoutf("you are BANNED from this server"); } - else if(firstplayer) strcpy_s(toservermap, getclientmap()); // we are the first client on this server, set map + else if(firstplayer) s_strcpy(toservermap, getclientmap()); // we are the first client on this server, set map break; }; @@ -179,7 +179,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_MAPRELOAD: // server requests next map { getint(p); - sprintf_sd(nextmapalias)("nextmap_%s", getclientmap()); + s_sprintfd(nextmapalias)("nextmap_%s", getclientmap()); char *map = getalias(nextmapalias); // look up map in the cycle changemap(map ? map : getclientmap()); break; @@ -204,9 +204,9 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th BotManager.LetBotsUpdateStats(); // End add by Rick }; - strcpy_s(d->name, text); + s_strcpy(d->name, text); sgetstr(); - strcpy_s(d->team, text); + s_strcpy(d->team, text); d->skin = getint(p); d->lifesequence = getint(p); c2si = true; @@ -522,9 +522,9 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th //c2sinit = false; // send new players my info again conoutf("connected: %s", &text); }; - strcpy_s(b->name, text); + s_strcpy(b->name, text); sgetstr(); - strcpy_s(b->team, text); + s_strcpy(b->team, text); b->lifesequence = getint(p); b->bIsBot = true; b->pBot = NULL; diff --git a/source/src/command.cpp b/source/src/command.cpp index fb1f6744..c545b7b8 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -17,10 +17,10 @@ struct ident bool persist; }; -void itoa(char *s, int i) { sprintf_s(s)("%d", i); }; -char *exchangestr(char *o, char *n) { gp()->deallocstr(o); return newstring(n); }; +void itoa(char *s, int i) { s_sprintf(s)("%d", i); }; +char *exchangestr(char *o, char *n) { delete[] o; return newstring(n); }; -hashtable *idents = NULL; // contains ALL vars/commands/aliases +hashtable *idents = NULL; // contains ALL vars/commands/aliases void alias(char *name, char *action) { @@ -44,7 +44,7 @@ COMMAND(alias, ARG_2STR); int variable(char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist) { - if(!idents) idents = new hashtable; + if(!idents) idents = new hashtable; ident v = { ID_VAR, name, min, max, storage, fun, 0, 0, persist }; idents->access(name, &v); return cur; @@ -62,7 +62,7 @@ char *getalias(char *name) bool addcommand(char *name, void (*fun)(), int narg) { - if(!idents) idents = new hashtable; + if(!idents) idents = new hashtable; ident c = { ID_COMMAND, name, 0, 0, 0, fun, narg, 0 }; idents->access(name, &c); return false; @@ -179,9 +179,9 @@ int execute(char *p, bool isdown) // all evaluation happens here, r[0] = 0; for(int i = 1; ifun)(r); break; @@ -217,15 +217,15 @@ int execute(char *p, bool isdown) // all evaluation happens here, case ID_ALIAS: // alias, also used as functions and (global) variables for(int i = 1; iaction); // create new string here because alias could rebind itself val = execute(action, isdown); - gp()->deallocstr(action); + delete[] action; break; }; - loopj(numargs) gp()->deallocstr(w[j]); + loopj(numargs) delete[] w[j]; }; return val; }; @@ -241,18 +241,18 @@ void complete(char *s) if(*s!='/') { string t; - strcpy_s(t, s); - strcpy_s(s, "/"); - strcat_s(s, t); + s_strcpy(t, s); + s_strcpy(s, "/"); + s_strcat(s, t); }; if(!s[1]) return; if(!completesize) { completesize = strlen(s)-1; completeidx = 0; }; int idx = 0; - enumerate(idents, ident *, id, - if(strncmp(id->name, s+1, completesize)==0 && idx++==completeidx) + enumerate(*idents, ident, id, + if(strncmp(id.name, s+1, completesize)==0 && idx++==completeidx) { - strcpy_s(s, "/"); - strcat_s(s, id->name); + s_strcpy(s, "/"); + s_strcat(s, id.name); }; ); completeidx++; @@ -262,7 +262,7 @@ void complete(char *s) bool execfile(char *cfgfile) { string s; - strcpy_s(s, cfgfile); + s_strcpy(s, cfgfile); char *buf = loadfile(path(s), NULL); if(!buf) return false; execute(buf); diff --git a/source/src/console.cpp b/source/src/console.cpp index 0df1b824..ddc32ed1 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -31,28 +31,29 @@ void conline(const char *sf, bool highlight) // add a line to the console { cl.cref[0] = '\f'; cl.cref[1] = 0; - strcat_s(cl.cref, sf); + s_strcat(cl.cref, sf); } else { - strcpy_s(cl.cref, sf); + s_strcpy(cl.cref, sf); }; - puts(cl.cref); }; void conoutf(const char *s, ...) { - sprintf_sdv(sf, s); + s_sprintfdv(sf, s); + puts(sf); s = sf; - int n = 0; - while(strlen(s)>WORDWRAP) // cut strings to fit on screen + int n = 0, visible; + while((visible = text_visible(s, VIRTW*4/3 - FONTH))) // cut strings to fit on screen { + const char *newline = (const char *)memchr(s, '\n', visible); + if(newline) visible = newline+1-s; string t; - strn0cpy(t, s, WORDWRAP+1); + s_strncpy(t, s, visible+1); conline(t, n++!=0); - s += WORDWRAP; + s += visible; }; - conline(s, n!=0); }; void renderconsole() // render buffer taking into account time & scrolling @@ -66,7 +67,7 @@ void renderconsole() // render buffer taking into }; loopj(nd) { - draw_text(refs[j], FONTH/3, (FONTH/4*5)*(nd-j-1)+FONTH/3, 2); + draw_text(refs[j], FONTH/3, (FONTH/4*5)*(nd-j-1)+FONTH/3); }; }; @@ -89,7 +90,7 @@ void bindkey(char *key, char *action) for(char *x = key; *x; x++) *x = toupper(*x); loopi(numkm) if(strcmp(keyms[i].name, key)==0) { - strcpy_s(keyms[i].action, action); + s_strcpy(keyms[i].action, action); return; }; conoutf("unknown key \"%s\"", key); @@ -103,10 +104,10 @@ void saycommand(char *init) // turns input to the comman setscope(false); if(!editmode) keyrepeat(saycommandon); if(!init) init = ""; - strcpy_s(commandbuf, init); + s_strcpy(commandbuf, init); }; -void mapmsg(char *s) { strn0cpy(hdr.maptitle, s, 128); }; +void mapmsg(char *s) { s_strncpy(hdr.maptitle, s, 128); }; COMMAND(saycommand, ARG_VARI); COMMAND(mapmsg, ARG_1STR); @@ -122,7 +123,7 @@ void pasteconsole() if(!IsClipboardFormatAvailable(CF_TEXT)) return; if(!OpenClipboard(NULL)) return; char *cb = (char *)GlobalLock(GetClipboardData(CF_TEXT)); - strcat_s(commandbuf, cb); + s_strcat(commandbuf, cb); GlobalUnlock(cb); CloseClipboard(); #else @@ -185,11 +186,11 @@ void keypress(int code, bool isdown, int cooked) }; case SDLK_UP: - if(histpos) strcpy_s(commandbuf, vhistory[--histpos]); + if(histpos) s_strcpy(commandbuf, vhistory[--histpos]); break; case SDLK_DOWN: - if(histpos + +#ifdef __GNUC__ +#undef gamma +#endif + +#include +#include +#include +#include +#include +#ifdef __GNUC__ +#include +#else +#include +#endif + +#ifdef WIN32 + #define strcasecmp strcmp // fixme + #define WIN32_LEAN_AND_MEAN + #include "windows.h" + #define _WINDOWS + #define ZLIB_DLL + #define cos(x) cos((float)(x)) + #define sin(x) sin((float)(x)) +#else + #include +#endif + +#include +#include + +#define GL_GLEXT_LEGACY +#define __glext_h__ +#define NO_SDL_GLEXT +#include +#undef __glext_h__ +#include "GL/glext.h" + +#include + +#include + #include "tools.h" enum // block types, order matters! @@ -458,31 +505,6 @@ enum // function signatures for script functions, see command.cpp #define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers -#ifdef WIN32 - #define strcasecmp strcmp // fixme - #define WIN32_LEAN_AND_MEAN - #include "windows.h" - #define _WINDOWS - #define ZLIB_DLL - #define cos(x) cos((float)(x)) - #define sin(x) sin((float)(x)) -#else - #include -#endif - -#include - -#include -#include -#include - -#include -#include - -#include - -#include - // Added by Rick extern ENetHost *clienthost; inline bool ishost(void) { return !clienthost; }; diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 8a649a01..2a9cbe59 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -37,14 +37,14 @@ void renderentities() if(f.state==CTFF_STOLEN && f.thief) { if(f.thief == player1) continue; - sprintf_sd(path)("pickups/flags/small_%s", rb_team_string(e.attr2)); + s_sprintfd(path)("pickups/flags/small_%s", rb_team_string(e.attr2)); mapmodelinfo mmi = {10, 4, 0, 0, path}; if(!&mmi) continue; rendermodel(mmi.name, 0, 1, 0, 0, f.thief->o.x, f.thief->o.z+0.3f+(sin(lastmillis/100.0f)+1)/10, f.thief->o.y, lastmillis/2.5f, 0, false, 0.6f, 120.0f, mmi.snap); } else { - sprintf_sd(path)("pickups/flags/%s", rb_team_string(e.attr2)); + s_sprintfd(path)("pickups/flags/%s", rb_team_string(e.attr2)); mapmodelinfo mmi = {10, 4, 0, 0, path}; if(!&mmi) continue; rendermodel(mmi.name, 0, 7, 0, (float)mmi.rad, e.x, f.state==CTFF_INBASE ? (float)S(e.x, e.y)->floor : e.z, e.y, (float)((e.attr1+7)-(e.attr1+7)%15), 0, false, 1.0f, 120.0f, mmi.snap); @@ -80,16 +80,16 @@ void renderentities() itemstat itemstats[] = { - 1, 1, 1, S_ITEMAMMO, //knife dummy - 16, 32, 72, S_ITEMAMMO, //pistol - 14, 28, 21, S_ITEMAMMO, //shotgun - 60, 90, 90, S_ITEMAMMO, //subgun - 10, 20, 15, S_ITEMAMMO, //sniper - 40, 60, 60, S_ITEMAMMO, //assault - 2, 0, 2, S_ITEMAMMO, //grenade - 33, 100,100,S_ITEMHEALTH, //health - 50, 100,100,S_ITEMARMOUR, //armour - 16, 0, 72, S_ITEMPUP, //powerup + {1, 1, 1, S_ITEMAMMO}, //knife dummy + {16, 32, 72, S_ITEMAMMO}, //pistol + {14, 28, 21, S_ITEMAMMO}, //shotgun + {60, 90, 90, S_ITEMAMMO}, //subgun + {10, 20, 15, S_ITEMAMMO}, //sniper + {40, 60, 60, S_ITEMAMMO}, //assault + {2, 0, 2, S_ITEMAMMO}, //grenade + {33, 100, 100, S_ITEMHEALTH}, //health + {50, 100, 100, S_ITEMARMOUR}, //armour + {16, 0, 72, S_ITEMPUP}, //powerup }; void baseammo(int gun) { player1->ammo[gun] = itemstats[gun].add*2; }; diff --git a/source/src/main.cpp b/source/src/main.cpp index 238cde51..67ebe2ec 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -30,7 +30,7 @@ void quit() // normal exit void fatal(char *s, char *o) // failure exit { - sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError()); + s_sprintfd(msg)("%s%s (%s)\n", s, o, SDL_GetError()); cleanup(msg); }; @@ -60,7 +60,7 @@ void screenshot() memcpy(dest, (char *)image->pixels+3*scr_w*(scr_h-1-idx), 3*scr_w); endianswap(dest, 3, scr_w); }; - sprintf_sd(buf)("screenshots/screenshot_%d.bmp", lastmillis); + s_sprintfd(buf)("screenshots/screenshot_%d.bmp", lastmillis); SDL_SaveBMP(temp, path(buf)); SDL_FreeSurface(temp); }; @@ -71,13 +71,121 @@ void screenshot() COMMAND(screenshot, ARG_NONE); COMMAND(quit, ARG_NONE); -int minfps, maxfps; +static void bar(float bar, int w, int o, float r, float g, float b) +{ + int side = 50; + glColor3f(r, g, b); + glVertex2f(side, o*FONTH); + glVertex2f(bar*(w*3-2*side)+side, o*FONTH); + glVertex2f(bar*(w*3-2*side)+side, (o+2)*FONTH); + glVertex2f(side, (o+2)*FONTH); +}; + +void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2, const char *text2) // also used during loading +{ + int w = scr_w, h = scr_h; + + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, w*3, h*3, 0, -1, 1); + + glBegin(GL_QUADS); + + if(text1) + { + bar(1, w, 4, 0, 0, 0.8f); + bar(bar1, w, 4, 0, 0.5f, 1); + }; + + if(bar2>0) + { + bar(1, w, 6, 0.5f, 0, 0); + bar(bar2, w, 6, 0.75f, 0, 0); + }; + + glEnd(); + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + + if(text1) draw_text(text1, 70, 4*FONTH + FONTH/2); + if(bar2>0) draw_text(text2, 70, 6*FONTH + FONTH/2); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + glPopMatrix(); + glEnable(GL_DEPTH_TEST); + SDL_GL_SwapBuffers(); +}; + +SDL_Surface *screen = NULL; + +void setfullscreen(bool enable) +{ + if(enable == !(screen->flags&SDL_FULLSCREEN)) + { +#ifdef WIN32 + conoutf("\"fullscreen\" variable not supported on this platform. Use the -t command-line option."); + extern int fullscreen; + fullscreen = !enable; +#else + SDL_WM_ToggleFullScreen(screen); + SDL_WM_GrabInput((screen->flags&SDL_FULLSCREEN) ? SDL_GRAB_ON : SDL_GRAB_OFF); +#endif + }; +} + +void screenres(int *w, int *h, int *bpp = 0) +{ +#ifdef WIN32 + conoutf("\"screenres\" command not supported on this platform. Use the -w and -h command-line options."); +#else + SDL_Surface *surf = SDL_SetVideoMode(*w, *h, bpp ? *bpp : 0, SDL_OPENGL|SDL_RESIZABLE|(screen->flags&SDL_FULLSCREEN)); + if(!surf) return; + scr_w = *w; + scr_h = *h; + screen = surf; + glViewport(0, 0, *w, *h); +#endif +} + +VARF(fullscreen, 0, 0, 1, setfullscreen(fullscreen!=0)); + +COMMAND(screenres, ARG_3INT); + +VAR(maxfps, 5, 200, 500); + +void limitfps(int &millis, int curmillis) +{ + static int fpserror = 0; + int delay = 1000/maxfps - (millis-curmillis); + if(delay < 0) fpserror = 0; + else + { + fpserror += 1000%maxfps; + if(fpserror >= maxfps) + { + ++delay; + fpserror -= maxfps; + }; + if(delay > 0) + { + SDL_Delay(delay); + millis += delay; + }; + }; +}; + +int lowfps, highfps; void fpsrange(int low, int high) { if(low>high || low<1) return; - minfps = low; - maxfps = high; + lowfps = low; + highfps = high; }; COMMAND(fpsrange, ARG_2INT); @@ -142,10 +250,21 @@ int main(int argc, char **argv) log("video: mode"); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if(SDL_SetVideoMode(scr_w, scr_h, 0, SDL_OPENGL|fs)==NULL) fatal("Unable to create OpenGL screen"); + #ifdef WIN32 + #ifdef SDL_RESIZABLE + #undef SDL_RESIZABLE + #endif + #define SDL_RESIZABLE 0 + #endif + screen = SDL_SetVideoMode(scr_w, scr_h, 0, SDL_OPENGL|SDL_RESIZABLE|fs); + if(screen==NULL) fatal("Unable to create OpenGL screen"); + fullscreen = fs!=0; log("video: misc"); SDL_WM_SetCaption("ActionCube", NULL); + #ifndef WIN32 + if(fs) + #endif SDL_WM_GrabInput(SDL_GRAB_ON); keyrepeat(false); SDL_ShowCursor(0); @@ -193,18 +312,30 @@ int main(int argc, char **argv) changemap("maps/ac_complex"); // if this map is changed, also change depthcorrect() log("mainloop"); - int ignore = 5; + int ignore = 5, grabmouse = 0; int lastflush = 0; for(;;) { - int millis = SDL_GetTicks()*gamespeed/100; - if(millis-lastmillis>200) lastmillis = millis-200; - else if(millis-lastmillis<1) lastmillis = millis-1; + static int curmillis = 0, frames = 0; + static float fps = 10.0f; + int millis = SDL_GetTicks(); + limitfps(millis, curmillis); + int elapsed = millis-curmillis; + curtime = elapsed*gamespeed/100; + if(curtime>200) curtime = 200; + else if(curtime<1) curtime = 1; + cleardlights(); - updateworld(millis); + if(lastmillis) updateworld(curtime, lastmillis); + + lastmillis += curtime; + curmillis = millis; + if(!demoplayback) serverslice((int)time(NULL), 0); - static float fps = 30.0f; - fps = (1000.0f/curtime+fps*50)/51; + + frames++; + fps = (1000.0f/elapsed+fps*10)/11; + computeraytable(player1->o.x, player1->o.y); readdepth(scr_w, scr_h); SDL_GL_SwapBuffers(); @@ -215,7 +346,7 @@ int main(int argc, char **argv) gl_drawframe(scr_w, scr_h, 1.0f, fps); player1->yaw -= 5; }; - gl_drawframe(scr_w, scr_h, fpsmaxfps ? fps/maxfps : 1.0f), fps); + gl_drawframe(scr_w, scr_h, fpshighfps ? fps/highfps : 1.0f), fps); //SDL_Delay(100); SDL_Event event; int lasttype = 0, lastbut = 0; @@ -227,13 +358,38 @@ int main(int argc, char **argv) quit(); break; + #ifndef WIN32 + case SDL_VIDEORESIZE: + screenres(&event.resize.w, &event.resize.h); + break; + #endif + case SDL_KEYDOWN: case SDL_KEYUP: keypress(event.key.keysym.sym, event.key.state==SDL_PRESSED, event.key.keysym.unicode); break; + case SDL_ACTIVEEVENT: + if(event.active.state & SDL_APPINPUTFOCUS) + grabmouse = event.active.gain; + else + if(event.active.gain) + grabmouse = 1; + break; + case SDL_MOUSEMOTION: if(ignore) { ignore--; break; }; + if(!(screen->flags&SDL_FULLSCREEN) && grabmouse) + { + #ifdef __APPLE__ + if(event.motion.y == 0) break; //let mac users drag windows via the title bar + #endif + if(event.motion.x == scr_w / 2 && event.motion.y == scr_h / 2) break; + SDL_WarpMouse(scr_w / 2, scr_h / 2); + }; + #ifndef WIN32 + if((screen->flags&SDL_FULLSCREEN) || grabmouse) + #endif mousemove(event.motion.xrel, event.motion.yrel); break; @@ -259,7 +415,7 @@ int main(int argc, char **argv) void loadcrosshair(char *c) { - sprintf_sd(p)("packages/misc/crosshairs/%s", c); + s_sprintfd(p)("packages/misc/crosshairs/%s", c); path(p); int xs, ys; installtex(1, p, xs, ys); diff --git a/source/src/menus.cpp b/source/src/menus.cpp index d82fc3b9..2c16bd76 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -61,7 +61,7 @@ bool rendermenu() if(vmenu==1) refreshservers(); gmenu &m = menus[vmenu]; - sprintf_sd(title)(vmenu>0 && vmenu!=2 ? "[ %s menu ]" : "%s", m.name); // EDIT: AH + s_sprintfd(title)(vmenu>0 && vmenu!=2 ? "[ %s menu ]" : "%s", m.name); // EDIT: AH int mdisp = m.items.length(); int w = 0; loopi(mdisp) @@ -76,7 +76,7 @@ bool rendermenu() int y = (VIRTH-h)/2; int x = (VIRTW-w)/2; blendbox(x-FONTH/2*3, y-FONTH, x+w+FONTH/2*3, y+h+FONTH, true, 6); - draw_text(title, x, y,2); + draw_text(title, x, y); y += FONTH*2; if(vmenu && vmenu!=2) { @@ -85,7 +85,7 @@ bool rendermenu() }; loopj(mdisp) { - draw_text(m.items[j].text, x, y, 2); + draw_text(m.items[j].text, x, y); y += step; }; return true; @@ -129,14 +129,14 @@ void rendermenumdl() }; if(m.rotspeed) glRotatef(lastmillis/5.0f/100.0f*m.rotspeed, 0, 1, 0); - rendermodel(m.mdl, m.frame, m.range, 0.0f, 0.0f, pos.x, pos.z, pos.y, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1.0f), 100, 0, 0, false); + rendermodel(m.mdl, m.frame, m.range, 0, 0.0f, pos.x, pos.z, pos.y, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1.0f), 100, 0, 0, false); if(isplayermodel) { string vwep; - strcpy_s(vwep, "weapons/subgun/world"); + s_strcpy(vwep, "weapons/subgun/world"); path(vwep); - rendermodel(vwep, m.frame, m.range, 0.0f, 0.0f, pos.x, pos.z, pos.y, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1.0f), 100, 0, 0, false); + rendermodel(vwep, m.frame, m.range, 0, 0.0f, pos.x, pos.z, pos.y, 0, 0, false, (float)(m.scale ? m.scale/25.0f : 1.0f), 100, 0, 0, false); }; glPopMatrix(); @@ -192,7 +192,7 @@ void chmenumdl(char *menu, char *mdl, char *frame, char *range, char *rotspeed, gmenu &m = menus[i]; if(strcmp(m.name, menu) == 0) { - if(m.mdl) strcpy_s(m.mdl, mdl); + if(m.mdl) s_strcpy(m.mdl, mdl); else m.mdl = newstring(mdl, _MAXDEFSTR); m.frame = atoi(frame); m.range = atoi(range); diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 051d8031..3056193e 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -84,10 +84,10 @@ bool collide(dynent *d, bool spawn, float drop, float rise) const float fy1 = d->o.y-d->radius; const float fx2 = d->o.x+d->radius; const float fy2 = d->o.y+d->radius; - const int x1 = fast_f2nat(fx1); - const int y1 = fast_f2nat(fy1); - const int x2 = fast_f2nat(fx2); - const int y2 = fast_f2nat(fy2); + const int x1 = int(fx1); + const int y1 = int(fy1); + const int x2 = int(fx2); + const int y2 = int(fy2); float hi = 127, lo = -128; float minfloor = (d->monsterstate && !spawn && d->health>100) ? d->o.z-d->eyeheight-4.5f : -1000.0f; // big monsters are afraid of heights, unless angry :) @@ -397,7 +397,7 @@ void moveplayer(dynent *pl, int moveres, bool local) physent *new_physent() { - physent *p = (physent *)gp()->alloc(sizeof(physent)); + physent *p = new physent; p->yaw = 270; p->pitch = 0; diff --git a/source/src/protos.h b/source/src/protos.h index 7f82078f..fca5e0d7 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -80,7 +80,7 @@ extern void newteam(char *name); // clientgame extern flaginfo flaginfos[2]; extern void mousemove(int dx, int dy); -extern void updateworld(int millis); +extern void updateworld(int curtime, int lastmillis); extern void startmap(char *name); extern void changemap(char *name); extern void initclient(); @@ -140,11 +140,13 @@ extern int isoccluded(float vx, float vy, float cx, float cy, float csize); extern void fatal(char *s, char *o = ""); extern void *alloc(int s); extern void keyrepeat(bool on); +extern void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2 = 0, const char *text2 = NULL); // rendertext -extern void draw_text(char *str, int left, int top, int gl_num); -extern void draw_textf(char *fstr, int left, int top, int gl_num, ...); -extern int text_width(char *str); +extern void draw_text(const char *str, int left, int top); +extern void draw_textf(const char *fstr, int left, int top, ...); +extern int text_width(const char *str, int limit = -1); +extern int text_visible(const char *str, int max); extern void draw_envbox(int t, int fogdist); // editing diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index ee16b4a8..4af8b62a 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -210,7 +210,7 @@ void renderents() // show sparkly thingies for map entities in edit mode if(e>=0) { entity &c = ents[e]; - sprintf_s(closeent)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, getvar("selxs"), getvar("selys")); + s_sprintf(closeent)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, getvar("selxs"), getvar("selys")); }; }; @@ -222,11 +222,11 @@ void loadsky(char *basename) int texnum = 14; loopi(6) { - sprintf_sd(name)("packages/%s_%s.jpg", basename, side[i]); + s_sprintfd(name)("packages/%s_%s.jpg", basename, side[i]); int xs, ys; if(!installtex(texnum+i, path(name), xs, ys, true)) conoutf("could not load sky textures"); }; - strcpy_s(lastsky, basename); + s_strcpy(lastsky, basename); }; COMMAND(loadsky, ARG_1STR); @@ -361,9 +361,9 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat char *command = getcurcommand(); dynent *player = playerincrosshair(); dynent *bot = botincrosshair(); - if(command) draw_textf("> %s_", 20, 1570, 2, command); - else if(closeent[0]) draw_text(closeent, 20, 1570, 2); - else if(player || (bot && (player=bot))) draw_text(player->name, 20, 1570, 2); + if(command) draw_textf("> %s_", 20, 1570, command); + else if(closeent[0]) draw_text(closeent, 20, 1570); + else if(player || (bot && (player=bot))) draw_text(player->name, 20, 1570); renderscores(); if(!rendermenu()) @@ -418,11 +418,11 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glPopMatrix(); glPushMatrix(); glOrtho(0, VIRTW*3/2, VIRTH*3/2, 0, -1, 1); - draw_textf("fps %d", 3200, 2320, 2, curfps); - draw_textf("lod %d", 3200, 2390, 2, lod_factor()); - draw_textf("wqd %d", 3200, 2460, 2, nquads); - draw_textf("wvt %d", 3200, 2530, 2, curvert); - draw_textf("evt %d", 3200, 2600, 2, xtraverts); + draw_textf("fps %d", 3200, 2320, curfps); + draw_textf("lod %d", 3200, 2390, lod_factor()); + draw_textf("wqd %d", 3200, 2460, nquads); + draw_textf("wvt %d", 3200, 2530, curvert); + draw_textf("evt %d", 3200, 2600, xtraverts); }; glPopMatrix(); @@ -431,17 +431,17 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat { glPushMatrix(); glOrtho(0, VIRTW/2, VIRTH/2, 0, -1, 1); - draw_textf("%d", 90, 827, 2, player1->health); - if(player1->armour) draw_textf("%d", 390, 827, 2, player1->armour); - //draw_textf("%d", 690, 827, 2, player1->mag[player1->gunselect]); + draw_textf("%d", 90, 827, player1->health); + if(player1->armour) draw_textf("%d", 390, 827, player1->armour); + //draw_textf("%d", 690, 827, player1->mag[player1->gunselect]); if (player1->gunselect!=GUN_KNIFE) { - //draw_textf("%d", 690, 827, 2, player1->mag[player1->gunselect]); + //draw_textf("%d", 690, 827, player1->mag[player1->gunselect]); char gunstats [64]; if (player1->gunselect!=GUN_GRENADE) sprintf(gunstats,"%i/%i",player1->mag[player1->gunselect],player1->ammo[player1->gunselect]); else sprintf(gunstats,"%i",player1->mag[player1->gunselect]); - draw_text(gunstats, 690, 827, 2); + draw_text(gunstats, 690, 827); //clean up pointer? //delete gunstats; } @@ -600,11 +600,11 @@ void renderphysents() switch(p->state) { case NADE_THROWED: - strcpy_s(model, "weapons/grenade/static"); + s_strcpy(model, "weapons/grenade/static"); break; case GIB: default: - sprintf_s(model)("misc/gib0%i", (((4*(int)p)+p->timetolife)%3)+1); + s_sprintf(model)("misc/gib0%i", (((4*(int)p)+p->timetolife)%3)+1); int t = lastmillis-p->millis; if(t>p->timetolife-2000) { diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 9863c169..f3528601 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -128,7 +128,7 @@ void texture(char *aframe, char *name) if(num<0 || num>=256 || frame<0 || frame>=MAXFRAMES) return; mapping[num][frame] = 1; char *n = mapname[num][frame]; - strcpy_s(n, name); + s_strcpy(n, name); path(n); }; @@ -164,9 +164,9 @@ int lookuptexture(int tex, int &xs, int &ys) if(curtex==MAXTEX) fatal("loaded too many textures"); int tnum = curtex+FIRSTTEX; - strcpy_s(texname[curtex], mapname[tex][frame]); + s_strcpy(texname[curtex], mapname[tex][frame]); - sprintf_sd(name)("packages%ctextures%c%s", PATHDIV, PATHDIV, texname[curtex]); + s_sprintfd(name)("packages%ctextures%c%s", PATHDIV, PATHDIV, texname[curtex]); if(installtex(tnum, name, xs, ys)) { @@ -285,7 +285,7 @@ char *hudgunnames[] = { "knife", "pistol", "shotgun", "subgun", "sniper", "assau void drawhudmodel(int start, int end, float speed, int base) { - sprintf_sd(mdl)("hudguns/%s", hudgunnames[player1->gunselect]); + s_sprintfd(mdl)("hudguns/%s", hudgunnames[player1->gunselect]); rendermodel(mdl, start, end, 0, 1.0f, player1->o.x, player1->o.z, player1->o.y, player1->yaw+90, player1->pitch, false, 1.0f, speed, 0, base); }; diff --git a/source/src/rendermd2.cpp b/source/src/rendermd2.cpp index 47b230c7..196e3741 100644 --- a/source/src/rendermd2.cpp +++ b/source/src/rendermd2.cpp @@ -261,7 +261,7 @@ void md2::render(vec &light, int frame, int range, float x, float y, float z, fl glPopMatrix(); } -hashtable *mdllookup = NULL; +hashtable *mdllookup = NULL; vector mapmodels; const int FIRSTMDL = 40; @@ -269,9 +269,9 @@ void delayedload(md2 *m) { if(!m->loaded) { - sprintf_sd(name1)("packages/models/%s/tris.md2", m->loadname); + s_sprintfd(name1)("packages/models/%s/tris.md2", m->loadname); if(!m->load(path(name1))) fatal("loadmodel: ", name1); - sprintf_sd(name2)("packages/models/%s/skin.jpg", m->loadname); + s_sprintfd(name2)("packages/models/%s/skin.jpg", m->loadname); int xs, ys; installtex(FIRSTMDL+m->mdlnum, path(name2), xs, ys); m->loaded = true; @@ -283,7 +283,7 @@ int modelnum = 0; md2 *loadmodel(char *name) { - if(!mdllookup) mdllookup = new hashtable; + if(!mdllookup) mdllookup = new hashtable; md2 **mm = mdllookup->access(name); if(mm) return *mm; md2 *m = new md2(); @@ -365,4 +365,4 @@ void preload_mapmodels() delayedload(m); lookuptexture(e.attr4 ? lookuptexture(e.attr4, xs, ys) : FIRSTMDL+m->mdlnum, xs, ys); } -} \ No newline at end of file +} diff --git a/source/src/rendermd3.cpp b/source/src/rendermd3.cpp index 9efbf7ef..dc8273bb 100644 --- a/source/src/rendermd3.cpp +++ b/source/src/rendermd3.cpp @@ -108,7 +108,7 @@ md3model::~md3model() if(meshes[i].triangles) delete [] meshes[i].triangles; if(meshes[i].uv) delete [] meshes[i].uv; }; - if(links) free(links); + if(links) delete[] links; if(tags) delete [] tags; }; @@ -153,7 +153,7 @@ bool md3model::load(char *path, bool _mirrored=false) numframes = header.numframes; numtags = header.numtags; - links = (md3model **) malloc(sizeof(md3model) * header.numtags); + links = new md3model *[header.numtags]; loopi(header.numtags) links[i] = NULL; int mesh_offset = ftell(f); @@ -164,7 +164,7 @@ bool md3model::load(char *path, bool _mirrored=false) md3meshheader mheader; fseek(f, mesh_offset, SEEK_SET); fread(&mheader, sizeof(md3meshheader), 1, f); - strn0cpy(mesh.name, mheader.name, 64); + s_strncpy(mesh.name, mheader.name, 64); mesh.triangles = new md3triangle[mheader.numtriangles]; fseek(f, mesh_offset + mheader.ofs_triangles, SEEK_SET); @@ -326,7 +326,7 @@ void md3skin(char *objname, char *skin) // called by the {lower|upper|head}.cfg if(strcmp(mesh->name, objname) == 0) { int xs, ys; - sprintf_sd(path)("%s/%s", basedir, skin); // 'skin' is a relative url + s_sprintfd(path)("%s/%s", basedir, skin); // 'skin' is a relative url bool highqual = strstr(basedir, "weapons") != NULL; installtex(FIRSTMD3 + numskins, path, xs, ys, true, highqual); mesh->tex = numskins; @@ -356,9 +356,9 @@ bool loadweapon(char *name, bool isakimbo=false) sprintf(basedir, "packages/models/weapons/%s", name); md3model *mdl = new md3model(); - sprintf_sd(mdl_path)("%s/tris_high.md3", basedir); - sprintf_sd(cfg_path)("%s/default.skin", basedir); - sprintf_sd(modelcfg_path) ("%s/animations.cfg", basedir); + s_sprintfd(mdl_path)("%s/tris_high.md3", basedir); + s_sprintfd(cfg_path)("%s/default.skin", basedir); + s_sprintfd(modelcfg_path) ("%s/animations.cfg", basedir); if(!mdl->load(mdl_path, isakimbo)) { diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index c93f28d0..556c5d52 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -100,34 +100,48 @@ short char_coords[96][4] = {310,448,363,512}, //~ }; -int text_width(char *str) +int char_width(int c, int x = 0) { - int x = 0; - for (int i = 0; str[i] != 0; i++) + if(c=='\t') x = (x+PIXELTAB)/PIXELTAB*PIXELTAB; + else if(c==' ') x += FONTH/2; + else if(c>=33 && c<=126) { - int c = str[i]; - if(c=='\t') { x = (x+PIXELTAB)/PIXELTAB*PIXELTAB; continue; }; - if(c=='\f') continue; - if(c==' ') { x += FONTH/2; continue; }; c -= 33; - if(c<0 || c>=95) continue; int in_width = char_coords[c][2] - char_coords[c][0]; x += in_width + 1; - } + }; + return x; +}; + +int text_width(const char *str, int limit) +{ + int x = 0; + for(int i = 0; str[i] && (limit<0 || i max) return i; + ++i; + }; + return i; }; -void draw_text(char *str, int left, int top, int gl_num) +void draw_textf(const char *fstr, int left, int top, ...) +{ + s_sprintfdlv(str, top, fstr); + draw_text(str, left, top); +}; + +void draw_text(const char *str, int left, int top) { glBlendFunc(GL_ONE, GL_ONE); - glBindTexture(GL_TEXTURE_2D, gl_num); + glBindTexture(GL_TEXTURE_2D, 2); glColor3ub(255,255,255); int x = left; diff --git a/source/src/savegamedemo.cpp b/source/src/savegamedemo.cpp index 4e1489fc..fd13433a 100644 --- a/source/src/savegamedemo.cpp +++ b/source/src/savegamedemo.cpp @@ -100,7 +100,7 @@ void loadstate(char *fn) void loadgame(char *name) { - sprintf_sd(fn)("savegames/%s.csgz", name); + s_sprintfd(fn)("savegames/%s.csgz", name); loadstate(fn); }; @@ -129,7 +129,7 @@ void loadgamerest() loopi(nplayers) if(!gzget()) { dynent *d = getclient(i); - assert(d); + ASSERT(d); gzread(f, d, sizeof(dynent)); }; @@ -148,7 +148,7 @@ void record(char *name) { int cn = getclientnum(); if(cn<0) return; - sprintf_sd(fn)("demos/%s.cdgz", name); + s_sprintfd(fn)("demos/%s.cdgz", name); savestate(fn); gzputi(cn); conoutf("started recording demo to %s", fn); @@ -188,7 +188,7 @@ void incomingdemodata(uchar *buf, int len, bool extras) void demo(char *name) { - sprintf_sd(fn)("demos/%s.cdgz", name); + s_sprintfd(fn)("demos/%s.cdgz", name); loadstate(fn); demoloading = true; }; @@ -221,7 +221,7 @@ void startdemo() starttime = lastmillis; conoutf("now playing demo"); dynent *d = getclient(democlientnum); - assert(d); + ASSERT(d); *d = *player1; readdemotime(); }; @@ -269,7 +269,7 @@ void demoplaybackstep() localservertoclient(buf, len); // update game state dynent *target = players[democlientnum]; - assert(target); + ASSERT(target); int extras; if(extras = gzget()) // read additional client side state not present in normal network stream diff --git a/source/src/server.cpp b/source/src/server.cpp index d9866985..8f432346 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -216,7 +216,7 @@ void readscfg(char *cfg) configsets.setsize(0); string s; - strcpy_s(s, cfg); + s_strcpy(s, cfg); char *buf = loadfile(path(s), NULL); if(!buf) return; char *p, *l; @@ -231,7 +231,7 @@ void readscfg(char *cfg) { size_t len = lastline ? strlen(l) : p-l; string line; - strn0cpy(line, l, len+1); + s_strncpy(line, l, len+1); char *d = line; int n = 0; while((p = strstr(d, ":")) != NULL && (d = p+1)) n++; @@ -271,7 +271,7 @@ void nextcfgset() // load next maprotation set configset &c = configsets[curcfgset]; mode = c.mode; minremain = c.time; - strcpy_s(smapname, c.mapname); + s_strcpy(smapname, c.mapname); mapend = lastsec+minremain*60; mapreload = false; @@ -291,12 +291,12 @@ bool vote(char *map, int reqmode, int sender) if(configsets.length() && curcfgset < configsets.length() && !configsets[curcfgset].vote && !clients[sender].ismaster) { - sprintf_sd(msg)("%s voted, but voting is currently disabled", clients[sender].name); + s_sprintfd(msg)("%s voted, but voting is currently disabled", clients[sender].name); sendservmsg(msg); return false; }; - strcpy_s(clients[sender].mapvote, map); + s_strcpy(clients[sender].mapvote, map); clients[sender].modevote = reqmode; int yes = 0, no = 0; loopv(clients) if(clients[i].type!=ST_EMPTY) @@ -305,7 +305,7 @@ bool vote(char *map, int reqmode, int sender) else no++; }; if(yes==1 && no==0) return true; // single player - sprintf_sd(msg)("%s suggests %s on map %s (set map to vote)", clients[sender].name, modestr(reqmode), map); + s_sprintfd(msg)("%s suggests %s on map %s (set map to vote)", clients[sender].name, modestr(reqmode), map); sendservmsg(msg); if(yes/(float)(yes+no) <= 0.5f && !clients[sender].ismaster) return false; sendservmsg("vote passed"); @@ -338,10 +338,10 @@ bool addbotvote(int count, char *team, int skill, char *name, int sender) clients[sender].kickbot = false; clients[sender].changebotskill = false; clients[sender].botcount = (count>=0) ? count : 0; - if (team && team[0]) strcpy_s(clients[sender].botteam, team); + if (team && team[0]) s_strcpy(clients[sender].botteam, team); else clients[sender].botteam[0] = 0; clients[sender].botskill = skill; - if (name && name[0]) strcpy_s(clients[sender].botname, name); + if (name && name[0]) s_strcpy(clients[sender].botname, name); else clients[sender].botname[0] = 0; int yes = 0, no = 0; loopv(clients) if(clients[i].type!=ST_EMPTY) @@ -358,7 +358,7 @@ bool addbotvote(int count, char *team, int skill, char *name, int sender) else no++; } if(yes==1 && no==0) return true; // single player - sprintf_sd(msg)("%s suggests to add a bot", clients[sender].name); + s_sprintfd(msg)("%s suggests to add a bot", clients[sender].name); if (team && team[0]) { strcat(msg, " on team "); @@ -392,7 +392,7 @@ bool kickbotvote(int specific, char *name, int sender) clients[sender].kickbot = true; clients[sender].changebotskill = false; clients[sender].kickallbots = !specific; - if (name && name[0]) strcpy_s(clients[sender].botname, name); + if (name && name[0]) s_strcpy(clients[sender].botname, name); else clients[sender].botname[0] = 0; int yes = 0, no = 0; loopv(clients) if(clients[i].type!=ST_EMPTY) @@ -448,7 +448,7 @@ bool botskillvote(int skill, int sender) } if(yes==1 && no==0) return true; // single player - sprintf_sd(msg)("%s suggests to change the skill of all bots to: %s", clients[sender].name, + s_sprintfd(msg)("%s suggests to change the skill of all bots to: %s", clients[sender].name, SkillNrToSkillName(clients[sender].botskill)); sendservmsg(msg); if(yes/(float)(yes+no) <= 0.5f) return false; @@ -668,7 +668,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_INITC2S: CN_CHECK; sgetstr(); - strcpy_s(clients[cn].name, text); + s_strcpy(clients[cn].name, text); sgetstr(); getint(p); getint(p); @@ -686,7 +686,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 minremain = m_ctf_s ? 10 : (m_teammode_s ? 15 : 10); mapend = lastsec+minremain*60; interm = 0; - strcpy_s(smapname, text); + s_strcpy(smapname, text); resetitems(); sender = -1; laststatus = lastsec-61; @@ -758,7 +758,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_ADDBOT: getint(p); sgetstr(); - //strcpy_s(clients[cn].name, text); + //s_strcpy(clients[cn].name, text); sgetstr(); getint(p); break; @@ -975,7 +975,7 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal { f.state=CTFF_INBASE; sendflaginfo(i, -1); - sprintf_sd(msg)("the server reset the %s flag", rb_team_string(i)); + s_sprintfd(msg)("the server reset the %s flag", rb_team_string(i)); sendservmsg(msg); send2(true, -1, SV_SOUND, S_FLAGRETURN); }; @@ -1051,7 +1051,7 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal c.peer->data = (void *)(&c-&clients[0]); c.ismaster = c.isauthed = false; char hn[1024]; - strcpy_s(c.hostname, (enet_address_get_host(&c.peer->address, hn, sizeof(hn))==0) ? hn : "localhost"); + s_strcpy(c.hostname, (enet_address_get_host(&c.peer->address, hn, sizeof(hn))==0) ? hn : "localhost"); printf("client connected (%s)\n", c.hostname); send_welcome(lastconnect = &c-&clients[0]); break; @@ -1091,7 +1091,7 @@ void localconnect() { client &c = addclient(); c.type = ST_LOCAL; - strcpy_s(c.hostname, "local"); + s_strcpy(c.hostname, "local"); send_welcome(&c-&clients[0]); }; diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index 0223e4af..418199fe 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -3,130 +3,188 @@ #include "cube.h" #include "SDL_thread.h" -struct resolverthread +struct resolverthread { SDL_Thread *thread; - char *query; + const char *query; int starttime; -}; - +}; + struct resolverresult { - char *query; + const char *query; ENetAddress address; -}; - +}; + vector resolverthreads; -vector resolverqueries; +vector resolverqueries; vector resolverresults; SDL_mutex *resolvermutex; -SDL_sem *resolversem; -int resolverlimit = 1000; +SDL_cond *querycond, *resultcond; + +#define RESOLVERTHREADS 1 +#define RESOLVERLIMIT 3000 int resolverloop(void * data) -{ +{ resolverthread *rt = (resolverthread *)data; - for(;;) + SDL_LockMutex(resolvermutex); + SDL_Thread *thread = rt->thread; + SDL_UnlockMutex(resolvermutex); + if(!thread || SDL_GetThreadID(thread) != SDL_ThreadID()) + return 0; + while(thread == rt->thread) { - SDL_SemWait(resolversem); SDL_LockMutex(resolvermutex); - if(resolverqueries.empty()) - { - SDL_UnlockMutex(resolvermutex); - continue; - } + while(resolverqueries.empty()) SDL_CondWait(querycond, resolvermutex); rt->query = resolverqueries.pop(); rt->starttime = lastmillis; SDL_UnlockMutex(resolvermutex); + ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT }; enet_address_set_host(&address, rt->query); + SDL_LockMutex(resolvermutex); - resolverresult &rr = resolverresults.add(); - rr.query = rt->query; - rr.address = address; - rt->query = NULL; - rt->starttime = 0; + if(thread == rt->thread) + { + resolverresult &rr = resolverresults.add(); + rr.query = rt->query; + rr.address = address; + rt->query = NULL; + rt->starttime = 0; + SDL_CondSignal(resultcond); + }; SDL_UnlockMutex(resolvermutex); }; return 0; }; -void resolverinit(int threads, int limit) +void resolverinit() { - resolverlimit = limit; - resolversem = SDL_CreateSemaphore(0); resolvermutex = SDL_CreateMutex(); + querycond = SDL_CreateCond(); + resultcond = SDL_CreateCond(); - while(threads > 0) + SDL_LockMutex(resolvermutex); + loopi(RESOLVERTHREADS) { resolverthread &rt = resolverthreads.add(); rt.query = NULL; rt.starttime = 0; rt.thread = SDL_CreateThread(resolverloop, &rt); - --threads; }; + SDL_UnlockMutex(resolvermutex); }; -void resolverstop(resolverthread &rt, bool restart) +void resolverstop(resolverthread &rt) { SDL_LockMutex(resolvermutex); - SDL_KillThread(rt.thread); + if(rt.query) + { +#ifndef __APPLE__ + SDL_KillThread(rt.thread); +#endif + rt.thread = SDL_CreateThread(resolverloop, &rt); + }; rt.query = NULL; rt.starttime = 0; - rt.thread = NULL; - if(restart) rt.thread = SDL_CreateThread(resolverloop, &rt); SDL_UnlockMutex(resolvermutex); -}; +}; void resolverclear() { + if(resolverthreads.empty()) return; + SDL_LockMutex(resolvermutex); resolverqueries.setsize(0); resolverresults.setsize(0); - while (SDL_SemTryWait(resolversem) == 0); loopv(resolverthreads) { resolverthread &rt = resolverthreads[i]; - resolverstop(rt, true); + resolverstop(rt); }; SDL_UnlockMutex(resolvermutex); }; -void resolverquery(char *name) +void resolverquery(const char *name) { + if(resolverthreads.empty()) resolverinit(); + SDL_LockMutex(resolvermutex); resolverqueries.add(name); - SDL_SemPost(resolversem); + SDL_CondSignal(querycond); SDL_UnlockMutex(resolvermutex); }; -bool resolvercheck(char **name, ENetAddress *address) +bool resolvercheck(const char **name, ENetAddress *address) { + bool resolved = false; SDL_LockMutex(resolvermutex); if(!resolverresults.empty()) { resolverresult &rr = resolverresults.pop(); *name = rr.query; - *address = rr.address; - SDL_UnlockMutex(resolvermutex); - return true; + address->host = rr.address.host; + resolved = true; } - loopv(resolverthreads) + else loopv(resolverthreads) { resolverthread &rt = resolverthreads[i]; - if(rt.query) + if(rt.query && lastmillis - rt.starttime > RESOLVERLIMIT) { - if(lastmillis - rt.starttime > resolverlimit) - { - resolverstop(rt, true); - *name = rt.query; - SDL_UnlockMutex(resolvermutex); - return true; - }; - }; + resolverstop(rt); + *name = rt.query; + resolved = true; + }; }; SDL_UnlockMutex(resolvermutex); - return false; + return resolved; +}; + +bool resolverwait(const char *name, ENetAddress *address) +{ + if(resolverthreads.empty()) resolverinit(); + + s_sprintfd(text)("resolving %s... (esc to abort)", name); + show_out_of_renderloop_progress(0, text); + + SDL_LockMutex(resolvermutex); + resolverqueries.add(name); + SDL_CondSignal(querycond); + int starttime = SDL_GetTicks(), timeout = 0; + bool resolved = false; + for(;;) + { + SDL_CondWaitTimeout(resultcond, resolvermutex, 250); + loopv(resolverresults) if(resolverresults[i].query == name) + { + address->host = resolverresults[i].address.host; + resolverresults.remove(i); + resolved = true; + break; + }; + if(resolved) break; + + timeout = SDL_GetTicks() - starttime; + show_out_of_renderloop_progress(min(float(timeout)/RESOLVERLIMIT, 1), text); + SDL_Event event; + while(SDL_PollEvent(&event)) + { + if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) timeout = RESOLVERLIMIT + 1; + }; + + if(timeout > RESOLVERLIMIT) break; + }; + if(!resolved && timeout > RESOLVERLIMIT) + { + loopv(resolverthreads) + { + resolverthread &rt = resolverthreads[i]; + if(rt.query == name) { resolverstop(rt); break; }; + }; + }; + SDL_UnlockMutex(resolvermutex); + return resolved; }; struct serverinfo @@ -149,7 +207,7 @@ void addserver(char *servername) { loopv(servers) if(strcmp(servers[i].name, servername)==0) return; serverinfo &si = servers.insert(0, serverinfo()); - strcpy_s(si.name, servername); + s_strcpy(si.name, servername); si.full[0] = 0; si.mode = 0; si.numplayers = 0; @@ -182,7 +240,7 @@ void pingservers() void checkresolver() { - char *name = NULL; + const char *name = NULL; ENetAddress addr = { ENET_HOST_ANY, CUBE_SERVINFO_PORT }; while(resolvercheck(&name, &addr)) { @@ -225,9 +283,9 @@ void checkpings() si.numplayers = getint(p); si.minremain = getint(p); sgetstr(); - strcpy_s(si.map, text); + s_strcpy(si.map, text); sgetstr(); - strcpy_s(si.sdesc, text); + s_strcpy(si.sdesc, text); break; }; }; @@ -244,19 +302,19 @@ void refreshservers() checkresolver(); checkpings(); if(lastmillis - lastinfo >= 5000) pingservers(); - servers.sort((void *)sicompare); + servers.sort(sicompare); int maxmenu = 16; loopv(servers) { serverinfo &si = servers[i]; if(si.address.host != ENET_HOST_ANY && si.ping != 9999) { - if(si.protocol!=PROTOCOL_VERSION) sprintf_s(si.full)("%s [different cube protocol]", si.name); - else sprintf_s(si.full)("%d\t%d\t%s, %s: %s %s", si.ping, si.numplayers, si.map[0] ? si.map : "[unknown]", modestr(si.mode), si.name, si.sdesc); + if(si.protocol!=PROTOCOL_VERSION) s_sprintf(si.full)("%s [different cube protocol]", si.name); + else s_sprintf(si.full)("%d\t%d\t%s, %s: %s %s", si.ping, si.numplayers, si.map[0] ? si.map : "[unknown]", modestr(si.mode), si.name, si.sdesc); } else { - sprintf_s(si.full)(si.address.host != ENET_HOST_ANY ? "%s [waiting for server response]" : "%s [unknown host]\t", si.name); + s_sprintf(si.full)(si.address.host != ENET_HOST_ANY ? "%s [waiting for server response]" : "%s [unknown host]\t", si.name); } si.full[50] = 0; // cut off too long server descriptions menumanual(1, i, si.full); @@ -269,7 +327,7 @@ void servermenu() if(pingsock == ENET_SOCKET_NULL) { pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL); - resolverinit(1, 1000); + resolverinit(); }; resolverclear(); loopv(servers) resolverquery(servers[i].name); @@ -298,4 +356,4 @@ void writeservercfg() fprintf(f, "// servers connected to are added here automatically\n\n"); loopvrev(servers) fprintf(f, "addserver %s\n", servers[i].name); fclose(f); -}; \ No newline at end of file +}; diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index 9978e6f8..3581a2d6 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -17,7 +17,7 @@ void httpgetsend(ENetAddress &ad, char *hostname, char *req, char *ref, char *ag if(mssock==ENET_SOCKET_NULL) { printf("could not open socket\n"); return; }; if(enet_socket_connect(mssock, &ad)<0) { printf("could not connect\n"); return; }; ENetBuffer buf; - sprintf_sd(httpget)("GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req, hostname, ref, agent); + s_sprintfd(httpget)("GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req, hostname, ref, agent); buf.data = httpget; buf.dataLength = strlen((char *)buf.data); printf("sending request to %s...\n", hostname); @@ -61,7 +61,7 @@ void updatemasterserver(int seconds) { if(seconds>updmaster) // send alive signal to masterserver every hour of uptime { - sprintf_sd(path)("%sregister.do?action=add", masterpath); + s_sprintfd(path)("%sregister.do?action=add", masterpath); httpgetsend(masterserver, masterbase, path, "actioncubeserver", "ActionCube Server"); masterrep[0] = 0; masterb.data = masterrep; @@ -79,7 +79,7 @@ void checkmasterreply() uchar *retrieveservers(uchar *buf, int buflen) { - sprintf_sd(path)("%sretrieve.do?item=list", masterpath); + s_sprintfd(path)("%sretrieve.do?item=list", masterpath); httpgetsend(masterserver, masterbase, path, "actioncubeserver", "ActionCube Server"); ENetBuffer eb; buf[0] = 0; @@ -115,8 +115,8 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int secon putint(p, numplayers); putint(p, minremain); string mname; - strcpy_s(mname, isfull ? "[FULL] " : ""); - strcat_s(mname, smapname); + s_strcpy(mname, isfull ? "[FULL] " : ""); + s_strcat(mname, smapname); sendstring(mname, p); sendstring(serverdesc, p); buf.dataLength = p - pong; @@ -128,9 +128,9 @@ void servermsinit(const char *master, char *sdesc, bool listen) { const char *mid = strstr(master, "/"); if(!mid) mid = master; - strcpy_s(masterpath, mid); - strn0cpy(masterbase, master, mid-master+1); - strcpy_s(serverdesc, sdesc); + s_strcpy(masterpath, mid); + s_strncpy(masterbase, master, mid-master+1); + s_strcpy(serverdesc, sdesc); if(listen) { diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index 35224020..2c1f20c1 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -88,7 +88,7 @@ uchar *copydata = NULL; void sendmaps(int n, string mapname, int mapsize, uchar *mapdata) { if(mapsize <= 0 || mapsize > 256*256) return; - strcpy_s(copyname, mapname); + s_strcpy(copyname, mapname); copysize = mapsize; if(copydata) free(copydata); copydata = (uchar *)alloc(mapsize); diff --git a/source/src/sound.cpp b/source/src/sound.cpp index a28cea78..b3451143 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -94,8 +94,8 @@ void music(char *name) if(soundvol && musicvol) { string sn; - strcpy_s(sn, "packages/audio/songs/"); - strcat_s(sn, name); + s_strcpy(sn, "packages/audio/songs/"); + s_strcat(sn, name); #ifdef USE_MIXER if(mod = Mix_LoadMUS(path(sn))) { @@ -182,7 +182,7 @@ void updatechanvol(int chan, vec *loc) void newsoundloc(int chan, vec *loc) { - assert(chan>=0 && chan=0 && chan +#include "cube.h" //////////////////////////// pool /////////////////////////// -pool::pool() -{ - blocks = 0; - allocnext(POOLSIZE); - for(int i = 0; iMAXREUSESIZE) - { - return malloc(size); - } - else - { - size = bucket(size); - void **r = (void **)reuse[size]; - if(r) - { - reuse[size] = *r; - return (void *)r; - } - else - { - size <<= PTRBITS; - if(leftMAXREUSESIZE) - { - free(p); - } - else - { - size = bucket(size); - if(size) // only needed for 0-size free, are there any? - { - *((void **)p) = reuse[size]; - reuse[size] = p; - }; - }; -}; - -void *pool::realloc(void *p, size_t oldsize, size_t newsize) -{ - void *np = alloc(newsize); - if(!oldsize) return np; - memcpy(np, p, newsize>oldsize ? oldsize : newsize); - dealloc(p, oldsize); - return np; -}; - -void pool::dealloc_block(void *b) -{ - if(b) - { - dealloc_block(*((char **)b)); - free(b); - }; -} - -void pool::allocnext(size_t allocsize) -{ - char *b = (char *)malloc(allocsize+PTRSIZE); - *((char **)b) = blocks; - blocks = b; - p = b+PTRSIZE; - left = allocsize; -}; - -char *pool::string(char *s, size_t l) -{ - char *b = (char *)alloc(l+1); - strncpy(b,s,l); - b[l] = 0; - return b; -}; - -pool *gp() // useful for global buffers that need to be initialisation order independant -{ - static pool *p = NULL; - return p ? p : (p = new pool()); -}; - - ///////////////////////// misc tools /////////////////////// char *path(char *s) @@ -112,13 +18,14 @@ char *loadfile(char *fn, int *size) if(!f) return NULL; fseek(f, 0, SEEK_END); int len = ftell(f); + if(len<=0) { fclose(f); return NULL; }; fseek(f, 0, SEEK_SET); - char *buf = (char *)malloc(len+1); - if(!buf) return NULL; + char *buf = new char[len+1]; + if(!buf) { fclose(f); return NULL; }; buf[len] = 0; size_t rlen = fread(buf, 1, len, f); fclose(f); - if(len!=rlen || len<=0) + if(size_t(len)!=rlen) { free(buf); return NULL; @@ -127,9 +34,9 @@ char *loadfile(char *fn, int *size) return buf; }; -void endianswap(void *memory, int stride, int length) // little indians as storage format +void endianswap(void *memory, int stride, int length) // little endian as storage format { - if(*((char *)&stride)) return; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN loop(w, length) loop(i, stride/2) { uchar *p = (uchar *)memory+w*stride; @@ -137,4 +44,5 @@ void endianswap(void *memory, int stride, int length) // little indians as sto p[i] = p[stride-i-1]; p[stride-i-1] = t; }; +#endif } diff --git a/source/src/tools.h b/source/src/tools.h index ed47d6e7..89c9aa60 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -3,24 +3,6 @@ #ifndef _TOOLS_H #define _TOOLS_H -#ifdef __GNUC__ -#define gamma __gamma -#endif - -#include - -#ifdef __GNUC__ -#undef gamma -#endif - -#include -#include -#include -#include -#include -#include -#include - #ifdef NULL #undef NULL #endif @@ -30,20 +12,55 @@ typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; +#ifdef _DEBUG +#ifdef __GNUC__ +#define ASSERT(c) if(!(c)) { asm("int $3"); }; +#else +#define ASSERT(c) if(!(c)) { __asm int 3 }; +#endif +#else +#define ASSERT(c) if(c) {}; +#endif + +#define swap(t,a,b) { t m=a; a=b; b=m; } +#ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif #define rnd(max) (rand()%(max)) #define rndreset() (srand(1)) #define rndtime() { loopi(lastmillis&0xF) rnd(i+1); } -#define loop(v,m) for(int v = 0; v<(m); v++) + +#define loop(v,m) for(int v = 0; v void _swap(T &a, T &b) { T t = a; a = b; b = t; }; extern char *path(char *s); +extern char *parentdir(char *directory); extern char *loadfile(char *fn, int *size); extern void endianswap(void *, int, int); +extern void seedMT(uint seed); +extern uint randomMT(void); -// memory pool that uses buckets and linear allocation for small objects -// VERY fast, and reasonably good memory reuse - -struct pool -{ - enum { POOLSIZE = 4096 }; // can be absolutely anything - enum { PTRSIZE = sizeof(char *) }; - enum { MAXBUCKETS = 65 }; // meaning up to size 256 on 32bit pointer systems - enum { MAXREUSESIZE = MAXBUCKETS*PTRSIZE-PTRSIZE }; - inline size_t bucket(size_t s) { return (s+PTRSIZE-1)>>PTRBITS; }; - enum { PTRBITS = PTRSIZE==2 ? 1 : PTRSIZE==4 ? 2 : 3 }; - - char *p; - size_t left; - char *blocks; - void *reuse[MAXBUCKETS]; - - pool(); - ~pool() { dealloc_block(blocks); }; - - void *alloc(size_t size); - void dealloc(void *p, size_t size); - void *realloc(void *p, size_t oldsize, size_t newsize); - - char *string(char *s, size_t l); - char *string(char *s) { return string(s, strlen(s)); }; - void deallocstr(char *s) { dealloc(s, strlen(s)+1); }; - char *stringbuf(char *s) { return string(s, _MAXDEFSTR-1); }; - - void dealloc_block(void *b); - void allocnext(size_t allocsize); -}; +#define loopv(v) if(false) {} else for(int i = 0; i<(v).length(); i++) +#define loopvj(v) if(false) {} else for(int j = 0; j<(v).length(); j++) +#define loopvk(v) if(false) {} else for(int k = 0; k<(v).length(); k++) +#define loopvrev(v) if(false) {} else for(int i = (v).length()-1; i>=0; i--) template struct vector { T *buf; int alen; int ulen; - pool *p; vector() { - this->p = gp(); alen = 8; - buf = (T *)p->alloc(alen*sizeof(T)); + buf = (T *)new uchar[alen*sizeof(T)]; ulen = 0; }; - - ~vector() { setsize(0); p->dealloc(buf, alen*sizeof(T)); }; - - vector(vector &v); - void operator=(vector &v); + vector(const vector &v) + { + alen = v.length(); + buf = (T *)new uchar[alen*sizeof(T)]; + ulen = 0; + *this = v; + }; + + ~vector() { setsize(0); delete[] (uchar *)buf; }; + + vector &operator=(const vector &v) + { + setsize(0); + loopv(v) add(v[i]); + return *this; + }; T &add(const T &x) { - if(ulen==alen) realloc(); + if(ulen==alen) vrealloc(); new (&buf[ulen]) T(x); return buf[ulen++]; }; T &add() { - if(ulen==alen) realloc(); + if(ulen==alen) vrealloc(); new (&buf[ulen]) T; return buf[ulen++]; }; + T &dup() + { + if(ulen==alen) vrealloc(); + new (&buf[ulen]) T(buf[ulen-1]); + return buf[ulen++]; + }; + + bool inrange(size_t i) const { return i=0 && i=0 && ii; ulen--) buf[ulen-1].~T(); }; - T *getbuf() { return buf; }; + int length() const { return ulen; }; + T &operator[](int i) { ASSERT(i>=0 && i= 0 && ii) drop(); }; + void setsizenodelete(int i) { ASSERT(i<=ulen); ulen = i; }; + + void deletecontentsp() { while(!empty()) delete pop(); }; + void deletecontentsa() { while(!empty()) delete[] pop(); }; + + T *getbuf() { return buf; }; + const T *getbuf() const { return buf; }; - void realloc() + template + void sort(int (__cdecl *cf)(ST *, ST *), int i = 0, int n = -1) { qsort(&buf[i], n<0?ulen:n, sizeof(T), (int (__cdecl *)(const void *,const void *))cf); }; + + void *_realloc(void *p, int oldsize, int newsize) + { + void *np = new uchar[newsize]; + if(!oldsize) return np; + memcpy(np, p, newsize>oldsize ? oldsize : newsize); + delete[] (char *)p; + return np; + }; + + void vrealloc() { int olen = alen; - buf = (T *)p->realloc(buf, olen*sizeof(T), (alen *= 2)*sizeof(T)); + buf = (T *)_realloc(buf, olen*sizeof(T), (alen *= 2)*sizeof(T)); + }; + + void reserve(size_t i) + { + while(size_t(alen-ulen) < i) vrealloc(); + }; + + void remove(int i, int n) + { + for(int p = i+n; p struct vector return e; }; + int find(const T &o) + { + loopi(ulen) if(buf[i]==o) return i; + return -1; + } + + void removeobj(const T &o) + { + loopi(ulen) if(buf[i]==o) remove(i--); + }; + + void replacewithlast(const T &o) + { + if(!ulen) return; + loopi(ulen-1) if(buf[i]==o) + { + buf[i] = buf[ulen-1]; + }; + ulen--; + }; + T &insert(int i, const T &e) { add(T()); @@ -213,67 +250,210 @@ template struct vector buf[i] = e; return buf[i]; }; + + void reverse() + { + loopi(ulen/2) swap(T, buf[i], buf[ulen-1-i]); + }; }; -#define loopv(v) if(false) {} else for(int i = 0; i<(v).length(); i++) -#define loopvrev(v) if(false) {} else for(int i = (v).length()-1; i>=0; i--) +typedef vector cvector; +typedef vector ivector; +typedef vector usvector; -template struct hashtable +static inline uint hthash(const char *key) { - struct chain { chain *next; char *key; T data; }; + uint h = 5381; + for(int i = 0, k; (k = key[i]); i++) h = ((h<<5)+h)^k; // bernstein k=33 xor + return h; +}; + +static inline bool htcmp(const char *x, const char *y) +{ + return !strcmp(x, y); +}; + +static inline uint hthash(int key) +{ + return key; +}; + +static inline bool htcmp(int x, int y) +{ + return x==y; +}; + +static inline uint hthash(uint key) +{ + return key; +}; + +static inline bool htcmp(uint x, uint y) +{ + return x==y; +}; + +template struct hashtable +{ + typedef K key; + typedef const K const_key; + typedef T value; + typedef const T const_value; + + enum { CHUNKSIZE = 16 }; + + struct chain { T data; K key; chain *next; }; + struct chainchunk { chain chunks[CHUNKSIZE]; chainchunk *next; }; int size; int numelems; chain **table; - pool *parent; chain *enumc; - hashtable() + int chunkremain; + chainchunk *lastchunk; + + hashtable(int size = 1<<10) + : size(size) { - this->size = 1<<10; - this->parent = gp(); numelems = 0; - table = (chain **)parent->alloc(size*sizeof(T)); - for(int i = 0; i &v); - void operator=(hashtable &v); - - T *access(char *key, T *data = NULL) + ~hashtable() { - unsigned int h = 5381; - for(int i = 0, k; k = key[i]; i++) h = ((h<<5)+h)^k; // bernstein k=33 xor - h = h&(size-1); // primes not much of an advantage + DELETEA(table); + }; + + chain *insert(const K &key, uint h) + { + if(!chunkremain) + { + chainchunk *chunk = new chainchunk; + chunk->next = lastchunk; + lastchunk = chunk; + chunkremain = CHUNKSIZE; + } + chain *c = &lastchunk->chunks[--chunkremain]; + c->key = key; + c->next = table[h]; + table[h] = c; + numelems++; + return c; + }; + + chain *find(const K &key, bool doinsert) + { + uint h = hthash(key)&(size-1); for(chain *c = table[h]; c; c = c->next) { - for(char *p1 = key, *p2 = c->key, ch; (ch = *p1++)==*p2++; ) if(!ch) //if(strcmp(key,c->key)==0) - { - T *d = &c->data; - if(data) c->data = *data; - return d; - }; - }; - if(data) - { - chain *c = (chain *)parent->alloc(sizeof(chain)); - c->data = *data; - c->key = key; - c->next = table[h]; - table[h] = c; - numelems++; - }; + if(htcmp(key, c->key)) return c; + } + if(doinsert) return insert(key, h); return NULL; }; + + T *access(const K &key, const T *data = NULL) + { + chain *c = find(key, data != NULL); + if(data) c->data = *data; + if(c) return &c->data; + return NULL; + }; + + T &operator[](const K &key) + { + return find(key, true)->data; + }; + + void clear() + { + loopi(size) + { + /* + for(chain *c = table[i], *next; c; c = next) + { + next = c->next; + delete c; + };*/ + table[i] = NULL; + }; + numelems = 0; + chunkremain = 0; + for(chainchunk *chunk; lastchunk; lastchunk = chunk) + { + chunk = lastchunk->next; + delete lastchunk; + } + }; }; +#define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(hashtable::chain *enumc = (ht).table[i]; enumc; enumc = enumc->next) { hashtable::const_key &e = enumc->key; t &f = enumc->data; b; } +#define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc; (ht).enumc = (ht).enumc->next) { t &e = (ht).enumc->data; b; } -#define enumerate(ht,t,e,b) loopi(ht->size) for(ht->enumc = ht->table[i]; ht->enumc; ht->enumc = ht->enumc->next) { t e = &ht->enumc->data; b; } +inline char *newstring(size_t l) { return new char[l+1]; }; +inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); }; +inline char *newstring(const char *s) { return newstring(s, strlen(s)); }; +inline char *newstringbuf(const char *s) { return newstring(s, _MAXDEFSTR-1); }; + +template +struct databuf +{ + enum + { + OVERREAD = 1<<0, + OVERWROTE = 1<<1 + }; + + T *buf; + int len, maxlen; + uchar flags; + + databuf(T *buf, int maxlen) : buf(buf), len(0), maxlen(maxlen), flags(0) {}; + + const T &get() + { + static T overreadval; + if(len charbuf; +typedef databuf ucharbuf; + +#ifndef __GNUC__ +#ifdef _DEBUG +//#define _CRTDBG_MAP_ALLOC +#include +inline void *__cdecl operator new(size_t n, const char *fn, int l) { return ::operator new(n, 1, fn, l); }; +inline void __cdecl operator delete(void *p, const char *fn, int l) { ::operator delete(p, 1, fn, l); }; +#define new new(__FILE__,__LINE__) +#endif +#endif -pool *gp(); -inline char *newstring(char *s) { return gp()->string(s); }; -inline char *newstring(char *s, size_t l) { return gp()->string(s, l); }; -inline char *newstringbuf(char *s) { return gp()->stringbuf(s); }; #endif diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 495a2f65..f9365a3c 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -168,6 +168,7 @@ void createrays(vec &from, vec &to) // create random spread of rays vec r = { RNDD, RNDD, RNDD }; sg[i] = to; vadd(sg[i], r); + #undef RNDD }; }; @@ -576,7 +577,7 @@ void spreadandrecoil(vec &from, vec &to, dynent *d) int spd = guns[d->gunselect].spread; //recoil - int rcl = guns[d->gunselect].recoil*-0.01f; + float rcl = guns[d->gunselect].recoil*-0.01f; if(d->gunselect==GUN_ASSAULT) { @@ -596,6 +597,7 @@ void spreadandrecoil(vec &from, vec &to, dynent *d) #define RNDD (rnd(spd)-spd/2)*f vec r = { RNDD, RNDD, RNDD }; vadd(to, r); + #undef RNDD }; //increase pitch for recoil diff --git a/source/src/world.cpp b/source/src/world.cpp index 8c9de858..ebb4106d 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -53,7 +53,7 @@ void trigger(int tag, int type, bool savegame) if(!tag) return; settag(tag, type); if(!savegame && type!=3) playsound(S_RUMBLE); - sprintf_sd(aliasname)("level_trigger_%d", tag); + s_sprintfd(aliasname)("level_trigger_%d", tag); if(identexists(aliasname)) execute(aliasname); }; @@ -169,7 +169,7 @@ void remipmore(block &b, int level) int closestent() // used for delent and edit mode ent display { if(noteditmode()) return -1; - int best; + int best = -1; float bdist = 99999; loopv(ents) { @@ -358,7 +358,7 @@ void empty_world(int factor, bool force) // main empty world creation routine } else { - strn0cpy(hdr.maptitle, "Untitled Map by Unknown", 128); + s_strncpy(hdr.maptitle, "Untitled Map by Unknown", 128); hdr.waterlevel = -100000; loopi(15) hdr.reserved[i] = 0; loopk(3) loopi(256) hdr.texlists[k][i] = i; diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index bde7df35..dbe0f99f 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -16,18 +16,18 @@ void setnames(char *name) char *slash = strpbrk(name, "/\\"); if(slash) { - strn0cpy(pakname, name, slash-name+1); - strcpy_s(mapname, slash+1); + s_strncpy(pakname, name, slash-name+1); + s_strcpy(mapname, slash+1); } else { - strcpy_s(pakname, "maps"); - strcpy_s(mapname, name); + s_strcpy(pakname, "maps"); + s_strcpy(mapname, name); }; - sprintf_s(cgzname)("packages/%s/%s.cgz", pakname, mapname); - sprintf_s(bakname)("packages/%s/%s_%d.BAK", pakname, mapname, lastmillis); - sprintf_s(pcfname)("packages/%s/package.cfg", pakname); - sprintf_s(mcfname)("packages/%s/%s.cfg", pakname, mapname); + s_sprintf(cgzname)("packages/%s/%s.cgz", pakname, mapname); + s_sprintf(bakname)("packages/%s/%s_%d.BAK", pakname, mapname, lastmillis); + s_sprintf(pcfname)("packages/%s/package.cfg", pakname); + s_sprintf(mcfname)("packages/%s/%s.cfg", pakname, mapname); path(cgzname); path(bakname); @@ -327,7 +327,7 @@ void load_world(char *mname) // still supports all map formats that have { if(type<0 || type>=MAXTYPE) { - sprintf_sd(t)("%d @ %d", type, k); + s_sprintfd(t)("%d @ %d", type, k); fatal("while reading map: type out of range: ", t); }; s->type = type; @@ -358,7 +358,7 @@ void load_world(char *mname) // still supports all map formats that have startmap(mname); loopl(256) { - sprintf_sd(aliasname)("level_trigger_%d", l); // can this be done smarter? + s_sprintfd(aliasname)("level_trigger_%d", l); // can this be done smarter? if(identexists(aliasname)) alias(aliasname, ""); }; execfile("config/default_map_settings.cfg"); diff --git a/source/src/worldlight.cpp b/source/src/worldlight.cpp index 60bf1d71..026fc9a7 100644 --- a/source/src/worldlight.cpp +++ b/source/src/worldlight.cpp @@ -23,7 +23,7 @@ void lightray(float bx, float by, persistent_entity &light) // done in realt int l = light.attr2<>PRECBITS, y>>PRECBITS)) return; int g = light.attr3<syaw-PI2) || (anglesyaw+PI2)) && !OUTBORD(vx, vy) - && !SOLID(S(fast_f2nat(vx), fast_f2nat(vy)))) // try to avoid tracing ray if outside of frustrum + && !SOLID(S(int(vx), int(vy)))) // try to avoid tracing ray if outside of frustrum { float ray = i*8/(float)NUMRAYS; float dx, dy; @@ -48,7 +48,7 @@ void computeraytable(float vx, float vy) { sx += dx; sy += dy; - if(SOLID(S(fast_f2nat(sx), fast_f2nat(sy)))) // 90% of time spend in this function is on this line + if(SOLID(S(int(sx), int(sy)))) // 90% of time spend in this function is on this line { rdist[i] = (float)(fabs(sx-vx)+fabs(sy-vy)); break; @@ -122,8 +122,8 @@ int isoccluded(float vx, float vy, float cx, float cy, float csize) // v = v } else { h = ca(cx+csize-vx, cy-vy); l = ca(cx-vx, cy+csize-vy); }; // H }; - int si = fast_f2nat(h*(NUMRAYS/8))+NUMRAYS; // get indexes into occlusion map from angles - int ei = fast_f2nat(l*(NUMRAYS/8))+NUMRAYS+1; + int si = int(h*(NUMRAYS/8))+NUMRAYS; // get indexes into occlusion map from angles + int ei = int(l*(NUMRAYS/8))+NUMRAYS+1; if(ei<=si) ei += NUMRAYS; for(int i = si; i<=ei; i++)