]> Dogcows Code - chaz/yoink/commitdiff
library class revamped as manager, goodbye tilemap
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 24 Jan 2010 01:14:26 +0000 (18:14 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 24 Jan 2010 01:14:26 +0000 (18:14 -0700)
53 files changed:
data/scenes/Classic.lua
data/textures/AlienWarrior.png
data/textures/BackgroundFar.png
data/textures/BackgroundNear.png
data/textures/BigExplosion.png
data/textures/Bonuses.png
data/textures/Building.png
data/textures/Font.png
data/textures/Heroine.png
data/textures/Jetbot.png
data/textures/Particles.png
data/textures/RobotTrooper.png
data/textures/Scenery.png
data/textures/StatusBars.png
data/textures/TowerBlock1.png
data/textures/Trees.png
data/tilemaps/AlienWarrior.lua [deleted file]
data/tilemaps/BackgroundFar.lua [deleted file]
data/tilemaps/BackgroundNear.lua [deleted file]
data/tilemaps/BigExplosion.lua [deleted file]
data/tilemaps/Bonuses.lua [deleted file]
data/tilemaps/Building.lua [deleted file]
data/tilemaps/Font.lua [deleted file]
data/tilemaps/Heroine.lua [deleted file]
data/tilemaps/Jetbot.lua [deleted file]
data/tilemaps/Particles.lua [deleted file]
data/tilemaps/RobotTrooper.lua [deleted file]
data/tilemaps/Scenery.lua [deleted file]
data/tilemaps/StatusBars.lua [deleted file]
data/tilemaps/TowerBlock1.lua [deleted file]
data/tilemaps/Trees.lua [deleted file]
src/Animation.cc
src/Character.cc
src/Character.hh
src/Hud.cc
src/Hud.hh
src/Makefile.am
src/Moof/Core.cc
src/Moof/Core.hh
src/Moof/Error.hh
src/Moof/Image.cc
src/Moof/Image.hh
src/Moof/Library.hh [deleted file]
src/Moof/Sound.cc
src/Moof/Texture.cc
src/Moof/Texture.hh
src/Moof/Video.cc
src/Moof/Video.hh
src/Scene.cc
src/Tilemap.cc [deleted file]
src/Tilemap.hh [deleted file]
src/TilemapFont.cc
src/TilemapFont.hh

index 2ec9e0271a2789f246b128a788414e79e3be4cca..10ba6a2d27597f5f6c6317bc7216918a6ac0c6d6 100644 (file)
@@ -1,10 +1,9 @@
 
--- Scene: Classic Yoink
--- created by Neil Carter
--- converted to Lua by Charles McGarvey
-
-LogInfo("-----", "Scene: Classic", "Created by Neil Carter",
-               "Converted to Lua by Charles McGarvey", "-----")
+LogInfo("-----",
+               "Scene: Classic",
+               "Created by Neil Carter",
+               "Converted to Lua by Charles McGarvey",
+               "-----")
 
 -- Scene API:
 --
index ece94d08932ef3ffadec3113e823a074e7df9d12..c93ee69e9891c01c1303b4c16a82cb380047b263 100644 (file)
Binary files a/data/textures/AlienWarrior.png and b/data/textures/AlienWarrior.png differ
index df103342ad4081078b8f0759ada535e19cb21d98..486c19126e0a2c664579e13a76815db8ccb885ed 100644 (file)
Binary files a/data/textures/BackgroundFar.png and b/data/textures/BackgroundFar.png differ
index fd30b7f7a9ef352b9a9c0a1ad14bd1c72bba411e..94e674727402fd7b3e35973b0ccc320dc7afcc32 100644 (file)
Binary files a/data/textures/BackgroundNear.png and b/data/textures/BackgroundNear.png differ
index 6bfc83792b0bf5d78c030219551b28bfa5b1a8e3..58bfe0df355a512a928548a6a83d6fddb4dddcfb 100644 (file)
Binary files a/data/textures/BigExplosion.png and b/data/textures/BigExplosion.png differ
index 1e9a21f8c0fa29fda34d6cd7bf85a675673b3a0a..2ab194e73427ebeb2580e7635655ce6f88e1c558 100644 (file)
Binary files a/data/textures/Bonuses.png and b/data/textures/Bonuses.png differ
index 43a458653a99f05ddd2f5d9c08480d6fdcdde8fd..5cb2a63f4d7c0e118f01ea9bd48d1cf3ec98b763 100644 (file)
Binary files a/data/textures/Building.png and b/data/textures/Building.png differ
index 30b54aa9c3e9a97ad65c3932c15e45b6f684ae90..dd90aa517bb6d554639c18d0d783798e4efa6472 100644 (file)
Binary files a/data/textures/Font.png and b/data/textures/Font.png differ
index aff328252d9a81d75ef84b2d774e994caa9c7a46..b08bf9ac34e1162634d947661d59c770a53a70c2 100644 (file)
Binary files a/data/textures/Heroine.png and b/data/textures/Heroine.png differ
index 1f02c6dbc16ea7e7c3dd324f8be6d8304838febf..c1c6b0a431f0421947b31307deea8a3608ac8da1 100644 (file)
Binary files a/data/textures/Jetbot.png and b/data/textures/Jetbot.png differ
index 659fae5758fa1007dfc89f3df7996b6c3bda18e7..0fae414d5e494a2db373bd9f75f6697c57e6fed4 100644 (file)
Binary files a/data/textures/Particles.png and b/data/textures/Particles.png differ
index ee76d850b9919826b19a43cc95334f3f2714f443..e5cf0cae7a31d878b7db0a3e1994ff774214b024 100644 (file)
Binary files a/data/textures/RobotTrooper.png and b/data/textures/RobotTrooper.png differ
index 99ede6e1197d8752015db39b14a048e38a24d9cd..b2fe47c53f3cc748ca1aefdcc3a4383f5b70f75b 100644 (file)
Binary files a/data/textures/Scenery.png and b/data/textures/Scenery.png differ
index 49abbc882fec837323d6422d2f6b9ae15358f6e3..904ea4c8e452841f4bbbf2c2b29b53ae84b84247 100644 (file)
Binary files a/data/textures/StatusBars.png and b/data/textures/StatusBars.png differ
index 67ec31b637cd1c6ae9bcc73865fa6dd2402bb2e6..677aa21ac9accdd6d5c1f6225bf3433e3c88be35 100644 (file)
Binary files a/data/textures/TowerBlock1.png and b/data/textures/TowerBlock1.png differ
index f665ff6c444135ee45c422b2b522be5d27f1824f..fc9fc35189de544451170532449a06e610bb2e91 100644 (file)
Binary files a/data/textures/Trees.png and b/data/textures/Trees.png differ
diff --git a/data/tilemaps/AlienWarrior.lua b/data/tilemaps/AlienWarrior.lua
deleted file mode 100644 (file)
index a98bb7c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/BackgroundFar.lua b/data/tilemaps/BackgroundFar.lua
deleted file mode 100644 (file)
index 1128761..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 1
-tiles_t = 1
-min_filter = LINEAR
-mag_filter = LINEAR
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/BackgroundNear.lua b/data/tilemaps/BackgroundNear.lua
deleted file mode 100644 (file)
index 26d50f2..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 1
-tiles_t = 1
-min_filter = LINEAR
-mag_filter = LINEAR
-wrap_s = REPEAT
-wrap_t = REPEAT
diff --git a/data/tilemaps/BigExplosion.lua b/data/tilemaps/BigExplosion.lua
deleted file mode 100644 (file)
index 2acfc3c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 8
-tiles_t = 1
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/Bonuses.lua b/data/tilemaps/Bonuses.lua
deleted file mode 100644 (file)
index e2cf01d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/Building.lua b/data/tilemaps/Building.lua
deleted file mode 100644 (file)
index e2cf01d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/Font.lua b/data/tilemaps/Font.lua
deleted file mode 100644 (file)
index d3670e1..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 8
-tiles_t = 8
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/Heroine.lua b/data/tilemaps/Heroine.lua
deleted file mode 100644 (file)
index a98bb7c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/Jetbot.lua b/data/tilemaps/Jetbot.lua
deleted file mode 100644 (file)
index d62e532..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 4
-tiles_t = 2
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/Particles.lua b/data/tilemaps/Particles.lua
deleted file mode 100644 (file)
index e2cf01d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/RobotTrooper.lua b/data/tilemaps/RobotTrooper.lua
deleted file mode 100644 (file)
index a98bb7c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 8
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/Scenery.lua b/data/tilemaps/Scenery.lua
deleted file mode 100644 (file)
index d42abc4..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 4
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = REPEAT
-wrap_t = REPEAT
diff --git a/data/tilemaps/StatusBars.lua b/data/tilemaps/StatusBars.lua
deleted file mode 100644 (file)
index 0b6a8fe..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-tiles_s = 4
-tiles_t = 1
-min_filter = NEAREST
-mag_filter = NEAREST
diff --git a/data/tilemaps/TowerBlock1.lua b/data/tilemaps/TowerBlock1.lua
deleted file mode 100644 (file)
index e31c4cc..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 4
-tiles_t = 4
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
diff --git a/data/tilemaps/Trees.lua b/data/tilemaps/Trees.lua
deleted file mode 100644 (file)
index 4f97474..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-tiles_s = 2
-tiles_t = 1
-min_filter = NEAREST
-mag_filter = NEAREST
-wrap_s = CLAMP
-wrap_t = CLAMP
index 598361bf97143c28cb1ca2d78d495692d50f6d31..477997037230b125635f28cf4980d8ffa3d3cc3a 100644 (file)
@@ -29,7 +29,7 @@
 #include <map>
 #include <vector>
 
-#include <Moof/Library.hh>
+#include <Moof/Manager.hh>
 #include <Moof/Log.hh>
 #include <Moof/Script.hh>
 
@@ -47,7 +47,7 @@
 
 class Animation::Impl
 {
-       friend class Animation;
+public:
 
        /**
         * Contains "global" animation data for the various animations which get
@@ -55,10 +55,9 @@ class Animation::Impl
         * which wants to use these loaded sequences.
         */
 
-       class Data : public Mf::Library<Data>
+       class Data : public Mf::Manager<Data>
        {
-               friend class Impl;
-               friend class Mf::Library<Data>;
+       public:
 
                /**
                 * A frame of an animation sequence.  A frame is merely an index which
@@ -68,7 +67,7 @@ class Animation::Impl
 
                class Frame
                {
-                       friend class Impl;
+               public:
 
                        unsigned        mIndex;                                 ///< Frame index.
                        Mf::Scalar      mDuration;                              ///< Frame duration.
@@ -98,9 +97,9 @@ class Animation::Impl
                 * that they should be played.
                 */
 
-               struct Sequence
+               class Sequence
                {
-                       friend class Impl;
+               public:
 
                        std::vector<Frame>      mFrames;                ///< List of frames.
                        Mf::Scalar                      mDelay;                 ///< Scale frame durations.
@@ -161,10 +160,10 @@ class Animation::Impl
                 * individual sequence.
                 */
 
-               void loadFromFile()
+               void init(const std::string& name)
                {
                        Mf::Script script;
-                       std::string filePath = Animation::getPath(getName());
+                       std::string filePath = Animation::getPath(name);
 
                        script.importBaseLibrary();
                        importLogFunctions(script);
@@ -186,7 +185,7 @@ class Animation::Impl
                        std::string nameStr;
                        name.get(nameStr);
 
-                       sequences.insert(std::pair<std::string,Sequence>(nameStr,
+                       mSequences.insert(std::pair<std::string,Sequence>(nameStr,
                                                Sequence(script, table)));
 
                        return 0;
@@ -208,18 +207,7 @@ class Animation::Impl
                }
 
 
-               /**
-                * Construction is initialization.  The animation class data container
-                * registers itself as a mippleton and then loads the animation data.
-                */
-
-               explicit Data(const std::string& name) :
-                       Mf::Library<Data>(name)
-               {
-                       loadFromFile();
-               }
-
-               std::map<std::string,Sequence> sequences;               ///< List of sequences.
+               std::map<std::string,Sequence> mSequences;              ///< List of sequences.
        };
 
 
@@ -246,9 +234,9 @@ class Animation::Impl
        {
                std::map<std::string,Data::Sequence>::iterator it;
 
-               it = mData->sequences.find(name);
+               it = mData->mSequences.find(name);
 
-               if (it != mData->sequences.end())
+               if (it != mData->mSequences.end())
                {
                        mCurrentSequence = &(*it).second;
                        mFrameCounter = 0;
index 9da4344aab361bd369eb26f41f56677eff2a5689..2290e3c2797a5d1023f63ddc4335921c04dfc602 100644 (file)
@@ -126,11 +126,10 @@ void Character::draw(Mf::Scalar alpha) const
        //glColor3f(1.0f, 1.0f, 1.0f);
        tilemap.bind();
 
-       Tilemap::Index frame = animation.getFrame();
+       Mf::Texture::TileIndex frame = animation.getFrame();
+       Mf::Texture::Orientation orientation = Mf::Texture::NORMAL;
 
-       Tilemap::Orientation orientation = Tilemap::NORMAL;
-
-       if (mState.velocity[0] < 0.0) orientation = Tilemap::REVERSE;
+       if (mState.velocity[0] < 0.0) orientation = Mf::Texture::REVERSE;
 
        Mf::Scalar coords[8];
        tilemap.getTileCoords(frame, coords, orientation);
index 6507906d067cf9c3d78162dd6a32916fafa9b76e..82804babf16b32b37ae4db339229398ef3a8983b 100644 (file)
@@ -36,9 +36,9 @@
 #include <Moof/Math.hh>
 #include <Moof/RigidBody.hh>
 #include <Moof/Sphere.hh>
+#include <Moof/Texture.hh>
 
 #include "Animation.hh"
-#include "Tilemap.hh"
 
 
 
@@ -67,7 +67,7 @@ public:
 
        //virtual int getOctant(const Mf::Aabb<3>& aabb) const;
 
-       Tilemap         tilemap;
+       Mf::Texture     tilemap;
        Animation       animation;
 };
 
index 1fdf39bcd0075874027fc9c129b6ad00f5486ede..f8f40d91c7ab79a114a9734f4b2a308153b34dcb 100644 (file)
@@ -33,7 +33,7 @@
 #include "Hud.hh"
 
 
-ProgressBar::ProgressBar(const Tilemap& tilemap, Tilemap::Index index) :
+ProgressBar::ProgressBar(const Mf::Texture& tilemap, Mf::Texture::TileIndex index) :
        mProgress(0.0),
        mTilemap(tilemap)
 {
@@ -120,8 +120,8 @@ void ProgressBar::draw(Mf::Scalar alpha) const
 
 Hud::Hud(GameState& state) :
        mState(state),
-       mBar1(Tilemap("StatusBars"), 0),
-       mBar2(Tilemap("StatusBars"), 2),
+       mBar1(Mf::Texture("StatusBars"), 0),
+       mBar2(Mf::Texture("StatusBars"), 2),
        mFont("Font")
 {
        ASSERT(Mf::video && "no current video context from which to get dimensions");
index 75ced92d0543816298435210b09222d3bda0d24a..2262b062983ae1d8faedc89bdc0cdcda21aaa270 100644 (file)
@@ -38,9 +38,9 @@
 #include <Moof/Layer.hh>
 #include <Moof/Math.hh>
 #include <Moof/Rectangle.hh>
+#include <Moof/Texture.hh>
 
 #include "GameState.hh"
-#include "Tilemap.hh"
 
 
 // TODO this stuff is still just hacked up
@@ -49,7 +49,7 @@ class ProgressBar : public Mf::Drawable
 {
 public:
 
-       ProgressBar(const Tilemap& tilemap, Tilemap::Index index);
+       ProgressBar(const Mf::Texture& tilemap, Mf::Texture::TileIndex index);
 
        void resize(const Mf::Rectangle& rect);
 
@@ -64,7 +64,7 @@ private:
        Mf::Vector2     mVertices[8];
        Mf::Scalar      mWidth;
 
-       Tilemap         mTilemap;
+       Mf::Texture     mTilemap;
        Mf::Scalar      mTexCoords[8];
        Mf::Scalar      mMidCoords[2];
 };
@@ -112,7 +112,7 @@ private:
        ProgressBar     mBar2;
 
        unsigned        mNumber;
-       Tilemap         mFont;
+       Mf::Texture     mFont;
 
        Mf::Matrix4     mProjection;
 };
index 3c3fc5312c697cb34540d039fb8c9f9dfdbdc00b..58b31118846ec4e601bdf0042cfba99ee818d27e 100644 (file)
@@ -35,10 +35,10 @@ libmoof_a_SOURCES = \
                                        Moof/Image.hh \
                                        Moof/Interpolator.hh \
                                        Moof/Layer.hh \
-                                       Moof/Library.hh \
                                        Moof/Line.hh \
                                        Moof/Log.cc \
                                        Moof/Log.hh \
+                                       Moof/Manager.hh \
                                        Moof/Math.hh \
                                        Moof/ModalDialog.hh \
                                        Moof/Octree.hh \
@@ -100,8 +100,6 @@ yoink_SOURCES = \
                                Main.hh \
                                Scene.cc \
                                Scene.hh \
-                               Tilemap.cc \
-                               Tilemap.hh \
                                TilemapFont.cc \
                                TilemapFont.hh \
                                TitleLayer.cc \
index 90027307c081f4050411713d47e24e2bb57a5c87..190f4c8d4d3bd064735c2f07da709c926fb77ddf 100644 (file)
@@ -32,7 +32,6 @@
 #include <list>
 #include <string>
 
-#include <AL/alc.h>
 #include <SDL/SDL.h>
 #include "fastevents.h"
 
@@ -368,9 +367,7 @@ class Backend_
 {
 public:
 
-       Backend_() :
-               mAlDevice(0),
-               mAlContext(0)
+       Backend_()
        {
 #if defined(_WIN32) || defined(__WIN32__)
                if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
@@ -397,31 +394,11 @@ public:
                        return; // fatal
                }
 
-               mAlDevice = alcOpenDevice(0);
-               mAlContext = alcCreateContext(mAlDevice, 0);
-               if (!mAlDevice || !mAlContext)
-               {
-                       const char* error = alcGetString(mAlDevice,alcGetError(mAlDevice));
-                       gError.init(Error::OPENAL_INIT, error);
-                       return;
-               }
-               else
-               {
-                       alcMakeContextCurrent(mAlContext);
-                       logInfo << "opened sound device `"
-                                        << alcGetString(mAlDevice, ALC_DEFAULT_DEVICE_SPECIFIER)
-                                        << "'" << std::endl;
-               }
-
                gError.init(Error::NONE);
        }
 
        ~Backend_()
        {
-               alcMakeContextCurrent(0);
-               alcDestroyContext(mAlContext);
-               alcCloseDevice(mAlDevice);
-
                FE_Quit();
                SDL_Quit();
        }
@@ -443,17 +420,13 @@ public:
                }
        }
 
-       static bool check(Error& error)
+       static const Error& getError()
        {
-               error = gError;
-               return error.code() == Error::NONE;
+               return gError;
        }
 
 private:
 
-       ALCdevice*              mAlDevice;
-       ALCcontext*             mAlContext;
-
        static Error    gError;
        static int              gRetainCount;
        static BackendP gInstance;
@@ -474,9 +447,14 @@ Backend::~Backend()
        Backend_::release();
 }
 
-bool Backend::check(Error& error)
+bool Backend::isInitialized()
+{
+       return getError().code() == Error::NONE;
+}
+
+const Error& Backend::getError()
 {
-       return Backend_::check(error);
+       return Backend_::getError();
 }
 
 
index fcb0340f3e5fbb93aec01ed6addbcc2a740c7848..109999a7913a26adfe6d16646be19b13a895242d 100644 (file)
@@ -100,7 +100,8 @@ public:
        Backend();
        ~Backend();
 
-       static bool check(Error& error);
+       static bool isInitialized();
+       static const Error& getError();
 };
 
 
index 05c637705a96d77c91169803e41ae4b1b7f8f6fc..c452ae6df836f8351660b5cd0e460239f1932697 100644 (file)
@@ -57,7 +57,7 @@ public:
                UNKNOWN_IMAGE_FORMAT,           // name of resource
        };
 
-       explicit Error(unsigned code, const std::string& what = "")
+       explicit Error(unsigned code = NONE, const std::string& what = "")
        {
                init(code, what);
        }
@@ -70,7 +70,7 @@ public:
                mCode = code;
        }
 
-       virtual void raise()
+       virtual void raise() const
        {
                throw *this;
        }
@@ -85,8 +85,9 @@ public:
                return mWhat;
        }
 
