WORKINGDIR := bind/
-TARGETNAME := pglib.so
+TARGETNAME := libpg.so
TARGETTMP := ${OBJSDIR}${TARGETNAME}
TARGET := ${WORKINGDIR}${TARGETNAME}
# how to link the main target
${TARGETTMP}: ${OBJS}
${Q1}${PRNTFMT} "${CXX}" "$@"
- ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
+ ${Q2}${CXX} -shared ${CXXFLAGS} -o $@ $^ ${LIBS}
# rule to copy tmp target to working directory
${TARGET}: ${TARGETTMP} | ${WORKINGDIR}
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "debug.h"
+
+#include <iostream>
+using std::cerr;
+using std::cout;
+using std::endl;
+
+#include <assert.h>
+
+#include "locks/Mutex.h"
+#include "locks/Autolock.h"
+
+/// ***** Public Methods *****
+
+Mutex muDPF;
+
+void DPF(int level, const char* pstr)
+{
+ Autolock lock(muDPF);
+
+ cout << pstr << endl;
+}
+
+void debug::init()
+{
+ muDPF.init();
+}
+
+void debug::clean()
+{
+ muDPF.clean();
+}
+
+void DASSERT(bool fBreak)
+{
+ assert(fBreak);
+}
+
+/// ***** Private Methods *****
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include <iostream>
+using std::cout;
+using std::cerr;
+using std::endl;
+
+void DPF(int level, const char* pstr);
+
+namespace debug
+{
+ void init();
+ void clean();
+}
+
+void DASSERT(bool fBreak);
+
+// comment out when not debugging
+#define DEBUGGING
+
+
+#endif // DEBUG_H
NEWSRCS := # insure blank
NEWSRCS += Vector2.cpp
+NEWSRCS += mathw.cpp
+NEWSRCS += debug.cpp
NEWDIRS := # insure blank
+NEWDIRS += locks/
+
# Post dir setup
CURDIR :=
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Autolock.h"
+
+#include "Mutex.h"
+
+/// ***** Constructors/Destructors *****
+Autolock::Autolock(Mutex& mu)
+ : m_mu(mu)
+{
+ Lock();
+}
+
+Autolock::~Autolock()
+{
+ Unlock();
+}
+
+void Autolock::Lock()
+{
+ m_mu.Lock();
+}
+
+void Autolock::Unlock()
+{
+ m_mu.Unlock();
+}
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef AUTOLOCK_H
+#define AUTOLOCK_H
+
+class Mutex;
+
+/// ***** Header Class *****
+class Autolock
+{
+public:
+ Autolock(Mutex& mu);
+ ~Autolock();
+
+ void Lock();
+ void Unlock();
+
+// hide copying methods!
+private:
+ Autolock(const Autolock&);
+ const Autolock& operator ==(const Autolock&);
+
+private:
+ Mutex& m_mu;
+};
+
+/// ***** Header Methods *****
+
+#endif // AUTOLOCK_H
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Mutex.h"
+#include "debug.h"
+
+#include <SDL/SDL.h>
+
+Mutex::Mutex()
+ : m_pSDL_mutex(NULL)
+{
+
+}
+Mutex::~Mutex()
+{
+
+}
+
+void Mutex::init()
+{
+ m_pSDL_mutex = SDL_CreateMutex();
+}
+void Mutex::clean()
+{
+ SDL_DestroyMutex(m_pSDL_mutex);
+ m_pSDL_mutex = NULL;
+}
+
+bool Mutex::IsValid()
+{
+ return NULL != m_pSDL_mutex;
+}
+
+void Mutex::Lock()
+{
+ DASSERT(IsValid());
+
+ SDL_mutexP(m_pSDL_mutex);
+ m_uiThreadID = SDL_ThreadID();
+}
+void Mutex::Unlock()
+{
+ DASSERT(IsValid());
+
+ DASSERT(m_uiThreadID == SDL_ThreadID());
+ SDL_mutexV(m_pSDL_mutex);
+}
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef MUTEX_H
+#define MUTEX_H
+
+/// ***** Header Class *****
+
+class SDL_mutex;
+
+class Mutex
+{
+public:
+ Mutex();
+ ~Mutex();
+
+ void init();
+ void clean();
+
+ bool IsValid();
+
+ void Lock();
+ void Unlock();
+
+// hide copying methods!
+private:
+ Mutex(const Mutex&);
+ const Mutex& operator ==(const Mutex&);
+
+private:
+ SDL_mutex* m_pSDL_mutex;
+ unsigned int m_uiThreadID;
+};
+
+#endif // MUTEX_H
--- /dev/null
+NEWSRCS := # insure blank
+
+NEWSRCS += Autolock.cpp
+NEWSRCS += Mutex.cpp
+
+
+# Post dir setup
+
+CURDIR := locks/
+
+NEWSRCS := $(addprefix ${CURDIR},${NEWSRCS})
+NEWOBJS := ${NEWSRCS:.cpp=.o}
+NEWDEPS := ${NEWSRCS:.cpp=.d}
+
+# Append to lists
+
+SRCS += ${NEWSRCS}
+OBJS += $(addprefix ${OBJSDIR},${NEWOBJS})
+DEPS += $(addprefix ${DEPSDIR},${NEWDEPS})
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mathw.h"
+
+
+/// ***** Public Methods *****
+
+int mod(int x, int y)
+{
+ return x % y + (x < 0 ? y : 0);
+}
+
+// Vector2 Math
+
+Vector2 vectorToLine
+(
+ const Vector2& vec,
+ float x1,
+ float y1,
+ float x2,
+ float y2
+)
+{
+ float lineSize = (float) sqrt((x1 - x2) * (x1 - x2)
+ + (y1 - y2) * (y1 - y2));
+ if (lineSize == 0)
+ return Vector2(x1 - vec.m_fX, y1 - vec.m_fY);
+
+ float u = ((vec.m_fX - x1) * (x2 - x1)
+ + (vec.m_fY - y1) * (y2 - y1)) / (lineSize * lineSize);
+
+ if (u < 0)
+ return Vector2(x1 - vec.m_fX, y1 - vec.m_fY);
+ else if (u > 1)
+ return Vector2(x2 - vec.m_fX, y2 - vec.m_fY);
+ else
+ {
+ float ix = x1 + u * (x2 - x1);
+ float iy = y1 + u * (y2 - y1);
+ return Vector2(ix - vec.m_fX, iy - vec.m_fY);
+ }
+}
+
+Vector2 perp(const Vector2& vec)
+{
+ return Vector2(-vec.m_fY, vec.m_fX);
+}
+
+float dot(const Vector2& vec1, const Vector2& vec2)
+{
+ return vec1.m_fX * vec2.m_fX + vec1.m_fY * vec2.m_fY;
+}
+
+//TODO float Vector2::projectionCoeff(const Vector2* vec) const;
+//TODO Vector2* Vector2::projection(const Vector2* vec) const;
+
--- /dev/null
+/*
+ * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MATHW_H
+#define MATHW_H
+
+#include <math.h>
+#include "Vector2.h"
+
+
+/// ***** Public Variables *****
+
+static const float PI = 3.1415926535897;
+
+/// ***** Header Methods *****
+
+int mod(int, int);
+
+/// Vector2 Math
+
+Vector2 vectorToLine
+(
+ const Vector2& vec,
+ float x1,
+ float y1,
+ float x2,
+ float y2
+);
+
+//Vector2 lineIntersection(Vector2&, Vector2&, Vector2&, Vector2&) const;
+
+//void Rotate(float rads);
+
+float dot(const Vector2&, const Vector2&);
+Vector2 perp(const Vector2&);
+
+//TODO float projectionCoeff(const Vector2&, const Vector2&) const;
+//TODO void projection(const Vector2&, const Vector2&);
+
+#endif // MATHW_H