Skip to content

Commit 710b50e

Browse files
committed
Vegetation vector for 31.19
1 parent 9f5ee8a commit 710b50e

File tree

4 files changed

+152
-77
lines changed

4 files changed

+152
-77
lines changed

data/Memory-ng.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,9 @@
19441944
<Group name="GUI" valid="false">
19451945
<Address name="pause_state" value="0x14c9be1" valid="true" />
19461946
</Group>
1947+
<Group name="Vegetation" valid="true">
1948+
<Address name="vector" value="0x16db478" />
1949+
</Group>
19471950
<!--
19481951
<Address name="WORLD" valid="false" />
19491952
<Group name="Buildings">
@@ -1977,10 +1980,6 @@
19771980
<Address name="language_vector" value="0x016e553c"/>
19781981
<Address name="translation_vector" value="0x016e551c"/>
19791982
</Group>
1980-
<Group name="Vegetation" valid="false">
1981-
<Address name="vector"/>
1982-
<Offset name="tree_desc_offset" valid="true"/>
1983-
</Group>
19841983
<Group name="Items" valid="false">
19851984
<Address name="items_vector" />
19861985
List of offsets in the VTable :

tools/supported/SegmentedFinder.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,15 @@ class Bytestream
386386
return false;
387387
}
388388
}
389-
bool insert( char what )
389+
template < class T >
390+
bool insert( T what )
390391
{
391392
if(constant)
392393
return false;
393-
if(d->length+1 == d->allocated)
394-
Allocate(d->allocated * 2);
395-
((char *) d->object)[d->length] = what;
396-
d->length ++;
394+
if(d->length+sizeof(T) >= d->allocated)
395+
Allocate((d->length+sizeof(T)) * 2);
396+
(*(T *)(d->object + d->length)) = what;
397+
d->length += sizeof(T);
397398
}
398399
Bytestreamdata * d;
399400
bool constant;

tools/supported/incrementalsearch.cpp

