]> git.itanic.dy.fi Git - sdl-planets/log
sdl-planets
12 years agoMakefile: honour CC variable given by user master
Timo Kokkonen [Sat, 30 Jul 2011 19:32:21 +0000 (22:32 +0300)]
Makefile: honour CC variable given by user

If user wants to override the default compiler (for example with
clang), the CC variable inherited from the environment should be left
as is.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomain.c: Print tree rebalance events
Timo Kokkonen [Sat, 30 Jul 2011 13:37:54 +0000 (16:37 +0300)]
main.c: Print tree rebalance events

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: export rebalance statistics
Timo Kokkonen [Sat, 30 Jul 2011 13:30:54 +0000 (16:30 +0300)]
quadtree: export rebalance statistics

These variables can be used to examine how many times tree rebalance
events have taken place and how many nodes were moved during the
rebalances.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: quadtree_move(): Avoid excess rebalancing
Timo Kokkonen [Wed, 20 Jul 2011 13:02:01 +0000 (16:02 +0300)]
quadtree: quadtree_move(): Avoid excess rebalancing

The most obvious bug here was that the "modify" variable was
uninitialized, thus the search for crossed parents resulted always
true for the very first parent. Therefore, every time a node was
moved, the tree was rebalanced below the node.

Fixing the uninitialzed variable bug revealed other problems in the
crossed subnodes search, which was broken too. This patch modifies the
crossed subnode search a slight. It will now return true if it finds
any subnode that the movement would cross, stopping the search
instantly as soon as such node is found.

If either crossed parent or subnode is found, the node is removed and
added back to the tree in order to ensure it will be put in the
correct place.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Remove unused variable
Timo Kokkonen [Wed, 20 Jul 2011 12:54:46 +0000 (15:54 +0300)]
quadtree: Remove unused variable

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agomerge_planets: Remove planet from linked lists before merging
Timo Kokkonen [Wed, 20 Jul 2011 12:47:55 +0000 (15:47 +0300)]
merge_planets: Remove planet from linked lists before merging

The planet needs to be remove from all linked lists before they are
being merged together. If merging takes place while both nodes are in
the same quad tree, the tree logic might collapse due to two nodes
sharing the same identical coordinates.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Optimize distance calculation
Timo Kokkonen [Tue, 19 Jul 2011 18:40:33 +0000 (21:40 +0300)]
quadtree: Optimize distance calculation

All of the distance values needed here are only used for comparing
between different distances. The actual distance itself is not used at
all. Thus, the distance calculation can be optimized by leaving out
all of the square root calculations and the end result is still the
same.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agovector.h: Introduce vector_abs_squared()
Timo Kokkonen [Tue, 19 Jul 2011 17:16:36 +0000 (20:16 +0300)]
vector.h: Introduce vector_abs_squared()

This function is identical to vector_abs but it returns the squared
distance instead. The advantage of this function is that the one
square root calculation canb e omitted. If the actual distance is not
important, this function is faster than the one which returns the
absolute distance.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Optimize recalculate_parent_area_stats()
Timo Kokkonen [Tue, 19 Jul 2011 17:10:14 +0000 (20:10 +0300)]
quadtree: Optimize recalculate_parent_area_stats()

There is no need to go through the entire tree in case one leaf node
has a minimal change in it. As long as we have gone high enough in the
tree that there is no more any changes to the corner vectors, we can
stop walking the tree up. According to perf measurements, this
optimization reduces the tree area recalculation overhead about 50%.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtre: Fix nearest neighborhood search
Timo Kokkonen [Tue, 19 Jul 2011 16:32:37 +0000 (19:32 +0300)]
quadtre: Fix nearest neighborhood search

The search was missing a check whether the current node is the
nearest. Obviously without this check we never found anything else
except the initial node as the nearest node.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoAdd perf data files into .gitignore
Timo Kokkonen [Wed, 13 Jul 2011 17:03:12 +0000 (20:03 +0300)]
Add perf data files into .gitignore

This reduces the risk that the perf data files accidentally clutter
the git tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Reduce excess stats calculation
Timo Kokkonen [Wed, 13 Jul 2011 16:59:05 +0000 (19:59 +0300)]
quadtree: Reduce excess stats calculation

