- use player_struct from JFDuke.

This commit is contained in:
Christoph Oelckers 2020-07-06 21:57:38 +02:00
parent 631398a35a
commit 642ae03d90
6 changed files with 125 additions and 158 deletions

View file

@ -12,7 +12,7 @@
struct PalEntry struct PalEntry
{ {
PalEntry() = default; PalEntry() = default;
PalEntry (uint32_t argb) { d = argb; } constexpr PalEntry (uint32_t argb) : d(argb) { }
operator uint32_t () const { return d; } operator uint32_t () const { return d; }
void SetRGB(PalEntry other) void SetRGB(PalEntry other)
{ {
@ -36,35 +36,35 @@ struct PalEntry
return other; return other;
} }
} }
int Luminance() const constexpr int Luminance() const
{ {
return (r * 77 + g * 143 + b * 37) >> 8; return (r * 77 + g * 143 + b * 37) >> 8;
} }
int Amplitude() const constexpr int Amplitude() const
{ {
return std::max(r, std::max(g, b)); return std::max(r, std::max(g, b));
} }
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark. constexpr void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
{ {
int v = (r + g + b); int v = (r + g + b);
r = g = b = ((255*3) + v + v) / 9; r = g = b = ((255*3) + v + v) / 9;
} }
bool isBlack() const constexpr bool isBlack() const
{ {
return (d & 0xffffff) == 0; return (d & 0xffffff) == 0;
} }
bool isWhite() const constexpr bool isWhite() const
{ {
return (d & 0xffffff) == 0xffffff; return (d & 0xffffff) == 0xffffff;
} }
PalEntry &operator= (const PalEntry &other) = default; PalEntry &operator= (const PalEntry &other) = default;
PalEntry &operator= (uint32_t other) { d = other; return *this; } constexpr PalEntry &operator= (uint32_t other) { d = other; return *this; }
PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; } constexpr PalEntry InverseColor() const { PalEntry nc(a, 255 - r, 255 - g, 255 - b); return nc; }
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {} constexpr PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {}
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {} constexpr PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {}
union union
{ {
struct struct
@ -74,8 +74,8 @@ struct PalEntry
uint32_t d; uint32_t d;
}; };
#else #else
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {} constexpr PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {}
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {} constexpr PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {}
union union
{ {
struct struct
@ -87,7 +87,7 @@ struct PalEntry
#endif #endif
}; };
inline int Luminance(int r, int g, int b) constexpr inline int Luminance(int r, int g, int b)
{ {
return (r * 77 + g * 143 + b * 37) >> 8; return (r * 77 + g * 143 + b * 37) >> 8;
} }

View file

@ -998,7 +998,7 @@ int parse(void)
ps[g_p].wackedbyactor = -1; ps[g_p].wackedbyactor = -1;
ps[g_p].shield_amount = max_armour_amount; ps[g_p].shield_amount = max_armour_amount;
ps[g_p].dead_flag = 0; ps[g_p].dead_flag = 0;
ps[g_p].pals.f = 0; ps[g_p].pals.a = 0;
ps[g_p].footprintcount = 0; ps[g_p].footprintcount = 0;
ps[g_p].weapreccnt = 0; ps[g_p].weapreccnt = 0;
ps[g_p].ftq = 0; ps[g_p].ftq = 0;

View file

