Bladeren bron

Sprite bugfixes, added ability to change retina support setting in Core::setVideoMode

Ivan Safrin 11 jaren geleden
bovenliggende
commit
40c5f004b8

+ 1 - 1
Core/Contents/Include/PolyCocoaCore.h

@@ -122,7 +122,7 @@ namespace Polycode {
 		
 		
 		void Render();
 		void Render();
 								
 								
-		void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel);		
+		void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport = true);
 		void resizeTo(int xRes, int yRes);
 		void resizeTo(int xRes, int yRes);
 		void createThread(Threaded *target);		
 		void createThread(Threaded *target);		
 		
 		

+ 1 - 1
Core/Contents/Include/PolyCore.h

@@ -284,7 +284,7 @@ namespace Polycode {
 		* @param fullScreen True to launch in fullscreen, false to launch in window.
 		* @param fullScreen True to launch in fullscreen, false to launch in window.
 		* @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
 		* @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
 		*/																									
 		*/																									
-		virtual void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) = 0;
+		virtual void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport=true) = 0;
 		
 		
 		/**
 		/**
 		* Resizes the renderer.
 		* Resizes the renderer.

+ 7 - 6
Core/Contents/Source/PolyCocoaCore.mm

@@ -103,10 +103,6 @@ CocoaCore::CocoaCore(PolycodeView *view, int _xRes, int _yRes, bool fullScreen,
 	
 	
 	glView = view;
 	glView = view;
     
     
-    if(retinaSupport) {
-        [glView setWantsBestResolutionOpenGLSurface:YES];
-    }
-    
 	context = nil;
 	context = nil;
 	
 	
 	initTime = mach_absolute_time();					
 	initTime = mach_absolute_time();					
@@ -144,7 +140,8 @@ String CocoaCore::getClipboardString() {
 	return [retString UTF8String];
 	return [retString UTF8String];
 }
 }
 
 
-void CocoaCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {	
+void CocoaCore::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport) {
+    this->retinaSupport = retinaSupport;
 	// hack to make sure there are no window race conditions
 	// hack to make sure there are no window race conditions
 	modeChangeInfo.needResolutionChange = true;
 	modeChangeInfo.needResolutionChange = true;
 	modeChangeInfo.xRes = xRes;
 	modeChangeInfo.xRes = xRes;
@@ -174,14 +171,18 @@ Number CocoaCore::getBackingYRes() {
 void CocoaCore::_setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {
 void CocoaCore::_setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {
 	this->xRes = xRes;
 	this->xRes = xRes;
 	this->yRes = yRes;
 	this->yRes = yRes;
-    
+
     NSRect backingBounds;
     NSRect backingBounds;
     if(retinaSupport) {
     if(retinaSupport) {
+        [glView setWantsBestResolutionOpenGLSurface:YES];
         backingBounds = [glView convertRectToBacking: NSMakeRect(0, 0, xRes, yRes)];
         backingBounds = [glView convertRectToBacking: NSMakeRect(0, 0, xRes, yRes)];
         renderer->setBackingResolutionScale(backingBounds.size.width/xRes, backingBounds.size.height/yRes);
         renderer->setBackingResolutionScale(backingBounds.size.width/xRes, backingBounds.size.height/yRes);
 	} else {
 	} else {
+        [glView setWantsBestResolutionOpenGLSurface:NO];
         backingBounds.size.width = xRes;
         backingBounds.size.width = xRes;
         backingBounds.size.height = yRes;
         backingBounds.size.height = yRes;
+        renderer->setBackingResolutionScale(1.0, 1.0);
+        
     }
     }
     
     
 	bool _wasFullscreen = this->fullScreen;
 	bool _wasFullscreen = this->fullScreen;

+ 9 - 5
Core/Contents/Source/PolySceneSprite.cpp

@@ -193,6 +193,11 @@ void SceneSprite::setSpriteStateByName(String name, unsigned int startingFrame,
 }
 }
 
 
 void SceneSprite::setSpriteState(SpriteState *spriteState, unsigned int startingFrame, bool playOnce) {
 void SceneSprite::setSpriteState(SpriteState *spriteState, unsigned int startingFrame, bool playOnce) {
+    
+    if(currentSpriteState != spriteState || playOnce) {
+        currentFrame = startingFrame;
+    }
+    
     currentSpriteState = spriteState;
     currentSpriteState = spriteState;
     
     
     if(!currentSpriteState) {
     if(!currentSpriteState) {
@@ -205,7 +210,6 @@ void SceneSprite::setSpriteState(SpriteState *spriteState, unsigned int starting
     spriteBoundingBox = currentSpriteState->getLargestFrameBoundingBox();
     spriteBoundingBox = currentSpriteState->getLargestFrameBoundingBox();
     
     
     this->playOnce = playOnce;
     this->playOnce = playOnce;
-    currentFrame = startingFrame;
     
     
 }
 }
 
 
@@ -401,10 +405,10 @@ void SpriteState::rebuildStateMeshes() {
         meshOffset.x -= frameWidth * frame.anchorPoint.x;
         meshOffset.x -= frameWidth * frame.anchorPoint.x;
         meshOffset.y += frameHeight * frame.anchorPoint.y;
         meshOffset.y += frameHeight * frame.anchorPoint.y;
         
         
-        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5, meshOffset.y+frameHeight*0.5, 0.0, frame.coordinates.x, 1.0-frame.coordinates.y);
-        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5, meshOffset.y+frameHeight*0.5-frameHeight, 0.0, frame.coordinates.x, 1.0-frame.coordinates.y  - frame.coordinates.h);
-        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5+frameWidth, meshOffset.y+frameHeight*0.5-frameHeight, 0.0, frame.coordinates.x+frame.coordinates.w, 1.0- frame.coordinates.y  - frame.coordinates.h);
-        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5+frameWidth, meshOffset.y+frameHeight*0.5, 0.0, frame.coordinates.x+frame.coordinates.w, 1.0-frame.coordinates.y);
+        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5, meshOffset.y+frameHeight*0.5, 0.0, frame.coordinates.x, 1.0-frame.coordinates.y)->setNormal(0.0, 0.0, 1.0);
+        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5, meshOffset.y+frameHeight*0.5-frameHeight, 0.0, frame.coordinates.x, 1.0-frame.coordinates.y  - frame.coordinates.h)->setNormal(0.0, 0.0, 1.0);
+        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5+frameWidth, meshOffset.y+frameHeight*0.5-frameHeight, 0.0, frame.coordinates.x+frame.coordinates.w, 1.0- frame.coordinates.y  - frame.coordinates.h)->setNormal(0.0, 0.0, 1.0);
+        frameMesh->addVertex(meshOffset.x+-frameWidth*0.5+frameWidth, meshOffset.y+frameHeight*0.5, 0.0, frame.coordinates.x+frame.coordinates.w, 1.0-frame.coordinates.y)->setNormal(0.0, 0.0, 1.0);
         
         
         
         
         for(int j=0; j < 4; j++) {
         for(int j=0; j < 4; j++) {

+ 5 - 0
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -513,6 +513,11 @@ std::vector<Entity*> EntityEditorMainView::getSelectedEntities() {
 
 
 void EntityEditorMainView::doAction(String actionName, PolycodeEditorActionData *data) {
 void EntityEditorMainView::doAction(String actionName, PolycodeEditorActionData *data) {
     PolycodeSceneEditorActionData *sceneData = (PolycodeSceneEditorActionData*)data;
     PolycodeSceneEditorActionData *sceneData = (PolycodeSceneEditorActionData*)data;
+    
+    if(!sceneData) {
+        return;
+    }
+    
 	if(actionName == "move") {
 	if(actionName == "move") {
 		for(int i=0; i < selectedEntities.size(); i++) {
 		for(int i=0; i < selectedEntities.size(); i++) {
             if(i < sceneData->entries.size()) {
             if(i < sceneData->entries.size()) {

+ 2 - 2
IDE/Contents/Source/PolycodeProps.cpp

@@ -1489,9 +1489,9 @@ void SceneSpriteProp::set(Sprite *sprite) {
     
     
     Number spriteScale = 1.0;
     Number spriteScale = 1.0;
     if(previewSprite->getHeight() > previewSprite->getWidth()) {
     if(previewSprite->getHeight() > previewSprite->getWidth()) {
-        spriteScale = 40.0 / previewSprite->getHeight();
+        spriteScale = 40.0 / previewSprite->getSpriteBoundingBox().y;
     } else {
     } else {
-        spriteScale = 40.0 / previewSprite->getWidth();
+        spriteScale = 40.0 / previewSprite->getSpriteBoundingBox().x;
     }
     }
     previewSprite->setScale(spriteScale, spriteScale, 1.0);
     previewSprite->setScale(spriteScale, spriteScale, 1.0);
 }
 }

+ 5 - 1
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -112,6 +112,9 @@ namespace Polycode {
 			 * Gets the last fixture selected (automatically set to last added on creation)
 			 * Gets the last fixture selected (automatically set to last added on creation)
 			 */
 			 */
 			b2Fixture* getFixture();
 			b2Fixture* getFixture();
