12 Commits
0.0.3 ... 0.0.9

Author SHA1 Message Date
7342cf8a56 Update for newer base libraries
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-10-30 11:56:06 +02:00
fbbfbfd3b3 Fixes for Windows.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-10-24 16:21:38 +02:00
3b2e4f20ac Adds helper functions to create Pokemon with more control.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-10-24 15:57:05 +02:00
35527f68bd Fix windows build.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build is passing
2021-10-23 14:57:46 +02:00
3507ea4f6a Force ninja on CI.
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-23 14:51:57 +02:00
7c2096853b Fix Windows build for new container.
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-23 14:48:04 +02:00
af81c92165 Use PkmnLib Debugger instead/
Some checks failed
continuous-integration/drone/push Build is failing
2021-10-23 14:42:29 +02:00
7043b12f34 Adds support for debugger.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-10-23 14:28:53 +02:00
77dd8e708a Change git handling to something with far fewer dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-09-07 19:42:34 +02:00
af2a0b9786 Make gitversion a submodule instead of nested git repo
Some checks failed
continuous-integration/drone/push Build is failing
2021-09-07 19:19:53 +02:00
e386078eb6 Adds support for force color argument
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-09-07 19:17:00 +02:00
7e1597531d Show version on run 2021-09-07 19:13:10 +02:00
14 changed files with 524 additions and 29 deletions

View File

@@ -13,16 +13,21 @@ steps:
CC: /usr/bin/clang CC: /usr/bin/clang
CXX: /usr/bin/clang++ CXX: /usr/bin/clang++
commands: commands:
- cmake -DCMAKE_BUILD_TYPE=Release . -B build-release - cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release
- cmake --build build-release --target all -- -j 4 - cmake --build build-release --target all -- -j 4
- name: build-release-windows - name: build-release-windows
image: deukhoofd/windowsbuilder image: deukhoofd/windowsbuilder
environment:
CHOST: x86_64-w64-mingw32
AR: x86_64-w64-mingw32-ar
AS: x86_64-w64-mingw32-as
RANLIB: x86_64-w64-mingw32-ranlib
CC: x86_64-w64-mingw32-gcc
CXX: x86_64-w64-mingw32-g++
STRIP: x86_64-w64-mingw32-strip
RC: x86_64-w64-mingw32-windres
commands: commands:
- update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix - cmake -GNinja -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -DWINDOWS=ON -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
- update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
- update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
- update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
- cmake -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -DWINDOWS=ON -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc -D CMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
- cmake --build build-release-windows --target all -- -j 4 - cmake --build build-release-windows --target all -- -j 4
- name: gitea_release - name: gitea_release
image: plugins/gitea-release image: plugins/gitea-release

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "src/BuildData"] [submodule "src/BuildData"]
path = src/BuildData path = src/BuildData
url = https://git.p-epsilon.com/Deukhoofd/BuildData.git url = https://git.p-epsilon.com/Deukhoofd/BuildData.git
[submodule "extern/gitversion"]
path = extern/gitversion
url = https://github.com/smessmer/gitversion.git

View File

