Build: Emscripten build target
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
@@ -63,7 +66,11 @@ int Audio_Init(){
|
|||||||
as.freq = 44100;
|
as.freq = 44100;
|
||||||
as.format = AUDIO_S16SYS;
|
as.format = AUDIO_S16SYS;
|
||||||
as.channels = 2;
|
as.channels = 2;
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
as.samples = 4096;
|
||||||
|
#else
|
||||||
as.samples = 1024;
|
as.samples = 1024;
|
||||||
|
#endif
|
||||||
as.callback = Audio_MixerCallback;
|
as.callback = Audio_MixerCallback;
|
||||||
if(SDL_OpenAudio(&as, &as2) < 0){
|
if(SDL_OpenAudio(&as, &as2) < 0){
|
||||||
printf("Audio_Init: Failure opening audio.\n");
|
printf("Audio_Init: Failure opening audio.\n");
|
||||||
|
|||||||
148
GameLib/Draw.c
148
GameLib/Draw.c
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -20,12 +21,17 @@
|
|||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
#include <emscripten.h>
|
||||||
|
#endif
|
||||||
#include "lodepng.c"
|
#include "lodepng.c"
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "Time.h"
|
#include "Time.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "QuadArray2D.h"
|
#include "QuadArray2D.h"
|
||||||
|
#include "Audio.h"
|
||||||
|
#include "Input.h"
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +48,7 @@ struct TDrawImage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
SDL_Surface *_screen=NULL;
|
SDL_Surface *_screen=NULL;
|
||||||
int _width;
|
int _width;
|
||||||
@@ -155,68 +162,96 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Draw_LoopIteration
|
||||||
|
//
|
||||||
|
// One iteracion of the loop updating the game window.
|
||||||
|
int (*_proc_func)()=NULL;
|
||||||
|
void (*_draw_func)(float f)=NULL;
|
||||||
|
long long _accTime;
|
||||||
|
int Draw_LoopIteration(){
|
||||||
|
SDL_Event event;
|
||||||
|
Uint8* keys;
|
||||||
|
int done=0;
|
||||||
|
// Update screen
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
|
||||||
|
// Process Events
|
||||||
|
while(SDL_PollEvent(&event) ){
|
||||||
|
if(event.type == SDL_QUIT ){
|
||||||
|
done=1;
|
||||||
|
}
|
||||||
|
if(event.type == SDL_KEYDOWN ){
|
||||||
|
if(event.key.keysym.sym == SDLK_ESCAPE ) {
|
||||||
|
done=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef EMSCRIPTEN
|
||||||
|
// Process keys for Draw
|
||||||
|
keys=(Uint8 *)SDL_GetKeyState(NULL);
|
||||||
|
if(keys[SDLK_F12]){
|
||||||
|
// Screenshot key
|
||||||
|
Draw_SaveScreenshoot("shot.bmp");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sound Frame
|
||||||
|
Audio_Frame();
|
||||||
|
|
||||||
|
// Process
|
||||||
|
if(_proc_func){
|
||||||
|
if(_accTime>100000){
|
||||||
|
_accTime=100000;
|
||||||
|
}
|
||||||
|
while(_accTime>=proc_t_frame && !done){
|
||||||
|
Input_Frame();
|
||||||
|
if(!_proc_func()){
|
||||||
|
done=1;
|
||||||
|
}
|
||||||
|
_accTime-=proc_t_frame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
if(_draw_func){
|
||||||
|
float frameFactor=0.0f;
|
||||||
|
frameFactor=(float)_accTime/(float)proc_t_frame;
|
||||||
|
_draw_func(frameFactor);
|
||||||
|
Draw_Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EMSCRIPTEN
|
||||||
|
long long _procTime1;
|
||||||
|
long long _procTime2;
|
||||||
|
void Draw_LoopIterationAux(){
|
||||||
|
Draw_LoopIteration();
|
||||||
|
|
||||||
|
// Update time
|
||||||
|
_procTime2=Time_GetTime();
|
||||||
|
_accTime+=_procTime2-_procTime1;
|
||||||
|
_procTime1=_procTime2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Draw_Loop
|
// Draw_Loop
|
||||||
//
|
//
|
||||||
// Loops updating the game window.
|
// Loops updating the game window.
|
||||||
void Draw_Loop(int (*proc)(),void (*draw)(float f)){
|
void Draw_Loop(int (*proc)(),void (*draw)(float f)){
|
||||||
int done=0;
|
long long newTime;
|
||||||
SDL_Event event;
|
|
||||||
Uint8* keys;
|
|
||||||
long long newTime,accTime;
|
|
||||||
long long procTime1,procTime2,drawTime1,drawTime2,waitTime;
|
long long procTime1,procTime2,drawTime1,drawTime2,waitTime;
|
||||||
float frameFactor=0.0f;
|
|
||||||
|
|
||||||
accTime=proc_t_frame;
|
_proc_func=proc;
|
||||||
|
_draw_func=draw;
|
||||||
|
#ifndef EMSCRIPTEN
|
||||||
|
_accTime=proc_t_frame;
|
||||||
procTime1=drawTime1=Time_GetTime();
|
procTime1=drawTime1=Time_GetTime();
|
||||||
while(!done){
|
while(!Draw_LoopIteration()){
|
||||||
|
|
||||||
// Update screen
|
|
||||||
SDL_GL_SwapBuffers();
|
|
||||||
|
|
||||||
// Process Events
|
|
||||||
while(SDL_PollEvent(&event) ){
|
|
||||||
if(event.type == SDL_QUIT ){
|
|
||||||
done=1;
|
|
||||||
}
|
|
||||||
if(event.type == SDL_KEYDOWN ){
|
|
||||||
if(event.key.keysym.sym == SDLK_ESCAPE ) {
|
|
||||||
done=1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process keys for Draw
|
|
||||||
keys=SDL_GetKeyState(NULL);
|
|
||||||
if(keys[SDLK_F12]){
|
|
||||||
// Screenshot key
|
|
||||||
Draw_SaveScreenshoot("shot.bmp");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sound Frame
|
|
||||||
Audio_Frame();
|
|
||||||
|
|
||||||
// Process
|
|
||||||
if(proc){
|
|
||||||
if(accTime>100000){
|
|
||||||
accTime=100000;
|
|
||||||
}
|
|
||||||
while(accTime>=proc_t_frame && !done){
|
|
||||||
Input_Frame();
|
|
||||||
if(!proc()){
|
|
||||||
done=1;
|
|
||||||
}
|
|
||||||
accTime-=proc_t_frame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
if(draw){
|
|
||||||
frameFactor=(float)accTime/(float)proc_t_frame;
|
|
||||||
draw(frameFactor);
|
|
||||||
Draw_Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait to round draw_t_frame
|
// Wait to round draw_t_frame
|
||||||
drawTime2=Time_GetTime();
|
drawTime2=Time_GetTime();
|
||||||
@@ -227,9 +262,14 @@ void Draw_Loop(int (*proc)(),void (*draw)(float f)){
|
|||||||
|
|
||||||
// Update time
|
// Update time
|
||||||
procTime2=Time_GetTime();
|
procTime2=Time_GetTime();
|
||||||
accTime+=procTime2-procTime1;
|
_accTime+=procTime2-procTime1;
|
||||||
procTime1=procTime2;
|
procTime1=procTime2;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
_accTime=proc_t_frame;
|
||||||
|
_procTime1=Time_GetTime();
|
||||||
|
emscripten_set_main_loop(Draw_LoopIterationAux, _fps, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "Time.h"
|
#include "Time.h"
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void Input_Frame(){
|
|||||||
Uint8* keys;
|
Uint8* keys;
|
||||||
|
|
||||||
// Process Keys
|
// Process Keys
|
||||||
keys=SDL_GetKeyState(NULL);
|
keys=(Uint8 *)SDL_GetKeyState(NULL);
|
||||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
||||||
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
|
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
|
||||||
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
|
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
@@ -187,7 +189,6 @@ int absmod(int v,int d){
|
|||||||
return(v%d);
|
return(v%d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float fabsmod(float v,int d){
|
float fabsmod(float v,int d){
|
||||||
if(v<0){
|
if(v<0){
|
||||||
v+=d*((((int)(v/d))*(-1))+1);
|
v+=d*((((int)(v/d))*(-1))+1);
|
||||||
@@ -199,6 +200,17 @@ float fabsmod(float v,int d){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// IsBigEndian
|
||||||
|
//
|
||||||
|
int IsBigEndian(){
|
||||||
|
union{
|
||||||
|
unsigned int i;
|
||||||
|
char c[4];
|
||||||
|
} bint={0x01020304};
|
||||||
|
return bint.c[0]==1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// EndsWith
|
// EndsWith
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ int absmod(int v,int d);
|
|||||||
float fabsmod(float v,int d);
|
float fabsmod(float v,int d);
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// IsBigEndian
|
||||||
|
//
|
||||||
|
int IsBigEndian();
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// EndsWith
|
// EndsWith
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ clean:
|
|||||||
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
|
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
|
||||||
|
|
||||||
run: $(BUILDDIR)/$(RESULT)
|
run: $(BUILDDIR)/$(RESULT)
|
||||||
./$(BUILDDIR)/$(RESULT) debug
|
$(LAUNCHER) ./$(BUILDDIR)/$(RESULT) debug
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# GameLib Rules #
|
# GameLib Rules #
|
||||||
@@ -95,7 +96,7 @@ $(BUILDDIR)/main.o: main.c $(HEADS)
|
|||||||
################
|
################
|
||||||
|
|
||||||
$(BUILDDIR)/$(RESULT): $(OBJS)
|
$(BUILDDIR)/$(RESULT): $(OBJS)
|
||||||
$(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS)
|
$(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
14
Makefile.emscripten
Normal file
14
Makefile.emscripten
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
CC= python /c/Program\ Files/Emscripten/emscripten/1.7.8/emcc
|
||||||
|
LAUNCHER= start
|
||||||
|
RM=rm -rf
|
||||||
|
|
||||||
|
LIBS=
|
||||||
|
CFLAGS= -s LEGACY_GL_EMULATION=1 -s ASM_JS=1 -O1
|
||||||
|
LDFLAGS= --preload-file data
|
||||||
|
|
||||||
|
RESULT=game.html
|
||||||
|
BUILDDIR=build-emscripten
|
||||||
|
|
||||||
|
include Makefile.common
|
||||||
|
|
||||||
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
CC=gcc
|
||||||
|
LAUNCHER=
|
||||||
|
RM=rm -rf
|
||||||
|
|
||||||
LIBS= -lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11
|
LIBS= -lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11
|
||||||
CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/
|
CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/
|
||||||
CC=gcc
|
LDFLAGS=
|
||||||
RM=rm -rf
|
|
||||||
|
|
||||||
RESULT=game
|
RESULT=game
|
||||||
BUILDDIR=build-linux
|
BUILDDIR=build-linux
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
CC= i486-mingw32-gcc
|
||||||
|
LAUNCHER=
|
||||||
|
RM=rm -rf
|
||||||
|
|
||||||
LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
|
LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
|
||||||
CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows
|
CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows
|
||||||
CC= i486-mingw32-gcc
|
LDFLAGS=
|
||||||
RM=rm -rf
|
|
||||||
|
|
||||||
RESULT=game.exe
|
RESULT=game.exe
|
||||||
BUILDDIR=build-mingw
|
BUILDDIR=build-mingw
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
CC=gcc
|
||||||
|
LAUNCHER=
|
||||||
|
RM=rm -rf
|
||||||
|
|
||||||
LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
|
LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
|
||||||
CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g
|
CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g
|
||||||
CC=gcc
|
LDFLAGS=
|
||||||
RM=rm -rf
|
|
||||||
|
|
||||||
RESULT=game.exe
|
RESULT=game.exe
|
||||||
BUILDDIR=build-mingw
|
BUILDDIR=build-mingw
|
||||||
|
|||||||
Reference in New Issue
Block a user