• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Jiraya
      For a 2D game, does using a float2 for position increases performance in any way?
      I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?
       
    • By BigJiggly
      Hello! So, I've been the leader of BJP for a while now. I'm a bit bored of taking the role I always take, leader. I was hoping someone out there is looking to forge a team maybe and needs a programmer. 
      I have experience mainly in the Unity engine(C# intermediate) and I have a very small amount of knowledge on Shaders, as well as experience on developing games(usually end up stuck in dev hell) and leading experience from my last team which at one point reached 11 people. I personally love the Unity engine and prefer to use it as it's the development environment I'm comfortable with. 
      I have used Unity for over a year and a few months, I'd consider myself an intermediate at the Engine, but to this day Unity still surprises me. 
      I live in the United Kingdom, I find it a bit strange to work with other programmers as the ones I've worked with tend to leave their code heavily unoptimised and I'm a on the go optimise kind of guy, I also like to get things done quickly.
       
      If you're a new team and need a programmer that has high levels of ambition and strives to maintain the motivation throughout the team, then I'm your guy. I don't care if you're just beginning because I'm all for helping people learn!
       
      To finish this off: I like to get things done and I like to get them done right the first time, if I fail I will do it again and again, etc, until I loose all motivation. So if you're a modeller or an artist, please don't leave me to do all the modelling/art as well as the programming and sound. I do have experience in all those areas but my main power is in programming and I'd prefer to keep it that way.
       
      [If this was posted in the wrong forum, sorry, I don't really know the layout of this website yet]
    • By Kristiyan21
      Hello guys,i am writing this topic to get to the opinion of more people.I have just released my first game for android(worked on it for about 5-6 months in my spare time) i used Unity framework and i am planning to make it a big project but i had to release 1.0 version so i am 100% sure i wouldn't quit the project at some time.What i am asking any of you guys is to give me your opinion about the game. What do you like,what you don't , is the ad too irritating?is the GUI okay?any information you might consider usefull for me would be helpful,thanks in advance!
      the game on google play:
      https://play.google.com/store/apps/details?id=com.KindieGames.PlaneDash
    • By ethancodes
      I've got a custom Brick class. I need at least one other type of Brick subclass, maybe more. These classes should do most of what the Brick class does, but have a bit of modified or added behavior. Normally I would assume inheriting from the Brick class would be the best choice for this, but when I tried to do it I was having some issues because of having to make additional instances of variables referencing manager objects. I'm not sure if I was just doing it wrong, or if maybe inheritance isn't the right solution here. Here is the Brick class:
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class Brick : MonoBehaviour { public AudioClip crack; public Sprite[] hitSprites; public static int breakableCount = 0; public GameObject smoke; private LevelManager levelManager; private int timesHit; private bool isBreakable; private float delay = 1.5f; //Delay till bricks move down 1 row. private float timer = 0; // update ever frame and compare to delay. // Use this for initialization void Start () { isBreakable = (this.tag == "Breakable"); //keep track of breakable bricks if (isBreakable){ breakableCount++; } timesHit = 0; levelManager = GameObject.FindObjectOfType<LevelManager>(); } // Update is called once per frame void Update () { timer += Time.deltaTime; if (timer >= delay) { transform.Translate(0.0f, -1.0f,0.0f); timer = 0; } } void OnCollisionEnter2D (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { levelManager = GameObject.FindObjectOfType<LevelManager>(); levelManager.LoadLevel("Lose"); } AudioSource.PlayClipAtPoint (crack,transform.position); if (isBreakable) { HandleHits (); } } void HandleHits () { timesHit++; int maxHits = hitSprites.Length + 1; if (timesHit >= maxHits) { breakableCount--; levelManager.BrickDestroyed(); PuffSmoke(); Destroy (gameObject); } else { LoadSprites(); } } void LoadSprites () { int spriteIndex = timesHit - 1; if (hitSprites [spriteIndex] != null) { //if statement keeps it from loading nothing if level designer forgets to assign a sprite this.GetComponent<SpriteRenderer> ().sprite = hitSprites [spriteIndex]; } else { Debug.LogError("Brick sprite missing"); } } void PuffSmoke () { var smokePuff = Instantiate(smoke, transform.position, Quaternion.identity); var effect = smokePuff.GetComponent<ParticleSystem>().main; effect.startColor = GetComponent<SpriteRenderer>().color; } } What I need is for a different kind of brick to destroy all other adjacent bricks when the ball hits it. I considered just adding this functionality in to the brick class, and have it activate based on tags, but that didn't seem like the best solution. I'm open to any ideas. Thanks!
    • By ucfchuck
      I am feeding in 16 bit unsigned integer data to process in a compute shader and i need to get a standard deviation.
      So I read in a series of samples and push them into float arrays
      float vals1[9], vals2[9], vals3[9], vals4[9]; int x = 0,y=0; for ( x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { vals1[3 * x + y] = (float) (asuint(Input1[threadID.xy + int2(x - 1, y - 1)].x)); vals2[3 * x + y] = (float) (asuint(Input2[threadID.xy + int2(x - 1, y - 1)].x)); vals3[3 * x + y] = (float) (asuint(Input3[threadID.xy + int2(x - 1, y - 1)].x)); vals4[3 * x + y] = (float) (asuint(Input4[threadID.xy + int2(x - 1, y - 1)].x)); } } I can send these values out directly and the data is as expected

                             
      Output1[threadID.xy] = (uint) (vals1[4] ); Output2[threadID.xy] = (uint) (vals2[4] ); Output3[threadID.xy] = (uint) (vals3[4] ); Output4[threadID.xy] = (uint) (vals4[4] ); however if i do anything to that data it is destroyed.
      If i add a
      vals1[4] = vals1[4]/2; 
      or a
      vals1[4] = vals[1]-vals[4];
      the data is gone and everything comes back 0.
       
       
      How does one go about converting a uint to a float and performing operations on it and then converting back to a rounded uint?
  • Advertisement
  • Advertisement
Sign in to follow this  

Directx 11 Wpf Message pump

Recommended Posts

Howdy

Ive got a WPF level editor  and a C++ Directx DLL.

Here are the main functions:

 public static class Engine
    {
        //DX dll
        //Init
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Initialize(IntPtr hwnd, int Width, int Height);

        //Messages / Input
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void HandleMessage(IntPtr hwnd, int msg, int wParam, int lParam);

        //Load
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Load();

        //Update
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Update();

        //Draw
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Draw();

        //Shutdown
        [DllImport("Win32Engine.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ShutDown();

    }

Okay so what is the proper way to get the window hosted inside a control and the pump the engine?

At the moment i have it inside a (winfom) panel and use:
 

 protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
            source.AddHook(WndProc);
        }

        private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            Engine.HandleMessage(hwnd, msg, (int)wParam, (int)lParam);

            Engine.Update();
            Engine.Draw();

            return IntPtr.Zero;
        }

But there's just a few problems:

  • Messages come from everywhere not just the panel (due to using the main window)
  • The input doesn't actually work
  • It's super duper ugly code wise

In terms of c++ side the normal enigne (non-editor ) uses this pump:

	while (msg.message != WM_QUIT)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);


			//Input
			if (msg.message == WM_INPUT)
			{

				//Buffer size
				UINT size = 512;
				BYTE buffer[512];
				GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, (LPVOID)buffer, &size, sizeof(RAWINPUTHEADER));

				RAWINPUT *raw = (RAWINPUT*)buffer;

				if (raw->header.dwType == RIM_TYPEKEYBOARD)
				{
					bool keyUp = raw->data.keyboard.Flags & RI_KEY_BREAK;
					USHORT keyCode = raw->data.keyboard.VKey;

					if (!keyUp)
					{
						Keyboard::SetKeyState(keyCode, true);
					}
					else
					{
						Keyboard::SetKeyState(keyCode, false);
					}
				}
			}
		}

		time->Update();
		engine->Update(time->DeltaTime());
		engine->Draw();
	}