-       bool isError() const throw()
+       operator bool () const
        {
+               // resolves to true if error code is not NONE
                return mCode != NONE;
        }
 
index 51e7ad836962139c55d29543f15dc60a22cac559..ee44dd75dcacb319f331411df02e9c28da92407b 100644 (file)
 #include <cstdio>              // FILE
 #include <cstring>             // strncmp
 
+#include <boost/algorithm/string.hpp>
+
 #include <SDL/SDL.h>
 #include <png.h>
 
 #include "Core.hh"
 #include "Error.hh"
 #include "Image.hh"
-#include "Library.hh"
 #include "Log.hh"
+#include "Manager.hh"
 
 
 namespace Mf {
 
 
-class Image::Impl : public Library<Impl>
+class Image::Impl : public Manager<Impl>
 {
 public:
 
-       explicit Impl(const std::string& name, bool flipped = false) :
-               Library<Impl>(name),
+       explicit Impl() :
                mContext(0),
-               mPixels(0)
-       {
-               init(getName(), flipped);
-       }
+               mPixels(0) {}
 
        ~Impl()
        {
@@ -89,23 +87,12 @@ public:
        }
 
 
-       SDL_Surface*    mContext;
-       char*                   mPixels;
-
-       unsigned                mDepth;
-       GLuint                  mColorMode;
-
-       std::string             mComment;
-
-
-private:
-
-       Backend                 mBackend;
-
-       bool init(const std::string& filePath, bool flipped)
+       bool init(const std::string& name, bool flipped = false)
        {
-               logInfo("opening image file...");
-               FILE* fp = fopen(filePath.c_str(), "rb");
+               std::string path = Image::getPath(name);
+
+               logInfo << "opening image file " << path << std::endl;
+               FILE* fp = fopen(path.c_str(), "rb");
                if (!fp) return false;
 
                png_byte        signature[8];
@@ -185,7 +172,7 @@ private:
                logInfo << "num texts: " << numTexts << std::endl;
                for (int i = 0; i < numTexts; ++i)
                {
-                       if (strncmp(texts[i].key, "Comment", 7) == 0)
+                       if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
                        {
                                mComment = texts[i].text;
                                break;
@@ -248,6 +235,19 @@ private:
 
                return mContext;
        }
+
+
+       SDL_Surface*    mContext;
+       char*                   mPixels;
+
+       unsigned                mDepth;
+       GLuint                  mColorMode;
+
+       std::string             mComment;
+
+private:
+
+       Backend                 mBackend;
 };
 
 
@@ -281,7 +281,7 @@ unsigned Image::getPitch() const
        return mImpl->mContext->pitch;
 }
 
-GLuint Image::getColorMode() const
+GLuint Image::getMode() const
 {
        return mImpl->mColorMode;
 }
@@ -315,11 +315,19 @@ void Image::setAsIcon() const
 }
 
 
-
 std::string Image::getPath(const std::string& name)
 {
-       std::string path = Resource::getPath("images/" + name + ".png");
-       return path;
+       if (boost::find_last(name, ".png"))
+       {
+               return Resource::getPath(name);
+       }
+       else
+       {
+               std::string path("images/");
+               path += name;
+               path += ".png";
+               return Resource::getPath(path);
+       }
 }
 
 
index 5f7c5a3205c746e8ca091ba6568ca7999561fef9..e958edcba2cccb0103b7616477097721d5a7e907 100644 (file)
 namespace Mf {
 
 
+class Image;
+typedef boost::shared_ptr<Image> ImageP;
+
 class Image : public Resource
 {
 public:
 
+       static ImageP alloc(const std::string& name)
+       {
+               return ImageP(new Image(name));
+       }
+
        explicit Image(const std::string& name);
 
        bool isValid() const;
@@ -51,7 +59,7 @@ public:
 
        unsigned getDepth() const;
        unsigned getPitch() const;
-       GLuint getColorMode() const;
+       GLuint getMode() const;
 
        std::string getComment() const;
 
diff --git a/src/Moof/Library.hh b/src/Moof/Library.hh
deleted file mode 100644 (file)
index c215567..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-
-/*******************************************************************************
-
- Copyright (c) 2009, Charles McGarvey
- All rights reserved.
- Redistribution   and   use  in  source  and  binary  forms,  with  or  without
- modification, are permitted provided that the following conditions are met:
-   * Redistributions  of  source  code  must retain the above copyright notice,
-     this list of conditions and the following disclaimer.
-   * Redistributions  in binary form must reproduce the above copyright notice,
-     this  list of conditions and the following disclaimer in the documentation
-     and/or other materials provided with the distribution.
- THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*******************************************************************************/
-
-#ifndef _MOOF_LIBRARY_HH_
-#define _MOOF_LIBRARY_HH_
-
-/**
- * @file Library.hh
- * A library is a collection of named objects of the same type.  Libraries use
- * reference counting to automagically delete objects which no longer have any
- * interested code.
- */
-
-#include <string>
-
-#include <boost/shared_ptr.hpp>
-
-#include <Moof/Hash.hh>
-
-
-namespace Mf {
-
-
-template <class T>
-class Library
-{
-       typedef std::pair<unsigned,T*>                                                  PtrValue;
-       typedef stlplus::hash<std::string,PtrValue,getHash>             PtrMap;
-
-       static PtrMap   mPtrMap;
-       std::string             mName;
-
-       static T* retain(const std::string& name)
-       {
-               typename PtrMap::iterator it = mPtrMap.find(name);
-
-               if (it != mPtrMap.end())
-               {
-                       ++((*it).second.first);
-                       return (*it).second.second;
-               }
-               else
-               {
-                       T* newObj(new T(name));
-                       if (newObj)
-                       {
-                               mPtrMap.insert(std::make_pair(name, std::make_pair(1, newObj)));
-                       }
-                       return newObj; 
-               }
-       }
-
-       static void release(T* obj)
-       {
-               releaseByName(obj->mName);
-       }
-
-       static void releaseByName(const std::string& name)
-       {
-               typename PtrMap::iterator it;
-
-               if ((it = mPtrMap.find(name)) != mPtrMap.end() &&
-                               --(*it).second.first == 0)
-               {
-                       delete (*it).second.second;
-                       mPtrMap.erase((*it).first);
-               }
-       }
-
-public:
-
-       explicit Library(const std::string& name) :
-               mName(name) {}
-
-       const std::string& getName() const
-       {
-               return mName;
-       }
-
-       static boost::shared_ptr<T> getInstance(const std::string& name)
-       {
-               return boost::shared_ptr<T>(retain(name), &release);
-       }
-};
-
-template <class T>
-stlplus::hash< std::string,std::pair<unsigned,T*>,getHash >
-       Library<T>::mPtrMap;
-
-
-} // namespace Mf
-
-#endif // _MOOF_LIBRARY_HH_
-
-/** vim: set ts=4 sw=4 tw=80: *************************************************/
-
index ca3ecfec8117fb93386edf6128c507d5ae41bcc2..f8f05baf75717aa376ae85eaebc950fc79d8db5e 100644 (file)
 #include <list>
 #include <string>
 
+#include <boost/algorithm/string.hpp>
+
 #include <AL/al.h>
+#include <AL/alc.h>
 #include <vorbis/codec.h>
 #include <vorbis/vorbisfile.h>
 
-#include "Core.hh"
 #include "Error.hh"
-#include "Library.hh"
+#include "Manager.hh"
 #include "Log.hh"
 #include "Sound.hh"
 #include "Timer.hh"
@@ -62,16 +64,14 @@ public:
        class Buffer;
        typedef boost::shared_ptr<Buffer> BufferP;
        
-       class Buffer : public Library<Buffer>
+       class Buffer : public Manager<Buffer>
        {
        public:
 
-               explicit Buffer(const std::string& name) :
-                       Library<Buffer>(name),
+               Buffer() :
                        mBuffer(-1)
                {
                        mOggStream.datasource = 0;
-                       openFile();
                }
 
                ~Buffer()
@@ -84,7 +84,7 @@ public:
                }
 
 
-               void openFile()
+               void init(const std::string& name)
                {
                        if (mOggStream.datasource)
                        {
@@ -92,14 +92,13 @@ public:
                                mOggStream.datasource = 0;
                        }
 
-                       std::string filePath = Sound::getPath(getName());
-                       int result = ov_fopen((char*)filePath.c_str(), &mOggStream);
+                       std::string path = Sound::getPath(name);
+                       int result = ov_fopen((char*)path.c_str(), &mOggStream);
 
                        if (result < 0)
                        {
-                               logWarning << "error while loading sound "
-                                                  << getName() << std::endl;
-                               throw Error(Error::UNKNOWN_AUDIO_FORMAT, getName());
+                               logWarning << "couldn't load sound: " << path << std::endl;
+                               throw Error(Error::UNKNOWN_AUDIO_FORMAT, path);
                        }
 
                        vorbis_info* vorbisInfo = ov_info(&mOggStream, -1);
@@ -110,7 +109,7 @@ public:
 
                void loadAll(ALuint source)
                {
-                       if (!mOggStream.datasource) openFile();
+                       if (!mOggStream.datasource) init(getName());
                        if (!mOggStream.datasource) return;
 
                        char data[BUFFER_SIZE];
@@ -180,7 +179,7 @@ public:
 
                void rewind()
                {
-                       if (!mOggStream.datasource) openFile();
+                       if (!mOggStream.datasource) init(getName());
                        else ov_raw_seek(&mOggStream, 0);
                }
 
@@ -207,6 +206,8 @@ public:
 
        void init()
        {
+               retainBackend();
+
                mIsLoaded = false;
                mIsPlaying = false;
                mIsLooping = false;
@@ -233,6 +234,8 @@ public:
                        alDeleteBuffers(1, &mBuffers.back());
                        mBuffers.pop_back();
                }
+
+               releaseBackend();
        }
 
 
@@ -426,6 +429,39 @@ public:
                // than a timer, probably as a compile-time option
        }
 
+       static void retainBackend()
+       {
+               if (gRetainCount++ == 0)
+               {
+                       gAlDevice = alcOpenDevice(0);
+                       gAlContext = alcCreateContext(gAlDevice, 0);
+                       if (!gAlDevice || !gAlContext)
+                       {
+                               const char* error = alcGetString(gAlDevice,
+                                               alcGetError(gAlDevice));
+                               logError << "audio subsystem initialization failure: "
+                                                << error << std::endl;
+                       }
+                       else
+                       {
+                               alcMakeContextCurrent(gAlContext);
+                               logInfo << "opened sound device `"
+                                               << alcGetString(gAlDevice, ALC_DEFAULT_DEVICE_SPECIFIER)
+                                               << "'" << std::endl;
+                       }
+               }
+       }
+
+       static void releaseBackend()
+       {
+               if (--gRetainCount == 0)
+               {
+                       alcMakeContextCurrent(0);
+                       alcDestroyContext(gAlContext);
+                       alcCloseDevice(gAlDevice);
+               }
+       }
+
 
        ALuint                                  mSource;
        std::list<ALuint>               mBuffers;
@@ -438,9 +474,15 @@ public:
 
        Timer                                   mStreamTimer;
 
-       Backend                                 mBackend;
+       static unsigned                 gRetainCount;
+       static ALCdevice*               gAlDevice;
+       static ALCcontext*              gAlContext;
 };
 
+unsigned       Sound::Impl::gRetainCount = 0;
+ALCdevice*     Sound::Impl::gAlDevice = 0;
+ALCcontext*    Sound::Impl::gAlContext = 0;
+
 
 Sound::Sound() :
        // pass through
@@ -550,8 +592,17 @@ void Sound::setListenerOrientation(const Vector3& forward, const Vector3& up)
 
 std::string Sound::getPath(const std::string& name)
 {
-       std::string path = Resource::getPath("sounds/" + name + ".ogg");
-       return path;
+       if (boost::find_last(name, ".ogg"))
+       {
+               return Resource::getPath(name);
+       }
+       else
+       {
+               std::string path("sounds/");
+               path += name;
+               path += ".ogg";
+               return Resource::getPath(path);
+       }
 }
 
 
index 5341af33d32085632d605029705fa21b4d1c3b7e..801acbae227f89d7a58970a1e97ed836a008391a 100644 (file)
 #include <cstdio>              // FILE
 #include <cstring>             // strncmp
 
+#include <boost/algorithm/string.hpp>
 #include <boost/bind.hpp>
 
 #include "Dispatch.hh"
-#include "Core.hh"
 #include "Error.hh"
-#include "Image.hh"
-#include "Library.hh"
+#include "Manager.hh"
 #include "Log.hh"
 #include "OpenGL.hh"
+#include "Script.hh"
 #include "Texture.hh"
 #include "Video.hh"
 
@@ -50,11 +50,11 @@ namespace Mf {
  * which is worth having in memory.  The image data itself is not worth keeping
  * in memory if the texture has been loaded to GL, but the name of the resource
  * is retained so that it can be reloaded if necessary.  The implementation is a
- * library so that multiple texture objects can share the same internal objects
+ * manager so that multiple texture objects can share the same internal objects
  * and avoid having duplicate textures loaded to GL.
  */
 
-class Texture::Impl : public Library<Impl>
+class Texture::Impl : public Manager<Impl>
 {
 
        /**
@@ -103,33 +103,40 @@ class Texture::Impl : public Library<Impl>
                return value;
        }
 
+
+       static void bindScriptConstants(Mf::Script& script)
+       {
+               script.push(GL_CLAMP); script.set("CLAMP");
+               script.push(GL_REPEAT); script.set("REPEAT");
+               script.push(GL_LINEAR); script.set("LINEAR");
+               script.push(GL_NEAREST); script.set("NEAREST");
+               script.push(GL_LINEAR_MIPMAP_LINEAR); script.set("LINEAR_MIPMAP_LINEAR");
+               script.push(GL_LINEAR_MIPMAP_NEAREST); script.set("LINEAR_MIPMAP_NEAREST");
+               script.push(GL_NEAREST_MIPMAP_LINEAR); script.set("NEAREST_MIPMAP_LINEAR");
+               script.push(GL_NEAREST_MIPMAP_NEAREST); script.set("NEAREST_MIPMAP_NEAREST");
+       }
+
 public:
 
        /**
         * Construction is initialization.
         */
 
-       explicit Impl(const std::string& name) :
-               Library<Impl>(name),
-               //mContext(0),
-               mImage(Texture::getPath(getName())),
-               mWidth(0),
-               mHeight(0),
-               mMode(0),
+       Impl() :
                mMinFilter(GL_NEAREST),
                mMagFilter(GL_NEAREST),
                mWrapS(GL_CLAMP),
                mWrapT(GL_CLAMP),
+               mTilesS(1),
+               mTilesT(1),
                mObject(0)
        {
                // make sure we have a video context
-               //ASSERT(video && "cannot load textures without a current video context");
+               ASSERT(video && "cannot load textures without a current video context");
 
                // we want to know when the GL context is recreated
                mDispatchHandler = core.addHandler("video.newcontext",
                                boost::bind(&Impl::contextRecreated, this));
-
-               loadFromFile();
        }
 
        ~Impl()
@@ -214,19 +221,55 @@ public:
         * @return Image data.
         */
 
-       void loadFromFile()
+       void init(const std::string& name)
        {
-               if (!mImage.isValid())
+               std::string path = Texture::getPath(name);
+
+               mImage = Image::alloc(path);
+               if (!mImage->isValid())
+               {
+                       logWarning << "texture not found: " << path << std::endl;
+                       Error(Error::RESOURCE_NOT_FOUND, path).raise();
+               }
+
+               mImage->flip();
+
+               Mf::Script script;
+
+               importLogFunctions(script);
+               bindScriptConstants(script);
+
+               if (script.doString(mImage->getComment()) != Mf::Script::SUCCESS)
                {
-                       logWarning << "texture not found: " << getName() << std::endl;
-                       throw Error(Error::RESOURCE_NOT_FOUND, getName());
+                       std::string str;
+                       script[-1].get(str);
+                       Mf::logWarning(str);
                }
+               else
+               {
+                       Mf::logInfo << "loading tiles from texture " << path << std::endl;
+
+                       Mf::Script::Slot globals = script.getGlobalTable();
+                       Mf::Script::Slot top = script[-1];
 
-               mImage.flip();
+                       globals.pushField("tiles_s");
+                       top.get(mTilesS);
 
-               mWidth = mImage.getWidth();
-               mHeight = mImage.getHeight();
-               mMode = mImage.getColorMode();
+                       globals.pushField("tiles_t");
+                       top.get(mTilesT);
+
+                       globals.pushField("min_filter");
+                       top.get(mMinFilter);
+
+                       globals.pushField("mag_filter");
+                       top.get(mMagFilter);
+
+                       globals.pushField("wrap_s");
+                       top.get(mWrapS);
+
+                       globals.pushField("wrap_t");
+                       top.get(mWrapT);
+               }
        }
 
 
@@ -243,8 +286,6 @@ public:
                        return;
                }
 
-               //if (!mContext) loadFromFile();
-
                glGenTextures(1, &mObject);
                glBindTexture(GL_TEXTURE_2D, mObject);
 
@@ -253,20 +294,17 @@ public:
                (
                        GL_TEXTURE_2D,
                        0,
-                       mMode,
+                       mImage->getMode(),
                        //3,
-                       mWidth,
-                       mHeight,
+                       mImage->getWidth(),
+                       mImage->getHeight(),
                        0,
-                       mMode,
+                       mImage->getMode(),
                        GL_UNSIGNED_BYTE,
-                       mImage.getPixels()
+                       mImage->getPixels()
                );
 
                setProperties();
-
-               //SDL_FreeSurface(mContext);
-               //mContext = 0;
        }
 
 
@@ -326,15 +364,35 @@ public:
        }
 
 
-       Image                           mImage;
-       unsigned                        mWidth;                 ///< Horizontal dimension of the image.
-       unsigned                        mHeight;                ///< Vertical dimension.
+       bool getTileCoords(Texture::TileIndex index, Scalar coords[8]) const
+       {
+               // make sure the index represents a real tile
+               if (index >= mTilesS * mTilesT) return false;
+
+               Scalar w = 1.0 / Scalar(mTilesS);
+               Scalar h = 1.0 / Scalar(mTilesT);
+
+               coords[0] = Scalar(index % mTilesS) * w;
+               coords[1] = (Scalar(mTilesT - 1) -
+                               Scalar(index / mTilesS)) * h;
+               coords[2] = coords[0] + w;
+               coords[3] = coords[1];
+               coords[4] = coords[2];
+               coords[5] = coords[1] + h;
+               coords[6] = coords[0];
+               coords[7] = coords[5];
+
+               return true;
+       }
+
+       ImageP                          mImage;
 
-       GLuint                          mMode;                  ///< GL_RGB or GL_RGBA.
-       GLuint                          mMinFilter;             ///< Minifcation filter.
+       GLuint                          mMinFilter;             ///< Minification filter.
        GLuint                          mMagFilter;             ///< Magnification filter.
        GLuint                          mWrapS;                 ///< Wrapping behavior horizontally.
        GLuint                          mWrapT;                 ///< Wrapping behavior vertically.
+       unsigned                        mTilesS;
+       unsigned                        mTilesT;
 
        GLuint                          mObject;                ///< GL texture handle.
        static GLuint           gObject;                ///< Global GL texture handle.
@@ -346,6 +404,7 @@ GLuint Texture::Impl::gObject = 0;
 
 
 Texture::Texture(const std::string& name) :
+       Image(Texture::getPath(name)),
        // pass through
        mImpl(Texture::Impl::getInstance(name)) {}
 
@@ -379,19 +438,6 @@ void Texture::resetBind()
 }
 
 
