C# wrapper - RELEASE

Posted By: Stromausfall

C# wrapper - RELEASE - 07/09/09 09:15

Hi !
I'm very proud to release Version 1.0 of the C# Wrapper for A7, it wraps 100% of the engine_sdk ! The wrapper allows the experienced A7 and C# user to create applications and games withouth the use of unsafe code !
On my site : acknexwrapper.matthias-auer.net
you find the wrapper, a manual that contains some tutorials and some info about the wrapper, plus a samples archive that contains the source and the compiled version of the projects explained in the "get Started" section of the manual.

Important : It is not advised to use the wrapper if you don't know object-oriented languages or C#, because C# uses a different programming paradigm than lite-c !

ATTENTION: a new version is on it's way, that may change naming conventions, so only use this version of the wrapper for a first glimpse at using a7 in C#

Post here questions, feedback or problems. If you know topics that should be covered in the manual and are not covered yet - send me an e-mail (mail@matthias-auer.net) or post in this thread!
Posted By: VeT

Re: C# wrapper - RELEASE - 07/09/09 09:16

wow... i'll look there
Posted By: the_mehmaster

Re: C# wrapper - RELEASE - 07/09/09 10:30

Awesome! i have been waiting ages for something like this!
Posted By: amy

Re: C# wrapper - RELEASE - 07/09/09 10:35

Great job!

From the manual it looks like you have to write very verbose code though which always is about twice as long as the corresponding Lite-C code. Can't you hide away stuff like the var conversions like ventilator did for his python wrapper?

It would be nicer if Entity and Vector and so on could be used like real classes. e = new Entity() instead of ent_create(), vectors with overloaded operators,...

Would C# also make it possible to use generators and yield() for a scheduler?

Can the wrapper be used with other .NET languages?
Posted By: maslone1

Re: C# wrapper - RELEASE - 07/09/09 10:37

Stromausfall, is not a name for a person like you.....
You should call yourself "The great coding Hero",
or "Strom-Maker",......

Thanx for your realy great contribution!

Cheers Marcel
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/09/09 11:00

i can't hide the var conversions because else it wouldn't be possible to use a var with a pointer.
about the idea to create the entity in the engine with the constructor - that's a great idea, i'll implement that !
I will also look into operator overloading for vectors, but not sure about that yet ^^
about the scheduler, i once created a scheduler, but the performance was quite bad - so it's better to use EVENT_FRAME (as i have heard) for that or a list that contains all functions to call in the while loop which is traversed and thus the functions are called.

No the wrapper can only be used for C# - not for all .net languages
Posted By: boyax

Re: C# wrapper - RELEASE - 07/09/09 11:00

cool! Thanks for this contribution! smile

Cheers,
boi
Posted By: seecah

Re: C# wrapper - RELEASE - 07/09/09 11:10

Nice.. Very very cool.. I would appreciate much if anybody can show here a simple game using C# already.. :-)

I'll try this..
Posted By: amy

Re: C# wrapper - RELEASE - 07/09/09 11:37

Quote:
i can't hide the var conversions because else it wouldn't be possible to use a var with a pointer.
Why do you need to use var with a pointer?

Quote:
about the scheduler, i once created a scheduler, but the performance was quite bad - so it's better to use EVENT_FRAME (as i have heard) for that
How did your scheduler work?

Quote:
or a list that contains all functions to call in the while loop which is traversed and thus the functions are called.
Actually I thought that's exactly what a scheduler does?

The advantage of a scheduler that uses yield() would be that it could work exactly like using wait() in Lite-C. That's what we all are very used to so it would be nice to have.
Posted By: enrike

Re: C# wrapper - RELEASE - 07/09/09 11:55

i think i did all steps correct but i get this error... any ideas? i am using VStudio 2008 and GameStudio Pro 7.06

Error 1 The command "CD C:\
C:\Program Files\GStudio7\WED.exe -p D:\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe" exited with code 9009.

It does not create the acknex.dll in the debug folder. i did the whole process again and get the same problem. I double checked the paths and they seem fine as far as i can see.

just found this
http://my-tech-talk.blogspot.com/2008/11/error-9009-in-visual-studio-means.html
so edited the WED path to "C:\Program Files\GStudio7\WED.exe" -p D:\c_sharp_wrapper_A7\ConsoleApplication1\ConsoleApplication1\bin\Debug\FirstTestProgram.exe

now it runs it but crashes after opening the engine, cannot see amything. i can see A7 startup says "3 objects" then the white startup window quits and all crashes. i tried to compile some of the examples with same result.

Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/09/09 11:58

A Var that doesn't contain a value, but a pointer is for example needed if you want to add a digits element to a panel. There you need to give a Var pointer to the engine - to ensure that the value is displayed in the panel that the Var object in C# has. Without a pointer in the Var it also wouldn't be able to display the current time in a panel - you would have to update the time every frame, with pointers you don't have to worry about this.

The scheduler i wrote created a thread for every function that was called by the engine (for example a function one gives as parameter if you create a ENTITY object). After an engine_frame it started to stop the current thread and started a thread in the list, after that thread ended or reached a wait, the current thread was stopped and the next thread in a list was started ...
But in the end it was just too slow to be usefull ^^

The difference between calling functions every frame and a scheduler is afaik, that if you have a scheduler you can use wait, and thus, when the function's turn has come, it doesn't need to go through the whole function, but may start after the wait command.
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/09/09 11:59

Thx very much.
Was playing with a previous wrapper posted here
adding more acknex stuff but will try
this one as ALL acknex is already added.
//
My level will not load, either from the level folder
in the project folder
Code:
a7.EngFun.level_load( (String)"..\\gsDefaults\\default.wmb" );


or directly from the project folder
Code:
a7.EngFun.level_load( (String)"default.wmb" );


So i am off to check why.
//
Everything else is fine though
and thanks again for your work.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/09/09 12:07

hmmm afaik this error may be thrown if the paths aren't correct. You didn't write the commands under quotation marks or (this would be wrong) ?

P.S.: you should really update Acknex to 7.77 because the wrapper is built towards 7.77
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/09/09 12:10

the second version should work, did you put the wmb file into the Debug/bin folder of your project ?
Posted By: ventilator

Re: C# wrapper - RELEASE - 07/09/09 12:26

thanks for working on this! having a c# wrapper for a7 is very nice. i also would try to reduce the amount of unnecessary verbosity though. i am no c# expert but i am sure it's possible to make it much more convenient to use.



def_debug_pan.setdigits(0, 0, 12, "fps%5.0f", ackfont, lambda: def_dfps * 16)

in python using pointers isn't possible at all so i use lambda expressions for panel elements. internally i have a big var array for panels which gets updated each frame by calling the lambdas that got registered for panel elements. it works great and even is much more powerful than simply passing a pointer. for example it supports local variables and arbitrary expressions.

lambdas are available in c# too.



i wouldn't use threads for the scheduler. the lite-c scheduler doesn't use threads either. it uses coroutines. coroutines can be simulated by generators in python and c#. you could look into the source of my scheduler. it's really simple.



just some ideas. smile
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/09/09 12:52

Thank you ventilator for your input !
I will look into coroutines - they could be the key ^^

your approach to simulating pointers is also quite interesting ! the c# wrapper is able to get a pointer of a local variable but not of arbitrary expressions - lambda may be worth a look ^^.
Posted By: Schmerzmittel

Re: C# wrapper - RELEASE - 07/09/09 12:59

Originally Posted By: enrike
i think i did all steps correct but i get this error... any ideas? i am using VStudio 2008 and GameStudio Pro 7.06



Use a legal version, then it works.
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/09/09 15:19

@Stromausfall
Tried in all the places
project folder
debug/release folder
(my) gsdefaults folder

but they load in my original c# project
so i know i' just need to look a little closer
at the problem.
No worries, will definately solve this when i get time
to concentrate

OK- fine now
should be in debug folder, but settings were to release folder
(knew it was something simple).
Posted By: MichaelGale

Re: C# wrapper - RELEASE - 07/09/09 23:38

I hate being negative about something, but I see a few issues with your wrapper that would stop me (personally) from using it:

1. your code doesn't follow the C# coding conventions at all and this is a really big issue as far as I am concerned because, especially in larger projects, continuity of style is important to ensure maintainability
2. there is no validation whatsoever anywhere in your wrapper
3. nested classes should not be used in the way you used them
4. the statement in your first post "withouth the use of unsafe code !" is obviously wrong since most of your code is unsafe and when the methods in your wrapper are called, unsafe code is executed - it's just less obvious.

Michael
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/10/09 05:58

about points 1-3 i will look into them, i have to admit that i don't have yet any knowledge about these mentioned points, but i will try to learn about these points and integrate them in the next rewrite of the wrapper!
about point 4, actually i wanted to say the user of the wrapper doesn't need to use unsafe statements, that didn't imply that the wrapper doesn't use unsafe code ^^

Thanks for your input, these seem to be points that i should learn about!
Posted By: MichaelGale

Re: C# wrapper - RELEASE - 07/10/09 06:29

For the coding conventions, I can recommend you to read this article. Obviously you don't need to stick 100% to that, but especially as long as you following the naming conventions you will improve the quality of your code tremendously.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/10/09 06:59

Thank you for the link, i will have a look at that article !

I really appreciate your help.
Best regards,
Matthias
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/10/09 11:11

Nice attempt.

Just use this in the Post-build...

Code:
"C:\Program Files\GStudio7\WED.exe" -p "$(TargetDir)\$(TargetFileName)"


Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/10/09 11:28

that's a lot better I'll change it in the manual for the next release!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/10/09 21:07

Could you provide a sample that uses the engine with a windows form project.
I think the main reason we all want a C# wrapper is to be able to use other .NET controls as well.

So how would you render the engine into a .NET form? Maybe you can pass a HWND handle or something.
Posted By: Stromausfall

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

Look in the EngVar, there are some IntPtr like hwnd, hwndparent, hwndtarget and pRectTarget (which points to some RECT struct afaik) - they should do the trick i think. I'm sorry but i didn't work with windows forms yet and thus can't provide you with any help reagrding this topic at the moment.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/11/09 17:54

hi i'm trying to get a basic app running. I do all the steps in the manual and i use code straight out of the manual.

I run my program, WED pops up and it says "acknex.dll" so i know the DLL is copied correctly. Then the engine pops up but says...

"(name of program).vshost.exe damaged"

... and it just crashes. I checked my post build and I have set it to the the correct .exe, why is it using the .vhost.exe one?

Maybe i'm missing something.

EDIT > I can run the program if i manually go into the project folder and start the .exe. Just wondered why this isnt automated when i press F5.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/11/09 18:32

a7.EngVar.d3d_lockable is read-only. To allow rendering into a target window this needs to be set to 1. I can try and add a set clause, but i haven't worked with unsafe code really.
Posted By: Stromausfall

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

hi about the problem with vshost.exe it looks like you haven't disabled the "Visual studio hosting process" you can disable it under project proberties, debug -> "Enable the Visual studio hosting process".
If you disable the visual studio hosting process it should work fine afaik.

only the Var object for a7.EngVar.d3d_lockable is read-only. You can still set it's value ->
a7.EngVar.d3d_lockable.IntValue = 1;
sets the value of d3d_lockable to 1.
I hope this helps, if you still got problems don't hesitate to post !

cheers,
Matthias

P.S.: I'm currently creating a new version of the wrapper, where names may and will differ from the current version, so only use this version for testing ^^
Posted By: AlexDeloy

Re: C# wrapper - RELEASE - 07/11/09 22:25

Awesome work, thanks

Tried to run on a 64bit system resulted in a BadImageFormatException
If anyone else is experiencing this problem here is how to solve it:

Set a new platform type in the configuration manager,
Build menu -> Configuration Manager -> Platform -> new -> new platform x86
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/11/09 23:30

@Stromausfal

Hi, i am looking for the acknex var texname.

a7.EngVar.hit. has no texname ?
or else how to find/use it ?

thanks.

MOD: delete this

Posted By: pararealist

Re: C# wrapper - RELEASE - 07/14/09 00:10

@Stromausfal

Hi, i am looking for the var texname.

a7.EngVar.hit. has no texname ?
or else how to find/use it ?

thanks.

(Sorry for double post)
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/14/09 09:40

Hi ! currrently hit is only a IntPtr that first needs to be cast to an EngObj.Contact (maybe i'm able to change this for the next release^^)!
here's an example :

String texname = ((a7.EngObj.CONTACT)a7.EngVar.hit).texname;

-> this should work!

cheers,
Matthias
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/14/09 10:49

Thanks, will try this later.

Good work you've done so far.
Looking forward to next release.
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/17/09 08:18

While playing with a7Wrapper:

If you use this loop

Code:
while (a7.EngFun.engine_frame() != 0) 
{ 
	UpdateAcknex(); // update your acknex stuff here
	Application.DoEvents(); //Add this here 
}




//set your acknex window to size

Code:
//get the x/y pos 
int left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left;
int top = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top + 
                                                       Program.gamePlayForm.Height;
//get the w/h
int right = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;
int bottom = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - top;

//place the position (left,top)/ (right/bottom) in vectors 
a7.Vector vWinPos = new a7.Vector((a7.Var)left, (a7.Var)top, (a7.Var)0);
a7.Vector vWinSize = new a7.Vector((a7.Var)right, (a7.Var)bottom, (a7.Var)0);

//set title
String winTitle = "Engine: ";


//place the window at position (left,top)
a7.EngFun.video_window(vWinPos, vWinSize, (a7.Var)2, winTitle);



//and dont forget to close acknex engine in your form exit

Code:
//QUIT
private void quitToolStripMenuItem_Click1(object sender, EventArgs e)
{
    //close engine
    if(a7.EngFun.engine_frame() != 0)
         a7.EngFun.engine_close();
    //and exit
    Application.Exit();
}



Then you can have forms as well as the acknex window working together like Gimp windows does.



//
forgot this:
Also use this

Code:
while(1)
{
      ... other stuff

   /// this is equivalent to wait(1)
   a7.EngFun.engine_frame(); break;
}


Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/17/09 08:48

Thank you for sharing this code with us !!
That's a great contribution !!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/21/09 11:28

Is a7.EngFun.engine_frame() analagous to wait(1)?

I'm experimenting with window handles and the Win32 API and i'm using vars such as a7.EngVar.hWnd and a7.EngVar.hWndTarget. The manual states that these variables only become available after 1 frame, so wait(1) is needed.

I'm using the API call GetWindowText to test if I can get the text of the engine Hwnd...

Code:
[DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Ansi)]
        public static extern bool GetWindowText(IntPtr hWnd, [OutAttribute()] StringBuilder strNewWindowName,
            Int32 maxCharCount);

        static void Main(string[] args)
        {
            a7.EngFun.engine_open(null);
            a7.EngFun.engine_frame(); // acts as wait(1) ???

            StringBuilder sb = new StringBuilder(256);
            GetWindowText(a7.EngVar.hWnd, sb, sb.Capacity);
            MessageBox.Show(sb.ToString());

            while (a7.EngFun.engine_frame() != 0)
            {

            }
        }
    }



...But every time the string buffer is empty. I've tested this code on other applications like notepad.exe, by getting it's handle, and it returns the name in the title bar no problems.

So is there a problem with my code? Or are the engine vars not functioning properly?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/21/09 12:58

Yes in this case a engine_frame() call should be equivalent to wait(1). I just tried to use hwnd and you are right, there seems to be a problem, because hwnd seems to be always 0. I'll look into that right now ^^
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/21/09 14:04

@DJBMASTER : sent you a pm with a test version
Posted By: DJBMASTER

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

Hi, Ok i was wondering if the form rendering issue was due to the difference of a C# form. I decided to investigate by not using a C# form and creating a form programmatically from WinAPI.

This is exactly the same process that C++ uses, and I can get the engine to target render in c++ no problems.

I used exactly the same methods/properties I used in C++ and the window appears no problem but still the engine wont render into it.

From this i can only conclude that it is the fault of the wrapper. It might not be marshalling the type correctly or something.

I know you have no experience with C# forms Stromausfall, but if you use WinAPI you will see the engine still wont render.

Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/24/09 06:55

