added command line options
This commit is contained in:
parent
33d71e6ee4
commit
4ccc9cc647
13 changed files with 285 additions and 86 deletions
|
@ -1,3 +1,12 @@
|
|||
[theme]
|
||||
name=null
|
||||
|
||||
[resolution]
|
||||
width=1
|
||||
height=1
|
||||
[/resolution]
|
||||
[/theme]
|
||||
|
||||
[theme]
|
||||
name=Default
|
||||
|
||||
|
|
|
@ -985,6 +985,15 @@ void check_victory(std::map<gamemap::location,unit>& units,
|
|||
game_events::fire("enemies defeated");
|
||||
}
|
||||
|
||||
if(non_interactive()) {
|
||||
std::cout << "winner: ";
|
||||
for(std::vector<int>::const_iterator i = seen_leaders.begin(); i != seen_leaders.end(); ++i) {
|
||||
std::cout << *i << " ";
|
||||
}
|
||||
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
throw end_level_exception(found_human ? VICTORY : DEFEAT);
|
||||
}
|
||||
|
||||
|
|
10
src/ai.cpp
10
src/ai.cpp
|
@ -117,7 +117,7 @@ gamemap::location ai_interface::move_unit(location from, location to, std::map<l
|
|||
log_scope("move_unit");
|
||||
unit_map::iterator u_it = info_.units.find(from);
|
||||
if(u_it == info_.units.end()) {
|
||||
std::cout << "Could not find unit at " << from.x << ", "
|
||||
std::cerr << "Could not find unit at " << from.x << ", "
|
||||
<< from.y << "\n";
|
||||
assert(false);
|
||||
return location();
|
||||
|
@ -333,7 +333,7 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
std::vector<attack_analysis> analysis = analyze_targets(srcdst,dstsrc,enemy_srcdst,enemy_dstsrc);
|
||||
|
||||
int time_taken = SDL_GetTicks() - ticks;
|
||||
std::cout << "took " << time_taken << " ticks for " << analysis.size() << " positions. Analyzing...\n";
|
||||
std::cerr << "took " << time_taken << " ticks for " << analysis.size() << " positions. Analyzing...\n";
|
||||
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
|
@ -344,7 +344,7 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
if(num_sims > 40)
|
||||
num_sims = 40;
|
||||
|
||||
std::cout << "simulations: " << num_sims << "\n";
|
||||
std::cerr << "simulations: " << num_sims << "\n";
|
||||
|
||||
const int max_positions = 30000;
|
||||
const int skip_num = analysis.size()/max_positions;
|
||||
|
@ -356,7 +356,7 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
continue;
|
||||
|
||||
const double rating = it->rating(current_team().aggression());
|
||||
std::cout << "attack option rated at " << rating << " (" << current_team().aggression() << ")\n";
|
||||
std::cerr << "attack option rated at " << rating << " (" << current_team().aggression() << ")\n";
|
||||
if(rating > choice_rating) {
|
||||
choice_it = it;
|
||||
choice_rating = rating;
|
||||
|
@ -364,7 +364,7 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
|
|||
}
|
||||
|
||||
time_taken = SDL_GetTicks() - ticks;
|
||||
std::cout << "analysis took " << time_taken << " ticks\n";
|
||||
std::cerr << "analysis took " << time_taken << " ticks\n";
|
||||
|
||||
if(choice_rating > 0.0) {
|
||||
location from = choice_it->movements[0].first;
|
||||
|
|
|
@ -213,7 +213,7 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
}
|
||||
|
||||
if(u == units_.end()) {
|
||||
std::cout << "no eligible units found\n";
|
||||
std::cerr << "no eligible units found\n";
|
||||
return std::pair<location,location>();
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
|
||||
|
||||
if(best_target == targets.end()) {
|
||||
std::cout << "no eligible targets found\n";
|
||||
std::cerr << "no eligible targets found\n";
|
||||
return std::pair<location,location>();
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
}
|
||||
|
||||
if(best != units_.end()) {
|
||||
std::cout << "Could not make good move, staying still\n";
|
||||
std::cerr << "Could not make good move, staying still\n";
|
||||
|
||||
//this sounds like the road ahead might be dangerous, and that's why we don't advance.
|
||||
//create this as a target, attempting to rally units around
|
||||
|
@ -324,6 +324,6 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
return std::pair<location,location>(best->first,best->first);
|
||||
}
|
||||
|
||||
std::cout << "Could not find anywhere to move!\n";
|
||||
std::cerr << "Could not find anywhere to move!\n";
|
||||
return std::pair<location,location>();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,9 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
turbo_(false), grid_(false), sidebarScaling_(1.0),
|
||||
theme_(theme_cfg,screen_area())
|
||||
{
|
||||
if(non_interactive())
|
||||
updatesLocked_++;
|
||||
|
||||
energy_bar_rect_.x = -1;
|
||||
|
||||
create_buttons();
|
||||
|
@ -965,7 +968,7 @@ void display::draw_terrain_palette(int x, int y, gamemap::TERRAIN selected)
|
|||
}
|
||||
|
||||
if(x + image->w >= this->x() || y + image->h >= this->y()) {
|
||||
std::cout << "terrain palette can't fit: " << x + image->w << " > " << this->x() << " or " << y+image->h << " > " << this->y() << "\n";
|
||||
std::cerr << "terrain palette can't fit: " << x + image->w << " > " << this->x() << " or " << y+image->h << " > " << this->y() << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
253
src/game.cpp
253
src/game.cpp
|
@ -199,18 +199,24 @@ int play_game(int argc, char** argv)
|
|||
const image::manager image_manager;
|
||||
const events::event_context main_event_context;
|
||||
|
||||
bool test_mode = false;
|
||||
bool test_mode = false, multiplayer_mode = false, no_gui = false;
|
||||
|
||||
for(int arg = 1; arg != argc; ++arg) {
|
||||
int arg;
|
||||
for(arg = 1; arg != argc; ++arg) {
|
||||
const std::string val(argv[arg]);
|
||||
if(val.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(val == "--windowed" || val == "-w") {
|
||||
if(val == "--nogui") {
|
||||
no_gui = true;
|
||||
} else if(val == "--windowed" || val == "-w") {
|
||||
preferences::set_fullscreen(false);
|
||||
} else if(val == "--fullscreen" || val == "-f") {
|
||||
preferences::set_fullscreen(true);
|
||||
} else if(val == "--multiplayer") {
|
||||
multiplayer_mode = true;
|
||||
break; //parse the rest of the arguments when we set up the game
|
||||
} else if(val == "--test" || val == "-t") {
|
||||
test_mode = true;
|
||||
} else if(val == "--debug" || val == "-d") {
|
||||
|
@ -241,6 +247,11 @@ int play_game(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
if(no_gui && !multiplayer_mode) {
|
||||
std::cerr << "--nogui flag is only valid with --multiplayer flag\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
preproc_map defines_map;
|
||||
defines_map["NORMAL"] = preproc_define();
|
||||
std::vector<line_source> line_src;
|
||||
|
@ -276,76 +287,80 @@ int play_game(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
image::set_wm_icon();
|
||||
if(!no_gui) {
|
||||
image::set_wm_icon();
|
||||
|
||||
int video_flags = preferences::fullscreen() ? FULL_SCREEN : 0;
|
||||
int video_flags = preferences::fullscreen() ? FULL_SCREEN : 0;
|
||||
|
||||
std::pair<int,int> resolution = preferences::resolution();
|
||||
|
||||
std::cerr << "checking mode possible...\n";
|
||||
const int bpp = video.modePossible(resolution.first,resolution.second,
|
||||
16,video_flags);
|
||||
|
||||
std::cerr << bpp << "\n";
|
||||
|
||||
if(bpp == 0) {
|
||||
//Video mode not supported, maybe from bad prefs.
|
||||
std::cerr << "The video mode, " << resolution.first
|
||||
<< "x" << resolution.second << "x16 "
|
||||
<< "is not supported\nAttempting 1024x768x16...\n";
|
||||
|
||||
//Attempt 1024x768.
|
||||
resolution.first = 1024;
|
||||
resolution.second = 768;
|
||||
|
||||
int bpp = video.modePossible(resolution.first,resolution.second,16,video_flags);
|
||||
std::pair<int,int> resolution = preferences::resolution();
|
||||
|
||||
std::cerr << "checking mode possible...\n";
|
||||
const int bpp = video.modePossible(resolution.first,resolution.second,
|
||||
16,video_flags);
|
||||
|
||||
std::cerr << bpp << "\n";
|
||||
|
||||
if(bpp == 0) {
|
||||
//Attempt 1024x768.
|
||||
resolution.first = 1024;
|
||||
resolution.second = 768;
|
||||
std::cerr << "1024x768x16 is not possible.\nAttempting 800x600x16...\n";
|
||||
|
||||
resolution.first = 800;
|
||||
resolution.second = 600;
|
||||
|
||||
bpp = video.modePossible(resolution.first,resolution.second,16,video_flags);
|
||||
//Video mode not supported, maybe from bad prefs.
|
||||
std::cerr << "The video mode, " << resolution.first
|
||||
<< "x" << resolution.second << "x16 "
|
||||
<< "is not supported\nAttempting 1024x768x16...\n";
|
||||
|
||||
//Attempt 1024x768.
|
||||
resolution.first = 1024;
|
||||
resolution.second = 768;
|
||||
|
||||
int bpp = video.modePossible(resolution.first,resolution.second,16,video_flags);
|
||||
|
||||
if(bpp == 0) {
|
||||
//Attempt 1024x768.
|
||||
resolution.first = 1024;
|
||||
resolution.second = 768;
|
||||
std::cerr << "1024x768x16 is not possible.\nAttempting 800x600x16...\n";
|
||||
|
||||
resolution.first = 800;
|
||||
resolution.second = 600;
|
||||
|
||||
bpp = video.modePossible(resolution.first,resolution.second,16,video_flags);
|
||||
}
|
||||
|
||||
if(bpp == 0) {
|
||||
//couldn't do 1024x768 or 800x600
|
||||
|
||||
std::cerr << "The required video mode, " << resolution.first
|
||||
<< "x" << resolution.second << "x16 "
|
||||
<< "is not supported\n";
|
||||
|
||||
if((video_flags&FULL_SCREEN) != 0 && argc == 0)
|
||||
std::cerr << "Try running the program with the --windowed option "
|
||||
<< "using a 16bpp X windows setting\n";
|
||||
|
||||
if((video_flags&FULL_SCREEN) == 0 && argc == 0)
|
||||
std::cerr << "Try running with the --fullscreen option\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(bpp == 0) {
|
||||
//couldn't do 1024x768 or 800x600
|
||||
|
||||
std::cerr << "The required video mode, " << resolution.first
|
||||
<< "x" << resolution.second << "x16 "
|
||||
<< "is not supported\n";
|
||||
|
||||
if((video_flags&FULL_SCREEN) != 0 && argc == 0)
|
||||
std::cerr << "Try running the program with the --windowed option "
|
||||
<< "using a 16bpp X windows setting\n";
|
||||
|
||||
if((video_flags&FULL_SCREEN) == 0 && argc == 0)
|
||||
std::cerr << "Try running with the --fullscreen option\n";
|
||||
|
||||
|
||||
if(bpp != 16) {
|
||||
std::cerr << "Video mode must be emulated; the game may run slowly. "
|
||||
<< "For best results, run the program on a 16 bpp display\n";
|
||||
}
|
||||
|
||||
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "\n";
|
||||
const int res = video.setMode(resolution.first,resolution.second,16,video_flags);
|
||||
video.setBpp(bpp);
|
||||
if(res != 16) {
|
||||
std::cerr << "required video mode, " << resolution.first << "x"
|
||||
<< resolution.second << "x16 is not supported\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption(string_table["game_title"].c_str(), NULL);
|
||||
} else {
|
||||
video.make_fake();
|
||||
}
|
||||
|
||||
if(bpp != 16) {
|
||||
std::cerr << "Video mode must be emulated; the game may run slowly. "
|
||||
<< "For best results, run the program on a 16 bpp display\n";
|
||||
}
|
||||
|
||||
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "\n";
|
||||
const int res = video.setMode(resolution.first,resolution.second,16,video_flags);
|
||||
video.setBpp(bpp);
|
||||
if(res != 16) {
|
||||
std::cerr << "required video mode, " << resolution.first << "x"
|
||||
<< resolution.second << "x16 is not supported\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_WM_SetCaption(string_table["game_title"].c_str(), NULL);
|
||||
|
||||
for(;;) {
|
||||
sound::play_music(game_config::title_music);
|
||||
|
||||
|
@ -364,6 +379,116 @@ int play_game(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(multiplayer_mode) {
|
||||
|
||||
std::string scenario = "multiplayer_test";
|
||||
std::map<int,std::string> side_types, side_controllers, side_algorithms;
|
||||
|
||||
int sides_counted = 0;
|
||||
|
||||
for(++arg; arg < argc; ++arg) {
|
||||
const std::string val(argv[arg]);
|
||||
if(val.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> name_value = config::split(val,'=');
|
||||
if(name_value.size() == 2) {
|
||||
const std::string name = name_value.front();
|
||||
const std::string value = name_value.back();
|
||||
|
||||
const std::string name_head = name.substr(0,name.size()-1);
|
||||
const char name_tail = name[name.size()-1];
|
||||
const bool last_digit = isdigit(name_tail) ? true:false;
|
||||
const int side = name_tail - '0';
|
||||
|
||||
if(last_digit && side > sides_counted) {
|
||||
std::cerr << "counted sides: " << side << "\n";
|
||||
sides_counted = side;
|
||||
}
|
||||
|
||||
if(name == "--scenario") {
|
||||
scenario = value;
|
||||
} else if(last_digit && name_head == "--controller") {
|
||||
side_controllers[side] = value;
|
||||
} else if(last_digit && name_head == "--algorithm") {
|
||||
side_algorithms[side] = value;
|
||||
} else if(last_digit && name_head == "--side") {
|
||||
side_types[side] = value;
|
||||
} else {
|
||||
std::cerr << "unrecognized option: '" << name << "'\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const config* const lvl = game_config.find_child("multiplayer","id",scenario);
|
||||
if(lvl == NULL) {
|
||||
std::cerr << "Could not find scenario '" << scenario << "'\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
state.campaign_type = "multiplayer";
|
||||
state.scenario = "";
|
||||
state.starting_pos = config();
|
||||
|
||||
config level = *lvl;
|
||||
std::vector<config*> story;
|
||||
|
||||
const config* const side = game_config.child("multiplayer_side");
|
||||
if(side == NULL) {
|
||||
std::cerr << "Could not find side\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(level.get_children("side").size() < sides_counted) {
|
||||
std::cerr << "now adding side...\n";
|
||||
level.add_child("side");
|
||||
}
|
||||
|
||||
int side_num = 1;
|
||||
for(config::child_itors itors = level.child_range("side"); itors.first != itors.second; ++itors.first, ++side_num) {
|
||||
std::map<int,std::string>::const_iterator type = side_types.find(side_num),
|
||||
controller = side_controllers.find(side_num),
|
||||
algorithm = side_algorithms.find(side_num);
|
||||
|
||||
const config* side = type == side_types.end() ? game_config.child("multiplayer_side") :
|
||||
game_config.find_child("multiplayer_side","type",type->second);
|
||||
if(side == NULL) {
|
||||
std::string side_name = (type == side_types.end() ? "default" : type->second);
|
||||
std::cerr << "Could not find side '" << side_name << "' for side " << side_num << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
char buf[20];
|
||||
sprintf(buf,"%d",side_num);
|
||||
(*itors.first)->values["side"] = buf;
|
||||
|
||||
(*itors.first)->values["canrecruit"] = "1";
|
||||
|
||||
for(string_map::const_iterator i = side->values.begin(); i != side->values.end(); ++i) {
|
||||
(*itors.first)->values[i->first] = i->second;
|
||||
}
|
||||
|
||||
if(controller != side_controllers.end()) {
|
||||
(*itors.first)->values["controller"] = controller->second;
|
||||
}
|
||||
|
||||
if(algorithm != side_algorithms.end()) {
|
||||
(*itors.first)->values["ai_algorithm"] = controller->second;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
play_level(units_data,game_config,&level,video,state,story);
|
||||
} catch(...) {
|
||||
std::cerr << "caught error playing level...\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
recorder.clear();
|
||||
|
||||
gui::TITLE_RESULT res = gui::show_title(disp);
|
||||
|
|
|
@ -164,7 +164,7 @@ SDL_Surface* get_image(const std::string& filename, TYPE type, COLOUR_ADJUSTMENT
|
|||
}
|
||||
|
||||
if(pixel_format != NULL) {
|
||||
SDL_Surface* const conv = SDL_DisplayFormatAlpha(surf);
|
||||
SDL_Surface* const conv = display_format_alpha(surf);
|
||||
SDL_FreeSurface(surf);
|
||||
surf = conv;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ paths::route a_star_search(const gamemap::location& src,
|
|||
const gamemap::location& dst, double stop_at, T obj,
|
||||
const std::set<gamemap::location>* teleports=NULL)
|
||||
{
|
||||
std::cout << "a* search: " << src.x << ", " << src.y << " - " << dst.x << ", " << dst.y << "\n";
|
||||
std::cerr << "a* search: " << src.x << ", " << src.y << " - " << dst.x << ", " << dst.y << "\n";
|
||||
using namespace detail;
|
||||
typedef gamemap::location location;
|
||||
std::list<node> open_list, closed_list;
|
||||
|
@ -209,7 +209,7 @@ paths::route a_star_search(const gamemap::location& src,
|
|||
|
||||
assert(rt.steps.front() == src);
|
||||
|
||||
std::cout << "exiting a* search (solved)\n";
|
||||
std::cerr << "exiting a* search (solved)\n";
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ paths::route a_star_search(const gamemap::location& src,
|
|||
}
|
||||
}
|
||||
|
||||
std::cout << "aborted a* search\n";
|
||||
std::cerr << "aborted a* search\n";
|
||||
paths::route val;
|
||||
val.move_left = 100000;
|
||||
return val;
|
||||
|
|
|
@ -280,7 +280,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& game_config,
|
|||
}
|
||||
|
||||
int turn = 1;
|
||||
std::cout << "starting main loop\n";
|
||||
std::cerr << "starting main loop\n";
|
||||
for(bool first_time = true; true; first_time = false, first_player = 0) {
|
||||
int player_number = 0;
|
||||
|
||||
|
@ -521,6 +521,10 @@ redo_turn:
|
|||
|
||||
//time has run out
|
||||
if(!status.next_turn()) {
|
||||
if(non_interactive()) {
|
||||
std::cout << "time over (draw)\n";
|
||||
}
|
||||
|
||||
game_events::fire("time over");
|
||||
throw end_level_exception(DEFEAT);
|
||||
}
|
||||
|
|
|
@ -147,6 +147,9 @@ void set_resolution(const std::pair<int,int>& resolution)
|
|||
|
||||
bool turbo()
|
||||
{
|
||||
if(non_interactive())
|
||||
return true;
|
||||
|
||||
const string_map::const_iterator turbo = prefs.values.find("turbo");
|
||||
return turbo != prefs.values.end() && turbo->second == "true";
|
||||
}
|
||||
|
@ -361,6 +364,9 @@ const std::string& theme()
|
|||
if(res.empty())
|
||||
res = "Default";
|
||||
|
||||
if(non_interactive())
|
||||
res = "null";
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ SDL_Surface* clone_surface(SDL_Surface* surface)
|
|||
if(surface == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface* const result = SDL_DisplayFormatAlpha(surface);
|
||||
SDL_Surface* const result = display_format_alpha(surface);
|
||||
invalidate_sdl_surface_cache(surface);
|
||||
if(result == surface) {
|
||||
std::cerr << "resulting surface is the same as the source!!!\n";
|
||||
|
@ -683,7 +683,7 @@ struct SDL_BlitMap {
|
|||
|
||||
void invalidate_sdl_surface_cache(SDL_Surface* surf)
|
||||
{
|
||||
if(surf->map->dst != SDL_GetVideoSurface()) {
|
||||
if(surf->map->dst != get_video_surface()) {
|
||||
surf->map->dst = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,28 @@ void clear_updates()
|
|||
update_rects.clear();
|
||||
}
|
||||
|
||||
SDL_Surface* frameBuffer = NULL;
|
||||
|
||||
}
|
||||
|
||||
bool non_interactive()
|
||||
{
|
||||
return SDL_GetVideoSurface() == NULL;
|
||||
}
|
||||
|
||||
SDL_Surface* display_format_alpha(SDL_Surface* surf)
|
||||
{
|
||||
if(SDL_GetVideoSurface() != NULL)
|
||||
return SDL_DisplayFormatAlpha(surf);
|
||||
else if(frameBuffer != NULL)
|
||||
return SDL_ConvertSurface(surf,frameBuffer->format,0);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_Surface* get_video_surface()
|
||||
{
|
||||
return frameBuffer;
|
||||
}
|
||||
|
||||
void update_rect(size_t x, size_t y, size_t w, size_t h)
|
||||
|
@ -105,7 +127,7 @@ void update_rect(const SDL_Rect& rect_value)
|
|||
|
||||
SDL_Rect rect = rect_value;
|
||||
|
||||
SDL_Surface* const fb = SDL_GetVideoSurface();
|
||||
SDL_Surface* const fb = get_video_surface();
|
||||
if(fb != NULL) {
|
||||
if(rect.x < 0) {
|
||||
if(rect.x*-1 > int(rect.w))
|
||||
|
@ -157,7 +179,7 @@ void update_whole_screen()
|
|||
{
|
||||
update_all = true;
|
||||
}
|
||||
CVideo::CVideo() : frameBuffer(NULL), bpp(0)
|
||||
CVideo::CVideo() : bpp(0), fake_screen(false)
|
||||
{
|
||||
const int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
|
||||
|
||||
|
@ -168,7 +190,7 @@ CVideo::CVideo() : frameBuffer(NULL), bpp(0)
|
|||
}
|
||||
|
||||
CVideo::CVideo( int x, int y, int bits_per_pixel, int flags)
|
||||
: frameBuffer(NULL), bpp(0)
|
||||
: bpp(0), fake_screen(false)
|
||||
{
|
||||
const int res = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
|
||||
if(res < 0) {
|
||||
|
@ -183,6 +205,13 @@ CVideo::~CVideo()
|
|||
SDL_Quit();
|
||||
}
|
||||
|
||||
void CVideo::make_fake()
|
||||
{
|
||||
fake_screen = true;
|
||||
frameBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE,1,1,24,0xFF0000,0xFF00,0xFF,0);
|
||||
image::set_pixel_format(frameBuffer->format);
|
||||
}
|
||||
|
||||
int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags )
|
||||
{
|
||||
return SDL_VideoModeOK( x, y, bits_per_pixel, get_flags(flags) );
|
||||
|
@ -244,6 +273,9 @@ int CVideo::getBlueMask()
|
|||
|
||||
void CVideo::flip()
|
||||
{
|
||||
if(fake_screen)
|
||||
return;
|
||||
|
||||
if(update_all) {
|
||||
::SDL_Flip(frameBuffer);
|
||||
} else if(update_rects.empty() == false) {
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
#define VIDEO_MEMORY SDL_HWSURFACE
|
||||
#define SYSTEM_MEMORY SDL_SWSURFACE
|
||||
|
||||
SDL_Surface* display_format_alpha(SDL_Surface* surf);
|
||||
SDL_Surface* get_video_surface();
|
||||
|
||||
bool non_interactive();
|
||||
|
||||
|
||||
void update_rect(size_t x, size_t y, size_t w, size_t h);
|
||||
void update_rect(const SDL_Rect& rect);
|
||||
void update_whole_screen();
|
||||
|
@ -60,10 +66,15 @@ class CVideo {
|
|||
//functions to allow changing video modes when 16BPP is emulated
|
||||
void setBpp( int bpp );
|
||||
int getBpp();
|
||||
private:
|
||||
|
||||
SDL_Surface* frameBuffer;
|
||||
void make_fake();
|
||||
|
||||
private:
|
||||
|
||||
int bpp; // Store real bits per pixel
|
||||
|
||||
//if there is no display at all, but we 'fake' it for clients
|
||||
bool fake_screen;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue