File: CDefHandler.h

package info (click to toggle)
vcmi 0.99%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: stretch
  • size: 10,264 kB
  • ctags: 16,826
  • sloc: cpp: 121,945; objc: 248; sh: 193; makefile: 28; python: 13; ansic: 9
file content (104 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once

#include "../lib/vcmi_endian.h"

struct SDL_Surface;
struct SDL_Color;

/*
 * CDefHandler.h, part of VCMI engine
 *
 * Authors: listed in file AUTHORS in main folder
 *
 * License: GNU General Public License v2.0 or later
 * Full text of license available in license.txt file, in main folder
 *
 */

struct Cimage
{
	int groupNumber;
	std::string imName; //name without extension
	SDL_Surface * bitmap;
};

// Def entry in file. Integer fields are all little endian and will
// need to be converted.
struct SDefEntryBlock
{
	ui32 unknown1;
	ui32 totalInBlock;
	ui32 unknown2;
	ui32 unknown3;
	ui8 data[0];
} PACKED_STRUCT;

// Def entry in file. Integer fields are all little endian and will
// need to be converted.
struct SDefEntry
{
	ui32 DEFType;
	ui32 width;
	ui32 height;
	ui32 totalBlocks;

	struct {
		ui8 R;
		ui8 G;
		ui8 B;
	} palette[256];

	// SDefEntry is followed by a series of SDefEntryBlock
	// This is commented out because VC++ doesn't accept C99 syntax.
	//struct SDefEntryBlock blocks[];
} PACKED_STRUCT;

// Def entry in file. Integer fields are all little endian and will
// need to be converted.
struct SSpriteDef
{
	ui32 prSize;
	ui32 defType2;
	ui32 FullWidth;
	ui32 FullHeight;
	ui32 SpriteWidth;
	ui32 SpriteHeight;
	ui32 LeftMargin;
	ui32 TopMargin;
} PACKED_STRUCT;

class CDefEssential //DefHandler with images only
{
public:
	std::vector<Cimage> ourImages;
	~CDefEssential(); //d-tor
};

class CDefHandler
{
private:
	ui32 DEFType;
	struct SEntry
	{
		std::string name;
		int offset;
		int group;
	} ;
	std::vector<SEntry> SEntries ;
	
	void openFromMemory(ui8 * table, const std::string & name);	
	SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const SDL_Color * palette) const;
public:
	int width, height; //width and height
	std::string defName;
	std::vector<Cimage> ourImages;
	bool notFreeImgs;

	CDefHandler(); //c-tor
	~CDefHandler(); //d-tor
	
	CDefEssential * essentialize();

	static CDefHandler * giveDef(const std::string & defName);
	static CDefEssential * giveDefEss(const std::string & defName);
};