From f2dca60c21c2e188a09f532bbf3a59dc7a50910d Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 16 Nov 2001 12:38:29 +0000 Subject: [PATCH] add fltInfo --- pandatool/src/fltprogs/Sources.pp | 14 ++++ pandatool/src/fltprogs/fltInfo.cxx | 110 +++++++++++++++++++++++++++++ pandatool/src/fltprogs/fltInfo.h | 49 +++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 pandatool/src/fltprogs/fltInfo.cxx create mode 100644 pandatool/src/fltprogs/fltInfo.h diff --git a/pandatool/src/fltprogs/Sources.pp b/pandatool/src/fltprogs/Sources.pp index a229fa802d..94085fcc7d 100644 --- a/pandatool/src/fltprogs/Sources.pp +++ b/pandatool/src/fltprogs/Sources.pp @@ -28,6 +28,20 @@ #end bin_target +#begin bin_target + #define TARGET flt-info + #define LOCAL_LIBS \ + progbase flt + #define OTHER_LIBS \ + linmath:c panda:m \ + express:c pandaexpress:m \ + dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub + + #define SOURCES \ + fltInfo.cxx fltInfo.h + +#end bin_target + #begin bin_target #define TARGET flt2egg #define LOCAL_LIBS flt fltegg eggbase progbase diff --git a/pandatool/src/fltprogs/fltInfo.cxx b/pandatool/src/fltprogs/fltInfo.cxx new file mode 100644 index 0000000000..2a9f8b1d97 --- /dev/null +++ b/pandatool/src/fltprogs/fltInfo.cxx @@ -0,0 +1,110 @@ +// Filename: fltInfo.cxx +// Created by: drose (05Sep01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "fltInfo.h" + +#include "fltHeader.h" +#include "indent.h" + +//////////////////////////////////////////////////////////////////// +// Function: FltInfo::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +FltInfo:: +FltInfo() { + set_program_description + ("This program reads a MultiGen OpenFlight (.flt) file and reports " + "some interesting things about its contents."); + + clear_runlines(); + add_runline("[opts] input.flt"); + + add_option + ("ls", "", 0, + "List the hierarchy in the flt file.", + &FltInfo::dispatch_none, &_list_hierarchy); +} + + +//////////////////////////////////////////////////////////////////// +// Function: FltInfo::run +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void FltInfo:: +run() { + PT(FltHeader) header = new FltHeader; + + nout << "Reading " << _input_filename << "\n"; + FltError result = header->read_flt(_input_filename); + if (result != FE_ok) { + nout << "Unable to read: " << result << "\n"; + exit(1); + } + + if (header->check_version()) { + nout << "Version is " << header->get_flt_version() / 100.0 << "\n"; + } + + if (_list_hierarchy) { + list_hierarchy(header, 0); + } +} + +//////////////////////////////////////////////////////////////////// +// Function: FltInfo::list_hierarchy +// Access: Protected +// Description: Recursively lists the flt file's hierarchy in a +// meaningful way. +//////////////////////////////////////////////////////////////////// +void FltInfo:: +list_hierarchy(FltRecord *record, int indent_level) { + // Maybe in the future we can do something fancier here. + record->write(cout, indent_level); +} + + +//////////////////////////////////////////////////////////////////// +// Function: FltInfo::handle_args +// Access: Protected, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +bool FltInfo:: +handle_args(ProgramBase::Args &args) { + if (args.empty()) { + nout << "You must specify the .flt file to read on the command line.\n"; + return false; + + } else if (args.size() != 1) { + nout << "You must specify only one .flt file to read on the command line.\n"; + return false; + } + + _input_filename = args[0]; + + return true; +} + + +int main(int argc, char *argv[]) { + FltInfo prog; + prog.parse_command_line(argc, argv); + prog.run(); + return 0; +} diff --git a/pandatool/src/fltprogs/fltInfo.h b/pandatool/src/fltprogs/fltInfo.h new file mode 100644 index 0000000000..d1799f897b --- /dev/null +++ b/pandatool/src/fltprogs/fltInfo.h @@ -0,0 +1,49 @@ +// Filename: fltInfo.h +// Created by: drose (05Sep01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef FLTINFO_H +#define FLTINFO_H + +#include "pandatoolbase.h" + +#include "programBase.h" + +class FltRecord; + +//////////////////////////////////////////////////////////////////// +// Class : FltInfo +// Description : A program to read a flt file and report interesting +// things about it. +//////////////////////////////////////////////////////////////////// +class FltInfo : public ProgramBase { +public: + FltInfo(); + + void run(); + +protected: + virtual bool handle_args(Args &args); + + void list_hierarchy(FltRecord *record, int indent_level); + + Filename _input_filename; + bool _list_hierarchy; +}; + +#endif +