view scn2k/scn2k_grp.h @ 74:f8751d74918b default tip

Remove “duplicate” functions as they can be remplaced by a nearly-identical existing function.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 02 Apr 2011 19:13:54 +0200
parents 1fd20d231376
children
line wrap: on
line source

/*
 * Copyright (c) 2009 Thibaut GIRKA
 * Copyright (c) 2004-2006  Kazunori "jagarl" Ueno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __SCN2K_GRP_H__
#define __SCN2K_GRP_H__

#include <set>

#include "scn2k_cmd.h"
#include "window/widget.h"

using namespace std;

void dprintf(const char* fmt, ...); //FIXME
void eprintf(const char* fmt, ...); //FIXME

struct SEL {
	Rect from;
	Rect to;
	int time;
	int sel_no;
	int args[8];
	SEL() : from(0,0), to(0,0) {}
};

struct GrpObj;
typedef std::map<int, GrpObj> GrpObjMap;

/*******************************************************************
** GrpObj(interface)
*/

struct GrpObj {
	string name;
	string gan_name;
	PicContainer* pic_parent;
	PicBase* picture;
	WidAnmTime* anm;
	int _posx, _posy;
	int posx[9], posy[9];
	Rect clip_area;
	unsigned char alpha;
	int order;
	int surface_num;

	GrpObjMap children_obj;

	string print_moji;
	int print_size, print_r, print_b, print_g;

	int dig_number, dig_digit;

	// zoom / rotate 関係
	int zoomx, zoomy; // 256 で 1 倍
	int rotate; // 0-360度

	vector<Rect> src_pos;
	enum GrpType { FILLRECT = 1, FILE = 2, GAN = 3, MOJI = 4, DIGIT = 5} gtype;
	enum Attribute { NONE=0, WIPEON=1, BLIT_ADD=2, HIDDEN=4,
		UPDATE_PICTURE = 16, UPDATE_POS = 32, UPDATE_ALPHA = 64, UPDATE_SNUM = 128, UPDATE_CLIP = 256, UPDATE_VISIBLE = 512,
		UPDATE_ALL = (UPDATE_PICTURE | UPDATE_POS | UPDATE_ALPHA | UPDATE_SNUM | UPDATE_CLIP | UPDATE_VISIBLE),
		ANM_PLAYSTART = 0x8000, ANM_PLAYING = 0x10000,
		DIG_ZERO = 0x10000*2, DIG_SIGN = 0x10000*4, DIG_PACK=0x10000*8,DIG_SPACE=0x10000*16
		};
	Attribute attr;

	GrpObj(void);
	~GrpObj(void);

	void SetPos(int index, int x, int y);
	void GetPos(int index, int& x, int& y);
	int PosX(void);
	int PosY(void);
	void SetAlpha(void);
	void SetAlpha(int alpha);
	void SetSurfaceNum(int num = -1);
	void SetZoomRotate(int zoomx=-1, int zoomy=-1, int rotate=-1);
	void SetClipArea(int x, int y, int width, int height);
	void GetSrcGeom(int& width, int& height);
	void SetUpdate(void);
	void UpdateMoji(void);
	void UpdateDigit(void);
	void UpdateSurface(void);
	void ZoomRotate(void);
	void Refresh(GrpObj& parent_obj);
	void _debug_Dump(int, int);
	void Update(void);
	void CreateSurface(PicContainer* parent);
	void CreateGan(Event::Container& event, int event_number);
	void CreateGanSpecial(Event::Container& event, int event_number, int time);
	PicBase* DeletePic(void);
};


/*******************************************************************
** Grp
*/

class Grp : public CommandHandler {
#define MAXPDT 256
#define WORKPDT 255
	private:
		void CreateObj(int number);
		void CreateSubObj(int grp_num, int number);
		void ZMoveObj(int number);
		void SetObjChanged(int number);
		void SwapObj(int a1, int a2);
		void DeleteObjPic(int num);// object の surface のみ削除
		void DeleteSubObjPic(int grp_num, int num);
		void DeleteObj(int num);
		void DeleteSubObj(int grp_num, int num);
		void RefreshObj(void);

		Surface* Dsurface(int pdt);
		Surface* Ssurface(int pdt);

		// cgmode 用画像処理関連
		void LoadCgm(void);

	public:
		Grp(Event::Container& _event, PicContainer& _parent, const Flags& _flag, set<int>& _cgm_data);
		~Grp();
		bool Wait(unsigned int current_time, Cmd& cmd);
		void Exec(Cmd& cmd);
		void InitSel(void);
		void Save(std::string& str);
		void Load(const char* str);
		void SaveSys(std::string& str);
		void LoadSys(const char* str);
		void SetSkipMode(SkipMode _mode);
		void LoadSurface(const char* str, int pdt);

	private:
		void LoadSurface(const char* str);
		void LoadSurface(void);
		void AddSurface(const char* str);

		void StartAnm(int type);
		void StartShake(int total, const int* pattern);
		void AbortAnm(void);
		static bool Pressed(int x, int y, void* pointer);

		GrpObj* GetGraphicObj(int grp, bool fg=true);
		GrpObj* GetGraphicObj(int grp, int index, bool fg=true);
		GrpObj* GetGraphicObjVarMode(Cmd& cmd, int &base_arg, bool fg=true);

		// Opcode handling
		void impl_stackClear(Cmd& cmd);
		void impl_grpBuffer(Cmd& cmd);
		void impl_grpMulti(Cmd &cmd);
		void impl_grpOpen(Cmd &cmd);
		void impl_shake(Cmd &cmd);
		void impl_grpCopy(Cmd &cmd);
		void impl_recFill(Cmd &cmd);
		void impl_recCopy(Cmd &cmd);
		void impl_recAdd(Cmd &cmd);
		void impl_grpPan(Cmd &cmd);
		void impl_snmPlay(Cmd &cmd);
		void impl_snmBgScroll(Cmd &cmd);
		void impl_cgGet(Cmd &cmd);
		void impl_cgStatus(Cmd &cmd);
		void impl_objClear(Cmd &cmd);
		void impl_createObj(Cmd &cmd);
		void impl_gan(Cmd &cmd);
		void impl_objSetPos(Cmd &cmd);
		void impl_objAlpha(Cmd &cmd);
		void impl_objShow(Cmd &cmd);
		void impl_objColour(Cmd &cmd);
		void impl_objComposite(Cmd &cmd);
		void impl_objSetText(Cmd &cmd);
		void impl_objTextOpts(Cmd &cmd);
		void impl_objOrder(Cmd &cmd);
		void impl_objDispArea(Cmd &cmd);
		void impl_objSetDigits(Cmd &cmd);
		void impl_objNumOpts(Cmd &cmd);
		void impl_objPattNo(Cmd &cmd);
		void impl_objScale(Cmd &cmd);
		void impl_objRotate(Cmd &cmd);
		void impl_objPosDims(Cmd &cmd);
		void impl_refresh(Cmd &cmd);
		void impl_bgmLoop(Cmd &cmd);
		void impl_bgmStop(Cmd &cmd);
		void impl_playWav(Cmd &cmd);
		void impl_playSE(Cmd &cmd);
		void impl_stopWav(Cmd &cmd);
		void impl_SetVolMod(Cmd &cmd);
		void impl_GetVolMod(Cmd &cmd);
		void impl_koePlay(Cmd &cmd);
		void impl_movPlay(Cmd &cmd);

	public:
		class AyuSysConfig *config;

	private:
		Event::Container& event;
		const Flags& flags;
		PicBase* screen;
		PicBase* screen_front;
		Surface* surface, *surface_update;

		Surface* dsurface[MAXPDT]; // 書き込み可能な Surface
		Surface* ssurface[MAXPDT]; // ファイルの内容等、読み込みのみ可能な状態の Surface
		PicContainer& parent;

		// 画像効果の保存用
		WidAnmTime* anm1, *anm2;
		typedef enum { NORMAL, WAIT_ANM, WAIT_SHAKE, WAIT_SE, WAIT_MOVIE} Status;
		Status status;
		SkipMode skip_mode;

		std::string bg_name;
		std::map<int, SEL> anmtype;
		GrpObjMap grpobj;
		GrpObjMap bs_obj;

		std::map<std::string, int> cgm_info;
		set<int>& cgm_data;
		int cgm_size;

		class MuSys *music;

		std::set<int> changed_obj;
		string reserved_load_surface0;
		vector<PicBase*> deleted_pic;
};


/******************************************************************
**
**	class ScnGrp*
*/
/* Princess Bride: 背景画の一部のみ移動、の実装 */

struct ScnGrpMove : public WidAnmTime {
	Surface* dest;
	Surface* src;
	PicRoot& root;
	Rect dest_r, from, to;
	ScnGrpMove(Event::Container& container, PicBase* _pic, PicRoot& root, Surface* dest, const Rect& _dest_r, Surface* src, const Rect& from, const Rect& to, int total_time);
	void Exec(int count);
};

/* Princess Bride: カードがおちるアニメーション */

struct ScnGrpAnmAtom {
	string name;
	int time;
	ScnGrpAnmAtom(const char* _n, int _t) : name(_n), time(_t) {}
};

struct ScnGrpAnm : public WidAnmTime, vector<ScnGrpAnmAtom> {
	Grp& owner;
	ScnGrpAnm(Event::Container& container, PicBase* _pic, Grp& _owner) :
		WidAnmTime(container, _pic, 0), owner(_owner) {
	}
	void CalcTotal(void);
	void Exec(int count);
};

#endif