[C#] AckNET

Posted By: MasterQ32

[C#] AckNET - 07/27/14 23:38

Hey guys!

Just started a new project today:
AckNET

AckNET is my try to create another C# wrapper for Gamestudio.

I don't want to create a 1:1 wrapper but a logical wrapper that allows you programming in the normal C# style.

You can get the current version of the wrapper at GitHub:
https://github.com/MasterQ32/AckNET/

Please note that the wrapper is in a very early stage (Just started this afternoon) but has already most of the types (Entity, Material, View, Event and Bitmap) wrapped.

Functions are currently missing as well as some global variables.

The wrapper will be developed on feature request or if I am missing features myself.

As the wrapper is a base for another project, it will get most of the common functions in early time but the lesser common functions will stay untouched.

"var" is wrapped with a custom struct named ackvar. It has an implicit operator casting it to and from double, but casting it to bool or int works with explicit casts (this allows better usage in conditionals)

Here is a small example using C# vNext:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AckNET.EngineVars;

namespace AckNET.Test
{
	class Program
	{
		static void Main(string[] args)
		{
			Acknex.Open("-nx 200");
			Console.WriteLine("Using version {0}", EngineVars.Version);

			OnTab = (x) => { Console.WriteLine("Pressed [TAB]"); return 0; };
			MouseMode = 3;

			Level.Load("");

			var ent = new Entity("cargo.mdl", new Vector(550.0, 0.0, 0.0));

			var snd = new Sound("beep.wav");

			OnSpace = (x) => { snd.Play(100, 0); return 0; };

			while (Acknex.Frame())
			{
				if (ent == EngineVars.MouseEnt)
				{
					ent.Pan += 1.5 * TimeStep;
				}

				Camera.Pan += (KeyCul - KeyCur) * TimeStep;

				Console.WriteLine("{0} - {1} -> {2}", KeyCul, KeyCur, (KeyCul - KeyCur));

				if ((bool)MouseLeft)
				{
					Console.WriteLine("{0}:{1}:{2}", (int)SysHours, (int)SysMinutes, (int)SysSeconds);
				}

				if ((bool)KeyEsc)
				{
					break;
				}
			}

			Acknex.Close();
		}
	}
}



Regards
Felix
Posted By: Michael_Schwarz

Re: [C#] AckNET - 07/28/14 06:16

KeyCul, KeyCur, => KeyCuL, KeyCuR, to emphasize the direction
Posted By: MasterQ32

Re: [C#] AckNET - 07/28/14 09:49

Sounds good. Will do this after every global variable is built in. Autogenerated code doesn't like changes wink
Posted By: Redeemer

Re: [C#] AckNET - 07/28/14 21:00

Looks like a pretty cool project! If I were still using gamestudio I might be inclined to play around with it, but unfortunately that's not the case.
Posted By: MasterQ32

Re: [C#] AckNET - 07/29/14 21:59

Made commit #11 right now. A important feature was added right now:
Code:
if (ReferenceEquals(ent, EngineVars.MouseEnt))
{
	ent.Pan += 1.5 * TimeStep;
}


All engine objects have now C# reference equality. This is useful for any referencing and won't cause problems with external libraries.
Posted By: MasterQ32

Re: [C#] AckNET - 07/30/14 12:57

Added first c_trace version and a simple fluent interface to vector.

Code:
private void EngineVars_OnMouseLeft(object sender, EngineEventArgs e)
{
	if (Collision.Trace(
		EngineVars.MousePos.SetZ(0).ForScreen(EngineVars.Camera),
		EngineVars.MousePos.SetZ(1000).ForScreen(EngineVars.Camera),
		CollisionFlags.UsePolygon | CollisionFlags.IgnoreSprites | CollisionFlags.IgnorePassable | CollisionFlags.IgnorePassents,
		out ackvar distance))
	{
		clicks.Add(EngineVars.Hit.Position);
	}
}


Posted By: FBL

Re: [C#] AckNET - 07/30/14 18:21

sys_... vars demand an own class tongue
Posted By: MasterQ32

Re: [C#] AckNET - 07/30/14 19:33

Most of the sys_ variables are also available in "better" via C# class libraries wink
Like Environment, DateTime and Screen...
Posted By: MasterQ32

Re: [C#] AckNET - 07/31/14 22:28

After a little bit of work, AckNET now documents its wrapper functionality itself:


Nice feature i think, i'll add a wrapper completeness calculator as well...
Posted By: pararealist

Re: [C#] AckNET - 08/01/14 07:58

A few minor mistakes?
ent_setskin -> Entity.GetSkin = mistake. should be Entity.SetSkin
ent_type -> Entity.get_Type why get_Type and not getType ? conformity.
Posted By: AceX

Re: [C#] AckNET - 08/01/14 08:15

Nice job,Felix wink
Keep up the good work.
Posted By: MasterQ32

Re: [C#] AckNET - 08/01/14 09:36

Originally Posted By: pararealist
A few minor mistakes?
ent_setskin -> Entity.GetSkin = mistake. should be Entity.SetSkin
ent_type -> Entity.get_Type why get_Type and not getType ? conformity.

Typo fixed. Why get_Type? Because conformity tongue
get_Type is the internal method created by C# if you use properties.

Code:
EntityType type = ent.Type;



So you don't call a function but use get_type as a read only variable.
Posted By: MasterQ32

Re: [C#] AckNET - 08/08/14 15:59

Added some new features!

AckNET has now a Scheduler similar behaving to the Gamestudio scheduler:

Code:
private static IEnumerable<Wait> MainMethod()
{
	OnTab += (s, e) => { Console.WriteLine("Pressed [TAB]"); };
	MouseMode = 3;

	Level.Load("");
	yield return Wait.ForFrames(1);
	EngineVars.SkyColor = Color.DeepSkyBlue;

	var ent = new Entity("cargo.mdl", new Vector(550.0, 0.0, 0.0));

	var snd = new Sound("beep.wav");

	OnSpace += (s, e) => { snd.Play(100, 0); };

	WindowsFormsHost host = new WindowsFormsHost(1024, 768);
	var tb = new TextBox()
	{
		Left = 120,
		Top = 120,
		Width = 80,
		Text = "Change me!"
	};
	host.Controls.Add(tb);

	var btn = new Button()
	{
		Left = 120,
		Top = 80,
		Width = 80,
		Height = 25,
		Text = "Click me!",
	};
	btn.Click += (s, e) => { MessageBox.Show(tb.Text); };

	host.Controls.Add(btn);

	while (!(bool)KeyEsc)
	{
		if (ReferenceEquals(ent, EngineVars.MouseEnt))
		{
			ent.Pan += 1.5 * TimeStep;
		}

		Camera.Pan += (KeyCul - KeyCur) * TimeStep;

		Graphics.DrawQuad(
			host.Target,
			new Vector(0, 0, 0),
			null,
			null,
			null,
			null,
			100,
			0);

		yield return Wait.ForFrames(1);
	}
}




Also i have added a WindowsFormsHosting tool that allows to host all Windows Forms controls in Gamestudio:
Posted By: Reconnoiter

Re: [C#] AckNET - 08/08/14 17:36

I see what you did there Leonidas wink.

Anyway keep it up, I imagine this can be very usefull in some situations.
Posted By: MasterQ32

Re: [C#] AckNET - 08/08/14 18:31

Yeah going to continue my current game project next week. Made the changes to make a login screen possible without much effort wink
Posted By: Rackscha

Re: [C#] AckNET - 08/10/14 01:18

@MasterQ32 you might consider using a different name? Acknet was(is?) a quite popular Networkingreplacement for Gamestudio. Just to avoid nameclashes when talking about wink
Posted By: pararealist

Re: [C#] AckNET - 08/10/14 02:07

I suppose NET(in uppers) does make one think more NET than Network though?
Posted By: MasterQ32

Re: [C#] AckNET - 08/10/14 10:29

yeah project name is going to change in either AckSharp or Ack.NET depending on what i like more grin

And yes, NET in upper cases shoud suppose .NET
Posted By: sivan

Re: [C#] AckNET - 08/10/14 13:36

or A# or Bb or Ack# laugh
Posted By: FBL

Re: [C#] AckNET - 08/10/14 16:31

AckNot.
Posted By: Tempelbauer

Re: [C#] AckNET - 08/10/14 22:34

Quote:
Acknet was(is?) a quite popular Networkingreplacement for Gamestudio.

this is Anet

But a change is no bad idea at all. Vote for Ack#
Posted By: pararealist

Re: [C#] AckNET - 09/14/14 18:57

Ack# is cool, or maybe spelt out?
AckSharp.
Posted By: MasterQ32

Re: [C#] AckNET - 10/12/14 12:40

There are news! I improved the wrapper again as well as it is now called AckSharp.
Yep, the name is much better now, also i changed some stuff:
- More vector functions
- c_updatehull is now existent
- Engine Object classes are now autogenerated

Last part may be the biggest as some classes (Material, ...) were totally broken with manual ported classes.
© 2024 lite-C Forums