How to get source changes included in the official release?

How to get source changes included in the official release?

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

How to get source changes included in the official release?

Post by zwzsg »

I'm trying to learn programming in Visual C++ 7.1 so I can code myself all I want in Spring.

So far I made a small change to source code:

Inside game.cpp

- Add in the beginning, add:

Code: Select all

#include "UnitLoader.h"
- Inside void CGame::HandleChatMsg(std::string s,int player) replace:

Code: Select all

	if(s.find(".cheat")==0 && player==0){
		gs->cheatEnabled=true;
		info->AddLine("Cheating!");
	}
be careful, just the cheat part, not the nocost part, someone should separe them with a return.

by:

Code: Select all

	if(s.find(".gi")==0 && gs->cheatEnabled){
		if (((s.rfind(" "))!=string::npos) && ((s.length() - s.rfind(" ") -1)>0)){

			string unit_to_give=s.substr(s.rfind(" ")+1,s.length() - s.rfind(" ") -1);
			string temp_string_unit_to_give=s.substr(s.find(" "),s.rfind(" ")+1 - s.find(" "));
			if(temp_string_unit_to_give.find_first_not_of(" ")!=string::npos)
				temp_string_unit_to_give=temp_string_unit_to_give.substr(temp_string_unit_to_give.find_first_not_of(" "),temp_string_unit_to_give.find_last_not_of(" ") +1 - temp_string_unit_to_give.find_first_not_of(" "));
			bool is_unit_to_give_nanoframe=(temp_string_unit_to_give.find("nano")!=string::npos);
			
			int number_of_unit_to_give=1;
			if(temp_string_unit_to_give.find_first_of("0123456789")!=string::npos){
				temp_string_unit_to_give=temp_string_unit_to_give.substr(temp_string_unit_to_give.find_first_of("0123456789"),temp_string_unit_to_give.find_last_of("0123456789") +1 -temp_string_unit_to_give.find_first_of("0123456789"));
				number_of_unit_to_give = atoi(temp_string_unit_to_give.c_str());
			}
			if (unitDefHandler->GetUnitByName(unit_to_give)!=0)	{
				float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
				float3 pos=camera->pos+mouse->dir*dist;

				UnitDef *unit_to_give_definition= unitDefHandler->GetUnitByName(unit_to_give);
				int xsize_utg=(unit_to_give_definition->xsize);
				int zsize_utg=(unit_to_give_definition->ysize);
				int counter_utg=number_of_unit_to_give;
				int znum_of_unit_to_give=(int)sqrt((float)number_of_unit_to_give);
				int xnum_of_unit_to_give=number_of_unit_to_give/znum_of_unit_to_give;
				float3 minpos=pos;
				minpos.x-=(xnum_of_unit_to_give*xsize_utg*SQUARE_SIZE)/2;
				minpos.z-=(znum_of_unit_to_give*zsize_utg*SQUARE_SIZE)/2;
				int counterx_utg;
				int counterz_utg;
				for(counterx_utg=xnum_of_unit_to_give;counterx_utg>=1;--counterx_utg){
					for(counterz_utg=znum_of_unit_to_give;counterz_utg>=1;--counterz_utg){
						unitLoader.LoadUnit(unit_to_give,float3(float (minpos.x + counterx_utg * xsize_utg*SQUARE_SIZE), float (minpos.y + 0), float (minpos.z + counterz_utg * zsize_utg*SQUARE_SIZE)),gu->myTeam,is_unit_to_give_nanoframe);
						--counter_utg;
					}
				}
				for(counterx_utg=counter_utg;counterx_utg>=1;--counterx_utg){
						unitLoader.LoadUnit(unit_to_give,float3(float (minpos.x + counterx_utg * xsize_utg*SQUARE_SIZE), float (minpos.y + 0), float (minpos.z + counterz_utg * zsize_utg*SQUARE_SIZE)),gu->myTeam,is_unit_to_give_nanoframe);
					}
				//unitLoader.LoadUnit(unit_to_give,pos,gu->myTeam,is_unit_to_give_nanoframe);
				char dsfdsfdsfdsfdsqfsqdg[130];//Sorry, I don't know how to convert an int to a string without using a temporary variable
				_itoa(gu->myTeam,dsfdsfdsfdsfdsqfsqdg,10);
				string speech_to_say="Giving one "+unit_to_give+" to team "+dsfdsfdsfdsfdsqfsqdg;
				_itoa(number_of_unit_to_give,dsfdsfdsfdsfdsqfsqdg,10);
				if (number_of_unit_to_give!=1)
					speech_to_say.replace(speech_to_say.find("one"),3,dsfdsfdsfdsfdsqfsqdg);
				if(is_unit_to_give_nanoframe)
					speech_to_say+=" nanoframe";
				info->AddLine(speech_to_say);
			}else{
				info->AddLine(unit_to_give+" is not a valid unitname");
			}
		}
	}

	if(s.find(".cheat")==0 && player==0){
		if (gs->cheatEnabled){
			gs->cheatEnabled=false;
			info->AddLine("No more cheating");
		}else{
			gs->cheatEnabled=true;
			info->AddLine("Cheating!");
		}
	}