-unsigned Texture::getWidth() const
-{
-       // pass through
-       return mImpl->mWidth;
-}
-
-unsigned Texture::getHeight() const
-{
-       // pass through
-       return mImpl->mHeight;
-}
-
-
 void Texture::setMinFilter(GLuint filter)
 {
        // pass through
@@ -417,10 +463,54 @@ void Texture::setWrapT(GLuint wrap)
 }
 
 
+bool Texture::getTileCoords(TileIndex index, Scalar coords[8]) const
+{
+       // pass through
+       return mImpl->getTileCoords(index, coords);
+}
+
+bool Texture::getTileCoords(TileIndex index, Scalar coords[8],
+               Orientation orientation) const
+{
+       if (getTileCoords(index, coords))
+       {
+               if (orientation & FLIP)
+               {
+                       // this looks kinda weird, but it's just swapping in a way that
+                       // doesn't require an intermediate variable
+                       coords[1] = coords[5];
+                       coords[5] = coords[3];
+                       coords[3] = coords[7];
+                       coords[7] = coords[5];
+               }
+               if (orientation & REVERSE)
+               {
+                       coords[0] = coords[2];
+                       coords[2] = coords[6];
+                       coords[4] = coords[6];
+                       coords[6] = coords[0];
+               }
+
+               return true;
+       }
+
+       return false;
+}
+
+
 std::string Texture::getPath(const std::string& name)
 {
-       std::string path = Resource::getPath("textures/" + name + ".png");
-       return path;
+       if (boost::find_last(name, ".png"))
+       {
+               return Resource::getPath(name);
+       }
+       else
+       {
+               std::string path("textures/");
+               path += name;
+               path += ".png";
+               return Resource::getPath(path);
+       }
 }
 
 
