Click here to Skip to main content
16,020,313 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I'm working with the Doom3 source code that ID\Zenimax recently released to the public, and I came across something that I can't seem to figure out. (I'm not the best C++ programmer, I'm more of C# kinda guy.)

C++
/*
================
idTarget_EndLevel::Spawn
================
*/
void idTarget_EndLevel::Spawn( void ) {
	idStr		guiName;

	gui = NULL;
	noGui = spawnArgs.GetBool("noGui");
	if (!noGui) {
		spawnArgs.GetString( "guiName", "guis/EndLevel.gui", guiName );

		if (guiName.Length()) {
			gui = idUserInterface::FindGui( guiName, true, false, true );			
		}
	}

	buttonsReleased = false;
	readyToExit = false;

	exitCommand = "";
}


The important bit, is the "idUnserInterface::FindGui" function call, this function does not exist in that class, nor does that class inherit that member from any other class. ? (ie, idUserInterface, doesn't contain that member, and it doesn't seem to inherit it. But, the code is correct, and compiles.)

Here is how the function is being defined, the best I can tell.

C++
class idUserInterfaceManagerLocal : public idUserInterfaceManager {
	friend class idUserInterfaceLocal;

public:
	virtual idUserInterface *	FindGui( const char *qpath, bool autoLoad = false, bool needInteractive = false, bool forceUnique = false );


This link contains a reference for the entire source code for the game, so you can easily look up the classes, view relations, etc, to help answer this question.

https://dev.visucore.com/doom3/doxygen/index.html[^]

You can also download the full source here.

https://github.com/TTimo/doom3.gpl[^]

(Just ask if you need any more info, I tried to keep it short, and relevant.)

-----

For the record, here is what I'm actually working on, I'm creating a new solution in VC++, and remaking the project by importing the original code, it originally consisted of several sub projects, which I'm condensing into a single project, since most of it's not needed for my purposes. (ie, it had code for the expansion packs, an SDK, editors, etc,.)

It was going well until I hit this error.

game\EndLevel.cpp(58): error C3861: 'FindGui': identifier not found


Which lead to the current question, I need to figure out how this technique works, what it's called, and research it, so I can properly implement this portion of the original source in my new VC++ solution. (Hope this all makes sense.)
Posted
Updated 7-Jan-12 7:42am
v4
Comments
Albert Holguin 7-Jan-12 20:55pm    
Not sure your question makes sense... FindGui() must exist within idUserInterface or else it won't compile, which by your error, seems like that's the case... the virtual definition means that it can be overridden, that's all. Don't forget that C++ allows you to break up a class into multiple files, in another words, the function may exist in another file (typically the declarations are kept together in one header (don't think you can break that up) but the method definitions can be in multiple files).
Kethu Sasikanth 7-Jan-12 21:56pm    
method signature tells it is non-static. But in above it is a static call, idUserInterface::FindGui(). I just skimmed the code in UserInterface.cpp
class name: idUserInterfaceManagerLocal.

you may have to do something like
idUserInterfaceManagerLocal obj = new idUserInterfaceManagerLocal();
obj->FingGui(..). The idUserInterfaceManager is an abstract base class to idUserInterfaceManagerLocal.

Also, I could not locate idUserInterfaceManagerLocal() default constructor. It is possible that the idUserInterfaceManager* pointer is returned by some extern C method.
Sergey Chepurin 8-Jan-12 9:17am    
I doubt very much that this code compiles. This is not described in the standard, and it generates an error when trying to recreate this code structure. Thanks for the link anyway, it is always interesting to see the internals of famous projects. By the way, i didn't see much of exception or error handling.

1 solution

I figured it out, what happened, was during the project migration, I loaded up an old file, it must have been from a earlier game build, so yeah, that won't build, and isn't required to build. (ie, it was just a junk file.)

Sorry, my fault. :(

@Sergey Chepurin, yeah, the code is actually kind of scary, they do lot's of stuff, you really shouldn't be doing, though, my ignorance of whats necessary for Mac\Linux support, may be clouding my judgement a bit.

Check out how they initialize the main window, and how they load OpenGL, it seems very wrong to me. (Like I said though, perhaps, hopefully, it's because they supported GCC\Linux\Mac builds, etc,.)

They also do stuff like.. (Roughly)

C++
void SomeFunc();

void FreeTexture(tex in)
{

if (SomeFunc) // Yes, no brackets. And on a void func. ??
{
  // Unload Textures (I'm assuming it leaks memory, or there is another method that works somewhere.. ?)
    UnloadTex(in);
}
}
 
Share this answer
 
Comments
Stefan_Lang 9-Jan-12 5:14am    
That code does look odd, but I could imagine it is meant to verify that the program hasn't reached a certain point of deinitialization that would prevent UnloadTex to work properly (e.g. if SomeFunc() is a virtual function referring to a VFT that may no longer be valid on program shutdown, but would be required within UnloadTex() )

(even then I expect the result may be compiler dependent and thus may not work as intended on other compilers)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900