Apply LF line endings as an SVN property, this time on the JGE source files.
This commit is contained in:
+59
-59
@@ -1,59 +1,59 @@
|
||||
#ifndef DEBUGROUTINES_H
|
||||
#define DEBUGROUTINES_H
|
||||
|
||||
// dirty, but I get OS header includes this way
|
||||
#include "JGE.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#ifdef _DEBUG
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
std::string ToHex(T* pointer)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << std::hex << showbase << setfill('0') << setw(8) << (int) pointer;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
|
||||
#ifndef QT_CONFIG
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
OutputDebugString(stream.str().c_str()); \
|
||||
}
|
||||
#else
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
qDebug(stream.str().c_str()); \
|
||||
}
|
||||
#endif //QT_CONFIG
|
||||
|
||||
#endif //#ifdef _DEBUG
|
||||
#endif // Win32, Linux
|
||||
|
||||
#if defined (IOS) && defined (DEBUG)
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::cout << inString << std::endl; \
|
||||
}
|
||||
#endif // IOS, DEBUG
|
||||
|
||||
|
||||
#ifndef DebugTrace
|
||||
#define DebugTrace(inString) (void (0))
|
||||
#endif
|
||||
|
||||
#endif // DEBUGROUTINES_H
|
||||
#ifndef DEBUGROUTINES_H
|
||||
#define DEBUGROUTINES_H
|
||||
|
||||
// dirty, but I get OS header includes this way
|
||||
#include "JGE.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#ifdef _DEBUG
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
std::string ToHex(T* pointer)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << std::hex << showbase << setfill('0') << setw(8) << (int) pointer;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
|
||||
#ifndef QT_CONFIG
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
OutputDebugString(stream.str().c_str()); \
|
||||
}
|
||||
#else
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::ostringstream stream; \
|
||||
stream << inString << std::endl; \
|
||||
qDebug(stream.str().c_str()); \
|
||||
}
|
||||
#endif //QT_CONFIG
|
||||
|
||||
#endif //#ifdef _DEBUG
|
||||
#endif // Win32, Linux
|
||||
|
||||
#if defined (IOS) && defined (DEBUG)
|
||||
#define DebugTrace(inString) \
|
||||
{ \
|
||||
std::cout << inString << std::endl; \
|
||||
}
|
||||
#endif // IOS, DEBUG
|
||||
|
||||
|
||||
#ifndef DebugTrace
|
||||
#define DebugTrace(inString) (void (0))
|
||||
#endif
|
||||
|
||||
#endif // DEBUGROUTINES_H
|
||||
|
||||
+20
-20
@@ -1,20 +1,20 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _ENCODING_H
|
||||
#define _ENCODING_H
|
||||
|
||||
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
|
||||
u16 charsets_gbk_to_ucs(const u8 * cjk);
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _ENCODING_H
|
||||
#define _ENCODING_H
|
||||
|
||||
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
|
||||
u16 charsets_gbk_to_ucs(const u8 * cjk);
|
||||
|
||||
#endif
|
||||
|
||||
+414
-414
@@ -1,414 +1,414 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JANIMATOR_H_
|
||||
#define _JANIMATOR_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class JResourceManager;
|
||||
class JQuad;
|
||||
class JAnimatorFrame;
|
||||
class JAnimatorObject;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A frame based animation system. The animation frames and play sequence
|
||||
/// are loaded from a XML file.
|
||||
///
|
||||
/// A sample animation script:
|
||||
///
|
||||
/// @code
|
||||
/// <?xml version="1.0" standalone="no" ?>
|
||||
///
|
||||
/// <script name="abc" type="ANIMATION_TYPE_ONCE_AND_STAY" framerate="20">
|
||||
/// @endcode
|
||||
///
|
||||
/// "type" can be ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY,
|
||||
/// ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE or
|
||||
/// ANIMATION_TYPE_PINGPONG
|
||||
///
|
||||
/// "framerate" is the rate of playback in frames per seconds.
|
||||
///
|
||||
/// @code
|
||||
/// <frame id="1">
|
||||
/// <obj name="head">
|
||||
/// <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" />
|
||||
/// </obj>
|
||||
/// <obj name="body">
|
||||
/// <settings quad="body" />
|
||||
/// </obj>
|
||||
/// </frame>
|
||||
/// @endcode
|
||||
///
|
||||
/// Each frame contains one or more frame objects. Each object is a quad with various
|
||||
/// settings. "quad" is the name of the quad. "x" and "y" is the position. "hsize" is
|
||||
/// the horizontal scaling and "vsize" is the vertical scaling. "rotation" is the angle
|
||||
/// that the quad will be rotated in radians. You can also specify the color and alpha
|
||||
/// of the quad with the "r", "g", "b" and "a" parameters.
|
||||
///
|
||||
/// @code
|
||||
/// <frame id="2" time="0.20">
|
||||
/// <obj name="head">
|
||||
/// <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" />
|
||||
/// </obj>
|
||||
/// <obj name="body">
|
||||
/// <settings quad="body" a="128" />
|
||||
/// </obj>
|
||||
/// </frame>
|
||||
///
|
||||
///
|
||||
/// </script>
|
||||
/// @endcode
|
||||
///
|
||||
/// A frame can also overide the global frame rate by using the "time" parameter (in second)
|
||||
/// as shown above.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimator
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param resourceMgr - ResourceManager to look for images (JQuads)
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimator(JResourceManager* resourceMgr);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimator();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load animation sequence from a script file.
|
||||
///
|
||||
/// @param scriptFile - Animation script.
|
||||
///
|
||||
/// @return True if no problem during loading. False otherwise.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char* scriptFile);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Stop();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Pause animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Pause();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Resume();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if animation is playing or not.
|
||||
///
|
||||
/// @return True if playing animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsAnimating();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the animation is active.
|
||||
///
|
||||
/// @return True if active.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
JResourceManager* GetResourceManager();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set current frame to a particular index.
|
||||
///
|
||||
/// @param index - The new index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCurrentFrameIndex(int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get index of current frame.
|
||||
///
|
||||
/// @return Index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetCurrentFrameIndex();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set animation type.
|
||||
///
|
||||
/// @param type - Animation type.
|
||||
///
|
||||
/// @code
|
||||
/// JSprite::ANIMATION_TYPE_LOOPING - Default
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_GONE
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_STAY
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_BACK
|
||||
/// JSprite::ANIMATION_TYPE_PINGPONG
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationType(int type);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set anchor point of the animation. All rendering operations will be
|
||||
/// based on this anchor point.
|
||||
///
|
||||
/// @param x - X position of the anchor point.
|
||||
/// @param y - Y position of the anchor point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHotSpot(float x, float y);
|
||||
|
||||
private:
|
||||
JResourceManager* mResource;
|
||||
vector<JAnimatorFrame *> mFrames;
|
||||
|
||||
bool mAnimating;
|
||||
bool mActive;
|
||||
int mCurrentFrame;
|
||||
int mAnimationType;
|
||||
int mFrameDelta;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
float mHotSpotX;
|
||||
float mHotSpotY;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A single frame of an animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimatorFrame
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param parent - Parent of the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorFrame(JAnimator* parent);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimatorFrame();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add a new object into the frame.
|
||||
///
|
||||
/// @param obj - New animation object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddObject(JAnimatorObject *obj);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set play time of the frame.
|
||||
///
|
||||
/// @param duration - Time to play (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFrameTime(float duration);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Frame update.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
/// @return True if the frame is done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render frame.
|
||||
///
|
||||
/// @param x - X position for rendering.
|
||||
/// @param y - Y position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start playing the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
|
||||
private:
|
||||
float mTimer;
|
||||
float mFrameTime;
|
||||
JAnimator* mAnimator;
|
||||
vector<JAnimatorObject *> mObjects;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Animation object (image quad) in a frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimatorObject
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimatorObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update object.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render object.
|
||||
///
|
||||
/// @param x - X position for rendering.
|
||||
/// @param y - Y position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set something to show.
|
||||
///
|
||||
/// @param quad - Image quad.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the object.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rotation factor of the object.
|
||||
///
|
||||
/// @param angle - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set horizontal scale of the object.
|
||||
///
|
||||
/// @param scale - Horizontal scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set vertical scale of the object.
|
||||
///
|
||||
/// @param scale - Vertical scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blending color of the object.
|
||||
///
|
||||
/// @param color - Blending color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set horizontal flipping.
|
||||
///
|
||||
/// @param flag - flipping flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFlip(bool flag);
|
||||
|
||||
private:
|
||||
JRenderer* mRenderer;
|
||||
JQuad* mQuad;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
float mRotation;
|
||||
float mHScale;
|
||||
float mVScale;
|
||||
PIXEL_TYPE mColor;
|
||||
bool mFlipped;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JANIMATOR_H_
|
||||
#define _JANIMATOR_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class JResourceManager;
|
||||
class JQuad;
|
||||
class JAnimatorFrame;
|
||||
class JAnimatorObject;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A frame based animation system. The animation frames and play sequence
|
||||
/// are loaded from a XML file.
|
||||
///
|
||||
/// A sample animation script:
|
||||
///
|
||||
/// @code
|
||||
/// <?xml version="1.0" standalone="no" ?>
|
||||
///
|
||||
/// <script name="abc" type="ANIMATION_TYPE_ONCE_AND_STAY" framerate="20">
|
||||
/// @endcode
|
||||
///
|
||||
/// "type" can be ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY,
|
||||
/// ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE or
|
||||
/// ANIMATION_TYPE_PINGPONG
|
||||
///
|
||||
/// "framerate" is the rate of playback in frames per seconds.
|
||||
///
|
||||
/// @code
|
||||
/// <frame id="1">
|
||||
/// <obj name="head">
|
||||
/// <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" />
|
||||
/// </obj>
|
||||
/// <obj name="body">
|
||||
/// <settings quad="body" />
|
||||
/// </obj>
|
||||
/// </frame>
|
||||
/// @endcode
|
||||
///
|
||||
/// Each frame contains one or more frame objects. Each object is a quad with various
|
||||
/// settings. "quad" is the name of the quad. "x" and "y" is the position. "hsize" is
|
||||
/// the horizontal scaling and "vsize" is the vertical scaling. "rotation" is the angle
|
||||
/// that the quad will be rotated in radians. You can also specify the color and alpha
|
||||
/// of the quad with the "r", "g", "b" and "a" parameters.
|
||||
///
|
||||
/// @code
|
||||
/// <frame id="2" time="0.20">
|
||||
/// <obj name="head">
|
||||
/// <settings quad="head" x="10" y="10" hsize="1.0" vsize="1.0" rotation="0.0" r="255" g="255" b="255" a="255" />
|
||||
/// </obj>
|
||||
/// <obj name="body">
|
||||
/// <settings quad="body" a="128" />
|
||||
/// </obj>
|
||||
/// </frame>
|
||||
///
|
||||
///
|
||||
/// </script>
|
||||
/// @endcode
|
||||
///
|
||||
/// A frame can also overide the global frame rate by using the "time" parameter (in second)
|
||||
/// as shown above.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimator
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param resourceMgr - ResourceManager to look for images (JQuads)
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimator(JResourceManager* resourceMgr);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimator();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load animation sequence from a script file.
|
||||
///
|
||||
/// @param scriptFile - Animation script.
|
||||
///
|
||||
/// @return True if no problem during loading. False otherwise.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char* scriptFile);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Stop();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Pause animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Pause();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Resume();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if animation is playing or not.
|
||||
///
|
||||
/// @return True if playing animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsAnimating();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the animation is active.
|
||||
///
|
||||
/// @return True if active.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
JResourceManager* GetResourceManager();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set current frame to a particular index.
|
||||
///
|
||||
/// @param index - The new index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCurrentFrameIndex(int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get index of current frame.
|
||||
///
|
||||
/// @return Index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetCurrentFrameIndex();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set animation type.
|
||||
///
|
||||
/// @param type - Animation type.
|
||||
///
|
||||
/// @code
|
||||
/// JSprite::ANIMATION_TYPE_LOOPING - Default
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_GONE
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_STAY
|
||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_BACK
|
||||
/// JSprite::ANIMATION_TYPE_PINGPONG
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationType(int type);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set anchor point of the animation. All rendering operations will be
|
||||
/// based on this anchor point.
|
||||
///
|
||||
/// @param x - X position of the anchor point.
|
||||
/// @param y - Y position of the anchor point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHotSpot(float x, float y);
|
||||
|
||||
private:
|
||||
JResourceManager* mResource;
|
||||
vector<JAnimatorFrame *> mFrames;
|
||||
|
||||
bool mAnimating;
|
||||
bool mActive;
|
||||
int mCurrentFrame;
|
||||
int mAnimationType;
|
||||
int mFrameDelta;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
float mHotSpotX;
|
||||
float mHotSpotY;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A single frame of an animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimatorFrame
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param parent - Parent of the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorFrame(JAnimator* parent);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimatorFrame();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add a new object into the frame.
|
||||
///
|
||||
/// @param obj - New animation object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddObject(JAnimatorObject *obj);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set play time of the frame.
|
||||
///
|
||||
/// @param duration - Time to play (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFrameTime(float duration);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Frame update.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
/// @return True if the frame is done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render frame.
|
||||
///
|
||||
/// @param x - X position for rendering.
|
||||
/// @param y - Y position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start playing the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
|
||||
private:
|
||||
float mTimer;
|
||||
float mFrameTime;
|
||||
JAnimator* mAnimator;
|
||||
vector<JAnimatorObject *> mObjects;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Animation object (image quad) in a frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JAnimatorObject
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Destructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~JAnimatorObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update object.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render object.
|
||||
///
|
||||
/// @param x - X position for rendering.
|
||||
/// @param y - Y position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set something to show.
|
||||
///
|
||||
/// @param quad - Image quad.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the object.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rotation factor of the object.
|
||||
///
|
||||
/// @param angle - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set horizontal scale of the object.
|
||||
///
|
||||
/// @param scale - Horizontal scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set vertical scale of the object.
|
||||
///
|
||||
/// @param scale - Vertical scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blending color of the object.
|
||||
///
|
||||
/// @param color - Blending color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set horizontal flipping.
|
||||
///
|
||||
/// @param flag - flipping flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFlip(bool flag);
|
||||
|
||||
private:
|
||||
JRenderer* mRenderer;
|
||||
JQuad* mQuad;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
float mRotation;
|
||||
float mHScale;
|
||||
float mVScale;
|
||||
PIXEL_TYPE mColor;
|
||||
bool mFlipped;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+88
-88
@@ -1,88 +1,88 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JAPP_H_
|
||||
#define _JAPP_H_
|
||||
|
||||
class JGE;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Main application class for the system to run. The core game class
|
||||
/// should be derived from this base class.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JApp
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
JApp();
|
||||
virtual ~JApp();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Initialization function.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Create() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Cleanup function before exiting from the game.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update function to be called for each frame update. Should perform
|
||||
/// all the game logic here.
|
||||
///
|
||||
/// @par Example: A simple Update() implementation:
|
||||
/// @code
|
||||
/// void Update()
|
||||
/// {
|
||||
/// float dt = JGE::GetInstance()->GetDelta();
|
||||
/// mX += mSpeed*dt;
|
||||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render function to be called for each frame update. Should do all the
|
||||
/// game rendering here.
|
||||
///
|
||||
/// @par Example: A simple Render() implementation:
|
||||
/// @code
|
||||
/// void Render()
|
||||
/// {
|
||||
/// JRenderer *r = JRenderer::GetInstance();
|
||||
/// r->FillRect(0,0,480,272,ARGB(255,0,0,0));
|
||||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Callback function called when the game is paused by the system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Pause() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Callback function called when the game is resumed by the system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Resume() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JAPP_H_
|
||||
#define _JAPP_H_
|
||||
|
||||
class JGE;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Main application class for the system to run. The core game class
|
||||
/// should be derived from this base class.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JApp
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
JApp();
|
||||
virtual ~JApp();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Initialization function.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Create() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Cleanup function before exiting from the game.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update function to be called for each frame update. Should perform
|
||||
/// all the game logic here.
|
||||
///
|
||||
/// @par Example: A simple Update() implementation:
|
||||
/// @code
|
||||
/// void Update()
|
||||
/// {
|
||||
/// float dt = JGE::GetInstance()->GetDelta();
|
||||
/// mX += mSpeed*dt;
|
||||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render function to be called for each frame update. Should do all the
|
||||
/// game rendering here.
|
||||
///
|
||||
/// @par Example: A simple Render() implementation:
|
||||
/// @code
|
||||
/// void Render()
|
||||
/// {
|
||||
/// JRenderer *r = JRenderer::GetInstance();
|
||||
/// r->FillRect(0,0,480,272,ARGB(255,0,0,0));
|
||||
/// }
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Callback function called when the game is paused by the system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Pause() = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Callback function called when the game is resumed by the system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Resume() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+62
-62
@@ -1,62 +1,62 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
// Copyright (c) 2007 Cooleyes
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _COOLEYES_MP3_
|
||||
#define _COOLEYES_MP3_
|
||||
|
||||
|
||||
#define FORCE_BUFFER_ALIGNMENT
|
||||
|
||||
class JCooleyesMP3
|
||||
{
|
||||
public:
|
||||
JCooleyesMP3();
|
||||
~JCooleyesMP3();
|
||||
|
||||
bool Load(const char* filename);
|
||||
void Release();
|
||||
bool Play(bool looping = false);
|
||||
void Stop();
|
||||
void Resume();
|
||||
void FeedAudioData(void* buf, unsigned int length/*, bool mixing = false*/);
|
||||
void Decode();
|
||||
bool IsPlaying();
|
||||
|
||||
void InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer);
|
||||
|
||||
public:
|
||||
bool mPlaying;
|
||||
SceUID mp3_handle;
|
||||
u8* mFileBuffer;
|
||||
u8* mMP3FirstFramePointer;
|
||||
int mFileSize;
|
||||
int mUpdateCounter;
|
||||
u8* mCurrFramePointer;
|
||||
int mDataPointer;
|
||||
int mSamplesPending;
|
||||
bool mAllMP3DataProcessed;
|
||||
|
||||
bool mLooping;
|
||||
|
||||
u32 mSamplePerFrame;
|
||||
u32 mChannelCount;
|
||||
u32 mSampleRate;
|
||||
|
||||
int mOutputBufferIndex;
|
||||
|
||||
short *mDecoderBuffer;
|
||||
short *mDecodedDataOutputBuffer;
|
||||
unsigned long *mMP3CodecBuffer;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
// Copyright (c) 2007 Cooleyes
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _COOLEYES_MP3_
|
||||
#define _COOLEYES_MP3_
|
||||
|
||||
|
||||
#define FORCE_BUFFER_ALIGNMENT
|
||||
|
||||
class JCooleyesMP3
|
||||
{
|
||||
public:
|
||||
JCooleyesMP3();
|
||||
~JCooleyesMP3();
|
||||
|
||||
bool Load(const char* filename);
|
||||
void Release();
|
||||
bool Play(bool looping = false);
|
||||
void Stop();
|
||||
void Resume();
|
||||
void FeedAudioData(void* buf, unsigned int length/*, bool mixing = false*/);
|
||||
void Decode();
|
||||
bool IsPlaying();
|
||||
|
||||
void InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer);
|
||||
|
||||
public:
|
||||
bool mPlaying;
|
||||
SceUID mp3_handle;
|
||||
u8* mFileBuffer;
|
||||
u8* mMP3FirstFramePointer;
|
||||
int mFileSize;
|
||||
int mUpdateCounter;
|
||||
u8* mCurrFramePointer;
|
||||
int mDataPointer;
|
||||
int mSamplesPending;
|
||||
bool mAllMP3DataProcessed;
|
||||
|
||||
bool mLooping;
|
||||
|
||||
u32 mSamplePerFrame;
|
||||
u32 mChannelCount;
|
||||
u32 mSampleRate;
|
||||
|
||||
int mOutputBufferIndex;
|
||||
|
||||
short *mDecoderBuffer;
|
||||
short *mDecodedDataOutputBuffer;
|
||||
unsigned long *mMP3CodecBuffer;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
// Note: Inspired by HGE's DistortionMesh.
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JDISTORT_MESH_H
|
||||
#define _JDISTORT_MESH_H
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
class JDistortionMesh
|
||||
{
|
||||
public:
|
||||
JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows);
|
||||
~JDistortionMesh();
|
||||
|
||||
void Render(float x, float y);
|
||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||
void SetDisplacement(int col, int row, float dx, float dy);//, int ref);
|
||||
|
||||
private:
|
||||
|
||||
static JRenderer *mRenderer;
|
||||
Vertex* mVertices;
|
||||
int mRows;
|
||||
int mCols;
|
||||
float mCellWidth;
|
||||
float mCellHeight;
|
||||
float mTexX;
|
||||
float mTexY;
|
||||
float mTexWidth;
|
||||
float mTexHeight;
|
||||
JTexture* mTexture;
|
||||
JQuad* mQuad;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
// Note: Inspired by HGE's DistortionMesh.
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JDISTORT_MESH_H
|
||||
#define _JDISTORT_MESH_H
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
class JDistortionMesh
|
||||
{
|
||||
public:
|
||||
JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows);
|
||||
~JDistortionMesh();
|
||||
|
||||
void Render(float x, float y);
|
||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||
void SetDisplacement(int col, int row, float dx, float dy);//, int ref);
|
||||
|
||||
private:
|
||||
|
||||
static JRenderer *mRenderer;
|
||||
Vertex* mVertices;
|
||||
int mRows;
|
||||
int mCols;
|
||||
float mCellWidth;
|
||||
float mCellHeight;
|
||||
float mTexX;
|
||||
float mTexY;
|
||||
float mTexWidth;
|
||||
float mTexHeight;
|
||||
JTexture* mTexture;
|
||||
JQuad* mQuad;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+143
-143
@@ -1,143 +1,143 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _FILE_SYSTEM_H_
|
||||
#define _FILE_SYSTEM_H_
|
||||
|
||||
#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename)
|
||||
#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot()
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||
|
||||
#else
|
||||
#include <pspiofilemgr.h>
|
||||
#include <pspiofilemgr_fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "unzip/unzip.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Interface for low level file access with ZIP archive support. All
|
||||
/// file operations in JGE are handled through this class so if a ZIP
|
||||
/// archive is attached, all the resources will be loaded from the
|
||||
/// archive file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class JZipCache {
|
||||
public:
|
||||
JZipCache();
|
||||
~JZipCache();
|
||||
map<string,unz_file_pos *> dir;
|
||||
|
||||
};
|
||||
|
||||
class JFileSystem
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JFileSystem* GetInstance();
|
||||
|
||||
static void Destroy();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Attach ZIP archive to the file system.
|
||||
///
|
||||
/// @param zipfile - Name of ZIP archive.
|
||||
/// @param password - Password for the ZIP archive. Default is NULL.
|
||||
///
|
||||
/// @return Status of the attach operation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool AttachZipFile(const string &zipfile, char *password = NULL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Release the attached ZIP archive.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void DetachZipFile();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Open file for reading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool OpenFile(const string &filename);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Read data from file.
|
||||
///
|
||||
/// @param buffer - Buffer for reading.
|
||||
/// @param size - Number of bytes to read.
|
||||
///
|
||||
/// @return Number of bytes read.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int ReadFile(void *buffer, int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get size of file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetFileSize();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Close file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CloseFile();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set root for all the following file operations
|
||||
///
|
||||
/// @resourceRoot - New root.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetResourceRoot(const string& resourceRoot);
|
||||
string GetResourceRoot();
|
||||
|
||||
// Returns a string prefixed with the resource path
|
||||
string GetResourceFile(string filename);
|
||||
|
||||
protected:
|
||||
JFileSystem();
|
||||
~JFileSystem();
|
||||
|
||||
private:
|
||||
static JFileSystem* mInstance;
|
||||
|
||||
map<string,JZipCache *>mZipCache;
|
||||
string mResourceRoot;
|
||||
string mZipFileName;
|
||||
char *mPassword;
|
||||
bool mZipAvailable;
|
||||
void preloadZip(string filename);
|
||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||
FILE *mFile;
|
||||
#else
|
||||
SceUID mFile;
|
||||
#endif
|
||||
unzFile mZipFile;
|
||||
int mFileSize;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _FILE_SYSTEM_H_
|
||||
#define _FILE_SYSTEM_H_
|
||||
|
||||
#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename)
|
||||
#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot()
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||
|
||||
#else
|
||||
#include <pspiofilemgr.h>
|
||||
#include <pspiofilemgr_fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "unzip/unzip.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Interface for low level file access with ZIP archive support. All
|
||||
/// file operations in JGE are handled through this class so if a ZIP
|
||||
/// archive is attached, all the resources will be loaded from the
|
||||
/// archive file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class JZipCache {
|
||||
public:
|
||||
JZipCache();
|
||||
~JZipCache();
|
||||
map<string,unz_file_pos *> dir;
|
||||
|
||||
};
|
||||
|
||||
class JFileSystem
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JFileSystem* GetInstance();
|
||||
|
||||
static void Destroy();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Attach ZIP archive to the file system.
|
||||
///
|
||||
/// @param zipfile - Name of ZIP archive.
|
||||
/// @param password - Password for the ZIP archive. Default is NULL.
|
||||
///
|
||||
/// @return Status of the attach operation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool AttachZipFile(const string &zipfile, char *password = NULL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Release the attached ZIP archive.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void DetachZipFile();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Open file for reading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool OpenFile(const string &filename);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Read data from file.
|
||||
///
|
||||
/// @param buffer - Buffer for reading.
|
||||
/// @param size - Number of bytes to read.
|
||||
///
|
||||
/// @return Number of bytes read.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int ReadFile(void *buffer, int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get size of file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetFileSize();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Close file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CloseFile();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set root for all the following file operations
|
||||
///
|
||||
/// @resourceRoot - New root.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetResourceRoot(const string& resourceRoot);
|
||||
string GetResourceRoot();
|
||||
|
||||
// Returns a string prefixed with the resource path
|
||||
string GetResourceFile(string filename);
|
||||
|
||||
protected:
|
||||
JFileSystem();
|
||||
~JFileSystem();
|
||||
|
||||
private:
|
||||
static JFileSystem* mInstance;
|
||||
|
||||
map<string,JZipCache *>mZipCache;
|
||||
string mResourceRoot;
|
||||
string mZipFileName;
|
||||
char *mPassword;
|
||||
bool mZipAvailable;
|
||||
void preloadZip(string filename);
|
||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||
FILE *mFile;
|
||||
#else
|
||||
SceUID mFile;
|
||||
#endif
|
||||
unzFile mZipFile;
|
||||
int mFileSize;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+192
-192
@@ -1,192 +1,192 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JBGK_FONT_H_
|
||||
#define _JBGK_FONT_H_
|
||||
|
||||
|
||||
#include "JTypes.h"
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include "JSprite.h"
|
||||
|
||||
#define BYTE u8
|
||||
#define DWORD u32
|
||||
#define BOOL int
|
||||
|
||||
|
||||
// #define GB_FONT_SIZE 16
|
||||
// #define GB_FONT_DATA_SIZE GB_FONT_SIZE*GB_FONT_SIZE/8
|
||||
// #define GB_FONT_BYTE_COUNT GB_FONT_SIZE/8
|
||||
//
|
||||
#define MAX_CACHE_SIZE 256
|
||||
//
|
||||
// #define CFONT_TEX_WIDTH 256
|
||||
// #define CFONT_TEX_HEIGHT 256
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Chinese bitmap font encoded with GBK encoding. All popurlar font sizes
|
||||
/// are supported and the following have been tested:
|
||||
/// 12x12, 16x16, 18x18, 20x20, 24x24, 28x28 and 32x32.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGBKFont
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGBKFont();
|
||||
|
||||
~JGBKFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Initialization of the font class. You need to provide both a Chinese
|
||||
/// font file and an English one as well.
|
||||
///
|
||||
/// For example:
|
||||
/// @code
|
||||
/// mChineseFont = new JGBKFont();
|
||||
/// mChineseFont->Init("Res/ASC16", "Res/GBK16");
|
||||
/// @endcode
|
||||
///
|
||||
/// @param engFileName - Name of the English font file.
|
||||
/// @param chnFileName - Name of the Chinese font file.
|
||||
/// @param fontsize - Font size.
|
||||
/// @param smallEnglishFont - Indicate to use half width when rendering English characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Init(const char* engFileName, const char* chnFileName, int fontsize=16, bool smallEnglishFont=false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering character into cache.
|
||||
///
|
||||
/// @param ch - Single byte or word of character code.
|
||||
///
|
||||
/// @return Index of the character in cache.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int PreCacheChar(const BYTE *ch);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Scan through the string and look up the index of each character in the
|
||||
/// cache and then return all indexes in an array to be rendered later on.
|
||||
///
|
||||
/// @param str - String to look for cache indexes.
|
||||
/// @return dest - Indexes of characters in cache.
|
||||
/// @return Number of characters processed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int PrepareString(BYTE* str, int* dest);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render string by using the indexes returned from PrepareString.
|
||||
///
|
||||
/// @param text - Cache indexes for rendering.
|
||||
/// @param count - Number of characters to render.
|
||||
/// @param x - X screen position for rendering.
|
||||
/// @param y - Y screen position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderEncodedString(const int* text, int count, float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render string to screen.
|
||||
///
|
||||
/// @param str - String to render.
|
||||
/// @param x - X screen position for rendering.
|
||||
/// @param y - Y screen position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(BYTE* str, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
int GetStringWidth(BYTE* str);
|
||||
int GetStringHeight(BYTE* str);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale for rendering.
|
||||
///
|
||||
/// @param scale - Scale for rendering characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle for rendering.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font color.
|
||||
///
|
||||
/// @param color - color of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set background color.
|
||||
///
|
||||
/// @param color - Background color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBgColor(PIXEL_TYPE color);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
BYTE* mChnFont;
|
||||
BYTE* mEngFont;
|
||||
|
||||
DWORD* mCharBuffer;
|
||||
|
||||
PIXEL_TYPE mColor;
|
||||
PIXEL_TYPE mBgColor;
|
||||
|
||||
int mFontSize;
|
||||
int mBytesPerChar;
|
||||
int mBytesPerRow;
|
||||
|
||||
int mCacheSize;
|
||||
int mCacheImageWidth;
|
||||
int mCacheImageHeight;
|
||||
|
||||
int mCol;
|
||||
int mRow;
|
||||
|
||||
//public:
|
||||
|
||||
JTexture* mTexture;
|
||||
JQuad** mSprites;
|
||||
|
||||
int *mGBCode;
|
||||
|
||||
int mCurr;
|
||||
|
||||
float mScale;
|
||||
float mRotation;
|
||||
|
||||
int mCount;
|
||||
|
||||
bool mSmallEnglishFont;
|
||||
|
||||
void GetStringArea(BYTE* str, int *w, int *h);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JBGK_FONT_H_
|
||||
#define _JBGK_FONT_H_
|
||||
|
||||
|
||||
#include "JTypes.h"
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include "JSprite.h"
|
||||
|
||||
#define BYTE u8
|
||||
#define DWORD u32
|
||||
#define BOOL int
|
||||
|
||||
|
||||
// #define GB_FONT_SIZE 16
|
||||
// #define GB_FONT_DATA_SIZE GB_FONT_SIZE*GB_FONT_SIZE/8
|
||||
// #define GB_FONT_BYTE_COUNT GB_FONT_SIZE/8
|
||||
//
|
||||
#define MAX_CACHE_SIZE 256
|
||||
//
|
||||
// #define CFONT_TEX_WIDTH 256
|
||||
// #define CFONT_TEX_HEIGHT 256
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Chinese bitmap font encoded with GBK encoding. All popurlar font sizes
|
||||
/// are supported and the following have been tested:
|
||||
/// 12x12, 16x16, 18x18, 20x20, 24x24, 28x28 and 32x32.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGBKFont
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGBKFont();
|
||||
|
||||
~JGBKFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Initialization of the font class. You need to provide both a Chinese
|
||||
/// font file and an English one as well.
|
||||
///
|
||||
/// For example:
|
||||
/// @code
|
||||
/// mChineseFont = new JGBKFont();
|
||||
/// mChineseFont->Init("Res/ASC16", "Res/GBK16");
|
||||
/// @endcode
|
||||
///
|
||||
/// @param engFileName - Name of the English font file.
|
||||
/// @param chnFileName - Name of the Chinese font file.
|
||||
/// @param fontsize - Font size.
|
||||
/// @param smallEnglishFont - Indicate to use half width when rendering English characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Init(const char* engFileName, const char* chnFileName, int fontsize=16, bool smallEnglishFont=false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering character into cache.
|
||||
///
|
||||
/// @param ch - Single byte or word of character code.
|
||||
///
|
||||
/// @return Index of the character in cache.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int PreCacheChar(const BYTE *ch);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Scan through the string and look up the index of each character in the
|
||||
/// cache and then return all indexes in an array to be rendered later on.
|
||||
///
|
||||
/// @param str - String to look for cache indexes.
|
||||
/// @return dest - Indexes of characters in cache.
|
||||
/// @return Number of characters processed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int PrepareString(BYTE* str, int* dest);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render string by using the indexes returned from PrepareString.
|
||||
///
|
||||
/// @param text - Cache indexes for rendering.
|
||||
/// @param count - Number of characters to render.
|
||||
/// @param x - X screen position for rendering.
|
||||
/// @param y - Y screen position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderEncodedString(const int* text, int count, float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render string to screen.
|
||||
///
|
||||
/// @param str - String to render.
|
||||
/// @param x - X screen position for rendering.
|
||||
/// @param y - Y screen position for rendering.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(BYTE* str, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
int GetStringWidth(BYTE* str);
|
||||
int GetStringHeight(BYTE* str);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale for rendering.
|
||||
///
|
||||
/// @param scale - Scale for rendering characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle for rendering.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font color.
|
||||
///
|
||||
/// @param color - color of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set background color.
|
||||
///
|
||||
/// @param color - Background color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBgColor(PIXEL_TYPE color);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
BYTE* mChnFont;
|
||||
BYTE* mEngFont;
|
||||
|
||||
DWORD* mCharBuffer;
|
||||
|
||||
PIXEL_TYPE mColor;
|
||||
PIXEL_TYPE mBgColor;
|
||||
|
||||
int mFontSize;
|
||||
int mBytesPerChar;
|
||||
int mBytesPerRow;
|
||||
|
||||
int mCacheSize;
|
||||
int mCacheImageWidth;
|
||||
int mCacheImageHeight;
|
||||
|
||||
int mCol;
|
||||
int mRow;
|
||||
|
||||
//public:
|
||||
|
||||
JTexture* mTexture;
|
||||
JQuad** mSprites;
|
||||
|
||||
int *mGBCode;
|
||||
|
||||
int mCurr;
|
||||
|
||||
float mScale;
|
||||
float mRotation;
|
||||
|
||||
int mCount;
|
||||
|
||||
bool mSmallEnglishFont;
|
||||
|
||||
void GetStringArea(BYTE* str, int *w, int *h);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+57
-57
@@ -1,57 +1,57 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GAME_LAUNCHER_H_
|
||||
#define _GAME_LAUNCHER_H_
|
||||
|
||||
|
||||
#include "JApp.h"
|
||||
#include "JTypes.h"
|
||||
#include "JFileSystem.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// An interface for JGE to get the user defined JApp class.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGameLauncher
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get user defined JApp instance. The function will be called when
|
||||
/// JGE starts.
|
||||
///
|
||||
/// @return - User defined JApp instance.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JApp* GetGameApp();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get application name. Mainly for Windows build to setup the name
|
||||
/// on the title bar.
|
||||
///
|
||||
/// @return - Application name.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char *GetName();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get initialization flags.
|
||||
///
|
||||
/// @return - Initialization flags.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
u32 GetInitFlags();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GAME_LAUNCHER_H_
|
||||
#define _GAME_LAUNCHER_H_
|
||||
|
||||
|
||||
#include "JApp.h"
|
||||
#include "JTypes.h"
|
||||
#include "JFileSystem.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// An interface for JGE to get the user defined JApp class.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGameLauncher
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get user defined JApp instance. The function will be called when
|
||||
/// JGE starts.
|
||||
///
|
||||
/// @return - User defined JApp instance.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JApp* GetGameApp();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get application name. Mainly for Windows build to setup the name
|
||||
/// on the title bar.
|
||||
///
|
||||
/// @return - Application name.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char *GetName();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get initialization flags.
|
||||
///
|
||||
/// @return - Initialization flags.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
u32 GetInitFlags();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+259
-259
@@ -1,259 +1,259 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JGAME_OBJECT_H_
|
||||
#define _JGAME_OBJECT_H_
|
||||
|
||||
#include "JTypes.h"
|
||||
#include "JRenderer.h"
|
||||
#include "JSprite.h"
|
||||
|
||||
|
||||
#define FLASH_TIME 0.10f
|
||||
#define FLASHING_COUNT 6
|
||||
|
||||
#define RENDER_FLAG_ANGLE 0x0001
|
||||
#define RENDER_FLAG_SIZE 0x0002
|
||||
#define RENDER_FLAG_ROTATION 0x0004
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A super Sprite class for in-game entities. Extra functions are added
|
||||
/// in addition to a normal Sprite for easier control of in-game
|
||||
/// activities.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGameObject: public JSprite
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param tex - Texture for first frame. NULL for no starting frame.
|
||||
/// @param x - X position of texture for the frame.
|
||||
/// @param y - Y position of texture for the frame.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGameObject(JTexture *tex, float x, float y, float width, float height);
|
||||
|
||||
virtual ~JGameObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update function.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Function to handle collision.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void OnCollide();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set bounding box for collision detection. All the following collision
|
||||
/// detections will be done using bounding box.
|
||||
///
|
||||
/// @param x - X position of the bounding box (relative to this sprite).
|
||||
/// @param y - Y position of the bounding box (relative to this sprite).
|
||||
/// @param width - Width of the bounding box.
|
||||
/// @param height - Height of the bounding box.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBBox(float x, float y, float width, float height);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get bounding box relative to screen position.
|
||||
///
|
||||
/// @param x - X of screen position.
|
||||
/// @param y - Y of screen position.
|
||||
///
|
||||
/// @return xNow - X position of the bounding box (relative to screen).
|
||||
/// @return yNow - Y position of the bounding box (relative to screen).
|
||||
/// @return width - Width of the bounding box.
|
||||
/// @return height - Height of the bounding box.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set up a circle for collision detection. All the following collision
|
||||
/// detections will be done using circle to circle collision detection.
|
||||
///
|
||||
/// @param cx - X of the circle center.
|
||||
/// @param cy - Y of the circle center.
|
||||
/// @param radius - Radius of the circle.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCollisionCircle(float cx, float cy, float radius);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check for collision. Either bounding box or circle to circle
|
||||
/// collision detection will be used depending on which one is setup last.
|
||||
///
|
||||
/// @param target - Target to check for collision.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Collide(JGameObject *target);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set object that has collided with this object.
|
||||
///
|
||||
/// @param target - Object that has collided with this object.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCollisionTarget(JGameObject *target);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get object that has collided with this object.
|
||||
///
|
||||
/// @return Object that has collided with this object.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGameObject *GetCollisionTarget();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set damage point of this object.
|
||||
///
|
||||
/// @param pt - Damage point.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHitPoint(int pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get damage point of this object.
|
||||
///
|
||||
/// @return Damage point.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetHitPoint();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blood of this object.
|
||||
///
|
||||
/// @param pt - Blood value.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBlood(int pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get blood of this object.
|
||||
///
|
||||
/// @return Blood value.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetBlood();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable alpha animation during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of changing the alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableAlpha(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable scaling during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of changing the scaling value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableScaling(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable rotation during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of rotation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableRotation(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rendering flags.
|
||||
///
|
||||
/// @param flags - Rendering flags encoded in bits.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRenderFlags(int flags);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start flashing during render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartFlashing();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start flashing during render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopFlashing();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if object is flashing.
|
||||
///
|
||||
/// @return Flashing status.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsFlashing();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
u32 mRenderFlags;
|
||||
|
||||
|
||||
bool mUseBoundingBox;
|
||||
|
||||
float mBBoxX;
|
||||
float mBBoxY;
|
||||
float mBBoxWidth;
|
||||
float mBBoxHeight;
|
||||
|
||||
float mCenterX;
|
||||
float mCenterY;
|
||||
float mRadius;
|
||||
|
||||
bool mDoAlpha;
|
||||
float mAlphaDelta;
|
||||
bool mDoScaling;
|
||||
float mScaleDelta;
|
||||
bool mDoRotation;
|
||||
float mRotationDelta;
|
||||
|
||||
bool mFlashing;
|
||||
float mFlashTimer;
|
||||
int mFlashCounter;
|
||||
|
||||
|
||||
protected:
|
||||
JGameObject *mCollisionTarget;
|
||||
bool mCollided;
|
||||
|
||||
int mHitPoint;
|
||||
int mBlood;
|
||||
int mOriginalBlood;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JGAME_OBJECT_H_
|
||||
#define _JGAME_OBJECT_H_
|
||||
|
||||
#include "JTypes.h"
|
||||
#include "JRenderer.h"
|
||||
#include "JSprite.h"
|
||||
|
||||
|
||||
#define FLASH_TIME 0.10f
|
||||
#define FLASHING_COUNT 6
|
||||
|
||||
#define RENDER_FLAG_ANGLE 0x0001
|
||||
#define RENDER_FLAG_SIZE 0x0002
|
||||
#define RENDER_FLAG_ROTATION 0x0004
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// A super Sprite class for in-game entities. Extra functions are added
|
||||
/// in addition to a normal Sprite for easier control of in-game
|
||||
/// activities.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JGameObject: public JSprite
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param tex - Texture for first frame. NULL for no starting frame.
|
||||
/// @param x - X position of texture for the frame.
|
||||
/// @param y - Y position of texture for the frame.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGameObject(JTexture *tex, float x, float y, float width, float height);
|
||||
|
||||
virtual ~JGameObject();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update function.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Function to handle collision.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void OnCollide();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set bounding box for collision detection. All the following collision
|
||||
/// detections will be done using bounding box.
|
||||
///
|
||||
/// @param x - X position of the bounding box (relative to this sprite).
|
||||
/// @param y - Y position of the bounding box (relative to this sprite).
|
||||
/// @param width - Width of the bounding box.
|
||||
/// @param height - Height of the bounding box.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBBox(float x, float y, float width, float height);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get bounding box relative to screen position.
|
||||
///
|
||||
/// @param x - X of screen position.
|
||||
/// @param y - Y of screen position.
|
||||
///
|
||||
/// @return xNow - X position of the bounding box (relative to screen).
|
||||
/// @return yNow - Y position of the bounding box (relative to screen).
|
||||
/// @return width - Width of the bounding box.
|
||||
/// @return height - Height of the bounding box.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set up a circle for collision detection. All the following collision
|
||||
/// detections will be done using circle to circle collision detection.
|
||||
///
|
||||
/// @param cx - X of the circle center.
|
||||
/// @param cy - Y of the circle center.
|
||||
/// @param radius - Radius of the circle.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCollisionCircle(float cx, float cy, float radius);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check for collision. Either bounding box or circle to circle
|
||||
/// collision detection will be used depending on which one is setup last.
|
||||
///
|
||||
/// @param target - Target to check for collision.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Collide(JGameObject *target);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set object that has collided with this object.
|
||||
///
|
||||
/// @param target - Object that has collided with this object.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCollisionTarget(JGameObject *target);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get object that has collided with this object.
|
||||
///
|
||||
/// @return Object that has collided with this object.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGameObject *GetCollisionTarget();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set damage point of this object.
|
||||
///
|
||||
/// @param pt - Damage point.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHitPoint(int pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get damage point of this object.
|
||||
///
|
||||
/// @return Damage point.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetHitPoint();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blood of this object.
|
||||
///
|
||||
/// @param pt - Blood value.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBlood(int pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get blood of this object.
|
||||
///
|
||||
/// @return Blood value.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetBlood();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable alpha animation during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of changing the alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableAlpha(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable scaling during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of changing the scaling value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableScaling(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable rotation during update.
|
||||
///
|
||||
/// @param flag - Enable flag.
|
||||
/// @param delta - Rate of rotation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EnableRotation(bool flag, float delta=0.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rendering flags.
|
||||
///
|
||||
/// @param flags - Rendering flags encoded in bits.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRenderFlags(int flags);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start flashing during render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartFlashing();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start flashing during render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopFlashing();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if object is flashing.
|
||||
///
|
||||
/// @return Flashing status.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsFlashing();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
u32 mRenderFlags;
|
||||
|
||||
|
||||
bool mUseBoundingBox;
|
||||
|
||||
float mBBoxX;
|
||||
float mBBoxY;
|
||||
float mBBoxWidth;
|
||||
float mBBoxHeight;
|
||||
|
||||
float mCenterX;
|
||||
float mCenterY;
|
||||
float mRadius;
|
||||
|
||||
bool mDoAlpha;
|
||||
float mAlphaDelta;
|
||||
bool mDoScaling;
|
||||
float mScaleDelta;
|
||||
bool mDoRotation;
|
||||
float mRotationDelta;
|
||||
|
||||
bool mFlashing;
|
||||
float mFlashTimer;
|
||||
int mFlashCounter;
|
||||
|
||||
|
||||
protected:
|
||||
JGameObject *mCollisionTarget;
|
||||
bool mCollided;
|
||||
|
||||
int mHitPoint;
|
||||
int mBlood;
|
||||
int mOriginalBlood;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+187
-187
@@ -1,187 +1,187 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef JLBF_H
|
||||
#define JLBF_H
|
||||
|
||||
#define PRINTF_BUFFER_SIZE 256
|
||||
#define MAX_CHAR 256
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include <string>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Bitmap font class for LMNOpc's Bitmap Font Builder:
|
||||
/// http://www.lmnopc.com/bitmapfontbuilder/
|
||||
///
|
||||
/// Two files are used for each font:
|
||||
/// 1: xxx.png, font bitmap.
|
||||
/// 2: xxx.dat, widths for each character
|
||||
/// Each font contains 2 sets of characters ASCII code (32-159).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JLBFont
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param fontname - Name of the font WITHOUT extensions.
|
||||
/// @param lineheight - Font height.
|
||||
/// @param useVideoRAM - Indicate to use video RAM to store the font image or not (PSP only).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JLBFont(const char *fontname, int lineheight, bool useVideoRAM=false);
|
||||
|
||||
~JLBFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering text to screen.
|
||||
///
|
||||
/// @param string - text for rendering.
|
||||
/// @param x - X position of text.
|
||||
/// @param y - Y position of text.
|
||||
/// @align - Text aligment.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void DrawString(const char *string, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering text to screen with syntax similar to printf of C/C++.
|
||||
///
|
||||
/// @param x - X position of text.
|
||||
/// @param y - Y position of text.
|
||||
/// @param format - String formatting.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void printf(float x, float y, const char *format, ...);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font color.
|
||||
///
|
||||
/// @param color - color of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale for rendering.
|
||||
///
|
||||
/// @param scale - Scale for rendering characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle for rendering.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font tracking.
|
||||
///
|
||||
/// @param tracking - Font tracking.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetTracking(float tracking);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get font color.
|
||||
///
|
||||
/// @return Font color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
PIXEL_TYPE GetColor() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rendering scale.
|
||||
///
|
||||
/// @return Rendering scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetScale() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rendering angle.
|
||||
///
|
||||
/// @return Rendering angle.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetRotation() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get font tracking.
|
||||
///
|
||||
/// @return Font tracking.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetTracking() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get height of font.
|
||||
///
|
||||
/// @return Height of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetHeight() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of rendering string on screen.
|
||||
///
|
||||
/// @param string - NULL terminated string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetStringWidth(const char *string) const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// There are usually 2 sets of characters in the font image. The first set
|
||||
/// is from index 0-127 and the second from 128-255. You should use this
|
||||
/// function to select which set of characters you want to use. The index
|
||||
/// base should be either 0 or 128.
|
||||
///
|
||||
/// @param base - Base for the character set to use.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBase(int base);
|
||||
|
||||
|
||||
private:
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
JTexture* mTexture;
|
||||
JQuad* mQuad;
|
||||
|
||||
float mXPos[MAX_CHAR];
|
||||
float mYPos[MAX_CHAR];
|
||||
float mCharWidth[MAX_CHAR];
|
||||
|
||||
float mHeight;
|
||||
float mScale;
|
||||
float mRotation;
|
||||
float mTracking;
|
||||
float mSpacing;
|
||||
|
||||
PIXEL_TYPE mColor;
|
||||
int mBlend;
|
||||
|
||||
int mBase;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef JLBF_H
|
||||
#define JLBF_H
|
||||
|
||||
#define PRINTF_BUFFER_SIZE 256
|
||||
#define MAX_CHAR 256
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include <string>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Bitmap font class for LMNOpc's Bitmap Font Builder:
|
||||
/// http://www.lmnopc.com/bitmapfontbuilder/
|
||||
///
|
||||
/// Two files are used for each font:
|
||||
/// 1: xxx.png, font bitmap.
|
||||
/// 2: xxx.dat, widths for each character
|
||||
/// Each font contains 2 sets of characters ASCII code (32-159).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JLBFont
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param fontname - Name of the font WITHOUT extensions.
|
||||
/// @param lineheight - Font height.
|
||||
/// @param useVideoRAM - Indicate to use video RAM to store the font image or not (PSP only).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JLBFont(const char *fontname, int lineheight, bool useVideoRAM=false);
|
||||
|
||||
~JLBFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering text to screen.
|
||||
///
|
||||
/// @param string - text for rendering.
|
||||
/// @param x - X position of text.
|
||||
/// @param y - Y position of text.
|
||||
/// @align - Text aligment.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void DrawString(const char *string, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
void DrawString(std::string s, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Rendering text to screen with syntax similar to printf of C/C++.
|
||||
///
|
||||
/// @param x - X position of text.
|
||||
/// @param y - Y position of text.
|
||||
/// @param format - String formatting.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void printf(float x, float y, const char *format, ...);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font color.
|
||||
///
|
||||
/// @param color - color of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale for rendering.
|
||||
///
|
||||
/// @param scale - Scale for rendering characters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle for rendering.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font tracking.
|
||||
///
|
||||
/// @param tracking - Font tracking.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetTracking(float tracking);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get font color.
|
||||
///
|
||||
/// @return Font color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
PIXEL_TYPE GetColor() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rendering scale.
|
||||
///
|
||||
/// @return Rendering scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetScale() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rendering angle.
|
||||
///
|
||||
/// @return Rendering angle.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetRotation() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get font tracking.
|
||||
///
|
||||
/// @return Font tracking.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetTracking() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get height of font.
|
||||
///
|
||||
/// @return Height of font.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetHeight() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of rendering string on screen.
|
||||
///
|
||||
/// @param string - NULL terminated string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetStringWidth(const char *string) const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// There are usually 2 sets of characters in the font image. The first set
|
||||
/// is from index 0-127 and the second from 128-255. You should use this
|
||||
/// function to select which set of characters you want to use. The index
|
||||
/// base should be either 0 or 128.
|
||||
///
|
||||
/// @param base - Base for the character set to use.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBase(int base);
|
||||
|
||||
|
||||
private:
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
JTexture* mTexture;
|
||||
JQuad* mQuad;
|
||||
|
||||
float mXPos[MAX_CHAR];
|
||||
float mYPos[MAX_CHAR];
|
||||
float mCharWidth[MAX_CHAR];
|
||||
|
||||
float mHeight;
|
||||
float mScale;
|
||||
float mRotation;
|
||||
float mTracking;
|
||||
float mSpacing;
|
||||
|
||||
PIXEL_TYPE mColor;
|
||||
int mBlend;
|
||||
|
||||
int mBase;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+255
-255
@@ -1,255 +1,255 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MD2MODEL_H
|
||||
#define _MD2MODEL_H
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
|
||||
#define SMALLEST_FP 0.000001f
|
||||
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_ANIMATION 16
|
||||
|
||||
//#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
//#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
enum MD2AnimationStates
|
||||
{
|
||||
STATE_IDLE,
|
||||
STATE_RUNNING,
|
||||
STATE_SHOT_NOT_FALLING_DOWN,
|
||||
STATE_SHOT_IN_SHOULDER,
|
||||
STATE_JUMP,
|
||||
STATE_IDLE2,
|
||||
STATE_SHOT_FALLING_DOWN,
|
||||
STATE_IDLE3,
|
||||
STATE_IDLE4,
|
||||
STATE_CROUCHING,
|
||||
STATE_CROUCHING_CRAWL,
|
||||
STATE_IDLE_CROUCHING,
|
||||
STATE_KNEELING_DYING,
|
||||
STATE_FALLING_BACK_DYING,
|
||||
STATE_FALING_FORWARD_DYING,
|
||||
STATE_FALLING_BACK_SLOWLY_DYING
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
class MD2Animation
|
||||
{
|
||||
public:
|
||||
int mStartFrame;
|
||||
int mEndFrame;
|
||||
|
||||
MD2Animation(int start, int end);
|
||||
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// texture coordinate
|
||||
typedef struct
|
||||
{
|
||||
float s;
|
||||
float t;
|
||||
} texCoord_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// texture coordinate index
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
} stIndex_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// info for a single frame point
|
||||
typedef struct
|
||||
{
|
||||
unsigned char v[3];
|
||||
unsigned char normalIndex; // not used
|
||||
} framePoint_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// information for a single frame
|
||||
typedef struct
|
||||
{
|
||||
float scale[3];
|
||||
float translate[3];
|
||||
char name[16];
|
||||
framePoint_t fp[1];
|
||||
} frame_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// data for a single triangle
|
||||
typedef struct
|
||||
{
|
||||
unsigned short meshIndex[3]; // vertex indices
|
||||
unsigned short stIndex[3]; // texture coordinate indices
|
||||
} mesh_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// the model data
|
||||
typedef struct
|
||||
{
|
||||
int numFrames; // number of frames
|
||||
int numPoints; // number of points
|
||||
int numTriangles; // number of triangles
|
||||
int numST; // number of skins
|
||||
int frameSize; // size of each frame in bytes
|
||||
int texWidth, texHeight; // texture width, height
|
||||
int currentFrame; // current frame # in animation
|
||||
int nextFrame; // next frame # in animation
|
||||
float interpol; // percent through current frame
|
||||
mesh_t *triIndex; // triangle list
|
||||
texCoord_t *st; // texture coordinate list
|
||||
Vector3D *pointList; // vertex list
|
||||
JTexture *modelTex; // texture
|
||||
} modelData_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
int ident; // identifies as MD2 file "IDP2"
|
||||
int version; //
|
||||
int skinwidth; // width of texture
|
||||
int skinheight; // height of texture
|
||||
int framesize; // number of bytes per frame
|
||||
int numSkins; // number of textures
|
||||
int numXYZ; // number of points
|
||||
int numST; // number of texture
|
||||
int numTris; // number of triangles
|
||||
int numGLcmds;
|
||||
int numFrames; // total number of frames
|
||||
int offsetSkins; // offset to skin names (64 bytes each)
|
||||
int offsetST; // offset of texture s-t values
|
||||
int offsetTris; // offset of triangle mesh
|
||||
int offsetFrames; // offset of frame data (points)
|
||||
int offsetGLcmds; // type of OpenGL commands to use
|
||||
int offsetEnd; // end of file
|
||||
} modelHeader_t;
|
||||
|
||||
|
||||
class JRenderer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Helper class to display Quake 2 MD2 model.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JMD2Model
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMD2Model();
|
||||
|
||||
~JMD2Model();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set model state.
|
||||
///
|
||||
/// @param newState - Model state.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetState(int newState);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load MD2 model.
|
||||
///
|
||||
/// @param filename - Name of MD2 file.
|
||||
/// @param texturenName - Name of texture.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(char *filename, char *textureName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render a single frame of the model.
|
||||
///
|
||||
/// @param frameNum - Frame to render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(int frameNum);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Time elpased since last update (in seconds).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set speed of animation.
|
||||
///
|
||||
/// @param speed - Speed of animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationSpeed(float speed);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the model.
|
||||
///
|
||||
/// @param percent - Interpolating percentage.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
modelData_t *mModel;
|
||||
|
||||
void CheckNextState();
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
void CalculateNormal(float *p1, float *p2, float *p3);
|
||||
#else
|
||||
void CalculateNormal(ScePspFVector3* normal, float *p1, float *p2, float *p3);
|
||||
#endif
|
||||
|
||||
MD2Animation **mAnimations;
|
||||
int mState;
|
||||
int mNextState;
|
||||
|
||||
float mAnimationSpeed;
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MD2MODEL_H
|
||||
#define _MD2MODEL_H
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
|
||||
#define SMALLEST_FP 0.000001f
|
||||
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_ANIMATION 16
|
||||
|
||||
//#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
//#pragma pack(pop)
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
enum MD2AnimationStates
|
||||
{
|
||||
STATE_IDLE,
|
||||
STATE_RUNNING,
|
||||
STATE_SHOT_NOT_FALLING_DOWN,
|
||||
STATE_SHOT_IN_SHOULDER,
|
||||
STATE_JUMP,
|
||||
STATE_IDLE2,
|
||||
STATE_SHOT_FALLING_DOWN,
|
||||
STATE_IDLE3,
|
||||
STATE_IDLE4,
|
||||
STATE_CROUCHING,
|
||||
STATE_CROUCHING_CRAWL,
|
||||
STATE_IDLE_CROUCHING,
|
||||
STATE_KNEELING_DYING,
|
||||
STATE_FALLING_BACK_DYING,
|
||||
STATE_FALING_FORWARD_DYING,
|
||||
STATE_FALLING_BACK_SLOWLY_DYING
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
class MD2Animation
|
||||
{
|
||||
public:
|
||||
int mStartFrame;
|
||||
int mEndFrame;
|
||||
|
||||
MD2Animation(int start, int end);
|
||||
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// texture coordinate
|
||||
typedef struct
|
||||
{
|
||||
float s;
|
||||
float t;
|
||||
} texCoord_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// texture coordinate index
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
} stIndex_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// info for a single frame point
|
||||
typedef struct
|
||||
{
|
||||
unsigned char v[3];
|
||||
unsigned char normalIndex; // not used
|
||||
} framePoint_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// information for a single frame
|
||||
typedef struct
|
||||
{
|
||||
float scale[3];
|
||||
float translate[3];
|
||||
char name[16];
|
||||
framePoint_t fp[1];
|
||||
} frame_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// data for a single triangle
|
||||
typedef struct
|
||||
{
|
||||
unsigned short meshIndex[3]; // vertex indices
|
||||
unsigned short stIndex[3]; // texture coordinate indices
|
||||
} mesh_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// the model data
|
||||
typedef struct
|
||||
{
|
||||
int numFrames; // number of frames
|
||||
int numPoints; // number of points
|
||||
int numTriangles; // number of triangles
|
||||
int numST; // number of skins
|
||||
int frameSize; // size of each frame in bytes
|
||||
int texWidth, texHeight; // texture width, height
|
||||
int currentFrame; // current frame # in animation
|
||||
int nextFrame; // next frame # in animation
|
||||
float interpol; // percent through current frame
|
||||
mesh_t *triIndex; // triangle list
|
||||
texCoord_t *st; // texture coordinate list
|
||||
Vector3D *pointList; // vertex list
|
||||
JTexture *modelTex; // texture
|
||||
} modelData_t;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
int ident; // identifies as MD2 file "IDP2"
|
||||
int version; //
|
||||
int skinwidth; // width of texture
|
||||
int skinheight; // height of texture
|
||||
int framesize; // number of bytes per frame
|
||||
int numSkins; // number of textures
|
||||
int numXYZ; // number of points
|
||||
int numST; // number of texture
|
||||
int numTris; // number of triangles
|
||||
int numGLcmds;
|
||||
int numFrames; // total number of frames
|
||||
int offsetSkins; // offset to skin names (64 bytes each)
|
||||
int offsetST; // offset of texture s-t values
|
||||
int offsetTris; // offset of triangle mesh
|
||||
int offsetFrames; // offset of frame data (points)
|
||||
int offsetGLcmds; // type of OpenGL commands to use
|
||||
int offsetEnd; // end of file
|
||||
} modelHeader_t;
|
||||
|
||||
|
||||
class JRenderer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Helper class to display Quake 2 MD2 model.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JMD2Model
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMD2Model();
|
||||
|
||||
~JMD2Model();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set model state.
|
||||
///
|
||||
/// @param newState - Model state.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetState(int newState);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load MD2 model.
|
||||
///
|
||||
/// @param filename - Name of MD2 file.
|
||||
/// @param texturenName - Name of texture.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(char *filename, char *textureName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render a single frame of the model.
|
||||
///
|
||||
/// @param frameNum - Frame to render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(int frameNum);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Time elpased since last update (in seconds).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set speed of animation.
|
||||
///
|
||||
/// @param speed - Speed of animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationSpeed(float speed);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the model.
|
||||
///
|
||||
/// @param percent - Interpolating percentage.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
modelData_t *mModel;
|
||||
|
||||
void CheckNextState();
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
void CalculateNormal(float *p1, float *p2, float *p3);
|
||||
#else
|
||||
void CalculateNormal(ScePspFVector3* normal, float *p1, float *p2, float *p3);
|
||||
#endif
|
||||
|
||||
MD2Animation **mAnimations;
|
||||
int mState;
|
||||
int mNextState;
|
||||
|
||||
float mAnimationSpeed;
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+82
-82
@@ -1,82 +1,82 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _OBJMODEL_H
|
||||
#define _OBJMODEL_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
class JTexture;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Helper class to display Wavefront OBJ model.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JOBJModel
|
||||
{
|
||||
|
||||
struct Face
|
||||
{
|
||||
int mVertCount;
|
||||
int mVertIdx[4];
|
||||
int mTexIdx[4];
|
||||
int mNormalIdx[4];
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JOBJModel();
|
||||
|
||||
~JOBJModel();
|
||||
|
||||
int ReadLine(char *output, const char *buffer, int start, int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load OBJ model.
|
||||
///
|
||||
/// @param modelName - Name of OBJ file.
|
||||
/// @param texturenName - Name of texture.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *modelName, const char *textureName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the model to screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
private:
|
||||
int mPolycount;
|
||||
Vertex3D* mPolygons;
|
||||
JTexture* mTexture;
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _OBJMODEL_H
|
||||
#define _OBJMODEL_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||
|
||||
#else
|
||||
|
||||
#include <pspgu.h>
|
||||
#include <pspgum.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
#include "Vector3D.h"
|
||||
|
||||
class JTexture;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Helper class to display Wavefront OBJ model.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JOBJModel
|
||||
{
|
||||
|
||||
struct Face
|
||||
{
|
||||
int mVertCount;
|
||||
int mVertIdx[4];
|
||||
int mTexIdx[4];
|
||||
int mNormalIdx[4];
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JOBJModel();
|
||||
|
||||
~JOBJModel();
|
||||
|
||||
int ReadLine(char *output, const char *buffer, int start, int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load OBJ model.
|
||||
///
|
||||
/// @param modelName - Name of OBJ file.
|
||||
/// @param texturenName - Name of texture.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *modelName, const char *textureName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the model to screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
private:
|
||||
int mPolycount;
|
||||
Vertex3D* mPolygons;
|
||||
JTexture* mTexture;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+105
-105
@@ -1,105 +1,105 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_H__
|
||||
#define __PARTICLE_H__
|
||||
|
||||
#include "JApp.h"
|
||||
#include "JRenderer.h"
|
||||
#include "Vector2D.h"
|
||||
|
||||
|
||||
#define MAX_KEYS 8
|
||||
|
||||
class JParticleData
|
||||
{
|
||||
public:
|
||||
JParticleData();
|
||||
void Init();
|
||||
void Clear();
|
||||
void AddKey(float keyTime, float keyValue);
|
||||
void Update(float dt);
|
||||
void SetScale(float scale);
|
||||
|
||||
float mCurr;
|
||||
float mTarget;
|
||||
float mDelta;
|
||||
float mTimer;
|
||||
int mKeyCount;
|
||||
int mKeyIndex;
|
||||
float mKeyTime[MAX_KEYS];
|
||||
float mKeyValue[MAX_KEYS];
|
||||
|
||||
float mScale;
|
||||
};
|
||||
|
||||
|
||||
enum ParticleField
|
||||
{
|
||||
FIELD_SPEED,
|
||||
FIELD_SIZE,
|
||||
FIELD_ROTATION,
|
||||
FIELD_ALPHA,
|
||||
FIELD_RED,
|
||||
FIELD_GREEN,
|
||||
FIELD_BLUE,
|
||||
FIELD_RADIAL_ACCEL,
|
||||
FIELD_TANGENTIAL_ACCEL,
|
||||
FIELD_GRAVITY,
|
||||
FIELD_COUNT
|
||||
};
|
||||
|
||||
class JParticle
|
||||
{
|
||||
public:
|
||||
|
||||
bool mActive;
|
||||
|
||||
JParticle();
|
||||
~JParticle();
|
||||
|
||||
bool Update(float dt);
|
||||
void Render();
|
||||
void Init(float lifeTime);
|
||||
|
||||
void InitPosition(float ox, float oy, float xoffset, float yoffset);
|
||||
void SetPosition(float x, float y);
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
JParticleData* GetField(int index);
|
||||
JParticleData* GetDataPtr();
|
||||
|
||||
void Move(float x, float y);
|
||||
void SetVelocity(float x, float y);
|
||||
void SetSize(float size);
|
||||
|
||||
|
||||
private:
|
||||
static JRenderer* mRenderer;
|
||||
JQuad* mQuad;
|
||||
|
||||
Vector2D mOrigin;
|
||||
Vector2D mPos;
|
||||
Vector2D mVelocity;
|
||||
|
||||
//float mSpeed;
|
||||
float mSize;
|
||||
|
||||
float mLifetime;
|
||||
|
||||
JParticleData mData[FIELD_COUNT];
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_H__
|
||||
#define __PARTICLE_H__
|
||||
|
||||
#include "JApp.h"
|
||||
#include "JRenderer.h"
|
||||
#include "Vector2D.h"
|
||||
|
||||
|
||||
#define MAX_KEYS 8
|
||||
|
||||
class JParticleData
|
||||
{
|
||||
public:
|
||||
JParticleData();
|
||||
void Init();
|
||||
void Clear();
|
||||
void AddKey(float keyTime, float keyValue);
|
||||
void Update(float dt);
|
||||
void SetScale(float scale);
|
||||
|
||||
float mCurr;
|
||||
float mTarget;
|
||||
float mDelta;
|
||||
float mTimer;
|
||||
int mKeyCount;
|
||||
int mKeyIndex;
|
||||
float mKeyTime[MAX_KEYS];
|
||||
float mKeyValue[MAX_KEYS];
|
||||
|
||||
float mScale;
|
||||
};
|
||||
|
||||
|
||||
enum ParticleField
|
||||
{
|
||||
FIELD_SPEED,
|
||||
FIELD_SIZE,
|
||||
FIELD_ROTATION,
|
||||
FIELD_ALPHA,
|
||||
FIELD_RED,
|
||||
FIELD_GREEN,
|
||||
FIELD_BLUE,
|
||||
FIELD_RADIAL_ACCEL,
|
||||
FIELD_TANGENTIAL_ACCEL,
|
||||
FIELD_GRAVITY,
|
||||
FIELD_COUNT
|
||||
};
|
||||
|
||||
class JParticle
|
||||
{
|
||||
public:
|
||||
|
||||
bool mActive;
|
||||
|
||||
JParticle();
|
||||
~JParticle();
|
||||
|
||||
bool Update(float dt);
|
||||
void Render();
|
||||
void Init(float lifeTime);
|
||||
|
||||
void InitPosition(float ox, float oy, float xoffset, float yoffset);
|
||||
void SetPosition(float x, float y);
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
JParticleData* GetField(int index);
|
||||
JParticleData* GetDataPtr();
|
||||
|
||||
void Move(float x, float y);
|
||||
void SetVelocity(float x, float y);
|
||||
void SetSize(float size);
|
||||
|
||||
|
||||
private:
|
||||
static JRenderer* mRenderer;
|
||||
JQuad* mQuad;
|
||||
|
||||
Vector2D mOrigin;
|
||||
Vector2D mPos;
|
||||
Vector2D mVelocity;
|
||||
|
||||
//float mSpeed;
|
||||
float mSize;
|
||||
|
||||
float mLifetime;
|
||||
|
||||
JParticleData mData[FIELD_COUNT];
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+146
-146
@@ -1,146 +1,146 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_EFFECT_H__
|
||||
#define __PARTICLE_EFFECT_H__
|
||||
|
||||
#define MAX_EMITTER 5
|
||||
|
||||
class JParticleSystem;
|
||||
class JParticleEmitter;
|
||||
class JResourceManager;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Particle effect. Each particle effect can contain one or more emitters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleEffect
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param mgr - Resource manager for retrieving image quads for the particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleEffect(JResourceManager* mgr);
|
||||
|
||||
~JParticleEffect();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load effect from file.
|
||||
///
|
||||
/// @param filename - Name of effect file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char* filename);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update particle effect.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render particle effect.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the particle effect is finished.
|
||||
///
|
||||
/// @return True if done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Done();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Stop();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set particle system.
|
||||
///
|
||||
/// @param particleSys - Particle system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetParticleSystem(JParticleSystem* particleSys);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get particle system.
|
||||
///
|
||||
/// @return Particle system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleSystem* GetParticleSystem();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the effect. New particles will be emitted from the
|
||||
/// new position but the existing active particles will not be affected.
|
||||
///
|
||||
/// @param x - X screen position.
|
||||
/// @param y - Y screen position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X position.
|
||||
///
|
||||
/// @return X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetX();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y position.
|
||||
///
|
||||
/// @return Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetY();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move the particle effect over to a new position. All the existing
|
||||
/// particles will be moved relatively.
|
||||
///
|
||||
/// @param X - X screen position.
|
||||
/// @param y - Y screen position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void MoveTo(float x, float y);
|
||||
|
||||
protected:
|
||||
JParticleSystem* mParticleSystem;
|
||||
JResourceManager* mResourceManager;
|
||||
float mX;
|
||||
float mY;
|
||||
|
||||
int mEmitterCount;
|
||||
JParticleEmitter* mParticleEmitters[MAX_EMITTER];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_EFFECT_H__
|
||||
#define __PARTICLE_EFFECT_H__
|
||||
|
||||
#define MAX_EMITTER 5
|
||||
|
||||
class JParticleSystem;
|
||||
class JParticleEmitter;
|
||||
class JResourceManager;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Particle effect. Each particle effect can contain one or more emitters.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleEffect
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param mgr - Resource manager for retrieving image quads for the particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleEffect(JResourceManager* mgr);
|
||||
|
||||
~JParticleEffect();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load effect from file.
|
||||
///
|
||||
/// @param filename - Name of effect file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char* filename);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update particle effect.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render particle effect.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the particle effect is finished.
|
||||
///
|
||||
/// @return True if done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Done();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Stop();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set particle system.
|
||||
///
|
||||
/// @param particleSys - Particle system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetParticleSystem(JParticleSystem* particleSys);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get particle system.
|
||||
///
|
||||
/// @return Particle system.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleSystem* GetParticleSystem();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the effect. New particles will be emitted from the
|
||||
/// new position but the existing active particles will not be affected.
|
||||
///
|
||||
/// @param x - X screen position.
|
||||
/// @param y - Y screen position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X position.
|
||||
///
|
||||
/// @return X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetX();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y position.
|
||||
///
|
||||
/// @return Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetY();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move the particle effect over to a new position. All the existing
|
||||
/// particles will be moved relatively.
|
||||
///
|
||||
/// @param X - X screen position.
|
||||
/// @param y - Y screen position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void MoveTo(float x, float y);
|
||||
|
||||
protected:
|
||||
JParticleSystem* mParticleSystem;
|
||||
JResourceManager* mResourceManager;
|
||||
float mX;
|
||||
float mY;
|
||||
|
||||
int mEmitterCount;
|
||||
JParticleEmitter* mParticleEmitters[MAX_EMITTER];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+221
-221
@@ -1,221 +1,221 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_EMITTER_H__
|
||||
#define __PARTICLE_EMITTER_H__
|
||||
|
||||
#define INIT_PARTICLE_COUNT 32
|
||||
#define MAX_PARTICLE_COUNT 256
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class JParticleEffect;
|
||||
class JParticle;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Particle emitter. This is where the particles actually generated.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleEmitter
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param parent - Particle effect that contains this emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleEmitter(JParticleEffect* parent);
|
||||
|
||||
~JParticleEmitter();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blending mode for rendering.
|
||||
///
|
||||
/// @param srcBlend - Blending mode for source.
|
||||
/// @param destBlend - Blending mode for destination.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBlending(int srcBlend, int destBlend);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set image quad for particles.
|
||||
///
|
||||
/// @param quad - Image quad.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start emitting particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Restart the emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ReStart();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update the emitter.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render particles emitted by this emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the emitter is done.
|
||||
///
|
||||
/// @return True if the emitter is done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Done();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set active flag.
|
||||
///
|
||||
/// @param flag - Active flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool flag);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move all particles to a distance.
|
||||
///
|
||||
/// @param x - X distance to move.
|
||||
/// @param y - Y distance to move
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void MoveAllParticles(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Emit certain amount of particles.
|
||||
///
|
||||
/// @param count - Number of particles to emit.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EmitParticles(int count);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get idle particle to reuse.
|
||||
///
|
||||
/// @return Idel particle to use.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticle* GetIdleParticle();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put a particle in action.
|
||||
///
|
||||
/// @param par - Particle to start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartParticle(JParticle *par);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set the maximum number of particles that this emitter can emit.
|
||||
///
|
||||
/// @param count - Maximum number of particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetMaxParticleCount(int count);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum JParticleEmitterMode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum JParticleEmitterMode
|
||||
{
|
||||
MODE_REPEAT, ///< Emit particles and repeat when done.
|
||||
MODE_ONCE, ///< Emit once.
|
||||
MODE_NTIMES, ///< Emit N times.
|
||||
MODE_CONTINUOUS, ///< Emit particles continuously.
|
||||
MODE_COUNT
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum JParticleEmitterType
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum JParticleEmitterType
|
||||
{
|
||||
TYPE_POINT, ///< Emit from one point.
|
||||
TYPE_AREA, ///< Emit from a rectangle area.
|
||||
TYPE_HORIZONTAL, ///< Emit from a horizontal line.
|
||||
TYPE_VERTICAL, ///< Emit from a vertical line.
|
||||
TYPE_CIRCLE, ///< Emit from a circle.
|
||||
TYPE_COUNT
|
||||
};
|
||||
|
||||
protected:
|
||||
JParticleEffect* mParent;
|
||||
JQuad* mQuad;
|
||||
|
||||
public:
|
||||
int mType;
|
||||
int mId;
|
||||
|
||||
JParticleData mQuantity;
|
||||
JParticleData mData[FIELD_COUNT];
|
||||
|
||||
float mLifeBase;
|
||||
float mLifeMax;
|
||||
|
||||
float mAngleBase;
|
||||
float mAngleMax;
|
||||
|
||||
float mSpeedBase;
|
||||
float mSpeedMax;
|
||||
|
||||
float mSizeBase;
|
||||
float mSizeMax;
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
int mQuadIndex;
|
||||
|
||||
int mEmitterMode;
|
||||
int mRepeatTimes;
|
||||
|
||||
float mLife;
|
||||
|
||||
|
||||
private:
|
||||
bool mActive;
|
||||
float mEmitTimer;
|
||||
|
||||
int mRepeatCounter;
|
||||
int mActiveParticleCount;
|
||||
|
||||
int mSrcBlending;
|
||||
int mDestBlending;
|
||||
int mMaxParticleCount;
|
||||
|
||||
vector<JParticle*> mParticles;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_EMITTER_H__
|
||||
#define __PARTICLE_EMITTER_H__
|
||||
|
||||
#define INIT_PARTICLE_COUNT 32
|
||||
#define MAX_PARTICLE_COUNT 256
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class JParticleEffect;
|
||||
class JParticle;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Particle emitter. This is where the particles actually generated.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleEmitter
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param parent - Particle effect that contains this emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleEmitter(JParticleEffect* parent);
|
||||
|
||||
~JParticleEmitter();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set blending mode for rendering.
|
||||
///
|
||||
/// @param srcBlend - Blending mode for source.
|
||||
/// @param destBlend - Blending mode for destination.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetBlending(int srcBlend, int destBlend);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set image quad for particles.
|
||||
///
|
||||
/// @param quad - Image quad.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetQuad(JQuad *quad);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start emitting particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Start();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Restart the emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ReStart();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update the emitter.
|
||||
///
|
||||
/// @param dt - Time elapsed since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render particles emitted by this emitter.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the emitter is done.
|
||||
///
|
||||
/// @return True if the emitter is done.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Done();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set active flag.
|
||||
///
|
||||
/// @param flag - Active flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool flag);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move all particles to a distance.
|
||||
///
|
||||
/// @param x - X distance to move.
|
||||
/// @param y - Y distance to move
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void MoveAllParticles(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Emit certain amount of particles.
|
||||
///
|
||||
/// @param count - Number of particles to emit.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void EmitParticles(int count);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get idle particle to reuse.
|
||||
///
|
||||
/// @return Idel particle to use.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticle* GetIdleParticle();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put a particle in action.
|
||||
///
|
||||
/// @param par - Particle to start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartParticle(JParticle *par);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set the maximum number of particles that this emitter can emit.
|
||||
///
|
||||
/// @param count - Maximum number of particles.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetMaxParticleCount(int count);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum JParticleEmitterMode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum JParticleEmitterMode
|
||||
{
|
||||
MODE_REPEAT, ///< Emit particles and repeat when done.
|
||||
MODE_ONCE, ///< Emit once.
|
||||
MODE_NTIMES, ///< Emit N times.
|
||||
MODE_CONTINUOUS, ///< Emit particles continuously.
|
||||
MODE_COUNT
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum JParticleEmitterType
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum JParticleEmitterType
|
||||
{
|
||||
TYPE_POINT, ///< Emit from one point.
|
||||
TYPE_AREA, ///< Emit from a rectangle area.
|
||||
TYPE_HORIZONTAL, ///< Emit from a horizontal line.
|
||||
TYPE_VERTICAL, ///< Emit from a vertical line.
|
||||
TYPE_CIRCLE, ///< Emit from a circle.
|
||||
TYPE_COUNT
|
||||
};
|
||||
|
||||
protected:
|
||||
JParticleEffect* mParent;
|
||||
JQuad* mQuad;
|
||||
|
||||
public:
|
||||
int mType;
|
||||
int mId;
|
||||
|
||||
JParticleData mQuantity;
|
||||
JParticleData mData[FIELD_COUNT];
|
||||
|
||||
float mLifeBase;
|
||||
float mLifeMax;
|
||||
|
||||
float mAngleBase;
|
||||
float mAngleMax;
|
||||
|
||||
float mSpeedBase;
|
||||
float mSpeedMax;
|
||||
|
||||
float mSizeBase;
|
||||
float mSizeMax;
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
int mQuadIndex;
|
||||
|
||||
int mEmitterMode;
|
||||
int mRepeatTimes;
|
||||
|
||||
float mLife;
|
||||
|
||||
|
||||
private:
|
||||
bool mActive;
|
||||
float mEmitTimer;
|
||||
|
||||
int mRepeatCounter;
|
||||
int mActiveParticleCount;
|
||||
|
||||
int mSrcBlending;
|
||||
int mDestBlending;
|
||||
int mMaxParticleCount;
|
||||
|
||||
vector<JParticle*> mParticles;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+114
-114
@@ -1,114 +1,114 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_SYSTEM_H__
|
||||
#define __PARTICLE_SYSTEM_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
|
||||
#include "JParticle.h"
|
||||
|
||||
|
||||
class JParticleEffect;
|
||||
class JParticleEmitter;
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// The particle system of JGE++ is built on a key frame concept with
|
||||
/// multiple emitters for each effect. It's inspired by the particle system
|
||||
/// of Torque Game Builder. At each key frame, you can specify the value
|
||||
/// of the changeable states of the particle. This gives you lots of
|
||||
/// control over the particles and making it possible to create
|
||||
/// almost all of the spectacular effects out of your imagination.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleSystem
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleSystem();
|
||||
|
||||
~JParticleSystem();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update all active effects.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render all active effects.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start an effect.
|
||||
///
|
||||
/// @param effect - Effect to start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartEffect(JParticleEffect* effect);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop all effects.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopAllEffects();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete all effects from memory.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ClearAll();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the particle system is active or not.
|
||||
///
|
||||
/// @return True if active.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set active flag.
|
||||
///
|
||||
/// @param flag - Active flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool flag);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool mActive;
|
||||
|
||||
list<JParticleEffect*> mEffects;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef __PARTICLE_SYSTEM_H__
|
||||
#define __PARTICLE_SYSTEM_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "JGE.h"
|
||||
|
||||
#include "JParticle.h"
|
||||
|
||||
|
||||
class JParticleEffect;
|
||||
class JParticleEmitter;
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// The particle system of JGE++ is built on a key frame concept with
|
||||
/// multiple emitters for each effect. It's inspired by the particle system
|
||||
/// of Torque Game Builder. At each key frame, you can specify the value
|
||||
/// of the changeable states of the particle. This gives you lots of
|
||||
/// control over the particles and making it possible to create
|
||||
/// almost all of the spectacular effects out of your imagination.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JParticleSystem
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JParticleSystem();
|
||||
|
||||
~JParticleSystem();
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update all active effects.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render all active effects.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start an effect.
|
||||
///
|
||||
/// @param effect - Effect to start playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartEffect(JParticleEffect* effect);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop all effects.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopAllEffects();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete all effects from memory.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ClearAll();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Check if the particle system is active or not.
|
||||
///
|
||||
/// @return True if active.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set active flag.
|
||||
///
|
||||
/// @param flag - Active flag.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool flag);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool mActive;
|
||||
|
||||
list<JParticleEffect*> mEffects;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+648
-648
File diff suppressed because it is too large
Load Diff
+30
-30
@@ -1,30 +1,30 @@
|
||||
#ifndef _JSOCKET_H_
|
||||
#define _JSOCKET_H_
|
||||
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
//TODO config ?
|
||||
#define SERVER_PORT 20666
|
||||
|
||||
class JSocket{
|
||||
public:
|
||||
queue<char> received_data;
|
||||
queue<char> tosend_data;
|
||||
static JSocket * mInstance;
|
||||
int start_server(const char *szIpAddr);
|
||||
int start_client(const char *szIpAddr);
|
||||
|
||||
JSocket();
|
||||
~JSocket();
|
||||
static int connected;
|
||||
private:
|
||||
void init();
|
||||
void readWrite(int sock);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#else
|
||||
int make_socket(uint16_t port);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef _JSOCKET_H_
|
||||
#define _JSOCKET_H_
|
||||
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
//TODO config ?
|
||||
#define SERVER_PORT 20666
|
||||
|
||||
class JSocket{
|
||||
public:
|
||||
queue<char> received_data;
|
||||
queue<char> tosend_data;
|
||||
static JSocket * mInstance;
|
||||
int start_server(const char *szIpAddr);
|
||||
int start_client(const char *szIpAddr);
|
||||
|
||||
JSocket();
|
||||
~JSocket();
|
||||
static int connected;
|
||||
private:
|
||||
void init();
|
||||
void readWrite(int sock);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#else
|
||||
int make_socket(uint16_t port);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+167
-167
@@ -1,167 +1,167 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JSPLINE_H
|
||||
#define _JSPLINE_H
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MID_POINT_THRESHOLD 1.0f
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Position of a single dot on screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param _x - X position.
|
||||
/// @param _y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
Point(float _x, float _y) { x = _x; y = _y; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor, set position to default (0.0f, 0.0f)
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
Point() { x = 0.0f; y = 0.0f; }
|
||||
|
||||
float x; ///< X position.
|
||||
float y; ///< Y position.
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Catmull Rom spline.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSpline
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSpline();
|
||||
~JSpline();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load spline from a file.
|
||||
///
|
||||
/// Here is a sample spline definition file:
|
||||
///
|
||||
/// @code
|
||||
/// <?xml version="1.0" standalone="no" ?>
|
||||
/// <path>
|
||||
/// <contro_point x="89" y="270" />
|
||||
/// <contro_point x="113" y="154" />
|
||||
/// <contro_point x="227" y="94" />
|
||||
/// <contro_point x="347" y="154" />
|
||||
/// <contro_point x="367" y="278" />
|
||||
/// </path>
|
||||
/// @endcode
|
||||
///
|
||||
/// @param filename - Name of spline definition file.
|
||||
/// @param xscale - Scaling factor for X of all control points.
|
||||
/// @param yscale - Scaling factor for Y of all control points.
|
||||
///
|
||||
/// @return True if loaded.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *filename, float xscale=1.0f, float yscale=1.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add a control point to the spline.
|
||||
///
|
||||
/// @param pt - Control point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddControlPoint(const Point &pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a control point of the spline.
|
||||
///
|
||||
/// @param index - Control point index.
|
||||
///
|
||||
/// @return Control point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetControlPoint(Point &point, int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Work out all pixels of the spline.
|
||||
///
|
||||
/// @note Have to call this function before calling GetPixel, GetPixelCount
|
||||
/// and Render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GeneratePixels();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a point between 2nd and 3rd control point.
|
||||
///
|
||||
/// @param t - Fraction of the curve between 2nd and 3rd control point. (0.0f ~ 1.0f)
|
||||
/// @param p0 - 1st control point.
|
||||
/// @param p1 - 2nd control point.
|
||||
/// @param p2 - 3rd control point.
|
||||
/// @param p3 - 4th control point.
|
||||
///
|
||||
/// @return Position of the desire point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a number of pixels for this spline.
|
||||
///
|
||||
/// @return Number of pixels for this spline.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetPixelCount();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a pixel on the spline.
|
||||
///
|
||||
/// @param index - Pixel index.
|
||||
///
|
||||
/// @return Position of the desire point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetPixel(Point &point, int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the spline to screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y, PIXEL_TYPE color=ARGB(255,255,255,255), PIXEL_TYPE controlColor=ARGB(192,0,192,0));
|
||||
|
||||
private:
|
||||
|
||||
vector<Point> mMidPoints;
|
||||
vector<Point> mPixels;
|
||||
int mCount;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JSPLINE_H
|
||||
#define _JSPLINE_H
|
||||
|
||||
#include "JRenderer.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MID_POINT_THRESHOLD 1.0f
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Position of a single dot on screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param _x - X position.
|
||||
/// @param _y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
Point(float _x, float _y) { x = _x; y = _y; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor, set position to default (0.0f, 0.0f)
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
Point() { x = 0.0f; y = 0.0f; }
|
||||
|
||||
float x; ///< X position.
|
||||
float y; ///< Y position.
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Catmull Rom spline.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSpline
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSpline();
|
||||
~JSpline();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load spline from a file.
|
||||
///
|
||||
/// Here is a sample spline definition file:
|
||||
///
|
||||
/// @code
|
||||
/// <?xml version="1.0" standalone="no" ?>
|
||||
/// <path>
|
||||
/// <contro_point x="89" y="270" />
|
||||
/// <contro_point x="113" y="154" />
|
||||
/// <contro_point x="227" y="94" />
|
||||
/// <contro_point x="347" y="154" />
|
||||
/// <contro_point x="367" y="278" />
|
||||
/// </path>
|
||||
/// @endcode
|
||||
///
|
||||
/// @param filename - Name of spline definition file.
|
||||
/// @param xscale - Scaling factor for X of all control points.
|
||||
/// @param yscale - Scaling factor for Y of all control points.
|
||||
///
|
||||
/// @return True if loaded.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *filename, float xscale=1.0f, float yscale=1.0f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add a control point to the spline.
|
||||
///
|
||||
/// @param pt - Control point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddControlPoint(const Point &pt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a control point of the spline.
|
||||
///
|
||||
/// @param index - Control point index.
|
||||
///
|
||||
/// @return Control point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetControlPoint(Point &point, int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Work out all pixels of the spline.
|
||||
///
|
||||
/// @note Have to call this function before calling GetPixel, GetPixelCount
|
||||
/// and Render.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GeneratePixels();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a point between 2nd and 3rd control point.
|
||||
///
|
||||
/// @param t - Fraction of the curve between 2nd and 3rd control point. (0.0f ~ 1.0f)
|
||||
/// @param p0 - 1st control point.
|
||||
/// @param p1 - 2nd control point.
|
||||
/// @param p2 - 3rd control point.
|
||||
/// @param p3 - 4th control point.
|
||||
///
|
||||
/// @return Position of the desire point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a number of pixels for this spline.
|
||||
///
|
||||
/// @return Number of pixels for this spline.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetPixelCount();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get a pixel on the spline.
|
||||
///
|
||||
/// @param index - Pixel index.
|
||||
///
|
||||
/// @return Position of the desire point.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void GetPixel(Point &point, int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render the spline to screen.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Render(float x, float y, PIXEL_TYPE color=ARGB(255,255,255,255), PIXEL_TYPE controlColor=ARGB(192,0,192,0));
|
||||
|
||||
private:
|
||||
|
||||
vector<Point> mMidPoints;
|
||||
vector<Point> mPixels;
|
||||
int mCount;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+487
-487
@@ -1,487 +1,487 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _SPRITE_H_
|
||||
#define _SPRITE_H_
|
||||
|
||||
#if defined (WIN32) || defined(LINUX) || defined(IOS)
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <fastmath.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Sprite is a container of single static image or animation frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSprite
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param tex - Texture for the first frame and the following frames.
|
||||
/// NULL to indicate no starting frame.
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSprite(JTexture *tex=NULL, float x=0.0f, float y=0.0f, float width=0.0f, float height=0.0f, bool flipped = false);
|
||||
|
||||
virtual ~JSprite();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set animation type.
|
||||
///
|
||||
/// @param type - Animation type.
|
||||
///
|
||||
/// @code
|
||||
/// ANIMATION_TYPE_LOOPING - Repeat playing (Default).
|
||||
/// ANIMATION_TYPE_ONCE_AND_GONE - Play animation once only.
|
||||
/// ANIMATION_TYPE_ONCE_AND_BACK - Play to end and then stay at first frame.
|
||||
/// ANIMATION_TYPE_PINGPONG - Play forward then backward and repeat.
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationType(int type);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable/Disable sprite.
|
||||
///
|
||||
/// @param f - True to enable, false to disable.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get current active status.
|
||||
///
|
||||
/// @return Active status.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Give sprite an id.
|
||||
///
|
||||
/// @param id - Id.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetId(int id);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get sprite id.
|
||||
///
|
||||
/// @return Sprite id.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetId();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Flip a frame or all frames horizontally when rendering.
|
||||
///
|
||||
/// @param flip - True to flip.
|
||||
/// @param index - Frame index, -1 to flip all frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFlip(bool flip, int index = -1);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add new animation frame.
|
||||
///
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddFrame(float x, float y, float width, float height, bool flipped = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add new animation frame.
|
||||
///
|
||||
/// @param tex - Texture for this frame and the following frames.
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddFrame(JTexture *tex, float x, float y, float width, float height, bool flipped = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set playback duration for each frame.
|
||||
///
|
||||
/// @param duration - Playback duration (in second) for each frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDuration(float duration);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get index of current frame.
|
||||
///
|
||||
/// @return Index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetCurrentFrameIndex();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set current frame to a particular index.
|
||||
///
|
||||
/// @param frame - The new index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCurrentFrameIndex(int frame);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get current frame image (quad).
|
||||
///
|
||||
/// @return Quad object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JQuad* GetCurrentFrame();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get numer of animation frames.
|
||||
///
|
||||
/// @return Numer of animation frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetFrameCount();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get frame image (quad).
|
||||
///
|
||||
/// @return Quad object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JQuad* GetFrame(int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Restart animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RestartAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get animation status.
|
||||
///
|
||||
/// @return animation status
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsAnimating();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move some distance from the current position.
|
||||
///
|
||||
/// @param x - X distance to move.
|
||||
/// @param y - Y distance to move.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Move(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set X position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetX(float x);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set Y position of the sprite.
|
||||
///
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetY(float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X position of the sprite.
|
||||
///
|
||||
/// @return X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetX();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y position of the sprite.
|
||||
///
|
||||
/// @return Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetY();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X velocity.
|
||||
///
|
||||
/// @return X velocity.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetXVelocity();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y velocity.
|
||||
///
|
||||
/// @return Y velocity.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetYVelocity();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set alpha value for rendering.
|
||||
///
|
||||
/// @param alpha - Alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAlpha(float alpha);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get alpha value.
|
||||
///
|
||||
/// @return Alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetAlpha();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale of the sprite.
|
||||
///
|
||||
/// @param hscale - Horizontal scale.
|
||||
/// @param vscale - Vertical scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float hscale, float vscale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale of the sprite.
|
||||
///
|
||||
/// @param scale - Scale for both horizontal and vertical dimension.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get scale of the sprite.
|
||||
///
|
||||
/// @return Scale of horizontal (assume same as the vertical).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetScale();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rotation factor of the sprite.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rotation factor of the sprite.
|
||||
///
|
||||
/// @return Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetRotation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving speed of the sprite.
|
||||
///
|
||||
/// @param speed - Moving speed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetSpeed(float speed);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get moving speed of the sprite.
|
||||
///
|
||||
/// @return Moving speed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetSpeed();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving direction of the sprite.
|
||||
///
|
||||
/// @param angle - Moving angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDirection(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving direction of the sprite based on a targeting position.
|
||||
///
|
||||
/// @param x - X position of the target.
|
||||
/// @param y - Y position of the target.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDirection(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get moving direction of the sprite.
|
||||
///
|
||||
/// @return Moving angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetDirection();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set anchor point of a frame or all frames of the sprite. All rotation
|
||||
/// and collision operations are based on this anchor point.
|
||||
///
|
||||
/// @param x - X position of the anchor point.
|
||||
/// @param y - Y position of the anchor point.
|
||||
/// @param index - Frame index, -1 for all frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHotSpot(float x, float y, int index=-1);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set color of the sprite for rendering.
|
||||
///
|
||||
/// @param color - Color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum ANIMATION_TYPE
|
||||
///
|
||||
/// Type of animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum ANIMATION_TYPE
|
||||
{
|
||||
ANIMATION_TYPE_LOOPING, ///< Repeat playing (Default).
|
||||
ANIMATION_TYPE_ONCE_AND_STAY, ///< Play to the end and stay at last frame
|
||||
ANIMATION_TYPE_ONCE_AND_BACK, ///< Play to end and then stay at first frame.
|
||||
ANIMATION_TYPE_ONCE_AND_GONE, ///< Play animation once only.
|
||||
ANIMATION_TYPE_PINGPONG ///< Play forward then backward and repeat.
|
||||
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
JTexture* mTex;
|
||||
vector<JQuad*> mFrames;
|
||||
float mDuration;
|
||||
float mTimer;
|
||||
int mFrameCount;
|
||||
int mCurrentFrame;
|
||||
int mAnimationType;
|
||||
int mDelta;
|
||||
bool mAnimating;
|
||||
|
||||
float mAlpha;
|
||||
PIXEL_TYPE mColor;
|
||||
|
||||
float mVScale;
|
||||
float mHScale;
|
||||
|
||||
float mRotation;
|
||||
float mDirection;
|
||||
float mSpeed;
|
||||
|
||||
int mId;
|
||||
bool mActive;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class JSpriteList
|
||||
{
|
||||
protected:
|
||||
|
||||
int mCount;
|
||||
JSprite** mList;
|
||||
//JSpriteList** mVictims;
|
||||
//JCollisionListener* mCollisionListener;
|
||||
|
||||
public:
|
||||
JSpriteList(int count);
|
||||
~JSpriteList();
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
void AddSprite(JSprite* sprite);//, JSpriteList* victim);
|
||||
|
||||
//bool CheckCollision(JSprite* sprite); // check collision against the provided list
|
||||
//void SetCollisionListener(JCollisionListener *listener);
|
||||
JSprite* Activate(float x, float y);
|
||||
void Activate(float x, float y, int index);
|
||||
|
||||
JSprite* GetSprite(int index);
|
||||
|
||||
void EnableAll(bool flag);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _SPRITE_H_
|
||||
#define _SPRITE_H_
|
||||
|
||||
#if defined (WIN32) || defined(LINUX) || defined(IOS)
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <fastmath.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "JRenderer.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Sprite is a container of single static image or animation frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JSprite
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param tex - Texture for the first frame and the following frames.
|
||||
/// NULL to indicate no starting frame.
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSprite(JTexture *tex=NULL, float x=0.0f, float y=0.0f, float width=0.0f, float height=0.0f, bool flipped = false);
|
||||
|
||||
virtual ~JSprite();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Update animation.
|
||||
///
|
||||
/// @param dt - Delta time since last update (in second).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Update(float dt);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
virtual void Render();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set animation type.
|
||||
///
|
||||
/// @param type - Animation type.
|
||||
///
|
||||
/// @code
|
||||
/// ANIMATION_TYPE_LOOPING - Repeat playing (Default).
|
||||
/// ANIMATION_TYPE_ONCE_AND_GONE - Play animation once only.
|
||||
/// ANIMATION_TYPE_ONCE_AND_BACK - Play to end and then stay at first frame.
|
||||
/// ANIMATION_TYPE_PINGPONG - Play forward then backward and repeat.
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAnimationType(int type);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Enable/Disable sprite.
|
||||
///
|
||||
/// @param f - True to enable, false to disable.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetActive(bool f);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get current active status.
|
||||
///
|
||||
/// @return Active status.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsActive();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Give sprite an id.
|
||||
///
|
||||
/// @param id - Id.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetId(int id);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get sprite id.
|
||||
///
|
||||
/// @return Sprite id.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetId();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Flip a frame or all frames horizontally when rendering.
|
||||
///
|
||||
/// @param flip - True to flip.
|
||||
/// @param index - Frame index, -1 to flip all frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetFlip(bool flip, int index = -1);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add new animation frame.
|
||||
///
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddFrame(float x, float y, float width, float height, bool flipped = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Add new animation frame.
|
||||
///
|
||||
/// @param tex - Texture for this frame and the following frames.
|
||||
/// @param x - X of the frame in texture.
|
||||
/// @param y - Y of the frame in texture.
|
||||
/// @param width - Width of the frame.
|
||||
/// @param height - Height of the frame.
|
||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void AddFrame(JTexture *tex, float x, float y, float width, float height, bool flipped = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set playback duration for each frame.
|
||||
///
|
||||
/// @param duration - Playback duration (in second) for each frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDuration(float duration);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get index of current frame.
|
||||
///
|
||||
/// @return Index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetCurrentFrameIndex();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set current frame to a particular index.
|
||||
///
|
||||
/// @param frame - The new index of current frame.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetCurrentFrameIndex(int frame);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get current frame image (quad).
|
||||
///
|
||||
/// @return Quad object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JQuad* GetCurrentFrame();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get numer of animation frames.
|
||||
///
|
||||
/// @return Numer of animation frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetFrameCount();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get frame image (quad).
|
||||
///
|
||||
/// @return Quad object.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JQuad* GetFrame(int index);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Restart animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RestartAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Start animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StartAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopAnimation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get animation status.
|
||||
///
|
||||
/// @return animation status
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool IsAnimating();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Move some distance from the current position.
|
||||
///
|
||||
/// @param x - X distance to move.
|
||||
/// @param y - Y distance to move.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Move(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetPosition(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set X position of the sprite.
|
||||
///
|
||||
/// @param x - X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetX(float x);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set Y position of the sprite.
|
||||
///
|
||||
/// @param y - Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetY(float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X position of the sprite.
|
||||
///
|
||||
/// @return X position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetX();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y position of the sprite.
|
||||
///
|
||||
/// @return Y position.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetY();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get X velocity.
|
||||
///
|
||||
/// @return X velocity.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetXVelocity();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get Y velocity.
|
||||
///
|
||||
/// @return Y velocity.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetYVelocity();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set alpha value for rendering.
|
||||
///
|
||||
/// @param alpha - Alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAlpha(float alpha);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get alpha value.
|
||||
///
|
||||
/// @return Alpha value.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetAlpha();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale of the sprite.
|
||||
///
|
||||
/// @param hscale - Horizontal scale.
|
||||
/// @param vscale - Vertical scale.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float hscale, float vscale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set scale of the sprite.
|
||||
///
|
||||
/// @param scale - Scale for both horizontal and vertical dimension.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetScale(float scale);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get scale of the sprite.
|
||||
///
|
||||
/// @return Scale of horizontal (assume same as the vertical).
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetScale();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set rotation factor of the sprite.
|
||||
///
|
||||
/// @param rot - Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetRotation(float rot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get rotation factor of the sprite.
|
||||
///
|
||||
/// @return Rotation angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetRotation();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving speed of the sprite.
|
||||
///
|
||||
/// @param speed - Moving speed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetSpeed(float speed);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get moving speed of the sprite.
|
||||
///
|
||||
/// @return Moving speed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetSpeed();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving direction of the sprite.
|
||||
///
|
||||
/// @param angle - Moving angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDirection(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set moving direction of the sprite based on a targeting position.
|
||||
///
|
||||
/// @param x - X position of the target.
|
||||
/// @param y - Y position of the target.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetDirection(float x, float y);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get moving direction of the sprite.
|
||||
///
|
||||
/// @return Moving angle in radian.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
float GetDirection();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set anchor point of a frame or all frames of the sprite. All rotation
|
||||
/// and collision operations are based on this anchor point.
|
||||
///
|
||||
/// @param x - X position of the anchor point.
|
||||
/// @param y - Y position of the anchor point.
|
||||
/// @param index - Frame index, -1 for all frames.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetHotSpot(float x, float y, int index=-1);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set color of the sprite for rendering.
|
||||
///
|
||||
/// @param color - Color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum ANIMATION_TYPE
|
||||
///
|
||||
/// Type of animation.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum ANIMATION_TYPE
|
||||
{
|
||||
ANIMATION_TYPE_LOOPING, ///< Repeat playing (Default).
|
||||
ANIMATION_TYPE_ONCE_AND_STAY, ///< Play to the end and stay at last frame
|
||||
ANIMATION_TYPE_ONCE_AND_BACK, ///< Play to end and then stay at first frame.
|
||||
ANIMATION_TYPE_ONCE_AND_GONE, ///< Play animation once only.
|
||||
ANIMATION_TYPE_PINGPONG ///< Play forward then backward and repeat.
|
||||
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static JRenderer* mRenderer;
|
||||
|
||||
JTexture* mTex;
|
||||
vector<JQuad*> mFrames;
|
||||
float mDuration;
|
||||
float mTimer;
|
||||
int mFrameCount;
|
||||
int mCurrentFrame;
|
||||
int mAnimationType;
|
||||
int mDelta;
|
||||
bool mAnimating;
|
||||
|
||||
float mAlpha;
|
||||
PIXEL_TYPE mColor;
|
||||
|
||||
float mVScale;
|
||||
float mHScale;
|
||||
|
||||
float mRotation;
|
||||
float mDirection;
|
||||
float mSpeed;
|
||||
|
||||
int mId;
|
||||
bool mActive;
|
||||
|
||||
float mX;
|
||||
float mY;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class JSpriteList
|
||||
{
|
||||
protected:
|
||||
|
||||
int mCount;
|
||||
JSprite** mList;
|
||||
//JSpriteList** mVictims;
|
||||
//JCollisionListener* mCollisionListener;
|
||||
|
||||
public:
|
||||
JSpriteList(int count);
|
||||
~JSpriteList();
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
void AddSprite(JSprite* sprite);//, JSpriteList* victim);
|
||||
|
||||
//bool CheckCollision(JSprite* sprite); // check collision against the provided list
|
||||
//void SetCollisionListener(JCollisionListener *listener);
|
||||
JSprite* Activate(float x, float y);
|
||||
void Activate(float x, float y, int index);
|
||||
|
||||
JSprite* GetSprite(int index);
|
||||
|
||||
void EnableAll(bool flag);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+307
-307
@@ -1,307 +1,307 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JTTFONT_H
|
||||
#define _JTTFONT_H
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#define TTF_CACHE_SIZE 256
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// True Type font support with the help of Freetype library. JTTFont has
|
||||
/// a simple caching system so that a character which has been rendered before
|
||||
/// can be retrieved from the cache instead of drawing it again by the
|
||||
/// Freetype library. This can give you a much faster rendering speed.
|
||||
/// Also, if you only need to use a limited number of characters
|
||||
/// in your game, you can actually cache all your characters in the cache
|
||||
/// beforehand and unload the font to save memory.
|
||||
///
|
||||
/// @par For example, if you only want to use the standard ASCII characters in
|
||||
/// your game:
|
||||
///
|
||||
/// @code
|
||||
///
|
||||
/// // in Create()
|
||||
/// mTTFont = new JTTFont();
|
||||
/// mTTFont->Load("arial.ttf", 32); // size 32
|
||||
///
|
||||
/// if (mTTFont->PreCacheASCII())
|
||||
/// mTTFont->Unload();
|
||||
/// ...
|
||||
///
|
||||
/// // in Render()
|
||||
/// mTTFont->RenderString("Hello World!", 240, 80, JGETEXT_CENTER);
|
||||
///
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JTTFont
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param cacheImageSize - Size of the texture used for caching. This can
|
||||
/// be 64x64, 128x128(default), 256x256 or 512x512.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JTTFont(int cacheImageSize=CACHE_IMAGE_256x256);
|
||||
|
||||
~JTTFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum FONT_LOADING_MODE
|
||||
///
|
||||
/// Font loading options.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum FONT_LOADING_MODE
|
||||
{
|
||||
MODE_NORMAL, ///< Load only.
|
||||
MODE_PRECACHE_ASCII, ///< Load the font and cache all ASCII characters.
|
||||
MODE_PRECACHE_ASCII_EX ///< Load the font and cache all Extended ASCII characters.
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum CACHE_IMAGE_SIZE
|
||||
///
|
||||
/// Size of the texture used for caching.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum CACHE_IMAGE_SIZE
|
||||
{
|
||||
CACHE_IMAGE_64x64, ///< 64x64
|
||||
CACHE_IMAGE_128x128, ///< 128x128
|
||||
CACHE_IMAGE_256x256, ///< 256x256
|
||||
CACHE_IMAGE_512x512 ///< 512x512
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set color of font.
|
||||
///
|
||||
/// @param color - Font color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle of the font for rendering.
|
||||
///
|
||||
/// @param angle - Angle in radians.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAngle(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font size.
|
||||
///
|
||||
/// @param size - Font size.
|
||||
///
|
||||
/// @note Setting font size will clear the cache.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool SetSize(int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load font file.
|
||||
///
|
||||
/// @param filename - Name of True Type font.
|
||||
/// @param size - Initial font size. Default is 12.
|
||||
/// @param mode - Loading mode.
|
||||
///
|
||||
/// @return - True if no error.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *filename, int size=12, int mode=MODE_NORMAL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Create font using font data from another JTTFont instance.
|
||||
///
|
||||
/// @param fontSource - Source of font data.
|
||||
/// @param size - Initial font size. Default is 12.
|
||||
/// @param mode - Loading mode.
|
||||
///
|
||||
/// @return - True if no error.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(JTTFont *fontSource, int size=12, int mode=MODE_NORMAL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Unload font file and related Freetype objects from memory.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Unload(void);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render Unicode string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const u16 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render ASCII string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const char *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render Chinese (GBK) string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const u8 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of an Unicode string into cache
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const u16 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of an ASCII string into cache.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const char *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of a Chinese (GBK) string into cache.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const u8 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of Unicode string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const u16 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of ASCII string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const char *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of Chinese (GBK) string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const u8 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put all standard ASCII characters (0x20-0x7F) into cache.
|
||||
///
|
||||
/// @return - True if success.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool PreCacheASCII();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put all ASCII characters (0x20-0xFF) into cache.
|
||||
///
|
||||
/// @return - True if success.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool PreCacheExtendedASCII();
|
||||
|
||||
void SetAntialias(bool flag);
|
||||
|
||||
protected:
|
||||
FT_Library GetFontLibrary();
|
||||
FT_Byte* GetFontBits();
|
||||
int GetFontBitsSize();
|
||||
|
||||
private:
|
||||
|
||||
int RenderString(const u16 *text, float x, float y, bool render);
|
||||
int RenderString(const char *text, float x, float y, bool render);
|
||||
int RenderString(const u8 *text, float x, float y, bool render);
|
||||
|
||||
|
||||
int PreCacheChar(u16 ch, u16 cachedCode);
|
||||
int GetCachedChar(u16 cachedCode);
|
||||
void DrawBitmap(void *image, FT_Bitmap *bitmap, FT_Int x, FT_Int y, int width, int height);
|
||||
|
||||
|
||||
JTexture* mTexture;
|
||||
|
||||
JQuad* mQuads[TTF_CACHE_SIZE];
|
||||
u16 mCachedCode[TTF_CACHE_SIZE];
|
||||
u8 mXAdvance[TTF_CACHE_SIZE];
|
||||
|
||||
int mCurr;
|
||||
|
||||
int mTexWidth;
|
||||
int mTexHeight;
|
||||
int mMaxCharWidth;
|
||||
int mMaxCharHeight;
|
||||
int mMaxCharCount;
|
||||
int mColCount;
|
||||
int mRowCount;
|
||||
|
||||
bool mASCIIDirectMapping;
|
||||
|
||||
JTTFont* mFontSource;
|
||||
bool mSharingFont;
|
||||
|
||||
int mSize;
|
||||
PIXEL_TYPE mColor;
|
||||
float mAngle;
|
||||
FT_Library mLibrary;
|
||||
FT_Face mFace;
|
||||
|
||||
FT_Byte* mFontBits;
|
||||
int mFontBitsSize;
|
||||
|
||||
bool mAntialias;
|
||||
|
||||
bool mFontLoaded;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _JTTFONT_H
|
||||
#define _JTTFONT_H
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#define TTF_CACHE_SIZE 256
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// True Type font support with the help of Freetype library. JTTFont has
|
||||
/// a simple caching system so that a character which has been rendered before
|
||||
/// can be retrieved from the cache instead of drawing it again by the
|
||||
/// Freetype library. This can give you a much faster rendering speed.
|
||||
/// Also, if you only need to use a limited number of characters
|
||||
/// in your game, you can actually cache all your characters in the cache
|
||||
/// beforehand and unload the font to save memory.
|
||||
///
|
||||
/// @par For example, if you only want to use the standard ASCII characters in
|
||||
/// your game:
|
||||
///
|
||||
/// @code
|
||||
///
|
||||
/// // in Create()
|
||||
/// mTTFont = new JTTFont();
|
||||
/// mTTFont->Load("arial.ttf", 32); // size 32
|
||||
///
|
||||
/// if (mTTFont->PreCacheASCII())
|
||||
/// mTTFont->Unload();
|
||||
/// ...
|
||||
///
|
||||
/// // in Render()
|
||||
/// mTTFont->RenderString("Hello World!", 240, 80, JGETEXT_CENTER);
|
||||
///
|
||||
/// @endcode
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class JTTFont
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Constructor.
|
||||
///
|
||||
/// @param cacheImageSize - Size of the texture used for caching. This can
|
||||
/// be 64x64, 128x128(default), 256x256 or 512x512.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JTTFont(int cacheImageSize=CACHE_IMAGE_256x256);
|
||||
|
||||
~JTTFont();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum FONT_LOADING_MODE
|
||||
///
|
||||
/// Font loading options.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum FONT_LOADING_MODE
|
||||
{
|
||||
MODE_NORMAL, ///< Load only.
|
||||
MODE_PRECACHE_ASCII, ///< Load the font and cache all ASCII characters.
|
||||
MODE_PRECACHE_ASCII_EX ///< Load the font and cache all Extended ASCII characters.
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// \enum CACHE_IMAGE_SIZE
|
||||
///
|
||||
/// Size of the texture used for caching.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
enum CACHE_IMAGE_SIZE
|
||||
{
|
||||
CACHE_IMAGE_64x64, ///< 64x64
|
||||
CACHE_IMAGE_128x128, ///< 128x128
|
||||
CACHE_IMAGE_256x256, ///< 256x256
|
||||
CACHE_IMAGE_512x512 ///< 512x512
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set color of font.
|
||||
///
|
||||
/// @param color - Font color.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetColor(PIXEL_TYPE color);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set angle of the font for rendering.
|
||||
///
|
||||
/// @param angle - Angle in radians.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetAngle(float angle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set font size.
|
||||
///
|
||||
/// @param size - Font size.
|
||||
///
|
||||
/// @note Setting font size will clear the cache.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool SetSize(int size);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load font file.
|
||||
///
|
||||
/// @param filename - Name of True Type font.
|
||||
/// @param size - Initial font size. Default is 12.
|
||||
/// @param mode - Loading mode.
|
||||
///
|
||||
/// @return - True if no error.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(const char *filename, int size=12, int mode=MODE_NORMAL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Create font using font data from another JTTFont instance.
|
||||
///
|
||||
/// @param fontSource - Source of font data.
|
||||
/// @param size - Initial font size. Default is 12.
|
||||
/// @param mode - Loading mode.
|
||||
///
|
||||
/// @return - True if no error.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool Load(JTTFont *fontSource, int size=12, int mode=MODE_NORMAL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Unload font file and related Freetype objects from memory.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void Unload(void);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render Unicode string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const u16 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render ASCII string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const char *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Render Chinese (GBK) string to screen.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
/// @param x - X position.
|
||||
/// @param y - Y position.
|
||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void RenderString(const u8 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of an Unicode string into cache
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const u16 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of an ASCII string into cache.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const char *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put characters of a Chinese (GBK) string into cache.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PreCacheString(const u8 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of Unicode string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated Unicode-16 string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const u16 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of ASCII string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated ASCII string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const char *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get width of Chinese (GBK) string on screen.
|
||||
///
|
||||
/// @param text - NULL terminated GBK encoded string.
|
||||
///
|
||||
/// @return - Width in pixels
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int GetWidth(const u8 *text);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put all standard ASCII characters (0x20-0x7F) into cache.
|
||||
///
|
||||
/// @return - True if success.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool PreCacheASCII();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Put all ASCII characters (0x20-0xFF) into cache.
|
||||
///
|
||||
/// @return - True if success.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool PreCacheExtendedASCII();
|
||||
|
||||
void SetAntialias(bool flag);
|
||||
|
||||
protected:
|
||||
FT_Library GetFontLibrary();
|
||||
FT_Byte* GetFontBits();
|
||||
int GetFontBitsSize();
|
||||
|
||||
private:
|
||||
|
||||
int RenderString(const u16 *text, float x, float y, bool render);
|
||||
int RenderString(const char *text, float x, float y, bool render);
|
||||
int RenderString(const u8 *text, float x, float y, bool render);
|
||||
|
||||
|
||||
int PreCacheChar(u16 ch, u16 cachedCode);
|
||||
int GetCachedChar(u16 cachedCode);
|
||||
void DrawBitmap(void *image, FT_Bitmap *bitmap, FT_Int x, FT_Int y, int width, int height);
|
||||
|
||||
|
||||
JTexture* mTexture;
|
||||
|
||||
JQuad* mQuads[TTF_CACHE_SIZE];
|
||||
u16 mCachedCode[TTF_CACHE_SIZE];
|
||||
u8 mXAdvance[TTF_CACHE_SIZE];
|
||||
|
||||
int mCurr;
|
||||
|
||||
int mTexWidth;
|
||||
int mTexHeight;
|
||||
int mMaxCharWidth;
|
||||
int mMaxCharHeight;
|
||||
int mMaxCharCount;
|
||||
int mColCount;
|
||||
int mRowCount;
|
||||
|
||||
bool mASCIIDirectMapping;
|
||||
|
||||
JTTFont* mFontSource;
|
||||
bool mSharingFont;
|
||||
|
||||
int mSize;
|
||||
PIXEL_TYPE mColor;
|
||||
float mAngle;
|
||||
FT_Library mLibrary;
|
||||
FT_Face mFace;
|
||||
|
||||
FT_Byte* mFontBits;
|
||||
int mFontBitsSize;
|
||||
|
||||
bool mAntialias;
|
||||
|
||||
bool mFontLoaded;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+73
-73
@@ -1,73 +1,73 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _VECTOR2D_H
|
||||
#define _VECTOR2D_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <math.h>
|
||||
#elif (defined LINUX) || (defined IOS)
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <fastmath.h>
|
||||
#endif
|
||||
|
||||
|
||||
struct Vector2D
|
||||
{
|
||||
|
||||
float x, y;
|
||||
static const Vector2D& Blank() { static const Vector2D V(0, 0); return V; }
|
||||
|
||||
inline Vector2D(void) {}
|
||||
|
||||
inline Vector2D(float _x,float _y) : x(_x), y(_y) {}
|
||||
|
||||
inline Vector2D &operator /=(const float scalar) { x /= scalar; y /= scalar; return *this; }
|
||||
|
||||
inline Vector2D &operator *=(const float scalar) { x *= scalar; y *= scalar; return *this; }
|
||||
|
||||
inline Vector2D &operator +=(const Vector2D &v) { x += v.x; y += v.y; return *this; }
|
||||
|
||||
inline Vector2D &operator -=(const Vector2D &v) { x -= v.x; y -= v.y; return *this; }
|
||||
|
||||
inline bool operator ==(const Vector2D &v) const { return x == v.x && y == v.y; }
|
||||
inline bool operator !=(const Vector2D &v) const { return x != v.x || y != v.y; }
|
||||
|
||||
|
||||
// cross product
|
||||
inline float operator ^ (const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
||||
|
||||
// dot product
|
||||
inline float operator * (const Vector2D &v) const { return (x*v.x) + (y*v.y); }
|
||||
|
||||
inline float Dot(const Vector2D &v) const { return (x * v.x) + (y * v.y); }
|
||||
inline float Cross(const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
||||
|
||||
|
||||
inline Vector2D operator * (float s) const { return Vector2D(x*s, y*s); }
|
||||
inline Vector2D operator / (float s) const { return Vector2D(x/s, y/s); }
|
||||
inline Vector2D operator + (const Vector2D &v) const { return Vector2D(x+v.x, y+v.y); }
|
||||
inline Vector2D operator - (const Vector2D &v) const { return Vector2D(x-v.x, y-v.y); }
|
||||
friend Vector2D operator * (float k, const Vector2D& v) { return Vector2D(v.x*k, v.y*k); }
|
||||
inline Vector2D operator -(void) const { return Vector2D(-x, -y); }
|
||||
|
||||
inline float Length(void) const;
|
||||
float Normalize(void) ;
|
||||
Vector2D Direction(void) const;
|
||||
float Angle(const Vector2D& xE);
|
||||
Vector2D& Rotate(float angle);
|
||||
Vector2D& Rotate(const Vector2D& xCentre, float fAngle);
|
||||
void Clamp(const Vector2D& min, const Vector2D& max);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _VECTOR2D_H
|
||||
#define _VECTOR2D_H
|
||||
|
||||
#ifdef WIN32
|
||||
#include <math.h>
|
||||
#elif (defined LINUX) || (defined IOS)
|
||||
#include <math.h>
|
||||
#else
|
||||
#include <fastmath.h>
|
||||
#endif
|
||||
|
||||
|
||||
struct Vector2D
|
||||
{
|
||||
|
||||
float x, y;
|
||||
static const Vector2D& Blank() { static const Vector2D V(0, 0); return V; }
|
||||
|
||||
inline Vector2D(void) {}
|
||||
|
||||
inline Vector2D(float _x,float _y) : x(_x), y(_y) {}
|
||||
|
||||
inline Vector2D &operator /=(const float scalar) { x /= scalar; y /= scalar; return *this; }
|
||||
|
||||
inline Vector2D &operator *=(const float scalar) { x *= scalar; y *= scalar; return *this; }
|
||||
|
||||
inline Vector2D &operator +=(const Vector2D &v) { x += v.x; y += v.y; return *this; }
|
||||
|
||||
inline Vector2D &operator -=(const Vector2D &v) { x -= v.x; y -= v.y; return *this; }
|
||||
|
||||
inline bool operator ==(const Vector2D &v) const { return x == v.x && y == v.y; }
|
||||
inline bool operator !=(const Vector2D &v) const { return x != v.x || y != v.y; }
|
||||
|
||||
|
||||
// cross product
|
||||
inline float operator ^ (const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
||||
|
||||
// dot product
|
||||
inline float operator * (const Vector2D &v) const { return (x*v.x) + (y*v.y); }
|
||||
|
||||
inline float Dot(const Vector2D &v) const { return (x * v.x) + (y * v.y); }
|
||||
inline float Cross(const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
||||
|
||||
|
||||
inline Vector2D operator * (float s) const { return Vector2D(x*s, y*s); }
|
||||
inline Vector2D operator / (float s) const { return Vector2D(x/s, y/s); }
|
||||
inline Vector2D operator + (const Vector2D &v) const { return Vector2D(x+v.x, y+v.y); }
|
||||
inline Vector2D operator - (const Vector2D &v) const { return Vector2D(x-v.x, y-v.y); }
|
||||
friend Vector2D operator * (float k, const Vector2D& v) { return Vector2D(v.x*k, v.y*k); }
|
||||
inline Vector2D operator -(void) const { return Vector2D(-x, -y); }
|
||||
|
||||
inline float Length(void) const;
|
||||
float Normalize(void) ;
|
||||
Vector2D Direction(void) const;
|
||||
float Angle(const Vector2D& xE);
|
||||
Vector2D& Rotate(float angle);
|
||||
Vector2D& Rotate(const Vector2D& xCentre, float fAngle);
|
||||
void Clamp(const Vector2D& min, const Vector2D& max);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+95
-95
@@ -1,95 +1,95 @@
|
||||
#ifndef __VECTOR3D_H_
|
||||
#define __VECTOR3D_H_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*************************** Macros and constants ***************************/
|
||||
// returns a number ranging from -1.0 to 1.0
|
||||
#define FRAND (((float)rand()-(float)rand())/RAND_MAX)
|
||||
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
||||
|
||||
#define SQUARE(x) (x)*(x)
|
||||
|
||||
|
||||
struct Vector3D
|
||||
{
|
||||
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
Vector3D(const Vector3D &v) : x(v.x), y(v.y), z(v.z) {}
|
||||
Vector3D() : x(0.0f), y(0.0f), z(0.0f) {}
|
||||
|
||||
Vector3D& operator=(const Vector3D &rhs)
|
||||
{
|
||||
x = rhs.x;
|
||||
y = rhs.y;
|
||||
z = rhs.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// vector add
|
||||
Vector3D operator+(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(x + rhs.x, y + rhs.y, z + rhs.z);
|
||||
}
|
||||
|
||||
// vector subtract
|
||||
Vector3D operator-(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(x - rhs.x, y - rhs.y, z - rhs.z);
|
||||
}
|
||||
|
||||
// scalar multiplication
|
||||
Vector3D operator*(const float scalar) const
|
||||
{
|
||||
return Vector3D(x * scalar, y * scalar, z * scalar);
|
||||
}
|
||||
|
||||
// dot product
|
||||
float operator*(const Vector3D &rhs) const
|
||||
{
|
||||
return x * rhs.x + y * rhs.y + z * rhs.z;
|
||||
}
|
||||
|
||||
// cross product
|
||||
Vector3D operator^(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(y * rhs.z - rhs.y * z, rhs.x * z - x * rhs.z, x * rhs.y - rhs.x * y);
|
||||
}
|
||||
|
||||
float& operator[](int index)
|
||||
{
|
||||
return v[index];
|
||||
}
|
||||
|
||||
float Length()
|
||||
{
|
||||
float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
||||
return (length != 0.0f) ? length : 1.0f;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Normalize()
|
||||
|
||||
Helper function to normalize vectors
|
||||
*****************************************************************************/
|
||||
Vector3D Normalize()
|
||||
{
|
||||
*this = *this * (1.0f/Length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
float v[3];
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __VECTOR3D_H_
|
||||
#define __VECTOR3D_H_
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*************************** Macros and constants ***************************/
|
||||
// returns a number ranging from -1.0 to 1.0
|
||||
#define FRAND (((float)rand()-(float)rand())/RAND_MAX)
|
||||
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
||||
|
||||
#define SQUARE(x) (x)*(x)
|
||||
|
||||
|
||||
struct Vector3D
|
||||
{
|
||||
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
Vector3D(const Vector3D &v) : x(v.x), y(v.y), z(v.z) {}
|
||||
Vector3D() : x(0.0f), y(0.0f), z(0.0f) {}
|
||||
|
||||
Vector3D& operator=(const Vector3D &rhs)
|
||||
{
|
||||
x = rhs.x;
|
||||
y = rhs.y;
|
||||
z = rhs.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// vector add
|
||||
Vector3D operator+(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(x + rhs.x, y + rhs.y, z + rhs.z);
|
||||
}
|
||||
|
||||
// vector subtract
|
||||
Vector3D operator-(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(x - rhs.x, y - rhs.y, z - rhs.z);
|
||||
}
|
||||
|
||||
// scalar multiplication
|
||||
Vector3D operator*(const float scalar) const
|
||||
{
|
||||
return Vector3D(x * scalar, y * scalar, z * scalar);
|
||||
}
|
||||
|
||||
// dot product
|
||||
float operator*(const Vector3D &rhs) const
|
||||
{
|
||||
return x * rhs.x + y * rhs.y + z * rhs.z;
|
||||
}
|
||||
|
||||
// cross product
|
||||
Vector3D operator^(const Vector3D &rhs) const
|
||||
{
|
||||
return Vector3D(y * rhs.z - rhs.y * z, rhs.x * z - x * rhs.z, x * rhs.y - rhs.x * y);
|
||||
}
|
||||
|
||||
float& operator[](int index)
|
||||
{
|
||||
return v[index];
|
||||
}
|
||||
|
||||
float Length()
|
||||
{
|
||||
float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
||||
return (length != 0.0f) ? length : 1.0f;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
Normalize()
|
||||
|
||||
Helper function to normalize vectors
|
||||
*****************************************************************************/
|
||||
Vector3D Normalize()
|
||||
{
|
||||
*this = *this * (1.0f/Length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
float v[3];
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+81
-81
@@ -1,81 +1,81 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeColor*** helper classes
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGECOLOR_H
|
||||
#define HGECOLOR_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
|
||||
#include "../JTypes.h"
|
||||
|
||||
#define hgeColor hgeColorRGB
|
||||
|
||||
inline void ColorClamp(float &x) { if(x<0.0f) x=0.0f; if(x>1.0f) x=1.0f; }
|
||||
|
||||
|
||||
class hgeColorRGB
|
||||
{
|
||||
public:
|
||||
float r,g,b,a;
|
||||
|
||||
hgeColorRGB(float _r, float _g, float _b, float _a) { r=_r; g=_g; b=_b; a=_a; }
|
||||
hgeColorRGB(DWORD col) { SetHWColor(col); }
|
||||
hgeColorRGB() { r=g=b=a=0; }
|
||||
|
||||
hgeColorRGB operator- (const hgeColorRGB &c) const { return hgeColorRGB(r-c.r, g-c.g, b-c.b, a-c.a); }
|
||||
hgeColorRGB operator+ (const hgeColorRGB &c) const { return hgeColorRGB(r+c.r, g+c.g, b+c.b, a+c.a); }
|
||||
hgeColorRGB operator* (const hgeColorRGB &c) const { return hgeColorRGB(r*c.r, g*c.g, b*c.b, a*c.a); }
|
||||
hgeColorRGB& operator-= (const hgeColorRGB &c) { r-=c.r; g-=c.g; b-=c.b; a-=c.a; return *this; }
|
||||
hgeColorRGB& operator+= (const hgeColorRGB &c) { r+=c.r; g+=c.g; b+=c.b; a+=c.a; return *this; }
|
||||
bool operator== (const hgeColorRGB &c) const { return (r==c.r && g==c.g && b==c.b && a==c.a); }
|
||||
bool operator!= (const hgeColorRGB &c) const { return (r!=c.r || g!=c.g || b!=c.b || a!=c.a); }
|
||||
|
||||
hgeColorRGB operator/ (const float scalar) const { return hgeColorRGB(r/scalar, g/scalar, b/scalar, a/scalar); }
|
||||
hgeColorRGB operator* (const float scalar) const { return hgeColorRGB(r*scalar, g*scalar, b*scalar, a*scalar); }
|
||||
hgeColorRGB& operator*= (const float scalar) { r*=scalar; g*=scalar; b*=scalar; a*=scalar; return *this; }
|
||||
|
||||
void Clamp() { ColorClamp(r); ColorClamp(g); ColorClamp(b); ColorClamp(a); }
|
||||
void SetHWColor(DWORD col) { a = (col>>24)/255.0f; r = ((col>>16) & 0xFF)/255.0f; g = ((col>>8) & 0xFF)/255.0f; b = (col & 0xFF)/255.0f; }
|
||||
DWORD GetHWColor() const { return ARGB(((int)(a*255.0f)), ((int)(r*255.0f)), ((int)(g*255.0f)), ((int)(b*255.0f))); }
|
||||
};
|
||||
|
||||
inline hgeColorRGB operator* (const float sc, const hgeColorRGB &c) { return c*sc; }
|
||||
|
||||
|
||||
class hgeColorHSV
|
||||
{
|
||||
public:
|
||||
float h,s,v,a;
|
||||
|
||||
hgeColorHSV(float _h, float _s, float _v, float _a) { h=_h; s=_s; v=_v; a=_a; }
|
||||
hgeColorHSV(DWORD col) { SetHWColor(col); }
|
||||
hgeColorHSV() { h=s=v=a=0; }
|
||||
|
||||
hgeColorHSV operator- (const hgeColorHSV &c) const { return hgeColorHSV(h-c.h, s-c.s, v-c.v, a-c.a); }
|
||||
hgeColorHSV operator+ (const hgeColorHSV &c) const { return hgeColorHSV(h+c.h, s+c.s, v+c.v, a+c.a); }
|
||||
hgeColorHSV operator* (const hgeColorHSV &c) const { return hgeColorHSV(h*c.h, s*c.s, v*c.v, a*c.a); }
|
||||
hgeColorHSV& operator-= (const hgeColorHSV &c) { h-=c.h; s-=c.s; v-=c.v; a-=c.a; return *this; }
|
||||
hgeColorHSV& operator+= (const hgeColorHSV &c) { h+=c.h; s+=c.s; v+=c.v; a+=c.a; return *this; }
|
||||
bool operator== (const hgeColorHSV &c) const { return (h==c.h && s==c.s && v==c.v && a==c.a); }
|
||||
bool operator!= (const hgeColorHSV &c) const { return (h!=c.h || s!=c.s || v!=c.v || a!=c.a); }
|
||||
|
||||
hgeColorHSV operator/ (const float scalar) const { return hgeColorHSV(h/scalar, s/scalar, v/scalar, a/scalar); }
|
||||
hgeColorHSV operator* (const float scalar) const { return hgeColorHSV(h*scalar, s*scalar, v*scalar, a*scalar); }
|
||||
hgeColorHSV& operator*= (const float scalar) { h*=scalar; s*=scalar; v*=scalar; a*=scalar; return *this; }
|
||||
|
||||
void Clamp() { ColorClamp(h); ColorClamp(s); ColorClamp(v); ColorClamp(a); }
|
||||
void SetHWColor(DWORD col);
|
||||
DWORD GetHWColor() const;
|
||||
};
|
||||
|
||||
inline hgeColorHSV operator* (const float sc, const hgeColorHSV &c) { return c*sc; }
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeColor*** helper classes
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGECOLOR_H
|
||||
#define HGECOLOR_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
|
||||
#include "../JTypes.h"
|
||||
|
||||
#define hgeColor hgeColorRGB
|
||||
|
||||
inline void ColorClamp(float &x) { if(x<0.0f) x=0.0f; if(x>1.0f) x=1.0f; }
|
||||
|
||||
|
||||
class hgeColorRGB
|
||||
{
|
||||
public:
|
||||
float r,g,b,a;
|
||||
|
||||
hgeColorRGB(float _r, float _g, float _b, float _a) { r=_r; g=_g; b=_b; a=_a; }
|
||||
hgeColorRGB(DWORD col) { SetHWColor(col); }
|
||||
hgeColorRGB() { r=g=b=a=0; }
|
||||
|
||||
hgeColorRGB operator- (const hgeColorRGB &c) const { return hgeColorRGB(r-c.r, g-c.g, b-c.b, a-c.a); }
|
||||
hgeColorRGB operator+ (const hgeColorRGB &c) const { return hgeColorRGB(r+c.r, g+c.g, b+c.b, a+c.a); }
|
||||
hgeColorRGB operator* (const hgeColorRGB &c) const { return hgeColorRGB(r*c.r, g*c.g, b*c.b, a*c.a); }
|
||||
hgeColorRGB& operator-= (const hgeColorRGB &c) { r-=c.r; g-=c.g; b-=c.b; a-=c.a; return *this; }
|
||||
hgeColorRGB& operator+= (const hgeColorRGB &c) { r+=c.r; g+=c.g; b+=c.b; a+=c.a; return *this; }
|
||||
bool operator== (const hgeColorRGB &c) const { return (r==c.r && g==c.g && b==c.b && a==c.a); }
|
||||
bool operator!= (const hgeColorRGB &c) const { return (r!=c.r || g!=c.g || b!=c.b || a!=c.a); }
|
||||
|
||||
hgeColorRGB operator/ (const float scalar) const { return hgeColorRGB(r/scalar, g/scalar, b/scalar, a/scalar); }
|
||||
hgeColorRGB operator* (const float scalar) const { return hgeColorRGB(r*scalar, g*scalar, b*scalar, a*scalar); }
|
||||
hgeColorRGB& operator*= (const float scalar) { r*=scalar; g*=scalar; b*=scalar; a*=scalar; return *this; }
|
||||
|
||||
void Clamp() { ColorClamp(r); ColorClamp(g); ColorClamp(b); ColorClamp(a); }
|
||||
void SetHWColor(DWORD col) { a = (col>>24)/255.0f; r = ((col>>16) & 0xFF)/255.0f; g = ((col>>8) & 0xFF)/255.0f; b = (col & 0xFF)/255.0f; }
|
||||
DWORD GetHWColor() const { return ARGB(((int)(a*255.0f)), ((int)(r*255.0f)), ((int)(g*255.0f)), ((int)(b*255.0f))); }
|
||||
};
|
||||
|
||||
inline hgeColorRGB operator* (const float sc, const hgeColorRGB &c) { return c*sc; }
|
||||
|
||||
|
||||
class hgeColorHSV
|
||||
{
|
||||
public:
|
||||
float h,s,v,a;
|
||||
|
||||
hgeColorHSV(float _h, float _s, float _v, float _a) { h=_h; s=_s; v=_v; a=_a; }
|
||||
hgeColorHSV(DWORD col) { SetHWColor(col); }
|
||||
hgeColorHSV() { h=s=v=a=0; }
|
||||
|
||||
hgeColorHSV operator- (const hgeColorHSV &c) const { return hgeColorHSV(h-c.h, s-c.s, v-c.v, a-c.a); }
|
||||
hgeColorHSV operator+ (const hgeColorHSV &c) const { return hgeColorHSV(h+c.h, s+c.s, v+c.v, a+c.a); }
|
||||
hgeColorHSV operator* (const hgeColorHSV &c) const { return hgeColorHSV(h*c.h, s*c.s, v*c.v, a*c.a); }
|
||||
hgeColorHSV& operator-= (const hgeColorHSV &c) { h-=c.h; s-=c.s; v-=c.v; a-=c.a; return *this; }
|
||||
hgeColorHSV& operator+= (const hgeColorHSV &c) { h+=c.h; s+=c.s; v+=c.v; a+=c.a; return *this; }
|
||||
bool operator== (const hgeColorHSV &c) const { return (h==c.h && s==c.s && v==c.v && a==c.a); }
|
||||
bool operator!= (const hgeColorHSV &c) const { return (h!=c.h || s!=c.s || v!=c.v || a!=c.a); }
|
||||
|
||||
hgeColorHSV operator/ (const float scalar) const { return hgeColorHSV(h/scalar, s/scalar, v/scalar, a/scalar); }
|
||||
hgeColorHSV operator* (const float scalar) const { return hgeColorHSV(h*scalar, s*scalar, v*scalar, a*scalar); }
|
||||
hgeColorHSV& operator*= (const float scalar) { h*=scalar; s*=scalar; v*=scalar; a*=scalar; return *this; }
|
||||
|
||||
void Clamp() { ColorClamp(h); ColorClamp(s); ColorClamp(v); ColorClamp(a); }
|
||||
void SetHWColor(DWORD col);
|
||||
DWORD GetHWColor() const;
|
||||
};
|
||||
|
||||
inline hgeColorHSV operator* (const float sc, const hgeColorHSV &c) { return c*sc; }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeDistortionMesh helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEDISTORT_H
|
||||
#define HGEDISTORT_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
#include "../JTypes.h"
|
||||
|
||||
|
||||
#define HGEDISP_NODE 0
|
||||
#define HGEDISP_TOPLEFT 1
|
||||
#define HGEDISP_CENTER 2
|
||||
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
|
||||
/*
|
||||
** HGE Distortion mesh class
|
||||
*/
|
||||
class hgeDistortionMesh
|
||||
{
|
||||
public:
|
||||
hgeDistortionMesh(int cols, int rows);
|
||||
hgeDistortionMesh(const hgeDistortionMesh &dm);
|
||||
~hgeDistortionMesh();
|
||||
|
||||
hgeDistortionMesh& operator= (const hgeDistortionMesh &dm);
|
||||
|
||||
void Render(float x, float y);
|
||||
void Clear(PIXEL_TYPE col=ARGB(0xFF,0xFF,0xFF,0xFF), float z=0.5f);
|
||||
|
||||
void SetTexture(JTexture* tex);
|
||||
void SetTextureRect(float x, float y, float w, float h);
|
||||
void SetBlendMode(int blend);
|
||||
void SetZ(int col, int row, float z);
|
||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||
void SetDisplacement(int col, int row, float dx, float dy, int ref);
|
||||
|
||||
JTexture* GetTexture() const {return quad->mTex;}
|
||||
void GetTextureRect(float *x, float *y, float *w, float *h) const { *x=tx; *y=ty; *w=width; *h=height; }
|
||||
int GetBlendMode() const { return 0; }
|
||||
float GetZ(int col, int row) const;
|
||||
PIXEL_TYPE GetColor(int col, int row) const;
|
||||
void GetDisplacement(int col, int row, float *dx, float *dy, int ref) const;
|
||||
|
||||
int GetRows() { return nRows; }
|
||||
int GetCols() { return nCols; }
|
||||
|
||||
private:
|
||||
hgeDistortionMesh();
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
Vertex *disp_array;
|
||||
int nRows, nCols;
|
||||
float cellw,cellh;
|
||||
float tx,ty,width,height;
|
||||
JQuad* quad;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeDistortionMesh helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEDISTORT_H
|
||||
#define HGEDISTORT_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
#include "../JTypes.h"
|
||||
|
||||
|
||||
#define HGEDISP_NODE 0
|
||||
#define HGEDISP_TOPLEFT 1
|
||||
#define HGEDISP_CENTER 2
|
||||
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
|
||||
/*
|
||||
** HGE Distortion mesh class
|
||||
*/
|
||||
class hgeDistortionMesh
|
||||
{
|
||||
public:
|
||||
hgeDistortionMesh(int cols, int rows);
|
||||
hgeDistortionMesh(const hgeDistortionMesh &dm);
|
||||
~hgeDistortionMesh();
|
||||
|
||||
hgeDistortionMesh& operator= (const hgeDistortionMesh &dm);
|
||||
|
||||
void Render(float x, float y);
|
||||
void Clear(PIXEL_TYPE col=ARGB(0xFF,0xFF,0xFF,0xFF), float z=0.5f);
|
||||
|
||||
void SetTexture(JTexture* tex);
|
||||
void SetTextureRect(float x, float y, float w, float h);
|
||||
void SetBlendMode(int blend);
|
||||
void SetZ(int col, int row, float z);
|
||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||
void SetDisplacement(int col, int row, float dx, float dy, int ref);
|
||||
|
||||
JTexture* GetTexture() const {return quad->mTex;}
|
||||
void GetTextureRect(float *x, float *y, float *w, float *h) const { *x=tx; *y=ty; *w=width; *h=height; }
|
||||
int GetBlendMode() const { return 0; }
|
||||
float GetZ(int col, int row) const;
|
||||
PIXEL_TYPE GetColor(int col, int row) const;
|
||||
void GetDisplacement(int col, int row, float *dx, float *dy, int ref) const;
|
||||
|
||||
int GetRows() { return nRows; }
|
||||
int GetCols() { return nCols; }
|
||||
|
||||
private:
|
||||
hgeDistortionMesh();
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
Vertex *disp_array;
|
||||
int nRows, nCols;
|
||||
float cellw,cellh;
|
||||
float tx,ty,width,height;
|
||||
JQuad* quad;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+93
-93
@@ -1,93 +1,93 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeFont helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEFONT_H
|
||||
#define HGEFONT_H
|
||||
|
||||
#include "../JTypes.h"
|
||||
//#include "hge.h"
|
||||
//#include "hgesprite.h"
|
||||
|
||||
|
||||
#define HGETEXT_LEFT 0
|
||||
#define HGETEXT_RIGHT 1
|
||||
#define HGETEXT_CENTER 2
|
||||
#define HGETEXT_HORZMASK 0x03
|
||||
|
||||
#define HGETEXT_TOP 0
|
||||
#define HGETEXT_BOTTOM 4
|
||||
#define HGETEXT_MIDDLE 8
|
||||
#define HGETEXT_VERTMASK 0x0C
|
||||
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
/*
|
||||
** HGE Font class
|
||||
*/
|
||||
class hgeFont
|
||||
{
|
||||
public:
|
||||
hgeFont(const char *filename, bool bMipmap=false);
|
||||
~hgeFont();
|
||||
|
||||
void Render(float x, float y, int align, const char *string);
|
||||
void printf(float x, float y, int align, const char *format, ...);
|
||||
void printfb(float x, float y, float w, float h, int align, const char *format, ...);
|
||||
|
||||
void SetColor(PIXEL_TYPE col);
|
||||
void SetZ(float z);
|
||||
void SetBlendMode(int blend);
|
||||
void SetScale(float scale) {fScale=scale;}
|
||||
void SetProportion(float prop) { fProportion=prop; }
|
||||
void SetRotation(float rot) {fRot=rot;}
|
||||
void SetTracking(float tracking) {fTracking=tracking;}
|
||||
void SetSpacing(float spacing) {fSpacing=spacing;}
|
||||
|
||||
PIXEL_TYPE GetColor() const {return dwCol;}
|
||||
float GetZ() const {return fZ;}
|
||||
int GetBlendMode() const {return nBlend;}
|
||||
float GetScale() const {return fScale;}
|
||||
float GetProportion() const { return fProportion; }
|
||||
float GetRotation() const {return fRot;}
|
||||
float GetTracking() const {return fTracking;}
|
||||
float GetSpacing() const {return fSpacing;}
|
||||
|
||||
JQuad* GetSprite(char chr) const { return letters[(unsigned char)chr]; }
|
||||
float GetHeight() const { return fHeight; }
|
||||
float GetStringWidth(const char *string) const;
|
||||
|
||||
private:
|
||||
hgeFont();
|
||||
hgeFont(const hgeFont &fnt);
|
||||
hgeFont& operator= (const hgeFont &fnt);
|
||||
|
||||
char* _get_line(char *file, char *line);
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
static char buffer[256];
|
||||
|
||||
JTexture* hTexture;
|
||||
JQuad* letters[256];
|
||||
float pre[256];
|
||||
float post[256];
|
||||
float fHeight;
|
||||
float fScale;
|
||||
float fProportion;
|
||||
float fRot;
|
||||
float fTracking;
|
||||
float fSpacing;
|
||||
|
||||
PIXEL_TYPE dwCol;
|
||||
float fZ;
|
||||
int nBlend;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeFont helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEFONT_H
|
||||
#define HGEFONT_H
|
||||
|
||||
#include "../JTypes.h"
|
||||
//#include "hge.h"
|
||||
//#include "hgesprite.h"
|
||||
|
||||
|
||||
#define HGETEXT_LEFT 0
|
||||
#define HGETEXT_RIGHT 1
|
||||
#define HGETEXT_CENTER 2
|
||||
#define HGETEXT_HORZMASK 0x03
|
||||
|
||||
#define HGETEXT_TOP 0
|
||||
#define HGETEXT_BOTTOM 4
|
||||
#define HGETEXT_MIDDLE 8
|
||||
#define HGETEXT_VERTMASK 0x0C
|
||||
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
/*
|
||||
** HGE Font class
|
||||
*/
|
||||
class hgeFont
|
||||
{
|
||||
public:
|
||||
hgeFont(const char *filename, bool bMipmap=false);
|
||||
~hgeFont();
|
||||
|
||||
void Render(float x, float y, int align, const char *string);
|
||||
void printf(float x, float y, int align, const char *format, ...);
|
||||
void printfb(float x, float y, float w, float h, int align, const char *format, ...);
|
||||
|
||||
void SetColor(PIXEL_TYPE col);
|
||||
void SetZ(float z);
|
||||
void SetBlendMode(int blend);
|
||||
void SetScale(float scale) {fScale=scale;}
|
||||
void SetProportion(float prop) { fProportion=prop; }
|
||||
void SetRotation(float rot) {fRot=rot;}
|
||||
void SetTracking(float tracking) {fTracking=tracking;}
|
||||
void SetSpacing(float spacing) {fSpacing=spacing;}
|
||||
|
||||
PIXEL_TYPE GetColor() const {return dwCol;}
|
||||
float GetZ() const {return fZ;}
|
||||
int GetBlendMode() const {return nBlend;}
|
||||
float GetScale() const {return fScale;}
|
||||
float GetProportion() const { return fProportion; }
|
||||
float GetRotation() const {return fRot;}
|
||||
float GetTracking() const {return fTracking;}
|
||||
float GetSpacing() const {return fSpacing;}
|
||||
|
||||
JQuad* GetSprite(char chr) const { return letters[(unsigned char)chr]; }
|
||||
float GetHeight() const { return fHeight; }
|
||||
float GetStringWidth(const char *string) const;
|
||||
|
||||
private:
|
||||
hgeFont();
|
||||
hgeFont(const hgeFont &fnt);
|
||||
hgeFont& operator= (const hgeFont &fnt);
|
||||
|
||||
char* _get_line(char *file, char *line);
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
static char buffer[256];
|
||||
|
||||
JTexture* hTexture;
|
||||
JQuad* letters[256];
|
||||
float pre[256];
|
||||
float post[256];
|
||||
float fHeight;
|
||||
float fScale;
|
||||
float fProportion;
|
||||
float fRot;
|
||||
float fTracking;
|
||||
float fSpacing;
|
||||
|
||||
PIXEL_TYPE dwCol;
|
||||
float fZ;
|
||||
int nBlend;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+165
-165
@@ -1,165 +1,165 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleSystem helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEPARTICLE_H
|
||||
#define HGEPARTICLE_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
//#include "hgesprite.h"
|
||||
#include "hgevector.h"
|
||||
#include "hgecolor.h"
|
||||
#include "hgerect.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
class JQuad;
|
||||
|
||||
#define MAX_PARTICLES 500
|
||||
#define MAX_PSYSTEMS 100
|
||||
|
||||
struct hgeParticle
|
||||
{
|
||||
hgeVector vecLocation;
|
||||
hgeVector vecVelocity;
|
||||
|
||||
float fGravity;
|
||||
float fRadialAccel;
|
||||
float fTangentialAccel;
|
||||
|
||||
float fSpin;
|
||||
float fSpinDelta;
|
||||
|
||||
float fSize;
|
||||
float fSizeDelta;
|
||||
|
||||
hgeColor colColor; // + alpha
|
||||
hgeColor colColorDelta;
|
||||
|
||||
float fAge;
|
||||
float fTerminalAge;
|
||||
};
|
||||
|
||||
struct hgeParticleSystemInfo
|
||||
{
|
||||
JQuad* sprite; // texture + blend mode
|
||||
int nEmission; // particles per sec
|
||||
float fLifetime;
|
||||
|
||||
float fParticleLifeMin;
|
||||
float fParticleLifeMax;
|
||||
|
||||
float fDirection;
|
||||
float fSpread;
|
||||
bool bRelative;
|
||||
|
||||
float fSpeedMin;
|
||||
float fSpeedMax;
|
||||
|
||||
float fGravityMin;
|
||||
float fGravityMax;
|
||||
|
||||
float fRadialAccelMin;
|
||||
float fRadialAccelMax;
|
||||
|
||||
float fTangentialAccelMin;
|
||||
float fTangentialAccelMax;
|
||||
|
||||
float fSizeStart;
|
||||
float fSizeEnd;
|
||||
float fSizeVar;
|
||||
|
||||
float fSpinStart;
|
||||
float fSpinEnd;
|
||||
float fSpinVar;
|
||||
|
||||
hgeColor colColorStart; // + alpha
|
||||
hgeColor colColorEnd;
|
||||
float fColorVar;
|
||||
float fAlphaVar;
|
||||
};
|
||||
|
||||
class hgeParticleSystem
|
||||
{
|
||||
public:
|
||||
hgeParticleSystemInfo info;
|
||||
|
||||
hgeParticleSystem(const char *filename, JQuad *sprite);
|
||||
hgeParticleSystem(hgeParticleSystemInfo *psi);
|
||||
hgeParticleSystem(const hgeParticleSystem &ps);
|
||||
~hgeParticleSystem() { }
|
||||
|
||||
hgeParticleSystem& operator= (const hgeParticleSystem &ps);
|
||||
|
||||
|
||||
void Render();
|
||||
void FireAt(float x, float y);
|
||||
void Fire();
|
||||
void Stop(bool bKillParticles=false);
|
||||
void Update(float fDeltaTime);
|
||||
void MoveTo(float x, float y, bool bMoveParticles=false);
|
||||
void Transpose(float x, float y) { fTx=x; fTy=y; }
|
||||
void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
|
||||
|
||||
int GetParticlesAlive() const { return nParticlesAlive; }
|
||||
float GetAge() const { return fAge; }
|
||||
void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
|
||||
void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
|
||||
hgeRect* GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); return rect; }
|
||||
|
||||
private:
|
||||
hgeParticleSystem();
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
float fAge;
|
||||
float fEmissionResidue;
|
||||
|
||||
hgeVector vecPrevLocation;
|
||||
hgeVector vecLocation;
|
||||
float fTx, fTy;
|
||||
|
||||
int nParticlesAlive;
|
||||
hgeRect rectBoundingBox;
|
||||
bool bUpdateBoundingBox;
|
||||
|
||||
typedef std::list<hgeParticle> ParticleBuffer;
|
||||
ParticleBuffer mParticleBuffer;
|
||||
|
||||
float mTimer;
|
||||
};
|
||||
|
||||
class hgeParticleManager
|
||||
{
|
||||
public:
|
||||
hgeParticleManager();
|
||||
~hgeParticleManager();
|
||||
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
|
||||
hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
|
||||
bool IsPSAlive(hgeParticleSystem *ps) const;
|
||||
void Transpose(float x, float y);
|
||||
void GetTransposition(float *dx, float *dy) const {*dx=tX; *dy=tY;}
|
||||
void KillPS(hgeParticleSystem *ps);
|
||||
void KillAll();
|
||||
|
||||
private:
|
||||
hgeParticleManager(const hgeParticleManager &);
|
||||
hgeParticleManager& operator= (const hgeParticleManager &);
|
||||
|
||||
int nPS;
|
||||
float tX;
|
||||
float tY;
|
||||
hgeParticleSystem* psList[MAX_PSYSTEMS];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleSystem helper class header
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEPARTICLE_H
|
||||
#define HGEPARTICLE_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
//#include "hgesprite.h"
|
||||
#include "hgevector.h"
|
||||
#include "hgecolor.h"
|
||||
#include "hgerect.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
class JQuad;
|
||||
|
||||
#define MAX_PARTICLES 500
|
||||
#define MAX_PSYSTEMS 100
|
||||
|
||||
struct hgeParticle
|
||||
{
|
||||
hgeVector vecLocation;
|
||||
hgeVector vecVelocity;
|
||||
|
||||
float fGravity;
|
||||
float fRadialAccel;
|
||||
float fTangentialAccel;
|
||||
|
||||
float fSpin;
|
||||
float fSpinDelta;
|
||||
|
||||
float fSize;
|
||||
float fSizeDelta;
|
||||
|
||||
hgeColor colColor; // + alpha
|
||||
hgeColor colColorDelta;
|
||||
|
||||
float fAge;
|
||||
float fTerminalAge;
|
||||
};
|
||||
|
||||
struct hgeParticleSystemInfo
|
||||
{
|
||||
JQuad* sprite; // texture + blend mode
|
||||
int nEmission; // particles per sec
|
||||
float fLifetime;
|
||||
|
||||
float fParticleLifeMin;
|
||||
float fParticleLifeMax;
|
||||
|
||||
float fDirection;
|
||||
float fSpread;
|
||||
bool bRelative;
|
||||
|
||||
float fSpeedMin;
|
||||
float fSpeedMax;
|
||||
|
||||
float fGravityMin;
|
||||
float fGravityMax;
|
||||
|
||||
float fRadialAccelMin;
|
||||
float fRadialAccelMax;
|
||||
|
||||
float fTangentialAccelMin;
|
||||
float fTangentialAccelMax;
|
||||
|
||||
float fSizeStart;
|
||||
float fSizeEnd;
|
||||
float fSizeVar;
|
||||
|
||||
float fSpinStart;
|
||||
float fSpinEnd;
|
||||
float fSpinVar;
|
||||
|
||||
hgeColor colColorStart; // + alpha
|
||||
hgeColor colColorEnd;
|
||||
float fColorVar;
|
||||
float fAlphaVar;
|
||||
};
|
||||
|
||||
class hgeParticleSystem
|
||||
{
|
||||
public:
|
||||
hgeParticleSystemInfo info;
|
||||
|
||||
hgeParticleSystem(const char *filename, JQuad *sprite);
|
||||
hgeParticleSystem(hgeParticleSystemInfo *psi);
|
||||
hgeParticleSystem(const hgeParticleSystem &ps);
|
||||
~hgeParticleSystem() { }
|
||||
|
||||
hgeParticleSystem& operator= (const hgeParticleSystem &ps);
|
||||
|
||||
|
||||
void Render();
|
||||
void FireAt(float x, float y);
|
||||
void Fire();
|
||||
void Stop(bool bKillParticles=false);
|
||||
void Update(float fDeltaTime);
|
||||
void MoveTo(float x, float y, bool bMoveParticles=false);
|
||||
void Transpose(float x, float y) { fTx=x; fTy=y; }
|
||||
void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
|
||||
|
||||
int GetParticlesAlive() const { return nParticlesAlive; }
|
||||
float GetAge() const { return fAge; }
|
||||
void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
|
||||
void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
|
||||
hgeRect* GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); return rect; }
|
||||
|
||||
private:
|
||||
hgeParticleSystem();
|
||||
|
||||
//static HGE *hge;
|
||||
|
||||
float fAge;
|
||||
float fEmissionResidue;
|
||||
|
||||
hgeVector vecPrevLocation;
|
||||
hgeVector vecLocation;
|
||||
float fTx, fTy;
|
||||
|
||||
int nParticlesAlive;
|
||||
hgeRect rectBoundingBox;
|
||||
bool bUpdateBoundingBox;
|
||||
|
||||
typedef std::list<hgeParticle> ParticleBuffer;
|
||||
ParticleBuffer mParticleBuffer;
|
||||
|
||||
float mTimer;
|
||||
};
|
||||
|
||||
class hgeParticleManager
|
||||
{
|
||||
public:
|
||||
hgeParticleManager();
|
||||
~hgeParticleManager();
|
||||
|
||||
void Update(float dt);
|
||||
void Render();
|
||||
|
||||
hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
|
||||
bool IsPSAlive(hgeParticleSystem *ps) const;
|
||||
void Transpose(float x, float y);
|
||||
void GetTransposition(float *dx, float *dy) const {*dx=tX; *dy=tY;}
|
||||
void KillPS(hgeParticleSystem *ps);
|
||||
void KillAll();
|
||||
|
||||
private:
|
||||
hgeParticleManager(const hgeParticleManager &);
|
||||
hgeParticleManager& operator= (const hgeParticleManager &);
|
||||
|
||||
int nPS;
|
||||
float tX;
|
||||
float tY;
|
||||
hgeParticleSystem* psList[MAX_PSYSTEMS];
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+35
-35
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeRect helper class
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGERECT_H
|
||||
#define HGERECT_H
|
||||
|
||||
|
||||
class hgeRect
|
||||
{
|
||||
public:
|
||||
float x1, y1, x2, y2;
|
||||
|
||||
hgeRect(float _x1, float _y1, float _x2, float _y2) {x1=_x1; y1=_y1; x2=_x2; y2=_y2; bClean=false; }
|
||||
hgeRect() {bClean=true;}
|
||||
|
||||
void Clear() {bClean=true;}
|
||||
bool IsClean() const {return bClean;}
|
||||
void Set(float _x1, float _y1, float _x2, float _y2) { x1=_x1; x2=_x2; y1=_y1; y2=_y2; bClean=false; }
|
||||
void SetRadius(float x, float y, float r) { x1=x-r; x2=x+r; y1=y-r; y2=y+r; bClean=false; }
|
||||
void Encapsulate(float x, float y);
|
||||
bool TestPoint(float x, float y) const;
|
||||
bool Intersect(const hgeRect *rect) const;
|
||||
|
||||
private:
|
||||
bool bClean;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeRect helper class
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGERECT_H
|
||||
#define HGERECT_H
|
||||
|
||||
|
||||
class hgeRect
|
||||
{
|
||||
public:
|
||||
float x1, y1, x2, y2;
|
||||
|
||||
hgeRect(float _x1, float _y1, float _x2, float _y2) {x1=_x1; y1=_y1; x2=_x2; y2=_y2; bClean=false; }
|
||||
hgeRect() {bClean=true;}
|
||||
|
||||
void Clear() {bClean=true;}
|
||||
bool IsClean() const {return bClean;}
|
||||
void Set(float _x1, float _y1, float _x2, float _y2) { x1=_x1; x2=_x2; y1=_y1; y2=_y2; bClean=false; }
|
||||
void SetRadius(float x, float y, float r) { x1=x-r; x2=x+r; y1=y-r; y2=y+r; bClean=false; }
|
||||
void Encapsulate(float x, float y);
|
||||
bool TestPoint(float x, float y) const;
|
||||
bool Intersect(const hgeRect *rect) const;
|
||||
|
||||
private:
|
||||
bool bClean;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+57
-57
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeVector helper class
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEVECTOR_H
|
||||
#define HGEVECTOR_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
** Fast 1.0/sqrtf(float) routine
|
||||
*/
|
||||
float InvSqrt(float x);
|
||||
|
||||
class hgeVector
|
||||
{
|
||||
public:
|
||||
float x,y;
|
||||
|
||||
hgeVector(float _x, float _y) { x=_x; y=_y; }
|
||||
hgeVector() { x=0; y=0; }
|
||||
|
||||
hgeVector operator- () const { return hgeVector(-x, -y); }
|
||||
hgeVector operator- (const hgeVector &v) const { return hgeVector(x-v.x, y-v.y); }
|
||||
hgeVector operator+ (const hgeVector &v) const { return hgeVector(x+v.x, y+v.y); }
|
||||
hgeVector& operator-= (const hgeVector &v) { x-=v.x; y-=v.y; return *this; }
|
||||
hgeVector& operator+= (const hgeVector &v) { x+=v.x; y+=v.y; return *this; }
|
||||
bool operator== (const hgeVector &v) const { return (x==v.x && y==v.y); }
|
||||
bool operator!= (const hgeVector &v) const { return (x!=v.x || y!=v.y); }
|
||||
|
||||
hgeVector operator/ (const float scalar) const { return hgeVector(x/scalar, y/scalar); }
|
||||
hgeVector operator* (const float scalar) const { return hgeVector(x*scalar, y*scalar); }
|
||||
hgeVector& operator*= (const float scalar) { x*=scalar; y*=scalar; return *this; }
|
||||
|
||||
float Dot(const hgeVector *v) const { return x*v->x + y*v->y; }
|
||||
float Length() const { return sqrtf(Dot(this)); }
|
||||
float Angle(const hgeVector *v = 0) const;
|
||||
|
||||
void Clamp(const float max) { if(Length() > max) { Normalize(); x *= max; y *= max; } }
|
||||
hgeVector* Normalize() { float rc=InvSqrt(Dot(this)); x*=rc; y*=rc; return this; }
|
||||
hgeVector* Rotate(float a);
|
||||
};
|
||||
|
||||
inline hgeVector operator* (const float s, const hgeVector &v) { return v*s; }
|
||||
inline float operator^ (const hgeVector &v, const hgeVector &u) { return v.Angle(&u); }
|
||||
inline float operator% (const hgeVector &v, const hgeVector &u) { return v.Dot(&u); }
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeVector helper class
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HGEVECTOR_H
|
||||
#define HGEVECTOR_H
|
||||
|
||||
|
||||
//#include "hge.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
** Fast 1.0/sqrtf(float) routine
|
||||
*/
|
||||
float InvSqrt(float x);
|
||||
|
||||
class hgeVector
|
||||
{
|
||||
public:
|
||||
float x,y;
|
||||
|
||||
hgeVector(float _x, float _y) { x=_x; y=_y; }
|
||||
hgeVector() { x=0; y=0; }
|
||||
|
||||
hgeVector operator- () const { return hgeVector(-x, -y); }
|
||||
hgeVector operator- (const hgeVector &v) const { return hgeVector(x-v.x, y-v.y); }
|
||||
hgeVector operator+ (const hgeVector &v) const { return hgeVector(x+v.x, y+v.y); }
|
||||
hgeVector& operator-= (const hgeVector &v) { x-=v.x; y-=v.y; return *this; }
|
||||
hgeVector& operator+= (const hgeVector &v) { x+=v.x; y+=v.y; return *this; }
|
||||
bool operator== (const hgeVector &v) const { return (x==v.x && y==v.y); }
|
||||
bool operator!= (const hgeVector &v) const { return (x!=v.x || y!=v.y); }
|
||||
|
||||
hgeVector operator/ (const float scalar) const { return hgeVector(x/scalar, y/scalar); }
|
||||
hgeVector operator* (const float scalar) const { return hgeVector(x*scalar, y*scalar); }
|
||||
hgeVector& operator*= (const float scalar) { x*=scalar; y*=scalar; return *this; }
|
||||
|
||||
float Dot(const hgeVector *v) const { return x*v->x + y*v->y; }
|
||||
float Length() const { return sqrtf(Dot(this)); }
|
||||
float Angle(const hgeVector *v = 0) const;
|
||||
|
||||
void Clamp(const float max) { if(Length() > max) { Normalize(); x *= max; y *= max; } }
|
||||
hgeVector* Normalize() { float rc=InvSqrt(Dot(this)); x*=rc; y*=rc; return this; }
|
||||
hgeVector* Rotate(float a);
|
||||
};
|
||||
|
||||
inline hgeVector operator* (const float s, const hgeVector &v) { return v*s; }
|
||||
inline float operator^ (const hgeVector &v, const hgeVector &u) { return v.Angle(&u); }
|
||||
inline float operator% (const hgeVector &v, const hgeVector &u) { return v.Dot(&u); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+132
-132
@@ -1,132 +1,132 @@
|
||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+75
-75
@@ -1,75 +1,75 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
|
||||
+356
-356
@@ -1,356 +1,356 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
"zlib/zlib113.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
/* ****************************************** */
|
||||
/* Ryan supplied functions */
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||
const char* password));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw,
|
||||
const char* password));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
"zlib/zlib113.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
/* ****************************************** */
|
||||
/* Ryan supplied functions */
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||
const char* password));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw,
|
||||
const char* password));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
||||
|
||||
+235
-235
@@ -1,235 +1,235 @@
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char* zipcharpc;
|
||||
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||
an Unix computer "zlib/zlib113.zip".
|
||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||
will be created at the end of the file.
|
||||
(useful if the file contain a self extractor code)
|
||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
||||
add files in existing zip (be sure you don't add file that doesn't exist)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
*/
|
||||
|
||||
/* Note : there is no delete function into a zipfile.
|
||||
If you want delete file into a zipfile, you must open a zipfile, and create another
|
||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte
|
||||
*/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCtypting));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCtypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const void* buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
/*
|
||||
Close the current file in the zipfile, for fiel opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char* zipcharpc;
|
||||
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||
an Unix computer "zlib/zlib113.zip".
|
||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||
will be created at the end of the file.
|
||||
(useful if the file contain a self extractor code)
|
||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
||||
add files in existing zip (be sure you don't add file that doesn't exist)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
*/
|
||||
|
||||
/* Note : there is no delete function into a zipfile.
|
||||
If you want delete file into a zipfile, you must open a zipfile, and create another
|
||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte
|
||||
*/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCtypting));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCtypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const void* buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
/*
|
||||
Close the current file in the zipfile, for fiel opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
||||
|
||||
+54
-54
@@ -1,54 +1,54 @@
|
||||
/*
|
||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||
* -----------------------------------------------------------------------
|
||||
* Licensed under GPL
|
||||
*
|
||||
* vram.c - Standard C high performance VRAM allocation routines.
|
||||
*
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef vram_h__
|
||||
#define vram_h__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* vrelptr( void *ptr ); // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!)
|
||||
void* vabsptr( void *ptr ); // make a pointer absolute (default return type of valloc)
|
||||
|
||||
void* valloc( size_t size );
|
||||
void vfree( void* ptr );
|
||||
size_t vmemavail();
|
||||
size_t vlargestblock();
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug printf (to stdout) a trace of the current Memblocks
|
||||
void __memwalk();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ifdef vram_h__
|
||||
/*
|
||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||
* -----------------------------------------------------------------------
|
||||
* Licensed under GPL
|
||||
*
|
||||
* vram.c - Standard C high performance VRAM allocation routines.
|
||||
*
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef vram_h__
|
||||
#define vram_h__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* vrelptr( void *ptr ); // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!)
|
||||
void* vabsptr( void *ptr ); // make a pointer absolute (default return type of valloc)
|
||||
|
||||
void* valloc( size_t size );
|
||||
void vfree( void* ptr );
|
||||
size_t vmemavail();
|
||||
size_t vlargestblock();
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug printf (to stdout) a trace of the current Memblocks
|
||||
void __memwalk();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ifdef vram_h__
|
||||
|
||||
+3223
-3223
File diff suppressed because it is too large
Load Diff
+411
-411
@@ -1,411 +1,411 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JSprite.h"
|
||||
#include "../include/JAnimator.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimator::JAnimator(JResourceManager* resourceMgr)
|
||||
{
|
||||
mResource = resourceMgr;
|
||||
mActive = false;
|
||||
mAnimating = false;
|
||||
}
|
||||
|
||||
JAnimator::~JAnimator()
|
||||
{
|
||||
while (mFrames.size()>0)
|
||||
{
|
||||
JAnimatorFrame* frame = mFrames.back();
|
||||
mFrames.pop_back();
|
||||
delete frame;
|
||||
}
|
||||
|
||||
mFrames.clear();
|
||||
}
|
||||
|
||||
bool JAnimator::Load(const char* scriptFile)
|
||||
{
|
||||
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem == NULL) return false;
|
||||
|
||||
if (!fileSystem->OpenFile(scriptFile)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
TiXmlNode* script = 0;
|
||||
TiXmlNode* frame = 0;
|
||||
TiXmlNode* obj = 0;
|
||||
TiXmlNode* param = 0;
|
||||
TiXmlElement* element = 0;
|
||||
|
||||
float defaultTime = 0.033f;
|
||||
|
||||
script = doc.FirstChild("script");
|
||||
if (script)
|
||||
{
|
||||
element = script->ToElement();
|
||||
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
||||
|
||||
const char *type[] =
|
||||
{
|
||||
"ANIMATION_TYPE_LOOPING",
|
||||
"ANIMATION_TYPE_ONCE_AND_STAY",
|
||||
"ANIMATION_TYPE_ONCE_AND_BACK",
|
||||
"ANIMATION_TYPE_ONCE_AND_GONE",
|
||||
"ANIMATION_TYPE_PINGPONG"
|
||||
};
|
||||
|
||||
const char* aniType = element->Attribute("type");
|
||||
for (int i=0;i<5;i++)
|
||||
if (strcmp(type[i], aniType)==0)
|
||||
{
|
||||
SetAnimationType(i);
|
||||
break;
|
||||
}
|
||||
|
||||
float fps;
|
||||
if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
|
||||
fps = 30.0f;
|
||||
|
||||
defaultTime = 1/fps;
|
||||
|
||||
for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
|
||||
{
|
||||
JAnimatorFrame *aniFrame = new JAnimatorFrame(this);
|
||||
|
||||
float duration;
|
||||
element = frame->ToElement();
|
||||
if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
|
||||
duration = defaultTime;
|
||||
aniFrame->SetFrameTime(duration);
|
||||
|
||||
for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
|
||||
{
|
||||
for (param = obj->FirstChild(); param; param = param->NextSibling())
|
||||
{
|
||||
|
||||
element = param->ToElement();
|
||||
if (element != NULL)
|
||||
{
|
||||
if (strcmp(element->Value(), "settings")==0)
|
||||
{
|
||||
const char* quadName = element->Attribute("quad");
|
||||
JQuad* quad = mResource->GetQuad(quadName);
|
||||
|
||||
float x, y;
|
||||
float vsize, hsize;
|
||||
float angle;
|
||||
int a, r, g, b;
|
||||
int value;
|
||||
bool flipped = false;
|
||||
|
||||
if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
|
||||
x = 0.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
|
||||
y = 0.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
|
||||
hsize = 1.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
|
||||
vsize = 1.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
|
||||
angle = 0.0f;
|
||||
|
||||
if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
|
||||
a = 255;
|
||||
|
||||
if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
|
||||
r = 255;
|
||||
|
||||
if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
|
||||
g = 255;
|
||||
|
||||
if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
|
||||
b = 255;
|
||||
|
||||
if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
|
||||
flipped = (value==1);
|
||||
|
||||
|
||||
JAnimatorObject *object = new JAnimatorObject();
|
||||
object->SetQuad(quad);
|
||||
object->SetPosition(x, y);
|
||||
object->SetHScale(hsize);
|
||||
object->SetVScale(vsize);
|
||||
object->SetRotation(angle);
|
||||
object->SetColor(ARGB(a,r,g,b));
|
||||
object->SetFlip(flipped);
|
||||
|
||||
aniFrame->AddObject(object);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mFrames.push_back(aniFrame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void JAnimator::Start()
|
||||
{
|
||||
mFrameDelta = 1;
|
||||
mAnimating = true;
|
||||
mActive = true;
|
||||
mCurrentFrame = 0;
|
||||
|
||||
mFrames[mCurrentFrame]->Start();
|
||||
}
|
||||
|
||||
void JAnimator::Stop()
|
||||
{
|
||||
mAnimating = false;
|
||||
mActive = false;
|
||||
}
|
||||
|
||||
void JAnimator::Pause()
|
||||
{
|
||||
mAnimating = false;
|
||||
}
|
||||
|
||||
void JAnimator::Resume()
|
||||
{
|
||||
mAnimating = true;
|
||||
}
|
||||
|
||||
void JAnimator::Update(float dt)
|
||||
{
|
||||
if (!mAnimating) return;
|
||||
|
||||
if (mFrames[mCurrentFrame]->Update(dt))
|
||||
{
|
||||
mCurrentFrame+=mFrameDelta;
|
||||
|
||||
int frameCount = mFrames.size();
|
||||
if (mCurrentFrame >= frameCount)
|
||||
{
|
||||
if (mAnimationType == JSprite::ANIMATION_TYPE_LOOPING)
|
||||
mCurrentFrame = 0;
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_GONE)
|
||||
{
|
||||
mAnimating = false;
|
||||
mActive = false;
|
||||
}
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_STAY)
|
||||
{
|
||||
mCurrentFrame = frameCount-1;
|
||||
mAnimating = false;
|
||||
}
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_BACK)
|
||||
{
|
||||
mCurrentFrame = 0;
|
||||
mAnimating = false;
|
||||
}
|
||||
else // ping pong
|
||||
{
|
||||
mFrameDelta *= -1;
|
||||
mCurrentFrame += mFrameDelta;
|
||||
}
|
||||
}
|
||||
else if (mCurrentFrame < 0)
|
||||
{
|
||||
if (mAnimationType == JSprite::ANIMATION_TYPE_PINGPONG)
|
||||
{
|
||||
mFrameDelta *= -1;
|
||||
mCurrentFrame += mFrameDelta;
|
||||
}
|
||||
}
|
||||
|
||||
if (mAnimating)
|
||||
mFrames[mCurrentFrame]->Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::Render()
|
||||
{
|
||||
if (!mActive)
|
||||
return;
|
||||
|
||||
mFrames[mCurrentFrame]->Render(mX-mHotSpotX, mY-mHotSpotY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JAnimator::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
|
||||
bool JAnimator::IsAnimating()
|
||||
{
|
||||
return mAnimating;
|
||||
}
|
||||
|
||||
|
||||
int JAnimator::GetCurrentFrameIndex()
|
||||
{
|
||||
return mCurrentFrame;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetCurrentFrameIndex(int index)
|
||||
{
|
||||
if (index < (int)mFrames.size())
|
||||
mCurrentFrame = index;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetAnimationType(int type)
|
||||
{
|
||||
mAnimationType = type;
|
||||
}
|
||||
|
||||
|
||||
JResourceManager* JAnimator::GetResourceManager()
|
||||
{
|
||||
return mResource;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetPosition(float x, float y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetHotSpot(float x, float y)
|
||||
{
|
||||
mHotSpotX = x;
|
||||
mHotSpotY = y;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorFrame::JAnimatorFrame(JAnimator* parent __attribute__((unused)))
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
mFrameTime = 100.0f;
|
||||
}
|
||||
|
||||
JAnimatorFrame::~JAnimatorFrame()
|
||||
{
|
||||
while (mObjects.size()>0)
|
||||
{
|
||||
JAnimatorObject* obj = mObjects.back();
|
||||
mObjects.pop_back();
|
||||
delete obj;
|
||||
}
|
||||
|
||||
mObjects.clear();
|
||||
|
||||
}
|
||||
|
||||
void JAnimatorFrame::AddObject(JAnimatorObject *obj)
|
||||
{
|
||||
mObjects.push_back(obj);
|
||||
}
|
||||
|
||||
bool JAnimatorFrame::Update(float dt)
|
||||
{
|
||||
mTimer += dt;
|
||||
if (mTimer >= mFrameTime)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
int size = mObjects.size();
|
||||
for (int i=0;i<size;i++)
|
||||
mObjects[i]->Update(dt);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void JAnimatorFrame::Render(float x, float y)
|
||||
{
|
||||
int size = mObjects.size();
|
||||
for (int i=0;i<size;i++)
|
||||
mObjects[i]->Render(x, y);
|
||||
}
|
||||
|
||||
void JAnimatorFrame::Start()
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
}
|
||||
|
||||
// bool JAnimatorFrame::IsDone()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
void JAnimatorFrame::SetFrameTime(float duration)
|
||||
{
|
||||
mFrameTime = duration;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorObject::JAnimatorObject()
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
mFlipped = false;
|
||||
}
|
||||
|
||||
JAnimatorObject::~JAnimatorObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void JAnimatorObject::Update(float dt __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void JAnimatorObject::Render(float x, float y)
|
||||
{
|
||||
mQuad->SetHFlip(mFlipped);
|
||||
mQuad->SetColor(mColor);
|
||||
mRenderer->RenderQuad(mQuad, x+mX, y+mY, mRotation, mHScale, mVScale);
|
||||
}
|
||||
|
||||
void JAnimatorObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
void JAnimatorObject::SetPosition(float x, float y) { mX = x; mY = y; }
|
||||
void JAnimatorObject::SetRotation(float angle) { mRotation = angle; }
|
||||
void JAnimatorObject::SetHScale(float scale) { mHScale = scale; }
|
||||
void JAnimatorObject::SetVScale(float scale) { mVScale = scale; }
|
||||
void JAnimatorObject::SetColor(PIXEL_TYPE color) { mColor = color; }
|
||||
void JAnimatorObject::SetFlip(bool flag) { mFlipped = flag; }
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JSprite.h"
|
||||
#include "../include/JAnimator.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimator::JAnimator(JResourceManager* resourceMgr)
|
||||
{
|
||||
mResource = resourceMgr;
|
||||
mActive = false;
|
||||
mAnimating = false;
|
||||
}
|
||||
|
||||
JAnimator::~JAnimator()
|
||||
{
|
||||
while (mFrames.size()>0)
|
||||
{
|
||||
JAnimatorFrame* frame = mFrames.back();
|
||||
mFrames.pop_back();
|
||||
delete frame;
|
||||
}
|
||||
|
||||
mFrames.clear();
|
||||
}
|
||||
|
||||
bool JAnimator::Load(const char* scriptFile)
|
||||
{
|
||||
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem == NULL) return false;
|
||||
|
||||
if (!fileSystem->OpenFile(scriptFile)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
TiXmlNode* script = 0;
|
||||
TiXmlNode* frame = 0;
|
||||
TiXmlNode* obj = 0;
|
||||
TiXmlNode* param = 0;
|
||||
TiXmlElement* element = 0;
|
||||
|
||||
float defaultTime = 0.033f;
|
||||
|
||||
script = doc.FirstChild("script");
|
||||
if (script)
|
||||
{
|
||||
element = script->ToElement();
|
||||
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
||||
|
||||
const char *type[] =
|
||||
{
|
||||
"ANIMATION_TYPE_LOOPING",
|
||||
"ANIMATION_TYPE_ONCE_AND_STAY",
|
||||
"ANIMATION_TYPE_ONCE_AND_BACK",
|
||||
"ANIMATION_TYPE_ONCE_AND_GONE",
|
||||
"ANIMATION_TYPE_PINGPONG"
|
||||
};
|
||||
|
||||
const char* aniType = element->Attribute("type");
|
||||
for (int i=0;i<5;i++)
|
||||
if (strcmp(type[i], aniType)==0)
|
||||
{
|
||||
SetAnimationType(i);
|
||||
break;
|
||||
}
|
||||
|
||||
float fps;
|
||||
if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
|
||||
fps = 30.0f;
|
||||
|
||||
defaultTime = 1/fps;
|
||||
|
||||
for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
|
||||
{
|
||||
JAnimatorFrame *aniFrame = new JAnimatorFrame(this);
|
||||
|
||||
float duration;
|
||||
element = frame->ToElement();
|
||||
if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
|
||||
duration = defaultTime;
|
||||
aniFrame->SetFrameTime(duration);
|
||||
|
||||
for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
|
||||
{
|
||||
for (param = obj->FirstChild(); param; param = param->NextSibling())
|
||||
{
|
||||
|
||||
element = param->ToElement();
|
||||
if (element != NULL)
|
||||
{
|
||||
if (strcmp(element->Value(), "settings")==0)
|
||||
{
|
||||
const char* quadName = element->Attribute("quad");
|
||||
JQuad* quad = mResource->GetQuad(quadName);
|
||||
|
||||
float x, y;
|
||||
float vsize, hsize;
|
||||
float angle;
|
||||
int a, r, g, b;
|
||||
int value;
|
||||
bool flipped = false;
|
||||
|
||||
if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
|
||||
x = 0.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
|
||||
y = 0.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
|
||||
hsize = 1.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
|
||||
vsize = 1.0f;
|
||||
|
||||
if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
|
||||
angle = 0.0f;
|
||||
|
||||
if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
|
||||
a = 255;
|
||||
|
||||
if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
|
||||
r = 255;
|
||||
|
||||
if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
|
||||
g = 255;
|
||||
|
||||
if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
|
||||
b = 255;
|
||||
|
||||
if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
|
||||
flipped = (value==1);
|
||||
|
||||
|
||||
JAnimatorObject *object = new JAnimatorObject();
|
||||
object->SetQuad(quad);
|
||||
object->SetPosition(x, y);
|
||||
object->SetHScale(hsize);
|
||||
object->SetVScale(vsize);
|
||||
object->SetRotation(angle);
|
||||
object->SetColor(ARGB(a,r,g,b));
|
||||
object->SetFlip(flipped);
|
||||
|
||||
aniFrame->AddObject(object);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mFrames.push_back(aniFrame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void JAnimator::Start()
|
||||
{
|
||||
mFrameDelta = 1;
|
||||
mAnimating = true;
|
||||
mActive = true;
|
||||
mCurrentFrame = 0;
|
||||
|
||||
mFrames[mCurrentFrame]->Start();
|
||||
}
|
||||
|
||||
void JAnimator::Stop()
|
||||
{
|
||||
mAnimating = false;
|
||||
mActive = false;
|
||||
}
|
||||
|
||||
void JAnimator::Pause()
|
||||
{
|
||||
mAnimating = false;
|
||||
}
|
||||
|
||||
void JAnimator::Resume()
|
||||
{
|
||||
mAnimating = true;
|
||||
}
|
||||
|
||||
void JAnimator::Update(float dt)
|
||||
{
|
||||
if (!mAnimating) return;
|
||||
|
||||
if (mFrames[mCurrentFrame]->Update(dt))
|
||||
{
|
||||
mCurrentFrame+=mFrameDelta;
|
||||
|
||||
int frameCount = mFrames.size();
|
||||
if (mCurrentFrame >= frameCount)
|
||||
{
|
||||
if (mAnimationType == JSprite::ANIMATION_TYPE_LOOPING)
|
||||
mCurrentFrame = 0;
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_GONE)
|
||||
{
|
||||
mAnimating = false;
|
||||
mActive = false;
|
||||
}
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_STAY)
|
||||
{
|
||||
mCurrentFrame = frameCount-1;
|
||||
mAnimating = false;
|
||||
}
|
||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_BACK)
|
||||
{
|
||||
mCurrentFrame = 0;
|
||||
mAnimating = false;
|
||||
}
|
||||
else // ping pong
|
||||
{
|
||||
mFrameDelta *= -1;
|
||||
mCurrentFrame += mFrameDelta;
|
||||
}
|
||||
}
|
||||
else if (mCurrentFrame < 0)
|
||||
{
|
||||
if (mAnimationType == JSprite::ANIMATION_TYPE_PINGPONG)
|
||||
{
|
||||
mFrameDelta *= -1;
|
||||
mCurrentFrame += mFrameDelta;
|
||||
}
|
||||
}
|
||||
|
||||
if (mAnimating)
|
||||
mFrames[mCurrentFrame]->Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::Render()
|
||||
{
|
||||
if (!mActive)
|
||||
return;
|
||||
|
||||
mFrames[mCurrentFrame]->Render(mX-mHotSpotX, mY-mHotSpotY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JAnimator::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
|
||||
bool JAnimator::IsAnimating()
|
||||
{
|
||||
return mAnimating;
|
||||
}
|
||||
|
||||
|
||||
int JAnimator::GetCurrentFrameIndex()
|
||||
{
|
||||
return mCurrentFrame;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetCurrentFrameIndex(int index)
|
||||
{
|
||||
if (index < (int)mFrames.size())
|
||||
mCurrentFrame = index;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetAnimationType(int type)
|
||||
{
|
||||
mAnimationType = type;
|
||||
}
|
||||
|
||||
|
||||
JResourceManager* JAnimator::GetResourceManager()
|
||||
{
|
||||
return mResource;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetPosition(float x, float y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
|
||||
void JAnimator::SetHotSpot(float x, float y)
|
||||
{
|
||||
mHotSpotX = x;
|
||||
mHotSpotY = y;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorFrame::JAnimatorFrame(JAnimator* parent __attribute__((unused)))
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
mFrameTime = 100.0f;
|
||||
}
|
||||
|
||||
JAnimatorFrame::~JAnimatorFrame()
|
||||
{
|
||||
while (mObjects.size()>0)
|
||||
{
|
||||
JAnimatorObject* obj = mObjects.back();
|
||||
mObjects.pop_back();
|
||||
delete obj;
|
||||
}
|
||||
|
||||
mObjects.clear();
|
||||
|
||||
}
|
||||
|
||||
void JAnimatorFrame::AddObject(JAnimatorObject *obj)
|
||||
{
|
||||
mObjects.push_back(obj);
|
||||
}
|
||||
|
||||
bool JAnimatorFrame::Update(float dt)
|
||||
{
|
||||
mTimer += dt;
|
||||
if (mTimer >= mFrameTime)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
int size = mObjects.size();
|
||||
for (int i=0;i<size;i++)
|
||||
mObjects[i]->Update(dt);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void JAnimatorFrame::Render(float x, float y)
|
||||
{
|
||||
int size = mObjects.size();
|
||||
for (int i=0;i<size;i++)
|
||||
mObjects[i]->Render(x, y);
|
||||
}
|
||||
|
||||
void JAnimatorFrame::Start()
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
}
|
||||
|
||||
// bool JAnimatorFrame::IsDone()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
void JAnimatorFrame::SetFrameTime(float duration)
|
||||
{
|
||||
mFrameTime = duration;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JAnimatorObject::JAnimatorObject()
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
mFlipped = false;
|
||||
}
|
||||
|
||||
JAnimatorObject::~JAnimatorObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void JAnimatorObject::Update(float dt __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void JAnimatorObject::Render(float x, float y)
|
||||
{
|
||||
mQuad->SetHFlip(mFlipped);
|
||||
mQuad->SetColor(mColor);
|
||||
mRenderer->RenderQuad(mQuad, x+mX, y+mY, mRotation, mHScale, mVScale);
|
||||
}
|
||||
|
||||
void JAnimatorObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
void JAnimatorObject::SetPosition(float x, float y) { mX = x; mY = y; }
|
||||
void JAnimatorObject::SetRotation(float angle) { mRotation = angle; }
|
||||
void JAnimatorObject::SetHScale(float scale) { mHScale = scale; }
|
||||
void JAnimatorObject::SetVScale(float scale) { mVScale = scale; }
|
||||
void JAnimatorObject::SetColor(PIXEL_TYPE color) { mColor = color; }
|
||||
void JAnimatorObject::SetFlip(bool flag) { mFlipped = flag; }
|
||||
|
||||
+331
-331
@@ -1,331 +1,331 @@
|
||||
#include <pspsdk.h>
|
||||
#include <pspaudiocodec.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <pspmpeg.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../include/JAudio.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JCooleyesMP3.h"
|
||||
|
||||
|
||||
JCooleyesMP3::JCooleyesMP3()
|
||||
{
|
||||
mPlaying = false;
|
||||
mp3_handle = 0;
|
||||
mFileBuffer = NULL;
|
||||
mMP3FirstFramePointer = NULL;
|
||||
mFileSize = 0;
|
||||
mCurrFramePointer = NULL;
|
||||
mDataPointer = 0;
|
||||
mSamplesPending = 0;
|
||||
mAllMP3DataProcessed = true;
|
||||
mUpdateCounter = 0;
|
||||
|
||||
mLooping = false;
|
||||
|
||||
mChannelCount = 2;
|
||||
mSampleRate = 44100; // this is mp3 file's sample rate, also can be 48000,....
|
||||
mSamplePerFrame = SAMPLE_PER_FRAME; // default value for MPEG1, Layer3
|
||||
|
||||
mOutputBufferIndex = 0;
|
||||
}
|
||||
|
||||
JCooleyesMP3::~JCooleyesMP3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::IsPlaying()
|
||||
{
|
||||
return mPlaying;
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer)
|
||||
{
|
||||
|
||||
mMP3CodecBuffer = MP3CodecBuffer;
|
||||
mDecoderBuffer = decoderBuffer;
|
||||
mDecodedDataOutputBuffer = decodedDataOutputBuffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::Load(const char *filename)
|
||||
{
|
||||
if (!g_MP3DecoderOK)
|
||||
return false;
|
||||
|
||||
bool ret = true;
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
|
||||
//mp3_handle = sceIoOpen(filename, PSP_O_RDONLY, 0777);
|
||||
if (fileSys->OpenFile(filename))
|
||||
{
|
||||
mFileSize = fileSys->GetFileSize();// sceIoLseek32(mp3_handle, 0, PSP_SEEK_END);
|
||||
//sceIoLseek32(mp3_handle, 0, PSP_SEEK_SET);
|
||||
|
||||
mFileBuffer = (u8*)memalign(64, mFileSize);
|
||||
if (mFileBuffer)
|
||||
{
|
||||
if (fileSys->ReadFile(mFileBuffer, mFileSize ) != mFileSize)
|
||||
ret = false;
|
||||
}
|
||||
else
|
||||
ret = false;
|
||||
|
||||
//sceIoClose(mp3_handle);
|
||||
fileSys->CloseFile();
|
||||
|
||||
if (ret)
|
||||
{
|
||||
mMP3FirstFramePointer = mFileBuffer;
|
||||
|
||||
// skip ID3v2.x header
|
||||
if (mFileBuffer[0]=='I' && mFileBuffer[1]=='D' && mFileBuffer[2]=='3')
|
||||
{
|
||||
u32 size = mFileBuffer[9];
|
||||
u32 n = mFileBuffer[8];
|
||||
size |= (n<<7);
|
||||
|
||||
n = mFileBuffer[7];
|
||||
size |= (n<<14);
|
||||
|
||||
n = mFileBuffer[6];
|
||||
size |= (n<<21);
|
||||
|
||||
size += 10;
|
||||
|
||||
mMP3FirstFramePointer += size;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mAllMP3DataProcessed = !ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void JCooleyesMP3::Release()
|
||||
{
|
||||
mAllMP3DataProcessed = true;
|
||||
|
||||
if (mFileBuffer)
|
||||
{
|
||||
free(mFileBuffer);
|
||||
mFileBuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::Play(bool looping)
|
||||
{
|
||||
if (!mAllMP3DataProcessed)
|
||||
{
|
||||
mOutputBufferIndex = 0;
|
||||
mLooping = looping;
|
||||
|
||||
mUpdateCounter = 0;
|
||||
mSamplesPending = 0;
|
||||
mDataPointer = 0;
|
||||
mCurrFramePointer = mMP3FirstFramePointer;
|
||||
|
||||
mPlaying = true;
|
||||
|
||||
|
||||
|
||||
|
||||
Decode();
|
||||
//MP3Decode();
|
||||
//MP3Decode();
|
||||
//MP3Decode();
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
mPlaying = false;
|
||||
|
||||
return mPlaying;
|
||||
}
|
||||
|
||||
|
||||
// bool JCooleyesMP3::PlaybackDone()
|
||||
// {
|
||||
// return (mAllMP3DataProcessed && mSamplesPending==0);
|
||||
// }
|
||||
|
||||
|
||||
void JCooleyesMP3::FeedAudioData(void* buf, unsigned int length/*, bool mixing*/)
|
||||
{
|
||||
if (mPlaying)
|
||||
{
|
||||
if (mSamplesPending > 0)
|
||||
{
|
||||
short *dest = (short *)buf;
|
||||
|
||||
if ((int)length > mSamplesPending)
|
||||
length = mSamplesPending;
|
||||
|
||||
int i;
|
||||
int count = length<<1;//*2
|
||||
int bufferMax = mSamplePerFrame<<2; //1152 * 2 * 4
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
// if (mixing)
|
||||
// {
|
||||
// dest[i] >>= 1;
|
||||
// dest[i] |= (mDecodedDataOutputBuffer[mDataPointer]>>1);
|
||||
// }
|
||||
// else
|
||||
|
||||
dest[i] = mDecodedDataOutputBuffer[mDataPointer];
|
||||
|
||||
mDataPointer++;
|
||||
if (mDataPointer >= bufferMax)
|
||||
mDataPointer = 0;
|
||||
}
|
||||
|
||||
mSamplesPending -= length;
|
||||
|
||||
}
|
||||
|
||||
Decode();
|
||||
|
||||
if (mAllMP3DataProcessed && mSamplesPending<=0)
|
||||
{
|
||||
if (mLooping)
|
||||
{
|
||||
mSamplesPending = 0;
|
||||
mAllMP3DataProcessed = false;
|
||||
mUpdateCounter = 0;
|
||||
mCurrFramePointer = mMP3FirstFramePointer;
|
||||
|
||||
Decode();
|
||||
|
||||
}
|
||||
else
|
||||
mPlaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JCooleyesMP3::Decode()
|
||||
{
|
||||
if (mAllMP3DataProcessed)
|
||||
return;
|
||||
|
||||
|
||||
// get offset to current decoding buffer
|
||||
int dest = mOutputBufferIndex*(mSamplePerFrame<<1);//*2;
|
||||
|
||||
if (mSamplesPending == 0 || dest > mDataPointer || (dest + (int)(mSamplePerFrame<<1) < mDataPointer)) //1152*2;
|
||||
{
|
||||
|
||||
memset(mDecoderBuffer, 0, mSamplePerFrame<<2);//*2*2);
|
||||
|
||||
unsigned int mp3_header = mCurrFramePointer[0];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||
|
||||
int bitrate = (mp3_header & 0xf000) >> 12;
|
||||
int padding = (mp3_header & 0x200) >> 9;
|
||||
|
||||
int bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320};
|
||||
int frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||
|
||||
|
||||
// skip 1 frame
|
||||
|
||||
// mCurrFramePointer += frame_size;
|
||||
// mUpdateCounter += frame_size;
|
||||
//
|
||||
// mp3_header = mCurrFramePointer[0];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||
//
|
||||
// bitrate = (mp3_header & 0xf000) >> 12;
|
||||
// padding = (mp3_header & 0x200) >> 9;
|
||||
//
|
||||
// frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||
|
||||
u8* mp3_data_buffer = (u8*)memalign(64, frame_size);
|
||||
memcpy(mp3_data_buffer, mCurrFramePointer, frame_size);
|
||||
mMP3CodecBuffer[6] = (unsigned long)mp3_data_buffer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#else
|
||||
|
||||
mMP3CodecBuffer[6] = (unsigned long)mCurrFramePointer;
|
||||
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mMP3CodecBuffer[8] = (unsigned long)mDecoderBuffer;
|
||||
|
||||
mMP3CodecBuffer[7] = mMP3CodecBuffer[10] = frame_size;
|
||||
mMP3CodecBuffer[9] = mSamplePerFrame << 2;//* 4;
|
||||
|
||||
int res = sceAudiocodecDecode(mMP3CodecBuffer, 0x1002);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||
|
||||
free (mp3_data_buffer);
|
||||
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if ( res < 0 )
|
||||
{
|
||||
|
||||
mAllMP3DataProcessed = true;
|
||||
return;
|
||||
}
|
||||
short *buffer = mDecodedDataOutputBuffer+dest;//mOutputBufferIndex*1152*2;
|
||||
|
||||
memcpy(buffer, mDecoderBuffer, mSamplePerFrame<<2);//1152*4);
|
||||
|
||||
mOutputBufferIndex = (mOutputBufferIndex+1)%DECODING_BUFFER_COUNT;
|
||||
|
||||
mSamplesPending += mSamplePerFrame;
|
||||
|
||||
mCurrFramePointer += frame_size;
|
||||
mUpdateCounter += frame_size;
|
||||
|
||||
if (mUpdateCounter >= mFileSize)
|
||||
{
|
||||
|
||||
mAllMP3DataProcessed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::Stop()
|
||||
{
|
||||
mPlaying = false;
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::Resume()
|
||||
{
|
||||
if (!mAllMP3DataProcessed)
|
||||
mPlaying = true;
|
||||
}
|
||||
#include <pspsdk.h>
|
||||
#include <pspaudiocodec.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <pspmpeg.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../include/JAudio.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JCooleyesMP3.h"
|
||||
|
||||
|
||||
JCooleyesMP3::JCooleyesMP3()
|
||||
{
|
||||
mPlaying = false;
|
||||
mp3_handle = 0;
|
||||
mFileBuffer = NULL;
|
||||
mMP3FirstFramePointer = NULL;
|
||||
mFileSize = 0;
|
||||
mCurrFramePointer = NULL;
|
||||
mDataPointer = 0;
|
||||
mSamplesPending = 0;
|
||||
mAllMP3DataProcessed = true;
|
||||
mUpdateCounter = 0;
|
||||
|
||||
mLooping = false;
|
||||
|
||||
mChannelCount = 2;
|
||||
mSampleRate = 44100; // this is mp3 file's sample rate, also can be 48000,....
|
||||
mSamplePerFrame = SAMPLE_PER_FRAME; // default value for MPEG1, Layer3
|
||||
|
||||
mOutputBufferIndex = 0;
|
||||
}
|
||||
|
||||
JCooleyesMP3::~JCooleyesMP3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::IsPlaying()
|
||||
{
|
||||
return mPlaying;
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer)
|
||||
{
|
||||
|
||||
mMP3CodecBuffer = MP3CodecBuffer;
|
||||
mDecoderBuffer = decoderBuffer;
|
||||
mDecodedDataOutputBuffer = decodedDataOutputBuffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::Load(const char *filename)
|
||||
{
|
||||
if (!g_MP3DecoderOK)
|
||||
return false;
|
||||
|
||||
bool ret = true;
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
|
||||
//mp3_handle = sceIoOpen(filename, PSP_O_RDONLY, 0777);
|
||||
if (fileSys->OpenFile(filename))
|
||||
{
|
||||
mFileSize = fileSys->GetFileSize();// sceIoLseek32(mp3_handle, 0, PSP_SEEK_END);
|
||||
//sceIoLseek32(mp3_handle, 0, PSP_SEEK_SET);
|
||||
|
||||
mFileBuffer = (u8*)memalign(64, mFileSize);
|
||||
if (mFileBuffer)
|
||||
{
|
||||
if (fileSys->ReadFile(mFileBuffer, mFileSize ) != mFileSize)
|
||||
ret = false;
|
||||
}
|
||||
else
|
||||
ret = false;
|
||||
|
||||
//sceIoClose(mp3_handle);
|
||||
fileSys->CloseFile();
|
||||
|
||||
if (ret)
|
||||
{
|
||||
mMP3FirstFramePointer = mFileBuffer;
|
||||
|
||||
// skip ID3v2.x header
|
||||
if (mFileBuffer[0]=='I' && mFileBuffer[1]=='D' && mFileBuffer[2]=='3')
|
||||
{
|
||||
u32 size = mFileBuffer[9];
|
||||
u32 n = mFileBuffer[8];
|
||||
size |= (n<<7);
|
||||
|
||||
n = mFileBuffer[7];
|
||||
size |= (n<<14);
|
||||
|
||||
n = mFileBuffer[6];
|
||||
size |= (n<<21);
|
||||
|
||||
size += 10;
|
||||
|
||||
mMP3FirstFramePointer += size;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mAllMP3DataProcessed = !ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void JCooleyesMP3::Release()
|
||||
{
|
||||
mAllMP3DataProcessed = true;
|
||||
|
||||
if (mFileBuffer)
|
||||
{
|
||||
free(mFileBuffer);
|
||||
mFileBuffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool JCooleyesMP3::Play(bool looping)
|
||||
{
|
||||
if (!mAllMP3DataProcessed)
|
||||
{
|
||||
mOutputBufferIndex = 0;
|
||||
mLooping = looping;
|
||||
|
||||
mUpdateCounter = 0;
|
||||
mSamplesPending = 0;
|
||||
mDataPointer = 0;
|
||||
mCurrFramePointer = mMP3FirstFramePointer;
|
||||
|
||||
mPlaying = true;
|
||||
|
||||
|
||||
|
||||
|
||||
Decode();
|
||||
//MP3Decode();
|
||||
//MP3Decode();
|
||||
//MP3Decode();
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
mPlaying = false;
|
||||
|
||||
return mPlaying;
|
||||
}
|
||||
|
||||
|
||||
// bool JCooleyesMP3::PlaybackDone()
|
||||
// {
|
||||
// return (mAllMP3DataProcessed && mSamplesPending==0);
|
||||
// }
|
||||
|
||||
|
||||
void JCooleyesMP3::FeedAudioData(void* buf, unsigned int length/*, bool mixing*/)
|
||||
{
|
||||
if (mPlaying)
|
||||
{
|
||||
if (mSamplesPending > 0)
|
||||
{
|
||||
short *dest = (short *)buf;
|
||||
|
||||
if ((int)length > mSamplesPending)
|
||||
length = mSamplesPending;
|
||||
|
||||
int i;
|
||||
int count = length<<1;//*2
|
||||
int bufferMax = mSamplePerFrame<<2; //1152 * 2 * 4
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
// if (mixing)
|
||||
// {
|
||||
// dest[i] >>= 1;
|
||||
// dest[i] |= (mDecodedDataOutputBuffer[mDataPointer]>>1);
|
||||
// }
|
||||
// else
|
||||
|
||||
dest[i] = mDecodedDataOutputBuffer[mDataPointer];
|
||||
|
||||
mDataPointer++;
|
||||
if (mDataPointer >= bufferMax)
|
||||
mDataPointer = 0;
|
||||
}
|
||||
|
||||
mSamplesPending -= length;
|
||||
|
||||
}
|
||||
|
||||
Decode();
|
||||
|
||||
if (mAllMP3DataProcessed && mSamplesPending<=0)
|
||||
{
|
||||
if (mLooping)
|
||||
{
|
||||
mSamplesPending = 0;
|
||||
mAllMP3DataProcessed = false;
|
||||
mUpdateCounter = 0;
|
||||
mCurrFramePointer = mMP3FirstFramePointer;
|
||||
|
||||
Decode();
|
||||
|
||||
}
|
||||
else
|
||||
mPlaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JCooleyesMP3::Decode()
|
||||
{
|
||||
if (mAllMP3DataProcessed)
|
||||
return;
|
||||
|
||||
|
||||
// get offset to current decoding buffer
|
||||
int dest = mOutputBufferIndex*(mSamplePerFrame<<1);//*2;
|
||||
|
||||
if (mSamplesPending == 0 || dest > mDataPointer || (dest + (int)(mSamplePerFrame<<1) < mDataPointer)) //1152*2;
|
||||
{
|
||||
|
||||
memset(mDecoderBuffer, 0, mSamplePerFrame<<2);//*2*2);
|
||||
|
||||
unsigned int mp3_header = mCurrFramePointer[0];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||
|
||||
int bitrate = (mp3_header & 0xf000) >> 12;
|
||||
int padding = (mp3_header & 0x200) >> 9;
|
||||
|
||||
int bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320};
|
||||
int frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||
|
||||
|
||||
// skip 1 frame
|
||||
|
||||
// mCurrFramePointer += frame_size;
|
||||
// mUpdateCounter += frame_size;
|
||||
//
|
||||
// mp3_header = mCurrFramePointer[0];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||
//
|
||||
// bitrate = (mp3_header & 0xf000) >> 12;
|
||||
// padding = (mp3_header & 0x200) >> 9;
|
||||
//
|
||||
// frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||
|
||||
u8* mp3_data_buffer = (u8*)memalign(64, frame_size);
|
||||
memcpy(mp3_data_buffer, mCurrFramePointer, frame_size);
|
||||
mMP3CodecBuffer[6] = (unsigned long)mp3_data_buffer;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#else
|
||||
|
||||
mMP3CodecBuffer[6] = (unsigned long)mCurrFramePointer;
|
||||
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mMP3CodecBuffer[8] = (unsigned long)mDecoderBuffer;
|
||||
|
||||
mMP3CodecBuffer[7] = mMP3CodecBuffer[10] = frame_size;
|
||||
mMP3CodecBuffer[9] = mSamplePerFrame << 2;//* 4;
|
||||
|
||||
int res = sceAudiocodecDecode(mMP3CodecBuffer, 0x1002);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||
|
||||
free (mp3_data_buffer);
|
||||
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
if ( res < 0 )
|
||||
{
|
||||
|
||||
mAllMP3DataProcessed = true;
|
||||
return;
|
||||
}
|
||||
short *buffer = mDecodedDataOutputBuffer+dest;//mOutputBufferIndex*1152*2;
|
||||
|
||||
memcpy(buffer, mDecoderBuffer, mSamplePerFrame<<2);//1152*4);
|
||||
|
||||
mOutputBufferIndex = (mOutputBufferIndex+1)%DECODING_BUFFER_COUNT;
|
||||
|
||||
mSamplesPending += mSamplePerFrame;
|
||||
|
||||
mCurrFramePointer += frame_size;
|
||||
mUpdateCounter += frame_size;
|
||||
|
||||
if (mUpdateCounter >= mFileSize)
|
||||
{
|
||||
|
||||
mAllMP3DataProcessed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::Stop()
|
||||
{
|
||||
mPlaying = false;
|
||||
}
|
||||
|
||||
|
||||
void JCooleyesMP3::Resume()
|
||||
{
|
||||
if (!mAllMP3DataProcessed)
|
||||
mPlaying = true;
|
||||
}
|
||||
|
||||
+121
-121
@@ -1,121 +1,121 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JDistortionMesh.h"
|
||||
|
||||
|
||||
JRenderer* JDistortionMesh::mRenderer = NULL;
|
||||
|
||||
JDistortionMesh::JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows)
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
|
||||
mCols = cols;
|
||||
mRows = rows;
|
||||
|
||||
mCellWidth = width/(mCols-1);
|
||||
mCellHeight = height/(mRows-1);
|
||||
|
||||
mTexX = x;
|
||||
mTexY = y;
|
||||
mTexWidth = width;
|
||||
mTexHeight = height;
|
||||
|
||||
mQuad = new JQuad(tex, x, y, mCellWidth, mCellHeight);
|
||||
|
||||
mVertices = new Vertex[mCols*mRows];
|
||||
|
||||
for(int j=0; j<mRows; j++)
|
||||
{
|
||||
for(int i=0; i<mCols; i++)
|
||||
{
|
||||
mVertices[j*mCols+i].u = x+i*mCellWidth;
|
||||
mVertices[j*mCols+i].v = y+j*mCellHeight;
|
||||
|
||||
mVertices[j*mCols+i].x = i*mCellWidth;
|
||||
mVertices[j*mCols+i].y = j*mCellHeight;
|
||||
|
||||
mVertices[j*mCols+i].color = ARGB(0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
JDistortionMesh::~JDistortionMesh()
|
||||
{
|
||||
|
||||
delete mQuad;
|
||||
delete[] mVertices;
|
||||
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::Render(float x, float y)
|
||||
{
|
||||
|
||||
// mQuad->mBlend = GU_TFX_ADD;
|
||||
|
||||
VertexColor points[4];
|
||||
|
||||
int index;
|
||||
|
||||
for(int j=0; j<mRows-1; j++)
|
||||
{
|
||||
for(int i=0; i<mCols-1; i++)
|
||||
{
|
||||
index=j*mCols+i;
|
||||
|
||||
mQuad->SetTextureRect(mVertices[index].u, mVertices[index].v, mCellWidth, mCellHeight);
|
||||
|
||||
points[0].x = x+mVertices[index].x;
|
||||
points[0].y = y+mVertices[index].y;
|
||||
points[0].z = mVertices[index].z;
|
||||
points[0].color = mVertices[index].color;
|
||||
|
||||
points[1].x = x+mVertices[index+1].x;
|
||||
points[1].y = y+mVertices[index+1].y;
|
||||
points[1].z = mVertices[index+1].z;
|
||||
points[1].color = mVertices[index+1].color;
|
||||
|
||||
points[2].x = x+mVertices[index+mCols].x;
|
||||
points[2].y = y+mVertices[index+mCols].y;
|
||||
points[2].z = mVertices[index+mCols].z;
|
||||
points[2].color = mVertices[index+mCols].color;
|
||||
|
||||
points[3].x = x+mVertices[index+mCols+1].x;
|
||||
points[3].y = y+mVertices[index+mCols+1].y;
|
||||
points[3].z = mVertices[index+mCols+1].z;
|
||||
points[3].color = mVertices[index+mCols+1].color;
|
||||
|
||||
mRenderer->RenderQuad(mQuad, points);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||
{
|
||||
mVertices[row*mCols+col].color = color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::SetDisplacement(int col, int row, float dx, float dy)
|
||||
{
|
||||
dx += col*mCellWidth;
|
||||
dy += row*mCellHeight;
|
||||
|
||||
mVertices[row*mCols+col].x = dx;
|
||||
mVertices[row*mCols+col].y = dy;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JDistortionMesh.h"
|
||||
|
||||
|
||||
JRenderer* JDistortionMesh::mRenderer = NULL;
|
||||
|
||||
JDistortionMesh::JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows)
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
|
||||
mCols = cols;
|
||||
mRows = rows;
|
||||
|
||||
mCellWidth = width/(mCols-1);
|
||||
mCellHeight = height/(mRows-1);
|
||||
|
||||
mTexX = x;
|
||||
mTexY = y;
|
||||
mTexWidth = width;
|
||||
mTexHeight = height;
|
||||
|
||||
mQuad = new JQuad(tex, x, y, mCellWidth, mCellHeight);
|
||||
|
||||
mVertices = new Vertex[mCols*mRows];
|
||||
|
||||
for(int j=0; j<mRows; j++)
|
||||
{
|
||||
for(int i=0; i<mCols; i++)
|
||||
{
|
||||
mVertices[j*mCols+i].u = x+i*mCellWidth;
|
||||
mVertices[j*mCols+i].v = y+j*mCellHeight;
|
||||
|
||||
mVertices[j*mCols+i].x = i*mCellWidth;
|
||||
mVertices[j*mCols+i].y = j*mCellHeight;
|
||||
|
||||
mVertices[j*mCols+i].color = ARGB(0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
JDistortionMesh::~JDistortionMesh()
|
||||
{
|
||||
|
||||
delete mQuad;
|
||||
delete[] mVertices;
|
||||
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::Render(float x, float y)
|
||||
{
|
||||
|
||||
// mQuad->mBlend = GU_TFX_ADD;
|
||||
|
||||
VertexColor points[4];
|
||||
|
||||
int index;
|
||||
|
||||
for(int j=0; j<mRows-1; j++)
|
||||
{
|
||||
for(int i=0; i<mCols-1; i++)
|
||||
{
|
||||
index=j*mCols+i;
|
||||
|
||||
mQuad->SetTextureRect(mVertices[index].u, mVertices[index].v, mCellWidth, mCellHeight);
|
||||
|
||||
points[0].x = x+mVertices[index].x;
|
||||
points[0].y = y+mVertices[index].y;
|
||||
points[0].z = mVertices[index].z;
|
||||
points[0].color = mVertices[index].color;
|
||||
|
||||
points[1].x = x+mVertices[index+1].x;
|
||||
points[1].y = y+mVertices[index+1].y;
|
||||
points[1].z = mVertices[index+1].z;
|
||||
points[1].color = mVertices[index+1].color;
|
||||
|
||||
points[2].x = x+mVertices[index+mCols].x;
|
||||
points[2].y = y+mVertices[index+mCols].y;
|
||||
points[2].z = mVertices[index+mCols].z;
|
||||
points[2].color = mVertices[index+mCols].color;
|
||||
|
||||
points[3].x = x+mVertices[index+mCols+1].x;
|
||||
points[3].y = y+mVertices[index+mCols+1].y;
|
||||
points[3].z = mVertices[index+mCols+1].z;
|
||||
points[3].color = mVertices[index+mCols+1].color;
|
||||
|
||||
mRenderer->RenderQuad(mQuad, points);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||
{
|
||||
mVertices[row*mCols+col].color = color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JDistortionMesh::SetDisplacement(int col, int row, float dx, float dy)
|
||||
{
|
||||
dx += col*mCellWidth;
|
||||
dy += row*mCellHeight;
|
||||
|
||||
mVertices[row*mCols+col].x = dx;
|
||||
mVertices[row*mCols+col].y = dy;
|
||||
}
|
||||
|
||||
+647
-647
File diff suppressed because it is too large
Load Diff
+334
-334
@@ -1,334 +1,334 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JApp.h"
|
||||
|
||||
#include "../include/JGameObject.h"
|
||||
|
||||
|
||||
//JRenderer* JGameObject::mRenderer = NULL;
|
||||
|
||||
|
||||
|
||||
JGameObject::JGameObject(JTexture *tex, float x, float y, float width, float height)
|
||||
:JSprite(tex, x, y, width, height)
|
||||
{
|
||||
//mRenderer = JRenderer::GetInstance();
|
||||
|
||||
//mX = 0.0f;
|
||||
//mY = 0.0f;
|
||||
|
||||
mRenderFlags = 0;
|
||||
//mSize = 1.0f;
|
||||
//mAngle = 0.0f;
|
||||
|
||||
mOriginalBlood = 1;
|
||||
mBlood = 1;
|
||||
mHitPoint = 1;
|
||||
|
||||
mCollided = false;
|
||||
mCollisionTarget = NULL;
|
||||
mFlashing = false;
|
||||
|
||||
//mActive = false;
|
||||
|
||||
mRotationDelta = 0.0f;
|
||||
mDoRotation = false;
|
||||
|
||||
mAlphaDelta = 0.0f;
|
||||
mDoAlpha = false;
|
||||
|
||||
mDoScaling = false;
|
||||
mScaleDelta = 0.0f;
|
||||
|
||||
SetBBox(x, y, width, height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
JGameObject::~JGameObject()
|
||||
{
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::Update(float dt)
|
||||
{
|
||||
JSprite::Update(dt);
|
||||
|
||||
if (mFlashing)
|
||||
{
|
||||
mFlashTimer += dt;
|
||||
if (mFlashTimer > FLASH_TIME)
|
||||
{
|
||||
mFlashTimer = 0;
|
||||
mFlashCounter++;
|
||||
if (mFlashCounter > FLASHING_COUNT)
|
||||
mFlashing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mDoAlpha)
|
||||
{
|
||||
mAlpha += mAlphaDelta*dt;
|
||||
if (mAlpha < 0.0f)
|
||||
{
|
||||
mAlpha = 0.0f;
|
||||
if (mAnimationType == ANIMATION_TYPE_ONCE_AND_GONE)
|
||||
mActive = false;
|
||||
}
|
||||
else if (mAlpha > 255.0f)
|
||||
{
|
||||
mAlpha = 255.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mDoRotation || mDoScaling)
|
||||
{
|
||||
mRotation += mRotationDelta*dt;
|
||||
mHScale += mScaleDelta*dt;
|
||||
mVScale += mScaleDelta*dt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::Render()
|
||||
{
|
||||
/*
|
||||
if (mQuad != NULL)
|
||||
{
|
||||
//mEngine->RenderQuad(mQuad, mX, mY);
|
||||
if (mFlashing && (mFlashCounter&1)==0)
|
||||
{
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
}
|
||||
|
||||
float angle = 0.0f;
|
||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||
angle = mAngle;
|
||||
if ((mRenderFlags & RENDER_FLAG_ROTATION)==RENDER_FLAG_ROTATION)
|
||||
angle = mRotation;
|
||||
float scale = 1.0f;
|
||||
if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||
scale = mSize;
|
||||
|
||||
mRenderer->RenderQuad(mQuad, mX, mY, angle, scale, scale);
|
||||
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
*/
|
||||
|
||||
if (!mActive) return;
|
||||
|
||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||
mRotation = mDirection;
|
||||
|
||||
if (mFlashing && (mFlashCounter&1)==0)
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
|
||||
// if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||
// {
|
||||
// mHScale = mSize;
|
||||
// mVScale = mSize;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mHScale = 1.0f;
|
||||
// mVScale = 1.0f;
|
||||
// }
|
||||
|
||||
JSprite::Render();
|
||||
|
||||
if (mFlashing)
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void JGameObject::SetPosition(float x, float y)
|
||||
// {
|
||||
// // mPos = Vector2D(x, y);
|
||||
// mX = x;
|
||||
// mY = y;
|
||||
// }
|
||||
|
||||
|
||||
//void JGameObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
|
||||
|
||||
|
||||
|
||||
//void JParticle::ResetVelocity()
|
||||
//{
|
||||
// float xx = mSpeed * cosf(mAngle);
|
||||
// float yy = mSpeed * sinf(mAngle);
|
||||
// mVelocity = Vector2D(xx, yy);
|
||||
//}
|
||||
|
||||
|
||||
void JGameObject::SetBBox(float x, float y, float width, float height)
|
||||
{
|
||||
mUseBoundingBox = true;
|
||||
|
||||
mBBoxX = x;
|
||||
mBBoxY = y;
|
||||
mBBoxWidth = width;
|
||||
mBBoxHeight = height;
|
||||
}
|
||||
|
||||
void JGameObject::GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height)
|
||||
{
|
||||
*xNow = x + mBBoxX;
|
||||
*yNow = y + mBBoxY;
|
||||
*width = mBBoxWidth;
|
||||
*height = mBBoxHeight;
|
||||
}
|
||||
|
||||
|
||||
bool JGameObject::Collide(JGameObject *target)
|
||||
{
|
||||
if (mUseBoundingBox)
|
||||
{
|
||||
// bounding box collision detection
|
||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) < -target->mBBoxWidth) return false;
|
||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) > mBBoxWidth) return false;
|
||||
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) < -target->mBBoxHeight) return false;
|
||||
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) > mBBoxHeight) return false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Circle-Circle collision detection
|
||||
float dx = (mX+mCenterX)-(target->mX+target->mCenterX);
|
||||
float dy = (mY+mCenterY)-(target->mY+target->mCenterY);
|
||||
float dr = mRadius+target->mRadius;
|
||||
if (dx*dx + dy*dy > dr*dr)
|
||||
return false;
|
||||
}
|
||||
|
||||
//mCollided = true;
|
||||
//mCollisionTarget = target;
|
||||
SetCollisionTarget(target);
|
||||
target->SetCollisionTarget(this);
|
||||
|
||||
return true; // collision!!!
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetCollisionTarget(JGameObject *target)
|
||||
{
|
||||
mBlood -= target->GetHitPoint();
|
||||
if (mBlood < 0)
|
||||
{
|
||||
// mActive = false;
|
||||
mBlood = 0;
|
||||
}
|
||||
|
||||
mCollided = true;
|
||||
mCollisionTarget = target;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int JGameObject::GetHitPoint()
|
||||
{
|
||||
return mHitPoint;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetHitPoint(int pt)
|
||||
{
|
||||
mHitPoint = pt;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetBlood(int pt)
|
||||
{
|
||||
mOriginalBlood = pt;
|
||||
mBlood = pt;
|
||||
}
|
||||
|
||||
int JGameObject::GetBlood()
|
||||
{
|
||||
return mBlood;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::OnCollide()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::StartFlashing()
|
||||
{
|
||||
mFlashing = true;
|
||||
mFlashTimer = 0.0f;
|
||||
mFlashCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::StopFlashing()
|
||||
{
|
||||
mFlashing = false;
|
||||
}
|
||||
|
||||
|
||||
bool JGameObject::IsFlashing()
|
||||
{
|
||||
return mFlashing;
|
||||
}
|
||||
|
||||
void JGameObject::SetRenderFlags(int flags)
|
||||
{
|
||||
mRenderFlags = flags;
|
||||
}
|
||||
|
||||
// void JGameObject::SetSize(float size)
|
||||
// {
|
||||
// mSize = size;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void JGameObject::SetAngle(float angle)
|
||||
// {
|
||||
// mAngle = angle;
|
||||
// }
|
||||
|
||||
void JGameObject::EnableAlpha(bool flag, float delta) { mDoAlpha = flag; mAlphaDelta = delta; }
|
||||
void JGameObject::EnableScaling(bool flag, float delta) { mDoScaling = flag; mScaleDelta = delta; }
|
||||
void JGameObject::EnableRotation(bool flag, float delta) { mDoRotation = flag; mRotationDelta = delta; }
|
||||
|
||||
|
||||
|
||||
void JGameObject::SetCollisionCircle(float cx, float cy, float radius)
|
||||
{
|
||||
mUseBoundingBox = false;
|
||||
|
||||
mCenterX = cx;
|
||||
mCenterY = cy;
|
||||
mRadius = radius;
|
||||
}
|
||||
|
||||
JGameObject *JGameObject::GetCollisionTarget()
|
||||
{
|
||||
return mCollisionTarget;
|
||||
}
|
||||
|
||||
// void JGameObject::SetSize(float size)
|
||||
// {
|
||||
// mSize = size;
|
||||
// //mHScale = size;
|
||||
// //mVScale = size;
|
||||
// }
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JApp.h"
|
||||
|
||||
#include "../include/JGameObject.h"
|
||||
|
||||
|
||||
//JRenderer* JGameObject::mRenderer = NULL;
|
||||
|
||||
|
||||
|
||||
JGameObject::JGameObject(JTexture *tex, float x, float y, float width, float height)
|
||||
:JSprite(tex, x, y, width, height)
|
||||
{
|
||||
//mRenderer = JRenderer::GetInstance();
|
||||
|
||||
//mX = 0.0f;
|
||||
//mY = 0.0f;
|
||||
|
||||
mRenderFlags = 0;
|
||||
//mSize = 1.0f;
|
||||
//mAngle = 0.0f;
|
||||
|
||||
mOriginalBlood = 1;
|
||||
mBlood = 1;
|
||||
mHitPoint = 1;
|
||||
|
||||
mCollided = false;
|
||||
mCollisionTarget = NULL;
|
||||
mFlashing = false;
|
||||
|
||||
//mActive = false;
|
||||
|
||||
mRotationDelta = 0.0f;
|
||||
mDoRotation = false;
|
||||
|
||||
mAlphaDelta = 0.0f;
|
||||
mDoAlpha = false;
|
||||
|
||||
mDoScaling = false;
|
||||
mScaleDelta = 0.0f;
|
||||
|
||||
SetBBox(x, y, width, height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
JGameObject::~JGameObject()
|
||||
{
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::Update(float dt)
|
||||
{
|
||||
JSprite::Update(dt);
|
||||
|
||||
if (mFlashing)
|
||||
{
|
||||
mFlashTimer += dt;
|
||||
if (mFlashTimer > FLASH_TIME)
|
||||
{
|
||||
mFlashTimer = 0;
|
||||
mFlashCounter++;
|
||||
if (mFlashCounter > FLASHING_COUNT)
|
||||
mFlashing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mDoAlpha)
|
||||
{
|
||||
mAlpha += mAlphaDelta*dt;
|
||||
if (mAlpha < 0.0f)
|
||||
{
|
||||
mAlpha = 0.0f;
|
||||
if (mAnimationType == ANIMATION_TYPE_ONCE_AND_GONE)
|
||||
mActive = false;
|
||||
}
|
||||
else if (mAlpha > 255.0f)
|
||||
{
|
||||
mAlpha = 255.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mDoRotation || mDoScaling)
|
||||
{
|
||||
mRotation += mRotationDelta*dt;
|
||||
mHScale += mScaleDelta*dt;
|
||||
mVScale += mScaleDelta*dt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::Render()
|
||||
{
|
||||
/*
|
||||
if (mQuad != NULL)
|
||||
{
|
||||
//mEngine->RenderQuad(mQuad, mX, mY);
|
||||
if (mFlashing && (mFlashCounter&1)==0)
|
||||
{
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
}
|
||||
|
||||
float angle = 0.0f;
|
||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||
angle = mAngle;
|
||||
if ((mRenderFlags & RENDER_FLAG_ROTATION)==RENDER_FLAG_ROTATION)
|
||||
angle = mRotation;
|
||||
float scale = 1.0f;
|
||||
if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||
scale = mSize;
|
||||
|
||||
mRenderer->RenderQuad(mQuad, mX, mY, angle, scale, scale);
|
||||
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
*/
|
||||
|
||||
if (!mActive) return;
|
||||
|
||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||
mRotation = mDirection;
|
||||
|
||||
if (mFlashing && (mFlashCounter&1)==0)
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
|
||||
// if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||
// {
|
||||
// mHScale = mSize;
|
||||
// mVScale = mSize;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mHScale = 1.0f;
|
||||
// mVScale = 1.0f;
|
||||
// }
|
||||
|
||||
JSprite::Render();
|
||||
|
||||
if (mFlashing)
|
||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void JGameObject::SetPosition(float x, float y)
|
||||
// {
|
||||
// // mPos = Vector2D(x, y);
|
||||
// mX = x;
|
||||
// mY = y;
|
||||
// }
|
||||
|
||||
|
||||
//void JGameObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
|
||||
|
||||
|
||||
|
||||
//void JParticle::ResetVelocity()
|
||||
//{
|
||||
// float xx = mSpeed * cosf(mAngle);
|
||||
// float yy = mSpeed * sinf(mAngle);
|
||||
// mVelocity = Vector2D(xx, yy);
|
||||
//}
|
||||
|
||||
|
||||
void JGameObject::SetBBox(float x, float y, float width, float height)
|
||||
{
|
||||
mUseBoundingBox = true;
|
||||
|
||||
mBBoxX = x;
|
||||
mBBoxY = y;
|
||||
mBBoxWidth = width;
|
||||
mBBoxHeight = height;
|
||||
}
|
||||
|
||||
void JGameObject::GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height)
|
||||
{
|
||||
*xNow = x + mBBoxX;
|
||||
*yNow = y + mBBoxY;
|
||||
*width = mBBoxWidth;
|
||||
*height = mBBoxHeight;
|
||||
}
|
||||
|
||||
|
||||
bool JGameObject::Collide(JGameObject *target)
|
||||
{
|
||||
if (mUseBoundingBox)
|
||||
{
|
||||
// bounding box collision detection
|
||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) < -target->mBBoxWidth) return false;
|
||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) > mBBoxWidth) return false;
|
||||
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) < -target->mBBoxHeight) return false;
|
||||
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) > mBBoxHeight) return false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Circle-Circle collision detection
|
||||
float dx = (mX+mCenterX)-(target->mX+target->mCenterX);
|
||||
float dy = (mY+mCenterY)-(target->mY+target->mCenterY);
|
||||
float dr = mRadius+target->mRadius;
|
||||
if (dx*dx + dy*dy > dr*dr)
|
||||
return false;
|
||||
}
|
||||
|
||||
//mCollided = true;
|
||||
//mCollisionTarget = target;
|
||||
SetCollisionTarget(target);
|
||||
target->SetCollisionTarget(this);
|
||||
|
||||
return true; // collision!!!
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetCollisionTarget(JGameObject *target)
|
||||
{
|
||||
mBlood -= target->GetHitPoint();
|
||||
if (mBlood < 0)
|
||||
{
|
||||
// mActive = false;
|
||||
mBlood = 0;
|
||||
}
|
||||
|
||||
mCollided = true;
|
||||
mCollisionTarget = target;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int JGameObject::GetHitPoint()
|
||||
{
|
||||
return mHitPoint;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetHitPoint(int pt)
|
||||
{
|
||||
mHitPoint = pt;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::SetBlood(int pt)
|
||||
{
|
||||
mOriginalBlood = pt;
|
||||
mBlood = pt;
|
||||
}
|
||||
|
||||
int JGameObject::GetBlood()
|
||||
{
|
||||
return mBlood;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::OnCollide()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::StartFlashing()
|
||||
{
|
||||
mFlashing = true;
|
||||
mFlashTimer = 0.0f;
|
||||
mFlashCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
void JGameObject::StopFlashing()
|
||||
{
|
||||
mFlashing = false;
|
||||
}
|
||||
|
||||
|
||||
bool JGameObject::IsFlashing()
|
||||
{
|
||||
return mFlashing;
|
||||
}
|
||||
|
||||
void JGameObject::SetRenderFlags(int flags)
|
||||
{
|
||||
mRenderFlags = flags;
|
||||
}
|
||||
|
||||
// void JGameObject::SetSize(float size)
|
||||
// {
|
||||
// mSize = size;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void JGameObject::SetAngle(float angle)
|
||||
// {
|
||||
// mAngle = angle;
|
||||
// }
|
||||
|
||||
void JGameObject::EnableAlpha(bool flag, float delta) { mDoAlpha = flag; mAlphaDelta = delta; }
|
||||
void JGameObject::EnableScaling(bool flag, float delta) { mDoScaling = flag; mScaleDelta = delta; }
|
||||
void JGameObject::EnableRotation(bool flag, float delta) { mDoRotation = flag; mRotationDelta = delta; }
|
||||
|
||||
|
||||
|
||||
void JGameObject::SetCollisionCircle(float cx, float cy, float radius)
|
||||
{
|
||||
mUseBoundingBox = false;
|
||||
|
||||
mCenterX = cx;
|
||||
mCenterY = cy;
|
||||
mRadius = radius;
|
||||
}
|
||||
|
||||
JGameObject *JGameObject::GetCollisionTarget()
|
||||
{
|
||||
return mCollisionTarget;
|
||||
}
|
||||
|
||||
// void JGameObject::SetSize(float size)
|
||||
// {
|
||||
// mSize = size;
|
||||
// //mHScale = size;
|
||||
// //mVScale = size;
|
||||
// }
|
||||
|
||||
+2259
-2259
File diff suppressed because it is too large
Load Diff
+257
-257
@@ -1,257 +1,257 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JGui.h"
|
||||
|
||||
JGE* JGuiObject::mEngine = NULL;
|
||||
|
||||
JGE* JGuiController::mEngine = NULL;
|
||||
|
||||
JGuiObject::JGuiObject(int id) :
|
||||
mId(id)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
}
|
||||
|
||||
JGuiObject::~JGuiObject()
|
||||
{
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JGuiObject::ButtonPressed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void JGuiObject::Entering()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int JGuiObject::GetId()
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
void JGuiObject::Update(float dt __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &out, const JGuiObject &j)
|
||||
{
|
||||
return j.toString(out);
|
||||
}
|
||||
|
||||
JGuiController::JGuiController(int id, JGuiListener* listener) :
|
||||
mId(id), mListener(listener)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
|
||||
mBg = NULL;
|
||||
mShadingBg = NULL;
|
||||
|
||||
mCount = 0;
|
||||
mCurr = 0;
|
||||
|
||||
mCursorX = SCREEN_WIDTH / 2;
|
||||
mCursorY = SCREEN_HEIGHT / 2;
|
||||
mShowCursor = false;
|
||||
|
||||
mActionButton = JGE_BTN_OK;
|
||||
mCancelButton = JGE_BTN_MENU;
|
||||
|
||||
mStyle = JGUI_STYLE_WRAPPING;
|
||||
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
JGuiController::~JGuiController()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) delete mObjects[i];
|
||||
|
||||
}
|
||||
|
||||
void JGuiController::Render()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Render();
|
||||
}
|
||||
|
||||
bool JGuiController::CheckUserInput(JButton key)
|
||||
{
|
||||
if (!mCount) return false;
|
||||
if (key == mActionButton)
|
||||
{
|
||||
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||
{
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (key == mCancelButton)
|
||||
{
|
||||
if (mListener != NULL)
|
||||
{
|
||||
mListener->ButtonPressed(mId, kCancelMenuID);
|
||||
}
|
||||
}
|
||||
else if (JGE_BTN_CANCEL == key)
|
||||
{
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
|
||||
return true;
|
||||
}
|
||||
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n < 0)
|
||||
{
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = mCount - 1;
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
if (n > mCount - 1)
|
||||
{
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = 0;
|
||||
else
|
||||
n = mCount - 1;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
|
||||
int x, y;
|
||||
unsigned int distance2;
|
||||
unsigned int minDistance2 = -1;
|
||||
int n = mCurr;
|
||||
if (mEngine->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
float top, left;
|
||||
if (mObjects[i]->getTopLeft(top, left))
|
||||
{
|
||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||
if (distance2 < minDistance2)
|
||||
{
|
||||
minDistance2 = distance2;
|
||||
n = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
mEngine->LeftClickedProcessed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void JGuiController::Update(float dt)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
|
||||
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
}
|
||||
|
||||
void JGuiController::Add(JGuiObject* ctrl)
|
||||
{
|
||||
mObjects.push_back(ctrl);
|
||||
mCount++;
|
||||
}
|
||||
|
||||
void JGuiController::RemoveAt(int i)
|
||||
{
|
||||
if (!mObjects[i]) return;
|
||||
mObjects.erase(mObjects.begin() + i);
|
||||
delete mObjects[i];
|
||||
mCount--;
|
||||
if (mCurr == mCount) mCurr = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void JGuiController::Remove(int id)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGuiController::Remove(JGuiObject* ctrl)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i] == ctrl)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGuiController::SetActionButton(JButton button)
|
||||
{
|
||||
mActionButton = button;
|
||||
}
|
||||
void JGuiController::SetStyle(int style)
|
||||
{
|
||||
mStyle = style;
|
||||
}
|
||||
void JGuiController::SetCursor(JSprite* cursor)
|
||||
{
|
||||
mCursor = cursor;
|
||||
}
|
||||
bool JGuiController::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
void JGuiController::SetActive(bool flag)
|
||||
{
|
||||
mActive = flag;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JGui.h"
|
||||
|
||||
JGE* JGuiObject::mEngine = NULL;
|
||||
|
||||
JGE* JGuiController::mEngine = NULL;
|
||||
|
||||
JGuiObject::JGuiObject(int id) :
|
||||
mId(id)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
}
|
||||
|
||||
JGuiObject::~JGuiObject()
|
||||
{
|
||||
// JGERelease();
|
||||
}
|
||||
|
||||
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JGuiObject::ButtonPressed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void JGuiObject::Entering()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int JGuiObject::GetId()
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
void JGuiObject::Update(float dt __attribute__((unused)))
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream &out, const JGuiObject &j)
|
||||
{
|
||||
return j.toString(out);
|
||||
}
|
||||
|
||||
JGuiController::JGuiController(int id, JGuiListener* listener) :
|
||||
mId(id), mListener(listener)
|
||||
{
|
||||
mEngine = JGE::GetInstance();
|
||||
|
||||
mBg = NULL;
|
||||
mShadingBg = NULL;
|
||||
|
||||
mCount = 0;
|
||||
mCurr = 0;
|
||||
|
||||
mCursorX = SCREEN_WIDTH / 2;
|
||||
mCursorY = SCREEN_HEIGHT / 2;
|
||||
mShowCursor = false;
|
||||
|
||||
mActionButton = JGE_BTN_OK;
|
||||
mCancelButton = JGE_BTN_MENU;
|
||||
|
||||
mStyle = JGUI_STYLE_WRAPPING;
|
||||
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
JGuiController::~JGuiController()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) delete mObjects[i];
|
||||
|
||||
}
|
||||
|
||||
void JGuiController::Render()
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Render();
|
||||
}
|
||||
|
||||
bool JGuiController::CheckUserInput(JButton key)
|
||||
{
|
||||
if (!mCount) return false;
|
||||
if (key == mActionButton)
|
||||
{
|
||||
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||
{
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (key == mCancelButton)
|
||||
{
|
||||
if (mListener != NULL)
|
||||
{
|
||||
mListener->ButtonPressed(mId, kCancelMenuID);
|
||||
}
|
||||
}
|
||||
else if (JGE_BTN_CANCEL == key)
|
||||
{
|
||||
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
|
||||
return true;
|
||||
}
|
||||
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
if (n < 0)
|
||||
{
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = mCount - 1;
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
if (n > mCount - 1)
|
||||
{
|
||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||
n = 0;
|
||||
else
|
||||
n = mCount - 1;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
|
||||
int x, y;
|
||||
unsigned int distance2;
|
||||
unsigned int minDistance2 = -1;
|
||||
int n = mCurr;
|
||||
if (mEngine->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
float top, left;
|
||||
if (mObjects[i]->getTopLeft(top, left))
|
||||
{
|
||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||
if (distance2 < minDistance2)
|
||||
{
|
||||
minDistance2 = distance2;
|
||||
n = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
mEngine->LeftClickedProcessed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void JGuiController::Update(float dt)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
|
||||
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
}
|
||||
|
||||
void JGuiController::Add(JGuiObject* ctrl)
|
||||
{
|
||||
mObjects.push_back(ctrl);
|
||||
mCount++;
|
||||
}
|
||||
|
||||
void JGuiController::RemoveAt(int i)
|
||||
{
|
||||
if (!mObjects[i]) return;
|
||||
mObjects.erase(mObjects.begin() + i);
|
||||
delete mObjects[i];
|
||||
mCount--;
|
||||
if (mCurr == mCount) mCurr = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void JGuiController::Remove(int id)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGuiController::Remove(JGuiObject* ctrl)
|
||||
{
|
||||
for (int i = 0; i < mCount; i++)
|
||||
{
|
||||
if (mObjects[i] != NULL && mObjects[i] == ctrl)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JGuiController::SetActionButton(JButton button)
|
||||
{
|
||||
mActionButton = button;
|
||||
}
|
||||
void JGuiController::SetStyle(int style)
|
||||
{
|
||||
mStyle = style;
|
||||
}
|
||||
void JGuiController::SetCursor(JSprite* cursor)
|
||||
{
|
||||
mCursor = cursor;
|
||||
}
|
||||
bool JGuiController::IsActive()
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
void JGuiController::SetActive(bool flag)
|
||||
{
|
||||
mActive = flag;
|
||||
}
|
||||
|
||||
+677
-677
File diff suppressed because it is too large
Load Diff
+222
-222
@@ -1,222 +1,222 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JTypes.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JOBJModel.h"
|
||||
|
||||
JOBJModel::JOBJModel()
|
||||
{
|
||||
mPolygons = NULL;
|
||||
mTexture = NULL;
|
||||
}
|
||||
|
||||
JOBJModel::~JOBJModel()
|
||||
{
|
||||
if (mPolygons)
|
||||
delete [] mPolygons;
|
||||
|
||||
if (mTexture)
|
||||
delete mTexture;
|
||||
}
|
||||
|
||||
int JOBJModel::ReadLine(char *output, const char *buffer, int start, int size)
|
||||
{
|
||||
int index = 0;
|
||||
while (start < size && buffer[start] != '\n' && buffer[start] != '\r')
|
||||
output[index++] = buffer[start++];
|
||||
|
||||
while ((start < size && buffer[start] == '\n') || buffer[start] == '\r')
|
||||
start++;
|
||||
|
||||
output[index] = 0;
|
||||
|
||||
return start;
|
||||
|
||||
}
|
||||
|
||||
bool JOBJModel::Load(const char *modelName, const char *textureName)
|
||||
{
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
if (!fileSys->OpenFile(modelName))
|
||||
return false;
|
||||
|
||||
int size = fileSys->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
|
||||
fileSys->ReadFile(buffer, size);
|
||||
fileSys->CloseFile();
|
||||
|
||||
Vector3D vert;
|
||||
|
||||
vector<Face> faceList;
|
||||
vector<Vector3D> normalList;
|
||||
vector<Vector3D> texList;
|
||||
vector<Vector3D> vertList;
|
||||
|
||||
normalList.reserve(32);
|
||||
texList.reserve(32);
|
||||
vertList.reserve(32);
|
||||
faceList.reserve(32);
|
||||
|
||||
int filePtr = 0;
|
||||
|
||||
char tmpLine[256];
|
||||
char s1[256];
|
||||
|
||||
int count;
|
||||
|
||||
while (filePtr < size)
|
||||
{
|
||||
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
||||
{
|
||||
|
||||
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
||||
{
|
||||
}
|
||||
else if (tmpLine[0] == 'v')
|
||||
{
|
||||
count = sscanf(tmpLine, "%s %f %f %f", s1, &vert.x, &vert.y, &vert.z);
|
||||
|
||||
if (count == 4)
|
||||
{
|
||||
if (strcmp(s1, "vn") == 0)
|
||||
normalList.push_back(vert);
|
||||
else if (strcmp(s1, "vt") == 0)
|
||||
texList.push_back(vert);
|
||||
else if (strcmp(s1, "v") == 0)
|
||||
vertList.push_back(vert);
|
||||
}
|
||||
else if (count == 3)
|
||||
{
|
||||
if (strcmp(s1, "vt") == 0)
|
||||
texList.push_back(vert);
|
||||
}
|
||||
|
||||
}
|
||||
else if (tmpLine[0] == 'f')
|
||||
{
|
||||
Face face;
|
||||
face.mVertCount = 0;
|
||||
|
||||
char *p = strchr(tmpLine, ' ');
|
||||
char *pNext = p;
|
||||
|
||||
int vertIdx, texIdx, norIdx;
|
||||
|
||||
while (p != NULL)
|
||||
{
|
||||
while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
|
||||
++p;
|
||||
strcpy(s1, p);
|
||||
count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
|
||||
if (count == 3)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||
face.mNormalIdx[face.mVertCount] = norIdx - 1;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
else if (count == 2)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||
face.mNormalIdx[face.mVertCount] = 0;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
else if (count == 1)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = 0;
|
||||
face.mNormalIdx[face.mVertCount] = 0;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
|
||||
pNext = strchr(p, ' ');
|
||||
p = pNext;
|
||||
}
|
||||
|
||||
if (face.mVertCount == 3) // we do triangles only ;)
|
||||
faceList.push_back(face);
|
||||
}
|
||||
else if (tmpLine[0] == 'g')
|
||||
{
|
||||
|
||||
}
|
||||
else if (tmpLine[0] == 'u')
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mPolycount = faceList.size();
|
||||
mPolygons = new Vertex3D[mPolycount*3];
|
||||
|
||||
int idx = 0;
|
||||
for (int i=0;i<mPolycount;i++)
|
||||
{
|
||||
|
||||
for (int j=0;j<3;j++)
|
||||
{
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
|
||||
mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
|
||||
idx++;
|
||||
}
|
||||
|
||||
/*
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
|
||||
idx++;
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
|
||||
idx++;
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
|
||||
idx++;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
if (textureName != NULL)
|
||||
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JOBJModel::Render()
|
||||
{
|
||||
JRenderer::GetInstance()->RenderTriangles(mTexture, mPolygons, 0, mPolycount);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JTypes.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JOBJModel.h"
|
||||
|
||||
JOBJModel::JOBJModel()
|
||||
{
|
||||
mPolygons = NULL;
|
||||
mTexture = NULL;
|
||||
}
|
||||
|
||||
JOBJModel::~JOBJModel()
|
||||
{
|
||||
if (mPolygons)
|
||||
delete [] mPolygons;
|
||||
|
||||
if (mTexture)
|
||||
delete mTexture;
|
||||
}
|
||||
|
||||
int JOBJModel::ReadLine(char *output, const char *buffer, int start, int size)
|
||||
{
|
||||
int index = 0;
|
||||
while (start < size && buffer[start] != '\n' && buffer[start] != '\r')
|
||||
output[index++] = buffer[start++];
|
||||
|
||||
while ((start < size && buffer[start] == '\n') || buffer[start] == '\r')
|
||||
start++;
|
||||
|
||||
output[index] = 0;
|
||||
|
||||
return start;
|
||||
|
||||
}
|
||||
|
||||
bool JOBJModel::Load(const char *modelName, const char *textureName)
|
||||
{
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
if (!fileSys->OpenFile(modelName))
|
||||
return false;
|
||||
|
||||
int size = fileSys->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
|
||||
fileSys->ReadFile(buffer, size);
|
||||
fileSys->CloseFile();
|
||||
|
||||
Vector3D vert;
|
||||
|
||||
vector<Face> faceList;
|
||||
vector<Vector3D> normalList;
|
||||
vector<Vector3D> texList;
|
||||
vector<Vector3D> vertList;
|
||||
|
||||
normalList.reserve(32);
|
||||
texList.reserve(32);
|
||||
vertList.reserve(32);
|
||||
faceList.reserve(32);
|
||||
|
||||
int filePtr = 0;
|
||||
|
||||
char tmpLine[256];
|
||||
char s1[256];
|
||||
|
||||
int count;
|
||||
|
||||
while (filePtr < size)
|
||||
{
|
||||
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
||||
{
|
||||
|
||||
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
||||
{
|
||||
}
|
||||
else if (tmpLine[0] == 'v')
|
||||
{
|
||||
count = sscanf(tmpLine, "%s %f %f %f", s1, &vert.x, &vert.y, &vert.z);
|
||||
|
||||
if (count == 4)
|
||||
{
|
||||
if (strcmp(s1, "vn") == 0)
|
||||
normalList.push_back(vert);
|
||||
else if (strcmp(s1, "vt") == 0)
|
||||
texList.push_back(vert);
|
||||
else if (strcmp(s1, "v") == 0)
|
||||
vertList.push_back(vert);
|
||||
}
|
||||
else if (count == 3)
|
||||
{
|
||||
if (strcmp(s1, "vt") == 0)
|
||||
texList.push_back(vert);
|
||||
}
|
||||
|
||||
}
|
||||
else if (tmpLine[0] == 'f')
|
||||
{
|
||||
Face face;
|
||||
face.mVertCount = 0;
|
||||
|
||||
char *p = strchr(tmpLine, ' ');
|
||||
char *pNext = p;
|
||||
|
||||
int vertIdx, texIdx, norIdx;
|
||||
|
||||
while (p != NULL)
|
||||
{
|
||||
while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
|
||||
++p;
|
||||
strcpy(s1, p);
|
||||
count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
|
||||
if (count == 3)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||
face.mNormalIdx[face.mVertCount] = norIdx - 1;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
else if (count == 2)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||
face.mNormalIdx[face.mVertCount] = 0;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
else if (count == 1)
|
||||
{
|
||||
if (face.mVertCount < 4)
|
||||
{
|
||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||
face.mTexIdx[face.mVertCount] = 0;
|
||||
face.mNormalIdx[face.mVertCount] = 0;
|
||||
face.mVertCount++;
|
||||
}
|
||||
}
|
||||
|
||||
pNext = strchr(p, ' ');
|
||||
p = pNext;
|
||||
}
|
||||
|
||||
if (face.mVertCount == 3) // we do triangles only ;)
|
||||
faceList.push_back(face);
|
||||
}
|
||||
else if (tmpLine[0] == 'g')
|
||||
{
|
||||
|
||||
}
|
||||
else if (tmpLine[0] == 'u')
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mPolycount = faceList.size();
|
||||
mPolygons = new Vertex3D[mPolycount*3];
|
||||
|
||||
int idx = 0;
|
||||
for (int i=0;i<mPolycount;i++)
|
||||
{
|
||||
|
||||
for (int j=0;j<3;j++)
|
||||
{
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
|
||||
mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
|
||||
idx++;
|
||||
}
|
||||
|
||||
/*
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
|
||||
idx++;
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
|
||||
idx++;
|
||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
|
||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
|
||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
|
||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
|
||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
|
||||
idx++;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
if (textureName != NULL)
|
||||
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JOBJModel::Render()
|
||||
{
|
||||
JRenderer::GetInstance()->RenderTriangles(mTexture, mPolygons, 0, mPolycount);
|
||||
}
|
||||
|
||||
+246
-246
@@ -1,246 +1,246 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//#include "JApp.h"
|
||||
#include "../include/JGE.h"
|
||||
|
||||
#include "../include/JParticle.h"
|
||||
|
||||
|
||||
|
||||
JParticleData::JParticleData()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void JParticleData::Clear()
|
||||
{
|
||||
mCurr = 0.0f;
|
||||
mTarget = 0.0f;
|
||||
mDelta = 0.0f;
|
||||
mKeyCount = 0;
|
||||
mKeyIndex = 0;
|
||||
mTimer = 0.0f;
|
||||
mScale = 1.0f;
|
||||
}
|
||||
|
||||
void JParticleData::Init()
|
||||
{
|
||||
mKeyIndex = 0;
|
||||
mDelta = 0.0f;
|
||||
mTimer = 0.0f;
|
||||
if (mKeyCount > 0)
|
||||
{
|
||||
mCurr = mKeyValue[mKeyIndex++];
|
||||
|
||||
if (mKeyIndex < mKeyCount)
|
||||
{
|
||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||
mTarget = mKeyValue[mKeyIndex];
|
||||
mDelta = (mTarget-mCurr)/mTimer;
|
||||
mKeyIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::AddKey(float keyTime, float keyValue)
|
||||
{
|
||||
if (mKeyCount < MAX_KEYS)
|
||||
{
|
||||
mKeyTime[mKeyCount] = keyTime;
|
||||
mKeyValue[mKeyCount] = keyValue;
|
||||
mKeyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::Update(float dt)
|
||||
{
|
||||
mCurr += mDelta*dt;
|
||||
if (mDelta < 0.0f)
|
||||
{
|
||||
if (mCurr < mTarget)
|
||||
mCurr = mTarget;
|
||||
|
||||
}
|
||||
else if (mDelta > 0.0f)
|
||||
{
|
||||
if (mCurr > mTarget)
|
||||
mCurr = mTarget;
|
||||
}
|
||||
|
||||
mTimer -= dt;
|
||||
|
||||
if (mTimer <= 0.0f)
|
||||
{
|
||||
if (mKeyIndex < mKeyCount)
|
||||
{
|
||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||
mTarget = mKeyValue[mKeyIndex];
|
||||
mDelta = (mTarget-mCurr)/mTimer;
|
||||
mKeyIndex++;
|
||||
}
|
||||
else
|
||||
mDelta = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::SetScale(float scale)
|
||||
{
|
||||
mScale = scale;
|
||||
}
|
||||
|
||||
|
||||
JRenderer* JParticle::mRenderer = NULL;
|
||||
|
||||
JParticleData* JParticle::GetField(int index)
|
||||
{
|
||||
if (index < FIELD_COUNT)
|
||||
return &mData[index];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
JParticleData* JParticle::GetDataPtr()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
JParticle::JParticle()//JQuad* texture, float x, float y)
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
|
||||
//mTexture = texture;
|
||||
mOrigin = Vector2D(0.0f, 0.0f);
|
||||
mPos = Vector2D(0.0f, 0.0f);
|
||||
mVelocity = Vector2D(0.0f, 0.0f);
|
||||
|
||||
mActive = false;
|
||||
mQuad = NULL;
|
||||
|
||||
// mNext = NULL;
|
||||
// mPrev = NULL;
|
||||
}
|
||||
|
||||
|
||||
JParticle::~JParticle()
|
||||
{
|
||||
//JGERelease();
|
||||
}
|
||||
|
||||
|
||||
bool JParticle::Update(float dt)
|
||||
{
|
||||
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
mData[i].Update(dt);
|
||||
|
||||
|
||||
// the radial and tangential acceleration code was taken from HGE's particle source
|
||||
Vector2D vecAccel = mPos - mOrigin; //par->vecLocation-vecLocation;
|
||||
vecAccel.Normalize();
|
||||
Vector2D vecAccel2 = vecAccel;
|
||||
vecAccel *= mData[FIELD_RADIAL_ACCEL].mCurr; //par->fRadialAccel;
|
||||
|
||||
// vecAccel2.Rotate(M_PI_2);
|
||||
// the following is faster
|
||||
float ang = vecAccel2.x;
|
||||
vecAccel2.x = -vecAccel2.y;
|
||||
vecAccel2.y = ang;
|
||||
|
||||
vecAccel2 *= mData[FIELD_TANGENTIAL_ACCEL].mCurr; //par->fTangentialAccel;
|
||||
mVelocity += (vecAccel+vecAccel2)*dt; //par->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||
mVelocity.y += mData[FIELD_GRAVITY].mCurr*dt; //par->vecVelocity.y += par->fGravity*fDeltaTime;
|
||||
|
||||
//par->vecLocation += par->vecVelocity*fDeltaTime;
|
||||
|
||||
////mPos.x += mData[FIELD_SPEED].mCurr * mVelocity.x * dt;
|
||||
////mPos.y += mData[FIELD_SPEED].mCurr * mVelocity.y * dt;
|
||||
mPos += mVelocity*mData[FIELD_SPEED].mCurr*dt;
|
||||
|
||||
|
||||
mLifetime -= dt;
|
||||
if (mLifetime <= 0.0f)
|
||||
{
|
||||
mActive = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void JParticle::Render()
|
||||
{
|
||||
if (mQuad)
|
||||
{
|
||||
int a = (int)(mData[FIELD_ALPHA].mCurr*255.0f);
|
||||
int r = (int)(mData[FIELD_RED].mCurr*255.0f);
|
||||
int g = (int)(mData[FIELD_GREEN].mCurr*255.0f);
|
||||
int b = (int)(mData[FIELD_BLUE].mCurr*255.0f);
|
||||
PIXEL_TYPE color = ARGB(a, r, g, b);
|
||||
mQuad->SetColor(color);
|
||||
|
||||
mRenderer->RenderQuad(mQuad, mPos.x, mPos.y, mData[FIELD_ROTATION].mCurr, mData[FIELD_SIZE].mCurr*mSize, mData[FIELD_SIZE].mCurr*mSize);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JParticle::Init(float lifeTime)
|
||||
{
|
||||
mLifetime = lifeTime;
|
||||
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
{
|
||||
mData[i].SetScale(lifeTime);
|
||||
mData[i].Init();
|
||||
}
|
||||
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
|
||||
void JParticle::InitPosition(float ox, float oy, float xoffset, float yoffset)
|
||||
{
|
||||
mOrigin = Vector2D(ox, oy);
|
||||
mPos = Vector2D(ox+xoffset, oy+yoffset);
|
||||
}
|
||||
|
||||
|
||||
void JParticle::SetPosition(float x, float y)
|
||||
{
|
||||
mPos = Vector2D(x, y);
|
||||
mOrigin = Vector2D(x, y);
|
||||
}
|
||||
|
||||
void JParticle::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
|
||||
void JParticle::Move(float x, float y)
|
||||
{
|
||||
mPos.x += x;
|
||||
mPos.y += y;
|
||||
|
||||
mOrigin.x += x;
|
||||
mOrigin.y += y;
|
||||
}
|
||||
|
||||
//void JParticle::ResetVelocity()
|
||||
//{
|
||||
// float xx = mSpeed * cosf(mAngle);
|
||||
// float yy = mSpeed * sinf(mAngle);
|
||||
// mVelocity = Vector2D(xx, yy);
|
||||
//}
|
||||
|
||||
void JParticle::SetVelocity(float x, float y) { mVelocity = Vector2D(x, y); }
|
||||
void JParticle::SetSize(float size) { mSize = size;}
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//#include "JApp.h"
|
||||
#include "../include/JGE.h"
|
||||
|
||||
#include "../include/JParticle.h"
|
||||
|
||||
|
||||
|
||||
JParticleData::JParticleData()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void JParticleData::Clear()
|
||||
{
|
||||
mCurr = 0.0f;
|
||||
mTarget = 0.0f;
|
||||
mDelta = 0.0f;
|
||||
mKeyCount = 0;
|
||||
mKeyIndex = 0;
|
||||
mTimer = 0.0f;
|
||||
mScale = 1.0f;
|
||||
}
|
||||
|
||||
void JParticleData::Init()
|
||||
{
|
||||
mKeyIndex = 0;
|
||||
mDelta = 0.0f;
|
||||
mTimer = 0.0f;
|
||||
if (mKeyCount > 0)
|
||||
{
|
||||
mCurr = mKeyValue[mKeyIndex++];
|
||||
|
||||
if (mKeyIndex < mKeyCount)
|
||||
{
|
||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||
mTarget = mKeyValue[mKeyIndex];
|
||||
mDelta = (mTarget-mCurr)/mTimer;
|
||||
mKeyIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::AddKey(float keyTime, float keyValue)
|
||||
{
|
||||
if (mKeyCount < MAX_KEYS)
|
||||
{
|
||||
mKeyTime[mKeyCount] = keyTime;
|
||||
mKeyValue[mKeyCount] = keyValue;
|
||||
mKeyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::Update(float dt)
|
||||
{
|
||||
mCurr += mDelta*dt;
|
||||
if (mDelta < 0.0f)
|
||||
{
|
||||
if (mCurr < mTarget)
|
||||
mCurr = mTarget;
|
||||
|
||||
}
|
||||
else if (mDelta > 0.0f)
|
||||
{
|
||||
if (mCurr > mTarget)
|
||||
mCurr = mTarget;
|
||||
}
|
||||
|
||||
mTimer -= dt;
|
||||
|
||||
if (mTimer <= 0.0f)
|
||||
{
|
||||
if (mKeyIndex < mKeyCount)
|
||||
{
|
||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||
mTarget = mKeyValue[mKeyIndex];
|
||||
mDelta = (mTarget-mCurr)/mTimer;
|
||||
mKeyIndex++;
|
||||
}
|
||||
else
|
||||
mDelta = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void JParticleData::SetScale(float scale)
|
||||
{
|
||||
mScale = scale;
|
||||
}
|
||||
|
||||
|
||||
JRenderer* JParticle::mRenderer = NULL;
|
||||
|
||||
JParticleData* JParticle::GetField(int index)
|
||||
{
|
||||
if (index < FIELD_COUNT)
|
||||
return &mData[index];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
JParticleData* JParticle::GetDataPtr()
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
JParticle::JParticle()//JQuad* texture, float x, float y)
|
||||
{
|
||||
mRenderer = JRenderer::GetInstance();
|
||||
|
||||
//mTexture = texture;
|
||||
mOrigin = Vector2D(0.0f, 0.0f);
|
||||
mPos = Vector2D(0.0f, 0.0f);
|
||||
mVelocity = Vector2D(0.0f, 0.0f);
|
||||
|
||||
mActive = false;
|
||||
mQuad = NULL;
|
||||
|
||||
// mNext = NULL;
|
||||
// mPrev = NULL;
|
||||
}
|
||||
|
||||
|
||||
JParticle::~JParticle()
|
||||
{
|
||||
//JGERelease();
|
||||
}
|
||||
|
||||
|
||||
bool JParticle::Update(float dt)
|
||||
{
|
||||
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
mData[i].Update(dt);
|
||||
|
||||
|
||||
// the radial and tangential acceleration code was taken from HGE's particle source
|
||||
Vector2D vecAccel = mPos - mOrigin; //par->vecLocation-vecLocation;
|
||||
vecAccel.Normalize();
|
||||
Vector2D vecAccel2 = vecAccel;
|
||||
vecAccel *= mData[FIELD_RADIAL_ACCEL].mCurr; //par->fRadialAccel;
|
||||
|
||||
// vecAccel2.Rotate(M_PI_2);
|
||||
// the following is faster
|
||||
float ang = vecAccel2.x;
|
||||
vecAccel2.x = -vecAccel2.y;
|
||||
vecAccel2.y = ang;
|
||||
|
||||
vecAccel2 *= mData[FIELD_TANGENTIAL_ACCEL].mCurr; //par->fTangentialAccel;
|
||||
mVelocity += (vecAccel+vecAccel2)*dt; //par->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||
mVelocity.y += mData[FIELD_GRAVITY].mCurr*dt; //par->vecVelocity.y += par->fGravity*fDeltaTime;
|
||||
|
||||
//par->vecLocation += par->vecVelocity*fDeltaTime;
|
||||
|
||||
////mPos.x += mData[FIELD_SPEED].mCurr * mVelocity.x * dt;
|
||||
////mPos.y += mData[FIELD_SPEED].mCurr * mVelocity.y * dt;
|
||||
mPos += mVelocity*mData[FIELD_SPEED].mCurr*dt;
|
||||
|
||||
|
||||
mLifetime -= dt;
|
||||
if (mLifetime <= 0.0f)
|
||||
{
|
||||
mActive = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void JParticle::Render()
|
||||
{
|
||||
if (mQuad)
|
||||
{
|
||||
int a = (int)(mData[FIELD_ALPHA].mCurr*255.0f);
|
||||
int r = (int)(mData[FIELD_RED].mCurr*255.0f);
|
||||
int g = (int)(mData[FIELD_GREEN].mCurr*255.0f);
|
||||
int b = (int)(mData[FIELD_BLUE].mCurr*255.0f);
|
||||
PIXEL_TYPE color = ARGB(a, r, g, b);
|
||||
mQuad->SetColor(color);
|
||||
|
||||
mRenderer->RenderQuad(mQuad, mPos.x, mPos.y, mData[FIELD_ROTATION].mCurr, mData[FIELD_SIZE].mCurr*mSize, mData[FIELD_SIZE].mCurr*mSize);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JParticle::Init(float lifeTime)
|
||||
{
|
||||
mLifetime = lifeTime;
|
||||
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
{
|
||||
mData[i].SetScale(lifeTime);
|
||||
mData[i].Init();
|
||||
}
|
||||
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
|
||||
void JParticle::InitPosition(float ox, float oy, float xoffset, float yoffset)
|
||||
{
|
||||
mOrigin = Vector2D(ox, oy);
|
||||
mPos = Vector2D(ox+xoffset, oy+yoffset);
|
||||
}
|
||||
|
||||
|
||||
void JParticle::SetPosition(float x, float y)
|
||||
{
|
||||
mPos = Vector2D(x, y);
|
||||
mOrigin = Vector2D(x, y);
|
||||
}
|
||||
|
||||
void JParticle::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||
|
||||
void JParticle::Move(float x, float y)
|
||||
{
|
||||
mPos.x += x;
|
||||
mPos.y += y;
|
||||
|
||||
mOrigin.x += x;
|
||||
mOrigin.y += y;
|
||||
}
|
||||
|
||||
//void JParticle::ResetVelocity()
|
||||
//{
|
||||
// float xx = mSpeed * cosf(mAngle);
|
||||
// float yy = mSpeed * sinf(mAngle);
|
||||
// mVelocity = Vector2D(xx, yy);
|
||||
//}
|
||||
|
||||
void JParticle::SetVelocity(float x, float y) { mVelocity = Vector2D(x, y); }
|
||||
void JParticle::SetSize(float size) { mSize = size;}
|
||||
|
||||
|
||||
+389
-389
@@ -1,389 +1,389 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
#include "../include/JParticleEmitter.h"
|
||||
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
JParticleEffect::JParticleEffect(JResourceManager* mgr)
|
||||
{
|
||||
mResourceManager = mgr;
|
||||
|
||||
mX = 0.0f;
|
||||
mY = 0.0f;
|
||||
|
||||
mEmitterCount = 0;
|
||||
}
|
||||
|
||||
|
||||
JParticleEffect::~JParticleEffect()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
if (mParticleEmitters[i])
|
||||
delete (mParticleEmitters[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JParticleEffect::Load(const char* filename)
|
||||
{
|
||||
mX = 0.0f;
|
||||
mY = 0.0f;
|
||||
|
||||
mEmitterCount = 0;
|
||||
|
||||
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem == NULL) return false;
|
||||
|
||||
if (!fileSystem->OpenFile(filename)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
|
||||
TiXmlNode* effect = 0;
|
||||
TiXmlNode* emitter = 0;
|
||||
TiXmlNode* param = 0;
|
||||
TiXmlNode* key = 0;
|
||||
|
||||
TiXmlElement* element = 0;
|
||||
|
||||
float keyTime;
|
||||
float value;
|
||||
float baseValue;
|
||||
int int_value;
|
||||
//
|
||||
// enum ParticleField
|
||||
// {
|
||||
// FIELD_SPEED,
|
||||
// FIELD_SIZE,
|
||||
// FIELD_ROTATION,
|
||||
// FIELD_ALPHA,
|
||||
// FIELD_RED,
|
||||
// FIELD_GREEN,
|
||||
// FIELD_BLUE,
|
||||
// FIELD_COUNT
|
||||
// };
|
||||
|
||||
const char* lifeValues[] =
|
||||
{
|
||||
"speed",
|
||||
"size",
|
||||
"rotation",
|
||||
"alpha",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"radial_accel",
|
||||
"tangential_accel",
|
||||
"gravity"
|
||||
};
|
||||
|
||||
const char* typeNames[] =
|
||||
{
|
||||
"POINT",
|
||||
"AREA",
|
||||
"HORIZONTAL",
|
||||
"VERTICAL",
|
||||
"CIRCLE"
|
||||
};
|
||||
|
||||
const char* modeNames[] =
|
||||
{
|
||||
"REPEAT",
|
||||
"ONCE",
|
||||
"NTIMES",
|
||||
"CONTINUOUS"
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// One effect per file only, well, we may extend it later to permit
|
||||
// multiple effect definitions:
|
||||
//
|
||||
// for (effect = doc.FirstChild("effect"); effect; effect = effect->NextSibling())
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
effect = doc.FirstChild("effect");
|
||||
if (effect)
|
||||
{
|
||||
element = effect->ToElement();
|
||||
printf("%s:%s\n", element->Value(), element->Attribute("name"));
|
||||
|
||||
|
||||
for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
|
||||
{
|
||||
|
||||
mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
|
||||
element = emitter->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
|
||||
mParticleEmitters[mEmitterCount]->mLife = value;
|
||||
|
||||
for (param = emitter->FirstChild(); param; param = param->NextSibling())
|
||||
{
|
||||
element = param->ToElement();
|
||||
|
||||
if (strcmp(element->Attribute("name"), "settings")==0)
|
||||
{
|
||||
|
||||
if (strcmp(element->Attribute("blend"), "NORMAL")==0)
|
||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
|
||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
|
||||
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("mode"), modeNames[i])==0)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
||||
#if defined (_DEBUG)
|
||||
printf("emitter mode:%s\n", modeNames[i]);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("type"), typeNames[i])==0)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mType = i;
|
||||
#if defined (_DEBUG)
|
||||
printf("emitter type:%s\n", typeNames[i]);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string quadName = element->Attribute("image");
|
||||
JQuad* quad = mResourceManager->GetQuad(quadName);
|
||||
if (quad != NULL)
|
||||
mParticleEmitters[mEmitterCount]->SetQuad(quad);
|
||||
|
||||
// if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
|
||||
// {
|
||||
// mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
|
||||
//
|
||||
// }
|
||||
if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mWidth = int_value;
|
||||
|
||||
}
|
||||
if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mHeight = int_value;
|
||||
|
||||
}
|
||||
|
||||
if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mId = int_value;
|
||||
|
||||
}
|
||||
|
||||
if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "quantity")==0)
|
||||
{
|
||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||
{
|
||||
element = key->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "lifex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "anglex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
|
||||
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "speedx")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "sizex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mSizeMax= value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("name"), lifeValues[i])==0)
|
||||
{
|
||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||
{
|
||||
element = key->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
if (i==FIELD_ROTATION)
|
||||
value *= DEG2RAD;
|
||||
|
||||
mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
mEmitterCount++;
|
||||
}
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::SetParticleSystem(JParticleSystem* particleSys)
|
||||
{
|
||||
mParticleSystem = particleSys;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::SetPosition(float x, float y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
|
||||
JParticleSystem* JParticleEffect::GetParticleSystem()
|
||||
{
|
||||
return mParticleSystem;
|
||||
}
|
||||
|
||||
|
||||
float JParticleEffect::GetX()
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
float JParticleEffect::GetY()
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Update(float dt)
|
||||
{
|
||||
// mTimer += dt;
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Update(dt);
|
||||
}
|
||||
|
||||
void JParticleEffect::Render()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Render();
|
||||
}
|
||||
|
||||
bool JParticleEffect::Done()
|
||||
{
|
||||
bool done = true;
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
if (!mParticleEmitters[i]->Done())
|
||||
done = false;
|
||||
|
||||
return (done);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Start()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Start();
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Stop()
|
||||
{
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::MoveTo(float x, float y)
|
||||
{
|
||||
float dx = x - mX;
|
||||
float dy = y - mY;
|
||||
|
||||
mX = x;
|
||||
mY = y;
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
{
|
||||
mParticleEmitters[i]->MoveAllParticles(dx, dy);
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
#include "../include/JParticleEmitter.h"
|
||||
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
JParticleEffect::JParticleEffect(JResourceManager* mgr)
|
||||
{
|
||||
mResourceManager = mgr;
|
||||
|
||||
mX = 0.0f;
|
||||
mY = 0.0f;
|
||||
|
||||
mEmitterCount = 0;
|
||||
}
|
||||
|
||||
|
||||
JParticleEffect::~JParticleEffect()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
if (mParticleEmitters[i])
|
||||
delete (mParticleEmitters[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JParticleEffect::Load(const char* filename)
|
||||
{
|
||||
mX = 0.0f;
|
||||
mY = 0.0f;
|
||||
|
||||
mEmitterCount = 0;
|
||||
|
||||
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem == NULL) return false;
|
||||
|
||||
if (!fileSystem->OpenFile(filename)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
|
||||
TiXmlNode* effect = 0;
|
||||
TiXmlNode* emitter = 0;
|
||||
TiXmlNode* param = 0;
|
||||
TiXmlNode* key = 0;
|
||||
|
||||
TiXmlElement* element = 0;
|
||||
|
||||
float keyTime;
|
||||
float value;
|
||||
float baseValue;
|
||||
int int_value;
|
||||
//
|
||||
// enum ParticleField
|
||||
// {
|
||||
// FIELD_SPEED,
|
||||
// FIELD_SIZE,
|
||||
// FIELD_ROTATION,
|
||||
// FIELD_ALPHA,
|
||||
// FIELD_RED,
|
||||
// FIELD_GREEN,
|
||||
// FIELD_BLUE,
|
||||
// FIELD_COUNT
|
||||
// };
|
||||
|
||||
const char* lifeValues[] =
|
||||
{
|
||||
"speed",
|
||||
"size",
|
||||
"rotation",
|
||||
"alpha",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"radial_accel",
|
||||
"tangential_accel",
|
||||
"gravity"
|
||||
};
|
||||
|
||||
const char* typeNames[] =
|
||||
{
|
||||
"POINT",
|
||||
"AREA",
|
||||
"HORIZONTAL",
|
||||
"VERTICAL",
|
||||
"CIRCLE"
|
||||
};
|
||||
|
||||
const char* modeNames[] =
|
||||
{
|
||||
"REPEAT",
|
||||
"ONCE",
|
||||
"NTIMES",
|
||||
"CONTINUOUS"
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// One effect per file only, well, we may extend it later to permit
|
||||
// multiple effect definitions:
|
||||
//
|
||||
// for (effect = doc.FirstChild("effect"); effect; effect = effect->NextSibling())
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
effect = doc.FirstChild("effect");
|
||||
if (effect)
|
||||
{
|
||||
element = effect->ToElement();
|
||||
printf("%s:%s\n", element->Value(), element->Attribute("name"));
|
||||
|
||||
|
||||
for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
|
||||
{
|
||||
|
||||
mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
|
||||
element = emitter->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
|
||||
mParticleEmitters[mEmitterCount]->mLife = value;
|
||||
|
||||
for (param = emitter->FirstChild(); param; param = param->NextSibling())
|
||||
{
|
||||
element = param->ToElement();
|
||||
|
||||
if (strcmp(element->Attribute("name"), "settings")==0)
|
||||
{
|
||||
|
||||
if (strcmp(element->Attribute("blend"), "NORMAL")==0)
|
||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
|
||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||
|
||||
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("mode"), modeNames[i])==0)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
||||
#if defined (_DEBUG)
|
||||
printf("emitter mode:%s\n", modeNames[i]);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("type"), typeNames[i])==0)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mType = i;
|
||||
#if defined (_DEBUG)
|
||||
printf("emitter type:%s\n", typeNames[i]);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string quadName = element->Attribute("image");
|
||||
JQuad* quad = mResourceManager->GetQuad(quadName);
|
||||
if (quad != NULL)
|
||||
mParticleEmitters[mEmitterCount]->SetQuad(quad);
|
||||
|
||||
// if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
|
||||
// {
|
||||
// mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
|
||||
//
|
||||
// }
|
||||
if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mWidth = int_value;
|
||||
|
||||
}
|
||||
if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mHeight = int_value;
|
||||
|
||||
}
|
||||
|
||||
if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mId = int_value;
|
||||
|
||||
}
|
||||
|
||||
if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "quantity")==0)
|
||||
{
|
||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||
{
|
||||
element = key->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "lifex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "anglex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
|
||||
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "speedx")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
||||
}
|
||||
}
|
||||
else if (strcmp(element->Attribute("name"), "sizex")==0)
|
||||
{
|
||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
|
||||
mParticleEmitters[mEmitterCount]->mSizeMax= value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0;i<FIELD_COUNT;i++)
|
||||
{
|
||||
if (strcmp(element->Attribute("name"), lifeValues[i])==0)
|
||||
{
|
||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||
{
|
||||
element = key->ToElement();
|
||||
|
||||
if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
|
||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||
{
|
||||
if (i==FIELD_ROTATION)
|
||||
value *= DEG2RAD;
|
||||
|
||||
mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
mEmitterCount++;
|
||||
}
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::SetParticleSystem(JParticleSystem* particleSys)
|
||||
{
|
||||
mParticleSystem = particleSys;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::SetPosition(float x, float y)
|
||||
{
|
||||
mX = x;
|
||||
mY = y;
|
||||
}
|
||||
|
||||
|
||||
JParticleSystem* JParticleEffect::GetParticleSystem()
|
||||
{
|
||||
return mParticleSystem;
|
||||
}
|
||||
|
||||
|
||||
float JParticleEffect::GetX()
|
||||
{
|
||||
return mX;
|
||||
}
|
||||
|
||||
|
||||
float JParticleEffect::GetY()
|
||||
{
|
||||
return mY;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Update(float dt)
|
||||
{
|
||||
// mTimer += dt;
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Update(dt);
|
||||
}
|
||||
|
||||
void JParticleEffect::Render()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Render();
|
||||
}
|
||||
|
||||
bool JParticleEffect::Done()
|
||||
{
|
||||
bool done = true;
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
if (!mParticleEmitters[i]->Done())
|
||||
done = false;
|
||||
|
||||
return (done);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Start()
|
||||
{
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->Start();
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::Stop()
|
||||
{
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
mParticleEmitters[i]->SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEffect::MoveTo(float x, float y)
|
||||
{
|
||||
float dx = x - mX;
|
||||
float dy = y - mY;
|
||||
|
||||
mX = x;
|
||||
mY = y;
|
||||
|
||||
for (int i=0;i<mEmitterCount;i++)
|
||||
{
|
||||
mParticleEmitters[i]->MoveAllParticles(dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
+323
-323
@@ -1,323 +1,323 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
#include "../include/JParticleEmitter.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
JParticleEmitter::JParticleEmitter(JParticleEffect* parent)
|
||||
{
|
||||
mParent = parent;
|
||||
mType = TYPE_POINT;
|
||||
mSrcBlending = BLEND_SRC_ALPHA;
|
||||
mDestBlending = BLEND_ONE;
|
||||
|
||||
mQuad = NULL;
|
||||
|
||||
mQuadIndex = 0;
|
||||
mWidth = 8;
|
||||
mHeight = 8;
|
||||
|
||||
mEmitTimer = 0.0f;
|
||||
mActive = false;
|
||||
|
||||
mMaxParticleCount = MAX_PARTICLE_COUNT;
|
||||
|
||||
mParticles.clear();
|
||||
mParticles.reserve(INIT_PARTICLE_COUNT);
|
||||
}
|
||||
|
||||
JParticleEmitter::~JParticleEmitter()
|
||||
{
|
||||
|
||||
while (mParticles.size()>0)
|
||||
{
|
||||
JParticle* par = mParticles.back();
|
||||
mParticles.pop_back();
|
||||
delete par;
|
||||
}
|
||||
}
|
||||
|
||||
JParticle* JParticleEmitter::GetIdleParticle()
|
||||
{
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (!mParticles[i]->mActive)
|
||||
return mParticles[i];
|
||||
}
|
||||
|
||||
if (size < mMaxParticleCount)
|
||||
{
|
||||
|
||||
JParticle*par = new JParticle();
|
||||
if (par != NULL)
|
||||
{
|
||||
mParticles.push_back(par);
|
||||
return par;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void JParticleEmitter::Start()
|
||||
{
|
||||
mActive = true;
|
||||
mActiveParticleCount = 0;
|
||||
mRepeatCounter = mRepeatTimes;
|
||||
|
||||
ReStart();
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::ReStart()
|
||||
{
|
||||
mQuantity.Init();
|
||||
mEmitTimer = 0.0f;
|
||||
|
||||
// if (mQuad == NULL)
|
||||
// {
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
// mQuad = particleSys->GetParticleQuad(mQuadIndex);
|
||||
// }
|
||||
|
||||
int count = (int) mQuantity.mCurr;
|
||||
if (count > 0)
|
||||
EmitParticles(count);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetQuad(JQuad *quad)
|
||||
{
|
||||
mQuad = quad;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JParticleEmitter::Update(float dt)
|
||||
{
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
|
||||
mActiveParticleCount = 0;
|
||||
|
||||
if (!mParticles.empty())
|
||||
{
|
||||
int count = 0;
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
count++;
|
||||
mParticles[i]->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
mActiveParticleCount = count;
|
||||
}
|
||||
|
||||
if (!mActive) return; // don't generate more
|
||||
|
||||
mEmitTimer += dt;
|
||||
if (mEmitTimer > mLife)
|
||||
{
|
||||
mEmitTimer = 0.0f;
|
||||
|
||||
if (mEmitterMode == MODE_ONCE)
|
||||
{
|
||||
mActive = false;
|
||||
}
|
||||
else if (mEmitterMode == MODE_REPEAT)
|
||||
{
|
||||
ReStart();
|
||||
return;
|
||||
}
|
||||
else if (mEmitterMode == MODE_NTIMES)
|
||||
{
|
||||
mRepeatCounter--;
|
||||
if (mRepeatCounter > 0)
|
||||
{
|
||||
ReStart();
|
||||
return;
|
||||
}
|
||||
else
|
||||
mActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mActive) return; // don't generate more
|
||||
|
||||
// more particles...
|
||||
int count = 0;
|
||||
|
||||
if (mQuantity.mCurr != 0.0f)
|
||||
{
|
||||
|
||||
float timeForOneParticle = 1.0f/mQuantity.mCurr;
|
||||
|
||||
float potentialParticles = (float) ((int)(mEmitTimer/timeForOneParticle));
|
||||
if (potentialParticles >= 1.0f)
|
||||
mEmitTimer -= (potentialParticles*timeForOneParticle);
|
||||
|
||||
count = (int)potentialParticles;
|
||||
}
|
||||
|
||||
//int count = (int)(mQuantity.mCurr * dt); // number of particles for this dt
|
||||
|
||||
mQuantity.Update(dt);
|
||||
|
||||
EmitParticles(count);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::EmitParticles(int count)
|
||||
{
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
|
||||
JParticleData *dataPtr;
|
||||
JParticle* particle;
|
||||
|
||||
float x, y;
|
||||
|
||||
float xOrigin = mParent->GetX();
|
||||
float yOrigin = mParent->GetY();
|
||||
|
||||
for (int i=0;i<count;i++)
|
||||
{
|
||||
particle = GetIdleParticle();
|
||||
if (particle != NULL)
|
||||
{
|
||||
particle->SetQuad(mQuad);
|
||||
|
||||
dataPtr = particle->GetDataPtr();
|
||||
memcpy(dataPtr, mData, sizeof(JParticleData)*FIELD_COUNT);
|
||||
|
||||
float angle = 0.0f;
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case TYPE_POINT:
|
||||
//particle->SetPosition(mParent->GetX(),mParent->GetY());
|
||||
particle->InitPosition(xOrigin, yOrigin, 0, 0);
|
||||
break;
|
||||
case TYPE_AREA:
|
||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY()+y);
|
||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||
break;
|
||||
case TYPE_HORIZONTAL:
|
||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY());
|
||||
particle->InitPosition(xOrigin, yOrigin, x, 0);
|
||||
break;
|
||||
case TYPE_VERTICAL:
|
||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||
//particle->SetPosition(mParent->GetX(),mParent->GetY()+y);
|
||||
particle->InitPosition(xOrigin, yOrigin, 0, y);
|
||||
break;
|
||||
case TYPE_CIRCLE:
|
||||
angle = M_PI* 2 * (rand()%1001)/1000.0f;
|
||||
x = cosf(angle)*mWidth;
|
||||
y = sinf(angle)*mHeight;
|
||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//particle->mSpeed
|
||||
float speed = mSpeedBase + (mSpeedMax-mSpeedBase) * (rand()%1001)/1000.0f;
|
||||
|
||||
if (mType != TYPE_CIRCLE)
|
||||
angle = mAngleBase + (mAngleMax-mAngleBase) * (rand()%1001)/1000.0f;
|
||||
//float x = cosf(angle);
|
||||
//float y = sinf(angle);
|
||||
// speed itself is not changing
|
||||
particle->SetVelocity(cosf(angle)*speed, sinf(angle)*speed);
|
||||
|
||||
particle->SetSize(mSizeBase + (mSizeMax-mSizeBase) * (rand()%1001)/1000.0f);
|
||||
|
||||
float life = mLifeBase + (mLifeMax-mLifeBase) * (rand()%1001)/1000.0f;
|
||||
particle->Init(life);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
renderer->SetTexBlend(mSrcBlending, mDestBlending);
|
||||
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
mParticles[i]->Render();
|
||||
}
|
||||
}
|
||||
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetBlending(int srcBlend, int destBlend)
|
||||
{
|
||||
mSrcBlending = srcBlend;
|
||||
mDestBlending = destBlend;
|
||||
}
|
||||
|
||||
|
||||
bool JParticleEmitter::Done()
|
||||
{
|
||||
return !mActive && mActiveParticleCount==0;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetActive(bool flag)
|
||||
{
|
||||
mActive = flag;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::MoveAllParticles(float x, float y)
|
||||
{
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
mParticles[i]->Move(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void JParticleEmitter::SetMaxParticleCount(int count)
|
||||
{
|
||||
mMaxParticleCount = count;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
#include "../include/JParticleEmitter.h"
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
JParticleEmitter::JParticleEmitter(JParticleEffect* parent)
|
||||
{
|
||||
mParent = parent;
|
||||
mType = TYPE_POINT;
|
||||
mSrcBlending = BLEND_SRC_ALPHA;
|
||||
mDestBlending = BLEND_ONE;
|
||||
|
||||
mQuad = NULL;
|
||||
|
||||
mQuadIndex = 0;
|
||||
mWidth = 8;
|
||||
mHeight = 8;
|
||||
|
||||
mEmitTimer = 0.0f;
|
||||
mActive = false;
|
||||
|
||||
mMaxParticleCount = MAX_PARTICLE_COUNT;
|
||||
|
||||
mParticles.clear();
|
||||
mParticles.reserve(INIT_PARTICLE_COUNT);
|
||||
}
|
||||
|
||||
JParticleEmitter::~JParticleEmitter()
|
||||
{
|
||||
|
||||
while (mParticles.size()>0)
|
||||
{
|
||||
JParticle* par = mParticles.back();
|
||||
mParticles.pop_back();
|
||||
delete par;
|
||||
}
|
||||
}
|
||||
|
||||
JParticle* JParticleEmitter::GetIdleParticle()
|
||||
{
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (!mParticles[i]->mActive)
|
||||
return mParticles[i];
|
||||
}
|
||||
|
||||
if (size < mMaxParticleCount)
|
||||
{
|
||||
|
||||
JParticle*par = new JParticle();
|
||||
if (par != NULL)
|
||||
{
|
||||
mParticles.push_back(par);
|
||||
return par;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void JParticleEmitter::Start()
|
||||
{
|
||||
mActive = true;
|
||||
mActiveParticleCount = 0;
|
||||
mRepeatCounter = mRepeatTimes;
|
||||
|
||||
ReStart();
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::ReStart()
|
||||
{
|
||||
mQuantity.Init();
|
||||
mEmitTimer = 0.0f;
|
||||
|
||||
// if (mQuad == NULL)
|
||||
// {
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
// mQuad = particleSys->GetParticleQuad(mQuadIndex);
|
||||
// }
|
||||
|
||||
int count = (int) mQuantity.mCurr;
|
||||
if (count > 0)
|
||||
EmitParticles(count);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetQuad(JQuad *quad)
|
||||
{
|
||||
mQuad = quad;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JParticleEmitter::Update(float dt)
|
||||
{
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
|
||||
mActiveParticleCount = 0;
|
||||
|
||||
if (!mParticles.empty())
|
||||
{
|
||||
int count = 0;
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
count++;
|
||||
mParticles[i]->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
mActiveParticleCount = count;
|
||||
}
|
||||
|
||||
if (!mActive) return; // don't generate more
|
||||
|
||||
mEmitTimer += dt;
|
||||
if (mEmitTimer > mLife)
|
||||
{
|
||||
mEmitTimer = 0.0f;
|
||||
|
||||
if (mEmitterMode == MODE_ONCE)
|
||||
{
|
||||
mActive = false;
|
||||
}
|
||||
else if (mEmitterMode == MODE_REPEAT)
|
||||
{
|
||||
ReStart();
|
||||
return;
|
||||
}
|
||||
else if (mEmitterMode == MODE_NTIMES)
|
||||
{
|
||||
mRepeatCounter--;
|
||||
if (mRepeatCounter > 0)
|
||||
{
|
||||
ReStart();
|
||||
return;
|
||||
}
|
||||
else
|
||||
mActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mActive) return; // don't generate more
|
||||
|
||||
// more particles...
|
||||
int count = 0;
|
||||
|
||||
if (mQuantity.mCurr != 0.0f)
|
||||
{
|
||||
|
||||
float timeForOneParticle = 1.0f/mQuantity.mCurr;
|
||||
|
||||
float potentialParticles = (float) ((int)(mEmitTimer/timeForOneParticle));
|
||||
if (potentialParticles >= 1.0f)
|
||||
mEmitTimer -= (potentialParticles*timeForOneParticle);
|
||||
|
||||
count = (int)potentialParticles;
|
||||
}
|
||||
|
||||
//int count = (int)(mQuantity.mCurr * dt); // number of particles for this dt
|
||||
|
||||
mQuantity.Update(dt);
|
||||
|
||||
EmitParticles(count);
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::EmitParticles(int count)
|
||||
{
|
||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||
|
||||
JParticleData *dataPtr;
|
||||
JParticle* particle;
|
||||
|
||||
float x, y;
|
||||
|
||||
float xOrigin = mParent->GetX();
|
||||
float yOrigin = mParent->GetY();
|
||||
|
||||
for (int i=0;i<count;i++)
|
||||
{
|
||||
particle = GetIdleParticle();
|
||||
if (particle != NULL)
|
||||
{
|
||||
particle->SetQuad(mQuad);
|
||||
|
||||
dataPtr = particle->GetDataPtr();
|
||||
memcpy(dataPtr, mData, sizeof(JParticleData)*FIELD_COUNT);
|
||||
|
||||
float angle = 0.0f;
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case TYPE_POINT:
|
||||
//particle->SetPosition(mParent->GetX(),mParent->GetY());
|
||||
particle->InitPosition(xOrigin, yOrigin, 0, 0);
|
||||
break;
|
||||
case TYPE_AREA:
|
||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY()+y);
|
||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||
break;
|
||||
case TYPE_HORIZONTAL:
|
||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY());
|
||||
particle->InitPosition(xOrigin, yOrigin, x, 0);
|
||||
break;
|
||||
case TYPE_VERTICAL:
|
||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||
//particle->SetPosition(mParent->GetX(),mParent->GetY()+y);
|
||||
particle->InitPosition(xOrigin, yOrigin, 0, y);
|
||||
break;
|
||||
case TYPE_CIRCLE:
|
||||
angle = M_PI* 2 * (rand()%1001)/1000.0f;
|
||||
x = cosf(angle)*mWidth;
|
||||
y = sinf(angle)*mHeight;
|
||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//particle->mSpeed
|
||||
float speed = mSpeedBase + (mSpeedMax-mSpeedBase) * (rand()%1001)/1000.0f;
|
||||
|
||||
if (mType != TYPE_CIRCLE)
|
||||
angle = mAngleBase + (mAngleMax-mAngleBase) * (rand()%1001)/1000.0f;
|
||||
//float x = cosf(angle);
|
||||
//float y = sinf(angle);
|
||||
// speed itself is not changing
|
||||
particle->SetVelocity(cosf(angle)*speed, sinf(angle)*speed);
|
||||
|
||||
particle->SetSize(mSizeBase + (mSizeMax-mSizeBase) * (rand()%1001)/1000.0f);
|
||||
|
||||
float life = mLifeBase + (mLifeMax-mLifeBase) * (rand()%1001)/1000.0f;
|
||||
particle->Init(life);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
renderer->SetTexBlend(mSrcBlending, mDestBlending);
|
||||
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
mParticles[i]->Render();
|
||||
}
|
||||
}
|
||||
|
||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetBlending(int srcBlend, int destBlend)
|
||||
{
|
||||
mSrcBlending = srcBlend;
|
||||
mDestBlending = destBlend;
|
||||
}
|
||||
|
||||
|
||||
bool JParticleEmitter::Done()
|
||||
{
|
||||
return !mActive && mActiveParticleCount==0;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::SetActive(bool flag)
|
||||
{
|
||||
mActive = flag;
|
||||
}
|
||||
|
||||
|
||||
void JParticleEmitter::MoveAllParticles(float x, float y)
|
||||
{
|
||||
int size = mParticles.size();
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if (mParticles[i]->mActive)
|
||||
{
|
||||
mParticles[i]->Move(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void JParticleEmitter::SetMaxParticleCount(int count)
|
||||
{
|
||||
mMaxParticleCount = count;
|
||||
}
|
||||
|
||||
|
||||
+124
-124
@@ -1,124 +1,124 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
JParticleSystem::JParticleSystem()
|
||||
{
|
||||
|
||||
mActive = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
JParticleSystem::~JParticleSystem()
|
||||
{
|
||||
mEffects.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::ClearAll()
|
||||
{
|
||||
mEffects.clear();
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::Update(float dt)
|
||||
{
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Update(dt);
|
||||
if (effect->Done())
|
||||
{
|
||||
mEffects.erase(curr++);
|
||||
}
|
||||
else
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::Render()
|
||||
{
|
||||
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Render();
|
||||
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void JParticleSystem::StartEffect(JParticleEffect* effect)
|
||||
{
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
if (effect == *curr && effect->GetParticleSystem() == this)
|
||||
{
|
||||
effect->Start();
|
||||
return;
|
||||
}
|
||||
curr++;
|
||||
}
|
||||
mEffects.push_back(effect);
|
||||
effect->SetParticleSystem(this);
|
||||
effect->Start();
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::StopAllEffects()
|
||||
{
|
||||
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Stop();
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool JParticleSystem::IsActive() { return mActive; }
|
||||
|
||||
void JParticleSystem::SetActive(bool flag) { mActive = flag; }
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JParticleSystem.h"
|
||||
#include "../include/JParticleEffect.h"
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
JParticleSystem::JParticleSystem()
|
||||
{
|
||||
|
||||
mActive = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
JParticleSystem::~JParticleSystem()
|
||||
{
|
||||
mEffects.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::ClearAll()
|
||||
{
|
||||
mEffects.clear();
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::Update(float dt)
|
||||
{
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Update(dt);
|
||||
if (effect->Done())
|
||||
{
|
||||
mEffects.erase(curr++);
|
||||
}
|
||||
else
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::Render()
|
||||
{
|
||||
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Render();
|
||||
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void JParticleSystem::StartEffect(JParticleEffect* effect)
|
||||
{
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
if (effect == *curr && effect->GetParticleSystem() == this)
|
||||
{
|
||||
effect->Start();
|
||||
return;
|
||||
}
|
||||
curr++;
|
||||
}
|
||||
mEffects.push_back(effect);
|
||||
effect->SetParticleSystem(this);
|
||||
effect->Start();
|
||||
}
|
||||
|
||||
|
||||
void JParticleSystem::StopAllEffects()
|
||||
{
|
||||
|
||||
if (!mEffects.empty())
|
||||
{
|
||||
JParticleEffect* effect;
|
||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||
while (curr != mEffects.end())
|
||||
{
|
||||
effect = *curr;
|
||||
effect->Stop();
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool JParticleSystem::IsActive() { return mActive; }
|
||||
|
||||
void JParticleSystem::SetActive(bool flag) { mActive = flag; }
|
||||
|
||||
|
||||
+203
-203
@@ -1,203 +1,203 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JSpline.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#define SMALL_NUMBER 0.0001f
|
||||
|
||||
|
||||
JSpline::JSpline()
|
||||
{
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.reserve(32);
|
||||
mPixels.reserve(32);
|
||||
}
|
||||
|
||||
|
||||
JSpline::~JSpline()
|
||||
{
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.clear();
|
||||
mPixels.clear();
|
||||
}
|
||||
|
||||
|
||||
bool JSpline::Load(const char *filename, float xscale, float yscale)
|
||||
{
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
|
||||
if (fileSystem == NULL) return false;
|
||||
if (!fileSystem->OpenFile(filename)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.clear();
|
||||
mPixels.clear();
|
||||
|
||||
|
||||
TiXmlNode* node = 0;
|
||||
//TiXmlElement* todoElement = 0;
|
||||
TiXmlElement* element;
|
||||
|
||||
node = doc.RootElement();
|
||||
|
||||
float xx, yy;
|
||||
|
||||
for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
|
||||
{
|
||||
xx = 0.0f;
|
||||
yy = 0.0f;
|
||||
element->QueryFloatAttribute("x", &xx);
|
||||
element->QueryFloatAttribute("y", &yy);
|
||||
|
||||
Point pt(xx*xscale, yy*yscale);
|
||||
AddControlPoint(pt);
|
||||
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JSpline::PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3)
|
||||
{
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
out.x = 0.5f * (( 2.0f * p1.x ) +
|
||||
( -p0.x + p2.x ) * t +
|
||||
( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
|
||||
( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
|
||||
|
||||
out.y = 0.5f * ( ( 2.0f * p1.y ) +
|
||||
( -p0.y + p2.y ) * t +
|
||||
( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
|
||||
( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JSpline::GeneratePixels()
|
||||
{
|
||||
float x, y;
|
||||
|
||||
float inc = SMALL_NUMBER;
|
||||
|
||||
mPixels.clear();
|
||||
|
||||
x = mMidPoints[1].x;
|
||||
y = mMidPoints[1].y;
|
||||
|
||||
Point newPt(x, y);
|
||||
Point extraPt;
|
||||
|
||||
mPixels.push_back(newPt);
|
||||
|
||||
for (int n=0; n < (int)mMidPoints.size()-3; n++)
|
||||
{
|
||||
float t = inc;
|
||||
while (t <= 1.0f)
|
||||
{
|
||||
PointOnCurve(newPt, t, mMidPoints[n], mMidPoints[n+1], mMidPoints[n+2], mMidPoints[n+3]);
|
||||
|
||||
float dx = newPt.x-x;
|
||||
float dy = newPt.y-y;
|
||||
|
||||
float dist = sqrtf(dx*dx + dy*dy);
|
||||
if (dist >= MID_POINT_THRESHOLD)
|
||||
{
|
||||
//
|
||||
//extraPt.x = (newPt.x+x)/2;
|
||||
//extraPt.y = (newPt.y+y)/2;
|
||||
//mPixels.push_back(extraPt);
|
||||
//
|
||||
mPixels.push_back(newPt);
|
||||
x = newPt.x;
|
||||
y = newPt.y;
|
||||
}
|
||||
|
||||
t += inc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mCount = mPixels.size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JSpline::AddControlPoint(const Point &pt)
|
||||
{
|
||||
mMidPoints.push_back(pt);
|
||||
}
|
||||
|
||||
|
||||
void JSpline::GetControlPoint(Point &point, int index)
|
||||
{
|
||||
if (index < (int)mMidPoints.size())
|
||||
{
|
||||
point.x = mMidPoints[index].x;
|
||||
point.y = mMidPoints[index].y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JSpline::GetPixel(Point &point, int index)
|
||||
{
|
||||
if (index < (int)mPixels.size())
|
||||
{
|
||||
point.x = mPixels[index].x;
|
||||
point.y = mPixels[index].y;
|
||||
}
|
||||
}
|
||||
|
||||
int JSpline::GetPixelCount()
|
||||
{
|
||||
return mCount;
|
||||
}
|
||||
|
||||
|
||||
void JSpline::Render(float x, float y, PIXEL_TYPE color, PIXEL_TYPE controlColor)
|
||||
{
|
||||
if (mCount > 0)
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
// renderer->SetLineWidth(1.2f);
|
||||
|
||||
int size = mPixels.size();
|
||||
|
||||
for (int i=0;i<size-1;i++)
|
||||
renderer->DrawLine(x+mPixels[i].x, y+mPixels[i].y, x+mPixels[i+1].x, y+mPixels[i+1].y, color);
|
||||
|
||||
size = mMidPoints.size();
|
||||
for (int i=0; i < size; i++)
|
||||
renderer->FillRect(mMidPoints[i].x-3, mMidPoints[i].y-3, 6, 6, controlColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../include/JFileSystem.h"
|
||||
#include "../include/JSpline.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#define SMALL_NUMBER 0.0001f
|
||||
|
||||
|
||||
JSpline::JSpline()
|
||||
{
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.reserve(32);
|
||||
mPixels.reserve(32);
|
||||
}
|
||||
|
||||
|
||||
JSpline::~JSpline()
|
||||
{
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.clear();
|
||||
mPixels.clear();
|
||||
}
|
||||
|
||||
|
||||
bool JSpline::Load(const char *filename, float xscale, float yscale)
|
||||
{
|
||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||
|
||||
if (fileSystem == NULL) return false;
|
||||
if (!fileSystem->OpenFile(filename)) return false;
|
||||
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *xmlBuffer = new char[size];
|
||||
fileSystem->ReadFile(xmlBuffer, size);
|
||||
|
||||
TiXmlDocument doc;
|
||||
doc.Parse(xmlBuffer);
|
||||
|
||||
mCount = 0;
|
||||
|
||||
mMidPoints.clear();
|
||||
mPixels.clear();
|
||||
|
||||
|
||||
TiXmlNode* node = 0;
|
||||
//TiXmlElement* todoElement = 0;
|
||||
TiXmlElement* element;
|
||||
|
||||
node = doc.RootElement();
|
||||
|
||||
float xx, yy;
|
||||
|
||||
for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
|
||||
{
|
||||
xx = 0.0f;
|
||||
yy = 0.0f;
|
||||
element->QueryFloatAttribute("x", &xx);
|
||||
element->QueryFloatAttribute("y", &yy);
|
||||
|
||||
Point pt(xx*xscale, yy*yscale);
|
||||
AddControlPoint(pt);
|
||||
|
||||
}
|
||||
|
||||
fileSystem->CloseFile();
|
||||
delete[] xmlBuffer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JSpline::PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3)
|
||||
{
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
out.x = 0.5f * (( 2.0f * p1.x ) +
|
||||
( -p0.x + p2.x ) * t +
|
||||
( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
|
||||
( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
|
||||
|
||||
out.y = 0.5f * ( ( 2.0f * p1.y ) +
|
||||
( -p0.y + p2.y ) * t +
|
||||
( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
|
||||
( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JSpline::GeneratePixels()
|
||||
{
|
||||
float x, y;
|
||||
|
||||
float inc = SMALL_NUMBER;
|
||||
|
||||
mPixels.clear();
|
||||
|
||||
x = mMidPoints[1].x;
|
||||
y = mMidPoints[1].y;
|
||||
|
||||
Point newPt(x, y);
|
||||
Point extraPt;
|
||||
|
||||
mPixels.push_back(newPt);
|
||||
|
||||
for (int n=0; n < (int)mMidPoints.size()-3; n++)
|
||||
{
|
||||
float t = inc;
|
||||
while (t <= 1.0f)
|
||||
{
|
||||
PointOnCurve(newPt, t, mMidPoints[n], mMidPoints[n+1], mMidPoints[n+2], mMidPoints[n+3]);
|
||||
|
||||
float dx = newPt.x-x;
|
||||
float dy = newPt.y-y;
|
||||
|
||||
float dist = sqrtf(dx*dx + dy*dy);
|
||||
if (dist >= MID_POINT_THRESHOLD)
|
||||
{
|
||||
//
|
||||
//extraPt.x = (newPt.x+x)/2;
|
||||
//extraPt.y = (newPt.y+y)/2;
|
||||
//mPixels.push_back(extraPt);
|
||||
//
|
||||
mPixels.push_back(newPt);
|
||||
x = newPt.x;
|
||||
y = newPt.y;
|
||||
}
|
||||
|
||||
t += inc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mCount = mPixels.size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JSpline::AddControlPoint(const Point &pt)
|
||||
{
|
||||
mMidPoints.push_back(pt);
|
||||
}
|
||||
|
||||
|
||||
void JSpline::GetControlPoint(Point &point, int index)
|
||||
{
|
||||
if (index < (int)mMidPoints.size())
|
||||
{
|
||||
point.x = mMidPoints[index].x;
|
||||
point.y = mMidPoints[index].y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JSpline::GetPixel(Point &point, int index)
|
||||
{
|
||||
if (index < (int)mPixels.size())
|
||||
{
|
||||
point.x = mPixels[index].x;
|
||||
point.y = mPixels[index].y;
|
||||
}
|
||||
}
|
||||
|
||||
int JSpline::GetPixelCount()
|
||||
{
|
||||
return mCount;
|
||||
}
|
||||
|
||||
|
||||
void JSpline::Render(float x, float y, PIXEL_TYPE color, PIXEL_TYPE controlColor)
|
||||
{
|
||||
if (mCount > 0)
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
// renderer->SetLineWidth(1.2f);
|
||||
|
||||
int size = mPixels.size();
|
||||
|
||||
for (int i=0;i<size-1;i++)
|
||||
renderer->DrawLine(x+mPixels[i].x, y+mPixels[i].y, x+mPixels[i+1].x, y+mPixels[i+1].y, color);
|
||||
|
||||
size = mMidPoints.size();
|
||||
for (int i=0; i < size; i++)
|
||||
renderer->FillRect(mMidPoints[i].x-3, mMidPoints[i].y-3, 6, 6, controlColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+511
-511
File diff suppressed because it is too large
Load Diff
+649
-649
File diff suppressed because it is too large
Load Diff
+81
-81
@@ -1,81 +1,81 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../include/Vector2D.h"
|
||||
|
||||
|
||||
float Vector2D::Length(void) const
|
||||
{
|
||||
return sqrtf(x*x + y*y);
|
||||
}
|
||||
|
||||
float Vector2D::Normalize(void)
|
||||
{
|
||||
float fLength = Length();
|
||||
|
||||
if (fLength == 0.0f)
|
||||
return 0.0f;
|
||||
|
||||
(*this) *= (1.0f / fLength);
|
||||
|
||||
return fLength;
|
||||
}
|
||||
|
||||
|
||||
Vector2D Vector2D::Direction(void) const
|
||||
{
|
||||
Vector2D temp(*this);
|
||||
|
||||
temp.Normalize();
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
float Vector2D::Angle(const Vector2D& xE)
|
||||
{
|
||||
float dot = (*this) * xE;
|
||||
float cross = (*this) ^ xE;
|
||||
|
||||
// angle between segments
|
||||
float angle = atan2f(cross, dot);
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
Vector2D& Vector2D::Rotate(float angle)
|
||||
{
|
||||
float tx = x;
|
||||
x = x * cosf(angle) - y * sinf(angle);
|
||||
y = tx * sinf(angle) + y * cosf(angle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2D& Vector2D::Rotate(const Vector2D& xCentre, float fAngle)
|
||||
{
|
||||
Vector2D D = *this - xCentre;
|
||||
D.Rotate(fAngle);
|
||||
|
||||
*this = xCentre + D;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Vector2D::Clamp(const Vector2D& min, const Vector2D& max)
|
||||
{
|
||||
x = (x < min.x)? min.x : (x > max.x)? max.x : x;
|
||||
x = (y < min.y)? min.y : (y > max.y)? max.y : y;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "../include/Vector2D.h"
|
||||
|
||||
|
||||
float Vector2D::Length(void) const
|
||||
{
|
||||
return sqrtf(x*x + y*y);
|
||||
}
|
||||
|
||||
float Vector2D::Normalize(void)
|
||||
{
|
||||
float fLength = Length();
|
||||
|
||||
if (fLength == 0.0f)
|
||||
return 0.0f;
|
||||
|
||||
(*this) *= (1.0f / fLength);
|
||||
|
||||
return fLength;
|
||||
}
|
||||
|
||||
|
||||
Vector2D Vector2D::Direction(void) const
|
||||
{
|
||||
Vector2D temp(*this);
|
||||
|
||||
temp.Normalize();
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
float Vector2D::Angle(const Vector2D& xE)
|
||||
{
|
||||
float dot = (*this) * xE;
|
||||
float cross = (*this) ^ xE;
|
||||
|
||||
// angle between segments
|
||||
float angle = atan2f(cross, dot);
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
Vector2D& Vector2D::Rotate(float angle)
|
||||
{
|
||||
float tx = x;
|
||||
x = x * cosf(angle) - y * sinf(angle);
|
||||
y = tx * sinf(angle) + y * cosf(angle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2D& Vector2D::Rotate(const Vector2D& xCentre, float fAngle)
|
||||
{
|
||||
Vector2D D = *this - xCentre;
|
||||
D.Rotate(fAngle);
|
||||
|
||||
*this = xCentre + D;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Vector2D::Clamp(const Vector2D& min, const Vector2D& max)
|
||||
{
|
||||
x = (x < min.x)? min.x : (x > max.x)? max.x : x;
|
||||
x = (y < min.y)? min.y : (y > max.y)? max.y : y;
|
||||
}
|
||||
|
||||
|
||||
+89
-89
@@ -1,89 +1,89 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeColor*** helper classes implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgecolor.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef min
|
||||
#define min(x, y) ((x<y)?x:y)
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(x, y) ((x>y)?x:y)
|
||||
#endif
|
||||
|
||||
void hgeColorHSV::SetHWColor(DWORD col)
|
||||
{
|
||||
float r, g, b;
|
||||
float minv, maxv, delta;
|
||||
float del_R, del_G, del_B;
|
||||
|
||||
a = (col>>24) / 255.0f;
|
||||
r = ((col>>16) & 0xFF) / 255.0f;
|
||||
g = ((col>>8) & 0xFF) / 255.0f;
|
||||
b = (col & 0xFF) / 255.0f;
|
||||
|
||||
minv = min(min(r, g), b);
|
||||
maxv = max(max(r, g), b);
|
||||
delta = maxv - minv;
|
||||
|
||||
v = maxv;
|
||||
|
||||
if (delta == 0)
|
||||
{
|
||||
h = 0;
|
||||
s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = delta / maxv;
|
||||
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
|
||||
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
|
||||
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
|
||||
|
||||
if (r == maxv) {h = del_B - del_G;}
|
||||
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
|
||||
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
|
||||
|
||||
if (h < 0) h += 1;
|
||||
if (h > 1) h -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD hgeColorHSV::GetHWColor() const
|
||||
{
|
||||
float r, g, b;
|
||||
float xh, i, p1, p2, p3;
|
||||
|
||||
if (s == 0)
|
||||
{
|
||||
r = v;
|
||||
g = v;
|
||||
b = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
xh = h * 6;
|
||||
if(xh == 6) xh=0;
|
||||
i = floorf(xh);
|
||||
p1 = v * (1 - s);
|
||||
p2 = v * (1 - s * (xh - i));
|
||||
p3 = v * (1 - s * (1 - (xh - i)));
|
||||
|
||||
if (i == 0) {r = v; g = p3; b = p1;}
|
||||
else if (i == 1) {r = p2; g = v; b = p1;}
|
||||
else if (i == 2) {r = p1; g = v; b = p3;}
|
||||
else if (i == 3) {r = p1; g = p2; b = v; }
|
||||
else if (i == 4) {r = p3; g = p1; b = v; }
|
||||
else {r = v; g = p1; b = p2;}
|
||||
}
|
||||
|
||||
return (ARGB((int)(a*255.0f), (int)(r*255.0f), (int)(g*255.0f), (int)(b*255.0f)));
|
||||
}
|
||||
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeColor*** helper classes implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgecolor.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef min
|
||||
#define min(x, y) ((x<y)?x:y)
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(x, y) ((x>y)?x:y)
|
||||
#endif
|
||||
|
||||
void hgeColorHSV::SetHWColor(DWORD col)
|
||||
{
|
||||
float r, g, b;
|
||||
float minv, maxv, delta;
|
||||
float del_R, del_G, del_B;
|
||||
|
||||
a = (col>>24) / 255.0f;
|
||||
r = ((col>>16) & 0xFF) / 255.0f;
|
||||
g = ((col>>8) & 0xFF) / 255.0f;
|
||||
b = (col & 0xFF) / 255.0f;
|
||||
|
||||
minv = min(min(r, g), b);
|
||||
maxv = max(max(r, g), b);
|
||||
delta = maxv - minv;
|
||||
|
||||
v = maxv;
|
||||
|
||||
if (delta == 0)
|
||||
{
|
||||
h = 0;
|
||||
s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = delta / maxv;
|
||||
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
|
||||
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
|
||||
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
|
||||
|
||||
if (r == maxv) {h = del_B - del_G;}
|
||||
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
|
||||
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
|
||||
|
||||
if (h < 0) h += 1;
|
||||
if (h > 1) h -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD hgeColorHSV::GetHWColor() const
|
||||
{
|
||||
float r, g, b;
|
||||
float xh, i, p1, p2, p3;
|
||||
|
||||
if (s == 0)
|
||||
{
|
||||
r = v;
|
||||
g = v;
|
||||
b = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
xh = h * 6;
|
||||
if(xh == 6) xh=0;
|
||||
i = floorf(xh);
|
||||
p1 = v * (1 - s);
|
||||
p2 = v * (1 - s * (xh - i));
|
||||
p3 = v * (1 - s * (1 - (xh - i)));
|
||||
|
||||
if (i == 0) {r = v; g = p3; b = p1;}
|
||||
else if (i == 1) {r = p2; g = v; b = p1;}
|
||||
else if (i == 2) {r = p1; g = v; b = p3;}
|
||||
else if (i == 3) {r = p1; g = p2; b = v; }
|
||||
else if (i == 4) {r = p3; g = p1; b = v; }
|
||||
else {r = v; g = p1; b = p2;}
|
||||
}
|
||||
|
||||
return (ARGB((int)(a*255.0f), (int)(r*255.0f), (int)(g*255.0f), (int)(b*255.0f)));
|
||||
}
|
||||
|
||||
|
||||
+252
-252
@@ -1,252 +1,252 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeDistortionMesh helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgedistort.h"
|
||||
|
||||
|
||||
//HGE *hgeDistortionMesh::hge=0;
|
||||
|
||||
|
||||
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
|
||||
{
|
||||
int i;
|
||||
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
nRows=rows;
|
||||
nCols=cols;
|
||||
cellw=cellh=0;
|
||||
//quad.tex=0;
|
||||
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
|
||||
|
||||
quad = NULL;
|
||||
|
||||
disp_array=new Vertex[rows*cols];
|
||||
|
||||
for(i=0;i<rows*cols;i++)
|
||||
{
|
||||
disp_array[i].x=0.0f;
|
||||
disp_array[i].y=0.0f;
|
||||
disp_array[i].u=0.0f;
|
||||
disp_array[i].v=0.0f;
|
||||
|
||||
disp_array[i].z=0.5f;
|
||||
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
|
||||
{
|
||||
// hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
nRows=dm.nRows;
|
||||
nCols=dm.nCols;
|
||||
cellw=dm.cellw;
|
||||
cellh=dm.cellh;
|
||||
tx=dm.tx;
|
||||
ty=dm.ty;
|
||||
width=dm.width;
|
||||
height=dm.height;
|
||||
quad=dm.quad;
|
||||
|
||||
disp_array=new Vertex[nRows*nCols];
|
||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||
}
|
||||
|
||||
hgeDistortionMesh::~hgeDistortionMesh()
|
||||
{
|
||||
delete[] disp_array;
|
||||
SAFE_DELETE(quad);
|
||||
}
|
||||
|
||||
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
|
||||
{
|
||||
if(this!=&dm)
|
||||
{
|
||||
nRows=dm.nRows;
|
||||
nCols=dm.nCols;
|
||||
cellw=dm.cellw;
|
||||
cellh=dm.cellh;
|
||||
tx=dm.tx;
|
||||
ty=dm.ty;
|
||||
width=dm.width;
|
||||
height=dm.height;
|
||||
quad=dm.quad;
|
||||
|
||||
delete[] disp_array;
|
||||
disp_array=new Vertex[nRows*nCols];
|
||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetTexture(JTexture* tex)
|
||||
{
|
||||
if (quad)
|
||||
delete quad;
|
||||
|
||||
quad = new JQuad(tex, 0, 0, 16, 16);
|
||||
//quad.tex=tex;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
|
||||
{
|
||||
int i,j;
|
||||
float tw,th;
|
||||
|
||||
tx=x; ty=y; width=w; height=h;
|
||||
|
||||
if (quad->mTex)
|
||||
{
|
||||
tw=(float)quad->mTex->mTexWidth;
|
||||
th=(float)quad->mTex->mTexHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
tw = w;
|
||||
th = h;
|
||||
}
|
||||
|
||||
cellw=w/(nCols-1);
|
||||
cellh=h/(nRows-1);
|
||||
|
||||
for(j=0; j<nRows; j++)
|
||||
for(i=0; i<nCols; i++)
|
||||
{
|
||||
disp_array[j*nCols+i].u=(x+i*cellw);
|
||||
disp_array[j*nCols+i].v=(y+j*cellh);
|
||||
|
||||
disp_array[j*nCols+i].x=i*cellw;
|
||||
disp_array[j*nCols+i].y=j*cellh;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
|
||||
{
|
||||
// quad.blend=blend;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
|
||||
{
|
||||
int i,j;
|
||||
|
||||
for(j=0; j<nRows; j++)
|
||||
for(i=0; i<nCols; i++)
|
||||
{
|
||||
disp_array[j*nCols+i].x=i*cellw;
|
||||
disp_array[j*nCols+i].y=j*cellh;
|
||||
disp_array[j*nCols+i].color=col;
|
||||
disp_array[j*nCols+i].z=z;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::Render(float x, float y)
|
||||
{
|
||||
int i,j,idx;
|
||||
|
||||
VertexColor points[4];
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
for(j=0; j<nRows-1; j++)
|
||||
for(i=0; i<nCols-1; i++)
|
||||
{
|
||||
idx=j*nCols+i;
|
||||
|
||||
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
|
||||
|
||||
points[0].x = x+disp_array[idx+nCols].x;
|
||||
points[0].y = y+disp_array[idx+nCols].y;
|
||||
points[0].z = disp_array[idx+nCols].z;
|
||||
points[0].color = disp_array[idx+nCols].color;
|
||||
|
||||
points[1].x = x+disp_array[idx+nCols+1].x;
|
||||
points[1].y = y+disp_array[idx+nCols+1].y;
|
||||
points[1].z = disp_array[idx+nCols+1].z;
|
||||
points[1].color = disp_array[idx+nCols+1].color;
|
||||
|
||||
points[2].x = x+disp_array[idx+1].x;
|
||||
points[2].y = y+disp_array[idx+1].y;
|
||||
points[2].z = disp_array[idx+1].z;
|
||||
points[2].color = disp_array[idx+1].color;
|
||||
|
||||
points[3].x = x+disp_array[idx].x;
|
||||
points[3].y = y+disp_array[idx].y;
|
||||
points[3].z = disp_array[idx].z;
|
||||
points[3].color = disp_array[idx].color;
|
||||
|
||||
renderer->RenderQuad(quad, points);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetZ(int col, int row, float z)
|
||||
{
|
||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||
{
|
||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].color=color;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetDisplacement(int col, int row, float dx, float dy, int ref)
|
||||
{
|
||||
if(row<nRows && col<nCols)
|
||||
{
|
||||
switch(ref)
|
||||
{
|
||||
case HGEDISP_NODE: dx+=col*cellw; dy+=row*cellh; break;
|
||||
case HGEDISP_CENTER: dx+=cellw*(nCols-1)/2;dy+=cellh*(nRows-1)/2; break;
|
||||
case HGEDISP_TOPLEFT: break;
|
||||
}
|
||||
|
||||
disp_array[row*nCols+col].x=dx;
|
||||
disp_array[row*nCols+col].y=dy;
|
||||
}
|
||||
}
|
||||
|
||||
float hgeDistortionMesh::GetZ(int col, int row) const
|
||||
{
|
||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
|
||||
else return 0.0f;
|
||||
}
|
||||
|
||||
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
|
||||
{
|
||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
|
||||
{
|
||||
if(row<nRows && col<nCols)
|
||||
{
|
||||
switch(ref)
|
||||
{
|
||||
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
|
||||
*dy=disp_array[row*nCols+col].y-row*cellh;
|
||||
break;
|
||||
|
||||
case HGEDISP_CENTER: *dx=disp_array[row*nCols+col].x-cellw*(nCols-1)/2;
|
||||
*dy=disp_array[row*nCols+col].x-cellh*(nRows-1)/2;
|
||||
break;
|
||||
|
||||
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
|
||||
*dy=disp_array[row*nCols+col].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeDistortionMesh helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgedistort.h"
|
||||
|
||||
|
||||
//HGE *hgeDistortionMesh::hge=0;
|
||||
|
||||
|
||||
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
|
||||
{
|
||||
int i;
|
||||
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
nRows=rows;
|
||||
nCols=cols;
|
||||
cellw=cellh=0;
|
||||
//quad.tex=0;
|
||||
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
|
||||
|
||||
quad = NULL;
|
||||
|
||||
disp_array=new Vertex[rows*cols];
|
||||
|
||||
for(i=0;i<rows*cols;i++)
|
||||
{
|
||||
disp_array[i].x=0.0f;
|
||||
disp_array[i].y=0.0f;
|
||||
disp_array[i].u=0.0f;
|
||||
disp_array[i].v=0.0f;
|
||||
|
||||
disp_array[i].z=0.5f;
|
||||
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
|
||||
{
|
||||
// hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
nRows=dm.nRows;
|
||||
nCols=dm.nCols;
|
||||
cellw=dm.cellw;
|
||||
cellh=dm.cellh;
|
||||
tx=dm.tx;
|
||||
ty=dm.ty;
|
||||
width=dm.width;
|
||||
height=dm.height;
|
||||
quad=dm.quad;
|
||||
|
||||
disp_array=new Vertex[nRows*nCols];
|
||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||
}
|
||||
|
||||
hgeDistortionMesh::~hgeDistortionMesh()
|
||||
{
|
||||
delete[] disp_array;
|
||||
SAFE_DELETE(quad);
|
||||
}
|
||||
|
||||
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
|
||||
{
|
||||
if(this!=&dm)
|
||||
{
|
||||
nRows=dm.nRows;
|
||||
nCols=dm.nCols;
|
||||
cellw=dm.cellw;
|
||||
cellh=dm.cellh;
|
||||
tx=dm.tx;
|
||||
ty=dm.ty;
|
||||
width=dm.width;
|
||||
height=dm.height;
|
||||
quad=dm.quad;
|
||||
|
||||
delete[] disp_array;
|
||||
disp_array=new Vertex[nRows*nCols];
|
||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetTexture(JTexture* tex)
|
||||
{
|
||||
if (quad)
|
||||
delete quad;
|
||||
|
||||
quad = new JQuad(tex, 0, 0, 16, 16);
|
||||
//quad.tex=tex;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
|
||||
{
|
||||
int i,j;
|
||||
float tw,th;
|
||||
|
||||
tx=x; ty=y; width=w; height=h;
|
||||
|
||||
if (quad->mTex)
|
||||
{
|
||||
tw=(float)quad->mTex->mTexWidth;
|
||||
th=(float)quad->mTex->mTexHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
tw = w;
|
||||
th = h;
|
||||
}
|
||||
|
||||
cellw=w/(nCols-1);
|
||||
cellh=h/(nRows-1);
|
||||
|
||||
for(j=0; j<nRows; j++)
|
||||
for(i=0; i<nCols; i++)
|
||||
{
|
||||
disp_array[j*nCols+i].u=(x+i*cellw);
|
||||
disp_array[j*nCols+i].v=(y+j*cellh);
|
||||
|
||||
disp_array[j*nCols+i].x=i*cellw;
|
||||
disp_array[j*nCols+i].y=j*cellh;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
|
||||
{
|
||||
// quad.blend=blend;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
|
||||
{
|
||||
int i,j;
|
||||
|
||||
for(j=0; j<nRows; j++)
|
||||
for(i=0; i<nCols; i++)
|
||||
{
|
||||
disp_array[j*nCols+i].x=i*cellw;
|
||||
disp_array[j*nCols+i].y=j*cellh;
|
||||
disp_array[j*nCols+i].color=col;
|
||||
disp_array[j*nCols+i].z=z;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::Render(float x, float y)
|
||||
{
|
||||
int i,j,idx;
|
||||
|
||||
VertexColor points[4];
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
for(j=0; j<nRows-1; j++)
|
||||
for(i=0; i<nCols-1; i++)
|
||||
{
|
||||
idx=j*nCols+i;
|
||||
|
||||
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
|
||||
|
||||
points[0].x = x+disp_array[idx+nCols].x;
|
||||
points[0].y = y+disp_array[idx+nCols].y;
|
||||
points[0].z = disp_array[idx+nCols].z;
|
||||
points[0].color = disp_array[idx+nCols].color;
|
||||
|
||||
points[1].x = x+disp_array[idx+nCols+1].x;
|
||||
points[1].y = y+disp_array[idx+nCols+1].y;
|
||||
points[1].z = disp_array[idx+nCols+1].z;
|
||||
points[1].color = disp_array[idx+nCols+1].color;
|
||||
|
||||
points[2].x = x+disp_array[idx+1].x;
|
||||
points[2].y = y+disp_array[idx+1].y;
|
||||
points[2].z = disp_array[idx+1].z;
|
||||
points[2].color = disp_array[idx+1].color;
|
||||
|
||||
points[3].x = x+disp_array[idx].x;
|
||||
points[3].y = y+disp_array[idx].y;
|
||||
points[3].z = disp_array[idx].z;
|
||||
points[3].color = disp_array[idx].color;
|
||||
|
||||
renderer->RenderQuad(quad, points);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetZ(int col, int row, float z)
|
||||
{
|
||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||
{
|
||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].color=color;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::SetDisplacement(int col, int row, float dx, float dy, int ref)
|
||||
{
|
||||
if(row<nRows && col<nCols)
|
||||
{
|
||||
switch(ref)
|
||||
{
|
||||
case HGEDISP_NODE: dx+=col*cellw; dy+=row*cellh; break;
|
||||
case HGEDISP_CENTER: dx+=cellw*(nCols-1)/2;dy+=cellh*(nRows-1)/2; break;
|
||||
case HGEDISP_TOPLEFT: break;
|
||||
}
|
||||
|
||||
disp_array[row*nCols+col].x=dx;
|
||||
disp_array[row*nCols+col].y=dy;
|
||||
}
|
||||
}
|
||||
|
||||
float hgeDistortionMesh::GetZ(int col, int row) const
|
||||
{
|
||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
|
||||
else return 0.0f;
|
||||
}
|
||||
|
||||
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
|
||||
{
|
||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
|
||||
{
|
||||
if(row<nRows && col<nCols)
|
||||
{
|
||||
switch(ref)
|
||||
{
|
||||
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
|
||||
*dy=disp_array[row*nCols+col].y-row*cellh;
|
||||
break;
|
||||
|
||||
case HGEDISP_CENTER: *dx=disp_array[row*nCols+col].x-cellw*(nCols-1)/2;
|
||||
*dy=disp_array[row*nCols+col].x-cellh*(nRows-1)/2;
|
||||
break;
|
||||
|
||||
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
|
||||
*dy=disp_array[row*nCols+col].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+360
-360
@@ -1,360 +1,360 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeFont helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgefont.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char FNTHEADERTAG[] = "[HGEFONT]";
|
||||
const char FNTBITMAPTAG[] = "Bitmap";
|
||||
const char FNTCHARTAG[] = "Char";
|
||||
|
||||
|
||||
//HGE *hgeFont::hge=0;
|
||||
char hgeFont::buffer[256];
|
||||
|
||||
|
||||
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
|
||||
{
|
||||
//void *data;
|
||||
DWORD size;
|
||||
char *desc, *pdesc;
|
||||
char linebuf[256];
|
||||
char buf[512], *pbuf;
|
||||
char chr;
|
||||
int i, x, y, w, h, a, c;
|
||||
|
||||
// Setup variables
|
||||
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
fHeight=0.0f;
|
||||
fScale=1.0f;
|
||||
fProportion=1.0f;
|
||||
fRot=0.0f;
|
||||
fTracking=0.0f;
|
||||
fSpacing=1.0f;
|
||||
hTexture=0;
|
||||
|
||||
fZ=0.5f;
|
||||
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
|
||||
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||
|
||||
memset( &letters, 0, sizeof(letters) );
|
||||
memset( &pre, 0, sizeof(letters) );
|
||||
memset( &post, 0, sizeof(letters) );
|
||||
|
||||
// Load font description
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
if (!fileSys->OpenFile(szFont)) return;
|
||||
|
||||
//data=hge->Resource_Load(szFont, &size);
|
||||
//if(!data) return;
|
||||
size = fileSys->GetFileSize();
|
||||
|
||||
desc = new char[size+1];
|
||||
//memcpy(desc,data,size);
|
||||
fileSys->ReadFile(desc, size);
|
||||
desc[size]=0;
|
||||
|
||||
//hge->Resource_Free(data);
|
||||
fileSys->CloseFile();
|
||||
|
||||
pdesc=_get_line(desc,linebuf);
|
||||
if(strcmp(linebuf, FNTHEADERTAG))
|
||||
{
|
||||
// hge->System_Log("Font %s has incorrect format.", szFont);
|
||||
delete[] desc;
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse font description
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
|
||||
{
|
||||
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
|
||||
{
|
||||
strcpy(buf,szFont);
|
||||
pbuf=strrchr(buf,'\\');
|
||||
if(!pbuf) pbuf=strrchr(buf,'/');
|
||||
if(!pbuf) pbuf=buf;
|
||||
else pbuf++;
|
||||
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
|
||||
|
||||
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
|
||||
hTexture = renderer->LoadTexture(buf);
|
||||
if(!hTexture)
|
||||
{
|
||||
delete[] desc;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
|
||||
{
|
||||
pbuf=strchr(linebuf,'=');
|
||||
if(!pbuf) continue;
|
||||
pbuf++;
|
||||
while(*pbuf==' ') pbuf++;
|
||||
if(*pbuf=='\"')
|
||||
{
|
||||
pbuf++;
|
||||
i=(unsigned char)*pbuf++;
|
||||
pbuf++; // skip "
|
||||
}
|
||||
else
|
||||
{
|
||||
i=0;
|
||||
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
|
||||
{
|
||||
chr=*pbuf;
|
||||
if(chr >= 'a') chr-='a'-':';
|
||||
if(chr >= 'A') chr-='A'-':';
|
||||
chr-='0';
|
||||
if(chr>0xF) chr=0xF;
|
||||
i=(i << 4) | chr;
|
||||
pbuf++;
|
||||
}
|
||||
if(i<0 || i>255) continue;
|
||||
}
|
||||
sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);
|
||||
|
||||
letters[i] = new JQuad(hTexture, (float)x, (float)y, (float)w, (float)h);
|
||||
pre[i]=(float)a;
|
||||
post[i]=(float)c;
|
||||
if(h>fHeight) fHeight=(float)h;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] desc;
|
||||
}
|
||||
|
||||
|
||||
hgeFont::~hgeFont()
|
||||
{
|
||||
for(int i=0; i<256; i++)
|
||||
if(letters[i]) delete letters[i];
|
||||
if(hTexture) delete hTexture;
|
||||
//hge->Release();
|
||||
}
|
||||
|
||||
void hgeFont::Render(float x, float y, int align, const char *string)
|
||||
{
|
||||
int i;
|
||||
float fx=x;
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
align &= HGETEXT_HORZMASK;
|
||||
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
|
||||
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
|
||||
|
||||
while(*string)
|
||||
{
|
||||
if(*string=='\n')
|
||||
{
|
||||
y += int(fHeight*fScale*fSpacing);
|
||||
fx = x;
|
||||
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
|
||||
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
i=(unsigned char)*string;
|
||||
if(!letters[i]) i='?';
|
||||
if(letters[i])
|
||||
{
|
||||
fx += pre[i]*fScale*fProportion;
|
||||
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
|
||||
renderer->RenderQuad(letters[i], fx, y, fRot, fScale*fProportion, fScale);
|
||||
fx += (letters[i]->mWidth+post[i]+fTracking)*fScale*fProportion;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeFont::printf(float x, float y, int align, const char *format, ...)
|
||||
{
|
||||
//char *pArg=(char *) &format+sizeof(format);
|
||||
|
||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||
//buffer[sizeof(buffer)-1]=0;
|
||||
//vsprintf(buffer, format, pArg);
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(buffer, format, list);
|
||||
va_end(list);
|
||||
|
||||
Render(x,y,align,buffer);
|
||||
}
|
||||
|
||||
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
|
||||
{
|
||||
char chr, *pbuf, *prevword, *linestart;
|
||||
int i,lines=0;
|
||||
float tx, ty, hh, ww;
|
||||
//char *pArg=(char *) &format+sizeof(format);
|
||||
|
||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||
//buffer[sizeof(buffer)-1]=0;
|
||||
//vsprintf(buffer, format, pArg);
|
||||
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(buffer, format, list);
|
||||
va_end(list);
|
||||
|
||||
|
||||
linestart=buffer;
|
||||
pbuf=buffer;
|
||||
prevword=0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
i=0;
|
||||
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
|
||||
|
||||
chr=pbuf[i];
|
||||
pbuf[i]=0;
|
||||
ww=GetStringWidth(linestart);
|
||||
pbuf[i]=chr;
|
||||
|
||||
if(ww > w)
|
||||
{
|
||||
if(pbuf==linestart)
|
||||
{
|
||||
pbuf[i]='\n';
|
||||
linestart=&pbuf[i+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
*prevword='\n';
|
||||
linestart=prevword+1;
|
||||
}
|
||||
|
||||
lines++;
|
||||
}
|
||||
|
||||
if(pbuf[i]=='\n')
|
||||
{
|
||||
prevword=&pbuf[i];
|
||||
linestart=&pbuf[i+1];
|
||||
pbuf=&pbuf[i+1];
|
||||
lines++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!pbuf[i]) {lines++;break;}
|
||||
|
||||
prevword=&pbuf[i];
|
||||
pbuf=&pbuf[i+1];
|
||||
}
|
||||
|
||||
tx=x;
|
||||
ty=y;
|
||||
hh=fHeight*fSpacing*fScale*lines;
|
||||
|
||||
switch(align & HGETEXT_HORZMASK)
|
||||
{
|
||||
case HGETEXT_LEFT: break;
|
||||
case HGETEXT_RIGHT: tx+=w; break;
|
||||
case HGETEXT_CENTER: tx+=int(w/2); break;
|
||||
}
|
||||
|
||||
switch(align & HGETEXT_VERTMASK)
|
||||
{
|
||||
case HGETEXT_TOP: break;
|
||||
case HGETEXT_BOTTOM: ty+=h-hh; break;
|
||||
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
|
||||
}
|
||||
|
||||
Render(tx,ty,align,buffer);
|
||||
}
|
||||
|
||||
float hgeFont::GetStringWidth(const char *string) const
|
||||
{
|
||||
int i;
|
||||
float linew, w = 0;
|
||||
|
||||
while(*string)
|
||||
{
|
||||
linew = 0;
|
||||
|
||||
while(*string && *string != '\n')
|
||||
{
|
||||
i=(unsigned char)*string;
|
||||
if(!letters[i]) i='?';
|
||||
if(letters[i])
|
||||
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
|
||||
|
||||
string++;
|
||||
}
|
||||
|
||||
if(linew > w) w = linew;
|
||||
|
||||
while (*string == '\n' || *string == '\r') string++;
|
||||
}
|
||||
|
||||
return w*fScale*fProportion;
|
||||
}
|
||||
|
||||
void hgeFont::SetColor(PIXEL_TYPE col)
|
||||
{
|
||||
dwCol = col;
|
||||
|
||||
for(int i=0; i<256; i++)
|
||||
if(letters[i])
|
||||
letters[i]->SetColor(col);
|
||||
}
|
||||
|
||||
void hgeFont::SetZ(float z)
|
||||
{
|
||||
fZ = z;
|
||||
|
||||
//for(int i=0; i<256; i++)
|
||||
// if(letters[i])
|
||||
// letters[i]->SetZ(z);
|
||||
}
|
||||
|
||||
void hgeFont::SetBlendMode(int blend)
|
||||
{
|
||||
nBlend = blend;
|
||||
|
||||
//for(int i=0; i<256; i++)
|
||||
// if(letters[i])
|
||||
// letters[i]->SetBlendMode(blend);
|
||||
}
|
||||
|
||||
char *hgeFont::_get_line(char *file, char *line)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
if(!file[i]) return 0;
|
||||
|
||||
while(file[i] && file[i]!='\n' && file[i]!='\r')
|
||||
{
|
||||
line[i]=file[i];
|
||||
i++;
|
||||
}
|
||||
line[i]=0;
|
||||
|
||||
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
|
||||
|
||||
return file + i;
|
||||
}
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeFont helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgefont.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char FNTHEADERTAG[] = "[HGEFONT]";
|
||||
const char FNTBITMAPTAG[] = "Bitmap";
|
||||
const char FNTCHARTAG[] = "Char";
|
||||
|
||||
|
||||
//HGE *hgeFont::hge=0;
|
||||
char hgeFont::buffer[256];
|
||||
|
||||
|
||||
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
|
||||
{
|
||||
//void *data;
|
||||
DWORD size;
|
||||
char *desc, *pdesc;
|
||||
char linebuf[256];
|
||||
char buf[512], *pbuf;
|
||||
char chr;
|
||||
int i, x, y, w, h, a, c;
|
||||
|
||||
// Setup variables
|
||||
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
fHeight=0.0f;
|
||||
fScale=1.0f;
|
||||
fProportion=1.0f;
|
||||
fRot=0.0f;
|
||||
fTracking=0.0f;
|
||||
fSpacing=1.0f;
|
||||
hTexture=0;
|
||||
|
||||
fZ=0.5f;
|
||||
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
|
||||
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||
|
||||
memset( &letters, 0, sizeof(letters) );
|
||||
memset( &pre, 0, sizeof(letters) );
|
||||
memset( &post, 0, sizeof(letters) );
|
||||
|
||||
// Load font description
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
if (!fileSys->OpenFile(szFont)) return;
|
||||
|
||||
//data=hge->Resource_Load(szFont, &size);
|
||||
//if(!data) return;
|
||||
size = fileSys->GetFileSize();
|
||||
|
||||
desc = new char[size+1];
|
||||
//memcpy(desc,data,size);
|
||||
fileSys->ReadFile(desc, size);
|
||||
desc[size]=0;
|
||||
|
||||
//hge->Resource_Free(data);
|
||||
fileSys->CloseFile();
|
||||
|
||||
pdesc=_get_line(desc,linebuf);
|
||||
if(strcmp(linebuf, FNTHEADERTAG))
|
||||
{
|
||||
// hge->System_Log("Font %s has incorrect format.", szFont);
|
||||
delete[] desc;
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse font description
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
|
||||
{
|
||||
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
|
||||
{
|
||||
strcpy(buf,szFont);
|
||||
pbuf=strrchr(buf,'\\');
|
||||
if(!pbuf) pbuf=strrchr(buf,'/');
|
||||
if(!pbuf) pbuf=buf;
|
||||
else pbuf++;
|
||||
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
|
||||
|
||||
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
|
||||
hTexture = renderer->LoadTexture(buf);
|
||||
if(!hTexture)
|
||||
{
|
||||
delete[] desc;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
|
||||
{
|
||||
pbuf=strchr(linebuf,'=');
|
||||
if(!pbuf) continue;
|
||||
pbuf++;
|
||||
while(*pbuf==' ') pbuf++;
|
||||
if(*pbuf=='\"')
|
||||
{
|
||||
pbuf++;
|
||||
i=(unsigned char)*pbuf++;
|
||||
pbuf++; // skip "
|
||||
}
|
||||
else
|
||||
{
|
||||
i=0;
|
||||
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
|
||||
{
|
||||
chr=*pbuf;
|
||||
if(chr >= 'a') chr-='a'-':';
|
||||
if(chr >= 'A') chr-='A'-':';
|
||||
chr-='0';
|
||||
if(chr>0xF) chr=0xF;
|
||||
i=(i << 4) | chr;
|
||||
pbuf++;
|
||||
}
|
||||
if(i<0 || i>255) continue;
|
||||
}
|
||||
sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);
|
||||
|
||||
letters[i] = new JQuad(hTexture, (float)x, (float)y, (float)w, (float)h);
|
||||
pre[i]=(float)a;
|
||||
post[i]=(float)c;
|
||||
if(h>fHeight) fHeight=(float)h;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] desc;
|
||||
}
|
||||
|
||||
|
||||
hgeFont::~hgeFont()
|
||||
{
|
||||
for(int i=0; i<256; i++)
|
||||
if(letters[i]) delete letters[i];
|
||||
if(hTexture) delete hTexture;
|
||||
//hge->Release();
|
||||
}
|
||||
|
||||
void hgeFont::Render(float x, float y, int align, const char *string)
|
||||
{
|
||||
int i;
|
||||
float fx=x;
|
||||
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
align &= HGETEXT_HORZMASK;
|
||||
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
|
||||
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
|
||||
|
||||
while(*string)
|
||||
{
|
||||
if(*string=='\n')
|
||||
{
|
||||
y += int(fHeight*fScale*fSpacing);
|
||||
fx = x;
|
||||
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
|
||||
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
i=(unsigned char)*string;
|
||||
if(!letters[i]) i='?';
|
||||
if(letters[i])
|
||||
{
|
||||
fx += pre[i]*fScale*fProportion;
|
||||
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
|
||||
renderer->RenderQuad(letters[i], fx, y, fRot, fScale*fProportion, fScale);
|
||||
fx += (letters[i]->mWidth+post[i]+fTracking)*fScale*fProportion;
|
||||
}
|
||||
}
|
||||
string++;
|
||||
}
|
||||
}
|
||||
|
||||
void hgeFont::printf(float x, float y, int align, const char *format, ...)
|
||||
{
|
||||
//char *pArg=(char *) &format+sizeof(format);
|
||||
|
||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||
//buffer[sizeof(buffer)-1]=0;
|
||||
//vsprintf(buffer, format, pArg);
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(buffer, format, list);
|
||||
va_end(list);
|
||||
|
||||
Render(x,y,align,buffer);
|
||||
}
|
||||
|
||||
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
|
||||
{
|
||||
char chr, *pbuf, *prevword, *linestart;
|
||||
int i,lines=0;
|
||||
float tx, ty, hh, ww;
|
||||
//char *pArg=(char *) &format+sizeof(format);
|
||||
|
||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||
//buffer[sizeof(buffer)-1]=0;
|
||||
//vsprintf(buffer, format, pArg);
|
||||
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(buffer, format, list);
|
||||
va_end(list);
|
||||
|
||||
|
||||
linestart=buffer;
|
||||
pbuf=buffer;
|
||||
prevword=0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
i=0;
|
||||
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
|
||||
|
||||
chr=pbuf[i];
|
||||
pbuf[i]=0;
|
||||
ww=GetStringWidth(linestart);
|
||||
pbuf[i]=chr;
|
||||
|
||||
if(ww > w)
|
||||
{
|
||||
if(pbuf==linestart)
|
||||
{
|
||||
pbuf[i]='\n';
|
||||
linestart=&pbuf[i+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
*prevword='\n';
|
||||
linestart=prevword+1;
|
||||
}
|
||||
|
||||
lines++;
|
||||
}
|
||||
|
||||
if(pbuf[i]=='\n')
|
||||
{
|
||||
prevword=&pbuf[i];
|
||||
linestart=&pbuf[i+1];
|
||||
pbuf=&pbuf[i+1];
|
||||
lines++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!pbuf[i]) {lines++;break;}
|
||||
|
||||
prevword=&pbuf[i];
|
||||
pbuf=&pbuf[i+1];
|
||||
}
|
||||
|
||||
tx=x;
|
||||
ty=y;
|
||||
hh=fHeight*fSpacing*fScale*lines;
|
||||
|
||||
switch(align & HGETEXT_HORZMASK)
|
||||
{
|
||||
case HGETEXT_LEFT: break;
|
||||
case HGETEXT_RIGHT: tx+=w; break;
|
||||
case HGETEXT_CENTER: tx+=int(w/2); break;
|
||||
}
|
||||
|
||||
switch(align & HGETEXT_VERTMASK)
|
||||
{
|
||||
case HGETEXT_TOP: break;
|
||||
case HGETEXT_BOTTOM: ty+=h-hh; break;
|
||||
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
|
||||
}
|
||||
|
||||
Render(tx,ty,align,buffer);
|
||||
}
|
||||
|
||||
float hgeFont::GetStringWidth(const char *string) const
|
||||
{
|
||||
int i;
|
||||
float linew, w = 0;
|
||||
|
||||
while(*string)
|
||||
{
|
||||
linew = 0;
|
||||
|
||||
while(*string && *string != '\n')
|
||||
{
|
||||
i=(unsigned char)*string;
|
||||
if(!letters[i]) i='?';
|
||||
if(letters[i])
|
||||
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
|
||||
|
||||
string++;
|
||||
}
|
||||
|
||||
if(linew > w) w = linew;
|
||||
|
||||
while (*string == '\n' || *string == '\r') string++;
|
||||
}
|
||||
|
||||
return w*fScale*fProportion;
|
||||
}
|
||||
|
||||
void hgeFont::SetColor(PIXEL_TYPE col)
|
||||
{
|
||||
dwCol = col;
|
||||
|
||||
for(int i=0; i<256; i++)
|
||||
if(letters[i])
|
||||
letters[i]->SetColor(col);
|
||||
}
|
||||
|
||||
void hgeFont::SetZ(float z)
|
||||
{
|
||||
fZ = z;
|
||||
|
||||
//for(int i=0; i<256; i++)
|
||||
// if(letters[i])
|
||||
// letters[i]->SetZ(z);
|
||||
}
|
||||
|
||||
void hgeFont::SetBlendMode(int blend)
|
||||
{
|
||||
nBlend = blend;
|
||||
|
||||
//for(int i=0; i<256; i++)
|
||||
// if(letters[i])
|
||||
// letters[i]->SetBlendMode(blend);
|
||||
}
|
||||
|
||||
char *hgeFont::_get_line(char *file, char *line)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
if(!file[i]) return 0;
|
||||
|
||||
while(file[i] && file[i]!='\n' && file[i]!='\r')
|
||||
{
|
||||
line[i]=file[i];
|
||||
i++;
|
||||
}
|
||||
line[i]=0;
|
||||
|
||||
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
|
||||
|
||||
return file + i;
|
||||
}
|
||||
|
||||
+306
-306
@@ -1,306 +1,306 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleSystem helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgeparticle.h"
|
||||
|
||||
|
||||
//HGE *hgeParticleSystem::hge=0;
|
||||
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** Core functions implementation: random number generation
|
||||
*/
|
||||
|
||||
|
||||
unsigned int g_seed=0;
|
||||
|
||||
void Random_Seed(int seed)
|
||||
{
|
||||
if(!seed) g_seed=JGE::GetInstance()->GetTime();
|
||||
else g_seed=seed;
|
||||
}
|
||||
|
||||
int Random_Int(int min, int max)
|
||||
{
|
||||
g_seed=214013*g_seed+2531011;
|
||||
return min+(g_seed ^ g_seed>>15)%(max-min+1);
|
||||
}
|
||||
|
||||
float Random_Float(float min, float max)
|
||||
{
|
||||
g_seed=214013*g_seed+2531011;
|
||||
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
||||
{
|
||||
//void *psi;
|
||||
//hgeParticleSystemInfo psi;
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
//psi=hge->Resource_Load(filename);
|
||||
if (!fileSys->OpenFile(filename)) return;
|
||||
|
||||
//if(!psi) return;
|
||||
|
||||
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||
//hge->Resource_Free(psi);
|
||||
|
||||
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
||||
void *dummyPointer;
|
||||
fileSys->ReadFile(&dummyPointer, 4);
|
||||
// we're actually trying to read more than the file size now, but it's no problem.
|
||||
// Note that this fix is only to avoid the largest problems, filling a structure
|
||||
// by directly reading a file, is really a bad idea ...
|
||||
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
|
||||
fileSys->CloseFile();
|
||||
|
||||
info.sprite=sprite;
|
||||
// info.fGravityMin *= 100;
|
||||
// info.fGravityMax *= 100;
|
||||
// info.fSpeedMin *= 100;
|
||||
// info.fSpeedMax *= 100;
|
||||
|
||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||
fTx=fTy=0;
|
||||
|
||||
fEmissionResidue=0.0f;
|
||||
nParticlesAlive=0;
|
||||
fAge=-2.0;
|
||||
mTimer = 0.0f;
|
||||
|
||||
rectBoundingBox.Clear();
|
||||
bUpdateBoundingBox=false;
|
||||
}
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
||||
{
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||
|
||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||
fTx=fTy=0;
|
||||
|
||||
fEmissionResidue=0.0f;
|
||||
nParticlesAlive=0;
|
||||
fAge=-2.0;
|
||||
mTimer = 0.0f;
|
||||
|
||||
rectBoundingBox.Clear();
|
||||
bUpdateBoundingBox=false;
|
||||
}
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
|
||||
{
|
||||
memcpy(this, &ps, sizeof(hgeParticleSystem));
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Update(float fDeltaTime)
|
||||
{
|
||||
int i;
|
||||
float ang;
|
||||
hgeVector vecAccel, vecAccel2;
|
||||
|
||||
if(fAge >= 0)
|
||||
{
|
||||
fAge += fDeltaTime;
|
||||
if(fAge >= info.fLifetime) fAge = -2.0f;
|
||||
}
|
||||
|
||||
mTimer += fDeltaTime;
|
||||
if (mTimer < 0.01f)
|
||||
return;
|
||||
|
||||
fDeltaTime = mTimer;
|
||||
mTimer = 0.0f;
|
||||
|
||||
|
||||
// update all alive particles
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Clear();
|
||||
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
while(particle != mParticleBuffer.end())
|
||||
{
|
||||
particle->fAge += fDeltaTime;
|
||||
if(particle->fAge >= particle->fTerminalAge)
|
||||
{
|
||||
nParticlesAlive--;
|
||||
++particle;
|
||||
mParticleBuffer.pop_front();
|
||||
continue;
|
||||
}
|
||||
|
||||
vecAccel = particle->vecLocation-vecLocation;
|
||||
vecAccel.Normalize();
|
||||
vecAccel2 = vecAccel;
|
||||
vecAccel *= particle->fRadialAccel;
|
||||
|
||||
// vecAccel2.Rotate(M_PI_2);
|
||||
// the following is faster
|
||||
ang = vecAccel2.x;
|
||||
vecAccel2.x = -vecAccel2.y;
|
||||
vecAccel2.y = ang;
|
||||
|
||||
vecAccel2 *= particle->fTangentialAccel;
|
||||
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
|
||||
|
||||
//par->vecVelocity.y = 0.1f;
|
||||
particle->vecLocation += particle->vecVelocity;
|
||||
|
||||
particle->fSpin += particle->fSpinDelta*fDeltaTime;
|
||||
particle->fSize += particle->fSizeDelta*fDeltaTime;
|
||||
particle->colColor += particle->colColorDelta*fDeltaTime;
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
|
||||
|
||||
++particle;
|
||||
}
|
||||
|
||||
// generate new particles
|
||||
|
||||
if(fAge != -2.0f)
|
||||
{
|
||||
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
|
||||
int nParticlesCreated = (unsigned int)fParticlesNeeded;
|
||||
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
|
||||
|
||||
for(i=0; i<nParticlesCreated; i++)
|
||||
{
|
||||
if(nParticlesAlive>=MAX_PARTICLES) break;
|
||||
|
||||
hgeParticle newParticle;
|
||||
newParticle.fAge = 0.0f;
|
||||
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
|
||||
|
||||
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
|
||||
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
|
||||
newParticle.vecLocation.y += Random_Float(-2.0f, 2.0f);
|
||||
|
||||
ang=info.fDirection-M_PI_2+Random_Float(0,info.fSpread)-info.fSpread/2.0f;
|
||||
if(info.bRelative) ang += (vecPrevLocation-vecLocation).Angle()+M_PI_2;
|
||||
newParticle.vecVelocity.x = cosf(ang);
|
||||
newParticle.vecVelocity.y = sinf(ang);
|
||||
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
|
||||
|
||||
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
|
||||
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
|
||||
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
|
||||
|
||||
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
|
||||
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
|
||||
|
||||
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
|
||||
newParticle.fSpinDelta = (info.fSpinEnd-newParticle.fSpin) / newParticle.fTerminalAge;
|
||||
|
||||
newParticle.colColor.r = Random_Float(info.colColorStart.r, info.colColorStart.r+(info.colColorEnd.r-info.colColorStart.r)*info.fColorVar);
|
||||
newParticle.colColor.g = Random_Float(info.colColorStart.g, info.colColorStart.g+(info.colColorEnd.g-info.colColorStart.g)*info.fColorVar);
|
||||
newParticle.colColor.b = Random_Float(info.colColorStart.b, info.colColorStart.b+(info.colColorEnd.b-info.colColorStart.b)*info.fColorVar);
|
||||
newParticle.colColor.a = Random_Float(info.colColorStart.a, info.colColorStart.a+(info.colColorEnd.a-info.colColorStart.a)*info.fAlphaVar);
|
||||
|
||||
newParticle.colColorDelta.r = (info.colColorEnd.r-newParticle.colColor.r) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.g = (info.colColorEnd.g-newParticle.colColor.g) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.b = (info.colColorEnd.b-newParticle.colColor.b) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
|
||||
|
||||
mParticleBuffer.push_back(newParticle);
|
||||
++nParticlesAlive;
|
||||
}
|
||||
}
|
||||
|
||||
vecPrevLocation=vecLocation;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
|
||||
{
|
||||
float dx,dy;
|
||||
|
||||
if(bMoveParticles)
|
||||
{
|
||||
dx=x-vecLocation.x;
|
||||
dy=y-vecLocation.y;
|
||||
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
for (; particle != mParticleBuffer.end(); ++particle)
|
||||
{
|
||||
particle->vecLocation.x += dx;
|
||||
particle->vecLocation.y += dy;
|
||||
}
|
||||
|
||||
vecPrevLocation.x=vecPrevLocation.x + dx;
|
||||
vecPrevLocation.y=vecPrevLocation.y + dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
|
||||
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
|
||||
}
|
||||
|
||||
vecLocation.x=x;
|
||||
vecLocation.y=y;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::FireAt(float x, float y)
|
||||
{
|
||||
Stop();
|
||||
MoveTo(x,y);
|
||||
Fire();
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Fire()
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
|
||||
if(info.fLifetime==-1.0f) fAge=-1.0f;
|
||||
else fAge=0.0f;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Stop(bool bKillParticles)
|
||||
{
|
||||
fAge=-2.0f;
|
||||
if(bKillParticles)
|
||||
{
|
||||
nParticlesAlive=0;
|
||||
mParticleBuffer.clear();
|
||||
rectBoundingBox.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Render()
|
||||
{
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
for (;particle != mParticleBuffer.end(); ++particle)
|
||||
{
|
||||
info.sprite->SetColor(particle->colColor.GetHWColor());
|
||||
JRenderer::GetInstance()->RenderQuad(
|
||||
info.sprite,
|
||||
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
|
||||
particle->fSpin * particle->fAge,
|
||||
particle->fSize, particle->fSize);
|
||||
}
|
||||
}
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleSystem helper class implementation
|
||||
*/
|
||||
|
||||
#include "../../include/JGE.h"
|
||||
#include "../../include/JTypes.h"
|
||||
#include "../../include/JRenderer.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
|
||||
#include "../../include/hge/hgeparticle.h"
|
||||
|
||||
|
||||
//HGE *hgeParticleSystem::hge=0;
|
||||
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** Core functions implementation: random number generation
|
||||
*/
|
||||
|
||||
|
||||
unsigned int g_seed=0;
|
||||
|
||||
void Random_Seed(int seed)
|
||||
{
|
||||
if(!seed) g_seed=JGE::GetInstance()->GetTime();
|
||||
else g_seed=seed;
|
||||
}
|
||||
|
||||
int Random_Int(int min, int max)
|
||||
{
|
||||
g_seed=214013*g_seed+2531011;
|
||||
return min+(g_seed ^ g_seed>>15)%(max-min+1);
|
||||
}
|
||||
|
||||
float Random_Float(float min, float max)
|
||||
{
|
||||
g_seed=214013*g_seed+2531011;
|
||||
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
||||
{
|
||||
//void *psi;
|
||||
//hgeParticleSystemInfo psi;
|
||||
|
||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
//psi=hge->Resource_Load(filename);
|
||||
if (!fileSys->OpenFile(filename)) return;
|
||||
|
||||
//if(!psi) return;
|
||||
|
||||
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||
//hge->Resource_Free(psi);
|
||||
|
||||
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
||||
void *dummyPointer;
|
||||
fileSys->ReadFile(&dummyPointer, 4);
|
||||
// we're actually trying to read more than the file size now, but it's no problem.
|
||||
// Note that this fix is only to avoid the largest problems, filling a structure
|
||||
// by directly reading a file, is really a bad idea ...
|
||||
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
|
||||
fileSys->CloseFile();
|
||||
|
||||
info.sprite=sprite;
|
||||
// info.fGravityMin *= 100;
|
||||
// info.fGravityMax *= 100;
|
||||
// info.fSpeedMin *= 100;
|
||||
// info.fSpeedMax *= 100;
|
||||
|
||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||
fTx=fTy=0;
|
||||
|
||||
fEmissionResidue=0.0f;
|
||||
nParticlesAlive=0;
|
||||
fAge=-2.0;
|
||||
mTimer = 0.0f;
|
||||
|
||||
rectBoundingBox.Clear();
|
||||
bUpdateBoundingBox=false;
|
||||
}
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
||||
{
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
|
||||
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||
|
||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||
fTx=fTy=0;
|
||||
|
||||
fEmissionResidue=0.0f;
|
||||
nParticlesAlive=0;
|
||||
fAge=-2.0;
|
||||
mTimer = 0.0f;
|
||||
|
||||
rectBoundingBox.Clear();
|
||||
bUpdateBoundingBox=false;
|
||||
}
|
||||
|
||||
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
|
||||
{
|
||||
memcpy(this, &ps, sizeof(hgeParticleSystem));
|
||||
//hge=hgeCreate(HGE_VERSION);
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Update(float fDeltaTime)
|
||||
{
|
||||
int i;
|
||||
float ang;
|
||||
hgeVector vecAccel, vecAccel2;
|
||||
|
||||
if(fAge >= 0)
|
||||
{
|
||||
fAge += fDeltaTime;
|
||||
if(fAge >= info.fLifetime) fAge = -2.0f;
|
||||
}
|
||||
|
||||
mTimer += fDeltaTime;
|
||||
if (mTimer < 0.01f)
|
||||
return;
|
||||
|
||||
fDeltaTime = mTimer;
|
||||
mTimer = 0.0f;
|
||||
|
||||
|
||||
// update all alive particles
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Clear();
|
||||
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
while(particle != mParticleBuffer.end())
|
||||
{
|
||||
particle->fAge += fDeltaTime;
|
||||
if(particle->fAge >= particle->fTerminalAge)
|
||||
{
|
||||
nParticlesAlive--;
|
||||
++particle;
|
||||
mParticleBuffer.pop_front();
|
||||
continue;
|
||||
}
|
||||
|
||||
vecAccel = particle->vecLocation-vecLocation;
|
||||
vecAccel.Normalize();
|
||||
vecAccel2 = vecAccel;
|
||||
vecAccel *= particle->fRadialAccel;
|
||||
|
||||
// vecAccel2.Rotate(M_PI_2);
|
||||
// the following is faster
|
||||
ang = vecAccel2.x;
|
||||
vecAccel2.x = -vecAccel2.y;
|
||||
vecAccel2.y = ang;
|
||||
|
||||
vecAccel2 *= particle->fTangentialAccel;
|
||||
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
|
||||
|
||||
//par->vecVelocity.y = 0.1f;
|
||||
particle->vecLocation += particle->vecVelocity;
|
||||
|
||||
particle->fSpin += particle->fSpinDelta*fDeltaTime;
|
||||
particle->fSize += particle->fSizeDelta*fDeltaTime;
|
||||
particle->colColor += particle->colColorDelta*fDeltaTime;
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
|
||||
|
||||
++particle;
|
||||
}
|
||||
|
||||
// generate new particles
|
||||
|
||||
if(fAge != -2.0f)
|
||||
{
|
||||
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
|
||||
int nParticlesCreated = (unsigned int)fParticlesNeeded;
|
||||
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
|
||||
|
||||
for(i=0; i<nParticlesCreated; i++)
|
||||
{
|
||||
if(nParticlesAlive>=MAX_PARTICLES) break;
|
||||
|
||||
hgeParticle newParticle;
|
||||
newParticle.fAge = 0.0f;
|
||||
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
|
||||
|
||||
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
|
||||
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
|
||||
newParticle.vecLocation.y += Random_Float(-2.0f, 2.0f);
|
||||
|
||||
ang=info.fDirection-M_PI_2+Random_Float(0,info.fSpread)-info.fSpread/2.0f;
|
||||
if(info.bRelative) ang += (vecPrevLocation-vecLocation).Angle()+M_PI_2;
|
||||
newParticle.vecVelocity.x = cosf(ang);
|
||||
newParticle.vecVelocity.y = sinf(ang);
|
||||
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
|
||||
|
||||
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
|
||||
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
|
||||
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
|
||||
|
||||
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
|
||||
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
|
||||
|
||||
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
|
||||
newParticle.fSpinDelta = (info.fSpinEnd-newParticle.fSpin) / newParticle.fTerminalAge;
|
||||
|
||||
newParticle.colColor.r = Random_Float(info.colColorStart.r, info.colColorStart.r+(info.colColorEnd.r-info.colColorStart.r)*info.fColorVar);
|
||||
newParticle.colColor.g = Random_Float(info.colColorStart.g, info.colColorStart.g+(info.colColorEnd.g-info.colColorStart.g)*info.fColorVar);
|
||||
newParticle.colColor.b = Random_Float(info.colColorStart.b, info.colColorStart.b+(info.colColorEnd.b-info.colColorStart.b)*info.fColorVar);
|
||||
newParticle.colColor.a = Random_Float(info.colColorStart.a, info.colColorStart.a+(info.colColorEnd.a-info.colColorStart.a)*info.fAlphaVar);
|
||||
|
||||
newParticle.colColorDelta.r = (info.colColorEnd.r-newParticle.colColor.r) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.g = (info.colColorEnd.g-newParticle.colColor.g) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.b = (info.colColorEnd.b-newParticle.colColor.b) / newParticle.fTerminalAge;
|
||||
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
|
||||
|
||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
|
||||
|
||||
mParticleBuffer.push_back(newParticle);
|
||||
++nParticlesAlive;
|
||||
}
|
||||
}
|
||||
|
||||
vecPrevLocation=vecLocation;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
|
||||
{
|
||||
float dx,dy;
|
||||
|
||||
if(bMoveParticles)
|
||||
{
|
||||
dx=x-vecLocation.x;
|
||||
dy=y-vecLocation.y;
|
||||
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
for (; particle != mParticleBuffer.end(); ++particle)
|
||||
{
|
||||
particle->vecLocation.x += dx;
|
||||
particle->vecLocation.y += dy;
|
||||
}
|
||||
|
||||
vecPrevLocation.x=vecPrevLocation.x + dx;
|
||||
vecPrevLocation.y=vecPrevLocation.y + dy;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
|
||||
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
|
||||
}
|
||||
|
||||
vecLocation.x=x;
|
||||
vecLocation.y=y;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::FireAt(float x, float y)
|
||||
{
|
||||
Stop();
|
||||
MoveTo(x,y);
|
||||
Fire();
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Fire()
|
||||
{
|
||||
mTimer = 0.0f;
|
||||
|
||||
if(info.fLifetime==-1.0f) fAge=-1.0f;
|
||||
else fAge=0.0f;
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Stop(bool bKillParticles)
|
||||
{
|
||||
fAge=-2.0f;
|
||||
if(bKillParticles)
|
||||
{
|
||||
nParticlesAlive=0;
|
||||
mParticleBuffer.clear();
|
||||
rectBoundingBox.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleSystem::Render()
|
||||
{
|
||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||
for (;particle != mParticleBuffer.end(); ++particle)
|
||||
{
|
||||
info.sprite->SetColor(particle->colColor.GetHWColor());
|
||||
JRenderer::GetInstance()->RenderQuad(
|
||||
info.sprite,
|
||||
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
|
||||
particle->fSpin * particle->fAge,
|
||||
particle->fSize, particle->fSize);
|
||||
}
|
||||
}
|
||||
|
||||
+91
-91
@@ -1,91 +1,91 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleManager helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgeparticle.h"
|
||||
|
||||
|
||||
hgeParticleManager::hgeParticleManager()
|
||||
{
|
||||
nPS=0;
|
||||
tX=tY=0.0f;
|
||||
}
|
||||
|
||||
hgeParticleManager::~hgeParticleManager()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) delete psList[i];
|
||||
}
|
||||
|
||||
void hgeParticleManager::Update(float dt)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++)
|
||||
{
|
||||
psList[i]->Update(dt);
|
||||
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
|
||||
{
|
||||
delete psList[i];
|
||||
psList[i]=psList[nPS-1];
|
||||
nPS--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleManager::Render()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) psList[i]->Render();
|
||||
}
|
||||
|
||||
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
|
||||
{
|
||||
if(nPS==MAX_PSYSTEMS) return 0;
|
||||
psList[nPS]=new hgeParticleSystem(psi);
|
||||
psList[nPS]->FireAt(x,y);
|
||||
psList[nPS]->Transpose(tX,tY);
|
||||
nPS++;
|
||||
return psList[nPS-1];
|
||||
}
|
||||
|
||||
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void hgeParticleManager::Transpose(float x, float y)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
|
||||
tX=x; tY=y;
|
||||
}
|
||||
|
||||
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++)
|
||||
{
|
||||
if(psList[i]==ps)
|
||||
{
|
||||
delete psList[i];
|
||||
psList[i]=psList[nPS-1];
|
||||
nPS--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleManager::KillAll()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) delete psList[i];
|
||||
nPS=0;
|
||||
}
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeParticleManager helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgeparticle.h"
|
||||
|
||||
|
||||
hgeParticleManager::hgeParticleManager()
|
||||
{
|
||||
nPS=0;
|
||||
tX=tY=0.0f;
|
||||
}
|
||||
|
||||
hgeParticleManager::~hgeParticleManager()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) delete psList[i];
|
||||
}
|
||||
|
||||
void hgeParticleManager::Update(float dt)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++)
|
||||
{
|
||||
psList[i]->Update(dt);
|
||||
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
|
||||
{
|
||||
delete psList[i];
|
||||
psList[i]=psList[nPS-1];
|
||||
nPS--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleManager::Render()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) psList[i]->Render();
|
||||
}
|
||||
|
||||
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
|
||||
{
|
||||
if(nPS==MAX_PSYSTEMS) return 0;
|
||||
psList[nPS]=new hgeParticleSystem(psi);
|
||||
psList[nPS]->FireAt(x,y);
|
||||
psList[nPS]->Transpose(tX,tY);
|
||||
nPS++;
|
||||
return psList[nPS-1];
|
||||
}
|
||||
|
||||
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void hgeParticleManager::Transpose(float x, float y)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
|
||||
tX=x; tY=y;
|
||||
}
|
||||
|
||||
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++)
|
||||
{
|
||||
if(psList[i]==ps)
|
||||
{
|
||||
delete psList[i];
|
||||
psList[i]=psList[nPS-1];
|
||||
nPS--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hgeParticleManager::KillAll()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<nPS;i++) delete psList[i];
|
||||
nPS=0;
|
||||
}
|
||||
|
||||
+45
-45
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeRect helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgerect.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
void hgeRect::Encapsulate(float x, float y)
|
||||
{
|
||||
if(bClean)
|
||||
{
|
||||
x1=x2=x;
|
||||
y1=y2=y;
|
||||
bClean=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(x<x1) x1=x;
|
||||
if(x>x2) x2=x;
|
||||
if(y<y1) y1=y;
|
||||
if(y>y2) y2=y;
|
||||
}
|
||||
}
|
||||
|
||||
bool hgeRect::TestPoint(float x, float y) const
|
||||
{
|
||||
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hgeRect::Intersect(const hgeRect *rect) const
|
||||
{
|
||||
if(fabs(x1 + x2 - rect->x1 - rect->x2) < (x2 - x1 + rect->x2 - rect->x1))
|
||||
if(fabs(y1 + y2 - rect->y1 - rect->y2) < (y2 - y1 + rect->y2 - rect->y1))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeRect helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgerect.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
void hgeRect::Encapsulate(float x, float y)
|
||||
{
|
||||
if(bClean)
|
||||
{
|
||||
x1=x2=x;
|
||||
y1=y2=y;
|
||||
bClean=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(x<x1) x1=x;
|
||||
if(x>x2) x2=x;
|
||||
if(y<y1) y1=y;
|
||||
if(y>y2) y2=y;
|
||||
}
|
||||
}
|
||||
|
||||
bool hgeRect::TestPoint(float x, float y) const
|
||||
{
|
||||
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hgeRect::Intersect(const hgeRect *rect) const
|
||||
{
|
||||
if(fabs(x1 + x2 - rect->x1 - rect->x2) < (x2 - x1 + rect->x2 - rect->x1))
|
||||
if(fabs(y1 + y2 - rect->y1 - rect->y2) < (y2 - y1 + rect->y2 - rect->y1))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+69
-69
@@ -1,69 +1,69 @@
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeVector helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgevector.h"
|
||||
|
||||
float InvSqrt(float x)
|
||||
{
|
||||
union
|
||||
{
|
||||
int intPart;
|
||||
float floatPart;
|
||||
} convertor;
|
||||
|
||||
convertor.floatPart = x;
|
||||
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
|
||||
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
|
||||
}
|
||||
|
||||
/*
|
||||
hgeVector *hgeVector::Normalize()
|
||||
{
|
||||
float lenRcp;
|
||||
|
||||
lenRcp=sqrtf(Dot(this));
|
||||
|
||||
if(lenRcp)
|
||||
{
|
||||
lenRcp=1.0f/lenRcp;
|
||||
|
||||
x*=lenRcp;
|
||||
y*=lenRcp;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
float hgeVector::Angle(const hgeVector *v) const
|
||||
{
|
||||
if(v)
|
||||
{
|
||||
hgeVector s=*this, t=*v;
|
||||
|
||||
s.Normalize(); t.Normalize();
|
||||
return acosf(s.Dot(&t));
|
||||
}
|
||||
else return atan2f(y, x);
|
||||
}
|
||||
|
||||
hgeVector *hgeVector::Rotate(float a)
|
||||
{
|
||||
hgeVector v;
|
||||
|
||||
v.x=x*cosf(a) - y*sinf(a);
|
||||
v.y=x*sinf(a) + y*cosf(a);
|
||||
|
||||
x=v.x; y=v.y;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Haaf's Game Engine 1.7
|
||||
** Copyright (C) 2003-2007, Relish Games
|
||||
** hge.relishgames.com
|
||||
**
|
||||
** hgeVector helper class implementation
|
||||
*/
|
||||
|
||||
|
||||
#include "../../include/hge/hgevector.h"
|
||||
|
||||
float InvSqrt(float x)
|
||||
{
|
||||
union
|
||||
{
|
||||
int intPart;
|
||||
float floatPart;
|
||||
} convertor;
|
||||
|
||||
convertor.floatPart = x;
|
||||
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
|
||||
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
|
||||
}
|
||||
|
||||
/*
|
||||
hgeVector *hgeVector::Normalize()
|
||||
{
|
||||
float lenRcp;
|
||||
|
||||
lenRcp=sqrtf(Dot(this));
|
||||
|
||||
if(lenRcp)
|
||||
{
|
||||
lenRcp=1.0f/lenRcp;
|
||||
|
||||
x*=lenRcp;
|
||||
y*=lenRcp;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
float hgeVector::Angle(const hgeVector *v) const
|
||||
{
|
||||
if(v)
|
||||
{
|
||||
hgeVector s=*this, t=*v;
|
||||
|
||||
s.Normalize(); t.Normalize();
|
||||
return acosf(s.Dot(&t));
|
||||
}
|
||||
else return atan2f(y, x);
|
||||
}
|
||||
|
||||
hgeVector *hgeVector::Rotate(float a)
|
||||
{
|
||||
hgeVector v;
|
||||
|
||||
v.x=x*cosf(a) - y*sinf(a);
|
||||
v.y=x*sinf(a) + y*cosf(a);
|
||||
|
||||
x=v.x; y=v.y;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
Change in 1.01e (12 feb 05)
|
||||
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
|
||||
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
|
||||
|
||||
Change in 1.01b (20 may 04)
|
||||
- Integrate patch from Debian package (submited by Mark Brown)
|
||||
- Add tools mztools from Xavier Roche
|
||||
|
||||
Change in 1.01 (8 may 04)
|
||||
- fix buffer overrun risk in unzip.c (Xavier Roche)
|
||||
- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
|
||||
|
||||
Change in 1.00: (10 sept 03)
|
||||
- rename to 1.00
|
||||
- cosmetic code change
|
||||
|
||||
Change in 0.22: (19 May 03)
|
||||
- crypting support (unless you define NOCRYPT)
|
||||
- append file in existing zipfile
|
||||
|
||||
Change in 0.21: (10 Mar 03)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.17: (27 Jan 02)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.16: (19 Jan 02)
|
||||
- Support of ioapi for virtualize zip file access
|
||||
|
||||
Change in 0.15: (19 Mar 98)
|
||||
- fix memory leak in minizip.c
|
||||
|
||||
Change in 0.14: (10 Mar 98)
|
||||
- fix bugs in minizip.c sample for zipping big file
|
||||
- fix problem in month in date handling
|
||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
|
||||
comment handling
|
||||
|
||||
Change in 0.13: (6 Mar 98)
|
||||
- fix bugs in zip.c
|
||||
- add real minizip sample
|
||||
|
||||
Change in 0.12: (4 Mar 98)
|
||||
- add zip.c and zip.h for creates .zip file
|
||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
|
||||
- fix miniunz.c for file without specific record for directory
|
||||
|
||||
Change in 0.11: (3 Mar 98)
|
||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment
|
||||
- enhance miniunz sample, remove the bad unztst.c sample
|
||||
|
||||
Change in 0.10: (2 Mar 98)
|
||||
- fix bug in unzReadCurrentFile
|
||||
- rename unzip* to unz* function and structure
|
||||
- remove Windows-like hungary notation variable name
|
||||
- modify some structure in unzip.h
|
||||
- add somes comment in source
|
||||
- remove unzipGetcCurrentFile function
|
||||
- replace ZUNZEXPORT by ZEXPORT
|
||||
- add unzGetLocalExtrafield for get the local extrafield info
|
||||
- add a new sample, miniunz.c
|
||||
|
||||
Change in 0.4: (25 Feb 98)
|
||||
- suppress the type unzipFileInZip.
|
||||
Only on file in the zipfile can be open at the same time
|
||||
- fix somes typo in code
|
||||
- added tm_unz structure in unzip_file_info (date/time in readable format)
|
||||
Change in 1.01e (12 feb 05)
|
||||
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
|
||||
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
|
||||
|
||||
Change in 1.01b (20 may 04)
|
||||
- Integrate patch from Debian package (submited by Mark Brown)
|
||||
- Add tools mztools from Xavier Roche
|
||||
|
||||
Change in 1.01 (8 may 04)
|
||||
- fix buffer overrun risk in unzip.c (Xavier Roche)
|
||||
- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
|
||||
|
||||
Change in 1.00: (10 sept 03)
|
||||
- rename to 1.00
|
||||
- cosmetic code change
|
||||
|
||||
Change in 0.22: (19 May 03)
|
||||
- crypting support (unless you define NOCRYPT)
|
||||
- append file in existing zipfile
|
||||
|
||||
Change in 0.21: (10 Mar 03)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.17: (27 Jan 02)
|
||||
- bug fixes
|
||||
|
||||
Change in 0.16: (19 Jan 02)
|
||||
- Support of ioapi for virtualize zip file access
|
||||
|
||||
Change in 0.15: (19 Mar 98)
|
||||
- fix memory leak in minizip.c
|
||||
|
||||
Change in 0.14: (10 Mar 98)
|
||||
- fix bugs in minizip.c sample for zipping big file
|
||||
- fix problem in month in date handling
|
||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
|
||||
comment handling
|
||||
|
||||
Change in 0.13: (6 Mar 98)
|
||||
- fix bugs in zip.c
|
||||
- add real minizip sample
|
||||
|
||||
Change in 0.12: (4 Mar 98)
|
||||
- add zip.c and zip.h for creates .zip file
|
||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
|
||||
- fix miniunz.c for file without specific record for directory
|
||||
|
||||
Change in 0.11: (3 Mar 98)
|
||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment
|
||||
- enhance miniunz sample, remove the bad unztst.c sample
|
||||
|
||||
Change in 0.10: (2 Mar 98)
|
||||
- fix bug in unzReadCurrentFile
|
||||
- rename unzip* to unz* function and structure
|
||||
- remove Windows-like hungary notation variable name
|
||||
- modify some structure in unzip.h
|
||||
- add somes comment in source
|
||||
- remove unzipGetcCurrentFile function
|
||||
- replace ZUNZEXPORT by ZEXPORT
|
||||
- add unzGetLocalExtrafield for get the local extrafield info
|
||||
- add a new sample, miniunz.c
|
||||
|
||||
Change in 0.4: (25 Feb 98)
|
||||
- suppress the type unzipFileInZip.
|
||||
Only on file in the zipfile can be open at the same time
|
||||
- fix somes typo in code
|
||||
- added tm_unz structure in unzip_file_info (date/time in readable format)
|
||||
|
||||
+25
-25
@@ -1,25 +1,25 @@
|
||||
CC=cc
|
||||
CFLAGS=-O -I../..
|
||||
|
||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
all: miniunz minizip
|
||||
|
||||
miniunz: $(UNZ_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||
|
||||
minizip: $(ZIP_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||
|
||||
test: miniunz minizip
|
||||
./minizip test readme.txt
|
||||
./miniunz -l test.zip
|
||||
mv readme.txt readme.old
|
||||
./miniunz test.zip
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o *~ minizip miniunz
|
||||
CC=cc
|
||||
CFLAGS=-O -I../..
|
||||
|
||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
all: miniunz minizip
|
||||
|
||||
miniunz: $(UNZ_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||
|
||||
minizip: $(ZIP_OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||
|
||||
test: miniunz minizip
|
||||
./minizip test readme.txt
|
||||
./miniunz -l test.zip
|
||||
mv readme.txt readme.old
|
||||
./miniunz test.zip
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o *~ minizip miniunz
|
||||
|
||||
+132
-132
@@ -1,132 +1,132 @@
|
||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+177
-177
@@ -1,177 +1,177 @@
|
||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
|
||||
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK fread_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK ftell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK fseek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK fclose_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK ferror_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||
file = fopen(filename, mode_fopen);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
long ret;
|
||||
ret = ftell((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
int fseek_origin=0;
|
||||
long ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
ret = 0;
|
||||
fseek((FILE *)stream, offset, fseek_origin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = fclose((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = ferror((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
|
||||
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK fread_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK ftell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK fseek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK fclose_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK ferror_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||
file = fopen(filename, mode_fopen);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
long ret;
|
||||
ret = ftell((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
int fseek_origin=0;
|
||||
long ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
ret = 0;
|
||||
fseek((FILE *)stream, offset, fseek_origin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = fclose((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = ferror((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
+75
-75
@@ -1,75 +1,75 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+270
-270
@@ -1,270 +1,270 @@
|
||||
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
#include "iowin32.h"
|
||||
|
||||
#ifndef INVALID_HANDLE_VALUE
|
||||
#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK win32_tell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK win32_seek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK win32_close_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK win32_error_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HANDLE hf;
|
||||
int error;
|
||||
} WIN32FILE_IOWIN;
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = 0;
|
||||
voidpf ret=NULL;
|
||||
|
||||
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
|
||||
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
dwShareMode = FILE_SHARE_READ;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = CREATE_ALWAYS;
|
||||
}
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
hFile = NULL;
|
||||
|
||||
if (hFile != NULL)
|
||||
{
|
||||
WIN32FILE_IOWIN w32fiow;
|
||||
w32fiow.hf = hFile;
|
||||
w32fiow.error = 0;
|
||||
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
||||
if (ret==NULL)
|
||||
CloseHandle(hFile);
|
||||
else *((WIN32FILE_IOWIN*)ret) = w32fiow;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
if (dwErr == ERROR_HANDLE_EOF)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
|
||||
if (hFile !=NULL)
|
||||
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
if (dwErr == ERROR_HANDLE_EOF)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_tell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
long ret=-1;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
{
|
||||
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
|
||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret=(long)dwSet;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
DWORD dwMoveMethod=0xFFFFFFFF;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
long ret=-1;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
dwMoveMethod = FILE_CURRENT;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
dwMoveMethod = FILE_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
dwMoveMethod = FILE_BEGIN;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
|
||||
if (hFile != NULL)
|
||||
{
|
||||
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
|
||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_close_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret=-1;
|
||||
|
||||
if (stream!=NULL)
|
||||
{
|
||||
HANDLE hFile;
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
ret=0;
|
||||
}
|
||||
free(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_error_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret=-1;
|
||||
if (stream!=NULL)
|
||||
{
|
||||
ret = ((WIN32FILE_IOWIN*)stream) -> error;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_win32_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque=NULL;
|
||||
}
|
||||
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "ioapi.h"
|
||||
#include "iowin32.h"
|
||||
|
||||
#ifndef INVALID_HANDLE_VALUE
|
||||
#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK win32_tell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK win32_seek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK win32_close_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK win32_error_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HANDLE hf;
|
||||
int error;
|
||||
} WIN32FILE_IOWIN;
|
||||
|
||||
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
const char* mode_fopen = NULL;
|
||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||
HANDLE hFile = 0;
|
||||
voidpf ret=NULL;
|
||||
|
||||
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
|
||||
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
dwShareMode = FILE_SHARE_READ;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = OPEN_EXISTING;
|
||||
}
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
{
|
||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||
dwCreationDisposition = CREATE_ALWAYS;
|
||||
}
|
||||
|
||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
|
||||
dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
hFile = NULL;
|
||||
|
||||
if (hFile != NULL)
|
||||
{
|
||||
WIN32FILE_IOWIN w32fiow;
|
||||
w32fiow.hf = hFile;
|
||||
w32fiow.error = 0;
|
||||
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
||||
if (ret==NULL)
|
||||
CloseHandle(hFile);
|
||||
else *((WIN32FILE_IOWIN*)ret) = w32fiow;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
if (dwErr == ERROR_HANDLE_EOF)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret=0;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
|
||||
if (hFile !=NULL)
|
||||
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
if (dwErr == ERROR_HANDLE_EOF)
|
||||
dwErr = 0;
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_tell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
long ret=-1;
|
||||
HANDLE hFile = NULL;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
{
|
||||
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
|
||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret=(long)dwSet;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
DWORD dwMoveMethod=0xFFFFFFFF;
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
long ret=-1;
|
||||
if (stream!=NULL)
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
dwMoveMethod = FILE_CURRENT;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
dwMoveMethod = FILE_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
dwMoveMethod = FILE_BEGIN;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
|
||||
if (hFile != NULL)
|
||||
{
|
||||
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
|
||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||
{
|
||||
DWORD dwErr = GetLastError();
|
||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
ret=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_close_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret=-1;
|
||||
|
||||
if (stream!=NULL)
|
||||
{
|
||||
HANDLE hFile;
|
||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||
if (hFile != NULL)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
ret=0;
|
||||
}
|
||||
free(stream);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK win32_error_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret=-1;
|
||||
if (stream!=NULL)
|
||||
{
|
||||
ret = ((WIN32FILE_IOWIN*)stream) -> error;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_win32_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||
pzlib_filefunc_def->opaque=NULL;
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+585
-585
File diff suppressed because it is too large
Load Diff
+420
-420
@@ -1,420 +1,420 @@
|
||||
/*
|
||||
minizip.c
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef unix
|
||||
# include <unistd.h>
|
||||
# include <utime.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
#else
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#include "zip.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define USEWIN32IOAPI
|
||||
#include "iowin32.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define WRITEBUFFERSIZE (16384)
|
||||
#define MAXFILENAME (256)
|
||||
|
||||
#ifdef WIN32
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
int ret = 0;
|
||||
{
|
||||
FILETIME ftLocal;
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATA ff32;
|
||||
|
||||
hFind = FindFirstFile(f,&ff32);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
||||
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
|
||||
FindClose(hFind);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#ifdef unix
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
int ret=0;
|
||||
struct stat s; /* results of stat() */
|
||||
struct tm* filedate;
|
||||
time_t tm_t=0;
|
||||
|
||||
if (strcmp(f,"-")!=0)
|
||||
{
|
||||
char name[MAXFILENAME+1];
|
||||
int len = strlen(f);
|
||||
if (len > MAXFILENAME)
|
||||
len = MAXFILENAME;
|
||||
|
||||
strncpy(name, f,MAXFILENAME-1);
|
||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||
name[ MAXFILENAME ] = '\0';
|
||||
|
||||
if (name[len - 1] == '/')
|
||||
name[len - 1] = '\0';
|
||||
/* not all systems allow stat'ing a file with / appended */
|
||||
if (stat(name,&s)==0)
|
||||
{
|
||||
tm_t = s.st_mtime;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
filedate = localtime(&tm_t);
|
||||
|
||||
tmzip->tm_sec = filedate->tm_sec;
|
||||
tmzip->tm_min = filedate->tm_min;
|
||||
tmzip->tm_hour = filedate->tm_hour;
|
||||
tmzip->tm_mday = filedate->tm_mday;
|
||||
tmzip->tm_mon = filedate->tm_mon ;
|
||||
tmzip->tm_year = filedate->tm_year;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
int check_exist_file(filename)
|
||||
const char* filename;
|
||||
{
|
||||
FILE* ftestexist;
|
||||
int ret = 1;
|
||||
ftestexist = fopen(filename,"rb");
|
||||
if (ftestexist==NULL)
|
||||
ret = 0;
|
||||
else
|
||||
fclose(ftestexist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void do_banner()
|
||||
{
|
||||
printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n");
|
||||
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
|
||||
}
|
||||
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
||||
" -o Overwrite existing file.zip\n" \
|
||||
" -a Append to existing file.zip\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n\n");
|
||||
}
|
||||
|
||||
/* calculate the CRC32 of a file,
|
||||
because to encrypt a file, we need known the CRC32 of the file before */
|
||||
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
|
||||
{
|
||||
unsigned long calculate_crc=0;
|
||||
int err=ZIP_OK;
|
||||
FILE * fin = fopen(filenameinzip,"rb");
|
||||
unsigned long size_read = 0;
|
||||
unsigned long total_read = 0;
|
||||
if (fin==NULL)
|
||||
{
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
calculate_crc = crc32(calculate_crc,buf,size_read);
|
||||
total_read += size_read;
|
||||
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
*result_crc=calculate_crc;
|
||||
printf("file %s crc %x\n",filenameinzip,calculate_crc);
|
||||
return err;
|
||||
}
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||
int zipfilenamearg = 0;
|
||||
char filename_try[MAXFILENAME+16];
|
||||
int zipok;
|
||||
int err=0;
|
||||
int size_buf=0;
|
||||
void* buf=NULL;
|
||||
const char* password=NULL;
|
||||
|
||||
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite = 1;
|
||||
if ((c=='a') || (c=='A'))
|
||||
opt_overwrite = 2;
|
||||
if ((c>='0') && (c<='9'))
|
||||
opt_compress_level = c-'0';
|
||||
|
||||
if (((c=='p') || (c=='P')) && (i+1<argc))
|
||||
{
|
||||
password=argv[i+1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (zipfilenamearg == 0)
|
||||
zipfilenamearg = i ;
|
||||
}
|
||||
}
|
||||
|
||||
size_buf = WRITEBUFFERSIZE;
|
||||
buf = (void*)malloc(size_buf);
|
||||
if (buf==NULL)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
return ZIP_INTERNALERROR;
|
||||
}
|
||||
|
||||
if (zipfilenamearg==0)
|
||||
zipok=0;
|
||||
else
|
||||
{
|
||||
int i,len;
|
||||
int dot_found=0;
|
||||
|
||||
zipok = 1 ;
|
||||
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
|
||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||
filename_try[ MAXFILENAME ] = '\0';
|
||||
|
||||
len=(int)strlen(filename_try);
|
||||
for (i=0;i<len;i++)
|
||||
if (filename_try[i]=='.')
|
||||
dot_found=1;
|
||||
|
||||
if (dot_found==0)
|
||||
strcat(filename_try,".zip");
|
||||
|
||||
if (opt_overwrite==2)
|
||||
{
|
||||
/* if the file don't exist, we not append file */
|
||||
if (check_exist_file(filename_try)==0)
|
||||
opt_overwrite=1;
|
||||
}
|
||||
else
|
||||
if (opt_overwrite==0)
|
||||
if (check_exist_file(filename_try)!=0)
|
||||
{
|
||||
char rep=0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
int ret;
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
|
||||
ret = scanf("%1s",answer);
|
||||
if (ret != 1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||
if (rep=='N')
|
||||
zipok = 0;
|
||||
if (rep=='A')
|
||||
opt_overwrite = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (zipok==1)
|
||||
{
|
||||
zipFile zf;
|
||||
int errclose;
|
||||
# ifdef USEWIN32IOAPI
|
||||
zlib_filefunc_def ffunc;
|
||||
fill_win32_filefunc(&ffunc);
|
||||
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
||||
# else
|
||||
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
|
||||
# endif
|
||||
|
||||
if (zf == NULL)
|
||||
{
|
||||
printf("error opening %s\n",filename_try);
|
||||
err= ZIP_ERRNO;
|
||||
}
|
||||
else
|
||||
printf("creating %s\n",filename_try);
|
||||
|
||||
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
|
||||
{
|
||||
if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
|
||||
((argv[i][1]=='o') || (argv[i][1]=='O') ||
|
||||
(argv[i][1]=='a') || (argv[i][1]=='A') ||
|
||||
(argv[i][1]=='p') || (argv[i][1]=='P') ||
|
||||
((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
|
||||
(strlen(argv[i]) == 2)))
|
||||
{
|
||||
FILE * fin;
|
||||
int size_read;
|
||||
const char* filenameinzip = argv[i];
|
||||
zip_fileinfo zi;
|
||||
unsigned long crcFile=0;
|
||||
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||
zi.dosDate = 0;
|
||||
zi.internal_fa = 0;
|
||||
zi.external_fa = 0;
|
||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
||||
|
||||
/*
|
||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL / * comment * /,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level);
|
||||
*/
|
||||
if ((password != NULL) && (err==ZIP_OK))
|
||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||
|
||||
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL /* comment*/,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level,0,
|
||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
password,crcFile);
|
||||
|
||||
if (err != ZIP_OK)
|
||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||
else
|
||||
{
|
||||
fin = fopen(filenameinzip,"rb");
|
||||
if (fin==NULL)
|
||||
{
|
||||
err=ZIP_ERRNO;
|
||||
printf("error in opening %s for reading\n",filenameinzip);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
{
|
||||
err = zipWriteInFileInZip (zf,buf,size_read);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error in writing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
|
||||
}
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
if (err<0)
|
||||
err=ZIP_ERRNO;
|
||||
else
|
||||
{
|
||||
err = zipCloseFileInZip(zf);
|
||||
if (err!=ZIP_OK)
|
||||
printf("error in closing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
}
|
||||
}
|
||||
errclose = zipClose(zf,NULL);
|
||||
if (errclose != ZIP_OK)
|
||||
printf("error in closing %s\n",filename_try);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_help();
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
minizip.c
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef unix
|
||||
# include <unistd.h>
|
||||
# include <utime.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
#else
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#include "zip.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define USEWIN32IOAPI
|
||||
#include "iowin32.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define WRITEBUFFERSIZE (16384)
|
||||
#define MAXFILENAME (256)
|
||||
|
||||
#ifdef WIN32
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
int ret = 0;
|
||||
{
|
||||
FILETIME ftLocal;
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATA ff32;
|
||||
|
||||
hFind = FindFirstFile(f,&ff32);
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
||||
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
|
||||
FindClose(hFind);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#ifdef unix
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
int ret=0;
|
||||
struct stat s; /* results of stat() */
|
||||
struct tm* filedate;
|
||||
time_t tm_t=0;
|
||||
|
||||
if (strcmp(f,"-")!=0)
|
||||
{
|
||||
char name[MAXFILENAME+1];
|
||||
int len = strlen(f);
|
||||
if (len > MAXFILENAME)
|
||||
len = MAXFILENAME;
|
||||
|
||||
strncpy(name, f,MAXFILENAME-1);
|
||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||
name[ MAXFILENAME ] = '\0';
|
||||
|
||||
if (name[len - 1] == '/')
|
||||
name[len - 1] = '\0';
|
||||
/* not all systems allow stat'ing a file with / appended */
|
||||
if (stat(name,&s)==0)
|
||||
{
|
||||
tm_t = s.st_mtime;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
filedate = localtime(&tm_t);
|
||||
|
||||
tmzip->tm_sec = filedate->tm_sec;
|
||||
tmzip->tm_min = filedate->tm_min;
|
||||
tmzip->tm_hour = filedate->tm_hour;
|
||||
tmzip->tm_mday = filedate->tm_mday;
|
||||
tmzip->tm_mon = filedate->tm_mon ;
|
||||
tmzip->tm_year = filedate->tm_year;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
int check_exist_file(filename)
|
||||
const char* filename;
|
||||
{
|
||||
FILE* ftestexist;
|
||||
int ret = 1;
|
||||
ftestexist = fopen(filename,"rb");
|
||||
if (ftestexist==NULL)
|
||||
ret = 0;
|
||||
else
|
||||
fclose(ftestexist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void do_banner()
|
||||
{
|
||||
printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n");
|
||||
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
|
||||
}
|
||||
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
||||
" -o Overwrite existing file.zip\n" \
|
||||
" -a Append to existing file.zip\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n\n");
|
||||
}
|
||||
|
||||
/* calculate the CRC32 of a file,
|
||||
because to encrypt a file, we need known the CRC32 of the file before */
|
||||
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
|
||||
{
|
||||
unsigned long calculate_crc=0;
|
||||
int err=ZIP_OK;
|
||||
FILE * fin = fopen(filenameinzip,"rb");
|
||||
unsigned long size_read = 0;
|
||||
unsigned long total_read = 0;
|
||||
if (fin==NULL)
|
||||
{
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
calculate_crc = crc32(calculate_crc,buf,size_read);
|
||||
total_read += size_read;
|
||||
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
*result_crc=calculate_crc;
|
||||
printf("file %s crc %x\n",filenameinzip,calculate_crc);
|
||||
return err;
|
||||
}
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||
int zipfilenamearg = 0;
|
||||
char filename_try[MAXFILENAME+16];
|
||||
int zipok;
|
||||
int err=0;
|
||||
int size_buf=0;
|
||||
void* buf=NULL;
|
||||
const char* password=NULL;
|
||||
|
||||
|
||||
do_banner();
|
||||
if (argc==1)
|
||||
{
|
||||
do_help();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<argc;i++)
|
||||
{
|
||||
if ((*argv[i])=='-')
|
||||
{
|
||||
const char *p=argv[i]+1;
|
||||
|
||||
while ((*p)!='\0')
|
||||
{
|
||||
char c=*(p++);;
|
||||
if ((c=='o') || (c=='O'))
|
||||
opt_overwrite = 1;
|
||||
if ((c=='a') || (c=='A'))
|
||||
opt_overwrite = 2;
|
||||
if ((c>='0') && (c<='9'))
|
||||
opt_compress_level = c-'0';
|
||||
|
||||
if (((c=='p') || (c=='P')) && (i+1<argc))
|
||||
{
|
||||
password=argv[i+1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (zipfilenamearg == 0)
|
||||
zipfilenamearg = i ;
|
||||
}
|
||||
}
|
||||
|
||||
size_buf = WRITEBUFFERSIZE;
|
||||
buf = (void*)malloc(size_buf);
|
||||
if (buf==NULL)
|
||||
{
|
||||
printf("Error allocating memory\n");
|
||||
return ZIP_INTERNALERROR;
|
||||
}
|
||||
|
||||
if (zipfilenamearg==0)
|
||||
zipok=0;
|
||||
else
|
||||
{
|
||||
int i,len;
|
||||
int dot_found=0;
|
||||
|
||||
zipok = 1 ;
|
||||
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
|
||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||
filename_try[ MAXFILENAME ] = '\0';
|
||||
|
||||
len=(int)strlen(filename_try);
|
||||
for (i=0;i<len;i++)
|
||||
if (filename_try[i]=='.')
|
||||
dot_found=1;
|
||||
|
||||
if (dot_found==0)
|
||||
strcat(filename_try,".zip");
|
||||
|
||||
if (opt_overwrite==2)
|
||||
{
|
||||
/* if the file don't exist, we not append file */
|
||||
if (check_exist_file(filename_try)==0)
|
||||
opt_overwrite=1;
|
||||
}
|
||||
else
|
||||
if (opt_overwrite==0)
|
||||
if (check_exist_file(filename_try)!=0)
|
||||
{
|
||||
char rep=0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
int ret;
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
|
||||
ret = scanf("%1s",answer);
|
||||
if (ret != 1)
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||
if (rep=='N')
|
||||
zipok = 0;
|
||||
if (rep=='A')
|
||||
opt_overwrite = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (zipok==1)
|
||||
{
|
||||
zipFile zf;
|
||||
int errclose;
|
||||
# ifdef USEWIN32IOAPI
|
||||
zlib_filefunc_def ffunc;
|
||||
fill_win32_filefunc(&ffunc);
|
||||
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
||||
# else
|
||||
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
|
||||
# endif
|
||||
|
||||
if (zf == NULL)
|
||||
{
|
||||
printf("error opening %s\n",filename_try);
|
||||
err= ZIP_ERRNO;
|
||||
}
|
||||
else
|
||||
printf("creating %s\n",filename_try);
|
||||
|
||||
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
|
||||
{
|
||||
if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
|
||||
((argv[i][1]=='o') || (argv[i][1]=='O') ||
|
||||
(argv[i][1]=='a') || (argv[i][1]=='A') ||
|
||||
(argv[i][1]=='p') || (argv[i][1]=='P') ||
|
||||
((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
|
||||
(strlen(argv[i]) == 2)))
|
||||
{
|
||||
FILE * fin;
|
||||
int size_read;
|
||||
const char* filenameinzip = argv[i];
|
||||
zip_fileinfo zi;
|
||||
unsigned long crcFile=0;
|
||||
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||
zi.dosDate = 0;
|
||||
zi.internal_fa = 0;
|
||||
zi.external_fa = 0;
|
||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
||||
|
||||
/*
|
||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL / * comment * /,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level);
|
||||
*/
|
||||
if ((password != NULL) && (err==ZIP_OK))
|
||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||
|
||||
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL /* comment*/,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level,0,
|
||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
password,crcFile);
|
||||
|
||||
if (err != ZIP_OK)
|
||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||
else
|
||||
{
|
||||
fin = fopen(filenameinzip,"rb");
|
||||
if (fin==NULL)
|
||||
{
|
||||
err=ZIP_ERRNO;
|
||||
printf("error in opening %s for reading\n",filenameinzip);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
{
|
||||
err = zipWriteInFileInZip (zf,buf,size_read);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error in writing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
|
||||
}
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
if (err<0)
|
||||
err=ZIP_ERRNO;
|
||||
else
|
||||
{
|
||||
err = zipCloseFileInZip(zf);
|
||||
if (err!=ZIP_OK)
|
||||
printf("error in closing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
}
|
||||
}
|
||||
errclose = zipClose(zf,NULL);
|
||||
if (errclose != ZIP_OK)
|
||||
printf("error in closing %s\n",filename_try);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_help();
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+281
-281
@@ -1,281 +1,281 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
/* Code */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zlib.h"
|
||||
#include "unzip.h"
|
||||
|
||||
#define READ_8(adr) ((unsigned char)*(adr))
|
||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||
|
||||
#define WRITE_8(buff, n) do { \
|
||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||
} while(0)
|
||||
#define WRITE_16(buff, n) do { \
|
||||
WRITE_8((unsigned char*)(buff), n); \
|
||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||
} while(0)
|
||||
#define WRITE_32(buff, n) do { \
|
||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||
} while(0)
|
||||
|
||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||
const char* file;
|
||||
const char* fileOut;
|
||||
const char* fileOutTmp;
|
||||
uLong* nRecovered;
|
||||
uLong* bytesRecovered;
|
||||
{
|
||||
int err = Z_OK;
|
||||
FILE* fpZip = fopen(file, "rb");
|
||||
FILE* fpOut = fopen(fileOut, "wb");
|
||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||
if (fpZip != NULL && fpOut != NULL) {
|
||||
int entries = 0;
|
||||
uLong totalBytes = 0;
|
||||
char header[30];
|
||||
char filename[256];
|
||||
char extra[1024];
|
||||
int offset = 0;
|
||||
int offsetCD = 0;
|
||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||
int currentOffset = offset;
|
||||
|
||||
/* File entry */
|
||||
if (READ_32(header) == 0x04034b50) {
|
||||
unsigned int version = READ_16(header + 4);
|
||||
unsigned int gpflag = READ_16(header + 6);
|
||||
unsigned int method = READ_16(header + 8);
|
||||
unsigned int filetime = READ_16(header + 10);
|
||||
unsigned int filedate = READ_16(header + 12);
|
||||
unsigned int crc = READ_32(header + 14); /* crc */
|
||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||
filename[0] = extra[0] = '\0';
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||
offset += 30;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||
offset += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||
offset += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Data */
|
||||
{
|
||||
int dataSize = cpsize;
|
||||
if (dataSize == 0) {
|
||||
dataSize = uncpsize;
|
||||
}
|
||||
if (dataSize > 0) {
|
||||
char* data = malloc(dataSize);
|
||||
if (data != NULL) {
|
||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||
offset += dataSize;
|
||||
totalBytes += dataSize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
free(data);
|
||||
if (err != Z_OK) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_MEM_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Central directory entry */
|
||||
{
|
||||
char header[46];
|
||||
char* comment = "";
|
||||
int comsize = (int) strlen(comment);
|
||||
WRITE_32(header, 0x02014b50);
|
||||
WRITE_16(header + 4, version);
|
||||
WRITE_16(header + 6, version);
|
||||
WRITE_16(header + 8, gpflag);
|
||||
WRITE_16(header + 10, method);
|
||||
WRITE_16(header + 12, filetime);
|
||||
WRITE_16(header + 14, filedate);
|
||||
WRITE_32(header + 16, crc);
|
||||
WRITE_32(header + 20, cpsize);
|
||||
WRITE_32(header + 24, uncpsize);
|
||||
WRITE_16(header + 28, fnsize);
|
||||
WRITE_16(header + 30, extsize);
|
||||
WRITE_16(header + 32, comsize);
|
||||
WRITE_16(header + 34, 0); /* disk # */
|
||||
WRITE_16(header + 36, 0); /* int attrb */
|
||||
WRITE_32(header + 38, 0); /* ext attrb */
|
||||
WRITE_32(header + 42, currentOffset);
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||
offsetCD += 46;
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||
offsetCD += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||
offsetCD += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||
offsetCD += comsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success */
|
||||
entries++;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final central directory */
|
||||
{
|
||||
int entriesZip = entries;
|
||||
char header[22];
|
||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||
int comsize = (int) strlen(comment);
|
||||
if (entriesZip > 0xffff) {
|
||||
entriesZip = 0xffff;
|
||||
}
|
||||
WRITE_32(header, 0x06054b50);
|
||||
WRITE_16(header + 4, 0); /* disk # */
|
||||
WRITE_16(header + 6, 0); /* disk # */
|
||||
WRITE_16(header + 8, entriesZip); /* hack */
|
||||
WRITE_16(header + 10, entriesZip); /* hack */
|
||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||
WRITE_32(header + 16, offset); /* offset to CD */
|
||||
WRITE_16(header + 20, comsize); /* comment */
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final merge (file + central directory) */
|
||||
fclose(fpOutCD);
|
||||
if (err == Z_OK) {
|
||||
fpOutCD = fopen(fileOutTmp, "rb");
|
||||
if (fpOutCD != NULL) {
|
||||
int nRead;
|
||||
char buffer[8192];
|
||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fpOutCD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close */
|
||||
fclose(fpZip);
|
||||
fclose(fpOut);
|
||||
|
||||
/* Wipe temporary file */
|
||||
(void)remove(fileOutTmp);
|
||||
|
||||
/* Number of recovered entries */
|
||||
if (err == Z_OK) {
|
||||
if (nRecovered != NULL) {
|
||||
*nRecovered = entries;
|
||||
}
|
||||
if (bytesRecovered != NULL) {
|
||||
*bytesRecovered = totalBytes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
/* Code */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zlib.h"
|
||||
#include "unzip.h"
|
||||
|
||||
#define READ_8(adr) ((unsigned char)*(adr))
|
||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||
|
||||
#define WRITE_8(buff, n) do { \
|
||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||
} while(0)
|
||||
#define WRITE_16(buff, n) do { \
|
||||
WRITE_8((unsigned char*)(buff), n); \
|
||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||
} while(0)
|
||||
#define WRITE_32(buff, n) do { \
|
||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||
} while(0)
|
||||
|
||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||
const char* file;
|
||||
const char* fileOut;
|
||||
const char* fileOutTmp;
|
||||
uLong* nRecovered;
|
||||
uLong* bytesRecovered;
|
||||
{
|
||||
int err = Z_OK;
|
||||
FILE* fpZip = fopen(file, "rb");
|
||||
FILE* fpOut = fopen(fileOut, "wb");
|
||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||
if (fpZip != NULL && fpOut != NULL) {
|
||||
int entries = 0;
|
||||
uLong totalBytes = 0;
|
||||
char header[30];
|
||||
char filename[256];
|
||||
char extra[1024];
|
||||
int offset = 0;
|
||||
int offsetCD = 0;
|
||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||
int currentOffset = offset;
|
||||
|
||||
/* File entry */
|
||||
if (READ_32(header) == 0x04034b50) {
|
||||
unsigned int version = READ_16(header + 4);
|
||||
unsigned int gpflag = READ_16(header + 6);
|
||||
unsigned int method = READ_16(header + 8);
|
||||
unsigned int filetime = READ_16(header + 10);
|
||||
unsigned int filedate = READ_16(header + 12);
|
||||
unsigned int crc = READ_32(header + 14); /* crc */
|
||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||
filename[0] = extra[0] = '\0';
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||
offset += 30;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||
offset += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||
offset += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Data */
|
||||
{
|
||||
int dataSize = cpsize;
|
||||
if (dataSize == 0) {
|
||||
dataSize = uncpsize;
|
||||
}
|
||||
if (dataSize > 0) {
|
||||
char* data = malloc(dataSize);
|
||||
if (data != NULL) {
|
||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||
offset += dataSize;
|
||||
totalBytes += dataSize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
free(data);
|
||||
if (err != Z_OK) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_MEM_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Central directory entry */
|
||||
{
|
||||
char header[46];
|
||||
char* comment = "";
|
||||
int comsize = (int) strlen(comment);
|
||||
WRITE_32(header, 0x02014b50);
|
||||
WRITE_16(header + 4, version);
|
||||
WRITE_16(header + 6, version);
|
||||
WRITE_16(header + 8, gpflag);
|
||||
WRITE_16(header + 10, method);
|
||||
WRITE_16(header + 12, filetime);
|
||||
WRITE_16(header + 14, filedate);
|
||||
WRITE_32(header + 16, crc);
|
||||
WRITE_32(header + 20, cpsize);
|
||||
WRITE_32(header + 24, uncpsize);
|
||||
WRITE_16(header + 28, fnsize);
|
||||
WRITE_16(header + 30, extsize);
|
||||
WRITE_16(header + 32, comsize);
|
||||
WRITE_16(header + 34, 0); /* disk # */
|
||||
WRITE_16(header + 36, 0); /* int attrb */
|
||||
WRITE_32(header + 38, 0); /* ext attrb */
|
||||
WRITE_32(header + 42, currentOffset);
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||
offsetCD += 46;
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||
offsetCD += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||
offsetCD += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||
offsetCD += comsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success */
|
||||
entries++;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final central directory */
|
||||
{
|
||||
int entriesZip = entries;
|
||||
char header[22];
|
||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||
int comsize = (int) strlen(comment);
|
||||
if (entriesZip > 0xffff) {
|
||||
entriesZip = 0xffff;
|
||||
}
|
||||
WRITE_32(header, 0x06054b50);
|
||||
WRITE_16(header + 4, 0); /* disk # */
|
||||
WRITE_16(header + 6, 0); /* disk # */
|
||||
WRITE_16(header + 8, entriesZip); /* hack */
|
||||
WRITE_16(header + 10, entriesZip); /* hack */
|
||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||
WRITE_32(header + 16, offset); /* offset to CD */
|
||||
WRITE_16(header + 20, comsize); /* comment */
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final merge (file + central directory) */
|
||||
fclose(fpOutCD);
|
||||
if (err == Z_OK) {
|
||||
fpOutCD = fopen(fileOutTmp, "rb");
|
||||
if (fpOutCD != NULL) {
|
||||
int nRead;
|
||||
char buffer[8192];
|
||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fpOutCD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close */
|
||||
fclose(fpZip);
|
||||
fclose(fpOut);
|
||||
|
||||
/* Wipe temporary file */
|
||||
(void)remove(fileOutTmp);
|
||||
|
||||
/* Number of recovered entries */
|
||||
if (err == Z_OK) {
|
||||
if (nRecovered != NULL) {
|
||||
*nRecovered = entries;
|
||||
}
|
||||
if (bytesRecovered != NULL) {
|
||||
*bytesRecovered = totalBytes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
||||
|
||||
+1598
-1598
File diff suppressed because it is too large
Load Diff
+356
-356
@@ -1,356 +1,356 @@
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
"zlib/zlib113.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
/* ****************************************** */
|
||||
/* Ryan supplied functions */
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||
const char* password));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw,
|
||||
const char* password));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _unz_H
|
||||
#define _unz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
"zlib/zlib113.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
/* ****************************************** */
|
||||
/* Ryan supplied functions */
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||
const char* password));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw,
|
||||
const char* password));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz_H */
|
||||
|
||||
+1219
-1219
File diff suppressed because it is too large
Load Diff
+235
-235
@@ -1,235 +1,235 @@
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char* zipcharpc;
|
||||
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||
an Unix computer "zlib/zlib113.zip".
|
||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||
will be created at the end of the file.
|
||||
(useful if the file contain a self extractor code)
|
||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
||||
add files in existing zip (be sure you don't add file that doesn't exist)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
*/
|
||||
|
||||
/* Note : there is no delete function into a zipfile.
|
||||
If you want delete file into a zipfile, you must open a zipfile, and create another
|
||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte
|
||||
*/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCtypting));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCtypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const void* buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
/*
|
||||
Close the current file in the zipfile, for fiel opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
||||
/* zip.h -- IO for compress .zip files using zlib
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||
WinZip, InfoZip tools and compatible.
|
||||
Multi volume ZipFile (span) are not supported.
|
||||
Encryption compatible with pkzip 2.04g only supported
|
||||
Old compressions used by old PKZip 1.x are not supported
|
||||
|
||||
For uncompress .zip file, look at unzip.h
|
||||
|
||||
|
||||
I WAIT FEEDBACK at mail info@winimage.com
|
||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* for more info about .ZIP format, see
|
||||
http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
||||
http://www.info-zip.org/pub/infozip/doc/
|
||||
PkWare has also a specification at :
|
||||
ftp://ftp.pkware.com/probdesc.zip
|
||||
*/
|
||||
|
||||
#ifndef _zip_H
|
||||
#define _zip_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char* zipcharpc;
|
||||
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||
an Unix computer "zlib/zlib113.zip".
|
||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||
will be created at the end of the file.
|
||||
(useful if the file contain a self extractor code)
|
||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
||||
add files in existing zip (be sure you don't add file that doesn't exist)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
*/
|
||||
|
||||
/* Note : there is no delete function into a zipfile.
|
||||
If you want delete file into a zipfile, you must open a zipfile, and create another
|
||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte
|
||||
*/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCtypting));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCtypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const void* buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
/*
|
||||
Close the current file in the zipfile, for fiel opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip_H */
|
||||
|
||||
+275
-275
@@ -1,275 +1,275 @@
|
||||
/*
|
||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||
* -----------------------------------------------------------------------
|
||||
* Licensed under GPL
|
||||
*
|
||||
* vram.c - Standard C high performance VRAM allocation routines.
|
||||
*
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "vram.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// Configure the memory to be managed
|
||||
#define __MEM_SIZE 0x00200000
|
||||
#define __MEM_START 0x04000000
|
||||
|
||||
// Configure the block size the memory gets subdivided into (page size)
|
||||
// __MEM_SIZE/__BLOCK_SIZE may not exceed 2^15 = 32768
|
||||
// The block size also defines the alignment of allocations
|
||||
// Larger block sizes perform better, because the blocktable is smaller and therefore fits better into cache
|
||||
// however the overhead is also bigger and more memory is wasted
|
||||
#define __BLOCK_SIZE 512
|
||||
#define __MEM_BLOCKS (__MEM_SIZE/__BLOCK_SIZE)
|
||||
#define __BLOCKS(x) ((x+__BLOCK_SIZE-1)/__BLOCK_SIZE)
|
||||
#define __BLOCKSIZE(x) ((x+__BLOCK_SIZE-1)&~(__BLOCK_SIZE-1))
|
||||
|
||||
|
||||
// A MEMORY BLOCK ENTRY IS MADE UP LIKE THAT:
|
||||
// bit: 31 32 30 - 15 14-0
|
||||
// free block prev size
|
||||
//
|
||||
// bit 31: free bit, indicating if block is allocated or not
|
||||
// bit 30: blocked bit, indicating if block is part of a larger block (0) - used for error resilience
|
||||
// bit 30-15: block index of previous block
|
||||
// bit 14- 0: size of current block
|
||||
//
|
||||
// This management can handle a max amount of 2^15 = 32768 blocks, which resolves to 32MB at blocksize of 1024 bytes
|
||||
//
|
||||
#define __BLOCK_GET_SIZE(x) ((x & 0x7FFF))
|
||||
#define __BLOCK_GET_PREV(x) ((x >> 15) & 0x7FFF)
|
||||
#define __BLOCK_GET_FREE(x) ((x >> 31))
|
||||
#define __BLOCK_GET_BLOCK(x) ((x >> 30) & 0x1)
|
||||
#define __BLOCK_SET_SIZE(x,y) x=((x & ~0x7FFF) | ((y) & 0x7FFF))
|
||||
#define __BLOCK_ADD_SIZE(x,y) x=((x & ~0x7FFF) | (((x & 0x7FFF)+((y) & 0x7FFF)) & 0x7FFF))
|
||||
#define __BLOCK_SET_PREV(x,y) x=((x & ~0x3FFF8000) | (((y) & 0x7FFF)<<15))
|
||||
#define __BLOCK_SET_FREE(x,y) x=((x & 0x7FFFFFFF) | (((y) & 0x1)<<31))
|
||||
#define __BLOCK_SET_BLOCK(x,y) x=((x & 0xBFFFFFFF) | (((y) & 0x1)<<30))
|
||||
#define __BLOCK_MAKE(s,p,f,n) (((f & 0x1)<<31) | ((n & 0x1)<<30) | (((p) & 0x7FFF)<<15) | ((s) & 0x7FFF))
|
||||
#define __BLOCK_GET_FREEBLOCK(x) ((x>>30) & 0x3) // returns 11b if block is a starting block and free, 10b if block is a starting block and allocated, 0xb if it is a non-starting block (don't change)
|
||||
#define __BLOCK0 ((__MEM_BLOCKS) | (1<<31) | (1<<30))
|
||||
|
||||
|
||||
unsigned int __mem_blocks[__MEM_BLOCKS] = { 0 };
|
||||
|
||||
|
||||
static int __largest_update = 0;
|
||||
static int __largest_block = __MEM_BLOCKS;
|
||||
static int __mem_free = __MEM_BLOCKS;
|
||||
|
||||
|
||||
inline void* vrelptr( void *ptr )
|
||||
{
|
||||
return (void*)((unsigned int)ptr & ~__MEM_START);
|
||||
}
|
||||
|
||||
inline void* vabsptr( void *ptr )
|
||||
{
|
||||
return (void*)((unsigned int)ptr | __MEM_START);
|
||||
}
|
||||
|
||||
|
||||
static void __find_largest_block()
|
||||
{
|
||||
int i = 0;
|
||||
__largest_block = 0;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>__largest_block)
|
||||
__largest_block = csize;
|
||||
i += csize;
|
||||
}
|
||||
__largest_update = 0;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void __memwalk()
|
||||
{
|
||||
int i = 0;
|
||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
printf("BLOCK %i:\n", i);
|
||||
printf(" free: %i\n", __BLOCK_GET_FREEBLOCK(__mem_blocks[i]));
|
||||
printf(" size: %i\n", __BLOCK_GET_SIZE(__mem_blocks[i]));
|
||||
printf(" prev: %i\n", __BLOCK_GET_PREV(__mem_blocks[i]));
|
||||
i+=__BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void* valloc( size_t size )
|
||||
{
|
||||
// Initialize memory block, if not yet done
|
||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int bsize = __BLOCKS(size);
|
||||
|
||||
if (__largest_update==0 && __largest_block<bsize)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("allocating %i bytes, in %i blocks\n", size, bsize);
|
||||
#endif
|
||||
// Find smallest block that still fits the requested size
|
||||
int bestblock = -1;
|
||||
int bestblock_prev = 0;
|
||||
int bestblock_size = __MEM_BLOCKS+1;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>=bsize)
|
||||
{
|
||||
if (csize<bestblock_size)
|
||||
{
|
||||
bestblock = i;
|
||||
bestblock_prev = j;
|
||||
bestblock_size = csize;
|
||||
}
|
||||
|
||||
if (csize==bsize)
|
||||
break;
|
||||
}
|
||||
j = i;
|
||||
i += csize;
|
||||
}
|
||||
|
||||
if (bestblock<0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
i = bestblock;
|
||||
j = bestblock_prev;
|
||||
int csize = bestblock_size;
|
||||
__mem_blocks[i] = __BLOCK_MAKE(bsize,j,0,1);
|
||||
|
||||
int next = i+bsize;
|
||||
if (csize>bsize && next<__MEM_BLOCKS)
|
||||
{
|
||||
__mem_blocks[next] = __BLOCK_MAKE(csize-bsize,i,1,1);
|
||||
int nextnext = i+csize;
|
||||
if (nextnext<__MEM_BLOCKS)
|
||||
{
|
||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], next);
|
||||
}
|
||||
}
|
||||
|
||||
__mem_free -= bsize;
|
||||
if (__largest_block==csize) // if we just allocated from one of the largest blocks
|
||||
{
|
||||
if ((csize-bsize)>(__mem_free/2))
|
||||
__largest_block = (csize-bsize); // there can't be another largest block
|
||||
else
|
||||
__largest_update = 1;
|
||||
}
|
||||
return ((void*)(__MEM_START + (i*__BLOCK_SIZE)));
|
||||
}
|
||||
|
||||
|
||||
void vfree( void* ptr )
|
||||
{
|
||||
if (ptr==0) return;
|
||||
|
||||
int block = ((unsigned int)ptr - __MEM_START)/__BLOCK_SIZE;
|
||||
if (block<0 || block>__MEM_BLOCKS)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Block is out of range: %i (0x%x)\n", block, (int)ptr);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
||||
#ifdef _DEBUG
|
||||
printf("freeing block %i (0x%x), size: %i\n", block, (int)ptr, csize);
|
||||
#endif
|
||||
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[block])!=1 || csize==0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Block was not allocated!\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark block as free
|
||||
__BLOCK_SET_FREE(__mem_blocks[block],1);
|
||||
__mem_free += csize;
|
||||
|
||||
int next = block+csize;
|
||||
// Merge with previous block if possible
|
||||
int prev = __BLOCK_GET_PREV(__mem_blocks[block]);
|
||||
if (prev<block)
|
||||
{
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[prev])==3)
|
||||
{
|
||||
__BLOCK_ADD_SIZE(__mem_blocks[prev], csize);
|
||||
__BLOCK_SET_BLOCK(__mem_blocks[block],0); // mark current block as inter block
|
||||
if (next<__MEM_BLOCKS)
|
||||
__BLOCK_SET_PREV(__mem_blocks[next], prev);
|
||||
block = prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge with next block if possible
|
||||
if (next<__MEM_BLOCKS)
|
||||
{
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[next])==3)
|
||||
{
|
||||
__BLOCK_ADD_SIZE(__mem_blocks[block], __BLOCK_GET_SIZE(__mem_blocks[next]));
|
||||
__BLOCK_SET_BLOCK(__mem_blocks[next],0); // mark next block as inter block
|
||||
int nextnext = next + __BLOCK_GET_SIZE(__mem_blocks[next]);
|
||||
if (nextnext<__MEM_BLOCKS)
|
||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], block);
|
||||
}
|
||||
}
|
||||
|
||||
// Update if a new largest block emerged
|
||||
if (__largest_block<__BLOCK_GET_SIZE(__mem_blocks[block]))
|
||||
{
|
||||
__largest_block = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
||||
__largest_update = 0; // No update necessary any more, because update only necessary when largest has shrinked at most
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t vmemavail()
|
||||
{
|
||||
return __mem_free * __BLOCK_SIZE;
|
||||
}
|
||||
|
||||
|
||||
size_t vlargestblock()
|
||||
{
|
||||
if (__largest_update) __find_largest_block();
|
||||
return __largest_block * __BLOCK_SIZE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||
* -----------------------------------------------------------------------
|
||||
* Licensed under GPL
|
||||
*
|
||||
* vram.c - Standard C high performance VRAM allocation routines.
|
||||
*
|
||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||
* http://wordpress.fx-world.org
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "vram.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// Configure the memory to be managed
|
||||
#define __MEM_SIZE 0x00200000
|
||||
#define __MEM_START 0x04000000
|
||||
|
||||
// Configure the block size the memory gets subdivided into (page size)
|
||||
// __MEM_SIZE/__BLOCK_SIZE may not exceed 2^15 = 32768
|
||||
// The block size also defines the alignment of allocations
|
||||
// Larger block sizes perform better, because the blocktable is smaller and therefore fits better into cache
|
||||
// however the overhead is also bigger and more memory is wasted
|
||||
#define __BLOCK_SIZE 512
|
||||
#define __MEM_BLOCKS (__MEM_SIZE/__BLOCK_SIZE)
|
||||
#define __BLOCKS(x) ((x+__BLOCK_SIZE-1)/__BLOCK_SIZE)
|
||||
#define __BLOCKSIZE(x) ((x+__BLOCK_SIZE-1)&~(__BLOCK_SIZE-1))
|
||||
|
||||
|
||||
// A MEMORY BLOCK ENTRY IS MADE UP LIKE THAT:
|
||||
// bit: 31 32 30 - 15 14-0
|
||||
// free block prev size
|
||||
//
|
||||
// bit 31: free bit, indicating if block is allocated or not
|
||||
// bit 30: blocked bit, indicating if block is part of a larger block (0) - used for error resilience
|
||||
// bit 30-15: block index of previous block
|
||||
// bit 14- 0: size of current block
|
||||
//
|
||||
// This management can handle a max amount of 2^15 = 32768 blocks, which resolves to 32MB at blocksize of 1024 bytes
|
||||
//
|
||||
#define __BLOCK_GET_SIZE(x) ((x & 0x7FFF))
|
||||
#define __BLOCK_GET_PREV(x) ((x >> 15) & 0x7FFF)
|
||||
#define __BLOCK_GET_FREE(x) ((x >> 31))
|
||||
#define __BLOCK_GET_BLOCK(x) ((x >> 30) & 0x1)
|
||||
#define __BLOCK_SET_SIZE(x,y) x=((x & ~0x7FFF) | ((y) & 0x7FFF))
|
||||
#define __BLOCK_ADD_SIZE(x,y) x=((x & ~0x7FFF) | (((x & 0x7FFF)+((y) & 0x7FFF)) & 0x7FFF))
|
||||
#define __BLOCK_SET_PREV(x,y) x=((x & ~0x3FFF8000) | (((y) & 0x7FFF)<<15))
|
||||
#define __BLOCK_SET_FREE(x,y) x=((x & 0x7FFFFFFF) | (((y) & 0x1)<<31))
|
||||
#define __BLOCK_SET_BLOCK(x,y) x=((x & 0xBFFFFFFF) | (((y) & 0x1)<<30))
|
||||
#define __BLOCK_MAKE(s,p,f,n) (((f & 0x1)<<31) | ((n & 0x1)<<30) | (((p) & 0x7FFF)<<15) | ((s) & 0x7FFF))
|
||||
#define __BLOCK_GET_FREEBLOCK(x) ((x>>30) & 0x3) // returns 11b if block is a starting block and free, 10b if block is a starting block and allocated, 0xb if it is a non-starting block (don't change)
|
||||
#define __BLOCK0 ((__MEM_BLOCKS) | (1<<31) | (1<<30))
|
||||
|
||||
|
||||
unsigned int __mem_blocks[__MEM_BLOCKS] = { 0 };
|
||||
|
||||
|
||||
static int __largest_update = 0;
|
||||
static int __largest_block = __MEM_BLOCKS;
|
||||
static int __mem_free = __MEM_BLOCKS;
|
||||
|
||||
|
||||
inline void* vrelptr( void *ptr )
|
||||
{
|
||||
return (void*)((unsigned int)ptr & ~__MEM_START);
|
||||
}
|
||||
|
||||
inline void* vabsptr( void *ptr )
|
||||
{
|
||||
return (void*)((unsigned int)ptr | __MEM_START);
|
||||
}
|
||||
|
||||
|
||||
static void __find_largest_block()
|
||||
{
|
||||
int i = 0;
|
||||
__largest_block = 0;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>__largest_block)
|
||||
__largest_block = csize;
|
||||
i += csize;
|
||||
}
|
||||
__largest_update = 0;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void __memwalk()
|
||||
{
|
||||
int i = 0;
|
||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
printf("BLOCK %i:\n", i);
|
||||
printf(" free: %i\n", __BLOCK_GET_FREEBLOCK(__mem_blocks[i]));
|
||||
printf(" size: %i\n", __BLOCK_GET_SIZE(__mem_blocks[i]));
|
||||
printf(" prev: %i\n", __BLOCK_GET_PREV(__mem_blocks[i]));
|
||||
i+=__BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void* valloc( size_t size )
|
||||
{
|
||||
// Initialize memory block, if not yet done
|
||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int bsize = __BLOCKS(size);
|
||||
|
||||
if (__largest_update==0 && __largest_block<bsize)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("allocating %i bytes, in %i blocks\n", size, bsize);
|
||||
#endif
|
||||
// Find smallest block that still fits the requested size
|
||||
int bestblock = -1;
|
||||
int bestblock_prev = 0;
|
||||
int bestblock_size = __MEM_BLOCKS+1;
|
||||
while (i<__MEM_BLOCKS)
|
||||
{
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>=bsize)
|
||||
{
|
||||
if (csize<bestblock_size)
|
||||
{
|
||||
bestblock = i;
|
||||
bestblock_prev = j;
|
||||
bestblock_size = csize;
|
||||
}
|
||||
|
||||
if (csize==bsize)
|
||||
break;
|
||||
}
|
||||
j = i;
|
||||
i += csize;
|
||||
}
|
||||
|
||||
if (bestblock<0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
|
||||
i = bestblock;
|
||||
j = bestblock_prev;
|
||||
int csize = bestblock_size;
|
||||
__mem_blocks[i] = __BLOCK_MAKE(bsize,j,0,1);
|
||||
|
||||
int next = i+bsize;
|
||||
if (csize>bsize && next<__MEM_BLOCKS)
|
||||
{
|
||||
__mem_blocks[next] = __BLOCK_MAKE(csize-bsize,i,1,1);
|
||||
int nextnext = i+csize;
|
||||
if (nextnext<__MEM_BLOCKS)
|
||||
{
|
||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], next);
|
||||
}
|
||||
}
|
||||
|
||||
__mem_free -= bsize;
|
||||
if (__largest_block==csize) // if we just allocated from one of the largest blocks
|
||||
{
|
||||
if ((csize-bsize)>(__mem_free/2))
|
||||
__largest_block = (csize-bsize); // there can't be another largest block
|
||||
else
|
||||
__largest_update = 1;
|
||||
}
|
||||
return ((void*)(__MEM_START + (i*__BLOCK_SIZE)));
|
||||
}
|
||||
|
||||
|
||||
void vfree( void* ptr )
|
||||
{
|
||||
if (ptr==0) return;
|
||||
|
||||
int block = ((unsigned int)ptr - __MEM_START)/__BLOCK_SIZE;
|
||||
if (block<0 || block>__MEM_BLOCKS)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Block is out of range: %i (0x%x)\n", block, (int)ptr);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
||||
#ifdef _DEBUG
|
||||
printf("freeing block %i (0x%x), size: %i\n", block, (int)ptr, csize);
|
||||
#endif
|
||||
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[block])!=1 || csize==0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
printf("Block was not allocated!\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark block as free
|
||||
__BLOCK_SET_FREE(__mem_blocks[block],1);
|
||||
__mem_free += csize;
|
||||
|
||||
int next = block+csize;
|
||||
// Merge with previous block if possible
|
||||
int prev = __BLOCK_GET_PREV(__mem_blocks[block]);
|
||||
if (prev<block)
|
||||
{
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[prev])==3)
|
||||
{
|
||||
__BLOCK_ADD_SIZE(__mem_blocks[prev], csize);
|
||||
__BLOCK_SET_BLOCK(__mem_blocks[block],0); // mark current block as inter block
|
||||
if (next<__MEM_BLOCKS)
|
||||
__BLOCK_SET_PREV(__mem_blocks[next], prev);
|
||||
block = prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge with next block if possible
|
||||
if (next<__MEM_BLOCKS)
|
||||
{
|
||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[next])==3)
|
||||
{
|
||||
__BLOCK_ADD_SIZE(__mem_blocks[block], __BLOCK_GET_SIZE(__mem_blocks[next]));
|
||||
__BLOCK_SET_BLOCK(__mem_blocks[next],0); // mark next block as inter block
|
||||
int nextnext = next + __BLOCK_GET_SIZE(__mem_blocks[next]);
|
||||
if (nextnext<__MEM_BLOCKS)
|
||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], block);
|
||||
}
|
||||
}
|
||||
|
||||
// Update if a new largest block emerged
|
||||
if (__largest_block<__BLOCK_GET_SIZE(__mem_blocks[block]))
|
||||
{
|
||||
__largest_block = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
||||
__largest_update = 0; // No update necessary any more, because update only necessary when largest has shrinked at most
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t vmemavail()
|
||||
{
|
||||
return __mem_free * __BLOCK_SIZE;
|
||||
}
|
||||
|
||||
|
||||
size_t vlargestblock()
|
||||
{
|
||||
if (__largest_update) __find_largest_block();
|
||||
return __largest_block * __BLOCK_SIZE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user