It's probably not the cleanest code, I'm still a newb in c++, anyone who could teach good way to code be welcome, I'm particularly not sure keeping on defining variables as I need them in the middle of the code is very good.

The effect are the following:
1) .cheat becomes a toggle, once cheat are enabled typing .cheat again disable the cheat mode. Useful when you need the cheat once in the beginning of a game but don't want other player to be able to use them later.
2) a new cheat code is added: .gi* (number) (nano*) unitname. For instance
.give armavp create an arm advanced vehicle plant
.gimme nanoframe armpw create an unbuilt peewee
.gift 50 CorKrog create fifty krogoths!
You can combine nano and a number. The unitname must always be last. Units are spawn under the cursor, nicely organised in a square.


Ok, the addition of that cheat code is probably not vital to spring (but I'd still like it to be included, it works well and it's very useful for testing stuff. For instance it's nice to be able to build anything without having to travel the whole buildtree, or to build stuff even if they aren't in the buildmenu, or to get unit that would cause problem in the factory they're supposed to be built from, or to get instabuild anywhere without using the .nocost cheat that can't be turned off, or....)

But now, given that concrete exemple, I'd like someone to teach me the proper way to get it uploaded on sourceforge. Using WinCVS I can download the latest source fine, but now, how to upload a change? Do I just post in the Spring Developpement forum like I did? Must I create a diff file with WinCVS and post it? (If so, what do I diff it with, lastest source from CVS or source of lastest officialy realesed build?) Is there some secret menu in WinCVS to upload my change automatically? Is there some page on the CVS to upload and comment my change?

I know that many people had trouble getting their change to the source code included in official release, so I'd like to know the proper way. So if I ever does a much bigger and more useful change (lemme dream!), I'll know the way.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 »

Whoa! Nice job!

Now watch C++ eat your soul :-) :shock:

The way Jounonmiko told me worked was to create the .diff file then just send it SJ (with commentary on what the .diff does, of course).

My corollary: pester him about it if he doesnt ge tback to you about whether or not he got the change.

You can't post chagnes directly to the CVS, but you have to go through SJ or one of the other members.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Nice work!
I would shorten the names though, it probably improves readability a lot.
You might also want to call a temp variable just "temp" or something instead of "dsfdsfdsfdsfdsqfsqdg" :)
User avatar
Min3mat
Posts: 3455
Joined: 17 Nov 2004, 20:19

Post by Min3mat »

the .gi command would be THE BEST for balance testing! once you work out relative cost etc you could test things in seconds! :D
User avatar
Isaactoo
Posts: 124
Joined: 08 Dec 2004, 21:53