Lines changed: 139 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,14 @@ bool Incremental ( vector <uint64_t> &found, const char * what, T& output,
179179
}
180180
goto incremental_more;
181181
}
182-
else if(select.empty())
182+
else if(select == "q")
183183
{
184184
return false;
185185
}
186+
else if(select.empty())
187+
{
188+
goto incremental_more;
189+
}
186190
else
187191
{
188192
if(numberz)
@@ -399,29 +403,91 @@ void FindData(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& range
399403
DF->Detach();
400404
}
401405
}
402-
/*
403-
while(Incremental(found, "integer",test1))
406+
407+
bool TriggerIncremental ( vector <uint64_t> &found )
408+
{
409+
string select;
410+
if(found.empty())
411+
{
412+
cout << "search ready - position the DF cursor and hit enter when ready" << endl;
413+
}
414+
else if( found.size() == 1 )
415+
{
416+
cout << "Found single coord!" << endl;
417+
cout << hex << "0x" << found[0] << endl;
418+
}
419+
else
420+
{
421+
cout << "Found " << dec << found.size() << " coords." << endl;
422+
}
423+
incremental_more:
424+
cout << ">>";
425+
std::getline(cin, select);
426+
size_t num = 0;
427+
if( sscanf(select.c_str(),"p %d", &num) && num > 0)
428+
{
429+
cout << "Found coords:" << endl;
430+
for(int i = 0; i < min(found.size(), num);i++)
431+
{
432+
cout << hex << "0x" << found[i] << endl;
433+
}
434+
goto incremental_more;
435+
}
436+
else if(select == "p")
437+
{
438+
cout << "Found coords:" << endl;
439+
for(int i = 0; i < found.size();i++)
440+
{
441+
cout << hex << "0x" << found[i] << endl;
442+
}
443+
goto incremental_more;
444+
}
445+
else if(select == "q")
446+
{
447+
return false;
448+
}
449+
else return true;
450+
}
451+
452+
453+
void FindCoords(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
454+
{
455+
vector <uint64_t> found;
456+
int size = 4;
457+
do
458+
{
459+
getNumber("Select coord size (2,4 bytes)",size, 4);
460+
} while (size != 2 && size != 4);
461+
while (TriggerIncremental(found))
404462
{
405463
DFMgr.Refresh();
406464
DFHack::Context * DF = DFMgr.getSingleContext();
407465
DF->Attach();
408-
SegmentedFinder sf(ranges,DF);
409-
switch(size)
466+
DFHack::Position * pos = DF->getPosition();
467+
pos->Start();
468+
int32_t x, y, z;
469+
pos->getCursorCoords(x,y,z);
470+
cout << "Searching for: " << dec << x << ":" << y << ":" << z << endl;
471+
Bytestream select;
472+
if(size == 2)
410473
{
411-
case 1:
412-
sf.Incremental<uint8_t,uint8_t>(test1,alignment,found, equalityP<uint8_t>);
413-
break;
414-
case 2:
415-
sf.Incremental<uint16_t,uint16_t>(test1,alignment,found, equalityP<uint16_t>);
416-
break;
417-
case 4:
418-
sf.Incremental<uint32_t,uint32_t>(test1,alignment,found, equalityP<uint32_t>);
419-
break;
474+
select.insert<uint16_t>(x);
475+
select.insert<uint16_t>(y);
476+
select.insert<uint16_t>(z);
477+
}
478+
else
479+
{
480+
select.insert<uint32_t>(x);
481+
select.insert<uint32_t>(y);
482+
select.insert<uint32_t>(z);
420483
}
484+
cout << select << endl;
485+
SegmentedFinder sf(ranges,DF);
486+
sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream);
421487
DF->Detach();
422488
}
423489
}
424-
*/
490+
425491
void PtrTrace(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
426492
{
427493
int element_size;
@@ -841,64 +907,69 @@ int main (void)
841907
"Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n"
842908
" 4=string, 5=automated offset search, 6=vector by address in its array,\n"
843909
" 7=pointer vector by address of an object, 8=vector>first object>string\n"
844-
" 9=string buffers, 10=known data, 11=backpointers, 12=data+backpointers\n";
910+
" 9=string buffers, 10=known data, 11=backpointers, 12=data+backpointers\n"
911+
" 13=coord lookup\n";
845912
int mode;
846913
do
847914
{
848915
getNumber(prompt,mode, 1, false);
916+
switch (mode)
917+
{
918+
case 1:
919+
DF->Detach();
920+
FindIntegers(DFMgr, selected_ranges);
921+
break;
922+
case 2:
923+
DF->Detach();
924+
FindVectorByLength(DFMgr, selected_ranges);
925+
break;
926+
case 3:
927+
DF->Detach();
928+
FindVectorByObjectRawname(DFMgr, selected_ranges);
929+
break;
930+
case 4:
931+
DF->Detach();
932+
FindStrings(DFMgr, selected_ranges);
933+
break;
934+
case 5:
935+
autoSearch(DF,selected_ranges);
936+
break;
937+
case 6:
938+
DF->Detach();
939+
FindVectorByBounds(DFMgr,selected_ranges);
940+
break;
941+
case 7:
942+
DF->Detach();
943+
FindPtrVectorsByObjectAddress(DFMgr,selected_ranges);
944+
break;
945+
case 8:
946+
DF->Detach();
947+
FindVectorByFirstObjectRawname(DFMgr, selected_ranges);
948+
break;
949+
case 9:
950+
DF->Detach();
951+
FindStrBufs(DFMgr, selected_ranges);
952+
break;
953+
case 10:
954+
DF->Detach();
955+
FindData(DFMgr, selected_ranges);
956+
break;
957+
case 11:
958+
DF->Detach();
959+
PtrTrace(DFMgr, selected_ranges);
960+
break;
961+
case 12:
962+
DF->Detach();
963+
DataPtrTrace(DFMgr, selected_ranges);
964+
break;
965+
case 13:
966+
DF->Detach();
967+
FindCoords(DFMgr, selected_ranges);
968+
break;
969+
default:
970+
cout << "not implemented :(" << endl;
971+
}
849972
} while (mode < 1 || mode > 12 );
850-
switch (mode)
851-
{
852-
case 1:
853-
DF->Detach();
854-
FindIntegers(DFMgr, selected_ranges);
855-
break;
856-
case 2:
857-
DF->Detach();
858-
FindVectorByLength(DFMgr, selected_ranges);
859-
break;
860-
case 3:
861-
DF->Detach();
862-
FindVectorByObjectRawname(DFMgr, selected_ranges);
863-
break;
864-
case 4:
865-
DF->Detach();
866-
FindStrings(DFMgr, selected_ranges);
867-
break;
868-
case 5:
869-
autoSearch(DF,selected_ranges);
870-
break;
871-
case 6:
872-
DF->Detach();
873-
FindVectorByBounds(DFMgr,selected_ranges);
874-
break;
875-
case 7:
876-
DF->Detach();
877-
FindPtrVectorsByObjectAddress(DFMgr,selected_ranges);
878-
break;
879-
case 8:
880-
DF->Detach();
881-
FindVectorByFirstObjectRawname(DFMgr, selected_ranges);
882-
break;
883-
case 9:
884-
DF->Detach();
885-
FindStrBufs(DFMgr, selected_ranges);
886-
break;
887-
case 10:
888-
DF->Detach();
889-
FindData(DFMgr, selected_ranges);
890-
break;
891-
case 11:
892-
DF->Detach();
893-
PtrTrace(DFMgr, selected_ranges);
894-
break;
895-
case 12:
896-
DF->Detach();
897-
DataPtrTrace(DFMgr, selected_ranges);
898-
break;
899-
default:
900-
cout << "not implemented :(" << endl;
901-
}
902973
#ifndef LINUX_BUILD
903974
cout << "Done. Press any key to continue" << endl;
904975
cin.ignore();

tools/supported/vdig.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ using namespace std;
1313
#include <argstream.h>
1414

1515
#define MAX_DIM 0x300
16+
17+
//TODO: turn into the official coord class for DFHack/DF
1618
class Vertex
1719
{
1820
public:
@@ -25,8 +27,10 @@ class Vertex
2527
{
2628
return (other.x == x && other.y == y && other.z == z);
2729
}
30+
// FIXME: <tomprince> peterix_: you could probably get away with not defining operator< if you defined a std::less specialization for Vertex.
2831
bool operator<(const Vertex &other) const
2932
{
33+
// FIXME: could be changed to eliminate MAX_DIM and make std::map lookups faster?
3034
return ( (z*MAX_DIM*MAX_DIM + y*MAX_DIM + x) < (other.z*MAX_DIM*MAX_DIM + other.y*MAX_DIM + other.x));
3135
}
3236
Vertex operator/(int number) const

0 commit comments

Comments
 (0)