Source-code discussion

No Longer Active! - The first TresCom Community Project - restoring and rebuilding the original game.

Moderators: tatu, scallenger, Rebel, Wajas

Post Reply
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Source-code discussion

Post 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;
};
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
User avatar
makairu
Gallimimus
Gallimimus
Posts: 635
Joined: Sun May 13, 2007 7:22 pm
Antispam: No
Location: Ohio, United States

Re: Source-code discussion

Post by makairu »

Nice! simple defining variables! Stuff I can almost understand. yay!
User avatar
Draconisaurus
T-Rex Killer
T-Rex Killer
Posts: 14032
Joined: Mon Dec 06, 2004 5:21 pm
Antispam: No
Location: Isla Sorna
Contact:

Re: Source-code discussion

Post by Draconisaurus »

Looking good at a quick glance...


(Mickey, quick reply? pretty please? :yum:)
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Re: Source-code discussion

Post 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 ;))
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
User avatar
Mickey
Dilophosaurus
Dilophosaurus
Posts: 2529
Joined: Sun Nov 10, 2002 9:58 pm
Location: England/Portugal

Re: Source-code discussion

Post by Mickey »

Draconisaurus wrote: (Mickey, quick reply? pretty please? :yum:)
Done :)
Image
Slugger
-=TresCom Developer=-
-=TresCom Developer=-
Posts: 4720
Joined: Sat Jun 12, 2004 6:52 pm
Antispam: No
Location: Atlanta

Re: Source-code discussion

Post 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?
0066521C: 'Cannot create local swap file - Is Trespasser installed??',0Ah,0
"Cold lino was the driving force behind world power!"
User avatar
machf
T-Rex Killer
T-Rex Killer
Posts: 12368
Joined: Thu Apr 24, 2003 11:20 pm
Location: Lima, Peru
Contact:

Re: Source-code discussion

Post by machf »

He isn't, he's just defining the equivalence between the labels and the numerical values...
Visit The Carnivores Saga - a forum devoted to modding Action Forms' Carnivores, Carnivores 2 and Carnivores: Ice Age games
Tres WIP: updated T-Script Reference and File Formats documents
Sound name listings for the Demo (build 117), Retail (build 116), Beta 103, Beta 99, Beta 97, Beta 96, Build 55, PC Gamer Alpha (build 32) and E3 1998 Alpha (build 22) TPA files
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Re: Source-code discussion

Post 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.
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Re: Source-code discussion

Post 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++...
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
Dragonlord
Compsognathus
Compsognathus
Posts: 1070
Joined: Fri Jan 04, 2008 12:14 am
Location: Switzerland
Contact:

Re: Source-code discussion

Post by Dragonlord »

What exactly are you trying to do here?
Image
Leader, Head Programmer: Epsylon | Drag[en]gine ( Wiki )
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Re: Source-code discussion

Post 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.)
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
Dragonlord
Compsognathus
Compsognathus
Posts: 1070
Joined: Fri Jan 04, 2008 12:14 am
Location: Switzerland
Contact:

Re: Source-code discussion

Post 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 :P
Image
Leader, Head Programmer: Epsylon | Drag[en]gine ( Wiki )
User avatar
RexHunter99
Albertosaurus
Albertosaurus
Posts: 2197
Joined: Mon Apr 24, 2006 12:12 pm
Location: Australia
Contact:

Re: Source-code discussion

Post 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 :P
Other people's engines always tend to never be low-level enough for me, they lack the customization many of my ideas require.
~ They told me humans weren't real... I proved them wrong.
ImageAnthropology ~ A beautiful tale.
EpicZen
Carnivores Hub ~ Need the full games without all the hassle of torrents or viruses? Run on over to EpicZen's Carnivores Hub!
Dragonlord
Compsognathus
Compsognathus
Posts: 1070
Joined: Fri Jan 04, 2008 12:14 am
Location: Switzerland
Contact:

Re: Source-code discussion

Post 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 :P
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 :P
Image
Leader, Head Programmer: Epsylon | Drag[en]gine ( Wiki )
Post Reply