1
1
Fork 0
Browse Source

windows port

thread-physics
alistair 4 years ago
parent
commit
e78c0f01e5
  1. 50
      Makefile
  2. 22
      draw.c
  3. 2
      draw.h
  4. 10
      game.c
  5. 24
      main.c
  6. 25
      setup.sh

50
Makefile

@ -1,8 +1,27 @@ @@ -1,8 +1,27 @@
CXX = gcc -g
SDL_INCLUDE = -lSDL2 -lm -lSDL2_image -pthread
CXXFLAGS = -Wall $(SDL_INCLUDE)
EXE = main
.PHONY: windows
.PHONY: linux
sdl2ibdir = sdllib
target=linux
ifeq ($(target),windows)
CC=x86_64-w64-mingw32-gcc
SDL_INCLUDE = -Dmain=SDL_main -Lsdllib -lSDL2main -lSDL2main -lSDL2 -lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,-static -lpthread -lm
CCFLAGS=$(SDL_INCLUDE) -O3
else
CC=gcc
SDL_INCLUDE= -lSDL2 -lm
CCFLAGS=$(SDL_INCLUDE) -O3
endif
ifdef debug
CC=$(CC) -g -Wall
endif
.PHONY: default
.PHONY: all
.PHONY: run
@ -17,39 +36,40 @@ run: all @@ -17,39 +36,40 @@ run: all
all: $(EXE)
$(EXE): main.o vect.o logger.o game.o garbo.o draw.o controlscheme.o environment.o c-colours/colours.o datastructures/datatypes.o
$(CXX) $(CXXFLAGS) -o $(EXE) main.o vect.o game.o logger.o draw.o garbo.o environment.o controlscheme.o c-colours/colours.o datastructures/datatypes.o
$(CC) -o $(EXE) main.o vect.o game.o logger.o draw.o garbo.o environment.o controlscheme.o c-colours/colours.o datastructures/datatypes.o $(CCFLAGS)
c-colours/colours.o: c-colours/colours.c c-colours/colours.h
cd c-colours && make
$(CC) -c c-colours/colours.c -o c-colours/colours.o $(CCFLAGS)
datastructures/datatypes.o: datastructures/datatypes.c datastructures/datatypes.h
cd datastructures && make
$(CC) -c datastructures/datatypes.c -o datastructures/datatypes.o $(CCFLAGS)
main.o: main.c logger.h game.h garbo.h draw.h
$(CXX) $(CXXFLAGS) -c main.c
$(CC) -c main.c $(CCFLAGS)
logger.o: logger.c logger.h
$(CXX) $(CXXFLAGS) -c logger.c
$(CC) -c logger.c $(CCFLAGS)
game.o: game.c game.h draw.h
$(CXX) $(CXXFLAGS) -c game.c
$(CC) -c game.c $(CCFLAGS)
garbo.o: garbo.c garbo.h
$(CXX) $(CXXFLAGS) -c garbo.c
$(CC) -c garbo.c $(CCFLAGS)
draw.o: draw.c draw.h
$(CXX) $(CXXFLAGS) -c draw.c
$(CC) -c draw.c $(CCFLAGS)
vect.o: vect.c vect.h
$(CXX) $(CXXFLAGS) -c vect.c
$(CC) -c vect.c $(CCFLAGS)
controlscheme.o: controlscheme.c controlscheme.h
$(CXX) $(CXXFLAGS) -c controlscheme.c
$(CC) -c controlscheme.c $(CCFLAGS)
environment.o: environment.c environment.h
$(CXX) $(CXXFLAGS) -c environment.c
$(CC) -c environment.c $(CCFLAGS)
clean:
rm c-colours/*.o
rm datastructures/*.o
rm *.o && rm $(EXE)

22
draw.c

@ -20,19 +20,19 @@ void render_texture_at(struct SDL_Renderer * ren, struct SDL_Texture * texture,i @@ -20,19 +20,19 @@ void render_texture_at(struct SDL_Renderer * ren, struct SDL_Texture * texture,i
SDL_RenderCopy(ren, texture, NULL, &destination);
}
SDL_Texture * load_image(SDL_Renderer * ren, char fname[]) {
/* Load an image into a texture */
/*SDL_Texture * load_image(SDL_Renderer * ren, char fname[]) {*/
/*[> Load an image into a texture <]*/
SDL_Surface * surface = IMG_Load(fname) ;
if(!surface) {
printf("IMG_Load: %s\n", IMG_GetError());
// handle error
}
/*SDL_Surface * surface = IMG_Load(fname) ;*/
/*if(!surface) {*/
/*printf("IMG_Load: %s\n", IMG_GetError());*/
/*// handle error*/
/*}*/
SDL_Texture * png_image = SDL_CreateTextureFromSurface(ren, surface);
cleanup(surface, SURFACE);
return (png_image);
}
/*SDL_Texture * png_image = SDL_CreateTextureFromSurface(ren, surface);*/
/*cleanup(surface, SURFACE);*/
/*return (png_image);*/
/*}*/
Vect in_view(Vect V) {
Vect ret;

2
draw.h

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
#include "game.h"
#include "environment.h"
#define SHOWCOLLISION 1
#define SHOWCOLLISION 0
#define SHOWFORCES 0
typedef enum {

10
game.c

@ -162,7 +162,7 @@ void get_new_physics(Body **phys) { @@ -162,7 +162,7 @@ void get_new_physics(Body **phys) {
// friction
add_motor(physics, 0.0, 0.0);
clock_gettime(CLOCK_MONOTONIC_RAW, &physics->last_advance_time);
clock_gettime(CLOCK_MONOTONIC, &physics->last_advance_time);
physics->updateCollisionPoly = default_update_collision_poly;
*phys = physics;
@ -700,7 +700,7 @@ void set_motor_max_velocity(Body *thing, int motorID, double max) { @@ -700,7 +700,7 @@ void set_motor_max_velocity(Body *thing, int motorID, double max) {
void set_motor_timeout(Body *thing, int motorID, uint32_t timeout) {
// this don't work yo
clock_gettime(CLOCK_MONOTONIC_RAW, &thing->motors[motorID].timeout);
clock_gettime(CLOCK_MONOTONIC, &thing->motors[motorID].timeout);
thing->motors[motorID].timeout.tv_nsec += 1000000 * timeout;
thing->motors[motorID].timeout.tv_sec
= thing->motors[motorID].timeout.tv_nsec * 0.000000001;
@ -998,7 +998,7 @@ int process_collisions(Body *thing, Vect *trans) { @@ -998,7 +998,7 @@ int process_collisions(Body *thing, Vect *trans) {
struct timespec get_now() {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
clock_gettime(CLOCK_MONOTONIC, &now);
if (now.tv_nsec >= 1000000000) {
now.tv_nsec -= 1000000000;
}
@ -1046,7 +1046,7 @@ void advance_thing(Body * thing) { @@ -1046,7 +1046,7 @@ void advance_thing(Body * thing) {
// get time delta
struct timespec now = get_now();
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
clock_gettime(CLOCK_MONOTONIC, &now);
if (now.tv_nsec >= 1000000000) {
now.tv_nsec -= 1000000000;
}
@ -1404,7 +1404,7 @@ void startgame(SDL_Renderer * ren) { @@ -1404,7 +1404,7 @@ void startgame(SDL_Renderer * ren) {
debug_ren = ren;
level = 0;
level = 4;
world = create_world();

24
main.c

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include <pthread.h>
#include "logger.h"
#include "game.h"
@ -29,25 +28,6 @@ struct SDL_Window* make_window(void) { @@ -29,25 +28,6 @@ struct SDL_Window* make_window(void) {
SDL_WINDOW_FULLSCREEN_DESKTOP);
}
void draw_pictures(struct SDL_Renderer * ren) {
logwrite(INFO, "Draw pictures\n");
// display an initial splash screen
/*
*SDL_Surface * png_surface = IMG_Load(png_file) ;
*if(!png_surface) {
* printf("IMG_Load: %s\n", IMG_GetError());
* // handle error
*}
*/
SDL_Texture * png_image = load_image(ren, "trans.PNG"); //SDL_CreateTextureFromSurface(ren, png_surface);
//render_texture_at(ren, texture, 100, 100);
//render_texture_at(ren, png_image, 100, 100);
SDL_RenderCopy(ren, png_image, NULL, NULL);
}
void redraw(struct SDL_Renderer * ren) {
// check time
@ -80,7 +60,7 @@ int game(void) { @@ -80,7 +60,7 @@ int game(void) {
queue_for_cleanup(win, WINDOW);
queue_for_cleanup(ren, RENDERER);
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
// IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
if (ren == NULL) {
SDL_DestroyWindow(win);
@ -119,7 +99,7 @@ int game(void) { @@ -119,7 +99,7 @@ int game(void) {
}
int main () {
int main (int argc, char** argv) {
game();
SDL_Quit();

25
setup.sh

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
#!/bin/bash
set -e
set -o pipefail
# This is here for building the windows binary
wget https://www.libsdl.org/release/SDL2-devel-2.0.12-mingw.tar.gz -O /tmp/sdl.tar.gz
mkdir -p /tmp/sdl-extract
# We want the library
tar -C /tmp/sdl-extract -xzf /tmp/sdl.tar.gz SDL2-2.0.12/x86_64-w64-mingw32/lib
# and the DLL
tar -C /tmp/sdl-extract -xzf /tmp/sdl.tar.gz SDL2-2.0.12/x86_64-w64-mingw32/bin/SDL2.dll
printf "copying...\n"
cp -r /tmp/sdl-extract/SDL2-2.0.12/x86_64-w64-mingw32/* .
mv bin/SDL2.dll .
rmdir bin
mv lib sdllib
printf "Success.\n"
Loading…
Cancel
Save