There is no need to explicitly recalculate the tree stats when a node
is moved from one place from the into another. As the node is added to
the tree, the stats are being recalculated automatically.

When the node is merely moved within the tree and the tree topology
doesn't change, it is sufficient to only recalculate the tree area
statistics. When some other usage is implemented for the tree
statistics, the need for more accurate statistics might change.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Unlink parent when rebalancing a subtree
Timo Kokkonen [Wed, 13 Jul 2011 16:53:08 +0000 (19:53 +0300)]
quadtree: Unlink parent when rebalancing a subtree

There is no need to keep the one way link to the parent while the
subtree is being rebalanced. Removing this link optimizes the
rebalancing process by stopping the stats recalculation from
propagating into the parent tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Remove redundant validity test
Timo Kokkonen [Wed, 13 Jul 2011 16:43:10 +0000 (19:43 +0300)]
quadtree: Remove redundant validity test

The sole purpose of this test wast to see whether the subtree was
removed correctly. If such condition exists, the failure will be
caught in the quadtree_del function. This test should be removed since
it causes unnecessary runtime overhead also on the non-debug build.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Trivial cleanup
Timo Kokkonen [Wed, 13 Jul 2011 16:18:00 +0000 (19:18 +0300)]
quadtree: Trivial cleanup

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Add better nearest neighborhood search
Timo Kokkonen [Wed, 13 Jul 2011 16:04:52 +0000 (19:04 +0300)]
quadtree: Add better nearest neighborhood search

This one attempts to leave majority of the tree unchecked while
searching for the nearest neighborhood, but ensures still that the
nearest node is always found.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Macros with complex values should be enclosed in parenthesis
Timo Kokkonen [Tue, 12 Jul 2011 16:42:35 +0000 (19:42 +0300)]
quadtree: Macros with complex values should be enclosed in parenthesis

This makes macro usage more reliable

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Factor out tree area stats calculation
Timo Kokkonen [Tue, 12 Jul 2011 16:38:18 +0000 (19:38 +0300)]
quadtree: Factor out tree area stats calculation

This makes it possible to only update the tree area statistics, in
case nothing else has updated from the tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Use tree corners from the tree itself
Timo Kokkonen [Sat, 9 Jul 2011 09:07:34 +0000 (12:07 +0300)]
quadtree: Use tree corners from the tree itself

Now that we have the tree corner points stored in the each three node
itself, we can use those corner points when rebalancing the tree. This
allows also removing great deal of clumsy and hard to understand code.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoQuadtree: Recalculate tree statistics after a node has been moved
Timo Kokkonen [Sat, 9 Jul 2011 07:24:28 +0000 (10:24 +0300)]
Quadtree: Recalculate tree statistics after a node has been moved

This is needed in order to ensure tree corner statistics are always up
to date.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Add subtree area into tree statistics
Timo Kokkonen [Fri, 8 Jul 2011 09:51:36 +0000 (12:51 +0300)]
quadtree: Add subtree area into tree statistics

Two corner coordinates are stored into each quadtree nodes. These
corner coordinates indicate the area where all the subnodes of the
tree are located in.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Move quadtree_recalculate_parent_stats() out from the header
Timo Kokkonen [Fri, 8 Jul 2011 10:03:21 +0000 (13:03 +0300)]
quadtree: Move quadtree_recalculate_parent_stats() out from the header

This function is not called anywhere outside of the quadtree.c, so
there is no really point in keeping it in the header. Furthermore,
this is one quite big function to keep inlined. Make it an ordinary
static function instead and let the compiler decide whether it should
be inlined or not.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
12 years agoquadtree: Document subtree indexing
Timo Kokkonen [Fri, 8 Jul 2011 08:49:32 +0000 (11:49 +0300)]
quadtree: Document subtree indexing

As stupid as it might sound, I forgot how the subtrees are indexed in
spatially. Therefore it might make sense to simply document even the
trivial things in the header file to avoid future confusion.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMakefile: Better output beautifier
Timo Kokkonen [Mon, 7 Feb 2011 18:33:09 +0000 (20:33 +0200)]
Makefile: Better output beautifier

