.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
koraX's utils
Old
  (#1)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default koraX's utils - 25-03-2005

so again something new :p

download
  • xml/cfg/ini parser
  • runtime profiler based on CPU cycles with low overhead (30 cycles)
  • 3d vector/position/angles, math stuff, compatible with HL SDK Vector class
  • loger to xml, redirecting cout
  • thread synchronization, thread creation
  • float variables comparsion, random number generator
  • ...more (detect CPU speed, string conversions, min-max, simple RGB class, ...)
  • ... and more (process and cpu id, ISO time and date format, ...)
  • all optimized for usage in hl plugins, but can be used anywhere
  • cross platform, tested undex MSVC.NET, DevC++, MinGW, gcc
  • open source, free, GPL with Half-Life exception
  • simple documentation and many examples
Just include source code into your program, include util.h in your .cpp and you can use everything. I'm using these utils in my bot and I consider them veery fast


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)

Last edited by koraX; 25-03-2005 at 00:32..
  
Reply With Quote
Re: koraX's utils
Old
  (#2)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: koraX's utils - 25-03-2005

just looking a bit thru it, looks nice

some suggestions : accordinging to some measurements I did quite some time ago, dividing all components by a factor is faster when you calculate 1/factor first and then multiply each of them, although this might be slightly less accurate due to floating point imprecisions, but this shouldnt be a problem with bot stuff at all. you did that already in the normalize function I see.

btw, and why isnt the RGB class derived from the vector class ? since then you had all arithmetrics stuff like + - whatever there too, which might be handy together with a clamp function.


  
Reply With Quote
Re: koraX's utils
Old
  (#3)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: koraX's utils - 25-03-2005

Quote:
Originally Posted by @$3.1415rin
btw, and why isnt the RGB class derived from the vector class ? since then you had all arithmetrics stuff like + - whatever there too, which might be handy together with a clamp function.
good point, I've done RGB class months ago and vector stuff is pretty new. But I like unsigned char for color, rather than floats


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote
Re: koraX's utils
Old
  (#4)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: koraX's utils - 25-03-2005

Nice! You know what I'm thinking ? Bots United should create and maintain a bot utilities DLL



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: koraX's utils
Old
  (#5)
sfx1999
Member
 
sfx1999's Avatar
 
Status: Offline
Posts: 534
Join Date: Jan 2004
Location: Pittsburgh, PA, USA
Default Re: koraX's utils - 25-03-2005

Who says it would need to be a DLL? It could just be headers.


sfx1999.postcount++
  
Reply With Quote
Re: koraX's utils
Old
  (#6)
Cpl. Shrike
ShrikeBot Coder/Moderator
 
Cpl. Shrike's Avatar
 
Status: Offline
Posts: 550
Join Date: Mar 2004
Location: The Netherlands
Default Re: koraX's utils - 25-03-2005

Darn if i just knew what yr talkin about ???
  
Reply With Quote
Re: koraX's utils
Old
  (#7)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: koraX's utils - 26-03-2005

Quote:
Originally Posted by koraX
good point, I've done RGB class months ago and vector stuff is pretty new. But I like unsigned char for color, rather than floats
then maybe write a "conversion" ctor or how those thingies are called


  
Reply With Quote
Re: koraX's utils
Old
  (#8)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: koraX's utils - 26-03-2005

this is from my bot, it isn't very "complicated" but may be enough for using in bots:
PHP Code:
/*
 * Copyright (c) 2004, Wei Mingzhi <whistler_wmz@users.sf.net>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (version 2 or any later
 * version) as published by the Free Software Foundation.
 *
 * [In other words, you are welcome to use, share and improve this
 * program. You are forbidden to forbid anyone else to use, share
 * and improve what you give them.]
 *
 * As a special exception, you have permission to link this program with
 * the Half-Life 1, as long as you follow the requirements of the GNU GPL
 * in regard to all of the software aside from HL1.
 */

//
// mathlib.h
//

#ifndef MATHLIBRARY_H
#define MATHLIBRARY_H

// Use this definition globally
#define ON_EPSILON        0.01
#define EQUAL_EPSILON     0.001

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#include <math.h>

#define FZero(v)       (fabs(v) < ON_EPSILON)
#define FEqual(v1, v2) (fabs((v1) - (v2)) < EQUAL_EPSILON)
#define SQUARE(f)      (f * f)

#pragma warning (disable: 4239)
#pragma warning (disable: 4244)

/**
 * This function adds or substracts 360 enough times needed to the given angle in
 * order to set it into the range [0, 360) and returns the resulting angle. Letting
 * the engine have a hand on angles that are outside these bounds may cause the
 * game to freeze by screwing up the engine math code.
 */
inline float AngleMod(float a)
{
   return (
360.0 65536) * ((int)(* (65536.0 360.0)) & 65535);
}

/**
 * This function adds or substracts 360 enough times needed to the given angle in
 * order to set it into the range [-180, 180) and returns the resulting angle. Letting
 * the engine have a hand on angles that are outside these bounds may cause the game
 * to freeze by screwing up the engine math code.
 */
inline float AngleNormalize(float angle)
{
   return (
360.0 65536) * ((int)((angle 180) * (65536.0 360.0)) & 65535) - 180;
}

// fast trig routine using inline assembly
void inline SinCosfloat radfloat *flSinfloat *flCos )
{
#ifdef __GNUC__
   // GNU style assembly, works with both GNU/Linux and MinGW
   
register double __cosr__sinr;
   
__asm __volatile__ ("fsincos" "=t" (__cosr), "=u" (__sinr) : "0" (rad));
   *
flSin __sinr;
   *
flCos __cosr;
#else
#ifndef _MSC_VER
   // don't use ASM as we're using some other compilers
   
*flSin sinf(rad);
   *
flCos cosf(rad);
#else
   // Microsoft style assembly
   
__asm {
      
fld DWORD PTR[rad]
      
fsincos
      mov edx
DWORD PTR[flCos]
      
mov eaxDWORD PTR[flSin]
      
fstp DWORD PTR[edx]
      
fstp DWORD PTR[eax]
   }
#endif
#endif
}

inline float AngleDifffloat destAnglefloat srcAngle )
{
   return 
AngleNormalize(destAngle srcAngle);
}

// 2D Vector
class Vector2D
{
public:
   
Vector2D() : x(0), y(0) {}
   
Vector2D(float afloat b) : x(a), y(b) {}
   
Vector2D(float *v) : x(v[0]), y(v[1]) {}

   
inline Vector2D operator-(void) const
   {
      return 
Vector2D(-x, -y);
   }

   
inline Vector2D operator+(const Vector2D &v) const
   {
      return 
Vector2D(v.xv.y);
   }

   
inline Vector2D operator-(const Vector2D &v) const
   {
      return 
Vector2D(v.xv.y);
   }

   
inline Vector2D operator*(float f) const
   {
      return 
Vector2D(ff);
   }

   
inline Vector2D operator/(float f) const
   {
      return 
Vector2D(ff);
   }

   
inline bool operator==(const Vector2D &v) const
   {
      return 
FEqual(xv.x) && FEqual(yv.y);
   }

   
inline bool operator!=(const Vector2D &v) const
   {
      return !
FEqual(xv.x) && !FEqual(yv.y);
   }

   
inline double Length() const
   {
      return 
sqrt((double)* (double)+ (double)* (double)y);
   }

   
inline double LengthSquared() const
   {
      return (double)
* (double)+ (double)* (double)y;
   }

   
inline operator float *()
   {
      return &
x;
   }

   
inline operator const float *() const
   {
      return &
x;
   }

   
inline Vector2D Normalize(void) const
   {
      if (
FZero(x) && FZero(y))
         return 
Vector2D(00); // reliability check

      
double l Length();
      return 
Vector2D(ll);
   }

   
float         xy;
};

inline double DotProduct(const Vector2D &a, const Vector2D &b)
{
   return (double)
a.* (double)b.+ (double)a.+ (double)b.y;
}

// 3D Vector
class Vector
{
public:
   
Vector() : x(0), y(0), z(0) {}
   
Vector(float afloat bfloat c) : x(a), y(b), z(c) {}
   
Vector(float *v) : x(v[0]), y(v[1]), z(v[2]) {}

   
inline Vector operator-(void) const
   {
      return 
Vector(-x, -y, -z);
   }

   
inline Vector operator+(const Vector &v) const
   {
      return 
Vector(v.xv.yv.z);
   }

   
inline Vector operator-(const Vector &v) const
   {
      return 
Vector(v.xv.yv.z);
   }

   
inline Vector operator*(float f) const
   {
      return 
Vector(fff);
   }

   
inline Vector operator/(float f) const
   {
      return 
Vector(fff);
   }

   
inline bool operator==(const Vector &v) const
   {
      return 
FEqual(xv.x) && FEqual(yv.y) && FEqual(zv.z);
   }

   
inline bool operator!=(const Vector &v) const
   {
      return !
FEqual(xv.x) && !FEqual(yv.y) && !FEqual(zv.z);
   }

   
inline double Length() const
   {
      return 
sqrt((double)* (double)+ (double)* (double)+
                  (double)
* (double)z);
   }

   
inline double LengthSquared() const
   {
      return (double)
* (double)+ (double)* (double)+
             (double)
* (double)z;
   }

   
inline double Length2D() const
   {
      return 
sqrt((double)* (double)+ (double)* (double)y);
   }

   
inline double LengthSquared2D() const
   {
      return (double)
* (double)+ (double)* (double)y;
   }

   
inline operator float *()
   {
      return &
x;
   }

   
inline operator const float *() const
   {
      return &
x;
   }

   
inline Vector Normalize(void) const
   {
      if (
FZero(x) && FZero(y) && FZero(z))
         return 
Vector(001); // reliability check

      
double l Length();
      return 
Vector(lll);
   }

   
inline Vector2D Make2D(void) const
   {
      return 
Vector2D(xy);
   }

   
inline void ClampAngles(void)
   {
      
AngleNormalize(x);
      
AngleNormalize(y);
      
0;
   }

   
// The purpose of this function is to convert a spatial location determined by the vector
   // passed in into an absolute Y angle (yaw) from the origin of the world.
   
inline float ToYaw(void) const
   {
      if (
FZero(x) && FZero(y))
         return 
0;
      else
         return 
atan2(yx) * (180 M_PI);
   }

   
// The purpose of this function is to convert a spatial location determined by the vector
   // passed in into an absolute X angle (pitch) from the origin of the world.
   
inline float ToPitch(void) const
   {
      if (
FZero(x) && FZero(y))
         return 
0;
      else
         return 
atan2(zLength2D()) * (180 M_PI);
   }

   
// The purpose of this function is to convert a spatial location determined by the vector
   // passed in into absolute angles from the origin of the world.
   
inline Vector ToAngles(void) const
   {
      
float yawpitch;

      if (
FZero(x) && FZero(y)) {
         
yaw 0;
         
pitch = (0) ? 90 270;
      } else {
         
yaw atan2(yx) * (180 M_PI);
         
pitch atan2(zLength2D()) * (180 M_PI);
      }

      return 
Vector(pitchyaw0);
   }

   
// This function builds a 3D referential from a view angle, that is to say, the relative
   // "forward", "right" and "upwards" direction that a player would have if he were facing this
   // view angle. World angles are stored in Vector structs too, the "x" component corresponding
   // to the X angle (horizontal angle), and the "y" component corresponding to the Y angle
   // (vertical angle).
   
inline void AngleVectorsVector *v_forward,
                             
Vector *v_right 0,
                             
Vector *v_up ) const
   {
      
float sp 0cp 0sy 0cy 0sr 0cr 0;
      
float angle * (M_PI 180);
      
SinCos(angle, &sp, &cp);
      
angle * (M_PI 180);
      
SinCos(angle, &sy, &cy);
      
angle * (M_PI 180);
      
SinCos(angle, &sr, &cr);

      if (
v_forward) {
         
v_forward->cp cy;
         
v_forward->cp sy;
         
v_forward->= -sp;
      }

      if (
v_right) {
         
v_right->= -sr sp cy cr sy;
         
v_right->= -sr sp sy cr cy;
         
v_right->= -sr cp;
      }

      if (
v_up) {
         
v_up->cr sp cy sr sy;
         
v_up->cr sp sy sr cy;
         
v_up->cr cp;
      }
   }

   
// This function returns the angle in degrees between the two vectors, regardless of
   // the axial planes (ie, considering the plane formed by the vectors themselves)
   
inline float AngleOf(const Vector &v)
   {
      
Vector v1 Normalize(), v2 v.Normalize();
      return 
acos((double)v1.* (double)v2.+ (double)v1.* (double)v2.+
                  (double)
v1.* (double)v2.z);
   }

   
float xyz;
};

static const 
Vector NULLVEC(000);

inline double DotProduct(const Vector &a, const Vector &b)
{
   return (double)
a.* (double)b.+ (double)a.* (double)b.+
          (double)
a.* (double)b.z;
}

inline Vector CrossProduct(const Vector &a, const Vector &b)
{
   return 
Vector((double)a.* (double)b.- (double)a.* (double)b.y,
                 (double)
a.* (double)b.- (double)a.* (double)b.z,
                 (double)
a.* (double)b.- (double)a.* (double)b.x);
}

// Returns if the specified point is inside the bounding box specified
// by origin, mins, maxs.
inline bool PointInsideBoundingBox(const Vector &point,
                                   const 
Vector &origin,
                                   const 
Vector &mins,
                                   const 
Vector &maxs)
{
   
float deltaX origin.point.x;
   
float deltaY origin.point.y;
   
float deltaZ origin.point.z;

   return (
deltaX >= mins.&& deltaX <= maxs.&&
      
deltaY >= mins.&& deltaY <= maxs.&&
      
deltaZ >= mins.&& deltaZ <= maxs.z);
}

// Returns if the specified two bounding boxes are touching each other.
inline bool BoundingBoxesTouching(const Vector &origin1,
                                  const 
Vector &mins1,
                                  const 
Vector &maxs1,
                                  const 
Vector &origin2,
                                  const 
Vector &mins2,
                                  const 
Vector &maxs2)
{
   return (
origin1.maxs1.>= origin2.mins2.&&
           
origin1.mins1.<= origin2.maxs2.&&
           
origin1.maxs1.>= origin2.mins2.&&
           
origin1.mins1.<= origin2.maxs2.&&
           
origin1.maxs1.>= origin2.mins2.&&
           
origin1.mins1.<= origin2.maxs2.z);
}

#endif 
warning: this hasn't been fully tested anyway so be aware of (possible) bugs

Last edited by Whistler; 26-03-2005 at 14:45..
  
Reply With Quote
Re: koraX's utils
Old
  (#9)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: koraX's utils - 26-03-2005

yep, that sincos asm stuff would be definately something to have on a 'bots united util lib'

although i'm not sure about that 2d vector, would it be missed if it wasnt there ?


  
Reply With Quote
Re: koraX's utils
Old
  (#10)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: koraX's utils - 26-03-2005

nice comments in Whistler's code

why not maintain this ASM stuff in the wiki ?



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."

Last edited by Pierre-Marie Baty; 26-03-2005 at 19:45..
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com