Not the nicest loop but works for now for testing and things.

Now the Editor versions code is:
 

//Initalize enigne and all sub systems
extern "C"
{
	//Hwnd is a panel usually
	DLLExport void Initialize(int* hwnd, int Width, int Height)
	{
		engine = new Engine();
		time = new Timer();
		time->Update();

		if (engine->Initialize(Width, Height,(WINHANDLE)hwnd))
		{
			//WindowMessagePump();
		}
		else
		{
			//return a fail?
		}
	}
}

extern "C"
{
	DLLExport void HandleMessage(int* hwnd, int msg, int wParam, int lParam)
	{
			//Input
			if (msg == WM_INPUT)
			{

				//Buffer size
				UINT size = 512;
				BYTE buffer[512];
				GetRawInputData((HRAWINPUT)lParam, RID_INPUT, (LPVOID)buffer, &size, sizeof(RAWINPUTHEADER));

				RAWINPUT *raw = (RAWINPUT*)buffer;

				if (raw->header.dwType == RIM_TYPEKEYBOARD)
				{
					bool keyUp = raw->data.keyboard.Flags & RI_KEY_BREAK;
					USHORT keyCode = raw->data.keyboard.VKey;

					if (!keyUp)
					{
						Keyboard::SetKeyState(keyCode, true);
					}
					else
					{
						Keyboard::SetKeyState(keyCode, false);
					}
				}
		}
	}
}

//Load
extern "C"
{
	DLLExport void Load()
	{
		engine->Load();
	}
}

//Update
extern "C"
{
	DLLExport void Update()
	{
		time->Update();
		engine->Update(time->DeltaTime());
	}
}

//Draw
extern "C"
{
	DLLExport void Draw()
	{
		engine->Draw();
	}
}

//ShutDown Engine
extern "C"
{
	DLLExport void ShutDown()
	{
		engine->ShutDown();
		delete time;
		delete engine;
	}
}

 

Any advice of how to do this properly would be much apprcieated.

p.s in my opinion the loop should kind of stay the same? but allow the wpf to psuh the message through some how and the loop within c++ calls the update and draw still so :
 

//Gets message from C# somehow
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
  TranslateMessage(&msg);
  DispatchMessage(&msg);
  //Input
}

time->Update();
engine->Update(time->DeltaTime());
engine->Draw();
//returns back to c#

^ some how have that in c++ as the message pump called from wpf 

Thanks :D

Share this post


Link to post
Share on other sites
Advertisement

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

Sign in to follow this  

  • Advertisement