Author Topic: Coding Questions  (Read 4589 times)

gruese

  • Guest
Coding Questions
« on: 6 June 2009, 21:35:21 »
Hey guys,

I'm using GAE for a school project and I'm trying to change the behavior of units. After looking through the code and browsing the forum, I haven't really been able to identify the places where the code for certain stuff is placed. For instance, I was trying to find the location of the piece of code that makes Workers auto-build and Technicians auto-heal. Is that even defined in the XML files? Can anybody help me with that?

I'm generally a little confused by the game's structure. Are there UML class diagrams or anything of that nature available? (Those would also help beefing up my project report  ;) )

Cheers
chris

Hectate

  • Guest
Re: Coding Questions
« Reply #1 on: 6 June 2009, 22:56:26 »
Just to clarify (I don't know the code, but it might speed up getting a correct answer) when you mean "auto-build" are you talking about the code that controls what command is given if the player right-clicks (on a structure being built, for instance)?

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Coding Questions
« Reply #2 on: 7 June 2009, 00:12:56 »
For instance, I was trying to find the location of the piece of code that makes Workers auto-build and Technicians auto-heal. Is that even defined in the XML files? Can anybody help me with that?
UnitUpdater::updateStop() checks if there are more commands in the command queue, if there isn't it checks if it can do any autocommands, UnitUpdater::doAutoRepair() will return a repair command if there is a repairable friendly unit in sight.

Quote
I'm generally a little confused by the game's structure. Are there UML class diagrams or anything of that nature available? (Those would also help beefing up my project report  ;) )
Unfortunately no, there are no UML diagrams, nor anything 'of that nature'. I've been working on an introduction to the engine (for coders), but it wont be ready for some time, certainly the part you'd be interested in wont be ready for 2-3 weeks, minimum.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

gruese

  • Guest
Re: Coding Questions
« Reply #3 on: 7 June 2009, 17:42:58 »
UnitUpdater::updateStop() checks if there are more commands in the command queue, if there isn't it checks if it can do any autocommands, UnitUpdater::doAutoRepair() will return a repair command if there is a repairable friendly unit in sight.

Thanks, that's what I was looking for.

Quote
Quote
I'm generally a little confused by the game's structure. Are there UML class diagrams or anything of that nature available? (Those would also help beefing up my project report  ;) )
Unfortunately no, there are no UML diagrams, nor anything 'of that nature'. I've been working on an introduction to the engine (for coders), but it wont be ready for some time, certainly the part you'd be interested in wont be ready for 2-3 weeks, minimum.

I'd still be very interested, is there a forum thread about your introduction I can follow?

gruese

  • Guest
Re: Coding Questions
« Reply #4 on: 7 June 2009, 17:50:41 »
Just to clarify (I don't know the code, but it might speed up getting a correct answer) when you mean "auto-build" are you talking about the code that controls what command is given if the player right-clicks (on a structure being built, for instance)?

No, not quite. I was actually talking about the worker going to work automatically when he's idle and standing close to a building that's under construction. I think silnarm got it right, will check the UnitUpdater functions. Thanks for the replies, guys!  :)

gruese

  • Guest
Re: Coding Questions
« Reply #5 on: 17 June 2009, 17:23:58 »
Ok, next question: Can someone tell me how the texture combiner for the team colors work? I know it's the MeshCallbackTeamColor class in renderer.cpp, but I can't figure out how it works. Google isn't telling me either  :-[

What I am trying to do is render something additional for each unit (a billboard flying over their head actually), but the team color texture keeps interfering with my color & alpha.

I basically added this to the inner loop in Renderer:renderUnits(), just before glPopMatrix():

// if unit is not a building, render billboard
if(!unit->getType()->isOfClass(ucBuilding)) {
   renderUnitBillboard(unit);
}

The renderUnitBillboard is a private function and looks like this:

void Renderer::renderUnitBillboard(Unit* unit) {
   Vec3f v1(-0.5f,-0.5f, 0.1f);
   Vec3f v2( 0.5f,-0.5f, 0.1f);
   Vec3f v3( 0.5f, 0.5f, 0.1f);
   Vec3f v4(-0.5f, 0.5f, 0.1f);

   glPushAttrib(GL_ALL_ATTRIB_BITS);
   glTranslatef(0.0f, 5.0f, 0.0f);
   glDisable(GL_DEPTH);
   glDisable(GL_CULL_FACE);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_BLEND);
   glDisable(GL_LIGHTING);
   glBindTexture(GL_TEXTURE_2D, static_cast<Texture2DGl*>(coreDate.getSomeTexture())->getHandle());

   // render the billboard
   glBegin(GL_QUADS);
      glTexCoord2f(0.0f, 0.0f);
      glVertex3fv(v1.ptr());
      glTexCoord2f(1.0f, 0.0f);
      glVertex3fv(v2.ptr());
      glTexCoord2f(1.0f, 1.0f);
      glVertex3fv(v3.ptr());
      glTexCoord2f(0.0f, 1.0f);
      glVertex3fv(v4.ptr());
   glEnd();

   glPopAttrib();
}

Like I said, the team color keeps getting put in place of the transparency I'm actually looking for. What's really strange is that sometimes it works, like when I send Workers to mine or harvest. I tried turning off the team colors altogether, commenting out the line
meshCallbackTeamColor.setTeamTexture(world->getFaction(i)->getTexture());

in the unit render loop. It works that way, but I want to keep the team colors, just not in my billboards.
Can someone help me out? Thanks!
« Last Edit: 17 June 2009, 19:52:44 by gruese »

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Coding Questions
« Reply #6 on: 17 June 2009, 22:10:46 »
The transparency thing seems like it might be a single/double sided mesh things... but I see you explicitly disabled face culling... so maybe not.

All I can say from looking at it quickly, is that perhaps 'mixing' immediate mode code with the vertex array based model renderer is an issue?  But I don't think this should be the case either... Sorry, not very helpful... but I'm no graphics  programmer.

Glest Advanced Engine - Code Monkey

Timeline | Downloads

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Coding Questions
« Reply #7 on: 17 June 2009, 23:39:17 »
Wait a year when I do the unit on graphics programming and I could tell you.  :P

Maybe it only affects a certain level of alpha. Perhaps the team colour areas should be something less used like a colour shade.
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

gruese

  • Guest
Re: Coding Questions
« Reply #8 on: 18 June 2009, 10:24:06 »
Quote from: silnarm
The transparency thing seems like it might be a single/double sided mesh things... but I see you explicitly disabled face culling... so maybe not.

I don't think it has anything to do with single or double sided meshes, although it seems that some animations (e.g. a harvesting worker) work fine while others (e.g. a stopped worker) don't. I'll play around with that to find out more.

Quote from: silnarm
All I can say from looking at it quickly, is that perhaps 'mixing' immediate mode code with the vertex array based model renderer is an issue?  But I don't think this should be the case either... Sorry, not very helpful... but I'm no graphics  programmer.

I'm not quite sure what you mean by "immediate mode code", can you elaborate?

Quote from: hailstone
Maybe it only affects a certain level of alpha. Perhaps the team colour areas should be something less used like a colour shade.

I think it has something to do with some settings of the opengl state machine that are being changed during rendering, but I can't quite figure out which ones. I'm not exactly an opengl-guru, but I understand enough to do basic rendering and effects. My guess is I have to adjust the glTexEnv()-settings, but I don't understand what is being done in MeshCallbackTeamColor::execute (and how to reverse it).

gruese

  • Guest
Re: Coding Questions
« Reply #9 on: 18 June 2009, 10:27:43 »
Just to show you what I'm talking about:

Works fine here


Doesn't work for the worker ...


... but when he's sent to harvest it does

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Coding Questions
« Reply #10 on: 18 June 2009, 12:36:08 »
Ok, I think I might have it, MeshCallbackTeamColor::execute() is sometimes enabling two texture units, sometimes just one... you're just using whichever is active...
try this,
Code: [Select]
glActiveTexture(GL_TEXTURE1);
if ( glIsEnabled ( GL_TEXTURE_2D ) )
   glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
Just after you push attribs.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

gruese

  • Guest
Re: Coding Questions
« Reply #11 on: 18 June 2009, 15:19:55 »
Ok, I think I might have it, MeshCallbackTeamColor::execute() is sometimes enabling two texture units, sometimes just one... you're just using whichever is active...
try this,
Code: [Select]
glActiveTexture(GL_TEXTURE1);
if ( glIsEnabled ( GL_TEXTURE_2D ) )
   glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
Just after you push attribs.

Yup, that was it. I had to add this line:
Code: [Select]
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
because the billboards were still being displayed differently (some were lighter than others because the mode wasn't identical for all of them).

But turning off the other texture sure got rid of the transparency problems and made me understand what was going on. I get it now :)
Thanks a lot! Stand by for my next question  ;)

gruese

  • Guest
Re: Coding Questions
« Reply #12 on: 19 June 2009, 16:25:36 »
Ok, I have a new question:
I'm puzzled by the Effects stuff. If I understand correctly, you can endow units with effects, that - depending on their effect type - do certain things with the unit's stats and may even make themselves seen graphically. Is that correct so far?

However, when trying to learn from already existing effects I could not find any xml file that contained effect definitions, nor could I find any examples of effects. So I kind of assumed that they just aren't used at all right now. Am I right or am I blind? :)

In any case, what I'd like to do is create a new effect, let's call it starvation, that is put on tech units when their food supply has run out. The way it is now is that when you run out of food, a pretty unspectular event occurs every now and then that takes hit points from some or all of your units. I'd like to replace that with the effect starvation that slowly reduces all of the units' hit points and ideally makes them glow red to show that something is wrong. Where and how would I define that effect in the xml files and how would I access it in the code? My idea is checking for food supplies in the UnitUpdater class and then putting the effect on all units, but I just don't know how to go about creating a new effect type and instantiating new effects of that type. Can you guys help?

I do have to add that I am currently running gae v0.1.8c, but I'm not really willing to switch to the newest version due to all the little changes I've made.

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Coding Questions
« Reply #13 on: 20 June 2009, 04:56:11 »
« Last Edit: 18 June 2016, 13:03:22 by filux »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

gruese

  • Guest
Re: Coding Questions
« Reply #14 on: 20 June 2009, 12:12:55 »
Do you know about https://docs.megaglest.org/GAE/Reference ?

No I didn't, thanks. I also decided to try switching to 2.11 so I wouldn't post any more stupid questions that have already been addressed.  :-[
Compiled it yesterday (Win XP, Visual C++ 2008) and it works fine. I'll check out the Wiki and try to solve this one myself.
« Last Edit: 18 June 2016, 13:03:08 by filux »

 

anything