MCPcopy Create free account
hub / github.com/ddnet/ddnet / Process

Function Process

src/tools/map_diff.cpp:11–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <game/mapitems.h>
10
11static bool Process(IStorage *pStorage, const char **pMapNames)
12{
13 CDataFileReader aMaps[2];
14
15 for(int i = 0; i < 2; ++i)
16 {
17 if(!aMaps[i].Open(pStorage, pMapNames[i], IStorage::TYPE_ABSOLUTE))
18 {
19 dbg_msg("map_diff", "error opening map '%s'", pMapNames[i]);
20 return false;
21 }
22
23 const CMapItemVersion *pVersion = static_cast<CMapItemVersion *>(aMaps[i].FindItem(MAPITEMTYPE_VERSION, 0));
24 if(pVersion == nullptr || pVersion->m_Version != 1)
25 {
26 dbg_msg("map_diff", "unsupported map version '%s'", pMapNames[i]);
27 return false;
28 }
29 }
30
31 int aStart[2], aLayersNum[2];
32 for(int i = 0; i < 2; ++i)
33 aMaps[i].GetType(MAPITEMTYPE_LAYER, &aStart[i], &aLayersNum[i]);
34
35 // ensure basic layout
36 if(aLayersNum[0] != aLayersNum[1])
37 {
38 dbg_msg("map_diff", "different layer numbers:");
39 for(int i = 0; i < 2; ++i)
40 dbg_msg("map_diff", " \"%s\": %d layers", pMapNames[i], aLayersNum[i]);
41 return false;
42 }
43
44 // preload data
45 for(int j = 0; j < aLayersNum[0]; ++j)
46 {
47 for(int i = 0; i < 2; ++i)
48 {
49 CMapItemLayer *pItem = (CMapItemLayer *)aMaps[i].GetItem(aStart[i] + j);
50 if(pItem->m_Type == LAYERTYPE_TILES)
51 (void)aMaps[i].GetData(((CMapItemLayerTilemap *)pItem)->m_Data);
52 }
53 }
54
55 // compare
56 for(int j = 0; j < aLayersNum[0]; ++j)
57 {
58 CMapItemLayer *apItem[2];
59 for(int i = 0; i < 2; ++i)
60 apItem[i] = (CMapItemLayer *)aMaps[i].GetItem(aStart[i] + j);
61
62 if(apItem[0]->m_Type != LAYERTYPE_TILES || apItem[1]->m_Type != LAYERTYPE_TILES)
63 continue;
64
65 CMapItemLayerTilemap *apTilemap[2];
66 char aaName[2][12];
67
68 for(int i = 0; i < 2; ++i)

Callers 2

mainFunction · 0.70
ProcessItemFunction · 0.70

Calls 8

dbg_msgFunction · 0.85
IntsToStrFunction · 0.85
str_compFunction · 0.85
OpenMethod · 0.45
FindItemMethod · 0.45
GetTypeMethod · 0.45
GetItemMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected