Forum

Tutorial: sv_progs: specify the "progs.dat" to run

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Tutorial: sv_progs: specify the "progs.dat" to run

Postby Baker » Wed Nov 26, 2008 4:31 pm

You've got a mod ...

And it supports single player and maybe a bots version and if you are particularly creative maybe a 3rd version that supports who knows.

Do you want to distribute awkward zip files with 3 gamedirs ... because standard Quake would require 3 different progs.dat in 3 different gamedirs?

Adding sv_progs capability to GLQuake/WinQuake

DarkPlaces has had this for over 4 years, no doubt some others.

1. sv_main.c

a. Right after "server_static_t svs;" at the top, add:

Code: Select all
cvar_t  sv_progs = {"sv_progs", "progs.dat" };


We need to define the new cvar.

b. Right after "Cvar_RegisterVariable (&sv_maxspeed);", add:

Code: Select all
Cvar_RegisterVariable (&sv_progs);


This registers it.

c. Find this and add the yellow

// load progs to get entity field count
PR_LoadProgs (sv_progs.string);


We aren't just calling PR_LoadProgs anymore, but telling it what the "progs.dat" name is.


2. progs.h

Find this and insert the yellow text replacing the word "void":

void PR_LoadProgs (char *progsname);


3. pr_edict.c

Goto PR_LoadProgs and make yellow changes:


void PR_LoadProgs (char *progsname)
{
int i;

// flush the non-C variable lookup cache
for (i=0 ; i<GEFV_CACHESIZE ; i++)
gefvCache[i].field[0] = 0;

if (!progsname || !*progsname)
Host_Error("PR_LoadProgs: passed empty progsname");


CRC_Init (&pr_crc);

if (!(progs = (dprograms_t *)COM_LoadHunkFile (progsname)))
Sys_Error ("PR_LoadProgs: couldn't load %s", progsname);

Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);

for (i=0 ; i<com_filesize ; i++)
CRC_ProcessByte (&pr_crc, ((byte *)progs)[i]);

// byte swap the header
for (i=0 ; i<sizeof(*progs)/4 ; i++)
((int *)progs)[i] = LittleLong ( ((int *)progs)[i] );

if (progs->version != PROG_VERSION)
Sys_Error ("%s has wrong version number (%i should be %i)", progsname, progs->version, PROG_VERSION);

if (progs->crc != PROGHEADER_CRC)
Sys_Error ("%s system vars have been modified, progdefs.h is out of date", progsname);

pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions);


All we did was replace the instances of "progs.dat" with "%s" and sprintf the progsname in there.

Plus an empty progsname check.


In Closing

Now you could create a readme.txt with

=============
My Readme.txt
=============
glquake -game mycastle +map mycastle
...
( description of mod )
...

We also included a bots version and a dmsp version. Just type "bots" or "dmsp" in the console to run those.

Requires DarkPlaces or <insert name here>


[Those bots/dmsp aliases would be in the autoexec.cfg, i.e. alias bots "sv_progs bots.dat; disconnect; maxplayers 4; map dm6", etc.]
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby goldenboy » Fri Nov 28, 2008 7:30 pm

good, is it also possible to have a command line switch?
User avatar
goldenboy
 
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel

Postby Spirit » Fri Nov 28, 2008 8:52 pm

AS usual +sv_progs should work?
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
Spirit
 
Posts: 1031
Joined: Sat Nov 20, 2004 9:00 pm

Postby Baker » Fri Nov 28, 2008 9:45 pm

Spirit wrote:AS usual +sv_progs should work?


That'd work, yes.

c:\quake\<your quake>.exe -game whatever +sv_progs bots.dat
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Team Xlink » Fri Nov 20, 2009 12:54 am

Is it possible to change it through the quake.cmdline file?
Last edited by Team Xlink on Fri Nov 20, 2009 1:05 am, edited 1 time in total.
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby Downsider » Fri Nov 20, 2009 1:03 am

If you read the code, you would know the answer is yes.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby Baker » Thu Jun 14, 2012 4:39 am

After a lot of consideration, I think sv_progs is a *bad* idea.

A save game saves to a gamedir. A save game does not know what progs created it.

We currently have a circumstance where aside from DarkPlaces, an engine can't save or load a multiplayer game. So the argument can be made that sv_progs is useful for multiplayer (you could have DM, CTF, CA, Rocket Arena, etc. all as different progs.dat in the same dir).

However, the fact that multiplayer games cannot be saved currently by very many engines is shortsighted. And may not persist as mainstream for any future length of time that will be relevant.

The proper way to re-use content would probably be:
1) Multiple gamedir support where the first gamedir represents the mod and the second gamedir represents the progs.
2) sv_progs if such were stored in a save game file. However, someone would have to devise a backwards compatible save game.
3) This is ignoring the fact that demos don't even know what gamedir or mod they are. Well --- maybe Quakeworld demos do?
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby mh » Thu Jun 14, 2012 8:54 am

Not too certain what the purpose of saving a multiplayer game is - there is just so much that can go wrong on reload that it seems quite a hairy process.

That aside, my humble proposal: instead of a user-settable progs (which may still be retained as an option for modders to switch between progs while testing and without needing to restart the engine - maybe only allow it if developer 1) try for <mapname>.dat, if you don't get that fall back on progs.dat. That seems to make all of the problems go away - the save game knows what map it used, so by default it also knows the correct progs to use, and likewise for demos.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby mankrip » Thu Jun 14, 2012 4:34 pm

Thanks, Baker. I've implemented this, but with some adjustments to print a console warning and make the engine load the default progs.dat if the specified sv_progs isn't found.
Of course, if progs.dat is also missing, the engine will Sys_Error, but using the sv_progs name in the message.
mh wrote:try for <mapname>.dat, if you don't get that fall back on progs.dat. That seems to make all of the problems go away - the save game knows what map it used, so by default it also knows the correct progs to use, and likewise for demos.

Good idea, but would get messy on map packs, because using the same custom progs on multiple maps would require an individual copy of it for each map. Also, it wouldn't allow for the same map to use different progs for different game modes. Let's say, the mod author could want to make a progs for single player, a progs for multiplayer, a progs for a in-game "start screen" menu (like the one in TAoV), a progs for machinimas, and even stuff like different progs for different difficulty settings.

Saving the current progs name in the saves seems to be a good idea.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby Spike » Thu Jun 14, 2012 4:49 pm

multiplayer saving is nice for coop (especially hexen2 with levels and stuff).
fte loads multiplayer games just fine (after I last fixed the thing). it matches players by names, and has to reorder player slots to match the mod to ensure nothing is broken. it is quite hairy (hence why it was broken), so really its only worth it if you support hexen2, but it is possible.
its pointless for deathmatch.

there's a lot of cvars that are easily broken by cvars when saving the game. all those for-the-gamecode cvars will all break over the course of save+quit+newgame+reload.
'sv_progs' really isn't special in that regard. imho my opinion is that the only real issue is that you refuse to change the saved game format. the question is which other cvars do you save?
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby r00k » Fri Jun 15, 2012 3:05 am

I would thinK loading a saved multiplayer game would help dev teams bug test
Another task would be to load a demo and run through the measures to test for cheaters
But that would be more in depth...

Typed this only iPhone sorry forteh typoz
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby Baker » Fri Jun 15, 2012 4:43 am

mankrip wrote:Thanks, Baker. I've implemented this, but with some adjustments to print a console warning and make the engine load the default progs.dat if the specified sv_progs isn't found.


Baker: I've changed my mind this bad.
MK: Thanks, Baker! I put this in my engine!

I like it :D :D

mh wrote:Not too certain what the purpose of saving a multiplayer game is - there is just so much that can go wrong on reload that it seems quite a hairy process.


Some players would kill for this feature. For example: Trying to coop Travail isn't a 30 minute ordeal. Even on LAN, it isn't gonna happen. Multiplayer it could open the door to "scenarios" or the ability to restore a recently disconnected player without foobaring the game and their stats.

Now I'm not pretending this would be easy. It would be extremely hard.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby Spike » Fri Jun 15, 2012 9:16 pm

ktpro restores disconnected players. pauses the game and everything. though it is still subject to a timeout (clones the player in clientdisconnect and restores them again if they reconnect. the pausing part is a nasty painful hack though, as the server isn't technically paused).
that doesn't require saved games of course.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: Tutorial: sv_progs: specify the "progs.dat" to run

Postby Baker » Sun Jun 17, 2012 8:07 pm

Spike wrote:ktpro restores disconnected players. pauses the game and everything. though it is still subject to a timeout (clones the player in clientdisconnect and restores them again if they reconnect. the pausing part is a nasty painful hack though, as the server isn't technically paused).
that doesn't require saved games of course.


Interesting.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest