mirror of
https://github.com/stevenhowes/CTheEscape.git
synced 2026-05-27 00:03:27 +01:00
proof of concept for tile based stuff (performance test).
Fixed 10x10 grid, so panning of 10x10 view around a real map yet.
This commit is contained in:
Binary file not shown.
@@ -64,3 +64,6 @@ o.Mission1: c.Mission1
|
|||||||
o.Mission1: h.Graphics
|
o.Mission1: h.Graphics
|
||||||
o.Mission2: c.Mission2
|
o.Mission2: c.Mission2
|
||||||
o.Mission2: h.Graphics
|
o.Mission2: h.Graphics
|
||||||
|
o.Mission2: C:h.swis
|
||||||
|
o.Mission2: C:h.kernel
|
||||||
|
o.Mission2: C:h.kernel
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -16,6 +16,8 @@ _kernel_swi_regs outreg;
|
|||||||
// Sprite buffer
|
// Sprite buffer
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
unsigned char *fontbuffer;
|
unsigned char *fontbuffer;
|
||||||
|
unsigned char *tilebuffer;
|
||||||
|
|
||||||
extern int screen;
|
extern int screen;
|
||||||
extern struct CompositionElement composition[128];
|
extern struct CompositionElement composition[128];
|
||||||
extern int current_element;
|
extern int current_element;
|
||||||
@@ -50,8 +52,8 @@ int main(int argc, char *argv[])
|
|||||||
screen_clear();
|
screen_clear();
|
||||||
|
|
||||||
// Load sprite library
|
// Load sprite library
|
||||||
load_sprites("Spr");
|
load_sprites("Spr",&buffer);
|
||||||
load_font("Font");
|
load_sprites("Font",&fontbuffer);
|
||||||
|
|
||||||
#ifndef SKIP_INTRO
|
#ifndef SKIP_INTRO
|
||||||
// Intro titles + music
|
// Intro titles + music
|
||||||
@@ -84,13 +86,15 @@ int main(int argc, char *argv[])
|
|||||||
#ifndef SKIP_MISSION2
|
#ifndef SKIP_MISSION2
|
||||||
lastoutcome = 1;
|
lastoutcome = 1;
|
||||||
|
|
||||||
|
load_sprites("Tiles",&tilebuffer);
|
||||||
|
|
||||||
// Mission 2
|
// Mission 2
|
||||||
while(lastoutcome == 1)
|
while(lastoutcome == 1)
|
||||||
{
|
{
|
||||||
outcome = 0;
|
outcome = 0;
|
||||||
game2_briefing();
|
game2_briefing();
|
||||||
screen_clear();
|
screen_clear();
|
||||||
//game2_setup();
|
game2_setup();
|
||||||
while(!outcome)
|
while(!outcome)
|
||||||
{
|
{
|
||||||
outcome = game2_tick();
|
outcome = game2_tick();
|
||||||
|
|||||||
+39
-59
@@ -8,10 +8,12 @@ extern _kernel_swi_regs outreg;
|
|||||||
|
|
||||||
extern unsigned char *buffer;
|
extern unsigned char *buffer;
|
||||||
extern unsigned char *fontbuffer;
|
extern unsigned char *fontbuffer;
|
||||||
|
extern unsigned char *tilebuffer;
|
||||||
|
|
||||||
int screen = 1;
|
int screen = 1;
|
||||||
|
|
||||||
// Loads sprite file into buffer
|
// Loads sprite file into buffer
|
||||||
void load_sprites(char* filename)
|
void load_sprites(char* filename, unsigned char **buffername)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
@@ -38,74 +40,24 @@ void load_sprites(char* filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt malloc, die if we cant
|
// Attempt malloc, die if we cant
|
||||||
buffer = (unsigned char *) malloc(length + 4);
|
*buffername = (unsigned char *) malloc(length + 4);
|
||||||
|
|
||||||
if(buffer==NULL)
|
if(buffername==NULL)
|
||||||
{
|
{
|
||||||
printf("Couldn't malloc %i bytes for sprite buffer",length);
|
printf("Couldn't malloc %i bytes for sprite buffer",length);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store size and other info as required for SpriteOp 9 to init sprite area
|
// Store size and other info as required for SpriteOp 9 to init sprite area
|
||||||
*(unsigned int *)buffer = length + 4;
|
*(unsigned int *)*buffername = length + 4;
|
||||||
*(unsigned int *)(buffer + 4) = 16;
|
*(unsigned int *)(*buffername + 4) = 16;
|
||||||
inreg.r[0] = 256+9;
|
inreg.r[0] = 256+9;
|
||||||
inreg.r[1] = (unsigned int) buffer;
|
inreg.r[1] = (unsigned int) *buffername;
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||||
|
|
||||||
// Load sprite file into buffer
|
// Load sprite file into buffer
|
||||||
inreg.r[0] = 256+10;
|
inreg.r[0] = 256+10;
|
||||||
inreg.r[1] = (int) buffer;
|
inreg.r[1] = (int) *buffername;
|
||||||
inreg.r[2] = (int) filename;
|
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loads sprite file into buffer
|
|
||||||
void load_font(char* filename)
|
|
||||||
{
|
|
||||||
int length;
|
|
||||||
|
|
||||||
// Attempt to get file info
|
|
||||||
inreg.r[0] = 13;
|
|
||||||
inreg.r[1] = (int) filename;
|
|
||||||
_kernel_swi(OS_File,&inreg,&outreg);
|
|
||||||
|
|
||||||
// Length will be in R4 if it exists
|
|
||||||
length = outreg.r[4];
|
|
||||||
|
|
||||||
// If it's <1 it's fil not found
|
|
||||||
if(outreg.r[0] < 1)
|
|
||||||
{
|
|
||||||
printf("Sprite file %s not found",filename);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stops us trying to mallocsomething mad if file is too big.
|
|
||||||
if(length > 200000)
|
|
||||||
{
|
|
||||||
printf("Sprite file %s seems unreasonably large at %i bytes",filename, length);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt malloc, die if we cant
|
|
||||||
fontbuffer = (unsigned char *) malloc(length + 4);
|
|
||||||
|
|
||||||
if(fontbuffer==NULL)
|
|
||||||
{
|
|
||||||
printf("Couldn't malloc %i bytes for sprite buffer",length);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store size and other info as required for SpriteOp 9 to init sprite area
|
|
||||||
*(unsigned int *)fontbuffer = length + 4;
|
|
||||||
*(unsigned int *)(fontbuffer + 4) = 16;
|
|
||||||
inreg.r[0] = 256+9;
|
|
||||||
inreg.r[1] = (unsigned int) fontbuffer;
|
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
|
||||||
|
|
||||||
// Load sprite file into buffer
|
|
||||||
inreg.r[0] = 256+10;
|
|
||||||
inreg.r[1] = (int) fontbuffer;
|
|
||||||
inreg.r[2] = (int) filename;
|
inreg.r[2] = (int) filename;
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||||
}
|
}
|
||||||
@@ -190,10 +142,21 @@ void draw_letter(char* spritename,int x, int y)
|
|||||||
inreg.r[2] = (int) spritename;
|
inreg.r[2] = (int) spritename;
|
||||||
inreg.r[3] = x;
|
inreg.r[3] = x;
|
||||||
inreg.r[4] = y;
|
inreg.r[4] = y;
|
||||||
inreg.r[5] = 8; // GCOL dest=source and sprite mask
|
inreg.r[5] = 8;
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_tile(char* spritename,int x, int y)
|
||||||
|
{
|
||||||
|
// SpriteOp 34 to put sprite at a location
|
||||||
|
inreg.r[0] = 256+34;
|
||||||
|
inreg.r[1] = (int) tilebuffer;
|
||||||
|
inreg.r[2] = (int) spritename;
|
||||||
|
inreg.r[3] = x;
|
||||||
|
inreg.r[4] = y;
|
||||||
|
inreg.r[5] = 0;
|
||||||
|
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||||
|
}
|
||||||
|
|
||||||
void draw_spritetext(char* text, int x, int y)
|
void draw_spritetext(char* text, int x, int y)
|
||||||
{
|
{
|
||||||
@@ -214,9 +177,9 @@ void draw_spritetext(char* text, int x, int y)
|
|||||||
{
|
{
|
||||||
case 't':
|
case 't':
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'y':
|
|
||||||
case '.':
|
case '.':
|
||||||
case ',':
|
case ',':
|
||||||
|
case 'y':
|
||||||
currentx += 12 + 4;
|
currentx += 12 + 4;
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
@@ -318,6 +281,23 @@ void screen_flipbuffer()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void screen_nobuffer()
|
||||||
|
{
|
||||||
|
// Hardware
|
||||||
|
inreg.r[0] = 113;
|
||||||
|
inreg.r[1] = 1;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
// Drivers
|
||||||
|
inreg.r[0] = 112;
|
||||||
|
inreg.r[1] = 1;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
inreg.r[0] = 19;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void screen_clear()
|
void screen_clear()
|
||||||
{
|
{
|
||||||
inreg.r[0] = 12;
|
inreg.r[0] = 12;
|
||||||
|
|||||||
+2
-2
@@ -1006,7 +1006,7 @@ void game1_victory()
|
|||||||
screen_clear();
|
screen_clear();
|
||||||
|
|
||||||
draw_spritetext(
|
draw_spritetext(
|
||||||
"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nour shuttlepod has been rescued by the uss archimedes - but our \njob here isn't done. the archimedes is now under attack from the \ndurnovarians, and recoverying the shuttle has come at a cost. \nSeveral major systems are now offline.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}"
|
"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nour shuttlepod has been rescued by the uss archimedes - but our \njob here isn't done. the archimedes is now under attack from the \ndurnovarians, and recoverying the shuttle has come at a cost. \nseveral major systems are now offline.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}"
|
||||||
, 50, 950);
|
, 50, 950);
|
||||||
|
|
||||||
draw_sprite("spacebar",(DISPLAY_X/2)-106,50);
|
draw_sprite("spacebar",(DISPLAY_X/2)-106,50);
|
||||||
@@ -1060,7 +1060,7 @@ int game1_tick()
|
|||||||
PROFILE(game_draw_player());
|
PROFILE(game_draw_player());
|
||||||
PROFILE(game_draw_npcs());
|
PROFILE(game_draw_npcs());
|
||||||
PROFILE(game_draw_projectiles());
|
PROFILE(game_draw_projectiles());
|
||||||
game_draw_comms("Shuttlepod Phoebe - this is the USS Archimedes.\nPower down your engines and stand by for\nimmediate tractor beam recovery.");
|
game_draw_comms("shuttlepod phoebe - this is the USS Archimedes.\npower down your engines and stand by for\nimmediate tractor beam recovery.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(Player.integrity > 0)
|
else if(Player.integrity > 0)
|
||||||
|
|||||||
+149
-10
@@ -1,10 +1,60 @@
|
|||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
|
#include "swis.h"
|
||||||
//#defene PROFILE(X) lastprofile = clock(); X; printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%s %i\n", #X, (clock() - lastprofile))
|
#include <kernel.h>
|
||||||
#define PROFILE(X) X
|
|
||||||
|
|
||||||
extern int tick;
|
extern int tick;
|
||||||
extern int lasttick;
|
extern int lasttick;
|
||||||
|
extern int screen;
|
||||||
|
|
||||||
|
extern _kernel_swi_regs inreg;
|
||||||
|
extern _kernel_swi_regs outreg;
|
||||||
|
|
||||||
|
|
||||||
|
#define TILESX 10
|
||||||
|
#define TILESY 10
|
||||||
|
|
||||||
|
// map[0] is the 'master', [1] and [2] represents what is currently
|
||||||
|
// believed to be displayed in the corresponding (+1) screen buffer
|
||||||
|
// and we run a compare to see if re-drawing is needed. 0xFF is used
|
||||||
|
// for a re-draw being required (so it's set on the tile under the player
|
||||||
|
unsigned char map[3][TILESX][TILESY];
|
||||||
|
|
||||||
|
char tilenamebuffer[4];
|
||||||
|
char textbuffer[63];
|
||||||
|
|
||||||
|
struct EntityLocation_s {
|
||||||
|
short signed int X,Y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilePlayer_s {
|
||||||
|
struct EntityLocation_s location;
|
||||||
|
struct EntityLocation_s hitbox_bl;
|
||||||
|
struct EntityLocation_s hitbox_tr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TilePlayer_s TilePlayer;
|
||||||
|
|
||||||
|
void game2_loadmap(char* filename)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
|
||||||
|
// Attempt to get file info
|
||||||
|
inreg.r[0] = 13;
|
||||||
|
inreg.r[1] = (int) filename;
|
||||||
|
_kernel_swi(OS_File,&inreg,&outreg);
|
||||||
|
|
||||||
|
// Length will be in R4 if it exists
|
||||||
|
length = outreg.r[4];
|
||||||
|
|
||||||
|
// Attempt to get file info
|
||||||
|
inreg.r[0] = 16;
|
||||||
|
inreg.r[1] = (int) filename;
|
||||||
|
inreg.r[2] = (int) map[0];
|
||||||
|
inreg.r[3] = 0;
|
||||||
|
|
||||||
|
_kernel_swi(OS_File,&inreg,&outreg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void game2_death()
|
void game2_death()
|
||||||
{
|
{
|
||||||
@@ -77,7 +127,7 @@ void game2_briefing()
|
|||||||
screen_clear();
|
screen_clear();
|
||||||
|
|
||||||
draw_spritetext(
|
draw_spritetext(
|
||||||
"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nYour mission is to be dead until I make mission 2. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}"
|
"~~~~~~~~{ chief engineers log - uss archimedes - stardate 1234567890 ==}\n\n\nyour mission is to be dead until i make mission 2. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~~~~~~~~{======================~~~~~~~~===========================}"
|
||||||
, 50, 950);
|
, 50, 950);
|
||||||
|
|
||||||
draw_sprite("spacebar",(DISPLAY_X/2)-106,50);
|
draw_sprite("spacebar",(DISPLAY_X/2)-106,50);
|
||||||
@@ -95,23 +145,112 @@ void game2_briefing()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game2_setup()
|
||||||
|
{
|
||||||
|
screen_flipbuffer();
|
||||||
|
screen_clear();
|
||||||
|
screen_flipbuffer();
|
||||||
|
screen_clear();
|
||||||
|
TilePlayer.location.X = 0;
|
||||||
|
TilePlayer.location.Y = 0;
|
||||||
|
TilePlayer.hitbox_bl.X = 0;
|
||||||
|
TilePlayer.hitbox_bl.Y = 0;
|
||||||
|
TilePlayer.hitbox_tr.X = 60;
|
||||||
|
TilePlayer.hitbox_tr.Y = 50;
|
||||||
|
game2_loadmap("map");
|
||||||
|
}
|
||||||
|
|
||||||
|
void game2_tick_input()
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
// Up arrow
|
||||||
|
if(input_readkey(57))
|
||||||
|
{
|
||||||
|
TilePlayer.location.Y += 1 * (tick - lasttick);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Down arrow
|
||||||
|
if(input_readkey(41))
|
||||||
|
{
|
||||||
|
TilePlayer.location.Y -= 1 * (tick - lasttick);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right arrow
|
||||||
|
if(input_readkey(121))
|
||||||
|
{
|
||||||
|
TilePlayer.location.X += 1 * (tick - lasttick);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left arrow
|
||||||
|
if(input_readkey(25))
|
||||||
|
{
|
||||||
|
TilePlayer.location.X -= 1 * (tick - lasttick);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Q
|
||||||
|
if(input_readkey(16))
|
||||||
|
{
|
||||||
|
for(x = 0; x < TILESX; x++)
|
||||||
|
{
|
||||||
|
for(y = 0; y < TILESY; y++)
|
||||||
|
{
|
||||||
|
map[0][x][y] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int game2_tick()
|
int game2_tick()
|
||||||
{
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int udt = 0;
|
||||||
lasttick = tick;
|
lasttick = tick;
|
||||||
tick = clock();
|
tick = clock();
|
||||||
|
|
||||||
screen_flipbuffer();
|
screen_flipbuffer();
|
||||||
screen_clear();
|
|
||||||
|
|
||||||
if(0)
|
if(1)
|
||||||
{
|
{
|
||||||
|
for(x = 0; x < TILESX; x++)
|
||||||
|
{
|
||||||
|
for(y = 0; y < TILESY; y++)
|
||||||
|
{
|
||||||
|
if(game_hitbox_collide(
|
||||||
|
(TilePlayer.location.X + TilePlayer.hitbox_bl.X),(TilePlayer.location.Y + TilePlayer.hitbox_bl.Y),
|
||||||
|
(TilePlayer.hitbox_tr.X - TilePlayer.hitbox_bl.X),(TilePlayer.hitbox_tr.Y - TilePlayer.hitbox_bl.Y),
|
||||||
|
x*100,y*100,
|
||||||
|
100,100
|
||||||
|
))
|
||||||
|
{
|
||||||
|
map[1][x][y] = 255;
|
||||||
|
map[2][x][y] = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(map[0][x][y] ^ map[screen+1][x][y])
|
||||||
|
{
|
||||||
|
map[screen+1][x][y] = map[0][x][y];
|
||||||
|
sprintf(tilenamebuffer,"%i",map[screen+1][x][y]);
|
||||||
|
draw_tile(tilenamebuffer,x*100,y*100);
|
||||||
|
udt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw_sprite("lcarsblack",1000,DISPLAY_Y-164);
|
||||||
|
|
||||||
|
//sprintf(textbuffer,"CPF: %i\nUDT: %i",(tick-lasttick), udt);
|
||||||
|
//draw_spritetext(textbuffer, 1070, 950);
|
||||||
|
}
|
||||||
|
|
||||||
|
game2_tick_input();
|
||||||
|
|
||||||
|
draw_sprite("man",TilePlayer.location.X,TilePlayer.location.Y);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
screen_flipbuffer();
|
/* screen_flipbuffer();
|
||||||
screen_clear();
|
screen_clear();
|
||||||
game2_death();
|
game2_death();
|
||||||
return 1;
|
return 1;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user