Build: Emscripten build target
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "Audio.h"
|
||||
@@ -63,7 +66,11 @@ int Audio_Init(){
|
||||
as.freq = 44100;
|
||||
as.format = AUDIO_S16SYS;
|
||||
as.channels = 2;
|
||||
#ifdef EMSCRIPTEN
|
||||
as.samples = 4096;
|
||||
#else
|
||||
as.samples = 1024;
|
||||
#endif
|
||||
as.callback = Audio_MixerCallback;
|
||||
if(SDL_OpenAudio(&as, &as2) < 0){
|
||||
printf("Audio_Init: Failure opening audio.\n");
|
||||
|
||||
148
GameLib/Draw.c
148
GameLib/Draw.c
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -20,12 +21,17 @@
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include "lodepng.c"
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "Time.h"
|
||||
#include "Util.h"
|
||||
#include "QuadArray2D.h"
|
||||
#include "Audio.h"
|
||||
#include "Input.h"
|
||||
#include "Draw.h"
|
||||
|
||||
|
||||
@@ -42,6 +48,7 @@ struct TDrawImage {
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Globals
|
||||
SDL_Surface *_screen=NULL;
|
||||
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
|
||||
//
|
||||
// Loops updating the game window.
|
||||
void Draw_Loop(int (*proc)(),void (*draw)(float f)){
|
||||
int done=0;
|
||||
SDL_Event event;
|
||||
Uint8* keys;
|
||||
long long newTime,accTime;
|
||||
long long newTime;
|
||||
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();
|
||||
while(!done){
|
||||
|
||||
// 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();
|
||||
}
|
||||
while(!Draw_LoopIteration()){
|
||||
|
||||
// Wait to round draw_t_frame
|
||||
drawTime2=Time_GetTime();
|
||||
@@ -227,9 +262,14 @@ void Draw_Loop(int (*proc)(),void (*draw)(float f)){
|
||||
|
||||
// Update time
|
||||
procTime2=Time_GetTime();
|
||||
accTime+=procTime2-procTime1;
|
||||
_accTime+=procTime2-procTime1;
|
||||
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)
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
#include "Time.h"
|
||||
|
||||
@@ -57,7 +57,7 @@ void Input_Frame(){
|
||||
Uint8* keys;
|
||||
|
||||
// Process Keys
|
||||
keys=SDL_GetKeyState(NULL);
|
||||
keys=(Uint8 *)SDL_GetKeyState(NULL);
|
||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
||||
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
|
||||
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
@@ -187,7 +189,6 @@ int absmod(int v,int d){
|
||||
return(v%d);
|
||||
}
|
||||
}
|
||||
|
||||
float fabsmod(float v,int d){
|
||||
if(v<0){
|
||||
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
|
||||
|
||||
@@ -65,6 +65,11 @@ int absmod(int v,int d);
|
||||
float fabsmod(float v,int d);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// IsBigEndian
|
||||
//
|
||||
int IsBigEndian();
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// EndsWith
|
||||
|
||||
@@ -50,8 +50,9 @@ clean:
|
||||
rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
|
||||
|
||||
run: $(BUILDDIR)/$(RESULT)
|
||||
./$(BUILDDIR)/$(RESULT) debug
|
||||
$(LAUNCHER) ./$(BUILDDIR)/$(RESULT) debug
|
||||
|
||||
rebuild: clean all
|
||||
|
||||
#################
|
||||
# GameLib Rules #
|
||||
@@ -95,7 +96,7 @@ $(BUILDDIR)/main.o: main.c $(HEADS)
|
||||
################
|
||||
|
||||
$(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
|
||||
CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/
|
||||
CC=gcc
|
||||
RM=rm -rf
|
||||
LDFLAGS=
|
||||
|
||||
RESULT=game
|
||||
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
|
||||
CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows
|
||||
CC= i486-mingw32-gcc
|
||||
RM=rm -rf
|
||||
LDFLAGS=
|
||||
|
||||
RESULT=game.exe
|
||||
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
|
||||
CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g
|
||||
CC=gcc
|
||||
RM=rm -rf
|
||||
LDFLAGS=
|
||||
|
||||
RESULT=game.exe
|
||||
BUILDDIR=build-mingw
|
||||
|
||||
Reference in New Issue
Block a user