Skip to content

Commit

Permalink
Lock texture if streaming (#500)
Browse files Browse the repository at this point in the history
Some cleanup
  • Loading branch information
cxong committed May 23, 2017
1 parent ff49132 commit 5d01f62
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cdogs/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ void UpdateAllActors(int ticks)
const int healthPct = actor->health * 100 / maxHealth;
if (healthPct < BLEED_PERCENTAGE)
{
actor->bleedCounter--;
actor->bleedCounter -= ticks;
if (actor->bleedCounter <= 0)
{
ActorAddBloodSplatters(actor, 1, Vec2iZero());
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/automap.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ void AutomapDraw(int flags, bool showExit)

void AutomapDrawRegion(
Map *map,
Vec2i pos, Vec2i size, Vec2i mapCenter,
int scale, int flags, bool showExit)
Vec2i pos, Vec2i size, Vec2i mapCenter, int flags, bool showExit)
{
const int scale = 1;
const BlitClipping oldClip = gGraphicsDevice.clipping;
GraphicsSetBlitClip(
&gGraphicsDevice,
Expand Down
8 changes: 2 additions & 6 deletions src/cdogs/automap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __AUTOMAP
#define __AUTOMAP
#pragma once

#include "actors.h"
#include "grafx.h"
Expand All @@ -38,7 +37,4 @@
void AutomapDraw(int flags, bool showExit);
void AutomapDrawRegion(
Map *map,
Vec2i pos, Vec2i size, Vec2i mapCenter,
int scale, int flags, bool showExit);

#endif
Vec2i pos, Vec2i size, Vec2i mapCenter, int flags, bool showExit);
27 changes: 26 additions & 1 deletion src/cdogs/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,32 @@ void BlitClearBuf(GraphicsDevice *g)
}
void BlitUpdateFromBuf(GraphicsDevice *g, SDL_Texture *t)
{
SDL_UpdateTexture(t, NULL, g->buf, g->cachedConfig.Res.x * sizeof(Uint32));
int textureAccess;
if (SDL_QueryTexture(t, NULL, &textureAccess, NULL, NULL) != 0)
{
LOG(LM_GFX, LL_ERROR, "Failed to query texture: %s", SDL_GetError());
return;
}
if (textureAccess == SDL_TEXTUREACCESS_STATIC)
{
SDL_UpdateTexture(
t, NULL, g->buf, g->cachedConfig.Res.x * sizeof(Uint32));
}
else
{
CASSERT(
textureAccess == SDL_TEXTUREACCESS_STREAMING,
"invalid texture access");
void *pixels;
int pitch;
if (SDL_LockTexture(t, NULL, &pixels, &pitch) != 0)
{
LOG(LM_GFX, LL_ERROR, "Failed to lock texture: %s", SDL_GetError());
return;
}
memcpy(pixels, g->buf, GraphicsGetMemSize(&g->cachedConfig));
SDL_UnlockTexture(t);
}
}

static void RenderTexture(SDL_Renderer *r, SDL_Texture *t);
Expand Down
3 changes: 0 additions & 3 deletions src/cdogs/collision/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
#include "minkowski_hex.h"
#include "objs.h"

#define TILE_CACHE_TILE 1
#define TILE_CACHE_ADJACENT 2


static void TileCacheInit(CArray *tc)
{
Expand Down
5 changes: 1 addition & 4 deletions src/cdogs/grafx.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,7 @@ void GraphicsInitialize(GraphicsDevice *g)
}
const color_t overlayColour = brightness > 0 ? colorWhite : colorBlack;
DrawRectangle(g, Vec2iZero(), g->cachedConfig.Res, overlayColour, 0);
SDL_UpdateTexture(
g->brightnessOverlay, NULL, g->buf,
g->cachedConfig.Res.x * sizeof(Uint32));
memset(g->buf, 0, GraphicsGetMemSize(&g->cachedConfig));
BlitUpdateFromBuf(g, g->brightnessOverlay);
g->cachedConfig.Brightness = brightness;
}

Expand Down
12 changes: 4 additions & 8 deletions src/cdogs/hud/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void DrawLives(
#define AUTOMAP_SIZE 45
static void DrawRadar(
GraphicsDevice *device, const TActor *p,
const int scale, const int flags, const bool showExit)
const int flags, const bool showExit)
{
Vec2i pos = Vec2iZero();
int w = device->cachedConfig.Res.x;
Expand Down Expand Up @@ -382,13 +382,12 @@ static void DrawRadar(
pos,
Vec2iNew(AUTOMAP_SIZE, AUTOMAP_SIZE),
playerPos,
scale,
AUTOMAP_FLAGS_MASK,
showExit);
}
}

static void DrawSharedRadar(GraphicsDevice *device, int scale, bool showExit)
static void DrawSharedRadar(GraphicsDevice *device, bool showExit)
{
int w = device->cachedConfig.Res.x;
Vec2i pos = Vec2iNew(w / 2 - AUTOMAP_SIZE / 2, AUTOMAP_PADDING);
Expand All @@ -400,13 +399,10 @@ static void DrawSharedRadar(GraphicsDevice *device, int scale, bool showExit)
pos,
Vec2iNew(AUTOMAP_SIZE, AUTOMAP_SIZE),
playerMidpoint,
scale,
AUTOMAP_FLAGS_MASK,
showExit);
}

#define RADAR_SCALE 1

static void DrawObjectiveCompass(
GraphicsDevice *g, Vec2i playerPos, Rect2i r, bool showExit);
// Draw player's score, health etc.
Expand Down Expand Up @@ -483,7 +479,7 @@ static void DrawPlayerStatus(
!(flags & HUDFLAGS_SHARE_SCREEN) &&
IsAutoMapEnabled(gCampaign.Entry.Mode))
{
DrawRadar(hud->device, p, RADAR_SCALE, flags, hud->showExit);
DrawRadar(hud->device, p, flags, hud->showExit);
}
}

Expand Down Expand Up @@ -733,7 +729,7 @@ static void DrawPlayerAreas(HUD *hud)
(flags & HUDFLAGS_SHARE_SCREEN) &&
IsAutoMapEnabled(gCampaign.Entry.Mode))
{
DrawSharedRadar(hud->device, RADAR_SCALE, hud->showExit);
DrawSharedRadar(hud->device, hud->showExit);
}
}

Expand Down

0 comments on commit 5d01f62

Please sign in to comment.