Separate SDL from graphics code
Also remove OS X specific project files and update Makefile to ensure the Element class generator only runs when necessary
This commit is contained in:
parent
7074036b89
commit
86746f38b0
4
.gitignore
vendored
4
.gitignore
vendored
@ -14,5 +14,7 @@ Saves/*
|
|||||||
generated/*
|
generated/*
|
||||||
generate
|
generate
|
||||||
Makefile.me
|
Makefile.me
|
||||||
PowderToypp.xcodeproj/*
|
*.xcodeproj
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
*.plist
|
||||||
|
*.lproj
|
||||||
|
10
Makefile
10
Makefile
@ -1,14 +1,9 @@
|
|||||||
HEADERS := $(wildcard src/*.h) $(wildcard src/*/*.h) $(wildcard generated/*.h)
|
HEADERS := $(wildcard src/*.h) $(wildcard src/*/*.h) $(wildcard generated/*.h)
|
||||||
|
|
||||||
SOURCES := $(wildcard src/*.cpp) $(wildcard src/*/*.cpp) $(wildcard src/*/*/*.cpp) $(wildcard generated/*.cpp)
|
SOURCES := $(wildcard src/*.cpp) $(wildcard src/*/*.cpp) $(wildcard src/*/*/*.cpp) $(wildcard generated/*.cpp)
|
||||||
|
GENERATEDSOURCES := $(wildcard src/*/*/*.h) $(wildcard src/*/*/*.cpp)
|
||||||
OBJS := $(patsubst src/%.cpp,build/obj/%.o,$(SOURCES))
|
OBJS := $(patsubst src/%.cpp,build/obj/%.o,$(SOURCES))
|
||||||
|
|
||||||
NEWLINE := $(`echo "d\nd"`)
|
|
||||||
ELEMENTFILES := $(patsubst src/simulation/%,\#include "%"$(NEWLINE),$(wildcard src/simulation/elements/*.cpp))
|
|
||||||
#ELEMENTFILES := \#include "elements/watr.cpp"
|
|
||||||
|
|
||||||
FOLDERS :=
|
|
||||||
|
|
||||||
CFLAGS := -w -Isrc/ -Idata/ -Igenerated/
|
CFLAGS := -w -Isrc/ -Idata/ -Igenerated/
|
||||||
OFLAGS := -fkeep-inline-functions
|
OFLAGS := -fkeep-inline-functions
|
||||||
|
|
||||||
@ -73,7 +68,8 @@ buildpaths-powder-x:
|
|||||||
$(shell mkdir -p build/obj/powder-x/)
|
$(shell mkdir -p build/obj/powder-x/)
|
||||||
$(shell mkdir -p $(sort $(dir $(patsubst build/obj/%.o,build/obj/powder-x/%.o,$(OBJS)))))
|
$(shell mkdir -p $(sort $(dir $(patsubst build/obj/%.o,build/obj/powder-x/%.o,$(OBJS)))))
|
||||||
|
|
||||||
generate:
|
generate: $(GENERATEDSOURCES)
|
||||||
|
touch generate
|
||||||
python generator.py
|
python generator.py
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
File diff suppressed because one or more lines are too long
@ -117,9 +117,7 @@ public:
|
|||||||
#ifdef OGLR
|
#ifdef OGLR
|
||||||
//OpenGL specific instance variables
|
//OpenGL specific instance variables
|
||||||
GLuint vidBuf, textTexture;
|
GLuint vidBuf, textTexture;
|
||||||
#else
|
#endif
|
||||||
SDL_Surface * sdl_scrn;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Common graphics methods in Graphics.cpp
|
//Common graphics methods in Graphics.cpp
|
||||||
static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size);
|
static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size);
|
||||||
@ -147,8 +145,7 @@ public:
|
|||||||
void draw_icon(int x, int y, Icon icon);
|
void draw_icon(int x, int y, Icon icon);
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void AttachSDLSurface(SDL_Surface * surface);
|
void Finalise();
|
||||||
void Blit();
|
|
||||||
//
|
//
|
||||||
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
||||||
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
|
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
|
||||||
|
@ -6,23 +6,6 @@
|
|||||||
Graphics::Graphics():
|
Graphics::Graphics():
|
||||||
sdl_scale(1)
|
sdl_scale(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics::~Graphics()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::Clear()
|
|
||||||
{
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::AttachSDLSurface(SDL_Surface * surface)
|
|
||||||
{
|
|
||||||
//sdl_scrn = surface;
|
|
||||||
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
@ -64,27 +47,19 @@ void Graphics::AttachSDLSurface(SDL_Surface * surface)
|
|||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::Blit()
|
Graphics::~Graphics()
|
||||||
{
|
{
|
||||||
//glDrawPixels(w,h,GL_BGRA,GL_UNSIGNED_BYTE,src); //Why does this still think it's ABGR?
|
}
|
||||||
/*glEnable( GL_TEXTURE_2D );
|
|
||||||
glBindTexture(GL_TEXTURE_2D, vidBuf);
|
|
||||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, GL_BGRA, GL_UNSIGNED_BYTE, vid);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glTexCoord2d(1, 0);
|
|
||||||
glVertex3f((XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0);
|
|
||||||
glTexCoord2d(0, 0);
|
|
||||||
glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0);
|
|
||||||
glTexCoord2d(0, 1);
|
|
||||||
glVertex3f(0, 0, 1.0);
|
|
||||||
glTexCoord2d(1, 1);
|
|
||||||
glVertex3f((XRES+BARSIZE)*sdl_scale, 0, 1.0);
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
glDisable( GL_TEXTURE_2D );*/
|
void Graphics::Clear()
|
||||||
|
{
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graphics::Finalise()
|
||||||
|
{
|
||||||
glFlush();
|
glFlush();
|
||||||
SDL_GL_SwapBuffers ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||||
|
@ -33,6 +33,38 @@ using namespace std;
|
|||||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SDL_Surface * sdl_scrn;
|
||||||
|
|
||||||
|
#ifdef OGLR
|
||||||
|
void blit()
|
||||||
|
{
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void blit(pixel * vid)
|
||||||
|
{
|
||||||
|
if(sdl_scrn)
|
||||||
|
{
|
||||||
|
pixel * dst;
|
||||||
|
pixel * src = vid;
|
||||||
|
int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE;
|
||||||
|
if (SDL_MUSTLOCK(sdl_scrn))
|
||||||
|
if (SDL_LockSurface(sdl_scrn)<0)
|
||||||
|
return;
|
||||||
|
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
||||||
|
for (j=0; j<h; j++)
|
||||||
|
{
|
||||||
|
memcpy(dst, src, w*PIXELSIZE);
|
||||||
|
dst+=sdl_scrn->pitch/PIXELSIZE;
|
||||||
|
src+=pitch;
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK(sdl_scrn))
|
||||||
|
SDL_UnlockSurface(sdl_scrn);
|
||||||
|
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Surface * SDLOpen()
|
SDL_Surface * SDLOpen()
|
||||||
{
|
{
|
||||||
SDL_Surface * surface;
|
SDL_Surface * surface;
|
||||||
@ -93,26 +125,18 @@ SDL_Surface * SDLOpen()
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int SDLPoll(SDL_Event * event)
|
|
||||||
{
|
|
||||||
while (SDL_PollEvent(event))
|
|
||||||
{
|
|
||||||
switch (event->type)
|
|
||||||
{
|
|
||||||
case SDL_QUIT:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
||||||
float fps = 0, delta = 1.0f;
|
float fps = 0, delta = 1.0f;
|
||||||
|
|
||||||
|
sdl_scrn = SDLOpen();
|
||||||
|
#ifdef OGLR
|
||||||
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
ui::Engine::Ref().g = new Graphics();
|
ui::Engine::Ref().g = new Graphics();
|
||||||
ui::Engine::Ref().g->AttachSDLSurface(SDLOpen());
|
//ui::Engine::Ref().g->AttachSDLSurface(SDLOpen());
|
||||||
|
|
||||||
ui::Engine * engine = &ui::Engine::Ref();
|
ui::Engine * engine = &ui::Engine::Ref();
|
||||||
engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
|
engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
|
||||||
@ -167,6 +191,12 @@ int main(int argc, char * argv[])
|
|||||||
engine->Tick();
|
engine->Tick();
|
||||||
engine->Draw();
|
engine->Draw();
|
||||||
|
|
||||||
|
#ifdef OGLR
|
||||||
|
blit();
|
||||||
|
#else
|
||||||
|
blit(engine->g->vid);
|
||||||
|
#endif
|
||||||
|
|
||||||
currentFrame++;
|
currentFrame++;
|
||||||
currentTime = SDL_GetTicks();
|
currentTime = SDL_GetTicks();
|
||||||
elapsedTime = currentTime - lastTime;
|
elapsedTime = currentTime - lastTime;
|
@ -20,32 +20,9 @@ void Graphics::Clear()
|
|||||||
memset(vid, 0, PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE)));
|
memset(vid, 0, PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::AttachSDLSurface(SDL_Surface * surface)
|
void Graphics::Finalise()
|
||||||
{
|
{
|
||||||
sdl_scrn = surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Graphics::Blit()
|
|
||||||
{
|
|
||||||
if(sdl_scrn)
|
|
||||||
{
|
|
||||||
pixel * dst;
|
|
||||||
pixel * src = vid;
|
|
||||||
int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE;
|
|
||||||
if (SDL_MUSTLOCK(sdl_scrn))
|
|
||||||
if (SDL_LockSurface(sdl_scrn)<0)
|
|
||||||
return;
|
|
||||||
dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
|
|
||||||
for (j=0; j<h; j++)
|
|
||||||
{
|
|
||||||
memcpy(dst, src, w*PIXELSIZE);
|
|
||||||
dst+=sdl_scrn->pitch/PIXELSIZE;
|
|
||||||
src+=pitch;
|
|
||||||
}
|
|
||||||
if (SDL_MUSTLOCK(sdl_scrn))
|
|
||||||
SDL_UnlockSurface(sdl_scrn);
|
|
||||||
SDL_UpdateRect(sdl_scrn,0,0,0,0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||||
|
@ -184,7 +184,7 @@ void Engine::Draw()
|
|||||||
char fpsText[512];
|
char fpsText[512];
|
||||||
sprintf(fpsText, "FPS: %.2f, Delta: %.3f", fps, dt);
|
sprintf(fpsText, "FPS: %.2f, Delta: %.3f", fps, dt);
|
||||||
ui::Engine::Ref().g->drawtext(10, 10, fpsText, 255, 255, 255, 255);
|
ui::Engine::Ref().g->drawtext(10, 10, fpsText, 255, 255, 255, 255);
|
||||||
g->Blit();
|
g->Finalise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::SetFps(float fps)
|
void Engine::SetFps(float fps)
|
||||||
|
Loading…
Reference in New Issue
Block a user