Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
file_main.h
Go to the documentation of this file.
1
/*
2
* Vega Strike
3
* Copyright (C) 2001-2002 Daniel Horn
4
*
5
* http://vegastrike.sourceforge.net/
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
*/
21
#ifndef _FILE_MAIN_H_
22
#define _FILE_MAIN_H_
23
#include <stdio.h>
24
#include <string.h>
25
//#include "gfxlib.h"
26
#include "
endianness.h
"
27
#include "
vsfilesystem.h
"
28
using
VSFileSystem::VSFile
;
29
//using namespace VSFileSystem;
30
extern
VSFile
fpread
;
31
32
/*File utility functions*/
33
inline
void
LoadFile
(
const
char
*filename )
34
{
35
fpread.
OpenReadOnly
( filename );
36
}
37
inline
void
CloseFile
()
38
{
39
fpread.
Close
();
40
}
41
42
inline
float
readf
(
VSFileSystem::VSFile
&f )
43
{
44
union
45
{
46
float
fval;
47
unsigned
int
ival;
48
}
49
t;
50
f.
Read
( &t.fval,
sizeof
t.fval );
51
t.ival =
le32_to_cpu
( t.ival );
52
return
t.fval;
53
}
54
inline
size_t
readf
(
VSFileSystem::VSFile
&f,
float
*
b
,
int
n )
55
{
56
int
i
;
57
size_t
rode = f.
Read
( b,
sizeof
(*b)*n );
58
#ifndef NATURAL_ENDIANNESS
59
for
(i = 0; i < n; i++)
60
( (
unsigned
int
*) b )[i] =
le32_to_cpu
( ( (
unsigned
int
*) b )[i] );
61
#endif
62
return
(rode > 0) ? ( rode/
sizeof
(*b) ) : rode;
63
}
64
inline
short
reads
(
VSFileSystem::VSFile
&f )
65
{
66
short
temp;
67
f.
Read
( &temp,
sizeof
(
short
) );
68
return
le16_to_cpu
( temp );
69
}
70
inline
int
readi
(
VSFileSystem::VSFile
&f )
71
{
72
int
i
;
73
f.
Read
( &i,
sizeof
(
int
) );
74
return
le32_to_cpu
( i );
75
}
76
inline
size_t
readi
(
VSFileSystem::VSFile
&f,
int
*
b
,
int
n )
77
{
78
int
i
;
79
size_t
rode = f.
Read
( b,
sizeof
(*b)*n );
80
#ifndef NATURAL_ENDIANNESS
81
for
(i = 0; i < n; i++)
82
b[i] =
le32_to_cpu
( b[i] );
83
#endif
84
return
(rode > 0) ? ( rode/
sizeof
(*b) ) : rode;
85
}
86
inline
unsigned
char
readc
(
VSFileSystem::VSFile
&f )
87
{
88
unsigned
char
temp;
89
f.
Read
( &temp,
sizeof
(
char
) );
90
return
temp;
91
}
92
93
/*Read simple data*/
94
inline
void
ReadInt
(
int
&integer )
95
{
96
fpread.
Read
( &integer,
sizeof
(
int
) );
97
integer =
le32_to_cpu
( integer );
98
}
99
inline
void
ReadFloat
(
float
&num )
100
{
101
fpread.
Read
( &num,
sizeof
(
float
) );
102
*( (
int
*) &num ) =
le32_to_cpu
( *( (
int
*) &num ) );
103
}
104
105
inline
void
ReadString
(
char
*
string
)
106
{
107
int
length = strlen(
string
);
108
109
ReadInt
( length );
110
fpread.
Read
(
string
, length );
111
string
[length] =
'\0'
;
112
}
113
114
/*Read aggregated data*/
115
inline
void
ReadVector
(
float
&
x
,
float
&
y
,
float
&z )
116
{
117
ReadFloat
( x );
118
ReadFloat
( y );
119
ReadFloat
( z );
120
}
121
122
inline
void
ReadVector
(
Vector
&
v
)
123
{
124
ReadVector
( v.i, v.j, v.k );
125
}
126
127
inline
void
ReadGeneric
(
char
*
string
,
float
&
x
,
float
&
y
,
float
&z )
128
{
129
ReadString
(
string
);
130
ReadVector
( x, y, z );
131
}
132
133
/*The goods*/
134
inline
void
ReadUnit
(
char
*filename,
int
&type,
float
&
x
,
float
&
y
,
float
&z )
135
{
136
ReadGeneric
( filename, x, y, z );
137
}
138
139
inline
void
ReadMesh
(
char
*filename,
float
&
x
,
float
&
y
,
float
&z )
140
{
141
ReadGeneric
( filename, x, y, z );
142
}
143
144
inline
void
ReadWeapon
(
char
*filename,
float
&
x
,
float
&
y
,
float
&z )
145
{
146
ReadGeneric
( filename, x, y, z );
147
}
148
149
inline
void
ReadRestriction
(
int
&isrestricted,
float
&
start
,
float
&end )
150
{
151
ReadInt
( isrestricted );
152
ReadFloat
( start );
153
ReadFloat
( end );
154
}
155
156
inline
long
GetPosition
()
157
{
158
return
fpread.
GetPosition
();
159
}
160
161
inline
void
SetPosition
(
long
position )
162
{
163
fpread.
GoTo
( position );
164
}
165
166
#endif
src
file_main.h
Generated on Fri May 29 2015 23:07:20 for Vegastrike 0.5.1 rc1 by
1.8.4