From dd009ccdfd62f9153dbc72f5f5de5d5f72979690 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 22 Apr 2014 15:13:38 +1000 Subject: Move all source into the new src directory, and shuffle a few other things around. --- src/extantz/CDemo.cpp | 510 +++++++++++++ src/extantz/CDemo.h | 63 ++ src/extantz/build.lua | 26 + src/extantz/crappisspuke.cpp | 294 ++++++++ src/extantz/extantz.c | 1588 +++++++++++++++++++++++++++++++++++++++++ src/extantz/extantz.edc | 30 + src/extantz/extantz.h | 215 ++++++ src/extantz/extantzCamera.cpp | 282 ++++++++ src/extantz/extantzCamera.h | 101 +++ 9 files changed, 3109 insertions(+) create mode 100644 src/extantz/CDemo.cpp create mode 100644 src/extantz/CDemo.h create mode 100755 src/extantz/build.lua create mode 100644 src/extantz/crappisspuke.cpp create mode 100644 src/extantz/extantz.c create mode 100644 src/extantz/extantz.edc create mode 100644 src/extantz/extantz.h create mode 100644 src/extantz/extantzCamera.cpp create mode 100644 src/extantz/extantzCamera.h (limited to 'src/extantz') diff --git a/src/extantz/CDemo.cpp b/src/extantz/CDemo.cpp new file mode 100644 index 0000000..0ca40f1 --- /dev/null +++ b/src/extantz/CDemo.cpp @@ -0,0 +1,510 @@ +// This is a Demo of the Irrlicht Engine (c) 2005-2009 by N.Gebhardt. +// This file is not documented. + +#include +#include "extantz.h" +#include "extantzCamera.h" +#include "CDemo.h" + + +CDemo::CDemo(GLData *gld, bool a) +: additive(a), + device(gld->device), + currentScene(0), + quakeLevelMesh(0), quakeLevelNode(0), skyboxNode(0), model1(0), model2(0), + campFire(0), metaSelector(0), mapSelector(0), sceneStartTime(0), + timeForThisScene(0) +{ +} + + +CDemo::~CDemo() +{ + if (mapSelector) + mapSelector->drop(); + + if (metaSelector) + metaSelector->drop(); +} + + +void CDemo::setup(GLData *gld) +{ + device = gld->device; + IrrlichtDevice *device = gld->device; +// IVideoDriver *driver = gld->driver; +// ISceneManager *smgr = gld->smgr; + + if (device->getFileSystem()->existFile("irrlicht.dat")) + device->getFileSystem()->addFileArchive("irrlicht.dat"); + else + device->getFileSystem()->addFileArchive("media/Irrlicht/irrlicht.dat"); + if (device->getFileSystem()->existFile("map-20kdm2.pk3")) + device->getFileSystem()->addFileArchive("map-20kdm2.pk3"); + else + device->getFileSystem()->addFileArchive("media/Irrlicht/map-20kdm2.pk3"); + + sceneStartTime = device->getTimer()->getTime(); + timeForThisScene = 0; + loadSceneData(); +} + + +void CDemo::preDraw(GLData *gld, u32 now) +{ + if (((now - sceneStartTime) > timeForThisScene) && (timeForThisScene != -1)) + switchToNextScene(gld); + + createParticleImpacts(); +} + + +bool CDemo::OnEvent(const SEvent& event) +{ + if (!device) + return false; + + if (( ((event.EventType == EET_KEY_INPUT_EVENT) && (event.KeyInput.Key == KEY_SPACE) && (event.KeyInput.PressedDown == false)) || + ((event.EventType == EET_MOUSE_INPUT_EVENT) && (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)) ) && (currentScene == 3)) + { + shoot(); + } + else + if (device->getSceneManager()->getActiveCamera()) + { + device->getSceneManager()->getActiveCamera()->OnEvent(event); + return true; + } + + return false; +} + + +void CDemo::switchToNextScene(GLData *gld) +{ + currentScene++; + if (currentScene > 3) + currentScene = 1; + + scene::ISceneManager* sm = device->getSceneManager(); + scene::ISceneNodeAnimator* sa = 0; + scene::ICameraSceneNode* camera = 0; + + camera = sm->getActiveCamera(); + + switch(currentScene) + { + case 1: // panorama camera + { + core::array points, points2; + + points.push_back(core::vector3df(-931.473755f, 900.0f, 2000.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 900.0f, 2000.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 700.0f, 1750.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 500.0f, 1500.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 300.0f, 1250.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 200.0f, 1000.0f)); // -49873 + points.push_back(core::vector3df(-931.473755f, 138.300003f, 987.279114f)); // -49873 + points.push_back(core::vector3df(-847.902222f, 136.757553f, 915.792725f)); // -50559 + points.push_back(core::vector3df(-748.680420f, 152.254501f, 826.418945f)); // -51964 + points.push_back(core::vector3df(-708.428406f, 213.569580f, 784.466675f)); // -53251 + points.push_back(core::vector3df(-686.217651f, 288.141174f, 762.965576f)); // -54015 + points.push_back(core::vector3df(-679.685059f, 365.095612f, 756.551453f)); // -54733 + points.push_back(core::vector3df(-671.317871f, 447.360107f, 749.394592f)); // -55588 + points.push_back(core::vector3df(-669.468445f, 583.335632f, 747.711853f)); // -56178 + points.push_back(core::vector3df(-667.611267f, 727.313232f, 746.018250f)); // -56757 + points.push_back(core::vector3df(-665.853210f, 862.791931f, 744.436096f)); // -57859 + points.push_back(core::vector3df(-642.649597f, 1026.047607f, 724.259827f)); // -59705 + points.push_back(core::vector3df(-517.793884f, 838.396790f, 490.326050f)); // -60983 + points.push_back(core::vector3df(-474.387299f, 715.691467f, 344.639984f)); // -61629 + points.push_back(core::vector3df(-444.600250f, 601.155701f, 180.938095f)); // -62319 + points.push_back(core::vector3df(-414.808899f, 479.691406f, 4.866660f)); // -63048 + points.push_back(core::vector3df(-410.418945f, 429.642242f, -134.332687f)); // -63757 + points.push_back(core::vector3df(-399.837585f, 411.498383f, -349.350983f)); // -64418 + points.push_back(core::vector3df(-390.756653f, 403.970093f, -524.454407f)); // -65005 + points.push_back(core::vector3df(-334.864227f, 350.065491f, -732.397400f)); // -65701 + points.push_back(core::vector3df(-195.253387f, 349.577209f, -812.475891f)); // -66335 + points.push_back(core::vector3df(16.255573f, 363.743134f, -833.800415f)); // -67170 + points.push_back(core::vector3df(234.940964f, 352.957825f, -820.150696f)); // -67939 + points.push_back(core::vector3df(436.797668f, 349.236450f, -816.914185f)); // -68596 + points.push_back(core::vector3df(575.236206f, 356.244812f, -719.788513f)); // -69166 + points.push_back(core::vector3df(594.131042f, 387.173828f, -609.675598f)); // -69744 + points.push_back(core::vector3df(617.615234f, 412.002899f, -326.174072f)); // -70640 + points.push_back(core::vector3df(606.456848f, 403.221954f, -104.179291f)); // -71390 + points.push_back(core::vector3df(610.958252f, 407.037750f, 117.209778f)); // -72085 + points.push_back(core::vector3df(597.956909f, 395.167877f, 345.942200f)); // -72817 + points.push_back(core::vector3df(587.383118f, 391.444519f, 566.098633f)); // -73477 + points.push_back(core::vector3df(559.572449f, 371.991333f, 777.689453f)); // -74124 + points.push_back(core::vector3df(423.753204f, 329.990051f, 925.859741f)); // -74941 + points.push_back(core::vector3df(247.520050f, 252.818954f, 935.311829f)); // -75651 + points.push_back(core::vector3df(114.756012f, 199.799759f, 805.014160f)); + points.push_back(core::vector3df(96.783348f, 181.639481f, 648.188110f)); + points.push_back(core::vector3df(97.865623f, 138.905975f, 484.812561f)); + points.push_back(core::vector3df(99.612457f, 102.463669f, 347.603210f)); + points.push_back(core::vector3df(99.0f, 95.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 90.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 85.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 80.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 75.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 75.0f, 347.0f)); + points.push_back(core::vector3df(99.0f, 75.0f, 347.0f)); + timeForThisScene = (points.size() - 2) * 1000; + camera = sm->addCameraSceneNode(0, points[0], core::vector3df(0, 400, 0)); + sa = sm->createFollowSplineAnimator(device->getTimer()->getTime(), points, 1.0f, 0.6f, false, false); + camera->addAnimator(sa); + sa->drop(); + } + break; + + case 2: // panorama camera + { + core::array points; + + camera->setTarget(core::vector3df(100, 145, -80)); + + points.push_back(core::vector3df(99.0f, 75.0f, 347.0f)); + points.push_back(core::vector3df(100.0f, 75.0f, 347.0f)); + points.push_back(core::vector3df(105.0f, 75.0f, 347.0f)); + points.push_back(core::vector3df(110.0f, 70.0f, 347.0f)); + points.push_back(core::vector3df(115.0f, 70.0f, -160.0f)); + points.push_back(core::vector3df(120.0f, 70.0f, -160.0f)); + points.push_back(core::vector3df(125.0f, 65.0f, -160.0f)); + points.push_back(core::vector3df(130.0f, 65.0f, -160.0f)); + points.push_back(core::vector3df(135.0f, 65.0f, -160.0f)); + points.push_back(core::vector3df(150.0f, 170.0f, -160.0f)); + points.push_back(core::vector3df(150.0f, 170.0f, -160.0f)); + points.push_back(core::vector3df(150.0f, 170.0f, -160.0f)); + timeForThisScene = (points.size() - 2) * 1000; + sa = sm->createFollowSplineAnimator(device->getTimer()->getTime(), points, 1.0f, 0.6f, false, false); + camera->addAnimator(sa); + sa->drop(); + } + break; + + case 3: // interactive, go around + { + if (camera) + { + sm->setActiveCamera(0); + camera->remove(); + camera = 0; + } + timeForThisScene = -1; + + gld->camera = addExtantzCamera(sm, NULL, -1); + camera = gld->camera; + camera->setPosition(core::vector3df(108, 140, -140)); + camera->setFarValue(5000.0f); + gld->move = getCameraMove(gld->camera); + + scene::ISceneNodeAnimatorCollisionResponse* collider = + sm->createCollisionResponseAnimator(metaSelector, camera, core::vector3df(25, 50, 25), core::vector3df(0, quakeLevelMesh ? -10.f : 0.0f, 0), core::vector3df(0, 45, 0), 0.005f); + camera->addAnimator(collider); + collider->drop(); + } + break; + } + + sceneStartTime = device->getTimer()->getTime(); +} + + +void CDemo::loadSceneData() +{ + // load quake level + + video::IVideoDriver* driver = device->getVideoDriver(); + scene::ISceneManager* sm = device->getSceneManager(); + + // Quake3 Shader controls Z-Writing + sm->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); + + quakeLevelMesh = (scene::IQ3LevelMesh*) sm->getMesh("maps/20kdm2.bsp"); + + if (quakeLevelMesh) + { + u32 i; + + //move all quake level meshes (non-realtime) + core::matrix4 m; + m.setTranslation(core::vector3df(-1300,-70,-1249)); + + for (i = 0; i != scene::quake3::E_Q3_MESH_SIZE; ++i) + sm->getMeshManipulator()->transform(quakeLevelMesh->getMesh(i), m); + + quakeLevelNode = sm->addOctreeSceneNode(quakeLevelMesh->getMesh( scene::quake3::E_Q3_MESH_GEOMETRY)); + if (quakeLevelNode) + { + //quakeLevelNode->setPosition(core::vector3df(-1300, -70, -1249)); + quakeLevelNode->setVisible(true); + + // create map triangle selector + mapSelector = sm->createOctreeTriangleSelector(quakeLevelMesh->getMesh(0), quakeLevelNode, 128); + + // if not using shader and no gamma it's better to use more lighting, because + // quake3 level are usually dark + quakeLevelNode->setMaterialType(video::EMT_LIGHTMAP_M4); + + // set additive blending if wanted + if (additive) + quakeLevelNode->setMaterialType(video::EMT_LIGHTMAP_ADD); + } + + // the additional mesh can be quite huge and is unoptimized + scene::IMesh *additional_mesh = quakeLevelMesh->getMesh(scene::quake3::E_Q3_MESH_ITEMS); + + for (i = 0; i != additional_mesh->getMeshBufferCount(); ++i) + { + scene::IMeshBuffer *meshBuffer = additional_mesh->getMeshBuffer(i); + const video::SMaterial &material = meshBuffer->getMaterial(); + + //! The ShaderIndex is stored in the material parameter + s32 shaderIndex = (s32) material.MaterialTypeParam2; + + // the meshbuffer can be rendered without additional support, or it has no shader + const scene::quake3::IShader *shader = quakeLevelMesh->getShader(shaderIndex); + if (0 == shader) + { + continue; + } + // Now add the MeshBuffer(s) with the current Shader to the Manager + sm->addQuake3SceneNode(meshBuffer, shader); + } + } + + // load sydney model and create 2 instances + + scene::IAnimatedMesh *mesh = 0; + mesh = sm->getMesh("media/Irrlicht/sydney.md2"); + if (mesh) + { + model1 = sm->addAnimatedMeshSceneNode(mesh); + if (model1) + { + model1->setMaterialTexture(0, driver->getTexture("media/Irrlicht/sydney.bmp")); + model1->setPosition(core::vector3df(100, 40, -80)); + model1->setScale(core::vector3df(2, 2, 2)); + model1->setMD2Animation(scene::EMAT_STAND); + model1->setMaterialFlag(video::EMF_LIGHTING, true); + model1->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true); + model1->addShadowVolumeSceneNode(); + } + + model2 = sm->addAnimatedMeshSceneNode(mesh); + if (model2) + { + model2->setMaterialTexture(0, driver->getTexture("media/Irrlicht/spheremap.jpg")); + model2->setPosition(core::vector3df(180, 15, -60)); + model2->setScale(core::vector3df(2, 2, 2)); + model2->setMD2Animation(scene::EMAT_RUN); + model2->setMaterialFlag(video::EMF_LIGHTING, false); + model2->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true); + model2->setMaterialType(video::EMT_SPHERE_MAP); + model2->addShadowVolumeSceneNode(); + } + } + + scene::ISceneNodeAnimator *anim = 0; + + // create sky box + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); + skyboxNode = sm->addSkyBoxSceneNode( + driver->getTexture("media/Irrlicht/irrlicht2_up.jpg"), + driver->getTexture("media/Irrlicht/irrlicht2_dn.jpg"), + driver->getTexture("media/Irrlicht/irrlicht2_lf.jpg"), + driver->getTexture("media/Irrlicht/irrlicht2_rt.jpg"), + driver->getTexture("media/Irrlicht/irrlicht2_ft.jpg"), + driver->getTexture("media/Irrlicht/irrlicht2_bk.jpg")); + driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true); + + // create walk-between-portals animation + core::vector3df waypoint[2]; + waypoint[0].set(-150, 40, 100); + waypoint[1].set(350, 40, 100); + + if (model2) + { + anim = device->getSceneManager()->createFlyStraightAnimator(waypoint[0], waypoint[1], 2000, true); + model2->addAnimator(anim); + anim->drop(); + } + + // create animation for portals; + core::array textures; + for (s32 g=1; g<8; ++g) + { + core::stringc tmp("media/Irrlicht/portal"); + tmp += g; + tmp += ".bmp"; + video::ITexture* t = driver->getTexture(tmp); + textures.push_back(t); + } + + anim = sm->createTextureAnimator(textures, 100); + + // create portals + scene::IBillboardSceneNode* bill = 0; + for (int r = 0; r < 2; ++r) + { + bill = sm->addBillboardSceneNode(0, core::dimension2d(100, 100), waypoint[r]+ core::vector3df(0, 20, 0)); + bill->setMaterialFlag(video::EMF_LIGHTING, false); + bill->setMaterialTexture(0, driver->getTexture("media/Irrlicht/portal1.bmp")); + bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); + bill->addAnimator(anim); + } + + anim->drop(); + + // create circle flying dynamic light with transparent billboard attached + scene::ILightSceneNode *light = 0; + + light = sm->addLightSceneNode(0, core::vector3df(0, 0, 0), video::SColorf(1.0f, 1.0f, 1.f, 1.0f), 500.f); + anim = sm->createFlyCircleAnimator(core::vector3df(100, 150, 80), 80.0f, 0.0005f); + + light->addAnimator(anim); + anim->drop(); + + bill = device->getSceneManager()->addBillboardSceneNode(light, core::dimension2d(40, 40)); + bill->setMaterialFlag(video::EMF_LIGHTING, false); + bill->setMaterialTexture(0, driver->getTexture("media/Irrlicht/particlewhite.bmp")); + bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); + + // create meta triangle selector with all triangles selectors in it. + metaSelector = sm->createMetaTriangleSelector(); + metaSelector->addTriangleSelector(mapSelector); + + // create camp fire + campFire = sm->addParticleSystemSceneNode(false); + campFire->setPosition(core::vector3df(100, 120, 600)); + campFire->setScale(core::vector3df(2, 2, 2)); + + scene::IParticleEmitter *em = campFire->createBoxEmitter(core::aabbox3d(-7, 0, -7, 7, 1, 7), core::vector3df(0.0f, 0.06f, 0.0f), 80, 100, video::SColor(1, 255, 255, 255), video::SColor(1, 255, 255, 255), 800, 2000); + em->setMinStartSize(core::dimension2d(20.0f, 10.0f)); + em->setMaxStartSize(core::dimension2d(20.0f, 10.0f)); + campFire->setEmitter(em); + em->drop(); + + scene::IParticleAffector *paf = campFire->createFadeOutParticleAffector(); + campFire->addAffector(paf); + paf->drop(); + + campFire->setMaterialFlag(video::EMF_LIGHTING, false); + campFire->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false); + campFire->setMaterialTexture(0, driver->getTexture("media/Irrlicht/fireball.bmp")); + campFire->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); +} + + +void CDemo::shoot() +{ + scene::ISceneManager *sm = device->getSceneManager(); + scene::ICameraSceneNode *camera = sm->getActiveCamera(); + + if ((!camera) || (!mapSelector)) + return; + + SParticleImpact imp; + imp.when = 0; + + // get line of camera + core::vector3df start = camera->getPosition(); + core::vector3df end = (camera->getTarget() - start); + end.normalize(); + start += end * 8.0f; + end = start + (end * camera->getFarValue()); + + core::triangle3df triangle; + + core::line3d line(start, end); + + // get intersection point with map + scene::ISceneNode* hitNode; + if (sm->getSceneCollisionManager()->getCollisionPoint(line, mapSelector, end, triangle, hitNode)) + { + // collides with wall + core::vector3df out = triangle.getNormal(); + out.setLength(0.03f); + + imp.when = 1; + imp.outVector = out; + imp.pos = end; + } + else + { + // doesnt collide with wall + core::vector3df start = camera->getPosition(); + core::vector3df end = (camera->getTarget() - start); + end.normalize(); + start += end * 8.0f; + end = start + (end * camera->getFarValue()); + } + + // create fire ball + scene::ISceneNode *node = 0; + node = sm->addBillboardSceneNode(0, core::dimension2d(25, 25), start); + + node->setMaterialFlag(video::EMF_LIGHTING, false); + node->setMaterialTexture(0, device->getVideoDriver()->getTexture("media/Irrlicht/fireball.bmp")); + node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); + + f32 length = (f32)(end - start).getLength(); + const f32 speed = 0.6f; + u32 time = (u32) (length / speed); + + scene::ISceneNodeAnimator *anim = 0; + + // set flight line + anim = sm->createFlyStraightAnimator(start, end, time); + node->addAnimator(anim); + anim->drop(); + + anim = sm->createDeleteAnimator(time); + node->addAnimator(anim); + anim->drop(); + + if (imp.when) + { + // create impact note + imp.when = device->getTimer()->getTime() + (time - 100); + Impacts.push_back(imp); + } +} + + +void CDemo::createParticleImpacts() +{ + u32 now = device->getTimer()->getTime(); + scene::ISceneManager *sm = device->getSceneManager(); + + for (s32 i = 0; i < (s32) Impacts.size(); ++i) + if (now > Impacts[i].when) + { + // create smoke particle system + scene::IParticleSystemSceneNode *pas = 0; + + pas = sm->addParticleSystemSceneNode(false, 0, -1, Impacts[i].pos); + + pas->setParticleSize(core::dimension2d(10.0f, 10.0f)); + + scene::IParticleEmitter* em = pas->createBoxEmitter(core::aabbox3d(-5, -5, -5, 5, 5, 5), Impacts[i].outVector, 20, 40, video::SColor(50, 255, 255, 255), video::SColor(50, 255, 255, 255), 1200, 1600, 20); + pas->setEmitter(em); + em->drop(); + + scene::IParticleAffector *paf = campFire->createFadeOutParticleAffector(); + pas->addAffector(paf); + paf->drop(); + + pas->setMaterialFlag(video::EMF_LIGHTING, false); + pas->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false); + pas->setMaterialTexture(0, device->getVideoDriver()->getTexture("media/Irrlicht/smoke.bmp")); + pas->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); + + scene::ISceneNodeAnimator *anim = sm->createDeleteAnimator(2000); + pas->addAnimator(anim); + anim->drop(); + + // delete entry + Impacts.erase(i); + i--; + } +} diff --git a/src/extantz/CDemo.h b/src/extantz/CDemo.h new file mode 100644 index 0000000..035c01f --- /dev/null +++ b/src/extantz/CDemo.h @@ -0,0 +1,63 @@ +// This is a Demo of the Irrlicht Engine (c) 2006 by N.Gebhardt. +// This file is not documented. + +#ifndef __C_DEMO_H_INCLUDED__ +#define __C_DEMO_H_INCLUDED__ + +#ifdef _IRR_WINDOWS_ +#include +#endif + +const int CAMERA_COUNT = 7; + +class CDemo : public IEventReceiver +{ +public: + + CDemo(GLData *gld, bool additive); + + ~CDemo(); + + void setup(GLData *gld); + void preDraw(GLData *gld, u32 now); + + virtual bool OnEvent(const SEvent& event); + +private: + + void createLoadingScreen(); + void loadSceneData(); + void switchToNextScene(GLData *gld); + void shoot(); + void createParticleImpacts(); + + bool additive; + IrrlichtDevice *device; + + struct SParticleImpact + { + u32 when; + core::vector3df pos; + core::vector3df outVector; + }; + + int currentScene; + + scene::IQ3LevelMesh* quakeLevelMesh; + scene::ISceneNode* quakeLevelNode; + scene::ISceneNode* skyboxNode; + scene::IAnimatedMeshSceneNode* model1; + scene::IAnimatedMeshSceneNode* model2; + scene::IParticleSystemSceneNode* campFire; + + scene::IMetaTriangleSelector* metaSelector; + scene::ITriangleSelector* mapSelector; + + s32 sceneStartTime; + s32 timeForThisScene; + + core::array Impacts; +}; + +#endif + diff --git a/src/extantz/build.lua b/src/extantz/build.lua new file mode 100755 index 0000000..0bb2a0b --- /dev/null +++ b/src/extantz/build.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +local dir = ... + +if 'nil' == type(dir) then + local build, err = loadfile('../../build.lua') + if build then + setfenv(build, getfenv(2)) + build(2) + else + print("ERROR - " .. err) + end + dir = workingDir +end + +CFLAGS = CFLAGS .. ' -I../../libraries/irrlicht-1.8.1/include -I/usr/X11R6/include' +LDFLAGS = LDFLAGS .. ' -L../../libraries/irrlicht-1.8.1/lib/Linux' +libs = libs .. ' -lIrrlicht -lGL -lbz2' + +removeFiles(dir, {'../../extantz', 'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', '../../media/extantz.edj'}) + +runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../media/extantz.edj') +runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) +runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) +runCommand('extantz', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) +runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' extantz.c crappisspuke.o CDemo.o extantzCamera.o -o ../../extantz ' .. LDFLAGS .. ' ' .. libs) diff --git a/src/extantz/crappisspuke.cpp b/src/extantz/crappisspuke.cpp new file mode 100644 index 0000000..2af9dde --- /dev/null +++ b/src/extantz/crappisspuke.cpp @@ -0,0 +1,294 @@ + +#include +#include "extantz.h" +#include "CDemo.h" + + +SExposedVideoData videoData; + +IAnimatedMeshSceneNode *node; +CDemo *myDemo; +// This is the movement speed in units per second. +const f32 MOVEMENT_SPEED = 5.f; +// In order to do framerate independent movement, we have to know +// how long it was since the last frame +u32 then; + +#ifdef __cplusplus +extern "C" { +#endif + +EAPI int startIrr(GLData *gld) +{ + SIrrlichtCreationParameters params; + IrrlichtDevice *device; + IVideoDriver *driver; + ISceneManager *smgr; + bool additive = true; + + if (!gld->useIrr) + return 1; // Return 1 so that the caller stops asking on each frame. + +#if USE_IRR + void *display = NULL; + unsigned long sfc = 0; + void *ctx = NULL; +// Evas_GL_API *gl = gld->glApi; + +#if USE_DEMO + myDemo = new CDemo(gld, additive); +#endif + +/* Raster says - +4. evas exposes an opengl-es2 api. any existing engine needs to be adapted to +use this. that's pretty much the end of that. if the engine doesn't have a +gles2 port.. it will need one. once it has one, then it is a simple matter of +replacing all the gl calls as follows: + +glDrawArrays() -> api->glDrawArrays() +glBindBuffer() -> api->glBindBuffer() + +you could make the port switchable with a macro: + +#ifdef EVASGL +#define EG() my_evas_gl_api-> +#else +#define EG() +#endif + +then fix up all the gl calls to be + +EG()glDrawArrays() +EG()glBindBuffer() + +etc. + +doing the above allows evas to decide how to share context. it may allocate a +separate context or share its own. either way as far as the evasgl api user is +concerned.. they get their own private context to play with. if it does NOT do +the above (use the api exposed by evas gl) then wrapping can't context switches +can't work. all gl calls HAVE to go through the wrapped api to work right. this +is because we can't REPLACE the internals of the gl driver which otherwise +would be managing context and state all internally and we have zero access to +that - especially with closed drivers. we'd end up writing a proxy gl library +which conflicts with real gl symbol-wise (thus taking over and replacing +normal gl calls) and i know i have no interest in maintaining a separate +libGLwhatever.so that is an exact copy of gl and it's api's just to wrap it +when we expose that wrapper without symbol complications via evas gl. + +5. the engine will need to be adapted so the draw function is callable - eg by +elm_glview. then it's easy to switch where rendering happens. evas offers a fast +path to avoid buffer copies and make the gl view draw part of the evas +rendering path directly. this would offer almost zero overhead vs doing it +directly with egl/gles etc. to your backbuffer yourself, BUT gets you the bonus +of having your 3d view as part of a larger scenegraph. combine 2 or 3 of them +in a single window. overlay with evas objects or elm widgets for hud etc. all +for free. this also implies the engine has to integrate to the efl mainloop +etc. of course. +*/ + + + sfc = ecore_evas_window_get(gld->ee); + // This is the way Raster wants me to do things, but these functions are not actually available. Pffft +// ctx = gl->glGetCurrentContext(); +// display = gl->glGetCurrentDisplay(); + ctx = glXGetCurrentContext(); + display = glXGetCurrentDisplay(); + /* For using a pre existing X11 window (with optional OpenGL). */ + videoData = SExposedVideoData(); + videoData.OpenGLLinux.X11Display = display; // void * - Connection to the X server. + videoData.OpenGLLinux.X11Window = sfc; // unsigned long - Specifies a GLX drawable. Must be either an X window ID or a GLX pixmap ID. + videoData.OpenGLLinux.X11Context = ctx; // void * - Specifies a GLX rendering context that is to be attached to drawable. + + /* + The most important function of the engine is the createDevice() + function. The IrrlichtDevice is created by it, which is the root + object for doing anything with the engine. createDevice() has 7 + parameters: + + - deviceType: Type of the device. This can currently be the Null-device, + one of the two software renderers, D3D8, D3D9, or OpenGL. In this + example we use EDT_SOFTWARE, but to try out, you might want to + change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, + EDT_DIRECT3D9, or EDT_OPENGL. + + - windowSize: Size of the Window or screen in FullScreenMode to be + created. In this example we use 640x480. + + - bits: Amount of color bits per pixel. This should be 16 or 32. The + parameter is often ignored when running in windowed mode. + + - fullscreen: Specifies if we want the device to run in fullscreen mode + or not. + + - stencilbuffer: Specifies if we want to use the stencil buffer (for + drawing shadows). + + - vsync: Specifies if we want to have vsync enabled, this is only useful + in fullscreen mode. + + - eventReceiver: An object to receive events. We do not want to use this + parameter here, and set it to 0. + + Always check the return value to cope with unsupported drivers, + dimensions, etc. + */ + + params.DeviceType = EIDT_X11; // EIDT_BEST might be preferable. + if (ctx) + params.DriverType = video::EDT_OPENGL; + else + params.DriverType = video::EDT_BURNINGSVIDEO; + params.WindowSize = dimension2d(gld->sfc_w, gld->sfc_h); + params.Bits = 32; // Ignored in windowed mode? + params.ZBufferBits = 16; // Default 16. + params.Fullscreen = false; // The default anyway. + params.Stencilbuffer = false; // For shadows. + params.Vsync = false; + params.AntiAlias=true; + params.WithAlphaChannel = true; + params.IgnoreInput = true; + params.EventReceiver = myDemo; // Probably useless, EFL might not let Irrlicht grab the input. + params.WindowId = (void *) videoData.OpenGLLinux.X11Window; + params.VideoData = &videoData; + + device = createDeviceEx(params); + + if (!device) + return 0; + gld->device = device; + + /* + Get a pointer to the VideoDriver and the SceneManager so that we do not always have to write + device->getVideoDriver() or device->getSceneManager(). + */ + driver = device->getVideoDriver(); gld->driver = driver; + smgr = device->getSceneManager(); gld->smgr = smgr; + + // FIXME - this is what makes the window vanish in EFL 1.8, but worked fine in 1.7 I think. +// device->setResizable(true); + driver->OnResize(dimension2d(gld->img_w, gld->img_h)); + // Just gives me a blank screen. grrrr +// driver->setViewPort(rect(0, 0, gld->img_w, gld->img_h)); + + // set ambient light + smgr->setAmbientLight (video::SColorf(0x00c0c0c0)); + +#if USE_DEMO + myDemo->setup(gld); +#else + /* + To show something interesting, we load a Quake 2 model and display it. + We only have to get the Mesh from the Scene Manager with getMesh() and add + a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We + check the return value of getMesh() to become aware of loading problems + and other errors. + + Instead of writing the filename sydney.md2, it would also be possible + to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any + other supported file format. By the way, that cool Quake 2 model + called sydney was modelled by Brian Collins. + */ + IAnimatedMesh* mesh = smgr->getMesh("media/Irrlicht/sydney.md2"); + if (!mesh) + { + device->drop(); + return 0; + } + node = smgr->addAnimatedMeshSceneNode(mesh); + + /* + To let the mesh look a little bit nicer, we change its material. We + disable lighting because we do not have a dynamic light in here, and + the mesh would be totally black otherwise. Then we set the frame loop, + such that the predefined STAND animation is used. And last, we apply a + texture to the mesh. Without it the mesh would be drawn using only a + color. + */ + if (node) + { +// node->setMaterialFlag(EMF_LIGHTING, false); + node->setMD2Animation(scene::EMAT_STAND); + node->setMaterialTexture(0, driver->getTexture("media/Irrlicht/sydney.bmp")); + } + + /* + To look at the mesh, we place a camera into 3d space at the position + (0, 30, -40). The camera looks from there to (0,5,0), which is + approximately the place where our md2 model is. + */ + smgr->addCameraSceneNode(0, vector3df(50, 70, -65), vector3df(0, 50, 0)); +#endif + + then = device->getTimer()->getTime(); +#endif + return 1; +} + +EAPI void drawIrr_start(GLData *gld) +{ + if (gld->useIrr) + { + IrrlichtDevice *device = gld->device; + IVideoDriver *driver = gld->driver; + ISceneManager *smgr = gld->smgr; + + // Increase virtual timer time, instead of device->run() if doing our own input processing. + device->getTimer()->tick(); + + // Work out a frame delta time. + const u32 now = device->getTimer()->getTime(); +// const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds + then = now; + + +#if USE_DEMO + myDemo->preDraw(gld, now); +#else + core::vector3df nodePosition = node->getPosition(); +// nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime; + node->setPosition(nodePosition); +#endif + + /* + Anything can be drawn between a beginScene() and an endScene() + call. The beginScene() call clears the screen with a color and + the depth buffer, if desired. Then we let the Scene Manager and + the GUI Environment draw their content. With the endScene() + call everything is presented on the screen. + */ + driver->beginScene(true, true, SColor(255, 255, 255, 255), videoData, NULL); // This does the context change, then clearBuffers() + + smgr->drawAll(); + } +} + +EAPI void drawIrr_end(GLData *gld) +{ + IVideoDriver *driver = gld->driver; + + if (gld->useIrr) + driver->endScene(); +} + +EAPI void finishIrr(GLData *gld) +{ + IrrlichtDevice *device = gld->device; + + /* + After we are done with the render loop, we have to delete the Irrlicht + Device created before with createDevice(). In the Irrlicht Engine, you + have to delete all objects you created with a method or function which + starts with 'create'. The object is simply deleted by calling ->drop(). + See the documentation at irr::IReferenceCounted::drop() for more + information. + */ + if (gld->useIrr) + device->drop(); +} + + +#ifdef __cplusplus +} +#endif + diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c new file mode 100644 index 0000000..09b5196 --- /dev/null +++ b/src/extantz/extantz.c @@ -0,0 +1,1588 @@ +#include "extantz.h" + + +int _log_domain = -1; + +Eina_Hash *grids; +Eina_Hash *viewers; + +static char *gridTest[][3] = +{ + {"3rd Rock Grid", "http://grid.3rdrockgrid.com:8002/", "http://grid.3rdrockgrid.com/3rg_login"}, + {"Infinite Grid", "http://grid.infinitegrid.org:8002/", "http://www.infinitegrid.org/loginscreen.php"}, + {"Second Life Grid", "https://login.agni.lindenlab.com/cgi-bin/login.cgi", "http://secondlife.com/"}, + {NULL, NULL, NULL} +}; + +static char *accountTest[][3] = +{ + {"3rd Rock Grid", "onefang rejected", "password"}, + {"Infinite Grid", "infinite onefang", "MyB1GSecrit"}, + {"Infinite Grid", "onefang rejected", "MySecrit"}, + {NULL, NULL, NULL} +}; + + +static char *viewerTest[][3] = +{ + {"Imprudence", "1.4.0 beta 3", ""}, + {"Kokua", "3.4.4.25633", ""}, + {"meta-impy", "1.4.0 beta 1.5", ""}, + {"SL", "v3", ""}, + {NULL, NULL, NULL} +}; + + +static Elm_Genlist_Item_Class *grid_gic = NULL; +static Elm_Genlist_Item_Class *account_gic = NULL; +static Elm_Genlist_Item_Class *viewer_gic = NULL; + +//static const char *img1 = PACKAGE_DATA_DIR "/media/plant_01.jpg"; +//static const char *img2 = PACKAGE_DATA_DIR "/media/sky_01.jpg"; +static const char *img3 = PACKAGE_DATA_DIR "/media/rock_01.jpg"; + + +#define EPHYSICS_TEST_THEME "extantz" + + +#if DO_GEARS +//--------------------------------// +// Gear Stuff. + +static GLfloat *vert(GLfloat *p, GLfloat x, GLfloat y, GLfloat z, GLfloat *n) +{ + p[0] = x; + p[1] = y; + p[2] = z; + p[3] = n[0]; + p[4] = n[1]; + p[5] = n[2]; + + return p + 6; +} + +/* Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static Gear *make_gear(GLData *gld, GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat da; + GLfloat *v; + Gear *gear; + double s[5], c[5]; + GLfloat normal[3]; + const int tris_per_tooth = 20; + Evas_GL_API *gl = gld->glApi; + + gear = (Gear*)malloc(sizeof(Gear)); + if (gear == NULL) + return NULL; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth / 2.0; + r2 = outer_radius + tooth_depth / 2.0; + + da = 2.0 * M_PI / teeth / 4.0; + + gear->vertices = calloc(teeth * tris_per_tooth * 3 * 6, sizeof *gear->vertices); + s[4] = 0; + c[4] = 1; + v = gear->vertices; + for (i = 0; i < teeth; i++) + { + s[0] = s[4]; + c[0] = c[4]; + s[1] = sin(i * 2.0 * M_PI / teeth + da); + c[1] = cos(i * 2.0 * M_PI / teeth + da); + s[2] = sin(i * 2.0 * M_PI / teeth + da * 2); + c[2] = cos(i * 2.0 * M_PI / teeth + da * 2); + s[3] = sin(i * 2.0 * M_PI / teeth + da * 3); + c[3] = cos(i * 2.0 * M_PI / teeth + da * 3); + s[4] = sin(i * 2.0 * M_PI / teeth + da * 4); + c[4] = cos(i * 2.0 * M_PI / teeth + da * 4); + + normal[0] = 0.0; + normal[1] = 0.0; + normal[2] = 1.0; + + v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); + + v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); + v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal); + v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); + v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal); + v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal); + v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal); + v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal); + + v = vert(v, r0 * c[4], r0 * s[4], width * 0.5, normal); + v = vert(v, r0 * c[0], r0 * s[0], width * 0.5, normal); + v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); + v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal); + + normal[0] = 0.0; + normal[1] = 0.0; + normal[2] = -1.0; + + v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); + + v = vert(v, r0 * c[4], r0 * s[4], -width * 0.5, normal); + v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); + v = vert(v, r0 * c[0], r0 * s[0], -width * 0.5, normal); + v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal); + v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal); + v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal); + v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal); + + v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); + + v = vert(v, r1 * c[0], r1 * s[0], width * 0.5, normal); + v = vert(v, r1 * c[0], r1 * s[0], -width * 0.5, normal); + v = vert(v, r2 * c[1], r2 * s[1], width * 0.5, normal); + v = vert(v, r2 * c[1], r2 * s[1], -width * 0.5, normal); + v = vert(v, r2 * c[2], r2 * s[2], width * 0.5, normal); + v = vert(v, r2 * c[2], r2 * s[2], -width * 0.5, normal); + v = vert(v, r1 * c[3], r1 * s[3], width * 0.5, normal); + v = vert(v, r1 * c[3], r1 * s[3], -width * 0.5, normal); + v = vert(v, r1 * c[4], r1 * s[4], width * 0.5, normal); + v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); + + v = vert(v, r1 * c[4], r1 * s[4], -width * 0.5, normal); + } + + gear->count = (v - gear->vertices) / 6; + + gl->glGenBuffers(1, &gear->vbo); + gl->glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); + gl->glBufferData(GL_ARRAY_BUFFER, gear->count * 6 * 4, gear->vertices, GL_STATIC_DRAW); + + + return gear; +} + +static void free_gear(Gear *gear) +{ + free(gear->vertices); + free(gear); + gear = NULL; +} + +static void multiply(GLfloat *m, const GLfloat *n) +{ + GLfloat tmp[16]; + const GLfloat *row, *column; + div_t d; + int i, j; + + for (i = 0; i < 16; i++) + { + tmp[i] = 0; + d = div(i, 4); + row = n + d.quot * 4; + column = m + d.rem; + for (j = 0; j < 4; j++) + tmp[i] += row[j] * column[j * 4]; + } + memcpy(m, &tmp, sizeof tmp); +} + +static void rotate(GLfloat *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z) +{ + double s, c; + + s = sin(angle); + c = cos(angle); + GLfloat r[16] = + { + x * x * (1 - c) + c, y * x * (1 - c) + z * s, x * z * (1 - c) - y * s, 0, + x * y * (1 - c) - z * s, y * y * (1 - c) + c, y * z * (1 - c) + x * s, 0, + x * z * (1 - c) + y * s, y * z * (1 - c) - x * s, z * z * (1 - c) + c, 0, + 0, 0, 0, 1 + }; + + multiply(m, r); +} + +static void translate(GLfloat *m, GLfloat x, GLfloat y, GLfloat z) +{ + GLfloat t[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 }; + + multiply(m, t); +} + +static void draw_gear(GLData *gld, Gear *gear, GLfloat *m, GLfloat x, GLfloat y, GLfloat angle, const GLfloat *color) +{ + Evas_GL_API *gl = gld->glApi; + GLfloat tmp[16]; + + memcpy(tmp, m, sizeof tmp); + translate(tmp, x, y, 0); + rotate(tmp, 2 * M_PI * angle / 360.0, 0, 0, 1); + gl->glUniformMatrix4fv(gld->proj_location, 1, GL_FALSE, tmp); + gl->glUniform3fv(gld->light_location, 1, gld->light); + gl->glUniform4fv(gld->color_location, 1, color); + + gl->glBindBuffer(GL_ARRAY_BUFFER, gear->vbo); + + gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), NULL); + gl->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLfloat *) 0 + 3); + gl->glEnableVertexAttribArray(0); + gl->glEnableVertexAttribArray(1); + gl->glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->count); +} +#endif + + +static void gldata_init(GLData *gld) +{ + gld->useEGL = USE_EGL; + gld->useIrr = USE_IRR; + + gld->view_rotx = -20.0; + gld->view_roty = -30.0; + gld->view_rotz = 0.0; + gld->angle = 0.0; + + gld->light[0] = 1.0; + gld->light[1] = 1.0; + gld->light[2] = -5.0; +} + +//-------------------------// + + +#if DO_GEARS +static const char vertex_shader[] = + "uniform mat4 proj;\n" + "attribute vec4 position;\n" + "attribute vec4 normal;\n" + "varying vec3 rotated_normal;\n" + "varying vec3 rotated_position;\n" + "vec4 tmp;\n" + "void main()\n" + "{\n" + " gl_Position = proj * position;\n" + " rotated_position = gl_Position.xyz;\n" + " tmp = proj * normal;\n" + " rotated_normal = tmp.xyz;\n" + "}\n"; + + static const char fragment_shader[] = + "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "uniform vec4 color;\n" + "uniform vec3 light;\n" + "varying vec3 rotated_normal;\n" + "varying vec3 rotated_position;\n" + "vec3 light_direction;\n" + "vec4 white = vec4(0.5, 0.5, 0.5, 1.0);\n" + "void main()\n" + "{\n" + " light_direction = normalize(light - rotated_position);\n" + " gl_FragColor = color + white * dot(light_direction, rotated_normal);\n" + "}\n"; + +static GLuint load_shader(GLData *gld, GLenum type, const char *shader_src) +{ + Evas_GL_API *gl = gld->glApi; + GLuint shader; + GLint compiled = 0; + + // Create the shader object + if (!(shader = gl->glCreateShader(type))) return 0; + gl->glShaderSource(shader, 1, &shader_src, NULL); + // Compile the shader + gl->glCompileShader(shader); + gl->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + + if (!compiled) + { + GLint len = 0; + + gl->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); + if (len > 1) + { + char *info = malloc(sizeof(char) * len); + + if (info) + { + gl->glGetShaderInfoLog(shader, len, NULL, info); + printf("Error compiling shader:\n" + "%s\n", info); + free(info); + } + } + gl->glDeleteShader(shader); + return 0; + } + return shader; +} + +static void gears_init(GLData *gld) +{ + Evas_GL_API *gl = gld->glApi; + GLint linked = 0; + +// char msg[512]; + + gl->glEnable(GL_CULL_FACE); + gl->glEnable(GL_DEPTH_TEST); + gl->glEnable(GL_BLEND); + + // Load the vertex/fragment shaders + gld->vtx_shader = load_shader(gld, GL_VERTEX_SHADER, vertex_shader); + gld->fgmt_shader = load_shader(gld, GL_FRAGMENT_SHADER, fragment_shader); + + // Create the program object + if (!(gld->program = gl->glCreateProgram())) + return; + + gl->glAttachShader(gld->program, gld->vtx_shader); + gl->glAttachShader(gld->program, gld->fgmt_shader); + + // Bind shader attributes. + gl->glBindAttribLocation(gld->program, 0, "position"); + gl->glBindAttribLocation(gld->program, 1, "normal"); + + // Link the program + gl->glLinkProgram(gld->program); + gld->glApi->glGetProgramiv(gld->program, GL_LINK_STATUS, &linked); + + if (!linked) + { + GLint len = 0; + + gld->glApi->glGetProgramiv(gld->program, GL_INFO_LOG_LENGTH, &len); + if (len > 1) + { + char *info = malloc(sizeof(char) * len); + + if (info) + { + gld->glApi->glGetProgramInfoLog(gld->program, len, NULL, info); + printf("Error linking program:\n%s\n", info); + free(info); + } + } + gld->glApi->glDeleteProgram(gld->program); + } + + gl->glUseProgram(gld->program); + gld->proj_location = gl->glGetUniformLocation(gld->program, "proj"); + gld->light_location = gl->glGetUniformLocation(gld->program, "light"); + gld->color_location = gl->glGetUniformLocation(gld->program, "color"); + + /* make the gears */ + gld->gear1 = make_gear(gld, 1.0, 4.0, 1.0, 20, 0.7); + gld->gear2 = make_gear(gld, 0.5, 2.0, 2.0, 10, 0.7); + gld->gear3 = make_gear(gld, 1.3, 2.0, 0.5, 10, 0.7); + + gld->gearsInited = EINA_TRUE; +} +#endif + +static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Key_Down *ev = event_info; + + if (gld->move) + { + // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't know at what point the camera animate routine is actually called. + + // Yes, we are dealing with the horrid Evas keyboard handling FUCKING STRING COMPARES! Soooo ... + // TODO - make this a hash lookup dammit. + if (0 == strcmp(ev->key, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->r = 2.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->r = -2.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 2.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = -2.0; +// else if (0 == strcmp(ev->key, "Prior")) +// ; +// else if (0 == strcmp(ev->key, "Next")) +// ; +// else if (0 == strcmp(ev->key, "Home")) +// ; +// else if (0 == strcmp(ev->key, "End")) +// ; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 1.0; + else + printf("Unexpected down keystroke - %s\n", ev->key); + } + else + printf("Camera input not ready\n"); +} + +/* SL / OS camera controls + up / down / w / s moves avatar forward / backward + shifted version does the same + double tap triggers run mode / or fast fly mode + Running backwards turns your avatar to suit, walking does not. + left / right / a / d rotates avatar left / right, strafes in mouselook + shifted version turns the avatar to walk sideways, so not really a strafe. + So not sure if the "strafe" in mouse look turns the avatar as well? + PgDn / c crouch while it is held down move up in flight mode + PgUp jump move down in flight mode + Home toggle flying + End Nothing? + Esc return to third person view + m toggle mouse look + mouse wheel move view closer / further away from current focused object or avatar + Alt left click focus on some other object + Ins ??? + Del ??? + BS ??? + Tab ??? + + Mouse look is just first person view, moving mouse looks left / right / up / down. + Not sure if the avatar rotates with left / right, but that's likely. + + mouse moves With the left mouse button held down - + left / right up / down + --------------------------------- + for avatar swings avatar around zoom in and out of avatar + for object nothing + alt orbit left / right zoom in and out + alt ctrl orbit left / right orbit up / down + alt shift orbit left / right zoom in and out + alt ctrl shift shift view left / right / up / down + ctrl Nothing? + shift Nothing? + ctrl shift Nothing? + + Need to also consider when looking at a moving object / avatar. + + I think there are other letter keys that duplicate arrow keys and such. I'll look for them later, but I don't use them. + No idea what the function keys are mapped to, but think it's various non camera stuff. + I'm damn well leaving the Win/Command and Menu keys for the OS / window manager. lol + Keypad keys? Not interested, I don't have them. + Print Screen / SysRq, Pause / Break, other oddball keys, also not interested. + NOTE - gonna have an easily programmable "bind key to command" thingy, like E17s, so that can deal with other keys. + Should even let them be saveable so people can swap them with other people easily. + + TODO - implement things like space mouse, sixaxis, phone as controller, joysticks, data gloves, etc. +*/ + +/* A moveRotate array of floats. + * X, Y, Z, and whatever the usual letters are for rotations. lol + * Each one means "move or rotate this much in this direction". + * Where 1.0 means "what ever the standard move is if that key is held down". + * So a keyboard move would just change it's part to 1.0 or -1.0 on key down, + * and back to 0.0 on key up. Or 2.0 / -2.0 if in run mode. + * Which would even work in fly mode. + * A joystick could be set to range over -2.0 to 2.0, and just set it's part directly. + * A mouse look rotate, well will come to that when we need to. B-) + * Setting the x or y to be the DIFFERENCE in window position of the mouse (-1.0 to 1.0) since the last frame. + * + * TODO - In the Elm_glview version, 2.0 seems to be correct speed for walking, but I thought 1.0 was in Evas_GL. + */ + +static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Key_Up *ev = event_info; + + if (gld->move) + { + // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't know at what point the camera animate routine is actually called. + + // Yes, we are dealing with the horrid Evas keyboard handling FUCKING STRING COMPARES! Soooo ... + // TODO - make this a hash lookup dammit. + if (0 == strcmp(ev->key, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->r = 0.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->r = 0.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = 0.0; +// else if (0 == strcmp(ev->key, "Prior")) +// ; +// else if (0 == strcmp(ev->key, "Next")) +// ; +// else if (0 == strcmp(ev->key, "Home")) +// ; +// else if (0 == strcmp(ev->key, "End")) +// ; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 0.0; + else + printf("Unexpected up keystroke - %s\n", ev->key); + } + else + printf("Camera input not ready\n"); +} + +// Elm style event callback. +static Eina_Bool _cb_event_GL(void *data, Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info) +{ + GLData *gld = data; + Eina_Bool processed = EINA_FALSE; + + switch (type) + { + case EVAS_CALLBACK_KEY_DOWN : + { + _on_camera_input_down(gld, evas_object_evas_get(obj), obj, event_info); + processed = EINA_TRUE; + break; + } + + case EVAS_CALLBACK_KEY_UP : + { + _on_camera_input_up(gld, evas_object_evas_get(obj), obj, event_info); + processed = EINA_TRUE; + break; + } + + default : + printf("Unknown GL input event.\n"); + } + + return processed; +} + +// Elm inlined image windows needs this to change focus on mouse click. +// Evas style event callback. +static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ +// GLData *gld = data; + Evas_Event_Mouse_Down *ev = event_info; + + if (1 == ev->button) + elm_object_focus_set(obj, EINA_TRUE); +} + +static void _resize_winwin(GLData *gld) +{ + Evas_Coord x, y, w, h; + + evas_object_geometry_get(gld->elmGl, &x, &y, &w, &h); + evas_object_move(elm_win_inlined_image_object_get (gld->winwin), x, y); + evas_object_resize(elm_win_inlined_image_object_get(gld->winwin), w, h); +} + +// Called from on_pixels (), or the Elm_gliew resize callback. +static void _resize(GLData *gld) +{ + Evas_GL_API *gl = gld->glApi; + + _resize_winwin(gld); + +#if DO_GEARS + GLfloat ar, m[16] = { + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 0.1, 0.0, + 0.0, 0.0, 0.0, 1.0 + }; + + // GL Viewport stuff. you can avoid doing this if viewport is all the + // same as last frame if you want + if (gld->img_w < gld->img_h) + ar = gld->img_w; + else + ar = gld->img_h; + + m[0] = 0.1 * ar / gld->img_w; + m[5] = 0.1 * ar / gld->img_h; + memcpy(gld->proj, m, sizeof gld->proj); +#endif + + gl->glViewport(0, 0, (GLint) gld->img_w, (GLint) gld->img_h); +} + +static void _resize_gl(Evas_Object *obj) +{ + int w, h; + GLData *gld = evas_object_data_get(obj, "gld"); + + elm_glview_size_get(obj, &w, &h); + + gld->img_w = w; + gld->img_h = h; + _resize(gld); +} + +static void on_pixels(void *data, Evas_Object *obj) +{ + GLData *gld = data; + Evas_GL_API *gl = gld->glApi; + + // get the image size in case it changed with evas_object_image_size_set() + if (gld->r1) + { + Evas_Coord w, h; + + // Poor mans resize check. coz Elm wont do it easily. + evas_object_image_size_get(gld->r1, &w, &h); + if ((gld->img_w != w) || (gld->img_h != h)) + { + // No idea where this crap came from. + //float new_w = ((float) gld->scr_w / ((float) gld->scr_w * (float) w)); + //float new_h = ((float) gld->scr_h / ((float) gld->scr_h * (float) h)); + + //gld->sfc_w = new_w; + //gld->sfc_h = new_h; + //evas_object_image_fill_set(gld->r1, 0, 0, gld->sfc_w, gld->sfc_h); + gld->img_w = w; + gld->img_h = h; + gld->resized = 1; + } + } + + if (gld->useEGL) + { + // Yes, we DO need to do our own make current, coz aparently the Irrlicht one is useless. + // Hopefully Elm_GL has done this for us by now. + // Evas_GL needs it to. + if (gld->ctx) + evas_gl_make_current(gld->evasGl, gld->sfc, gld->ctx); + } + + if (!gld->doneIrr) + gld->doneIrr = startIrr(gld); // Needs to be after gld->win is shown, and needs to be done in the render thread. +#if DO_GEARS + if (!gld->gearsInited) + gears_init(gld); +#endif + + if (gld->resized) + _resize(gld); + + drawIrr_start(gld); + +#if DO_GEARS + if (gld->useEGL) + { + static const GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 }; + static const GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 }; + static const GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 }; + GLfloat m[16]; + + // Draw the gears. + if (!gld->useIrr) + { + gl->glClearColor(0.7, 0.0, 1.0, 1.0); + gl->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + memcpy(m, gld->proj, sizeof m); + rotate(m, 2 * M_PI * gld->view_rotx / 360.0, 1, 0, 0); + rotate(m, 2 * M_PI * gld->view_roty / 360.0, 0, 1, 0); + rotate(m, 2 * M_PI * gld->view_rotz / 360.0, 0, 0, 1); + + draw_gear(gld, gld->gear1, m, -3.0, -2.0, gld->angle, red); + draw_gear(gld, gld->gear2, m, 3.1, -2.0, -2 * gld->angle - 9.0, green); + draw_gear(gld, gld->gear3, m, -3.1, 4.2, -2 * gld->angle - 25.0, blue); + gld->angle += 2.0; + } +#endif + + drawIrr_end(gld); + +#if USE_IR +#else + // This might get done deep within drawIrr_end, but only if we are using Irrlicht. + + // Optional - Flush the GL pipeline + gl->glFlush(); +// gl->glFinish(); +#endif + + gld->resized = 0; +} + +static void _draw_gl(Evas_Object *obj) +{ +// Evas_GL_API *gl = elm_glview_gl_api_get(obj); + GLData *gld = evas_object_data_get(obj, "gld"); + if (!gld) return; + + on_pixels(gld, obj); +} + +// Callback from Evas, also used as the general callback for deleting the GL stuff. +static void _clean_gl(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + GLData *gld = data; + Evas_GL_API *gl = gld->glApi; + + ecore_animator_del(gld->animator); + + if (gld->useEGL) + { + // Do a make_current before deleting all the GL stuff. + evas_gl_make_current(gld->evasGl, gld->sfc, gld->ctx); + + } + + gl->glDeleteShader(gld->vtx_shader); + gl->glDeleteShader(gld->fgmt_shader); + gl->glDeleteProgram(gld->program); + + if (gld->evasGl) + { + // Irrlicht wants to destroy the context and surface, so only do this if Irrlicht wont. + if (!gld->doneIrr) + { + evas_gl_surface_destroy(gld->evasGl, gld->sfc); + evas_gl_context_destroy(gld->evasGl, gld->ctx); + } + // TODO - hope this is OK, considering the context and surface might get dealt with by Irrlicht. + // Might be better to teach Irrlicht to not destroy shit it did not create. + evas_gl_config_free(gld->cfg); + evas_gl_free(gld->evasGl); + } + + // TODO - Since this is created on the render thread, better hope this is being deleted on the render thread. + finishIrr(gld); + +#if DO_GEARS + gl->glDeleteBuffers(1, &gld->gear1->vbo); + gl->glDeleteBuffers(1, &gld->gear2->vbo); + gl->glDeleteBuffers(1, &gld->gear3->vbo); + + free_gear(gld->gear1); + free_gear(gld->gear2); + free_gear(gld->gear3); +#endif +} + +// Callback from Elm, coz they do shit different. +static void _del_gl(Evas_Object *obj) +{ + GLData *gld = evas_object_data_get(obj, "gld"); + if (!gld) + { + printf("Unable to get GLData. \n"); + return; + } + + _clean_gl(gld, NULL, NULL, NULL); + + evas_object_data_del((Evas_Object*)obj, "gld"); +} + +// Callback for when the app quits. +static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + GLData *gld = data; + + evas_object_del(gld->win); + free(gld); + elm_exit(); +} + +// Callback from the animator. +static Eina_Bool doFrame(void *data) +{ + GLData *gld = data; + + // Mark the pixels as dirty, so they get rerendered each frame, then Irrlicht can draw it's stuff each frame. + // This causes on_pixel to be triggered by Evas_GL, and _draw_gl for Elm_glview. + if (gld->r1) + evas_object_image_pixels_dirty_set(gld->r1, EINA_TRUE); + if (gld->elmGl) + elm_glview_changed_set(gld->elmGl); + + // If not using Evas_GL, we need to call on_pixel() manually. + if (!gld->useEGL) + on_pixels(gld, gld->r1); + + return EINA_TRUE; // Keep calling us. +} + +static void init_evas_gl(GLData *gld) +{ + if (!gld->useEGL) + return; + + gld->sfc_w = gld->win_w; + gld->sfc_h = gld->win_h; + + // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas. + gld->canvas = evas_object_evas_get(gld->win); + // An Ecore_Evas holds an Evas. + // Get the Ecore_Evas that wraps an Evas. + gld->ee = ecore_evas_ecore_evas_get(gld->canvas); // Only use this on Evas that was created with Ecore_Evas. + +#if USE_ELM_GL + // Add a GLView + gld->elmGl = elm_glview_add(gld->win); + evas_object_size_hint_align_set(gld->elmGl, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(gld->elmGl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_glview_mode_set(gld->elmGl, 0 | ELM_GLVIEW_ALPHA | ELM_GLVIEW_DEPTH | ELM_GLVIEW_DIRECT); + elm_glview_resize_policy_set(gld->elmGl, ELM_GLVIEW_RESIZE_POLICY_RECREATE); // Destroy the current surface on a resize and create a new one. + elm_glview_render_policy_set(gld->elmGl, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND); +// elm_glview_render_policy_set(gld->elmGl, ELM_GLVIEW_RENDER_POLICY_ALWAYS); + // These get called in the render thread I think. + // None let me pass data, so this is why we are adding "gld" data to the object below. + // Maybe we can use elm_object_signal_callback_add or elm_object_item_signal_callback_add (edje signals)? + //elm_glview_init_func_set(gld->elmGl, _init_gl); // Not actually needed, it gets done in on_pixels. + elm_glview_del_func_set(gld->elmGl, _del_gl); + elm_glview_resize_func_set(gld->elmGl, _resize_gl); + elm_glview_render_func_set(gld->elmGl, (Elm_GLView_Func_Cb) _draw_gl); + + // Not needed, the resize callback above deals with that. + //elm_win_resize_object_add(gld->win, gld->elmGl); + gld->glApi = elm_glview_gl_api_get(gld->elmGl); + evas_object_data_set(gld->elmGl, "gld", gld); + evas_object_show(gld->elmGl); + elm_box_pack_end(gld->bx, gld->elmGl); +#else + // get the evas gl handle for doing gl things + gld->evasGl = evas_gl_new(gld->canvas); + gld->glApi = evas_gl_api_get(gld->evasGl); + + // Set a surface config + gld->cfg = evas_gl_config_new(); + gld->cfg->color_format = EVAS_GL_RGBA_8888; + gld->cfg->depth_bits = EVAS_GL_DEPTH_BIT_32; + gld->cfg->stencil_bits = EVAS_GL_STENCIL_NONE; + gld->cfg->options_bits = EVAS_GL_OPTIONS_DIRECT; + + // create a surface and context + gld->sfc = evas_gl_surface_create(gld->evasGl, gld->cfg, gld->sfc_w, gld->sfc_h); + gld->ctx = evas_gl_context_create(gld->evasGl, NULL); // The second NULL is for sharing contexts I think, which might be what we want to do with Irrlicht. It's not documented. + + // Set up the image object, a filled one by default. + gld->r1 = evas_object_image_filled_add(gld->canvas); + + // attach important data we need to the object using key names. This just + // avoids some global variables and means we can do nice cleanup. You can + // avoid this if you are lazy + // Not actually needed, with evas we can pass data pointers to stuff. + //evas_object_data_set(gld->r1, "gld", gld); + + // when the object is deleted - call the on_del callback. like the above, + // this is just being clean + evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_DEL, _clean_gl, gld); + + // set up an actual pixel size for the buffer data. it may be different + // to the output size. any windowing system has something like this, just + // evas has 2 sizes, a pixel size and the output object size + evas_object_image_size_set(gld->r1, gld->sfc_w, gld->sfc_h); + // Not actualy needed, as we create the image already filled. + //evas_object_image_fill_set(gld->r1, 0, 0, gld->sfc_w, gld->sfc_h); + + // These two are not in the original example, but I get black r1 when I leave them out. + evas_object_size_hint_align_set(gld->r1, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(gld->r1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + + // set up the native surface info to use the context and surface created + // above + evas_gl_native_surface_get(gld->evasGl, gld->sfc, &(gld->ns)); + evas_object_image_native_surface_set(gld->r1, &(gld->ns)); + evas_object_image_pixels_get_callback_set(gld->r1, on_pixels, gld); + + // move the image object somewhere, resize it and show it. any windowing + // system would need this kind of thing - place a child "window" + // Hmm, no need to resize it anyway, it's sized above. + evas_object_move(gld->r1, 0, 0); + //evas_object_resize(gld->r1, gld->sfc_w, gld->sfc_h); + elm_win_resize_object_add(gld->win, gld->r1); + evas_object_show(gld->r1); + elm_box_pack_end(gld->bx, gld->r1); + + evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld); +// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, gld); +// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, gld); +#endif + + // NOTE: if you delete r1, this animator will keep running trying to access + // r1 so you'd better delete this animator with ecore_animator_del() or + // structure how you do animation differently. you can also attach it like + // evasGl, sfc, etc. etc. if this animator is specific to this object + // only and delete it in the del handler for the obj. + // + // TODO - apparently the proper way to deal with the new async rendering is to have this animator do the dirty thing, and call the Irrlicht rendering stuff in the on_pixel call set above. + // That still leaves the problem of the Irrlicht setup being in the main thread. Which also should be done in on_pixel, as that's done in the correct thread. + + // Jiggling this seems to produce a trade off between flickering and frame rate. Nothing else changed the flickering. + ecore_animator_frametime_set(0.04); // Default is 1/30, or 0.033333 + gld->animator = ecore_animator_add(doFrame, gld); // This animator will be called every frame tick, which defaults to 1/30 seconds. + + return; +} + + +//-------------------------// + + +static Evas_Object *_content_image_new(Evas_Object *parent, const char *img) +{ + Evas_Object *ic; + + ic = elm_icon_add(parent); + elm_image_file_set(ic, img, NULL); + return ic; +} + +static void _promote(void *data, Evas_Object *obj , void *event_info ) +{ + elm_naviframe_item_promote(data); +} + +static char *_grid_label_get(void *data, Evas_Object *obj, const char *part) +{ + ezGrid *thisGrid = data; + char buf[256]; + + if (!strcmp(part, "elm.text")) + { + int count = eina_clist_count(&(thisGrid->accounts)); + + if (0 == count) + snprintf(buf, sizeof(buf), "%s (no accounts)", thisGrid->name); + else if (1 == count) + snprintf(buf, sizeof(buf), "%s (%d account)", thisGrid->name, count); + else + snprintf(buf, sizeof(buf), "%s (%d accounts)", thisGrid->name, count); + } + else + snprintf(buf, sizeof(buf), "%s", thisGrid->loginURI); + return strdup(buf); +} + +static Evas_Object *_grid_content_get(void *data, Evas_Object *obj, const char *part) +{ + ezGrid *thisGrid = data; + Evas_Object *ic = elm_icon_add(obj); + + if (!strcmp(part, "elm.swallow.icon")) + elm_icon_standard_set(ic, thisGrid->icon); + + evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + return ic; +} + +static char * _account_label_get(void *data, Evas_Object *obj, const char *part) +{ + ezAccount *thisAccount = data; + char buf[256]; + + buf[0] = '\0'; + if (!strcmp(part, "elm.text")) + snprintf(buf, sizeof(buf), "%s", thisAccount->name); + + return strdup(buf); +} + +static Evas_Object *_account_content_get(void *data, Evas_Object *obj, const char *part) +{ + ezAccount *thisAccount = data; + Evas_Object *ic = elm_icon_add(obj); + + if (!strcmp(part, "elm.swallow.icon")) + elm_icon_standard_set(ic, thisAccount->icon); + + evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + return ic; +} + +static char *_viewer_label_get(void *data, Evas_Object *obj, const char *part) +{ + ezViewer *thisViewer = data; + char buf[256]; + + if (!strcmp(part, "elm.text")) + snprintf(buf, sizeof(buf), "%s", thisViewer->name); + else + snprintf(buf, sizeof(buf), "%s", thisViewer->version); + return strdup(buf); +} + +static Evas_Object *_viewer_content_get(void *data, Evas_Object *obj, const char *part) +{ + ezViewer *thisViewer = data; + Evas_Object *ic = elm_icon_add(obj); + + if (!strcmp(part, "elm.swallow.icon")) + elm_icon_standard_set(ic, thisViewer->icon); + + evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); + return ic; +} + + +static void _grid_sel_cb(void *data, Evas_Object *obj, void *event_info) +{ + ezGrid *thisGrid = data; + GLData *gld = thisGrid->gld; + char buf[PATH_MAX]; + +// sprintf(buf, "dillo -f -g '%dx%d+%d+%d' %s &", gld->win_w - (gld->win_w / 5), gld->win_h - 30, gld->win_w / 5, gld->win_y, thisGrid->splashPage); + sprintf(buf, "uzbl -g '%dx%d+%d+%d' -u %s &", gld->win_w - (gld->win_w / 5), gld->win_h - 30, gld->win_w / 5, gld->win_y, thisGrid->splashPage); + printf("%s ### genlist obj [%p], item pointer [%p]\n", buf, obj, event_info); +// comment this out for now, busy dealing with input stuff, don't want to trigger this multiple times. +// system(buf); +} + +static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + Evas_Event_Mouse_Move *ev = event_info; + Evas_Object *orig = data; + Evas_Coord x, y; + Evas_Map *p; + int i, w, h; + + if (!ev->buttons) return; + evas_object_geometry_get(obj, &x, &y, NULL, NULL); + evas_object_move(obj, + x + (ev->cur.canvas.x - ev->prev.output.x), + y + (ev->cur.canvas.y - ev->prev.output.y)); + evas_object_image_size_get(orig, &w, &h); + p = evas_map_new(4); + evas_object_map_enable_set(orig, EINA_TRUE); +// evas_object_raise(orig); + for (i = 0; i < 4; i++) + { + Evas_Object *hand; + char key[32]; + + snprintf(key, sizeof(key), "h-%i\n", i); + hand = evas_object_data_get(orig, key); + evas_object_raise(hand); + evas_object_geometry_get(hand, &x, &y, NULL, NULL); + x += 15; + y += 15; + evas_map_point_coord_set(p, i, x, y, 0); + if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0); + else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0); + else if (i == 2) evas_map_point_image_uv_set(p, i, w, h); + else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h); + } + evas_object_map_set(orig, p); + evas_map_free(p); +} + +static void create_handles(Evas_Object *obj) +{ + int i; + Evas_Coord x, y, w, h; + + evas_object_geometry_get(obj, &x, &y, &w, &h); + for (i = 0; i < 4; i++) + { + Evas_Object *hand; + char buf[PATH_MAX]; + char key[32]; + + hand = evas_object_image_filled_add(evas_object_evas_get(obj)); + evas_object_resize(hand, 31, 31); + snprintf(buf, sizeof(buf), "%s/media/pt.png", elm_app_data_dir_get()); + evas_object_image_file_set(hand, buf, NULL); + if (i == 0) evas_object_move(hand, x - 15, y - 15); + else if (i == 1) evas_object_move(hand, x + w - 15, y - 15); + else if (i == 2) evas_object_move(hand, x + w - 15, y + h - 15); + else if (i == 3) evas_object_move(hand, x - 15, y + h - 15); + evas_object_event_callback_add(hand, EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj); + evas_object_show(hand); + snprintf(key, sizeof(key), "h-%i\n", i); + evas_object_data_set(obj, key, hand); + } +} + +static Evas_Object *_toolbar_menu_add(Evas_Object *win, Evas_Object *tb, char *label) +{ + Evas_Object *menu= NULL; + Elm_Object_Item *tb_it; +//, *menu_it; + + tb_it = elm_toolbar_item_append(tb, NULL, label, NULL, NULL); + elm_toolbar_item_menu_set(tb_it, EINA_TRUE); + // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. + elm_toolbar_item_priority_set(tb_it, 9999); + elm_toolbar_menu_parent_set(tb, win); + menu = elm_toolbar_item_menu_get(tb_it); + + return menu; +} + +static Evas_Object *fang_win_add(GLData *gld) +{ + Evas_Object *win, *bg; + + // In theory this should create an EWS window, in practice, I'm not seeing any difference. + // Guess I'll have to implement my own internal window manager. I don't think a basic one will be that hard. Famous last words. +// elm_config_engine_set("ews"); + win = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); + // On mouse down we try to shift focus to the backing image, this seems to be the correct thing to force focus onto it's widgets. + // According to the Elm inlined image window example, this is what's needed to. + evas_object_event_callback_add(elm_win_inlined_image_object_get(win), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, gld); + elm_win_alpha_set(win, EINA_TRUE); + + // Apparently transparent is not good enough for ELM backgrounds, so make it a rectangle. + // Apparently coz ELM prefers stuff to have edjes. A bit over the top if all I want is a transparent rectangle. + bg = evas_object_rectangle_add(evas_object_evas_get(win)); + evas_object_color_set(bg, 50, 0, 100, 100); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bg); + evas_object_show(bg); + + return win; +} + +static void fang_win_complete(GLData *gld, Evas_Object *win, int x, int y, int w, int h) +{ + // image object for win is unlinked to its pos/size - so manual control + // this allows also for using map and other things with it. + evas_object_move(elm_win_inlined_image_object_get(win), x, y); + // Odd, it needs to be resized twice. WTF? + evas_object_resize(win, w, h); + evas_object_resize(elm_win_inlined_image_object_get(win), w, h); + evas_object_show(win); + create_handles(elm_win_inlined_image_object_get(win)); +} + +static void overlay_add(GLData *gld) +{ + Evas_Object *bg; +//, *bx, *tb, *menu; +// Elm_Object_Item *tb_it, *menu_it; + + // There many are reasons for this window. + // The first is to cover the GL and provide something to click on to change focus. + // The second is to provide something to click on for all the GL type clicking stuff that needs to be done. In other words, no click through,we catch the clicks here. + // So we can probably avoid the following issue - + // How to do click through? evas_object_pass_events_set(rectangle, EINA_TRUE), and maybe need to do that to the underlaying window to? + // Though if the rectangle is entirely transparent, or even hidden, events might pass through anyway. + // Gotta have click through on the parts where there's no other window. + // The third is to have the other windows live here. + // This idea doesn't work, as it breaks the damn focus again. + // Don't think it's needed anyway. + // While on the subject of layers, need a HUD layer of some sort, but Irrlicht might support that itself. + + gld->winwin = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); + // On mouse down we try to shift focus to the backing image, this seems to be the correct thing to force focus onto it's widgets. + // According to the Elm inlined image window example, this is what's needed to. + evas_object_event_callback_add(elm_win_inlined_image_object_get(gld->winwin), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, gld); + // In this code, we are making our own camera, so grab it's input when we are focused. + evas_object_event_callback_add(gld->winwin, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, gld); + evas_object_event_callback_add(gld->winwin, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, gld); + elm_object_event_callback_add(gld->winwin, _cb_event_GL, gld); + + elm_win_alpha_set(gld->winwin, EINA_TRUE); + // Apparently transparent is not good enough for ELM backgrounds, so make it a rectangle. + // Apparently coz ELM prefers stuff to have edjes. A bit over the top if all I want is a transparent rectangle. + bg = evas_object_rectangle_add(evas_object_evas_get(gld->winwin)); + evas_object_color_set(bg, 0, 0, 0, 0); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(gld->winwin, bg); + evas_object_show(bg); + + // image object for win is unlinked to its pos/size - so manual control + // this allows also for using map and other things with it. + evas_object_move(elm_win_inlined_image_object_get(gld->winwin), 0, 0); + // Odd, it needs to be resized twice. WTF? + evas_object_resize(gld->winwin, gld->win_w, gld->win_h); + evas_object_resize(elm_win_inlined_image_object_get(gld->winwin), gld->win_w, gld->win_h); + evas_object_show(gld->winwin); +} + +static void chat_add(GLData *gld) +{ + Evas_Object *win, *bx, *en; + + win = fang_win_add(gld); + + bx = elm_box_add(win); + elm_win_resize_object_add(win, bx); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL); + + en = elm_entry_add(win); + elm_entry_scrollable_set(en, EINA_TRUE); + evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_text_set(en, "History is shown here"); + elm_entry_editable_set(en, EINA_FALSE); + evas_object_show(en); + elm_box_pack_end(bx, en); + + en = elm_entry_add(win); + elm_entry_scrollable_set(en, EINA_TRUE); + evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_text_set(en, ""); + elm_entry_editable_set(en, EINA_TRUE); + evas_object_show(en); + elm_box_pack_end(bx, en); + + evas_object_show(bx); + + fang_win_complete(gld, win, 30, 500, gld->win_w / 3, gld->win_h / 3); +} + + +static void woMan_add(GLData *gld) +{ +// Evas_Object *win, *bg, *bx, *ic, *bb, *av, *en, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; + Evas_Object *win, *bx, *bt, *nf, *tab, *tb, *gridList, *viewerList, *menu; + Elm_Object_Item *tb_it, *menu_it, *tab_it; +// char buf[PATH_MAX]; + int i; + + win = fang_win_add(gld); + + bx = elm_box_add(win); + elm_win_resize_object_add(win, bx); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL); + + // A tab thingy. + tb = elm_toolbar_add(win); + evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); + + // Menu. + tb_it = elm_toolbar_item_append(tb, NULL, "Menu", NULL, NULL); + elm_toolbar_item_menu_set(tb_it, EINA_TRUE); + // Priority is for when toolbar items are set to hide or menu when there are too many of them. They get hidden or put on the menu based on priority. + elm_toolbar_item_priority_set(tb_it, 9999); + elm_toolbar_menu_parent_set(tb, win); + menu = elm_toolbar_item_menu_get(tb_it); + + menu_it = elm_menu_item_add(menu, NULL, NULL, "edit", NULL, NULL); + elm_menu_item_add(menu, menu_it, NULL, "preferences", NULL, NULL); + menu_it = elm_menu_item_add(menu, NULL, NULL, "help", NULL, NULL); + elm_menu_item_add(menu, menu_it, NULL, "about woMan", NULL, NULL); + elm_menu_item_separator_add(menu, NULL); + menu_it = elm_menu_item_add(menu, NULL, NULL, "advanced", NULL, NULL); + elm_menu_item_add(menu, menu_it, NULL, "debug settings", NULL, NULL); + + // The toolbar needs to be packed into the box AFTER the menus are added. + elm_box_pack_end(bx, tb); + evas_object_show(tb); + + gridList = elm_genlist_add(win); + grids = eina_hash_stringshared_new(free); + + grid_gic = elm_genlist_item_class_new(); + grid_gic->item_style = "double_label"; + grid_gic->func.text_get = _grid_label_get; + grid_gic->func.content_get = _grid_content_get; + grid_gic->func.state_get = NULL; + grid_gic->func.del = NULL; + for (i = 0; NULL != gridTest[i][0]; i++) + { + ezGrid *thisGrid = calloc(1, sizeof(ezGrid)); + + if (thisGrid) + { + eina_clist_init(&(thisGrid->accounts)); + eina_clist_init(&(thisGrid->landmarks)); + thisGrid->name = gridTest[i][0]; + thisGrid->loginURI = gridTest[i][1]; + thisGrid->splashPage = gridTest[i][2]; + thisGrid->icon = "folder"; + thisGrid->gld = gld; + thisGrid->item = elm_genlist_item_append(gridList, grid_gic, thisGrid, NULL, ELM_GENLIST_ITEM_TREE, _grid_sel_cb, thisGrid); + eina_hash_add(grids, thisGrid->name, thisGrid); + } + } + + account_gic = elm_genlist_item_class_new(); + account_gic->item_style = "default"; + account_gic->func.text_get = _account_label_get; + account_gic->func.content_get = _account_content_get; + account_gic->func.state_get = NULL; + account_gic->func.del = NULL; + for (i = 0; NULL != accountTest[i][0]; i++) + { + ezAccount *thisAccount = calloc(1, sizeof(ezAccount)); + ezGrid *grid = eina_hash_find(grids, accountTest[i][0]); + + if (thisAccount && grid) + { + thisAccount->name = accountTest[i][1]; + thisAccount->password = accountTest[i][2]; + thisAccount->icon = "file"; + elm_genlist_item_append(gridList, account_gic, thisAccount, grid->item, ELM_GENLIST_ITEM_NONE, NULL, NULL); + eina_clist_add_tail(&(grid->accounts), &(thisAccount->grid)); + } + } + + // Viewers stuff + viewerList = elm_genlist_add(win); + viewer_gic = elm_genlist_item_class_new(); + viewer_gic->item_style = "double_label"; + viewer_gic->func.text_get = _viewer_label_get; + viewer_gic->func.content_get = _viewer_content_get; + viewer_gic->func.state_get = NULL; + viewer_gic->func.del = NULL; + for (i = 0; NULL != viewerTest[i][0]; i++) + { + ezViewer *thisViewer = calloc(1, sizeof(ezViewer)); + + if (thisViewer) + { + thisViewer->name = viewerTest[i][0]; + thisViewer->version = viewerTest[i][1]; + thisViewer->path = viewerTest[i][2]; + thisViewer->icon = "file"; + thisViewer->item = elm_genlist_item_append(viewerList, viewer_gic, thisViewer, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + } + } + + // Toolbar pages + nf = elm_naviframe_add(win); + evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(nf); + + tab = viewerList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Viewers", _promote, tab_it); + tab = _content_image_new(win, img3); tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Landmarks", _promote, tab_it); + tab = gridList; tab_it = elm_naviframe_item_push(nf, NULL, NULL, NULL, tab, NULL); elm_naviframe_item_title_enabled_set(tab_it, EINA_FALSE, EINA_TRUE); elm_toolbar_item_append(tb, NULL, "Grids", _promote, tab_it); + elm_box_pack_end(bx, nf); + +#if USE_EO + // Not ready for prime time yet, or I'm missing a step. Causes it to hang after closing the window. + // Slightly better now, it bitches instead of hanging. + bt = eo_add(ELM_OBJ_BUTTON_CLASS, win); + elm_object_text_set(bt, "Login"); // No eo interface for this that I can find. + eo_do(bt, +// evas_obj_text_set("Login"), + evas_obj_size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL), + evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0.0), + evas_obj_visibility_set(EINA_TRUE) + ); +#else + bt = elm_button_add(win); + elm_object_text_set(bt, "Login"); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0); + evas_object_show(bt); +#endif +// evas_object_smart_callback_add(bt, "clicked", NULL, NULL); + elm_box_pack_end(bx, bt); + evas_object_show(bx); + + fang_win_complete(gld, win, 30, 30, gld->win_w / 3, gld->win_h / 3); +} + +EAPI_MAIN int elm_main(int argc, char **argv) +{ +// Evas_Object *bg, *menu, *bt, *tb; + Evas_Object *menu, *tb; + Elm_Object_Item *tb_it; +//, *menu_it; + EPhysics_Body *boundary; + EPhysics_World *world; + EPhysics_Body *box_body1, *box_body2; + Evas_Object *box1, *box2; + GLData *gld = NULL; +// char buf[PATH_MAX]; +// int i; +// Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. + + _log_domain = eina_log_domain_register("extantz", NULL); + // Don't do this, we need to clean up other stuff to, so set a clean up function below. + //elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + + // If you want efl to handle finding your bin/lib/data dirs, you must do this below. + elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR); + elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); + elm_app_info_set(elm_main, "datadir", "media/sky_03.jpg"); + fprintf(stdout, "prefix was set to: %s\n", elm_app_prefix_dir_get()); + fprintf(stdout, "data directory is: %s\n", elm_app_data_dir_get()); + fprintf(stdout, "library directory is: %s\n", elm_app_lib_dir_get()); + fprintf(stdout, "locale directory is: %s\n", elm_app_locale_dir_get()); + + // These are set via the elementary_config tool, which is hard to find. + elm_config_finger_size_set(0); + elm_config_scale_set(1.0); + + // alloc a data struct to hold our relevant gl info in + if (!(gld = calloc(1, sizeof(GLData)))) return 1; + gldata_init(gld); + + // Set the engine to opengl_x11, then open our window. + if (gld->useEGL) + elm_config_preferred_engine_set("opengl_x11"); + gld->win = elm_win_add(NULL, "extantz", ELM_WIN_BASIC); + // Set preferred engine back to default from config + elm_config_preferred_engine_set(NULL); + +#if USE_PHYSICS + if (!ephysics_init()) + return 1; +#endif + + elm_win_title_set(gld->win, "extantz virtual world manager"); + evas_object_smart_callback_add(gld->win, "delete,request", _on_done, gld); + + // Get the screen size. + elm_win_screen_size_get(gld->win, &gld->win_x, &gld->win_y, &gld->scr_w, &gld->scr_h); + gld->win_x = gld->win_x + (gld->scr_w / 3); + gld->win_w = gld->scr_w / 2; + gld->win_h = gld->scr_h - 30; + + // Note, we don't need an Elm_bg, the entire thing gets covered with the GL rendering surface anyway. +#if 0 + bg = elm_bg_add(gld->win); + elm_bg_load_size_set(bg, gld->win_w, gld->win_h); + elm_bg_option_set(bg, ELM_BG_OPTION_CENTER); + snprintf(buf, sizeof(buf), "%s/media/sky_03.jpg", elm_app_data_dir_get()); + elm_bg_file_set(bg, buf, NULL); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(gld->win, bg); + evas_object_show(bg); +#endif + + gld->bx = elm_box_add(gld->win); + evas_object_size_hint_weight_set(gld->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(gld->bx, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_win_resize_object_add(gld->win, gld->bx); + evas_object_show(gld->bx); + + overlay_add(gld); + woMan_add(gld); + chat_add(gld); + + // Gotta do this after adding the windows, otherwise the menu renders under the window. + // This sucks, gotta redefine this menu each time we create a new window? + // Also, GL focus gets lost when any menu is used. sigh + + // A toolbar thingy. + tb = elm_toolbar_add(gld->win); + evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL); + elm_toolbar_align_set(tb, 0.0); + + // Menus. + menu = _toolbar_menu_add(gld->win, tb, "file"); + elm_menu_item_add(menu, NULL, NULL, "quit", _on_done, gld); + + menu = _toolbar_menu_add(gld->win, tb, "edit"); + elm_menu_item_add(menu, NULL, NULL, "preferences", NULL, NULL); + + menu = _toolbar_menu_add(gld->win, tb, "view"); + menu = _toolbar_menu_add(gld->win, tb, "world"); + menu = _toolbar_menu_add(gld->win, tb, "tools"); + + menu = _toolbar_menu_add(gld->win, tb, "help"); + elm_menu_item_add(menu, NULL, NULL, "grid help", NULL, NULL); + elm_menu_item_separator_add(menu, NULL); + elm_menu_item_add(menu, NULL, NULL, "extantz blogs", NULL, NULL); + elm_menu_item_add(menu, NULL, NULL, "extantz forum", NULL, NULL); + elm_menu_item_separator_add(menu, NULL); + elm_menu_item_add(menu, NULL, NULL, "about extantz", NULL, NULL); + + menu = _toolbar_menu_add(gld->win, tb, "advanced"); + elm_menu_item_add(menu, NULL, NULL, "debug settings", NULL, NULL); + + menu = _toolbar_menu_add(gld->win, tb, "god"); + + // Other stuff in the toolbar. + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_toolbar_item_separator_set(tb_it, EINA_TRUE); + tb_it = elm_toolbar_item_append(tb, NULL, "restriction icons", NULL, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_toolbar_item_separator_set(tb_it, EINA_TRUE); + tb_it = elm_toolbar_item_append(tb, NULL, "hop://localhost/Anarchadia 152, 155, 51 - Lost plot (Adult)", NULL, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_toolbar_item_separator_set(tb_it, EINA_TRUE); + tb_it = elm_toolbar_item_append(tb, NULL, "date time:o'clock", NULL, NULL); + + // The toolbar needs to be packed into the box AFTER the menus are added. + evas_object_show(tb); + elm_box_pack_start(gld->bx, tb); + + // This does elm_box_pack_end(), so needs to be after the others. + init_evas_gl(gld); + + evas_object_show(gld->bx); + +#if USE_PHYSICS + // ePhysics stuff. + world = ephysics_world_new(); + ephysics_world_render_geometry_set(world, 0, 0, -50, gld->win_w, gld->win_h, 100); + + boundary = ephysics_body_bottom_boundary_add(world); + ephysics_body_restitution_set(boundary, 1); + ephysics_body_friction_set(boundary, 0); + + boundary = ephysics_body_top_boundary_add(world); + ephysics_body_restitution_set(boundary, 1); + ephysics_body_friction_set(boundary, 0); + + boundary = ephysics_body_left_boundary_add(world); + ephysics_body_restitution_set(boundary, 1); + ephysics_body_friction_set(boundary, 0); + + boundary = ephysics_body_right_boundary_add(world); + ephysics_body_restitution_set(boundary, 1); + ephysics_body_friction_set(boundary, 0); + + box1 = elm_image_add(gld->win); + elm_image_file_set(box1, PACKAGE_DATA_DIR "/media/" EPHYSICS_TEST_THEME ".edj", "blue-cube"); + evas_object_move(box1, gld->win_w / 2 - 80, gld->win_h - 200); + evas_object_resize(box1, 70, 70); + evas_object_show(box1); + + box_body1 = ephysics_body_box_add(world); + ephysics_body_evas_object_set(box_body1, box1, EINA_TRUE); + ephysics_body_restitution_set(box_body1, 0.7); + ephysics_body_friction_set(box_body1, 0); + ephysics_body_linear_velocity_set(box_body1, -150, 200, 0); + ephysics_body_angular_velocity_set(box_body1, 0, 0, 36); + ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); + + box2 = elm_image_add(gld->win); + elm_image_file_set(box2, PACKAGE_DATA_DIR "/media/" EPHYSICS_TEST_THEME ".edj", "purple-cube"); + evas_object_move(box2, gld->win_w / 2 + 10, gld->win_h - 200); + evas_object_resize(box2, 70, 70); + evas_object_show(box2); + + box_body2 = ephysics_body_box_add(world); + ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE); + ephysics_body_restitution_set(box_body2, 0.7); + ephysics_body_friction_set(box_body2, 0); + ephysics_body_linear_velocity_set(box_body2, 80, -60, 0); + ephysics_body_angular_velocity_set(box_body2, 0, 0, 360); + ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1); + + ephysics_world_gravity_set(world, 0, 0, 0); +#endif + + evas_object_move(gld->win, gld->win_x, gld->win_y); + evas_object_resize(gld->win, gld->win_w, gld->win_h); + evas_object_show(gld->win); + + _resize_winwin(gld); + + elm_run(); + +#if USE_PHYSICS + ephysics_world_del(world); + ephysics_shutdown(); +#endif + + elm_shutdown(); + + return 0; +} +ELM_MAIN() diff --git a/src/extantz/extantz.edc b/src/extantz/extantz.edc new file mode 100644 index 0000000..b4ed0b3 --- /dev/null +++ b/src/extantz/extantz.edc @@ -0,0 +1,30 @@ +externals { + external: "elm"; +} + +collections { +#define ADD_CUBE(_group, _file) \ + images { \ + image: #_file##".png" COMP; \ + } \ + group { \ + name: #_group; \ + parts { \ + part { \ + name: "cube"; \ + type: IMAGE; \ + mouse_events: 1; \ + repeat_events: 0; \ + description { \ + state: "default" 0.0; \ + image.normal: #_file##".png"; \ + } \ + } \ + } \ + } + +ADD_CUBE(blue-cube, cube-blue); +ADD_CUBE(purple-cube, cube-purple); + +#undef ADD_CUBE +} diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h new file mode 100644 index 0000000..afb94af --- /dev/null +++ b/src/extantz/extantz.h @@ -0,0 +1,215 @@ +#define USE_EO 0 +#define USE_PHYSICS 1 +#define USE_EGL 1 // If using Evas_GL, though it might be via Elm. +#define USE_ELM_GL 1 +#define USE_IRR 1 +#define USE_DEMO 1 +#define DO_GEARS 0 + +#if USE_EO + /* Enable access to unstable EFL API that are still in beta */ + #define EFL_BETA_API_SUPPORT 1 + /* Enable access to unstable EFL EO API. */ + #define EFL_EO_API_SUPPORT 1 +#endif + +#include +#include +#include +#include +#include "extantzCamera.h" + + +#ifdef GL_GLES +#include +#include +#else +# include +# include +#endif + + +#ifdef __cplusplus +/* +In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if +you want to use a class of the engine, you have to write irr:: before the name +of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice. +To get rid of the irr:: in front of the name of every class, we tell the +compiler that we use that namespace from now on, and we will not have to write +irr:: anymore. +*/ +using namespace irr; + +/* +There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can +read a detailed description of them in the documentation by clicking on the top +menu item 'Namespace List' or by using this link: +http://irrlicht.sourceforge.net/docu/namespaces.html +Like the irr namespace, we do not want these 5 sub namespaces now, to keep this +example simple. Hence, we tell the compiler again that we do not want always to +write their names. +*/ +using namespace core; +using namespace scene; +using namespace video; + +extern "C"{ +#else + +// Irrlicht stuff. It's C++, so we gotta use incomplete types. +typedef struct IrrlichtDevice IrrlichtDevice; +typedef struct IVideoDriver IVideoDriver; +typedef struct ISceneManager ISceneManager; +typedef struct ICameraSceneNode ICameraSceneNode; + +#endif + + +#define CRI(...) EINA_LOG_DOM_CRIT(_log_domain, _VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__) +#define WRN(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__) +#define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__) + +extern int _log_domain; + + +typedef struct _Gear Gear; +typedef struct _GLData GLData; + +typedef enum +{ + EZP_NONE, + EZP_AURORA, + EZP_OPENSIM, + EZP_SECOND_LIFE, + EZP_SLEDJHAMR, + EZP_TRITIUM +} ezPlatform; + +typedef struct +{ + char *name; + char *version; // Version string. + char *path; // OS filesystem path to the viewer install. + char *icon; + uint16_t tag; // The UUID of the texture used in the avatar bake hack. + uint8_t r, g, b; // Colour used for the in world tag. + Elm_Object_Item *item; +} ezViewer; + +typedef struct +{ + Eina_Clist accounts; + Eina_Clist landmarks; + char *name; + char *loginURI; + char *splashPage; + char *helperURI; + char *website; + char *supportPage; + char *registerPage; + char *passwordPage; + char *icon; + ezPlatform platform; + ezViewer *viewer; + Elm_Object_Item *item; +GLData *gld; // Just a temporary evil hack to pass gld to _grid_sel_cb(). +} ezGrid; + +typedef struct +{ + Eina_Clist grid; + char *name; + char *password; // Think we need to pass unencrypted passwords to the viewer. B-( + char *icon; + ezViewer *viewer; +} ezAccount; + +typedef struct +{ + Eina_Clist grid; + char *name; + char *sim; + char *screenshot; + short x, y, z; +} ezLandmark; + + + +struct _Gear +{ + GLfloat *vertices; + GLuint vbo; + int count; +}; + +// GL related data here. +struct _GLData +{ + Evas_Object *win, *winwin; + + Ecore_Evas *ee; + Evas *canvas; + Evas_Native_Surface ns; + + Evas_GL_Context *ctx; + Evas_GL_Surface *sfc; + Evas_GL_Config *cfg; + Evas_GL *evasGl; // The Evas way. + Evas_Object *elmGl; // The Elm way. + Evas_GL_API *glApi; + + GLuint program; + GLuint vtx_shader; + GLuint fgmt_shader; + int scr_w, scr_h; // The size of the screen. + int win_w, win_h; // The size of the window. + int win_x, win_y; // The position of the window. + int sfc_w, sfc_h; // This is what Irrlicht is using, size of the GL image surface / glview. + int img_w, img_h; // Size of the viewport. DON'T reuse sfc_* here. Despite the fach that sfc_* is only used in the init when Irricht is disabled? WTF? + int useEGL : 1; + int useIrr : 1; + int doneIrr : 1; + int gearsInited : 1; + int resized : 1; + + Evas_Object *bx, *r1; + Ecore_Animator *animator; + + IrrlichtDevice *device; + IVideoDriver *driver; + ISceneManager *smgr; + ICameraSceneNode *camera; + + cameraMove *move; + + // Gear Stuff + GLfloat view_rotx; + GLfloat view_roty; + GLfloat view_rotz; + + Gear *gear1; + Gear *gear2; + Gear *gear3; + + GLfloat angle; + + GLuint proj_location; + GLuint light_location; + GLuint color_location; + + GLfloat proj[16]; + GLfloat light[3]; +}; + + +EAPI int startIrr(GLData *gld); +EAPI void drawIrr_start(GLData *gld); +EAPI void drawIrr_end(GLData *gld); +EAPI void finishIrr(GLData *gld); + +#ifdef __cplusplus +} +#endif + diff --git a/src/extantz/extantzCamera.cpp b/src/extantz/extantzCamera.cpp new file mode 100644 index 0000000..6a7d36a --- /dev/null +++ b/src/extantz/extantzCamera.cpp @@ -0,0 +1,282 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +// The above is the copyright notice for CSceneNodeAnimatorCameraFPS.cpp, +// According to the Irrlicht docs, that's just a demo and you are supposed to use it as an example for writing your own FPS style camera. +// I'll be writing my own camera code, that includes first person, third person, and free camera styles. +// I'll start with CSceneNodeAnimatorCameraFPS.cpp and morph it until it suits me. +// As such, I expect lots of Nikolaus Gebhardt's code to go away. +// To be replaced by my code, which will be copyright and licensed under the same license as the rest of extantz. + +// Initally I'll make it SecondLife like, coz that's what my muscle memory is used to. +// It will get extended and made generic though. + +#include "extantzCamera.h" +#include "IVideoDriver.h" +#include "ISceneManager.h" +#include "Keycodes.h" +#include "ICursorControl.h" +#include "ICameraSceneNode.h" +#include "ISceneNodeAnimatorCollisionResponse.h" + +namespace irr +{ +namespace scene +{ + +// Irrlicht hard codes a reference to the original FPS camera code inside it's scene manager. This is that code extracted so we can be more flexible. +// TODO - Hmmm, Where's CursorControl come from? Ah, passed to the scene manager constructor, it's a GUI thing that we need to replace with an EFL thing. But only for mouselook mode. +ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, s32 id) +{ + ICameraSceneNode* node = sm->addCameraSceneNode(parent, core::vector3df(), core::vector3df(0, 0, 100), id, true); + if (node) + { +// ISceneNodeAnimator* anm = new extantzCamera(CursorControl); + ISceneNodeAnimator* anm = new extantzCamera(); + + // Bind the node's rotation to its target. This is consistent with 1.4.2 and below. + node->bindTargetAndRotation(true); + node->addAnimator(anm); + anm->drop(); + } + + return node; +} + + +//! constructor +//extantzCamera::extantzCamera(gui::ICursorControl* cursorControl) +// : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(0.4f), RotateSpeed(100.0f), JumpSpeed(3.0f), +extantzCamera::extantzCamera() + : MaxVerticalAngle(88.0f), MouseYDirection(1.0f), LastAnimationTime(0), NoVerticalMovement(false) +{ + #ifdef _DEBUG + setDebugName("extantzCamera"); + #endif + + move.jump = 0.0; // Coz otherwise we start in jumping mode. + move.MoveSpeed = 0.1f; + move.RotateSpeed = 1.0f; + move.JumpSpeed = 3.0f; + +// if (CursorControl) +// CursorControl->grab(); +} + + +//! destructor +extantzCamera::~extantzCamera() +{ +// if (CursorControl) +// CursorControl->drop(); +} + + +void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) +{ + if (!node || node->getType() != ESNT_CAMERA) + return; + + ICameraSceneNode* camera = static_cast(node); + + if (0 == LastAnimationTime) + { + camera->updateAbsolutePosition(); +// if (CursorControl ) +// { +// CursorControl->setPosition(0.5f, 0.5f); +// CursorPos = CenterCursor = CursorControl->getRelativePosition(); +// } + + LastAnimationTime = timeMs; + } + + // If the camera isn't the active camera, and receiving input, then don't process it. + // TODO - it never is, coz we are bypassing that, but can we replace this with something else? + if(!camera->isInputReceiverEnabled()) + { +// return; + } + + scene::ISceneManager * smgr = camera->getSceneManager(); + if(smgr && smgr->getActiveCamera() != camera) + return; + + // get time + f32 timeDiff = (f32) (timeMs - LastAnimationTime); + LastAnimationTime = timeMs; + + // update position + core::vector3df pos = camera->getPosition(); + + // Update rotation + core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition()); + core::vector3df relativeRotation = target.getHorizontalAngle(); + +#if 0 + if (CursorControl) + { + if (CursorPos != CenterCursor) + { + relativeRotation.Y -= (0.5f - CursorPos.X) * move.RotateSpeed; + relativeRotation.X -= (0.5f - CursorPos.Y) * move.RotateSpeed * MouseYDirection; + + // X < MaxVerticalAngle or X > 360-MaxVerticalAngle + + if (relativeRotation.X > MaxVerticalAngle*2 && + relativeRotation.X < 360.0f-MaxVerticalAngle) + { + relativeRotation.X = 360.0f-MaxVerticalAngle; + } + else + if (relativeRotation.X > MaxVerticalAngle && + relativeRotation.X < 360.0f-MaxVerticalAngle) + { + relativeRotation.X = MaxVerticalAngle; + } + + // Do the fix as normal, special case below + // reset cursor position to the centre of the window. + CursorControl->setPosition(0.5f, 0.5f); + CenterCursor = CursorControl->getRelativePosition(); + + // needed to avoid problems when the event receiver is disabled + CursorPos = CenterCursor; + } + + // Special case, mouse is whipped outside of window before it can update. + video::IVideoDriver* driver = smgr->getVideoDriver(); + core::vector2d mousepos(u32(CursorControl->getPosition().X), u32(CursorControl->getPosition().Y)); + core::rect screenRect(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height); + + // Only if we are moving outside quickly. + bool reset = !screenRect.isPointInside(mousepos); + + if(reset) + { + // Force a reset. + CursorControl->setPosition(0.5f, 0.5f); + CenterCursor = CursorControl->getRelativePosition(); + CursorPos = CenterCursor; + } + } +#else + relativeRotation.Y -= move.r * move.RotateSpeed; + relativeRotation.X -= move.s * move.RotateSpeed * MouseYDirection; + + // X < MaxVerticalAngle or X > 360-MaxVerticalAngle + + if ((relativeRotation.X > (MaxVerticalAngle * 2)) && (relativeRotation.X < (360.0f - MaxVerticalAngle))) + relativeRotation.X = 360.0f - MaxVerticalAngle; + else if ((relativeRotation.X > MaxVerticalAngle) && (relativeRotation.X < (360.0f - MaxVerticalAngle))) + relativeRotation.X = MaxVerticalAngle; +#endif + + // set target + + target.set(0,0, core::max_(1.f, pos.getLength())); + core::vector3df movedir = target; + + core::matrix4 mat; + mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0)); + mat.transformVect(target); + + if (NoVerticalMovement) + { + mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0)); + mat.transformVect(movedir); + } + else + { + movedir = target; + } + + movedir.normalize(); + + pos += movedir * timeDiff * move.MoveSpeed * move.x; + + // strafing + core::vector3df strafevect = target; + strafevect = strafevect.crossProduct(camera->getUpVector()); + + if (NoVerticalMovement) + strafevect.Y = 0.0f; + + strafevect.normalize(); + + pos += strafevect * timeDiff * move.MoveSpeed * move.y; + + // For jumping, we find the collision response animator attached to our camera + // and if it's not falling, we tell it to jump. + if (0.0 < move.jump) + { + const ISceneNodeAnimatorList& animators = camera->getAnimators(); + ISceneNodeAnimatorList::ConstIterator it = animators.begin(); + while(it != animators.end()) + { + if(ESNAT_COLLISION_RESPONSE == (*it)->getType()) + { + ISceneNodeAnimatorCollisionResponse * collisionResponse = + static_cast(*it); + + if(!collisionResponse->isFalling()) + collisionResponse->jump(move.JumpSpeed); + } + + it++; + } + } + + // write translation + camera->setPosition(pos); + + // write right target + target += pos; + camera->setTarget(target); +} + + +ISceneNodeAnimator* extantzCamera::createClone(ISceneNode* node, ISceneManager* newManager) +{ +// extantzCamera *newAnimator = new extantzCamera(CursorControl); + extantzCamera *newAnimator = new extantzCamera(); + return newAnimator; +} + +#ifdef __cplusplus +extern "C" { +#endif + +cameraMove *getCameraMove(ICameraSceneNode *camera) +{ + cameraMove *cm = NULL; + + if (camera) + { + const ISceneNodeAnimatorList &animators = camera->getAnimators(); + ISceneNodeAnimatorList::ConstIterator it = animators.begin(); + while(it != animators.end()) + { + // TODO - We assume FPS == extantzCamera, coz Irrlicht hard codes the camera types in an enum, which is a pain to add to from outside. + if(ESNAT_CAMERA_FPS == (*it)->getType()) + { + extantzCamera *ec = static_cast(*it); + + cm = &(ec->move); + } + + it++; + } + } + return cm; +} + +#ifdef __cplusplus +} +#endif + + +} // namespace scene +} // namespace irr + diff --git a/src/extantz/extantzCamera.h b/src/extantz/extantzCamera.h new file mode 100644 index 0000000..9d74236 --- /dev/null +++ b/src/extantz/extantzCamera.h @@ -0,0 +1,101 @@ +// Copyright (C) 2002-2012 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#ifndef __EXTANTZ_CAMERA_H_INCLUDED__ +#define __EXTANTZ_CAMERA_H_INCLUDED__ + + +#ifdef __cplusplus +#include +#include +#include +#include +#include +#include + +using namespace irr; +using namespace scene; + +extern "C"{ +#else +typedef struct extantzCamera extantzCamera; +typedef struct ICameraSceneNode ICameraSceneNode; +#endif + +typedef struct +{ + float x, y, z; + float r, s, t; + float jump; + float JumpSpeed, RotateSpeed, MoveSpeed; +} cameraMove; + +cameraMove *getCameraMove(ICameraSceneNode *camera); + +#ifdef __cplusplus +} + + +//namespace irr::gui +//{ +// class ICursorControl; +//} + + +namespace irr +{ +namespace scene +{ + ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, s32 id); + + class extantzCamera : public ISceneNodeAnimator + { + public: + + //! Constructor +// extantzCamera(gui::ICursorControl* cursorControl); + extantzCamera(); + + //! Destructor + virtual ~extantzCamera(); + + //! Animates the scene node, currently only works on cameras + virtual void animateNode(ISceneNode* node, u32 timeMs); + + //! This animator will receive events when attached to the active camera + virtual bool isEventReceiverEnabled() const + { + return false; + } + + //! Returns the type of this animator + virtual ESCENE_NODE_ANIMATOR_TYPE getType() const + { + return ESNAT_CAMERA_FPS; + } + + //! Creates a clone of this animator. + /** Please note that you will have to drop + (IReferenceCounted::drop()) the returned pointer once you're + done with it. */ + virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); + + bool NoVerticalMovement; + // -1.0f for inverted mouse, defaults to 1.0f + f32 MouseYDirection; + + cameraMove move; + + private: + f32 MaxVerticalAngle; + s32 LastAnimationTime; +// core::position2d CenterCursor, CursorPos; + }; +}; +}; +#endif + + +#endif // __EXTANTZ_CAMERA_H_INCLUDED__ + -- cgit v1.1