ソースを参照

Added time and switched to fixed real numbers for drawing walls

Florian DORMONT 11 年 前
コミット
5430ef9bb4
共有11 個のファイルを変更した317 個の追加64 個の削除を含む
  1. 12 12
      AddinInfo.txt
  2. 2 2
      FXSH_Build.bat
  3. 36 21
      draw_states.c
  4. 0 2
      draw_states.h
  5. 198 0
      fixed.c
  6. 33 0
      fixed.h
  7. 1 2
      hexagon.g1w
  8. 1 0
      init_states.c
  9. 1 0
      struct.h
  10. 2 0
      update_states.c
  11. 31 25
      wall.c

+ 12 - 12
AddinInfo.txt

@@ -1,12 +1,12 @@
-//------------------------------------------------------------------
-// Addin-Application header control file, created with the CASIO SDK
-//------------------------------------------------------------------
-[OUTPUT]     : "HEXAGON.G1A"
-[BINDATA]    : "FXADDINror.bin"
-[DISPNAME]   : "hexagon"
-[APPNAME]    : "@HEXAGON"
-[VERSION]    : "01.00.0000"
-[APL_ICON]   : "MainIcon.bmp"
-[MODULE_NUM] : 0
-[MOD1_TITLE] : "hexagon"
-[MOD1_ICON]  : "eActivityIcon.bmp"
+//------------------------------------------------------------------
+// Addin-Application header control file, created with the CASIO SDK
+//------------------------------------------------------------------
+[OUTPUT]     : "HEXAGON.G1A"
+[BINDATA]    : "FXADDINror.bin"
+[DISPNAME]   : "hexagon"
+[APPNAME]    : "@HEXAGON"
+[VERSION]    : "01.00.0000"
+[APL_ICON]   : "MainIcon.bmp"
+[MODULE_NUM] : 0
+[MOD1_TITLE] : "hexagon"
+[MOD1_ICON]  : "eActivityIcon.bmp"

+ 2 - 2
FXSH_Build.bat

@@ -6,11 +6,11 @@ if exist HEXAGON.G1A  del HEXAGON.G1A
 
 
 cd debug
 cd debug
 if exist FXADDINror.bin  del FXADDINror.bin
 if exist FXADDINror.bin  del FXADDINror.bin
-"C:\CASIO\fx-9860G_SDK\OS\SH\Bin\Hmake.exe" Addin.mak
+"C:\CASIO\fx-9860G SDK\OS\SH\Bin\Hmake.exe" Addin.mak
 cd ..
 cd ..
 if not exist debug\FXADDINror.bin  goto error
 if not exist debug\FXADDINror.bin  goto error
 
 
-"C:\CASIO\fx-9860G_SDK\Tools\MakeAddinHeader363.exe" "Z:\home\eiyeron\Programming\Casio\Super-Hexagon-Casio"
+"C:\CASIO\fx-9860G SDK\Tools\MakeAddinHeader363.exe" "C:\users\eiyeron\My Documents\Programming\SDK\fxsdk\Super-Hexagon-Casio"
 if not exist HEXAGON.G1A  goto error
 if not exist HEXAGON.G1A  goto error
 echo Build has completed.
 echo Build has completed.
 goto end
 goto end

+ 36 - 21
draw_states.c

@@ -1,12 +1,21 @@
 #include "draw_states.h"
 #include "draw_states.h"
+#include "fxlib.h"
+#include <stdio.h>
+// static functions
+static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition);
+static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition);
+static void drawHud(Game_Data *data);
+
+
 void draw_game(Game_Data *data)
 void draw_game(Game_Data *data)
 {
 {
 	//draw the player and the lines
 	//draw the player and the lines
-    drawPlayer(&(data->cam), data->player_angle, data->nb_lines, data->line_transition);
-    drawDiagonals(data->cam, data->nb_lines, data->line_transition);
+	drawPlayer(&(data->cam), data->player_angle, data->nb_lines, data->line_transition);
+	drawDiagonals(data->cam, data->nb_lines, data->line_transition);
+	drawHud(data);
     	//showing the walls
     	//showing the walls
-    if(data->list != NULL)
-	drawWalls(data->list, &(data->cam), data->nb_lines, data->line_transition);
+	if(data->list != NULL)
+		drawWalls(data->list, &(data->cam), data->nb_lines, data->line_transition);
 }
 }
 void draw_title(Game_Data *data)
 void draw_title(Game_Data *data)
 {
 {
@@ -21,11 +30,17 @@ void draw_game_over(Game_Data *data)
 
 
 }
 }
 
 
