Permalink
Browse files

Transitions and more.

Added SDL_Surface debug print function.
Removed unneeded gl calls.
Lists: Fixed memory-leak in removeItem. Added fast-append and fast remove functions.
Makefile.linux updated so settings is saved in ./ unless DATADIR is
specified.
Removed useless calls.
Fixed compile warning in lits.c
Added transitions between menu/game screens.
Minor optimization of particle-system removal.
  • Loading branch information...
DusteDdk committed Aug 20, 2012
1 parent c1101db commit e42e0786485e2683632064977dd4ace12b0a7850
Showing with 370 additions and 27 deletions.
  1. +4 −1 Makefile.linux
  2. +0 −1 credits.c
  3. +9 −0 game.c
  4. +2 −0 leveleditor.c
  5. +24 −1 list.c
  6. +11 −2 list.h
  7. +8 −3 main.c
  8. +54 −16 menu.c
  9. +4 −1 particle.c
  10. +66 −0 pixel.c
  11. +3 −0 pixel.h
  12. +1 −2 platform/pc.c
  13. +144 −0 transition.c
  14. +36 −0 transition.h
  15. +4 −0 wizznic.cbp
View
@@ -17,7 +17,9 @@ DEFS = -DDATADIR="\"$(DATADIR)\""
#Add the PER_USER_FILES define if the DATADIR is set
ifneq ($(DATADIR),)
+ ifneq ($(DATADIR),"./")
DEFS +=-DPER_USER_FILES
+ endif
endif
ifneq ($(BUILD_NUMBER),)
@@ -38,7 +40,8 @@ endif
OBJS = dumplevelimages.o board.o cursor.o draw.o input.o main.o menu.o sprite.o\
text.o ticks.o sound.o game.o player.o list.o levels.o pixel.o stars.o\
levelselector.o leveleditor.o particle.o pack.o settings.o stats.o strings.o\
-mbrowse.o teleport.o credits.o waveimg.o userfiles.o swscale.o platform/pc.o pointer.o
+mbrowse.o teleport.o credits.o waveimg.o userfiles.o swscale.o platform/pc.o\
+pointer.o transition.o
MYCC = $(CC) $(CFLAGS) $(INCS) $(DEFS)
View
@@ -154,7 +154,6 @@ void clearCredits()
freeMsg(cm);
}
freeList(msgList);
- clearParticles();
}
View
9 game.c
@@ -19,6 +19,7 @@
#include "strings.h"
#include "settings.h"
#include "defs.h"
+#include "transition.h"
static playField pf;
static cursorType cur;
@@ -165,6 +166,9 @@ int runGame(SDL_Surface* screen)
//Pause ?
if( getButton( C_BTNMENU ) || isPointerEscapeClicked() )
{
+
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN,500);
+
restartConfirm=0;
resetBtn( C_BTNMENU );
if(player()->inEditor)
@@ -240,6 +244,7 @@ int runGame(SDL_Surface* screen)
timeBeforeRestart=pf.levelInfo->time;
spentTimeBeforeRestart=player()->hsEntry.time;
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_DISSOLVE, 2500);
initGame(screen);
if(!player()->inEditor)
{
@@ -424,6 +429,7 @@ int runGame(SDL_Surface* screen)
}
}
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
} else if(ret > 0) //Player destroyed bricks.
@@ -554,6 +560,7 @@ int runGame(SDL_Surface* screen)
player()->hsEntry.score=0;
//Goto cleanup, then menu
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
}
@@ -597,6 +604,7 @@ int runGame(SDL_Surface* screen)
player()->hsEntry.score=0;
//Goto cleanup, then menu
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
}
@@ -652,6 +660,7 @@ int runGame(SDL_Surface* screen)
resetBtn(C_BTNB);
resetMouseBtn();
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
View
@@ -30,6 +30,7 @@
#include "strings.h"
#include "teleport.h"
+#include "transition.h"
#include "defs.h"
#define EDITOR_MAIN 0
@@ -150,6 +151,7 @@ int runEditor(SDL_Surface* screen)
{
resetMouseBtn();
editorCleanUp();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 500 );
return(STATEMENU);
}
}
View
25 list.c
@@ -17,6 +17,7 @@
#include "list.h"
#include <stdlib.h>
+#include <stdio.h>
void listAddData(listItem* start, void* data)
{
@@ -38,7 +39,21 @@ void listAddData(listItem* start, void* data)
}
-//Inserts into the list at pos p. 0 = first
+listItem* listAppendData(listItem* item, void* data)
+{
+ listItem *tt;
+ if(item->next)
+ {
+ printf("listAppendData ERROR: item %p is not the last item in the list.\n", item);
+ return( (listItem*)0 );
+ }
+ tt=malloc(sizeof(listItem));
+ tt->data=data;
+ tt->next=0;
+ item->next=tt;
+ return(tt);
+}
+
void listInsertData(listItem* start, void* data, int p)
{
int pos=0;
@@ -74,6 +89,7 @@ listItem* listRemoveItem(listItem* start, listItem* item)
if(l->next)
{
prev->next=l->next;
+ free(item);
} else {
prev->next=0;
}
@@ -84,6 +100,13 @@ listItem* listRemoveItem(listItem* start, listItem* item)
return(0);
}
+listItem* cutItem(listItem* previous, listItem* removeMe )
+{
+ previous->next=removeMe->next;
+ free(removeMe);
+ return(previous->next);
+}
+
listItem* initList()
{
listItem* ptr = malloc(sizeof(listItem));
View
13 list.h
@@ -26,10 +26,19 @@ struct listItemStruct
typedef struct listItemStruct listItem;
+//Add data to the end of a list
void listAddData(listItem* start, void* data);
-void listInsertData(listItem* start, void* data, int p); //Inserts into the list at pos p. 0 = first
-listItem* listRemoveItem(listItem* start, listItem* item); //Removes item from list, returns item just before removed item.
+//Fast, appends a new item containing data to a listitem.
+listItem* listAppendData(listItem* item, void* data);
+
+
+//Inserts into the list at pos p. 0 = first
+void listInsertData(listItem* start, void* data, int p);
+
+listItem* listRemoveItem(listItem* start, listItem* item); //Removes item from list, returns item just before removed item. (or 0)
+listItem* cutItem(listItem* previous, listItem* removeMe ); //Given previous item, removes item, returns next item (or 0)
+
listItem* initList();
void freeList(listItem* start);
int listSize(listItem* start);
View
11 main.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
@@ -42,6 +43,7 @@
#include "strings.h"
#include "swscale.h"
#include "pointer.h"
+#include "transition.h"
#ifdef PC
#include "dumplevelimages.h"
@@ -225,6 +227,8 @@ int main(int argc, char *argv[])
//Init particles
initParticles(screen);
+ srand( (int)time(NULL) );
+
#if defined(PC)
//Need to dump level-screenshots?
if(doDump)
@@ -265,14 +269,15 @@ int main(int argc, char *argv[])
//Initialize credits
initCredits(screen);
+ initTransition();
+
int lastTick;
while(state!=STATEQUIT)
{
lastTick=SDL_GetTicks();
frameStart();
if(runControls()) state=STATEQUIT;
-
switch(state)
{
case STATEPLAY:
@@ -292,6 +297,8 @@ int main(int argc, char *argv[])
soundRun(screen,state);
+ runTransition(screen);
+
if(setting()->showFps)
drawFPS(screen);
@@ -327,14 +334,12 @@ int main(int argc, char *argv[])
#endif
}
-
#if defined(PLATFORM_NEEDS_EXIT)
platformExit();
#endif
SDL_Quit();
- //Not even trying to clean up, OS should do that anyway..
return(0);
}
Oops, something went wrong.

0 comments on commit e42e078

Please sign in to comment.