From b87064909e6d20e1ee2995adae0c1ce5cb692d7e Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 8 Feb 2010 22:20:49 +0000 Subject: [PATCH] Miscellaneous updates, mostly aesthetic --- docs/api/libgis-docs.sgml | 1 + examples/plugin/teapot.c | 4 +- src/data/gis-data.c | 2 +- src/data/gis-http.c | 4 +- src/data/gis-wms.h | 1 - src/gis-opengl.c | 9 ++-- src/gis-plugin.h | 13 +++--- src/gis-prefs.c | 22 ++++----- src/gis-util.h | 2 - src/gis-viewer.h | 2 +- src/objects/gis-callback.h | 2 +- src/objects/gis-object.h | 6 +-- src/objects/gis-tile.c | 92 +++++++++++++++++++------------------- src/objects/gis-tile.h | 16 +++---- src/plugins/env.c | 4 +- src/plugins/map.c | 4 +- src/plugins/test.c | 2 +- src/roam.c | 35 ++++++++------- src/roam.h | 50 ++++++++++++--------- 19 files changed, 139 insertions(+), 132 deletions(-) diff --git a/docs/api/libgis-docs.sgml b/docs/api/libgis-docs.sgml index fe5763e..163e4c3 100644 --- a/docs/api/libgis-docs.sgml +++ b/docs/api/libgis-docs.sgml @@ -17,6 +17,7 @@ Data Access + diff --git a/examples/plugin/teapot.c b/examples/plugin/teapot.c index a506cf1..d80ab21 100644 --- a/examples/plugin/teapot.c +++ b/examples/plugin/teapot.c @@ -35,7 +35,7 @@ static gboolean rotate(gpointer _teapot) return TRUE; } -static gpointer expose(GisCallback *callback, gpointer _teapot) +static void expose(GisCallback *callback, gpointer _teapot) { GisPluginTeapot *teapot = GIS_PLUGIN_TEAPOT(_teapot); g_debug("GisPluginTeapot: expose"); @@ -60,8 +60,6 @@ static gpointer expose(GisCallback *callback, gpointer _teapot) glColor4f(0.9, 0.9, 0.7, 1.0); glDisable(GL_CULL_FACE); gdk_gl_draw_teapot(TRUE, 0.25); - - return NULL; } diff --git a/src/data/gis-data.c b/src/data/gis-data.c index db3b16e..d3e5b9b 100644 --- a/src/data/gis-data.c +++ b/src/data/gis-data.c @@ -21,7 +21,7 @@ #include "gis-data.h" -/* +/** * Open a file, creating parent directories if needed */ FILE *fopen_p(const gchar *path, const gchar *mode) diff --git a/src/data/gis-http.c b/src/data/gis-http.c index 78251be..e64d5ba 100644 --- a/src/data/gis-http.c +++ b/src/data/gis-http.c @@ -42,7 +42,7 @@ void gis_http_free(GisHttp *http) } /* For passing data to the chunck callback */ -struct _cache_info { +struct _CacheInfo { FILE *fp; gchar *path; GisChunkCallback callback; @@ -54,7 +54,7 @@ struct _cache_info { */ static void _chunk_cb(SoupMessage *message, SoupBuffer *chunk, gpointer _info) { - struct _cache_info *info = _info; + struct _CacheInfo *info = _info; if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) { g_warning("GisHttp: _chunk_cb - soup failed with %d", diff --git a/src/data/gis-wms.h b/src/data/gis-wms.h index 90152b8..6177d59 100644 --- a/src/data/gis-wms.h +++ b/src/data/gis-wms.h @@ -33,7 +33,6 @@ typedef struct _GisWms { gint height; } GisWms; - GisWms *gis_wms_new( const gchar *uri_prefix, const gchar *uri_layer, const gchar *uri_format, const gchar *prefix, diff --git a/src/gis-opengl.c b/src/gis-opengl.c index 08babe5..ad0b5f4 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -36,11 +36,12 @@ #include "objects/gis-marker.h" #include "objects/gis-callback.h" -#define FOV_DIST 2000.0 -#define MPPX(dist) (4*dist/FOV_DIST) - // #define ROAM_DEBUG +/* Tessellation, "finding intersecting triangles" */ +/* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */ +/* http://www.opengl.org/wiki/Alpha_Blending */ + /*********** * Helpers * ***********/ @@ -198,7 +199,7 @@ static void _draw_tiles(GisOpenGL *opengl, GisTile *tile) static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) { - GisPoint *point = gis_object_center(GIS_OBJECT(marker)); + GisPoint *point = gis_object_center(marker); gdouble px, py, pz; gis_viewer_project(GIS_VIEWER(opengl), point->lat, point->lon, point->elev, diff --git a/src/gis-plugin.h b/src/gis-plugin.h index 1bc73dc..fc85f44 100644 --- a/src/gis-plugin.h +++ b/src/gis-plugin.h @@ -28,7 +28,6 @@ typedef struct _GisPlugin GisPlugin; typedef struct _GisPluginInterface GisPluginInterface; -typedef struct _GisPlugins GisPlugins; struct _GisPluginInterface { @@ -52,17 +51,19 @@ const gchar *gis_plugin_get_description(GisPlugin *plugin); GtkWidget *gis_plugin_get_config(GisPlugin *plugin); /* Plugins API */ +typedef struct _GisPlugins GisPlugins; + #include "gis-viewer.h" #include "gis-prefs.h" +typedef GisPlugin *(*GisPluginConstructor)(GisViewer *viewer, GisPrefs *prefs); + struct _GisPlugins { gchar *dir; GList *plugins; GisPrefs *prefs; }; -typedef GisPlugin *(*GisPluginConstructor)(GisViewer *viewer, GisPrefs *prefs); - GisPlugins *gis_plugins_new(const gchar *dir, GisPrefs *prefs); void gis_plugins_free(); @@ -72,13 +73,13 @@ GList *gis_plugins_available(GisPlugins *plugins); GisPlugin *gis_plugins_load(GisPlugins *plugins, const char *name, GisViewer *viewer, GisPrefs *prefs); -GisPlugin *gis_plugins_enable(GisPlugins *plugin, const char *name, +GisPlugin *gis_plugins_enable(GisPlugins *plugins, const char *name, GisViewer *viewer, GisPrefs *prefs); -GList *gis_plugins_load_enabled(GisPlugins *plugin, +GList *gis_plugins_load_enabled(GisPlugins *plugins, GisViewer *viewer, GisPrefs *prefs); -gboolean gis_plugins_disable(GisPlugins *plugin, const char *name); +gboolean gis_plugins_disable(GisPlugins *plugins, const char *name); gboolean gis_plugins_unload(GisPlugins *plugins, const char *name); diff --git a/src/gis-prefs.c b/src/gis-prefs.c index 70b5006..d3d3783 100644 --- a/src/gis-prefs.c +++ b/src/gis-prefs.c @@ -65,11 +65,11 @@ GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults) } #define make_pref_type(name, c_type, g_type) \ -c_type gis_prefs_get_##name##_v(GisPrefs *prefs, \ +c_type gis_prefs_get_##name##_v(GisPrefs *prefs, \ const gchar *group, const gchar *key, GError **_error) \ { \ GError *error = NULL; \ - c_type value = g_key_file_get_##name(prefs->key_file, group, key, &error); \ + c_type value = g_key_file_get_##name(prefs->key_file, group, key, &error); \ if (error && error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) \ g_warning("GisPrefs: get_value_##name - error getting key %s: %s\n", \ key, error->message); \ @@ -77,27 +77,27 @@ c_type gis_prefs_get_##name##_v(GisPrefs *prefs, *_error = error; \ return value; \ } \ -c_type gis_prefs_get_##name(GisPrefs *prefs, const gchar *key, GError **error) \ +c_type gis_prefs_get_##name(GisPrefs *prefs, const gchar *key, GError **error) \ { \ gchar **keys = g_strsplit(key, "/", 2); \ - c_type value = gis_prefs_get_##name##_v(prefs, keys[0], keys[1], error); \ + c_type value = gis_prefs_get_##name##_v(prefs, keys[0], keys[1], error); \ g_strfreev(keys); \ return value; \ } \ \ -void gis_prefs_set_##name##_v(GisPrefs *prefs, \ +void gis_prefs_set_##name##_v(GisPrefs *prefs, \ const gchar *group, const gchar *key, const c_type value) \ { \ - g_key_file_set_##name(prefs->key_file, group, key, value); \ + g_key_file_set_##name(prefs->key_file, group, key, value); \ gchar *all = g_strconcat(group, "/", key, NULL); \ - g_signal_emit(prefs, signals[SIG_PREF_CHANGED], 0, \ + g_signal_emit(prefs, signals[SIG_PREF_CHANGED], 0, \ all, g_type, &value); \ g_free(all); \ } \ -void gis_prefs_set_##name(GisPrefs *prefs, const gchar *key, const c_type value) \ +void gis_prefs_set_##name(GisPrefs *prefs, const gchar *key, const c_type value) \ { \ gchar **keys = g_strsplit(key, "/", 2); \ - gis_prefs_set_##name##_v(prefs, keys[0], keys[1], value); \ + gis_prefs_set_##name##_v(prefs, keys[0], keys[1], value); \ g_strfreev(keys); \ } \ @@ -138,7 +138,7 @@ static void gis_prefs_class_init(GisPrefsClass *klass) { g_debug("GisPrefs: class_init"); GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->dispose = gis_prefs_dispose; + gobject_class->dispose = gis_prefs_dispose; signals[SIG_PREF_CHANGED] = g_signal_new( "pref-changed", G_TYPE_FROM_CLASS(gobject_class), @@ -148,7 +148,7 @@ static void gis_prefs_class_init(GisPrefsClass *klass) NULL, gis_cclosure_marshal_VOID__STRING_UINT_POINTER, G_TYPE_NONE, - 1, + 3, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_POINTER); diff --git a/src/gis-util.h b/src/gis-util.h index 3bc4d66..234bb16 100644 --- a/src/gis-util.h +++ b/src/gis-util.h @@ -67,8 +67,6 @@ * xyz2lle: 0.0, 0.0, 10.0 -> 0.0, 0.0, 0.0 */ -#define azim2lon(azim) ((azim)*180/G_PI) -#define lon2azim(lon) ((lon)*G_PI/180) #define incl2lat(incl) (90-(incl)*180/G_PI) #define lat2incl(lat) ((90-(lat))*G_PI/180) #define rad2elev(rad) ((rad)-EARTH_R) diff --git a/src/gis-viewer.h b/src/gis-viewer.h index fbc9767..ba92b49 100644 --- a/src/gis-viewer.h +++ b/src/gis-viewer.h @@ -92,7 +92,7 @@ gchar *gis_viewer_get_time(GisViewer *viewer); void gis_viewer_set_location(GisViewer *viewer, gdouble lat, gdouble lon, gdouble elev); void gis_viewer_get_location(GisViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev); -void gis_viewer_pan(GisViewer *viewer, gdouble forward, gdouble sideways, gdouble up); +void gis_viewer_pan(GisViewer *viewer, gdouble forward, gdouble right, gdouble up); void gis_viewer_zoom(GisViewer *viewer, gdouble scale); void gis_viewer_set_rotation(GisViewer *viewer, gdouble x, gdouble y, gdouble z); diff --git a/src/objects/gis-callback.h b/src/objects/gis-callback.h index f3eee6d..aa95ff9 100644 --- a/src/objects/gis-callback.h +++ b/src/objects/gis-callback.h @@ -33,7 +33,7 @@ typedef struct _GisCallback GisCallback; typedef struct _GisCallbackClass GisCallbackClass; -typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data); +typedef void (*GisCallbackFunc)(GisCallback *callback, gpointer user_data); struct _GisCallback { GisObject parent; diff --git a/src/objects/gis-object.h b/src/objects/gis-object.h index b823161..313f454 100644 --- a/src/objects/gis-object.h +++ b/src/objects/gis-object.h @@ -56,9 +56,7 @@ struct _GisObjectClass { GType gis_object_get_type(void); -static inline GisPoint *gis_object_center(GisObject *object) -{ - return &GIS_OBJECT(object)->center; -} +#define gis_object_center(object) \ + (&GIS_OBJECT(object)->center) #endif diff --git a/src/objects/gis-tile.c b/src/objects/gis-tile.c index d7f8ac7..5b4b767 100644 --- a/src/objects/gis-tile.c +++ b/src/objects/gis-tile.c @@ -39,7 +39,7 @@ GisTile *gis_tile_new(GisTile *parent, gchar *gis_tile_get_path(GisTile *child) { - /* This could be easily cached if necessasairy */ + /* This could be easily cached if necessary */ int x, y; GList *parts = NULL; for (GisTile *parent = child->parent; parent; child = parent, parent = child->parent) @@ -53,7 +53,7 @@ gchar *gis_tile_get_path(GisTile *child) return g_string_free(path, FALSE); } -gdouble _gis_tile_get_min_dist(GisTile *tile, +static gdouble _gis_tile_get_min_dist(GisTile *tile, gdouble lat, gdouble lon, gdouble elev) { gdouble tlat = lat > tile->edge.n ? tile->edge.n : @@ -69,7 +69,7 @@ gdouble _gis_tile_get_min_dist(GisTile *tile, return distd(a, b); } -gboolean _gis_tile_needs_split(GisTile *tile, +static gboolean _gis_tile_needs_split(GisTile *tile, gdouble max_res, gint width, gint height, gdouble lat, gdouble lon, gdouble elev) { @@ -96,29 +96,29 @@ gboolean _gis_tile_needs_split(GisTile *tile, return view_res < tile_res; } -void gis_tile_update(GisTile *tile, +void gis_tile_update(GisTile *root, gdouble res, gint width, gint height, gdouble lat, gdouble lon, gdouble elev, GisTileLoadFunc load_func, gpointer user_data) { - tile->atime = time(NULL); - //g_debug("GisTile: update - %p->atime = %u", tile, (guint)tile->atime); - gdouble lat_dist = tile->edge.n - tile->edge.s; - gdouble lon_dist = tile->edge.e - tile->edge.w; - if (_gis_tile_needs_split(tile, res, width, height, lat, lon, elev)) { - gdouble lat_step = lat_dist / G_N_ELEMENTS(tile->children); - gdouble lon_step = lon_dist / G_N_ELEMENTS(tile->children[0]); + root->atime = time(NULL); + //g_debug("GisTile: update - %p->atime = %u", root, (guint)root->atime); + gdouble lat_dist = root->edge.n - root->edge.s; + gdouble lon_dist = root->edge.e - root->edge.w; + if (_gis_tile_needs_split(root, res, width, height, lat, lon, elev)) { + gdouble lat_step = lat_dist / G_N_ELEMENTS(root->children); + gdouble lon_step = lon_dist / G_N_ELEMENTS(root->children[0]); int x, y; - gis_tile_foreach_index(tile, x, y) { - if (!tile->children[x][y]) { - tile->children[x][y] = gis_tile_new(tile, - tile->edge.n-(lat_step*(x+0)), - tile->edge.n-(lat_step*(x+1)), - tile->edge.w+(lon_step*(y+1)), - tile->edge.w+(lon_step*(y+0))); - load_func(tile->children[x][y], user_data); + gis_tile_foreach_index(root, x, y) { + if (!root->children[x][y]) { + root->children[x][y] = gis_tile_new(root, + root->edge.n-(lat_step*(x+0)), + root->edge.n-(lat_step*(x+1)), + root->edge.w+(lon_step*(y+1)), + root->edge.w+(lon_step*(y+0))); + load_func(root->children[x][y], user_data); } - gis_tile_update(tile->children[x][y], + gis_tile_update(root->children[x][y], res, width, height, lat, lon, elev, load_func, user_data); @@ -126,16 +126,16 @@ void gis_tile_update(GisTile *tile, } } -GisTile *gis_tile_find(GisTile *tile, gdouble lat, gdouble lon) +GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon) { - gint rows = G_N_ELEMENTS(tile->children); - gint cols = G_N_ELEMENTS(tile->children[0]); + gint rows = G_N_ELEMENTS(root->children); + gint cols = G_N_ELEMENTS(root->children[0]); - gdouble lat_step = (tile->edge.n - tile->edge.s) / rows; - gdouble lon_step = (tile->edge.e - tile->edge.w) / cols; + gdouble lat_step = (root->edge.n - root->edge.s) / rows; + gdouble lon_step = (root->edge.e - root->edge.w) / cols; - gdouble lat_offset = tile->edge.n - lat;; - gdouble lon_offset = lon - tile->edge.w; + gdouble lat_offset = root->edge.n - lat;; + gdouble lon_offset = lon - root->edge.w; gint row = lat_offset / lat_step; gint col = lon_offset / lon_step; @@ -149,47 +149,47 @@ GisTile *gis_tile_find(GisTile *tile, gdouble lat, gdouble lon) if (row < 0 || row >= rows || col < 0 || col >= cols) return NULL; - else if (tile->children[row][col] && tile->children[row][col]->data) - return gis_tile_find(tile->children[row][col], lat, lon); + else if (root->children[row][col] && root->children[row][col]->data) + return gis_tile_find(root->children[row][col], lat, lon); else - return tile; + return root; } -GisTile *gis_tile_gc(GisTile *tile, time_t atime, +GisTile *gis_tile_gc(GisTile *root, time_t atime, GisTileFreeFunc free_func, gpointer user_data) { - if (!tile) + if (!root) return NULL; gboolean has_children = FALSE; int x, y; - gis_tile_foreach_index(tile, x, y) { - tile->children[x][y] = gis_tile_gc( - tile->children[x][y], atime, + gis_tile_foreach_index(root, x, y) { + root->children[x][y] = gis_tile_gc( + root->children[x][y], atime, free_func, user_data); - if (tile->children[x][y]) + if (root->children[x][y]) has_children = TRUE; } //g_debug("GisTile: gc - %p->atime=%u < atime=%u", - // tile, (guint)tile->atime, (guint)atime); - if (!has_children && tile->atime < atime && tile->data) { - free_func(tile, user_data); - g_object_unref(tile); + // root, (guint)root->atime, (guint)atime); + if (!has_children && root->atime < atime && root->data) { + free_func(root, user_data); + g_object_unref(root); return NULL; } - return tile; + return root; } /* Use GObject for this */ -void gis_tile_free(GisTile *tile, GisTileFreeFunc free_func, gpointer user_data) +void gis_tile_free(GisTile *root, GisTileFreeFunc free_func, gpointer user_data) { - if (!tile) + if (!root) return; GisTile *child; - gis_tile_foreach(tile, child) + gis_tile_foreach(root, child) gis_tile_free(child, free_func, user_data); if (free_func) - free_func(tile, user_data); - g_object_unref(tile); + free_func(root, user_data); + g_object_unref(root); } /* GObject code */ diff --git a/src/objects/gis-tile.h b/src/objects/gis-tile.h index c1e3ea7..06ce337 100644 --- a/src/objects/gis-tile.h +++ b/src/objects/gis-tile.h @@ -59,14 +59,14 @@ typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data); typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data); /* Forech functions */ -#define gis_tile_foreach(tile, child) \ - for (int _x = 0; _x < G_N_ELEMENTS(tile->children); _x++) \ - for (int _y = 0; child = tile->children[_x][_y], \ - _y < G_N_ELEMENTS(tile->children[_x]); _y++) \ - -#define gis_tile_foreach_index(tile, x, y) \ - for (x = 0; x < G_N_ELEMENTS(tile->children); x++) \ - for (y = 0; y < G_N_ELEMENTS(tile->children[x]); y++) +#define gis_tile_foreach(parent, child) \ + for (int _x = 0; _x < G_N_ELEMENTS(parent->children); _x++) \ + for (int _y = 0; child = parent->children[_x][_y], \ + _y < G_N_ELEMENTS(parent->children[_x]); _y++) + +#define gis_tile_foreach_index(parent, x, y) \ + for (x = 0; x < G_N_ELEMENTS(parent->children); x++) \ + for (y = 0; y < G_N_ELEMENTS(parent->children[x]); y++) /* Path to string table, keep in sync with tile->children */ extern gchar *gis_tile_path_table[2][2]; diff --git a/src/plugins/env.c b/src/plugins/env.c index e5787c6..fc1c7fe 100644 --- a/src/plugins/env.c +++ b/src/plugins/env.c @@ -26,7 +26,7 @@ /*********** * Helpers * ***********/ -static gpointer expose(GisCallback *callback, gpointer _env) +static void expose(GisCallback *callback, gpointer _env) { GisPluginEnv *env = GIS_PLUGIN_ENV(_env); g_debug("GisPluginEnv: expose"); @@ -67,8 +67,6 @@ static gpointer expose(GisCallback *callback, gpointer _env) glPopMatrix(); } */ - - return NULL; } diff --git a/src/plugins/map.c b/src/plugins/map.c index 7edc1ce..0dbb79f 100644 --- a/src/plugins/map.c +++ b/src/plugins/map.c @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -27,7 +28,7 @@ #define TILE_WIDTH 1024 #define TILE_HEIGHT 512 -const guchar colormap[][2][4] = { +static const guchar colormap[][2][4] = { {{0x73, 0x91, 0xad}, {0x73, 0x91, 0xad, 0x20}}, // Oceans {{0xf6, 0xee, 0xee}, {0xf6, 0xee, 0xee, 0x00}}, // Ground {{0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff}}, // Borders @@ -40,7 +41,6 @@ struct _LoadTileData { GisTile *tile; GdkPixbuf *pixbuf; }; -#include static gboolean _load_tile_cb(gpointer _data) { struct _LoadTileData *data = _data; diff --git a/src/plugins/test.c b/src/plugins/test.c index 986a4f0..4993938 100644 --- a/src/plugins/test.c +++ b/src/plugins/test.c @@ -33,7 +33,7 @@ GisPluginTest *gis_plugin_test_new(GisViewer *viewer) test->viewer = g_object_ref(viewer); GisMarker *marker = gis_marker_new("St. Charles"); - gis_point_set_lle(gis_object_center(GIS_OBJECT(marker)), 38.841847, -90.491982, 0); + gis_point_set_lle(gis_object_center(marker), 38.841847, -90.491982, 0); GIS_OBJECT(marker)->lod = EARTH_R/4; test->marker = gis_viewer_add(test->viewer, GIS_OBJECT(marker), GIS_LEVEL_OVERLAY, 0); diff --git a/src/roam.c b/src/roam.c index a5fd272..5faed38 100644 --- a/src/roam.c +++ b/src/roam.c @@ -18,10 +18,10 @@ #include #include #include -#include "gpqueue.h" #include #include +#include "gpqueue.h" #include "gis-util.h" #include "roam.h" @@ -60,7 +60,8 @@ RoamPoint *roam_point_new(gdouble lat, gdouble lon, gdouble elev) lle2xyz(lat, lon, elev, &point->x, &point->y, &point->z); return point; } -RoamPoint *roam_point_dup(RoamPoint *point) + +static RoamPoint *roam_point_dup(RoamPoint *point) { RoamPoint *new = g_memdup(point, sizeof(RoamPoint)); new->tris = 0; @@ -96,22 +97,23 @@ void roam_point_update_height(RoamPoint *point) &point->x, &point->y, &point->z); } } -void roam_point_update_projection(RoamPoint *point, RoamSphere *sphere) + +void roam_point_update_projection(RoamPoint *point, RoamView *view) { static int count = 0; static int version = 0; - if (version != sphere->view->version) { + if (version != view->version) { g_debug("RoamPoint: Projected %d points", count); count = 0; - version = sphere->view->version; + version = view->version; } - if (point->pversion != sphere->view->version) { + if (point->pversion != view->version) { /* Cache projection */ gluProject(point->x, point->y, point->z, - sphere->view->model, sphere->view->proj, sphere->view->view, + view->model, view->proj, view->view, &point->px, &point->py, &point->pz); - point->pversion = sphere->view->version; + point->pversion = view->version; count++; } } @@ -230,7 +232,7 @@ void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere) g_pqueue_remove(sphere->triangles, triangle->handle); } -void roam_triangle_sync_neighbors(RoamTriangle *new, RoamTriangle *old, RoamTriangle *neigh) +static void roam_triangle_sync_neighbors(RoamTriangle *new, RoamTriangle *old, RoamTriangle *neigh) { if (neigh->t.l == old) neigh->t.l = new; else if (neigh->t.b == old) neigh->t.b = new; @@ -238,14 +240,14 @@ void roam_triangle_sync_neighbors(RoamTriangle *new, RoamTriangle *old, RoamTria else g_assert_not_reached(); } -gboolean roam_point_visible(RoamPoint *triangle, RoamSphere *sphere) +static gboolean roam_point_visible(RoamPoint *triangle, RoamSphere *sphere) { gint *view = sphere->view->view; return triangle->px > view[0] && triangle->px < view[2] && triangle->py > view[1] && triangle->py < view[3] && triangle->pz > 0 && triangle->pz < 1; } -gboolean roam_triangle_visible(RoamTriangle *triangle, RoamSphere *sphere) +static gboolean roam_triangle_visible(RoamTriangle *triangle, RoamSphere *sphere) { /* Do this with a bounding box */ return roam_point_visible(triangle->p.l, sphere) || @@ -256,15 +258,15 @@ gboolean roam_triangle_visible(RoamTriangle *triangle, RoamSphere *sphere) void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere) { /* Update points */ - roam_point_update_projection(triangle->p.l, sphere); - roam_point_update_projection(triangle->p.m, sphere); - roam_point_update_projection(triangle->p.r, sphere); + roam_point_update_projection(triangle->p.l, sphere->view); + roam_point_update_projection(triangle->p.m, sphere->view); + roam_point_update_projection(triangle->p.r, sphere->view); /* Not exactly correct, could be out on both sides (middle in) */ if (!roam_triangle_visible(triangle, sphere)) { triangle->error = -1; } else { - roam_point_update_projection(triangle->split, sphere); + roam_point_update_projection(triangle->split, sphere->view); RoamPoint *l = triangle->p.l; RoamPoint *m = triangle->p.m; RoamPoint *r = triangle->p.r; @@ -666,7 +668,8 @@ GList *roam_sphere_get_intersect(RoamSphere *sphere, gboolean all, list, all, n, s, e, w); return list; } -void roam_sphere_free_tri(RoamTriangle *triangle) + +static void roam_sphere_free_tri(RoamTriangle *triangle) { if (--triangle->p.l->tris == 0) g_free(triangle->p.l); if (--triangle->p.m->tris == 0) g_free(triangle->p.m); diff --git a/src/roam.h b/src/roam.h index 0e18527..361025e 100644 --- a/src/roam.h +++ b/src/roam.h @@ -40,12 +40,13 @@ struct _RoamView { * RoamPoint * *************/ struct _RoamPoint { - gdouble x,y,z; // Model coordinates - gdouble px,py,pz; // Projected coordinates - gint pversion; // Version of cached projection + /*< private >*/ + gdouble x, y, z; /* Model coordinates */ + gdouble px, py, pz; /* Projected coordinates */ + gint pversion; /* Version of cached projection */ - gint tris; // Associated triangles - gdouble norm[3]; // Vertex normal + gint tris; /* Count of associated triangles */ + gdouble norm[3]; /* Vertex normal */ /* For get_intersect */ gdouble lat, lon, elev; @@ -54,22 +55,27 @@ struct _RoamPoint { RoamHeightFunc height_func; gpointer height_data; }; -RoamPoint *roam_point_new(double x, double y, double z); +RoamPoint *roam_point_new(double lat, double lon, double elev); void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle); void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle); void roam_point_update_height(RoamPoint *point); -void roam_point_update_projection(RoamPoint *point, RoamSphere *sphere); +void roam_point_update_projection(RoamPoint *point, RoamView *view); /**************** * RoamTriangle * ****************/ struct _RoamTriangle { + /*< private >*/ + /* Left, middle and right vertices */ struct { RoamPoint *l,*m,*r; } p; + + /* Left, base, and right neighbor triangles */ struct { RoamTriangle *l,*b,*r; } t; - RoamPoint *split; - RoamDiamond *parent; - double norm[3]; - double error; + + RoamPoint *split; /* Split point */ + RoamDiamond *parent; /* Parent diamond */ + double norm[3]; /* Surface normal */ + double error; /* Screen space error */ GPQueueHandle handle; /* For get_intersect */ @@ -77,22 +83,25 @@ struct _RoamTriangle { RoamTriangle *kids[2]; }; RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r); +void roam_triangle_free(RoamTriangle *triangle); void roam_triangle_add(RoamTriangle *triangle, RoamTriangle *left, RoamTriangle *base, RoamTriangle *right, RoamSphere *sphere); void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere); void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere); void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere); +void roam_triangle_draw(RoamTriangle *triangle); void roam_triangle_draw_normal(RoamTriangle *triangle); /*************** * RoamDiamond * ***************/ struct _RoamDiamond { - RoamTriangle *kids[4]; - RoamTriangle *parents[2]; - double error; - gboolean active; + /*< private >*/ + RoamTriangle *kids[4]; /* Child triangles */ + RoamTriangle *parents[2]; /* Parent triangles */ + double error; /* Screen space error */ + gboolean active; /* For internal use */ GPQueueHandle handle; }; RoamDiamond *roam_diamond_new( @@ -108,13 +117,14 @@ void roam_diamond_update_errors(RoamDiamond *diamond, RoamSphere *sphere); * RoamSphere * **************/ struct _RoamSphere { - GPQueue *triangles; - GPQueue *diamonds; - RoamView *view; - gint polys; + /*< private >*/ + GPQueue *triangles; /* List of triangles */ + GPQueue *diamonds; /* List of diamonds */ + RoamView *view; /* Current projection */ + gint polys; /* Polygon count */ /* For get_intersect */ - RoamTriangle *roots[8]; + RoamTriangle *roots[8]; /* Original 8 triangles */ }; RoamSphere *roam_sphere_new(); void roam_sphere_update_view(RoamSphere *sphere); -- 2.43.2