Merge branch 'next' of git://gitorious.org/fg/simgear into fredb/winbuild
This commit is contained in:
@@ -627,6 +627,14 @@
|
||||
RelativePath="..\..\simgear\misc\sg_path.hxx"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\misc\sg_dir.cxx"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\misc\sg_dir.hxx"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\simgear\misc\sgstream.cxx"
|
||||
>
|
||||
|
||||
@@ -12,7 +12,8 @@ include_HEADERS = \
|
||||
zfstream.hxx \
|
||||
interpolator.hxx \
|
||||
stdint.hxx \
|
||||
PathOptions.hxx
|
||||
PathOptions.hxx \
|
||||
sg_dir.hxx
|
||||
|
||||
libsgmisc_a_SOURCES = \
|
||||
sg_path.cxx \
|
||||
@@ -22,7 +23,8 @@ libsgmisc_a_SOURCES = \
|
||||
texcoord.cxx \
|
||||
zfstream.cxx \
|
||||
interpolator.cxx \
|
||||
PathOptions.cxx
|
||||
PathOptions.cxx \
|
||||
sg_dir.cxx
|
||||
|
||||
#noinst_PROGRAMS = tabbed_value_test swap_test
|
||||
|
||||
|
||||
154
simgear/misc/sg_dir.cxx
Normal file
154
simgear/misc/sg_dir.cxx
Normal file
@@ -0,0 +1,154 @@
|
||||
// Written by James Turner, started July 2010.
|
||||
//
|
||||
// Copyright (C) 2010 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <simgear/misc/sg_dir.hxx>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
namespace simgear
|
||||
{
|
||||
|
||||
Dir::Dir(const SGPath& path) :
|
||||
_path(path)
|
||||
{
|
||||
}
|
||||
|
||||
Dir::Dir(const Dir& rel, const SGPath& relPath) :
|
||||
_path(rel.file(relPath.str()))
|
||||
{
|
||||
}
|
||||
|
||||
PathList Dir::children(int types, const std::string& nameFilter) const
|
||||
{
|
||||
PathList result;
|
||||
if (types == 0) {
|
||||
types = TYPE_FILE | TYPE_DIR | NO_DOT_OR_DOTDOT;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string search(_path.str());
|
||||
if (nameFilter.empty()) {
|
||||
search += "\\*"; // everything
|
||||
} else {
|
||||
search += "\\*" + nameFilter;
|
||||
}
|
||||
|
||||
WIN32_FIND_DATA fData;
|
||||
HANDLE find = FindFirstFile(search.c_str(), &fData);
|
||||
if (find == INVALID_HANDLE_VALUE) {
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "Dir::children: FindFirstFile failed:" << _path.str());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
for (bool done = false; !done; done = (FindNextFile(find, &fData) == 0)) {
|
||||
if (fData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
|
||||
if (!(types & INCLUDE_HIDDEN)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
if (!(types & TYPE_DIR)) {
|
||||
continue;
|
||||
}
|
||||
} else if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) ||
|
||||
(fData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
|
||||
{
|
||||
continue; // always ignore device files
|
||||
} else if (!(types & TYPE_FILE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push_back(file(fData.cFileName));
|
||||
}
|
||||
|
||||
FindClose(find);
|
||||
#else
|
||||
DIR* dp = opendir(_path.c_str());
|
||||
if (!dp) {
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "Dir::children: opendir failed:" << _path.str());
|
||||
return result;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
struct dirent* entry = readdir(dp);
|
||||
if (!entry) {
|
||||
break; // done iteration
|
||||
}
|
||||
|
||||
// skip hidden files (names beginning with '.') unless requested
|
||||
if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry->d_type == DT_DIR) {
|
||||
if (!(types & TYPE_DIR)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (types & NO_DOT_OR_DOTDOT) {
|
||||
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (entry->d_type == DT_REG) {
|
||||
if (!(types & TYPE_FILE)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
continue; // ignore char/block devices, fifos, etc
|
||||
}
|
||||
|
||||
if (!nameFilter.empty()) {
|
||||
if (strstr(entry->d_name, nameFilter.c_str()) == NULL) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// passed all criteria, add to our result vector
|
||||
result.push_back(file(entry->d_name));
|
||||
}
|
||||
|
||||
closedir(dp);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
SGPath Dir::file(const std::string& name) const
|
||||
{
|
||||
SGPath childPath = _path;
|
||||
childPath.append(name);
|
||||
return childPath;
|
||||
}
|
||||
|
||||
} // of namespace simgear
|
||||
62
simgear/misc/sg_dir.hxx
Normal file
62
simgear/misc/sg_dir.hxx
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
// Written by James Turner, started July 2010.
|
||||
//
|
||||
// Copyright (C) 2010 Curtis L. Olson - http://www.flightgear.org/~curt
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Library General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#ifndef _SG_DIR_HXX
|
||||
#define _SG_DIR_HXX
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <string>
|
||||
|
||||
#include <simgear/math/sg_types.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
namespace simgear
|
||||
{
|
||||
typedef std::vector<SGPath> PathList;
|
||||
|
||||
class Dir
|
||||
{
|
||||
public:
|
||||
Dir(const SGPath& path);
|
||||
Dir(const Dir& rel, const SGPath& relPath);
|
||||
|
||||
enum FileTypes
|
||||
{
|
||||
TYPE_FILE = 1,
|
||||
TYPE_DIR = 2,
|
||||
NO_DOT_OR_DOTDOT = 1 << 12,
|
||||
INCLUDE_HIDDEN = 1 << 13
|
||||
};
|
||||
|
||||
PathList children(int types = 0, const std::string& nameGlob = "") const;
|
||||
|
||||
SGPath file(const std::string& name) const;
|
||||
private:
|
||||
mutable SGPath _path;
|
||||
};
|
||||
} // of namespace simgear
|
||||
|
||||
#endif // _SG_DIR_HXX
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ void TextureUnitBuilder::buildAttribute(Effect* effect, Pass* pass,
|
||||
texture = TextureBuilder::buildFromType(effect, type, prop,
|
||||
options);
|
||||
}
|
||||
catch (BuilderException& e) {
|
||||
catch (BuilderException& ) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No image file, "
|
||||
<< "maybe the reader did not set the filename attribute, "
|
||||
<< "using white on " << pass->getName());
|
||||
|
||||
@@ -274,7 +274,7 @@ void MakeEffectVisitor::apply(osg::Geode& geode)
|
||||
ref_ptr<SGSceneUserData> userData = SGSceneUserData::getSceneUserData(&geode);
|
||||
if (userData.valid())
|
||||
eg->setUserData(new SGSceneUserData(*userData));
|
||||
for (int i = 0; i < geode.getNumDrawables(); ++i) {
|
||||
for (unsigned i = 0; i < geode.getNumDrawables(); ++i) {
|
||||
osg::Drawable *drawable = geode.getDrawable(i);
|
||||
eg->addDrawable(drawable);
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ void SGSampleGroup::update( double dt ) {
|
||||
}
|
||||
|
||||
if ( result == AL_STOPPED ) {
|
||||
sample->stop();
|
||||
ALuint buffer = sample->get_buffer();
|
||||
alDeleteBuffers( 1, &buffer );
|
||||
testForALError("buffer remove");
|
||||
@@ -157,17 +158,6 @@ void SGSampleGroup::update( double dt ) {
|
||||
// sadly, no free source available at this time
|
||||
}
|
||||
|
||||
} else if ( sample->is_valid_source() && sample->has_changed() ) {
|
||||
if ( !sample->is_playing() ) {
|
||||
// a request to stop playing the sound has been filed.
|
||||
|
||||
sample->stop();
|
||||
sample->no_valid_source();
|
||||
_smgr->release_source( sample->get_source() );
|
||||
} else if ( _smgr->has_changed() ) {
|
||||
update_sample_config( sample );
|
||||
}
|
||||
|
||||
} else if ( sample->is_valid_source() ) {
|
||||
// check if the sound has stopped by itself
|
||||
|
||||
@@ -183,6 +173,18 @@ void SGSampleGroup::update( double dt ) {
|
||||
_smgr->release_buffer( sample );
|
||||
remove( sample->get_sample_name() );
|
||||
}
|
||||
else
|
||||
if ( sample->has_changed() ) {
|
||||
if ( !sample->is_playing() ) {
|
||||
// a request to stop playing the sound has been filed.
|
||||
sample->stop();
|
||||
sample->no_valid_source();
|
||||
_smgr->release_source( sample->get_source() );
|
||||
} else if ( _smgr->has_changed() ) {
|
||||
update_sample_config( sample );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
testForALError("update");
|
||||
}
|
||||
@@ -258,6 +260,7 @@ SGSampleGroup::stop ()
|
||||
if ( sample->is_playing() ) {
|
||||
alSourceStop( source );
|
||||
alSourcei( source, AL_BUFFER, 0 );
|
||||
sample->stop();
|
||||
}
|
||||
_smgr->release_source( source );
|
||||
sample->no_valid_source();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "event_mgr.hxx"
|
||||
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
void SGEventMgr::add(SGCallback* cb,
|
||||
void SGEventMgr::add(const std::string& name, SGCallback* cb,
|
||||
double interval, double delay,
|
||||
bool repeat, bool simtime)
|
||||
{
|
||||
@@ -16,7 +17,8 @@ void SGEventMgr::add(SGCallback* cb,
|
||||
t->mgr = this;
|
||||
t->repeat = repeat;
|
||||
t->simtime = simtime;
|
||||
|
||||
t->name = name;
|
||||
|
||||
SGTimerQueue* q = simtime ? &_simQueue : &_rtQueue;
|
||||
|
||||
q->insert(t, delay);
|
||||
@@ -43,6 +45,21 @@ void SGEventMgr::update(double delta_time_sec)
|
||||
_rtQueue.update(rt);
|
||||
}
|
||||
|
||||
void SGEventMgr::removeTask(const std::string& name)
|
||||
{
|
||||
SGTimer* t = _simQueue.findByName(name);
|
||||
if (t) {
|
||||
_simQueue.remove(t);
|
||||
} else if ((t = _rtQueue.findByName(name))) {
|
||||
_rtQueue.remove(t);
|
||||
} else {
|
||||
SG_LOG(SG_GENERAL, SG_WARN, "removeTask: no task found with name:" << name);
|
||||
return;
|
||||
}
|
||||
|
||||
delete t;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SGTimerQueue
|
||||
// This is the priority queue implementation:
|
||||
@@ -165,3 +182,15 @@ void SGTimerQueue::growArray()
|
||||
delete[] _table;
|
||||
_table = newTable;
|
||||
}
|
||||
|
||||
SGTimer* SGTimerQueue::findByName(const std::string& name) const
|
||||
{
|
||||
for (int i=0; i < _numEntries; ++i) {
|
||||
if (_table[i].timer->name == name) {
|
||||
return _table[i].timer;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
class SGEventMgr;
|
||||
|
||||
struct SGTimer {
|
||||
std::string name;
|
||||
double interval;
|
||||
SGCallback* callback;
|
||||
SGEventMgr* mgr;
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
SGTimer* nextTimer() { return _numEntries ? _table[0].timer : 0; }
|
||||
double nextTime() { return -_table[0].pri; }
|
||||
|
||||
SGTimer* findByName(const std::string& name) const;
|
||||
private:
|
||||
// The "priority" is stored as a negative time. This allows the
|
||||
// implemenetation to treat the "top" of the heap as the largest
|
||||
@@ -77,43 +79,45 @@ public:
|
||||
* ex: addTask("foo", &Function ... )
|
||||
*/
|
||||
template<typename FUNC>
|
||||
inline void addTask(const char* name, const FUNC& f,
|
||||
inline void addTask(const std::string& name, const FUNC& f,
|
||||
double interval, double delay=0, bool sim=false)
|
||||
{ add(make_callback(f), interval, delay, true, sim); }
|
||||
{ add(name, make_callback(f), interval, delay, true, sim); }
|
||||
|
||||
/**
|
||||
* Add a single function callback event as a one-shot event.
|
||||
* ex: addEvent("foo", &Function ... )
|
||||
*/
|
||||
template<typename FUNC>
|
||||
inline void addEvent(const char* name, const FUNC& f,
|
||||
inline void addEvent(const std::string& name, const FUNC& f,
|
||||
double delay, bool sim=false)
|
||||
{ add(make_callback(f), 0, delay, false, sim); }
|
||||
{ add(name, make_callback(f), 0, delay, false, sim); }
|
||||
|
||||
/**
|
||||
* Add a object/method pair as a repeating task.
|
||||
* ex: addTask("foo", &object, &ClassName::Method, ...)
|
||||
*/
|
||||
template<class OBJ, typename METHOD>
|
||||
inline void addTask(const char* name,
|
||||
inline void addTask(const std::string& name,
|
||||
const OBJ& o, METHOD m,
|
||||
double interval, double delay=0, bool sim=false)
|
||||
{ add(make_callback(o,m), interval, delay, true, sim); }
|
||||
{ add(name, make_callback(o,m), interval, delay, true, sim); }
|
||||
|
||||
/**
|
||||
* Add a object/method pair as a repeating task.
|
||||
* ex: addEvent("foo", &object, &ClassName::Method, ...)
|
||||
*/
|
||||
template<class OBJ, typename METHOD>
|
||||
inline void addEvent(const char* name,
|
||||
inline void addEvent(const std::string& name,
|
||||
const OBJ& o, METHOD m,
|
||||
double delay, bool sim=false)
|
||||
{ add(make_callback(o,m), 0, delay, false, sim); }
|
||||
{ add(name, make_callback(o,m), 0, delay, false, sim); }
|
||||
|
||||
|
||||
void removeTask(const std::string& name);
|
||||
private:
|
||||
friend struct SGTimer;
|
||||
|
||||
void add(SGCallback* cb,
|
||||
void add(const std::string& name, SGCallback* cb,
|
||||
double interval, double delay,
|
||||
bool repeat, bool simtime);
|
||||
|
||||
|
||||
@@ -384,6 +384,8 @@ public:
|
||||
INIT = 0,
|
||||
GENERAL,
|
||||
FDM, ///< flight model, autopilot, instruments that run coupled
|
||||
POST_FDM, ///< certain subsystems depend on FDM data
|
||||
DISPLAY, ///< view, camera, rendering updates
|
||||
MAX_GROUPS
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user