diff --git a/BitmapFont.h b/BitmapFont.h index b62ab16..53e8e05 100644 --- a/BitmapFont.h +++ b/BitmapFont.h @@ -6,4 +6,5 @@ using namespace hgl; bool LoadBitmapFont(); void ClearBitmapFont(); +const uint8 *Get8x8Char(const char ch); const uint8 *Get8x16Char(const char ch); \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b7bf02..ffc2774 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,9 @@ set_example_project_folder("DataType/DataArray" PoolTest) add_executable(ActiveIDManagerTest datatype/ActiveIDManagerTest.cpp) set_example_project_folder("DataType/DataArray" ActiveIDManagerTest) +add_executable(ActiveDataManagerTest datatype/ActiveDataManagerTest.cpp) +set_example_project_folder("DataType/DataArray" ActiveDataManagerTest) + add_executable(MapTest datatype/MapTest.cpp) set_example_project_folder("DataType/DataArray" MapTest) @@ -103,14 +106,21 @@ add_executable(OSFontList OSFontList.cpp) cm_example_project("os" OSFontList) target_link_libraries(OSFontList PRIVATE CMUtil) -add_executable(DistributionChart2D DistributionChart2D.cpp BitmapFont.cpp BitmapFont.h) -cm_example_project("chart" DistributionChart2D) - add_executable(TimeCount time/time_count.cpp) cm_example_project("time" TimeCount) #################################################################################################### +add_executable(DistributionChart2D DistributionChart2D.cpp BitmapFont.cpp BitmapFont.h) +cm_example_project("chart" DistributionChart2D) +target_link_libraries(DistributionChart2D PRIVATE CM2D) + +add_executable(PlayerTraceChart2D PlayerTraceChart2D.cpp BitmapFont.cpp BitmapFont.h) +cm_example_project("chart" PlayerTraceChart2D) +target_link_libraries(PlayerTraceChart2D PRIVATE CM2D) + +#################################################################################################### + add_executable(PAttribTest utils/PAttribTest.cpp) cm_example_project("utils" PAttribTest) diff --git a/DistributionChart2D.cpp b/DistributionChart2D.cpp index 7120d12..2bdc544 100644 --- a/DistributionChart2D.cpp +++ b/DistributionChart2D.cpp @@ -16,7 +16,7 @@ using namespace hgl::bitmap; OSString csv_filename; -uint MAP_RATE_SCALE=100; //地图缩小比例,UNREAL中单位为厘米,换算到米需要/100。 +uint POSITION_SCALE_RATE=100; //坐标缩小比例,UNREAL中单位为厘米,换算到米需要/100。 //原地图4K,现底层为1K,所以需要再/4。 //2K地图用的底层为2K,所以只/100 @@ -127,8 +127,8 @@ bool ParsePosition(Vector2i *result,const UTF8String &str) if(!hgl::stoi(sp,result->y)) return(false); - result->x/=MAP_RATE_SCALE; //Unreal单位为cm,把单位缩到米 - result->y/=MAP_RATE_SCALE; //同时把4096的地图缩小到1024 + result->x/=POSITION_SCALE_RATE; //Unreal单位为cm,把单位缩到米 + result->y/=POSITION_SCALE_RATE; //同时把4096的地图缩小到1024 if(result->x>=BackgroundBitmap->GetWidth() ||result->y>=BackgroundBitmap->GetHeight() diff --git a/PlayerTraceChart2D.cpp b/PlayerTraceChart2D.cpp new file mode 100644 index 0000000..0c54ad5 --- /dev/null +++ b/PlayerTraceChart2D.cpp @@ -0,0 +1,336 @@ +#include +#include +#include +#include +#include +#include +#include +#include"BitmapFont.h" +#include +#include + +using namespace hgl; +using namespace hgl::bitmap; + +uint POSITION_SCALE_RATE=100; //λű,unrealеλΪcm +uint64 BATTLE_FIELD_ID=0; //սID + +constexpr const uint CHAR_WIDTH=8; +constexpr const uint CHAR_HEIGHT=16; +constexpr const uint CHAR_HALF_WIDTH=4; +constexpr const uint CHAR_HALF_HEIGHT=8; + +constexpr const uint ICON_SIZE=8; + +BitmapRGB8 *BackgroundBitmap=nullptr; +DrawGeometryRGB8 *draw_bmp=nullptr; + +using TraceList=List; + +ObjectMap PlayerTrace; //ҹ켣 + +Vector3u8 *PlayerColor=nullptr; + +class TraceParse:public util::CSVParseCallback +{ + uint record_count=0; + uint parse_count=0; + uint valid_count=0; + + Vector2i pos; + uint64 bf_id; + uint player_id; + +public: + + bool ParsePosition(const char *str,const int len) + { + const char *sp=str; + const char *cp; + + cp=hgl::strchr(sp,' '); + if(!cp)return(false); + + if(!hgl::stoi(sp,pos.x)) + return(false); + + ++cp; + if(!hgl::stoi(cp,pos.y)) + return(false); + + pos/=POSITION_SCALE_RATE; + + if(pos.x<0||pos.y<0)return(false); + if(pos.x>=BackgroundBitmap->GetWidth() + ||pos.y>=BackgroundBitmap->GetHeight())return(false); + + return(true); + } + + bool OnLine(util::CSVFieldSplite &split) override + { + ++record_count; + + const char *p; + int len; + + p=split.next_field(&len); + if(!p) + return(false); + + if(!ParsePosition(p,len)) + return(false); + + p=split.next_field(&len); + + if(!hgl::stou(p,bf_id)) + return(false); + + if(bf_id!=BATTLE_FIELD_ID) + return(false); + + p=split.next_field(&len); + + if(!hgl::stou(p,player_id)) + return(false); + + ++parse_count; + + { + TraceList *tl; + + if(!PlayerTrace.Get(player_id,tl)) + { + tl=new TraceList; + + PlayerTrace.Add(player_id,tl); + } + + tl->Add(pos); + } + + return(true); + } +};//class CSVTest; + +bool LoadCSVRecord(const OSString &filename) +{ + TraceParse tp; + + return util::ParseCSVFile(filename,&tp); +} + +void DrawIcon(const uint index,const uint x,uint y,const Vector3u8 &color) +{ + const uint8 *sp=Get8x8Char(index); + + if(!sp)return; + + draw_bmp->SetDrawColor(color); + draw_bmp->DrawMonoBitmap(x,y,sp,8,8); +} + +void DrawChar(const char ch,const uint x,const uint y) +{ + const uint8 *sp=Get8x16Char(ch); + + if(!sp)return; + + draw_bmp->DrawMonoBitmap(x,y,sp,CHAR_WIDTH,CHAR_HEIGHT); +} + +void DrawString(const uint x,const uint y,const AnsiString &str,const Vector3u8 &color) +{ + const char *sp=str.c_str(); + const uint len=str.Length(); + + uint pos=x; + + draw_bmp->CloseBlend(); + + draw_bmp->SetDrawColor(color); + + for(uint i=0;ikey<<" Trace Count "<<(*pt)->value->GetCount()<key); + DrawString(left+20,top,str,PlayerColor[i]); + + top+=CHAR_HEIGHT+2; + + { + TraceList *tl=(*pt)->value; + + const Vector2i *last_pos=nullptr; + const Vector2i *pos=tl->GetData(); + const uint count=tl->GetCount(); + + for(uint j=0;jSetDrawColor(PlayerColor[i]); + + if(j==0) + { + draw_bmp->DrawSolidCircle(pos->x,pos->y,8); + } + else + { + draw_bmp->DrawLine(last_pos->x,last_pos->y,pos->x,pos->y); + + str=AnsiString::numberOf(j); + + DrawString(pos->x-str.Length()*CHAR_HALF_WIDTH,pos->y-CHAR_HALF_HEIGHT,str,PlayerColor[i]); + } + + last_pos=pos; + ++pos; + } + } + } + + ++pt; + } +} + +int os_main(int argc,os_char **argv) +{ + std::cout<<"PlayerTraceChart2D"<GetWidth()<<"x"<GetHeight()<0) + { + PlayerColor=new Vector3u8[pc]; + + const auto *pt=PlayerTrace.GetDataList(); + + Color3f color; + + for(uint i=0;ikey<<" Trace Count "<<(*pt)->value->GetCount()<value->GetCount(); + ++pt; + } + } + + if(total<=0)return(-5); + } + } + + draw_bmp=new DrawGeometryRGB8(BackgroundBitmap); + StatPlayerTrace(); + + { + const OSString tga_filename=filesystem::ReplaceExtName(csv_filename,OSString(OS_TEXT(".tga"))); + + os_out<