Bläddra i källkod

Changed sockets back to non-threaded because of bug, touch simulation for mouse event option, option to disable frustum culling in camera, made data public in Texture

Ivan Safrin 13 år sedan
förälder
incheckning
1930a3aa9b

+ 1 - 0
Core/Contents/Include/PolyCamera.h

@@ -125,6 +125,7 @@ namespace Polycode {
 			*/			
 			Material *getScreenShaderMaterial() { return filterShaderMaterial; }
 			
+			bool frustumCulling;
 			
 		protected:
 		

+ 5 - 3
Core/Contents/Include/PolyCoreInput.h

@@ -109,12 +109,14 @@ namespace Polycode {
 		void setKeyState(PolyKEY keyCode, wchar_t code, bool newState, int ticks);
 		void setDeltaPosition(int x, int y);
 		
-		void touchesBegan(std::vector<TouchInfo> touches, int ticks);
-		void touchesMoved(std::vector<TouchInfo> touches, int ticks);
-		void touchesEnded(std::vector<TouchInfo> touches, int ticks);
+		void touchesBegan(TouchInfo touch, std::vector<TouchInfo> touches, int ticks);
+		void touchesMoved(TouchInfo touch, std::vector<TouchInfo> touches, int ticks);
+		void touchesEnded(TouchInfo touch, std::vector<TouchInfo> touches, int ticks);
 				
 		static InputEvent *createEvent(Event *event){ return (InputEvent*)event; }
 		
+		bool simulateTouchWithMouse;
+		
 	protected:
 		
 		std::vector<JoystickInfo> joysticks;

+ 1 - 0
Core/Contents/Include/PolyInputEvent.h

@@ -107,6 +107,7 @@ namespace Polycode {
 		int timestamp;
 		
 		std::vector<TouchInfo> touches;
+		TouchInfo touch;
 		
 		unsigned int joystickDeviceID;
 		float joystickAxisValue;

+ 2 - 2
Core/Contents/Include/PolyTexture.h

@@ -56,7 +56,8 @@ namespace Polycode {
 			int getHeight() const;
 		
 			bool clamp;
-		
+			char *textureData;
+					
 		protected:
 
 			int pixelSize;
@@ -66,7 +67,6 @@ namespace Polycode {
 			int width;
 			int height;
 			String resourcePath;
-			char *textureData;
 			Number scrollOffsetX;
 			Number scrollOffsetY;
 	};

+ 3 - 0
Core/Contents/Source/PolyCamera.cpp

@@ -42,6 +42,7 @@ Camera::Camera(Scene *parentScene) : SceneEntity() {
 	exposureLevel = 1.0f;
 	_hasFilterShader = false;	
 	fovSet = false;
+	frustumCulling = true;
 }
 
 Camera::~Camera() {	
@@ -73,6 +74,8 @@ Number Camera::getFOV() {
 
 
 bool Camera::isSphereInFrustrum(Vector3 pos, Number fRadius) {
+	if(!frustumCulling)
+		return true;
     for( int i = 0; i < 6; ++i )
     {
         if( frustumPlanes[i][0] * pos.x +

+ 33 - 4
Core/Contents/Source/PolyCoreInput.cpp

@@ -42,7 +42,9 @@ namespace Polycode {
 		
 		for(int i=0; i < 512; i++) {
 			keyboardState[i] = 0;
-		}		
+		}
+		
+		simulateTouchWithMouse = false;
 	}
 	
 	CoreInput::~CoreInput() {
@@ -139,6 +141,20 @@ namespace Polycode {
 		else
 			dispatchEvent(evt, InputEvent::EVENT_MOUSEUP);
 		mouseButtons[mouseButton] = state;
+				
+		if(simulateTouchWithMouse && mouseButton == MOUSE_BUTTON1) {
+			TouchInfo touch;
+			touch.position = mousePosition;
+			touch.id = 0;			
+			std::vector<TouchInfo> touches;
+			touches.push_back(touch);
+			
+			if(state) {
+				touchesBegan(touch, touches, ticks);
+			} else {
+				touchesEnded(touch, touches, ticks);			
+			}
+		}
 	}
 	
 	void CoreInput::mouseWheelDown(int ticks) {
@@ -156,6 +172,16 @@ namespace Polycode {
 		mousePosition.y = y;
 		InputEvent *evt = new InputEvent(mousePosition, ticks);
 		dispatchEvent(evt, InputEvent::EVENT_MOUSEMOVE);
+		
+		if(simulateTouchWithMouse && mouseButtons[MOUSE_BUTTON1]) {
+			TouchInfo touch;
+			touch.position = mousePosition;
+			touch.id = 0;			
+			std::vector<TouchInfo> touches;
+			touches.push_back(touch);
+			
+			touchesMoved(touch, touches, ticks);
+		}		
 	}
 	
 	Vector2 CoreInput::getMouseDelta() {
@@ -189,22 +215,25 @@ namespace Polycode {
 		}
 	}
 	
-	void CoreInput::touchesBegan(std::vector<TouchInfo> touches, int ticks) {
+	void CoreInput::touchesBegan(TouchInfo touch, std::vector<TouchInfo> touches, int ticks) {
 		InputEvent *evt = new InputEvent();
+		evt->touch = touch;		
 		evt->touches = touches;
 		evt->timestamp = ticks;
 		dispatchEvent(evt, InputEvent::EVENT_TOUCHES_BEGAN);
 	}
 	
-	void CoreInput::touchesMoved(std::vector<TouchInfo> touches, int ticks) {
+	void CoreInput::touchesMoved(TouchInfo touch, std::vector<TouchInfo> touches, int ticks) {
 		InputEvent *evt = new InputEvent();
+		evt->touch = touch;
 		evt->touches = touches;
 		evt->timestamp = ticks;		
 		dispatchEvent(evt, InputEvent::EVENT_TOUCHES_MOVED);	
 	}
 	
-	void CoreInput::touchesEnded(std::vector<TouchInfo> touches, int ticks) {
+	void CoreInput::touchesEnded(TouchInfo touch, std::vector<TouchInfo> touches, int ticks) {
 		InputEvent *evt = new InputEvent();
+		evt->touch = touch;		
 		evt->touches = touches;
 		evt->timestamp = ticks;		
 		dispatchEvent(evt, InputEvent::EVENT_TOUCHES_ENDED);	

+ 13 - 1
Modules/Contents/Curl/PolycodeDownloader.cpp

@@ -27,6 +27,16 @@ PolycodeDownloader::PolycodeDownloader(String url) : Threaded() {
 	this->url = url;
 	data = (char*)malloc(0);
 	size = 0;
+	returned = false;
+}
+
+bool PolycodeDownloader::writeToFile(String fileName) {
+	FILE *f = fopen(fileName.c_str(), "wb");
+	if(!f)
+		return false;	
+	fwrite(data, 1, size, f);
+	fclose(f);	
+	return true;
 }
 
 void PolycodeDownloader::runThread() {
@@ -39,8 +49,10 @@ void PolycodeDownloader::runThread() {
 	CURLcode curl_res = curl_easy_perform(curl);
 	
 	curl_easy_cleanup(curl);	
-	
+
+	returned = true;	
 	dispatchEvent(new Event(Event::COMPLETE_EVENT), Event::COMPLETE_EVENT);
+
 }
 
 PolycodeDownloader::~PolycodeDownloader() {

+ 7 - 1
Modules/Contents/Curl/PolycodeDownloader.h

@@ -14,9 +14,15 @@ class PolycodeDownloader : public Threaded {
 		
 		String getDataAsString();
 		
+		bool writeToFile(String fileName);
+		
 		char *data;
 		size_t size;
-				
+		
+		bool returned;
+		
+		void *userData;
+		
 	protected:
 		String url;		
 		CURL *curl;

+ 4 - 0
Modules/Contents/Networking/Include/PolyPeer.h

@@ -70,7 +70,11 @@ namespace Polycode {
 		Address address;
 	};
 		
+#if USE_THREADED_SOCKETS == 1		
 	class _PolyExport Peer : public Threaded {
+#else
+	class _PolyExport Peer : public EventDispatcher {
+#endif
 		public:
 			Peer(unsigned int port);
 			~Peer();

+ 5 - 1
Modules/Contents/Networking/Source/PolyPeer.cpp

@@ -36,7 +36,11 @@ void PeerConnection::ackPackets(unsigned int ack) {
 	}
 }
 
-Peer::Peer(unsigned int port) : Threaded() {
+#if USE_THREADED_SOCKETS == 1
+	Peer::Peer(unsigned int port) : Threaded() {
+#else
+	Peer::Peer(unsigned int port) : EventDispatcher() {
+#endif
 	socket = new Socket(port);
 	socket->addEventListener(this, SocketEvent::EVENT_DATA_RECEIVED);
 

+ 1 - 0
Modules/Contents/TUIO/Include/TUIOInputModule.h

@@ -18,6 +18,7 @@ class TUIOEvent {
 	public:
 		std::vector<TouchInfo> touches;		
 		unsigned int type;
+		TouchInfo touch;
 };
 
 class TUIOInputModule : public PolycodeModule, TuioListener {

+ 19 - 4
Modules/Contents/TUIO/Source/TUIOInputModule.cpp

@@ -46,6 +46,10 @@ void TUIOInputModule::addTuioCursor(TuioCursor *tcur) {
 	event.type = InputEvent::EVENT_TOUCHES_BEGAN;
 	event.touches = touches;
 	
+	event.touch.position.x = tcur->getX();
+	event.touch.position.y = tcur->getY();
+	event.touch.id = tcur->getCursorID();
+	
 	CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
 	events.push_back(event);					
 	CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
@@ -68,6 +72,10 @@ void TUIOInputModule::updateTuioCursor(TuioCursor *tcur) {
 	event.type = InputEvent::EVENT_TOUCHES_MOVED;
 	event.touches = touches;
 	
+	event.touch.position.x = tcur->getX();
+	event.touch.position.y = tcur->getY();
+	event.touch.id = tcur->getCursorID();
+		
 	CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
 	events.push_back(event);					
 	CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
@@ -85,11 +93,15 @@ void TUIOInputModule::removeTuioCursor(TuioCursor *tcur) {
 			touch.id= tuioCursor->getCursorID();			
 			touches.push_back(touch);
 	}
-	tuioClient->unlockCursorList();	
+	tuioClient->unlockCursorList();
 	TUIOEvent event;
 	event.type = InputEvent::EVENT_TOUCHES_ENDED;
 	event.touches = touches;
 	
+	event.touch.position.x = tcur->getX();
+	event.touch.position.y = tcur->getY();
+	event.touch.id = tcur->getCursorID();	
+	
 	CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
 	events.push_back(event);					
 	CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
@@ -108,15 +120,18 @@ void TUIOInputModule::Update(Number elapsed) {
 			events[i].touches[j].position.x = events[i].touches[j].position.x * core->getXRes();
 			events[i].touches[j].position.y = events[i].touches[j].position.y * core->getYRes();			
 		}
+		events[i].touch.position.x = events[i].touch.position.x * core->getXRes();
+		events[i].touch.position.y = events[i].touch.position.y * core->getYRes();
+		
 		switch(events[i].type) {
 			case InputEvent::EVENT_TOUCHES_BEGAN:
-				CoreServices::getInstance()->getCore()->getInput()->touchesBegan(events[i].touches, core->getTicks());
+				CoreServices::getInstance()->getCore()->getInput()->touchesBegan(events[i].touch, events[i].touches, core->getTicks());
 			break;
 			case InputEvent::EVENT_TOUCHES_MOVED:
-				CoreServices::getInstance()->getCore()->getInput()->touchesMoved(events[i].touches, core->getTicks());
+				CoreServices::getInstance()->getCore()->getInput()->touchesMoved(events[i].touch, events[i].touches, core->getTicks());
 			break;
 			case InputEvent::EVENT_TOUCHES_ENDED:
-				CoreServices::getInstance()->getCore()->getInput()->touchesEnded(events[i].touches, core->getTicks());			
+				CoreServices::getInstance()->getCore()->getInput()->touchesEnded(events[i].touch, events[i].touches, core->getTicks());			
 			break;			
 		}
 	}