index 4e311ea53a05f75689b0e7b2c31dfedf4b573135..41add2bca92638f135dc1b58abea615cb32f3d72 100644 (file)
@@ -36,8 +36,8 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <Moof/Image.hh>
 #include <Moof/OpenGL.hh>
-#include <Moof/Resource.hh>
 
 
 namespace Mf {
@@ -47,10 +47,26 @@ class Texture;
 typedef boost::shared_ptr<Texture> TextureP;
 
 
-class Texture : public Resource
+class Texture : public Image
 {
 public:
 
+       /**
+        * Possible orientations for texture coordinates.
+        */
+
+       typedef unsigned TileIndex;
+       static const TileIndex NO_TILE = -1;
+
+       typedef enum
+       {
+               NORMAL =                        0,                      ///< Normal orientation.
+               FLIP =                          1,                      ///< Flip over a horizontal axis.
+               REVERSE =                       2,                      ///< Flip over a vertical axis.
+               FLIP_AND_REVERSE =      3                       ///< Flip over both.
+       } Orientation;
+
+
        static TextureP alloc(const std::string& name)
        {
                return TextureP(new Texture(name));
@@ -63,14 +79,38 @@ public:
 
        static void resetBind();
 
-       unsigned getWidth() const;
-       unsigned getHeight() const;
-
        void setMinFilter(GLuint filter);
        void setMagFilter(GLuint filter);
        void setWrapS(GLuint wrap);
        void setWrapT(GLuint wrap);
 
+
+       /**
+        * Calculate texture coordinates for a tile at a certain index.  Tiles are
+        * indexed start with zero as the to-left tile and moving across, then down.
+        * @param index The tile index.
+        * @param coords An array of scalars where the texture coordinates will be
+        * stored after this call.  The first coordinate (u,v) will be in the first
+        * two places and so on until all four coordinates are stored, therefore
+        * requiring enough room for an array of eight scalars.  The winding of the
+        * coordinates is always counter-clockwise (the GL default).
+        * @return True if index is valid, false otherwise.
+        */
+
+       bool getTileCoords(TileIndex index, Scalar coords[8]) const;
+
+
+       /**
+        * This version let's you specify an orientation that will be reflected in
+        * the texture coordinates.  This allows you to easily map a texture
+        * backwards or upside-down.
+        * @param what The orientation; can be flip, reverse, or flip_and_reverse.
+        * @return True if index is valid, false otherwise.
+        */
+
+       bool getTileCoords(TileIndex index, Scalar coords[8], Orientation what) const;
+
+
        static std::string getPath(const std::string& name);
 
 private:
index 62addb406dc804b7a31644ef586b3a43b3dd1dce..e0716091fcc7a4e4ce1d07a48328d9a1a77a66e3 100644 (file)
@@ -39,42 +39,39 @@ namespace Mf {
 
 Video::Video()
 {
-       init(mAttribs);
+       init();
 }
 
-Video::Video(const Attributes& attribs)
+Video::Video(const Attributes& attribs) :
+       mAttribs(attribs)
 {
-       init(attribs);
+       init();
 }
 
 Video::Video(const std::string& caption, const std::string& icon)
 {
-       if (mAttribs.caption == "Untitled")
-       {
-               mAttribs.caption = caption;
-       }
-       if (mAttribs.icon == "")
-       {
-               mAttribs.icon = icon;
-       }
+       mAttribs.caption = caption;
+       mAttribs.icon = icon;
 
-       init(mAttribs);
+       init();
 }
 
-void Video::init(const Attributes& attribs)
+void Video::init()
 {
+       Error error = Backend::getError();
+       if (error) error.raise();
+
        mContext = 0;
        mFlags = 0;
-       mAttribs = attribs;
 
-       setFull(attribs.fullscreen);
-       setResizable(attribs.resizable);
+       setFull(mAttribs.fullscreen);
+       setResizable(mAttribs.resizable);
        setOpenGLAttributes();
-       setCaption(attribs.caption);
+       setCaption(mAttribs.caption);
        setIcon();
-       setCursorVisible(attribs.cursorVisible);
-       setCursorGrab(attribs.cursorGrab);
-       setVideoMode(attribs.mode);
+       setCursorVisible(mAttribs.cursorVisible);
+       setCursorGrab(mAttribs.cursorGrab);
+       setVideoMode(mAttribs.mode);
 
        video = this;
 }
@@ -104,7 +101,7 @@ void Video::setOpenGLAttributes()
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, mAttribs.multisampleBuffers);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, mAttribs.multisampleSamples);
        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,       mAttribs.swapControl);
-       SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, mAttribs.hardwareonly);
+       SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, mAttribs.hardwareOnly);
 }
 
 
