C# wrapper 2.0 - RELEASE

Posted By: Stromausfall

C# wrapper 2.0 - RELEASE - 10/15/10 13:49

I'm proud to finally release an updated version of the C# wrapper for Acknex.

this version features, compared to the old c# wrapper, the following features (thanks to the many suggestions in the C# wrapper - REALESE thread) :

- no more var variables, only doubles or int
- no more NativeSTRING only normal string
- functions and variables are now commented
- works without unsafe code (no more allowing of unsafe code)
- a more object oriented approach
etc...


download the wrapper

or visit the homepage for some tutorials and how to use the wrapper !


P.S.:
oh and if anyone got more suggestions or notices any bugs, don't hesitate to post them here !
Posted By: 3dgs_snake

Re: C# wrapper 2.0 - RELEASE - 10/15/10 13:56

Wow! great work! got it!

Thank's.
Posted By: Stromausfall

Re: C# wrapper 2.0.1 - RELEASE - 10/15/10 17:55

a new version of the wrapper, some flags and some documentary was missing...


download the wrapper 2.0.1
Posted By: Joozey

Re: C# wrapper 2.0.1 - RELEASE - 10/16/10 19:51

Very nice update laugh thanks!
Posted By: Stromausfall

Re: C# wrapper 2.0.2 - RELEASE - 10/16/10 21:13

and again a new version ^^
fixed a bug where assigning EngineObjects to some EngineVar variables didn't work

here's the new version : wrapper 2.0.2
Posted By: MasterQ32

Re: C# wrapper 2.0.1 - RELEASE - 10/16/10 22:21

cool!
some very nice changes!
best thing is that you use double instead of the old Var!
It's easier than before and much clearer!
Thanks!
Posted By: ventilator

Re: C# wrapper 2.0.1 - RELEASE - 10/16/10 22:37

sounds great! but i don't have time to look into it at the moment. you could post some code examples. laugh
Posted By: Stromausfall

Re: C# wrapper 2.0.1 - RELEASE - 10/16/10 22:51

@ventilator, here's an example from the homepage..
the lambda usage still seams a bit awkward but without a doubt much better than the var solution (thanks again ^^)

Code:
using System;
using System.Collections;
using AcknexWrapper;

namespace panelExampleTwo
{
    class Program
    {
        private static PANEL testPanel = null;
        private static FONT testFont = null;
        private static BMAP background = null;
        private static BMAP knob = null;

        //the main method, called by the scheduler
        private static IEnumerable myMainMethod()
        {
            double dummyVariable = 0;

            //create an empty panel
            testPanel = PANEL.pan_create(null, 0);
            //make the panel visible
            testPanel.SHOW = true;

            //create a font
            testFont = FONT.font_create("Arial#40");

            //display the dummyVariable
            testPanel.pan_setdigits(
                0,
                200,
                400,
                "dummyVariable = %2.f",
                testFont,
                1,
                () => dummyVariable);

            //create a background
            background =
                BMAP.bmap_createblack(200, 50, 128);

            //create a knob
            knob =
                BMAP.bmap_createblack(25, 25, 32);

            //make the knob white
            knob.bmap_fill(
                new Color(255, 255, 255), 100);

            dummyVariable = 75;

            //create a slider which sets the dummyVariable
            testPanel.pan_setslider(
                0,
                50,
                50,
                background,
                knob,
                0,
                100,
                (double x) => dummyVariable = x,
                null);

            //activate mouse
            EngVar.mouse_mode = 4;

            yield return 1;
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //create/load an empty level
            EngFun.level_load(null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: ventilator

Re: C# wrapper 2.0.1 - RELEASE - 10/17/10 12:10

nice, that's a huge improvement! laugh

what i still would change is this:

testPanel = PANEL.pan_create(null, 0);
testPanel = new Panel(null, 0);

but that's a rather small thing...

edit:
and for the method names i would leave away the prefixes like pan_.
Posted By: Stromausfall

Re: C# wrapper 2.0.1 - RELEASE - 10/17/10 15:55

@ventilator
at first i also used constructors, but then i thought about, what happens if the creation of a engine object doesn't work - for example wrong path for a sound (which doesn't throw an error afaik) - the user wouldn't know and a c# object would still be created... and the other option would be to throw exceptions, but that's too much imho...
but i guess the difference is minimal and constructors might be better after all

i didn't think about leaving away the prefixes, it would look cleaner, but also a bit harder to trace back the class method to the acknex function for the user imho!
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/25/10 09:31

Hi,
The wrapper is really really great, thanks.
I wanted just to ask a question : Is there some reason why some functions are not included (ex : file_..., add_folder, add_resource, add_buffer, add_new, ...)? I was able to add some of them but just wondered why you didn't put them inside.

Best regards.

PS : I think that it is best to let the functions like they are, it is more easy to find them in the documentation.
Posted By: MasterQ32

Re: C# wrapper 2.0.1 - RELEASE - 10/25/10 14:00

i think you don't really need those file functions from Gamestudio!
Think about the classes of System.IO!
You have File Streams or read/write files directly with File.*
Directories you can create with Directory.*
So why use those file functions from Gamestudio if you have full file system power of .NET?
grin this is one of the really good things of the wrapper, you can use it for graphics only and for data and so you can use c#
Posted By: Stromausfall

Re: C# wrapper 2.0.1 - RELEASE - 10/25/10 21:08

yes, richi007 is right, for the file_ functions i thought about all the posibilities c# offers for file i/o !
hmmm i think i didn't add add_folder, add_resource etc because first, they aren't really necessary and second because i suspected them to be only usable in engine plugin, as they are under "// conversion and utility functions for the DLL interface" in the afuncs.h !
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/26/10 05:14

smile OK then for the file_* functions (I have already implemented some of them blush ). I have also implemented add_folder and it works well. I just wanted the add_buffer and add_resource but i think that they need the file_load function, or how can I do something similar?
Posted By: Stromausfall

Re: C# wrapper 2.0.1 - RELEASE - 10/26/10 08:13

hmmm I'm not really familiar with these functions... the easiest thing will be to just implement them, I'll try to upload a new version of the wrapper as soon as possible (most likely today) which implements these functions !
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/26/10 09:38

Thank's a lot, that is really very kind of you.

Best regards.
Posted By: Stromausfall

Re: C# wrapper 2.0.3 - RELEASE - 10/26/10 10:56

I've uploaded a new version of the wrapper, it adds most of the i/o, utility and dll functions that were missing !

get it here!
Posted By: 3dgs_snake

Re: C# wrapper 2.0.3 - RELEASE - 10/26/10 11:18

Wow! that was fast! many many thanks, you really did a good job!

Thanks again!
Posted By: Stromausfall

Re: C# wrapper 2.0.3 - RELEASE - 10/26/10 11:22

thanks grin
Posted By: Stromausfall

Re: C# wrapper 2.0.4 - RELEASE - 10/28/10 12:19

I've uploaded a new version, it fixes some bugs with the PATH_ objects and changes how PATH_ objects are built internally

get it here!
Posted By: ventilator

Re: C# wrapper 2.0.1 - RELEASE - 10/28/10 13:23

Originally Posted By: 3dgs_snake
PS : I think that it is best to let the functions like they are, it is more easy to find them in the documentation.
i don't think this is a good argument. tongue

how hard can it be to look for pan_setslider if you see that setslider is a method of panel objects? and a search function will find pan_setslider anyway if you enter setslider.

having a clean and non-verbose/non-redundant API should always come first.

ideally the wrapper should come with its own complete documentation since the usage of some functions will be quite different to lite-c. but i know that doing such a documentation would be a lot of (quite boring) work.
Posted By: Tempelbauer

Re: C# wrapper 2.0.1 - RELEASE - 10/29/10 07:55

does the wrapper works with A8 too?
i havnīt gamestudio installed, so i canīt test
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/29/10 08:05

Originally Posted By: ventilator
i don't think this is a good argument. tongue

grin (nice try!) You are certainly right, but like you say, it is a boring task so waiting for some motivation blush .

Best regards.
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/29/10 08:12

Originally Posted By: Tempelbauer
does the wrapper works with A8 too?


If you don't use physX then yes, it works ok (Stromausfall is correcting some little problems). But for physX support we will wait for Stromausfall to get A8(soon) smile .

Best regards.
Posted By: ventilator

Re: C# wrapper 2.0.1 - RELEASE - 10/29/10 10:51

he should ask jcl if he gets the upgrade for free or at least cheaper since this wrapper is really a big and important contribution to the community.
Posted By: 3dgs_snake

Re: C# wrapper 2.0.1 - RELEASE - 10/29/10 11:09

smile Yes, that would also be a good idea. I have also made a wrapper for A8, based on the A7 wrapper and with his precious help. It is working but like I said to him, I think that it is best to wait for his A8 Wrapper (It won't be long as he said) as he is good on maintaining his works ( grin Not like me ). If you want it, I can post it here next week while waiting for Stromausfall's A8 C# Wrapper.

Best regards.
Posted By: Stromausfall

C# wrapper 2.1.0 - RELEASE - 10/29/10 20:30

@ventilator your're quite right about the documentation esepcially about how much boring work it would involve ^^
And as I don't plan to really create a real documentation I also don't plan to create a api which isn't that blatantly based on the lite-c api, because an own documentation would be needed for it - and that's too much work imho - like you said ^^



I was already able to update the wrapper :

The new version supports
-A8 and A7 (you can switch the wrapper to support A7 through adding 'A7_WRAPPER' to the 'Build>Conditional compilation symbols' property in Visual Studio)
-most of the on_ engine variables now use an 'EventHandler' in whose list you can add (and of course also remove) all functions which should be called when the event fires
-additionally some bugs in the Material engine object were fixed (thanks 3dgs_snake ^^)!

here's the link :

AcknexWrapper_8_0_3_2__2_1_0.zip (update : don't download this version, it has a serious bug when an entity is removed (endless loop) !)
Posted By: Stromausfall

C# wrapper 2.1.1 - RELEASE - 10/30/10 22:24

this update fixes a critical bug with on_ent_remove and lets all engine objects inherit from a new EngineObject class which offers the Equals Method and operator overloading for == and !=, which allows for example that two entity objects which point to the same entity are 'equal'

here's the link :

AcknexWrapper_8_0_3_2__2_1_1.zip
Posted By: Tempelbauer

Re: C# wrapper 2.1.1 - RELEASE - 10/30/10 23:38

thanks for the new version laugh

but i have a small problem with it (with all versions i tried).
i want to embed the engine into a panel of a winform-window in .net2.0 (like a control). for this i use a code-snippet posted long ago by DJBMASTER: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=280835#Post280835
this snippet works, but not very well: over the whole winform-window the hand-cursor is forced at every frame. the result of this is a ugly flicker of the cursor (because every frame the default-cursor will be replaced by the hand-cursor).
furthermore there is a problem with the dockpanel-suite (by weifenluo): i canīt dock anything while the engine is running.

does anyone know how to fix this problems or a work-around?
thanks

Posted By: DJBMASTER

Re: C# wrapper 2.1.1 - RELEASE - 10/31/10 00:17

@Tempelbauer, this issue can be solved by running the engine in a new thread.
Posted By: Tempelbauer

Re: C# wrapper 2.1.1 - RELEASE - 10/31/10 00:55

many thanks, djb laugh
now it works perfectly
Posted By: Stromausfall

Re: C# wrapper 2.1.2 - RELEASE - 10/31/10 09:07

this update fixes a bug in the EngineObject (which resulted in a wrong counting of references)

here's the link :

AcknexWrapper_8_0_3_2__2_1_2.zip
Posted By: Stromausfall

Re: C# wrapper 2.1.3 - RELEASE - 11/02/10 13:31

this update includes (big thanks to 3dgs_snake):
- fixes a bug were assigning null to some EngineObject EngineObject properties resulted in a crash
- moved all vector and angle functions to VectorBase and change the Parameters to VectorBase which allows to use these functions with all class which are derived from VectorBase (Vector, Color and Angle)
- constructors of EngineObjects changed from private to protected
- added the ReferenceStorage class which allows to store a reference to an object in an integer, thus allowing to store a object in for example ENTITY.skill50

here's the link :

AcknexWrapper_8_0_3_2__2_1_3.zip
Posted By: 3dgs_snake

Re: C# wrapper 2.1.3 - RELEASE - 11/02/10 13:37

crazy You are really fast at doing things! How many hands do you have? Or do you use some magic keyboard and mouse grin ?

I'll get it now and make some test, perhaps we have here the best wrapper of all?

Thanks for your work!
Posted By: maslone1

Re: C# wrapper 2.1.3 - RELEASE - 11/02/10 18:11

Thanx a lot for your great contribution!
Posted By: Stromausfall

C# wrapper 2.1.4 - RELEASE - 11/03/10 20:27

and again a new version ^^
this update includes:
- added + and - operator for eventHandlers
- changed return type of file_length from double to int
- changed return type of file_load from IntPtr to String

here's the link :

AcknexWrapper_8_0_3_2__2_1_4.zip
Posted By: maslone1

Re: C# wrapper 2.1.4 - RELEASE - 11/03/10 20:58

grin thanx again! laugh
Posted By: Rei_Ayanami

Re: C# wrapper 2.1.4 - RELEASE - 11/15/10 20:37

Hello laugh

I have tried your wrapper, and I really like it.
But I have a problem (maybe it's because of my stupidness and because I just started with C#...)...
However, if I embed my window in a Form(with the tut on your site), I cannot really create entities because I get an AccesViolationExeption in engine_frame (Reading/Writing protected memory areas), this seem to happen only with some models, though.

Any ideas why?
Posted By: Stromausfall

Re: C# wrapper 2.1.4 - RELEASE - 11/15/10 22:38

i guess that's most likely because you press a button or something in your form and then you create there the entity, but this leads almost inevitably to problems, as functions may only be called when the engine is no in the engine_frame or any other engine function ^^
thus the proper way to create an entity or interact with the entity from another thread - thus in the function of your button is the following (like in the example on the homepage) - should be
Code:
private void changeTextButton_Click(object sender, EventArgs e)
{
    //add this function THREAD SAFE to the scheduler
    Scheduler.AddEventVoidThreadSafe(createEntity);
}
static ENTITY dummy = null;
private IEnumerable changeText()
{
    dummy = ENTITY.ent_create("some entity", new Vector(), null);
    yield return 1;
}


if this doesn't work for you - send me the part of your project or a small example project were this happens and I'll have a look at it !
Posted By: Rei_Ayanami

Re: C# wrapper 2.1.4 - RELEASE - 11/16/10 15:59

Ahr, thanks, my fault. I knew the thing with the Scheduler, but I just wrote AddEventVoid and forgot the ThreadSafe ^^

Thanks, I really like the wrapper laugh
Posted By: gri

Re: C# wrapper 2.1.4 - RELEASE - 12/02/10 13:55



@Stromausfall,

is your C# wrapper going to be the "official" Version for 3DGS ?

Youre in contact with Conitec in this and your software will be included in a future engine release?

I ask because somethere in Forecast of 3DGS I did read about an offical C# Wrapper and would like to know if yours become this.


regards,
gri
Posted By: Stromausfall

Re: C# wrapper 2.1.4 - RELEASE - 12/03/10 14:21

hmmm that's a good question...
I don't think that the c#, python or delphi wrapper are official wrappers for 3dgs..
Because if you have a problem with them you can't ask Conitec for help - thus i think they are not 'official'.
And i personally also wouldn't know that this wrapper is the 'offical' c# wrapper ^^
Posted By: Stromausfall

Re: C# wrapper 2.1.5 - RELEASE - 12/08/10 00:13

a new version was uploaded (only minor changes)
this update includes:
- ent_status changed from "static ent_status(entity, double)" to "ent_status(double)",
- engine_debugposition -> changed the scriptname paramter from IntPtr to String,
- added fsin, fcos, ftan, fasin, facos, fatan (thanks pararealist ^^)

here's the link :

AcknexWrapper_8_0_3_2__2_1_5.zip
Posted By: Stromausfall

Re: C# wrapper 2.1.5 - RELEASE - 12/14/10 17:11

a new version was uploaded
this update includes:
- changed inheritance structure, added DataObject and ActorObject (shouldn't be noticeable !)
- valid variable add (if false the entity has been invalidated)
- link added, C_LINK added - the link variable in combination ptr_first allows to traverse all objects of a certain type
- ptr_first added to the EngFun class
- ptr_remove now invalidates all instances of the engine object
- level_load invalidates all entities but 'view-entities' (thanks pararealist ^^)

here's the link :

AcknexWrapper_8_0_3_2__2_1_6
Posted By: Stromausfall

Re: C# wrapper 2.1.7 - RELEASE - 12/20/10 20:16

a new version was uploaded
this update includes:
- fixed a bug in the ActorObject.cs file
- layer_sort can now additionally be called directly as a function (it is also called when a value is assigned to the layer variable !)
- added AddEventObject, AddEventObjectThreadSafe

here's the link :

AcknexWrapper_8_0_3_2__2_1_7
Posted By: Frederick_Lim

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 03:32

Originally Posted By: gri


@Stromausfall,

is your C# wrapper going to be the "official" Version for 3DGS ?

Youre in contact with Conitec in this and your software will be included in a future engine release?

I ask because somethere in Forecast of 3DGS I did read about an offical C# Wrapper and would like to know if yours become this.


regards,
gri


Where is the C# wrapper in the forecast page?

And I believe the C# should be execute faster than lite-C, if offical C# wrapper released, that implicate it is the end of lite-C.
Posted By: the_mehmaster

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 03:41

Quote:
Where is the C# wrapper in the forecast page?


It was there a couple of weeks ago, I can confirm.
JCL must have taken it off for some reason...

Also, lite-c was the main 'feature' of a7, I reckon if the wrapper WAS made official, it would be an optional language.
Posted By: Spirit

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 06:05

Stromausfall's wrapper was always the official C# wrapper for A7 and A8, its on the download page since many years. I dont think Conitec had another wrapper on forecast.
Posted By: the_mehmaster

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 06:20

Quote:
Stromausfall's wrapper was always the official C# wrapper for A7 and A8, its on the download page since many years. I dont think Conitec had another wrapper on forecast.


Yes, but I'm pretty sure I saw it on the forecast page as well, might have been only for a day or two as it was taken down shortly after. strange...
Posted By: Tempelbauer

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 09:57

i donīt think that jcl will develop an own c#-wrapper, even if it was on the forecast. thereīs no reason to do this. stromausfallīs wrapper does a great work. and on the other hand, if they develop an own c#-wrapper why not an own ackwii-plugin (the current was developed by firoball)?
Posted By: the_mehmaster

Re: C# wrapper 2.1.4 - RELEASE - 12/21/10 10:15

I'm pretty sure the one I saw on forecast WAS Stromausfall's wrapper. wink
Posted By: Stromausfall

Re: C# wrapper 2.1.8 - RELEASE - 01/02/11 13:30

a new version was uploaded
this update includes:
- update to 8.10
- engine extern Vector method vec_compareValues added, returns true if the values of the two vectors are equal
- engine extern Vector method vec_copy added, creates and returns a copy of the Vector/Color/Angle/VectorBase/PATH_EDGE (doesn't use the same memory, but has the same values)
- Vector xyz, Vector nxnynz, Vector x3y3z3 removed from D3DVertex, because D3DVertex doesn't use Var but Float !
- c_updatehull added

here's the link :

AcknexWrapper_8_10__2_1_8.zip
Posted By: DJBMASTER

Re: C# wrapper 2.1.8 - RELEASE - 01/02/11 13:57

Hey Stromausfall, I haven't used C# with acknex in a while, good to see you're still developing it smile.

For the vec_compareValues and vec_copy features you've added;

I think it would be more OOP friendly to implement the IComparer interface to perform comparisons.

Also for the vec_copy method, IMO it's better to implement ICloneable, and in the 'Clone' method, serialize the object into a MemoryStream and return the new object.

Just my thoughts, don't mean to trash your design implementations, it's great as always wink
Posted By: Stromausfall

Re: C# wrapper 2.1.9 - RELEASE - 01/02/11 18:27

@DJBMASTER
Big thanks for the design tips ! IComparer seems to be really better ! I also implemented the ICloneable interface for the vectors, although i also implemented a copy constructor for the vectors as the clone method always returns a object and thus a cast is always required (the copy constructor solves this issue)!

a new version was uploaded
this update includes:
- vec_compareValues removed
- Vector/Color/Angle/VectorBase/PATH_EDGE now implement the IComparable<T> interface, thus CompareTo can be used (0 if the two objects have the same value)
- vec_copy removed
- Vector/Color/Angle/VectorBase/PATH_EDGE now implement the ICloneable interface
- Vector/Color/Angle/VectorBase/PATH_EDGE now have a copy constructor
- All EngineObjects now implement the IEquatable<t> interface (doesn't change anything, because equals and GetHashCode were already implemented...)

here's the link :

AcknexWrapper_8_10__2_1_9.zip
Posted By: Stromausfall

Re: C# wrapper 2.2.0 - RELEASE - 02/15/11 19:05

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
additonaly a shader example, a bones example and a how to load lite-c scripts in C# example and a list of lite-c functions with their c# counterparts was added to the homepage
the update of the wrapper includes:

- return type of engine_getscript changed to IntPtr
- smooth function was accidently named accelerate - fixed
- return type of floatv, floatd, floatr changed to Int32
- vec_for_vertex, called vec_for_normal instead of vec_for_vertex - fixed
- mat_scale, removed Matrix argument (unnecessary as the method is an instance method)
- changed return type of bmap_to_uv from IntPtr to BMAP
- return types of bmap_unlock, bmap_blit, bmap_blitpart, bmap_zbuffer changed from void to double
- bmap_process was implemented
- pixel_for_vec, pixel_to_vec moved from static BMAP methods to instance methods of VectorBase
- return type of engine_open changed from void to bool (indicates whether the engine_open call was successful)
- MATERIAL/ENTITY skills now have a raw_skills equivalent which allows to directly save Integer (important for Shaders!)
- c_ignore changed from an instance method to a static method
- video_border - documentation was added
- send_data_id function was added
- execute function was added

here's the link:

AcknexWrapper_8_10_2_2_0.zip
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/03/11 23:56

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- methods for schedulers now have IEnumerable<ScheduleMethod> as return type instead of IEnumerable !
- instead of PROC_MODE.EARLIEST -> ScheduleMethod.PROC_EARLIEST
- yield return Schedule.wait(x) is now the equivalent to lite-c wait(x)
- SchedulerEnabled removed
- Scheduler code revised
- Scheduler.StartScheduler(EventObject, object) added
- ent_createterrain -> if position wasn't null an exception was thrown -> bug fixed
- execute -> FreeHGlobal was called twice -> caused an exception -> bug fixed
- var_for_name added
- Scheduler.ThreadExecutingTheScheduler - returns the thread that executes the scheduler

here's the link:

AcknexWrapper_8_10_2_2_1.zip


ATTENTION :
as mentioned this update changes how PROC_MODE is changed and the return type of functions which are called by the scheduler (this is a quite significant change, but it allows the yield return calls to be far safer (as only allowed variables/objects can be returned) and the speed of the Scheduler is improved as the previous constant casting has now been removed)!
thus :

Code:
private IEnumerable bla()
{
yield return 1;
}


now becomes :
Code:
private IEnumerable<ScheduleMethod> bla()
{
yield return 1;
//or: yield return ScheduleMethod.wait(1);
//or: yield return ScheduleMethod.waitForFrames(1);
//ALL these three calls are equivalent !
}


and
Code:
private IEnumerable bla()
{
yield return 1;
yield return Scheduler.PROC_MODE.PROC_EARLIEST;
yield return 1;
}


now becomes :
Code:
private IEnumerable<ScheduleMethod> bla()
{
yield return 1;
yield return ScheduleMethod.PROC_EARLIEST;
yield return 1;
}


Posted By: MasterQ32

Re: C# wrapper 2.2.1 - RELEASE - 03/04/11 20:51

some question:
is it normal that Panels pos_x, size_x and so on are double, but Texts pos_x, ... are int??
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/04/11 22:36

yes, that's an inconsistency..I will fix that in the next update (all double instead of int), but it's not that critical i guess !
Thanks !
Posted By: pararealist

Re: C# wrapper 2.2.1 - RELEASE - 03/15/11 17:00

Hi matthias,
for some reason the update does or is not working as shown in your update examples?

Code:
After adding AW 2.21 get ERROR:

error CS0308: The non-generic type 'System.Collections.IEnumerable' cannot be used with type arguments


using:
private IEnumerable<ScheduleMethod> myMainMethod() //ERROR:
{

	//....
       //yield return 1;
       yield return ScheduleMethod.wait( 1 );

}

and:
        private IEnumerable<ScheduleMethod> SizeWindow() //ERROR:
        {
            /*wait until the form is being resized*/
            while (ResizingNow == false)
            {
                //yield return 1;
                yield return ScheduleMethod.wait( 1 );
            }
            /*change the resolution*/
            EngFun.video_window(null, new Vector((this.panel_acknexWindow.Width),
                                                  this.panel_acknexWindow.Height, 0), 0, null);
            IsChangingSize = false;   //reset flag
            //yield return 1;
            yield return ScheduleMethod.wait( 1 );
        }



I re-downloaded AW from your page, and tried again, but get the same error as above:
Have i missed anything else that has changed?
Or am i missing something?
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/15/11 17:02

hmm it looks like you haven't included System.Collections.Generic
in which example did this error occur ?
Posted By: pararealist

Re: C# wrapper 2.2.1 - RELEASE - 03/15/11 17:11

Its in my app, but System.Collections.Generic
could well be the cause if that is a new requirement,
as i may well not have that included in my main.cs.
Will try this in about 5 mins as i am not at home.
thanks for quick reply.
Posted By: pararealist

Re: C# wrapper 2.2.1 - RELEASE - 03/15/11 17:28

It seems that was needed.
Thanks again.
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/15/11 17:41

Glad it worked ^^
Posted By: monotonic

Re: C# wrapper 2.2.1 - RELEASE - 03/19/11 11:57

Hi,

I'm new to 3DGS and will be purchasing the Commercial version on Friday next week (when I get paid). I will be using your C# wrapper as I've been using C# for many years now so feel comfortable with it.

I will be writing the main game code in C# and scripting objects with Lite-C. I have seen that I can call Lite-C functions within my C# code, which is fantastic, now my question is can I call my C# functions from within Lite-C. I have though of a way that I could get around it if not, I will use a queue, which I will add calls/params to then parse this from within C#. However it woulf be infinitely nicer if I could directly call the functions.

Thanks in advance.
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/19/11 13:49

Hmmm yes, this should be possible i guess, because C# functions are called from the engine, for example in ent_create or when events occur !

But I don't really see a need for lite-c if you use C# ! The only thing were you really need (from what i know) lite-c instead of C# is for declaring bitmaps which you use in shader (at least i know of no workaround for this..). You can also access all engine objects like entities and modify them in C#, the wrapper also has a scheduler, similar to the one in lite-c !
Did you have a look at the examples at the wrapper homepage ? http://acknexwrapper2.matthias-auer.net/

If you got more questions don't hesitate to post or e-mail them !
Posted By: monotonic

Re: C# wrapper 2.2.1 - RELEASE - 03/19/11 18:27

Hi,

What I'm planning on doing is writing the main code in C# then for things like AI behaviour I was going to use Lite-C as the scripting language to save me from recompiling every time I tweak the behavioural script. This is how I've done it in the past but with LUA or something similar.

What method do you use for calling managed functions from within Lite-C?

Yeah I've looked at the examples on your site, they were very informative. I would like to extend my gratitude to you for creating this wrapper it is very useful.
Posted By: DJBMASTER

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 03:52

I think you'll have to make a choice - either C# or lite-c laugh mixing them isn't possible. 'acknex.dll' is the heart of the engine which C# uses, so I can't see any reason why you would want to call lite-c functions.

You can of course write a lite-c parser which converts lite-c code to C# wrapper code.
Posted By: monotonic

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 07:20

Hi,

It is possible I have already got the process for calling Lite-C from C# resolved and the process for Lite-C to C# calls is something that I have a method of doing but would like to improve it.

The reason I'm wanting to use a scripting language as well as C# is that after many years of being a professional developer I have learnt that hard coding things that are likely to change is a bad idea.

I was thinking that I could just use C# as my scripting language and compile the scripts at runtime, but I would prefer to use Lite-C for this.
Posted By: ventilator

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 07:49

lite-c is a c compiler, not an interpreted language like lua.

if you use c# and additionally want a real scripting language then you could combine it with something like ironpython, lua.net,...
Posted By: monotonic

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 08:35

Hi Ventilator,

Yeah this is what I've been contemplating over the past day or so. The reason why I'm trying to figure out if Lite-C is suitable for my needs is that the functionality is already there for me to load and call the functions within LC code from C#. Now if I interface with LUA or something similar it would require me integrating it (not a difficult task I know, but still a task none the less). Thus using LC would save me time, plus LC obviously already has full integration with all the engine functionality, whereas LUA does not and it would require me to implement this functionality myself.

I'm aware that LC is not a "scripting" language, I'm trying to figure out if it would lend itself to my needs or not. I have several options, I could use dynamically compiled C# code as my script, LUA or Lite-C.

To be honest I will probablly go with C# for the scripts, but I thought I would just ask you kind people for your input because you have far more experience with 3DGS than I.

Thank you for your help guys and sorry for derailing this thread a little smile
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 08:58

I've uploaded an example which shows how you can call a C# function from lite-c, here's the link to the downloadable project link

i too think that using c# for the scripts is most likely easier than using lite-c!
Posted By: Dark_samurai

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 09:27

Is a game written in C# using gamestudio faster or slower than writing it in lite-c?
A small test would be cool (a huge crowd of entities that perform a function).
Posted By: ventilator

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 10:01

yes, would be interesting. i don't think there is much difference though. lite-c isn't a very optimizing c compiler.
Posted By: monotonic

Re: C# wrapper 2.2.1 - RELEASE - 03/20/11 19:31

@Stromausfall

Thank you very much laugh I will have a play around and see what I can do. I have noticed though that you (or at least I believe) can only load one script when opening the world as opposed to loading scripts at will. If this is the case then I will have to go with C# as the scripting language.
Posted By: Dark_samurai

Re: C# wrapper 2.2.1 - RELEASE - 03/24/11 20:46

I finally had time to look into your wrapper. I love it!

One bug I noticed:
The ent_nextvertex() method of the ENTITY class doesn't work if null is passed for the first parameter (contact). Although this is possible in Lite-C!

The most interesting example was the embedded engine window example. One problem I noticed is, that even if the parent window (the window the engin is embedded in) is active, I need to click into the engine window so that acknex detects my key strokes.
Is it possible to activate the engine window when the parent window is active?
I also didn't managed to get resizing of the engine window with the parent window to work... The panel is resizing correct. In the resize event of the panel I tried to change the engine resolution to the current panel size... without an effect (I used the threadsafe event of your scheduler of course).

Really great work!
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/24/11 21:05

@Dark_samurai
thank you! I'll fix that bug in the next update !
about the embedded engine window - I've noticed that too ! If i find some time I'll look into this !
Posted By: DJBMASTER

Re: C# wrapper 2.2.1 - RELEASE - 03/24/11 21:29

For the window stuff...

To resize the engine to the resolution of the container, overload the WndProc and catch WM_RESIZE, then pass the call onto the engine grin Handling the 'Resized' event of a .NET control would also do grin

As for the keystroke stuff, It's something I have been trying to resolve for some time. This is a consequence of the SetParent call, as I've seen this behaviour in other apps unrelated to GameStudio. I think the function 'AttachThreadInput' may hold the key grin

A workaround is to simply overload the container WndProc, catch any WM_KEYDOWN, etc messages, and pass them onto the acknex window handler grin

good luck grin
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/24/11 23:46

experimented a bit and came to the same conclusion as DJBMASTER ^^
works pretty good, but as DJBMASTER wrote, WndProc has to be overloaded smirk
It would be interesting to see how mouse interaction works with this method !
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/25/11 23:28

I've experimented with the original method of embedding the window and after quite some time found a way to resize the window and also give the impression/(or even manage ^^) that the focus is correctly switched according to the mouse position and the status of the main form....
It uses some dirty tricks, but should works quite good (at least it does on my pc ^^)

ImprovedEmbeddedWindow.zip
Posted By: Dark_samurai

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 12:19

Wow thank you very much!

Resizing works already perfect!

But I noticed a problem with the focus thing. If the main form creates a dialog that is placed over the engine window, you will be unable to click a button in this dialog.
Another problem of this solution is, that the mouse has to be over the engine window so that key strokes are recognized. I think I will use the keydown event of the form and forward the key strokes to the engine window if the mouse isn't over the window.
Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 15:11

>>But I noticed a problem with the focus thing. If the main form creates a dialog that is placed over the engine window, you will be unable to click a button in this dialog.


lol yeah that's indeed a problem, to fix this the dialog would have to somehow register itself to the focus handling piece of the code...

yepp the other solution is far easier in this regard ^^
Posted By: DJBMASTER

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 18:34

Stromausfall - did you ever use/look into 'AttachThreadInput'. I'm sure this is the right way to do this. It will attach the engine thread to the window thread, so any input registered on the window, will automatically transfer to the engine handler.
Posted By: Dark_samurai

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 18:45

I have a question regarding to the scheduler and time_step:
In Lite-C we have to multiply things like the camera speed with time_step so that the speed is framerate unrelated. But I converted my camera code to c# and now it moves slow as hell. --> is SchedulerMethod.wait(1); some kind of slower than wait(1) in Lite-C?

Code:
private IEnumerable<ScheduleMethod> myMainMethod()
{
   //...
   while (true)
   {
      CameraFunc();

      //HeavyFunc();

      yield return ScheduleMethod.wait(1);
   }
}

void ShowEditorCam()
{
   EngVar.Camera.x += 5 * time_step;
}



Another thing I notice, if a function that does heavy calculations is also called every frame the camera moves faster --> time_step got bigger.

Could it be that SchedulerMethod.wait(1) doesn't wait only 1 frame but more?
Posted By: pararealist

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 18:56

I have not had any problems with camera being slower,
but i make my camera method also an IEnumerable<ScheduleMethod>.

Posted By: Stromausfall

Re: C# wrapper 2.2.1 - RELEASE - 03/26/11 19:08

@DJBMASTER, nope didn't have a look yet, but I'll look into that, the function name at least sounds promising ^^
edit: I had a quick look at the function, and it seams that this function uses thread ids, but not managed thread ids ! That's a potential problem afaik, because the native thread of a managed thread may change during runtime afaik!
second edit: the two methods Thread.EndThreadAffinity() and Thread.BeginThreadAffinity() prevent this... hmmm now only the function would need to work (let's hope it does ^^)
third edit ^^: didn't manage to get it to work frown

@Dark_samurai hmmm nope wait(1), should only wait one frame !
did you set fps_max ?

Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/28/11 18:39

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- MATERIAL, too large internal type(double instead of float) for matrix11 to matrix44 variables - skin1..4 didn't work - fixed
- MATRIX, too large internal type(double instead of float) for element00 to element33 - fixed
- EngVar.on_message, can now be not only changed (set) but also retrieved (get)
- ent_getvertex - null couldn't be passed as Contact argument - fixed
- the Scheduler.EngineClosed variable was intialized with false even though the scheduler wasn't started (the scheduler sets it automatically to false and after it exits, to true !) -> fixed, EngineClosed is now initialized with true
- int to double : Text.pos_x, Text.pos_y, Text.offset_y, Text.size_y, Text.size_x

here's the link:

AcknexWrapper_8_10__2_2_2.zip
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 11:16

Hi,

I purchased the Commercial license yesterday and when I came to start making my project using the wrapper I keep getting an AccessViolationException - Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This exception is thrown during the EngFun.engine_open(null, null); line in the example code. I have also tested a previous project (that was working) that I created whilst using the Free version of 3DGS and that throws the same exception. This leads me to believe that there is an issue with the Commercial version I have installed.

Any ideas what this could be?

Thanks in advance.
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 12:55

hmmm could you zip a small version of your project and send it to my e-mail address ? then I could have a look at it (mail@matthias-auer.net) !
The commercial version should without a doubt be able to be used from external languages !
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 13:04

Hi,

I have sent you an email with a test project attached, this is essentially an example off your the website.

Thanks
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 13:32

thanks, i received your project, it worked for me without a problem...
This is indeed strange ! Does a lite-c program already display Commercial version ? Other than that I can't really think of why this doesn't work on your computer...
edit : do you have administrator rights on the windows user account you use ?
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 13:47

Hi Stromausfall,

Yeah when I run the lite-c scripts that come with the engine it displays my name and lists it as Commercial edition. I have full admin privileges on my machine and the project is located in a separate partition to the OS so there shouldn't be any locks on the working dir.

I'm going to try and uninstall everything to do with 3DGS and then reinstall it all, I'll see if that has any bearing on the problem.

it's a confusing one.
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 14:21

did you have any luck yet ?
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:00

I have un-installed 3DGS re-installed it, cleaned my registry, set access rights, ran both debug and release builds all to no avail.

The call stack where the program crashes is as follows:

1) EngVar.initializePointers(IntPtr engVarPointer)

2) [within the function above]
#if A7_WRAPPER
#else
renderLayerEventHandler =
new Scheduler.NativeEventHandler<EventVoid>(renderLayerPointer);
#endif

3) setIntPtrFromIntPtr(IntPtr intPtrToVariable, IntPtr intPtrToWrite)

The exception occurs in the last function call.
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:04

Which version of A8 do use ?
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:05

I downloaded the version that was supplied within my download link which is 8.03
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:08

Excellent ! I think this may be the solution to the problem ^^

go to http://www.3dgamestudio.com/download.php

and then download the
"Gamestudio / A8 (free version / trial version - V 8.10 - ~100 MB - December 2010)"

and then activate it ! Most likely the problem occured because you used 8.03 instead of 8.10 ! It's nonetheless a bit misleading that you didn't get a download link to the newest version !
Posted By: monotonic

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:12

Stromausfall, you are a genius. It;s now working fine and dandy.

Thank you very much.
Posted By: Stromausfall

Re: C# wrapper 2.2.2 - RELEASE - 03/29/11 15:14

Glad it worked ! ^^
Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/01/11 10:17

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- DYNAMIC flag was assigned to flags instead of emask, thus DYNAMIC didn't work - fixed

here's the link:

AcknexWrapper_8_10__2_2_3.zip
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/01/11 14:02

Hi,

I think ive found a problem.
I usually compile the wrapper and add the dll reference to project. This workd when i use A8, but when i went back to A7 to try out some shaders, (i only have A8 free)i find it only works if i add the AW folder to the project, not as dll.
I tried all the examples out and that is the result i got.
Using A7_WRAPPER as conditional i have to remove the dll reference and add the AW folder to the project.
Without A7_WRAPPER as conditional the dll works fine.
Hope this makes sense my explanation.
Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/01/11 15:41

I've never compiled the wrapper to a dll...

But I think that the A7_WRAPPER conditional only needs to be added when you compile the dll... But I don't really know that much about .net dll compiling and stuff smirk
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/02/11 14:03

Ha, good thought.
Will try compiling wrapper dll with A7_WRAPPER then.
So it probably does not need to be inserted in project when using dll if already in Wrapper compilation.
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 09:56

Hi,
i noticed bmap_create always seems to returns null.
Please check using your Shader example.
//
compiling AW as dll is fine now.
Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 10:57

hmmm I can't reproduce that error ! Are you able to load the image file in lite-c ? If you're able to load it in lite-c, could you post or send me an example project or the part of the script were you call it ?
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 11:11

i am actually using your shader example
and just added bmap_create to test it
as bmap_create returned null in my project.
Did a breakpoint and it returns null in every case.

But i think i need to check that i dont call bmap_create before
video is started, will get back to you.
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 11:45

//-------------------------------------------
I just added in Shader Example:
private static BMAP bmapTest = null;

then in myMainMethod()
private static IEnumerable<ScheduleMethod> myMainMethod()
{
//Tested setup video here

//load empty level
EngFun.level_load(null);

//wait a frame
yield return 1;

//move camera back
EngVar.camera.x = -100;

//create entity
ENTITY.ent_create("model.mdl", new Vector(0, 0, 0), entityFun);

//ADDED:
bmapTest = BMAP.bmap_create( "skyDay+6.tga" );
bmapTest.bmap_to_cubemap(); //SET BREAKPOINT here to test bmapTest and it is null

yield return ScheduleMethod.wait( 1 );
}

ERROR:
A first chance exception of type 'System.NullReferenceException' occurred in ShaderExample.exe
An unhandled exception of type 'System.NullReferenceException' occurred in ShaderExample.exe

Additional information: Object reference not set to an instance of an object.
BECAUSE bmapTest is null

if i check bmapTest with
if(bmpTest != null) bmapTest.bmap_to_cubemap();

there is then no error, but bmapTest returns null
//-------------------------------------------

Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 12:42

This code works for me (i used the "skycube+6.tga" file from templates\images)
Have you tried loading your image in lite-c ?

Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 17:20

Strange, i think i am using that one too, (renamed), and getting the same
result with other bmap files too.
But if it works by you, something must be wrong my end,
so i will try bmap files in lite-c first to make sure they
are okay.

Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 20:04

I Narrowed it down to:
For some reason
bmap_create seems not to be able to load bitmaps from a path,
but can load them direct from bin folder OK.

Path:
public static String textures = Application.StartupPath + @"\defaults\textures\";
and use like so:
water_bump = BMAP.bmap_create( textures + "waves2.tga" );

All other load or create commands load from these types path fine, but bmap_create does not.

Would not seem to be a wrapper problem though.
Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 20:12

does the add_folder method help ?
Posted By: pararealist

Re: C# wrapper 2.2.3 - RELEASE - 04/07/11 20:36

No, all paths are already added as add_folder.
Its a strange one, and being A7 may well not be fixed?
Will check if same in A8 later on.
Posted By: BoH_Havoc

Re: C# wrapper 2.2.3 - RELEASE - 04/20/11 14:42

Just wanted to drop by and say i love the new possibility to call lite-c scripts from C#. I was able to get Shade-C working in C# in no time.

Thanks!
Posted By: Stromausfall

Re: C# wrapper 2.2.3 - RELEASE - 04/20/11 14:49

great to hear that ^^
Posted By: stoneco10

Re: C# wrapper 2.2.3 - RELEASE - 04/27/11 13:19


This website's really the best.
Posted By: Stromausfall

C# wrapper 2.2.4 - RELEASE - 04/28/11 23:43

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- engine_getvar, wrong return type, wrong type for type parameter - fixed
- engine_getvarinfo, wrong return type, wrong type for type parameter - fixed
- engine_debugposition, wrong return type, wrong type for type parameter - fixed
- EventOnBreakPoint, wrong type of the line argument - fixed

here's the link:

AcknexWrapper_2_2_4_FOR_8_10_AND_7_85_4.zip

+ an example to show how to use some debug functions has been added to the examples page
Posted By: jenGs

Re: C# wrapper 2.2.4 - RELEASE - 05/06/11 01:54

Hi,
Thank you for the work you put into this laugh

I have a small problem.
I am using different classes.
I am creating the instances of this classes in my Scheduled main method.
Now I want to run a Scheduled method within this class. It is a classmember function with a wait in it.
The function is called by the constructor of my new class.
But until now the funtiction will not run, even it is called from the constuctor,
Code:
class Controller
{
  public Controller()
  {
    StartGamepad();
  }

  public IEnumerable<ScheduleMethod> StartGamepad()
  {
    //do stuff
    while(true)
    {
      yield return ScheduleMethod.wait(1);
    }
  }
}



Perhaps I don't understand the concept of the Scheduler.
Posted By: Stromausfall

Re: C# wrapper 2.2.4 - RELEASE - 05/06/11 06:02

the method StartGamepad seams to be correct !
the problem is that the StartGamepad method is an IEnumerable, thus you can't directly call it !
to add an IEnumerable to the Scheduler, you have to add it, using Scheduler.AddEventVoid(...)

in your case instead of trying to call it like :
Code:
StartGamepad();


call it like this :
Code:
Scheduler.AddEventVoid(StartGamePad);



Scheduler.AddEventVoid method also immediately returns, after it has run the method for one time and then attached it to the scheduler !
Posted By: jenGs

Re: C# wrapper 2.2.4 - RELEASE - 05/06/11 12:13

Thank you. It works fine laugh

It is great to work with the engine AND classes laugh
Posted By: Stromausfall

C# wrapper 2.2.5 - RELEASE - 05/25/11 21:04

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- ScheduleMethod.executeEventVoid and ScheduleMethod.executeEventObject added - they allow to execute functions not "beside" but "inside" the function they are called
- EVENT_BLOCK, EVENT_ENTITY, EVENT_FRICTION, EVENT_PUSH, EVENT_IMPACT, EVENT_SHOOT, EVENT_SONAR, EVENT_SCAN, EVENT_DETECT, EVENT_TRIGGER, EVENT_TOUCH, EVENT_RELEASE, EVENT_CLICK, EVENT_RIGHTCLICK, EVENT_RECEIVE, EVENT_DISCONNECT and EVENT_FRAME were wrongfully implemented as ENTITY flags - removed from ENTITY
- Scheduler.StartScheduler(null) didn't work - fixed

The new ScheduleMethod.executeEventVoid and ScheduleMethod.executeEventObject feature in comparision to the Scheduler.AddEventVoid feature
Click to reveal..




here's the link:

AcknexWrapper_2_2_5_FOR_8_10_AND_7_85_4.zip

+ an example which shows the two types of method calling in the scheduler
Posted By: Stromausfall

C# wrapper 2.2.6 - RELEASE - 05/25/11 22:59

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

- calling ScheduleMethod.executeEventVoid and ScheduleMethod.executeEventObject as the first “yield” command in a method added by Scheduler.AddEventVoid resulted in wrong scheduler behaviour – fixed

here's the link:

AcknexWrapper_2_2_6_FOR_8_10_AND_7_85_4.zip
Posted By: jenGs

Re: C# wrapper 2.2.6 - RELEASE - 06/04/11 00:56

Hi,
How can I load a shader of the Standart material library.
Do I have to load a Script via "engine_getscript".
And how do I access the Material (not the functions) from this script.
Thank you,
Patrick
Posted By: Stromausfall

Re: C# wrapper 2.2.6 - RELEASE - 06/04/11 07:52

Hi !
From what i can see, there are two types of materials in the shader library :
Predefined Materials
and
Predefined Surface Shaders

for an example of how to load a Predefined Surface Shader (a shader that uses a .fx file) follow this link to an example (there is also a download link to an example) : shader example

If you on the other hand want to assign a Predefined Material, then you only have to assign the corresponding EngVar. Here's an example :

Code:
using System;
using System.Collections.Generic;
using AcknexWrapper;

namespace ShaderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            EngFun.engine_open(null, null);

            Scheduler.StartScheduler(MyMainMethod);
        }

        private static IEnumerable<ScheduleMethod> MyMainMethod()
        {
            // load an empty level
            EngFun.level_load(null);

            // create a cube (_CUBE.mdl is a predefined model - CUBE_MDL in lite-c)
            ENTITY cube =
                ENTITY.ent_create(
                    "_CUBE.mdl",
                    new Vector(60, -20, 0),
                    CubeMethod);

            yield break;
        }

        private static IEnumerable<ScheduleMethod> CubeMethod(IntPtr p)
        {
            ENTITY cube =
                ENTITY.createFromPointer(p);

            // now assign the standard metal material
            cube.material =
                EngVar.mtl_metal;

            // change the ambient vector of the standard metal material
            EngVar.mtl_metal.ambient_red = 255;

            while (true)
            {
                // rotate the cube
                cube.pan += 2 * EngVar.time_step;
                cube.tilt += 1.5 * EngVar.time_step;

                // wait one frame
                yield return 1;
            }
        }
    }
}



Posted By: jenGs

Re: C# wrapper 2.2.6 - RELEASE - 06/06/11 02:49

Hey, thank you for your help.

But I have another problem.

I have an embeded engine Window in a form.
Now I want to feed my Form with data from the engine thread.
Is this possible? I don't now that much about threading in csharp.

Another question: How do I pass a parameter value to a Scheduled method?

Edit: Ok, the last problem is solved. I should read your examples more carfully laugh . Is the AddEventObject method the only possible way to pass a parameter? So I guess I have to create a data structure with the information I want to pass?
Posted By: Stromausfall

Re: C# wrapper 2.2.6 - RELEASE - 06/06/11 14:29

Hi!
yes the AddEventObject and Scheduler.AddEventObjectThreadSafe methods are the only way to pass an argument !

But passing an argument is often not necessary, because you can of course create an object fore the method, and thus store as many parameters as you want !

for example :
Code:
class SomeClass
    {
        private string storedParameter1;
        private int storedParameter2;

        public SomeClass(string parameter1, int parameter2)
        {
            this.storedParameter1 = parameter1;
            this.storedParameter2 = parameter2;

            Scheduler.AddEventVoid(SomeFun);
        }

        private IEnumerable<ScheduleMethod> SomeFun()
        {
            Console.WriteLine(storedParameter1 + storedParameter2);
            yield break;
        }
    }



There are lots and lots of different approaches to solve this ! Putting all arguments into a struct and then pass it as object parameter is most likely not the best one - because it is quite unsafe and involves casting !
Posted By: Stromausfall

Re: C# wrapper 2.2.7 - RELEASE - 06/23/11 12:15

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

this update includes:
- the conversion between acknex Var variables/values and C# double values has been improved signifcantly ! If you now set/get the value of an engine object/variable to 9.493, it IS 9.493 in the acknex engine ! Previously a slight rounding error was always present (this showed when using a panel which displayed a number, or using pixel_ functions).
- the scheduler/acknex engine can now be closed and started again, through using the new Scheduler.CloseEngineAndScheduler method and waiting for Scheduler.EngineClosed to become true (after calling the Scheduler.CloseEngineAndScheduler method). After this the engine/scheduler is fully reset and can be started again !

here's the link:

AcknexWrapper_2_2_7_FOR_8_10_AND_7_85_4.zip
Posted By: Stromausfall

Re: C# wrapper 2.2.8 - RELEASE - 06/24/11 09:48

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

this update includes:
- reverted ‘improved conversion’ to the old (pre 2.2.7) conversion, because the ‘new conversion’ (2.2.7) is buggy and slow
- pixel_for_vec, pixel_to_vec, pixel_for_bmap, pixel_to_bmap – internally no conversion happens anymore – the pixel value now has type ‘int’ not double (thus allows consistent read and write)

here's the link:

AcknexWrapper_2_2_8_FOR_8_10_AND_7_85_4.zip
Posted By: Stromausfall

Re: C# wrapper 2.2.9 - RELEASE - 06/26/11 09:37

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

this update includes:
- ScheduleMethod.executeEventVoid and ScheduleMethod.executeEventObject improved -> methods added that way, when they end, immediately jump back to the method that called them, not wait 1 frame to jump back !

here's the link:

AcknexWrapper_2_2_9_FOR_8_10_AND_7_85_4.zip
Posted By: pararealist

Re: C# wrapper 2.2.9 - RELEASE - 06/27/11 12:30

Hi M
Where/how have you implemented path_create
I cannot seem to find it in wrapper.
Posted By: Stromausfall

Re: C# wrapper 2.2.9 - RELEASE - 06/30/11 13:09

hi !
path_create is 8.20, but the wrapper is still 8.10 ! I'll update the wrapper in the next release (1-2 weeks).
Posted By: pararealist

Re: C# wrapper 2.2.9 - RELEASE - 06/30/11 16:36

OK, noticed it was still 8.10 after post.
Posted By: Stromausfall

C# wrapper 2.3.0 - RELEASE - 07/01/11 16:37

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.20)
the update of the wrapper includes:

- updated to 8.20
- the wrapper can be used without the scheduler - using the Conditional compilation symbols (VS2010) value "NO_SCHEDULER" ("A7_WRAPPER" can be used beside "NO_SCHEDULER" !)

here's the link:

AcknexWrapper_2_3_0_FOR_8_20_AND_7_85_4.zip

when using the wrapper without the scheduler, references to used delegates have to be stored ! Additionally WrappedDouble, WrappedInt and WrappedString objects are introduced, they have to be used in order to interact with certain methods like pan_setneedle etc... These objects are needed, because WITHOUT a scheduler, the creation/deletion and updating of such variables isn't done automatically ! Additionally no more IEnumerables have to be used, if the scheduler isn't used !

here's an example, providing an overview on how to use the wrapper wihtout a scheduler and how the WrappedDouble is used :

Click to reveal..

Code:
using AcknexWrapper;

namespace NoSchedulerTest
{
    public class Program
    {
        static void Main(string[] args)
        {
            // opening the engine
            EngFun.engine_open(null, null);

            // limit frame rate
            EngVar.fps_max = 60;

            // load an empty level
            EngFun.level_load(null);

            // create a player entity
            Player player =
                new Player(new Vector(100, 0, 0));

            // create and keep the reference to the delegate as long as it is needed !
            WrapperDelegateVoid onSpaceMethodDelegate =
                OnSpaceMethod;

            // assign the delegate to the EngVar variable
            EngVar.on_space =
                onSpaceMethodDelegate;

            // create a panel
            PANEL sliderPanel =
                PANEL.pan_create(null, 1);
            sliderPanel.SHOW = true;
            sliderPanel.size_x = 300;
            sliderPanel.size_y = 100;
            
            // allow mouse interaction
            EngVar.mouse_mode = 4;

            // create bitmaps, to be used in the slider
            BMAP sliderBackground =
                BMAP.bmap_createblack(200, 40, 24);
            BMAP sliderKnob =
                BMAP.bmap_createblack(20, 60, 24);
            sliderBackground.bmap_fill(new Color(255, 255, 255), 100);

            // the value to be read and modified by the user AND the engine
            WrappedDouble wrappedDouble =
                new WrappedDouble(50);

            // create the slider
            sliderPanel.pan_setslider(
                0,
                50,
                50,
                sliderBackground,
                sliderKnob,
                0,
                255,
                wrappedDouble);

            bool keyEnterHasBeenReleased = true;

            while (EngFun.engine_frame() != 0)
            {
                // interaction in the rendering loop
                if (EngVar.key_enter == true)
                {
                    if (keyEnterHasBeenReleased == true)
                    {
                        EngVar.sky_color.blue += 25;
                        EngVar.sky_color.blue %= 255;
                        keyEnterHasBeenReleased = false;
                    }
                }
                else
                {
                    keyEnterHasBeenReleased = true;
                }

                EngVar.sky_color.red = wrappedDouble.Value;
            }

            EngFun.engine_close();
        }

        // interaction using EngVar key events
        private static void OnSpaceMethod()
        {
            EngVar.sky_color.green += 25;
            EngVar.sky_color.green %= 255;
        }
    }

    public class Player
    {
        private readonly ENTITY PlayerEntity;

        /// <summary>
        /// the delegate has to be referenced to, as long as it is used !
        /// </summary>
        private readonly WrapperDelegateVoid PlayerRoutineDelegate;

        public Player(Vector position)
        {
            // create the entity
            this.PlayerEntity =
                ENTITY.ent_create("_CUBE.MDL", new Vector(100, 0, 0), null);

            // enable triggering of the event function, every frame !
            this.PlayerEntity.ENABLE_FRAME = true;

            // create and store the delegate
            this.PlayerRoutineDelegate =
                this.PlayerRoutine;

            // assign the event method/delegate
            this.PlayerEntity.event_ =
                this.PlayerRoutineDelegate;
        }

        // interaction using on_frame
        private void PlayerRoutine()
        {
            double speedOfPositionChange =
                2.5 * EngVar.time_step;

            if (EngVar.key_a == true)
            {
                this.PlayerEntity.y += speedOfPositionChange;
            }
            if (EngVar.key_d == true)
            {
                this.PlayerEntity.y -= speedOfPositionChange;
            }
            if (EngVar.key_w == true)
            {
                this.PlayerEntity.z += speedOfPositionChange;
            }
            if (EngVar.key_s == true)
            {
                this.PlayerEntity.z -= speedOfPositionChange;
            }
        }
    }
}



Posted By: 3dgs_snake

Re: C# wrapper 2.3.0 - RELEASE - 07/01/11 18:14

Hi,

Thanks for the update, I'll grab it right now!

Best regards.
Posted By: Tempelbauer

Re: C# wrapper 2.3.0 - RELEASE - 07/02/11 10:38

Dein Wrapper ist immer Top-aktuell. Das ist auch wichtig für jeden der ihn einsetzt. Gibt andere Engines, da wird ein solches Projekt gestartet, nach einigen Monaten wieder fallen gelassen und dessen Nutzer sitzen dann auf dem Trockenen

Vielen Dank für den kontinuierlichen Einsatz und die regelmäßigen Updates laugh
Beteiligt sich Conitec eigentlich mittlerweile an der Entwicklung (sei es mit Manpower oder mit anderweitigen Entlohnungen)? Ein solcher Wrapper ist ja auch eines derer Interessen...
Posted By: Stromausfall

Re: C# wrapper 2.3.0 - RELEASE - 07/02/11 11:33

jo danke ^^ ist wahrscheinlich deshalb aktuell, weil ich ihn ja selber auch benutze ^^
Und von Conitec hab ich auch eine Entlohnung bekommen ^^
Posted By: keilyn3d

Re: C# wrapper 2.3.0 - RELEASE - 07/06/11 05:33

Stromausfall Thanks for make this awesome wrapper, this was the best thing that could be happen to 3dgamestudio...

I had a software created with 3dgamestudio/winapi, but the application only worked in "windows 7", but with this wrapper I have port the app to .net/winform easily and now it work in any windows system...

The power of acknex + .net is amazing

Thank you very much!!! you are the best!!
Posted By: Stromausfall

Re: C# wrapper 2.3.0 - RELEASE - 07/06/11 12:02

Thanks ^^
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 07/08/11 12:28

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.10)
the update of the wrapper includes:

this update includes:
- missing PhysX functions included : pXent_rotate, pXent_setbodyflag, pXent_setbodyflagall (thanks to pararealist !)

here's the link:

AcknexWrapper_2_3_1_FOR_8_20_AND_7_85_4.zip
Posted By: MasterQ32

Re: C# wrapper 2.3.1 - RELEASE - 07/31/11 17:01

Hey!
I have to say again: Great Work!
But would it be possible to create a fluent interface for the vector things??
Because coding would be much easier then:
Code:
Old way:
Vector direction = new Vector(activeCCharacter.Position);
direction.vec_sub(EngVar.target);
direction.vec_normalize(5);

New Way:
Vector direction = new Vector(activeCCharacter.Position).vec_sub(EngVar.target).vec_normalize(5);



Sure it's not to hard to implement this. Afak the only thing to change is the return type of those vector functions....

Another thing, but i think it's too late for that:
We have object orientation so we can't simply call the function create of a BMAP with an ENTITY. My thought is:
Why to use those prefixes??

This would be much nicer:
ENTITY myEnt = ENTITY.create("pla",pla,pla);
Or even better:
ENTITY myEnt = new ENTITY("pla",pla,pla);

Would be cool to see this.

Greetz Felix
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 07/31/11 21:30

i try to keep as close to lite-c as possible !
the return values of functions aren't always that obvious !

I also chose static constructors, because then you know WHICH function is used to create the entity (as there are several available, like ent_createlayer etc...)

thus in short, looking at the code, it should be easy to see which acknex function is called/used, this isn't as obvious anymore if the name is changed (for example through a constructor, or changing vec_add to add or even overload the + operator...)
Posted By: pararealist

Re: C# wrapper 2.3.1 - RELEASE - 08/02/11 15:10

I agree with Stromausfall.

With those changes the wrapper will have a higher learn curve, where as now if you know lite-c, the wrapper is no problem, and it is an acknexwrapper after all.
Posted By: 2010_Trekky

Re: C# wrapper 2.3.1 - RELEASE - 08/02/11 16:19

Hallo Stromausfall,
dein wrapper ist wirklich eine tolle Sache, aber irgendwie funktioniert das bei mir nicht. Genauer gesagt meldet WED, dass er die HelloWorldExample.C nicht öffnen kann.
Mein Vorgehen: Ich verwende Visual Studio 2010 und bin bei dem Erstellen des Projektes so vorgegangen wie es auf deiner Webseite vorgeschlagen wird. Habe also ein neues Projekt erstellt, den Post-build event command eingefügt, den VS Hosting Process ausgeschaltet und im Anschluß die wrapper-Dateien hinzugefügt. Anschließend habe ich den Quelltext des HelloWorld Programms von deiner Webseite in das Programm kopiert. Dann habe ich den Debug gestartet und das Programm hat auch super kompiliert aber der WED hat dann anschließend gemeldet, dass er die HelloWorldExample.C nicht öffnen kann.
Weißt du reinzufällig woran das liegen könnte, habe ich da irgendeine Einstellung vergessen vorzunehmen und auf deiner Webseite überlesen?
Posted By: MasterQ32

Re: C# wrapper 2.3.1 - RELEASE - 08/03/11 14:35

Originally Posted By: Stromausfall
i try to keep as close to lite-c as possible !


afak every vec_ function returns the first parameter (a vector) as return value
so you can write this:
Code:
vec_set(a,vec_rotate(b,vec_normalize(c,5)));


and this would be nice in c#, too
Posted By: ventilator

Re: C# wrapper 2.3.1 - RELEASE - 08/03/11 18:56

Originally Posted By: Richi007
Originally Posted By: Stromausfall
i try to keep as close to lite-c as possible !


afak every vec_ function returns the first parameter (a vector) as return value
so you can write this:
Code:
vec_set(a,vec_rotate(b,vec_normalize(c,5)));


and this would be nice in c#, too


no, this would be nice in c#:

a = b.rotate(c.normalize(5));
Posted By: MasterQ32

Re: C# wrapper 2.3.1 - RELEASE - 08/03/11 19:39

yes, but he don't wanna do this ;(

but if we use the c# wrapper, we want to get rid of all those non-class system wich is used by lite-c
but if the c# wrapper is like lite-c, we can't use the full power of c#
that's what i want to say...
Posted By: ratchet

Re: C# wrapper 2.3.1 - RELEASE - 08/03/11 19:50

I've tesetd the demo, and it coould tranform easily in real indie selling game, just by adding levels, some more gameplay meachnism or any addition like RPG system !
It could make some Metroid alternative game laugh

I've took a look at the code , i have some questions :
How is made the complete level ? it is not imported from WED ?

For entities that have code scritp attached to them, can we do that with C# ? or howw do we manage the entities with code and their attributes: values, AI state etc ... ?
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/05/11 16:16

@Richi007
>>afak every vec_ function returns the first parameter (a vector) as return value

hmmm then it may be just an expected behaviour, that the function behaves as you showed..
@ventilator
yep ^^

@ratchet
the level was created in blender and then imported in MED and then in WED I just added some lights...

nope attaching a script in WED won't do anything I guess !
but assigning skills works of course, thus there are several possibilities, hard code the entity-function relationship or assign them according to a skill value, or even type of entitity !
Posted By: jenGs

Re: C# wrapper 2.3.1 - RELEASE - 08/10/11 15:47

Hi,
Is it possible that the panel.event function is not implemented in c#-wrapper?
Patrick

edit:
Another question:
How can I add a on_mouse_click event.
"private IEnumerable<ScheduleMethod> pEvent()" doesn't work in this case.
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/10/11 16:42

@jenGs
indeed, it looks like the panel.event_ property is missing !

to add an event to for example EngVar.on_mouse_left you have to do the following :

Code:
private static IEnumerable<ScheduleMethod> onMouseLeftMethod(double value)
{
    yield return 1;
}

static void Main(string[] args)
{
    EngFun.engine_open(null, null);
    EngFun.level_load(null);

    // ....

    // register this method on the event
    EngVar.on_mouse_left += onMouseLeftMethod;

    // ....

    // unregister this method on the event
    EngVar.on_mouse_left -= onMouseLeftMethod;

    // clear all registered method on this event...
    EngVar.on_mouse_left.Events.Clear();
}



P.S.:
I'll try to update the wrapper as soon as possible !
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/10/11 18:59

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.20)
the update of the wrapper includes:

- missing event_ property for PANELs was added (thanks at jenGs)
- class methods that return void and aren't static, now return the instance of the object (thanks at Richi007)

here's the link:

AcknexWrapper_2_3_2_FOR_8_20_AND_7_85_4.zip
Posted By: jenGs

Re: C# wrapper 2.3.1 - RELEASE - 08/10/11 19:27

Hi,
Thank you. But I can't figure out how to assign an event.
Thank you for this very fast update laugh
MfG,
Patrick
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/10/11 19:41

there are two types of events :
one that uses 'EventHandlers' like EngVar.on_mouse_left, an example for this is shown in one of my previous posts !
the other type only allows one method to be called, for example the Panel.event_ property :

Code:
// the method to be called when the panel is clicked
    static void PanelEvent(IntPtr p)
    {
        // get the clicked panel
        PANEL thisPanel =
            PANEL.createFromPointer(p);

        // change the color of the clicked panel
        thisPanel.bmap.bmap_fill(new Color(200, 0, 0), 50);
    }

// the main method called by the scheduler
    private static IEnumerable<ScheduleMethod> MyMainMethod()
    {
        // create a red panel and make it visible...
        PANEL p =
            PANEL.pan_create(null, 24);
        
        p.SHOW = true;
        p.size_x = 100;
        p.size_y = 100;
        p.pos_x = 300;
        p.pos_y = 300;
        p.bmap =
            BMAP.bmap_createblack(100, 100, 32);
        p.bmap.bmap_fill(new Color(0, 0, 255), 50);

        // assign the method to be called when the panel is clicked..
        p.event_ =
            PanelEvent;

        // use the mouse !!
        EngVar.mouse_mode = 4;
}

// the entry point of the program
    static void Main(string[] args)
    {
        // load an empty level
        EngFun.engine_open(null, null);
        EngFun.level_load(null);

        // start the scheduler
        Scheduler.StartScheduler(MyMainMethod);
    }


Posted By: jenGs

Re: C# wrapper 2.3.1 - RELEASE - 08/15/11 13:18

Hi,
I have another question laugh
Do I have to write an own inkey function or is it somewhere. I noticed that you are using csharp native strings. So I guess it is difficult to wrap the inkey function?
Patrick
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/15/11 16:36

The problem with inkey is that it isn't part of the acknex.dll (from http://www.conitec.net/beta/ainkey.htm) as it uses wait (and thus the lite-c scheduler) !

simulating inkey shouldn't be that hard, I guess the description of inkey in the GameStudio manual offers a reasonable solution :
You could use wait and check a variable that contains the value of the last pressed char, for example the engine variable key_lastpressed !
Posted By: pararealist

Re: C# wrapper 2.3.1 - RELEASE - 08/18/11 14:50

Please check if
button_state(num, state)
is working properly?
I do not seem to be getting any result.
Posted By: Stromausfall

Re: C# wrapper 2.3.1 - RELEASE - 08/18/11 15:19

button_state works for me ! look at the following example, it uses button_state to switch the state of the toggle button ! it uses a toggle button and switches it on/off depending on its current state, using button_state (when space is pressed) ! The state is also changed if you press the button, but remember to move the mouse away from the button to see it's state (because of mouseOver and mouseOverOff)

Code:
// here's some sample code

