• Advertisement
Sign in to follow this  
  • entries
    177
  • comments
    531
  • views
    163919

Help, I'm melting

Sign in to follow this  

160 views

There needs to be some sort of law where if the outside temperature is too high we get to stay home. I say we make it between -40 and 40(Celsius), that seems fair. I'm tired of literally melting at work.

Anyway I've implement sprites into GB.Net, although currently it only supports 8x8 sprites and not 8x16. I've also changed the map and tile code so it doesn't do everything tile-tile, pixel-pixel. Now I just have the data read the data into a large byte[] array and use Stream.Write(). This gives me an FPS of 110 in debug and 240 in release.

There's a problem with reading in the object data though. Well it works, but it's a horrible unsafe and ugly hack.

See I have a struct:

[InteropServices.StructLayout(InteropServices.LayoutKind.Sequential)]
private struct ObjectData
{
internal int X;
internal int Y;
internal int Tile;
internal int Priority;
internal int Flip;
internal int Palette;
}


and an array of said struct:
private static ObjectData[] DataArray = new ObjectData[40];

The problem occurs with passing the array to the DLL.
extern "C" DLLEXPORT void GetObjectData( ObjectData *DataArray )

When I tried to pass the array as is like:
GetObjectData( ref DataArray );

It would either do nothing at all or crash. I guess it was trying to pass the Array object itself. Anyway right now I'm just pass the first element:
GetObjectData( ref DataArray[0] );

This works, but it just doesn't seem right to assume .Net arrays operate the same way as C arrays.

So anyone know a better way to do this?

Screenshot time:

The ships on the left are the sprites.
Sign in to follow this  


4 Comments


Recommended Comments

Guest Anonymous Poster

Posted

I'm not sure how you defined your PInvoke method (The static method in C# with the DllImportAttribute attribute corresponding with your unmanaged procedure "GetObjectData") but you may have to prepend the "ref" keyword or MarshalAsAttribute attribute to your "DataArray" parameter.

Share this comment


Link to comment
Oh yeah I forgot it is actually using ref. However when passing the whole Array object with or without ref, it crashes.

This is the current one, where I just pass the first element:

[InteropServices.DllImport("SharpBoy.dll", EntryPoint = "GetObjectData")]
private static extern void GetData( ref ObjectData DataArray );

Share this comment


Link to comment
Guest Anonymous Poster

Posted

Another place to look:

http://msdn2.microsoft.com/en-us/library/hk9wyw21.aspx

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement