Code reformatting project [DONE]

Development directions, tasks, and features being actively implemented or pursued by the development team.
Post Reply
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

This is confusing... Under /src there's,
  • configxml.h
  • configxml.cpp
  • config_xml.h and
  • config_xml.cpp
and config_xml.h has a class GameVegaConfig where everything is private except the ctor, and has no friend declarations; but it inherits VegaConfig, from configxml.h, which is all public (should be a struct), and whose dtor was non-virtual (fixed now).
Anyhow, config_xml.h #includes config.h, which I can't find anywhere...
pheonixstorm
Elite
Elite
Posts: 1567
Joined: Tue Jan 26, 2010 2:03 am

Re: Code reformatting project

Post by pheonixstorm »

The entire source project is confusing.. too much code that doesnt make sense, doesnt belong, or shouldnt have been added to begin with. We should write a book, How NOT to write a game! :lol: Oh well, it works (up to .5.0) and its open source. By build .6.0 the codebase should be fairly clean and might run a little better. To me the biggest problem is still checking on what files are actually needed and why the rest were never deleted out of the code base, at least for the win build... linux base gets a lot more attention.

Still using the same crusty settings or did they change slightly?

*EDIT* I should say by release build .6.0 as no one has really said what build number we should use.
Because of YOU Arbiter, MY kids? can't get enough gas. OR NIPPLE! How does that mkae you feeeel? ~ Halo
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Don't worry; it will get a lot better, now that after reformatting many more programmers will be able to work with it.
No, the configs haven't changed since I last updated them at their existing links.
Well, today I didn't do any more bad macro hunting, got distracted with getting rid of warnings.
The good news is I got rid of them. Well, almost... First there's the boost warnings (converting
strings to char* or something like that. Nothing I can do about that except put pragmas before
the includes.
And right now I have an interesting case in /objconv/basemaker.cpp, line 1366:

Code: Select all

bool LinkStage3Goto(std::string input, unsigned int unusedindexdat, void *dat1, void *dat2, const void *dat3, float x, float y) {
	 return (sscanf(input.c_str(), "%d", dat1)>=1);
}

Code: Select all

objconv/basemaker/base_maker.cpp:1364: warning: format ‘%d’ expects type ‘int*’, but argument 3 has type ‘void*’
I'm going to try changing arg3 to int* and see what else breaks.
It is heartening to see const void *dat3; so it seems hellcat and ace DO know about const... :)

EDIT:
Nope, changing void* to int* is a no-go; there's another function that takes a pointer to a function with the whole signature; seems the change would spread all over. Just changed the function above to,

Code: Select all

bool LinkStage3Goto(std::string input, unsigned int unusedindexdat, void *dat1, void *dat2, const void *dat3, float x, float y) {
	 return ( sscanf( input.c_str(), "%d", reinterpret_cast<int*>(dat1) )>=1 );
}
A few more warnings to go...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Weird...
objconv/mesher/to_obj.h was missing in my local repo.
I restored it with svn up, but it was blank.
So I looked at it in trunk and it's blank also.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

All warnings squashed, except those that happen in boost.
r12631
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

What on Earth is this doing at the bottom of cmd/unit.h?

Code: Select all

/*
 ***************************************************************************
 **** Since we now use templates, we have to include GameUnit related    ***
 **** .cpp files in unit.h to avoid problems with some compilers         ***
 ***************************************************************************
 */
#include "unit.cpp"
I'm having convulsions... unit.h is included in almost every other header, and
it so happens to include unit.cpp ?!?!?!?!
(Not to speak of the fact that unit.cpp includes half a million headers...)

I'm going to comment this out, see what happens...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

HELP!

I commented out the #include "unit.cpp" from unit.h, and fixed the gazillion of
files that were missing headers after doing that. Everything compiles now, but
the linker borks because there is no unit.o target. Been looking at all the files
with "make" and "configure" in their names, trying to find where a .o target is
specified and linked. Managed to add unit.cpp to the CMakeLists.txt, but I've
no idea what file to change how for the regular make file. I'd never looked at
make files before.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Please help! I modified Makefile.am, and I saw unit.o being generated during the build,
but at link-time all the GameUnit class functions were still not found.
I'm totally out of ideas... :(

