ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

sprite.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/endian.h"
00024 
00025 #include "engines/grim/debug.h"
00026 #include "engines/grim/sprite.h"
00027 #include "engines/grim/resource.h"
00028 #include "engines/grim/gfx_base.h"
00029 #include "engines/grim/emi/costumeemi.h"
00030 
00031 
00032 namespace Grim {
00033 
00034 Sprite::Sprite() :
00035         _width(0), _height(0), _visible(false), _material(nullptr), _next(nullptr),
00036         _flags1(0), _flags2(0) {
00037 }
00038 
00039 
00040 void Sprite::draw() const {
00041     if (!_visible)
00042         return;
00043 
00044     _material->select();
00045     g_driver->drawSprite(this);
00046 }
00047 
00048 void Sprite::loadGrim(const Common::String &name, const char *comma, CMap *cmap) {
00049     int width, height, x, y, z;
00050     sscanf(comma, ",%d,%d,%d,%d,%d", &width, &height, &x, &y, &z);
00051     _material = g_resourceloader->loadMaterial(name, cmap, true);
00052     _width = (float)width / 100.0f;
00053     _height = (float)height / 100.0f;
00054     _pos.set((float)x / 100.0f, (float)y / 100.0f, (float)z / 100.0f);
00055 
00056     // Set the default flags for GRIM sprites
00057     _flags1 = Sprite::AlphaTest;
00058     _flags2 = Sprite::DepthTest;
00059 }
00060 
00061 void Sprite::loadBinary(Common::SeekableReadStream *stream, EMICostume *costume) {
00062     if (!stream)
00063         return;
00064 
00065     uint32 namelength = stream->readUint32LE();
00066     char *name = new char[namelength];
00067     stream->read(name, namelength);
00068 
00069     stream->seek(40, SEEK_CUR);
00070     uint32 texnamelength = stream->readUint32LE();
00071     char *texname = new char[texnamelength];
00072     stream->read(texname, texnamelength);
00073     _flags1 = stream->readUint32LE();
00074     if (_flags1 & ~(BlendAdditive)) {
00075         Debug::debug(Debug::Sprites, "Sprite %s has unknown flags (%08x) in first flag field", name, _flags1);
00076     }
00077     _width = stream->readFloatLE();
00078     _height = stream->readFloatLE();
00079     _pos.readFromStream(stream);
00080     for (int i = 0; i < 4; ++i) {
00081         _alpha[i] = stream->readSint32LE();
00082         _red[i] = stream->readSint32LE();
00083         _green[i] = stream->readSint32LE();
00084         _blue[i] = stream->readSint32LE();
00085     }
00086     for (int i = 0; i < 4; ++i) {
00087         _texCoordX[i] = stream->readFloatLE();
00088         _texCoordY[i] = stream->readFloatLE();
00089     }
00090     _flags2 = stream->readUint32LE();
00091     if (_flags2 & ~(DepthTest | AlphaTest)) {
00092         Debug::debug(Debug::Sprites, "Sprite %s has unknown flags (%08x) in second flag field", name, _flags2);
00093     }
00094 
00095     _material = costume->loadMaterial(texname, true);
00096     _next = nullptr;
00097     _visible = true;
00098 
00099     delete[] name;
00100     delete[] texname;
00101 }
00102 
00103 } // end of namespace Grim


Generated on Sat Mar 16 2019 05:01:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge