1 // userdata.hxx -- two classes for populating ssg user data slots in association
2 //                 with our implimenation of random surface objects.
3 //
4 // Written by David Megginson, started December 2001.
5 //
6 // Copyright (C) 2001 - 2003  Curtis L. Olson  - http://www.flightgear.org/~curt
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23 
24 #ifdef HAVE_CONFIG_H
25 #  include <simgear_config.h>
26 #endif
27 
28 #include <osgDB/Registry>
29 
30 #include <simgear/sg_inlines.h>
31 #include <simgear/math/sg_geodesy.hxx>
32 #include <simgear/math/sg_random.h>
33 #include <simgear/scene/material/mat.hxx>
34 #include <simgear/scene/material/matmodel.hxx>
35 #include <simgear/scene/model/ModelRegistry.hxx>
36 
37 #include "userdata.hxx"
38 #include "SGReaderWriterBTG.hxx"
39 #include "ReaderWriterSPT.hxx"
40 #include "ReaderWriterSTG.hxx"
41 #include <simgear/scene/dem/ReaderWriterPGT.hxx>
42 
43 // the following are static values needed by the runtime object
44 // loader.  However, the loading is done via a call back so these
45 // values cannot be passed as parameters.  The calling application
46 // needs to call sgUserDataInit() with the appropriate values before
47 // building / drawing any scenery.
48 
49 static bool _inited = false;
50 static SGPropertyNode *root_props = NULL;
51 
52 // Because BTG files are now loaded through the osgDB::Registry, there
53 // are no symbols referenced by FlightGear in this library other than
54 // sgUserDataInit. But the libraries are all statically linked, so
55 // none of the other object files in this library would be included in
56 // the executable! Sticking the static proxy here forces the BTG code
57 // to be sucked in.
58 namespace {
59 osgDB::RegisterReaderWriterProxy<SGReaderWriterBTG> g_readerWriter_BTG_Proxy;
60 
61 osgDB::RegisterReaderWriterProxy<simgear::ReaderWriterSTG> g_readerWriterSTGProxy;
62 simgear::ModelRegistryCallbackProxy<simgear::LoadOnlyCallback> g_stgCallbackProxy("stg");
63 
64 osgDB::RegisterReaderWriterProxy<simgear::ReaderWriterSPT> g_readerWriterSPTProxy;
65 simgear::ModelRegistryCallbackProxy<simgear::LoadOnlyCallback> g_sptCallbackProxy("spt");
66 
67 #ifdef ENABLE_GDAL
68 osgDB::RegisterReaderWriterProxy<simgear::ReaderWriterPGT> g_readerWriterPGTProxy;
69 simgear::ModelRegistryCallbackProxy<simgear::LoadOnlyCallback> g_pgtCallbackProxy("pgt");
70 #endif
71 }
72 
sgUserDataInit(SGPropertyNode * p)73 void sgUserDataInit( SGPropertyNode *p ) {
74     _inited = true;
75     root_props = p;
76 }
77 
78 namespace simgear
79 {
getPropertyRoot()80 SGPropertyNode* getPropertyRoot()
81 {
82     return root_props;
83 }
84 }
85