Skip to content

Commit

Permalink
finished fixing lint errors, enabling cpplint in CI. Fixes #10. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Foran committed Mar 9, 2018
1 parent e6bf439 commit dba6a11
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 81 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -21,5 +21,6 @@ before_install:
- sudo apt-get install -y liblua5.1-0-dev bazel

script:
- bazel run @cpplint_archive//:cpplint -- $(find $(pwd) | grep -E "[.](h|cc|cpp)$")
- bazel build //...
- bazel test //... --test_output=streamed
10 changes: 10 additions & 0 deletions src/lib/levelmodel/rdl.cc
Expand Up @@ -14,6 +14,16 @@

using ::DESCENT_BOT::SRC::LIB::LOG::global_Log;
using ::DESCENT_BOT::SRC::LIB::LOG::LogType;
using ::DESCENT_BOT::SRC::LIB::MATH::DESCENT_SHORTFIXED;
using ::std::cout;
using ::std::dec;
using ::std::endl;
using ::std::hex;
using ::std::ios;
using ::std::ios_base;
using ::std::istream;
using ::std::ostream;
using ::std::string;

namespace DESCENT_BOT {
namespace SRC {
Expand Down
39 changes: 21 additions & 18 deletions src/lib/levelmodel/rdl.h
Expand Up @@ -32,11 +32,12 @@ namespace LIB {
namespace LEVELMODEL {

typedef struct DESCENT_VERTEX {
DESCENT_FIXED x, y, z;
::DESCENT_BOT::SRC::LIB::MATH::DESCENT_FIXED x, y, z;

private:
friend class CRdl;
friend istream &operator>>(istream &input, DESCENT_VERTEX &vertex);
friend ::std::istream &operator>>(::std::istream &input,
DESCENT_VERTEX &vertex);
} DESCENT_VERTEX;

typedef struct DESCENT_CUBE {
Expand All @@ -53,13 +54,13 @@ typedef struct DESCENT_CUBE {
char energyCenterNumber;
int16_t value;
} energyCenter;
DESCENT_SHORTFIXED staticLight;
::DESCENT_BOT::SRC::LIB::MATH::DESCENT_SHORTFIXED staticLight;
unsigned char walls[6];

private:
friend class CRdl;
friend istream &operator>>(istream &input, DESCENT_CUBE &cube);
friend ostream &operator<<(ostream &output, DESCENT_CUBE &cube);
friend ::std::istream &operator>>(::std::istream &input, DESCENT_CUBE &cube);
friend ::std::ostream &operator<<(::std::ostream &output, DESCENT_CUBE &cube);
} DESCENT_CUBE;

typedef struct RDL_HEADER {
Expand All @@ -71,8 +72,8 @@ typedef struct RDL_HEADER {

private:
friend class CRdl;
friend istream &operator>>(istream &input, RDL_HEADER &header);
friend ostream &operator<<(ostream &output, RDL_HEADER &header);
friend ::std::istream &operator>>(::std::istream &input, RDL_HEADER &header);
friend ::std::ostream &operator<<(::std::ostream &output, RDL_HEADER &header);
} RDL_HEADER;

typedef struct RDL_GAMEDATA_HEADER {
Expand Down Expand Up @@ -116,35 +117,37 @@ typedef struct RDL_GAMEDATA_HEADER {

private:
friend class CRdl;
friend istream &operator>>(istream &input, RDL_GAMEDATA_HEADER &header);
friend ostream &operator<<(ostream &output, RDL_GAMEDATA_HEADER &header);
friend ::std::istream &operator>>(::std::istream &input,
RDL_GAMEDATA_HEADER &header);
friend ::std::ostream &operator<<(::std::ostream &output,
RDL_GAMEDATA_HEADER &header);
} RDL_GAMEDATA_HEADER;

class CRdl : public CFile {
public:
CRdl();
explicit CRdl(const string &filename);
CRdl(const CHog &hog, const string &filename);
CRdl(const string &hog, const string &filename);
explicit CRdl(const ::std::string &filename);
CRdl(const CHog &hog, const ::std::string &filename);
CRdl(const ::std::string &hog, const ::std::string &filename);
CRdl(const CRdl &source);
~CRdl();

CRdl &operator=(const CRdl &source);

void Reset();
void Load(const string &filename);
void Load(const CHog &hog, const string &filename);
void Load(const string &hog, const string &filename);
void Load(const ::std::string &filename);
void Load(const CHog &hog, const ::std::string &filename);
void Load(const ::std::string &hog, const ::std::string &filename);

private:
RDL_HEADER mHeader;
vector<DESCENT_VERTEX> mDescentVerticies;
vector<DESCENT_CUBE> mDescentCubes;
::std::vector<DESCENT_VERTEX> mDescentVerticies;
::std::vector<DESCENT_CUBE> mDescentCubes;
RDL_GAMEDATA_HEADER mGameDataHeader;

void Init();
void doLoad();
friend istream &operator>>(istream &input, CRdl &rdl);
friend ::std::istream &operator>>(::std::istream &input, CRdl &rdl);
};

} // namespace LEVELMODEL
Expand Down
73 changes: 42 additions & 31 deletions src/lib/math/math.cc
@@ -1,57 +1,68 @@
/****************************************************
* This work is licensed under the Creative
* Commons Attribution-NonCommercial-ShareAlike
* 3.0 Unported License. To view a copy of this
* license, visit
* http://creativecommons.org/licenses/by-nc-sa/3.0/
* or send a letter to Creative Commons, 444
* Castro Street, Suite 900, Mountain View,
* California, 94041, USA.
* Copyright 2018 Ben M. Ward
*
* This work is licensed under the Creative
* Commons Attribution-NonCommercial-ShareAlike
* 3.0 Unported License. To view a copy of this
* license, visit
* http://creativecommons.org/licenses/by-nc-sa/3.0/
* or send a letter to Creative Commons, 444
* Castro Street, Suite 900, Mountain View,
* California, 94041, USA.
***************************************************/
#include "math.h"
#include "src/lib/math/math.h"

float DESCENT_FIXED::get_Value()
{
return static_cast<double>(((float)value.raw) / 65536.0);
using ::std::istream;
using ::std::ostream;

namespace DESCENT_BOT {
namespace SRC {
namespace LIB {
namespace MATH {

float DESCENT_FIXED::get_Value() {
return static_cast<double>((static_cast<float>(value.raw)) / 65536.0);
}

void DESCENT_FIXED::set_Value(float f)
{
value.raw = static_cast<int>(f * 65536);
void DESCENT_FIXED::set_Value(float f) {
value.raw = static_cast<int>(f * 65536);
}

void DESCENT_FIXED::set_Value(int i)
{
value.parts.hi = i;
value.parts.lo = 0;
void DESCENT_FIXED::set_Value(int i) {
value.parts.hi = i;
value.parts.lo = 0;
}

/********************************
* This method compartmentalizes
* the loading of fixed data types
*******************************/
istream &operator>>(istream &input, DESCENT_FIXED &fixed)
{
input.read((char *)&fixed.value.raw, sizeof(fixed.value.raw));
return input;
istream &operator>>(istream &input, DESCENT_FIXED &fixed) {
input.read(reinterpret_cast<char *>(&fixed.value.raw),
sizeof(fixed.value.raw));
return input;
}

/********************************
* This method compartmentalizes
* the displaying of fixed data types
*******************************/
ostream &operator<<(ostream &output, DESCENT_FIXED &fixed)
{
output << fixed.get_Value();
return output;
ostream &operator<<(ostream &output, DESCENT_FIXED &fixed) {
output << fixed.get_Value();
return output;
}

/********************************
* This method compartmentalizes
* the loading of fixed data types
*******************************/
istream &operator>>(istream &input, DESCENT_SHORTFIXED &fixed)
{
input.read((char *)&fixed.value.raw, sizeof(fixed.value.raw));
return input;
istream &operator>>(istream &input, DESCENT_SHORTFIXED &fixed) {
input.read(reinterpret_cast<char *>(&fixed.value.raw),
sizeof(fixed.value.raw));
return input;
}

} // namespace MATH
} // namespace LIB
} // namespace SRC
} // namespace DESCENT_BOT
77 changes: 45 additions & 32 deletions src/lib/math/math.h
@@ -1,4 +1,6 @@
/****************************************************
* Copyright 2018 Ben M. Ward
*
* This work is licensed under the Creative
* Commons Attribution-NonCommercial-ShareAlike
* 3.0 Unported License. To view a copy of this
Expand All @@ -8,47 +10,58 @@
* Castro Street, Suite 900, Mountain View,
* California, 94041, USA.
***************************************************/
#ifndef __MATH_H__
#define __MATH_H__
#ifndef SRC_LIB_MATH_MATH_H_
#define SRC_LIB_MATH_MATH_H_

#include <iostream>

using namespace std;
namespace DESCENT_BOT {
namespace SRC {
namespace LIB {
namespace MATH {

/// This structure supports Long Fixed point math
typedef struct DESCENT_FIXED
{
union {
int raw;
struct {
short hi;
unsigned short lo;
} parts;
} value;
float get_Value();
void set_Value(float f);
void set_Value(int i);
typedef struct DESCENT_FIXED {
union {
int raw;
struct {
int16_t hi;
uint16_t lo;
} parts;
} value;
float get_Value();
void set_Value(float f);
void set_Value(int i);

private:
friend struct DESCENT_VERTEX;
friend class CRdl;
friend istream &operator>>(istream &input, DESCENT_FIXED &fixed);
friend ostream &operator<<(ostream &output, DESCENT_FIXED &fixed);
friend struct DESCENT_VERTEX;
friend class CRdl;
friend ::std::istream &operator>>(::std::istream &input,
DESCENT_FIXED &fixed);
friend ::std::ostream &operator<<(::std::ostream &output,
DESCENT_FIXED &fixed);
} DESCENT_FIXED;

/// This structure supports Short Fixed point math
typedef struct DESCENT_SHORTFIXED
{
union {
short raw;
struct {
signed hi: 4;
unsigned lo: 12;
} parts;
} value;
typedef struct DESCENT_SHORTFIXED {
union {
int16_t raw;
struct {
signed hi: 4;
unsigned lo: 12;
} parts;
} value;

private:
friend struct DESCENT_VERTEX;
friend class CRdl;
friend istream &operator>>(istream &input, DESCENT_SHORTFIXED &fixed);
friend struct DESCENT_VERTEX;
friend class CRdl;
friend ::std::istream &operator>>(::std::istream &input,
DESCENT_SHORTFIXED &fixed);
} DESCENT_SHORTFIXED;

#endif
} // namespace MATH
} // namespace LIB
} // namespace SRC
} // namespace DESCENT_BOT

#endif // SRC_LIB_MATH_MATH_H_

0 comments on commit dba6a11

Please sign in to comment.