Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1916 from captainurist/macos_fixes_616
Browse files Browse the repository at this point in the history
Always run game tests
  • Loading branch information
pskelton authored Feb 9, 2025
2 parents 7f35f86 + b45dc05 commit a92ee53
Show file tree
Hide file tree
Showing 36 changed files with 193 additions and 249 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,14 @@ jobs:
make Run_UnitTest
- name: Run game tests
if: steps.restore-data-cache.outputs.cache-hit == 'true'
working-directory: build
run: |
make Run_GameTest_Headless_Parallel
env:
OPENENROTH_MM7_PATH: /home/runner/work/OpenEnroth/OpenEnroth/OpenEnroth_GameData/mm7

- name: Run retrace tests
if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug'
if: matrix.configuration != 'Debug'
working-directory: build
run: |
make Run_RetraceTest_Headless_Parallel
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ jobs:
make Run_UnitTest
- name: Run game tests
if: steps.restore-data-cache.outputs.cache-hit == 'true'
working-directory: build
run: |
make Run_GameTest_Headless_Parallel
env:
OPENENROTH_MM7_PATH: /Users/runner/work/OpenEnroth/OpenEnroth/OpenEnroth_GameData/mm7

- name: Run retrace tests
if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug'
if: matrix.configuration != 'Debug'
working-directory: build
run: |
make Run_RetraceTest_Headless_Parallel
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ jobs:
# Only run gametest if we restored game data.
- name: Run game tests
if: steps.restore-data-cache.outputs.cache-hit == 'true'
working-directory: build
run: |
ninja Run_GameTest_Headless_Parallel
env:
OPENENROTH_MM7_PATH: 'D:\a\OpenEnroth\OpenEnroth\OpenEnroth_GameData\mm7'

