Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- AFADoomer's initial minimap submission.

git-svn-id: http://mancubus.net/svn/hosted/zdoom/zdoom/branches/minimap@3642 a95907f1-e10c-0410-b46f-9e587ccb1026
  • Loading branch information...
commit 0236c78e8be926ee6ff3d7c247fab3b04cd2d826 1 parent ce5a6a9
graf authored
Showing with 244 additions and 9 deletions.
  1. +230 −9 src/am_map.cpp
  2. +2 −0  src/am_map.h
  3. +12 −0 src/p_acs.cpp
View
239 src/am_map.cpp
@@ -337,8 +337,6 @@ static mline_t square_guy[] = {
#undef R
-
-
EXTERN_CVAR (Bool, sv_cheats)
CUSTOM_CVAR (Int, am_cheat, 0, 0)
{
@@ -352,16 +350,29 @@ CUSTOM_CVAR (Int, am_cheat, 0, 0)
static int grid = 0;
bool automapactive = false;
+bool minimapactive = false;
+bool stickyminimap = false;
// location of window on screen
static int f_x;
static int f_y;
+static int f_x_mini;
+static int f_y_mini;
// size of window on screen
static int f_w;
static int f_h;
+static int f_w_mini;
+static int f_h_mini;
static int f_p; // [RH] # of bytes from start of a line to start of next
+static float f_x_mini_input;
+static float f_y_mini_input;
+static float f_w_mini_input;
+static float f_h_mini_input;
+static float hudwidth_mini_input;
+static float hudheight_mini_input;
+
static int amclock;
static mpoint_t m_paninc; // how far the window pans each tic (map coords)
@@ -1079,6 +1090,7 @@ void AM_LevelInit ()
void AM_Stop ()
{
automapactive = false;
+ minimapactive = false;
stopped = true;
BorderNeedRefresh = screen->GetPageCount ();
viewactive = true;
@@ -1148,7 +1160,7 @@ void AM_NewResolution()
f_h = ST_Y;
AM_activateNewScale();
}
-
+\
//=============================================================================
//
@@ -1161,6 +1173,17 @@ CCMD (togglemap)
gameaction = ga_togglemap;
}
+CCMD (enableminimap)
+{
+ if (argv.argc() >= 4)
+ {
+ AM_PositionMap ((float)atof(argv[1]), (float)atof(argv[2]), (float)atof(argv[3]), (float)atof(argv[4]), 320.0, 200.0, 0);
+ minimapactive = true;
+ }
+ else
+ Printf ("enableminimap [x origin] [y origin] [width] [height] : toggle the custom mini-map on and off\n");
+}
+
//=============================================================================
//
//
@@ -1180,12 +1203,30 @@ void AM_ToggleMap ()
if (!automapactive)
{
AM_Start ();
- viewactive = (am_overlay != 0.f);
+ viewactive = (am_overlay != 0.f) || minimapactive || stickyminimap;
}
else
{
- if (am_overlay==1 && viewactive)
+ if (am_overlay==1 && viewactive && !minimapactive)
+ {
+ viewactive = false;
+ SB_state = screen->GetPageCount ();
+ }
+ else if (am_overlay==1 && !viewactive && f_w_mini && f_h_mini)
+ {
+ viewactive = true;
+ minimapactive = true;
+ SB_state = screen->GetPageCount ();
+ }
+ else if (!minimapactive && f_w_mini && f_h_mini && !viewactive)
+ {
+ viewactive = true;
+ minimapactive = true;
+ SB_state = screen->GetPageCount ();
+ }
+ else if (stickyminimap)
{
+ minimapactive = false;
viewactive = false;
SB_state = screen->GetPageCount ();
}
@@ -1196,6 +1237,174 @@ void AM_ToggleMap ()
}
}
+void AM_RefreshMiniMap()
+{
+ AM_PositionMap (f_x_mini_input, f_y_mini_input, f_w_mini_input, f_h_mini_input, hudwidth_mini_input, hudheight_mini_input, stickyminimap);
+}
+
+void AM_PositionMap (float x, float y, float Width, float Height, float hudwidth, float hudheight, int sticky)
+{
+ int bottom = ST_Y;
+ float HUDWidth, HUDHeight;
+ float Left, Top;
+ float drawx, drawy;
+ bool CenterX;
+
+ int screen_width = screen->GetWidth ();
+ int screen_height = ST_Y;
+
+ f_x_mini_input = x;
+ f_y_mini_input = y;
+ f_w_mini_input = Width;
+ f_h_mini_input = Height;
+ hudwidth_mini_input = hudwidth;
+ hudheight_mini_input = hudheight;
+
+ if (hudwidth == 0 || hudheight == 0)
+ {
+ // for y range [-1.0, 0.0]: Positions top edge of box
+ // for y range [0.0, 1.0]: Positions center of box
+ // for x range [-1.0, 0.0]: Positions left edge of box
+ // for x range [0.0, 1.0]: Positions center of box
+ HUDWidth = HUDHeight = 0;
+ if (fabs (x) > 2.f)
+ {
+ CenterX = true;
+ Left = 0.5f;
+ }
+ else
+ {
+ Left = x < -1.f ? x + 1.f : x > 1.f ? x - 1.f : x;
+ if (fabs(x) > 1.f)
+ {
+ CenterX = true;
+ }
+ else
+ {
+ CenterX = false;
+ }
+ }
+ }
+ else
+ { // HUD size is specified, so coordinates are in pixels, but you can add
+ // some fractions to affect positioning:
+ // For y: .1 = positions top edge of box
+ // .2 = positions bottom edge of box
+ // For x: .1 = positions left edge of box
+ // .2 = positions right edge of box
+ Top = y;
+ HUDWidth = hudwidth;
+ HUDHeight = hudheight;
+
+ float intpart;
+ int fracpart = (int)(fabsf (modff (x, &intpart)) * 10.f + 0.5f);
+ if (fracpart & 4)
+ {
+ CenterX = true;
+ }
+ else
+ {
+ CenterX = false;
+ }
+ if (x > 0)
+ {
+ Left = intpart + (float)(fracpart & 3) / 10.f;
+ }
+ else
+ {
+ Left = intpart - (float)(fracpart & 3) / 10.f;
+ }
+ }
+ Top = y;
+
+ if (HUDWidth == 0)
+ {
+ if (Left > 0.f)
+ { // Position center
+ drawx = (float)(screen_width - Width) * Left;
+ }
+ else
+ { // Position edge
+ drawx = (float)screen_width * -Left;
+ }
+ if (Top > 0.f)
+ { // Position center
+ drawy = (float)(bottom - Height) * Top;
+ }
+ else
+ { // Position edge
+ drawy = (float)bottom * -Top;
+ }
+ }
+ else
+ {
+ float intpart;
+ int fracpart;
+
+ fracpart = (int)(fabsf (modff (Left, &intpart)) * 10.f + 0.5f);
+ drawx = intpart;
+ switch (fracpart & 3)
+ {
+ case 0: // Position center
+ drawx -= Width / 2;
+ break;
+
+ case 2: // Position right
+ drawx -= Width;
+ break;
+ }
+
+ fracpart = (int)(fabsf (modff (Top, &intpart)) * 10.f + 0.5f);
+ drawy = intpart;
+ switch (fracpart & 3)
+ {
+ case 0: // Position center
+ drawy -= Height / 2;
+ break;
+
+ case 2: // Position bottom
+ drawy -= Height;
+ break;
+ }
+ }
+
+ if (CenterX)
+ {
+ drawx += Width / 2;
+ }
+
+ if (HUDHeight < 0)
+ {
+ // A negative height means the HUD size covers the status bar
+ hudheight = -HUDHeight;
+ }
+ else
+ {
+ // A positive height means the HUD size does not cover the status bar
+ hudheight = (float) Scale ((SDWORD)HUDHeight, screen_height, bottom);
+ }
+
+ drawx = CenterX ? x - Width / 2 : drawx;
+
+ if (hudheight && hudwidth)
+ {
+ drawx = viewwidth * (drawx / hudwidth);
+ Width = Width * (viewwidth / hudwidth);
+ drawy = viewheight * (drawy / hudheight);
+ Height = Height * (viewheight / hudheight);
+ }
+
+ f_x = f_x_mini = (int)drawx;
+ f_y = f_y_mini = (int)drawy;
+ f_w = f_w_mini = (int)Width;
+ f_h = f_h_mini = (int)Height;
+
+ stickyminimap = (sticky > 0) ? true : false;
+
+ automapactive = true;
+ minimapactive = true;
+}
+
//=============================================================================
//
// Handle events (user inputs) in automap mode
@@ -1354,9 +1563,9 @@ void AM_Ticker ()
void AM_clearFB (const AMColor &color)
{
- if (!mapback.isValid() || !am_drawmapback)
+ if (!mapback.isValid() || !am_drawmapback || minimapactive)
{
- screen->Clear (0, 0, f_w, f_h, color.Index, color.RGB);
+ screen->Clear (f_x, f_y, f_x + f_w, f_y + f_h, color.Index, color.RGB);
}
else
{
@@ -2538,12 +2747,15 @@ void AM_Drawer ()
if (!automapactive)
return;
+ if (minimapactive && (SB_state != 0 || BorderNeedRefresh))
+ AM_RefreshMiniMap();
+
bool allmap = (level.flags2 & LEVEL2_ALLMAP) != 0;
bool allthings = allmap && players[consoleplayer].mo->FindInventory(RUNTIME_CLASS(APowerScanner), true) != NULL;
- AM_initColors (viewactive);
+ AM_initColors (viewactive && !minimapactive);
- if (!viewactive)
+ if (!viewactive && !minimapactive)
{
// [RH] Set f_? here now to handle automap overlaying
// and view size adjustments.
@@ -2554,6 +2766,15 @@ void AM_Drawer ()
AM_clearFB(Background);
}
+ else if (minimapactive)
+ {
+ f_x = viewwindowx + f_x_mini;
+ f_y = viewwindowy + f_y_mini;
+ f_w = (f_x_mini + f_w_mini > viewwidth) ? viewwidth - f_x_mini : f_w_mini;
+ f_h = (f_y_mini + f_h_mini > viewheight) ? viewheight - f_y_mini : f_h_mini;
+ f_p = screen->GetPitch ();
+ AM_clearFB(Background);
+ }
else
{
f_x = viewwindowx;
View
2  src/am_map.h
@@ -44,6 +44,8 @@ void AM_Stop (void);
void AM_NewResolution ();
void AM_ToggleMap ();
+void AM_RefreshMiniMap ();
+void AM_PositionMap (float x, float y, float Width, float Height, float hudwidth, float hudheight, int sticky);
void AM_LevelInit ();
void AM_SerializeMarkers(FArchive &arc);
View
12 src/p_acs.cpp
@@ -73,6 +73,7 @@
#include "po_man.h"
#include "actorptrselect.h"
#include "farchive.h"
+#include "am_map.h"
#include "g_shared/a_pickups.h"
@@ -3431,6 +3432,7 @@ enum EACSFunctions
ACSF_ACS_NamedLockedExecuteDoor,
ACSF_ACS_NamedExecuteWithResult,
ACSF_ACS_NamedExecuteAlways,
+ ACSF_DrawMap,
};
int DLevelScript::SideFromID(int id, int side)
@@ -3942,7 +3944,17 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
scriptnum, arg1, arg2, arg3, arg4);
}
break;
+ case ACSF_DrawMap:
+ {
+ float arg0 = argCount > 0 ? FIXED2FLOAT(args[0]) : 0;
+ float arg1 = argCount > 1 ? FIXED2FLOAT(args[1]) : 0;
+ float arg2 = argCount > 2 ? FIXED2FLOAT(args[2]) : viewwidth;
+ float arg3 = argCount > 3 ? FIXED2FLOAT(args[3]) : viewheight;
+ int arg4 = argCount > 4 ? args[4] : 0;
+ AM_PositionMap (arg0, arg1, arg2, arg3, (float)hudwidth, (float)hudheight, arg4);
+ }
+ break;
default:
break;
}
Please sign in to comment.
Something went wrong with that request. Please try again.