int main(int argc, char const *argv[]) {
  double tf = 10, t0, dt;
  double g = 9.8, l = 1, ko, kw;
  double o0 = M_PI/4, w0 = 0, o1, w1;

  int n = 100000;

  dt = (tf - t0)/n;
  printf("t\ttheta\tomega\n");
  printf("%f\t%f\t%f\n", t0, o0, w0);

  while (t0 <= tf) {
    ko = fo(w0);
    kw = fw(o0);

    o1 = o0 + dt*fo(w0 + 0.5*dt*ko);
    w1 = w0 - dt*fw(o0 + 0.5*dt*kw);

    o0 = o1;
    w0 = w1;
    t0 += dt;

    printf("%f\t%f\t%f\n", t0, o0, w0);
  }
  return 0;
}
Beispiel #2
0
VideoScreen::VideoScreen(const UString &videoPath, sp<Stage> nextScreen)
    : Stage(), nextScreen(nextScreen)
{
	if (videoPath != "")
	{
		this->video = fw().data->loadVideo(videoPath);
		if (!this->video)
		{
			LogWarning("Failed to load video \"%s\"", videoPath);
		}
		else
		{
			// Scale keeping aspect ratio to the max of the screen size
			Vec2<float> unscaled_frame_size = this->video->getVideoSize();
			Vec2<float> display_size = fw().displayGetSize();
			Vec2<float> scale_factors = display_size / unscaled_frame_size;
			float scale = std::min(scale_factors.x, scale_factors.y);
			this->frame_size = unscaled_frame_size * scale;
			LogInfo("Scaling video from %s to %s", this->video->getVideoSize(), this->frame_size);
			this->frame_position = (fw().displayGetSize() / 2) - (this->frame_size / 2);
		}
	}
	else
	{
		LogInfo("No video");
	}
}
Beispiel #3
0
void MessageBox::eventOccurred(Event *e)
{
	form->eventOccured(e);

	if (e->type() == EVENT_FORM_INTERACTION)
	{
		if (e->forms().EventFlag == FormEventType::ButtonClick)
		{
			if (e->forms().RaisedBy->Name == "BUTTON_OK" ||
			    e->forms().RaisedBy->Name == "BUTTON_YES")
			{
				fw().stageQueueCommand({StageCmd::Command::POP});
				if (callbackYes)
					callbackYes();
				return;
			}
			else if (e->forms().RaisedBy->Name == "BUTTON_CANCEL" ||
			         e->forms().RaisedBy->Name == "BUTTON_NO")
			{
				fw().stageQueueCommand({StageCmd::Command::POP});
				if (callbackNo)
					callbackNo();
				return;
			}
		}
	}
}
Beispiel #4
0
void TextEdit::onRender()
{
	int xpos = align(TextHAlign, Size.x, font->getFontWidth(text));
	int ypos = align(TextVAlign, Size.y, font->getFontHeight());

	if (editing)
	{
		int cxpos = xpos + font->getFontWidth(text.substr(0, SelectionStart)) + 1;

		if (cxpos < 0)
		{
			xpos += cxpos;
			cxpos = xpos + font->getFontWidth(text.substr(0, SelectionStart)) + 1;
		}
		if (cxpos > Size.x)
		{
			xpos -= cxpos - Size.x;
			cxpos = xpos + font->getFontWidth(text.substr(0, SelectionStart)) + 1;
		}

		if (caretDraw)
		{
			auto textImage = font->getString(cursor);
			fw().renderer->draw(textImage, Vec2<float>{cxpos, ypos});
		}
	}

	auto textImage = font->getString(text);
	fw().renderer->draw(textImage, Vec2<float>{xpos, ypos});
}
Beispiel #5
0
VEquipScreen::VEquipScreen(sp<GameState> state)
    : Stage(), form(fw().gamecore->GetForm("FORM_VEQUIPSCREEN")), selected(nullptr),
      selectionType(VEquipmentType::Type::Weapon),
      pal(fw().data->load_palette("xcom3/UFODATA/VROADWAR.PCX")),
      labelFont(fw().gamecore->GetFont("SMALFONT")), highlightedVehicle(nullptr),
      highlightedEquipment(nullptr), drawHighlightBox(false), draggedEquipment(nullptr),
      state(state), glowCounter(0)

{
	form->FindControlTyped<RadioButton>("BUTTON_SHOW_WEAPONS")->SetChecked(true);
	sp<Vehicle> vehicle;
	for (auto &vehiclePtr : state->getPlayer()->vehicles)
	{
		vehicle = vehiclePtr.lock();
		if (vehicle)
			break;
		LogError("Invalid vehicle found in list - this should never happen as they're cleaned up "
		         "at the end of each city update?");
	}
	if (vehicle == nullptr)
	{
		LogError(
		    "No vehicles - 'original' apoc didn't allow the equip screen to appear in this case");
	}
	this->setSelectedVehicle(vehicle);
}
Beispiel #6
0
VideoScreen::VideoScreen(const UString &videoPath, std::future<void> task,
                         std::function<sp<Stage>()> nextScreenFn, sp<Image> background)
    : Stage(), loading_task(std::move(task)), nextScreenFn(nextScreenFn),
      backgroundimage(background)
{
	if (videoPath != "")
	{
		this->video = fw().data->loadVideo(videoPath);
		if (!this->video)
		{
			LogWarning("Failed to load video \"%s\"", videoPath.cStr());
		}
		else
		{
			// Scale keeping aspect ratio to the max of the screen size
			Vec2<float> unscaled_frame_size = this->video->getVideoSize();
			Vec2<float> display_size = fw().displayGetSize();
			Vec2<float> scale_factors = display_size / unscaled_frame_size;
			float scale = std::min(scale_factors.x, scale_factors.y);
			this->frame_size = unscaled_frame_size * scale;
			LogInfo("Scaling video from {%d,%d} to {%d,%d}", this->video->getVideoSize().x,
			        this->video->getVideoSize().y, this->frame_size.x, this->frame_size.y);
			this->frame_position = (fw().displayGetSize() / 2) - (this->frame_size / 2);
		}
	}
	else
	{
		LogInfo("No video");
	}
}
Beispiel #7
0
void ScrollBar::OnRender()
{
	// LoadResources();
	if (Minimum == Maximum)
		return;

	int pos = static_cast<int>(segmentsize * (Value - Minimum));
	Vec2<float> newpos, newsize;
	switch (BarOrientation)
	{
		case Orientation::Vertical:
			newpos = {0, pos};
			newsize = {Size.x, grippersize};
			break;
		case Orientation::Horizontal:
			newpos = {pos, 0};
			newsize = {grippersize, Size.y};
			break;
	}

	switch (RenderStyle)
	{
		case ScrollBarRenderStyles::SolidButtonStyle:
			fw().renderer->drawFilledRect(newpos, newsize, GripperColour);
			break;
		case ScrollBarRenderStyles::MenuButtonStyle:
			fw().renderer->draw(gripperbutton, newpos);
			break;
	}
}
Beispiel #8
0
void InGameOptions::Render()
{
	fw().Stage_GetPrevious(this->shared_from_this())->Render();
	fw().renderer->drawFilledRect({0, 0}, fw().Display_GetSize(), Colour{0, 0, 0, 128});
	menuform->Render();
	fw().gamecore->MouseCursor->Render();
}
int pack_exe(FILE *stream, char *msg)
{
 char lx[2];
 long patch_offset;
 int i;

 fseek(stream, 0L, SEEK_SET);
 if(fread(lx, 1, 2, stream)<2||memcmp(lx, "LX", 2))
 {
  printf("Not an unstubbed LX executable, can't pack\n");
  return(1);
 }
 fseek(stream, 0L, SEEK_END);
 patch_offset=ftell(stream);
 if(patch_offset>32870)
 {
  printf("The EXE file is too large\n");
  return(1);
 }
 fseek(stream, 8L, SEEK_SET);
 fc(0xEB); fc(0x7F);
 fseek(stream, 0x89L, SEEK_SET);
 fc(0xE9); fw(patch_offset-0x8C);
 fseek(stream, 0L, SEEK_END);
 fc(0xB4); fc(0x09);
 fc(0xBA); fw(patch_offset+0x109);
 fc(0xCD); fc(0x21);
 fc(0xCD); fc(0x20);
 fprintf(stream, "%s$", msg);
 return(0);
}
Beispiel #10
0
void VideoScreen::render()
{
	TRACE_FN;
	if (this->video)
	{
		auto time_now = std::chrono::high_resolution_clock::now();
		auto time_since_last_frame = time_now - this->last_frame_time;
		while (time_since_last_frame >= this->video->getFrameTime())
		{
			this->last_frame_time += video->getFrameTime();
			this->current_frame = this->video->popImage();

			if (!this->current_frame)
			{
				// End of video
				this->video = nullptr;
				break;
			}
			time_since_last_frame = time_now - this->last_frame_time;
		}
	}
	if (this->current_frame)
	{
		if (this->current_frame->palette)
			fw().renderer->setPalette(this->current_frame->palette);
		fw().renderer->drawScaled(this->current_frame->image, this->frame_position,
		                          this->frame_size, Renderer::Scaler::Nearest);
	}
}
void ResearchSelect::eventOccurred(Event *e)
{
	form->eventOccured(e);

	if (e->type() == EVENT_KEY_DOWN)
	{
		if (e->keyboard().KeyCode == SDLK_ESCAPE)
		{
			fw().stageQueueCommand({StageCmd::Command::POP});
			return;
		}
	}

	if (e->type() == EVENT_FORM_INTERACTION)
	{
		if (e->forms().EventFlag == FormEventType::ButtonClick)
		{
			if (e->forms().RaisedBy->Name == "BUTTON_OK")
			{
				fw().stageQueueCommand({StageCmd::Command::POP});
				return;
			}
		}
	}
}
Beispiel #12
0
sp<PaletteImage> BitmapFont::getString(const UString &Text)
{
	int height = this->getFontHeight();
	int width = this->getFontWidth(Text);
	int pos = 0;

	auto img = fw().data->getFontStringCacheEntry(this->name, Text);
	if (img)
		return img;

	img = mksp<PaletteImage>(Vec2<int>{width, height});

	auto u8Str = Text.str();
	auto pointString = boost::locale::conv::utf_to_utf<UniChar>(u8Str);

	for (size_t i = 0; i < pointString.length(); i++)
	{
		UniChar c = pointString[i];
		auto glyph = this->getGlyph(c);
		PaletteImage::blit(glyph, img, {0, 0}, {pos, 0});
		pos += glyph->size.x;
	}

	fw().data->putFontStringCacheEntry(this->name, Text, img);

	return img;
}
Beispiel #13
0
void Ticker::onRender()
{
	int xpos;
	int ypos;
	if (!animating)
	{
		xpos = align(TextHAlign, Size.x, font->getFontWidth(text));
		ypos = 0;

		auto textImage = font->getString(text);
		fw().renderer->draw(textImage, Vec2<float>{xpos, ypos});
	}
	else
	{
		UString out = text;
		xpos = align(TextHAlign, Size.x, font->getFontWidth(out));
		ypos = 0 - animTimer / 4;
		auto outImage = font->getString(out);
		fw().renderer->draw(outImage, Vec2<float>{xpos, ypos});

		if (!messages.empty())
		{
			UString in = messages.front();
			xpos = align(TextHAlign, Size.x, font->getFontWidth(in));
			ypos = 15 - animTimer / 4;
			auto inImage = font->getString(in);
			fw().renderer->draw(inImage, Vec2<float>{xpos, ypos});
		}
	}
}
Beispiel #14
0
void MessageBox::render()
{
	fw().stageGetPrevious(this->shared_from_this())->render();
	form->render();
	fw().renderer->drawRect(form->Location, form->Size, Colour{48, 48, 52});
	fw().renderer->drawRect(form->Location + 2, form->Size - 2, Colour{96, 100, 104});
	fw().renderer->drawRect(form->Location + 1, form->Size - 2, Colour{236, 236, 236});
}
Beispiel #15
0
void BaseScreen::render()
{
	fw().stageGetPrevious(this->shared_from_this())->render();
	fw().renderer->drawFilledRect({0, 0}, fw().displayGetSize(), Colour{0, 0, 0, 128});
	form->render();
	renderBase();
	BaseStage::render();
}
Beispiel #16
0
void BootUp::update()
{
	bool skipIntro = skipIntroOption.get();
	// The first forms instance causes it to get loaded
	sp<GameState> loadedState;
	std::future<void> loadTask;
	bool loadGame = false;

	if (loadGameOption.get().empty())
	{
		loadTask = fw().threadPoolEnqueue([]() {
			auto &ui_instance = ui();
			std::ignore = ui_instance;
		});
	}
	else
	{
		loadGame = true;
		auto path = loadGameOption.get();
		loadedState = mksp<GameState>();
		loadTask = fw().threadPoolEnqueue([loadedState, path]() {
			auto &ui_instance = ui();
			std::ignore = ui_instance;
			LogWarning("Loading save \"%s\"", path);

			if (!loadedState->loadGame(path))
			{
				LogError("Failed to load supplied game \"%s\"", path);
			}
			loadedState->initState();
		});
	}

	sp<Stage> nextScreen;
	if (loadGame == true)
	{
		nextScreen = mksp<LoadingScreen>(std::move(loadTask), [loadedState]() -> sp<Stage> {
			if (loadedState->current_battle)
			{
				return mksp<BattleView>(loadedState);
			}
			else
			{
				return mksp<CityView>(loadedState);
			}
		});
	}
	else
	{
		nextScreen = mksp<LoadingScreen>(std::move(loadTask),
		                                 []() -> sp<Stage> { return mksp<MainMenu>(); });
	}

	fw().stageQueueCommand(
	    {StageCmd::Command::REPLACE,
	     mksp<VideoScreen>(skipIntro ? "" : "SMK:xcom3/smk/intro1.smk", nextScreen)});
}
Beispiel #17
0
TextButton::TextButton(const UString &Text, sp<BitmapFont> font)
    : Control(), buttonclick(fw().data->loadSample(
                     "RAWSOUND:xcom3/RAWSOUND/STRATEGC/INTRFACE/BUTTON1.RAW:22050")),
      buttonbackground(fw().data->loadImage("UI/TEXTBUTTONBACK.PNG")),
      TextHAlign(HorizontalAlignment::Centre), TextVAlign(VerticalAlignment::Centre),
      RenderStyle(ButtonRenderStyle::Menu)
{
	label = mksp<Label>(Text, font);
}
Beispiel #18
0
void DebugMenu::Render()
{
    fw().Stage_GetPrevious(this->shared_from_this())->Render();
    fw().renderer->drawFilledRect(Vec2<float>(0, 0),
                                  Vec2<float>(fw().Display_GetWidth(), fw().Display_GetHeight()),
                                  Colour(0, 0, 0, 128));
    menuform->Render();
    fw().gamecore->MouseCursor->Render();
}
Beispiel #19
0
TileView::TileView(TileMap &map, Vec3<int> isoTileSize, Vec2<int> stratTileSize,
                   TileViewMode initialMode)
    : Stage(), map(map), isoTileSize(isoTileSize), stratTileSize(stratTileSize),
      viewMode(initialMode), dpySize(fw().displayGetWidth(), fw().displayGetHeight()),
      strategyViewBoxColour(212, 176, 172, 255), strategyViewBoxThickness(2.0f),
      selectedTilePosition(0, 0, 0), maxZDraw(map.size.z), centerPos(0, 0, 0),
      isoScrollSpeed(0.5, 0.5), stratScrollSpeed(2.0f, 2.0f)
{
	LogInfo("dpySize: %s", dpySize);
}
Beispiel #20
0
void VideoScreen::begin()
{
	last_frame_time = std::chrono::high_resolution_clock::now();
	if (this->video)
	{
		this->current_frame = this->video->popImage();

		fw().soundBackend->setTrack(video->getMusicTrack());
		fw().soundBackend->playMusic([](void *) {}, nullptr);
	}
}
Beispiel #21
0
ScrollBar::ScrollBar()
    : Control(), capture(false), grippersize(1), segmentsize(1),
      gripperbutton(fw().data->load_image(
          "PCK:XCOM3/UFODATA/NEWBUT.PCK:XCOM3/UFODATA/NEWBUT.TAB:4:UI/menuopt.pal")),
      buttonerror(fw().data->load_sample("RAWSOUND:xcom3/RAWSOUND/EXTRA/TEXTBEEP.RAW:22050")),
      Value(0), BarOrientation(Orientation::Vertical),
      RenderStyle(ScrollBarRenderStyles::MenuButtonStyle), GripperColour(220, 192, 192), Minimum(0),
      Maximum(10), LargeChange(2)
{
	// LoadResources();
}
Beispiel #22
0
InGameOptions::~InGameOptions()
{
	/* Store persistent options */

	fw().Settings->set("Audio.GlobalGain",
	                   menuform->FindControlTyped<ScrollBar>("GLOBAL_GAIN_SLIDER")->GetValue());
	fw().Settings->set("Audio.MusicGain",
	                   menuform->FindControlTyped<ScrollBar>("MUSIC_GAIN_SLIDER")->GetValue());
	fw().Settings->set("Audio.SampleGain",
	                   menuform->FindControlTyped<ScrollBar>("SAMPLE_GAIN_SLIDER")->GetValue());
}
Beispiel #23
0
void tst_factor_rewriter() {
    ast_manager m;
    m.register_decl_plugins();

    factor_rewriter_star fw(m);
    arith_util a(m);    
    expr_ref fml1(m), fml2(m);
    expr_ref z(m.mk_const(symbol("z"), a.mk_real()), m);
    expr_ref two(a.mk_numeral(rational(2),false),m);
    expr_ref zero(a.mk_numeral(rational(0),false),m);    
    fml1 = a.mk_le(zero, a.mk_mul(two, z, z));
    fw(fml1, fml2);
    std::cout << mk_pp(fml1, m) << " -> " << mk_pp(fml2, m) << "\n";
}
Beispiel #24
0
int KinshipHolder::saveDecomposed() {
  char buffer[1024];
  FileWriter fw(this->eigenFileName.c_str());
  const std::vector<std::string>& names = *this->pSample;
  const int nSample = (int)names.size();

  fw.write("IID\tLambda");
  for (int i = 0; i < nSample; ++i) {
    fw.printf("\tU%d", i + 1);
  }
  fw.write("\n");

  for (int i = 0; i < nSample; ++i) {
    fw.write(names[i].c_str());
    fw.write("\t");
    char* p = rapidjson::internal::dtoa(matS->mat(nSample - 1 - i), buffer);
    *p = '\0';
    fw.write(buffer);
    for (int j = 0; j < nSample; ++j) {
      char* p =
          rapidjson::internal::dtoa(matU->mat(i, nSample - 1 - j), buffer);
      *p = '\0';
      fw.write("\t");
      fw.write(buffer);
    }
    fw.write("\n");
  }
  return 0;
}
void BaseSelectScreen::Render()
{
	TileView::Render();
	for (auto b : state->current_city->buildings)
	{
		auto building = b.second;
		if (building->base_layout)
		{
			Vec3<float> posA = {building->bounds.p0.x, building->bounds.p0.y, 0};
			Vec2<float> screenPosA = this->tileToOffsetScreenCoords(posA);
			Vec3<float> posB = {building->bounds.p1.x, building->bounds.p1.y, 0};
			Vec2<float> screenPosB = this->tileToOffsetScreenCoords(posB);

			// Apply offset to borders every half-second
			if (counter >= COUNTER_MAX / 2)
			{
				screenPosA -= Vec2<float>{2.0f, 2.0f};
				screenPosB += Vec2<float>{2.0f, 2.0f};
			}

			Colour borderColour;
			if (building->owner == state->getPlayer())
			{
				borderColour = PLAYER_BASE_OWNED;
			}
			else if (building->owner.id == "ORG_GOVERNMENT")
			{
				borderColour = PLAYER_BASE_AVAILABLE;
			}
			fw().renderer->drawRect(screenPosA, screenPosB - screenPosA, borderColour, 2.0f);
		}
	}
	menuform->Render();
}
Beispiel #26
0
void InitialGameStateExtractor::extractBuildings(GameState &state, UString bldFileName,
                                                 sp<City> city)
{
	auto &data = this->ufo2p;

	auto fileName = "xcom3/ufodata/" + bldFileName + ".bld";

	auto inFile = fw().data->fs.open(fileName);
	if (!inFile)
	{
		LogError("Failed to open \"%s\"", fileName.c_str());
	}
	auto fileSize = inFile.size();
	auto bldCount = fileSize / sizeof(struct bld_file_entry);

	LogInfo("Loading %lu buildings from %s", (unsigned long)bldCount, fileName.c_str());

	for (unsigned i = 0; i < bldCount; i++)
	{
		struct bld_file_entry entry;
		inFile.read((char *)&entry, sizeof(entry));

		auto b = mksp<Building>();
		b->name = data.building_names->get(entry.name_idx);
		b->owner = {&state, data.get_org_id(entry.owner_idx)};
		// Our rects are exclusive of p2
		b->bounds = {entry.x0, entry.y0, entry.x1 + 1, entry.y1 + 1};
		auto id =
		    UString::format("%s%s", Building::getPrefix().c_str(), canon_string(b->name).c_str());

		city->buildings[id] = b;
	}
}
Beispiel #27
0
void VideoScreen::begin()
{
	// FIXME: This is now useless, as it doesn't actually load anything interesting here
	loadingimage = fw().data->loadImage("ui/loading.png");
	if (!backgroundimage)
	{
		backgroundimage = fw().data->loadImage("ui/logo.png");
	}
	fw().displaySetIcon();
	loadingimageangle = 0;
	last_frame_time = std::chrono::high_resolution_clock::now();
	this->current_frame = this->video->popImage();

	fw().soundBackend->setTrack(video->getMusicTrack());
	fw().soundBackend->playMusic([](void *) {}, nullptr);
}
Beispiel #28
0
GraphicButton::GraphicButton(sp<Image> image, sp<Image> imageDepressed, sp<Image> imageHover)
    : Control(), image(image), imagedepressed(imageDepressed), imagehover(imageHover),
      buttonclick(
          fw().data->loadSample("RAWSOUND:xcom3/rawsound/strategc/intrface/button1.raw:22050"))
{
	isClickable = true;
}
Beispiel #29
0
void GraphicButton::eventOccured(Event *e)
{
	Control::eventOccured(e);

	if (e->type() == EVENT_FORM_INTERACTION && e->forms().RaisedBy == shared_from_this() &&
	    e->forms().EventFlag == FormEventType::MouseDown)
	{
		if (buttonclick)
		{
			fw().soundBackend->playSample(buttonclick);
		}
	}

	if (e->type() == EVENT_FORM_INTERACTION && e->forms().RaisedBy == shared_from_this() &&
	    e->forms().EventFlag == FormEventType::MouseClick)
	{
		this->pushFormEvent(FormEventType::ButtonClick, e);

		if (ScrollBarPrev != nullptr)
		{
			ScrollBarPrev->scrollPrev(!scrollLarge);
		}

		if (ScrollBarNext != nullptr)
		{
			ScrollBarNext->scrollNext(!scrollLarge);
		}
	}
}
Beispiel #30
0
bool QPanel::forward(QMouseEvent *e)
{
	QPoint pos, globalPos = e->globalPos(), ref = editor()->viewport()->pos();
	
	if ( editor()->viewport()->parentWidget() )
		ref = editor()->viewport()->parentWidget()->mapToGlobal(ref);
	
	globalPos.setX(qBound(ref.x(), globalPos.x(), ref.x() + editor()->width()));
	globalPos.setY(qBound(ref.y(), globalPos.y(), ref.y() + editor()->height()));
	
	pos = editor()->viewport()->mapFromGlobal(globalPos);
	
	QMouseEvent fw(
					e->type(),
					pos,
					globalPos,
					e->button(),
					e->buttons(),
					e->modifiers()
				);
	
	bool ok = qApp->sendEvent(editor()->viewport(), &fw) && fw.isAccepted();
	
	//qDebug("forwarding mouse event : (%i, %i) => %i", pos.x(), pos.y(), ok);
	
	return ok;
}