| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "grafx_bg.h" |
| 29 |
|
| 30 |
#include "actors.h" |
| 31 |
#include "ai.h" |
| 32 |
#include "draw/draw.h" |
| 33 |
#include "draw/drawtools.h" |
| 34 |
#include "game_events.h" |
| 35 |
#include "handle_game_events.h" |
| 36 |
#include "log.h" |
| 37 |
#include "map_build.h" |
| 38 |
#include "objs.h" |
| 39 |
#include "pickup.h" |
| 40 |
#include "quick_play.h" |
| 41 |
#include "texture.h" |
| 42 |
#include "triggers.h" |
| 43 |
|
| 44 |
static void DrawBackgroundWithRenderer( |
| 45 |
GraphicsDevice *g, WindowContext *wc, SDL_Texture *target, |
| 46 |
SDL_Texture *src, DrawBuffer *buffer, const HSV tint, |
| 47 |
const struct vec2 pos, const DrawBufferArgs *args); |
| 48 |
void GrafxDrawBackground( |
| 49 |
GraphicsDevice *g, DrawBuffer *buffer, const HSV tint, |
| 50 |
const struct vec2 pos, const DrawBufferArgs *args) |
| 51 |
{ |
| 52 |
DrawBackgroundWithRenderer( |
| 53 |
g, &g->gameWindow, g->bkgTgt, g->bkg, buffer, tint, pos, args); |
| 54 |
if (g->cachedConfig.SecondWindow) |
| 55 |
{ |
| 56 |
DrawBackgroundWithRenderer( |
| 57 |
g, &g->secondWindow, g->bkgTgt2, g->bkg2, buffer, tint, pos, |
| 58 |
args); |
| 59 |
} |
| 60 |
} |
| 61 |
static void DrawBackground( |
| 62 |
GraphicsDevice *g, SDL_Texture *t, DrawBuffer *buffer, Map *map, |
| 63 |
const struct vec2 pos, const DrawBufferArgs *args); |
| 64 |
static void DrawBackgroundWithRenderer( |
| 65 |
GraphicsDevice *g, WindowContext *wc, SDL_Texture *target, |
| 66 |
SDL_Texture *src, DrawBuffer *buffer, const HSV tint, |
| 67 |
const struct vec2 pos, const DrawBufferArgs *args) |
| 68 |
{ |
| 69 |
SDL_RendererInfo ri; |
| 70 |
if (SDL_GetRendererInfo(wc->renderer, &ri) != 0) |
| 71 |
{ |
| 72 |
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError()); |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
if (!(ri.flags & SDL_RENDERER_TARGETTEXTURE)) |
| 77 |
{ |
| 78 |
LOG(LM_GFX, LL_ERROR, |
| 79 |
"renderer does not support render to texture"); |
| 80 |
} |
| 81 |
} |
| 82 |
if (SDL_SetRenderTarget(wc->renderer, target) != 0) |
| 83 |
{ |
| 84 |
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError()); |
| 85 |
} |
| 86 |
wc->bkgMask = ColorTint(colorWhite, tint); |
| 87 |
DrawBackground(g, src, buffer, &gMap, pos, args); |
| 88 |
if (SDL_SetRenderTarget(wc->renderer, NULL) != 0) |
| 89 |
{ |
| 90 |
LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError()); |
| 91 |
} |
| 92 |
} |
| 93 |
static void DrawBackground( |
| 94 |
GraphicsDevice *g, SDL_Texture *t, DrawBuffer *buffer, Map *map, |
| 95 |
const struct vec2 pos, const DrawBufferArgs *args) |
| 96 |
{ |
| 97 |
BlitClearBuf(g); |
| 98 |
DrawBufferSetFromMap(buffer, map, pos, X_TILES); |
| 99 |
DrawBufferDraw(buffer, svec2i_zero(), args); |
| 100 |
BlitUpdateFromBuf(g, t); |
| 101 |
BlitClearBuf(g); |
| 102 |
} |
| 103 |
|
| 104 |
void GrafxRedrawBackground(GraphicsDevice *g, const struct vec2 pos) |
| 105 |
{ |
| 106 |
memset(g->buf, 0, GraphicsGetMemSize(&g->cachedConfig)); |
| 107 |
DrawBuffer buffer; |
| 108 |
DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), g); |
| 109 |
const HSV tint = {rand() * 360.0 / RAND_MAX, rand() * 1.0 / RAND_MAX, 0.5}; |
| 110 |
DrawBufferArgs args; |
| 111 |
memset(&args, 0, sizeof args); |
| 112 |
GrafxDrawBackground(g, &buffer, tint, pos, &args); |
| 113 |
DrawBufferTerminate(&buffer); |
| 114 |
} |
| 115 |
|
| 116 |
void GrafxMakeBackground( |
| 117 |
GraphicsDevice *device, DrawBuffer *buffer, Campaign *co, |
| 118 |
struct MissionOptions *mo, Map *map, HSV tint, const bool isEditor, |
| 119 |
struct vec2 pos, const DrawBufferArgs *args) |
| 120 |
{ |
| 121 |
CampaignAndMissionSetup(co, mo); |
| 122 |
GameEventsInit(&gGameEvents); |
| 123 |
MapBuild(map, mo->missionData, true, mo->index, GAME_MODE_NORMAL, &co->Setting.characters); |
| 124 |
InitializeBadGuys(); |
| 125 |
CreateEnemies(); |
| 126 |
MapMarkAllAsVisited(map); |
| 127 |
if (isEditor) |
| 128 |
{ |
| 129 |
for (int i = 0; i < (int)map->exits.size; i++) |
| 130 |
{ |
| 131 |
MapShowExitArea(map, i); |
| 132 |
} |
| 133 |
} |
| 134 |
else |
| 135 |
{ |
| 136 |
pos = Vec2CenterOfTile(svec2i_scale_divide(map->Size, 2)); |
| 137 |
} |
| 138 |
|
| 139 |
HandleGameEvents(&gGameEvents, NULL, NULL, NULL, NULL); |
| 140 |
GrafxDrawBackground(device, buffer, tint, pos, args); |
| 141 |
GameEventsTerminate(&gGameEvents); |
| 142 |
} |