diff --git a/build_openmw.bat b/build_openmw.bat index 8c4f8f2d8..8d3575d54 100755 --- a/build_openmw.bat +++ b/build_openmw.bat @@ -8,4 +8,4 @@ g++ -c ogre\cpp_ogre.cpp -I.\includes\ogre\ g++ -c bullet\cpp_bullet.cpp -I.\includes\bullet\ echo Compiling main program (openmw.exe) -gdc -Wall -g openmw.d bsa\*.d core\*.d esm\*.d input\*.d nif\*.d ogre\*.d scene\*.d sound\*.d util\*.d bullet\*.d cpp_ogre.o cpp_avcodec.o cpp_bullet.o libbulletdynamics.a libbulletcollision.a libbulletmath.a monster\util\*.d avcodec-51.dll avformat-52.dll avdevice-52.dll avutil-49.dll openal32.dll ogremain_d.dll OIS_d.dll -lstdc++ -o openmw.exe +gdc -Wall -g openmw.d bsa\*.d core\*.d esm\*.d input\*.d nif\*.d ogre\*.d scene\*.d sound\*.d util\*.d bullet\*.d cpp_ogre.o cpp_avcodec.o cpp_bullet.o libbulletdynamics.a libbulletcollision.a libbulletmath.a mscripts\object.d monster\compiler\*.d monster\vm\*.d monster\util\*.d avcodec-51.dll avformat-52.dll avdevice-52.dll avutil-49.dll openal32.dll ogremain_d.dll OIS_d.dll -lstdc++ -o openmw.exe diff --git a/bullet/cpp_bullet.cpp b/bullet/cpp_bullet.cpp index c544d7a9a..0e0959a86 100644 --- a/bullet/cpp_bullet.cpp +++ b/bullet/cpp_bullet.cpp @@ -404,10 +404,38 @@ extern "C" void bullet_insertStatic(btConcaveShape *shape, // FIXME: Scaling does NOT work. // Are we scaled? - if(scale != 1.0) {} - // Wrap the shape in a class that scales it. TODO: Try this on - // ALL shapes, just to test the slowdown. - //shape = new ScaleShape(shape, scale); + if(scale != 1.0) + { + cout << "Scaling shape " << shape << " by " << scale << endl; + + // Not quite sure how to handle local scaling yet. Our initial + // attempt was to create a wrapper that showed a scale mesh to + // the "outside world" while referencing the original, but I + // suspect it ended up altering the original data. At least it + // doesn't work the way it is now, and only crashes. + + // The alternative is to create a new copy of the shape for each + // scaled version we insert. This is wasteful, but might be + // acceptable. + + // It's also possible we can achieve this effect by changing + // larger parts of the Bullet library - but I hope I don't have + // to create my own dispatcher and such. Finally, even if the + // transformations given to objects are supposed to be uniform + // in length, maybe we can cheat the system and scale the + // transformation instead. Try it just for kicks, and go through + // the system to see what parts of Bullet it would break. + + // In any case, when we find a solution we should apply it to + // all shapes (not just scale!=1.0) to get a better impression + // of any performance and memory overhead. + + // Also, as an optimization, it looks like multiple instances of + // the same shape are often inserted with the same scale + // factor. We could easily cache this. The scale-recreation of + // meshes (in necessary) could be done as a separate function, + // and the caching could be done in D code. + } btTransform trafo; trafo.setIdentity(); diff --git a/mscripts/jukebox.mn b/mscripts/jukebox.mn index 622cfc9d4..e2c93c412 100644 --- a/mscripts/jukebox.mn +++ b/mscripts/jukebox.mn @@ -32,8 +32,8 @@ class Jukebox : Object; float fadeLevel = 0.0; // How much to fade in and out each second -float fadeInRate = 0.10; -float fadeOutRate = 0.25; +float fadeInRate = 0.14; +float fadeOutRate = 0.30; // Time between each fade step float fadeInterval = 0.2; @@ -50,12 +50,7 @@ int index; float musVolume; bool isPlaying; // Is a song currently playing? - -// TODO: Make "isPaused" instead, makes more sense -bool hasSong; // Is a song currently selected (playing or paused) - -// TODO: Move to Object for now -native int randInt(int a, int b); +bool isPaused; // Is the song currently paused? // Native functions to control music native setSound(char[] filename); @@ -66,12 +61,18 @@ idle waitUntilFinished(); // Fade out and then stop the music. TODO: Rename these to resume() // etc and use super.resume, when this is possible. -pause() { state = fadeOut; } +pause() +{ + isPaused = true; + state = fadeOut; +} + resume() { - if(!hasSong) next(); - else playSound(); + if(isPaused) playSound(); + else next(); + isPaused = false; state = fadeIn; } @@ -81,7 +82,6 @@ stop() { stopSound(); - hasSong = false; isPlaying = false; fadeLevel = 0.0; state = null; @@ -96,7 +96,9 @@ play() playSound(); isPlaying = true; - hasSong = true; + isPaused = false; + + state = playing; } // Play the next song in the playlist @@ -159,7 +161,6 @@ randomize() state fadeIn { begin: - setVolume(musVolume*fadeLevel); sleep(fadeInterval); @@ -179,7 +180,6 @@ state fadeIn state fadeOut { begin: - sleep(fadeInterval); fadeLevel -= fadeInterval*fadeOutRate; @@ -187,7 +187,6 @@ state fadeOut if(fadeLevel <= 0.0) { fadeLevel = 0.0; - stopSound(); isPlaying = false; @@ -201,12 +200,16 @@ state fadeOut state playing { begin: - // Wait for the song to play. Will return imediately if the song has - // already stopped or if no song is playing - waitUntilFinished(); + setVolume(musVolume); + fadeLevel = 1.0; - // Start playing the next song - next(); + while(true) + { + // Wait for the song to play. Will return imediately if the song has + // already stopped or if no song is playing + waitUntilFinished(); - goto begin; + // Start playing the next song + next(); + } } diff --git a/mscripts/object.d b/mscripts/object.d index a5defcb15..ac4e6ca81 100644 --- a/mscripts/object.d +++ b/mscripts/object.d @@ -26,6 +26,7 @@ module mscripts.object; import monster.monster; import std.stdio; import std.date; +import core.resource : rnd; // Set up the base Monster classes we need in OpenMW void initMonsterScripts() @@ -38,6 +39,9 @@ void initMonsterScripts() // Bind various functions mc.bind("print", { print(); }); + mc.bind("randInt", + { stack.pushInt(rnd.randInt + (stack.popInt,stack.popInt));}); mc.bind("sleep", new IdleSleep); // Load and run the test script diff --git a/mscripts/object.mn b/mscripts/object.mn index 79aec0475..cfc9634b4 100644 --- a/mscripts/object.mn +++ b/mscripts/object.mn @@ -29,3 +29,6 @@ idle sleep(float seconds); // Print a message to screen native print(char[][] msg...); + +// Get a random number between a and b (inclusive) +native int randInt(int a, int b); diff --git a/mscripts/test.mn b/mscripts/test.mn index ee769984d..587a8c129 100644 --- a/mscripts/test.mn +++ b/mscripts/test.mn @@ -10,7 +10,7 @@ state printMessage { // This state code will run as long as the object is in this state. begin: - sleep(10); + sleep(15); print("Howdy from the world of Monster scripts!"); print("This script is located in mscripts/test.mn. Check it out!"); goto begin; diff --git a/sound/music.d b/sound/music.d index 8d0a0ae60..fac3a9677 100644 --- a/sound/music.d +++ b/sound/music.d @@ -90,9 +90,6 @@ struct MusicManager { assert(mc is null); mc = new MonsterClass("Jukebox", "jukebox.mn"); - mc.bind("randInt", - { stack.pushInt(rnd.randInt - (stack.popInt,stack.popInt));}); mc.bind("waitUntilFinished", new Idle_waitUntilFinished);