Permalink
Browse files

game: use function parameter instead of return function for output fi…

…red entity
  • Loading branch information...
Aranud committed Nov 8, 2017
1 parent 9d91897 commit 7952bb9ac62ec6b666f80fef9d12b9e822f02b84
Showing with 76 additions and 87 deletions.
  1. +2 −2 src/game/g_local.h
  2. +74 −85 src/game/g_weapon.c
View
@@ -1550,7 +1550,7 @@ void G_PreFilledMissileEntity(gentity_t *ent, int weaponNum, int realWeapon, int
qboolean AccuracyHit(gentity_t *target, gentity_t *attacker);
void CalcMuzzlePoint(gentity_t *ent, int weapon, vec3_t forward, vec3_t right, vec3_t up, vec3_t muzzlePoint);
void SnapVectorTowards(vec3_t v, vec3_t to);
gentity_t *weapon_grenadelauncher_fire(gentity_t *ent);
void weapon_grenadelauncher_fire(gentity_t *ent, gentity_t *firedShot);
void G_FadeItems(gentity_t *ent, int modType);
gentity_t *G_FindSatchel(gentity_t *ent);
@@ -2738,7 +2738,7 @@ void G_RailBox(vec_t *origin, vec_t *mins, vec_t *maxs, vec_t *color, int index)
typedef struct weapFireFunction_s
{
weapon_t weapon;
gentity_t *(*fire)(gentity_t * ent);
void (*fire)(gentity_t *ent, gentity_t *firedShot);
} weapFireFunction_t;
Oops, something went wrong.

2 comments on commit 7952bb9

@zturtleman

This comment has been minimized.

Show comment
Hide comment
@zturtleman

zturtleman Nov 9, 2017

Contributor

This commit introduces a bug. Omni-bot will never know about fired projectiles.

Changing the function argument gentity_t *firedShot to point to a different address does not affect the calling function.

void FireWeapon() {
    gentity_t *firedShot = NULL;
    Weapon_XFire(ent, firedShot);
    // firedShot will _always_ be NULL here.
}

To be able to change the pointer located in FireWeapon(), you have to pass a pointer to the pointer.

void Weapon_XFire(gentity_t *ent, gentity_t **firedShot) {
    gentity_t *traceEnt = NULL;
...
    if (firedShot != NULL) // passed address to a pointer
        *firedShot = traceEnt; // set the pointer
}

void FireWeapon() {
    gentity_t *firedShot = NULL;
    Weapon_XFire(ent, &firedShot);
    // firedShot may be non-NULL here.
}
Contributor

zturtleman replied Nov 9, 2017

This commit introduces a bug. Omni-bot will never know about fired projectiles.

Changing the function argument gentity_t *firedShot to point to a different address does not affect the calling function.

void FireWeapon() {
    gentity_t *firedShot = NULL;
    Weapon_XFire(ent, firedShot);
    // firedShot will _always_ be NULL here.
}

To be able to change the pointer located in FireWeapon(), you have to pass a pointer to the pointer.

void Weapon_XFire(gentity_t *ent, gentity_t **firedShot) {
    gentity_t *traceEnt = NULL;
...
    if (firedShot != NULL) // passed address to a pointer
        *firedShot = traceEnt; // set the pointer
}

void FireWeapon() {
    gentity_t *firedShot = NULL;
    Weapon_XFire(ent, &firedShot);
    // firedShot may be non-NULL here.
}
@Aranud

This comment has been minimized.

Show comment
Hide comment
@Aranud

Aranud Nov 10, 2017

Contributor

Thx you ! Now it's fixed ! a355600

Contributor

Aranud replied Nov 10, 2017

Thx you ! Now it's fixed ! a355600

Please sign in to comment.