109 lines
4.6 KiB
C++
109 lines
4.6 KiB
C++
#include "core/pokemon_table.h"
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <chrono>
|
|
|
|
using namespace PokEng;
|
|
|
|
int main() {
|
|
std::cout << "Pokemon Table Example" << std::endl;
|
|
std::cout << "====================" << std::endl;
|
|
|
|
// Initialize the global Pokemon table
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
if (!initializePokemonTable()) {
|
|
std::cerr << "Failed to initialize Pokemon table!" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
|
|
|
std::cout << "Pokemon table initialized in " << duration.count() << "ms" << std::endl;
|
|
std::cout << "Total Pokemon loaded: " << g_pokemonTable->size() << std::endl;
|
|
std::cout << "Max Pokemon ID: " << g_pokemonTable->getMaxId() << std::endl;
|
|
std::cout << std::endl;
|
|
|
|
// Demonstrate fast ID-based lookup
|
|
std::cout << "Fast ID-based lookups:" << std::endl;
|
|
std::cout << "--------------------" << std::endl;
|
|
|
|
const uint16_t testIds[] = {1, 25, 150, 493, 807, 905}; // Bulbasaur, Pikachu, Mewtwo, Arceus, Zeraora, Enamorus
|
|
|
|
for (uint16_t id : testIds) {
|
|
const auto* pokemon = g_pokemonTable->getPokemon(id);
|
|
if (pokemon) {
|
|
std::cout << "#" << std::setw(3) << std::setfill('0') << pokemon->id << " "
|
|
<< std::setw(15) << std::left << pokemon->name << " | "
|
|
<< "HP: " << std::setw(3) << static_cast<int>(pokemon->base_stats.hp) << " | "
|
|
<< "Atk: " << std::setw(3) << static_cast<int>(pokemon->base_stats.attack) << " | "
|
|
<< "Def: " << std::setw(3) << static_cast<int>(pokemon->base_stats.defense) << " | "
|
|
<< "SpA: " << std::setw(3) << static_cast<int>(pokemon->base_stats.sp_attack) << " | "
|
|
<< "SpD: " << std::setw(3) << static_cast<int>(pokemon->base_stats.sp_defense) << " | "
|
|
<< "Spe: " << std::setw(3) << static_cast<int>(pokemon->base_stats.speed) << " | "
|
|
<< "Type: " << TypeUtils::typeToString(pokemon->types.getPrimary());
|
|
if (pokemon->types.hasSecondary()) {
|
|
std::cout << "/" << TypeUtils::typeToString(pokemon->types.getSecondary());
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
// Demonstrate name-based lookup
|
|
std::cout << "Name-based lookups:" << std::endl;
|
|
std::cout << "------------------" << std::endl;
|
|
|
|
const std::string testNames[] = {"charizard", "gengar", "snorlax", "dragonite", "mew"};
|
|
|
|
for (const auto& name : testNames) {
|
|
const auto* pokemon = g_pokemonTable->getPokemonByName(name);
|
|
if (pokemon) {
|
|
std::cout << "#" << std::setw(3) << std::setfill('0') << pokemon->id << " "
|
|
<< std::setw(12) << std::left << pokemon->name << " | "
|
|
<< "Total: " << std::setw(3) << (pokemon->base_stats.hp +
|
|
pokemon->base_stats.attack +
|
|
pokemon->base_stats.defense +
|
|
pokemon->base_stats.sp_attack +
|
|
pokemon->base_stats.sp_defense +
|
|
pokemon->base_stats.speed)
|
|
<< std::endl;
|
|
} else {
|
|
std::cout << "Pokemon '" << name << "' not found" << std::endl;
|
|
}
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
// Performance test for ID lookups
|
|
std::cout << "Performance test (100,000 ID lookups):" << std::endl;
|
|
std::cout << "--------------------------------------" << std::endl;
|
|
|
|
start = std::chrono::high_resolution_clock::now();
|
|
|
|
volatile size_t checksum = 0; // Prevent optimization
|
|
for (int i = 0; i < 100000; ++i) {
|
|
uint16_t randomId = (i % g_pokemonTable->getMaxId()) + 1;
|
|
const auto* pokemon = g_pokemonTable->getPokemon(randomId);
|
|
if (pokemon) {
|
|
checksum += pokemon->base_stats.hp;
|
|
}
|
|
}
|
|
|
|
end = std::chrono::high_resolution_clock::now();
|
|
duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
|
|
|
std::cout << "Time: " << duration.count() << "ms (" << (100000.0 / duration.count()) << " lookups/ms)" << std::endl;
|
|
std::cout << "Checksum: " << checksum << std::endl;
|
|
|
|
// Cleanup
|
|
shutdownPokemonTable();
|
|
|
|
std::cout << std::endl;
|
|
std::cout << "Example completed successfully!" << std::endl;
|
|
|
|
return 0;
|
|
}
|