+        
+            bool getFixedRotation() const;
+            void setFixedRotation(bool val);
 
 
 			/**
 			/**
 			* Rectangular physics entity
 			* Rectangular physics entity
@@ -147,7 +150,8 @@ namespace Polycode {
 
 
 		protected:
 		protected:
         
         
-			Number worldScale;        
+            bool fixedRotation;
+			Number worldScale;
 			Entity *entity;
 			Entity *entity;
 	};
 	};
 	
 	

+ 10 - 0
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -31,6 +31,7 @@ using namespace Polycode;
 
 
 PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) {
 PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) {
 	
 	
+    this->fixedRotation =  fixedRotation;
 	this->entity = entity;
 	this->entity = entity;
 
 
 	Vector3 entityScale = entity->getCompoundScale();
 	Vector3 entityScale = entity->getCompoundScale();
@@ -162,6 +163,15 @@ PhysicsScene2DEntity::PhysicsScene2DEntity(Entity *entity, b2World *world, Numbe
 	}
 	}
 }
 }
 
 
+bool PhysicsScene2DEntity::getFixedRotation() const {
+    return fixedRotation;
+}
+
+void PhysicsScene2DEntity::setFixedRotation(bool val) {
+    fixedRotation = val;
+    
+}
+
 void PhysicsScene2DEntity::applyTorque(Number torque) {
 void PhysicsScene2DEntity::applyTorque(Number torque) {
 	body->ApplyTorque(torque);
 	body->ApplyTorque(torque);
 }
 }