+static void drawHud(Game_Data *data) {
+	unsigned char time_text[8] = "";
+	sprintf(time_text, "%.2f", data->chrono_time);
+	PrintMini(0, 0, time_text, MINI_REV);
+}
+
 //draws the player
 //draws the player
 //at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
 //at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
 //but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
 //but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
 //there is still for code to calculate the vertices of the hexagon, in case we want to change that again
 //there is still for code to calculate the vertices of the hexagon, in case we want to change that again
-void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition)
+static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition)
 {
 {
 	int x[32];
 	int x[32];
 	int y[32];
 	int y[32];
@@ -52,20 +67,20 @@ void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition lin
 		switch(line_transition.delta_nb_lines)
 		switch(line_transition.delta_nb_lines)
 		{
 		{
 			case 0:
 			case 0:
-				tmp_angle += delta_angle;
-				break;
+			tmp_angle += delta_angle;
+			break;
 			case 1:
 			case 1:
-				if(i < nb_lines)
-					tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
-				else
-					tmp_angle += delta_angle - transition_angle;
-				break;
+			if(i < nb_lines)
+				tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
+			else
+				tmp_angle += delta_angle - transition_angle;
+			break;
 			case -1:
 			case -1:
-				if(i < nb_lines)
-					tmp_angle += (360 - transition_angle) / (nb_lines - 1);
-				else
-					tmp_angle = transition_angle;
-				break;
+			if(i < nb_lines)
+				tmp_angle += (360 - transition_angle) / (nb_lines - 1);
+			else
+				tmp_angle = transition_angle;
+			break;
 		}
 		}
 	}while(i <= nb_lines);
 	}while(i <= nb_lines);
 
 
@@ -78,7 +93,7 @@ void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition lin
 }
 }
 
 
 //draws one of the three rotating lines
 //draws one of the three rotating lines
