Skip to content

Commit

Permalink
support setup max game console height
Browse files Browse the repository at this point in the history
  • Loading branch information
glKarin committed Dec 23, 2024
1 parent dd30ec4 commit f3bd868
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.changelog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ctrl
console height
2 changes: 2 additions & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EGameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ public boolean Start(Surface surface, int surfaceWidth, int surfaceHeight)
int glVersion = preferences.getInt(Q3EPreference.pref_harm_opengl, 0x00020000);
boolean usingMouse = preferences.getBoolean(Q3EPreference.pref_harm_using_mouse, false) && Q3EUtils.SupportMouse() == Q3EGlobals.MOUSE_EVENT;
boolean useExternalLibPath = preferences.getBoolean(Q3EPreference.USE_EXTERNAL_LIB_PATH, false);
int consoleMaxHeightFrac = preferences.getInt(Q3EPreference.pref_harm_max_console_height_frac, 0);

String subdatadir = Q3EUtils.q3ei.subdatadir;
// if(Q3EUtils.q3ei.isTDM) subdatadir = "dnf"; // Test a new game using TDM
Expand Down Expand Up @@ -884,6 +885,7 @@ public boolean Start(Surface surface, int surfaceWidth, int surfaceHeight)
refreshRate,
appHome,
Q3EUtils.q3ei.joystick_smooth,
consoleMaxHeightFrac,
runBackground > 0
);
if(res)
Expand Down
1 change: 1 addition & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static native boolean init(
int refreshRate, // refresh rate,
String appHome, // app home path
boolean smoothJoystick, // is smooth joystick
int consoleMaxHeightFrac, // max console height frac(0 - 100)
boolean continueNoGLContext
);
public static native void sendKeyEvent(int state,int key,int character);
Expand Down
1 change: 1 addition & 0 deletions Q3E/src/main/java/com/n0n3m4/q3e/Q3EPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public final class Q3EPreference
public static final String pref_harm_r_shadowMapPerforatedShadow = "q3e_harm_r_shadowMapPerforatedShadow"; //k
public static final String pref_harm_gzdoom_load_lights_pk3 = "harm_gzdoom_load_lights_pk3";
public static final String pref_harm_gzdoom_load_brightmaps_pk3 = "harm_gzdoom_load_brightmaps_pk3";
public static final String pref_harm_max_console_height_frac = "q3e_harm_max_console_height_frac"; //k

public static final String RUN_BACKGROUND = "harm_run_background";
public static final String RENDER_MEM_STATUS = "harm_render_mem_status";
Expand Down
1 change: 1 addition & 0 deletions Q3E/src/main/jni/common/q3e/q3e_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct
const char *appHomeDir; // application home directory
int refreshRate; // screen refresh rate
int smoothJoystick; // smooth joystick
int consoleMaxHeightFrac; // max console height frac(0 - 100)

ANativeWindow *window;
int width;
Expand Down
17 changes: 17 additions & 0 deletions Q3E/src/main/jni/common/q3e/q3e_android.inc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int screen_height = 480;
// Screen refresh rate
int refresh_rate = 60;

// max console height frac
float console_max_height_frac = -1.0f;

// Smooth joystick
Q3Ebool smooth_joystick = Q3E_FALSE;

Expand Down Expand Up @@ -553,6 +556,19 @@ void Android_ExitFinish(void)
exit_finish();
}

float Android_GetConsoleMaxHeightFrac(float frac)
{
return console_max_height_frac > 0.0f && console_max_height_frac < frac ? console_max_height_frac : frac;
}

int Android_GetConsoleMaxHeight(int height, int maxHeight)
{
if(console_max_height_frac <= 0.0f)
return height;
int h = console_max_height_frac * (float)maxHeight;
return h < height ? h : height;
}

const char * Sys_DLLDefaultPath(void)
{
return native_library_dir ? native_library_dir : _ANDROID_DLL_PATH;
Expand Down Expand Up @@ -661,6 +677,7 @@ void Q3E_SetInitialContext(const void *context)
mouse_available = ptr->mouseAvailable ? Q3E_TRUE : Q3E_FALSE;
refresh_rate = ptr->refreshRate <= 0 ? 60 : ptr->refreshRate;
smooth_joystick = ptr->smoothJoystick ? Q3E_TRUE : Q3E_FALSE;
console_max_height_frac = ptr->consoleMaxHeightFrac > 0 && ptr->consoleMaxHeightFrac < 100 ? (float)ptr->consoleMaxHeightFrac / 100.0f : -1.0f;

window = ptr->window;
screen_width = ptr->width;
Expand Down
2 changes: 1 addition & 1 deletion Q3E/src/main/jni/common/q3e/q3e_glimp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static void Q3E_HandleEGLError(const char *func, Q3Ebool exit)
"EGL_BAD_SURFACE",
"EGL_CONTEXT_LOST",
};
GLint err = eglGetError();
EGLint err = eglGetError();
if(err == EGL_SUCCESS)
return;

Expand Down
12 changes: 12 additions & 0 deletions Q3E/src/main/jni/doom3/neo/framework/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void SCR_DrawTextRightAlign(float &y, const char *text, ...) id_attribute((forma

#define COMMAND_HISTORY 64

#ifdef __ANDROID__ //karin: limit console max height
extern float Android_GetConsoleMaxHeightFrac(float frac);
#endif

// the console will query the cvar and command systems for
// command completion information

Expand Down Expand Up @@ -859,9 +863,17 @@ bool idConsoleLocal::ProcessEvent(const sysEvent_t *event, bool forceAccept)

if (idKeyInput::IsDown(K_SHIFT)) {
// if the shift key is down, don't open the console as much
#ifdef __ANDROID__ //karin: limit console max height
SetDisplayFraction(Android_GetConsoleMaxHeightFrac(0.2f));
#else
SetDisplayFraction(0.2f);
#endif
} else {
#ifdef __ANDROID__ //karin: limit console max height
SetDisplayFraction(Android_GetConsoleMaxHeightFrac(0.5f));
#else
SetDisplayFraction(0.5f);
#endif
}

cvarSystem->SetCVarBool("ui_chat", true);
Expand Down
2 changes: 1 addition & 1 deletion Q3E/src/main/jni/doom3/neo/sys/android/glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static void GLimp_HandleError(const char *func, bool exit = true)
"EGL_BAD_SURFACE",
"EGL_CONTEXT_LOST",
};
GLint err = eglGetError();
EGLint err = eglGetError();
if(err == EGL_SUCCESS)
return;

Expand Down
10 changes: 10 additions & 0 deletions Q3E/src/main/jni/doom3/neo/sys/android/sys_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ int refresh_rate = 60;
// Smooth joystick
bool smooth_joystick = false;

// max console height frac
float console_max_height_frac = -1.0f;

// Using mouse
bool mouse_available = false;

Expand Down Expand Up @@ -401,6 +404,11 @@ void Android_ExitFinish(void)
exit_finish();
}

float Android_GetConsoleMaxHeightFrac(float frac)
{
return console_max_height_frac > 0.0f && console_max_height_frac < frac ? console_max_height_frac : frac;
}