@@ -312,7 +309,7 @@ Video::Attributes::Attributes()
        multisampleBuffers = 0;
        multisampleSamples = 0;
        swapControl = false;
-       hardwareonly = false;
+       hardwareOnly = false;
        mode[0] = 640;
        mode[1] = 480;
        mode[2] = 0;
@@ -344,7 +341,7 @@ Video::Attributes::Attributes()
        settings.get("multiesamplebuffers", multisampleBuffers);
        settings.get("multiesamplesamples", multisampleSamples);
        settings.get("swapcontrol", swapControl);
-       settings.get("hardwareonly", hardwareonly);
+       settings.get("hardwareonly", hardwareOnly);
 
        if (!settings.get("caption", caption))
        {
@@ -364,7 +361,7 @@ Video::Attributes::Attributes()
                mode[0] = dimensions[0];
                mode[1] = dimensions[1];
        }
-       else if (fullscreen)
+       else if (fullscreen && Backend::isInitialized())
        {
                SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
 
index 0199bc51dc43e3a38508fae9da2d81149b4a7ac0..0cc1a4e66687c8c33ea7c7a8d7ea89e983142c20 100644 (file)
@@ -1,30 +1,13 @@
 
-/*******************************************************************************
-
- Copyright (c) 2009, Charles McGarvey
- All rights reserved.
- Redistribution   and   use  in  source  and  binary  forms,  with  or  without
- modification, are permitted provided that the following conditions are met:
-   * Redistributions  of  source  code  must retain the above copyright notice,
-     this list of conditions and the following disclaimer.
-   * Redistributions  in binary form must reproduce the above copyright notice,
-     this  list of conditions and the following disclaimer in the documentation
-     and/or other materials provided with the distribution.
- THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*******************************************************************************/
+/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+**]  All rights reserved.
+*
+* vi:ts=8 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
 
 #ifndef _MOOF_VIDEO_HH_
 #define _MOOF_VIDEO_HH_
