Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2007-10-21 23:02:47 +0000
committerStijn Buys <ingar@osirion.org>2007-10-21 23:02:47 +0000
commita237a2d7723b94df6cd3e91401ec28388de6f1a0 (patch)
tree7da376d276d03fced7b94a807c0952fd32bcde08 /src/common
parent084c6212afaa6f996091f36d0ff85ac845803a87 (diff)
namespace cleanup
Diffstat (limited to 'src/common')
-rw-r--r--src/common/color.cc14
-rw-r--r--src/common/color.h14
-rw-r--r--src/common/file.cc70
-rw-r--r--src/common/file.h35
-rw-r--r--src/common/functions.cc13
-rw-r--r--src/common/functions.h11
-rw-r--r--src/common/vector3f.cc14
-rw-r--r--src/common/vector3f.h21
8 files changed, 166 insertions, 26 deletions
diff --git a/src/common/color.cc b/src/common/color.cc
index 85892c8..da43efc 100644
--- a/src/common/color.cc
+++ b/src/common/color.cc
@@ -1,15 +1,14 @@
/*
- ***************************************************************************
- * Copyright (C) 2002-2004 by Stijn Buys *
- * stijn.buys@pandora.be *
- * *
- * This software is redistributed under the terms of the *
- * GNU General Public License. Please read LICENSE.txt. *
- ***************************************************************************
+ common/color.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
+// project headers
#include "color.h"
+namespace common {
+
Color::Color() {
_r = _g = _b = 0.0f;
_a = 1.0f;
@@ -82,3 +81,4 @@ std::ostream &operator<<(std::ostream &os, const Color &c) {
return os;
}
+} // namespace common
diff --git a/src/common/color.h b/src/common/color.h
index d84d1a3..e6aa9eb 100644
--- a/src/common/color.h
+++ b/src/common/color.h
@@ -1,11 +1,7 @@
/*
- ***************************************************************************
- * Copyright (C) 2004 by Stijn Buys *
- * stijn.buys@pandora.be *
- * *
- * This software is redistributed under the terms of the *
- * GNU General Public License. Please read LICENSE.txt. *
- ***************************************************************************
+ common/color.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __COLOR_HEADER__
@@ -13,6 +9,8 @@
#include <iostream>
+namespace common {
+
/// a class representing an RGBA color value
class Color {
public:
@@ -47,4 +45,6 @@ std::ostream &operator<<(std::ostream &os, const Color &c);
Color operator*(const float scalar, const Color& color);
+} // namespace commmon
+
#endif // ___HEADER__
diff --git a/src/common/file.cc b/src/common/file.cc
new file mode 100644
index 0000000..2ebd457
--- /dev/null
+++ b/src/common/file.cc
@@ -0,0 +1,70 @@
+/*
+ common/file.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+// project headers
+#include "file.h"
+
+// C++ headers
+#include <iostream>
+
+namespace common {
+
+std::string File::datadir = "";
+std::string File::homedir = "";
+std::string File::basedir = "";
+std::string File::moddir = "";
+
+void File::open(const char * filename, ios_base::openmode mode)
+{
+ std::string fn;
+
+ // if moddir is set, try the mods subdir first
+ if (moddir.size() > 0) {
+ // try homedir+moddir
+ fn = homedir;
+ fn.append(moddir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "File opened " << fn << std::endl;
+ return;
+ }
+
+ // try datadir + moddir
+ fn = datadir;
+ fn.append(moddir);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "File opened " << fn << std::endl;
+ return;
+ }
+ }
+
+ // try homedir+basedir
+ fn = homedir;
+ fn.append(basedir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+ if (this->is_open()) {
+ std::cerr << "File opened " << fn << std::endl;
+ return;
+ }
+
+ // try datadir+basedir
+ fn = datadir;
+ fn.append(basedir);
+ fn.append(filename);
+ std::ifstream::open(fn.c_str(), mode);
+
+ // FIXME console
+ if (!this->is_open()) {
+ std::cerr << "File could not open " << filename << std::endl;
+ } else {
+ std::cerr << "File opened " << fn << std::endl;
+ }
+}
+
+} // namespace common
diff --git a/src/common/file.h b/src/common/file.h
new file mode 100644
index 0000000..a377981
--- /dev/null
+++ b/src/common/file.h
@@ -0,0 +1,35 @@
+/*
+ common/file.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_FILE_H__
+#define __INCLUDED_FILE_H__
+
+// C++ headers
+#include <string>
+#include <fstream>
+
+namespace common {
+
+/// a class to open data files
+class File : public std::ifstream
+{
+public:
+ /// open the file for reading
+ void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in );
+
+ /// location of the main data files, includes trailing /
+ static std::string datadir;
+ /// location of the personal data files, includes trailing /
+ static std::string homedir;
+ /// subdirectory with the base data files, includes trailing /
+ static std::string basedir;
+ /// subdirectory for the current mod, includes trailing /
+ static std::string moddir;
+}; // class File
+
+} // namespace common
+
+#endif // __INCLUDED_GAME_H__
diff --git a/src/common/functions.cc b/src/common/functions.cc
index 7152c91..7a01628 100644
--- a/src/common/functions.cc
+++ b/src/common/functions.cc
@@ -1,9 +1,14 @@
-/* functions.cc
- * This file is part of the Osirion project
- */
+/*
+ common/functions.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+// project headers
#include "functions.h"
+namespace common {
+
float min(float a, float b) {
return (a < b ? a : b);
}
@@ -46,3 +51,5 @@ float sgnf(float value)
return 1;
}
+
+} // namespace common
diff --git a/src/common/functions.h b/src/common/functions.h
index 02f25da..62cf627 100644
--- a/src/common/functions.h
+++ b/src/common/functions.h
@@ -1,13 +1,18 @@
-/* functions.h
- This file is part of the Osirion project
+/*
+ common/functions.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_FUNCTIONS_H__
#define __INCLUDED_FUNCTIONS_H__
+// C++ headers
#include <cstdlib>
#include <cmath>
+namespace common {
+
/// return the smallest of two float values
float min(float a, float b);
@@ -38,5 +43,7 @@ float sgnf(float value);
/// return an angle in the ]-180,180] range
float degreesf(float angle);
+} // namespace common
+
#endif // __INCLUDED_FUNCTIONS_H__
diff --git a/src/common/vector3f.cc b/src/common/vector3f.cc
index 3e469b6..86bdb36 100644
--- a/src/common/vector3f.cc
+++ b/src/common/vector3f.cc
@@ -1,9 +1,17 @@
-/* vector3f.h
- This file is part of the Osirion project
+/*
+ common/vector3f.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
+
+// project headers
#include "vector3f.h"
+
+// C++ headers
#include <cmath>
+namespace common {
+
Vector3f::Vector3f() :
x(coord[0]), y(coord[1]), z(coord[2])
{
@@ -149,3 +157,5 @@ std::istream &operator>>(std::istream & is, Vector3f & vector) {
Vector3f operator*(float scalar, const Vector3f& vector) {
return vector * scalar;
}
+
+} // namespace common
diff --git a/src/common/vector3f.h b/src/common/vector3f.h
index 53b2ce7..e943bd4 100644
--- a/src/common/vector3f.h
+++ b/src/common/vector3f.h
@@ -1,11 +1,20 @@
-/* vector3f.h
- This file is part of the Osirion project
+/*
+ common/vector3f.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
- #ifndef __INCLUDED_VECTOR3F_H__
- #define __INCLUDED_VECTOR3F_H__
+#ifndef __INCLUDED_VECTOR3F_H__
+#define __INCLUDED_VECTOR3F_H__
+
+// project headers
+#include "vector3f.h"
+
+// C++ headers
+#include <iostream>
+
+namespace common {
- #include <iostream>
/// A point or vector in 3D-space
/*!
An instance of this class represents a point in 3D-space or a 3D-vector
@@ -135,4 +144,6 @@ std::istream &operator>>(std::istream & is, Vector3f& vector);
/// scalar*Vector3f operators
Vector3f operator*(float scalar, const Vector3f& vector);
+} // namespace common
+
#endif // __INCLUDED_VECTOR3F_H__