Page 1 of 1
Source-code discussion
Posted: Tue Jul 06, 2010 3:08 am
by RexHunter99
I'm okay with posting source-code in here for the new engine (it doesn't bother me) so people can criticize it constructively or add to it or do as they please
All source-code must and will be in C++ or C, and must be either commented or simple enough to understand it's purpose or happenings.
Definitions:
Code: Select all
//AI Constants, used in AIType property of Instances
#define AI_NONE 0
#define AI_PLAYER 1
#define AI_MEAT 2
#define AI_FOLIAGE 3
#define AI_WATER 4
#define AI_ANIMAL 5
#define AI_HUMAN 6
//ArchType Constants, used in ArchType property of CAnimal
#define ARCH_CARNIVORE 0
#define ARCH_HERBIVORE 1
#define ARCH_OMNIVORE 2
#define ARCH_CARN_DOCILE 3
#define ARCH_HERB_MEAN 4
//ActionType Constants, used in the ActionType property of CTrigger and it's siblings
/* Space is reserved... */
Cinstance Class:
Code: Select all
class CInstance
{
public:
float x,y,z; //3D Space co-ordinates
float xr,yr,zr; //Rotation angles in radians
float scale; //Scale of mesh
//Properties of the instance
BOOL Tangible;
BOOL Moveable;
BOOL Visible;
BOOL AI;
BOOL Planted;
BOOL AlwaysFace;
BOOL Bumpmaps;
BOOL Curved;
BOOL MipMap;
BOOL Reflect;
BOOL Refract;
BOOL Shadow;
BOOL Unlit;
BOOL Floats;
BOOL Frozen;
long AIType;
long AlphaChannel;
long Normals;
float AIMass;
float Damage;
float Height;
float Armour;
float Bumpiness;
float Diffuse;
float Emissive;
float RefractIndex;
float Specular;
float SpecularAngle;
float Density;
float Elasticity;
float Friction;
float Mass;
string Mesh;
string Physics;
string SoundMaterial;
string Type;
string Model00,
Model01,
Model02,
Model03,
Model04,
Model05,
Model06,
Model07,
Model08,
Model09;
};
Re: Source-code discussion
Posted: Tue Jul 06, 2010 3:23 am
by makairu
Nice! simple defining variables! Stuff I can almost understand. yay!
Re: Source-code discussion
Posted: Tue Jul 06, 2010 3:27 am
by Draconisaurus
Looking good at a quick glance...
(Mickey, quick reply? pretty please?
)
Re: Source-code discussion
Posted: Tue Jul 06, 2010 8:27 am
by RexHunter99
What can you guys spot? Heheheheh...
Code: Select all
class CAnimal
{
public:
string Name;
float x,y,z;
float xr,yr,zr;
float scale;
CMesh Mesh;
CMesh Collision;
long ArcheType;
long Team;
//1.0 = 1 metre;
float Width,
Length,
Height;
float ClawReach,
TailReach,
HeadReach,
FeintReach;
float MaxHitPoints;
float HitPoints;
float Mass;
float Danger;
float Anger,
Fear,
Hunger,
Thirst,
Curiosity,
Love,
Fatigue;
//========ACTIONS=========
//Movement
BOOL ActWander,
ActFlee,
ActDash,
ActPursue,
ActRearBack,
ActCircle,
ActFeint,
ActJump,
ActCrawl,
;
//Senses
BOOL ActLookAround,
ActStare,
ActSniff,
ActSniffTarget,
ActTaste;
//Other
BOOL ActEat,
ActDrink,
ActSleep,
ActWake,
ActHerd;
//Attacks
BOOL ActBite,
ActStomp,
ActRam,
ActTailSwipe,
ActSlash;
//Vocals
BOOL ActSnarl, //Make intimidating sounds
ActWhimper, //Make crying sounds
ActStalk, //Make stalking sounds (soft purring or breathing)
ActDying, //Make dying cries, is also animated
ActHowl, //Make chilling cries
ActBark, //Make curt, sharp barking sounds
ActRoar, //Make a scary bellow, may also perform animation
ActHelp; //Make a threatened call for help (alerts pack/herd/family)
};
The units of measurement are metric (metric scale is easier to program with, it's mathematically simple) so ClawReach = 1.0 means that this creature's claws can reach 1 metre away, and Mass = 1.0 means that this object/creature weighs 1 kilogram. I think that it would be possible to make the measurement system an option in the editors if necessary (as I know some people are more fond of Imperial system (I admit I gauge distance in feet and inches
)
Re: Source-code discussion
Posted: Tue Jul 06, 2010 3:00 pm
by Mickey
Draconisaurus wrote:
(Mickey, quick reply? pretty please?
)
Done
Re: Source-code discussion
Posted: Tue Jul 06, 2010 8:26 pm
by Slugger
Code: Select all
//ArchType Constants, used in ArchType property of CAnimal
#define ARCH_CARNIVORE 0
#define ARCH_HERBIVORE 1
#define ARCH_OMNIVORE 2
#define ARCH_CARN_DOCILE 3
#define ARCH_HERB_MEAN 4
Specifically numbers 3 & 4 -- why are you defining them thus instead of allowing TScripts to govern personality?
Re: Source-code discussion
Posted: Tue Jul 06, 2010 8:38 pm
by machf
He isn't, he's just defining the equivalence between the labels and the numerical values...
Re: Source-code discussion
Posted: Tue Jul 06, 2010 9:37 pm
by RexHunter99
Slugger wrote:Code: Select all
//ArchType Constants, used in ArchType property of CAnimal
#define ARCH_CARNIVORE 0
#define ARCH_HERBIVORE 1
#define ARCH_OMNIVORE 2
#define ARCH_CARN_DOCILE 3
#define ARCH_HERB_MEAN 4
Specifically numbers 3 & 4 -- why are you defining them thus instead of allowing TScripts to govern personality?
We have 0,1 and -1 in current Tres, 0 being Carnivore, 1 being Herbivore and -1 being a Carnivore who ignores Anne unless she annoys it, so why not expand upon it a little? Herbivores are generally docile and Carnivores are generally mean, so I added extra stuff in there to add greater weight to the Animal's actions.
Re: Source-code discussion
Posted: Tue Jul 06, 2010 9:57 pm
by RexHunter99
string class type definition:
Code: Select all
#include "string.h"
class string
{
public:
char *s;
string()
{
s = NULL;
}
~string()
{
if (s != NULL)
delete [] s;
}
inline operator char*(void)
{
return s;
}
inline void operator = (const char *str)
{
if (s != NULL)
delete [] s;
s = new char[strlen(str)];
strcpy(this->s,str);
return;
}
inline string& operator = (string &str)
{
return str;
}
inline string& operator + (string &str)
{
if (s != NULL)
{
char *s2;
s2 = new char[strlen(s)];
strcpy(s2,s);
delete [] s;
this->s = new char[strlen(s2)+strlen(str.s)];
strcpy(this->s,s2);
strcat(this->s,str.s);
delete [] s2;
}
return *this;
}
inline string& operator + (const char *str)
{
if (s != NULL)
{
char *s2;
s2 = new char[strlen(this->s)];
strcpy(s2,this->s);
delete [] this->s;
this->s = new char[strlen(s2)+strlen(str)];
strcpy(this->s,s2);
strcat(this->s,str);
MessageBox(0,s,"+",MB_OK);
delete [] s2;
}
return *this;
}
inline void operator += (const char *str)
{
if (s != NULL)
{
char *s2;
s2 = new char[strlen(this->s)];
strcpy(s2,s);
delete [] s;
s = new char[strlen(str)+strlen(s2)];
strcpy(this->s,s2);
strcat(this->s,str);
delete [] s2;
}
return;
}
inline void operator += (string &str)
{
if (s != NULL)
{
char *s2;
s2 = new char[strlen(s)];
strcpy(s2,s);
MessageBox(0,s2,"s",MB_OK);
delete [] s;
s = new char[strlen(str.s)+strlen(s2)];
strcpy(s,s2);
strcat(s,str.s);
delete [] s2;
}
return;
}
//--OPERATORS -- EVALUATIONS
inline BOOL operator == (const char *str)
{
if (strcmp(this->s,str)==0)
return TRUE;
else
return FALSE;
}
inline BOOL operator == (string &str)
{
if (strcmp(this->s,str.s)==0)
return TRUE;
else
return FALSE;
}
inline BOOL operator != (const char *str)
{
if (strcmp(this->s,str)==0)
return FALSE;
else
return TRUE;
}
inline BOOL operator != (string &str)
{
if (strcmp(this->s,str.s)==0)
return FALSE;
else
return TRUE;
}
};
I had to create this for the TScript engine, but gee it makes strings a helluva lot easier to use in C++...
Re: Source-code discussion
Posted: Wed Jul 07, 2010 8:11 pm
by Dragonlord
What exactly are you trying to do here?
Re: Source-code discussion
Posted: Thu Jul 08, 2010 1:23 am
by RexHunter99
Dragonlord wrote:What exactly are you trying to do here?
Recreate Trespasser from the ground up, using Trespasser's features as a base and expanding upon them (or in some cases removing them or simplifying them) I was actually going to ask you if you would mind venturing with me in this endeavour as your work is pretty damn cool on your own game engine.
As for this thread... I'm posting parts of the source code (actual processes are still coming so it's just classes and whatnot for now... but as you can see, I make heavy use of the inline keyword in my classes
there's a lot of functions written in headers.)
Re: Source-code discussion
Posted: Thu Jul 08, 2010 6:33 pm
by Dragonlord
Why not using an existing engine? Or is it for education purpose?
Concerning inlines... beware! Compilers are rather sophisticated and what's marked inline is not required to be inline. Furthermore smacking too much code into headers blows up binaries causing other kinds of problems if you are unlucky. Inlines should be only used on specific places, in general one-liners (getters). Function call overhead is in general very low. Add inlines to more complex functions only if profiling shows a real bottle neck and after you optimized the code logic first. I've seen even people forcing inlining complex functions. We call this "premature optimizations" and they are as bad as not optimizing at all
Re: Source-code discussion
Posted: Thu Jul 08, 2010 10:25 pm
by RexHunter99
Dragonlord wrote:Why not using an existing engine? Or is it for education purpose?
Concerning inlines... beware! Compilers are rather sophisticated and what's marked inline is not required to be inline. Furthermore smacking too much code into headers blows up binaries causing other kinds of problems if you are unlucky. Inlines should be only used on specific places, in general one-liners (getters). Function call overhead is in general very low. Add inlines to more complex functions only if profiling shows a real bottle neck and after you optimized the code logic first. I've seen even people forcing inlining complex functions. We call this "premature optimizations" and they are as bad as not optimizing at all
Other people's engines always tend to never be low-level enough for me, they lack the customization many of my ideas require.
Re: Source-code discussion
Posted: Fri Jul 09, 2010 12:30 am
by Dragonlord
RexHunter99 wrote:Dragonlord wrote:Why not using an existing engine? Or is it for education purpose?
Concerning inlines... beware! Compilers are rather sophisticated and what's marked inline is not required to be inline. Furthermore smacking too much code into headers blows up binaries causing other kinds of problems if you are unlucky. Inlines should be only used on specific places, in general one-liners (getters). Function call overhead is in general very low. Add inlines to more complex functions only if profiling shows a real bottle neck and after you optimized the code logic first. I've seen even people forcing inlining complex functions. We call this "premature optimizations" and they are as bad as not optimizing at all
Other people's engines always tend to never be low-level enough for me, they lack the customization many of my ideas require.
Good... then my engine goes the right way