S60游戏移植到S40上遇到的问题

zsq010 2005-09-01 03:48:18
其中有一个类有90多k,里面包括游戏所有的逻辑,有许多静态的成员变量和方法,单加载这一个类40的215040bit的内存都不够用,各位大虾有啥好办法嘛?请赐教,谢谢!!
...全文
332 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
zsq010 2005-09-05
  • 打赏
  • 举报
回复
多谢各位的指点,万分感激!!

结贴了,先。
xueyong1203 2005-09-04
  • 打赏
  • 举报
回复
static 和 final 可以小幅提高运行速度
xueyong1203 2005-09-04
  • 打赏
  • 举报
回复
能用局部变量的尽量使用局部变量~~~
zjstu 2005-09-04
  • 打赏
  • 举报
回复
static final int 之类的东西混淆的时候就会去掉的。
我估计是你的代码类太多了吧,我写的一个S40单文件4000行都没你这么大,58K的样子,图片还用了18K
cnesky 2005-09-03
  • 打赏
  • 举报
回复
楼主会使用7za.zip这个开源工具吗??

在sourceforge.net上去下载一个,然后用ant调用它预编译代码,这些变量80%就会自动处理掉了
zsq010 2005-09-02
  • 打赏
  • 举报
回复
谢谢的各位指点,昨天程序优化那篇文章我找到了,通读一遍,获益匪浅!!

图片已经压缩过了,共占用18k左右,已经到最小极限了,再压缩就如随风兄所说,降低游戏画面的质量了。

我单独加载了一下逻辑类,测试结果如下:
Allocated world, heap left 196176
LoadTexts Begin
numtexts = 59
Allocated world, heap left 1956

源文件有90多k,有3000多行,这个类是逻辑类,所有的控制都在这里,单把它加载进来后用掉190多k的内存,别的就啥了做不了了。
这类老外写的,竟然没有一句注释,头都大了,~_~

各位兄弟,如何给这个类瘦身一下啊,请多提宝贵意见,谢谢了先
homesos 2005-09-02
  • 打赏
  • 举报
回复
如果想要代码清晰明了,自然会多费些代码,效率可能也会降低。
如果想要追求效率,代码可能就要变的难懂一些。

如果你实在想要减少内存,不妨将
像 private static final int PORTWIDTH = 128; 这样的,去掉,直接在代码里使用,也许会好些。

在使用的地方,写注释标明。
zsq010 2005-09-02
  • 打赏
  • 举报
回复
成员变量就这么一大堆,加载时还没有执行构造函数就占用了60多k的内存,各位大虾,有没有办法优化啊?
yayaleon801030 2005-09-02
  • 打赏
  • 举报
回复
关注中
zsq010 2005-09-02
  • 打赏
  • 举报
回复
private static final short scorp_framestart[] = { 0, 18, 35, 50, 68, 81 };
private static final short scorp_frameoffset[] = { 2, 1, 0, 1, 0 };
private static final short scorp_flipstart[] = { 63, 46, 31, 13, 0 };
private static final short scorp_flipoffset[] = { 2, 2, 1, 3, -1 };
private static final byte scorp_fireseq[] = { 0,2,2,3,3,2,2,2 };
private static final byte scorp_deathseq[] = { 4 };

