SourceForge: osrpgcreation/osrpgcreation: changeset 63:014721b97109
moved all logic to Core class; can select only correct tiles now
authorkornerr
Sat Oct 31 23:36:13 2009 +0700 (3 weeks ago)
changeset 63014721b97109
parent 624b9115307313
child 6465adda9a59f3
moved all logic to Core class; can select only correct tiles now
CMakeLists.txt
include/lf/mj/Common.h
include/lf/mj/Core.h
include/lf/mj/TileType.h
src/lf/mj/Common.cpp
src/lf/mj/Core.cpp
src/lf/mj/TileType.cpp
src/main.cpp
     1.1 --- a/CMakeLists.txt	Sat Oct 31 18:53:10 2009 +0700
     1.2 +++ b/CMakeLists.txt	Sat Oct 31 23:36:13 2009 +0700
     1.3 @@ -9,7 +9,6 @@
     1.4      src/lf/mj/TileType.cpp
     1.5      src/lf/mj/Layout.cpp
     1.6      src/lf/mj/Core.cpp
     1.7 -    src/lf/mj/Common.cpp
     1.8      src/main.cpp
     1.9  )
    1.10  # Generate TI files for TileType class
     2.1 --- a/include/lf/mj/Common.h	Sat Oct 31 18:53:10 2009 +0700
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,26 +0,0 @@
     2.4 -
     2.5 -#ifndef LF_MJ_COMMON_H
     2.6 -#define LF_MJ_COMMON_H
     2.7 -
     2.8 -#include <lf/Lightfeather.h>
     2.9 -#include <lf/mj/TileType.h>
    2.10 -
    2.11 -#include <map>
    2.12 -
    2.13 -namespace lf {
    2.14 -namespace mj {
    2.15 -
    2.16 -class Common {
    2.17 -    public:
    2.18 -        typedef std::map<scene::CSceneNode*, TileType*> HashNodeTile;
    2.19 -        // Scene node <-> Tile correspondence
    2.20 -        static HashNodeTile hnt;
    2.21 -};
    2.22 -
    2.23 -//bool operator<(const scene::CSceneNode *s1, const scene::CSceneNode *s2);
    2.24 -
    2.25 -} // namespace mj 
    2.26 -} // namespace lf 
    2.27 -
    2.28 -#endif // LF_MJ_COMMON_H
    2.29 -
     3.1 --- a/include/lf/mj/Core.h	Sat Oct 31 18:53:10 2009 +0700
     3.2 +++ b/include/lf/mj/Core.h	Sat Oct 31 23:36:13 2009 +0700
     3.3 @@ -2,17 +2,25 @@
     3.4  #ifndef LF_MJ_CORE_H
     3.5  #define LF_MJ_CORE_H
     3.6  
     3.7 +#include <lf/mj/TileType.h>
     3.8  #include <lf/Lightfeather.h>
     3.9 +#include <map>
    3.10 +#include <vector>
    3.11  
    3.12  namespace lf {
    3.13  namespace mj {
    3.14  
    3.15 +class TileTemplate;
    3.16 +
    3.17  class Core : public input::IKeyListener,
    3.18               public input::IMouseListener {
    3.19      public:
    3.20          Core();
    3.21 +        ~Core();
    3.22  
    3.23 +        bool canSelect(const TileType *tile) const;
    3.24          void keyPressed(input::CKeyEvent &e);
    3.25 +        void lighting();
    3.26          void mousePressed(input::CMouseEvent &e);
    3.27          void run();
    3.28  
    3.29 @@ -23,9 +31,17 @@
    3.30          scene::C3DCamera *mCam;
    3.31          scene::CSceneNodeController *mCamCtrl;
    3.32          s8 mCtrlType;
    3.33 -        scene::APickingResults pickResults;
    3.34 +        scene::CSceneNode *mSelectedNode;
    3.35          u32 mFPS;
    3.36          u32 mPolys;
    3.37 +        std::vector<core::stringc> mTexs;
    3.38 +        TileTemplate *tmpl;
    3.39 +        typedef std::map<scene::CSceneNode*, TileType*> HashNodeTile;
    3.40 +        // Scene node <-> Tile correspondence
    3.41 +        HashNodeTile mHNT;
    3.42 +        typedef std::vector<TileType*> Tiles;
    3.43 +        typedef Tiles::const_iterator TIt;
    3.44 +        Tiles mTiles;
    3.45  };
    3.46  
    3.47  } // namespace lf
     4.1 --- a/include/lf/mj/TileType.h	Sat Oct 31 18:53:10 2009 +0700
     4.2 +++ b/include/lf/mj/TileType.h	Sat Oct 31 23:36:13 2009 +0700
     4.3 @@ -28,7 +28,7 @@
     4.4          scene::CSceneNode* getNode() {
     4.5              return mNode;
     4.6          }
     4.7 -        core::vector3df getPos() const {
     4.8 +        core::vector3di getPos() const {
     4.9              return mPos;
    4.10          }
    4.11          core::vector3df getRot() const {
    4.12 @@ -51,10 +51,10 @@
    4.13          }
    4.14          // Must be references
    4.15          virtual void setGroup(const u32 &group);
    4.16 -        virtual void setID(const u32 &id);
    4.17 +        void setID(const u32 &id);
    4.18          virtual void setTex(const core::stringc &mat);
    4.19          virtual void setMesh(const core::stringc &mesh);
    4.20 -        virtual void setPos(const core::vector3df &pos);
    4.21 +        void setPos(const core::vector3di &pos);
    4.22          virtual void setRot(const core::vector3df &rot);
    4.23          virtual void setScale(const core::vector3df &scale);
    4.24          virtual void setSelectability(const bool &selectability);
    4.25 @@ -62,11 +62,13 @@
    4.26          virtual void setVisibility(const bool &visibility);
    4.27  
    4.28      protected:
    4.29 +        TileType& operator=(const TileType &other);
    4.30 +
    4.31          s32 mGroup;
    4.32          u32 mID;
    4.33          core::stringc mTex;
    4.34          core::stringc mMesh;
    4.35 -        core::vector3df mPos;
    4.36 +        core::vector3di mPos;
    4.37          core::vector3df mRot;
    4.38          core::vector3df mScale;
    4.39          bool mSelectability;
     5.1 --- a/src/lf/mj/Common.cpp	Sat Oct 31 18:53:10 2009 +0700
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,17 +0,0 @@
     5.4 -
     5.5 -#include <lf/mj/Common.h>
     5.6 -
     5.7 -namespace lf {
     5.8 -namespace mj {
     5.9 -
    5.10 -Common::HashNodeTile Common::hnt;
    5.11 -
    5.12 -/*
    5.13 -bool operator<(const scene::CSceneNode *s1, const scene::CSceneNode *s2) {
    5.14 -    return *s1 < *s2;
    5.15 -}
    5.16 -*/
    5.17 -
    5.18 -} // namespace mj 
    5.19 -} // namespace lf 
    5.20 -
     6.1 --- a/src/lf/mj/Core.cpp	Sat Oct 31 18:53:10 2009 +0700
     6.2 +++ b/src/lf/mj/Core.cpp	Sat Oct 31 23:36:13 2009 +0700
     6.3 @@ -1,13 +1,14 @@
     6.4  
     6.5  #include <lf/mj/Core.h>
     6.6 -
     6.7 -#include <lf/mj/Common.h>
     6.8 +#include <lf/mj/Layout.h>
     6.9 +#include <lf/mj/TileTI.h>
    6.10  
    6.11  namespace lf {
    6.12  namespace mj {
    6.13  
    6.14  Core::Core() :
    6.15          mWin(0), mRMgr(0), mScn(0), mCam(0),
    6.16 +        mSelectedNode(0),
    6.17          mFPS(0), mPolys(0) {
    6.18      mWin = CLFRender::getInstance().createRenderWindow(
    6.19          core::vector2di(0, 0),
    6.20 @@ -38,83 +39,7 @@
    6.21      mCtrlType--;
    6.22      input::CKeyEvent ne(mWin, 0, input::KEY_KEY_N, 'n');
    6.23      keyPressed(ne);
    6.24 -    /*
    6.25 -    mCamCtrl = new scene::CEditorController(mWin, mCam);
    6.26 -    mScn->addSceneNodeController(mCamCtrl);
    6.27 -    mCamCtrl->drop();
    6.28 -    */
    6.29 -    // Lighting state.
    6.30 -    render::CRenderStateLighting *rsl =
    6.31 -        new render::CRenderStateLighting(true);
    6.32 -    mCam->replaceRenderState(rsl);
    6.33 -    rsl->drop();
    6.34 -    // No ambient.
    6.35 -    render::CRenderStateAmbientLight *rsal =
    6.36 -        new render::CRenderStateAmbientLight(core::CColorI(20, 20, 20, 255));
    6.37 -    mCam->replaceRenderState(rsal);
    6.38 -    rsal->drop();
    6.39 -    // Light source.
    6.40 -    scene::CLight *light = new scene::CLight(
    6.41 -            scene::ELT_SPOT,
    6.42 -            core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
    6.43 -            core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
    6.44 -            core::CColorF(0.0f, 0.0f, 0.0f, 0.0f),
    6.45 -            20.0f,
    6.46 -            1.0f,
    6.47 -            core::PI / 3,
    6.48 -            core::PI / 2,
    6.49 -            0.0f,
    6.50 -            0.0f,
    6.51 -            1.0f / 500.0f,
    6.52 -            0.0f);
    6.53 -    light->setPosition(core::vector3df(100, 30, 0));
    6.54 -    mScn->addLight(light);
    6.55 -    // So we can move it.
    6.56 -    mScn->addSceneNode(light);
    6.57 -    // Point down.
    6.58 -    light->setRotationDegrees(core::vector3df(90, 0, 0));
    6.59 -    light->drop();
    6.60 -    scene::CSceneStateLight *csl = new scene::CSceneStateLight(light, true);
    6.61 -    mScn->getRootSceneNode()->addSceneState(csl);
    6.62 -    csl->drop();
    6.63 -    // Light rotation.
    6.64 -    scene::CSceneNodeController *lrot = new scene::CFlyCircleController(
    6.65 -        light,
    6.66 -        core::vector3df(0, 30, 0),
    6.67 -        core::vector3df(0, 1, 0),
    6.68 -        20,
    6.69 -        0.1);
    6.70 -    mScn->addSceneNodeController(lrot);
    6.71 -    lrot->drop();
    6.72 -    // Billboard to display light source position.
    6.73 -    res::CBillboardModel *model = new res::CBillboardModel(
    6.74 -        "billboard",
    6.75 -        mRMgr->getTexture("particlewhite.bmp"),
    6.76 -        res::EBT_VIEW_PLANE,
    6.77 -        1.5f,
    6.78 -        1.5f);
    6.79 -    model->setMaterial(0, mRMgr->getMaterial("light_billboard"));
    6.80 -    scene::CModelSceneNode *node = new scene::CModelSceneNode(model);
    6.81 -    light->addChild(node);
    6.82 -    // Disable lighting for the billboard.
    6.83 -    rsl = new render::CRenderStateLighting(false);
    6.84 -    node->addRenderStateToMaterials(rsl);
    6.85 -    node->drop();
    6.86 -    // Shadow mapping.
    6.87 -    light->makeShadowProjector(
    6.88 -        2048,
    6.89 -        2048,
    6.90 -        1.0f,
    6.91 -        1000.0f,
    6.92 -        0.0f, 0.0f, 0.0f, 0.0f);
    6.93 -    scene::CSceneStateShadowCaster *sssc =
    6.94 -        new scene::CSceneStateShadowCaster(light);
    6.95 -    mScn->getRootSceneNode()->addSceneState(sssc);
    6.96 -    sssc->drop();
    6.97 -    scene::CSceneStateShadowReceiver *sssr =
    6.98 -        new scene::CSceneStateShadowReceiver(light, true);
    6.99 -    mScn->getRootSceneNode()->addSceneState(sssr);
   6.100 -    sssr->drop();
   6.101 +    lighting();
   6.102      // Ground plane.
   6.103      res::CPlaneModel *plane = new res::CPlaneModel(
   6.104          "plane",
   6.105 @@ -123,10 +48,45 @@
   6.106          core::vector2dui(10, 10));
   6.107      plane->getMaterial(0)->setRenderFeature(render::ERPF_DIFFUSEMAP);
   6.108      plane->getMaterial(0)->setTexture(0, mRMgr->getTexture("tile1.jpg"));
   6.109 -    node = new scene::CModelSceneNode(plane);
   6.110 +    scene::CSceneNode *node = new scene::CModelSceneNode(plane);
   6.111      mScn->addSceneNode(node);
   6.112      node->setPosition(core::vector3df(0, -10, 0));
   6.113      node->drop();
   6.114 +    // [ID : Texture] correspondance.
   6.115 +    mTexs.push_back("tile01.png");
   6.116 +    mTexs.push_back("tile02.png");
   6.117 +    mTexs.push_back("tile03.png");
   6.118 +    mTexs.push_back("tile04.png");
   6.119 +    mRMgr->loadResources("res/lfm/tile.lfm");
   6.120 +    tmpl = new TileTemplate;
   6.121 +    tmpl->setMesh("Tile");
   6.122 +}
   6.123 +
   6.124 +Core::~Core() {
   6.125 +    tmpl->drop();
   6.126 +}
   6.127 +
   6.128 +bool Core::canSelect(const TileType *tile) const {
   6.129 +    core::vector3di pos = tile->getPos();
   6.130 +    u8 adjTilesNb = 0;
   6.131 +    for (TIt it = mTiles.begin(); it != mTiles.end(); it++)
   6.132 +        if (*it != tile) {
   6.133 +            core::vector3di posNew = (*it)->getPos();
   6.134 +            // Find out if this tile is above us.
   6.135 +            if (posNew.Y - pos.Y == 1 &&
   6.136 +                fabs(posNew.X - pos.X) <= 1 &&
   6.137 +                fabs(posNew.Z - pos.Z) <= 1)
   6.138 +                return false;
   6.139 +            // Find out if this tile is adjacent to our side;
   6.140 +            if (posNew.Y == pos.Y &&
   6.141 +                fabs(posNew.Z - pos.Z) <= 1 &&
   6.142 +                fabs(posNew.X - pos.X) == 2)
   6.143 +                adjTilesNb++;
   6.144 +            // We are between two tiles.
   6.145 +            if (adjTilesNb == 2)
   6.146 +                return false;
   6.147 +        }
   6.148 +    return true;
   6.149  }
   6.150  
   6.151  void Core::keyPressed(input::CKeyEvent &e) {
   6.152 @@ -178,28 +138,139 @@
   6.153  void Core::mousePressed(input::CMouseEvent &e) {
   6.154      if (e.getButton() != 1)
   6.155          return;
   6.156 -    // Deselect selected nodes.
   6.157 -    for (u32 i = 0; i < pickResults.size(); i++) {
   6.158 -        scene::CSceneNode *node = pickResults[i]->node;
   6.159 -        if (Common::hnt.find(node) != Common::hnt.end())
   6.160 -            Common::hnt[node]->setSelected(false);
   6.161 -    }
   6.162 -    pickResults.clear();
   6.163 +    // Deselect.
   6.164 +    if (mSelectedNode && mHNT.find(mSelectedNode) != mHNT.end())
   6.165 +        mHNT[mSelectedNode]->setSelected(false);
   6.166 +    // Select
   6.167 +    scene::APickingResults pickResults;
   6.168      core::line3df line = mCam->getPickingLine(
   6.169          mWin->getCursorControl()->getRelativePosition().X,
   6.170          mWin->getCursorControl()->getRelativePosition().Y);
   6.171      mScn->getRootSceneNode()->pick(
   6.172          line, true, true, mCam, false, pickResults);
   6.173 -    // Select selected nodes.
   6.174 -    for (u32 i = 0; i < pickResults.size(); i++) {
   6.175 -        scene::CSceneNode *node = pickResults[i]->node;
   6.176 -        if (Common::hnt.find(node) != Common::hnt.end())
   6.177 -            Common::hnt[node]->setSelected(true);
   6.178 +    scene::CSceneNode *newNode = 0;
   6.179 +    // There's always only one selected node.
   6.180 +    if (pickResults.size())
   6.181 +        newNode = pickResults[0]->node;
   6.182 +    // Do not select, if it was previously selected.
   6.183 +    if (mSelectedNode && newNode == mSelectedNode) {
   6.184 +        mSelectedNode = 0;
   6.185 +        return;
   6.186      }
   6.187 +    // Select new one.
   6.188 +    if (newNode) {
   6.189 +        TileType *tile = 0;
   6.190 +        if (mHNT.find(newNode) != mHNT.end())
   6.191 +            tile = mHNT[newNode];
   6.192 +        if (tile && canSelect(mHNT[newNode])) {
   6.193 +            mHNT[newNode]->setSelected(true);
   6.194 +            mSelectedNode = newNode;
   6.195 +            core::vector3di pos = tile->getPos();
   6.196 +            std::cout << "pos(" << pos.X << ", "
   6.197 +                      << pos.Y << ", "
   6.198 +                      << pos.Z << ")\n";
   6.199 +        }
   6.200 +    }
   6.201 +}
   6.202 +
   6.203 +void Core::lighting() {
   6.204 +    // Lighting state.
   6.205 +    render::CRenderStateLighting *rsl =
   6.206 +        new render::CRenderStateLighting(true);
   6.207 +    mCam->replaceRenderState(rsl);
   6.208 +    rsl->drop();
   6.209 +    // No ambient.
   6.210 +    render::CRenderStateAmbientLight *rsal =
   6.211 +        new render::CRenderStateAmbientLight(core::CColorI(20, 20, 20, 255));
   6.212 +    mCam->replaceRenderState(rsal);
   6.213 +    rsal->drop();
   6.214 +    // Light source.
   6.215 +    scene::CLight *light = new scene::CLight(
   6.216 +            scene::ELT_SPOT,
   6.217 +            core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
   6.218 +            core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
   6.219 +            core::CColorF(0.0f, 0.0f, 0.0f, 0.0f),
   6.220 +            20.0f,
   6.221 +            1.0f,
   6.222 +            core::PI / 3,
   6.223 +            core::PI / 2,
   6.224 +            0.0f,
   6.225 +            0.0f,
   6.226 +            1.0f / 500.0f,
   6.227 +            0.0f);
   6.228 +    light->setPosition(core::vector3df(100, 30, 0));
   6.229 +    mScn->addLight(light);
   6.230 +    // So we can move it.
   6.231 +    mScn->addSceneNode(light);
   6.232 +    // Point down.
   6.233 +    light->setRotationDegrees(core::vector3df(90, 0, 0));
   6.234 +    light->drop();
   6.235 +    scene::CSceneStateLight *csl = new scene::CSceneStateLight(light, true);
   6.236 +    mScn->getRootSceneNode()->addSceneState(csl);
   6.237 +    csl->drop();
   6.238 +    // Light rotation.
   6.239 +    scene::CSceneNodeController *lrot = new scene::CFlyCircleController(
   6.240 +        light,
   6.241 +        core::vector3df(0, 30, 0),
   6.242 +        core::vector3df(0, 1, 0),
   6.243 +        20,
   6.244 +        0.1);
   6.245 +    mScn->addSceneNodeController(lrot);
   6.246 +    lrot->drop();
   6.247 +    // Billboard to display light source position.
   6.248 +    res::CBillboardModel *model = new res::CBillboardModel(
   6.249 +        "billboard",
   6.250 +        mRMgr->getTexture("particlewhite.bmp"),
   6.251 +        res::EBT_VIEW_PLANE,
   6.252 +        1.5f,
   6.253 +        1.5f);
   6.254 +    model->setMaterial(0, mRMgr->getMaterial("light_billboard"));
   6.255 +    scene::CModelSceneNode *node = new scene::CModelSceneNode(model);
   6.256 +    light->addChild(node);
   6.257 +    // Disable lighting for the billboard.
   6.258 +    rsl = new render::CRenderStateLighting(false);
   6.259 +    node->addRenderStateToMaterials(rsl);
   6.260 +    node->drop();
   6.261 +    // Shadow mapping.
   6.262 +    light->makeShadowProjector(
   6.263 +        2048,
   6.264 +        2048,
   6.265 +        1.0f,
   6.266 +        1000.0f,
   6.267 +        0.0f, 0.0f, 0.0f, 0.0f);
   6.268 +    scene::CSceneStateShadowCaster *sssc =
   6.269 +        new scene::CSceneStateShadowCaster(light);
   6.270 +    mScn->getRootSceneNode()->addSceneState(sssc);
   6.271 +    sssc->drop();
   6.272 +    scene::CSceneStateShadowReceiver *sssr =
   6.273 +        new scene::CSceneStateShadowReceiver(light, true);
   6.274 +    mScn->getRootSceneNode()->addSceneState(sssr);
   6.275 +    sssr->drop();
   6.276  }
   6.277  
   6.278  void Core::run() {
   6.279      bool quit = false;
   6.280 +    // Read in layout.
   6.281 +    Layout ly;
   6.282 +    if (ly.read("res/layout/pirates.layout")) {
   6.283 +        for (u32 i = 0; i < ly.positions().size(); i++) {
   6.284 +            TileInstance *inst = tmpl->instantiate();
   6.285 +            inst->setPos(ly.positions()[i]);
   6.286 +            inst->setID(i);
   6.287 +            inst->setTex(mTexs[i % 4]);
   6.288 +            inst->setGroup(i % 8);
   6.289 +            mHNT[inst->getNode()] = inst;
   6.290 +            mTiles.push_back(inst);
   6.291 +        }
   6.292 +        tmpl->setRot(core::vector3df(0, 180, 0));
   6.293 +    }
   6.294 +    else {
   6.295 +        CLFLog::getInstance().log(lf::log::ELS_USER1,
   6.296 +                                  lf::log::ELL_ERROR,
   6.297 +                                  "Could not open layout");
   6.298 +        quit = true;
   6.299 +    }
   6.300 +    // Loop.
   6.301      while (!quit) {
   6.302          u32 fps = mWin->getOneSecondFPS();
   6.303          u32 polys = mWin->getTotalPolygonCount();
     7.1 --- a/src/lf/mj/TileType.cpp	Sat Oct 31 18:53:10 2009 +0700
     7.2 +++ b/src/lf/mj/TileType.cpp	Sat Oct 31 23:36:13 2009 +0700
     7.3 @@ -10,7 +10,7 @@
     7.4          mID(0),
     7.5          mTex(""),
     7.6          mMesh(""),
     7.7 -        mPos(core::vector3df(0, 0, 0)),
     7.8 +        mPos(core::vector3di(0, 0, 0)),
     7.9          mRot(core::vector3df(0, 0, 0)),
    7.10          mScale(core::vector3df(1, 1, 1)),
    7.11          mSelectability(true),
    7.12 @@ -39,7 +39,7 @@
    7.13          mID(0),
    7.14          mTex(other.mTex),
    7.15          mMesh(other.mMesh),
    7.16 -        mPos(core::vector3df(0, 0, 0)),
    7.17 +        mPos(core::vector3di(0, 0, 0)),
    7.18          mRot(other.mRot),
    7.19          mScale(other.mScale),
    7.20          mSelectability(other.mSelectability),
    7.21 @@ -89,9 +89,14 @@
    7.22      }
    7.23  }
    7.24  
    7.25 -void TileType::setPos(const core::vector3df &pos) {
    7.26 +void TileType::setPos(const core::vector3di &pos) {
    7.27      mPos = pos;
    7.28 -    mNode->setPosition(pos);
    7.29 +    core::aabbox3df tbb = mRMgr->getMesh(mMesh)->getBoundingBox();
    7.30 +    core::vector3df np = tbb.MaxEdge - tbb.MinEdge;
    7.31 +    np.X = pos.X * np.X / 2 - 30;
    7.32 +    np.Y = pos.Y * np.Y;
    7.33 +    np.Z = pos.Z * np.Z / 2 - 30;
    7.34 +    mNode->setPosition(np);
    7.35  }
    7.36  
    7.37  void TileType::setRot(const core::vector3df &rot) {
     8.1 --- a/src/main.cpp	Sat Oct 31 18:53:10 2009 +0700
     8.2 +++ b/src/main.cpp	Sat Oct 31 23:36:13 2009 +0700
     8.3 @@ -1,61 +1,14 @@
     8.4  
     8.5 -#include <lf/mj/Common.h>
     8.6  #include <lf/mj/Core.h>
     8.7 -#include <lf/mj/Layout.h>
     8.8 -#include <lf/mj/TileTI.h>
     8.9 -
    8.10 -#include <iostream>
    8.11 -#include <vector>
    8.12  
    8.13  using namespace lf;
    8.14  using namespace lf::mj;
    8.15 -using namespace std;
    8.16  
    8.17  int main() {
    8.18 -    // [ID : Texture] correspondance.
    8.19 -    vector<core::stringc> texs;
    8.20 -    texs.push_back("tile01.png");
    8.21 -    texs.push_back("tile02.png");
    8.22 -    texs.push_back("tile03.png");
    8.23 -    texs.push_back("tile04.png");
    8.24 -    // Initialization.
    8.25      initLF();
    8.26 -    //Common *cmn = new Common;
    8.27      Core *core = new Core;
    8.28 -    // Script.
    8.29 -    CResourceManager::getInstance().loadResources("res/lfm/tile.lfm");
    8.30 -    TileTemplate *tmpl = new TileTemplate;
    8.31 -    tmpl->setMesh("Tile");
    8.32 -    // Get mesh dimensions.
    8.33 -    core::aabbox3df tbb =
    8.34 -        CResourceManager::getInstance().getMesh("Tile")->getBoundingBox();
    8.35 -    core::vector3df dim = tbb.MaxEdge - tbb.MinEdge;
    8.36 -    // Read in layout.
    8.37 -    Layout ly;
    8.38 -    if (ly.read("res/layout/pirates.layout")) {
    8.39 -        for (u32 i = 0; i < ly.positions().size(); i++) {
    8.40 -            TileInstance *inst = tmpl->instantiate();
    8.41 -            core::vector3di pos = ly.positions()[i];
    8.42 -            inst->setPos(core::vector3df(-30 + pos.X * dim.X / 1.9,
    8.43 -                                         pos.Y * dim.Y,
    8.44 -                                         -30 + pos.Z * dim.Z / 1.9));
    8.45 -            inst->setID(i);
    8.46 -            inst->setTex(texs[i % 4]);
    8.47 -            inst->setGroup(i % 8);
    8.48 -            Common::hnt[inst->getNode()] = inst;
    8.49 -        }
    8.50 -        tmpl->setRot(core::vector3df(0, 180, 0));
    8.51 -        // Run.
    8.52 -        core->run();
    8.53 -    }
    8.54 -    else
    8.55 -        CLFLog::getInstance().log(lf::log::ELS_USER1,
    8.56 -                                  lf::log::ELL_ERROR,
    8.57 -                                  "Could not open layout");
    8.58 -    // Clean up.
    8.59 -    tmpl->drop();
    8.60 +    core->run();
    8.61      delete core;
    8.62 -    //delete cmn;
    8.63      deinitLF();
    8.64      return 0;
    8.65  }