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
|
#ifndef DEBUGROUTINES_H
|
||||||
#define DEBUGROUTINES_H
|
#define DEBUGROUTINES_H
|
||||||
|
|
||||||
// dirty, but I get OS header includes this way
|
// dirty, but I get OS header includes this way
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX)
|
#if defined (WIN32) || defined (LINUX)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string ToHex(T* pointer)
|
std::string ToHex(T* pointer)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << std::hex << showbase << setfill('0') << setw(8) << (int) pointer;
|
stream << std::hex << showbase << setfill('0') << setw(8) << (int) pointer;
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef QT_CONFIG
|
#ifndef QT_CONFIG
|
||||||
#define DebugTrace(inString) \
|
#define DebugTrace(inString) \
|
||||||
{ \
|
{ \
|
||||||
std::ostringstream stream; \
|
std::ostringstream stream; \
|
||||||
stream << inString << std::endl; \
|
stream << inString << std::endl; \
|
||||||
OutputDebugString(stream.str().c_str()); \
|
OutputDebugString(stream.str().c_str()); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define DebugTrace(inString) \
|
#define DebugTrace(inString) \
|
||||||
{ \
|
{ \
|
||||||
std::ostringstream stream; \
|
std::ostringstream stream; \
|
||||||
stream << inString << std::endl; \
|
stream << inString << std::endl; \
|
||||||
qDebug(stream.str().c_str()); \
|
qDebug(stream.str().c_str()); \
|
||||||
}
|
}
|
||||||
#endif //QT_CONFIG
|
#endif //QT_CONFIG
|
||||||
|
|
||||||
#endif //#ifdef _DEBUG
|
#endif //#ifdef _DEBUG
|
||||||
#endif // Win32, Linux
|
#endif // Win32, Linux
|
||||||
|
|
||||||
#if defined (IOS) && defined (DEBUG)
|
#if defined (IOS) && defined (DEBUG)
|
||||||
#define DebugTrace(inString) \
|
#define DebugTrace(inString) \
|
||||||
{ \
|
{ \
|
||||||
std::cout << inString << std::endl; \
|
std::cout << inString << std::endl; \
|
||||||
}
|
}
|
||||||
#endif // IOS, DEBUG
|
#endif // IOS, DEBUG
|
||||||
|
|
||||||
|
|
||||||
#ifndef DebugTrace
|
#ifndef DebugTrace
|
||||||
#define DebugTrace(inString) (void (0))
|
#define DebugTrace(inString) (void (0))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // DEBUGROUTINES_H
|
#endif // DEBUGROUTINES_H
|
||||||
|
|||||||
+20
-20
@@ -1,20 +1,20 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _ENCODING_H
|
#ifndef _ENCODING_H
|
||||||
#define _ENCODING_H
|
#define _ENCODING_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "../../JGE/include/JGE.h"
|
#include "../../JGE/include/JGE.h"
|
||||||
|
|
||||||
u16 charsets_gbk_to_ucs(const u8 * cjk);
|
u16 charsets_gbk_to_ucs(const u8 * cjk);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+414
-414
@@ -1,414 +1,414 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JANIMATOR_H_
|
#ifndef _JANIMATOR_H_
|
||||||
#define _JANIMATOR_H_
|
#define _JANIMATOR_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
class JResourceManager;
|
class JResourceManager;
|
||||||
class JQuad;
|
class JQuad;
|
||||||
class JAnimatorFrame;
|
class JAnimatorFrame;
|
||||||
class JAnimatorObject;
|
class JAnimatorObject;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// A frame based animation system. The animation frames and play sequence
|
/// A frame based animation system. The animation frames and play sequence
|
||||||
/// are loaded from a XML file.
|
/// are loaded from a XML file.
|
||||||
///
|
///
|
||||||
/// A sample animation script:
|
/// A sample animation script:
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// <?xml version="1.0" standalone="no" ?>
|
/// <?xml version="1.0" standalone="no" ?>
|
||||||
///
|
///
|
||||||
/// <script name="abc" type="ANIMATION_TYPE_ONCE_AND_STAY" framerate="20">
|
/// <script name="abc" type="ANIMATION_TYPE_ONCE_AND_STAY" framerate="20">
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
/// "type" can be ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY,
|
/// "type" can be ANIMATION_TYPE_LOOPING, ANIMATION_TYPE_ONCE_AND_STAY,
|
||||||
/// ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE or
|
/// ANIMATION_TYPE_ONCE_AND_BACK, ANIMATION_TYPE_ONCE_AND_GONE or
|
||||||
/// ANIMATION_TYPE_PINGPONG
|
/// ANIMATION_TYPE_PINGPONG
|
||||||
///
|
///
|
||||||
/// "framerate" is the rate of playback in frames per seconds.
|
/// "framerate" is the rate of playback in frames per seconds.
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// <frame id="1">
|
/// <frame id="1">
|
||||||
/// <obj name="head">
|
/// <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" />
|
/// <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>
|
||||||
/// <obj name="body">
|
/// <obj name="body">
|
||||||
/// <settings quad="body" />
|
/// <settings quad="body" />
|
||||||
/// </obj>
|
/// </obj>
|
||||||
/// </frame>
|
/// </frame>
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
/// Each frame contains one or more frame objects. Each object is a quad with various
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// of the quad with the "r", "g", "b" and "a" parameters.
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// <frame id="2" time="0.20">
|
/// <frame id="2" time="0.20">
|
||||||
/// <obj name="head">
|
/// <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" />
|
/// <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>
|
||||||
/// <obj name="body">
|
/// <obj name="body">
|
||||||
/// <settings quad="body" a="128" />
|
/// <settings quad="body" a="128" />
|
||||||
/// </obj>
|
/// </obj>
|
||||||
/// </frame>
|
/// </frame>
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// </script>
|
/// </script>
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
/// A frame can also overide the global frame rate by using the "time" parameter (in second)
|
/// A frame can also overide the global frame rate by using the "time" parameter (in second)
|
||||||
/// as shown above.
|
/// as shown above.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JAnimator
|
class JAnimator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param resourceMgr - ResourceManager to look for images (JQuads)
|
/// @param resourceMgr - ResourceManager to look for images (JQuads)
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimator(JResourceManager* resourceMgr);
|
JAnimator(JResourceManager* resourceMgr);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Destructor.
|
/// Destructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
~JAnimator();
|
~JAnimator();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load animation sequence from a script file.
|
/// Load animation sequence from a script file.
|
||||||
///
|
///
|
||||||
/// @param scriptFile - Animation script.
|
/// @param scriptFile - Animation script.
|
||||||
///
|
///
|
||||||
/// @return True if no problem during loading. False otherwise.
|
/// @return True if no problem during loading. False otherwise.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(const char* scriptFile);
|
bool Load(const char* scriptFile);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start animation.
|
/// Start animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Stop animation.
|
/// Stop animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Pause animation.
|
/// Pause animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Pause();
|
void Pause();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Resume animation.
|
/// Resume animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Resume();
|
void Resume();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update animation.
|
/// Update animation.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elapsed since last update (in second).
|
/// @param dt - Time elapsed since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render animation.
|
/// Render animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if animation is playing or not.
|
/// Check if animation is playing or not.
|
||||||
///
|
///
|
||||||
/// @return True if playing animation.
|
/// @return True if playing animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsAnimating();
|
bool IsAnimating();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if the animation is active.
|
/// Check if the animation is active.
|
||||||
///
|
///
|
||||||
/// @return True if active.
|
/// @return True if active.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsActive();
|
bool IsActive();
|
||||||
|
|
||||||
JResourceManager* GetResourceManager();
|
JResourceManager* GetResourceManager();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set current frame to a particular index.
|
/// Set current frame to a particular index.
|
||||||
///
|
///
|
||||||
/// @param index - The new index of current frame.
|
/// @param index - The new index of current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetCurrentFrameIndex(int index);
|
void SetCurrentFrameIndex(int index);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get index of current frame.
|
/// Get index of current frame.
|
||||||
///
|
///
|
||||||
/// @return Index of current frame.
|
/// @return Index of current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetCurrentFrameIndex();
|
int GetCurrentFrameIndex();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set animation type.
|
/// Set animation type.
|
||||||
///
|
///
|
||||||
/// @param type - Animation type.
|
/// @param type - Animation type.
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// JSprite::ANIMATION_TYPE_LOOPING - Default
|
/// JSprite::ANIMATION_TYPE_LOOPING - Default
|
||||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_GONE
|
/// JSprite::ANIMATION_TYPE_ONCE_AND_GONE
|
||||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_STAY
|
/// JSprite::ANIMATION_TYPE_ONCE_AND_STAY
|
||||||
/// JSprite::ANIMATION_TYPE_ONCE_AND_BACK
|
/// JSprite::ANIMATION_TYPE_ONCE_AND_BACK
|
||||||
/// JSprite::ANIMATION_TYPE_PINGPONG
|
/// JSprite::ANIMATION_TYPE_PINGPONG
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetAnimationType(int type);
|
void SetAnimationType(int type);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set position of the sprite.
|
/// Set position of the sprite.
|
||||||
///
|
///
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set anchor point of the animation. All rendering operations will be
|
/// Set anchor point of the animation. All rendering operations will be
|
||||||
/// based on this anchor point.
|
/// based on this anchor point.
|
||||||
///
|
///
|
||||||
/// @param x - X position of the anchor point.
|
/// @param x - X position of the anchor point.
|
||||||
/// @param y - Y position of the anchor point.
|
/// @param y - Y position of the anchor point.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetHotSpot(float x, float y);
|
void SetHotSpot(float x, float y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JResourceManager* mResource;
|
JResourceManager* mResource;
|
||||||
vector<JAnimatorFrame *> mFrames;
|
vector<JAnimatorFrame *> mFrames;
|
||||||
|
|
||||||
bool mAnimating;
|
bool mAnimating;
|
||||||
bool mActive;
|
bool mActive;
|
||||||
int mCurrentFrame;
|
int mCurrentFrame;
|
||||||
int mAnimationType;
|
int mAnimationType;
|
||||||
int mFrameDelta;
|
int mFrameDelta;
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
float mHotSpotX;
|
float mHotSpotX;
|
||||||
float mHotSpotY;
|
float mHotSpotY;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// A single frame of an animation.
|
/// A single frame of an animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JAnimatorFrame
|
class JAnimatorFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param parent - Parent of the frame.
|
/// @param parent - Parent of the frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimatorFrame(JAnimator* parent);
|
JAnimatorFrame(JAnimator* parent);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Destructor.
|
/// Destructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
~JAnimatorFrame();
|
~JAnimatorFrame();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Add a new object into the frame.
|
/// Add a new object into the frame.
|
||||||
///
|
///
|
||||||
/// @param obj - New animation object.
|
/// @param obj - New animation object.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void AddObject(JAnimatorObject *obj);
|
void AddObject(JAnimatorObject *obj);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set play time of the frame.
|
/// Set play time of the frame.
|
||||||
///
|
///
|
||||||
/// @param duration - Time to play (in second).
|
/// @param duration - Time to play (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetFrameTime(float duration);
|
void SetFrameTime(float duration);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Frame update.
|
/// Frame update.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elapsed since last update (in second).
|
/// @param dt - Time elapsed since last update (in second).
|
||||||
///
|
///
|
||||||
/// @return True if the frame is done.
|
/// @return True if the frame is done.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Update(float dt);
|
bool Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render frame.
|
/// Render frame.
|
||||||
///
|
///
|
||||||
/// @param x - X position for rendering.
|
/// @param x - X position for rendering.
|
||||||
/// @param y - Y position for rendering.
|
/// @param y - Y position for rendering.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render(float x, float y);
|
void Render(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start playing the frame.
|
/// Start playing the frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float mTimer;
|
float mTimer;
|
||||||
float mFrameTime;
|
float mFrameTime;
|
||||||
JAnimator* mAnimator;
|
JAnimator* mAnimator;
|
||||||
vector<JAnimatorObject *> mObjects;
|
vector<JAnimatorObject *> mObjects;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Animation object (image quad) in a frame.
|
/// Animation object (image quad) in a frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JAnimatorObject
|
class JAnimatorObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimatorObject();
|
JAnimatorObject();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Destructor.
|
/// Destructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
~JAnimatorObject();
|
~JAnimatorObject();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update object.
|
/// Update object.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elapsed since last update (in second).
|
/// @param dt - Time elapsed since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render object.
|
/// Render object.
|
||||||
///
|
///
|
||||||
/// @param x - X position for rendering.
|
/// @param x - X position for rendering.
|
||||||
/// @param y - Y position for rendering.
|
/// @param y - Y position for rendering.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render(float x, float y);
|
void Render(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set something to show.
|
/// Set something to show.
|
||||||
///
|
///
|
||||||
/// @param quad - Image quad.
|
/// @param quad - Image quad.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetQuad(JQuad *quad);
|
void SetQuad(JQuad *quad);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set position of the object.
|
/// Set position of the object.
|
||||||
///
|
///
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set rotation factor of the object.
|
/// Set rotation factor of the object.
|
||||||
///
|
///
|
||||||
/// @param angle - Rotation angle in radian.
|
/// @param angle - Rotation angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetRotation(float angle);
|
void SetRotation(float angle);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set horizontal scale of the object.
|
/// Set horizontal scale of the object.
|
||||||
///
|
///
|
||||||
/// @param scale - Horizontal scale.
|
/// @param scale - Horizontal scale.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetHScale(float scale);
|
void SetHScale(float scale);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set vertical scale of the object.
|
/// Set vertical scale of the object.
|
||||||
///
|
///
|
||||||
/// @param scale - Vertical scale.
|
/// @param scale - Vertical scale.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetVScale(float scale);
|
void SetVScale(float scale);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set blending color of the object.
|
/// Set blending color of the object.
|
||||||
///
|
///
|
||||||
/// @param color - Blending color.
|
/// @param color - Blending color.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetColor(PIXEL_TYPE color);
|
void SetColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set horizontal flipping.
|
/// Set horizontal flipping.
|
||||||
///
|
///
|
||||||
/// @param flag - flipping flag.
|
/// @param flag - flipping flag.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetFlip(bool flag);
|
void SetFlip(bool flag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JRenderer* mRenderer;
|
JRenderer* mRenderer;
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
float mRotation;
|
float mRotation;
|
||||||
float mHScale;
|
float mHScale;
|
||||||
float mVScale;
|
float mVScale;
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
bool mFlipped;
|
bool mFlipped;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+88
-88
@@ -1,88 +1,88 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JAPP_H_
|
#ifndef _JAPP_H_
|
||||||
#define _JAPP_H_
|
#define _JAPP_H_
|
||||||
|
|
||||||
class JGE;
|
class JGE;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Main application class for the system to run. The core game class
|
/// Main application class for the system to run. The core game class
|
||||||
/// should be derived from this base class.
|
/// should be derived from this base class.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JApp
|
class JApp
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
JApp();
|
JApp();
|
||||||
virtual ~JApp();
|
virtual ~JApp();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Initialization function.
|
/// Initialization function.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Create() = 0;
|
virtual void Create() = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Cleanup function before exiting from the game.
|
/// Cleanup function before exiting from the game.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Destroy() = 0;
|
virtual void Destroy() = 0;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update function to be called for each frame update. Should perform
|
/// Update function to be called for each frame update. Should perform
|
||||||
/// all the game logic here.
|
/// all the game logic here.
|
||||||
///
|
///
|
||||||
/// @par Example: A simple Update() implementation:
|
/// @par Example: A simple Update() implementation:
|
||||||
/// @code
|
/// @code
|
||||||
/// void Update()
|
/// void Update()
|
||||||
/// {
|
/// {
|
||||||
/// float dt = JGE::GetInstance()->GetDelta();
|
/// float dt = JGE::GetInstance()->GetDelta();
|
||||||
/// mX += mSpeed*dt;
|
/// mX += mSpeed*dt;
|
||||||
/// }
|
/// }
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Update() = 0;
|
virtual void Update() = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render function to be called for each frame update. Should do all the
|
/// Render function to be called for each frame update. Should do all the
|
||||||
/// game rendering here.
|
/// game rendering here.
|
||||||
///
|
///
|
||||||
/// @par Example: A simple Render() implementation:
|
/// @par Example: A simple Render() implementation:
|
||||||
/// @code
|
/// @code
|
||||||
/// void Render()
|
/// void Render()
|
||||||
/// {
|
/// {
|
||||||
/// JRenderer *r = JRenderer::GetInstance();
|
/// JRenderer *r = JRenderer::GetInstance();
|
||||||
/// r->FillRect(0,0,480,272,ARGB(255,0,0,0));
|
/// r->FillRect(0,0,480,272,ARGB(255,0,0,0));
|
||||||
/// }
|
/// }
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Render() = 0;
|
virtual void Render() = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Callback function called when the game is paused by the system.
|
/// Callback function called when the game is paused by the system.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Pause() = 0;
|
virtual void Pause() = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Callback function called when the game is resumed by the system.
|
/// Callback function called when the game is resumed by the system.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Resume() = 0;
|
virtual void Resume() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+62
-62
@@ -1,62 +1,62 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
// Copyright (c) 2007 Cooleyes
|
// Copyright (c) 2007 Cooleyes
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _COOLEYES_MP3_
|
#ifndef _COOLEYES_MP3_
|
||||||
#define _COOLEYES_MP3_
|
#define _COOLEYES_MP3_
|
||||||
|
|
||||||
|
|
||||||
#define FORCE_BUFFER_ALIGNMENT
|
#define FORCE_BUFFER_ALIGNMENT
|
||||||
|
|
||||||
class JCooleyesMP3
|
class JCooleyesMP3
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JCooleyesMP3();
|
JCooleyesMP3();
|
||||||
~JCooleyesMP3();
|
~JCooleyesMP3();
|
||||||
|
|
||||||
bool Load(const char* filename);
|
bool Load(const char* filename);
|
||||||
void Release();
|
void Release();
|
||||||
bool Play(bool looping = false);
|
bool Play(bool looping = false);
|
||||||
void Stop();
|
void Stop();
|
||||||
void Resume();
|
void Resume();
|
||||||
void FeedAudioData(void* buf, unsigned int length/*, bool mixing = false*/);
|
void FeedAudioData(void* buf, unsigned int length/*, bool mixing = false*/);
|
||||||
void Decode();
|
void Decode();
|
||||||
bool IsPlaying();
|
bool IsPlaying();
|
||||||
|
|
||||||
void InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer);
|
void InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool mPlaying;
|
bool mPlaying;
|
||||||
SceUID mp3_handle;
|
SceUID mp3_handle;
|
||||||
u8* mFileBuffer;
|
u8* mFileBuffer;
|
||||||
u8* mMP3FirstFramePointer;
|
u8* mMP3FirstFramePointer;
|
||||||
int mFileSize;
|
int mFileSize;
|
||||||
int mUpdateCounter;
|
int mUpdateCounter;
|
||||||
u8* mCurrFramePointer;
|
u8* mCurrFramePointer;
|
||||||
int mDataPointer;
|
int mDataPointer;
|
||||||
int mSamplesPending;
|
int mSamplesPending;
|
||||||
bool mAllMP3DataProcessed;
|
bool mAllMP3DataProcessed;
|
||||||
|
|
||||||
bool mLooping;
|
bool mLooping;
|
||||||
|
|
||||||
u32 mSamplePerFrame;
|
u32 mSamplePerFrame;
|
||||||
u32 mChannelCount;
|
u32 mChannelCount;
|
||||||
u32 mSampleRate;
|
u32 mSampleRate;
|
||||||
|
|
||||||
int mOutputBufferIndex;
|
int mOutputBufferIndex;
|
||||||
|
|
||||||
short *mDecoderBuffer;
|
short *mDecoderBuffer;
|
||||||
short *mDecodedDataOutputBuffer;
|
short *mDecodedDataOutputBuffer;
|
||||||
unsigned long *mMP3CodecBuffer;
|
unsigned long *mMP3CodecBuffer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
// Note: Inspired by HGE's DistortionMesh.
|
// Note: Inspired by HGE's DistortionMesh.
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JDISTORT_MESH_H
|
#ifndef _JDISTORT_MESH_H
|
||||||
#define _JDISTORT_MESH_H
|
#define _JDISTORT_MESH_H
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
|
|
||||||
class JDistortionMesh
|
class JDistortionMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows);
|
JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows);
|
||||||
~JDistortionMesh();
|
~JDistortionMesh();
|
||||||
|
|
||||||
void Render(float x, float y);
|
void Render(float x, float y);
|
||||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||||
void SetDisplacement(int col, int row, float dx, float dy);//, int ref);
|
void SetDisplacement(int col, int row, float dx, float dy);//, int ref);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static JRenderer *mRenderer;
|
static JRenderer *mRenderer;
|
||||||
Vertex* mVertices;
|
Vertex* mVertices;
|
||||||
int mRows;
|
int mRows;
|
||||||
int mCols;
|
int mCols;
|
||||||
float mCellWidth;
|
float mCellWidth;
|
||||||
float mCellHeight;
|
float mCellHeight;
|
||||||
float mTexX;
|
float mTexX;
|
||||||
float mTexY;
|
float mTexY;
|
||||||
float mTexWidth;
|
float mTexWidth;
|
||||||
float mTexHeight;
|
float mTexHeight;
|
||||||
JTexture* mTexture;
|
JTexture* mTexture;
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+143
-143
@@ -1,143 +1,143 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FILE_SYSTEM_H_
|
#ifndef _FILE_SYSTEM_H_
|
||||||
#define _FILE_SYSTEM_H_
|
#define _FILE_SYSTEM_H_
|
||||||
|
|
||||||
#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename)
|
#define JGE_GET_RES(filename) JFileSystem::GetInstance()->GetResourceFile(filename)
|
||||||
#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot()
|
#define JGE_GET_RESPATH() JFileSystem::GetInstance()->GetResourceRoot()
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <pspiofilemgr.h>
|
#include <pspiofilemgr.h>
|
||||||
#include <pspiofilemgr_fcntl.h>
|
#include <pspiofilemgr_fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "unzip/unzip.h"
|
#include "unzip/unzip.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Interface for low level file access with ZIP archive support. All
|
/// Interface for low level file access with ZIP archive support. All
|
||||||
/// file operations in JGE are handled through this class so if a ZIP
|
/// 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 is attached, all the resources will be loaded from the
|
||||||
/// archive file.
|
/// archive file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class JZipCache {
|
class JZipCache {
|
||||||
public:
|
public:
|
||||||
JZipCache();
|
JZipCache();
|
||||||
~JZipCache();
|
~JZipCache();
|
||||||
map<string,unz_file_pos *> dir;
|
map<string,unz_file_pos *> dir;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class JFileSystem
|
class JFileSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get the singleton instance
|
/// Get the singleton instance
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
static JFileSystem* GetInstance();
|
static JFileSystem* GetInstance();
|
||||||
|
|
||||||
static void Destroy();
|
static void Destroy();
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Attach ZIP archive to the file system.
|
/// Attach ZIP archive to the file system.
|
||||||
///
|
///
|
||||||
/// @param zipfile - Name of ZIP archive.
|
/// @param zipfile - Name of ZIP archive.
|
||||||
/// @param password - Password for the ZIP archive. Default is NULL.
|
/// @param password - Password for the ZIP archive. Default is NULL.
|
||||||
///
|
///
|
||||||
/// @return Status of the attach operation.
|
/// @return Status of the attach operation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool AttachZipFile(const string &zipfile, char *password = NULL);
|
bool AttachZipFile(const string &zipfile, char *password = NULL);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Release the attached ZIP archive.
|
/// Release the attached ZIP archive.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void DetachZipFile();
|
void DetachZipFile();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Open file for reading.
|
/// Open file for reading.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool OpenFile(const string &filename);
|
bool OpenFile(const string &filename);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Read data from file.
|
/// Read data from file.
|
||||||
///
|
///
|
||||||
/// @param buffer - Buffer for reading.
|
/// @param buffer - Buffer for reading.
|
||||||
/// @param size - Number of bytes to read.
|
/// @param size - Number of bytes to read.
|
||||||
///
|
///
|
||||||
/// @return Number of bytes read.
|
/// @return Number of bytes read.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int ReadFile(void *buffer, int size);
|
int ReadFile(void *buffer, int size);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get size of file.
|
/// Get size of file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetFileSize();
|
int GetFileSize();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Close file.
|
/// Close file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set root for all the following file operations
|
/// Set root for all the following file operations
|
||||||
///
|
///
|
||||||
/// @resourceRoot - New root.
|
/// @resourceRoot - New root.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetResourceRoot(const string& resourceRoot);
|
void SetResourceRoot(const string& resourceRoot);
|
||||||
string GetResourceRoot();
|
string GetResourceRoot();
|
||||||
|
|
||||||
// Returns a string prefixed with the resource path
|
// Returns a string prefixed with the resource path
|
||||||
string GetResourceFile(string filename);
|
string GetResourceFile(string filename);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JFileSystem();
|
JFileSystem();
|
||||||
~JFileSystem();
|
~JFileSystem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static JFileSystem* mInstance;
|
static JFileSystem* mInstance;
|
||||||
|
|
||||||
map<string,JZipCache *>mZipCache;
|
map<string,JZipCache *>mZipCache;
|
||||||
string mResourceRoot;
|
string mResourceRoot;
|
||||||
string mZipFileName;
|
string mZipFileName;
|
||||||
char *mPassword;
|
char *mPassword;
|
||||||
bool mZipAvailable;
|
bool mZipAvailable;
|
||||||
void preloadZip(string filename);
|
void preloadZip(string filename);
|
||||||
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
#if defined (WIN32) || defined (LINUX) || defined(IOS)
|
||||||
FILE *mFile;
|
FILE *mFile;
|
||||||
#else
|
#else
|
||||||
SceUID mFile;
|
SceUID mFile;
|
||||||
#endif
|
#endif
|
||||||
unzFile mZipFile;
|
unzFile mZipFile;
|
||||||
int mFileSize;
|
int mFileSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+192
-192
@@ -1,192 +1,192 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JBGK_FONT_H_
|
#ifndef _JBGK_FONT_H_
|
||||||
#define _JBGK_FONT_H_
|
#define _JBGK_FONT_H_
|
||||||
|
|
||||||
|
|
||||||
#include "JTypes.h"
|
#include "JTypes.h"
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
#include "JSprite.h"
|
#include "JSprite.h"
|
||||||
|
|
||||||
#define BYTE u8
|
#define BYTE u8
|
||||||
#define DWORD u32
|
#define DWORD u32
|
||||||
#define BOOL int
|
#define BOOL int
|
||||||
|
|
||||||
|
|
||||||
// #define GB_FONT_SIZE 16
|
// #define GB_FONT_SIZE 16
|
||||||
// #define GB_FONT_DATA_SIZE GB_FONT_SIZE*GB_FONT_SIZE/8
|
// #define GB_FONT_DATA_SIZE GB_FONT_SIZE*GB_FONT_SIZE/8
|
||||||
// #define GB_FONT_BYTE_COUNT GB_FONT_SIZE/8
|
// #define GB_FONT_BYTE_COUNT GB_FONT_SIZE/8
|
||||||
//
|
//
|
||||||
#define MAX_CACHE_SIZE 256
|
#define MAX_CACHE_SIZE 256
|
||||||
//
|
//
|
||||||
// #define CFONT_TEX_WIDTH 256
|
// #define CFONT_TEX_WIDTH 256
|
||||||
// #define CFONT_TEX_HEIGHT 256
|
// #define CFONT_TEX_HEIGHT 256
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Chinese bitmap font encoded with GBK encoding. All popurlar font sizes
|
/// Chinese bitmap font encoded with GBK encoding. All popurlar font sizes
|
||||||
/// are supported and the following have been tested:
|
/// are supported and the following have been tested:
|
||||||
/// 12x12, 16x16, 18x18, 20x20, 24x24, 28x28 and 32x32.
|
/// 12x12, 16x16, 18x18, 20x20, 24x24, 28x28 and 32x32.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JGBKFont
|
class JGBKFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JGBKFont();
|
JGBKFont();
|
||||||
|
|
||||||
~JGBKFont();
|
~JGBKFont();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Initialization of the font class. You need to provide both a Chinese
|
/// Initialization of the font class. You need to provide both a Chinese
|
||||||
/// font file and an English one as well.
|
/// font file and an English one as well.
|
||||||
///
|
///
|
||||||
/// For example:
|
/// For example:
|
||||||
/// @code
|
/// @code
|
||||||
/// mChineseFont = new JGBKFont();
|
/// mChineseFont = new JGBKFont();
|
||||||
/// mChineseFont->Init("Res/ASC16", "Res/GBK16");
|
/// mChineseFont->Init("Res/ASC16", "Res/GBK16");
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
/// @param engFileName - Name of the English font file.
|
/// @param engFileName - Name of the English font file.
|
||||||
/// @param chnFileName - Name of the Chinese font file.
|
/// @param chnFileName - Name of the Chinese font file.
|
||||||
/// @param fontsize - Font size.
|
/// @param fontsize - Font size.
|
||||||
/// @param smallEnglishFont - Indicate to use half width when rendering English characters.
|
/// @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);
|
bool Init(const char* engFileName, const char* chnFileName, int fontsize=16, bool smallEnglishFont=false);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Rendering character into cache.
|
/// Rendering character into cache.
|
||||||
///
|
///
|
||||||
/// @param ch - Single byte or word of character code.
|
/// @param ch - Single byte or word of character code.
|
||||||
///
|
///
|
||||||
/// @return Index of the character in cache.
|
/// @return Index of the character in cache.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int PreCacheChar(const BYTE *ch);
|
int PreCacheChar(const BYTE *ch);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Scan through the string and look up the index of each character in the
|
/// 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.
|
/// cache and then return all indexes in an array to be rendered later on.
|
||||||
///
|
///
|
||||||
/// @param str - String to look for cache indexes.
|
/// @param str - String to look for cache indexes.
|
||||||
/// @return dest - Indexes of characters in cache.
|
/// @return dest - Indexes of characters in cache.
|
||||||
/// @return Number of characters processed.
|
/// @return Number of characters processed.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int PrepareString(BYTE* str, int* dest);
|
int PrepareString(BYTE* str, int* dest);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render string by using the indexes returned from PrepareString.
|
/// Render string by using the indexes returned from PrepareString.
|
||||||
///
|
///
|
||||||
/// @param text - Cache indexes for rendering.
|
/// @param text - Cache indexes for rendering.
|
||||||
/// @param count - Number of characters to render.
|
/// @param count - Number of characters to render.
|
||||||
/// @param x - X screen position for rendering.
|
/// @param x - X screen position for rendering.
|
||||||
/// @param y - Y screen position for rendering.
|
/// @param y - Y screen position for rendering.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RenderEncodedString(const int* text, int count, float x, float y);
|
void RenderEncodedString(const int* text, int count, float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render string to screen.
|
/// Render string to screen.
|
||||||
///
|
///
|
||||||
/// @param str - String to render.
|
/// @param str - String to render.
|
||||||
/// @param x - X screen position for rendering.
|
/// @param x - X screen position for rendering.
|
||||||
/// @param y - Y screen position for rendering.
|
/// @param y - Y screen position for rendering.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RenderString(BYTE* str, float x, float y, int alignment=JGETEXT_LEFT);
|
void RenderString(BYTE* str, float x, float y, int alignment=JGETEXT_LEFT);
|
||||||
|
|
||||||
int GetStringWidth(BYTE* str);
|
int GetStringWidth(BYTE* str);
|
||||||
int GetStringHeight(BYTE* str);
|
int GetStringHeight(BYTE* str);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set scale for rendering.
|
/// Set scale for rendering.
|
||||||
///
|
///
|
||||||
/// @param scale - Scale for rendering characters.
|
/// @param scale - Scale for rendering characters.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetScale(float scale);
|
void SetScale(float scale);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set angle for rendering.
|
/// Set angle for rendering.
|
||||||
///
|
///
|
||||||
/// @param rot - Rotation angle in radian.
|
/// @param rot - Rotation angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetRotation(float rot);
|
void SetRotation(float rot);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set font color.
|
/// Set font color.
|
||||||
///
|
///
|
||||||
/// @param color - color of font.
|
/// @param color - color of font.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetColor(PIXEL_TYPE color);
|
void SetColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set background color.
|
/// Set background color.
|
||||||
///
|
///
|
||||||
/// @param color - Background color.
|
/// @param color - Background color.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetBgColor(PIXEL_TYPE color);
|
void SetBgColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static JRenderer* mRenderer;
|
static JRenderer* mRenderer;
|
||||||
|
|
||||||
BYTE* mChnFont;
|
BYTE* mChnFont;
|
||||||
BYTE* mEngFont;
|
BYTE* mEngFont;
|
||||||
|
|
||||||
DWORD* mCharBuffer;
|
DWORD* mCharBuffer;
|
||||||
|
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
PIXEL_TYPE mBgColor;
|
PIXEL_TYPE mBgColor;
|
||||||
|
|
||||||
int mFontSize;
|
int mFontSize;
|
||||||
int mBytesPerChar;
|
int mBytesPerChar;
|
||||||
int mBytesPerRow;
|
int mBytesPerRow;
|
||||||
|
|
||||||
int mCacheSize;
|
int mCacheSize;
|
||||||
int mCacheImageWidth;
|
int mCacheImageWidth;
|
||||||
int mCacheImageHeight;
|
int mCacheImageHeight;
|
||||||
|
|
||||||
int mCol;
|
int mCol;
|
||||||
int mRow;
|
int mRow;
|
||||||
|
|
||||||
//public:
|
//public:
|
||||||
|
|
||||||
JTexture* mTexture;
|
JTexture* mTexture;
|
||||||
JQuad** mSprites;
|
JQuad** mSprites;
|
||||||
|
|
||||||
int *mGBCode;
|
int *mGBCode;
|
||||||
|
|
||||||
int mCurr;
|
int mCurr;
|
||||||
|
|
||||||
float mScale;
|
float mScale;
|
||||||
float mRotation;
|
float mRotation;
|
||||||
|
|
||||||
int mCount;
|
int mCount;
|
||||||
|
|
||||||
bool mSmallEnglishFont;
|
bool mSmallEnglishFont;
|
||||||
|
|
||||||
void GetStringArea(BYTE* str, int *w, int *h);
|
void GetStringArea(BYTE* str, int *w, int *h);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+57
-57
@@ -1,57 +1,57 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _GAME_LAUNCHER_H_
|
#ifndef _GAME_LAUNCHER_H_
|
||||||
#define _GAME_LAUNCHER_H_
|
#define _GAME_LAUNCHER_H_
|
||||||
|
|
||||||
|
|
||||||
#include "JApp.h"
|
#include "JApp.h"
|
||||||
#include "JTypes.h"
|
#include "JTypes.h"
|
||||||
#include "JFileSystem.h"
|
#include "JFileSystem.h"
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// An interface for JGE to get the user defined JApp class.
|
/// An interface for JGE to get the user defined JApp class.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JGameLauncher
|
class JGameLauncher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get user defined JApp instance. The function will be called when
|
/// Get user defined JApp instance. The function will be called when
|
||||||
/// JGE starts.
|
/// JGE starts.
|
||||||
///
|
///
|
||||||
/// @return - User defined JApp instance.
|
/// @return - User defined JApp instance.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JApp* GetGameApp();
|
JApp* GetGameApp();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get application name. Mainly for Windows build to setup the name
|
/// Get application name. Mainly for Windows build to setup the name
|
||||||
/// on the title bar.
|
/// on the title bar.
|
||||||
///
|
///
|
||||||
/// @return - Application name.
|
/// @return - Application name.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
char *GetName();
|
char *GetName();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get initialization flags.
|
/// Get initialization flags.
|
||||||
///
|
///
|
||||||
/// @return - Initialization flags.
|
/// @return - Initialization flags.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
u32 GetInitFlags();
|
u32 GetInitFlags();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+259
-259
@@ -1,259 +1,259 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JGAME_OBJECT_H_
|
#ifndef _JGAME_OBJECT_H_
|
||||||
#define _JGAME_OBJECT_H_
|
#define _JGAME_OBJECT_H_
|
||||||
|
|
||||||
#include "JTypes.h"
|
#include "JTypes.h"
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
#include "JSprite.h"
|
#include "JSprite.h"
|
||||||
|
|
||||||
|
|
||||||
#define FLASH_TIME 0.10f
|
#define FLASH_TIME 0.10f
|
||||||
#define FLASHING_COUNT 6
|
#define FLASHING_COUNT 6
|
||||||
|
|
||||||
#define RENDER_FLAG_ANGLE 0x0001
|
#define RENDER_FLAG_ANGLE 0x0001
|
||||||
#define RENDER_FLAG_SIZE 0x0002
|
#define RENDER_FLAG_SIZE 0x0002
|
||||||
#define RENDER_FLAG_ROTATION 0x0004
|
#define RENDER_FLAG_ROTATION 0x0004
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// A super Sprite class for in-game entities. Extra functions are added
|
/// A super Sprite class for in-game entities. Extra functions are added
|
||||||
/// in addition to a normal Sprite for easier control of in-game
|
/// in addition to a normal Sprite for easier control of in-game
|
||||||
/// activities.
|
/// activities.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JGameObject: public JSprite
|
class JGameObject: public JSprite
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param tex - Texture for first frame. NULL for no starting frame.
|
/// @param tex - Texture for first frame. NULL for no starting frame.
|
||||||
/// @param x - X position of texture for the frame.
|
/// @param x - X position of texture for the frame.
|
||||||
/// @param y - Y position of texture for the frame.
|
/// @param y - Y position of texture for the frame.
|
||||||
/// @param width - Width of the frame.
|
/// @param width - Width of the frame.
|
||||||
/// @param height - Height of the frame.
|
/// @param height - Height of the frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JGameObject(JTexture *tex, float x, float y, float width, float height);
|
JGameObject(JTexture *tex, float x, float y, float width, float height);
|
||||||
|
|
||||||
virtual ~JGameObject();
|
virtual ~JGameObject();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update function.
|
/// Update function.
|
||||||
///
|
///
|
||||||
/// @param dt - Delta time since last update (in second).
|
/// @param dt - Delta time since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render current frame.
|
/// Render current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Function to handle collision.
|
/// Function to handle collision.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void OnCollide();
|
virtual void OnCollide();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set bounding box for collision detection. All the following collision
|
/// Set bounding box for collision detection. All the following collision
|
||||||
/// detections will be done using bounding box.
|
/// detections will be done using bounding box.
|
||||||
///
|
///
|
||||||
/// @param x - X position of the bounding box (relative to this sprite).
|
/// @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 y - Y position of the bounding box (relative to this sprite).
|
||||||
/// @param width - Width of the bounding box.
|
/// @param width - Width of the bounding box.
|
||||||
/// @param height - Height of the bounding box.
|
/// @param height - Height of the bounding box.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetBBox(float x, float y, float width, float height);
|
void SetBBox(float x, float y, float width, float height);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get bounding box relative to screen position.
|
/// Get bounding box relative to screen position.
|
||||||
///
|
///
|
||||||
/// @param x - X of screen position.
|
/// @param x - X of screen position.
|
||||||
/// @param y - Y of screen position.
|
/// @param y - Y of screen position.
|
||||||
///
|
///
|
||||||
/// @return xNow - X position of the bounding box (relative to screen).
|
/// @return xNow - X position of the bounding box (relative to screen).
|
||||||
/// @return yNow - Y 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 width - Width of the bounding box.
|
||||||
/// @return height - Height 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);
|
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
|
/// Set up a circle for collision detection. All the following collision
|
||||||
/// detections will be done using circle to circle collision detection.
|
/// detections will be done using circle to circle collision detection.
|
||||||
///
|
///
|
||||||
/// @param cx - X of the circle center.
|
/// @param cx - X of the circle center.
|
||||||
/// @param cy - Y of the circle center.
|
/// @param cy - Y of the circle center.
|
||||||
/// @param radius - Radius of the circle.
|
/// @param radius - Radius of the circle.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetCollisionCircle(float cx, float cy, float radius);
|
void SetCollisionCircle(float cx, float cy, float radius);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check for collision. Either bounding box or circle to circle
|
/// Check for collision. Either bounding box or circle to circle
|
||||||
/// collision detection will be used depending on which one is setup last.
|
/// collision detection will be used depending on which one is setup last.
|
||||||
///
|
///
|
||||||
/// @param target - Target to check for collision.
|
/// @param target - Target to check for collision.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Collide(JGameObject *target);
|
bool Collide(JGameObject *target);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set object that has collided with this object.
|
/// Set object that has collided with this object.
|
||||||
///
|
///
|
||||||
/// @param target - Object that has collided with this object.
|
/// @param target - Object that has collided with this object.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetCollisionTarget(JGameObject *target);
|
void SetCollisionTarget(JGameObject *target);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get object that has collided with this object.
|
/// Get object that has collided with this object.
|
||||||
///
|
///
|
||||||
/// @return Object that has collided with this object.
|
/// @return Object that has collided with this object.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JGameObject *GetCollisionTarget();
|
JGameObject *GetCollisionTarget();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set damage point of this object.
|
/// Set damage point of this object.
|
||||||
///
|
///
|
||||||
/// @param pt - Damage point.
|
/// @param pt - Damage point.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetHitPoint(int pt);
|
void SetHitPoint(int pt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get damage point of this object.
|
/// Get damage point of this object.
|
||||||
///
|
///
|
||||||
/// @return Damage point.
|
/// @return Damage point.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetHitPoint();
|
int GetHitPoint();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set blood of this object.
|
/// Set blood of this object.
|
||||||
///
|
///
|
||||||
/// @param pt - Blood value.
|
/// @param pt - Blood value.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetBlood(int pt);
|
void SetBlood(int pt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get blood of this object.
|
/// Get blood of this object.
|
||||||
///
|
///
|
||||||
/// @return Blood value.
|
/// @return Blood value.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetBlood();
|
int GetBlood();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Enable alpha animation during update.
|
/// Enable alpha animation during update.
|
||||||
///
|
///
|
||||||
/// @param flag - Enable flag.
|
/// @param flag - Enable flag.
|
||||||
/// @param delta - Rate of changing the alpha value.
|
/// @param delta - Rate of changing the alpha value.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void EnableAlpha(bool flag, float delta=0.0f);
|
void EnableAlpha(bool flag, float delta=0.0f);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Enable scaling during update.
|
/// Enable scaling during update.
|
||||||
///
|
///
|
||||||
/// @param flag - Enable flag.
|
/// @param flag - Enable flag.
|
||||||
/// @param delta - Rate of changing the scaling value.
|
/// @param delta - Rate of changing the scaling value.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void EnableScaling(bool flag, float delta=0.0f);
|
void EnableScaling(bool flag, float delta=0.0f);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Enable rotation during update.
|
/// Enable rotation during update.
|
||||||
///
|
///
|
||||||
/// @param flag - Enable flag.
|
/// @param flag - Enable flag.
|
||||||
/// @param delta - Rate of rotation.
|
/// @param delta - Rate of rotation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void EnableRotation(bool flag, float delta=0.0f);
|
void EnableRotation(bool flag, float delta=0.0f);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set rendering flags.
|
/// Set rendering flags.
|
||||||
///
|
///
|
||||||
/// @param flags - Rendering flags encoded in bits.
|
/// @param flags - Rendering flags encoded in bits.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetRenderFlags(int flags);
|
void SetRenderFlags(int flags);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start flashing during render.
|
/// Start flashing during render.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StartFlashing();
|
void StartFlashing();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start flashing during render.
|
/// Start flashing during render.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StopFlashing();
|
void StopFlashing();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if object is flashing.
|
/// Check if object is flashing.
|
||||||
///
|
///
|
||||||
/// @return Flashing status.
|
/// @return Flashing status.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsFlashing();
|
bool IsFlashing();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
u32 mRenderFlags;
|
u32 mRenderFlags;
|
||||||
|
|
||||||
|
|
||||||
bool mUseBoundingBox;
|
bool mUseBoundingBox;
|
||||||
|
|
||||||
float mBBoxX;
|
float mBBoxX;
|
||||||
float mBBoxY;
|
float mBBoxY;
|
||||||
float mBBoxWidth;
|
float mBBoxWidth;
|
||||||
float mBBoxHeight;
|
float mBBoxHeight;
|
||||||
|
|
||||||
float mCenterX;
|
float mCenterX;
|
||||||
float mCenterY;
|
float mCenterY;
|
||||||
float mRadius;
|
float mRadius;
|
||||||
|
|
||||||
bool mDoAlpha;
|
bool mDoAlpha;
|
||||||
float mAlphaDelta;
|
float mAlphaDelta;
|
||||||
bool mDoScaling;
|
bool mDoScaling;
|
||||||
float mScaleDelta;
|
float mScaleDelta;
|
||||||
bool mDoRotation;
|
bool mDoRotation;
|
||||||
float mRotationDelta;
|
float mRotationDelta;
|
||||||
|
|
||||||
bool mFlashing;
|
bool mFlashing;
|
||||||
float mFlashTimer;
|
float mFlashTimer;
|
||||||
int mFlashCounter;
|
int mFlashCounter;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JGameObject *mCollisionTarget;
|
JGameObject *mCollisionTarget;
|
||||||
bool mCollided;
|
bool mCollided;
|
||||||
|
|
||||||
int mHitPoint;
|
int mHitPoint;
|
||||||
int mBlood;
|
int mBlood;
|
||||||
int mOriginalBlood;
|
int mOriginalBlood;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+187
-187
@@ -1,187 +1,187 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#ifndef JLBF_H
|
#ifndef JLBF_H
|
||||||
#define JLBF_H
|
#define JLBF_H
|
||||||
|
|
||||||
#define PRINTF_BUFFER_SIZE 256
|
#define PRINTF_BUFFER_SIZE 256
|
||||||
#define MAX_CHAR 256
|
#define MAX_CHAR 256
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Bitmap font class for LMNOpc's Bitmap Font Builder:
|
/// Bitmap font class for LMNOpc's Bitmap Font Builder:
|
||||||
/// http://www.lmnopc.com/bitmapfontbuilder/
|
/// http://www.lmnopc.com/bitmapfontbuilder/
|
||||||
///
|
///
|
||||||
/// Two files are used for each font:
|
/// Two files are used for each font:
|
||||||
/// 1: xxx.png, font bitmap.
|
/// 1: xxx.png, font bitmap.
|
||||||
/// 2: xxx.dat, widths for each character
|
/// 2: xxx.dat, widths for each character
|
||||||
/// Each font contains 2 sets of characters ASCII code (32-159).
|
/// Each font contains 2 sets of characters ASCII code (32-159).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JLBFont
|
class JLBFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param fontname - Name of the font WITHOUT extensions.
|
/// @param fontname - Name of the font WITHOUT extensions.
|
||||||
/// @param lineheight - Font height.
|
/// @param lineheight - Font height.
|
||||||
/// @param useVideoRAM - Indicate to use video RAM to store the font image or not (PSP only).
|
/// @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(const char *fontname, int lineheight, bool useVideoRAM=false);
|
||||||
|
|
||||||
~JLBFont();
|
~JLBFont();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Rendering text to screen.
|
/// Rendering text to screen.
|
||||||
///
|
///
|
||||||
/// @param string - text for rendering.
|
/// @param string - text for rendering.
|
||||||
/// @param x - X position of text.
|
/// @param x - X position of text.
|
||||||
/// @param y - Y position of text.
|
/// @param y - Y position of text.
|
||||||
/// @align - Text aligment.
|
/// @align - Text aligment.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void DrawString(const char *string, float x, float y, int align=JGETEXT_LEFT, float leftOffset = 0, float width = 0);
|
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);
|
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++.
|
/// Rendering text to screen with syntax similar to printf of C/C++.
|
||||||
///
|
///
|
||||||
/// @param x - X position of text.
|
/// @param x - X position of text.
|
||||||
/// @param y - Y position of text.
|
/// @param y - Y position of text.
|
||||||
/// @param format - String formatting.
|
/// @param format - String formatting.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void printf(float x, float y, const char *format, ...);
|
void printf(float x, float y, const char *format, ...);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set font color.
|
/// Set font color.
|
||||||
///
|
///
|
||||||
/// @param color - color of font.
|
/// @param color - color of font.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetColor(PIXEL_TYPE color);
|
void SetColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set scale for rendering.
|
/// Set scale for rendering.
|
||||||
///
|
///
|
||||||
/// @param scale - Scale for rendering characters.
|
/// @param scale - Scale for rendering characters.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetScale(float scale);
|
void SetScale(float scale);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set angle for rendering.
|
/// Set angle for rendering.
|
||||||
///
|
///
|
||||||
/// @param rot - Rotation angle in radian.
|
/// @param rot - Rotation angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetRotation(float rot);
|
void SetRotation(float rot);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set font tracking.
|
/// Set font tracking.
|
||||||
///
|
///
|
||||||
/// @param tracking - Font tracking.
|
/// @param tracking - Font tracking.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetTracking(float tracking);
|
void SetTracking(float tracking);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get font color.
|
/// Get font color.
|
||||||
///
|
///
|
||||||
/// @return Font color.
|
/// @return Font color.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
PIXEL_TYPE GetColor() const;
|
PIXEL_TYPE GetColor() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get rendering scale.
|
/// Get rendering scale.
|
||||||
///
|
///
|
||||||
/// @return Rendering scale.
|
/// @return Rendering scale.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetScale() const;
|
float GetScale() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get rendering angle.
|
/// Get rendering angle.
|
||||||
///
|
///
|
||||||
/// @return Rendering angle.
|
/// @return Rendering angle.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetRotation() const;
|
float GetRotation() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get font tracking.
|
/// Get font tracking.
|
||||||
///
|
///
|
||||||
/// @return Font tracking.
|
/// @return Font tracking.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetTracking() const;
|
float GetTracking() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get height of font.
|
/// Get height of font.
|
||||||
///
|
///
|
||||||
/// @return Height of font.
|
/// @return Height of font.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetHeight() const;
|
float GetHeight() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get width of rendering string on screen.
|
/// Get width of rendering string on screen.
|
||||||
///
|
///
|
||||||
/// @param string - NULL terminated string.
|
/// @param string - NULL terminated string.
|
||||||
///
|
///
|
||||||
/// @return - Width in pixels
|
/// @return - Width in pixels
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetStringWidth(const char *string) const;
|
float GetStringWidth(const char *string) const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// There are usually 2 sets of characters in the font image. The first set
|
/// 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
|
/// 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
|
/// function to select which set of characters you want to use. The index
|
||||||
/// base should be either 0 or 128.
|
/// base should be either 0 or 128.
|
||||||
///
|
///
|
||||||
/// @param base - Base for the character set to use.
|
/// @param base - Base for the character set to use.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetBase(int base);
|
void SetBase(int base);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static JRenderer* mRenderer;
|
static JRenderer* mRenderer;
|
||||||
|
|
||||||
JTexture* mTexture;
|
JTexture* mTexture;
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
float mXPos[MAX_CHAR];
|
float mXPos[MAX_CHAR];
|
||||||
float mYPos[MAX_CHAR];
|
float mYPos[MAX_CHAR];
|
||||||
float mCharWidth[MAX_CHAR];
|
float mCharWidth[MAX_CHAR];
|
||||||
|
|
||||||
float mHeight;
|
float mHeight;
|
||||||
float mScale;
|
float mScale;
|
||||||
float mRotation;
|
float mRotation;
|
||||||
float mTracking;
|
float mTracking;
|
||||||
float mSpacing;
|
float mSpacing;
|
||||||
|
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
int mBlend;
|
int mBlend;
|
||||||
|
|
||||||
int mBase;
|
int mBase;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+255
-255
@@ -1,255 +1,255 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _MD2MODEL_H
|
#ifndef _MD2MODEL_H
|
||||||
#define _MD2MODEL_H
|
#define _MD2MODEL_H
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <pspgu.h>
|
#include <pspgu.h>
|
||||||
#include <pspgum.h>
|
#include <pspgum.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
|
||||||
|
|
||||||
#define SMALLEST_FP 0.000001f
|
#define SMALLEST_FP 0.000001f
|
||||||
|
|
||||||
#define MAX_FRAMES 512
|
#define MAX_FRAMES 512
|
||||||
#define MAX_ANIMATION 16
|
#define MAX_ANIMATION 16
|
||||||
|
|
||||||
//#pragma pack(push)
|
//#pragma pack(push)
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
//#pragma pack(pop)
|
//#pragma pack(pop)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
enum MD2AnimationStates
|
enum MD2AnimationStates
|
||||||
{
|
{
|
||||||
STATE_IDLE,
|
STATE_IDLE,
|
||||||
STATE_RUNNING,
|
STATE_RUNNING,
|
||||||
STATE_SHOT_NOT_FALLING_DOWN,
|
STATE_SHOT_NOT_FALLING_DOWN,
|
||||||
STATE_SHOT_IN_SHOULDER,
|
STATE_SHOT_IN_SHOULDER,
|
||||||
STATE_JUMP,
|
STATE_JUMP,
|
||||||
STATE_IDLE2,
|
STATE_IDLE2,
|
||||||
STATE_SHOT_FALLING_DOWN,
|
STATE_SHOT_FALLING_DOWN,
|
||||||
STATE_IDLE3,
|
STATE_IDLE3,
|
||||||
STATE_IDLE4,
|
STATE_IDLE4,
|
||||||
STATE_CROUCHING,
|
STATE_CROUCHING,
|
||||||
STATE_CROUCHING_CRAWL,
|
STATE_CROUCHING_CRAWL,
|
||||||
STATE_IDLE_CROUCHING,
|
STATE_IDLE_CROUCHING,
|
||||||
STATE_KNEELING_DYING,
|
STATE_KNEELING_DYING,
|
||||||
STATE_FALLING_BACK_DYING,
|
STATE_FALLING_BACK_DYING,
|
||||||
STATE_FALING_FORWARD_DYING,
|
STATE_FALING_FORWARD_DYING,
|
||||||
STATE_FALLING_BACK_SLOWLY_DYING
|
STATE_FALLING_BACK_SLOWLY_DYING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
class MD2Animation
|
class MD2Animation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int mStartFrame;
|
int mStartFrame;
|
||||||
int mEndFrame;
|
int mEndFrame;
|
||||||
|
|
||||||
MD2Animation(int start, int end);
|
MD2Animation(int start, int end);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// texture coordinate
|
// texture coordinate
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float s;
|
float s;
|
||||||
float t;
|
float t;
|
||||||
} texCoord_t;
|
} texCoord_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// texture coordinate index
|
// texture coordinate index
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
short s;
|
short s;
|
||||||
short t;
|
short t;
|
||||||
} stIndex_t;
|
} stIndex_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// info for a single frame point
|
// info for a single frame point
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned char v[3];
|
unsigned char v[3];
|
||||||
unsigned char normalIndex; // not used
|
unsigned char normalIndex; // not used
|
||||||
} framePoint_t;
|
} framePoint_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// information for a single frame
|
// information for a single frame
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float scale[3];
|
float scale[3];
|
||||||
float translate[3];
|
float translate[3];
|
||||||
char name[16];
|
char name[16];
|
||||||
framePoint_t fp[1];
|
framePoint_t fp[1];
|
||||||
} frame_t;
|
} frame_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// data for a single triangle
|
// data for a single triangle
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned short meshIndex[3]; // vertex indices
|
unsigned short meshIndex[3]; // vertex indices
|
||||||
unsigned short stIndex[3]; // texture coordinate indices
|
unsigned short stIndex[3]; // texture coordinate indices
|
||||||
} mesh_t;
|
} mesh_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// the model data
|
// the model data
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int numFrames; // number of frames
|
int numFrames; // number of frames
|
||||||
int numPoints; // number of points
|
int numPoints; // number of points
|
||||||
int numTriangles; // number of triangles
|
int numTriangles; // number of triangles
|
||||||
int numST; // number of skins
|
int numST; // number of skins
|
||||||
int frameSize; // size of each frame in bytes
|
int frameSize; // size of each frame in bytes
|
||||||
int texWidth, texHeight; // texture width, height
|
int texWidth, texHeight; // texture width, height
|
||||||
int currentFrame; // current frame # in animation
|
int currentFrame; // current frame # in animation
|
||||||
int nextFrame; // next frame # in animation
|
int nextFrame; // next frame # in animation
|
||||||
float interpol; // percent through current frame
|
float interpol; // percent through current frame
|
||||||
mesh_t *triIndex; // triangle list
|
mesh_t *triIndex; // triangle list
|
||||||
texCoord_t *st; // texture coordinate list
|
texCoord_t *st; // texture coordinate list
|
||||||
Vector3D *pointList; // vertex list
|
Vector3D *pointList; // vertex list
|
||||||
JTexture *modelTex; // texture
|
JTexture *modelTex; // texture
|
||||||
} modelData_t;
|
} modelData_t;
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int ident; // identifies as MD2 file "IDP2"
|
int ident; // identifies as MD2 file "IDP2"
|
||||||
int version; //
|
int version; //
|
||||||
int skinwidth; // width of texture
|
int skinwidth; // width of texture
|
||||||
int skinheight; // height of texture
|
int skinheight; // height of texture
|
||||||
int framesize; // number of bytes per frame
|
int framesize; // number of bytes per frame
|
||||||
int numSkins; // number of textures
|
int numSkins; // number of textures
|
||||||
int numXYZ; // number of points
|
int numXYZ; // number of points
|
||||||
int numST; // number of texture
|
int numST; // number of texture
|
||||||
int numTris; // number of triangles
|
int numTris; // number of triangles
|
||||||
int numGLcmds;
|
int numGLcmds;
|
||||||
int numFrames; // total number of frames
|
int numFrames; // total number of frames
|
||||||
int offsetSkins; // offset to skin names (64 bytes each)
|
int offsetSkins; // offset to skin names (64 bytes each)
|
||||||
int offsetST; // offset of texture s-t values
|
int offsetST; // offset of texture s-t values
|
||||||
int offsetTris; // offset of triangle mesh
|
int offsetTris; // offset of triangle mesh
|
||||||
int offsetFrames; // offset of frame data (points)
|
int offsetFrames; // offset of frame data (points)
|
||||||
int offsetGLcmds; // type of OpenGL commands to use
|
int offsetGLcmds; // type of OpenGL commands to use
|
||||||
int offsetEnd; // end of file
|
int offsetEnd; // end of file
|
||||||
} modelHeader_t;
|
} modelHeader_t;
|
||||||
|
|
||||||
|
|
||||||
class JRenderer;
|
class JRenderer;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Helper class to display Quake 2 MD2 model.
|
/// Helper class to display Quake 2 MD2 model.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JMD2Model
|
class JMD2Model
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JMD2Model();
|
JMD2Model();
|
||||||
|
|
||||||
~JMD2Model();
|
~JMD2Model();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set model state.
|
/// Set model state.
|
||||||
///
|
///
|
||||||
/// @param newState - Model state.
|
/// @param newState - Model state.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetState(int newState);
|
void SetState(int newState);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load MD2 model.
|
/// Load MD2 model.
|
||||||
///
|
///
|
||||||
/// @param filename - Name of MD2 file.
|
/// @param filename - Name of MD2 file.
|
||||||
/// @param texturenName - Name of texture.
|
/// @param texturenName - Name of texture.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(char *filename, char *textureName);
|
bool Load(char *filename, char *textureName);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render a single frame of the model.
|
/// Render a single frame of the model.
|
||||||
///
|
///
|
||||||
/// @param frameNum - Frame to render.
|
/// @param frameNum - Frame to render.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render(int frameNum);
|
void Render(int frameNum);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update animation.
|
/// Update animation.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elpased since last update (in seconds).
|
/// @param dt - Time elpased since last update (in seconds).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set speed of animation.
|
/// Set speed of animation.
|
||||||
///
|
///
|
||||||
/// @param speed - Speed of animation.
|
/// @param speed - Speed of animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetAnimationSpeed(float speed);
|
void SetAnimationSpeed(float speed);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render the model.
|
/// Render the model.
|
||||||
///
|
///
|
||||||
/// @param percent - Interpolating percentage.
|
/// @param percent - Interpolating percentage.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
modelData_t *mModel;
|
modelData_t *mModel;
|
||||||
|
|
||||||
void CheckNextState();
|
void CheckNextState();
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||||
void CalculateNormal(float *p1, float *p2, float *p3);
|
void CalculateNormal(float *p1, float *p2, float *p3);
|
||||||
#else
|
#else
|
||||||
void CalculateNormal(ScePspFVector3* normal, float *p1, float *p2, float *p3);
|
void CalculateNormal(ScePspFVector3* normal, float *p1, float *p2, float *p3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MD2Animation **mAnimations;
|
MD2Animation **mAnimations;
|
||||||
int mState;
|
int mState;
|
||||||
int mNextState;
|
int mNextState;
|
||||||
|
|
||||||
float mAnimationSpeed;
|
float mAnimationSpeed;
|
||||||
|
|
||||||
static JRenderer* mRenderer;
|
static JRenderer* mRenderer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+82
-82
@@ -1,82 +1,82 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _OBJMODEL_H
|
#ifndef _OBJMODEL_H
|
||||||
#define _OBJMODEL_H
|
#define _OBJMODEL_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <pspgu.h>
|
#include <pspgu.h>
|
||||||
#include <pspgum.h>
|
#include <pspgum.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
|
||||||
class JTexture;
|
class JTexture;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Helper class to display Wavefront OBJ model.
|
/// Helper class to display Wavefront OBJ model.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JOBJModel
|
class JOBJModel
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Face
|
struct Face
|
||||||
{
|
{
|
||||||
int mVertCount;
|
int mVertCount;
|
||||||
int mVertIdx[4];
|
int mVertIdx[4];
|
||||||
int mTexIdx[4];
|
int mTexIdx[4];
|
||||||
int mNormalIdx[4];
|
int mNormalIdx[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JOBJModel();
|
JOBJModel();
|
||||||
|
|
||||||
~JOBJModel();
|
~JOBJModel();
|
||||||
|
|
||||||
int ReadLine(char *output, const char *buffer, int start, int size);
|
int ReadLine(char *output, const char *buffer, int start, int size);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load OBJ model.
|
/// Load OBJ model.
|
||||||
///
|
///
|
||||||
/// @param modelName - Name of OBJ file.
|
/// @param modelName - Name of OBJ file.
|
||||||
/// @param texturenName - Name of texture.
|
/// @param texturenName - Name of texture.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(const char *modelName, const char *textureName);
|
bool Load(const char *modelName, const char *textureName);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render the model to screen.
|
/// Render the model to screen.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mPolycount;
|
int mPolycount;
|
||||||
Vertex3D* mPolygons;
|
Vertex3D* mPolygons;
|
||||||
JTexture* mTexture;
|
JTexture* mTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+105
-105
@@ -1,105 +1,105 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __PARTICLE_H__
|
#ifndef __PARTICLE_H__
|
||||||
#define __PARTICLE_H__
|
#define __PARTICLE_H__
|
||||||
|
|
||||||
#include "JApp.h"
|
#include "JApp.h"
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
#include "Vector2D.h"
|
#include "Vector2D.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_KEYS 8
|
#define MAX_KEYS 8
|
||||||
|
|
||||||
class JParticleData
|
class JParticleData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JParticleData();
|
JParticleData();
|
||||||
void Init();
|
void Init();
|
||||||
void Clear();
|
void Clear();
|
||||||
void AddKey(float keyTime, float keyValue);
|
void AddKey(float keyTime, float keyValue);
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void SetScale(float scale);
|
void SetScale(float scale);
|
||||||
|
|
||||||
float mCurr;
|
float mCurr;
|
||||||
float mTarget;
|
float mTarget;
|
||||||
float mDelta;
|
float mDelta;
|
||||||
float mTimer;
|
float mTimer;
|
||||||
int mKeyCount;
|
int mKeyCount;
|
||||||
int mKeyIndex;
|
int mKeyIndex;
|
||||||
float mKeyTime[MAX_KEYS];
|
float mKeyTime[MAX_KEYS];
|
||||||
float mKeyValue[MAX_KEYS];
|
float mKeyValue[MAX_KEYS];
|
||||||
|
|
||||||
float mScale;
|
float mScale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum ParticleField
|
enum ParticleField
|
||||||
{
|
{
|
||||||
FIELD_SPEED,
|
FIELD_SPEED,
|
||||||
FIELD_SIZE,
|
FIELD_SIZE,
|
||||||
FIELD_ROTATION,
|
FIELD_ROTATION,
|
||||||
FIELD_ALPHA,
|
FIELD_ALPHA,
|
||||||
FIELD_RED,
|
FIELD_RED,
|
||||||
FIELD_GREEN,
|
FIELD_GREEN,
|
||||||
FIELD_BLUE,
|
FIELD_BLUE,
|
||||||
FIELD_RADIAL_ACCEL,
|
FIELD_RADIAL_ACCEL,
|
||||||
FIELD_TANGENTIAL_ACCEL,
|
FIELD_TANGENTIAL_ACCEL,
|
||||||
FIELD_GRAVITY,
|
FIELD_GRAVITY,
|
||||||
FIELD_COUNT
|
FIELD_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
class JParticle
|
class JParticle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool mActive;
|
bool mActive;
|
||||||
|
|
||||||
JParticle();
|
JParticle();
|
||||||
~JParticle();
|
~JParticle();
|
||||||
|
|
||||||
bool Update(float dt);
|
bool Update(float dt);
|
||||||
void Render();
|
void Render();
|
||||||
void Init(float lifeTime);
|
void Init(float lifeTime);
|
||||||
|
|
||||||
void InitPosition(float ox, float oy, float xoffset, float yoffset);
|
void InitPosition(float ox, float oy, float xoffset, float yoffset);
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
void SetQuad(JQuad *quad);
|
void SetQuad(JQuad *quad);
|
||||||
|
|
||||||
JParticleData* GetField(int index);
|
JParticleData* GetField(int index);
|
||||||
JParticleData* GetDataPtr();
|
JParticleData* GetDataPtr();
|
||||||
|
|
||||||
void Move(float x, float y);
|
void Move(float x, float y);
|
||||||
void SetVelocity(float x, float y);
|
void SetVelocity(float x, float y);
|
||||||
void SetSize(float size);
|
void SetSize(float size);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static JRenderer* mRenderer;
|
static JRenderer* mRenderer;
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
Vector2D mOrigin;
|
Vector2D mOrigin;
|
||||||
Vector2D mPos;
|
Vector2D mPos;
|
||||||
Vector2D mVelocity;
|
Vector2D mVelocity;
|
||||||
|
|
||||||
//float mSpeed;
|
//float mSpeed;
|
||||||
float mSize;
|
float mSize;
|
||||||
|
|
||||||
float mLifetime;
|
float mLifetime;
|
||||||
|
|
||||||
JParticleData mData[FIELD_COUNT];
|
JParticleData mData[FIELD_COUNT];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+146
-146
@@ -1,146 +1,146 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __PARTICLE_EFFECT_H__
|
#ifndef __PARTICLE_EFFECT_H__
|
||||||
#define __PARTICLE_EFFECT_H__
|
#define __PARTICLE_EFFECT_H__
|
||||||
|
|
||||||
#define MAX_EMITTER 5
|
#define MAX_EMITTER 5
|
||||||
|
|
||||||
class JParticleSystem;
|
class JParticleSystem;
|
||||||
class JParticleEmitter;
|
class JParticleEmitter;
|
||||||
class JResourceManager;
|
class JResourceManager;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Particle effect. Each particle effect can contain one or more emitters.
|
/// Particle effect. Each particle effect can contain one or more emitters.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JParticleEffect
|
class JParticleEffect
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param mgr - Resource manager for retrieving image quads for the particles.
|
/// @param mgr - Resource manager for retrieving image quads for the particles.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JParticleEffect(JResourceManager* mgr);
|
JParticleEffect(JResourceManager* mgr);
|
||||||
|
|
||||||
~JParticleEffect();
|
~JParticleEffect();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load effect from file.
|
/// Load effect from file.
|
||||||
///
|
///
|
||||||
/// @param filename - Name of effect file.
|
/// @param filename - Name of effect file.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(const char* filename);
|
bool Load(const char* filename);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update particle effect.
|
/// Update particle effect.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elapsed since last update (in second).
|
/// @param dt - Time elapsed since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render particle effect.
|
/// Render particle effect.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if the particle effect is finished.
|
/// Check if the particle effect is finished.
|
||||||
///
|
///
|
||||||
/// @return True if done.
|
/// @return True if done.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Done();
|
bool Done();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start playing.
|
/// Start playing.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Stop playing.
|
/// Stop playing.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set particle system.
|
/// Set particle system.
|
||||||
///
|
///
|
||||||
/// @param particleSys - Particle system.
|
/// @param particleSys - Particle system.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetParticleSystem(JParticleSystem* particleSys);
|
void SetParticleSystem(JParticleSystem* particleSys);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get particle system.
|
/// Get particle system.
|
||||||
///
|
///
|
||||||
/// @return Particle system.
|
/// @return Particle system.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JParticleSystem* GetParticleSystem();
|
JParticleSystem* GetParticleSystem();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set position of the effect. New particles will be emitted from the
|
/// Set position of the effect. New particles will be emitted from the
|
||||||
/// new position but the existing active particles will not be affected.
|
/// new position but the existing active particles will not be affected.
|
||||||
///
|
///
|
||||||
/// @param x - X screen position.
|
/// @param x - X screen position.
|
||||||
/// @param y - Y screen position.
|
/// @param y - Y screen position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get X position.
|
/// Get X position.
|
||||||
///
|
///
|
||||||
/// @return X position.
|
/// @return X position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetX();
|
float GetX();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get Y position.
|
/// Get Y position.
|
||||||
///
|
///
|
||||||
/// @return Y position.
|
/// @return Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetY();
|
float GetY();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Move the particle effect over to a new position. All the existing
|
/// Move the particle effect over to a new position. All the existing
|
||||||
/// particles will be moved relatively.
|
/// particles will be moved relatively.
|
||||||
///
|
///
|
||||||
/// @param X - X screen position.
|
/// @param X - X screen position.
|
||||||
/// @param y - Y screen position.
|
/// @param y - Y screen position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void MoveTo(float x, float y);
|
void MoveTo(float x, float y);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JParticleSystem* mParticleSystem;
|
JParticleSystem* mParticleSystem;
|
||||||
JResourceManager* mResourceManager;
|
JResourceManager* mResourceManager;
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
|
|
||||||
int mEmitterCount;
|
int mEmitterCount;
|
||||||
JParticleEmitter* mParticleEmitters[MAX_EMITTER];
|
JParticleEmitter* mParticleEmitters[MAX_EMITTER];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+221
-221
@@ -1,221 +1,221 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __PARTICLE_EMITTER_H__
|
#ifndef __PARTICLE_EMITTER_H__
|
||||||
#define __PARTICLE_EMITTER_H__
|
#define __PARTICLE_EMITTER_H__
|
||||||
|
|
||||||
#define INIT_PARTICLE_COUNT 32
|
#define INIT_PARTICLE_COUNT 32
|
||||||
#define MAX_PARTICLE_COUNT 256
|
#define MAX_PARTICLE_COUNT 256
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
class JParticleEffect;
|
class JParticleEffect;
|
||||||
class JParticle;
|
class JParticle;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Particle emitter. This is where the particles actually generated.
|
/// Particle emitter. This is where the particles actually generated.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JParticleEmitter
|
class JParticleEmitter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param parent - Particle effect that contains this emitter.
|
/// @param parent - Particle effect that contains this emitter.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JParticleEmitter(JParticleEffect* parent);
|
JParticleEmitter(JParticleEffect* parent);
|
||||||
|
|
||||||
~JParticleEmitter();
|
~JParticleEmitter();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set blending mode for rendering.
|
/// Set blending mode for rendering.
|
||||||
///
|
///
|
||||||
/// @param srcBlend - Blending mode for source.
|
/// @param srcBlend - Blending mode for source.
|
||||||
/// @param destBlend - Blending mode for destination.
|
/// @param destBlend - Blending mode for destination.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetBlending(int srcBlend, int destBlend);
|
void SetBlending(int srcBlend, int destBlend);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set image quad for particles.
|
/// Set image quad for particles.
|
||||||
///
|
///
|
||||||
/// @param quad - Image quad.
|
/// @param quad - Image quad.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetQuad(JQuad *quad);
|
void SetQuad(JQuad *quad);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start emitting particles.
|
/// Start emitting particles.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Restart the emitter.
|
/// Restart the emitter.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void ReStart();
|
void ReStart();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update the emitter.
|
/// Update the emitter.
|
||||||
///
|
///
|
||||||
/// @param dt - Time elapsed since last update (in second).
|
/// @param dt - Time elapsed since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render particles emitted by this emitter.
|
/// Render particles emitted by this emitter.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if the emitter is done.
|
/// Check if the emitter is done.
|
||||||
///
|
///
|
||||||
/// @return True if the emitter is done.
|
/// @return True if the emitter is done.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Done();
|
bool Done();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set active flag.
|
/// Set active flag.
|
||||||
///
|
///
|
||||||
/// @param flag - Active flag.
|
/// @param flag - Active flag.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetActive(bool flag);
|
void SetActive(bool flag);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Move all particles to a distance.
|
/// Move all particles to a distance.
|
||||||
///
|
///
|
||||||
/// @param x - X distance to move.
|
/// @param x - X distance to move.
|
||||||
/// @param y - Y distance to move
|
/// @param y - Y distance to move
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void MoveAllParticles(float x, float y);
|
void MoveAllParticles(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Emit certain amount of particles.
|
/// Emit certain amount of particles.
|
||||||
///
|
///
|
||||||
/// @param count - Number of particles to emit.
|
/// @param count - Number of particles to emit.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void EmitParticles(int count);
|
void EmitParticles(int count);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get idle particle to reuse.
|
/// Get idle particle to reuse.
|
||||||
///
|
///
|
||||||
/// @return Idel particle to use.
|
/// @return Idel particle to use.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JParticle* GetIdleParticle();
|
JParticle* GetIdleParticle();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put a particle in action.
|
/// Put a particle in action.
|
||||||
///
|
///
|
||||||
/// @param par - Particle to start playing.
|
/// @param par - Particle to start playing.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StartParticle(JParticle *par);
|
void StartParticle(JParticle *par);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set the maximum number of particles that this emitter can emit.
|
/// Set the maximum number of particles that this emitter can emit.
|
||||||
///
|
///
|
||||||
/// @param count - Maximum number of particles.
|
/// @param count - Maximum number of particles.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetMaxParticleCount(int count);
|
void SetMaxParticleCount(int count);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// \enum JParticleEmitterMode
|
/// \enum JParticleEmitterMode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum JParticleEmitterMode
|
enum JParticleEmitterMode
|
||||||
{
|
{
|
||||||
MODE_REPEAT, ///< Emit particles and repeat when done.
|
MODE_REPEAT, ///< Emit particles and repeat when done.
|
||||||
MODE_ONCE, ///< Emit once.
|
MODE_ONCE, ///< Emit once.
|
||||||
MODE_NTIMES, ///< Emit N times.
|
MODE_NTIMES, ///< Emit N times.
|
||||||
MODE_CONTINUOUS, ///< Emit particles continuously.
|
MODE_CONTINUOUS, ///< Emit particles continuously.
|
||||||
MODE_COUNT
|
MODE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// \enum JParticleEmitterType
|
/// \enum JParticleEmitterType
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum JParticleEmitterType
|
enum JParticleEmitterType
|
||||||
{
|
{
|
||||||
TYPE_POINT, ///< Emit from one point.
|
TYPE_POINT, ///< Emit from one point.
|
||||||
TYPE_AREA, ///< Emit from a rectangle area.
|
TYPE_AREA, ///< Emit from a rectangle area.
|
||||||
TYPE_HORIZONTAL, ///< Emit from a horizontal line.
|
TYPE_HORIZONTAL, ///< Emit from a horizontal line.
|
||||||
TYPE_VERTICAL, ///< Emit from a vertical line.
|
TYPE_VERTICAL, ///< Emit from a vertical line.
|
||||||
TYPE_CIRCLE, ///< Emit from a circle.
|
TYPE_CIRCLE, ///< Emit from a circle.
|
||||||
TYPE_COUNT
|
TYPE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JParticleEffect* mParent;
|
JParticleEffect* mParent;
|
||||||
JQuad* mQuad;
|
JQuad* mQuad;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int mType;
|
int mType;
|
||||||
int mId;
|
int mId;
|
||||||
|
|
||||||
JParticleData mQuantity;
|
JParticleData mQuantity;
|
||||||
JParticleData mData[FIELD_COUNT];
|
JParticleData mData[FIELD_COUNT];
|
||||||
|
|
||||||
float mLifeBase;
|
float mLifeBase;
|
||||||
float mLifeMax;
|
float mLifeMax;
|
||||||
|
|
||||||
float mAngleBase;
|
float mAngleBase;
|
||||||
float mAngleMax;
|
float mAngleMax;
|
||||||
|
|
||||||
float mSpeedBase;
|
float mSpeedBase;
|
||||||
float mSpeedMax;
|
float mSpeedMax;
|
||||||
|
|
||||||
float mSizeBase;
|
float mSizeBase;
|
||||||
float mSizeMax;
|
float mSizeMax;
|
||||||
|
|
||||||
int mWidth;
|
int mWidth;
|
||||||
int mHeight;
|
int mHeight;
|
||||||
|
|
||||||
int mQuadIndex;
|
int mQuadIndex;
|
||||||
|
|
||||||
int mEmitterMode;
|
int mEmitterMode;
|
||||||
int mRepeatTimes;
|
int mRepeatTimes;
|
||||||
|
|
||||||
float mLife;
|
float mLife;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mActive;
|
bool mActive;
|
||||||
float mEmitTimer;
|
float mEmitTimer;
|
||||||
|
|
||||||
int mRepeatCounter;
|
int mRepeatCounter;
|
||||||
int mActiveParticleCount;
|
int mActiveParticleCount;
|
||||||
|
|
||||||
int mSrcBlending;
|
int mSrcBlending;
|
||||||
int mDestBlending;
|
int mDestBlending;
|
||||||
int mMaxParticleCount;
|
int mMaxParticleCount;
|
||||||
|
|
||||||
vector<JParticle*> mParticles;
|
vector<JParticle*> mParticles;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+114
-114
@@ -1,114 +1,114 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __PARTICLE_SYSTEM_H__
|
#ifndef __PARTICLE_SYSTEM_H__
|
||||||
#define __PARTICLE_SYSTEM_H__
|
#define __PARTICLE_SYSTEM_H__
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#include "JGE.h"
|
#include "JGE.h"
|
||||||
|
|
||||||
#include "JParticle.h"
|
#include "JParticle.h"
|
||||||
|
|
||||||
|
|
||||||
class JParticleEffect;
|
class JParticleEffect;
|
||||||
class JParticleEmitter;
|
class JParticleEmitter;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// The particle system of JGE++ is built on a key frame concept with
|
/// 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
|
/// 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 Torque Game Builder. At each key frame, you can specify the value
|
||||||
/// of the changeable states of the particle. This gives you lots of
|
/// of the changeable states of the particle. This gives you lots of
|
||||||
/// control over the particles and making it possible to create
|
/// control over the particles and making it possible to create
|
||||||
/// almost all of the spectacular effects out of your imagination.
|
/// almost all of the spectacular effects out of your imagination.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JParticleSystem
|
class JParticleSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JParticleSystem();
|
JParticleSystem();
|
||||||
|
|
||||||
~JParticleSystem();
|
~JParticleSystem();
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update all active effects.
|
/// Update all active effects.
|
||||||
///
|
///
|
||||||
/// @param dt - Delta time since last update (in second).
|
/// @param dt - Delta time since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render all active effects.
|
/// Render all active effects.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start an effect.
|
/// Start an effect.
|
||||||
///
|
///
|
||||||
/// @param effect - Effect to start playing.
|
/// @param effect - Effect to start playing.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StartEffect(JParticleEffect* effect);
|
void StartEffect(JParticleEffect* effect);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Stop all effects.
|
/// Stop all effects.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StopAllEffects();
|
void StopAllEffects();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Delete all effects from memory.
|
/// Delete all effects from memory.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void ClearAll();
|
void ClearAll();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Check if the particle system is active or not.
|
/// Check if the particle system is active or not.
|
||||||
///
|
///
|
||||||
/// @return True if active.
|
/// @return True if active.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsActive();
|
bool IsActive();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set active flag.
|
/// Set active flag.
|
||||||
///
|
///
|
||||||
/// @param flag - Active flag.
|
/// @param flag - Active flag.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetActive(bool flag);
|
void SetActive(bool flag);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool mActive;
|
bool mActive;
|
||||||
|
|
||||||
list<JParticleEffect*> mEffects;
|
list<JParticleEffect*> mEffects;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+648
-648
File diff suppressed because it is too large
Load Diff
+30
-30
@@ -1,30 +1,30 @@
|
|||||||
#ifndef _JSOCKET_H_
|
#ifndef _JSOCKET_H_
|
||||||
#define _JSOCKET_H_
|
#define _JSOCKET_H_
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//TODO config ?
|
//TODO config ?
|
||||||
#define SERVER_PORT 20666
|
#define SERVER_PORT 20666
|
||||||
|
|
||||||
class JSocket{
|
class JSocket{
|
||||||
public:
|
public:
|
||||||
queue<char> received_data;
|
queue<char> received_data;
|
||||||
queue<char> tosend_data;
|
queue<char> tosend_data;
|
||||||
static JSocket * mInstance;
|
static JSocket * mInstance;
|
||||||
int start_server(const char *szIpAddr);
|
int start_server(const char *szIpAddr);
|
||||||
int start_client(const char *szIpAddr);
|
int start_client(const char *szIpAddr);
|
||||||
|
|
||||||
JSocket();
|
JSocket();
|
||||||
~JSocket();
|
~JSocket();
|
||||||
static int connected;
|
static int connected;
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void readWrite(int sock);
|
void readWrite(int sock);
|
||||||
#if defined (WIN32) || defined (LINUX)
|
#if defined (WIN32) || defined (LINUX)
|
||||||
#else
|
#else
|
||||||
int make_socket(uint16_t port);
|
int make_socket(uint16_t port);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+167
-167
@@ -1,167 +1,167 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JSPLINE_H
|
#ifndef _JSPLINE_H
|
||||||
#define _JSPLINE_H
|
#define _JSPLINE_H
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define MID_POINT_THRESHOLD 1.0f
|
#define MID_POINT_THRESHOLD 1.0f
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Position of a single dot on screen.
|
/// Position of a single dot on screen.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class Point
|
class Point
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param _x - X position.
|
/// @param _x - X position.
|
||||||
/// @param _y - Y position.
|
/// @param _y - Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
Point(float _x, float _y) { x = _x; y = _y; }
|
Point(float _x, float _y) { x = _x; y = _y; }
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor, set position to default (0.0f, 0.0f)
|
/// Constructor, set position to default (0.0f, 0.0f)
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
Point() { x = 0.0f; y = 0.0f; }
|
Point() { x = 0.0f; y = 0.0f; }
|
||||||
|
|
||||||
float x; ///< X position.
|
float x; ///< X position.
|
||||||
float y; ///< Y position.
|
float y; ///< Y position.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Catmull Rom spline.
|
/// Catmull Rom spline.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JSpline
|
class JSpline
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JSpline();
|
JSpline();
|
||||||
~JSpline();
|
~JSpline();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load spline from a file.
|
/// Load spline from a file.
|
||||||
///
|
///
|
||||||
/// Here is a sample spline definition file:
|
/// Here is a sample spline definition file:
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// <?xml version="1.0" standalone="no" ?>
|
/// <?xml version="1.0" standalone="no" ?>
|
||||||
/// <path>
|
/// <path>
|
||||||
/// <contro_point x="89" y="270" />
|
/// <contro_point x="89" y="270" />
|
||||||
/// <contro_point x="113" y="154" />
|
/// <contro_point x="113" y="154" />
|
||||||
/// <contro_point x="227" y="94" />
|
/// <contro_point x="227" y="94" />
|
||||||
/// <contro_point x="347" y="154" />
|
/// <contro_point x="347" y="154" />
|
||||||
/// <contro_point x="367" y="278" />
|
/// <contro_point x="367" y="278" />
|
||||||
/// </path>
|
/// </path>
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
/// @param filename - Name of spline definition file.
|
/// @param filename - Name of spline definition file.
|
||||||
/// @param xscale - Scaling factor for X of all control points.
|
/// @param xscale - Scaling factor for X of all control points.
|
||||||
/// @param yscale - Scaling factor for Y of all control points.
|
/// @param yscale - Scaling factor for Y of all control points.
|
||||||
///
|
///
|
||||||
/// @return True if loaded.
|
/// @return True if loaded.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(const char *filename, float xscale=1.0f, float yscale=1.0f);
|
bool Load(const char *filename, float xscale=1.0f, float yscale=1.0f);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Add a control point to the spline.
|
/// Add a control point to the spline.
|
||||||
///
|
///
|
||||||
/// @param pt - Control point.
|
/// @param pt - Control point.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void AddControlPoint(const Point &pt);
|
void AddControlPoint(const Point &pt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get a control point of the spline.
|
/// Get a control point of the spline.
|
||||||
///
|
///
|
||||||
/// @param index - Control point index.
|
/// @param index - Control point index.
|
||||||
///
|
///
|
||||||
/// @return Control point.
|
/// @return Control point.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void GetControlPoint(Point &point, int index);
|
void GetControlPoint(Point &point, int index);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Work out all pixels of the spline.
|
/// Work out all pixels of the spline.
|
||||||
///
|
///
|
||||||
/// @note Have to call this function before calling GetPixel, GetPixelCount
|
/// @note Have to call this function before calling GetPixel, GetPixelCount
|
||||||
/// and Render.
|
/// and Render.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void GeneratePixels();
|
void GeneratePixels();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get a point between 2nd and 3rd control point.
|
/// 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 t - Fraction of the curve between 2nd and 3rd control point. (0.0f ~ 1.0f)
|
||||||
/// @param p0 - 1st control point.
|
/// @param p0 - 1st control point.
|
||||||
/// @param p1 - 2nd control point.
|
/// @param p1 - 2nd control point.
|
||||||
/// @param p2 - 3rd control point.
|
/// @param p2 - 3rd control point.
|
||||||
/// @param p3 - 4th control point.
|
/// @param p3 - 4th control point.
|
||||||
///
|
///
|
||||||
/// @return Position of the desire 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);
|
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.
|
/// Get a number of pixels for this spline.
|
||||||
///
|
///
|
||||||
/// @return Number of pixels for this spline.
|
/// @return Number of pixels for this spline.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetPixelCount();
|
int GetPixelCount();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get a pixel on the spline.
|
/// Get a pixel on the spline.
|
||||||
///
|
///
|
||||||
/// @param index - Pixel index.
|
/// @param index - Pixel index.
|
||||||
///
|
///
|
||||||
/// @return Position of the desire point.
|
/// @return Position of the desire point.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void GetPixel(Point &point, int index);
|
void GetPixel(Point &point, int index);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render the spline to screen.
|
/// 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));
|
void Render(float x, float y, PIXEL_TYPE color=ARGB(255,255,255,255), PIXEL_TYPE controlColor=ARGB(192,0,192,0));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
vector<Point> mMidPoints;
|
vector<Point> mMidPoints;
|
||||||
vector<Point> mPixels;
|
vector<Point> mPixels;
|
||||||
int mCount;
|
int mCount;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+487
-487
@@ -1,487 +1,487 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _SPRITE_H_
|
#ifndef _SPRITE_H_
|
||||||
#define _SPRITE_H_
|
#define _SPRITE_H_
|
||||||
|
|
||||||
#if defined (WIN32) || defined(LINUX) || defined(IOS)
|
#if defined (WIN32) || defined(LINUX) || defined(IOS)
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#else
|
#else
|
||||||
#include <fastmath.h>
|
#include <fastmath.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "JRenderer.h"
|
#include "JRenderer.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Sprite is a container of single static image or animation frames.
|
/// Sprite is a container of single static image or animation frames.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JSprite
|
class JSprite
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param tex - Texture for the first frame and the following frames.
|
/// @param tex - Texture for the first frame and the following frames.
|
||||||
/// NULL to indicate no starting frame.
|
/// NULL to indicate no starting frame.
|
||||||
/// @param x - X of the frame in texture.
|
/// @param x - X of the frame in texture.
|
||||||
/// @param y - Y of the frame in texture.
|
/// @param y - Y of the frame in texture.
|
||||||
/// @param width - Width of the frame.
|
/// @param width - Width of the frame.
|
||||||
/// @param height - Height of the frame.
|
/// @param height - Height of the frame.
|
||||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
/// @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);
|
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();
|
virtual ~JSprite();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Update animation.
|
/// Update animation.
|
||||||
///
|
///
|
||||||
/// @param dt - Delta time since last update (in second).
|
/// @param dt - Delta time since last update (in second).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Update(float dt);
|
virtual void Update(float dt);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render current frame.
|
/// Render current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set animation type.
|
/// Set animation type.
|
||||||
///
|
///
|
||||||
/// @param type - Animation type.
|
/// @param type - Animation type.
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
/// ANIMATION_TYPE_LOOPING - Repeat playing (Default).
|
/// ANIMATION_TYPE_LOOPING - Repeat playing (Default).
|
||||||
/// ANIMATION_TYPE_ONCE_AND_GONE - Play animation once only.
|
/// 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_ONCE_AND_BACK - Play to end and then stay at first frame.
|
||||||
/// ANIMATION_TYPE_PINGPONG - Play forward then backward and repeat.
|
/// ANIMATION_TYPE_PINGPONG - Play forward then backward and repeat.
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetAnimationType(int type);
|
void SetAnimationType(int type);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Enable/Disable sprite.
|
/// Enable/Disable sprite.
|
||||||
///
|
///
|
||||||
/// @param f - True to enable, false to disable.
|
/// @param f - True to enable, false to disable.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetActive(bool f);
|
void SetActive(bool f);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get current active status.
|
/// Get current active status.
|
||||||
///
|
///
|
||||||
/// @return Active status.
|
/// @return Active status.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsActive();
|
bool IsActive();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Give sprite an id.
|
/// Give sprite an id.
|
||||||
///
|
///
|
||||||
/// @param id - Id.
|
/// @param id - Id.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetId(int id);
|
void SetId(int id);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get sprite id.
|
/// Get sprite id.
|
||||||
///
|
///
|
||||||
/// @return Sprite id.
|
/// @return Sprite id.
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetId();
|
int GetId();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Flip a frame or all frames horizontally when rendering.
|
/// Flip a frame or all frames horizontally when rendering.
|
||||||
///
|
///
|
||||||
/// @param flip - True to flip.
|
/// @param flip - True to flip.
|
||||||
/// @param index - Frame index, -1 to flip all frames.
|
/// @param index - Frame index, -1 to flip all frames.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetFlip(bool flip, int index = -1);
|
void SetFlip(bool flip, int index = -1);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Add new animation frame.
|
/// Add new animation frame.
|
||||||
///
|
///
|
||||||
/// @param x - X of the frame in texture.
|
/// @param x - X of the frame in texture.
|
||||||
/// @param y - Y of the frame in texture.
|
/// @param y - Y of the frame in texture.
|
||||||
/// @param width - Width of the frame.
|
/// @param width - Width of the frame.
|
||||||
/// @param height - Height of the frame.
|
/// @param height - Height of the frame.
|
||||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void AddFrame(float x, float y, float width, float height, bool flipped = false);
|
void AddFrame(float x, float y, float width, float height, bool flipped = false);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Add new animation frame.
|
/// Add new animation frame.
|
||||||
///
|
///
|
||||||
/// @param tex - Texture for this frame and the following frames.
|
/// @param tex - Texture for this frame and the following frames.
|
||||||
/// @param x - X of the frame in texture.
|
/// @param x - X of the frame in texture.
|
||||||
/// @param y - Y of the frame in texture.
|
/// @param y - Y of the frame in texture.
|
||||||
/// @param width - Width of the frame.
|
/// @param width - Width of the frame.
|
||||||
/// @param height - Height of the frame.
|
/// @param height - Height of the frame.
|
||||||
/// @param flipped - Indicate if the frame is horizontally flipped.
|
/// @param flipped - Indicate if the frame is horizontally flipped.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void AddFrame(JTexture *tex, float x, float y, float width, float height, bool flipped = false);
|
void AddFrame(JTexture *tex, float x, float y, float width, float height, bool flipped = false);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set playback duration for each frame.
|
/// Set playback duration for each frame.
|
||||||
///
|
///
|
||||||
/// @param duration - Playback duration (in second) for each frame.
|
/// @param duration - Playback duration (in second) for each frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetDuration(float duration);
|
void SetDuration(float duration);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get index of current frame.
|
/// Get index of current frame.
|
||||||
///
|
///
|
||||||
/// @return Index of current frame.
|
/// @return Index of current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetCurrentFrameIndex();
|
int GetCurrentFrameIndex();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set current frame to a particular index.
|
/// Set current frame to a particular index.
|
||||||
///
|
///
|
||||||
/// @param frame - The new index of current frame.
|
/// @param frame - The new index of current frame.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetCurrentFrameIndex(int frame);
|
void SetCurrentFrameIndex(int frame);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get current frame image (quad).
|
/// Get current frame image (quad).
|
||||||
///
|
///
|
||||||
/// @return Quad object.
|
/// @return Quad object.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JQuad* GetCurrentFrame();
|
JQuad* GetCurrentFrame();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get numer of animation frames.
|
/// Get numer of animation frames.
|
||||||
///
|
///
|
||||||
/// @return Numer of animation frames.
|
/// @return Numer of animation frames.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetFrameCount();
|
int GetFrameCount();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get frame image (quad).
|
/// Get frame image (quad).
|
||||||
///
|
///
|
||||||
/// @return Quad object.
|
/// @return Quad object.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JQuad* GetFrame(int index);
|
JQuad* GetFrame(int index);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Restart animation.
|
/// Restart animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RestartAnimation();
|
void RestartAnimation();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Start animation.
|
/// Start animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StartAnimation();
|
void StartAnimation();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Stop animation.
|
/// Stop animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void StopAnimation();
|
void StopAnimation();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get animation status.
|
/// Get animation status.
|
||||||
///
|
///
|
||||||
/// @return animation status
|
/// @return animation status
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool IsAnimating();
|
bool IsAnimating();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Move some distance from the current position.
|
/// Move some distance from the current position.
|
||||||
///
|
///
|
||||||
/// @param x - X distance to move.
|
/// @param x - X distance to move.
|
||||||
/// @param y - Y distance to move.
|
/// @param y - Y distance to move.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Move(float x, float y);
|
void Move(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set position of the sprite.
|
/// Set position of the sprite.
|
||||||
///
|
///
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetPosition(float x, float y);
|
void SetPosition(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set X position of the sprite.
|
/// Set X position of the sprite.
|
||||||
///
|
///
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetX(float x);
|
void SetX(float x);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set Y position of the sprite.
|
/// Set Y position of the sprite.
|
||||||
///
|
///
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetY(float y);
|
void SetY(float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get X position of the sprite.
|
/// Get X position of the sprite.
|
||||||
///
|
///
|
||||||
/// @return X position.
|
/// @return X position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetX();
|
float GetX();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get Y position of the sprite.
|
/// Get Y position of the sprite.
|
||||||
///
|
///
|
||||||
/// @return Y position.
|
/// @return Y position.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetY();
|
float GetY();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get X velocity.
|
/// Get X velocity.
|
||||||
///
|
///
|
||||||
/// @return X velocity.
|
/// @return X velocity.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetXVelocity();
|
float GetXVelocity();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get Y velocity.
|
/// Get Y velocity.
|
||||||
///
|
///
|
||||||
/// @return Y velocity.
|
/// @return Y velocity.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetYVelocity();
|
float GetYVelocity();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set alpha value for rendering.
|
/// Set alpha value for rendering.
|
||||||
///
|
///
|
||||||
/// @param alpha - Alpha value.
|
/// @param alpha - Alpha value.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetAlpha(float alpha);
|
void SetAlpha(float alpha);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get alpha value.
|
/// Get alpha value.
|
||||||
///
|
///
|
||||||
/// @return Alpha value.
|
/// @return Alpha value.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetAlpha();
|
float GetAlpha();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set scale of the sprite.
|
/// Set scale of the sprite.
|
||||||
///
|
///
|
||||||
/// @param hscale - Horizontal scale.
|
/// @param hscale - Horizontal scale.
|
||||||
/// @param vscale - Vertical scale.
|
/// @param vscale - Vertical scale.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetScale(float hscale, float vscale);
|
void SetScale(float hscale, float vscale);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set scale of the sprite.
|
/// Set scale of the sprite.
|
||||||
///
|
///
|
||||||
/// @param scale - Scale for both horizontal and vertical dimension.
|
/// @param scale - Scale for both horizontal and vertical dimension.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetScale(float scale);
|
void SetScale(float scale);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get scale of the sprite.
|
/// Get scale of the sprite.
|
||||||
///
|
///
|
||||||
/// @return Scale of horizontal (assume same as the vertical).
|
/// @return Scale of horizontal (assume same as the vertical).
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetScale();
|
float GetScale();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set rotation factor of the sprite.
|
/// Set rotation factor of the sprite.
|
||||||
///
|
///
|
||||||
/// @param rot - Rotation angle in radian.
|
/// @param rot - Rotation angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetRotation(float rot);
|
void SetRotation(float rot);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get rotation factor of the sprite.
|
/// Get rotation factor of the sprite.
|
||||||
///
|
///
|
||||||
/// @return Rotation angle in radian.
|
/// @return Rotation angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetRotation();
|
float GetRotation();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set moving speed of the sprite.
|
/// Set moving speed of the sprite.
|
||||||
///
|
///
|
||||||
/// @param speed - Moving speed.
|
/// @param speed - Moving speed.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetSpeed(float speed);
|
void SetSpeed(float speed);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get moving speed of the sprite.
|
/// Get moving speed of the sprite.
|
||||||
///
|
///
|
||||||
/// @return Moving speed.
|
/// @return Moving speed.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetSpeed();
|
float GetSpeed();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set moving direction of the sprite.
|
/// Set moving direction of the sprite.
|
||||||
///
|
///
|
||||||
/// @param angle - Moving angle in radian.
|
/// @param angle - Moving angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetDirection(float angle);
|
void SetDirection(float angle);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set moving direction of the sprite based on a targeting position.
|
/// Set moving direction of the sprite based on a targeting position.
|
||||||
///
|
///
|
||||||
/// @param x - X position of the target.
|
/// @param x - X position of the target.
|
||||||
/// @param y - Y position of the target.
|
/// @param y - Y position of the target.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetDirection(float x, float y);
|
void SetDirection(float x, float y);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get moving direction of the sprite.
|
/// Get moving direction of the sprite.
|
||||||
///
|
///
|
||||||
/// @return Moving angle in radian.
|
/// @return Moving angle in radian.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
float GetDirection();
|
float GetDirection();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set anchor point of a frame or all frames of the sprite. All rotation
|
/// Set anchor point of a frame or all frames of the sprite. All rotation
|
||||||
/// and collision operations are based on this anchor point.
|
/// and collision operations are based on this anchor point.
|
||||||
///
|
///
|
||||||
/// @param x - X position of the anchor point.
|
/// @param x - X position of the anchor point.
|
||||||
/// @param y - Y position of the anchor point.
|
/// @param y - Y position of the anchor point.
|
||||||
/// @param index - Frame index, -1 for all frames.
|
/// @param index - Frame index, -1 for all frames.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetHotSpot(float x, float y, int index=-1);
|
void SetHotSpot(float x, float y, int index=-1);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set color of the sprite for rendering.
|
/// Set color of the sprite for rendering.
|
||||||
///
|
///
|
||||||
/// @param color - Color.
|
/// @param color - Color.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetColor(PIXEL_TYPE color);
|
void SetColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// \enum ANIMATION_TYPE
|
/// \enum ANIMATION_TYPE
|
||||||
///
|
///
|
||||||
/// Type of animation.
|
/// Type of animation.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum ANIMATION_TYPE
|
enum ANIMATION_TYPE
|
||||||
{
|
{
|
||||||
ANIMATION_TYPE_LOOPING, ///< Repeat playing (Default).
|
ANIMATION_TYPE_LOOPING, ///< Repeat playing (Default).
|
||||||
ANIMATION_TYPE_ONCE_AND_STAY, ///< Play to the end and stay at last frame
|
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_BACK, ///< Play to end and then stay at first frame.
|
||||||
ANIMATION_TYPE_ONCE_AND_GONE, ///< Play animation once only.
|
ANIMATION_TYPE_ONCE_AND_GONE, ///< Play animation once only.
|
||||||
ANIMATION_TYPE_PINGPONG ///< Play forward then backward and repeat.
|
ANIMATION_TYPE_PINGPONG ///< Play forward then backward and repeat.
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static JRenderer* mRenderer;
|
static JRenderer* mRenderer;
|
||||||
|
|
||||||
JTexture* mTex;
|
JTexture* mTex;
|
||||||
vector<JQuad*> mFrames;
|
vector<JQuad*> mFrames;
|
||||||
float mDuration;
|
float mDuration;
|
||||||
float mTimer;
|
float mTimer;
|
||||||
int mFrameCount;
|
int mFrameCount;
|
||||||
int mCurrentFrame;
|
int mCurrentFrame;
|
||||||
int mAnimationType;
|
int mAnimationType;
|
||||||
int mDelta;
|
int mDelta;
|
||||||
bool mAnimating;
|
bool mAnimating;
|
||||||
|
|
||||||
float mAlpha;
|
float mAlpha;
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
|
|
||||||
float mVScale;
|
float mVScale;
|
||||||
float mHScale;
|
float mHScale;
|
||||||
|
|
||||||
float mRotation;
|
float mRotation;
|
||||||
float mDirection;
|
float mDirection;
|
||||||
float mSpeed;
|
float mSpeed;
|
||||||
|
|
||||||
int mId;
|
int mId;
|
||||||
bool mActive;
|
bool mActive;
|
||||||
|
|
||||||
float mX;
|
float mX;
|
||||||
float mY;
|
float mY;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class JSpriteList
|
class JSpriteList
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
int mCount;
|
int mCount;
|
||||||
JSprite** mList;
|
JSprite** mList;
|
||||||
//JSpriteList** mVictims;
|
//JSpriteList** mVictims;
|
||||||
//JCollisionListener* mCollisionListener;
|
//JCollisionListener* mCollisionListener;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JSpriteList(int count);
|
JSpriteList(int count);
|
||||||
~JSpriteList();
|
~JSpriteList();
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void Render();
|
void Render();
|
||||||
void AddSprite(JSprite* sprite);//, JSpriteList* victim);
|
void AddSprite(JSprite* sprite);//, JSpriteList* victim);
|
||||||
|
|
||||||
//bool CheckCollision(JSprite* sprite); // check collision against the provided list
|
//bool CheckCollision(JSprite* sprite); // check collision against the provided list
|
||||||
//void SetCollisionListener(JCollisionListener *listener);
|
//void SetCollisionListener(JCollisionListener *listener);
|
||||||
JSprite* Activate(float x, float y);
|
JSprite* Activate(float x, float y);
|
||||||
void Activate(float x, float y, int index);
|
void Activate(float x, float y, int index);
|
||||||
|
|
||||||
JSprite* GetSprite(int index);
|
JSprite* GetSprite(int index);
|
||||||
|
|
||||||
void EnableAll(bool flag);
|
void EnableAll(bool flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+307
-307
@@ -1,307 +1,307 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _JTTFONT_H
|
#ifndef _JTTFONT_H
|
||||||
#define _JTTFONT_H
|
#define _JTTFONT_H
|
||||||
|
|
||||||
#include "../../JGE/include/JGE.h"
|
#include "../../JGE/include/JGE.h"
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include <freetype/freetype.h>
|
#include <freetype/freetype.h>
|
||||||
|
|
||||||
#define TTF_CACHE_SIZE 256
|
#define TTF_CACHE_SIZE 256
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// True Type font support with the help of Freetype library. JTTFont has
|
/// 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
|
/// 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
|
/// can be retrieved from the cache instead of drawing it again by the
|
||||||
/// Freetype library. This can give you a much faster rendering speed.
|
/// Freetype library. This can give you a much faster rendering speed.
|
||||||
/// Also, if you only need to use a limited number of characters
|
/// 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
|
/// in your game, you can actually cache all your characters in the cache
|
||||||
/// beforehand and unload the font to save memory.
|
/// beforehand and unload the font to save memory.
|
||||||
///
|
///
|
||||||
/// @par For example, if you only want to use the standard ASCII characters in
|
/// @par For example, if you only want to use the standard ASCII characters in
|
||||||
/// your game:
|
/// your game:
|
||||||
///
|
///
|
||||||
/// @code
|
/// @code
|
||||||
///
|
///
|
||||||
/// // in Create()
|
/// // in Create()
|
||||||
/// mTTFont = new JTTFont();
|
/// mTTFont = new JTTFont();
|
||||||
/// mTTFont->Load("arial.ttf", 32); // size 32
|
/// mTTFont->Load("arial.ttf", 32); // size 32
|
||||||
///
|
///
|
||||||
/// if (mTTFont->PreCacheASCII())
|
/// if (mTTFont->PreCacheASCII())
|
||||||
/// mTTFont->Unload();
|
/// mTTFont->Unload();
|
||||||
/// ...
|
/// ...
|
||||||
///
|
///
|
||||||
/// // in Render()
|
/// // in Render()
|
||||||
/// mTTFont->RenderString("Hello World!", 240, 80, JGETEXT_CENTER);
|
/// mTTFont->RenderString("Hello World!", 240, 80, JGETEXT_CENTER);
|
||||||
///
|
///
|
||||||
/// @endcode
|
/// @endcode
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
class JTTFont
|
class JTTFont
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
///
|
///
|
||||||
/// @param cacheImageSize - Size of the texture used for caching. This can
|
/// @param cacheImageSize - Size of the texture used for caching. This can
|
||||||
/// be 64x64, 128x128(default), 256x256 or 512x512.
|
/// be 64x64, 128x128(default), 256x256 or 512x512.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JTTFont(int cacheImageSize=CACHE_IMAGE_256x256);
|
JTTFont(int cacheImageSize=CACHE_IMAGE_256x256);
|
||||||
|
|
||||||
~JTTFont();
|
~JTTFont();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// \enum FONT_LOADING_MODE
|
/// \enum FONT_LOADING_MODE
|
||||||
///
|
///
|
||||||
/// Font loading options.
|
/// Font loading options.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum FONT_LOADING_MODE
|
enum FONT_LOADING_MODE
|
||||||
{
|
{
|
||||||
MODE_NORMAL, ///< Load only.
|
MODE_NORMAL, ///< Load only.
|
||||||
MODE_PRECACHE_ASCII, ///< Load the font and cache all ASCII characters.
|
MODE_PRECACHE_ASCII, ///< Load the font and cache all ASCII characters.
|
||||||
MODE_PRECACHE_ASCII_EX ///< Load the font and cache all Extended ASCII characters.
|
MODE_PRECACHE_ASCII_EX ///< Load the font and cache all Extended ASCII characters.
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// \enum CACHE_IMAGE_SIZE
|
/// \enum CACHE_IMAGE_SIZE
|
||||||
///
|
///
|
||||||
/// Size of the texture used for caching.
|
/// Size of the texture used for caching.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
enum CACHE_IMAGE_SIZE
|
enum CACHE_IMAGE_SIZE
|
||||||
{
|
{
|
||||||
CACHE_IMAGE_64x64, ///< 64x64
|
CACHE_IMAGE_64x64, ///< 64x64
|
||||||
CACHE_IMAGE_128x128, ///< 128x128
|
CACHE_IMAGE_128x128, ///< 128x128
|
||||||
CACHE_IMAGE_256x256, ///< 256x256
|
CACHE_IMAGE_256x256, ///< 256x256
|
||||||
CACHE_IMAGE_512x512 ///< 512x512
|
CACHE_IMAGE_512x512 ///< 512x512
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set color of font.
|
/// Set color of font.
|
||||||
///
|
///
|
||||||
/// @param color - Font color.
|
/// @param color - Font color.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetColor(PIXEL_TYPE color);
|
void SetColor(PIXEL_TYPE color);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set angle of the font for rendering.
|
/// Set angle of the font for rendering.
|
||||||
///
|
///
|
||||||
/// @param angle - Angle in radians.
|
/// @param angle - Angle in radians.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void SetAngle(float angle);
|
void SetAngle(float angle);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Set font size.
|
/// Set font size.
|
||||||
///
|
///
|
||||||
/// @param size - Font size.
|
/// @param size - Font size.
|
||||||
///
|
///
|
||||||
/// @note Setting font size will clear the cache.
|
/// @note Setting font size will clear the cache.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool SetSize(int size);
|
bool SetSize(int size);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Load font file.
|
/// Load font file.
|
||||||
///
|
///
|
||||||
/// @param filename - Name of True Type font.
|
/// @param filename - Name of True Type font.
|
||||||
/// @param size - Initial font size. Default is 12.
|
/// @param size - Initial font size. Default is 12.
|
||||||
/// @param mode - Loading mode.
|
/// @param mode - Loading mode.
|
||||||
///
|
///
|
||||||
/// @return - True if no error.
|
/// @return - True if no error.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(const char *filename, int size=12, int mode=MODE_NORMAL);
|
bool Load(const char *filename, int size=12, int mode=MODE_NORMAL);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Create font using font data from another JTTFont instance.
|
/// Create font using font data from another JTTFont instance.
|
||||||
///
|
///
|
||||||
/// @param fontSource - Source of font data.
|
/// @param fontSource - Source of font data.
|
||||||
/// @param size - Initial font size. Default is 12.
|
/// @param size - Initial font size. Default is 12.
|
||||||
/// @param mode - Loading mode.
|
/// @param mode - Loading mode.
|
||||||
///
|
///
|
||||||
/// @return - True if no error.
|
/// @return - True if no error.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool Load(JTTFont *fontSource, int size=12, int mode=MODE_NORMAL);
|
bool Load(JTTFont *fontSource, int size=12, int mode=MODE_NORMAL);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Unload font file and related Freetype objects from memory.
|
/// Unload font file and related Freetype objects from memory.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void Unload(void);
|
void Unload(void);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render Unicode string to screen.
|
/// Render Unicode string to screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated Unicode-16 string.
|
/// @param text - NULL terminated Unicode-16 string.
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RenderString(const u16 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
void RenderString(const u16 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render ASCII string to screen.
|
/// Render ASCII string to screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated ASCII string.
|
/// @param text - NULL terminated ASCII string.
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RenderString(const char *text, float x, float y, int alignment=JGETEXT_LEFT);
|
void RenderString(const char *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Render Chinese (GBK) string to screen.
|
/// Render Chinese (GBK) string to screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated GBK encoded string.
|
/// @param text - NULL terminated GBK encoded string.
|
||||||
/// @param x - X position.
|
/// @param x - X position.
|
||||||
/// @param y - Y position.
|
/// @param y - Y position.
|
||||||
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
/// @param alignment - Text alignment: JGETEXT_LEFT, JGETEXT_RIGHT, JGETEXT_CENTER
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void RenderString(const u8 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
void RenderString(const u8 *text, float x, float y, int alignment=JGETEXT_LEFT);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put characters of an Unicode string into cache
|
/// Put characters of an Unicode string into cache
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated Unicode-16 string.
|
/// @param text - NULL terminated Unicode-16 string.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void PreCacheString(const u16 *text);
|
void PreCacheString(const u16 *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put characters of an ASCII string into cache.
|
/// Put characters of an ASCII string into cache.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated ASCII string.
|
/// @param text - NULL terminated ASCII string.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void PreCacheString(const char *text);
|
void PreCacheString(const char *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put characters of a Chinese (GBK) string into cache.
|
/// Put characters of a Chinese (GBK) string into cache.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated GBK encoded string.
|
/// @param text - NULL terminated GBK encoded string.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
void PreCacheString(const u8 *text);
|
void PreCacheString(const u8 *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get width of Unicode string on screen.
|
/// Get width of Unicode string on screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated Unicode-16 string.
|
/// @param text - NULL terminated Unicode-16 string.
|
||||||
///
|
///
|
||||||
/// @return - Width in pixels
|
/// @return - Width in pixels
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetWidth(const u16 *text);
|
int GetWidth(const u16 *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get width of ASCII string on screen.
|
/// Get width of ASCII string on screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated ASCII string.
|
/// @param text - NULL terminated ASCII string.
|
||||||
///
|
///
|
||||||
/// @return - Width in pixels
|
/// @return - Width in pixels
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetWidth(const char *text);
|
int GetWidth(const char *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Get width of Chinese (GBK) string on screen.
|
/// Get width of Chinese (GBK) string on screen.
|
||||||
///
|
///
|
||||||
/// @param text - NULL terminated GBK encoded string.
|
/// @param text - NULL terminated GBK encoded string.
|
||||||
///
|
///
|
||||||
/// @return - Width in pixels
|
/// @return - Width in pixels
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
int GetWidth(const u8 *text);
|
int GetWidth(const u8 *text);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put all standard ASCII characters (0x20-0x7F) into cache.
|
/// Put all standard ASCII characters (0x20-0x7F) into cache.
|
||||||
///
|
///
|
||||||
/// @return - True if success.
|
/// @return - True if success.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool PreCacheASCII();
|
bool PreCacheASCII();
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Put all ASCII characters (0x20-0xFF) into cache.
|
/// Put all ASCII characters (0x20-0xFF) into cache.
|
||||||
///
|
///
|
||||||
/// @return - True if success.
|
/// @return - True if success.
|
||||||
///
|
///
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool PreCacheExtendedASCII();
|
bool PreCacheExtendedASCII();
|
||||||
|
|
||||||
void SetAntialias(bool flag);
|
void SetAntialias(bool flag);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FT_Library GetFontLibrary();
|
FT_Library GetFontLibrary();
|
||||||
FT_Byte* GetFontBits();
|
FT_Byte* GetFontBits();
|
||||||
int GetFontBitsSize();
|
int GetFontBitsSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int RenderString(const u16 *text, float x, float y, bool render);
|
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 char *text, float x, float y, bool render);
|
||||||
int RenderString(const u8 *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 PreCacheChar(u16 ch, u16 cachedCode);
|
||||||
int GetCachedChar(u16 cachedCode);
|
int GetCachedChar(u16 cachedCode);
|
||||||
void DrawBitmap(void *image, FT_Bitmap *bitmap, FT_Int x, FT_Int y, int width, int height);
|
void DrawBitmap(void *image, FT_Bitmap *bitmap, FT_Int x, FT_Int y, int width, int height);
|
||||||
|
|
||||||
|
|
||||||
JTexture* mTexture;
|
JTexture* mTexture;
|
||||||
|
|
||||||
JQuad* mQuads[TTF_CACHE_SIZE];
|
JQuad* mQuads[TTF_CACHE_SIZE];
|
||||||
u16 mCachedCode[TTF_CACHE_SIZE];
|
u16 mCachedCode[TTF_CACHE_SIZE];
|
||||||
u8 mXAdvance[TTF_CACHE_SIZE];
|
u8 mXAdvance[TTF_CACHE_SIZE];
|
||||||
|
|
||||||
int mCurr;
|
int mCurr;
|
||||||
|
|
||||||
int mTexWidth;
|
int mTexWidth;
|
||||||
int mTexHeight;
|
int mTexHeight;
|
||||||
int mMaxCharWidth;
|
int mMaxCharWidth;
|
||||||
int mMaxCharHeight;
|
int mMaxCharHeight;
|
||||||
int mMaxCharCount;
|
int mMaxCharCount;
|
||||||
int mColCount;
|
int mColCount;
|
||||||
int mRowCount;
|
int mRowCount;
|
||||||
|
|
||||||
bool mASCIIDirectMapping;
|
bool mASCIIDirectMapping;
|
||||||
|
|
||||||
JTTFont* mFontSource;
|
JTTFont* mFontSource;
|
||||||
bool mSharingFont;
|
bool mSharingFont;
|
||||||
|
|
||||||
int mSize;
|
int mSize;
|
||||||
PIXEL_TYPE mColor;
|
PIXEL_TYPE mColor;
|
||||||
float mAngle;
|
float mAngle;
|
||||||
FT_Library mLibrary;
|
FT_Library mLibrary;
|
||||||
FT_Face mFace;
|
FT_Face mFace;
|
||||||
|
|
||||||
FT_Byte* mFontBits;
|
FT_Byte* mFontBits;
|
||||||
int mFontBitsSize;
|
int mFontBitsSize;
|
||||||
|
|
||||||
bool mAntialias;
|
bool mAntialias;
|
||||||
|
|
||||||
bool mFontLoaded;
|
bool mFontLoaded;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+73
-73
@@ -1,73 +1,73 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _VECTOR2D_H
|
#ifndef _VECTOR2D_H
|
||||||
#define _VECTOR2D_H
|
#define _VECTOR2D_H
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#elif (defined LINUX) || (defined IOS)
|
#elif (defined LINUX) || (defined IOS)
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#else
|
#else
|
||||||
#include <fastmath.h>
|
#include <fastmath.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct Vector2D
|
struct Vector2D
|
||||||
{
|
{
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
static const Vector2D& Blank() { static const Vector2D V(0, 0); return V; }
|
static const Vector2D& Blank() { static const Vector2D V(0, 0); return V; }
|
||||||
|
|
||||||
inline Vector2D(void) {}
|
inline Vector2D(void) {}
|
||||||
|
|
||||||
inline Vector2D(float _x,float _y) : x(_x), y(_y) {}
|
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 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 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; }
|
||||||
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
|
// cross product
|
||||||
inline float operator ^ (const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
inline float operator ^ (const Vector2D &v) const { return (x * v.y) - (y * v.x); }
|
||||||
|
|
||||||
// dot product
|
// dot product
|
||||||
inline float operator * (const Vector2D &v) const { return (x*v.x) + (y*v.y); }
|
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 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 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 / (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); }
|
||||||
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); }
|
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 Vector2D operator -(void) const { return Vector2D(-x, -y); }
|
||||||
|
|
||||||
inline float Length(void) const;
|
inline float Length(void) const;
|
||||||
float Normalize(void) ;
|
float Normalize(void) ;
|
||||||
Vector2D Direction(void) const;
|
Vector2D Direction(void) const;
|
||||||
float Angle(const Vector2D& xE);
|
float Angle(const Vector2D& xE);
|
||||||
Vector2D& Rotate(float angle);
|
Vector2D& Rotate(float angle);
|
||||||
Vector2D& Rotate(const Vector2D& xCentre, float fAngle);
|
Vector2D& Rotate(const Vector2D& xCentre, float fAngle);
|
||||||
void Clamp(const Vector2D& min, const Vector2D& max);
|
void Clamp(const Vector2D& min, const Vector2D& max);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+95
-95
@@ -1,95 +1,95 @@
|
|||||||
#ifndef __VECTOR3D_H_
|
#ifndef __VECTOR3D_H_
|
||||||
#define __VECTOR3D_H_
|
#define __VECTOR3D_H_
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
/*************************** Macros and constants ***************************/
|
/*************************** Macros and constants ***************************/
|
||||||
// returns a number ranging from -1.0 to 1.0
|
// returns a number ranging from -1.0 to 1.0
|
||||||
#define FRAND (((float)rand()-(float)rand())/RAND_MAX)
|
#define FRAND (((float)rand()-(float)rand())/RAND_MAX)
|
||||||
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
#define Clamp(x, min, max) x = (x<min ? min : x<max ? x : max);
|
||||||
|
|
||||||
#define SQUARE(x) (x)*(x)
|
#define SQUARE(x) (x)*(x)
|
||||||
|
|
||||||
|
|
||||||
struct Vector3D
|
struct Vector3D
|
||||||
{
|
{
|
||||||
Vector3D(float x, float y, float z) : x(x), y(y), z(z) {}
|
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(const Vector3D &v) : x(v.x), y(v.y), z(v.z) {}
|
||||||
Vector3D() : x(0.0f), y(0.0f), z(0.0f) {}
|
Vector3D() : x(0.0f), y(0.0f), z(0.0f) {}
|
||||||
|
|
||||||
Vector3D& operator=(const Vector3D &rhs)
|
Vector3D& operator=(const Vector3D &rhs)
|
||||||
{
|
{
|
||||||
x = rhs.x;
|
x = rhs.x;
|
||||||
y = rhs.y;
|
y = rhs.y;
|
||||||
z = rhs.z;
|
z = rhs.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// vector add
|
// vector add
|
||||||
Vector3D operator+(const Vector3D &rhs) const
|
Vector3D operator+(const Vector3D &rhs) const
|
||||||
{
|
{
|
||||||
return Vector3D(x + rhs.x, y + rhs.y, z + rhs.z);
|
return Vector3D(x + rhs.x, y + rhs.y, z + rhs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
// vector subtract
|
// vector subtract
|
||||||
Vector3D operator-(const Vector3D &rhs) const
|
Vector3D operator-(const Vector3D &rhs) const
|
||||||
{
|
{
|
||||||
return Vector3D(x - rhs.x, y - rhs.y, z - rhs.z);
|
return Vector3D(x - rhs.x, y - rhs.y, z - rhs.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scalar multiplication
|
// scalar multiplication
|
||||||
Vector3D operator*(const float scalar) const
|
Vector3D operator*(const float scalar) const
|
||||||
{
|
{
|
||||||
return Vector3D(x * scalar, y * scalar, z * scalar);
|
return Vector3D(x * scalar, y * scalar, z * scalar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dot product
|
// dot product
|
||||||
float operator*(const Vector3D &rhs) const
|
float operator*(const Vector3D &rhs) const
|
||||||
{
|
{
|
||||||
return x * rhs.x + y * rhs.y + z * rhs.z;
|
return x * rhs.x + y * rhs.y + z * rhs.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cross product
|
// cross product
|
||||||
Vector3D operator^(const Vector3D &rhs) const
|
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);
|
return Vector3D(y * rhs.z - rhs.y * z, rhs.x * z - x * rhs.z, x * rhs.y - rhs.x * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
float& operator[](int index)
|
float& operator[](int index)
|
||||||
{
|
{
|
||||||
return v[index];
|
return v[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Length()
|
float Length()
|
||||||
{
|
{
|
||||||
float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
float length = (float)sqrt(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
||||||
return (length != 0.0f) ? length : 1.0f;
|
return (length != 0.0f) ? length : 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
Normalize()
|
Normalize()
|
||||||
|
|
||||||
Helper function to normalize vectors
|
Helper function to normalize vectors
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
Vector3D Normalize()
|
Vector3D Normalize()
|
||||||
{
|
{
|
||||||
*this = *this * (1.0f/Length());
|
*this = *this * (1.0f/Length());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
};
|
};
|
||||||
float v[3];
|
float v[3];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+81
-81
@@ -1,81 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeColor*** helper classes
|
** hgeColor*** helper classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGECOLOR_H
|
#ifndef HGECOLOR_H
|
||||||
#define HGECOLOR_H
|
#define HGECOLOR_H
|
||||||
|
|
||||||
|
|
||||||
//#include "hge.h"
|
//#include "hge.h"
|
||||||
|
|
||||||
#include "../JTypes.h"
|
#include "../JTypes.h"
|
||||||
|
|
||||||
#define hgeColor hgeColorRGB
|
#define hgeColor hgeColorRGB
|
||||||
|
|
||||||
inline void ColorClamp(float &x) { if(x<0.0f) x=0.0f; if(x>1.0f) x=1.0f; }
|
inline void ColorClamp(float &x) { if(x<0.0f) x=0.0f; if(x>1.0f) x=1.0f; }
|
||||||
|
|
||||||
|
|
||||||
class hgeColorRGB
|
class hgeColorRGB
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float r,g,b,a;
|
float r,g,b,a;
|
||||||
|
|
||||||
hgeColorRGB(float _r, float _g, float _b, float _a) { r=_r; g=_g; b=_b; a=_a; }
|
hgeColorRGB(float _r, float _g, float _b, float _a) { r=_r; g=_g; b=_b; a=_a; }
|
||||||
hgeColorRGB(DWORD col) { SetHWColor(col); }
|
hgeColorRGB(DWORD col) { SetHWColor(col); }
|
||||||
hgeColorRGB() { r=g=b=a=0; }
|
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) 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; }
|
||||||
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); }
|
||||||
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) 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; }
|
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 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; }
|
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))); }
|
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; }
|
inline hgeColorRGB operator* (const float sc, const hgeColorRGB &c) { return c*sc; }
|
||||||
|
|
||||||
|
|
||||||
class hgeColorHSV
|
class hgeColorHSV
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float h,s,v,a;
|
float h,s,v,a;
|
||||||
|
|
||||||
hgeColorHSV(float _h, float _s, float _v, float _a) { h=_h; s=_s; v=_v; a=_a; }
|
hgeColorHSV(float _h, float _s, float _v, float _a) { h=_h; s=_s; v=_v; a=_a; }
|
||||||
hgeColorHSV(DWORD col) { SetHWColor(col); }
|
hgeColorHSV(DWORD col) { SetHWColor(col); }
|
||||||
hgeColorHSV() { h=s=v=a=0; }
|
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) 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; }
|
||||||
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); }
|
||||||
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) 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; }
|
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 Clamp() { ColorClamp(h); ColorClamp(s); ColorClamp(v); ColorClamp(a); }
|
||||||
void SetHWColor(DWORD col);
|
void SetHWColor(DWORD col);
|
||||||
DWORD GetHWColor() const;
|
DWORD GetHWColor() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline hgeColorHSV operator* (const float sc, const hgeColorHSV &c) { return c*sc; }
|
inline hgeColorHSV operator* (const float sc, const hgeColorHSV &c) { return c*sc; }
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,70 +1,70 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeDistortionMesh helper class header
|
** hgeDistortionMesh helper class header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGEDISTORT_H
|
#ifndef HGEDISTORT_H
|
||||||
#define HGEDISTORT_H
|
#define HGEDISTORT_H
|
||||||
|
|
||||||
|
|
||||||
//#include "hge.h"
|
//#include "hge.h"
|
||||||
#include "../JTypes.h"
|
#include "../JTypes.h"
|
||||||
|
|
||||||
|
|
||||||
#define HGEDISP_NODE 0
|
#define HGEDISP_NODE 0
|
||||||
#define HGEDISP_TOPLEFT 1
|
#define HGEDISP_TOPLEFT 1
|
||||||
#define HGEDISP_CENTER 2
|
#define HGEDISP_CENTER 2
|
||||||
|
|
||||||
class JTexture;
|
class JTexture;
|
||||||
class JQuad;
|
class JQuad;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** HGE Distortion mesh class
|
** HGE Distortion mesh class
|
||||||
*/
|
*/
|
||||||
class hgeDistortionMesh
|
class hgeDistortionMesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
hgeDistortionMesh(int cols, int rows);
|
hgeDistortionMesh(int cols, int rows);
|
||||||
hgeDistortionMesh(const hgeDistortionMesh &dm);
|
hgeDistortionMesh(const hgeDistortionMesh &dm);
|
||||||
~hgeDistortionMesh();
|
~hgeDistortionMesh();
|
||||||
|
|
||||||
hgeDistortionMesh& operator= (const hgeDistortionMesh &dm);
|
hgeDistortionMesh& operator= (const hgeDistortionMesh &dm);
|
||||||
|
|
||||||
void Render(float x, float y);
|
void Render(float x, float y);
|
||||||
void Clear(PIXEL_TYPE col=ARGB(0xFF,0xFF,0xFF,0xFF), float z=0.5f);
|
void Clear(PIXEL_TYPE col=ARGB(0xFF,0xFF,0xFF,0xFF), float z=0.5f);
|
||||||
|
|
||||||
void SetTexture(JTexture* tex);
|
void SetTexture(JTexture* tex);
|
||||||
void SetTextureRect(float x, float y, float w, float h);
|
void SetTextureRect(float x, float y, float w, float h);
|
||||||
void SetBlendMode(int blend);
|
void SetBlendMode(int blend);
|
||||||
void SetZ(int col, int row, float z);
|
void SetZ(int col, int row, float z);
|
||||||
void SetColor(int col, int row, PIXEL_TYPE color);
|
void SetColor(int col, int row, PIXEL_TYPE color);
|
||||||
void SetDisplacement(int col, int row, float dx, float dy, int ref);
|
void SetDisplacement(int col, int row, float dx, float dy, int ref);
|
||||||
|
|
||||||
JTexture* GetTexture() const {return quad->mTex;}
|
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; }
|
void GetTextureRect(float *x, float *y, float *w, float *h) const { *x=tx; *y=ty; *w=width; *h=height; }
|
||||||
int GetBlendMode() const { return 0; }
|
int GetBlendMode() const { return 0; }
|
||||||
float GetZ(int col, int row) const;
|
float GetZ(int col, int row) const;
|
||||||
PIXEL_TYPE GetColor(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;
|
void GetDisplacement(int col, int row, float *dx, float *dy, int ref) const;
|
||||||
|
|
||||||
int GetRows() { return nRows; }
|
int GetRows() { return nRows; }
|
||||||
int GetCols() { return nCols; }
|
int GetCols() { return nCols; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hgeDistortionMesh();
|
hgeDistortionMesh();
|
||||||
|
|
||||||
//static HGE *hge;
|
//static HGE *hge;
|
||||||
|
|
||||||
Vertex *disp_array;
|
Vertex *disp_array;
|
||||||
int nRows, nCols;
|
int nRows, nCols;
|
||||||
float cellw,cellh;
|
float cellw,cellh;
|
||||||
float tx,ty,width,height;
|
float tx,ty,width,height;
|
||||||
JQuad* quad;
|
JQuad* quad;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+93
-93
@@ -1,93 +1,93 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeFont helper class header
|
** hgeFont helper class header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGEFONT_H
|
#ifndef HGEFONT_H
|
||||||
#define HGEFONT_H
|
#define HGEFONT_H
|
||||||
|
|
||||||
#include "../JTypes.h"
|
#include "../JTypes.h"
|
||||||
//#include "hge.h"
|
//#include "hge.h"
|
||||||
//#include "hgesprite.h"
|
//#include "hgesprite.h"
|
||||||
|
|
||||||
|
|
||||||
#define HGETEXT_LEFT 0
|
#define HGETEXT_LEFT 0
|
||||||
#define HGETEXT_RIGHT 1
|
#define HGETEXT_RIGHT 1
|
||||||
#define HGETEXT_CENTER 2
|
#define HGETEXT_CENTER 2
|
||||||
#define HGETEXT_HORZMASK 0x03
|
#define HGETEXT_HORZMASK 0x03
|
||||||
|
|
||||||
#define HGETEXT_TOP 0
|
#define HGETEXT_TOP 0
|
||||||
#define HGETEXT_BOTTOM 4
|
#define HGETEXT_BOTTOM 4
|
||||||
#define HGETEXT_MIDDLE 8
|
#define HGETEXT_MIDDLE 8
|
||||||
#define HGETEXT_VERTMASK 0x0C
|
#define HGETEXT_VERTMASK 0x0C
|
||||||
|
|
||||||
class JTexture;
|
class JTexture;
|
||||||
class JQuad;
|
class JQuad;
|
||||||
/*
|
/*
|
||||||
** HGE Font class
|
** HGE Font class
|
||||||
*/
|
*/
|
||||||
class hgeFont
|
class hgeFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
hgeFont(const char *filename, bool bMipmap=false);
|
hgeFont(const char *filename, bool bMipmap=false);
|
||||||
~hgeFont();
|
~hgeFont();
|
||||||
|
|
||||||
void Render(float x, float y, int align, const char *string);
|
void Render(float x, float y, int align, const char *string);
|
||||||
void printf(float x, float y, int align, const char *format, ...);
|
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 printfb(float x, float y, float w, float h, int align, const char *format, ...);
|
||||||
|
|
||||||
void SetColor(PIXEL_TYPE col);
|
void SetColor(PIXEL_TYPE col);
|
||||||
void SetZ(float z);
|
void SetZ(float z);
|
||||||
void SetBlendMode(int blend);
|
void SetBlendMode(int blend);
|
||||||
void SetScale(float scale) {fScale=scale;}
|
void SetScale(float scale) {fScale=scale;}
|
||||||
void SetProportion(float prop) { fProportion=prop; }
|
void SetProportion(float prop) { fProportion=prop; }
|
||||||
void SetRotation(float rot) {fRot=rot;}
|
void SetRotation(float rot) {fRot=rot;}
|
||||||
void SetTracking(float tracking) {fTracking=tracking;}
|
void SetTracking(float tracking) {fTracking=tracking;}
|
||||||
void SetSpacing(float spacing) {fSpacing=spacing;}
|
void SetSpacing(float spacing) {fSpacing=spacing;}
|
||||||
|
|
||||||
PIXEL_TYPE GetColor() const {return dwCol;}
|
PIXEL_TYPE GetColor() const {return dwCol;}
|
||||||
float GetZ() const {return fZ;}
|
float GetZ() const {return fZ;}
|
||||||
int GetBlendMode() const {return nBlend;}
|
int GetBlendMode() const {return nBlend;}
|
||||||
float GetScale() const {return fScale;}
|
float GetScale() const {return fScale;}
|
||||||
float GetProportion() const { return fProportion; }
|
float GetProportion() const { return fProportion; }
|
||||||
float GetRotation() const {return fRot;}
|
float GetRotation() const {return fRot;}
|
||||||
float GetTracking() const {return fTracking;}
|
float GetTracking() const {return fTracking;}
|
||||||
float GetSpacing() const {return fSpacing;}
|
float GetSpacing() const {return fSpacing;}
|
||||||
|
|
||||||
JQuad* GetSprite(char chr) const { return letters[(unsigned char)chr]; }
|
JQuad* GetSprite(char chr) const { return letters[(unsigned char)chr]; }
|
||||||
float GetHeight() const { return fHeight; }
|
float GetHeight() const { return fHeight; }
|
||||||
float GetStringWidth(const char *string) const;
|
float GetStringWidth(const char *string) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hgeFont();
|
hgeFont();
|
||||||
hgeFont(const hgeFont &fnt);
|
hgeFont(const hgeFont &fnt);
|
||||||
hgeFont& operator= (const hgeFont &fnt);
|
hgeFont& operator= (const hgeFont &fnt);
|
||||||
|
|
||||||
char* _get_line(char *file, char *line);
|
char* _get_line(char *file, char *line);
|
||||||
|
|
||||||
//static HGE *hge;
|
//static HGE *hge;
|
||||||
|
|
||||||
static char buffer[256];
|
static char buffer[256];
|
||||||
|
|
||||||
JTexture* hTexture;
|
JTexture* hTexture;
|
||||||
JQuad* letters[256];
|
JQuad* letters[256];
|
||||||
float pre[256];
|
float pre[256];
|
||||||
float post[256];
|
float post[256];
|
||||||
float fHeight;
|
float fHeight;
|
||||||
float fScale;
|
float fScale;
|
||||||
float fProportion;
|
float fProportion;
|
||||||
float fRot;
|
float fRot;
|
||||||
float fTracking;
|
float fTracking;
|
||||||
float fSpacing;
|
float fSpacing;
|
||||||
|
|
||||||
PIXEL_TYPE dwCol;
|
PIXEL_TYPE dwCol;
|
||||||
float fZ;
|
float fZ;
|
||||||
int nBlend;
|
int nBlend;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+165
-165
@@ -1,165 +1,165 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeParticleSystem helper class header
|
** hgeParticleSystem helper class header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGEPARTICLE_H
|
#ifndef HGEPARTICLE_H
|
||||||
#define HGEPARTICLE_H
|
#define HGEPARTICLE_H
|
||||||
|
|
||||||
|
|
||||||
//#include "hge.h"
|
//#include "hge.h"
|
||||||
//#include "hgesprite.h"
|
//#include "hgesprite.h"
|
||||||
#include "hgevector.h"
|
#include "hgevector.h"
|
||||||
#include "hgecolor.h"
|
#include "hgecolor.h"
|
||||||
#include "hgerect.h"
|
#include "hgerect.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class JQuad;
|
class JQuad;
|
||||||
|
|
||||||
#define MAX_PARTICLES 500
|
#define MAX_PARTICLES 500
|
||||||
#define MAX_PSYSTEMS 100
|
#define MAX_PSYSTEMS 100
|
||||||
|
|
||||||
struct hgeParticle
|
struct hgeParticle
|
||||||
{
|
{
|
||||||
hgeVector vecLocation;
|
hgeVector vecLocation;
|
||||||
hgeVector vecVelocity;
|
hgeVector vecVelocity;
|
||||||
|
|
||||||
float fGravity;
|
float fGravity;
|
||||||
float fRadialAccel;
|
float fRadialAccel;
|
||||||
float fTangentialAccel;
|
float fTangentialAccel;
|
||||||
|
|
||||||
float fSpin;
|
float fSpin;
|
||||||
float fSpinDelta;
|
float fSpinDelta;
|
||||||
|
|
||||||
float fSize;
|
float fSize;
|
||||||
float fSizeDelta;
|
float fSizeDelta;
|
||||||
|
|
||||||
hgeColor colColor; // + alpha
|
hgeColor colColor; // + alpha
|
||||||
hgeColor colColorDelta;
|
hgeColor colColorDelta;
|
||||||
|
|
||||||
float fAge;
|
float fAge;
|
||||||
float fTerminalAge;
|
float fTerminalAge;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hgeParticleSystemInfo
|
struct hgeParticleSystemInfo
|
||||||
{
|
{
|
||||||
JQuad* sprite; // texture + blend mode
|
JQuad* sprite; // texture + blend mode
|
||||||
int nEmission; // particles per sec
|
int nEmission; // particles per sec
|
||||||
float fLifetime;
|
float fLifetime;
|
||||||
|
|
||||||
float fParticleLifeMin;
|
float fParticleLifeMin;
|
||||||
float fParticleLifeMax;
|
float fParticleLifeMax;
|
||||||
|
|
||||||
float fDirection;
|
float fDirection;
|
||||||
float fSpread;
|
float fSpread;
|
||||||
bool bRelative;
|
bool bRelative;
|
||||||
|
|
||||||
float fSpeedMin;
|
float fSpeedMin;
|
||||||
float fSpeedMax;
|
float fSpeedMax;
|
||||||
|
|
||||||
float fGravityMin;
|
float fGravityMin;
|
||||||
float fGravityMax;
|
float fGravityMax;
|
||||||
|
|
||||||
float fRadialAccelMin;
|
float fRadialAccelMin;
|
||||||
float fRadialAccelMax;
|
float fRadialAccelMax;
|
||||||
|
|
||||||
float fTangentialAccelMin;
|
float fTangentialAccelMin;
|
||||||
float fTangentialAccelMax;
|
float fTangentialAccelMax;
|
||||||
|
|
||||||
float fSizeStart;
|
float fSizeStart;
|
||||||
float fSizeEnd;
|
float fSizeEnd;
|
||||||
float fSizeVar;
|
float fSizeVar;
|
||||||
|
|
||||||
float fSpinStart;
|
float fSpinStart;
|
||||||
float fSpinEnd;
|
float fSpinEnd;
|
||||||
float fSpinVar;
|
float fSpinVar;
|
||||||
|
|
||||||
hgeColor colColorStart; // + alpha
|
hgeColor colColorStart; // + alpha
|
||||||
hgeColor colColorEnd;
|
hgeColor colColorEnd;
|
||||||
float fColorVar;
|
float fColorVar;
|
||||||
float fAlphaVar;
|
float fAlphaVar;
|
||||||
};
|
};
|
||||||
|
|
||||||
class hgeParticleSystem
|
class hgeParticleSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
hgeParticleSystemInfo info;
|
hgeParticleSystemInfo info;
|
||||||
|
|
||||||
hgeParticleSystem(const char *filename, JQuad *sprite);
|
hgeParticleSystem(const char *filename, JQuad *sprite);
|
||||||
hgeParticleSystem(hgeParticleSystemInfo *psi);
|
hgeParticleSystem(hgeParticleSystemInfo *psi);
|
||||||
hgeParticleSystem(const hgeParticleSystem &ps);
|
hgeParticleSystem(const hgeParticleSystem &ps);
|
||||||
~hgeParticleSystem() { }
|
~hgeParticleSystem() { }
|
||||||
|
|
||||||
hgeParticleSystem& operator= (const hgeParticleSystem &ps);
|
hgeParticleSystem& operator= (const hgeParticleSystem &ps);
|
||||||
|
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
void FireAt(float x, float y);
|
void FireAt(float x, float y);
|
||||||
void Fire();
|
void Fire();
|
||||||
void Stop(bool bKillParticles=false);
|
void Stop(bool bKillParticles=false);
|
||||||
void Update(float fDeltaTime);
|
void Update(float fDeltaTime);
|
||||||
void MoveTo(float x, float y, bool bMoveParticles=false);
|
void MoveTo(float x, float y, bool bMoveParticles=false);
|
||||||
void Transpose(float x, float y) { fTx=x; fTy=y; }
|
void Transpose(float x, float y) { fTx=x; fTy=y; }
|
||||||
void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
|
void TrackBoundingBox(bool bTrack) { bUpdateBoundingBox=bTrack; }
|
||||||
|
|
||||||
int GetParticlesAlive() const { return nParticlesAlive; }
|
int GetParticlesAlive() const { return nParticlesAlive; }
|
||||||
float GetAge() const { return fAge; }
|
float GetAge() const { return fAge; }
|
||||||
void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
|
void GetPosition(float *x, float *y) const { *x=vecLocation.x; *y=vecLocation.y; }
|
||||||
void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
|
void GetTransposition(float *x, float *y) const { *x=fTx; *y=fTy; }
|
||||||
hgeRect* GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); return rect; }
|
hgeRect* GetBoundingBox(hgeRect *rect) const { memcpy(rect, &rectBoundingBox, sizeof(hgeRect)); return rect; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hgeParticleSystem();
|
hgeParticleSystem();
|
||||||
|
|
||||||
//static HGE *hge;
|
//static HGE *hge;
|
||||||
|
|
||||||
float fAge;
|
float fAge;
|
||||||
float fEmissionResidue;
|
float fEmissionResidue;
|
||||||
|
|
||||||
hgeVector vecPrevLocation;
|
hgeVector vecPrevLocation;
|
||||||
hgeVector vecLocation;
|
hgeVector vecLocation;
|
||||||
float fTx, fTy;
|
float fTx, fTy;
|
||||||
|
|
||||||
int nParticlesAlive;
|
int nParticlesAlive;
|
||||||
hgeRect rectBoundingBox;
|
hgeRect rectBoundingBox;
|
||||||
bool bUpdateBoundingBox;
|
bool bUpdateBoundingBox;
|
||||||
|
|
||||||
typedef std::list<hgeParticle> ParticleBuffer;
|
typedef std::list<hgeParticle> ParticleBuffer;
|
||||||
ParticleBuffer mParticleBuffer;
|
ParticleBuffer mParticleBuffer;
|
||||||
|
|
||||||
float mTimer;
|
float mTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class hgeParticleManager
|
class hgeParticleManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
hgeParticleManager();
|
hgeParticleManager();
|
||||||
~hgeParticleManager();
|
~hgeParticleManager();
|
||||||
|
|
||||||
void Update(float dt);
|
void Update(float dt);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
|
hgeParticleSystem* SpawnPS(hgeParticleSystemInfo *psi, float x, float y);
|
||||||
bool IsPSAlive(hgeParticleSystem *ps) const;
|
bool IsPSAlive(hgeParticleSystem *ps) const;
|
||||||
void Transpose(float x, float y);
|
void Transpose(float x, float y);
|
||||||
void GetTransposition(float *dx, float *dy) const {*dx=tX; *dy=tY;}
|
void GetTransposition(float *dx, float *dy) const {*dx=tX; *dy=tY;}
|
||||||
void KillPS(hgeParticleSystem *ps);
|
void KillPS(hgeParticleSystem *ps);
|
||||||
void KillAll();
|
void KillAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hgeParticleManager(const hgeParticleManager &);
|
hgeParticleManager(const hgeParticleManager &);
|
||||||
hgeParticleManager& operator= (const hgeParticleManager &);
|
hgeParticleManager& operator= (const hgeParticleManager &);
|
||||||
|
|
||||||
int nPS;
|
int nPS;
|
||||||
float tX;
|
float tX;
|
||||||
float tY;
|
float tY;
|
||||||
hgeParticleSystem* psList[MAX_PSYSTEMS];
|
hgeParticleSystem* psList[MAX_PSYSTEMS];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+35
-35
@@ -1,35 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeRect helper class
|
** hgeRect helper class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGERECT_H
|
#ifndef HGERECT_H
|
||||||
#define HGERECT_H
|
#define HGERECT_H
|
||||||
|
|
||||||
|
|
||||||
class hgeRect
|
class hgeRect
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float x1, y1, x2, y2;
|
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(float _x1, float _y1, float _x2, float _y2) {x1=_x1; y1=_y1; x2=_x2; y2=_y2; bClean=false; }
|
||||||
hgeRect() {bClean=true;}
|
hgeRect() {bClean=true;}
|
||||||
|
|
||||||
void Clear() {bClean=true;}
|
void Clear() {bClean=true;}
|
||||||
bool IsClean() const {return bClean;}
|
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 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 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);
|
void Encapsulate(float x, float y);
|
||||||
bool TestPoint(float x, float y) const;
|
bool TestPoint(float x, float y) const;
|
||||||
bool Intersect(const hgeRect *rect) const;
|
bool Intersect(const hgeRect *rect) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool bClean;
|
bool bClean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+57
-57
@@ -1,57 +1,57 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeVector helper class
|
** hgeVector helper class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef HGEVECTOR_H
|
#ifndef HGEVECTOR_H
|
||||||
#define HGEVECTOR_H
|
#define HGEVECTOR_H
|
||||||
|
|
||||||
|
|
||||||
//#include "hge.h"
|
//#include "hge.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Fast 1.0/sqrtf(float) routine
|
** Fast 1.0/sqrtf(float) routine
|
||||||
*/
|
*/
|
||||||
float InvSqrt(float x);
|
float InvSqrt(float x);
|
||||||
|
|
||||||
class hgeVector
|
class hgeVector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float x,y;
|
float x,y;
|
||||||
|
|
||||||
hgeVector(float _x, float _y) { x=_x; y=_y; }
|
hgeVector(float _x, float _y) { x=_x; y=_y; }
|
||||||
hgeVector() { x=0; y=0; }
|
hgeVector() { x=0; y=0; }
|
||||||
|
|
||||||
hgeVector operator- () const { return hgeVector(-x, -y); }
|
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) 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; }
|
||||||
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); }
|
||||||
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) 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; }
|
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 Dot(const hgeVector *v) const { return x*v->x + y*v->y; }
|
||||||
float Length() const { return sqrtf(Dot(this)); }
|
float Length() const { return sqrtf(Dot(this)); }
|
||||||
float Angle(const hgeVector *v = 0) const;
|
float Angle(const hgeVector *v = 0) const;
|
||||||
|
|
||||||
void Clamp(const float max) { if(Length() > max) { Normalize(); x *= max; y *= max; } }
|
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* Normalize() { float rc=InvSqrt(Dot(this)); x*=rc; y*=rc; return this; }
|
||||||
hgeVector* Rotate(float a);
|
hgeVector* Rotate(float a);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline hgeVector operator* (const float s, const hgeVector &v) { return v*s; }
|
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.Angle(&u); }
|
||||||
inline float operator% (const hgeVector &v, const hgeVector &u) { return v.Dot(&u); }
|
inline float operator% (const hgeVector &v, const hgeVector &u) { return v.Dot(&u); }
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+132
-132
@@ -1,132 +1,132 @@
|
|||||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||||
|
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This code is a modified version of crypting code in Infozip distribution
|
This code is a modified version of crypting code in Infozip distribution
|
||||||
|
|
||||||
The encryption/decryption parts of this source code (as opposed to the
|
The encryption/decryption parts of this source code (as opposed to the
|
||||||
non-echoing password parts) were originally written in Europe. The
|
non-echoing password parts) were originally written in Europe. The
|
||||||
whole source package can be freely distributed, including from the USA.
|
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.)
|
(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
|
This encryption code is a direct transcription of the algorithm from
|
||||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||||
version without encryption capabilities).
|
version without encryption capabilities).
|
||||||
|
|
||||||
If you don't need crypting in your application, just define symbols
|
If you don't need crypting in your application, just define symbols
|
||||||
NOCRYPT and NOUNCRYPT.
|
NOCRYPT and NOUNCRYPT.
|
||||||
|
|
||||||
This code support the "Traditional PKWARE Encryption".
|
This code support the "Traditional PKWARE Encryption".
|
||||||
|
|
||||||
The new AES encryption added on Zip format by Winzip (see the page
|
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
|
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||||
Encryption is not supported.
|
Encryption is not supported.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Return the next byte in the pseudo-random sequence
|
* Return the next byte in the pseudo-random sequence
|
||||||
*/
|
*/
|
||||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||||
{
|
{
|
||||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||||
* unpredictable manner on 16-bit systems; not a problem
|
* unpredictable manner on 16-bit systems; not a problem
|
||||||
* with any known compiler so far, though */
|
* with any known compiler so far, though */
|
||||||
|
|
||||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Update the encryption keys with the next byte of plain text
|
* 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)
|
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||||
{
|
{
|
||||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||||
{
|
{
|
||||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Initialize the encryption keys and the random header according to
|
* Initialize the encryption keys and the random header according to
|
||||||
* the given password.
|
* the given password.
|
||||||
*/
|
*/
|
||||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||||
{
|
{
|
||||||
*(pkeys+0) = 305419896L;
|
*(pkeys+0) = 305419896L;
|
||||||
*(pkeys+1) = 591751049L;
|
*(pkeys+1) = 591751049L;
|
||||||
*(pkeys+2) = 878082192L;
|
*(pkeys+2) = 878082192L;
|
||||||
while (*passwd != '\0') {
|
while (*passwd != '\0') {
|
||||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||||
passwd++;
|
passwd++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||||
|
|
||||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||||
|
|
||||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||||
|
|
||||||
#define RAND_HEAD_LEN 12
|
#define RAND_HEAD_LEN 12
|
||||||
/* "last resort" source for second part of crypt seed pattern */
|
/* "last resort" source for second part of crypt seed pattern */
|
||||||
# ifndef ZCR_SEED2
|
# ifndef ZCR_SEED2
|
||||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||||
const char *passwd; /* password string */
|
const char *passwd; /* password string */
|
||||||
unsigned char *buf; /* where to write header */
|
unsigned char *buf; /* where to write header */
|
||||||
int bufSize;
|
int bufSize;
|
||||||
unsigned long* pkeys;
|
unsigned long* pkeys;
|
||||||
const unsigned long* pcrc_32_tab;
|
const unsigned long* pcrc_32_tab;
|
||||||
unsigned long crcForCrypting;
|
unsigned long crcForCrypting;
|
||||||
{
|
{
|
||||||
int n; /* index in random header */
|
int n; /* index in random header */
|
||||||
int t; /* temporary */
|
int t; /* temporary */
|
||||||
int c; /* random byte */
|
int c; /* random byte */
|
||||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||||
static unsigned calls = 0; /* ensure different random header each time */
|
static unsigned calls = 0; /* ensure different random header each time */
|
||||||
|
|
||||||
if (bufSize<RAND_HEAD_LEN)
|
if (bufSize<RAND_HEAD_LEN)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||||
* output of rand() to get less predictability, since rand() is
|
* output of rand() to get less predictability, since rand() is
|
||||||
* often poorly implemented.
|
* often poorly implemented.
|
||||||
*/
|
*/
|
||||||
if (++calls == 1)
|
if (++calls == 1)
|
||||||
{
|
{
|
||||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||||
}
|
}
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
{
|
{
|
||||||
c = (rand() >> 7) & 0xff;
|
c = (rand() >> 7) & 0xff;
|
||||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||||
}
|
}
|
||||||
/* Encrypt random header (last two bytes is high word of crc) */
|
/* Encrypt random header (last two bytes is high word of crc) */
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
{
|
{
|
||||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
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 >> 16) & 0xff, t);
|
||||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+75
-75
@@ -1,75 +1,75 @@
|
|||||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#define _ZLIBIOAPI_H
|
#define _ZLIBIOAPI_H
|
||||||
|
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||||
|
|
||||||
|
|
||||||
#ifndef ZCALLBACK
|
#ifndef ZCALLBACK
|
||||||
|
|
||||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||||
#define ZCALLBACK CALLBACK
|
#define ZCALLBACK CALLBACK
|
||||||
#else
|
#else
|
||||||
#define ZCALLBACK
|
#define ZCALLBACK
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
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 *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 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 *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
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 *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
|
|
||||||
typedef struct zlib_filefunc_def_s
|
typedef struct zlib_filefunc_def_s
|
||||||
{
|
{
|
||||||
open_file_func zopen_file;
|
open_file_func zopen_file;
|
||||||
read_file_func zread_file;
|
read_file_func zread_file;
|
||||||
write_file_func zwrite_file;
|
write_file_func zwrite_file;
|
||||||
tell_file_func ztell_file;
|
tell_file_func ztell_file;
|
||||||
seek_file_func zseek_file;
|
seek_file_func zseek_file;
|
||||||
close_file_func zclose_file;
|
close_file_func zclose_file;
|
||||||
testerror_file_func zerror_file;
|
testerror_file_func zerror_file;
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
} zlib_filefunc_def;
|
} zlib_filefunc_def;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_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 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 ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
#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 ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+31
-31
@@ -1,31 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
Additional tools for Minizip
|
Additional tools for Minizip
|
||||||
Code: Xavier Roche '2004
|
Code: Xavier Roche '2004
|
||||||
License: Same as ZLIB (www.gzip.org)
|
License: Same as ZLIB (www.gzip.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _zip_tools_H
|
#ifndef _zip_tools_H
|
||||||
#define _zip_tools_H
|
#define _zip_tools_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
|
||||||
/* Repair a ZIP file (missing central directory)
|
/* Repair a ZIP file (missing central directory)
|
||||||
file: file to recover
|
file: file to recover
|
||||||
fileOut: output file after recovery
|
fileOut: output file after recovery
|
||||||
fileOutTmp: temporary file name used for recovery
|
fileOutTmp: temporary file name used for recovery
|
||||||
*/
|
*/
|
||||||
extern int ZEXPORT unzRepair(const char* file,
|
extern int ZEXPORT unzRepair(const char* file,
|
||||||
const char* fileOut,
|
const char* fileOut,
|
||||||
const char* fileOutTmp,
|
const char* fileOutTmp,
|
||||||
uLong* nRecovered,
|
uLong* nRecovered,
|
||||||
uLong* bytesRecovered);
|
uLong* bytesRecovered);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+356
-356
@@ -1,356 +1,356 @@
|
|||||||
/* unzip.h -- IO for uncompress .zip files using zlib
|
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||||
WinZip, InfoZip tools and compatible.
|
WinZip, InfoZip tools and compatible.
|
||||||
|
|
||||||
Multi volume ZipFile (span) are not supported.
|
Multi volume ZipFile (span) are not supported.
|
||||||
Encryption compatible with pkzip 2.04g only supported
|
Encryption compatible with pkzip 2.04g only supported
|
||||||
Old compressions used by old PKZip 1.x are not supported
|
Old compressions used by old PKZip 1.x are not supported
|
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com
|
I WAIT FEEDBACK at mail info@winimage.com
|
||||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib :
|
Condition of use and distribution are the same than zlib :
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* 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/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at :
|
PkWare has also a specification at :
|
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _unz_H
|
#ifndef _unz_H
|
||||||
#define _unz_H
|
#define _unz_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */
|
from (void*) without cast */
|
||||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||||
typedef unzFile__ *unzFile;
|
typedef unzFile__ *unzFile;
|
||||||
#else
|
#else
|
||||||
typedef voidp unzFile;
|
typedef voidp unzFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define UNZ_OK (0)
|
#define UNZ_OK (0)
|
||||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||||
#define UNZ_ERRNO (Z_ERRNO)
|
#define UNZ_ERRNO (Z_ERRNO)
|
||||||
#define UNZ_EOF (0)
|
#define UNZ_EOF (0)
|
||||||
#define UNZ_PARAMERROR (-102)
|
#define UNZ_PARAMERROR (-102)
|
||||||
#define UNZ_BADZIPFILE (-103)
|
#define UNZ_BADZIPFILE (-103)
|
||||||
#define UNZ_INTERNALERROR (-104)
|
#define UNZ_INTERNALERROR (-104)
|
||||||
#define UNZ_CRCERROR (-105)
|
#define UNZ_CRCERROR (-105)
|
||||||
|
|
||||||
|
|
||||||
/* tm_unz contain date/time info */
|
/* tm_unz contain date/time info */
|
||||||
typedef struct tm_unz_s
|
typedef struct tm_unz_s
|
||||||
{
|
{
|
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||||
uInt tm_mday; /* day of the month - [1,31] */
|
uInt tm_mday; /* day of the month - [1,31] */
|
||||||
uInt tm_mon; /* months since January - [0,11] */
|
uInt tm_mon; /* months since January - [0,11] */
|
||||||
uInt tm_year; /* years - [1980..2044] */
|
uInt tm_year; /* years - [1980..2044] */
|
||||||
} tm_unz;
|
} tm_unz;
|
||||||
|
|
||||||
/* unz_global_info structure contain global data about the ZIPfile
|
/* unz_global_info structure contain global data about the ZIPfile
|
||||||
These data comes from the end of central dir */
|
These data comes from the end of central dir */
|
||||||
typedef struct unz_global_info_s
|
typedef struct unz_global_info_s
|
||||||
{
|
{
|
||||||
uLong number_entry; /* total number of entries in
|
uLong number_entry; /* total number of entries in
|
||||||
the central dir on this disk */
|
the central dir on this disk */
|
||||||
uLong size_comment; /* size of the global comment of the zipfile */
|
uLong size_comment; /* size of the global comment of the zipfile */
|
||||||
} unz_global_info;
|
} unz_global_info;
|
||||||
|
|
||||||
|
|
||||||
/* unz_file_info contain information about a file in the zipfile */
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
typedef struct unz_file_info_s
|
typedef struct unz_file_info_s
|
||||||
{
|
{
|
||||||
uLong version; /* version made by 2 bytes */
|
uLong version; /* version made by 2 bytes */
|
||||||
uLong version_needed; /* version needed to extract 2 bytes */
|
uLong version_needed; /* version needed to extract 2 bytes */
|
||||||
uLong flag; /* general purpose bit flag 2 bytes */
|
uLong flag; /* general purpose bit flag 2 bytes */
|
||||||
uLong compression_method; /* compression method 2 bytes */
|
uLong compression_method; /* compression method 2 bytes */
|
||||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||||
uLong crc; /* crc-32 4 bytes */
|
uLong crc; /* crc-32 4 bytes */
|
||||||
uLong compressed_size; /* compressed size 4 bytes */
|
uLong compressed_size; /* compressed size 4 bytes */
|
||||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||||
uLong size_filename; /* filename length 2 bytes */
|
uLong size_filename; /* filename length 2 bytes */
|
||||||
uLong size_file_extra; /* extra field length 2 bytes */
|
uLong size_file_extra; /* extra field length 2 bytes */
|
||||||
uLong size_file_comment; /* file comment length 2 bytes */
|
uLong size_file_comment; /* file comment length 2 bytes */
|
||||||
|
|
||||||
uLong disk_num_start; /* disk number start 2 bytes */
|
uLong disk_num_start; /* disk number start 2 bytes */
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
uLong external_fa; /* external file attributes 4 bytes */
|
||||||
|
|
||||||
tm_unz tmu_date;
|
tm_unz tmu_date;
|
||||||
} unz_file_info;
|
} unz_file_info;
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||||
const char* fileName2,
|
const char* fileName2,
|
||||||
int iCaseSensitivity));
|
int iCaseSensitivity));
|
||||||
/*
|
/*
|
||||||
Compare two filename (fileName1,fileName2).
|
Compare two filename (fileName1,fileName2).
|
||||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||||
or strcasecmp)
|
or strcasecmp)
|
||||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||||
(like 1 on Unix, 2 on Windows)
|
(like 1 on Unix, 2 on Windows)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||||
/*
|
/*
|
||||||
Open a Zip file. path contain the full pathname (by example,
|
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
|
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||||
"zlib/zlib113.zip".
|
"zlib/zlib113.zip".
|
||||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||||
return value is NULL.
|
return value is NULL.
|
||||||
Else, the return value is a unzFile Handle, usable with other function
|
Else, the return value is a unzFile Handle, usable with other function
|
||||||
of this unzip package.
|
of this unzip package.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||||
zlib_filefunc_def* pzlib_filefunc_def));
|
zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
/*
|
/*
|
||||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||||
for read/write the zip file (see ioapi.h)
|
for read/write the zip file (see ioapi.h)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzClose OF((unzFile file));
|
extern int ZEXPORT unzClose OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Close a ZipFile opened with unzipOpen.
|
Close a ZipFile opened with unzipOpen.
|
||||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||||
return UNZ_OK if there is no problem. */
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||||
unz_global_info *pglobal_info));
|
unz_global_info *pglobal_info));
|
||||||
/*
|
/*
|
||||||
Write info about the ZipFile in the *pglobal_info structure.
|
Write info about the ZipFile in the *pglobal_info structure.
|
||||||
No preparation of the structure is needed
|
No preparation of the structure is needed
|
||||||
return UNZ_OK if there is no problem. */
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||||
char *szComment,
|
char *szComment,
|
||||||
uLong uSizeBuf));
|
uLong uSizeBuf));
|
||||||
/*
|
/*
|
||||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||||
uSizeBuf is the size of the szComment buffer.
|
uSizeBuf is the size of the szComment buffer.
|
||||||
return the number of byte copied or an error code <0
|
return the number of byte copied or an error code <0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/* Unzip package allow you browse the directory of the zipfile */
|
/* Unzip package allow you browse the directory of the zipfile */
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the first file.
|
Set the current file of the zipfile to the first file.
|
||||||
return UNZ_OK if there is no problem
|
return UNZ_OK if there is no problem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the next file.
|
Set the current file of the zipfile to the next file.
|
||||||
return UNZ_OK if there is no problem
|
return UNZ_OK if there is no problem
|
||||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||||
const char *szFileName,
|
const char *szFileName,
|
||||||
int iCaseSensitivity));
|
int iCaseSensitivity));
|
||||||
/*
|
/*
|
||||||
Try locate the file szFileName in the zipfile.
|
Try locate the file szFileName in the zipfile.
|
||||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||||
|
|
||||||
return value :
|
return value :
|
||||||
UNZ_OK if the file is found. It becomes the current file.
|
UNZ_OK if the file is found. It becomes the current file.
|
||||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* Ryan supplied functions */
|
/* Ryan supplied functions */
|
||||||
/* unz_file_info contain information about a file in the zipfile */
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
typedef struct unz_file_pos_s
|
typedef struct unz_file_pos_s
|
||||||
{
|
{
|
||||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||||
uLong num_of_file; /* # of file */
|
uLong num_of_file; /* # of file */
|
||||||
} unz_file_pos;
|
} unz_file_pos;
|
||||||
|
|
||||||
extern int ZEXPORT unzGetFilePos(
|
extern int ZEXPORT unzGetFilePos(
|
||||||
unzFile file,
|
unzFile file,
|
||||||
unz_file_pos* file_pos);
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFilePos(
|
extern int ZEXPORT unzGoToFilePos(
|
||||||
unzFile file,
|
unzFile file,
|
||||||
unz_file_pos* file_pos);
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
||||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||||
unz_file_info *pfile_info,
|
unz_file_info *pfile_info,
|
||||||
char *szFileName,
|
char *szFileName,
|
||||||
uLong fileNameBufferSize,
|
uLong fileNameBufferSize,
|
||||||
void *extraField,
|
void *extraField,
|
||||||
uLong extraFieldBufferSize,
|
uLong extraFieldBufferSize,
|
||||||
char *szComment,
|
char *szComment,
|
||||||
uLong commentBufferSize));
|
uLong commentBufferSize));
|
||||||
/*
|
/*
|
||||||
Get Info about the current file
|
Get Info about the current file
|
||||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||||
the current file
|
the current file
|
||||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||||
(fileNameBufferSize is the size of the buffer)
|
(fileNameBufferSize is the size of the buffer)
|
||||||
if extraField!=NULL, the extra field information will be copied in extraField
|
if extraField!=NULL, the extra field information will be copied in extraField
|
||||||
(extraFieldBufferSize is the size of the buffer).
|
(extraFieldBufferSize is the size of the buffer).
|
||||||
This is the Central-header version of the extra field
|
This is the Central-header version of the extra field
|
||||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||||
(commentBufferSize is the size of the buffer)
|
(commentBufferSize is the size of the buffer)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/* for reading the content of the current zipfile, you can open it, read data
|
/* 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)
|
from it, and close it (you can close it before reading all the file)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile.
|
Open for reading data the current file in the zipfile.
|
||||||
If there is no error, the return value is UNZ_OK.
|
If there is no error, the return value is UNZ_OK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||||
const char* password));
|
const char* password));
|
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile.
|
Open for reading data the current file in the zipfile.
|
||||||
password is a crypting password
|
password is a crypting password
|
||||||
If there is no error, the return value is UNZ_OK.
|
If there is no error, the return value is UNZ_OK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||||
int* method,
|
int* method,
|
||||||
int* level,
|
int* level,
|
||||||
int raw));
|
int raw));
|
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
if raw==1
|
if raw==1
|
||||||
*method will receive method of compression, *level will receive level of
|
*method will receive method of compression, *level will receive level of
|
||||||
compression
|
compression
|
||||||
note : you can set level parameter as NULL (if you did not want known level,
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
but you CANNOT set method parameter as NULL
|
but you CANNOT set method parameter as NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||||
int* method,
|
int* method,
|
||||||
int* level,
|
int* level,
|
||||||
int raw,
|
int raw,
|
||||||
const char* password));
|
const char* password));
|
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
if raw==1
|
if raw==1
|
||||||
*method will receive method of compression, *level will receive level of
|
*method will receive method of compression, *level will receive level of
|
||||||
compression
|
compression
|
||||||
note : you can set level parameter as NULL (if you did not want known level,
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
but you CANNOT set method parameter as NULL
|
but you CANNOT set method parameter as NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Close the file in zip opened with unzOpenCurrentFile
|
Close the file in zip opened with unzOpenCurrentFile
|
||||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||||
voidp buf,
|
voidp buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||||
buf contain buffer where data must be copied
|
buf contain buffer where data must be copied
|
||||||
len the size of buf.
|
len the size of buf.
|
||||||
|
|
||||||
return the number of byte copied if somes bytes are copied
|
return the number of byte copied if somes bytes are copied
|
||||||
return 0 if the end of file was reached
|
return 0 if the end of file was reached
|
||||||
return <0 with error code if there is an error
|
return <0 with error code if there is an error
|
||||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Give the current position in uncompressed data
|
Give the current position in uncompressed data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzeof OF((unzFile file));
|
extern int ZEXPORT unzeof OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
return 1 if the end of file was reached, 0 elsewhere
|
return 1 if the end of file was reached, 0 elsewhere
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||||
voidp buf,
|
voidp buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||||
This is the local-header version of the extra field (sometimes, there is
|
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)
|
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, 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
|
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||||
buf.
|
buf.
|
||||||
the return value is the number of bytes copied in buf, or (if <0)
|
the return value is the number of bytes copied in buf, or (if <0)
|
||||||
the error code
|
the error code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
/* Get the current file offset */
|
/* Get the current file offset */
|
||||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||||
|
|
||||||
/* Set the current file offset */
|
/* Set the current file offset */
|
||||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _unz_H */
|
#endif /* _unz_H */
|
||||||
|
|||||||
+235
-235
@@ -1,235 +1,235 @@
|
|||||||
/* zip.h -- IO for compress .zip files using zlib
|
/* zip.h -- IO for compress .zip files using zlib
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||||
WinZip, InfoZip tools and compatible.
|
WinZip, InfoZip tools and compatible.
|
||||||
Multi volume ZipFile (span) are not supported.
|
Multi volume ZipFile (span) are not supported.
|
||||||
Encryption compatible with pkzip 2.04g only supported
|
Encryption compatible with pkzip 2.04g only supported
|
||||||
Old compressions used by old PKZip 1.x are not supported
|
Old compressions used by old PKZip 1.x are not supported
|
||||||
|
|
||||||
For uncompress .zip file, look at unzip.h
|
For uncompress .zip file, look at unzip.h
|
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com
|
I WAIT FEEDBACK at mail info@winimage.com
|
||||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib :
|
Condition of use and distribution are the same than zlib :
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* 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/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at :
|
PkWare has also a specification at :
|
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _zip_H
|
#ifndef _zip_H
|
||||||
#define _zip_H
|
#define _zip_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */
|
from (void*) without cast */
|
||||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||||
typedef zipFile__ *zipFile;
|
typedef zipFile__ *zipFile;
|
||||||
#else
|
#else
|
||||||
typedef voidp zipFile;
|
typedef voidp zipFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ZIP_OK (0)
|
#define ZIP_OK (0)
|
||||||
#define ZIP_EOF (0)
|
#define ZIP_EOF (0)
|
||||||
#define ZIP_ERRNO (Z_ERRNO)
|
#define ZIP_ERRNO (Z_ERRNO)
|
||||||
#define ZIP_PARAMERROR (-102)
|
#define ZIP_PARAMERROR (-102)
|
||||||
#define ZIP_BADZIPFILE (-103)
|
#define ZIP_BADZIPFILE (-103)
|
||||||
#define ZIP_INTERNALERROR (-104)
|
#define ZIP_INTERNALERROR (-104)
|
||||||
|
|
||||||
#ifndef DEF_MEM_LEVEL
|
#ifndef DEF_MEM_LEVEL
|
||||||
# if MAX_MEM_LEVEL >= 8
|
# if MAX_MEM_LEVEL >= 8
|
||||||
# define DEF_MEM_LEVEL 8
|
# define DEF_MEM_LEVEL 8
|
||||||
# else
|
# else
|
||||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
/* default memLevel */
|
/* default memLevel */
|
||||||
|
|
||||||
/* tm_zip contain date/time info */
|
/* tm_zip contain date/time info */
|
||||||
typedef struct tm_zip_s
|
typedef struct tm_zip_s
|
||||||
{
|
{
|
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||||
uInt tm_mday; /* day of the month - [1,31] */
|
uInt tm_mday; /* day of the month - [1,31] */
|
||||||
uInt tm_mon; /* months since January - [0,11] */
|
uInt tm_mon; /* months since January - [0,11] */
|
||||||
uInt tm_year; /* years - [1980..2044] */
|
uInt tm_year; /* years - [1980..2044] */
|
||||||
} tm_zip;
|
} tm_zip;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
tm_zip tmz_date; /* date in understandable format */
|
tm_zip tmz_date; /* date in understandable format */
|
||||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||||
|
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
uLong external_fa; /* external file attributes 4 bytes */
|
||||||
} zip_fileinfo;
|
} zip_fileinfo;
|
||||||
|
|
||||||
typedef const char* zipcharpc;
|
typedef const char* zipcharpc;
|
||||||
|
|
||||||
|
|
||||||
#define APPEND_STATUS_CREATE (0)
|
#define APPEND_STATUS_CREATE (0)
|
||||||
#define APPEND_STATUS_CREATEAFTER (1)
|
#define APPEND_STATUS_CREATEAFTER (1)
|
||||||
#define APPEND_STATUS_ADDINZIP (2)
|
#define APPEND_STATUS_ADDINZIP (2)
|
||||||
|
|
||||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||||
/*
|
/*
|
||||||
Create a zipfile.
|
Create a zipfile.
|
||||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||||
an Unix computer "zlib/zlib113.zip".
|
an Unix computer "zlib/zlib113.zip".
|
||||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||||
will be created at the end of the file.
|
will be created at the end of the file.
|
||||||
(useful if the file contain a self extractor code)
|
(useful if the file contain a self extractor code)
|
||||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
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)
|
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.
|
If the zipfile cannot be opened, the return value is NULL.
|
||||||
Else, the return value is a zipFile Handle, usable with other function
|
Else, the return value is a zipFile Handle, usable with other function
|
||||||
of this zip package.
|
of this zip package.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Note : there is no delete function into a zipfile.
|
/* 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
|
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
|
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,
|
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||||
int append,
|
int append,
|
||||||
zipcharpc* globalcomment,
|
zipcharpc* globalcomment,
|
||||||
zlib_filefunc_def* pzlib_filefunc_def));
|
zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level));
|
int level));
|
||||||
/*
|
/*
|
||||||
Open a file in the ZIP for writing.
|
Open a file in the ZIP for writing.
|
||||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||||
*zipfi contain supplemental information
|
*zipfi contain supplemental information
|
||||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||||
contains the extrafield data the the local header
|
contains the extrafield data the the local header
|
||||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||||
contains the extrafield data the the local header
|
contains the extrafield data the the local header
|
||||||
if comment != NULL, comment contain the comment string
|
if comment != NULL, comment contain the comment string
|
||||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level,
|
int level,
|
||||||
int raw));
|
int raw));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level,
|
int level,
|
||||||
int raw,
|
int raw,
|
||||||
int windowBits,
|
int windowBits,
|
||||||
int memLevel,
|
int memLevel,
|
||||||
int strategy,
|
int strategy,
|
||||||
const char* password,
|
const char* password,
|
||||||
uLong crcForCtypting));
|
uLong crcForCtypting));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip2, except
|
Same than zipOpenNewFileInZip2, except
|
||||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||||
password : crypting password (NULL for no crypting)
|
password : crypting password (NULL for no crypting)
|
||||||
crcForCtypting : crc of file to compress (needed for crypting)
|
crcForCtypting : crc of file to compress (needed for crypting)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||||
const void* buf,
|
const void* buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Write data in the zipfile
|
Write data in the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile
|
Close the current file in the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||||
uLong uncompressed_size,
|
uLong uncompressed_size,
|
||||||
uLong crc32));
|
uLong crc32));
|
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile, for fiel opened with
|
Close the current file in the zipfile, for fiel opened with
|
||||||
parameter raw=1 in zipOpenNewFileInZip2
|
parameter raw=1 in zipOpenNewFileInZip2
|
||||||
uncompressed_size and crc32 are value for the uncompressed size
|
uncompressed_size and crc32 are value for the uncompressed size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipClose OF((zipFile file,
|
extern int ZEXPORT zipClose OF((zipFile file,
|
||||||
const char* global_comment));
|
const char* global_comment));
|
||||||
/*
|
/*
|
||||||
Close the zipfile
|
Close the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _zip_H */
|
#endif /* _zip_H */
|
||||||
|
|||||||
+54
-54
@@ -1,54 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||||
* -----------------------------------------------------------------------
|
* -----------------------------------------------------------------------
|
||||||
* Licensed under GPL
|
* Licensed under GPL
|
||||||
*
|
*
|
||||||
* vram.c - Standard C high performance VRAM allocation routines.
|
* vram.c - Standard C high performance VRAM allocation routines.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||||
* http://wordpress.fx-world.org
|
* http://wordpress.fx-world.org
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
#ifndef vram_h__
|
#ifndef vram_h__
|
||||||
#define vram_h__
|
#define vram_h__
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void* vrelptr( void *ptr ); // make a pointer relative to memory base address (ATTENTION: A NULL rel ptr is not illegal/invalid!)
|
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* vabsptr( void *ptr ); // make a pointer absolute (default return type of valloc)
|
||||||
|
|
||||||
void* valloc( size_t size );
|
void* valloc( size_t size );
|
||||||
void vfree( void* ptr );
|
void vfree( void* ptr );
|
||||||
size_t vmemavail();
|
size_t vmemavail();
|
||||||
size_t vlargestblock();
|
size_t vlargestblock();
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
// Debug printf (to stdout) a trace of the current Memblocks
|
// Debug printf (to stdout) a trace of the current Memblocks
|
||||||
void __memwalk();
|
void __memwalk();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // ifdef vram_h__
|
#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.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JResourceManager.h"
|
#include "../include/JResourceManager.h"
|
||||||
#include "../include/JFileSystem.h"
|
#include "../include/JFileSystem.h"
|
||||||
#include "../include/JRenderer.h"
|
#include "../include/JRenderer.h"
|
||||||
#include "../include/JSprite.h"
|
#include "../include/JSprite.h"
|
||||||
#include "../include/JAnimator.h"
|
#include "../include/JAnimator.h"
|
||||||
|
|
||||||
#include "tinyxml/tinyxml.h"
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimator::JAnimator(JResourceManager* resourceMgr)
|
JAnimator::JAnimator(JResourceManager* resourceMgr)
|
||||||
{
|
{
|
||||||
mResource = resourceMgr;
|
mResource = resourceMgr;
|
||||||
mActive = false;
|
mActive = false;
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JAnimator::~JAnimator()
|
JAnimator::~JAnimator()
|
||||||
{
|
{
|
||||||
while (mFrames.size()>0)
|
while (mFrames.size()>0)
|
||||||
{
|
{
|
||||||
JAnimatorFrame* frame = mFrames.back();
|
JAnimatorFrame* frame = mFrames.back();
|
||||||
mFrames.pop_back();
|
mFrames.pop_back();
|
||||||
delete frame;
|
delete frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFrames.clear();
|
mFrames.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JAnimator::Load(const char* scriptFile)
|
bool JAnimator::Load(const char* scriptFile)
|
||||||
{
|
{
|
||||||
|
|
||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(scriptFile)) return false;
|
if (!fileSystem->OpenFile(scriptFile)) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize();
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
|
|
||||||
TiXmlNode* script = 0;
|
TiXmlNode* script = 0;
|
||||||
TiXmlNode* frame = 0;
|
TiXmlNode* frame = 0;
|
||||||
TiXmlNode* obj = 0;
|
TiXmlNode* obj = 0;
|
||||||
TiXmlNode* param = 0;
|
TiXmlNode* param = 0;
|
||||||
TiXmlElement* element = 0;
|
TiXmlElement* element = 0;
|
||||||
|
|
||||||
float defaultTime = 0.033f;
|
float defaultTime = 0.033f;
|
||||||
|
|
||||||
script = doc.FirstChild("script");
|
script = doc.FirstChild("script");
|
||||||
if (script)
|
if (script)
|
||||||
{
|
{
|
||||||
element = script->ToElement();
|
element = script->ToElement();
|
||||||
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));
|
||||||
|
|
||||||
const char *type[] =
|
const char *type[] =
|
||||||
{
|
{
|
||||||
"ANIMATION_TYPE_LOOPING",
|
"ANIMATION_TYPE_LOOPING",
|
||||||
"ANIMATION_TYPE_ONCE_AND_STAY",
|
"ANIMATION_TYPE_ONCE_AND_STAY",
|
||||||
"ANIMATION_TYPE_ONCE_AND_BACK",
|
"ANIMATION_TYPE_ONCE_AND_BACK",
|
||||||
"ANIMATION_TYPE_ONCE_AND_GONE",
|
"ANIMATION_TYPE_ONCE_AND_GONE",
|
||||||
"ANIMATION_TYPE_PINGPONG"
|
"ANIMATION_TYPE_PINGPONG"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* aniType = element->Attribute("type");
|
const char* aniType = element->Attribute("type");
|
||||||
for (int i=0;i<5;i++)
|
for (int i=0;i<5;i++)
|
||||||
if (strcmp(type[i], aniType)==0)
|
if (strcmp(type[i], aniType)==0)
|
||||||
{
|
{
|
||||||
SetAnimationType(i);
|
SetAnimationType(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fps;
|
float fps;
|
||||||
if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
|
||||||
fps = 30.0f;
|
fps = 30.0f;
|
||||||
|
|
||||||
defaultTime = 1/fps;
|
defaultTime = 1/fps;
|
||||||
|
|
||||||
for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
|
for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
|
||||||
{
|
{
|
||||||
JAnimatorFrame *aniFrame = new JAnimatorFrame(this);
|
JAnimatorFrame *aniFrame = new JAnimatorFrame(this);
|
||||||
|
|
||||||
float duration;
|
float duration;
|
||||||
element = frame->ToElement();
|
element = frame->ToElement();
|
||||||
if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
|
||||||
duration = defaultTime;
|
duration = defaultTime;
|
||||||
aniFrame->SetFrameTime(duration);
|
aniFrame->SetFrameTime(duration);
|
||||||
|
|
||||||
for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
|
for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
|
||||||
{
|
{
|
||||||
for (param = obj->FirstChild(); param; param = param->NextSibling())
|
for (param = obj->FirstChild(); param; param = param->NextSibling())
|
||||||
{
|
{
|
||||||
|
|
||||||
element = param->ToElement();
|
element = param->ToElement();
|
||||||
if (element != NULL)
|
if (element != NULL)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Value(), "settings")==0)
|
if (strcmp(element->Value(), "settings")==0)
|
||||||
{
|
{
|
||||||
const char* quadName = element->Attribute("quad");
|
const char* quadName = element->Attribute("quad");
|
||||||
JQuad* quad = mResource->GetQuad(quadName);
|
JQuad* quad = mResource->GetQuad(quadName);
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
float vsize, hsize;
|
float vsize, hsize;
|
||||||
float angle;
|
float angle;
|
||||||
int a, r, g, b;
|
int a, r, g, b;
|
||||||
int value;
|
int value;
|
||||||
bool flipped = false;
|
bool flipped = false;
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
|
||||||
x = 0.0f;
|
x = 0.0f;
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
|
||||||
y = 0.0f;
|
y = 0.0f;
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
|
||||||
hsize = 1.0f;
|
hsize = 1.0f;
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
|
||||||
vsize = 1.0f;
|
vsize = 1.0f;
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
|
||||||
angle = 0.0f;
|
angle = 0.0f;
|
||||||
|
|
||||||
if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
|
if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
|
||||||
a = 255;
|
a = 255;
|
||||||
|
|
||||||
if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
|
if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
|
||||||
r = 255;
|
r = 255;
|
||||||
|
|
||||||
if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
|
if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
|
||||||
g = 255;
|
g = 255;
|
||||||
|
|
||||||
if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
|
if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
|
||||||
b = 255;
|
b = 255;
|
||||||
|
|
||||||
if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
|
if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
|
||||||
flipped = (value==1);
|
flipped = (value==1);
|
||||||
|
|
||||||
|
|
||||||
JAnimatorObject *object = new JAnimatorObject();
|
JAnimatorObject *object = new JAnimatorObject();
|
||||||
object->SetQuad(quad);
|
object->SetQuad(quad);
|
||||||
object->SetPosition(x, y);
|
object->SetPosition(x, y);
|
||||||
object->SetHScale(hsize);
|
object->SetHScale(hsize);
|
||||||
object->SetVScale(vsize);
|
object->SetVScale(vsize);
|
||||||
object->SetRotation(angle);
|
object->SetRotation(angle);
|
||||||
object->SetColor(ARGB(a,r,g,b));
|
object->SetColor(ARGB(a,r,g,b));
|
||||||
object->SetFlip(flipped);
|
object->SetFlip(flipped);
|
||||||
|
|
||||||
aniFrame->AddObject(object);
|
aniFrame->AddObject(object);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mFrames.push_back(aniFrame);
|
mFrames.push_back(aniFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile();
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimator::Start()
|
void JAnimator::Start()
|
||||||
{
|
{
|
||||||
mFrameDelta = 1;
|
mFrameDelta = 1;
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
mActive = true;
|
mActive = true;
|
||||||
mCurrentFrame = 0;
|
mCurrentFrame = 0;
|
||||||
|
|
||||||
mFrames[mCurrentFrame]->Start();
|
mFrames[mCurrentFrame]->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimator::Stop()
|
void JAnimator::Stop()
|
||||||
{
|
{
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimator::Pause()
|
void JAnimator::Pause()
|
||||||
{
|
{
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimator::Resume()
|
void JAnimator::Resume()
|
||||||
{
|
{
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimator::Update(float dt)
|
void JAnimator::Update(float dt)
|
||||||
{
|
{
|
||||||
if (!mAnimating) return;
|
if (!mAnimating) return;
|
||||||
|
|
||||||
if (mFrames[mCurrentFrame]->Update(dt))
|
if (mFrames[mCurrentFrame]->Update(dt))
|
||||||
{
|
{
|
||||||
mCurrentFrame+=mFrameDelta;
|
mCurrentFrame+=mFrameDelta;
|
||||||
|
|
||||||
int frameCount = mFrames.size();
|
int frameCount = mFrames.size();
|
||||||
if (mCurrentFrame >= frameCount)
|
if (mCurrentFrame >= frameCount)
|
||||||
{
|
{
|
||||||
if (mAnimationType == JSprite::ANIMATION_TYPE_LOOPING)
|
if (mAnimationType == JSprite::ANIMATION_TYPE_LOOPING)
|
||||||
mCurrentFrame = 0;
|
mCurrentFrame = 0;
|
||||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_GONE)
|
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_GONE)
|
||||||
{
|
{
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_STAY)
|
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_STAY)
|
||||||
{
|
{
|
||||||
mCurrentFrame = frameCount-1;
|
mCurrentFrame = frameCount-1;
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
}
|
}
|
||||||
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_BACK)
|
else if (mAnimationType == JSprite::ANIMATION_TYPE_ONCE_AND_BACK)
|
||||||
{
|
{
|
||||||
mCurrentFrame = 0;
|
mCurrentFrame = 0;
|
||||||
mAnimating = false;
|
mAnimating = false;
|
||||||
}
|
}
|
||||||
else // ping pong
|
else // ping pong
|
||||||
{
|
{
|
||||||
mFrameDelta *= -1;
|
mFrameDelta *= -1;
|
||||||
mCurrentFrame += mFrameDelta;
|
mCurrentFrame += mFrameDelta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mCurrentFrame < 0)
|
else if (mCurrentFrame < 0)
|
||||||
{
|
{
|
||||||
if (mAnimationType == JSprite::ANIMATION_TYPE_PINGPONG)
|
if (mAnimationType == JSprite::ANIMATION_TYPE_PINGPONG)
|
||||||
{
|
{
|
||||||
mFrameDelta *= -1;
|
mFrameDelta *= -1;
|
||||||
mCurrentFrame += mFrameDelta;
|
mCurrentFrame += mFrameDelta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAnimating)
|
if (mAnimating)
|
||||||
mFrames[mCurrentFrame]->Start();
|
mFrames[mCurrentFrame]->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimator::Render()
|
void JAnimator::Render()
|
||||||
{
|
{
|
||||||
if (!mActive)
|
if (!mActive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mFrames[mCurrentFrame]->Render(mX-mHotSpotX, mY-mHotSpotY);
|
mFrames[mCurrentFrame]->Render(mX-mHotSpotX, mY-mHotSpotY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JAnimator::IsActive()
|
bool JAnimator::IsActive()
|
||||||
{
|
{
|
||||||
return mActive;
|
return mActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JAnimator::IsAnimating()
|
bool JAnimator::IsAnimating()
|
||||||
{
|
{
|
||||||
return mAnimating;
|
return mAnimating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int JAnimator::GetCurrentFrameIndex()
|
int JAnimator::GetCurrentFrameIndex()
|
||||||
{
|
{
|
||||||
return mCurrentFrame;
|
return mCurrentFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimator::SetCurrentFrameIndex(int index)
|
void JAnimator::SetCurrentFrameIndex(int index)
|
||||||
{
|
{
|
||||||
if (index < (int)mFrames.size())
|
if (index < (int)mFrames.size())
|
||||||
mCurrentFrame = index;
|
mCurrentFrame = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimator::SetAnimationType(int type)
|
void JAnimator::SetAnimationType(int type)
|
||||||
{
|
{
|
||||||
mAnimationType = type;
|
mAnimationType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JResourceManager* JAnimator::GetResourceManager()
|
JResourceManager* JAnimator::GetResourceManager()
|
||||||
{
|
{
|
||||||
return mResource;
|
return mResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimator::SetPosition(float x, float y)
|
void JAnimator::SetPosition(float x, float y)
|
||||||
{
|
{
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimator::SetHotSpot(float x, float y)
|
void JAnimator::SetHotSpot(float x, float y)
|
||||||
{
|
{
|
||||||
mHotSpotX = x;
|
mHotSpotX = x;
|
||||||
mHotSpotY = y;
|
mHotSpotY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimatorFrame::JAnimatorFrame(JAnimator* parent __attribute__((unused)))
|
JAnimatorFrame::JAnimatorFrame(JAnimator* parent __attribute__((unused)))
|
||||||
{
|
{
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
mFrameTime = 100.0f;
|
mFrameTime = 100.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
JAnimatorFrame::~JAnimatorFrame()
|
JAnimatorFrame::~JAnimatorFrame()
|
||||||
{
|
{
|
||||||
while (mObjects.size()>0)
|
while (mObjects.size()>0)
|
||||||
{
|
{
|
||||||
JAnimatorObject* obj = mObjects.back();
|
JAnimatorObject* obj = mObjects.back();
|
||||||
mObjects.pop_back();
|
mObjects.pop_back();
|
||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
mObjects.clear();
|
mObjects.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimatorFrame::AddObject(JAnimatorObject *obj)
|
void JAnimatorFrame::AddObject(JAnimatorObject *obj)
|
||||||
{
|
{
|
||||||
mObjects.push_back(obj);
|
mObjects.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JAnimatorFrame::Update(float dt)
|
bool JAnimatorFrame::Update(float dt)
|
||||||
{
|
{
|
||||||
mTimer += dt;
|
mTimer += dt;
|
||||||
if (mTimer >= mFrameTime)
|
if (mTimer >= mFrameTime)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int size = mObjects.size();
|
int size = mObjects.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
mObjects[i]->Update(dt);
|
mObjects[i]->Update(dt);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimatorFrame::Render(float x, float y)
|
void JAnimatorFrame::Render(float x, float y)
|
||||||
{
|
{
|
||||||
int size = mObjects.size();
|
int size = mObjects.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
mObjects[i]->Render(x, y);
|
mObjects[i]->Render(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimatorFrame::Start()
|
void JAnimatorFrame::Start()
|
||||||
{
|
{
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool JAnimatorFrame::IsDone()
|
// bool JAnimatorFrame::IsDone()
|
||||||
// {
|
// {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void JAnimatorFrame::SetFrameTime(float duration)
|
void JAnimatorFrame::SetFrameTime(float duration)
|
||||||
{
|
{
|
||||||
mFrameTime = duration;
|
mFrameTime = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
JAnimatorObject::JAnimatorObject()
|
JAnimatorObject::JAnimatorObject()
|
||||||
{
|
{
|
||||||
mRenderer = JRenderer::GetInstance();
|
mRenderer = JRenderer::GetInstance();
|
||||||
mFlipped = false;
|
mFlipped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JAnimatorObject::~JAnimatorObject()
|
JAnimatorObject::~JAnimatorObject()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimatorObject::Update(float dt __attribute__((unused)))
|
void JAnimatorObject::Update(float dt __attribute__((unused)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JAnimatorObject::Render(float x, float y)
|
void JAnimatorObject::Render(float x, float y)
|
||||||
{
|
{
|
||||||
mQuad->SetHFlip(mFlipped);
|
mQuad->SetHFlip(mFlipped);
|
||||||
mQuad->SetColor(mColor);
|
mQuad->SetColor(mColor);
|
||||||
mRenderer->RenderQuad(mQuad, x+mX, y+mY, mRotation, mHScale, mVScale);
|
mRenderer->RenderQuad(mQuad, x+mX, y+mY, mRotation, mHScale, mVScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JAnimatorObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
void JAnimatorObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||||
void JAnimatorObject::SetPosition(float x, float y) { mX = x; mY = y; }
|
void JAnimatorObject::SetPosition(float x, float y) { mX = x; mY = y; }
|
||||||
void JAnimatorObject::SetRotation(float angle) { mRotation = angle; }
|
void JAnimatorObject::SetRotation(float angle) { mRotation = angle; }
|
||||||
void JAnimatorObject::SetHScale(float scale) { mHScale = scale; }
|
void JAnimatorObject::SetHScale(float scale) { mHScale = scale; }
|
||||||
void JAnimatorObject::SetVScale(float scale) { mVScale = scale; }
|
void JAnimatorObject::SetVScale(float scale) { mVScale = scale; }
|
||||||
void JAnimatorObject::SetColor(PIXEL_TYPE color) { mColor = color; }
|
void JAnimatorObject::SetColor(PIXEL_TYPE color) { mColor = color; }
|
||||||
void JAnimatorObject::SetFlip(bool flag) { mFlipped = flag; }
|
void JAnimatorObject::SetFlip(bool flag) { mFlipped = flag; }
|
||||||
|
|||||||
+331
-331
@@ -1,331 +1,331 @@
|
|||||||
#include <pspsdk.h>
|
#include <pspsdk.h>
|
||||||
#include <pspaudiocodec.h>
|
#include <pspaudiocodec.h>
|
||||||
#include <pspaudiolib.h>
|
#include <pspaudiolib.h>
|
||||||
#include <pspmpeg.h>
|
#include <pspmpeg.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../include/JAudio.h"
|
#include "../include/JAudio.h"
|
||||||
#include "../include/JFileSystem.h"
|
#include "../include/JFileSystem.h"
|
||||||
#include "../include/JCooleyesMP3.h"
|
#include "../include/JCooleyesMP3.h"
|
||||||
|
|
||||||
|
|
||||||
JCooleyesMP3::JCooleyesMP3()
|
JCooleyesMP3::JCooleyesMP3()
|
||||||
{
|
{
|
||||||
mPlaying = false;
|
mPlaying = false;
|
||||||
mp3_handle = 0;
|
mp3_handle = 0;
|
||||||
mFileBuffer = NULL;
|
mFileBuffer = NULL;
|
||||||
mMP3FirstFramePointer = NULL;
|
mMP3FirstFramePointer = NULL;
|
||||||
mFileSize = 0;
|
mFileSize = 0;
|
||||||
mCurrFramePointer = NULL;
|
mCurrFramePointer = NULL;
|
||||||
mDataPointer = 0;
|
mDataPointer = 0;
|
||||||
mSamplesPending = 0;
|
mSamplesPending = 0;
|
||||||
mAllMP3DataProcessed = true;
|
mAllMP3DataProcessed = true;
|
||||||
mUpdateCounter = 0;
|
mUpdateCounter = 0;
|
||||||
|
|
||||||
mLooping = false;
|
mLooping = false;
|
||||||
|
|
||||||
mChannelCount = 2;
|
mChannelCount = 2;
|
||||||
mSampleRate = 44100; // this is mp3 file's sample rate, also can be 48000,....
|
mSampleRate = 44100; // this is mp3 file's sample rate, also can be 48000,....
|
||||||
mSamplePerFrame = SAMPLE_PER_FRAME; // default value for MPEG1, Layer3
|
mSamplePerFrame = SAMPLE_PER_FRAME; // default value for MPEG1, Layer3
|
||||||
|
|
||||||
mOutputBufferIndex = 0;
|
mOutputBufferIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
JCooleyesMP3::~JCooleyesMP3()
|
JCooleyesMP3::~JCooleyesMP3()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JCooleyesMP3::IsPlaying()
|
bool JCooleyesMP3::IsPlaying()
|
||||||
{
|
{
|
||||||
return mPlaying;
|
return mPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JCooleyesMP3::InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer)
|
void JCooleyesMP3::InitBuffers(unsigned long *MP3CodecBuffer, short* decoderBuffer, short* decodedDataOutputBuffer)
|
||||||
{
|
{
|
||||||
|
|
||||||
mMP3CodecBuffer = MP3CodecBuffer;
|
mMP3CodecBuffer = MP3CodecBuffer;
|
||||||
mDecoderBuffer = decoderBuffer;
|
mDecoderBuffer = decoderBuffer;
|
||||||
mDecodedDataOutputBuffer = decodedDataOutputBuffer;
|
mDecodedDataOutputBuffer = decodedDataOutputBuffer;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JCooleyesMP3::Load(const char *filename)
|
bool JCooleyesMP3::Load(const char *filename)
|
||||||
{
|
{
|
||||||
if (!g_MP3DecoderOK)
|
if (!g_MP3DecoderOK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
|
|
||||||
//mp3_handle = sceIoOpen(filename, PSP_O_RDONLY, 0777);
|
//mp3_handle = sceIoOpen(filename, PSP_O_RDONLY, 0777);
|
||||||
if (fileSys->OpenFile(filename))
|
if (fileSys->OpenFile(filename))
|
||||||
{
|
{
|
||||||
mFileSize = fileSys->GetFileSize();// sceIoLseek32(mp3_handle, 0, PSP_SEEK_END);
|
mFileSize = fileSys->GetFileSize();// sceIoLseek32(mp3_handle, 0, PSP_SEEK_END);
|
||||||
//sceIoLseek32(mp3_handle, 0, PSP_SEEK_SET);
|
//sceIoLseek32(mp3_handle, 0, PSP_SEEK_SET);
|
||||||
|
|
||||||
mFileBuffer = (u8*)memalign(64, mFileSize);
|
mFileBuffer = (u8*)memalign(64, mFileSize);
|
||||||
if (mFileBuffer)
|
if (mFileBuffer)
|
||||||
{
|
{
|
||||||
if (fileSys->ReadFile(mFileBuffer, mFileSize ) != mFileSize)
|
if (fileSys->ReadFile(mFileBuffer, mFileSize ) != mFileSize)
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = false;
|
ret = false;
|
||||||
|
|
||||||
//sceIoClose(mp3_handle);
|
//sceIoClose(mp3_handle);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile();
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
mMP3FirstFramePointer = mFileBuffer;
|
mMP3FirstFramePointer = mFileBuffer;
|
||||||
|
|
||||||
// skip ID3v2.x header
|
// skip ID3v2.x header
|
||||||
if (mFileBuffer[0]=='I' && mFileBuffer[1]=='D' && mFileBuffer[2]=='3')
|
if (mFileBuffer[0]=='I' && mFileBuffer[1]=='D' && mFileBuffer[2]=='3')
|
||||||
{
|
{
|
||||||
u32 size = mFileBuffer[9];
|
u32 size = mFileBuffer[9];
|
||||||
u32 n = mFileBuffer[8];
|
u32 n = mFileBuffer[8];
|
||||||
size |= (n<<7);
|
size |= (n<<7);
|
||||||
|
|
||||||
n = mFileBuffer[7];
|
n = mFileBuffer[7];
|
||||||
size |= (n<<14);
|
size |= (n<<14);
|
||||||
|
|
||||||
n = mFileBuffer[6];
|
n = mFileBuffer[6];
|
||||||
size |= (n<<21);
|
size |= (n<<21);
|
||||||
|
|
||||||
size += 10;
|
size += 10;
|
||||||
|
|
||||||
mMP3FirstFramePointer += size;
|
mMP3FirstFramePointer += size;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mAllMP3DataProcessed = !ret;
|
mAllMP3DataProcessed = !ret;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JCooleyesMP3::Release()
|
void JCooleyesMP3::Release()
|
||||||
{
|
{
|
||||||
mAllMP3DataProcessed = true;
|
mAllMP3DataProcessed = true;
|
||||||
|
|
||||||
if (mFileBuffer)
|
if (mFileBuffer)
|
||||||
{
|
{
|
||||||
free(mFileBuffer);
|
free(mFileBuffer);
|
||||||
mFileBuffer = NULL;
|
mFileBuffer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JCooleyesMP3::Play(bool looping)
|
bool JCooleyesMP3::Play(bool looping)
|
||||||
{
|
{
|
||||||
if (!mAllMP3DataProcessed)
|
if (!mAllMP3DataProcessed)
|
||||||
{
|
{
|
||||||
mOutputBufferIndex = 0;
|
mOutputBufferIndex = 0;
|
||||||
mLooping = looping;
|
mLooping = looping;
|
||||||
|
|
||||||
mUpdateCounter = 0;
|
mUpdateCounter = 0;
|
||||||
mSamplesPending = 0;
|
mSamplesPending = 0;
|
||||||
mDataPointer = 0;
|
mDataPointer = 0;
|
||||||
mCurrFramePointer = mMP3FirstFramePointer;
|
mCurrFramePointer = mMP3FirstFramePointer;
|
||||||
|
|
||||||
mPlaying = true;
|
mPlaying = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
//MP3Decode();
|
//MP3Decode();
|
||||||
//MP3Decode();
|
//MP3Decode();
|
||||||
//MP3Decode();
|
//MP3Decode();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mPlaying = false;
|
mPlaying = false;
|
||||||
|
|
||||||
return mPlaying;
|
return mPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// bool JCooleyesMP3::PlaybackDone()
|
// bool JCooleyesMP3::PlaybackDone()
|
||||||
// {
|
// {
|
||||||
// return (mAllMP3DataProcessed && mSamplesPending==0);
|
// return (mAllMP3DataProcessed && mSamplesPending==0);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
void JCooleyesMP3::FeedAudioData(void* buf, unsigned int length/*, bool mixing*/)
|
void JCooleyesMP3::FeedAudioData(void* buf, unsigned int length/*, bool mixing*/)
|
||||||
{
|
{
|
||||||
if (mPlaying)
|
if (mPlaying)
|
||||||
{
|
{
|
||||||
if (mSamplesPending > 0)
|
if (mSamplesPending > 0)
|
||||||
{
|
{
|
||||||
short *dest = (short *)buf;
|
short *dest = (short *)buf;
|
||||||
|
|
||||||
if ((int)length > mSamplesPending)
|
if ((int)length > mSamplesPending)
|
||||||
length = mSamplesPending;
|
length = mSamplesPending;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int count = length<<1;//*2
|
int count = length<<1;//*2
|
||||||
int bufferMax = mSamplePerFrame<<2; //1152 * 2 * 4
|
int bufferMax = mSamplePerFrame<<2; //1152 * 2 * 4
|
||||||
for (i=0;i<count;i++)
|
for (i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
// if (mixing)
|
// if (mixing)
|
||||||
// {
|
// {
|
||||||
// dest[i] >>= 1;
|
// dest[i] >>= 1;
|
||||||
// dest[i] |= (mDecodedDataOutputBuffer[mDataPointer]>>1);
|
// dest[i] |= (mDecodedDataOutputBuffer[mDataPointer]>>1);
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
|
|
||||||
dest[i] = mDecodedDataOutputBuffer[mDataPointer];
|
dest[i] = mDecodedDataOutputBuffer[mDataPointer];
|
||||||
|
|
||||||
mDataPointer++;
|
mDataPointer++;
|
||||||
if (mDataPointer >= bufferMax)
|
if (mDataPointer >= bufferMax)
|
||||||
mDataPointer = 0;
|
mDataPointer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSamplesPending -= length;
|
mSamplesPending -= length;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
|
|
||||||
if (mAllMP3DataProcessed && mSamplesPending<=0)
|
if (mAllMP3DataProcessed && mSamplesPending<=0)
|
||||||
{
|
{
|
||||||
if (mLooping)
|
if (mLooping)
|
||||||
{
|
{
|
||||||
mSamplesPending = 0;
|
mSamplesPending = 0;
|
||||||
mAllMP3DataProcessed = false;
|
mAllMP3DataProcessed = false;
|
||||||
mUpdateCounter = 0;
|
mUpdateCounter = 0;
|
||||||
mCurrFramePointer = mMP3FirstFramePointer;
|
mCurrFramePointer = mMP3FirstFramePointer;
|
||||||
|
|
||||||
Decode();
|
Decode();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mPlaying = false;
|
mPlaying = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JCooleyesMP3::Decode()
|
void JCooleyesMP3::Decode()
|
||||||
{
|
{
|
||||||
if (mAllMP3DataProcessed)
|
if (mAllMP3DataProcessed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
// get offset to current decoding buffer
|
// get offset to current decoding buffer
|
||||||
int dest = mOutputBufferIndex*(mSamplePerFrame<<1);//*2;
|
int dest = mOutputBufferIndex*(mSamplePerFrame<<1);//*2;
|
||||||
|
|
||||||
if (mSamplesPending == 0 || dest > mDataPointer || (dest + (int)(mSamplePerFrame<<1) < mDataPointer)) //1152*2;
|
if (mSamplesPending == 0 || dest > mDataPointer || (dest + (int)(mSamplePerFrame<<1) < mDataPointer)) //1152*2;
|
||||||
{
|
{
|
||||||
|
|
||||||
memset(mDecoderBuffer, 0, mSamplePerFrame<<2);//*2*2);
|
memset(mDecoderBuffer, 0, mSamplePerFrame<<2);//*2*2);
|
||||||
|
|
||||||
unsigned int mp3_header = mCurrFramePointer[0];
|
unsigned int mp3_header = mCurrFramePointer[0];
|
||||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||||
mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||||
|
|
||||||
int bitrate = (mp3_header & 0xf000) >> 12;
|
int bitrate = (mp3_header & 0xf000) >> 12;
|
||||||
int padding = (mp3_header & 0x200) >> 9;
|
int padding = (mp3_header & 0x200) >> 9;
|
||||||
|
|
||||||
int bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320};
|
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;
|
int frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||||
|
|
||||||
|
|
||||||
// skip 1 frame
|
// skip 1 frame
|
||||||
|
|
||||||
// mCurrFramePointer += frame_size;
|
// mCurrFramePointer += frame_size;
|
||||||
// mUpdateCounter += frame_size;
|
// mUpdateCounter += frame_size;
|
||||||
//
|
//
|
||||||
// mp3_header = mCurrFramePointer[0];
|
// mp3_header = mCurrFramePointer[0];
|
||||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
// mp3_header = (mp3_header<<8) | mCurrFramePointer[1];
|
||||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
// mp3_header = (mp3_header<<8) | mCurrFramePointer[2];
|
||||||
// mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
// mp3_header = (mp3_header<<8) | mCurrFramePointer[3];
|
||||||
//
|
//
|
||||||
// bitrate = (mp3_header & 0xf000) >> 12;
|
// bitrate = (mp3_header & 0xf000) >> 12;
|
||||||
// padding = (mp3_header & 0x200) >> 9;
|
// padding = (mp3_header & 0x200) >> 9;
|
||||||
//
|
//
|
||||||
// frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
// frame_size = 144000*bitrates[bitrate]/mSampleRate + padding;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||||
|
|
||||||
u8* mp3_data_buffer = (u8*)memalign(64, frame_size);
|
u8* mp3_data_buffer = (u8*)memalign(64, frame_size);
|
||||||
memcpy(mp3_data_buffer, mCurrFramePointer, frame_size);
|
memcpy(mp3_data_buffer, mCurrFramePointer, frame_size);
|
||||||
mMP3CodecBuffer[6] = (unsigned long)mp3_data_buffer;
|
mMP3CodecBuffer[6] = (unsigned long)mp3_data_buffer;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
#else
|
#else
|
||||||
|
|
||||||
mMP3CodecBuffer[6] = (unsigned long)mCurrFramePointer;
|
mMP3CodecBuffer[6] = (unsigned long)mCurrFramePointer;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mMP3CodecBuffer[8] = (unsigned long)mDecoderBuffer;
|
mMP3CodecBuffer[8] = (unsigned long)mDecoderBuffer;
|
||||||
|
|
||||||
mMP3CodecBuffer[7] = mMP3CodecBuffer[10] = frame_size;
|
mMP3CodecBuffer[7] = mMP3CodecBuffer[10] = frame_size;
|
||||||
mMP3CodecBuffer[9] = mSamplePerFrame << 2;//* 4;
|
mMP3CodecBuffer[9] = mSamplePerFrame << 2;//* 4;
|
||||||
|
|
||||||
int res = sceAudiocodecDecode(mMP3CodecBuffer, 0x1002);
|
int res = sceAudiocodecDecode(mMP3CodecBuffer, 0x1002);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
#if defined (FORCE_BUFFER_ALIGNMENT)
|
#if defined (FORCE_BUFFER_ALIGNMENT)
|
||||||
|
|
||||||
free (mp3_data_buffer);
|
free (mp3_data_buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if ( res < 0 )
|
if ( res < 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
mAllMP3DataProcessed = true;
|
mAllMP3DataProcessed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
short *buffer = mDecodedDataOutputBuffer+dest;//mOutputBufferIndex*1152*2;
|
short *buffer = mDecodedDataOutputBuffer+dest;//mOutputBufferIndex*1152*2;
|
||||||
|
|
||||||
memcpy(buffer, mDecoderBuffer, mSamplePerFrame<<2);//1152*4);
|
memcpy(buffer, mDecoderBuffer, mSamplePerFrame<<2);//1152*4);
|
||||||
|
|
||||||
mOutputBufferIndex = (mOutputBufferIndex+1)%DECODING_BUFFER_COUNT;
|
mOutputBufferIndex = (mOutputBufferIndex+1)%DECODING_BUFFER_COUNT;
|
||||||
|
|
||||||
mSamplesPending += mSamplePerFrame;
|
mSamplesPending += mSamplePerFrame;
|
||||||
|
|
||||||
mCurrFramePointer += frame_size;
|
mCurrFramePointer += frame_size;
|
||||||
mUpdateCounter += frame_size;
|
mUpdateCounter += frame_size;
|
||||||
|
|
||||||
if (mUpdateCounter >= mFileSize)
|
if (mUpdateCounter >= mFileSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
mAllMP3DataProcessed = true;
|
mAllMP3DataProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JCooleyesMP3::Stop()
|
void JCooleyesMP3::Stop()
|
||||||
{
|
{
|
||||||
mPlaying = false;
|
mPlaying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JCooleyesMP3::Resume()
|
void JCooleyesMP3::Resume()
|
||||||
{
|
{
|
||||||
if (!mAllMP3DataProcessed)
|
if (!mAllMP3DataProcessed)
|
||||||
mPlaying = true;
|
mPlaying = true;
|
||||||
}
|
}
|
||||||
|
|||||||
+121
-121
@@ -1,121 +1,121 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "../include/JDistortionMesh.h"
|
#include "../include/JDistortionMesh.h"
|
||||||
|
|
||||||
|
|
||||||
JRenderer* JDistortionMesh::mRenderer = NULL;
|
JRenderer* JDistortionMesh::mRenderer = NULL;
|
||||||
|
|
||||||
JDistortionMesh::JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows)
|
JDistortionMesh::JDistortionMesh(JTexture *tex, float x, float y, float width, float height, int cols, int rows)
|
||||||
{
|
{
|
||||||
mRenderer = JRenderer::GetInstance();
|
mRenderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
mCols = cols;
|
mCols = cols;
|
||||||
mRows = rows;
|
mRows = rows;
|
||||||
|
|
||||||
mCellWidth = width/(mCols-1);
|
mCellWidth = width/(mCols-1);
|
||||||
mCellHeight = height/(mRows-1);
|
mCellHeight = height/(mRows-1);
|
||||||
|
|
||||||
mTexX = x;
|
mTexX = x;
|
||||||
mTexY = y;
|
mTexY = y;
|
||||||
mTexWidth = width;
|
mTexWidth = width;
|
||||||
mTexHeight = height;
|
mTexHeight = height;
|
||||||
|
|
||||||
mQuad = new JQuad(tex, x, y, mCellWidth, mCellHeight);
|
mQuad = new JQuad(tex, x, y, mCellWidth, mCellHeight);
|
||||||
|
|
||||||
mVertices = new Vertex[mCols*mRows];
|
mVertices = new Vertex[mCols*mRows];
|
||||||
|
|
||||||
for(int j=0; j<mRows; j++)
|
for(int j=0; j<mRows; j++)
|
||||||
{
|
{
|
||||||
for(int i=0; i<mCols; i++)
|
for(int i=0; i<mCols; i++)
|
||||||
{
|
{
|
||||||
mVertices[j*mCols+i].u = x+i*mCellWidth;
|
mVertices[j*mCols+i].u = x+i*mCellWidth;
|
||||||
mVertices[j*mCols+i].v = y+j*mCellHeight;
|
mVertices[j*mCols+i].v = y+j*mCellHeight;
|
||||||
|
|
||||||
mVertices[j*mCols+i].x = i*mCellWidth;
|
mVertices[j*mCols+i].x = i*mCellWidth;
|
||||||
mVertices[j*mCols+i].y = j*mCellHeight;
|
mVertices[j*mCols+i].y = j*mCellHeight;
|
||||||
|
|
||||||
mVertices[j*mCols+i].color = ARGB(0,0,0,0);
|
mVertices[j*mCols+i].color = ARGB(0,0,0,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JDistortionMesh::~JDistortionMesh()
|
JDistortionMesh::~JDistortionMesh()
|
||||||
{
|
{
|
||||||
|
|
||||||
delete mQuad;
|
delete mQuad;
|
||||||
delete[] mVertices;
|
delete[] mVertices;
|
||||||
|
|
||||||
// JGERelease();
|
// JGERelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JDistortionMesh::Render(float x, float y)
|
void JDistortionMesh::Render(float x, float y)
|
||||||
{
|
{
|
||||||
|
|
||||||
// mQuad->mBlend = GU_TFX_ADD;
|
// mQuad->mBlend = GU_TFX_ADD;
|
||||||
|
|
||||||
VertexColor points[4];
|
VertexColor points[4];
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for(int j=0; j<mRows-1; j++)
|
for(int j=0; j<mRows-1; j++)
|
||||||
{
|
{
|
||||||
for(int i=0; i<mCols-1; i++)
|
for(int i=0; i<mCols-1; i++)
|
||||||
{
|
{
|
||||||
index=j*mCols+i;
|
index=j*mCols+i;
|
||||||
|
|
||||||
mQuad->SetTextureRect(mVertices[index].u, mVertices[index].v, mCellWidth, mCellHeight);
|
mQuad->SetTextureRect(mVertices[index].u, mVertices[index].v, mCellWidth, mCellHeight);
|
||||||
|
|
||||||
points[0].x = x+mVertices[index].x;
|
points[0].x = x+mVertices[index].x;
|
||||||
points[0].y = y+mVertices[index].y;
|
points[0].y = y+mVertices[index].y;
|
||||||
points[0].z = mVertices[index].z;
|
points[0].z = mVertices[index].z;
|
||||||
points[0].color = mVertices[index].color;
|
points[0].color = mVertices[index].color;
|
||||||
|
|
||||||
points[1].x = x+mVertices[index+1].x;
|
points[1].x = x+mVertices[index+1].x;
|
||||||
points[1].y = y+mVertices[index+1].y;
|
points[1].y = y+mVertices[index+1].y;
|
||||||
points[1].z = mVertices[index+1].z;
|
points[1].z = mVertices[index+1].z;
|
||||||
points[1].color = mVertices[index+1].color;
|
points[1].color = mVertices[index+1].color;
|
||||||
|
|
||||||
points[2].x = x+mVertices[index+mCols].x;
|
points[2].x = x+mVertices[index+mCols].x;
|
||||||
points[2].y = y+mVertices[index+mCols].y;
|
points[2].y = y+mVertices[index+mCols].y;
|
||||||
points[2].z = mVertices[index+mCols].z;
|
points[2].z = mVertices[index+mCols].z;
|
||||||
points[2].color = mVertices[index+mCols].color;
|
points[2].color = mVertices[index+mCols].color;
|
||||||
|
|
||||||
points[3].x = x+mVertices[index+mCols+1].x;
|
points[3].x = x+mVertices[index+mCols+1].x;
|
||||||
points[3].y = y+mVertices[index+mCols+1].y;
|
points[3].y = y+mVertices[index+mCols+1].y;
|
||||||
points[3].z = mVertices[index+mCols+1].z;
|
points[3].z = mVertices[index+mCols+1].z;
|
||||||
points[3].color = mVertices[index+mCols+1].color;
|
points[3].color = mVertices[index+mCols+1].color;
|
||||||
|
|
||||||
mRenderer->RenderQuad(mQuad, points);
|
mRenderer->RenderQuad(mQuad, points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
void JDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||||
{
|
{
|
||||||
mVertices[row*mCols+col].color = color;
|
mVertices[row*mCols+col].color = color;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JDistortionMesh::SetDisplacement(int col, int row, float dx, float dy)
|
void JDistortionMesh::SetDisplacement(int col, int row, float dx, float dy)
|
||||||
{
|
{
|
||||||
dx += col*mCellWidth;
|
dx += col*mCellWidth;
|
||||||
dy += row*mCellHeight;
|
dy += row*mCellHeight;
|
||||||
|
|
||||||
mVertices[row*mCols+col].x = dx;
|
mVertices[row*mCols+col].x = dx;
|
||||||
mVertices[row*mCols+col].y = dy;
|
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.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JApp.h"
|
#include "../include/JApp.h"
|
||||||
|
|
||||||
#include "../include/JGameObject.h"
|
#include "../include/JGameObject.h"
|
||||||
|
|
||||||
|
|
||||||
//JRenderer* JGameObject::mRenderer = NULL;
|
//JRenderer* JGameObject::mRenderer = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JGameObject::JGameObject(JTexture *tex, float x, float y, float width, float height)
|
JGameObject::JGameObject(JTexture *tex, float x, float y, float width, float height)
|
||||||
:JSprite(tex, x, y, width, height)
|
:JSprite(tex, x, y, width, height)
|
||||||
{
|
{
|
||||||
//mRenderer = JRenderer::GetInstance();
|
//mRenderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
//mX = 0.0f;
|
//mX = 0.0f;
|
||||||
//mY = 0.0f;
|
//mY = 0.0f;
|
||||||
|
|
||||||
mRenderFlags = 0;
|
mRenderFlags = 0;
|
||||||
//mSize = 1.0f;
|
//mSize = 1.0f;
|
||||||
//mAngle = 0.0f;
|
//mAngle = 0.0f;
|
||||||
|
|
||||||
mOriginalBlood = 1;
|
mOriginalBlood = 1;
|
||||||
mBlood = 1;
|
mBlood = 1;
|
||||||
mHitPoint = 1;
|
mHitPoint = 1;
|
||||||
|
|
||||||
mCollided = false;
|
mCollided = false;
|
||||||
mCollisionTarget = NULL;
|
mCollisionTarget = NULL;
|
||||||
mFlashing = false;
|
mFlashing = false;
|
||||||
|
|
||||||
//mActive = false;
|
//mActive = false;
|
||||||
|
|
||||||
mRotationDelta = 0.0f;
|
mRotationDelta = 0.0f;
|
||||||
mDoRotation = false;
|
mDoRotation = false;
|
||||||
|
|
||||||
mAlphaDelta = 0.0f;
|
mAlphaDelta = 0.0f;
|
||||||
mDoAlpha = false;
|
mDoAlpha = false;
|
||||||
|
|
||||||
mDoScaling = false;
|
mDoScaling = false;
|
||||||
mScaleDelta = 0.0f;
|
mScaleDelta = 0.0f;
|
||||||
|
|
||||||
SetBBox(x, y, width, height);
|
SetBBox(x, y, width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JGameObject::~JGameObject()
|
JGameObject::~JGameObject()
|
||||||
{
|
{
|
||||||
// JGERelease();
|
// JGERelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::Update(float dt)
|
void JGameObject::Update(float dt)
|
||||||
{
|
{
|
||||||
JSprite::Update(dt);
|
JSprite::Update(dt);
|
||||||
|
|
||||||
if (mFlashing)
|
if (mFlashing)
|
||||||
{
|
{
|
||||||
mFlashTimer += dt;
|
mFlashTimer += dt;
|
||||||
if (mFlashTimer > FLASH_TIME)
|
if (mFlashTimer > FLASH_TIME)
|
||||||
{
|
{
|
||||||
mFlashTimer = 0;
|
mFlashTimer = 0;
|
||||||
mFlashCounter++;
|
mFlashCounter++;
|
||||||
if (mFlashCounter > FLASHING_COUNT)
|
if (mFlashCounter > FLASHING_COUNT)
|
||||||
mFlashing = false;
|
mFlashing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDoAlpha)
|
if (mDoAlpha)
|
||||||
{
|
{
|
||||||
mAlpha += mAlphaDelta*dt;
|
mAlpha += mAlphaDelta*dt;
|
||||||
if (mAlpha < 0.0f)
|
if (mAlpha < 0.0f)
|
||||||
{
|
{
|
||||||
mAlpha = 0.0f;
|
mAlpha = 0.0f;
|
||||||
if (mAnimationType == ANIMATION_TYPE_ONCE_AND_GONE)
|
if (mAnimationType == ANIMATION_TYPE_ONCE_AND_GONE)
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
else if (mAlpha > 255.0f)
|
else if (mAlpha > 255.0f)
|
||||||
{
|
{
|
||||||
mAlpha = 255.0f;
|
mAlpha = 255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDoRotation || mDoScaling)
|
if (mDoRotation || mDoScaling)
|
||||||
{
|
{
|
||||||
mRotation += mRotationDelta*dt;
|
mRotation += mRotationDelta*dt;
|
||||||
mHScale += mScaleDelta*dt;
|
mHScale += mScaleDelta*dt;
|
||||||
mVScale += mScaleDelta*dt;
|
mVScale += mScaleDelta*dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::Render()
|
void JGameObject::Render()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if (mQuad != NULL)
|
if (mQuad != NULL)
|
||||||
{
|
{
|
||||||
//mEngine->RenderQuad(mQuad, mX, mY);
|
//mEngine->RenderQuad(mQuad, mX, mY);
|
||||||
if (mFlashing && (mFlashCounter&1)==0)
|
if (mFlashing && (mFlashCounter&1)==0)
|
||||||
{
|
{
|
||||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||||
angle = mAngle;
|
angle = mAngle;
|
||||||
if ((mRenderFlags & RENDER_FLAG_ROTATION)==RENDER_FLAG_ROTATION)
|
if ((mRenderFlags & RENDER_FLAG_ROTATION)==RENDER_FLAG_ROTATION)
|
||||||
angle = mRotation;
|
angle = mRotation;
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||||
scale = mSize;
|
scale = mSize;
|
||||||
|
|
||||||
mRenderer->RenderQuad(mQuad, mX, mY, angle, scale, scale);
|
mRenderer->RenderQuad(mQuad, mX, mY, angle, scale, scale);
|
||||||
|
|
||||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!mActive) return;
|
if (!mActive) return;
|
||||||
|
|
||||||
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
if ((mRenderFlags & RENDER_FLAG_ANGLE)==RENDER_FLAG_ANGLE)
|
||||||
mRotation = mDirection;
|
mRotation = mDirection;
|
||||||
|
|
||||||
if (mFlashing && (mFlashCounter&1)==0)
|
if (mFlashing && (mFlashCounter&1)==0)
|
||||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||||
|
|
||||||
// if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
// if ((mRenderFlags & RENDER_FLAG_SIZE)==RENDER_FLAG_SIZE)
|
||||||
// {
|
// {
|
||||||
// mHScale = mSize;
|
// mHScale = mSize;
|
||||||
// mVScale = mSize;
|
// mVScale = mSize;
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// mHScale = 1.0f;
|
// mHScale = 1.0f;
|
||||||
// mVScale = 1.0f;
|
// mVScale = 1.0f;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
JSprite::Render();
|
JSprite::Render();
|
||||||
|
|
||||||
if (mFlashing)
|
if (mFlashing)
|
||||||
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
mRenderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void JGameObject::SetPosition(float x, float y)
|
// void JGameObject::SetPosition(float x, float y)
|
||||||
// {
|
// {
|
||||||
// // mPos = Vector2D(x, y);
|
// // mPos = Vector2D(x, y);
|
||||||
// mX = x;
|
// mX = x;
|
||||||
// mY = y;
|
// mY = y;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
//void JGameObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
//void JGameObject::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//void JParticle::ResetVelocity()
|
//void JParticle::ResetVelocity()
|
||||||
//{
|
//{
|
||||||
// float xx = mSpeed * cosf(mAngle);
|
// float xx = mSpeed * cosf(mAngle);
|
||||||
// float yy = mSpeed * sinf(mAngle);
|
// float yy = mSpeed * sinf(mAngle);
|
||||||
// mVelocity = Vector2D(xx, yy);
|
// mVelocity = Vector2D(xx, yy);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::SetBBox(float x, float y, float width, float height)
|
void JGameObject::SetBBox(float x, float y, float width, float height)
|
||||||
{
|
{
|
||||||
mUseBoundingBox = true;
|
mUseBoundingBox = true;
|
||||||
|
|
||||||
mBBoxX = x;
|
mBBoxX = x;
|
||||||
mBBoxY = y;
|
mBBoxY = y;
|
||||||
mBBoxWidth = width;
|
mBBoxWidth = width;
|
||||||
mBBoxHeight = height;
|
mBBoxHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGameObject::GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height)
|
void JGameObject::GetBBox(float x, float y, float* xNow, float* yNow, float* width, float *height)
|
||||||
{
|
{
|
||||||
*xNow = x + mBBoxX;
|
*xNow = x + mBBoxX;
|
||||||
*yNow = y + mBBoxY;
|
*yNow = y + mBBoxY;
|
||||||
*width = mBBoxWidth;
|
*width = mBBoxWidth;
|
||||||
*height = mBBoxHeight;
|
*height = mBBoxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JGameObject::Collide(JGameObject *target)
|
bool JGameObject::Collide(JGameObject *target)
|
||||||
{
|
{
|
||||||
if (mUseBoundingBox)
|
if (mUseBoundingBox)
|
||||||
{
|
{
|
||||||
// bounding box collision detection
|
// bounding box collision detection
|
||||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) < -target->mBBoxWidth) return false;
|
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) < -target->mBBoxWidth) return false;
|
||||||
if ((target->mX+target->mBBoxX)-(mX+mBBoxX) > 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) < -target->mBBoxHeight) return false;
|
||||||
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) > mBBoxHeight) return false;
|
if ((target->mY+target->mBBoxY)-(mY+mBBoxY) > mBBoxHeight) return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Circle-Circle collision detection
|
// Circle-Circle collision detection
|
||||||
float dx = (mX+mCenterX)-(target->mX+target->mCenterX);
|
float dx = (mX+mCenterX)-(target->mX+target->mCenterX);
|
||||||
float dy = (mY+mCenterY)-(target->mY+target->mCenterY);
|
float dy = (mY+mCenterY)-(target->mY+target->mCenterY);
|
||||||
float dr = mRadius+target->mRadius;
|
float dr = mRadius+target->mRadius;
|
||||||
if (dx*dx + dy*dy > dr*dr)
|
if (dx*dx + dy*dy > dr*dr)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//mCollided = true;
|
//mCollided = true;
|
||||||
//mCollisionTarget = target;
|
//mCollisionTarget = target;
|
||||||
SetCollisionTarget(target);
|
SetCollisionTarget(target);
|
||||||
target->SetCollisionTarget(this);
|
target->SetCollisionTarget(this);
|
||||||
|
|
||||||
return true; // collision!!!
|
return true; // collision!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::SetCollisionTarget(JGameObject *target)
|
void JGameObject::SetCollisionTarget(JGameObject *target)
|
||||||
{
|
{
|
||||||
mBlood -= target->GetHitPoint();
|
mBlood -= target->GetHitPoint();
|
||||||
if (mBlood < 0)
|
if (mBlood < 0)
|
||||||
{
|
{
|
||||||
// mActive = false;
|
// mActive = false;
|
||||||
mBlood = 0;
|
mBlood = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCollided = true;
|
mCollided = true;
|
||||||
mCollisionTarget = target;
|
mCollisionTarget = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int JGameObject::GetHitPoint()
|
int JGameObject::GetHitPoint()
|
||||||
{
|
{
|
||||||
return mHitPoint;
|
return mHitPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::SetHitPoint(int pt)
|
void JGameObject::SetHitPoint(int pt)
|
||||||
{
|
{
|
||||||
mHitPoint = pt;
|
mHitPoint = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::SetBlood(int pt)
|
void JGameObject::SetBlood(int pt)
|
||||||
{
|
{
|
||||||
mOriginalBlood = pt;
|
mOriginalBlood = pt;
|
||||||
mBlood = pt;
|
mBlood = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JGameObject::GetBlood()
|
int JGameObject::GetBlood()
|
||||||
{
|
{
|
||||||
return mBlood;
|
return mBlood;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::OnCollide()
|
void JGameObject::OnCollide()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::StartFlashing()
|
void JGameObject::StartFlashing()
|
||||||
{
|
{
|
||||||
mFlashing = true;
|
mFlashing = true;
|
||||||
mFlashTimer = 0.0f;
|
mFlashTimer = 0.0f;
|
||||||
mFlashCounter = 0;
|
mFlashCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::StopFlashing()
|
void JGameObject::StopFlashing()
|
||||||
{
|
{
|
||||||
mFlashing = false;
|
mFlashing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JGameObject::IsFlashing()
|
bool JGameObject::IsFlashing()
|
||||||
{
|
{
|
||||||
return mFlashing;
|
return mFlashing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGameObject::SetRenderFlags(int flags)
|
void JGameObject::SetRenderFlags(int flags)
|
||||||
{
|
{
|
||||||
mRenderFlags = flags;
|
mRenderFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void JGameObject::SetSize(float size)
|
// void JGameObject::SetSize(float size)
|
||||||
// {
|
// {
|
||||||
// mSize = size;
|
// mSize = size;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// void JGameObject::SetAngle(float angle)
|
// void JGameObject::SetAngle(float angle)
|
||||||
// {
|
// {
|
||||||
// mAngle = angle;
|
// mAngle = angle;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void JGameObject::EnableAlpha(bool flag, float delta) { mDoAlpha = flag; mAlphaDelta = delta; }
|
void JGameObject::EnableAlpha(bool flag, float delta) { mDoAlpha = flag; mAlphaDelta = delta; }
|
||||||
void JGameObject::EnableScaling(bool flag, float delta) { mDoScaling = flag; mScaleDelta = 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::EnableRotation(bool flag, float delta) { mDoRotation = flag; mRotationDelta = delta; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JGameObject::SetCollisionCircle(float cx, float cy, float radius)
|
void JGameObject::SetCollisionCircle(float cx, float cy, float radius)
|
||||||
{
|
{
|
||||||
mUseBoundingBox = false;
|
mUseBoundingBox = false;
|
||||||
|
|
||||||
mCenterX = cx;
|
mCenterX = cx;
|
||||||
mCenterY = cy;
|
mCenterY = cy;
|
||||||
mRadius = radius;
|
mRadius = radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
JGameObject *JGameObject::GetCollisionTarget()
|
JGameObject *JGameObject::GetCollisionTarget()
|
||||||
{
|
{
|
||||||
return mCollisionTarget;
|
return mCollisionTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void JGameObject::SetSize(float size)
|
// void JGameObject::SetSize(float size)
|
||||||
// {
|
// {
|
||||||
// mSize = size;
|
// mSize = size;
|
||||||
// //mHScale = size;
|
// //mHScale = size;
|
||||||
// //mVScale = 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.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JGui.h"
|
#include "../include/JGui.h"
|
||||||
|
|
||||||
JGE* JGuiObject::mEngine = NULL;
|
JGE* JGuiObject::mEngine = NULL;
|
||||||
|
|
||||||
JGE* JGuiController::mEngine = NULL;
|
JGE* JGuiController::mEngine = NULL;
|
||||||
|
|
||||||
JGuiObject::JGuiObject(int id) :
|
JGuiObject::JGuiObject(int id) :
|
||||||
mId(id)
|
mId(id)
|
||||||
{
|
{
|
||||||
mEngine = JGE::GetInstance();
|
mEngine = JGE::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
JGuiObject::~JGuiObject()
|
JGuiObject::~JGuiObject()
|
||||||
{
|
{
|
||||||
// JGERelease();
|
// JGERelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
|
bool JGuiObject::Leaving(JButton key __attribute__((unused)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JGuiObject::ButtonPressed()
|
bool JGuiObject::ButtonPressed()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiObject::Entering()
|
void JGuiObject::Entering()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int JGuiObject::GetId()
|
int JGuiObject::GetId()
|
||||||
{
|
{
|
||||||
return mId;
|
return mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiObject::Update(float dt __attribute__((unused)))
|
void JGuiObject::Update(float dt __attribute__((unused)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream& operator<<(ostream &out, const JGuiObject &j)
|
ostream& operator<<(ostream &out, const JGuiObject &j)
|
||||||
{
|
{
|
||||||
return j.toString(out);
|
return j.toString(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
JGuiController::JGuiController(int id, JGuiListener* listener) :
|
JGuiController::JGuiController(int id, JGuiListener* listener) :
|
||||||
mId(id), mListener(listener)
|
mId(id), mListener(listener)
|
||||||
{
|
{
|
||||||
mEngine = JGE::GetInstance();
|
mEngine = JGE::GetInstance();
|
||||||
|
|
||||||
mBg = NULL;
|
mBg = NULL;
|
||||||
mShadingBg = NULL;
|
mShadingBg = NULL;
|
||||||
|
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
mCurr = 0;
|
mCurr = 0;
|
||||||
|
|
||||||
mCursorX = SCREEN_WIDTH / 2;
|
mCursorX = SCREEN_WIDTH / 2;
|
||||||
mCursorY = SCREEN_HEIGHT / 2;
|
mCursorY = SCREEN_HEIGHT / 2;
|
||||||
mShowCursor = false;
|
mShowCursor = false;
|
||||||
|
|
||||||
mActionButton = JGE_BTN_OK;
|
mActionButton = JGE_BTN_OK;
|
||||||
mCancelButton = JGE_BTN_MENU;
|
mCancelButton = JGE_BTN_MENU;
|
||||||
|
|
||||||
mStyle = JGUI_STYLE_WRAPPING;
|
mStyle = JGUI_STYLE_WRAPPING;
|
||||||
|
|
||||||
mActive = true;
|
mActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JGuiController::~JGuiController()
|
JGuiController::~JGuiController()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
if (mObjects[i] != NULL) delete mObjects[i];
|
if (mObjects[i] != NULL) delete mObjects[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Render()
|
void JGuiController::Render()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
if (mObjects[i] != NULL) mObjects[i]->Render();
|
if (mObjects[i] != NULL) mObjects[i]->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JGuiController::CheckUserInput(JButton key)
|
bool JGuiController::CheckUserInput(JButton key)
|
||||||
{
|
{
|
||||||
if (!mCount) return false;
|
if (!mCount) return false;
|
||||||
if (key == mActionButton)
|
if (key == mActionButton)
|
||||||
{
|
{
|
||||||
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
if (!mObjects.empty() && mObjects[mCurr] != NULL && mObjects[mCurr]->ButtonPressed())
|
||||||
{
|
{
|
||||||
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
if (mListener != NULL) mListener->ButtonPressed(mId, mObjects[mCurr]->GetId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (key == mCancelButton)
|
else if (key == mCancelButton)
|
||||||
{
|
{
|
||||||
if (mListener != NULL)
|
if (mListener != NULL)
|
||||||
{
|
{
|
||||||
mListener->ButtonPressed(mId, kCancelMenuID);
|
mListener->ButtonPressed(mId, kCancelMenuID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (JGE_BTN_CANCEL == key)
|
else if (JGE_BTN_CANCEL == key)
|
||||||
{
|
{
|
||||||
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
|
if (mListener != NULL) mListener->ButtonPressed(mId, kInfoMenuID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||||
{
|
{
|
||||||
int n = mCurr;
|
int n = mCurr;
|
||||||
n--;
|
n--;
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||||
n = mCount - 1;
|
n = mCount - 1;
|
||||||
else
|
else
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
|
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
|
||||||
{
|
{
|
||||||
mCurr = n;
|
mCurr = n;
|
||||||
mObjects[mCurr]->Entering();
|
mObjects[mCurr]->Entering();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
||||||
{
|
{
|
||||||
int n = mCurr;
|
int n = mCurr;
|
||||||
n++;
|
n++;
|
||||||
if (n > mCount - 1)
|
if (n > mCount - 1)
|
||||||
{
|
{
|
||||||
if ((mStyle & JGUI_STYLE_WRAPPING))
|
if ((mStyle & JGUI_STYLE_WRAPPING))
|
||||||
n = 0;
|
n = 0;
|
||||||
else
|
else
|
||||||
n = mCount - 1;
|
n = mCount - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||||
{
|
{
|
||||||
mCurr = n;
|
mCurr = n;
|
||||||
mObjects[mCurr]->Entering();
|
mObjects[mCurr]->Entering();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
|
{ // a dude may have clicked somewhere, we're gonna select the closest object from where he clicked
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int distance2;
|
unsigned int distance2;
|
||||||
unsigned int minDistance2 = -1;
|
unsigned int minDistance2 = -1;
|
||||||
int n = mCurr;
|
int n = mCurr;
|
||||||
if (mEngine->GetLeftClickCoordinates(x, y))
|
if (mEngine->GetLeftClickCoordinates(x, y))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
{
|
{
|
||||||
float top, left;
|
float top, left;
|
||||||
if (mObjects[i]->getTopLeft(top, left))
|
if (mObjects[i]->getTopLeft(top, left))
|
||||||
{
|
{
|
||||||
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
distance2 = (top - y) * (top - y) + (left - x) * (left - x);
|
||||||
if (distance2 < minDistance2)
|
if (distance2 < minDistance2)
|
||||||
{
|
{
|
||||||
minDistance2 = distance2;
|
minDistance2 = distance2;
|
||||||
n = i;
|
n = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||||
{
|
{
|
||||||
mCurr = n;
|
mCurr = n;
|
||||||
mObjects[mCurr]->Entering();
|
mObjects[mCurr]->Entering();
|
||||||
}
|
}
|
||||||
mEngine->LeftClickedProcessed();
|
mEngine->LeftClickedProcessed();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Update(float dt)
|
void JGuiController::Update(float dt)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
|
if (mObjects[i] != NULL) mObjects[i]->Update(dt);
|
||||||
|
|
||||||
JButton key = mEngine->ReadButton();
|
JButton key = mEngine->ReadButton();
|
||||||
CheckUserInput(key);
|
CheckUserInput(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Add(JGuiObject* ctrl)
|
void JGuiController::Add(JGuiObject* ctrl)
|
||||||
{
|
{
|
||||||
mObjects.push_back(ctrl);
|
mObjects.push_back(ctrl);
|
||||||
mCount++;
|
mCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::RemoveAt(int i)
|
void JGuiController::RemoveAt(int i)
|
||||||
{
|
{
|
||||||
if (!mObjects[i]) return;
|
if (!mObjects[i]) return;
|
||||||
mObjects.erase(mObjects.begin() + i);
|
mObjects.erase(mObjects.begin() + i);
|
||||||
delete mObjects[i];
|
delete mObjects[i];
|
||||||
mCount--;
|
mCount--;
|
||||||
if (mCurr == mCount) mCurr = 0;
|
if (mCurr == mCount) mCurr = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Remove(int id)
|
void JGuiController::Remove(int id)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
{
|
{
|
||||||
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
|
if (mObjects[i] != NULL && mObjects[i]->GetId() == id)
|
||||||
{
|
{
|
||||||
RemoveAt(i);
|
RemoveAt(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::Remove(JGuiObject* ctrl)
|
void JGuiController::Remove(JGuiObject* ctrl)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < mCount; i++)
|
for (int i = 0; i < mCount; i++)
|
||||||
{
|
{
|
||||||
if (mObjects[i] != NULL && mObjects[i] == ctrl)
|
if (mObjects[i] != NULL && mObjects[i] == ctrl)
|
||||||
{
|
{
|
||||||
RemoveAt(i);
|
RemoveAt(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JGuiController::SetActionButton(JButton button)
|
void JGuiController::SetActionButton(JButton button)
|
||||||
{
|
{
|
||||||
mActionButton = button;
|
mActionButton = button;
|
||||||
}
|
}
|
||||||
void JGuiController::SetStyle(int style)
|
void JGuiController::SetStyle(int style)
|
||||||
{
|
{
|
||||||
mStyle = style;
|
mStyle = style;
|
||||||
}
|
}
|
||||||
void JGuiController::SetCursor(JSprite* cursor)
|
void JGuiController::SetCursor(JSprite* cursor)
|
||||||
{
|
{
|
||||||
mCursor = cursor;
|
mCursor = cursor;
|
||||||
}
|
}
|
||||||
bool JGuiController::IsActive()
|
bool JGuiController::IsActive()
|
||||||
{
|
{
|
||||||
return mActive;
|
return mActive;
|
||||||
}
|
}
|
||||||
void JGuiController::SetActive(bool flag)
|
void JGuiController::SetActive(bool flag)
|
||||||
{
|
{
|
||||||
mActive = 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.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "../include/JTypes.h"
|
#include "../include/JTypes.h"
|
||||||
#include "../include/JFileSystem.h"
|
#include "../include/JFileSystem.h"
|
||||||
#include "../include/JRenderer.h"
|
#include "../include/JRenderer.h"
|
||||||
#include "../include/JOBJModel.h"
|
#include "../include/JOBJModel.h"
|
||||||
|
|
||||||
JOBJModel::JOBJModel()
|
JOBJModel::JOBJModel()
|
||||||
{
|
{
|
||||||
mPolygons = NULL;
|
mPolygons = NULL;
|
||||||
mTexture = NULL;
|
mTexture = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JOBJModel::~JOBJModel()
|
JOBJModel::~JOBJModel()
|
||||||
{
|
{
|
||||||
if (mPolygons)
|
if (mPolygons)
|
||||||
delete [] mPolygons;
|
delete [] mPolygons;
|
||||||
|
|
||||||
if (mTexture)
|
if (mTexture)
|
||||||
delete mTexture;
|
delete mTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JOBJModel::ReadLine(char *output, const char *buffer, int start, int size)
|
int JOBJModel::ReadLine(char *output, const char *buffer, int start, int size)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (start < size && buffer[start] != '\n' && buffer[start] != '\r')
|
while (start < size && buffer[start] != '\n' && buffer[start] != '\r')
|
||||||
output[index++] = buffer[start++];
|
output[index++] = buffer[start++];
|
||||||
|
|
||||||
while ((start < size && buffer[start] == '\n') || buffer[start] == '\r')
|
while ((start < size && buffer[start] == '\n') || buffer[start] == '\r')
|
||||||
start++;
|
start++;
|
||||||
|
|
||||||
output[index] = 0;
|
output[index] = 0;
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JOBJModel::Load(const char *modelName, const char *textureName)
|
bool JOBJModel::Load(const char *modelName, const char *textureName)
|
||||||
{
|
{
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(modelName))
|
if (!fileSys->OpenFile(modelName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int size = fileSys->GetFileSize();
|
int size = fileSys->GetFileSize();
|
||||||
char *buffer = new char[size];
|
char *buffer = new char[size];
|
||||||
|
|
||||||
fileSys->ReadFile(buffer, size);
|
fileSys->ReadFile(buffer, size);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile();
|
||||||
|
|
||||||
Vector3D vert;
|
Vector3D vert;
|
||||||
|
|
||||||
vector<Face> faceList;
|
vector<Face> faceList;
|
||||||
vector<Vector3D> normalList;
|
vector<Vector3D> normalList;
|
||||||
vector<Vector3D> texList;
|
vector<Vector3D> texList;
|
||||||
vector<Vector3D> vertList;
|
vector<Vector3D> vertList;
|
||||||
|
|
||||||
normalList.reserve(32);
|
normalList.reserve(32);
|
||||||
texList.reserve(32);
|
texList.reserve(32);
|
||||||
vertList.reserve(32);
|
vertList.reserve(32);
|
||||||
faceList.reserve(32);
|
faceList.reserve(32);
|
||||||
|
|
||||||
int filePtr = 0;
|
int filePtr = 0;
|
||||||
|
|
||||||
char tmpLine[256];
|
char tmpLine[256];
|
||||||
char s1[256];
|
char s1[256];
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
while (filePtr < size)
|
while (filePtr < size)
|
||||||
{
|
{
|
||||||
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
filePtr = ReadLine(tmpLine, buffer, filePtr, size);
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
if ((tmpLine[0] == '#') || (strlen(tmpLine) < 3))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if (tmpLine[0] == 'v')
|
else if (tmpLine[0] == 'v')
|
||||||
{
|
{
|
||||||
count = sscanf(tmpLine, "%s %f %f %f", s1, &vert.x, &vert.y, &vert.z);
|
count = sscanf(tmpLine, "%s %f %f %f", s1, &vert.x, &vert.y, &vert.z);
|
||||||
|
|
||||||
if (count == 4)
|
if (count == 4)
|
||||||
{
|
{
|
||||||
if (strcmp(s1, "vn") == 0)
|
if (strcmp(s1, "vn") == 0)
|
||||||
normalList.push_back(vert);
|
normalList.push_back(vert);
|
||||||
else if (strcmp(s1, "vt") == 0)
|
else if (strcmp(s1, "vt") == 0)
|
||||||
texList.push_back(vert);
|
texList.push_back(vert);
|
||||||
else if (strcmp(s1, "v") == 0)
|
else if (strcmp(s1, "v") == 0)
|
||||||
vertList.push_back(vert);
|
vertList.push_back(vert);
|
||||||
}
|
}
|
||||||
else if (count == 3)
|
else if (count == 3)
|
||||||
{
|
{
|
||||||
if (strcmp(s1, "vt") == 0)
|
if (strcmp(s1, "vt") == 0)
|
||||||
texList.push_back(vert);
|
texList.push_back(vert);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (tmpLine[0] == 'f')
|
else if (tmpLine[0] == 'f')
|
||||||
{
|
{
|
||||||
Face face;
|
Face face;
|
||||||
face.mVertCount = 0;
|
face.mVertCount = 0;
|
||||||
|
|
||||||
char *p = strchr(tmpLine, ' ');
|
char *p = strchr(tmpLine, ' ');
|
||||||
char *pNext = p;
|
char *pNext = p;
|
||||||
|
|
||||||
int vertIdx, texIdx, norIdx;
|
int vertIdx, texIdx, norIdx;
|
||||||
|
|
||||||
while (p != NULL)
|
while (p != NULL)
|
||||||
{
|
{
|
||||||
while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
|
while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
|
||||||
++p;
|
++p;
|
||||||
strcpy(s1, p);
|
strcpy(s1, p);
|
||||||
count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
|
count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
|
||||||
if (count == 3)
|
if (count == 3)
|
||||||
{
|
{
|
||||||
if (face.mVertCount < 4)
|
if (face.mVertCount < 4)
|
||||||
{
|
{
|
||||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||||
face.mNormalIdx[face.mVertCount] = norIdx - 1;
|
face.mNormalIdx[face.mVertCount] = norIdx - 1;
|
||||||
face.mVertCount++;
|
face.mVertCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (count == 2)
|
else if (count == 2)
|
||||||
{
|
{
|
||||||
if (face.mVertCount < 4)
|
if (face.mVertCount < 4)
|
||||||
{
|
{
|
||||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||||
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
face.mTexIdx[face.mVertCount] = texIdx - 1;
|
||||||
face.mNormalIdx[face.mVertCount] = 0;
|
face.mNormalIdx[face.mVertCount] = 0;
|
||||||
face.mVertCount++;
|
face.mVertCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (count == 1)
|
else if (count == 1)
|
||||||
{
|
{
|
||||||
if (face.mVertCount < 4)
|
if (face.mVertCount < 4)
|
||||||
{
|
{
|
||||||
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
face.mVertIdx[face.mVertCount] = vertIdx - 1;
|
||||||
face.mTexIdx[face.mVertCount] = 0;
|
face.mTexIdx[face.mVertCount] = 0;
|
||||||
face.mNormalIdx[face.mVertCount] = 0;
|
face.mNormalIdx[face.mVertCount] = 0;
|
||||||
face.mVertCount++;
|
face.mVertCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pNext = strchr(p, ' ');
|
pNext = strchr(p, ' ');
|
||||||
p = pNext;
|
p = pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (face.mVertCount == 3) // we do triangles only ;)
|
if (face.mVertCount == 3) // we do triangles only ;)
|
||||||
faceList.push_back(face);
|
faceList.push_back(face);
|
||||||
}
|
}
|
||||||
else if (tmpLine[0] == 'g')
|
else if (tmpLine[0] == 'g')
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (tmpLine[0] == 'u')
|
else if (tmpLine[0] == 'u')
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mPolycount = faceList.size();
|
mPolycount = faceList.size();
|
||||||
mPolygons = new Vertex3D[mPolycount*3];
|
mPolygons = new Vertex3D[mPolycount*3];
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (int i=0;i<mPolycount;i++)
|
for (int i=0;i<mPolycount;i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int j=0;j<3;j++)
|
for (int j=0;j<3;j++)
|
||||||
{
|
{
|
||||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
|
mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
|
||||||
mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
|
mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
|
||||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
|
mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
|
||||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
|
mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
|
||||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
|
mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
|
mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
|
||||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
|
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
|
||||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
|
mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
|
||||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
|
mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
|
||||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
|
mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
|
||||||
idx++;
|
idx++;
|
||||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
|
mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
|
||||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
|
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
|
||||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
|
mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
|
||||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
|
mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
|
||||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
|
mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
|
||||||
idx++;
|
idx++;
|
||||||
mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
|
mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
|
||||||
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
|
mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
|
||||||
mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
|
mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
|
||||||
mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
|
mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
|
||||||
mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
|
mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
|
||||||
idx++;
|
idx++;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (textureName != NULL)
|
if (textureName != NULL)
|
||||||
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
mTexture = JRenderer::GetInstance()->LoadTexture(textureName);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JOBJModel::Render()
|
void JOBJModel::Render()
|
||||||
{
|
{
|
||||||
JRenderer::GetInstance()->RenderTriangles(mTexture, mPolygons, 0, mPolycount);
|
JRenderer::GetInstance()->RenderTriangles(mTexture, mPolygons, 0, mPolycount);
|
||||||
}
|
}
|
||||||
|
|||||||
+246
-246
@@ -1,246 +1,246 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
//#include "JApp.h"
|
//#include "JApp.h"
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
|
|
||||||
#include "../include/JParticle.h"
|
#include "../include/JParticle.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JParticleData::JParticleData()
|
JParticleData::JParticleData()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleData::Clear()
|
void JParticleData::Clear()
|
||||||
{
|
{
|
||||||
mCurr = 0.0f;
|
mCurr = 0.0f;
|
||||||
mTarget = 0.0f;
|
mTarget = 0.0f;
|
||||||
mDelta = 0.0f;
|
mDelta = 0.0f;
|
||||||
mKeyCount = 0;
|
mKeyCount = 0;
|
||||||
mKeyIndex = 0;
|
mKeyIndex = 0;
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
mScale = 1.0f;
|
mScale = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleData::Init()
|
void JParticleData::Init()
|
||||||
{
|
{
|
||||||
mKeyIndex = 0;
|
mKeyIndex = 0;
|
||||||
mDelta = 0.0f;
|
mDelta = 0.0f;
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
if (mKeyCount > 0)
|
if (mKeyCount > 0)
|
||||||
{
|
{
|
||||||
mCurr = mKeyValue[mKeyIndex++];
|
mCurr = mKeyValue[mKeyIndex++];
|
||||||
|
|
||||||
if (mKeyIndex < mKeyCount)
|
if (mKeyIndex < mKeyCount)
|
||||||
{
|
{
|
||||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||||
mTarget = mKeyValue[mKeyIndex];
|
mTarget = mKeyValue[mKeyIndex];
|
||||||
mDelta = (mTarget-mCurr)/mTimer;
|
mDelta = (mTarget-mCurr)/mTimer;
|
||||||
mKeyIndex++;
|
mKeyIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleData::AddKey(float keyTime, float keyValue)
|
void JParticleData::AddKey(float keyTime, float keyValue)
|
||||||
{
|
{
|
||||||
if (mKeyCount < MAX_KEYS)
|
if (mKeyCount < MAX_KEYS)
|
||||||
{
|
{
|
||||||
mKeyTime[mKeyCount] = keyTime;
|
mKeyTime[mKeyCount] = keyTime;
|
||||||
mKeyValue[mKeyCount] = keyValue;
|
mKeyValue[mKeyCount] = keyValue;
|
||||||
mKeyCount++;
|
mKeyCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleData::Update(float dt)
|
void JParticleData::Update(float dt)
|
||||||
{
|
{
|
||||||
mCurr += mDelta*dt;
|
mCurr += mDelta*dt;
|
||||||
if (mDelta < 0.0f)
|
if (mDelta < 0.0f)
|
||||||
{
|
{
|
||||||
if (mCurr < mTarget)
|
if (mCurr < mTarget)
|
||||||
mCurr = mTarget;
|
mCurr = mTarget;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (mDelta > 0.0f)
|
else if (mDelta > 0.0f)
|
||||||
{
|
{
|
||||||
if (mCurr > mTarget)
|
if (mCurr > mTarget)
|
||||||
mCurr = mTarget;
|
mCurr = mTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTimer -= dt;
|
mTimer -= dt;
|
||||||
|
|
||||||
if (mTimer <= 0.0f)
|
if (mTimer <= 0.0f)
|
||||||
{
|
{
|
||||||
if (mKeyIndex < mKeyCount)
|
if (mKeyIndex < mKeyCount)
|
||||||
{
|
{
|
||||||
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
mTimer = mKeyTime[mKeyIndex]*mScale-mKeyTime[mKeyIndex-1]*mScale;
|
||||||
mTarget = mKeyValue[mKeyIndex];
|
mTarget = mKeyValue[mKeyIndex];
|
||||||
mDelta = (mTarget-mCurr)/mTimer;
|
mDelta = (mTarget-mCurr)/mTimer;
|
||||||
mKeyIndex++;
|
mKeyIndex++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mDelta = 0.0f;
|
mDelta = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleData::SetScale(float scale)
|
void JParticleData::SetScale(float scale)
|
||||||
{
|
{
|
||||||
mScale = scale;
|
mScale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JRenderer* JParticle::mRenderer = NULL;
|
JRenderer* JParticle::mRenderer = NULL;
|
||||||
|
|
||||||
JParticleData* JParticle::GetField(int index)
|
JParticleData* JParticle::GetField(int index)
|
||||||
{
|
{
|
||||||
if (index < FIELD_COUNT)
|
if (index < FIELD_COUNT)
|
||||||
return &mData[index];
|
return &mData[index];
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JParticleData* JParticle::GetDataPtr()
|
JParticleData* JParticle::GetDataPtr()
|
||||||
{
|
{
|
||||||
return mData;
|
return mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
JParticle::JParticle()//JQuad* texture, float x, float y)
|
JParticle::JParticle()//JQuad* texture, float x, float y)
|
||||||
{
|
{
|
||||||
mRenderer = JRenderer::GetInstance();
|
mRenderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
//mTexture = texture;
|
//mTexture = texture;
|
||||||
mOrigin = Vector2D(0.0f, 0.0f);
|
mOrigin = Vector2D(0.0f, 0.0f);
|
||||||
mPos = Vector2D(0.0f, 0.0f);
|
mPos = Vector2D(0.0f, 0.0f);
|
||||||
mVelocity = Vector2D(0.0f, 0.0f);
|
mVelocity = Vector2D(0.0f, 0.0f);
|
||||||
|
|
||||||
mActive = false;
|
mActive = false;
|
||||||
mQuad = NULL;
|
mQuad = NULL;
|
||||||
|
|
||||||
// mNext = NULL;
|
// mNext = NULL;
|
||||||
// mPrev = NULL;
|
// mPrev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JParticle::~JParticle()
|
JParticle::~JParticle()
|
||||||
{
|
{
|
||||||
//JGERelease();
|
//JGERelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JParticle::Update(float dt)
|
bool JParticle::Update(float dt)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i=0;i<FIELD_COUNT;i++)
|
for (int i=0;i<FIELD_COUNT;i++)
|
||||||
mData[i].Update(dt);
|
mData[i].Update(dt);
|
||||||
|
|
||||||
|
|
||||||
// the radial and tangential acceleration code was taken from HGE's particle source
|
// the radial and tangential acceleration code was taken from HGE's particle source
|
||||||
Vector2D vecAccel = mPos - mOrigin; //par->vecLocation-vecLocation;
|
Vector2D vecAccel = mPos - mOrigin; //par->vecLocation-vecLocation;
|
||||||
vecAccel.Normalize();
|
vecAccel.Normalize();
|
||||||
Vector2D vecAccel2 = vecAccel;
|
Vector2D vecAccel2 = vecAccel;
|
||||||
vecAccel *= mData[FIELD_RADIAL_ACCEL].mCurr; //par->fRadialAccel;
|
vecAccel *= mData[FIELD_RADIAL_ACCEL].mCurr; //par->fRadialAccel;
|
||||||
|
|
||||||
// vecAccel2.Rotate(M_PI_2);
|
// vecAccel2.Rotate(M_PI_2);
|
||||||
// the following is faster
|
// the following is faster
|
||||||
float ang = vecAccel2.x;
|
float ang = vecAccel2.x;
|
||||||
vecAccel2.x = -vecAccel2.y;
|
vecAccel2.x = -vecAccel2.y;
|
||||||
vecAccel2.y = ang;
|
vecAccel2.y = ang;
|
||||||
|
|
||||||
vecAccel2 *= mData[FIELD_TANGENTIAL_ACCEL].mCurr; //par->fTangentialAccel;
|
vecAccel2 *= mData[FIELD_TANGENTIAL_ACCEL].mCurr; //par->fTangentialAccel;
|
||||||
mVelocity += (vecAccel+vecAccel2)*dt; //par->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
mVelocity += (vecAccel+vecAccel2)*dt; //par->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||||
mVelocity.y += mData[FIELD_GRAVITY].mCurr*dt; //par->vecVelocity.y += par->fGravity*fDeltaTime;
|
mVelocity.y += mData[FIELD_GRAVITY].mCurr*dt; //par->vecVelocity.y += par->fGravity*fDeltaTime;
|
||||||
|
|
||||||
//par->vecLocation += par->vecVelocity*fDeltaTime;
|
//par->vecLocation += par->vecVelocity*fDeltaTime;
|
||||||
|
|
||||||
////mPos.x += mData[FIELD_SPEED].mCurr * mVelocity.x * dt;
|
////mPos.x += mData[FIELD_SPEED].mCurr * mVelocity.x * dt;
|
||||||
////mPos.y += mData[FIELD_SPEED].mCurr * mVelocity.y * dt;
|
////mPos.y += mData[FIELD_SPEED].mCurr * mVelocity.y * dt;
|
||||||
mPos += mVelocity*mData[FIELD_SPEED].mCurr*dt;
|
mPos += mVelocity*mData[FIELD_SPEED].mCurr*dt;
|
||||||
|
|
||||||
|
|
||||||
mLifetime -= dt;
|
mLifetime -= dt;
|
||||||
if (mLifetime <= 0.0f)
|
if (mLifetime <= 0.0f)
|
||||||
{
|
{
|
||||||
mActive = false;
|
mActive = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticle::Render()
|
void JParticle::Render()
|
||||||
{
|
{
|
||||||
if (mQuad)
|
if (mQuad)
|
||||||
{
|
{
|
||||||
int a = (int)(mData[FIELD_ALPHA].mCurr*255.0f);
|
int a = (int)(mData[FIELD_ALPHA].mCurr*255.0f);
|
||||||
int r = (int)(mData[FIELD_RED].mCurr*255.0f);
|
int r = (int)(mData[FIELD_RED].mCurr*255.0f);
|
||||||
int g = (int)(mData[FIELD_GREEN].mCurr*255.0f);
|
int g = (int)(mData[FIELD_GREEN].mCurr*255.0f);
|
||||||
int b = (int)(mData[FIELD_BLUE].mCurr*255.0f);
|
int b = (int)(mData[FIELD_BLUE].mCurr*255.0f);
|
||||||
PIXEL_TYPE color = ARGB(a, r, g, b);
|
PIXEL_TYPE color = ARGB(a, r, g, b);
|
||||||
mQuad->SetColor(color);
|
mQuad->SetColor(color);
|
||||||
|
|
||||||
mRenderer->RenderQuad(mQuad, mPos.x, mPos.y, mData[FIELD_ROTATION].mCurr, mData[FIELD_SIZE].mCurr*mSize, mData[FIELD_SIZE].mCurr*mSize);
|
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)
|
void JParticle::Init(float lifeTime)
|
||||||
{
|
{
|
||||||
mLifetime = lifeTime;
|
mLifetime = lifeTime;
|
||||||
|
|
||||||
for (int i=0;i<FIELD_COUNT;i++)
|
for (int i=0;i<FIELD_COUNT;i++)
|
||||||
{
|
{
|
||||||
mData[i].SetScale(lifeTime);
|
mData[i].SetScale(lifeTime);
|
||||||
mData[i].Init();
|
mData[i].Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
mActive = true;
|
mActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticle::InitPosition(float ox, float oy, float xoffset, float yoffset)
|
void JParticle::InitPosition(float ox, float oy, float xoffset, float yoffset)
|
||||||
{
|
{
|
||||||
mOrigin = Vector2D(ox, oy);
|
mOrigin = Vector2D(ox, oy);
|
||||||
mPos = Vector2D(ox+xoffset, oy+yoffset);
|
mPos = Vector2D(ox+xoffset, oy+yoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticle::SetPosition(float x, float y)
|
void JParticle::SetPosition(float x, float y)
|
||||||
{
|
{
|
||||||
mPos = Vector2D(x, y);
|
mPos = Vector2D(x, y);
|
||||||
mOrigin = Vector2D(x, y);
|
mOrigin = Vector2D(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticle::SetQuad(JQuad *quad) { mQuad = quad; }
|
void JParticle::SetQuad(JQuad *quad) { mQuad = quad; }
|
||||||
|
|
||||||
void JParticle::Move(float x, float y)
|
void JParticle::Move(float x, float y)
|
||||||
{
|
{
|
||||||
mPos.x += x;
|
mPos.x += x;
|
||||||
mPos.y += y;
|
mPos.y += y;
|
||||||
|
|
||||||
mOrigin.x += x;
|
mOrigin.x += x;
|
||||||
mOrigin.y += y;
|
mOrigin.y += y;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void JParticle::ResetVelocity()
|
//void JParticle::ResetVelocity()
|
||||||
//{
|
//{
|
||||||
// float xx = mSpeed * cosf(mAngle);
|
// float xx = mSpeed * cosf(mAngle);
|
||||||
// float yy = mSpeed * sinf(mAngle);
|
// float yy = mSpeed * sinf(mAngle);
|
||||||
// mVelocity = Vector2D(xx, yy);
|
// mVelocity = Vector2D(xx, yy);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void JParticle::SetVelocity(float x, float y) { mVelocity = Vector2D(x, y); }
|
void JParticle::SetVelocity(float x, float y) { mVelocity = Vector2D(x, y); }
|
||||||
void JParticle::SetSize(float size) { mSize = size;}
|
void JParticle::SetSize(float size) { mSize = size;}
|
||||||
|
|
||||||
|
|||||||
+389
-389
@@ -1,389 +1,389 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JParticleSystem.h"
|
#include "../include/JParticleSystem.h"
|
||||||
#include "../include/JParticleEffect.h"
|
#include "../include/JParticleEffect.h"
|
||||||
#include "../include/JParticleEmitter.h"
|
#include "../include/JParticleEmitter.h"
|
||||||
|
|
||||||
#include "../include/JFileSystem.h"
|
#include "../include/JFileSystem.h"
|
||||||
#include "../include/JResourceManager.h"
|
#include "../include/JResourceManager.h"
|
||||||
|
|
||||||
#include "tinyxml/tinyxml.h"
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
JParticleEffect::JParticleEffect(JResourceManager* mgr)
|
JParticleEffect::JParticleEffect(JResourceManager* mgr)
|
||||||
{
|
{
|
||||||
mResourceManager = mgr;
|
mResourceManager = mgr;
|
||||||
|
|
||||||
mX = 0.0f;
|
mX = 0.0f;
|
||||||
mY = 0.0f;
|
mY = 0.0f;
|
||||||
|
|
||||||
mEmitterCount = 0;
|
mEmitterCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JParticleEffect::~JParticleEffect()
|
JParticleEffect::~JParticleEffect()
|
||||||
{
|
{
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
if (mParticleEmitters[i])
|
if (mParticleEmitters[i])
|
||||||
delete (mParticleEmitters[i]);
|
delete (mParticleEmitters[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool JParticleEffect::Load(const char* filename)
|
bool JParticleEffect::Load(const char* filename)
|
||||||
{
|
{
|
||||||
mX = 0.0f;
|
mX = 0.0f;
|
||||||
mY = 0.0f;
|
mY = 0.0f;
|
||||||
|
|
||||||
mEmitterCount = 0;
|
mEmitterCount = 0;
|
||||||
|
|
||||||
|
|
||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
|
|
||||||
if (!fileSystem->OpenFile(filename)) return false;
|
if (!fileSystem->OpenFile(filename)) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize();
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
|
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
|
|
||||||
|
|
||||||
TiXmlNode* effect = 0;
|
TiXmlNode* effect = 0;
|
||||||
TiXmlNode* emitter = 0;
|
TiXmlNode* emitter = 0;
|
||||||
TiXmlNode* param = 0;
|
TiXmlNode* param = 0;
|
||||||
TiXmlNode* key = 0;
|
TiXmlNode* key = 0;
|
||||||
|
|
||||||
TiXmlElement* element = 0;
|
TiXmlElement* element = 0;
|
||||||
|
|
||||||
float keyTime;
|
float keyTime;
|
||||||
float value;
|
float value;
|
||||||
float baseValue;
|
float baseValue;
|
||||||
int int_value;
|
int int_value;
|
||||||
//
|
//
|
||||||
// enum ParticleField
|
// enum ParticleField
|
||||||
// {
|
// {
|
||||||
// FIELD_SPEED,
|
// FIELD_SPEED,
|
||||||
// FIELD_SIZE,
|
// FIELD_SIZE,
|
||||||
// FIELD_ROTATION,
|
// FIELD_ROTATION,
|
||||||
// FIELD_ALPHA,
|
// FIELD_ALPHA,
|
||||||
// FIELD_RED,
|
// FIELD_RED,
|
||||||
// FIELD_GREEN,
|
// FIELD_GREEN,
|
||||||
// FIELD_BLUE,
|
// FIELD_BLUE,
|
||||||
// FIELD_COUNT
|
// FIELD_COUNT
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const char* lifeValues[] =
|
const char* lifeValues[] =
|
||||||
{
|
{
|
||||||
"speed",
|
"speed",
|
||||||
"size",
|
"size",
|
||||||
"rotation",
|
"rotation",
|
||||||
"alpha",
|
"alpha",
|
||||||
"red",
|
"red",
|
||||||
"green",
|
"green",
|
||||||
"blue",
|
"blue",
|
||||||
"radial_accel",
|
"radial_accel",
|
||||||
"tangential_accel",
|
"tangential_accel",
|
||||||
"gravity"
|
"gravity"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* typeNames[] =
|
const char* typeNames[] =
|
||||||
{
|
{
|
||||||
"POINT",
|
"POINT",
|
||||||
"AREA",
|
"AREA",
|
||||||
"HORIZONTAL",
|
"HORIZONTAL",
|
||||||
"VERTICAL",
|
"VERTICAL",
|
||||||
"CIRCLE"
|
"CIRCLE"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* modeNames[] =
|
const char* modeNames[] =
|
||||||
{
|
{
|
||||||
"REPEAT",
|
"REPEAT",
|
||||||
"ONCE",
|
"ONCE",
|
||||||
"NTIMES",
|
"NTIMES",
|
||||||
"CONTINUOUS"
|
"CONTINUOUS"
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// One effect per file only, well, we may extend it later to permit
|
// One effect per file only, well, we may extend it later to permit
|
||||||
// multiple effect definitions:
|
// multiple effect definitions:
|
||||||
//
|
//
|
||||||
// for (effect = doc.FirstChild("effect"); effect; effect = effect->NextSibling())
|
// for (effect = doc.FirstChild("effect"); effect; effect = effect->NextSibling())
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
effect = doc.FirstChild("effect");
|
effect = doc.FirstChild("effect");
|
||||||
if (effect)
|
if (effect)
|
||||||
{
|
{
|
||||||
element = effect->ToElement();
|
element = effect->ToElement();
|
||||||
printf("%s:%s\n", element->Value(), element->Attribute("name"));
|
printf("%s:%s\n", element->Value(), element->Attribute("name"));
|
||||||
|
|
||||||
|
|
||||||
for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
|
for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
|
||||||
{
|
{
|
||||||
|
|
||||||
mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
|
mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
|
||||||
element = emitter->ToElement();
|
element = emitter->ToElement();
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
|
if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
|
||||||
mParticleEmitters[mEmitterCount]->mLife = value;
|
mParticleEmitters[mEmitterCount]->mLife = value;
|
||||||
|
|
||||||
for (param = emitter->FirstChild(); param; param = param->NextSibling())
|
for (param = emitter->FirstChild(); param; param = param->NextSibling())
|
||||||
{
|
{
|
||||||
element = param->ToElement();
|
element = param->ToElement();
|
||||||
|
|
||||||
if (strcmp(element->Attribute("name"), "settings")==0)
|
if (strcmp(element->Attribute("name"), "settings")==0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (strcmp(element->Attribute("blend"), "NORMAL")==0)
|
if (strcmp(element->Attribute("blend"), "NORMAL")==0)
|
||||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||||
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
|
else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
|
||||||
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
|
||||||
|
|
||||||
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
for (unsigned int i=0;i<sizeof(modeNames)/sizeof(char*);i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("mode"), modeNames[i])==0)
|
if (strcmp(element->Attribute("mode"), modeNames[i])==0)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
mParticleEmitters[mEmitterCount]->mEmitterMode = i;
|
||||||
#if defined (_DEBUG)
|
#if defined (_DEBUG)
|
||||||
printf("emitter mode:%s\n", modeNames[i]);
|
printf("emitter mode:%s\n", modeNames[i]);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
for (unsigned i=0;i<sizeof(typeNames)/sizeof(char*);i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("type"), typeNames[i])==0)
|
if (strcmp(element->Attribute("type"), typeNames[i])==0)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mType = i;
|
mParticleEmitters[mEmitterCount]->mType = i;
|
||||||
#if defined (_DEBUG)
|
#if defined (_DEBUG)
|
||||||
printf("emitter type:%s\n", typeNames[i]);
|
printf("emitter type:%s\n", typeNames[i]);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string quadName = element->Attribute("image");
|
string quadName = element->Attribute("image");
|
||||||
JQuad* quad = mResourceManager->GetQuad(quadName);
|
JQuad* quad = mResourceManager->GetQuad(quadName);
|
||||||
if (quad != NULL)
|
if (quad != NULL)
|
||||||
mParticleEmitters[mEmitterCount]->SetQuad(quad);
|
mParticleEmitters[mEmitterCount]->SetQuad(quad);
|
||||||
|
|
||||||
// if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
|
// if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
|
||||||
// {
|
// {
|
||||||
// mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
|
// mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
|
if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mWidth = int_value;
|
mParticleEmitters[mEmitterCount]->mWidth = int_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
|
if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mHeight = int_value;
|
mParticleEmitters[mEmitterCount]->mHeight = int_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
|
if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mId = int_value;
|
mParticleEmitters[mEmitterCount]->mId = int_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
|
if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;
|
mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "quantity")==0)
|
else if (strcmp(element->Attribute("name"), "quantity")==0)
|
||||||
{
|
{
|
||||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||||
{
|
{
|
||||||
element = key->ToElement();
|
element = key->ToElement();
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
|
mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "lifex")==0)
|
else if (strcmp(element->Attribute("name"), "lifex")==0)
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
|
mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
|
||||||
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
mParticleEmitters[mEmitterCount]->mLifeMax= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "anglex")==0)
|
else if (strcmp(element->Attribute("name"), "anglex")==0)
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
|
mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
|
||||||
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "speedx")==0)
|
else if (strcmp(element->Attribute("name"), "speedx")==0)
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
|
mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
|
||||||
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
mParticleEmitters[mEmitterCount]->mSpeedMax= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(element->Attribute("name"), "sizex")==0)
|
else if (strcmp(element->Attribute("name"), "sizex")==0)
|
||||||
{
|
{
|
||||||
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
|
mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
|
||||||
mParticleEmitters[mEmitterCount]->mSizeMax= value;
|
mParticleEmitters[mEmitterCount]->mSizeMax= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i=0;i<FIELD_COUNT;i++)
|
for (int i=0;i<FIELD_COUNT;i++)
|
||||||
{
|
{
|
||||||
if (strcmp(element->Attribute("name"), lifeValues[i])==0)
|
if (strcmp(element->Attribute("name"), lifeValues[i])==0)
|
||||||
{
|
{
|
||||||
for (key = param->FirstChild(); key; key = key->NextSibling())
|
for (key = param->FirstChild(); key; key = key->NextSibling())
|
||||||
{
|
{
|
||||||
element = key->ToElement();
|
element = key->ToElement();
|
||||||
|
|
||||||
if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
|
if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
|
||||||
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
|
||||||
{
|
{
|
||||||
if (i==FIELD_ROTATION)
|
if (i==FIELD_ROTATION)
|
||||||
value *= DEG2RAD;
|
value *= DEG2RAD;
|
||||||
|
|
||||||
mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
|
mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mEmitterCount++;
|
mEmitterCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile();
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::SetParticleSystem(JParticleSystem* particleSys)
|
void JParticleEffect::SetParticleSystem(JParticleSystem* particleSys)
|
||||||
{
|
{
|
||||||
mParticleSystem = particleSys;
|
mParticleSystem = particleSys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::SetPosition(float x, float y)
|
void JParticleEffect::SetPosition(float x, float y)
|
||||||
{
|
{
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JParticleSystem* JParticleEffect::GetParticleSystem()
|
JParticleSystem* JParticleEffect::GetParticleSystem()
|
||||||
{
|
{
|
||||||
return mParticleSystem;
|
return mParticleSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float JParticleEffect::GetX()
|
float JParticleEffect::GetX()
|
||||||
{
|
{
|
||||||
return mX;
|
return mX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float JParticleEffect::GetY()
|
float JParticleEffect::GetY()
|
||||||
{
|
{
|
||||||
return mY;
|
return mY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::Update(float dt)
|
void JParticleEffect::Update(float dt)
|
||||||
{
|
{
|
||||||
// mTimer += dt;
|
// mTimer += dt;
|
||||||
|
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
mParticleEmitters[i]->Update(dt);
|
mParticleEmitters[i]->Update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleEffect::Render()
|
void JParticleEffect::Render()
|
||||||
{
|
{
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
mParticleEmitters[i]->Render();
|
mParticleEmitters[i]->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JParticleEffect::Done()
|
bool JParticleEffect::Done()
|
||||||
{
|
{
|
||||||
bool done = true;
|
bool done = true;
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
if (!mParticleEmitters[i]->Done())
|
if (!mParticleEmitters[i]->Done())
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
return (done);
|
return (done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::Start()
|
void JParticleEffect::Start()
|
||||||
{
|
{
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
mParticleEmitters[i]->Start();
|
mParticleEmitters[i]->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::Stop()
|
void JParticleEffect::Stop()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
mParticleEmitters[i]->SetActive(false);
|
mParticleEmitters[i]->SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEffect::MoveTo(float x, float y)
|
void JParticleEffect::MoveTo(float x, float y)
|
||||||
{
|
{
|
||||||
float dx = x - mX;
|
float dx = x - mX;
|
||||||
float dy = y - mY;
|
float dy = y - mY;
|
||||||
|
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
|
|
||||||
for (int i=0;i<mEmitterCount;i++)
|
for (int i=0;i<mEmitterCount;i++)
|
||||||
{
|
{
|
||||||
mParticleEmitters[i]->MoveAllParticles(dx, dy);
|
mParticleEmitters[i]->MoveAllParticles(dx, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+323
-323
@@ -1,323 +1,323 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JParticleSystem.h"
|
#include "../include/JParticleSystem.h"
|
||||||
#include "../include/JParticleEffect.h"
|
#include "../include/JParticleEffect.h"
|
||||||
#include "../include/JParticleEmitter.h"
|
#include "../include/JParticleEmitter.h"
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
JParticleEmitter::JParticleEmitter(JParticleEffect* parent)
|
JParticleEmitter::JParticleEmitter(JParticleEffect* parent)
|
||||||
{
|
{
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
mType = TYPE_POINT;
|
mType = TYPE_POINT;
|
||||||
mSrcBlending = BLEND_SRC_ALPHA;
|
mSrcBlending = BLEND_SRC_ALPHA;
|
||||||
mDestBlending = BLEND_ONE;
|
mDestBlending = BLEND_ONE;
|
||||||
|
|
||||||
mQuad = NULL;
|
mQuad = NULL;
|
||||||
|
|
||||||
mQuadIndex = 0;
|
mQuadIndex = 0;
|
||||||
mWidth = 8;
|
mWidth = 8;
|
||||||
mHeight = 8;
|
mHeight = 8;
|
||||||
|
|
||||||
mEmitTimer = 0.0f;
|
mEmitTimer = 0.0f;
|
||||||
mActive = false;
|
mActive = false;
|
||||||
|
|
||||||
mMaxParticleCount = MAX_PARTICLE_COUNT;
|
mMaxParticleCount = MAX_PARTICLE_COUNT;
|
||||||
|
|
||||||
mParticles.clear();
|
mParticles.clear();
|
||||||
mParticles.reserve(INIT_PARTICLE_COUNT);
|
mParticles.reserve(INIT_PARTICLE_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
JParticleEmitter::~JParticleEmitter()
|
JParticleEmitter::~JParticleEmitter()
|
||||||
{
|
{
|
||||||
|
|
||||||
while (mParticles.size()>0)
|
while (mParticles.size()>0)
|
||||||
{
|
{
|
||||||
JParticle* par = mParticles.back();
|
JParticle* par = mParticles.back();
|
||||||
mParticles.pop_back();
|
mParticles.pop_back();
|
||||||
delete par;
|
delete par;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JParticle* JParticleEmitter::GetIdleParticle()
|
JParticle* JParticleEmitter::GetIdleParticle()
|
||||||
{
|
{
|
||||||
int size = mParticles.size();
|
int size = mParticles.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
{
|
{
|
||||||
if (!mParticles[i]->mActive)
|
if (!mParticles[i]->mActive)
|
||||||
return mParticles[i];
|
return mParticles[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < mMaxParticleCount)
|
if (size < mMaxParticleCount)
|
||||||
{
|
{
|
||||||
|
|
||||||
JParticle*par = new JParticle();
|
JParticle*par = new JParticle();
|
||||||
if (par != NULL)
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
mParticles.push_back(par);
|
mParticles.push_back(par);
|
||||||
return par;
|
return par;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleEmitter::Start()
|
void JParticleEmitter::Start()
|
||||||
{
|
{
|
||||||
mActive = true;
|
mActive = true;
|
||||||
mActiveParticleCount = 0;
|
mActiveParticleCount = 0;
|
||||||
mRepeatCounter = mRepeatTimes;
|
mRepeatCounter = mRepeatTimes;
|
||||||
|
|
||||||
ReStart();
|
ReStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::ReStart()
|
void JParticleEmitter::ReStart()
|
||||||
{
|
{
|
||||||
mQuantity.Init();
|
mQuantity.Init();
|
||||||
mEmitTimer = 0.0f;
|
mEmitTimer = 0.0f;
|
||||||
|
|
||||||
// if (mQuad == NULL)
|
// if (mQuad == NULL)
|
||||||
// {
|
// {
|
||||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||||
// mQuad = particleSys->GetParticleQuad(mQuadIndex);
|
// mQuad = particleSys->GetParticleQuad(mQuadIndex);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
int count = (int) mQuantity.mCurr;
|
int count = (int) mQuantity.mCurr;
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
EmitParticles(count);
|
EmitParticles(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::SetQuad(JQuad *quad)
|
void JParticleEmitter::SetQuad(JQuad *quad)
|
||||||
{
|
{
|
||||||
mQuad = quad;
|
mQuad = quad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::Update(float dt)
|
void JParticleEmitter::Update(float dt)
|
||||||
{
|
{
|
||||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||||
|
|
||||||
mActiveParticleCount = 0;
|
mActiveParticleCount = 0;
|
||||||
|
|
||||||
if (!mParticles.empty())
|
if (!mParticles.empty())
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int size = mParticles.size();
|
int size = mParticles.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
{
|
{
|
||||||
if (mParticles[i]->mActive)
|
if (mParticles[i]->mActive)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
mParticles[i]->Update(dt);
|
mParticles[i]->Update(dt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mActiveParticleCount = count;
|
mActiveParticleCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mActive) return; // don't generate more
|
if (!mActive) return; // don't generate more
|
||||||
|
|
||||||
mEmitTimer += dt;
|
mEmitTimer += dt;
|
||||||
if (mEmitTimer > mLife)
|
if (mEmitTimer > mLife)
|
||||||
{
|
{
|
||||||
mEmitTimer = 0.0f;
|
mEmitTimer = 0.0f;
|
||||||
|
|
||||||
if (mEmitterMode == MODE_ONCE)
|
if (mEmitterMode == MODE_ONCE)
|
||||||
{
|
{
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
else if (mEmitterMode == MODE_REPEAT)
|
else if (mEmitterMode == MODE_REPEAT)
|
||||||
{
|
{
|
||||||
ReStart();
|
ReStart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (mEmitterMode == MODE_NTIMES)
|
else if (mEmitterMode == MODE_NTIMES)
|
||||||
{
|
{
|
||||||
mRepeatCounter--;
|
mRepeatCounter--;
|
||||||
if (mRepeatCounter > 0)
|
if (mRepeatCounter > 0)
|
||||||
{
|
{
|
||||||
ReStart();
|
ReStart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mActive) return; // don't generate more
|
if (!mActive) return; // don't generate more
|
||||||
|
|
||||||
// more particles...
|
// more particles...
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (mQuantity.mCurr != 0.0f)
|
if (mQuantity.mCurr != 0.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
float timeForOneParticle = 1.0f/mQuantity.mCurr;
|
float timeForOneParticle = 1.0f/mQuantity.mCurr;
|
||||||
|
|
||||||
float potentialParticles = (float) ((int)(mEmitTimer/timeForOneParticle));
|
float potentialParticles = (float) ((int)(mEmitTimer/timeForOneParticle));
|
||||||
if (potentialParticles >= 1.0f)
|
if (potentialParticles >= 1.0f)
|
||||||
mEmitTimer -= (potentialParticles*timeForOneParticle);
|
mEmitTimer -= (potentialParticles*timeForOneParticle);
|
||||||
|
|
||||||
count = (int)potentialParticles;
|
count = (int)potentialParticles;
|
||||||
}
|
}
|
||||||
|
|
||||||
//int count = (int)(mQuantity.mCurr * dt); // number of particles for this dt
|
//int count = (int)(mQuantity.mCurr * dt); // number of particles for this dt
|
||||||
|
|
||||||
mQuantity.Update(dt);
|
mQuantity.Update(dt);
|
||||||
|
|
||||||
EmitParticles(count);
|
EmitParticles(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::EmitParticles(int count)
|
void JParticleEmitter::EmitParticles(int count)
|
||||||
{
|
{
|
||||||
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
// JParticleSystem* particleSys = mParent->GetParticleSystem();
|
||||||
|
|
||||||
JParticleData *dataPtr;
|
JParticleData *dataPtr;
|
||||||
JParticle* particle;
|
JParticle* particle;
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
float xOrigin = mParent->GetX();
|
float xOrigin = mParent->GetX();
|
||||||
float yOrigin = mParent->GetY();
|
float yOrigin = mParent->GetY();
|
||||||
|
|
||||||
for (int i=0;i<count;i++)
|
for (int i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
particle = GetIdleParticle();
|
particle = GetIdleParticle();
|
||||||
if (particle != NULL)
|
if (particle != NULL)
|
||||||
{
|
{
|
||||||
particle->SetQuad(mQuad);
|
particle->SetQuad(mQuad);
|
||||||
|
|
||||||
dataPtr = particle->GetDataPtr();
|
dataPtr = particle->GetDataPtr();
|
||||||
memcpy(dataPtr, mData, sizeof(JParticleData)*FIELD_COUNT);
|
memcpy(dataPtr, mData, sizeof(JParticleData)*FIELD_COUNT);
|
||||||
|
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
|
|
||||||
switch (mType)
|
switch (mType)
|
||||||
{
|
{
|
||||||
case TYPE_POINT:
|
case TYPE_POINT:
|
||||||
//particle->SetPosition(mParent->GetX(),mParent->GetY());
|
//particle->SetPosition(mParent->GetX(),mParent->GetY());
|
||||||
particle->InitPosition(xOrigin, yOrigin, 0, 0);
|
particle->InitPosition(xOrigin, yOrigin, 0, 0);
|
||||||
break;
|
break;
|
||||||
case TYPE_AREA:
|
case TYPE_AREA:
|
||||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY()+y);
|
//particle->SetPosition(mParent->GetX()+x,mParent->GetY()+y);
|
||||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||||
break;
|
break;
|
||||||
case TYPE_HORIZONTAL:
|
case TYPE_HORIZONTAL:
|
||||||
x = (float)((rand()%mWidth) - (mWidth>>1));
|
x = (float)((rand()%mWidth) - (mWidth>>1));
|
||||||
//particle->SetPosition(mParent->GetX()+x,mParent->GetY());
|
//particle->SetPosition(mParent->GetX()+x,mParent->GetY());
|
||||||
particle->InitPosition(xOrigin, yOrigin, x, 0);
|
particle->InitPosition(xOrigin, yOrigin, x, 0);
|
||||||
break;
|
break;
|
||||||
case TYPE_VERTICAL:
|
case TYPE_VERTICAL:
|
||||||
y = (float)((rand()%mHeight) - (mHeight>>1));
|
y = (float)((rand()%mHeight) - (mHeight>>1));
|
||||||
//particle->SetPosition(mParent->GetX(),mParent->GetY()+y);
|
//particle->SetPosition(mParent->GetX(),mParent->GetY()+y);
|
||||||
particle->InitPosition(xOrigin, yOrigin, 0, y);
|
particle->InitPosition(xOrigin, yOrigin, 0, y);
|
||||||
break;
|
break;
|
||||||
case TYPE_CIRCLE:
|
case TYPE_CIRCLE:
|
||||||
angle = M_PI* 2 * (rand()%1001)/1000.0f;
|
angle = M_PI* 2 * (rand()%1001)/1000.0f;
|
||||||
x = cosf(angle)*mWidth;
|
x = cosf(angle)*mWidth;
|
||||||
y = sinf(angle)*mHeight;
|
y = sinf(angle)*mHeight;
|
||||||
particle->InitPosition(xOrigin, yOrigin, x, y);
|
particle->InitPosition(xOrigin, yOrigin, x, y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//particle->mSpeed
|
//particle->mSpeed
|
||||||
float speed = mSpeedBase + (mSpeedMax-mSpeedBase) * (rand()%1001)/1000.0f;
|
float speed = mSpeedBase + (mSpeedMax-mSpeedBase) * (rand()%1001)/1000.0f;
|
||||||
|
|
||||||
if (mType != TYPE_CIRCLE)
|
if (mType != TYPE_CIRCLE)
|
||||||
angle = mAngleBase + (mAngleMax-mAngleBase) * (rand()%1001)/1000.0f;
|
angle = mAngleBase + (mAngleMax-mAngleBase) * (rand()%1001)/1000.0f;
|
||||||
//float x = cosf(angle);
|
//float x = cosf(angle);
|
||||||
//float y = sinf(angle);
|
//float y = sinf(angle);
|
||||||
// speed itself is not changing
|
// speed itself is not changing
|
||||||
particle->SetVelocity(cosf(angle)*speed, sinf(angle)*speed);
|
particle->SetVelocity(cosf(angle)*speed, sinf(angle)*speed);
|
||||||
|
|
||||||
particle->SetSize(mSizeBase + (mSizeMax-mSizeBase) * (rand()%1001)/1000.0f);
|
particle->SetSize(mSizeBase + (mSizeMax-mSizeBase) * (rand()%1001)/1000.0f);
|
||||||
|
|
||||||
float life = mLifeBase + (mLifeMax-mLifeBase) * (rand()%1001)/1000.0f;
|
float life = mLifeBase + (mLifeMax-mLifeBase) * (rand()%1001)/1000.0f;
|
||||||
particle->Init(life);
|
particle->Init(life);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::Render()
|
void JParticleEmitter::Render()
|
||||||
{
|
{
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
renderer->SetTexBlend(mSrcBlending, mDestBlending);
|
renderer->SetTexBlend(mSrcBlending, mDestBlending);
|
||||||
|
|
||||||
int size = mParticles.size();
|
int size = mParticles.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
{
|
{
|
||||||
if (mParticles[i]->mActive)
|
if (mParticles[i]->mActive)
|
||||||
{
|
{
|
||||||
mParticles[i]->Render();
|
mParticles[i]->Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::SetBlending(int srcBlend, int destBlend)
|
void JParticleEmitter::SetBlending(int srcBlend, int destBlend)
|
||||||
{
|
{
|
||||||
mSrcBlending = srcBlend;
|
mSrcBlending = srcBlend;
|
||||||
mDestBlending = destBlend;
|
mDestBlending = destBlend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JParticleEmitter::Done()
|
bool JParticleEmitter::Done()
|
||||||
{
|
{
|
||||||
return !mActive && mActiveParticleCount==0;
|
return !mActive && mActiveParticleCount==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::SetActive(bool flag)
|
void JParticleEmitter::SetActive(bool flag)
|
||||||
{
|
{
|
||||||
mActive = flag;
|
mActive = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleEmitter::MoveAllParticles(float x, float y)
|
void JParticleEmitter::MoveAllParticles(float x, float y)
|
||||||
{
|
{
|
||||||
int size = mParticles.size();
|
int size = mParticles.size();
|
||||||
for (int i=0;i<size;i++)
|
for (int i=0;i<size;i++)
|
||||||
{
|
{
|
||||||
if (mParticles[i]->mActive)
|
if (mParticles[i]->mActive)
|
||||||
{
|
{
|
||||||
mParticles[i]->Move(x, y);
|
mParticles[i]->Move(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JParticleEmitter::SetMaxParticleCount(int count)
|
void JParticleEmitter::SetMaxParticleCount(int count)
|
||||||
{
|
{
|
||||||
mMaxParticleCount = count;
|
mMaxParticleCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+124
-124
@@ -1,124 +1,124 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "../include/JGE.h"
|
#include "../include/JGE.h"
|
||||||
#include "../include/JParticleSystem.h"
|
#include "../include/JParticleSystem.h"
|
||||||
#include "../include/JParticleEffect.h"
|
#include "../include/JParticleEffect.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
JParticleSystem::JParticleSystem()
|
JParticleSystem::JParticleSystem()
|
||||||
{
|
{
|
||||||
|
|
||||||
mActive = false;
|
mActive = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JParticleSystem::~JParticleSystem()
|
JParticleSystem::~JParticleSystem()
|
||||||
{
|
{
|
||||||
mEffects.clear();
|
mEffects.clear();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleSystem::ClearAll()
|
void JParticleSystem::ClearAll()
|
||||||
{
|
{
|
||||||
mEffects.clear();
|
mEffects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleSystem::Update(float dt)
|
void JParticleSystem::Update(float dt)
|
||||||
{
|
{
|
||||||
if (!mEffects.empty())
|
if (!mEffects.empty())
|
||||||
{
|
{
|
||||||
JParticleEffect* effect;
|
JParticleEffect* effect;
|
||||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||||
while (curr != mEffects.end())
|
while (curr != mEffects.end())
|
||||||
{
|
{
|
||||||
effect = *curr;
|
effect = *curr;
|
||||||
effect->Update(dt);
|
effect->Update(dt);
|
||||||
if (effect->Done())
|
if (effect->Done())
|
||||||
{
|
{
|
||||||
mEffects.erase(curr++);
|
mEffects.erase(curr++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
curr++;
|
curr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleSystem::Render()
|
void JParticleSystem::Render()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!mEffects.empty())
|
if (!mEffects.empty())
|
||||||
{
|
{
|
||||||
JParticleEffect* effect;
|
JParticleEffect* effect;
|
||||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||||
while (curr != mEffects.end())
|
while (curr != mEffects.end())
|
||||||
{
|
{
|
||||||
effect = *curr;
|
effect = *curr;
|
||||||
effect->Render();
|
effect->Render();
|
||||||
|
|
||||||
curr++;
|
curr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JParticleSystem::StartEffect(JParticleEffect* effect)
|
void JParticleSystem::StartEffect(JParticleEffect* effect)
|
||||||
{
|
{
|
||||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||||
while (curr != mEffects.end())
|
while (curr != mEffects.end())
|
||||||
{
|
{
|
||||||
if (effect == *curr && effect->GetParticleSystem() == this)
|
if (effect == *curr && effect->GetParticleSystem() == this)
|
||||||
{
|
{
|
||||||
effect->Start();
|
effect->Start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
curr++;
|
curr++;
|
||||||
}
|
}
|
||||||
mEffects.push_back(effect);
|
mEffects.push_back(effect);
|
||||||
effect->SetParticleSystem(this);
|
effect->SetParticleSystem(this);
|
||||||
effect->Start();
|
effect->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JParticleSystem::StopAllEffects()
|
void JParticleSystem::StopAllEffects()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!mEffects.empty())
|
if (!mEffects.empty())
|
||||||
{
|
{
|
||||||
JParticleEffect* effect;
|
JParticleEffect* effect;
|
||||||
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
std::list<JParticleEffect*>::iterator curr = mEffects.begin();
|
||||||
while (curr != mEffects.end())
|
while (curr != mEffects.end())
|
||||||
{
|
{
|
||||||
effect = *curr;
|
effect = *curr;
|
||||||
effect->Stop();
|
effect->Stop();
|
||||||
curr++;
|
curr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JParticleSystem::IsActive() { return mActive; }
|
bool JParticleSystem::IsActive() { return mActive; }
|
||||||
|
|
||||||
void JParticleSystem::SetActive(bool flag) { mActive = flag; }
|
void JParticleSystem::SetActive(bool flag) { mActive = flag; }
|
||||||
|
|
||||||
|
|||||||
+203
-203
@@ -1,203 +1,203 @@
|
|||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "../include/JFileSystem.h"
|
#include "../include/JFileSystem.h"
|
||||||
#include "../include/JSpline.h"
|
#include "../include/JSpline.h"
|
||||||
|
|
||||||
#include "tinyxml/tinyxml.h"
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
#define SMALL_NUMBER 0.0001f
|
#define SMALL_NUMBER 0.0001f
|
||||||
|
|
||||||
|
|
||||||
JSpline::JSpline()
|
JSpline::JSpline()
|
||||||
{
|
{
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
|
|
||||||
mMidPoints.reserve(32);
|
mMidPoints.reserve(32);
|
||||||
mPixels.reserve(32);
|
mPixels.reserve(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSpline::~JSpline()
|
JSpline::~JSpline()
|
||||||
{
|
{
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
|
|
||||||
mMidPoints.clear();
|
mMidPoints.clear();
|
||||||
mPixels.clear();
|
mPixels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JSpline::Load(const char *filename, float xscale, float yscale)
|
bool JSpline::Load(const char *filename, float xscale, float yscale)
|
||||||
{
|
{
|
||||||
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
JFileSystem *fileSystem = JFileSystem::GetInstance();
|
||||||
|
|
||||||
if (fileSystem == NULL) return false;
|
if (fileSystem == NULL) return false;
|
||||||
if (!fileSystem->OpenFile(filename)) return false;
|
if (!fileSystem->OpenFile(filename)) return false;
|
||||||
|
|
||||||
int size = fileSystem->GetFileSize();
|
int size = fileSystem->GetFileSize();
|
||||||
char *xmlBuffer = new char[size];
|
char *xmlBuffer = new char[size];
|
||||||
fileSystem->ReadFile(xmlBuffer, size);
|
fileSystem->ReadFile(xmlBuffer, size);
|
||||||
|
|
||||||
TiXmlDocument doc;
|
TiXmlDocument doc;
|
||||||
doc.Parse(xmlBuffer);
|
doc.Parse(xmlBuffer);
|
||||||
|
|
||||||
mCount = 0;
|
mCount = 0;
|
||||||
|
|
||||||
mMidPoints.clear();
|
mMidPoints.clear();
|
||||||
mPixels.clear();
|
mPixels.clear();
|
||||||
|
|
||||||
|
|
||||||
TiXmlNode* node = 0;
|
TiXmlNode* node = 0;
|
||||||
//TiXmlElement* todoElement = 0;
|
//TiXmlElement* todoElement = 0;
|
||||||
TiXmlElement* element;
|
TiXmlElement* element;
|
||||||
|
|
||||||
node = doc.RootElement();
|
node = doc.RootElement();
|
||||||
|
|
||||||
float xx, yy;
|
float xx, yy;
|
||||||
|
|
||||||
for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
|
for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
|
||||||
{
|
{
|
||||||
xx = 0.0f;
|
xx = 0.0f;
|
||||||
yy = 0.0f;
|
yy = 0.0f;
|
||||||
element->QueryFloatAttribute("x", &xx);
|
element->QueryFloatAttribute("x", &xx);
|
||||||
element->QueryFloatAttribute("y", &yy);
|
element->QueryFloatAttribute("y", &yy);
|
||||||
|
|
||||||
Point pt(xx*xscale, yy*yscale);
|
Point pt(xx*xscale, yy*yscale);
|
||||||
AddControlPoint(pt);
|
AddControlPoint(pt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile();
|
||||||
delete[] xmlBuffer;
|
delete[] xmlBuffer;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JSpline::PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3)
|
void JSpline::PointOnCurve(Point &out, float t, const Point &p0, const Point &p1, const Point &p2, const Point &p3)
|
||||||
{
|
{
|
||||||
float t2 = t * t;
|
float t2 = t * t;
|
||||||
float t3 = t2 * t;
|
float t3 = t2 * t;
|
||||||
out.x = 0.5f * (( 2.0f * p1.x ) +
|
out.x = 0.5f * (( 2.0f * p1.x ) +
|
||||||
( -p0.x + p2.x ) * t +
|
( -p0.x + p2.x ) * t +
|
||||||
( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
|
( 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 );
|
( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
|
||||||
|
|
||||||
out.y = 0.5f * ( ( 2.0f * p1.y ) +
|
out.y = 0.5f * ( ( 2.0f * p1.y ) +
|
||||||
( -p0.y + p2.y ) * t +
|
( -p0.y + p2.y ) * t +
|
||||||
( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
|
( 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 );
|
( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void JSpline::GeneratePixels()
|
void JSpline::GeneratePixels()
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
float inc = SMALL_NUMBER;
|
float inc = SMALL_NUMBER;
|
||||||
|
|
||||||
mPixels.clear();
|
mPixels.clear();
|
||||||
|
|
||||||
x = mMidPoints[1].x;
|
x = mMidPoints[1].x;
|
||||||
y = mMidPoints[1].y;
|
y = mMidPoints[1].y;
|
||||||
|
|
||||||
Point newPt(x, y);
|
Point newPt(x, y);
|
||||||
Point extraPt;
|
Point extraPt;
|
||||||
|
|
||||||
mPixels.push_back(newPt);
|
mPixels.push_back(newPt);
|
||||||
|
|
||||||
for (int n=0; n < (int)mMidPoints.size()-3; n++)
|
for (int n=0; n < (int)mMidPoints.size()-3; n++)
|
||||||
{
|
{
|
||||||
float t = inc;
|
float t = inc;
|
||||||
while (t <= 1.0f)
|
while (t <= 1.0f)
|
||||||
{
|
{
|
||||||
PointOnCurve(newPt, t, mMidPoints[n], mMidPoints[n+1], mMidPoints[n+2], mMidPoints[n+3]);
|
PointOnCurve(newPt, t, mMidPoints[n], mMidPoints[n+1], mMidPoints[n+2], mMidPoints[n+3]);
|
||||||
|
|
||||||
float dx = newPt.x-x;
|
float dx = newPt.x-x;
|
||||||
float dy = newPt.y-y;
|
float dy = newPt.y-y;
|
||||||
|
|
||||||
float dist = sqrtf(dx*dx + dy*dy);
|
float dist = sqrtf(dx*dx + dy*dy);
|
||||||
if (dist >= MID_POINT_THRESHOLD)
|
if (dist >= MID_POINT_THRESHOLD)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
//extraPt.x = (newPt.x+x)/2;
|
//extraPt.x = (newPt.x+x)/2;
|
||||||
//extraPt.y = (newPt.y+y)/2;
|
//extraPt.y = (newPt.y+y)/2;
|
||||||
//mPixels.push_back(extraPt);
|
//mPixels.push_back(extraPt);
|
||||||
//
|
//
|
||||||
mPixels.push_back(newPt);
|
mPixels.push_back(newPt);
|
||||||
x = newPt.x;
|
x = newPt.x;
|
||||||
y = newPt.y;
|
y = newPt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
t += inc;
|
t += inc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mCount = mPixels.size();
|
mCount = mPixels.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JSpline::AddControlPoint(const Point &pt)
|
void JSpline::AddControlPoint(const Point &pt)
|
||||||
{
|
{
|
||||||
mMidPoints.push_back(pt);
|
mMidPoints.push_back(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JSpline::GetControlPoint(Point &point, int index)
|
void JSpline::GetControlPoint(Point &point, int index)
|
||||||
{
|
{
|
||||||
if (index < (int)mMidPoints.size())
|
if (index < (int)mMidPoints.size())
|
||||||
{
|
{
|
||||||
point.x = mMidPoints[index].x;
|
point.x = mMidPoints[index].x;
|
||||||
point.y = mMidPoints[index].y;
|
point.y = mMidPoints[index].y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JSpline::GetPixel(Point &point, int index)
|
void JSpline::GetPixel(Point &point, int index)
|
||||||
{
|
{
|
||||||
if (index < (int)mPixels.size())
|
if (index < (int)mPixels.size())
|
||||||
{
|
{
|
||||||
point.x = mPixels[index].x;
|
point.x = mPixels[index].x;
|
||||||
point.y = mPixels[index].y;
|
point.y = mPixels[index].y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int JSpline::GetPixelCount()
|
int JSpline::GetPixelCount()
|
||||||
{
|
{
|
||||||
return mCount;
|
return mCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void JSpline::Render(float x, float y, PIXEL_TYPE color, PIXEL_TYPE controlColor)
|
void JSpline::Render(float x, float y, PIXEL_TYPE color, PIXEL_TYPE controlColor)
|
||||||
{
|
{
|
||||||
if (mCount > 0)
|
if (mCount > 0)
|
||||||
{
|
{
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
// renderer->SetLineWidth(1.2f);
|
// renderer->SetLineWidth(1.2f);
|
||||||
|
|
||||||
int size = mPixels.size();
|
int size = mPixels.size();
|
||||||
|
|
||||||
for (int i=0;i<size-1;i++)
|
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);
|
renderer->DrawLine(x+mPixels[i].x, y+mPixels[i].y, x+mPixels[i+1].x, y+mPixels[i+1].y, color);
|
||||||
|
|
||||||
size = mMidPoints.size();
|
size = mMidPoints.size();
|
||||||
for (int i=0; i < size; i++)
|
for (int i=0; i < size; i++)
|
||||||
renderer->FillRect(mMidPoints[i].x-3, mMidPoints[i].y-3, 6, 6, controlColor);
|
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.
|
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||||
//
|
//
|
||||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
// 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 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#include "../include/Vector2D.h"
|
#include "../include/Vector2D.h"
|
||||||
|
|
||||||
|
|
||||||
float Vector2D::Length(void) const
|
float Vector2D::Length(void) const
|
||||||
{
|
{
|
||||||
return sqrtf(x*x + y*y);
|
return sqrtf(x*x + y*y);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2D::Normalize(void)
|
float Vector2D::Normalize(void)
|
||||||
{
|
{
|
||||||
float fLength = Length();
|
float fLength = Length();
|
||||||
|
|
||||||
if (fLength == 0.0f)
|
if (fLength == 0.0f)
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
(*this) *= (1.0f / fLength);
|
(*this) *= (1.0f / fLength);
|
||||||
|
|
||||||
return fLength;
|
return fLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2D Vector2D::Direction(void) const
|
Vector2D Vector2D::Direction(void) const
|
||||||
{
|
{
|
||||||
Vector2D temp(*this);
|
Vector2D temp(*this);
|
||||||
|
|
||||||
temp.Normalize();
|
temp.Normalize();
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2D::Angle(const Vector2D& xE)
|
float Vector2D::Angle(const Vector2D& xE)
|
||||||
{
|
{
|
||||||
float dot = (*this) * xE;
|
float dot = (*this) * xE;
|
||||||
float cross = (*this) ^ xE;
|
float cross = (*this) ^ xE;
|
||||||
|
|
||||||
// angle between segments
|
// angle between segments
|
||||||
float angle = atan2f(cross, dot);
|
float angle = atan2f(cross, dot);
|
||||||
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2D& Vector2D::Rotate(float angle)
|
Vector2D& Vector2D::Rotate(float angle)
|
||||||
{
|
{
|
||||||
float tx = x;
|
float tx = x;
|
||||||
x = x * cosf(angle) - y * sinf(angle);
|
x = x * cosf(angle) - y * sinf(angle);
|
||||||
y = tx * sinf(angle) + y * cosf(angle);
|
y = tx * sinf(angle) + y * cosf(angle);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vector2D& Vector2D::Rotate(const Vector2D& xCentre, float fAngle)
|
Vector2D& Vector2D::Rotate(const Vector2D& xCentre, float fAngle)
|
||||||
{
|
{
|
||||||
Vector2D D = *this - xCentre;
|
Vector2D D = *this - xCentre;
|
||||||
D.Rotate(fAngle);
|
D.Rotate(fAngle);
|
||||||
|
|
||||||
*this = xCentre + D;
|
*this = xCentre + D;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Vector2D::Clamp(const Vector2D& min, const Vector2D& max)
|
void Vector2D::Clamp(const Vector2D& min, const Vector2D& max)
|
||||||
{
|
{
|
||||||
x = (x < min.x)? min.x : (x > max.x)? max.x : x;
|
x = (x < min.x)? min.x : (x > max.x)? max.x : x;
|
||||||
x = (y < min.y)? min.y : (y > max.y)? max.y : y;
|
x = (y < min.y)? min.y : (y > max.y)? max.y : y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+89
-89
@@ -1,89 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeColor*** helper classes implementation
|
** hgeColor*** helper classes implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../../include/hge/hgecolor.h"
|
#include "../../include/hge/hgecolor.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
#define min(x, y) ((x<y)?x:y)
|
#define min(x, y) ((x<y)?x:y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef max
|
#ifndef max
|
||||||
#define max(x, y) ((x>y)?x:y)
|
#define max(x, y) ((x>y)?x:y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void hgeColorHSV::SetHWColor(DWORD col)
|
void hgeColorHSV::SetHWColor(DWORD col)
|
||||||
{
|
{
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
float minv, maxv, delta;
|
float minv, maxv, delta;
|
||||||
float del_R, del_G, del_B;
|
float del_R, del_G, del_B;
|
||||||
|
|
||||||
a = (col>>24) / 255.0f;
|
a = (col>>24) / 255.0f;
|
||||||
r = ((col>>16) & 0xFF) / 255.0f;
|
r = ((col>>16) & 0xFF) / 255.0f;
|
||||||
g = ((col>>8) & 0xFF) / 255.0f;
|
g = ((col>>8) & 0xFF) / 255.0f;
|
||||||
b = (col & 0xFF) / 255.0f;
|
b = (col & 0xFF) / 255.0f;
|
||||||
|
|
||||||
minv = min(min(r, g), b);
|
minv = min(min(r, g), b);
|
||||||
maxv = max(max(r, g), b);
|
maxv = max(max(r, g), b);
|
||||||
delta = maxv - minv;
|
delta = maxv - minv;
|
||||||
|
|
||||||
v = maxv;
|
v = maxv;
|
||||||
|
|
||||||
if (delta == 0)
|
if (delta == 0)
|
||||||
{
|
{
|
||||||
h = 0;
|
h = 0;
|
||||||
s = 0;
|
s = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s = delta / maxv;
|
s = delta / maxv;
|
||||||
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
|
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
|
||||||
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
|
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
|
||||||
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
|
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
|
||||||
|
|
||||||
if (r == maxv) {h = del_B - del_G;}
|
if (r == maxv) {h = del_B - del_G;}
|
||||||
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
|
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
|
||||||
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
|
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
|
||||||
|
|
||||||
if (h < 0) h += 1;
|
if (h < 0) h += 1;
|
||||||
if (h > 1) h -= 1;
|
if (h > 1) h -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD hgeColorHSV::GetHWColor() const
|
DWORD hgeColorHSV::GetHWColor() const
|
||||||
{
|
{
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
float xh, i, p1, p2, p3;
|
float xh, i, p1, p2, p3;
|
||||||
|
|
||||||
if (s == 0)
|
if (s == 0)
|
||||||
{
|
{
|
||||||
r = v;
|
r = v;
|
||||||
g = v;
|
g = v;
|
||||||
b = v;
|
b = v;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xh = h * 6;
|
xh = h * 6;
|
||||||
if(xh == 6) xh=0;
|
if(xh == 6) xh=0;
|
||||||
i = floorf(xh);
|
i = floorf(xh);
|
||||||
p1 = v * (1 - s);
|
p1 = v * (1 - s);
|
||||||
p2 = v * (1 - s * (xh - i));
|
p2 = v * (1 - s * (xh - i));
|
||||||
p3 = v * (1 - s * (1 - (xh - i)));
|
p3 = v * (1 - s * (1 - (xh - i)));
|
||||||
|
|
||||||
if (i == 0) {r = v; g = p3; b = p1;}
|
if (i == 0) {r = v; g = p3; b = p1;}
|
||||||
else if (i == 1) {r = p2; g = v; 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 == 2) {r = p1; g = v; b = p3;}
|
||||||
else if (i == 3) {r = p1; g = p2; b = v; }
|
else if (i == 3) {r = p1; g = p2; b = v; }
|
||||||
else if (i == 4) {r = p3; g = p1; b = v; }
|
else if (i == 4) {r = p3; g = p1; b = v; }
|
||||||
else {r = v; g = p1; b = p2;}
|
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)));
|
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
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeDistortionMesh helper class implementation
|
** hgeDistortionMesh helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../include/JGE.h"
|
#include "../../include/JGE.h"
|
||||||
#include "../../include/JTypes.h"
|
#include "../../include/JTypes.h"
|
||||||
#include "../../include/JRenderer.h"
|
#include "../../include/JRenderer.h"
|
||||||
#include "../../include/JFileSystem.h"
|
#include "../../include/JFileSystem.h"
|
||||||
|
|
||||||
#include "../../include/hge/hgedistort.h"
|
#include "../../include/hge/hgedistort.h"
|
||||||
|
|
||||||
|
|
||||||
//HGE *hgeDistortionMesh::hge=0;
|
//HGE *hgeDistortionMesh::hge=0;
|
||||||
|
|
||||||
|
|
||||||
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
|
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//hge=hgeCreate(HGE_VERSION);
|
||||||
|
|
||||||
nRows=rows;
|
nRows=rows;
|
||||||
nCols=cols;
|
nCols=cols;
|
||||||
cellw=cellh=0;
|
cellw=cellh=0;
|
||||||
//quad.tex=0;
|
//quad.tex=0;
|
||||||
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
|
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
|
||||||
|
|
||||||
quad = NULL;
|
quad = NULL;
|
||||||
|
|
||||||
disp_array=new Vertex[rows*cols];
|
disp_array=new Vertex[rows*cols];
|
||||||
|
|
||||||
for(i=0;i<rows*cols;i++)
|
for(i=0;i<rows*cols;i++)
|
||||||
{
|
{
|
||||||
disp_array[i].x=0.0f;
|
disp_array[i].x=0.0f;
|
||||||
disp_array[i].y=0.0f;
|
disp_array[i].y=0.0f;
|
||||||
disp_array[i].u=0.0f;
|
disp_array[i].u=0.0f;
|
||||||
disp_array[i].v=0.0f;
|
disp_array[i].v=0.0f;
|
||||||
|
|
||||||
disp_array[i].z=0.5f;
|
disp_array[i].z=0.5f;
|
||||||
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
|
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
|
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
|
||||||
{
|
{
|
||||||
// hge=hgeCreate(HGE_VERSION);
|
// hge=hgeCreate(HGE_VERSION);
|
||||||
|
|
||||||
nRows=dm.nRows;
|
nRows=dm.nRows;
|
||||||
nCols=dm.nCols;
|
nCols=dm.nCols;
|
||||||
cellw=dm.cellw;
|
cellw=dm.cellw;
|
||||||
cellh=dm.cellh;
|
cellh=dm.cellh;
|
||||||
tx=dm.tx;
|
tx=dm.tx;
|
||||||
ty=dm.ty;
|
ty=dm.ty;
|
||||||
width=dm.width;
|
width=dm.width;
|
||||||
height=dm.height;
|
height=dm.height;
|
||||||
quad=dm.quad;
|
quad=dm.quad;
|
||||||
|
|
||||||
disp_array=new Vertex[nRows*nCols];
|
disp_array=new Vertex[nRows*nCols];
|
||||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeDistortionMesh::~hgeDistortionMesh()
|
hgeDistortionMesh::~hgeDistortionMesh()
|
||||||
{
|
{
|
||||||
delete[] disp_array;
|
delete[] disp_array;
|
||||||
SAFE_DELETE(quad);
|
SAFE_DELETE(quad);
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
|
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
|
||||||
{
|
{
|
||||||
if(this!=&dm)
|
if(this!=&dm)
|
||||||
{
|
{
|
||||||
nRows=dm.nRows;
|
nRows=dm.nRows;
|
||||||
nCols=dm.nCols;
|
nCols=dm.nCols;
|
||||||
cellw=dm.cellw;
|
cellw=dm.cellw;
|
||||||
cellh=dm.cellh;
|
cellh=dm.cellh;
|
||||||
tx=dm.tx;
|
tx=dm.tx;
|
||||||
ty=dm.ty;
|
ty=dm.ty;
|
||||||
width=dm.width;
|
width=dm.width;
|
||||||
height=dm.height;
|
height=dm.height;
|
||||||
quad=dm.quad;
|
quad=dm.quad;
|
||||||
|
|
||||||
delete[] disp_array;
|
delete[] disp_array;
|
||||||
disp_array=new Vertex[nRows*nCols];
|
disp_array=new Vertex[nRows*nCols];
|
||||||
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::SetTexture(JTexture* tex)
|
void hgeDistortionMesh::SetTexture(JTexture* tex)
|
||||||
{
|
{
|
||||||
if (quad)
|
if (quad)
|
||||||
delete quad;
|
delete quad;
|
||||||
|
|
||||||
quad = new JQuad(tex, 0, 0, 16, 16);
|
quad = new JQuad(tex, 0, 0, 16, 16);
|
||||||
//quad.tex=tex;
|
//quad.tex=tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
|
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
float tw,th;
|
float tw,th;
|
||||||
|
|
||||||
tx=x; ty=y; width=w; height=h;
|
tx=x; ty=y; width=w; height=h;
|
||||||
|
|
||||||
if (quad->mTex)
|
if (quad->mTex)
|
||||||
{
|
{
|
||||||
tw=(float)quad->mTex->mTexWidth;
|
tw=(float)quad->mTex->mTexWidth;
|
||||||
th=(float)quad->mTex->mTexHeight;
|
th=(float)quad->mTex->mTexHeight;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tw = w;
|
tw = w;
|
||||||
th = h;
|
th = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
cellw=w/(nCols-1);
|
cellw=w/(nCols-1);
|
||||||
cellh=h/(nRows-1);
|
cellh=h/(nRows-1);
|
||||||
|
|
||||||
for(j=0; j<nRows; j++)
|
for(j=0; j<nRows; j++)
|
||||||
for(i=0; i<nCols; i++)
|
for(i=0; i<nCols; i++)
|
||||||
{
|
{
|
||||||
disp_array[j*nCols+i].u=(x+i*cellw);
|
disp_array[j*nCols+i].u=(x+i*cellw);
|
||||||
disp_array[j*nCols+i].v=(y+j*cellh);
|
disp_array[j*nCols+i].v=(y+j*cellh);
|
||||||
|
|
||||||
disp_array[j*nCols+i].x=i*cellw;
|
disp_array[j*nCols+i].x=i*cellw;
|
||||||
disp_array[j*nCols+i].y=j*cellh;
|
disp_array[j*nCols+i].y=j*cellh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
|
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
|
||||||
{
|
{
|
||||||
// quad.blend=blend;
|
// quad.blend=blend;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
|
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
|
|
||||||
for(j=0; j<nRows; j++)
|
for(j=0; j<nRows; j++)
|
||||||
for(i=0; i<nCols; i++)
|
for(i=0; i<nCols; i++)
|
||||||
{
|
{
|
||||||
disp_array[j*nCols+i].x=i*cellw;
|
disp_array[j*nCols+i].x=i*cellw;
|
||||||
disp_array[j*nCols+i].y=j*cellh;
|
disp_array[j*nCols+i].y=j*cellh;
|
||||||
disp_array[j*nCols+i].color=col;
|
disp_array[j*nCols+i].color=col;
|
||||||
disp_array[j*nCols+i].z=z;
|
disp_array[j*nCols+i].z=z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::Render(float x, float y)
|
void hgeDistortionMesh::Render(float x, float y)
|
||||||
{
|
{
|
||||||
int i,j,idx;
|
int i,j,idx;
|
||||||
|
|
||||||
VertexColor points[4];
|
VertexColor points[4];
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
for(j=0; j<nRows-1; j++)
|
for(j=0; j<nRows-1; j++)
|
||||||
for(i=0; i<nCols-1; i++)
|
for(i=0; i<nCols-1; i++)
|
||||||
{
|
{
|
||||||
idx=j*nCols+i;
|
idx=j*nCols+i;
|
||||||
|
|
||||||
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
|
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
|
||||||
|
|
||||||
points[0].x = x+disp_array[idx+nCols].x;
|
points[0].x = x+disp_array[idx+nCols].x;
|
||||||
points[0].y = y+disp_array[idx+nCols].y;
|
points[0].y = y+disp_array[idx+nCols].y;
|
||||||
points[0].z = disp_array[idx+nCols].z;
|
points[0].z = disp_array[idx+nCols].z;
|
||||||
points[0].color = disp_array[idx+nCols].color;
|
points[0].color = disp_array[idx+nCols].color;
|
||||||
|
|
||||||
points[1].x = x+disp_array[idx+nCols+1].x;
|
points[1].x = x+disp_array[idx+nCols+1].x;
|
||||||
points[1].y = y+disp_array[idx+nCols+1].y;
|
points[1].y = y+disp_array[idx+nCols+1].y;
|
||||||
points[1].z = disp_array[idx+nCols+1].z;
|
points[1].z = disp_array[idx+nCols+1].z;
|
||||||
points[1].color = disp_array[idx+nCols+1].color;
|
points[1].color = disp_array[idx+nCols+1].color;
|
||||||
|
|
||||||
points[2].x = x+disp_array[idx+1].x;
|
points[2].x = x+disp_array[idx+1].x;
|
||||||
points[2].y = y+disp_array[idx+1].y;
|
points[2].y = y+disp_array[idx+1].y;
|
||||||
points[2].z = disp_array[idx+1].z;
|
points[2].z = disp_array[idx+1].z;
|
||||||
points[2].color = disp_array[idx+1].color;
|
points[2].color = disp_array[idx+1].color;
|
||||||
|
|
||||||
points[3].x = x+disp_array[idx].x;
|
points[3].x = x+disp_array[idx].x;
|
||||||
points[3].y = y+disp_array[idx].y;
|
points[3].y = y+disp_array[idx].y;
|
||||||
points[3].z = disp_array[idx].z;
|
points[3].z = disp_array[idx].z;
|
||||||
points[3].color = disp_array[idx].color;
|
points[3].color = disp_array[idx].color;
|
||||||
|
|
||||||
renderer->RenderQuad(quad, points);
|
renderer->RenderQuad(quad, points);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::SetZ(int col, int row, float z)
|
void hgeDistortionMesh::SetZ(int col, int row, float z)
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
|
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols) disp_array[row*nCols+col].color=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)
|
void hgeDistortionMesh::SetDisplacement(int col, int row, float dx, float dy, int ref)
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols)
|
if(row<nRows && col<nCols)
|
||||||
{
|
{
|
||||||
switch(ref)
|
switch(ref)
|
||||||
{
|
{
|
||||||
case HGEDISP_NODE: dx+=col*cellw; dy+=row*cellh; break;
|
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_CENTER: dx+=cellw*(nCols-1)/2;dy+=cellh*(nRows-1)/2; break;
|
||||||
case HGEDISP_TOPLEFT: break;
|
case HGEDISP_TOPLEFT: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
disp_array[row*nCols+col].x=dx;
|
disp_array[row*nCols+col].x=dx;
|
||||||
disp_array[row*nCols+col].y=dy;
|
disp_array[row*nCols+col].y=dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float hgeDistortionMesh::GetZ(int col, int row) const
|
float hgeDistortionMesh::GetZ(int col, int row) const
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
|
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
|
||||||
else return 0.0f;
|
else return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
|
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
|
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
|
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
|
||||||
{
|
{
|
||||||
if(row<nRows && col<nCols)
|
if(row<nRows && col<nCols)
|
||||||
{
|
{
|
||||||
switch(ref)
|
switch(ref)
|
||||||
{
|
{
|
||||||
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
|
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
|
||||||
*dy=disp_array[row*nCols+col].y-row*cellh;
|
*dy=disp_array[row*nCols+col].y-row*cellh;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HGEDISP_CENTER: *dx=disp_array[row*nCols+col].x-cellw*(nCols-1)/2;
|
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;
|
*dy=disp_array[row*nCols+col].x-cellh*(nRows-1)/2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
|
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
|
||||||
*dy=disp_array[row*nCols+col].y;
|
*dy=disp_array[row*nCols+col].y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+360
-360
@@ -1,360 +1,360 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeFont helper class implementation
|
** hgeFont helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../include/JGE.h"
|
#include "../../include/JGE.h"
|
||||||
#include "../../include/JTypes.h"
|
#include "../../include/JTypes.h"
|
||||||
#include "../../include/JRenderer.h"
|
#include "../../include/JRenderer.h"
|
||||||
#include "../../include/JFileSystem.h"
|
#include "../../include/JFileSystem.h"
|
||||||
|
|
||||||
#include "../../include/hge/hgefont.h"
|
#include "../../include/hge/hgefont.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const char FNTHEADERTAG[] = "[HGEFONT]";
|
const char FNTHEADERTAG[] = "[HGEFONT]";
|
||||||
const char FNTBITMAPTAG[] = "Bitmap";
|
const char FNTBITMAPTAG[] = "Bitmap";
|
||||||
const char FNTCHARTAG[] = "Char";
|
const char FNTCHARTAG[] = "Char";
|
||||||
|
|
||||||
|
|
||||||
//HGE *hgeFont::hge=0;
|
//HGE *hgeFont::hge=0;
|
||||||
char hgeFont::buffer[256];
|
char hgeFont::buffer[256];
|
||||||
|
|
||||||
|
|
||||||
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
|
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
|
||||||
{
|
{
|
||||||
//void *data;
|
//void *data;
|
||||||
DWORD size;
|
DWORD size;
|
||||||
char *desc, *pdesc;
|
char *desc, *pdesc;
|
||||||
char linebuf[256];
|
char linebuf[256];
|
||||||
char buf[512], *pbuf;
|
char buf[512], *pbuf;
|
||||||
char chr;
|
char chr;
|
||||||
int i, x, y, w, h, a, c;
|
int i, x, y, w, h, a, c;
|
||||||
|
|
||||||
// Setup variables
|
// Setup variables
|
||||||
|
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//hge=hgeCreate(HGE_VERSION);
|
||||||
|
|
||||||
fHeight=0.0f;
|
fHeight=0.0f;
|
||||||
fScale=1.0f;
|
fScale=1.0f;
|
||||||
fProportion=1.0f;
|
fProportion=1.0f;
|
||||||
fRot=0.0f;
|
fRot=0.0f;
|
||||||
fTracking=0.0f;
|
fTracking=0.0f;
|
||||||
fSpacing=1.0f;
|
fSpacing=1.0f;
|
||||||
hTexture=0;
|
hTexture=0;
|
||||||
|
|
||||||
fZ=0.5f;
|
fZ=0.5f;
|
||||||
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
|
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
|
||||||
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
|
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
|
||||||
|
|
||||||
memset( &letters, 0, sizeof(letters) );
|
memset( &letters, 0, sizeof(letters) );
|
||||||
memset( &pre, 0, sizeof(letters) );
|
memset( &pre, 0, sizeof(letters) );
|
||||||
memset( &post, 0, sizeof(letters) );
|
memset( &post, 0, sizeof(letters) );
|
||||||
|
|
||||||
// Load font description
|
// Load font description
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
if (!fileSys->OpenFile(szFont)) return;
|
if (!fileSys->OpenFile(szFont)) return;
|
||||||
|
|
||||||
//data=hge->Resource_Load(szFont, &size);
|
//data=hge->Resource_Load(szFont, &size);
|
||||||
//if(!data) return;
|
//if(!data) return;
|
||||||
size = fileSys->GetFileSize();
|
size = fileSys->GetFileSize();
|
||||||
|
|
||||||
desc = new char[size+1];
|
desc = new char[size+1];
|
||||||
//memcpy(desc,data,size);
|
//memcpy(desc,data,size);
|
||||||
fileSys->ReadFile(desc, size);
|
fileSys->ReadFile(desc, size);
|
||||||
desc[size]=0;
|
desc[size]=0;
|
||||||
|
|
||||||
//hge->Resource_Free(data);
|
//hge->Resource_Free(data);
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile();
|
||||||
|
|
||||||
pdesc=_get_line(desc,linebuf);
|
pdesc=_get_line(desc,linebuf);
|
||||||
if(strcmp(linebuf, FNTHEADERTAG))
|
if(strcmp(linebuf, FNTHEADERTAG))
|
||||||
{
|
{
|
||||||
// hge->System_Log("Font %s has incorrect format.", szFont);
|
// hge->System_Log("Font %s has incorrect format.", szFont);
|
||||||
delete[] desc;
|
delete[] desc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse font description
|
// Parse font description
|
||||||
|
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
|
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
|
||||||
{
|
{
|
||||||
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
|
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
|
||||||
{
|
{
|
||||||
strcpy(buf,szFont);
|
strcpy(buf,szFont);
|
||||||
pbuf=strrchr(buf,'\\');
|
pbuf=strrchr(buf,'\\');
|
||||||
if(!pbuf) pbuf=strrchr(buf,'/');
|
if(!pbuf) pbuf=strrchr(buf,'/');
|
||||||
if(!pbuf) pbuf=buf;
|
if(!pbuf) pbuf=buf;
|
||||||
else pbuf++;
|
else pbuf++;
|
||||||
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
|
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
|
||||||
|
|
||||||
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
|
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
|
||||||
hTexture = renderer->LoadTexture(buf);
|
hTexture = renderer->LoadTexture(buf);
|
||||||
if(!hTexture)
|
if(!hTexture)
|
||||||
{
|
{
|
||||||
delete[] desc;
|
delete[] desc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
|
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
|
||||||
{
|
{
|
||||||
pbuf=strchr(linebuf,'=');
|
pbuf=strchr(linebuf,'=');
|
||||||
if(!pbuf) continue;
|
if(!pbuf) continue;
|
||||||
pbuf++;
|
pbuf++;
|
||||||
while(*pbuf==' ') pbuf++;
|
while(*pbuf==' ') pbuf++;
|
||||||
if(*pbuf=='\"')
|
if(*pbuf=='\"')
|
||||||
{
|
{
|
||||||
pbuf++;
|
pbuf++;
|
||||||
i=(unsigned char)*pbuf++;
|
i=(unsigned char)*pbuf++;
|
||||||
pbuf++; // skip "
|
pbuf++; // skip "
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i=0;
|
i=0;
|
||||||
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
|
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
|
||||||
{
|
{
|
||||||
chr=*pbuf;
|
chr=*pbuf;
|
||||||
if(chr >= 'a') chr-='a'-':';
|
if(chr >= 'a') chr-='a'-':';
|
||||||
if(chr >= 'A') chr-='A'-':';
|
if(chr >= 'A') chr-='A'-':';
|
||||||
chr-='0';
|
chr-='0';
|
||||||
if(chr>0xF) chr=0xF;
|
if(chr>0xF) chr=0xF;
|
||||||
i=(i << 4) | chr;
|
i=(i << 4) | chr;
|
||||||
pbuf++;
|
pbuf++;
|
||||||
}
|
}
|
||||||
if(i<0 || i>255) continue;
|
if(i<0 || i>255) continue;
|
||||||
}
|
}
|
||||||
sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);
|
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);
|
letters[i] = new JQuad(hTexture, (float)x, (float)y, (float)w, (float)h);
|
||||||
pre[i]=(float)a;
|
pre[i]=(float)a;
|
||||||
post[i]=(float)c;
|
post[i]=(float)c;
|
||||||
if(h>fHeight) fHeight=(float)h;
|
if(h>fHeight) fHeight=(float)h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] desc;
|
delete[] desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hgeFont::~hgeFont()
|
hgeFont::~hgeFont()
|
||||||
{
|
{
|
||||||
for(int i=0; i<256; i++)
|
for(int i=0; i<256; i++)
|
||||||
if(letters[i]) delete letters[i];
|
if(letters[i]) delete letters[i];
|
||||||
if(hTexture) delete hTexture;
|
if(hTexture) delete hTexture;
|
||||||
//hge->Release();
|
//hge->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::Render(float x, float y, int align, const char *string)
|
void hgeFont::Render(float x, float y, int align, const char *string)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float fx=x;
|
float fx=x;
|
||||||
|
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
|
|
||||||
align &= HGETEXT_HORZMASK;
|
align &= HGETEXT_HORZMASK;
|
||||||
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
|
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
|
||||||
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
|
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
|
||||||
|
|
||||||
while(*string)
|
while(*string)
|
||||||
{
|
{
|
||||||
if(*string=='\n')
|
if(*string=='\n')
|
||||||
{
|
{
|
||||||
y += int(fHeight*fScale*fSpacing);
|
y += int(fHeight*fScale*fSpacing);
|
||||||
fx = x;
|
fx = x;
|
||||||
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
|
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
|
||||||
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
|
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i=(unsigned char)*string;
|
i=(unsigned char)*string;
|
||||||
if(!letters[i]) i='?';
|
if(!letters[i]) i='?';
|
||||||
if(letters[i])
|
if(letters[i])
|
||||||
{
|
{
|
||||||
fx += pre[i]*fScale*fProportion;
|
fx += pre[i]*fScale*fProportion;
|
||||||
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
|
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
|
||||||
renderer->RenderQuad(letters[i], 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;
|
fx += (letters[i]->mWidth+post[i]+fTracking)*fScale*fProportion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string++;
|
string++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::printf(float x, float y, int align, const char *format, ...)
|
void hgeFont::printf(float x, float y, int align, const char *format, ...)
|
||||||
{
|
{
|
||||||
//char *pArg=(char *) &format+sizeof(format);
|
//char *pArg=(char *) &format+sizeof(format);
|
||||||
|
|
||||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||||
//buffer[sizeof(buffer)-1]=0;
|
//buffer[sizeof(buffer)-1]=0;
|
||||||
//vsprintf(buffer, format, pArg);
|
//vsprintf(buffer, format, pArg);
|
||||||
va_list list;
|
va_list list;
|
||||||
|
|
||||||
va_start(list, format);
|
va_start(list, format);
|
||||||
vsprintf(buffer, format, list);
|
vsprintf(buffer, format, list);
|
||||||
va_end(list);
|
va_end(list);
|
||||||
|
|
||||||
Render(x,y,align,buffer);
|
Render(x,y,align,buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
|
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
|
||||||
{
|
{
|
||||||
char chr, *pbuf, *prevword, *linestart;
|
char chr, *pbuf, *prevword, *linestart;
|
||||||
int i,lines=0;
|
int i,lines=0;
|
||||||
float tx, ty, hh, ww;
|
float tx, ty, hh, ww;
|
||||||
//char *pArg=(char *) &format+sizeof(format);
|
//char *pArg=(char *) &format+sizeof(format);
|
||||||
|
|
||||||
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
|
||||||
//buffer[sizeof(buffer)-1]=0;
|
//buffer[sizeof(buffer)-1]=0;
|
||||||
//vsprintf(buffer, format, pArg);
|
//vsprintf(buffer, format, pArg);
|
||||||
|
|
||||||
va_list list;
|
va_list list;
|
||||||
|
|
||||||
va_start(list, format);
|
va_start(list, format);
|
||||||
vsprintf(buffer, format, list);
|
vsprintf(buffer, format, list);
|
||||||
va_end(list);
|
va_end(list);
|
||||||
|
|
||||||
|
|
||||||
linestart=buffer;
|
linestart=buffer;
|
||||||
pbuf=buffer;
|
pbuf=buffer;
|
||||||
prevword=0;
|
prevword=0;
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
i=0;
|
i=0;
|
||||||
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
|
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
|
||||||
|
|
||||||
chr=pbuf[i];
|
chr=pbuf[i];
|
||||||
pbuf[i]=0;
|
pbuf[i]=0;
|
||||||
ww=GetStringWidth(linestart);
|
ww=GetStringWidth(linestart);
|
||||||
pbuf[i]=chr;
|
pbuf[i]=chr;
|
||||||
|
|
||||||
if(ww > w)
|
if(ww > w)
|
||||||
{
|
{
|
||||||
if(pbuf==linestart)
|
if(pbuf==linestart)
|
||||||
{
|
{
|
||||||
pbuf[i]='\n';
|
pbuf[i]='\n';
|
||||||
linestart=&pbuf[i+1];
|
linestart=&pbuf[i+1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*prevword='\n';
|
*prevword='\n';
|
||||||
linestart=prevword+1;
|
linestart=prevword+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pbuf[i]=='\n')
|
if(pbuf[i]=='\n')
|
||||||
{
|
{
|
||||||
prevword=&pbuf[i];
|
prevword=&pbuf[i];
|
||||||
linestart=&pbuf[i+1];
|
linestart=&pbuf[i+1];
|
||||||
pbuf=&pbuf[i+1];
|
pbuf=&pbuf[i+1];
|
||||||
lines++;
|
lines++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!pbuf[i]) {lines++;break;}
|
if(!pbuf[i]) {lines++;break;}
|
||||||
|
|
||||||
prevword=&pbuf[i];
|
prevword=&pbuf[i];
|
||||||
pbuf=&pbuf[i+1];
|
pbuf=&pbuf[i+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
tx=x;
|
tx=x;
|
||||||
ty=y;
|
ty=y;
|
||||||
hh=fHeight*fSpacing*fScale*lines;
|
hh=fHeight*fSpacing*fScale*lines;
|
||||||
|
|
||||||
switch(align & HGETEXT_HORZMASK)
|
switch(align & HGETEXT_HORZMASK)
|
||||||
{
|
{
|
||||||
case HGETEXT_LEFT: break;
|
case HGETEXT_LEFT: break;
|
||||||
case HGETEXT_RIGHT: tx+=w; break;
|
case HGETEXT_RIGHT: tx+=w; break;
|
||||||
case HGETEXT_CENTER: tx+=int(w/2); break;
|
case HGETEXT_CENTER: tx+=int(w/2); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(align & HGETEXT_VERTMASK)
|
switch(align & HGETEXT_VERTMASK)
|
||||||
{
|
{
|
||||||
case HGETEXT_TOP: break;
|
case HGETEXT_TOP: break;
|
||||||
case HGETEXT_BOTTOM: ty+=h-hh; break;
|
case HGETEXT_BOTTOM: ty+=h-hh; break;
|
||||||
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
|
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Render(tx,ty,align,buffer);
|
Render(tx,ty,align,buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
float hgeFont::GetStringWidth(const char *string) const
|
float hgeFont::GetStringWidth(const char *string) const
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float linew, w = 0;
|
float linew, w = 0;
|
||||||
|
|
||||||
while(*string)
|
while(*string)
|
||||||
{
|
{
|
||||||
linew = 0;
|
linew = 0;
|
||||||
|
|
||||||
while(*string && *string != '\n')
|
while(*string && *string != '\n')
|
||||||
{
|
{
|
||||||
i=(unsigned char)*string;
|
i=(unsigned char)*string;
|
||||||
if(!letters[i]) i='?';
|
if(!letters[i]) i='?';
|
||||||
if(letters[i])
|
if(letters[i])
|
||||||
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
|
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
|
||||||
|
|
||||||
string++;
|
string++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(linew > w) w = linew;
|
if(linew > w) w = linew;
|
||||||
|
|
||||||
while (*string == '\n' || *string == '\r') string++;
|
while (*string == '\n' || *string == '\r') string++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return w*fScale*fProportion;
|
return w*fScale*fProportion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::SetColor(PIXEL_TYPE col)
|
void hgeFont::SetColor(PIXEL_TYPE col)
|
||||||
{
|
{
|
||||||
dwCol = col;
|
dwCol = col;
|
||||||
|
|
||||||
for(int i=0; i<256; i++)
|
for(int i=0; i<256; i++)
|
||||||
if(letters[i])
|
if(letters[i])
|
||||||
letters[i]->SetColor(col);
|
letters[i]->SetColor(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::SetZ(float z)
|
void hgeFont::SetZ(float z)
|
||||||
{
|
{
|
||||||
fZ = z;
|
fZ = z;
|
||||||
|
|
||||||
//for(int i=0; i<256; i++)
|
//for(int i=0; i<256; i++)
|
||||||
// if(letters[i])
|
// if(letters[i])
|
||||||
// letters[i]->SetZ(z);
|
// letters[i]->SetZ(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeFont::SetBlendMode(int blend)
|
void hgeFont::SetBlendMode(int blend)
|
||||||
{
|
{
|
||||||
nBlend = blend;
|
nBlend = blend;
|
||||||
|
|
||||||
//for(int i=0; i<256; i++)
|
//for(int i=0; i<256; i++)
|
||||||
// if(letters[i])
|
// if(letters[i])
|
||||||
// letters[i]->SetBlendMode(blend);
|
// letters[i]->SetBlendMode(blend);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *hgeFont::_get_line(char *file, char *line)
|
char *hgeFont::_get_line(char *file, char *line)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
if(!file[i]) return 0;
|
if(!file[i]) return 0;
|
||||||
|
|
||||||
while(file[i] && file[i]!='\n' && file[i]!='\r')
|
while(file[i] && file[i]!='\n' && file[i]!='\r')
|
||||||
{
|
{
|
||||||
line[i]=file[i];
|
line[i]=file[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
line[i]=0;
|
line[i]=0;
|
||||||
|
|
||||||
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
|
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
|
||||||
|
|
||||||
return file + i;
|
return file + i;
|
||||||
}
|
}
|
||||||
|
|||||||
+306
-306
@@ -1,306 +1,306 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeParticleSystem helper class implementation
|
** hgeParticleSystem helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../include/JGE.h"
|
#include "../../include/JGE.h"
|
||||||
#include "../../include/JTypes.h"
|
#include "../../include/JTypes.h"
|
||||||
#include "../../include/JRenderer.h"
|
#include "../../include/JRenderer.h"
|
||||||
#include "../../include/JFileSystem.h"
|
#include "../../include/JFileSystem.h"
|
||||||
|
|
||||||
#include "../../include/hge/hgeparticle.h"
|
#include "../../include/hge/hgeparticle.h"
|
||||||
|
|
||||||
|
|
||||||
//HGE *hgeParticleSystem::hge=0;
|
//HGE *hgeParticleSystem::hge=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** Core functions implementation: random number generation
|
** Core functions implementation: random number generation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
unsigned int g_seed=0;
|
unsigned int g_seed=0;
|
||||||
|
|
||||||
void Random_Seed(int seed)
|
void Random_Seed(int seed)
|
||||||
{
|
{
|
||||||
if(!seed) g_seed=JGE::GetInstance()->GetTime();
|
if(!seed) g_seed=JGE::GetInstance()->GetTime();
|
||||||
else g_seed=seed;
|
else g_seed=seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Random_Int(int min, int max)
|
int Random_Int(int min, int max)
|
||||||
{
|
{
|
||||||
g_seed=214013*g_seed+2531011;
|
g_seed=214013*g_seed+2531011;
|
||||||
return min+(g_seed ^ g_seed>>15)%(max-min+1);
|
return min+(g_seed ^ g_seed>>15)%(max-min+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Random_Float(float min, float max)
|
float Random_Float(float min, float max)
|
||||||
{
|
{
|
||||||
g_seed=214013*g_seed+2531011;
|
g_seed=214013*g_seed+2531011;
|
||||||
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
|
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
|
||||||
{
|
{
|
||||||
//void *psi;
|
//void *psi;
|
||||||
//hgeParticleSystemInfo psi;
|
//hgeParticleSystemInfo psi;
|
||||||
|
|
||||||
JFileSystem* fileSys = JFileSystem::GetInstance();
|
JFileSystem* fileSys = JFileSystem::GetInstance();
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//hge=hgeCreate(HGE_VERSION);
|
||||||
|
|
||||||
//psi=hge->Resource_Load(filename);
|
//psi=hge->Resource_Load(filename);
|
||||||
if (!fileSys->OpenFile(filename)) return;
|
if (!fileSys->OpenFile(filename)) return;
|
||||||
|
|
||||||
//if(!psi) return;
|
//if(!psi) return;
|
||||||
|
|
||||||
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||||
//hge->Resource_Free(psi);
|
//hge->Resource_Free(psi);
|
||||||
|
|
||||||
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
// Skip reading the pointer as it may be larger than 4 bytes in the structure
|
||||||
void *dummyPointer;
|
void *dummyPointer;
|
||||||
fileSys->ReadFile(&dummyPointer, 4);
|
fileSys->ReadFile(&dummyPointer, 4);
|
||||||
// we're actually trying to read more than the file size now, but it's no problem.
|
// 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
|
// Note that this fix is only to avoid the largest problems, filling a structure
|
||||||
// by directly reading a file, is really a bad idea ...
|
// by directly reading a file, is really a bad idea ...
|
||||||
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
|
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
|
||||||
fileSys->CloseFile();
|
fileSys->CloseFile();
|
||||||
|
|
||||||
info.sprite=sprite;
|
info.sprite=sprite;
|
||||||
// info.fGravityMin *= 100;
|
// info.fGravityMin *= 100;
|
||||||
// info.fGravityMax *= 100;
|
// info.fGravityMax *= 100;
|
||||||
// info.fSpeedMin *= 100;
|
// info.fSpeedMin *= 100;
|
||||||
// info.fSpeedMax *= 100;
|
// info.fSpeedMax *= 100;
|
||||||
|
|
||||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||||
fTx=fTy=0;
|
fTx=fTy=0;
|
||||||
|
|
||||||
fEmissionResidue=0.0f;
|
fEmissionResidue=0.0f;
|
||||||
nParticlesAlive=0;
|
nParticlesAlive=0;
|
||||||
fAge=-2.0;
|
fAge=-2.0;
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
|
|
||||||
rectBoundingBox.Clear();
|
rectBoundingBox.Clear();
|
||||||
bUpdateBoundingBox=false;
|
bUpdateBoundingBox=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
|
||||||
{
|
{
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//hge=hgeCreate(HGE_VERSION);
|
||||||
|
|
||||||
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
|
||||||
|
|
||||||
vecLocation.x=vecPrevLocation.x=0.0f;
|
vecLocation.x=vecPrevLocation.x=0.0f;
|
||||||
vecLocation.y=vecPrevLocation.y=0.0f;
|
vecLocation.y=vecPrevLocation.y=0.0f;
|
||||||
fTx=fTy=0;
|
fTx=fTy=0;
|
||||||
|
|
||||||
fEmissionResidue=0.0f;
|
fEmissionResidue=0.0f;
|
||||||
nParticlesAlive=0;
|
nParticlesAlive=0;
|
||||||
fAge=-2.0;
|
fAge=-2.0;
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
|
|
||||||
rectBoundingBox.Clear();
|
rectBoundingBox.Clear();
|
||||||
bUpdateBoundingBox=false;
|
bUpdateBoundingBox=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
|
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
|
||||||
{
|
{
|
||||||
memcpy(this, &ps, sizeof(hgeParticleSystem));
|
memcpy(this, &ps, sizeof(hgeParticleSystem));
|
||||||
//hge=hgeCreate(HGE_VERSION);
|
//hge=hgeCreate(HGE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::Update(float fDeltaTime)
|
void hgeParticleSystem::Update(float fDeltaTime)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float ang;
|
float ang;
|
||||||
hgeVector vecAccel, vecAccel2;
|
hgeVector vecAccel, vecAccel2;
|
||||||
|
|
||||||
if(fAge >= 0)
|
if(fAge >= 0)
|
||||||
{
|
{
|
||||||
fAge += fDeltaTime;
|
fAge += fDeltaTime;
|
||||||
if(fAge >= info.fLifetime) fAge = -2.0f;
|
if(fAge >= info.fLifetime) fAge = -2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTimer += fDeltaTime;
|
mTimer += fDeltaTime;
|
||||||
if (mTimer < 0.01f)
|
if (mTimer < 0.01f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fDeltaTime = mTimer;
|
fDeltaTime = mTimer;
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
// update all alive particles
|
// update all alive particles
|
||||||
|
|
||||||
if(bUpdateBoundingBox) rectBoundingBox.Clear();
|
if(bUpdateBoundingBox) rectBoundingBox.Clear();
|
||||||
|
|
||||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||||
while(particle != mParticleBuffer.end())
|
while(particle != mParticleBuffer.end())
|
||||||
{
|
{
|
||||||
particle->fAge += fDeltaTime;
|
particle->fAge += fDeltaTime;
|
||||||
if(particle->fAge >= particle->fTerminalAge)
|
if(particle->fAge >= particle->fTerminalAge)
|
||||||
{
|
{
|
||||||
nParticlesAlive--;
|
nParticlesAlive--;
|
||||||
++particle;
|
++particle;
|
||||||
mParticleBuffer.pop_front();
|
mParticleBuffer.pop_front();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
vecAccel = particle->vecLocation-vecLocation;
|
vecAccel = particle->vecLocation-vecLocation;
|
||||||
vecAccel.Normalize();
|
vecAccel.Normalize();
|
||||||
vecAccel2 = vecAccel;
|
vecAccel2 = vecAccel;
|
||||||
vecAccel *= particle->fRadialAccel;
|
vecAccel *= particle->fRadialAccel;
|
||||||
|
|
||||||
// vecAccel2.Rotate(M_PI_2);
|
// vecAccel2.Rotate(M_PI_2);
|
||||||
// the following is faster
|
// the following is faster
|
||||||
ang = vecAccel2.x;
|
ang = vecAccel2.x;
|
||||||
vecAccel2.x = -vecAccel2.y;
|
vecAccel2.x = -vecAccel2.y;
|
||||||
vecAccel2.y = ang;
|
vecAccel2.y = ang;
|
||||||
|
|
||||||
vecAccel2 *= particle->fTangentialAccel;
|
vecAccel2 *= particle->fTangentialAccel;
|
||||||
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
|
||||||
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
|
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
|
||||||
|
|
||||||
//par->vecVelocity.y = 0.1f;
|
//par->vecVelocity.y = 0.1f;
|
||||||
particle->vecLocation += particle->vecVelocity;
|
particle->vecLocation += particle->vecVelocity;
|
||||||
|
|
||||||
particle->fSpin += particle->fSpinDelta*fDeltaTime;
|
particle->fSpin += particle->fSpinDelta*fDeltaTime;
|
||||||
particle->fSize += particle->fSizeDelta*fDeltaTime;
|
particle->fSize += particle->fSizeDelta*fDeltaTime;
|
||||||
particle->colColor += particle->colColorDelta*fDeltaTime;
|
particle->colColor += particle->colColorDelta*fDeltaTime;
|
||||||
|
|
||||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
|
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
|
||||||
|
|
||||||
++particle;
|
++particle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate new particles
|
// generate new particles
|
||||||
|
|
||||||
if(fAge != -2.0f)
|
if(fAge != -2.0f)
|
||||||
{
|
{
|
||||||
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
|
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
|
||||||
int nParticlesCreated = (unsigned int)fParticlesNeeded;
|
int nParticlesCreated = (unsigned int)fParticlesNeeded;
|
||||||
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
|
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
|
||||||
|
|
||||||
for(i=0; i<nParticlesCreated; i++)
|
for(i=0; i<nParticlesCreated; i++)
|
||||||
{
|
{
|
||||||
if(nParticlesAlive>=MAX_PARTICLES) break;
|
if(nParticlesAlive>=MAX_PARTICLES) break;
|
||||||
|
|
||||||
hgeParticle newParticle;
|
hgeParticle newParticle;
|
||||||
newParticle.fAge = 0.0f;
|
newParticle.fAge = 0.0f;
|
||||||
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
|
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
|
||||||
|
|
||||||
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
|
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
|
||||||
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
|
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
|
||||||
newParticle.vecLocation.y += 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;
|
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;
|
if(info.bRelative) ang += (vecPrevLocation-vecLocation).Angle()+M_PI_2;
|
||||||
newParticle.vecVelocity.x = cosf(ang);
|
newParticle.vecVelocity.x = cosf(ang);
|
||||||
newParticle.vecVelocity.y = sinf(ang);
|
newParticle.vecVelocity.y = sinf(ang);
|
||||||
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
|
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
|
||||||
|
|
||||||
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
|
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
|
||||||
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
|
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
|
||||||
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
|
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
|
||||||
|
|
||||||
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
|
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
|
||||||
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
|
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
|
||||||
|
|
||||||
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
|
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
|
||||||
newParticle.fSpinDelta = (info.fSpinEnd-newParticle.fSpin) / newParticle.fTerminalAge;
|
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.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.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.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.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.r = (info.colColorEnd.r-newParticle.colColor.r) / newParticle.fTerminalAge;
|
||||||
newParticle.colColorDelta.g = (info.colColorEnd.g-newParticle.colColor.g) / 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.b = (info.colColorEnd.b-newParticle.colColor.b) / newParticle.fTerminalAge;
|
||||||
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
|
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
|
||||||
|
|
||||||
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
|
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
|
||||||
|
|
||||||
mParticleBuffer.push_back(newParticle);
|
mParticleBuffer.push_back(newParticle);
|
||||||
++nParticlesAlive;
|
++nParticlesAlive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vecPrevLocation=vecLocation;
|
vecPrevLocation=vecLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
|
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
|
||||||
{
|
{
|
||||||
float dx,dy;
|
float dx,dy;
|
||||||
|
|
||||||
if(bMoveParticles)
|
if(bMoveParticles)
|
||||||
{
|
{
|
||||||
dx=x-vecLocation.x;
|
dx=x-vecLocation.x;
|
||||||
dy=y-vecLocation.y;
|
dy=y-vecLocation.y;
|
||||||
|
|
||||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||||
for (; particle != mParticleBuffer.end(); ++particle)
|
for (; particle != mParticleBuffer.end(); ++particle)
|
||||||
{
|
{
|
||||||
particle->vecLocation.x += dx;
|
particle->vecLocation.x += dx;
|
||||||
particle->vecLocation.y += dy;
|
particle->vecLocation.y += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
vecPrevLocation.x=vecPrevLocation.x + dx;
|
vecPrevLocation.x=vecPrevLocation.x + dx;
|
||||||
vecPrevLocation.y=vecPrevLocation.y + dy;
|
vecPrevLocation.y=vecPrevLocation.y + dy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
|
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
|
||||||
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
|
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
|
||||||
}
|
}
|
||||||
|
|
||||||
vecLocation.x=x;
|
vecLocation.x=x;
|
||||||
vecLocation.y=y;
|
vecLocation.y=y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::FireAt(float x, float y)
|
void hgeParticleSystem::FireAt(float x, float y)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
MoveTo(x,y);
|
MoveTo(x,y);
|
||||||
Fire();
|
Fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::Fire()
|
void hgeParticleSystem::Fire()
|
||||||
{
|
{
|
||||||
mTimer = 0.0f;
|
mTimer = 0.0f;
|
||||||
|
|
||||||
if(info.fLifetime==-1.0f) fAge=-1.0f;
|
if(info.fLifetime==-1.0f) fAge=-1.0f;
|
||||||
else fAge=0.0f;
|
else fAge=0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::Stop(bool bKillParticles)
|
void hgeParticleSystem::Stop(bool bKillParticles)
|
||||||
{
|
{
|
||||||
fAge=-2.0f;
|
fAge=-2.0f;
|
||||||
if(bKillParticles)
|
if(bKillParticles)
|
||||||
{
|
{
|
||||||
nParticlesAlive=0;
|
nParticlesAlive=0;
|
||||||
mParticleBuffer.clear();
|
mParticleBuffer.clear();
|
||||||
rectBoundingBox.Clear();
|
rectBoundingBox.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleSystem::Render()
|
void hgeParticleSystem::Render()
|
||||||
{
|
{
|
||||||
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
ParticleBuffer::iterator particle = mParticleBuffer.begin();
|
||||||
for (;particle != mParticleBuffer.end(); ++particle)
|
for (;particle != mParticleBuffer.end(); ++particle)
|
||||||
{
|
{
|
||||||
info.sprite->SetColor(particle->colColor.GetHWColor());
|
info.sprite->SetColor(particle->colColor.GetHWColor());
|
||||||
JRenderer::GetInstance()->RenderQuad(
|
JRenderer::GetInstance()->RenderQuad(
|
||||||
info.sprite,
|
info.sprite,
|
||||||
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
|
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
|
||||||
particle->fSpin * particle->fAge,
|
particle->fSpin * particle->fAge,
|
||||||
particle->fSize, particle->fSize);
|
particle->fSize, particle->fSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+91
-91
@@ -1,91 +1,91 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeParticleManager helper class implementation
|
** hgeParticleManager helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../../include/hge/hgeparticle.h"
|
#include "../../include/hge/hgeparticle.h"
|
||||||
|
|
||||||
|
|
||||||
hgeParticleManager::hgeParticleManager()
|
hgeParticleManager::hgeParticleManager()
|
||||||
{
|
{
|
||||||
nPS=0;
|
nPS=0;
|
||||||
tX=tY=0.0f;
|
tX=tY=0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleManager::~hgeParticleManager()
|
hgeParticleManager::~hgeParticleManager()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++) delete psList[i];
|
for(i=0;i<nPS;i++) delete psList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleManager::Update(float dt)
|
void hgeParticleManager::Update(float dt)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++)
|
for(i=0;i<nPS;i++)
|
||||||
{
|
{
|
||||||
psList[i]->Update(dt);
|
psList[i]->Update(dt);
|
||||||
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
|
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
|
||||||
{
|
{
|
||||||
delete psList[i];
|
delete psList[i];
|
||||||
psList[i]=psList[nPS-1];
|
psList[i]=psList[nPS-1];
|
||||||
nPS--;
|
nPS--;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleManager::Render()
|
void hgeParticleManager::Render()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++) psList[i]->Render();
|
for(i=0;i<nPS;i++) psList[i]->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
|
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
|
||||||
{
|
{
|
||||||
if(nPS==MAX_PSYSTEMS) return 0;
|
if(nPS==MAX_PSYSTEMS) return 0;
|
||||||
psList[nPS]=new hgeParticleSystem(psi);
|
psList[nPS]=new hgeParticleSystem(psi);
|
||||||
psList[nPS]->FireAt(x,y);
|
psList[nPS]->FireAt(x,y);
|
||||||
psList[nPS]->Transpose(tX,tY);
|
psList[nPS]->Transpose(tX,tY);
|
||||||
nPS++;
|
nPS++;
|
||||||
return psList[nPS-1];
|
return psList[nPS-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
|
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
|
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleManager::Transpose(float x, float y)
|
void hgeParticleManager::Transpose(float x, float y)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
|
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
|
||||||
tX=x; tY=y;
|
tX=x; tY=y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
|
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++)
|
for(i=0;i<nPS;i++)
|
||||||
{
|
{
|
||||||
if(psList[i]==ps)
|
if(psList[i]==ps)
|
||||||
{
|
{
|
||||||
delete psList[i];
|
delete psList[i];
|
||||||
psList[i]=psList[nPS-1];
|
psList[i]=psList[nPS-1];
|
||||||
nPS--;
|
nPS--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hgeParticleManager::KillAll()
|
void hgeParticleManager::KillAll()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<nPS;i++) delete psList[i];
|
for(i=0;i<nPS;i++) delete psList[i];
|
||||||
nPS=0;
|
nPS=0;
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-45
@@ -1,45 +1,45 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeRect helper class implementation
|
** hgeRect helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../../include/hge/hgerect.h"
|
#include "../../include/hge/hgerect.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
void hgeRect::Encapsulate(float x, float y)
|
void hgeRect::Encapsulate(float x, float y)
|
||||||
{
|
{
|
||||||
if(bClean)
|
if(bClean)
|
||||||
{
|
{
|
||||||
x1=x2=x;
|
x1=x2=x;
|
||||||
y1=y2=y;
|
y1=y2=y;
|
||||||
bClean=false;
|
bClean=false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(x<x1) x1=x;
|
if(x<x1) x1=x;
|
||||||
if(x>x2) x2=x;
|
if(x>x2) x2=x;
|
||||||
if(y<y1) y1=y;
|
if(y<y1) y1=y;
|
||||||
if(y>y2) y2=y;
|
if(y>y2) y2=y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hgeRect::TestPoint(float x, float y) const
|
bool hgeRect::TestPoint(float x, float y) const
|
||||||
{
|
{
|
||||||
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
|
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hgeRect::Intersect(const hgeRect *rect) const
|
bool hgeRect::Intersect(const hgeRect *rect) const
|
||||||
{
|
{
|
||||||
if(fabs(x1 + x2 - rect->x1 - rect->x2) < (x2 - x1 + rect->x2 - rect->x1))
|
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))
|
if(fabs(y1 + y2 - rect->y1 - rect->y2) < (y2 - y1 + rect->y2 - rect->y1))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+69
-69
@@ -1,69 +1,69 @@
|
|||||||
/*
|
/*
|
||||||
** Haaf's Game Engine 1.7
|
** Haaf's Game Engine 1.7
|
||||||
** Copyright (C) 2003-2007, Relish Games
|
** Copyright (C) 2003-2007, Relish Games
|
||||||
** hge.relishgames.com
|
** hge.relishgames.com
|
||||||
**
|
**
|
||||||
** hgeVector helper class implementation
|
** hgeVector helper class implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../../include/hge/hgevector.h"
|
#include "../../include/hge/hgevector.h"
|
||||||
|
|
||||||
float InvSqrt(float x)
|
float InvSqrt(float x)
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int intPart;
|
int intPart;
|
||||||
float floatPart;
|
float floatPart;
|
||||||
} convertor;
|
} convertor;
|
||||||
|
|
||||||
convertor.floatPart = x;
|
convertor.floatPart = x;
|
||||||
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
|
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
|
||||||
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
|
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
hgeVector *hgeVector::Normalize()
|
hgeVector *hgeVector::Normalize()
|
||||||
{
|
{
|
||||||
float lenRcp;
|
float lenRcp;
|
||||||
|
|
||||||
lenRcp=sqrtf(Dot(this));
|
lenRcp=sqrtf(Dot(this));
|
||||||
|
|
||||||
if(lenRcp)
|
if(lenRcp)
|
||||||
{
|
{
|
||||||
lenRcp=1.0f/lenRcp;
|
lenRcp=1.0f/lenRcp;
|
||||||
|
|
||||||
x*=lenRcp;
|
x*=lenRcp;
|
||||||
y*=lenRcp;
|
y*=lenRcp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float hgeVector::Angle(const hgeVector *v) const
|
float hgeVector::Angle(const hgeVector *v) const
|
||||||
{
|
{
|
||||||
if(v)
|
if(v)
|
||||||
{
|
{
|
||||||
hgeVector s=*this, t=*v;
|
hgeVector s=*this, t=*v;
|
||||||
|
|
||||||
s.Normalize(); t.Normalize();
|
s.Normalize(); t.Normalize();
|
||||||
return acosf(s.Dot(&t));
|
return acosf(s.Dot(&t));
|
||||||
}
|
}
|
||||||
else return atan2f(y, x);
|
else return atan2f(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeVector *hgeVector::Rotate(float a)
|
hgeVector *hgeVector::Rotate(float a)
|
||||||
{
|
{
|
||||||
hgeVector v;
|
hgeVector v;
|
||||||
|
|
||||||
v.x=x*cosf(a) - y*sinf(a);
|
v.x=x*cosf(a) - y*sinf(a);
|
||||||
v.y=x*sinf(a) + y*cosf(a);
|
v.y=x*sinf(a) + y*cosf(a);
|
||||||
|
|
||||||
x=v.x; y=v.y;
|
x=v.x; y=v.y;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +1,67 @@
|
|||||||
Change in 1.01e (12 feb 05)
|
Change in 1.01e (12 feb 05)
|
||||||
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
|
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
|
||||||
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
|
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
|
||||||
|
|
||||||
Change in 1.01b (20 may 04)
|
Change in 1.01b (20 may 04)
|
||||||
- Integrate patch from Debian package (submited by Mark Brown)
|
- Integrate patch from Debian package (submited by Mark Brown)
|
||||||
- Add tools mztools from Xavier Roche
|
- Add tools mztools from Xavier Roche
|
||||||
|
|
||||||
Change in 1.01 (8 may 04)
|
Change in 1.01 (8 may 04)
|
||||||
- fix buffer overrun risk in unzip.c (Xavier Roche)
|
- fix buffer overrun risk in unzip.c (Xavier Roche)
|
||||||
- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
|
- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
|
||||||
|
|
||||||
Change in 1.00: (10 sept 03)
|
Change in 1.00: (10 sept 03)
|
||||||
- rename to 1.00
|
- rename to 1.00
|
||||||
- cosmetic code change
|
- cosmetic code change
|
||||||
|
|
||||||
Change in 0.22: (19 May 03)
|
Change in 0.22: (19 May 03)
|
||||||
- crypting support (unless you define NOCRYPT)
|
- crypting support (unless you define NOCRYPT)
|
||||||
- append file in existing zipfile
|
- append file in existing zipfile
|
||||||
|
|
||||||
Change in 0.21: (10 Mar 03)
|
Change in 0.21: (10 Mar 03)
|
||||||
- bug fixes
|
- bug fixes
|
||||||
|
|
||||||
Change in 0.17: (27 Jan 02)
|
Change in 0.17: (27 Jan 02)
|
||||||
- bug fixes
|
- bug fixes
|
||||||
|
|
||||||
Change in 0.16: (19 Jan 02)
|
Change in 0.16: (19 Jan 02)
|
||||||
- Support of ioapi for virtualize zip file access
|
- Support of ioapi for virtualize zip file access
|
||||||
|
|
||||||
Change in 0.15: (19 Mar 98)
|
Change in 0.15: (19 Mar 98)
|
||||||
- fix memory leak in minizip.c
|
- fix memory leak in minizip.c
|
||||||
|
|
||||||
Change in 0.14: (10 Mar 98)
|
Change in 0.14: (10 Mar 98)
|
||||||
- fix bugs in minizip.c sample for zipping big file
|
- fix bugs in minizip.c sample for zipping big file
|
||||||
- fix problem in month in date handling
|
- fix problem in month in date handling
|
||||||
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
|
- fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for
|
||||||
comment handling
|
comment handling
|
||||||
|
|
||||||
Change in 0.13: (6 Mar 98)
|
Change in 0.13: (6 Mar 98)
|
||||||
- fix bugs in zip.c
|
- fix bugs in zip.c
|
||||||
- add real minizip sample
|
- add real minizip sample
|
||||||
|
|
||||||
Change in 0.12: (4 Mar 98)
|
Change in 0.12: (4 Mar 98)
|
||||||
- add zip.c and zip.h for creates .zip file
|
- add zip.c and zip.h for creates .zip file
|
||||||
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
|
- fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
|
||||||
- fix miniunz.c for file without specific record for directory
|
- fix miniunz.c for file without specific record for directory
|
||||||
|
|
||||||
Change in 0.11: (3 Mar 98)
|
Change in 0.11: (3 Mar 98)
|
||||||
- fix bug in unzGetCurrentFileInfo for get extra field and comment
|
- fix bug in unzGetCurrentFileInfo for get extra field and comment
|
||||||
- enhance miniunz sample, remove the bad unztst.c sample
|
- enhance miniunz sample, remove the bad unztst.c sample
|
||||||
|
|
||||||
Change in 0.10: (2 Mar 98)
|
Change in 0.10: (2 Mar 98)
|
||||||
- fix bug in unzReadCurrentFile
|
- fix bug in unzReadCurrentFile
|
||||||
- rename unzip* to unz* function and structure
|
- rename unzip* to unz* function and structure
|
||||||
- remove Windows-like hungary notation variable name
|
- remove Windows-like hungary notation variable name
|
||||||
- modify some structure in unzip.h
|
- modify some structure in unzip.h
|
||||||
- add somes comment in source
|
- add somes comment in source
|
||||||
- remove unzipGetcCurrentFile function
|
- remove unzipGetcCurrentFile function
|
||||||
- replace ZUNZEXPORT by ZEXPORT
|
- replace ZUNZEXPORT by ZEXPORT
|
||||||
- add unzGetLocalExtrafield for get the local extrafield info
|
- add unzGetLocalExtrafield for get the local extrafield info
|
||||||
- add a new sample, miniunz.c
|
- add a new sample, miniunz.c
|
||||||
|
|
||||||
Change in 0.4: (25 Feb 98)
|
Change in 0.4: (25 Feb 98)
|
||||||
- suppress the type unzipFileInZip.
|
- suppress the type unzipFileInZip.
|
||||||
Only on file in the zipfile can be open at the same time
|
Only on file in the zipfile can be open at the same time
|
||||||
- fix somes typo in code
|
- fix somes typo in code
|
||||||
- added tm_unz structure in unzip_file_info (date/time in readable format)
|
- added tm_unz structure in unzip_file_info (date/time in readable format)
|
||||||
|
|||||||
+25
-25
@@ -1,25 +1,25 @@
|
|||||||
CC=cc
|
CC=cc
|
||||||
CFLAGS=-O -I../..
|
CFLAGS=-O -I../..
|
||||||
|
|
||||||
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a
|
||||||
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c $(CFLAGS) $*.c
|
$(CC) -c $(CFLAGS) $*.c
|
||||||
|
|
||||||
all: miniunz minizip
|
all: miniunz minizip
|
||||||
|
|
||||||
miniunz: $(UNZ_OBJS)
|
miniunz: $(UNZ_OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
|
||||||
|
|
||||||
minizip: $(ZIP_OBJS)
|
minizip: $(ZIP_OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
|
||||||
|
|
||||||
test: miniunz minizip
|
test: miniunz minizip
|
||||||
./minizip test readme.txt
|
./minizip test readme.txt
|
||||||
./miniunz -l test.zip
|
./miniunz -l test.zip
|
||||||
mv readme.txt readme.old
|
mv readme.txt readme.old
|
||||||
./miniunz test.zip
|
./miniunz test.zip
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
/bin/rm -f *.o *~ minizip miniunz
|
/bin/rm -f *.o *~ minizip miniunz
|
||||||
|
|||||||
+132
-132
@@ -1,132 +1,132 @@
|
|||||||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||||
|
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This code is a modified version of crypting code in Infozip distribution
|
This code is a modified version of crypting code in Infozip distribution
|
||||||
|
|
||||||
The encryption/decryption parts of this source code (as opposed to the
|
The encryption/decryption parts of this source code (as opposed to the
|
||||||
non-echoing password parts) were originally written in Europe. The
|
non-echoing password parts) were originally written in Europe. The
|
||||||
whole source package can be freely distributed, including from the USA.
|
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.)
|
(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
|
This encryption code is a direct transcription of the algorithm from
|
||||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||||
version without encryption capabilities).
|
version without encryption capabilities).
|
||||||
|
|
||||||
If you don't need crypting in your application, just define symbols
|
If you don't need crypting in your application, just define symbols
|
||||||
NOCRYPT and NOUNCRYPT.
|
NOCRYPT and NOUNCRYPT.
|
||||||
|
|
||||||
This code support the "Traditional PKWARE Encryption".
|
This code support the "Traditional PKWARE Encryption".
|
||||||
|
|
||||||
The new AES encryption added on Zip format by Winzip (see the page
|
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
|
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||||
Encryption is not supported.
|
Encryption is not supported.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Return the next byte in the pseudo-random sequence
|
* Return the next byte in the pseudo-random sequence
|
||||||
*/
|
*/
|
||||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||||
{
|
{
|
||||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||||
* unpredictable manner on 16-bit systems; not a problem
|
* unpredictable manner on 16-bit systems; not a problem
|
||||||
* with any known compiler so far, though */
|
* with any known compiler so far, though */
|
||||||
|
|
||||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Update the encryption keys with the next byte of plain text
|
* 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)
|
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||||
{
|
{
|
||||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||||
{
|
{
|
||||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Initialize the encryption keys and the random header according to
|
* Initialize the encryption keys and the random header according to
|
||||||
* the given password.
|
* the given password.
|
||||||
*/
|
*/
|
||||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||||
{
|
{
|
||||||
*(pkeys+0) = 305419896L;
|
*(pkeys+0) = 305419896L;
|
||||||
*(pkeys+1) = 591751049L;
|
*(pkeys+1) = 591751049L;
|
||||||
*(pkeys+2) = 878082192L;
|
*(pkeys+2) = 878082192L;
|
||||||
while (*passwd != '\0') {
|
while (*passwd != '\0') {
|
||||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||||
passwd++;
|
passwd++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||||
|
|
||||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||||
|
|
||||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||||
|
|
||||||
#define RAND_HEAD_LEN 12
|
#define RAND_HEAD_LEN 12
|
||||||
/* "last resort" source for second part of crypt seed pattern */
|
/* "last resort" source for second part of crypt seed pattern */
|
||||||
# ifndef ZCR_SEED2
|
# ifndef ZCR_SEED2
|
||||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||||
const char *passwd; /* password string */
|
const char *passwd; /* password string */
|
||||||
unsigned char *buf; /* where to write header */
|
unsigned char *buf; /* where to write header */
|
||||||
int bufSize;
|
int bufSize;
|
||||||
unsigned long* pkeys;
|
unsigned long* pkeys;
|
||||||
const unsigned long* pcrc_32_tab;
|
const unsigned long* pcrc_32_tab;
|
||||||
unsigned long crcForCrypting;
|
unsigned long crcForCrypting;
|
||||||
{
|
{
|
||||||
int n; /* index in random header */
|
int n; /* index in random header */
|
||||||
int t; /* temporary */
|
int t; /* temporary */
|
||||||
int c; /* random byte */
|
int c; /* random byte */
|
||||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||||
static unsigned calls = 0; /* ensure different random header each time */
|
static unsigned calls = 0; /* ensure different random header each time */
|
||||||
|
|
||||||
if (bufSize<RAND_HEAD_LEN)
|
if (bufSize<RAND_HEAD_LEN)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||||
* output of rand() to get less predictability, since rand() is
|
* output of rand() to get less predictability, since rand() is
|
||||||
* often poorly implemented.
|
* often poorly implemented.
|
||||||
*/
|
*/
|
||||||
if (++calls == 1)
|
if (++calls == 1)
|
||||||
{
|
{
|
||||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||||
}
|
}
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
{
|
{
|
||||||
c = (rand() >> 7) & 0xff;
|
c = (rand() >> 7) & 0xff;
|
||||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||||
}
|
}
|
||||||
/* Encrypt random header (last two bytes is high word of crc) */
|
/* Encrypt random header (last two bytes is high word of crc) */
|
||||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||||
{
|
{
|
||||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
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 >> 16) & 0xff, t);
|
||||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+177
-177
@@ -1,177 +1,177 @@
|
|||||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||||
|
|
||||||
#ifndef SEEK_CUR
|
#ifndef SEEK_CUR
|
||||||
#define SEEK_CUR 1
|
#define SEEK_CUR 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SEEK_END
|
#ifndef SEEK_END
|
||||||
#define SEEK_END 2
|
#define SEEK_END 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SEEK_SET
|
#ifndef SEEK_SET
|
||||||
#define SEEK_SET 0
|
#define SEEK_SET 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
voidpf ZCALLBACK fopen_file_func OF((
|
voidpf ZCALLBACK fopen_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
int mode));
|
int mode));
|
||||||
|
|
||||||
uLong ZCALLBACK fread_file_func OF((
|
uLong ZCALLBACK fread_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
void* buf,
|
void* buf,
|
||||||
uLong size));
|
uLong size));
|
||||||
|
|
||||||
uLong ZCALLBACK fwrite_file_func OF((
|
uLong ZCALLBACK fwrite_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
const void* buf,
|
const void* buf,
|
||||||
uLong size));
|
uLong size));
|
||||||
|
|
||||||
long ZCALLBACK ftell_file_func OF((
|
long ZCALLBACK ftell_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
long ZCALLBACK fseek_file_func OF((
|
long ZCALLBACK fseek_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
uLong offset,
|
uLong offset,
|
||||||
int origin));
|
int origin));
|
||||||
|
|
||||||
int ZCALLBACK fclose_file_func OF((
|
int ZCALLBACK fclose_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
int ZCALLBACK ferror_file_func OF((
|
int ZCALLBACK ferror_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
|
|
||||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
const char* filename;
|
const char* filename;
|
||||||
int mode;
|
int mode;
|
||||||
{
|
{
|
||||||
FILE* file = NULL;
|
FILE* file = NULL;
|
||||||
const char* mode_fopen = NULL;
|
const char* mode_fopen = NULL;
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||||
mode_fopen = "rb";
|
mode_fopen = "rb";
|
||||||
else
|
else
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||||
mode_fopen = "r+b";
|
mode_fopen = "r+b";
|
||||||
else
|
else
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||||
mode_fopen = "wb";
|
mode_fopen = "wb";
|
||||||
|
|
||||||
if ((filename!=NULL) && (mode_fopen != NULL))
|
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||||
file = fopen(filename, mode_fopen);
|
file = fopen(filename, mode_fopen);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
void* buf;
|
void* buf;
|
||||||
uLong size;
|
uLong size;
|
||||||
{
|
{
|
||||||
uLong ret;
|
uLong ret;
|
||||||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
const void* buf;
|
const void* buf;
|
||||||
uLong size;
|
uLong size;
|
||||||
{
|
{
|
||||||
uLong ret;
|
uLong ret;
|
||||||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ZCALLBACK ftell_file_func (opaque, stream)
|
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
ret = ftell((FILE *)stream);
|
ret = ftell((FILE *)stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
uLong offset;
|
uLong offset;
|
||||||
int origin;
|
int origin;
|
||||||
{
|
{
|
||||||
int fseek_origin=0;
|
int fseek_origin=0;
|
||||||
long ret;
|
long ret;
|
||||||
switch (origin)
|
switch (origin)
|
||||||
{
|
{
|
||||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||||
fseek_origin = SEEK_CUR;
|
fseek_origin = SEEK_CUR;
|
||||||
break;
|
break;
|
||||||
case ZLIB_FILEFUNC_SEEK_END :
|
case ZLIB_FILEFUNC_SEEK_END :
|
||||||
fseek_origin = SEEK_END;
|
fseek_origin = SEEK_END;
|
||||||
break;
|
break;
|
||||||
case ZLIB_FILEFUNC_SEEK_SET :
|
case ZLIB_FILEFUNC_SEEK_SET :
|
||||||
fseek_origin = SEEK_SET;
|
fseek_origin = SEEK_SET;
|
||||||
break;
|
break;
|
||||||
default: return -1;
|
default: return -1;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
fseek((FILE *)stream, offset, fseek_origin);
|
fseek((FILE *)stream, offset, fseek_origin);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZCALLBACK fclose_file_func (opaque, stream)
|
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = fclose((FILE *)stream);
|
ret = fclose((FILE *)stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZCALLBACK ferror_file_func (opaque, stream)
|
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = ferror((FILE *)stream);
|
ret = ferror((FILE *)stream);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_fopen_filefunc (pzlib_filefunc_def)
|
void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||||
zlib_filefunc_def* pzlib_filefunc_def;
|
zlib_filefunc_def* pzlib_filefunc_def;
|
||||||
{
|
{
|
||||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||||
pzlib_filefunc_def->opaque = NULL;
|
pzlib_filefunc_def->opaque = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+75
-75
@@ -1,75 +1,75 @@
|
|||||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#define _ZLIBIOAPI_H
|
#define _ZLIBIOAPI_H
|
||||||
|
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||||
|
|
||||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||||
|
|
||||||
|
|
||||||
#ifndef ZCALLBACK
|
#ifndef ZCALLBACK
|
||||||
|
|
||||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||||
#define ZCALLBACK CALLBACK
|
#define ZCALLBACK CALLBACK
|
||||||
#else
|
#else
|
||||||
#define ZCALLBACK
|
#define ZCALLBACK
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
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 *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 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 *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
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 *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||||
|
|
||||||
typedef struct zlib_filefunc_def_s
|
typedef struct zlib_filefunc_def_s
|
||||||
{
|
{
|
||||||
open_file_func zopen_file;
|
open_file_func zopen_file;
|
||||||
read_file_func zread_file;
|
read_file_func zread_file;
|
||||||
write_file_func zwrite_file;
|
write_file_func zwrite_file;
|
||||||
tell_file_func ztell_file;
|
tell_file_func ztell_file;
|
||||||
seek_file_func zseek_file;
|
seek_file_func zseek_file;
|
||||||
close_file_func zclose_file;
|
close_file_func zclose_file;
|
||||||
testerror_file_func zerror_file;
|
testerror_file_func zerror_file;
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
} zlib_filefunc_def;
|
} zlib_filefunc_def;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_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 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 ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
#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 ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+270
-270
@@ -1,270 +1,270 @@
|
|||||||
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
#include "iowin32.h"
|
#include "iowin32.h"
|
||||||
|
|
||||||
#ifndef INVALID_HANDLE_VALUE
|
#ifndef INVALID_HANDLE_VALUE
|
||||||
#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
|
#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef INVALID_SET_FILE_POINTER
|
#ifndef INVALID_SET_FILE_POINTER
|
||||||
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
voidpf ZCALLBACK win32_open_file_func OF((
|
voidpf ZCALLBACK win32_open_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
int mode));
|
int mode));
|
||||||
|
|
||||||
uLong ZCALLBACK win32_read_file_func OF((
|
uLong ZCALLBACK win32_read_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
void* buf,
|
void* buf,
|
||||||
uLong size));
|
uLong size));
|
||||||
|
|
||||||
uLong ZCALLBACK win32_write_file_func OF((
|
uLong ZCALLBACK win32_write_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
const void* buf,
|
const void* buf,
|
||||||
uLong size));
|
uLong size));
|
||||||
|
|
||||||
long ZCALLBACK win32_tell_file_func OF((
|
long ZCALLBACK win32_tell_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
long ZCALLBACK win32_seek_file_func OF((
|
long ZCALLBACK win32_seek_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream,
|
voidpf stream,
|
||||||
uLong offset,
|
uLong offset,
|
||||||
int origin));
|
int origin));
|
||||||
|
|
||||||
int ZCALLBACK win32_close_file_func OF((
|
int ZCALLBACK win32_close_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
int ZCALLBACK win32_error_file_func OF((
|
int ZCALLBACK win32_error_file_func OF((
|
||||||
voidpf opaque,
|
voidpf opaque,
|
||||||
voidpf stream));
|
voidpf stream));
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
HANDLE hf;
|
HANDLE hf;
|
||||||
int error;
|
int error;
|
||||||
} WIN32FILE_IOWIN;
|
} WIN32FILE_IOWIN;
|
||||||
|
|
||||||
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
|
voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
const char* filename;
|
const char* filename;
|
||||||
int mode;
|
int mode;
|
||||||
{
|
{
|
||||||
const char* mode_fopen = NULL;
|
const char* mode_fopen = NULL;
|
||||||
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
||||||
HANDLE hFile = 0;
|
HANDLE hFile = 0;
|
||||||
voidpf ret=NULL;
|
voidpf ret=NULL;
|
||||||
|
|
||||||
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
|
dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
|
||||||
|
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||||
{
|
{
|
||||||
dwDesiredAccess = GENERIC_READ;
|
dwDesiredAccess = GENERIC_READ;
|
||||||
dwCreationDisposition = OPEN_EXISTING;
|
dwCreationDisposition = OPEN_EXISTING;
|
||||||
dwShareMode = FILE_SHARE_READ;
|
dwShareMode = FILE_SHARE_READ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||||
{
|
{
|
||||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||||
dwCreationDisposition = OPEN_EXISTING;
|
dwCreationDisposition = OPEN_EXISTING;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||||
{
|
{
|
||||||
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
||||||
dwCreationDisposition = CREATE_ALWAYS;
|
dwCreationDisposition = CREATE_ALWAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
||||||
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
|
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
|
||||||
dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
||||||
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
hFile = NULL;
|
hFile = NULL;
|
||||||
|
|
||||||
if (hFile != NULL)
|
if (hFile != NULL)
|
||||||
{
|
{
|
||||||
WIN32FILE_IOWIN w32fiow;
|
WIN32FILE_IOWIN w32fiow;
|
||||||
w32fiow.hf = hFile;
|
w32fiow.hf = hFile;
|
||||||
w32fiow.error = 0;
|
w32fiow.error = 0;
|
||||||
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
||||||
if (ret==NULL)
|
if (ret==NULL)
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
else *((WIN32FILE_IOWIN*)ret) = w32fiow;
|
else *((WIN32FILE_IOWIN*)ret) = w32fiow;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
void* buf;
|
void* buf;
|
||||||
uLong size;
|
uLong size;
|
||||||
{
|
{
|
||||||
uLong ret=0;
|
uLong ret=0;
|
||||||
HANDLE hFile = NULL;
|
HANDLE hFile = NULL;
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||||
if (hFile != NULL)
|
if (hFile != NULL)
|
||||||
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
||||||
{
|
{
|
||||||
DWORD dwErr = GetLastError();
|
DWORD dwErr = GetLastError();
|
||||||
if (dwErr == ERROR_HANDLE_EOF)
|
if (dwErr == ERROR_HANDLE_EOF)
|
||||||
dwErr = 0;
|
dwErr = 0;
|
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
const void* buf;
|
const void* buf;
|
||||||
uLong size;
|
uLong size;
|
||||||
{
|
{
|
||||||
uLong ret=0;
|
uLong ret=0;
|
||||||
HANDLE hFile = NULL;
|
HANDLE hFile = NULL;
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||||
|
|
||||||
if (hFile !=NULL)
|
if (hFile !=NULL)
|
||||||
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
||||||
{
|
{
|
||||||
DWORD dwErr = GetLastError();
|
DWORD dwErr = GetLastError();
|
||||||
if (dwErr == ERROR_HANDLE_EOF)
|
if (dwErr == ERROR_HANDLE_EOF)
|
||||||
dwErr = 0;
|
dwErr = 0;
|
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ZCALLBACK win32_tell_file_func (opaque, stream)
|
long ZCALLBACK win32_tell_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
long ret=-1;
|
long ret=-1;
|
||||||
HANDLE hFile = NULL;
|
HANDLE hFile = NULL;
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||||
if (hFile != NULL)
|
if (hFile != NULL)
|
||||||
{
|
{
|
||||||
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
|
DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
|
||||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||||
{
|
{
|
||||||
DWORD dwErr = GetLastError();
|
DWORD dwErr = GetLastError();
|
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret=(long)dwSet;
|
ret=(long)dwSet;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
uLong offset;
|
uLong offset;
|
||||||
int origin;
|
int origin;
|
||||||
{
|
{
|
||||||
DWORD dwMoveMethod=0xFFFFFFFF;
|
DWORD dwMoveMethod=0xFFFFFFFF;
|
||||||
HANDLE hFile = NULL;
|
HANDLE hFile = NULL;
|
||||||
|
|
||||||
long ret=-1;
|
long ret=-1;
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||||
switch (origin)
|
switch (origin)
|
||||||
{
|
{
|
||||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||||
dwMoveMethod = FILE_CURRENT;
|
dwMoveMethod = FILE_CURRENT;
|
||||||
break;
|
break;
|
||||||
case ZLIB_FILEFUNC_SEEK_END :
|
case ZLIB_FILEFUNC_SEEK_END :
|
||||||
dwMoveMethod = FILE_END;
|
dwMoveMethod = FILE_END;
|
||||||
break;
|
break;
|
||||||
case ZLIB_FILEFUNC_SEEK_SET :
|
case ZLIB_FILEFUNC_SEEK_SET :
|
||||||
dwMoveMethod = FILE_BEGIN;
|
dwMoveMethod = FILE_BEGIN;
|
||||||
break;
|
break;
|
||||||
default: return -1;
|
default: return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hFile != NULL)
|
if (hFile != NULL)
|
||||||
{
|
{
|
||||||
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
|
DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
|
||||||
if (dwSet == INVALID_SET_FILE_POINTER)
|
if (dwSet == INVALID_SET_FILE_POINTER)
|
||||||
{
|
{
|
||||||
DWORD dwErr = GetLastError();
|
DWORD dwErr = GetLastError();
|
||||||
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret=0;
|
ret=0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZCALLBACK win32_close_file_func (opaque, stream)
|
int ZCALLBACK win32_close_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
int ret=-1;
|
int ret=-1;
|
||||||
|
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
{
|
{
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
||||||
if (hFile != NULL)
|
if (hFile != NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
ret=0;
|
ret=0;
|
||||||
}
|
}
|
||||||
free(stream);
|
free(stream);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZCALLBACK win32_error_file_func (opaque, stream)
|
int ZCALLBACK win32_error_file_func (opaque, stream)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf stream;
|
voidpf stream;
|
||||||
{
|
{
|
||||||
int ret=-1;
|
int ret=-1;
|
||||||
if (stream!=NULL)
|
if (stream!=NULL)
|
||||||
{
|
{
|
||||||
ret = ((WIN32FILE_IOWIN*)stream) -> error;
|
ret = ((WIN32FILE_IOWIN*)stream) -> error;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_win32_filefunc (pzlib_filefunc_def)
|
void fill_win32_filefunc (pzlib_filefunc_def)
|
||||||
zlib_filefunc_def* pzlib_filefunc_def;
|
zlib_filefunc_def* pzlib_filefunc_def;
|
||||||
{
|
{
|
||||||
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
||||||
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
||||||
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
||||||
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
|
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
|
||||||
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
||||||
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
||||||
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
||||||
pzlib_filefunc_def->opaque=NULL;
|
pzlib_filefunc_def->opaque=NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -1,21 +1,21 @@
|
|||||||
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
/* iowin32.h -- IO base function header for compress/uncompress .zip
|
||||||
files using zlib + zip or unzip API
|
files using zlib + zip or unzip API
|
||||||
This IO API version uses the Win32 API (for Microsoft Windows)
|
This IO API version uses the Win32 API (for Microsoft Windows)
|
||||||
|
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+585
-585
File diff suppressed because it is too large
Load Diff
+420
-420
@@ -1,420 +1,420 @@
|
|||||||
/*
|
/*
|
||||||
minizip.c
|
minizip.c
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef unix
|
#ifdef unix
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <utime.h>
|
# include <utime.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
#else
|
#else
|
||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "zip.h"
|
#include "zip.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define USEWIN32IOAPI
|
#define USEWIN32IOAPI
|
||||||
#include "iowin32.h"
|
#include "iowin32.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define WRITEBUFFERSIZE (16384)
|
#define WRITEBUFFERSIZE (16384)
|
||||||
#define MAXFILENAME (256)
|
#define MAXFILENAME (256)
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
uLong filetime(f, tmzip, dt)
|
uLong filetime(f, tmzip, dt)
|
||||||
char *f; /* name of file to get info on */
|
char *f; /* name of file to get info on */
|
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||||
uLong *dt; /* dostime */
|
uLong *dt; /* dostime */
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
{
|
{
|
||||||
FILETIME ftLocal;
|
FILETIME ftLocal;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
WIN32_FIND_DATA ff32;
|
WIN32_FIND_DATA ff32;
|
||||||
|
|
||||||
hFind = FindFirstFile(f,&ff32);
|
hFind = FindFirstFile(f,&ff32);
|
||||||
if (hFind != INVALID_HANDLE_VALUE)
|
if (hFind != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
|
||||||
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
|
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef unix
|
#ifdef unix
|
||||||
uLong filetime(f, tmzip, dt)
|
uLong filetime(f, tmzip, dt)
|
||||||
char *f; /* name of file to get info on */
|
char *f; /* name of file to get info on */
|
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||||
uLong *dt; /* dostime */
|
uLong *dt; /* dostime */
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
struct stat s; /* results of stat() */
|
struct stat s; /* results of stat() */
|
||||||
struct tm* filedate;
|
struct tm* filedate;
|
||||||
time_t tm_t=0;
|
time_t tm_t=0;
|
||||||
|
|
||||||
if (strcmp(f,"-")!=0)
|
if (strcmp(f,"-")!=0)
|
||||||
{
|
{
|
||||||
char name[MAXFILENAME+1];
|
char name[MAXFILENAME+1];
|
||||||
int len = strlen(f);
|
int len = strlen(f);
|
||||||
if (len > MAXFILENAME)
|
if (len > MAXFILENAME)
|
||||||
len = MAXFILENAME;
|
len = MAXFILENAME;
|
||||||
|
|
||||||
strncpy(name, f,MAXFILENAME-1);
|
strncpy(name, f,MAXFILENAME-1);
|
||||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||||
name[ MAXFILENAME ] = '\0';
|
name[ MAXFILENAME ] = '\0';
|
||||||
|
|
||||||
if (name[len - 1] == '/')
|
if (name[len - 1] == '/')
|
||||||
name[len - 1] = '\0';
|
name[len - 1] = '\0';
|
||||||
/* not all systems allow stat'ing a file with / appended */
|
/* not all systems allow stat'ing a file with / appended */
|
||||||
if (stat(name,&s)==0)
|
if (stat(name,&s)==0)
|
||||||
{
|
{
|
||||||
tm_t = s.st_mtime;
|
tm_t = s.st_mtime;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filedate = localtime(&tm_t);
|
filedate = localtime(&tm_t);
|
||||||
|
|
||||||
tmzip->tm_sec = filedate->tm_sec;
|
tmzip->tm_sec = filedate->tm_sec;
|
||||||
tmzip->tm_min = filedate->tm_min;
|
tmzip->tm_min = filedate->tm_min;
|
||||||
tmzip->tm_hour = filedate->tm_hour;
|
tmzip->tm_hour = filedate->tm_hour;
|
||||||
tmzip->tm_mday = filedate->tm_mday;
|
tmzip->tm_mday = filedate->tm_mday;
|
||||||
tmzip->tm_mon = filedate->tm_mon ;
|
tmzip->tm_mon = filedate->tm_mon ;
|
||||||
tmzip->tm_year = filedate->tm_year;
|
tmzip->tm_year = filedate->tm_year;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
uLong filetime(f, tmzip, dt)
|
uLong filetime(f, tmzip, dt)
|
||||||
char *f; /* name of file to get info on */
|
char *f; /* name of file to get info on */
|
||||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||||
uLong *dt; /* dostime */
|
uLong *dt; /* dostime */
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int check_exist_file(filename)
|
int check_exist_file(filename)
|
||||||
const char* filename;
|
const char* filename;
|
||||||
{
|
{
|
||||||
FILE* ftestexist;
|
FILE* ftestexist;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
ftestexist = fopen(filename,"rb");
|
ftestexist = fopen(filename,"rb");
|
||||||
if (ftestexist==NULL)
|
if (ftestexist==NULL)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
else
|
else
|
||||||
fclose(ftestexist);
|
fclose(ftestexist);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_banner()
|
void do_banner()
|
||||||
{
|
{
|
||||||
printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n");
|
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");
|
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_help()
|
void do_help()
|
||||||
{
|
{
|
||||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \
|
||||||
" -o Overwrite existing file.zip\n" \
|
" -o Overwrite existing file.zip\n" \
|
||||||
" -a Append to existing file.zip\n" \
|
" -a Append to existing file.zip\n" \
|
||||||
" -0 Store only\n" \
|
" -0 Store only\n" \
|
||||||
" -1 Compress faster\n" \
|
" -1 Compress faster\n" \
|
||||||
" -9 Compress better\n\n");
|
" -9 Compress better\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate the CRC32 of a file,
|
/* calculate the CRC32 of a file,
|
||||||
because to encrypt a file, we need known the CRC32 of the file before */
|
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)
|
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
|
||||||
{
|
{
|
||||||
unsigned long calculate_crc=0;
|
unsigned long calculate_crc=0;
|
||||||
int err=ZIP_OK;
|
int err=ZIP_OK;
|
||||||
FILE * fin = fopen(filenameinzip,"rb");
|
FILE * fin = fopen(filenameinzip,"rb");
|
||||||
unsigned long size_read = 0;
|
unsigned long size_read = 0;
|
||||||
unsigned long total_read = 0;
|
unsigned long total_read = 0;
|
||||||
if (fin==NULL)
|
if (fin==NULL)
|
||||||
{
|
{
|
||||||
err = ZIP_ERRNO;
|
err = ZIP_ERRNO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == ZIP_OK)
|
if (err == ZIP_OK)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
err = ZIP_OK;
|
err = ZIP_OK;
|
||||||
size_read = (int)fread(buf,1,size_buf,fin);
|
size_read = (int)fread(buf,1,size_buf,fin);
|
||||||
if (size_read < size_buf)
|
if (size_read < size_buf)
|
||||||
if (feof(fin)==0)
|
if (feof(fin)==0)
|
||||||
{
|
{
|
||||||
printf("error in reading %s\n",filenameinzip);
|
printf("error in reading %s\n",filenameinzip);
|
||||||
err = ZIP_ERRNO;
|
err = ZIP_ERRNO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_read>0)
|
if (size_read>0)
|
||||||
calculate_crc = crc32(calculate_crc,buf,size_read);
|
calculate_crc = crc32(calculate_crc,buf,size_read);
|
||||||
total_read += size_read;
|
total_read += size_read;
|
||||||
|
|
||||||
} while ((err == ZIP_OK) && (size_read>0));
|
} while ((err == ZIP_OK) && (size_read>0));
|
||||||
|
|
||||||
if (fin)
|
if (fin)
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
*result_crc=calculate_crc;
|
*result_crc=calculate_crc;
|
||||||
printf("file %s crc %x\n",filenameinzip,calculate_crc);
|
printf("file %s crc %x\n",filenameinzip,calculate_crc);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(argc,argv)
|
int main(argc,argv)
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int opt_overwrite=0;
|
int opt_overwrite=0;
|
||||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||||
int zipfilenamearg = 0;
|
int zipfilenamearg = 0;
|
||||||
char filename_try[MAXFILENAME+16];
|
char filename_try[MAXFILENAME+16];
|
||||||
int zipok;
|
int zipok;
|
||||||
int err=0;
|
int err=0;
|
||||||
int size_buf=0;
|
int size_buf=0;
|
||||||
void* buf=NULL;
|
void* buf=NULL;
|
||||||
const char* password=NULL;
|
const char* password=NULL;
|
||||||
|
|
||||||
|
|
||||||
do_banner();
|
do_banner();
|
||||||
if (argc==1)
|
if (argc==1)
|
||||||
{
|
{
|
||||||
do_help();
|
do_help();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i=1;i<argc;i++)
|
for (i=1;i<argc;i++)
|
||||||
{
|
{
|
||||||
if ((*argv[i])=='-')
|
if ((*argv[i])=='-')
|
||||||
{
|
{
|
||||||
const char *p=argv[i]+1;
|
const char *p=argv[i]+1;
|
||||||
|
|
||||||
while ((*p)!='\0')
|
while ((*p)!='\0')
|
||||||
{
|
{
|
||||||
char c=*(p++);;
|
char c=*(p++);;
|
||||||
if ((c=='o') || (c=='O'))
|
if ((c=='o') || (c=='O'))
|
||||||
opt_overwrite = 1;
|
opt_overwrite = 1;
|
||||||
if ((c=='a') || (c=='A'))
|
if ((c=='a') || (c=='A'))
|
||||||
opt_overwrite = 2;
|
opt_overwrite = 2;
|
||||||
if ((c>='0') && (c<='9'))
|
if ((c>='0') && (c<='9'))
|
||||||
opt_compress_level = c-'0';
|
opt_compress_level = c-'0';
|
||||||
|
|
||||||
if (((c=='p') || (c=='P')) && (i+1<argc))
|
if (((c=='p') || (c=='P')) && (i+1<argc))
|
||||||
{
|
{
|
||||||
password=argv[i+1];
|
password=argv[i+1];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (zipfilenamearg == 0)
|
if (zipfilenamearg == 0)
|
||||||
zipfilenamearg = i ;
|
zipfilenamearg = i ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_buf = WRITEBUFFERSIZE;
|
size_buf = WRITEBUFFERSIZE;
|
||||||
buf = (void*)malloc(size_buf);
|
buf = (void*)malloc(size_buf);
|
||||||
if (buf==NULL)
|
if (buf==NULL)
|
||||||
{
|
{
|
||||||
printf("Error allocating memory\n");
|
printf("Error allocating memory\n");
|
||||||
return ZIP_INTERNALERROR;
|
return ZIP_INTERNALERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zipfilenamearg==0)
|
if (zipfilenamearg==0)
|
||||||
zipok=0;
|
zipok=0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i,len;
|
int i,len;
|
||||||
int dot_found=0;
|
int dot_found=0;
|
||||||
|
|
||||||
zipok = 1 ;
|
zipok = 1 ;
|
||||||
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
|
strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
|
||||||
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
/* strncpy doesnt append the trailing NULL, of the string is too long. */
|
||||||
filename_try[ MAXFILENAME ] = '\0';
|
filename_try[ MAXFILENAME ] = '\0';
|
||||||
|
|
||||||
len=(int)strlen(filename_try);
|
len=(int)strlen(filename_try);
|
||||||
for (i=0;i<len;i++)
|
for (i=0;i<len;i++)
|
||||||
if (filename_try[i]=='.')
|
if (filename_try[i]=='.')
|
||||||
dot_found=1;
|
dot_found=1;
|
||||||
|
|
||||||
if (dot_found==0)
|
if (dot_found==0)
|
||||||
strcat(filename_try,".zip");
|
strcat(filename_try,".zip");
|
||||||
|
|
||||||
if (opt_overwrite==2)
|
if (opt_overwrite==2)
|
||||||
{
|
{
|
||||||
/* if the file don't exist, we not append file */
|
/* if the file don't exist, we not append file */
|
||||||
if (check_exist_file(filename_try)==0)
|
if (check_exist_file(filename_try)==0)
|
||||||
opt_overwrite=1;
|
opt_overwrite=1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (opt_overwrite==0)
|
if (opt_overwrite==0)
|
||||||
if (check_exist_file(filename_try)!=0)
|
if (check_exist_file(filename_try)!=0)
|
||||||
{
|
{
|
||||||
char rep=0;
|
char rep=0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char answer[128];
|
char answer[128];
|
||||||
int ret;
|
int ret;
|
||||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
|
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
|
||||||
ret = scanf("%1s",answer);
|
ret = scanf("%1s",answer);
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
{
|
{
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
rep = answer[0] ;
|
rep = answer[0] ;
|
||||||
if ((rep>='a') && (rep<='z'))
|
if ((rep>='a') && (rep<='z'))
|
||||||
rep -= 0x20;
|
rep -= 0x20;
|
||||||
}
|
}
|
||||||
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||||
if (rep=='N')
|
if (rep=='N')
|
||||||
zipok = 0;
|
zipok = 0;
|
||||||
if (rep=='A')
|
if (rep=='A')
|
||||||
opt_overwrite = 2;
|
opt_overwrite = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zipok==1)
|
if (zipok==1)
|
||||||
{
|
{
|
||||||
zipFile zf;
|
zipFile zf;
|
||||||
int errclose;
|
int errclose;
|
||||||
# ifdef USEWIN32IOAPI
|
# ifdef USEWIN32IOAPI
|
||||||
zlib_filefunc_def ffunc;
|
zlib_filefunc_def ffunc;
|
||||||
fill_win32_filefunc(&ffunc);
|
fill_win32_filefunc(&ffunc);
|
||||||
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
|
||||||
# else
|
# else
|
||||||
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
|
zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (zf == NULL)
|
if (zf == NULL)
|
||||||
{
|
{
|
||||||
printf("error opening %s\n",filename_try);
|
printf("error opening %s\n",filename_try);
|
||||||
err= ZIP_ERRNO;
|
err= ZIP_ERRNO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("creating %s\n",filename_try);
|
printf("creating %s\n",filename_try);
|
||||||
|
|
||||||
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
|
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
|
||||||
{
|
{
|
||||||
if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
|
if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
|
||||||
((argv[i][1]=='o') || (argv[i][1]=='O') ||
|
((argv[i][1]=='o') || (argv[i][1]=='O') ||
|
||||||
(argv[i][1]=='a') || (argv[i][1]=='A') ||
|
(argv[i][1]=='a') || (argv[i][1]=='A') ||
|
||||||
(argv[i][1]=='p') || (argv[i][1]=='P') ||
|
(argv[i][1]=='p') || (argv[i][1]=='P') ||
|
||||||
((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
|
((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
|
||||||
(strlen(argv[i]) == 2)))
|
(strlen(argv[i]) == 2)))
|
||||||
{
|
{
|
||||||
FILE * fin;
|
FILE * fin;
|
||||||
int size_read;
|
int size_read;
|
||||||
const char* filenameinzip = argv[i];
|
const char* filenameinzip = argv[i];
|
||||||
zip_fileinfo zi;
|
zip_fileinfo zi;
|
||||||
unsigned long crcFile=0;
|
unsigned long crcFile=0;
|
||||||
|
|
||||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
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.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||||
zi.dosDate = 0;
|
zi.dosDate = 0;
|
||||||
zi.internal_fa = 0;
|
zi.internal_fa = 0;
|
||||||
zi.external_fa = 0;
|
zi.external_fa = 0;
|
||||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
||||||
NULL,0,NULL,0,NULL / * comment * /,
|
NULL,0,NULL,0,NULL / * comment * /,
|
||||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||||
opt_compress_level);
|
opt_compress_level);
|
||||||
*/
|
*/
|
||||||
if ((password != NULL) && (err==ZIP_OK))
|
if ((password != NULL) && (err==ZIP_OK))
|
||||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||||
|
|
||||||
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
|
err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
|
||||||
NULL,0,NULL,0,NULL /* comment*/,
|
NULL,0,NULL,0,NULL /* comment*/,
|
||||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||||
opt_compress_level,0,
|
opt_compress_level,0,
|
||||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||||
password,crcFile);
|
password,crcFile);
|
||||||
|
|
||||||
if (err != ZIP_OK)
|
if (err != ZIP_OK)
|
||||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fin = fopen(filenameinzip,"rb");
|
fin = fopen(filenameinzip,"rb");
|
||||||
if (fin==NULL)
|
if (fin==NULL)
|
||||||
{
|
{
|
||||||
err=ZIP_ERRNO;
|
err=ZIP_ERRNO;
|
||||||
printf("error in opening %s for reading\n",filenameinzip);
|
printf("error in opening %s for reading\n",filenameinzip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == ZIP_OK)
|
if (err == ZIP_OK)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
err = ZIP_OK;
|
err = ZIP_OK;
|
||||||
size_read = (int)fread(buf,1,size_buf,fin);
|
size_read = (int)fread(buf,1,size_buf,fin);
|
||||||
if (size_read < size_buf)
|
if (size_read < size_buf)
|
||||||
if (feof(fin)==0)
|
if (feof(fin)==0)
|
||||||
{
|
{
|
||||||
printf("error in reading %s\n",filenameinzip);
|
printf("error in reading %s\n",filenameinzip);
|
||||||
err = ZIP_ERRNO;
|
err = ZIP_ERRNO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_read>0)
|
if (size_read>0)
|
||||||
{
|
{
|
||||||
err = zipWriteInFileInZip (zf,buf,size_read);
|
err = zipWriteInFileInZip (zf,buf,size_read);
|
||||||
if (err<0)
|
if (err<0)
|
||||||
{
|
{
|
||||||
printf("error in writing %s in the zipfile\n",
|
printf("error in writing %s in the zipfile\n",
|
||||||
filenameinzip);
|
filenameinzip);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} while ((err == ZIP_OK) && (size_read>0));
|
} while ((err == ZIP_OK) && (size_read>0));
|
||||||
|
|
||||||
if (fin)
|
if (fin)
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
if (err<0)
|
if (err<0)
|
||||||
err=ZIP_ERRNO;
|
err=ZIP_ERRNO;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = zipCloseFileInZip(zf);
|
err = zipCloseFileInZip(zf);
|
||||||
if (err!=ZIP_OK)
|
if (err!=ZIP_OK)
|
||||||
printf("error in closing %s in the zipfile\n",
|
printf("error in closing %s in the zipfile\n",
|
||||||
filenameinzip);
|
filenameinzip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errclose = zipClose(zf,NULL);
|
errclose = zipClose(zf,NULL);
|
||||||
if (errclose != ZIP_OK)
|
if (errclose != ZIP_OK)
|
||||||
printf("error in closing %s\n",filename_try);
|
printf("error in closing %s\n",filename_try);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
do_help();
|
do_help();
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+281
-281
@@ -1,281 +1,281 @@
|
|||||||
/*
|
/*
|
||||||
Additional tools for Minizip
|
Additional tools for Minizip
|
||||||
Code: Xavier Roche '2004
|
Code: Xavier Roche '2004
|
||||||
License: Same as ZLIB (www.gzip.org)
|
License: Same as ZLIB (www.gzip.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Code */
|
/* Code */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
|
||||||
#define READ_8(adr) ((unsigned char)*(adr))
|
#define READ_8(adr) ((unsigned char)*(adr))
|
||||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
#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 READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||||
|
|
||||||
#define WRITE_8(buff, n) do { \
|
#define WRITE_8(buff, n) do { \
|
||||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#define WRITE_16(buff, n) do { \
|
#define WRITE_16(buff, n) do { \
|
||||||
WRITE_8((unsigned char*)(buff), n); \
|
WRITE_8((unsigned char*)(buff), n); \
|
||||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||||
} while(0)
|
} while(0)
|
||||||
#define WRITE_32(buff, n) do { \
|
#define WRITE_32(buff, n) do { \
|
||||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||||
const char* file;
|
const char* file;
|
||||||
const char* fileOut;
|
const char* fileOut;
|
||||||
const char* fileOutTmp;
|
const char* fileOutTmp;
|
||||||
uLong* nRecovered;
|
uLong* nRecovered;
|
||||||
uLong* bytesRecovered;
|
uLong* bytesRecovered;
|
||||||
{
|
{
|
||||||
int err = Z_OK;
|
int err = Z_OK;
|
||||||
FILE* fpZip = fopen(file, "rb");
|
FILE* fpZip = fopen(file, "rb");
|
||||||
FILE* fpOut = fopen(fileOut, "wb");
|
FILE* fpOut = fopen(fileOut, "wb");
|
||||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||||
if (fpZip != NULL && fpOut != NULL) {
|
if (fpZip != NULL && fpOut != NULL) {
|
||||||
int entries = 0;
|
int entries = 0;
|
||||||
uLong totalBytes = 0;
|
uLong totalBytes = 0;
|
||||||
char header[30];
|
char header[30];
|
||||||
char filename[256];
|
char filename[256];
|
||||||
char extra[1024];
|
char extra[1024];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int offsetCD = 0;
|
int offsetCD = 0;
|
||||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||||
int currentOffset = offset;
|
int currentOffset = offset;
|
||||||
|
|
||||||
/* File entry */
|
/* File entry */
|
||||||
if (READ_32(header) == 0x04034b50) {
|
if (READ_32(header) == 0x04034b50) {
|
||||||
unsigned int version = READ_16(header + 4);
|
unsigned int version = READ_16(header + 4);
|
||||||
unsigned int gpflag = READ_16(header + 6);
|
unsigned int gpflag = READ_16(header + 6);
|
||||||
unsigned int method = READ_16(header + 8);
|
unsigned int method = READ_16(header + 8);
|
||||||
unsigned int filetime = READ_16(header + 10);
|
unsigned int filetime = READ_16(header + 10);
|
||||||
unsigned int filedate = READ_16(header + 12);
|
unsigned int filedate = READ_16(header + 12);
|
||||||
unsigned int crc = READ_32(header + 14); /* crc */
|
unsigned int crc = READ_32(header + 14); /* crc */
|
||||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||||
filename[0] = extra[0] = '\0';
|
filename[0] = extra[0] = '\0';
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||||
offset += 30;
|
offset += 30;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Filename */
|
/* Filename */
|
||||||
if (fnsize > 0) {
|
if (fnsize > 0) {
|
||||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||||
offset += fnsize;
|
offset += fnsize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_STREAM_ERROR;
|
err = Z_STREAM_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extra field */
|
/* Extra field */
|
||||||
if (extsize > 0) {
|
if (extsize > 0) {
|
||||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||||
offset += extsize;
|
offset += extsize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data */
|
/* Data */
|
||||||
{
|
{
|
||||||
int dataSize = cpsize;
|
int dataSize = cpsize;
|
||||||
if (dataSize == 0) {
|
if (dataSize == 0) {
|
||||||
dataSize = uncpsize;
|
dataSize = uncpsize;
|
||||||
}
|
}
|
||||||
if (dataSize > 0) {
|
if (dataSize > 0) {
|
||||||
char* data = malloc(dataSize);
|
char* data = malloc(dataSize);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||||
offset += dataSize;
|
offset += dataSize;
|
||||||
totalBytes += dataSize;
|
totalBytes += dataSize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
}
|
}
|
||||||
free(data);
|
free(data);
|
||||||
if (err != Z_OK) {
|
if (err != Z_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_MEM_ERROR;
|
err = Z_MEM_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Central directory entry */
|
/* Central directory entry */
|
||||||
{
|
{
|
||||||
char header[46];
|
char header[46];
|
||||||
char* comment = "";
|
char* comment = "";
|
||||||
int comsize = (int) strlen(comment);
|
int comsize = (int) strlen(comment);
|
||||||
WRITE_32(header, 0x02014b50);
|
WRITE_32(header, 0x02014b50);
|
||||||
WRITE_16(header + 4, version);
|
WRITE_16(header + 4, version);
|
||||||
WRITE_16(header + 6, version);
|
WRITE_16(header + 6, version);
|
||||||
WRITE_16(header + 8, gpflag);
|
WRITE_16(header + 8, gpflag);
|
||||||
WRITE_16(header + 10, method);
|
WRITE_16(header + 10, method);
|
||||||
WRITE_16(header + 12, filetime);
|
WRITE_16(header + 12, filetime);
|
||||||
WRITE_16(header + 14, filedate);
|
WRITE_16(header + 14, filedate);
|
||||||
WRITE_32(header + 16, crc);
|
WRITE_32(header + 16, crc);
|
||||||
WRITE_32(header + 20, cpsize);
|
WRITE_32(header + 20, cpsize);
|
||||||
WRITE_32(header + 24, uncpsize);
|
WRITE_32(header + 24, uncpsize);
|
||||||
WRITE_16(header + 28, fnsize);
|
WRITE_16(header + 28, fnsize);
|
||||||
WRITE_16(header + 30, extsize);
|
WRITE_16(header + 30, extsize);
|
||||||
WRITE_16(header + 32, comsize);
|
WRITE_16(header + 32, comsize);
|
||||||
WRITE_16(header + 34, 0); /* disk # */
|
WRITE_16(header + 34, 0); /* disk # */
|
||||||
WRITE_16(header + 36, 0); /* int attrb */
|
WRITE_16(header + 36, 0); /* int attrb */
|
||||||
WRITE_32(header + 38, 0); /* ext attrb */
|
WRITE_32(header + 38, 0); /* ext attrb */
|
||||||
WRITE_32(header + 42, currentOffset);
|
WRITE_32(header + 42, currentOffset);
|
||||||
/* Header */
|
/* Header */
|
||||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||||
offsetCD += 46;
|
offsetCD += 46;
|
||||||
|
|
||||||
/* Filename */
|
/* Filename */
|
||||||
if (fnsize > 0) {
|
if (fnsize > 0) {
|
||||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||||
offsetCD += fnsize;
|
offsetCD += fnsize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_STREAM_ERROR;
|
err = Z_STREAM_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extra field */
|
/* Extra field */
|
||||||
if (extsize > 0) {
|
if (extsize > 0) {
|
||||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||||
offsetCD += extsize;
|
offsetCD += extsize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Comment field */
|
/* Comment field */
|
||||||
if (comsize > 0) {
|
if (comsize > 0) {
|
||||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||||
offsetCD += comsize;
|
offsetCD += comsize;
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
entries++;
|
entries++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Final central directory */
|
/* Final central directory */
|
||||||
{
|
{
|
||||||
int entriesZip = entries;
|
int entriesZip = entries;
|
||||||
char header[22];
|
char header[22];
|
||||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||||
int comsize = (int) strlen(comment);
|
int comsize = (int) strlen(comment);
|
||||||
if (entriesZip > 0xffff) {
|
if (entriesZip > 0xffff) {
|
||||||
entriesZip = 0xffff;
|
entriesZip = 0xffff;
|
||||||
}
|
}
|
||||||
WRITE_32(header, 0x06054b50);
|
WRITE_32(header, 0x06054b50);
|
||||||
WRITE_16(header + 4, 0); /* disk # */
|
WRITE_16(header + 4, 0); /* disk # */
|
||||||
WRITE_16(header + 6, 0); /* disk # */
|
WRITE_16(header + 6, 0); /* disk # */
|
||||||
WRITE_16(header + 8, entriesZip); /* hack */
|
WRITE_16(header + 8, entriesZip); /* hack */
|
||||||
WRITE_16(header + 10, entriesZip); /* hack */
|
WRITE_16(header + 10, entriesZip); /* hack */
|
||||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||||
WRITE_32(header + 16, offset); /* offset to CD */
|
WRITE_32(header + 16, offset); /* offset to CD */
|
||||||
WRITE_16(header + 20, comsize); /* comment */
|
WRITE_16(header + 20, comsize); /* comment */
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||||
|
|
||||||
/* Comment field */
|
/* Comment field */
|
||||||
if (comsize > 0) {
|
if (comsize > 0) {
|
||||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Final merge (file + central directory) */
|
/* Final merge (file + central directory) */
|
||||||
fclose(fpOutCD);
|
fclose(fpOutCD);
|
||||||
if (err == Z_OK) {
|
if (err == Z_OK) {
|
||||||
fpOutCD = fopen(fileOutTmp, "rb");
|
fpOutCD = fopen(fileOutTmp, "rb");
|
||||||
if (fpOutCD != NULL) {
|
if (fpOutCD != NULL) {
|
||||||
int nRead;
|
int nRead;
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||||
err = Z_ERRNO;
|
err = Z_ERRNO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fpOutCD);
|
fclose(fpOutCD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close */
|
/* Close */
|
||||||
fclose(fpZip);
|
fclose(fpZip);
|
||||||
fclose(fpOut);
|
fclose(fpOut);
|
||||||
|
|
||||||
/* Wipe temporary file */
|
/* Wipe temporary file */
|
||||||
(void)remove(fileOutTmp);
|
(void)remove(fileOutTmp);
|
||||||
|
|
||||||
/* Number of recovered entries */
|
/* Number of recovered entries */
|
||||||
if (err == Z_OK) {
|
if (err == Z_OK) {
|
||||||
if (nRecovered != NULL) {
|
if (nRecovered != NULL) {
|
||||||
*nRecovered = entries;
|
*nRecovered = entries;
|
||||||
}
|
}
|
||||||
if (bytesRecovered != NULL) {
|
if (bytesRecovered != NULL) {
|
||||||
*bytesRecovered = totalBytes;
|
*bytesRecovered = totalBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = Z_STREAM_ERROR;
|
err = Z_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-31
@@ -1,31 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
Additional tools for Minizip
|
Additional tools for Minizip
|
||||||
Code: Xavier Roche '2004
|
Code: Xavier Roche '2004
|
||||||
License: Same as ZLIB (www.gzip.org)
|
License: Same as ZLIB (www.gzip.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _zip_tools_H
|
#ifndef _zip_tools_H
|
||||||
#define _zip_tools_H
|
#define _zip_tools_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "unzip.h"
|
#include "unzip.h"
|
||||||
|
|
||||||
/* Repair a ZIP file (missing central directory)
|
/* Repair a ZIP file (missing central directory)
|
||||||
file: file to recover
|
file: file to recover
|
||||||
fileOut: output file after recovery
|
fileOut: output file after recovery
|
||||||
fileOutTmp: temporary file name used for recovery
|
fileOutTmp: temporary file name used for recovery
|
||||||
*/
|
*/
|
||||||
extern int ZEXPORT unzRepair(const char* file,
|
extern int ZEXPORT unzRepair(const char* file,
|
||||||
const char* fileOut,
|
const char* fileOut,
|
||||||
const char* fileOutTmp,
|
const char* fileOutTmp,
|
||||||
uLong* nRecovered,
|
uLong* nRecovered,
|
||||||
uLong* bytesRecovered);
|
uLong* bytesRecovered);
|
||||||
|
|
||||||
#endif
|
#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
|
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
||||||
WinZip, InfoZip tools and compatible.
|
WinZip, InfoZip tools and compatible.
|
||||||
|
|
||||||
Multi volume ZipFile (span) are not supported.
|
Multi volume ZipFile (span) are not supported.
|
||||||
Encryption compatible with pkzip 2.04g only supported
|
Encryption compatible with pkzip 2.04g only supported
|
||||||
Old compressions used by old PKZip 1.x are not supported
|
Old compressions used by old PKZip 1.x are not supported
|
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com
|
I WAIT FEEDBACK at mail info@winimage.com
|
||||||
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib :
|
Condition of use and distribution are the same than zlib :
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* 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/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at :
|
PkWare has also a specification at :
|
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _unz_H
|
#ifndef _unz_H
|
||||||
#define _unz_H
|
#define _unz_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */
|
from (void*) without cast */
|
||||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||||
typedef unzFile__ *unzFile;
|
typedef unzFile__ *unzFile;
|
||||||
#else
|
#else
|
||||||
typedef voidp unzFile;
|
typedef voidp unzFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define UNZ_OK (0)
|
#define UNZ_OK (0)
|
||||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||||
#define UNZ_ERRNO (Z_ERRNO)
|
#define UNZ_ERRNO (Z_ERRNO)
|
||||||
#define UNZ_EOF (0)
|
#define UNZ_EOF (0)
|
||||||
#define UNZ_PARAMERROR (-102)
|
#define UNZ_PARAMERROR (-102)
|
||||||
#define UNZ_BADZIPFILE (-103)
|
#define UNZ_BADZIPFILE (-103)
|
||||||
#define UNZ_INTERNALERROR (-104)
|
#define UNZ_INTERNALERROR (-104)
|
||||||
#define UNZ_CRCERROR (-105)
|
#define UNZ_CRCERROR (-105)
|
||||||
|
|
||||||
|
|
||||||
/* tm_unz contain date/time info */
|
/* tm_unz contain date/time info */
|
||||||
typedef struct tm_unz_s
|
typedef struct tm_unz_s
|
||||||
{
|
{
|
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||||
uInt tm_mday; /* day of the month - [1,31] */
|
uInt tm_mday; /* day of the month - [1,31] */
|
||||||
uInt tm_mon; /* months since January - [0,11] */
|
uInt tm_mon; /* months since January - [0,11] */
|
||||||
uInt tm_year; /* years - [1980..2044] */
|
uInt tm_year; /* years - [1980..2044] */
|
||||||
} tm_unz;
|
} tm_unz;
|
||||||
|
|
||||||
/* unz_global_info structure contain global data about the ZIPfile
|
/* unz_global_info structure contain global data about the ZIPfile
|
||||||
These data comes from the end of central dir */
|
These data comes from the end of central dir */
|
||||||
typedef struct unz_global_info_s
|
typedef struct unz_global_info_s
|
||||||
{
|
{
|
||||||
uLong number_entry; /* total number of entries in
|
uLong number_entry; /* total number of entries in
|
||||||
the central dir on this disk */
|
the central dir on this disk */
|
||||||
uLong size_comment; /* size of the global comment of the zipfile */
|
uLong size_comment; /* size of the global comment of the zipfile */
|
||||||
} unz_global_info;
|
} unz_global_info;
|
||||||
|
|
||||||
|
|
||||||
/* unz_file_info contain information about a file in the zipfile */
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
typedef struct unz_file_info_s
|
typedef struct unz_file_info_s
|
||||||
{
|
{
|
||||||
uLong version; /* version made by 2 bytes */
|
uLong version; /* version made by 2 bytes */
|
||||||
uLong version_needed; /* version needed to extract 2 bytes */
|
uLong version_needed; /* version needed to extract 2 bytes */
|
||||||
uLong flag; /* general purpose bit flag 2 bytes */
|
uLong flag; /* general purpose bit flag 2 bytes */
|
||||||
uLong compression_method; /* compression method 2 bytes */
|
uLong compression_method; /* compression method 2 bytes */
|
||||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||||
uLong crc; /* crc-32 4 bytes */
|
uLong crc; /* crc-32 4 bytes */
|
||||||
uLong compressed_size; /* compressed size 4 bytes */
|
uLong compressed_size; /* compressed size 4 bytes */
|
||||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||||
uLong size_filename; /* filename length 2 bytes */
|
uLong size_filename; /* filename length 2 bytes */
|
||||||
uLong size_file_extra; /* extra field length 2 bytes */
|
uLong size_file_extra; /* extra field length 2 bytes */
|
||||||
uLong size_file_comment; /* file comment length 2 bytes */
|
uLong size_file_comment; /* file comment length 2 bytes */
|
||||||
|
|
||||||
uLong disk_num_start; /* disk number start 2 bytes */
|
uLong disk_num_start; /* disk number start 2 bytes */
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
uLong external_fa; /* external file attributes 4 bytes */
|
||||||
|
|
||||||
tm_unz tmu_date;
|
tm_unz tmu_date;
|
||||||
} unz_file_info;
|
} unz_file_info;
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||||
const char* fileName2,
|
const char* fileName2,
|
||||||
int iCaseSensitivity));
|
int iCaseSensitivity));
|
||||||
/*
|
/*
|
||||||
Compare two filename (fileName1,fileName2).
|
Compare two filename (fileName1,fileName2).
|
||||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||||
or strcasecmp)
|
or strcasecmp)
|
||||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||||
(like 1 on Unix, 2 on Windows)
|
(like 1 on Unix, 2 on Windows)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
extern unzFile ZEXPORT unzOpen OF((const char *path));
|
||||||
/*
|
/*
|
||||||
Open a Zip file. path contain the full pathname (by example,
|
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
|
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||||
"zlib/zlib113.zip".
|
"zlib/zlib113.zip".
|
||||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||||
return value is NULL.
|
return value is NULL.
|
||||||
Else, the return value is a unzFile Handle, usable with other function
|
Else, the return value is a unzFile Handle, usable with other function
|
||||||
of this unzip package.
|
of this unzip package.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
||||||
zlib_filefunc_def* pzlib_filefunc_def));
|
zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
/*
|
/*
|
||||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||||
for read/write the zip file (see ioapi.h)
|
for read/write the zip file (see ioapi.h)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzClose OF((unzFile file));
|
extern int ZEXPORT unzClose OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Close a ZipFile opened with unzipOpen.
|
Close a ZipFile opened with unzipOpen.
|
||||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||||
return UNZ_OK if there is no problem. */
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||||
unz_global_info *pglobal_info));
|
unz_global_info *pglobal_info));
|
||||||
/*
|
/*
|
||||||
Write info about the ZipFile in the *pglobal_info structure.
|
Write info about the ZipFile in the *pglobal_info structure.
|
||||||
No preparation of the structure is needed
|
No preparation of the structure is needed
|
||||||
return UNZ_OK if there is no problem. */
|
return UNZ_OK if there is no problem. */
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||||
char *szComment,
|
char *szComment,
|
||||||
uLong uSizeBuf));
|
uLong uSizeBuf));
|
||||||
/*
|
/*
|
||||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||||
uSizeBuf is the size of the szComment buffer.
|
uSizeBuf is the size of the szComment buffer.
|
||||||
return the number of byte copied or an error code <0
|
return the number of byte copied or an error code <0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/* Unzip package allow you browse the directory of the zipfile */
|
/* Unzip package allow you browse the directory of the zipfile */
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the first file.
|
Set the current file of the zipfile to the first file.
|
||||||
return UNZ_OK if there is no problem
|
return UNZ_OK if there is no problem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Set the current file of the zipfile to the next file.
|
Set the current file of the zipfile to the next file.
|
||||||
return UNZ_OK if there is no problem
|
return UNZ_OK if there is no problem
|
||||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||||
const char *szFileName,
|
const char *szFileName,
|
||||||
int iCaseSensitivity));
|
int iCaseSensitivity));
|
||||||
/*
|
/*
|
||||||
Try locate the file szFileName in the zipfile.
|
Try locate the file szFileName in the zipfile.
|
||||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||||
|
|
||||||
return value :
|
return value :
|
||||||
UNZ_OK if the file is found. It becomes the current file.
|
UNZ_OK if the file is found. It becomes the current file.
|
||||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* Ryan supplied functions */
|
/* Ryan supplied functions */
|
||||||
/* unz_file_info contain information about a file in the zipfile */
|
/* unz_file_info contain information about a file in the zipfile */
|
||||||
typedef struct unz_file_pos_s
|
typedef struct unz_file_pos_s
|
||||||
{
|
{
|
||||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||||
uLong num_of_file; /* # of file */
|
uLong num_of_file; /* # of file */
|
||||||
} unz_file_pos;
|
} unz_file_pos;
|
||||||
|
|
||||||
extern int ZEXPORT unzGetFilePos(
|
extern int ZEXPORT unzGetFilePos(
|
||||||
unzFile file,
|
unzFile file,
|
||||||
unz_file_pos* file_pos);
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
extern int ZEXPORT unzGoToFilePos(
|
extern int ZEXPORT unzGoToFilePos(
|
||||||
unzFile file,
|
unzFile file,
|
||||||
unz_file_pos* file_pos);
|
unz_file_pos* file_pos);
|
||||||
|
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
||||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||||
unz_file_info *pfile_info,
|
unz_file_info *pfile_info,
|
||||||
char *szFileName,
|
char *szFileName,
|
||||||
uLong fileNameBufferSize,
|
uLong fileNameBufferSize,
|
||||||
void *extraField,
|
void *extraField,
|
||||||
uLong extraFieldBufferSize,
|
uLong extraFieldBufferSize,
|
||||||
char *szComment,
|
char *szComment,
|
||||||
uLong commentBufferSize));
|
uLong commentBufferSize));
|
||||||
/*
|
/*
|
||||||
Get Info about the current file
|
Get Info about the current file
|
||||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||||
the current file
|
the current file
|
||||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||||
(fileNameBufferSize is the size of the buffer)
|
(fileNameBufferSize is the size of the buffer)
|
||||||
if extraField!=NULL, the extra field information will be copied in extraField
|
if extraField!=NULL, the extra field information will be copied in extraField
|
||||||
(extraFieldBufferSize is the size of the buffer).
|
(extraFieldBufferSize is the size of the buffer).
|
||||||
This is the Central-header version of the extra field
|
This is the Central-header version of the extra field
|
||||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||||
(commentBufferSize is the size of the buffer)
|
(commentBufferSize is the size of the buffer)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/* for reading the content of the current zipfile, you can open it, read data
|
/* 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)
|
from it, and close it (you can close it before reading all the file)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile.
|
Open for reading data the current file in the zipfile.
|
||||||
If there is no error, the return value is UNZ_OK.
|
If there is no error, the return value is UNZ_OK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||||
const char* password));
|
const char* password));
|
||||||
/*
|
/*
|
||||||
Open for reading data the current file in the zipfile.
|
Open for reading data the current file in the zipfile.
|
||||||
password is a crypting password
|
password is a crypting password
|
||||||
If there is no error, the return value is UNZ_OK.
|
If there is no error, the return value is UNZ_OK.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||||
int* method,
|
int* method,
|
||||||
int* level,
|
int* level,
|
||||||
int raw));
|
int raw));
|
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
if raw==1
|
if raw==1
|
||||||
*method will receive method of compression, *level will receive level of
|
*method will receive method of compression, *level will receive level of
|
||||||
compression
|
compression
|
||||||
note : you can set level parameter as NULL (if you did not want known level,
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
but you CANNOT set method parameter as NULL
|
but you CANNOT set method parameter as NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||||
int* method,
|
int* method,
|
||||||
int* level,
|
int* level,
|
||||||
int raw,
|
int raw,
|
||||||
const char* password));
|
const char* password));
|
||||||
/*
|
/*
|
||||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||||
if raw==1
|
if raw==1
|
||||||
*method will receive method of compression, *level will receive level of
|
*method will receive method of compression, *level will receive level of
|
||||||
compression
|
compression
|
||||||
note : you can set level parameter as NULL (if you did not want known level,
|
note : you can set level parameter as NULL (if you did not want known level,
|
||||||
but you CANNOT set method parameter as NULL
|
but you CANNOT set method parameter as NULL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Close the file in zip opened with unzOpenCurrentFile
|
Close the file in zip opened with unzOpenCurrentFile
|
||||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||||
voidp buf,
|
voidp buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||||
buf contain buffer where data must be copied
|
buf contain buffer where data must be copied
|
||||||
len the size of buf.
|
len the size of buf.
|
||||||
|
|
||||||
return the number of byte copied if somes bytes are copied
|
return the number of byte copied if somes bytes are copied
|
||||||
return 0 if the end of file was reached
|
return 0 if the end of file was reached
|
||||||
return <0 with error code if there is an error
|
return <0 with error code if there is an error
|
||||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
Give the current position in uncompressed data
|
Give the current position in uncompressed data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzeof OF((unzFile file));
|
extern int ZEXPORT unzeof OF((unzFile file));
|
||||||
/*
|
/*
|
||||||
return 1 if the end of file was reached, 0 elsewhere
|
return 1 if the end of file was reached, 0 elsewhere
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||||
voidp buf,
|
voidp buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||||
This is the local-header version of the extra field (sometimes, there is
|
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)
|
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, 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
|
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||||
buf.
|
buf.
|
||||||
the return value is the number of bytes copied in buf, or (if <0)
|
the return value is the number of bytes copied in buf, or (if <0)
|
||||||
the error code
|
the error code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
/* Get the current file offset */
|
/* Get the current file offset */
|
||||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||||
|
|
||||||
/* Set the current file offset */
|
/* Set the current file offset */
|
||||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _unz_H */
|
#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
|
/* zip.h -- IO for compress .zip files using zlib
|
||||||
Version 1.01e, February 12th, 2005
|
Version 1.01e, February 12th, 2005
|
||||||
|
|
||||||
Copyright (C) 1998-2005 Gilles Vollant
|
Copyright (C) 1998-2005 Gilles Vollant
|
||||||
|
|
||||||
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
|
||||||
WinZip, InfoZip tools and compatible.
|
WinZip, InfoZip tools and compatible.
|
||||||
Multi volume ZipFile (span) are not supported.
|
Multi volume ZipFile (span) are not supported.
|
||||||
Encryption compatible with pkzip 2.04g only supported
|
Encryption compatible with pkzip 2.04g only supported
|
||||||
Old compressions used by old PKZip 1.x are not supported
|
Old compressions used by old PKZip 1.x are not supported
|
||||||
|
|
||||||
For uncompress .zip file, look at unzip.h
|
For uncompress .zip file, look at unzip.h
|
||||||
|
|
||||||
|
|
||||||
I WAIT FEEDBACK at mail info@winimage.com
|
I WAIT FEEDBACK at mail info@winimage.com
|
||||||
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
|
||||||
|
|
||||||
Condition of use and distribution are the same than zlib :
|
Condition of use and distribution are the same than zlib :
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
arising from the use of this software.
|
arising from the use of this software.
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it
|
including commercial applications, and to alter it and redistribute it
|
||||||
freely, subject to the following restrictions:
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
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
|
claim that you wrote the original software. If you use this software
|
||||||
in a product, an acknowledgment in the product documentation would be
|
in a product, an acknowledgment in the product documentation would be
|
||||||
appreciated but is not required.
|
appreciated but is not required.
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* for more info about .ZIP format, see
|
/* 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/appnote-981119-iz.zip
|
||||||
http://www.info-zip.org/pub/infozip/doc/
|
http://www.info-zip.org/pub/infozip/doc/
|
||||||
PkWare has also a specification at :
|
PkWare has also a specification at :
|
||||||
ftp://ftp.pkware.com/probdesc.zip
|
ftp://ftp.pkware.com/probdesc.zip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _zip_H
|
#ifndef _zip_H
|
||||||
#define _zip_H
|
#define _zip_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIB_H
|
#ifndef _ZLIB_H
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _ZLIBIOAPI_H
|
#ifndef _ZLIBIOAPI_H
|
||||||
#include "ioapi.h"
|
#include "ioapi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||||
from (void*) without cast */
|
from (void*) without cast */
|
||||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||||
typedef zipFile__ *zipFile;
|
typedef zipFile__ *zipFile;
|
||||||
#else
|
#else
|
||||||
typedef voidp zipFile;
|
typedef voidp zipFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ZIP_OK (0)
|
#define ZIP_OK (0)
|
||||||
#define ZIP_EOF (0)
|
#define ZIP_EOF (0)
|
||||||
#define ZIP_ERRNO (Z_ERRNO)
|
#define ZIP_ERRNO (Z_ERRNO)
|
||||||
#define ZIP_PARAMERROR (-102)
|
#define ZIP_PARAMERROR (-102)
|
||||||
#define ZIP_BADZIPFILE (-103)
|
#define ZIP_BADZIPFILE (-103)
|
||||||
#define ZIP_INTERNALERROR (-104)
|
#define ZIP_INTERNALERROR (-104)
|
||||||
|
|
||||||
#ifndef DEF_MEM_LEVEL
|
#ifndef DEF_MEM_LEVEL
|
||||||
# if MAX_MEM_LEVEL >= 8
|
# if MAX_MEM_LEVEL >= 8
|
||||||
# define DEF_MEM_LEVEL 8
|
# define DEF_MEM_LEVEL 8
|
||||||
# else
|
# else
|
||||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
/* default memLevel */
|
/* default memLevel */
|
||||||
|
|
||||||
/* tm_zip contain date/time info */
|
/* tm_zip contain date/time info */
|
||||||
typedef struct tm_zip_s
|
typedef struct tm_zip_s
|
||||||
{
|
{
|
||||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||||
uInt tm_mday; /* day of the month - [1,31] */
|
uInt tm_mday; /* day of the month - [1,31] */
|
||||||
uInt tm_mon; /* months since January - [0,11] */
|
uInt tm_mon; /* months since January - [0,11] */
|
||||||
uInt tm_year; /* years - [1980..2044] */
|
uInt tm_year; /* years - [1980..2044] */
|
||||||
} tm_zip;
|
} tm_zip;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
tm_zip tmz_date; /* date in understandable format */
|
tm_zip tmz_date; /* date in understandable format */
|
||||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||||
|
|
||||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||||
uLong external_fa; /* external file attributes 4 bytes */
|
uLong external_fa; /* external file attributes 4 bytes */
|
||||||
} zip_fileinfo;
|
} zip_fileinfo;
|
||||||
|
|
||||||
typedef const char* zipcharpc;
|
typedef const char* zipcharpc;
|
||||||
|
|
||||||
|
|
||||||
#define APPEND_STATUS_CREATE (0)
|
#define APPEND_STATUS_CREATE (0)
|
||||||
#define APPEND_STATUS_CREATEAFTER (1)
|
#define APPEND_STATUS_CREATEAFTER (1)
|
||||||
#define APPEND_STATUS_ADDINZIP (2)
|
#define APPEND_STATUS_ADDINZIP (2)
|
||||||
|
|
||||||
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
|
||||||
/*
|
/*
|
||||||
Create a zipfile.
|
Create a zipfile.
|
||||||
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
|
||||||
an Unix computer "zlib/zlib113.zip".
|
an Unix computer "zlib/zlib113.zip".
|
||||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||||
will be created at the end of the file.
|
will be created at the end of the file.
|
||||||
(useful if the file contain a self extractor code)
|
(useful if the file contain a self extractor code)
|
||||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
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)
|
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.
|
If the zipfile cannot be opened, the return value is NULL.
|
||||||
Else, the return value is a zipFile Handle, usable with other function
|
Else, the return value is a zipFile Handle, usable with other function
|
||||||
of this zip package.
|
of this zip package.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Note : there is no delete function into a zipfile.
|
/* 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
|
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
|
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,
|
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
|
||||||
int append,
|
int append,
|
||||||
zipcharpc* globalcomment,
|
zipcharpc* globalcomment,
|
||||||
zlib_filefunc_def* pzlib_filefunc_def));
|
zlib_filefunc_def* pzlib_filefunc_def));
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level));
|
int level));
|
||||||
/*
|
/*
|
||||||
Open a file in the ZIP for writing.
|
Open a file in the ZIP for writing.
|
||||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||||
*zipfi contain supplemental information
|
*zipfi contain supplemental information
|
||||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||||
contains the extrafield data the the local header
|
contains the extrafield data the the local header
|
||||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||||
contains the extrafield data the the local header
|
contains the extrafield data the the local header
|
||||||
if comment != NULL, comment contain the comment string
|
if comment != NULL, comment contain the comment string
|
||||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level,
|
int level,
|
||||||
int raw));
|
int raw));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const zip_fileinfo* zipfi,
|
const zip_fileinfo* zipfi,
|
||||||
const void* extrafield_local,
|
const void* extrafield_local,
|
||||||
uInt size_extrafield_local,
|
uInt size_extrafield_local,
|
||||||
const void* extrafield_global,
|
const void* extrafield_global,
|
||||||
uInt size_extrafield_global,
|
uInt size_extrafield_global,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int method,
|
int method,
|
||||||
int level,
|
int level,
|
||||||
int raw,
|
int raw,
|
||||||
int windowBits,
|
int windowBits,
|
||||||
int memLevel,
|
int memLevel,
|
||||||
int strategy,
|
int strategy,
|
||||||
const char* password,
|
const char* password,
|
||||||
uLong crcForCtypting));
|
uLong crcForCtypting));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Same than zipOpenNewFileInZip2, except
|
Same than zipOpenNewFileInZip2, except
|
||||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||||
password : crypting password (NULL for no crypting)
|
password : crypting password (NULL for no crypting)
|
||||||
crcForCtypting : crc of file to compress (needed for crypting)
|
crcForCtypting : crc of file to compress (needed for crypting)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||||
const void* buf,
|
const void* buf,
|
||||||
unsigned len));
|
unsigned len));
|
||||||
/*
|
/*
|
||||||
Write data in the zipfile
|
Write data in the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile
|
Close the current file in the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||||
uLong uncompressed_size,
|
uLong uncompressed_size,
|
||||||
uLong crc32));
|
uLong crc32));
|
||||||
/*
|
/*
|
||||||
Close the current file in the zipfile, for fiel opened with
|
Close the current file in the zipfile, for fiel opened with
|
||||||
parameter raw=1 in zipOpenNewFileInZip2
|
parameter raw=1 in zipOpenNewFileInZip2
|
||||||
uncompressed_size and crc32 are value for the uncompressed size
|
uncompressed_size and crc32 are value for the uncompressed size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern int ZEXPORT zipClose OF((zipFile file,
|
extern int ZEXPORT zipClose OF((zipFile file,
|
||||||
const char* global_comment));
|
const char* global_comment));
|
||||||
/*
|
/*
|
||||||
Close the zipfile
|
Close the zipfile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _zip_H */
|
#endif /* _zip_H */
|
||||||
|
|||||||
+275
-275
@@ -1,275 +1,275 @@
|
|||||||
/*
|
/*
|
||||||
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
* Helper for use with the PSP Software Development Kit - http://www.pspdev.org
|
||||||
* -----------------------------------------------------------------------
|
* -----------------------------------------------------------------------
|
||||||
* Licensed under GPL
|
* Licensed under GPL
|
||||||
*
|
*
|
||||||
* vram.c - Standard C high performance VRAM allocation routines.
|
* vram.c - Standard C high performance VRAM allocation routines.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
* Copyright (c) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
|
||||||
* http://wordpress.fx-world.org
|
* http://wordpress.fx-world.org
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vram.h"
|
#include "vram.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// Configure the memory to be managed
|
// Configure the memory to be managed
|
||||||
#define __MEM_SIZE 0x00200000
|
#define __MEM_SIZE 0x00200000
|
||||||
#define __MEM_START 0x04000000
|
#define __MEM_START 0x04000000
|
||||||
|
|
||||||
// Configure the block size the memory gets subdivided into (page size)
|
// Configure the block size the memory gets subdivided into (page size)
|
||||||
// __MEM_SIZE/__BLOCK_SIZE may not exceed 2^15 = 32768
|
// __MEM_SIZE/__BLOCK_SIZE may not exceed 2^15 = 32768
|
||||||
// The block size also defines the alignment of allocations
|
// 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
|
// 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
|
// however the overhead is also bigger and more memory is wasted
|
||||||
#define __BLOCK_SIZE 512
|
#define __BLOCK_SIZE 512
|
||||||
#define __MEM_BLOCKS (__MEM_SIZE/__BLOCK_SIZE)
|
#define __MEM_BLOCKS (__MEM_SIZE/__BLOCK_SIZE)
|
||||||
#define __BLOCKS(x) ((x+__BLOCK_SIZE-1)/__BLOCK_SIZE)
|
#define __BLOCKS(x) ((x+__BLOCK_SIZE-1)/__BLOCK_SIZE)
|
||||||
#define __BLOCKSIZE(x) ((x+__BLOCK_SIZE-1)&~(__BLOCK_SIZE-1))
|
#define __BLOCKSIZE(x) ((x+__BLOCK_SIZE-1)&~(__BLOCK_SIZE-1))
|
||||||
|
|
||||||
|
|
||||||
// A MEMORY BLOCK ENTRY IS MADE UP LIKE THAT:
|
// A MEMORY BLOCK ENTRY IS MADE UP LIKE THAT:
|
||||||
// bit: 31 32 30 - 15 14-0
|
// bit: 31 32 30 - 15 14-0
|
||||||
// free block prev size
|
// free block prev size
|
||||||
//
|
//
|
||||||
// bit 31: free bit, indicating if block is allocated or not
|
// 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: 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 30-15: block index of previous block
|
||||||
// bit 14- 0: size of current 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
|
// 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_SIZE(x) ((x & 0x7FFF))
|
||||||
#define __BLOCK_GET_PREV(x) ((x >> 15) & 0x7FFF)
|
#define __BLOCK_GET_PREV(x) ((x >> 15) & 0x7FFF)
|
||||||
#define __BLOCK_GET_FREE(x) ((x >> 31))
|
#define __BLOCK_GET_FREE(x) ((x >> 31))
|
||||||
#define __BLOCK_GET_BLOCK(x) ((x >> 30) & 0x1)
|
#define __BLOCK_GET_BLOCK(x) ((x >> 30) & 0x1)
|
||||||
#define __BLOCK_SET_SIZE(x,y) x=((x & ~0x7FFF) | ((y) & 0x7FFF))
|
#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_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_PREV(x,y) x=((x & ~0x3FFF8000) | (((y) & 0x7FFF)<<15))
|
||||||
#define __BLOCK_SET_FREE(x,y) x=((x & 0x7FFFFFFF) | (((y) & 0x1)<<31))
|
#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_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_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 __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))
|
#define __BLOCK0 ((__MEM_BLOCKS) | (1<<31) | (1<<30))
|
||||||
|
|
||||||
|
|
||||||
unsigned int __mem_blocks[__MEM_BLOCKS] = { 0 };
|
unsigned int __mem_blocks[__MEM_BLOCKS] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
static int __largest_update = 0;
|
static int __largest_update = 0;
|
||||||
static int __largest_block = __MEM_BLOCKS;
|
static int __largest_block = __MEM_BLOCKS;
|
||||||
static int __mem_free = __MEM_BLOCKS;
|
static int __mem_free = __MEM_BLOCKS;
|
||||||
|
|
||||||
|
|
||||||
inline void* vrelptr( void *ptr )
|
inline void* vrelptr( void *ptr )
|
||||||
{
|
{
|
||||||
return (void*)((unsigned int)ptr & ~__MEM_START);
|
return (void*)((unsigned int)ptr & ~__MEM_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void* vabsptr( void *ptr )
|
inline void* vabsptr( void *ptr )
|
||||||
{
|
{
|
||||||
return (void*)((unsigned int)ptr | __MEM_START);
|
return (void*)((unsigned int)ptr | __MEM_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void __find_largest_block()
|
static void __find_largest_block()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
__largest_block = 0;
|
__largest_block = 0;
|
||||||
while (i<__MEM_BLOCKS)
|
while (i<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>__largest_block)
|
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>__largest_block)
|
||||||
__largest_block = csize;
|
__largest_block = csize;
|
||||||
i += csize;
|
i += csize;
|
||||||
}
|
}
|
||||||
__largest_update = 0;
|
__largest_update = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
void __memwalk()
|
void __memwalk()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||||
while (i<__MEM_BLOCKS)
|
while (i<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
printf("BLOCK %i:\n", i);
|
printf("BLOCK %i:\n", i);
|
||||||
printf(" free: %i\n", __BLOCK_GET_FREEBLOCK(__mem_blocks[i]));
|
printf(" free: %i\n", __BLOCK_GET_FREEBLOCK(__mem_blocks[i]));
|
||||||
printf(" size: %i\n", __BLOCK_GET_SIZE(__mem_blocks[i]));
|
printf(" size: %i\n", __BLOCK_GET_SIZE(__mem_blocks[i]));
|
||||||
printf(" prev: %i\n", __BLOCK_GET_PREV(__mem_blocks[i]));
|
printf(" prev: %i\n", __BLOCK_GET_PREV(__mem_blocks[i]));
|
||||||
i+=__BLOCK_GET_SIZE(__mem_blocks[i]);
|
i+=__BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void* valloc( size_t size )
|
void* valloc( size_t size )
|
||||||
{
|
{
|
||||||
// Initialize memory block, if not yet done
|
// Initialize memory block, if not yet done
|
||||||
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
if (__mem_blocks[0]==0) __mem_blocks[0] = __BLOCK0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
int bsize = __BLOCKS(size);
|
int bsize = __BLOCKS(size);
|
||||||
|
|
||||||
if (__largest_update==0 && __largest_block<bsize)
|
if (__largest_update==0 && __largest_block<bsize)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||||
#endif
|
#endif
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("allocating %i bytes, in %i blocks\n", size, bsize);
|
printf("allocating %i bytes, in %i blocks\n", size, bsize);
|
||||||
#endif
|
#endif
|
||||||
// Find smallest block that still fits the requested size
|
// Find smallest block that still fits the requested size
|
||||||
int bestblock = -1;
|
int bestblock = -1;
|
||||||
int bestblock_prev = 0;
|
int bestblock_prev = 0;
|
||||||
int bestblock_size = __MEM_BLOCKS+1;
|
int bestblock_size = __MEM_BLOCKS+1;
|
||||||
while (i<__MEM_BLOCKS)
|
while (i<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
int csize = __BLOCK_GET_SIZE(__mem_blocks[i]);
|
||||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>=bsize)
|
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[i])==3 && csize>=bsize)
|
||||||
{
|
{
|
||||||
if (csize<bestblock_size)
|
if (csize<bestblock_size)
|
||||||
{
|
{
|
||||||
bestblock = i;
|
bestblock = i;
|
||||||
bestblock_prev = j;
|
bestblock_prev = j;
|
||||||
bestblock_size = csize;
|
bestblock_size = csize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (csize==bsize)
|
if (csize==bsize)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
j = i;
|
j = i;
|
||||||
i += csize;
|
i += csize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestblock<0)
|
if (bestblock<0)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
printf("Not enough memory to allocate %i bytes (largest: %i)!\n",size,vlargestblock());
|
||||||
#endif
|
#endif
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
i = bestblock;
|
i = bestblock;
|
||||||
j = bestblock_prev;
|
j = bestblock_prev;
|
||||||
int csize = bestblock_size;
|
int csize = bestblock_size;
|
||||||
__mem_blocks[i] = __BLOCK_MAKE(bsize,j,0,1);
|
__mem_blocks[i] = __BLOCK_MAKE(bsize,j,0,1);
|
||||||
|
|
||||||
int next = i+bsize;
|
int next = i+bsize;
|
||||||
if (csize>bsize && next<__MEM_BLOCKS)
|
if (csize>bsize && next<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
__mem_blocks[next] = __BLOCK_MAKE(csize-bsize,i,1,1);
|
__mem_blocks[next] = __BLOCK_MAKE(csize-bsize,i,1,1);
|
||||||
int nextnext = i+csize;
|
int nextnext = i+csize;
|
||||||
if (nextnext<__MEM_BLOCKS)
|
if (nextnext<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], next);
|
__BLOCK_SET_PREV(__mem_blocks[nextnext], next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__mem_free -= bsize;
|
__mem_free -= bsize;
|
||||||
if (__largest_block==csize) // if we just allocated from one of the largest blocks
|
if (__largest_block==csize) // if we just allocated from one of the largest blocks
|
||||||
{
|
{
|
||||||
if ((csize-bsize)>(__mem_free/2))
|
if ((csize-bsize)>(__mem_free/2))
|
||||||
__largest_block = (csize-bsize); // there can't be another largest block
|
__largest_block = (csize-bsize); // there can't be another largest block
|
||||||
else
|
else
|
||||||
__largest_update = 1;
|
__largest_update = 1;
|
||||||
}
|
}
|
||||||
return ((void*)(__MEM_START + (i*__BLOCK_SIZE)));
|
return ((void*)(__MEM_START + (i*__BLOCK_SIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void vfree( void* ptr )
|
void vfree( void* ptr )
|
||||||
{
|
{
|
||||||
if (ptr==0) return;
|
if (ptr==0) return;
|
||||||
|
|
||||||
int block = ((unsigned int)ptr - __MEM_START)/__BLOCK_SIZE;
|
int block = ((unsigned int)ptr - __MEM_START)/__BLOCK_SIZE;
|
||||||
if (block<0 || block>__MEM_BLOCKS)
|
if (block<0 || block>__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Block is out of range: %i (0x%x)\n", block, (int)ptr);
|
printf("Block is out of range: %i (0x%x)\n", block, (int)ptr);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int csize = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
int csize = __BLOCK_GET_SIZE(__mem_blocks[block]);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("freeing block %i (0x%x), size: %i\n", block, (int)ptr, csize);
|
printf("freeing block %i (0x%x), size: %i\n", block, (int)ptr, csize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[block])!=1 || csize==0)
|
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[block])!=1 || csize==0)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf("Block was not allocated!\n");
|
printf("Block was not allocated!\n");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark block as free
|
// Mark block as free
|
||||||
__BLOCK_SET_FREE(__mem_blocks[block],1);
|
__BLOCK_SET_FREE(__mem_blocks[block],1);
|
||||||
__mem_free += csize;
|
__mem_free += csize;
|
||||||
|
|
||||||
int next = block+csize;
|
int next = block+csize;
|
||||||
// Merge with previous block if possible
|
// Merge with previous block if possible
|
||||||
int prev = __BLOCK_GET_PREV(__mem_blocks[block]);
|
int prev = __BLOCK_GET_PREV(__mem_blocks[block]);
|
||||||
if (prev<block)
|
if (prev<block)
|
||||||
{
|
{
|
||||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[prev])==3)
|
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[prev])==3)
|
||||||
{
|
{
|
||||||
__BLOCK_ADD_SIZE(__mem_blocks[prev], csize);
|
__BLOCK_ADD_SIZE(__mem_blocks[prev], csize);
|
||||||
__BLOCK_SET_BLOCK(__mem_blocks[block],0); // mark current block as inter block
|
__BLOCK_SET_BLOCK(__mem_blocks[block],0); // mark current block as inter block
|
||||||
if (next<__MEM_BLOCKS)
|
if (next<__MEM_BLOCKS)
|
||||||
__BLOCK_SET_PREV(__mem_blocks[next], prev);
|
__BLOCK_SET_PREV(__mem_blocks[next], prev);
|
||||||
block = prev;
|
block = prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge with next block if possible
|
// Merge with next block if possible
|
||||||
if (next<__MEM_BLOCKS)
|
if (next<__MEM_BLOCKS)
|
||||||
{
|
{
|
||||||
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[next])==3)
|
if (__BLOCK_GET_FREEBLOCK(__mem_blocks[next])==3)
|
||||||
{
|
{
|
||||||
__BLOCK_ADD_SIZE(__mem_blocks[block], __BLOCK_GET_SIZE(__mem_blocks[next]));
|
__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
|
__BLOCK_SET_BLOCK(__mem_blocks[next],0); // mark next block as inter block
|
||||||
int nextnext = next + __BLOCK_GET_SIZE(__mem_blocks[next]);
|
int nextnext = next + __BLOCK_GET_SIZE(__mem_blocks[next]);
|
||||||
if (nextnext<__MEM_BLOCKS)
|
if (nextnext<__MEM_BLOCKS)
|
||||||
__BLOCK_SET_PREV(__mem_blocks[nextnext], block);
|
__BLOCK_SET_PREV(__mem_blocks[nextnext], block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update if a new largest block emerged
|
// Update if a new largest block emerged
|
||||||
if (__largest_block<__BLOCK_GET_SIZE(__mem_blocks[block]))
|
if (__largest_block<__BLOCK_GET_SIZE(__mem_blocks[block]))
|
||||||
{
|
{
|
||||||
__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
|
__largest_update = 0; // No update necessary any more, because update only necessary when largest has shrinked at most
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t vmemavail()
|
size_t vmemavail()
|
||||||
{
|
{
|
||||||
return __mem_free * __BLOCK_SIZE;
|
return __mem_free * __BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t vlargestblock()
|
size_t vlargestblock()
|
||||||
{
|
{
|
||||||
if (__largest_update) __find_largest_block();
|
if (__largest_update) __find_largest_block();
|
||||||
return __largest_block * __BLOCK_SIZE;
|
return __largest_block * __BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user