Skip to content

Conversation

ifeldshteyn
Copy link
Contributor

Allow FS to load the current difficulty

InfElevator* data = (InfElevator*)allocator_getByIndex(s_infSerState.infElevators, elev->m_id);
return data->type == IELEV_ROTATE_WALL ? floor16(angleToFloat(data->speed)) : floor16(data->speed);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this Karjala.
I have realised a (reasonably minor) flaw in my Elevator speed setter. Namely, in INF, it is possible to set an elevator to a floating point speed (like 6.5) whereas I have forced it to be integer (s32).

@luciusDXL and @ifeldshteyn Do you think we should correct this, and allow getting/setting of speed as a float via scripting? If so, would you be able to please make that amendment with this PR?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should return a float - both angles and speed are fixed point.

Copy link
Contributor

@jerethk jerethk Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ifeldshteyn @luciusDXL
Ok I'm pretty much responsible for creating this issue (used int instead of float when I made the setter), so here is the fix

2320077

Karjala, please go ahead and cherry pick it.

Copy link
Owner

@luciusDXL luciusDXL Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I think there is still a problem.
In the infUpdate_rotateWall() function, you can see the speed is a fixed-point angle that gets rounded in the function. This code still truncates it before returning, losing the fractional part of the angle delta, which will break if used in cases like the tram in Harkov.

So you should treat it as a fixed-point value, convert to float and then convert to degrees.

Copy link
Contributor

@jerethk jerethk Apr 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, I think you will need to explain in more detail please.

Let's say we want to set a speed of 20.5 degrees / sec
the formula currently there is intToFixed16(floatToAngle(20.5))

floatToAngle(20.5) = 20.5 * 45.51 = 932
intToFixed(932) = 932 << 16 = 61079552

That seems correct, doesn't it? It looks the same as what is done when INF is parsed.

Then back the other way, formula is
angleToFloat(61079552 >> FRAC_BITS_16)

61079552 >> FRAC_BITS_16 = 932
angleToFloat(932) = 932 / 45.51 = 20.479

A small amount of precision has been lost but that's acceptable, isn't it?

ScriptPropertyGetFunc("bool get_master()", getElevMaster);


ScriptPropertyGetFunc("int get_speed()", getElevSpeed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you decide to make the change, then this would become
float get_speed()
and
void set_speed(float)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, non-integer speeds are used in mods and even vanilla levels. So it would make sense to make it float instead of int.

Copy link
Contributor

@jerethk jerethk Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was me with my brain not being fully engaged when I made the original addition :-)
If you can be bothered Karjala, you can make the amendment, otherwise I'll raise a change (for both the get and set) after this is merged.

<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, I wonder if Lucius will approve this. I have it as v143 too, it would save me the hassle of continually stashing and unstashing this file whenever I merge/rebase etc.
I assumed he must have some reason to want to keep it at v141....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRUD - accidental commit =)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is meant to be here? Mistake?

<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these recipe files are supposed to be committed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recipe file is still here

@luciusDXL
Copy link
Owner

Currently VS2017 is used to preserve support for Win7 and 8 (theoretically at least).

@Gerwin2k
Copy link

Gerwin2k commented Apr 8, 2025

Currently VS2017 is used to preserve support for Win7 and 8 (theoretically at least).

The ForceEngine Github builds work in Windows 7 x64 so far, practically that is.


InfElevator* data = (InfElevator*)allocator_getByIndex(s_infSerState.infElevators, elev->m_id);
data->speed = data->type == IELEV_ROTATE_WALL ? FIXED(floatToAngle(value)) : FIXED(value);
data->speed = data->type == IELEV_ROTATE_WALL ? intToFixed16(floatToAngle(value)) : floatToFixed16(value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here, you are losing the fractional part of the angular speed. angle degrees to DF angles -> float to fixed I think is the order here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think see what you are saying. But line 2157 of infSystem.cpp uses intToFixed and therefore loses the precision as well. That is from vanilla, isn't it? Isn't it reasonable to just copy what vanilla does when it parses INF?

Copy link
Contributor

@jerethk jerethk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked at this again. A couple issues, I think

if (!ScriptElev::isScriptElevValid(elev)) { return 0; }

InfElevator* data = (InfElevator*)allocator_getByIndex(s_infSerState.infElevators, elev->m_id);
return data->type == IELEV_ROTATE_WALL ? degreesToFixedAngle(data->speed) : fixed16ToFloat(data->speed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at this again -- I think you've got these round the wrong way.
This is the getter, so it should call fixedAngleToDegrees

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Karjala22 I've built this and tested it and yes, you need to swap these functions around

Here it should be fixedAngleToDegrees
And in the setter below it should be degreesToFixedAngle


InfElevator* data = (InfElevator*)allocator_getByIndex(s_infSerState.infElevators, elev->m_id);
data->speed = data->type == IELEV_ROTATE_WALL ? FIXED(floatToAngle(value)) : FIXED(value);
data->speed = data->type == IELEV_ROTATE_WALL ? fixedAngleToDegrees(value) : floatToFixed16(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the setter, so I think it should call degreesToFixedAngle

<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recipe file is still here

if (!ScriptElev::isScriptElevValid(elev)) { return 0; }

InfElevator* data = (InfElevator*)allocator_getByIndex(s_infSerState.infElevators, elev->m_id);
return data->type == IELEV_ROTATE_WALL ? degreesToFixedAngle(data->speed) : fixed16ToFloat(data->speed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Karjala22 I've built this and tested it and yes, you need to swap these functions around

Here it should be fixedAngleToDegrees
And in the setter below it should be degreesToFixedAngle

Copy link
Contributor

@jerethk jerethk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all good to me now. Thanks Karjala

@luciusDXL luciusDXL merged commit 62891e7 into luciusDXL:master Sep 9, 2025
2 checks passed
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.

5 participants