@@ -62,7 +45,7 @@ public:
                long            multisampleBuffers;
                long            multisampleSamples;
                bool            swapControl;
-               bool            hardwareonly;
+               bool            hardwareOnly;
 
                // Window attributes
                std::string     caption;
@@ -77,11 +60,13 @@ public:
 
        private:
 
-               Backend         backend;
+               Backend         mBackend;
+
        };
 
 
-       static VideoP alloc(const std::string& caption, const std::string& icon)
+       static VideoP alloc(const std::string& caption,
+                                               const std::string& icon)
        {
                return VideoP(new Video(caption, icon));
        }
@@ -125,7 +110,7 @@ public:
 
 private:
 
-       void init(const Attributes& attribs);
+       void init();
 
        void recreateContext();
        void setOpenGLAttributes();
@@ -147,5 +132,3 @@ extern Video* video;
 
 #endif // _MOOF_VIDEO_HH_
 
-/** vim: set ts=4 sw=4 tw=80: *************************************************/
-
index aa2249c596ae0b462e9910db1bd93362ef8ceabd..45fc3a0ac9bc6f70397206fc49646546c1006614 100644 (file)
 #include <Moof/Aabb.hh>
 #include <Moof/Camera.hh>
 #include <Moof/Entity.hh>
-#include <Moof/Library.hh>
+#include <Moof/Manager.hh>
 #include <Moof/Line.hh>
 #include <Moof/Log.hh>
 #include <Moof/Math.hh>
 //#include <Moof/Octree.hh>
 #include <Moof/Script.hh>
 #include <Moof/Settings.hh>