This is better code and makes prettier output

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMakefile: More advanced dependency tracking
Timo Kokkonen [Thu, 3 Feb 2011 20:10:15 +0000 (22:10 +0200)]
Makefile: More advanced dependency tracking

Inspired by: http://mad-scientist.net/make/autodep.html#norule

Ensure that dependency tracking does not get confused even if some
dependencies (header files for example) are renamed or deleted.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoplanet.c: merge_planet: Keep quadtree spatially sorted
Timo Kokkonen [Fri, 24 Dec 2010 21:11:08 +0000 (23:11 +0200)]
planet.c: merge_planet: Keep quadtree spatially sorted

If we move planet in the quadtree, we must call quadtree_move() in
order to keep the tree sorted. As the tree ordering might change, the
merge planet must also return the possibly new parent node of the
tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoplanet.c: Use the quadtree_move function from quadtree lib
Timo Kokkonen [Fri, 24 Dec 2010 21:03:46 +0000 (23:03 +0200)]
planet.c: Use the quadtree_move function from quadtree lib

This will remove the duplicate functionality from the planet.c

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree: Add quadtree_move() function
Timo Kokkonen [Fri, 24 Dec 2010 20:27:35 +0000 (22:27 +0200)]
quadtree: Add quadtree_move() function

This function will do necessary steps to keep the tree in correct
spatial order when a node is moved.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree: Fix compiler warnings
Timo Kokkonen [Fri, 24 Dec 2010 20:23:23 +0000 (22:23 +0200)]
quadtree: Fix compiler warnings

quadtree.c:370: warning: unused variable ‘ret’

Trivial remove

quadtree.c: In function ‘quadtree_find_nearest’:
quadtree.c:369: warning: ‘distance’ may be used uninitialized in this function

This variable will not be used uninitialized, but the compiler warning
is trivial to fix with simply initializing the variable with zero.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree: Implement proper rebalancing
Timo Kokkonen [Tue, 7 Dec 2010 20:13:46 +0000 (22:13 +0200)]
quadtree: Implement proper rebalancing

Select nodes in predetermined spatial order that will produce well
balanced tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree: validator: Catch missing leaf node
Timo Kokkonen [Tue, 7 Dec 2010 20:07:55 +0000 (22:07 +0200)]
quadtree: validator: Catch missing leaf node

This patch will make the validator to catch error when a leaf node has
a pointer to a parent which does not have pointer back to the leaf
node.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree: tree validator: Add spatial validation
Timo Kokkonen [Tue, 7 Dec 2010 20:06:17 +0000 (22:06 +0200)]
quadtree: tree validator: Add spatial validation

This will catch errors when the tree is not in spatial order.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree.c: Print line number when trap is caught
Timo Kokkonen [Tue, 7 Dec 2010 19:57:00 +0000 (21:57 +0200)]
quadtree.c: Print line number when trap is caught

This helps debugging

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoquadtree.c: Compare vectors, not quadtrees
Timo Kokkonen [Tue, 7 Dec 2010 18:20:57 +0000 (20:20 +0200)]
quadtree.c: Compare vectors, not quadtrees

Factor out the vector comparison into a separate function. That way it
is more useful if plain vector comparison is needed.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMakefile: Reduce wildcard usage
Timo Kokkonen [Mon, 6 Dec 2010 09:09:36 +0000 (11:09 +0200)]
Makefile: Reduce wildcard usage

Having wildcards in the Makefile is error prone in situations where
there are unrelated files in the source tree that are not related to
the actual project. For example, if some source files have been
renamed and there are leftover .*.o.d files that still contain the old
source files. Then make will incorrectly determine that some old files
would still be needed even though they are not part of the project any
more.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMerge branch 'master' of git://itanic.dy.fi/sdl-planets
Timo Kokkonen [Sun, 31 Oct 2010 09:03:36 +0000 (11:03 +0200)]
Merge branch 'master' of git://itanic.dy.fi/sdl-planets

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMove quadtree comparison code inside quadtree.c
Timo Kokkonen [Sat, 30 Oct 2010 18:56:59 +0000 (21:56 +0300)]
Move quadtree comparison code inside quadtree.c

The .compare function can also be removed now from the quadtree_ops
structure.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agoMove position vector from planet to quadtree
Timo Kokkonen [Sat, 30 Oct 2010 16:57:19 +0000 (19:57 +0300)]
Move position vector from planet to quadtree

Moving the position information inside the quadtree structure will
make it eventually much easier to do varios tree operations within the
quadtree code. Most of the quadtree callback functions can be moved
inside the quadtree code. This patch implements just the first part of
the change, moving the coordinates inside quadtree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agomain.c: Use getopt_long() for reading cmd line arguments
Timo Kokkonen [Sun, 13 Jun 2010 16:07:14 +0000 (19:07 +0300)]
main.c: Use getopt_long() for reading cmd line arguments

This makes it easier to read various different command line arguments.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agomain.c: Skip simulation when time step is zero
Timo Kokkonen [Sun, 13 Jun 2010 13:04:57 +0000 (16:04 +0300)]
main.c: Skip simulation when time step is zero

When user has set the simulation speed to zero, there is no need to
run the simulation at all, as it won't be changing anyway. This makes
it possible to run excessively large simulations and occassionally
freeze the simulation. Then, for example, inspecting the tree topology
(if draw_lines variable is enabled) becomes easier without need to
worry about slow camera movement.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
13 years agomerge_planets: Calculate new color for the remaining planet
Esko Kokkonen [Sat, 1 May 2010 14:23:23 +0000 (17:23 +0300)]
merge_planets: Calculate new color for the remaining planet

14 years agoquadtree: Try to keep the tree in better balance.
Timo Kokkonen [Sat, 24 Apr 2010 11:00:49 +0000 (14:00 +0300)]
quadtree: Try to keep the tree in better balance.

When a tree node is removed, we now attempt to add the detached
subtree in more optimized order to the new tree. This is done so that
we walk down the detached tree and add a new node to the main tree
always when the tree is one quarter'th smaller than the previous node
that was added.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree_add: Zero child pointers when a new node is added
Timo Kokkonen [Sat, 24 Apr 2010 10:59:14 +0000 (13:59 +0300)]
quadtree_add: Zero child pointers when a new node is added

Since we don't support adding an entire subtree, it is better to zero
out the child pointers to ensure there are no leftover child nodes
that might corrupt the tree integrity.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree.c: Improve debuggin capabilities
Timo Kokkonen [Sat, 24 Apr 2010 10:48:12 +0000 (13:48 +0300)]
quadtree.c: Improve debuggin capabilities

-Flush out prints immedeatly. This will ensure prints get out even
 though execution is halted to a breakpoint.

-Add some extra debug messages

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agopoll_events: Add support for stopping the simulation
Timo Kokkonen [Sun, 18 Apr 2010 10:26:31 +0000 (13:26 +0300)]
poll_events: Add support for stopping the simulation

This makes it possible to for example inspect the tree structure in a
stopped simulation.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomove_planet: Optimize the tree topology change detection
Timo Kokkonen [Sun, 18 Apr 2010 10:24:56 +0000 (13:24 +0300)]
move_planet: Optimize the tree topology change detection

This change avoids repositioning unnecessary the nodes within the
tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoplanet.c: Add support for drawing the planet tree structure
Timo Kokkonen [Sun, 18 Apr 2010 08:49:25 +0000 (11:49 +0300)]
planet.c: Add support for drawing the planet tree structure

A line will be drawn from a planet parent to the child node. Local
variable is used to enable line drawing at compile time.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agodraw_planet: Separate circle drawing into its own function
Timo Kokkonen [Tue, 13 Apr 2010 17:18:11 +0000 (20:18 +0300)]
draw_planet: Separate circle drawing into its own function

It is easier to draw circles elsewhere in the code if the circle
drawing is separated.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: quadtree_del: Fix tree integrity bug
Timo Kokkonen [Mon, 12 Apr 2010 17:31:57 +0000 (20:31 +0300)]
quadtree: quadtree_del: Fix tree integrity bug

When a root node is deleted and new tree is built under the new root,
the new root node needs to have its parent set to null.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoplanet: Add tree statistics
Timo Kokkonen [Sun, 11 Apr 2010 16:16:18 +0000 (19:16 +0300)]
planet: Add tree statistics

The total mass and area of the subtree tree is calculated.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Allow updating other than just quadtree stats
Timo Kokkonen [Sun, 11 Apr 2010 16:14:57 +0000 (19:14 +0300)]
quadtree: Allow updating other than just quadtree stats

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoIntroduce struct quadree_ops
Timo Kokkonen [Sun, 11 Apr 2010 15:05:13 +0000 (18:05 +0300)]
Introduce struct quadree_ops

Store all related function pointers (so far only the comparison) in
one structure. This will make it easier to add function pointers that
are needed in various quadtree operations.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Fix minor coding convention issue
Timo Kokkonen [Sun, 11 Apr 2010 09:18:59 +0000 (12:18 +0300)]
quadtree: Fix minor coding convention issue

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoplanet.c: Optimize moving of planets within thetree
Timo Kokkonen [Sun, 11 Apr 2010 09:13:55 +0000 (12:13 +0300)]
planet.c: Optimize moving of planets within thetree

If there is no changes in the tree topology when a planet is moved,
there is no need to do any tree operations. This will decrease tree
maintenance overhead especially with large trees.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomove_planet: Remove debug code
Timo Kokkonen [Sat, 10 Apr 2010 19:41:23 +0000 (22:41 +0300)]
move_planet: Remove debug code

This was not supposed to be there after debugging was finished.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain.c: Print tree statistics
Timo Kokkonen [Sat, 10 Apr 2010 14:42:19 +0000 (17:42 +0300)]
main.c: Print tree statistics

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Collect tree statistics
Timo Kokkonen [Sat, 10 Apr 2010 14:39:07 +0000 (17:39 +0300)]
quadtree: Collect tree statistics

Tree depth and child count is collected and kept up to date.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain.c: Do not allow creating zero planets
Timo Kokkonen [Sat, 10 Apr 2010 11:49:31 +0000 (14:49 +0300)]
main.c: Do not allow creating zero planets

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefile: Enable DEBUG definition in debug build
Timo Kokkonen [Thu, 8 Apr 2010 19:36:06 +0000 (22:36 +0300)]
Makefile: Enable DEBUG definition in debug build

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Fix style issues
Timo Kokkonen [Thu, 8 Apr 2010 16:50:24 +0000 (19:50 +0300)]
quadtree: Fix style issues

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain.c: Use quadtrees to draw only visible planets
Timo Kokkonen [Thu, 8 Apr 2010 16:46:44 +0000 (19:46 +0300)]
main.c: Use quadtrees to draw only visible planets

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoplanets: Add support for spatial search from quadtree
Timo Kokkonen [Thu, 8 Apr 2010 16:45:12 +0000 (19:45 +0300)]
planets: Add support for spatial search from quadtree

This can be used to for example draw only visible planets on the
screen.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoplanets: Add quadtrees in use
Timo Kokkonen [Thu, 8 Apr 2010 16:43:01 +0000 (19:43 +0300)]
planets: Add quadtrees in use

The tree is used and kept sorted, but it is not used for anything
useful yet.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMerge branch 'master' into quadtree
Timo Kokkonen [Thu, 8 Apr 2010 16:34:41 +0000 (19:34 +0300)]
Merge branch 'master' into quadtree

14 years agoquadtree: Pass quadtree iterator structure to the callback functions quadtree-dev
Timo Kokkonen [Thu, 8 Apr 2010 16:23:24 +0000 (19:23 +0300)]
quadtree: Pass quadtree iterator structure to the callback functions

This is better than plain void pointer, since now the iterator can be
embedded as part of some other struct. This simplifies the design.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years ago.gitignore: Add debug-planet
Timo Kokkonen [Mon, 5 Apr 2010 16:43:42 +0000 (19:43 +0300)]
.gitignore: Add debug-planet

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefile: Add debug-planet to the clean target
Timo Kokkonen [Mon, 5 Apr 2010 16:43:24 +0000 (19:43 +0300)]
Makefile: Add debug-planet to the clean target

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefile: rename debug target to obey naming convention
Timo Kokkonen [Mon, 5 Apr 2010 16:41:40 +0000 (19:41 +0300)]
Makefile: rename debug target to obey naming convention

