Understanding something in Quake 2 Source Code

This is a discussion on Understanding something in Quake 2 Source Code within the C Programming forums, part of the General Programming Boards category; Hi, I recently downloaded the source code to Quake 2 (not including the rendering engine), and I'm trying to understand ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    127

    Understanding something in Quake 2 Source Code

    Hi,

    I recently downloaded the source code to Quake 2 (not including the rendering engine), and I'm trying to understand how it works. In it, there's a source file called p_client.c, which includes a function declared thus:

    Code:
    void PutClientInServer (edict_t *ent)
    Inside this function, a pointer is declared like this:

    Code:
    gclient_t *client;
    Now here's what I don't get. Say if I make myself another source code file called "bot.c", and I include all the header files that were included in p_client.c:

    Code:
    #include "g_local.h"
    #include "m_player.h"
    And then, in a function in "bot.c" I try to declare a pointer like this:

    Code:
    gclient_t *client;
    If I do this, I get an error. It says "error C2275: 'gclient_t' : illegal use of this type as an expression".

    Could this be something to do with how gclient_t is declared in "game.h"? This file is included by "g_local.h" which is one of the ones I mentioned to be included earlier.

    Code:
    typedef struct edict_s edict_t;
    typedef struct gclient_s gclient_t;
    
    
    #ifndef GAME_INCLUDE
    
    struct gclient_s
    {
    	player_state_t	ps;		// communicated by server to clients
    	int				ping;
    	// the game dll can add anything it wants after
    	// this point in the structure
    };
    Thanks. If you want to see the full source code you can download it here:

    ftp://ftp.idsoftware.com/idstuff/qua...e/q2src320.exe

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    457
    Why is the struct declared as gclient_s, and the variables as gclient_t?

  3. #3
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    Posts
    88
    Why is the struct declared as gclient_s, and the variables as gclient_t?
    typedef struct gclient_s gclient_t;
    ~Your Captain Obvious
    Last edited by GL.Sam; 08-05-2009 at 08:19 AM.
    The only good is knowledge and the only evil is ignorance.
    ~Socrates

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    127
    Thanks for the replies but actually someone on another forum has explained the problem. Apparently it's because you have to have variable declarations at the beginning of a block. When I was declaring
    Code:
    gclient_t *client;
    I was doing so after doing some other stuff in the function first. Thanks anyway guys.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Well its seems you have this underwraps. Also glcient_t is fully defined in g_local.h, so within your preprocessor definitions, for game.h you may want to move your typedefs below your structure declaration, but that was noted in your previous forum I guess. Though this depends on how this gclient_s is to be populated as this is somewhat dynamic based on server response, kind of slick.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    127
    Quote Originally Posted by slingerland3g View Post
    Well its seems you have this underwraps. Also glcient_t is fully defined in g_local.h, so within your preprocessor definitions, for game.h you may want to move your typedefs below your structure declaration, but that was noted in your previous forum I guess. Though this depends on how this gclient_s is to be populated as this is somewhat dynamic based on server response, kind of slick.
    Actually that stuff I posted from game.h is part of the original code. There's more to it than I posted though, so presumably there's some other stuff in there that makes it work ok. Thanks for the reply though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'Type' Error on Build of Officially Released Source Code
    By Jedi_Mediator in forum C++ Programming
    Replies: 5
    Last Post: 07-07-2008, 06:28 PM
  2. How to make a program that prints it's own source code???
    By chottachatri in forum C++ Programming
    Replies: 38
    Last Post: 03-28-2008, 08:06 PM
  3. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 06:50 PM
  4. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 04:50 PM
  5. Source Code Beautifier
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-05-2002, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21