Adding rscons as the building system and beginning to re-factor code
This commit is contained in:
parent
a23ce67434
commit
9afc19cba0
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
build/
|
||||||
|
.rscons*
|
||||||
|
.vscode/
|
12
Rsconscript.rb
Normal file
12
Rsconscript.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
task "configure" do
|
||||||
|
check_cxx_compiler "g++"
|
||||||
|
check_lib "SDL2"
|
||||||
|
check_lib "SDL2main"
|
||||||
|
end
|
||||||
|
|
||||||
|
task "build" do
|
||||||
|
env do |env|
|
||||||
|
env.Program("Chess", glob("src/*.cpp"))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
2507
src/chess_board.cpp
2507
src/chess_board.cpp
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL_video.h>
|
#include <SDL2/SDL_video.h>
|
||||||
|
|
||||||
void click(SDL_Renderer *p_renderer, int x, int y);
|
void click(SDL_Renderer *p_renderer, int x, int y);
|
||||||
void chess_board_resize(SDL_Renderer *p_renderer, int w, int h);
|
void chess_board_resize(SDL_Renderer *p_renderer, int w, int h);
|
||||||
void chess_board_init(SDL_Renderer *p_renderer);
|
void chess_board_init(SDL_Renderer *p_renderer);
|
||||||
void draw_board(SDL_Renderer * p_renderer);
|
void draw_board(SDL_Renderer * p_renderer);
|
214
src/game.cpp
214
src/game.cpp
@ -1,108 +1,108 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL_video.h>
|
#include <SDL2/SDL_video.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "chess_board.h"
|
#include "chess_board.h"
|
||||||
|
|
||||||
static clock_t start_time, end_time;
|
static clock_t start_time, end_time;
|
||||||
|
|
||||||
int begin_game(SDL_Renderer *renderer, SDL_Window *win)
|
int begin_game(SDL_Renderer *renderer, SDL_Window *win)
|
||||||
{
|
{
|
||||||
SDL_Rect srcR, destR;
|
SDL_Rect srcR, destR;
|
||||||
|
|
||||||
srcR.h = 800;
|
srcR.h = 800;
|
||||||
srcR.w = 800;
|
srcR.w = 800;
|
||||||
destR.h = 800;
|
destR.h = 800;
|
||||||
destR.w = 800;
|
destR.w = 800;
|
||||||
chess_board_resize(renderer, 800, 800);
|
chess_board_resize(renderer, 800, 800);
|
||||||
chess_board_init(renderer);
|
chess_board_init(renderer);
|
||||||
srcR.x = 0;
|
srcR.x = 0;
|
||||||
srcR.y = 0;
|
srcR.y = 0;
|
||||||
destR.x = 0;
|
destR.x = 0;
|
||||||
destR.y = 0;
|
destR.y = 0;
|
||||||
bool run = true;
|
bool run = true;
|
||||||
while (run)
|
while (run)
|
||||||
{
|
{
|
||||||
clock_t start_t, end_t;
|
clock_t start_t, end_t;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
bool redraw = false;
|
bool redraw = false;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
/* handle your event here */
|
/* handle your event here */
|
||||||
if (event.type == SDL_MOUSEBUTTONDOWN)
|
if (event.type == SDL_MOUSEBUTTONDOWN)
|
||||||
{
|
{
|
||||||
if (event.button.button == SDL_BUTTON_MIDDLE) // scroll up
|
if (event.button.button == SDL_BUTTON_MIDDLE) // scroll up
|
||||||
{
|
{
|
||||||
run = false;
|
run = false;
|
||||||
}
|
}
|
||||||
else if ((event.button.button == SDL_BUTTON_LEFT)
|
else if ((event.button.button == SDL_BUTTON_LEFT)
|
||||||
|| (event.button.button == SDL_BUTTON_RIGHT)) // scroll up
|
|| (event.button.button == SDL_BUTTON_RIGHT)) // scroll up
|
||||||
{
|
{
|
||||||
start_time = clock();
|
start_time = clock();
|
||||||
|
|
||||||
click(renderer, event.button.x, event.button.y);
|
click(renderer, event.button.x, event.button.y);
|
||||||
|
|
||||||
end_time = clock();
|
end_time = clock();
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
clock_t t = end_time - start_time;
|
clock_t t = end_time - start_time;
|
||||||
SDL_Log("No. of clicks %ld clicks (%f seconds) to process the incoming click.\n", t, ((float)t) / CLOCKS_PER_SEC);
|
SDL_Log("No. of clicks %ld clicks (%f seconds) to process the incoming click.\n", t, ((float)t) / CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_QUIT)
|
else if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
run = false;
|
run = false;
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_WINDOWEVENT)
|
else if (event.type == SDL_WINDOWEVENT)
|
||||||
{
|
{
|
||||||
switch (event.window.event)
|
switch (event.window.event)
|
||||||
{
|
{
|
||||||
case SDL_WINDOWEVENT_ENTER:
|
case SDL_WINDOWEVENT_ENTER:
|
||||||
case SDL_WINDOWEVENT_SHOWN:
|
case SDL_WINDOWEVENT_SHOWN:
|
||||||
case SDL_WINDOWEVENT_MOVED:
|
case SDL_WINDOWEVENT_MOVED:
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
case SDL_WINDOWEVENT_RESTORED:
|
case SDL_WINDOWEVENT_RESTORED:
|
||||||
redraw = true;
|
redraw = true;
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||||
redraw = true;
|
redraw = true;
|
||||||
SDL_GetWindowSize(win, &destR.w, &destR.h);
|
SDL_GetWindowSize(win, &destR.w, &destR.h);
|
||||||
chess_board_resize(renderer, destR.w, destR.h);
|
chess_board_resize(renderer, destR.w, destR.h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (redraw)
|
if (redraw)
|
||||||
{
|
{
|
||||||
start_time = clock();
|
start_time = clock();
|
||||||
|
|
||||||
draw_board(renderer);
|
draw_board(renderer);
|
||||||
|
|
||||||
end_time = clock();
|
end_time = clock();
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
clock_t t = end_time - start_time;
|
clock_t t = end_time - start_time;
|
||||||
SDL_Log("No. of clicks %ld clicks (%f seconds).\n",
|
SDL_Log("No. of clicks %ld clicks (%f seconds).\n",
|
||||||
t, ((float)t) / CLOCKS_PER_SEC);
|
t, ((float)t) / CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
/* do some other stuff here -- draw your app, etc. */
|
/* do some other stuff here -- draw your app, etc. */
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//g++ main.cpp -o blah `sdl2-config --cflags --libs`
|
//g++ main.cpp -o blah `sdl2-config --cflags --libs`
|
||||||
/*
|
/*
|
||||||
g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain
|
g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain
|
||||||
*/
|
*/
|
11
src/game.h
11
src/game.h
@ -1,5 +1,6 @@
|
|||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
#include <SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL_video.h>
|
#include <SDL2/SDL_video.h>
|
||||||
|
|
||||||
int begin_game(SDL_Renderer *renderer, SDL_Window *win);
|
|
||||||
|
int begin_game(SDL_Renderer *renderer, SDL_Window *win);
|
||||||
|
102
src/main.cpp
102
src/main.cpp
@ -1,52 +1,52 @@
|
|||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL_video.h>
|
#include <SDL2/SDL_video.h>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
int main( int argc, const char* argv[] )
|
int main( int argc, const char* argv[] )
|
||||||
{
|
{
|
||||||
SDL_Renderer *renderer = NULL;
|
SDL_Renderer *renderer = NULL;
|
||||||
SDL_Texture *texture = NULL;
|
SDL_Texture *texture = NULL;
|
||||||
SDL_Window *win;
|
SDL_Window *win;
|
||||||
SDL_Rect srcR, destR;
|
SDL_Rect srcR, destR;
|
||||||
const char name[] = "Game";
|
const char name[] = "Game";
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||||
{
|
{
|
||||||
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
|
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
win = SDL_CreateWindow(name, 0, 0, 800, 800, SDL_WINDOW_RESIZABLE);
|
win = SDL_CreateWindow(name, 0, 0, 800, 800, SDL_WINDOW_RESIZABLE);
|
||||||
if (win == NULL)
|
if (win == NULL)
|
||||||
{
|
{
|
||||||
// In the case that the window could not be made...
|
// In the case that the window could not be made...
|
||||||
printf("Could not create window: %s\n", SDL_GetError());
|
printf("Could not create window: %s\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
|
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||||
SDL_Rect rectangle;
|
SDL_Rect rectangle;
|
||||||
|
|
||||||
rectangle.x = 0;
|
rectangle.x = 0;
|
||||||
rectangle.y = 0;
|
rectangle.y = 0;
|
||||||
rectangle.w = 50;
|
rectangle.w = 50;
|
||||||
rectangle.h = 50;
|
rectangle.h = 50;
|
||||||
SDL_RenderFillRect(renderer, &rectangle);
|
SDL_RenderFillRect(renderer, &rectangle);
|
||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 800, 800);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 800, 800);
|
||||||
|
|
||||||
(void)begin_game(renderer, win);
|
(void)begin_game(renderer, win);
|
||||||
|
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
SDL_DestroyWindow(win);
|
SDL_DestroyWindow(win);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//g++ main.cpp -o blah `sdl2-config --cflags --libs`
|
//g++ main.cpp -o blah `sdl2-config --cflags --libs`
|
||||||
/*
|
/*
|
||||||
g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain
|
g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain
|
||||||
*/
|
*/
|
@ -1,12 +1,12 @@
|
|||||||
#include "pieces.hpp"
|
#include "pieces.hpp"
|
||||||
|
|
||||||
pieces::pieces(uint8_t row, uint8_t column)
|
pieces::pieces(uint8_t row, uint8_t column)
|
||||||
{
|
{
|
||||||
my_position.row = row;
|
my_position.row = row;
|
||||||
my_position.column = column;
|
my_position.column = column;
|
||||||
}
|
}
|
||||||
|
|
||||||
pieces::~pieces()
|
pieces::~pieces()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define UNINIT 0xFFu
|
#define UNINIT 0xFFu
|
||||||
|
|
||||||
struct position
|
struct position
|
||||||
{
|
{
|
||||||
uint8_t row;
|
uint8_t row;
|
||||||
uint8_t column;
|
uint8_t column;
|
||||||
};
|
};
|
||||||
|
|
||||||
class pieces
|
class pieces
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
position my_position;
|
position my_position;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
pieces(uint8_t row, uint8_t column);
|
pieces(uint8_t row, uint8_t column);
|
||||||
~pieces();
|
~pieces();
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user