Classes

Posted By: Alberto

Classes - 08/27/06 14:24

Hello

Is it possible to expose a C++ class to 3dgs cscript?
I mean :

- To create a class in C++
- To create an instance of the class
- To call a method from cscript

Thanks in advance
Posted By: ventilator

Re: Classes - 08/27/06 14:43

no, you can't directly expose classes. you will have to do non-object oriented wrapper functions.
Posted By: Alberto

Re: Classes - 08/27/06 23:00

Thanks

This is what I was concerned about

Can you still full exploit C++ power and \or flexibility ?

Or

Does your code get over complicated ?

It is just a question , actually I have never used a combination of C++ and scripting language till now
Posted By: Uhrwerk

Re: Classes - 08/28/06 11:26

Quote:

Does your code get over complicated ? I have never used a combination of C++ and scripting language till now



C-Script is not a comnination of c++ and a script. It is just a script language, having a very similiar syntax to c, and therefore even to c++. The big big difference is, that C++ is object oriented. C-Script isn't. That means you won't ever have things like encapsulation or inheritence. Of course this makes programming a little more complicated. Wit oop you can have a cleaner design and write more secure code.

Though it does not influence flexibility. You can do almost everything with c-script, but in my opinion you need some experience in order to write clear, stable and complex scripts.
Posted By: CBuilder2

Re: Classes - 08/28/06 13:37

Quote:

Thanks

This is what I was concerned about

Can you still full exploit C++ power and \or flexibility ?

Or

Does your code get over complicated ?

It is just a question , actually I have never used a combination of C++ and scripting language till now




Alberto,

I have attempted to do this. It just gets too messy and over complicated. The problem is the A6 architecture still only supports the "old school" Win32 API style dlls. If it actually supported COM, it would be much easier.

CBuilder
Posted By: Alberto

Re: Classes - 08/28/06 17:07

CBuilder

Thanks
Do you mean in general or just for accesing Directx methods ?
I would like to use C++ just for some AI applications ( FSM, neural.. etc)
For rendering, gameplay,collision etc I keep usinc cscript
What do you think ?
Posted By: CBuilder2

Re: Classes - 09/06/06 15:27

Quote:

CBuilder

Thanks
Do you mean in general or just for accesing Directx methods ?
I would like to use C++ just for some AI applications ( FSM, neural.. etc)
For rendering, gameplay,collision etc I keep usinc cscript
What do you think ?




Alberto,

I would create classes for all of the messy structures and API functions. So, one would not have to do the following:

myEnt.Pan+= INT2FIX(20);

Instead:

// In the class method, do the conversion under the hood.....
// To the outside world, it is an int.....
myEntClass.Pan+=20;

The big chunk of work is sitting down and figuring out a class structure; beyond that, most of the work is tedious wrapping of the structures and methods.

Finally, I would put it in a static LIB or DLL and just use it in your games. I just found it too messy. I really wish they had just used classes instead of functions and structures..... They did exist in C++ when the original A4 code was written.

Rich
Posted By: guanohead

Re: Classes - 09/12/06 10:55

You can use the SDK to setup a link between C++ DLL's and 3DGS. You can write classes as you wish in C++ and just have a REFERENCE member WITHIN the class to the entity pointer in 3D Game Studio. Finally, you write wrappers for whatever you want to do in C++ such as tracing and moving.

In this way, you can use 3DGS as a simple environment for testing out different AI and whatnot in C++.

It's a bit of work to learn and stup, but once you have that you can use the same base code for lots of different things. Check out the SDK!
Posted By: Alberto

Re: Classes - 09/15/06 19:04

Quanohead

It seems very interesting but I am not sure to have fully understood
Any example, tutorial available ?
Posted By: Game Wizard

Re: Classes - 09/15/06 21:02

You can create an mfc dll with all of your game logic in it using c++. The minimum script you need is 3 functions of about 3 statements each: for the main startup call, event handler, and the entity added calls. If you want, you can also subclass the main window in the dll and do your own windows event handling. It's not that hard if you have enough c++ and program development experience.
Posted By: guanohead

Re: Classes - 09/19/06 06:09

I apologize, here are a few links you can check out. It's not too hard if you know C++ pretty well.

The A6 SDK
This is a small set of libraries you can include in your C++ DLL project and use to communicate with 3D Game Studio. It also comes with sample source code that touches on most everything you can use the SDK for.

Basic tutorial
This is a simple tutorial that can help you get started.

Basically the idea is that, using this SDK, you can get pointers to entities that are in your 3DGS project, store those pointers in a c++ class and reference them when you want to make the entity do anything in 3DGS. You can also call ANY C-Script functions in C++ using this SDK, so entity manipulation is more or less as straightforeward as in C-Script.
You could, for instance, have a C++ member function:

DLLFUNC fixed walktowards(long entFocus)

and call it thusly:

entMyEntity->walktowards(entAnEntityPointer);

In this member function you could reference the object's pointer entity and have it turn towards the "entFocus" parameter (another pointer to an entity) and walk towards it.

I'm not at a computer I can test code on, so I can't give you an example at this time, but that tutorial above is pretty complete. Check it out. If things are not clear, let me know and I'll write out example some stuff for you.

Good luck.

BTW, the C++ project must be a DLL (to reference it in C-Script) however you don't need to use MFC, or even Visual Studio. The SDK comes with libraries for MinGW, Borland and other compiler/libraries.
Posted By: Alberto

Re: Classes - 09/22/06 19:12

Quanohead

Thanks, very kind of you
© 2024 lite-C Forums