        private static PANEL p;

        private static IEnumerable<ScheduleMethod> switchStateOfButtonUsingButtonState()
        {
            // first get old state... -1 means DON'T change state of the button
            double oldState =
                p.button_state(1, -1);

            // then switch the state, according to the return value
            if (oldState == 0)
            {
                // switch to on
                p.button_state(1, 1);
            }
            else
            {
                // switch to off
                p.button_state(1, 0);
            }

            yield break;
        }

        public static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // use mouse !!
            EngVar.mouse_mode = 4;

            p =
                PANEL.pan_create(null, 1);
            p.SHOW = true;
            p.pos_x = 100;
            p.pos_y = 100;
            p.size_x = 500;
            p.size_y = 500;

            BMAP on =
                BMAP.bmap_createblack(200, 200, 32);
            on.bmap_fill(new Color(0, 255, 0), 50);
            BMAP off =
                BMAP.bmap_createblack(200, 200, 32);
            off.bmap_fill(new Color(0, 0, 255), 50);
            BMAP over =
                BMAP.bmap_createblack(200, 200, 32);
            over.bmap_fill(new Color(200, 200, 20), 50);

            p.pan_setbutton(
                0,
                2,
                50,
                50,
                on,
                off,
                over,
                over,
                null,
                null,
                null);

