The online racing simulator
C++ Typedef & Variable Types
(8 posts, started )
C++ Typedef & Variable Types
Ok, so I manged to fix the 301 errors that come from byte, word, vec, and vector not being defined with these lines.

typedef unsigned char byte;
typedef unsigned short word;

typedef struct vec {
int x;
int y;
int z;
} Vec;

typedef struct vector {
float x;
float y;
float z;
} Vector;

Compiles without errors. I'm not sure why this information was not included with the InSim.txt file ...
I don't know why its not included, although my ideas are so you could do them yourself. 'byte' is commonly defined as unsigned char, but what it in some application they had defined it as char, first there would be errors of redefinition and second strange things might happen. Another possibility is that since InSim, OutSim and OutGauge work through sockets, it is language, compiler and platform independent so in C / C++

#define byte unsigned char

that is acceptable, where as in Visual Basic, Java? or other languages this may not be acceptable, so Scawen went the 'safe' route of just documenting the type and allowing the developer to do as needed. Although that said, maybe some languages don't allow struct { } or enum { } syntax... So I'm out of ideas for the moment but there you have it, it is what it is.

That said it is documented as far as what the types are and I am only speculating the reasons why they aren't defined.
Yeah, I'm using Visual C++ Express Edition, and I just downloaded it to start a project. I've not done a lot of C++ programming in my life (I would say less then 1000 lines of code seems like it would be about right as my cumulative total of C++ experience) So, I'm got to this point, included insim.h and got a load of errors (over 300) and I manged to fix it with some google searching. Thought this might be useful to other people as well. I also forgot to include this part tho:

typedef struct NodeLap NodeLap;
typedef struct CompCar CompCar;

For the vectors, IMO a template is the most elegant solution in C++:
#include <iostream>

template <class T>
struct Vector3
{
T x;
T y;
T z;
};

int main()
{
Vector3<int> myintvec = {10,20,40};
std::cout << myintvec.x << myintvec.y << myintvec.z << std::endl;
std::cin.get();
}

Quote from morpha :For the vectors, IMO a template is the most elegant solution in C++:
#include <iostream>

template <class T>
struct Vector3
{
T x;
T y;
T z;
};

int main()
{
Vector3<int> myintvec = {10,20,40};
std::cout << myintvec.x << myintvec.y << myintvec.z << std::endl;
std::cin.get();
}


I've never seen the template ... directive? ... before. Also Class T, and then using T as the datatype for x, y and z ... I'm guessing it takes the datatype from the Vector3<{$datatype}> part ...
Right.


template<typename T>
struct Vec
{
T x;
T y;
}

Then you declare Vec<float> mVectorOfFloats;

OR even

Vec<double> mVectorOfDoubles;
Vec<int> mVectorOfInts.

---------------------------------

In my opinion this is more flexible, however for the needs of InSim, where the type is defined as a 3, 4byte floating point values for a Vec., I would stick with;

struct Vec { float x; float y; float z; };

But, this is half-dozen one way to a half dozen the other. Just my opinion on the 'fixed' status of the packets types. No need to further complicate things by accidentally typing Vec<int> somewhere you meant for a float.
It's cool that's an option tho. I wonder how many little nuggets are in C++ ... I mean, I've not used it much, but there seems to be some very cool things in it. (I really wish I had buckled down sooner and started using C++, it would make my life so much easier right now.)
Oh there are tons more tidbits to it!

C++ Typedef & Variable Types
(8 posts, started )
FGED GREDG RDFGDR GSFDG