Code: Select all

src/star_system.o: In function `GameStarSystem::Draw(bool)':
star_system.cpp:(.text+0x19e8): undefined reference to `GameUnit<Unit>::Draw(Transformation const&, Matrix const&)'
src/cmd/asteroid.o: In function `GameAsteroid::GameAsteroid(char const*, int, Flightgroup*, int, float)':
asteroid.cpp:(.text+0x45d): undefined reference to `GameUnit<Asteroid>::GameUnit(char const*, bool, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Flightgroup*, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
asteroid.cpp:(.text+0x4f7): undefined reference to `GameUnit<Asteroid>::~GameUnit()'
src/cmd/asteroid.o: In function `GameAsteroid::GameAsteroid(char const*, int, Flightgroup*, int, float)':
asteroid.cpp:(.text+0x56d): undefined reference to `GameUnit<Asteroid>::GameUnit(char const*, bool, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Flightgroup*, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
asteroid.cpp:(.text+0x607): undefined reference to `GameUnit<Asteroid>::~GameUnit()'
src/cmd/asteroid.o: In function `GameAsteroid::UpdatePhysics2(Transformation const&, Transformation const&, Vector const&, float, Matrix const&, Vector const&, bool, UnitCollection*)':
asteroid.cpp:(.text+0xa): undefined reference to `GameUnit<Asteroid>::UpdatePhysics2(Transformation const&, Transformation const&, Vector const&, float, Matr
.............................................................................
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Never mind; my makefile hacking was okay; the problem is I needed to
have explicit instantiations of GameUnit<UnitType>.
Now I have a different problem... members referred to that don't exist.
So I'm trying to understand how the GameUnit template class works...
Let us light up an incense stick to the Flying Spaghetti Monster before
we begin. Done. Ok.
This is how the declaration of GameUnit begins, in unit.h:

Code: Select all

template < class UnitType >
class GameUnit : public UnitType
{
    friend class UnitFactory;
protected:
    ........................................
I'm not sure I understand why we're using a template here.
There's only a handful of unit types, by the way, so these are my explicit
instantiations:

Code: Select all

template class GameUnit< Asteroid >;
template class GameUnit< Building >;
template class GameUnit< Nebula >;
template class GameUnit< Planet >;
template class GameUnit< Unit >;
template class GameUnit< Missile >;
template class GameUnit< Mesh >;
template class GameUnit< Flightgroup >;
template class GameUnit< Terrain >;
template class GameUnit< ContinuousTerrain >;
template class GameUnit< Enhancement >;
For a moment I thought we were using the CRTP (Curiously Recursing
Template Pattern), but that one templetizes a class by its derived...

Code: Select all

template< class Derived >
class CRTP
{
    ....
};
class CRTP_derived : private CRTP< CRTP_derived >
{
    ....
};
But okay, I was looking for where those missing members were, and I
figured they might be inherited from the unit types, so I picked one
at random, --planet.h:

Code: Select all

class GamePlanet : public GameUnit< class Planet >
{
private:
    Animation *shine;
protected:
    ..................
So, GamePlanet derives from GameUnit<Planet> which in turn
derives from Planet (which comes from planet_generic.h).
((Planet inherits Unit, which comes from "unit_generic.h".))
(((Any class X is always defined in X_generic.h, rather than X.h.)))

I understand the motivation for deriving a common template class from
a handful of different classes, a way of adding common interfaces that
need to vary in types of arguments or returns with base class type. But
do we really want that for units?
And then deriving a non-template class from a template class... Well,
that can be useful too, like when you want to get rid of long template
types that can drive you nuts in the debugger, you just make a non-
-template wrapper... but the thing is, GamePlanet is more than a mere
wrapper; it adds a member UnitCollection satellites, for example.
Why wouldn't sattellites be in Planet rather than in GamePlanet?

Anyways, my problem right now is the implementation of GameUnit<>
in unit.cpp uses members named image, meshdata, faction, name,
etceteras, which don't exist in GameUnit, so I suppose they should be
coming from e.g. Planet, but they don't; so maybe from Unit...
Yep. At least faction is there. Getting somewhere...
Unit must be the largest class ever coded.
Don't look at unit_generic.cpp if you value your sanity...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Alright, vegastrike compiles and links again.
Just had to comment out some of the explicit instantiations. The bottom
of the unit.cpp file now looks like,

Code: Select all

/////////////////////////////////////////////////////
//explicit instantiations, added by chuck_starchaser:

 #include "cmd/asteroid_generic.h"
 template class GameUnit< Asteroid >;

 #include "cmd/building_generic.h"
 template class GameUnit< Building >;

 #include "cmd/planet_generic.h"
 template class GameUnit< Planet >;

 #include "cmd/unit_generic.h"
 template class GameUnit< Unit >;

 #include "cmd/missile_generic.h"
 template class GameUnit< Missile >;

 #include "cmd/nebula.h"
 template class GameUnit< Nebula >;
 
 #include "cmd/enhancement.h"
 template class GameUnit< Enhancement >;

// The unit types below don't compile; --probably they don't inherit from Unit.

// #include "gfx/mesh.h"
// template class GameUnit< Mesh >;

// #include "cmd/script/flightgroup.h"
// template class GameUnit< Flightgroup >;

// #include "cmd/terrain.h"
// template class GameUnit< Terrain >;

// #include "cmd/cont_terrain.h"
// template class GameUnit< ContinuousTerrain >;

/////////////////////////////////////////////////////


Now the problem is with vegaserver; can't imagine why...

Code: Select all

src/cmd/unit.o: In function `perspectiveFactor(float)':
unit.cpp:(.text+0x1c): undefined reference to `GFXGetZPerspective(float)'
src/cmd/unit.o: In function `T.10206':
unit.cpp:(.text+0x82d): undefined reference to `Camera::GetPQR(Vector&, Vector&, Vector&)'
src/cmd/unit.o: In function `GameUnit<Unit>::GameUnit(std::vector<Mesh*, std::allocator<Mesh*> >&, bool, int)':
unit.cpp:(.text._ZN8GameUnitI4UnitEC1ERSt6vectorIP4MeshSaIS4_EEbi[GameUnit<Unit>::GameUnit(std::vector<Mesh*, std::allocator<Mesh*> >&, bool, int)]+0x1f): undefined reference to `HaloSystem::HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Unit>::GameUnit(std::vector<Mesh*, std::allocator<Mesh*> >&, bool, int)':
unit.cpp:(.text._ZN8GameUnitI4UnitEC2ERSt6vectorIP4MeshSaIS4_EEbi[GameUnit<Unit>::GameUnit(std::vector<Mesh*, std::allocator<Mesh*> >&, bool, int)]+0x1f): undefined reference to `HaloSystem::HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Nebula>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI6NebulaEC1Ei[GameUnit<Nebula>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI6NebulaEC1Ei[GameUnit<Nebula>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Nebula>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI6NebulaEC2Ei[GameUnit<Nebula>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI6NebulaEC2Ei[GameUnit<Nebula>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Missile>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI7MissileEC1Ei[GameUnit<Missile>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI7MissileEC1Ei[GameUnit<Missile>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Missile>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI7MissileEC2Ei[GameUnit<Missile>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI7MissileEC2Ei[GameUnit<Missile>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Unit>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI4UnitEC1Ei[GameUnit<Unit>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI4UnitEC1Ei[GameUnit<Unit>::GameUnit(int)]+0x71): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Unit>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI4UnitEC2Ei[GameUnit<Unit>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI4UnitEC2Ei[GameUnit<Unit>::GameUnit(int)]+0x71): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Building>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI8BuildingEC1Ei[GameUnit<Building>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI8BuildingEC1Ei[GameUnit<Building>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Building>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI8BuildingEC2Ei[GameUnit<Building>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI8BuildingEC2Ei[GameUnit<Building>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Asteroid>::GameUnit(int)':
unit.cpp:(.text._ZN8GameUnitI8AsteroidEC1Ei[GameUnit<Asteroid>::GameUnit(int)]+0x2d): undefined reference to `HaloSystem::HaloSystem()'
unit.cpp:(.text._ZN8GameUnitI8AsteroidEC1Ei[GameUnit<Asteroid>::GameUnit(int)]+0x78): undefined reference to `HaloSystem::~HaloSystem()'
src/cmd/unit.o: In function `GameUnit<Asteroid>::GameUnit(int)':
...................................................................................................
The makefile lists unit.o, and I found it in the big linker echo spurt before
the error messages. Haven't looked deeply yet, but it's complaining about
a reference to a halo system, later a reference to setting orientation of
the camera. These errors seem rather specific...

EDIT:
I think I know why: unit.cpp includes many headers, as well as a few .cpp
files; and the way it was before, instead of unit.cpp including unit.h, it was
unit.h that included unit.cpp! So, whatever included unit.h ended up with
all that huge amount of code... (scroll down)

Code: Select all

//file unit.cpp:
#include "unit.h"   <------------------ I put this there; originally it didn't
                   as this file, unit.cpp, was included at the bottom of unit.h

#include "vsfilesystem.h"
#include "vs_globals.h"
#include "file_main.h"
#include "gfx/halo.h"

#include "unit_factory.h"

#include "gfx/sprite.h"
#include "lin_time.h"

#include "gfx/vsbox.h"
#include "bolt.h"
#include "gfx/lerp.h"
#include "gfx/bsp.h"
#include "audiolib.h"
#include "gfx/cockpit.h"
#include "config_xml.h"
#include "images.h"
//#include "gfx/planetary_transform.h"
///for saving features
#include "main_loop.h"
#include "script/mission.h"
#include "script/flightgroup.h"
#include "savegame.h"
#include "xml_serializer.h"
#include "python/python_class.h"
#include "cmd/ai/missionscript.h"
#include "gfx/particle.h"
#include "cmd/ai/aggressive.h"
#include "cmd/base.h"
//#include "unit_template.h"
//#include "gfx/animation.h"
#include "gfx/point_to_cam.h"
#include "unit_jump.cpp"                         <------------------ cpp!
#include "unit_customize.cpp"                         <------------------ cpp!
#include "unit_damage.cpp"                         <------------------ cpp!
#include "unit_physics.cpp"                         <------------------ cpp!
#include "unit_bsp.h"
#include "unit_click.cpp"                         <------------------ cpp!
#include "base_util.h"

//if the PQR of the unit may be variable...for radius size computation
//#define VARIABLE_LENGTH_PQR

//#define DESTRUCTDEBUG
#include "beam.h"
#include "python/init.h"
#include "unit_const_cache.h"

.................

template < class UnitType >
void GameUnit< UnitType >::UpgradeInterface( Unit *baseun )
{
((Not sure if you realize, by making unit.cpp compile to a .o, I've driven a
blessed samurai sword through the heart of the medusa. And you can feel the
compile time improvement already. Thing is, a lot of modules, and even header
files, include unit.h. THAT was the main reason why a change anywhere used to
trigger so much recompiling. The rest will be a mop-up job.))
Now that sanity has prevailed, some of what used to be delivered via unit.h
will need to be compiled to a .o and put into the linker requirements for
vegaserver. I'm sure this is the problem, but it's going to take work. So, I'm
not going to commit yet. Not sure what the criteria is, yet, but I've been
committing only when everything builds; and right now at least vegaserver
doesn't.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Code reformatting project

Post by klauss »

You're probably having a problem with vegaserver since all that template stuff is there for vegaserver, which changes the template instantiation in a way that cuts off a lot of cruft from unit classes.

I think fixing this would require major refactoring.

Now you'll understand why I mentioned task-oriented branches instead of author-oriented branches. If you've been doing all this on the reformat branch you'll notice you can't separate the changes - can you make me a diff (patch) showing what you changed to get rid of #include "unit.cpp" (or the like)? Probably not. You'll have to work on it on its own branch so that I might help.

Note: might. I have a lot of stuff on my hands as it is. But this kind of refactoring is a good thing, and if you managed to build vegastrike client that's a huge thing, I might try to get vegaserver building again.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

klauss wrote:You're probably having a problem with vegaserver since all that template stuff is there for vegaserver, which changes the template instantiation in a way that cuts off a lot of cruft from unit classes.

I think fixing this would require major refactoring.

Now you'll understand why I mentioned task-oriented branches instead of author-oriented branches. If you've been doing all this on the reformat branch you'll notice you can't separate the changes - can you make me a diff (patch) showing what you changed to get rid of #include "unit.cpp" (or the like)? Probably not. You'll have to work on it on its own branch so that I might help.
Hmm... Yeah, I guess I shouldn't have done this in this branch; I had no idea it was going to take so much work to make it work; thought it was going to be 5-minute fix.
Note: might. I have a lot of stuff on my hands as it is. But this kind of refactoring is a good thing, and if you managed to build vegastrike client that's a huge thing, I might try to get vegaserver building again.
Well, what I could do is commit now (but I'll wait for you to give me the okay)... What I'm thinking is, if I just commit (to the reformat branch), you can check out my branch and see the diff since the previous commit. Except for one tiny change to one file, I think, everything I've done since the last commit is about getting rid of #include "unit.cpp", so you'd simply diff against the previous commit to know what I've done. And, thanks in advance.

EDIT:
And, by the way, if you do check out my branch, I want to apollogize for something in advance:
As I said, I've gotten rid of ALL warnings for vs code (some warnings remain from boost code), and most of what I did to get rid of warnings was perfectly legitimate; but I'm less than proud about a few hacks, namely, to get rid of warnings about ignored return values from functions such as sscanf, fscanf, chdir, etceteras... What I did was to create bogus static variables and assign the results to them. However, all such variables I named starting with "bogus_", so they are easy to grep. What I was planning to do later was to make a "vs_stdio.h" that wraps those functions into macros or template functions that don't return values, but throw exceptions, instead; --and/or log messages to errout; but I needed some guidence for how best to implement them, so, in the interest of expedience I just hacked it like that.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Code reformatting project

Post by klauss »

chuck_starchaser wrote:but I'm less than proud about a few hacks, namely, to get rid of warnings about ignored return values from functions such as sscanf, fscanf, chdir, etceteras...
I've never had those warnings... AFAIK, it's perfectly legitimate to throw away return values - and rather common as well.

How do those look like?
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

I can't remember the exact wording, but, paraphrasingly, it said that on line such and so, the return value was ignored, while some compiler setting was set to warn about ignored return values.
Rather strange that you and I have different compiler settings; I didn't touch anything.
charlieg
Elite Mercenary
Elite Mercenary
Posts: 1329
Joined: Thu Mar 27, 2003 11:51 pm
Location: Manchester, UK
Contact:

Re: Code reformatting project

Post by charlieg »

I'm enjoying watching progress, even if some of it is a little bull-in-a-china-shop - sometimes you gotta break a bit to make a bit!
Free Gamer - free software games compendium and commentary!
FreeGameDev forum - open source game development community
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Hehehe, thanks for the encouragement. Unfortunately, the china smashing is like an expanding shock-wave, right now; complete disaster...
I added the files that define classes Animation, Mission, AnimatedTexture, BaseInterface, FactionUtil, Music and Mesh to the appropriate variable lists for vegaserver in Makefile.am (and CMakeLists.txt, in parallel), so that the linker would find the many functions that unit.o seemed to be looking for. But after make clean, ./bootstrap-sh, ./configure --enable-release --disable-debug --enable-cubemap, and make, the linker errors for vegaserver have multiplied. It seems that all the new modules are also looking for all kinds of other modules... Plus, I got a lot of redefinition errors... Just a tiny fraction of the errors:

Code: Select all

 src/faction_util.o: In function `FactionUtil::GetNumAnimation(int)':
faction_util.cpp:(.text+0x0): multiple definition of `FactionUtil::GetNumAnimation(int)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x80): first defined here
src/faction_util.o: In function `FactionUtil::GetAnimation(int, int, unsigned char&)':
faction_util.cpp:(.text+0x20): multiple definition of `FactionUtil::GetAnimation(int, int, unsigned char&)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x10): first defined here
src/faction_util.o: In function `FactionUtil::createTexture(char const*, char const*, bool)':
faction_util.cpp:(.text+0x60): multiple definition of `FactionUtil::createTexture(char const*, char const*, bool)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x30): first defined here
src/faction_util.o: In function `FactionUtil::createTexture(char const*, bool)':
faction_util.cpp:(.text+0x1b0): multiple definition of `FactionUtil::createTexture(char const*, bool)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x40): first defined here
src/faction_util.o: In function `FactionUtil::getForceLogo(int)':
faction_util.cpp:(.text+0x2c0): multiple definition of `FactionUtil::getForceLogo(int)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x60): first defined here
src/faction_util.o: In function `FactionUtil::getSquadLogo(int)':
faction_util.cpp:(.text+0x360): multiple definition of `FactionUtil::getSquadLogo(int)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x70): first defined here
src/faction_util.o: In function `FactionUtil::createAnimation(char const*)':
faction_util.cpp:(.text+0x410): multiple definition of `FactionUtil::createAnimation(char const*)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x20): first defined here
src/faction_util.o: In function `FactionUtil::LoadFactionPlaylists()':
faction_util.cpp:(.text+0x930): multiple definition of `FactionUtil::LoadFactionPlaylists()'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x50): first defined here
src/faction_util.o: In function `FactionUtil::GetRandCommAnimation(int, Unit*, unsigned char&)':
faction_util.cpp:(.text+0xaa0): multiple definition of `FactionUtil::GetRandCommAnimation(int, Unit*, unsigned char&)'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x0): first defined here
src/faction_util.o: In function `Faction::~Faction()':
faction_util.cpp:(.text+0xcf0): multiple definition of `Faction::~Faction()'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x810): first defined here
src/faction_util.o: In function `Faction::~Faction()':
faction_util.cpp:(.text+0x10a0): multiple definition of `Faction::~Faction()'
src/faction_util_server.o:faction_util_server.cpp:(.text+0x470): first defined here
src/cmd/script/mission.o: In function `Mission::getPlayerMissionNumber()':
...................................................................................................... 
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Update:
Just a hunch, for now, that a lot of the problems occur because of those #include "whatever.cpp"'s in unit.cpp.
So, I commented them out, and got compiler errors; needed a few headers and now unit.cpp compiles; not sure if it links, waiting for the moment of truth, sitting by the dock in the bay, watching gcc scroll away...
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Now I can't seem to get vegastrike to link, anymore... :(
After I commented out those #include "<crap>.cpp" from unit.cpp, I found I needed a few headers
for unit.cpp to compile; namely,

Code: Select all

#include "cmd/unit_generic.h"
#include "cmd/unit_util.h"
#include "networking/netclient.h"
#include "gfx/animation.h"
but then the linker complained about undefined references to functions of Unit,
which is defined in unit_generic.cpp.
So, I added unit_generic.cpp to the link list in Makefile.am, and clean-compiled.
Now I get redefinitions...

Code: Select all

src/cmd/unit_generic.o: In function `Mount::SetMountPosition(Vector const&)':
unit_generic.cpp:(.text+0x0): multiple definition of `Mount::SetMountPosition(Vector const&)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x0): first defined here
src/cmd/unit_generic.o: In function `Mount::SetMountOrientation(Quaternion const&)':
unit_generic.cpp:(.text+0x10): multiple definition of `Mount::SetMountOrientation(Quaternion const&)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x10): first defined here
src/cmd/unit_generic.o: In function `Unit::SetNetworkMode(bool)':
unit_generic.cpp:(.text+0x20): multiple definition of `Unit::SetNetworkMode(bool)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x20): first defined here
src/cmd/unit_generic.o: In function `Unit::SetSerial(unsigned short)':
unit_generic.cpp:(.text+0x30): multiple definition of `Unit::SetSerial(unsigned short)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x30): first defined here
src/cmd/unit_generic.o: In function `Unit::graphic_options::graphic_options()':
unit_generic.cpp:(.text+0x40): multiple definition of `Unit::graphic_options::graphic_options()'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x40): first defined here
src/cmd/unit_generic.o: In function `Unit::graphic_options::graphic_options()':
unit_generic.cpp:(.text+0x70): multiple definition of `Unit::graphic_options::graphic_options()'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x70): first defined here
src/cmd/unit_generic.o: In function `Unit::setFaceCamera()':
unit_generic.cpp:(.text+0xa0): multiple definition of `Unit::setFaceCamera()'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0xa0): first defined here
src/cmd/unit_generic.o: In function `Unit::attackPreference(unsigned char)':
unit_generic.cpp:(.text+0xb0): multiple definition of `Unit::attackPreference(unsigned char)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0xb0): first defined here
src/cmd/unit_generic.o: In function `Unit::unitRole(unsigned char)':
unit_generic.cpp:(.text+0xc0): multiple definition of `Unit::unitRole(unsigned char)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0xc0): first defined here
src/cmd/unit_generic.o: In function `Unit::SetNebula(Nebula*)':
unit_generic.cpp:(.text+0xd0): multiple definition of `Unit::SetNebula(Nebula*)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0xd0): first defined here
src/cmd/unit_generic.o: In function `Unit::InCorrectStarSystem(StarSystem*)':
unit_generic.cpp:(.text+0x120): multiple definition of `Unit::InCorrectStarSystem(StarSystem*)'
src/cmd/unit_generic.o:unit_generic.cpp:(.text+0x120): first defined here
..........................
What I don't understand is why the multiple definitions mention the same file for both, as if
there were two unit_generic.o files linked, or something... But if this were so, why would it
have complained about undefined references before I added it to the link list? :?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Code reformatting project

Post by klauss »

Perhaps you're attacking the problem from the wrong perspective.

You're trying to change too much of too much code that isn't well understood.

I would like to try having vegastrike and vegaserver build with different defines... although it brings a whole new set of trouble, perhaps it's more manageable.

The different defines would replace the #include "unit.cpp" with different, proper extern template blah.

I dunno... I'll have to try...
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

klauss wrote:Perhaps you're attacking the problem from the wrong perspective.

You're trying to change too much of too much code that isn't well understood.
Yeah, no kidding; I'm more like a blind bull in a china shop.
I would like to try having vegastrike and vegaserver build with different defines... although it brings a whole new set of trouble, perhaps it's more manageable.

The different defines would replace the #include "unit.cpp" with different, proper extern template blah.

I dunno... I'll have to try...
So, would you like me to commit what I have?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Re: Code reformatting project

Post by klauss »

chuck_starchaser wrote:So, would you like me to commit what I have?
Never commit things that you know don't work. It will haunt you. I always keep SVN clean and working (unless I make a mistake of course), so if somehow I get lost and desperate, I can svn revert and back to square one. Which is good. Not lost anymore.

Which means most of the time you have to do things in small non-breaking steps.

So, for instance, you (or I) could leave the include for vegaserver, take it out for vegastrike, and make sure you can build both (by using define magic in the makefile).

That's one small step.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Okay, sounds good.
Right now I'm kind of reverting the changes that broke vegastrike linking.
I removed the unit_generic.cpp I had added to Makefile.am, and now the
multiple definition errors are gone, but the undefined references are still
there,

Code: Select all

src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x20): undefined reference to `GameUnit<Enhancement>::UpgradeSubUnits(Unit const*, int, bool, bool, int&, double&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x30): undefined reference to `GameUnit<Enhancement>::Upgrade(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, bool, bool)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x40): undefined reference to `GameUnit<Enhancement>::Split(int)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x50): undefined reference to `GameUnit<Enhancement>::Explode(bool, float)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x80): undefined reference to `GameUnit<Enhancement>::TransferUnitToSystem(unsigned int, StarSystem*&, bool)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0x98): undefined reference to `GameUnit<Enhancement>::ArmorDamageSound(Vector const&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xa0): undefined reference to `GameUnit<Enhancement>::HullDamageSound(Vector const&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xa8): undefined reference to `GameUnit<Enhancement>::Thrust(Vector const&, bool)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xb0): undefined reference to `GameUnit<Enhancement>::UpdatePhysics2(Transformation const&, Transformation const&, Vector const&, float, Matrix const&, Vector const&, bool, UnitCollection*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xc8): undefined reference to `GameUnit<Enhancement>::ResolveForces(Transformation const&, Matrix const&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xd0): undefined reference to `GameUnit<Enhancement>::DealDamageToShield(Vector const&, float&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xd8): undefined reference to `GameUnit<Enhancement>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0x20): undefined reference to `GameUnit<Nebula>::UpgradeSubUnits(Unit const*, int, bool, bool, int&, double&)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0x30): undefined reference to `GameUnit<Nebula>::Upgrade(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, bool, bool)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0x40): undefined reference to `GameUnit<Nebula>::Split(int)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0x50): undefined reference to `GameUnit<Nebula>::Explode(bool, float)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0x80): undefined reference to `GameUnit<Nebula>::TransferUnitToSystem(unsigned int, StarSystem*&, bool)'
......................................
I'm going to try un-commenting the .cpp includes I commented out; then I'll try commenting
one at a time, to see which are really needed.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

