From: matthew Date: Sat, 28 Jul 2018 17:05:36 +0000 (+0000) Subject: initial commit X-Git-Url: https://git.owens.tech/assets/wrapped.html/assets/wrapped.html/git?a=commitdiff_plain;h=5a760b788460e1c192c153a932b18af25e41ea7c;p=csrpg.git initial commit --- 5a760b788460e1c192c153a932b18af25e41ea7c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb11606 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build.sh +game +game-nogl +*.o +*.sw* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..130724a --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +GL_TARGET = game +LIBS = -lm -D_REENTRANT -lGL -lGLEW -lSDL2 -lSDL2_image + +NOGL_TARGET = game-nogl +NOGL_LIBS = -lm -D_REENTRANT -lSDL2 -lSDL2_image + +CC = gcc +CFLAGS = -g -Wall -I/usr/include/SDL2 -Icommon/ -Inogl/ -Igl/ + +.PHONY: default all clean + +default: $(GL_TARGET) +all: default + +COMMON_OBJECTS = $(patsubst common/%.c, common/%.o, $(wildcard common/*.c)) +COMMON_HEADERS = $(wildcard common/*.h) +COMMON_SRCS = $(wildcard common/*.c) + +NOGL_OBJECTS = $(patsubst nogl/%.c, nogl/%.o, $(wildcard nogl/*.c)) +NOGL_HEADERS = $(wildcard nogl/*.h) +NOGL_SRCS = $(wildcard nogl/*.c) + +GL_OBJECTS = $(patsubst gl/%.c, gl/%.o, $(wildcard gl/*.c)) +GL_HEADERS = $(wildcard gl/*.h) +GL_SRCS = $(wildcard gl/*.c) + +.PRECIOUS: $(TARGET) $(NOGL_TARGET) $(COMMON_OBJECTS) $(GL_OBJECTS) $(NOGL_OBJECTS) + +$(GL_TARGET): $(COMMON_OBJECTS) $(GL_OBJECTS) + $(CC) $(COMMON_OBJECTS) $(GL_OBJECTS) -Wall $(LIBS) -o $@ + +$(NOGL_TARGET): $(COMMON_OBJECTS) $(NOGL_OBJECTS) + $(CC) $(COMMON_OBJECTS) $(NOGL_OBJECTS) -Wall $(LIBS) -o $@ + +common/%.o: $(COMMON_SRCS) + $(CC) $(CFLAGS) -c $< -o $@ + +nogl/%.o: $(NOGL_SRCS) + $(CC) $(CFLAGS) -c $< -o $@ + +gl/%.o: $(GL_SRCS) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f gl/*.o + rm -f nogl/*.o + rm -f common/*.o + rm -f $(GL_TARGET) + rm -f $(NOGL_TARGET) + +output: + @echo "==== gl ====" + @echo "gl sources: $(GL_SRCS)" + @echo "gl headers: $(GL_HEADERS)" + @echo "gl objects: $(GL_OBJECTS)" + @echo "==== nogl ====" + @echo "nogl sources: $(NOGL_SRCS)" + @echo "nogl headers: $(NOGL_HEADERS)" + @echo "nogl objects: $(NOGL_OBJECTS)" + @echo "==== common ====" + @echo "common sources: $(COMMON_SRCS)" + @echo "common headers: $(COMMON_HEADERS)" + @echo "common objects: $(COMMON_OBJECTS)" diff --git a/common/point.h b/common/point.h new file mode 100644 index 0000000..aaaff87 --- /dev/null +++ b/common/point.h @@ -0,0 +1,14 @@ +/* + * This is a simple header file that defines structs to represent + * points in space. points can be comprised of 2-4 integers or + * floats. This makes the header versitile as it can also be + * used to store other data. For example: colour information +*/ + +typedef struct { int x, y; } Point2i; +typedef struct { int x, y, z ; } Point3i; +typedef struct { int w, x, y , z; } Point4i; + +typedef struct { float x, y; } Point2f; +typedef struct { float x, y, z; } Point3f; +typedef struct { float w, x, y, z; } Point4f; diff --git a/common/tile.c b/common/tile.c new file mode 100644 index 0000000..d1b6005 --- /dev/null +++ b/common/tile.c @@ -0,0 +1,33 @@ +#include "tile.h" +#include + +typedef struct +{ + Point3i position; + enum Terrain terrain; +} Tile_t; + +Tile *tile_init(Point3i pos, enum Terrain ter) +{ + Tile_t *t = malloc(sizeof(Tile_t)); + t->position = pos; + t->terrain = ter; + return (Tile *) t; +} + +void tile_cleanup(Tile *t) +{ + free(t); +} + +Point3i tile_position(Tile *t) +{ + Tile_t *tt = (Tile *) t; + return tt->position; +} + +enum Terrain tile_terrain(Tile *t) +{ + Tile_t *tt = (Tile *) t; + return tt->terrain; +} diff --git a/common/tile.h b/common/tile.h new file mode 100644 index 0000000..25c6757 --- /dev/null +++ b/common/tile.h @@ -0,0 +1,19 @@ +#include "point.h" + +enum Terrain{ + IMPASSABLE = -1, + PLAINS, + MOUNTAIN, + S_WATER, + D_WATER, + WALL, + FLOOR, + ROAD +}; + +typedef struct {} Tile; + +Tile *tile_init(Point3i pos, enum Terrain ter); +void tile_cleanup(Tile *t); +Point3i tile_position(Tile *t); +enum Terrain tile_terrain(Tile *t); diff --git a/gl/main.c b/gl/main.c new file mode 100644 index 0000000..0d07da1 --- /dev/null +++ b/gl/main.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +static SDL_Window *window = NULL; +static SDL_GLContext *context = NULL; + +static bool init() +{ + if (SDL_Init( + SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS + ) < 0){ + printf("SDL couldn't init! SDL_Error: %s\n", SDL_GetError()); + return false; + } + + window = SDL_CreateWindow("csrpg", SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL); + + if (window == NULL){ + printf("SDL couldn't make an OpenGL window! SDL_Error: %s\n", SDL_GetError()); + return false; + } + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + context = SDL_GL_CreateContext(window); + + if(context == NULL){ + printf("SDL couldn't create an OpenGL context! SDL_Error: %s\n", SDL_GetError()); + return false; + } + + /* syncing the buffer swap with the monitor's vertical refresh */ + SDL_GL_SetSwapInterval(1); + + glewExperimental = GL_TRUE; + glewInit(); + + return true; +} + +int main() +{ + Uint32 itime; + Uint32 ctime = 0; + + if(!init()) + return -1; + + itime = SDL_GetTicks(); + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + SDL_GL_SwapWindow(window); + + while(ctime != itime + 2000){ + ctime = SDL_GetTicks(); + } + SDL_Quit(); + return 0; +} diff --git a/nogl/main.c b/nogl/main.c new file mode 100644 index 0000000..fcbe1e0 --- /dev/null +++ b/nogl/main.c @@ -0,0 +1,68 @@ +#include +#include +#include +//#include "tile.h" + + +//static Tile *tile = NULL; +//static Point3 pos; + +bool init() +{ + if(SDL_Init(SDL_INIT_TIMER) < 0){ + printf("SDL couldn't init! SDL_Error: %s\n", SDL_GetError()); + return false; + } +/* + pos.x = 1; + pos.y = 2; + pos.z = 3; + + tile = tile_init(pos, Terrain.D_WATER); + + pos.x = pos.y = pos.z = 0; + pos = tile_position(t); + + if(tile == NULL){ + printf("ERROR: tile null!"); + return false; + } +*/ + return true; +} + +int main() +{ + if(!init()) + return -1; + + char *str = malloc(10); + char *rot = malloc(4); + Uint32 itime = SDL_GetTicks(); + Uint32 ctime = 0; + int i = 0; + +/* + printf("Tile pos - (%d,%d,%d), ter - %d", + pos.x, pos.y, pos.z, tile_terrain(t)); +*/ + strcpy(str, "Hello... |"); + strcpy(rot, "|/-\\"); + printf("%s", str); + + while(itime < ctime + 2000){ + str[9] = rot[i]; + printf("\r%s", str); + + ++i; + if(i > 3) i = 0; + itime = SDL_GetTicks(); + } + printf("\n"); + + free(str); + free(rot); + SDL_Quit(); + + return 0; +}