commit 1df28151
Added part of new libary
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@106 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
diff --git a/source/code/CppSdl/CppSdlCommon.cpp b/source/code/CppSdl/CppSdlCommon.cpp
new file mode 100644
index 0000000..bc8d942
--- /dev/null
+++ b/source/code/CppSdl/CppSdlCommon.cpp
@@ -0,0 +1,33 @@
+/*
+ * File: CppSdlCommon.cpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 20:12
+ */
+
+#include "CppSdlCommon.hpp"
+
+
+namespace CppSdl {
+
+CppSdlCommon* CppSdlCommon::instance = NULL;
+
+CppSdlCommon* CppSdlCommon::getInstance() {
+ if(!instance) {
+ instance = new CppSdlCommon();
+ return instance;
+ } else
+ return instance;
+}
+void CppSdlCommon::setTime(long time) {
+ this->time = time;
+}
+long CppSdlCommon::getTime() const {
+ return time;
+}
+
+CppSdlCommon::CppSdlCommon() {
+}
+
+
+} //namespace
\ No newline at end of file
diff --git a/source/code/CppSdl/CppSdlCommon.hpp b/source/code/CppSdl/CppSdlCommon.hpp
new file mode 100644
index 0000000..b0c2f78
--- /dev/null
+++ b/source/code/CppSdl/CppSdlCommon.hpp
@@ -0,0 +1,27 @@
+/*
+ * File: CppSdlCommon.hpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 20:12
+ */
+
+#ifndef _CPPSDLCOMMON_HPP
+#define _CPPSDLCOMMON_HPP
+
+namespace CppSdl {
+class CppSdlCommon {
+public:
+ CppSdlCommon* getInstance();
+ void setTime(long time);
+ long getTime() const;
+protected:
+ CppSdlCommon();
+
+private:
+ static CppSdlCommon *instance;
+ long time;
+};
+}//namespace
+
+#endif /* _CPPSDLCOMMON_HPP */
+
diff --git a/source/code/CppSdl/CppSdlException.cpp b/source/code/CppSdl/CppSdlException.cpp
index f01c0db..a05c6da 100644
--- a/source/code/CppSdl/CppSdlException.cpp
+++ b/source/code/CppSdl/CppSdlException.cpp
@@ -9,12 +9,10 @@
namespace CppSdl {
-CppSdlException::CppSdlException() {
- message = "An CppSdlException";
-}
-
-CppSdlException::CppSdlException(std::string msg) {
- message = msg;
+CppSdlException::CppSdlException(Subsystem subsystem,long errorNumber, std::string msg) {
+ _errorNumber = errorNumber;
+ _message = msg;
+ _subsystem = subsystem;
}
CppSdlException::CppSdlException(const CppSdlException& orig) {
@@ -24,7 +22,15 @@ CppSdlException::CppSdlException(const CppSdlException& orig) {
//}
const char* CppSdlException::what() const throw() {
- return message.c_str();
+ return _message.c_str();
+}
+
+long CppSdlException::GetErrorNumber() {
+ return _errorNumber;
+}
+
+Subsystem CppSdlException::GetSubSystem() {
+ return _subsystem;
}
}
\ No newline at end of file
diff --git a/source/code/CppSdl/CppSdlException.hpp b/source/code/CppSdl/CppSdlException.hpp
index 7625a20..f4ba246 100644
--- a/source/code/CppSdl/CppSdlException.hpp
+++ b/source/code/CppSdl/CppSdlException.hpp
@@ -10,17 +10,28 @@
#include <string>
+#define CPPSDL_ERROR_DATA 1
+#define CPPSDL_ERROR_INVALID 2
+#define CPPSDL_ERROR_MISSINGFILE 3
+#define CPPSDL_ERROR_NULLPOINTER 4
+
+enum Subsystem {OTHER,IMAGE,TILE,SPRITE,LAYER,SCREEN };
+
namespace CppSdl {
class CppSdlException : std::exception{
public:
- CppSdlException();
- CppSdlException(std::string msg);
+ //CppSdlException();
+ CppSdlException(Subsystem subsystem, long errorNumber, std::string msg);
CppSdlException(const CppSdlException& orig);
virtual ~CppSdlException() throw();
virtual const char* what() const throw();
+ long GetErrorNumber();
+ long GetSubSystem();
private:
- std::string message;
+ std::string _message;
+ long _errorNumber;
+ Subsystem _subsystem;
};
diff --git a/source/code/CppSdl/CppSdlFrame.cpp b/source/code/CppSdl/CppSdlFrame.cpp
new file mode 100644
index 0000000..6a0bd85
--- /dev/null
+++ b/source/code/CppSdl/CppSdlFrame.cpp
@@ -0,0 +1,32 @@
+/*
+ * File: CppSdlFrame.cpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 20:27
+ */
+
+#include "CppSdlFrame.hpp"
+
+namespace CppSdl {
+CppSdlFrame::CppSdlFrame() {
+}
+
+CppSdlFrame::CppSdlFrame(const CppSdlFrame& orig) {
+}
+
+CppSdlFrame::~CppSdlFrame() {
+}
+void CppSdlFrame::SetMilliseconds(long _milliseconds) {
+ this->_milliseconds = _milliseconds;
+}
+long CppSdlFrame::GetMilliseconds() const {
+ return _milliseconds;
+}
+void CppSdlFrame::SetImage(CppSdlImageHolder _image) {
+ this->_image = _image;
+}
+CppSdlImageHolder CppSdlFrame::GetImage() const {
+ return _image;
+}
+
+}//namespace
diff --git a/source/code/CppSdl/CppSdlFrame.hpp b/source/code/CppSdl/CppSdlFrame.hpp
new file mode 100644
index 0000000..0a5cf84
--- /dev/null
+++ b/source/code/CppSdl/CppSdlFrame.hpp
@@ -0,0 +1,32 @@
+/*
+ * File: CppSdlFrame.hpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 20:27
+ */
+
+#ifndef _CPPSDLFRAME_HPP
+#define _CPPSDLFRAME_HPP
+
+#include "CppSdlImageHolder.hpp"
+
+
+namespace CppSdl {
+class CppSdlFrame {
+public:
+ CppSdlFrame();
+ CppSdlFrame(const CppSdlFrame& orig);
+ virtual ~CppSdlFrame();
+ void SetMilliseconds(long _milliseconds);
+ long GetMilliseconds() const;
+ void SetImage(CppSdlImageHolder _image);
+ CppSdlImageHolder GetImage() const;
+private:
+ CppSdlImageHolder _image;
+ long _milliseconds;
+};
+
+} // namespace
+
+#endif /* _CPPSDLFRAME_HPP */
+
diff --git a/source/code/CppSdl/CppSdlImageHolder.cpp b/source/code/CppSdl/CppSdlImageHolder.cpp
index 387ec0d..909ffd2 100644
--- a/source/code/CppSdl/CppSdlImageHolder.cpp
+++ b/source/code/CppSdl/CppSdlImageHolder.cpp
@@ -15,7 +15,7 @@ CppSdlImageHolder::CppSdlImageHolder(std::string filename) {
if(!data)
{
//Here we should throw an exception
- CppSdlException e("Could not read file \""+filename+"\"");
+ CppSdlException e(IMAGE,CPPSDL_ERROR_MISSINGFILE,"Could not read file \""+filename+"\"");
throw e;
}
SDL_GetClipRect(data,&area);
@@ -36,7 +36,7 @@ CppSdlImageHolder::CppSdlImageHolder(char* rawdata, int datasize) {
//The above might fail an return null.
if(!rw)
{
- CppSdlException e("Could not read raw data");
+ CppSdlException e(IMAGE,CPPSDL_ERROR_NULLPOINTER, "Could not read raw data");
throw e;
}
@@ -44,7 +44,7 @@ CppSdlImageHolder::CppSdlImageHolder(char* rawdata, int datasize) {
if(!data)
{
- CppSdlException e("Could not read raw data");
+ CppSdlException e(IMAGE,CPPSDL_ERROR_DATA,"Could not read raw data");
throw e;
}
diff --git a/source/code/CppSdl/CppSdlSprite.cpp b/source/code/CppSdl/CppSdlSprite.cpp
new file mode 100644
index 0000000..ea2888a
--- /dev/null
+++ b/source/code/CppSdl/CppSdlSprite.cpp
@@ -0,0 +1,18 @@
+/*
+ * File: CppSdlSprite.cpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 19:47
+ */
+
+#include "CppSdlSprite.hpp"
+
+CppSdlSprite::CppSdlSprite() {
+}
+
+CppSdlSprite::CppSdlSprite(const CppSdlSprite& orig) {
+}
+
+CppSdlSprite::~CppSdlSprite() {
+}
+
diff --git a/source/code/CppSdl/CppSdlSprite.hpp b/source/code/CppSdl/CppSdlSprite.hpp
new file mode 100644
index 0000000..fd1b2ce
--- /dev/null
+++ b/source/code/CppSdl/CppSdlSprite.hpp
@@ -0,0 +1,21 @@
+/*
+ * File: CppSdlSprite.hpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 19:47
+ */
+
+#ifndef _CPPSDLSPRITE_HPP
+#define _CPPSDLSPRITE_HPP
+
+class CppSdlSprite {
+public:
+ CppSdlSprite();
+ CppSdlSprite(const CppSdlSprite& orig);
+ virtual ~CppSdlSprite();
+private:
+
+};
+
+#endif /* _CPPSDLSPRITE_HPP */
+
diff --git a/source/code/CppSdl/CppSdlTile.cpp b/source/code/CppSdl/CppSdlTile.cpp
new file mode 100644
index 0000000..5997230
--- /dev/null
+++ b/source/code/CppSdl/CppSdlTile.cpp
@@ -0,0 +1,50 @@
+/*
+ * File: CppSdlTile.cpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 19:55
+ */
+
+#include <vector>
+
+#include "CppSdlTile.hpp"
+
+namespace CppSdl {
+CppSdlTile::CppSdlTile() {
+ _collideMode = OFF;
+ _frames.clear();
+}
+
+CppSdlTile::CppSdlTile(const CppSdlTile& orig) {
+ _collideMode = orig->_collideMode;
+ _frames = orig->_frames;
+}
+
+CppSdlTile::~CppSdlTile() {
+}
+
+void CppSdlTile::setCollideMode(CollideMode _collideMode) {
+ this->_collideMode = _collideMode;
+}
+
+CollideMode CppSdlTile::getCollideMode() const {
+ return _collideMode;
+}
+
+void CppSdlTile::addFrame(CppSdlFrame frame) {
+ _frames.push_back(frame);
+}
+
+void CppSdlTile::addFrame(CppSdlImageHolder image, long milliseconds) {
+ CppSdlFrame f;
+ f.SetImage(image);
+ f.SetMilliseconds(milliseconds);
+ addFrame(f);
+}
+
+void CppSdlTile::clearFrames() {
+ _frames.clear();
+}
+
+
+} //namespace
\ No newline at end of file
diff --git a/source/code/CppSdl/CppSdlTile.hpp b/source/code/CppSdl/CppSdlTile.hpp
new file mode 100644
index 0000000..6d5d02c
--- /dev/null
+++ b/source/code/CppSdl/CppSdlTile.hpp
@@ -0,0 +1,38 @@
+/*
+ * File: CppSdlTile.hpp
+ * Author: poul
+ *
+ * Created on 7. december 2010, 19:55
+ */
+
+#ifndef _CPPSDLTILE_HPP
+#define _CPPSDLTILE_HPP
+
+#include "CppSdlFrame.hpp"
+
+
+namespace CppSdl {
+enum CollideMode {OFF,BOX,PIXEL};
+
+class CppSdlTile {
+public:
+ CppSdlTile();
+ CppSdlTile(const CppSdlTile& orig);
+ virtual ~CppSdlTile();
+
+ void addFrame(CppSdlImageHolder image, long milliseconds);
+ void addFrame(CppSdlFrame frame);
+ void clearFrames();
+
+ void draw();
+
+ void setCollideMode(CollideMode _collideMode);
+ CollideMode getCollideMode() const;
+private:
+ CollideMode _collideMode;
+ std::vector<CppSdlFrame> _frames;
+};
+} //namespace
+
+#endif /* _CPPSDLTILE_HPP */
+