Ah ok, if i get some spare time i will maybe look into c# forms and thus be able to investigate where the problem lies ^^
Could you send me an example for the WinAPI and/or form ?
Posted By: pararealist

Re: C# wrapper - RELEASE - 07/24/09 08:00

With the older wrapper was the same problems.
No problem rendering in C++
but trying to render into a form was a no go.
I thought it was me.
//
Maybe the other way (see above) is ok, only problem is that it works and looks like Gimp windows. This seems to be better for applications anyway i think. No problems using it this way,
and you can add System.Threading too. I am building my classes
and hoping that a7Wrapper does not change too drastically, but
still this should not affect my classes too much, and i can just use them with the new updated wrapper.
//
@Stromausfall
There are some probs with a7.Delegate and/or a7.DelegateEvent
or i cannot overstand it in your manual, perhaps a clear(er) example?
I was trying to delegate an event for EventLoad(percent).
but it seems to not want to work.
//
@anyone
ARGHHHH the posting form is driving me mad, it keeps jumping away from the line you are writing back to the top of the page???
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/24/09 08:07

yepp you are right in this version of the wrapper the delegates are kind of messed up, but in the new version there are delegates that match all types of events including the ones that pass an int -> like on_level (that's what you meant with eventload(percent) or ?
The new version of the wrapper should be ready, i only need to update the manual and maybe add a page, but i should be able to upload the new version of the wrapper today.

Concerning the forms: here's the post pararealist is speaking of, concerning the c# form problem, afaik : http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=111527&page=1
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 08:14

@ pararealist > Yeh that way of displaying the forms does work, but i'm building an MDI application, and so i would need to embed the form into the application. I don't know if SetParent(...) will work for this.I'll have a look...

Also, Stromausfall, have you ever considered using C++/CLI to load the engine into a .NET environment. Here is an article that showed how they embedded a directX engine into C#.

http://www.gamedev.net/reference/articles/article2526.asp

I know you wouldn't really want to do this after all the work you have started but just a thought.

Either way I'd say your the first to come this far with C#, and i do appreciate it.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 08:54

hmmm SetParent(...) actually works. I just created a MDIParent Form in my application, loaded the engine, and used SetParent(a7.EngVar.hWnd,myform.Handle);

You do have to do a bit of sizing and positioning, but i use SetWindowPos, which can perform sizing, positioning and Z-order editing. It doesn't seem that bad.

Here is a screeny...



I'm sure there is a Win32 function that can remove the Title and close button from the engine window... I'll try and find that now...
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/24/09 09:19

Great Work !
actually you can remove the title, the border and the close button via the acknex function video_window afaik!
a7.EngFun.video_window(null, null, (a7.Var)1, "MyTitle");
that should do the trick!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 09:53

LOL, i went the hard way and used win32, i forgot about video_window.

Here is how it looks now after modifying the engine window...



This seems to be promising although there might be a couple of issues with hooking input and resizing when the parent form is moved / resized. I think on_message can be used to send the engine's message loop to another window.

I'll keep at it and post the code if anyone wants it. There is a restriction that it will only work for a MDIForm, so we would still need the hWndTarget working to render into other forms/controls.

This method of embedding the form inside a parent form doesn't actually need to use any part of the wrapper. You can do this by running Process.Start(), and retrieving the handle to the engine window. I just used the wrapper because it exposes the hWnd variable nicer.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/24/09 10:03

That's great!
I have no clue about forms, mdi and stuff, but is mdi an as adequate solution as c# forms ?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 10:17

Ermm well I would say that most Windows Forms applications are MDI, because they allow you to manage child forms easier, and allow you to implement interfaces easier. They also look more professional.

So this 'seems' to be quite a good solution to using Acknex in C#. I emphasise 'seem' because there might be some things i havent encountered yet.

I'm currently creating a MDI application for use with Game Studio, so this solution seems to be fine for me.
Posted By: pararealist

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

@DJBMASTER
Please post code, would be interested to see acknex in MDIForm working.

Didnt they (on this forum somewhere) say to keep away from MDI? Was that real or what?

I'll use both ways to see which works better for my App.


Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/24/09 10:50

Now that's great news i'd say ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 11:46

What am i saying? It isn't restricted to only MDI Forms. .Net controls are essentially windows, and so also expose a handle. I've now got the engine rendering into a Panel control. This gives you a bit more control.

Well here is how you do it...

First you need the Interop namespace...
Code:
using System.Runtime.InteropServices;


Now you need to define the Win32 constants and functions...
Code:
const int WS_VISIBLE = 0x10000000;
const UInt32 SWP_SHOWWINDOW = 0x0040;

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);



Now basically you create a control inside your form. A Panel is a simple one.
Then you call these 3 functions. You should use the Form's 'Shown' event to execute this...

Code:
a7.EngFun.engine_open(null);
a7.EngFun.engine_frame(); // Required else crash (D3D isnt loaded yet)

SetParent(a7.EngVar.hWnd, MyPanel.Handle);
SetWindowLong(a7.EngVar.hWnd, -16, WS_VISIBLE);
SetWindowPos(a7.EngVar.hWnd, (IntPtr)0, 0, 0, MyPanel.Width, MyPanel.Height,
SWP_SHOWWINDOW);

while (a7.EngFun.engine_frame() != 0)
{

}


That's pretty much it. I've created my own control derived from Panel, and wrapped everything inside it.

There are a couple of issues with setting focus to the parent that i'm gonna look into later on today, and i'll update this post.

BTW > WTF is wrong with the forum? Everytime i type something it jusmps to the first line? I've noticed this for a while but now it's getting really annoying!!!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/24/09 12:13

Another good thing about this method is that is seems that 'acknex.exe' isn't registered in Task Manager. Therefore the engine can't be terminated accidently from outside the application.

Also, by rendering into a Panel, you can set it at the back of the Z-order list by using 'Bring-to-front' and 'Send-to-back'. This allows you to define other controls on top of the panel which can recieve focus.

I'm currently controlling the sunlight of the engine by using a TrackBar, LOL.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 12:47

A new version of the AcknexWrapper has been releases, Version 1.1.0.1 !
The change list is in the manual of the AcknexWrapper.
get the AcknexWrapper here : http://acknexwrapper.matthias-auer.net

Unfortunately it is not backwards compatible to Version 1.0, because some names changed.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 12:48

Thank you DJBMASTER, for you great contribution, i guess with your contribution c# got a lot more interesting for some users!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 13:09

Thanks for the update. No problem.

Would you like me to create a sample showing loading the engine into a form and interacting with it? You could then add this to the samples zip. Saves people having to copy all the code from the forum.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 15:33

That would be great and help many people !
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 15:47

Wow, i'm impressed with how much you've updated, Excellent work!!!

I'm having trouble with EngVar.screen_color.I'm trying to change the background colour of the engine by specifying r,g and b values...

I've tried using EngVar.screen_color.red.IntValue = 255; but i keep getting a 'unable to cast AcknexWrapper.Vector to AcknexWrapper.Color' error.
Posted By: amy

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 16:02

Nice improvements! The scheduler looks promising. I still don't like how vars have to be handled. It must be possible to solve this much more elegantly somehow?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 16:41

Thank you ^^
@DJBMASTER: yepp that's a bug i will fix it.
@amy: i also would prefer another kind of handling for vars, but implicit operator won't work, because it can only create a new object afaik. The only other possiblity would be operator overloading, but i think that one can't overload " = " which is essential.
But i would like to keep the var object as it is now, because it allows to pass and use pointers - but maybe another way would also be possible, like something with lambda stuff like ventilator mentionend smirk

But on the other hand this way you have more freedom of how to use Var variables, because you can pass reference. Yes the handling may be not as good as in lite-c but Var is an object and thus handled like an object - which makes sense ^^

Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 17:12

i uploaded a new Version 1.1.0.1 - which should fix the problem with Color and Angle!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 17:34

Thanks, but i'm not getting anything. How would i change the engine background colour?

BTW > Is there a limit to how many times you can load the engine? At the moment i'm only to load one instance of it. I was hoping to achieve mutliple instances in different controls.

Maybe because each one has to reference the same DLL.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 19:28

Not getting anything ? you should be able to change to background color as you tried, with for example : EngVar.screen_color.red.IntValue = 255;
i uploaded the new version to my homepage (It's 1.1.0.1). (I'm a bit confused right now^^)
Concerning how many times one can load the engine, i think that one can only load the engine once, because commands like engine_frame() don't take any parameters that would identify an instance.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 20:04

Beautiful update, thank you very much.
love it.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/24/09 20:07

Thank you ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/25/09 08:03

hmmm, When you load the engine, any other forms in the same application get taken over. I mean their cursors are changed to the same one as the engine, and it is really difficult to use controls, because the cursor wont change.

I don't think this is normal because I tested running a new instance of the engine (by running acknex.exe) and it doesn't control the form it was loaded from.

This is a major problem if using the wrapper with a form application.

btw > still can't get screen_color to change, LOL.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/25/09 18:19

Argh! this is driving me insane. I've tried everything I can think of to stop the engine affecting the parent form, or any other form for that matter.

Why is the engine controlling the cursor for other windows?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/25/09 18:34

could u send me the project so that i could have a look at it ?

thx got it ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 01:06

Well me and Stromausfall finally got the engine to render into a windows form, even if it was a complete hack ,lol.

I've prepared a sample (basic model viewer), which shows how to initialize the engine and embed it into a control/form. I've added a couple of controls to demonstate how the engine can be controlled using .NET controls.

Here's a screenshot of it in action...



and the download link...

http:\\djbm.kawanda.net\EngineInForm.zip

Hope you guys can use it to create some good C# applications. Once again I must thank Stromausfall for his excellent contributions, and making us .NET programmers lives a little easier.

Wow 1.1.0.2 already! I can't keep up with the updates, LMAO.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 05:07

More Questions LMAO >>>

1) Do the events have to be static? I'm wondering how i would use values of controls inside a static function eg like Button.Text. Because static works at class level rather than object level, if several entities use the same function, wont they pick up values left by the previous run function?

2) How can you just run a function called from anywhere, eg when clicked on a button?

I need to use a while loop and so I need to use the scheduler. I'm just simply rotating an entity...

public static IEnumerable RotateEnt()
{
while (true)
{
MyEnt.pan.IntValue += 5;
yield return 1;
}
}

i've tried just using RotateEnt() in the buttons click event, but it wont execute.

Thanks. Btw, what did 1.1.0.2 update?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 07:00

Cool demo !

1.1.0.2 fixed a bug where one couldn't use functions that use Angles or Colors ^^

question 1, nope they don't have to be static and i also would say that several entites would pick up the same values if the run the same function.

question 2, currently you have to create a dummy entity to add a function to the scheduler e.g. -> "EngFun.ent_create(null, new Vector(0, 0, 0), RotateEnt);"
This will result in the engine calling this function and thus it is added to the scheduler! But if you add the funciton via ent_create you have to change the signature to "public static IEnumerable RotateEnt(IntPtr p)".
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 07:06

May i add your ModelViewer to the Samples ?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 07:51

Of course, no problem.

One other thing. Are you able to set the mouse_map? I've tried and failed, lol.

In regards to creating a dummy entity to add a function to the scheduler, are your plans in the future for something like scheduler.Addfunction(pointer)?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 08:11

Great!
hmmm yes mouse_map is indeed strange! bmap_create works perfectly but there seems to be an problem with mouse_map, I'll look into it right now.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 08:44

while you're there you might wanna check passing null to a Color parameter. I'm using draw_line_3D, and the manual says if you pass 'null' to the 2nd parameter, then it just sets the point > which i want.

I've tried (Color)null, (Vector)null and just null, all cause Exception.
Posted By: Tempelbauer

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 16:18

Sounds great, but i cant use them, cause i´m dont have a7 frown
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 17:26

@djbmaster: yes a function like scheduler.addfunction would be useful and will most likely be implemented in a future release.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 20:04

@Stromausfall

Seems to be a problem with

EngVar.enable_polycollision.IntValue = 1;

Please check this.

Thanks
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/26/09 20:14

hmmm, what exactly doesn't work with enable_polycollision ?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.0 - 07/26/09 21:09

