Awesomium XNA FPS Drop - c#

We are trying to develop a game using XNA. We decided to use Awesomium for GUI, because it is easy to use and its extremely powerful. However we found a weird problem:
After hover over any form elements (like input, buttons, input etc) we noticed a massive FPS drop to like 2 fps. On the other hand when we hover over text elements (p, div, a etc) nothings happen and everything is working as it is suppose to (we have over 400 FPS). We found out that problem is with isDirty function (Awesomium::WebView), because is always true (when mouse is over form element). I don't know if it can be a reason, but onMouseOut function is never called.
Does anybody have similar problem? What can we do about that?
Greeting, Valker

I've used Awesomium in a Unity 3D project and didn't have any problem like that.
You should check the onmouseover event handler.
If you've done your homework you should be able to load the assets from the webpage.
So load the page directly in chrome and use console.log('on-mouse-over') to have a JS feedback when the event is called. If you are flooded with those console messages than the event handler is invoked way to often and you should first debug your JS in the browser. Only then load it up in your AWE client.
I'll share some more of my experience with Awesomium with you.
My recommendation is to keep the JS code as thin as possible and unload as much code as possible to C#. Here's the reason why.
You'll probably want to implement C# routines to check if the mouse is actually on an opaque spot (inside a WebView) or on a (semi-)transparent zone that should not prevent click-throughs to underlying objects. When you use CSS like box-shadow you'll soon notice that the shadow adds pixels around and inside the WebView boundary.
Those bordering pixels should be click-through. You may also have non-rectangular shapes or dynamic slide-down UI elements and similar. So you'll have to work your way around the fixed WebView boundaries by checking manually if you're on a transparent spot or not.
You also want C# code to handle drag&drop across multiple WebView instances because each has its own global context and there is no way to handle cross-WebView drag&drop in JS alone.
So you already have all this C# code implemented.
Just do another step and charge all UI processing off the WebView.
You should use JS just to send/receive messages from the C# code and complex JS scripts should be avoided.
The same functionality in C# is much easier to debug. And what emerges naturally is the MVC pattern, with controllers implemented in C#.
Very thin JS is less error prone.
And last but not least, if you are a paying customer you should take advantage of their customer-only support and forums.
Wish you luck especially with the drag&drop nightmare! :)

Related

How to make non-modal MessageBox pop-ups for Unity project

Gday,
I am currently doing a small Unity project where the game takes place on the desktop, we have a creature that communicates with the player. It is currently severely limited with how it acts/reacts due to the only way that I can figure out how to make popups in the windows system style is through the use of the MessageBox function which is Modal (it suspends the application from running until the MessageBox has been answered or closed).
So I was wondering if there was any way to get the same effect without it suspending the entire application, I've tried looking into Forms however I can't get it to recognise it as a thing in VisualStudios. I have also looked at GUI.Window however doesn't create a window that looks like a Windows style popup.
What do yall reckon?
(Thankyou in advance)
In general, trying to mix Unity and WinForms is a really bad idea. They were built around completely different design philosophies and if you keep going down this path, they're going to keep fighting each other.
The best option here would be to create your own lookalike windows in-game. That would require quite a bit of work and infrastructure to set up at the beginning, but it would also give you full control over the style and behaviour of the dialogs.
Browse the asset store for assets that solve the problem for you. There are a number of dialog type assets you can grab and plug into your unity project to get you running quickly. A lot of them mimic windows features like moving around, scrolling or X to close.

Breaking up an all C# WPF application into XAML for one of its UI controls and C#

This is a broad question, I am aware. However, I have been trying to make a modification in a C# source code to enable a ToolboxControl UI control's right hand border to respond to a mouse drag. In other words make the control size bigger by grabbing the right hand boarder and dragging it to the right. I Have not been successful. So I am thinking if I incorporate a XAML file and create the ToolboxControl in XAML, maybe I would have more control in manipulating the ToolBoxControl.
I dont know how to break up a pure C# WPF code into C# and XAML.
In a nutshell, The problem I am dealing currently is that there is already C# code developed by other developers to perform certain function. I am using the existing C# code but I believe if I move some of the UI functionality from the C# into a XAML file, I would have a better handle on adding some of the needed UI features to the original program.
So you see my problem is I am not starting from scratch. I need to use an existing C# code and break away some UI functionality of it nd put it in a new xaml file. Do you have any ideas about any place that that has been done?
I am looking for any repsonse that leads me to a conversation thread or a sample. In other words I dont know where to start from. any useful guidance is apprecaited and would be marked as an answer.
Check out this article.
At its simplest, you will need to add an invisible (or not) drag handle to the right hand border of your control, then adjust the control size during the drag events raised by that drag handle.
Here is another article showing a similar concept expanded to an entire diagramming system, which includes the resize behavior you mentioned.
You may be able to define a style for what you are trying to accomplish. I wouldn't worry too much about breaking apart the C# from the XAML as that is a nice to have but not nec

Best way to pass metadata between XNA & WPF for a level editor

I have a pre-existing game in XNA that I've unfortunately lost the level editor code for. Before it used to run as a separate .exe, but I've done the work to modify the game so that it can be paused to run a level editor in the game itself. I'd like to use WPF to actually do the level editing as it seems well-suited to the task, but I don't know the best way to pass information between the two systems.
My XNA game spawns a WPF Window and I've registered events with the XNA game such that when I click a Button on the WPF Window, the XNA game receives the ClickEvent and responds appropriately. This worked wonderfully for placing objects that require no initialization data other than position (things like statues), which I simply interpret in XNA directly. However, now I have objects that have more information that the user defines in the WPF editor (e.g. starting enemy health) and I'm not sure of the best way to route the information across to XNA. I'm especially trying to keep in mind that eventually, I'll want to make it so that I can click an object in the game to edit it "in-line" (or at least make it appear that way to the person using the level editor). So essentially, I'll need to be able to set the WPF control values based on information stored in XNA when the user clicks on an object in XNA.
Here's what I've thought of so far, but none of these were as straight forward as I'd like them to be and so I'm not sure that I'm going down the right path.
Override RoutedEventArgs to include the extra metadata that I need such that when the event is raised from WPF and picked up by XNA, all of the extra information is there already.
This seems to be an ok approach, but doesn't really help me at all when I want to go the other way around.
Also, I could be misunderstanding how this works, but it seems like I needed to add a bunch of generic EventHandler code to my XNA game that was not required for the "statue" case.
Override the Button class to attach the extra metadata I need and then access it via sender or RoutedEventArgs.OriginalSender
This seems like one of the easier approaches, but feels a bit forced. The information doesn't really belong as part of the Button.
I'm not sure how this will work for passing the information back from XNA to WPF.
Get the information via sender.Parent or RoutedEventArgs.OriginalSender.Parent, which will require casting it to the appropriate WPF UI element.
This seems relatively easy, but is kind of ugly. It basically means putting a bunch of regular C# style properties that get their value set when things like ComboBoxes have a change/selection event.
This seems easier to go the other way with than making a custom Button, but I haven't spend serious time looking at it yet.
Any help / direction would be appreciated. I'm also happy to post any relevant code snippets, but the game is quite large and the WPF implementation so far is extremely basic, so I'm not sure what would be helpful.

WPF element hosted in ElementHost not redrawing correctly

I'm writing a program to implement COM component in C#. This component provides a UI component too. In the interest of making it easy to implement future additions to the component, I decided to write the UI in Xaml using WPF and wrapping it in an ElementHost control to provide the handle back to to the COM consumer.
Here's where this gets interesting. The element is being hosted in a win32 tab control. The first time the tab is selected, it loads fine. Switching to another tab and coming back causes it to not draw the component correctly. If I move the mouse through it, it'll draw the TextBox elements, but it'll never redraw the whole UserComponent.
I've tried every possible solution I've seen suggested, from changing the height/width values of the component to putting the HwndTarget in SoftwareOnly rendering mode.
I'm not sure what to try at this point, so suggestions are welcome. I'd really like to do this without using Windows Forms as the future maintainers of this aren't the best programmers and it's a lot easier to tell them to write up a Xaml file with data bindings than manually lay out a form and set the values in the code-behind.
Haven't met such problem yet.
Try to force refresh or focus (methods) to the hosting wrapper or HwndSource when switching to the hosting tab.

Is there a way to ask about the status of a drag operation while it is in progress?

I know that when a drag/drop operation is completed, upon receiving a MouseUp or Esc key event, it returns an enum that indicates what happened (Move, Copy, None, etc.) My question is this: is there a way to send back status information to the form/control that initiated the drag event, while it is going on?
The use case is as follows (think Visual Studio-esque layout manager for all of this): I am writing a layout/window managing component that allows regions of the layout to be dragged around. I use a transparent form to paint a semi-transparent overlay that changes based on where the mouse is dragging over, a la the preview overlay that appears when dragging windows around in Visual Studio.
Another motivation is that the serialization process I describe is relatively resource intensive, and I'd prefer not to do it if the dragging is all going to occur within the same process/window. So, if there was a way to lazily serialize only when an actual "drop" in another window happens, that would probably make all the difference in usability.
What I want to do is enable dragging between different windows or even different instances of the application. I've already plumbed out the serialization code and everything, but the issue is that, when I drag a chunk of layout into another window, the first window doesn't have any way of knowing that the mouse is now over another instance of the application, which is more than capable of painting its own overlay. So, the original overlay hangs around like an idiot and my program looks like crap.
Is there any way for me to pass along some kind of callback or is there any message or property I can listen for/poll during a drag operation that will tell me if my mouse pointer is over a region that can accept its data? Please don't make me resort to listening for the CursorChanged event, I've already lost too much self respect using reflection to hack around weird wpf/winforms dragging interop bugs. If anyone could suggest a clean resolution for this problem I would be extremely grateful.
Additionally, if anyone could point me to any favorite sites which describe how to go about doing reeeeally funky things with drag and drop, it would be appreciated, as I've found there is quite a lack of really nitty gritty information available about dragging. Usual things like custom cursors and the like are okay, but I'm probably more interested in Win32 black arts and the like.
UPDATE:
I actually just found out about the GiveFeedback event a second ago, came back to my question, and there it was. Huge facepalm moment. However, since I've got you here, what about my second question: is there any way to lazily load the information only when it encounters a valid target? Could I somehow implement my own IDataObject or do things get marshaled righ when the mouse leaves the form? GiveFeedback provides me only with whether there's a valid target under the cursor, but doesn't let me change what data is being dragged...
ANOTHER UPDATE:
Is there any way to determine the source of a drag operation? That is, when my control receives a DragEnter message, how can I tell if the source of the drag is my own control or a foreign one? I know I can hackishly encode it by messing with the AllowedEffects property, but is there any more direct route?
Check out the GiveFeedback event (there's a nice article here) - that sounds to me to be exactly what you're after.

Categories

Resources