Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DDunda committed Aug 2, 2020
0 parents commit bcb4bce
Show file tree
Hide file tree
Showing 26 changed files with 3,187 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Debug
Release
x64
3 changes: 3 additions & 0 deletions AbstractedAccess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "AbstractedAccess.h"

std::vector<Updater*> Updater::sources = std::vector<Updater*>();
284 changes: 284 additions & 0 deletions AbstractedAccess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
#pragma once

#include <vector>

struct ValueContainer {
size_t ownerships;
ValueContainer() {
ownerships = 1;
}
void addPtr() {
ownerships++;
}
void removePtr() {
ownerships--;
}
};

template<class T>
class EasyPointer {
public:
ValueContainer* internalPtr = NULL;
T* ptr = NULL;

EasyPointer() {}
EasyPointer(T* val) : internalPtr(new ValueContainer()), ptr(val) { }
EasyPointer(const EasyPointer<T>& val) : internalPtr(val.internalPtr), ptr(val.ptr) {
internalPtr->addPtr();
}
template <class T2>
EasyPointer(const EasyPointer<T2>& val) : internalPtr(val.internalPtr), ptr((T*)val.ptr) {
internalPtr->addPtr();
}
~EasyPointer() {
RemovePointer();
}

T& operator* ()
{
return *ptr;
}
T* operator-> ()
{
return ptr;
}
operator T* () {
return ptr;
}

void operator= (const EasyPointer<T>& p) {
RemovePointer();

internalPtr = p.internalPtr;
ptr = p.ptr;

if (internalPtr != NULL) internalPtr->addPtr();
else ptr = NULL;
}
template <class T2>
void operator= (const EasyPointer<T2>& p) {
RemovePointer();

internalPtr = p.internalPtr;
ptr = (T*)p.ptr;

if (internalPtr != NULL) internalPtr->addPtr();
else ptr = NULL;
}

bool isSet() {
return internalPtr != NULL;
}
void RemovePointer() {
if (internalPtr == NULL) return;

internalPtr->removePtr();

if (internalPtr->ownerships == 0) {
delete ptr;
delete internalPtr;
}
internalPtr = NULL;
ptr = NULL;
}
};

template <class T>
class GetVal {
public:
virtual T Get() = 0;
};

template <class T>
class SetVal {
public:
virtual void Set(T input) = 0;
};

class Updater {
private:
static std::vector<Updater*> sources;
public:
Updater() {
sources.push_back(this);
}
~Updater() {
auto it = std::find(sources.begin(), sources.end(), this);
sources.erase(it, it + 1);
}
virtual void reset() {}
virtual void frameUpdate() {}

static void updateAllSources() {
for (auto s : sources) s->frameUpdate();
}
};

template <class T>
class Source : public GetVal<T>, public Updater {};

template <class T>
class Val : public Source<float>, public SetVal<T> {
private:
T val;
public:
Val(T v) {
val = v;
}
T Get() {
return val;
}
void Set(T input) {
val = input;
};
void reset() {}
};

template <class T>
class pVal : public Source<float>, public SetVal<T> {
private:
T* val;
public:
pVal(T* v) {
val = v;
}
T Get() {
return *val;
}
T& Get() {
return *val;
}
void Set(T input) {
*val = input;
}
void reset() {}
};

typedef Val<float> fVal;
typedef EasyPointer<Source<float>> epSource;

/*#pragma once
template <class T>
class GetVal {
public:
virtual T Get() {
return T();
};
};
template <class T>
class SetVal {
public:
virtual void Set(T input) = 0;
};
template <class T>
class Source : public GetVal<T> {
public:
virtual void reset() = 0;
};
template <class T>
class Val : public Source<T>, public SetVal<T> {
private:
T val;
public:
Val(T v) {
val = v;
}
T Get() {
return val;
}
void Set(T input) {
val = input;
};
void reset() {}
};
template <class T>
class pVal : public Source<T>, public SetVal<T> {
private:
T* val;
public:
pVal(T* v) {
val = v;
}
T Get() {
return *val;
}
T& Get() {
return *val;
}
void Set(T input) {
*val = input;
}
void reset() {}
};
template<class T>
struct ValueContainer {
T* val;
size_t ownerships;
ValueContainer(T* val) {
this->val = val;
ownerships = 1;
}
~ValueContainer() {
delete val;
}
void addPtr() {
ownerships++;
}
void removePtr() {
ownerships--;
if (ownerships == 0) delete this;
}
};
template<class T>
class EasyPointer {
public:
ValueContainer<T>* internalPtr = NULL;
EasyPointer() {}
EasyPointer(T* val) {
internalPtr = new ValueContainer<T>(val);
internalPtr->addPtr();
}
template <class T2>
EasyPointer(EasyPointer<T2>& val) {
internalPtr = (ValueContainer<T>*)val.internalPtr;
internalPtr->addPtr();
}
~EasyPointer() {
if (internalPtr == NULL) return;
internalPtr->removePtr();
internalPtr = NULL;
}
void NewPointer(T* val) {
if (internalPtr != NULL) internalPtr->removePtr();
internalPtr = new ValueContainer<T>(val);
}
void NewPointer() {
NewPointer(new T);
}
T& operator* ()
{
return *internalPtr->val;
}
T* operator-> ()
{
return internalPtr->val;
}
void operator= (const EasyPointer<T>& D) {
if (internalPtr != NULL) internalPtr->removePtr();
internalPtr = D.internalPtr;
if (internalPtr != NULL) internalPtr->addPtr();
}
bool isSet() {
return !(internalPtr == NULL);
}
};*/
37 changes: 37 additions & 0 deletions Generic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <SDL.h>
#include "AbstractedAccess.h"

static constexpr bool InBounds(SDL_Rect bounds, int x, int y) {
return
x >= bounds.x &&
x < bounds.x + bounds.w &&
y >= bounds.y &&
y < bounds.y + bounds.h;
}
static constexpr bool InBounds(SDL_Rect bounds, SDL_Point coord) { return InBounds(bounds, coord.x, coord.y); }

SDL_Rect ToRect(SDL_FRect rect) {
return { (int)rect.x, (int)rect.y, (int)rect.w, (int)rect.h };
}

template <class T>
using ep = EasyPointer<T>;

struct frame {
SDL_FPoint parentRelativeOrigin; // Origin point within parent
SDL_FPoint selfRelativeOrigin; // Origin point within own rect

SDL_FPoint relativeScale; // Scale compared to parent

SDL_FPoint absoluteScale; // A constant scale, added to the relative scale
SDL_FPoint absoluteOffset; // Rect offset from origin

frame* parent = NULL;
};

struct sprite {
SDL_Rect src;
SDL_Texture** texture;
};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 DDunda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions SDL2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!include
!lib
2 changes: 2 additions & 0 deletions SDL2/include/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
4 changes: 4 additions & 0 deletions SDL2/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!x64
!x86
2 changes: 2 additions & 0 deletions SDL2/lib/x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions SDL2/lib/x86/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
4 changes: 4 additions & 0 deletions SDL2_image/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!include
!lib
2 changes: 2 additions & 0 deletions SDL2_image/include/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
4 changes: 4 additions & 0 deletions SDL2_image/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!x64
!x86
Loading

0 comments on commit bcb4bce

Please sign in to comment.