I uploaded a new Version of the wrapper : 1.1.1.0 for A7.77
This update fixes two severe bugs, it also adds a function to let the user add a method to the scheduler without creating a dummy entity. And with this update the Samples got updated, the excellent contribution by DJBMASTER (to use the engine in c# forms) was added to the samples zip-archive.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 04:36

Code:
EngVar.time_smooth.FloatValue = 0.666f;

            //CRASHES:: ?????
            //collision
            //EngVar.enable_polycollision.IntValue = (int)1;

            EngVar.floor_range.IntValue = (int)100;



This is a statement in my init code
and it now causes a crash, ( memory access error ).
I had to comment it out for the moment.
I dont know why it suddenly decides to cause problems that line
but it did not before.


Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 06:34

Did u try if this error also occurs when you use the laterst version, 1.1.1.0 ?

If it still doesn't work, could u send me more code that surrounds this block of code, or a small demo where this error occurs ? Because i can't reproduce this error with these 3 assignments!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 10:50

Is it possible to let EngFun.engine_open() return an ENGINE_VARS struct? This way i think it might be possible to allow multiple instances of the engine to be used.

At first I thought multiple instances wasn't available because of accessing "acknex.DLL" simulataneously.You can create a C# app that runs the engine, and run the exe many and it will load seperate engine windows each time. The manual states the engine can be run many times even.

So i'm wondering which method could be used to load the engine multiple times, within the same exe? I'm in need of this for a MDI application, and i can't think of a way to get around it.

Or maybe you could explain to me why multiple instancing is not possible.

I know you said in an earlier post that functions like engine_frame() dont take an instance parameter, but if there was a way to return a structure or pointer from an engine_open call, then couldn't you use something like...

Engine_Ref ref_1 = EngFun.engine_open(null);
Engine_Ref ref_2 = EngFun.engine_open(null);

Then each engine could be referenced with ref_1 and ref_2. Don't know how possible this is, just a thought.

I know i'm asking a lot but i' see so much potential in this wrapper.

Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 11:25

hmmm now this is a good question, i have to admit that you will have to ask JCL regarding this topic.

I've read the "Starting the Engine" chapter in the manual. And it seems to me that starting the engine multiple times is possible but not from the same instance of an exe file. Engine_open() returns a pointer to a Engine_var struct, that's right, but there is no way (afaik) to tell the engine if a certain command like ent_create should be executed on Engine_ref1 or Engine_ref2.

What may be possible in your case is that your program creates one instance of the engine (like normal) and then it executes an exe file that also opens the engine (thus you would have two instances of your program). And then you could communicate between them with multiplayer commands (as stated in the manual). And thus it may be possible to embed the other instance into your main programm by passing the hwnd pointer - or something like this ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 11:31

hmm, well thats pretty interesting. I was thinking about the workaround of opening an exe seperately and then embedding that window, but my main problem was how was i going to communicate between them.

I never thought of using multiplayer commands, its didnt really fall into that category, but now you mention it; it does seem like quite a good method.

I'm going off to experiment. I'll ask JCL regarding multiple instances...

Thanks.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 14:14


EDIT::
Juist found in manual:


<<This variable must be set at the beginning of the main script before level loading.>>

SO:
I guess i will have to open engine with null, Init the vars and then load my level.
//
Will let you know.
Or you could try calling it (enable_polycollision) in the EngineInForm sample ( in IEnumerable MainFunction() ) to see the error.
So it seems now it is not an error in the wrapper.
//
ALL is good.



Posted By: amy

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 14:21

Couldn't you simply do all the var conversions in the properties (get/set)?

Does the scheduler handle my and you correctly? I took a quick glance at the code and didn't notice anything about my and you.

Did you write all the wrapper code manually or did you use some generator script or something for the repetitive parts?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 14:38

You dont need to cast them to (int) because it expects an int anyway. I've just tested "enable_polycollision" and i cant produce an error with it.

EDIT > posted this before i saw ur updated post. I didn't know that it had to be set before the level_load. Ok cool...
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 14:57

I know, but i like putting (int) there because it helps me to
see distinguish easilly between the type of variables
in my code. Mind you my code is coming from C++ project
so i left the casts in when i copied it.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 14:58

@pararealist: ah didn't know that, cool ^^

@amy: in lite-c afaik my is always set to the entity that is scheduled at the moment. But in the wrapper my is not set automatically that means, that for things like IGNORE_ME or USE_BOX in a c_trace you have to set the EngVar me (same as my) to the entity that should be be "me".
The you variable isn't set by the scheduler afaik, but for example if an event like impact happens - that should work.

The var conversion could be set in the properties but then references(pointers) to variables would be impossible or would have to be updated each frame. I know it's not perfect to write .IntValue and .FloatValue, but else references aren't possible as easy as they are at the moment.

For the first version of the wrapper i wrote all by myself, for the next i let most EngFuns and all EngVars be generated by two small programms i wrote, but the problem is that there are many cases where this automatically created code has to be polished or doesn't mind all special cases - so it's only a small help, as many things have to be polished anyways after the creation smirk
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 15:17

Have you noticed any performance issues when
the form (not fixed) is resized?
I have a mainform containing toolstrip container, menu and 2 toolbars.
Then my panel, a splitter and a propertygrid.
When the main form is sized there is some delay
in sizing the rest or is this C# NET?
Posted By: amy

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 15:34

Yes, Lite-C stores/restores my and you at each wait(). So in my opinion it would make sense if your scheduler did that too. It's no big deal though.

Hm... Couldn't you do something like always having two versions of each property. For example time_step and time_step_as_reference. I think most commonly variables don't get used as references. It would make sense to make the most common case easy and clean from the user perspective. If you want to use a variable in a panel you can add _as_reference.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 16:29

@pararealist >>> You shouldn't really see a performance decrease because the engine is running on a seperate thread. Are you using the "embedding" sample from the manual? If you want to resize the engine when the form resizes then you will have to use the Resize event handler or you can override WndProc and handle the WM_RESIZE message. Then you will need to use the win32 call "SetWindowPos" to set the size of the engine window.

PM me if you want me to give you a "resizing" demo.

@amy >>> I think the way it uses Vars at the moment is pretty good, if not fine. Having time_step and time_step_as_reference would be overkill i think, and more work on Stromousfall's part. I think it also serves as a helper to use IntValue and FloatValue to stop you eg, passing a float to a function that wants an int, thus preventing errors.

@Stromausfall >>> I looked over the multiplayer functions in the manual and after some consideration decided not to go that way because a number of errors could occur (ip settings etc) and the engine's network functions don't have a reputation as being useful.

I wanted to go a bit more 'low-level' and operate on windows messages, so i decided to create a method of sending custom messages to the exe window. Then the window can handle it and do whatever it wants. It works fine...



...and i can control each instance seperately by passing values to each window.

LMAO, i have learnt more win32 in the past 3 days than ever before. At least we now have multiple instances running.

If anyone wants the code for running more than one instance of the engine, then ask here or PM me.

Thanks.
Posted By: amy

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 16:38

If he uses code generator scripts anyway it shouldn't be much work to add the _as_reference feature.

In what cases do you need references? Panels? What else? These rare cases where you need a reference shouldn't prevent streamlining the wrapper API in my opinion. Stromausfall did a great job so far but i still find the API a bit ugly. It's not wrist friendly to always have to type that much.

I think lengthy code which isn't easy to read leads to more errors than passing floats to ints. :p

Another question... I have never tried this but if you make a .NET dll out of this wrapper it should be usable from other .NET languages, right?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 17:00

@DJBMASTER looks great! You're progress is really fast!

@amy I'm sorry but Var will stay the way it is now, as long as i don't find a solution that truly is easier for the user (and of course not too much work for me to implement ^^). The problem with your concept is, how would one pass a reference of a Var that the User created - your concept would only work for EngVar and maybe Vars in Engine Objects and it would also be confusing, as one would have "two" variables that represent the same but are of different types.

Regarding the .net dll, i have to admit that i have actually less to no knowledge about this topic. The only thing i know is that all .net languages compile to the same language.
Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 17:09

in my opinion fixed point variables aren't that great. the user of the c# wrapper shouldn't be forced to ever create one himself. they are relics from a time when cpus didn't have floating point units. smile it shouldn't be necessary to think about vars at all. the issues with panels and other cases where references to vars are needed can be solved differently.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 17:12

yeh, if you write the wrapper to be CLI compliant then it should be accessible though-out all .NET languages because they all run on the CLR.

If you can get unmanaged code into C#, then getting the C# into VB should be no problem, you don't have to worry about marshalling etc.

I agree that Var shouldn't change and if you really want to use ints and floats implicitly then you can write your own helper method/macro.

I think this would work...

Code:
public void SetVar(ref Var sender, object value)
        {
            if(value.GetType() == typeof(int))
            {
                sender.IntValue = (int)value;
            }
            if (value.GetType() == typeof(float))
            {
                sender.FloatValue = (float)value;
            }
        }


Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 17:23

My intention in using float and int is, that the engine uses these with it's var variable.
And thus also the user should use them if he interacts with the engine ^^

Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 19:25

Does anyone know how to hide the start-up window completely. When using engine_open() the engine window flashes up. I've got "-nwnd" as the command line.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 20:08

http://www.galep.com/beta/a-black.htm
according to this page you it's a pro feature, do you have pro ?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/27/09 20:13

yeh, but it still shows the window momentarily. I think this is required to start rendering. I'll see if i can hack with win32.

Thanks.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 10:28

Hi Stromausfall

Dont know if you would like to add this to manual as the add_folders() (have never) dont seem to work outside Lite-C.
//
Setting up paths in C#
First create your folders in your bin/debug bin/release folder.
then:
Code:
//
        public static String levels = Application.StartupPath + @"\gsDefaults\levels\";
        public static String models = Application.StartupPath + @"\gsDefaults\models\";
        public static String terrains = Application.StartupPath + @"\gsDefaults\terrains\";
        public static String props = Application.StartupPath + @"\gsDefaults\props\";
        public static String textures = Application.StartupPath + @"\gsDefaults\textures\";
        public static String fx = Application.StartupPath + @"\gsDefaults\fx\";
        public static String ppfx = Application.StartupPath + @"\gsDefaults\pp_fx\";



Then use like so
Code:
public static String strDefLevel = levels + "default.wmb";
        public static String strDefEntity = models + "camnode.mdl";

OR

Actor = EngFun.ent_create(models + "cbabe.mdl", new Vector(0, 0, 32), ActorAction);


Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 10:45

add_folder() works fine in every language but it has no effect if you use it before engine initialization.
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 10:56

Oh, couldnt find any help on getting it working
but thats good to know.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 11:11

i will add it to the manual as "add_folder alternative"! thank you!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 11:23

hi, how can i create a sky entity?

I'm using this Lite-C code...
Code:
ENTITY* skycube =
{
  type = "t_day_sky+6.tga"; // the image for a backdrop scene
  flags2 = SKY | CUBE | SHOW; // sky cube, visible
}



...how can i do this in C#. The ENTITY doesn't have a SKY property. Also if i set ENTITY.type = "t_day_sky+6.tga";, it results in a Marshalling Exception.

Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 11:47

I'm looking into this!
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.0 - 07/28/09 11:54

i found this via a7oogle in a thread (http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&topic=27906&gonew=1) :

//Make a Pretty Sky
skycube = (ENTITY *)ent_createlayer("Sky_2+6.tga", _VAR(SKY | CUBE | VISIBLE), _VAR(0));

in c# it would then be

ENTITY MySky = EngFun.ent_createlayer("Sky_2+6.tga", (Var)(1 << 17 | 1 << 20 | 1 << 14), (Var)0);

In the next version this will be fixed and i will add an enum for CUBE SHOW and the other flags and i will also add a property for SKY which i somehow forgot !

In fact, you may also write it, like you will be able to in the next update of the wrapper (But you have change the enum FLAGS2 to public enum FLAGS2 in ENTITY.cs as workaround until the next update arrives ^^):

ENTITY MySky = EngFun.ent_createlayer("Skycube+6.tga", (Var)(int)(ENTITY.FLAGS2.SKY | ENTITY.FLAGS2.SHOW | ENTITY.FLAGS2.CUBE), (Var)0);
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.1 - 07/28/09 13:17

i just uploaded the newest version of the wrapper : 1.1.1.1 get it here : http://acknexwrapper.matthias-auer.net
This version features several small improvements
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 07/28/09 16:23

i just uploaded a new version of the wrapper : 1.1.1.2 get it here : http://acknexwrapper.matthias-auer.net
This version fixes a bug in engine_close()
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.2 - 07/28/09 19:44

Hi Stromausfall

after update to ver 1.1.1.1 or ver 1.1.1.2 gets error setting camera stage.
before update i had (ver 1.1.1.0)
Code:
aFXCamera.stage = (IntPtr)null;


now after update i have to cast to VIEW
Code:
aFXCamera.stage = (VIEW)(IntPtr)null;


but this crashes in
Code:
/* -------- VIEW -------- */
        /* VIEW to NativeVIEW* (address in void*) */
        public static explicit operator IntPtr(VIEW d)
        {
            unsafe
            {
                return (IntPtr)(NativeVIEW*)d.VIEWPointer; // CRASH HERE!
            }
        }


with an exception:

Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 07/28/09 19:47

ah thanks, will fix it and upload a new version, will upload in 10 mins if everyything works as planned!

You also mentioned that you have to cast to view now.
But there are also other possibilities than
aFXCamera.stage = (VIEW)(IntPtr)null;

for example

aFXCamera.stage = (VIEW)null;

aFXCamera.stage = null;

aFXCamera.stage = (VIEW)IntPtr.Zero;
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.2 - 07/28/09 19:48

great
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 19:56

i just uploaded a new version of the wrapper : 1.1.1.3 get it here : http://acknexwrapper.matthias-auer.net
Fixes bug where assigning null to an EngineObject parameter caused an exception.
Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 20:25

i have looked into boo a bit the last two evenings. it kind of is c# with a python-like syntax. i could imagine that it would be quite easy to convert my python wrapper to boo with some simple converter scripts. so maybe there will be a competitor .net wrapper with automatic var handling. :p

it's rather unlikely though since i don't have much time and i am pretty new to .net and all this marshaling stuff. probably unforeseen problems will arise. smile
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 20:28

All OK again. This will be a great wrapper, Stolz kannst du sein.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 20:40

@pararealist danke ^^

@ventilator the more, the merrier i would say ^^
Concerning marshalling stuff, you should have a look at the c# wrapper, how it handles marshalling. You will see it's not that hard - actually easy, as .net handles all the difficult stuff ^^ And if you have questions regarding wrapping the acknex engine in c# i will surely help you!
On my end, it doesn't matter if there's a wrapper i have created or you, as long as there is one - i'm happy ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:04

Has anyone any experience with runtime evaluation/ execution of strings? What i'm talking about is say you have a string >> "EngVar.sunlight.Intvalue=0" and then being able to process this at runtime, and have C# execute it. I don't think C# has an eval() function at the moment, i think python does though.

This way you could create your own scripting engine allowing the user to change almost anything at runtime.

I'll probably have to wait until C# 4.0 or even 5.0 appears. I think they are exposing the CLR compiler as a set of classes, so you can control what happens at runtime.
Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:15

you could use ironpython for that. it's supposed to be very easy to include in a c# project.

@stromausfall: thanks for offering your help. maybe i will have some questions about delegates. i don't wrap the engine in c# but in boo. doesn't make much difference though and it will be usable by all .net languages.

in boo the wrapper will look kind of like that:
Code:
class Engine:
	
	ev as ENGINE_VARS
	
	def constructor(commandline as string):
		ev = Marshal.PtrToStructure(engine_open(commandline), ENGINE_VARS)
	def frame():
		return engine_frame()
	def close():
		engine_close()
		
	version as single:
		get: return _FLOAT(Marshal.ReadInt32(ev.version))
	edition as int:
		get: return _INT(Marshal.ReadInt32(ev.edition))
	compatibility as int:
		get: return _INT(Marshal.ReadInt32(ev.compatibility))
		set: Marshal.WriteInt32(ev.compatibility, _VAR(value))
	
	...



edit: i tested using the boo wrapper from c# now. works nicely. i really like how all languages can work together automatically in .net. here is how it looks like:
Code:
using System;
using a7;

namespace test
{
	class Program
	{
		public static void Main(string[] args)
		{
			Engine e = new Engine("-nwnd");
			Console.WriteLine(e.version);
			Vector v1 = new Vector(10, 10, 10);
			Vector v2 = new Vector(30, 30, 30);
			Vector v = v1 + v2;
			Console.WriteLine(v);
			while(e.frame() != 0)
			{
				
			}
			e.close();
		}
	}
}


Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:22

This seems to be a hot topic regarding c# ^^
I found two pages which show different approaches :
(evaluation at runtime but sure this would be damn much work to implement, because of the sheer amount of commands)
http://www.codeproject.com/KB/cs/runtime_eval.aspx

and
(compiling at runtime)
http://www.digitalcoding.com/Code-Snippe...e-run-time.html

@ventilator for sure ! delegates are maybe the most interesting part of the wrapper, as one has to keep the references of a delegate until it isn't used anymore ^^
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:38

It seems that the code overall is quite short, but this can't be the whole source to call for example engine_close() in the dll or ?

I'm missing something like this :

[DllImport("acknex.dll")]
internal static extern void engine_close();
Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:40

wow, looks complicated. why not use ironpython?
http://secretgeek.net/host_ironpython.asp
with just a few lines of code you get a full scripting engine and for one liners python doesn't look different to c# anyway.

yes, in boo you also need the [DllImport("acknex.dll")]. i left it away in the example snippet.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 21:43

hmmm, i'll look into ironpython.

Yeh the C# way looks complicated because you have to build assemblies at runtime, and i guess you have to be really comfortable with reflection; which i'm not lol.


Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 22:03

WOW ironpython seems powerful. In under 5 mins i had everything set up and running and it worked pretty well. I'll see if i can now call something like "ent_create" from a string...
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/28/09 23:09

hmmm, i'm not really sure how to use ironpython. I can use it to change controls at runtime, but i had no success in using it to create engine objects like an ENTITY*.

I did some browsing and learnt what assemblies and functions i needed to create assemblies at runtime and execute my own code. The only requirement is that I pass in required DLLs, so i had to compile the C# wrapper into a single DLL. The result is pretty good. I called "ent_create..." from a string and it created then entity just like as if it had been compiled on the project build.

There will be a slight lag due to memory IO but it should be OK. I dont really need this for my project right now, just thought it would be cool to learn it, but this method has the potential to create a whole new game engine allowing the user to write actions / particles / shaders and test them in real-time without the need for compilation by acknex.

BTW Stromousfall, isn't it easier to compile the Wrapper source files into one DLL and then distribute that?
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/29/09 06:23

That's a good idea i would say, thus all internal methods and properties wouldn't be visible from outside, just as they were meant to be. But i will do some research if DLL is at least as fast as plain source code - that's in fact what matters ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/29/09 10:44

Well i havent tested it but i'm sure there wouldnt be any performance hit, if not the DLL runs faster. The source files all together occupy around 1.2mb, but the DLL is only around 300kb, so it probably strips down some of the common data or compresses it.

Only thing is, i'm not sure if you can debug inside a DLL. At the moment if we have a crash we can find the method/line inside the wrapper which is causing it and report it to you. I'm not sure how we would do that with a DLL.

Either way the wrapper works fine.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/29/09 11:35

That debug thing makes the point i would say. And creating a dll from the wrapper shouldn't be hard if anyone wants to. Did you have to change much to get it into a dll ?
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.3 - 07/29/09 14:58

<<Only thing is, i'm not sure if you can debug inside a DLL. At the moment if we have a crash we can find the method/line inside the wrapper which is causing it and report it to you. I'm not sure how we would do that with a DLL.>>

This makes sense.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 07/30/09 09:01

It wasn't hard creating the DLL, because they all share the common namespace "AcknexWrapper". I just created a new 'Class Library Project'. Added the AcknexWrapper folder, press build and the DLL is created.

Then to use it in the project just add a reference to it, and all functions remain the same, no problems.

But I think the fact that we can't debug is a disadvantage and so i'm leaving it as it is for the moment. Maybe when you get a rock-solid version that causes no crashes, then maybe a DLL is more suitable.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 07/30/09 10:00

thank you for the small tutorial ^^
yeah it will be best to wait until the wrapper is really stable !
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 08/01/09 12:43

Originally Posted By: ventilator

Code:
using System;
using a7;

namespace test
{
	class Program
	{
		public static void Main(string[] args)
		{
			Engine e = new Engine("-nwnd");
			Console.WriteLine(e.version);
			Vector v1 = new Vector(10, 10, 10);
			Vector v2 = new Vector(30, 30, 30);
			Vector v = v1 + v2;
			Console.WriteLine(v);
			while(e.frame() != 0)
			{
				
			}
			e.close();
		}
	}
}



I like how you overloaded the "+" operator!
You seem to be making decent progress !
Posted By: ventilator

Re: C# wrapper - RELEASE 1.1.1.3 - 08/01/09 13:01

no, not really. smile i don't have much time for this unfortunately.

...but actually the only thing i still have to figure out is how to best handle callbacks with boo. afterwards it would only be some grunt work to complete a nice wrapper.



...
i think it makes sense to use a vector class with overloaded operators. the class also doesn't use vars but floats which results in better precision in many cases.



...
by the way, boo features powerful macros which are nice for avoiding repetitive code like often happens in a wrapper. it would be possible to do stuff like:

# f = float, i = int, _ = no setter
property version f_
property edition i_
property compatibility ii

only one line per property! smile

unfortunately macros seem to be quite complicated to write. you have to work with the AST (abstract syntax tree) and there isn't any documentation about it yet so i probably won't use macros.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.3 - 08/02/09 13:58

Hey stromousfall i think i've found another bug...

I'm experimenting with particles. In my particle function if i set one of the flags to false, eg my.BRIGHT = false , it results in a memory read exception. I think the same goes for other flags like MOVE, TRANSLUCENT etc.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.3 - 08/02/09 16:37

Thank you !
I will look into this!

@ventilator i wish c# would even have some kind of macro ^^
Boo macros seem to be extremely powerful !
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.4 - 08/02/09 16:54

The new version of the c# wrapper for A7.77 Version 1.1.1.4 is ready to download on it's homepage : http://acknexwrapper.matthias-auer.net
It fixes a bug, where a boolean property, which was assigned with false, threw an exception !
Big thanks go to DJBMASTER for finding this bug!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.4 - 08/05/09 01:20

Another bug >>>

MATERIAL mat = new MATERIAL();
mat.ambient_red.IntValue = 64; [Results in memory exception!]

Also MATERIAL.effect causing a marshalling exception. Other properties of MATERIAL may cause similar exception, i havent tested them all.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.4 - 08/05/09 10:05

at the moment one can't create a material through new MATERIAL(), one has to use mtl_create() as in lite-c, like the other engine objects, these objects have to be created through engine functions!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.4 - 08/05/09 17:47

oh ok, good to know.
Posted By: Claus_N

Re: C# wrapper - RELEASE 1.1.1.4 - 08/06/09 17:49

It looks very interresting! I'm using Visual Studio 2003 (Academic) though, so my C# compiler does not support generics and static classes frown

I'll try changing the code to make it compatible with my C# compiler and I hope it will be working then. I'd really love to use C# with 3DGS smile
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.4 - 08/06/09 18:40

Try Sharp Develop, its free
http://www.icsharpcode.net/OpenSource/SD/
or
Visual Studio Express 2008
Posted By: Claus_N

Re: C# wrapper - RELEASE 1.1.1.4 - 08/07/09 10:54

I think I'll have a look at Sharp Develop, thanks for the link smile
Posted By: kns

Re: C# wrapper - RELEASE 1.1.1.4 - 08/08/09 17:45


Setup instructions for Sharp Develop would be most appreciated. Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.4 - 08/08/09 17:50

i don't know sharp develop, but the setings that have to be set are :
-allow unsafe code
-no hosting process (unlikely in sharp develop)
-to automatically create and bind an acknex.dll after compilation (with the console commands as shown in the manual)

that should be all afaik. If i have some spare time i will look into sharp develop and add a topic in the manual that shows how to get the wrapper working in sharp develop!
Posted By: pararealist

Re: C# wrapper - RELEASE 1.1.1.4 - 08/09/09 08:59

Its the same as Visual Studio
Even the Solution Preferences has the same options

Just open the Engine in Form example in #Develop.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.4 - 08/09/09 09:05

ah ok, now that renders an own topic in the manual obsolete, thanks for the info pararealist!
Posted By: Tempelbauer

Re: C# wrapper - RELEASE 1.1.1.4 - 08/10/09 18:41

is there a version for a6 in planning?
there are many developers, including me, who only have a6. i could need the engine good in c#
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.4 - 08/10/09 19:18

hmmmm, this really shouldn't be much work, i think i can create a version for a6 and upload it, but i would need the version of a6 for which you would need the wrapper - 6.60 or 6.40 ?
Posted By: Tempelbauer

Re: C# wrapper - RELEASE 1.1.1.4 - 08/10/09 19:44

i have A6.60
thanks in advance
Posted By: Stromausfall

Re: C# wrapper - A6.60 - 08/10/09 23:02

Hi !
i just uploaded version 1.0 of the wrapper for A6.60 !
It should work just as the wrapper for A7.77 !
Posted By: Tempelbauer

Re: C# wrapper - A6.60 - 08/11/09 02:36

great smile

but where is the downloadlink? on your site are just the A7-versions.
maybe i´m blind... confused
Posted By: Stromausfall

Re: C# wrapper - A6.60 - 08/11/09 07:14

now that's really strange, the site should look like the following picture (screenshot of the homepage) : http://acknexwrapper.matthias-auer.net/homepage.PNG
Posted By: Tempelbauer

Re: C# wrapper - A6.60 - 08/11/09 11:40

oh, sry
the browser-cache... blush
Posted By: pararealist

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

@Stromausfall

Problem in entity class
Code:
public class Actor : ENTITY
{
        /*create entity player*/
        private static ENTITY m_actor = null; 
        ...
        public Actor()
        {
           // m_actor = new ENTITY();  //CRASH
           // m_actor = (ENTITY)EngVar.player; //CRASH
           //m_actor = (ENTITY)EngFun.ent_create(null, new Vector(0, 0, 0), null); //CRASH
           ...
        }
        ...
}


CRASHES in Var.cs
Code:
public class Var
    {
        private NativeVar HiddenVar = new NativeVar();
        private IntPtr VarIntPtr = IntPtr.Zero;

        private int mValue
        {
            get
            {
                if (VarIntPtr != IntPtr.Zero)
                {
                    unsafe
                    {
                        HiddenVar = *((NativeVar*)VarIntPtr);
                    }
                }
                return HiddenVar.mValue;
            }
            set
            {
                HiddenVar.mValue = value;
                if (VarIntPtr != IntPtr.Zero)  //update structure in unmanaged memory if the var was already used as IntPtr
                {
                    Marshal.StructureToPtr(HiddenVar, VarIntPtr, false); //CRASH HERE
                }
            }
        }



In Main called
Actor testactor = new Actor();

Please can you try to reproduce?
Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 08/11/09 18:57

i wrote the following :
Code:
public class Actor : ENTITY
    {
        private static ENTITY m_actor = null;

        public Actor()
        {
            m_actor = new ENTITY();  //CRASH
            m_actor = (ENTITY)EngVar.player; //CRASH
            m_actor = (ENTITY)EngFun.ent_create(null, new Vector(0, 0, 0), null); //CRASH
        }
    }


and in my main method i called
Code:
Actor testactor = new Actor();



but this call didn't cause any crash, error or exception : /
Do you have another example where this crash happens ?
Posted By: pararealist

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

No, its just in the actor class
OK, i will create the actor class new
and see, maybe there is an error in
the first one somewhere.

Its still the same, each call from constructor crashes
in the newly created class.
//
If i comment out the call in main, all is fine.
//
Sorted it just now, i had left out public before class, how silly of me.
can now use

Code:
Actor m_actor = new Actor(models + "cbabe.mdl", new Vector(0, 0, 16), Actor.ActorAction);


Posted By: Claus_N

Re: C# wrapper - RELEASE - 08/14/09 22:10

I finally got the time for trying it (using SharpDevelop) - so far everything works great!

Thank you for this very nice contribution! smile
Posted By: pararealist

Re: C# wrapper - RELEASE - 08/15/09 04:55

Great.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0 - 08/15/09 13:25

version 1.0 of the wrapper for A7.80 was released, it contains all new features of A7.80 except the Engine Variable "sys_active" which be added when the next version of Gamestudio is released. It also features an alternative way to set flags and masks. The manual was also updated (but only the change list ^^)
get it here : http://acknexwrapper.matthias-auer.net
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.1 - 08/15/09 16:57

version 1.0.1 of the wrapper for A7.80 and A6.60 was released, it fixes a bug with the Var method getValueFrom (which affects some functions)
get it here : http://acknexwrapper.matthias-auer.net
Posted By: Claus_N

Re: C# wrapper - A7.80 V1.0.1 - 08/16/09 11:26

Hmm, I tried this and it doesn't seem to be working... Am I just missing something simple, or does vec_to_angle not work?

Code:
EngFun.vec_set(EngVar.target,player.xyz);
EngFun.vec_sub(EngVar.target,EngVar.camera.xyz);
EngFun.vec_to_angle(EngVar.camera.panTiltRoll,EngVar.target);



It's version 1.1.1.4 for A7.77, haven't updated to A7.80 yet.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.1 - 08/16/09 11:36

this seems to be the bug with getValueFrom which affects some functions (i think that this one is also affected)
I uploaded version 1.1.1.6 for A7.77, try this version of the wrapper it should fix your problem i think ! (as i prior to your post only fixed this problem in the wrapper for A7.80 and A6.60)
Posted By: Claus_N

Re: C# wrapper - A7.80 V1.0.1 - 08/16/09 12:07

Thanks, it's working now wink
Posted By: Enduriel

Re: C# wrapper - A7.80 V1.0.1 - 08/16/09 14:30

hmm, just curious. Making a wrapper means like making all the function prototypes and stuff that comes with the acknex header files if I understand it correct? Not that I know C#, I just wonder it laugh
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.1 - 08/16/09 17:23

yes, i think one could explain wrapper in this way ^^
Posted By: Stromausfall

C# wrapper - A7.80 V1.0.2 - 08/16/09 18:32

I have just released

Version 1.0.2 for A6.60
Version 1.1.1.7 for A.77
Version 1.0.2 for A7.80


these new versions now support implicit casting.
this means that one doesn't need to type
Code:
int x = EngFun.clamp((Var)3, (Var)4, (Var)5).IntValue;


anymore (although this is still supported), but now one can type :
Code:
int x = EngFun.clamp(3, 4, 5);


thus explicit casting isn't needed anymore (although it's supported)

BUT one doesn't forget that if one writes
Code:
Var TempVar = new Var(3);
TempVar = 4;


then not the value of the TempVar object is changed, but a new object is created that has the value 4 ! Thus Var.IntValue and Var.FloatValue aren't obsolete and are still needed and useful ! For example if you want to change the position of an Entity :
Code:
ENTITY Dummy = EngFun.ent_create("dummy.mdl", new Vector(0, 0, 0), null);
MySky.z.IntValue += 30;



That's why you should use implicit casting with care, as it ALWAYS creates a new object and DOESN'T modify the existing object !

Another thing that i need to mention is that if one writes :
Code:
Var xxx = null;
int z = xxx;


normally implicit casting would fail here, that's why null is casted to 0 (like in lite-c). That means that the code above will result in :
Code:
z = 0



And as already mentioned, one can still only use explicit casting like with the previous versions!
Posted By: DJBMASTER

Re: C# wrapper - A7.80 V1.0.2 - 08/20/09 16:04

I'm trying to convert this lite-c snippet i wrote to C# but i can't seem to get it to work...

(Lite-C) "Both executed in the main function"
Code:
BMAP* arrow = "arrow.pcx";
mouse_map = arrow;
mouse_mode = 2;
int snap_amount = 30;
double ux = 0.0;
double uy = 0.0;

while (1) // move it over the screen
{  
ux = mouse_cursor.x / snap_amount;
uy = mouse_cursor.y / snap_amount;
		
mouse_pos.x = (integer(ux)*snap_amount);
mouse_pos.y = (integer(uy)*snap_amount);
wait(1);
}


(Wrapper attempt)
Code:
BMAP* arrow = EngFun.bmap_create("arrow.pcx");
EngVar.mouse_map = arrow;
EngVar.mouse_mode.IntValue = 2;
int snap_amount = 30;
double ux = 0.0;
double uy = 0.0;

while(true)
{
ux = (EngVar.mouse_cursor.x.FloatValue / snap_amount);
uy = (EngVar.mouse_cursor.y.FloatValue / snap_amount);

EngVar.mouse_pos.x.IntValue = (EngFun.integer((Var)ux).IntValue * snap_amount);
EngVar.mouse_pos.y.IntValue = (EngFun.integer((Var)uy).IntValue * snap_amount);
yeild return 1;
}



Thanks.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/20/09 21:02

Hi !

It seems that i only had to change BMAP* to BMAP to get this code snippet to work!

Code:
BMAP arrow = EngFun.bmap_create("arrow.pcx");
EngVar.mouse_map = arrow;
EngVar.mouse_mode.IntValue = 2;
int snap_amount = 30;
double ux = 0.0;
double uy = 0.0;

while(true)
{
ux = (EngVar.mouse_cursor.x.FloatValue / snap_amount);
uy = (EngVar.mouse_cursor.y.FloatValue / snap_amount);

EngVar.mouse_pos.x.IntValue = (EngFun.integer((Var)ux).IntValue * snap_amount);
EngVar.mouse_pos.y.IntValue = (EngFun.integer((Var)uy).IntValue * snap_amount);
yield return 1;
}


Posted By: DJBMASTER

Re: C# wrapper - A7.80 V1.0.2 - 08/20/09 21:25

hmmm thats strange, i must of changed part of my code as i typed the post because BMAP* wont even compile in C#,so it was a typo LOL. Guess i fixed my code while posting it, ahahahaha. Thanks anyway.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/20/09 21:29

LoL ^^
Posted By: MichaelGale

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 11:33

I was going to point that out, but pointers are valid in C# in an unsafe context if you compile the assembly with the /unsafe switch. See here.
Posted By: DJBMASTER

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 14:03

Hi, here is a function that allows you to drag a panel across the screen...
Code:
public IEnumerable DragPanel()
{
PANEL sender = EngVar.mouse_panel;
int startx = EngVar.mouse_cursor.x.IntValue - sender.pos_x.IntValue;
int starty = EngVar.mouse_cursor.y.IntValue - sender.pos_y.IntValue;

while (EngVar.mouse_left.IntValue == 1)
{
if (EngVar.mouse_moving.IntValue == 1)
{
sender.pos_x.IntValue = EngVar.mouse_cursor.x.IntValue- startx;
sender.pos_y.IntValue = EngVar.mouse_cursor.y.IntValue -starty;
}
yield return 1;
}
}


and it is assigned to a PANEL's 'event' property...
Code:
PANEL pnl = EngFun.pan_create("bmap = hi.bmp;",(Var)1);
pnl.pos_x.IntValue = 0;
pnl.pos_y.IntValue = 0;
pnl.event_ = DragPanel;
pnl.SHOW = true;


Maybe i'm doing something wrong or it's a bug or something but i can only ever drag the panel once. So it seems the event function is only being called once.

I think the while loop may be a contributing factor because if i just have a function that calls a messageBox, then i can click the panel infinite times and it will show the MessageBox.

While we are on the subject. In Lite-C, when you call a PANEL event you can pass the PANEL pointer to the function allowing you to see which panel called the function. I don't know if this is possible with the wrapper because the event property expects an EventVoid signature, so no paramter passing. I do have a workaround with mouse_panel, but it would make things a little easier. Just a thought.
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 14:50

@Stromausfall

How to use
ent_animate(actor, "idle",percent, ANM_CYCLE);

cant find ANM_CYCLE??
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 15:47

Hi !
@DJBMASTER: it worked for me, even multiple times, but it seems that one can only drag it if one clicks in the lower right part of the panel !
here's the code i used :
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AcknexWrapper;
using System.Collections;

namespace game
{
    class Program
    {
        static IEnumerable mouse()
        {
            BMAP arrow = EngFun.bmap_create("mouse.bmp");
            EngVar.mouse_map = arrow;
            EngVar.mouse_mode.IntValue = 2;

            while (true)
            {
                EngVar.mouse_pos.x.FloatValue = EngVar.mouse_cursor.x.FloatValue;
                EngVar.mouse_pos.y.FloatValue = EngVar.mouse_cursor.y.FloatValue;
                yield return 1;
            }
        }

        public static IEnumerable DragPanel()
        {
            Console.WriteLine("i was called !");

            PANEL sender = EngVar.mouse_panel;
            int startx = EngVar.mouse_cursor.x.IntValue - sender.pos_x.IntValue;
            int starty = EngVar.mouse_cursor.y.IntValue - sender.pos_y.IntValue;

            while (EngVar.mouse_left.IntValue == 1)
            {
                if (EngVar.mouse_moving.IntValue == 1)
                {
                    sender.pos_x.IntValue = EngVar.mouse_cursor.x.IntValue - startx;
                    sender.pos_y.IntValue = EngVar.mouse_cursor.y.IntValue - starty;
                }
                yield return 1;
            }
        }

        static IEnumerable MainMethod()
        {
            PANEL pnl = EngFun.pan_create("bmap = mouse.bmp;", (Var)1);
            pnl.pos_x.IntValue = 0;
            pnl.pos_y.IntValue = 0;
            pnl.event_ = DragPanel;
            pnl.SHOW = true;
            yield return 1;
        }

        static void Main(string[] args)
        {
            EngFun.engine_open(null);
            Scheduler.AddEventVoid(mouse);
            Scheduler.StartScheduler(MainMethod);
        }
    }
}



Didn't knew that the panel event takes a Panel as Parameter, i will add that in the next version of the wrapper thanks !

@pararealist
Ah, it seems i have forgotten to add an enum for ent_animate, i will fix that in the next version (which will be released quite soon) !

Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 16:07

I've just released
Version 1.0.3 for a6.60
Version 1.1.1.8 for a7.77
Version 1.0.2 for a7.80

these versions now include the ent_animate flags and the PANEL event now doesn't take an EVENTVOID any longer but an EVENTINTPTR !
Big thanks to DJBMASTER and pararealist ^^

edit:
@DJBMASTER lol xD
Posted By: DJBMASTER

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 16:07

ahhh it was because i forgot to continously set the mouse position...
Code:
EngVar.mouse_pos.x.IntValue = EngVar.mouse_cursor.x.IntValue;
EngVar.mouse_pos.y.IntValue = EngVar.mouse_cursor.y.IntValue;



So it was always only detecting panels at (0,0). Don't know why you can only drag in the bottom corner, but i'm not using a mouse_map so maybe it limits the 'detection' region. Thanks again.

LOL, when you said soon i thought you meant like a day, not a minute, ahahaha. Nice one!
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 17:29

Thanks.
ver is 1.0.3
//
please do same for
EngFun.ent_sky_FLAGS ???
for ent_createlayer();
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 17:53

you can access the flags for the entity via : ENTITY.
for example : ENTITY.FLAGS2.SKY !
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 18:00

OK
Posted By: DJBMASTER

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 22:34

I think it's a bug that setting the 'bmapOverOff' in 'EngVar.pan_setbutton' as 'null' creates an error.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.2 - 08/21/09 23:03

Yes that seems to be a bug, thank you ! I will upload a new version tomorrow, that fixes this issue (and i will also have a look at the other pan_ functions which most likely also suffer from this)!

until then you can replace the pan_setbutton function in the EngFun.cs file with the following pan_setbutton method : http://www.matthias-auer.net/pan_.txt which should enable to pass null as parameter for BMAP in pan_setbutton!

edit:
I will upload the updated wrapper later, as my main pc is currently defect ^^
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.4 - 08/29/09 21:02

Finally i got my pc to work again ^^
I've uploaded a new Version of the Wrapper for A7.80, Version 1.0.4 :
It fixes the issue with BMAP bein null in pan_setbmap, pan_setneedle, pan_setslider, pan_setwindow and pan_setbutton.
This update additionally features a new class called "Flags" which contains ALL flags which may be used (the are now stored as const int and not as enum, so one doesn't have to cast them to int anymore !). Thus one doesn't have to guess where the enum for certain flags is stored (thanks to pararealist as he showed me that the current usage of flags wasn't flawless!).
Thus flags may now be used as followed :
Quote:
//old usage (is still supported)
EngFun.c_trace(new Vector(0, 0, 0), new Vector(0, 0, 0), (int)(EngFun.c_FLAGS.IGNORE_FLAG2 | EngFun.c_FLAGS.IGNORE_PASSABLE));

//new usage
EngFun.c_trace(new Vector(0, 0, 0), new Vector(0, 0, 0), Flags.IGNORE_FLAG2 | Flags.IGNORE_PASSABLE);


If someone has any suggestions for the next release, post them here please!
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.4 - 08/30/09 05:25

Hi Stromausfakk
i was trying to convert this:

viewTo.flags = ( (int)(viewTo.flags & ~NOSHADER) | (m_camera.flags & NOSHADER) );

but NOSHADER seems to be returning bool instead of int.
bool wont work with ~(tilde).

viewTo.NOSHADER = false;
m_camera.NOSHADER = true;
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.4 - 08/30/09 17:10

Hi !
i just uploaded version 1.0.5 (in 1.0.4 i added static to const int variables -.- and 1.0.5 fixes that error !)

the problem in your example is that viewTo.NOSHADER is indeed bool, which is WAD !
you would have to write the following code if you want to convert that line (i didn't try it, but it should work !):
Code:
viewTo.flags = ((int)(viewTo.flags & ~Flags.NOSHADER) | (m_camera.flags & Flags.NOSHADER));


Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.4 - 08/31/09 02:16

Using
viewTo.flags = ((int)(viewTo.flags & ~Flags.NOSHADER) | (m_camera.flags & Flags.NOSHADER));

The name Flags does not exist in the current context.
(Flags.NOSHADER). Using ver 1.0.5.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.4 - 08/31/09 08:30

I just included the new version of the wrapper into a project which used a former version of the wrapper and also experienced your problem !
It seems that Visual Studio doesn't include new files automatically, so you have to do the following :

-Go to the Solution explorer (on the far right)
-Open the folder AcknexWrapper through clicking on the plus beside it
-then click on the second symbol in the solution explorer "Show all files"
-then right-click on the white/gray file called Flags in the solution explorer
-and click on "Include In Project"
-after this you can click on "Show all files" again !

this should fix the problem !
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.4 - 08/31/09 09:23

I'm surprised at the problems VS 2008 Express has.
And its very slow loading a project. But its free
so we cant really complain too much i suppose.
Posted By: Stromausfall

C# wrapper - A7.80 V1.0.6 - 09/23/09 19:14

Hi !
I've just uploaded version 1.0.6 of the AcknexWrapper for A7.80.
This version adds two functions to the Scheduler class additionally to the
Scheduler.AddEventVoid(EventVoid MethodToSchedule)
method:

Scheduler.NewFirstEventVoid(EventVoid MethodToSchedule)
Scheduler.NewLastEventVoid(EventVoid MethodToSchedule)

NewFirstEventVoid adds the function passed as parameter to the scheduler so that it is always executed BEFORE all other scheduled functions

NewLastEventVoid adds the function passed as parameter to the scheduler so that it is always executed AFTER all other scheduled functions

But one has to notice that the First and the Last EventVoid which may be assigned through this method, are first scheduled after one frame !

As always : if you know a function which should be added or something that you would like to see changed in the wrapper, post here ^^
Posted By: Stromausfall

C# wrapper - A7.80 V1.0.7 - 09/24/09 09:12

Hi !
I recently found a bug that is now fixed in version 1.0.7 for A7.80 !
Methods that were added to the Scheduler via AddEventVoid didn't take in account what value the first yield returned.
Posted By: pararealist

Re: C# wrapper - A7.80 V1.0.7 - 09/24/09 12:19

Thanks ever so much, resizing works perfect now.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.7 - 09/24/09 12:33

Glad to hear that ^^
Posted By: Quad

Re: C# wrapper - A7.80 V1.0.7 - 09/28/09 13:08

Hey Stromausfall,

i am getting an error if i try to compile the project,

Error 1 The command "CD C:\
C:\Program Files\GStudio7\WED.exe -p "C:\Users\Quadraxas\Desktop\test\testproj\testproj\bin\Debug\\testproj.exe"" exited with code 9009. testproj

post build command-line:
CD C:\
C:\Program files\GStudio7\WED.exe -p "$(TargetDir)\$(TargetFileName)"

i guess ijust saw this someone else asking this but i lost it, ill be glad if you could help.

edit:k, i changed post-build command line to this:

CD C:\Program Files\GStudio7\
WED.exe -p $(TargetDir)$(TargetFileName)

and it worked.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.8 - 09/29/09 12:47

I've just uploaded version 1.0.8 of the C# wrapper for A7.80
This version fixes a bug where a negative value X for "yield return" didn't result in pausing the method for X seconds, but only for a few frames.
example :
Code:
yield return -1; //pause the method for 1 second
yield return 1; //pause the method for 1 frame


The new version now fixes this bug.
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.0.9 - 10/01/09 20:44

I've just uploaded version 1.0.9 of the C# wrapper for A7.80
This version removes the two functions :
Scheduler.NewFirstEventVoid(EventVoid MethodToSchedule)
Scheduler.NewLastEventVoid(EventVoid MethodToSchedule)
and instead offers a new system to control when a function should be executed.
I've also uploaded a small demo project to show how the new scheduler priority feature which works with 5 different lists and should imitate the proc_mode feature of lite-c, works !
here's the link to the demo project :
http://acknexwrapper.matthias-auer.net/7_80/1_0/WrapperTestApp1_0_9_A7_80.zip
One should also notice that each change from one SchedulerList to another results in the function waiting for one frame, just like yield return 1 !

another thing that changed with 1.0.9 is, that all standard constructors from EngineObjects were removed - to ensure that they don't fool one to believe that it is possible to create for example an ENTITY object without the help of for example ent_create !

If one didn't use standard constructors for EngineObjects or used the two functions introduced in 1.0.6, this update should be 100% downward compatible !

Big thanks go to pararealist, who helped me in deciding to rework the two functions (NewFirstEventVoid and NewLastEventVoid) to the new scheduler priority feature !
Posted By: Stromausfall

Re: C# wrapper - A7.80 V1.1.0 - 10/05/09 18:57

I'v just uploaded version 1.1.0 of the c# wrapper for A7.80

- This version adds several Vectors to access Vars like skill_x, skill_y and skill_z additionally easier
- String to STRING operator changed from explicit to implicit

Big thanks to pararealist, who told me that some Vectors to access Vars easier weren't implemented !
Posted By: Jaeger

Re: C# wrapper - RELEASE 1.1.1.2 - 10/15/09 05:39

Wow! Looks like this project is coming along nicely!

Been away for quite a while, since I don't use 3DGS anymore, but wanted to come back for a visit. I'm thoroughly impressed with this project though, and think this is going to make the engine a very finely polished piece of machinery! laugh

I got into C# a while back, and I've totally embraced it as my primary language. My productivity over C++ has been amazing. So I think this is definitely a step in the right direction for the community. It would be awesome to see this formally supported by the developers (if they aren't already, and I'm unaware)!

I've got some serious projects going on, so I've been extremely busy. But I hope I'll have time to contribute to something like this some day. Great work, and my applause to all of you who've developed this though! wink

One suggestion I'd like to make though is to look into some security measures. We all (I hope) know how easy it is to decompile .NET, which would make people's games easy to hack. :-/ There are lots of good obfuscators out there, but I don't feel it's enough, personally. I've developed my own measures for this, but it would be foolish to elaborate on. So do look into it, please! It would suck to see someone get screwed after releasing their game! frown
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 10/15/09 18:36

Thanks - but you also have to thank the community, as quite a large part of the wrapper was implemented after I got input from the community ^^

I have to admit that you caught me off guard ^^ I didn't knew about decompiling .net programs smirk
I will try to look in this issue in my spare time - but right now I would expect that this is not a wrapper issue.
If even a good obfuscator can't stop someone from hacking the game, then I don't know what can frown
Posted By: Jaeger

Re: C# wrapper - RELEASE 1.1.1.2 - 11/08/09 15:54

No, the wrapper itself isn't the/a problem. The problem is in how people will deploy their games. I can't look now, since I've given away my 3DGS license key (and don’t even have it installed anymore), but I think even Lite-C games can be easily patched/reversed/cracked/etc.

Without revealing too much of my personal "insurance policy", I'll try to give a bit of an explanation...

#1) Good obfuscators are a MUST! Dotfuscator should be sufficient in repelling the majority of attacks. But don't kid yourself into thinking it's invincible. eek

The key is verbosity and ambiguity. Good obfuscators will let you control what lengths it goes to. With a good one, any program (like Reflector) which tries to parse the IL, metadata and generate source code will get a whacky jumble of practically meaningless code. It is hard enough to understand clean code without documentation and comments, but this ups the ante. The only thing you really have to worry about is using System.Reflection in your assemblies, which can cause unexpected bugs in obfuscated CIL.

#2) Next is encryption. You can have all of your strings encrypted, of course. But you can also fully encrypt your assemblies with certain tools (or on your own). wink They key to this is just making sure there's a way for the CLR to decrypt and understand the code, so it can be JIT'ed. Believe it or not, there are still even ways to precompile .NET to native binary! However, portability is a HUGE concern, and you lose the power of CLR management. So I really wouldn't think of that, honestly.

So I think there's two possible options. There's raising community awareness about possible attacks on their .NET games, and there's creating a tool to prevent it. The former, I think, needs to be done in any case. People need to understand what's possible BEFORE they start working on a serious project.

I'm very experienced with .NET and know most of the intricacies of the CLR. I've also got a pretty strong arsenal of knowledge pertaining to native assembly language, and how it relates to programmers concerned with security. When we were teenagers, my friends and I would even exchange Win32 "crackme" applications and try to crack/patch/keygen each other's code. laugh And I still probe my own native code for weaknesses with a good ol' debugger. Even native can be frighteningly easy to crack. :-/ The trick is to make it so time consuming that the attacker will give up and move on.

If wanted, I can make time soon to do some articles/tutorials about such topics, and .NET/CLR themselves. I think that could shed some light on different vulnerabilities and possibilities. So if people are interested, please let me know, and what topics you would like to know more about. I can even do general C# stuff too, since I’ve noticed that most people try to make C# code “just work”, instead of work correctly and efficiently. I.e., making fields public (static) for external access. Ewww! *shudders* laugh

But on top of this, there are even less forceful ways to impede cheaters and crackers. Those pertain to the actual design of the software itself. This is especially true for online game networking; where a good client/server architecture can make cheating nearly impossible!

Oops, sorry for MY verbosity, heheh… But let me know. I’ll be around frequently.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 12/17/09 05:27

Hey guys, remember when we were talking about buidling assemblies on the fly and executing them. I was messing around earlier and it works pretty well...

http://www.youtube.com/watch?v=A5tTo11xp8w
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 12/17/09 13:50

Impressive application !! That 'Dynamic-lite-c' is a really interesting use of the engine sdk!


Posted By: aenkku

Re: C# wrapper - RELEASE 1.1.1.2 - 12/27/09 17:19

Very cool endeed smile
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 01/18/10 20:15

Hey Stromausfall, I'm in need to customize the wrapper a little bit so I can access some of the parameters of the Native structs.

Specifically I need to get the 'dy' member of the NativeFont struct. I tried adding this to the 'FONT' class...
Code:
private Var dy_ = null;
        public Var dy
        {
            get
            {
                unsafe
                {
                    if (dy_ == null)
                    {
                        dy_ = (Var)(IntPtr)(&((*FONTPointer).dy));
                    }
                }
                return dy_;
            }
        }


...yet I'm always getting 0, where as testing in lite-c gives me the value of 20.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 01/20/10 09:10

hi!
the problem in your code snippet was, that dy is an int not a var (open the NativeFONT.cs to see what type a variable has)! This snippet should work.
Code:
/// <summary>
        /// dy - see Gamestudio manual
        /// </summary>
        public int dy
        {
            get
            {
                unsafe
                {
                    return (*FONTPointer).dy;
                }
            }
        }


Maybe I will include some unlisted properties of engine objects in the next release (which I will release, when the new engine version isn't in public beta anymore)
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 01/20/10 09:15

ahh didn't notice that, I did a quick copy & paste from ENTITY* for the x member and assumed it would work, lol. I really need to start looking properly, lol.

Thanks again.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 01/25/10 01:06

The member 'matrix' is missing from the 'MATERIAL' struct. I need this variable for the function 'mat_set'. Could you please add a definition for it?

Edit>>> While we're on the subject of material, I think there may be a bug floating about somewhere. I'm trying to apply the shader 'envglass.fx' from the 'GStudio7\Code' folder to a model...
Code:
MATERIAL mat_ent = EngFun.mtl_create();
ENTITY entity = EngFun.ent_create("blob.mdl", new Vector(150, 0, 0), null);
mat_ent.skin1 = EngFun.bmap_create("t_day_sky+6.tga");
entity.material = mat_ent;
entity.SHOW = true;

EngFun.bmap_to_cubemap(mat_ent.skin1);
EngFun.effect_load(mat_ent, "envglass.fx");


The shader also needs 'default.fx' from 'GStudio7\Include'. The same code works fine in lite-c. I think it may have something to do with the 'mat_ent.skin1' as the shader uses this skin, and modifying the shader to use a skin embedded with the .mdl, works fine.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 01/25/10 18:23

hi!
in fact i already implemented some kind of mechanism to access this 'matrix', but as I now tried it myself, I had to recognize, that it doesn't work and is not that handy....
Thus I will implement a class 'MATRIX' (just like 'ENTITY' or 'VIEW), that offers function to get it's matrix as float[][] or set it with a float[][] and functions or properties to access each part of the matrix, like matrix41...
It's necessary to implement the matrix itself as class, as the engine functions can only access unmanaged memory, and thus the class will wrap a float[][] matrix in the unmanaged space of the application.

Concerning the bug - I tried your example and found only one difference between the wrapper and the lite-c version (i used the "sf_woman.mdl" as model and "skycube+6.tga" as bmap, both from the template folder) - the lite-c version gave me warnings, that "SKIN#01 - normal or height map missing" and that one 3 times! As I'm a real newbie in shader programming, this doesn't have to mean anything smirk
What was the error that occurred in your application ? What did differ between the lite-c and the c# version ?

I will fix the wrapper on the weekend - as I don't have that much time during this week ^^

Thanks in advance for your help in spotting down that error!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 01/26/10 00:20

The shader simply didn't work in C#. I broke the code down in lite-c, and by not setting material.skin1 to the sky-cube map, then the shader appears like it does in C#, thus I can only assume that material.skin1 is'nt being assigned correctly or something.

That 'SKIN#01' error is caused because that particular shader uses additional skins. You can use 'box.mdl' from 'GStudio7\Projects\shadertest' which has all the skins attached as required.

Here is a demo in lite-c...

http://djbm.kawanda.net/Public/ShaderTest.zip
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 01/26/10 21:16

Thank you for the sample project!
I've tried to rebuild that project in C# and it seems to me that it works just like the lite-c version.
I've uploaded the project (with a compiled version in the Debug folder)

http://www.matthias-auer.net/acknexwrapper/WrapperTestApp.zip

hmmmm, I wasn't able to see any difference between the lite-c and the c# version frown
Posted By: DJBMASTER

Re: C# wrapper - RELEASE 1.1.1.2 - 01/27/10 08:46

Ahh, it seems that the shader editor for my application, was using an older version of the wrapper. I haven't worked on the shader part in a long time so I guess I just forgot to update it. It's working fine now.

Thanks for once again bailing me out of trouble, lol.
Posted By: Stromausfall

Re: C# wrapper - RELEASE 1.1.1.2 - 01/27/10 08:52

No problem ^^
I hope to be able to upload a new version of the wrapper which supports Matrix operations this weekend!
Posted By: Stromausfall

Re: C# wrapper - 01/31/10 13:34

I've just uploaded a new version of the wrapper (1.0 for A7.82.3) which now offers a class MATRIX, which may be used like the Var class.
Posted By: maslone1

Re: C# wrapper - 02/04/10 18:57

Sorry, verwechslung
Posted By: Stromausfall

Re: C# wrapper - 02/06/10 17:23

hä ?
Posted By: DJBMASTER

Re: C# wrapper - 02/10/10 17:30

Thanks for the MATRIX class, it will come in handy.

Can u provide a delegate for the callback function that can be passed to 'engine_open' so that we can handle breakpoints etc through C#?

Thanks David.
Posted By: Joozey

Re: C# wrapper - 02/10/10 19:45

I will make good use of this wrapper laugh Thank you!!
Posted By: Stromausfall

Re: C# wrapper - 02/10/10 22:23

@DJBMASTER, I will look into this !

@Joozey, thanks ^^
Posted By: DJBMASTER

Re: C# wrapper - 02/14/10 03:11

Hi, I just noticed that the member 'greenBlueRed' of an ENTITY is in the wrong order because colors in lite-c go (blue,green,red). Why conitec couldn't stick to rgb, i'll never know, lol.
Posted By: Cowabanga

Re: C# wrapper - 02/14/10 11:31

Quote:
Why conitec couldn't stick to rgb, i'll never know, lol.
This is my dream.
Posted By: Joozey

Re: C# wrapper - 02/16/10 16:20

Stromausfall I keep getting the error that default.c is not found, but the game appears to work afterwards. What's wrong?
Posted By: pararealist

Re: C# wrapper - 02/16/10 17:29

Since the last update V7.80.1 this happens in the start up window
also in C++ project, but application still runs.
So its not the C# wrapper.
Posted By: Joozey

Re: C# wrapper - 02/18/10 00:57

Hm, I see. Luckily it's not fatal.

Another question:
Can I assign pointers to engine object parameters?

e.g.
Code:
override public unsafe void createComponent(int *posX, int *posY)
{
  BMAP myMap = EngFun.bmap_create("component.tga");

  myPan = EngFun.pan_create(null, 1);
  myPan.bmap = myMap;
  myPan.flags |= Flags.VISIBLE;
            
  myPan.pos_x.IntValue = *posX;
  myPan.pos_y.IntValue = *posY;
}



If the application behind the interface then changes the integers given through the function, the panel should move... but nothing appears to happen. Is it jammed at the IntValue part?

EDIT:
Nvm, I see now that I -sort of- can't pull pointers out of classes.
Posted By: DJBMASTER

Re: C# wrapper - 02/18/10 21:27

If you want to update an engine object when a variable changes, why not do it in the 'set' clause?
Posted By: Joozey

Re: C# wrapper - 02/18/10 23:56

What set clause? PANEL.pos_x needs to be *automatically* updated in my case.
Posted By: DJBMASTER

Re: C# wrapper - 02/19/10 02:02

To have it update you would need a while loop to set the pos_x to the value of the variable every frame. The way I suggest you do it is create a property for the variable, and update the pos_x within the set clause.

You could create a custom event which fires when the var changes.
Posted By: mikaldinho

Re: C# wrapper - RELEASE - 02/19/10 11:26

w
o
w


(^_^) that is impressive.

i downloaded it.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 02/19/10 11:40

hmm, I'm interested in how you could extend the wrapper so that we can use DirectX functions. You can do that in lite-c, by calling draw_begin() and then calling DX functions. Instead of having to wrap d3dx9.dll for C#, maybe the D3D device created by the engine could be exposed so that we can use managed DirectX.

I'm going to need this so I can add blocks in the level editor of easy scripter. Any thoughts?
Posted By: mikaldinho

Re: C# wrapper - RELEASE - 02/19/10 13:20

it could work. i think with a bit of work then it will work
Posted By: MasterQ32

Re: C# wrapper - RELEASE - 02/25/10 16:09

i tried it!
super

but whats about a statment like this:
Code:
ENTITY my = ent_create("guard.mdl",new Vector(0,0,50),null);
my.animate("stand", my.skill1, (Var)(int)EngFun.ent_anim_FLAGS.ANM_CYCLE);



or better:

Code:
ENTITY my = ent_create("guard.mdl",new Vector(0,0,50),null);
my.animate("stand", my.skill1, EngFun.ent_anim_FLAGS.ANM_CYCLE);


Richi007
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 02/25/10 17:45

you mean, you would like to have certain methods as class methods from ENTITY ?
Posted By: MasterQ32

Re: C# wrapper - RELEASE - 02/27/10 10:35

yes, because the meaning of the code is much cleaner und you don't need the EngFun everytime.
An the code will be smaller, so you don't have to write as much as in the actual way.
Posted By: ventilator

Re: C# wrapper - RELEASE - 02/27/10 14:12

i strongly agree with this too. it doesn't really make sense to directly copy the c-api as much as possible. make better use of c#'s oo features.

it would be a lot cleaner if all the engine functions were put into the proper objects as methods. the structure is quite clear anyway. all ent_ functions belong to entities and so on.

it also should be
Entity my = new Entity("guard.mdl", new Vector(0,0,50), null);
instead of ent_create().

...and i still think that var handling should be automatic. tongue
Posted By: Joozey

Re: C# wrapper - RELEASE - 02/27/10 15:46

It's not hard to make it yourself if you plan to use the wrapper, but yeah it would save time if this were implemented right away tongue.
Posted By: ventilator

Re: C# wrapper - RELEASE - 02/27/10 16:01

sure, in a few days i could complete my own wrapper i have started to do with boo a while ago but i don't work much with gamestudio at the moment...

...but since stromausfall's wrapper kind of is the official gamestudio c# wrapper now (it is on a prominent spot on the download page) it could/should strive for perfection in my opinion. laugh
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 03/07/10 21:46

thanks for your input ventilator, Joozey and Richi007 !
These are some good ideas !
This wrapper may be on the download page, but I'm still critical over certain aspects of it smirk
one is of course the var handling, which, as Ventilator pointed out is quite clumsy
another one, which definately poses a problem is the handling of strings which are sent to the engine ... I'll explain that issue in a short example here
-if I want that the engine is able to access a certain variable which is declared in c#, I have to create a variable on the heap(I think ^^). This data on the heap will be deleted (and thus freeing the space it occupied) when the var object is collected by the garbage collector -> now that's fine !
-but if I want to send a string to the engine, that's something different.. I currently allocate space for the string on the heap and then pass the address to the engine (just like I did with variables), but as I'm having here an inconsistency (in fact if I would want to use the current concept of the wrapper consistently, only STRING objects should be able to be passed) i don't create String objects for strings... That's why the memory allocated for strings, won't be freed EVER !
I will need to find out which functions actually copy strings into the engine data space or only use them for a short time, and functions that access the given pointer over an amount of time. Kind of like functions that only pass a variable and functions that ACCESS a variable (like pan_setneedle).

To actually improve the wrapper, a complete rewrite is necessary without a doubt.
You mentioned that you would be able to finish your own .net wrapper in a few days, in my opinion you should seriously think about completing it.
It wouldn't be wise to just don't create the wrapper because someone else's is on the download page with another wrapper, that is inferior to one's wrapper ! I will gladly step aside, as soon as you post a wrapper that is superior to mine (which yours should easily be if you implement it the way you propose it and already showed in this thread - although I'm not that sure about the speed of lambda expressions and the big array that you use to simulate pointers ^^).
I just wouldn't like to see that a better wrapper is hold back, because of the fact that another wrapper is on the download page ! My aim is not to create a wrapper, but to be able to use the engine in c#, which is why I would highly encourage you to compleate your wrapper, if you think that it's better !
Nonetheless I will most likely start to work on a rewrite of the wrapper in the next weeks, the actual rewrite may take some time.
My post isn't intended to put pressure onto you to finish your wrapper, by saying "I won't continue my wrapper - create a better one", I just would like to say that if you want to create a wrapper yourself, which you think is superior to mine, don't let yourself be hold back, by something like a spot on the download page (which will switch in a second without a doubt if your wrapper is better ^^), or a feeling that you wouldn't want to take someone else's territory, or even a feeling that you wouldn't want to finish and release your wrapper, while I'm still working on mine - out of "kindness" !
As you can see I'm a strong supporter of a free market ^^
Posted By: ventilator

Re: C# wrapper - RELEASE - 03/07/10 23:47

the few days probably rather would be a whole week. tongue which i don't have at the moment and i also don't work with gamestudio currently so my interest is pretty low. that's the reason i don't complete it.

i also don't think that your wrapper is inferior. its completeness makes it much superior even if there are some design quirks i don't like that much. i am looking forward to your future versions. laugh



what is your inconsistency with strings? i didn't quite get that part in your post. (edit: ah, now i get it. i missed the sentence in the (). but i wouldn't use STRING objects if not absolutely necessary. they are useless compared to the powerful strings of languages like c# or python.)

if i remember correctly the functions that need the pointer for a longer time mainly are some gui functions. in my python wrapper i simply wrote some code in the wrapper functions which handles keeping the reference around as long as it is needed. this shouldn't be a big deal.



writing wrappers is a very repetitive task. i more and more think that it would make sense to write some kind of a7 header file parser which then automatically spits out most of the code. could be quite tricky but changes to stuff like var handling could be done without almost complete manual rewrites then.
Posted By: Neiko

Re: C# wrapper - RELEASE - 03/18/10 00:13

First of all, nice wrapper. I was waiting for something like this.

I haven't found so many tutorials or code snippet for this wrapper. I will contribute my prototype code, when its finished.

But at the moment i have a problems with printing Text.

I've tested something like this:

Code:
TEXT my_text = EngFun.txt_create(1, 0);
my_text.pos_x.IntValue = 100;
my_text.pos_x.IntValue = 100;
EngFun.str_cpy(my_text.pstring[0], "Hello World");
my_text.flags = Flags.INVISIBLE | Flags.SHOW;



Which gives me a ArgumentNullException in the EngFun.cs line 2634. I'm using the 7.82 wrapper.

If i use instead:
Code:
EngFun.txt_addstring(my_text, "test");



Then I can see the "test" string, but how can I change it afterward?

Another thing is, I'm not sure if these both methods are connected somehow, but I've tried this:

Code:
TEXT my_text = EngFun.txt_create(2, 0);
my_text.pos_x.IntValue = 100;
my_text.pos_x.IntValue = 100;
Var v = EngFun.txt_addstring(my_text, "test");
STRING s = EngFun.txt_str(my_text, v.IntValue);
my_text.flags = Flags.INVISIBLE | Flags.SHOW;



And got an "s = null" as an result, but only when the first parameter from txt_create is bigger then 1.

I hope you can help me and I'm sure I will have some more questions in the future.

best regards
Neiko
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 03/18/10 07:10

here's the code to change the string array of a TEXT object :

Code:
TEXT my_text = EngFun.txt_create(2, 0);
            my_text.pos_x.IntValue = 100;
            my_text.pos_x.IntValue = 100;
            my_text.pstring = new String[] { "asdfasdf", "asdfasfd" };
            my_text.flags = Flags.SHOW;
            yield return 200;
            my_text.pstring = new String[] { "234234", "234324" };



special thanks go to neiko who found a bug (some functions who return Angle didn't work) which is fixed in the new version of the wrapper : 1.0.1
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 03/24/10 20:43

Hey Stromausfall. In your next release of the wrapper, do you mind marking your classes as Serializable? This way we can clone engine objects using a MemoryStream.

Thanks.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 03/27/10 07:47

afaik serializable is used to save an object and later restore it - but this would only work in the same session/instance of the engine.
For what exactly would you use MemoryStream for ?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 03/27/10 09:33

I'm using it for my panel editor at the moment but I can extend it for my other editors. It allows me to create an exact memory clone of a current engine object, without having to manually copy over properties.

As for your same session argument, yes this is true that the object will only remain while the current instance of the engine is 'alive'.

As my editor is just the visual part, it retrives the data from an external source, where the data is also cloned.

You don't have to mark them if you don't want to, lol.

Btw, I know that it's off-topic, but have you experience with the 'var' keyword in VS 2008?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 03/28/10 12:20

nope I've got no experience with 'var' smirk
Posted By: DJBMASTER

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

oh ok, well I had only recently discovered it while reading a C# book. It allows implicit conversion...
Code:
var a = 45;
var b = 7.86;
var c = "hello world";
var d = false;


Maybe that could help you with automatic var handling?
Posted By: pararealist

Re: C# wrapper - RELEASE - 03/28/10 13:42

Would'nt there be some confusion between C# var and Acknex var?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 03/28/10 13:48

I haven't looked up all the rules of the C# var, but maybe it could be used internally by the wrapper. Instead of the Var.IntValue and Var.FloatValue business.
Posted By: pararealist

Re: C# wrapper - RELEASE - 03/28/10 16:11

I see, Var.IntValue is a little too much sometimes, find myself forgetting them a lot, expecially when i return from C++ project.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 03/31/10 20:38

the current Var object also allows implicit conversion for example
Var xx = 30;

but the main reason why 'Var' is indispensable at the moment, is, that certain functions like "pan_setneedle" take a REFERENCE to a variable !
and in c# it's not possible (at least not user friendly afaik) to get the reference to a value type, like int, var, or float !
and if one would only use implicit conversion, for example :

Var xx = 30;
and then give pan_setneedle the xx variable
and then for example change xx like this : xx = 400 + 70;
pan_setneedle would NOT take notice of the change, as xx references now to another new variable...

but nonetheless, the wrapper already uses implicit conversion, thus

float value1 = 3.4f;
int bla = minv(value1, 100);

and

int currentTimeStepValue = EngVar.time_step;
int currentTimeStepValue2 = EngVar.time_step.IntValue;

should work fine afaik!

I already tried to use ventilator's suggestion - lambda expressions, but they don't seem to be able to hold references to value types in c# frown
Posted By: ventilator

Re: C# wrapper - RELEASE - 03/31/10 21:26

can you post some snippets of your lambda experiments? i have never seen lambdas in c# so it would be very interesting.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 03/31/10 21:31

ooo, i thought getting a reference to a value type was as easy as supplying the 'ref' keyword...
Code:
public void ChangeMe(ref int i)
{
i++;
}
...
int x = 3;
ChangeMe(ref x);
// now x = 4


It's probably alot more complex than that, lol.
Lambdas seem pretty powerful, although havent really played with them.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/01/10 02:07

here's an example for a lambda expression in c# :
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lambdaTest
{
    class Program
    {
        delegate int getValueOfReference();

        static getValueOfReference newReferenceStorage = null;

        static void dummy(int valueInteger)
        {
            newReferenceStorage = () => { return valueInteger; };

            //that's how it should look like - but unfortunately doesn't work in c#
            //newReferenceStorage = () => { return refInteger; };
        }

        static void Main(string[] args)
        {
            int refInteger = 3;
            int valueInteger = 4;

            dummy(ref refInteger, valueInteger);

            valueInteger++;

            //when newReferenceStorage is called, the anonymous method is called..
            Console.WriteLine("variable : " + valueInteger);
            Console.WriteLine("lambda expresssion : " + newReferenceStorage());

            //give some time to read the output...
            Console.ReadLine();
        }
    }
}



Meanwhile I was able to further reduce the lines of code required for a experimental method (as mentioned : "at least not user friendly") which allows to store the reference of a value type. Although this method has some drawbacks :

1. the code needed from the user...

Code:
int dummyVariable = 3;



EngFun.pan_setvar(
  dummyPanel,
  1,
  1,
  delegate() { Reference.acquire(ref dummyVariable); }
);

//or (the same)

EngFun.pan_setvar(
  dummyPanel,
  1,
  1,
  () => { Reference.acquire(ref dummyVariable); }
);



2. for each variable that is stored, one thread needs to be created -> overhead smirk

3. the method pins/fixes the position of the variable in the memory, thus it disables the object, of which the variable is a member variable, to be moved from the garbage collector, which isn't preferrable....


My conclusion is that taking a reference from a variable still isn't a solution smirk
One way to deal with this problem would be, to remove the Var object alltogether and replace them with doubles (properties). And to create a special object/class for the panel functions that use a pointer to a variable - like the current Var object. Thus such a special class would only be needed for these panel functions, and everywhere else doubles (properties) would be used...

edit : -> thus the Var object would only be used in the panel functions that need a pointer to a variable..
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/01/10 07:58

Finally I got an idea, how to store references to a value type, without the need of a Thread. This method would/could use ventilator's suggested idea, of keeping an array for all variables that should be updated, in/because of these panel functions and update them at the beginning/end of a frame...
The downside is, that the code for the user to enter isn't that beautiful (two lambdas, if the panel function would read AND write into the variable)...
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class ReferenceStorage
    {
        public delegate double getValue();
        public delegate void setValue(double value);
        public getValue getValueLambda;
        public setValue setValueLambda;

        public ReferenceStorage(getValue getValueLambda, setValue setValueLambda)
        {
            this.getValueLambda = getValueLambda;
            this.setValueLambda = setValueLambda;
        }


    }

    class Program
    {
        /* this method should depict the engine, changing/reading through the reference */
        static void backgroundFunction(ReferenceStorage.getValue getValue, ReferenceStorage.setValue setValue)
        {
            /* 
             * if a permanent reference to that variable would be needed,
             * create a Reference Storage, to keep the two Lambda expressions
             * 
             * code :
             * 
             * ReferenceStorage newStorage = new ReferenceStorage(getValue, setValue);
             */


            while (true)
            {
                setValue(getValue() + 1);
                Console.WriteLine(getValue() + " increased, using lambda expression");

                System.Threading.Thread.Sleep(1500);
            }

        }

        /* a method that would be called from the user */
        static void dummyWrapperFunction(ReferenceStorage.getValue getValue, ReferenceStorage.setValue setValue)
        {
            System.Threading.Thread t = new System.Threading.Thread(
                () => { backgroundFunction(getValue, setValue); }
            );
            t.Start();
        }



        static void Main(string[] args)
        {
            double dummyValue = 30;

            /* call a dummy wrapper function and pass a 'reference' to the value type dummyValue 
             *
             * THIS is the code that user would have to enter, if the panel function would read AND write into the variable
             */
            dummyWrapperFunction(
                () => { return dummyValue; },
                (double newDummyValue) => { dummyValue = newDummyValue; }
            );

            while (true)
            {
                dummyValue += 1;
                Console.WriteLine(dummyValue + " increaesd, through directly increasing the variable");

                System.Threading.Thread.Sleep(1500);
            }
        }
    }
}



This could/would most likely be preferable over the two other options I mentioned, although it's not that easy for the user to use....

edit:
I'm currently always referring to double as the new variable type that could replace Var, but what I'm asking myself is, wouldn't a float suffice, as the value range of Var is already way smaller than float ?
pros for float in my opinion would be, a double isn't really needed and float should be faster in general than double I think
cons for float would be, that the usage of float is ugly to say the least... for example, the following statement is not allowed :
Code:
float bla = 30.2;


it has to be :
Code:
float bla = 30.2f;


Posted By: ventilator

Re: C# wrapper - RELEASE - 04/01/10 10:51

thanks for your examples. laugh

wouldn't it also be possible to do a solution without lambdas but simply with "ref" and an array with all the vars and refs that get updated each frame?

Posted By: Stromausfall

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

i also tried that, but as soon, as the function returns -> the ref gets out of scope, the reference is lost !
Thus the ref is only valid within that function, but as soon as the function ends, the ref isn't valid anymore - and these special panel functions need a permanent reference to the variable smirk
Posted By: ventilator

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

but don't you store the ref in the array together with the corresponding var? then it shouldn't get lost?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/01/10 12:15

the first problem is, that it's not able to save a ref to a variable afaik!
and the next problem is, that the ref is only as long valid, as it is in the scope of the function ->

Code:
void dummy(ref int x) 
{
only here x is valid !, as soon as the program jumps back to where dummy was called 
from, x is invalid ! 

this works fine as long as we don't want to pass a permanent reference to a variable!
to make it permanent it would be necessary to stay as long in this scope, as we need the ref !
I tried that with Threads, but as mentioned - too much overhead and calling the function is 
at least as ugly as the lambda approach ...
}



and one may also not use lambdas which use variables that are declared 'ref'!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 04/01/10 13:00

Does boxing the variable to System.Object help?

Also, I guess the problem with losing the reference is because when the function ends, the variable is marked for garbage collection.

You could use a 'fixed' block to pin the var in memory, although I'm not sure if this remains after the function is ended.

Additionally you can allocate memory using 'stackalloc' in an unsafe block, which means the GC wont touch it.
Posted By: pararealist

Re: C# wrapper - RELEASE - 04/01/10 13:05

I was wondering if the two files var.h and var.cpp that are now in sdk could perhaps throw any light on the subject.
It seems they have created a var class that is much better for programming in C++.
I wonder if something similar could be done for C# ?
This is just a suggestion.
Posted By: ventilator

Re: C# wrapper - RELEASE - 04/01/10 13:18

but fixed point variables are so old school. laugh they shouldn't be used anymore. i think if you work with c# you should just use ints, floats,... and the wrapper should hide the necessary conversions.

i would prefer if a8 gave up vars altogether. tongue

...
i really would like to experiment with all that c# reference/lambda/closure stuff but unfortunately i don't have much time at the moment. i am sure though that there is an elegant solution somewhere for this whole problem.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/01/10 13:22

@DJBMASTER
nope boxing isn't useful, as you only box the value itself, not the variable !
thus if you pass a boxed variable and change it, the variable itself won't change !

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

namespace dummyTest
{
    class Program
    {
        static void changeVariableValue(object i)
        {
            int bla = (int)i;   //unbox
            bla++;
        }

        static void Main(string[] args)
        {
            int bla = 30;
            changeVariableValue(bla);
            Console.WriteLine(bla);

            Console.ReadLine();
        }
    }
}



afaik the problem with ref is, as long as ref is active, the object can't be moved by the garbage collector (that doesn't imply deleting of the object, but just moving the object for better usage of memory). And like you said, when the function is out of scope, the variable in the object isn't fixed anymore and maybe somewhere else!

You're right with stackalloc, that's how the current Var object handles this situation!

@pararealist
i had a quick look at these two files, but unfortunately their concept of operator overloading won't work in c#, as it's not possible to overload the equals (=) operator in c# frown


@all
what do you think about the mentioned method to use double instead of var and lambdas when necessaray (in the special panel functions) - is it superior to the current concept, or has someone a suggestion for another solution to this problem ?
thanks in advance ^^
Posted By: ventilator

Re: C# wrapper - RELEASE - 04/01/10 16:48

hm...

Code:
using System;

namespace AnonymousMethod
{
	delegate int Func();
	
	class Program
	{
		static Func[] funcArr = new Func[10];

		static void setPanelVariable(int i, Func f)
		{
			funcArr[i] = f;
		}

		static void Main(string[] args)
		{
			int i1 = 10;
			int i2 = 20;
			int i3 = 30;
			
			setPanelVariable(0, () => i1);
			setPanelVariable(1, () => i2);
			setPanelVariable(2, () => i3);
			
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine(funcArr[i]());
			}

			i1 = 111;
			i2 = 121;
			i3 = 131;
			
			for (int i = 0; i < 3; i++)
			{
				Console.WriteLine(funcArr[i]());
			}
			
			Console.ReadLine();
		}
	}
}

this seems to work fine. shouldn't this be useable nicely for panel variables? looks very similar to what i did in python but maybe i am misunderstanding something. i am no c# expert. laugh
Posted By: Joozey

Re: C# wrapper - RELEASE - 04/01/10 18:19

Is there also a possibility to not make the wrapper unsafe, or implementations using the wrapper not bound to use unsafe code?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/01/10 20:29

@ventilator
this looks great, i like how the code needed for the lambda expression is shorter than my attempt !
The handling of the updating process itself doesn't pose problem, only the usage for the user did ^^

@Joozey
i had a quick look at the wrapper and think this could indeed be possible !
edit : I'll try to implement the wrapper, without using any unsafe instructions - so far I was able to do this ^^

@all
should the wrapper use double or float instead of Var ?
Posted By: ventilator

Re: C# wrapper - RELEASE - 04/01/10 20:47

yes, floats are cheaper but i think this only really matters for heavy number crunching. probably it doesn't make much difference for passing some numbers around.

(in python there only are doubles. single precision floats don't exist.)

so i think doubles are fine but i also wouldn't mind the needed f that much.
Posted By: DarkPhantom

Re: C# wrapper - RELEASE - 04/04/10 17:45

you should use double instead of float. the floatingpoint unit in the cpu converts floats always to double. double needs as double as much memory as a float. but i think that doesnt matter that much because textures, models etc need around 90% of used memory
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/04/10 18:28

I didn't knew that, that should clarify the question if double or float should be preferred ^^
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 04/04/10 18:57

Hi, I'm sometimes getting the exception 'Collection was modified after the enumerator was instantiated.' at the line...
'while (AddToScheduleListEnumerator.MoveNext() == true)'.

This is in the function 'AddToScheduleList' of 'Scheduler.cs'.

Any ideas what events could cause this to happen, and any possible workarounds?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/04/10 20:27

I'll have a look at it, it seems like there's some inconsistency in the scheduler...

do you happen to have an example of a program that causes such a crash - or any guess, which events or function seem to cause this problem more often ?

edit :
do you use two threads in your program ? because i think that this problem could arise if the "engine"-thread (that iterates over the "yield return" functiosn) exists AND ANOTHER thread that somehow also tries to interact with that thread or the engine !
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 04/04/10 21:01

Ermm well first I use 'engine_open' to load the engine and then once the 'hWnd' variable is available, I use some win32 functions to embed the engine into my form.

Whenever I want to interact with the engine I use a seperate function (IEnumerable type) and call 'Scheduler.AddEventVoid(FunctionName)'.

So yes there is probably the 'engine' thread and the 'form' thread. I have however used 'yeild return Scheduler.PROC_MODE.PROC_EARLIEST' at the beginning of most functions. I thought this would allow a 'gap' into the engine processing.

There does seem to be some synchronisation issue though, because it is a very random bug.

You could maybe re-create this scenario but using the 'windows embed' demo I submitted, and from the form try to change something in the engine multiple times, like a random screen color, etc; to see if you get synchronisation problems.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 04/04/10 21:06

thank you for your detailed explanation - they are invaluable to detect the cause of the problem !!
the situation you mentioned, seems to be the exact reason, why this bug occurs ! You add a thread to the scheduler (regardless of the priority of the function like Scheduler.PROC_MODE.PROC_EARLIEST), while this one is maybe just iterating over the list to which you add the function -> this causes the crash !
I will have a look at it and see if i can create a quick hotfix for the wrapper, which adds some kind of "thread-safe" - Scheduler.AddEventVoid(FunctionName) function - which should prevent this problem !

edit :

I've uploaded a new version of the wrapper : 1.0.2 (big thanks go to DJBMASTER for providing me with the needed details to solve this problem !!), that now includes a method named AddEventVoidThreadSafe that is the thread safe variant of the method AddEventVoid !
Whenever you don't need AddEventVoidThreadSafe, use AddEventVoid, as methods added through AddEventVoidThreadSafe aren't executed immediately, but may take up to one frame to execute - so only use AddEventVoidThreadSafe if you access the scheduler from another thread !

I've used the following code to test this new function :
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections;

using AcknexWrapper;

using System.Threading;

namespace OldWrapperTestApp
{
    class Program
    {
        private static DateTime StartTime = DateTime.Now;

        static IEnumerable bla()
        {
            yield return 1;
        }

        static void dummyFun()
        {
            Thread.Sleep(1000);
            while (true)
            {
                Console.WriteLine(DateTime.Now - StartTime);
                Scheduler.AddEventVoidThreadSafe(bla);
                //Scheduler.AddEventVoid(bla);
                Thread.Sleep(2);
            }
        }

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

            Thread t = new Thread(dummyFun);
            t.Start();

            Scheduler.StartScheduler(bla);

        }
    }
}



and I've got the following results :
Code:
AddEventVoid

1.)  00:00:16.4375000 - crash
2.)  00:00:40.8750000 - crash
3.)  00:00:04.4375000 - crash
4.)  00:00:04.2968750 - crash
5.)  00:06:12.2968750 - crash
6.)  00:00:03.3750000 - crash
7.)  00:00:45.0781250 - crash
8.)  00:00:05.2968750 - crash
9.)  00:00:07.7031250 - crash
10.) 00:00:14.4687500 - crash

