SWORD25: Mass-astyle.
svn-id: r53222
This commit is contained in:
parent
ca17def625
commit
47904bc7b2
146 changed files with 5057 additions and 5644 deletions
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -38,7 +38,9 @@ namespace Sword25 {
|
|||
|
||||
#define BS_LOG_PREFIX "MOVIEPLAYER"
|
||||
|
||||
BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { return new BS_MoviePlayer(pKernel); }
|
||||
BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) {
|
||||
return new BS_MoviePlayer(pKernel);
|
||||
}
|
||||
|
||||
BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) {
|
||||
if (!_RegisterScriptBindings())
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -67,16 +67,16 @@ public:
|
|||
* This method loads a movie file and prepares it for playback.
|
||||
* There can be oly one movie file loaded at a time. If you already have loaded a
|
||||
* movie file, it will be unloaded and, if necessary, stopped playing.
|
||||
* @param Filename The filename of the movie file to be loaded
|
||||
* @param Z Z indicates the position of the film on the main graphics layer
|
||||
* @return Returns false if an error occured while loading, otherwise true.
|
||||
* @param Filename The filename of the movie file to be loaded
|
||||
* @param Z Z indicates the position of the film on the main graphics layer
|
||||
* @return Returns false if an error occured while loading, otherwise true.
|
||||
*/
|
||||
bool LoadMovie(const Common::String &Filename, unsigned int Z);
|
||||
|
||||
/**
|
||||
* Unloads the currently loaded movie file.
|
||||
* @return Returns false if an error occurred while unloading, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @return Returns false if an error occurred while unloading, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool UnloadMovie();
|
||||
|
||||
|
@ -85,8 +85,8 @@ public:
|
|||
*
|
||||
* The film will be keeping the aspect ratio of the screen.
|
||||
* If the film was previously paused with Pause(), then the film will resume playing.
|
||||
* @return Returns false if an error occurred while starting, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @return Returns false if an error occurred while starting, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool Play();
|
||||
|
||||
|
@ -94,8 +94,8 @@ public:
|
|||
* Pauses movie playback.
|
||||
*
|
||||
* A paused movie can later be resumed by calling the Play() method again.
|
||||
* @return Returns false if an error occurred while pausing, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @return Returns false if an error occurred while pausing, otherwise true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool Pause();
|
||||
|
||||
|
@ -111,7 +111,7 @@ public:
|
|||
|
||||
/**
|
||||
* Returns whether the movie playback is paused.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
bool IsPaused();
|
||||
|
||||
|
@ -120,21 +120,21 @@ public:
|
|||
*
|
||||
* When a movie is loaded, the scaling factor is automatically selected so that the film
|
||||
* takes the maximum screen space, without the film being distorted.
|
||||
* @return Returns the scaling factor of the film.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @return Returns the scaling factor of the film.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
float GetScaleFactor();
|
||||
|
||||
/**
|
||||
* Sets the factor by which the loaded film is to be scaled.
|
||||
* @param ScaleFactor The desired scale factor.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @param ScaleFactor The desired scale factor.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
void SetScaleFactor(float ScaleFactor);
|
||||
|
||||
/**
|
||||
* Returns the current playing position in seconds.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
* @remark This method can only be called when IsMovieLoaded() returns true.
|
||||
*/
|
||||
double GetTime();
|
||||
|
||||
|
|
|
@ -64,11 +64,11 @@ TheoraDecoder::~TheoraDecoder() {
|
|||
}
|
||||
|
||||
void TheoraDecoder::queuePage(ogg_page *page) {
|
||||
if (_theoraPacket)
|
||||
ogg_stream_pagein(&_theoraOut, page);
|
||||
if (_theoraPacket)
|
||||
ogg_stream_pagein(&_theoraOut, page);
|
||||
|
||||
if (_vorbisPacket)
|
||||
ogg_stream_pagein(&_vorbisOut, page);
|
||||
if (_vorbisPacket)
|
||||
ogg_stream_pagein(&_vorbisOut, page);
|
||||
}
|
||||
|
||||
int TheoraDecoder::bufferData() {
|
||||
|
@ -203,7 +203,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) {
|
|||
|
||||
if (_theoraInfo.pic_width != _theoraInfo.frame_width || _theoraInfo.pic_height != _theoraInfo.frame_height)
|
||||
debug(1, " Frame content is %dx%d with offset (%d,%d).",
|
||||
_theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y);
|
||||
_theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y);
|
||||
|
||||
th_decode_ctl(_theoraDecode, TH_DECCTL_GET_PPLEVEL_MAX, &_ppLevelMax, sizeof(_ppLevelMax));
|
||||
_ppLevel = _ppLevelMax;
|
||||
|
@ -222,7 +222,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) {
|
|||
vorbis_synthesis_init(&_vorbisDSP, &_vorbisInfo);
|
||||
vorbis_block_init(&_vorbisDSP, &_vorbisBlock);
|
||||
debug(3, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.",
|
||||
_vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate);
|
||||
_vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate);
|
||||
} else {
|
||||
// tear down the partial vorbis setup
|
||||
vorbis_info_clear(&_vorbisInfo);
|
||||
|
@ -307,7 +307,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() {
|
|||
_audiobufGranulePos = _vorbisDSP.granulepos - ret + i;
|
||||
else
|
||||
_audiobufGranulePos += i;
|
||||
} else {
|
||||
} else {
|
||||
|
||||
// no pending audio; is there a pending packet to decode?
|
||||
if (ogg_stream_packetout(&_vorbisOut, &_oggPacket) > 0) {
|
||||
|
@ -367,7 +367,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() {
|
|||
// are we at or past time for this video frame?
|
||||
if (_stateFlag && _videobufReady) {
|
||||
th_ycbcr_buffer yuv;
|
||||
|
||||
|
||||
th_decode_ycbcr_out(_theoraDecode, yuv);
|
||||
|
||||
// TODO: YUV->RGB
|
||||
|
@ -388,7 +388,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() {
|
|||
// if our buffers either don't exist or are ready to go,
|
||||
// we can begin playback
|
||||
if ((!_theoraPacket || _videobufReady) &&
|
||||
(!_vorbisPacket || _audiobufReady))
|
||||
(!_vorbisPacket || _audiobufReady))
|
||||
_stateFlag = true;
|
||||
|
||||
// same if we've run out of input
|
||||
|
|
26
engines/sword25/fmv/theora_decoder.h
Executable file → Normal file
26
engines/sword25/fmv/theora_decoder.h
Executable file → Normal file
|
@ -34,7 +34,7 @@
|
|||
#include <vorbis/codec.h>
|
||||
|
||||
namespace Common {
|
||||
class SeekableReadStream;
|
||||
class SeekableReadStream;
|
||||
}
|
||||
|
||||
namespace Sword25 {
|
||||
|
@ -65,16 +65,28 @@ public:
|
|||
*/
|
||||
Graphics::Surface *decodeNextFrame();
|
||||
|
||||
bool isVideoLoaded() const { return _fileStream != 0; }
|
||||
uint16 getWidth() const { return _surface->w; }
|
||||
uint16 getHeight() const { return _surface->h; }
|
||||
uint32 getFrameCount() const { return _frameCount; }
|
||||
Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); }
|
||||
bool isVideoLoaded() const {
|
||||
return _fileStream != 0;
|
||||
}
|
||||
uint16 getWidth() const {
|
||||
return _surface->w;
|
||||
}
|
||||
uint16 getHeight() const {
|
||||
return _surface->h;
|
||||
}
|
||||
uint32 getFrameCount() const {
|
||||
return _frameCount;
|
||||
}
|
||||
Graphics::PixelFormat getPixelFormat() const {
|
||||
return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
uint32 getElapsedTime() const;
|
||||
|
||||
protected:
|
||||
Common::Rational getFrameRate() const { return _frameRate; }
|
||||
Common::Rational getFrameRate() const {
|
||||
return _frameRate;
|
||||
}
|
||||
|
||||
private:
|
||||
void queuePage(ogg_page *page);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -57,9 +57,8 @@ namespace Sword25 {
|
|||
// Konstruktion / Destruktion
|
||||
// --------------------------
|
||||
|
||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String & FileName) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION)
|
||||
{
|
||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &FileName) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION) {
|
||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||
if (!m_InitSuccess) return;
|
||||
|
||||
|
@ -69,16 +68,15 @@ BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const
|
|||
m_InitSuccess = false;
|
||||
|
||||
InitializeAnimationResource(FileName);
|
||||
|
||||
|
||||
// Erfolg signalisieren.
|
||||
m_InitSuccess = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate & Template) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION)
|
||||
{
|
||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate &Template) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION) {
|
||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||
if (!m_InitSuccess) return;
|
||||
|
||||
|
@ -95,9 +93,8 @@ BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Animation::BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION, Handle)
|
||||
{
|
||||
BS_Animation::BS_Animation(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION, Handle) {
|
||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||
if (!m_InitSuccess) return;
|
||||
|
||||
|
@ -109,14 +106,12 @@ BS_Animation::BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::InitializeAnimationResource(const Common::String &FileName)
|
||||
{
|
||||
void BS_Animation::InitializeAnimationResource(const Common::String &FileName) {
|
||||
// Die Resource wird für die gesamte Lebensdauer des Animations-Objektes gelockt.
|
||||
BS_Resource * ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(FileName);
|
||||
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(FileName);
|
||||
if (ResourcePtr && ResourcePtr->GetType() == BS_Resource::TYPE_ANIMATION)
|
||||
m_AnimationResourcePtr = static_cast<BS_AnimationResource *>(ResourcePtr);
|
||||
else
|
||||
{
|
||||
else {
|
||||
BS_LOG_ERRORLN("The resource \"%s\" could not be requested. The Animation can't be created.", FileName.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -127,8 +122,7 @@ void BS_Animation::InitializeAnimationResource(const Common::String &FileName)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::InitMembers()
|
||||
{
|
||||
void BS_Animation::InitMembers() {
|
||||
m_CurrentFrame = 0;
|
||||
m_CurrentFrameTime = 0;
|
||||
m_Direction = FORWARD;
|
||||
|
@ -146,17 +140,15 @@ void BS_Animation::InitMembers()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Animation::~BS_Animation()
|
||||
{
|
||||
if (GetAnimationDescription())
|
||||
{
|
||||
BS_Animation::~BS_Animation() {
|
||||
if (GetAnimationDescription()) {
|
||||
Stop();
|
||||
GetAnimationDescription()->Unlock();
|
||||
}
|
||||
|
||||
// Delete Callbacks
|
||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_DeleteCallbacks.begin();
|
||||
for (; it != m_DeleteCallbacks.end(); it++) ((*it).Callback)((*it).Data);
|
||||
for (; it != m_DeleteCallbacks.end(); it++)((*it).Callback)((*it).Data);
|
||||
|
||||
}
|
||||
|
||||
|
@ -164,8 +156,7 @@ BS_Animation::~BS_Animation()
|
|||
// Steuermethoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::Play()
|
||||
{
|
||||
void BS_Animation::Play() {
|
||||
// Wenn die Animation zuvor komplett durchgelaufen ist, wird sie wieder von Anfang abgespielt
|
||||
if (m_Finished) Stop();
|
||||
|
||||
|
@ -175,16 +166,14 @@ void BS_Animation::Play()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::Pause()
|
||||
{
|
||||
void BS_Animation::Pause() {
|
||||
m_Running = false;
|
||||
UnlockAllFrames();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::Stop()
|
||||
{
|
||||
void BS_Animation::Stop() {
|
||||
m_CurrentFrame = 0;
|
||||
m_CurrentFrameTime = 0;
|
||||
m_Direction = FORWARD;
|
||||
|
@ -193,15 +182,13 @@ void BS_Animation::Stop()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetFrame(unsigned int Nr)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::SetFrame(unsigned int Nr) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
|
||||
if (Nr >= animationDescriptionPtr->GetFrameCount())
|
||||
{
|
||||
if (Nr >= animationDescriptionPtr->GetFrameCount()) {
|
||||
BS_LOG_ERRORLN("Tried to set animation to illegal frame (%d). Value must be between 0 and %d.",
|
||||
Nr, animationDescriptionPtr->GetFrameCount());
|
||||
Nr, animationDescriptionPtr->GetFrameCount());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -215,37 +202,33 @@ void BS_Animation::SetFrame(unsigned int Nr)
|
|||
// Rendern
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::DoRender()
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::DoRender() {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
BS_ASSERT(m_CurrentFrame < animationDescriptionPtr->GetFrameCount());
|
||||
|
||||
// Bitmap des aktuellen Frames holen
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(m_CurrentFrame).FileName);
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(m_CurrentFrame).FileName);
|
||||
BS_ASSERT(pResource);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource * pBitmapResource = static_cast<BS_BitmapResource*>(pResource);
|
||||
BS_BitmapResource *pBitmapResource = static_cast<BS_BitmapResource *>(pResource);
|
||||
|
||||
// Framebufferobjekt holen
|
||||
BS_GraphicEngine * pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_GraphicEngine *pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_ASSERT(pGfx);
|
||||
|
||||
// Bitmap zeichnen
|
||||
bool Result;
|
||||
if (IsScalingAllowed() && (m_Width != pBitmapResource->GetWidth() || m_Height != pBitmapResource->GetHeight()))
|
||||
{
|
||||
if (IsScalingAllowed() && (m_Width != pBitmapResource->GetWidth() || m_Height != pBitmapResource->GetHeight())) {
|
||||
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
} else {
|
||||
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
}
|
||||
|
||||
// Resource freigeben
|
||||
|
@ -258,15 +241,13 @@ bool BS_Animation::DoRender()
|
|||
// Frame Notifikation
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::FrameNotification(int TimeElapsed)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::FrameNotification(int TimeElapsed) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
BS_ASSERT(TimeElapsed >= 0);
|
||||
|
||||
// Nur wenn die Animation läuft wird sie auch weiterbewegt
|
||||
if (m_Running)
|
||||
{
|
||||
if (m_Running) {
|
||||
int OldFrame = m_CurrentFrame;
|
||||
|
||||
// Gesamte vergangene Zeit bestimmen (inkl. Restzeit des aktuellen Frames)
|
||||
|
@ -280,8 +261,7 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
|||
|
||||
// Neuen Frame bestimmen (je nach aktuellener Abspielrichtung wird addiert oder subtrahiert)
|
||||
int TmpCurFrame = m_CurrentFrame;
|
||||
switch (m_Direction)
|
||||
{
|
||||
switch (m_Direction) {
|
||||
case FORWARD:
|
||||
TmpCurFrame += SkipFrames;
|
||||
break;
|
||||
|
@ -292,20 +272,16 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
|||
|
||||
default:
|
||||
BS_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Überläufe behandeln
|
||||
if (TmpCurFrame < 0)
|
||||
{
|
||||
if (TmpCurFrame < 0) {
|
||||
// Loop-Point Callbacks
|
||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
||||
while (it != m_LoopPointCallbacks.end())
|
||||
{
|
||||
if (((*it).Callback)((*it).Data) == false)
|
||||
{
|
||||
while (it != m_LoopPointCallbacks.end()) {
|
||||
if (((*it).Callback)((*it).Data) == false) {
|
||||
it = m_LoopPointCallbacks.erase(it);
|
||||
}
|
||||
else
|
||||
} else
|
||||
it++;
|
||||
}
|
||||
|
||||
|
@ -313,21 +289,17 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
|||
BS_ASSERT(animationDescriptionPtr->GetAnimationType() == AT_JOJO);
|
||||
TmpCurFrame = - TmpCurFrame;
|
||||
m_Direction = FORWARD;
|
||||
}
|
||||
else if (static_cast<unsigned int>(TmpCurFrame) >= animationDescriptionPtr->GetFrameCount())
|
||||
{
|
||||
} else if (static_cast<unsigned int>(TmpCurFrame) >= animationDescriptionPtr->GetFrameCount()) {
|
||||
// Loop-Point Callbacks
|
||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
||||
while (it != m_LoopPointCallbacks.end())
|
||||
{
|
||||
while (it != m_LoopPointCallbacks.end()) {
|
||||
if (((*it).Callback)((*it).Data) == false)
|
||||
it = m_LoopPointCallbacks.erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
|
||||
switch (animationDescriptionPtr->GetAnimationType())
|
||||
{
|
||||
switch (animationDescriptionPtr->GetAnimationType()) {
|
||||
case AT_ONESHOT:
|
||||
TmpCurFrame = animationDescriptionPtr->GetFrameCount() - 1;
|
||||
m_Finished = true;
|
||||
|
@ -348,16 +320,13 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
|||
}
|
||||
}
|
||||
|
||||
if (m_CurrentFrame != TmpCurFrame)
|
||||
{
|
||||
if (m_CurrentFrame != TmpCurFrame) {
|
||||
ForceRefresh();
|
||||
|
||||
if (animationDescriptionPtr->GetFrame(m_CurrentFrame).Action != "")
|
||||
{
|
||||
|
||||
if (animationDescriptionPtr->GetFrame(m_CurrentFrame).Action != "") {
|
||||
// Action Callbacks
|
||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_ActionCallbacks.begin();
|
||||
while (it != m_ActionCallbacks.end())
|
||||
{
|
||||
while (it != m_ActionCallbacks.end()) {
|
||||
if (((*it).Callback)((*it).Data) == false)
|
||||
it = m_ActionCallbacks.erase(it);
|
||||
else
|
||||
|
@ -378,23 +347,22 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::ComputeCurrentCharacteristics()
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::ComputeCurrentCharacteristics() {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_ASSERT(pResource);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
|
||||
// Größe des Bitmaps auf die Animation übertragen
|
||||
m_Width = static_cast<int>(pBitmap->GetWidth() * m_ScaleFactorX);
|
||||
m_Height = static_cast<int>(pBitmap->GetHeight() * m_ScaleFactorY);
|
||||
|
||||
// Position anhand des Hotspots berechnen und setzen
|
||||
int PosX = m_RelX + ComputeXModifier();
|
||||
int PosX = m_RelX + ComputeXModifier();
|
||||
int PosY = m_RelY + ComputeYModifier();
|
||||
|
||||
BS_RenderObject::SetPos(PosX, PosY);
|
||||
|
@ -404,16 +372,12 @@ void BS_Animation::ComputeCurrentCharacteristics()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::LockAllFrames()
|
||||
{
|
||||
if (!m_FramesLocked)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::LockAllFrames() {
|
||||
if (!m_FramesLocked) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i)
|
||||
{
|
||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName))
|
||||
{
|
||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i) {
|
||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName)) {
|
||||
BS_LOG_ERRORLN("Could not lock all animation frames.");
|
||||
return false;
|
||||
}
|
||||
|
@ -427,17 +391,13 @@ bool BS_Animation::LockAllFrames()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::UnlockAllFrames()
|
||||
{
|
||||
if (m_FramesLocked)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::UnlockAllFrames() {
|
||||
if (m_FramesLocked) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i)
|
||||
{
|
||||
BS_Resource* pResource;
|
||||
if (!(pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName)))
|
||||
{
|
||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i) {
|
||||
BS_Resource *pResource;
|
||||
if (!(pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName))) {
|
||||
BS_LOG_ERRORLN("Could not unlock all animation frames.");
|
||||
return false;
|
||||
}
|
||||
|
@ -457,54 +417,48 @@ bool BS_Animation::UnlockAllFrames()
|
|||
// Getter
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Animation::ANIMATION_TYPES BS_Animation::GetAnimationType() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_Animation::ANIMATION_TYPES BS_Animation::GetAnimationType() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->GetAnimationType();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetFPS() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
int BS_Animation::GetFPS() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->GetFPS();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetFrameCount() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
int BS_Animation::GetFrameCount() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->GetFrameCount();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::IsScalingAllowed() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::IsScalingAllowed() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->IsScalingAllowed();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::IsAlphaAllowed() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::IsAlphaAllowed() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->IsAlphaAllowed();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::IsColorModulationAllowed() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
bool BS_Animation::IsColorModulationAllowed() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->IsColorModulationAllowed();
|
||||
}
|
||||
|
@ -513,8 +467,7 @@ bool BS_Animation::IsColorModulationAllowed() const
|
|||
// Positionieren
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetPos(int RelX, int RelY)
|
||||
{
|
||||
void BS_Animation::SetPos(int RelX, int RelY) {
|
||||
m_RelX = RelX;
|
||||
m_RelY = RelY;
|
||||
|
||||
|
@ -523,8 +476,7 @@ void BS_Animation::SetPos(int RelX, int RelY)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetX(int RelX)
|
||||
{
|
||||
void BS_Animation::SetX(int RelX) {
|
||||
m_RelX = RelX;
|
||||
|
||||
ComputeCurrentCharacteristics();
|
||||
|
@ -532,8 +484,7 @@ void BS_Animation::SetX(int RelX)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetY(int RelY)
|
||||
{
|
||||
void BS_Animation::SetY(int RelY) {
|
||||
m_RelY = RelY;
|
||||
|
||||
ComputeCurrentCharacteristics();
|
||||
|
@ -543,19 +494,16 @@ void BS_Animation::SetY(int RelY)
|
|||
// Darstellungsart festlegen
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetAlpha(int Alpha)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::SetAlpha(int Alpha) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
if (!animationDescriptionPtr->IsAlphaAllowed())
|
||||
{
|
||||
if (!animationDescriptionPtr->IsAlphaAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set alpha value on an animation that does not support alpha. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -563,19 +511,16 @@ void BS_Animation::SetAlpha(int Alpha)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetModulationColor(unsigned int ModulationColor)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::SetModulationColor(unsigned int ModulationColor) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
if (!animationDescriptionPtr->IsColorModulationAllowed())
|
||||
{
|
||||
if (!animationDescriptionPtr->IsColorModulationAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set modulation color on an animation that does not support color modulation. Call was ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -583,26 +528,22 @@ void BS_Animation::SetModulationColor(unsigned int ModulationColor)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetScaleFactor(float ScaleFactor)
|
||||
{
|
||||
void BS_Animation::SetScaleFactor(float ScaleFactor) {
|
||||
SetScaleFactorX(ScaleFactor);
|
||||
SetScaleFactorY(ScaleFactor);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetScaleFactorX(float ScaleFactorX)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::SetScaleFactorX(float ScaleFactorX) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
if (!animationDescriptionPtr->IsScalingAllowed())
|
||||
{
|
||||
if (!animationDescriptionPtr->IsScalingAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set x scale factor on an animation that does not support scaling. Call was ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorX != m_ScaleFactorX)
|
||||
{
|
||||
if (ScaleFactorX != m_ScaleFactorX) {
|
||||
m_ScaleFactorX = ScaleFactorX;
|
||||
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
||||
ForceRefresh();
|
||||
|
@ -612,18 +553,15 @@ void BS_Animation::SetScaleFactorX(float ScaleFactorX)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::SetScaleFactorY(float ScaleFactorY)
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
void BS_Animation::SetScaleFactorY(float ScaleFactorY) {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
if (!animationDescriptionPtr->IsScalingAllowed())
|
||||
{
|
||||
if (!animationDescriptionPtr->IsScalingAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set y scale factor on an animation that does not support scaling. Call was ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorY != m_ScaleFactorY)
|
||||
{
|
||||
if (ScaleFactorY != m_ScaleFactorY) {
|
||||
m_ScaleFactorY = ScaleFactorY;
|
||||
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
||||
ForceRefresh();
|
||||
|
@ -633,56 +571,50 @@ void BS_Animation::SetScaleFactorY(float ScaleFactorY)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const Common::String & BS_Animation::GetCurrentAction() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
const Common::String &BS_Animation::GetCurrentAction() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
return animationDescriptionPtr->GetFrame(m_CurrentFrame).Action;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetX() const
|
||||
{
|
||||
int BS_Animation::GetX() const {
|
||||
return m_RelX;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetY() const
|
||||
{
|
||||
int BS_Animation::GetY() const {
|
||||
return m_RelY;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetAbsoluteX() const
|
||||
{
|
||||
int BS_Animation::GetAbsoluteX() const {
|
||||
return m_AbsoluteX + (m_RelX - m_X);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::GetAbsoluteY() const
|
||||
{
|
||||
int BS_Animation::GetAbsoluteY() const {
|
||||
return m_AbsoluteY + (m_RelY - m_Y);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::ComputeXModifier() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
int BS_Animation::ComputeXModifier() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_ASSERT(pResource);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
|
||||
int Result = CurFrame.FlipV ? - static_cast<int>((pBitmap->GetWidth() - 1 - CurFrame.HotspotX) * m_ScaleFactorX) :
|
||||
- static_cast<int>(CurFrame.HotspotX * m_ScaleFactorX);
|
||||
- static_cast<int>(CurFrame.HotspotX * m_ScaleFactorX);
|
||||
|
||||
pBitmap->Release();
|
||||
|
||||
|
@ -691,19 +623,18 @@ int BS_Animation::ComputeXModifier() const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int BS_Animation::ComputeYModifier() const
|
||||
{
|
||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
||||
int BS_Animation::ComputeYModifier() const {
|
||||
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||
BS_ASSERT(animationDescriptionPtr);
|
||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||
BS_ASSERT(pResource);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||
|
||||
int Result = CurFrame.FlipH ? - static_cast<int>((pBitmap->GetHeight() - 1 - CurFrame.HotspotY) * m_ScaleFactorY) :
|
||||
- static_cast<int>(CurFrame.HotspotY * m_ScaleFactorY);
|
||||
- static_cast<int>(CurFrame.HotspotY * m_ScaleFactorY);
|
||||
|
||||
pBitmap->Release();
|
||||
|
||||
|
@ -712,8 +643,7 @@ int BS_Animation::ComputeYModifier() const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
||||
{
|
||||
void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||
ANIMATION_CALLBACK_DATA CD;
|
||||
CD.Callback = Callback;
|
||||
CD.Data = Data;
|
||||
|
@ -722,8 +652,7 @@ void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
||||
{
|
||||
void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||
ANIMATION_CALLBACK_DATA CD;
|
||||
CD.Callback = Callback;
|
||||
CD.Data = Data;
|
||||
|
@ -732,8 +661,7 @@ void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsign
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
||||
{
|
||||
void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||
ANIMATION_CALLBACK_DATA CD;
|
||||
CD.Callback = Callback;
|
||||
CD.Data = Data;
|
||||
|
@ -744,15 +672,13 @@ void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock & Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector)
|
||||
{
|
||||
void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock &Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector) {
|
||||
// Anzahl an Callbacks persistieren.
|
||||
Writer.Write(Vector.size());
|
||||
|
||||
|
||||
// Alle Callbacks einzeln persistieren.
|
||||
Common::Array<ANIMATION_CALLBACK_DATA>::const_iterator It = Vector.begin();
|
||||
while (It != Vector.end())
|
||||
{
|
||||
while (It != Vector.end()) {
|
||||
Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(It->Callback));
|
||||
Writer.Write(It->Data);
|
||||
|
||||
|
@ -762,8 +688,7 @@ void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock & Writer, con
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector)
|
||||
{
|
||||
void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock &Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector) {
|
||||
// Callbackvector leeren.
|
||||
Vector.resize(0);
|
||||
|
||||
|
@ -772,14 +697,13 @@ void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Co
|
|||
Reader.Read(CallbackCount);
|
||||
|
||||
// Alle Callbacks einzeln wieder herstellen.
|
||||
for (unsigned int i = 0; i < CallbackCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < CallbackCount; ++i) {
|
||||
ANIMATION_CALLBACK_DATA CallbackData;
|
||||
|
||||
Common::String CallbackFunctionName;
|
||||
Reader.Read(CallbackFunctionName);
|
||||
CallbackData.Callback = reinterpret_cast<ANIMATION_CALLBACK>(BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName));
|
||||
|
||||
|
||||
Reader.Read(CallbackData.Data);
|
||||
|
||||
Vector.push_back(CallbackData);
|
||||
|
@ -788,8 +712,7 @@ void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Co
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_Animation::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Persist(Writer);
|
||||
|
@ -806,20 +729,15 @@ bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
Writer.Write(static_cast<unsigned int>(m_Direction));
|
||||
|
||||
// Je nach Animationstyp entweder das Template oder die Ressource speichern.
|
||||
if (m_AnimationResourcePtr)
|
||||
{
|
||||
if (m_AnimationResourcePtr) {
|
||||
unsigned int Marker = 0;
|
||||
Writer.Write(Marker);
|
||||
Writer.Write(m_AnimationResourcePtr->GetFileName());
|
||||
}
|
||||
else if (m_AnimationTemplateHandle)
|
||||
{
|
||||
} else if (m_AnimationTemplateHandle) {
|
||||
unsigned int Marker = 1;
|
||||
Writer.Write(Marker);
|
||||
Writer.Write(m_AnimationTemplateHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BS_ASSERT(false);
|
||||
}
|
||||
|
||||
|
@ -837,8 +755,7 @@ bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_Animation::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Unpersist(Reader);
|
||||
|
@ -859,18 +776,13 @@ bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
// Animationstyp einlesen.
|
||||
unsigned int Marker;
|
||||
Reader.Read(Marker);
|
||||
if (Marker == 0)
|
||||
{
|
||||
if (Marker == 0) {
|
||||
Common::String ResourceFilename;
|
||||
Reader.Read(ResourceFilename);
|
||||
InitializeAnimationResource(ResourceFilename);
|
||||
}
|
||||
else if (Marker == 1)
|
||||
{
|
||||
} else if (Marker == 1) {
|
||||
Reader.Read(m_AnimationTemplateHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BS_ASSERT(false);
|
||||
}
|
||||
|
||||
|
@ -888,8 +800,7 @@ bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationDescription * BS_Animation::GetAnimationDescription() const
|
||||
{
|
||||
BS_AnimationDescription *BS_Animation::GetAnimationDescription() const {
|
||||
if (m_AnimationResourcePtr) return m_AnimationResourcePtr;
|
||||
else return BS_AnimationTemplateRegistry::GetInstance().ResolveHandle(m_AnimationTemplateHandle);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,23 +53,21 @@ class BS_AnimationTemplate;
|
|||
class BS_AnimationDescription;
|
||||
class BS_InputPersistenceBlock;
|
||||
|
||||
class BS_Animation : public BS_TimedRenderObject
|
||||
{
|
||||
friend class BS_RenderObject;
|
||||
class BS_Animation : public BS_TimedRenderObject {
|
||||
friend class BS_RenderObject;
|
||||
|
||||
private:
|
||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String & FileName);
|
||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate & Template);
|
||||
BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &FileName);
|
||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate &Template);
|
||||
BS_Animation(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
|
||||
public:
|
||||
enum ANIMATION_TYPES
|
||||
{
|
||||
enum ANIMATION_TYPES {
|
||||
AT_ONESHOT,
|
||||
AT_LOOP,
|
||||
AT_JOJO
|
||||
};
|
||||
|
||||
|
||||
virtual ~BS_Animation();
|
||||
|
||||
void Play();
|
||||
|
@ -80,44 +78,44 @@ public:
|
|||
virtual void SetPos(int X, int Y);
|
||||
virtual void SetX(int X);
|
||||
virtual void SetY(int Y);
|
||||
|
||||
|
||||
virtual int GetX() const;
|
||||
virtual int GetY() const;
|
||||
virtual int GetAbsoluteX() const;
|
||||
virtual int GetAbsoluteY() const;
|
||||
|
||||
/**
|
||||
@brief Setzt den Alphawert der Animation.
|
||||
@param Alpha der neue Alphawert der Animation (0 = keine Deckung, 255 = volle Deckung).
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
@brief Setzt den Alphawert der Animation.
|
||||
@param Alpha der neue Alphawert der Animation (0 = keine Deckung, 255 = volle Deckung).
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetAlpha(int Alpha);
|
||||
|
||||
/**
|
||||
@brief Setzt die Modulationfarbe der Animation.
|
||||
@param Color eine 24-Bit Farbe, die die Modulationsfarbe der Animation festlegt.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
@brief Setzt die Modulationfarbe der Animation.
|
||||
@param Color eine 24-Bit Farbe, die die Modulationsfarbe der Animation festlegt.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetModulationColor(unsigned int ModulationColor);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor der Animation.
|
||||
@param ScaleFactor der Faktor um den die Animation in beide Richtungen gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor der Animation.
|
||||
@param ScaleFactor der Faktor um den die Animation in beide Richtungen gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactor(float ScaleFactor);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor der Animation auf der X-Achse.
|
||||
@param ScaleFactor der Faktor um den die Animation in Richtungen der X-Achse gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor der Animation auf der X-Achse.
|
||||
@param ScaleFactor der Faktor um den die Animation in Richtungen der X-Achse gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactorX(float ScaleFactorX);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor der Animation auf der Y-Achse.
|
||||
@param ScaleFactor der Faktor um den die Animation in Richtungen der Y-Achse gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor der Animation auf der Y-Achse.
|
||||
@param ScaleFactor der Faktor um den die Animation in Richtungen der Y-Achse gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactorY(float ScaleFactorY);
|
||||
|
||||
|
@ -125,28 +123,36 @@ public:
|
|||
@brief Gibt den Skalierungsfakter der Animation auf der X-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
float GetScaleFactorX() const { return m_ScaleFactorX; }
|
||||
float GetScaleFactorX() const {
|
||||
return m_ScaleFactorX;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Skalierungsfakter der Animation auf der Y-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
float GetScaleFactorY() const { return m_ScaleFactorY; }
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
float GetScaleFactorY() const {
|
||||
return m_ScaleFactorY;
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
virtual void FrameNotification(int TimeElapsed);
|
||||
|
||||
ANIMATION_TYPES GetAnimationType() const;
|
||||
int GetFPS() const;
|
||||
int GetFrameCount() const;
|
||||
bool IsScalingAllowed() const;
|
||||
bool IsAlphaAllowed() const;
|
||||
bool IsColorModulationAllowed() const;
|
||||
unsigned int GetCurrentFrame() const { return m_CurrentFrame; }
|
||||
const Common::String & GetCurrentAction() const ;
|
||||
bool IsRunning() const { return m_Running; }
|
||||
|
||||
ANIMATION_TYPES GetAnimationType() const;
|
||||
int GetFPS() const;
|
||||
int GetFrameCount() const;
|
||||
bool IsScalingAllowed() const;
|
||||
bool IsAlphaAllowed() const;
|
||||
bool IsColorModulationAllowed() const;
|
||||
unsigned int GetCurrentFrame() const {
|
||||
return m_CurrentFrame;
|
||||
}
|
||||
const Common::String &GetCurrentAction() const ;
|
||||
bool IsRunning() const {
|
||||
return m_Running;
|
||||
}
|
||||
|
||||
typedef bool (*ANIMATION_CALLBACK)(unsigned int);
|
||||
|
||||
|
@ -158,68 +164,66 @@ protected:
|
|||
virtual bool DoRender();
|
||||
|
||||
private:
|
||||
enum DIRECTION
|
||||
{
|
||||
enum DIRECTION {
|
||||
FORWARD,
|
||||
BACKWARD
|
||||
};
|
||||
|
||||
int m_RelX;
|
||||
int m_RelY;
|
||||
float m_ScaleFactorX;
|
||||
float m_ScaleFactorY;
|
||||
unsigned int m_ModulationColor;
|
||||
unsigned int m_CurrentFrame;
|
||||
int m_CurrentFrameTime;
|
||||
bool m_Running;
|
||||
bool m_Finished;
|
||||
DIRECTION m_Direction;
|
||||
BS_AnimationResource * m_AnimationResourcePtr;
|
||||
unsigned int m_AnimationTemplateHandle;
|
||||
bool m_FramesLocked;
|
||||
int m_RelX;
|
||||
int m_RelY;
|
||||
float m_ScaleFactorX;
|
||||
float m_ScaleFactorY;
|
||||
unsigned int m_ModulationColor;
|
||||
unsigned int m_CurrentFrame;
|
||||
int m_CurrentFrameTime;
|
||||
bool m_Running;
|
||||
bool m_Finished;
|
||||
DIRECTION m_Direction;
|
||||
BS_AnimationResource *m_AnimationResourcePtr;
|
||||
unsigned int m_AnimationTemplateHandle;
|
||||
bool m_FramesLocked;
|
||||
|
||||
struct ANIMATION_CALLBACK_DATA
|
||||
{
|
||||
ANIMATION_CALLBACK Callback;
|
||||
unsigned int Data;
|
||||
struct ANIMATION_CALLBACK_DATA {
|
||||
ANIMATION_CALLBACK Callback;
|
||||
unsigned int Data;
|
||||
};
|
||||
Common::Array<ANIMATION_CALLBACK_DATA> m_LoopPointCallbacks;
|
||||
Common::Array<ANIMATION_CALLBACK_DATA> m_ActionCallbacks;
|
||||
Common::Array<ANIMATION_CALLBACK_DATA> m_DeleteCallbacks;
|
||||
|
||||
/**
|
||||
@brief Lockt alle Frames.
|
||||
@return Gibt false zurück, falls nicht alle Frames gelockt werden konnten.
|
||||
@brief Lockt alle Frames.
|
||||
@return Gibt false zurück, falls nicht alle Frames gelockt werden konnten.
|
||||
*/
|
||||
bool LockAllFrames();
|
||||
|
||||
/**
|
||||
@brief Unlockt alle Frames.
|
||||
@return Gibt false zurück, falls nicht alles Frames freigegeben werden konnten.
|
||||
@brief Unlockt alle Frames.
|
||||
@return Gibt false zurück, falls nicht alles Frames freigegeben werden konnten.
|
||||
*/
|
||||
bool UnlockAllFrames();
|
||||
|
||||
/**
|
||||
@brief Diese Methode aktualisiert die Parameter (Größe, Position) der Animation anhand des aktuellen Frames.
|
||||
@brief Diese Methode aktualisiert die Parameter (Größe, Position) der Animation anhand des aktuellen Frames.
|
||||
|
||||
Diese Methode muss bei jedem Framewechsel aufgerufen werden damit der RenderObject-Manager immer aktuelle Daten hat.
|
||||
Diese Methode muss bei jedem Framewechsel aufgerufen werden damit der RenderObject-Manager immer aktuelle Daten hat.
|
||||
*/
|
||||
void ComputeCurrentCharacteristics();
|
||||
|
||||
/**
|
||||
@brief Berechnet den Abstand zwischen dem linken Rand und dem Hotspot auf X-Achse in der aktuellen Darstellung.
|
||||
@brief Berechnet den Abstand zwischen dem linken Rand und dem Hotspot auf X-Achse in der aktuellen Darstellung.
|
||||
*/
|
||||
int ComputeXModifier() const;
|
||||
|
||||
/**
|
||||
@brief Berechnet den Abstand zwischen dem linken Rand und dem Hotspot auf X-Achse in der aktuellen Darstellung.
|
||||
@brief Berechnet den Abstand zwischen dem linken Rand und dem Hotspot auf X-Achse in der aktuellen Darstellung.
|
||||
*/
|
||||
int ComputeYModifier() const;
|
||||
|
||||
void InitMembers();
|
||||
void PersistCallbackVector(BS_OutputPersistenceBlock & Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||
void UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||
BS_AnimationDescription * GetAnimationDescription() const;
|
||||
void PersistCallbackVector(BS_OutputPersistenceBlock &Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||
void UnpersistCallbackVector(BS_InputPersistenceBlock &Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||
BS_AnimationDescription *GetAnimationDescription() const;
|
||||
void InitializeAnimationResource(const Common::String &FileName);
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -46,8 +46,7 @@ namespace Sword25 {
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
Writer.Write(static_cast<unsigned int>(m_AnimationType));
|
||||
Writer.Write(m_FPS);
|
||||
Writer.Write(m_MillisPerFrame);
|
||||
|
@ -60,8 +59,7 @@ bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationDescription::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_AnimationDescription::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
unsigned int AnimationType;
|
||||
Reader.Read(AnimationType);
|
||||
m_AnimationType = static_cast<BS_Animation::ANIMATION_TYPES>(AnimationType);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -49,8 +49,7 @@ namespace Sword25 {
|
|||
// Klassendefinition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_AnimationDescription : public BS_Persistable
|
||||
{
|
||||
class BS_AnimationDescription : public BS_Persistable {
|
||||
protected:
|
||||
BS_AnimationDescription() :
|
||||
m_AnimationType(BS_Animation::AT_LOOP),
|
||||
|
@ -62,46 +61,57 @@ protected:
|
|||
{};
|
||||
|
||||
public:
|
||||
struct Frame
|
||||
{
|
||||
struct Frame {
|
||||
// Die Hotspot-Angabe bezieht sich auf das ungeflippte Bild!!
|
||||
int HotspotX;
|
||||
int HotspotY;
|
||||
bool FlipV;
|
||||
bool FlipH;
|
||||
Common::String FileName;
|
||||
Common::String Action;
|
||||
int HotspotX;
|
||||
int HotspotY;
|
||||
bool FlipV;
|
||||
bool FlipH;
|
||||
Common::String FileName;
|
||||
Common::String Action;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Abstrakte Methoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
virtual const Frame & GetFrame(unsigned int Index) const = 0;
|
||||
virtual unsigned int GetFrameCount() const = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
virtual const Frame &GetFrame(unsigned int Index) const = 0;
|
||||
virtual unsigned int GetFrameCount() const = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Getter Methoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const { return m_AnimationType; }
|
||||
int GetFPS() const { return m_FPS; }
|
||||
int GetMillisPerFrame() const { return m_MillisPerFrame; }
|
||||
bool IsScalingAllowed() const { return m_ScalingAllowed; }
|
||||
bool IsAlphaAllowed() const { return m_AlphaAllowed; }
|
||||
bool IsColorModulationAllowed() const { return m_ColorModulationAllowed; }
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const {
|
||||
return m_AnimationType;
|
||||
}
|
||||
int GetFPS() const {
|
||||
return m_FPS;
|
||||
}
|
||||
int GetMillisPerFrame() const {
|
||||
return m_MillisPerFrame;
|
||||
}
|
||||
bool IsScalingAllowed() const {
|
||||
return m_ScalingAllowed;
|
||||
}
|
||||
bool IsAlphaAllowed() const {
|
||||
return m_AlphaAllowed;
|
||||
}
|
||||
bool IsColorModulationAllowed() const {
|
||||
return m_ColorModulationAllowed;
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
BS_Animation::ANIMATION_TYPES m_AnimationType;
|
||||
int m_FPS;
|
||||
int m_MillisPerFrame;
|
||||
bool m_ScalingAllowed;
|
||||
bool m_AlphaAllowed;
|
||||
bool m_ColorModulationAllowed;
|
||||
BS_Animation::ANIMATION_TYPES m_AnimationType;
|
||||
int m_FPS;
|
||||
int m_MillisPerFrame;
|
||||
bool m_ScalingAllowed;
|
||||
bool m_AlphaAllowed;
|
||||
bool m_ColorModulationAllowed;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,34 +54,31 @@ namespace Sword25 {
|
|||
// Constants
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
const int DEFAULT_FPS = 10;
|
||||
const int MIN_FPS = 1;
|
||||
const int MAX_FPS = 200;
|
||||
namespace {
|
||||
const int DEFAULT_FPS = 10;
|
||||
const int MIN_FPS = 1;
|
||||
const int MAX_FPS = 200;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Construction / Destruction
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||
BS_AnimationResource::BS_AnimationResource(const Common::String &FileName) :
|
||||
BS_Resource(FileName, BS_Resource::TYPE_ANIMATION),
|
||||
m_Valid(false)
|
||||
{
|
||||
m_Valid(false) {
|
||||
// Pointer auf den Package-Manager bekommen
|
||||
BS_PackageManager* PackagePtr = BS_Kernel::GetInstance()->GetPackage();
|
||||
BS_PackageManager *PackagePtr = BS_Kernel::GetInstance()->GetPackage();
|
||||
BS_ASSERT(PackagePtr);
|
||||
|
||||
// Animations-XML laden
|
||||
TiXmlDocument Doc;
|
||||
{
|
||||
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
|
||||
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
|
||||
// NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
||||
unsigned int FileSize;
|
||||
char * LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
|
||||
if (!LoadBuffer)
|
||||
{
|
||||
char *LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
|
||||
if (!LoadBuffer) {
|
||||
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -94,27 +91,24 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
|||
// Datei parsen
|
||||
Doc.Parse(&WorkBuffer[0]);
|
||||
free(WorkBuffer);
|
||||
if (Doc.Error())
|
||||
{
|
||||
if (Doc.Error()) {
|
||||
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Wurzelknoten des Animations-Tags finden, prüfen und Attribute auslesen.
|
||||
TiXmlElement* pElement;
|
||||
TiXmlElement *pElement;
|
||||
{
|
||||
TiXmlNode* pNode = Doc.FirstChild("animation");
|
||||
if (!pNode || pNode->Type() != TiXmlNode::ELEMENT)
|
||||
{
|
||||
TiXmlNode *pNode = Doc.FirstChild("animation");
|
||||
if (!pNode || pNode->Type() != TiXmlNode::ELEMENT) {
|
||||
BS_LOG_ERRORLN("No <animation> tag found in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
pElement = pNode->ToElement();
|
||||
|
||||
// Animation-Tag parsen
|
||||
if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType))
|
||||
{
|
||||
if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType)) {
|
||||
BS_LOG_ERRORLN("An error occurred while parsing <animation> tag in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -131,17 +125,15 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
|||
}
|
||||
|
||||
// Nacheinander alle Frames-Informationen erstellen.
|
||||
TiXmlElement* pFrameElement = pElement->FirstChild("frame")->ToElement();
|
||||
while (pFrameElement)
|
||||
{
|
||||
TiXmlElement *pFrameElement = pElement->FirstChild("frame")->ToElement();
|
||||
while (pFrameElement) {
|
||||
Frame CurFrame;
|
||||
|
||||
if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr))
|
||||
{
|
||||
|
||||
if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr)) {
|
||||
BS_LOG_ERRORLN("An error occurred in \"%s\" while parsing <frame> tag.", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_Frames.push_back(CurFrame);
|
||||
pFrameElement = pFrameElement->NextSiblingElement("frame");
|
||||
}
|
||||
|
@ -150,54 +142,46 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
|||
PackagePtr->ChangeDirectory(OldDirectory);
|
||||
|
||||
// Sicherstellen, dass die Animation mindestens einen Frame besitzt
|
||||
if (m_Frames.empty())
|
||||
{
|
||||
if (m_Frames.empty()) {
|
||||
BS_LOG_ERRORLN("\"%s\" does not have any frames.", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Alle Frame-Dateien werden vorgecached
|
||||
if (!PrecacheAllFrames())
|
||||
{
|
||||
if (!PrecacheAllFrames()) {
|
||||
BS_LOG_ERRORLN("Could not precache all frames of \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Feststellen, ob die Animation skalierbar ist
|
||||
if (!ComputeFeatures())
|
||||
{
|
||||
BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
if (!ComputeFeatures()) {
|
||||
BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
m_Valid = true;
|
||||
m_Valid = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Dokument-Parsermethoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FPS, BS_Animation::ANIMATION_TYPES & AnimationType)
|
||||
{
|
||||
bool BS_AnimationResource::ParseAnimationTag(TiXmlElement &AnimationTag, int &FPS, BS_Animation::ANIMATION_TYPES &AnimationType) {
|
||||
// FPS einlesen
|
||||
const char* FPSString;
|
||||
if (FPSString = AnimationTag.Attribute("fps"))
|
||||
{
|
||||
const char *FPSString;
|
||||
if (FPSString = AnimationTag.Attribute("fps")) {
|
||||
int TempFPS;
|
||||
if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS)
|
||||
{
|
||||
if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS) {
|
||||
BS_LOG_WARNINGLN("Illegal fps value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"%d\"). "
|
||||
"The fps value has to be between %d and %d.",
|
||||
FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
|
||||
}
|
||||
else
|
||||
"The fps value has to be between %d and %d.",
|
||||
FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
|
||||
} else
|
||||
FPS = TempFPS;
|
||||
}
|
||||
|
||||
// Loop-Typ einlesen
|
||||
const char* LoopTypeString;
|
||||
if (LoopTypeString = AnimationTag.Attribute("type"))
|
||||
{
|
||||
const char *LoopTypeString;
|
||||
if (LoopTypeString = AnimationTag.Attribute("type")) {
|
||||
if (strcmp(LoopTypeString, "oneshot") == 0)
|
||||
AnimationType = BS_Animation::AT_ONESHOT;
|
||||
else if (strcmp(LoopTypeString, "loop") == 0)
|
||||
|
@ -206,7 +190,7 @@ bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FP
|
|||
AnimationType = BS_Animation::AT_JOJO;
|
||||
else
|
||||
BS_LOG_WARNINGLN("Illegal type value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"loop\").",
|
||||
LoopTypeString, GetFileName().c_str());
|
||||
LoopTypeString, GetFileName().c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -214,68 +198,59 @@ bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FP
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_, BS_PackageManager& PackageManager)
|
||||
{
|
||||
const char* FileString = FrameTag.Attribute("file");
|
||||
if (!FileString)
|
||||
{
|
||||
bool BS_AnimationResource::ParseFrameTag(TiXmlElement &FrameTag, Frame &Frame_, BS_PackageManager &PackageManager) {
|
||||
const char *FileString = FrameTag.Attribute("file");
|
||||
if (!FileString) {
|
||||
BS_LOG_ERRORLN("<frame> tag without file attribute occurred in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
Frame_.FileName = PackageManager.GetAbsolutePath(FileString);
|
||||
if (Frame_.FileName == "")
|
||||
{
|
||||
if (Frame_.FileName == "") {
|
||||
BS_LOG_ERRORLN("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", GetFileName().c_str(), FileString);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* ActionString = FrameTag.Attribute("action");
|
||||
const char *ActionString = FrameTag.Attribute("action");
|
||||
if (ActionString)
|
||||
Frame_.Action = ActionString;
|
||||
|
||||
const char* HotspotxString = FrameTag.Attribute("hotspotx");
|
||||
const char* HotspotyString = FrameTag.Attribute("hotspoty");
|
||||
const char *HotspotxString = FrameTag.Attribute("hotspotx");
|
||||
const char *HotspotyString = FrameTag.Attribute("hotspoty");
|
||||
if ((!HotspotxString && HotspotyString) ||
|
||||
(HotspotxString && !HotspotyString))
|
||||
(HotspotxString && !HotspotyString))
|
||||
BS_LOG_WARNINGLN("%s attribute occurred without %s attribute in <frame> tag in \"%s\". Assuming default (\"0\").",
|
||||
HotspotxString ? "hotspotx" : "hotspoty",
|
||||
!HotspotyString ? "hotspoty" : "hotspotx",
|
||||
GetFileName().c_str());
|
||||
HotspotxString ? "hotspotx" : "hotspoty",
|
||||
!HotspotyString ? "hotspoty" : "hotspotx",
|
||||
GetFileName().c_str());
|
||||
|
||||
Frame_.HotspotX = 0;
|
||||
if (HotspotxString && !BS_String::ToInt(Common::String(HotspotxString), Frame_.HotspotX))
|
||||
BS_LOG_WARNINGLN("Illegal hotspotx value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
||||
HotspotxString,GetFileName().c_str(), Frame_.HotspotX);
|
||||
HotspotxString, GetFileName().c_str(), Frame_.HotspotX);
|
||||
|
||||
Frame_.HotspotY = 0;
|
||||
if (HotspotyString && !BS_String::ToInt(Common::String(HotspotyString), Frame_.HotspotY))
|
||||
BS_LOG_WARNINGLN("Illegal hotspoty value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
||||
HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
|
||||
HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
|
||||
|
||||
const char* FlipVString = FrameTag.Attribute("flipv");
|
||||
if (FlipVString)
|
||||
{
|
||||
if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV))
|
||||
{
|
||||
const char *FlipVString = FrameTag.Attribute("flipv");
|
||||
if (FlipVString) {
|
||||
if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV)) {
|
||||
BS_LOG_WARNINGLN("Illegal flipv value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
||||
FlipVString, GetFileName().c_str());
|
||||
FlipVString, GetFileName().c_str());
|
||||
Frame_.FlipV = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
Frame_.FlipV = false;
|
||||
|
||||
const char* FlipHString = FrameTag.Attribute("fliph");
|
||||
if (FlipHString)
|
||||
{
|
||||
if (!BS_String::ToBool(FlipHString, Frame_.FlipH))
|
||||
{
|
||||
const char *FlipHString = FrameTag.Attribute("fliph");
|
||||
if (FlipHString) {
|
||||
if (!BS_String::ToBool(FlipHString, Frame_.FlipH)) {
|
||||
BS_LOG_WARNINGLN("Illegal fliph value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
||||
FlipHString, GetFileName().c_str());
|
||||
FlipHString, GetFileName().c_str());
|
||||
Frame_.FlipH = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
Frame_.FlipH = false;
|
||||
|
||||
return true;
|
||||
|
@ -283,19 +258,15 @@ bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_,
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationResource::~BS_AnimationResource()
|
||||
{
|
||||
BS_AnimationResource::~BS_AnimationResource() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationResource::PrecacheAllFrames() const
|
||||
{
|
||||
bool BS_AnimationResource::PrecacheAllFrames() const {
|
||||
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
||||
for (; Iter != m_Frames.end(); ++Iter)
|
||||
{
|
||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName))
|
||||
{
|
||||
for (; Iter != m_Frames.end(); ++Iter) {
|
||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName)) {
|
||||
BS_LOG_ERRORLN("Could not precache \"%s\".", (*Iter).FileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -306,8 +277,7 @@ bool BS_AnimationResource::PrecacheAllFrames() const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationResource::ComputeFeatures()
|
||||
{
|
||||
bool BS_AnimationResource::ComputeFeatures() {
|
||||
BS_ASSERT(m_Frames.size());
|
||||
|
||||
// Alle Features werden als vorhanden angenommen
|
||||
|
@ -317,11 +287,9 @@ bool BS_AnimationResource::ComputeFeatures()
|
|||
|
||||
// Alle Frame durchgehen und alle Features deaktivieren, die auch nur von einem Frame nicht unterstützt werden.
|
||||
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
||||
for (; Iter != m_Frames.end(); ++Iter)
|
||||
{
|
||||
BS_BitmapResource* pBitmap;
|
||||
if (!(pBitmap = static_cast<BS_BitmapResource*> (BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName))))
|
||||
{
|
||||
for (; Iter != m_Frames.end(); ++Iter) {
|
||||
BS_BitmapResource *pBitmap;
|
||||
if (!(pBitmap = static_cast<BS_BitmapResource *>(BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName)))) {
|
||||
BS_LOG_ERRORLN("Could not request \"%s\".", (*Iter).FileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -63,34 +63,54 @@ class BS_PackageManager;
|
|||
// Class Definition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_AnimationResource : public BS_Resource, public BS_AnimationDescription
|
||||
{
|
||||
class BS_AnimationResource : public BS_Resource, public BS_AnimationDescription {
|
||||
public:
|
||||
BS_AnimationResource(const Common::String & FileName);
|
||||
BS_AnimationResource(const Common::String &FileName);
|
||||
virtual ~BS_AnimationResource();
|
||||
|
||||
virtual const Frame & GetFrame(unsigned int Index) const { BS_ASSERT(Index < m_Frames.size()); return m_Frames[Index]; }
|
||||
virtual unsigned int GetFrameCount() const { return m_Frames.size(); }
|
||||
virtual void Unlock() { Release(); }
|
||||
virtual const Frame &GetFrame(unsigned int Index) const {
|
||||
BS_ASSERT(Index < m_Frames.size());
|
||||
return m_Frames[Index];
|
||||
}
|
||||
virtual unsigned int GetFrameCount() const {
|
||||
return m_Frames.size();
|
||||
}
|
||||
virtual void Unlock() {
|
||||
Release();
|
||||
}
|
||||
|
||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const { return m_AnimationType; }
|
||||
int GetFPS() const { return m_FPS; }
|
||||
int GetMillisPerFrame() const { return m_MillisPerFrame; }
|
||||
bool IsScalingAllowed() const { return m_ScalingAllowed; }
|
||||
bool IsAlphaAllowed() const { return m_AlphaAllowed; }
|
||||
bool IsColorModulationAllowed() const { return m_ColorModulationAllowed; }
|
||||
bool IsValid() const { return m_Valid; }
|
||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const {
|
||||
return m_AnimationType;
|
||||
}
|
||||
int GetFPS() const {
|
||||
return m_FPS;
|
||||
}
|
||||
int GetMillisPerFrame() const {
|
||||
return m_MillisPerFrame;
|
||||
}
|
||||
bool IsScalingAllowed() const {
|
||||
return m_ScalingAllowed;
|
||||
}
|
||||
bool IsAlphaAllowed() const {
|
||||
return m_AlphaAllowed;
|
||||
}
|
||||
bool IsColorModulationAllowed() const {
|
||||
return m_ColorModulationAllowed;
|
||||
}
|
||||
bool IsValid() const {
|
||||
return m_Valid;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_Valid;
|
||||
bool m_Valid;
|
||||
|
||||
Common::Array<Frame> m_Frames;
|
||||
Common::Array<Frame> m_Frames;
|
||||
|
||||
//@{
|
||||
/** @name Dokument-Parser Methoden */
|
||||
|
||||
bool ParseAnimationTag(TiXmlElement& AnimationTag, int& FPS, BS_Animation::ANIMATION_TYPES & AnimationType);
|
||||
bool ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame, BS_PackageManager& PackageManager);
|
||||
bool ParseAnimationTag(TiXmlElement &AnimationTag, int &FPS, BS_Animation::ANIMATION_TYPES &AnimationType);
|
||||
bool ParseFrameTag(TiXmlElement &FrameTag, Frame &Frame, BS_PackageManager &PackageManager);
|
||||
|
||||
//@}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,16 +53,12 @@ namespace Sword25 {
|
|||
// Konstruktion / Destruktion
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_AnimationTemplate::Create(const Common::String & SourceAnimation)
|
||||
{
|
||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(SourceAnimation);
|
||||
unsigned int BS_AnimationTemplate::Create(const Common::String &SourceAnimation) {
|
||||
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(SourceAnimation);
|
||||
|
||||
if (AnimationTemplatePtr->IsValid())
|
||||
{
|
||||
if (AnimationTemplatePtr->IsValid()) {
|
||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
delete AnimationTemplatePtr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -70,16 +66,12 @@ unsigned int BS_AnimationTemplate::Create(const Common::String & SourceAnimation
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate & Other)
|
||||
{
|
||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(Other);
|
||||
unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate &Other) {
|
||||
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(Other);
|
||||
|
||||
if (AnimationTemplatePtr->IsValid())
|
||||
{
|
||||
if (AnimationTemplatePtr->IsValid()) {
|
||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
delete AnimationTemplatePtr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,16 +79,12 @@ unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate & Other)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock & Reader, unsigned int Handle)
|
||||
{
|
||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(Reader, Handle);
|
||||
unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
|
||||
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(Reader, Handle);
|
||||
|
||||
if (AnimationTemplatePtr->IsValid())
|
||||
{
|
||||
if (AnimationTemplatePtr->IsValid()) {
|
||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
delete AnimationTemplatePtr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -104,8 +92,7 @@ unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock & Reader, uns
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(const Common::String & SourceAnimation)
|
||||
{
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(const Common::String &SourceAnimation) {
|
||||
// Objekt registrieren.
|
||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
||||
|
||||
|
@ -120,8 +107,7 @@ BS_AnimationTemplate::BS_AnimationTemplate(const Common::String & SourceAnimatio
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate & Other)
|
||||
{
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate &Other) {
|
||||
// Objekt registrieren.
|
||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
||||
|
||||
|
@ -147,23 +133,20 @@ BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate & Other)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(BS_InputPersistenceBlock & Reader, unsigned int Handle)
|
||||
{
|
||||
BS_AnimationTemplate::BS_AnimationTemplate(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
|
||||
// Objekt registrieren.
|
||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this, Handle);
|
||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this, Handle);
|
||||
|
||||
// Objekt laden.
|
||||
m_Valid = Unpersist(Reader);
|
||||
m_Valid = Unpersist(Reader);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationResource * BS_AnimationTemplate::RequestSourceAnimation(const Common::String & SourceAnimation) const
|
||||
{
|
||||
BS_ResourceManager * RMPtr = BS_Kernel::GetInstance()->GetResourceManager();
|
||||
BS_Resource * ResourcePtr;
|
||||
if (NULL == (ResourcePtr = RMPtr->RequestResource(SourceAnimation)) || ResourcePtr->GetType() != BS_Resource::TYPE_ANIMATION)
|
||||
{
|
||||
BS_AnimationResource *BS_AnimationTemplate::RequestSourceAnimation(const Common::String &SourceAnimation) const {
|
||||
BS_ResourceManager *RMPtr = BS_Kernel::GetInstance()->GetResourceManager();
|
||||
BS_Resource *ResourcePtr;
|
||||
if (NULL == (ResourcePtr = RMPtr->RequestResource(SourceAnimation)) || ResourcePtr->GetType() != BS_Resource::TYPE_ANIMATION) {
|
||||
BS_LOG_ERRORLN("The resource \"%s\" could not be requested or is has an invalid type. The animation template can't be created.", SourceAnimation.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
@ -172,11 +155,9 @@ BS_AnimationResource * BS_AnimationTemplate::RequestSourceAnimation(const Common
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_AnimationTemplate::~BS_AnimationTemplate()
|
||||
{
|
||||
BS_AnimationTemplate::~BS_AnimationTemplate() {
|
||||
// Animations-Resource freigeben
|
||||
if (m_SourceAnimationPtr)
|
||||
{
|
||||
if (m_SourceAnimationPtr) {
|
||||
m_SourceAnimationPtr->Release();
|
||||
}
|
||||
|
||||
|
@ -186,64 +167,52 @@ BS_AnimationTemplate::~BS_AnimationTemplate()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_AnimationTemplate::AddFrame(int Index)
|
||||
{
|
||||
if (ValidateSourceIndex(Index))
|
||||
{
|
||||
void BS_AnimationTemplate::AddFrame(int Index) {
|
||||
if (ValidateSourceIndex(Index)) {
|
||||
m_Frames.push_back(m_SourceAnimationPtr->GetFrame(Index));
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_AnimationTemplate::SetFrame(int DestIndex, int SrcIndex)
|
||||
{
|
||||
if (ValidateDestIndex(DestIndex) && ValidateSourceIndex(SrcIndex))
|
||||
{
|
||||
void BS_AnimationTemplate::SetFrame(int DestIndex, int SrcIndex) {
|
||||
if (ValidateDestIndex(DestIndex) && ValidateSourceIndex(SrcIndex)) {
|
||||
m_Frames[DestIndex] = m_SourceAnimationPtr->GetFrame(SrcIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplate::ValidateSourceIndex(unsigned int Index) const
|
||||
{
|
||||
if (Index > m_SourceAnimationPtr->GetFrameCount())
|
||||
{
|
||||
bool BS_AnimationTemplate::ValidateSourceIndex(unsigned int Index) const {
|
||||
if (Index > m_SourceAnimationPtr->GetFrameCount()) {
|
||||
BS_LOG_WARNINGLN("Tried to insert a frame (\"%d\") that does not exist in the source animation (\"%s\"). Ignoring call.",
|
||||
Index, m_SourceAnimationPtr->GetFileName().c_str());
|
||||
Index, m_SourceAnimationPtr->GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplate::ValidateDestIndex(unsigned int Index) const
|
||||
{
|
||||
if (Index > m_Frames.size())
|
||||
{
|
||||
bool BS_AnimationTemplate::ValidateDestIndex(unsigned int Index) const {
|
||||
if (Index > m_Frames.size()) {
|
||||
BS_LOG_WARNINGLN("Tried to change a nonexistent frame (\"%d\") in a template animation. Ignoring call.",
|
||||
Index);
|
||||
Index);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_AnimationTemplate::SetFPS(int FPS)
|
||||
{
|
||||
void BS_AnimationTemplate::SetFPS(int FPS) {
|
||||
m_FPS = FPS;
|
||||
m_MillisPerFrame = 1000000 / m_FPS;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
// Parent persistieren.
|
||||
|
@ -254,8 +223,7 @@ bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// Frames einzeln persistieren.
|
||||
Common::Array<const Frame>::const_iterator Iter = m_Frames.begin();
|
||||
while (Iter != m_Frames.end())
|
||||
{
|
||||
while (Iter != m_Frames.end()) {
|
||||
Writer.Write(Iter->HotspotX);
|
||||
Writer.Write(Iter->HotspotY);
|
||||
Writer.Write(Iter->FlipV);
|
||||
|
@ -274,8 +242,7 @@ bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
// Parent wieder herstellen.
|
||||
|
@ -286,8 +253,7 @@ bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
Reader.Read(FrameCount);
|
||||
|
||||
// Frames einzeln wieder herstellen.
|
||||
for (unsigned int i = 0; i < FrameCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < FrameCount; ++i) {
|
||||
Frame frame;
|
||||
Reader.Read(frame.HotspotX);
|
||||
Reader.Read(frame.HotspotY);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -59,65 +59,75 @@ class BS_AnimationResource;
|
|||
// Klassendefinition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_AnimationTemplate : public BS_AnimationDescription
|
||||
{
|
||||
class BS_AnimationTemplate : public BS_AnimationDescription {
|
||||
public:
|
||||
static unsigned int Create(const Common::String & SourceAnimation);
|
||||
static unsigned int Create(const BS_AnimationTemplate & Other);
|
||||
static unsigned int Create(BS_InputPersistenceBlock & Reader, unsigned int Handle);
|
||||
BS_AnimationTemplate * ResolveHandle(unsigned int Handle) const;
|
||||
static unsigned int Create(const Common::String &SourceAnimation);
|
||||
static unsigned int Create(const BS_AnimationTemplate &Other);
|
||||
static unsigned int Create(BS_InputPersistenceBlock &Reader, unsigned int Handle);
|
||||
BS_AnimationTemplate *ResolveHandle(unsigned int Handle) const;
|
||||
|
||||
private:
|
||||
BS_AnimationTemplate(const Common::String & SourceAnimation);
|
||||
BS_AnimationTemplate(const BS_AnimationTemplate & Other);
|
||||
BS_AnimationTemplate(BS_InputPersistenceBlock & Reader, unsigned int Handle);
|
||||
BS_AnimationTemplate(const Common::String &SourceAnimation);
|
||||
BS_AnimationTemplate(const BS_AnimationTemplate &Other);
|
||||
BS_AnimationTemplate(BS_InputPersistenceBlock &Reader, unsigned int Handle);
|
||||
|
||||
public:
|
||||
~BS_AnimationTemplate();
|
||||
|
||||
virtual const Frame & GetFrame(unsigned int Index) const { BS_ASSERT(Index < m_Frames.size()); return m_Frames[Index]; }
|
||||
virtual unsigned int GetFrameCount() const { return m_Frames.size(); }
|
||||
virtual void Unlock() { delete this; }
|
||||
virtual const Frame &GetFrame(unsigned int Index) const {
|
||||
BS_ASSERT(Index < m_Frames.size());
|
||||
return m_Frames[Index];
|
||||
}
|
||||
virtual unsigned int GetFrameCount() const {
|
||||
return m_Frames.size();
|
||||
}
|
||||
virtual void Unlock() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
bool IsValid() const { return m_Valid; }
|
||||
bool IsValid() const {
|
||||
return m_Valid;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Fügt einen neuen Frame zur Animation hinzu.
|
||||
@brief Fügt einen neuen Frame zur Animation hinzu.
|
||||
|
||||
Der Frame wird an das Ende der Animation angehängt.
|
||||
Der Frame wird an das Ende der Animation angehängt.
|
||||
|
||||
@param Index der Index des Frames in der Quellanimation
|
||||
@param Index der Index des Frames in der Quellanimation
|
||||
*/
|
||||
void AddFrame(int Index);
|
||||
|
||||
/**
|
||||
@brief Ändert einen bereits in der Animation vorhandenen Frame.
|
||||
@param DestIndex der Index des Frames der überschrieben werden soll
|
||||
@param SrcIndex der Index des einzufügenden Frames in der Quellanimation
|
||||
@brief Ändert einen bereits in der Animation vorhandenen Frame.
|
||||
@param DestIndex der Index des Frames der überschrieben werden soll
|
||||
@param SrcIndex der Index des einzufügenden Frames in der Quellanimation
|
||||
*/
|
||||
void SetFrame(int DestIndex, int SrcIndex);
|
||||
|
||||
/**
|
||||
@brief Setzt den Animationstyp.
|
||||
@param Type der Typ der Animation. Muss aus den enum BS_Animation::ANIMATION_TYPES sein.
|
||||
@brief Setzt den Animationstyp.
|
||||
@param Type der Typ der Animation. Muss aus den enum BS_Animation::ANIMATION_TYPES sein.
|
||||
*/
|
||||
void SetAnimationType(BS_Animation::ANIMATION_TYPES Type) { m_AnimationType = Type; }
|
||||
void SetAnimationType(BS_Animation::ANIMATION_TYPES Type) {
|
||||
m_AnimationType = Type;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Setzt die Abspielgeschwindigkeit.
|
||||
@param FPS die Abspielgeschwindigkeit in Frames pro Sekunde.
|
||||
@brief Setzt die Abspielgeschwindigkeit.
|
||||
@param FPS die Abspielgeschwindigkeit in Frames pro Sekunde.
|
||||
*/
|
||||
void SetFPS(int FPS);
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
private:
|
||||
Common::Array<const Frame> m_Frames;
|
||||
BS_AnimationResource * m_SourceAnimationPtr;
|
||||
bool m_Valid;
|
||||
Common::Array<const Frame> m_Frames;
|
||||
BS_AnimationResource *m_SourceAnimationPtr;
|
||||
bool m_Valid;
|
||||
|
||||
BS_AnimationResource * RequestSourceAnimation(const Common::String & SourceAnimation) const;
|
||||
BS_AnimationResource *RequestSourceAnimation(const Common::String &SourceAnimation) const;
|
||||
bool ValidateSourceIndex(unsigned int Index) const;
|
||||
bool ValidateDestIndex(unsigned int Index) const;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -57,22 +57,19 @@ std::auto_ptr<BS_AnimationTemplateRegistry> BS_AnimationTemplateRegistry::m_Inst
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_AnimationTemplateRegistry::LogErrorLn(const char * Message) const
|
||||
{
|
||||
void BS_AnimationTemplateRegistry::LogErrorLn(const char *Message) const {
|
||||
BS_LOG_ERRORLN(Message);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_AnimationTemplateRegistry::LogWarningLn(const char * Message) const
|
||||
{
|
||||
void BS_AnimationTemplateRegistry::LogWarningLn(const char *Message) const {
|
||||
BS_LOG_WARNINGLN(Message);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
// Das nächste zu vergebene Handle schreiben.
|
||||
|
@ -83,8 +80,7 @@ bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// Alle BS_AnimationTemplates persistieren.
|
||||
HANDLE2PTR_MAP::const_iterator Iter = m_Handle2PtrMap.begin();
|
||||
while (Iter != m_Handle2PtrMap.end())
|
||||
{
|
||||
while (Iter != m_Handle2PtrMap.end()) {
|
||||
// Handle persistieren.
|
||||
Writer.Write(Iter->first);
|
||||
|
||||
|
@ -99,8 +95,7 @@ bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
// Das nächste zu vergebene Handle wieder herstellen.
|
||||
|
@ -114,8 +109,7 @@ bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
Reader.Read(AnimationTemplateCount);
|
||||
|
||||
// Alle gespeicherten BS_AnimationTemplates wieder herstellen.
|
||||
for (unsigned int i = 0; i < AnimationTemplateCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < AnimationTemplateCount; ++i) {
|
||||
// Handle lesen.
|
||||
unsigned int Handle;
|
||||
Reader.Read(Handle);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -59,21 +59,19 @@ class BS_AnimationTemplate;
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_AnimationTemplateRegistry : public BS_ObjectRegistry<BS_AnimationTemplate>, public BS_Persistable
|
||||
{
|
||||
class BS_AnimationTemplateRegistry : public BS_ObjectRegistry<BS_AnimationTemplate>, public BS_Persistable {
|
||||
public:
|
||||
static BS_AnimationTemplateRegistry & GetInstance()
|
||||
{
|
||||
static BS_AnimationTemplateRegistry &GetInstance() {
|
||||
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_AnimationTemplateRegistry);
|
||||
return *m_InstancePtr.get();
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
private:
|
||||
virtual void LogErrorLn(const char * Message) const;
|
||||
virtual void LogWarningLn(const char * Message) const;
|
||||
virtual void LogErrorLn(const char *Message) const;
|
||||
virtual void LogWarningLn(const char *Message) const;
|
||||
|
||||
static std::auto_ptr<BS_AnimationTemplateRegistry> m_InstancePtr;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -58,41 +58,35 @@ BS_Bitmap::BS_Bitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, TYPES Type,
|
|||
m_ScaleFactorX(1.0f),
|
||||
m_ScaleFactorY(1.0f),
|
||||
m_FlipH(false),
|
||||
m_FlipV(false)
|
||||
{
|
||||
m_FlipV(false) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Bitmap::~BS_Bitmap()
|
||||
{
|
||||
BS_Bitmap::~BS_Bitmap() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Darstellungsart festlegen
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetAlpha(int Alpha)
|
||||
{
|
||||
if (!IsAlphaAllowed())
|
||||
{
|
||||
void BS_Bitmap::SetAlpha(int Alpha) {
|
||||
if (!IsAlphaAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set alpha value on a bitmap that does not support alpha blending. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Alpha < 0 || Alpha > 255)
|
||||
{
|
||||
if (Alpha < 0 || Alpha > 255) {
|
||||
int OldAlpha = Alpha;
|
||||
if (Alpha < 0) Alpha = 0;
|
||||
if (Alpha > 255) Alpha = 255;
|
||||
BS_LOG_WARNINGLN("Tried to set an invalid alpha value (%d) on a bitmap. Value was changed to %d.", OldAlpha, Alpha);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -100,17 +94,14 @@ void BS_Bitmap::SetAlpha(int Alpha)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetModulationColor(unsigned int ModulationColor)
|
||||
{
|
||||
if (!IsColorModulationAllowed())
|
||||
{
|
||||
void BS_Bitmap::SetModulationColor(unsigned int ModulationColor) {
|
||||
if (!IsColorModulationAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set modulation color of a bitmap that does not support color modulation. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -118,30 +109,25 @@ void BS_Bitmap::SetModulationColor(unsigned int ModulationColor)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetScaleFactor(float ScaleFactor)
|
||||
{
|
||||
void BS_Bitmap::SetScaleFactor(float ScaleFactor) {
|
||||
SetScaleFactorX(ScaleFactor);
|
||||
SetScaleFactorY(ScaleFactor);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetScaleFactorX(float ScaleFactorX)
|
||||
{
|
||||
if (!IsScalingAllowed())
|
||||
{
|
||||
void BS_Bitmap::SetScaleFactorX(float ScaleFactorX) {
|
||||
if (!IsScalingAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorX < 0)
|
||||
{
|
||||
if (ScaleFactorX < 0) {
|
||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorX != m_ScaleFactorX)
|
||||
{
|
||||
if (ScaleFactorX != m_ScaleFactorX) {
|
||||
m_ScaleFactorX = ScaleFactorX;
|
||||
m_Width = static_cast<int>(m_OriginalWidth * m_ScaleFactorX);
|
||||
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
||||
|
@ -151,22 +137,18 @@ void BS_Bitmap::SetScaleFactorX(float ScaleFactorX)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetScaleFactorY(float ScaleFactorY)
|
||||
{
|
||||
if (!IsScalingAllowed())
|
||||
{
|
||||
void BS_Bitmap::SetScaleFactorY(float ScaleFactorY) {
|
||||
if (!IsScalingAllowed()) {
|
||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorY < 0)
|
||||
{
|
||||
if (ScaleFactorY < 0) {
|
||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ScaleFactorY != m_ScaleFactorY)
|
||||
{
|
||||
if (ScaleFactorY != m_ScaleFactorY) {
|
||||
m_ScaleFactorY = ScaleFactorY;
|
||||
m_Height = static_cast<int>(m_OriginalHeight * ScaleFactorY);
|
||||
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
||||
|
@ -176,16 +158,14 @@ void BS_Bitmap::SetScaleFactorY(float ScaleFactorY)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetFlipH(bool FlipH)
|
||||
{
|
||||
void BS_Bitmap::SetFlipH(bool FlipH) {
|
||||
m_FlipH = FlipH;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Bitmap::SetFlipV(bool FlipV)
|
||||
{
|
||||
void BS_Bitmap::SetFlipV(bool FlipV) {
|
||||
m_FlipV = FlipV;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -194,8 +174,7 @@ void BS_Bitmap::SetFlipV(bool FlipV)
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Bitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_Bitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Persist(Writer);
|
||||
|
@ -212,8 +191,7 @@ bool BS_Bitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Bitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_Bitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,8 +48,7 @@ namespace Sword25 {
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_Bitmap : public BS_RenderObject
|
||||
{
|
||||
class BS_Bitmap : public BS_RenderObject {
|
||||
protected:
|
||||
BS_Bitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, TYPES Type, unsigned int Handle = 0);
|
||||
|
||||
|
@ -58,127 +57,139 @@ public:
|
|||
virtual ~BS_Bitmap();
|
||||
|
||||
/**
|
||||
@brief Setzt den Alphawert des Bitmaps.
|
||||
@param Alpha der neue Alphawert der Bitmaps (0 = keine Deckung, 255 = volle Deckung).
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
@brief Setzt den Alphawert des Bitmaps.
|
||||
@param Alpha der neue Alphawert der Bitmaps (0 = keine Deckung, 255 = volle Deckung).
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetAlpha(int Alpha);
|
||||
|
||||
/**
|
||||
@brief Setzt die Modulationfarbe der Bitmaps.
|
||||
@param Color eine 24-Bit Farbe, die die Modulationsfarbe des Bitmaps festlegt.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
@brief Setzt die Modulationfarbe der Bitmaps.
|
||||
@param Color eine 24-Bit Farbe, die die Modulationsfarbe des Bitmaps festlegt.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetModulationColor(unsigned int ModulationColor);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor des Bitmaps.
|
||||
@param ScaleFactor der Faktor um den das Bitmap in beide Richtungen gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor des Bitmaps.
|
||||
@param ScaleFactor der Faktor um den das Bitmap in beide Richtungen gestreckt werden soll.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactor(float ScaleFactor);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor der Bitmap auf der X-Achse.
|
||||
@param ScaleFactor der Faktor um den die Bitmap in Richtungen der X-Achse gestreckt werden soll. Dieser Wert muss positiv sein.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor der Bitmap auf der X-Achse.
|
||||
@param ScaleFactor der Faktor um den die Bitmap in Richtungen der X-Achse gestreckt werden soll. Dieser Wert muss positiv sein.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactorX(float ScaleFactorX);
|
||||
|
||||
/**
|
||||
@brief Setzt den Skalierungsfaktor der Bitmap auf der Y-Achse.
|
||||
@param ScaleFactor der Faktor um den die Bitmap in Richtungen der Y-Achse gestreckt werden soll. Dieser Wert muss positiv sein.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Setzt den Skalierungsfaktor der Bitmap auf der Y-Achse.
|
||||
@param ScaleFactor der Faktor um den die Bitmap in Richtungen der Y-Achse gestreckt werden soll. Dieser Wert muss positiv sein.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
void SetScaleFactorY(float ScaleFactorY);
|
||||
|
||||
/**
|
||||
@brief Legt fest, ob das Bild an der X-Achse gespiegelt werden soll.
|
||||
@brief Legt fest, ob das Bild an der X-Achse gespiegelt werden soll.
|
||||
*/
|
||||
void SetFlipH(bool FlipH);
|
||||
|
||||
/**
|
||||
@brief Legt fest, ob das Bild an der Y-Achse gespiegelt werden soll.
|
||||
@brief Legt fest, ob das Bild an der Y-Achse gespiegelt werden soll.
|
||||
*/
|
||||
void SetFlipV(bool FlipV);
|
||||
|
||||
/**
|
||||
@brief Gibt den aktuellen Alphawert des Bildes zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
@brief Gibt den aktuellen Alphawert des Bildes zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||
*/
|
||||
int GetAlpha() { return m_ModulationColor >> 24; }
|
||||
int GetAlpha() {
|
||||
return m_ModulationColor >> 24;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die aktuelle 24bit RGB Modulationsfarde des Bildes zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
@brief Gibt die aktuelle 24bit RGB Modulationsfarde des Bildes zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||
*/
|
||||
int GetModulationColor() { return m_ModulationColor & 0x00ffffff; }
|
||||
int GetModulationColor() {
|
||||
return m_ModulationColor & 0x00ffffff;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der X-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der X-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
float GetScaleFactorX() const { return m_ScaleFactorX; }
|
||||
float GetScaleFactorX() const {
|
||||
return m_ScaleFactorX;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der Y-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der Y-Achse zurück.
|
||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||
*/
|
||||
float GetScaleFactorY() const { return m_ScaleFactorY; }
|
||||
float GetScaleFactorY() const {
|
||||
return m_ScaleFactorY;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt zurück, ob das Bild an der X-Achse gespiegelt angezeigt wird.
|
||||
@brief Gibt zurück, ob das Bild an der X-Achse gespiegelt angezeigt wird.
|
||||
*/
|
||||
bool IsFlipH() { return m_FlipH; }
|
||||
bool IsFlipH() {
|
||||
return m_FlipH;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt zurück, ob das Bild an der Y-Achse gespiegelt angezeigt wird.
|
||||
@brief Gibt zurück, ob das Bild an der Y-Achse gespiegelt angezeigt wird.
|
||||
*/
|
||||
bool IsFlipV() { return m_FlipV; }
|
||||
bool IsFlipV() {
|
||||
return m_FlipV;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Die folgenden Methoden müssen alle BS_Bitmap-Klassen implementieren
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
*/
|
||||
virtual unsigned int GetPixel(int X, int Y) const = 0;
|
||||
|
||||
/**
|
||||
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
||||
@param Pixeldata ein Vector der die Pixeldaten enthält. Sie müssen in dem Farbformat des Bildes vorliegen und es müssen genügend Daten
|
||||
vorhanden sein, um das ganze Bild zu füllen.
|
||||
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
||||
@param Pixeldata ein Vector der die Pixeldaten enthält. Sie müssen in dem Farbformat des Bildes vorliegen und es müssen genügend Daten
|
||||
vorhanden sein, um das ganze Bild zu füllen.
|
||||
@param Offset der Offset in Byte im Pixeldata-Vector an dem sich der erste zu schreibende Pixel befindet.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Stride der Abstand in Byte zwischen dem Zeilenende und dem Beginn einer neuen Zeile im Pixeldata-Vector.<br>
|
||||
Der Standardwert ist 0.
|
||||
@return Gibt false zurück, falls der Aufruf fehlgeschlagen ist.
|
||||
@remark Ein Aufruf dieser Methode ist nur erlaubt, wenn IsSetContentAllowed() true zurückgibt.
|
||||
Der Standardwert ist 0.
|
||||
@param Stride der Abstand in Byte zwischen dem Zeilenende und dem Beginn einer neuen Zeile im Pixeldata-Vector.<br>
|
||||
Der Standardwert ist 0.
|
||||
@return Gibt false zurück, falls der Aufruf fehlgeschlagen ist.
|
||||
@remark Ein Aufruf dieser Methode ist nur erlaubt, wenn IsSetContentAllowed() true zurückgibt.
|
||||
*/
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset = 0, unsigned int Stride = 0) = 0;
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset = 0, unsigned int Stride = 0) = 0;
|
||||
|
||||
virtual bool IsScalingAllowed() const = 0;
|
||||
virtual bool IsAlphaAllowed() const = 0;
|
||||
virtual bool IsColorModulationAllowed() const = 0;
|
||||
virtual bool IsSetContentAllowed() const = 0;
|
||||
virtual bool IsScalingAllowed() const = 0;
|
||||
virtual bool IsAlphaAllowed() const = 0;
|
||||
virtual bool IsColorModulationAllowed() const = 0;
|
||||
virtual bool IsSetContentAllowed() const = 0;
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
bool m_FlipH;
|
||||
bool m_FlipV;
|
||||
float m_ScaleFactorX;
|
||||
float m_ScaleFactorY;
|
||||
unsigned int m_ModulationColor;
|
||||
int m_OriginalWidth;
|
||||
int m_OriginalHeight;
|
||||
bool m_FlipH;
|
||||
bool m_FlipV;
|
||||
float m_ScaleFactorX;
|
||||
float m_ScaleFactorY;
|
||||
unsigned int m_ModulationColor;
|
||||
int m_OriginalWidth;
|
||||
int m_OriginalHeight;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -47,23 +47,20 @@ namespace Sword25 {
|
|||
// Konstruktion / Destruktion
|
||||
// --------------------------
|
||||
|
||||
BS_BitmapResource::BS_BitmapResource(const Common::String & Filename, BS_Image * pImage) :
|
||||
BS_BitmapResource::BS_BitmapResource(const Common::String &Filename, BS_Image *pImage) :
|
||||
m_Valid(false),
|
||||
m_pImage(pImage),
|
||||
BS_Resource(Filename, BS_Resource::TYPE_BITMAP)
|
||||
{
|
||||
BS_Resource(Filename, BS_Resource::TYPE_BITMAP) {
|
||||
m_Valid = m_pImage != 0;
|
||||
}
|
||||
|
||||
BS_BitmapResource::~BS_BitmapResource()
|
||||
{
|
||||
BS_BitmapResource::~BS_BitmapResource() {
|
||||
delete m_pImage;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_BitmapResource::GetPixel(int X, int Y) const
|
||||
{
|
||||
unsigned int BS_BitmapResource::GetPixel(int X, int Y) const {
|
||||
BS_ASSERT(X >= 0 && X < m_pImage->GetWidth());
|
||||
BS_ASSERT(Y >= 0 && Y < m_pImage->GetHeight());
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,14 +48,12 @@ namespace Sword25 {
|
|||
|
||||
class BS_Rect;
|
||||
|
||||
class BS_BitmapResource : public BS_Resource
|
||||
{
|
||||
class BS_BitmapResource : public BS_Resource {
|
||||
public:
|
||||
/**
|
||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||
*/
|
||||
enum FLIP_FLAGS
|
||||
{
|
||||
enum FLIP_FLAGS {
|
||||
/// Das Bild wird nicht gespiegelt.
|
||||
FLIP_NONE = 0,
|
||||
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
||||
|
@ -68,92 +66,102 @@ public:
|
|||
FLIP_VH = FLIP_H | FLIP_V
|
||||
};
|
||||
|
||||
BS_BitmapResource(const Common::String & Filename, BS_Image * pImage);
|
||||
BS_BitmapResource(const Common::String &Filename, BS_Image *pImage);
|
||||
virtual ~BS_BitmapResource();
|
||||
|
||||
/**
|
||||
@brief Gibt zurück, ob das Objekt einen gültigen Zustand hat.
|
||||
@brief Gibt zurück, ob das Objekt einen gültigen Zustand hat.
|
||||
*/
|
||||
bool IsValid() const { return m_Valid; }
|
||||
bool IsValid() const {
|
||||
return m_Valid;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die Breite des Bitmaps zurück.
|
||||
@brief Gibt die Breite des Bitmaps zurück.
|
||||
*/
|
||||
int GetWidth() const { BS_ASSERT(m_pImage); return m_pImage->GetWidth(); }
|
||||
int GetWidth() const {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->GetWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die Höhe des Bitmaps zurück.
|
||||
@brief Gibt die Höhe des Bitmaps zurück.
|
||||
*/
|
||||
int GetHeight() const { BS_ASSERT(m_pImage); return m_pImage->GetHeight(); }
|
||||
int GetHeight() const {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->GetHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Rendert das Bild in den Framebuffer.
|
||||
@param PosX die Position auf der X-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param PosY die Position auf der Y-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Flipping gibt an, wie das Bild gespiegelt werden soll.<br>
|
||||
Der Standardwert ist BS_Image::FLIP_NONE (keine Spiegelung)
|
||||
@param pSrcPartRect Pointer auf ein BS_Rect, welches den Ausschnitt des Quellbildes spezifiziert, der gerendert
|
||||
werden soll oder NULL, falls das gesamte Bild gerendert werden soll.<br>
|
||||
Dieser Ausschnitt bezieht sich auf das ungespiegelte und unskalierte Bild.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color ein ARGB Farbwert, der die Parameter für die Farbmodulation und fürs Alphablending festlegt.<br>
|
||||
Die Alpha-Komponente der Farbe bestimmt den Alphablending Parameter (0 = keine Deckung, 255 = volle Deckung).<br>
|
||||
Die Farbkomponenten geben die Farbe für die Farbmodulation an.<br>
|
||||
Der Standardwert is BS_ARGB(255, 255, 255, 255) (volle Deckung, keine Farbmodulation).
|
||||
Zum Erzeugen des Farbwertes können die Makros BS_RGB und BS_ARGB benutzt werden.
|
||||
@param Width gibt die Ausgabebreite des Bildausschnittes an.
|
||||
Falls diese von der Breite des Bildausschnittes abweicht wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@param Width gibt die Ausgabehöhe des Bildausschnittes an.
|
||||
Falls diese von der Höhe des Bildauschnittes abweicht, wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark Er werden nicht alle Blitting-Operationen von allen BS_Image-Klassen unterstützt.<br>
|
||||
Mehr Informationen gibt es in der Klassenbeschreibung von BS_Image und durch folgende Methoden:
|
||||
- IsBlitTarget()
|
||||
- IsScalingAllowed()
|
||||
- IsFillingAllowed()
|
||||
- IsAlphaAllowed()
|
||||
- IsColorModulationAllowed()
|
||||
@brief Rendert das Bild in den Framebuffer.
|
||||
@param PosX die Position auf der X-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param PosY die Position auf der Y-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Flipping gibt an, wie das Bild gespiegelt werden soll.<br>
|
||||
Der Standardwert ist BS_Image::FLIP_NONE (keine Spiegelung)
|
||||
@param pSrcPartRect Pointer auf ein BS_Rect, welches den Ausschnitt des Quellbildes spezifiziert, der gerendert
|
||||
werden soll oder NULL, falls das gesamte Bild gerendert werden soll.<br>
|
||||
Dieser Ausschnitt bezieht sich auf das ungespiegelte und unskalierte Bild.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color ein ARGB Farbwert, der die Parameter für die Farbmodulation und fürs Alphablending festlegt.<br>
|
||||
Die Alpha-Komponente der Farbe bestimmt den Alphablending Parameter (0 = keine Deckung, 255 = volle Deckung).<br>
|
||||
Die Farbkomponenten geben die Farbe für die Farbmodulation an.<br>
|
||||
Der Standardwert is BS_ARGB(255, 255, 255, 255) (volle Deckung, keine Farbmodulation).
|
||||
Zum Erzeugen des Farbwertes können die Makros BS_RGB und BS_ARGB benutzt werden.
|
||||
@param Width gibt die Ausgabebreite des Bildausschnittes an.
|
||||
Falls diese von der Breite des Bildausschnittes abweicht wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@param Width gibt die Ausgabehöhe des Bildausschnittes an.
|
||||
Falls diese von der Höhe des Bildauschnittes abweicht, wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark Er werden nicht alle Blitting-Operationen von allen BS_Image-Klassen unterstützt.<br>
|
||||
Mehr Informationen gibt es in der Klassenbeschreibung von BS_Image und durch folgende Methoden:
|
||||
- IsBlitTarget()
|
||||
- IsScalingAllowed()
|
||||
- IsFillingAllowed()
|
||||
- IsAlphaAllowed()
|
||||
- IsColorModulationAllowed()
|
||||
*/
|
||||
bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect* pSrcPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1)
|
||||
{
|
||||
bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect *pSrcPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1) {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->Blit(PosX, PosY, Flipping, pSrcPartRect, Color, Width, Height);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Füllt einen Rechteckigen Bereich des Bildes mit einer Farbe.
|
||||
@param pFillRect Pointer auf ein BS_Rect, welches den Ausschnitt des Bildes spezifiziert, der gefüllt
|
||||
werden soll oder NULL, falls das gesamte Bild gefüllt werden soll.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color der 32 Bit Farbwert mit dem der Bildbereich gefüllt werden soll.
|
||||
@remark Ein Aufruf dieser Methode ist nur gestattet, wenn IsFillingAllowed() true zurückgibt.
|
||||
@remark Es ist möglich über die Methode transparente Rechtecke darzustellen, indem man eine Farbe mit einem Alphawert ungleich
|
||||
255 angibt.
|
||||
@remark Unabhängig vom Farbformat des Bildes muss ein 32 Bit Farbwert angegeben werden. Zur Erzeugung, können die Makros
|
||||
BS_RGB und BS_ARGB benutzt werden.
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
@brief Füllt einen Rechteckigen Bereich des Bildes mit einer Farbe.
|
||||
@param pFillRect Pointer auf ein BS_Rect, welches den Ausschnitt des Bildes spezifiziert, der gefüllt
|
||||
werden soll oder NULL, falls das gesamte Bild gefüllt werden soll.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color der 32 Bit Farbwert mit dem der Bildbereich gefüllt werden soll.
|
||||
@remark Ein Aufruf dieser Methode ist nur gestattet, wenn IsFillingAllowed() true zurückgibt.
|
||||
@remark Es ist möglich über die Methode transparente Rechtecke darzustellen, indem man eine Farbe mit einem Alphawert ungleich
|
||||
255 angibt.
|
||||
@remark Unabhängig vom Farbformat des Bildes muss ein 32 Bit Farbwert angegeben werden. Zur Erzeugung, können die Makros
|
||||
BS_RGB und BS_ARGB benutzt werden.
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
*/
|
||||
bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) { BS_ASSERT(m_pImage); return m_pImage->Fill(pFillRect, Color); }
|
||||
bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->Fill(pFillRect, Color);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
*/
|
||||
unsigned int GetPixel(int X, int Y) const;
|
||||
|
||||
|
@ -161,34 +169,49 @@ public:
|
|||
/** @name Auskunfts-Methoden */
|
||||
|
||||
/**
|
||||
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
||||
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
||||
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
||||
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
||||
*/
|
||||
bool IsBlitTarget() { BS_ASSERT(m_pImage); return m_pImage->IsBlitTarget(); }
|
||||
bool IsBlitTarget() {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->IsBlitTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
||||
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
||||
*/
|
||||
bool IsScalingAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsScalingAllowed(); }
|
||||
bool IsScalingAllowed() {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->IsScalingAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
||||
*/
|
||||
bool IsFillingAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsFillingAllowed(); }
|
||||
bool IsFillingAllowed() {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->IsFillingAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
||||
*/
|
||||
bool IsAlphaAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsAlphaAllowed(); }
|
||||
bool IsAlphaAllowed() {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->IsAlphaAllowed();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
||||
*/
|
||||
bool IsColorModulationAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsColorModulationAllowed(); }
|
||||
bool IsColorModulationAllowed() {
|
||||
BS_ASSERT(m_pImage);
|
||||
return m_pImage->IsColorModulationAllowed();
|
||||
}
|
||||
|
||||
private:
|
||||
BS_Image * m_pImage;
|
||||
bool m_Valid;
|
||||
BS_Image *m_pImage;
|
||||
bool m_Valid;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -56,8 +56,7 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_DynamicBitmap::BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height) :
|
||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP)
|
||||
{
|
||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP) {
|
||||
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||
if (!m_InitSuccess) return;
|
||||
|
||||
|
@ -66,16 +65,14 @@ BS_DynamicBitmap::BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_DynamicBitmap::BS_DynamicBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP, Handle)
|
||||
{
|
||||
BS_DynamicBitmap::BS_DynamicBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP, Handle) {
|
||||
m_InitSuccess = Unpersist(Reader);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height)
|
||||
{
|
||||
bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height) {
|
||||
// GLImage mit den gewünschten Maßen erstellen
|
||||
bool Result;
|
||||
m_Image.reset(new BS_GLImage(Width, Height, Result));
|
||||
|
@ -88,14 +85,12 @@ bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_DynamicBitmap::~BS_DynamicBitmap()
|
||||
{
|
||||
BS_DynamicBitmap::~BS_DynamicBitmap() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const
|
||||
{
|
||||
unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const {
|
||||
BS_ASSERT(X >= 0 && X < m_Width);
|
||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||
|
||||
|
@ -104,27 +99,23 @@ unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::DoRender()
|
||||
{
|
||||
bool BS_DynamicBitmap::DoRender() {
|
||||
// Framebufferobjekt holen
|
||||
BS_GraphicEngine * pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_GraphicEngine *pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_ASSERT(pGfx);
|
||||
|
||||
// Bitmap zeichnen
|
||||
bool Result;
|
||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f)
|
||||
{
|
||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f) {
|
||||
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
} else {
|
||||
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
}
|
||||
|
||||
return Result;
|
||||
|
@ -132,8 +123,7 @@ bool BS_DynamicBitmap::DoRender()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
||||
{
|
||||
bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||
return m_Image->SetContent(Pixeldata, Offset, Stride);
|
||||
}
|
||||
|
||||
|
@ -141,29 +131,25 @@ bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, un
|
|||
// Auskunftsmethoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::IsScalingAllowed() const
|
||||
{
|
||||
bool BS_DynamicBitmap::IsScalingAllowed() const {
|
||||
return m_Image->IsScalingAllowed();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::IsAlphaAllowed() const
|
||||
{
|
||||
bool BS_DynamicBitmap::IsAlphaAllowed() const {
|
||||
return m_Image->IsAlphaAllowed();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::IsColorModulationAllowed() const
|
||||
{
|
||||
bool BS_DynamicBitmap::IsColorModulationAllowed() const {
|
||||
return m_Image->IsColorModulationAllowed();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::IsSetContentAllowed() const
|
||||
{
|
||||
bool BS_DynamicBitmap::IsSetContentAllowed() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -171,12 +157,11 @@ bool BS_DynamicBitmap::IsSetContentAllowed() const
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_Bitmap::Persist(Writer);
|
||||
|
||||
|
||||
// Bilddaten werden nicht gespeichert. Dies ist auch nicht weiter von bedeutung, da BS_DynamicBitmap nur vom Videoplayer benutzt wird.
|
||||
// Während ein Video abläuft kann niemals gespeichert werden. BS_DynamicBitmap kann nur der Vollständigkeit halber persistiert werden.
|
||||
BS_LOG_WARNINGLN("Persisting a BS_DynamicBitmap. Bitmap content is not persisted.");
|
||||
|
@ -186,8 +171,7 @@ bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
return Result;
|
||||
}
|
||||
|
||||
bool BS_DynamicBitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_DynamicBitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_Bitmap::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,31 +54,30 @@ namespace Sword25 {
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_DynamicBitmap : public BS_Bitmap
|
||||
{
|
||||
friend class BS_RenderObject;
|
||||
class BS_DynamicBitmap : public BS_Bitmap {
|
||||
friend class BS_RenderObject;
|
||||
|
||||
public:
|
||||
virtual ~BS_DynamicBitmap();
|
||||
|
||||
virtual unsigned int GetPixel(int X, int Y) const;
|
||||
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
|
||||
virtual bool IsScalingAllowed() const;
|
||||
virtual bool IsAlphaAllowed() const;
|
||||
virtual bool IsColorModulationAllowed() const;
|
||||
virtual bool IsSetContentAllowed() const;
|
||||
virtual bool IsScalingAllowed() const;
|
||||
virtual bool IsAlphaAllowed() const;
|
||||
virtual bool IsColorModulationAllowed() const;
|
||||
virtual bool IsSetContentAllowed() const;
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
virtual bool DoRender();
|
||||
virtual bool DoRender();
|
||||
|
||||
private:
|
||||
BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height);
|
||||
BS_DynamicBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
BS_DynamicBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
|
||||
bool CreateGLImage(unsigned int Width, unsigned int Height);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -60,31 +60,27 @@ static const unsigned int DEFAULT_GAPWIDTH = 1;
|
|||
// Konstruktion / Destruktion
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileName) :
|
||||
BS_FontResource::BS_FontResource(BS_Kernel *pKernel, const Common::String &FileName) :
|
||||
_pKernel(pKernel),
|
||||
_Valid(false),
|
||||
BS_Resource(FileName, BS_Resource::TYPE_FONT)
|
||||
{
|
||||
BS_Resource(FileName, BS_Resource::TYPE_FONT) {
|
||||
// XML Fontdatei parsen
|
||||
TiXmlDocument Doc;
|
||||
if (!_ParseXMLDocument(FileName, Doc))
|
||||
{
|
||||
if (!_ParseXMLDocument(FileName, Doc)) {
|
||||
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
||||
return;
|
||||
}
|
||||
|
||||
// Font-Tag finden
|
||||
TiXmlElement* pElement = Doc.FirstChildElement("font");
|
||||
if (!pElement)
|
||||
{
|
||||
TiXmlElement *pElement = Doc.FirstChildElement("font");
|
||||
if (!pElement) {
|
||||
BS_LOG_ERRORLN("No <font> tag found in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Font-Tag parsen
|
||||
Common::String BitmapFileName;
|
||||
if (!_ParseFontTag(*pElement, BitmapFileName, _LineHeight, _GapWidth))
|
||||
{
|
||||
if (!_ParseFontTag(*pElement, BitmapFileName, _LineHeight, _GapWidth)) {
|
||||
BS_LOG_ERRORLN("An error occurred while parsing <font> tag in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -93,43 +89,38 @@ BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileN
|
|||
{
|
||||
// Pointer auf den Package-Manager bekommen
|
||||
BS_ASSERT(_pKernel);
|
||||
BS_PackageManager* pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||
BS_ASSERT(pPackage);
|
||||
|
||||
// Absoluten, eindeutigen Pfad bestimmen
|
||||
_BitmapFileName = pPackage->GetAbsolutePath(BitmapFileName);
|
||||
if (_BitmapFileName == "")
|
||||
{
|
||||
if (_BitmapFileName == "") {
|
||||
BS_LOG_ERRORLN("Image file \"%s\" was specified in <font> tag of \"%s\" but could not be found.",
|
||||
_BitmapFileName.c_str(), GetFileName().c_str());
|
||||
_BitmapFileName.c_str(), GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Bitmapdatei cachen
|
||||
if (!_pKernel->GetResourceManager()->PrecacheResource(_BitmapFileName))
|
||||
{
|
||||
if (!_pKernel->GetResourceManager()->PrecacheResource(_BitmapFileName)) {
|
||||
BS_LOG_ERRORLN("Could not precache \"%s\".", _BitmapFileName.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Das Erste Character-Tag finden
|
||||
pElement = pElement->FirstChildElement("character");
|
||||
if (!pElement)
|
||||
{
|
||||
if (!pElement) {
|
||||
BS_LOG_ERRORLN("No <character> tag found in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Alle Character-Tags parsen
|
||||
while (pElement)
|
||||
{
|
||||
int CharCode;
|
||||
while (pElement) {
|
||||
int CharCode;
|
||||
BS_Rect CharRect;
|
||||
|
||||
// Aktuelles Character-Tag parsen
|
||||
if (!_ParseCharacterTag(*pElement, CharCode, CharRect))
|
||||
{
|
||||
if (!_ParseCharacterTag(*pElement, CharCode, CharRect)) {
|
||||
BS_LOG_ERRORLN("An error occured while parsing a <character> tag in \"%s\".", GetFileName().c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -148,19 +139,17 @@ BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileN
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_FontResource::_ParseXMLDocument(const Common::String & FileName, TiXmlDocument & Doc) const
|
||||
{
|
||||
bool BS_FontResource::_ParseXMLDocument(const Common::String &FileName, TiXmlDocument &Doc) const {
|
||||
// Pointer auf den Package-Manager bekommen
|
||||
BS_ASSERT(_pKernel);
|
||||
BS_PackageManager* pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||
BS_ASSERT(pPackage);
|
||||
|
||||
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert
|
||||
// und NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
||||
unsigned int FileSize;
|
||||
char * LoadBuffer = (char*) pPackage->GetFile(GetFileName(), &FileSize);
|
||||
if (!LoadBuffer)
|
||||
{
|
||||
char *LoadBuffer = (char *) pPackage->GetFile(GetFileName(), &FileSize);
|
||||
if (!LoadBuffer) {
|
||||
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -182,33 +171,29 @@ bool BS_FontResource::_ParseXMLDocument(const Common::String & FileName, TiXmlDo
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_FontResource::_ParseFontTag(TiXmlElement & Tag, Common::String & BitmapFileName, int & Lineheight, int & GapWidth) const
|
||||
{
|
||||
bool BS_FontResource::_ParseFontTag(TiXmlElement &Tag, Common::String &BitmapFileName, int &Lineheight, int &GapWidth) const {
|
||||
// Bitmap Attribut auslesen
|
||||
const char * BitmapString = Tag.Attribute("bitmap");
|
||||
if (!BitmapString)
|
||||
{
|
||||
const char *BitmapString = Tag.Attribute("bitmap");
|
||||
if (!BitmapString) {
|
||||
BS_LOG_ERRORLN("<font> tag without bitmap attribute occurred in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
BitmapFileName = BitmapString;
|
||||
|
||||
// Lineheight Attribut auslesen
|
||||
const char * LineheightString = Tag.Attribute("lineheight");
|
||||
if (!LineheightString || !BS_String::ToInt(Common::String(LineheightString), Lineheight) || Lineheight < 0)
|
||||
{
|
||||
const char *LineheightString = Tag.Attribute("lineheight");
|
||||
if (!LineheightString || !BS_String::ToInt(Common::String(LineheightString), Lineheight) || Lineheight < 0) {
|
||||
BS_LOG_WARNINGLN("Illegal or missing lineheight attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
||||
GetFileName().c_str(), DEFAULT_LINEHEIGHT);
|
||||
GetFileName().c_str(), DEFAULT_LINEHEIGHT);
|
||||
Lineheight = DEFAULT_LINEHEIGHT;
|
||||
}
|
||||
|
||||
|
||||
// Gap Attribut auslesen
|
||||
const char * GapString = Tag.Attribute("gap");
|
||||
if (!GapString || !BS_String::ToInt(Common::String(GapString), GapWidth) || GapWidth < 0)
|
||||
{
|
||||
const char *GapString = Tag.Attribute("gap");
|
||||
if (!GapString || !BS_String::ToInt(Common::String(GapString), GapWidth) || GapWidth < 0) {
|
||||
BS_LOG_WARNINGLN("Illegal or missing gap attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
||||
GetFileName().c_str(), DEFAULT_GAPWIDTH);
|
||||
GetFileName().c_str(), DEFAULT_GAPWIDTH);
|
||||
GapWidth = DEFAULT_GAPWIDTH;
|
||||
}
|
||||
|
||||
|
@ -217,12 +202,10 @@ bool BS_FontResource::_ParseFontTag(TiXmlElement & Tag, Common::String & BitmapF
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect & Rect) const
|
||||
{
|
||||
bool BS_FontResource::_ParseCharacterTag(TiXmlElement &Tag, int &Code, BS_Rect &Rect) const {
|
||||
// Code Attribut auslesen
|
||||
const char * CodeString = Tag.Attribute("code");
|
||||
if (!CodeString || !BS_String::ToInt(Common::String(CodeString), Code) || Code < 0 || Code >= 256)
|
||||
{
|
||||
const char *CodeString = Tag.Attribute("code");
|
||||
if (!CodeString || !BS_String::ToInt(Common::String(CodeString), Code) || Code < 0 || Code >= 256) {
|
||||
BS_LOG_ERRORLN("Illegal or missing code attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -238,7 +221,7 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
|||
Rect.left = tmp;
|
||||
|
||||
// Right Attribut auslesen
|
||||
const char * RightString = Tag.Attribute("right");
|
||||
const char *RightString = Tag.Attribute("right");
|
||||
if (!RightString || !BS_String::ToInt(RightString, tmp) || tmp < 0) {
|
||||
BS_LOG_ERRORLN("Illegal or missing right attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
|
@ -246,7 +229,7 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
|||
Rect.right = tmp;
|
||||
|
||||
// Top Attribut auslesen
|
||||
const char * TopString = Tag.Attribute("top");
|
||||
const char *TopString = Tag.Attribute("top");
|
||||
if (!TopString || !BS_String::ToInt(TopString, tmp) || tmp < 0) {
|
||||
BS_LOG_ERRORLN("Illegal or missing top attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
|
@ -254,9 +237,8 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
|||
Rect.top = tmp;
|
||||
|
||||
// Bottom Attribut auslesen
|
||||
const char * BottomString = Tag.Attribute("bottom");
|
||||
if (!BottomString || !BS_String::ToInt(BottomString, tmp) || tmp < 0)
|
||||
{
|
||||
const char *BottomString = Tag.Attribute("bottom");
|
||||
if (!BottomString || !BS_String::ToInt(BottomString, tmp) || tmp < 0) {
|
||||
BS_LOG_ERRORLN("Illegal or missing bottom attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -58,65 +58,75 @@ class BS_Kernel;
|
|||
// Klassendefinition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_FontResource : public BS_Resource
|
||||
{
|
||||
class BS_FontResource : public BS_Resource {
|
||||
public:
|
||||
/**
|
||||
@brief Erzeugt eine neues Exemplar von BS_FontResource
|
||||
@param pKernel ein Pointer auf den Kernel
|
||||
@param FileName der Dateiname der zu ladenen Resource
|
||||
@remark Wenn der Konstruktor erfolgreich ausgeführt werden konnte gibt die Methode IsValid true zurück.
|
||||
@brief Erzeugt eine neues Exemplar von BS_FontResource
|
||||
@param pKernel ein Pointer auf den Kernel
|
||||
@param FileName der Dateiname der zu ladenen Resource
|
||||
@remark Wenn der Konstruktor erfolgreich ausgeführt werden konnte gibt die Methode IsValid true zurück.
|
||||
*/
|
||||
BS_FontResource(BS_Kernel * pKernel, const Common::String & FileName);
|
||||
BS_FontResource(BS_Kernel *pKernel, const Common::String &FileName);
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das Objekt korrekt initialisiert wurde.
|
||||
@brief Gibt true zurück, wenn das Objekt korrekt initialisiert wurde.
|
||||
|
||||
Diese Methode kann dazu benutzt werden um festzustellen, ob der Konstruktor erfolgreich ausgeführt wurde.
|
||||
Diese Methode kann dazu benutzt werden um festzustellen, ob der Konstruktor erfolgreich ausgeführt wurde.
|
||||
*/
|
||||
bool IsValid() const { return _Valid; }
|
||||
bool IsValid() const {
|
||||
return _Valid;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die Zeilenhöhe des Fonts in Pixeln zurück.
|
||||
@brief Gibt die Zeilenhöhe des Fonts in Pixeln zurück.
|
||||
|
||||
Die Zeilenhöhe ist der Wert, der zur Y-Koordinate addiert wird, wenn ein Zeilenumbruch auftritt.
|
||||
Die Zeilenhöhe ist der Wert, der zur Y-Koordinate addiert wird, wenn ein Zeilenumbruch auftritt.
|
||||
*/
|
||||
int GetLineHeight() const { return _LineHeight; }
|
||||
int GetLineHeight() const {
|
||||
return _LineHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Buchstabenabstand der Fonts in Pixeln zurück.
|
||||
@brief Gibt den Buchstabenabstand der Fonts in Pixeln zurück.
|
||||
|
||||
Der Buchstabenabstand ist der Wert, der zwischen zwei Buchstaben freigelassen wird.
|
||||
Der Buchstabenabstand ist der Wert, der zwischen zwei Buchstaben freigelassen wird.
|
||||
*/
|
||||
int GetGapWidth() const { return _GapWidth; }
|
||||
int GetGapWidth() const {
|
||||
return _GapWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt das Bounding-Rect eines Zeichens auf der Charactermap zurück.
|
||||
@param Character der ASCII-Code des Zeichens
|
||||
@return Das Bounding-Rect des übergebenen Zeichens auf der Charactermap.
|
||||
@brief Gibt das Bounding-Rect eines Zeichens auf der Charactermap zurück.
|
||||
@param Character der ASCII-Code des Zeichens
|
||||
@return Das Bounding-Rect des übergebenen Zeichens auf der Charactermap.
|
||||
*/
|
||||
const BS_Rect & GetCharacterRect(int Character) const { BS_ASSERT(Character >= 0 && Character < 256); return _CharacterRects[Character]; }
|
||||
const BS_Rect &GetCharacterRect(int Character) const {
|
||||
BS_ASSERT(Character >= 0 && Character < 256);
|
||||
return _CharacterRects[Character];
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Dateinamen der Charactermap zurück.
|
||||
@brief Gibt den Dateinamen der Charactermap zurück.
|
||||
*/
|
||||
const Common::String & GetCharactermapFileName() const { return _BitmapFileName; }
|
||||
const Common::String &GetCharactermapFileName() const {
|
||||
return _BitmapFileName;
|
||||
}
|
||||
|
||||
private:
|
||||
BS_Kernel * _pKernel;
|
||||
bool _Valid;
|
||||
Common::String _BitmapFileName;
|
||||
int _LineHeight;
|
||||
int _GapWidth;
|
||||
BS_Rect _CharacterRects[256];
|
||||
BS_Kernel *_pKernel;
|
||||
bool _Valid;
|
||||
Common::String _BitmapFileName;
|
||||
int _LineHeight;
|
||||
int _GapWidth;
|
||||
BS_Rect _CharacterRects[256];
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Hilfsmethoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool _ParseXMLDocument(const Common::String & FileName, TiXmlDocument & Doc) const;
|
||||
bool _ParseFontTag(TiXmlElement & Tag, Common::String & BitmapFileName, int & LineHeight, int & GapWidth) const;
|
||||
bool _ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect & Rect) const;
|
||||
|
||||
bool _ParseXMLDocument(const Common::String &FileName, TiXmlDocument &Doc) const;
|
||||
bool _ParseFontTag(TiXmlElement &Tag, Common::String &BitmapFileName, int &LineHeight, int &GapWidth) const;
|
||||
bool _ParseCharacterTag(TiXmlElement &Tag, int &Code, BS_Rect &Rect) const;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -38,14 +38,13 @@
|
|||
namespace Sword25 {
|
||||
|
||||
BS_Framecounter::BS_Framecounter(int UpdateFrequency) :
|
||||
m_FPS(0),
|
||||
m_FPSCount(0),
|
||||
m_LastUpdateTime(-1) {
|
||||
m_FPS(0),
|
||||
m_FPSCount(0),
|
||||
m_LastUpdateTime(-1) {
|
||||
SetUpdateFrequency(UpdateFrequency);
|
||||
}
|
||||
|
||||
void BS_Framecounter::Update()
|
||||
{
|
||||
void BS_Framecounter::Update() {
|
||||
// Aktuellen Systemtimerstand auslesen
|
||||
uint64_t Timer = g_system->getMillis() * 1000;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,14 +53,14 @@ private:
|
|||
public:
|
||||
/**
|
||||
* Creates a new BS_Framecounter object
|
||||
* @param UpdateFrequency Specifies how often the frame counter should be updated in a sceond.
|
||||
* @param UpdateFrequency Specifies how often the frame counter should be updated in a sceond.
|
||||
* The default value is 10.
|
||||
*/
|
||||
BS_Framecounter(int UpdateFrequency = DEFAULT_UPDATE_FREQUENCY);
|
||||
|
||||
/**
|
||||
* Determines how often the frame counter should be updated in a second.
|
||||
* @param UpdateFrequency Specifies how often the frame counter should be updated in a second.
|
||||
* @param UpdateFrequency Specifies how often the frame counter should be updated in a second.
|
||||
*/
|
||||
inline void SetUpdateFrequency(int UpdateFrequency);
|
||||
|
||||
|
@ -72,10 +72,12 @@ public:
|
|||
/**
|
||||
* Returns the current FPS value.
|
||||
*/
|
||||
int GetFPS() const { return m_FPS; }
|
||||
int GetFPS() const {
|
||||
return m_FPS;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_FPS;
|
||||
int m_FPS;
|
||||
int m_FPSCount;
|
||||
int64_t m_LastUpdateTime;
|
||||
uint64_t m_UpdateDelay;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -58,20 +58,19 @@ namespace Sword25 {
|
|||
using namespace std;
|
||||
using namespace Lua;
|
||||
|
||||
static const unsigned int FRAMETIME_SAMPLE_COUNT = 5; // Anzahl der Framezeiten über die, die Framezeit gemittelt wird
|
||||
static const unsigned int FRAMETIME_SAMPLE_COUNT = 5; // Anzahl der Framezeiten über die, die Framezeit gemittelt wird
|
||||
|
||||
BS_GraphicEngine::BS_GraphicEngine(BS_Kernel * pKernel) :
|
||||
BS_GraphicEngine::BS_GraphicEngine(BS_Kernel *pKernel) :
|
||||
m_Width(0),
|
||||
m_Height(0),
|
||||
m_BitDepth(0),
|
||||
m_Windowed(0),
|
||||
m_LastTimeStamp((uint64)-1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
|
||||
m_LastTimeStamp((uint64) - 1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
|
||||
m_LastFrameDuration(0),
|
||||
m_TimerActive(true),
|
||||
m_FrameTimeSampleSlot(0),
|
||||
m_RepaintedPixels(0),
|
||||
BS_ResourceService(pKernel)
|
||||
{
|
||||
BS_ResourceService(pKernel) {
|
||||
for (int i = 0; i < FRAMETIME_SAMPLE_COUNT; i++)
|
||||
m_FrameTimeSamples[i] = 0;
|
||||
|
||||
|
@ -83,8 +82,7 @@ BS_GraphicEngine::BS_GraphicEngine(BS_Kernel * pKernel) :
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_GraphicEngine::UpdateLastFrameDuration()
|
||||
{
|
||||
void BS_GraphicEngine::UpdateLastFrameDuration() {
|
||||
// Aktuelle Zeit holen
|
||||
uint64_t CurrentTime = BS_Kernel::GetInstance()->GetMicroTicks();
|
||||
|
||||
|
@ -106,58 +104,50 @@ void BS_GraphicEngine::UpdateLastFrameDuration()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
bool DoSaveScreenshot(BS_GraphicEngine & GraphicEngine, const Common::String & Filename, bool Thumbnail)
|
||||
{
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
Common::Array<unsigned int> Data;
|
||||
if (!GraphicEngine.GetScreenshot(Width, Height, Data))
|
||||
{
|
||||
BS_LOG_ERRORLN("Call to GetScreenshot() failed. Cannot save screenshot.");
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int test = Data.size();
|
||||
|
||||
if (Thumbnail)
|
||||
return BS_Screenshot::SaveThumbnailToFile(Width, Height, Data, Filename);
|
||||
else
|
||||
return BS_Screenshot::SaveToFile(Width, Height, Data, Filename);
|
||||
namespace {
|
||||
bool DoSaveScreenshot(BS_GraphicEngine &GraphicEngine, const Common::String &Filename, bool Thumbnail) {
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
Common::Array<unsigned int> Data;
|
||||
if (!GraphicEngine.GetScreenshot(Width, Height, Data)) {
|
||||
BS_LOG_ERRORLN("Call to GetScreenshot() failed. Cannot save screenshot.");
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int test = Data.size();
|
||||
|
||||
if (Thumbnail)
|
||||
return BS_Screenshot::SaveThumbnailToFile(Width, Height, Data, Filename);
|
||||
else
|
||||
return BS_Screenshot::SaveToFile(Width, Height, Data, Filename);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GraphicEngine::SaveScreenshot(const Common::String & Filename)
|
||||
{
|
||||
bool BS_GraphicEngine::SaveScreenshot(const Common::String &Filename) {
|
||||
return DoSaveScreenshot(*this, Filename, false);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GraphicEngine::SaveThumbnailScreenshot( const Common::String & Filename )
|
||||
{
|
||||
bool BS_GraphicEngine::SaveThumbnailScreenshot(const Common::String &Filename) {
|
||||
return DoSaveScreenshot(*this, Filename, true);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_GraphicEngine::ARGBColorToLuaColor(lua_State * L, unsigned int Color)
|
||||
{
|
||||
lua_Number Components[4] =
|
||||
{
|
||||
(Color >> 16) & 0xff, // Rot
|
||||
(Color >> 8) & 0xff, // Grün
|
||||
Color & 0xff, // Blau
|
||||
Color >> 24, // Alpha
|
||||
void BS_GraphicEngine::ARGBColorToLuaColor(lua_State *L, unsigned int Color) {
|
||||
lua_Number Components[4] = {
|
||||
(Color >> 16) & 0xff, // Rot
|
||||
(Color >> 8) & 0xff, // Grün
|
||||
Color & 0xff, // Blau
|
||||
Color >> 24, // Alpha
|
||||
};
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for (unsigned int i = 1; i <= 4; i++)
|
||||
{
|
||||
for (unsigned int i = 1; i <= 4; i++) {
|
||||
lua_pushnumber(L, i);
|
||||
lua_pushnumber(L, Components[i - 1]);
|
||||
lua_settable(L, -3);
|
||||
|
@ -166,8 +156,7 @@ void BS_GraphicEngine::ARGBColorToLuaColor(lua_State * L, unsigned int Color)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex)
|
||||
{
|
||||
unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State *L, int StackIndex) {
|
||||
#ifdef DEBUG
|
||||
int __startStackDepth = lua_gettop(L);
|
||||
#endif
|
||||
|
@ -199,8 +188,7 @@ unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex
|
|||
|
||||
// Alpha Farbkomponente auslesen
|
||||
unsigned int Alpha = 0xff;
|
||||
if (n == 4)
|
||||
{
|
||||
if (n == 4) {
|
||||
lua_rawgeti(L, StackIndex, 4);
|
||||
Alpha = static_cast<unsigned int>(lua_tonumber(L, -1));
|
||||
if (!lua_isnumber(L, -1) || Alpha >= 256) luaL_argcheck(L, 0, StackIndex, "alpha color component must be an integer between 0 and 255");
|
||||
|
@ -216,16 +204,14 @@ unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GraphicEngine::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_GraphicEngine::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
Writer.Write(m_TimerActive);
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GraphicEngine::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_GraphicEngine::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
Reader.Read(m_TimerActive);
|
||||
return Reader.IsGood();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -65,15 +65,15 @@ class BS_Screenshot;
|
|||
typedef unsigned int BS_COLOR;
|
||||
|
||||
// Makros
|
||||
#define BS_RGB(R,G,B) (0xFF000000 | ((R) << 16) | ((G) << 8) | (B))
|
||||
#define BS_ARGB(A,R,G,B) (((A) << 24) | ((R) << 16) | ((G) << 8) | (B))
|
||||
#define BS_RGB(R,G,B) (0xFF000000 | ((R) << 16) | ((G) << 8) | (B))
|
||||
#define BS_ARGB(A,R,G,B) (((A) << 24) | ((R) << 16) | ((G) << 8) | (B))
|
||||
|
||||
/**
|
||||
@brief Dies ist das Graphik-Engine Interface, dass alle Methoden und Klassen enthält, die eine Graphik-Engine implementieren muss.
|
||||
@brief Dies ist das Graphik-Engine Interface, dass alle Methoden und Klassen enthält, die eine Graphik-Engine implementieren muss.
|
||||
|
||||
Hier sind nur wenige Rumpffunktionen realisiert, wie z.B. das Abfragen der Parameter des Ausgabepuffers.
|
||||
Die Hauptfunktionen muss eine Implementation dieses Inferfaces stellen.<br>
|
||||
Die bisher einzige Implementation ist BS_DDrawGfx.
|
||||
Hier sind nur wenige Rumpffunktionen realisiert, wie z.B. das Abfragen der Parameter des Ausgabepuffers.
|
||||
Die Hauptfunktionen muss eine Implementation dieses Inferfaces stellen.<br>
|
||||
Die bisher einzige Implementation ist BS_DDrawGfx.
|
||||
*/
|
||||
|
||||
class BS_GraphicEngine : public BS_ResourceService, public BS_Persistable {
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
// -----
|
||||
|
||||
// Colour formats
|
||||
//
|
||||
//
|
||||
/**
|
||||
* The colour format used by the engine
|
||||
*/
|
||||
|
@ -124,33 +124,33 @@ public:
|
|||
*/
|
||||
CF_ARGB32,
|
||||
/**
|
||||
32-bit colour format (A8B8G8R8) (little endian)
|
||||
32-bit colour format (A8B8G8R8) (little endian)
|
||||
*/
|
||||
CF_ABGR32
|
||||
};
|
||||
|
||||
|
||||
// Interface
|
||||
// ---------
|
||||
|
||||
/**
|
||||
* Initialises the graphics engine and sets the screen mode. Returns true if initialisation failed.
|
||||
* Notes: This method should be called immediately after the initialisation of all services.
|
||||
*
|
||||
* @param Height The height of the output buffer in pixels. The default value is 600
|
||||
* @param BitDepth The bit depth of the desired output buffer in bits. The default value is 16
|
||||
* @param BackbufferCount The number of back buffers to be created. The default value is 2
|
||||
* @param Windowed Indicates whether the engine is to run in windowed mode.
|
||||
*
|
||||
* @param Height The height of the output buffer in pixels. The default value is 600
|
||||
* @param BitDepth The bit depth of the desired output buffer in bits. The default value is 16
|
||||
* @param BackbufferCount The number of back buffers to be created. The default value is 2
|
||||
* @param Windowed Indicates whether the engine is to run in windowed mode.
|
||||
*/
|
||||
virtual bool Init(int Width = 800, int Height = 600, int BitDepth = 16, int BackbufferCount = 2, bool Windowed = false) = 0;
|
||||
virtual bool Init(int Width = 800, int Height = 600, int BitDepth = 16, int BackbufferCount = 2, bool Windowed = false) = 0;
|
||||
|
||||
/**
|
||||
* Begins rendering a new frame.
|
||||
* Notes: This method must be called at the beginning of the main loop, before any rendering methods are used.
|
||||
* Notes: Implementations of this method must call _UpdateLastFrameDuration()
|
||||
* @param UpdateAll Specifies whether the renderer should redraw everything on the next frame.
|
||||
* @param UpdateAll Specifies whether the renderer should redraw everything on the next frame.
|
||||
* This feature can be useful if the renderer with Dirty Rectangles works, but sometimes the client may
|
||||
*/
|
||||
virtual bool StartFrame(bool UpdateAll = false) = 0;
|
||||
virtual bool StartFrame(bool UpdateAll = false) = 0;
|
||||
|
||||
/**
|
||||
* Ends the rendering of a frame and draws it on the screen.
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
* This method must be at the end of the main loop. After this call, no further Render method may be called.
|
||||
* This should only be called once for a given previous call to #StartFrame.
|
||||
*/
|
||||
virtual bool EndFrame() = 0;
|
||||
virtual bool EndFrame() = 0;
|
||||
|
||||
// Debug methods
|
||||
|
||||
|
@ -168,17 +168,17 @@ public:
|
|||
* This method must be called between calls to StartFrame() and EndFrame(), and is intended only for debugging
|
||||
* purposes. The line will only appear for a single frame. If the line is to be shown permanently, it must be
|
||||
* called for every frame.
|
||||
* @param Start The starting point of the line
|
||||
* @param End The ending point of the line
|
||||
* @param Color The colour of the line. The default is BS_RGB (255,255,255) (White)
|
||||
* @param Start The starting point of the line
|
||||
* @param End The ending point of the line
|
||||
* @param Color The colour of the line. The default is BS_RGB (255,255,255) (White)
|
||||
*/
|
||||
virtual void DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color = BS_RGB(255, 255, 255)) = 0;
|
||||
virtual void DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color = BS_RGB(255, 255, 255)) = 0;
|
||||
|
||||
/**
|
||||
* Creates a screenshot of the current frame buffer and writes it to a graphic file in PNG format.
|
||||
* Returns true if the screenshot was saved successfully.
|
||||
* Returns true if the screenshot was saved successfully.
|
||||
* Notes: This method should only be called after a call to EndFrame(), and before the next call to StartFrame().
|
||||
* @param Filename The filename for the screenshot
|
||||
* @param Filename The filename for the screenshot
|
||||
*/
|
||||
bool SaveScreenshot(const Common::String &Filename);
|
||||
|
||||
|
@ -187,7 +187,7 @@ public:
|
|||
* the interface boards the the image as a 16th of it's original size.
|
||||
* Notes: This method should only be called after a call to EndFrame(), and before the next call to StartFrame().
|
||||
* The frame buffer must have a resolution of 800x600.
|
||||
* @param Filename The filename for the screenshot
|
||||
* @param Filename The filename for the screenshot
|
||||
*/
|
||||
bool SaveThumbnailScreenshot(const Common::String &Filename);
|
||||
|
||||
|
@ -195,91 +195,117 @@ public:
|
|||
* Reads the current contents of the frame buffer
|
||||
* Notes: This method is for creating screenshots. It is not very optimised. It should only be called
|
||||
* after a call to EndFrame(), and before the next call to StartFrame().
|
||||
* @param Width Returns the width of the frame buffer
|
||||
* @param Height Returns the height of the frame buffer
|
||||
* @param Data Returns the raw data of the frame buffer as an array of 32-bit colour values.
|
||||
* @param Width Returns the width of the frame buffer
|
||||
* @param Height Returns the height of the frame buffer
|
||||
* @param Data Returns the raw data of the frame buffer as an array of 32-bit colour values.
|
||||
*/
|
||||
virtual bool GetScreenshot(unsigned int &Width, unsigned int &Height, Common::Array<unsigned int> &Data) = 0;
|
||||
|
||||
|
||||
|
||||
virtual BS_RenderObjectPtr<BS_Panel> GetMainPanel() = 0;
|
||||
|
||||
/**
|
||||
* Specifies the time (in microseconds) since the last frame has passed
|
||||
*/
|
||||
int GetLastFrameDurationMicro() { if (m_TimerActive) return m_LastFrameDuration; else return 0; }
|
||||
int GetLastFrameDurationMicro() {
|
||||
if (m_TimerActive) return m_LastFrameDuration;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the time (in microseconds) the previous frame took
|
||||
*/
|
||||
float GetLastFrameDuration() { if (m_TimerActive) return static_cast<float>(m_LastFrameDuration) / 1000000.0f; else return 0; }
|
||||
float GetLastFrameDuration() {
|
||||
if (m_TimerActive) return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void StopMainTimer() { m_TimerActive = false; }
|
||||
void ResumeMainTimer() { m_TimerActive = true; }
|
||||
float GetSecondaryFrameDuration() { return static_cast<float>(m_LastFrameDuration) / 1000000.0f; }
|
||||
void StopMainTimer() {
|
||||
m_TimerActive = false;
|
||||
}
|
||||
void ResumeMainTimer() {
|
||||
m_TimerActive = true;
|
||||
}
|
||||
float GetSecondaryFrameDuration() {
|
||||
return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
|
||||
}
|
||||
|
||||
// Accessor methods
|
||||
|
||||
/**
|
||||
* Returns the width of the output buffer in pixels
|
||||
*/
|
||||
int GetDisplayWidth() { return m_Width; }
|
||||
int GetDisplayWidth() {
|
||||
return m_Width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the output buffer in pixels
|
||||
*/
|
||||
int GetDisplayHeight() { return m_Height; }
|
||||
int GetDisplayHeight() {
|
||||
return m_Height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounding box of the output buffer: (0, 0, Width, Height)
|
||||
*/
|
||||
BS_Rect& GetDisplayRect() { return m_ScreenRect; }
|
||||
BS_Rect &GetDisplayRect() {
|
||||
return m_ScreenRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit depth of the output buffer
|
||||
*/
|
||||
int GetBitDepth() { return m_BitDepth; }
|
||||
int GetBitDepth() {
|
||||
return m_BitDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the frame buffer change is to be synchronised with Vsync. This is turned on by default.
|
||||
* Notes: In windowed mode, this setting has no effect.
|
||||
* @param Vsync Indicates whether the frame buffer changes are to be synchronised with Vsync.
|
||||
* @param Vsync Indicates whether the frame buffer changes are to be synchronised with Vsync.
|
||||
*/
|
||||
virtual void SetVsync(bool Vsync) = 0;
|
||||
virtual void SetVsync(bool Vsync) = 0;
|
||||
|
||||
/**
|
||||
* Returns true if V-Sync is on.
|
||||
* Notes: In windowed mode, this setting has no effect.
|
||||
*/
|
||||
virtual bool GetVsync() const = 0;
|
||||
virtual bool GetVsync() const = 0;
|
||||
|
||||
/**
|
||||
* Returns true if the engine is running in Windowed mode.
|
||||
*/
|
||||
bool IsWindowed() { return m_Windowed; }
|
||||
bool IsWindowed() {
|
||||
return m_Windowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills a rectangular area of the frame buffer with a colour.
|
||||
* Notes: It is possible to create transparent rectangles by passing a colour with an Alpha value of 255.
|
||||
* @param FillRectPtr Pointer to a BS_Rect, which specifies the section of the frame buffer to be filled.
|
||||
* If the rectangle falls partly off-screen, then it is automatically trimmed.
|
||||
* @param FillRectPtr Pointer to a BS_Rect, which specifies the section of the frame buffer to be filled.
|
||||
* If the rectangle falls partly off-screen, then it is automatically trimmed.
|
||||
* If a NULL value is passed, then the entire image is to be filled.
|
||||
* @param Color The 32-bit colour with which the area is to be filled. The default is BS_RGB(0, 0, 0) (black)
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
* @param Color The 32-bit colour with which the area is to be filled. The default is BS_RGB(0, 0, 0) (black)
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
*/
|
||||
virtual bool Fill(const BS_Rect * FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||
virtual bool Fill(const BS_Rect *FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||
|
||||
// Debugging Methods
|
||||
|
||||
int GetFPSCount() const { return m_FPSCounter.GetFPS(); }
|
||||
int GetRepaintedPixels() const { return m_RepaintedPixels; }
|
||||
int GetFPSCount() const {
|
||||
return m_FPSCounter.GetFPS();
|
||||
}
|
||||
int GetRepaintedPixels() const {
|
||||
return m_RepaintedPixels;
|
||||
}
|
||||
|
||||
// Access methods
|
||||
|
||||
/**
|
||||
* Returns the size of a pixel entry in bytes for a particular colour format
|
||||
* @param ColorFormat The desired colour format. The parameter must be of type COLOR_FORMATS
|
||||
* @return Returns the size of a pixel in bytes. If the colour format is unknown, -1 is returned.
|
||||
* @param ColorFormat The desired colour format. The parameter must be of type COLOR_FORMATS
|
||||
* @return Returns the size of a pixel in bytes. If the colour format is unknown, -1 is returned.
|
||||
*/
|
||||
static int GetPixelSize(BS_GraphicEngine::COLOR_FORMATS ColorFormat) {
|
||||
switch (ColorFormat) {
|
||||
|
@ -297,16 +323,16 @@ public:
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the length of an image line in bytes, depending on a given colour format.
|
||||
* @param ColorFormat The colour format
|
||||
* @param Width The width of the line in pixels
|
||||
* @return Reflects the length of the line in bytes. If the colour format is
|
||||
* @param ColorFormat The colour format
|
||||
* @param Width The width of the line in pixels
|
||||
* @return Reflects the length of the line in bytes. If the colour format is
|
||||
* unknown, -1 is returned
|
||||
*/
|
||||
static int CalcPitch(BS_GraphicEngine::COLOR_FORMATS ColorFormat, int Width) {
|
||||
switch (ColorFormat){
|
||||
switch (ColorFormat) {
|
||||
case BS_GraphicEngine::CF_RGB16:
|
||||
case BS_GraphicEngine::CF_RGB15:
|
||||
return Width * 2;
|
||||
|
@ -337,21 +363,21 @@ public:
|
|||
protected:
|
||||
// Constructor
|
||||
// -----------
|
||||
BS_GraphicEngine(BS_Kernel* pKernel);
|
||||
BS_GraphicEngine(BS_Kernel *pKernel);
|
||||
|
||||
// Display Variables
|
||||
// -----------------
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
BS_Rect m_ScreenRect;
|
||||
int m_BitDepth;
|
||||
bool m_Windowed;
|
||||
int m_BitDepth;
|
||||
bool m_Windowed;
|
||||
|
||||
// Debugging Variables
|
||||
// -------------------
|
||||
BS_Framecounter m_FPSCounter;
|
||||
|
||||
unsigned int m_RepaintedPixels;
|
||||
unsigned int m_RepaintedPixels;
|
||||
|
||||
/**
|
||||
* Calculates the time since the last frame beginning has passed.
|
||||
|
@ -363,11 +389,11 @@ private:
|
|||
|
||||
// LastFrameDuration Variables
|
||||
// ---------------------------
|
||||
uint64 m_LastTimeStamp;
|
||||
unsigned int m_LastFrameDuration;
|
||||
bool m_TimerActive;
|
||||
Common::Array<unsigned int> m_FrameTimeSamples;
|
||||
unsigned int m_FrameTimeSampleSlot;
|
||||
uint64 m_LastTimeStamp;
|
||||
unsigned int m_LastFrameDuration;
|
||||
bool m_TimerActive;
|
||||
Common::Array<unsigned int> m_FrameTimeSamples;
|
||||
unsigned int m_FrameTimeSampleSlot;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,38 +50,33 @@ namespace Sword25 {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
unsigned int FindEmbeddedPNG(const char * FileDataPtr, unsigned int FileSize)
|
||||
{
|
||||
// Einen Stringstream mit dem Anfang der Datei intialisieren. 512 Byte sollten hierfür genügen.
|
||||
istringstream StringStream(string(FileDataPtr, FileDataPtr + min(static_cast<unsigned int>(512), FileSize)));
|
||||
namespace {
|
||||
unsigned int FindEmbeddedPNG(const char *FileDataPtr, unsigned int FileSize) {
|
||||
// Einen Stringstream mit dem Anfang der Datei intialisieren. 512 Byte sollten hierfür genügen.
|
||||
istringstream StringStream(string(FileDataPtr, FileDataPtr + min(static_cast<unsigned int>(512), FileSize)));
|
||||
|
||||
// Headerinformationen der Spielstandes einlesen.
|
||||
string Marker, VersionID;
|
||||
unsigned int CompressedGamedataSize, UncompressedGamedataSize;
|
||||
StringStream >> Marker >> VersionID >> CompressedGamedataSize >> UncompressedGamedataSize;
|
||||
if (!StringStream.good()) return 0;
|
||||
// Headerinformationen der Spielstandes einlesen.
|
||||
string Marker, VersionID;
|
||||
unsigned int CompressedGamedataSize, UncompressedGamedataSize;
|
||||
StringStream >> Marker >> VersionID >> CompressedGamedataSize >> UncompressedGamedataSize;
|
||||
if (!StringStream.good()) return 0;
|
||||
|
||||
// Testen, ob wir tatsächlich einen Spielstand haben.
|
||||
if (Marker == "BS25SAVEGAME")
|
||||
{
|
||||
// Offset zum PNG innerhalb des Spielstandes berechnen und zurückgeben.
|
||||
return static_cast<unsigned int>(StringStream.tellg()) + CompressedGamedataSize + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Testen, ob wir tatsächlich einen Spielstand haben.
|
||||
if (Marker == "BS25SAVEGAME") {
|
||||
// Offset zum PNG innerhalb des Spielstandes berechnen und zurückgeben.
|
||||
return static_cast<unsigned int>(StringStream.tellg()) + CompressedGamedataSize + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_B25SLoader::IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize)
|
||||
{
|
||||
bool BS_B25SLoader::IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||
if (PNGOffset > 0)
|
||||
{
|
||||
if (PNGOffset > 0) {
|
||||
return BS_PNGLoader::DoIsCorrectImageFormat(FileDataPtr + PNGOffset, FileSize - PNGOffset);
|
||||
}
|
||||
|
||||
|
@ -90,13 +85,11 @@ bool BS_B25SLoader::IsCorrectImageFormat(const char * FileDataPtr, unsigned int
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_B25SLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int & Width, int & Height, int & Pitch)
|
||||
{
|
||||
bool BS_B25SLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int &Width, int &Height, int &Pitch) {
|
||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||
if (PNGOffset > 0)
|
||||
{
|
||||
if (PNGOffset > 0) {
|
||||
return BS_PNGLoader::DoDecodeImage(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
||||
}
|
||||
|
||||
|
@ -105,12 +98,10 @@ bool BS_B25SLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize,
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_B25SLoader::ImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
||||
{
|
||||
bool BS_B25SLoader::ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||
if (PNGOffset > 0)
|
||||
{
|
||||
if (PNGOffset > 0) {
|
||||
return BS_PNGLoader::DoImageProperties(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, Width, Height);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,21 +48,19 @@ namespace Sword25 {
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_B25SLoader : public BS_ImageLoader
|
||||
{
|
||||
class BS_B25SLoader : public BS_ImageLoader {
|
||||
public:
|
||||
static BS_ImageLoader * CreateInstance()
|
||||
{
|
||||
#include "sword25/kernel/memlog_off.h"
|
||||
static BS_ImageLoader *CreateInstance() {
|
||||
#include "sword25/kernel/memlog_off.h"
|
||||
return static_cast<BS_ImageLoader *>(new BS_B25SLoader());
|
||||
#include "sword25/kernel/memlog_on.h"
|
||||
#include "sword25/kernel/memlog_on.h"
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
||||
virtual bool DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int & Width, int & Height, int & Pitch);
|
||||
virtual bool ImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
||||
virtual bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||
virtual bool DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int &Width, int &Height, int &Pitch);
|
||||
virtual bool ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,10 +33,10 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
BS_Image
|
||||
--------
|
||||
BS_Image
|
||||
--------
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_IMAGE_H
|
||||
|
@ -52,17 +52,15 @@
|
|||
|
||||
namespace Sword25 {
|
||||
|
||||
class BS_Image
|
||||
{
|
||||
class BS_Image {
|
||||
public:
|
||||
virtual ~BS_Image() {};
|
||||
|
||||
// Enums
|
||||
/**
|
||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||
*/
|
||||
enum FLIP_FLAGS
|
||||
{
|
||||
enum FLIP_FLAGS {
|
||||
/// Das Bild wird nicht gespiegelt.
|
||||
FLIP_NONE = 0,
|
||||
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
||||
|
@ -74,22 +72,22 @@ public:
|
|||
/// Das Bild wird an der horizontalen und vertikalen Achse gespiegelt.
|
||||
FLIP_VH = FLIP_H | FLIP_V
|
||||
};
|
||||
|
||||
|
||||
//@{
|
||||
/** @name Accessor-Methoden */
|
||||
|
||||
/**
|
||||
@brief Gibt die Breite des Bildes in Pixeln zurück
|
||||
@brief Gibt die Breite des Bildes in Pixeln zurück
|
||||
*/
|
||||
virtual int GetWidth() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt die Höhe des Bildes in Pixeln zurück
|
||||
@brief Gibt die Höhe des Bildes in Pixeln zurück
|
||||
*/
|
||||
virtual int GetHeight() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt das Farbformat des Bildes zurück
|
||||
@brief Gibt das Farbformat des Bildes zurück
|
||||
*/
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const = 0;
|
||||
|
||||
|
@ -99,83 +97,83 @@ public:
|
|||
/** @name Render-Methoden */
|
||||
|
||||
/**
|
||||
@brief Rendert das Bild in den Framebuffer.
|
||||
@param pDest ein Pointer auf das Zielbild. In den meisten Fällen ist dies der Framebuffer.
|
||||
@param PosX die Position auf der X-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param PosY die Position auf der Y-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Flipping gibt an, wie das Bild gespiegelt werden soll.<br>
|
||||
Der Standardwert ist BS_Image::FLIP_NONE (keine Spiegelung)
|
||||
@param pSrcPartRect Pointer auf ein BS_Rect, welches den Ausschnitt des Quellbildes spezifiziert, der gerendert
|
||||
werden soll oder NULL, falls das gesamte Bild gerendert werden soll.<br>
|
||||
Dieser Ausschnitt bezieht sich auf das ungespiegelte und unskalierte Bild.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color ein ARGB Farbwert, der die Parameter für die Farbmodulation und fürs Alphablending festlegt.<br>
|
||||
Die Alpha-Komponente der Farbe bestimmt den Alphablending Parameter (0 = keine Deckung, 255 = volle Deckung).<br>
|
||||
Die Farbkomponenten geben die Farbe für die Farbmodulation an.<br>
|
||||
Der Standardwert is BS_ARGB(255, 255, 255, 255) (volle Deckung, keine Farbmodulation).
|
||||
Zum Erzeugen des Farbwertes können die Makros BS_RGB und BS_ARGB benutzt werden.
|
||||
@param Width gibt die Ausgabebreite des Bildausschnittes an.
|
||||
Falls diese von der Breite des Bildausschnittes abweicht wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@param Width gibt die Ausgabehöhe des Bildausschnittes an.
|
||||
Falls diese von der Höhe des Bildauschnittes abweicht, wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark Er werden nicht alle Blitting-Operationen von allen BS_Image-Klassen unterstützt.<br>
|
||||
Mehr Informationen gibt es in der Klassenbeschreibung von BS_Image und durch folgende Methoden:
|
||||
- IsBlitTarget()
|
||||
- IsScalingAllowed()
|
||||
- IsFillingAllowed()
|
||||
- IsAlphaAllowed()
|
||||
- IsColorModulationAllowed()
|
||||
- IsSetContentAllowed()
|
||||
@brief Rendert das Bild in den Framebuffer.
|
||||
@param pDest ein Pointer auf das Zielbild. In den meisten Fällen ist dies der Framebuffer.
|
||||
@param PosX die Position auf der X-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param PosY die Position auf der Y-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Flipping gibt an, wie das Bild gespiegelt werden soll.<br>
|
||||
Der Standardwert ist BS_Image::FLIP_NONE (keine Spiegelung)
|
||||
@param pSrcPartRect Pointer auf ein BS_Rect, welches den Ausschnitt des Quellbildes spezifiziert, der gerendert
|
||||
werden soll oder NULL, falls das gesamte Bild gerendert werden soll.<br>
|
||||
Dieser Ausschnitt bezieht sich auf das ungespiegelte und unskalierte Bild.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color ein ARGB Farbwert, der die Parameter für die Farbmodulation und fürs Alphablending festlegt.<br>
|
||||
Die Alpha-Komponente der Farbe bestimmt den Alphablending Parameter (0 = keine Deckung, 255 = volle Deckung).<br>
|
||||
Die Farbkomponenten geben die Farbe für die Farbmodulation an.<br>
|
||||
Der Standardwert is BS_ARGB(255, 255, 255, 255) (volle Deckung, keine Farbmodulation).
|
||||
Zum Erzeugen des Farbwertes können die Makros BS_RGB und BS_ARGB benutzt werden.
|
||||
@param Width gibt die Ausgabebreite des Bildausschnittes an.
|
||||
Falls diese von der Breite des Bildausschnittes abweicht wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@param Width gibt die Ausgabehöhe des Bildausschnittes an.
|
||||
Falls diese von der Höhe des Bildauschnittes abweicht, wird
|
||||
das Bild entsprechend Skaliert.<br>
|
||||
Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br>
|
||||
Der Standardwert ist -1.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark Er werden nicht alle Blitting-Operationen von allen BS_Image-Klassen unterstützt.<br>
|
||||
Mehr Informationen gibt es in der Klassenbeschreibung von BS_Image und durch folgende Methoden:
|
||||
- IsBlitTarget()
|
||||
- IsScalingAllowed()
|
||||
- IsFillingAllowed()
|
||||
- IsAlphaAllowed()
|
||||
- IsColorModulationAllowed()
|
||||
- IsSetContentAllowed()
|
||||
*/
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect* pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1) = 0;
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect *pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1) = 0;
|
||||
|
||||
/**
|
||||
@brief Füllt einen Rechteckigen Bereich des Bildes mit einer Farbe.
|
||||
@param pFillRect Pointer auf ein BS_Rect, welches den Ausschnitt des Bildes spezifiziert, der gefüllt
|
||||
werden soll oder NULL, falls das gesamte Bild gefüllt werden soll.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color der 32 Bit Farbwert mit dem der Bildbereich gefüllt werden soll.
|
||||
@remark Es ist möglich über die Methode transparente Rechtecke darzustellen, indem man eine Farbe mit einem Alphawert ungleich
|
||||
255 angibt.
|
||||
@remark Unabhängig vom Farbformat des Bildes muss ein 32 Bit Farbwert angegeben werden. Zur Erzeugung, können die Makros
|
||||
BS_RGB und BS_ARGB benutzt werden.
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
@brief Füllt einen Rechteckigen Bereich des Bildes mit einer Farbe.
|
||||
@param pFillRect Pointer auf ein BS_Rect, welches den Ausschnitt des Bildes spezifiziert, der gefüllt
|
||||
werden soll oder NULL, falls das gesamte Bild gefüllt werden soll.<br>
|
||||
Der Standardwert ist NULL.
|
||||
@param Color der 32 Bit Farbwert mit dem der Bildbereich gefüllt werden soll.
|
||||
@remark Es ist möglich über die Methode transparente Rechtecke darzustellen, indem man eine Farbe mit einem Alphawert ungleich
|
||||
255 angibt.
|
||||
@remark Unabhängig vom Farbformat des Bildes muss ein 32 Bit Farbwert angegeben werden. Zur Erzeugung, können die Makros
|
||||
BS_RGB und BS_ARGB benutzt werden.
|
||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||
*/
|
||||
virtual bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||
virtual bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||
|
||||
/**
|
||||
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
||||
@param Pixeldata ein Vector der die Pixeldaten enthält. Sie müssen in dem Farbformat des Bildes vorliegen und es müssen genügend Daten
|
||||
vorhanden sein, um das ganze Bild zu füllen.
|
||||
@param Offset der Offset in Byte im Pixeldata-Vector an dem sich der erste zu schreibende Pixel befindet.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Stride der Abstand in Byte zwischen dem Zeilenende und dem Beginn einer neuen Zeile im Pixeldata-Vector.<br>
|
||||
Der Standardwert ist 0.
|
||||
@return Gibt false zurück, falls der Aufruf fehlgeschlagen ist.
|
||||
@remark Ein Aufruf dieser Methode ist nur erlaubt, wenn IsSetContentAllowed() true zurückgibt.
|
||||
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
||||
@param Pixeldata ein Vector der die Pixeldaten enthält. Sie müssen in dem Farbformat des Bildes vorliegen und es müssen genügend Daten
|
||||
vorhanden sein, um das ganze Bild zu füllen.
|
||||
@param Offset der Offset in Byte im Pixeldata-Vector an dem sich der erste zu schreibende Pixel befindet.<br>
|
||||
Der Standardwert ist 0.
|
||||
@param Stride der Abstand in Byte zwischen dem Zeilenende und dem Beginn einer neuen Zeile im Pixeldata-Vector.<br>
|
||||
Der Standardwert ist 0.
|
||||
@return Gibt false zurück, falls der Aufruf fehlgeschlagen ist.
|
||||
@remark Ein Aufruf dieser Methode ist nur erlaubt, wenn IsSetContentAllowed() true zurückgibt.
|
||||
*/
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) = 0;
|
||||
|
||||
/**
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
@brief Liest einen Pixel des Bildes.
|
||||
@param X die X-Koordinate des Pixels.
|
||||
@param Y die Y-Koordinate des Pixels
|
||||
@return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück.
|
||||
@remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist
|
||||
eher dafür gedacht einzelne Pixel des Bildes auszulesen.
|
||||
*/
|
||||
virtual unsigned int GetPixel(int X, int Y) = 0;
|
||||
|
||||
|
@ -183,39 +181,39 @@ public:
|
|||
/** @name Auskunfts-Methoden */
|
||||
|
||||
/**
|
||||
@brief Überprüft, ob an dem BS_Image Blit() aufgerufen werden darf.
|
||||
@return Gibt false zurück, falls ein Blit()-Aufruf an diesem Objekt nicht gestattet ist.
|
||||
@brief Überprüft, ob an dem BS_Image Blit() aufgerufen werden darf.
|
||||
@return Gibt false zurück, falls ein Blit()-Aufruf an diesem Objekt nicht gestattet ist.
|
||||
*/
|
||||
virtual bool IsBlitSource() const = 0;
|
||||
|
||||
/**
|
||||
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
||||
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
||||
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
||||
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
||||
*/
|
||||
virtual bool IsBlitTarget() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
||||
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
||||
*/
|
||||
virtual bool IsScalingAllowed() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
||||
*/
|
||||
virtual bool IsFillingAllowed() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
||||
*/
|
||||
virtual bool IsAlphaAllowed() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
||||
*/
|
||||
virtual bool IsColorModulationAllowed() const = 0;
|
||||
|
||||
/**
|
||||
@brief Gibt true zurück, wenn der Inhalt des BS_Image durch eine Aufruf von SetContent() ausgetauscht werden kann.
|
||||
@brief Gibt true zurück, wenn der Inhalt des BS_Image durch eine Aufruf von SetContent() ausgetauscht werden kann.
|
||||
*/
|
||||
virtual bool IsSetContentAllowed() const = 0;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -40,31 +40,29 @@ namespace Sword25 {
|
|||
#define BS_LOG_PREFIX "IMAGELOADER"
|
||||
|
||||
// Statische Elemente der Klasse BS_ImageLoader intialisieren.
|
||||
std::list<BS_ImageLoader*> BS_ImageLoader::_ImageLoaderList;
|
||||
std::list<BS_ImageLoader *> BS_ImageLoader::_ImageLoaderList;
|
||||
bool BS_ImageLoader::_ImageLoaderListInitialized = false;
|
||||
|
||||
// Lade Methode
|
||||
// ------------
|
||||
|
||||
bool BS_ImageLoader::LoadImage(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int& Width, int& Height,
|
||||
int& Pitch)
|
||||
{
|
||||
bool BS_ImageLoader::LoadImage(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int &Width, int &Height,
|
||||
int &Pitch) {
|
||||
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
||||
if (!_ImageLoaderListInitialized)
|
||||
_InitializeLoaderList();
|
||||
|
||||
// Passenden BS_ImageLoader finden und Bild dekodieren
|
||||
BS_ImageLoader* pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||
if (pLoader)
|
||||
{
|
||||
BS_ImageLoader *pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||
if (pLoader) {
|
||||
return pLoader->DecodeImage(pFileData, FileSize,
|
||||
ColorFormat,
|
||||
pUncompressedData,
|
||||
Width, Height,
|
||||
Pitch);
|
||||
ColorFormat,
|
||||
pUncompressedData,
|
||||
Width, Height,
|
||||
Pitch);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -73,21 +71,19 @@ bool BS_ImageLoader::LoadImage(const char* pFileData, unsigned int FileSize,
|
|||
// Info Methode
|
||||
// ------------
|
||||
|
||||
bool BS_ImageLoader::ExtractImageProperties(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
||||
int& Width, int& Height)
|
||||
{
|
||||
bool BS_ImageLoader::ExtractImageProperties(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||
int &Width, int &Height) {
|
||||
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
||||
if (!_ImageLoaderListInitialized)
|
||||
_InitializeLoaderList();
|
||||
|
||||
// Passenden BS_ImageLoader finden und Bildeigenschaften auslesen.
|
||||
BS_ImageLoader* pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||
if (pLoader)
|
||||
{
|
||||
BS_ImageLoader *pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||
if (pLoader) {
|
||||
return pLoader->ImageProperties(pFileData, FileSize,
|
||||
ColorFormat,
|
||||
Width, Height);
|
||||
ColorFormat,
|
||||
Width, Height);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -96,8 +92,7 @@ bool BS_ImageLoader::ExtractImageProperties(const char* pFileData, unsigned int
|
|||
// Verwaltungs Methoden
|
||||
// --------------------
|
||||
|
||||
void BS_ImageLoader::_InitializeLoaderList()
|
||||
{
|
||||
void BS_ImageLoader::_InitializeLoaderList() {
|
||||
// Von jedem BS_ImageLoader wird eine Instanz erzeugt, diese fügen sich selbständig in die BS_ImageLoader-Liste ein.
|
||||
for (int i = 0; i < BS_IMAGELOADER_COUNT; i++)
|
||||
BS_IMAGELOADER_IDS[i]();
|
||||
|
@ -109,24 +104,19 @@ void BS_ImageLoader::_InitializeLoaderList()
|
|||
atexit(BS_ImageLoader::_DeinitializeLoaderList);
|
||||
}
|
||||
|
||||
void BS_ImageLoader::_DeinitializeLoaderList()
|
||||
{
|
||||
while (!_ImageLoaderList.empty())
|
||||
{
|
||||
void BS_ImageLoader::_DeinitializeLoaderList() {
|
||||
while (!_ImageLoaderList.empty()) {
|
||||
delete _ImageLoaderList.back();
|
||||
_ImageLoaderList.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
BS_ImageLoader* BS_ImageLoader::_FindSuitableImageLoader(const char* pFileData, unsigned int FileSize)
|
||||
{
|
||||
BS_ImageLoader *BS_ImageLoader::_FindSuitableImageLoader(const char *pFileData, unsigned int FileSize) {
|
||||
// Alle BS_ImageLoader-Objekte durchgehen, bis eins gefunden wurde, dass das Bild laden kann
|
||||
std::list<BS_ImageLoader*>::iterator Iter = _ImageLoaderList.begin();
|
||||
for (; Iter != _ImageLoaderList.end(); ++Iter)
|
||||
{
|
||||
std::list<BS_ImageLoader *>::iterator Iter = _ImageLoaderList.begin();
|
||||
for (; Iter != _ImageLoaderList.end(); ++Iter) {
|
||||
// Falls ein geeigneter BS-ImageLoader gefunden wurde, wird er zurückgegeben.
|
||||
if ((*Iter)->IsCorrectImageFormat(pFileData, FileSize))
|
||||
{
|
||||
if ((*Iter)->IsCorrectImageFormat(pFileData, FileSize)) {
|
||||
return (*Iter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,10 +33,10 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
BS_ImageLoader
|
||||
--------------
|
||||
BS_ImageLoader
|
||||
--------------
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_IMAGELOADER_H
|
||||
|
@ -55,90 +55,88 @@
|
|||
namespace Sword25 {
|
||||
|
||||
/**
|
||||
@brief Über die statischen Methoden dieser Klasse werden alle unterstützten Bildformate geladen.
|
||||
@brief Über die statischen Methoden dieser Klasse werden alle unterstützten Bildformate geladen.
|
||||
|
||||
Zum Laden von Bildern wird die #LoadImage-Methode benutzt.
|
||||
Zum Laden von Bildern wird die #LoadImage-Methode benutzt.
|
||||
|
||||
Außerdem stellt diese Klasse das Interface da, das alle Klassen implementieren müssen, die Bildformate einlesen.<br>
|
||||
Zur Unterstützung eines neuen Bildformates muss folgendermaßen vorgegangen werden:
|
||||
- Erzeugen einer neuen von #BS_ImageLoader abgeleiteten Klasse, die die Methoden #IsCorrectImageFormat und #DecodeImage impelementiert.
|
||||
- Die Klasse muss eine statische Methode haben, die eine Instanz von ihr erzeugt und einen Pointer darauf zurückgibt.
|
||||
- Diese Methode muss in der Liste in der Datei imageloader_ids.h eingetragen werden.
|
||||
- Die Klasse muss JEDES Eingabebild seines Bildformates in die folgenden Farbformate konvertieren können:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
- BS_GraphicEngine::CF_BGRA32
|
||||
- Zum Konvertieren der Bilddaten können die Hilfsmethoden dieser Klasse benutzt werden, die ARGB Bilddaten in alle benötigten
|
||||
Farbformate konvertieren.
|
||||
Außerdem stellt diese Klasse das Interface da, das alle Klassen implementieren müssen, die Bildformate einlesen.<br>
|
||||
Zur Unterstützung eines neuen Bildformates muss folgendermaßen vorgegangen werden:
|
||||
- Erzeugen einer neuen von #BS_ImageLoader abgeleiteten Klasse, die die Methoden #IsCorrectImageFormat und #DecodeImage impelementiert.
|
||||
- Die Klasse muss eine statische Methode haben, die eine Instanz von ihr erzeugt und einen Pointer darauf zurückgibt.
|
||||
- Diese Methode muss in der Liste in der Datei imageloader_ids.h eingetragen werden.
|
||||
- Die Klasse muss JEDES Eingabebild seines Bildformates in die folgenden Farbformate konvertieren können:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
- BS_GraphicEngine::CF_BGRA32
|
||||
- Zum Konvertieren der Bilddaten können die Hilfsmethoden dieser Klasse benutzt werden, die ARGB Bilddaten in alle benötigten
|
||||
Farbformate konvertieren.
|
||||
*/
|
||||
class BS_ImageLoader
|
||||
{
|
||||
class BS_ImageLoader {
|
||||
public:
|
||||
|
||||
//@{
|
||||
/** @name Lade Methoden */
|
||||
|
||||
/**
|
||||
@brief Lädt eine Bilddatei.
|
||||
@brief Lädt eine Bilddatei.
|
||||
|
||||
Diese Methode kann sämtliche unterstütztem Bildformate lesen. Die Methode erkennt selbstständing um welches Dateiformat es sich
|
||||
bei der vorliegenden Datei handelt.<br>
|
||||
Bisher wird nur PNG unterstützt.
|
||||
Diese Methode kann sämtliche unterstütztem Bildformate lesen. Die Methode erkennt selbstständing um welches Dateiformat es sich
|
||||
bei der vorliegenden Datei handelt.<br>
|
||||
Bisher wird nur PNG unterstützt.
|
||||
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe der Bilddaten in Byte.
|
||||
@param ColorFormat gibt das gewünschte Farbformat an, in das die Bilddaten konvertiert werden sollen.<br>
|
||||
Folgende Farbformate werden unterstützt:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
@param pUncompressedData nach erfolgreichen Laden zeigt dieser Pointer auf die enpackten und konvertierten Bilddaten.
|
||||
@param Width gibt nach erfolgreichen Laden die Breite des geladenen Bildes an.
|
||||
@param Height gibt nach erfolgreichen Laden die Höhe des geladenen Bildes an.
|
||||
@param Pitch gibt nach erfolgreichen Laden die Länge einer Bildzeile in Byte an.
|
||||
@return Gibt false zurück, falls das Laden fehlgeschlagen ist.
|
||||
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe der Bilddaten in Byte.
|
||||
@param ColorFormat gibt das gewünschte Farbformat an, in das die Bilddaten konvertiert werden sollen.<br>
|
||||
Folgende Farbformate werden unterstützt:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
@param pUncompressedData nach erfolgreichen Laden zeigt dieser Pointer auf die enpackten und konvertierten Bilddaten.
|
||||
@param Width gibt nach erfolgreichen Laden die Breite des geladenen Bildes an.
|
||||
@param Height gibt nach erfolgreichen Laden die Höhe des geladenen Bildes an.
|
||||
@param Pitch gibt nach erfolgreichen Laden die Länge einer Bildzeile in Byte an.
|
||||
@return Gibt false zurück, falls das Laden fehlgeschlagen ist.
|
||||
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
*/
|
||||
static bool LoadImage(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int& Width, int& Height,
|
||||
int& Pitch);
|
||||
static bool LoadImage(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int &Width, int &Height,
|
||||
int &Pitch);
|
||||
|
||||
/**
|
||||
@brief Liest die Bildeigenschaften eines Bildes aus.
|
||||
@brief Liest die Bildeigenschaften eines Bildes aus.
|
||||
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe des Bilddaten in Byte.
|
||||
@param ColorFormat enthält nach einem erfolgreichem Aufruf das Farbformat des Bildes.
|
||||
@param Width enthält nach einem erfolgreichem Aufruf die Breite des Bildes in Pixeln.
|
||||
@param Height enthält nach einem erfolgreichem Aufruf die Höhe des Bildes in Pixeln.
|
||||
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe des Bilddaten in Byte.
|
||||
@param ColorFormat enthält nach einem erfolgreichem Aufruf das Farbformat des Bildes.
|
||||
@param Width enthält nach einem erfolgreichem Aufruf die Breite des Bildes in Pixeln.
|
||||
@param Height enthält nach einem erfolgreichem Aufruf die Höhe des Bildes in Pixeln.
|
||||
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
*/
|
||||
static bool ExtractImageProperties(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
||||
int& Width, int& Height);
|
||||
static bool ExtractImageProperties(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||
int &Width, int &Height);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Konstruktor, damit Instanzen dieser Klasse nur von BS_ImageLoader-Objekten erstellt werden können
|
||||
/**
|
||||
@brief Der Standardkonstruktor.
|
||||
@brief Der Standardkonstruktor.
|
||||
|
||||
Dieser Konstruktor registriert alle Instanzen von #BS_ImageLoader-Klassen in einer Liste.<br>
|
||||
Diese Liste enthält jeweils eine Instanz jedes #BS_ImageLoader und wird benutzt um beliebige Bilddateien einem Loader zuzuordnen.
|
||||
@remark Dieser Konstruktor ist protected damit nur #BS_ImageLoader-Objekte diese Klasse instanziieren können.
|
||||
Dieser Konstruktor registriert alle Instanzen von #BS_ImageLoader-Klassen in einer Liste.<br>
|
||||
Diese Liste enthält jeweils eine Instanz jedes #BS_ImageLoader und wird benutzt um beliebige Bilddateien einem Loader zuzuordnen.
|
||||
@remark Dieser Konstruktor ist protected damit nur #BS_ImageLoader-Objekte diese Klasse instanziieren können.
|
||||
*/
|
||||
BS_ImageLoader()
|
||||
{
|
||||
BS_ImageLoader() {
|
||||
// Klasse registrieren
|
||||
_ImageLoaderList.push_front(this);
|
||||
}
|
||||
|
@ -147,54 +145,54 @@ protected:
|
|||
/** @name Abstrakte Methoden */
|
||||
|
||||
/**
|
||||
@brief Gibt an, ob der #BS_ImageLoader ein Bild lesen kann.
|
||||
@param pFileData ein Pointer auf die kompletten Daten des Bildes.
|
||||
@param FileSize die Größe der Daten in Byte.
|
||||
@return Gibt true zurück, wenn der #BS_ImageLoader das Bild lesen kann, ansonsten false.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
@brief Gibt an, ob der #BS_ImageLoader ein Bild lesen kann.
|
||||
@param pFileData ein Pointer auf die kompletten Daten des Bildes.
|
||||
@param FileSize die Größe der Daten in Byte.
|
||||
@return Gibt true zurück, wenn der #BS_ImageLoader das Bild lesen kann, ansonsten false.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
*/
|
||||
virtual bool IsCorrectImageFormat(const char* pFileData, unsigned int FileSize) = 0;
|
||||
virtual bool IsCorrectImageFormat(const char *pFileData, unsigned int FileSize) = 0;
|
||||
|
||||
/**
|
||||
@brief Lädt eine Bilddatei.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe der Bilddaten in Byte.
|
||||
@param ColorFormat gibt das gewünschte Farbformat an, in das die Bilddaten konvertiert werden sollen.<br>
|
||||
Folgende Farbformate werden unterstützt:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
@param pUncompressedData nach erfolgreichen Laden zeigt dieser Pointer auf die enpackten und konvertierten Bilddaten.
|
||||
@param Width gibt nach erfolgreichen Laden die Breite des geladenen Bildes an.
|
||||
@param Height gibt nach erfolgreichen Laden die Höhe des geladenen Bildes an.
|
||||
@param Pitch gibt nach erfolgreichen Laden die Länge einer Bildzeile in Byte an.
|
||||
@return Gibt false zurück, falls das Laden fehlgeschlagen ist.
|
||||
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
@brief Lädt eine Bilddatei.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe der Bilddaten in Byte.
|
||||
@param ColorFormat gibt das gewünschte Farbformat an, in das die Bilddaten konvertiert werden sollen.<br>
|
||||
Folgende Farbformate werden unterstützt:
|
||||
- BS_GraphicEngine::CF_RGB16
|
||||
- BS_GraphicEngine::CF_RGB15
|
||||
- BS_GraphicEngine::CF_RGB16_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_RGB15_INTERLEAVED
|
||||
- BS_GraphicEngine::CF_ARGB32
|
||||
@param pUncompressedData nach erfolgreichen Laden zeigt dieser Pointer auf die enpackten und konvertierten Bilddaten.
|
||||
@param Width gibt nach erfolgreichen Laden die Breite des geladenen Bildes an.
|
||||
@param Height gibt nach erfolgreichen Laden die Höhe des geladenen Bildes an.
|
||||
@param Pitch gibt nach erfolgreichen Laden die Länge einer Bildzeile in Byte an.
|
||||
@return Gibt false zurück, falls das Laden fehlgeschlagen ist.
|
||||
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
*/
|
||||
virtual bool DecodeImage(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int& Width, int& Height,
|
||||
int& Pitch) = 0;
|
||||
virtual bool DecodeImage(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char*& pUncompressedData,
|
||||
int &Width, int &Height,
|
||||
int &Pitch) = 0;
|
||||
|
||||
/**
|
||||
@brief Liest die Bildeigenschaften aus.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe des Bilddaten in Byte.
|
||||
@param ColorFormat enthält nach einem erfolgreichem Aufruf das Farbformat des Bildes.
|
||||
@param Width enthält nach einem erfolgreichem Aufruf die Breite des Bildes in Pixeln.
|
||||
@param Height enthält nach einem erfolgreichem Aufruf die Höhe des Bildes in Pixeln.
|
||||
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
@brief Liest die Bildeigenschaften aus.
|
||||
@param pFileData ein Pointer auf die Bilddaten.
|
||||
@param FileSize die Größe des Bilddaten in Byte.
|
||||
@param ColorFormat enthält nach einem erfolgreichem Aufruf das Farbformat des Bildes.
|
||||
@param Width enthält nach einem erfolgreichem Aufruf die Breite des Bildes in Pixeln.
|
||||
@param Height enthält nach einem erfolgreichem Aufruf die Höhe des Bildes in Pixeln.
|
||||
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||
*/
|
||||
virtual bool ImageProperties(const char* pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
||||
int& Width, int& Height) = 0;
|
||||
virtual bool ImageProperties(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||
int &Width, int &Height) = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
@ -202,69 +200,62 @@ protected:
|
|||
/** @name Konvertierungsmethoden */
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB16 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens Width * 2 Byte notwendig.
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB16 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens Width * 2 Byte notwendig.
|
||||
*/
|
||||
static void RowARGB32ToRGB16(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
||||
{
|
||||
for (unsigned int i = 0; i < Width; i++)
|
||||
{
|
||||
((uint16_t*)pDestData)[i] = ((pSrcData[2] >> 3) << 11) | ((pSrcData[1] >> 2) << 5) | (pSrcData[0] >> 3);
|
||||
pSrcData += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB15 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens Width * 2 Byte notwendig.
|
||||
*/
|
||||
static void RowARGB32ToRGB15(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
||||
{
|
||||
for (unsigned int i = 0; i < Width; i++)
|
||||
{
|
||||
((uint16_t*)pDestData)[i] = ((pSrcData[2] >> 3) << 10) | ((pSrcData[1] >> 3) << 5) | (pSrcData[0] >> 3);
|
||||
static void RowARGB32ToRGB16(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
((uint16_t *)pDestData)[i] = ((pSrcData[2] >> 3) << 11) | ((pSrcData[1] >> 2) << 5) | (pSrcData[0] >> 3);
|
||||
pSrcData += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB16_INTERLEAVED Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß sein muss.<br>
|
||||
Es sind mindestens ((Width + 3) / 4) * 12 Byte notwendig.
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB15 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens Width * 2 Byte notwendig.
|
||||
*/
|
||||
static void RowARGB32ToRGB16_INTERLEAVED(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
||||
{
|
||||
static void RowARGB32ToRGB15(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
((uint16_t *)pDestData)[i] = ((pSrcData[2] >> 3) << 10) | ((pSrcData[1] >> 3) << 5) | (pSrcData[0] >> 3);
|
||||
pSrcData += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB16_INTERLEAVED Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß sein muss.<br>
|
||||
Es sind mindestens ((Width + 3) / 4) * 12 Byte notwendig.
|
||||
*/
|
||||
static void RowARGB32ToRGB16_INTERLEAVED(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
||||
unsigned int BlockFillCount = 0;
|
||||
unsigned int AlphaBlock = 0;
|
||||
for (unsigned int i = 0; i < Width; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
// Alphawert in den Alphablock schreiben
|
||||
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
||||
|
||||
|
||||
// Füllstand der Pixelblockes aktualisieren
|
||||
BlockFillCount++;
|
||||
|
||||
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
||||
if (BlockFillCount == 4 || i == (Width - 1))
|
||||
{
|
||||
if (BlockFillCount == 4 || i == (Width - 1)) {
|
||||
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
||||
// "left aligned" sind.
|
||||
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
||||
|
||||
// Alphablock schreiben
|
||||
*((unsigned int*)pDestData) = AlphaBlock;
|
||||
*((unsigned int *)pDestData) = AlphaBlock;
|
||||
pDestData += 4;
|
||||
|
||||
// Pixel konvertieren und schreiben
|
||||
|
@ -283,35 +274,32 @@ protected:
|
|||
}
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB15_INTERLEAVED Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens (Width / 4 + Width % 4) * 3 Byte notwendig.
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_RGB15_INTERLEAVED Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||
Es sind mindestens (Width / 4 + Width % 4) * 3 Byte notwendig.
|
||||
*/
|
||||
static void RowARGB32ToRGB15_INTERLEAVED(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
||||
{
|
||||
static void RowARGB32ToRGB15_INTERLEAVED(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
||||
unsigned int BlockFillCount = 0;
|
||||
unsigned int AlphaBlock = 0;
|
||||
for (unsigned int i = 0; i < Width; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < Width; i++) {
|
||||
// Alphawert in den Alphablock schreiben
|
||||
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
||||
|
||||
|
||||
// Füllstand der Pixelblockes aktualisieren
|
||||
BlockFillCount++;
|
||||
|
||||
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
||||
if (BlockFillCount == 4 || i == (Width - 1))
|
||||
{
|
||||
if (BlockFillCount == 4 || i == (Width - 1)) {
|
||||
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
||||
// "left aligned" sind.
|
||||
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
||||
|
||||
// Alphablock schreiben
|
||||
*((unsigned int*)pDestData) = AlphaBlock;
|
||||
*((unsigned int *)pDestData) = AlphaBlock;
|
||||
pDestData += 4;
|
||||
|
||||
// Pixel konvertieren und schreiben
|
||||
|
@ -330,15 +318,13 @@ protected:
|
|||
}
|
||||
|
||||
/**
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_BGRA32 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
@brief Konvertiert eine Bildzeile mit ARGB Pixeldaten in das BS_GraphicEngine::CF_BGRA32 Farbformat.
|
||||
@param pSrcData ein Pointer auf die Quelldaten.
|
||||
@param pDestData ein Pointer auf den Zielpuffern.
|
||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||
*/
|
||||
static void RowARGB32ToABGR32(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
||||
{
|
||||
for (unsigned int i = 0; i < Width; ++i)
|
||||
{
|
||||
static void RowARGB32ToABGR32(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||
for (unsigned int i = 0; i < Width; ++i) {
|
||||
*pDestData++ = pSrcData[2];
|
||||
*pDestData++ = pSrcData[1];
|
||||
*pDestData++ = pSrcData[0];
|
||||
|
@ -351,25 +337,25 @@ protected:
|
|||
private:
|
||||
|
||||
/**
|
||||
@brief Erzeugt je eine Instanz aller BS_ImageLoader Klassen und fügt diese in eine interne Liste ein. Diese werden dann beim
|
||||
Laden von Bildern benutzt.
|
||||
@remark Die Klassen müssen in der Datei imageloader_ids.h eingetragen sein, damit sie an dieser Stelle berücksichtigt werden.
|
||||
@brief Erzeugt je eine Instanz aller BS_ImageLoader Klassen und fügt diese in eine interne Liste ein. Diese werden dann beim
|
||||
Laden von Bildern benutzt.
|
||||
@remark Die Klassen müssen in der Datei imageloader_ids.h eingetragen sein, damit sie an dieser Stelle berücksichtigt werden.
|
||||
*/
|
||||
static void _InitializeLoaderList();
|
||||
|
||||
/**
|
||||
@brief Zerstört alle Instanzen von BS_ImageLoader Klassen, die in dieser Klasse registriert sind.
|
||||
@brief Zerstört alle Instanzen von BS_ImageLoader Klassen, die in dieser Klasse registriert sind.
|
||||
*/
|
||||
static void _DeinitializeLoaderList();
|
||||
|
||||
/**
|
||||
@brief Sucht zu Bilddaten ein BS_ImageLoader Objekt, dass die Bilddaten dekodieren kann.
|
||||
@return Gibt einen Pointer auf ein passendes BS_ImageLoader Objekt zurück, oder NULL, wenn kein passendes Objekt gefunden wurde.
|
||||
@brief Sucht zu Bilddaten ein BS_ImageLoader Objekt, dass die Bilddaten dekodieren kann.
|
||||
@return Gibt einen Pointer auf ein passendes BS_ImageLoader Objekt zurück, oder NULL, wenn kein passendes Objekt gefunden wurde.
|
||||
*/
|
||||
static BS_ImageLoader* _FindSuitableImageLoader(const char* pFileData, unsigned int FileSize);
|
||||
static BS_ImageLoader *_FindSuitableImageLoader(const char *pFileData, unsigned int FileSize);
|
||||
|
||||
static std::list<BS_ImageLoader*> _ImageLoaderList; // Die Liste aller BS_ImageLoader-Objekte
|
||||
static bool _ImageLoaderListInitialized; // Gibt an, ob die Liste schon intialisiert wurde
|
||||
static std::list<BS_ImageLoader *> _ImageLoaderList; // Die Liste aller BS_ImageLoader-Objekte
|
||||
static bool _ImageLoaderListInitialized; // Gibt an, ob die Liste schon intialisiert wurde
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,12 +33,12 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
imageloader_ids.h
|
||||
-----------------
|
||||
In dieser Datei sind alle ImageLoader verzeichnet.
|
||||
JEDER neuer ImageLoader muss hier eingetragen werden, ansonsten wird er beim Laden eines Bildes nicht berücksichtigt.
|
||||
imageloader_ids.h
|
||||
-----------------
|
||||
In dieser Datei sind alle ImageLoader verzeichnet.
|
||||
JEDER neuer ImageLoader muss hier eingetragen werden, ansonsten wird er beim Laden eines Bildes nicht berücksichtigt.
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#include "sword25/gfx/image/imageloader.h"
|
||||
|
@ -51,9 +51,8 @@ namespace Sword25 {
|
|||
|
||||
// Die Tabelle enthält Pointer auf statische Member-Funktionen innerhalb der Klassen, die eine Instanz der Klasse
|
||||
// erzeugen
|
||||
typedef BS_ImageLoader* (*BS_IMAGELOADER_NEW)();
|
||||
const BS_IMAGELOADER_NEW BS_IMAGELOADER_IDS[] =
|
||||
{
|
||||
typedef BS_ImageLoader*(*BS_IMAGELOADER_NEW)();
|
||||
const BS_IMAGELOADER_NEW BS_IMAGELOADER_IDS[] = {
|
||||
BS_PNGLoader::CreateInstance,
|
||||
BS_B25SLoader::CreateInstance,
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,66 +48,58 @@ namespace Sword25 {
|
|||
// Konstruktor / Destruktor
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_PNGLoader::BS_PNGLoader()
|
||||
{
|
||||
BS_PNGLoader::BS_PNGLoader() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Laden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
memcpy(data, (char*)png_ptr->io_ptr, length);
|
||||
png_ptr->io_ptr = (void*)((png_size_t)png_ptr->io_ptr + length);
|
||||
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||
memcpy(data, (char *)png_ptr->io_ptr, length);
|
||||
png_ptr->io_ptr = (void *)((png_size_t)png_ptr->io_ptr + length);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int & Width, int & Height, int & Pitch)
|
||||
{
|
||||
bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int &Width, int &Height, int &Pitch) {
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
png_bytep RawDataBuffer = NULL;
|
||||
png_bytep* pRowPtr = NULL;
|
||||
png_bytep RawDataBuffer = NULL;
|
||||
png_bytep *pRowPtr = NULL;
|
||||
|
||||
int BitDepth;
|
||||
int ColorType;
|
||||
int InterlaceType;
|
||||
int i;
|
||||
int BitDepth;
|
||||
int ColorType;
|
||||
int InterlaceType;
|
||||
int i;
|
||||
|
||||
// Zielfarbformat überprüfen
|
||||
if (ColorFormat != BS_GraphicEngine::CF_RGB16 &&
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB15 &&
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB16_INTERLEAVED &&
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB15_INTERLEAVED &&
|
||||
ColorFormat != BS_GraphicEngine::CF_ARGB32 &&
|
||||
ColorFormat != BS_GraphicEngine::CF_ABGR32)
|
||||
{
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB15 &&
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB16_INTERLEAVED &&
|
||||
ColorFormat != BS_GraphicEngine::CF_RGB15_INTERLEAVED &&
|
||||
ColorFormat != BS_GraphicEngine::CF_ARGB32 &&
|
||||
ColorFormat != BS_GraphicEngine::CF_ABGR32) {
|
||||
BS_LOG_ERRORLN("Illegal or unsupported color format.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// PNG Signatur überprüfen
|
||||
if (!png_check_sig(reinterpret_cast<png_bytep>(const_cast<char *>(FileDataPtr)), 8))
|
||||
{
|
||||
if (!png_check_sig(reinterpret_cast<png_bytep>(const_cast<char *>(FileDataPtr)), 8)) {
|
||||
throw(0);
|
||||
}
|
||||
|
||||
// Die beiden PNG Strukturen erstellen
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
if (!png_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
if (!info_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
@ -116,13 +108,13 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
if (setjmp(png_jmpbuf(png_ptr))) throw(0);
|
||||
|
||||
// Alternative Lesefunktion benutzen
|
||||
png_set_read_fn(png_ptr, (void*)FileDataPtr, png_user_read_data);
|
||||
png_set_read_fn(png_ptr, (void *)FileDataPtr, png_user_read_data);
|
||||
|
||||
// PNG Header einlesen
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
// PNG Informationen auslesen
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, &InterlaceType, NULL, NULL);
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, &InterlaceType, NULL, NULL);
|
||||
|
||||
// Pitch des Ausgabebildes berechnen
|
||||
Pitch = BS_GraphicEngine::CalcPitch(ColorFormat, Width);
|
||||
|
@ -130,8 +122,7 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
// Speicher für die endgültigen Bilddaten reservieren
|
||||
// Dieses geschieht vor dem reservieren von Speicher für temporäre Bilddaten um die Fragmentierung des Speichers gering zu halten
|
||||
UncompressedDataPtr = new char[Pitch * Height];
|
||||
if (!UncompressedDataPtr)
|
||||
{
|
||||
if (!UncompressedDataPtr) {
|
||||
BS_LOG_ERRORLN("Could not allocate memory for output image.");
|
||||
throw(0);
|
||||
}
|
||||
|
@ -146,7 +137,7 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png_ptr);
|
||||
if (ColorType == PNG_COLOR_TYPE_GRAY ||
|
||||
ColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
ColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
png_set_bgr(png_ptr);
|
||||
|
@ -156,62 +147,58 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
|
||||
// Nachdem die Transformationen registriert wurden, werden die Bilddaten erneut eingelesen
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||
|
||||
// PNGs ohne Interlacing werden Zeilenweise eingelesen
|
||||
if (InterlaceType == PNG_INTERLACE_NONE)
|
||||
{
|
||||
if (InterlaceType == PNG_INTERLACE_NONE) {
|
||||
// Speicher für eine Bildzeile reservieren
|
||||
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
||||
if (!RawDataBuffer)
|
||||
{
|
||||
if (!RawDataBuffer) {
|
||||
BS_LOG_ERRORLN("Could not allocate memory for row buffer.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
// Bilddaten zeilenweise einlesen und in das gewünschte Zielformat konvertieren
|
||||
for (i = 0; i < Height; i++)
|
||||
{
|
||||
for (i = 0; i < Height; i++) {
|
||||
// Zeile einlesen
|
||||
png_read_row(png_ptr, RawDataBuffer, NULL);
|
||||
|
||||
// Zeile konvertieren
|
||||
switch (ColorFormat)
|
||||
{
|
||||
switch (ColorFormat) {
|
||||
case BS_GraphicEngine::CF_RGB16:
|
||||
RowARGB32ToRGB16((unsigned char*)RawDataBuffer,
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB16((unsigned char *)RawDataBuffer,
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB15:
|
||||
RowARGB32ToRGB15((unsigned char*)RawDataBuffer,
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB15((unsigned char *)RawDataBuffer,
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char*)RawDataBuffer,
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char *)RawDataBuffer,
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char*)RawDataBuffer,
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char *)RawDataBuffer,
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_ARGB32:
|
||||
memcpy(&UncompressedDataPtr[i * Pitch],
|
||||
RawDataBuffer,
|
||||
Pitch);
|
||||
RawDataBuffer,
|
||||
Pitch);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_ABGR32:
|
||||
RowARGB32ToABGR32((unsigned char*)RawDataBuffer,
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToABGR32((unsigned char *)RawDataBuffer,
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -220,20 +207,17 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
}
|
||||
}
|
||||
// PNGs mit Interlacing werden an einem Stück eingelesen
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Speicher für das komplette Bild reservieren
|
||||
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr) * Height];
|
||||
if (!RawDataBuffer)
|
||||
{
|
||||
if (!RawDataBuffer) {
|
||||
BS_LOG_ERRORLN("Could not allocate memory for raw image buffer.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
// Speicher für die Rowpointer reservieren
|
||||
pRowPtr = new png_bytep[Height];
|
||||
if (!pRowPtr)
|
||||
{
|
||||
if (!pRowPtr) {
|
||||
BS_LOG_ERRORLN("Could not allocate memory for row pointers.");
|
||||
throw(0);
|
||||
}
|
||||
|
@ -246,41 +230,40 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
png_read_image(png_ptr, pRowPtr);
|
||||
|
||||
// Bilddaten zeilenweise in das gewünschte Ausgabeformat konvertieren
|
||||
switch (ColorFormat)
|
||||
{
|
||||
switch (ColorFormat) {
|
||||
case BS_GraphicEngine::CF_RGB16:
|
||||
for (i = 0; i < Height; i++)
|
||||
RowARGB32ToRGB16((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB16((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB15:
|
||||
for (i = 0; i < Height; i++)
|
||||
RowARGB32ToRGB15((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB15((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
||||
for (i = 0; i < Height; i++)
|
||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
||||
for (i = 0; i < Height; i++)
|
||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||
Width);
|
||||
break;
|
||||
|
||||
case BS_GraphicEngine::CF_ARGB32:
|
||||
for (i = 0; i < Height; i++)
|
||||
memcpy(&UncompressedDataPtr[i * Pitch],
|
||||
&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)],
|
||||
Pitch);
|
||||
&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)],
|
||||
Pitch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -296,8 +279,7 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
delete[] RawDataBuffer;
|
||||
}
|
||||
|
||||
catch(int)
|
||||
{
|
||||
catch (int) {
|
||||
delete[] pRowPtr;
|
||||
delete[] RawDataBuffer;
|
||||
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
|
@ -313,40 +295,35 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int & Width, int & Height, int & Pitch)
|
||||
{
|
||||
bool BS_PNGLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int &Width, int &Height, int &Pitch) {
|
||||
return DoDecodeImage(FileDataPtr, FileSize, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
||||
{
|
||||
bool BS_PNGLoader::DoImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||
// PNG Signatur überprüfen
|
||||
if (!DoIsCorrectImageFormat(FileDataPtr, FileSize)) return false;
|
||||
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Die beiden PNG Strukturen erstellen
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
if (!png_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
if (!info_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
// Alternative Lesefunktion benutzen
|
||||
png_set_read_fn(png_ptr, (void*)FileDataPtr, png_user_read_data);
|
||||
png_set_read_fn(png_ptr, (void *)FileDataPtr, png_user_read_data);
|
||||
|
||||
// PNG Header einlesen
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
@ -354,7 +331,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
|||
// PNG Informationen auslesen
|
||||
int BitDepth;
|
||||
int ColorType;
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||
|
||||
// PNG-ColorType in BS ColorFormat konvertieren.
|
||||
if (ColorType & PNG_COLOR_MASK_ALPHA || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
|
@ -366,8 +343,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
|||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
}
|
||||
|
||||
catch (int)
|
||||
{
|
||||
catch (int) {
|
||||
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
if (info_ptr) png_destroy_read_struct(NULL, &info_ptr, NULL);
|
||||
|
||||
|
@ -381,8 +357,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::ImageProperties(const char* FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
||||
{
|
||||
bool BS_PNGLoader::ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||
return DoImageProperties(FileDataPtr, FileSize, ColorFormat, Width, Height);
|
||||
}
|
||||
|
||||
|
@ -390,18 +365,16 @@ bool BS_PNGLoader::ImageProperties(const char* FileDataPtr, unsigned int FileSiz
|
|||
// Header überprüfen
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::DoIsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize)
|
||||
{
|
||||
bool BS_PNGLoader::DoIsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||
if (FileSize > 8)
|
||||
return png_check_sig((unsigned char*)FileDataPtr, 8) ? true : false;
|
||||
return png_check_sig((unsigned char *)FileDataPtr, 8) ? true : false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_PNGLoader::IsCorrectImageFormat(const char* FileDataPtr, unsigned int FileSize)
|
||||
{
|
||||
bool BS_PNGLoader::IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||
return DoIsCorrectImageFormat(FileDataPtr, FileSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,11 +33,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
BS_PNGLoader
|
||||
------------
|
||||
BS_ImageLoader-Klasse zum Laden von PNG-Dateien
|
||||
BS_PNGLoader
|
||||
------------
|
||||
BS_ImageLoader-Klasse zum Laden von PNG-Dateien
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_PNGLOADER2_H
|
||||
|
@ -50,32 +50,30 @@
|
|||
namespace Sword25 {
|
||||
|
||||
// Klassendefinition
|
||||
class BS_PNGLoader : public BS_ImageLoader
|
||||
{
|
||||
class BS_PNGLoader : public BS_ImageLoader {
|
||||
public:
|
||||
static BS_ImageLoader* CreateInstance()
|
||||
{
|
||||
#include "sword25/kernel/memlog_off.h"
|
||||
return (BS_ImageLoader*) new BS_PNGLoader();
|
||||
#include "sword25/kernel/memlog_on.h"
|
||||
static BS_ImageLoader *CreateInstance() {
|
||||
#include "sword25/kernel/memlog_off.h"
|
||||
return (BS_ImageLoader *) new BS_PNGLoader();
|
||||
#include "sword25/kernel/memlog_on.h"
|
||||
}
|
||||
|
||||
// Alle virtuellen Methoden von BS_ImageLoader sind hier als static-Methode implementiert, damit sie von BS_B25SLoader aufgerufen werden können.
|
||||
// Die virtuellen Methoden rufen diese Methoden auf.
|
||||
static bool DoIsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
||||
static bool DoDecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int & Width, int & Height, int & Pitch);
|
||||
static bool DoImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
||||
static bool DoIsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||
static bool DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||
int &Width, int &Height, int &Pitch);
|
||||
static bool DoImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||
|
||||
protected:
|
||||
BS_PNGLoader();
|
||||
bool DecodeImage(const char * pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char * & pUncompressedData,
|
||||
int & Width, int & Height,
|
||||
int & Pitch);
|
||||
bool IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
||||
bool ImageProperties(const char * FileDatePtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
||||
bool DecodeImage(const char *pFileData, unsigned int FileSize,
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||
char * & pUncompressedData,
|
||||
int &Width, int &Height,
|
||||
int &Pitch);
|
||||
bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||
bool ImageProperties(const char *FileDatePtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -68,111 +68,94 @@ typedef int16_t s32;
|
|||
// Diese Klasse ist speziell dafür ausgestattet.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_VectorImage::SWFBitStream
|
||||
{
|
||||
class BS_VectorImage::SWFBitStream {
|
||||
public:
|
||||
SWFBitStream(const unsigned char * pData, unsigned int DataSize) :
|
||||
m_Pos(pData), m_End(pData + DataSize), m_WordMask(0)
|
||||
{}
|
||||
SWFBitStream(const unsigned char *pData, unsigned int DataSize) :
|
||||
m_Pos(pData), m_End(pData + DataSize), m_WordMask(0)
|
||||
{}
|
||||
|
||||
inline u32 GetBits(unsigned int BitCount)
|
||||
{
|
||||
if (BitCount == 0 || BitCount > 32)
|
||||
{
|
||||
throw(runtime_error("SWFBitStream::GetBits() must read at least 1 and at most 32 bits at a time"));
|
||||
}
|
||||
inline u32 GetBits(unsigned int BitCount) {
|
||||
if (BitCount == 0 || BitCount > 32) {
|
||||
throw(runtime_error("SWFBitStream::GetBits() must read at least 1 and at most 32 bits at a time"));
|
||||
}
|
||||
|
||||
u32 value = 0;
|
||||
while (BitCount)
|
||||
{
|
||||
if (m_WordMask == 0) FlushByte();
|
||||
u32 value = 0;
|
||||
while (BitCount) {
|
||||
if (m_WordMask == 0) FlushByte();
|
||||
|
||||
value <<= 1;
|
||||
value |= ((m_Word & m_WordMask) != 0) ? 1 : 0;
|
||||
m_WordMask >>= 1;
|
||||
value <<= 1;
|
||||
value |= ((m_Word & m_WordMask) != 0) ? 1 : 0;
|
||||
m_WordMask >>= 1;
|
||||
|
||||
--BitCount;
|
||||
}
|
||||
--BitCount;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
inline s32 GetSignedBits(unsigned int BitCount)
|
||||
{
|
||||
// Bits einlesen
|
||||
u32 Temp = GetBits(BitCount);
|
||||
inline s32 GetSignedBits(unsigned int BitCount) {
|
||||
// Bits einlesen
|
||||
u32 Temp = GetBits(BitCount);
|
||||
|
||||
// Falls das Sign-Bit gesetzt ist, den Rest des Rückgabewertes mit 1-Bits auffüllen (Sign Extension)
|
||||
if (Temp & 1 << (BitCount - 1))
|
||||
return (0xffffffff << BitCount) | Temp;
|
||||
else
|
||||
return Temp;
|
||||
}
|
||||
// Falls das Sign-Bit gesetzt ist, den Rest des Rückgabewertes mit 1-Bits auffüllen (Sign Extension)
|
||||
if (Temp & 1 << (BitCount - 1))
|
||||
return (0xffffffff << BitCount) | Temp;
|
||||
else
|
||||
return Temp;
|
||||
}
|
||||
|
||||
inline u32 GetU32()
|
||||
{
|
||||
u32 Byte1 = GetU8();
|
||||
u32 Byte2 = GetU8();
|
||||
u32 Byte3 = GetU8();
|
||||
u32 Byte4 = GetU8();
|
||||
inline u32 GetU32() {
|
||||
u32 Byte1 = GetU8();
|
||||
u32 Byte2 = GetU8();
|
||||
u32 Byte3 = GetU8();
|
||||
u32 Byte4 = GetU8();
|
||||
|
||||
return Byte1 | (Byte2 << 8) | (Byte3 << 16) | (Byte4 << 24);
|
||||
}
|
||||
return Byte1 | (Byte2 << 8) | (Byte3 << 16) | (Byte4 << 24);
|
||||
}
|
||||
|
||||
inline u16 GetU16()
|
||||
{
|
||||
u32 Byte1 = GetU8();
|
||||
u32 Byte2 = GetU8();
|
||||
inline u16 GetU16() {
|
||||
u32 Byte1 = GetU8();
|
||||
u32 Byte2 = GetU8();
|
||||
|
||||
return Byte1 | (Byte2 << 8);
|
||||
}
|
||||
return Byte1 | (Byte2 << 8);
|
||||
}
|
||||
|
||||
inline u8 GetU8()
|
||||
{
|
||||
FlushByte();
|
||||
u8 Value = m_Word;
|
||||
m_WordMask = 0;
|
||||
FlushByte();
|
||||
inline u8 GetU8() {
|
||||
FlushByte();
|
||||
u8 Value = m_Word;
|
||||
m_WordMask = 0;
|
||||
FlushByte();
|
||||
|
||||
return Value;
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
|
||||
inline void FlushByte()
|
||||
{
|
||||
if (m_WordMask != 128)
|
||||
{
|
||||
if (m_Pos >= m_End)
|
||||
{
|
||||
throw(runtime_error("Attempted to read past end of file"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Word = *m_Pos++;
|
||||
m_WordMask = 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void FlushByte() {
|
||||
if (m_WordMask != 128) {
|
||||
if (m_Pos >= m_End) {
|
||||
throw(runtime_error("Attempted to read past end of file"));
|
||||
} else {
|
||||
m_Word = *m_Pos++;
|
||||
m_WordMask = 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void SkipBytes(unsigned int SkipLength)
|
||||
{
|
||||
FlushByte();
|
||||
if (m_Pos + SkipLength >= m_End)
|
||||
{
|
||||
throw(runtime_error("Attempted to read past end of file"));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Pos += SkipLength;
|
||||
m_Word = *(m_Pos - 1);
|
||||
}
|
||||
}
|
||||
inline void SkipBytes(unsigned int SkipLength) {
|
||||
FlushByte();
|
||||
if (m_Pos + SkipLength >= m_End) {
|
||||
throw(runtime_error("Attempted to read past end of file"));
|
||||
} else {
|
||||
m_Pos += SkipLength;
|
||||
m_Word = *(m_Pos - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned char * m_Pos;
|
||||
const unsigned char * m_End;
|
||||
const unsigned char *m_Pos;
|
||||
const unsigned char *m_End;
|
||||
|
||||
u8 m_Word;
|
||||
unsigned int m_WordMask;
|
||||
u8 m_Word;
|
||||
unsigned int m_WordMask;
|
||||
};
|
||||
|
||||
|
||||
|
@ -180,69 +163,66 @@ private:
|
|||
// Konstanten und Hilfsfunktionen
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konstanten
|
||||
// -----------------------------------------------------------------------------
|
||||
namespace {
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konstanten
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const u32 MAX_ACCEPTED_FLASH_VERSION = 3; // Die höchste Flash-Dateiversion, die vom Lader akzeptiert wird
|
||||
const u32 MAX_ACCEPTED_FLASH_VERSION = 3; // Die höchste Flash-Dateiversion, die vom Lader akzeptiert wird
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konvertiert SWF-Rechteckdaten in einem Bitstrom in BS_Rect-Objekte
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konvertiert SWF-Rechteckdaten in einem Bitstrom in BS_Rect-Objekte
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Rect FlashRectToBSRect(BS_VectorImage::SWFBitStream & bs)
|
||||
{
|
||||
bs.FlushByte();
|
||||
BS_Rect FlashRectToBSRect(BS_VectorImage::SWFBitStream &bs) {
|
||||
bs.FlushByte();
|
||||
|
||||
// Feststellen mit wie vielen Bits die einzelnen Komponenten kodiert sind
|
||||
u32 BitsPerValue = bs.GetBits(5);
|
||||
// Feststellen mit wie vielen Bits die einzelnen Komponenten kodiert sind
|
||||
u32 BitsPerValue = bs.GetBits(5);
|
||||
|
||||
// Die einzelnen Komponenten einlesen
|
||||
s32 XMin = bs.GetSignedBits(BitsPerValue);
|
||||
s32 XMax = bs.GetSignedBits(BitsPerValue);
|
||||
s32 YMin = bs.GetSignedBits(BitsPerValue);
|
||||
s32 YMax = bs.GetSignedBits(BitsPerValue);
|
||||
// Die einzelnen Komponenten einlesen
|
||||
s32 XMin = bs.GetSignedBits(BitsPerValue);
|
||||
s32 XMax = bs.GetSignedBits(BitsPerValue);
|
||||
s32 YMin = bs.GetSignedBits(BitsPerValue);
|
||||
s32 YMax = bs.GetSignedBits(BitsPerValue);
|
||||
|
||||
return BS_Rect(XMin, YMin, XMax + 1, YMax + 1);
|
||||
return BS_Rect(XMin, YMin, XMax + 1, YMax + 1);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konvertiert SWF-Farben in AntiGrain Farben
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
agg::rgba8 FlashColorToAGGRGBA8(unsigned int FlashColor) {
|
||||
agg::rgba8 ResultColor((FlashColor >> 16) & 0xff, (FlashColor >> 8) & 0xff, FlashColor & 0xff, FlashColor >> 24);
|
||||
ResultColor.premultiply();
|
||||
return ResultColor;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Berechnet die Bounding-Box eines BS_VectorImageElement
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct CBBGetId {
|
||||
CBBGetId(const BS_VectorImageElement &VectorImageElement_) : VectorImageElement(VectorImageElement_) {}
|
||||
unsigned operator [](unsigned i) const {
|
||||
return VectorImageElement.GetPathInfo(i).GetID();
|
||||
}
|
||||
const BS_VectorImageElement &VectorImageElement;
|
||||
};
|
||||
|
||||
BS_Rect CalculateBoundingBox(const BS_VectorImageElement &VectorImageElement) {
|
||||
agg::path_storage Path = VectorImageElement.GetPaths();
|
||||
CBBGetId IdSource(VectorImageElement);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Konvertiert SWF-Farben in AntiGrain Farben
|
||||
// -----------------------------------------------------------------------------
|
||||
double x1, x2, y1, y2;
|
||||
agg::bounding_rect(Path, IdSource, 0, VectorImageElement.GetPathCount(), &x1, &y1, &x2, &y2);
|
||||
|
||||
agg::rgba8 FlashColorToAGGRGBA8(unsigned int FlashColor)
|
||||
{
|
||||
agg::rgba8 ResultColor((FlashColor >> 16) & 0xff, (FlashColor >> 8) & 0xff, FlashColor & 0xff, FlashColor >> 24);
|
||||
ResultColor.premultiply();
|
||||
return ResultColor;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Berechnet die Bounding-Box eines BS_VectorImageElement
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct CBBGetId
|
||||
{
|
||||
CBBGetId(const BS_VectorImageElement & VectorImageElement_) : VectorImageElement(VectorImageElement_) {}
|
||||
unsigned operator [] (unsigned i) const { return VectorImageElement.GetPathInfo(i).GetID(); }
|
||||
const BS_VectorImageElement & VectorImageElement;
|
||||
};
|
||||
|
||||
BS_Rect CalculateBoundingBox(const BS_VectorImageElement & VectorImageElement)
|
||||
{
|
||||
agg::path_storage Path = VectorImageElement.GetPaths();
|
||||
CBBGetId IdSource(VectorImageElement);
|
||||
|
||||
double x1, x2, y1, y2;
|
||||
agg::bounding_rect(Path, IdSource, 0, VectorImageElement.GetPathCount(), &x1, &y1, &x2, &y2);
|
||||
|
||||
return BS_Rect(static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2) + 1, static_cast<int>(y2) + 1);
|
||||
}
|
||||
return BS_Rect(static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2) + 1, static_cast<int>(y2) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,41 +230,36 @@ namespace
|
|||
// Konstruktion
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int FileSize, bool & Success)
|
||||
{
|
||||
BS_VectorImage::BS_VectorImage(const unsigned char *pFileData, unsigned int FileSize, bool &Success) {
|
||||
Success = false;
|
||||
|
||||
// Bitstream-Objekt erzeugen
|
||||
// Im Folgenden werden die Dateidaten aus diesem ausgelesen.
|
||||
SWFBitStream bs(pFileData, FileSize);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// SWF-Signatur überprüfen
|
||||
u32 Signature[3];
|
||||
Signature[0] = bs.GetU8();
|
||||
Signature[1] = bs.GetU8();
|
||||
Signature[2] = bs.GetU8();
|
||||
if (Signature[0] != 'F' ||
|
||||
Signature[1] != 'W' ||
|
||||
Signature[2] != 'S')
|
||||
{
|
||||
Signature[1] != 'W' ||
|
||||
Signature[2] != 'S') {
|
||||
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
||||
return;
|
||||
}
|
||||
|
||||
// Versionsangabe überprüfen
|
||||
u32 Version = bs.GetU8();
|
||||
if (Version > MAX_ACCEPTED_FLASH_VERSION)
|
||||
{
|
||||
if (Version > MAX_ACCEPTED_FLASH_VERSION) {
|
||||
BS_LOG_ERRORLN("File is of version %d. Highest accepted version is %d.", Version, MAX_ACCEPTED_FLASH_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
// Dateigröße auslesen und mit der tatsächlichen Größe vergleichen
|
||||
u32 StoredFileSize = bs.GetU32();
|
||||
if (StoredFileSize != FileSize)
|
||||
{
|
||||
if (StoredFileSize != FileSize) {
|
||||
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
||||
return;
|
||||
}
|
||||
|
@ -299,8 +274,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
|||
// Tags parsen
|
||||
// Da wir uns nur für das erste DefineShape-Tag interessieren
|
||||
bool KeepParsing = true;
|
||||
while (KeepParsing)
|
||||
{
|
||||
while (KeepParsing) {
|
||||
// Tags beginnen immer an Bytegrenzen
|
||||
bs.FlushByte();
|
||||
|
||||
|
@ -310,8 +284,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
|||
u32 TagLength = TagTypeAndLength & 0x3f;
|
||||
if (TagLength == 0x3f) TagLength = bs.GetU32();
|
||||
|
||||
switch (TagType)
|
||||
{
|
||||
switch (TagType) {
|
||||
case 2:
|
||||
// DefineShape
|
||||
Success = ParseDefineShape(2, bs);
|
||||
|
@ -330,8 +303,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
|||
}
|
||||
}
|
||||
|
||||
catch (runtime_error & e)
|
||||
{
|
||||
catch (runtime_error &e) {
|
||||
// Fehler loggen und Funktion verlassen
|
||||
// Success ist somit "false" und signalisiert dem Programmierer, dass die Konstruktion fehlgeschlagen ist.
|
||||
BS_LOG_ERRORLN("The following exception occured while parsing a SWF-file: %s", e.what());
|
||||
|
@ -345,8 +317,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||
{
|
||||
bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream &bs) {
|
||||
u32 ShapeID = bs.GetU16();
|
||||
|
||||
// Bounding Box auslesen
|
||||
|
@ -368,13 +339,11 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
// ------------------
|
||||
|
||||
bool EndOfShapeDiscovered = false;
|
||||
while (!EndOfShapeDiscovered)
|
||||
{
|
||||
while (!EndOfShapeDiscovered) {
|
||||
u32 TypeFlag = bs.GetBits(1);
|
||||
|
||||
// Non-Edge Record
|
||||
if (TypeFlag == 0)
|
||||
{
|
||||
if (TypeFlag == 0) {
|
||||
// Feststellen welche Parameter gesetzt werden
|
||||
u32 StateNewStyles = bs.GetBits(1);
|
||||
u32 StateLineStyle = bs.GetBits(1);
|
||||
|
@ -386,43 +355,37 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
if (!StateNewStyles && !StateLineStyle && !StateFillStyle0 && !StateFillStyle1 && !StateMoveTo)
|
||||
EndOfShapeDiscovered = true;
|
||||
// Parameter dekodieren
|
||||
else
|
||||
{
|
||||
else {
|
||||
s32 MoveDeltaX = 0;
|
||||
s32 MoveDeltaY = 0;
|
||||
if (StateMoveTo)
|
||||
{
|
||||
if (StateMoveTo) {
|
||||
u32 MoveToBits = bs.GetBits(5);
|
||||
MoveDeltaX = bs.GetSignedBits(MoveToBits);
|
||||
MoveDeltaY = bs.GetSignedBits(MoveToBits);
|
||||
}
|
||||
|
||||
if (StateFillStyle0)
|
||||
{
|
||||
if (StateFillStyle0) {
|
||||
if (NumFillBits > 0)
|
||||
FillStyle0 = bs.GetBits(NumFillBits);
|
||||
else
|
||||
FillStyle0 = 0;
|
||||
}
|
||||
|
||||
if (StateFillStyle1)
|
||||
{
|
||||
if (StateFillStyle1) {
|
||||
if (NumFillBits > 0)
|
||||
FillStyle1 = bs.GetBits(NumFillBits);
|
||||
else
|
||||
FillStyle1 = 0;
|
||||
}
|
||||
|
||||
if (StateLineStyle)
|
||||
{
|
||||
if (StateLineStyle) {
|
||||
if (NumLineBits)
|
||||
LineStyle = bs.GetBits(NumLineBits);
|
||||
else
|
||||
NumLineBits = 0;
|
||||
}
|
||||
|
||||
if (StateNewStyles)
|
||||
{
|
||||
if (StateNewStyles) {
|
||||
// An dieser Stelle werden in Flash die alten Style-Definitionen verworfen und mit den neuen überschrieben.
|
||||
// Es wird ein neues Element begonnen.
|
||||
m_Elements.resize(m_Elements.size() + 1);
|
||||
|
@ -430,8 +393,7 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
}
|
||||
|
||||
// Ein neuen Pfad erzeugen, es sei denn, es wurden nur neue Styles definiert
|
||||
if (StateLineStyle || StateFillStyle0 || StateFillStyle1 || StateMoveTo)
|
||||
{
|
||||
if (StateLineStyle || StateFillStyle0 || StateFillStyle1 || StateMoveTo) {
|
||||
// Letzte Zeichenposition merken, beim Aufruf von start_new_path() wird die Zeichenpostionen auf 0, 0 zurückgesetzt
|
||||
double LastX = m_Elements.back().m_Paths.last_x();
|
||||
double LastY = m_Elements.back().m_Paths.last_y();
|
||||
|
@ -449,14 +411,12 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
}
|
||||
}
|
||||
// Edge Record
|
||||
else
|
||||
{
|
||||
else {
|
||||
u32 EdgeFlag = bs.GetBits(1);
|
||||
u32 NumBits = bs.GetBits(4) + 2;
|
||||
|
||||
// Curved edge
|
||||
if (EdgeFlag == 0)
|
||||
{
|
||||
if (EdgeFlag == 0) {
|
||||
s32 ControlDeltaX = bs.GetSignedBits(NumBits);
|
||||
s32 ControlDeltaY = bs.GetSignedBits(NumBits);
|
||||
s32 AnchorDeltaX = bs.GetSignedBits(NumBits);
|
||||
|
@ -469,19 +429,15 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
m_Elements.back().m_Paths.curve3(ControlX, ControlY, AnchorX, AnchorY);
|
||||
}
|
||||
// Staight edge
|
||||
else
|
||||
{
|
||||
else {
|
||||
s32 DeltaX = 0;
|
||||
s32 DeltaY = 0;
|
||||
|
||||
u32 GeneralLineFlag = bs.GetBits(1);
|
||||
if (GeneralLineFlag)
|
||||
{
|
||||
if (GeneralLineFlag) {
|
||||
DeltaX = bs.GetSignedBits(NumBits);
|
||||
DeltaY = bs.GetSignedBits(NumBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
u32 VertLineFlag = bs.GetBits(1);
|
||||
if (VertLineFlag)
|
||||
DeltaY = bs.GetSignedBits(NumBits);
|
||||
|
@ -504,8 +460,7 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsigned int & NumFillBits, unsigned int & NumLineBits)
|
||||
{
|
||||
bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream &bs, unsigned int &NumFillBits, unsigned int &NumLineBits) {
|
||||
bs.FlushByte();
|
||||
|
||||
// Fillstyles parsen
|
||||
|
@ -518,15 +473,12 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
|||
// Alle Fillstyles einlesen, falls ein Fillstyle mit Typ != 0 gefunden wird, wird das Parsen abgebrochen.
|
||||
// Es wird nur "solid fill" (Typ 0) unterstützt.
|
||||
m_Elements.back().m_FillStyles.reserve(FillStyleCount);
|
||||
for (unsigned int i = 0; i < FillStyleCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < FillStyleCount; ++i) {
|
||||
u8 Type = bs.GetU8();
|
||||
u32 Color;
|
||||
if (ShapeType == 3)
|
||||
{
|
||||
if (ShapeType == 3) {
|
||||
Color = (bs.GetU8() << 16) | (bs.GetU8() << 8) | bs.GetU8() | (bs.GetU8() << 24);
|
||||
}
|
||||
else
|
||||
} else
|
||||
Color = bs.GetBits(24) | (0xff << 24);
|
||||
if (Type != 0) return false;
|
||||
|
||||
|
@ -542,8 +494,7 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
|||
|
||||
// Alle Linestyles einlesen
|
||||
m_Elements.back().m_LineStyles.reserve(LineStyleCount);
|
||||
for (unsigned int i = 0; i < LineStyleCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < LineStyleCount; ++i) {
|
||||
double Width = bs.GetU16();
|
||||
u32 Color;
|
||||
if (ShapeType == 3)
|
||||
|
@ -564,8 +515,7 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
||||
{
|
||||
bool BS_VectorImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
@ -573,16 +523,14 @@ bool BS_VectorImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_VectorImage::GetPixel(int X, int Y)
|
||||
{
|
||||
unsigned int BS_VectorImage::GetPixel(int X, int Y) {
|
||||
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
||||
{
|
||||
bool BS_VectorImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||
BS_LOG_ERRORLN("SetContent() is not supported.");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,22 +53,29 @@ namespace Sword25 {
|
|||
class BS_VectorImage;
|
||||
|
||||
/**
|
||||
@brief Pfadinformationen zu BS_VectorImageElement Objekten
|
||||
@brief Pfadinformationen zu BS_VectorImageElement Objekten
|
||||
|
||||
Jedes BS_VectorImageElement besteht aus Kantenzügen, oder auch Pfaden. Jeder dieser Pfad hat Eigenschaften, die in Objekten diesen Typs
|
||||
gespeichert werden.
|
||||
Jedes BS_VectorImageElement besteht aus Kantenzügen, oder auch Pfaden. Jeder dieser Pfad hat Eigenschaften, die in Objekten diesen Typs
|
||||
gespeichert werden.
|
||||
*/
|
||||
|
||||
class BS_VectorPathInfo
|
||||
{
|
||||
class BS_VectorPathInfo {
|
||||
public:
|
||||
BS_VectorPathInfo(unsigned int ID, unsigned int LineStyle, unsigned int FillStyle0, unsigned int FillStyle1) :
|
||||
m_ID(ID), m_LineStyle(LineStyle), m_FillStyle0(FillStyle0), m_FillStyle1(FillStyle1) {};
|
||||
m_ID(ID), m_LineStyle(LineStyle), m_FillStyle0(FillStyle0), m_FillStyle1(FillStyle1) {};
|
||||
|
||||
unsigned int GetID() const { return m_ID; }
|
||||
unsigned int GetLineStyle() const { return m_LineStyle; }
|
||||
unsigned int GetFillStyle0() const { return m_FillStyle0; }
|
||||
unsigned int GetFillStyle1() const { return m_FillStyle1; }
|
||||
unsigned int GetID() const {
|
||||
return m_ID;
|
||||
}
|
||||
unsigned int GetLineStyle() const {
|
||||
return m_LineStyle;
|
||||
}
|
||||
unsigned int GetFillStyle0() const {
|
||||
return m_FillStyle0;
|
||||
}
|
||||
unsigned int GetFillStyle1() const {
|
||||
return m_FillStyle1;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int m_ID;
|
||||
|
@ -79,106 +86,136 @@ private:
|
|||
|
||||
|
||||
/**
|
||||
@brief Ein Element eines Vektorbild. Ein BS_VectorImage besteht aus diesen Elementen, die jeweils einen Teil der Graphik definieren.
|
||||
Werden alle Elemente eines Vektorbildes übereinandergelegt, ergibt sich das komplette Bild.
|
||||
@brief Ein Element eines Vektorbild. Ein BS_VectorImage besteht aus diesen Elementen, die jeweils einen Teil der Graphik definieren.
|
||||
Werden alle Elemente eines Vektorbildes übereinandergelegt, ergibt sich das komplette Bild.
|
||||
*/
|
||||
class BS_VectorImageElement
|
||||
{
|
||||
friend BS_VectorImage;
|
||||
class BS_VectorImageElement {
|
||||
friend BS_VectorImage;
|
||||
public:
|
||||
const agg::path_storage & GetPaths() const { return m_Paths; }
|
||||
unsigned int GetPathCount() const { return m_PathInfos.size(); }
|
||||
const BS_VectorPathInfo & GetPathInfo(unsigned int PathNr) const { BS_ASSERT(PathNr < GetPathCount()); return m_PathInfos[PathNr]; }
|
||||
const agg::path_storage &GetPaths() const {
|
||||
return m_Paths;
|
||||
}
|
||||
unsigned int GetPathCount() const {
|
||||
return m_PathInfos.size();
|
||||
}
|
||||
const BS_VectorPathInfo &GetPathInfo(unsigned int PathNr) const {
|
||||
BS_ASSERT(PathNr < GetPathCount());
|
||||
return m_PathInfos[PathNr];
|
||||
}
|
||||
|
||||
double GetLineStyleWidth(unsigned int LineStyle) const
|
||||
{
|
||||
double GetLineStyleWidth(unsigned int LineStyle) const {
|
||||
BS_ASSERT(LineStyle < m_LineStyles.size());
|
||||
return m_LineStyles[LineStyle].Width;
|
||||
}
|
||||
|
||||
unsigned int GetLineStyleCount() const { return m_LineStyles.size(); }
|
||||
unsigned int GetLineStyleCount() const {
|
||||
return m_LineStyles.size();
|
||||
}
|
||||
|
||||
const agg::rgba8 & GetLineStyleColor(unsigned int LineStyle) const
|
||||
{
|
||||
const agg::rgba8 &GetLineStyleColor(unsigned int LineStyle) const {
|
||||
BS_ASSERT(LineStyle < m_LineStyles.size());
|
||||
return m_LineStyles[LineStyle].Color;
|
||||
}
|
||||
|
||||
unsigned int GetFillStyleCount() const { return m_FillStyles.size(); }
|
||||
unsigned int GetFillStyleCount() const {
|
||||
return m_FillStyles.size();
|
||||
}
|
||||
|
||||
const agg::rgba8 & GetFillStyleColor(unsigned int FillStyle) const
|
||||
{
|
||||
const agg::rgba8 &GetFillStyleColor(unsigned int FillStyle) const {
|
||||
BS_ASSERT(FillStyle < m_FillStyles.size());
|
||||
return m_FillStyles[FillStyle];
|
||||
}
|
||||
|
||||
const BS_Rect & GetBoundingBox() const { return m_BoundingBox; }
|
||||
const BS_Rect &GetBoundingBox() const {
|
||||
return m_BoundingBox;
|
||||
}
|
||||
|
||||
private:
|
||||
struct LineStyleType
|
||||
{
|
||||
LineStyleType(double Width_, const agg::rgba8 & Color_) : Width(Width_), Color(Color_) {};
|
||||
double Width;
|
||||
agg::rgba8 Color;
|
||||
struct LineStyleType {
|
||||
LineStyleType(double Width_, const agg::rgba8 &Color_) : Width(Width_), Color(Color_) {};
|
||||
double Width;
|
||||
agg::rgba8 Color;
|
||||
};
|
||||
|
||||
agg::path_storage m_Paths;
|
||||
Common::Array<BS_VectorPathInfo> m_PathInfos;
|
||||
Common::Array<LineStyleType> m_LineStyles;
|
||||
Common::Array<agg::rgba8> m_FillStyles;
|
||||
BS_Rect m_BoundingBox;
|
||||
agg::path_storage m_Paths;
|
||||
Common::Array<BS_VectorPathInfo> m_PathInfos;
|
||||
Common::Array<LineStyleType> m_LineStyles;
|
||||
Common::Array<agg::rgba8> m_FillStyles;
|
||||
BS_Rect m_BoundingBox;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@brief Eine Vektorgraphik
|
||||
@brief Eine Vektorgraphik
|
||||
|
||||
Objekte dieser Klasse enthalten die Informationen eines SWF-Shapes.
|
||||
Objekte dieser Klasse enthalten die Informationen eines SWF-Shapes.
|
||||
*/
|
||||
|
||||
class BS_VectorImage : public BS_Image
|
||||
{
|
||||
class BS_VectorImage : public BS_Image {
|
||||
public:
|
||||
BS_VectorImage(const unsigned char * pFileData, unsigned int FileSize, bool & Success);
|
||||
BS_VectorImage(const unsigned char *pFileData, unsigned int FileSize, bool &Success);
|
||||
|
||||
unsigned int GetElementCount() const { return m_Elements.size(); }
|
||||
const BS_VectorImageElement & GetElement(unsigned int ElementNr) const
|
||||
{
|
||||
unsigned int GetElementCount() const {
|
||||
return m_Elements.size();
|
||||
}
|
||||
const BS_VectorImageElement &GetElement(unsigned int ElementNr) const {
|
||||
BS_ASSERT(ElementNr < m_Elements.size());
|
||||
return m_Elements[ElementNr];
|
||||
}
|
||||
const BS_Rect & GetBoundingBox() const { return m_BoundingBox; }
|
||||
const BS_Rect &GetBoundingBox() const {
|
||||
return m_BoundingBox;
|
||||
}
|
||||
|
||||
//
|
||||
// Die abstrakten Methoden von BS_Image
|
||||
//
|
||||
virtual int GetWidth() const { return m_BoundingBox.GetWidth(); }
|
||||
virtual int GetHeight() const { return m_BoundingBox.GetHeight(); }
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
||||
virtual bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||
virtual int GetWidth() const {
|
||||
return m_BoundingBox.GetWidth();
|
||||
}
|
||||
virtual int GetHeight() const {
|
||||
return m_BoundingBox.GetHeight();
|
||||
}
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||
return BS_GraphicEngine::CF_ARGB32;
|
||||
}
|
||||
virtual bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||
virtual unsigned int GetPixel(int X, int Y);
|
||||
virtual bool IsBlitSource() const { return true; }
|
||||
virtual bool IsBlitTarget() const { return false; }
|
||||
virtual bool IsScalingAllowed() const { return true; }
|
||||
virtual bool IsFillingAllowed() const { return false; }
|
||||
virtual bool IsAlphaAllowed() const { return true; }
|
||||
virtual bool IsColorModulationAllowed() const { return true; }
|
||||
virtual bool IsSetContentAllowed() const { return false; }
|
||||
virtual bool IsBlitSource() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsBlitTarget() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsScalingAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsFillingAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsAlphaAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsColorModulationAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsSetContentAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect* pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
int Flipping = FLIP_NONE,
|
||||
BS_Rect *pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
|
||||
class SWFBitStream;
|
||||
|
||||
private:
|
||||
bool ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs);
|
||||
bool ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsigned int & NumFillBits, unsigned int & NumLineBits);
|
||||
bool ParseDefineShape(unsigned int ShapeType, SWFBitStream &bs);
|
||||
bool ParseStyles(unsigned int ShapeType, SWFBitStream &bs, unsigned int &NumFillBits, unsigned int &NumLineBits);
|
||||
|
||||
Common::Array<BS_VectorImageElement> m_Elements;
|
||||
BS_Rect m_BoundingBox;
|
||||
Common::Array<BS_VectorImageElement> m_Elements;
|
||||
BS_Rect m_BoundingBox;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -49,10 +49,9 @@ namespace Sword25 {
|
|||
// CompoundShape
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class CompoundShape
|
||||
{
|
||||
class CompoundShape {
|
||||
public:
|
||||
CompoundShape(const BS_VectorImageElement & VectorImageElement) :
|
||||
CompoundShape(const BS_VectorImageElement &VectorImageElement) :
|
||||
m_ImageElement(VectorImageElement),
|
||||
m_Path(VectorImageElement.GetPaths()),
|
||||
m_Affine(),
|
||||
|
@ -60,29 +59,28 @@ public:
|
|||
m_Trans(m_Curve, m_Affine)
|
||||
{}
|
||||
|
||||
unsigned operator [] (unsigned i) const
|
||||
{
|
||||
unsigned operator [](unsigned i) const {
|
||||
return m_ImageElement.GetPathInfo(i).GetID();
|
||||
}
|
||||
|
||||
unsigned paths() const { return m_ImageElement.GetPathCount(); }
|
||||
unsigned paths() const {
|
||||
return m_ImageElement.GetPathCount();
|
||||
}
|
||||
|
||||
void rewind(unsigned path_id)
|
||||
{
|
||||
void rewind(unsigned path_id) {
|
||||
m_Trans.rewind(path_id);
|
||||
}
|
||||
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
unsigned vertex(double *x, double *y) {
|
||||
return m_Trans.vertex(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
const BS_VectorImageElement & m_ImageElement;
|
||||
agg::path_storage m_Path;
|
||||
agg::trans_affine m_Affine;
|
||||
agg::conv_curve<agg::path_storage> m_Curve;
|
||||
agg::conv_transform< agg::conv_curve<agg::path_storage> > m_Trans;
|
||||
const BS_VectorImageElement &m_ImageElement;
|
||||
agg::path_storage m_Path;
|
||||
agg::trans_affine m_Affine;
|
||||
agg::conv_curve<agg::path_storage> m_Curve;
|
||||
agg::conv_transform< agg::conv_curve<agg::path_storage> > m_Trans;
|
||||
};
|
||||
|
||||
|
||||
|
@ -90,29 +88,25 @@ private:
|
|||
// StyleHandler
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class StyleHandler
|
||||
{
|
||||
class StyleHandler {
|
||||
public:
|
||||
StyleHandler(const BS_VectorImageElement & VectorImageElement) : m_ImageElement(VectorImageElement) {}
|
||||
StyleHandler(const BS_VectorImageElement &VectorImageElement) : m_ImageElement(VectorImageElement) {}
|
||||
|
||||
bool is_solid(unsigned int style) const
|
||||
{
|
||||
bool is_solid(unsigned int style) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
const agg::rgba8 & color(unsigned style) const
|
||||
{
|
||||
const agg::rgba8 &color(unsigned style) const {
|
||||
return m_ImageElement.GetFillStyleColor(style);
|
||||
}
|
||||
|
||||
void generate_span(agg::rgba8 * span, int x, int y, unsigned len, unsigned style)
|
||||
{
|
||||
void generate_span(agg::rgba8 *span, int x, int y, unsigned len, unsigned style) {
|
||||
// Wird nicht benutzt
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
const BS_VectorImageElement & m_ImageElement;
|
||||
const BS_VectorImageElement &m_ImageElement;
|
||||
};
|
||||
|
||||
|
||||
|
@ -121,21 +115,19 @@ private:
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_VectorImageRenderer::BS_VectorImageRenderer() :
|
||||
PixelFormat(rbuf)
|
||||
{
|
||||
PixelFormat(rbuf) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
||||
float ScaleFactorX, float ScaleFactorY,
|
||||
unsigned int & Width, unsigned int & Height,
|
||||
Common::Array<char> & ImageData,
|
||||
float LineScaleFactor,
|
||||
bool NoAlphaShapes)
|
||||
{
|
||||
bool BS_VectorImageRenderer::Render(const BS_VectorImage &VectorImage,
|
||||
float ScaleFactorX, float ScaleFactorY,
|
||||
unsigned int &Width, unsigned int &Height,
|
||||
Common::Array<char> & ImageData,
|
||||
float LineScaleFactor,
|
||||
bool NoAlphaShapes) {
|
||||
Width = static_cast<unsigned int>(VectorImage.GetWidth() * ScaleFactorX);
|
||||
Height = static_cast<unsigned int>(VectorImage.GetHeight() * ScaleFactorY);
|
||||
|
||||
|
@ -151,9 +143,8 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
|||
Scale = agg::trans_affine_translation(- VectorImage.GetBoundingBox().left, - VectorImage.GetBoundingBox().top);
|
||||
Scale *= agg::trans_affine_scaling(ScaleFactorX, ScaleFactorY);
|
||||
|
||||
for (unsigned int element = 0; element < VectorImage.GetElementCount(); ++element)
|
||||
{
|
||||
const BS_VectorImageElement & CurImageElement = VectorImage.GetElement(element);
|
||||
for (unsigned int element = 0; element < VectorImage.GetElementCount(); ++element) {
|
||||
const BS_VectorImageElement &CurImageElement = VectorImage.GetElement(element);
|
||||
|
||||
CompoundShape ImageCompoundShape(CurImageElement);
|
||||
StyleHandler ImageStyleHandler(CurImageElement);
|
||||
|
@ -164,19 +155,16 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
|||
//----------------------
|
||||
CompoundRasterizer.clip_box(0, 0, Width, Height);
|
||||
CompoundRasterizer.reset();
|
||||
for(unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i) {
|
||||
unsigned int FillStyle0 = CurImageElement.GetPathInfo(i).GetFillStyle0();
|
||||
unsigned int FillStyle1 = CurImageElement.GetPathInfo(i).GetFillStyle1();
|
||||
|
||||
if (NoAlphaShapes)
|
||||
{
|
||||
if (NoAlphaShapes) {
|
||||
if (FillStyle0 != 0 && CurImageElement.GetFillStyleColor(FillStyle0 - 1).a != 255) FillStyle0 = 0;
|
||||
if (FillStyle1 != 0 && CurImageElement.GetFillStyleColor(FillStyle1 - 1).a != 255) FillStyle1 = 0;
|
||||
}
|
||||
|
||||
if(FillStyle0 != 0 || FillStyle1 != 0)
|
||||
{
|
||||
if (FillStyle0 != 0 || FillStyle1 != 0) {
|
||||
CompoundRasterizer.styles(FillStyle0 - 1, FillStyle1 - 1);
|
||||
CompoundRasterizer.add_path(Shape, CurImageElement.GetPathInfo(i).GetID());
|
||||
}
|
||||
|
@ -189,13 +177,11 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
|||
Rasterizer.clip_box(0, 0, Width, Height);
|
||||
Stroke.line_join(agg::round_join);
|
||||
Stroke.line_cap(agg::round_cap);
|
||||
for(unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i) {
|
||||
Rasterizer.reset();
|
||||
|
||||
|
||||
unsigned int CurrentLineStyle = CurImageElement.GetPathInfo(i).GetLineStyle();
|
||||
if (CurrentLineStyle != 0)
|
||||
{
|
||||
if (CurrentLineStyle != 0) {
|
||||
Stroke.width(ScaleFactorX * CurImageElement.GetLineStyleWidth(CurrentLineStyle - 1) * LineScaleFactor);
|
||||
Rasterizer.add_path(Stroke, CurImageElement.GetPathInfo(i).GetID());
|
||||
ScanlineRenderer.color(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1));
|
||||
|
@ -203,9 +189,9 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
|||
// Die SWF-Frames enthalten zum Teil Reste von grünen Linien, die wohl von Bernd als Umriss benutzt wurden.
|
||||
// Damit diese Reste nicht störend auffallen werden grüne Linien schlichtweg ignoriert.
|
||||
if (!(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).a == 255 &&
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).r == 0 &&
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).g == 255 &&
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).b == 0))
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).r == 0 &&
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).g == 255 &&
|
||||
CurImageElement.GetLineStyleColor(CurrentLineStyle - 1).b == 0))
|
||||
agg::render_scanlines(Rasterizer, Scanline, ScanlineRenderer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -58,20 +58,19 @@ class BS_VectorImage;
|
|||
|
||||
|
||||
/**
|
||||
@brief Rendert BS_VectorImage Objekte
|
||||
@brief Rendert BS_VectorImage Objekte
|
||||
*/
|
||||
|
||||
class BS_VectorImageRenderer
|
||||
{
|
||||
class BS_VectorImageRenderer {
|
||||
public:
|
||||
BS_VectorImageRenderer();
|
||||
|
||||
bool Render(const BS_VectorImage & VectorImage,
|
||||
float ScaleFactorX, float ScaleFactorY,
|
||||
unsigned int & Width, unsigned int & Height,
|
||||
Common::Array<char> & ImageData,
|
||||
float LineScaleFactor = 1.0f,
|
||||
bool NoAlphaShapes = false);
|
||||
bool Render(const BS_VectorImage &VectorImage,
|
||||
float ScaleFactorX, float ScaleFactorY,
|
||||
unsigned int &Width, unsigned int &Height,
|
||||
Common::Array<char> & ImageData,
|
||||
float LineScaleFactor = 1.0f,
|
||||
bool NoAlphaShapes = false);
|
||||
|
||||
private:
|
||||
typedef agg::pixfmt_rgba32_pre PixelFormatType;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,21 +50,19 @@ namespace Sword25 {
|
|||
// CONSTRUCTION / DESTRUCTION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
||||
BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) :
|
||||
m_Sprite(0),
|
||||
m_Width(0),
|
||||
m_Height(0)
|
||||
{
|
||||
m_Height(0) {
|
||||
Result = false;
|
||||
|
||||
BS_PackageManager * pPackage = static_cast<BS_PackageManager*>(BS_Kernel::GetInstance()->GetService("package"));
|
||||
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"));
|
||||
BS_ASSERT(pPackage);
|
||||
|
||||
// Datei laden
|
||||
char* pFileData;
|
||||
char *pFileData;
|
||||
unsigned int FileSize;
|
||||
if (!(pFileData = (char*) pPackage->GetFile(Filename, &FileSize)))
|
||||
{
|
||||
if (!(pFileData = (char *) pPackage->GetFile(Filename, &FileSize))) {
|
||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -72,16 +70,14 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
|||
// Bildeigenschaften bestimmen
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
||||
int Pitch;
|
||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height))
|
||||
{
|
||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height)) {
|
||||
BS_LOG_ERRORLN("Could not read image properties.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Das Bild dekomprimieren
|
||||
char * pUncompressedData;
|
||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch))
|
||||
{
|
||||
char *pUncompressedData;
|
||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) {
|
||||
BS_LOG_ERRORLN("Could not decode image.");
|
||||
return;
|
||||
}
|
||||
|
@ -91,11 +87,10 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
|||
|
||||
// GLS-Sprite mit den Bilddaten erstellen
|
||||
GLS_Result GLSResult = GLS_NewSprite(m_Width, m_Height,
|
||||
(ColorFormat == BS_GraphicEngine::CF_ARGB32) ? GLS_True : GLS_False,
|
||||
pUncompressedData,
|
||||
&m_Sprite);
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
(ColorFormat == BS_GraphicEngine::CF_ARGB32) ? GLS_True : GLS_False,
|
||||
pUncompressedData,
|
||||
&m_Sprite);
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
||||
return;
|
||||
}
|
||||
|
@ -109,20 +104,18 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool & Result) :
|
||||
BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool &Result) :
|
||||
m_Sprite(0),
|
||||
m_Width(Width),
|
||||
m_Height(Height)
|
||||
{
|
||||
m_Height(Height) {
|
||||
Result = false;
|
||||
|
||||
// GLS-Sprite mit den Bilddaten erstellen
|
||||
GLS_Result GLSResult = GLS_NewSprite(m_Width, m_Height,
|
||||
GLS_True,
|
||||
0,
|
||||
&m_Sprite);
|
||||
if (GLSResult != GLS_OK)
|
||||
{
|
||||
GLS_True,
|
||||
0,
|
||||
&m_Sprite);
|
||||
if (GLSResult != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
||||
return;
|
||||
}
|
||||
|
@ -133,34 +126,29 @@ BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool & Result) :
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_GLImage::~BS_GLImage()
|
||||
{
|
||||
BS_GLImage::~BS_GLImage() {
|
||||
if (m_Sprite) GLS_DeleteSprite(m_Sprite);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GLImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
||||
{
|
||||
bool BS_GLImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
||||
{
|
||||
bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||
// Überprüfen, ob PixelData ausreichend viele Pixel enthält um ein Bild der Größe Width * Height zu erzeugen
|
||||
if (Pixeldata.size() < static_cast<unsigned int>(m_Width * m_Height * 4))
|
||||
{
|
||||
if (Pixeldata.size() < static_cast<unsigned int>(m_Width * m_Height * 4)) {
|
||||
BS_LOG_ERRORLN("PixelData vector is too small to define a 32 bit %dx%d image.", m_Width, m_Height);
|
||||
return false;
|
||||
}
|
||||
|
||||
// GLS-Sprite mit den Bilddaten füllen
|
||||
GLS_Result GLSResult = GLS_SetSpriteData(m_Sprite, m_Width, m_Height, &Pixeldata[Offset], Stride / 4);
|
||||
if (GLSResult != GLS_OK)
|
||||
{
|
||||
if (GLSResult != GLS_OK) {
|
||||
BS_LOG_ERRORLN("CGLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(GLSResult));
|
||||
return false;
|
||||
}
|
||||
|
@ -170,8 +158,7 @@ bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_GLImage::GetPixel(int X, int Y)
|
||||
{
|
||||
unsigned int BS_GLImage::GetPixel(int X, int Y) {
|
||||
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -179,15 +166,13 @@ unsigned int BS_GLImage::GetPixel(int X, int Y)
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_GLImage::Blit(int PosX, int PosY,
|
||||
int Flipping,
|
||||
BS_Rect* pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height)
|
||||
{
|
||||
int Flipping,
|
||||
BS_Rect *pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height) {
|
||||
// BS_Rect nach GLS_Rect konvertieren
|
||||
GLS_Rect SubImage;
|
||||
if (pPartRect)
|
||||
{
|
||||
if (pPartRect) {
|
||||
SubImage.x1 = pPartRect->left;
|
||||
SubImage.y1 = pPartRect->top;
|
||||
SubImage.x2 = pPartRect->right;
|
||||
|
@ -214,11 +199,11 @@ bool BS_GLImage::Blit(int PosX, int PosY,
|
|||
// Die Bedeutung von FLIP_V und FLIP_H ist vertauscht. Allerdings glaubt der Rest der Engine auch daran, daher war es einfacher diesen Fehler
|
||||
// weiterzuführen. Bei Gelegenheit ist dieses aber zu ändern.
|
||||
GLS_Result Result = GLS_Blit(m_Sprite,
|
||||
PosX, PosY,
|
||||
pPartRect ? &SubImage : 0, &GLSColor,
|
||||
(Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
|
||||
(Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
|
||||
ScaleX, ScaleY);
|
||||
PosX, PosY,
|
||||
pPartRect ? &SubImage : 0, &GLSColor,
|
||||
(Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
|
||||
(Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
|
||||
ScaleX, ScaleY);
|
||||
if (Result != GLS_OK) BS_LOG_ERRORLN("GLS_Blit() failed. Reason: %s", GLS_ResultString(Result));
|
||||
|
||||
return Result == GLS_OK;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -51,52 +51,71 @@ namespace Sword25 {
|
|||
// FORWARD DECLARATION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
typedef void * GLS_Sprite;
|
||||
typedef void *GLS_Sprite;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// CLASS DEFINITION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_GLImage : public BS_Image
|
||||
{
|
||||
class BS_GLImage : public BS_Image {
|
||||
public:
|
||||
BS_GLImage(const Common::String & Filename, bool & Result);
|
||||
BS_GLImage(const Common::String &Filename, bool &Result);
|
||||
|
||||
/**
|
||||
@brief Erzeugt ein leeres BS_GLImage
|
||||
@brief Erzeugt ein leeres BS_GLImage
|
||||
|
||||
@param Width die Breite des zu erzeugenden Bildes.
|
||||
@param Height die Höhe des zu erzeugenden Bildes
|
||||
@param Result gibt dem Aufrufer bekannt, ob der Konstruktor erfolgreich ausgeführt wurde. Wenn es nach dem Aufruf false enthalten sollte,
|
||||
dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören.
|
||||
@param Width die Breite des zu erzeugenden Bildes.
|
||||
@param Height die Höhe des zu erzeugenden Bildes
|
||||
@param Result gibt dem Aufrufer bekannt, ob der Konstruktor erfolgreich ausgeführt wurde. Wenn es nach dem Aufruf false enthalten sollte,
|
||||
dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören.
|
||||
*/
|
||||
BS_GLImage(unsigned int Width, unsigned int Height, bool & Result);
|
||||
BS_GLImage(unsigned int Width, unsigned int Height, bool &Result);
|
||||
virtual ~BS_GLImage();
|
||||
|
||||
virtual int GetWidth() const { return m_Width; }
|
||||
virtual int GetHeight() const { return m_Height; }
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
||||
virtual int GetWidth() const {
|
||||
return m_Width;
|
||||
}
|
||||
virtual int GetHeight() const {
|
||||
return m_Height;
|
||||
}
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||
return BS_GraphicEngine::CF_ARGB32;
|
||||
}
|
||||
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = BS_Image::FLIP_NONE,
|
||||
BS_Rect* pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
virtual bool Fill(const BS_Rect* pFillRect, unsigned int Color);
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = BS_Image::FLIP_NONE,
|
||||
BS_Rect *pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
virtual bool Fill(const BS_Rect *pFillRect, unsigned int Color);
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset = 0, unsigned int Stride = 0);
|
||||
virtual unsigned int GetPixel(int X, int Y);
|
||||
|
||||
virtual bool IsBlitSource() const { return true; }
|
||||
virtual bool IsBlitTarget() const { return false; }
|
||||
virtual bool IsScalingAllowed() const { return true; }
|
||||
virtual bool IsFillingAllowed() const { return false; }
|
||||
virtual bool IsAlphaAllowed() const { return true; }
|
||||
virtual bool IsColorModulationAllowed() const { return true; }
|
||||
virtual bool IsSetContentAllowed() const { return true; }
|
||||
virtual bool IsBlitSource() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsBlitTarget() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsScalingAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsFillingAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsAlphaAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsColorModulationAllowed() const {
|
||||
return true;
|
||||
}
|
||||
virtual bool IsSetContentAllowed() const {
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
GLS_Sprite m_Sprite;
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
GLS_Sprite m_Sprite;
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,64 +50,56 @@ using namespace std;
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
const float LINE_SCALE_FACTOR = 1.0f;
|
||||
namespace {
|
||||
const float LINE_SCALE_FACTOR = 1.0f;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_VectorImage::Blit(int PosX, int PosY,
|
||||
int Flipping,
|
||||
BS_Rect* pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height)
|
||||
{
|
||||
int Flipping,
|
||||
BS_Rect *pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height) {
|
||||
static BS_VectorImageRenderer VectorImageRenderer;
|
||||
static vector<char> PixelData;
|
||||
static GLS_Sprite Sprite = 0;
|
||||
static BS_VectorImage * OldThis = 0;
|
||||
static int OldWidth;
|
||||
static int OldHeight;
|
||||
static GLS_Rect OldSubImage;
|
||||
static BS_VectorImage *OldThis = 0;
|
||||
static int OldWidth;
|
||||
static int OldHeight;
|
||||
static GLS_Rect OldSubImage;
|
||||
|
||||
// Falls Breite oder Höhe 0 sind, muss nichts dargestellt werden.
|
||||
if (Width == 0 || Height == 0) return true;
|
||||
|
||||
// Sprite erstellen, falls es noch nicht erstellt wurde
|
||||
if (Sprite == 0)
|
||||
{
|
||||
if (Sprite == 0) {
|
||||
GLS_Result Result = GLS_NewSprite(512, 512, GLS_True, 0, &Sprite);
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
|
||||
if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0))
|
||||
{
|
||||
if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0)) {
|
||||
float ScaleFactorX = (Width == - 1) ? 1 : static_cast<float>(Width) / static_cast<float>(GetWidth());
|
||||
float ScaleFactorY = (Height == - 1) ? 1: static_cast<float>(Height) / static_cast<float>(GetHeight());
|
||||
float ScaleFactorY = (Height == - 1) ? 1 : static_cast<float>(Height) / static_cast<float>(GetHeight());
|
||||
|
||||
unsigned int RenderedWidth;
|
||||
unsigned int RenderedHeight;
|
||||
if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR))
|
||||
{
|
||||
if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR)) {
|
||||
BS_LOG_ERRORLN("Call to BS_VectorImageRenderer::Render() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RenderedWidth > 512 || RenderedHeight > 512)
|
||||
{
|
||||
if (RenderedWidth > 512 || RenderedHeight > 512) {
|
||||
BS_LOG_WARNINGLN("Currently the maximum size for scaled vector images is 512x512.");
|
||||
return true;
|
||||
}
|
||||
|
||||
GLS_Result Result = GLS_SetSpriteData(Sprite, RenderedWidth, RenderedHeight, &PixelData[0], 0);
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Call to GLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
|
@ -140,11 +132,11 @@ bool BS_VectorImage::Blit(int PosX, int PosY,
|
|||
// Die Bedeutung von FLIP_V und FLIP_H ist vertauscht. Allerdings glaubt der Rest der Engine auch daran, daher war es einfacher diesen Fehler
|
||||
// weiterzuführen. Bei Gelegenheit ist dieses aber zu ändern.
|
||||
GLS_Result Result = GLS_Blit(Sprite,
|
||||
PosX, PosY,
|
||||
&OldSubImage, &GLSColor,
|
||||
(Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
|
||||
(Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
|
||||
1.0f, 1.0f);
|
||||
PosX, PosY,
|
||||
&OldSubImage, &GLSColor,
|
||||
(Flipping & BS_Image::FLIP_V) ? GLS_True : GLS_False,
|
||||
(Flipping & BS_Image::FLIP_H) ? GLS_True : GLS_False,
|
||||
1.0f, 1.0f);
|
||||
if (Result != GLS_OK) BS_LOG_ERRORLN("GLS_Blit() failed. Reason: %s", GLS_ResultString(Result));
|
||||
|
||||
return Result == GLS_OK;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -68,16 +68,15 @@ using namespace std;
|
|||
// CONSTANTS
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
const unsigned int BIT_DEPTH = 32;
|
||||
const unsigned int BACKBUFFER_COUNT = 1;
|
||||
const Common::String PNG_EXTENSION(".png");
|
||||
const Common::String PNG_S_EXTENSION("_s.png");
|
||||
const Common::String ANI_EXTENSION("_ani.xml");
|
||||
const Common::String FNT_EXTENSION("_fnt.xml");
|
||||
const Common::String SWF_EXTENSION(".swf");
|
||||
const Common::String B25S_EXTENSION(".b25s");
|
||||
namespace {
|
||||
const unsigned int BIT_DEPTH = 32;
|
||||
const unsigned int BACKBUFFER_COUNT = 1;
|
||||
const Common::String PNG_EXTENSION(".png");
|
||||
const Common::String PNG_S_EXTENSION("_s.png");
|
||||
const Common::String ANI_EXTENSION("_ani.xml");
|
||||
const Common::String FNT_EXTENSION("_fnt.xml");
|
||||
const Common::String SWF_EXTENSION(".swf");
|
||||
const Common::String B25S_EXTENSION(".b25s");
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,23 +84,20 @@ namespace
|
|||
// CONSTRUCTION / DESTRUCTION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_OpenGLGfx::BS_OpenGLGfx(BS_Kernel * pKernel) :
|
||||
BS_OpenGLGfx::BS_OpenGLGfx(BS_Kernel *pKernel) :
|
||||
BS_GraphicEngine(pKernel),
|
||||
m_GLspritesInitialized(false)
|
||||
{
|
||||
m_GLspritesInitialized(false) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_OpenGLGfx::~BS_OpenGLGfx()
|
||||
{
|
||||
BS_OpenGLGfx::~BS_OpenGLGfx() {
|
||||
if (m_GLspritesInitialized) GLS_Quit();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Service * BS_OpenGLGfx_CreateObject(BS_Kernel* pKernel)
|
||||
{
|
||||
BS_Service *BS_OpenGLGfx_CreateObject(BS_Kernel *pKernel) {
|
||||
return new BS_OpenGLGfx(pKernel);
|
||||
}
|
||||
|
||||
|
@ -110,18 +106,15 @@ BS_Service * BS_OpenGLGfx_CreateObject(BS_Kernel* pKernel)
|
|||
// INTERFACE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed)
|
||||
{
|
||||
bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed) {
|
||||
// Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde.
|
||||
if (BitDepth != BIT_DEPTH)
|
||||
{
|
||||
if (BitDepth != BIT_DEPTH) {
|
||||
BS_LOG_WARNINGLN("Can't use a bit depth of %d (not supported). Falling back to %d.", BitDepth, BIT_DEPTH);
|
||||
m_BitDepth = BIT_DEPTH;
|
||||
}
|
||||
|
||||
// Warnung ausgeben, wenn nicht genau ein Backbuffer gewählt wurde.
|
||||
if (BackbufferCount != BACKBUFFER_COUNT)
|
||||
{
|
||||
if (BackbufferCount != BACKBUFFER_COUNT) {
|
||||
BS_LOG_WARNINGLN("Can't use %d backbuffers (not supported). Falling back to %d.", BackbufferCount, BACKBUFFER_COUNT);
|
||||
BackbufferCount = BACKBUFFER_COUNT;
|
||||
}
|
||||
|
@ -139,8 +132,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
|||
// GLsprites initialisieren
|
||||
HWND hwnd = reinterpret_cast<HWND>(BS_Kernel::GetInstance()->GetWindow()->GetWindowHandle());
|
||||
GLS_Result Result = GLS_InitExternalWindow(Width, Height, Windowed ? GLS_False : GLS_True, hwnd);
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Could not initialize GLsprites. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
|
@ -153,7 +145,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
|||
m_RenderObjectManagerPtr.reset(new BS_RenderObjectManager(Width, Height, BackbufferCount + 1));
|
||||
|
||||
// Hauptpanel erstellen
|
||||
m_MainPanelPtr = m_RenderObjectManagerPtr->GetTreeRoot()->AddPanel(Width, Height, BS_ARGB(0,0,0,0));
|
||||
m_MainPanelPtr = m_RenderObjectManagerPtr->GetTreeRoot()->AddPanel(Width, Height, BS_ARGB(0, 0, 0, 0));
|
||||
if (!m_MainPanelPtr.IsValid()) return false;
|
||||
m_MainPanelPtr->SetVisible(true);
|
||||
|
||||
|
@ -162,8 +154,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
||||
{
|
||||
bool BS_OpenGLGfx::StartFrame(bool UpdateAll) {
|
||||
// Berechnen, wie viel Zeit seit dem letzten Frame vergangen ist.
|
||||
// Dieser Wert kann über GetLastFrameDuration() von Modulen abgefragt werden, die zeitabhängig arbeiten.
|
||||
UpdateLastFrameDuration();
|
||||
|
@ -173,8 +164,7 @@ bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
|||
|
||||
// GLsprites bescheidgeben
|
||||
GLS_Result Result = GLS_StartFrame();
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Call to GLS_StartFrame() failed. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
|
@ -184,23 +174,20 @@ bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::EndFrame()
|
||||
{
|
||||
bool BS_OpenGLGfx::EndFrame() {
|
||||
// Scene zeichnen
|
||||
m_RenderObjectManagerPtr->Render();
|
||||
|
||||
// Debug-Lines zeichnen
|
||||
if (!m_DebugLines.empty())
|
||||
{
|
||||
if (!m_DebugLines.empty()) {
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glBegin(GL_LINES);
|
||||
|
||||
Common::Array<DebugLine>::const_iterator iter = m_DebugLines.begin();
|
||||
for (; iter != m_DebugLines.end(); ++iter)
|
||||
{
|
||||
const unsigned int & Color = (*iter).Color;
|
||||
const BS_Vertex & Start = (*iter).Start;
|
||||
const BS_Vertex & End = (*iter).End;
|
||||
for (; iter != m_DebugLines.end(); ++iter) {
|
||||
const unsigned int &Color = (*iter).Color;
|
||||
const BS_Vertex &Start = (*iter).Start;
|
||||
const BS_Vertex &End = (*iter).End;
|
||||
|
||||
glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24);
|
||||
glVertex2d(Start.X, Start.Y);
|
||||
|
@ -215,8 +202,7 @@ bool BS_OpenGLGfx::EndFrame()
|
|||
|
||||
// Flippen
|
||||
GLS_Result Result = GLS_EndFrame();
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_ERRORLN("Call to GLS_EndFrame() failed. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
|
@ -229,27 +215,23 @@ bool BS_OpenGLGfx::EndFrame()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Panel> BS_OpenGLGfx::GetMainPanel()
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Panel> BS_OpenGLGfx::GetMainPanel() {
|
||||
return m_MainPanelPtr;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_OpenGLGfx::SetVsync(bool Vsync)
|
||||
{
|
||||
void BS_OpenGLGfx::SetVsync(bool Vsync) {
|
||||
GLS_Result Result = GLS_SetVSync(Vsync ? GLS_True : GLS_False);
|
||||
if (Result != GLS_OK) BS_LOG_WARNINGLN("Could not set vsync status. Reason: %s", GLS_ResultString(Result));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::GetVsync() const
|
||||
{
|
||||
bool BS_OpenGLGfx::GetVsync() const {
|
||||
GLS_Bool Status;
|
||||
GLS_Result Result = GLS_IsVsync(&Status);
|
||||
if (Result != GLS_OK)
|
||||
{
|
||||
if (Result != GLS_OK) {
|
||||
BS_LOG_WARNINGLN("Could not get vsync status. Returning false. Reason: %s", GLS_ResultString(Result));
|
||||
return false;
|
||||
}
|
||||
|
@ -259,12 +241,10 @@ bool BS_OpenGLGfx::GetVsync() const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::Fill(const BS_Rect* FillRectPtr, unsigned int Color)
|
||||
{
|
||||
bool BS_OpenGLGfx::Fill(const BS_Rect *FillRectPtr, unsigned int Color) {
|
||||
BS_Rect Rect;
|
||||
|
||||
if (!FillRectPtr)
|
||||
{
|
||||
if (!FillRectPtr) {
|
||||
Rect.left = 0;
|
||||
Rect.top = 0;
|
||||
Rect.right = m_Width;
|
||||
|
@ -273,12 +253,12 @@ bool BS_OpenGLGfx::Fill(const BS_Rect* FillRectPtr, unsigned int Color)
|
|||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24);
|
||||
glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24);
|
||||
|
||||
glVertex2i(FillRectPtr->left, FillRectPtr->top);
|
||||
glVertex2i(FillRectPtr->right, FillRectPtr->top);
|
||||
glVertex2i(FillRectPtr->right, FillRectPtr->bottom);
|
||||
glVertex2i(FillRectPtr->left, FillRectPtr->bottom);
|
||||
glVertex2i(FillRectPtr->left, FillRectPtr->top);
|
||||
glVertex2i(FillRectPtr->right, FillRectPtr->top);
|
||||
glVertex2i(FillRectPtr->right, FillRectPtr->bottom);
|
||||
glVertex2i(FillRectPtr->left, FillRectPtr->bottom);
|
||||
glEnd();
|
||||
|
||||
return glGetError() == 0;
|
||||
|
@ -286,8 +266,7 @@ bool BS_OpenGLGfx::Fill(const BS_Rect* FillRectPtr, unsigned int Color)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::GetScreenshot(unsigned int & Width, unsigned int & Height, vector<unsigned int> & Data)
|
||||
{
|
||||
bool BS_OpenGLGfx::GetScreenshot(unsigned int &Width, unsigned int &Height, vector<unsigned int> & Data) {
|
||||
if (!ReadFramebufferContents(m_Width, m_Height, Data)) return false;
|
||||
|
||||
// Die Größe des Framebuffers zurückgeben.
|
||||
|
@ -303,15 +282,13 @@ bool BS_OpenGLGfx::GetScreenshot(unsigned int & Width, unsigned int & Height, ve
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Height, Common::Array<unsigned int> & Data)
|
||||
{
|
||||
bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Height, Common::Array<unsigned int> & Data) {
|
||||
Data.resize(Width * Height);
|
||||
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
|
||||
|
||||
if (glGetError() == 0)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
else {
|
||||
Data.clear();
|
||||
return false;
|
||||
}
|
||||
|
@ -319,11 +296,9 @@ bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Heig
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data)
|
||||
{
|
||||
void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data) {
|
||||
vector<unsigned int>::iterator It = Data.begin();
|
||||
while (It != Data.end())
|
||||
{
|
||||
while (It != Data.end()) {
|
||||
unsigned int Pixel = *It;
|
||||
*It = (Pixel & 0xff00ff00) | ((Pixel >> 16) & 0xff) | ((Pixel & 0xff) << 16);
|
||||
++It;
|
||||
|
@ -332,12 +307,10 @@ void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height, vector<unsigned int> & Data)
|
||||
{
|
||||
void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height, vector<unsigned int> & Data) {
|
||||
vector<unsigned int> LineBuffer(Width);
|
||||
|
||||
for (unsigned int Y = 0; Y < Height / 2; ++Y)
|
||||
{
|
||||
for (unsigned int Y = 0; Y < Height / 2; ++Y) {
|
||||
vector<unsigned int>::iterator Line1It = Data.begin() + Y * Width;
|
||||
vector<unsigned int>::iterator Line2It = Data.begin() + (Height - 1 - Y) * Width;
|
||||
copy(Line1It, Line1It + Width, LineBuffer.begin());
|
||||
|
@ -350,8 +323,7 @@ void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height
|
|||
// RESOURCE MANAGING
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static bool DoesStringEndWith(const Common::String & String, const std::string & OtherString)
|
||||
{
|
||||
static bool DoesStringEndWith(const Common::String &String, const std::string &OtherString) {
|
||||
Common::String::size_type StringPos = String.rfind(OtherString);
|
||||
if (StringPos == Common::String::npos) return false;
|
||||
|
||||
|
@ -360,24 +332,20 @@ static bool DoesStringEndWith(const Common::String & String, const std::string &
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
||||
{
|
||||
BS_Resource *BS_OpenGLGfx::LoadResource(const Common::String &FileName) {
|
||||
BS_ASSERT(CanLoadResource(FileName));
|
||||
|
||||
// Bild für den Softwarebuffer laden
|
||||
if (DoesStringEndWith(FileName, PNG_S_EXTENSION))
|
||||
{
|
||||
if (DoesStringEndWith(FileName, PNG_S_EXTENSION)) {
|
||||
bool Result;
|
||||
BS_SWImage * pImage = new BS_SWImage(FileName, Result);
|
||||
if (!Result)
|
||||
{
|
||||
BS_SWImage *pImage = new BS_SWImage(FileName, Result);
|
||||
if (!Result) {
|
||||
delete pImage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid())
|
||||
{
|
||||
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid()) {
|
||||
delete pResource;
|
||||
return 0;
|
||||
}
|
||||
|
@ -386,19 +354,16 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
|||
}
|
||||
|
||||
// Sprite-Bild laden
|
||||
if (DoesStringEndWith(FileName, PNG_EXTENSION) || DoesStringEndWith(FileName, B25S_EXTENSION))
|
||||
{
|
||||
if (DoesStringEndWith(FileName, PNG_EXTENSION) || DoesStringEndWith(FileName, B25S_EXTENSION)) {
|
||||
bool Result;
|
||||
BS_GLImage * pImage = new BS_GLImage(FileName, Result);
|
||||
if (!Result)
|
||||
{
|
||||
BS_GLImage *pImage = new BS_GLImage(FileName, Result);
|
||||
if (!Result) {
|
||||
delete pImage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid())
|
||||
{
|
||||
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid()) {
|
||||
delete pResource;
|
||||
return 0;
|
||||
}
|
||||
|
@ -408,33 +373,29 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
|||
|
||||
|
||||
// Vectorgraphik laden
|
||||
if (DoesStringEndWith(FileName, SWF_EXTENSION))
|
||||
{
|
||||
if (DoesStringEndWith(FileName, SWF_EXTENSION)) {
|
||||
// Pointer auf Package-Manager holen
|
||||
BS_PackageManager * pPackage = BS_Kernel::GetInstance()->GetPackage();
|
||||
BS_PackageManager *pPackage = BS_Kernel::GetInstance()->GetPackage();
|
||||
BS_ASSERT(pPackage);
|
||||
|
||||
// Datei laden
|
||||
unsigned char* pFileData;
|
||||
unsigned char *pFileData;
|
||||
unsigned int FileSize;
|
||||
if (!(pFileData = static_cast<unsigned char*>(pPackage->GetFile(FileName, &FileSize))))
|
||||
{
|
||||
if (!(pFileData = static_cast<unsigned char *>(pPackage->GetFile(FileName, &FileSize)))) {
|
||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", FileName.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Result;
|
||||
BS_VectorImage * pImage = new BS_VectorImage(pFileData, FileSize, Result);
|
||||
if (!Result)
|
||||
{
|
||||
BS_VectorImage *pImage = new BS_VectorImage(pFileData, FileSize, Result);
|
||||
if (!Result) {
|
||||
delete pImage;
|
||||
delete [] pFileData;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid())
|
||||
{
|
||||
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||
if (!pResource->IsValid()) {
|
||||
delete pResource;
|
||||
delete [] pFileData;
|
||||
return 0;
|
||||
|
@ -445,26 +406,22 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
|||
}
|
||||
|
||||
// Animation laden
|
||||
if (DoesStringEndWith(FileName, ANI_EXTENSION))
|
||||
{
|
||||
BS_AnimationResource * pResource = new BS_AnimationResource(FileName);
|
||||
if (DoesStringEndWith(FileName, ANI_EXTENSION)) {
|
||||
BS_AnimationResource *pResource = new BS_AnimationResource(FileName);
|
||||
if (pResource->IsValid())
|
||||
return pResource;
|
||||
else
|
||||
{
|
||||
else {
|
||||
delete pResource;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Font laden
|
||||
if (DoesStringEndWith(FileName, FNT_EXTENSION))
|
||||
{
|
||||
BS_FontResource * pResource = new BS_FontResource(BS_Kernel::GetInstance(), FileName);
|
||||
if (DoesStringEndWith(FileName, FNT_EXTENSION)) {
|
||||
BS_FontResource *pResource = new BS_FontResource(BS_Kernel::GetInstance(), FileName);
|
||||
if (pResource->IsValid())
|
||||
return pResource;
|
||||
else
|
||||
{
|
||||
else {
|
||||
delete pResource;
|
||||
return 0;
|
||||
}
|
||||
|
@ -476,13 +433,12 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::CanLoadResource(const Common::String& FileName)
|
||||
{
|
||||
bool BS_OpenGLGfx::CanLoadResource(const Common::String &FileName) {
|
||||
return DoesStringEndWith(FileName, PNG_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, ANI_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, FNT_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, SWF_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, B25S_EXTENSION);
|
||||
DoesStringEndWith(FileName, ANI_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, FNT_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, SWF_EXTENSION) ||
|
||||
DoesStringEndWith(FileName, B25S_EXTENSION);
|
||||
}
|
||||
|
||||
|
||||
|
@ -490,8 +446,7 @@ bool BS_OpenGLGfx::CanLoadResource(const Common::String& FileName)
|
|||
// DEBUGGING
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End, unsigned int Color)
|
||||
{
|
||||
void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color) {
|
||||
m_DebugLines.push_back(DebugLine(Start, End, Color));
|
||||
}
|
||||
|
||||
|
@ -499,8 +454,7 @@ void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End,
|
|||
// PERSISTENZ
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool result = true;
|
||||
|
||||
result &= BS_GraphicEngine::Persist(Writer);
|
||||
|
@ -511,8 +465,7 @@ bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_OpenGLGfx::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_OpenGLGfx::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool result = true;
|
||||
|
||||
result &= BS_GraphicEngine::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -67,58 +67,56 @@ class BS_RenderObjectManager;
|
|||
// CLASS DECLARATION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_OpenGLGfx : public BS_GraphicEngine
|
||||
{
|
||||
class BS_OpenGLGfx : public BS_GraphicEngine {
|
||||
public:
|
||||
BS_OpenGLGfx(BS_Kernel* pKernel);
|
||||
BS_OpenGLGfx(BS_Kernel *pKernel);
|
||||
virtual ~BS_OpenGLGfx();
|
||||
|
||||
// Interface
|
||||
// ---------
|
||||
virtual bool Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed);
|
||||
virtual bool StartFrame(bool UpdateAll);
|
||||
virtual bool EndFrame();
|
||||
virtual bool Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed);
|
||||
virtual bool StartFrame(bool UpdateAll);
|
||||
virtual bool EndFrame();
|
||||
|
||||
virtual BS_RenderObjectPtr<BS_Panel> GetMainPanel();
|
||||
|
||||
virtual void SetVsync(bool Vsync);
|
||||
virtual bool GetVsync() const;
|
||||
virtual void SetVsync(bool Vsync);
|
||||
virtual bool GetVsync() const;
|
||||
|
||||
virtual bool Fill(const BS_Rect* FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||
virtual bool GetScreenshot(unsigned int & Width, unsigned int & Height, Common::Array<unsigned int> & Data);
|
||||
virtual bool Fill(const BS_Rect *FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||
virtual bool GetScreenshot(unsigned int &Width, unsigned int &Height, Common::Array<unsigned int> & Data);
|
||||
|
||||
// Resource-Managing Methoden
|
||||
// --------------------------
|
||||
virtual BS_Resource* LoadResource(const Common::String& FileName);
|
||||
virtual bool CanLoadResource(const Common::String& FileName);
|
||||
virtual BS_Resource *LoadResource(const Common::String &FileName);
|
||||
virtual bool CanLoadResource(const Common::String &FileName);
|
||||
|
||||
// Debugging Methoden
|
||||
// ------------------
|
||||
virtual void DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End, unsigned int Color);
|
||||
static const char * GetGLSResultString(GLS_Result Result);
|
||||
virtual void DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color);
|
||||
static const char *GetGLSResultString(GLS_Result Result);
|
||||
|
||||
// Persistenz Methoden
|
||||
// -------------------
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
private:
|
||||
bool m_GLspritesInitialized;
|
||||
bool m_GLspritesInitialized;
|
||||
|
||||
BS_RenderObjectPtr<BS_Panel> m_MainPanelPtr;
|
||||
|
||||
std::auto_ptr<BS_RenderObjectManager> m_RenderObjectManagerPtr;
|
||||
std::auto_ptr<BS_RenderObjectManager> m_RenderObjectManagerPtr;
|
||||
|
||||
struct DebugLine
|
||||
{
|
||||
DebugLine(const BS_Vertex & _Start, const BS_Vertex & _End, unsigned int _Color) :
|
||||
struct DebugLine {
|
||||
DebugLine(const BS_Vertex &_Start, const BS_Vertex &_End, unsigned int _Color) :
|
||||
Start(_Start),
|
||||
End(_End),
|
||||
Color(_Color) {};
|
||||
|
||||
BS_Vertex Start;
|
||||
BS_Vertex End;
|
||||
unsigned int Color;
|
||||
|
||||
BS_Vertex Start;
|
||||
BS_Vertex End;
|
||||
unsigned int Color;
|
||||
};
|
||||
|
||||
Common::Array<DebugLine> m_DebugLines;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,21 +50,19 @@ namespace Sword25 {
|
|||
// CONSTRUCTION / DESTRUCTION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
||||
BS_SWImage::BS_SWImage(const Common::String &Filename, bool &Result) :
|
||||
_ImageDataPtr(0),
|
||||
m_Width(0),
|
||||
m_Height(0)
|
||||
{
|
||||
m_Height(0) {
|
||||
Result = false;
|
||||
|
||||
BS_PackageManager * pPackage = static_cast<BS_PackageManager*>(BS_Kernel::GetInstance()->GetService("package"));
|
||||
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"));
|
||||
BS_ASSERT(pPackage);
|
||||
|
||||
// Datei laden
|
||||
char* pFileData;
|
||||
char *pFileData;
|
||||
unsigned int FileSize;
|
||||
if (!(pFileData = (char*) pPackage->GetFile(Filename, &FileSize)))
|
||||
{
|
||||
if (!(pFileData = (char *) pPackage->GetFile(Filename, &FileSize))) {
|
||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
@ -72,16 +70,14 @@ BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
|||
// Bildeigenschaften bestimmen
|
||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
||||
int Pitch;
|
||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height))
|
||||
{
|
||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height)) {
|
||||
BS_LOG_ERRORLN("Could not read image properties.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Das Bild dekomprimieren
|
||||
char * pUncompressedData;
|
||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch))
|
||||
{
|
||||
char *pUncompressedData;
|
||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) {
|
||||
BS_LOG_ERRORLN("Could not decode image.");
|
||||
return;
|
||||
}
|
||||
|
@ -97,8 +93,7 @@ BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_SWImage::~BS_SWImage()
|
||||
{
|
||||
BS_SWImage::~BS_SWImage() {
|
||||
delete [] _ImageDataPtr;
|
||||
}
|
||||
|
||||
|
@ -106,35 +101,31 @@ BS_SWImage::~BS_SWImage()
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_SWImage::Blit(int PosX, int PosY,
|
||||
int Flipping,
|
||||
BS_Rect* pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height)
|
||||
{
|
||||
int Flipping,
|
||||
BS_Rect *pPartRect,
|
||||
unsigned int Color,
|
||||
int Width, int Height) {
|
||||
BS_LOG_ERRORLN("Blit() is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_SWImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
||||
{
|
||||
bool BS_SWImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_SWImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
||||
{
|
||||
bool BS_SWImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||
BS_LOG_ERRORLN("SetContent() is not supported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_SWImage::GetPixel(int X, int Y)
|
||||
{
|
||||
unsigned int BS_SWImage::GetPixel(int X, int Y) {
|
||||
BS_ASSERT(X >= 0 && X < m_Width);
|
||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,36 +50,55 @@ namespace Sword25 {
|
|||
// CLASS DEFINITION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_SWImage : public BS_Image
|
||||
{
|
||||
class BS_SWImage : public BS_Image {
|
||||
public:
|
||||
BS_SWImage(const Common::String & Filename, bool & Result);
|
||||
BS_SWImage(const Common::String &Filename, bool &Result);
|
||||
virtual ~BS_SWImage();
|
||||
|
||||
virtual int GetWidth() const { return m_Width; }
|
||||
virtual int GetHeight() const { return m_Height; }
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
||||
virtual int GetWidth() const {
|
||||
return m_Width;
|
||||
}
|
||||
virtual int GetHeight() const {
|
||||
return m_Height;
|
||||
}
|
||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||
return BS_GraphicEngine::CF_ARGB32;
|
||||
}
|
||||
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = BS_Image::FLIP_NONE,
|
||||
BS_Rect* pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
virtual bool Fill(const BS_Rect* FillRectPtr, unsigned int Color);
|
||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||
int Flipping = BS_Image::FLIP_NONE,
|
||||
BS_Rect *pPartRect = NULL,
|
||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||
int Width = -1, int Height = -1);
|
||||
virtual bool Fill(const BS_Rect *FillRectPtr, unsigned int Color);
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
virtual unsigned int GetPixel(int X, int Y);
|
||||
|
||||
virtual bool IsBlitSource() const { return false; }
|
||||
virtual bool IsBlitTarget() const { return false; }
|
||||
virtual bool IsScalingAllowed() const { return false; }
|
||||
virtual bool IsFillingAllowed() const { return false; }
|
||||
virtual bool IsAlphaAllowed() const { return false; }
|
||||
virtual bool IsColorModulationAllowed() const { return false; }
|
||||
virtual bool IsSetContentAllowed() const { return false; }
|
||||
virtual bool IsBlitSource() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsBlitTarget() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsScalingAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsFillingAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsAlphaAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsColorModulationAllowed() const {
|
||||
return false;
|
||||
}
|
||||
virtual bool IsSetContentAllowed() const {
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
unsigned int * _ImageDataPtr;
|
||||
unsigned int *_ImageDataPtr;
|
||||
|
||||
int m_Width;
|
||||
int m_Width;
|
||||
int m_Height;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -55,21 +55,18 @@ namespace Sword25 {
|
|||
|
||||
BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color) :
|
||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL),
|
||||
m_Color(Color)
|
||||
{
|
||||
m_Color(Color) {
|
||||
m_InitSuccess = false;
|
||||
|
||||
m_Width = Width;
|
||||
m_Height = Height;
|
||||
|
||||
if (m_Width < 0)
|
||||
{
|
||||
if (m_Width < 0) {
|
||||
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid width (%d).", m_Width);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Height < 0)
|
||||
{
|
||||
if (m_Height < 0) {
|
||||
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid height (%d).", m_Height);
|
||||
return;
|
||||
}
|
||||
|
@ -79,28 +76,25 @@ BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Panel::BS_Panel(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL, Handle)
|
||||
{
|
||||
BS_Panel::BS_Panel(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL, Handle) {
|
||||
m_InitSuccess = Unpersist(Reader);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Panel::~BS_Panel()
|
||||
{
|
||||
|
||||
BS_Panel::~BS_Panel() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Rendern
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Panel::DoRender()
|
||||
{
|
||||
bool BS_Panel::DoRender() {
|
||||
// Falls der Alphawert 0 ist, ist das Panel komplett durchsichtig und es muss nichts gezeichnet werden.
|
||||
if (m_Color >> 24 == 0) return true;
|
||||
|
||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_ASSERT(GfxPtr);
|
||||
|
||||
return GfxPtr->Fill(&m_BBox, m_Color);
|
||||
|
@ -110,8 +104,7 @@ bool BS_Panel::DoRender()
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Panel::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_Panel::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Persist(Writer);
|
||||
|
@ -124,8 +117,7 @@ bool BS_Panel::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Panel::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_Panel::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,22 +48,26 @@ namespace Sword25 {
|
|||
// Class Definition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_Panel : public BS_RenderObject
|
||||
{
|
||||
friend class BS_RenderObject;
|
||||
class BS_Panel : public BS_RenderObject {
|
||||
friend class BS_RenderObject;
|
||||
|
||||
private:
|
||||
BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color);
|
||||
BS_Panel(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
BS_Panel(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
|
||||
public:
|
||||
virtual ~BS_Panel();
|
||||
|
||||
unsigned int GetColor() const { return m_Color; }
|
||||
void SetColor(unsigned int Color) { m_Color = Color; ForceRefresh(); }
|
||||
unsigned int GetColor() const {
|
||||
return m_Color;
|
||||
}
|
||||
void SetColor(unsigned int Color) {
|
||||
m_Color = Color;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
virtual bool DoRender();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -70,8 +70,7 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
|||
m_Type(Type),
|
||||
m_InitSuccess(false),
|
||||
m_RefreshForced(true),
|
||||
m_Handle(0)
|
||||
{
|
||||
m_Handle(0) {
|
||||
// Renderobject registrieren, abhängig vom Handle-Parameter entweder mit beliebigem oder vorgegebenen Handle.
|
||||
if (Handle == 0)
|
||||
m_Handle = BS_RenderObjectRegistry::GetInstance().RegisterObject(this);
|
||||
|
@ -83,15 +82,11 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
|||
|
||||
// Dieses Objekt zu den Kindern der Elternobjektes hinzufügen, falls nicht Wurzel (ParentPtr ungültig) und dem
|
||||
// selben RenderObjektManager zuweisen.
|
||||
if (m_ParentPtr.IsValid())
|
||||
{
|
||||
if (m_ParentPtr.IsValid()) {
|
||||
m_ManagerPtr = m_ParentPtr->GetManager();
|
||||
m_ParentPtr->AddObject(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetType() != TYPE_ROOT)
|
||||
{
|
||||
} else {
|
||||
if (GetType() != TYPE_ROOT) {
|
||||
BS_LOG_ERRORLN("Tried to create a non-root render object and has no parent. All non-root render objects have to have a parent.");
|
||||
return;
|
||||
}
|
||||
|
@ -102,11 +97,10 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
|||
m_InitSuccess = true;
|
||||
}
|
||||
|
||||
BS_RenderObject::~BS_RenderObject()
|
||||
{
|
||||
BS_RenderObject::~BS_RenderObject() {
|
||||
// Objekt aus dem Elternobjekt entfernen.
|
||||
if (m_ParentPtr.IsValid()) m_ParentPtr->DetatchChildren(this);
|
||||
|
||||
|
||||
DeleteAllChildren();
|
||||
|
||||
// Objekt deregistrieren.
|
||||
|
@ -115,8 +109,7 @@ BS_RenderObject::~BS_RenderObject()
|
|||
|
||||
// Rendern
|
||||
// -------
|
||||
bool BS_RenderObject::Render()
|
||||
{
|
||||
bool BS_RenderObject::Render() {
|
||||
// Objektänderungen validieren
|
||||
ValidateObject();
|
||||
|
||||
|
@ -124,8 +117,7 @@ bool BS_RenderObject::Render()
|
|||
if (!m_Visible) return true;
|
||||
|
||||
// Falls notwendig, wird die Renderreihenfolge der Kinderobjekte aktualisiert.
|
||||
if (m_ChildChanged)
|
||||
{
|
||||
if (m_ChildChanged) {
|
||||
SortRenderObjects();
|
||||
m_ChildChanged = false;
|
||||
}
|
||||
|
@ -144,8 +136,7 @@ bool BS_RenderObject::Render()
|
|||
// Objektverwaltung
|
||||
// ----------------
|
||||
|
||||
void BS_RenderObject::ValidateObject()
|
||||
{
|
||||
void BS_RenderObject::ValidateObject() {
|
||||
// Die Veränderungen in den Objektvariablen aufheben
|
||||
m_OldBBox = m_BBox;
|
||||
m_OldVisible = m_Visible;
|
||||
|
@ -155,27 +146,25 @@ void BS_RenderObject::ValidateObject()
|
|||
m_RefreshForced = false;
|
||||
}
|
||||
|
||||
bool BS_RenderObject::UpdateObjectState()
|
||||
{
|
||||
bool BS_RenderObject::UpdateObjectState() {
|
||||
// Falls sich das Objekt verändert hat, muss der interne Zustand neu berechnet werden und evtl. Update-Regions für den nächsten Frame
|
||||
// registriert werden.
|
||||
if ((CalcBoundingBox() != m_OldBBox) ||
|
||||
(m_Visible != m_OldVisible) ||
|
||||
(m_X != m_OldX) ||
|
||||
(m_Y != m_OldY) ||
|
||||
(m_Z != m_OldZ) ||
|
||||
m_RefreshForced)
|
||||
{
|
||||
(m_Visible != m_OldVisible) ||
|
||||
(m_X != m_OldX) ||
|
||||
(m_Y != m_OldY) ||
|
||||
(m_Z != m_OldZ) ||
|
||||
m_RefreshForced) {
|
||||
// Renderrang des Objektes neu bestimmen, da sich dieser verändert haben könnte
|
||||
if (m_ParentPtr.IsValid()) m_ParentPtr->SignalChildChange();
|
||||
|
||||
|
||||
// Die Bounding-Box neu berechnen und Update-Regions registrieren.
|
||||
UpdateBoxes();
|
||||
|
||||
|
||||
// Änderungen Validieren
|
||||
ValidateObject();
|
||||
}
|
||||
|
||||
|
||||
// Dann muss der Objektstatus der Kinder aktualisiert werden.
|
||||
RENDEROBJECT_ITER it = m_Children.begin();
|
||||
for (; it != m_Children.end(); ++it)
|
||||
|
@ -184,14 +173,12 @@ bool BS_RenderObject::UpdateObjectState()
|
|||
return true;
|
||||
}
|
||||
|
||||
void BS_RenderObject::UpdateBoxes()
|
||||
{
|
||||
void BS_RenderObject::UpdateBoxes() {
|
||||
// Bounding-Box aktualisieren
|
||||
m_BBox = CalcBoundingBox();
|
||||
}
|
||||
|
||||
BS_Rect BS_RenderObject::CalcBoundingBox() const
|
||||
{
|
||||
BS_Rect BS_RenderObject::CalcBoundingBox() const {
|
||||
// Die Bounding-Box mit der Objektgröße initialisieren.
|
||||
BS_Rect BBox(0, 0, m_Width, m_Height);
|
||||
|
||||
|
@ -204,22 +191,19 @@ BS_Rect BS_RenderObject::CalcBoundingBox() const
|
|||
return BBox;
|
||||
}
|
||||
|
||||
void BS_RenderObject::CalcAbsolutePos(int& X, int& Y) const
|
||||
{
|
||||
void BS_RenderObject::CalcAbsolutePos(int &X, int &Y) const {
|
||||
X = CalcAbsoluteX();
|
||||
Y = CalcAbsoluteY();
|
||||
}
|
||||
|
||||
int BS_RenderObject::CalcAbsoluteX() const
|
||||
{
|
||||
int BS_RenderObject::CalcAbsoluteX() const {
|
||||
if (m_ParentPtr.IsValid())
|
||||
return m_ParentPtr->GetAbsoluteX() + m_X;
|
||||
else
|
||||
return m_X;
|
||||
}
|
||||
|
||||
int BS_RenderObject::CalcAbsoluteY() const
|
||||
{
|
||||
int BS_RenderObject::CalcAbsoluteY() const {
|
||||
if (m_ParentPtr.IsValid())
|
||||
return m_ParentPtr->GetAbsoluteY() + m_Y;
|
||||
else
|
||||
|
@ -229,41 +213,35 @@ int BS_RenderObject::CalcAbsoluteY() const
|
|||
// Baumverwaltung
|
||||
// --------------
|
||||
|
||||
void BS_RenderObject::DeleteAllChildren()
|
||||
{
|
||||
void BS_RenderObject::DeleteAllChildren() {
|
||||
// Es ist nicht notwendig die Liste zu iterieren, da jedes Kind für sich DetatchChildren an diesem Objekt aufruft und sich somit
|
||||
// selber entfernt. Daher muss immer nur ein beliebiges Element (hier das letzte) gelöscht werden, bis die Liste leer ist.
|
||||
while (!m_Children.empty())
|
||||
{
|
||||
while (!m_Children.empty()) {
|
||||
BS_RenderObjectPtr<BS_RenderObject> CurPtr = m_Children.back();
|
||||
CurPtr.Erase();
|
||||
}
|
||||
}
|
||||
|
||||
bool BS_RenderObject::AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject)
|
||||
{
|
||||
if (!pObject.IsValid())
|
||||
{
|
||||
bool BS_RenderObject::AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject) {
|
||||
if (!pObject.IsValid()) {
|
||||
BS_LOG_ERRORLN("Tried to add a null object to a renderobject.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Objekt in die Kinderliste einfügen.
|
||||
m_Children.push_back(pObject);
|
||||
|
||||
|
||||
// Sicherstellen, dass vor dem nächsten Rendern die Renderreihenfolge aktualisiert wird.
|
||||
if (m_ParentPtr.IsValid()) m_ParentPtr->SignalChildChange();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject)
|
||||
{
|
||||
bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject) {
|
||||
// Kinderliste durchgehen und Objekt entfernen falls vorhanden
|
||||
RENDEROBJECT_ITER it = m_Children.begin();
|
||||
for (; it != m_Children.end(); ++it)
|
||||
if (*it == pObject)
|
||||
{
|
||||
if (*it == pObject) {
|
||||
m_Children.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
@ -272,13 +250,11 @@ bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObjec
|
|||
return false;
|
||||
}
|
||||
|
||||
void BS_RenderObject::SortRenderObjects()
|
||||
{
|
||||
void BS_RenderObject::SortRenderObjects() {
|
||||
std::sort(m_Children.begin(), m_Children.end(), Greater);
|
||||
}
|
||||
|
||||
void BS_RenderObject::UpdateAbsolutePos()
|
||||
{
|
||||
void BS_RenderObject::UpdateAbsolutePos() {
|
||||
CalcAbsolutePos(m_AbsoluteX, m_AbsoluteY);
|
||||
|
||||
RENDEROBJECT_ITER it = m_Children.begin();
|
||||
|
@ -289,42 +265,36 @@ void BS_RenderObject::UpdateAbsolutePos()
|
|||
// Get-Methoden
|
||||
// ------------
|
||||
|
||||
bool BS_RenderObject::GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect& Result)
|
||||
{
|
||||
bool BS_RenderObject::GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect &Result) {
|
||||
return m_BBox.Intersect(pObject->GetBBox(), Result);
|
||||
}
|
||||
|
||||
// Set-Methoden
|
||||
// ------------
|
||||
void BS_RenderObject::SetPos(int X, int Y)
|
||||
{
|
||||
m_X = X;
|
||||
void BS_RenderObject::SetPos(int X, int Y) {
|
||||
m_X = X;
|
||||
m_Y = Y;
|
||||
UpdateAbsolutePos();
|
||||
}
|
||||
|
||||
void BS_RenderObject::SetX(int X)
|
||||
{
|
||||
void BS_RenderObject::SetX(int X) {
|
||||
m_X = X;
|
||||
UpdateAbsolutePos();
|
||||
}
|
||||
|
||||
void BS_RenderObject::SetY(int Y)
|
||||
{
|
||||
void BS_RenderObject::SetY(int Y) {
|
||||
m_Y = Y;
|
||||
UpdateAbsolutePos();
|
||||
}
|
||||
|
||||
void BS_RenderObject::SetZ(int Z)
|
||||
{
|
||||
void BS_RenderObject::SetZ(int Z) {
|
||||
if (Z < 0)
|
||||
BS_LOG_ERRORLN("Tried to set a negative Z value (%d).", Z);
|
||||
else
|
||||
m_Z = Z;
|
||||
}
|
||||
|
||||
void BS_RenderObject::SetVisible(bool Visible)
|
||||
{
|
||||
void BS_RenderObject::SetVisible(bool Visible) {
|
||||
m_Visible = Visible;
|
||||
}
|
||||
|
||||
|
@ -332,13 +302,11 @@ void BS_RenderObject::SetVisible(bool Visible)
|
|||
// Objekterzeuger
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::String& Filename)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::String &Filename) {
|
||||
BS_RenderObjectPtr<BS_Animation> AniPtr(new BS_Animation(this, Filename));
|
||||
if (AniPtr.IsValid() && AniPtr->GetInitSuccess())
|
||||
return AniPtr;
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (AniPtr.IsValid()) AniPtr.Erase();
|
||||
return BS_RenderObjectPtr<BS_Animation>();
|
||||
}
|
||||
|
@ -347,13 +315,11 @@ BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::Str
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_AnimationTemplate & AnimationTemplate)
|
||||
{
|
||||
BS_Animation * AniPtr = new BS_Animation(this, AnimationTemplate);
|
||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_AnimationTemplate &AnimationTemplate) {
|
||||
BS_Animation *AniPtr = new BS_Animation(this, AnimationTemplate);
|
||||
if (AniPtr && AniPtr->GetInitSuccess())
|
||||
return AniPtr;
|
||||
else
|
||||
{
|
||||
else {
|
||||
delete AniPtr;
|
||||
return BS_RenderObjectPtr<BS_Animation>();
|
||||
}
|
||||
|
@ -361,13 +327,11 @@ BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_Animatio
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String& Filename)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String &Filename) {
|
||||
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_StaticBitmap(this, Filename));
|
||||
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
||||
return BS_RenderObjectPtr<BS_Bitmap>(BitmapPtr);
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
||||
return BS_RenderObjectPtr<BS_Bitmap>();
|
||||
}
|
||||
|
@ -375,13 +339,11 @@ BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String& F
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Width, unsigned int Height)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Width, unsigned int Height) {
|
||||
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_DynamicBitmap(this, Width, Height));
|
||||
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
||||
return BitmapPtr;
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
||||
return BS_RenderObjectPtr<BS_Bitmap>();
|
||||
}
|
||||
|
@ -389,13 +351,11 @@ BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Wid
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, unsigned int Color)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, unsigned int Color) {
|
||||
BS_RenderObjectPtr<BS_Panel> PanelPtr(new BS_Panel(this, Width, Height, Color));
|
||||
if (PanelPtr.IsValid() && PanelPtr->GetInitSuccess())
|
||||
return PanelPtr;
|
||||
else
|
||||
{
|
||||
else {
|
||||
if (PanelPtr.IsValid()) PanelPtr.Erase();
|
||||
return BS_RenderObjectPtr<BS_Panel>();
|
||||
}
|
||||
|
@ -403,16 +363,12 @@ BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, un
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String & Font, const std::string & Text)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String &Font, const std::string &Text) {
|
||||
BS_RenderObjectPtr<BS_Text> TextPtr(new BS_Text(this));
|
||||
if (TextPtr.IsValid() && TextPtr->GetInitSuccess() && TextPtr->SetFont(Font))
|
||||
{
|
||||
if (TextPtr.IsValid() && TextPtr->GetInitSuccess() && TextPtr->SetFont(Font)) {
|
||||
TextPtr->SetText(Text);
|
||||
return TextPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (TextPtr.IsValid()) TextPtr.Erase();
|
||||
return BS_RenderObjectPtr<BS_Text>();
|
||||
}
|
||||
|
@ -421,8 +377,7 @@ BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String & Font
|
|||
// Persistenz-Methoden
|
||||
// -------------------
|
||||
|
||||
bool BS_RenderObject::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_RenderObject::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
// Typ und Handle werden als erstes gespeichert, damit beim Laden ein Objekt vom richtigen Typ mit dem richtigen Handle erzeugt werden kann.
|
||||
Writer.Write(static_cast<unsigned int>(m_Type));
|
||||
Writer.Write(m_Handle);
|
||||
|
@ -458,8 +413,7 @@ bool BS_RenderObject::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
// Typ und Handle wurden schon von RecreatePersistedRenderObject() ausgelesen. Jetzt werden die restlichen Objekteigenschaften ausgelesen.
|
||||
Reader.Read(m_X);
|
||||
Reader.Read(m_Y);
|
||||
|
@ -496,8 +450,7 @@ bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
// Kinderanzahl speichern.
|
||||
|
@ -505,8 +458,7 @@ bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// Rekursiv alle Kinder speichern.
|
||||
RENDEROBJECT_LIST::iterator It = m_Children.begin();
|
||||
while (It != m_Children.end())
|
||||
{
|
||||
while (It != m_Children.end()) {
|
||||
Result &= (*It)->Persist(Writer);
|
||||
++It;
|
||||
}
|
||||
|
@ -516,8 +468,7 @@ bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
// Kinderanzahl einlesen.
|
||||
|
@ -526,8 +477,7 @@ bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
|||
if (!Reader.IsGood()) return false;
|
||||
|
||||
// Alle Kinder rekursiv wieder herstellen.
|
||||
for (unsigned int i = 0; i < ChildrenCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < ChildrenCount; ++i) {
|
||||
if (!RecreatePersistedRenderObject(Reader).IsValid()) return false;
|
||||
}
|
||||
|
||||
|
@ -536,8 +486,7 @@ bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObject(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObject(BS_InputPersistenceBlock &Reader) {
|
||||
BS_RenderObjectPtr<BS_RenderObject> Result;
|
||||
|
||||
// Typ und Handle auslesen.
|
||||
|
@ -547,8 +496,7 @@ BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObje
|
|||
Reader.Read(Handle);
|
||||
if (!Reader.IsGood()) return Result;
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
switch (Type) {
|
||||
case TYPE_PANEL:
|
||||
Result = new BS_Panel(Reader, this, Handle);
|
||||
break;
|
||||
|
@ -578,8 +526,7 @@ BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObje
|
|||
|
||||
// Hilfs-Methoden
|
||||
// --------------
|
||||
bool BS_RenderObject::Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs)
|
||||
{
|
||||
bool BS_RenderObject::Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs) {
|
||||
// Das Objekt mit dem kleinem Z-Wert müssen zuerst gerendert werden.
|
||||
if (lhs->m_Z != rhs->m_Z)
|
||||
return lhs->m_Z < rhs->m_Z;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,13 +33,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
BS_RenderObject
|
||||
---------------
|
||||
Dieses ist die Klasse die sämtliche sichtbaren Objekte beschreibt. Alle anderen sichtbaren Objekte müssen von ihr abgeleitet werden.
|
||||
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
||||
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjectManager in einem Baum verwaltet.
|
||||
BS_RenderObject
|
||||
---------------
|
||||
Dieses ist die Klasse die sämtliche sichtbaren Objekte beschreibt. Alle anderen sichtbaren Objekte müssen von ihr abgeleitet werden.
|
||||
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
||||
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjectManager in einem Baum verwaltet.
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_RENDEROBJECT_H
|
||||
|
@ -69,19 +69,17 @@ class BS_Text;
|
|||
|
||||
// Klassendefinition
|
||||
/**
|
||||
@brief Dieses ist die Klasse die sämtliche sichtbaren Objekte beschreibt.
|
||||
|
||||
Alle anderen sichtbaren Objekte müssen von ihr abgeleitet werden.
|
||||
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
||||
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjektManager in einem Baum verwaltet.
|
||||
@brief Dieses ist die Klasse die sämtliche sichtbaren Objekte beschreibt.
|
||||
|
||||
Alle anderen sichtbaren Objekte müssen von ihr abgeleitet werden.
|
||||
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
||||
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjektManager in einem Baum verwaltet.
|
||||
*/
|
||||
class BS_RenderObject
|
||||
{
|
||||
class BS_RenderObject {
|
||||
public:
|
||||
// Konstanten
|
||||
// ----------
|
||||
enum TYPES
|
||||
{
|
||||
enum TYPES {
|
||||
/// Das Wurzelobjekt. Siehe BS_RenderObjectManager
|
||||
TYPE_ROOT,
|
||||
/// Ein Image. Siehe BS_Bitmap.
|
||||
|
@ -102,111 +100,111 @@ public:
|
|||
|
||||
/**
|
||||
@brief Erzeugt ein Bitmap als Kinderobjekt des Renderobjektes.
|
||||
@param FileName der Dateiname der Quellbilddatei
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@param FileName der Dateiname der Quellbilddatei
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Bitmap> AddBitmap(const Common::String &FileName);
|
||||
/**
|
||||
@brief Erzeugt ein veränderbares Bitmap als Kinderobjekt des Renderobjektes.
|
||||
@param Width die Breite des Bitmaps
|
||||
@param Height die Höhe des Bitmaps
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@brief Erzeugt ein veränderbares Bitmap als Kinderobjekt des Renderobjektes.
|
||||
@param Width die Breite des Bitmaps
|
||||
@param Height die Höhe des Bitmaps
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Bitmap> AddDynamicBitmap(unsigned int Width, unsigned int Height);
|
||||
/**
|
||||
@brief Erzeugt eine Animation auf Basis einer Animationsdatei als Kinderobjekt des Renderobjektes.
|
||||
@param FileName der Dateiname der Quelldatei
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@param FileName der Dateiname der Quelldatei
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Animation> AddAnimation(const Common::String &FileName);
|
||||
/**
|
||||
@brief Erzeugt eine Animation auf Basis eines Animationstemplate als Kinderobjekt des Renderobjektes.
|
||||
@param pAnimationTemplate ein Pointer auf das Animationstemplate
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@remark Das Renderobjekt übernimmt die Verwaltung des Animationstemplate.
|
||||
@brief Erzeugt eine Animation auf Basis eines Animationstemplate als Kinderobjekt des Renderobjektes.
|
||||
@param pAnimationTemplate ein Pointer auf das Animationstemplate
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@remark Das Renderobjekt übernimmt die Verwaltung des Animationstemplate.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Animation> AddAnimation(const BS_AnimationTemplate &AnimationTemplate);
|
||||
/**
|
||||
@brief Erzeugt ein neues Farbpanel als Kinderobjekt des Renderobjektes.
|
||||
@param Width die Breite des Panels
|
||||
@param Height die Höhe des Panels
|
||||
@param Color die Farbe des Panels.<br>
|
||||
Der Standardwert ist Schwarz (BS_RGB(0, 0, 0)).
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@param Width die Breite des Panels
|
||||
@param Height die Höhe des Panels
|
||||
@param Color die Farbe des Panels.<br>
|
||||
Der Standardwert ist Schwarz (BS_RGB(0, 0, 0)).
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
|
||||
|
||||
BS_RenderObjectPtr<BS_Panel> AddPanel(int Width, int Height, unsigned int Color = 0xff000000);
|
||||
/**
|
||||
@brief Erzeugt ein Textobjekt als Kinderobjekt des Renderobjektes.
|
||||
@param Font der Dateiname des zu verwendenen Fonts
|
||||
@param Text der anzuzeigende Text.<br>
|
||||
Der Standardwert ist "".
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@param Font der Dateiname des zu verwendenen Fonts
|
||||
@param Text der anzuzeigende Text.<br>
|
||||
Der Standardwert ist "".
|
||||
@return Gibt einen BS_RenderObjectPtr auf das erzeugte Objekt zurück.<br>
|
||||
Falls ein Fehler aufgetreten ist wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Text> AddText(const Common::String &Font, const Common::String &Text = "");
|
||||
|
||||
// Cast-Methoden
|
||||
// -------------
|
||||
/**
|
||||
@brief Castet das Objekt zu einem BS_Bitmap-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@brief Castet das Objekt zu einem BS_Bitmap-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Bitmap> ToBitmap()
|
||||
{
|
||||
if (m_Type == TYPE_STATICBITMAP || m_Type == TYPE_DYNAMICBITMAP) return BS_RenderObjectPtr<BS_Bitmap>(this); else return BS_RenderObjectPtr<BS_Bitmap>();
|
||||
BS_RenderObjectPtr<BS_Bitmap> ToBitmap() {
|
||||
if (m_Type == TYPE_STATICBITMAP || m_Type == TYPE_DYNAMICBITMAP) return BS_RenderObjectPtr<BS_Bitmap>(this);
|
||||
else return BS_RenderObjectPtr<BS_Bitmap>();
|
||||
}
|
||||
/**
|
||||
@brief Castet das Objekt zu einem BS_Animation-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@brief Castet das Objekt zu einem BS_Animation-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Animation> ToAnimation()
|
||||
{
|
||||
if (m_Type == TYPE_ANIMATION) return BS_RenderObjectPtr<BS_Animation>(this); else return BS_RenderObjectPtr<BS_Animation>();
|
||||
BS_RenderObjectPtr<BS_Animation> ToAnimation() {
|
||||
if (m_Type == TYPE_ANIMATION) return BS_RenderObjectPtr<BS_Animation>(this);
|
||||
else return BS_RenderObjectPtr<BS_Animation>();
|
||||
}
|
||||
/**
|
||||
@brief Castet das Objekt zu einem BS_Panel-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@brief Castet das Objekt zu einem BS_Panel-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Panel> ToPanel()
|
||||
{
|
||||
if (m_Type == TYPE_PANEL) return BS_RenderObjectPtr<BS_Panel>(this); else return BS_RenderObjectPtr<BS_Panel>();
|
||||
BS_RenderObjectPtr<BS_Panel> ToPanel() {
|
||||
if (m_Type == TYPE_PANEL) return BS_RenderObjectPtr<BS_Panel>(this);
|
||||
else return BS_RenderObjectPtr<BS_Panel>();
|
||||
}
|
||||
/**
|
||||
@brief Castet das Object zu einem BS_Text-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
@brief Castet das Object zu einem BS_Text-Objekt wenn zulässig.
|
||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_Text> ToText()
|
||||
{
|
||||
if (m_Type == TYPE_TEXT) return BS_RenderObjectPtr<BS_Text>(this); else return BS_RenderObjectPtr<BS_Text>();
|
||||
BS_RenderObjectPtr<BS_Text> ToText() {
|
||||
if (m_Type == TYPE_TEXT) return BS_RenderObjectPtr<BS_Text>(this);
|
||||
else return BS_RenderObjectPtr<BS_Text>();
|
||||
}
|
||||
|
||||
// Konstruktor / Desktruktor
|
||||
// -------------------------
|
||||
/**
|
||||
@brief Erzeugt ein neues BS_RenderObject.
|
||||
@param pKernel ein Pointer auf den Kernel
|
||||
@param pParent ein Pointer auf das Elternobjekt des neuen Objektes im Objektbaum.<br>
|
||||
Der Pointer darf nicht NULL sein.
|
||||
@param Type der Objekttyp<br>
|
||||
Der Typ BS_RenderObject::TYPE_ROOT ist nicht zulässig. Wurzelknoten müssen mit dem alternativen Konstruktor erzeugt
|
||||
werden.
|
||||
@param Handle das Handle, welches dem Objekt zugewiesen werden soll.<br>
|
||||
Dieser Parameter erzwingt ein bestimmtes Handle für das neue Objekt, oder wählt automatisch ein Handle, wenn der Parameter 0 ist.
|
||||
Ist das gewünschte Handle bereits vergeben, gibt GetInitSuccess() false zurück.<br>
|
||||
Der Standardwert ist 0.
|
||||
@remark Nach dem Aufruf des Konstruktors kann über die Methode GetInitSuccess() abgefragt werden, ob die Konstruktion erfolgreich war.<br>
|
||||
Es ist nicht notwendig alle BS_RenderObject Instanzen einzeln zu löschen. Dieses geschiet automatisch beim Löschen eines
|
||||
Vorfahren oder beim Löschen des zuständigen BS_RenderObjectManager.
|
||||
@brief Erzeugt ein neues BS_RenderObject.
|
||||
@param pKernel ein Pointer auf den Kernel
|
||||
@param pParent ein Pointer auf das Elternobjekt des neuen Objektes im Objektbaum.<br>
|
||||
Der Pointer darf nicht NULL sein.
|
||||
@param Type der Objekttyp<br>
|
||||
Der Typ BS_RenderObject::TYPE_ROOT ist nicht zulässig. Wurzelknoten müssen mit dem alternativen Konstruktor erzeugt
|
||||
werden.
|
||||
@param Handle das Handle, welches dem Objekt zugewiesen werden soll.<br>
|
||||
Dieser Parameter erzwingt ein bestimmtes Handle für das neue Objekt, oder wählt automatisch ein Handle, wenn der Parameter 0 ist.
|
||||
Ist das gewünschte Handle bereits vergeben, gibt GetInitSuccess() false zurück.<br>
|
||||
Der Standardwert ist 0.
|
||||
@remark Nach dem Aufruf des Konstruktors kann über die Methode GetInitSuccess() abgefragt werden, ob die Konstruktion erfolgreich war.<br>
|
||||
Es ist nicht notwendig alle BS_RenderObject Instanzen einzeln zu löschen. Dieses geschiet automatisch beim Löschen eines
|
||||
Vorfahren oder beim Löschen des zuständigen BS_RenderObjectManager.
|
||||
*/
|
||||
BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle = 0);
|
||||
virtual ~BS_RenderObject();
|
||||
|
@ -214,119 +212,145 @@ public:
|
|||
// Interface
|
||||
// ---------
|
||||
/**
|
||||
@brief Rendert des Objekt und alle seine Unterobjekte.
|
||||
@return Gibt false zurück, falls beim Rendern ein Fehler aufgetreten ist.
|
||||
@remark Vor jedem Aufruf dieser Methode muss ein Aufruf von UpdateObjectState() erfolgt sein.
|
||||
Dieses kann entweder direkt geschehen oder durch den Aufruf von UpdateObjectState() an einem Vorfahren-Objekt.<br>
|
||||
Diese Methode darf nur von BS_RenderObjectManager aufgerufen werden.
|
||||
@brief Rendert des Objekt und alle seine Unterobjekte.
|
||||
@return Gibt false zurück, falls beim Rendern ein Fehler aufgetreten ist.
|
||||
@remark Vor jedem Aufruf dieser Methode muss ein Aufruf von UpdateObjectState() erfolgt sein.
|
||||
Dieses kann entweder direkt geschehen oder durch den Aufruf von UpdateObjectState() an einem Vorfahren-Objekt.<br>
|
||||
Diese Methode darf nur von BS_RenderObjectManager aufgerufen werden.
|
||||
*/
|
||||
bool Render();
|
||||
bool Render();
|
||||
/**
|
||||
@brief Bereitet das Objekt und alle seine Unterobjekte auf einen Rendervorgang vor.
|
||||
Hierbei werden alle Dirty-Rectangles berechnet und die Renderreihenfolge aktualisiert.
|
||||
@return Gibt false zurück, falls ein Fehler aufgetreten ist.
|
||||
@remark Diese Methode darf nur von BS_RenderObjectManager aufgerufen werden.
|
||||
@brief Bereitet das Objekt und alle seine Unterobjekte auf einen Rendervorgang vor.
|
||||
Hierbei werden alle Dirty-Rectangles berechnet und die Renderreihenfolge aktualisiert.
|
||||
@return Gibt false zurück, falls ein Fehler aufgetreten ist.
|
||||
@remark Diese Methode darf nur von BS_RenderObjectManager aufgerufen werden.
|
||||
*/
|
||||
bool UpdateObjectState();
|
||||
bool UpdateObjectState();
|
||||
/**
|
||||
@brief Löscht alle Kinderobjekte.
|
||||
@brief Löscht alle Kinderobjekte.
|
||||
*/
|
||||
void DeleteAllChildren();
|
||||
|
||||
// Accessor-Methoden
|
||||
// -----------------
|
||||
/**
|
||||
@brief Setzt die Position des Objektes.
|
||||
@param X die neue X-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
@param Y die neue Y-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
@brief Setzt die Position des Objektes.
|
||||
@param X die neue X-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
@param Y die neue Y-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
*/
|
||||
virtual void SetPos(int X, int Y);
|
||||
/**
|
||||
@brief Setzt die Position des Objektes auf der X-Achse.
|
||||
@param X die neue X-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
@brief Setzt die Position des Objektes auf der X-Achse.
|
||||
@param X die neue X-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
*/
|
||||
virtual void SetX(int X);
|
||||
/**
|
||||
@brief Setzt die Position des Objektes auf der Y-Achse.
|
||||
@param Y die neue Y-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
@brief Setzt die Position des Objektes auf der Y-Achse.
|
||||
@param Y die neue Y-Koordinate des Objektes relativ zum Elternobjekt.
|
||||
*/
|
||||
virtual void SetY(int Y);
|
||||
/**
|
||||
@brief Setzt den Z-Wert des Objektes.
|
||||
@param Z der neue Z-Wert des Objektes relativ zum Elternobjekt<br>
|
||||
Negative Z-Werte sind nicht zulässig.
|
||||
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
||||
Z-Wert gezeichnet. Je höher der Z-Wert desto weiter "vorne" liegt ein Objekt also.<br>
|
||||
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
||||
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
||||
@brief Setzt den Z-Wert des Objektes.
|
||||
@param Z der neue Z-Wert des Objektes relativ zum Elternobjekt<br>
|
||||
Negative Z-Werte sind nicht zulässig.
|
||||
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
||||
Z-Wert gezeichnet. Je höher der Z-Wert desto weiter "vorne" liegt ein Objekt also.<br>
|
||||
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
||||
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
||||
*/
|
||||
virtual void SetZ(int Z);
|
||||
/**
|
||||
@brief Setzt die Sichtbarkeit eine Objektes.
|
||||
@param Visible der neue Sichtbarkeits-Zustand des Objektes<br>
|
||||
true entspricht sichtbar, false entspricht unsichtbar.
|
||||
@brief Setzt die Sichtbarkeit eine Objektes.
|
||||
@param Visible der neue Sichtbarkeits-Zustand des Objektes<br>
|
||||
true entspricht sichtbar, false entspricht unsichtbar.
|
||||
*/
|
||||
virtual void SetVisible(bool Visible);
|
||||
/**
|
||||
@brief Gibt die Position des Objektes auf der X-Achse relativ zum Elternobjekt zurück.
|
||||
@brief Gibt die Position des Objektes auf der X-Achse relativ zum Elternobjekt zurück.
|
||||
*/
|
||||
virtual int GetX() const { return m_X; }
|
||||
virtual int GetX() const {
|
||||
return m_X;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die Position des Objektes auf der Y-Achse relativ zum Elternobjekt zurück.
|
||||
@brief Gibt die Position des Objektes auf der Y-Achse relativ zum Elternobjekt zurück.
|
||||
*/
|
||||
virtual int GetY() const { return m_Y; }
|
||||
virtual int GetY() const {
|
||||
return m_Y;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die absolute Position des Objektes auf der X-Achse zurück.
|
||||
@brief Gibt die absolute Position des Objektes auf der X-Achse zurück.
|
||||
*/
|
||||
virtual int GetAbsoluteX() const { return m_AbsoluteX; }
|
||||
virtual int GetAbsoluteX() const {
|
||||
return m_AbsoluteX;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die absolute Position des Objektes auf der Y-Achse zurück.
|
||||
@brief Gibt die absolute Position des Objektes auf der Y-Achse zurück.
|
||||
*/
|
||||
virtual int GetAbsoluteY() const { return m_AbsoluteY; }
|
||||
virtual int GetAbsoluteY() const {
|
||||
return m_AbsoluteY;
|
||||
}
|
||||
/**
|
||||
@brief Gibt den Z-Wert des Objektes relativ zum Elternobjekt zurück.
|
||||
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
||||
Z-Wert gezeichnet. Je höher der Z-Wert desto weiter "vorne" liegt ein Objekt also.<br>
|
||||
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
||||
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
||||
@brief Gibt den Z-Wert des Objektes relativ zum Elternobjekt zurück.
|
||||
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
||||
Z-Wert gezeichnet. Je höher der Z-Wert desto weiter "vorne" liegt ein Objekt also.<br>
|
||||
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
||||
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
||||
*/
|
||||
int GetZ() const { return m_Z; }
|
||||
int GetZ() const {
|
||||
return m_Z;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die Breite des Objektes zurück.
|
||||
@brief Gibt die Breite des Objektes zurück.
|
||||
*/
|
||||
int GetWidth() const { return m_Width; }
|
||||
int GetWidth() const {
|
||||
return m_Width;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die Höhe des Objektes zurück.
|
||||
@brief Gibt die Höhe des Objektes zurück.
|
||||
*/
|
||||
int GetHeight() const { return m_Height; }
|
||||
int GetHeight() const {
|
||||
return m_Height;
|
||||
}
|
||||
/**
|
||||
@brief Gibt den Sichtbarkeitszustand des Objektes zurück.
|
||||
@return Gibt den Sichtbarkeitszustand des Objektes zurück.<br>
|
||||
true entspricht sichtbar, false entspricht unsichtbar.
|
||||
@brief Gibt den Sichtbarkeitszustand des Objektes zurück.
|
||||
@return Gibt den Sichtbarkeitszustand des Objektes zurück.<br>
|
||||
true entspricht sichtbar, false entspricht unsichtbar.
|
||||
*/
|
||||
bool IsVisible() const { return m_Visible; }
|
||||
bool IsVisible() const {
|
||||
return m_Visible;
|
||||
}
|
||||
/**
|
||||
@brief Gibt den Typ des Objektes zurück.
|
||||
@brief Gibt den Typ des Objektes zurück.
|
||||
*/
|
||||
TYPES GetType() const { return m_Type; }
|
||||
TYPES GetType() const {
|
||||
return m_Type;
|
||||
}
|
||||
/**
|
||||
@brief Gibt zurück, ob das Objekt erfolgreich initialisiert wurde.
|
||||
@remark Hässlicher Workaround um das Problem, dass Konstruktoren keine Rückgabewerte haben.
|
||||
@brief Gibt zurück, ob das Objekt erfolgreich initialisiert wurde.
|
||||
@remark Hässlicher Workaround um das Problem, dass Konstruktoren keine Rückgabewerte haben.
|
||||
*/
|
||||
bool GetInitSuccess() const { return m_InitSuccess; }
|
||||
bool GetInitSuccess() const {
|
||||
return m_InitSuccess;
|
||||
}
|
||||
/**
|
||||
@brief Gibt die Bounding-Box des Objektes zurück.
|
||||
@remark Diese Angabe erfolgt ausnahmsweise in Bildschirmkoordianten und nicht relativ zum Elternobjekt.
|
||||
@brief Gibt die Bounding-Box des Objektes zurück.
|
||||
@remark Diese Angabe erfolgt ausnahmsweise in Bildschirmkoordianten und nicht relativ zum Elternobjekt.
|
||||
*/
|
||||
const BS_Rect& GetBBox() const { return m_BBox; }
|
||||
const BS_Rect &GetBBox() const {
|
||||
return m_BBox;
|
||||
}
|
||||
/**
|
||||
@brief Stellt sicher, dass das Objekt im nächsten Frame neu gezeichnet wird.
|
||||
@brief Stellt sicher, dass das Objekt im nächsten Frame neu gezeichnet wird.
|
||||
*/
|
||||
void ForceRefresh() { m_RefreshForced = true; };
|
||||
void ForceRefresh() {
|
||||
m_RefreshForced = true;
|
||||
};
|
||||
/**
|
||||
@brief Gibt das Handle des Objekte zurück.
|
||||
@brief Gibt das Handle des Objekte zurück.
|
||||
*/
|
||||
unsigned int GetHandle() const { return m_Handle; }
|
||||
unsigned int GetHandle() const {
|
||||
return m_Handle;
|
||||
}
|
||||
|
||||
// Persistenz-Methoden
|
||||
// -------------------
|
||||
|
@ -341,28 +365,28 @@ public:
|
|||
protected:
|
||||
// Typen
|
||||
// -----
|
||||
typedef Common::List<BS_RenderObjectPtr<BS_RenderObject> > RENDEROBJECT_LIST;
|
||||
typedef Common::List<BS_RenderObjectPtr<BS_RenderObject> >::iterator RENDEROBJECT_ITER;
|
||||
typedef Common::List<BS_RenderObjectPtr<BS_RenderObject> > RENDEROBJECT_LIST;
|
||||
typedef Common::List<BS_RenderObjectPtr<BS_RenderObject> >::iterator RENDEROBJECT_ITER;
|
||||
|
||||
int m_X; ///< Die X-Position des Objektes relativ zum Eltern-Objekt
|
||||
int m_Y; ///< Die Y-Position des Objektes relativ zum Eltern-Objekt
|
||||
int m_AbsoluteX; ///< Die absolute X-Position des Objektes
|
||||
int m_AbsoluteY; ///< Die absolute Y-Position des Objektes
|
||||
int m_Z; ///< Der Z-Wert des Objektes relativ zum Eltern-Objekt
|
||||
int m_Width; ///< Die Breite des Objektes
|
||||
int m_Height; ///< Die Höhe des Objektes
|
||||
bool m_Visible; ///< Ist true, wenn das Objekt sichtbar ist
|
||||
bool m_ChildChanged; ///< Ist true, wenn sich ein Kinderobjekt verändert hat
|
||||
TYPES m_Type; ///< Der Objekttyp
|
||||
bool m_InitSuccess; ///< Ist true, wenn Objekt erfolgreich intialisiert werden konnte
|
||||
BS_Rect m_BBox; ///< Die Bounding-Box des Objektes in Bildschirmkoordinaten
|
||||
int m_X; ///< Die X-Position des Objektes relativ zum Eltern-Objekt
|
||||
int m_Y; ///< Die Y-Position des Objektes relativ zum Eltern-Objekt
|
||||
int m_AbsoluteX; ///< Die absolute X-Position des Objektes
|
||||
int m_AbsoluteY; ///< Die absolute Y-Position des Objektes
|
||||
int m_Z; ///< Der Z-Wert des Objektes relativ zum Eltern-Objekt
|
||||
int m_Width; ///< Die Breite des Objektes
|
||||
int m_Height; ///< Die Höhe des Objektes
|
||||
bool m_Visible; ///< Ist true, wenn das Objekt sichtbar ist
|
||||
bool m_ChildChanged; ///< Ist true, wenn sich ein Kinderobjekt verändert hat
|
||||
TYPES m_Type; ///< Der Objekttyp
|
||||
bool m_InitSuccess; ///< Ist true, wenn Objekt erfolgreich intialisiert werden konnte
|
||||
BS_Rect m_BBox; ///< Die Bounding-Box des Objektes in Bildschirmkoordinaten
|
||||
|
||||
// Kopien der Variablen, die für die Errechnung des Dirty-Rects und zur Bestimmung der Objektveränderung notwendig sind
|
||||
BS_Rect m_OldBBox;
|
||||
int m_OldX;
|
||||
int m_OldY;
|
||||
int m_OldZ;
|
||||
bool m_OldVisible;
|
||||
BS_Rect m_OldBBox;
|
||||
int m_OldX;
|
||||
int m_OldY;
|
||||
int m_OldZ;
|
||||
bool m_OldVisible;
|
||||
|
||||
/// Ein Pointer auf den BS_RenderObjektManager, der das Objekt verwaltet.
|
||||
BS_RenderObjectManager *m_ManagerPtr;
|
||||
|
@ -370,13 +394,13 @@ protected:
|
|||
// Render-Methode
|
||||
// --------------
|
||||
/**
|
||||
@brief Einschubmethode, die den tatsächlichen Redervorgang durchführt.
|
||||
@brief Einschubmethode, die den tatsächlichen Redervorgang durchführt.
|
||||
|
||||
Diese Methode wird von Render() aufgerufen um das Objekt darzustellen.
|
||||
Diese Methode sollte von allen Klassen implementiert werden, die von BS_RederObject erben, um das Zeichnen umzusetzen.
|
||||
Diese Methode wird von Render() aufgerufen um das Objekt darzustellen.
|
||||
Diese Methode sollte von allen Klassen implementiert werden, die von BS_RederObject erben, um das Zeichnen umzusetzen.
|
||||
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@remark
|
||||
*/
|
||||
virtual bool DoRender() = 0; // { return true; };
|
||||
|
||||
|
@ -393,27 +417,29 @@ protected:
|
|||
// / | \.
|
||||
// / | \.
|
||||
// Background Interface Maus
|
||||
// / \ / | \.
|
||||
// / \ / | \.
|
||||
// / \ / | \.
|
||||
// George Tür Icn1 Icn2 Icn3
|
||||
//
|
||||
//
|
||||
// Wenn jetzt das Interface mit SetVisible() ausgeblendet würde, verschwinden auch die Icons, die sich im Interface
|
||||
// befinden.
|
||||
// Wenn der Hintergrund bewegt wird (Scrolling), bewegen sich auch die darauf befindlichen Gegenstände und Personen.
|
||||
|
||||
/// Ein Pointer auf das Elternobjekt.
|
||||
BS_RenderObjectPtr<BS_RenderObject> m_ParentPtr;
|
||||
BS_RenderObjectPtr<BS_RenderObject> m_ParentPtr;
|
||||
/// Die Liste der Kinderobjekte nach der Renderreihenfolge geordnet
|
||||
RENDEROBJECT_LIST m_Children;
|
||||
RENDEROBJECT_LIST m_Children;
|
||||
|
||||
/**
|
||||
@brief Gibt einen Pointer auf den BS_RenderObjektManager zurück, der das Objekt verwaltet.
|
||||
@brief Gibt einen Pointer auf den BS_RenderObjektManager zurück, der das Objekt verwaltet.
|
||||
*/
|
||||
BS_RenderObjectManager* GetManager() const { return m_ManagerPtr; }
|
||||
BS_RenderObjectManager *GetManager() const {
|
||||
return m_ManagerPtr;
|
||||
}
|
||||
/**
|
||||
@brief Fügt dem Objekt ein neues Kinderobjekt hinzu.
|
||||
@param pObject ein Pointer auf das einzufügende Objekt
|
||||
@return Gibt false zurück, falls das Objekt nicht eingefügt werden konnte.
|
||||
@brief Fügt dem Objekt ein neues Kinderobjekt hinzu.
|
||||
@param pObject ein Pointer auf das einzufügende Objekt
|
||||
@return Gibt false zurück, falls das Objekt nicht eingefügt werden konnte.
|
||||
*/
|
||||
bool AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject);
|
||||
|
||||
|
@ -424,67 +450,69 @@ private:
|
|||
unsigned int m_Handle;
|
||||
|
||||
/**
|
||||
@brief Entfernt ein Objekt aus der Kinderliste.
|
||||
@param pObject ein Pointer auf das zu entfernende Objekt
|
||||
@return Gibt false zurück, falls das zu entfernende Objekt nicht in der Liste gefunden werden konnte.
|
||||
@brief Entfernt ein Objekt aus der Kinderliste.
|
||||
@param pObject ein Pointer auf das zu entfernende Objekt
|
||||
@return Gibt false zurück, falls das zu entfernende Objekt nicht in der Liste gefunden werden konnte.
|
||||
*/
|
||||
bool DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject);
|
||||
bool DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject);
|
||||
/**
|
||||
@brief Berechnet die Bounding-Box und registriert das Dirty-Rect beim BS_RenderObjectManager.
|
||||
@brief Berechnet die Bounding-Box und registriert das Dirty-Rect beim BS_RenderObjectManager.
|
||||
*/
|
||||
void UpdateBoxes();
|
||||
void UpdateBoxes();
|
||||
/**
|
||||
@brief Berechnet die Bounding-Box des Objektes.
|
||||
@return Gibt die Bounding-Box des Objektes in Bildschirmkoordinaten zurück.
|
||||
@brief Berechnet die Bounding-Box des Objektes.
|
||||
@return Gibt die Bounding-Box des Objektes in Bildschirmkoordinaten zurück.
|
||||
*/
|
||||
BS_Rect CalcBoundingBox() const;
|
||||
/**
|
||||
@brief Berechnet das Dirty-Rectangle des Objektes.
|
||||
@return Gibt das Dirty-Rectangle des Objektes in Bildschirmkoordinaten zurück.
|
||||
@brief Berechnet das Dirty-Rectangle des Objektes.
|
||||
@return Gibt das Dirty-Rectangle des Objektes in Bildschirmkoordinaten zurück.
|
||||
*/
|
||||
BS_Rect CalcDirtyRect() const;
|
||||
/**
|
||||
@brief Berechnet die absolute Position des Objektes.
|
||||
@brief Berechnet die absolute Position des Objektes.
|
||||
*/
|
||||
void CalcAbsolutePos(int &X, int &Y) const;
|
||||
/**
|
||||
@brief Berechnet die absolute Position des Objektes auf der X-Achse.
|
||||
@brief Berechnet die absolute Position des Objektes auf der X-Achse.
|
||||
*/
|
||||
int CalcAbsoluteX() const;
|
||||
/**
|
||||
@brief Berechnet die absolute Position des Objektes.
|
||||
@brief Berechnet die absolute Position des Objektes.
|
||||
*/
|
||||
int CalcAbsoluteY() const;
|
||||
/**
|
||||
@brief Sortiert alle Kinderobjekte nach ihrem Renderang.
|
||||
@brief Sortiert alle Kinderobjekte nach ihrem Renderang.
|
||||
*/
|
||||
void SortRenderObjects();
|
||||
/**
|
||||
@brief Validiert den Zustand eines Objektes nachdem die durch die Veränderung verursachten Folgen abgearbeitet wurden.
|
||||
@brief Validiert den Zustand eines Objektes nachdem die durch die Veränderung verursachten Folgen abgearbeitet wurden.
|
||||
*/
|
||||
void ValidateObject();
|
||||
void ValidateObject();
|
||||
/**
|
||||
@brief Berechnet die absolute Position des Objektes und aller seiner Kinderobjekte neu.
|
||||
@brief Berechnet die absolute Position des Objektes und aller seiner Kinderobjekte neu.
|
||||
|
||||
Diese Methode muss aufgerufen werden, wann immer sich die Position des Objektes verändert. Damit die Kinderobjekte immer die
|
||||
richtige absolute Position haben.
|
||||
Diese Methode muss aufgerufen werden, wann immer sich die Position des Objektes verändert. Damit die Kinderobjekte immer die
|
||||
richtige absolute Position haben.
|
||||
*/
|
||||
void UpdateAbsolutePos();
|
||||
/**
|
||||
@brief Teilt dem Objekt mit, dass sich eines seiner Kinderobjekte dahingehend verändert hat, die eine erneute Bestimmung der
|
||||
Rendereihenfolge verlangt.
|
||||
@brief Teilt dem Objekt mit, dass sich eines seiner Kinderobjekte dahingehend verändert hat, die eine erneute Bestimmung der
|
||||
Rendereihenfolge verlangt.
|
||||
*/
|
||||
void SignalChildChange() { m_ChildChanged = true; }
|
||||
void SignalChildChange() {
|
||||
m_ChildChanged = true;
|
||||
}
|
||||
/**
|
||||
@brief Berechnet des Schnittrechteck der Bounding-Box des Objektes mit einem anderen Objekt.
|
||||
@param pObjekt ein Pointer auf das Objekt mit dem geschnitten werden soll
|
||||
@param Result das Ergebnisrechteck
|
||||
@return Gibt false zurück, falls sich die Objekte gar nicht schneiden.
|
||||
@brief Berechnet des Schnittrechteck der Bounding-Box des Objektes mit einem anderen Objekt.
|
||||
@param pObjekt ein Pointer auf das Objekt mit dem geschnitten werden soll
|
||||
@param Result das Ergebnisrechteck
|
||||
@return Gibt false zurück, falls sich die Objekte gar nicht schneiden.
|
||||
*/
|
||||
bool GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect& Result);
|
||||
bool GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect &Result);
|
||||
/**
|
||||
@brief Vergleichsoperator der auf Objektpointern basiert statt auf Objekten.
|
||||
@remark Diese Methode wird fürs Sortieren der Kinderliste nach der Rendereihenfolge benutzt.
|
||||
@brief Vergleichsoperator der auf Objektpointern basiert statt auf Objekten.
|
||||
@remark Diese Methode wird fürs Sortieren der Kinderliste nach der Rendereihenfolge benutzt.
|
||||
*/
|
||||
static bool Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs);
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -57,16 +57,14 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectManager::BS_RenderObjectManager(int Width, int Height, int FramebufferCount) :
|
||||
m_FrameStarted(false)
|
||||
{
|
||||
m_FrameStarted(false) {
|
||||
// Wurzel des BS_RenderObject-Baumes erzeugen.
|
||||
m_RootPtr = new BS_RootRenderObject(this, Width, Height);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_RenderObjectManager::~BS_RenderObjectManager()
|
||||
{
|
||||
BS_RenderObjectManager::~BS_RenderObjectManager() {
|
||||
// Die Wurzel des Baumes löschen, damit werden alle BS_RenderObjects mitgelöscht.
|
||||
m_RootPtr.Erase();
|
||||
}
|
||||
|
@ -75,8 +73,7 @@ BS_RenderObjectManager::~BS_RenderObjectManager()
|
|||
// Interface
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_RenderObjectManager::StartFrame()
|
||||
{
|
||||
void BS_RenderObjectManager::StartFrame() {
|
||||
m_FrameStarted = true;
|
||||
|
||||
// Verstrichene Zeit bestimmen
|
||||
|
@ -90,8 +87,7 @@ void BS_RenderObjectManager::StartFrame()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObjectManager::Render()
|
||||
{
|
||||
bool BS_RenderObjectManager::Render() {
|
||||
// Den Objekt-Status des Wurzelobjektes aktualisieren. Dadurch werden rekursiv alle Baumelemente aktualisiert.
|
||||
// Beim aktualisieren des Objekt-Status werden auch die Update-Rects gefunden, so dass feststeht, was neu gezeichnet
|
||||
// werden muss.
|
||||
|
@ -105,25 +101,22 @@ bool BS_RenderObjectManager::Render()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_RenderObjectManager::AttatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr)
|
||||
{
|
||||
void BS_RenderObjectManager::AttatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr) {
|
||||
m_TimedRenderObjects.push_back(RenderObjectPtr);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_RenderObjectManager::DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr)
|
||||
{
|
||||
void BS_RenderObjectManager::DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr) {
|
||||
RenderObjectList::iterator Iter = find(m_TimedRenderObjects.begin(), m_TimedRenderObjects.end(), RenderObjectPtr);
|
||||
if (Iter != m_TimedRenderObjects.end()) m_TimedRenderObjects.erase(Iter);
|
||||
if (Iter != m_TimedRenderObjects.end()) m_TimedRenderObjects.erase(Iter);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
// Alle Kinder des Wurzelknotens speichern. Dadurch werden alle BS_RenderObjects gespeichert rekursiv gespeichert.
|
||||
|
@ -134,8 +127,7 @@ bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
// Referenzen auf die TimedRenderObjects persistieren.
|
||||
Writer.Write(m_TimedRenderObjects.size());
|
||||
RenderObjectList::const_iterator Iter = m_TimedRenderObjects.begin();
|
||||
while (Iter != m_TimedRenderObjects.end())
|
||||
{
|
||||
while (Iter != m_TimedRenderObjects.end()) {
|
||||
Writer.Write((*Iter)->GetHandle());
|
||||
++Iter;
|
||||
}
|
||||
|
@ -148,8 +140,7 @@ bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
// Alle Kinder des Wurzelknotens löschen. Damit werden alle BS_RenderObjects gelöscht.
|
||||
|
@ -166,8 +157,7 @@ bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock & Reader)
|
|||
// Referenzen auf die TimedRenderObjects wieder herstellen.
|
||||
unsigned int TimedObjectCount;
|
||||
Reader.Read(TimedObjectCount);
|
||||
for (unsigned int i = 0; i < TimedObjectCount; ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < TimedObjectCount; ++i) {
|
||||
unsigned int Handle;
|
||||
Reader.Read(Handle);
|
||||
m_TimedRenderObjects.push_back(Handle);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,13 +33,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
BS_RenderObjectManager
|
||||
----------------------
|
||||
Diese Klasse ist für die Verwaltung von BS_RenderObjects zuständig.
|
||||
|
||||
Sie sorgt z.B. dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden.
|
||||
BS_RenderObjectManager
|
||||
----------------------
|
||||
Diese Klasse ist für die Verwaltung von BS_RenderObjects zuständig.
|
||||
|
||||
Autor: Malte Thiesen
|
||||
Sie sorgt z.B. dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden.
|
||||
|
||||
Autor: Malte Thiesen
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_RENDEROBJECTMANAGER_H
|
||||
|
@ -63,59 +63,60 @@ class BS_RenderObject;
|
|||
class BS_TimedRenderObject;
|
||||
|
||||
/**
|
||||
@brief Diese Klasse ist für die Verwaltung von BS_RenderObjects zuständig.
|
||||
|
||||
Sie sorgt dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden und ermöglicht den Zugriff auf die
|
||||
BS_RenderObjects über einen String.
|
||||
@brief Diese Klasse ist für die Verwaltung von BS_RenderObjects zuständig.
|
||||
|
||||
Sie sorgt dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden und ermöglicht den Zugriff auf die
|
||||
BS_RenderObjects über einen String.
|
||||
*/
|
||||
class BS_RenderObjectManager : public BS_Persistable
|
||||
{
|
||||
class BS_RenderObjectManager : public BS_Persistable {
|
||||
public:
|
||||
/**
|
||||
@brief Erzeugt ein neues BS_RenderObjectManager-Objekt.
|
||||
@param Width die horizontale Bildschirmauflösung in Pixeln
|
||||
@param Height die vertikale Bildschirmauflösung in Pixeln
|
||||
@param Die Anzahl an Framebuffern, die eingesetzt wird (Backbuffer + Primary).
|
||||
@brief Erzeugt ein neues BS_RenderObjectManager-Objekt.
|
||||
@param Width die horizontale Bildschirmauflösung in Pixeln
|
||||
@param Height die vertikale Bildschirmauflösung in Pixeln
|
||||
@param Die Anzahl an Framebuffern, die eingesetzt wird (Backbuffer + Primary).
|
||||
*/
|
||||
BS_RenderObjectManager(int Width, int Height, int FramebufferCount);
|
||||
virtual ~BS_RenderObjectManager();
|
||||
|
||||
|
||||
// Interface
|
||||
// ---------
|
||||
/**
|
||||
@brief Initialisiert den Manager für einen neuen Frame.
|
||||
@remark Alle Veränderungen an Objekten müssen nach einem Aufruf dieser Methode geschehen, damit sichergestellt ist, dass diese
|
||||
visuell umgesetzt werden.<br>
|
||||
Mit dem Aufruf dieser Methode werden die Rückgabewerte von GetUpdateRects() und GetUpdateRectCount() auf ihre Startwerte
|
||||
zurückgesetzt. Wenn man also mit diesen Werten arbeiten möchten, muss man dies nach einem Aufruf von Render() und vor
|
||||
einem Aufruf von StartFrame() tun.
|
||||
@brief Initialisiert den Manager für einen neuen Frame.
|
||||
@remark Alle Veränderungen an Objekten müssen nach einem Aufruf dieser Methode geschehen, damit sichergestellt ist, dass diese
|
||||
visuell umgesetzt werden.<br>
|
||||
Mit dem Aufruf dieser Methode werden die Rückgabewerte von GetUpdateRects() und GetUpdateRectCount() auf ihre Startwerte
|
||||
zurückgesetzt. Wenn man also mit diesen Werten arbeiten möchten, muss man dies nach einem Aufruf von Render() und vor
|
||||
einem Aufruf von StartFrame() tun.
|
||||
*/
|
||||
void StartFrame();
|
||||
/**
|
||||
@brief Rendert alle Objekte die sich während des letzten Aufrufes von Render() verändert haben.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
@brief Rendert alle Objekte die sich während des letzten Aufrufes von Render() verändert haben.
|
||||
@return Gibt false zurück, falls das Rendern fehlgeschlagen ist.
|
||||
*/
|
||||
bool Render();
|
||||
/**
|
||||
@brief Gibt einen Pointer auf die Wurzel des Objektbaumes zurück.
|
||||
@brief Gibt einen Pointer auf die Wurzel des Objektbaumes zurück.
|
||||
*/
|
||||
BS_RenderObjectPtr<BS_RenderObject> GetTreeRoot() { return m_RootPtr; }
|
||||
BS_RenderObjectPtr<BS_RenderObject> GetTreeRoot() {
|
||||
return m_RootPtr;
|
||||
}
|
||||
/**
|
||||
@brief Fügt ein BS_TimedRenderObject in die Liste der zeitabhängigen Render-Objekte.
|
||||
@brief Fügt ein BS_TimedRenderObject in die Liste der zeitabhängigen Render-Objekte.
|
||||
|
||||
Alle Objekte die sich in dieser Liste befinden werden vor jedem Frame über die seit dem letzten Frame
|
||||
vergangene Zeit informiert, so dass sich ihren Zustand zeitabhängig verändern können.
|
||||
Alle Objekte die sich in dieser Liste befinden werden vor jedem Frame über die seit dem letzten Frame
|
||||
vergangene Zeit informiert, so dass sich ihren Zustand zeitabhängig verändern können.
|
||||
|
||||
@param RenderObject das einzufügende BS_TimedRenderObject
|
||||
@param RenderObject das einzufügende BS_TimedRenderObject
|
||||
*/
|
||||
void AttatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> pRenderObject);
|
||||
/**
|
||||
@brief Entfernt ein BS_TimedRenderObject aus der Liste für zeitabhängige Render-Objekte.
|
||||
@brief Entfernt ein BS_TimedRenderObject aus der Liste für zeitabhängige Render-Objekte.
|
||||
*/
|
||||
void DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> pRenderObject);
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
private:
|
||||
bool m_FrameStarted;
|
||||
|
@ -126,7 +127,7 @@ private:
|
|||
// ---------------------------
|
||||
// Der Baum legt die hierachische Ordnung der BS_RenderObjects fest.
|
||||
// Zu weiteren Informationen siehe: "renderobject.h"
|
||||
BS_RenderObjectPtr<BS_RenderObject> m_RootPtr; // Die Wurzel der Baumes
|
||||
BS_RenderObjectPtr<BS_RenderObject> m_RootPtr; // Die Wurzel der Baumes
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
namespace Sword25 {
|
||||
|
||||
BS_RenderObjectPtr::BS_RenderObjectPtr(BS_RenderObject * RenderObjectPtr) {
|
||||
BS_RenderObjectPtr::BS_RenderObjectPtr(BS_RenderObject *RenderObjectPtr) {
|
||||
m_Handle = RenderObjectPtr->GetHandle();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -55,8 +55,7 @@ class BS_RenderObject;
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
template<class T>
|
||||
class BS_RenderObjectPtr
|
||||
{
|
||||
class BS_RenderObjectPtr {
|
||||
public:
|
||||
BS_RenderObjectPtr() : m_Handle(0)
|
||||
{}
|
||||
|
@ -64,25 +63,21 @@ public:
|
|||
BS_RenderObjectPtr(unsigned int Handle) : m_Handle(Handle)
|
||||
{}
|
||||
|
||||
BS_RenderObjectPtr(BS_RenderObject * RenderObjectPtr);
|
||||
BS_RenderObjectPtr(BS_RenderObject *RenderObjectPtr);
|
||||
|
||||
T * operator->() const
|
||||
{
|
||||
T *operator->() const {
|
||||
return static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
||||
}
|
||||
|
||||
bool operator==(const BS_RenderObjectPtr<T> & other)
|
||||
{
|
||||
bool operator==(const BS_RenderObjectPtr<T> & other) {
|
||||
return m_Handle == other.m_Handle;
|
||||
}
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
bool IsValid() const {
|
||||
return BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle) != 0;
|
||||
}
|
||||
|
||||
void Erase()
|
||||
{
|
||||
void Erase() {
|
||||
delete static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
||||
m_Handle = 0;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,15 +54,13 @@ std::auto_ptr<BS_RenderObjectRegistry> BS_RenderObjectRegistry::m_InstancePtr;
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_RenderObjectRegistry::LogErrorLn(const char * Message) const
|
||||
{
|
||||
void BS_RenderObjectRegistry::LogErrorLn(const char *Message) const {
|
||||
BS_LOG_ERRORLN(Message);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_RenderObjectRegistry::LogWarningLn(const char * Message) const
|
||||
{
|
||||
void BS_RenderObjectRegistry::LogWarningLn(const char *Message) const {
|
||||
BS_LOG_WARNINGLN(Message);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -60,7 +60,7 @@ class BS_RenderObject;
|
|||
|
||||
class BS_RenderObjectRegistry : public BS_ObjectRegistry<BS_RenderObject> {
|
||||
public:
|
||||
static BS_RenderObjectRegistry & GetInstance() {
|
||||
static BS_RenderObjectRegistry &GetInstance() {
|
||||
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_RenderObjectRegistry);
|
||||
return *m_InstancePtr.get();
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ public:
|
|||
virtual ~BS_RenderObjectRegistry() {}
|
||||
|
||||
private:
|
||||
virtual void LogErrorLn(const char * Message) const;
|
||||
virtual void LogWarningLn(const char * Message) const;
|
||||
virtual void LogErrorLn(const char *Message) const;
|
||||
virtual void LogWarningLn(const char *Message) const;
|
||||
|
||||
static std::auto_ptr<BS_RenderObjectRegistry> m_InstancePtr;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -50,21 +50,21 @@ class BS_Kernel;
|
|||
// Klassendefinition
|
||||
class BS_RenderObjectManager;
|
||||
|
||||
class BS_RootRenderObject : public BS_RenderObject
|
||||
{
|
||||
friend BS_RenderObjectManager;
|
||||
class BS_RootRenderObject : public BS_RenderObject {
|
||||
friend BS_RenderObjectManager;
|
||||
|
||||
private:
|
||||
BS_RootRenderObject(BS_RenderObjectManager * ManagerPtr, int Width, int Height) :
|
||||
BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject>(), TYPE_ROOT)
|
||||
{
|
||||
BS_RootRenderObject(BS_RenderObjectManager *ManagerPtr, int Width, int Height) :
|
||||
BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject>(), TYPE_ROOT) {
|
||||
m_ManagerPtr = ManagerPtr;
|
||||
m_Width = Width;
|
||||
m_Height = Height;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool DoRender() { return true; }
|
||||
virtual bool DoRender() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -47,21 +47,19 @@ using namespace std;
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct RGB_PIXEL
|
||||
{
|
||||
struct RGB_PIXEL {
|
||||
RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) :
|
||||
Red(_Red),
|
||||
Green(_Green),
|
||||
Blue(_Blue)
|
||||
{};
|
||||
{};
|
||||
|
||||
unsigned char Red;
|
||||
unsigned char Green;
|
||||
unsigned char Blue;
|
||||
};
|
||||
|
||||
bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string & Filename)
|
||||
{
|
||||
bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string &Filename) {
|
||||
BS_ASSERT(Data.size() == Width * Height);
|
||||
|
||||
// Buffer für Bildschirminhalt in RGB reservieren
|
||||
|
@ -70,10 +68,8 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
|||
|
||||
// Framebufferdaten pixelweise von RGBA nach RGB konvertieren
|
||||
vector<unsigned int>::const_iterator it = Data.begin();
|
||||
for (unsigned int y = 0; y < Height; y++)
|
||||
{
|
||||
for (unsigned int x = 0; x < Width; x++)
|
||||
{
|
||||
for (unsigned int y = 0; y < Height; y++) {
|
||||
for (unsigned int x = 0; x < Width; x++) {
|
||||
unsigned int SrcPixel = *it++;
|
||||
PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff));
|
||||
}
|
||||
|
@ -82,29 +78,25 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
|||
BS_ASSERT(Data.size() == PixelBuffer.size());
|
||||
|
||||
// Variablen für die PNG-Erstellung
|
||||
FILE * OutFile = 0;
|
||||
FILE *OutFile = 0;
|
||||
png_structp png_ptr = 0;
|
||||
png_infop info_ptr = 0;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
OutFile = fopen(Filename.c_str(), "wb");
|
||||
if (!OutFile)
|
||||
{
|
||||
if (!OutFile) {
|
||||
BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str());
|
||||
throw(0);
|
||||
}
|
||||
|
||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
if (!png_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create PNG write-struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
if (!info_ptr) {
|
||||
BS_LOG_ERRORLN("Could not create PNG info-struct.");
|
||||
throw(0);
|
||||
}
|
||||
|
@ -115,20 +107,19 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
|||
png_set_compression_buffer_size(png_ptr, (Width * Height * 3 * 110) / 100);
|
||||
|
||||
// PNG-Info Struktur initialisieren
|
||||
png_set_IHDR(png_ptr, info_ptr,
|
||||
Width, // Breite
|
||||
Height, // Höhe
|
||||
8, // Bittiefe pro Kanal
|
||||
PNG_COLOR_TYPE_RGB, // Farbformat
|
||||
PNG_INTERLACE_NONE, // Interlacing-Typ
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ
|
||||
PNG_FILTER_TYPE_DEFAULT); // Filter-Typ
|
||||
png_set_IHDR(png_ptr, info_ptr,
|
||||
Width, // Breite
|
||||
Height, // Höhe
|
||||
8, // Bittiefe pro Kanal
|
||||
PNG_COLOR_TYPE_RGB, // Farbformat
|
||||
PNG_INTERLACE_NONE, // Interlacing-Typ
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, // Kompressions-Typ
|
||||
PNG_FILTER_TYPE_DEFAULT); // Filter-Typ
|
||||
|
||||
// Rowpointer erstellen
|
||||
vector<png_bytep> RowPointers;
|
||||
RowPointers.reserve(Height);
|
||||
for (unsigned int i = 0; i < Height; i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < Height; i++) {
|
||||
RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i]));
|
||||
}
|
||||
png_set_rows(png_ptr, info_ptr, &RowPointers[0]);
|
||||
|
@ -142,11 +133,9 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
|||
fclose(OutFile);
|
||||
}
|
||||
|
||||
catch (int)
|
||||
{
|
||||
catch (int) {
|
||||
// Wenn die Datei bereits erstellt wurde, Datei schließen und löschen.
|
||||
if (OutFile)
|
||||
{
|
||||
if (OutFile) {
|
||||
fclose(OutFile);
|
||||
remove(Filename.c_str());
|
||||
}
|
||||
|
@ -163,8 +152,7 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string & Filename)
|
||||
{
|
||||
bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string &Filename) {
|
||||
//
|
||||
// Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125.
|
||||
// Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf
|
||||
|
@ -173,27 +161,23 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height,
|
|||
//
|
||||
|
||||
// Die Ausgangsgröße muss 800x600 sein.
|
||||
if (Width != 800 || Height != 600)
|
||||
{
|
||||
if (Width != 800 || Height != 600) {
|
||||
BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Buffer für die Zieldaten erstellen (RGBA Bild mit den Maßen 200x125).
|
||||
vector<unsigned int> ThumbnailData(200 * 125);
|
||||
|
||||
// Über das Zielbild iterieren und einen Pixel zur Zeit berechnen.
|
||||
unsigned int x, y;
|
||||
x = y = 0;
|
||||
for(vector<unsigned int>::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter)
|
||||
{
|
||||
for (vector<unsigned int>::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) {
|
||||
// Durchschnitt über 4x4 Pixelblock im Quellbild bilden.
|
||||
unsigned int Alpha, Red, Green, Blue;
|
||||
Alpha = Red = Green = Blue = 0;
|
||||
for (unsigned int j = 0; j < 4; ++j)
|
||||
{
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
for (unsigned int j = 0; j < 4; ++j) {
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)];
|
||||
Alpha += (Pixel >> 24);
|
||||
Red += (Pixel >> 16) & 0xff;
|
||||
|
@ -207,8 +191,7 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height,
|
|||
|
||||
// Mitzählen an welcher Stelle im Zielbild wir uns befinden.
|
||||
++x;
|
||||
if (x == 200)
|
||||
{
|
||||
if (x == 200) {
|
||||
x = 0;
|
||||
++y;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_SCREENSHOT_H
|
||||
#ifndef SWORD25_SCREENSHOT_H
|
||||
#define SWORD25_SCREENSHOT_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -51,11 +51,10 @@ namespace Sword25 {
|
|||
// Class declaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_Screenshot
|
||||
{
|
||||
class BS_Screenshot {
|
||||
public:
|
||||
static bool SaveToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String & Filename);
|
||||
static bool SaveThumbnailToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String & Filename);
|
||||
static bool SaveToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String &Filename);
|
||||
static bool SaveThumbnailToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String &Filename);
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,9 +54,8 @@ namespace Sword25 {
|
|||
// Konstruktion / Destruktion
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String& Filename) :
|
||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP)
|
||||
{
|
||||
BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &Filename) :
|
||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP) {
|
||||
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||
if (!m_InitSuccess) return;
|
||||
|
||||
|
@ -65,30 +64,26 @@ BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_StaticBitmap::BS_StaticBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP, Handle)
|
||||
{
|
||||
BS_StaticBitmap::BS_StaticBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP, Handle) {
|
||||
m_InitSuccess = Unpersist(Reader);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::InitBitmapResource(const Common::String & Filename)
|
||||
{
|
||||
bool BS_StaticBitmap::InitBitmapResource(const Common::String &Filename) {
|
||||
// Bild-Resource laden
|
||||
BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(Filename);
|
||||
if (!ResourcePtr)
|
||||
{
|
||||
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(Filename);
|
||||
if (!ResourcePtr) {
|
||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", Filename.c_str());
|
||||
return false;
|
||||
}
|
||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_BITMAP)
|
||||
{
|
||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_BITMAP) {
|
||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", Filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
BS_BitmapResource * BitmapPtr = static_cast<BS_BitmapResource*>(ResourcePtr);
|
||||
BS_BitmapResource *BitmapPtr = static_cast<BS_BitmapResource *>(ResourcePtr);
|
||||
|
||||
// Den eindeutigen Dateinamen zum späteren Referenzieren speichern
|
||||
m_ResourceFilename = BitmapPtr->GetFileName();
|
||||
|
@ -105,39 +100,34 @@ bool BS_StaticBitmap::InitBitmapResource(const Common::String & Filename)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_StaticBitmap::~BS_StaticBitmap()
|
||||
{
|
||||
BS_StaticBitmap::~BS_StaticBitmap() {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::DoRender()
|
||||
{
|
||||
bool BS_StaticBitmap::DoRender() {
|
||||
// Bitmap holen
|
||||
BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_ASSERT(ResourcePtr);
|
||||
BS_ASSERT(ResourcePtr->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource * BitmapResourcePtr = static_cast<BS_BitmapResource*>(ResourcePtr);
|
||||
BS_BitmapResource *BitmapResourcePtr = static_cast<BS_BitmapResource *>(ResourcePtr);
|
||||
|
||||
// Framebufferobjekt holen
|
||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_ASSERT(GfxPtr);
|
||||
|
||||
// Bitmap zeichnen
|
||||
bool Result;
|
||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f)
|
||||
{
|
||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f) {
|
||||
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, -1, -1);
|
||||
} else {
|
||||
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||
0, m_ModulationColor, m_Width, m_Height);
|
||||
}
|
||||
|
||||
// Resource freigeben
|
||||
|
@ -148,14 +138,13 @@ bool BS_StaticBitmap::DoRender()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const
|
||||
{
|
||||
unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const {
|
||||
BS_ASSERT(X >= 0 && X < m_Width);
|
||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
BS_BitmapResource* pBitmapResource = static_cast<BS_BitmapResource*>(pResource);
|
||||
BS_BitmapResource *pBitmapResource = static_cast<BS_BitmapResource *>(pResource);
|
||||
unsigned int Result = pBitmapResource->GetPixel(X, Y);
|
||||
pResource->Release();
|
||||
return Result;
|
||||
|
@ -163,8 +152,7 @@ unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
||||
{
|
||||
bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||
BS_LOG_ERRORLN("SetContent() ist not supported with this object.");
|
||||
return false;
|
||||
}
|
||||
|
@ -173,33 +161,30 @@ bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, uns
|
|||
// Auskunftsmethoden
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::IsAlphaAllowed() const
|
||||
{
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
bool BS_StaticBitmap::IsAlphaAllowed() const {
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsAlphaAllowed();
|
||||
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsAlphaAllowed();
|
||||
pResource->Release();
|
||||
return Result;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::IsColorModulationAllowed() const
|
||||
{
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
bool BS_StaticBitmap::IsColorModulationAllowed() const {
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsColorModulationAllowed();
|
||||
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsColorModulationAllowed();
|
||||
pResource->Release();
|
||||
return Result;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::IsScalingAllowed() const
|
||||
{
|
||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
bool BS_StaticBitmap::IsScalingAllowed() const {
|
||||
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsScalingAllowed();
|
||||
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsScalingAllowed();
|
||||
pResource->Release();
|
||||
return Result;
|
||||
}
|
||||
|
@ -208,8 +193,7 @@ bool BS_StaticBitmap::IsScalingAllowed() const
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_Bitmap::Persist(Writer);
|
||||
|
@ -220,8 +204,7 @@ bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
return Result;
|
||||
}
|
||||
|
||||
bool BS_StaticBitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_StaticBitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_Bitmap::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,39 +48,40 @@ namespace Sword25 {
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_StaticBitmap : public BS_Bitmap
|
||||
{
|
||||
friend class BS_RenderObject;
|
||||
class BS_StaticBitmap : public BS_Bitmap {
|
||||
friend class BS_RenderObject;
|
||||
|
||||
private:
|
||||
/**
|
||||
@remark Filename muss absoluter Pfad sein
|
||||
@remark Filename muss absoluter Pfad sein
|
||||
*/
|
||||
BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String& Filename);
|
||||
BS_StaticBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &Filename);
|
||||
BS_StaticBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
|
||||
public:
|
||||
virtual ~BS_StaticBitmap();
|
||||
|
||||
virtual unsigned int GetPixel(int X, int Y) const;
|
||||
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||
|
||||
virtual bool IsScalingAllowed() const;
|
||||
virtual bool IsAlphaAllowed() const;
|
||||
virtual bool IsColorModulationAllowed() const;
|
||||
virtual bool IsSetContentAllowed() const { return false; }
|
||||
virtual bool IsScalingAllowed() const;
|
||||
virtual bool IsAlphaAllowed() const;
|
||||
virtual bool IsColorModulationAllowed() const;
|
||||
virtual bool IsSetContentAllowed() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
virtual bool DoRender();
|
||||
virtual bool DoRender();
|
||||
|
||||
private:
|
||||
Common::String m_ResourceFilename;
|
||||
|
||||
bool InitBitmapResource(const Common::String & Filename);
|
||||
bool InitBitmapResource(const Common::String &Filename);
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -56,9 +56,8 @@ namespace Sword25 {
|
|||
// Konstanten
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
const unsigned int AUTO_WRAP_THRESHOLD_DEFAULT = 300;
|
||||
namespace {
|
||||
const unsigned int AUTO_WRAP_THRESHOLD_DEFAULT = 300;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -69,33 +68,27 @@ BS_Text::BS_Text(BS_RenderObjectPtr<BS_RenderObject> ParentPtr) :
|
|||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_TEXT),
|
||||
m_ModulationColor(0xffffffff),
|
||||
m_AutoWrap(false),
|
||||
m_AutoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT)
|
||||
{
|
||||
|
||||
m_AutoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT) {
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Text::BS_Text(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_RenderObject(ParentPtr, TYPE_TEXT, Handle)
|
||||
{
|
||||
BS_Text::BS_Text(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||
BS_RenderObject(ParentPtr, TYPE_TEXT, Handle) {
|
||||
m_InitSuccess = Unpersist(Reader);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Text::SetFont(const Common::String & Font)
|
||||
{
|
||||
bool BS_Text::SetFont(const Common::String &Font) {
|
||||
// Font precachen.
|
||||
if (GetResourceManager()->PrecacheResource(Font))
|
||||
{
|
||||
if (GetResourceManager()->PrecacheResource(Font)) {
|
||||
m_Font = Font;
|
||||
UpdateFormat();
|
||||
ForceRefresh();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BS_LOG_ERRORLN("Could not precache font \"%s\". Font probably does not exist.", Font.c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -104,8 +97,7 @@ bool BS_Text::SetFont(const Common::String & Font)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::SetText(const Common::String & Text)
|
||||
{
|
||||
void BS_Text::SetText(const Common::String &Text) {
|
||||
m_Text = Text;
|
||||
UpdateFormat();
|
||||
ForceRefresh();
|
||||
|
@ -113,11 +105,9 @@ void BS_Text::SetText(const Common::String & Text)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::SetColor(unsigned int ModulationColor)
|
||||
{
|
||||
void BS_Text::SetColor(unsigned int ModulationColor) {
|
||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -125,12 +115,10 @@ void BS_Text::SetColor(unsigned int ModulationColor)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::SetAlpha(int Alpha)
|
||||
{
|
||||
void BS_Text::SetAlpha(int Alpha) {
|
||||
BS_ASSERT(Alpha >= 0 && Alpha < 256);
|
||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||
if (NewModulationColor != m_ModulationColor)
|
||||
{
|
||||
if (NewModulationColor != m_ModulationColor) {
|
||||
m_ModulationColor = NewModulationColor;
|
||||
ForceRefresh();
|
||||
}
|
||||
|
@ -138,10 +126,8 @@ void BS_Text::SetAlpha(int Alpha)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::SetAutoWrap(bool AutoWrap)
|
||||
{
|
||||
if (AutoWrap != m_AutoWrap)
|
||||
{
|
||||
void BS_Text::SetAutoWrap(bool AutoWrap) {
|
||||
if (AutoWrap != m_AutoWrap) {
|
||||
m_AutoWrap = AutoWrap;
|
||||
UpdateFormat();
|
||||
ForceRefresh();
|
||||
|
@ -150,10 +136,8 @@ void BS_Text::SetAutoWrap(bool AutoWrap)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold)
|
||||
{
|
||||
if (AutoWrapThreshold != m_AutoWrapThreshold)
|
||||
{
|
||||
void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold) {
|
||||
if (AutoWrapThreshold != m_AutoWrapThreshold) {
|
||||
m_AutoWrapThreshold = AutoWrapThreshold;
|
||||
UpdateFormat();
|
||||
ForceRefresh();
|
||||
|
@ -162,39 +146,35 @@ void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold)
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Text::DoRender()
|
||||
{
|
||||
bool BS_Text::DoRender() {
|
||||
// Font-Resource locken.
|
||||
BS_FontResource * FontPtr = LockFontResource();
|
||||
BS_FontResource *FontPtr = LockFontResource();
|
||||
if (!FontPtr) return false;
|
||||
|
||||
// Charactermap-Resource locken.
|
||||
BS_ResourceManager * RMPtr = GetResourceManager();
|
||||
BS_BitmapResource * CharMapPtr;
|
||||
BS_ResourceManager *RMPtr = GetResourceManager();
|
||||
BS_BitmapResource *CharMapPtr;
|
||||
{
|
||||
BS_Resource * pResource = RMPtr->RequestResource(FontPtr->GetCharactermapFileName());
|
||||
if (!pResource)
|
||||
{
|
||||
BS_Resource *pResource = RMPtr->RequestResource(FontPtr->GetCharactermapFileName());
|
||||
if (!pResource) {
|
||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", FontPtr->GetCharactermapFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
if (pResource->GetType() != BS_Resource::TYPE_BITMAP)
|
||||
{
|
||||
if (pResource->GetType() != BS_Resource::TYPE_BITMAP) {
|
||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", FontPtr->GetCharactermapFileName().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
CharMapPtr = static_cast<BS_BitmapResource*>(pResource);
|
||||
CharMapPtr = static_cast<BS_BitmapResource *>(pResource);
|
||||
}
|
||||
|
||||
// Framebufferobjekt holen.
|
||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||
BS_ASSERT(GfxPtr);
|
||||
|
||||
bool Result = true;
|
||||
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
||||
for (; Iter != m_Lines.end(); ++Iter)
|
||||
{
|
||||
for (; Iter != m_Lines.end(); ++Iter) {
|
||||
// Feststellen, ob überhaupt Buchstaben der aktuellen Zeile vom Update betroffen sind.
|
||||
BS_Rect CheckRect = (*Iter).BBox;
|
||||
CheckRect.Move(m_AbsoluteX, m_AbsoluteY);
|
||||
|
@ -202,8 +182,7 @@ bool BS_Text::DoRender()
|
|||
// Jeden Buchstaben einzeln Rendern.
|
||||
int CurX = m_AbsoluteX + (*Iter).BBox.left;
|
||||
int CurY = m_AbsoluteY + (*Iter).BBox.top;
|
||||
for (unsigned int i = 0; i < (*Iter).Text.size(); ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < (*Iter).Text.size(); ++i) {
|
||||
BS_Rect CurRect = FontPtr->GetCharacterRect((unsigned char)(*Iter).Text.at(i));
|
||||
|
||||
BS_Rect RenderRect(CurX, CurY, CurX + CurRect.GetWidth(), CurY + CurRect.GetHeight());
|
||||
|
@ -213,7 +192,7 @@ bool BS_Text::DoRender()
|
|||
Result = CharMapPtr->Blit(RenderX, RenderY, BS_Image::FLIP_NONE, &RenderRect, m_ModulationColor);
|
||||
if (!Result) break;
|
||||
|
||||
CurX += CurRect.GetWidth() + FontPtr->GetGapWidth();
|
||||
CurX += CurRect.GetWidth() + FontPtr->GetGapWidth();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,34 +207,30 @@ bool BS_Text::DoRender()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_ResourceManager * BS_Text::GetResourceManager()
|
||||
{
|
||||
BS_ResourceManager *BS_Text::GetResourceManager() {
|
||||
// Pointer auf den Resource-Manager holen.
|
||||
return BS_Kernel::GetInstance()->GetResourceManager();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_FontResource * BS_Text::LockFontResource()
|
||||
{
|
||||
BS_ResourceManager * RMPtr = GetResourceManager();
|
||||
BS_FontResource *BS_Text::LockFontResource() {
|
||||
BS_ResourceManager *RMPtr = GetResourceManager();
|
||||
|
||||
// Font-Resource locken.
|
||||
BS_FontResource * FontPtr;
|
||||
BS_FontResource *FontPtr;
|
||||
{
|
||||
BS_Resource * ResourcePtr = RMPtr->RequestResource(m_Font);
|
||||
if (!ResourcePtr)
|
||||
{
|
||||
BS_Resource *ResourcePtr = RMPtr->RequestResource(m_Font);
|
||||
if (!ResourcePtr) {
|
||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", m_Font.c_str());
|
||||
return NULL;
|
||||
}
|
||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_FONT)
|
||||
{
|
||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_FONT) {
|
||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a font.", m_Font.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FontPtr = static_cast<BS_FontResource*>(ResourcePtr);
|
||||
FontPtr = static_cast<BS_FontResource *>(ResourcePtr);
|
||||
}
|
||||
|
||||
return FontPtr;
|
||||
|
@ -263,16 +238,14 @@ BS_FontResource * BS_Text::LockFontResource()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::UpdateFormat()
|
||||
{
|
||||
BS_FontResource * FontPtr = LockFontResource();
|
||||
void BS_Text::UpdateFormat() {
|
||||
BS_FontResource *FontPtr = LockFontResource();
|
||||
BS_ASSERT(FontPtr);
|
||||
|
||||
UpdateMetrics(*FontPtr);
|
||||
|
||||
m_Lines.resize(1);
|
||||
if (m_AutoWrap && (unsigned int) m_Width >= m_AutoWrapThreshold && m_Text.size() >= 2)
|
||||
{
|
||||
if (m_AutoWrap && (unsigned int) m_Width >= m_AutoWrapThreshold && m_Text.size() >= 2) {
|
||||
m_Width = 0;
|
||||
unsigned int CurLineWidth = 0;
|
||||
unsigned int CurLineHeight = 0;
|
||||
|
@ -280,19 +253,17 @@ void BS_Text::UpdateFormat()
|
|||
unsigned int TempLineWidth = 0;
|
||||
unsigned int LastSpace = 0; // we need at least 1 space character to start a new line...
|
||||
m_Lines[0].Text = "";
|
||||
for (unsigned int i = 0; i < m_Text.size(); ++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_Text.size(); ++i) {
|
||||
unsigned int j;
|
||||
TempLineWidth = 0;
|
||||
LastSpace = 0;
|
||||
for (j = i; j < m_Text.size(); ++j)
|
||||
{
|
||||
for (j = i; j < m_Text.size(); ++j) {
|
||||
if ((unsigned char)m_Text[j] == ' ') LastSpace = j;
|
||||
|
||||
const BS_Rect & CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||
const BS_Rect &CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||
TempLineWidth += CurCharRect.GetWidth();
|
||||
TempLineWidth += FontPtr->GetGapWidth();
|
||||
|
||||
|
||||
if ((TempLineWidth >= m_AutoWrapThreshold) && (LastSpace > 0))
|
||||
break;
|
||||
}
|
||||
|
@ -301,46 +272,41 @@ void BS_Text::UpdateFormat()
|
|||
|
||||
CurLineWidth = 0;
|
||||
CurLineHeight = 0;
|
||||
for (j = i; j < LastSpace; ++j)
|
||||
{
|
||||
for (j = i; j < LastSpace; ++j) {
|
||||
m_Lines[CurLine].Text += m_Text[j];
|
||||
|
||||
const BS_Rect & CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||
const BS_Rect &CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||
CurLineWidth += CurCharRect.GetWidth();
|
||||
CurLineWidth += FontPtr->GetGapWidth();
|
||||
if ((unsigned int) CurCharRect.GetHeight() > CurLineHeight) CurLineHeight = CurCharRect.GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
m_Lines[CurLine].BBox.right = CurLineWidth;
|
||||
m_Lines[CurLine].BBox.bottom = CurLineHeight;
|
||||
if ((unsigned int) m_Width < CurLineWidth) m_Width = CurLineWidth;
|
||||
|
||||
if(LastSpace < m_Text.size())
|
||||
{
|
||||
|
||||
if (LastSpace < m_Text.size()) {
|
||||
++CurLine;
|
||||
BS_ASSERT(CurLine == m_Lines.size());
|
||||
m_Lines.resize(CurLine + 1);
|
||||
m_Lines[CurLine].Text = "";
|
||||
}
|
||||
|
||||
m_Lines[CurLine].Text = "";
|
||||
}
|
||||
|
||||
i = LastSpace;
|
||||
}
|
||||
|
||||
// Bounding-Box der einzelnen Zeilen relativ zur ersten festlegen (vor allem zentrieren).
|
||||
m_Height = 0;
|
||||
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
||||
for (; Iter != m_Lines.end(); ++Iter)
|
||||
{
|
||||
BS_Rect & BBox = (*Iter).BBox;
|
||||
for (; Iter != m_Lines.end(); ++Iter) {
|
||||
BS_Rect &BBox = (*Iter).BBox;
|
||||
BBox.left = (m_Width - BBox.right) / 2;
|
||||
BBox.right = BBox.left + BBox.right;
|
||||
BBox.top = (Iter - m_Lines.begin()) * FontPtr->GetLineHeight();
|
||||
BBox.top = (Iter - m_Lines.begin()) * FontPtr->GetLineHeight();
|
||||
BBox.bottom = BBox.top + BBox.bottom;
|
||||
m_Height += BBox.GetHeight();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Keine automatische Formatierung, also wird der gesamte Text in nur eine Zeile kopiert.
|
||||
m_Lines[0].Text = m_Text;
|
||||
m_Lines[0].BBox = BS_Rect(0, 0, m_Width, m_Height);
|
||||
|
@ -351,14 +317,12 @@ void BS_Text::UpdateFormat()
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_Text::UpdateMetrics(BS_FontResource & FontResource)
|
||||
{
|
||||
void BS_Text::UpdateMetrics(BS_FontResource &FontResource) {
|
||||
m_Width = 0;
|
||||
m_Height = 0;
|
||||
|
||||
for (unsigned int i = 0; i < m_Text.size(); ++i)
|
||||
{
|
||||
const BS_Rect & CurRect = FontResource.GetCharacterRect((unsigned char)m_Text.at(i));
|
||||
for (unsigned int i = 0; i < m_Text.size(); ++i) {
|
||||
const BS_Rect &CurRect = FontResource.GetCharacterRect((unsigned char)m_Text.at(i));
|
||||
m_Width += CurRect.GetWidth();
|
||||
if (i != m_Text.size() - 1) m_Width += FontResource.GetGapWidth();
|
||||
if (m_Height < CurRect.GetHeight()) m_Height = CurRect.GetHeight();
|
||||
|
@ -369,8 +333,7 @@ void BS_Text::UpdateMetrics(BS_FontResource & FontResource)
|
|||
// Persistenz
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Text::Persist(BS_OutputPersistenceBlock & Writer)
|
||||
{
|
||||
bool BS_Text::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Persist(Writer);
|
||||
|
@ -386,8 +349,7 @@ bool BS_Text::Persist(BS_OutputPersistenceBlock & Writer)
|
|||
return Result;
|
||||
}
|
||||
|
||||
bool BS_Text::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||
{
|
||||
bool BS_Text::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||
bool Result = true;
|
||||
|
||||
Result &= BS_RenderObject::Unpersist(Reader);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -61,113 +61,123 @@ class BS_ResourceManager;
|
|||
// Klassendefinition
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class BS_Text : public BS_RenderObject
|
||||
{
|
||||
friend class BS_RenderObject;
|
||||
class BS_Text : public BS_RenderObject {
|
||||
friend class BS_RenderObject;
|
||||
|
||||
public:
|
||||
/**
|
||||
@brief Setzt den Font mit dem der Text dargestellt werden soll.
|
||||
@param Font der Dateiname der Fontdatei.
|
||||
@return Gibt false zurück, wenn der Font nicht gefunden wurde.
|
||||
@brief Setzt den Font mit dem der Text dargestellt werden soll.
|
||||
@param Font der Dateiname der Fontdatei.
|
||||
@return Gibt false zurück, wenn der Font nicht gefunden wurde.
|
||||
*/
|
||||
bool SetFont(const Common::String & Font);
|
||||
bool SetFont(const Common::String &Font);
|
||||
|
||||
/**
|
||||
@brief Setzt den darzustellenden Text.
|
||||
@param Text der darzustellende Text
|
||||
@brief Setzt den darzustellenden Text.
|
||||
@param Text der darzustellende Text
|
||||
*/
|
||||
void SetText(const Common::String & Text);
|
||||
void SetText(const Common::String &Text);
|
||||
|
||||
/**
|
||||
@brief Setzt den Alphawert des Textes.
|
||||
@param Alpha der neue Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
||||
@brief Setzt den Alphawert des Textes.
|
||||
@param Alpha der neue Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
||||
*/
|
||||
void SetAlpha(int Alpha);
|
||||
|
||||
/**
|
||||
@brief Legt fest, ob der Text automatisch umgebrochen werden soll.
|
||||
@brief Legt fest, ob der Text automatisch umgebrochen werden soll.
|
||||
|
||||
Wenn dieses Attribut auf true gesetzt ist, wird der Text umgebrochen, sofern er länger als GetAutoWrapThreshold() ist.
|
||||
Wenn dieses Attribut auf true gesetzt ist, wird der Text umgebrochen, sofern er länger als GetAutoWrapThreshold() ist.
|
||||
|
||||
@param AutoWrap gibt an, ob der automatische Umbruch aktiviert oder deaktiviert werden soll.
|
||||
@remark Dieses Attribut wird mit dem Wert false initialisiert.
|
||||
@param AutoWrap gibt an, ob der automatische Umbruch aktiviert oder deaktiviert werden soll.
|
||||
@remark Dieses Attribut wird mit dem Wert false initialisiert.
|
||||
*/
|
||||
void SetAutoWrap(bool AutoWrap);
|
||||
|
||||
/**
|
||||
@brief Legt die Längengrenze des Textes in Pixeln fest, ab der ein automatischer Zeilenumbruch vorgenommen wird.
|
||||
@remark Dieses Attribut wird mit dem Wert 300 initialisiert.
|
||||
@remark Eine automatische Formatierung wird nur vorgenommen, wenn diese durch einen Aufruf von SetAutoWrap() aktiviert wurde.
|
||||
@brief Legt die Längengrenze des Textes in Pixeln fest, ab der ein automatischer Zeilenumbruch vorgenommen wird.
|
||||
@remark Dieses Attribut wird mit dem Wert 300 initialisiert.
|
||||
@remark Eine automatische Formatierung wird nur vorgenommen, wenn diese durch einen Aufruf von SetAutoWrap() aktiviert wurde.
|
||||
*/
|
||||
void SetAutoWrapThreshold(unsigned int AutoWrapThreshold);
|
||||
|
||||
/**
|
||||
@brief Gibt den dargestellten Text zurück.
|
||||
@brief Gibt den dargestellten Text zurück.
|
||||
*/
|
||||
const Common::String & GetText() { return m_Text; }
|
||||
const Common::String &GetText() {
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt den Namen das momentan benutzten Fonts zurück.
|
||||
*/
|
||||
const Common::String & GetFont() { return m_Font; }
|
||||
const Common::String &GetFont() {
|
||||
return m_Font;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Setzt die Farbe des Textes.
|
||||
@param Color eine 24-Bit RGB Farbe, die die Farbe des Textes festlegt.
|
||||
@brief Setzt die Farbe des Textes.
|
||||
@param Color eine 24-Bit RGB Farbe, die die Farbe des Textes festlegt.
|
||||
*/
|
||||
void SetColor(unsigned int ModulationColor);
|
||||
|
||||
/**
|
||||
@brief Gibt den Alphawert des Textes zurück.
|
||||
@return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
||||
@brief Gibt den Alphawert des Textes zurück.
|
||||
@return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
||||
*/
|
||||
int GetAlpha() const { return m_ModulationColor >> 24; }
|
||||
int GetAlpha() const {
|
||||
return m_ModulationColor >> 24;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die Farbe des Textes zurück.
|
||||
@return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
|
||||
@brief Gibt die Farbe des Textes zurück.
|
||||
@return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
|
||||
*/
|
||||
int GetColor() const { return m_ModulationColor & 0x00ffffff; }
|
||||
int GetColor() const {
|
||||
return m_ModulationColor & 0x00ffffff;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt zurück, ob die automatische Formatierung aktiviert ist.
|
||||
@brief Gibt zurück, ob die automatische Formatierung aktiviert ist.
|
||||
*/
|
||||
bool IsAutoWrapActive() const { return m_AutoWrap; }
|
||||
bool IsAutoWrapActive() const {
|
||||
return m_AutoWrap;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gibt die Längengrenze des Textes in Pixeln zurück, ab der eine automatische Formatierung vorgenommen wird.
|
||||
@brief Gibt die Längengrenze des Textes in Pixeln zurück, ab der eine automatische Formatierung vorgenommen wird.
|
||||
*/
|
||||
unsigned int GetAutoWrapThreshold() const { return m_AutoWrapThreshold; }
|
||||
unsigned int GetAutoWrapThreshold() const {
|
||||
return m_AutoWrapThreshold;
|
||||
}
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||
|
||||
protected:
|
||||
virtual bool DoRender();
|
||||
|
||||
private:
|
||||
BS_Text(BS_RenderObjectPtr<BS_RenderObject> ParentPtr);
|
||||
BS_Text(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
BS_Text(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||
|
||||
unsigned int m_ModulationColor;
|
||||
Common::String m_Font;
|
||||
Common::String m_Text;
|
||||
bool m_AutoWrap;
|
||||
unsigned int m_AutoWrapThreshold;
|
||||
unsigned int m_ModulationColor;
|
||||
Common::String m_Font;
|
||||
Common::String m_Text;
|
||||
bool m_AutoWrap;
|
||||
unsigned int m_AutoWrapThreshold;
|
||||
|
||||
struct LINE
|
||||
{
|
||||
BS_Rect BBox;
|
||||
Common::String Text;
|
||||
struct LINE {
|
||||
BS_Rect BBox;
|
||||
Common::String Text;
|
||||
};
|
||||
|
||||
Common::Array<LINE> m_Lines;
|
||||
Common::Array<LINE> m_Lines;
|
||||
|
||||
void UpdateFormat();
|
||||
void UpdateMetrics(BS_FontResource & FontResource);
|
||||
BS_ResourceManager * GetResourceManager();
|
||||
BS_FontResource * LockFontResource();
|
||||
void UpdateMetrics(BS_FontResource &FontResource);
|
||||
BS_ResourceManager *GetResourceManager();
|
||||
BS_FontResource *LockFontResource();
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -43,14 +43,12 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_TimedRenderObject::BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle) :
|
||||
BS_RenderObject(pParent, Type, Handle)
|
||||
{
|
||||
BS_RenderObject(pParent, Type, Handle) {
|
||||
BS_ASSERT(GetManager());
|
||||
GetManager()->AttatchTimedRenderObject(this);
|
||||
}
|
||||
|
||||
BS_TimedRenderObject::~BS_TimedRenderObject()
|
||||
{
|
||||
BS_TimedRenderObject::~BS_TimedRenderObject() {
|
||||
BS_ASSERT(GetManager());
|
||||
GetManager()->DetatchTimedRenderObject(this);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,21 +54,20 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@brief
|
||||
@brief
|
||||
*/
|
||||
|
||||
class BS_TimedRenderObject : public BS_RenderObject
|
||||
{
|
||||
class BS_TimedRenderObject : public BS_RenderObject {
|
||||
public:
|
||||
BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle = 0);
|
||||
~BS_TimedRenderObject();
|
||||
|
||||
/**
|
||||
@brief Teilt dem Objekt mit, dass ein neuer Frame begonnen wird.
|
||||
@brief Teilt dem Objekt mit, dass ein neuer Frame begonnen wird.
|
||||
|
||||
Diese Methode wird jeden Frame an jedem BS_TimedRenderObject aufgerufen um diesen zu ermöglichen
|
||||
ihren Zustand Zeitabhängig zu verändern (z.B. Animationen).<br>
|
||||
@param int TimeElapsed gibt an wie viel Zeit (in Microsekunden) seit dem letzten Frame vergangen ist.
|
||||
Diese Methode wird jeden Frame an jedem BS_TimedRenderObject aufgerufen um diesen zu ermöglichen
|
||||
ihren Zustand Zeitabhängig zu verändern (z.B. Animationen).<br>
|
||||
@param int TimeElapsed gibt an wie viel Zeit (in Microsekunden) seit dem letzten Frame vergangen ist.
|
||||
*/
|
||||
virtual void FrameNotification(int TimeElapsed) = 0;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -57,15 +57,15 @@ namespace Sword25 {
|
|||
|
||||
class BS_InputEngine : public BS_Service, public BS_Persistable {
|
||||
public:
|
||||
BS_InputEngine(BS_Kernel* pKernel);
|
||||
virtual ~BS_InputEngine(){};
|
||||
BS_InputEngine(BS_Kernel *pKernel);
|
||||
virtual ~BS_InputEngine() {};
|
||||
|
||||
// NOTE: These codes are registered in inputengine_script.cpp
|
||||
// Any changes to these enums must also adjust the above file.
|
||||
enum KEY_CODES {
|
||||
KEY_BACKSPACE = 0x08,
|
||||
KEY_TAB = 0x09,
|
||||
KEY_CLEAR = 0x0C,
|
||||
enum KEY_CODES {
|
||||
KEY_BACKSPACE = 0x08,
|
||||
KEY_TAB = 0x09,
|
||||
KEY_CLEAR = 0x0C,
|
||||
KEY_RETURN = 0x0D,
|
||||
KEY_PAUSE = 0x13,
|
||||
KEY_CAPSLOCK = 0x14,
|
||||
|
@ -79,45 +79,45 @@ public:
|
|||
KEY_UP = 0x26,
|
||||
KEY_RIGHT = 0x27,
|
||||
KEY_DOWN = 0x28,
|
||||
KEY_PRINTSCREEN = 0x2C,
|
||||
KEY_PRINTSCREEN = 0x2C,
|
||||
KEY_INSERT = 0x2D,
|
||||
KEY_DELETE = 0x2E,
|
||||
KEY_0 = 0x30,
|
||||
KEY_1 = 0x31,
|
||||
KEY_2 = 0x32,
|
||||
KEY_3 = 0x33,
|
||||
KEY_4 = 0x34,
|
||||
KEY_5 = 0x35,
|
||||
KEY_6 = 0x36,
|
||||
KEY_7 = 0x37,
|
||||
KEY_8 = 0x38,
|
||||
KEY_9 = 0x39,
|
||||
KEY_A = 0x41,
|
||||
KEY_B = 0x42,
|
||||
KEY_C = 0x43,
|
||||
KEY_D = 0x44,
|
||||
KEY_E = 0x45,
|
||||
KEY_F = 0x46,
|
||||
KEY_G = 0x47,
|
||||
KEY_H = 0x48,
|
||||
KEY_I = 0x49,
|
||||
KEY_J = 0x4A,
|
||||
KEY_K = 0x4B,
|
||||
KEY_L = 0x4C,
|
||||
KEY_M = 0x4D,
|
||||
KEY_N = 0x4E,
|
||||
KEY_O = 0x4F,
|
||||
KEY_P = 0x50,
|
||||
KEY_Q = 0x51,
|
||||
KEY_R = 0x52,
|
||||
KEY_S = 0x53,
|
||||
KEY_T = 0x54,
|
||||
KEY_U = 0x55,
|
||||
KEY_V = 0x56,
|
||||
KEY_W = 0x57,
|
||||
KEY_X = 0x58,
|
||||
KEY_Y = 0x59,
|
||||
KEY_Z = 0x5A,
|
||||
KEY_0 = 0x30,
|
||||
KEY_1 = 0x31,
|
||||
KEY_2 = 0x32,
|
||||
KEY_3 = 0x33,
|
||||
KEY_4 = 0x34,
|
||||
KEY_5 = 0x35,
|
||||
KEY_6 = 0x36,
|
||||
KEY_7 = 0x37,
|
||||
KEY_8 = 0x38,
|
||||
KEY_9 = 0x39,
|
||||
KEY_A = 0x41,
|
||||
KEY_B = 0x42,
|
||||
KEY_C = 0x43,
|
||||
KEY_D = 0x44,
|
||||
KEY_E = 0x45,
|
||||
KEY_F = 0x46,
|
||||
KEY_G = 0x47,
|
||||
KEY_H = 0x48,
|
||||
KEY_I = 0x49,
|
||||
KEY_J = 0x4A,
|
||||
KEY_K = 0x4B,
|
||||
KEY_L = 0x4C,
|
||||
KEY_M = 0x4D,
|
||||
KEY_N = 0x4E,
|
||||
KEY_O = 0x4F,
|
||||
KEY_P = 0x50,
|
||||
KEY_Q = 0x51,
|
||||
KEY_R = 0x52,
|
||||
KEY_S = 0x53,
|
||||
KEY_T = 0x54,
|
||||
KEY_U = 0x55,
|
||||
KEY_V = 0x56,
|
||||
KEY_W = 0x57,
|
||||
KEY_X = 0x58,
|
||||
KEY_Y = 0x59,
|
||||
KEY_Z = 0x5A,
|
||||
KEY_NUMPAD0 = 0x60,
|
||||
KEY_NUMPAD1 = 0x61,
|
||||
KEY_NUMPAD2 = 0x62,
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
KEY_RCONTROL = 0xA3
|
||||
};
|
||||
|
||||
// NOTE: These codes are registered in inputengine_script.cpp.
|
||||
// NOTE: These codes are registered in inputengine_script.cpp.
|
||||
// Any changes to these enums must also adjust the above file.
|
||||
enum KEY_COMMANDS {
|
||||
KEY_COMMAND_ENTER = 1,
|
||||
|
@ -171,16 +171,16 @@ public:
|
|||
/// --------------------------------------------------------------
|
||||
/// THESE METHODS MUST BE IMPLEMENTED BY THE INPUT ENGINE
|
||||
/// --------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Initialises the input engine
|
||||
* @return Returns a true on success, otherwise false.
|
||||
* @return Returns a true on success, otherwise false.
|
||||
*/
|
||||
virtual bool Init() = 0;
|
||||
|
||||
/**
|
||||
* Performs a "tick" of the input engine.
|
||||
*
|
||||
*
|
||||
* This method should be called once per frame. It can be used by implementations
|
||||
* of the input engine that are not running in their own thread, or to perform
|
||||
* additional administrative tasks that are needed.
|
||||
|
@ -240,8 +240,8 @@ public:
|
|||
|
||||
/**
|
||||
* Returns true if a given key was pressed
|
||||
* @param KeyCode The key code to be checked
|
||||
* @return Returns true if the given key is done, otherwise false.
|
||||
* @param KeyCode The key code to be checked
|
||||
* @return Returns true if the given key is done, otherwise false.
|
||||
*/
|
||||
virtual bool IsKeyDown(unsigned int KeyCode) = 0;
|
||||
|
||||
|
@ -251,7 +251,7 @@ public:
|
|||
* The difference between IsKeyDown() is that this only returns true after the key
|
||||
* has been released. This method facilitates the retrieval of keys, and reading
|
||||
* strings that users type.
|
||||
* @param KeyCode The key code to be checked
|
||||
* @param KeyCode The key code to be checked
|
||||
*/
|
||||
virtual bool WasKeyDown(unsigned int KeyCode) = 0;
|
||||
|
||||
|
@ -261,19 +261,19 @@ public:
|
|||
* Registers a callback function for keyboard input.
|
||||
*
|
||||
* The callbacks that are registered with this function will be called whenever an
|
||||
* input key is pressed. A letter entry is different from the query using the
|
||||
* methods IsKeyDown () and WasKeyDown () in the sense that are treated instead
|
||||
* of actual scan-coded letters. These were taken into account, among other things:
|
||||
* input key is pressed. A letter entry is different from the query using the
|
||||
* methods IsKeyDown () and WasKeyDown () in the sense that are treated instead
|
||||
* of actual scan-coded letters. These were taken into account, among other things:
|
||||
* the keyboard layout, the condition the Shift and Caps Lock keys and the repetition
|
||||
* of longer holding the key.
|
||||
* The input of strings by the user through use of callbacks should be implemented.
|
||||
* @return Returns true if the function was registered, otherwise false.
|
||||
* @return Returns true if the function was registered, otherwise false.
|
||||
*/
|
||||
virtual bool RegisterCharacterCallback(CallbackPtr Callback) = 0;
|
||||
|
||||
/**
|
||||
* De-registeres a previously registered callback function.
|
||||
* @return Returns true if the function could be de-registered, otherwise false.
|
||||
* @return Returns true if the function could be de-registered, otherwise false.
|
||||
*/
|
||||
virtual bool UnregisterCharacterCallback(CallbackPtr Callback) = 0;
|
||||
|
||||
|
@ -282,17 +282,17 @@ public:
|
|||
/**
|
||||
* Registers a callback function for the input of commands that can have influence on the string input
|
||||
*
|
||||
* The callbacks that are registered with this function will be called whenever the input service
|
||||
* has a key that affects the character string input. This could be the following keys:
|
||||
* The callbacks that are registered with this function will be called whenever the input service
|
||||
* has a key that affects the character string input. This could be the following keys:
|
||||
* Enter, End, Left, Right, ...
|
||||
* The input of strings by the user through the use of callbacks should be implemented.
|
||||
* @return Returns true if the function was registered, otherwise false.
|
||||
* @return Returns true if the function was registered, otherwise false.
|
||||
*/
|
||||
virtual bool RegisterCommandCallback(CallbackPtr Callback) = 0;
|
||||
|
||||
/**
|
||||
* Un-register a callback function for the input of commands that can have an influence on the string input.
|
||||
* @return Returns true if the function could be de-registered, otherwise false.
|
||||
* @return Returns true if the function could be de-registered, otherwise false.
|
||||
*/
|
||||
virtual bool UnregisterCommandCallback(CommandCallback Callback) = 0;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -61,45 +61,47 @@ static void TheCharacterCallback(int Character);
|
|||
static void TheCommandCallback(int Command);
|
||||
|
||||
namespace {
|
||||
class CharacterCallbackClass : public BS_LuaCallback {
|
||||
public:
|
||||
CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {};
|
||||
class CharacterCallbackClass : public BS_LuaCallback {
|
||||
public:
|
||||
CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {};
|
||||
|
||||
Common::String Character;
|
||||
Common::String Character;
|
||||
|
||||
protected:
|
||||
int PreFunctionInvokation(lua_State *L) {
|
||||
lua_pushstring(L, Character.c_str());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr;
|
||||
protected:
|
||||
int PreFunctionInvokation(lua_State *L) {
|
||||
lua_pushstring(L, Character.c_str());
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class CommandCallbackClass : public BS_LuaCallback {
|
||||
public:
|
||||
CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) { Command = BS_InputEngine::KEY_COMMAND_BACKSPACE; }
|
||||
class CommandCallbackClass : public BS_LuaCallback {
|
||||
public:
|
||||
CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) {
|
||||
Command = BS_InputEngine::KEY_COMMAND_BACKSPACE;
|
||||
}
|
||||
|
||||
BS_InputEngine::KEY_COMMANDS Command;
|
||||
BS_InputEngine::KEY_COMMANDS Command;
|
||||
|
||||
protected:
|
||||
int PreFunctionInvokation(lua_State *L) {
|
||||
lua_pushnumber(L, Command);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr;
|
||||
protected:
|
||||
int PreFunctionInvokation(lua_State *L) {
|
||||
lua_pushnumber(L, Command);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
struct CallbackfunctionRegisterer {
|
||||
CallbackfunctionRegisterer() {
|
||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback);
|
||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback);
|
||||
}
|
||||
};
|
||||
static CallbackfunctionRegisterer Instance;
|
||||
struct CallbackfunctionRegisterer {
|
||||
CallbackfunctionRegisterer() {
|
||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback);
|
||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback);
|
||||
}
|
||||
};
|
||||
static CallbackfunctionRegisterer Instance;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -313,7 +315,7 @@ static const luaL_reg PACKAGE_FUNCTIONS[] = {
|
|||
"UnregisterCharacterCallback", UnregisterCharacterCallback,
|
||||
"RegisterCommandCallback", RegisterCommandCallback,
|
||||
"UnregisterCommandCallback", UnregisterCommandCallback,
|
||||
0, 0,
|
||||
0, 0,
|
||||
};
|
||||
|
||||
#define X(k) "KEY_" #k, BS_InputEngine::KEY_##k
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,19 +54,19 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
ScummVMInput::ScummVMInput(BS_Kernel *pKernel) :
|
||||
m_CurrentState(0),
|
||||
m_LeftMouseDown(false),
|
||||
m_RightMouseDown(false),
|
||||
m_MouseX(0),
|
||||
m_MouseY(0),
|
||||
m_LeftDoubleClick(false),
|
||||
m_DoubleClickTime(DOUBLE_CLICK_TIME),
|
||||
m_DoubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE),
|
||||
m_DoubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE),
|
||||
m_LastLeftClickTime(0),
|
||||
m_LastLeftClickMouseX(0),
|
||||
m_LastLeftClickMouseY(0),
|
||||
BS_InputEngine(pKernel) {
|
||||
m_CurrentState(0),
|
||||
m_LeftMouseDown(false),
|
||||
m_RightMouseDown(false),
|
||||
m_MouseX(0),
|
||||
m_MouseY(0),
|
||||
m_LeftDoubleClick(false),
|
||||
m_DoubleClickTime(DOUBLE_CLICK_TIME),
|
||||
m_DoubleClickRectWidth(DOUBLE_CLICK_RECT_SIZE),
|
||||
m_DoubleClickRectHeight(DOUBLE_CLICK_RECT_SIZE),
|
||||
m_LastLeftClickTime(0),
|
||||
m_LastLeftClickMouseX(0),
|
||||
m_LastLeftClickMouseY(0),
|
||||
BS_InputEngine(pKernel) {
|
||||
memset(m_KeyboardState[0], 0, sizeof(m_KeyboardState[0]));
|
||||
memset(m_KeyboardState[1], 0, sizeof(m_KeyboardState[1]));
|
||||
m_LeftMouseState[0] = false;
|
||||
|
@ -80,7 +80,9 @@ ScummVMInput::~ScummVMInput() {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { return new ScummVMInput(pKernel); }
|
||||
BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) {
|
||||
return new ScummVMInput(pKernel);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -102,18 +104,21 @@ void ScummVMInput::Update() {
|
|||
case Common::EVENT_LBUTTONDOWN:
|
||||
case Common::EVENT_LBUTTONUP:
|
||||
m_LeftMouseDown = event.type == Common::EVENT_LBUTTONDOWN;
|
||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
||||
m_MouseX = event.mouse.x;
|
||||
m_MouseY = event.mouse.y;
|
||||
handleEvents = false;
|
||||
break;
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
m_RightMouseDown = event.type == Common::EVENT_RBUTTONDOWN;
|
||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
||||
m_MouseX = event.mouse.x;
|
||||
m_MouseY = event.mouse.y;
|
||||
handleEvents = false;
|
||||
break;
|
||||
|
||||
case Common::EVENT_MOUSEMOVE:
|
||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
||||
m_MouseX = event.mouse.x;
|
||||
m_MouseY = event.mouse.y;
|
||||
break;
|
||||
|
||||
case Common::EVENT_KEYDOWN:
|
||||
|
@ -162,8 +167,8 @@ void ScummVMInput::TestForLeftDoubleClick() {
|
|||
// 1. The two clicks are close enough together
|
||||
// 2. The mouse cursor hasn't moved much
|
||||
if (Now - m_LastLeftClickTime <= m_DoubleClickTime &&
|
||||
ABS(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 &&
|
||||
ABS(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) {
|
||||
ABS(m_MouseX - m_LastLeftClickMouseX) <= m_DoubleClickRectWidth / 2 &&
|
||||
ABS(m_MouseY - m_LastLeftClickMouseY) <= m_DoubleClickRectHeight / 2) {
|
||||
m_LeftDoubleClick = true;
|
||||
|
||||
// Reset the time and position of the last click, so that clicking is not
|
||||
|
@ -184,7 +189,7 @@ void ScummVMInput::TestForLeftDoubleClick() {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AlterKeyboardState(int keycode, byte newState) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -208,7 +213,7 @@ bool ScummVMInput::WasRightMouseDown() {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ScummVMInput::GetMouseX() {
|
||||
return m_MouseX;
|
||||
return m_MouseX;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -226,8 +231,8 @@ bool ScummVMInput::IsKeyDown(unsigned int KeyCode) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool ScummVMInput::WasKeyDown(unsigned int KeyCode) {
|
||||
return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) &&
|
||||
((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0);
|
||||
return ((m_KeyboardState[m_CurrentState][KeyCode] & 0x80) == 0) &&
|
||||
((m_KeyboardState[m_CurrentState ^ 1][KeyCode] & 0x80) != 0);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -259,8 +264,8 @@ bool ScummVMInput::RegisterCharacterCallback(CharacterCallback Callback) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool ScummVMInput::UnregisterCharacterCallback(CharacterCallback Callback) {
|
||||
Common::List<CharacterCallback>::iterator CallbackIter = Common::find(m_CharacterCallbacks.begin(),
|
||||
m_CharacterCallbacks.end(), Callback);
|
||||
Common::List<CharacterCallback>::iterator CallbackIter = Common::find(m_CharacterCallbacks.begin(),
|
||||
m_CharacterCallbacks.end(), Callback);
|
||||
if (CallbackIter != m_CharacterCallbacks.end()) {
|
||||
m_CharacterCallbacks.erase(CallbackIter);
|
||||
return true;
|
||||
|
@ -285,8 +290,8 @@ bool ScummVMInput::RegisterCommandCallback(CommandCallback Callback) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool ScummVMInput::UnregisterCommandCallback(CommandCallback Callback) {
|
||||
Common::List<CommandCallback>::iterator CallbackIter =
|
||||
Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback);
|
||||
Common::List<CommandCallback>::iterator CallbackIter =
|
||||
Common::find(m_CommandCallbacks.begin(), m_CommandCallbacks.end(), Callback);
|
||||
if (CallbackIter != m_CommandCallbacks.end()) {
|
||||
m_CommandCallbacks.erase(CallbackIter);
|
||||
return true;
|
||||
|
@ -302,7 +307,7 @@ void ScummVMInput::ReportCharacter(unsigned char Character) {
|
|||
Common::List<CharacterCallback>::const_iterator CallbackIter = m_CharacterCallbacks.begin();
|
||||
while (CallbackIter != m_CharacterCallbacks.end()) {
|
||||
// Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten.
|
||||
// Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
|
||||
// Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
|
||||
// invalidiert wird.
|
||||
Common::List<CharacterCallback>::const_iterator CurCallbackIter = CallbackIter;
|
||||
++CallbackIter;
|
||||
|
@ -317,7 +322,7 @@ void ScummVMInput::ReportCommand(KEY_COMMANDS Command) {
|
|||
Common::List<CommandCallback>::const_iterator CallbackIter = m_CommandCallbacks.begin();
|
||||
while (CallbackIter != m_CommandCallbacks.end()) {
|
||||
// Iterator vor dem Aufruf erhöhen und im Folgendem auf einer Kopie arbeiten.
|
||||
// Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
|
||||
// Dieses Vorgehen ist notwendig da der Iterator möglicherweise von der Callbackfunktion durch das Deregistrieren des Callbacks
|
||||
// invalidiert wird.
|
||||
Common::List<CommandCallback>::const_iterator CurCallbackIter = CallbackIter;
|
||||
++CallbackIter;
|
||||
|
@ -374,7 +379,7 @@ bool ScummVMInput::Unpersist(BS_InputPersistenceBlock &Reader) {
|
|||
Reader.Read(CallbackFunctionName);
|
||||
|
||||
m_CommandCallbacks.push_back(reinterpret_cast<CommandCallback>(
|
||||
BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName)));
|
||||
BS_CallbackRegistry::GetInstance().ResolveCallbackFunction(CallbackFunctionName)));
|
||||
}
|
||||
|
||||
// Character-Callbackliste leeren.
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -51,7 +51,7 @@ class ScummVMInput : public BS_InputEngine {
|
|||
public:
|
||||
ScummVMInput(BS_Kernel *pKernel);
|
||||
virtual ~ScummVMInput();
|
||||
|
||||
|
||||
virtual bool Init();
|
||||
virtual void Update();
|
||||
virtual bool IsLeftMouseDown();
|
||||
|
@ -79,23 +79,23 @@ private:
|
|||
void TestForLeftDoubleClick();
|
||||
void AlterKeyboardState(int keycode, byte newState);
|
||||
|
||||
byte m_KeyboardState[2][256];
|
||||
bool m_LeftMouseState[2];
|
||||
bool m_RightMouseState[2];
|
||||
unsigned int m_CurrentState;
|
||||
int m_MouseX;
|
||||
int m_MouseY;
|
||||
bool m_LeftMouseDown;
|
||||
bool m_RightMouseDown;
|
||||
bool m_LeftDoubleClick;
|
||||
unsigned int m_DoubleClickTime;
|
||||
int m_DoubleClickRectWidth;
|
||||
int m_DoubleClickRectHeight;
|
||||
unsigned int m_LastLeftClickTime;
|
||||
int m_LastLeftClickMouseX;
|
||||
int m_LastLeftClickMouseY;
|
||||
Common::List<CommandCallback> m_CommandCallbacks;
|
||||
Common::List<CharacterCallback> m_CharacterCallbacks;
|
||||
byte m_KeyboardState[2][256];
|
||||
bool m_LeftMouseState[2];
|
||||
bool m_RightMouseState[2];
|
||||
unsigned int m_CurrentState;
|
||||
int m_MouseX;
|
||||
int m_MouseY;
|
||||
bool m_LeftMouseDown;
|
||||
bool m_RightMouseDown;
|
||||
bool m_LeftDoubleClick;
|
||||
unsigned int m_DoubleClickTime;
|
||||
int m_DoubleClickRectWidth;
|
||||
int m_DoubleClickRectHeight;
|
||||
unsigned int m_LastLeftClickTime;
|
||||
int m_LastLeftClickMouseX;
|
||||
int m_LastLeftClickMouseY;
|
||||
Common::List<CommandCallback> m_CommandCallbacks;
|
||||
Common::List<CharacterCallback> m_CharacterCallbacks;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -76,7 +76,7 @@ bool BS_CallbackRegistry::RegisterCallbackFunction(const Common::String &Name, C
|
|||
}
|
||||
|
||||
StoreCallbackFunction(Name, Ptr);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -52,28 +52,30 @@ namespace Sword25 {
|
|||
// Klassendeklaration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
typedef void (*CallbackPtr)(int Command);
|
||||
typedef void (*CallbackPtr)(int Command);
|
||||
|
||||
class BS_CallbackRegistry {
|
||||
public:
|
||||
static BS_CallbackRegistry & GetInstance() {
|
||||
static BS_CallbackRegistry &GetInstance() {
|
||||
static BS_CallbackRegistry Instance;
|
||||
return Instance;
|
||||
}
|
||||
|
||||
bool RegisterCallbackFunction(const Common::String &Name, CallbackPtr Ptr);
|
||||
CallbackPtr ResolveCallbackFunction(const Common::String &Name) const;
|
||||
Common::String ResolveCallbackPointer(CallbackPtr Ptr) const;
|
||||
bool RegisterCallbackFunction(const Common::String &Name, CallbackPtr Ptr);
|
||||
CallbackPtr ResolveCallbackFunction(const Common::String &Name) const;
|
||||
Common::String ResolveCallbackPointer(CallbackPtr Ptr) const;
|
||||
|
||||
private:
|
||||
typedef Common::HashMap<Common::String, CallbackPtr, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> NameToPtrMap;
|
||||
NameToPtrMap m_NameToPtrMap;
|
||||
|
||||
struct CallbackPtr_EqualTo {
|
||||
bool operator()(CallbackPtr x, CallbackPtr y) const { return x == y; }
|
||||
bool operator()(CallbackPtr x, CallbackPtr y) const {
|
||||
return x == y;
|
||||
}
|
||||
};
|
||||
struct CallbackPtr_Hash {
|
||||
uint operator()(CallbackPtr x) const {
|
||||
uint operator()(CallbackPtr x) const {
|
||||
return static_cast<uint>((int64)x % ((int64)1 << sizeof(uint)));
|
||||
}
|
||||
};
|
||||
|
@ -81,9 +83,9 @@ private:
|
|||
typedef Common::HashMap<CallbackPtr, Common::String, CallbackPtr_Hash, CallbackPtr_EqualTo> PtrToNameMap;
|
||||
PtrToNameMap m_PtrToNameMap;
|
||||
|
||||
CallbackPtr FindPtrByName(const Common::String &Name) const;
|
||||
Common::String FindNameByPtr(CallbackPtr Ptr) const;
|
||||
void StoreCallbackFunction(const Common::String &Name, CallbackPtr Ptr);
|
||||
CallbackPtr FindPtrByName(const Common::String &Name) const;
|
||||
Common::String FindNameByPtr(CallbackPtr Ptr) const;
|
||||
void StoreCallbackFunction(const Common::String &Name, CallbackPtr Ptr);
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -47,10 +47,10 @@
|
|||
|
||||
// Global constants
|
||||
#if _DEBUG && !DEBUG
|
||||
#define DEBUG
|
||||
#define DEBUG
|
||||
#endif
|
||||
|
||||
#define BS_ACTIVATE_LOGGING // When defined, logging is activated
|
||||
#define BS_ACTIVATE_LOGGING // When defined, logging is activated
|
||||
|
||||
// Engine Includes
|
||||
#include "sword25/kernel/memleaks.h"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
return "";
|
||||
}
|
||||
|
||||
// Return the path
|
||||
// Return the path
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -33,8 +33,8 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* The class BS_FileSystemUtil represents a wrapper for file system specific
|
||||
*
|
||||
* The class BS_FileSystemUtil represents a wrapper for file system specific
|
||||
* operations that do not have equivalents in the C/C++ libraries.
|
||||
*
|
||||
* Each supported platform must implement this interface, and the method
|
||||
|
@ -69,42 +69,42 @@ public:
|
|||
* This function returns the name of the directory in which all user data is to be stored.
|
||||
*
|
||||
* These are for example Screenshots, game saves, configuration files, log files, ...
|
||||
* @return Returns the name of the directory for user data.
|
||||
* @return Returns the name of the directory for user data.
|
||||
*/
|
||||
virtual Common::String GetUserdataDirectory() = 0;
|
||||
/**
|
||||
* @return Returns the path seperator
|
||||
* @return Returns the path seperator
|
||||
*/
|
||||
virtual Common::String GetPathSeparator() = 0;
|
||||
virtual Common::String GetPathSeparator() = 0;
|
||||
/**
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns the size of the specified file. If the size could not be
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns the size of the specified file. If the size could not be
|
||||
* determined, or the file does not exist, returns -1
|
||||
*/
|
||||
virtual int64 GetFileSize(const Common::String &Filename) = 0;
|
||||
/**
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns the timestamp of the specified file.
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns the timestamp of the specified file.
|
||||
*/
|
||||
virtual TimeDate GetFileTime(const Common::String &Filename) = 0;
|
||||
/**
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns true if the file exists.
|
||||
* @param Filename The path to a file.
|
||||
* @return Returns true if the file exists.
|
||||
*/
|
||||
virtual bool FileExists(const Common::String &Filename) = 0;
|
||||
/**
|
||||
* This function creates a directory
|
||||
*
|
||||
*
|
||||
* If the parameter is "\b\c\d\e" is passed, and "\b\c" already exists, then folder 'd'
|
||||
* will be created, and subdirectory 'e' under it.
|
||||
* @param DirectoryName The name of the directory to be created
|
||||
* @return Returns true if the folder(s) could be created, otherwise false.
|
||||
* @param DirectoryName The name of the directory to be created
|
||||
* @return Returns true if the folder(s) could be created, otherwise false.
|
||||
*/
|
||||
virtual bool CreateDirectory(const Common::String &DirectoryName) = 0;
|
||||
/**
|
||||
* Creates a list of filenames in a given directory.
|
||||
* @param Directory The directory to search
|
||||
* @return Returns a vector containing all of the found filenames
|
||||
* @param Directory The directory to search
|
||||
* @return Returns a vector containing all of the found filenames
|
||||
*/
|
||||
virtual Common::StringArray GetFilesInDirectory(const Common::String &Path) = 0;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -46,9 +46,9 @@ namespace Sword25 {
|
|||
// Constructor / Destructor
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void * Data, unsigned int DataLength) :
|
||||
m_Data(static_cast<const unsigned char *>(Data), DataLength),
|
||||
m_ErrorState(NONE) {
|
||||
BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void *Data, unsigned int DataLength) :
|
||||
m_Data(static_cast<const unsigned char *>(Data), DataLength),
|
||||
m_ErrorState(NONE) {
|
||||
m_Iter = m_Data.begin();
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ void BS_InputPersistenceBlock::Read(bool &Value) {
|
|||
|
||||
void BS_InputPersistenceBlock::Read(Common::String &Value) {
|
||||
Value = "";
|
||||
|
||||
|
||||
if (CheckMarker(STRING_MARKER)) {
|
||||
unsigned int Size;
|
||||
Read(Size);
|
||||
|
@ -146,7 +146,7 @@ void BS_InputPersistenceBlock::Read(Common::Array<unsigned char> &Value) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BS_InputPersistenceBlock::RawRead(void * DestPtr, size_t Size) {
|
||||
void BS_InputPersistenceBlock::RawRead(void *DestPtr, size_t Size) {
|
||||
if (CheckBlockSize(Size)) {
|
||||
memcpy(DestPtr, &*m_Iter, Size);
|
||||
m_Iter += Size;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_INPUTPERSISTENCEBLOCK_H
|
||||
#ifndef SWORD25_INPUTPERSISTENCEBLOCK_H
|
||||
#define SWORD25_INPUTPERSISTENCEBLOCK_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -68,8 +68,12 @@ public:
|
|||
void Read(Common::String &Value);
|
||||
void Read(Common::Array<unsigned char> &Value);
|
||||
|
||||
bool IsGood() const { return m_ErrorState == NONE; }
|
||||
ErrorState GetErrorState() const { return m_ErrorState; }
|
||||
bool IsGood() const {
|
||||
return m_ErrorState == NONE;
|
||||
}
|
||||
ErrorState GetErrorState() const {
|
||||
return m_ErrorState;
|
||||
}
|
||||
|
||||
private:
|
||||
bool CheckMarker(unsigned char Marker);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -54,7 +54,7 @@ BS_Kernel::BS_Kernel() :
|
|||
_Running(false),
|
||||
_pResourceManager(NULL),
|
||||
_InitSuccess(false) {
|
||||
|
||||
|
||||
// Log that the kernel is beign created
|
||||
BS_LOGLN("created.");
|
||||
|
||||
|
@ -115,7 +115,7 @@ BS_Kernel::~BS_Kernel() {
|
|||
delete _SuperclassList.back();
|
||||
_SuperclassList.pop_back();
|
||||
}
|
||||
|
||||
|
||||
// Release the window object
|
||||
delete _pWindow;
|
||||
BS_LOGLN("Window destroyed.");
|
||||
|
@ -129,12 +129,11 @@ BS_Kernel::~BS_Kernel() {
|
|||
// Service Methoden
|
||||
// ----------------
|
||||
|
||||
BS_Kernel::Superclass::Superclass (BS_Kernel* pKernel, const Common::String& Identifier) :
|
||||
BS_Kernel::Superclass::Superclass(BS_Kernel *pKernel, const Common::String &Identifier) :
|
||||
_pKernel(pKernel),
|
||||
_Identifier(Identifier),
|
||||
_ServiceCount(0),
|
||||
_ActiveService(NULL)
|
||||
{
|
||||
_Identifier(Identifier),
|
||||
_ServiceCount(0),
|
||||
_ActiveService(NULL) {
|
||||
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
||||
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier)
|
||||
_ServiceCount++;
|
||||
|
@ -147,15 +146,15 @@ BS_Kernel::Superclass::~Superclass() {
|
|||
/**
|
||||
* Gets the identifier of a service with a given superclass.
|
||||
* The number of services in a superclass can be learned with GetServiceCount().
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br>
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
*/
|
||||
Common::String BS_Kernel::Superclass::GetServiceIdentifier(unsigned int Number) {
|
||||
if (Number > _ServiceCount) return NULL;
|
||||
|
||||
|
||||
unsigned int CurServiceOrd = 0;
|
||||
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++) {
|
||||
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier)
|
||||
|
@ -169,31 +168,27 @@ Common::String BS_Kernel::Superclass::GetServiceIdentifier(unsigned int Number)
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* service could not be created
|
||||
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
*/
|
||||
BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdentifier) {
|
||||
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
||||
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier &&
|
||||
BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier)
|
||||
{
|
||||
BS_Service* NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel);
|
||||
|
||||
if (NewService)
|
||||
{
|
||||
BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier) {
|
||||
BS_Service *NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel);
|
||||
|
||||
if (NewService) {
|
||||
DisconnectService();
|
||||
BS_LOGLN("Service '%s' created from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
||||
_ActiveService = NewService;
|
||||
_ActiveServiceName = BS_SERVICE_TABLE[i].ServiceIdentifier;
|
||||
return _ActiveService;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
@ -204,10 +199,10 @@ BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdent
|
|||
}
|
||||
|
||||
/**
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* does not exist or if not service was active
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
bool BS_Kernel::Superclass::DisconnectService() {
|
||||
if (_ActiveService) {
|
||||
|
@ -221,7 +216,7 @@ bool BS_Kernel::Superclass::DisconnectService() {
|
|||
}
|
||||
|
||||
BS_Kernel::Superclass *BS_Kernel::GetSuperclassByIdentifier(const Common::String &Identifier) {
|
||||
Common::Array<Superclass*>::iterator Iter;
|
||||
Common::Array<Superclass *>::iterator Iter;
|
||||
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
||||
if ((*Iter)->GetIdentifier() == Identifier)
|
||||
return *Iter;
|
||||
|
@ -241,32 +236,32 @@ unsigned int BS_Kernel::GetSuperclassCount() {
|
|||
/**
|
||||
* Returns the name of a superclass with the specified index.
|
||||
* Note: The number of superclasses can be retrieved using GetSuperclassCount
|
||||
* @param Number The number of the superclass to return the identifier for.
|
||||
* @param Number The number of the superclass to return the identifier for.
|
||||
* It should be noted that the number should be between 0 und GetSuperclassCount() - 1.
|
||||
*/
|
||||
Common::String BS_Kernel::GetSuperclassIdentifier(unsigned int Number) {
|
||||
if (Number > _SuperclassList.size()) return NULL;
|
||||
|
||||
|
||||
unsigned int CurSuperclassOrd = 0;
|
||||
Common::Array<Superclass*>::iterator Iter;
|
||||
Common::Array<Superclass *>::iterator Iter;
|
||||
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
||||
if (CurSuperclassOrd == Number)
|
||||
return ((*Iter)->GetIdentifier());
|
||||
|
||||
|
||||
CurSuperclassOrd++;
|
||||
}
|
||||
|
||||
|
||||
return Common::String("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of services registered with a given superclass
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentifier) {
|
||||
unsigned int BS_Kernel::GetServiceCount(const Common::String &SuperclassIdentifier) {
|
||||
Superclass *pSuperclass;
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier)))
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier)))
|
||||
return 0;
|
||||
|
||||
return pSuperclass->GetServiceCount();
|
||||
|
@ -276,29 +271,29 @@ unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentif
|
|||
/**
|
||||
* Gets the identifier of a service with a given superclass.
|
||||
* The number of services in a superclass can be learned with GetServiceCount().
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br>
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
*/
|
||||
Common::String BS_Kernel::GetServiceIdentifier(const Common::String & SuperclassIdentifier, unsigned int Number) {
|
||||
Superclass* pSuperclass;
|
||||
Common::String BS_Kernel::GetServiceIdentifier(const Common::String &SuperclassIdentifier, unsigned int Number) {
|
||||
Superclass *pSuperclass;
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||
|
||||
return (pSuperclass->GetServiceIdentifier(Number));
|
||||
return (pSuperclass->GetServiceIdentifier(Number));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* service could not be created
|
||||
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
*/
|
||||
BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, const Common::String& ServiceIdentifier) {
|
||||
BS_Service *BS_Kernel::NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier) {
|
||||
Superclass *pSuperclass;
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||
|
||||
|
@ -309,12 +304,12 @@ BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, co
|
|||
}
|
||||
|
||||
/**
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* does not exist or if not service was active
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) {
|
||||
bool BS_Kernel::DisconnectService(const Common::String &SuperclassIdentifier) {
|
||||
Superclass *pSuperclass;
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return false;
|
||||
|
||||
|
@ -323,10 +318,10 @@ bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) {
|
|||
|
||||
/**
|
||||
* Returns a pointer to the currently active service object of a superclass
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) {
|
||||
BS_Service *BS_Kernel::GetService(const Common::String &SuperclassIdentifier) {
|
||||
Superclass *pSuperclass;
|
||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||
|
||||
|
@ -336,11 +331,11 @@ BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) {
|
|||
/**
|
||||
* Returns the name of the currentl active service object of a superclass.
|
||||
* If an error occurs, then an empty string is returned
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String& SuperclassIdentifier) {
|
||||
Superclass * pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier);
|
||||
Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier) {
|
||||
Superclass *pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier);
|
||||
if (!pSuperclass) return Common::String("");
|
||||
|
||||
return (pSuperclass->GetActiveServiceName());
|
||||
|
@ -350,8 +345,8 @@ Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String& Super
|
|||
|
||||
/**
|
||||
* Returns a random number
|
||||
* @param Min The minimum allowed value
|
||||
* @param Max The maximum allowed value
|
||||
* @param Min The minimum allowed value
|
||||
* @param Max The maximum allowed value
|
||||
*/
|
||||
int BS_Kernel::GetRandomNumber(int Min, int Max) {
|
||||
BS_ASSERT(Min <= Max);
|
||||
|
@ -386,12 +381,9 @@ size_t BS_Kernel::GetUsedMemory() {
|
|||
#ifdef SCUMMVM_DISABLED_CODE
|
||||
PROCESS_MEMORY_COUNTERS pmc;
|
||||
pmc.cb = sizeof(pmc);
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
|
||||
{
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
||||
return pmc.WorkingSetSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BS_LOG_ERRORLN("Call to GetProcessMemoryInfo() failed. Error code: %d", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
@ -403,7 +395,7 @@ size_t BS_Kernel::GetUsedMemory() {
|
|||
/**
|
||||
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active
|
||||
*/
|
||||
BS_GraphicEngine * BS_Kernel::GetGfx() {
|
||||
BS_GraphicEngine *BS_Kernel::GetGfx() {
|
||||
return static_cast<BS_GraphicEngine *>(GetService("gfx"));
|
||||
}
|
||||
|
||||
|
@ -412,7 +404,7 @@ BS_GraphicEngine * BS_Kernel::GetGfx() {
|
|||
/**
|
||||
* Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active
|
||||
*/
|
||||
BS_SoundEngine * BS_Kernel::GetSfx() {
|
||||
BS_SoundEngine *BS_Kernel::GetSfx() {
|
||||
return static_cast<BS_SoundEngine *>(GetService("sfx"));
|
||||
}
|
||||
|
||||
|
@ -421,7 +413,7 @@ BS_SoundEngine * BS_Kernel::GetSfx() {
|
|||
/**
|
||||
* Returns a pointer to the active input service, or NULL if no input service is active
|
||||
*/
|
||||
BS_InputEngine * BS_Kernel::GetInput() {
|
||||
BS_InputEngine *BS_Kernel::GetInput() {
|
||||
return static_cast<BS_InputEngine *>(GetService("input"));
|
||||
}
|
||||
|
||||
|
@ -430,7 +422,7 @@ BS_InputEngine * BS_Kernel::GetInput() {
|
|||
/**
|
||||
* Returns a pointer to the active package manager, or NULL if no manager is active
|
||||
*/
|
||||
BS_PackageManager * BS_Kernel::GetPackage() {
|
||||
BS_PackageManager *BS_Kernel::GetPackage() {
|
||||
return static_cast<BS_PackageManager *>(GetService("package"));
|
||||
}
|
||||
|
||||
|
@ -439,7 +431,7 @@ BS_PackageManager * BS_Kernel::GetPackage() {
|
|||
/**
|
||||
* Returns a pointer to the script engine, or NULL if it is not active
|
||||
*/
|
||||
BS_ScriptEngine * BS_Kernel::GetScript() {
|
||||
BS_ScriptEngine *BS_Kernel::GetScript() {
|
||||
return static_cast<BS_ScriptEngine *>(GetService("script"));
|
||||
}
|
||||
|
||||
|
@ -448,7 +440,7 @@ BS_ScriptEngine * BS_Kernel::GetScript() {
|
|||
/**
|
||||
* Returns a pointer to the movie player, or NULL if it is not active
|
||||
*/
|
||||
BS_MoviePlayer * BS_Kernel::GetFMV() {
|
||||
BS_MoviePlayer *BS_Kernel::GetFMV() {
|
||||
return static_cast<BS_MoviePlayer *>(GetService("fmv"));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -71,7 +71,7 @@ class BS_MoviePlayer;
|
|||
/**
|
||||
* This is the main engine class
|
||||
*
|
||||
* This class creates and manages all other engine components such as sound engine, graphics engine ...
|
||||
* This class creates and manages all other engine components such as sound engine, graphics engine ...
|
||||
* It is not necessary to release all the items individually, this is performed by the Kernel class.
|
||||
*/
|
||||
class BS_Kernel {
|
||||
|
@ -82,42 +82,44 @@ public:
|
|||
/**
|
||||
* Returns a pointer to the window object
|
||||
*/
|
||||
BS_Window *GetWindow() { return _pWindow; }
|
||||
BS_Window *GetWindow() {
|
||||
return _pWindow;
|
||||
}
|
||||
|
||||
// Service Methods
|
||||
// ---------------
|
||||
|
||||
/**
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
||||
* service could not be created
|
||||
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
||||
* @param SuperclassIdentifier The name of the superclass of the service
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param ServiceIdentifier The name of the service
|
||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||
*/
|
||||
BS_Service *NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier);
|
||||
|
||||
/**
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
||||
* does not exist or if not service was active
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
bool DisconnectService(const Common::String &SuperclassIdentifier);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the currently active service object of a superclass
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
BS_Service *GetService(const Common::String &SuperclassIdentifier);
|
||||
|
||||
/**
|
||||
* Returns the name of the currentl active service object of a superclass.
|
||||
* If an error occurs, then an empty string is returned
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentfier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
Common::String GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier);
|
||||
|
||||
|
@ -129,26 +131,26 @@ public:
|
|||
/**
|
||||
* Returns the name of a superclass with the specified index.
|
||||
* Note: The number of superclasses can be retrieved using GetSuperclassCount
|
||||
* @param Number The number of the superclass to return the identifier for.
|
||||
* @param Number The number of the superclass to return the identifier for.
|
||||
* It should be noted that the number should be between 0 und GetSuperclassCount() - 1.
|
||||
*/
|
||||
Common::String GetSuperclassIdentifier(unsigned int Number);
|
||||
|
||||
/**
|
||||
* Returns the number of services registered with a given superclass
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
*/
|
||||
unsigned int GetServiceCount(const Common::String & SuperclassIdentifier);
|
||||
unsigned int GetServiceCount(const Common::String &SuperclassIdentifier);
|
||||
|
||||
/**
|
||||
* Gets the identifier of a service with a given superclass.
|
||||
* The number of services in a superclass can be learned with GetServiceCount().
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param SuperclassIdentifier The name of the superclass
|
||||
* z.B: "sfx", "gfx", "package" ...
|
||||
* @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br>
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||
* 0 und GetServiceCount() - 1 sein.
|
||||
*/
|
||||
Common::String GetServiceIdentifier(const Common::String &SuperclassIdentifier, unsigned int Number);
|
||||
|
||||
|
@ -166,19 +168,23 @@ public:
|
|||
/**
|
||||
* Specifies whether the kernel was successfully initialised
|
||||
*/
|
||||
bool GetInitSuccess() { return _InitSuccess; }
|
||||
bool GetInitSuccess() {
|
||||
return _InitSuccess;
|
||||
}
|
||||
/**
|
||||
* Returns a pointer to the BS_ResourceManager
|
||||
*/
|
||||
BS_ResourceManager *GetResourceManager() { return _pResourceManager; }
|
||||
BS_ResourceManager *GetResourceManager() {
|
||||
return _pResourceManager;
|
||||
}
|
||||
/**
|
||||
* Returns how much memory is being used
|
||||
*/
|
||||
size_t GetUsedMemory();
|
||||
/**
|
||||
* Returns a random number
|
||||
* @param Min The minimum allowed value
|
||||
* @param Max The maximum allowed value
|
||||
* @param Min The minimum allowed value
|
||||
* @param Max The maximum allowed value
|
||||
*/
|
||||
int GetRandomNumber(int Min, int Max);
|
||||
/**
|
||||
|
@ -208,14 +214,14 @@ public:
|
|||
|
||||
/**
|
||||
* Pauses for the specified amount of time
|
||||
* @param Msecs The amount of time in milliseconds
|
||||
* @param Msecs The amount of time in milliseconds
|
||||
*/
|
||||
void Sleep(unsigned int Msecs) const;
|
||||
|
||||
/**
|
||||
* Returns the singleton instance for the kernel
|
||||
*/
|
||||
static BS_Kernel *GetInstance() {
|
||||
static BS_Kernel *GetInstance() {
|
||||
if (!_Instance) _Instance = new BS_Kernel();
|
||||
return _Instance;
|
||||
}
|
||||
|
@ -238,13 +244,13 @@ public:
|
|||
void Crash() const {
|
||||
error("BS_Kernel::Crash");
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constructor / destructor
|
||||
// Private singleton methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
BS_Kernel();
|
||||
virtual ~BS_Kernel();
|
||||
|
||||
|
@ -262,27 +268,35 @@ private:
|
|||
Common::String _Identifier;
|
||||
BS_Service *_ActiveService;
|
||||
Common::String _ActiveServiceName;
|
||||
|
||||
|
||||
public:
|
||||
Superclass (BS_Kernel *pKernel, const Common::String &Identifier);
|
||||
Superclass(BS_Kernel *pKernel, const Common::String &Identifier);
|
||||
~Superclass();
|
||||
|
||||
unsigned int GetServiceCount() const { return _ServiceCount; }
|
||||
Common::String GetIdentifier() const { return _Identifier; }
|
||||
BS_Service *GetActiveService() const { return _ActiveService; }
|
||||
Common::String GetActiveServiceName() const { return _ActiveServiceName; }
|
||||
|
||||
unsigned int GetServiceCount() const {
|
||||
return _ServiceCount;
|
||||
}
|
||||
Common::String GetIdentifier() const {
|
||||
return _Identifier;
|
||||
}
|
||||
BS_Service *GetActiveService() const {
|
||||
return _ActiveService;
|
||||
}
|
||||
Common::String GetActiveServiceName() const {
|
||||
return _ActiveServiceName;
|
||||
}
|
||||
Common::String GetServiceIdentifier(unsigned int Number);
|
||||
BS_Service *NewService(const Common::String &ServiceIdentifier);
|
||||
bool DisconnectService();
|
||||
};
|
||||
|
||||
Common::Array<Superclass*> _SuperclassList;
|
||||
Common::Stack<Common::String> _ServiceCreationOrder;
|
||||
|
||||
Common::Array<Superclass *> _SuperclassList;
|
||||
Common::Stack<Common::String> _ServiceCreationOrder;
|
||||
Superclass *GetSuperclassByIdentifier(const Common::String &Identifier);
|
||||
|
||||
|
||||
bool _InitSuccess; // Specifies whether the engine was set up correctly
|
||||
bool _Running; // Specifies whether the application should keep running on the next main loop iteration
|
||||
|
||||
bool _Running; // Specifies whether the application should keep running on the next main loop iteration
|
||||
|
||||
// Active window
|
||||
// -------------
|
||||
BS_Window *_pWindow;
|
||||
|
@ -296,22 +310,22 @@ private:
|
|||
// ----------------------------------
|
||||
enum _CPU_FEATURES_BITMASKS
|
||||
{
|
||||
_MMX_BITMASK = (1 << 23),
|
||||
_SSE_BITMASK = (1 << 25),
|
||||
_SSE2_BITMASK = (1 << 26),
|
||||
_3DNOW_BITMASK = (1 << 30),
|
||||
_3DNOWEXT_BITMASK = (1 << 31)
|
||||
_MMX_BITMASK = (1 << 23),
|
||||
_SSE_BITMASK = (1 << 25),
|
||||
_SSE2_BITMASK = (1 << 26),
|
||||
_3DNOW_BITMASK = (1 << 30),
|
||||
_3DNOWEXT_BITMASK = (1 << 31)
|
||||
};
|
||||
|
||||
bool _DetectCPU();
|
||||
bool _DetectCPU();
|
||||
|
||||
bool _MMXPresent;
|
||||
bool _SSEPresent;
|
||||
bool _SSE2Present;
|
||||
bool _3DNowPresent;
|
||||
bool _3DNowExtPresent;
|
||||
CPU_TYPES _CPUType;
|
||||
Common::String _CPUVendorID;
|
||||
bool _MMXPresent;
|
||||
bool _SSEPresent;
|
||||
bool _SSE2Present;
|
||||
bool _3DNowPresent;
|
||||
bool _3DNowExtPresent;
|
||||
CPU_TYPES _CPUType;
|
||||
Common::String _CPUVendorID;
|
||||
*/
|
||||
|
||||
// Resourcemanager
|
||||
|
@ -322,21 +336,21 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* This is only a small class that manages the data of a service. It is a little ugly, I know,
|
||||
* This is only a small class that manages the data of a service. It is a little ugly, I know,
|
||||
* but with Common::String a simple struct could not be used.
|
||||
*/
|
||||
class BS_ServiceInfo {
|
||||
public:
|
||||
BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String& ServiceIdentifier_,
|
||||
BS_Service* (*CreateMethod_)(BS_Kernel*)) {
|
||||
BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String &ServiceIdentifier_,
|
||||
BS_Service*(*CreateMethod_)(BS_Kernel *)) {
|
||||
this->SuperclassIdentifier = SuperclassIdentifier_;
|
||||
this->ServiceIdentifier = ServiceIdentifier_;
|
||||
this->CreateMethod = CreateMethod_;
|
||||
};
|
||||
|
||||
Common::String SuperclassIdentifier;
|
||||
Common::String ServiceIdentifier;
|
||||
BS_Service* (*CreateMethod)(BS_Kernel *);
|
||||
|
||||
Common::String SuperclassIdentifier;
|
||||
Common::String ServiceIdentifier;
|
||||
BS_Service*(*CreateMethod)(BS_Kernel *);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -64,7 +64,7 @@ static int GetActiveServiceIdentifier(lua_State *L) {
|
|||
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||
BS_ASSERT(pKernel);
|
||||
|
||||
lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L,1)).c_str());
|
||||
lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L, 1)).c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ static int GetSuperclassIdentifier(lua_State *L) {
|
|||
BS_ASSERT(pKernel);
|
||||
|
||||
lua_pushstring(L, pKernel->GetSuperclassIdentifier(
|
||||
static_cast<unsigned int>(luaL_checknumber(L,1))).c_str());
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1))).c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ static int GetServiceIdentifier(lua_State *L) {
|
|||
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||
BS_ASSERT(pKernel);
|
||||
|
||||
lua_pushstring(L, pKernel->GetServiceIdentifier(luaL_checkstring(L, 1),
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 2))).c_str());
|
||||
lua_pushstring(L, pKernel->GetServiceIdentifier(luaL_checkstring(L, 1),
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 2))).c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ static int Crash(lua_State *L) {
|
|||
static int ExecuteFile(lua_State *L) {
|
||||
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||
BS_ASSERT(pKernel);
|
||||
BS_ScriptEngine * pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
||||
BS_ScriptEngine *pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
||||
BS_ASSERT(pSE);
|
||||
|
||||
lua_pushbooleancpp(L, pSE->ExecuteFile(luaL_checkstring(L, 1)));
|
||||
|
@ -231,7 +231,7 @@ static int GetUsedMemory(lua_State *L) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const char * KERNEL_LIBRARY_NAME = "Kernel";
|
||||
static const char *KERNEL_LIBRARY_NAME = "Kernel";
|
||||
|
||||
static const luaL_reg KERNEL_FUNCTIONS[] = {
|
||||
"DisconnectService", DisconnectService,
|
||||
|
@ -492,7 +492,7 @@ static int HasFocus(lua_State *L) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const char * WINDOW_LIBRARY_NAME = "Window";
|
||||
static const char *WINDOW_LIBRARY_NAME = "Window";
|
||||
|
||||
static const luaL_reg WINDOW_FUNCTIONS[] = {
|
||||
"IsVisible", IsVisible,
|
||||
|
@ -622,7 +622,7 @@ static int DumpLockedResources(lua_State *L) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const char * RESOURCE_LIBRARY_NAME = "Resource";
|
||||
static const char *RESOURCE_LIBRARY_NAME = "Resource";
|
||||
|
||||
static const luaL_reg RESOURCE_FUNCTIONS[] = {
|
||||
"PrecacheResource", PrecacheResource,
|
||||
|
@ -655,7 +655,7 @@ static int GetSlotCount(lua_State *L) {
|
|||
|
||||
static int IsSlotOccupied(lua_State *L) {
|
||||
lua_pushbooleancpp(L, BS_PersistenceService::GetInstance().IsSlotOccupied(
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1));
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -670,7 +670,7 @@ static int GetSavegameDirectory(lua_State *L) {
|
|||
|
||||
static int IsSavegameCompatible(lua_State *L) {
|
||||
lua_pushbooleancpp(L, BS_PersistenceService::GetInstance().IsSavegameCompatible(
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1));
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -678,7 +678,7 @@ static int IsSavegameCompatible(lua_State *L) {
|
|||
|
||||
static int GetSavegameDescription(lua_State *L) {
|
||||
lua_pushstring(L, BS_PersistenceService::GetInstance().GetSavegameDescription(
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1).c_str());
|
||||
static_cast<unsigned int>(luaL_checknumber(L, 1)) - 1).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -705,7 +705,7 @@ static int SaveGame(lua_State *L) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const char * PERSISTENCE_LIBRARY_NAME = "Persistence";
|
||||
static const char *PERSISTENCE_LIBRARY_NAME = "Persistence";
|
||||
|
||||
static const luaL_reg PERSISTENCE_FUNCTIONS[] = {
|
||||
"ReloadSlots", ReloadSlots,
|
||||
|
@ -723,7 +723,7 @@ static const luaL_reg PERSISTENCE_FUNCTIONS[] = {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool BS_Kernel::_RegisterScriptBindings() {
|
||||
BS_ScriptEngine * pScript = static_cast<BS_ScriptEngine *>(GetService("script"));
|
||||
BS_ScriptEngine *pScript = static_cast<BS_ScriptEngine *>(GetService("script"));
|
||||
BS_ASSERT(pScript);
|
||||
lua_State *L = static_cast<lua_State *>(pScript->GetScriptObject());
|
||||
BS_ASSERT(L);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -41,18 +41,18 @@ namespace Sword25 {
|
|||
|
||||
// Constants
|
||||
static const char *BF_LOG_FILENAME = "log.txt";
|
||||
static const size_t LOG_BUFFERSIZE = 1024 * 16;
|
||||
static const size_t LOG_BUFFERSIZE = 1024 * 16;
|
||||
|
||||
// Logging will take place only when it's activated
|
||||
#ifdef BS_ACTIVATE_LOGGING
|
||||
|
||||
Common::WriteStream* BS_Log::_LogFile = NULL;
|
||||
bool BS_Log::_LineBegin = true;
|
||||
const char * BS_Log::_Prefix = NULL;
|
||||
const char * BS_Log::_File = NULL;
|
||||
int BS_Log::_Line = 0;
|
||||
bool BS_Log::_AutoNewline = false;
|
||||
Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener;
|
||||
Common::WriteStream *BS_Log::_LogFile = NULL;
|
||||
bool BS_Log::_LineBegin = true;
|
||||
const char *BS_Log::_Prefix = NULL;
|
||||
const char *BS_Log::_File = NULL;
|
||||
int BS_Log::_Line = 0;
|
||||
bool BS_Log::_AutoNewline = false;
|
||||
Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener;
|
||||
|
||||
bool BS_Log::_CreateLog() {
|
||||
// Open the log file
|
||||
|
@ -109,7 +109,7 @@ void BS_Log::LogPrefix(const char *Prefix, const char *Format, ...) {
|
|||
if (!NextLine || *(NextLine + strlen("\n")) == 0) {
|
||||
_snprintf(ExtFormat, sizeof(ExtFormat), "%s%s", ExtFormat, Format);
|
||||
if (NextLine) _LineBegin = true;
|
||||
break;
|
||||
break;
|
||||
} else {
|
||||
strncat(ExtFormat, Format, (NextLine - Format) + strlen("\n"));
|
||||
_snprintf(ExtFormat, sizeof(ExtFormat), "%s%s: ", ExtFormat, Prefix);
|
||||
|
@ -117,7 +117,7 @@ void BS_Log::LogPrefix(const char *Prefix, const char *Format, ...) {
|
|||
|
||||
Format = NextLine + strlen("\n");
|
||||
}
|
||||
|
||||
|
||||
// Create message
|
||||
va_list ArgList;
|
||||
va_start(ArgList, Format);
|
||||
|
@ -140,7 +140,7 @@ void BS_Log::LogDecorated(const char *Format, ...) {
|
|||
char SecondaryPrefix[1024];
|
||||
if (_File && _Line)
|
||||
_snprintf(SecondaryPrefix, sizeof(SecondaryPrefix), "(file: %s, line: %d) - ", _File, _Line);
|
||||
|
||||
|
||||
// Nachricht zeilenweise ausgeben und an jeden Zeilenanfang das Präfix setzen
|
||||
char *MessageWalker = Message;
|
||||
for (;;) {
|
||||
|
@ -183,7 +183,7 @@ void BS_Log::LogDecorated(const char *Format, ...) {
|
|||
_FlushLog();
|
||||
}
|
||||
|
||||
int BS_Log::_WriteLog(const char * Message) {
|
||||
int BS_Log::_WriteLog(const char *Message) {
|
||||
if (!_LogFile) if (!_CreateLog()) return false;
|
||||
|
||||
Common::Array<LOG_LISTENER_CALLBACK>::iterator Iter = _LogListener.begin();
|
||||
|
@ -207,7 +207,7 @@ void BS_Log_C(const char *Message) {
|
|||
|
||||
#else
|
||||
|
||||
void BS_Log_C(const char* Message) {};
|
||||
void BS_Log_C(const char *Message) {};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -46,32 +46,41 @@ namespace Sword25 {
|
|||
#ifdef BS_ACTIVATE_LOGGING
|
||||
|
||||
// Logging-Makros
|
||||
#define BS_LOG BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::LogDecorated
|
||||
#define BS_LOGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_WARNING BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::LogDecorated
|
||||
#define BS_LOG_WARNINGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_ERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::LogDecorated
|
||||
#define BS_LOG_ERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_EXTERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::LogDecorated
|
||||
#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::LogDecorated
|
||||
#define BS_LOGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_WARNING BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::LogDecorated
|
||||
#define BS_LOG_WARNINGLN BS_Log::SetPrefix(BS_LOG_PREFIX ": WARNING - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_ERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::LogDecorated
|
||||
#define BS_LOG_ERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR - "), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
#define BS_LOG_EXTERROR BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::LogDecorated
|
||||
#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||
|
||||
// Die Version der Logging-Klasse mit aktiviertem Logging
|
||||
class BS_Log
|
||||
{
|
||||
class BS_Log {
|
||||
public:
|
||||
static void Clear();
|
||||
static void Log(const char* Format, ...);
|
||||
static void LogPrefix(const char* Prefix, const char* Format, ...);
|
||||
static void LogDecorated(const char* Format, ...);
|
||||
static void Log(const char *Format, ...);
|
||||
static void LogPrefix(const char *Prefix, const char *Format, ...);
|
||||
static void LogDecorated(const char *Format, ...);
|
||||
|
||||
static void SetPrefix(const char* Prefix) { _Prefix = Prefix; }
|
||||
static void SetFile(const char* File) { _File = File; }
|
||||
static void SetLine(int Line) { _Line = Line; }
|
||||
static void SetAutoNewline(bool AutoNewline) { _AutoNewline = AutoNewline; }
|
||||
static void SetPrefix(const char *Prefix) {
|
||||
_Prefix = Prefix;
|
||||
}
|
||||
static void SetFile(const char *File) {
|
||||
_File = File;
|
||||
}
|
||||
static void SetLine(int Line) {
|
||||
_Line = Line;
|
||||
}
|
||||
static void SetAutoNewline(bool AutoNewline) {
|
||||
_AutoNewline = AutoNewline;
|
||||
}
|
||||
|
||||
typedef void (*LOG_LISTENER_CALLBACK)(const char *);
|
||||
static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) { _LogListener.push_back(Callback); }
|
||||
static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) {
|
||||
static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) {
|
||||
_LogListener.push_back(Callback);
|
||||
}
|
||||
static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) {
|
||||
Common::Array<LOG_LISTENER_CALLBACK>::iterator i;
|
||||
for (i = _LogListener.begin(); i != _LogListener.end(); ++i) {
|
||||
if (**i == Callback)
|
||||
|
@ -82,17 +91,17 @@ public:
|
|||
static void _CloseLog();
|
||||
|
||||
private:
|
||||
static Common::WriteStream * _LogFile;
|
||||
static bool _LineBegin;
|
||||
static const char * _Prefix;
|
||||
static const char * _File;
|
||||
static int _Line;
|
||||
static bool _AutoNewline;
|
||||
static Common::Array<LOG_LISTENER_CALLBACK> _LogListener;
|
||||
|
||||
static Common::WriteStream *_LogFile;
|
||||
static bool _LineBegin;
|
||||
static const char *_Prefix;
|
||||
static const char *_File;
|
||||
static int _Line;
|
||||
static bool _AutoNewline;
|
||||
static Common::Array<LOG_LISTENER_CALLBACK> _LogListener;
|
||||
|
||||
static bool _CreateLog();
|
||||
|
||||
static int _WriteLog(const char* Message);
|
||||
static int _WriteLog(const char *Message);
|
||||
static void _FlushLog();
|
||||
};
|
||||
|
||||
|
@ -112,16 +121,16 @@ private:
|
|||
#define BS_LOG_EXTERROR
|
||||
#define BS_LOG_EXTERRORLN
|
||||
|
||||
// The version of the logging class with logging disabled
|
||||
// The version of the logging class with logging disabled
|
||||
class BS_Log {
|
||||
public:
|
||||
// This version implements all the various methods as empty stubs
|
||||
static void Log(const char* Text, ...) {};
|
||||
static void LogPrefix(const char* Prefix, const char* Format, ...) {};
|
||||
static void LogDecorated(const char* Format, ...) {};
|
||||
static void Log(const char *Text, ...) {};
|
||||
static void LogPrefix(const char *Prefix, const char *Format, ...) {};
|
||||
static void LogDecorated(const char *Format, ...) {};
|
||||
|
||||
static void SetPrefix(const char* Prefix) {};
|
||||
static void SetFile(const char* File) {};
|
||||
static void SetPrefix(const char *Prefix) {};
|
||||
static void SetFile(const char *File) {};
|
||||
static void SetLine(int Line) {};
|
||||
static void SetAutoNewline(bool AutoNewline) {};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,54 +53,47 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int address;
|
||||
unsigned int size;
|
||||
std::string file;
|
||||
unsigned int line;
|
||||
typedef struct {
|
||||
unsigned int address;
|
||||
unsigned int size;
|
||||
std::string file;
|
||||
unsigned int line;
|
||||
} ALLOC_INFO;
|
||||
|
||||
static const char * MEMLEAK_LOG_FILE = "memory_leaks.txt";
|
||||
static const char *MEMLEAK_LOG_FILE = "memory_leaks.txt";
|
||||
static const unsigned int BUCKET_COUNT = 1021;
|
||||
std::vector< std::vector<ALLOC_INFO> > TrackData(BUCKET_COUNT);
|
||||
|
||||
static unsigned int TotalSize = 0;
|
||||
|
||||
// Diese Klasse stellt sicher, dass beim Programmende, das Memory-Leak Log geschrieben wird.
|
||||
static class LeakDumper
|
||||
{
|
||||
static class LeakDumper {
|
||||
public:
|
||||
LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE)
|
||||
{
|
||||
LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE) {
|
||||
// Sicherstellen, dass das Ausgabeverzeichnis für die Datei existiert.
|
||||
BS_FileSystemUtil::GetInstance().CreateDirectory(BS_FileSystemUtil::GetInstance().GetUserdataDirectory());
|
||||
}
|
||||
|
||||
~LeakDumper()
|
||||
{
|
||||
~LeakDumper() {
|
||||
DumpUnfreed(OutputFilename.c_str());
|
||||
}
|
||||
|
||||
std::string OutputFilename;
|
||||
} LeakDumperInstance;
|
||||
|
||||
void DumpUnfreed(const char * OutputFilename)
|
||||
{
|
||||
FILE * Log = fopen(OutputFilename, "w");
|
||||
void DumpUnfreed(const char *OutputFilename) {
|
||||
FILE *Log = fopen(OutputFilename, "w");
|
||||
fputs("MEMORY LEAK REPORT:\n----------------------\n", Log);
|
||||
std::vector< std::vector<ALLOC_INFO> >::iterator BucketIter = TrackData.begin();
|
||||
for (; BucketIter != TrackData.end(); ++BucketIter)
|
||||
{
|
||||
for (; BucketIter != TrackData.end(); ++BucketIter) {
|
||||
std::vector<ALLOC_INFO>::iterator Iter = (*BucketIter).begin();
|
||||
for (; Iter != (*BucketIter).end(); ++Iter)
|
||||
{
|
||||
ALLOC_INFO & CurItem = (*Iter);
|
||||
for (; Iter != (*BucketIter).end(); ++Iter) {
|
||||
ALLOC_INFO &CurItem = (*Iter);
|
||||
fprintf(Log, "%-50s LINE:%d ADDRESS:0x%x SIZE:%d\n",
|
||||
CurItem.file.c_str(),
|
||||
CurItem.line,
|
||||
CurItem.address,
|
||||
CurItem.size);
|
||||
CurItem.file.c_str(),
|
||||
CurItem.line,
|
||||
CurItem.address,
|
||||
CurItem.size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,8 +102,7 @@ void DumpUnfreed(const char * OutputFilename)
|
|||
fclose(Log);
|
||||
}
|
||||
|
||||
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum)
|
||||
{
|
||||
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum) {
|
||||
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
||||
ALLOC_INFO Info;
|
||||
Info.address = addr;
|
||||
|
@ -122,18 +114,14 @@ void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsign
|
|||
TotalSize += asize;
|
||||
}
|
||||
|
||||
void RemoveTrack(unsigned int addr)
|
||||
{
|
||||
if (addr != 0 && TrackData.size() == BUCKET_COUNT)
|
||||
{
|
||||
void RemoveTrack(unsigned int addr) {
|
||||
if (addr != 0 && TrackData.size() == BUCKET_COUNT) {
|
||||
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
||||
std::vector<ALLOC_INFO>::iterator Iter = CurBucket.begin();
|
||||
for (; Iter != CurBucket.end(); ++Iter)
|
||||
{
|
||||
if ((*Iter).address == addr)
|
||||
{
|
||||
for (; Iter != CurBucket.end(); ++Iter) {
|
||||
if ((*Iter).address == addr) {
|
||||
TotalSize -= (*Iter).size;
|
||||
|
||||
|
||||
std::swap(*Iter, CurBucket.back());
|
||||
CurBucket.pop_back();
|
||||
return;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -43,25 +43,22 @@
|
|||
|
||||
#include <malloc.h>
|
||||
|
||||
void DumpUnfreed(const char * OutputFilename);
|
||||
void DumpUnfreed(const char *OutputFilename);
|
||||
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum);
|
||||
void RemoveTrack(unsigned int addr);
|
||||
|
||||
inline void * __cdecl operator new(unsigned int size, const char *file, int line)
|
||||
{
|
||||
inline void *__cdecl operator new(unsigned int size, const char *file, int line) {
|
||||
void *ptr = malloc(size);
|
||||
if (ptr) AddTrack((unsigned int)ptr, size, file, line);
|
||||
return(ptr);
|
||||
};
|
||||
|
||||
inline void __cdecl operator delete(void *p)
|
||||
{
|
||||
inline void __cdecl operator delete(void *p) {
|
||||
RemoveTrack((unsigned int)p);
|
||||
free(p);
|
||||
};
|
||||
|
||||
inline void __cdecl operator delete[](void *p)
|
||||
{
|
||||
inline void __cdecl operator delete[](void *p) {
|
||||
RemoveTrack((unsigned int)p);
|
||||
free(p);
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -35,8 +35,8 @@
|
|||
// Deaktivieren der Memory-Leak Detektion
|
||||
|
||||
#ifdef BS_MEMLOG
|
||||
#ifdef new
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#endif
|
||||
#ifdef new
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -35,8 +35,8 @@
|
|||
// Aktivieren der Memory-Leak Detektion
|
||||
|
||||
#ifdef BS_MEMLOG
|
||||
#ifndef DEBUG_NEW
|
||||
#define DEBUG_NEW new(__FILE__, __LINE__)
|
||||
#endif
|
||||
#define new DEBUG_NEW
|
||||
#ifndef DEBUG_NEW
|
||||
#define DEBUG_NEW new(__FILE__, __LINE__)
|
||||
#endif
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -150,20 +150,22 @@ public:
|
|||
protected:
|
||||
// FIXME: I'm not entirely sure my current hash function is legitimate
|
||||
struct ClassPointer_EqualTo {
|
||||
bool operator()(const T *x, const T *y) const { return x == y; }
|
||||
bool operator()(const T *x, const T *y) const {
|
||||
return x == y;
|
||||
}
|
||||
};
|
||||
struct ClassPointer_Hash {
|
||||
uint operator()(const T *x) const {
|
||||
uint operator()(const T *x) const {
|
||||
return static_cast<uint>((int64)x % ((int64)1 << sizeof(uint)));
|
||||
}
|
||||
};
|
||||
|
||||
typedef Common::HashMap<unsigned int, T *> HANDLE2PTR_MAP;
|
||||
typedef Common::HashMap<unsigned int, T *> HANDLE2PTR_MAP;
|
||||
typedef Common::HashMap<T *, unsigned int, ClassPointer_Hash, ClassPointer_EqualTo> PTR2HANDLE_MAP;
|
||||
|
||||
HANDLE2PTR_MAP m_Handle2PtrMap;
|
||||
PTR2HANDLE_MAP m_Ptr2HandleMap;
|
||||
unsigned int m_NextHandle;
|
||||
HANDLE2PTR_MAP m_Handle2PtrMap;
|
||||
PTR2HANDLE_MAP m_Ptr2HandleMap;
|
||||
unsigned int m_NextHandle;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -45,7 +45,7 @@
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64;
|
||||
const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64;
|
||||
}
|
||||
|
||||
namespace Sword25 {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_OUTPUTPERSISTENCEBLOCK_H
|
||||
#ifndef SWORD25_OUTPUTPERSISTENCEBLOCK_H
|
||||
#define SWORD25_OUTPUTPERSISTENCEBLOCK_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -59,8 +59,12 @@ public:
|
|||
void Write(const Common::String &String);
|
||||
void Write(const void *BufferPtr, size_t Size);
|
||||
|
||||
const void *GetData() const { return &m_Data[0]; }
|
||||
unsigned int GetDataSize() const { return m_Data.size(); }
|
||||
const void *GetData() const {
|
||||
return &m_Data[0];
|
||||
}
|
||||
unsigned int GetDataSize() const {
|
||||
return m_Data.size();
|
||||
}
|
||||
|
||||
private:
|
||||
void WriteMarker(unsigned char Marker);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -44,8 +44,8 @@ class BS_Persistable {
|
|||
public:
|
||||
virtual ~BS_Persistable() {};
|
||||
|
||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer) = 0;
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader) = 0;
|
||||
virtual bool Persist(BS_OutputPersistenceBlock &Writer) = 0;
|
||||
virtual bool Unpersist(BS_InputPersistenceBlock &Reader) = 0;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_PERSISTENCEBLOCK_H
|
||||
#ifndef SWORD25_PERSISTENCEBLOCK_H
|
||||
#define SWORD25_PERSISTENCEBLOCK_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -49,12 +49,20 @@ namespace Sword25 {
|
|||
|
||||
class BS_PersistenceBlock {
|
||||
public:
|
||||
static unsigned int GetSInt32Size() { return sizeof(signed int) + sizeof(unsigned char); }
|
||||
static unsigned int GetUInt32Size() { return sizeof(unsigned int) + sizeof(unsigned char); }
|
||||
static unsigned int GetFloat32Size() { return sizeof(float) + sizeof(unsigned char); }
|
||||
static unsigned int GetBoolSize() { return sizeof(unsigned char) + sizeof(unsigned char); }
|
||||
static unsigned int GetStringSize(const Common::String &String) {
|
||||
return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char));
|
||||
static unsigned int GetSInt32Size() {
|
||||
return sizeof(signed int) + sizeof(unsigned char);
|
||||
}
|
||||
static unsigned int GetUInt32Size() {
|
||||
return sizeof(unsigned int) + sizeof(unsigned char);
|
||||
}
|
||||
static unsigned int GetFloat32Size() {
|
||||
return sizeof(float) + sizeof(unsigned char);
|
||||
}
|
||||
static unsigned int GetBoolSize() {
|
||||
return sizeof(unsigned char) + sizeof(unsigned char);
|
||||
}
|
||||
static unsigned int GetStringSize(const Common::String &String) {
|
||||
return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -90,7 +98,7 @@ protected:
|
|||
private:
|
||||
static bool IsBigEndian() {
|
||||
unsigned int Dummy = 1;
|
||||
unsigned char * DummyPtr = reinterpret_cast<unsigned char *>(&Dummy);
|
||||
unsigned char *DummyPtr = reinterpret_cast<unsigned char *>(&Dummy);
|
||||
return DummyPtr[0] == 0;
|
||||
}
|
||||
|
||||
|
@ -103,7 +111,7 @@ private:
|
|||
|
||||
static void ReverseByteOrder(void *Ptr) {
|
||||
// Reverses the byte order of the 32-bit word pointed to by Ptr
|
||||
unsigned char * CharPtr = static_cast<unsigned char *>(Ptr);
|
||||
unsigned char *CharPtr = static_cast<unsigned char *>(Ptr);
|
||||
Swap(CharPtr[0], CharPtr[3]);
|
||||
Swap(CharPtr[1], CharPtr[2]);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -58,61 +58,61 @@ using namespace std;
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace Sword25 {
|
||||
const char * SAVEGAME_EXTENSION = ".b25s";
|
||||
const char * SAVEGAME_DIRECTORY = "saves";
|
||||
const char * FILE_MARKER = "BS25SAVEGAME";
|
||||
const unsigned int SLOT_COUNT = 18;
|
||||
const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10;
|
||||
const char *VERSIONID = "1";
|
||||
const char *SAVEGAME_EXTENSION = ".b25s";
|
||||
const char *SAVEGAME_DIRECTORY = "saves";
|
||||
const char *FILE_MARKER = "BS25SAVEGAME";
|
||||
const unsigned int SLOT_COUNT = 18;
|
||||
const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10;
|
||||
const char *VERSIONID = "1";
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String GenerateSavegameFilename(unsigned int SlotID) {
|
||||
Common::String oss;
|
||||
oss += SlotID;
|
||||
oss += SAVEGAME_EXTENSION;
|
||||
return oss;
|
||||
Common::String GenerateSavegameFilename(unsigned int SlotID) {
|
||||
Common::String oss;
|
||||
oss += SlotID;
|
||||
oss += SAVEGAME_EXTENSION;
|
||||
return oss;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String GenerateSavegamePath(unsigned int SlotID) {
|
||||
Common::String oss;
|
||||
oss = BS_PersistenceService::GetSavegameDirectory();
|
||||
oss += BS_FileSystemUtil::GetInstance().GetPathSeparator();
|
||||
oss += GenerateSavegameFilename(SlotID);
|
||||
return oss;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String FormatTimestamp(TimeDate Time) {
|
||||
// In the original BS2.5 engine, this used a local object to show the date/time as as a string.
|
||||
// For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss'
|
||||
Common::String monthList[12] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
char buffer[100];
|
||||
snprintf(buffer, 100, "%.2d-%s-%.4d %.2d:%.2d:%.2d",
|
||||
Time.tm_mday, monthList[Time.tm_mon].c_str(), Time.tm_year,
|
||||
Time.tm_hour, Time.tm_min, Time.tm_sec
|
||||
);
|
||||
|
||||
return Common::String(buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) {
|
||||
Common::String Result;
|
||||
char ch;
|
||||
while ((ch = (char)In->readByte()) != '\0') {
|
||||
Result += ch;
|
||||
if (Result.size() >= MaxSize) break;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String GenerateSavegamePath(unsigned int SlotID) {
|
||||
Common::String oss;
|
||||
oss = BS_PersistenceService::GetSavegameDirectory();
|
||||
oss += BS_FileSystemUtil::GetInstance().GetPathSeparator();
|
||||
oss += GenerateSavegameFilename(SlotID);
|
||||
return oss;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String FormatTimestamp(TimeDate Time) {
|
||||
// In the original BS2.5 engine, this used a local object to show the date/time as as a string.
|
||||
// For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss'
|
||||
Common::String monthList[12] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
char buffer[100];
|
||||
snprintf(buffer, 100, "%.2d-%s-%.4d %.2d:%.2d:%.2d",
|
||||
Time.tm_mday, monthList[Time.tm_mon].c_str(), Time.tm_year,
|
||||
Time.tm_hour, Time.tm_min, Time.tm_sec
|
||||
);
|
||||
|
||||
return Common::String(buffer);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) {
|
||||
Common::String Result;
|
||||
char ch;
|
||||
while ((ch = (char)In->readByte()) != '\0') {
|
||||
Result += ch;
|
||||
if (Result.size() >= MaxSize) break;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Sword25 {
|
||||
|
@ -122,15 +122,17 @@ namespace Sword25 {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct SavegameInformation {
|
||||
bool IsOccupied;
|
||||
bool IsCompatible;
|
||||
Common::String Description;
|
||||
Common::String Filename;
|
||||
unsigned int GamedataLength;
|
||||
unsigned int GamedataOffset;
|
||||
unsigned int GamedataUncompressedLength;
|
||||
bool IsOccupied;
|
||||
bool IsCompatible;
|
||||
Common::String Description;
|
||||
Common::String Filename;
|
||||
unsigned int GamedataLength;
|
||||
unsigned int GamedataOffset;
|
||||
unsigned int GamedataUncompressedLength;
|
||||
|
||||
SavegameInformation() { Clear(); }
|
||||
SavegameInformation() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
IsOccupied = false;
|
||||
|
@ -163,7 +165,7 @@ struct BS_PersistenceService::Impl {
|
|||
|
||||
void ReadSlotSavegameInformation(unsigned int SlotID) {
|
||||
// Aktuelle Slotinformationen in den Ausgangszustand versetzen, er wird im Folgenden neu gefüllt.
|
||||
SavegameInformation & CurSavegameInfo = m_SavegameInformations[SlotID];
|
||||
SavegameInformation &CurSavegameInfo = m_SavegameInformations[SlotID];
|
||||
CurSavegameInfo.Clear();
|
||||
|
||||
// Den Dateinamen für den Spielstand des Slots generieren.
|
||||
|
@ -207,7 +209,7 @@ struct BS_PersistenceService::Impl {
|
|||
// Construction / Destruction
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BS_PersistenceService & BS_PersistenceService::GetInstance() {
|
||||
BS_PersistenceService &BS_PersistenceService::GetInstance() {
|
||||
static BS_PersistenceService Instance;
|
||||
return Instance;
|
||||
}
|
||||
|
@ -246,16 +248,16 @@ Common::String BS_PersistenceService::GetSavegameDirectory() {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
bool CheckSlotID(unsigned int SlotID) {
|
||||
// Überprüfen, ob die Slot-ID zulässig ist.
|
||||
if (SlotID >= SLOT_COUNT) {
|
||||
BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
bool CheckSlotID(unsigned int SlotID) {
|
||||
// Überprüfen, ob die Slot-ID zulässig ist.
|
||||
if (SlotID >= SLOT_COUNT) {
|
||||
BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
@ -304,7 +306,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String &
|
|||
|
||||
// Spielstanddatei öffnen und die Headerdaten schreiben.
|
||||
Common::SaveFileManager *sfm = g_system->getSavefileManager();
|
||||
Common::OutSaveFile *File = sfm->openForSaving(Filename);
|
||||
Common::OutSaveFile *File = sfm->openForSaving(Filename);
|
||||
|
||||
File->writeString(FILE_MARKER);
|
||||
File->writeByte(' ');
|
||||
|
@ -330,7 +332,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String &
|
|||
// Daten komprimieren.
|
||||
uLongf CompressedLength = Writer.GetDataSize() + (Writer.GetDataSize() + 500) / 1000 + 12;
|
||||
Bytef *CompressionBuffer = new Bytef[CompressedLength];
|
||||
|
||||
|
||||
if (compress2(&CompressionBuffer[0], &CompressedLength, reinterpret_cast<const Bytef *>(Writer.GetData()), Writer.GetDataSize(), 6) != Z_OK) {
|
||||
error("Unable to compress savegame data in savegame file \"%s\".", Filename.c_str());
|
||||
}
|
||||
|
@ -353,7 +355,7 @@ bool BS_PersistenceService::SaveGame(unsigned int SlotID, const Common::String &
|
|||
// Screenshotdatei an die Datei anfügen.
|
||||
if (BS_FileSystemUtil::GetInstance().FileExists(ScreenshotFilename)) {
|
||||
Common::File ScreenshotFile;
|
||||
if (!ScreenshotFile.open(ScreenshotFilename.c_str()))
|
||||
if (!ScreenshotFile.open(ScreenshotFilename.c_str()))
|
||||
error("Unable to load screenshot file");
|
||||
|
||||
byte *Buffer = new Byte[FILE_COPY_BUFFER_SIZE];
|
||||
|
@ -386,7 +388,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SavegameInformation & CurSavegameInfo = m_impl->m_SavegameInformations[SlotID];
|
||||
SavegameInformation &CurSavegameInfo = m_impl->m_SavegameInformations[SlotID];
|
||||
|
||||
// Überprüfen, ob der Slot belegt ist.
|
||||
if (!CurSavegameInfo.IsOccupied) {
|
||||
|
@ -398,8 +400,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
|||
// Im Debug-Modus wird dieser Test übersprungen. Für das Testen ist es hinderlich auf die Einhaltung dieser strengen Bedingung zu bestehen,
|
||||
// da sich die Versions-ID bei jeder Codeänderung mitändert.
|
||||
#ifndef DEBUG
|
||||
if (!CurSavegameInfo.IsCompatible)
|
||||
{
|
||||
if (!CurSavegameInfo.IsCompatible) {
|
||||
BS_LOG_ERRORLN("Tried to load a savegame (%d) that is not compatible with this engine version.", SlotID);
|
||||
return false;
|
||||
}
|
||||
|
@ -408,7 +409,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
|||
byte *CompressedDataBuffer = new byte[CurSavegameInfo.GamedataLength];
|
||||
byte *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
|
||||
|
||||
File = sfm->openForLoading(GenerateSavegamePath(SlotID));
|
||||
File = sfm->openForLoading(GenerateSavegamePath(SlotID));
|
||||
|
||||
File->seek(CurSavegameInfo.GamedataOffset);
|
||||
File->read(reinterpret_cast<char *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength);
|
||||
|
@ -422,7 +423,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
|||
// Spieldaten dekomprimieren.
|
||||
uLongf UncompressedBufferSize = CurSavegameInfo.GamedataUncompressedLength;
|
||||
if (uncompress(reinterpret_cast<Bytef *>(&UncompressedDataBuffer[0]), &UncompressedBufferSize,
|
||||
reinterpret_cast<Bytef *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength) != Z_OK) {
|
||||
reinterpret_cast<Bytef *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength) != Z_OK) {
|
||||
BS_LOG_ERRORLN("Unable to decompress the gamedata from savegame file \"%s\".", CurSavegameInfo.Filename.c_str());
|
||||
delete[] UncompressedDataBuffer;
|
||||
delete[] CompressedDataBuffer;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -32,7 +32,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef SWORD25_PERSISTENCESERVICE_H
|
||||
#ifndef SWORD25_PERSISTENCESERVICE_H
|
||||
#define SWORD25_PERSISTENCESERVICE_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -62,21 +62,21 @@ public:
|
|||
// Interface
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static unsigned int GetSlotCount();
|
||||
static unsigned int GetSlotCount();
|
||||
static Common::String GetSavegameDirectory();
|
||||
|
||||
void ReloadSlots();
|
||||
bool IsSlotOccupied(unsigned int SlotID);
|
||||
bool IsSavegameCompatible(unsigned int SlotID);
|
||||
void ReloadSlots();
|
||||
bool IsSlotOccupied(unsigned int SlotID);
|
||||
bool IsSavegameCompatible(unsigned int SlotID);
|
||||
Common::String &GetSavegameDescription(unsigned int SlotID);
|
||||
Common::String &GetSavegameFilename(unsigned int SlotID);
|
||||
|
||||
bool SaveGame(unsigned int SlotID, const Common::String & ScreenshotFilename);
|
||||
bool LoadGame(unsigned int SlotID);
|
||||
|
||||
bool SaveGame(unsigned int SlotID, const Common::String &ScreenshotFilename);
|
||||
bool LoadGame(unsigned int SlotID);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl * m_impl;
|
||||
Impl *m_impl;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -53,7 +53,9 @@ BS_ResourceManager::~BS_ResourceManager() {
|
|||
BS_LOG_WARNINGLN("Resource \"%s\" was not released.", (*Iter)->GetFileName().c_str());
|
||||
|
||||
// Set the lock count to zero
|
||||
while ((*Iter)->GetLockCount() > 0) { (*Iter)->Release(); };
|
||||
while ((*Iter)->GetLockCount() > 0) {
|
||||
(*Iter)->Release();
|
||||
};
|
||||
|
||||
// Delete the resource
|
||||
delete(*Iter);
|
||||
|
@ -63,7 +65,7 @@ BS_ResourceManager::~BS_ResourceManager() {
|
|||
/**
|
||||
* Returns a resource by it's ordinal index. Returns NULL if any error occurs
|
||||
* Note: This method is not optimised for speed and should be used only for debugging purposes
|
||||
* @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
|
||||
* @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
|
||||
*/
|
||||
BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const {
|
||||
// Überprüfen ob der Index Ord innerhald der Listengrenzen liegt.
|
||||
|
@ -74,7 +76,7 @@ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const {
|
|||
|
||||
// Liste durchlaufen und die Resource mit dem gewünschten Index zurückgeben.
|
||||
int CurOrd = 0;
|
||||
Common::List<BS_Resource*>::const_iterator Iter = m_Resources.begin();
|
||||
Common::List<BS_Resource *>::const_iterator Iter = m_Resources.begin();
|
||||
for (; Iter != m_Resources.end(); ++Iter, ++CurOrd) {
|
||||
if (CurOrd == Ord)
|
||||
return (*Iter);
|
||||
|
@ -88,7 +90,7 @@ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const {
|
|||
/**
|
||||
* Registers a RegisterResourceService. This method is the constructor of
|
||||
* BS_ResourceService, and thus helps all resource services in the ResourceManager list
|
||||
* @param pService Which service
|
||||
* @param pService Which service
|
||||
*/
|
||||
bool BS_ResourceManager::RegisterResourceService(BS_ResourceService *pService) {
|
||||
if (!pService) {
|
||||
|
@ -109,7 +111,7 @@ void BS_ResourceManager::DeleteResourcesIfNecessary() {
|
|||
if (m_KernelPtr->GetUsedMemory() < m_MaxMemoryUsage || m_Resources.empty()) return;
|
||||
|
||||
// Keep deleting resources until the memory usage of the process falls below the set maximum limit.
|
||||
// The list is processed backwards in order to first release those resources who have been
|
||||
// The list is processed backwards in order to first release those resources who have been
|
||||
// not been accessed for the longest
|
||||
Common::List<BS_Resource *>::iterator Iter = m_Resources.end();
|
||||
do {
|
||||
|
@ -137,7 +139,7 @@ void BS_ResourceManager::EmptyCache() {
|
|||
|
||||
/**
|
||||
* Returns a requested resource. If any error occurs, returns NULL
|
||||
* @param FileName Filename of resource
|
||||
* @param FileName Filename of resource
|
||||
*/
|
||||
BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName) {
|
||||
// Get the absolute path to the file
|
||||
|
@ -170,11 +172,11 @@ BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName)
|
|||
|
||||
/**
|
||||
* Loads a resource into the cache
|
||||
* @param FileName The filename of the resource to be cached
|
||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||
* @param FileName The filename of the resource to be cached
|
||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||
* This is useful for files that may have changed in the interim
|
||||
*/
|
||||
bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool ForceReload) {
|
||||
bool BS_ResourceManager::PrecacheResource(const Common::String &FileName, bool ForceReload) {
|
||||
// Get the absolute path to the file
|
||||
Common::String UniqueFileName = GetUniqueFileName(FileName);
|
||||
if (UniqueFileName == "")
|
||||
|
@ -202,7 +204,7 @@ bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool F
|
|||
|
||||
/**
|
||||
* Moves a resource to the top of the resource list
|
||||
* @param pResource The resource
|
||||
* @param pResource The resource
|
||||
*/
|
||||
void BS_ResourceManager::MoveToFront(BS_Resource *pResource) {
|
||||
// Erase the resource from it's current position
|
||||
|
@ -217,7 +219,7 @@ void BS_ResourceManager::MoveToFront(BS_Resource *pResource) {
|
|||
* Loads a resource and updates the m_UsedMemory total
|
||||
*
|
||||
* The resource must not already be loaded
|
||||
* @param FileName The unique filename of the resource to be loaded
|
||||
* @param FileName The unique filename of the resource to be loaded
|
||||
*/
|
||||
BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) {
|
||||
// ResourceService finden, der die Resource laden kann.
|
||||
|
@ -252,7 +254,7 @@ BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) {
|
|||
* Returns the full path of a given resource filename.
|
||||
* It will return an empty string if a path could not be created.
|
||||
*/
|
||||
Common::String BS_ResourceManager::GetUniqueFileName(const Common::String& FileName) const {
|
||||
Common::String BS_ResourceManager::GetUniqueFileName(const Common::String &FileName) const {
|
||||
// Get a pointer to the package manager
|
||||
BS_PackageManager *pPackage = (BS_PackageManager *)m_KernelPtr->GetService("package");
|
||||
if (!pPackage) {
|
||||
|
@ -281,7 +283,7 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso
|
|||
Common::List<BS_Resource *>::iterator Result = m_Resources.erase(pResource->_Iterator);
|
||||
|
||||
// Delete the resource
|
||||
delete (pDummy);
|
||||
delete(pDummy);
|
||||
|
||||
// Return the iterator
|
||||
return Result;
|
||||
|
@ -289,17 +291,16 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso
|
|||
|
||||
/**
|
||||
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
|
||||
* @param UniqueFileName The absolute path and filename
|
||||
* @param UniqueFileName The absolute path and filename
|
||||
* Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
|
||||
*/
|
||||
BS_Resource * BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const {
|
||||
BS_Resource *BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const {
|
||||
// Determine whether the resource is already loaded
|
||||
const Common::List<BS_Resource *>& HashBucket = m_ResourceHashTable[
|
||||
BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
|
||||
BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
|
||||
{
|
||||
Common::List<BS_Resource*>::const_iterator Iter = HashBucket.begin();
|
||||
for (; Iter != HashBucket.end(); ++Iter)
|
||||
{
|
||||
Common::List<BS_Resource *>::const_iterator Iter = HashBucket.begin();
|
||||
for (; Iter != HashBucket.end(); ++Iter) {
|
||||
// Wenn die Resource gefunden wurde wird sie zurückgegeben.
|
||||
if ((*Iter)->GetFileName() == UniqueFileName)
|
||||
return *Iter;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -48,41 +48,43 @@ class BS_Resource;
|
|||
class BS_Kernel;
|
||||
|
||||
class BS_ResourceManager {
|
||||
friend class BS_Kernel;
|
||||
friend class BS_Kernel;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns a requested resource. If any error occurs, returns NULL
|
||||
* @param FileName Filename of resource
|
||||
* @param FileName Filename of resource
|
||||
*/
|
||||
BS_Resource *RequestResource(const Common::String &FileName);
|
||||
|
||||
/**
|
||||
* Loads a resource into the cache
|
||||
* @param FileName The filename of the resource to be cached
|
||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||
* @param FileName The filename of the resource to be cached
|
||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||
* This is useful for files that may have changed in the interim
|
||||
*/
|
||||
bool PrecacheResource(const Common::String& FileName, bool ForceReload = false);
|
||||
bool PrecacheResource(const Common::String &FileName, bool ForceReload = false);
|
||||
|
||||
/**
|
||||
* Returns the number of loaded resources
|
||||
*/
|
||||
int GetResourceCount() const { return static_cast<int>(m_Resources.size()); }
|
||||
int GetResourceCount() const {
|
||||
return static_cast<int>(m_Resources.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a resource by it's ordinal index. Returns NULL if any error occurs
|
||||
* Note: This method is not optimised for speed and should be used only for debugging purposes
|
||||
* @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
|
||||
* @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
|
||||
*/
|
||||
BS_Resource *GetResourceByOrdinal(int Ord) const;
|
||||
|
||||
/**
|
||||
* Registers a RegisterResourceService. This method is the constructor of
|
||||
* BS_ResourceService, and thus helps all resource services in the ResourceManager list
|
||||
* @param pService Which service
|
||||
* @param pService Which service
|
||||
*/
|
||||
bool RegisterResourceService(BS_ResourceService* pService);
|
||||
bool RegisterResourceService(BS_ResourceService *pService);
|
||||
|
||||
/**
|
||||
* Releases all resources that are not locked.
|
||||
|
@ -92,7 +94,9 @@ public:
|
|||
/**
|
||||
* Returns the maximum memory the kernel has used
|
||||
*/
|
||||
int GetMaxMemoryUsage() const { return m_MaxMemoryUsage; }
|
||||
int GetMaxMemoryUsage() const {
|
||||
return m_MaxMemoryUsage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the maximum amount of memory the engine is allowed to use.
|
||||
|
@ -106,13 +110,17 @@ public:
|
|||
* Specifies whether a warning is written to the log when a cache miss occurs.
|
||||
* THe default value is "false".
|
||||
*/
|
||||
bool IsLogCacheMiss() const { return m_LogCacheMiss; }
|
||||
bool IsLogCacheMiss() const {
|
||||
return m_LogCacheMiss;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether warnings are written to the log if a cache miss occurs.
|
||||
* @param Flag If "true", then future warnings will be logged
|
||||
* @param Flag If "true", then future warnings will be logged
|
||||
*/
|
||||
void SetLogCacheMiss(bool Flag) { m_LogCacheMiss = Flag; }
|
||||
void SetLogCacheMiss(bool Flag) {
|
||||
m_LogCacheMiss = Flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the names of all currently locked resources to the log file
|
||||
|
@ -124,21 +132,20 @@ private:
|
|||
* Creates a new resource manager
|
||||
* Only the BS_Kernel class can generate copies this class. Thus, the constructor is private
|
||||
*/
|
||||
BS_ResourceManager(BS_Kernel* pKernel) :
|
||||
BS_ResourceManager(BS_Kernel *pKernel) :
|
||||
m_KernelPtr(pKernel),
|
||||
m_MaxMemoryUsage(100000000),
|
||||
m_LogCacheMiss(false)
|
||||
{};
|
||||
virtual ~BS_ResourceManager();
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
enum {
|
||||
HASH_TABLE_BUCKETS = 256
|
||||
};
|
||||
|
||||
/**
|
||||
* Moves a resource to the top of the resource list
|
||||
* @param pResource The resource
|
||||
* @param pResource The resource
|
||||
*/
|
||||
void MoveToFront(BS_Resource *pResource);
|
||||
|
||||
|
@ -146,7 +153,7 @@ private:
|
|||
* Loads a resource and updates the m_UsedMemory total
|
||||
*
|
||||
* The resource must not already be loaded
|
||||
* @param FileName The unique filename of the resource to be loaded
|
||||
* @param FileName The unique filename of the resource to be loaded
|
||||
*/
|
||||
BS_Resource *LoadResource(const Common::String &FileName);
|
||||
|
||||
|
@ -159,11 +166,11 @@ private:
|
|||
/**
|
||||
* Deletes a resource, removes it from the lists, and updates m_UsedMemory
|
||||
*/
|
||||
Common::List<BS_Resource*>::iterator DeleteResource(BS_Resource *pResource);
|
||||
Common::List<BS_Resource *>::iterator DeleteResource(BS_Resource *pResource);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
|
||||
* @param UniqueFileName The absolute path and filename
|
||||
* @param UniqueFileName The absolute path and filename
|
||||
* Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
|
||||
*/
|
||||
BS_Resource *GetResource(const Common::String &UniqueFileName) const;
|
||||
|
@ -173,12 +180,12 @@ private:
|
|||
*/
|
||||
void DeleteResourcesIfNecessary();
|
||||
|
||||
BS_Kernel * m_KernelPtr;
|
||||
unsigned int m_MaxMemoryUsage;
|
||||
Common::Array<BS_ResourceService *> m_ResourceServices;
|
||||
Common::List<BS_Resource *> m_Resources;
|
||||
Common::List<BS_Resource *> m_ResourceHashTable[HASH_TABLE_BUCKETS];
|
||||
bool m_LogCacheMiss;
|
||||
BS_Kernel *m_KernelPtr;
|
||||
unsigned int m_MaxMemoryUsage;
|
||||
Common::Array<BS_ResourceService *> m_ResourceServices;
|
||||
Common::List<BS_Resource *> m_Resources;
|
||||
Common::List<BS_Resource *> m_ResourceHashTable[HASH_TABLE_BUCKETS];
|
||||
bool m_LogCacheMiss;
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -42,8 +42,8 @@ namespace Sword25 {
|
|||
#define BS_LOG_PREFIX "RESOURCE"
|
||||
|
||||
BS_Resource::BS_Resource(const Common::String &FileName, RESOURCE_TYPES Type) :
|
||||
_Type(Type),
|
||||
_RefCount(0) {
|
||||
_Type(Type),
|
||||
_RefCount(0) {
|
||||
BS_ASSERT(BS_Kernel::GetInstance()->GetService("package"));
|
||||
|
||||
_FileName = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"))->GetAbsolutePath(FileName);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -45,7 +45,7 @@ class BS_Kernel;
|
|||
class BS_ResourceManager;
|
||||
|
||||
class BS_Resource {
|
||||
friend class BS_ResourceManager;
|
||||
friend class BS_ResourceManager;
|
||||
|
||||
public:
|
||||
enum RESOURCE_TYPES {
|
||||
|
@ -60,47 +60,57 @@ public:
|
|||
|
||||
/**
|
||||
* Prevents the resource from being released.
|
||||
* @remarks This method allows a resource to be locked multiple times.
|
||||
* @remarks This method allows a resource to be locked multiple times.
|
||||
**/
|
||||
void AddReference() { ++_RefCount; }
|
||||
void AddReference() {
|
||||
++_RefCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a previous lock
|
||||
* @remarks The resource can still be released more times than it was 'locked', although it is
|
||||
* @remarks The resource can still be released more times than it was 'locked', although it is
|
||||
* not recommended.
|
||||
**/
|
||||
void Release();
|
||||
|
||||
/**
|
||||
* Returns the current lock count for the resource
|
||||
* @return The current lock count
|
||||
* @return The current lock count
|
||||
**/
|
||||
int GetLockCount() const { return _RefCount; }
|
||||
int GetLockCount() const {
|
||||
return _RefCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute path of the given resource
|
||||
*/
|
||||
const Common::String &GetFileName() const { return _FileName; }
|
||||
const Common::String &GetFileName() const {
|
||||
return _FileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash of the filename of a resource
|
||||
*/
|
||||
unsigned int GetFileNameHash() const { return _FileNameHash; }
|
||||
unsigned int GetFileNameHash() const {
|
||||
return _FileNameHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a resource's type
|
||||
*/
|
||||
unsigned int GetType() const { return _Type; }
|
||||
unsigned int GetType() const {
|
||||
return _Type;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~BS_Resource() {};
|
||||
|
||||
private:
|
||||
Common::String _FileName; ///< The absolute filename
|
||||
unsigned int _FileNameHash; ///< The hash value of the filename
|
||||
unsigned int _RefCount; ///< The number of locks
|
||||
unsigned int _Type; ///< The type of the resource
|
||||
Common::List<BS_Resource *>::iterator _Iterator; ///< Points to the resource position in the LRU list
|
||||
Common::String _FileName; ///< The absolute filename
|
||||
unsigned int _FileNameHash; ///< The hash value of the filename
|
||||
unsigned int _RefCount; ///< The number of locks
|
||||
unsigned int _Type; ///< The type of the resource
|
||||
Common::List<BS_Resource *>::iterator _Iterator; ///< Points to the resource position in the LRU list
|
||||
};
|
||||
|
||||
} // End of namespace Sword25
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -47,9 +47,8 @@ class BS_Resource;
|
|||
|
||||
class BS_ResourceService : public BS_Service {
|
||||
public:
|
||||
BS_ResourceService(BS_Kernel* pKernel) : BS_Service(pKernel)
|
||||
{
|
||||
BS_ResourceManager* pResource = pKernel->GetResourceManager();
|
||||
BS_ResourceService(BS_Kernel *pKernel) : BS_Service(pKernel) {
|
||||
BS_ResourceManager *pResource = pKernel->GetResourceManager();
|
||||
pResource->RegisterResourceService(this);
|
||||
}
|
||||
|
||||
|
@ -58,25 +57,25 @@ public:
|
|||
|
||||
/**
|
||||
* Loads a resource
|
||||
* @return Returns the resource if successful, otherwise NULL
|
||||
* @return Returns the resource if successful, otherwise NULL
|
||||
*/
|
||||
virtual BS_Resource *LoadResource(const Common::String &FileName) = 0;
|
||||
|
||||
/**
|
||||
* Checks whether the given name can be loaded by the resource service
|
||||
* @param FileName Dateiname
|
||||
* @return Returns true if the resource can be loaded.
|
||||
* @param FileName Dateiname
|
||||
* @return Returns true if the resource can be loaded.
|
||||
*/
|
||||
virtual bool CanLoadResource(const Common::String& FileName) = 0;
|
||||
virtual bool CanLoadResource(const Common::String &FileName) = 0;
|
||||
|
||||
protected:
|
||||
// Alternative methods for classes BS_ResourceService
|
||||
|
||||
/**
|
||||
* Compares two strings, with the second string allowed to contain '*' and '?' wildcards
|
||||
* @param String The first comparison string. This must not contain wildcards
|
||||
* @param Pattern The sceond comaprison string. Wildcards of '*' and '?' are allowed.
|
||||
* @return Returns true if the string matches the pattern, otherwise false.
|
||||
* @param String The first comparison string. This must not contain wildcards
|
||||
* @param Pattern The sceond comaprison string. Wildcards of '*' and '?' are allowed.
|
||||
* @return Returns true if the string matches the pattern, otherwise false.
|
||||
*/
|
||||
bool _WildCardStringMatch(const Common::String &String, const Common::String &Pattern) {
|
||||
return _WildCardStringMatchRecursion(String.c_str(), Pattern.c_str());
|
||||
|
@ -89,18 +88,20 @@ private:
|
|||
if (*Pattern == '*') {
|
||||
// Use a copy of the pattern pointer so as not to destroy the current state
|
||||
const char *PatternCopy = Pattern;
|
||||
while (*PatternCopy == '*') { PatternCopy++; }
|
||||
while (*PatternCopy == '*') {
|
||||
PatternCopy++;
|
||||
}
|
||||
if (!*PatternCopy) return true;
|
||||
}
|
||||
// 2. The string is over, but the patern is not -> FALSE
|
||||
if (!*String && *Pattern) return false;
|
||||
// 3. The string is over, and the pattern is finished -> TRUE
|
||||
if (!*String) return true;
|
||||
|
||||
|
||||
// Recursive check 1:
|
||||
// If the two current characters are the same, or pattern '?', then keep scanning
|
||||
if (*String == *Pattern || *Pattern == '?') return _WildCardStringMatchRecursion(String + 1, Pattern + 1);
|
||||
|
||||
|
||||
// Falls nicht, wird untersucht ob ein '*' vorliegt
|
||||
if (*Pattern == '*') {
|
||||
// Recursive check 2:
|
||||
|
@ -111,7 +112,7 @@ private:
|
|||
// The recursion ends, therefore, keep returning to this place until a character
|
||||
// in the string which corresponds to the '*' in pattern
|
||||
}
|
||||
|
||||
|
||||
// The match has failed
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* This code is based on Broken Sword 2.5 engine
|
||||
*
|
||||
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
||||
|
@ -45,7 +45,7 @@ namespace Sword25 {
|
|||
|
||||
bool BS_ScummVMWindow::_ClassRegistered = false;
|
||||
|
||||
// Constructor / Destructor
|
||||
// Constructor / Destructor
|
||||
// ------------------------
|
||||
BS_ScummVMWindow::BS_ScummVMWindow(int X, int Y, int Width, int Height, bool Visible) {
|
||||
// Presume that init will fail
|
||||
|
@ -163,133 +163,133 @@ bool BS_ScummVMWindow::WaitForFocus() {
|
|||
// Die WindowProc aller Fenster der Klasse
|
||||
LRESULT CALLBACK BS_ScummVMWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_PAINT:
|
||||
ValidateRect(hwnd, NULL);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
// Das Fenster wird zerstört
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_PAINT:
|
||||
ValidateRect(hwnd, NULL);
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
{
|
||||
BS_Window * WindowPtr = BS_Kernel::GetInstance()->GetWindow();
|
||||
if (WindowPtr) {
|
||||
WindowPtr->SetCloseWanted(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_DESTROY:
|
||||
// Das Fenster wird zerstört
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
// Tastendrücke, die für das Inputmodul interessant sind, werden diesem gemeldet.
|
||||
BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
|
||||
case WM_CLOSE:
|
||||
{
|
||||
BS_Window * WindowPtr = BS_Kernel::GetInstance()->GetWindow();
|
||||
if (WindowPtr) {
|
||||
WindowPtr->SetCloseWanted(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (InputPtr)
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_RETURN:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_ENTER);
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
{
|
||||
// Tastendrücke, die für das Inputmodul interessant sind, werden diesem gemeldet.
|
||||
BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
|
||||
|
||||
case VK_LEFT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_LEFT);
|
||||
break;
|
||||
if (InputPtr)
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case VK_RETURN:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_ENTER);
|
||||
break;
|
||||
|
||||
case VK_RIGHT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_RIGHT);
|
||||
break;
|
||||
case VK_LEFT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_LEFT);
|
||||
break;
|
||||
|
||||
case VK_HOME:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_HOME);
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_RIGHT);
|
||||
break;
|
||||
|
||||
case VK_END:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_END);
|
||||
break;
|
||||
case VK_HOME:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_HOME);
|
||||
break;
|
||||
|
||||
case VK_BACK:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_BACKSPACE);
|
||||
break;
|
||||
case VK_END:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_END);
|
||||
break;
|
||||
|
||||
case VK_TAB:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_TAB);
|
||||
break;
|
||||
case VK_BACK:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_BACKSPACE);
|
||||
break;
|
||||
|
||||
case VK_INSERT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_INSERT);
|
||||
break;
|
||||
case VK_TAB:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_TAB);
|
||||
break;
|
||||
|
||||
case VK_DELETE:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_DELETE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VK_INSERT:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_INSERT);
|
||||
break;
|
||||
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
// Alle Tastendrücke werden ignoriert, damit Windows per DefWindowProc() nicht darauf
|
||||
// reagieren kann und damit unerwartete Seiteneffekte auslöst.
|
||||
// Zum Beispiel würden ALT und F10 Tastendrücke das "Menü" aktivieren und somit den Message-Loop zum Stillstand bringen.
|
||||
break;
|
||||
case VK_DELETE:
|
||||
InputPtr->ReportCommand(BS_InputEngine::KEY_COMMAND_DELETE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SYSCOMMAND:
|
||||
// Verhindern, dass der Bildschirmschoner aktiviert wird, während das Spiel läuft
|
||||
if (wParam != SC_SCREENSAVE) return DefWindowProc(hwnd,uMsg,wParam,lParam);
|
||||
break;
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
// Alle Tastendrücke werden ignoriert, damit Windows per DefWindowProc() nicht darauf
|
||||
// reagieren kann und damit unerwartete Seiteneffekte auslöst.
|
||||
// Zum Beispiel würden ALT und F10 Tastendrücke das "Menü" aktivieren und somit den Message-Loop zum Stillstand bringen.
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
{
|
||||
unsigned char theChar = static_cast<unsigned char>(wParam & 0xff);
|
||||
case WM_SYSCOMMAND:
|
||||
// Verhindern, dass der Bildschirmschoner aktiviert wird, während das Spiel läuft
|
||||
if (wParam != SC_SCREENSAVE) return DefWindowProc(hwnd,uMsg,wParam,lParam);
|
||||
break;
|
||||
|
||||
// Alle Zeichen, die keine Steuerzeichen sind, werden als Buchstaben dem Input-Service mitgeteilt.
|
||||
if (theChar >= 32)
|
||||
{
|
||||
BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
|
||||
if (InputPtr) InputPtr->ReportCharacter(theChar);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
{
|
||||
unsigned char theChar = static_cast<unsigned char>(wParam & 0xff);
|
||||
|
||||
case WM_SETCURSOR:
|
||||
{
|
||||
// Der Systemcursor wird in der Client-Area des Fensters nicht angezeigt, jedoch in der nicht Client-Area, damit der Benutzer das Fenster wie gewohnt
|
||||
// schließen und verschieben kann.
|
||||
// Alle Zeichen, die keine Steuerzeichen sind, werden als Buchstaben dem Input-Service mitgeteilt.
|
||||
if (theChar >= 32)
|
||||
{
|
||||
BS_InputEngine * InputPtr = BS_Kernel::GetInstance()->GetInput();
|
||||
if (InputPtr) InputPtr->ReportCharacter(theChar);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// Koordinaten des Cursors in der Client-Area berechnen.
|
||||
POINT pt;
|
||||
GetCursorPos(&pt);
|
||||
ScreenToClient(hwnd, &pt);
|
||||
case WM_SETCURSOR:
|
||||
{
|
||||
// Der Systemcursor wird in der Client-Area des Fensters nicht angezeigt, jedoch in der nicht Client-Area, damit der Benutzer das Fenster wie gewohnt
|
||||
// schließen und verschieben kann.
|
||||
|
||||
// Feststellen, ob sich der Cursor in der Client-Area befindet.
|
||||
// Get client rect
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
// Koordinaten des Cursors in der Client-Area berechnen.
|
||||
POINT pt;
|
||||
GetCursorPos(&pt);
|
||||
ScreenToClient(hwnd, &pt);
|
||||
|
||||
// See if cursor is in client area
|
||||
if(PtInRect(&rc, pt))
|
||||
// In der Client-Area keinen Cursor anzeigen.
|
||||
SetCursor(NULL);
|
||||
else
|
||||
// Ausserhalb der Client-Area den Cursor anzeigen.
|
||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
// Feststellen, ob sich der Cursor in der Client-Area befindet.
|
||||
// Get client rect
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
// See if cursor is in client area
|
||||
if(PtInRect(&rc, pt))
|
||||
// In der Client-Area keinen Cursor anzeigen.
|
||||
SetCursor(NULL);
|
||||
else
|
||||
// Ausserhalb der Client-Area den Cursor anzeigen.
|
||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
|
||||
default:
|
||||
// Um alle anderen Vorkommnisse kümmert sich Windows
|
||||
return DefWindowProc(hwnd,uMsg,wParam,lParam);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
return 0;
|
||||
default:
|
||||
// Um alle anderen Vorkommnisse kümmert sich Windows
|
||||
return DefWindowProc(hwnd,uMsg,wParam,lParam);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue