Quellcode durchsuchen

Tweaked binding generation to allow for receiving charCode from InputEvent in Lua, added an option for SceneSounds to play and loop automatically when loaded as part of a SceneEntityInstance, added an option for it to the entity editor in the IDE

Ivan Safrin vor 11 Jahren
Ursprung
Commit
92920fd47d

+ 2 - 1
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -54,6 +54,7 @@ def typeFilter(ty):
 	ty = re.sub(r'^.*\sint\s*$', 'int', ty) # eg "unsigned int"
 	ty = re.sub(r'^.*\sint\s*$', 'int', ty) # eg "unsigned int"
 	ty = re.sub(r'^.*\schar\s*$', 'char', ty) # eg "unsigned int"
 	ty = re.sub(r'^.*\schar\s*$', 'char', ty) # eg "unsigned int"
 	ty = re.sub(r'^.*\slong\s*$', 'int', ty)
 	ty = re.sub(r'^.*\slong\s*$', 'int', ty)
+	ty = re.sub(r'^.*\swchar_t\s*$', 'int', ty)
 	ty = re.sub(r'^.*\sshort\s*$', 'int', ty)
 	ty = re.sub(r'^.*\sshort\s*$', 'int', ty)
 	ty = re.sub(r'^.*\sfloat\s*$', 'Number', ty)
 	ty = re.sub(r'^.*\sfloat\s*$', 'Number', ty)
 	ty = re.sub(r'^.*\sdouble\s*$', 'Number', ty) # eg "long double"
 	ty = re.sub(r'^.*\sdouble\s*$', 'Number', ty) # eg "long double"
@@ -654,7 +655,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 									outfunc = "lua_pushstring"
 									outfunc = "lua_pushstring"
 									basicType = True
 									basicType = True
 									retFunc = ".c_str()"
 									retFunc = ".c_str()"
-								if pm["rtnType"] == "int" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static int" or  pm["rtnType"] == "size_t" or pm["rtnType"] == "static size_t" or pm["rtnType"] == "long" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static long" or pm["rtnType"] == "short" or pm["rtnType"] == "PolyKEY":
+								if pm["rtnType"] == "int" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static int" or  pm["rtnType"] == "size_t" or pm["rtnType"] == "static size_t" or pm["rtnType"] == "long" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static long" or pm["rtnType"] == "short" or pm["rtnType"] == "PolyKEY" or pm["rtnType"] == "wchar_t":
 									outfunc = "lua_pushinteger"
 									outfunc = "lua_pushinteger"
 									basicType = True
 									basicType = True
 								if pm["rtnType"] == "bool" or pm["rtnType"] == "static bool" or pm["rtnType"] == "virtual bool":
 								if pm["rtnType"] == "bool" or pm["rtnType"] == "static bool" or pm["rtnType"] == "virtual bool":

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

@@ -98,6 +98,7 @@ namespace Polycode {
 		PolyKEY key;
 		PolyKEY key;
 		
 		
 		
 		
+        wchar_t getCharCode();
 		
 		
 		int keyCode() { return key; }
 		int keyCode() { return key; }
 		
 		

+ 4 - 0
Core/Contents/Include/PolySceneSound.h

@@ -58,9 +58,13 @@ namespace Polycode {
 			* Returns the sound object associated with this positional sound.
 			* Returns the sound object associated with this positional sound.
 			*/
 			*/
 			Sound *getSound();
 			Sound *getSound();
+        
+            void setLoopOnLoad(bool val);
+            bool getLoopOnLoad();
 			
 			
 		protected:
 		protected:
 		
 		
+            bool loopOnLoad;
 			bool directionalSound;
 			bool directionalSound;
 			Sound *sound;
 			Sound *sound;
 	};
 	};

+ 4 - 0
Core/Contents/Source/PolyInputEvent.cpp

@@ -40,6 +40,10 @@ InputEvent::InputEvent(PolyKEY key, wchar_t charCode, int timestamp) : Event() {
 	this->timestamp = timestamp;
 	this->timestamp = timestamp;
 	eventType = "InputEvent";	
 	eventType = "InputEvent";	
 }
 }
