Unit Actions

This is a discussion on Unit Actions within the Game Programming forums, part of the General Programming Boards category; no, you misunderstand! The first search just finds what parts of the world the mouse lies in (it can lie ...

  1. #16
    Banned
    Join Date
    May 2004
    Posts
    129
    no, you misunderstand! The first search just finds what parts of the world the mouse lies in (it can lie in an arbitrary number, but practically in 2D the most is 4). Then, for every single part of the world the mouse is in, search the pertinent entities to see if the mouse bounding box overlaps the entity bounding box. You must search every one because typically your mouse can overlap more than one unit (if it is enclosed in a box), in that case you want the closest.

  2. #17
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    Wouldnt something like this work too:
    If you always keep track of what units are visible why not store pointers to those units in a list and only search through that list? That would probably reduce the amount of units to search through quite much unless you have like 100-200 units visible at the same time.
    Last edited by Shakti; 05-28-2004 at 05:55 AM.

  3. #18
    Banned
    Join Date
    May 2004
    Posts
    129
    Keep in mind that is exactly what we have been saying the whole time...the only way you can find those visible objects is by recursively searching the quadtree

  4. #19
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    There is no need to find where the mouse is. The mouse is the origin of the system. We test everything against the mouse. It is much easier to test like this instead of first finding the mouse in the tree and then finding the units as well.
    We test all bounding boxes of the objects against the bounding box of the mouse. Besides if you search the entire list on the first recursion and then logarithmically reduce the number of units to search....the time involved is still nothing compared to the O(n^2) linear search.

  5. #20
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    typically a section of the world would contain a list of pointers to the entities that are within that particular section. Whenever an object is moved, it undergoes a process called "relinking", where you calculate what parts of the world each object's bounding box lies in, and removing itself from the previous parts of the world it no longer resides in. You do not have to recurse the entire world when you do this.
    Hm so you would have a world object with several different regions and when you move a unit you (possibly) place it into a different region? Or something along that line...Could someone post a basic class design to show how it would be set up?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #21
    Banned
    Join Date
    May 2004
    Posts
    129
    Download quake2 source
    www.idsoftware.com
    open project, search (in all files) 'relink' or 'linkedict'

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating C/C++ Unit Test Cases
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2009, 08:29 PM
  2. structural fault any ideas
    By kaijuu in forum C Programming
    Replies: 17
    Last Post: 04-17-2007, 02:43 PM
  3. newbie here.. pls help me in this program!
    By rothj0hn in forum C Programming
    Replies: 2
    Last Post: 02-01-2006, 09:40 PM
  4. 2-d object avoidance. Help please! (basic stuff, I think)
    By charbach007 in forum Game Programming
    Replies: 4
    Last Post: 06-15-2004, 03:49 PM
  5. Unit Theory - input requested
    By Jeremy G in forum Game Programming
    Replies: 9
    Last Post: 11-18-2003, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21