TresCom Forums
http://www.trescomforum.org/

Source-code discussion
http://www.trescomforum.org/viewtopic.php?f=133&t=8576
Page 1 of 1

Author:  RexHunter99 [ Tue Jul 06, 2010 3:08 am ]
Post subject:  Source-code discussion

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:
//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:
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;
};

Author:  makairu [ Tue Jul 06, 2010 3:23 am ]
Post subject:  Re: Source-code discussion

Nice! simple defining variables! Stuff I can almost understand. yay!

Author:  Draconisaurus [ Tue Jul 06, 2010 3:27 am ]
Post subject:  Re: Source-code discussion

Looking good at a quick glance...


(Mickey, quick reply? pretty please? :yum:)

Author:  RexHunter99 [ Tue Jul 06, 2010 8:27 am ]
Post subject:  Re: Source-code discussion

What can you guys spot? Heheheheh...

Code:
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 ;))

Author:  Mickey [ Tue Jul 06, 2010 3:00 pm ]
Post subject:  Re: Source-code discussion

Draconisaurus wrote:
(Mickey, quick reply? pretty please? :yum:)

Done :)

Author:  Slugger [ Tue Jul 06, 2010 8:26 pm ]
Post subject:  Re: Source-code discussion

Code:
//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?

Author:  machf [ Tue Jul 06, 2010 8:38 pm ]
Post subject:  Re: Source-code discussion

He isn't, he's just defining the equivalence between the labels and the numerical values...

Author:  RexHunter99 [ Tue Jul 06, 2010 9:37 pm ]
Post subject:  Re: Source-code discussion

Slugger wrote:
Code:
//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.

Author:  RexHunter99 [ Tue Jul 06, 2010 9:57 pm ]
Post subject:  Re: Source-code discussion

string class type definition:
Code:

#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++...

Author:  Dragonlord [ Wed Jul 07, 2010 8:11 pm ]
Post subject:  Re: Source-code discussion

What exactly are you trying to do here?

Author:  RexHunter99 [ Thu Jul 08, 2010 1:23 am ]
Post subject:  Re: Source-code discussion

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.)

Author:  Dragonlord [ Thu Jul 08, 2010 6:33 pm ]
Post subject:  Re: Source-code discussion

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

Author:  RexHunter99 [ Thu Jul 08, 2010 10:25 pm ]
Post subject:  Re: Source-code discussion

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.

Author:  Dragonlord [ Fri Jul 09, 2010 12:30 am ]
Post subject:  Re: Source-code discussion

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/