project_files/frontlib/test.c
author Medo <smaxein@googlemail.com>
Tue, 12 Jun 2012 11:25:05 +0200
changeset 7224 5143861c83bd
child 7227 1c859f572d72
permissions -rw-r--r--
Cleanup, refactoring and generally more development in the frontlib
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7224
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
#include "frontlib.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
#include "util/logging.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
#include "model/map.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
#include "ipc/mapconn.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
#include "ipc/gameconn.h"
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
#include <stdlib.h>
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
#include <stdbool.h>
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
#include <assert.h>
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
// Callback function that will be called when the map is rendered
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
static void handleMapSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
	printf("Drawing map for %i brave little hogs...", numHedgehogs);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
	// Draw the map as ASCII art
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
	for(int y=0; y<MAPIMAGE_HEIGHT; y++) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
		for(int x=0; x<MAPIMAGE_WIDTH; x++) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
			int pixelnum = x + y*MAPIMAGE_WIDTH;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
			bool pixel = bitmap[pixelnum>>3] & (1<<(7-(pixelnum&7)));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
			printf(pixel ? "#" : " ");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
		}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
		printf("\n");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
	// Destroy the connection object (this will end the "tick" loop below)
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
	flib_mapconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
	flib_mapconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
static void onDisconnect(void *context, int reason) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
	flib_log_i("Connection closed. Reason: %i", reason);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
	flib_gameconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
	flib_gameconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
static void onGameRecorded(void *context, const uint8_t *record, int size, bool isSavegame) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	flib_log_i("Writing %s (%i bytes)...", isSavegame ? "savegame" : "demo", size);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
	FILE *file = fopen(isSavegame ? "testsave.42.hws" : "testdemo.42.hwd", "wb");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
	fwrite(record, 1, size, file);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
	fclose(file);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
// Callback function that will be called on error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
static void handleMapFailure(void *context, const char *errormessage) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	flib_log_e("Map rendering failed: %s", errormessage);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	// Destroy the connection object (this will end the "tick" loop below)
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
	flib_mapconn **connptr = context;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	flib_mapconn_destroy(*connptr);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
	*connptr = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
