aboutsummaryrefslogtreecommitdiff
path: root/drivers/theoraplayer/src/TheoraDataSource.cpp
diff options
context:
space:
mode:
authorJuan Linietsky2014-09-15 11:33:30 -0300
committerJuan Linietsky2014-09-15 11:33:30 -0300
commit8cab401d08f8e25aa9b2dc710204785858ff3dbb (patch)
tree1a4cec868f937fb24d340ee33fbeba2f1c6fa9f2 /drivers/theoraplayer/src/TheoraDataSource.cpp
parent1a2cb755e2d8b9d59178f36702f6dff7235b9088 (diff)
downloadgodot-8cab401d08f8e25aa9b2dc710204785858ff3dbb.tar.gz
godot-8cab401d08f8e25aa9b2dc710204785858ff3dbb.tar.zst
godot-8cab401d08f8e25aa9b2dc710204785858ff3dbb.zip
3D Physics Rework, Other Stuff
-=-=-=-=-=-=-=-=-=-=-=-=-=- 3D Physics: -Fixed "Bounce" parameter in 3D -Fixed bug affecting Area (sometims it would not detect properly) -Vehicle Body has seen heavy work -Added Query API for doing space queries in 3D. Needs some docs though. -Added JOINTS! Adapted Bullet Joints: and created easy gizmos for setting them up: -PinJoint -HingeJoint (with motor) -SliderJoint -ConeTwistJoint -Generic6DOFJoint -Added OBJECT PICKING! based on the new query API. Any physics object now (Area or Body) has the following signals and virtual functions: -input_event (mouse or multitouch input over the body) -mouse_enter (mouse entered the body area) -mouse_exit (mouse exited body area) For Area it needs to be activated manually, as it isn't by default (ray goes thru). Other: -Begun working on Windows 8 (RT) port. Compiles but does not work yet. -Added TheoraPlayer library for improved to-texture and portable video support. -Fixed a few bugs in the renderer, collada importer, collada exporter, etc.
Diffstat (limited to 'drivers/theoraplayer/src/TheoraDataSource.cpp')
-rw-r--r--drivers/theoraplayer/src/TheoraDataSource.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/drivers/theoraplayer/src/TheoraDataSource.cpp b/drivers/theoraplayer/src/TheoraDataSource.cpp
new file mode 100644
index 000000000..6011dc678
--- /dev/null
+++ b/drivers/theoraplayer/src/TheoraDataSource.cpp
@@ -0,0 +1,128 @@
+/************************************************************************************
+This source file is part of the Theora Video Playback Library
+For latest info, see http://libtheoraplayer.googlecode.com
+*************************************************************************************
+Copyright (c) 2008-2014 Kresimir Spes (kspes@cateia.com)
+This program is free software; you can redistribute it and/or modify it under
+the terms of the BSD license: http://opensource.org/licenses/BSD-3-Clause
+*************************************************************************************/
+#include <stdio.h>
+#include <memory.h>
+#include "TheoraDataSource.h"
+#include "TheoraException.h"
+#include "TheoraVideoManager.h"
+#include "TheoraUtil.h"
+
+TheoraDataSource::~TheoraDataSource()
+{
+
+}
+
+TheoraFileDataSource::TheoraFileDataSource(std::string filename)
+{
+ mFilename = filename;
+ mFilePtr = NULL;
+}
+
+TheoraFileDataSource::~TheoraFileDataSource()
+{
+ if (mFilePtr)
+ {
+ fclose(mFilePtr);
+ mFilePtr = NULL;
+ }
+}
+
+void TheoraFileDataSource::openFile()
+{
+ if (mFilePtr == NULL)
+ {
+ mFilePtr=fopen(mFilename.c_str(), "rb");
+ if (!mFilePtr)
+ {
+ std::string msg = "Can't open video file: " + mFilename;
+ th_writelog(msg);
+ throw TheoraGenericException(msg);
+ }
+ fseek(mFilePtr, 0, SEEK_END);
+ mSize = ftell(mFilePtr);
+ fseek(mFilePtr, 0, SEEK_SET);
+ }
+}
+
+int TheoraFileDataSource::read(void* output, int nBytes)
+{
+ if (mFilePtr == NULL) openFile();
+ size_t n = fread(output, 1, nBytes, mFilePtr);
+ return (int) n;
+}
+
+void TheoraFileDataSource::seek(unsigned long byte_index)
+{
+ if (mFilePtr == NULL) openFile();
+ fseek(mFilePtr, byte_index, SEEK_SET);
+}
+
+unsigned long TheoraFileDataSource::size()
+{
+ if (mFilePtr == NULL) openFile();
+ return mSize;
+}
+
+unsigned long TheoraFileDataSource::tell()
+{
+ if (mFilePtr == NULL) return 0;
+ return ftell(mFilePtr);
+}
+
+TheoraMemoryFileDataSource::TheoraMemoryFileDataSource(std::string filename) :
+ mReadPointer(0),
+ mData(0)
+{
+ mFilename=filename;
+ FILE* f=fopen(filename.c_str(),"rb");
+ if (!f) throw TheoraGenericException("Can't open video file: "+filename);
+ fseek(f,0,SEEK_END);
+ mSize=ftell(f);
+ fseek(f,0,SEEK_SET);
+ mData=new unsigned char[mSize];
+ fread(mData,1,mSize,f);
+ fclose(f);
+}
+
+TheoraMemoryFileDataSource::TheoraMemoryFileDataSource(unsigned char* data, long size, const std::string& filename)
+{
+ mFilename = filename;
+ mData = data;
+ mSize = size;
+ mReadPointer = 0;
+}
+
+TheoraMemoryFileDataSource::~TheoraMemoryFileDataSource()
+{
+ if (mData) delete [] mData;
+}
+
+int TheoraMemoryFileDataSource::read(void* output, int nBytes)
+{
+ int n = (int) ((mReadPointer+nBytes <= mSize) ? nBytes : mSize - mReadPointer);
+ if (!n) return 0;
+ memcpy(output, mData + mReadPointer, n);
+ mReadPointer += n;
+ return n;
+}
+
+void TheoraMemoryFileDataSource::seek(unsigned long byte_index)
+{
+ mReadPointer=byte_index;
+}
+
+unsigned long TheoraMemoryFileDataSource::size()
+{
+ return mSize;
+}
+
+unsigned long TheoraMemoryFileDataSource::tell()
+{
+ return mReadPointer;
+}