Author Topic: DOA  (Read 72399 times)

0 Members and 1 Guest are viewing this topic.

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #150 on: February 26, 2012, 12:11:57 am »
PROGRESS UPDATE:

I've been spending a ton of time optimizing the game, and so far I've gotten the game engine compiling down to 49816 bytes, and it's faster than ever!

Hopefully when I have the yet again rewritten save and load game features working, I'll be ready to release another alpha for testing. Right now, the save game feature works, but the code to load the game from the save file does not! :O

I'm not really sure what's going wrong right now either. :/

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: DOA
« Reply #151 on: February 26, 2012, 10:54:33 am »
Well, my initial reaction was Ü and then it went to ö. That is really awesome! O.O I hope you can figure out where stuff got broken! :D

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: DOA
« Reply #152 on: February 26, 2012, 03:42:44 pm »
Nice too see progress!
Maybe you could post the saving code, so maybe we can look into it? :D

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #153 on: February 26, 2012, 06:39:25 pm »
If any of you can spot what I did wrong, I would greatly appreciate it. I'm not sure what's going on with this, but I haven't looked into it too deeply yet. 

This part works, it generates the file, with the correct tag and all that stuff.
Code: [Select]
void SaveGame(short type_of_game)
{

short i,x,y;
const char const* filename = type_of_game ? "doasava" : "doasavb";

// size of file:
short totalDataSize =
sizeof(gameglobals) + 21 +
(8 * MAX_LEVEL_SPRITES) +
((14 * NR_SPRITE_TYPE_DEFS) * 2) +
(sizeof(FATSPRITE) * MAX_SPRITES) +
(sizeof(SpriteStruct) * MAX_SPRITES) +
(sizeof(SwitchStruct) * MAX_NR_SWITCHES) +
(sizeof(GlassWall) * MAX_GLASS_WALLS) +
(sizeof(ExplodingFalseWall) * MAX_NR_DOORS) +
(sizeof(PushableWall) * MAX_NR_DOORS) +
(sizeof(LockedDoor) * MAX_NR_DOORS) +
(4 * TOTAL_NR_WEAPONS) +
(4 * gg.nr_doors);

HSym hsym = SymAddMain(SYMSTR (filename));
if (hsym.folder == 0) return;
SYM_ENTRY *SymPtr = (DerefSym(hsym));
SymPtr->handle = HeapAlloc(totalDataSize);
if (SymPtr->handle == H_NULL) return;

unsigned char *VarPtr = HLock(SymPtr->handle);

if (VarPtr == NULL) return;


*(unsigned short*)VarPtr = (totalDataSize - 2);
VarPtr+=2; // 2

*(unsigned short*)VarPtr = fc.cam_xpos;
VarPtr+=2;  // 4
*(unsigned short*)VarPtr = fc.cam_xpos;
VarPtr+=2; // 6
*(unsigned short*)VarPtr = fc.cam_orientation;
VarPtr+=2; // 8

*(short*)VarPtr = nr_item_sprites;
VarPtr+=2; // 10
*(short*)VarPtr = nr_static_sprites;
VarPtr +=2; // 12
*(short*)VarPtr = nr_dynamic_sprites;
VarPtr +=2; // 14

memcpy(VarPtr,&gg,sizeof(gameglobals));
VarPtr += sizeof(gameglobals);

for (i = 0; i <MAX_LEVEL_SPRITES; i++)
{
*(short*)VarPtr = item_sprites[i];
VarPtr+=2;
*(short*)VarPtr = static_sprites[i];
VarPtr+=2;
*(short*)VarPtr = dynamic_sprites[i];
VarPtr+=2;
*(short*)VarPtr = sprite_checked[i];
VarPtr+=2;
}

for (y = 0; y < NR_SPRITE_TYPE_DEFS; y++)
{
for (x = 0; x < 7; x++)
{
*(short*)VarPtr = sprite_action_steps[y][x];
VarPtr+=2;
*(short*)VarPtr = sprite_action_nr_sprites[y][x];
VarPtr+=2;
}
}

for (i = 0; i < MAX_SPRITES; i++)
{
memcpy(VarPtr,&sprites[i],sizeof(FATSPRITE));
VarPtr+=sizeof(FATSPRITE);
memcpy(VarPtr,&sprt_data[i],sizeof(SpriteStruct));
VarPtr+=sizeof(SpriteStruct);
}

for (i = 0; i < MAX_NR_SWITCHES; i++)
{
memcpy(VarPtr,&Switches[i],sizeof(SwitchStruct));
VarPtr+=sizeof(SwitchStruct);
}

for (i = 0; i < MAX_GLASS_WALLS; i++)
{
memcpy(VarPtr,&glass_walls[i],sizeof(GlassWall));
VarPtr+=sizeof(GlassWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(VarPtr,&exploding_false_walls[i],sizeof(ExplodingFalseWall));
VarPtr+=sizeof(ExplodingFalseWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(VarPtr,&push_walls[i],sizeof(PushableWall));
VarPtr+=sizeof(PushableWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(VarPtr,&lockedDoors[i],sizeof(LockedDoor));
VarPtr+=sizeof(LockedDoor);
}

for (i = 0; i < TOTAL_NR_WEAPONS; i++)
{
*(short*)VarPtr = weapon_array[i]->have_weapon;
VarPtr+=2;
*(short*)VarPtr = weapon_array[i]->ammo;
VarPtr+=2;
}

FATDOOR *doorsarray = FAT_GetDoorsArray();

for (i = 0; i < gg.nr_doors; i++)
{
*VarPtr = doorsarray[i].type;
VarPtr++;
*VarPtr = doorsarray[i].state;
VarPtr++;
*(unsigned short*)VarPtr = doorsarray[i].position;
VarPtr+=2;
}


*VarPtr = 0;       // 15
VarPtr++;
*VarPtr = 'd';     // 16
VarPtr++;
*VarPtr = 'o';     // 17
VarPtr++;
*VarPtr = 'a';     // 18
VarPtr++;
*VarPtr = 's';     // 19
VarPtr++;
*VarPtr = 0;       // 20
VarPtr++;
*VarPtr = OTH_TAG; // 21


HeapUnlock(SymPtr->handle);
}

This part always generates a protected memory violation.

Code: [Select]
short LoadGame(short type_of_game)
{
short i,x,y;
const char const* filename = type_of_game ? "doasava" : "doasavb";

        // open file returns the pointer to the actual data in the file, past the size bytes.
unsigned char* VarPtr = OpenFile(filename);

if (VarPtr == NULL) return 0;

fc.cam_xpos = *(unsigned short*)VarPtr;
VarPtr+=2;  // 4
fc.cam_xpos = *(unsigned short*)VarPtr;
VarPtr+=2; // 6
fc.cam_orientation = *(unsigned short*)VarPtr;
VarPtr+=2; // 8

nr_item_sprites = *(short*)VarPtr;
VarPtr+=2; // 10
nr_static_sprites = *(short*)VarPtr;
VarPtr +=2; // 12
nr_dynamic_sprites = *(short*)VarPtr;
VarPtr +=2; // 14

memcpy(&gg,VarPtr,sizeof(gameglobals));
VarPtr += sizeof(gameglobals);

for (i = 0; i <MAX_LEVEL_SPRITES; i++)
{
item_sprites[i] = *(short*)VarPtr;
VarPtr+=2;
static_sprites[i] = *(short*)VarPtr;
VarPtr+=2;
dynamic_sprites[i] = *(short*)VarPtr;
VarPtr+=2;
sprite_checked[i] = *(short*)VarPtr;
VarPtr+=2;
}

for (y = 0; y < NR_SPRITE_TYPE_DEFS; y++)
{
for (x = 0; x < 7; x++)
{
sprite_action_steps[y][x] = *(short*)VarPtr;
VarPtr+=2;
sprite_action_nr_sprites[y][x] = *(short*)VarPtr;
VarPtr+=2;
}
}

for (i = 0; i < MAX_SPRITES; i++)
{
memcpy(&sprites[i],VarPtr,sizeof(FATSPRITE));
VarPtr+=sizeof(FATSPRITE);
memcpy(&sprt_data[i],VarPtr,sizeof(SpriteStruct));
VarPtr+=sizeof(SpriteStruct);
}

for (i = 0; i < MAX_NR_SWITCHES; i++)
{
memcpy(&Switches[i],VarPtr,sizeof(SwitchStruct));
VarPtr+=sizeof(SwitchStruct);
}

for (i = 0; i < MAX_GLASS_WALLS; i++)
{
memcpy(&glass_walls[i],VarPtr,sizeof(GlassWall));
VarPtr+=sizeof(GlassWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(&exploding_false_walls[i],VarPtr,sizeof(ExplodingFalseWall));
VarPtr+=sizeof(ExplodingFalseWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(&push_walls[i],VarPtr,sizeof(PushableWall));
VarPtr+=sizeof(PushableWall);
}

for (i = 0; i < MAX_NR_DOORS; i++)
{
memcpy(&lockedDoors[i],VarPtr,sizeof(LockedDoor));
VarPtr+=sizeof(LockedDoor);
}

for (i = 0; i < TOTAL_NR_WEAPONS; i++)
{
weapon_array[i]->have_weapon = *(short*)VarPtr;
VarPtr+=2;
weapon_array[i]->ammo = *(short*)VarPtr;
VarPtr+=2;
}

FATDOOR *doorsarray = FAT_GetDoorsArray();

for (i = 0; i < gg.nr_doors; i++)
{
doorsarray[i].type = *VarPtr;
VarPtr++;
doorsarray[i].state= *VarPtr;
VarPtr++;
doorsarray[i].position = *(unsigned short*)VarPtr;
VarPtr+=2;
}

CloseFile(filename);

// the game engine may not have the correct number of sprites to work with, so
// set it to what we loaded from the file.
fc.nr_sprites = gg.number_total_sprites;

// this part here has to be here, because the texconfig pointers for each sprite
// may be pointing to some random place in archive memory, that may not correspond
// to the textures anymore, so I just use the function I already have to
// set the current texture frame for the current animation, to set the
// pointers back to what they should be.

for (i = 0; i < fc.nr_sprites; i++)
{
SetSpriteToCurrentAnimationFrame(&sprites[i],&sprt_data[i]);
}

return 1;
}


Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: DOA
« Reply #154 on: February 27, 2012, 01:14:48 am »
Protected Memory Violation is triggered when writing to NULL or nearby addresses (where the vector table is)...
I cannot see any mistakes that are all too obvious here. Check that all structs you save and restore through memcpy do not contain pointers, which must be reinitialized to match the new runtime conditions in a different run of DOA.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: DOA
« Reply #155 on: March 22, 2012, 04:25:32 pm »
I'm glad this was still progressing. Hopefully the coding issue is resolved without too much hassle. :)

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #156 on: March 26, 2012, 10:25:23 pm »
PROGRESS FINALLY:

I now have the save/load feature working as long as you save/load while the game is already running. Now the task is to get it working for when you start the game up and want to continue from where you left off. It's proving difficult due to the large amount of data that has to be stored/recalled and not have any of it screw up a sequence in the loading. To give you an idea of the amount of data that needs to be stored:

Saving the game on the first level generates a save file of 15295 bytes.

That's a bit more than half of the entire ram of a ti-82. This game has a ton going on internally.

EDIT:

Turns out, the loading is pretty quirky. It works in certain situations, but there are problems in other situations. I  have some ideas on how to fix it though, so I may have a solution before too long. We'll see.
« Last Edit: March 26, 2012, 10:37:35 pm by AaroneusTheGreat »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: DOA
« Reply #157 on: March 26, 2012, 10:42:01 pm »
Glad to see you (and some progress) again :)

Yeah saving can be annoying, plus you have to be careful about dependencies on variables and stuff. X.x

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #158 on: April 15, 2012, 01:10:39 am »
Good to see you as always too DJ.

Progress update:

Well I made a little progress. I've got the story mode game saving/loading working 100% now, but in the process I decided it was best to take away the ability to save during the mini-game. It kind of defeats the purpose of the mini-game to be able to save, the object is to stay alive as long as possible.

I'm also working on fixing a little feature that got broken during the major rewrite. When you kill a robotic enemy, they are supposed to drop items, but it's not working quite right. When they do drop the items, you can't pick them up for whatever reason. I'm probably missing some minute detail, but haven't figured out what that could be yet.

Next on the list is more levels and tasks. I'm open to suggestions as to different types of tasks to accomplish to make the game more dynamic.

Hopefully there will be more to come soon! I am trying to focus on getting something significant done each week with this, we'll see how well it goes. :p I'll let you all know when I do though.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: DOA
« Reply #159 on: April 15, 2012, 02:22:05 am »
Yeah I still visit the chat and sometimes the forums, although not as much as a few years ago and often take breaks. I'm glad more progress was done. Hopefully you can fix the bugs without too much hassle.


New screenshot soon? :P

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: DOA
« Reply #160 on: April 15, 2012, 02:47:04 am »
Good to see more progress :)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #161 on: April 16, 2012, 11:42:36 am »
Thanks guys, here's a screenshot of the current little detail I added. When you die in the minigame, there is now a screen telling you how many rounds you survived.

I can't really do animated screenshots right now, I've had trouble with CalcCapture lately.

I'm working on a few other details right now, but they're not really visible things at the moment. Mostly internal bug fixes. As it is there's not really any major bugs. I haven't been able to make the code crash, but there's some quirks here and there I'm working out. I'll keep you posted if I make any more progress.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: DOA
« Reply #162 on: April 16, 2012, 11:44:58 am »
Nice o.o I like the fonts, by the way :)

Offline AaroneusTheGreat

  • Moderator
  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 287
  • Rating: +26/-1
    • View Profile
Re: DOA
« Reply #163 on: April 16, 2012, 09:45:21 pm »
The credit for the font goes to David Randall. He designed them and wrote the function for drawing them to the screen. I was focusing on gameplay stuff at the time and he volunteered to do the font stuff. Several people's hands have been at this game besides my own. All of which will be mentioned in the credits/readme when it comes time to release the game.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: DOA
« Reply #164 on: April 16, 2012, 09:49:59 pm »
Oh, cool :)