Mobility interface, flashlight button switch

This commit is contained in:
mittorn 2016-03-02 08:02:02 +00:00
parent f8f80b9a08
commit 9c3ffa636a
5 changed files with 122 additions and 12 deletions

View File

@ -29,16 +29,16 @@ extern "C"
#include <string.h>
#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;
}

View File

@ -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 <string.h>
#define _cdecl
#include <string.h>
extern cl_enginefunc_t gEngfuncs;
#include "../engine/mobility_int.h"
extern mobile_engfuncs_t *gMobileEngfuncs;

View File

@ -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;

View File

@ -27,6 +27,7 @@
#include "parsemsg.h"
#include <string.h>
#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;
}

82
engine/mobility_int.h Normal file
View File

@ -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