Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Angled" sprites from FTEQW #73

Closed
wants to merge 1 commit into from
Closed

"Angled" sprites from FTEQW #73

wants to merge 1 commit into from

Conversation

erysdren
Copy link
Contributor

@erysdren erysdren commented Aug 9, 2023

I found out that FTEQW supports "angled" sprites, i.e. ones that change frame based on player viewing angle. The code is rather simple.

I ported it to QuakeSpasm in a few minutes.

To author an angled sprite, one must construct a regular sprite with a traditional "Group Frame" (with 8 frames in the group), and mark the type integer as "2" rather than "1".

This can be done using my sprconv tool:

https://github.com/erysdren/sprconv

@erysdren erysdren changed the title Port code from FTE "Angled" sprites from FTEQW Aug 9, 2023
@sezero
Copy link
Owner

sezero commented Aug 9, 2023

Any maps that uses this kind of sprites ?

@erysdren
Copy link
Contributor Author

erysdren commented Aug 9, 2023

Not that I know of, but I've authored a few example sprites to show how they work. I thought it might be useful to modders, especially since the footprint in the codebase is so small.

Since an "angled" frame group has the same format as a regular "group" frame, it is represented as 1 frame in QuakeC. so you can animate a sprite walking, for example, and the engine (with these changes) will automatically switch to the correct frame based on the player's viewing perspective to the sprite.

@sezero
Copy link
Owner

sezero commented Aug 9, 2023

@ericwa: What do you think about this one? I'm not sure myself..

@4LT
Copy link

4LT commented Aug 14, 2023

Shouldn't Mod_LoadSpriteModel need to be updated to ensure there are 8 frames in the framegroup?

@ericwa
Copy link
Contributor

ericwa commented Aug 14, 2023

I'm fine with this as it looks handy for porting e.g. doom-style sprites, small code, and already supported in FTE.

Documenting that it's 8 frames per group would be good + checking in the loading code, to avoid crashes.

Maybe a demo .spr file would be useful to attach here for testing.

@sezero
Copy link
Owner

sezero commented Aug 14, 2023

I'm fine with this as it looks handy for porting e.g. doom-style sprites, small code, and already supported in FTE.

OK then. A few notes:

  • Please revise the commit message to something like: Backport angled sprites code from FTEQW
  • Please revise the author attribution (see below)
  • Please make it build in C89 mode (see below)
  • Please verify that angled sprite has 8 frames in spritegroup, as noted by others (see below)

See the following patch (on top of yours) that does most of the above -- the framenum validation hopefully being correct (please check!).

diff --git a/Quake/r_sprite.c b/Quake/r_sprite.c
index 9893a64..19c8425 100644
--- a/Quake/r_sprite.c
+++ b/Quake/r_sprite.c
@@ -51,15 +51,17 @@ mspriteframe_t *R_GetSpriteFrame (entity_t *currentent)
 	}
 	else if (psprite->frames[frame].type == SPR_ANGLED)
 	{
-		// erysdren - angled sprites
+		// erysdren - angled sprites backported from FTEQW
 		vec3_t axis[3];
 		AngleVectors(currententity->angles, axis[0], axis[1], axis[2]);
+		{
 		float f = DotProduct(vpn, axis[0]);
 		float r = DotProduct(vright, axis[0]);
 		int dir = (atan2(r, f)+1.125*M_PI)*(4/M_PI);
 
 		pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
 		pspriteframe = pspritegroup->frames[dir&7];
+		}
 	}
 	else
 	{
diff --git a/Quake/gl_model.c b/Quake/gl_model.c
index 6fc3c18..1e97626 100644
--- a/Quake/gl_model.c
+++ b/Quake/gl_model.c
@@ -2956,7 +2956,7 @@ static void *Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int fram
 Mod_LoadSpriteGroup
 =================
 */
-static void *Mod_LoadSpriteGroup (void * pin, mspriteframe_t **ppframe, int framenum)
+static void *Mod_LoadSpriteGroup (void * pin, mspriteframe_t **ppframe, int framenum, spriteframetype_t type)
 {
 	dspritegroup_t		*pingroup;
 	mspritegroup_t		*pspritegroup;
@@ -2968,6 +2968,8 @@ static void *Mod_LoadSpriteGroup (void * pin, mspriteframe_t **ppframe, int fram
 	pingroup = (dspritegroup_t *)pin;
 
 	numframes = LittleLong (pingroup->numframes);
+	if (type == SPR_ANGLED && numframes != 8)
+		Sys_Error ("Mod_LoadSpriteGroup: Bad # of frames: %d", numframes);
 
 	pspritegroup = (mspritegroup_t *) Hunk_AllocName (sizeof (mspritegroup_t) +
 				(numframes - 1) * sizeof (pspritegroup->frames[0]), loadname);
@@ -3071,7 +3073,7 @@ static void Mod_LoadSpriteModel (qmodel_t *mod, void *buffer)
 		else
 		{
 			pframetype = (dspriteframetype_t *)
-					Mod_LoadSpriteGroup (pframetype + 1, &psprite->frames[i].frameptr, i);
+					Mod_LoadSpriteGroup (pframetype + 1, &psprite->frames[i].frameptr, i, frametype);
 		}
 	}
 

Documenting that it's 8 frames per group would be good

Where to put that info ?

Maybe a demo .spr file would be useful to attach here for testing.

Yes, I think

@sezero
Copy link
Owner

sezero commented Aug 20, 2023

Looks like the author lost interest. I tend to reject-close this if I won't get any response in about 3 days.

@sezero
Copy link
Owner

sezero commented Aug 21, 2023

Looks like the author lost interest. I tend to reject-close this if I won't get any response in about 3 days.

@ericwa: Any objections?

@erysdren
Copy link
Contributor Author

Sorry, haven't had time to work on it lately. I'll see if i can get to it today.

@erysdren
Copy link
Contributor Author

i added your changes, sorry for the delay.

@sezero
Copy link
Owner

sezero commented Aug 27, 2023

i added your changes, sorry for the delay.

Thanks. Can you give us a sample sprite, possibly a map along with it, as @ericwa requested?

@erysdren
Copy link
Contributor Author

Here's a map with a sample sprite (it overwrites s_light.spr)

https://erysdren.me/files/angled_sprite_example.zip

@sezero
Copy link
Owner

sezero commented Aug 27, 2023

Here's a map with a sample sprite (it overwrites s_light.spr)

https://erysdren.me/files/angled_sprite_example.zip

OK, thanks!

Will be merging the patch tomorrow.

@sezero
Copy link
Owner

sezero commented Aug 28, 2023

This patch is in now. Thank you.

@sezero sezero closed this Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants