Skip to content

Commit

Permalink
Remove all dependencies of PermMem (View, FF)
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Sep 16, 2018
1 parent f207213 commit 5983013
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
4 changes: 1 addition & 3 deletions _work/data/Scripts/Content/GFA/_intern/const.d
Expand Up @@ -33,9 +33,7 @@ const string GFA_VERSION = "Gothic Free Aim v1.0.1";
const int GFA_LEGO_FLAGS = LeGo_HookEngine // For initializing all hooks
| LeGo_ConsoleCommands // For console commands and debugging
| LeGo_Random // For scattering and other uses of random numbers
| LeGo_Draw3D // For debug visualizations (may be removed)
| LeGo_FrameFunctions // For hitmarker in config (may be removed)
| LeGo_View; // For hitmarker in config (may be removed)
| LeGo_Draw3D; // For debug visualizations (may be removed)

var int GFA_Flags; // Flags for initialization of GFA
const int GFA_RANGED = 1<<0; // Free aiming for ranged combat (bow and crossbow)
Expand Down
35 changes: 27 additions & 8 deletions _work/data/Scripts/Content/GFA/config/criticalHit.d
Expand Up @@ -9,6 +9,10 @@
*/


// Stores the pointer of the hit marker zCView
const int GFA_HITMARKER = 0;


/*
* This function is called every time (any kind of) NPC is hit by a projectile (arrows and bolts). Originally it was
* meant to design critical hits based on a specific bone of the model, but it can also be used to change the damage
Expand Down Expand Up @@ -143,20 +147,19 @@ func void GFA_GetCriticalHit(var C_Npc target, var string bone, var C_Item weapo
PrintS("Critical hit"); */

// Shooter-like hit marker
var int hitMarker;
if (!Hlp_IsValidHandle(hitMarker)) {
if (!GFA_HITMARKER) {
// Create it (if it does not exist) in the center of the screen
var zCView screen; screen = _^(MEM_Game._zCSession_viewport);
hitMarker = View_CreateCenterPxl(screen.psizex/2, screen.psizey/2, // Coordinates
GFA_RETICLE_MAX_SIZE, GFA_RETICLE_MAX_SIZE); // Dimensions
GFA_HITMARKER = ViewPtr_CreateCenterPxl(screen.psizex/2, screen.psizey/2, // Coordinates
GFA_RETICLE_MAX_SIZE, GFA_RETICLE_MAX_SIZE); // Dimensions

// Get 7th frame of animated texture as static texture
View_SetTexture(hitMarker, GFA_AnimateReticleByPercent(RETICLE_TRI_IN, 100, 7));
ViewPtr_SetTexture(GFA_HITMARKER, GFA_AnimateReticleByPercent(RETICLE_TRI_IN, 100, 7));
};
View_Open(hitMarker);
ViewPtr_Open(GFA_HITMARKER);

// Hide the hit marker after 300 ms
FF_ApplyExtData(View_Close, 300, 1, hitMarker);
// Hide the hit marker after 300 ms (formerly a timed framefunction, see below)
HookEngineF(oCGame__Render, 7, GFA_RemoveHitMarker);

// Sound notification
Snd_Play3D(target, "GFA_CRITICALHIT_SFX");
Expand All @@ -166,6 +169,22 @@ func void GFA_GetCriticalHit(var C_Npc target, var string bone, var C_Item weapo
};


/*
* A little helper function to avoid using handles (View and FrameFunction) for removing the hit marker. This way,
* neither the hit marker, nor the framefunction to remove it will be stored in the game save. Furthermore, the number
* of available handles will not be depleted by creating a new framefunction every time the hit marker is displayed.
*/
func void GFA_RemoveHitMarker() {
const int TIME = 0; TIME += MEM_Timer.frameTime;
// After 300 ms hide the hit marker
if (TIME >= 300) {
TIME = 0;
ViewPtr_Close(GFA_HITMARKER);
RemoveHookF(oCGame__Render, 0, GFA_RemoveHitMarker);
};
};


/*
* This function is analogous to GFA_GetCriticalHit() above, but is called when free aiming for ranged weapons is not
* active.
Expand Down

0 comments on commit 5983013

Please sign in to comment.