Skip to content

Commit 92920fd

Browse files
committed
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
1 parent 6ebb557 commit 92920fd

File tree

9 files changed

+52
-5
lines changed

9 files changed

+52
-5
lines changed

Bindings/Scripts/create_lua_library/create_lua_library.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def typeFilter(ty):
5454
ty = re.sub(r'^.*\sint\s*$', 'int', ty) # eg "unsigned int"
5555
ty = re.sub(r'^.*\schar\s*$', 'char', ty) # eg "unsigned int"
5656
ty = re.sub(r'^.*\slong\s*$', 'int', ty)
57+
ty = re.sub(r'^.*\swchar_t\s*$', 'int', ty)
5758
ty = re.sub(r'^.*\sshort\s*$', 'int', ty)
5859
ty = re.sub(r'^.*\sfloat\s*$', 'Number', ty)
5960
ty = re.sub(r'^.*\sdouble\s*$', 'Number', ty) # eg "long double"
@@ -654,7 +655,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
654655
outfunc = "lua_pushstring"
655656
basicType = True
656657
retFunc = ".c_str()"
657-
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":
658+
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":
658659
outfunc = "lua_pushinteger"
659660
basicType = True
660661
if pm["rtnType"] == "bool" or pm["rtnType"] == "static bool" or pm["rtnType"] == "virtual bool":

