[go: up one dir, main page]

Menu

[r6]: / src / Main.cpp  Maximize  Restore  History

Download this file

125 lines (97 with data), 2.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include "PNGImageLoader.h"
#include "Game.h"
String vmfiles[] =
{
"luasrc/Consts.lua",
"luasrc/Entity.lua",
"luasrc/AbstractTimer.lua",
"luasrc/Timer.lua",
"uisrc/UICore.lua",
"uisrc/test.lua"
};
RTexture* loadPng(Renderer* renderer, const char* file);
int main(int argc, char** argv)
{
Game TheGame;
//Read game configuration file, and then process command line arguments
//so that they can override what is stored on disk.
TheGame.readConfig();
if(argc > 1)
{
int i;
for(i=1; i<argc; i++)
{
//Accept '-game' command line argument
if(strcmp(argv[i], "-game") == 0)
{
if(i+1 < argc)
TheGame.setConfigValue("GAME", argv[i+1]);
else
{
printf("Expected game name after '-game'\n");
return 1;
}
}
}
}
if(!TheGame.initialize())
return 2;
//Main game loop. Simple, I know.
while(TheGame.frame())
;
#if 0
UIGC* gc;
UIEngine UI(&vm);
bool exit_time = false;
gc = UI.getGC();
gc->renderer = &renderer;
gc->wndclose = loadPng(&renderer, "images/wndclose.png");
gc->wndborder = loadPng(&renderer, "images/wndborder.png");
gc->wndcorner = loadPng(&renderer, "images/wndcorner.png");
gc->wndbkg = loadPng(&renderer, "images/wndbkg.png");
gc->button = loadPng(&renderer, "images/btn.png");
gc->minalpha = 0.1f;
gc->maxalpha = 1.0f;
int i;
for(i=0; i<sizeof(vmfiles)/sizeof(String); i++)
{
if(vm.loadScriptFromFile(vmfiles[i]) == false)
printf("Failed to load %s!\n", vmfiles[i].c_str());
else
printf("Loaded %s!\n", vmfiles[i].c_str());
}
#endif
TheGame.shutdown();
}
RTexture* loadPng(Renderer* renderer, const char* file)
{
FILE* fp = fopen(file, "rb");
RTexture* tex = NULL;
int size;
void* buf;
if(fp == NULL)
return NULL;
fseek(fp, 0, SEEK_END);
size = ftell(fp);
rewind(fp);
buf = malloc(size);
fread(buf, 1, size, fp);
fclose(fp);
PNGImageLoader loader(buf, size);
if(!loader.readHeader())
printf("Failed to read PNG header\n");
else
{
printf("%dx%dx%d surface\n", loader.getWidth(), loader.getHeight(), loader.getBPP());
tex = renderer->createTexture(loader.getWidth(), loader.getHeight(), loader.hasAlpha(), false);
void* addr = tex->lock();
if(loader.readData(addr))
printf("successfully loaded png\n");
else
printf("png load fail\n");
tex->unlock();
}
free(buf);
return tex;
}