+#include <Moof/Texture.hh>
 
 #include "Character.hh"
 #include "Scene.hh"
-#include "Tilemap.hh"
 
 
-struct Scene::Impl : public Mf::Library<Impl>
+struct Scene::Impl : public Mf::Manager<Impl>
 {
        struct Quad : public Mf::Entity
        {
@@ -57,7 +57,7 @@ struct Scene::Impl : public Mf::Library<Impl>
                };
 
                Quad(const Mf::Vector3* vertices[4], const std::string& texture,
-                               Tilemap::Index tileIndex) :
+                               Mf::Texture::TileIndex tileIndex) :
                        mTilemap(texture),
                        mBlending(false),
                        mFog(false),
@@ -143,7 +143,7 @@ struct Scene::Impl : public Mf::Library<Impl>
                Mf::Vector3             mVertices[4];
                Mf::Scalar              mTexCoords[8];
                
-               Tilemap                 mTilemap;
+               Mf::Texture             mTilemap;
 
                bool                    mBlending;
                bool                    mFog;
@@ -170,8 +170,8 @@ struct Scene::Impl : public Mf::Library<Impl>
        };
 
 
-       explicit Impl(const std::string& name) :
-               Mf::Library<Impl>(name) {}
+       void init(const std::string& name) {}
+
 
        void importSceneBindings(Mf::Script& script)
        {
@@ -372,7 +372,7 @@ struct Scene::Impl : public Mf::Library<Impl>
 
                                table.pushField(i);
 
-                               Tilemap::Index index;
+                               Mf::Texture::TileIndex index;
                                top.get(index);
 
                                script.pop();
@@ -380,7 +380,7 @@ struct Scene::Impl : public Mf::Library<Impl>
                                vertices[h][wPlus1] = Mf::demote(mTransform *
                                                Mf::Vector4(wPlus1, h, 0.0, 1.0));
 
-                               if (index == Tilemap::NO_TILE) continue;
+                               if (index == Mf::Texture::NO_TILE) continue;
 
                                const Mf::Vector3* corners[4] = {
                                        &vertices[h][w],
@@ -425,10 +425,10 @@ struct Scene::Impl : public Mf::Library<Impl>
                Mf::Script::Slot param = script[1];
                Mf::Script::Slot top = script[-1];
 
-               Tilemap::Index  index = 0;
-               int                             width = 1;
-               bool                    blending = false;
-               bool                    fog = false;
+               Mf::Texture::TileIndex  index = 0;
+               int                                             width = 1;
+               bool                                    blending = false;
+               bool                                    fog = false;
 
                if (param.isTable())
                {
diff --git a/src/Tilemap.cc b/src/Tilemap.cc
deleted file mode 100644 (file)
index dc3785a..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-
-/*******************************************************************************
-
- Copyright (c) 2009, Charles McGarvey
- All rights reserved.
- Redistribution   and   use  in  source  and  binary  forms,  with  or  without
- modification, are permitted provided that the following conditions are met:
-   * Redistributions  of  source  code  must retain the above copyright notice,
-     this list of conditions and the following disclaimer.
-   * Redistributions  in binary form must reproduce the above copyright notice,
-     this  list of conditions and the following disclaimer in the documentation
-     and/or other materials provided with the distribution.
- THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*******************************************************************************/
-
-#include <Moof/Library.hh>
-#include <Moof/OpenGL.hh>
-#include <Moof/Script.hh>
-
-#include "Tilemap.hh"
-
-
-struct Tilemap::Impl : public Mf::Library<Impl>
-{
-       Impl(const std::string& name) :
-               Mf::Library<Impl>(name),
-               mMagFilter(GL_NEAREST),
-               mMinFilter(GL_NEAREST),
-               mTilesS(1),
-               mTilesT(1),
-               mWrapS(GL_CLAMP),
-               mWrapT(GL_CLAMP)
-       {
-               loadFromFile();
-       }
-
-
-       static void bindScriptConstants(Mf::Script& script)
-       {
-               script.push(GL_CLAMP); script.set("CLAMP");
-               script.push(GL_REPEAT); script.set("REPEAT");
-               script.push(GL_LINEAR); script.set("LINEAR");
-               script.push(GL_NEAREST); script.set("NEAREST");
-               script.push(GL_LINEAR_MIPMAP_LINEAR); script.set("LINEAR_MIPMAP_LINEAR");
-               script.push(GL_LINEAR_MIPMAP_NEAREST); script.set("LINEAR_MIPMAP_NEAREST");
-               script.push(GL_NEAREST_MIPMAP_LINEAR); script.set("NEAREST_MIPMAP_LINEAR");
-               script.push(GL_NEAREST_MIPMAP_NEAREST); script.set("NEAREST_MIPMAP_NEAREST");
-       }
-
-       void loadFromFile()
-       {
-               Mf::Script script;
-               std::string filePath = Tilemap::getPath(getName());
-
-               script.importStandardLibraries();
-               importLogFunctions(script);
-               bindScriptConstants(script);
-
-               if (script.doFile(filePath) != Mf::Script::SUCCESS)
-               {
-                       std::string str;
-                       script[-1].get(str);
-                       Mf::logWarning(str);
-                       return;         // TODO needs a better exit strategy
-               }
-
-               Mf::logInfo << "loading tiles from tilemap " << filePath << std::endl;
-
-               Mf::Script::Slot globals = script.getGlobalTable();
-               Mf::Script::Slot top = script[-1];
-
-               globals.pushField("tiles_s");
-               top.get(mTilesS);
-
-               globals.pushField("tiles_t");
-               top.get(mTilesT);
-
-               globals.pushField("min_filter");
-               top.get(mMinFilter);
-
-               globals.pushField("mag_filter");
-               top.get(mMagFilter);
-
-               globals.pushField("wrap_s");
-               top.get(mWrapS);
-
-               globals.pushField("wrap_t");
-               top.get(mWrapT);
-       }
-
-
-       bool getTileCoords(Tilemap::Index index, Mf::Scalar coords[8]) const
-       {
-               // make sure the index represents a real tile
-               if (index >= mTilesS * mTilesT) return false;
-
-               Mf::Scalar w = 1.0 / Mf::Scalar(mTilesS);
-               Mf::Scalar h = 1.0 / Mf::Scalar(mTilesT);
-
-               coords[0] = Mf::Scalar(index % mTilesS) * w;
-               coords[1] = (Mf::Scalar(mTilesT - 1) -
-                               Mf::Scalar(index / mTilesS)) * h;
-               coords[2] = coords[0] + w;
-               coords[3] = coords[1];
-               coords[4] = coords[2];
-               coords[5] = coords[1] + h;
-               coords[6] = coords[0];
-               coords[7] = coords[5];
-
-               return true;
-       }
-
-
-       GLuint          mMagFilter;
-       GLuint          mMinFilter;
-       unsigned        mTilesS;
-       unsigned        mTilesT;
-       GLuint          mWrapS;
-       GLuint          mWrapT;
-};
-
-
-Tilemap::Tilemap(const std::string& name) :
-       Texture(name),
-       mImpl(Tilemap::Impl::getInstance(name))
-{
-       setMinFilter(mImpl->mMinFilter);
-       setMagFilter(mImpl->mMagFilter);
-       setWrapS(mImpl->mWrapS);
-       setWrapT(mImpl->mWrapT);
-}
-
-
-bool Tilemap::getTileCoords(Index index, Mf::Scalar coords[8]) const
-{
-       // pass through
-       return mImpl->getTileCoords(index, coords);
-}
-
-bool Tilemap::getTileCoords(Index index, Mf::Scalar coords[8],
-               Orientation orientation) const
-{
-       if (getTileCoords(index, coords))
-       {
-               if (orientation & FLIP)
-               {
-                       // this looks kinda weird, but it's just swapping in a way that
-                       // doesn't require an intermediate variable
-                       coords[1] = coords[5];
-                       coords[5] = coords[3];
-                       coords[3] = coords[7];
-                       coords[7] = coords[5];
-               }
-               if (orientation & REVERSE)
-               {
-                       coords[0] = coords[2];
-                       coords[2] = coords[6];
-                       coords[4] = coords[6];
-                       coords[6] = coords[0];
-               }
-
-               return true;
-       }
-
-       return false;
-}
-
-
-std::string Tilemap::getPath(const std::string& name)
-{
-       return Resource::getPath("tilemaps/" + name + ".lua");
-}
-
-
-/** vim: set ts=4 sw=4 tw=80: *************************************************/
-
diff --git a/src/Tilemap.hh b/src/Tilemap.hh
deleted file mode 100644 (file)
index 9277387..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-
-/*******************************************************************************
-
- Copyright (c) 2009, Charles McGarvey
- All rights reserved.
- Redistribution   and   use  in  source  and  binary  forms,  with  or  without
- modification, are permitted provided that the following conditions are met:
-   * Redistributions  of  source  code  must retain the above copyright notice,
-     this list of conditions and the following disclaimer.
-   * Redistributions  in binary form must reproduce the above copyright notice,
-     this  list of conditions and the following disclaimer in the documentation
-     and/or other materials provided with the distribution.
- THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*******************************************************************************/
-
-#ifndef _TILEMAP_HH_
-#define _TILEMAP_HH_
-
-/**
- * @file Tilemap.hh
- * Small subclass to give some basic tile-mapping functionality to textures.
- */
-
-#include <boost/shared_ptr.hpp>
-
-#include <Moof/Math.hh>
-#include <Moof/Texture.hh>
-
-
-/**
- * A tilemap is a texture which is meant to be divided into smaller sprites.
- * This class provides all the functionality of a texture and adds some methods
- * to get texture coordinates to individual tiles within the tilemap.  For
- * simplicity, this class assumes square tiles.
- */
-
-class Tilemap : public Mf::Texture
-{
-public:
-
-       /**
-        * Possible orientations for texture coordinates.
-        */
-
-       typedef unsigned Index;
-       static const Index NO_TILE = -1;
-
-       typedef enum
-       {
-               NORMAL =                        0,                      ///< Normal orientation.
-               FLIP =                          1,                      ///< Flip over a horizontal axis.
-               REVERSE =                       2,                      ///< Flip over a vertical axis.
-               FLIP_AND_REVERSE =      3                       ///< Flip over both.
-       } Orientation;
-
-
-       explicit Tilemap(const std::string& name);
-
-       /**
-        * Calculate texture coordinates for a tile at a certain index.  Tiles are
-        * indexed start with zero as the to-left tile and moving across, then down.
-        * @param index The tile index.
-        * @param coords An array of scalars where the texture coordinates will be
-        * stored after this call.  The first coordinate (u,v) will be in the first
-        * two places and so on until all four coordinates are stored, therefore
-        * requiring enough room for an array of eight scalars.  The winding of the
-        * coordinates is always counter-clockwise (the GL default).
-        * @return True if index is valid, false otherwise.
-        */
-
-       bool getTileCoords(Index index, Mf::Scalar coords[8]) const;
-
-
-       /**
-        * This version let's you specify an orientation that will be reflected in
-        * the texture coordinates.  This allows you to easily map a texture
-        * backwards or upside-down.
-        * @param what The orientation; can be flip, reverse, or flip_and_reverse.
-        * @return True if index is valid, false otherwise.
-        */
-
-       bool getTileCoords(Index index, Mf::Scalar coords[8], Orientation what) const;
-
-
-       static std::string getPath(const std::string& name);
-
-private:
-
-       class Impl;
-       boost::shared_ptr<Impl> mImpl;
-};
-
-
-#endif // _TILEMAP_HH_
-
-/** vim: set ts=4 sw=4 tw=80: *************************************************/
-
index da0e9a67f866b6af2dde5c6540c7d3748e8647e4..48b0fc3951d7655f4c657cdc5f1b053616a37d80 100644 (file)
 
 
 TilemapFont::TilemapFont() :
-       Tilemap("Font") {}
+       Mf::Texture("Font") {}
 
 
 void TilemapFont::getTileCoords(char symbol, Mf::Scalar coords[8],
-               Tilemap::Orientation what)
+               Mf::Texture::Orientation what)
 {
-       Tilemap::Index index = 0;
+       Mf::Texture::TileIndex index = 0;
 
        if (symbol >= ' ' && symbol <= '_')
        {
@@ -53,7 +53,7 @@ void TilemapFont::getTileCoords(char symbol, Mf::Scalar coords[8],
                index = 0;
        }
 
-       Tilemap::getTileCoords(index, coords, what);
+       Mf::Texture::getTileCoords(index, coords, what);
 }
 
 
index 98a3a13ce1431c7589eb61e2d34dc8bd401ebcbe..89cb062ad8cedbc0539b3ea45f89a45146ab77e7 100644 (file)
  * Text on the screen.
  */
 
-#include "Tilemap.hh"
+#include <Moof/Texture.hh>
 
 
-class TilemapFont : public Tilemap
+class TilemapFont : public Mf::Texture
 {
 public:
 
        TilemapFont();
 
        void getTileCoords(char symbol, Mf::Scalar coords[8],
-                       Tilemap::Orientation what = Tilemap::NORMAL);
+                       Mf::Texture::Orientation what = Mf::Texture::NORMAL);
 };
 
 
This page took 0.087322 seconds and 4 git commands to generate.