CSQC - display an image

Discuss programming in the QuakeC language.
Post Reply
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

CSQC - display an image

Post by ajay »

Hello!
I'm at an early dipping-my-toe-in-the-water stage of CSQC awareness. I'm really haven't covered the basics of it at yet, but I am reading whatever I can find. Anyway, what I'm planning to achieve:
- At various points in the mod, and event, trigger etc., would cause an image to be displayed to the screen (while the game is functionally paused) the aim of which is to provide either pictorial or written information to the player; it's not a menu, and would need to be cleared and the game restarted after the player clicks mouse button 1 for example
- The image would clearly need to be different each time and be of a reasonably high res >= 800x600

That's it really, I'm reasonably sure that's all doable, my problem is the details of the how! Anyway, are there any code examples that I could read to get a handle on CSQC generally, and this kind of thing specifically?

Although I'm reading http://www.fteqw.com/wiki/index.php?title=EXT_CSQC code examples bring things to life a bit for me.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: CSQC - display an image

Post by Spike »

quake/$modname/cssrc/progs.src :

Code: Select all

#pragma TARGET "../csprogs.dat" //csqc is built into csprogs.dat and not (qw)progs.dat
#define CSQC //for the following line
#include "fteextensions.qc" //include the various system fields, globals, constants, and builtins.

void(float width, float height, float menushown) CSQC_UpdateView =
{
//draw the 3d view as the engine normally would. well, mostly. it's over the fullscreen anyway.
	clearscene();//reset the various view properties/flags to their defaults and clear the mesh/entity/etc lists.
	setviewprop(VF_MIN, '0 0 0');
	setviewprop(VF_SIZE, [width, height, 0]);
	setviewprop(VF_DRAWENGINESBAR, 1);//include the engine's statusbar/hud/whatever. beware the viewsize cvar.
	setviewprop(VF_DRAWCROSSHAIR, 1);//include the crosshair. for the luls... or rather the accuracy. whatever
	addentities((intermission?0:MASK_VIEWMODEL)|MASK_ENGINE);//add the various entities to the scene lists. skip the regular view model while in intermission.
	renderscene();//render the view and all entities contained within it, yay

//draw a 2d image in the middle of the screen over the top of the 3d view with a 1/4th screen border. just to be annoying.
//this will scale the image accordingly. beware of aspect ratios
	drawpic([width, height,0]*0.25, "gfx/someimage.lmp", [width, height,0]*0.5, '1 1 1', 1, 0);
//check the other various draw* functions for other 2d operations.
};

float(float evtype, float scanx, float chary, float devid) CSQC_InputEvent =
{
	if (evtype == IE_KEYDOWN && scanx == K_MOUSE1 && getstatf(STAT_HEALTH) == 100)
	{
		localcmd("cmd say Hey, I just pressed mouse1 while with full health\n");
		return TRUE;  //return true to cancel/inhibit the input event. this prevents the engine from doing its normal binds, etc
	}
//you can check the other input event types, like IE_MOUSEDELTA to provide a mouse cursor, return true to stop the engine from changing view angles (don't forget to draw your own mouse cursor too).
	else
		return FALSE;//not recognised, let the engine do its thing.
};
then download http://triptohell.info/moodles/fteqcc/fteextensions.qc and compile the above file.

at some point, you'll likely want to change VF_DRAWENGINESBAR to 0 and implement entirely your own hud. use getstatf to read float stats (ie: all but STAT_ITEMS, which is unique in that it requires getstatbits to distinguish between items and runes, due to legacy weirdness with packing and runes).
combine with KRIMZON_SV_PARSECLIENTCOMMAND and you can see the results of localcmd("cmd your message here\n")

to create custom stats, into your ssqc's worldspawn function, put the following call to clientstat (as documented in fteextensions.qc):
#define STAT_MYSTAT 32
.float mystat;
clientstat(STAT_MYSTAT, EV_FLOAT, mystat);
you can then call getstatf(STAT_MYSTAT) to get the current value in your csqc code. Be aware of round-trip times (even in single player).

