Skip to content

Commit

Permalink
Allow setting a shader for each model level, rather than for entire m…
Browse files Browse the repository at this point in the history
…odel.
  • Loading branch information
perim committed Apr 19, 2015
1 parent 38b4fe1 commit 1b82691
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion lib/gamelib/anim.cpp
Expand Up @@ -34,7 +34,6 @@
#include "lib/framework/frame.h"
#include "lib/framework/string_ext.h"
#include "lib/framework/frameresource.h"
#include "lib/ivis_opengl/piematrix.h"
#include "lib/framework/fixedpoint.h"

#include "anim.h"
Expand Down
21 changes: 15 additions & 6 deletions lib/ivis_opengl/imdload.cpp
Expand Up @@ -663,7 +663,8 @@ static inline int addVertex(iIMDShape *s, int i, const iIMDPoly *p, int frameidx
*/
static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataEnd, int nlevels, int pieVersion)
{
const char *pTmp, *pFileData = *ppFileData;
const char *pFileName = GetLastResourceFilename(); // Last loaded filename
const char *pFileData = *ppFileData;
char buffer[PATH_MAX] = {'\0'};
int cnt = 0, n = 0, i;
iIMDShape *s = NULL;
Expand All @@ -674,7 +675,6 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
return NULL;
}

pTmp = pFileData; // remember position
i = sscanf(pFileData, "%255s %n", buffer, &cnt);
ASSERT_OR_RETURN(NULL, i == 1, "Bad directive following LEVEL");

Expand All @@ -689,9 +689,17 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
debug(LOG_WARNING, "MATERIALS directive no longer supported!");
pFileData += cnt;
}
else // use defaults
else if (strcmp(buffer, "SHADERS") == 0)
{
pFileData = pTmp;
char vertex[PATH_MAX], fragment[PATH_MAX];

if (sscanf(pFileData, "%255s %255s %255s%n", buffer, vertex, fragment, &cnt) != 3)
{
debug(LOG_ERROR, "%s shader corrupt: %s", pFileName, buffer);
return NULL;
}
s->shaderProgram = pie_LoadShader(pFileName, vertex, fragment);
pFileData += cnt;
}

if (sscanf(pFileData, "%255s %d%n", buffer, &s->npoints, &cnt) != 2)
Expand Down Expand Up @@ -968,6 +976,7 @@ static iIMDShape *iV_ProcessIMD(const char **ppFileData, const char *FileDataEnd
pFileData += cnt;
}

// DEPRECATED SHADERS DIRECTIVE! Has been moved into levels block now. Remove me later.
if (strncmp(buffer, "SHADERS", 7) == 0)
{
char vertex[PATH_MAX], fragment[PATH_MAX];
Expand Down Expand Up @@ -1019,8 +1028,8 @@ static iIMDShape *iV_ProcessIMD(const char **ppFileData, const char *FileDataEnd
return NULL;
}

// assign shader to all levels
for (iIMDShape *psShape = shape; psShape != NULL; psShape = psShape->next)
// assign shader to all levels, if old deprecated SHADERS directive used. FIXME remove this later.
for (iIMDShape *psShape = shape; shader && psShape != NULL; psShape = psShape->next)
{
shape->shaderProgram = shader;
}
Expand Down
3 changes: 1 addition & 2 deletions src/display3d.cpp
Expand Up @@ -3550,8 +3550,7 @@ static void processSensorTarget(void)
}
iV_DrawImage(IntImages, index, x, y);

offset = (SWORD)(12 + ((TARGET_TO_SENSOR_TIME) - (realTime -
lastTargetAssignation)) / 2);
offset = (SWORD)(12 + ((TARGET_TO_SENSOR_TIME) - (realTime - lastTargetAssignation)) / 2);

x0 = (SWORD)(x - offset);
y0 = (SWORD)(y - offset);
Expand Down
2 changes: 1 addition & 1 deletion src/structure.cpp
Expand Up @@ -2823,7 +2823,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
// or that have been ordered to this repair facility (DORDER_RTR_SPECIFIED),
// or any "lost" unit with one of those two orders.
if (((psDroid->order.type == DORDER_RTR || (psDroid->order.type == DORDER_RTR_SPECIFIED
&& (!psTarget || psTarget == psStructure)))
&& (!psTarget || psTarget == psStructure)))
&& psDroid->action != DACTION_WAITFORREPAIR && psDroid->action != DACTION_MOVETOREPAIRPOINT
&& psDroid->action != DACTION_WAITDURINGREPAIR)
|| (psTarget && psTarget == psStructure))
Expand Down

0 comments on commit 1b82691

Please sign in to comment.