GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Dec-2003, 16:20
EvilIce EvilIce is offline
New Member
 
Join Date: Dec 2003
Posts: 3
EvilIce is an unknown quantity at this point

Need C++ help with functions


Hi, I know from the title of this thread that you would all assume that this is some very newbish or beginner kind of problem, and although I am still kinda new to C++, my true problem is a bit more complex than something that I can just figure out from text books...

See here is my problem: I started my programming coureer back about 5 or maybe even 6 years ago, when I first started to gain interest in modifying games... So I started reading some of the work others had done and eventually had taught myself all the basics to programming, in general. Very soon after, I had also developed a great skill with the particular C++ language variant used by the game's engine, and could create practically anything I wanted, with the greatest of ease. The game was called Starsiege: Tribes 1, made by the now nonexistant Dynamix division of Sierra. The game was incredibly addictive, and in my opinion is one of the greatest games ever made, it was easy to modify, save for the modeling anyway, and fun to play. One thing that really made it easy for me was how the development team had set up the game's engine with a good many additions to the basic C++ language... sadly the game's engine was never documented, the source code never released, and with the games outdating, became altogether forgotten.
Now that I have moved on from modding, and onto the much more advanced, and much more limitless hardcoding of C++, I still find myself more hendered by the language's system of variable information.
Although I do understand that it is necessary to be set up the way it is, I also realize that the additions of Tribes 1 could also be replicated, and used again in my C++ projects, and although I, with my limited experience with C++, do not fully understand how dynamix did what they did, I'm sure some one else out there can help me to 'decode' what they did...

(if you are still reading and are some how interested in helping me read the next post, and thank you for your interest so far)
Last edited by EvilIce : 01-Dec-2003 at 17:13.
  #2  
Old 01-Dec-2003, 16:37
EvilIce EvilIce is offline
New Member
 
Join Date: Dec 2003
Posts: 3
EvilIce is an unknown quantity at this point
OK, now onto my quandry itself:

See, the game was setup with greatly enhanced (in my opinion anyway) variable and function settings, for to create a function you did not need to go through all of the overloading and other miscellaneous menial task, you just simply named your function, and declared what the input would be called within the function... here is an example:

function newfunc(%var1,%var2)
{
//does something here!
}

-Notice how very similiar it is to C++ function declaring, but how it also differs, using modulus symbols in front of the variables, and no declaration of variable type. The only declaration needed for all of the coding, was either a modulus (%) or a Dollar sign ($)
to declare whether it is %local, existing only temporarily while the function is called, or $global, being assigned and/or changed at any time, but not deleted until told to be
-Also notice that function declaration name used is "function", I'm sure this is only a struct or something, and that it can't be too complicated to replicate, but I am not sure how to create a new "function" declaration type like this...
-The declared variables in the input of the function are also globally variable, since they have no int, float, or char declarations, the variables are all saved as string types, which are read as both string and number alike... this is by far the most useful aspect of this addition to C++ because I could VERY simply just send variables where I wished without worry of how it would be interpreted, and I would never have to worry about not having declared a variable in the first place...
-Finally notice how nothing internally is required to properly structure the function, and that all that is needed is a closing bracket (}) to end it

Now I know this sort of thing could be accomplished with major overloading of the struct function, but the "function" had infinite possibilities which allowed any random assortment of variables that I needed or desired, so it could be:
function(int, float, char[256], float, char, int, float, char[256])
or
function(float, int, char[256], char, char, int, float, float, int)
if I wanted, but that would be an INSANE amount of overloading, and I'm still not entirely sure as to how I should go about allowing the input of strings, because the variables input were, to my observation anyway, all in some sort of universal string format, and VERY VERY easy to use...

(still interested in helping me? I thank you from the bottom of my heart =) please read the next post)
Last edited by EvilIce : 01-Dec-2003 at 17:16.
  #3  
Old 01-Dec-2003, 17:04
EvilIce EvilIce is offline
New Member
 
Join Date: Dec 2003
Posts: 3
EvilIce is an unknown quantity at this point
Now I will continue with a true example:
CPP / C++ / C Code:
function Cannon::onCycle(%this)
{
	%Barrel = $Cannon[%this,Barrel];
	%pos = GameBase::getPosition(%Barrel);
	playSound($CannonSpinSound,%pos);
	Cannon::FX1(%Barrel);
}
That is a piece of code taken from a modification I made for Tribes1, and as you can see, the variable system is very easy to utilize, using the input variable %this, which is the ID of the Cannon (not location of a pointer or anything this is just a game ID number tag), I ask for the Global variable array $Cannon[%this,Barrel] because using this type of array, every cannon will have its own set of global variables called
$Cannon[IDhere,whateverelsehere]
using standard C++ syntax of coarse, closing the statement with a semicolon ( I then proceed to:
1) declare the local variable %Barrel which is deleted after the function ends
2) declare the local variable %pos treated in the same manner, and notice how "on-the-spot" these variables can be created? No precursors needed, just simple define them, and they then exist, and you don't even need to worry about clean up!
3) then I use a function defined else where by the engine to utilize my newly defined local variable, %pos, to play a .wav file at that position on the map (because %pos is a 3 value vector, defining the position on all 3 axis at the time it was assigned)
4) finally, I call on another function that I created else where, utilizing my newly created local variable %Barrel (which is the ID of the Barrel of the Cannon, because they are really seperate entities), to call on a whole new sequence of functions, initiating with the Barrel's ID as its input variable.

Now, here is another thing about it that is useful, but allows for confusion,

The name of the local variables are irrevelant when they are passed to another function, because they are sent as data, with no tag name, and then they are assigned, by the function they are sent to, to a new name... confusing? here's an example:
CPP / C++ / C Code:
function func1(%this)
{
    echo(%this);
    func2(%this);
}

function func2(%hello)
{
    echo(%hello);
}
Although a bit strange, both %hello and %this, are the same thing, because when %this is passed to func2, it is renamed to be %hello, so the name changes but the data does not, this I also found very useful...

That about covers the "function"s anyway, I really wish I knew how they made these things so I could use them myself on newer projects... please if anyone out there thinks they can help me, please let me know, who knows, you all might benefit as well from this?
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help to define a class in C++ yannoush C++ Forum 7 09-Sep-2003 01:28
Question about C and C++ pcxgamer C++ Forum 28 02-Sep-2003 15:20
Google Update and DeepCrawl Alert JdS Search Engine Optimization Forum 24 16-Aug-2003 06:35
[script] Password Protect web pages/site using PHP and MySQL JdS PHP Code Library 0 23-Jul-2003 11:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:23.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.