AddEventVoidThreadSafe

1.) ~ 00:02:30 - aborted by user - no crash
2.) ~ 00:02:45 - aborted by user - no crash
3.) ~ 00:02:30 - aborted by user - no crash
4.) ~ 00:03:00 - aborted by user - no crash
5.) ~ 00:02:30 - aborted by user - no crash


Posted By: Joozey

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

For some reason Visual C# can't open the acknex.dll, can't get it to work. Any ideas? Tried to copy the dll everywhere, did the post-build event exactly as described, but no results.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 06/14/10 12:27

hmm, when you build your application does the WED dialog popup and display 'acknex.dll'?

It will then be copied to the same directory as your exe.
Posted By: Joozey

Re: C# wrapper - RELEASE - 06/14/10 12:41

No, it crashes on engine_open() line in the wrapper:
EngVar.EngineVarPtr = NativeEngFun.engine_open(tempString, 0);

and saying it could not find acknex.dll.
But the path should be good in the post build event.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 06/14/10 13:17

It should be...

"C:\Program Files\GStudio7\WED.exe" -p "$(TargetDir)\$(TargetFileName)".

Open the folder where your exe is located (usually in the bin/debug folder) and when you build your project, check to see that the 'acknex.dll' is actual copied.
Posted By: Joozey

