X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FScene.cc;h=dc6ab75cac02f218bebd54d1b173382c64086389;hp=9510e3670577fff9a7385f343f34a6773a9a9392;hb=HEAD;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/Scene.cc b/src/Scene.cc index 9510e36..dc6ab75 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -1,13 +1,11 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ #include @@ -18,9 +16,10 @@ #include #include #include +#include #include #include -#include +#include #include "Character.hh" #include "Scene.hh" @@ -35,13 +34,13 @@ struct Scene::impl : public moof::manager NONE = 0, LEFT = 1, RIGHT = 2, - TOP = 3 + TOP = 3 }; Quad(const moof::vector3* vertices[4], - const std::string& texture, - int tileIndex) : - mTilemap(texture), + const moof::image_handle& texture, + int tileIndex) : + mTilemap(texture, tileIndex), mBlending(false), mFog(false), mSurface(NONE) @@ -55,17 +54,6 @@ struct Scene::impl : public moof::manager //} } - if (!mTilemap.tile_coordinates(tileIndex, mTexCoords)) - { - moof::log_warning << "no index " << tileIndex << - " in texture " << texture << std::endl; - - mTexCoords[0] = mTexCoords[1] = - mTexCoords[3] = mTexCoords[6] = 0.0; - mTexCoords[2] = mTexCoords[4] = - mTexCoords[5] = mTexCoords[7] = 1.0; - } - aabb_.enclose_vertices(mVertices, 4); sphere_.point = aabb_.center(); sphere_.radius = (aabb_.min - sphere_.point).length(); @@ -106,12 +94,7 @@ struct Scene::impl : public moof::manager } //glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - mTilemap.bind(); - - glVertexPointer(3, GL_SCALAR, 0, mVertices[0].data()); - glTexCoordPointer(2, GL_SCALAR, 0, mTexCoords); - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + mTilemap.draw(mVertices); glDisable(GL_BLEND); glDisable(GL_FOG); @@ -123,25 +106,24 @@ struct Scene::impl : public moof::manager } - moof::vector3 mVertices[4]; - moof::scalar mTexCoords[8]; + moof::vector3 mVertices[4]; - moof::texture mTilemap; + moof::sprite mTilemap; - bool mBlending; - bool mFog; - Surface mSurface; + bool mBlending; + bool mFog; + Surface mSurface; }; - moof::matrix4 mTransform; - std::string mTexture; + moof::matrix4 mTransform; + moof::image_handle mTexture; std::list< boost::shared_ptr > mObjects; - std::list mLines; + std::list mLines; - moof::aabb<3> mBounds; + moof::aabb<3> mBounds; enum AXIS @@ -194,8 +176,8 @@ struct Scene::impl : public moof::manager moof::script::status load(moof::settings& settings, moof::script& script) { - std::string path(name()); - if (!Scene::find_path(path)) + std::string path = moof::resource::find_file("scenes/"+name(), "lua"); + if (path.empty()) { script.push("the scene file could not be found"); return moof::script::file_error; @@ -208,8 +190,8 @@ struct Scene::impl : public moof::manager static int loadBox(moof::script& script, moof::aabb3& aabb) { - script[1].require_table(); - script[2].require_table(); + script[1].require_table("point"); + script[2].require_table("point"); script[1].push_field(1).get(aabb.min[0]); script[1].push_field(2).get(aabb.min[1]); @@ -223,8 +205,7 @@ struct Scene::impl : public moof::manager int setBounds(moof::script& script) { - int ret = loadBox(script, mBounds); - return ret; + return loadBox(script, mBounds); } int resetTransform(moof::script& script) @@ -281,21 +262,22 @@ struct Scene::impl : public moof::manager int rotate(moof::script& script) { - size_t index = 0; - script[1].require_number().get(index); + size_t index = 0; + moof::scalar value; - moof::scalar value; + script[1].require_number().get(index); script[2].require_number().get(value); - moof::matrix_rotate_about_world_axis(mTransform, index, - moof::rad(value)); + moof::matrix_rotate_about_world_axis(mTransform, index, moof::rad(value)); return 0; } int setTexture(moof::script& script) { - script[1].require_string().get(mTexture); + std::string texture_name; + script[1].require_string().get(texture_name); + mTexture = moof::resource::load(texture_name, "png"); return 0; } @@ -348,7 +330,7 @@ struct Scene::impl : public moof::manager vertices[h][wPlus1] = moof::demote(mTransform * moof::vector4(wPlus1, h, 0.0, 1.0)); - if (index == moof::texture::no_tile) continue; + if (index == moof::image::no_tile) continue; const moof::vector3* corners[4] = { &vertices[h][w], @@ -365,7 +347,7 @@ struct Scene::impl : public moof::manager } } - Quad::Surface surface = Quad::NONE; + Quad::Surface surface = Quad::NONE; table.get(surface, "surface"); if (surface != Quad::NONE) @@ -380,7 +362,6 @@ struct Scene::impl : public moof::manager mLines.push_back(moof::line<2>(bl, tr)); } - return 0; } @@ -389,8 +370,8 @@ struct Scene::impl : public moof::manager moof::script::slot param = script[1]; moof::script::slot top = script[-1]; - int index = 0; - int width = 1; + int index = 0; + int width = 1; bool blending = false; bool fog = false; @@ -494,7 +475,7 @@ void Scene::draw_if_visible(moof::scalar alpha, bool Scene::castRay(const moof::ray<2>& ray, - std::list::contact>& hits) const + std::list::contact>& hits) const { std::list< moof::line<2> >& lines = impl_->mLines; std::list< moof::line<2> >::const_iterator it; @@ -573,9 +554,3 @@ bool Scene::checkForCollision(Character& character) return false; } - -bool Scene::find_path(std::string& name) -{ - return moof::resource::find_path(name, "scenes/", "lua"); -} -