From 5060e9b7ba569e7e736662f1c5a1dab3c7629d95 Mon Sep 17 00:00:00 2001 From: Allanis Date: Thu, 23 May 2013 20:13:41 +0100 Subject: [PATCH] [Change] Just a few bits of cleanup. --- src/base64.c | 4 ++-- src/mission.c | 9 +++++++-- src/space.c | 14 ++++++++++---- src/spfx.h | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/base64.c b/src/base64.c index 86ef816..e39d53d 100644 --- a/src/base64.c +++ b/src/base64.c @@ -187,13 +187,13 @@ char* base64_encode(size_t* len, char* src, size_t sz) { } // Decode the buffer, same syntax as base64_encode. -inline int dec_valid(char inp) { +static inline int dec_valid(char inp) { if(cd64[(int)inp] == -1) return 0; return 1; } -inline char dec_ch(char inp) { +static inline char dec_ch(char inp) { return cd64[(int)inp]; } diff --git a/src/mission.c b/src/mission.c index ee40626..d5993e2 100644 --- a/src/mission.c +++ b/src/mission.c @@ -422,6 +422,10 @@ MBuf* mbuf_create(int len, int alloc) { MBuf* buf; buf = malloc(sizeof(MBuf)); + if(buf == NULL) { + WARN("Out of memory"); + return NULL; + } buf->data = 0; buf->ndata = buf->mdata = 0; @@ -462,6 +466,7 @@ int missions_save(xmlTextWriterPtr writer) { MBuf* buf; char* data; int i, j; + size_t sz; xmlw_startElem(writer, "missions"); @@ -485,9 +490,9 @@ int missions_save(xmlTextWriterPtr writer) { buf = mbuf_create(1, 128); lua_pushvalue(player_missions[i].L, LUA_GLOBALSINDEX); pluto_persist(player_missions[i].L, mission_writeLua, buf); - data = base64_encode(&j, buf->data, buf->ndata); + data = base64_encode(&sz, buf->data, buf->ndata); mbuf_free(buf); - xmlw_raw(writer, data, j); + xmlw_raw(writer, data, sz); free(data); xmlw_endElem(writer); // Lua. diff --git a/src/space.c b/src/space.c index bda1c0b..4038bdc 100644 --- a/src/space.c +++ b/src/space.c @@ -1012,13 +1012,19 @@ void space_render(double dt) { else if(stars[i].y < -STAR_BUF) stars[i].y = gl_screen.h + STAR_BUF; // Render. - glColor4d(1., 1., 1., stars[i].brightness); - glVertex2d(stars[i].x, stars[i].y); + if((stars[i].x < SCREEN_W) && (stars[i].x > 0) && + (stars[i].y < SCREEN_H) && (stars[i].y > 0)) { + glColor4d(1., 1., 1., stars[i].brightness); + glVertex2d(stars[i].x, stars[i].y); + } } } else { // Just render. for(i = 0; i < nstars; i++) { - glColor4d(1., 1., 1., stars[i].brightness); - glVertex2d(stars[i].x, stars[i].y); + if((stars[i].x < SCREEN_W) && (stars[i].x > 0) && + (stars[i].y < SCREEN_H) && (stars[i].y > 0)) { + glColor4d(1., 1., 1., stars[i].brightness); + glVertex2d(stars[i].x, stars[i].y); + } } } glEnd(); // GL_POINTS diff --git a/src/spfx.h b/src/spfx.h index 70174d6..809c5c6 100644 --- a/src/spfx.h +++ b/src/spfx.h @@ -1,11 +1,12 @@ #pragma once #include "physics.h" +#include "opengl.h" #define SPFX_LAYER_FRONT 0 #define SPFX_LAYER_BACK 1 #define SHAKE_DECAY 50. // Decay parameter. -#define SHAKE_MAX 50. // Max parameter. +#define SHAKE_MAX 50.*SCREEN_W*SCREEN_H/1024./768. // Max parameter. // Stack manipulation. int spfx_get(char* name);