hexsha
stringlengths
40
40
size
int64
7
1.05M
ext
stringclasses
13 values
lang
stringclasses
1 value
max_stars_repo_path
stringlengths
4
269
max_stars_repo_name
stringlengths
5
108
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
9
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
4
269
max_issues_repo_name
stringlengths
5
116
max_issues_repo_head_hexsha
stringlengths
40
40
max_issues_repo_licenses
listlengths
1
9
max_issues_count
float64
1
77k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
4
269
max_forks_repo_name
stringlengths
5
116
max_forks_repo_head_hexsha
stringlengths
40
40
max_forks_repo_licenses
listlengths
1
9
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
7
1.05M
avg_line_length
float64
1.21
653k
max_line_length
int64
6
990k
alphanum_fraction
float64
0.01
1
6577079424087467dfb544b8d563874f3a5262b1
1,162
cc
C++
Projects/Grafeo/attic/grafeo_20091012_qt/app/mainwindow.cc
fredmorcos/attic
0da3b94aa525df59ddc977c32cb71c243ffd0dbd
[ "Unlicense" ]
2
2021-01-24T09:00:51.000Z
2022-01-23T20:52:17.000Z
Projects/Grafeo/attic/grafeo_20091012_qt/app/mainwindow.cc
fredmorcos/attic
0da3b94aa525df59ddc977c32cb71c243ffd0dbd
[ "Unlicense" ]
6
2020-02-29T01:59:03.000Z
2022-02-15T10:25:40.000Z
Projects/Grafeo/attic/grafeo_20091012_qt/app/mainwindow.cc
fredmorcos/attic
0da3b94aa525df59ddc977c32cb71c243ffd0dbd
[ "Unlicense" ]
1
2019-03-22T14:41:21.000Z
2019-03-22T14:41:21.000Z
#include "mainwindow.h" #include <QFileDialog> MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { setupUi(this); tabWidget->removeTab(0); } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: retranslateUi(this); break; default: break; } } void MainWindow::closeEvent(QCloseEvent *event) { event->accept(); qApp->quit(); } void MainWindow::on_actionOpen_triggered() { QFileDialog fd(this, tr("Select File to Open")); fd.setFileMode(QFileDialog::ExistingFile); fd.setOption(QFileDialog::ReadOnly); fd.exec(); } void MainWindow::on_actionSave_triggered() { Document *document = DocumentManager::instance()->documentFromIndex( tabWidget->currentIndex()); if (document->fileName().isEmpty() == true) { QFileDialog fd(this, tr("Select Filename to Save")); fd.setFileMode(QFileDialog::AnyFile); connect(&fd, SIGNAL(fileSelected(QString)), this, SLOT(saveFileSelected(QString))); fd.exec(); } else DocumentManager::instance()->saveDocument(tabWidget->currentIndex(), } void MainWindow::saveFileSelected(const QString &filename) { }
19.366667
70
0.72031
65773eb4d3d4009263fbd5df2240e268355ac09a
309
cpp
C++
Decorator Pattern/Decorator Pattern/HouseBlend.cpp
mrlegowatch/HeadFirstDesignPatternsCpp
436ee8f0344b6a2ccfef6dcfa216a16a6ca7b482
[ "MIT" ]
43
2018-07-17T21:53:21.000Z
2022-03-23T13:15:06.000Z
Decorator Pattern/Decorator Pattern/HouseBlend.cpp
mrlegowatch/HeadFirstDesignPatternsCpp
436ee8f0344b6a2ccfef6dcfa216a16a6ca7b482
[ "MIT" ]
null
null
null
Decorator Pattern/Decorator Pattern/HouseBlend.cpp
mrlegowatch/HeadFirstDesignPatternsCpp
436ee8f0344b6a2ccfef6dcfa216a16a6ca7b482
[ "MIT" ]
14
2019-04-10T13:01:07.000Z
2022-03-08T13:19:14.000Z
// // HouseBlend.cpp // Decorator Pattern // // Created by Kevin Lee on 2/13/18. // Copyright © 2018 Brian Arnold. All rights reserved. // #include "HouseBlend.hpp" std::string HouseBlend::getDescription() const { return "House Blend Coffee"; } double HouseBlend::cost() const { return 0.89; }
17.166667
55
0.673139
657b0bd920f85fed566616a0e8c1eec48f75ca6c
9,204
cc
C++
tests/nonsmoke/functional/CompileTests/vxworks_tests/pond.cc
ouankou/rose
76f2a004bd6d8036bc24be2c566a14e33ba4f825
[ "BSD-3-Clause" ]
488
2015-01-09T08:54:48.000Z
2022-03-30T07:15:46.000Z
tests/nonsmoke/functional/CompileTests/vxworks_tests/pond.cc
WildeGeist/rose
17db6454e8baba0014e30a8ec23df1a11ac55a0c
[ "BSD-3-Clause" ]
174
2015-01-28T18:41:32.000Z
2022-03-31T16:51:05.000Z
tests/nonsmoke/functional/CompileTests/vxworks_tests/pond.cc
WildeGeist/rose
17db6454e8baba0014e30a8ec23df1a11ac55a0c
[ "BSD-3-Clause" ]
146
2015-04-27T02:48:34.000Z
2022-03-04T07:32:53.000Z
// Example code from VX Works #ifndef CPU // DQ: changed defalt from Sparc to PPC // #define CPU 10 #define CPU 91 #endif #include "vxWorks.h" #include "taskLib.h" #include "vxwSemLib.h" // Control the number of creatures in the pond #define MAX_FLIES 5 // The initial number of flies #define MAX_FROGS 2 // Same for frogs #define FROG_STARVED 3 // How long ot takes a frog to starve #define GRAB_CHANCE RAND_MAX / 2 // The probability of a frog catching a fly #define FLY_BIRTH_RATE RAND_MAX / 4 // The probability of a fly reproducing #define FROG_BIRTH_RATE RAND_MAX / 2 // Remeber here that frogs only give birth after they have eaten!! int fly_lifecycle(); int frog_lifecycle(); /****************************************************************************************/ /* Linked list thingy */ class node { public: class Fly *key; node *next; node() { key = NULL; next = NULL; } ~node() { key = NULL; next = NULL; } }; class List { private: node header; node end; public: List() { header.key = NULL; header.next = &end; end.key = NULL; end.next = &end; } void add(Fly *val) { node *tmp; // printf("\nAdding %X ",val); tmp = new node; tmp->next = header.next; tmp->key = val; header.next = tmp; //traverse(); } void remove(Fly *val) { node *previous, *current; //printf("\nRemoving %X ",val); previous = &header; current = previous->next; while(current->key != val && current != &end) { previous = current; current = current->next; } if(current->key == val) { previous->next = current->next; delete current; } //traverse(); } Fly *get() { Fly *tmp; tmp = header.next->key; //printf("\nGetting %X ",tmp); //traverse(); return tmp; } int empty() { if(header.next == &end) return 1; else return 0; } void traverse() { node *current; //printf("\n"); current = header.next; while(current != &end) { // printf("%X ",current->key); current = current->next; } } }; /*****************************************************************************************/ /* The pond class is basically a database or resource. Both flies and frogs will access */ /* the data and therefore proection is needed */ class Pond { private: int number_of_flies, number_of_frogs; List *flying_db; public: VXWBSem *fly_mutex; //mutex_t fly_mutex; Pond() { // mutex_init(&fly_mutex,NULL,NULL); fly_mutex = new VXWBSem(SEM_Q_PRIORITY,SEM_FULL); number_of_flies = 0; number_of_frogs = 0; flying_db = new List; } void lock() // { mutex_lock(&fly_mutex) } { fly_mutex->take(WAIT_FOREVER); } void unlock() // { mutex_unlock(&fly_mutex);} { fly_mutex->give(); } void fly_born() { number_of_flies++; } void fly_flying(Fly *id) { flying_db->add(id); } void fly_landed(Fly *id) { flying_db->remove(id); } /* void fly_died() { number_of_flies--; } */ void fly_died(Fly *id) { number_of_flies--; flying_db->remove(id); } Fly *flies_about() { if(!flying_db->empty()) return flying_db->get(); else return NULL; } }; /*************************************************************************************/ /* */ class Fly { private: enum { landed, flying, dead} status; int age; Pond *our_pond; VXWMSem *mutex; // mutex_t mutex; public: Fly(Pond *a_pond) { age = 3; status = landed; our_pond = a_pond; our_pond->lock(); our_pond->fly_born(); our_pond->unlock(); mutex = new VXWMSem(SEM_Q_PRIORITY); //mutex_init(&mutex,NULL,NULL); } void lock() // { mutex_lock(&mutex); } { mutex->take(WAIT_FOREVER); } void unlock() //{ mutex_unlock(&mutex); } { mutex->give(); } void fly_landed() { status = landed; our_pond->lock(); our_pond->fly_landed(this); our_pond->unlock(); } void fly_flying() { status = flying; our_pond->lock(); our_pond->fly_flying(this); // This will be change to a pointer to the fly shortly our_pond->unlock(); } void fly_dead() { status = dead; our_pond->lock(); our_pond->fly_died(this); our_pond->unlock(); } // DQ: Added return type. // fly_isdead() int fly_isdead() { if(status == dead) return 1; else return 0; } int get_age() { return age; } void happy_birthday() { age--; } int grab() { int result; if(status==flying && (rand() > GRAB_CHANCE)) { status = dead; our_pond->lock(); our_pond->fly_died(this); our_pond->unlock(); //fly_dead(); // Here I make use of implied 'this' and af the recursive mutual exclusion pointer result = 1; } else { result = 0; } return result; } }; /****************************************************************************/ /* This is the frog class */ class Frog { private: int last_meal; Pond *our_pond; public: Frog(Pond *a_pond) { last_meal = 0; our_pond = a_pond; } // DQ: Added return type. // starved() int starved() { if(last_meal>FROG_STARVED) return 1; else return 0; } void not_hungry() { last_meal = 0; } Fly *flies_about() { Fly *dummy; our_pond->lock(); dummy = our_pond->flies_about(); our_pond->unlock(); return dummy; } void no_dinner() { last_meal++; } void dead() { } }; /****************************************************************************/ /* This is the controlling code - 'main' function */ Pond *the_pond; // DQ: Added return type. // ostmain() int ostmain() { //thread_t tid[MAX_FROGS+MAX_FLIES]; //void *arg=NULL; int i; the_pond = new Pond; for( i=0; i<MAX_FLIES; i++) { // taskSpawn( NULL, 100, 0, 2000, fly_lifecycle, 0,0,0,0,0,0,0,0,0,0); taskSpawn( NULL, 100, 0, 2000, &fly_lifecycle, 0,0,0,0,0,0,0,0,0,0); //thr_create(NULL, NULL, fly_lifecycle, arg, NULL, &tid[i]); } for(i=0; i<MAX_FROGS; i++) { taskSpawn( NULL, 100, 0, 2000, frog_lifecycle, 0,0,0,0,0,0,0,0,0,0); //thr_create(NULL, NULL, frog_lifecycle, arg, NULL, &tid[MAX_FLIES+i]); } //while(thr_join(NULL,NULL,NULL)==0); return 0; } /***********************************************************************************/ /* Task that models/controls the life of the fly */ /* */ /***********************************************************************************/ int fly_lifecycle() { Fly fly(the_pond); int id; //thread_t *tid; //void *arg=NULL; // This is the life cycle - each time round the fly gets older while(fly.get_age()) { // the fly may have been eaten before it lands fly.lock(); if(!fly.fly_isdead()) { fly.unlock(); fly.lock(); fly.fly_landed(); fly.unlock(); // sleep(1); fly.lock(); fly.fly_flying(); fly.unlock(); if(rand() < FLY_BIRTH_RATE) { taskSpawn( NULL, 100, 0, 2000, fly_lifecycle, 0,0,0,0,0,0,0,0,0,0); //tid = new thread_t; //thr_create(NULL, NULL, fly_lifecycle, arg, NULL, tid); } //sleep(1); fly.lock(); fly.happy_birthday(); fly.unlock(); } else { fly.unlock(); return NULL; } } fly.lock(); fly.fly_dead(); fly.unlock(); return NULL; } /***********************************************************************************/ /* Task that models/controls the life of the fro */ /* */ /***********************************************************************************/ int frog_lifecycle() { Frog frog(the_pond); Fly *food; //thread_t *tid; //void *arg=NULL; while(!frog.starved()) { if((food = (Fly *)frog.flies_about()) != NULL) { food->lock(); if(food->grab()==1) // try to catch a fly and eat it. Then think about giving birth { frog.not_hungry(); if(rand() < FROG_BIRTH_RATE) { taskSpawn( NULL, 100, 0, 2000, frog_lifecycle, 0,0,0,0,0,0,0,0,0,0); // tid = new thread_t; //thr_create(NULL, NULL, frog_lifecycle, arg, NULL, tid); } } else frog.no_dinner(); food->unlock(); } else { // The frog gets closer to starving frog.no_dinner(); } // sleep(2); } frog.dead(); return NULL; }
18.631579
107
0.479791
657b6e05c0b450096ec97900a9be50fd856371f9
10,078
cpp
C++
eX0/src/PolyBoolean/pbpolys.cpp
shurcooL/eX0
425cdd4bace184bef3b63efa0867add4e469e291
[ "MIT" ]
54
2015-03-09T08:38:12.000Z
2021-06-20T15:54:57.000Z
eX0/src/PolyBoolean/pbpolys.cpp
shurcooL/eX0
425cdd4bace184bef3b63efa0867add4e469e291
[ "MIT" ]
7
2015-03-02T21:03:54.000Z
2017-12-21T06:06:00.000Z
eX0/src/PolyBoolean/pbpolys.cpp
shurcooL/eX0
425cdd4bace184bef3b63efa0867add4e469e291
[ "MIT" ]
10
2015-03-11T06:38:38.000Z
2021-05-10T04:35:33.000Z
// pbpolys.cpp - basic operations with vertices and polygons // // This file is a part of PolyBoolean software library // (C) 1998-1999 Michael Leonov // Consult your license regarding permissions and restrictions // // fix: 2006 Oct 2 Alexey Nikitin // PLINE2::Prepare / left middle point from 3 points on the same line #include "polybool.h" #include "pbimpl.h" #define SETBITS(n,mask,s) (((n)->Flags & ~(mask)) | ((s) & mask)) namespace POLYBOOLEAN { ////////////////////// class VNODE2 ///////////////////////////// VNODE2 * VNODE2::New(const GRID2 & g) { VNODE2 * res = (VNODE2 *)calloc(1, sizeof(VNODE2)); if (res == NULL) error(err_no_memory); res->g = g; res->prev = res->next = res; return res; } // VNODE2::New //////////////////// class PLINE2 ///////////////////////// local void AdjustBox(PLINE2 * pline, const GRID2 & g) { if (pline->gMin.x > g.x) pline->gMin.x = g.x; if (pline->gMin.y > g.y) pline->gMin.y = g.y; if (pline->gMax.x < g.x) pline->gMax.x = g.x; if (pline->gMax.y < g.y) pline->gMax.y = g.y; } // AdjustBox local bool GridInBox(const GRID2 & g, const PLINE2 * pline) { return (g.x > pline->gMin.x and g.y > pline->gMin.y and g.x < pline->gMax.x and g.y < pline->gMax.y); } // GridInBox local bool BoxInBox(const PLINE2 * c1, const PLINE2 * c2) { return (c1->gMin.x >= c2->gMin.x and c1->gMin.y >= c2->gMin.y and c1->gMax.x <= c2->gMax.x and c1->gMax.y <= c2->gMax.y); } // BoxInBox void PLINE2::Del(PLINE2 ** pline) { if (*pline == NULL) return; VNODE2 *vn; while ((vn = (*pline)->head->next) != (*pline)->head) vn->Excl(), free(vn); free(vn); free(*pline), *pline = NULL; } // PLINE2::Del PLINE2 * PLINE2::New(const GRID2 &g) { PLINE2 *res = (PLINE2 *)calloc(1, sizeof(PLINE2)); if (res == NULL) error(err_no_memory); try { res->head = VNODE2::New(g); } catch (int) { free(res); throw; } res->gMax = res->gMin = g; res->Count = 1; return res; } // PLINE2::New local void InclPlineVnode(PLINE2 *c, VNODE2 *vn) { assert(vn != NULL and c != NULL); vn->Incl(c->head->prev); c->Count++; AdjustBox(c, vn->g); } // InclPlineVnode void PLINE2::Incl(PLINE2 ** pline, const GRID2 & g) { if (*pline == NULL) *pline = PLINE2::New(g); else InclPlineVnode(*pline, VNODE2::New(g)); } // PLINE2::Incl PLINE2 * PLINE2::Copy(bool bMakeLinks) const { PLINE2 * dst = NULL; VNODE2* vn = head; try { do { Incl(&dst, vn->g); if (bMakeLinks) (vn->vn = dst->head->prev)->vn = vn; } while ((vn = vn->next) != head); } catch (int) { Del(&dst); throw; } dst->Count = Count; dst->Flags = Flags; dst->gMin = gMin; dst->gMax = gMax; return dst; } // PLINE2::Copy // returns if b lies on (a,c) local bool PointOnLine(const GRID2 & a, const GRID2 & b, const GRID2 & c) { return (INT64)(b.x - a.x) * (c.y - b.y) == (INT64)(b.y - a.y) * (c.x - b.x); } // PointOnLine bool PLINE2::Prepare() { gMin.x = gMax.x = head->g.x; gMin.y = gMax.y = head->g.y; // remove coincident vertices and those lying on the same line VNODE2 * p = head; VNODE2 * c = p->next; for (int test = 0, tests = Count; test < tests; ++test) { VNODE2 * n = c->next; if (PointOnLine(p->g, c->g, n->g)) { ++tests; if (n == head) ++tests; --Count; if (Count < 3) return false; if (c == head) head = p; c->Excl(), free(c); p = (c = p)->prev; } else { p = c; c = n; } } c = head; p = c->prev; INT64 nArea = 0; do { nArea += (INT64)(p->g.x - c->g.x) * (p->g.y + c->g.y); AdjustBox(this, c->g); } while ((c = (p = c)->next) != head); if (nArea == 0) return false; Flags = SETBITS(this, ORIENT, (nArea < 0) ? INV : DIR); return true; } // PLINE2::Prepare void PLINE2::Invert() { VNODE2 *vn = head, *next; do { next = vn->next, vn->next = vn->prev, vn->prev = next; } while ((vn = next) != head); Flags ^= ORIENT; } // PLINE2::Invert /********************** PAREA stuff **********************************/ PAREA *PAREA::New() { PAREA *res = (PAREA *)calloc(1, sizeof(PAREA)); if (res == NULL) error(err_no_memory); return res->f = res->b = res; } // PAREA::New local void ClearArea(PAREA *P) { PLINE2 *p; assert(P != NULL); while ((p = P->cntr) != NULL) { P->cntr = p->next; PLINE2::Del(&p); } free(P->tria), P->tria = NULL; P->tnum = 0; } // ClearArea void PAREA::Del(PAREA ** p) { if (*p == NULL) return; PAREA *cur; while ((cur = (*p)->f) != *p) { (cur->b->f = cur->f)->b = cur->b; ClearArea(cur); free(cur); } ClearArea(cur); free(cur), *p = NULL; } // PAREA::Del local void InclPareaPline(PAREA * p, PLINE2 * c) { assert(c->next == NULL); if (c->IsOuter()) { assert(p->cntr == NULL); p->cntr = c; } else { assert(p->cntr != NULL); c->next = p->cntr->next, p->cntr->next = c; } } // InclPareaPline void PAREA::InclParea(PAREA **list, PAREA *a) { if (a != NULL) { if (*list == NULL) *list = a; else (((a->b = (*list)->b)->f = a)->f = *list)->b = a; } } // PAREA::InclParea void PAREA::InclPline(PAREA ** area, PLINE2 * pline) { assert(pline != NULL and pline->next == NULL); PAREA * t; if (pline->IsOuter()) { t = New(); InclParea(area, t); } else { assert(*area != NULL); // find the smallest container for the hole t = NULL; PAREA * pa = *area; do { if (PlineInPline(pline, pa->cntr) and (t == NULL or PlineInPline(pa->cntr, t->cntr))) t = pa; } while ((pa = pa->f) != *area); if (t == NULL) // couldn't find a container for the hole error(err_bad_parm); } InclPareaPline(t, pline); } // PAREA::InclPline void PLINE2::Put(PLINE2 * pline, PAREA ** area, PLINE2 ** holes) { assert(pline->next == NULL); if (pline->IsOuter()) PAREA::InclPline(area, pline); else pline->next = *holes, *holes = pline; } // PLINE2::Put void PAREA::InsertHoles(PAREA ** area, PLINE2 ** holes) { if (*holes == NULL) return; if (*area == NULL) error(err_bad_parm); while (*holes != NULL) { PLINE2 * next = (*holes)->next; (*holes)->next = NULL; InclPline(area, *holes); *holes = next; } } // PAREA::InsertHoles local PAREA * PareaCopy0(const PAREA * area) { PAREA * dst = NULL; try { for (const PLINE2 * pline = area->cntr; pline != NULL; pline = pline->next) PAREA::InclPline(&dst, pline->Copy(true)); if (area->tria == NULL) return dst; dst->tria = (PTRIA2 *)calloc(area->tnum, sizeof(PTRIA2)); if (dst->tria == NULL) error(err_no_memory); } catch (int) { PAREA::Del(&dst); throw; } dst->tnum = area->tnum; for (UINT32 i = 0; i < area->tnum; i++) { PTRIA2 * td = dst->tria + i; PTRIA2 * ts = area->tria + i; td->v0 = ts->v0->vn; td->v1 = ts->v1->vn; td->v2 = ts->v2->vn; } return dst; } // PareaCopy0 PAREA * PAREA::Copy() const { PAREA * dst = NULL; const PAREA *src = this; try { do { PAREA *di = PareaCopy0(src); InclParea(&dst, di); } while ((src = src->f) != this); } catch (int) { Del(&dst); throw; } return dst; } // PAREA::Copy bool GridInPline(const GRID2 * g, const PLINE2 * outer) { if (outer == NULL) return false; if (!GridInBox(*g, outer)) return false; const VNODE2 *vn = outer->head; bool bInside = false; do { const GRID2 & vc = vn->g; const GRID2 & vp = vn->prev->g; if (vc.y <= g->y and g->y < vp.y and (INT64)(vp.y - vc.y) * (g->x - vc.x) < (INT64)(g->y - vc.y) * (vp.x - vc.x)) { bInside = not bInside; } else if (vp.y <= g->y and g->y < vc.y and (INT64)(vp.y - vc.y) * (g->x - vc.x) > (INT64)(g->y - vc.y) * (vp.x - vc.x)) { bInside = not bInside; } } while ((vn = vn->next) != outer->head); return bInside; } // GridInPline bool PlineInPline(const PLINE2 * p, const PLINE2 * outer) { assert(p != NULL); return outer != NULL && BoxInBox(p, outer) and GridInPline(&p->head->g, outer); } // PlineInPline typedef bool (*INSIDE_PROC)(const void *p, const PLINE2 *outer); local bool PolyInside(const void *p, const PAREA * outfst, INSIDE_PROC ins_actor) { const PAREA * pa = outfst; if (pa == NULL) return false; assert(p != NULL && pa != NULL); do { const PLINE2 *curc = pa->cntr; if (ins_actor(p, curc)) { while ((curc = curc->next) != NULL) if (ins_actor(p, curc)) goto Proceed; return true; } Proceed: ; } while ((pa = pa->f) != outfst); return false; } // PolyInside bool GridInParea(const GRID2 * g, const PAREA * outer) { return PolyInside(g, outer, (INSIDE_PROC)GridInPline); } // GridInParea bool PlineInParea(const PLINE2* p, const PAREA * outer) { return PolyInside(p, outer, (INSIDE_PROC)PlineInPline); } // PlineInParea #ifndef NDEBUG local bool Chk(INT32 x) { return INT20_MIN > x or x > INT20_MAX; } bool PAREA::CheckDomain() { PAREA * pa = this; do { for (PLINE2 * pline = pa->cntr; pline != NULL; pline = pline->next) { if (Chk(pline->gMin.x) or Chk(pline->gMin.y) or Chk(pline->gMax.x) or Chk(pline->gMax.y)) return false; } } while ((pa = pa->f) != this); return true; } // PAREA::CheckDomain #endif // NDEBUG } // namespace POLYBOOLEAN
21.261603
78
0.513991
6583b3d93fb5f4885db405c9f64563c26ccf25f8
5,709
hpp
C++
sources/SceneGraph/Animation/spAnimationJoint.hpp
rontrek/softpixel
73a13a67e044c93f5c3da9066eedbaf3805d6807
[ "Zlib" ]
14
2015-08-16T21:05:20.000Z
2019-08-21T17:22:01.000Z
sources/SceneGraph/Animation/spAnimationJoint.hpp
rontrek/softpixel
73a13a67e044c93f5c3da9066eedbaf3805d6807
[ "Zlib" ]
null
null
null
sources/SceneGraph/Animation/spAnimationJoint.hpp
rontrek/softpixel
73a13a67e044c93f5c3da9066eedbaf3805d6807
[ "Zlib" ]
3
2020-02-15T09:17:41.000Z
2020-05-21T14:10:40.000Z
/* * Animation bone header * * This file is part of the "SoftPixel Engine" (Copyright (c) 2008 by Lukas Hermanns) * See "SoftPixelEngine.hpp" for license information. */ #ifndef __SP_ANIMATION_BONE_H__ #define __SP_ANIMATION_BONE_H__ #include "Base/spStandard.hpp" #include "Base/spInputOutputString.hpp" #include "Base/spDimension.hpp" #include "Base/spMemoryManagement.hpp" #include "SceneGraph/spSceneMesh.hpp" #include "Base/spTransformation3D.hpp" #include "SceneGraph/Animation/spAnimationBaseStructures.hpp" #include <vector> namespace sp { namespace scene { class AnimationSkeleton; /** Animation joints are the foundation of animation skeletons (used for skeletal animations). \see AnimationSkeleton. \ingroup group_animation */ class SP_EXPORT AnimationJoint : public BaseObject { public: AnimationJoint( const Transformation &OriginTransform, const io::stringc Name = "" ); virtual ~AnimationJoint(); /* === Functions === */ //! Returns the global joint transformation. virtual dim::matrix4f getGlobalTransformation() const; //! Returns the final vertex transformation. Use this to transform the vertices by yourself. virtual dim::matrix4f getVertexTransformation() const; /* === Inline functions === */ /** Enables or disables the bone. If disabled the bone won't be transformed automatically by the animation but you can still transform it manual. By default enabled. \todo RENAME this to "setAutoTransform" */ inline void setEnable(bool Enable) // !TODO! -> RENAME this to "setAutoTransform" { isEnable_ = Enable; } inline bool getEnable() const { return isEnable_; } //! Returns a pointer to the AnimationJoint parent object. inline AnimationJoint* getParent() const { return Parent_; } //! Sets the vertex groups list. inline void setVertexGroups(const std::vector<SVertexGroup> &VertexGroups) { VertexGroups_ = VertexGroups; } inline const std::vector<SVertexGroup>& getVertexGroups() const { return VertexGroups_; } inline std::vector<SVertexGroup>& getVertexGroups() { return VertexGroups_; } //! Sets the new (local) origin transformation. Internally the origin transformation is stored as inverse matrix. inline void setOriginTransformation(const Transformation &Transform) { OriginTransform_ = Transform; } inline Transformation getOriginTransformation() const { return OriginTransform_; } //! Sets the new (local) current transformation. inline void setTransformation(const Transformation &Transform) { Transform_ = Transform; } inline const Transformation& getTransformation() const { return Transform_; } inline Transformation& getTransformation() { return Transform_; } //! Returns the final origin matrix which will be computed when the "AnimationSkeleton::updateSkeleton" function is called. inline dim::matrix4f getOriginMatrix() const { return OriginMatrix_; } //! Returns the joint children list. inline const std::vector<AnimationJoint*>& getChildren() const { return Children_; } protected: friend class AnimationSkeleton; /* === Functions === */ /** Transforms the vertices of the specified Mesh object. Which vertices will be transformed depends on the bone's vertex groups. \param[in] MeshObj Specifies the mesh object which vertices are to be transformed. This pointer must never be null! \param[in] BaseMatrix: Specifies the base matrix transformation. If the bone has a parent this matrix should be its parent's matrix transformation. \param[in] useTangentSpace: Specifies whether tanget space is used or not. \note The pointer is not checked for validity! */ void transformVertices(scene::Mesh* MeshObj, dim::matrix4f BaseMatrix, bool useTangentSpace) const; bool checkParentIncest(AnimationJoint* Joint) const; /* === Inline functions === */ inline void setParent(AnimationJoint* Parent) { Parent_ = Parent; } inline void addChild(AnimationJoint* Child) { Children_.push_back(Child); } inline void removeChild(AnimationJoint* Child) { MemoryManager::removeElement(Children_, Child); } private: /* === Members === */ bool isEnable_; AnimationJoint* Parent_; std::vector<AnimationJoint*> Children_; Transformation OriginTransform_; //!< Origin transformation. Transformation Transform_; //!< Current transformation. dim::matrix4f OriginMatrix_; //!< Final origin transformation matrix. Stored as inverse matrix for combining with the current transformation. std::vector<SVertexGroup> VertexGroups_; }; } // /namespace scene } // /namespace sp #endif // ================================================================================
29.890052
156
0.602207
65871db5c93f24650df9b1659e5d6c4b4852db33
5,497
cpp
C++
atcoder/marathon/rcl-contest-2020-qual/b.cpp
knuu/competitive-programming
16bc68fdaedd6f96ae24310d697585ca8836ab6e
[ "MIT" ]
1
2018-11-12T15:18:55.000Z
2018-11-12T15:18:55.000Z
atcoder/marathon/rcl-contest-2020-qual/b.cpp
knuu/competitive-programming
16bc68fdaedd6f96ae24310d697585ca8836ab6e
[ "MIT" ]
null
null
null
atcoder/marathon/rcl-contest-2020-qual/b.cpp
knuu/competitive-programming
16bc68fdaedd6f96ae24310d697585ca8836ab6e
[ "MIT" ]
null
null
null
#include <algorithm> #include <iostream> #include <vector> #include <chrono> #include <random> #include <tuple> #include <utility> #include <queue> #include <cstdio> #include <iomanip> const int dr[4] = {-1, 1, 0, 0}; const int dc[4] = {0, 0, -1, 1}; int N, M; std::vector<std::vector<int>> board, conn, tunnel; std::vector<std::vector<bool>> used; std::vector<int> conn_colors; int n_conn; const std::string DIR = "UDLR"; const int colors[4] = {0, 1, 2, 3}; int calc_score(std::vector<std::vector<int>> &ans) { int ret = 0; for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { ret += ans[r][c] == board[r][c]; } } return ret; } void input() { std::cin >> N >> M; board.resize(N); for (int i = 0; i < N; i++) { board[i].resize(N); for (int j = 0; j < N; j++) std::cin >> board[i][j]; } } void output(const std::vector<std::tuple<int, int, int>> &ans) { for (std::tuple<int, int, int> t : ans) { int r, c, d; std::tie(r, c, d) = t; if (r == -1) { std::cout << -1 << '\n'; } else { std::cout << r << ' ' << c << ' ' << DIR[d] << '\n'; } } } inline bool in_board(const int r, const int c) { return 0 <= r and r < N and 0 <= c and c < N; } void dfs(int r, int c, int color) { if (board[r][c] == color) { conn[r][c] = n_conn; } used[r][c] = true; for (int d = 0; d < 4; d++) { int nr = r + dr[d], nc = c + dc[d]; if (not in_board(nr, nc) or (board[nr][nc] != color and (tunnel[nr][nc] >> color & 1) == 0)) continue; if (used[nr][nc]) continue; dfs(nr, nc, color); } } void create_tunnel_sub() { conn.assign(N, std::vector<int>(N, -1)); conn_colors.clear(); n_conn = 0; /* 連結成分の色塗り */ for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { if (conn[r][c] == -1) { used.assign(N, std::vector<bool>(N, false)); dfs(r, c, board[r][c]); n_conn++; conn_colors.emplace_back(board[r][c]); } } } if (n_conn == 4) return; /* for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { std::cerr << std::setw(2) << conn[r][c]; } std::cerr << std::endl; } */ /* 各連結成分に対して、同じ色の連結成分が出るまで探索し、 1 番近い連結成分までトンネルを掘る */ for (int i = 0; i < n_conn; i++) { std::queue<std::tuple<int, int, int>> que; std::vector<std::vector<int>> dists(N, std::vector<int>(N, N * N)), prev(N, std::vector<int>(N, -1)); for (int r = 0; r < N; r++) for (int c = 0; c < N; c++) { if (conn[r][c] == i) que.emplace(r, c, 0), dists[r][c] = 0; } while (not que.empty()) { int r, c, dist; std::tie(r, c, dist) = que.front(); que.pop(); if (dists[r][c] < dist) continue; if (conn[r][c] != i and board[r][c] == conn_colors[i]) { int nr = prev[r][c] / N, nc = prev[r][c] % N; r = nr, c = nc; while (prev[r][c] != -1) { tunnel[r][c] |= 1 << conn_colors[i]; nr = prev[r][c] / N, nc = prev[r][c] % N; r = nr, c = nc; } break; } for (int i = 0; i < 4; i++) { int nr = r + dr[i], nc = c + dc[i]; if (in_board(nr, nc) and dists[nr][nc] > dist + 1) { dists[nr][nc] = dist + 1; prev[nr][nc] = r * N + c; que.emplace(nr, nc, dist + 1); } } } } } void create_tunnel() { tunnel.assign(N, std::vector<int>(N, 0)); while (true) { create_tunnel_sub(); if (n_conn == 4) break; } } void solve() { // create tunnnel create_tunnel(); ///* for (int i = 0; i < 4; i++) { for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { std::cerr << ((tunnel[r][c] >> i & 1) | (board[r][c] == i)); //for (int i = 0; i < 4; i++) std::cerr << (tunnel[r][c] >> i & 1); //std::cerr << ' '; //std::cerr << conn[r][c] << ' '; } std::cerr << '\n'; } std::cerr << '\n'; } //*/ // coloring greedy std::vector<std::vector<int>> colored(N, std::vector<int>(N, -1)); colored[0][0] = 0, colored[0][N-1] = 1, colored[N-1][0] = 2, colored[N-1][N-1] = 3; std::vector<std::tuple<int, int, int>> ans(M); for (int m = 0; m < M; m++) { int color = colors[m % 4]; int cr = -1, cc = -1, cd = -1, up_score = -1; for (int r = 0; r < N; r++) { for (int c = 0; c < N; c++) { if (colored[r][c] != color) continue; for (int d = 0; d < 4; d++) { int cand_score = 0; for (int res_cnt = 5, nr = r, nc = c; res_cnt >= 0 and in_board(nr, nc); res_cnt--, nr += dr[d], nc += dc[d]) { if (board[nr][nc] == color and (m >= M - 41 or tunnel[nr][nc] == 0)) cand_score += 10; if (colored[nr][nc] == board[nr][nc] and (m >= M - 41 or tunnel[nr][nc] == 0)) cand_score -= 10; if (m < M - 41 and (tunnel[nr][nc] >> color & 1) and colored[nr][nc] != color) cand_score += 3; if (colored[nr][nc] == -1) cand_score++; } if (cand_score > up_score) { cr = r, cc = c, cd = d; up_score = cand_score; } } } } if (cr != -1) { for (int res_cnt = 5, nr = cr, nc = cc; res_cnt >= 0 and in_board(nr, nc); res_cnt--, nr += dr[cd], nc += dc[cd]) { colored[nr][nc] = color; } } ans[m] = std::make_tuple(cr, cc, cd); } std::cerr << calc_score(colored) << '\n'; output(ans); } int main() { input(); n_conn = 0; solve(); return 0; }
26.814634
108
0.458978
658aabb1147a7a406e2f86a21215a02bc2ec3809
2,304
cpp
C++
ctable.cpp
Rescator7/Hearts
e72e46c5a1f90a0a553bf5527ee9a5aabf5154d7
[ "MIT" ]
13
2018-11-19T00:11:52.000Z
2022-03-31T20:01:49.000Z
ctable.cpp
Rescator7/Hearts
e72e46c5a1f90a0a553bf5527ee9a5aabf5154d7
[ "MIT" ]
3
2019-10-22T18:46:03.000Z
2022-03-31T18:16:48.000Z
ctable.cpp
Rescator7/Hearts
e72e46c5a1f90a0a553bf5527ee9a5aabf5154d7
[ "MIT" ]
2
2020-10-12T11:34:11.000Z
2021-01-21T07:12:56.000Z
#ifdef ONLINE_PLAY #include "ctable.h" #include "define.h" #include "ui_ctable.h" CTable::CTable(QWidget *parent) : QWidget(parent), ui(new Ui::CTable) { ui->setupUi(this); ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); setWindowTitle(tr("Tables list")); setAttribute( Qt::WA_QuitOnClose, false ); } CTable::~CTable() { delete ui; } void CTable::AddRow(QString id, QString flags) { int rowc = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowc); QTableWidgetItem *item_id = new QTableWidgetItem(id); ui->tableWidget->setItem(rowc, 0, item_id); QString s; int i = flags.toInt(); if (i & QUEEN_SPADE_f) s += "Q "; if (i & PERFECT_100_f) s += "P "; if (i & OMNIBUS_f) s += "O "; if (i & NO_TRICK_BONUS_f) s += "T "; if (i & NEW_MOON_f) s += "M "; if (!(i & NO_DRAW_f)) s += "D"; QTableWidgetItem *item_flags = new QTableWidgetItem(s); ui->tableWidget->setItem(rowc, 1, item_flags); for (int i=0; i<4; i++) { QTableWidgetItem *empty_item = new QTableWidgetItem(""); ui->tableWidget->setItem(rowc, i+2, empty_item); } } void CTable::Empty() { ui->tableWidget->setRowCount(0); } void CTable::RemoveRow(QString id) { int rowc = ui->tableWidget->rowCount(); for (int i=0; i<rowc; i++) { if (ui->tableWidget->item(i, 0)->text() == id) { ui->tableWidget->removeRow(i); // by removing a row, the index changes, don't forget to break. break; } } } void CTable::SetPlayer(QString id, QString name, QString chair) { int rowc = ui->tableWidget->rowCount(); int c = 0; if (chair == "n") c = 2; else if (chair == "s") c = 3; else if (chair == "w") c = 4; else if (chair == "e") c = 5; if (!c) return; for (int i=0; i<rowc; i++) { if (ui->tableWidget->item(i, 0)->text() == id) { ui->tableWidget->item(i, c)->setText(name); } } } void CTable::on_tableWidget_cellDoubleClicked(int row, int column) { int id = ui->tableWidget->item(row, 0)->text().toInt(); char chair = ' '; switch (column) { case 2: chair = 'n'; break; case 3: chair = 's'; break; case 4: chair = 'w'; break; case 5: chair = 'e'; break; } emit clicked(id, chair); } void CTable::Translate() { ui->retranslateUi(this); } #endif // ONLINE_PLAY
20.756757
100
0.608073
658b5f4b6f51da51cea226963cb6731dd35d2f88
13,245
cpp
C++
01_Develop/libXMCocos2D-v3/Source/3d/C3DScene.cpp
mcodegeeks/OpenKODE-Framework
d4382d781da7f488a0e7667362a89e8e389468dd
[ "MIT" ]
2
2017-08-03T07:15:00.000Z
2018-06-18T10:32:53.000Z
01_Develop/libXMCocos2D-v3/Source/3d/C3DScene.cpp
mcodegeeks/OpenKODE-Framework
d4382d781da7f488a0e7667362a89e8e389468dd
[ "MIT" ]
null
null
null
01_Develop/libXMCocos2D-v3/Source/3d/C3DScene.cpp
mcodegeeks/OpenKODE-Framework
d4382d781da7f488a0e7667362a89e8e389468dd
[ "MIT" ]
2
2019-03-04T22:57:42.000Z
2020-03-06T01:32:26.000Z
#include "3d/Base.h" #include "3d/C3DScene.h" #include "3d/C3DVector3.h" #include "3d/C3DRenderNode.h" #include "3d/C3DCamera.h" #include "3d/C3DLight.h" #include "3d/C3DSprite.h" #include "3d/C3DStaticObj.h" #include "3d/C3DBatchModel.h" #include "3d/C3DMaterial.h" #include "3d/MaterialParameter.h" #include "3d/C3DRenderChannel.h" #include "3d/C3DVertexFormat.h" #include "3d/C3DLayer.h" #include "3d/C3DBatchMesh.h" #include "3d/Vertex.h" #include "3d/C3DStat.h" #include "3d/C3DShadowMap.h" #include "3d/C3DRenderSystem.h" #include "3d/C3DViewport.h" #include "3d/C3DPostProcess.h" #include "3d/C3DGeoWireRender.h" namespace cocos3d { C3DNode* C3DScene::findNode(const char* strId) { return C3DNode::findNode(strId, true); } void C3DScene::removeAllNode() { SAFE_RELEASE(_activeLight); SAFE_RELEASE(_activeCamera); SAFE_RELEASE(_activeShadowMap); SAFE_RELEASE(_activePostProcess); removeAllChildren(); size_t i; for (i = 0; i < _lights.size(); i++) { SAFE_RELEASE(_lights[i]); } _lights.clear(); for (i = 0; i < _cameras.size(); i++) { SAFE_RELEASE(_cameras[i]); } _cameras.clear(); for (i = 0; i < _shadowMaps.size(); i++) { SAFE_RELEASE(_shadowMaps[i]); } _shadowMaps.clear(); for (i = 0; i < _postProcesss.size(); i++) { SAFE_RELEASE(_postProcesss[i]); } _postProcesss.clear(); } C3DScene::C3DScene(const char* str) : C3DNode(str) { _ambientColor = new C3DVector3(); _showBoundingBox = false; _showPosAxis = false; _showScaleAxis = false; _showLightPos = false; _activeCamera = NULL; _activeLight = NULL; _defDepthZ = 0.5f; _inShadowPass = false; _activeShadowMap = NULL; _activePostProcess = NULL; _layer = NULL; _geoWireRender = NULL; setScene(this); } C3DScene::~C3DScene() { SAFE_RELEASE(_activeCamera); SAFE_RELEASE(_activeLight); SAFE_DELETE(_ambientColor); removeAllNode(); SAFE_DELETE(_geoWireRender); } C3DScene* C3DScene::createScene(C3DLayer* layer) { C3DScene* scene = new C3DScene(); scene->_layer = layer; return scene; } C3DCamera* C3DScene::getActiveCamera() const { return _activeCamera; } //set active camera by index bool C3DScene::setActiveCamera(int index) { if (index < getCameraCount() ) { if (_activeCamera != _cameras[index]) { if (_activeCamera) _activeCamera->release(); _activeCamera = _cameras[index]; _activeCamera->retain(); _activeCamera->setAspectRatio((float)C3DRenderSystem::getInstance()->getViewport()->width/(float)C3DRenderSystem::getInstance()->getViewport()->height); } return true; } return false; } //get number of cameras in the scene int C3DScene::getCameraCount() const { return (int)_cameras.size(); } C3DLight* C3DScene::getLight(int index) { if(index < (int)_lights.size()) return _lights[index]; else return NULL; } void C3DScene::setViewAspectRatio(float aspectRatio) { if(getActiveCamera() != NULL) { getActiveCamera()->setAspectRatio(aspectRatio); } } const C3DVector3* C3DScene::getAmbientColor() const { return _ambientColor; } void C3DScene::setAmbientColor(float red, float green, float blue) { _ambientColor->set(red, green, blue); } void C3DScene::showBoundingBox(bool show) { _showBoundingBox = show; } void C3DScene::showLight(bool show) { _showLightPos = show; } void C3DScene::drawLights() { for (std::vector<C3DLight*>::iterator iter = _lights.begin(); iter != _lights.end(); ++iter) { C3DLight* light = *iter; C3DVector3 pos =light->getTranslationWorld(); C3DVector4 color; if (light->getLightType() == C3DLight::DIRECTIONAL) color = C3DVector4(1,0,0,1); else if (light->getLightType() == C3DLight::POINT) color = C3DVector4(0,1,0,1); else if (light->getLightType() == C3DLight::SPOT) color = C3DVector4(0,0,1,1); C3DVector3 offsetX(0.2f, 0.0f, 0.0f); C3DVector3 offsetY(0.0f, 0.2f, 0.0f); C3DVector3 offsetZ(0.0f, 0.0f, 0.2f); C3DGeoWireRender* render = getGeoWireRender(); render->add3DLine(pos + offsetX, pos - offsetX, color); render->add3DLine(pos + offsetY, pos - offsetY, color); render->add3DLine(pos + offsetZ, pos - offsetZ, color); } } C3DGeoWireRender* C3DScene::getGeoWireRender() { if (_geoWireRender == NULL) { _geoWireRender = new C3DGeoWireRender(); C3DNode* node = C3DNode::create("geowirerender"); this->addChild(node); _geoWireRender->init(node); } return _geoWireRender; } void C3DScene::drawDebug() { for (size_t i = 0; i < _children.size(); i++) { _children[i]->drawDebug(); } // show lights if (_showLightPos) drawLights(); if (_geoWireRender) _geoWireRender->flush(); } void C3DScene::preDraw() { C3DStat::getInstance()->beginStat(); C3DRenderSystem::getInstance()->getRenderChannelManager()->clearChannelItems(); if (_activeShadowMap && _activeShadowMap->active()) { _inShadowPass = true; _activeShadowMap->beginDraw(); //draw scene bool bStatEnable = C3DStat::getInstance()->isStatEnable(); for (size_t i = 0; i < _children.size(); ++i) { C3DNode* node = _children[i]; if(node->active()) { node->draw(); if (bStatEnable) C3DStat::getInstance()->incTriangleTotal(node->getTriangleCount()); } } _activeShadowMap->endDraw(); _inShadowPass = false; } //....posteffect start .... if (_activePostProcess && _activePostProcess->active()) { _activePostProcess->beginDraw(); } //....posteffect end....... } void C3DScene::draw() { // C3DNode::draw(); bool bStatEnable = C3DStat::getInstance()->isStatEnable(); size_t i; for (i = 0; i < _children.size(); ++i) { C3DNode* node = _children[i]; if(node->active()) { node->draw(); if (bStatEnable) C3DStat::getInstance()->incTriangleTotal(node->getTriangleCount()); } } } void C3DScene::drawCameraAndLight() { // to do.. draw cameras and lights } void C3DScene::postDraw() { C3DRenderSystem::getInstance()->getRenderChannelManager()->draw(); C3DStat::getInstance()->endStat(); //....posteffect start .... if (_activePostProcess && _activePostProcess->active()) { _activePostProcess->endDraw(); _activePostProcess->draw(); } //....posteffect end....... } // update routine void C3DScene::update(long elapsedTime) { //update children then // C3DNode::update(elapsedTime); size_t i; for (i = 0; i < _children.size(); ++i) { C3DNode* node = _children[i]; if(node->active()) node->update(elapsedTime); } if (_geoWireRender) _geoWireRender->begin(); } C3DNode::Type C3DScene::getType() const { return C3DNode::NodeType_Scene; } void C3DScene::addNodeToRenderList(C3DNode* node) { node->setScene(this); C3DNode::Type type = node->getType(); switch (type) { case C3DNode::NodeType_Camera: { bool found = false; for (std::vector<C3DCamera*>::iterator iter=_cameras.begin(); iter!=_cameras.end(); ++iter) { if (*iter == node) { found = true; break; } } if (found == false) { _cameras.push_back((C3DCamera*)node); node->retain(); } else { assert(false && "Duplicated camera node!"); } } break; case C3DNode::NodeType_Light: { bool found = false; for (std::vector<C3DLight*>::iterator iter=_lights.begin(); iter!=_lights.end(); ++iter) { if (*iter == node) { found = true; break; } } if (found == false) { _lights.push_back((C3DLight*)node); node->retain(); } else { assert(false && "Duplicated light node!"); } } break; case C3DNode::NodeType_ShadowMap: { bool found = false; for (std::vector<C3DShadowMap*>::iterator iter=_shadowMaps.begin(); iter!=_shadowMaps.end(); ++iter) { if (*iter == node) { found = true; break; } } if (found == false) { _shadowMaps.push_back((C3DShadowMap*)node); node->retain(); } else { assert(false && "Duplicated shadow map node!"); } } break; case C3DNode::NodeType_PostProcess: { bool found = false; for (std::vector<C3DPostProcess*>::iterator iter=_postProcesss.begin(); iter!=_postProcesss.end(); ++iter) { if (*iter == node) { found = true; break; } } if (found == false) { _postProcesss.push_back((C3DPostProcess*)node); node->retain(); } else { assert(false && "Duplicated posteffect node!"); } } break; default: break; } for (size_t i = 0; i < node->_children.size(); i++) { // addNodeToRenderList(node->_children[i]); } } void C3DScene::removeNodeFromRenderList(C3DNode* node) { node->setScene(NULL); for (size_t i = 0; i < node->_children.size(); i++) { // removeNodeFromRenderList(node->_children[i]); } C3DNode::Type type = node->getType(); switch (type) { case C3DNode::NodeType_Camera: { if ( _activeCamera == node) { assert(false && "removing active camera"); } std::vector<C3DCamera*>::iterator it = find(_cameras.begin(), _cameras.end(), (C3DCamera*)node); if (it != _cameras.end()) { _cameras.erase(it); node->release(); } else { assert(false && "unrefereed node"); } } break; case C3DNode::NodeType_Light: { std::vector<C3DLight*>::iterator it = find(_lights.begin(), _lights.end(), (C3DLight*)node); if (it != _lights.end()) { _lights.erase(it); node->release(); } else { assert(false && "unrefereed node"); } break; } case C3DNode::NodeType_ShadowMap: { std::vector<C3DShadowMap*>::iterator it = find(_shadowMaps.begin(), _shadowMaps.end(), (C3DShadowMap*)node); if (it != _shadowMaps.end()) { _shadowMaps.erase(it); node->release(); } else { assert(false && "unrefereed node"); } break; } case C3DNode::NodeType_PostProcess: { std::vector<C3DPostProcess*>::iterator it = find(_postProcesss.begin(), _postProcesss.end(), (C3DPostProcess*)node); if (it != _postProcesss.end()) { _postProcesss.erase(it); node->release(); } else { assert(false && "unrefereed node"); } break; } default: break; } } void C3DScene::onChildChanged(ChangeEvent eventType, C3DNode* child) { switch (eventType) { case C3DNode::ADD: addNodeToRenderList(child); break; case C3DNode::REMOVE: removeNodeFromRenderList(child); break; } } const C3DMatrix& C3DScene::getViewProjectionMatrix() const { if (_inShadowPass) { CCAssert(_activeShadowMap, "active shadow map!"); return _activeShadowMap->getViewProjectionMatrix(); } else { if (_activeCamera) return _activeCamera->getViewProjectionMatrix(); else return C3DMatrix::identity(); } } C3DShadowMap* C3DScene::getActiveShadowMap() const { return _activeShadowMap; } C3DShadowMap* C3DScene::setActiveShadowMap(int index) { C3DShadowMap* sm; if (index >= 0 && index < (int)_shadowMaps.size()) sm = _shadowMaps[index]; else sm = NULL; if (sm != _activeShadowMap) { SAFE_RELEASE(_activeShadowMap); _activeShadowMap = sm; _activeShadowMap->retain(); } return _activeShadowMap; } int C3DScene::GetShadowMapCount() const { return (int)_shadowMaps.size(); } C3DPostProcess* C3DScene::getActivePostProcess() const { return _activePostProcess; } C3DPostProcess* C3DScene::setActivePostProcess(int index) { C3DPostProcess* pp; if (index >= 0 && index < (int)_postProcesss.size()) pp = _postProcesss[index]; else pp = NULL; if(pp == NULL) { SAFE_RELEASE(_activePostProcess); } else if (pp != _activePostProcess) { SAFE_RELEASE(_activePostProcess); _activePostProcess = pp; _activePostProcess->retain(); } return _activePostProcess; } C3DLayer* C3DScene::getLayer() const { return _layer; } void C3DScene::setLayer(C3DLayer* layer) { if (layer != _layer) { SAFE_RELEASE(_layer); _layer = layer; if (layer) { layer->retain(); } } } }
20.598756
156
0.588373
6590b799fd04541ed819819c4b6bac8f524eba26
687
cpp
C++
src/script_interface/DropSourceAction.cpp
kbuffington/foo_jscript_panel
8e8375c109595b18e624e8709ee6d84effba66b4
[ "MIT" ]
15
2020-02-20T19:39:54.000Z
2022-02-06T10:03:00.000Z
src/script_interface/DropSourceAction.cpp
kbuffington/foo_jscript_panel
8e8375c109595b18e624e8709ee6d84effba66b4
[ "MIT" ]
1
2020-04-26T04:02:44.000Z
2020-04-26T04:02:44.000Z
src/script_interface/DropSourceAction.cpp
kbuffington/foo_jscript_panel
8e8375c109595b18e624e8709ee6d84effba66b4
[ "MIT" ]
2
2020-04-24T11:09:45.000Z
2021-05-21T08:41:39.000Z
#include "stdafx.h" #include "DropSourceAction.h" DropSourceAction::DropSourceAction() {} DropSourceAction::~DropSourceAction() {} void DropSourceAction::FinalRelease() {} STDMETHODIMP DropSourceAction::get_Effect(UINT* p) { if (!p) return E_POINTER; *p = m_effect; return S_OK; } STDMETHODIMP DropSourceAction::put_Base(UINT base) { m_base = base; return S_OK; } STDMETHODIMP DropSourceAction::put_Effect(UINT effect) { m_effect = effect; return S_OK; } STDMETHODIMP DropSourceAction::put_Playlist(UINT id) { m_playlist_idx = id; return S_OK; } STDMETHODIMP DropSourceAction::put_ToSelect(VARIANT_BOOL select) { m_to_select = select != VARIANT_FALSE; return S_OK; }
16.756098
64
0.756914
6590d71a0949a66233120069104b8f4dc05e9e49
991
cpp
C++
UVa/11241.cpp
tico88612/Solution-Note
31a9d220fd633c6920760707a07c9a153c2f76cc
[ "MIT" ]
1
2018-02-11T09:41:54.000Z
2018-02-11T09:41:54.000Z
UVa/11241.cpp
tico88612/Solution-Note
31a9d220fd633c6920760707a07c9a153c2f76cc
[ "MIT" ]
null
null
null
UVa/11241.cpp
tico88612/Solution-Note
31a9d220fd633c6920760707a07c9a153c2f76cc
[ "MIT" ]
null
null
null
#include <bits/stdc++.h> using namespace std; double T=-999999,D=-999999,H=-999999; double dohum(double tt,double dd){ double ee=6.11*exp(5417.7530*((1/273.16)-(1/(dd+273.16)))); double hh=(0.5555)*(ee-10.0); return tt+hh; } double dotemp(){ double ee=6.11*exp(5417.7530*((1/273.16)-(1/(D+273.16)))); double hh=(0.5555)*(ee-10.0); return H-hh; } double dodew(){ double ans=0; double delta=100; for(delta=100;delta>0.00001;delta*=0.5){ if(dohum(T,ans)>H) ans-=delta; else ans+=delta; } return ans; } int main(){ char e1,e2; double t1,t2; while(scanf(" %c",&e1)&&e1!='E'){ scanf("%lf %c %lf",&t1,&e2,&t2); if(e1=='T') T=t1; else if(e1=='D') D=t1; else if(e1=='H') H=t1; if(e2=='T') T=t2; else if(e2=='D') D=t2; else if(e2=='H') H=t2; if(T==-999999) T=dotemp(); else if(D==-999999) D=dodew(); else if(H==-999999) H=dohum(T,D); printf("T %0.1lf D %0.1lf H %0.1lf\n",T,D,H); T=-999999; D=-999999; H=-999999; } return 0; }
19.057692
60
0.565086
6594a2eb329a534b7fef1a53777d488e87f37a03
76,327
cpp
C++
source/ff.graphics/source/draw_device.cpp
spadapet/ff_game_library
f1bf00f90adde66c2c2aa35b109fe61b8d2c6352
[ "MIT" ]
null
null
null
source/ff.graphics/source/draw_device.cpp
spadapet/ff_game_library
f1bf00f90adde66c2c2aa35b109fe61b8d2c6352
[ "MIT" ]
null
null
null
source/ff.graphics/source/draw_device.cpp
spadapet/ff_game_library
f1bf00f90adde66c2c2aa35b109fe61b8d2c6352
[ "MIT" ]
null
null
null
#include "pch.h" #include "depth.h" #include "draw_device.h" #include "graphics.h" #include "matrix.h" #include "matrix_stack.h" #include "palette_data.h" #include "shader.h" #include "sprite_data.h" #include "sprite_type.h" #include "target_base.h" #include "texture.h" #include "texture_view_base.h" #include "transform.h" #include "vertex.h" #if DXVER == 11 static const size_t MAX_TEXTURES = 32; static const size_t MAX_TEXTURES_USING_PALETTE = 32; static const size_t MAX_PALETTES = 128; // 256 color palettes only static const size_t MAX_PALETTE_REMAPS = 128; // 256 entries only static const size_t MAX_TRANSFORM_MATRIXES = 1024; static const size_t MAX_RENDER_COUNT = 524288; // 0x00080000 static const float MAX_RENDER_DEPTH = 1.0f; static const float RENDER_DEPTH_DELTA = ::MAX_RENDER_DEPTH / ::MAX_RENDER_COUNT; static std::array<ID3D11ShaderResourceView*, ::MAX_TEXTURES + ::MAX_TEXTURES_USING_PALETTE + 2 /* palette + remap */> NULL_TEXTURES{}; static std::array<uint8_t, ff::constants::palette_size> DEFAULT_PALETTE_REMAP = { 0, 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, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, }; static size_t DEFAULT_PALETTE_REMAP_HASH = ff::stable_hash_bytes(::DEFAULT_PALETTE_REMAP.data(), ff::array_byte_size(::DEFAULT_PALETTE_REMAP)); namespace { enum class alpha_type { opaque, transparent, invisible, }; enum class last_depth_type { none, nudged, line, circle, triangle, sprite, line_no_overlap, circle_no_overlap, triangle_no_overlap, sprite_no_overlap, start_no_overlap = line_no_overlap, }; enum class geometry_bucket_type { lines, circles, triangles, sprites, palette_sprites, lines_alpha, circles_alpha, triangles_alpha, sprites_alpha, count, first_alpha = lines_alpha, }; class geometry_bucket { private: geometry_bucket( ::geometry_bucket_type bucket_type, const std::type_info& item_type, size_t item_size, size_t item_align, const D3D11_INPUT_ELEMENT_DESC* element_desc, size_t element_count) : bucket_type_(bucket_type) , item_type_(&item_type) , item_size_(item_size) , item_align(item_align) , render_start_(0) , render_count_(0) , data_start(nullptr) , data_cur(nullptr) , data_end(nullptr) , element_desc(element_desc) , element_count(element_count) {} public: template<typename T, ::geometry_bucket_type BucketType> static ::geometry_bucket create() { return ::geometry_bucket(BucketType, typeid(T), sizeof(T), alignof(T), T::layout().data(), T::layout().size()); } geometry_bucket(::geometry_bucket&& rhs) noexcept : vs_res(std::move(rhs.vs_res)) , gs_res(std::move(rhs.gs_res)) , ps_res(std::move(rhs.ps_res)) , ps_palette_out_res(std::move(rhs.ps_palette_out_res)) , layout(std::move(rhs.layout)) , vs(std::move(rhs.vs)) , gs(std::move(rhs.gs)) , ps(std::move(rhs.ps)) , ps_palette_out(std::move(rhs.ps_palette_out)) , element_desc(rhs.element_desc) , element_count(rhs.element_count) , bucket_type_(rhs.bucket_type_) , item_type_(rhs.item_type_) , item_size_(rhs.item_size_) , item_align(rhs.item_align) , render_start_(0) , render_count_(0) , data_start(rhs.data_start) , data_cur(rhs.data_cur) , data_end(rhs.data_end) { rhs.data_start = nullptr; rhs.data_cur = nullptr; rhs.data_end = nullptr; } ~geometry_bucket() { ::_aligned_free(this->data_start); } void reset(std::string_view vs_res, std::string_view gs_res, std::string_view ps_res, std::string_view ps_palette_out_res) { this->reset(); this->vs_res = ff::global_resources::get(vs_res); this->gs_res = ff::global_resources::get(gs_res); this->ps_res = ff::global_resources::get(ps_res); this->ps_palette_out_res = ff::global_resources::get(ps_palette_out_res); } void reset() { this->layout.Reset(); this->vs.Reset(); this->gs.Reset(); this->ps.Reset(); this->ps_palette_out.Reset(); ::_aligned_free(this->data_start); this->data_start = nullptr; this->data_cur = nullptr; this->data_end = nullptr; } void apply(ID3D11Buffer* geometry_buffer, bool palette_out) const { const_cast<::geometry_bucket*>(this)->create_shaders(palette_out); ff_dx::device_state& state = ff_dx::get_device_state(); state.set_vertex_ia(geometry_buffer, item_size(), 0); state.set_layout_ia(this->layout.Get()); state.set_vs(this->vs.Get()); state.set_gs(this->gs.Get()); state.set_ps(palette_out ? this->ps_palette_out.Get() : this->ps.Get()); } void* add(const void* data = nullptr) { if (this->data_cur == this->data_end) { size_t cur_size = this->data_end - this->data_start; size_t new_size = std::max<size_t>(cur_size * 2, this->item_size_ * 64); this->data_start = reinterpret_cast<uint8_t*>(_aligned_realloc(this->data_start, new_size, this->item_align)); this->data_cur = this->data_start + cur_size; this->data_end = this->data_start + new_size; } if (this->data_cur && data) { std::memcpy(this->data_cur, data, this->item_size_); } void* result = this->data_cur; this->data_cur += this->item_size_; return result; } size_t item_size() const { return this->item_size_; } const std::type_info& item_type() const { return *this->item_type_; } ::geometry_bucket_type bucket_type() const { return this->bucket_type_; } size_t count() const { return (this->data_cur - this->data_start) / this->item_size_; } void clear_items() { this->data_cur = this->data_start; } size_t byte_size() const { return this->data_cur - this->data_start; } const uint8_t* data() const { return this->data_start; } void render_start(size_t start) { this->render_start_ = start; this->render_count_ = this->count(); } size_t render_start() const { return this->render_start_; } size_t render_count() const { return this->render_count_; } private: void create_shaders(bool palette_out) { if (!this->vs) { this->vs = ff_dx::get_object_cache().get_vertex_shader_and_input_layout(this->vs_res.resource()->name(), this->layout, this->element_desc, this->element_count); } if (!this->gs) { this->gs = ff_dx::get_object_cache().get_geometry_shader(this->gs_res.resource()->name()); } Microsoft::WRL::ComPtr<ID3D11PixelShader>& ps = palette_out ? this->ps_palette_out : this->ps; if (!ps) { ps = ff_dx::get_object_cache().get_pixel_shader(palette_out ? this->ps_palette_out_res.resource()->name() : this->ps_res.resource()->name()); } } ff::auto_resource<ff::shader> vs_res; ff::auto_resource<ff::shader> gs_res; ff::auto_resource<ff::shader> ps_res; ff::auto_resource<ff::shader> ps_palette_out_res; Microsoft::WRL::ComPtr<ID3D11InputLayout> layout; Microsoft::WRL::ComPtr<ID3D11VertexShader> vs; Microsoft::WRL::ComPtr<ID3D11GeometryShader> gs; Microsoft::WRL::ComPtr<ID3D11PixelShader> ps; Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_palette_out; const D3D11_INPUT_ELEMENT_DESC* element_desc; size_t element_count; ::geometry_bucket_type bucket_type_; const std::type_info* item_type_; size_t item_size_; size_t item_align; size_t render_start_; size_t render_count_; uint8_t* data_start; uint8_t* data_cur; uint8_t* data_end; }; struct alpha_geometry_entry { const ::geometry_bucket* bucket; size_t index; float depth; }; struct geometry_shader_constants_0 { DirectX::XMFLOAT4X4 projection; ff::point_float view_size; ff::point_float view_scale; float z_offset; float padding[3]; }; struct geometry_shader_constants_1 { std::vector<DirectX::XMFLOAT4X4> model; }; struct pixel_shader_constants_0 { std::array<ff::rect_float, ::MAX_TEXTURES_USING_PALETTE> texture_palette_sizes; }; } namespace std { static bool operator==(const DirectX::XMFLOAT4X4& lhs, const DirectX::XMFLOAT4X4& rhs) { return ::operator==(lhs, rhs); } } static ::alpha_type get_alpha_type(const DirectX::XMFLOAT4& color, bool force_opaque) { if (color.w == 0) { return alpha_type::invisible; } if (color.w == 1 || force_opaque) { return alpha_type::opaque; } return alpha_type::transparent; } static alpha_type get_alpha_type(const DirectX::XMFLOAT4* colors, size_t count, bool force_opaque) { alpha_type type = alpha_type::invisible; for (size_t i = 0; i < count; i++) { switch (::get_alpha_type(colors[i], force_opaque)) { case alpha_type::opaque: type = alpha_type::opaque; break; case alpha_type::transparent: return alpha_type::transparent; } } return type; } static alpha_type get_alpha_type(const ff::sprite_data& data, const DirectX::XMFLOAT4& color, bool force_opaque) { switch (::get_alpha_type(color, force_opaque)) { case alpha_type::transparent: return ff::flags::has(data.type(), ff::sprite_type::palette) ? alpha_type::opaque : alpha_type::transparent; case alpha_type::opaque: return (ff::flags::has(data.type(), ff::sprite_type::transparent) && !force_opaque) ? alpha_type::transparent : alpha_type::opaque; default: return alpha_type::invisible; } } static alpha_type get_alpha_type(const ff::sprite_data** datas, const DirectX::XMFLOAT4* colors, size_t count, bool force_opaque) { alpha_type type = alpha_type::invisible; for (size_t i = 0; i < count; i++) { switch (::get_alpha_type(*datas[i], colors[i], force_opaque)) { case alpha_type::opaque: type = alpha_type::opaque; break; case alpha_type::transparent: return alpha_type::transparent; } } return type; } static void get_alpha_blend(D3D11_RENDER_TARGET_BLEND_DESC& desc) { // newColor = (srcColor * SrcBlend) BlendOp (destColor * DestBlend) // newAlpha = (srcAlpha * SrcBlendAlpha) BlendOpAlpha (destAlpha * DestBlendAlpha) desc.BlendEnable = TRUE; desc.SrcBlend = D3D11_BLEND_SRC_ALPHA; desc.DestBlend = D3D11_BLEND_INV_SRC_ALPHA; desc.BlendOp = D3D11_BLEND_OP_ADD; desc.SrcBlendAlpha = D3D11_BLEND_ONE; desc.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; desc.BlendOpAlpha = D3D11_BLEND_OP_ADD; } static void get_pre_multiplied_alpha_blend(D3D11_RENDER_TARGET_BLEND_DESC& desc) { // newColor = (srcColor * SrcBlend) BlendOp (destColor * DestBlend) // newAlpha = (srcAlpha * SrcBlendAlpha) BlendOpAlpha (destAlpha * DestBlendAlpha) desc.BlendEnable = TRUE; desc.SrcBlend = D3D11_BLEND_ONE; desc.DestBlend = D3D11_BLEND_INV_SRC_ALPHA; desc.BlendOp = D3D11_BLEND_OP_ADD; desc.SrcBlendAlpha = D3D11_BLEND_ONE; desc.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; desc.BlendOpAlpha = D3D11_BLEND_OP_ADD; } static ID3D11SamplerState* get_texture_sampler_state(D3D11_FILTER filter) { CD3D11_SAMPLER_DESC sampler(D3D11_DEFAULT); sampler.Filter = filter; return ff_dx::get_object_cache().get_sampler_state(sampler); } static ID3D11BlendState* get_opaque_blend_state() { CD3D11_BLEND_DESC blend(D3D11_DEFAULT); return ff_dx::get_object_cache().get_blend_state(blend); } static ID3D11BlendState* get_alpha_blend_state() { CD3D11_BLEND_DESC blend(D3D11_DEFAULT); ::get_alpha_blend(blend.RenderTarget[0]); return ff_dx::get_object_cache().get_blend_state(blend); } static ID3D11BlendState* get_pre_multiplied_alpha_blend_state() { CD3D11_BLEND_DESC blend(D3D11_DEFAULT); ::get_pre_multiplied_alpha_blend(blend.RenderTarget[0]); return ff_dx::get_object_cache().get_blend_state(blend); } static ID3D11DepthStencilState* get_enabled_depth_state() { CD3D11_DEPTH_STENCIL_DESC depth(D3D11_DEFAULT); depth.DepthFunc = D3D11_COMPARISON_GREATER; return ff_dx::get_object_cache().get_depth_stencil_state(depth); } static ID3D11DepthStencilState* get_disabled_depth_state() { CD3D11_DEPTH_STENCIL_DESC depth(D3D11_DEFAULT); depth.DepthEnable = FALSE; depth.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; return ff_dx::get_object_cache().get_depth_stencil_state(depth); } static ID3D11RasterizerState* get_no_cull_raster_state() { CD3D11_RASTERIZER_DESC raster(D3D11_DEFAULT); raster.CullMode = D3D11_CULL_NONE; return ff_dx::get_object_cache().get_rasterize_state(raster); } static ff_dx::fixed_state create_opaque_draw_state() { ff_dx::fixed_state state; state.blend = ::get_opaque_blend_state(); state.depth = ::get_enabled_depth_state(); state.disabled_depth = ::get_disabled_depth_state(); state.raster = ::get_no_cull_raster_state(); return state; } static ff_dx::fixed_state create_alpha_draw_state() { ff_dx::fixed_state state; state.blend = ::get_alpha_blend_state(); state.depth = ::get_enabled_depth_state(); state.disabled_depth = ::get_disabled_depth_state(); state.raster = ::get_no_cull_raster_state(); return state; } static ff_dx::fixed_state create_pre_multiplied_alpha_draw_state() { ff_dx::fixed_state state; state.blend = ::get_pre_multiplied_alpha_blend_state(); state.depth = ::get_enabled_depth_state(); state.disabled_depth = ::get_disabled_depth_state(); state.raster = ::get_no_cull_raster_state(); return state; } static ff::rect_float get_rotated_view_rect(ff::target_base& target, const ff::rect_float& view_rect) { ff::window_size size = target.size(); ff::rect_float rotated_view_rect; switch (size.current_rotation) { default: rotated_view_rect = view_rect; break; case DMDO_90: { float height = size.rotated_pixel_size().cast<float>().y; rotated_view_rect.left = height - view_rect.bottom; rotated_view_rect.top = view_rect.left; rotated_view_rect.right = height - view_rect.top; rotated_view_rect.bottom = view_rect.right; } break; case DMDO_180: { ff::point_float target_size = size.rotated_pixel_size().cast<float>(); rotated_view_rect.left = target_size.x - view_rect.right; rotated_view_rect.top = target_size.y - view_rect.bottom; rotated_view_rect.right = target_size.x - view_rect.left; rotated_view_rect.bottom = target_size.y - view_rect.top; } break; case DMDO_270: { float width = size.rotated_pixel_size().cast<float>().x; rotated_view_rect.left = view_rect.top; rotated_view_rect.top = width - view_rect.right; rotated_view_rect.right = view_rect.bottom; rotated_view_rect.bottom = width - view_rect.left; } break; } return rotated_view_rect; } static DirectX::XMMATRIX get_view_matrix(const ff::rect_float& world_rect) { return DirectX::XMMatrixOrthographicOffCenterLH( world_rect.left, world_rect.right, world_rect.bottom, world_rect.top, 0, ::MAX_RENDER_DEPTH); } static DirectX::XMMATRIX get_orientation_matrix(ff::target_base& target, const ff::rect_float& view_rect, ff::point_float world_center) { DirectX::XMMATRIX orientation_matrix; int degrees = target.size().current_rotation; switch (degrees) { default: orientation_matrix = DirectX::XMMatrixIdentity(); break; case DMDO_90: case DMDO_270: { float view_height_per_width = view_rect.height() / view_rect.width(); float view_width_per_height = view_rect.width() / view_rect.height(); orientation_matrix = DirectX::XMMatrixTransformation2D( DirectX::XMVectorSet(world_center.x, world_center.y, 0, 0), 0, // scale center DirectX::XMVectorSet(view_height_per_width, view_width_per_height, 1, 1), // scale DirectX::XMVectorSet(world_center.x, world_center.y, 0, 0), // rotation center ff::math::pi<float>() * degrees / 2.0f, // rotation DirectX::XMVectorZero()); // translation } break; case DMDO_180: orientation_matrix = DirectX::XMMatrixAffineTransformation2D( DirectX::XMVectorSet(1, 1, 1, 1), // scale DirectX::XMVectorSet(world_center.x, world_center.y, 0, 0), // rotation center ff::math::pi<float>(), // rotation DirectX::XMVectorZero()); // translation break; } return orientation_matrix; } static D3D11_VIEWPORT get_viewport(const ff::rect_float& view_rect) { D3D11_VIEWPORT viewport; viewport.TopLeftX = view_rect.left; viewport.TopLeftY = view_rect.top; viewport.Width = view_rect.width(); viewport.Height = view_rect.height(); viewport.MinDepth = 0; viewport.MaxDepth = 1; return viewport; } static bool setup_view_matrix(ff::target_base& target, const ff::rect_float& view_rect, const ff::rect_float& world_rect, DirectX::XMFLOAT4X4& view_matrix) { if (world_rect.width() != 0 && world_rect.height() != 0 && view_rect.width() > 0 && view_rect.height() > 0) { DirectX::XMMATRIX unoriented_view_matrix = ::get_view_matrix(world_rect); DirectX::XMMATRIX orientation_matrix = ::get_orientation_matrix(target, view_rect, world_rect.center()); DirectX::XMStoreFloat4x4(&view_matrix, DirectX::XMMatrixTranspose(orientation_matrix * unoriented_view_matrix)); return true; } return false; } static bool setup_render_target(ff::target_base& target, ff::depth* depth, const ff::rect_float& view_rect) { ID3D11RenderTargetView* target_view = target.view(); if (target_view) { ID3D11DepthStencilView* depth_view = nullptr; if (depth) { if (depth->size(target.size().pixel_size)) { depth->clear(0, 0); depth_view = depth->view(); } if (!depth_view) { assert(false); return false; } } ff::rect_float rotated_view_rect = ::get_rotated_view_rect(target, view_rect); D3D11_VIEWPORT viewport = ::get_viewport(rotated_view_rect); ff_dx::get_device_state().set_targets(&target_view, 1, depth_view); ff_dx::get_device_state().set_viewports(&viewport, 1); return true; } assert(false); return false; } namespace { class draw_device_internal : public ff::draw_device , public ff::draw_base , private ff::dxgi::device_child_base { public: draw_device_internal() : state(::draw_device_internal::state_t::invalid) , world_matrix_stack_changing_connection(this->world_matrix_stack_.matrix_changing().connect(std::bind(&draw_device_internal::matrix_changing, this, std::placeholders::_1))) , geometry_buffer(ff::dxgi::buffer_type::vertex) , geometry_constants_buffer_0(ff::dxgi::buffer_type::constant) , geometry_constants_buffer_1(ff::dxgi::buffer_type::constant) , pixel_constants_buffer_0(ff::dxgi::buffer_type::constant) , geometry_buckets { ::geometry_bucket::create<ff::vertex::line_geometry, ::geometry_bucket_type::lines>(), ::geometry_bucket::create<ff::vertex::circle_geometry, ::geometry_bucket_type::circles>(), ::geometry_bucket::create<ff::vertex::triangle_geometry, ::geometry_bucket_type::triangles>(), ::geometry_bucket::create<ff::vertex::sprite_geometry, ::geometry_bucket_type::sprites>(), ::geometry_bucket::create<ff::vertex::sprite_geometry, ::geometry_bucket_type::palette_sprites>(), ::geometry_bucket::create<ff::vertex::line_geometry, ::geometry_bucket_type::lines_alpha>(), ::geometry_bucket::create<ff::vertex::circle_geometry, ::geometry_bucket_type::circles_alpha>(), ::geometry_bucket::create<ff::vertex::triangle_geometry, ::geometry_bucket_type::triangles_alpha>(), ::geometry_bucket::create<ff::vertex::sprite_geometry, ::geometry_bucket_type::sprites_alpha>(), } { this->reset(); ff_dx::add_device_child(this, ff_dx::device_reset_priority::normal); } virtual ~draw_device_internal() override { assert(this->state != ::draw_device_internal::state_t::drawing); ff_dx::remove_device_child(this); } draw_device_internal(draw_device_internal&& other) noexcept = delete; draw_device_internal(const draw_device_internal& other) = delete; draw_device_internal& operator=(draw_device_internal&& other) noexcept = delete; draw_device_internal& operator=(const draw_device_internal& other) = delete; virtual bool valid() const override { return this->state != ::draw_device_internal::state_t::invalid; } virtual ff::draw_ptr begin_draw(ff::target_base& target, ff::depth* depth, const ff::rect_float& view_rect, const ff::rect_float& world_rect, ff::draw_options options) override { this->end_draw(); if (::setup_view_matrix(target, view_rect, world_rect, this->view_matrix) && ::setup_render_target(target, depth, view_rect)) { this->init_geometry_constant_buffers_0(target, view_rect, world_rect); this->target_requires_palette = ff::dxgi::palette_format(target.format()); this->force_pre_multiplied_alpha = ff::flags::has(options, ff::draw_options::pre_multiplied_alpha) && ff::dxgi::supports_pre_multiplied_alpha(target.format()) ? 1 : 0; this->state = ::draw_device_internal::state_t::drawing; return this; } return nullptr; } virtual void end_draw() override { if (this->state == state_t::drawing) { this->flush(); ff_dx::get_device_state().set_resources_ps(::NULL_TEXTURES.data(), 0, ::NULL_TEXTURES.size()); this->state = ::draw_device_internal::state_t::valid; this->palette_stack.resize(1); this->palette_remap_stack.resize(1); this->sampler_stack.resize(1); this->custom_context_stack.clear(); this->world_matrix_stack_.reset(); this->draw_depth = 0; this->force_no_overlap = 0; this->force_opaque = 0; this->force_pre_multiplied_alpha = 0; } } virtual void draw_sprite(const ff::sprite_data& sprite, const ff::transform& transform) override { ::alpha_type alpha_type = ::get_alpha_type(sprite, transform.color, this->force_opaque || this->target_requires_palette); if (alpha_type != ::alpha_type::invisible && sprite.view()) { bool use_palette = ff::flags::has(sprite.type(), ff::sprite_type::palette); ::geometry_bucket_type bucket_type = (alpha_type == ::alpha_type::transparent && !this->target_requires_palette) ? (use_palette ? ::geometry_bucket_type::palette_sprites : ::geometry_bucket_type::sprites_alpha) : (use_palette ? ::geometry_bucket_type::palette_sprites : ::geometry_bucket_type::sprites); float depth = this->nudge_depth(this->force_no_overlap ? ::last_depth_type::sprite_no_overlap : ::last_depth_type::sprite); ff::vertex::sprite_geometry& input = *reinterpret_cast<ff::vertex::sprite_geometry*>(this->add_geometry(nullptr, bucket_type, depth)); this->get_world_matrix_and_texture_index(*sprite.view(), use_palette, input.matrix_index, input.texture_index); input.position.x = transform.position.x; input.position.y = transform.position.y; input.position.z = depth; input.scale = *reinterpret_cast<const DirectX::XMFLOAT2*>(&transform.scale); input.rotate = transform.rotation_radians(); input.color = transform.color; input.uv_rect = *reinterpret_cast<const DirectX::XMFLOAT4*>(&sprite.texture_uv()); input.rect = *reinterpret_cast<const DirectX::XMFLOAT4*>(&sprite.world()); } } virtual void draw_line_strip(const ff::point_float* points, const DirectX::XMFLOAT4* colors, size_t count, float thickness, bool pixel_thickness) override { this->draw_line_strip(points, count, colors, count, thickness, pixel_thickness); } virtual void draw_line_strip(const ff::point_float* points, size_t count, const DirectX::XMFLOAT4& color, float thickness, bool pixel_thickness) override { this->draw_line_strip(points, count, &color, 1, thickness, pixel_thickness); } virtual void draw_line(const ff::point_float& start, const ff::point_float& end, const DirectX::XMFLOAT4& color, float thickness, bool pixel_thickness) override { const ff::point_float points[2] = { start, end }; this->draw_line_strip(points, 2, color, thickness, pixel_thickness); } virtual void draw_filled_rectangle(const ff::rect_float& rect, const DirectX::XMFLOAT4* colors) override { const float tri_points[12] = { rect.left, rect.top, rect.right, rect.top, rect.right, rect.bottom, rect.right, rect.bottom, rect.left, rect.bottom, rect.left, rect.top, }; const DirectX::XMFLOAT4 tri_colors[6] = { colors[0], colors[1], colors[2], colors[2], colors[3], colors[0], }; this->draw_filled_triangles(reinterpret_cast<const ff::point_float*>(tri_points), tri_colors, 2); } virtual void draw_filled_rectangle(const ff::rect_float& rect, const DirectX::XMFLOAT4& color) override { const float tri_points[12] = { rect.left, rect.top, rect.right, rect.top, rect.right, rect.bottom, rect.right, rect.bottom, rect.left, rect.bottom, rect.left, rect.top, }; const DirectX::XMFLOAT4 tri_colors[6] = { color, color, color, color, color, color, }; this->draw_filled_triangles(reinterpret_cast<const ff::point_float*>(tri_points), tri_colors, 2); } virtual void draw_filled_triangles(const ff::point_float* points, const DirectX::XMFLOAT4* colors, size_t count) override { ff::vertex::triangle_geometry input; input.matrix_index = (this->world_matrix_index == ff::constants::invalid_dword) ? this->get_world_matrix_index() : this->world_matrix_index; input.depth = this->nudge_depth(this->force_no_overlap ? ::last_depth_type::triangle_no_overlap : ::last_depth_type::triangle); for (size_t i = 0; i < count; i++, points += 3, colors += 3) { std::memcpy(input.position, points, sizeof(input.position)); std::memcpy(input.color, colors, sizeof(input.color)); ::alpha_type alpha_type = ::get_alpha_type(colors, 3, this->force_opaque || this->target_requires_palette); if (alpha_type != ::alpha_type::invisible) { ::geometry_bucket_type bucket_type = (alpha_type == ::alpha_type::transparent) ? ::geometry_bucket_type::triangles_alpha : ::geometry_bucket_type::triangles; this->add_geometry(&input, bucket_type, input.depth); } } } virtual void draw_filled_circle(const ff::point_float& center, float radius, const DirectX::XMFLOAT4& color) override { this->draw_outline_circle(center, radius, color, color, std::abs(radius), false); } virtual void draw_filled_circle(const ff::point_float& center, float radius, const DirectX::XMFLOAT4& inside_color, const DirectX::XMFLOAT4& outside_color) override { this->draw_outline_circle(center, radius, inside_color, outside_color, std::abs(radius), false); } virtual void draw_outline_rectangle(const ff::rect_float& rect, const DirectX::XMFLOAT4& color, float thickness, bool pixel_thickness) override { ff::rect_float rect2 = rect.normalize(); if (thickness < 0) { ff::point_float deflate = this->geometry_constants_0.view_scale * thickness; rect2 = rect2.deflate(deflate); this->draw_outline_rectangle(rect2, color, -thickness, pixel_thickness); } else if (!pixel_thickness && (thickness * 2 >= rect2.width() || thickness * 2 >= rect2.height())) { this->draw_filled_rectangle(rect2, color); } else { ff::point_float half_thickness(thickness / 2, thickness / 2); if (pixel_thickness) { half_thickness *= this->geometry_constants_0.view_scale; } rect2 = rect2.deflate(half_thickness); const ff::point_float points[5] = { rect2.top_left(), rect2.top_right(), rect2.bottom_right(), rect2.bottom_left(), rect2.top_left(), }; this->draw_line_strip(points, 5, color, thickness, pixel_thickness); } } virtual void draw_outline_circle(const ff::point_float& center, float radius, const DirectX::XMFLOAT4& color, float thickness, bool pixel_thickness) override { this->draw_outline_circle(center, radius, color, color, thickness, pixel_thickness); } virtual void draw_outline_circle(const ff::point_float& center, float radius, const DirectX::XMFLOAT4& inside_color, const DirectX::XMFLOAT4& outside_color, float thickness, bool pixel_thickness) override { ff::vertex::circle_geometry input; input.matrix_index = (this->world_matrix_index == ff::constants::invalid_dword) ? this->get_world_matrix_index() : this->world_matrix_index; input.position.x = center.x; input.position.y = center.y; input.position.z = this->nudge_depth(this->force_no_overlap ? ::last_depth_type::circle_no_overlap : ::last_depth_type::circle); input.radius = std::abs(radius); input.thickness = pixel_thickness ? -std::abs(thickness) : std::min(std::abs(thickness), input.radius); input.inside_color = inside_color; input.outside_color = outside_color; ::alpha_type alpha_type = ::get_alpha_type(&input.inside_color, 2, this->force_opaque || this->target_requires_palette); if (alpha_type != ::alpha_type::invisible) { ::geometry_bucket_type bucket_type = (alpha_type == ::alpha_type::transparent) ? ::geometry_bucket_type::circles_alpha : ::geometry_bucket_type::circles; this->add_geometry(&input, bucket_type, input.position.z); } } virtual void draw_palette_line_strip(const ff::point_float* points, const int* colors, size_t count, float thickness, bool pixel_thickness) override { ff::stack_vector<DirectX::XMFLOAT4, 64> colors2; colors2.resize(count); for (size_t i = 0; i != colors2.size(); i++) { ff::palette_index_to_color(this->remap_palette_index(colors[i]), colors2[i]); } this->draw_line_strip(points, count, colors2.data(), count, thickness, pixel_thickness); } virtual void draw_palette_line_strip(const ff::point_float* points, size_t count, int color, float thickness, bool pixel_thickness) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_line_strip(points, count, &color2, 1, thickness, pixel_thickness); } virtual void draw_palette_line(const ff::point_float& start, const ff::point_float& end, int color, float thickness, bool pixel_thickness) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_line(start, end, color2, thickness, pixel_thickness); } virtual void draw_palette_filled_rectangle(const ff::rect_float& rect, const int* colors) override { std::array<DirectX::XMFLOAT4, 4> colors2; for (size_t i = 0; i != colors2.size(); i++) { ff::palette_index_to_color(this->remap_palette_index(colors[i]), colors2[i]); } this->draw_filled_rectangle(rect, colors2.data()); } virtual void draw_palette_filled_rectangle(const ff::rect_float& rect, int color) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_filled_rectangle(rect, color2); } virtual void draw_palette_filled_triangles(const ff::point_float* points, const int* colors, size_t count) override { ff::stack_vector<DirectX::XMFLOAT4, 64 * 3> colors2; colors2.resize(count * 3); for (size_t i = 0; i != colors2.size(); i++) { ff::palette_index_to_color(this->remap_palette_index(colors[i]), colors2[i]); } this->draw_filled_triangles(points, colors2.data(), count); } virtual void draw_palette_filled_circle(const ff::point_float& center, float radius, int color) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_filled_circle(center, radius, color2); } virtual void draw_palette_filled_circle(const ff::point_float& center, float radius, int inside_color, int outside_color) override { DirectX::XMFLOAT4 inside_color2, outside_color2; ff::palette_index_to_color(this->remap_palette_index(inside_color), inside_color2); ff::palette_index_to_color(this->remap_palette_index(outside_color), outside_color2); this->draw_filled_circle(center, radius, inside_color2, outside_color2); } virtual void draw_palette_outline_rectangle(const ff::rect_float& rect, int color, float thickness, bool pixel_thickness) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_outline_rectangle(rect, color2, thickness, pixel_thickness); } virtual void draw_palette_outline_circle(const ff::point_float& center, float radius, int color, float thickness, bool pixel_thickness) override { DirectX::XMFLOAT4 color2; ff::palette_index_to_color(this->remap_palette_index(color), color2); this->draw_outline_circle(center, radius, color2, thickness, pixel_thickness); } virtual void draw_palette_outline_circle(const ff::point_float& center, float radius, int inside_color, int outside_color, float thickness, bool pixel_thickness) override { DirectX::XMFLOAT4 inside_color2, outside_color2; ff::palette_index_to_color(this->remap_palette_index(inside_color), inside_color2); ff::palette_index_to_color(this->remap_palette_index(outside_color), outside_color2); this->draw_outline_circle(center, radius, inside_color2, outside_color2, thickness, pixel_thickness); } virtual ff::matrix_stack& world_matrix_stack() override { return this->world_matrix_stack_; } virtual void nudge_depth() override { this->last_depth_type = ::last_depth_type::nudged; } virtual void push_palette(ff::palette_base* palette) override { assert(!this->target_requires_palette && palette); this->palette_stack.push_back(palette); this->palette_index = ff::constants::invalid_dword; this->push_palette_remap(palette->index_remap(), palette->index_remap_hash()); } virtual void pop_palette() override { assert(this->palette_stack.size() > 1); this->palette_stack.pop_back(); this->palette_index = ff::constants::invalid_dword; this->pop_palette_remap(); } virtual void push_palette_remap(const uint8_t* remap, size_t hash) override { this->palette_remap_stack.push_back(std::make_pair( remap ? remap : ::DEFAULT_PALETTE_REMAP.data(), remap ? (hash ? hash : ff::stable_hash_bytes(remap, ff::constants::palette_size)) : ::DEFAULT_PALETTE_REMAP_HASH)); this->palette_remap_index = ff::constants::invalid_dword; } virtual void pop_palette_remap() override { assert(this->palette_remap_stack.size() > 1); this->palette_remap_stack.pop_back(); this->palette_remap_index = ff::constants::invalid_dword; } virtual void push_no_overlap() override { this->force_no_overlap++; } virtual void pop_no_overlap() override { assert(this->force_no_overlap > 0); if (!--this->force_no_overlap) { this->nudge_depth(); } } virtual void push_opaque() override { this->force_opaque++; } virtual void pop_opaque() override { assert(this->force_opaque > 0); this->force_opaque--; } virtual void push_pre_multiplied_alpha() override { if (!this->force_pre_multiplied_alpha) { this->flush(); } this->force_pre_multiplied_alpha++; } virtual void pop_pre_multiplied_alpha() override { assert(this->force_pre_multiplied_alpha > 0); if (this->force_pre_multiplied_alpha == 1) { this->flush(); } this->force_pre_multiplied_alpha--; } virtual void push_custom_context(ff::draw_base::custom_context_func&& func) override { this->flush(); this->custom_context_stack.push_back(std::move(func)); } virtual void pop_custom_context() override { assert(this->custom_context_stack.size()); this->flush(); this->custom_context_stack.pop_back(); } virtual void push_sampler_linear_filter(bool linear_filter) override { this->flush(); this->sampler_stack.push_back(::get_texture_sampler_state(linear_filter ? D3D11_FILTER_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_POINT)); } virtual void pop_sampler_linear_filter() override { assert(this->sampler_stack.size() > 1); this->flush(); this->sampler_stack.pop_back(); } private: // device_child_base virtual bool reset() { this->destroy(); // Geometry buckets this->get_geometry_bucket(::geometry_bucket_type::lines).reset("ff.shader.line_vs", "ff.shader.line_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::circles).reset("ff.shader.circle_vs", "ff.shader.circle_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::triangles).reset("ff.shader.triangle_vs", "ff.shader.triangle_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::sprites).reset("ff.shader.sprite_vs", "ff.shader.sprite_gs", "ff.shader.sprite_ps", "ff.shader.palette_out_sprite_ps"); this->get_geometry_bucket(::geometry_bucket_type::palette_sprites).reset("ff.shader.sprite_vs", "ff.shader.sprite_gs", "ff.shader.sprite_palette_ps", "ff.shader.palette_out_sprite_palette_ps"); this->get_geometry_bucket(::geometry_bucket_type::lines_alpha).reset("ff.shader.line_vs", "ff.shader.line_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::circles_alpha).reset("ff.shader.circle_vs", "ff.shader.circle_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::triangles_alpha).reset("ff.shader.triangle_vs", "ff.shader.triangle_gs", "ff.shader.color_ps", "ff.shader.palette_out_color_ps"); this->get_geometry_bucket(::geometry_bucket_type::sprites_alpha).reset("ff.shader.sprite_vs", "ff.shader.sprite_gs", "ff.shader.sprite_ps", "ff.shader.palette_out_sprite_ps"); // Palette this->palette_stack.push_back(nullptr); this->palette_texture = std::make_shared<ff::texture>( ff::point_size(ff::constants::palette_size, ::MAX_PALETTES).cast<int>(), ff::dxgi::PALETTE_FORMAT); this->palette_remap_stack.push_back(std::make_pair(::DEFAULT_PALETTE_REMAP.data(), ::DEFAULT_PALETTE_REMAP_HASH)); this->palette_remap_texture = std::make_shared<ff::texture>( ff::point_size(ff::constants::palette_size, ::MAX_PALETTE_REMAPS).cast<int>(), ff::dxgi::PALETTE_INDEX_FORMAT); // States this->sampler_stack.push_back(::get_texture_sampler_state(D3D11_FILTER_MIN_MAG_MIP_POINT)); this->opaque_state = ::create_opaque_draw_state(); this->alpha_state = ::create_alpha_draw_state(); this->pre_multiplied_alpha_state = ::create_pre_multiplied_alpha_draw_state(); this->state = ::draw_device_internal::state_t::valid; return true; } void destroy() { this->state = ::draw_device_internal::state_t::invalid; this->geometry_constants_0 = ::geometry_shader_constants_0{}; this->geometry_constants_1 = ::geometry_shader_constants_1{}; this->pixel_constants_0 = ::pixel_shader_constants_0{}; this->geometry_constants_hash_0 = 0; this->geometry_constants_hash_1 = 0; this->pixel_constants_hash_0 = 0; this->sampler_stack.clear(); this->opaque_state = ff_dx::fixed_state(); this->alpha_state = ff_dx::fixed_state(); this->pre_multiplied_alpha_state = ff_dx::fixed_state(); this->custom_context_stack.clear(); this->view_matrix = ff::matrix::identity_4x4(); this->world_matrix_stack_.reset(); this->world_matrix_to_index.clear(); this->world_matrix_index = ff::constants::invalid_dword; std::memset(this->textures.data(), 0, ff::array_byte_size(this->textures)); std::memset(this->textures_using_palette.data(), 0, ff::array_byte_size(this->textures_using_palette)); this->texture_count = 0; this->textures_using_palette_count = 0; std::memset(this->palette_texture_hashes.data(), 0, ff::array_byte_size(this->palette_texture_hashes)); this->palette_stack.clear(); this->palette_to_index.clear(); this->palette_texture = nullptr; this->palette_index = ff::constants::invalid_dword; std::memset(this->palette_remap_texture_hashes.data(), 0, ff::array_byte_size(this->palette_remap_texture_hashes)); this->palette_remap_stack.clear(); this->palette_remap_to_index.clear(); this->palette_remap_texture = nullptr; this->palette_remap_index = ff::constants::invalid_dword; this->alpha_geometry.clear(); this->last_depth_type = ::last_depth_type::none; this->draw_depth = 0; this->force_no_overlap = 0; this->force_opaque = 0; this->force_pre_multiplied_alpha = 0; for (auto& bucket : this->geometry_buckets) { bucket.reset(); } } void matrix_changing(const ff::matrix_stack& matrix_stack) { this->world_matrix_index = ff::constants::invalid_dword; } void draw_line_strip(const ff::point_float* points, size_t point_count, const DirectX::XMFLOAT4* colors, size_t color_count, float thickness, bool pixel_thickness) { assert(color_count == 1 || color_count == point_count); thickness = pixel_thickness ? -std::abs(thickness) : std::abs(thickness); ff::vertex::line_geometry input; input.matrix_index = (this->world_matrix_index == ff::constants::invalid_dword) ? this->get_world_matrix_index() : this->world_matrix_index; input.depth = this->nudge_depth(this->force_no_overlap ? ::last_depth_type::line_no_overlap : ::last_depth_type::line); input.color[0] = colors[0]; input.color[1] = colors[0]; input.thickness[0] = thickness; input.thickness[1] = thickness; const DirectX::XMFLOAT2* dxpoints = reinterpret_cast<const DirectX::XMFLOAT2*>(points); bool closed = point_count > 2 && points[0] == points[point_count - 1]; ::alpha_type alpha_type = ::get_alpha_type(colors[0], this->force_opaque || this->target_requires_palette); for (size_t i = 0; i < point_count - 1; i++) { input.position[1] = dxpoints[i]; input.position[2] = dxpoints[i + 1]; input.position[0] = (i == 0) ? (closed ? dxpoints[point_count - 2] : dxpoints[i]) : dxpoints[i - 1]; input.position[3] = (i == point_count - 2) ? (closed ? dxpoints[1] : dxpoints[i + 1]) : dxpoints[i + 2]; if (color_count != 1) { input.color[0] = colors[i]; input.color[1] = colors[i + 1]; alpha_type = ::get_alpha_type(colors + i, 2, this->force_opaque || this->target_requires_palette); } if (alpha_type != ::alpha_type::invisible) { ::geometry_bucket_type bucket_type = (alpha_type == ::alpha_type::transparent) ? ::geometry_bucket_type::lines_alpha : ::geometry_bucket_type::lines; this->add_geometry(&input, bucket_type, input.depth); } } } void init_geometry_constant_buffers_0(ff::target_base& target, const ff::rect_float& view_rect, const ff::rect_float& world_rect) { this->geometry_constants_0.view_size = view_rect.size() / static_cast<float>(target.size().dpi_scale); this->geometry_constants_0.view_scale = world_rect.size() / this->geometry_constants_0.view_size; } void update_geometry_constant_buffers_0() { this->geometry_constants_0.projection = this->view_matrix; size_t hash0 = ff::stable_hash_func(this->geometry_constants_0); if (!this->geometry_constants_hash_0 || this->geometry_constants_hash_0 != hash0) { this->geometry_constants_buffer_0.update(ff_dx::get_device_state(), &this->geometry_constants_0, sizeof(::geometry_shader_constants_0)); this->geometry_constants_hash_0 = hash0; } } void update_geometry_constant_buffers_1() { // Build up model matrix array size_t world_matrix_count = this->world_matrix_to_index.size(); this->geometry_constants_1.model.resize(world_matrix_count); for (const auto& iter : this->world_matrix_to_index) { this->geometry_constants_1.model[iter.second] = iter.first; } size_t hash1 = world_matrix_count ? ff::stable_hash_bytes(this->geometry_constants_1.model.data(), ff::vector_byte_size(this->geometry_constants_1.model)) : 0; if (!this->geometry_constants_hash_1 || this->geometry_constants_hash_1 != hash1) { this->geometry_constants_hash_1 = hash1; #if _DEBUG size_t buffer_size = sizeof(DirectX::XMFLOAT4X4) * ::MAX_TRANSFORM_MATRIXES; #else size_t buffer_size = sizeof(DirectX::XMFLOAT4X4) * world_matrix_count; #endif this->geometry_constants_buffer_1.update(ff_dx::get_device_state(), this->geometry_constants_1.model.data(), ff::vector_byte_size(this->geometry_constants_1.model), buffer_size); } } void update_pixel_constant_buffers_0() { if (this->textures_using_palette_count) { for (size_t i = 0; i < this->textures_using_palette_count; i++) { ff::rect_float& rect = this->pixel_constants_0.texture_palette_sizes[i]; ff::point_float size = this->textures_using_palette[i]->view_texture()->size().cast<float>(); rect.left = size.x; rect.top = size.y; } size_t hash0 = ff::stable_hash_func(this->pixel_constants_0); if (!this->pixel_constants_hash_0 || this->pixel_constants_hash_0 != hash0) { this->pixel_constants_buffer_0.update(ff_dx::get_device_state(), &this->pixel_constants_0, sizeof(::pixel_shader_constants_0)); this->pixel_constants_hash_0 = hash0; } } } void update_palette_texture() { if (this->textures_using_palette_count && !this->palette_to_index.empty()) { ID3D11Resource* dest_resource = this->palette_texture->dx_texture(); CD3D11_BOX box(0, 0, 0, static_cast<int>(ff::constants::palette_size), 1, 1); for (const auto& iter : this->palette_to_index) { ff::palette_base* palette = iter.second.first; if (palette) { unsigned int index = iter.second.second; size_t palette_row = palette->current_row(); const ff::palette_data* palette_data = palette->data(); size_t row_hash = palette_data->row_hash(palette_row); if (this->palette_texture_hashes[index] != row_hash) { this->palette_texture_hashes[index] = row_hash; ID3D11Resource* src_resource = palette_data->texture()->dx_texture(); box.top = static_cast<UINT>(palette_row); box.bottom = box.top + 1; ff_dx::get_device_state().copy_subresource_region(dest_resource, 0, 0, index, 0, src_resource, 0, &box); } } } } if ((this->textures_using_palette_count || this->target_requires_palette) && !this->palette_remap_to_index.empty()) { ID3D11Resource* dest_remap_resource = this->palette_remap_texture->dx_texture(); CD3D11_BOX box(0, 0, 0, static_cast<int>(ff::constants::palette_size), 1, 1); for (const auto& iter : this->palette_remap_to_index) { const uint8_t* remap = iter.second.first; unsigned int row = iter.second.second; size_t row_hash = iter.first; if (this->palette_remap_texture_hashes[row] != row_hash) { this->palette_remap_texture_hashes[row] = row_hash; box.top = row; box.bottom = row + 1; ff_dx::get_device_state().update_subresource(dest_remap_resource, 0, &box, remap, static_cast<UINT>(ff::constants::palette_size), 0); } } } } void set_shader_input() { std::array<ID3D11Buffer*, 2> buffers_gs = { this->geometry_constants_buffer_0.dx_buffer(), this->geometry_constants_buffer_1.dx_buffer() }; ff_dx::get_device_state().set_constants_gs(buffers_gs.data(), 0, buffers_gs.size()); std::array<ID3D11Buffer*, 1> buffers_ps = { this->pixel_constants_buffer_0.dx_buffer() }; ff_dx::get_device_state().set_constants_ps(buffers_ps.data(), 0, buffers_ps.size()); std::array<ID3D11SamplerState*, 1> sample_states = { this->sampler_stack.back().Get() }; ff_dx::get_device_state().set_samplers_ps(sample_states.data(), 0, sample_states.size()); if (this->texture_count) { std::array<ID3D11ShaderResourceView*, ::MAX_TEXTURES> textures; for (size_t i = 0; i < this->texture_count; i++) { textures[i] = this->textures[i]->view(); } ff_dx::get_device_state().set_resources_ps(textures.data(), 0, this->texture_count); } if (this->textures_using_palette_count) { std::array<ID3D11ShaderResourceView*, ::MAX_TEXTURES_USING_PALETTE> textures_using_palette; for (size_t i = 0; i < this->textures_using_palette_count; i++) { textures_using_palette[i] = this->textures_using_palette[i]->view(); } ff_dx::get_device_state().set_resources_ps(textures_using_palette.data(), ::MAX_TEXTURES, this->textures_using_palette_count); } if (this->textures_using_palette_count || this->target_requires_palette) { std::array<ID3D11ShaderResourceView*, 2> palettes = { (this->textures_using_palette_count ? this->palette_texture->view() : nullptr), this->palette_remap_texture->view(), }; ff_dx::get_device_state().set_resources_ps(palettes.data(), ::MAX_TEXTURES + ::MAX_TEXTURES_USING_PALETTE, palettes.size()); } } void flush() { if (this->last_depth_type != ::last_depth_type::none && this->create_geometry_buffer()) { this->update_geometry_constant_buffers_0(); this->update_geometry_constant_buffers_1(); this->update_pixel_constant_buffers_0(); this->update_palette_texture(); this->set_shader_input(); this->draw_opaque_geometry(); this->draw_alpha_geometry(); // Reset draw data this->world_matrix_to_index.clear(); this->world_matrix_index = ff::constants::invalid_dword; this->palette_to_index.clear(); this->palette_index = ff::constants::invalid_dword; this->palette_remap_to_index.clear(); this->palette_remap_index = ff::constants::invalid_dword; this->texture_count = 0; this->textures_using_palette_count = 0; this->alpha_geometry.clear(); this->last_depth_type = ::last_depth_type::none; } } bool create_geometry_buffer() { size_t byte_size = 0; for (::geometry_bucket& bucket : this->geometry_buckets) { byte_size = ff::math::round_up(byte_size, bucket.item_size()); bucket.render_start(byte_size / bucket.item_size()); byte_size += bucket.byte_size(); } void* buffer_data = this->geometry_buffer.map(ff_dx::get_device_state(), byte_size); if (buffer_data) { for (::geometry_bucket& bucket : this->geometry_buckets) { if (bucket.render_count()) { ::memcpy(reinterpret_cast<uint8_t*>(buffer_data) + bucket.render_start() * bucket.item_size(), bucket.data(), bucket.byte_size()); bucket.clear_items(); } } this->geometry_buffer.unmap(); return true; } assert(false); return false; } void draw_opaque_geometry() { const ff::draw_base::custom_context_func* custom_func = this->custom_context_stack.size() ? &this->custom_context_stack.back() : nullptr; ff_dx::get_device_state().set_topology_ia(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); this->opaque_state.apply(); for (::geometry_bucket& bucket : this->geometry_buckets) { if (bucket.bucket_type() >= ::geometry_bucket_type::first_alpha) { break; } if (bucket.render_count()) { bucket.apply(this->geometry_buffer.dx_buffer(), this->target_requires_palette); if (!custom_func || (*custom_func)(bucket.item_type(), true)) { ff_dx::get_device_state().draw(bucket.render_count(), bucket.render_start()); } } } } void draw_alpha_geometry() { const size_t alpha_geometry_size = this->alpha_geometry.size(); if (alpha_geometry_size) { const ff::draw_base::custom_context_func* custom_func = this->custom_context_stack.size() ? &this->custom_context_stack.back() : nullptr; ff_dx::get_device_state().set_topology_ia(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); ff_dx::fixed_state& alpha_state = this->force_pre_multiplied_alpha ? this->pre_multiplied_alpha_state : this->alpha_state; alpha_state.apply(); for (size_t i = 0; i < alpha_geometry_size; ) { const ::alpha_geometry_entry& entry = this->alpha_geometry[i]; size_t geometry_count = 1; for (i++; i < alpha_geometry_size; i++, geometry_count++) { const ::alpha_geometry_entry& entry2 = this->alpha_geometry[i]; if (entry2.bucket != entry.bucket || entry2.depth != entry.depth || entry2.index != entry.index + geometry_count) { break; } } entry.bucket->apply(this->geometry_buffer.dx_buffer(), this->target_requires_palette); if (!custom_func || (*custom_func)(entry.bucket->item_type(), false)) { ff_dx::get_device_state().draw(geometry_count, entry.bucket->render_start() + entry.index); } } } } float nudge_depth(::last_depth_type depth_type) { if (depth_type < ::last_depth_type::start_no_overlap || this->last_depth_type != depth_type) { this->draw_depth += ::RENDER_DEPTH_DELTA; } this->last_depth_type = depth_type; return this->draw_depth; } unsigned int get_world_matrix_index() { unsigned int index = this->get_world_matrix_index_no_flush(); if (index == ff::constants::invalid_dword) { this->flush(); index = this->get_world_matrix_index_no_flush(); } return index; } unsigned int get_world_matrix_index_no_flush() { if (this->world_matrix_index == ff::constants::invalid_dword) { DirectX::XMFLOAT4X4 wm; DirectX::XMStoreFloat4x4(&wm, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->world_matrix_stack_.matrix()))); auto iter = this->world_matrix_to_index.find(wm); if (iter == this->world_matrix_to_index.cend() && this->world_matrix_to_index.size() != ::MAX_TRANSFORM_MATRIXES) { iter = this->world_matrix_to_index.try_emplace(wm, static_cast<unsigned int>(this->world_matrix_to_index.size())).first; } if (iter != this->world_matrix_to_index.cend()) { this->world_matrix_index = iter->second; } } return this->world_matrix_index; } unsigned int get_texture_index_no_flush(const ff::texture_view_base& texture_view, bool use_palette) { if (use_palette) { unsigned int palette_index = (this->palette_index == ff::constants::invalid_dword) ? this->get_palette_index_no_flush() : this->palette_index; if (palette_index == ff::constants::invalid_dword) { return ff::constants::invalid_dword; } unsigned int palette_remap_index = (this->palette_remap_index == ff::constants::invalid_dword) ? this->get_palette_remap_index_no_flush() : this->palette_remap_index; if (palette_remap_index == ff::constants::invalid_dword) { return ff::constants::invalid_dword; } unsigned int texture_index = ff::constants::invalid_dword; for (size_t i = this->textures_using_palette_count; i != 0; i--) { if (this->textures_using_palette[i - 1] == &texture_view) { texture_index = static_cast<unsigned int>(i - 1); break; } } if (texture_index == ff::constants::invalid_dword) { if (this->textures_using_palette_count == ::MAX_TEXTURES_USING_PALETTE) { return ff::constants::invalid_dword; } this->textures_using_palette[this->textures_using_palette_count] = &texture_view; texture_index = static_cast<unsigned int>(this->textures_using_palette_count++); } return texture_index | (palette_index << 8) | (palette_remap_index << 16); } else { unsigned int palette_remap_index = 0; if (this->target_requires_palette) { palette_remap_index = (this->palette_remap_index == ff::constants::invalid_dword) ? this->get_palette_remap_index_no_flush() : this->palette_remap_index; if (palette_remap_index == ff::constants::invalid_dword) { return ff::constants::invalid_dword; } } unsigned int texture_index = ff::constants::invalid_dword; for (size_t i = this->texture_count; i != 0; i--) { if (this->textures[i - 1] == &texture_view) { texture_index = static_cast<unsigned int>(i - 1); break; } } if (texture_index == ff::constants::invalid_dword) { if (this->texture_count == ::MAX_TEXTURES) { return ff::constants::invalid_dword; } this->textures[this->texture_count] = &texture_view; texture_index = static_cast<unsigned int>(this->texture_count++); } return texture_index | (palette_remap_index << 16); } } unsigned int get_palette_index_no_flush() { if (this->palette_index == ff::constants::invalid_dword) { if (this->target_requires_palette) { // Not converting palette to RGBA, so don't use a palette this->palette_index = 0; } else { ff::palette_base* palette = this->palette_stack.back(); size_t palette_hash = palette ? palette->data()->row_hash(palette->current_row()) : 0; auto iter = this->palette_to_index.find(palette_hash); if (iter == this->palette_to_index.cend() && this->palette_to_index.size() != ::MAX_PALETTES) { iter = this->palette_to_index.try_emplace(palette_hash, std::make_pair(palette, static_cast<unsigned int>(this->palette_to_index.size()))).first; } if (iter != this->palette_to_index.cend()) { this->palette_index = iter->second.second; } } } return this->palette_index; } unsigned int get_palette_remap_index_no_flush() { if (this->palette_remap_index == ff::constants::invalid_dword) { auto& remap_pair = this->palette_remap_stack.back(); auto iter = this->palette_remap_to_index.find(remap_pair.second); if (iter == this->palette_remap_to_index.cend() && this->palette_remap_to_index.size() != ::MAX_PALETTE_REMAPS) { iter = this->palette_remap_to_index.try_emplace(remap_pair.second, std::make_pair(remap_pair.first, static_cast<unsigned int>(this->palette_remap_to_index.size()))).first; } if (iter != this->palette_remap_to_index.cend()) { this->palette_remap_index = iter->second.second; } } return this->palette_remap_index; } int remap_palette_index(int color) const { return this->palette_remap_stack.back().first[color]; } void get_world_matrix_and_texture_index(const ff::texture_view_base& texture_view, bool use_palette, unsigned int& model_index, unsigned int& texture_index) { model_index = (this->world_matrix_index == ff::constants::invalid_dword) ? this->get_world_matrix_index_no_flush() : this->world_matrix_index; texture_index = this->get_texture_index_no_flush(texture_view, use_palette); if (model_index == ff::constants::invalid_dword || texture_index == ff::constants::invalid_dword) { this->flush(); this->get_world_matrix_and_texture_index(texture_view, use_palette, model_index, texture_index); } } void get_world_matrix_and_texture_indexes(ff::texture_view_base* const* texture_views, bool use_palette, unsigned int* texture_indexes, size_t count, unsigned int& model_index) { model_index = (this->world_matrix_index == ff::constants::invalid_dword) ? this->get_world_matrix_index_no_flush() : this->world_matrix_index; bool flush = (model_index == ff::constants::invalid_dword); for (size_t i = 0; !flush && i < count; i++) { texture_indexes[i] = this->get_texture_index_no_flush(*texture_views[i], use_palette); flush |= (texture_indexes[i] == ff::constants::invalid_dword); } if (flush) { this->flush(); this->get_world_matrix_and_texture_indexes(texture_views, use_palette, texture_indexes, count, model_index); } } void* add_geometry(const void* data, ::geometry_bucket_type bucket_type, float depth) { ::geometry_bucket& bucket = this->get_geometry_bucket(bucket_type); if (bucket_type >= ::geometry_bucket_type::first_alpha) { assert(!this->force_opaque); this->alpha_geometry.push_back(::alpha_geometry_entry { &bucket, bucket.count(), depth }); } return bucket.add(data); } ::geometry_bucket& get_geometry_bucket(::geometry_bucket_type type) { return this->geometry_buckets[static_cast<size_t>(type)]; } enum class state_t { invalid, valid, drawing, } state; // Constant data for shaders ff_dx::buffer geometry_buffer; ff_dx::buffer geometry_constants_buffer_0; ff_dx::buffer geometry_constants_buffer_1; ff_dx::buffer pixel_constants_buffer_0; ::geometry_shader_constants_0 geometry_constants_0; ::geometry_shader_constants_1 geometry_constants_1; ::pixel_shader_constants_0 pixel_constants_0; size_t geometry_constants_hash_0; size_t geometry_constants_hash_1; size_t pixel_constants_hash_0; // Render state std::vector<Microsoft::WRL::ComPtr<ID3D11SamplerState>> sampler_stack; ff_dx::fixed_state opaque_state; ff_dx::fixed_state alpha_state; ff_dx::fixed_state pre_multiplied_alpha_state; std::vector<ff::draw_base::custom_context_func> custom_context_stack; // Matrixes DirectX::XMFLOAT4X4 view_matrix; ff::matrix_stack world_matrix_stack_; ff::signal_connection world_matrix_stack_changing_connection; std::unordered_map<DirectX::XMFLOAT4X4, unsigned int, ff::stable_hash<DirectX::XMFLOAT4X4>> world_matrix_to_index; unsigned int world_matrix_index; // Textures std::array<const ff::texture_view_base*, ::MAX_TEXTURES> textures; std::array<const ff::texture_view_base*, ::MAX_TEXTURES_USING_PALETTE> textures_using_palette; size_t texture_count; size_t textures_using_palette_count; // Palettes bool target_requires_palette; std::vector<ff::palette_base*> palette_stack; std::shared_ptr<ff::texture> palette_texture; std::array<size_t, ::MAX_PALETTES> palette_texture_hashes; std::unordered_map<size_t, std::pair<ff::palette_base*, unsigned int>, ff::no_hash<size_t>> palette_to_index; unsigned int palette_index; std::vector<std::pair<const uint8_t*, size_t>> palette_remap_stack; std::shared_ptr<ff::texture> palette_remap_texture; std::array<size_t, ::MAX_PALETTE_REMAPS> palette_remap_texture_hashes; std::unordered_map<size_t, std::pair<const uint8_t*, unsigned int>, ff::no_hash<size_t>> palette_remap_to_index; unsigned int palette_remap_index; // Render data std::vector<::alpha_geometry_entry> alpha_geometry; std::array<::geometry_bucket, static_cast<size_t>(::geometry_bucket_type::count)> geometry_buckets; ::last_depth_type last_depth_type; float draw_depth; int force_no_overlap; int force_opaque; int force_pre_multiplied_alpha; }; } std::unique_ptr<ff::draw_device> ff::draw_device::create() { return std::make_unique<::draw_device_internal>(); } ff::draw_ptr ff::draw_device::begin_draw(ff::target_base& target, ff::depth* depth, const ff::rect_fixed& view_rect, const ff::rect_fixed& world_rect, ff::draw_options options) { return this->begin_draw(target, depth, std::floor(view_rect).cast<float>(), std::floor(world_rect).cast<float>(), options); } #endif
40.024646
212
0.595844
65997a849b40b9899b50f9d4c9f7a8950fea29fe
2,425
cpp
C++
piLibs/src/libLog/piXmlLogger.cpp
fossabot/arctic
f3f6e1051b7209020cdaec69ad1f1edbd1acb522
[ "MIT" ]
6
2021-03-27T01:54:55.000Z
2021-12-15T22:50:28.000Z
piLibs/src/libLog/piXmlLogger.cpp
fossabot/arctic
f3f6e1051b7209020cdaec69ad1f1edbd1acb522
[ "MIT" ]
null
null
null
piLibs/src/libLog/piXmlLogger.cpp
fossabot/arctic
f3f6e1051b7209020cdaec69ad1f1edbd1acb522
[ "MIT" ]
3
2020-07-15T13:27:02.000Z
2021-04-19T01:12:02.000Z
#include <stdio.h> #include <malloc.h> #include <string.h> #include "piXmlLogger.h" namespace piLibs { piXmlLogger::piXmlLogger() :piLogger() { } piXmlLogger::~piXmlLogger() { } static void printHeader(FILE *fp, const piLogStartInfo *info) { fwprintf(fp, L"<?xml version=\"1.0\"?>\n"); fwprintf(fp, L"<?xml-stylesheet type=\"text/xsl\" href=\"ComplexXSLT.xsl\" ?>\n"); fwprintf(fp, L"\n"); fwprintf(fp, L"\n"); fwprintf(fp, L"<DebugSesion>\n"); fwprintf(fp, L"\n"); fwprintf(fp, L"<Info>\n"); fwprintf(fp, L" <Date>%s</Date>\n", info->date); fwprintf(fp, L" <Memory>%d / %d Megabytes</Memory>", info->free_memory_MB, info->total_memory_MB); fwprintf(fp, L" <CPU>\n"); fwprintf(fp, L" <Processor>%s</Processor>\n", info->processor); fwprintf(fp, L" <Units>%d</Units>\n", info->number_cpus); fwprintf(fp, L" <Speed>%d Mhz</Speed>\n", info->mhz); fwprintf(fp, L" <CPU/>\n"); fwprintf(fp, L" <OS>%s</OS>\n", info->os); fwprintf(fp, L" <GPU>\n"); fwprintf(fp, L" <Vendor>%s</Vendor>\n", info->gpuVendor); fwprintf(fp, L" <Model>%s</Model>\n", info->gpuModel); fwprintf(fp, L" </GPU>\n"); fwprintf(fp, L" <VRam>%d Megabytes</GPU>\n", info->total_videomemory_MB); fwprintf(fp, L" <Screen>%d x %d</Screen>\n", info->mScreenResolution[0], info->mScreenResolution[1]); fwprintf(fp, L" <Multitouch>%d</Multitouch>\n", info->mIntegratedMultitouch); fwprintf(fp, L"</Info>\n"); fwprintf(fp, L"\n"); fwprintf(fp, L"<Events>\n"); fflush(fp); } bool piXmlLogger::Init(const wchar_t *path, const piLogStartInfo *info) { //path mFp = _wfopen(path, L"wt"); if (!mFp) return false; printHeader(mFp, info); return true; } void piXmlLogger::End(void) { fprintf(mFp, "</DebugSesion>\n"); fclose(mFp); } static const wchar_t *stype[5] = { L"Error", L"Warning", L"Assume", L"Message", L"Debug" }; void piXmlLogger::Printf(int messageId, int threadId, const wchar_t *file, const wchar_t *func, int line, int type, const wchar_t *str) { if (!mFp) return; fwprintf(mFp, L" <Event id=\"%d\">\n", messageId); fwprintf(mFp, L" <Type>%s</Type>\n", stype[type - 1]); fwprintf(mFp, L" <Th>%d</Th>\n", threadId); fwprintf(mFp, L" <File>%s</File>\n", file); fwprintf(mFp, L" <Func>%s</Func>\n", func); fwprintf(mFp, L" <Line>%d</Line>\n", line); fwprintf(mFp, L" <Text>%s</Text>\n", str); fwprintf(mFp, L" </Event>\n"); fflush(mFp); } }
28.869048
135
0.621031
659bfcb3b3d2eda72683ba09bc7e8f7416d3b963
481
cpp
C++
Online Judges/URI/2482/main.cpp
AnneLivia/URI-Online
02ff972be172a62b8abe25030c3676f6c04efd1b
[ "MIT" ]
64
2019-03-17T08:56:28.000Z
2022-01-14T02:31:21.000Z
Online Judges/URI/2482/main.cpp
AnneLivia/URI-Online
02ff972be172a62b8abe25030c3676f6c04efd1b
[ "MIT" ]
1
2020-12-24T07:16:30.000Z
2021-03-23T20:51:05.000Z
Online Judges/URI/2482/main.cpp
AnneLivia/URI-Online
02ff972be172a62b8abe25030c3676f6c04efd1b
[ "MIT" ]
19
2019-05-25T10:48:16.000Z
2022-01-07T10:07:46.000Z
#include <iostream> #include <map> using namespace std; int main() { int qtdI, qtdP; string s, idioma; map<string,string>m; cin >> qtdI; cin.ignore(); while(qtdI--) { getline(cin,idioma); getline(cin,s); m.insert(make_pair(idioma,s)); } cin >> qtdP; cin.ignore(); while(qtdP--) { getline(cin,s); getline(cin,idioma); cout << s << "\n" << m.at(idioma) << endl << endl; } return 0; }
17.178571
58
0.511435
659e17ea59230014ef413980bf7ee3a01f858a09
14,781
hpp
C++
include/boost/hana/fwd/type.hpp
josephwinston/hana
a8586ec1812e14e43dfd6867209412aa1d254e1a
[ "BSL-1.0" ]
null
null
null
include/boost/hana/fwd/type.hpp
josephwinston/hana
a8586ec1812e14e43dfd6867209412aa1d254e1a
[ "BSL-1.0" ]
null
null
null
include/boost/hana/fwd/type.hpp
josephwinston/hana
a8586ec1812e14e43dfd6867209412aa1d254e1a
[ "BSL-1.0" ]
null
null
null
/*! @file Forward declares `boost::hana::Type` and `boost::hana::Metafunction`. @copyright Louis Dionne 2015 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_FWD_TYPE_HPP #define BOOST_HANA_FWD_TYPE_HPP #include <boost/hana/core/operators.hpp> namespace boost { namespace hana { //! @ingroup group-datatypes //! Represents a C++ type. //! //! @note //! This page explains how Types work at a low level. To gain intuition //! about type-level metaprogramming in Hana, you should read the //! [tutorial section](@ref tutorial-type) on type-level computations. //! //! A `Type` is a special kind of object representing a C++ type like //! `int`, `void`, `std::vector<float>` or anything else you can imagine. //! Basically, the trick to implement such an object is to create the //! following dummy type: //! @code //! template <typename T> //! struct _type { }; //! @endcode //! //! Now, if we want to represent the type `int` by an object, we just //! create the following object //! @code //! _type<int> foo; //! @endcode //! and pretend that `foo` represents the type `int`. Note that since //! `_type<int>` can only be default constructed and hence has only one //! value, we could even not bother giving this object a name and we //! could simply use the `_type<int>{}` expression. The point here is //! that there is nothing special about the `foo` variable; it is just //! an alias for `_type<int>{}`. //! //! > __Note__ //! > This is not exactly how `Type`s are implemented in Hana because of //! > some subtleties; things were dumbed down here for the sake of //! > clarity. Please check below to know exactly what you can expect //! > from a `Type`. //! //! Now, let's say we wanted to transform our type `int` (represented by //! `foo`) into a type `int*` (represented by some other variable); how //! could we do that? More generally, how could we transform a type `T` //! into a type `T*`? Let's write a function! //! @code //! template <typename T> //! _type<T*> add_pointer(_type<T> foo) { //! _type<T*> bar; //! return bar; //! } //! @endcode //! //! We just let the compiler deduce the `T`, and from that we are able to //! generate the proper return type. That's it for the signature. For the //! implementation, we provide the simplest one that will make the code //! compile; we create a dummy object of the proper type and we return it. //! We can now use our function like: //! @code //! auto bar = add_pointer(foo); //! auto baz = add_pointer(bar); //! @endcode //! and we now have objects that represent the types `int*` and `int**`, //! respectively. //! //! As a side note, since we're lazy and we want to save as many //! keystrokes as possible, we'll use a variable template (new in //! C++14) to create our dummy variables: //! @code //! template <typename T> //! _type<T> type; //! @endcode //! Instead of typing `foo` or `_type<int>{}`, we can now simply write //! `type<int>`, which is effectively the same but looks better. //! //! However, the current definition of `_type` does not make it very //! useful. Indeed, we are only able to copy those objects around and //! perform pattern matching in template functions, which is still a bit //! limited. To make them more widely useful, we add the requirement //! that a `_type<T>` provides a nested alias to the type it wraps. //! In Boost.MPL parlance, we make `_type<T>` a nullary metafunction: //! @code //! template <typename T> //! struct _type { //! using type = T; //! }; //! @endcode //! //! Now, we can get the type represented by one of our objects without //! having to perform pattern matching inside a template function: //! @code //! auto bar = type<int*>; //! using Bar = decltype(bar)::type; //! static_assert(std::is_same<int*, Bar>{}, ""); //! @endcode //! //! Also, this makes any function returning a `Type` easily usable as a //! classic metafunction, by simply using decltype. For example, let's //! consider the following function, which finds the largest type in //! a sequence of types: //! //! @snippet example/type.cpp largest //! //! To make it a classic metafunction instead, we only need to modify it //! slightly using `decltype`: //! //! @snippet example/type.cpp largest2 //! //! While this new paradigm for type level programming might be difficult //! to grok at first, it will make more sense as you use it more and more. //! You will also come to appreciate how it blurs the line between types //! and values, opening new exciting possibilities. //! //! //! Lvalues and rvalues //! ------------------- //! When storing `Type`s in heterogeneous containers, some algorithms will //! return references to those objects. Since we are primarily interested //! in accessing their nested `::type`, receiving a reference is //! undesirable; we would end up trying to fetch the nested `::type` //! inside a reference type, which is a compilation error: //! @code //! auto ts = std::make_tuple(type<int>, type<char>); //! // Error; decltype(...) is a reference! //! using T = decltype(std::get<1>(ts))::type; //! @endcode //! //! For this reason, `Type`s provide an overload of the unary `+` operator //! that can be used to turn a lvalue into a rvalue. So when using a result //! which might be a reference to a `Type` object, one can use `+` to make //! sure a rvalue is obtained before fetching its nested `::type`: //! @code //! auto ts = std::make_tuple(type<int>, type<char>); //! // Good; decltype(+...) is an rvalue. //! using T = decltype(+std::get<1>(ts))::type; //! @endcode //! //! //! The actual representation of a Type //! ----------------------------------- //! For subtle reasons having to do with ADL, the actual type of the //! `type<T>` expression is not `_type<T>`. It is a dependent type //! which inherits `_type<T>`. Hence, you should never rely on the //! fact that `type<T>` is of type `_type<T>`, but you can rely on //! the fact that it inherits it, which is different in some contexts, //! e.g. for template specialization. //! //! //! Modeled concepts //! ---------------- //! 1. `Comparable` (operators provided)\n //! Two `Type`s are equal if and only if they represent the same C++ type. //! Hence, equality is equivalent to the `std::is_same` type trait. //! @snippet example/type.cpp comparable //! //! //! @todo //! - Completely figure out and document the category theoretical //! foundation of this data type. //! - Consider instantiating `Functor`, `Applicative` and `Monad` if //! that's possible. struct Type { }; //! Creates an object representing the C++ type `T`. //! @relates Type #ifdef BOOST_HANA_DOXYGEN_INVOKED template <typename T> constexpr unspecified-type type{}; #else template <typename T> struct _type { struct _; }; template <typename T> constexpr typename _type<T>::_ type{}; #endif //! Returns the type of an object as a `Type`. //! @relates Type //! //! ### Example //! @snippet example/type.cpp decltype #ifdef BOOST_HANA_DOXYGEN_INVOKED constexpr auto decltype_ = [](auto x) { return type<decltype(x)>; }; #else struct _decltype { template <typename T> constexpr auto operator()(T) const { return type<T>; } }; constexpr _decltype decltype_{}; #endif //! Returns the size of the C++ type represented by a `Type`. //! @relates Type //! //! ### Example //! @snippet example/type.cpp sizeof //! //! @todo //! Should we also support non-`Type`s? That could definitely be useful. #ifdef BOOST_HANA_DOXYGEN_INVOKED constexpr auto sizeof_ = [](_type<T> const&) { return size_t<sizeof(T)>; }; #else struct _sizeof { template <typename T> constexpr auto operator()(T const&) const; }; constexpr _sizeof sizeof_{}; #endif //! @ingroup group-datatypes //! A `Metafunction` is a function that takes `Type`s as inputs and //! gives a `Type` as output. //! //! In addition to the usual requirement of being callable, a //! `Metafunction` must provide a nested `apply` template to //! perform the same type-level computation as is done by its //! call operator. In Boost.MPL parlance, a `Metafunction` `F` //! must be a Boost.MPL MetafunctionClass in addition to being //! a function on `Type`s. In other words again, any `Metafunction` //! `f` must satisfy: //! @code //! f(type<T1>, ..., type<Tn>) == type<decltype(f)::apply<T1, ..., Tn>::type> //! @endcode struct Metafunction { }; //! Lift a template to a function on `Type`s. //! @relates Metafunction //! //! Specifically, `template_<f>` is a `Metafunction` satisfying //! @code //! template_<f>(type<x1>, ..., type<xN>) == type<f<x1, ..., xN>> //! decltype(template_<f>)::apply<x1, ..., xN>::type == f<x1, ..., xN> //! @endcode //! //! @note //! `template_` can't be SFINAE-friendly right now because of //! [Core issue 1430][1]. //! //! //! Example //! ------- //! @snippet example/type.cpp template //! //! [1]: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1430 #ifdef BOOST_HANA_DOXYGEN_INVOKED template <template <typename ...> class F> constexpr auto template_ = [](_type<T> const& ...) { return type<F<T...>>; }; #else template <template <typename ...> class F> struct _template; template <template <typename ...> class F> constexpr _template<F> template_{}; #endif //! Lift a MPL-style metafunction to a function on `Type`s. //! @relates Metafunction //! //! Specifically, `metafunction<f>` is a `Metafunction` satisfying //! @code //! metafunction<f>(type<x1>, ..., type<xN>) == type<f<x1, ..., xN>::type> //! decltype(metafunction<f>)::apply<x1, ..., xN>::type == f<x1, ..., xN>::type //! @endcode //! //! ### Example //! @snippet example/type.cpp metafunction #ifdef BOOST_HANA_DOXYGEN_INVOKED template <template <typename ...> class F> constexpr auto metafunction = [](_type<T> const& ...) { return type<typename F<T...>::type>; }; #else template <template <typename ...> class f> struct _metafunction; template <template <typename ...> class f> constexpr _metafunction<f> metafunction{}; #endif //! Lift a MPL-style metafunction class to a function on `Type`s. //! @relates Metafunction //! //! Specifically, `metafunction_class<f>` is a `Metafunction` satisfying //! @code //! metafunction_class<f>(type<x1>, ..., type<xN>) == type<f::apply<x1, ..., xN>::type> //! decltype(metafunction_class<f>)::apply<x1, ..., xN>::type == f::apply<x1, ..., xN>::type //! @endcode #ifdef BOOST_HANA_DOXYGEN_INVOKED template <typename F> constexpr auto metafunction_class = [](_type<T> const& ...) { return type<typename F::template apply<T...>::type>; }; #else template <typename F> struct _metafunction_class : _metafunction<F::template apply> { }; template <typename F> constexpr _metafunction_class<F> metafunction_class{}; #endif //! Lift a MPL-style metafunction to a function taking `Type`s and //! returning a default-constructed object. //! @relates Metafunction //! //! Specifically, `trait<f>(t...)` is equivalent to `template_<f>(t...)()`. //! The principal use case for `trait` is to transform metafunctions //! inheriting from a meaningful base like `std::integral_constant` //! into functions returning e.g. an `IntegralConstant`. //! //! The word `trait` is used because a name was needed and the principal //! use case involves metafunctions from the standard that we also call //! type traits. //! //! @note //! This is not a `Metafunction` because it does not return a `Type`. //! In particular, it would not make sense to make `decltype(trait<f>)` //! a MPL metafunction class. //! //! ### Example //! @snippet example/type.cpp liftable_trait //! //! Note that not all metafunctions of the standard library can be lifted //! this way. For example, `std::aligned_storage` can't be lifted because //! it requires non-type template parameters. Since there is no uniform //! way of dealing with non-type template parameters, one must resort to //! using e.g. an inline lambda to "lift" those metafunctions. In practice, //! however, this should not be a problem. //! //! ### Example of a non-liftable metafunction //! @snippet example/type.cpp non_liftable_trait //! //! @note //! When using `trait` with metafunctions returning `std::integral_constant`s, //! don't forget to include the boost/hana/ext/std/integral_constant.hpp //! header! #ifdef BOOST_HANA_DOXYGEN_INVOKED template <template <typename ...> class F> constexpr auto trait = [](_type<T> const& ...) { return F<T...>{}; }; #else template <template <typename ...> class F> struct _trait; template <template <typename ...> class F> constexpr _trait<F> trait{}; #endif //! Equivalent to `compose(trait<f>, decltype_)`; provided for convenience. //! @relates Metafunction //! //! @note //! This is not a `Metafunction` because it does not return a `Type`. //! In particular, it would not make sense to make `decltype(trait_<f>)` //! a MPL metafunction class. //! //! //! Example //! ------- //! @snippet example/type.cpp trait_ #ifdef BOOST_HANA_DOXYGEN_INVOKED template <template <typename ...> class F> constexpr auto trait_ = [](auto ...xs) { return F<decltype(xs)...>{}; }; #else template <template <typename ...> class F> struct _trait_; template <template <typename ...> class F> constexpr _trait_<F> trait_{}; #endif }} // end namespace boost::hana #endif // !BOOST_HANA_FWD_TYPE_HPP
36.9525
100
0.610987