            EngVar.on_space +=
                switchStateOfButtonUsingButtonState;

            yield break;
        }

        static void Main(string[] args)
        {
            EngFun.engine_open(null, null);
            EngFun.level_load(null);

            Scheduler.StartScheduler(myMainMethod);
        }


Posted By: pararealist

Re: C# wrapper 2.3.1 - RELEASE - 08/19/11 11:56

Thanks for checking.
It did not seem to return anything for me.
Will try again later.
Posted By: Rackscha

Re: C# wrapper 2.3.1 - RELEASE - 08/19/11 18:13

tried to use it the firts time(copied helloworld example).

It crashes instantly in engine_open when calling NativeEngFun.engine_open

BatImageFormatException


Greets
Rackscha
Posted By: Rackscha

Re: C# wrapper 2.3.1 - RELEASE - 08/19/11 18:45

Damn it, express compiled an x64 assembly. Had to change platform target manually in projectfile >.<
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/23/11 14:32

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.20)
the update of the wrapper includes:

- missing model property for CONTACTs was added

here's the link:

AcknexWrapper_2_3_3_FOR_8_20_AND_7_85_4.zip
Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/23/11 15:07

eh...your wrapper is using SHOW for entities. But isnt the correct flag VISIBLE ?
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/23/11 15:36

http://manual.3dgamestudio.net/beta.htm

not since 'V7.63b beta - released 15-Dec-2008' anymore - this was afaik, when VISIBLE was taken out of the headers of the engine_sdk !
Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/23/11 15:46

ah...got confused with INVISIBLE^^
Posted By: painkiller

Re: C# wrapper 2.3.3 - RELEASE - 08/23/11 20:45

Originally Posted By: Rackscha
eh...your wrapper is using SHOW for entities. But isnt the correct flag VISIBLE ?


panels and view entities use SHOW, and world entities use INVISIBLE
Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/25/11 13:51

mh i have a problem with the partikle example.

i wrote this
Code:
class MyGraphic
    {
        private static void ParticleLine(PARTICLE p)
        {

        }

        public static void DrawLine3DEx(Vector AFrom, Vector ATo, Color AColor, int AAlpha, int ASize)
        {
            PARTICLE.effect(ParticleLine, 1, AFrom, ATo);
        }


    }



Get the error: "1 argument cannot be converted from ethodgroup to AcknexWrapper.WrapperDelegateParticle"

Cant see any differences between my and your particle event in the tutorial. What have i done cry
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/25/11 23:07

well you're not using the scheduler (at least that's how it seams), thus some small things change ! in this case, the particle functions doesn't have a PARTICLE as argument anymore, but an IntPtr !
thus the correct code should be :
Code:
class MyGraphic
    {
        private static void ParticleLine(IntPtr p)
        {

        }

        public static void DrawLine3DEx(Vector AFrom, Vector ATo, Color AColor, int AAlpha, int ASize)
        {
            PARTICLE.effect(ParticleLine, 1, AFrom, ATo);
        }


    }


Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/26/11 00:19

ah thanks laugh

ANd how do i use it correctly now? ssems i got my first problem with the garbage collector tongue

Got a message that WrapperDelegateParticle did a callback(or however i have to translate it o.O), and it needs to be guranteed that objects are still available..etc. A bit tired and fully translating the germantext(wow ms c# really has long messages :D) is a bit to much now.

currently i have those 3 Methods for testing:

Code:
private static void ParticleLineEvent(IntPtr AP)
        {
            PARTICLE P = PARTICLE.createFromPointer(AP);
            P.lifespan = 0;
        }

        private static void ParticleLine(IntPtr AP)
        {
            PARTICLE P = PARTICLE.createFromPointer(AP);
            P.lifespan = 1;
            P.event_ = ParticleLineEvent;
        }

        public static void DrawLine3DEx(Vector AFrom, Vector ATo, Color AColor, int AAlpha, int ASize)
        {
            PARTICLE.effect(ParticleLine, 1, AFrom, (Vector) ATo.vec_sub(AFrom));
        }



runs well for some frames, then it jumps out of the program into engine_frame
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/26/11 06:36

yes, that's because when you use no scheduler, you have to do some extra tasks !
The delegates are automatically collected by the garbage collector, that's why the scheduler stores them !
If use no scheduler, you have to store the used delegates yourself !
the following code snippet should work (i guess) :
Code:
// create a delegate for the particle method and store it, if you use instance
// methods etc... you have to store them in another way, but using only static
// methods, this should work too !
private static readonly WrapperDelegateParticle StoredDelegateForParticles = ParticleLineEvent;

private static void ParticleLineEvent(IntPtr AP)
        {
            PARTICLE P = PARTICLE.createFromPointer(AP);
            P.lifespan = 0;
        }

        private static void ParticleLine(IntPtr AP)
        {
            PARTICLE P = PARTICLE.createFromPointer(AP);
            P.lifespan = 1;
            P.event_ = ParticleLineEvent;
        }

        public static void DrawLine3DEx(Vector AFrom, Vector ATo, Color AColor, int AAlpha, int ASize)
        {
            // call the effect method, already with the stored delegate
            PARTICLE.effect(StoredDelegateForParticles, 1, AFrom, (Vector) ATo.vec_sub(AFrom));
        }


Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/26/11 15:08

a thanks. and executing the drawline3dex method multiple times still works? laugh

And just in case: if i want to use it in an instanced object(so no static methods),
how do i handle those?

edit: and you explain a little bit how your example above in combination with the garbage collector works within your acknexwrapper? just interseted^^

edit2: Little question: even if your scheduler is not running, isnt it possible for the wrapper to catch the delegate? I mean i call PARTICLE.effect. Isnt it possible to catch it inside your effect function?

Greets
Rackscha
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/26/11 17:16

nope shouldn't be a problem because you use the same STATIC method !

well if you use instanced methods, then you should create a member variable that stores the delegate (like the static one in the example, but NOT static) !

well after you pass the delegate the wrapper, a Marshal method allows to get an IntPtr that points to the managed delegate, this delegate is then passed to the C++ API of the acknex.dll, then the acknex.dll calls the IntPtr, which then calls the delegate (this done inside of .net) ! Thus if the delegate was removed by the garbage collector, the IntPtr points to a delegate that has been removed !

In the scheduler, the delegates for particles are stored as long as they are called every frame, if a particle delegate isn't called anymore, it is automatically removed (because particle functions are called every frame !)
Other delegates for example in ent_create only have to be stored while the function is called (for example ent_create), because after this they aren't called anymore... Variables that use delgates, store the delegate and simply overwrite it when the value is changed... And the delgates that are used for the panel methods are stored in a dictionary, that removes the delegates, when the panel element is removed..
Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 08/26/11 20:19

ah thanks laugh

One last question though: how do i do a basic setup for the particle?
The example above only uses ParticleLineEvent. But how can i setup size/color etc only once?

Do i have to store the other event in a wrapper delegate too, use this one first and then reassign the event delegate after first execute of the setup function?
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 08/27/11 05:57

hmmm i don't know that much about particles, but the way you described : storing the other delegate and then using it should work fine !
Posted By: jenGs

Re: C# wrapper 2.3.3 - RELEASE - 11/03/11 17:24

Hi,
I have a problem.
I am using ent_getvertex/ent_setvertex to morph my models. This works fine until you call the function ent_fixnormals. This resets the mesh to the prvious version. I did not observe the same behaviour in Lite-C.
MfG,
Patrick
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 11/10/11 14:25

hmm i can't seem to reproduce that behaviour... can you tell me more about the instance where this problem occured or maybe even send me a small demo project where the problem occurs ?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace Test
{
    class Program
    {
        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            EngFun.level_load(null);

            yield return 1;

            ENTITY terrain =             
                ENTITY.ent_createterrain(null, new Vector(100, 0, -5), 10, 10, 5);

            // wait a frame, before changing the terrain !
            yield return 1;

            CONTACT c =
                terrain.ent_getvertex(null, 7);

            c.z += 10;  // increase the vertex height
            c.v = null; // c.x,y,z was changed, instead of c.v      
            terrain.ent_setvertex(c, 7);    // update the mesh

            terrain.ent_fixnormals(0);
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: Stromausfall

C# wrapper 2.3.4 - RELEASE - 11/10/11 20:38

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- updated to work with A8.30.4

here's the link:

AcknexWrapper_2_3_4_FOR_8_30_4_AND_7_85_4.zip
Posted By: Dark_samurai

Re: C# wrapper 2.3.4 - RELEASE - 11/12/11 09:55

Thank you very much for your ongoing development of this great wrapper! laugh
Posted By: jenGs

Re: C# wrapper 2.3.3 - RELEASE - 11/18/11 19:02

Hi,
Sorry for my long response time. Here is a demo Project. It is a vs2010 sollution in debug build mode.
demo
If you press f1 the terrain is morphed randomly, if you press f3 the mdl is morphed.
On f2 you can call fixnormals for the terrain, on f4 you can call fixnormals for the mdl.
Thank you for taking the time to look onto this.
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 11/20/11 11:54

Hi !
i finally found some time to look at the example !
This is indeed a strange bug ! I tried to convert the code from the example to lite-c - there the problem happens too (at least for me!) !
It seems to me that this problem is not isolated to the C# wrapper ! I tried several other things, but it somehow seems that ent_fixnormals always resets to the original state of the terrain ...
Does the problem also occur for you in lite-c with this code ? :

(edited) :
I just discovered that the code i previously posted, in which I said that i can't reproduce the error, now also produces this error !

I guess this is because i used 8.20.1 when i wasn't able to reproduce the error but now after updating to 8.30.5, the error is always produced....

THUS i think the error somehow smuggled itself into existence between A8.20.1 and A8.30.5 ! That's why I guess this is a engine bug, caused by the new Acknex version !

Code:
// we can't use default.c because there f1 - f4 are already preset with some other stuff !

#include <acknex.h>

ENTITY *demoTerrain;
ENTITY *demoModel;

void MorphTerrain()
{
	int i;
	
	for (i = 0; i < ent_status(demoTerrain, 0); i++)
	{
		CONTACT *c = ent_getvertex(demoTerrain, NULL, i);
		c.z += random(10);
		c.v = NULL;
		ent_setvertex(demoTerrain, c, i);
	}
}

void MorphModel()
{
	int i;
	
	for (i = 0; i < ent_status(demoModel, 0); i++)
	{
		CONTACT *c = ent_getvertex(demoModel, NULL, i);
		c.z += random(10);
		c.v = NULL;
		ent_setvertex(demoModel, c, i);
	}
}

void FixNormalsTerrain()
{
	ent_fixnormals(demoTerrain, 0);
}

void FixNormalsModel()
{
	ent_fixnormals(demoModel, 0);
}

void SetUpDemo()
{
	camera.x = -1676;
	camera.y = 432;
	camera.z = 1126;
	camera.pan = 0;
	camera.tilt = -35;
	
	BMAP *grey = bmap_createblack(512, 512, 24);
	bmap_fill(grey, vector(128,128,128), 100);
	demoTerrain = ent_createterrain(grey, vector(0,0,0), 16, 16, 64);
	
	demoModel = ent_create("plane.mdl", vector(0, 1040, 0), NULL);
}

int main()
{
	mouse_mode = 4;
	mouse_pointer = 2;
	mouse_sync = 1;
	video_switch(10, 32, 2);
	wait(1);
	level_load(NULL);
	sun_light = 100;
	sun_pos.x = 80;
	sun_pos.y = 154;
	sun_pos.z = 0;
	SetUpDemo();
	
	on_f1 = MorphTerrain;
	on_f2 = FixNormalsTerrain;
	on_f3 = MorphModel;
	on_f4 = FixNormalsModel;
}



P.S.:
@Dark_samurai : Thank you laugh
Posted By: jenGs

Re: C# wrapper 2.3.3 - RELEASE - 11/20/11 17:57

Hi,
Thank you for looking laugh
Now I get the problem too. Figured out that my Laptop had an old Acknex version. I tested the Lite-C version with it and the c# version with my desktop PC which is up to date in Acknex matters.
So this seems to be a bug-Forum case. I will open a topic there when I have some time today.
MfG,
Patrick
Posted By: MasterQ32

Re: C# wrapper 2.3.3 - RELEASE - 01/04/12 12:18

hey stromausfall!
i'm asking another time:
could you please change some things in your wrapper?
you simply copied all acknex functions to lite-c, but your wrapper could be much more powerful.
Atm i'm changing a lot of stuff to have faster results.
so some suggestions what to change:

  • Allow users to set vectors per =, not only per vec_set. Some possible solution:
    Code:
    public Color blueGreenRed
    {
    	get
    	{
    		return Color.createFromPointer(bluePointer);
    	}
    	set
    	{
    		Color.createFromPointer(bluePointer).vec_set(value);
    	}
    }
    
    
  • Please add constructors to your classe. Eg:
    Code:
    new ENTITY("mymodel.mdl", new Vector(1,2,3), new EventIntPtr(pla));
    new PANEL("pos_x = 5; pos_y =10; flags = SHOW;",6);
    ...
    
    
  • Add a implicit cast to the Vector class, so we can write this:
    Code:
    double x = myent.xyz;
    myent.xyz = 4;
    
    
    This looks a little weird, but you can now also simply remove this xyz-vector and name it x. This results in the simple gamestudio style:
    Code:
    myent.x = new Vector(1,2,3);
    double x = myent.x;
    myent.x = 4;
    Vector k = myent.x;
    
    
  • Add a Tag property to all objects (like in WinForms), so we can store custom objects into the engine objects
  • Also you could split the class ENTITY into ViewEntity and WorldEntity, so we can differ also in code and it will be much clearer what is used.
  • another thing what would be nice: remove all prefixes of the class functions. this looks simply strange. much better would be this:
    Code:
    Entity myEnt = new Entity("lalala.mdl",new Vector(4,5,6),null);
    myEnt.animate("walk",50,AnimationMode.None);
    myEnt.remove();
    
    
  • Also if you change the constructor thing, you can add this constructor to Entity:
    Code:
    public Entity(string modelFile, Vector position)
    
    
    Because sometimes we don't need an entity event or we manage those things ourselves, so we don't need this parameter.


Would be really cool if we could see some of my suggestions in the next version of the wrapper!

Greetz Felix

A little bit offtopic:
If someone needs some cool libraries c# (network and multitouch, both useable with gs):
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=390042#Post390042
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 01/05/12 22:55

hi !

>>Allow users to set vectors per =, not only per vec_set. Some possible solution:
I don't think that that's an optimal solution, as it suggests that the Vector object is actually assigned, which would mean that
Code:
Vector temp = new Vector(2, 3, 4);
entity.xyz = temp;

temp.x = 2000;

// I would expect entity.x now to be 2000 ! but it wouldn't be that way !



>>Please add constructors to your classe. Eg:
i already once used constructors for this, but static methods are preferable for me, as with static constructors it's immediately clear which method is used to construct the object, with a normal constructor, one has to read, guess or search (because only the number/types of arguments would change for the constructors)!

>>Add a implicit cast to the Vector class, so we can write this:
looks too weird imho


>>Add a Tag property to all objects (like in WinForms), so we can store custom objects into the engine objects

i currently don't know what Tags are for, I had a quick look and only found something about an object variable ? In which situations is such a tag used or beneficial ?

>>Also you could split the class ENTITY into ViewEntity and WorldEntity, so we can differ also in code and it will be much clearer what is used.

this is a good idea, although I'll have to see if this is actually doable (because i don't know if viewEntities and worldEntities are handled that separate)

>>another thing what would be nice: remove all prefixes of the class functions. this looks simply strange. much better would be this:
this has been mentioned multiple times in this thread, and yes it would look much better, but i want to know exactly what method I'm calling and be able to look it up immediately in the gamestudio manual, that's why i think that the actual name of the lite-c method is preferable

Thanks for the feedback laugh
Posted By: MasterQ32

Re: C# wrapper 2.3.3 - RELEASE - 01/05/12 22:58

Originally Posted By: Stromausfall

i currently don't know what Tags are for, I had a quick look and only found something about an object variable ? In which situations is such a tag used or beneficial ?
)

you can store objects in "engine objects", not only two different double values (skill_x, skill_y)
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 01/05/12 23:11

ah okay ! thanks for the explanation !
Tags are not a good idea then, because think of the following scenario :

you assign an object as tag to entity#1, then you are c_tracing and hit entity#1 and want to access its tag object -> but this won't work, because the object that you retrieve via c_trace is a new object (although it points to the same memory location and thus 'is' the entity#1) and doesn't have a tag !

edit :
a 'tag' could be simualted simply by a "Dictionary<IntPtr, object> tagObjects" where you can get the unique entity identifier by someEntity.getIntPtr() !
Posted By: Rackscha

Re: C# wrapper 2.3.3 - RELEASE - 01/06/12 12:03

@MasterQ32:
Some good ideas. Especially like the idea of removing prefixes and adding constructors. C# is not lite-c and doesnt have its limitations. :|
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/01/12 12:04

@Stromausfall:

Thanks for the great wrapper again. Exactly what i need right now.

I need to embed engine in a form, there is an example in your site, but i figured out a simpler approach:

Code:
EngFun.video_window(null, null, 256, null);
EngFun.video_set(panelEngine.Width,panelEngine.Height,0,0);
EngVar.hWndTarget = panelEngine.Handle;
EngVar.hWndParent = this.Handle;



you just have to make sure you set EngVar.d3d_lockable to 1 after engine_open and before first frame. Then use the code i posted above AFTER first frame.
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/03/12 14:16

it seems, that neither keyboard input nor especially mouse input works with this method, although if you don't need direct interaction (via keyboard/mouse), this seems to be the best solution !
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/05/12 12:29

adding EngFun.on_message(or something like that) to form's message loop should solve that problem in 1 line of code.
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/16/12 10:02

@Stromausfall,

How do i differantiate between events in the event function? I have both enable frame, click and impact.
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/16/12 16:42

via event_frame !
I've made a small example that shows how to use it ! you'll need the c# project to be a console project to view the output (when an event is triggered..) !
You won't need any models or stuff like that for the project to work, only the code !

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace eventExample
{
    class Program
    {
        private static IEnumerable<ScheduleMethod> testEntity2Method(IntPtr e)
        {
            ENTITY me =
                ENTITY.createFromPointer(e);
            Vector originalPos =
                new Vector(me.xyz);
            double originalYPos =
                me.y;

            // cube should be red
            me.LIGHT = true;
            me.red = 255;
            me.blue = 0;
            me.green = 0;
            me.lightrange = 0;

            // low push value
            me.push = 10;

            double timeValue = 0;
            double newYForce;
            
            while (true)
            {
                // increase by 1 every second and limit to 0...1.999
                timeValue += EngVar.time_step / 16;
                timeValue %= 2;

                if (timeValue > 1.5)
                {
                    // 1/4 of time, move away
                    newYForce = 2.5 * EngVar.time_step;
                }
                else
                {
                    // 3/4 of time move to cube -> to cause an impact !
                    newYForce = -2.5 * EngVar.time_step;
                }

                // c_move to new position to trigger impact event !
                me.c_move(
                    new Vector(0, newYForce, 0),
                    new Vector(0, 0, 0),
                    Flags.GLIDE);

                yield return 1;
            }
        }

        private static IEnumerable<ScheduleMethod> testEntityMethodEvent()
        {
            if (EngVar.event_type == Flags.EVENT_CLICK)
            {
                Console.WriteLine("Flags.EVENT_CLICK");
            }
            if (EngVar.event_type == Flags.EVENT_IMPACT)
            {
                Console.WriteLine("Flags.EVENT_IMPACT");
            }
            if (EngVar.event_type == Flags.EVENT_FRAME)
            {
                Console.WriteLine("Flags.EVENT_FRAME");
            }

            // there's nothing to wait for...
            yield break;
        }

        private static IEnumerable<ScheduleMethod> testEntityMethod(IntPtr e)
        {
            ENTITY me =
                ENTITY.createFromPointer(e);

            // cube should be blue
            me.LIGHT = true;
            me.red = 0;
            me.blue = 255;
            me.green = 0;
            me.lightrange = 0;

            // enable some events...
            me.ENABLE_FRAME = true;
            me.ENABLE_IMPACT = true;
            me.ENABLE_CLICK = true;

            // high push value
            me.push = 1000;

            me.event_ = testEntityMethodEvent;

            // nothing to wait for here...
            yield break;
        }
 
        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // limit frame rate
            EngVar.fps_max = 60;

            // load an empty level
            EngFun.level_load(null);

            // use mouse
            EngVar.mouse_mode = 4;

            ENTITY testEntity =
                ENTITY.ent_create("_CUBE.MDL", new Vector(200, -25, 0), testEntityMethod);

            ENTITY testEntity2 =
                ENTITY.ent_create("_CUBE.MDL", new Vector(200, 25, 0), testEntity2Method);
 
            yield return ScheduleMethod.wait(1);
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/17/12 09:23

Thanks!
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/17/12 10:19

in case of testEntityMethodEvent, how do i use the entity skills? is there a way to reach that ent?

Scratch that. EngVar.me
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/20/12 09:58

Okay, another question.
How do i get the "final_bits" of a BMAP? or how do i access the NativeBMAP struct from a BMAP?
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/20/12 10:53

getting information from the NativeBMAP is quite easy :
- get the pointer from the BMAP object
- use Marshal.PtrToStructure to get the content

you should be able to do this with all objects, like NativeENTITY etc...

Code:
BMAP someBmap = BMAP.bmap_create("someBmap.bmp");

AcknexWrapper.Native.NativeBMAP nativeBmapStruct =
    (AcknexWrapper.Native.NativeBMAP)System.Runtime.InteropServices.Marshal.PtrToStructure(someBmap.getIntPtr(), typeof(AcknexWrapper.Native.NativeBMAP));

IntPtr final_bits = nativeBmapStruct.finalbits;



if you want to change such a variable (that is normally not used and thus not implemented in the wrapper.. things are not that easy.. for example to change the finalbits member of the NativeBMAP struct you would have to do the following :

Code:
IntPtr newFinalBitsValue = (IntPtr)234234;
IntPtr positionOfFinalBitsInStruct =
  System.Runtime.InteropServices.Marshal.OffsetOf(typeof(AcknexWrapper.Native.NativeBMAP), "finalbits");

// destination to write to = the pointer to the struct in unmanaged memory + the offset of the finalbits variable in the struct
IntPtr positionToWriteTo =
  (IntPtr)(
    (int)someBmap.getIntPtr() +
    (int)positionOfFinalBitsInStruct);
            
// write the new value to the position in the memory where the finalbit part of the
// struct is stored
System.Runtime.InteropServices.Marshal.WriteIntPtr(positionToWriteTo, newFinalBitsValue);



P.S.:
this of course only works for IntPtr in this example, there are several other cases where you have to do conversions etc...
Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/22/12 09:16

It's probably that i'm doing something wrong but,

System.Runtime.InteropServices.Marshal.WriteIntPtr(positionToWriteTo, newFinalBitsValue);

does not seem to be changing final bits
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/22/12 13:26

it appears to work with the example I posted below!

hmmm did you recreate the struct after changing the value (thus creating the struct from the pointer again) ?

I just saw that changing the finalbit variable is a bad idea, because it keeps crashing the engine, probably because of what's written in the sdk_engine\atypes.h file :
Code:
typedef struct BMAP {
...
void	*finalbits;	// bitmap content when locked, otherwise NULL
}


thus it seems that the value shouldn't be changed by the user, because the user can't unlock the bitmap that way...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace eventExample
{
    using AcknexWrapper.Native;
    using System.Runtime.InteropServices;

    public static class FinalBit
    {
        public static IntPtr GetFinalBit(BMAP toGetFinalBitOf)
        {
            NativeBMAP nativeBmapStruct =
                (NativeBMAP)Marshal.PtrToStructure(
                    toGetFinalBitOf.getIntPtr(),
                    typeof(NativeBMAP));

            return
                nativeBmapStruct.finalbits;
        }

        public static void SetFinalBit(BMAP toSetFinalBitOf, IntPtr valueToSet)
        {
            IntPtr positionOfFinalBitsInStruct =
              Marshal.OffsetOf(typeof(NativeBMAP), "finalbits");

            // destination to write to = the pointer to the struct in unmanaged memory + the offset of the finalbits variable in the struct
            IntPtr positionToWriteTo =
              (IntPtr)(
                (int)toSetFinalBitOf.getIntPtr() +
                (int)positionOfFinalBitsInStruct);

            // write the new value to the position in the memory where the finalbit part of the
            // struct is stored
            Marshal.WriteIntPtr(
                positionToWriteTo,
                valueToSet);
        }
    }


    class Program
    { 
        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // limit frame rate
            EngVar.fps_max = 60;

            // load an empty level
            EngFun.level_load(null);

            BMAP bla =
                BMAP.bmap_createblack(300, 300, 32);

            // print current value
            Console.WriteLine(FinalBit.GetFinalBit(bla));

            // change the finalbit value
            FinalBit.SetFinalBit(bla, (IntPtr)12345);

            // print current value
            Console.WriteLine(FinalBit.GetFinalBit(bla));

            yield return ScheduleMethod.wait(1);
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/22/12 15:28

I've used finalbits in c++ plugin sdk and it was working fine this way

bmap_lock..
change parts of finalbits
bmap_unlock

but there seems to be something i cannot see here, changing kinda feels like i am changing the finalbits but not writing to the real struct engine is using.

Anyway i do not really HAVE TO use finalbits, i just need change parts of bitmaps in an efficent way. pixel_to_bmapping pixel by pixel is way too slow for that, do you have any other suggestions?
Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/23/12 07:48

after using real values for the finalbits (0 and the IntPtr to the EngineObject) and additionaly adding a wait after loading the level, it seems to work just fine ! I changed the code to use the methods the wrapper uses internally, so less code and additonally it should be faster, because for getting the value, now only the IntPtr is read, not the whole struct !

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace eventExample
{
    using AcknexWrapper.Native;
    using System.Runtime.InteropServices;

    public static class FinalBit
    {
        private static IntPtr GetPointerToFinalBit(BMAP bitmap)
        {
            return
                (IntPtr)(
                    (int)bitmap.getIntPtr() +
                    (int)Marshal.OffsetOf(typeof(NativeBMAP), "finalbits"));
        }

        public static IntPtr GetValue(BMAP bmap)
        {
            return
                Conversion.getIntPtrFromIntPtr(
                    FinalBit.GetPointerToFinalBit(bmap));
        }

        public static void SetValue(BMAP bmap, IntPtr value)
        {
            Conversion.setIntPtrFromIntPtr(
                FinalBit.GetPointerToFinalBit(bmap),
                value);
        }
    }

    class Program
    { 
        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // limit frame rate
            EngVar.fps_max = 60;

            // load an empty level
            EngFun.level_load(null);

            yield return 1;

            BMAP bla =
                BMAP.bmap_createblack(300, 300, 32);

            // print current value
            Console.WriteLine(FinalBit.GetValue(bla));

            // change the finalbit to Zero and storing the current value
            IntPtr currentFinalBitValue =
                FinalBit.GetValue(bla);
            FinalBit.SetValue(bla, IntPtr.Zero);

            // print current value
            Console.WriteLine(FinalBit.GetValue(bla));

            // change the finalbit from Zero to the stored value
            FinalBit.SetValue(bla, currentFinalBitValue);

            // print current value
            Console.WriteLine(FinalBit.GetValue(bla));

            yield return ScheduleMethod.wait(1);
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: Quad

Re: C# wrapper 2.3.3 - RELEASE - 02/23/12 15:52

That is, if you don't lock/unlock bmap.

Engine is supposed to fill finalbits when the bmap is locked. When you unlock the bmap it should read the finalbits and change the bitmap. This is the part that is not working.

When you don't lock/unlock bmap engine does not change the finalbits. Whatever you put there you get it back.

I get the feeling even if i lock/unlock bmap i still get some different memory field that is not the real finalbits. Engine never modifies the data in the field we are looking at.(F.i) it should be empty when bmap is locked, and it should have bits when it's locked. With the above code it always gets the same value wether bmap is locked or not. Could be an engine bug. I will try different stuff now.

i wrote the following function in a c++ dll, and pinvoked it from c# as a workaround.

Code:
extern "C" __declspec(dllexport) void setFinalBits(BMAP* bmap,byte* data,int size)
{
	bmap_lock(bmap,0);
	memcpy(bmap->finalbits,data,size);
	bmap_unlock(bmap);
}


Posted By: Stromausfall

Re: C# wrapper 2.3.3 - RELEASE - 02/23/12 19:55

indeed !
i think i found the problem -> NativeBMAP.cs contains a wrong member ....
currently it is (I'll make a new version of the wrapper available asap):

Code:
namespace AcknexWrapper
{
    namespace Native
    {
        [StructLayout(LayoutKind.Sequential)]
        internal struct NativeBMAP
        {
            public NativeC_LINK link;
            public int width, height;
            public int bytespp;
            public IntPtr ptr;
            public IntPtr pixels;
            public int flags;
            public IntPtr d3dtex;
            public double u1, v1, u2, v2;
            public int u, v;
            public int refcount;
            public int finalwidth, finalheight, finalbytespp;
            public int pitch, finalpitch;
            public int miplevels;
            public int finalformat;
            public IntPtr finalbits;
        }
    }
}



but it should be ... (and it works that way - thus the value changes correctly it seems when locking and unlocking...)

Code:
namespace AcknexWrapper
{
    namespace Native
    {
        [StructLayout(LayoutKind.Sequential)]
        internal struct NativeBMAP
        {
            public NativeC_LINK link;
            public int width, height;
            public int bytespp;
            public IntPtr ptr;
            public IntPtr pixels;
            public int flags;
            public IntPtr d3dtex;
            public float u1, v1, u2, v2;
            public int u, v;
            public int refcount;
            public int finalwidth, finalheight, finalbytespp;
            public int pitch, finalpitch;
            public int miplevels;
            public int finalformat;
            public IntPtr finalbits;
        }
    }
}



sorry for the hassle ! it was a stupid mistake on my part -.-
Posted By: Stromausfall

Re: C# wrapper 2.3.5 - RELEASE - 02/23/12 20:07

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- fixes a bug in the NativeBMAP struct - big thanks to Quad !

here's the link:

AcknexWrapper_2_3_5_FOR_8_30_4_AND_7_85_4.zip
Posted By: Quad

Re: C# wrapper 2.3.5 - RELEASE - 02/24/12 08:02

Big thanks to you too!
Posted By: Michael_Schwarz

Re: C# wrapper 2.3.5 - RELEASE - 02/28/12 20:18

The panel pan_setbutton allows to assign functions to button events. But it is a EventVoid, when in-fact the manual states:

"Several buttons may share the same function. The number of the button is passed as the first parameter to the function (1 = first button), the panel pointer is passed as the second parameter. "

Can you change it to an EventObject? EventVar?
Posted By: Stromausfall

Re: C# wrapper 2.3.6 - RELEASE - 02/29/12 15:11

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- pan_setbutton now passes EventVar instead of EventVoid methods (allows to use a method for multiple panel elements - like buttons, toggle or radio) - big thanks to Michael_Schwarz !

here's the link:

AcknexWrapper_2_3_6_FOR_8_30_4_AND_7_85_4.zip


P.S.:
@Michael_Schwarz thanks for the suggestion ! That's really a nifty trick for panels oO
Posted By: Michael_Schwarz

Re: C# wrapper 2.3.6 - RELEASE - 03/02/12 05:07

No problem! Thanks for changing it, even though I already altered it myself 8D
Posted By: Stromausfall

Re: C# wrapper 2.3.6 - RELEASE - 03/02/12 08:16

^^
Posted By: Stromausfall

Re: C# wrapper 2.3.7 - RELEASE - 03/20/12 20:49

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- entity skills can now be accessed via an array (big thanks to Pararealist!):

Code:
// skill1 == skills[0] - compare to Gamestudio Manual skill1 ... skill100 entry !
tempEntity.skill75 = 71;
Console.WriteLine(tempEntity.skill75);
Console.WriteLine(tempEntity.skills[74]);

tempEntity.skills[74] = 17;
Console.WriteLine(tempEntity.skill75);
Console.WriteLine(tempEntity.skills[74]);




here's the link:

AcknexWrapper_2_3_7_FOR_8_30_4_AND_7_85_4.zip
Posted By: pararealist

Re: C# wrapper 2.0 - RELEASE - 03/21/12 16:43

I was wondering, how many people are coding with C# and AcknexWrapper?
Posted By: Quad

Re: C# wrapper 2.0 - RELEASE - 03/21/12 18:48

I do
Posted By: pararealist

Re: C# wrapper 2.0 - RELEASE - 03/22/12 11:31

@ Quad: I know.

@Matthias,
Just to let you know:
Problems when compiling the AW lib.

D:\VISUAL STUDIO ULTIMATE 2010 PROJECTS\C#\USING A8 WRAPPER\AcknexWrapper\AcknexWrapper\EngineObjects\ENTITY.cs(88,25): error CS0246: The type or namespace name 'VarIndexer' could not be found (are you missing a using directive or an assembly reference?)

In ENTITY.cs

/// <summary>
/// Gets or sets the skills at the given index
/// </summary>
public readonly VarIndexer skills;


EDIT: me ijit, forgot to re-add my reference.
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 05/13/12 10:22

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- several bugfixes for the MATRIX class (big thanks to Pararealist!):

here's the link:

AcknexWrapper_2_3_8_FOR_8_30_4_AND_7_85_4.zip
Posted By: pararealist

Re: C# wrapper 2.0 - RELEASE - 05/13/12 10:52

Wow, that was fast. Thought i was doing something wrong.
(Now i have visions of you sitting there waiting for a problem, and then fixing it.) smile.
Will try it later when i get home.
Hope i can then get my shaders working properly now.
Thx.

Forgot to ask about EngVar.mtl_Hdr ?
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 05/13/12 11:16

mtl_hdr isn't directly implemented in the acknex engine, it's defined in the include/mtlView.c file in the acknex install folder.
To use mtl_hdr, you would have to simply transcribe/rewrite the effect to/in c#. If you're having problem with that, let me know !
Posted By: pararealist

Re: C# wrapper 2.0 - RELEASE - 05/13/12 12:20

Thought as much. I had started doing that(transcribe/rewrite the effect to/in c#. ), then came across the matrix problem.
I probably will get back to it sooner or later.
I am doing so many things at once, plus living as well.
Posted By: jenGs

Re: C# wrapper 2.0 - RELEASE - 06/01/12 16:33

Hey,
is it possible to document the use of a button event?
I don't get the syntax right. I tried
"public static IEnumerable<ScheduleMethod> SetMode(IntPtr ptr)"
It doesn't work.
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 06/02/12 11:30

Something like this (a button with events that are triggered) ? Or something else ?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AcknexWrapper;

namespace ButtonExample
{
    class Program
    {
        private static BMAP button1On;
        private static BMAP button1Off;
        private static BMAP button1Over;
        private static PANEL mainPanel;

        private static IEnumerable<ScheduleMethod> buttonClick(double p)
        {
            Console.Write("button clicked");
            yield break;
        }

        private static IEnumerable<ScheduleMethod> buttonLeave(double p)
        {
            Console.WriteLine("mouse left button");
            yield break;
        }

        private static IEnumerable<ScheduleMethod> buttonOver(double p)
        {
            Console.WriteLine("mouse is over the button");
            yield break;
        }

        private static void CreatePushButton()
        {
            // create BMAPS for button (and change their color)
            Program.button1On =
                BMAP.bmap_createblack(200, 200, 32);
            Program.button1Off =
                BMAP.bmap_createblack(200, 200, 32);
            Program.button1Over =
                BMAP.bmap_createblack(200, 200, 32);

            Program.button1On.bmap_fill(new Color(200, 0, 0), 100);
            Program.button1Off.bmap_fill(new Color(100, 0, 0), 100);
            Program.button1Over.bmap_fill(new Color(150, 0, 0), 100);

            // create a button in the panel
            Program.mainPanel.pan_setbutton(
                0,
                1,
                50,
                50,
                Program.button1On,
                Program.button1Off,
                Program.button1Over,
                Program.button1On,
                Program.buttonClick,
                Program.buttonLeave,
                Program.buttonOver);
        }

        //the main method, called by the scheduler
        private static IEnumerable<ScheduleMethod> myMainMethod()
        {
            // create the main panel and make it visible
            Program.mainPanel =
                PANEL.pan_create(null, 1);
            Program.mainPanel.SHOW = true;
            Program.mainPanel.size_x = EngVar.screen_size.x;
            Program.mainPanel.size_y = EngVar.screen_size.y;

            // Shows how to create a simple push button and assign functions to it
            Program.CreatePushButton();

            // use mouse !!
            EngVar.mouse_mode = 4;

            yield break;
        }

        static void Main(string[] args)
        {
            //open the engine
            EngFun.engine_open(null, null);

            //start the scheduler
            Scheduler.StartScheduler(myMainMethod);
        }
    }
}


Posted By: jenGs

Re: C# wrapper 2.0 - RELEASE - 06/02/12 13:52

Ahh, yes. the parameter is a double ... never guessed that.
Ah, now I looked into the source code and saw it.
Thank you for your help.
Is it possible, that the engine is slower since the last update?
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 06/02/12 22:49

hmmm i can't imagine that the update could have affected the speed...
do you have an idea where the bottle neck could be ?
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 06/06/12 14:34

a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

- changing Scheduling of method now also possible without a previous "yield return 1" – big thanks to Timothy and pararealist

here's the link:

AcknexWrapper_2_3_9_FOR_8_30_4_AND_7_85_4.zip
Posted By: pararealist

Re: C# wrapper 2.0 - RELEASE - 06/07/12 07:15

Thanks.
Posted By: Arrovs

Re: C# wrapper 2.0 - RELEASE - 11/08/13 10:45

I have small question.
Engine objects like PANEL, TEXT and others gets managed by garbage collector or i need to remove them myself still, when usign C# and this wrapper.
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 11/08/13 18:15

now they only wrap the objects so you have to delete them with the matching functions (like in lite-c)
Posted By: Arrovs

Re: C# wrapper 2.0 - RELEASE - 11/14/13 00:03

Found out that when using class destructor for cleaning up lite-c structs is just like miracle wand. Now i never want to leave C#.

And by the way layer property should be double as it can be 3.01 too not only int. Even in PANEL class it gets converted as double.

And why here isnt implemented randomize() function, but random() and random_seed() is? Without that function all others is useless.

And i hope MULTIMEDIA gets managed by C# as there is no such object in lite-c.

And could it be when closing 3DGS window C# is running for some frames after? Im saying because im getting corrupt memory message then, but when closing console window first it didnt happens. Ahh. Found out it is destructor. Seems when i said it to remove unmanaged resources it cant do it when 3DGS is already closed. It was easely fixable by adding static variable which on engine exit lets C# know it.

Also you could tell how to get rid of that console at final version.
Posted By: Arrovs

Re: C# wrapper 2.0 - RELEASE - 11/18/13 10:33

How does your wrapper handles TEXT object strings?
As i saw it uses string copying to native TEXT structs.
But that way copying makes string still managed or is it copied through lite-c function and gets unmanaged?
I say this because TEXT strings need to be manually removed from TEXT before you remove that itself. It is even said in manual.
But if this is true that strings will stay in memory.

Also i dont like TEXT.strings property as it now allows only to set and get whole array. it could even stay so, but you should warn users. Cant get out one element so i need to use getString.
Posted By: Stromausfall

Re: C# wrapper 2.0 - RELEASE - 11/20/13 21:41

I haven't used the acknex engine for some time now and currently am not planning to - unfortunately I can't help you with most of them as it's very rare that I visit this site anymore... and don't remember that much about the wrapper anymore to help you without digging into the materia myself - I'm sorry !

>>Also you could tell how to get rid of that console at final version.
change the type of your application from console to I think Application in the project properties
Posted By: Arrovs

Re: C# wrapper 2.0 - RELEASE - 11/21/13 04:54

Pity you here left your project, this wrapper is best thing what ever happened with this engine.
Posted By: FBL

Re: C# wrapper 2.0 - RELEASE - 01/03/14 12:35

Yes. C# together with proper tooling (editors!) would help the engine a lot.
Anyway I remember looking at some code of the wrapper and it really helped me to get the engine running in an managed Winforms environment and dealing with marshalling. I used C++/CLI, but the methods were pretty much the same.

Very useful project laugh
© 2024 lite-C Forums