1.1 --- a/CMakeLists.txt Wed Oct 28 08:23:07 2009 +0700
1.2 +++ b/CMakeLists.txt Sat Oct 31 13:21:42 2009 +0700
1.3 @@ -9,6 +9,7 @@
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 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/include/lf/mj/Common.h Sat Oct 31 13:21:42 2009 +0700
2.3 @@ -0,0 +1,26 @@
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 Wed Oct 28 08:23:07 2009 +0700
3.2 +++ b/include/lf/mj/Core.h Sat Oct 31 13:21:42 2009 +0700
3.3 @@ -7,11 +7,13 @@
3.4 namespace lf {
3.5 namespace mj {
3.6
3.7 -class Core : input::IKeyListener {
3.8 +class Core : public input::IKeyListener,
3.9 + public input::IMouseListener {
3.10 public:
3.11 Core();
3.12
3.13 void keyPressed(input::CKeyEvent &e);
3.14 + void mousePressed(input::CMouseEvent &e);
3.15 void run();
3.16
3.17 private:
3.18 @@ -20,6 +22,9 @@
3.19 scene::CScene *mScn;
3.20 scene::C3DCamera *mCam;
3.21 scene::CSceneNodeController *mCamCtrl;
3.22 + scene::APickingResults pickResults;
3.23 + u32 mFPS;
3.24 + u32 mPolys;
3.25 };
3.26
3.27 } // namespace lf
4.1 --- a/include/lf/mj/TileType.h Wed Oct 28 08:23:07 2009 +0700
4.2 +++ b/include/lf/mj/TileType.h Sat Oct 31 13:21:42 2009 +0700
4.3 @@ -21,12 +21,13 @@
4.4 u32 getID() const {
4.5 return mID;
4.6 }
4.7 - core::stringc getMat() const {
4.8 - return mMat;
4.9 - }
4.10 core::stringc getMesh() const {
4.11 return mMesh;
4.12 }
4.13 + // Untracked. Do not alter object through this pointer!
4.14 + scene::CSceneNode* getNode() {
4.15 + return mNode;
4.16 + }
4.17 core::vector3df getPos() const {
4.18 return mPos;
4.19 }
4.20 @@ -39,29 +40,37 @@
4.21 bool getSelectability() const {
4.22 return mSelectability;
4.23 }
4.24 + bool getSelected() const {
4.25 + return mSelected;
4.26 + }
4.27 + core::stringc getTex() const {
4.28 + return mTex;
4.29 + }
4.30 bool getVisibility() const {
4.31 return mVisibility;
4.32 }
4.33 // Must be references
4.34 virtual void setGroup(const u32 &group);
4.35 virtual void setID(const u32 &id);
4.36 - virtual void setMat(const core::stringc &mat);
4.37 + virtual void setTex(const core::stringc &mat);
4.38 virtual void setMesh(const core::stringc &mesh);
4.39 virtual void setPos(const core::vector3df &pos);
4.40 virtual void setRot(const core::vector3df &rot);
4.41 virtual void setScale(const core::vector3df &scale);
4.42 virtual void setSelectability(const bool &selectability);
4.43 + virtual void setSelected(const bool &selected);
4.44 virtual void setVisibility(const bool &visibility);
4.45
4.46 protected:
4.47 s32 mGroup;
4.48 u32 mID;
4.49 - core::stringc mMat;
4.50 + core::stringc mTex;
4.51 core::stringc mMesh;
4.52 core::vector3df mPos;
4.53 core::vector3df mRot;
4.54 core::vector3df mScale;
4.55 bool mSelectability;
4.56 + bool mSelected;
4.57 bool mVisibility;
4.58
4.59 CResourceManager *mRMgr;
5.1 --- a/res/lfm/tile.lfm Wed Oct 28 08:23:07 2009 +0700
5.2 +++ b/res/lfm/tile.lfm Sat Oct 31 13:21:42 2009 +0700
5.3 @@ -1,20 +1,14 @@
5.4 -# PyLFM Version (0, 3, 12)
5.5 -# Lightfeather LFMG Version 3
5.6 -# AUTHOR:
5.7 -# COPYRIGHT:
5.8 -# DESIGNER: Blender v249
5.9 -# MODIFIED: October 25, 2009
5.10 [geometry]
5.11 -filename=tile.lfmg
5.12 -name=tile
5.13 +filename=tile_subsurf.lfmg
5.14 +name=tile_subsurf
5.15 [/geometry]
5.16 [mesh]
5.17 name=Tile
5.18 type=EPT_TRIANGLE_LIST
5.19 -vertexbuffer=tile/Cube_vb0
5.20 -indexbuffer=tile/Cube_ib0
5.21 +vertexbuffer=tile_subsurf/Cube_vb0
5.22 +indexbuffer=tile_subsurf/Cube_ib0
5.23 firstindex=0
5.24 -numindexes=36
5.25 +numindexes=2304
5.26 [/mesh]
5.27 # Materials
5.28 [material]
5.29 @@ -26,49 +20,34 @@
5.30 name=particlewhite.bmp
5.31 [/texture]
5.32 [/material]
5.33 -
5.34 -[material]
5.35 -name=tile01
5.36 -feature=ERPF_DIFFUSEMAP
5.37 +# Textures
5.38 [texture]
5.39 type=2D
5.40 filename=res/tex/tile01.png
5.41 name=tile01.png
5.42 [/texture]
5.43 -[/material]
5.44
5.45 -[material]
5.46 -name=tile02
5.47 -feature=ERPF_DIFFUSEMAP
5.48 [texture]
5.49 type=2D
5.50 filename=res/tex/tile02.png
5.51 name=tile02.png
5.52 [/texture]
5.53 -[/material]
5.54
5.55 -[material]
5.56 -name=tile03
5.57 -feature=ERPF_DIFFUSEMAP
5.58 [texture]
5.59 type=2D
5.60 filename=res/tex/tile03.png
5.61 name=tile03.png
5.62 [/texture]
5.63 -[/material]
5.64
5.65 -[material]
5.66 -name=tile04
5.67 -feature=ERPF_DIFFUSEMAP
5.68 [texture]
5.69 type=2D
5.70 filename=res/tex/tile04.png
5.71 name=tile04.png
5.72 [/texture]
5.73 -[/material]
5.74
5.75 [texture]
5.76 type=2D
5.77 filename=res/tex/tile1.jpg
5.78 name=tile1.jpg
5.79 [/texture]
5.80 +
6.1 Binary file res/lfm/tile_subsurf.lfmg has changed
7.1 --- a/res/ti/tile.ti Wed Oct 28 08:23:07 2009 +0700
7.2 +++ b/res/ti/tile.ti Sat Oct 31 13:21:42 2009 +0700
7.3 @@ -9,7 +9,7 @@
7.4 [/field]
7.5
7.6 [field]
7.7 -name = Mat
7.8 +name = Tex
7.9 type = core::stringc
7.10 [/field]
7.11
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/src/lf/mj/Common.cpp Sat Oct 31 13:21:42 2009 +0700
8.3 @@ -0,0 +1,17 @@
8.4 +
8.5 +#include <lf/mj/Common.h>
8.6 +
8.7 +namespace lf {
8.8 +namespace mj {
8.9 +
8.10 +Common::HashNodeTile Common::hnt;
8.11 +
8.12 +/*
8.13 +bool operator<(const scene::CSceneNode *s1, const scene::CSceneNode *s2) {
8.14 + return *s1 < *s2;
8.15 +}
8.16 +*/
8.17 +
8.18 +} // namespace mj
8.19 +} // namespace lf
8.20 +
9.1 --- a/src/lf/mj/Core.cpp Wed Oct 28 08:23:07 2009 +0700
9.2 +++ b/src/lf/mj/Core.cpp Sat Oct 31 13:21:42 2009 +0700
9.3 @@ -1,11 +1,14 @@
9.4
9.5 #include <lf/mj/Core.h>
9.6
9.7 +#include <lf/mj/Common.h>
9.8 +
9.9 namespace lf {
9.10 namespace mj {
9.11
9.12 Core::Core() :
9.13 - mWin(0), mRMgr(0), mScn(0), mCam(0) {
9.14 + mWin(0), mRMgr(0), mScn(0), mCam(0),
9.15 + mFPS(0), mPolys(0) {
9.16 mWin = CLFRender::getInstance().createRenderWindow(
9.17 core::vector2di(0, 0),
9.18 core::vector2d<s32>(1024, 768),
9.19 @@ -16,6 +19,7 @@
9.20 mWin->setWindowCaption(L"LF MJ");
9.21 mWin->setVisible(true);
9.22 mWin->addKeyListener(this);
9.23 + mWin->addMouseListener(this);
9.24 mRMgr = CResourceManager::getInstancePtr();
9.25 mScn = mWin->getRenderLayer3D()->getScene();
9.26 CLFRender::getInstance().setAutoSleep(0);
9.27 @@ -26,11 +30,11 @@
9.28 // Camera.
9.29 mCam = new scene::C3DCamera(mWin);
9.30 mCam->setBackgroundColor(core::CColorI(150, 170, 150, 0));
9.31 - mCam->setPosition(core::vector3df(0.0f, 85.0f, -30.0f));
9.32 - mCam->setRotationDegrees(73.0f, 1.0f, 0.0f);
9.33 + mCam->setPosition(core::vector3df(2.0f, 75.0f, -3.0f));
9.34 + mCam->setRotationDegrees(90.0f, 0.001f, 0.0f);
9.35 mWin->getRenderLayer3D()->addCamera(mCam);
9.36 mCam->drop();
9.37 - mCamCtrl = new scene::CFPSController(mWin, mCam, true);
9.38 + mCamCtrl = new scene::CEditorController(mWin, mCam);
9.39 mScn->addSceneNodeController(mCamCtrl);
9.40 mCamCtrl->drop();
9.41 // Lighting state.
9.42 @@ -141,10 +145,43 @@
9.43 }
9.44 }
9.45
9.46 +void Core::mousePressed(input::CMouseEvent &e) {
9.47 + if (e.getButton() != 1)
9.48 + return;
9.49 + // Deselect selected nodes.
9.50 + for (u32 i = 0; i < pickResults.size(); i++) {
9.51 + scene::CSceneNode *node = pickResults[i]->node;
9.52 + if (Common::hnt.find(node) != Common::hnt.end())
9.53 + Common::hnt[node]->setSelected(false);
9.54 + }
9.55 + pickResults.clear();
9.56 + core::line3df line = mCam->getPickingLine(
9.57 + mWin->getCursorControl()->getRelativePosition().X,
9.58 + mWin->getCursorControl()->getRelativePosition().Y);
9.59 + mScn->getRootSceneNode()->pick(
9.60 + line, true, true, mCam, false, pickResults);
9.61 + // Select selected nodes.
9.62 + for (u32 i = 0; i < pickResults.size(); i++) {
9.63 + scene::CSceneNode *node = pickResults[i]->node;
9.64 + if (Common::hnt.find(node) != Common::hnt.end())
9.65 + Common::hnt[node]->setSelected(true);
9.66 + }
9.67 +}
9.68 +
9.69 void Core::run() {
9.70 bool quit = false;
9.71 - while (!quit)
9.72 + while (!quit) {
9.73 + u32 fps = mWin->getOneSecondFPS();
9.74 + u32 polys = mWin->getTotalPolygonCount();
9.75 + if (fps != mFPS || polys != mPolys) {
9.76 + wchar_t tmp[256];
9.77 + snwprintf(tmp, 256, L"LF MJ. FPS: %u Polys: %u", fps, polys);
9.78 + mWin->setWindowCaption(tmp);
9.79 + mFPS = fps;
9.80 + mPolys = polys;
9.81 + }
9.82 quit = !CLFRender::getInstance().update();
9.83 + }
9.84 }
9.85
9.86 } // namespace lf
10.1 --- a/src/lf/mj/TileType.cpp Wed Oct 28 08:23:07 2009 +0700
10.2 +++ b/src/lf/mj/TileType.cpp Sat Oct 31 13:21:42 2009 +0700
10.3 @@ -8,12 +8,13 @@
10.4 TileType::TileType(const TileType *other) :
10.5 mGroup(0),
10.6 mID(0),
10.7 - mMat(""),
10.8 + mTex(""),
10.9 mMesh(""),
10.10 mPos(core::vector3df(0, 0, 0)),
10.11 mRot(core::vector3df(0, 0, 0)),
10.12 mScale(core::vector3df(1, 1, 1)),
10.13 mSelectability(true),
10.14 + mSelected(false),
10.15 mVisibility(true),
10.16 mRMgr(CResourceManager::getInstancePtr()),
10.17 mScn(CLFRender::getInstance().getRenderWindow(0)->getRenderLayer3D()->getScene()),
10.18 @@ -22,12 +23,13 @@
10.19 if (other) {
10.20 mGroup = other->mGroup;
10.21 mID = other->mID;
10.22 - mMat = other->mMat;
10.23 + mTex = other->mTex;
10.24 mMesh = other->mMesh;
10.25 mPos = other->mPos;
10.26 mRot = other->mRot;
10.27 mScale = other->mScale;
10.28 mSelectability = other->mSelectability;
10.29 + mSelected = other->mSelected;
10.30 mVisibility = other->mVisibility;
10.31 }
10.32 }
10.33 @@ -35,12 +37,13 @@
10.34 TileType::TileType(const TileType &other) :
10.35 mGroup(other.mGroup),
10.36 mID(0),
10.37 - mMat(other.mMat),
10.38 + mTex(other.mTex),
10.39 mMesh(other.mMesh),
10.40 mPos(core::vector3df(0, 0, 0)),
10.41 mRot(other.mRot),
10.42 mScale(other.mScale),
10.43 mSelectability(other.mSelectability),
10.44 + mSelected(other.mSelected),
10.45 mVisibility(other.mVisibility),
10.46 mRMgr(other.mRMgr),
10.47 mScn(other.mScn),
10.48 @@ -48,42 +51,28 @@
10.49
10.50 void TileType::create() {
10.51 res::CModel *model = new res::CModel;
10.52 + res::CMaterial *mat = new res::CMaterial;
10.53 + mat->setRenderFeature(render::ERPF_DIFFUSEMAP);
10.54 res::CModel *stub = mRMgr->getModel("stub");
10.55 - model->addMesh(stub->getMesh(0));
10.56 + mat->setTexture(0, stub->getMaterial(0)->getTexture(0));
10.57 + model->addMesh(stub->getMesh(0), mat);
10.58 mNode = new scene::CModelSceneNode(model);
10.59 mScn->addSceneNode(mNode);
10.60 mNode->drop();
10.61 if (mMesh.size())
10.62 setMesh(mMesh);
10.63 - if (mMat.size())
10.64 - setMat(mMat);
10.65 + if (mTex.size())
10.66 + setTex(mTex);
10.67 }
10.68
10.69 void TileType::setGroup(const u32 &group) {
10.70 -
10.71 + mGroup = group;
10.72 }
10.73
10.74 void TileType::setID(const u32 &id) {
10.75 mID = id;
10.76 }
10.77
10.78 -void TileType::setMat(const core::stringc &mat) {
10.79 - mMat = mat;
10.80 - if (!mNode)
10.81 - return;
10.82 - res::CMaterial *m = mRMgr->getMaterial(mMat);
10.83 - if (m)
10.84 - mNode->getModel()->setMaterial(0, m);
10.85 - else {
10.86 - CLFLog::getInstance().log(log::ELS_USER1,
10.87 - log::ELL_WARN,
10.88 - "Invalid material '%s' set. Using stub.",
10.89 - mMat.c_str());
10.90 - mNode->getModel()->setMaterial(
10.91 - 0, mRMgr->getModel("stub")->getMaterial(0));
10.92 - }
10.93 -}
10.94 -
10.95 void TileType::setMesh(const core::stringc &mesh) {
10.96 mMesh = mesh;
10.97 if (!mNode)
10.98 @@ -120,6 +109,33 @@
10.99
10.100 }
10.101
10.102 +void TileType::setSelected(const bool &selected) {
10.103 + mSelected = selected;
10.104 + if (!mNode)
10.105 + return;
10.106 + if (mSelected)
10.107 + mNode->getModel()->getMaterial(0)->setRenderFeature(render::ERPF_TRANSLUCENT_ADD);
10.108 + else
10.109 + mNode->getModel()->getMaterial(0)->setRenderFeature(render::ERPF_DIFFUSEMAP);
10.110 +}
10.111 +
10.112 +void TileType::setTex(const core::stringc &tex) {
10.113 + mTex = tex;
10.114 + if (!mNode)
10.115 + return;
10.116 + res::CTexture *t = mRMgr->getTexture(mTex);
10.117 + if (t)
10.118 + mNode->getModel()->getMaterial(0)->setTexture(0, t);
10.119 + else {
10.120 + CLFLog::getInstance().log(log::ELS_USER1,
10.121 + log::ELL_WARN,
10.122 + "Invalid texture '%s' set. Using stub.",
10.123 + mTex.c_str());
10.124 + mNode->getModel()->getMaterial(0)->setTexture(0,
10.125 + mRMgr->getModel("stub")->getMaterial(0)->getTexture(0));
10.126 + }
10.127 +}
10.128 +
10.129 void TileType::setVisibility(const bool &visibility) {
10.130
10.131 }
11.1 --- a/src/main.cpp Wed Oct 28 08:23:07 2009 +0700
11.2 +++ b/src/main.cpp Sat Oct 31 13:21:42 2009 +0700
11.3 @@ -1,7 +1,8 @@
11.4
11.5 +#include <lf/mj/Common.h>
11.6 +#include <lf/mj/Core.h>
11.7 +#include <lf/mj/Layout.h>
11.8 #include <lf/mj/TileTI.h>
11.9 -#include <lf/mj/Layout.h>
11.10 -#include <lf/mj/Core.h>
11.11
11.12 #include <iostream>
11.13 #include <vector>
11.14 @@ -11,14 +12,15 @@
11.15 using namespace std;
11.16
11.17 int main() {
11.18 - // [ID : Material] correspondance.
11.19 - vector<core::stringc> mats;
11.20 - mats.push_back("tile01");
11.21 - mats.push_back("tile02");
11.22 - mats.push_back("tile03");
11.23 - mats.push_back("tile04");
11.24 + // [ID : Texture] correspondance.
11.25 + vector<core::stringc> texs;
11.26 + texs.push_back("tile01.png");
11.27 + texs.push_back("tile02.png");
11.28 + texs.push_back("tile03.png");
11.29 + texs.push_back("tile04.png");
11.30 // Initialization.
11.31 initLF();
11.32 + //Common *cmn = new Common;
11.33 Core *core = new Core;
11.34 // Script.
11.35 CResourceManager::getInstance().loadResources("res/lfm/tile.lfm");
11.36 @@ -38,7 +40,13 @@
11.37 pos.Y * dim.Y,
11.38 -30 + pos.Z * dim.Z / 1.9));
11.39 inst->setID(i);
11.40 - inst->setMat(mats[i % 4]);
11.41 + inst->setTex(texs[i % 4]);
11.42 + inst->setGroup(i % 8);
11.43 + Common::hnt[inst->getNode()] = inst;
11.44 + /*
11.45 + if (i == ly.positions().size() - 1)
11.46 + inst->setSelected(true);
11.47 + */
11.48 }
11.49 tmpl->setRot(core::vector3df(0, 180, 0));
11.50 // Run.
11.51 @@ -51,6 +59,7 @@
11.52 // Clean up.
11.53 tmpl->drop();
11.54 delete core;
11.55 + //delete cmn;
11.56 deinitLF();
11.57 return 0;
11.58 }