Core/Contents/Include/PolyInputEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace Polycode {
9898
PolyKEY key;
9999

100100

101+
wchar_t getCharCode();
101102

102103
int keyCode() { return key; }
103104

Core/Contents/Include/PolySceneSound.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ namespace Polycode {
5858
* Returns the sound object associated with this positional sound.
5959
*/
6060
Sound *getSound();
61+
62+
void setLoopOnLoad(bool val);
63+
bool getLoopOnLoad();
6164

6265
protected:
6366

67+
bool loopOnLoad;
6468
bool directionalSound;
6569
Sound *sound;
6670
};

Core/Contents/Source/PolyInputEvent.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ InputEvent::InputEvent(PolyKEY key, wchar_t charCode, int timestamp) : Event() {
4040
this->timestamp = timestamp;
4141
eventType = "InputEvent";
4242
}
43+
44+
wchar_t InputEvent::getCharCode() {
45+
return charCode;
46+
}
4347

4448
/*
4549
InputEvent::InputEvent(PolyKEY key, int timestamp) : Event() {

Core/Contents/Source/PolySceneEntityInstance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ Entity *SceneEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry, Entit
454454
sound->getSound()->setVolume(volume);
455455
sound->getSound()->setPitch(pitch);
456456

457+
if((*soundEntry)["loopOnLoad"]) {
458+
bool loopOnLoad = (*soundEntry)["loopOnLoad"]->boolVal;
459+
sound->setLoopOnLoad(loopOnLoad);
460+
if(loopOnLoad) {
461+
sound->getSound()->Play(true);
462+
}
463+
}
464+
465+
457466
entity = sound;
458467
} else if(entityType->stringVal == "Camera") {
459468
ObjectEntry *cameraEntry = (*entry)["Camera"];

Core/Contents/Source/PolySceneSound.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ void SceneSoundListener::Update() {
4343
CoreServices::getInstance()->getSoundManager()->setListenerOrientation(direction, upVector);
4444
}
4545

46+
void SceneSound::setLoopOnLoad(bool val) {
47+
loopOnLoad = val;
48+
}
49+
50+
bool SceneSound::getLoopOnLoad() {
51+
return loopOnLoad;
52+
}
53+
54+
4655
Entity *SceneSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
4756
SceneSound *newSound = new SceneSound(sound->getFileName(), sound->getReferenceDistance(), sound->getMaxDistance(), directionalSound);
4857
applyClone(newSound, deepClone, ignoreEditorOnly);
@@ -52,7 +61,7 @@ Entity *SceneSound::Clone(bool deepClone, bool ignoreEditorOnly) const {
5261
void SceneSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) const {
5362
Entity::applyClone(clone, deepClone, ignoreEditorOnly);
5463
SceneSound *cloneSound = (SceneSound*) clone;
55-
64+
cloneSound->setLoopOnLoad(loopOnLoad);
5665
cloneSound->getSound()->setPositionalProperties(sound->getReferenceDistance(), sound->getMaxDistance());
5766
cloneSound->setDirectionalSound(directionalSound);
5867
cloneSound->getSound()->setVolume(sound->getVolume());
@@ -62,7 +71,7 @@ void SceneSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly
6271
SceneSound::SceneSound(const String& fileName, Number referenceDistance, Number maxDistance, bool directionalSound) : Entity() {
6372

6473
this->directionalSound = directionalSound;
65-
74+
loopOnLoad = false;
6675
sound = new Sound(fileName);
6776
sound->setIsPositional(true);
6877
sound->setPositionalProperties(referenceDistance, maxDistance);

IDE/Contents/Include/PolycodeProps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ class SoundSheet : public PropSheet {
895895

896896
SoundProp *soundProp;
897897
NumberProp *referenceDistance;
898-
NumberProp *maxDistance;
898+
BoolProp *loopOnLoad;
899+
NumberProp *maxDistance;
899900
SliderProp *volume;
900901
SliderProp *pitch;
901902
};

IDE/Contents/Source/PolycodeEntityEditor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,14 @@ bool PolycodeEntityEditor::openFile(OSFileEntry filePath) {
20802080
// return true;
20812081
loadedInstance = new SceneEntityInstance(mainView->getMainScene(), filePath.fullPath);
20822082

2083+
// disable sounds :)
2084+
for(int i=0; i < loadedInstance->getNumChildren(); i++) {
2085+
SceneSound *sound = dynamic_cast<SceneSound*>(loadedInstance->getChildAtIndex(i));
2086+
if(sound) {
2087+
sound->getSound()->Stop();
2088+
}
2089+
}
2090+
20832091
mainView->setObjectRoot(loadedInstance);
20842092
mainView->setEditorPropsRecursive(loadedInstance);
20852093

@@ -2298,6 +2306,7 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
22982306
soundEntry->addChild("maxDistance", sound->getSound()->getMaxDistance());
22992307
soundEntry->addChild("volume", sound->getSound()->getVolume());
23002308
soundEntry->addChild("pitch", sound->getSound()->getPitch());
2309+
soundEntry->addChild("loopOnLoad", sound->getLoopOnLoad());
23012310
}
23022311

23032312
if(dynamic_cast<Camera*>(entity)) {

IDE/Contents/Source/PolycodeProps.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3943,10 +3943,14 @@ SoundSheet::SoundSheet() : PropSheet("SOUND", "sound") {
39433943
referenceDistance = new NumberProp("Reference dist");
39443944
referenceDistance->addEventListener(this, Event::CHANGE_EVENT);
39453945
addProp(referenceDistance);
3946-
3946+
39473947
maxDistance = new NumberProp("Max dist");
39483948
maxDistance->addEventListener(this, Event::CHANGE_EVENT);
39493949
addProp(maxDistance);
3950+
3951+
loopOnLoad = new BoolProp("Loop on load");
3952+
loopOnLoad->addEventListener(this, Event::CHANGE_EVENT);
3953+
addProp(loopOnLoad);
39503954

39513955
volume = new SliderProp("Volume", 0.0, 1.0);
39523956
volume->addEventListener(this, Event::CHANGE_EVENT);
@@ -3989,6 +3993,10 @@ void SoundSheet::handleEvent(Event *event) {
39893993
if(event->getDispatcher() == soundProp && event->getEventCode() == Event::CHANGE_EVENT) {
39903994
sound->getSound()->loadFile(soundProp->get(), false);
39913995
}
3996+
3997+
if(event->getDispatcher() == loopOnLoad && event->getEventCode() == Event::CHANGE_EVENT) {
3998+
sound->setLoopOnLoad(loopOnLoad->get());
3999+
}
39924000

39934001

39944002
PropSheet::handleEvent(event);
@@ -4006,6 +4014,7 @@ void SoundSheet::setSound(SceneSound *sound) {
40064014
volume->set(sound->getSound()->getVolume());
40074015
pitch->set(sound->getSound()->getPitch());
40084016
soundProp->previewSound->setPitch(sound->getSound()->getPitch());
4017+
loopOnLoad->set(sound->getLoopOnLoad());
40094018

40104019
} else {
40114020
enabled = false;

0 commit comments

Comments
 (0)