1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename    : OSFRMRES.CPP
22 //Description : Object Sprite Frame Resource
23 
24 #include <ALL.h>
25 #include <OSTR.h>
26 #include <OSYS.h>
27 #include <OGAMESET.h>
28 #include <OSFRMRES.h>
29 
30 //-------- define file name -----------//
31 
32 #define SPRITE_FRAME_DB    "SFRAME"
33 
34 
35 //-------- Begin of function SpriteFrameRes::init ---------//
36 
init()37 void SpriteFrameRes::init()
38 {
39 	deinit();
40 
41 	//------- load database information --------//
42 
43 	load_info();
44 
45 	init_flag=1;
46 }
47 //--------- End of function SpriteFrameRes::init ----------//
48 
49 
50 //-------- Begin of function SpriteFrameRes::deinit ---------//
51 
deinit()52 void SpriteFrameRes::deinit()
53 {
54 	if( init_flag )
55 	{
56 		delete[] sprite_frame_array;
57 
58 		init_flag=0;
59 	}
60 }
61 //--------- End of function SpriteFrameRes::deinit ----------//
62 
63 
64 //------- Begin of function SpriteFrameRes::load_info ---------//
65 
load_info()66 void SpriteFrameRes::load_info()
67 {
68 	Database   		*dbSpriteFrame = game_set.open_db(SPRITE_FRAME_DB);
69 	SpriteFrameRec *frameRec;
70 	SpriteFrame 	*spriteFrame;
71 	int		  		i;
72 
73 	sprite_frame_count = dbSpriteFrame->rec_count();
74 	sprite_frame_array = new SpriteFrame[sprite_frame_count];
75 
76 	memset( sprite_frame_array, 0, sizeof(SpriteFrame)*sprite_frame_count );
77 
78 	//--------- read in frame information ---------//
79 
80 	for( i=0 ; i<dbSpriteFrame->rec_count() ; i++ )
81 	{
82 		frameRec  = (SpriteFrameRec*) dbSpriteFrame->read(i+1);
83 		spriteFrame = sprite_frame_array+i;
84 
85 		spriteFrame->offset_x = misc.atoi(frameRec->offset_x, frameRec->OFFSET_LEN);
86 		spriteFrame->offset_y = misc.atoi(frameRec->offset_y, frameRec->OFFSET_LEN);
87 
88 		spriteFrame->width  = misc.atoi(frameRec->width , frameRec->WIDTH_LEN);
89 		spriteFrame->height = misc.atoi(frameRec->height, frameRec->HEIGHT_LEN);
90 
91 		memcpy( &spriteFrame->bitmap_offset, frameRec->bitmap_offset, sizeof(uint32_t) );
92 	}
93 }
94 //-------- End of function SpriteFrameRes::load_info ---------//
95 
96 
97 #ifdef DYNARRAY_DEBUG_ELEMENT_ACCESS
98 
99 //-------- Begin of function SpriteFrameRes::operator[] -------//
100 
operator [](int recNo)101 SpriteFrame* SpriteFrameRes::operator[](int recNo)
102 {
103 	if( recNo<1 || recNo>sprite_frame_count )
104 		err.run( "SpriteFrameRes::operator[]" );
105 
106 	return sprite_frame_array+recNo-1;
107 }
108 
109 //--------- End of function SpriteFrameRes::operator[] --------//
110 
111 #endif
112