static void startEngineMap(int port) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	char commandbuffer[255];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	const char *enginePath = "C:\\Programmieren\\Hedgewars\\bin";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	const char *configPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
	snprintf(commandbuffer, 255, "start %s\\hwengine.exe %s %i landpreview", enginePath, configPath, port);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
	system(commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
static void startEngineGame(int port) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
	char commandbuffer[255];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
	const char *enginePath = "C:\\Programmieren\\Hedgewars\\bin";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
	const char *configPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
	const char *dataPath = "C:\\Programmieren\\Hedgewars\\share\\hedgewars\\Data";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
	snprintf(commandbuffer, 255, "start %s\\hwengine.exe %s 1024 768 32 %i 0 0 0 10 10 %s 0 0 TWVkbzQy 0 0 en.txt", enginePath, configPath, port, dataPath);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
	flib_log_d("Starting engine with CMD: %s", commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
	system(commandbuffer);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
void testMapPreview() {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
	// Create a map description and check that there was no error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	flib_map *map = flib_map_create_maze("Jungle", MAZE_SIZE_SMALL_TUNNELS);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
	assert(map);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
	// Create a new connection to the engine and check that there was no error
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
	flib_mapconn *mapConnection = flib_mapconn_create("This is the seed value", map);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
	assert(mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
	// We don't need the map description anymore
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
	flib_map_destroy(map);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
	map = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
	// Register the callback functions
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	flib_mapconn_onFailure(mapConnection, &handleMapFailure, &mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
	flib_mapconn_onSuccess(mapConnection, &handleMapSuccess, &mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
	// Start the engine process and tell it which port the frontlib is listening on
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
	startEngineMap(flib_mapconn_getport(mapConnection));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
	// Usually, flib_mapconn_tick will be called in an event loop that runs several
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
	// times per second. It handles I/O operations and progress, and calls
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
	// callbacks when something interesting happens.
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
	while(mapConnection) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
		flib_mapconn_tick(mapConnection);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
void testGame() {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
	flib_cfg_meta *metaconf = flib_cfg_meta_from_ini("basicsettings.ini", "gamemods.ini");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
	assert(metaconf);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
	flib_gamesetup setup;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
	setup.gamescheme = flib_cfg_from_ini(metaconf, "scheme_shoppa.ini");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
	setup.map = flib_map_create_maze("Jungle", MAZE_SIZE_MEDIUM_TUNNELS);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
	setup.seed = "apsfooasdgnds";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
	setup.script = NULL;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
	setup.teamcount = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
	setup.teams = calloc(2, sizeof(flib_team*));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
	setup.teams[0] = calloc(1, sizeof(flib_team));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
	setup.teams[0]->color = 0xffff0000;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
	setup.teams[0]->flag = "australia";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
	setup.teams[0]->fort = "Plane";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
	setup.teams[0]->grave = "Bone";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
	setup.teams[0]->hogsInGame = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
	setup.teams[0]->name = "Team Awesome";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
	setup.teams[0]->voicepack = "British";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
	setup.teams[0]->weaponset = flib_weaponset_create("Defaultweaps");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
	setup.teams[0]->hogs[0].difficulty = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
	setup.teams[0]->hogs[0].hat = "NoHat";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
	setup.teams[0]->hogs[0].initialHealth = 100;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
	setup.teams[0]->hogs[0].name = "Harry 120";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
	setup.teams[0]->hogs[1].difficulty = 2;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
	setup.teams[0]->hogs[1].hat = "chef";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
	setup.teams[0]->hogs[1].initialHealth = 100;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
	setup.teams[0]->hogs[1].name = "Chefkoch";
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
	setup.teams[1] = flib_team_from_ini("Cave Dwellers.hwt");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
	setup.teams[1]->color = 0xff0000ff;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
	setup.teams[1]->hogsInGame = 8;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
	setup.teams[1]->weaponset = flib_weaponset_create("Defaultweaps");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
	flib_gameconn *gameconn = flib_gameconn_create("Medo42", metaconf, &setup, false);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   134
	assert(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
	flib_gameconn_onDisconnect(gameconn, &onDisconnect, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   137
	flib_gameconn_onGameRecorded(gameconn, &onGameRecorded, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
	startEngineGame(flib_gameconn_getport(gameconn));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
	while(gameconn) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
		flib_gameconn_tick(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
void testDemo() {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
	FILE *demofile = fopen("testdemo.42.hwd", "rb");
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
	assert(demofile);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
	flib_vector *vec = flib_vector_create();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
	uint8_t demobuf[512];
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
	int len;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
	while((len=fread(demobuf, 1, 512, demofile))>0) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
		flib_vector_append(vec, demobuf, len);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
	fclose(demofile);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
	flib_constbuffer constbuf = flib_vector_as_constbuffer(vec);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
	flib_gameconn *gameconn = flib_gameconn_create_playdemo(constbuf.data, constbuf.size);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
	flib_vector_destroy(vec);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
	assert(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   160
	flib_gameconn_onDisconnect(gameconn, &onDisconnect, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   161
	flib_gameconn_onGameRecorded(gameconn, &onGameRecorded, &gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   162
	startEngineGame(flib_gameconn_getport(gameconn));
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
	while(gameconn) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   165
		flib_gameconn_tick(gameconn);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   166
	}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   167
}
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   168
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   169
int main(int argc, char *argv[]) {
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   170
	flib_init(0);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   171
	flib_log_setLevel(FLIB_LOGLEVEL_ALL);
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   172
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   173
	//testMapPreview();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   174
	testDemo();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   175
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   176
	flib_quit();
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   177
	return 0;
5143861c83bd Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
diff changeset
   178
}