+    
+wchar_t InputEvent::getCharCode() {
+    return charCode;
+}
 
 
 /*
 /*
 InputEvent::InputEvent(PolyKEY key, int timestamp)  : Event() {
 InputEvent::InputEvent(PolyKEY key, int timestamp)  : Event() {

+ 9 - 0
Core/Contents/Source/PolySceneEntityInstance.cpp

@@ -454,6 +454,15 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit
 			sound->getSound()->setVolume(volume);
 			sound->getSound()->setVolume(volume);
 			sound->getSound()->setPitch(pitch);
 			sound->getSound()->setPitch(pitch);
 			
 			
+            if((*soundEntry)["loopOnLoad"]) {
+                bool loopOnLoad = (*soundEntry)["loopOnLoad"]->boolVal;
+                sound->setLoopOnLoad(loopOnLoad);
+                if(loopOnLoad) {
+                    sound->getSound()->Play(true);
+                }
+            }
+            
+            
 			entity = sound;
 			entity = sound;
         } else if(entityType->stringVal == "Camera") {
         } else if(entityType->stringVal == "Camera") {
 			ObjectEntry *cameraEntry = (*entry)["Camera"];
 			ObjectEntry *cameraEntry = (*entry)["Camera"];

+ 11 - 2
Core/Contents/Source/PolySceneSound.cpp

@@ -43,6 +43,15 @@ void SceneSoundListener::Update() {
 	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction, upVector);
 	CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction, upVector);
 }
 }
 
 
+void SceneSound::setLoopOnLoad(bool val) {
+    loopOnLoad = val;
+}
+
+bool SceneSound::getLoopOnLoad() {
+    return loopOnLoad;
+}
+
+
 Entity *SceneSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
 Entity *SceneSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
     SceneSound *newSound = new SceneSound(sound->getFileName(), sound->getReferenceDistance(), sound->getMaxDistance(), directionalSound);
     SceneSound *newSound = new SceneSound(sound->getFileName(), sound->getReferenceDistance(), sound->getMaxDistance(), directionalSound);
     applyClone(newSound, deepClone, ignoreEditorOnly);
     applyClone(newSound, deepClone, ignoreEditorOnly);
@@ -52,7 +61,7 @@ Entity *SceneSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
 void SceneSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
 void SceneSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
     Entity::applyClone(clone, deepClone, ignoreEditorOnly);
     Entity::applyClone(clone, deepClone, ignoreEditorOnly);
     SceneSound *cloneSound = (SceneSound*) clone;
     SceneSound *cloneSound = (SceneSound*) clone;
-    
+    cloneSound->setLoopOnLoad(loopOnLoad);
     cloneSound->getSound()->setPositionalProperties(sound->getReferenceDistance(), sound->getMaxDistance());
     cloneSound->getSound()->setPositionalProperties(sound->getReferenceDistance(), sound->getMaxDistance());
     cloneSound->setDirectionalSound(directionalSound);
     cloneSound->setDirectionalSound(directionalSound);
     cloneSound->getSound()->setVolume(sound->getVolume());
     cloneSound->getSound()->setVolume(sound->getVolume());
@@ -62,7 +71,7 @@ void SceneSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly
 SceneSound::SceneSound(const String& fileName, Number referenceDistance, Number maxDistance, bool directionalSound) : Entity() {
 SceneSound::SceneSound(const String& fileName, Number referenceDistance, Number maxDistance, bool directionalSound) : Entity() {
 
 
 	this->directionalSound = directionalSound;
 	this->directionalSound = directionalSound;
-	
+	loopOnLoad = false;
 	sound = new Sound(fileName);
 	sound = new Sound(fileName);
 	sound->setIsPositional(true);
 	sound->setIsPositional(true);
 	sound->setPositionalProperties(referenceDistance, maxDistance);
 	sound->setPositionalProperties(referenceDistance, maxDistance);

+ 2 - 1
IDE/Contents/Include/PolycodeProps.h

@@ -895,7 +895,8 @@ class SoundSheet : public PropSheet {
 
 
 		SoundProp *soundProp;		
 		SoundProp *soundProp;		
 		NumberProp *referenceDistance;
 		NumberProp *referenceDistance;
-		NumberProp *maxDistance;		
+        BoolProp *loopOnLoad;
+		NumberProp *maxDistance;
 		SliderProp *volume;
 		SliderProp *volume;
 		SliderProp *pitch;
 		SliderProp *pitch;
 };
 };

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

@@ -2080,6 +2080,14 @@ bool PolycodeEntityEditor::openFile(OSFileEntry filePath) {
 //    return true;
 //    return true;
     loadedInstance = new SceneEntityInstance(mainView->getMainScene(), filePath.fullPath);
     loadedInstance = new SceneEntityInstance(mainView->getMainScene(), filePath.fullPath);
     
     
+    // disable sounds :)
+    for(int i=0; i < loadedInstance->getNumChildren(); i++) {
+        SceneSound *sound = dynamic_cast<SceneSound*>(loadedInstance->getChildAtIndex(i));
+        if(sound) {
+            sound->getSound()->Stop();
+        }
+    }
+    
     mainView->setObjectRoot(loadedInstance);
     mainView->setObjectRoot(loadedInstance);
     mainView->setEditorPropsRecursive(loadedInstance);
     mainView->setEditorPropsRecursive(loadedInstance);
     
     
@@ -2298,6 +2306,7 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
         soundEntry->addChild("maxDistance", sound->getSound()->getMaxDistance());
         soundEntry->addChild("maxDistance", sound->getSound()->getMaxDistance());
         soundEntry->addChild("volume", sound->getSound()->getVolume());
         soundEntry->addChild("volume", sound->getSound()->getVolume());
         soundEntry->addChild("pitch", sound->getSound()->getPitch());
         soundEntry->addChild("pitch", sound->getSound()->getPitch());
+        soundEntry->addChild("loopOnLoad", sound->getLoopOnLoad());
     }
     }
 
 
     if(dynamic_cast<Camera*>(entity)) {
     if(dynamic_cast<Camera*>(entity)) {

+ 10 - 1
IDE/Contents/Source/PolycodeProps.cpp

@@ -3943,10 +3943,14 @@ SoundSheet::SoundSheet() : PropSheet("SOUND", "sound") {
 	referenceDistance = new NumberProp("Reference dist");
 	referenceDistance = new NumberProp("Reference dist");
 	referenceDistance->addEventListener(this, Event::CHANGE_EVENT);
 	referenceDistance->addEventListener(this, Event::CHANGE_EVENT);
 	addProp(referenceDistance);
 	addProp(referenceDistance);
-
+    
 	maxDistance = new NumberProp("Max dist");
 	maxDistance = new NumberProp("Max dist");
 	maxDistance->addEventListener(this, Event::CHANGE_EVENT);
 	maxDistance->addEventListener(this, Event::CHANGE_EVENT);
 	addProp(maxDistance);
 	addProp(maxDistance);
+    
+    loopOnLoad = new BoolProp("Loop on load");
+    loopOnLoad->addEventListener(this, Event::CHANGE_EVENT);
+    addProp(loopOnLoad);
 
 
 	volume = new SliderProp("Volume", 0.0, 1.0);
 	volume = new SliderProp("Volume", 0.0, 1.0);
 	volume->addEventListener(this, Event::CHANGE_EVENT);
 	volume->addEventListener(this, Event::CHANGE_EVENT);
@@ -3989,6 +3993,10 @@ void SoundSheet::handleEvent(Event *event) {
 	if(event->getDispatcher() == soundProp  && event->getEventCode() == Event::CHANGE_EVENT) {
 	if(event->getDispatcher() == soundProp  && event->getEventCode() == Event::CHANGE_EVENT) {
 		sound->getSound()->loadFile(soundProp->get(), false);
 		sound->getSound()->loadFile(soundProp->get(), false);
 	}
 	}
+    
+    if(event->getDispatcher() == loopOnLoad && event->getEventCode() == Event::CHANGE_EVENT) {
+        sound->setLoopOnLoad(loopOnLoad->get());
+    }
 
 
 
 
 	PropSheet::handleEvent(event);
 	PropSheet::handleEvent(event);
@@ -4006,6 +4014,7 @@ void SoundSheet::setSound(SceneSound *sound) {
         volume->set(sound->getSound()->getVolume());
         volume->set(sound->getSound()->getVolume());
         pitch->set(sound->getSound()->getPitch());
         pitch->set(sound->getSound()->getPitch());
         soundProp->previewSound->setPitch(sound->getSound()->getPitch());
         soundProp->previewSound->setPitch(sound->getSound()->getPitch());
+        loopOnLoad->set(sound->getLoopOnLoad());
 
 
 	} else {
 	} else {
 		enabled = false;
 		enabled = false;