const char * Sys_DLLDefaultPath(void)
{
return native_library_dir ? native_library_dir : _ANDROID_DLL_PATH;
Expand Down Expand Up @@ -570,6 +578,8 @@ void Q3E_SetInitialContext(const void *context)
mouse_available = ptr->mouseAvailable ? true : false;
refresh_rate = ptr->refreshRate <= 0 ? 60 : ptr->refreshRate;
smooth_joystick = ptr->smoothJoystick ? true : false;
if(ptr->consoleMaxHeightFrac > 0 && ptr->consoleMaxHeightFrac < 100)
console_max_height_frac = ptr->consoleMaxHeightFrac > 0 && ptr->consoleMaxHeightFrac < 100 ? (float)ptr->consoleMaxHeightFrac / 100.0f : -1.0f;

window = ptr->window;
screen_width = ptr->width;
Expand Down
1 change: 1 addition & 0 deletions Q3E/src/main/jni/doom3/neo/sys/android/sys_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef struct
const char *appHomeDir; // application home directory
int refreshRate; // screen refresh rate
int smoothJoystick; // smooth joystick
int consoleMaxHeightFrac; // max console height frac(0 - 100)

ANativeWindow *window;
int width;
Expand Down
16 changes: 16 additions & 0 deletions Q3E/src/main/jni/doom3bfg/neo/framework/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ If you have questions concerning this license or the applicable additional terms

#define COMMAND_HISTORY 64

#ifdef __ANDROID__ //karin: limit console max height
extern float Android_GetConsoleMaxHeightFrac(float frac);
#endif

struct overlayText_t
{
idStr text;
Expand Down Expand Up @@ -620,7 +624,11 @@ void idConsoleLocal::Open()
consoleField.ClearAutoComplete();
consoleField.Clear();
keyCatching = true;
#ifdef __ANDROID__ //karin: limit console max height
SetDisplayFraction(Android_GetConsoleMaxHeightFrac(0.5f));
#else
SetDisplayFraction( 0.5f );
#endif
}

/*
Expand Down Expand Up @@ -1043,11 +1051,19 @@ bool idConsoleLocal::ProcessEvent( const sysEvent_t* event, bool forceAccept )
if( idKeyInput::IsDown( K_LSHIFT ) || idKeyInput::IsDown( K_RSHIFT ) )
{
// if the shift key is down, don't open the console as much
#ifdef __ANDROID__ //karin: limit console max height
SetDisplayFraction(Android_GetConsoleMaxHeightFrac(0.2f));
#else
SetDisplayFraction( 0.2f );
#endif
}
else
{
#ifdef __ANDROID__ //karin: limit console max height
SetDisplayFraction(Android_GetConsoleMaxHeightFrac(0.5f));
#else
SetDisplayFraction( 0.5f );
#endif
}
}
return true;
Expand Down
22 changes: 19 additions & 3 deletions Q3E/src/main/jni/etw/src/client/cl_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#define CONSOLE_COLOR COLOR_WHITE
#define DEFAULT_CONSOLE_WIDTH 158

#ifdef __ANDROID__ //karin: limit console max height
extern float Android_GetConsoleMaxHeightFrac(float frac);
#endif

int smallCharWidth = SMALLCHAR_WIDTH;
int smallCharHeight = SMALLCHAR_HEIGHT;

Expand Down Expand Up @@ -102,7 +106,11 @@ void Con_ToggleConsole_f(void)
// short console
if (ctrl && con.desiredFrac != shortConsole)
{
#ifdef __ANDROID__ //karin: limit console max height
con.desiredFrac = Android_GetConsoleMaxHeightFrac(shortConsole);
#else
con.desiredFrac = shortConsole;
#endif
}
// full console
else if (alt && con.desiredFrac != fullConsole)
Expand All @@ -122,7 +130,11 @@ void Con_ToggleConsole_f(void)
// short console
if (ctrl)
{
con.desiredFrac = shortConsole;
#ifdef __ANDROID__ //karin: limit console max height
con.desiredFrac = Android_GetConsoleMaxHeightFrac(shortConsole);
#else
con.desiredFrac = shortConsole;
#endif
}
// full console
else if (alt)
Expand All @@ -132,7 +144,11 @@ void Con_ToggleConsole_f(void)
// normal half-screen console
else
{
con.desiredFrac = normalConsole;
#ifdef __ANDROID__ //karin: limit console max height
con.desiredFrac = Android_GetConsoleMaxHeightFrac(normalConsole);
#else
con.desiredFrac = normalConsole;
#endif
}
}
}
Expand Down Expand Up @@ -1133,7 +1149,7 @@ void Con_RunConsole(void)
// short console support via shift+~
if (cls.keyCatchers & KEYCATCH_CONSOLE)
{
con.finalFrac = con.desiredFrac;
con.finalFrac = con.desiredFrac;
}
else
{
Expand Down
26 changes: 24 additions & 2 deletions Q3E/src/main/jni/gzdoom/src/common/console/c_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
#define RIGHTMARGIN 8
#define BOTTOMARGIN 12

#ifdef __ANDROID__ //karin: limit console max height
extern int Android_GetConsoleMaxHeight(int height, int maxHeight);
#endif

extern bool AppActive;

CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
Expand Down Expand Up @@ -507,8 +511,17 @@ void C_AdjustBottom ()
{
if (gamestate == GS_FULLCONSOLE || gamestate == GS_STARTUP)
ConBottom = twod->GetHeight();
#ifdef __ANDROID__ //karin: limit console max height
else
{
int conMaxHeight = Android_GetConsoleMaxHeight(twod->GetHeight() / 2, twod->GetHeight());
if (ConBottom > conMaxHeight || ConsoleState == c_down)
ConBottom = conMaxHeight;
}
#else
else if (ConBottom > twod->GetHeight() / 2 || ConsoleState == c_down)
ConBottom = twod->GetHeight() / 2;
#endif
}

void C_NewModeAdjust ()
Expand Down Expand Up @@ -537,11 +550,20 @@ void C_Ticker()
if (ConsoleState == c_falling)
{
ConBottom += (consoletic - lasttic) * (twod->GetHeight() * 2 / 25);
if (ConBottom >= twod->GetHeight() / 2)
#ifdef __ANDROID__ //karin: limit console max height
int conMaxHeight = Android_GetConsoleMaxHeight(twod->GetHeight() / 2, twod->GetHeight());
if (ConBottom >= conMaxHeight)
{
ConBottom = twod->GetHeight() / 2;
ConBottom = conMaxHeight;
ConsoleState = c_down;
}
#else
if (ConBottom >= twod->GetHeight() / 2)
{
ConBottom = twod->GetHeight() / 2;
ConsoleState = c_down;
}
#endif
}
else if (ConsoleState == c_rising)
{
Expand Down
3 changes: 2 additions & 1 deletion Q3E/src/main/jni/q3e/q3e.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ static void setup_Q3E_callback(void)
setCallbacks(&callback);
}

JNIEXPORT jboolean JNICALL Java_com_n0n3m4_q3e_Q3EJNI_init(JNIEnv *env, jclass c, jstring LibPath, jstring nativeLibPath, jint width, jint height, jstring GameDir, jstring gameSubDir, jstring Cmdline, jobject view, jint format, jint msaa, jint glVersion, jboolean redirectOutputToFile, jint signalsHandler, jboolean bMultithread, jboolean mouseAvailable, jint refreshRate, jstring appHome, jboolean smoothJoystick, jboolean bContinueNoGLContext)
JNIEXPORT jboolean JNICALL Java_com_n0n3m4_q3e_Q3EJNI_init(JNIEnv *env, jclass c, jstring LibPath, jstring nativeLibPath, jint width, jint height, jstring GameDir, jstring gameSubDir, jstring Cmdline, jobject view, jint format, jint msaa, jint glVersion, jboolean redirectOutputToFile, jint signalsHandler, jboolean bMultithread, jboolean mouseAvailable, jint refreshRate, jstring appHome, jboolean smoothJoystick, jint consoleMaxHeightFrac, jboolean bContinueNoGLContext)
{
char **argv;
int argc;
Expand Down Expand Up @@ -532,6 +532,7 @@ JNIEXPORT jboolean JNICALL Java_com_n0n3m4_q3e_Q3EJNI_init(JNIEnv *env, jclass c
context.gameDataDir = game_data_dir;
context.refreshRate = refreshRate;
context.smoothJoystick = smoothJoystick ? 1 : 0;
context.consoleMaxHeightFrac = consoleMaxHeightFrac;

window = ANativeWindow_fromSurface(env, view);
// set_gl_context(window);
Expand Down
2 changes: 1 addition & 1 deletion Q3E/src/main/jni/q3e/q3e.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Q3E/src/main/jni/q3e/q3emisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void Q3E_PrintInitialContext(const Q3E_InitialContext_t *context)
LOGI(" Application home directory: %s", context->appHomeDir);
LOGI(" Refresh rate: %d", context->refreshRate);
LOGI(" Smooth joystick: %d", context->smoothJoystick);
LOGI(" Max console height frac: %d", context->consoleMaxHeightFrac);
LOGI(" Continue when missing OpenGL context: %d", context->continueWhenNoGLContext);

LOGI("<---------");
Expand Down
8 changes: 8 additions & 0 deletions Q3E/src/main/jni/quake1/cl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// we have to include snd_main.h here only to get access to snd_renderbuffer->format.speed when writing the AVI headers
#include "snd_main.h"

#ifdef __ANDROID__ //karin: limit console max height
extern int Android_GetConsoleMaxHeight(int height, int maxHeight);
#endif

cvar_t scr_viewsize = {CF_CLIENT | CF_ARCHIVE, "viewsize","100", "how large the view should be, 110 disables inventory bar, 120 disables status bar"};
cvar_t scr_fov = {CF_CLIENT | CF_ARCHIVE, "fov","90", "field of vision, 1-170 degrees, default 90, some players use 110-130"};
cvar_t scr_conalpha = {CF_CLIENT | CF_ARCHIVE, "scr_conalpha", "1", "opacity of console background gfx/conback"};
Expand Down Expand Up @@ -747,7 +751,11 @@ void SCR_DrawConsole (void)
Con_DrawConsole (vid_conheight.integer - scr_con_margin_bottom);
}
else if (scr_con_current)
#ifdef __ANDROID__ //karin: limit console max height
Con_DrawConsole (Android_GetConsoleMaxHeight(min(scr_con_current, vid_conheight.integer - scr_con_margin_bottom), vid_conheight.integer - scr_con_margin_bottom));
#else
Con_DrawConsole (min(scr_con_current, vid_conheight.integer - scr_con_margin_bottom));
#endif
else
con_vislines = 0;
}
Expand Down
Loading

0 comments on commit f3bd868

Please sign in to comment.