Re: C# wrapper - RELEASE - 06/14/10 13:25

Yes got that, although my drive is D:.
I removed the acknex.dll in the debug folder, build it, and it complains that it can't find it. But the acknex.dll is in the folder, again so it is copied.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 06/14/10 14:21

hmm that's strange, i'm not sure why it wouldn't find it. The exe will always search it's working directory first for the dll. The other explanation could be that you are actually building the exe in a different folder.

Check Project > [ProjectName] Properties > Build > Output path. It should be 'bin\Debug\'.

Apart from that i'm not sure what's going on.
Posted By: Joozey

Re: C# wrapper - RELEASE - 06/14/10 14:23

The path is bin\release but changing has no effect.
Could it be a screwed newer version of 3dgs?

EDIT:
Even the examples like firstprogram/compiled/FirstTestProgram.exe wont work. What's going on frown.
Posted By: Joozey

Re: C# wrapper - RELEASE - 06/15/10 11:58

Sorry for doublepost.
Anyone knows a possible solution?

When I download the wrapper and try an example, it can't find acknex.dll. The cause can't thus be visual studio nor gamestudio related, as published apps should work. Is it .NET?
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 06/15/10 12:25

What .NET framework version are you running? Are you using the free visual C# express or visual studio (even though this shouldn't really make a difference).

I think maybe the problem is not that 'DLLImport' can't find 'acknex.dll' but it can't find another dll that acknex.dll is dependant upon.

You can use a program called 'dependency walker' to check which dlls acknex.dll needs. You may also have to change your PATH environment variables.

But if normal lite-c apps work when published, then I would try re-installing .NET or updating to the newest version, if possible.
Posted By: Joozey

Re: C# wrapper - RELEASE - 06/15/10 13:09

did a reinstall but no effect.

But luckily it has been solved. As you say acknex.dll was missing dependencies. No idea what ones but copying all dll's in the 3dgs folder to the project folder provided the solution laugh. This is a big relief. Certainly will give dependency walker a try. Thank you!
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 06/15/10 13:38

ahh I would say it is most likely 'd3dx9_30.dll' that it needed. Glad you got it working.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/04/10 00:43

Hey Stromausfall, there seems to be a problem with 'ang_rotate'. Whenever I try to use it I get...

"Unable to cast object of type 'AcknexWrapper.Vector' to type 'AcknexWrapper.Angle'."

...and it may not be limited to ang_rotate.

Any ideas?

Thanks.
Posted By: skeu

Re: C# wrapper - RELEASE - 07/05/10 06:58

Good morning to all laugh
First, thank you for your help, it was great laugh
I have one question about c# wrapper: is there any way to import a proyect from liteC to C-Sharp?
I would like to know this because i need to interoperate with a software developed.

