summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2002-12-25 02:36:16 +0000
committerpixel <pixel>2002-12-25 02:36:16 +0000
commit05b3214cc4af88977e09163ce8e3b6cc7256cebe (patch)
tree3c93af573848f35ed7508db2a7c91936714e0d8e /lib
parent041b4dea4bf8413835ee8a7d0520ab5016c69799 (diff)
Added SDL_RWops things
Diffstat (limited to 'lib')
-rw-r--r--lib/engine.cc70
1 files changed, 69 insertions, 1 deletions
diff --git a/lib/engine.cc b/lib/engine.cc
index 6e3f303..bcf5dc0 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -1,4 +1,3 @@
-#include <SDL/SDL.h>
#include "engine.h"
#define _(x) x
@@ -23,3 +22,72 @@ int mogltk::engine::setup() throw(GeneralException) {
int mogltk::engine::GetInited() {
return inited;
}
+
+class embedRWops : public Base {
+ public:
+ embedRWops(Handle *);
+ ~embedRWops();
+ int seek(int, int);
+ int read(void *, int, int);
+ int write(const void *, int, int);
+ private:
+ Handle * h;
+};
+
+embedRWops::embedRWops(Handle * ah) : h(new Handle(*ah)) {}
+
+embedRWops::~embedRWops() {
+ delete h;
+}
+
+int embedRWops::seek(int offset, int whence) {
+ return h->seek(offset, whence);
+}
+
+int embedRWops::read(void * ptr, int size, int num) {
+ return h->read(ptr, size * num);
+}
+
+int embedRWops::write(const void * ptr, int size, int num) {
+ return h->write(ptr, size * num);
+}
+
+static int embedRWseek(SDL_RWops * context, int offset, int whence) {
+ if (context->hidden.unknown.data1)
+ return ((embedRWops *)(context->hidden.unknown.data1))->seek(offset, whence);
+ return -1;
+}
+
+static int embedRWread(SDL_RWops * context, void * ptr, int size, int num) {
+ if (context->hidden.unknown.data1)
+ return ((embedRWops *)(context->hidden.unknown.data1))->read(ptr, size, num);
+ return -1;
+}
+
+static int embedRWwrite(SDL_RWops * context, const void * ptr, int size, int num) {
+ if (context->hidden.unknown.data1)
+ return ((embedRWops *)(context->hidden.unknown.data1))->write(ptr, size, num);
+ return -1;
+}
+
+static int embedRWclose(SDL_RWops * context) {
+ if (context->hidden.unknown.data1) {
+ delete ((embedRWops *)(context->hidden.unknown.data1));
+ return 0;
+ }
+ return -1;
+}
+
+SDL_RWops * mogltk::engine::RWFromHandle(Handle * h) throw (GeneralException) {
+ SDL_RWops * r = 0;
+ if (h) {
+ if (!(r = SDL_AllocRW()))
+ throw GeneralException(_("Couldn't allocate memory for SDL_RWops"));
+ r->hidden.unknown.data1 = (void *) new embedRWops(h);
+ r->seek = embedRWseek;
+ r->read = embedRWread;
+ r->write = embedRWwrite;
+ r->close = embedRWclose;
+ }
+ return r;
+}