SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送

BMLBulletML.h

00001 #ifndef BML_BULLETML_H__
00002 #define BML_BULLETML_H__
00003 
00004 #include "BMLBulletPool.h"
00005 #include <DxEx/DxExFixedData.h>
00006 
00007 #ifndef M_PI
00008 #define M_PI 3.141592
00009 #endif
00010 
00011 namespace bml{
00012 //dxexを使う
00013 using namespace dxex;
00014 
00016 typedef bml_array_in_c simple_array_type;
00018 typedef bml_array_in_c action_array_type;
00019 
00020 //プロトタイプ宣言
00021 class BMLRunner_in_c;
00022 
00024 typedef smart_ptr<BMLRunner_in_c> smartaction_ptr;
00026 typedef static_array_onebyone_ex<smartaction_ptr> smartaction_ptr_container;
00028 typedef smartaction_ptr_container::handle sa_ptr_handle;
00029 
00030 //typedef std::deque<action_array_type::handle> al_free_queue;
00032 typedef std::pair<smartaction_ptr,BML_BULLET_DATA> al_pq_item;
00033 typedef std::deque<al_pq_item> al_push_queue;
00034 
00035 //typedef std::deque<BML_BULLET_DATA> al_push_queue;
00036 
00037 
00038 typedef simple_array_type::iterator simple_iterator;
00039 typedef simple_array_type::handle simple_handle;
00040 typedef action_array_type::iterator action_iterator;
00041 typedef action_array_type::handle action_handle;
00042 
00044 typedef   std::pair<sa_ptr_handle,action_handle> al_fq_item;
00045 
00046 typedef dkutil::set_to_deque_adapter<al_fq_item> al_free_queue;
00047 /*
00048 struct ActionBulletManager{
00049   smartaction_ptr_pool mPool;
00050   action_array_type mActionArray;
00051 
00052 };
00053 */
00054 
00055 
00056 struct BMLStaticData{
00057 
00058 protected:
00060   static simple_array_type bullets;
00062   static action_array_type action_list;
00064   static smartaction_ptr_container sapc;
00065 
00067   static al_free_queue fq;
00069   static al_push_queue pq;
00071   static double mDefaultSpeed;
00073   static int mBulletNum;
00075   static int mFrame;
00077   static void ActionBulletInsertProcess();
00079   static void ActionBulletEraseProcess();
00081   static void ActionBulletRunningProcess();
00082 
00083 public:
00085   static void arrangement_memory(){
00086     ActionBulletRunningProcess();
00087     ActionBulletEraseProcess();
00088     ActionBulletInsertProcess();
00089   }
00090 
00091   simple_iterator begin_s(){return bullets.begin();}
00092   simple_iterator end_s(){return bullets.end();}
00093   action_iterator begin_a(){return action_list.begin();}
00094   action_iterator end_a(){return action_list.end();}
00095   static simple_iterator s_begin_s(){return bullets.begin();}
00096   static simple_iterator s_end_s(){return bullets.end();}
00097   static action_iterator s_begin_a(){return action_list.begin();}
00098   static action_iterator s_end_a(){return action_list.end();}
00099   //配列のMAX添え字をゲット 
00100   static size_t GetSimpleSentinel(){return bullets.max_size();}
00101   static size_t GetActionSentinel(){return action_list.max_size();}
00102   //試し。
00103   //static int RealBulletNum(){ return action_list.size() + bullets.size();}
00104 
00105   //シンプル弾系
00106   static simple_handle PushSimpleBullet(const BML_BULLET_DATA &x);
00107   static void PopSimpleBullet(simple_iterator it);
00108   //アクション弾系
00109   static BML_BULLET_DATA &at_action_bullet(action_handle h){  
00110     return action_list.at(h);
00111   }
00112   static smartaction_ptr &at_action_ptr(sa_ptr_handle h){
00113     return sapc.at(h);
00114   }
00115   static void PushActionBullet(const smartaction_ptr &x,BML_BULLET_DATA &);
00116   static void PopActionBullet(action_iterator it);
00117   static void PopActionBullet(action_handle it);
00118 
00122 
00123   static bool Init(int bulletnum,double bulletspeed,int queuesize=200);
00125   static bool End();
00126   
00127 
00128 
00129   
00130   static int GetFrame(){  return mFrame;}
00131   static void IncFrame(){ mFrame++;}
00132   static void ClearFrame(){ mFrame = 0;}
00133   static int GetBulletNum(){  return mBulletNum;}
00134 
00135   static void SetBulletNum(int n){mBulletNum = n;}
00136   static void IncBulletNum(){mBulletNum++;}
00137   static void DecBulletNum(){mBulletNum--;}
00138   
00139   
00140   static void SetBulletSpeed(double speed){ mDefaultSpeed = speed;}
00141   static double GetBulletSpeed(){return mDefaultSpeed;}
00142 
00143 
00144 
00145 };
00146 
00147 extern BMLStaticData gBMLData;
00148 
00149 
00150 inline BMLStaticData &GetBMLStaticData(){
00151   return gBMLData;
00152 }
00154 inline void InitBulletWork(BML_BULLET_DATA *work,int flag,
00155                            double x,double y,
00156                            double ax,double ay,double direction,double speed,
00157                            int action_handle,
00158                            const char *data,size_t datasize)
00159 {
00160   //この作業・・・C言語時代を思い出す〜〜
00161   work->x = x;
00162   work->y = y;
00163   work->accelx = ax;
00164   work->accely = ay;
00165   work->direction = direction;
00166   work->flag = flag;
00167   work->pos = -1;
00168   work->action_handle = action_handle;
00169   work->speed = speed;
00170   DKUTIL_NOT_ASSERT(datasize > sizeof(work->work));
00171   memcpy(work->work,data,sizeof(work->work));
00172 }
00173 inline bool CreateActionBulletHelper(smartaction_ptr ptr,BML_BULLET_DATA &rddata){
00174 
00175   BML_BULLET_DATA data;
00176   BML_BULLET_DATA &rd =  rddata;
00177 
00178   InitBulletWork(&data,ebmlACTION_BULLET,rd.x,rd.y,
00179     rd.accelx,rd.accely,rd.direction,rd.speed,
00180     NULL,//PushActionBulletでポインタへのIDを指定するのでNULL
00181     rd.work,sizeof(rd.work));
00182 
00183   GetBMLStaticData().PushActionBullet(ptr,data);
00184   return true;//多分^^;
00185 }
00186 
00187 
00188 
00189 //extern double jx,jy;
00190 class BMLRunner_in_c : public BulletMLRunner 
00191 {
00192 public:
00193   //tagBulletData getBulletWork();
00194   typedef action_handle handle;
00195   handle mIt;
00197   int State;
00198   BML_GETPLAYER_DATA_CALLBACK mCallback;
00199   int getState(){return State;}
00200   void setState(int s){State=s;}
00201   double getX(){return getBulletWork().x;}
00202   double getY(){return getBulletWork().y;}
00203   /*virtual void dispose(){
00204     //別に何もしないよ〜〜。
00205   }
00206   virtual void *get_deleter(std::type_info const & ti){
00207     return NULL;
00208   }*/
00209   BML_BULLET_DATA &getBulletWork(){return gBMLData.at_action_bullet(mIt);}
00210   
00211 public:
00212   void Move(){
00213     BML_BULLET_DATA &rd = getBulletWork();
00214     double speed = GetBMLStaticData().GetBulletSpeed();
00215 #ifdef NDEBUG
00216     rd.x += getBulletSpeedX() * speed;
00217     rd.y += getBulletSpeedY() * speed;
00218 #else
00219     double speedX = getBulletSpeedX();
00220     double speedY =  getBulletSpeedY();
00221     double tmpX = speedX * speed;
00222     double tmpY = speedY * speed;
00223     rd.x += tmpX;
00224     rd.y += tmpY;
00225     BML_BULLET_DATA *data = GetBMLStaticData().s_begin_a();
00226 
00227 #endif
00228 
00229 
00230   }
00231   void setHandle(handle it){
00232      mIt = it;
00233   }
00234   handle getHandle(){
00235     return mIt;
00236   }
00237   BMLRunner_in_c(BulletMLParser* bulletml,
00238     BML_GETPLAYER_DATA_CALLBACK cback) : BulletMLRunner(bulletml) {
00239     //これらは後で入れる事にする。
00240     //setState( ebmlRUN );
00241     //getBulletWork().x = x0;
00242     //getBulletWork().y = y0;
00243     //getBulletWork().direction=180;
00244     //getBulletWork().speed=0;
00245     //getBulletWork().accelx=0;
00246     //getBulletWork().accely=0;
00247     DKUTIL_NOT_ASSERT(cback == NULL);
00248     mCallback = cback;
00249   }
00250   BMLRunner_in_c(BulletMLState* state,
00251     BML_GETPLAYER_DATA_CALLBACK cback) : BulletMLRunner(state) {
00252     //これらは後で入れる事にする。
00253     //setState( ebmlRUN );
00254     //getBulletWork().x = x0;
00255     //getBulletWork().y = y0;
00256     //getBulletWork().direction=dir0;
00257     //getBulletWork().speed=spd0;
00258     //getBulletWork().accelx=0;
00259     //getBulletWork().accely=0;
00260 
00261     DKUTIL_NOT_ASSERT(cback == NULL);
00262     mCallback = cback;
00263   }
00264   //~BMLRunner_in_c() {}
00265   double getBulletDirection() {return getBulletWork().direction;}
00266   inline int getX(RECT &collision){
00267     return collision.left + ((collision.right - collision.left) / 2);// >> 1
00268   }
00269   inline int getY(RECT &collision){
00270     return collision.top + ((collision.bottom - collision.top)  / 2);// >> 1
00271   }
00272   double getAimDirection() {
00273     int dx, dy;
00274     BML_PLAYER_CALLBACK_DATA player;
00275     if(FALSE==mCallback(&player)){
00276       dx = 340;//いい加減^^;;;
00277       dy = 240;
00278     }else{
00279       dx = getX(player.collision);
00280       dy = getY(player.collision);
00281     }
00282     //dODS("px=%d,py=%d,",dx,dy);
00283     BML_BULLET_DATA &rd = getBulletWork();
00284     dx = (int)(rd.x-dx);
00285     dy = (int)(dy-rd.y);
00286     //dkutil::dODS("dx=%d,dy=%d",dx,dy);
00287     
00288 
00289 
00290     if((dx==0)&&(dy==0)) return 180;
00291     else{
00292 # ifdef NDEBUG
00293       return atan2((double)dx, (double)dy)/M_PI*180 + 180;
00294 # else
00295       double d = atan2((double)dx, (double)dy)/M_PI*180 + 180;
00296       //dODS("atan2=%f",d);
00297       return d;
00298 # endif
00299     }
00300   }
00301 //  double getAimDirection() {return 0;}
00302   double getBulletSpeed() {return getBulletWork().speed;}
00303   double getDefaultSpeed() {
00304     return GetBMLStaticData().GetBulletSpeed();
00305     //return 1;
00306   }
00307   double getRank() {return 0.5;}
00308   void createSimpleBullet(double direction, double speed) {
00309     //int n = akiBullet(bmax);
00310     BML_BULLET_DATA b;
00311     //b.flag = 1;
00312     b.x = getBulletWork().x;
00313     b.y = getBulletWork().y;
00314     b.accelx = sin(direction/180*3.14)*speed;
00315     b.accely = -cos(direction/180*3.14)*speed;
00316     GetBMLStaticData().PushSimpleBullet(b);
00317 //#error ここも
00318 
00319     
00320   }
00321   void createBullet(BulletMLState* state, double dir, double spd) 
00322   {
00323     smartaction_ptr ptr(
00324       new BMLRunner_in_c(state,mCallback)
00325       ); 
00326     BML_BULLET_DATA data;
00327     BML_BULLET_DATA &rd =  getBulletWork();
00328 
00329     InitBulletWork(&data,ebmlACTION_BULLET,rd.x,rd.y,
00330       rd.accelx,rd.accely,dir,spd,
00331       NULL,//PushActionBulletでポインタへのIDを指定するのでNULL
00332       rd.work,sizeof(rd.work));
00333 
00334     GetBMLStaticData().PushActionBullet(ptr,data);
00335     
00336     //CreateActionBulletHelper(ptr,getBulletWork());
00337       /*  BML_BULLET_DATA data;
00338     BML_BULLET_DATA &rd =  getBulletWork();
00339     InitBulletWork(&data,ebmlACTION_BULLET,rd.x,rd.y,
00340       rd.accelx,rd.accely,rd.direction,rd.speed,
00341       NULL,//PushActionBulletでポインタへのIDを指定するのでNULL
00342       rd.work,sizeof(rd.work));
00343 
00344     handle h = GetBMLStaticData().PushActionBullet(ptr,&data);
00345   */
00346     //getBulletWork().x,getBulletWork().y,dir,spd
00347 //#error ここで
00348     //GetBMLStaticData().at_action(it)->setHandle(it); 
00349   }
00350     
00351   int getTurn() {return GetBMLStaticData().GetFrame();}
00352   void doVanish() {
00353     GetBMLStaticData().PopActionBullet(mIt);
00354   }
00355 
00356 
00357   void doChangeDirection(double direction) { getBulletWork().direction = direction; } 
00358   void doChangeSpeed(double speed) { getBulletWork().speed = speed; }
00359   void doAccelX(double dx) { getBulletWork().accelx = dx; }
00360   void doAccelY(double dy) { getBulletWork().accely = dy; }
00361   double getBulletSpeedX() {
00362     BML_BULLET_DATA &rd = getBulletWork();
00363     return dxex::gTrig.fsin(rd.direction / 180 * 3.14) * rd.speed + rd.accelx;
00364     //return sin(getBulletWork().direction/180*3.14)*getBulletWork().speed  + getBulletWork().accelx; 
00365   }
00366   double getBulletSpeedY() {
00367     BML_BULLET_DATA &rd = getBulletWork();
00368     return -dxex::gTrig.fcos(rd.direction / 180 * 3.14) * rd.speed + rd.accely;
00369     //return -cos(getBulletWork().direction/180*3.14)*getBulletWork().speed + getBulletWork().accely; 
00370   }
00371 
00372 };
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 class BulletMLManager //: public DxExBMLStaticVariable{
00381 {
00382 public:
00383 
00385   typedef dxex::BulletMLParserDxEx BULLETML_PARSER;
00387   typedef smart_ptr<BULLETML_PARSER> DXEX_XMLPARSER_PTR;
00389   typedef dkutil::array_onebyone_ex<DXEX_XMLPARSER_PTR> PARSED_XML_CONTAINER;
00391   typedef  PARSED_XML_CONTAINER::handle xml_handle;
00392   
00393   //typedef BMLRunner::GET_COLLISION_FP GET_COLLISION_FP;
00394 
00395 
00396   typedef BMLStaticData BML_STATIC_DATA;
00397   //typedef BML_STATIC_DATA::simple_handle simple_handle;//弾のハンドル。
00398   //typedef BML_STATIC_DATA::simple_iterator simple_iterator;
00399   //typedef BML_STATIC_DATA::action_iterator action_iterator;
00400   //typedef BML_STATIC_DATA::DATA_TYPE DATA_TYPE;
00401 
00402 
00403 private:
00405   PARSED_XML_CONTAINER mXMLC;
00406 protected:
00407 
00408 public:
00409   struct action_iteration{
00410     typedef action_iterator iterator;
00411     iterator begin(){return BML_STATIC_DATA::s_begin_a();}
00412     iterator end(){return BML_STATIC_DATA::s_end_a();}
00413   };
00414   struct simple_iteration{
00415     typedef simple_iterator iterator;
00416     iterator begin(){return BML_STATIC_DATA::s_begin_s();}
00417     iterator end(){return BML_STATIC_DATA::s_end_s();}
00418   };
00419     //bool empty()const{return BML_STATIC_DATA::empty();}
00420   BulletMLManager(){
00421     //mBmlPool.clear();
00422   }
00423   virtual ~BulletMLManager(){
00424     //clear();
00425 
00426     //GetPool().DoubleEntryKill();
00427     //FreeMemoryHelper();
00428     //GetPool().RealDestructor();
00429   }
00430 //準備系
00431   bool Init(int bulletnum,double bulletspeed,int queuenum){
00432     return BML_STATIC_DATA::Init(bulletnum,bulletspeed,queuenum);
00433   }
00434   bool End(){
00435     return BML_STATIC_DATA::End();
00436   }
00437 
00438 //イテレーション系
00439   BML_BULLET_DATA *GetSimpleAddress(){return BML_STATIC_DATA::s_begin_s();}
00440   BML_BULLET_DATA *GetActionAddress(){return BML_STATIC_DATA::s_begin_a();}
00441 
00442   BML_BULLET_DATA *GetSimpleAddressSentinel(){return BML_STATIC_DATA::s_end_s();}
00443   BML_BULLET_DATA *GetActionAddressSentinel(){return BML_STATIC_DATA::s_end_a();}
00444 
00445   size_t GetSimpleSentinel(){return BML_STATIC_DATA::GetSimpleSentinel();}
00446   size_t GetActionSentinel(){return BML_STATIC_DATA::GetActionSentinel();}
00447   
00448 //弾の生成、削除系
00449   
00450   void DeleteSimpleBullet(BML_BULLET_DATA *data){
00451     BML_STATIC_DATA::PopSimpleBullet(data);
00452   }
00453   void DeleteActionBullet(BML_BULLET_DATA *data){
00454     BML_STATIC_DATA::PopActionBullet(data);
00455   }
00467   bool CreateBullet(xml_handle xml_h,int x,int y,
00468     const char *work,size_t worksize,BML_GETPLAYER_DATA_CALLBACK fp){
00469 
00470     BML_BULLET_DATA data;
00471     //ここの初期か間違えているかもしれない。スピードとかDIRECTIONとか設定していないし。
00472     InitBulletWork(&data,ebmlNULL,x,y,
00473       0,//accelx
00474       0,//accely
00475       180,//direction
00476       0,//speed
00477       0,//action handle... (後々入れる
00478       work,worksize);
00479 
00480     BulletMLManager::BULLETML_PARSER *parser = ReferenceBML(xml_h).get();
00481     smartaction_ptr ptr(new BMLRunner_in_c(parser,fp));
00482 
00483     CreateActionBulletHelper(ptr,data);
00484   
00485 
00486     return (false==ptr.isNull());
00487   }
00488 
00489 
00490 
00491 
00492 //BML XML ロードアンロード系  
00493   
00494   DXEX_XMLPARSER_PTR &ReferenceBML(xml_handle h){
00495     return mXMLC.at(h);
00496   }
00501   xml_handle LoadBMLFile(const char *filename);
00502 
00506   xml_handle LoadBML(const char *memory_image_str);
00507 
00508 
00513 
00514   bool UnloadBML(xml_handle h,bool isCheck=true);
00515   
00516 
00517 //フレーム系
00518   
00519   int GetFrame()const{
00520     return BML_STATIC_DATA::GetFrame();
00521   }
00522   void ClearFrame(){
00523     BML_STATIC_DATA::ClearFrame();
00524   }
00525   void IncFrame(){
00526     BML_STATIC_DATA::IncFrame();
00527   }
00528 
00529 //弾の数
00530   
00531   UINT GetBulletNum()const{
00532     return BML_STATIC_DATA::GetBulletNum();
00533   }
00534 
00535 //弾の速さ
00536 
00538   void SetBulletSpeed(double s){
00539     BML_STATIC_DATA::SetBulletSpeed(s);
00540   }
00541   
00543   double GetBulletSpeed(){return BML_STATIC_DATA::GetBulletSpeed();}
00544 
00545 //libBulletMLの処理
00546 
00547   void Move();
00548   void Update();
00549 
00550   
00551   
00552 };
00553 
00554 
00555 
00556 }//end of bml namespace
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 #endif

BMLDLL.dllに対してTue Mar 23 01:17:27 2004に生成されました。 doxygen 1.3.6