/* Relay -- a tool to record and play Quake2 demos Copyright (C) 2000 Conor Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Conor Davis cedavis@planetquake.com */ #include #include "r_local.h" void import_bprintf(int printlevel, char *fmt, ...) { char string[MAX_MSGLEN]; va_list argptr; va_start(argptr, fmt); vsprintf(string, fmt, argptr); va_end(argptr); gi.bprintf(printlevel, "%s", string); WriteByte(&reliable, SVC_PRINT); DM2_WritePrint(&reliable, printlevel, string); } void import_cprintf(edict_t *ent, int printlevel, char *fmt, ...) { char string[MAX_MSGLEN]; va_list argptr; va_start(argptr, fmt); vsprintf(string, fmt, argptr); va_end(argptr); gi.cprintf(ent, printlevel, "%s", string); // NULL ent means console only if (ent) { WriteByte(&reliable, SVC_PRINT | MSG_UNICAST); WriteByte(&reliable, (byte)(EDICT2NUM(ent) - 1)); DM2_WritePrint(&reliable, printlevel, string); } } void import_centerprintf(edict_t *ent, char *fmt, ...) { char string[MAX_MSGLEN]; va_list argptr; va_start(argptr, fmt); vsprintf(string, fmt, argptr); va_end(argptr); gi.centerprintf(ent, "%s", string); WriteByte(&reliable, SVC_CENTERPRINT | MSG_UNICAST); WriteByte(&reliable, (byte)(EDICT2NUM(ent) - 1)); DM2_WriteCenterprint(&reliable, string); } void import_sound(edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs) { gi.sound(ent, channel, soundindex, volume, attenuation, timeofs); WriteByte(&unreliable, SVC_SOUND); DM2_WriteSound(&unreliable, soundindex, volume, attenuation, timeofs, EDICT2NUM(ent), channel, NULL, false); } void import_positioned_sound(vec3_t origin, edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs) { gi.sound(ent, channel, soundindex, volume, attenuation, timeofs); WriteByte(&unreliable, SVC_SOUND); DM2_WriteSound(&unreliable, soundindex, volume, attenuation, timeofs, EDICT2NUM(ent), channel, origin, true); } void import_configstring(int num, char *string) { gi.configstring(num, string); if (string) strcpy(dm2out.configstrings[num], string); else dm2out.configstrings[num][0] = 0; if (dm2out.current_frame != 0) { WriteByte(&reliable, SVC_CONFIGSTRING); DM2_WriteConfigstring(&reliable, num, string); } } int import_modelindex(char *name) { int index; index = gi.modelindex(name); if (index && !dm2out.configstrings[CS_MODELS+index][0]) { strcpy(dm2out.configstrings[CS_MODELS+index], name); if (dm2out.current_frame != 0) { WriteByte(&reliable, SVC_CONFIGSTRING); DM2_WriteConfigstring(&reliable, CS_MODELS+index, name); } } return index; } int import_soundindex(char *name) { int index; index = gi.soundindex(name); if (index && !dm2out.configstrings[CS_SOUNDS+index][0]) { strcpy(dm2out.configstrings[CS_SOUNDS+index], name); if (dm2out.current_frame != 0) { WriteByte(&reliable, SVC_CONFIGSTRING); DM2_WriteConfigstring(&reliable, CS_SOUNDS+index, name); } } return index; } int import_imageindex(char *name) { int index; index = gi.imageindex(name); if (index && !dm2out.configstrings[CS_IMAGES+index][0]) { strcpy(dm2out.configstrings[CS_IMAGES+index], name); if (dm2out.current_frame != 0) { WriteByte(&reliable, SVC_CONFIGSTRING); DM2_WriteConfigstring(&reliable, CS_IMAGES+index, name); } } return index; } void import_setmodel(edict_t *ent, char *name) { gi.setmodel(ent, name); if (ent->s.modelindex && !dm2out.configstrings[CS_MODELS+ent->s.modelindex][0]) { strcpy(dm2out.configstrings[CS_MODELS+ent->s.modelindex], name); if (dm2out.current_frame != 0) { WriteByte(&reliable, SVC_CONFIGSTRING); DM2_WriteConfigstring(&reliable, CS_MODELS+ent->s.modelindex, name); } } } void import_SetAreaPortalState(int portalnum, qboolean connected) { gi.SetAreaPortalState(portalnum, connected); SETBIT(areaportals, portalnum, connected); } void import_linkentity(edict_t *ent) { gi.linkentity(ent); } void import_unlinkentity(edict_t *ent) { gi.unlinkentity(ent); } void import_multicast(vec3_t origin, multicast_t to) { gi.multicast(origin, to); BlockWrite(&unreliable, tempblock.buffer, tempblock.writeoffset); BlockRewind(&tempblock); } void import_unicast(edict_t *ent, qboolean isreliable) { gi.unicast(ent, isreliable); if (isreliable) { WriteByte(&reliable, (byte)(tempblock.buffer[0] | MSG_UNICAST)); WriteByte(&reliable, (byte)(EDICT2NUM(ent) - 1)); BlockWrite(&reliable, tempblock.buffer+1, tempblock.writeoffset-1); } else { WriteByte(&unreliable, (byte)(tempblock.buffer[0] | MSG_UNICAST)); WriteByte(&unreliable, (byte)(EDICT2NUM(ent) - 1)); BlockWrite(&unreliable, tempblock.buffer+1, tempblock.writeoffset-1); } BlockRewind(&tempblock); } void import_WriteChar(int c) { gi.WriteChar(c); WriteChar(&tempblock, (char)c); } void import_WriteByte(int c) { gi.WriteByte(c); WriteByte(&tempblock, (byte)c); } void import_WriteShort(int c) { gi.WriteShort(c); WriteShort(&tempblock, (short)c); } void import_WriteLong(int c) { gi.WriteLong(c); WriteLong(&tempblock, (long)c); } void import_WriteFloat(float f) { gi.WriteFloat(f); } void import_WriteString(char *s) { gi.WriteString(s); if (s) WriteString(&tempblock, s); else WriteString(&tempblock, ""); } void import_WritePosition(vec3_t pos) { gi.WritePosition(pos); if (pos) WritePosition(&tempblock, pos); else WritePosition(&tempblock, vec3_origin); } void import_WriteDir(vec3_t pos) { gi.WriteDir(pos); if (pos) WriteDir(&tempblock, pos); else WriteDir(&tempblock, vec3_origin); } void import_WriteAngle(float f) { gi.WriteAngle(f); WriteAngle(&tempblock, f); }