# Copyright (C) 2007 Peter De Wachter <pdewacht@gmail.com>
# Distributed under the same license as the game. See debian/copyright.
Sat Aug 25 23:59:12 CEST 2007 pdewacht@gmail.com
* 06_d_language_changes
--- a/src/abagames/a7xpg/A7xBoot.d
+++ b/src/abagames/a7xpg/A7xBoot.d
@@ -5,13 +5,15 @@
*/
module abagames.a7xpg.A7xBoot;
-import string;
+import std.string;
+import std.c.stdlib: exit, EXIT_SUCCESS, EXIT_FAILURE;
import abagames.a7xpg.A7xScreen;
import abagames.a7xpg.A7xGameManager;
import abagames.a7xpg.A7xPrefManager;
import abagames.util.Logger;
import abagames.util.sdl.Input;
import abagames.util.sdl.MainLoop;
+import abagames.util.sdl.Sound;
/**
* Boot A7Xpg.
@@ -37,7 +39,7 @@
exit(EXIT_FAILURE);
}
i++;
- float b = (float) atoi(args[i]) / 100;
+ float b = cast(float) atoi(args[i]) / 100;
if (b < 0 || b > 1) {
usage();
exit(EXIT_FAILURE);
@@ -50,7 +52,7 @@
exit(EXIT_FAILURE);
}
i++;
- float l = (float) atoi(args[i]) / 100;
+ float l = cast(float) atoi(args[i]) / 100;
if (l < 0 || l > 1) {
usage();
exit(EXIT_FAILURE);
--- a/src/abagames/a7xpg/A7xGameManager.d
+++ b/src/abagames/a7xpg/A7xGameManager.d
@@ -5,12 +5,13 @@
*/
module abagames.a7xpg.A7xGameManager;
-import math;
+import std.math;
import opengl;
import SDL;
import abagames.util.Rand;
import abagames.util.GameManager;
import abagames.util.ActorPool;
+import abagames.util.Vector;
import abagames.util.sdl.Screen3D;
import abagames.util.sdl.Texture;
import abagames.util.sdl.Input;
@@ -115,8 +116,8 @@
int enemyTableIdx, enemyNum;
public override void init() {
- prefManager = (A7xPrefManager) abstPrefManager;
- screen = (A7xScreen) abstScreen;
+ prefManager = cast(A7xPrefManager) abstPrefManager;
+ screen = cast(A7xScreen) abstScreen;
screen.makeLuminousTexture();
rand = new Rand;
field = new Field;
@@ -189,7 +190,7 @@
}
public void addGold() {
- Gold gold = (Gold) golds.getInstance();
+ Gold gold = cast(Gold) golds.getInstance();
assert(gold);
gold.set();
}
@@ -210,14 +211,14 @@
public void addBonus(int sc, Vector pos, float size) {
addScore(sc);
- Bonus bonus = (Bonus) bonuses.getInstanceForced();
+ Bonus bonus = cast(Bonus) bonuses.getInstanceForced();
assert(bonus);
bonus.set(sc, pos, size);
}
public void getGold() {
playSe(0);
- addBonus(((int)(ship.speed / (ship.DEFAULT_SPEED / 2))) * 10, ship.pos, 0.7);
+ addBonus((cast(int)(ship.speed / (ship.DEFAULT_SPEED / 2))) * 10, ship.pos, 0.7);
leftGold--;
if (leftGold - appGold >= 0)
addGold();
@@ -235,14 +236,14 @@
public void addEnemy(int type, float size, float speed) {
playSe(5);
- Enemy enemy = (Enemy) enemies.getInstance();
+ Enemy enemy = cast(Enemy) enemies.getInstance();
if (!enemy) return;
enemy.set(type, size, speed);
}
public void addParticle(Vector pos, float deg, float ofs, float speed,
float r, float g, float b) {
- Particle pt = (Particle) particles.getInstanceForced();
+ Particle pt = cast(Particle) particles.getInstanceForced();
assert(pt);
pt.set(pos, deg, ofs, speed, r, g, b);
}
@@ -254,14 +255,14 @@
field.size.y = stgData[st][1];
field.eyeZ = 300;
field.alpha = 1;
- stageTimer = stgData[st][2] * 60;
- leftGold = stgData[st][3];
- appGold = stgData[st][4];
- enemyAppInterval = stgData[st][5];
+ stageTimer = cast(int)(stgData[st][2] * 60);
+ leftGold = cast(int)stgData[st][3];
+ appGold = cast(int)stgData[st][4];
+ enemyAppInterval = cast(int)(stgData[st][5]);
int ei = 0;
for (int i = 6; i < stgData[st].length;) {
- int n = stgData[st][i]; i++;
- int tp = stgData[st][i]; i++;
+ int n = cast(int)stgData[st][i]; i++;
+ int tp = cast(int)stgData[st][i]; i++;
float sz = stgData[st][i]; i++;
float sp = stgData[st][i]; i++;
for (int j = 0; j < n; j++) {
@@ -374,7 +375,7 @@
if (enemyTableIdx == 0 && lap >= 1) {
int ei = enemyNum - 1;
for (int i = 0; i < lap * 2; i++) {
- addEnemy(enemyTable[ei][0],
+ addEnemy(cast(int)enemyTable[ei][0],
enemyTable[ei][1] * (1 + lap * 0.1),
enemyTable[ei][2] * (1 + lap * 0.1));
ei--;
@@ -383,7 +384,7 @@
}
}
enemyTimer = enemyAppInterval;
- addEnemy(enemyTable[enemyTableIdx][0],
+ addEnemy(cast(int)enemyTable[enemyTableIdx][0],
enemyTable[enemyTableIdx][1],
enemyTable[enemyTableIdx][2]);
enemyTableIdx++;
--- a/src/abagames/a7xpg/A7xPrefManager.d
+++ b/src/abagames/a7xpg/A7xPrefManager.d
@@ -30,7 +30,7 @@
if (ver != VERSION_NUM)
throw new Error("Wrong version num");
fd.read(hiScore);
- } catch (Error e) {
+ } catch (Exception e) {
init();
} finally {
fd.close();
--- a/src/abagames/a7xpg/A7xScreen.d
+++ b/src/abagames/a7xpg/A7xScreen.d
@@ -6,6 +6,7 @@
module abagames.a7xpg.A7xScreen;
import opengl;
+import std.c.string;
import abagames.util.sdl.Screen3D;
/**
@@ -40,13 +41,13 @@
GLuint luminousTexture;
const int LUMINOUS_TEXTURE_WIDTH_MAX = 128;
const int LUMINOUS_TEXTURE_HEIGHT_MAX = 128;
- GLuint td[LUMINOUS_TEXTURE_WIDTH_MAX * LUMINOUS_TEXTURE_HEIGHT_MAX * 4 * uint.size];
+ GLuint td[LUMINOUS_TEXTURE_WIDTH_MAX * LUMINOUS_TEXTURE_HEIGHT_MAX * 4 * uint.sizeof];
int luminousTextureWidth = 128, luminousTextureHeight = 128;
public void makeLuminousTexture() {
- uint *data = td;
+ uint *data = cast(uint *)td;
int i;
- memset(data, 0, luminousTextureWidth * luminousTextureHeight * 4 * uint.size);
+ memset(data, 0, luminousTextureWidth * luminousTextureHeight * 4 * uint.sizeof);
glGenTextures(1, &luminousTexture);
glBindTexture(GL_TEXTURE_2D, luminousTexture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, luminousTextureWidth, luminousTextureHeight, 0,
--- a/src/abagames/a7xpg/Bonus.d
+++ b/src/abagames/a7xpg/Bonus.d
@@ -36,7 +36,7 @@
tn /= 10;
pos.x = p.x - s / 2 * tn; pos.y = p.y;
size = s;
- cnt = 32 + s * 24;
+ cnt = cast(int)(32 + s * 24);
my = 0.03 + s * 0.2;
isExist = true;
}
--- a/src/abagames/a7xpg/Enemy.d
+++ b/src/abagames/a7xpg/Enemy.d
@@ -5,13 +5,15 @@
*/
module abagames.a7xpg.Enemy;
-import math;
+import math = std.math;
+import std.math;
import opengl;
import abagames.util.Vector;
import abagames.util.Rand;
import abagames.util.ActorInitializer;
import abagames.a7xpg.LuminousActor;
import abagames.a7xpg.Ship;
+import abagames.a7xpg.Field;
import abagames.a7xpg.A7xGameManager;
import abagames.a7xpg.A7xScreen;
@@ -48,7 +50,7 @@
}
public override void init(ActorInitializer ini) {
- EnemyInitializer ei = (EnemyInitializer) ini;
+ EnemyInitializer ei = cast(EnemyInitializer) ini;
ship = ei.ship;
field = ei.field;
rand = ei.rand;
--- a/src/abagames/a7xpg/Gold.d
+++ b/src/abagames/a7xpg/Gold.d
@@ -5,7 +5,8 @@
*/
module abagames.a7xpg.Gold;
-import math;
+import math = std.math;
+import std.math;
import opengl;
import abagames.util.Vector;
import abagames.util.Rand;
@@ -37,7 +38,7 @@
}
public override void init(ActorInitializer ini) {
- GoldInitializer gi = (GoldInitializer) ini;
+ GoldInitializer gi = cast(GoldInitializer) ini;
ship = gi.ship;
field = gi.field;
rand = gi.rand;
--- a/src/abagames/a7xpg/LetterRender.d
+++ b/src/abagames/a7xpg/LetterRender.d
@@ -123,7 +123,7 @@
float x, y, length, size, t;
int deg;
for ( i=0 ; ; i++ ) {
- deg = (int) spData[idx][i][4];
+ deg = cast(int) spData[idx][i][4];
if (deg > 99990) break;
x = -spData[idx][i][0];
y = -spData[idx][i][1];
--- a/src/abagames/a7xpg/LuminousActor.d
+++ b/src/abagames/a7xpg/LuminousActor.d
@@ -5,7 +5,7 @@
*/
module abagames.a7xpg.LuminousActor;
-import abagames.util.Actor;
+public import abagames.util.Actor;
/**
* Actor with the luminous effect.
--- a/src/abagames/a7xpg/LuminousActorPool.d
+++ b/src/abagames/a7xpg/LuminousActorPool.d
@@ -21,7 +21,7 @@
public void drawLuminous() {
for (int i = 0; i < actor.length; i++) {
if (actor[i].isExist)
- ((LuminousActor) actor[i]).drawLuminous();
+ (cast(LuminousActor) actor[i]).drawLuminous();
}
}
}
--- a/src/abagames/a7xpg/Particle.d
+++ b/src/abagames/a7xpg/Particle.d
@@ -5,7 +5,7 @@
*/
module abagames.a7xpg.Particle;
-import math;
+import std.math;
import opengl;
import abagames.util.Vector;
import abagames.util.Rand;
@@ -34,7 +34,7 @@
}
public override void init(ActorInitializer ini) {
- ParticleInitializer pi = (ParticleInitializer) ini;
+ ParticleInitializer pi = cast(ParticleInitializer) ini;
field = pi.field;
rand = pi.rand;
pos = new Vector;
--- a/src/abagames/a7xpg/Ship.d
+++ b/src/abagames/a7xpg/Ship.d
@@ -5,7 +5,8 @@
*/
module abagames.a7xpg.Ship;
-import math;
+import math = std.math;
+import std.math;
import opengl;
import abagames.util.Vector;
import abagames.util.Rand;
@@ -237,7 +238,7 @@
manager.addParticle(pos, deg + math.PI + rand.nextFloat(0.5) - 0.25, SIZE, ps, pr, pg, pb);
}
if (hitWall && pSpeed > DEFAULT_SPEED * 1.1) {
- int pn = pSpeed / (DEFAULT_SPEED / 4);
+ int pn = cast(int)(pSpeed / (DEFAULT_SPEED / 4));
for (int i = 0; i < pn; i++) {
manager.addParticle(pos, deg + rand.nextFloat(1.2) - 0.6, SIZE, pSpeed * 3,
0.8, 0.6, 0.1);
--- a/src/abagames/util/Actor.d
+++ b/src/abagames/util/Actor.d
@@ -5,7 +5,7 @@
*/
module abagames.util.Actor;
-import abagames.util.ActorInitializer;
+public import abagames.util.ActorInitializer;
/**
* Actor in the game that has the interface to move and draw.
--- a/src/abagames/util/Logger.d
+++ b/src/abagames/util/Logger.d
@@ -5,28 +5,28 @@
*/
module abagames.util.Logger;
-import stream;
+import std.cstream;
/**
* Logger(error/info).
*/
public class Logger {
public static void info(char[] msg) {
- stderr.writeLine("Info: " ~ msg);
+ derr.writeLine("Info: " ~ msg);
}
public static void error(char[] msg) {
- //stderr.writeLine("Error: " ~ msg);
+ //derr.writeLine("Error: " ~ msg);
throw new Exception("Error: " ~ msg ~ "\0");
}
public static void error(Exception e) {
- //stderr.writeLine("Error: " ~ e.toString());
+ //derr.writeLine("Error: " ~ e.toString());
throw new Exception("Error: " ~ e.toString() ~ "\0");
}
public static void error(Error e) {
- //stderr.writeLine("Error: " ~ e.toString());
+ //derr.writeLine("Error: " ~ e.toString());
//if (e.next)
// error(e.next);
throw new Exception("Error: " ~ e.toString() ~ "\0");
--- a/src/abagames/util/Rand.d
+++ b/src/abagames/util/Rand.d
@@ -5,8 +5,8 @@
*/
module abagames.util.Rand;
-import random;
-import date;
+import std.random;
+import std.date;
/**
* Random number generator.
@@ -19,14 +19,14 @@
}
public int nextInt(int n) {
- return random.rand() % n;
+ return rand() % n;
}
public int nextSignedInt(int n) {
- return random.rand() % (n * 2) - n;
+ return rand() % (n * 2) - n;
}
public float nextFloat(float n) {
- return ((float)(random.rand() % (n * 10000))) / 10000;
+ return (cast(float)(rand() % (n * 10000))) / 10000;
}
}
--- a/src/abagames/util/sdl/Input.d
+++ b/src/abagames/util/sdl/Input.d
@@ -5,7 +5,7 @@
*/
module abagames.util.sdl.Input;
-import string;
+import string = std.string;
import SDL;
import abagames.util.sdl.SDLInitFailedException;
--- a/src/abagames/util/sdl/MainLoop.d
+++ b/src/abagames/util/sdl/MainLoop.d
@@ -5,8 +5,7 @@
*/
module abagames.util.sdl.MainLoop;
-import string;
-import c.stdlib;
+import std.c.stdlib;
import SDL;
import abagames.util.Logger;
import abagames.util.Rand;
@@ -88,7 +87,7 @@
done = 1;
nowTick = SDL_GetTicks();
- frame = (int) (nowTick-prvTickCount) / interval;
+ frame = cast(int) (nowTick-prvTickCount) / interval;
if (frame <= 0) {
frame = 1;
SDL_Delay(prvTickCount+interval-nowTick);
--- a/src/abagames/util/sdl/Screen3D.d
+++ b/src/abagames/util/sdl/Screen3D.d
@@ -5,8 +5,8 @@
*/
module abagames.util.sdl.Screen3D;
-import string;
-import c.stdlib;
+import string = std.string;
+import std.c.stdlib;
import SDL;
import opengl;
import abagames.util.Logger;
@@ -64,11 +64,11 @@
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- //gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, nearPlane, farPlane);
+ //gluPerspective(45.0f, cast(GLfloat)width/cast(GLfloat)height, nearPlane, farPlane);
glFrustum(-nearPlane,
nearPlane,
- -nearPlane * (GLfloat)height / (GLfloat)width,
- nearPlane * (GLfloat)height / (GLfloat)width,
+ -nearPlane * cast(GLfloat)height / cast(GLfloat)width,
+ nearPlane * cast(GLfloat)height / cast(GLfloat)width,
0.1f, farPlane);
glMatrixMode(GL_MODELVIEW);
}
--- a/src/abagames/util/sdl/Sound.d
+++ b/src/abagames/util/sdl/Sound.d
@@ -5,7 +5,7 @@
*/
module abagames.util.sdl.Sound;
-import string;
+import string = std.string;
import SDL;
import SDL_mixer;
import abagames.util.sdl.SDLInitFailedException;
--- a/src/abagames/util/sdl/Texture.d
+++ b/src/abagames/util/sdl/Texture.d
@@ -5,7 +5,7 @@
*/
module abagames.util.sdl.Texture;
-import string;
+import string = std.string;
import opengl;
import SDL;
import abagames.util.sdl.SDLInitFailedException;
--- a/src/abagames/util/Vector.d
+++ b/src/abagames/util/Vector.d
@@ -5,7 +5,7 @@
*/
module abagames.util.Vector;
-import math;
+import std.math;
/**
* Vector.
@@ -60,19 +60,19 @@
}
public int checkSide(Vector pos1, Vector pos2) {
- int xo = pos2.x - pos1.x;
- int yo = pos2.y - pos1.y;
+ int xo = cast(int)(pos2.x - pos1.x);
+ int yo = cast(int)(pos2.y - pos1.y);
if (xo == 0) {
if (yo == 0)
return 0;
- return x - pos1.x;
+ return cast(int)(x - pos1.x);
} else if (yo == 0) {
- return pos1.y - y;
+ return cast(int)(pos1.y - y);
} else {
if (xo * yo > 0) {
- return (x - pos1.x) / xo - (y - pos1.y) / yo;
+ return cast(int)((x - pos1.x) / xo - (y - pos1.y) / yo);
} else {
- return -(x - pos1.x) / xo + (y - pos1.y) / yo;
+ return cast(int)(-(x - pos1.x) / xo + (y - pos1.y) / yo);
}
}
}