- name: Run retrace tests
if: steps.restore-data-cache.outputs.cache-hit == 'true' && matrix.configuration != 'Debug'
if: matrix.configuration != 'Debug'
working-directory: build
run: |
ninja Run_RetraceTest_Headless_Parallel
Expand Down
4 changes: 4 additions & 0 deletions src/Application/GameWindowHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ void GameWindowHandler::OnMouseLeftClick(Pointi position) {
} else {
pMediaPlayer->StopMovie();

mouse->SetMousePosition(position.x, position.y);

if (GetCurrentMenuID() == MENU_CREATEPARTY) {
UI_OnKeyDown(PlatformKey::KEY_SELECT);
}
Expand All @@ -226,6 +228,8 @@ void GameWindowHandler::OnMouseRightClick(Pointi position) {
} else {
pMediaPlayer->StopMovie();

mouse->SetMousePosition(position.x, position.y);

if (engine) {
engine->PickMouse(pCamera3D->GetMouseInfoDepth(), position.x, position.y, &vis_allsprites_filter, &vis_door_filter);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Bin/OpenEnroth/OpenEnrothOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ OpenEnrothOptions OpenEnrothOptions::parse(int argc, char **argv) {

if (result.retrace.traces.empty())
throw Exception("No trace files to retrace.");

if (!result.logLevel)
result.logLevel = LOG_ERROR; // Default log level for retracing is LOG_ERROR.
}

if (result.subcommand == SUBCOMMAND_PLAY)
Expand Down
1 change: 1 addition & 0 deletions src/Engine/Components/Control/EngineControlComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <utility>
#include <memory>
#include <exception>

#include "Library/Platform/Interface/PlatformEventHandler.h"

Expand Down
1 change: 0 additions & 1 deletion src/Engine/Components/Control/EngineControlState.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <queue>
#include <functional>
#include <memory>
#include <exception>

#include "Utility/IndexedArray.h"

Expand Down
221 changes: 107 additions & 114 deletions src/Engine/Objects/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "GUI/UI/UISpell.h"
#include "GUI/UI/UIDialogue.h"
#include "GUI/UI/Books/AutonotesBook.h"
#include "GUI/UI/ItemGrid.h"

#include "Library/Logger/Logger.h"

Expand Down Expand Up @@ -651,7 +650,7 @@ int Character::CreateItemInInventory(unsigned int uSlot, ItemId uItemID) {

return 0;
} else { // place items
PutItemAtInventoryIndex(uItemID, freeSlot, uSlot);
PutItemArInventoryIndex(uItemID, freeSlot, uSlot);
this->pInventoryItemList[freeSlot].uItemID = uItemID;
}

Expand Down Expand Up @@ -739,7 +738,7 @@ int Character::CreateItemInInventory2(unsigned int index,
if (freeSlot == -1) { // no room
result = 0;
} else {
PutItemAtInventoryIndex(Src->uItemID, freeSlot, index);
PutItemArInventoryIndex(Src->uItemID, freeSlot, index);
pInventoryItemList[freeSlot] = *Src;
result = freeSlot + 1;
}
Expand All @@ -748,23 +747,21 @@ int Character::CreateItemInInventory2(unsigned int index,
}

//----- (0049298B) --------------------------------------------------------
void Character::PutItemAtInventoryIndex(
void Character::PutItemArInventoryIndex(
ItemId uItemID, int itemListPos,
int index) { // originally accepted ItemGen *but needed only its uItemID

auto img = assets->getImage_ColorKey(pItemTable->pItems[uItemID].iconName);
int slot_width = GetSizeInInventorySlots(img->width());
int slot_height = GetSizeInInventorySlots(img->height());

// TODO(_): try to come up with a better
// solution. negative values are used when
// drawing the inventory - nothing is drawn
if (slot_width > 0) {
int *pInvPos = &pInventoryMatrix[index];
for (int i = 0; i < slot_height; i++) {
memset32(pInvPos, -1 - index,
slot_width); // TODO(_): try to come up with a better
// solution. negative values are used when
// drawing the inventory - nothing is drawn
pInvPos += INVENTORY_SLOTS_WIDTH;
}
for (int i = 0; i < slot_height; i++)
for (int j = 0; j < slot_width; j++)
pInventoryMatrix[index + i * INVENTORY_SLOTS_WIDTH + j] = -1 - index;
}

pInventoryMatrix[index] = itemListPos + 1;
Expand All @@ -786,11 +783,9 @@ void Character::RemoveItemAtInventoryIndex(unsigned int index) {
}

if (slot_width > 0) {
int *pInvPos = &pInventoryMatrix[index];
for (int i = 0; i < slot_height; i++) {
memset32(pInvPos, 0, slot_width);
pInvPos += INVENTORY_SLOTS_WIDTH;
}
for (int i = 0; i < slot_height; i++)
for (int j = 0; j < slot_width; j++)
pInventoryMatrix[index + i * INVENTORY_SLOTS_WIDTH + j] = 0;
}
}

Expand Down Expand Up @@ -6558,115 +6553,113 @@ void DamageCharacterFromMonster(Pid uObjID, ActorAbility dmgSource, signed int t
}

void Character::OnInventoryLeftClick() {
if (current_character_screen_window != WINDOW_CharacterWindow_Inventory) {
return;
}
ItemId pickedItemId; // esi@12
unsigned int invItemIndex; // eax@12
unsigned int itemPos; // eax@18
ItemGen tmpItem; // [sp+Ch] [bp-3Ch]@1

CastSpellInfo *pSpellInfo;

if (current_character_screen_window == WINDOW_CharacterWindow_Inventory) {
int pY;
int pX;
mouse->GetClickPos(&pX, &pY);

int inventoryYCoord = (pY - 17) / 32;
int inventoryXCoord = (pX - 14) / 32;
int invMatrixIndex = inventoryXCoord + (INVENTORY_SLOTS_WIDTH * inventoryYCoord);

if (inventoryYCoord >= 0 && inventoryYCoord < INVENTORY_SLOTS_HEIGHT &&
inventoryXCoord >= 0 && inventoryXCoord < INVENTORY_SLOTS_WIDTH) {
if (IsEnchantingInProgress) {
unsigned int enchantedItemPos = this->GetItemListAtInventoryIndex(invMatrixIndex);

if (enchantedItemPos) {
/* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &=
*0x7Fu;
*((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) =
*pParty->activeCharacterIndex() - 1;
*((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) =
*enchantedItemPos - 1;
*((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) =
*invMatrixIndex;*/
pSpellInfo = pGUIWindow_CastTargetedSpell->spellInfo();
pSpellInfo->flags &= ~ON_CAST_TargetedEnchantment;
pSpellInfo->targetCharacterIndex = pParty->activeCharacterIndex() - 1;
pSpellInfo->targetInventoryIndex = enchantedItemPos - 1;
ptr_50C9A4_ItemToEnchant = &this->pInventoryItemList[enchantedItemPos - 1];
IsEnchantingInProgress = false;

engine->_messageQueue->clear();

mouse->SetCursorImage("MICON1");
AfterEnchClickEventId = UIMSG_Escape;
AfterEnchClickEventSecondParam = 0;
AfterEnchClickEventTimeout = Duration::fromRealtimeSeconds(2);
}

int pY;
int pX;
mouse->GetClickPos(&pX, &pY);

int inventoryXCoord = (pX + mouse->pickedItemOffsetX - 14) / 32;
int inventoryYCoord = (pY + mouse->pickedItemOffsetY - 17) / 32;
int invMatrixIndex = inventoryXCoord + (INVENTORY_SLOTS_WIDTH * inventoryYCoord);

if (inventoryYCoord >= 0 && inventoryYCoord < INVENTORY_SLOTS_HEIGHT &&
inventoryXCoord >= 0 && inventoryXCoord < INVENTORY_SLOTS_WIDTH) {
if (IsEnchantingInProgress) {
unsigned int enchantedItemPos = this->GetItemListAtInventoryIndex(invMatrixIndex);

if (enchantedItemPos) {
/* *((char *)pGUIWindow_CastTargetedSpell->ptr_1C + 8) &=
*0x7Fu;
*((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 2) =
*pParty->activeCharacterIndex() - 1;
*((int *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) =
*enchantedItemPos - 1;
*((short *)pGUIWindow_CastTargetedSpell->ptr_1C + 3) =
*invMatrixIndex;*/
CastSpellInfo* pSpellInfo;
pSpellInfo = pGUIWindow_CastTargetedSpell->spellInfo();
pSpellInfo->flags &= ~ON_CAST_TargetedEnchantment;
pSpellInfo->targetCharacterIndex = pParty->activeCharacterIndex() - 1;
pSpellInfo->targetInventoryIndex = enchantedItemPos - 1;
ptr_50C9A4_ItemToEnchant = &this->pInventoryItemList[enchantedItemPos - 1];
IsEnchantingInProgress = false;

engine->_messageQueue->clear();

mouse->SetCursorImage("MICON1");
AfterEnchClickEventId = UIMSG_Escape;
AfterEnchClickEventSecondParam = 0;
AfterEnchClickEventTimeout = Duration::fromRealtimeSeconds(2);
return;
}

return;
}

if (ptr_50C9A4_ItemToEnchant)
return;
if (ptr_50C9A4_ItemToEnchant)
return;

auto item = this->GetItemAtInventoryIndex(invMatrixIndex);
if (!item && pParty->pPickedItem.uItemID == ITEM_NULL) {
return; // nothing to do
}
pickedItemId = pParty->pPickedItem.uItemID;
invItemIndex = this->GetItemListAtInventoryIndex(invMatrixIndex);

// calc offsets of where on the item was clicked
// first need index of top left corner of the item
int cornerInd = GetItemMainInventoryIndex(invMatrixIndex);
int cornerX = cornerInd % INVENTORY_SLOTS_WIDTH;
int cornerY = cornerInd / INVENTORY_SLOTS_WIDTH;
int itemXOffset = pX + mouse->pickedItemOffsetX - 14 - (cornerX * 32);
int itemYOffset = pY + mouse->pickedItemOffsetY - 17 - (cornerY * 32);

if (item) {
auto tex = assets->getImage_Alpha(item->GetIconName());
itemXOffset -= itemOffset(tex->width());
itemYOffset -= itemOffset(tex->height());
}
if (pickedItemId == ITEM_NULL) { // no hold item
if (!invItemIndex) {
return;
} else {
pParty->pPickedItem = this->pInventoryItemList[invItemIndex - 1];
this->RemoveItemAtInventoryIndex(invMatrixIndex);
pickedItemId = pParty->pPickedItem.uItemID;
mouse->SetCursorImage(pItemTable->pItems[pickedItemId].iconName);
return;
}
} else { // hold item
if (invItemIndex) {
ItemGen *invItemPtr = &this->pInventoryItemList[invItemIndex - 1];
tmpItem = *invItemPtr;
int oldinvMatrixIndex = invMatrixIndex;
invMatrixIndex = GetItemMainInventoryIndex(invMatrixIndex);
this->RemoveItemAtInventoryIndex(oldinvMatrixIndex);
int emptyIndex = this->AddItem2(invMatrixIndex, &pParty->pPickedItem);

if (pParty->pPickedItem.uItemID == ITEM_NULL) {
// pick up the item
pParty->setHoldingItem(item, -itemXOffset, -itemYOffset);
this->RemoveItemAtInventoryIndex(invMatrixIndex);
return;
} else {
if (item) {
// swap items
ItemGen tmpItem = *item;
int oldinvMatrixIndex = invMatrixIndex;
this->RemoveItemAtInventoryIndex(invMatrixIndex);
invMatrixIndex = GetItemMainInventoryIndex(invMatrixIndex);
int invItemIndex = this->GetItemListAtInventoryIndex(invMatrixIndex);

// try to add where we clicked
int emptyIndex = this->AddItem2(invMatrixIndex, &pParty->pPickedItem);
if (!emptyIndex) {
// try to add anywhere
emptyIndex = this->AddItem2(-1, &pParty->pPickedItem);
if (!emptyIndex) {
// failed to add, put back the old item
this->PutItemAtInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex);
emptyIndex = this->AddItem2(-1, &pParty->pPickedItem);
if (!emptyIndex) {
this->PutItemArInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex);
*invItemPtr = tmpItem;
return;
}
}

pParty->pPickedItem = tmpItem;
mouse->SetCursorImage(pParty->pPickedItem.GetIconName());
return;
} else {
itemPos = this->AddItem(invMatrixIndex, pickedItemId);

if (itemPos) {
this->pInventoryItemList[itemPos - 1] = pParty->pPickedItem;
mouse->RemoveHoldingItem();
return;
}
}

mouse->RemoveHoldingItem();
pParty->setHoldingItem(&tmpItem);
return;
} else {
// place picked item
int itemPos = this->AddItem(invMatrixIndex, pParty->pPickedItem.uItemID);
// itemPos = this->AddItem(-1, pickedItemId);

if (itemPos) {
this->pInventoryItemList[itemPos - 1] = pParty->pPickedItem;
mouse->RemoveHoldingItem();
return;
// if ( itemPos ) {
// memcpy(&this->pInventoryItemList[itemPos-1],
// &pParty->pPickedItem, sizeof(ItemGen));
// pMouse->RemoveHoldingItem();
// return;
// }
}
}
}
}
}
} // held item or no
} // limits
} // char wind
} // func

bool Character::IsWeak() const {
return this->conditions.Has(CONDITION_WEAK);
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Objects/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Character {
int AddItem(int uSlot, ItemId uItemID);
int AddItem2(int uSlot, ItemGen *Src);
int CreateItemInInventory2(unsigned int index, ItemGen *Src);
void PutItemAtInventoryIndex(ItemId uItemID, int itemListPos, int uSlot);
void PutItemArInventoryIndex(ItemId uItemID, int itemListPos, int uSlot);
void RemoveItemAtInventoryIndex(unsigned int uSlot);
bool CanAct() const;
bool CanSteal() const;
Expand Down
Loading

0 comments on commit a92ee53

Please sign in to comment.