@@ -19,7 +19,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif () endif ()
file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.hpp) file(GLOB_RECURSE SRC_FILES src/*.cpp src/*.hpp extern/AngelscriptDebugger/src/*.cpp)
add_executable(PokemonScriptTester ${SRC_FILES}) add_executable(PokemonScriptTester ${SRC_FILES})
target_precompile_headers(PokemonScriptTester PUBLIC src/Precompiled.hxx) target_precompile_headers(PokemonScriptTester PUBLIC src/Precompiled.hxx)
add_definitions(-DLEVEL_U8) add_definitions(-DLEVEL_U8)
@@ -39,3 +39,8 @@ if (WINDOWS)
set_target_properties(PokemonScriptTester PROPERTIES SUFFIX ".exe") set_target_properties(PokemonScriptTester PROPERTIES SUFFIX ".exe")
endif(SHARED) endif(SHARED)
endif (WINDOWS) endif (WINDOWS)
set(PRE_CONFIGURE_FILE "git.h.in")
set(POST_CONFIGURE_FILE "src/git.h")
include(git_watcher.cmake)
add_dependencies(PokemonScriptTester check_git)

View File

@@ -44,9 +44,10 @@ function(include_pkmnlib)
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/PkmnLib/extern) ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/PkmnLib/extern)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include include_directories(${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include) ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/Angelscript/src/AngelscriptProj/angelscript/include
${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/bin/CreatureLib/bin/Arbutils/include)
endfunction() endfunction()

5
git.h.in Normal file
View File

@@ -0,0 +1,5 @@
// automatically generated
#pragma once
// The output from git --describe (e.g. the most recent tag)
#define GIT_DESCRIBE "@GIT_DESCRIBE@"

335
git_watcher.cmake Normal file
View File

@@ -0,0 +1,335 @@
# git_watcher.cmake
# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/git_watcher.cmake
#
# Released under the MIT License.
# https://raw.githubusercontent.com/andrew-hardin/cmake-git-version-tracking/master/LICENSE
# This file defines a target that monitors the state of a git repo.
# If the state changes (e.g. a commit is made), then a file gets reconfigured.
# Here are the primary variables that control script behavior:
#
# PRE_CONFIGURE_FILE (REQUIRED)
# -- The path to the file that'll be configured.
#
# POST_CONFIGURE_FILE (REQUIRED)
# -- The path to the configured PRE_CONFIGURE_FILE.
#
# GIT_STATE_FILE (OPTIONAL)
# -- The path to the file used to store the previous build's git state.
# Defaults to the current binary directory.
#
# GIT_WORKING_DIR (OPTIONAL)
# -- The directory from which git commands will be run.
# Defaults to the directory with the top level CMakeLists.txt.
#
# GIT_EXECUTABLE (OPTIONAL)
# -- The path to the git executable. It'll automatically be set if the
# user doesn't supply a path.
#
# GIT_FAIL_IF_NONZERO_EXIT (optional)
# -- Raise a FATAL_ERROR if any of the git commands return a non-zero
# exit code. This is set to TRUE by default. You can set this to FALSE
# if you'd like the build to continue even if a git command fails.
#
# DESIGN
# - This script was designed similar to a Python application
# with a Main() function. I wanted to keep it compact to
# simplify "copy + paste" usage.
#
# - This script is invoked under two CMake contexts:
# 1. Configure time (when build files are created).
# 2. Build time (called via CMake -P).
# The first invocation is what registers the script to
# be executed at build time.
#
# MODIFICATIONS
# You may wish to track other git properties like when the last
# commit was made. There are two sections you need to modify,
# and they're tagged with a ">>>" header.
# Short hand for converting paths to absolute.
macro(PATH_TO_ABSOLUTE var_name)
get_filename_component(${var_name} "${${var_name}}" ABSOLUTE)
endmacro()
# Check that a required variable is set.
macro(CHECK_REQUIRED_VARIABLE var_name)
if(NOT DEFINED ${var_name})
message(FATAL_ERROR "The \"${var_name}\" variable must be defined.")
endif()
PATH_TO_ABSOLUTE(${var_name})
endmacro()
# Check that an optional variable is set, or, set it to a default value.
macro(CHECK_OPTIONAL_VARIABLE_NOPATH var_name default_value)
if(NOT DEFINED ${var_name})
set(${var_name} ${default_value})
endif()
endmacro()
# Check that an optional variable is set, or, set it to a default value.
# Also converts that path to an abspath.
macro(CHECK_OPTIONAL_VARIABLE var_name default_value)
CHECK_OPTIONAL_VARIABLE_NOPATH(${var_name} ${default_value})
PATH_TO_ABSOLUTE(${var_name})
endmacro()
CHECK_REQUIRED_VARIABLE(PRE_CONFIGURE_FILE)
CHECK_REQUIRED_VARIABLE(POST_CONFIGURE_FILE)
CHECK_OPTIONAL_VARIABLE(GIT_STATE_FILE "${CMAKE_BINARY_DIR}/git-state-hash")
CHECK_OPTIONAL_VARIABLE(GIT_WORKING_DIR "${CMAKE_SOURCE_DIR}")
CHECK_OPTIONAL_VARIABLE_NOPATH(GIT_FAIL_IF_NONZERO_EXIT TRUE)
# Check the optional git variable.
# If it's not set, we'll try to find it using the CMake packaging system.
if(NOT DEFINED GIT_EXECUTABLE)
find_package(Git QUIET REQUIRED)
endif()
CHECK_REQUIRED_VARIABLE(GIT_EXECUTABLE)
set(_state_variable_names
GIT_RETRIEVED_STATE
GIT_HEAD_SHA1
GIT_IS_DIRTY
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_COMMIT_DATE_ISO8601
GIT_COMMIT_SUBJECT
GIT_COMMIT_BODY
GIT_DESCRIBE
# >>>
# 1. Add the name of the additional git variable you're interested in monitoring
# to this list.
)
# Macro: RunGitCommand
# Description: short-hand macro for calling a git function. Outputs are the
# "exit_code" and "output" variables.
macro(RunGitCommand)
execute_process(COMMAND
"${GIT_EXECUTABLE}" ${ARGV}
WORKING_DIRECTORY "${_working_dir}"
RESULT_VARIABLE exit_code
OUTPUT_VARIABLE output
ERROR_VARIABLE stderr
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT exit_code EQUAL 0)
set(ENV{GIT_RETRIEVED_STATE} "false")
# Issue 26: git info not properly set
#
# Check if we should fail if any of the exit codes are non-zero.
if(GIT_FAIL_IF_NONZERO_EXIT)
string(REPLACE ";" " " args_with_spaces "${ARGV}")
message(FATAL_ERROR "${stderr} (${GIT_EXECUTABLE} ${args_with_spaces})")
endif()
endif()
endmacro()
# Function: GetGitState
# Description: gets the current state of the git repo.
# Args:
# _working_dir (in) string; the directory from which git commands will be executed.
function(GetGitState _working_dir)
# This is an error code that'll be set to FALSE if the
# RunGitCommand ever returns a non-zero exit code.
set(ENV{GIT_RETRIEVED_STATE} "true")
# Get whether or not the working tree is dirty.
RunGitCommand(status --porcelain)
if(NOT exit_code EQUAL 0)
set(ENV{GIT_IS_DIRTY} "false")
else()
if(NOT "${output}" STREQUAL "")
set(ENV{GIT_IS_DIRTY} "true")
else()
set(ENV{GIT_IS_DIRTY} "false")
endif()
endif()
# There's a long list of attributes grabbed from git show.
set(object HEAD)
RunGitCommand(show -s "--format=%H" ${object})
if(exit_code EQUAL 0)
set(ENV{GIT_HEAD_SHA1} ${output})
endif()
RunGitCommand(show -s "--format=%an" ${object})
if(exit_code EQUAL 0)
set(ENV{GIT_AUTHOR_NAME} "${output}")
endif()
RunGitCommand(show -s "--format=%ae" ${object})
if(exit_code EQUAL 0)
set(ENV{GIT_AUTHOR_EMAIL} "${output}")
endif()
RunGitCommand(show -s "--format=%ci" ${object})
if(exit_code EQUAL 0)
set(ENV{GIT_COMMIT_DATE_ISO8601} "${output}")
endif()
RunGitCommand(show -s "--format=%s" ${object})
if(exit_code EQUAL 0)
# Escape quotes
string(REPLACE "\"" "\\\"" output "${output}")
set(ENV{GIT_COMMIT_SUBJECT} "${output}")
endif()
RunGitCommand(show -s "--format=%b" ${object})
if(exit_code EQUAL 0)
if(output)
# Escape quotes
string(REPLACE "\"" "\\\"" output "${output}")
# Escape line breaks in the commit message.
string(REPLACE "\r\n" "\\r\\n\\\r\n" safe "${output}")
if(safe STREQUAL output)
# Didn't have windows lines - try unix lines.
string(REPLACE "\n" "\\n\\\n" safe "${output}")
endif()
else()
# There was no commit body - set the safe string to empty.
set(safe "")
endif()
set(ENV{GIT_COMMIT_BODY} "\"${safe}\"")
else()
set(ENV{GIT_COMMIT_BODY} "\"\"") # empty string.
endif()
# Get output of git describe
RunGitCommand(describe --always --tags ${object})
if(NOT exit_code EQUAL 0)
set(ENV{GIT_DESCRIBE} "unknown")
else()
set(ENV{GIT_DESCRIBE} "${output}")
endif()
# >>>
# 2. Additional git properties can be added here via the
# "execute_process()" command. Be sure to set them in
# the environment using the same variable name you added
# to the "_state_variable_names" list.
endfunction()
# Function: GitStateChangedAction
# Description: this function is executed when the state of the git
# repository changes (e.g. a commit is made).
function(GitStateChangedAction)
foreach(var_name ${_state_variable_names})
set(${var_name} $ENV{${var_name}})
endforeach()
configure_file("${PRE_CONFIGURE_FILE}" "${POST_CONFIGURE_FILE}" @ONLY)
endfunction()
# Function: HashGitState
# Description: loop through the git state variables and compute a unique hash.
# Args:
# _state (out) string; a hash computed from the current git state.
function(HashGitState _state)
set(ans "")
foreach(var_name ${_state_variable_names})
string(SHA256 ans "${ans}$ENV{${var_name}}")
endforeach()
set(${_state} ${ans} PARENT_SCOPE)
endfunction()
# Function: CheckGit
# Description: check if the git repo has changed. If so, update the state file.
# Args:
# _working_dir (in) string; the directory from which git commands will be ran.
# _state_changed (out) bool; whether or no the state of the repo has changed.
function(CheckGit _working_dir _state_changed)
# Get the current state of the repo.
GetGitState("${_working_dir}")
# Convert that state into a hash that we can compare against
# the hash stored on-disk.
HashGitState(state)
# Issue 14: post-configure file isn't being regenerated.
#
# Update the state to include the SHA256 for the pre-configure file.
# This forces the post-configure file to be regenerated if the
# pre-configure file has changed.
file(SHA256 ${PRE_CONFIGURE_FILE} preconfig_hash)
string(SHA256 state "${preconfig_hash}${state}")
# Check if the state has changed compared to the backup on disk.
if(EXISTS "${GIT_STATE_FILE}")
file(READ "${GIT_STATE_FILE}" OLD_HEAD_CONTENTS)
if(OLD_HEAD_CONTENTS STREQUAL "${state}")
# State didn't change.
set(${_state_changed} "false" PARENT_SCOPE)
return()
endif()
endif()
# The state has changed.
# We need to update the state file on disk.
# Future builds will compare their state to this file.
file(WRITE "${GIT_STATE_FILE}" "${state}")
set(${_state_changed} "true" PARENT_SCOPE)
endfunction()
# Function: SetupGitMonitoring
# Description: this function sets up custom commands that make the build system
# check the state of git before every build. If the state has
# changed, then a file is configured.
function(SetupGitMonitoring)
add_custom_target(check_git
ALL
DEPENDS ${PRE_CONFIGURE_FILE}
BYPRODUCTS
${POST_CONFIGURE_FILE}
${GIT_STATE_FILE}
COMMENT "Checking the git repository for changes..."
COMMAND
${CMAKE_COMMAND}
-D_BUILD_TIME_CHECK_GIT=TRUE
-DGIT_WORKING_DIR=${GIT_WORKING_DIR}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DGIT_STATE_FILE=${GIT_STATE_FILE}
-DPRE_CONFIGURE_FILE=${PRE_CONFIGURE_FILE}
-DPOST_CONFIGURE_FILE=${POST_CONFIGURE_FILE}
-DGIT_FAIL_IF_NONZERO_EXIT=${GIT_FAIL_IF_NONZERO_EXIT}
-P "${CMAKE_CURRENT_LIST_FILE}")
endfunction()
# Function: Main
# Description: primary entry-point to the script. Functions are selected based
# on whether it's configure or build time.
function(Main)
if(_BUILD_TIME_CHECK_GIT)
# Check if the repo has changed.
# If so, run the change action.
CheckGit("${GIT_WORKING_DIR}" changed)
if(changed OR NOT EXISTS "${POST_CONFIGURE_FILE}")
GitStateChangedAction()
endif()
else()
# >> Executes at configure time.
SetupGitMonitoring()
endif()
endfunction()
# And off we go...
Main()

View File

@@ -12,7 +12,7 @@
class BattleFunctions { class BattleFunctions {
static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) { static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto lib = Globals::Library.GetValue(); auto lib = Globals::Library.GetValue();
auto p1 = new PkmnLib::Battling::PokemonParty(species->GetSize()); auto p1 = new PkmnLib::Battling::PokemonParty(species->GetSize());
@@ -31,10 +31,25 @@ class BattleFunctions {
return p1; return p1;
} }
static CreatureLib::Battling::CreatureParty* CreateParty(CScriptArray* mons) {
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto p1 = new PkmnLib::Battling::PokemonParty(mons->GetSize());
for (u32 i = 0; i < mons->GetSize(); ++i) {
auto s = *reinterpret_cast<PkmnLib::Battling::Pokemon**>(mons->At(i));
p1->SwapInto(i, s);
// Party becomes owner of mon, so take it from GC.
env->TakeOwnershipOfGarbage(s);
}
env->AddGarbage(p1);
return p1;
}
static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1, static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1,
const ArbUt::StringView& species2, u8 level) { const ArbUt::StringView& species2, u8 level) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto lib = Globals::Library.GetValue(); auto lib = Globals::Library.GetValue();
auto mon1 = PkmnLib::Battling::CreatePokemon(lib, species1, level) auto mon1 = PkmnLib::Battling::CreatePokemon(lib, species1, level)
@@ -79,7 +94,7 @@ class BattleFunctions {
static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, PkmnLib::Battling::PokemonParty* p1, static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, PkmnLib::Battling::PokemonParty* p1,
PkmnLib::Battling::PokemonParty* p2) { PkmnLib::Battling::PokemonParty* p2) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto lib = Globals::Library.GetValue(); auto lib = Globals::Library.GetValue();
auto battle = new PkmnLib::Battling::Battle( auto battle = new PkmnLib::Battling::Battle(
@@ -109,7 +124,7 @@ class BattleFunctions {
return false; return false;
} }
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto learnedMove = auto learnedMove =
new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown); new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown);
@@ -152,6 +167,8 @@ public:
Ensure( Ensure(
engine->RegisterGlobalFunction("Party@ CreateSimpleParty(const array<constString>&in species, uint8 level)", engine->RegisterGlobalFunction("Party@ CreateSimpleParty(const array<constString>&in species, uint8 level)",
asFUNCTION(CreateSimpleParty), asCALL_CDECL) >= 0); asFUNCTION(CreateSimpleParty), asCALL_CDECL) >= 0);
Ensure(engine->RegisterGlobalFunction("Party@ CreateParty(const array<Pokemon@>&in mons)",
asFUNCTION(CreateParty), asCALL_CDECL) >= 0);
Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, const constString&in species1, " Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, const constString&in species1, "
"const constString&in species2, uint8 level)", "const constString&in species2, uint8 level)",
asFUNCTION(CreateSimpleBattle), asCALL_CDECL) >= 0); asFUNCTION(CreateSimpleBattle), asCALL_CDECL) >= 0);

View File

@@ -5,10 +5,10 @@
class MiscMockFunctions { class MiscMockFunctions {
static CScriptHandle CreateMoveScript(const ArbUt::StringView& name) { static CScriptHandle CreateMoveScript(const ArbUt::StringView& name) {
auto script = Globals::Library.GetValue()->GetScriptResolver()->LoadScript(ScriptCategory::Attack, name); auto script = Globals::Library.GetValue()->GetScriptResolver()->LoadScript(nullptr, ScriptCategory::Attack, name);
if (script != nullptr) { if (script != nullptr) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
env->AddGarbage(script); env->AddGarbage(script);
} }
auto p = dynamic_cast<AngelScriptScript*>(script); auto p = dynamic_cast<AngelScriptScript*>(script);
@@ -21,7 +21,7 @@ class MiscMockFunctions {
PkmnLib::Battling::Pokemon* user, PkmnLib::Battling::Pokemon* user,
PkmnLib::Battling::Pokemon* target) { PkmnLib::Battling::Pokemon* target) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName); auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
if (!move.has_value()) { if (!move.has_value()) {
@@ -41,7 +41,7 @@ class MiscMockFunctions {
PkmnLib::Battling::Pokemon* user, PkmnLib::Battling::Pokemon* user,
u8 targetSide, u8 target) { u8 targetSide, u8 target) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName); auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
if (!move.has_value()) { if (!move.has_value()) {

View File

@@ -0,0 +1,83 @@
#ifndef POKEMONSCRIPTTESTER_POKEMONBUILDER_HPP
#define POKEMONSCRIPTTESTER_POKEMONBUILDER_HPP
#include <PkmnLib/Battling/Pokemon/CreatePokemon.hpp>
#include <angelscript.h>
class PokemonBuilderRegistration {
public:
static PkmnLib::Battling::CreatePokemon* CreatePokemonBuilder(const ArbUt::StringView& species, uint8_t level) {
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto lib = Globals::Library.GetValue();
auto builder = new PkmnLib::Battling::CreatePokemon(lib, species, level);
env->AddGarbage(builder);
return builder;
}
static PkmnLib::Battling::CreatePokemon& WithGenderWrapper(PkmnLib::Battling::CreatePokemon* builder, i32 gender) {
return builder->WithGender((CreatureLib::Library::Gender)gender);
}
static PkmnLib::Battling::Pokemon* BuildWrapper(PkmnLib::Battling::CreatePokemon* builder, u32 seed) {
auto rand = ArbUt::Random(seed);
auto p = builder->Build(rand);
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
env->AddGarbage(p);
return p;
}
static void Register(AngelScriptResolver* resolver) {
auto engine = resolver->GetEngine();
Ensure(engine->RegisterObjectType("PokemonBuilder", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
Ensure(engine->RegisterGlobalFunction(
"PokemonBuilder@ CreatePokemonBuilder(const constString&in species, uint8 level)",
asFUNCTION(CreatePokemonBuilder), asCALL_CDECL) >= 0);
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "PokemonBuilder@ WithForme(const constString&in forme)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithForme,
(const ArbUt::StringView&), PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "PokemonBuilder@ WithGender(Gender gender)",
asFUNCTION(WithGenderWrapper), asCALL_CDECL_OBJFIRST));
Ensure(engine->RegisterObjectMethod(
"PokemonBuilder", "PokemonBuilder@ IsShiny(bool value)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, IsShiny, (bool), PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "PokemonBuilder@ WithHeldItem(const constString&in item)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithHeldItem,
(const ArbUt::StringView&), PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod(
"PokemonBuilder", "PokemonBuilder@ LearnMove(const constString&in move, MoveLearnMethod method)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, LearnMove,
(const ArbUt::StringView&, CreatureLib::Battling::AttackLearnMethod),
PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod(
"PokemonBuilder",
"PokemonBuilder@ WithIndividualValues(uint8 hp,uint8 att,uint8 def,uint8 spa,uint8 spd,uint8 speed)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithIndividualValues, (u8, u8, u8, u8, u8, u8),
PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod(
"PokemonBuilder",
"PokemonBuilder@ WithEffortValues(uint8 hp,uint8 att,uint8 def,uint8 spa,uint8 spd,uint8 speed)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithEffortValues, (u8, u8, u8, u8, u8, u8),
PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "PokemonBuilder@ WithNature(const constString&in nature)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithNature,
(const ArbUt::StringView&), PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "PokemonBuilder@ WithNickname(const string&in name)",
asMETHODPR(PkmnLib::Battling::CreatePokemon, WithNickname,
(const std::string&), PkmnLib::Battling::CreatePokemon&),
asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("PokemonBuilder", "Pokemon@ Build(uint seed = 0)", asFUNCTION(BuildWrapper),
asCALL_CDECL_OBJFIRST));
}
};
#endif // POKEMONSCRIPTTESTER_POKEMONBUILDER_HPP

View File

@@ -23,7 +23,7 @@ private:
static bool Require(bool value) { static bool Require(bool value) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
env->TotalRequirements += 1; env->TotalRequirements += 1;
if (!value) { if (!value) {
env->FailedRequirements += 1; env->FailedRequirements += 1;
@@ -43,7 +43,7 @@ private:
static bool RequireEqualsI32(i32 expected, i32 actual) { static bool RequireEqualsI32(i32 expected, i32 actual) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
env->TotalRequirements += 1; env->TotalRequirements += 1;
if (expected != actual) { if (expected != actual) {
env->FailedRequirements += 1; env->FailedRequirements += 1;
@@ -56,7 +56,7 @@ private:
static bool RequireEqualsString(const std::string& expected, const std::string& actual) { static bool RequireEqualsString(const std::string& expected, const std::string& actual) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData()); TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
if (expected != actual) { if (expected != actual) {
env->FailedRequirements += 1; env->FailedRequirements += 1;
auto data = GetRequirementData(ctx); auto data = GetRequirementData(ctx);

View File

@@ -13,8 +13,17 @@ public:
void Run(asIScriptContext* ctx) { void Run(asIScriptContext* ctx) {
ctx->PushState(); ctx->PushState();
ctx->Prepare(_function); ctx->Prepare(_function);
ctx->SetUserData(_env.get()); ctx->SetUserData(_env.get(), 684);
auto e = ctx->Execute(); auto e = ctx->Execute();
if (e == asEXECUTION_SUSPENDED) {
auto s = ctx->GetState();
while (s != asEXECUTION_FINISHED && s != asEXECUTION_EXCEPTION && s != asEXECUTION_ABORTED &&
s != asEXECUTION_ERROR) {
s = ctx->GetState();
continue;
}
}
_env->CollectGarbage(); _env->CollectGarbage();
if (e == asEXECUTION_EXCEPTION) { if (e == asEXECUTION_EXCEPTION) {
_errorMessage = ctx->GetExceptionString(); _errorMessage = ctx->GetExceptionString();
@@ -23,7 +32,6 @@ public:
return; return;
} }
ctx->PopState(); ctx->PopState();
Ensure(e == asEXECUTION_FINISHED);
_result = TestResult::Success; _result = TestResult::Success;
} }

View File

@@ -6,6 +6,13 @@ struct TestEnvironment {
size_t FailedRequirements = 0; size_t FailedRequirements = 0;
template <typename T> void AddGarbage(T* data) { _garbage.Append(GarbageObject(data)); } template <typename T> void AddGarbage(T* data) { _garbage.Append(GarbageObject(data)); }
template <typename T> void TakeOwnershipOfGarbage(T* data) {
for (auto& g : _garbage) {
if (g.Ptr == data) {
g.Ptr = nullptr;
}
}
}
void CollectGarbage() { void CollectGarbage() {
for (auto& o : _garbage) { for (auto& o : _garbage) {

View File

@@ -2,14 +2,18 @@
#define POKEMONSCRIPTTESTER_TESTRUNNER_HPP #define POKEMONSCRIPTTESTER_TESTRUNNER_HPP
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp> #include <PkmnLib/ScriptResolving/AngelScript/AngelScriptMetadata.hpp>
#include <PkmnLib/ScriptResolving/AngelScript/ContextPool.hpp>
#include <chrono>
#include <thread>
#include "../../extern/termcolor.hpp" #include "../../extern/termcolor.hpp"
#include "Test.hpp" #include "Test.hpp"
class TestRunner { class TestRunner {
AngelScriptResolver* _scriptResolver;
ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests; ArbUt::Dictionary<std::string, std::unique_ptr<Test>> _tests;
public: public:
TestRunner(AngelScriptResolver* scriptResolver) { TestRunner(AngelScriptResolver* scriptResolver) : _scriptResolver(scriptResolver) {
const auto* module = scriptResolver->GetMainModule(); const auto* module = scriptResolver->GetMainModule();
auto builder = scriptResolver->GetBuilder(); auto builder = scriptResolver->GetBuilder();
for (u32 i = 0; i < module->GetFunctionCount(); ++i) { for (u32 i = 0; i < module->GetFunctionCount(); ++i) {
@@ -30,8 +34,21 @@ public:
} }
} }
i32 RunAll(asIScriptEngine* engine) { i32 RunAll(bool waitForDebugger) {
auto ctx = engine->CreateContext(); auto ctx = _scriptResolver->GetContextPool()->RequestContext();
ctx->SetUserData(_scriptResolver->GetUserdata());
_scriptResolver->SetDebugger(new AngelscriptDebugger());
auto& debugger = *_scriptResolver->GetDebugger().GetValue();
debugger.Run(8684);
debugger.RegisterContext(ctx);
if (waitForDebugger) {
std::cout << "Waiting for debugger" << std::endl;
while (!debugger.HasDebuggerAttached()) {
continue;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
for (auto& test : _tests) { for (auto& test : _tests) {
test.second->Run(ctx); test.second->Run(ctx);
} }

View File

@@ -7,10 +7,13 @@
#include "Globals.hpp" #include "Globals.hpp"
#include "Tester/AngelScript/BattleFunctions.hpp" #include "Tester/AngelScript/BattleFunctions.hpp"
#include "Tester/AngelScript/MiscMockFunctions.hpp" #include "Tester/AngelScript/MiscMockFunctions.hpp"
#include "Tester/AngelScript/PokemonBuilder.hpp"
#include "Tester/AngelScript/TestFunctions.hpp" #include "Tester/AngelScript/TestFunctions.hpp"
#include "Tester/TestRunner.hpp" #include "Tester/TestRunner.hpp"
#include "git.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
std::cout << "PokemonScript Tester version: " << GIT_DESCRIBE << std::endl;
args::ArgumentParser parser("PkmnLib Script Tester.", ""); args::ArgumentParser parser("PkmnLib Script Tester.", "");
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
@@ -20,6 +23,9 @@ int main(int argc, char** argv) {
args::ValueFlag<std::string> workingDirFlag(parser, "Working Directory", "Which work directory to use.", args::ValueFlag<std::string> workingDirFlag(parser, "Working Directory", "Which work directory to use.",
{"workdir"}); {"workdir"});
args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"}); args::Flag logTimeFlag(parser, "time-log", "Whether to show time logging.", {'t', "time-log"});
args::Flag forceColorFlag(parser, "force-color", "Whether to force color text output.", {'c', "force-color"});
args::Flag waitForDebuggerFlag(parser, "wait-for-debugger", "Whether to wait until a debugger is connected or not.",
{'w', "wait-for-debugger"});
try { try {
parser.ParseCLI(argc, argv); parser.ParseCLI(argc, argv);
} catch (args::Help&) { } catch (args::Help&) {
@@ -40,6 +46,9 @@ int main(int argc, char** argv) {
if (!workingDirectory.empty()) { if (!workingDirectory.empty()) {
chdir((const char*)std::filesystem::path(workingDirectory).c_str()); chdir((const char*)std::filesystem::path(workingDirectory).c_str());
} }
if (forceColorFlag.Get()) {
termcolor::colorize(std::cout);
}
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
std::function<void(PkmnLib::Battling::ScriptResolver*)> initialize = std::function<void(PkmnLib::Battling::ScriptResolver*)> initialize =
@@ -49,6 +58,7 @@ int main(int argc, char** argv) {
TestFunctions::Register(scriptResolver); TestFunctions::Register(scriptResolver);
BattleFunctions::Register(scriptResolver); BattleFunctions::Register(scriptResolver);
MiscMockFunctions::Register(scriptResolver); MiscMockFunctions::Register(scriptResolver);
PokemonBuilderRegistration::Register(scriptResolver);
}; };
Globals::Library = BuildLibrary::Build("", initialize); Globals::Library = BuildLibrary::Build("", initialize);
@@ -65,9 +75,8 @@ int main(int argc, char** argv) {
} }
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get()); auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(Globals::Library.GetValue()->GetScriptResolver().get());
auto testRunner = TestRunner(scriptResolver); auto testRunner = TestRunner(scriptResolver);
auto* engine = scriptResolver->GetBuilder().GetEngine();
std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point beginTests = std::chrono::steady_clock::now();
auto v = testRunner.RunAll(engine); auto v = testRunner.RunAll(waitForDebuggerFlag.Get());
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << std::endl std::cout << std::endl
<< "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "Total Run time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count()