The C Language

View previous topic View next topic Go down

The C Language

Post  bucket on Tue Oct 07, 2008 1:29 pm

I am wondering why C was the language used here. I am in the process of implementing the use of IPO curves into SIO2. I want to be able to have SIO2 handle IPO curves for lights, cameras, and meshes using the same code. This would work wonderfully if all three of these objects inherited the same base object. Only problem is that the way the C code is written each object cannot be handled with the same code becuase each object is different.

I am coming up with a solution that works around this C limitation but I am just wondering what decision caused you to use purely C.

bucket

Posts : 4
Join date : 2008-10-07

View user profile

Back to top Go down

Re: The C Language

Post  sio2interactive on Tue Oct 07, 2008 4:04 pm

Well for the IPO it is still pretty easy to implement. In example SIO2curve and after that simply add a SIO2curve* to the SIO2camera, SIO2object, SIO2light structure and that's it... I don't see why C++ should be used here...

The reason why C is mainly of speed and control... more low level you got more fast your code will run and well let's just say that I don't have the patience to write the code is ASM so I go for C Wink
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: The C Language

Post  bucket on Tue Oct 07, 2008 4:51 pm

Okay, just wondering why C was chosen. I can see the desire to have a speed boost. I hope I didn't come across like I was trying to pick out problems with the engine. Although it still has some development to go through, I find it to be really a great tool to build games with.

I don't want to sound like I am knit picking the engine but is performance the reason why loops are written like this.
Code:

i = 0;
while (i != cap)
{

    ++i;
}

instead of this
Code:

for (i = 0; i != cap; ++i)
{

}

bucket

Posts : 4
Join date : 2008-10-07

View user profile

Back to top Go down

Re: The C Language

Post  sio2interactive on Tue Oct 07, 2008 6:26 pm

Because when I profile with shark I found out that for was slower using a 32bit int than a while using the approach that I include everywhere... and probably faster to unroll as well... ++i is faster that i++ Wink while != give same performance as == and is faster than <, >, <=, >= of course comparison with 0 is the best but for loop well not really convenient... I mean think in ASM how you would code it... and you'll see that its kinda of obvious Wink

Another thing why C more than C++ is the constructor, with class you need to init all variable to 0 with C struct 1 line of code using calloc is good enough. Also to resize **, with class its a pain in the !@#!*@ to do so with C a simple realloc would do and this is use ALOT in a game engine, since practically every structure are dynamically generated in run time etc... I think also C is more clean in general, more short straight to the point and ANSI ISO 99 (what Im using) is compatible with every compiler on this planet (well almost Wink). All the library that Im using: OpenGL, OpenAL, jpeg, lua, zlib, theora, ogg are all in pure C only Bullet is C++, but its standard as well and cross platform so it's ok I think, but if the C API of Bullet where more developed and if Bullet can use fixed point math well SIO2 will be in heaven Wink

Theses are some of my thoughts and opinion, I don't want to start a debate thread here allright Wink
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

For performance

Post  kevinbutler on Thu Oct 16, 2008 3:22 pm

For performance, you should reverse the loop:

i = n;

while ( i )
{
--i;
}

That way you can do the comparison with 0.

But beware off-by-one errors, and careful if n == 0 to start...

kb

kevinbutler

Posts : 1
Join date : 2008-10-16

View user profile

Back to top Go down

Re: The C Language

Post  sio2interactive on Thu Oct 16, 2008 4:29 pm

Good suggestion Wink
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 38
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: The C Language

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum