Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/CompileFlags.cmake
#	src/crashlog.cpp
#	src/crashlog.h
#	src/date_type.h
#	src/depot_type.h
#	src/landscape.cpp
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/os/macosx/crashlog_osx.cpp
#	src/os/unix/crashlog_unix.cpp
#	src/os/windows/crashlog_win.cpp
#	src/pathfinder/npf/npf.cpp
#	src/road_cmd.cpp
#	src/script/api/script_infrastructure.cpp
#	src/stdafx.h
#	src/table/settings/gui_settings.ini
#	src/table/settings/pathfinding_settings.ini
#	src/tests/CMakeLists.txt
This commit is contained in:
Jonathan G Rennison
2023-11-13 19:08:22 +00:00
154 changed files with 1004 additions and 1007 deletions

View File

@@ -346,9 +346,9 @@ void Hash::Clear(bool free_values)
* bucket, or nullptr if it is empty. prev can also be nullptr, in which case it is
* not used for output.
*/
HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
HashNode *Hash::FindNode(TileIndex tile, Trackdir dir, HashNode** prev_out) const
{
uint hash = this->hash(key1, key2);
uint hash = this->hash(tile, dir);
HashNode *result = nullptr;
/* Check if the bucket is empty */
@@ -356,7 +356,7 @@ HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
if (prev_out != nullptr) *prev_out = nullptr;
result = nullptr;
/* Check the first node specially */
} else if (this->buckets[hash].key1 == key1 && this->buckets[hash].key2 == key2) {
} else if (this->buckets[hash].tile == tile && this->buckets[hash].dir == dir) {
/* Save the value */
result = this->buckets + hash;
if (prev_out != nullptr) *prev_out = nullptr;
@@ -366,7 +366,7 @@ HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
HashNode *node;
for (node = prev->next; node != nullptr; node = node->next) {
if (node->key1 == key1 && node->key2 == key2) {
if (node->tile == tile && node->dir == dir) {
/* Found it */
result = node;
break;
@@ -383,11 +383,11 @@ HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const
* that value. Returns nullptr when the value was not present. The value returned
* is _not_ free()'d!
*/
void *Hash::DeleteValue(uint key1, uint key2)
void *Hash::DeleteValue(TileIndex tile, Trackdir dir)
{
void *result;
HashNode *prev; // Used as output var for below function call
HashNode *node = this->FindNode(key1, key2, &prev);
HashNode *node = this->FindNode(tile, dir, &prev);
if (node == nullptr) {
/* not found */
@@ -406,7 +406,7 @@ void *Hash::DeleteValue(uint key1, uint key2)
} else {
/* This was the last in this bucket
* Mark it as empty */
uint hash = this->hash(key1, key2);
uint hash = this->hash(tile, dir);
this->buckets_in_use[hash] = false;
}
} else {
@@ -426,10 +426,10 @@ void *Hash::DeleteValue(uint key1, uint key2)
* Sets the value associated with the given key pair to the given value.
* Returns the old value if the value was replaced, nullptr when it was not yet present.
*/
void *Hash::Set(uint key1, uint key2, void *value)
void *Hash::Set(TileIndex tile, Trackdir dir, void *value)
{
HashNode *prev;
HashNode *node = this->FindNode(key1, key2, &prev);
HashNode *node = this->FindNode(tile, dir, &prev);
if (node != nullptr) {
/* Found it */
@@ -441,7 +441,7 @@ void *Hash::Set(uint key1, uint key2, void *value)
/* It is not yet present, let's add it */
if (prev == nullptr) {
/* The bucket is still empty */
uint hash = this->hash(key1, key2);
uint hash = this->hash(tile, dir);
this->buckets_in_use[hash] = true;
node = this->buckets + hash;
} else {
@@ -450,8 +450,8 @@ void *Hash::Set(uint key1, uint key2, void *value)
prev->next = node;
}
node->next = nullptr;
node->key1 = key1;
node->key2 = key2;
node->tile = tile;
node->dir = dir;
node->value = value;
this->size++;
return nullptr;
@@ -461,9 +461,9 @@ void *Hash::Set(uint key1, uint key2, void *value)
* Gets the value associated with the given key pair, or nullptr when it is not
* present.
*/
void *Hash::Get(uint key1, uint key2) const
void *Hash::Get(TileIndex tile, Trackdir dir) const
{
HashNode *node = this->FindNode(key1, key2, nullptr);
HashNode *node = this->FindNode(tile, dir, nullptr);
return (node != nullptr) ? node->value : nullptr;
}

View File

@@ -10,6 +10,9 @@
#ifndef QUEUE_H
#define QUEUE_H
#include "../../tile_type.h"
#include "../../track_type.h"
//#define HASH_STATS
@@ -58,8 +61,8 @@ struct BinaryHeap {
* Hash
*/
struct HashNode {
uint key1;
uint key2;
TileIndex tile;
Trackdir dir;
void *value;
HashNode *next;
};
@@ -67,7 +70,7 @@ struct HashNode {
* Generates a hash code from the given key pair. You should make sure that
* the resulting range is clearly defined.
*/
typedef uint Hash_HashProc(uint key1, uint key2);
typedef uint Hash_HashProc(TileIndex tile, Trackdir dir);
struct Hash {
/* The hash function used */
Hash_HashProc *hash;
@@ -83,10 +86,10 @@ struct Hash {
void Init(Hash_HashProc *hash, uint num_buckets);
void *Get(uint key1, uint key2) const;
void *Set(uint key1, uint key2, void *value);
void *Get(TileIndex tile, Trackdir dir) const;
void *Set(TileIndex tile, Trackdir dir, void *value);
void *DeleteValue(uint key1, uint key2);
void *DeleteValue(TileIndex tile, Trackdir dir);
void Clear(bool free_values);
void Delete(bool free_values);
@@ -103,7 +106,7 @@ protected:
#ifdef HASH_STATS
void PrintStatistics() const;
#endif
HashNode *FindNode(uint key1, uint key2, HashNode** prev_out) const;
HashNode *FindNode(TileIndex tile, Trackdir dir, HashNode** prev_out) const;
};
#endif /* QUEUE_H */