Interesting!
After un-commenting the cpp includes, I still I have unresolved references, though just a few:

Code: Select all

src/cmd/unit.o:(.rodata._ZTV8GameUnitI11EnhancementE[vtable for GameUnit<Enhancement>]+0xd8): undefined reference to `GameUnit<Enhancement>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6NebulaE[vtable for GameUnit<Nebula>]+0xd8): undefined reference to `GameUnit<Nebula>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI4UnitE[vtable for GameUnit<Unit>]+0xd8): undefined reference to `GameUnit<Unit>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI8BuildingE[vtable for GameUnit<Building>]+0xd8): undefined reference to `GameUnit<Building>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI8AsteroidE[vtable for GameUnit<Asteroid>]+0xd8): undefined reference to `GameUnit<Asteroid>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI6PlanetE[vtable for GameUnit<Planet>]+0xd8): undefined reference to `GameUnit<Planet>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit.o:(.rodata._ZTV8GameUnitI7MissileE[vtable for GameUnit<Missile>]+0xd8): undefined reference to `GameUnit<Missile>::querySphereClickList(int, int, float, Camera*)'
src/cmd/asteroid.o:(.rodata._ZTV12GameAsteroid[vtable for GameAsteroid]+0xd8): undefined reference to `GameUnit<Asteroid>::querySphereClickList(int, int, float, Camera*)'
src/cmd/building.o:(.rodata._ZTV12GameBuilding[vtable for GameBuilding]+0xd8): undefined reference to `GameUnit<Building>::querySphereClickList(int, int, float, Camera*)'
src/cmd/nebula.o:(.rodata._ZTV10GameNebula[vtable for GameNebula]+0xd8): undefined reference to `GameUnit<Nebula>::querySphereClickList(int, int, float, Camera*)'
src/cmd/planet.o:(.rodata._ZTV10GamePlanet[vtable for GamePlanet]+0xd8): undefined reference to `GameUnit<Planet>::querySphereClickList(int, int, float, Camera*)'
src/cmd/planet.o:(.rodata._ZTV14AtmosphereHalo[vtable for AtmosphereHalo]+0xd8): undefined reference to `GameUnit<Unit>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit_factory.o:(.rodata._ZTV15GameEnhancement[vtable for GameEnhancement]+0xd8): undefined reference to `GameUnit<Enhancement>::querySphereClickList(int, int, float, Camera*)'
src/cmd/unit_factory.o:(.rodata._ZTV11GameMissile[vtable for GameMissile]+0xd8): undefined reference to `GameUnit<Missile>::querySphereClickList(int, int, float, Camera*)'
collect2: ld returned 1 exit status
make: *** [vegastrike] Error 1
all of them about querySphereClickList(int, int, float, Camera*).

EDIT:
Never mind, I'd just missed one cpp include; now vegastrike builds again.
Okay, so first I'm going to try to remove all the files I added to the makefile
lists for vegaserver --which only served to multiply the number of errors...
Then I'll need you to explain to me how to do the makefile hacks to do what
you suggest.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: Code reformatting project

Post by chuck_starchaser »

The thing about those cpp files included in unit.cpp is that they contain template functions only.
They should really have been named .h.

I reverted the file lists for vegaserver in the makefile, so I'm back to the original linker error messages, trying to figure out exactly what's missing and why.
Post Reply