Post by Isaactoo »

That's really cool.
Any chance of adding a cheat equivalent to +nowisee ? :-)
User avatar
NOiZE
Balanced Annihilation Developer
Posts: 3984
Joined: 28 Apr 2005, 19:29

Post by NOiZE »

and +atm
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post by SJ »

.atm ? :)

Ok I will include the code although I think i might redo it a bit.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Re: How to get source changes included in the official relea

Post by PauloMorfeo »

zwzsg wrote:... I'm still a newb in c++, anyone who could teach good way to code be welcome, I'm particularly not sure keeping on defining variables as I need them in the middle of the code is very good.
Even though i don't fancy much a 2 space indentation, you're taking good care of the indentation keeping things organised, which is fundamental to good programing.
I fancy the way you control the lines:

Code: Select all

if (whatever) {
      code();
} else {
      moreCode();
}
Saves vertical space and is very readable (maybe even more than the «normal» way).

Instead of this:
number_of_unit_to_give
I think this is better:
numberOfUnitToGive, for variables,
NumberOfUnitToGive, for functions, class methods and class names and other things i can't remember.
Or maybe a shorter name (with the same casing style) that's still descriptive of what it does. It makes things easier than trying to figure out what the variable "noutg" does.

About temporary variables, "dsfdsfdsfdsfdsqfsqdg" is probably not so good and "temp" or something like "x", "z", "i", etc is probably better.

I use the coding guides that i once saw on the mono project page but i can't seem to find it again.
If you haven't already, i would tell you to check out some coding guidelines for C/C++/C# and follow they're fundamentals. Although you're doing a very nice coding job, anyway.

About defining variables in the middle of the code, i don't usually do that, trying to always define them all together in the begining of the code to keep them organized. Sometimes, i don't follow that padron, especially when i'm using a variable that's used only when a condition is met (if) and it's a class that's complex, so it is not created if not needed.
But i don't know for sure how good/bad such practices are. I'm not a C/C++ guru...
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

The way of writing } else { on same line I copied from SJ's code above and below.

I have trouble finding short and descriptive names quickly, and I don't like wasting time pondering what would be the best name of a variable. I wish I had more imagination.

Ok, so that's the casing style to use.

The problem with name like temp,i,j,k,x,y is that I'm always afraid someone might already have used them somewhere. I wish I could have find a way to write that without using a temp var. It seem odd to have to name well something used only in two lines.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Post by SinbadEV »

Yay Local Variables and Scope!!!

if you define a variable that has the same name as something else within a codeblock {statements}, even if they share a name with a global variable, they will be stored in an entirely different memory location...

If I remember correctly from "C++ Programming 1"
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

zwzsg wrote:...
The problem with name like temp,i,j,k,x,y is that I'm always afraid someone might already have used them somewhere. ...
SinbadEV wrote:Yay Local Variables and Scope!!!
...
Yes, the scope of variables. That would be usefull for you to learn although boring. So, i'll give you a walkthrough (prone to errors. I haven't been coding C/C++ for a while. Only C#...).

Code: Select all

Function1()
{
      int var;
}
Function2()
{
      int var;
}
Both the variables are only accesible inside it's own function. If you make sure there are no duplication of variable names inside the function/class you're writing (compiler will warn you, anyway), you're ok. «Local» variables with same names coexist happily because they exist only inside that function.

When global variables hit the scene (global variables are generaly avoided much because of problems like these):

Code: Select all

int var; //Global variable
Function1()
{
      int var;
}
In this case, i think that when you try to use the variable var, it will use the one that's been declared inside the function where the code is executing.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

But is a mere if {} enough a scope to have its own set of local variable?

Add SJ's rewriting of it is so much smaller and simpler it ain't funny.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Yes it is, even {} alone is enough:

This:

Code: Select all

void testfunc() 
{
  int var;
  
  { int var; }
}

is valid code.
Post Reply

Return to “Engine”