Skip to content

Commit

Permalink
Merge branch 'main' into modernize-use-nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Jan 16, 2024
2 parents 79a74f8 + 59af02c commit 250203e
Show file tree
Hide file tree
Showing 39 changed files with 636 additions and 591 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
target_sources(${EXECUTABLE_NAME} PUBLIC
"src/audio_engine.cc"
"src/audio_engine.h"
"src/delay.cc"
"src/delay.h"
"src/fps_limiter.cc"
"src/fps_limiter.h"
"src/platform_compat.cc"
Expand Down Expand Up @@ -362,7 +364,7 @@ add_subdirectory("third_party/fpattern")
target_link_libraries(${EXECUTABLE_NAME} ${FPATTERN_LIBRARY})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${FPATTERN_INCLUDE_DIR})

if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux") AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") AND (NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD"))
add_subdirectory("third_party/zlib")
add_subdirectory("third_party/sdl2")
else()
Expand Down
36 changes: 18 additions & 18 deletions src/actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int _is_next_to(Object* a1, Object* a2);
static int _action_climb_ladder(Object* a1, Object* a2);
static int _action_use_skill_in_combat_error(Object* critter);
static int _pick_fall(Object* obj, int anim);
static int _report_explosion(Attack* attack, Object* a2);
static int _report_explosion(Attack* attack, Object* sourceObj);
static int _finished_explosion(Object* a1, Object* a2);
static int _compute_explosion_damage(int min, int max, Object* defender, int* knockbackDistancePtr);
static int _can_talk_to(Object* a1, Object* a2);
Expand Down Expand Up @@ -1579,9 +1579,9 @@ bool _action_explode_running()

// action_explode
// 0x412CF4
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* a5, bool a6)
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* sourceObj, bool animate)
{
if (a6 && _action_in_explode) {
if (animate && _action_in_explode) {
return -2;
}

Expand Down Expand Up @@ -1656,7 +1656,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object*

attackComputeDeathFlags(attack);

if (a6) {
if (animate) {
_action_in_explode = true;

reg_anim_begin(ANIMATION_REQUEST_RESERVED);
Expand All @@ -1678,7 +1678,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object*
animationRegisterHideObjectForced(adjacentExplosions[rotation]);
}

animationRegisterCallbackForced(attack, a5, (AnimationCallback*)_report_explosion, -1);
animationRegisterCallbackForced(attack, sourceObj, (AnimationCallback*)_report_explosion, -1);
animationRegisterCallbackForced(nullptr, nullptr, (AnimationCallback*)_finished_explosion, -1);
if (reg_anim_end() == -1) {
_action_in_explode = false;
Expand Down Expand Up @@ -1709,7 +1709,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object*
}
}

_report_explosion(attack, a5);
_report_explosion(attack, sourceObj);

_combat_explode_scenery(explosion, nullptr);

Expand All @@ -1724,7 +1724,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object*
}

// 0x413144
int _report_explosion(Attack* attack, Object* a2)
int _report_explosion(Attack* attack, Object* sourceObj)
{
bool mainTargetWasDead;
if (attack->defender != nullptr) {
Expand All @@ -1744,27 +1744,27 @@ int _report_explosion(Attack* attack, Object* a2)

Object* anyDefender = nullptr;
int xp = 0;
if (a2 != nullptr) {
if (attack->defender != nullptr && attack->defender != a2) {
if (sourceObj != nullptr) {
if (attack->defender != nullptr && attack->defender != sourceObj) {
if ((attack->defender->data.critter.combat.results & DAM_DEAD) != 0) {
if (a2 == gDude && !mainTargetWasDead) {
if (sourceObj == gDude && !mainTargetWasDead) {
xp += critterGetExp(attack->defender);
}
} else {
_critter_set_who_hit_me(attack->defender, a2);
_critter_set_who_hit_me(attack->defender, sourceObj);
anyDefender = attack->defender;
}
}

for (int index = 0; index < attack->extrasLength; index++) {
Object* critter = attack->extras[index];
if (critter != a2) {
if (critter != sourceObj) {
if ((critter->data.critter.combat.results & DAM_DEAD) != 0) {
if (a2 == gDude && !extrasWasDead[index]) {
if (sourceObj == gDude && !extrasWasDead[index]) {
xp += critterGetExp(critter);
}
} else {
_critter_set_who_hit_me(critter, a2);
_critter_set_who_hit_me(critter, sourceObj);

if (anyDefender == nullptr) {
anyDefender = critter;
Expand All @@ -1775,15 +1775,15 @@ int _report_explosion(Attack* attack, Object* a2)

if (anyDefender != nullptr) {
if (!isInCombat()) {
STRUCT_664980 combat;
CombatStartData combat;
combat.attacker = anyDefender;
combat.defender = a2;
combat.defender = sourceObj;
combat.actionPointsBonus = 0;
combat.accuracyBonus = 0;
combat.damageBonus = 0;
combat.minDamage = 0;
combat.maxDamage = INT_MAX;
combat.field_1C = 0;
combat.overrideAttackResults = 0;
scriptsRequestCombat(&combat);
}
}
Expand All @@ -1792,7 +1792,7 @@ int _report_explosion(Attack* attack, Object* a2)
internal_free(attack);
gameUiEnable();

if (a2 == gDude) {
if (sourceObj == gDude) {
_combat_give_exps(xp);
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ int actionPickUp(Object* critter, Object* item);
int _action_loot_container(Object* critter, Object* container);
int _action_skill_use(int a1);
int actionUseSkill(Object* a1, Object* a2, int skill);
bool _is_hit_from_front(Object* a1, Object* a2);
bool _is_hit_from_front(Object* attacker, Object* defender);
bool _can_see(Object* a1, Object* a2);
bool _action_explode_running();
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* a5, bool a6);
int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* sourceObj, bool animate);
int actionTalk(Object* a1, Object* a2);
void actionDamage(int tile, int elevation, int minDamage, int maxDamage, int damageType, bool animated, bool bypassArmor);
bool actionCheckPush(Object* a1, Object* a2);
Expand Down
52 changes: 18 additions & 34 deletions src/character_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "db.h"
#include "dbox.h"
#include "debug.h"
#include "delay.h"
#include "draw.h"
#include "game.h"
#include "game_mouse.h"
Expand Down Expand Up @@ -1991,7 +1992,7 @@ static int _get_input_str(int win, int cancelKeyCode, char* text, int maxLength,

windowRefresh(win);

while (getTicksSince(_frame_time) < 1000 / 24) { }
delay_ms(1000 / 24 - (getTicks() - _frame_time));

renderPresent();
sharedFpsLimiter.throttle();
Expand Down Expand Up @@ -2281,8 +2282,7 @@ static void characterEditorDrawBigNumber(int x, int y, int flags, int value, int
windowWidth);
windowRefreshRect(windowHandle, &rect);
renderPresent();
while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY)
;
delay_ms(BIG_NUM_ANIMATION_DELAY - (getTicks() - _frame_time));
}

blitBufferToBuffer(numbersGraphicBufferPtr + BIG_NUM_WIDTH * ones,
Expand All @@ -2304,8 +2304,7 @@ static void characterEditorDrawBigNumber(int x, int y, int flags, int value, int
windowWidth);
windowRefreshRect(windowHandle, &rect);
renderPresent();
while (getTicksSince(_frame_time) < BIG_NUM_ANIMATION_DELAY)
;
delay_ms(BIG_NUM_ANIMATION_DELAY - (getTicks() - _frame_time));
}

blitBufferToBuffer(numbersGraphicBufferPtr + BIG_NUM_WIDTH * tens,
Expand Down Expand Up @@ -3530,11 +3529,9 @@ static int characterEditorEditAge()
}

if (v33 > dbl_50170B) {
while (getTicksSince(_frame_time) < 1000 / _repFtime)
;
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / 24)
;
delay_ms(1000 / 24 - (getTicks() - _frame_time));
}

keyCode = inputGetInput();
Expand All @@ -3548,8 +3545,7 @@ static int characterEditorEditAge()
} else {
windowRefresh(win);

while (getTicksSince(_frame_time) < 1000 / 24)
;
delay_ms(1000 / 24 - (getTicks() - _frame_time));
}

renderPresent();
Expand Down Expand Up @@ -3699,8 +3695,7 @@ static void characterEditorEditGender()

windowRefresh(win);

while (getTicksSince(_frame_time) < 41)
;
delay_ms(41 - (getTicks() - _frame_time));

renderPresent();
sharedFpsLimiter.throttle();
Expand Down Expand Up @@ -3778,12 +3773,9 @@ static void characterEditorAdjustPrimaryStat(int eventCode)
}

if (v11 >= 19.2) {
unsigned int delay = 1000 / _repFtime;
while (getTicksSince(_frame_time) < delay) {
}
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / 24) {
}
delay_ms(1000 / 24 - (getTicks() - _frame_time));
}

renderPresent();
Expand Down Expand Up @@ -5279,11 +5271,9 @@ static void characterEditorHandleAdjustSkillButtonPressed(int keyCode)
if (!isUsingKeyboard) {
unspentSp = pcGetStat(PC_STAT_UNSPENT_SKILL_POINTS);
if (repeatDelay >= dbl_5018F0) {
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
}
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / 24) {
}
delay_ms(1000 / 24 - (getTicks() - _frame_time));
}

int keyCode = inputGetInput();
Expand Down Expand Up @@ -6141,11 +6131,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
}

if (v19 < dbl_5019BE) {
while (getTicksSince(_frame_time) < 1000 / 24) {
}
delay_ms(1000 / 24 - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
}
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
}

renderPresent();
Expand Down Expand Up @@ -6188,11 +6176,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
}

if (v19 < dbl_5019BE) {
while (getTicksSince(_frame_time) < 1000 / 24) {
}
delay_ms(1000 / 24 - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
}
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
}

renderPresent();
Expand Down Expand Up @@ -6224,11 +6210,9 @@ static int perkDialogHandleInput(int count, void (*refreshProc)())
}

if (v19 < dbl_5019BE) {
while (getTicksSince(_frame_time) < 1000 / 24) {
}
delay_ms(1000 / 24 - (getTicks() - _frame_time));
} else {
while (getTicksSince(_frame_time) < 1000 / _repFtime) {
}
delay_ms(1000 / _repFtime - (getTicks() - _frame_time));
}

renderPresent();
Expand Down
Loading

0 comments on commit 250203e

Please sign in to comment.