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