The main target is called sdl-planet, so the debug target should be
called then as debug-planet.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMerge branch 'master' of git://itanic.dy.fi/sdl-planets
Timo Kokkonen [Mon, 5 Apr 2010 16:36:45 +0000 (19:36 +0300)]
Merge branch 'master' of git://itanic.dy.fi/sdl-planets

14 years agomain loop: Fade correctly when simulation runs fast
Timo Kokkonen [Mon, 5 Apr 2010 16:33:53 +0000 (19:33 +0300)]
main loop: Fade correctly when simulation runs fast

There was a bug that buffer fade amount was relative to the time it
took to run one simulation step, not relatively to the time interval
between two drawn frame. This patch fixes the issue.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Obey naming conventions
Timo Kokkonen [Mon, 5 Apr 2010 13:14:57 +0000 (16:14 +0300)]
quadtree: Obey naming conventions

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Suppress compiler warnings
Timo Kokkonen [Mon, 5 Apr 2010 13:14:40 +0000 (16:14 +0300)]
quadtree: Suppress compiler warnings

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Only use the validator when debugging is enabled
Timo Kokkonen [Mon, 5 Apr 2010 13:00:48 +0000 (16:00 +0300)]
quadtree: Only use the validator when debugging is enabled

14 years agoMerge branch 'master' into quadtree-dev
Timo Kokkonen [Mon, 5 Apr 2010 13:04:13 +0000 (16:04 +0300)]
Merge branch 'master' into quadtree-dev

14 years agoMakefile: Enable DEBUG definition when debugging
Timo Kokkonen [Mon, 5 Apr 2010 13:02:38 +0000 (16:02 +0300)]
Makefile: Enable DEBUG definition when debugging

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agocreate_planets: Initialize also the first planet
Timo Kokkonen [Mon, 5 Apr 2010 12:38:32 +0000 (15:38 +0300)]
create_planets: Initialize also the first planet

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Be more careful when deleting a node from the tree
Timo Kokkonen [Mon, 5 Apr 2010 12:43:43 +0000 (15:43 +0300)]
quadtree: Be more careful when deleting a node from the tree

Before attempting to move nodes back to the main tree, detach the
subtree completely from the main tree. When detaching individual nodes
from the tree, also ensure that each node has its old children
removed.

If these measures are not taken into account, loops will form in the
tree.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Use the validator
Timo Kokkonen [Mon, 5 Apr 2010 12:43:14 +0000 (15:43 +0300)]
quadtree: Use the validator

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Add a tree validator
Timo Kokkonen [Mon, 5 Apr 2010 12:41:39 +0000 (15:41 +0300)]
quadtree: Add a tree validator

This will find some typical erros in the tree and print error messages
when such erros are found.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Implement node removing
Timo Kokkonen [Mon, 5 Apr 2010 09:19:26 +0000 (12:19 +0300)]
quadtree: Implement node removing

Removing a node from a quadtree is a tricky process. The node might
have multiple children which all need to be repositioned in the
remainig tree, which propably requires a recursive recreation of the
entire (sub)tree. If the given node happens to be the root node of the
tree, a new root needs to be selected for the remaining tree.

This kind of tree manipulation might have significant impact on the
balance of the tree. On the contrary, as massive tree reorganization
might be required, this is a good opportunity to rebalance the
(sub)tree. The introduced implementation does not address any
balancing issues at all.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Implement quadtree_find_parent
Timo Kokkonen [Mon, 5 Apr 2010 08:42:15 +0000 (11:42 +0300)]
quadtree: Implement quadtree_find_parent

This helper function simply returns the highest parent of a given
node.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoquadtree: Add missing function definition to the header
Timo Kokkonen [Sun, 4 Apr 2010 08:51:47 +0000 (11:51 +0300)]
quadtree: Add missing function definition to the header

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain.c: Fix a typo in a comment
Timo Kokkonen [Sun, 4 Apr 2010 08:44:10 +0000 (11:44 +0300)]
main.c: Fix a typo in a comment

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agocreate_planets: Modify the for-loop to start from 0.
Arto Heikkinen [Sun, 4 Apr 2010 07:44:15 +0000 (10:44 +0300)]
create_planets: Modify the for-loop to start from 0.

14 years agomain.c: Coding convention fixes
Timo Kokkonen [Sun, 4 Apr 2010 08:33:59 +0000 (11:33 +0300)]
main.c: Coding convention fixes

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agofade_buf: Allow fading with very small increments
Timo Kokkonen [Sun, 4 Apr 2010 07:37:42 +0000 (10:37 +0300)]
fade_buf: Allow fading with very small increments

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agopoll_events: Add predefined time scales
Esko Kokkonen [Sat, 3 Apr 2010 15:49:06 +0000 (18:49 +0300)]
poll_events: Add predefined time scales

14 years agomain.c: Fix typo
Timo Kokkonen [Sat, 3 Apr 2010 11:17:39 +0000 (14:17 +0300)]
main.c: Fix typo

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefie: Add debug target
Timo Kokkonen [Sat, 3 Apr 2010 11:12:24 +0000 (14:12 +0300)]
Makefie: Add debug target

This makes debugging with gdb easier, when there is no need to modify
the makefile in order to disable optimizations while debugging.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefile: rename object variables
Timo Kokkonen [Sat, 3 Apr 2010 10:46:44 +0000 (13:46 +0300)]
Makefile: rename object variables

This used to be a test project..

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agofade_buf: Optimizations
Timo Kokkonen [Sat, 3 Apr 2010 10:02:44 +0000 (13:02 +0300)]
fade_buf: Optimizations

Since most of the buffer is usually black, we can skip the fading
entirely on those words that are already null. Only when the buffer
contains something to fade, individual color values are being
substracted.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain loop: Add support for tracers
Timo Kokkonen [Fri, 2 Apr 2010 13:19:21 +0000 (16:19 +0300)]
main loop: Add support for tracers

Tracers are a fading trail of the planet's movement.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMain loop: Suppress a compiler warning
Timo Kokkonen [Fri, 2 Apr 2010 12:56:44 +0000 (15:56 +0300)]
Main loop: Suppress a compiler warning

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMain loop: Collect simulation status variables into a structure
Timo Kokkonen [Fri, 2 Apr 2010 12:54:27 +0000 (15:54 +0300)]
Main loop: Collect simulation status variables into a structure

This eases passing of the variables between function since there is no
need to pass that many individual variables.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agosetup_planet: Concentrate the mass mostly in the middle of the system
Timo Kokkonen [Fri, 2 Apr 2010 09:59:03 +0000 (12:59 +0300)]
setup_planet: Concentrate the mass mostly in the middle of the system

This will increase the stability of the created planetar system. Most
of the central planets collapse into one large object, which will keep
most of the system more stable.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agoMakefile: Add missing lib
Timo Kokkonen [Fri, 2 Apr 2010 09:03:37 +0000 (12:03 +0300)]
Makefile: Add missing lib

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain loop: Modify debug prints
Timo Kokkonen [Wed, 31 Mar 2010 19:44:23 +0000 (22:44 +0300)]
main loop: Modify debug prints

 - Change the ordering of the fields

 - Add the counter of the simulation steps

 - Flush the stdout buffer out after each print.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain loop: Separate simulation time from true time
Timo Kokkonen [Wed, 31 Mar 2010 16:54:29 +0000 (19:54 +0300)]
main loop: Separate simulation time from true time

This allows simulation and other actions, such as camera movements, to
use different time steps. Now camera will move the same speed
regardless of the simulation time (eg. very low fps scenarios).

Furthermore, the maximum time step value is always respected and won't
be exceeded even though user adjusts the simulation speed to higher.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agomain loop: Limit to max 60FPS
Timo Kokkonen [Wed, 31 Mar 2010 16:44:43 +0000 (19:44 +0300)]
main loop: Limit to max 60FPS

Do not even try to draw more than 60FPS. If we have time left, do some
extra simulation steps.

As an extra bonus this patch fixes the timer usage which was broken
since we moved to higher clock resolution.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
14 years agogettime fixes
Timo Kokkonen [Wed, 31 Mar 2010 16:42:41 +0000 (19:42 +0300)]
gettime fixes

Return microseconds instead of nanoseconds. Also return value is now
delta from the first call to gettime instead of the absolute value of
the monotonic clock.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>