From 29de10fc91dbefcdec0c9f7e8798ae18490f353f Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 29 Jan 2018 02:14:00 +0000 Subject: [PATCH] Maintenance on Gv_DivVar git-svn-id: https://svn.eduke32.com/eduke32@6610 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gamevars.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source/duke3d/src/gamevars.h b/source/duke3d/src/gamevars.h index 3cfc94e13..efb3977db 100644 --- a/source/duke3d/src/gamevars.h +++ b/source/duke3d/src/gamevars.h @@ -187,10 +187,11 @@ static FORCE_INLINE void __fastcall Gv_DivVar(int const id, int32_t const operan static libdivide_s32_t sdiv; static int32_t lastValue; - libdivide_s32_t *dptr = ((unsigned) operand < DIVTABLESIZE) ? (libdivide_s32_t *) &divtable32[operand] : &sdiv; intptr_t *iptr = &aGameVars[id].global; + bool const foundInTable = (unsigned) operand < DIVTABLESIZE; + libdivide_s32_t *dptr = foundInTable ? (libdivide_s32_t *) &divtable32[operand] : &sdiv; - if (operand == lastValue || dptr != &sdiv) + if (operand == lastValue || foundInTable) goto skip; sdiv = libdivide_s32_gen((lastValue = operand)); @@ -202,17 +203,23 @@ skip: default: break; case GAMEVAR_PERACTOR: iptr = &aGameVars[id].pValues[vm.spriteNum]; break; case GAMEVAR_INT32PTR: - *((int32_t *)aGameVars[id].global) = - (int32_t)libdivide_s32_do(*((int32_t *)aGameVars[id].global), dptr); + { + int32_t & var = *(int32_t *)aGameVars[id].global; + var = (int32_t)libdivide_s32_do(var, dptr); return; + } case GAMEVAR_INT16PTR: - *((int16_t *)aGameVars[id].global) = - (int16_t)libdivide_s32_do(*((int16_t *)aGameVars[id].global), dptr); + { + int16_t & var = *(int16_t *)aGameVars[id].global; + var = (int16_t)libdivide_s32_do(var, dptr); return; + } case GAMEVAR_UINT8PTR: - *((uint8_t *)aGameVars[id].global) = - (uint8_t)libdivide_s32_do(*((uint8_t *)aGameVars[id].global), dptr); + { + uint8_t & var = *(uint8_t *)aGameVars[id].global; + var = (uint8_t)libdivide_s32_do(var, dptr); return; + } } *iptr = libdivide_s32_do(*iptr, dptr);