@ -265,8 +265,8 @@ int domovethings()
if (ud.pause_on == 0) if (ud.pause_on == 0)
{ {
auto p = &ps[i]; auto p = &ps[i];
if (p->pals.f > 0) if (p->pals.a > 0)
p->pals.f--; p->pals.a--;
fi.processinput(i); fi.processinput(i);
fi.checksectors(i); fi.checksectors(i);

View file

@ -109,44 +109,119 @@ typedef struct {
} input_t; } input_t;
#pragma pack(push,1) #pragma pack(push,1)
// XXX: r1625 changed a lot types here, among others
// * int32_t --> int16_t typedef struct player_struct
// * int16_t --> int8_t {
// * char --> int8_t // This is basically the version from JFDuke but this first block contains a few changes to make it work with other parts of Raze.
// Need to carefully think about implications!
// TODO: rearrange this if the opportunity arises! // The sound code wants to read a vector out of this so we need to define one for the main coordinate.
// KEEPINSYNC lunatic/_defs_game.lua
typedef struct player_struct {
union union
{ {
vec3_t pos; vec3_t pos;
struct { int32_t posx, posy, posz; }; struct { int32_t posx, posy, posz; };
}; };
union
{
vec3_t opos;
struct { int32_t oposx, oposy, oposz; };
};
union // input handles angle and horizon as fixed16 numbers. We need to account for that as well.
{ fixed_t q16ang, oq16ang, q16horiz, q16horizoff; // oq16horiz, oq16horizoff; // These two are currently not used but may be again later.
vec3_t vel;
struct { int32_t posxv, posyv, poszv; };
};
vec3_t npos;
union
{
vec2_t bobpos;
struct { int32_t bobposx, bobposy; };
};
// using a bit field for this to save a bit of space.
FixedBitArray<MAX_WEAPONS> gotweapon;
// Palette management uses indices into the engine's palette table now.
unsigned int palette;
PalEntry pals;
// these did not exist in JFDuke.
uint8_t movement_lock;
vec2_t fric; vec2_t fric;
fix16_t q16horiz, q16horizoff; // From here on it is unaltered from JFDuke with the exception of a few fields that are no longer needed and were removed.
fix16_t q16ang, oq16ang; int zoom, exitx, exity, loogiex[64], loogiey[64], numloogs, loogcnt;
int look_ang; int invdisptime;
int16_t orotscrnang, rotscrnang; // JBF 20031220: added orotscrnang int bobposx, bobposy, oposx, oposy, oposz, pyoff, opyoff;
int posxv, posyv, poszv, last_pissed_time, truefz, truecz;
int player_par, visibility;
int bobcounter, weapon_sway;
int pals_time, randomflamex, crack_time;
int aim_mode, auto_aim, weaponswitch;
short angvel, cursectnum, look_ang, last_extra, subweapon;
short ammo_amount[MAX_WEAPONS], wackedbyactor, frag, fraggedself;
short curr_weapon, last_weapon, tipincs, wantweaponfire;
short holoduke_amount, newowner, hurt_delay, hbomb_hold_delay;
short jumping_counter, airleft, knee_incs, access_incs;
short ftq, access_wallnum, access_spritenum;
short kickback_pic, got_access, weapon_ang, firstaid_amount;
short somethingonplayer, on_crane, i, one_parallax_sectnum;
short over_shoulder_on, random_club_frame, fist_incs;
short one_eighty_count, cheat_phase;
short dummyplayersprite, extra_extra8, quick_kick;
short heat_amount, actorsqu, timebeforeexit, customexitsound;
short weaprecs[256], weapreccnt;
unsigned int interface_toggle_flag;
short orotscrnang, rotscrnang, dead_flag, show_empty_weapon; // JBF 20031220: added orotscrnang
short scuba_amount, jetpack_amount, steroids_amount, shield_amount;
short holoduke_on, pycount, weapon_pos, frag_ps;
short transporter_hold, last_full_weapon, footprintshade, boot_amount;
int scream_voice;
unsigned char gm;
unsigned char on_warping_sector, footprintcount;
unsigned char hbomb_on, jumping_toggle, rapid_fire_hold, on_ground;
char name[32];
unsigned char inven_icon, buttonpalette;
unsigned char jetpack_on, spritebridge, lastrandomspot;
unsigned char scuba_on, footprintpal, heat_on;
unsigned char holster_weapon;
unsigned char falling_counter;
unsigned char refresh_inventory;
unsigned char toggle_key_flag, knuckle_incs; // ,select_dir;
unsigned char walking_snd_toggle, palookup, hard_landing;
unsigned char return_to_center;
int max_secret_rooms, secret_rooms, max_actors_killed, actors_killed;
// Redneck Rampage additions. Those which did not have names in the reconstructed source got one from either RedneckGDX or RedNukem.
// Items were reordered by size.
int stairs;
int detonate_count; // at57e
int noise_x, noise_y, noise_radius; // at286, at28a, at290
int drink_timer; // at58e
int eat_timer; // at592
int SlotWin;
short recoil;
short detonate_time; // at57c
short yehaa_timer;
short drink_amt, eat, drunkang, eatang;
uint8_t shotgun_state[2];
uint8_t donoise; // at28e
uint8_t keys[5];
// RRRA. The same as for the RR block applies.
int drug_aspect;
int drug_timer;
int SeaSick;
short MamaEnd; // raat609
short MotoSpeed, TiltStatus, moto_drink;
short VBumpNow, VBumpTarget, TurbCount;
short drug_stat[3]; // raat5f1..5
uint8_t DrugMode, lotag800kill;
uint8_t sea_sick_stat; // raat5dd
uint8_t hurt_delay2, nocheat;
uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround;
uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud;
int8_t crouch_toggle;
// Access helpers for the widened angle and horizon fields.
int getlookang() { return look_ang; } int getlookang() { return look_ang; }
void setlookang(int b) { look_ang = b; } void setlookang(int b) { look_ang = b; }
void addlookang(int b) { look_ang += b; } void addlookang(int b) { look_ang += b; }
@ -156,7 +231,7 @@ typedef struct player_struct {
int getang() { return q16ang >> FRACBITS; } int getang() { return q16ang >> FRACBITS; }
int getoang() { return oq16ang >> FRACBITS; } int getoang() { return oq16ang >> FRACBITS; }
void setang(int v) { q16ang = v << FRACBITS; } void setang(int v) { q16ang = v << FRACBITS; }
void addang(int v) { q16ang = (q16ang + (v << FRACBITS)) & ((2048 << FRACBITS)-1); } void addang(int v) { q16ang = (q16ang + (v << FRACBITS)) & ((2048 << FRACBITS) - 1); }
void setoang(int v) { oq16ang = v << FRACBITS; } void setoang(int v) { oq16ang = v << FRACBITS; }
void addhoriz(int v) { q16horiz += (v << FRACBITS); } void addhoriz(int v) { q16horiz += (v << FRACBITS); }
void addhorizoff(int v) { q16horiz += (v << FRACBITS); } void addhorizoff(int v) { q16horiz += (v << FRACBITS); }
@ -166,113 +241,8 @@ typedef struct player_struct {
int gethorizof() { return q16horizoff >> FRACBITS; } int gethorizof() { return q16horizoff >> FRACBITS; }
int gethorizsum() { return (q16horiz + q16horizoff) >> FRACBITS; } int gethorizsum() { return (q16horiz + q16horizoff) >> FRACBITS; }
int32_t truefz, truecz, player_par;
int32_t randomflamex, exitx, exity;
int32_t runspeed;
uint32_t interface_toggle_flag;
uint16_t max_actors_killed, actors_killed;
FixedBitArray<MAX_WEAPONS> gotweapon;
uint16_t zoom;
int16_t loogiex[64], loogiey[64], sbs, sound_pitch;
int16_t cursectnum, last_extra, subweapon;
int16_t ammo_amount[MAX_WEAPONS];
int16_t firstaid_amount;
int16_t steroids_amount;
int16_t holoduke_amount;
int16_t jetpack_amount;
int16_t heat_amount;
int16_t scuba_amount;
int16_t boot_amount;
int16_t shield_amount;
int16_t wackedbyactor, pyoff, opyoff;
int16_t newowner, jumping_counter, airleft;
int16_t /*fta,*/ ftq, access_wallnum, access_spritenum;
int16_t got_access, weapon_ang, visibility;
int16_t somethingonplayer, on_crane, i, one_parallax_sectnum;
int16_t random_club_frame, one_eighty_count;
int16_t dummyplayersprite, extra_extra8;
int16_t actorsqu, timebeforeexit, customexitsound, last_pissed_time;
int16_t weaprecs[MAX_WEAPON_RECS], weapon_sway, crack_time, bobcounter;
int16_t dead_flag;
int16_t holoduke_on, pycount;
int16_t transporter_hold/*, clipdist*/;
uint8_t max_secret_rooms, secret_rooms;
// XXX: 255 values for frag(gedself) seems too small.
uint8_t frag, fraggedself, quick_kick, last_quick_kick;
uint8_t return_to_center, reloading, weapreccnt;
uint8_t aim_mode, auto_aim, weaponswitch, movement_lock, team;
uint8_t tipincs, hbomb_hold_delay, frag_ps, kickback_pic;
uint8_t gm, on_warping_sector, footprintcount, hurt_delay;
uint8_t hbomb_on, jumping_toggle, rapid_fire_hold, on_ground;
uint8_t inven_icon, buttonpalette, over_shoulder_on, show_empty_weapon;
uint8_t jetpack_on, spritebridge, lastrandomspot;
uint8_t scuba_on, footprintpal, heat_on, invdisptime;
uint8_t holster_weapon, falling_counter, footprintshade;
uint8_t refresh_inventory, last_full_weapon;
uint8_t toggle_key_flag, knuckle_incs, knee_incs, access_incs;
uint8_t walking_snd_toggle, palookup, hard_landing, fist_incs;
int8_t numloogs, loogcnt, scream_voice;
int8_t last_weapon, cheat_phase, weapon_pos, wantweaponfire, curr_weapon;
uint8_t palette;
palette_t pals;
int8_t last_used_weapon;
int16_t recoil;
int32_t stairs;
int32_t detonate_count;
int16_t detonate_time;
uint8_t shotgun_state[2];
uint8_t donoise; // at28e
int32_t noise_x, noise_y, noise_radius; // at286, at28a, at290
uint8_t keys[5];
int16_t yehaa_timer;
int16_t drink_amt, eat, drunkang, eatang;
int32_t drink_timer, eat_timer;
int16_t MamaEnd;
int16_t MotoSpeed, TiltStatus, moto_drink;
uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround;
uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud;
int16_t VBumpNow, VBumpTarget, TurbCount;
int16_t drug_stat[3];
int32_t drug_aspect;
uint8_t DrugMode, lotag800kill, sea_sick_stat;
int32_t drug_timer;
int32_t sea_sick;
uint8_t hurt_delay2, nocheat;
int32_t dhat60f, dhat613, dhat617, dhat61b, dhat61f;
int8_t crouch_toggle;
int SlotWin;
int8_t padding_[3];
} DukePlayer_t; } DukePlayer_t;
// transition helpers
#define SeaSick sea_sick
#define raat609 MamaEnd
#define raat5dd sea_sick_stat
#define at57e detonate_count
#define at57c detonate_time
#define at58e drink_timer
#define at592 eat_timer
#define raat5f1 drug_stat[0]
#define raat5f3 drug_stat[1]
#define raat5f5 drug_stat[2]
// KEEPINSYNC lunatic/_defs_game.lua // KEEPINSYNC lunatic/_defs_game.lua
typedef struct typedef struct
@ -337,10 +307,7 @@ extern int32_t mouseyaxismode;
inline void SetPlayerPal(DukePlayer_t* pPlayer, PalEntry pe) inline void SetPlayerPal(DukePlayer_t* pPlayer, PalEntry pe)
{ {
pPlayer->pals.f = pe.a; pPlayer->pals = pe;
pPlayer->pals.r = pe.r;
pPlayer->pals.g = pe.g;
pPlayer->pals.b = pe.b;
} }
int hitawall(DukePlayer_t* pPlayer, int* hitWall); int hitawall(DukePlayer_t* pPlayer, int* hitWall);

View file

@ -388,7 +388,7 @@ void resetprestat(int snum,int g)
for(i=0;i<spriteqamount;i++) spriteq[i] = -1; for(i=0;i<spriteqamount;i++) spriteq[i] = -1;
p->hbomb_on = 0; p->hbomb_on = 0;
p->pals.f = 0; p->pals.a = 0;
p->toggle_key_flag = 0; p->toggle_key_flag = 0;
p->secret_rooms = 0; p->secret_rooms = 0;
p->max_secret_rooms = 0; p->max_secret_rooms = 0;

View file

@ -85,7 +85,7 @@ typedef struct {
* But note that for more than one tint, the composite tint will in general * But note that for more than one tint, the composite tint will in general
* change its hue as the ratio of the weights of the individual ones changes. * change its hue as the ratio of the weights of the individual ones changes.
*/ */
static void palaccum_add(palaccum_t *pa, const palette_t *pal, int32_t f) static void palaccum_add(palaccum_t *pa, const PalEntry *pal, int32_t f)
{ {
f = clamp(f, 0, 63); f = clamp(f, 0, 63);
if (f == 0) if (f == 0)
@ -153,10 +153,10 @@ void G_DisplayRest(int32_t smoothratio)
fstint.tintFlags = 0; fstint.tintFlags = 0;
} }
} }
palaccum_add(&tint, &pp->pals, pp->pals.f); palaccum_add(&tint, &pp->pals, pp->pals.a);
if (!isRR()) if (!isRR())
{ {
static const palette_t loogiepal = { 0, 63, 0, 0 }; static const PalEntry loogiepal(0, 63, 0, 0 );
palaccum_add(&tint, &loogiepal, pp->loogcnt>>1); palaccum_add(&tint, &loogiepal, pp->loogcnt>>1);
} }