Free obj
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
|
|
||||||
extern struct games_state globalR;
|
extern struct games_state globalR;
|
||||||
void gamesiterate(struct games_state *rs);
|
void *gamesiterate(struct games_state *rs);
|
||||||
|
|
||||||
char USERPASS[8192]; uint16_t GAMES_PORT;
|
char USERPASS[8192]; uint16_t GAMES_PORT;
|
||||||
char Gametxidstr[67];
|
char Gametxidstr[67];
|
||||||
@@ -866,7 +866,7 @@ void games_bailout(struct games_state *rs)
|
|||||||
|
|
||||||
int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis)
|
int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct games_player *player,int32_t sleepmillis)
|
||||||
{
|
{
|
||||||
struct games_state *rs; FILE *fp; int32_t i,n;
|
struct games_state *rs; FILE *fp; int32_t i,n; void *ptr;
|
||||||
rs = (struct games_state *)calloc(1,sizeof(*rs));
|
rs = (struct games_state *)calloc(1,sizeof(*rs));
|
||||||
rs->seed = seed;
|
rs->seed = seed;
|
||||||
rs->keystrokes = keystrokes;
|
rs->keystrokes = keystrokes;
|
||||||
@@ -882,7 +882,7 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
|
|||||||
}
|
}
|
||||||
globalR = *rs;
|
globalR = *rs;
|
||||||
uint32_t starttime = (uint32_t)time(NULL);
|
uint32_t starttime = (uint32_t)time(NULL);
|
||||||
gamesiterate(rs);
|
ptr = gamesiterate(rs);
|
||||||
if ( 0 )
|
if ( 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime);
|
fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime);
|
||||||
@@ -909,8 +909,13 @@ int32_t games_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
|
|||||||
if ( newdata != 0 && rs->playersize > 0 )
|
if ( newdata != 0 && rs->playersize > 0 )
|
||||||
memcpy(newdata,rs->playerdata,rs->playersize);
|
memcpy(newdata,rs->playerdata,rs->playersize);
|
||||||
}*/
|
}*/
|
||||||
if ( newdata != 0 && rs->playersize > 0 )
|
if ( ptr != 0 )
|
||||||
memcpy(newdata,rs->playerdata,rs->playersize);
|
{
|
||||||
|
// extract data from ptr
|
||||||
|
if ( newdata != 0 && rs->playersize > 0 )
|
||||||
|
memcpy(newdata,rs->playerdata,rs->playersize);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
n = rs->playersize;
|
n = rs->playersize;
|
||||||
free(rs);
|
free(rs);
|
||||||
return(n);
|
return(n);
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols)
|
|||||||
// Initialization logic
|
// Initialization logic
|
||||||
obj->rows = rows;
|
obj->rows = rows;
|
||||||
obj->cols = cols;
|
obj->cols = cols;
|
||||||
obj->board = (char *)malloc(rows * cols);
|
//obj->board = (char *)malloc(rows * cols);
|
||||||
memset(obj->board, TC_EMPTY, rows * cols);
|
memset(obj->board, TC_EMPTY, rows * cols);
|
||||||
obj->points = 0;
|
obj->points = 0;
|
||||||
obj->level = 0;
|
obj->level = 0;
|
||||||
@@ -454,19 +454,19 @@ void tg_init(struct games_state *rs,tetris_game *obj, int rows, int cols)
|
|||||||
|
|
||||||
tetris_game *tg_create(struct games_state *rs,int rows, int cols)
|
tetris_game *tg_create(struct games_state *rs,int rows, int cols)
|
||||||
{
|
{
|
||||||
tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game));
|
tetris_game *obj = (tetris_game *)malloc(sizeof(tetris_game) + rows*cols);
|
||||||
tg_init(rs,obj, rows, cols);
|
tg_init(rs,obj, rows, cols);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tg_destroy(tetris_game *obj)
|
/*void tg_destroy(tetris_game *obj)
|
||||||
{
|
{
|
||||||
// Cleanup logic
|
// Cleanup logic
|
||||||
free(obj->board);
|
free(obj->board);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void tg_delete(tetris_game *obj) {
|
void tg_delete(tetris_game *obj) {
|
||||||
tg_destroy(obj);
|
//tg_destroy(obj);
|
||||||
free(obj);
|
free(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +591,7 @@ void display_score(WINDOW *w, tetris_game *tg)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Save and exit the game.
|
Save and exit the game.
|
||||||
*/
|
|
||||||
void save(tetris_game *game, WINDOW *w)
|
void save(tetris_game *game, WINDOW *w)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@@ -614,7 +614,7 @@ void save(tetris_game *game, WINDOW *w)
|
|||||||
fprintf(stderr,"Game saved to \"tetris.save\".\n");
|
fprintf(stderr,"Game saved to \"tetris.save\".\n");
|
||||||
fprintf(stderr,"Resume by passing the filename as an argument to this program.\n");
|
fprintf(stderr,"Resume by passing the filename as an argument to this program.\n");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do the NCURSES initialization steps for color blocks.
|
Do the NCURSES initialization steps for color blocks.
|
||||||
@@ -685,7 +685,7 @@ char *clonestr(char *str)
|
|||||||
|
|
||||||
struct games_state globalR;
|
struct games_state globalR;
|
||||||
|
|
||||||
void gamesiterate(struct games_state *rs)
|
void *gamesiterate(struct games_state *rs)
|
||||||
{
|
{
|
||||||
uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE;
|
uint32_t counter = 0; bool running = true; tetris_move move = TM_NONE;
|
||||||
int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg;
|
int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg;
|
||||||
@@ -771,12 +771,13 @@ void gamesiterate(struct games_state *rs)
|
|||||||
move = TM_NONE;
|
move = TM_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return(tg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tetris(int argc, char **argv)
|
int tetris(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct games_state *rs = &globalR;
|
struct games_state *rs = &globalR;
|
||||||
int32_t c,skipcount=0; uint32_t eventid = 0;
|
int32_t c,skipcount=0; uint32_t eventid = 0; tetris_game *tg = 0;
|
||||||
memset(rs,0,sizeof(*rs));
|
memset(rs,0,sizeof(*rs));
|
||||||
rs->guiflag = 1;
|
rs->guiflag = 1;
|
||||||
rs->sleeptime = 1; // non-zero to allow refresh()
|
rs->sleeptime = 1; // non-zero to allow refresh()
|
||||||
@@ -824,7 +825,7 @@ int tetris(int argc, char **argv)
|
|||||||
init_colors(); // setup tetris colors
|
init_colors(); // setup tetris colors
|
||||||
|
|
||||||
// Game loop
|
// Game loop
|
||||||
gamesiterate(rs);
|
tg = gamesiterate(rs);
|
||||||
games_bailout(rs);
|
games_bailout(rs);
|
||||||
// Deinitialize NCurses
|
// Deinitialize NCurses
|
||||||
wclear(stdscr);
|
wclear(stdscr);
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
int rows;
|
int rows;
|
||||||
int cols;
|
int cols;
|
||||||
char *board;
|
|
||||||
/*
|
/*
|
||||||
Scoring information:
|
Scoring information:
|
||||||
*/
|
*/
|
||||||
@@ -118,6 +117,7 @@ typedef struct {
|
|||||||
Number of lines until you advance to the next level.
|
Number of lines until you advance to the next level.
|
||||||
*/
|
*/
|
||||||
int lines_remaining;
|
int lines_remaining;
|
||||||
|
char board[];
|
||||||
} tetris_game;
|
} tetris_game;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user