-void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
+static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
 {
 {
 	int tmp_angle = cam.angle;
 	int tmp_angle = cam.angle;
 	float tmp_angle_rad = 0.0f;
 	float tmp_angle_rad = 0.0f;
@@ -111,11 +126,11 @@ void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
 		i++;
 		i++;
 
 
 		switch(line_transition.delta_nb_lines){
 		switch(line_transition.delta_nb_lines){
-		case 0:
+			case 0:
 			tmp_angle += 360/nb_lines;
 			tmp_angle += 360/nb_lines;
 			break;
 			break;
 
 
-		case 1:
+			case 1:
 			if(i < nb_lines - 1)
 			if(i < nb_lines - 1)
 			{
 			{
 				tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
 				tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
@@ -124,7 +139,7 @@ void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
 			}
 			}
 			break;
 			break;
 
 
-		case -1:
+			case -1:
 			if(i < nb_lines - 1)
 			if(i < nb_lines - 1)
 			{
 			{
 				tmp_angle += (360 - transition_angle) / (nb_lines - 1);
 				tmp_angle += (360 - transition_angle) / (nb_lines - 1);

+ 0 - 2
draw_states.h

@@ -9,6 +9,4 @@ void draw_title(Game_Data *data);
 void draw_menu(Game_Data *data);
 void draw_menu(Game_Data *data);
 void draw_game_over(Game_Data *data);
 void draw_game_over(Game_Data *data);
 
 
-void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition);
-void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition);
 #endif
 #endif

+ 198 - 0
fixed.c

@@ -0,0 +1,198 @@
+#include <fixed.h>
+
+char* fixtostr (fix f, char* string) {
+	int n;
+	int  i;
+	int  cpt;
+	int start = 0;
+	n = UNFIX(f);  	
+	
+	if (n<0) {
+		start=1;
+		string[0] = '-';
+		n *= -1;
+	}
+	for (i = 1, cpt = 1; n / i >= 10; i *= 10, cpt++);
+	for (cpt = start; i; cpt++, i /= 10) string[cpt] = (n / i) % 10 + '0';
+	string[cpt] = '\0';
+	return string;
+}
+
+fix ftofix(float f) {
+	return f*(1<<DB);
+}
+
+float fixtof(fix f) {
+	return ((float)f)/(1<<DB);
+}
+
+fix fdiv(fix x, fix y) {
+	if (y>(1<<(2*DB-2))) return x/(y>>DB);
+	return fmul(x, ((1<<(2*DB))/y));
+	// return mult(x, (0x40000000/y)>>(30-2*precision));
+}
+
+fix fmul(fix x, fix y) {
+	int d1, d2, e1, e2;
+	e1 = x >> DB;
+	e2 = y >> DB;
+	d1 = x & (0xFFFFFFFF>>(32-DB));
+	d2 = y & (0xFFFFFFFF>>(32-DB));
+	return ((e1*e2)<<DB) + e1*d2 + e2*d1 + ((d1*d2)>>DB);
+}
+
+
+// Precomputed table of sinus value, between 0 and 90° inclued with step of 0.1°.
+// Values are in fixed 30 bits of decimal.
+int precalc_sin[901] = {
+	0,			1874032,	3748058,	5622073,	7496071,	9370046,	11243993,
+	13117905,	14991777,	16865604,	18739378,	20613096,	22486752,	24360338,
+	26233852,	28107284,	29980632,	31853888,	33727044,	35600100,	37473048,
+	39345884,	41218596,	43091184,	44963640,	46835960,	48708136,	50580168,
+	52452040,	54323756,	56195304,	58066684,	59937884,	61808904,	63679732,
+	65550372,	67420808,	69291040,	71161056,	73030864,	74900440,	76769800,
+	78638912,	80507792,	82376432,	84244816,	86112936,	87980800,	89848400,
+	91715720,	93582768,	95449528,	97315992,	99182160,	101048032,	102913592,
+	104778840,	106643768,	108508376,	110372648,	112236584,	114100176,	115963424,
+	117826320,	119688856,	121551024,	123412824,	125274248,	127135296,	128995952,
+	130856208,	132716072,	134575536,	136434592,	138293216,	140151424,	142009216,
+	143866576,	145723488,	147579952,	149435984,	151291552,	153146656,	155001296,
+	156855456,	158709152,	160562352,	162415072,	164267296,	166119008,	167970224,
+	169820928,	171671120,	173520784,	175369920,	177218512,	179066576,	180914096,
+	182761056,	184607472,	186453312,	188298592,	190143296,	191987424,	193830960,
+	195673904,	197516256,	199358016,	201199152,	203039680,	204879600,	206718880,
+	208557552,	210395568,	212232960,	214069696,	215905776,	217741200,	219575968,
+	221410064,	223243472,	225076224,	226908272,	228739632,	230570304,	232400272,
+	234229520,	236058064,	237885888,	239712992,	241539360,	243364992,	245189872,
+	247014032,	248837424,	250660048,	252481920,	254303024,	256123344,	257942896,
+	259761664,	261579632,	263396800,	265213168,	267028736,	268843488,	270657408,
+	272470528,	274282784,	276094240,	277904832,	279714592,	281523488,	283331520,
+	285138720,	286945024,	288750464,	290555008,	292358688,	294161472,	295963360,
+	297764352,	299564416,	301363584,	303161824,	304959168,	306755552,	308551008,
+	310345536,	312139104,	313931712,	315723392,	317514112,	319303840,	321092608,
+	322880384,	324667200,	326453024,	328237824,	330021664,	331804480,	333586272,
+	335367072,	337146848,	338925568,	340703296,	342479936,	344255584,	346030144,
+	347803680,	349576160,	351347552,	353117888,	354887136,	356655296,	358422400,
+	360188384,	361953280,	363717088,	365479744,	367241344,	369001792,	370761120,
+	372519328,	374276384,	376032320,	377787104,	379540736,	381293184,	383044512,
+	384794656,	386543616,	388291424,	390038048,	391783456,	393527680,	395270720,
+	397012544,	398753184,	400492576,	402230752,	403967712,	405703456,	407437952,
+	409171200,	410903200,	412633952,	414363456,	416091680,	417818656,	419544352,
+	421268768,	422991904,	424713760,	426434304,	428153568,	429871488,	431588128,
+	433303456,	435017472,	436730144,	438441504,	440151520,	441860192,	443567488,
+	445273472,	446978112,	448681344,	450383232,	452083776,	453782912,	455480672,
+	457177024,	458872000,	460565600,	462257760,	463948544,	465637888,	467325824,
+	469012352,	470697440,	472381088,	474063296,	475744064,	477423392,	479101248,
+	480777664,	482452608,	484126080,	485798080,	487468576,	489137632,	490805152,
+	492471200,	494135744,	495798784,	497460320,	499120352,	500778848,	502435808,
+	504091264,	505745152,	507397536,	509048352,	510697600,	512345312,	513991456,
+	515636064,	517279072,	518920512,	520560352,	522198624,	523835328,	525470400,
+	527103904,	528735776,	530366048,	531994688,	533621728,	535247136,	536870912,
+	538493056,	540113536,	541732416,	543349632,	544965184,	546579072,	548191296,
+	549801856,	551410752,	553017920,	554623424,	556227264,	557829376,	559429824,
+	561028544,	562625600,	564220864,	565814464,	567406336,	568996480,	570584896,
+	572171520,	573756480,	575339648,	576921088,	578500736,	580078656,	581654784,
+	583229120,	584801728,	586372544,	587941504,	589508736,	591074176,	592637824,
+	594199680,	595759680,	597317888,	598874240,	600428800,	601981568,	603532416,
+	605081472,	606628672,	608174080,	609717568,	611259264,	612799040,	614336960,
+	615873024,	617407168,	618939456,	620469888,	621998400,	623525056,	625049792,
+	626572608,	628093504,	629612544,	631129600,	632644800,	634158016,	635669312,
+	637178688,	638686080,	640191616,	641695104,	643196672,	644696320,	646193984,
+	647689664,	649183360,	650675072,	652164864,	653652608,	655138368,	656622144,
+	658103936,	659583680,	661061504,	662537216,	664010944,	665482688,	666952320,
+	668420032,	669885632,	671349184,	672810688,	674270208,	675727616,	677182976,
+	678636288,	680087552,	681536704,	682983808,	684428800,	685871744,	687312576,
+	688751296,	690187968,	691622464,	693054912,	694485248,	695913472,	697339520,
+	698763520,	700185344,	701605056,	703022592,	704438016,	705851264,	707262400,
+	708671424,	710078208,	711482880,	712885312,	714285632,	715683776,	717079744,
+	718473536,	719865088,	721254464,	722641664,	724026688,	725409472,	726790016,
+	728168384,	729544576,	730918464,	732290176,	733659648,	735026880,	736391872,
+	737754624,	739115072,	740473344,	741829312,	743183104,	744534528,	745883776,
+	747230656,	748575360,	749917696,	751257792,	752595584,	753931072,	755264320,
+	756595200,	757923840,	759250112,	760574080,	761895808,	763215104,	764532160,
+	765846848,	767159168,	768469248,	769776896,	771082240,	772385216,	773685888,
+	774984128,	776280064,	777573632,	778864832,	780153600,	781440064,	782724096,
+	784005760,	785285056,	786561920,	787836416,	789108544,	790378240,	791645504,
+	792910400,	794172864,	795432896,	796690496,	797945664,	799198464,	800448768,
+	801696640,	802942080,	804185088,	805425600,	806663744,	807899328,	809132544,
+	810363264,	811591488,	812817280,	814040576,	815261376,	816479680,	817695552,
+	818908864,	820119744,	821328128,	822533952,	823737280,	824938176,	826136512,
+	827332288,	828525568,	829716352,	830904576,	832090304,	833273472,	834454144,
+	835632192,	836807744,	837980800,	839151232,	840319104,	841484416,	842647232,
+	843807424,	844965056,	846120128,	847272576,	848422464,	849569792,	850714496,
+	851856640,	852996224,	854133120,	855267456,	856399232,	857528320,	858654848,
+	859778752,	860900032,	862018688,	863134720,	864248128,	865358912,	866467008,
+	867572544,	868675392,	869775616,	870873152,	871968064,	873060288,	874149888,
+	875236800,	876321088,	877402624,	878481600,	879557824,	880631360,	881702272,
+	882770432,	883835968,	884898752,	885958848,	887016320,	888070976,	889123008,
+	890172288,	891218880,	892262784,	893303936,	894342400,	895378112,	896411072,
+	897441344,	898468864,	899493632,	900515648,	901534976,	902551488,	903565312,
+	904576384,	905584640,	906590208,	907592960,	908593024,	909590208,	910584704,
+	911576384,	912565312,	913551488,	914534848,	915515392,	916493184,	917468160,
+	918440384,	919409792,	920376384,	921340160,	922301184,	923259328,	924214720,
+	925167296,	926116992,	927063936,	928008000,	928949248,	929887680,	930823296,
+	931756032,	932686016,	933613056,	934537344,	935458688,	936377280,	937292928,
+	938205760,	939115776,	940022848,	940927104,	941828544,	942727040,	943622720,
+	944515456,	945405376,	946292352,	947176512,	948057728,	948936128,	949811584,
+	950684160,	951553856,	952420608,	953284480,	954145472,	955003584,	955858752,
+	956710976,	957560320,	958406720,	959250240,	960090816,	960928448,	961763200,
+	962594944,	963423808,	964249792,	965072768,	965892800,	966709888,	967524096,
+	968335296,	969143552,	969948864,	970751232,	971550656,	972347072,	973140608,
+	973931072,	974718656,	975503232,	976284864,	977063488,	977839104,	978611840,
+	979381504,	980148224,	980911936,	981672704,	982430464,	983185216,	983936960,
+	984685760,	985431552,	986174272,	986914048,	987650816,	988384576,	989115328,
+	989843008,	990567744,	991289408,	992008064,	992723776,	993436352,	994145984,
+	994852544,	995556096,	996256576,	996954048,	997648512,	998339904,	999028288,
+	999713600,	1000395840,	1001075072,	1001751232,	1002424320,	1003094400,	1003761408,
+	1004425408,	1005086272,	1005744128,	1006398848,	1007050560,	1007699200,	1008344768,
+	1008987264,	1009626688,	1010263040,	1010896320,	1011526464,	1012153600,	1012777600,
+	1013398528,	1014016384,	1014631168,	1015242816,	1015851392,	1016456896,	1017059264,
+	1017658560,	1018254784,	1018847872,	1019437824,	1020024704,	1020608512,	1021189184,
+	1021766720,	1022341120,	1022912448,	1023480704,	1024045760,	1024607744,	1025166592,
+	1025722304,	1026274944,	1026824384,	1027370752,	1027913984,	1028454080,	1028991040,
+	1029524864,	1030055552,	1030583104,	1031107520,	1031628736,	1032146880,	1032661888,
+	1033173696,	1033682368,	1034187904,	1034690304,	1035189568,	1035685632,	1036178560,
+	1036668352,	1037154944,	1037638400,	1038118720,	1038595840,	1039069824,	1039540608,
+	1040008256,	1040472704,	1040934016,	1041392128,	1041847104,	1042298880,	1042747520,
+	1043192896,	1043635200,	1044074240,	1044510144,	1044942848,	1045372416,	1045798720,
+	1046221888,	1046641856,	1047058624,	1047472256,	1047882624,	1048289856,	1048693888,
+	1049094720,	1049492352,	1049886784,	1050278016,	1050666048,	1051050880,	1051432512,
+	1051810944,	1052186112,	1052558144,	1052926976,	1053292608,	1053654976,	1054014144,
+	1054370112,	1054722880,	1055072448,	1055418816,	1055761920,	1056101824,	1056438528,
+	1056771968,	1057102272,	1057429248,	1057753088,	1058073664,	1058391040,	1058705152,
+	1059016128,	1059323776,	1059628288,	1059929472,	1060227520,	1060522304,	1060813824,
+	1061102144,	1061387200,	1061669056,	1061947712,	1062223104,	1062495232,	1062764160,
+	1063029824,	1063292224,	1063551424,	1063807424,	1064060096,	1064309568,	1064555840,
+	1064798784,	1065038528,	1065275072,	1065508288,	1065738304,	1065965056,	1066188608,
+	1066408896,	1066625856,	1066839680,	1067050176,	1067257472,	1067461440,	1067662208,
+	1067859776,	1068054016,	1068245056,	1068432768,	1068617280,	1068798528,	1068976512,
+	1069151232,	1069322752,	1069490944,	1069655936,	1069817600,	1069976064,	1070131264,
+	1070283200,	1070431808,	1070577216,	1070719360,	1070858240,	1070993856,	1071126272,
+	1071255360,	1071381184,	1071503744,	1071623040,	1071739072,	1071851840,	1071961344,
+	1072067584,	1072170560,	1072270272,	1072366720,	1072459904,	1072549824,	1072636480,
+	1072719872,	1072800000,	1072876800,	1072950400,	1073020672,	1073087744,	1073151488,
+	1073211968,	1073269248,	1073323200,	1073373888,	1073421312,	1073465472,	1073506304,
+	1073543936,	1073578304,	1073609344,	1073637184,	1073661696,	1073682944,	1073700928,
+	1073715648,	1073727104,	1073735296,	1073740160,	1073741824	};
+
+fix fsin(fix a) {
+	int v;
+	if(a<0) v = 3600+UNFIX(a*10)%3600;
+	else v = UNFIX(a*10)%3600;
+	if (v<=900) return precalc_sin[v]>>(30-DB);
+	if (v<=1800) return precalc_sin[1800-v]>>(30-DB);
+	if (v<=2700) return -(precalc_sin[v-1800]>>(30-DB));
+	return -(precalc_sin[3600-v]>>(30-DB));
+}
+
+
+fix fcos(fix a) {
+	return fsin(FIX(90)-a);
+}
+
+
+fix ftan(fix a) {
+	return fdiv(fsin(a), fcos(a));
+}
+//
+

+ 33 - 0
fixed.h

@@ -0,0 +1,33 @@
+#ifndef _FIXED_H
+#define _FIXED_H
+
+// Bit lenght of the decimal part, change it to change the precision :
+#define DB 12
+
+#define MOD(x, y) ((x)<0 ? (y)+(x)%(y) : (x)%(y))
+
+typedef int fix;
+
+
+
+// Fixed point manipulations functions and macros :
+char* fixtostr (fix n, char* string);
+
+fix ftofix(float f);
+
+float fixtof(fix f);
+
+#define FIX(x) ((x)<<DB)
+
+#define UNFIX(x) ((x)>>DB)
+
+fix fdiv(fix x, fix y);
+
+fix fmul(fix x, fix y);
+
+fix fsin(fix a);
+fix fcos(fix a);
+fix ftan(fix a);
+
+
+#endif // _FIXED_H

+ 1 - 2
hexagon.g1w

@@ -20,6 +20,5 @@ SourceFile=:syscall.src
 SourceFile=:update_states.c
 SourceFile=:update_states.c
 SourceFile=:ECode.c
 SourceFile=:ECode.c
 SourceFile=:hexagon.c
 SourceFile=:hexagon.c
-SourceFile=:MonochromeLib.c
-SourceFile=:syscall.src
 SourceFile=:wall.c
 SourceFile=:wall.c
+SourceFile=:fixed.c

+ 1 - 0
init_states.c

@@ -26,6 +26,7 @@ void init_game(Game_Data *data)
 	data->start_time = RTC_GetTicks(); //1 tick == 1/128 second
 	data->start_time = RTC_GetTicks(); //1 tick == 1/128 second
 	data->last_time = 0;
 	data->last_time = 0;
 	data->current_time = RTC_GetTicks();
 	data->current_time = RTC_GetTicks();
+	data->chrono_time = 0;
 
 
 	data->player_angle = 0;
 	data->player_angle = 0;
 
 

+ 1 - 0
struct.h

@@ -87,6 +87,7 @@ struct Game_Data{
 	unsigned int start_time;
 	unsigned int start_time;
 	unsigned int last_time;
 	unsigned int last_time;
 	unsigned int current_time;
 	unsigned int current_time;
+	float chrono_time;
 	int player_angle;
 	int player_angle;
 
 
 	unsigned int nb_lines;
 	unsigned int nb_lines;

+ 2 - 0
update_states.c

@@ -11,6 +11,8 @@ void update_game(Game_Data *data)
 {
 {
 	data->last_time = data->current_time;
 	data->last_time = data->current_time;
 	data->current_time = RTC_GetTicks();
 	data->current_time = RTC_GetTicks();
+	data->chrono_time += (data->current_time - data->last_time)/ 128.;
+
 	if(data->list != NULL){ //if the linked list is not empty
 	if(data->list != NULL){ //if the linked list is not empty
 		updateWalls(data->list, min(data->current_time - data->last_time, 2)); //update the linked list
 		updateWalls(data->list, min(data->current_time - data->last_time, 2)); //update the linked list
 
 

+ 31 - 25
wall.c

@@ -1,4 +1,5 @@
 #include "wall.h"
 #include "wall.h"
+#include "fixed.h"
 
 
 Wall *addWall(Wall *list, int d, int h, int id, int line)
 Wall *addWall(Wall *list, int d, int h, int id, int line)
 {
 {
@@ -83,45 +84,50 @@ void updateWalls(Wall *list, unsigned int delta_time)
 
 
 void drawWalls(Wall *list, Camera *cam, int nb_lines, Line_Transition line_transition)
 void drawWalls(Wall *list, Camera *cam, int nb_lines, Line_Transition line_transition)
 {//NEEDS A COMPLETE REWRITE TO SUPPORT THE LINE TRANSITIONS !
 {//NEEDS A COMPLETE REWRITE TO SUPPORT THE LINE TRANSITIONS !
+	// TODO : Speeed up with more fixed.
 	Wall *tmp;
 	Wall *tmp;
 
 
-
-	float coeff = 0.0;
-	float transition_angle = 0.0;
-	
-	float delta_angle = 360.0 / nb_lines;
-
-	float meh = 0;
-
-	float offset = 0;
+	fix coeff = 0;
+	// float coeff = 0.0;
+	fix transition_angle = 0;
+	// float transition_angle = 0.0;
+	fix delta_angle = fdiv(FIX(360), FIX(nb_lines));
+	// float delta_angle = 360.0 / nb_lines;
+	fix offset = 0;
+	// float offset = 0;
 
 
 	if(line_transition.delta_nb_lines == 1)
 	if(line_transition.delta_nb_lines == 1)
 		nb_lines ++;
 		nb_lines ++;
 
 
 	if(line_transition.counter_start != 0)
 	if(line_transition.counter_start != 0)
-		coeff = (float)line_transition.counter / (float)line_transition.counter_start;
-	transition_angle = delta_angle * coeff;
+		coeff = fdiv(FIX(line_transition.counter), FIX(line_transition.counter_start));
+	// 	coeff = (float)line_transition.counter / (float)line_transition.counter_start;
+	transition_angle = fmul(delta_angle, coeff);
+	// transition_angle = delta_angle * coeff;
 
 
-	offset = (delta_angle - transition_angle) * line_transition.delta_nb_lines/(float)nb_lines;
+	offset = fdiv(fmul((delta_angle - transition_angle), FIX(line_transition.delta_nb_lines)), FIX(nb_lines));
+	// offset = (delta_angle - transition_angle) * line_transition.delta_nb_lines/(float)nb_lines;
 
 
 	tmp = list;
 	tmp = list;
 	do{
 	do{
 		if(tmp != NULL)
 		if(tmp != NULL)
 		{
 		{
-			if(tmp->d + tmp->h< 64)
+			if(tmp->d + tmp->h < 128)
 			{
 			{
-				const float angle =  ((delta_angle - offset) * tmp->line + cam->angle) * PI / 180.;
-				const float cos1 = cos(angle);
-				const float cos2 = cos(angle +  (delta_angle - offset) * (PI / 180.));
-				const float sin1 = sin(angle);
-				const float sin2 = sin(angle + (delta_angle - offset) * (PI / 180.));
-
-				int i,j, x, y;
-
-				float dist = tmp->d + cam->zoom;
-				for(i = 0; i < tmp->h && dist > 8; ++i) {
-					ML_line(64 + dist*cos1, 32 + dist*sin1, 64 + dist*cos2, 32 + dist*sin2, BLACK);
-					--dist;
+				const fix delta_angle_minus_offset = delta_angle - offset;
+				const fix angle =  fmul(delta_angle_minus_offset, FIX(tmp->line)) + FIX(cam->angle);
+				// const float angle = ((delta_angle - offset) * tmp->line + cam->angle) * PI / 180.;
+				const fix cos1 = fcos(angle);
+				const fix cos2 = fcos(angle + delta_angle_minus_offset);
+				const fix sin1 = fsin(angle);
+				const fix sin2 = fsin(angle + delta_angle_minus_offset);
+				int i;
+
+				fix dist = ftofix(tmp->d + cam->zoom);
+				// float dist = tmp->d + cam->zoom;
+				for(i = 0; i < tmp->h && dist > FIX(8); ++i) {
+					ML_line(64 + fixtof(fmul(dist, cos1)), 32 + fixtof(fmul(dist,sin1)), 64 + fixtof(fmul(dist, cos2)), 32 + fixtof(fmul(dist, sin2)), BLACK);
+					dist -= FIX(1);
 				}
 				}
 			}
 			}
 		}
 		}