private static final short arab_framestart[] = { 0, 18, 36, 59, 78, 100, 112 };
private static final short arab_frameoffset[] = { 3, 3, 2, 3, 5, 0 };
private static final short arab_flipstart[] = { 94, 76, 53, 34, 12, 0 };
private static final short arab_flipoffset[] = { 3, 3, 9, 4, 5, 0 };
private static final byte arab_fireseq[] = { 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
private static final byte arab_deathseq[] = { 4,3,3,3,3 };

private static final short mummy_framestart[] = { 0, 18, 37, 53, 67, 99, 129 };
private static final short mummy_frameoffset[] = { 4, 0, 3, 2, 11, 10 };
private static final short mummy_flipstart[] = { 111, 92, 76, 62, 30, 0 };
private static final short mummy_flipoffset[] = { 4, 9, 3, 2, 11, 10 };
private static final byte mummy_fireseq[] = { 0,3,3,2,2,2,1,1,0,0 };
private static final byte mummy_deathseq[] = { 5,4,4,4,4 };

private static final short sandboss_framestart[] = { 0, 26, 52, 79, 118, 152 };
private static final short sandboss_flipstart[] = { 126, 100, 73, 34, 0 };
private static final short sandboss_flipoffset[] = { 8, 7, 11, 17, 9 };
private static final byte sandboss_fireseq[] = { 0,2,2,2,1,1,1,1 };
private static final byte sandboss_deathseq[] = { 4,3,3,3,3,3 };

private static final MonsterInfo miScorp = new MonsterInfo();
private static final MonsterInfo miMummy = new MonsterInfo();
private static final MonsterInfo miArab = new MonsterInfo();
private static final MonsterInfo miSandBoss = new MonsterInfo();
private static final MonsterInfo miScorpBox = new MonsterInfo();
private static final MonsterInfo miChildScorp = new MonsterInfo();
private static final MonsterInfo miPlayer = new MonsterInfo();
private static final MonsterInfo monsterinfo[] =
{ miScorp, miMummy, miArab, miSandBoss, miScorpBox };

private final static int PROJECTILE_RADIUS = 6;
private final static int PROJECTILE_DIAMETER = 12;
private final static int MAXPROJECTILES = 6;
private static final Monster playerprojectiles[] = new Monster[MAXPROJECTILES];
private static final Monster enemyprojectiles[] = new Monster[MAXPROJECTILES];
private static int nplayerprojs;
private static int nmonsterprojs;

private static final short magic2_framestart[] = { 0, 11, 21, 35, 50, 63 };
private static final short magic2_frameoffset[] = { 0, 0, 2, 2, 1 };
private static final byte magic2_deathseq[] = { 4, 4, 3, 3, 2, 2, 1, 1 };

private static final short magic3_framestart[] = { 0, 11, 29, 49, 74 };
private static final short magic3_frameoffset[] = { 0, 4, 5, 7 };
private static final byte magic3_deathseq[] = { 3, 2, 1, 3, 3, 2, 2, 1, 1 };

private static final MonsterInfo magictype[] = new MonsterInfo[3];

private static final short arabfire_framestart[] = { 0, 7 };
private static final short arabfire_frameoffset[] = { -1 };

private static final short wind_framestart[] =
{ 0, 18, 36 };
private static final short wind_frameoffset[] = { 4, 4 };

private static int winx1, winx2, winy1, winy1sc, winy2;

private static int windx, windy;

private static boolean healthredrawneeded;
private static boolean ammoredrawneeded;
private static boolean scoreredrawneeded;
private static final short animCoin[][] = {
{ 0, 90,55, 18,18, 6,6, 0, 0 },
{ 0, 108,55, 12,18, 3,6, 0, 0 },
{ 0, 120,55, 4,18, -1,6, 0, 0 },
{ 0, 124,55, 12,18, 3,6, 0, 0 }
};
private static final short animSavePoint[][] = {
{ 0, 122,41, 14,14, 4,4, 0, 0 },
{ 0, 114,42, 10,10, 2,2, 0, 0 }
};

private static final int clBackPanel = 0xDFA800;

private static Image imgPanel;
private static Image imgFire;
private static Image imgMenu;
//private static final int WEAPONICON_HEIGHT = 15;
//final int WEAPONICON_START = 155;
private final static int weaponicon_picx[] = { 73, 91, 84 };
private final static int weaponicon_width[] = { 11, 7, 7 };
private final static int weaponicon_scx[] = { 116, 119, 119 };
private final static int digit_start[] = { 24, 29, 33, 38, 43, 48, 53, 58, 63, 68 };
private final static int digit_width[] = { 5, 4, 5, 5, 5, 5, 5, 5, 5, 5 };

private static Sound sndOuch;
private static Sound sndCast;
private static Sound sndFireExp;
private static Sound sndIceExp;
private static Sound sndFist;
private static Sound sndDie;
private static Sound sndBonus;
private static Sound sndGun;
private static Sound sndBossFire;
private static Sound sndBossDie;
// UI
private static Sound sndWin;
zsq010 2005-09-02
  • 打赏
  • 举报
回复
private static final int MOVESPEED = 2;
private static final int RUNSPEED = 4;
private static final int MAXYSPEED = 6;
private static final int JUMPXSPEED = 2;
private static final int JUMPYSPEED = 10;
private static final int FALLXSPEED = 1;
private static final int GRAVITY = 1;
private static final int CELLSIZE = 5;
//final int STEPHEIGHT = CELLSIZE;
private static final int PL_HEIGHT = 25;
private static final int PL_WIDTH = 12;
private final int JUMPPADXSPEED = 2;
private final int JUMPPADYSPEED = 15;

private static final byte PL_STAND = 0;
private static final byte PL_WALK1 = 1;
private static final byte PL_WALK2 = 2;
private static final byte PL_WALK3 = 3;
private static final byte PL_DOWN = 4;
private static final byte PL_JUMP = 5;
private static final byte PL_INAIR = 6;
private static final byte PL_DUCK = 7;
private static final byte PL_DIE = 8;
private static final byte PL_DEAD = 9;
private static final byte PL_FIST1 = 10;
private static final byte PL_FIST2 = 11;
private static final byte PL_CAST1 = 12;
private static final byte PL_CAST2 = 13;

private static final short pl_framestart[] = { 0, 14, 25, 41, 57, 73, 89, 111, 141, 163, 191, 207, 226, 240, 256 };
private static final short pl_frameoffset[] = { 1, 0, 2, 2, 2, 2, 5, 9, 5, 8, 2, 0, 1, 0 };
private static final short pl_flipframestart[] = { 242, 231, 215, 199, 183, 167, 145, 115, 93, 65, 49, 30, 16, 0 };
private static final short pl_flipframeoffset[] = { 1, -1, 2, 2, 2, 2, 5, 9, 5, 8, 2, 7, 1, 4 };

private static final byte pl_walkframes[] = { PL_WALK1, PL_WALK1, PL_WALK2, PL_WALK2, PL_WALK1, PL_WALK1, PL_WALK3, PL_WALK3 };

private static final int PL_NUMJUMPTICKS = 5;
private static final byte pl_jumpframes[] = { PL_JUMP, PL_DOWN, PL_DOWN, PL_DOWN, PL_DOWN };

private static final int PL_WAITAFTERFALL = 5;

private static final int PL_NUMFISTTICKS = 5;
private static final byte pl_fistframes[] = { PL_STAND, PL_FIST2, PL_FIST2, PL_FIST1, PL_FIST1 };

private static final int PL_NUMCASTTICKS = 7;
private static final byte pl_castframes[] = { PL_STAND, PL_CAST2, PL_CAST2, PL_CAST2, PL_CAST1, PL_CAST1, PL_CAST1 };

private static final int PL_NUMDIETICKS = 5;
private static final byte pl_dieframes[] = { PL_DEAD, PL_DIE, PL_DIE, PL_DIE, PL_DIE };

private static final int REASON_LAND = 0;
private static final int REASON_JUMP = 1;
private static final int REASON_DIE = 2;
private static final int REASON_FIST = 3;
private static final int REASON_CAST = 4;

private static final int MONSTERRESPAWNDELAY = 600;

private final static int MAXCHILDREN = 5;
private static final Monster[] children = new Monster[MAXCHILDREN];
private static final int maxsimultmonsters = 4;

zsq010 2005-09-02
  • 打赏
  • 举报
回复
贴一下这个类的成员变量

private static final int PORTWIDTH = 128;
private static final int PORTHEIGHT = 113;
private static final int UPPERHEIGHT = 8;
private static final int LOWERHEIGHT = 7;
private static final int LOWERPANELY = UPPERHEIGHT+PORTHEIGHT;

static Image TileImages[];
private static Image imgPlayer;
private static Image imgBuffer;
private static Graphics grBuffer;
static Image imgArrows;

private static final int IND_BMNUMBER = 0;
private static final int IND_X = 1;
private static final int IND_Y = 2;
private static final int IND_WID = 3;
private static final int IND_HEI = 4;
private static final int IND_DX = 5;
private static final int IND_DY = 6;
private static final int IND_TILED = 7;
static final int IND_SOLIDITY = 8;
static short picinfo[][];
private int numpicinfos;

public static boolean gameinprogress;

private static int tick;
static Mobj mobiles[];
static Mobj seenmobjs[];
static Mobj mobjunrol[];
static final int MAXSEENMONSTERS = 10;
static Monster monsterunrol[];

static int maxscen, maxdead, maxmobjs, maxmonsters;

static int nseenmobjs;
static int div_back_front;
static int div_front_tech;
static int div_tech_monsters;

static Mobj screen = new Mobj();

static int nmobiles;

private static int startskill;

private static boolean firsttime;
static int nscen;
static byte scennum[];
static short scenx[], sceny[];
static int ndead;
static byte deadnum[];
static short deadx1[], deady1[], deadx2[], deady2[];
static int dead_frontthreshold;

static int nmonsters;
static short mon_x1[];
static short mon_y2[];
static short mon_data1[];
static short mon_data2[];
static short mon_data3[];
static short mon_data4[];
static byte mon_hp[];
static MonsterInfo mon_info[];
static int mon_tick[];
static byte mon_frame[];

private static Image imgJumpPadX;

static int scx, scy, oldscx, oldscy;
static int blocknumx, blocknumy;
static int blockstepx, blockstepy;
static int maxbmcount;
private static short[] blockmap;
private static short[][] bm_thinkers;

public static Monster player;
private static int xspeed,yspeed;
private static int normyspeed;
private static int player_waitticks;
private static int player_waitreason;
private static boolean player_bumpwall;
private static int player_duckdepth;
private static int player_maxhp;
private static int origplayery1;
private static Mobj supporter;
private static int platspeed;
private static int player_weapon;
private static int player_usedweapon;
private static boolean player_hithead;
static int score;
private static int scoreaccum;
private static final int ammoleft[] = new int[3];
private final static int GODTICK = 17*6;
private static int player_godtime;
private static int player_castcountdown;
private static int runcount;
private static int player_step;
private static int lives;
private static int player_castrate;
private static boolean player_sunk;

private static Mobj jumppad;
private static int padframe;
private static final int NUMPADFRAMES = 8;
private static final int PADAPEX = 4;
private static final int PADXAPEX = 5;
private static final int PADXHEIGHT = 13;
private static final int PADXWIDTH = 21;
private static int paddontmovecount;

private static final int MSGR_DEATH = 0;
private static final int MSGR_DONE = 1;
private static final int MSGR_GAMEOVER = 2;
private static int messagereason;
private static int messagecountdown;
private static final int MESSAGEDELAY = 50;
private static int origpx1, origpy2;

gameover1234 2005-09-02
  • 打赏
  • 举报
回复
楼上的家伙谁能分得清楚:
1,jar的大小
2,运行时内存大小

的区别?

nokia 40系列

1,jar的大小最大不能超过65k,否则不能运行。
2,运行时内存大小是220k

jar里面的图片是压缩的,一般来说jar里面的图片在程序运行时,经过手机解压装载到内存里是原先的10倍(大概估计)。

有不同意见的请举手。
JavaAndJava 2005-09-02
  • 打赏
  • 举报
回复
把这个类拆开了,分成几个类,一般3000行代码运行起来没有什么问题,但是不要在一个文件中,分开写,分开加载就没什么问题,具体怎么拆,那就只有看代码了~
homesos 2005-09-02
  • 打赏
  • 举报
回复
呵呵
听起来这个类是蛮强滴
cnesky 2005-09-02
  • 打赏
  • 举报
回复
实在压缩不了的话 还有一个方法, 就是做这个游戏的DEMO版,去掉一些功能了 :)
cnesky 2005-09-02
  • 打赏
  • 举报
回复
该说的都说了,再说就只有把代码贴出来,大家帮你压缩类了
homesos 2005-09-01
  • 打赏
  • 举报
回复
既然是运行于s40上,那图片进行压缩后,看上去不会有什么明显滴差距滴
ransion 2005-09-01
  • 打赏
  • 举报
回复
6k的图,lz你还是留在S60里用吧,S40由于性能的原因是要作出适当的取舍

看上去释放资源是一个好的方法,但是实际应用中频繁的释放和在创建并不能从本质上解决堆不够的问题

因为java毕竟它的释放空间不可能很彻底,而且我们也不能控制GC的行为

ps:
图的压缩可以试试这个工具:xat.com Image Optimizer
hszr99 2005-09-01
  • 打赏
  • 举报
回复
可以把类合并,没创建一个类大约要用0.2K左右的空间。
S40的我们公司是<59K的。图片也不能太压缩,否则对游戏的
画面有影响.
加载更多回复(10)

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