root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/RecordInputStream.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14//
15// OpenFlight® loader for OpenSceneGraph
16//
17//  Copyright (C) 2005-2007  Brede Johansen
18//
19
20#include <iostream>
21#include "Opcodes.h"
22#include "Registry.h"
23#include "Document.h"
24#include "RecordInputStream.h"
25
26using namespace flt;
27using namespace std;
28
29
30RecordInputStream::RecordInputStream(std::streambuf* sb):
31    DataInputStream(sb),
32    _recordSize(0)
33{}
34
35bool RecordInputStream::readRecord(Document& document)
36{
37    opcode_type opcode = (opcode_type)readUInt16();
38    size_type   size   = (size_type)readUInt16();
39
40    return readRecordBody(opcode, size, document);
41}
42
43bool RecordInputStream::readRecordBody(opcode_type opcode, size_type size, Document& document)
44{
45    // Correct endian error in Creator v2.5 gallery models.
46    // Last pop level record in little-endian.
47    const uint16 LITTLE_ENDIAN_POP_LEVEL_OP = 0x0B00;
48    if (opcode==LITTLE_ENDIAN_POP_LEVEL_OP)
49    {
50        OSG_INFO << "Little endian pop-level record" << std::endl;
51        opcode=POP_LEVEL_OP;
52        size=4;
53    }
54
55    _recordSize = size;
56
57    // Get prototype record
58    Record* prototype = Registry::instance()->getPrototype((int)opcode);
59
60    if (prototype)
61    {
62#if 0 // for debugging
63        {
64            for (int i=0; i<document.level(); i++)
65                cout << "   ";
66            cout << "opcode=" << opcode << " size=" << size;
67            if (prototype) std::cout << " " << typeid(*prototype).name();
68            cout << endl;
69        }
70#endif
71        // Create from prototype.
72        osg::ref_ptr<Record> record = prototype->cloneType();
73
74        // Read record
75        record->read(*this,document);
76    }
77    else // prototype not found
78    {
79        OSG_WARN << "Unknown record, opcode=" << opcode << " size=" << size << std::endl;
80
81        // Add to registry so we only have to see this error message once.
82        Registry::instance()->addPrototype(opcode,new DummyRecord);
83    }
84
85    return good();
86}
Note: See TracBrowser for help on using the browser.