Thank you in advance.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/05/10 07:35

I think you'll have to start again using C#. Even if you could import a lite-c script, you would have to change a lot of things anyway.

The best thing to do it to write a little utility that will replace the syntax in your lite-c script to C# syntax.
Posted By: skeu

Re: C# wrapper - RELEASE - 07/05/10 07:52

ok, so i should translate my software.
My concern is how to include developed libraries that i need to execute my software. In Acknex manual i didn't see anything to do that.
Do you know where can i see information about developed libraries import?
(I'm very grateful for your help)

Regards
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/05/10 07:54

What language are the libraries developed in?
Posted By: skeu

Re: C# wrapper - RELEASE - 07/05/10 08:07

The libraries are developed in LiteC too, but i don't know if with C# Conversion and posterior import, is enough to run it.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 07/05/10 08:42

Doubt it, you'll have to do a lot of converting.
Posted By: skeu

Re: C# wrapper - RELEASE - 07/05/10 09:13

I see... i will try it, if i can't i will study other method.
thanks!
Posted By: BoH_Havoc

Re: C# wrapper - RELEASE - 08/06/10 14:47

I always get this error when trying to compile.
I'm reather new to C# (only did the tutorials that come with it as well as some online tuts), so the error message doesn't really help me.

Unfortunally it's also in german
Quote:
PInvokeStackImbalance wurde erkannt.
Message: Ein Aufruf an die PInvoke-Funktion "AcknexTest!AcknexWrapper.Native.NativeEngFun::engine_open" hat das Gleichgewicht des Stapels gestört. Wahrscheinlich stimmt die verwaltete PInvoke-Signatur nicht mit der nicht verwalteten Zielsignatur überein. Überprüfen Sie, ob die Aufrufkonvention und die Parameter der PInvoke-Signatur mit der nicht verwalteten Zielsignatur übereinstimmen.


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

namespace AcknexTest
{
    class Program
    {
        static void Main(string[] args)
        {
            EngFun.engine_open(null);
            EngFun.error("Hello World!");
            Scheduler.StartScheduler(null);
        }
    }
}



Also correctly linked to the AcknexWrapper folder, and .dll seems to be created by WED (at least acknex.dll gets copied to the debug folder and a wed console window pops up everytime i compile)

I'm using Visual C# Express 2010 at the moment, but could switch to Visual Studio 2010 Ultimate if really needed (don't like the 7GB install size though...).

Would be nice if someone can help me out here, as i'm trying to create some editors for shade-c and am sick of WinAPI wink
Posted By: MasterQ32

Re: C# wrapper - RELEASE - 08/06/10 15:15

try this:
EngFun.engine_open("");
Posted By: BoH_Havoc

Re: C# wrapper - RELEASE - 08/06/10 16:24

Tried that, still get the same error.
Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 08/06/10 16:36

It has nothing to do with the parameters, its the 'engine_open' function itself.

This is a 'PInvokeStackImbalance', a much more serious error which will corrupt the statck leading to all kinds of problems.

The problem is due to that the managed signature/method name does not match the unmanaged function in acknex.dll, upsetting the stack.

The weird thing is, is that this is handled by the wrapper with the P/Invoke declaration / mashalling stuff. I've never experiences this exception before whilst using the wrapper and so I'm not sure of the cause.

What version is the acknex.dll you are using?
Posted By: BoH_Havoc

Re: C# wrapper - RELEASE - 08/06/10 17:20

My acknex.dll is version 7.8.4.2 (8,0,0,1) .
I'm using the latest A7 release (7.86 pro).

[edit] also, when trying to start my compiled exe, i get these errors:
Quote:

Error in line 1:
include file default.c not found
"#include <default.c>"

Error in line 3:
'MZ' undeclared identifier


I never included default.c, nor do i know what MZ is

Posted By: DJBMASTER

Re: C# wrapper - RELEASE - 08/06/10 17:56

hmm this is really strange, why does it even use default.fx?
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 09/25/10 22:40

@BoH_Havoc
Sorry, I was/am kind of busy lately, I unfortunately didn't look at this thread for a while !

I also experienced the error you mentioned under VS 2010, i uploaded a fix for VS 2010 on the acknexwrapper.matthias-auer.net homepage !

I also hope to upload a beta version of the new wrapper (only for 7.8x atm) in the next days (hopefully not weeks) - if i find enough time !

The new wrapper won't use unsafe code anymore, the usage of strings will be improved and won't use a var object, only normal doubles and ints, and the engine objects like ENTITY will have class methods which are the corresponding functions in lite-c like ent_create (although I'm not quite sure whether this will prove to be handy in practice - as it's not always intuitive where to find a function that one searches)..
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/05/12 20:50

Hi, when I use "yield return ScheduleMethod.PROC_EARLY;" the engine (A7) crashes. Do I have to consider something when using PROC_... or is this a bug?

Thanks in advance!
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 06/06/12 06:43

hmmm this should work afaik, did you add “A7_WRAPPER” to Project Properties > Build > Conditional compilation symbols ?
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/06/12 10:52

Yes I did add "A7_WRAPPER" before. I readded it but still it won't work.
If I comment the PROC_... lines everything is working fine.
I tried the same code snippet in A7 without the wrapper - there it works.
btw: I use Visual C# Express 2010

Debugging: http://img266.imageshack.us/img266/4423/62305807i.jpg
Posted By: pararealist

Re: C# wrapper - RELEASE - 06/06/12 13:35

I am using A8, but find if i do not add
yield return 1;
somewhere before
yield return ScheduleMethod.PROC_LATE;
it also crashes.

I have this in my camera method and it stops the jagged panning,which returns when i remove PROC_LATE, so it seems to work.
Posted By: Stromausfall

Re: C# wrapper - RELEASE - 06/06/12 13:42

I've installed A7.866 but can't reproduce the error !
could you create a small example and post the code here or send me the small example project ?

EDIT :
thanks pararealist now i can reproduce it too !

btw, I'll post the link to the new version in the "C# wrapper 2.0 - RELEASE" thread - the thread for the new wrapper (not the old one from some years ago !"
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/06/12 15:33

Thank you very much, it works now. laugh
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/08/12 14:28

How can I use vec_for_screen in the wrapper? There are no examples and I can't figure it out by myself.
Posted By: pararealist

Re: C# wrapper - RELEASE - 06/08/12 15:06

i have not used it but should be
the same as manual except called like this

yourvector.vec_for_screen(yourview)
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/08/12 15:21

Thank you, it works. I got the whole syntax wrong crazy
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/12/12 17:01

Hi, when I use an OpenFileDialog to load a model with

"ENTITY.ent_create(LoadModel.FileName, new Vector(100, 100, 0), *anyfunction*);"

I often get an AccessViolationException error (...wurde nicht behandelt. Es wurde versucht,
im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf,
dass anderer Speicher beschädigt ist).

The Debugger points to (EngFun.cs):
Code:
/// <summary>
        /// engine_frame - see Gamestudio manual
        ///  - for more detailed and up to date documentation, visit http://manual.3dgamestudio.net/ </summary>
        public static int engine_frame()
        {
            return NativeEngFun.engine_frame();
        }


This mainly happens if I load an *.MDL-file with 3+ MB. Then the engine needs a little time to load the model
(short freeze of the embedded engine window) and I get the error (depends on the complexity/texture space of the model).
I suspect that maybe the Scheduler and this freeze cause this error but it could be my fault, too. Do you have an idea?
Posted By: pararealist

Re: C# wrapper - RELEASE - 06/12/12 17:28

Where are you calling openfiledialog from?
could be a threading issue maybe.
LoadModel.FileName is this a string? or a class that returns a string? Maybe check that string is not empty before passing to ent_create().
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/12/12 18:10

Thanks for your answer. I use this code:
Code:
private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog LoadModel = new OpenFileDialog();
            LoadModel.Title = "Import Model";
            LoadModel.InitialDirectory = @"C:\";
            LoadModel.Filter = "MDL (*.mdl)|*.mdl|Alle Dateien (*.*)|*.*";
            LoadModel.FilterIndex = 1;
            LoadModel.RestoreDirectory = true;
            if(LoadModel.ShowDialog() == DialogResult.OK)
            {
                ENTITY.ent_create(LoadModel.FileName, new Vector(100, 100, 0), obj);
                _items.Add(LoadModel.FileName);
                listBox1.DataSource = null;
                listBox1.DataSource = _items;
            }
        }



It is called by a button in my Form. I think that OpenFileDialog returns a string but I don't know how to control the string.
The code does work sometimes, but bigger models cause it to crash and this is not because I am out of memory.


Posted By: pararealist

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

Yes i had the same problem too.
To give you an idea what i did.

Code:
private void button_LoadLevel_Click(object sender, EventArgs e)
        {
            //you can still put opendialog here
            //i use a global "levelloaded" string in a static
            //class called Global accessed through properties.
            ...
            Global.strLoadedLevel = opendialog.filename;

            Scheduler.AddEventVoidThreadSafe(LoadLevel);
        }
     
private IEnumerable<ScheduleMethod> LoadLevel()
        {
            //i use a Global.strLoadedLevel as string
            if(Global.strLoadedLevel != string.empty}
             {
                EngFun.level_load(Global.strLoadedLevel);

		//reinit camera
                InitCamera();
             }
            yield break;
        }



Calling some engine functions from a Form event will cause thread problems.
Hope this makes sense.
Posted By: Timothy

Re: C# wrapper - RELEASE - 06/13/12 10:51

I defined the Global class like this:
Code:
public static class Global
        {
            public static string entity_import;
        }


I used the string like you said and it seems to work now.
Thank you very much!
Posted By: pararealist

Re: C# wrapper - RELEASE - 06/13/12 16:47

Good.

probably better to use properties in global
Code:
public static class Global
        {
            private static string entity_import;

            public static string Import
            {
               get {return entity_import;}
            }
        }


Posted By: MasterQ32

Re: C# wrapper - RELEASE - 07/20/12 17:36

could you please do something like this:
Code:
public Vector xyz
{
	get
	{
		return Vector.createFromPointer(xPointer);
	}
	set
	{
		Vector.createFromPointer(xPointer).vec_set(value);
	}
}


this would enable us to write better and easier code, because assigning a vector would look like this:
Code:
skyStars.xyz = camera.xyz;


and not like this:
Code:
skyStars.xyz.vec_set(camera.xyz);



EDIT:
And please do not wrap all functions!
I know it was hard work, but wrapping clamp instead of rewriting it is really bad. This solution is much safer and faster:
Code:
public static double clamp(double x, double a, double b)
{
	if (x < a) return a;
	if (x > b) return b;
	return x;
}



also you should use ref/out instead of DoubleSet and those strange variable-setting delegates

another thing to mention is that using read-only properties for stuff like getting entity or bmap properties:
Code:
public int Width
{
	get
	{
		return bmap_width();
	}
}


Posted By: Stromausfall

Re: C# wrapper - RELEASE - 07/22/12 12:50

please use the new thread (C# wrapper 2.0 - RELEASE) in the future for discussions about the wrapper !

@MasterQ32
The idea with assigning vectors isn't a good idea. If vectors were immutable, then assigning them this way would be plausible. But as they are now they are mutable thus the syntax you would propse would mean that the vector object would be REPLACED by the new vector object and that is simply not the case - you only want it to assume the same value - not the same reference to the unmanaged memory.

about wrapping all functions - this is after all a wrapper - which has the advantage that it basically should only wrap methods - not implementing them. Thus through wrapping the functions you have the exact same behaviour as without the wrapper !
You can always build your own 'optimized' vector utility class !

ref/out aren't the same as the delegates !
There are only a handful of situations where they are needed - for example with a slider (panel element) ! The value of the variable you want to be modified isn't modified while the function you call the arguments with is executed ! The values are modified at not yet known points in time (when the user moves the slider) thus ref/out doesn't work - because you can't keep (variable references !) with a ref/out after the method has returned !
© 2024 lite-C Forums