messing with entities and things from csqc too is an exercise for another day.
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Re: CSQC - display an image

Post by ajay »

Thanks spike
Just covering some basics also and to save mysefl some time:
* for CSQC, are there any qc files you have to have, or is it only those custom ones you want?
* do you need a progs.src?
* I'm using fteqcc, to compile CSQC files, do I just run as normal and it will compile them separately into csprogs.dat when compiling ordinary qc progs.dat?
Cheers
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: CSQC - display an image

Post by Spike »

There are no specific .qc files you must have (in fact, if your .src file starts with a preprocessor directive, you don't need any .qc files at all, though that's impractical when its large, but hey, #include to the rescue).
That said, you will need some equivelent of defs.qc to get the system defs+fields right, and so the compiler knows what the builtins are and their names and arguments and stuff.
The file I linked serves this purpose, and contains no actual logic itself, just defs.
DP specific:
DP requires that the following four functions are defined. I don't really know why. Any dp-specific csqc def listings will thus define them as not var etc, and the compiler will complain about them not being defined.
CSQC_Init
CSQC_InputEvent
CSQC_UpdateView
CSQC_ConsoleCommand
The file I linked should have correct definitions for these and will not result in errors if they are omitted as fte has no issues with them missing (although skipping CSQC_UpdateView would defeat the point of most csqc mods).
InputEvent and ConsoleCommand can be implemented as stubs by just returning false. Init can simply contain nothing. UpdateView requires something like the code I already wrote in my previous post, just without the drawpic call obscuring the screen.

To compile both a csprogs.dat and a progs.dat, you need to run the compiler twice, with two separate foo.src files. As far as the qcc is concerned, there's no difference between the two (any warnings about crcs are purely cosmetic, and are in an attempt to warn about people who acidentilly changed the top of defs.qc or whatever).
menu.src is a third form of src file that you might have.

With FTEQCC, you can put '#pragma sourcefile csprogs.src' in your ssqc's defs.qc file or somewhere if you want. this will get fteqcc to attempt to compile from csprogs.src after it has finished compiling from progs.src (automatically restarting compiling with an alternative source file).
Personally I tend to have all the src files as $mod/src/*.src with the common qc files in the same dir, and the module-specific qc files in an appropriate subdir (fte's built-in qcc can then be used via 'compile csprogs.src', woo). If you're invoking qcc via double-clicking it, having files NOT called exactly progs.src can be annoying, separate subdirectories can help with that, or you can just use that pragma.
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Re: CSQC - display an image

Post by ajay »

Thanks spike, much appreciated
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: CSQC - display an image

Post by ceriux »

also these are all the sites iv been reading over when looking for information for csqc.

http://quakewiki.org/wiki/EXT_CSQC

http://www.quakewiki.net/darkplaces-wik ... de-quakec/

http://www.inside3d.com/showtutorial.php?id=245

http://quakeone.com/forums/quake-mod-re ... ars-3.html

http://quakeone.com/forums/quake-mod-re ... -csqc.html

a lot of these the csqc is a little off, but easily fixable. just look at your original defs.qc. some are just open source csqc mods. but all kinds of information and knowlege is available.
goldenboy
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel
Contact:

Re: CSQC - display an image

Post by goldenboy »

https://gitorious.org/salvatrix/salvatr ... sqc_gui.qc

here's my current hud csqc. Pops up a GUI image when TAB is pressed, and tracks mouse cursor movements drawing a cursor image too.

http://www.youtube.com/watch?v=R37q2XDM18M

The qc is for FTE, hence it doesn't bother with those DP required functions. It uses a list of engine builtings dumped directly from the engine to compile, instead of a csqc defs.qc. My aim is to eradicate most of defs.qc.
ajay
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Re: CSQC - display an image

Post by ajay »

Ceriux and goldenboy; that's marvellous, thank you. GB your hud is very close, in terms of displaying an image, to what I want, except it won't need to be so complex. You're both really helpful, thank you.
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Re: CSQC - display an image

Post by gnounc »

Post Reply