From 9c3ffa636a2e409296a4e0fb93994e96d46b49f1 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 2 Mar 2016 08:02:02 +0000 Subject: [PATCH] Mobility interface, flashlight button switch --- cl_dll/cdll_int.cpp | 20 +++++++---- cl_dll/cl_dll.h | 10 +++--- cl_dll/flashlight.cpp | 11 +++++- cl_dll/health.cpp | 11 ++++++ engine/mobility_int.h | 82 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 engine/mobility_int.h diff --git a/cl_dll/cdll_int.cpp b/cl_dll/cdll_int.cpp index d7b50957..1ad81773 100644 --- a/cl_dll/cdll_int.cpp +++ b/cl_dll/cdll_int.cpp @@ -29,16 +29,16 @@ extern "C" #include -#ifdef _WIN32 +#ifdef _WIN32 #define DLLEXPORT __declspec( dllexport ) -#else -#define DLLEXPORT -#endif +#else +#define DLLEXPORT +#endif cl_enginefunc_t gEngfuncs; CHud gHUD; - +mobile_engfuncs_t *gMobileEngfuncs = NULL; void InitInput (void); void EV_HookEvents( void ); void IN_Commands( void ); @@ -66,6 +66,7 @@ int DLLEXPORT HUD_GetHullBounds( int hullnumber, float *mins, float *maxs ); void DLLEXPORT HUD_Frame( double time ); void DLLEXPORT HUD_VoiceStatus(int entindex, qboolean bTalking); void DLLEXPORT HUD_DirectorMessage( int iSize, void *pbuf ); +void DLLEXPORT HUD_MobilityInterface( mobile_engfuncs_t *gpMobileEngfuncs ); } /* @@ -260,7 +261,7 @@ Called when a player starts or stops talking. void DLLEXPORT HUD_VoiceStatus(int entindex, qboolean bTalking) { - + } /* @@ -276,4 +277,9 @@ void DLLEXPORT HUD_DirectorMessage( int iSize, void *pbuf ) gHUD.m_Spectator.DirectorMessage( iSize, pbuf ); } - +void DLLEXPORT HUD_MobilityInterface( mobile_engfuncs_t *gpMobileEngfuncs ) +{ + if( gpMobileEngfuncs->version != MOBILITY_API_VERSION ) + return; + gMobileEngfuncs = gpMobileEngfuncs; +} diff --git a/cl_dll/cl_dll.h b/cl_dll/cl_dll.h index 99020179..aeacb8be 100644 --- a/cl_dll/cl_dll.h +++ b/cl_dll/cl_dll.h @@ -36,8 +36,10 @@ typedef int (*pfnUserMsgHook)(const char *pszName, int iSize, void *pbuf); #include "../engine/cdll_int.h" #include "../dlls/cdll_dll.h" - -#define _cdecl -#include - + +#define _cdecl +#include + extern cl_enginefunc_t gEngfuncs; +#include "../engine/mobility_int.h" +extern mobile_engfuncs_t *gMobileEngfuncs; diff --git a/cl_dll/flashlight.cpp b/cl_dll/flashlight.cpp index dab2421b..ab8f70a4 100644 --- a/cl_dll/flashlight.cpp +++ b/cl_dll/flashlight.cpp @@ -96,7 +96,16 @@ int CHudFlashlight:: MsgFunc_Flashlight(const char *pszName, int iSize, void *p int CHudFlashlight::Draw(float flTime) { - if ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) + static bool show = ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ); + if( show != !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) ) + { + show = !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ); + if( gMobileEngfuncs ) + { + gMobileEngfuncs->pfnTouchHideButtons( "flashlight", !show ); + } + } + if ( !show ) return 1; int r, g, b, x, y, a; diff --git a/cl_dll/health.cpp b/cl_dll/health.cpp index da664720..0b73efca 100644 --- a/cl_dll/health.cpp +++ b/cl_dll/health.cpp @@ -27,6 +27,7 @@ #include "parsemsg.h" #include +#include "mobility_int.h" DECLARE_MESSAGE(m_Health, Health ) DECLARE_MESSAGE(m_Health, Damage ) @@ -133,8 +134,18 @@ int CHudHealth:: MsgFunc_Damage(const char *pszName, int iSize, void *pbuf ) // Actually took damage? if ( damageTaken > 0 || armor > 0 ) + { CalcDamageDirection(vecFrom); + if( gMobileEngfuncs && damageTaken > 0 ) + { + float time = damageTaken * 4.0f; + + if( time > 200.0f ) time = 200.0f; + gMobileEngfuncs->pfnVibrate( time, 0 ); + } + } + return 1; } diff --git a/engine/mobility_int.h b/engine/mobility_int.h new file mode 100644 index 00000000..88f63315 --- /dev/null +++ b/engine/mobility_int.h @@ -0,0 +1,82 @@ +/* +mobility_int.h - interface between engine and client for mobile platforms +Copyright (C) 2015 a1batross + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +*/ + +#pragma once +#ifndef MOBILITY_INT_H +#define MOBILITY_INT_H +#ifdef __cplusplus +extern "C" { +#endif + +#define MOBILITY_API_VERSION 2 +#define MOBILITY_CLIENT_EXPORT "HUD_MobilityInterface" + +#define VIBRATE_NORMAL (1U << 0) // just vibrate for given "life" + +#define TOUCH_FL_HIDE (1U << 0) +#define TOUCH_FL_NOEDIT (1U << 1) +#define TOUCH_FL_CLIENT (1U << 2) +#define TOUCH_FL_MP (1U << 3) +#define TOUCH_FL_SP (1U << 4) +#define TOUCH_FL_DEF_SHOW (1U << 5) +#define TOUCH_FL_DEF_HIDE (1U << 6) +#define TOUCH_FL_DRAW_ADDITIVE (1U << 7) +#define TOUCH_FL_STROKE (1U << 8) +#define TOUCH_FL_PRECISION (1U << 9) + +typedef struct mobile_engfuncs_s +{ + // indicates version of API. Should be equal to MOBILITY_API_VERSION + // version changes when existing functions are changes + int version; + + // vibration control + // life -- time to vibrate in ms + void (*pfnVibrate)( float life, char flags ); + + // enable text input + void (*pfnEnableTextInput)( int enable ); + + // add temporaty button, edit will be disabled + void (*pfnTouchAddClientButton)( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, unsigned char *color, int round, float aspect, int flags ); + + // add button to defaults list. Will be loaded on config generation + void (*pfnTouchAddDefaultButton)( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, unsigned char *color, int round, float aspect, int flags ); + + // hide/show buttons by pattern + void (*pfnTouchHideButtons)( const char *name, unsigned char hide ); + + // remove button with given name + void (*pfnTouchRemoveButton)( const char *name ); + + // when enabled, only client buttons shown + void (*pfnTouchSetClientOnly)( unsigned char state ); + + // Clean defaults list + void (*pfnTouchResetDefaultButtons)(); + + // To be continued... +} mobile_engfuncs_t; + +extern mobile_engfuncs_t *gMobileEngfuncs; + +// function exported from client +// returns 0 on no error otherwise error +typedef int (*pfnMobilityInterface)( mobile_engfuncs_t *gMobileEngfuncs ); + +#ifdef __cplusplus +} +#endif +#endif