Forum

Is it possible to use an int in qc?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Is it possible to use an int in qc?

Postby Mexicouger » Fri Oct 15, 2010 1:38 am

Well is it?
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby gnounc » Fri Oct 15, 2010 2:19 am

an integer?
like uh...the number 10?
Yes.

I think perhaps I'm confused as to what you're asking exactly.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby Mexicouger » Fri Oct 15, 2010 2:39 am

gnounc wrote:an integer?
like uh...the number 10?
Yes.

I think perhaps I'm confused as to what you're asking exactly.


No, Like this:
Code: Select all
void() Function =
{
local int i;
//Stuff
};

Or just simply defining an int in Defs.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby Downsider » Fri Oct 15, 2010 2:49 am

You can use integers.. but they're stored in the same data type as a float. Why are you even asking this? For the purposes of QC, floats and integers are obviously completely interchangable.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby frag.machine » Fri Oct 15, 2010 12:34 pm

Vanilla QuakeC doesn't support integers, only floats.
However, fteqcc and frikqcc does emulate integers (they're still floats internally).

In QuakeC, you can treat a float as a 24 bit integer (ignoring the 8 msb). That's why things like this work:
Code: Select all
 if (self.flags & 1)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Fri Oct 15, 2010 1:36 pm

fteqcc doesn't emulate ints. it has direct support, but uses an extended instruction set.

#define int __integer
#define int float
Take your pick.

Floats are fine for everything you really need. Slightly slower, but its all intepreted anyway. And obviously pointer maths has restrictions with floats. And you're limited to 24 bits instead of 32.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby frag.machine » Fri Oct 15, 2010 2:31 pm

Thanks for the correction, Spike.

Regarding the emulation aspect, I observed that QuakeC indeed runs pretty fast, and even in not so modern hardware is fast enough to turn the idea of writing game logic code in native C worthless (at least, in most of the cases). What really eats a lot of processing resources during QuakeC execution usually are built-ins (traceline is the more frequently used) calling SV_RecursiveHullCheck and other similar function to traverse the BSP tree - which are C code already.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Mexicouger » Fri Oct 15, 2010 10:18 pm

I think the game gets weighed down when you spam PlayerPreThink, and PlayerPostThink. I added a cvar function to PlayerPostThink, and the framerate fell by nearly 7 Frames.

Quake c Runs just fine without Ints, So we can go on without them I suppose.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby frag.machine » Sat Oct 16, 2010 4:55 pm

Mexicouger wrote:I think the game gets weighed down when you spam PlayerPreThink, and PlayerPostThink. I added a cvar function to PlayerPostThink, and the framerate fell by nearly 7 Frames.

Quake c Runs just fine without Ints, So we can go on without them I suppose.


Having ints would be great for bitwise operations: one single int can hold 32 bitflags against 24 in a float.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Sat Oct 16, 2010 7:41 pm

because its important to have 8 more bits when you can just create two vars.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby frag.machine » Sat Oct 16, 2010 8:53 pm

Or because it's important NOT HAVING TO create another entity field just because I need 2 or 3 more bitflags in, let's say, .flags ?

Anyway, it's kinda funny see you arguing against the utility of ints in QuakeC, since your engine does support it. :)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Sun Oct 17, 2010 2:43 am

The engine requires .flags to be a .float, regardless of whether you can use ints.

I generally prefer to ensure that stuff works with more than one project. it helps figure out what contains the bugs.

ints are faster than floats, yeah, they can be pipelined better than x87 instructions, etc... but at the end of the day, its really not that significant for a game.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest