OSFRMRES.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. //Filename : OSFRMRES.CPP
  21. //Description : Object Sprite Frame Resource
  22. #include <ALL.h>
  23. #include <OSTR.h>
  24. #include <OSYS.h>
  25. #include <OGAMESET.h>
  26. #include <OSFRMRES.h>
  27. //-------- define file name -----------//
  28. #define SPRITE_FRAME_DB "SFRAME"
  29. //-------- Begin of function SpriteFrameRes::init ---------//
  30. void SpriteFrameRes::init()
  31. {
  32. deinit();
  33. //------- load database information --------//
  34. load_info();
  35. init_flag=1;
  36. }
  37. //--------- End of function SpriteFrameRes::init ----------//
  38. //-------- Begin of function SpriteFrameRes::deinit ---------//
  39. void SpriteFrameRes::deinit()
  40. {
  41. if( init_flag )
  42. {
  43. delete sprite_frame_array;
  44. init_flag=0;
  45. }
  46. }
  47. //--------- End of function SpriteFrameRes::deinit ----------//
  48. //------- Begin of function SpriteFrameRes::load_info ---------//
  49. void SpriteFrameRes::load_info()
  50. {
  51. Database *dbSpriteFrame = game_set.open_db(SPRITE_FRAME_DB);
  52. SpriteFrameRec *frameRec;
  53. SpriteFrame *spriteFrame;
  54. int i;
  55. sprite_frame_count = dbSpriteFrame->rec_count();
  56. sprite_frame_array = new SpriteFrame[sprite_frame_count];
  57. memset( sprite_frame_array, 0, sizeof(SpriteFrame)*sprite_frame_count );
  58. //--------- read in frame information ---------//
  59. for( i=0 ; i<dbSpriteFrame->rec_count() ; i++ )
  60. {
  61. frameRec = (SpriteFrameRec*) dbSpriteFrame->read(i+1);
  62. spriteFrame = sprite_frame_array+i;
  63. spriteFrame->offset_x = m.atoi(frameRec->offset_x, frameRec->OFFSET_LEN);
  64. spriteFrame->offset_y = m.atoi(frameRec->offset_y, frameRec->OFFSET_LEN);
  65. spriteFrame->width = m.atoi(frameRec->width , frameRec->WIDTH_LEN);
  66. spriteFrame->height = m.atoi(frameRec->height, frameRec->HEIGHT_LEN);
  67. memcpy( &spriteFrame->bitmap_offset, frameRec->bitmap_offset, sizeof(long) );
  68. }
  69. }
  70. //-------- End of function SpriteFrameRes::load_info ---------//
  71. #ifdef DEBUG
  72. //-------- Begin of function SpriteFrameRes::operator[] -------//
  73. SpriteFrame* SpriteFrameRes::operator[](int recNo)
  74. {
  75. if( recNo<1 || recNo>sprite_frame_count )
  76. err.run( "SpriteFrameRes::operator[]" );
  77. return sprite_frame_array+recNo-1;
  78. }
  79. //--------- End of function SpriteFrameRes::operator[] --------//
  80. #endif