Started on common and core packages.

This commit is contained in:
2016-03-26 15:49:05 -05:00
parent 2434a43cec
commit 807d0397a1
39 changed files with 1849 additions and 0 deletions

19
src/common/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 2.8.8)
add_library(
NostalgiaCommon OBJECT
bounds.cpp
memops.cpp
point.cpp
)
#install(TARGETS NostalgiaCommon DESTINATION lib)
install(
FILES
bounds.hpp
common.hpp
memops.hpp
point.hpp
DESTINATION
include/wombat/common
)

41
src/common/bounds.cpp Normal file
View File

@ -0,0 +1,41 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "bounds.hpp"
namespace wombat {
namespace common {
Bounds::Bounds() {
}
bool Bounds::intersects(Bounds o) const {
return o.x2() >= X && x2() >= o.X && o.y2() >= Y && y2() >= o.Y;
}
bool Bounds::contains(int x, int y) const {
return x >= X && y >= Y && x <= x2() && y <= y2();
}
int Bounds::x2() const {
return X + Width;
}
int Bounds::y2() const {
return Y + Height;
}
Point Bounds::pt1() {
return Point(X, Y);
}
Point Bounds::pt2() {
return Point(x2(), y2());
}
}
}

44
src/common/bounds.hpp Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef WOMBAT_COMMON_BOUNDS_HPP
#define WOMBAT_COMMON_BOUNDS_HPP
#include "point.hpp"
namespace wombat {
namespace common {
class Bounds {
public:
int X = 0;
int Y = 0;
int Width = 0;
int Height = 0;
/**
* Constructor
*/
Bounds();
bool intersects(Bounds other) const;
bool contains(int x, int y) const;
int x2() const;
int y2() const;
Point pt1();
Point pt2();
};
}
}
#endif

15
src/common/common.hpp Normal file
View File

@ -0,0 +1,15 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef WOMBAT_COMMON_COMMON_HPP
#define WOMBAT_COMMON_COMMON_HPP
#include "bounds.hpp"
#include "flyweight.hpp"
#include "point.hpp"
#endif

29
src/common/memops.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "memops.hpp"
namespace nostalgia {
namespace common {
void memcpy(void *src, void *dest, int size) {
char *srcBuf = (char*) src;
char *dstBuf = (char*) dest;
for (int i = 0; i < size; i++) {
dstBuf[i] = (char) srcBuf[i];
}
}
void memset(void *ptr, char val, int size) {
char *buf = (char*) ptr;
for (int i = 0; i < size; i++) {
buf[i] = val;
}
}
}
}

21
src/common/memops.hpp Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef MEMPHIS_MEMOPS_HPP
#define MEMPHIS_MEMOPS_HPP
namespace nostalgia {
namespace common {
void memcpy(void *src, void *dest, int size);
void memset(void *ptr, char val, int size);
}
}
#endif

125
src/common/point.cpp Normal file
View File

@ -0,0 +1,125 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "point.hpp"
namespace wombat {
namespace common {
Point::Point() {
}
Point::Point(int x, int y) {
X = x;
Y = y;
}
Point Point::operator+(common::Point p) const {
p.X += X;
p.Y += Y;
return p;
}
Point Point::operator-(common::Point p) const {
auto out = *this;
out.X -= p.X;
out.Y -= p.Y;
return out;
}
Point Point::operator*(common::Point p) const {
p.X *= X;
p.Y *= Y;
return p;
}
Point Point::operator/(common::Point p) const {
auto out = *this;
out.X /= p.X;
out.Y /= p.Y;
return out;
}
Point Point::operator+=(common::Point p) {
X += p.X;
Y += p.Y;
return *this;
}
Point Point::operator-=(common::Point p) {
X -= p.X;
Y -= p.Y;
return *this;
}
Point Point::operator*=(common::Point p) {
X *= p.X;
Y *= p.Y;
return *this;
}
Point Point::operator/=(common::Point p) {
X /= p.X;
Y /= p.Y;
return *this;
}
Point Point::operator+(int i) const {
auto out = *this;
out.X += i;
out.Y += i;
return out;
}
Point Point::operator-(int i) const {
auto out = *this;
out.X -= i;
out.Y -= i;
return out;
}
Point Point::operator*(int i) const {
auto out = *this;
out.X *= i;
out.Y *= i;
return out;
}
Point Point::operator/(int i) const {
auto out = *this;
out.X /= i;
out.Y /= i;
return out;
}
Point Point::operator+=(int i) {
X += i;
Y += i;
return *this;
}
Point Point::operator-=(int i) {
X -= i;
Y -= i;
return *this;
}
Point Point::operator*=(int i) {
X *= i;
Y *= i;
return *this;
}
Point Point::operator/=(int i) {
X /= i;
Y /= i;
return *this;
}
}
}

62
src/common/point.hpp Normal file
View File

@ -0,0 +1,62 @@
/*
* Copyright 2016 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef WOMBAT_COMMON_POINT_HPP
#define WOMBAT_COMMON_POINT_HPP
namespace wombat {
namespace common {
class Point {
public:
int X = 0;
int Y = 0;
Point();
Point(int x, int y);
Point operator+(common::Point p) const;
Point operator-(common::Point p) const;
Point operator*(common::Point p) const;
Point operator/(common::Point p) const;
Point operator+=(common::Point p);
Point operator-=(common::Point p);
Point operator*=(common::Point p);
Point operator/=(common::Point p);
Point operator+(int i) const;
Point operator-(int i) const;
Point operator*(int i) const;
Point operator/(int i) const;
Point operator+=(int i);
Point operator-=(int i);
Point operator*=(int i);
Point operator/=(int i);
};
}
}
#endif