Jump to content
Xtreme .Net Talk

Napivo1972

Avatar/Signature
  • Posts

    85
  • Joined

  • Last visited

Napivo1972's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Like this value always contains the value you are looking for. Select Case value Case 1, 2, 3 If value = 1 Then End If If value = 2 Then End If If value = 3 Then End If ' value could be 1, 2 or 3 Exit Select Case 4, 5, 6 Select Case value Case 4 ' value is 4 Case 5 ' value is 5 Case 6 ' value is 6 End Select ' value could be 4, 5 or 6 Exit Select Case Else Exit Select End Select
  2. You have the value from your case evaluation that should tell you all you need to know. I am not a VB programmer, so you'll have to do with a C# example switch (value) { case 1: case 2: case 3: // value could be 1, 2 or 3 break; case 4: case 5: case 6: // value could be 4, 5 or 6 break; default: // value can be anything else break; } Here it in in VB Select Case value Case 1, 2, 3 ' value could be 1, 2 or 3 Exit Select Case 4, 5, 6 ' value could be 4, 5 or 6 Exit Select Case Else ' value can be anything else Exit Select End Select
  3. I screwed up majorly when writing my program.... never envisioned I would need threading while updating... But having like 2000 objects needing Updating, collision detection and AI, no computer can handle this on a single thread. In essence my program implements a GameObject that is iUpdatable, iDrawable and contains an iSprite. iUpdateble only contains one function Update(); iDrawable only contains one function iSpriteInfo[] GetSprites() //I just do this as I have other classes derived from iDrawable Like CompositeSprite and Spriteanimation and then we have iSpriteInfo public interface iSpriteInfo { float X { get; set; } float Y { get; set; } float Angle { get; set; } Vector2 Origin { get; set; } float Scale { get; set; } float Depth { get; set; } Color Color { get; set; } Boolean Visible { get; set; } Rectangle SourceRectangle { get; set; } Rectangle DestinationRectangle { get; set; } Rectangle BoundingRectangle { get; } Matrix Matrix { get; } SpriteSheet SpriteSheet { get; set; } int SpriteSheetNum { get;} Color[] TextureData { get; set; } Vector2 GetVector2 { get; } Vector3 GetVector3 { get; } } As you can imagine I don't have time for lock conditions while updating and as these objects are accessed by 3 threads (in fact there are hundred or so for hitttesting alone) I have decided to implement BaseReadWriteLock as most data is only changed during updating. I say most as there is one expensive calculation I don't do during updating. that is Calculating the bounding box and Matrix, Those are calculated on a as needed basis. And then I run into a major problem. Most of the time it is clear when I need a read lock or when I need a write lock but when I need to go and update my bounding rectangle (which is only done the first time I need it when certain parameters have changed) every thing goes wrong. The RecalcBounding rectangle gets called by every thread blocking my entire application and taking like forever to unblock. Am I just too stupid? Anyone have a book recommendation about in-dept threading? I am really stuck as this is only the beginning I need at least 10 000 objects to update, hit test and AI every 60th of a second Any help appreciated Napivo
  4. That could work searching looking around the Internet a bit more I found this. At least you thought me something. Thank you. http://www.codeproject.com/KB/threads/CrossThreadEvents.aspx I tried converting it to c# but for some reason this throws a compiler error. private void InvokeAction<T>(EventHandler<T> anAction, T arg, bool ThrowMainFormMissingError = true) So in the end I came up with this far less generic function but it seems to do the job... private void InvokeAction(EventHandler<EventArgs> anAction, EventArgs arg, bool ThrowMainFormMissingError = true) { if ((!ThrowMainFormMissingError) && (Application.OpenForms.Count == 0)) { return; } try { Form f = Application.OpenForms[0]; if (f.InvokeRequired) f.Invoke(anAction, this, arg); else anAction(this, arg); } finally { } } What I really meant was, the XnaForm and game class are actually the same class but My Video Player Class is unaware of either. It just loads the frames and prepares a Texture2D (Comparable to a bitmap) actulaly the Class Name is VideoTexture2D. I was trying to keep it that way so I didn't have to pass around a lot of references and that it would work even if there is no Game class... for instance, if I just want to grab frames and save them to file.
  5. That's sound really nice but how can I invoke the event on the main thread in a fully isolated class? I have no reference to my main form (which is an XNA Game window) and would like to keep it that way, if at all possible.
  6. I suck at threading but now I really need it... I have an VideoTexture class that uses an internal thread to monitor the events of the video. when the video is done it raises an event complete. Now the event is captured in my XNA game class and it loads another video (Actually switches to another one that was loaded in the background) Since the videoTexture is pretty heavy on resources I need to dispose of it. I can't call a thread abort since that would kill my thread I use to make the switch. How do I solve this?
  7. I will give you a hand but will not write the code for you... Let's take an easy example. 255 we all know that translates into 1111 1111 and FF but why? 255 / 2 = 127 rest 1 127/ 2 = 63 rest 1 63 / 2 = 31 rest 1 31 / 2 = 15 rest 1 15 / 2 = 7 rest 1 7 / 2 = 3 rest 1 3 / 2 = 1 rest 1 1 / 2 = 0 rest 1 Easy? This works for every other system you can up with 255 / 16 = 15 rest 15 = F 15 / 16 = 0 rest 15 = F 255 / 8 = 31 rest 7 31 / 8 = 3 rest 7 7 / 8 = 3 rest 3 Just remember to add the results from back to front. It makes sense as you do that for decimal numbers too so the octal of 255 is 377 not 773 Now the inverse should be easy too 377 octal 7 * 1 = 7 7 * 8 = 56 3 * 8 * 8= 192 7 + 56 + 192 = 255 note that the sequence of numbers I multiply with is 8 ^ 0 = 1 8 ^ 1 = 8 8 ^ 2 = 8 * 8 = 64 that counts for binary too 2 ^ 0 = 1 2 ^ 1 = 2 2 ^ 2 = 4 2 ^ 3 = 8 2 ^ 4 = 16 and for hexadecimal 16 ^ 0 = 1 16 ^ 1 = 16 16 ^ 2 = 255 We start here with the last char and not the first.
  8. Of course, you are right... as usual :D Can't remember why I started doing something stupid like this in the first place. I only recently started programming again, after a break of a year or so... Must still be rusty
  9. Could you explain me a bit more what you are looking for? If it's just drawing a grid on your form I guess GDI would be fast enough. private void Form1_Paint(object sender, PaintEventArgs e) { const int Gridsize = 15; Pen p = new Pen(Color.Black); for (int t1 = 0; t1 < ClientSize.Height; t1 += Gridsize) { e.Graphics.DrawLine(p, 0, t1, ClientSize.Width, t1); } for (int t1 = 0; t1 < ClientSize.Width; t1 += Gridsize) { e.Graphics.DrawLine(p, t1,0, t1, ClientSize.Height); } p.Dispose(); }
  10. Maybe try this Probably being the Laziest programmer in the known universe... When I need to do something like this in VS10 I design a from in the designer I change the inherited item from form to panel I modify InitializeComponent() in the designer code, to start as a panel instead of a form Now just add the new panels to your form and make them visible and invisible as you like. This works quite well, Quick and dirty :)
  11. Can I add objects to a listbox so that they display their name but are still linked to te induvidual objects?
  12. Here is what I want to do: I have an MDI form and it has a tool dialog docked to the right side. I want to keep it on top of all other MDI child Forms and if possible remove the portion it takes from the MDI client frame. Can anyone help me by explaining how I should do this? Thanks in advance Napivo got this: So what can you do ? Here's how to set up an MDI application so that MDI childs operate normally, but some child windows always stay on top. (there is a simple trick � ) How do we�ll do it ? 1. The always-on-top child is not an MDI child ! � Don�t set its MdiPatent property 2. We will achieve the child�s behavior for this form by calling the win32 api SetParent( child.hwnd, parent.hwnd) Follow these instructions to set up a simple demonstration: 1. Open visual studio 2. Create a windows application 3. Rename Form1 to MainForm and change the IsMdiContainer property to true. 4. Add two new Windows Forms to the project and name them frmMdiChild and frmAlwaysOnTop 5. Add the flowing lines to the MainForm load event: frmMdiChild child1=new frmMdiChild(); child1.MdiParent=this; child1.Show(); frmMdiChild child2=new frmMdiChild(); child2.MdiParent=this; child2.Show(); frmAlwaysOnTop topform=new frmAlwaysOnTop(); topform.Show(); SetParent((int)topform.Handle,(int)this.Handle); <<< Here is the Magic :-) 6. Add declaration of the SetParent win32api to the MainForm class: [DllImport("user32")] public static extern int SetParent(int hWndChild, int hWndNewParent) ; The only problem is: 6. Add declaration of the SetParent win32api to the MainForm class: [DllImport("user32")] public static extern int SetParent(int hWndChild, int hWndNewParent) ; How can I do this in Microsoft Visual Studio 2008 Express?
  13. The issue is that when my data gets edited the combo box does not reflect the changes. I solved this by adding items to the combo box myself. So now it�s unbound and I can choose when to update. It works like a charm. About the data view. I put all database access in a single class. So I only load a table once in my application. Tables can be used in different forms. I rather dislike one form changing the sort order of another form or even worse changing the row filter and not showing all records. This happens if you use the default view.
  14. Hi, It�s been a while since I posted here� I have been away from programming for a while. I have a problem with a data bound combo box. I included the forms load event where I do all the bindings. I have a form with a combo box cmbTVARates and 2 textboxes txtValue and txtName I use the combo box to select a record but I don�t edit in it. The data is send to the 2 textboxes where I edit the data and then save it. This works like a charm but while the data is saved to the datatable and even saved to the database, the combo box is not updated with the new names and added rows. I have tried breaking and restoring data bindings, call refresh, update or even invalidate but nothing seems to work. Anyone have an idea? Private Sub frmTVA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dv = New DataView(Startup.DB.t_TVA.DataTable) dv.Sort = "ID" Dim b As Binding cmbTVARates.DataSource = dv cmbTVARates.DisplayMember = "Name" cmbTVARates.ValueMember = "Value" b = txtValue.DataBindings.Add("Text", dv, "Value") AddHandler b.Format, AddressOf SingleToPercent AddHandler b.Parse, AddressOf PercentToSingle txtName.DataBindings.Add("Text", dv, "Name") ' Specify the CurrencyManager for the DataView. cm = CType(Me.BindingContext(dv), CurrencyManager) AddHandler cm.CurrentChanged, AddressOf CM_CurrentChanged AddHandler cm.ItemChanged, AddressOf CM_ItemChanged AddHandler cm.MetaDataChanged, AddressOf CM_MetaDataChanged AddHandler cm.PositionChanged, AddressOf CM_PositionChanged End Sub
  15. This engine is designed for c# and they have plenty of examples for c# c++ and c.net
×
×
  • Create New...