Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 20 of 23 1 2 18 19 20 21 22 23
Re: C# wrapper 2.3.3 - RELEASE [Re: Quad] #395143
02/20/12 09:58
02/20/12 09:58
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Okay, another question.
How do i get the "final_bits" of a BMAP? or how do i access the NativeBMAP struct from a BMAP?


3333333333
Re: C# wrapper 2.3.3 - RELEASE [Re: Quad] #395149
02/20/12 10:53
02/20/12 10:53
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline OP
User

Joined: Dec 2002
Posts: 616
Austria
getting information from the NativeBMAP is quite easy :
- get the pointer from the BMAP object
- use Marshal.PtrToStructure to get the content

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

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

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

IntPtr final_bits = nativeBmapStruct.finalbits;



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

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

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



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

Last edited by Stromausfall; 02/20/12 10:55.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper 2.3.3 - RELEASE [Re: Stromausfall] #395306
02/22/12 09:16
02/22/12 09:16
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
It's probably that i'm doing something wrong but,

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

does not seem to be changing final bits


3333333333
Re: C# wrapper 2.3.3 - RELEASE [Re: Quad] #395324
02/22/12 13:26
02/22/12 13:26
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline OP
User

Joined: Dec 2002
Posts: 616
Austria
it appears to work with the example I posted below!

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

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


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

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

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

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

            return
                nativeBmapStruct.finalbits;
        }

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

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

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


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

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

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

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

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

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

            yield return ScheduleMethod.wait(1);
        }

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

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



Last edited by Stromausfall; 02/22/12 13:28.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper 2.3.3 - RELEASE [Re: Stromausfall] #395336
02/22/12 15:28
02/22/12 15:28
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
I've used finalbits in c++ plugin sdk and it was working fine this way

bmap_lock..
change parts of finalbits
bmap_unlock

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

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


3333333333
Re: C# wrapper 2.3.3 - RELEASE [Re: Quad] #395392
02/23/12 07:48
02/23/12 07:48
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline OP
User

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

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

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

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

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

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

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

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

            yield return 1;

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

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

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

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

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

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

            yield return ScheduleMethod.wait(1);
        }

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

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



Last edited by Stromausfall; 02/23/12 07:54.

get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper 2.3.3 - RELEASE [Re: Stromausfall] #395442
02/23/12 15:52
02/23/12 15:52
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
That is, if you don't lock/unlock bmap.

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

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

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

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

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




3333333333
Re: C# wrapper 2.3.3 - RELEASE [Re: Quad] #395475
02/23/12 19:55
02/23/12 19:55
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline OP
User

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

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



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

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



sorry for the hassle ! it was a stupid mistake on my part -.-


get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper 2.3.5 - RELEASE [Re: Stromausfall] #395476
02/23/12 20:07
02/23/12 20:07
Joined: Dec 2002
Posts: 616
Austria
Stromausfall Offline OP
User
Stromausfall  Offline OP
User

Joined: Dec 2002
Posts: 616
Austria
a new version was uploaded (for Acknex 7.85.4 AND Acknex 8.30.4)
the update of the wrapper includes:

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

here's the link:

AcknexWrapper_2_3_5_FOR_8_30_4_AND_7_85_4.zip


get the C# wrapper:
for A7.85.4 and A8.30.4, Version 2.3.9
at http://acknexwrapper2.matthias-auer.net/ or visit the thread
Re: C# wrapper 2.3.5 - RELEASE [Re: Stromausfall] #395506
02/24/12 08:02
02/24/12 08:02
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Big thanks to you too!


3333333333
Page 20 of 23 1 2 18 19 20 21 22 23

Moderated by  TWO 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1