# HG changeset patch # User John Tsiombikas # Date 1435521877 -10800 # Node ID 16a420432aa34ff2368f1ecffe54df331ad6cb0e # Parent d6209903454bb4a144cb87d0aa7ce456f497edbe pieces on the board diff -r d6209903454b -r 16a420432aa3 src/board.cc --- a/src/board.cc Sun Jun 28 08:48:25 2015 +0300 +++ b/src/board.cc Sun Jun 28 23:04:37 2015 +0300 @@ -5,10 +5,49 @@ #include "meshgen.h" #include "pnoise.h" #include "revol.h" +#include "opt.h" + + +#define HSIZE 1.0 +#define VSIZE (2.0 * HSIZE) +#define BOT_THICKNESS (HSIZE * 0.01) +#define WALL_THICKNESS (HSIZE * 0.05) +#define WALL_HEIGHT (HSIZE * 0.1) +#define GAP (HSIZE * 0.025) +#define HINGE_RAD (GAP * 0.5) +#define HINGE_HEIGHT (VSIZE * 0.075) +#define PIECE_RAD (0.45 * HSIZE / 5.0) +#define BOARD_OFFSET (HSIZE / 2.0 + WALL_THICKNESS + HINGE_RAD * 0.25) +#define PIECES_PER_LAYER 5 + + +Piece::Piece() +{ + owner = 0; + slot = prev_slot = -1; + level = 0; + move_start = 0; +} + +void Piece::move_to(int slot, int level, bool anim) +{ + int prev_slot = this->slot; + int prev_level = this->level; + + this->slot = slot; + this->level = level; + + if(anim) { + this->prev_slot = prev_slot; + this->prev_level = prev_level; + move_start = cur_time; + } +} + Board::Board() { - puck_obj = 0; + piece_obj = 0; clear(); } @@ -36,13 +75,77 @@ } obj.clear(); - delete puck_obj; - puck_obj = 0; + delete piece_obj; + piece_obj = 0; } void Board::clear() { - memset(slots, 0, sizeof slots); + memset(hist, 0, sizeof hist); + + for(int i=0; idraw(); } } + + for(int i=0; ixform().set_translation(pos); + piece_obj->mtl.diffuse = opt.piece_color[pieces[i].owner]; + piece_obj->draw(); + } } -#define HSIZE 1.0 -#define VSIZE (2.0 * HSIZE) -#define BOT_THICKNESS (HSIZE * 0.01) -#define WALL_THICKNESS (HSIZE * 0.05) -#define WALL_HEIGHT (HSIZE * 0.1) -#define GAP (HSIZE * 0.025) -#define HINGE_RAD (GAP * 0.5) -#define HINGE_HEIGHT (VSIZE * 0.075) -#define PIECE_RAD (0.45 * HSIZE / 5.0) - static const vec2_t piece_cp[] = { {0, 0.25}, @@ -106,7 +206,7 @@ Object *obottom = new Object; obottom->set_mesh(bottom); - obottom->xform().set_translation(Vector3(sign * (HSIZE / 2.0 + WALL_THICKNESS + HINGE_RAD * 0.25), 0, 0)); + obottom->xform().set_translation(Vector3(sign * BOARD_OFFSET, 0, 0)); obottom->set_texture(img_field.texture()); obj.push_back(obottom); @@ -222,7 +322,9 @@ opiece->mtl.specular = Vector3(0.8, 0.8, 0.8); opiece->xform().set_translation(Vector3(0, 0.2, 0)); opiece->set_shader(sdr_phong_notex); - obj.push_back(opiece); + //obj.push_back(opiece); + + piece_obj = opiece; // meshgen stats printf("Generated board:\n %u meshes\n", (unsigned int)obj.size()); diff -r d6209903454b -r 16a420432aa3 src/board.h --- a/src/board.h Sun Jun 28 08:48:25 2015 +0300 +++ b/src/board.h Sun Jun 28 23:04:37 2015 +0300 @@ -5,16 +5,33 @@ #include "object.h" #include "image.h" -#define NUM_SLOTS 24 -#define MAX_PUCKS 30 +#define NUM_SLOTS 20 +#define PLAYER_PIECES 15 +#define MAX_PIECES (PLAYER_PIECES * 2) -enum { EMPTY = 0, MINE, OTHER }; +enum { MINE, OTHER }; + +class Piece { +private: + int prev_slot, prev_level; + unsigned long move_start; + +public: + int owner, slot, level; + + Piece(); + + void move_to(int slot, int level, bool anim = true); +}; + class Board { private: - int slots[NUM_SLOTS][MAX_PUCKS]; + Piece pieces[MAX_PIECES]; + int hist[NUM_SLOTS + 1]; + std::vector obj; - Object *puck_obj; + Object *piece_obj; Image img_wood, img_field, img_hinge; @@ -29,6 +46,12 @@ void destroy(); void clear(); + void setup(); + + int slot_pieces(int slot) const; + bool move_piece(int id, int slot, bool anim = true); + + Vector3 piece_pos(int slot, int level = 0) const; void draw() const; }; diff -r d6209903454b -r 16a420432aa3 src/game.cc --- a/src/game.cc Sun Jun 28 08:48:25 2015 +0300 +++ b/src/game.cc Sun Jun 28 23:04:37 2015 +0300 @@ -8,6 +8,7 @@ static void draw_backdrop(); int win_width, win_height; +unsigned long cur_time; unsigned int sdr_phong, sdr_phong_notex; bool wireframe; @@ -52,6 +53,7 @@ if(!board.init()) { return false; } + board.setup(); if(!init_scenery()) { return false; @@ -68,6 +70,7 @@ void game_update(unsigned long time_msec) { + cur_time = time_msec; } void game_display() diff -r d6209903454b -r 16a420432aa3 src/game.h --- a/src/game.h Sun Jun 28 08:48:25 2015 +0300 +++ b/src/game.h Sun Jun 28 23:04:37 2015 +0300 @@ -3,6 +3,7 @@ extern int win_width, win_height; extern unsigned int sdr_phong, sdr_phong_notex; +extern unsigned long cur_time; extern bool wireframe; diff -r d6209903454b -r 16a420432aa3 src/main.cc --- a/src/main.cc Sun Jun 28 08:48:25 2015 +0300 +++ b/src/main.cc Sun Jun 28 23:04:37 2015 +0300 @@ -8,6 +8,7 @@ #include #endif #include "game.h" +#include "opt.h" static void display(); static void reshape(int x, int y); @@ -19,10 +20,19 @@ int main(int argc, char **argv) { glutInit(&argc, argv); - glutInitWindowSize(1280, 800); + + if(!init_options(argc, argv)) { + return 1; + } + + glutInitWindowSize(opt.xres, opt.yres); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE); glutCreateWindow("Tavli"); + if(opt.fullscreen) { + glutFullScreen(); + } + glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keypress); diff -r d6209903454b -r 16a420432aa3 src/opt.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opt.cc Sun Jun 28 23:04:37 2015 +0300 @@ -0,0 +1,19 @@ +#include +#include "opt.h" + +Options opt; + +bool init_options(int argc, char **argv) +{ + // TODO read config files, parse args, etc... + + opt.xres = 1280; + opt.yres = 800; + opt.fullscreen = false; + opt.def_username = opt.saved_passwd = 0; + + opt.piece_color[0] = v3_cons(0.3, 0.35, 0.6); + opt.piece_color[1] = v3_cons(1.0, 0.75, 0.5); + + return true; +} diff -r d6209903454b -r 16a420432aa3 src/opt.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opt.h Sun Jun 28 23:04:37 2015 +0300 @@ -0,0 +1,19 @@ +#ifndef OPT_H_ +#define OPT_H_ + +#include "vmath/vmath.h" + +struct Options { + int xres, yres; + bool fullscreen; + + char *def_username, *saved_passwd; + + vec3_t piece_color[2]; +}; + +extern Options opt; + +bool init_options(int argc, char **argv); + +#endif /* OPT_H_ */