1.1 --- a/CMakeLists.txt Tue Oct 27 21:32:42 2009 +0700
1.2 +++ b/CMakeLists.txt Wed Oct 28 00:24:09 2009 +0700
1.3 @@ -6,8 +6,9 @@
1.4 INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${MJ_SOURCE_DIR}/include)
1.5 LINK_DIRECTORIES(/usr/lib /usr/lib64 /usr/local/lib)
1.6 SET(MJ_SRC
1.7 + src/lf/mj/TileType.cpp
1.8 + src/lf/mj/Layout.cpp
1.9 src/lf/mj/Core.cpp
1.10 - src/lf/mj/TileType.cpp
1.11 src/main.cpp
1.12 )
1.13 # Generate TI files for TileType class
2.1 --- a/include/lf/mj/Layout.h Tue Oct 27 21:32:42 2009 +0700
2.2 +++ b/include/lf/mj/Layout.h Wed Oct 28 00:24:09 2009 +0700
2.3 @@ -2,6 +2,8 @@
2.4 #ifndef LF_MJ_LAYOUT_H
2.5 #define LF_MJ_LAYOUT_H
2.6
2.7 +#include <lf/Lightfeather.h>
2.8 +
2.9 #include <vector>
2.10 #include <fstream>
2.11
2.12 @@ -11,19 +13,19 @@
2.13 // Mahjongg layout
2.14 class Layout {
2.15 public:
2.16 - typedef std::vector<vector3di> Positions;
2.17 + typedef std::vector<core::vector3di> Positions;
2.18 typedef Positions::iterator PIt;
2.19
2.20 - Layout() {}
2.21 - ~Layout() {}
2.22 Positions positions() const {
2.23 return mPositions;
2.24 }
2.25 - void read(const core::stringc &fileName);
2.26 + // \return true on success, false when file could not be
2.27 + // opened or file format is wrong.
2.28 + bool read(const core::stringc &fileName);
2.29
2.30 private:
2.31 // Read a line skipping comments.
2.32 - bool readLine(std::ifstream &in, core::stringc &str);
2.33 + bool readLine(std::ifstream &in, std::string &str);
2.34
2.35 Positions mPositions;
2.36 };
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/res/layout/pirates.layout Wed Oct 28 00:24:09 2009 +0700
3.3 @@ -0,0 +1,81 @@
3.4 +kmahjongg-layout-v1.0
3.5 +.............121212.......12..12
3.6 +.............434343.......43..43
3.7 +.............12.............12..
3.8 +.........1212431212.........43..
3.9 +.........4343124343.......12..12
3.10 +.......12121243121212.....43..43
3.11 +.......43434312434343...........
3.12 +...1212121212431212121212.......
3.13 +...4343434343124343434343....12.
3.14 +12...........43..............43.
3.15 +43...........12..........121212.
3.16 +.12..........43..........434343.
3.17 +.431212121212121212121212121212.
3.18 +...4343434343434343434343434343.
3.19 +.......1212121212121212121212...
3.20 +.......4343434343434343434343...
3.21 +.............12.................
3.22 +.............43.................
3.23 +.............12.............12..
3.24 +.........12124312...........43..
3.25 +.........43431243...............
3.26 +.........1212431212.............
3.27 +.........4343124343.............
3.28 +.......12121243121212...........
3.29 +.......43434312434343........12.
3.30 +.............43..............43.
3.31 +.............12..........121212.
3.32 +.............43..........434343.
3.33 +.....121212121212121212121212...
3.34 +.....434343434343434343434343...
3.35 +.........1212121212121212.......
3.36 +.........4343434343434343.......
3.37 +................................
3.38 +................................
3.39 +................................
3.40 +...........12..12...............
3.41 +...........43..43...............
3.42 +.........1212..1212.............
3.43 +.........4343..4343.............
3.44 +.........1212..1212.............
3.45 +.........4343..4343.............
3.46 +................................
3.47 +.............................12.
3.48 +...........................1243.
3.49 +......121212121212121212.1243...
3.50 +......434343434343434343.43.....
3.51 +.........1212121212121212.......
3.52 +.........4343434343434343.......
3.53 +................................
3.54 +................................
3.55 +................................
3.56 +...........12..12...............
3.57 +...........43..43...............
3.58 +...........12..12...............
3.59 +...........43..43...............
3.60 +.........12......12.............
3.61 +.........43......43.............
3.62 +................................
3.63 +................................
3.64 +................................
3.65 +................................
3.66 +................................
3.67 +................................
3.68 +................................
3.69 +................................
3.70 +................................
3.71 +................................
3.72 +................................
3.73 +................................
3.74 +................................
3.75 +................................
3.76 +................................
3.77 +................................
3.78 +................................
3.79 +................................
3.80 +................................
3.81 +................................
3.82 +................................
3.83 +................................
3.84 +................................
4.1 --- a/res/lfm/tile.lfm Tue Oct 27 21:32:42 2009 +0700
4.2 +++ b/res/lfm/tile.lfm Wed Oct 28 00:24:09 2009 +0700
4.3 @@ -67,3 +67,8 @@
4.4 [/texture]
4.5 [/material]
4.6
4.7 +[texture]
4.8 +type=2D
4.9 +filename=res/tex/tile1.jpg
4.10 +name=tile1.jpg
4.11 +[/texture]
5.1 Binary file res/lfm/tile.lfmg has changed
6.1 Binary file res/tex/tile1.jpg has changed
7.1 --- a/src/lf/mj/Core.cpp Tue Oct 27 21:32:42 2009 +0700
7.2 +++ b/src/lf/mj/Core.cpp Wed Oct 28 00:24:09 2009 +0700
7.3 @@ -26,7 +26,8 @@
7.4 // Camera.
7.5 mCam = new scene::C3DCamera(mWin);
7.6 mCam->setBackgroundColor(core::CColorI(150, 170, 150, 0));
7.7 - mCam->setPosition(core::vector3df(0.0f, 0.0f, -20.0f));
7.8 + mCam->setPosition(core::vector3df(0.0f, 85.0f, -30.0f));
7.9 + mCam->setRotationDegrees(73.0f, 1.0f, 0.0f);
7.10 mWin->getRenderLayer3D()->addCamera(mCam);
7.11 mCam->drop();
7.12 mCamCtrl = new scene::CFPSController(mWin, mCam, true);
7.13 @@ -37,20 +38,31 @@
7.14 new render::CRenderStateLighting(true);
7.15 mCam->replaceRenderState(rsl);
7.16 rsl->drop();
7.17 + // No ambient.
7.18 + render::CRenderStateAmbientLight *rsal =
7.19 + new render::CRenderStateAmbientLight(core::CColorI(20, 20, 20, 255));
7.20 + mCam->replaceRenderState(rsal);
7.21 + rsal->drop();
7.22 // Light source.
7.23 scene::CLight *light = new scene::CLight(
7.24 + scene::ELT_SPOT,
7.25 core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
7.26 core::CColorF(1.0f, 1.0f, 1.0f, 1.0f),
7.27 - core::CColorF(0.5f, 0.5f, 0.5f, 1.0f),
7.28 - 0.0f,
7.29 + core::CColorF(0.0f, 0.0f, 0.0f, 0.0f),
7.30 + 20.0f,
7.31 + 1.0f,
7.32 + core::PI / 3,
7.33 + core::PI / 2,
7.34 0.0f,
7.35 0.0f,
7.36 1.0f / 500.0f,
7.37 0.0f);
7.38 - light->setPosition(core::vector3df(0, 30, 0));
7.39 + light->setPosition(core::vector3df(100, 30, 0));
7.40 mScn->addLight(light);
7.41 // So we can move it.
7.42 mScn->addSceneNode(light);
7.43 + // Point down.
7.44 + light->setRotationDegrees(core::vector3df(90, 0, 0));
7.45 light->drop();
7.46 scene::CSceneStateLight *csl = new scene::CSceneStateLight(light, true);
7.47 mScn->getRootSceneNode()->addSceneState(csl);
7.48 @@ -59,8 +71,8 @@
7.49 scene::CSceneNodeController *lrot = new scene::CFlyCircleController(
7.50 light,
7.51 core::vector3df(0, 30, 0),
7.52 - core::vector3df(15, 0, 30),
7.53 - 10,
7.54 + core::vector3df(0, 1, 0),
7.55 + 20,
7.56 0.1);
7.57 mScn->addSceneNodeController(lrot);
7.58 lrot->drop();
7.59 @@ -78,10 +90,49 @@
7.60 rsl = new render::CRenderStateLighting(false);
7.61 node->addRenderStateToMaterials(rsl);
7.62 node->drop();
7.63 + // Shadow mapping.
7.64 + light->makeShadowProjector(
7.65 + 2048,
7.66 + 2048,
7.67 + 1.0f,
7.68 + 1000.0f,
7.69 + 0.0f, 0.0f, 0.0f, 0.0f);
7.70 + scene::CSceneStateShadowCaster *sssc =
7.71 + new scene::CSceneStateShadowCaster(light);
7.72 + mScn->getRootSceneNode()->addSceneState(sssc);
7.73 + sssc->drop();
7.74 + scene::CSceneStateShadowReceiver *sssr =
7.75 + new scene::CSceneStateShadowReceiver(light, true);
7.76 + mScn->getRootSceneNode()->addSceneState(sssr);
7.77 + sssr->drop();
7.78 + // Ground plane.
7.79 + res::CPlaneModel *plane = new res::CPlaneModel(
7.80 + "plane",
7.81 + core::vector2df(100.0f, 100.0f),
7.82 + core::vector2dui(2, 2),
7.83 + core::vector2dui(10, 10));
7.84 + plane->getMaterial(0)->setRenderFeature(render::ERPF_DIFFUSEMAP);
7.85 + plane->getMaterial(0)->setTexture(0, mRMgr->getTexture("tile1.jpg"));
7.86 + node = new scene::CModelSceneNode(plane);
7.87 + mScn->addSceneNode(node);
7.88 + node->setPosition(core::vector3df(0, -10, 0));
7.89 + node->drop();
7.90 }
7.91
7.92 void Core::keyPressed(input::CKeyEvent &e) {
7.93 switch (e.getKey()) {
7.94 + case input::KEY_KEY_C:
7.95 + {
7.96 + core::vector3df pos = mCam->getPosition();
7.97 + std::cout << "pos(" << pos.X << ", "
7.98 + << pos.Y << ", "
7.99 + << pos.Z << ")\n";
7.100 + pos = mCam->getRotationDegrees();
7.101 + std::cout << "rot(" << pos.X << ", "
7.102 + << pos.Y << ", "
7.103 + << pos.Z << ")\n";
7.104 + }
7.105 + break;
7.106 case input::KEY_ESCAPE:
7.107 mWin->closeWindow();
7.108 break;
8.1 --- a/src/lf/mj/Layout.cpp Tue Oct 27 21:32:42 2009 +0700
8.2 +++ b/src/lf/mj/Layout.cpp Wed Oct 28 00:24:09 2009 +0700
8.3 @@ -4,45 +4,42 @@
8.4 namespace lf {
8.5 namespace mj {
8.6
8.7 -void Layout::read(const core::stringc &fileName) {
8.8 +bool Layout::read(const core::stringc &fileName) {
8.9 mPositions.clear();
8.10 - std::ifstream in(file.c_str());
8.11 - if (in.is_open()) {
8.12 - std::string s;
8.13 - readLine(in, s);
8.14 - if (s != "kmahjongg-layout-v1.0")
8.15 - throw std::runtime_error("Layout is not of 1.0 version");
8.16 - // Field by field
8.17 - u8 fieldID = 0;
8.18 - while (readLine(in, s)) {
8.19 - // Field (32 x 32)
8.20 - u8 ln = 1;
8.21 - std::string field = s;
8.22 - while (ln < 16 && readLine(in, s)) {
8.23 - field += s;
8.24 - ln++;
8.25 - }
8.26 - // Parse the field
8.27 - if (ln == 16) {
8.28 - for (u8 j = 0; j < 15; j++)
8.29 - for (u8 i = 0; i < 31; i++) {
8.30 - if (field[j * 32 + i] == '1' &&
8.31 - field[j * 32 + i + 1] == '2' &&
8.32 - field[(j + 1) * 32 + i] == '4' &&
8.33 - field[(j + 1) * 32 + i + 1] == '3') {
8.34 - Vector3I v = Vector3I(i, fieldID, 16 - j);
8.35 - mPositions.push_back(v);
8.36 - }
8.37 + std::ifstream in(fileName.c_str());
8.38 + if (!in.is_open())
8.39 + return false;
8.40 + std::string s;
8.41 + readLine(in, s);
8.42 + if (s != "kmahjongg-layout-v1.0")
8.43 + return false;
8.44 + // Field by field
8.45 + u8 fieldID = 0;
8.46 + while (readLine(in, s)) {
8.47 + // Field (32 x 32)
8.48 + u8 ln = 1;
8.49 + std::string field = s;
8.50 + while (ln < 16 && readLine(in, s)) {
8.51 + field += s;
8.52 + ln++;
8.53 + }
8.54 + // Parse the field
8.55 + if (ln == 16) {
8.56 + for (u8 j = 0; j < 15; j++)
8.57 + for (u8 i = 0; i < 31; i++) {
8.58 + if (field[j * 32 + i] == '1' &&
8.59 + field[j * 32 + i + 1] == '2' &&
8.60 + field[(j + 1) * 32 + i] == '4' &&
8.61 + field[(j + 1) * 32 + i + 1] == '3') {
8.62 + core::vector3di v =
8.63 + core::vector3di(i, fieldID, 16 - j);
8.64 + mPositions.push_back(v);
8.65 }
8.66 - fieldID++;
8.67 - }
8.68 + }
8.69 + fieldID++;
8.70 }
8.71 }
8.72 - else {
8.73 - std::stringstream ss;
8.74 - ss << "Could not open \"" << file << "\" file";
8.75 - throw std::runtime_error(ss.str());
8.76 - }
8.77 + return true;
8.78 }
8.79
8.80 bool Layout::readLine(std::ifstream &in, std::string &str) {
9.1 --- a/src/main.cpp Tue Oct 27 21:32:42 2009 +0700
9.2 +++ b/src/main.cpp Wed Oct 28 00:24:09 2009 +0700
9.3 @@ -1,5 +1,6 @@
9.4
9.5 #include <lf/mj/TileTI.h>
9.6 +#include <lf/mj/Layout.h>
9.7 #include <lf/mj/Core.h>
9.8
9.9 #include <iostream>
9.10 @@ -23,15 +24,30 @@
9.11 CResourceManager::getInstance().loadResources("res/lfm/tile.lfm");
9.12 TileTemplate *tmpl = new TileTemplate;
9.13 tmpl->setMesh("Tile");
9.14 - for (u32 i = 0; i < mats.size(); i++) {
9.15 - TileInstance *inst = tmpl->instantiate();
9.16 - inst->setPos(core::vector3df(i * 10, 0, 0));
9.17 - inst->setID(i);
9.18 - inst->setMat(mats[i]);
9.19 + // Get mesh dimensions.
9.20 + core::aabbox3df tbb =
9.21 + CResourceManager::getInstance().getMesh("Tile")->getBoundingBox();
9.22 + core::vector3df dim = tbb.MaxEdge - tbb.MinEdge;
9.23 + // Read in layout.
9.24 + Layout ly;
9.25 + if (ly.read("res/layout/pirates.layout")) {
9.26 + for (u32 i = 0; i < ly.positions().size(); i++) {
9.27 + TileInstance *inst = tmpl->instantiate();
9.28 + core::vector3di pos = ly.positions()[i];
9.29 + inst->setPos(core::vector3df(-30 + pos.X * dim.X / 1.9,
9.30 + pos.Y * dim.Y,
9.31 + -30 + pos.Z * dim.Z / 1.9));
9.32 + inst->setID(i);
9.33 + inst->setMat(mats[i % 4]);
9.34 + }
9.35 + tmpl->setRot(core::vector3df(0, 180, 0));
9.36 + // Run.
9.37 + core->run();
9.38 }
9.39 - tmpl->setRot(core::vector3df(0, 180, 0));
9.40 - // Run.
9.41 - core->run();
9.42 + else
9.43 + CLFLog::getInstance().log(log::ELS_USER1,
9.44 + log::ELL_ERROR,
9.45 + "Could not open layout");
9.46 // Clean up.
9.47 tmpl->drop();
9.48 delete core;